您可使用 Java SDK 程式庫直接呼叫 Orchestrator REST API 上含物件的 Java 應用程式與工作作業。

Orchestrator REST SDK 的每項 RESTful 網路服務都擁有對應作業方法的換行 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);