您可以使用 Java SDK 库在 Java 应用程序中的 Orchestrator REST API 上调用操作,并直接使用对象。

Orchestrator REST SDK 的每项 RESTful Web 服务都具有封装 Java 类以及使用该服务时可运行的操作对应的方法。

Java REST SDK 随 Orchestrator 一同安装。Java REST SDK 项目可在以下位置找到。

注:

仅当部署 Orchestrator Appliance 后,您才能访问项目。

  • https://orchestrator_host:port/vco-repo/com/vmware/o11n/o11n-rest-client/

  • https://orchestrator_host:port/vco-repo/com/vmware/o11n/o11n-rest-client-examples/

  • https://orchestrator_host:port/vco-repo/com/vmware/o11n/o11n-rest-client-services/

  • https://orchestrator_host:port/vco-repo/com/vmware/o11n/o11n-rest-client-stubs/

运行工作流并等待其完成

以下示例代码运行了工作流并等待其完成。

//start a new session to Orchestrator by using specified credentials
VcoSession session = DefaultVcoSessionFactory.newLdapSession(new URI("https://orchestrator-server:8281/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);