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

Email task that can also be rolled back and can send a different message during roll back

Description

Prerequisites

Minimum UCSD version: 5.4.0.2

CategoryCustom task
Components
User Inputs

User Output

Instructions for Regular Workflow Use:

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 .WFD file resides. Choose the .WFD 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.

The workflow:

Screen Shot 2016-03-01 at 4.45.51 PM.png

Task input:

Screen Shot 2016-03-01 at 4.46.01 PM.png

Workflow execution during deployment:

Screen Shot 2016-03-01 at 4.46.57 PM.png

Log during deployment:

Service Request ID: 6308

Mar 01, 2016 22:26:14 UTC Request submitted

Mar 01, 2016 22:26:15 UTC Executing workflow item number 1

Mar 01, 2016 22:26:15 UTC Completed workflow item number 0, with status Completed

Mar 01, 2016 22:26:22 UTC Executing workflow item number 2

Mar 01, 2016 22:26:22 UTC Trigger context executeWorkFlowStep called

Mar 01, 2016 22:26:22 UTC Executing custom action Email_With_Rollback_v1 (custom_Email_with_Rollback)

Mar 01, 2016 22:26:22 UTC Executing custom action Email_With_Rollback_v1 (custom_Email_with_Rollback)

Mar 01, 2016 22:26:22 UTC Executing custom script for Email_with_Rollback

Mar 01, 2016 22:26:25 UTC Sending email...

Mar 01, 2016 22:26:25 UTC Task #1 (Email_With_Rollback_v1 (custom_Email_with_Rollback)) completed successfully in 3 seconds

Mar 01, 2016 22:26:25 UTC Input/Output values for Task #1 (Email_With_Rollback_v1 (custom_Email_with_Rollback)):

Mar 01, 2016 22:26:25 UTC [Template Input:EmailTo = ${SUBMITTER_EMAIL}]

Mar 01, 2016 22:26:25 UTC [Resolved Template Input: EmailTo = ogelbric@cisco.com]

Mar 01, 2016 22:26:25 UTC [Local Input: EmailTo = ogelbric@cisco.com]

Mar 01, 2016 22:26:25 UTC [Local Input: EmailFrom = no-reply@cisco.com]

Mar 01, 2016 22:26:25 UTC [Template Input:EmailSubject = Deploy Application XYZ ${SR_ID}]

Mar 01, 2016 22:26:25 UTC [Resolved Template Input: EmailSubject = Deploy Application XYZ 6308]

Mar 01, 2016 22:26:25 UTC [Local Input: EmailSubject = Deploy Application XYZ 6308]

Mar 01, 2016 22:26:25 UTC [Local Input: MessageExecute = going forward info]

Mar 01, 2016 22:26:25 UTC [Local Input: MessageRollback = rolling back info]

Mar 01, 2016 22:26:25 UTC Completed workflow item number 1, with status Completed

Mar 01, 2016 22:26:29 UTC Executing workflow item number 3

Mar 01, 2016 22:26:29 UTC Completed workflow item number 2, with status Completed

The rollback execution:

Screen Shot 2016-03-01 at 4.48.08 PM.png

The Rollback log:

Service Request ID: 6309

Mar 01, 2016 22:26:55 UTC Request submitted

Mar 01, 2016 22:26:58 UTC Executing workflow item number 1

Mar 01, 2016 22:26:58 UTC Completed workflow item number 0, with status Completed

Mar 01, 2016 22:27:02 UTC Executing workflow item number 2

Mar 01, 2016 22:27:02 UTC Trigger context executeWorkFlowStep called

Mar 01, 2016 22:27:02 UTC Executing custom action Rollback Email_With_Rollback_v1 (SR 6308) (custom_Email_with_Rollback)

Mar 01, 2016 22:27:02 UTC Executing custom action Rollback Email_With_Rollback_v1 (SR 6308) (custom_Email_with_Rollback)

Mar 01, 2016 22:27:02 UTC Executing custom script for Email_with_Rollback

Mar 01, 2016 22:27:05 UTC Sending email...

Mar 01, 2016 22:27:05 UTC Task #1 (Rollback Email_With_Rollback_v1 (SR 6308) (custom_Email_with_Rollback)) completed successfully in 3 seconds

Mar 01, 2016 22:27:05 UTC Input/Output values for Task #1 (Rollback Email_With_Rollback_v1 (SR 6308) (custom_Email_with_Rollback)):

Mar 01, 2016 22:27:05 UTC [Local Input: EmailTo = ogelbric@cisco.com]

Mar 01, 2016 22:27:05 UTC [Local Input: EmailFrom = no-reply@cisco.com]

Mar 01, 2016 22:27:05 UTC [Local Input: EmailSubject = Deploy Application XYZ 6308 Rollback!!!]

Mar 01, 2016 22:27:05 UTC [Local Input: MessageExecute = rolling back info]

Mar 01, 2016 22:27:05 UTC [Local Input: MessageRollback = ]

Mar 01, 2016 22:27:05 UTC Completed workflow item number 1, with status Completed

Mar 01, 2016 22:27:10 UTC Executing workflow item number 3

Mar 01, 2016 22:27:10 UTC Completed workflow item number 2, with status Completed

The resulting e-mails:

Screen Shot 2016-03-01 at 4.43.46 PM.png

The custom task code:

importPackage(java.util);

importPackage(java.lang);

importPackage(java.io);

importPackage(com.cloupia.model.cEvent.notify);

importPackage(com.cloupia.model.cIM);

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

importPackage(com.cloupia.fw.objstore);

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

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

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

var emailto = input.EmailTo;

var emailfrom = input.EmailFrom;

var emailsubject = input.EmailSubject;

var messageexecute = input.MessageExecute;

var messagerollback = input.MessageRollback;

function registerUndoTask()

{

     //

     // the handler name is as follows "custom_" + Task name

     //

     var undoHandler = "custom_Email_with_Rollback";

     var undoContext = ctxt.createInnerTaskContext(undoHandler);

     var undoConfig = undoContext.getConfigObject();

     //

     // The order of input is important

     // Note on the left hand side are the variables for the task

     // Note the swap happens in the Message Execute = Message Rollback

     //

     undoConfig.EmailTo = input.EmailTo;

     undoConfig.EmailFrom = input.EmailFrom;

     undoConfig.EmailSubject = input.EmailSubject + " Rollback!!!";

     undoConfig.MessageExecute = input.MessageRollback;

     undoConfig.MessageRollback = "";

     ctxt.getChangeTracker().undoableResourceModified("custom_Email_with_Rollback",

                 "Asset ID "+input.EmailTo,

                 "Not sure what this field does",

                 "Task Description "+input.EmailSubject,

                 undoHandler,

                 undoConfig);

}

function getMailSettings()

{

      return ObjStoreHelper.getStore((new MailSettings()).getClass()).getSingleton();

}

//

// Main

//

if ( (input.EmailTo === null) || (input.EmailTo.trim().length() === 0) )

{

        ctxt.setFailed("No email to send");

       ctxt.exit();

}

//

// Register the undo event on initial execution

//

registerUndoTask();

var message = new EmailMessageRequest();

message.setToAddr(input.EmailTo);

message.setFromAddress(input.EmailFrom);

message.setSubject(input.EmailSubject);

message.setMessageBody(messageexecute);

logger.addInfo("Sending email...");

MailManager.sendEmail(emailsubject, getMailSettings(), message);

More information on getChangeTracker().undoableResourceModified:

This code is used for registering the respective rollback task.

It is required for supporting the rollback functionality.

Full signature of undoableResourceModified method:

public void undoableResourceModified(String assetType, String assetId,String assetLabel, String description, String undoTask,  Object undoConfigData).

The undoHandler(undoTask) represents the rollback task name.

The undoConfig(undoConfigData) holds all the data that is required for the rollback task.

Suppose we created a custom task(Create file custom task) that will create a file inside /opt directory.

We want to provide the rollback functionality(Deleting the created file) for that custom task.

Then we can use this code inside Create file custom task for registering the respective rollback task(Let’s say rollback task name is Delete file custom task) .

So when we rollback the SR(generated due to the execution of Create file custom task),the rollback task(Delete file custom task) will be executed.

Here is the Java underbelly:

context.getChangeTracker().resourceModified(assetType, assetId, assetLabel, description);

So to register rollback in an OA workflow task, I’d do something like this (Method is Add, not Modified in my example):

context.getChangeTracker().undoableResourceAdded("assetType", "idString", "Nimble Add Initiator to Initiator Group",

"Rollback Nimble Add Initiator to Initiator Group " + config.getInitiatorGroupName(),

new SlimceaRemoveFcInitiatorFromIgroupTask().getTaskName(), new SlimceaRemoveFcInitiatorFromIgroupConfig(config));

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