UCSD - Schedule Workflow / Schedule a Future Rollback of a Service Request ID

Version 3
    Task Name

    Schedule a workflow / Schedule a workflow for rollback by given SR ID

    Description

     

    Prerequisites
    1. Tested on 6.0
    CategoryWorkflow
    ComponentsvSphere 5.x
    User Inputs
    Output

    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

     

    A big thank you goes to Tejeswar Sahu for the contribution.

     

     

    This example will schedule a workflow which in turn will roll back a give service request ID:

     

    The rollback workflow:

     

    Screen Shot 2016-09-19 at 6.52.16 AM.png

     

    The scheduling workflow:

     

    Screen Shot 2016-09-19 at 6.52.50 AM.png

     

     

    The run for the workflows:

     

    Screen Shot 2016-09-19 at 6.49.51 AM.png

     

    The created schedule:

     

    Screen Shot 2016-09-19 at 6.46.00 AM.png

     

     

    The schedule code in the custom task:

     

    importPackage(com.cloupia.model.cIM);

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

    importPackage(com.cloupia.fw.objstore);

    importPackage(com.cloupia.feature.customactions);

    importPackage(java.lang);

    importPackage(java.util);

    var SCHEDULE_HOURLY                 = 1;

    var SCHEDULE_DAILY                  = 2;

    var SCHEDULE_WEEKLY                 = 3;

    var SCHEDULE_MONTHLY                = 4;

    var SCHEDULE_MINUTES                = 5;

    var RECURRENCE_NO_END               = 1;

    var RECURRENCE_NUMBER_OF_OCCURENCES = 2;

    var RECURRENCE_END_BY_DATE          = 3;

    var RECURRENCE_ONLY_ONCE            = 4;

     

     

    var startTime = input.StartTime;

    var frequency = input.FrequencyType;

    var repeatCount = input.FrequencyInterval;

    var recurrenceType = input.RecurrenceType;

    var workflowName = input.workflowName;

    var userId = input.UserID;

     

     

    if(frequency == "HOURLY"){

    frequency = SCHEDULE_HOURLY;

     

     

    }else if(frequency == "DAILY"){

    frequency = SCHEDULE_DAILY;

     

     

    }else if(frequency == "WEEKLY"){

    frequency = SCHEDULE_WEEKLY;

     

     

    }else if(frequency == "MONTHLY"){

    frequency = SCHEDULE_MONTHLY;

     

     

    }else if(frequency == "MINUTES"){

    frequency = SCHEDULE_MINUTES;

     

     

    }

     

     

    if(recurrenceType == "NO_END"){

    recurrenceType = RECURRENCE_NO_END;

     

     

    }else if(recurrenceType == "NUMBER_OF_OCCURENCES"){

    recurrenceType = RECURRENCE_NUMBER_OF_OCCURENCES;

     

     

    }else if(recurrenceType == "END_BY_DATE"){

    recurrenceType = RECURRENCE_END_BY_DATE;

     

     

    }else if(recurrenceType == "ONLY_ONCE"){

    recurrenceType = RECURRENCE_ONLY_ONCE;

    }

     

     

    if(startTime <= System.currentTimeMillis())

    {

    throw new Exception("Start Time cannot be set to Past time");

    }

     

     

    var item = new Schedule();

     

     

    var store = ObjStoreHelper.getStore(new CustomActionDefinition().getClass());

    var list= store.query("name == '" + workflowName + "'");

    var def = list.get(0);

     

     

    var status;

    status = WFSchedulerUtil.isWFScheduleExist(def.getId());

    if(status){

    throw new Exception("Workflow schedule already exists.");

    }

     

     

    var validator = new WFValidator(def);

    validator.validate();

     

     

    //long type

    item.setStartTime(startTime);

     

     

    //int type, Hourly, Daily,Weekly,Monthly,Minutes

    item.setFrequency(frequency);

     

     

    //int type

    item.setRepeatCount(repeatCount);

     

     

    //long type

    var endTime = startTime + item.getFrequencyInMilliseconds();

    item.setEndTime(endTime);

     

     

    //int type, No End, Only Once,Fixed Numbr Of Times

    item.setRecurrenceType(recurrenceType);

     

     

    var scheduleId = WFSchedulerUtil.addSchedule(item);

     

     

    //workflow Inputs

    var wfInputDef = CustomActionUtil.getWorkflowInputFieldDefinitions(def.getId());

    var inputIDs = [];

    var inputValues = input.srId;

     

     

    for(var i=0;i<wfInputDef.size();i++){

    inputIDs[i] = wfInputDef.get(i).getName();

    }

     

     

    var map = new HashMap();

    map.put(inputIDs[0],inputValues);

     

     

    var inputSetId = CustomActionUtil.addWorkflowInputValues(map , def.getId(), "admin");

    var itemData = new WFSchedulerData();

     

     

    itemData.setScheduleId(item.getScheduleId());

    itemData.setUserId(userId);

    itemData.setScheduleId(scheduleId);

    itemData.setSchedule(item);

    itemData.setActionId(def.getId());

    itemData.setInputSetId(inputSetId);

    WFSchedulerUtil.addWFSchedulerData(itemData);

     

     

    logger.addInfo("workflow task "+workflowName+"  Scheduled successfully.");

     

     

     

    Please Note:

     

     

     

    //As there is no functionality available to add dynamically all workflow input but I have generalized the code as shown in below snipped

    //If you need to add more inputs then you can do it by adding map value as shown below

    var inputIDs = [];

    var inputValues = input.srId;

     

    for(var i=0;i<wfInputDef.size();i++){

    inputIDs[i] = wfInputDef.get(i).getName();

    }

    var map = new HashMap();

    map.put(inputIDs[0],inputValues_1);

    .

    .

    .

    map.put(inputIDs[1],inputValues_2);

    map.put(inputIDs[2],inputValues_3);

     

    As of now I have updated the workflow with single workflow input only

     

     

    Caveat Note!!!

         Limitations with scheduling, only have one “active” schedule per workflow!

         Ticket is in place to get this fixed.