Using the Java REST SDK
You can use a Java SDK library to call operations on the vRealize Orchestrator REST API in Java applications and work directly with objects.
Every RESTful Web service of the vRealize Orchestrator REST SDK has a wrapping Java class with methods that correspond to the operations that can be run by using the service.
Run a Workflow and Wait for Its Completion
The following example code runs a workflow and waits
for it to complete.
Note: When running the
example code in vRealize
Orchestrator deployments authenticated with vRealize Automation, you must use a
different
VcoSession session
function that uses your
vRealize Automation
authentication token. The rest of the code example is identical regardless of
whether you are using vSphere or vRealize Automation as a authentication
provider.VcoSession session = DefaultVcoSessionFactory.newSession(new OAuthTokenAuthentication("{token-from-vra/vrac}"));
//start a new session to Orchestrator by using specified credentials VcoSession session = DefaultVcoSessionFactory.newLdapSession(new URI("https://{orchestrator_fqdn}:443/vco/api/"), "username", "password"); //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);