UCSD - Semaphore / Lock Wait example #2

Version 1
    Task Name


    Lock wait example



    1. Tested on
    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?.



    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:



      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.



      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.

















    //Generic Function to get a report from the GUI

    function getReport(reportContext, reportName){

      var report = null;


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



      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.");



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


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

      var totalEarlierSRs = [];


      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){


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

      var completedRequests=0;


      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...");







      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";





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

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

      semaphore = "GREEN";








    // Clean the inputs

    var textToFind = String(input.textToFind);

    var waitingSeconds = String(input.waitingSeconds);

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

      var workflowName = ctxt.SR.getWorkflowName()



      var workflowName = String(input.workflowName);


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