cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1578
Views
0
Helpful
2
Comments
Orf Gelbrich
Cisco Employee
Cisco Employee
Task Name

Lock wait example

Description

Prerequisites
  1. Tested on 5.4.0.2
CategoryWorkflow
ComponentsvSphere 5.x
User Inputse-mail address
Outpute-mail with counter

Instructions for Regular Workflow Use:

  1. Download the attached .ZIP file below to your computer. *Remember the location of the saved file on your computer.
  2. Unzip the file on your computer. Should end up with a .WFD file.
  3. Log in to UCS Director as a user that has "system-admin" privileges.
  4. Navigate to "Policies-->Orchestration" and click on "Import".
  5. Click "Browse" and navigate to the location on your computer where the .WFDX file resides. Choose the .WFDX file and click "Open".
  6. Click "Upload" and then "OK" once the file upload is completed. Then click "Next".
  7. Click the "Select" button next to "Import Workflows". Click the "Check All" button to check all checkboxes and then the "Select" button.
  8. Click "Submit".
  9. A new folder should appear in "Policies-->Orchestration" that contains the imported workflow. You will now need to update the included tasks with information about the specific environment

Thank you goes to: Alejandro Madurga Ainoza

The import:

Screen Shot 2016-04-20 at 9.47.31 AM.png

Screen Shot 2016-04-20 at 9.48.12 AM.png

Sample Workflow:

Screen Shot 2016-04-20 at 9.48.46 AM.png

Please read attached document for further instructions!

The after Marshall code:

//After Marshall :

/* Use this method to hide or unhide an input field. */

var status = page.getValue(id+".chkWorkflowName");

if (status == "true"){

page.setHidden(id + ".workflowName", true); //hide the input field ?portList?.

}

else{

page.setHidden(id + ".workflowName", false); //hide the input field ?portList?.

}

The java script code:

/*

Name: lockWait.js

Author: Alejandro Madurga (almadurg@cisco.com)

Date: 10th September 2015

Version: 0.1

UCSD Version: 5.3.1.2

Description:

  This custom task look for the execution of workflows with the same name on the Requests table, and if there is more than one, it checks the SR ID

  to see which one is the first one (lower SRID), if it is not the lowest one, it checks for a initiator comment text,

  the idea is the precedent SRIDs will update the comment when the exclusion phase is finished, so if the earlier SRs

  have completed the exclusion phase they will add a comment on the Initiatior comments telling the others that they have

  exited the exclusion phase, so the others can enter on the exclusion phase using the SRID order to do so.

  //INPUTS:

  chkWorkflowName: [Generic String Text] A boolean selection (true or false), if enabled  then the custom task will look for

  workflows with the same name than the one executing this custom task, if is not selected you will need

  to input the workflow name to look the lock for

  workflowName: [Generic String Text] The name of the workflows to look the locking. Only available if you uncheck

  the chkWorkflowName

  textToFind:[Generic String Text] The text to find on the Initiator Comments to see if the request has passed that step

  waitingSeconds: [Generic String Text]: Number of seconds to wait each iteration.

  //OUTPUTS

  NONE

 

*/

//IMPORTS

importPackage(java.lang);

importPackage(com.cloupia.model.cIM);

importPackage(com.cloupia.lib.util.managedreports);

importPackage(com.cloupia.service.cIM.inframgr);

importPackage(com.cloupia.lib.util);

//FUNCTIONS

//Generic Function to get a report from the GUI

function getReport(reportContext, reportName){

  var report = null;

            try{

                 report = ctxt.getAPI().getConfigTableReport(reportContext, reportName);

                }catch(e)

                            {}

  if (report == null)

      {

      return ctxt.getAPI().getTabularReport(reportName, reportContext);

      }

            else {

        var source = report.getSourceReport();

                   return ctxt.getAPI().getTabularReport (source, reportContext);

        }

}

//Generic function to get a tableview from the gui.

function getReportView(reportContext, reportName){

  var report = getReport(reportContext, reportName);

  if (report == null)

              {

  logger.addError("No such report exists for the specified context "+reportName);

  return null;

              }

  return new TableView(report);

}

//Check if other Requests are waiting for lock

function waitForLock(workflowName,textToFind,waitingSeconds){

  var mySRID = Integer.parseInt(ctxt.getSrId());

  var seconds = Integer.parseInt(waitingSeconds)*1000;

  var reportName="ServiceRequestFeature.group.table_config";

  var semaphore = "RED";

  while (semaphore == "RED"){

  var repContext = util.createContextByType(6, null, null );

  var report = getReportView(repContext, reportName);

  report = report.filterRowsByColumn("Catalog/Workflow Name", workflowName, false);

  report = report.filterRowsByColumn("Request Status","In Progress",false);

  logger.addInfo("Total Requests in progress found with workflow Name : " + workflowName +" = " + report.rowCount());

  if (report.rowCount() == 1){

  //NO Request colliding!, I'm the only one here --> continue!

  semaphore = "GREEN";

  logger.addInfo("There are no other requests pending.");

  }

  else{

  //Count the number of SR IDs with an ID lower than mine

  //

  logger.addInfo("There are other requests pending.");

  var totalEarlierSRs = [];

  for(j=0;j<report.rowCount();j++){

  if(mySRID > Integer.parseInt(report.getColumnValue(j,"Service Request Id"))){

  //There is a SR that have been submitted earlier than me!

  totalEarlierSRs.push(Integer.parseInt(report.getColumnValue(j,"Service Request Id")));

  }

  }

  if (totalEarlierSRs.length > 0){

  //MORE REQUEST ONGOING, LETS CHECK THOSE!

  logger.addInfo("There are " + String(totalEarlierSRs.length) + " before me.");

  var completedRequests=0;

  for(i=0;i<totalEarlierSRs.length;i++){

  var auxReport = report.filterRowsByColumn("Service Request Id",String(totalEarlierSRs[i]),false);

  //Get the SR ID comments

  var sr = InfraPersistenceUtil.getServiceRequest(Integer.parseInt(auxReport.getColumnValue(0,"Service Request Id")));

  //Showing the comments

  var comments =  sr.getComments();

  if (comments.search(textToFind) == -1){

  logger.addInfo("Request found without specified text on the comments: " + report.getColumnValue(0,"Service Request Id"));

  logger.addInfo("Waiting " + waitingSeconds + " seconds...");

  Thread.sleep(seconds);

  break;

  }

  else{

  completedRequests=completedRequests+1;

  }

  if(completedRequests == totalEarlierSRs.length){

  logger.addInfo("There are other in front of me, but they already have the correct text on the Initiator Comments!");

  semaphore = "GREEN";

  }

  }

  }

  else{

  // No SRs ordered before me, so I can continue

  logger.addInfo("There are no other requests in front of me");

  semaphore = "GREEN";

  }

  }

  }

}

//MAIN FUNCTION

// Clean the inputs

var textToFind = String(input.textToFind);

var waitingSeconds = String(input.waitingSeconds);

if (String(input.chkWorkflowName) == "true"){

  var workflowName = ctxt.SR.getWorkflowName()

}

else{

  var workflowName = String(input.workflowName);

}

logger.addInfo("Checking workflows executing with workflow name: " + workflowName);

waitForLock(workflowName,textToFind,waitingSeconds);



Comments
staabrah
Community Member

If we are using this in a compound workflow, it won't work. Because this code is looking in the GUI report for Workflow name and status. Child SRs usually not shown in GUI report.

Orf Gelbrich
Cisco Employee
Cisco Employee

Hence I choose to use a flag file: UCSD - Semaphore Example (v1)

and typically a semaphore is used to lock something quick and unlock it quickly and ensure the process is the only one touching it.  Calling compound workflows does not sound like things are locked and unlocked quickly.

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community:

Quick Links