Skip to content

User interactions and approvals

Some steps need a person. A change needs an approval, a request is missing a detail, or an operator has to confirm that a maintenance window really has started. Orchestrator handles this with the User interaction element. When a run reaches it, the run stops and waits for someone to fill in a small form. Their answers go into the run’s variables, and the workflow carries on with them.

In this recipe you build Approve a VM description. It asks for approval before it runs Describe a VM from recipe 3.1, logs the reason if the request is rejected, and gives up cleanly if nobody answers in time. The workflow only reads from vCenter, so you can try the whole approval loop without risk.

Getting ready

  • The workflow Describe a VM from recipe 3.1, and the folder VCF Orchestrator Guide/Chapter 3.
  • A second login to answer with, if you want to see the approval from the approver’s side. It doesn’t need an Orchestrator role: Broadcom’s role table says users without one can still respond to user interaction requests.
  • The idea of an exception path from recipe 3.4, and of the long-running elements from recipe 3.7.

How to do it

Set up the workflow

  1. Create a workflow called Approve a VM description in VCF Orchestrator Guide/Chapter 3.
  2. On the Inputs/Outputs tab, add:
    • An input vm of type VC:VirtualMachine.
    • An input approvalHours of type number. On the Input Form tab later, you can give it a default of 24.
    • An output summary of type string.
  3. On the Variables tab, add four variables:
Name Type Holds
approvalDeadline Date The time the request stops waiting
approved boolean The approver’s answer
approverComment string The approver’s reason
approvalError string The error if nobody answers in time
  1. On the Schema tab, add a scriptable task called Set the deadline, with approvalHours in and approvalDeadline out:
Approve a VM description — Set the deadline
// approvalHours can be a fraction: 0.05 is three minutes
var waitMs = Math.round(approvalHours * 60 * 60 * 1000);
approvalDeadline = new Date(new Date().getTime() + waitMs);
System.log("Waiting for approval until " + approvalDeadline);

Add the user interaction

  1. From the Generic group of the palette, drag a User interaction onto the arrow after Set the deadline. Name it Ask for approval.
  2. Select it and open Options. Bind timeout.date to approvalDeadline. Leave security.group, security.assignees, and security.assignee.groups unbound for now. There’s more shows what they do.
  3. Add the two answers the approver gives. Under Form Inputs, click + and pick approved, then + again and pick approverComment. These are the fields the approver sees, and their answers are written back to these variables. Adding them here also lays out a default answer form.
  4. The workflow now has an extra tab, named after the element: Ask for approval. Open it (or click Edit input form on the element). Select each field and, on Appearance, set the Label: Approve this request for approved and Reason for approverComment. On the Constraints tab of Reason, set Required to Yes. The editor is the same one you used on the Input Form tab in recipe 3.6.
Schema tab of Approve a VM description, Ask for approval selected. Options: security.group (LdapGroup), security.assignees (Array/LdapUser) and security.assignee.groups (Array/LdapGroup) unbound; timeout.date (Date) bound to approvalDeadline. Form Inputs: Edit Input Form button; approved (boolean) and approverComment (string).
Figure 3.30. A user interaction with its deadline bound and two answer fields.

Fill in the form inputs with + in the editor, not only in an imported or hand-edited workflow file: a user interaction without a laid-out form shows the approver an empty dialog.

Act on the answer

  1. Drag a Decision onto the arrow after Ask for approval. Name it Approved?, choose the variable approved, and the condition is true.
  2. On the decision’s true path, drag the workflow Describe a VM from the library. Bind its input vm to vm and its output summary to summary.
  3. On the false path, add a scriptable task called Log the rejection, with vm and approverComment in and summary out, and link it to an end element:
Approve a VM description — Log the rejection
summary = "Request for " + vm.name + " rejected: " + approverComment;
System.warn(summary);

Handle the timeout

  1. Select Ask for approval again. Under its exception handling, choose approvalError as the variable that receives the error.
  2. Drag a scriptable task onto Ask for approval itself, not onto an arrow. Orchestrator draws a red dashed exception arrow to it. Name it Log the timeout, with approvalDeadline and approvalError in and summary out, and link it to an end element:
Approve a VM description — Log the timeout
summary = "No answer before " + approvalDeadline + ". Nothing was done.";
System.warn(summary + " (" + approvalError + ")");
  1. Click Save.
Full schema of Approve a VM description: Start, Set the deadline, Ask for approval, Approved?, Describe a VM, End along the top. A red dashed exception arrow from Ask for approval down to Log the timeout and its End; a red dashed arrow from Approved? down to Log the rejection and its End.
Figure 3.31. The finished approval workflow, with a decision on the answer and an exception path for the timeout.

Answer it

  1. Run the workflow with any VM and approvalHours = 1. The run logs its deadline, then stops in the Waiting state.
  2. As the approver, open Activity > Waiting for Input. The run appears there as a card, and on the Dashboard under Waiting for Input. Click Answer on the card to open the form from step 8.
  3. Select Approve this request, type a reason, and click Answer. The run carries on, runs Describe a VM, and completes with the VM’s summary in its summary output.
Activity, Waiting for Input (1): a card for Approve a VM description : Ask for approval. The dialog Input Request: Approve a VM description : Ask for approval is open, with Approve this request ticked, Reason (required) = Lab test, and Cancel and Answer buttons.
Figure 3.32. The approver's view of a waiting user interaction.
  1. Run it again and answer with Approve this request cleared. The run follows the false path and logs the rejection with your reason.
  2. Run it a third time with approvalHours = 0.05 and don’t answer. After about three minutes, the run follows the exception path to Log the timeout and ends Completed. In the lab the timeout fired ten seconds after the deadline, and approvalError held Timeout on signal.

How it works

A user interaction is a long-running element, like the waiting timer and waiting event in recipe 3.7. When a run reaches it, Orchestrator saves the run to its database, frees the run’s thread, and creates a user interaction object: a record that says which run is waiting, which fields it needs, who may answer, and until when. The run sits in the Waiting state, using no thread, for as long as it takes. A restart of the server doesn’t lose it.

When someone answers, Orchestrator checks that they’re allowed to, writes their values into the variables listed as the element’s form inputs, and picks the run up again at the next element. From there it’s an ordinary run. The decision in step 9 reads approved like any other variable.

Its special inputs control the waiting:

  • timeout.date is the deadline. When it passes with no answer, the element throws an exception. With an exception path, as in step 13, the workflow handles it. Without one, the run fails. Leave it unbound and the run waits for ever.
  • security.group, security.assignees, and security.assignee.groups say who may answer. With none of them bound, the request isn’t restricted to particular people.

Answering is just another call to the Orchestrator REST API. The client calls it when you click Answer, and so can any other system, which is how a ticketing tool or a chat bot can approve a run.

Back in vRO 5.5–7Add a User Interaction in the Java client, list the answer fields on its External inputs tab, and lay out their form on its Presentation tab. Approvers answer from the Java client or from a web view.
In Orchestrator 9.xAdd a User interaction in the browser client and design its answer form with the same form editor as the run form. Approvers answer from Activity > Waiting for Input, or through the REST API.

There's more

Choose who answers. Bind one of the security inputs to restrict the approvers. security.group (LdapGroup) takes one group, and only its members can answer. security.assignees (Array/LdapUser) takes a list of users, and security.assignee.groups (Array/LdapGroup) a list of groups. Which users and groups you can pick depends on the authentication provider from Chapter 1. With vSphere authentication, they come from vCenter Single Sign-On. With a VCF Automation organization, they come from that organization.

Needs a lab check. On 9.1.1 with vSphere authentication, bind security.assignees to one user and confirm that another non-administrator can’t answer, that an Orchestrator administrator can, and how a user or group value is picked in the form.

Answer from a script or another system. The REST API has one call to read a waiting interaction and one to answer it, both under the run that’s waiting. To find the waiting runs, list GET /vco/api/interactions. To read the form of one, call GET on the run’s interaction, and to answer, POST the values to the same address:

Answering a user interaction through the REST API
# WF_ID is the workflow's ID, RUN_ID the waiting run's ID, TOKEN a bearer token (Chapter 7)
curl -k -X POST \
"https://vco01.vmw.lab/vco/api/workflows/$WF_ID/executions/$RUN_ID/interaction" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"parameters": [
{"name": "approved", "type": "boolean", "value": {"boolean": {"value": true}}},
{"name": "approverComment", "type": "string", "value": {"string": {"value": "Approved from the API"}}}
]}'

The call returns 204 No Content when the answer is accepted, and the run carries on at once: tested on 9.1.1, both with an approval and with a rejection. A DELETE on the same address cancels the interaction. Chapter 7 shows how to get a token and find workflow and run IDs.

Approvals in VCF Automation. VCF Automation has its own approval policies for catalog requests. They’re separate from user interactions and answered in VCF Automation, not in the Orchestrator Client. Use an approval policy when the question is “may this person order this item?”, and a user interaction when a step in the middle of a workflow needs a decision. Chapter 8 covers the VCF Automation side.

Send a reminder. Nobody watches Waiting for Input all day. Before the user interaction, send the approver an email or chat message with the VM name, the deadline, and a link to the client. The mail plug-in is covered in Chapter 5.

Keep deadlines realistic. A request that waits for a week ties up nothing on the server, but it does keep a half-finished change in flight. Pick a deadline that matches how the approvers work, and make the timeout path tell someone that the request expired.

Ask for more than yes or no. The answer form can hold any input type, with defaults, drop-downs filled by actions, and validations, exactly as in recipe 3.6. An approver can pick a datastore, correct a hostname, or choose a change window, and the workflow uses the answer like any other variable.

See also