-
Notifications
You must be signed in to change notification settings - Fork 366
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1048 from nokia/mistral
Mistral: add task and action execution endpoints
- Loading branch information
Showing
20 changed files
with
938 additions
and
37 deletions.
There are no files selected for viewing
143 changes: 143 additions & 0 deletions
143
core-test/src/main/java/org/openstack4j/api/workflow/ActionExecutionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
package org.openstack4j.api.workflow; | ||
|
||
import org.openstack4j.model.common.ActionResponse; | ||
import org.openstack4j.model.workflow.ActionExecution; | ||
import org.openstack4j.model.workflow.State; | ||
import org.openstack4j.openstack.workflow.domain.MistralActionExecution; | ||
import org.testng.annotations.BeforeTest; | ||
import org.testng.annotations.Test; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import static org.testng.Assert.*; | ||
|
||
/** | ||
* Test cases for {@link ActionExecutionService}. | ||
* | ||
* @author Renat Akhmerov | ||
*/ | ||
@Test(suiteName="ActionExecutions") | ||
public class ActionExecutionTest extends WorkflowBaseTest { | ||
|
||
private static final String JSON_ACTION_EXEC = "/workflow/action_exec.json"; | ||
private static final String JSON_ACTION_EXECS = "/workflow/action_execs.json"; | ||
private static final String JSON_ACTION_EXEC_CREATE = "/workflow/action_exec_create.json"; | ||
|
||
private ActionExecutionService service; | ||
|
||
@BeforeTest | ||
public void setUp() { | ||
this.service = osv3().workflow().actionExecutions(); | ||
} | ||
|
||
@Test | ||
public void listActionExecutions() throws Exception { | ||
respondWith(JSON_ACTION_EXECS); | ||
|
||
List<? extends ActionExecution> actionExecs = service.list(); | ||
|
||
assertEquals(actionExecs.size(), 2); | ||
|
||
// Check first action execution. | ||
ActionExecution actionExec = actionExecs.get(0); | ||
|
||
assertNotNull(actionExec); | ||
assertIsUUID(actionExec.getId()); | ||
assertEquals(actionExec.getName(), "std.noop"); | ||
assertEquals(actionExec.getTaskName(), "task_1"); | ||
assertEquals(actionExec.getDescription(), ""); | ||
assertNotNull(actionExec.getCreatedAt()); | ||
assertNotNull(actionExec.getUpdatedAt()); | ||
assertEquals(actionExec.getWorkflowName(), "parallel_join_2"); | ||
assertEquals(actionExec.getTaskExecutionId(), "c40c26cb-f695-4f20-8455-c57ca5c0770a"); | ||
assertEquals(actionExec.getInput().size(), 1); | ||
assertEquals(actionExec.getInput().get("param1"), "val1"); | ||
assertEquals(actionExec.getOutput().size(), 1); | ||
assertNull(actionExec.getOutput().get("result")); | ||
assertEquals(actionExec.getState(), State.SUCCESS); | ||
assertNull(actionExec.getStateInfo()); | ||
assertTrue(actionExec.isAccepted()); | ||
|
||
// Check second action execution. | ||
actionExec = actionExecs.get(1); | ||
|
||
assertNotNull(actionExec); | ||
assertIsUUID(actionExec.getId()); | ||
assertEquals(actionExec.getName(), "std.noop"); | ||
assertEquals(actionExec.getTaskName(), "task_2"); | ||
assertEquals(actionExec.getDescription(), ""); | ||
assertNotNull(actionExec.getCreatedAt()); | ||
assertNotNull(actionExec.getUpdatedAt()); | ||
assertEquals(actionExec.getWorkflowName(), "parallel_join_2"); | ||
assertEquals(actionExec.getTaskExecutionId(), "c40c26cb-f695-4f20-8455-c57ca5c0770a"); | ||
assertEquals(actionExec.getInput().size(), 1); | ||
assertEquals(actionExec.getInput().get("param1"), "val1"); | ||
assertEquals(actionExec.getOutput().size(), 1); | ||
assertNull(actionExec.getOutput().get("result")); | ||
assertEquals(actionExec.getState(), State.ERROR); | ||
assertEquals(actionExec.getStateInfo(), "Some error info"); | ||
assertTrue(actionExec.isAccepted()); | ||
} | ||
|
||
@Test | ||
public void getActionExecution() throws Exception { | ||
respondWith(JSON_ACTION_EXEC); | ||
|
||
ActionExecution actionExec = service.get("294725fa-980d-436f-b882-a75cfeffa8c0"); | ||
|
||
assertNotNull(actionExec); | ||
assertIsUUID(actionExec.getId()); | ||
assertEquals(actionExec.getName(), "std.noop"); | ||
assertEquals(actionExec.getTaskName(), "task_1"); | ||
assertEquals(actionExec.getDescription(), ""); | ||
assertNotNull(actionExec.getCreatedAt()); | ||
assertNotNull(actionExec.getUpdatedAt()); | ||
assertEquals(actionExec.getWorkflowName(), "parallel_join_2"); | ||
assertEquals(actionExec.getTaskExecutionId(), "c40c26cb-f695-4f20-8455-c57ca5c0770a"); | ||
assertEquals(actionExec.getInput().size(), 1); | ||
assertEquals(actionExec.getInput().get("param1"), "val1"); | ||
assertEquals(actionExec.getOutput().size(), 1); | ||
assertNull(actionExec.getOutput().get("result")); | ||
assertEquals(actionExec.getState(), State.SUCCESS); | ||
assertNull(actionExec.getStateInfo()); | ||
assertTrue(actionExec.isAccepted()); | ||
} | ||
|
||
@Test | ||
public void createActionExecution() throws Exception { | ||
respondWith(JSON_ACTION_EXEC_CREATE); | ||
|
||
ActionExecution actionExec = new MistralActionExecution.MistralActionExecutionBuilder(). | ||
name("std.echo"). | ||
input(Collections.<String, Object>singletonMap("output", "Hello Mistral Java Client!")). | ||
build(); | ||
|
||
actionExec = service.create(actionExec); | ||
|
||
assertNotNull(actionExec); | ||
assertIsUUID(actionExec.getId()); | ||
assertEquals(actionExec.getName(), "std.noop"); | ||
assertEquals(actionExec.getTaskName(), "task_1"); | ||
assertEquals(actionExec.getDescription(), ""); | ||
assertNotNull(actionExec.getCreatedAt()); | ||
assertNotNull(actionExec.getUpdatedAt()); | ||
assertEquals(actionExec.getWorkflowName(), "parallel_join_2"); | ||
assertEquals(actionExec.getTaskExecutionId(), "c40c26cb-f695-4f20-8455-c57ca5c0770a"); | ||
assertEquals(actionExec.getInput().size(), 1); | ||
assertEquals(actionExec.getInput().get("param1"), "val1"); | ||
assertEquals(actionExec.getOutput().size(), 1); | ||
assertNull(actionExec.getOutput().get("result")); | ||
assertEquals(actionExec.getState(), State.SUCCESS); | ||
assertNull(actionExec.getStateInfo()); | ||
assertTrue(actionExec.isAccepted()); | ||
} | ||
|
||
@Test | ||
public void deleteActionExecution() throws Exception { | ||
respondWith(204); // No content. | ||
|
||
ActionResponse resp = service.delete("294725fa-980d-436f-b882-a75cfeffa8c0"); | ||
|
||
assertEquals(resp.getCode(), 204); | ||
}} |
106 changes: 106 additions & 0 deletions
106
core-test/src/main/java/org/openstack4j/api/workflow/TaskExecutionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package org.openstack4j.api.workflow; | ||
|
||
import org.openstack4j.model.workflow.State; | ||
import org.openstack4j.model.workflow.TaskExecution; | ||
import org.testng.annotations.BeforeTest; | ||
import org.testng.annotations.Test; | ||
|
||
import java.util.List; | ||
|
||
import static org.testng.Assert.*; | ||
|
||
/** | ||
* Test cases for {@link TaskExecutionService}. | ||
* | ||
* @author Renat Akhmerov | ||
*/ | ||
@Test(suiteName="TaskExecutions") | ||
public class TaskExecutionTest extends WorkflowBaseTest { | ||
|
||
private static final String JSON_TASK_EXEC = "/workflow/task_exec.json"; | ||
private static final String JSON_TASK_EXECS = "/workflow/task_execs.json"; | ||
|
||
private TaskExecutionService service; | ||
|
||
@BeforeTest | ||
public void setUp() { | ||
this.service = osv3().workflow().taskExecutions(); | ||
} | ||
|
||
@Test | ||
public void listTaskExecutions() throws Exception { | ||
respondWith(JSON_TASK_EXECS); | ||
|
||
List<? extends TaskExecution> taskExecs = service.list(); | ||
|
||
assertEquals(taskExecs.size(), 2); | ||
|
||
// Check first task execution. | ||
TaskExecution taskExec = taskExecs.get(0); | ||
|
||
assertNotNull(taskExec); | ||
assertIsUUID(taskExec.getId()); | ||
assertEquals(taskExec.getName(), "join_task"); | ||
assertEquals(taskExec.getType(), "ACTION"); | ||
assertNotNull(taskExec.getCreatedAt()); | ||
assertNotNull(taskExec.getUpdatedAt()); | ||
assertEquals(taskExec.getWorkflowName(), "parallel_join_2"); | ||
assertIsUUID(taskExec.getWorkflowDefinitionId()); | ||
assertIsUUID(taskExec.getWorkflowExecutionId()); | ||
assertEquals(taskExec.getState(), State.SUCCESS); | ||
assertNull(taskExec.getStateInfo()); | ||
assertEquals(taskExec.getRuntimeContext().size(), 1); | ||
assertEquals(taskExec.getRuntimeContext().get("retry_cnt"), 1); | ||
assertEquals(taskExec.getPublished().size(), 1); | ||
assertEquals(taskExec.getPublished().get("my_var"), "my_val"); | ||
assertEquals(taskExec.getResult(), "my task result"); | ||
assertTrue(taskExec.isProcessed()); | ||
|
||
// Check second task execution. | ||
taskExec = taskExecs.get(1); | ||
|
||
assertNotNull(taskExec); | ||
assertIsUUID(taskExec.getId()); | ||
assertEquals(taskExec.getName(), "task1"); | ||
assertEquals(taskExec.getType(), "WORKFLOW"); | ||
assertNotNull(taskExec.getCreatedAt()); | ||
assertNotNull(taskExec.getUpdatedAt()); | ||
assertEquals(taskExec.getWorkflowName(), "parallel_join_2"); | ||
assertIsUUID(taskExec.getWorkflowDefinitionId()); | ||
assertIsUUID(taskExec.getWorkflowExecutionId()); | ||
assertEquals(taskExec.getState(), State.ERROR); | ||
assertEquals(taskExec.getStateInfo(), "Some error info"); | ||
assertEquals(taskExec.getRuntimeContext().size(), 1); | ||
assertEquals(taskExec.getRuntimeContext().get("retry_cnt"), 1); | ||
assertEquals(taskExec.getPublished().size(), 1); | ||
assertEquals(taskExec.getPublished().get("my_var"), "my_val"); | ||
assertEquals(taskExec.getResult(), "my task result"); | ||
assertFalse(taskExec.isProcessed()); | ||
|
||
} | ||
|
||
@Test | ||
public void getTaskExecution() throws Exception { | ||
respondWith(JSON_TASK_EXEC); | ||
|
||
TaskExecution taskExec = service.get("6e7cce36-1ab2-45c8-baf5-88d5d726ea1d"); | ||
|
||
assertNotNull(taskExec); | ||
assertIsUUID(taskExec.getId()); | ||
assertEquals(taskExec.getName(), "join_task"); | ||
assertEquals(taskExec.getType(), "ACTION"); | ||
assertNotNull(taskExec.getCreatedAt()); | ||
assertNotNull(taskExec.getUpdatedAt()); | ||
assertEquals(taskExec.getWorkflowName(), "parallel_join_2"); | ||
assertIsUUID(taskExec.getWorkflowDefinitionId()); | ||
assertIsUUID(taskExec.getWorkflowExecutionId()); | ||
assertEquals(taskExec.getState(), State.SUCCESS); | ||
assertNull(taskExec.getStateInfo()); | ||
assertEquals(taskExec.getRuntimeContext().size(), 1); | ||
assertEquals(taskExec.getRuntimeContext().get("retry_cnt"), 1); | ||
assertEquals(taskExec.getPublished().size(), 1); | ||
assertEquals(taskExec.getPublished().get("my_var"), "my_val"); | ||
assertEquals(taskExec.getResult(), "my task result"); | ||
assertTrue(taskExec.isProcessed()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"id": "294725fa-980d-436f-b882-a75cfeffa8c0", | ||
"name": "std.noop", | ||
"task_name": "task_1", | ||
"description": "", | ||
"created_at": "2016-08-17 10:34:00", | ||
"updated_at": "2016-08-17 10:34:01", | ||
"workflow_name": "parallel_join_2", | ||
"task_execution_id": "c40c26cb-f695-4f20-8455-c57ca5c0770a", | ||
"tags": null, | ||
"input": { | ||
"param1": "val1" | ||
}, | ||
"output": { | ||
"result": null | ||
}, | ||
"state": "SUCCESS", | ||
"state_info": null, | ||
"accepted": true | ||
} |
20 changes: 20 additions & 0 deletions
20
core-test/src/main/resources/workflow/action_exec_create.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"id": "294725fa-980d-436f-b882-a75cfeffa8c0", | ||
"name": "std.noop", | ||
"task_name": "task_1", | ||
"description": "", | ||
"created_at": "2016-08-17 10:34:00", | ||
"updated_at": "2016-08-17 10:34:01", | ||
"workflow_name": "parallel_join_2", | ||
"task_execution_id": "c40c26cb-f695-4f20-8455-c57ca5c0770a", | ||
"tags": null, | ||
"input": { | ||
"param1": "val1" | ||
}, | ||
"output": { | ||
"result": null | ||
}, | ||
"state": "SUCCESS", | ||
"state_info": null, | ||
"accepted": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"action_executions": [ | ||
{ | ||
"id": "294725fa-980d-436f-b882-a75cfeffa8c0", | ||
"name": "std.noop", | ||
"task_name": "task_1", | ||
"description": "", | ||
"created_at": "2016-08-17 10:34:00", | ||
"updated_at": "2016-08-17 10:34:01", | ||
"workflow_name": "parallel_join_2", | ||
"task_execution_id": "c40c26cb-f695-4f20-8455-c57ca5c0770a", | ||
"tags": null, | ||
"input": { | ||
"param1": "val1" | ||
}, | ||
"output": { | ||
"result": null | ||
}, | ||
"state": "SUCCESS", | ||
"state_info": null, | ||
"accepted": true | ||
}, | ||
{ | ||
"id": "294725fa-980d-436f-b882-a75cfeffa8c0", | ||
"name": "std.noop", | ||
"task_name": "task_2", | ||
"description": "", | ||
"created_at": "2016-08-17 10:34:00", | ||
"updated_at": "2016-08-17 10:34:01", | ||
"workflow_name": "parallel_join_2", | ||
"task_execution_id": "c40c26cb-f695-4f20-8455-c57ca5c0770a", | ||
"tags": null, | ||
"input": { | ||
"param1": "val1" | ||
}, | ||
"output": { | ||
"result": null | ||
}, | ||
"state": "ERROR", | ||
"state_info": "Some error info", | ||
"accepted": true | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"id": "6e7cce36-1ab2-45c8-baf5-88d5d726ea1d", | ||
"name": "join_task", | ||
"type": "ACTION", | ||
"created_at": "2016-08-17 10:34:02", | ||
"updated_at": "2016-08-17 10:34:04", | ||
"workflow_name": "parallel_join_2", | ||
"workflow_id": "0169affc-e6a1-4013-a59e-c89dfd5523f2", | ||
"workflow_execution_id": "79d187f4-b8e5-4288-b2cd-ed27ee31e4b0", | ||
"state": "SUCCESS", | ||
"state_info": null, | ||
"runtime_context": {"retry_cnt": 1}, | ||
"published": {"my_var": "my_val"}, | ||
"result": "my task result", | ||
"processed": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"tasks": [ | ||
{ | ||
"id": "6e7cce36-1ab2-45c8-baf5-88d5d726ea1d", | ||
"name": "join_task", | ||
"type": "ACTION", | ||
"created_at": "2016-08-17 10:34:02", | ||
"updated_at": "2016-08-17 10:34:04", | ||
"workflow_name": "parallel_join_2", | ||
"workflow_id": "0169affc-e6a1-4013-a59e-c89dfd5523f2", | ||
"workflow_execution_id": "79d187f4-b8e5-4288-b2cd-ed27ee31e4b0", | ||
"state": "SUCCESS", | ||
"state_info": null, | ||
"runtime_context": {"retry_cnt": 1}, | ||
"published": {"my_var": "my_val"}, | ||
"result": "my task result", | ||
"processed": true | ||
}, | ||
{ | ||
"id": "6e7cce36-1ab2-45c8-baf5-88d5d726ea1d", | ||
"name": "task1", | ||
"type": "WORKFLOW", | ||
"created_at": "2016-08-17 10:34:02", | ||
"updated_at": "2016-08-17 10:34:04", | ||
"workflow_name": "parallel_join_2", | ||
"workflow_id": "0169affc-e6a1-4013-a59e-c89dfd5523f2", | ||
"workflow_execution_id": "79d187f4-b8e5-4288-b2cd-ed27ee31e4b0", | ||
"state": "ERROR", | ||
"state_info": "Some error info", | ||
"runtime_context": {"retry_cnt": 1}, | ||
"published": {"my_var": "my_val"}, | ||
"result": "my task result", | ||
"processed": false | ||
} | ||
] | ||
} |
Oops, something went wrong.