5.5.1

Table Of Contents
//create the services
WorkflowService workflowService = new WorkflowService(session);
ExecutionService executionService = new ExecutionService(session);
//find a workflow by ID
Workflow workflow = workflowService.getWorkflow("1231235");
//create an ExecutionContext from the user's input
ExecutionContext context = new ExecutionContextBuilder().addParam("name",
"Jerry").addParam("age", 18).build();
//run the workflow
WorkflowExecution execution = executionService.execute(workflow, context);
//wait for the workflow to reach the user interaction state, checking every 500 milliseconds
execution = executionService.awaitState(execution, 500, 10, WorkflowExecutionState.CANCELED,
WorkflowExecutionState.FAILED, WorkflowExecutionState.COMPLETED);
String nameParamValue = new
ParameterExtractor().fromTheOutputOf(execution).extractString("name");
System.out.println("workflow was executed with 'name' input set to" + nameParamValue);
Operations with Workflows
The Orchestrator REST API provides Web services that you can use to perform various operations with
workflows.
Find a Workflow and Retrieve Its Definition
To be able to perform any kind of operation with a workflow, you must find that workflow in the
Orchestrator inventory and retrieve its definition. The definition lists the workflow input and output
parameters, and contains links to the available workflow runs, the workflow presentation, and other objects.
Prerequisites
Verify that you have imported the sample workflows package in Orchestrator. The package is included in
the Orchestrator sample applications ZIP file that you can download from the Orchestrator documentation
page.
Procedure
1 Find the inventory item of the workflow.
n
If you have the full name of the workflow or a key word from the name, make a GET request at the
URL of the Workflow service by applying a filter:
GET https://{vcoHost}:{port}/vco/api/workflows?conditions=name={workflowFullName}
GET https://{vcoHost}:{port}/vco/api/workflows?conditions=name~{keyWord}
n
Search for the workflow through the Catalog or the Inventory service by making a GET request at
the URL that is an entry point for the workflow inventory items:
GET https://{vcoHost}:{port}/vco/api/catalog/System/Workflow/
GET https://{vcoHost}:{port}/vco/api/inventory/System/Workflows/
2 Retrieve the inventory item of the workflow by making a GET request at its URL:
GET https://{vcoHost}:{port}/vco/api/catalog/System/Workflow/{workflowID}/
Chapter 2 Using the vCenter Orchestrator REST API
VMware, Inc. 15