use of com.netflix.conductor.common.metadata.workflow.WorkflowTask in project conductor by Netflix.
the class AbstractWorkflowServiceTest method testExecutionTimes.
@Test
public void testExecutionTimes() {
String taskName = "junit_task_1";
TaskDef taskDef = notFoundSafeGetTaskDef(taskName);
taskDef.setTimeoutSeconds(10);
metadataService.updateTaskDef(taskDef);
metadataService.registerTaskDef(Collections.singletonList(taskDef));
WorkflowDef workflowDef = new WorkflowDef();
workflowDef.setName("test_execution_times_wf");
workflowDef.setSchemaVersion(2);
WorkflowTask workflowTask1 = new WorkflowTask();
workflowTask1.setName("junit_task_1");
workflowTask1.setTaskReferenceName("task1");
WorkflowTask workflowTask2 = new WorkflowTask();
workflowTask2.setName("junit_task_1");
workflowTask2.setTaskReferenceName("task2");
WorkflowTask workflowTask3 = new WorkflowTask();
workflowTask3.setName("junit_task_1");
workflowTask3.setTaskReferenceName("task3");
WorkflowTask forkTask = new WorkflowTask();
forkTask.setType(TaskType.FORK_JOIN.name());
forkTask.setName("forktask1");
forkTask.setTaskReferenceName("forktask1");
forkTask.getForkTasks().add(Collections.singletonList(workflowTask2));
forkTask.getForkTasks().add(Collections.singletonList(workflowTask3));
WorkflowTask joinTask = new WorkflowTask();
joinTask.setType(TaskType.JOIN.name());
joinTask.setTaskReferenceName("jointask");
joinTask.setJoinOn(Arrays.asList("task2", "task3"));
Map<String, Object> decisionInputParameters = new HashMap<>();
decisionInputParameters.put("case", "a");
WorkflowTask decisionTask = new WorkflowTask();
decisionTask.setType(TaskType.DECISION.name());
decisionTask.setName("decision1");
decisionTask.setTaskReferenceName("decision1");
decisionTask.setInputParameters(decisionInputParameters);
decisionTask.setDefaultCase(Collections.singletonList(workflowTask1));
decisionTask.setCaseValueParam("case");
Map<String, List<WorkflowTask>> decisionCases = new HashMap<>();
decisionCases.put("a", Arrays.asList(forkTask, joinTask));
decisionTask.setDecisionCases(decisionCases);
workflowDef.getTasks().add(decisionTask);
assertNotNull(workflowDef);
metadataService.registerWorkflowDef(workflowDef);
Map workflowInput = Collections.emptyMap();
// noinspection unchecked
String workflowId = startOrLoadWorkflowExecution(workflowDef.getName(), workflowDef.getVersion(), "test", workflowInput, null, null);
Workflow workflow = workflowExecutor.getWorkflow(workflowId, true);
assertNotNull(workflow);
assertEquals(5, workflow.getTasks().size());
Task task = workflowExecutionService.poll("junit_task_1", "test");
assertNotNull(task);
task.setStatus(Status.COMPLETED);
workflowExecutionService.updateTask(task);
task = workflowExecutionService.poll("junit_task_1", "test");
assertNotNull(task);
task.setStatus(Status.COMPLETED);
workflowExecutionService.updateTask(task);
workflowExecutor.decide(workflowId);
workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertNotNull(workflow);
assertEquals(WorkflowStatus.COMPLETED, workflow.getStatus());
workflow.getTasks().forEach(workflowTask -> {
assertTrue(workflowTask.getScheduledTime() <= workflowTask.getStartTime());
assertTrue("" + (workflowTask.getStartTime() - workflowTask.getEndTime()), workflowTask.getStartTime() <= workflowTask.getEndTime());
});
assertEquals("decision1", workflow.getTasks().get(0).getReferenceTaskName());
assertEquals("forktask1", workflow.getTasks().get(1).getReferenceTaskName());
assertEquals("task2", workflow.getTasks().get(2).getReferenceTaskName());
assertEquals("task3", workflow.getTasks().get(3).getReferenceTaskName());
assertEquals("jointask", workflow.getTasks().get(4).getReferenceTaskName());
metadataService.unregisterWorkflowDef(workflowDef.getName(), 1);
}
use of com.netflix.conductor.common.metadata.workflow.WorkflowTask in project conductor by Netflix.
the class AbstractWorkflowServiceTest method testEventWorkflow.
@Test
public void testEventWorkflow() {
TaskDef taskDef = new TaskDef();
taskDef.setName("eventX");
taskDef.setTimeoutSeconds(1);
metadataService.registerTaskDef(Collections.singletonList(taskDef));
WorkflowDef workflowDef = new WorkflowDef();
workflowDef.setName("test_event");
workflowDef.setSchemaVersion(2);
WorkflowTask eventWorkflowTask = new WorkflowTask();
eventWorkflowTask.setWorkflowTaskType(TaskType.EVENT);
eventWorkflowTask.setName("eventX");
eventWorkflowTask.setTaskReferenceName("wait0");
eventWorkflowTask.setSink("conductor");
WorkflowTask workflowTask = new WorkflowTask();
workflowTask.setName("junit_task_1");
workflowTask.setTaskReferenceName("t1");
workflowDef.getTasks().add(eventWorkflowTask);
workflowDef.getTasks().add(workflowTask);
metadataService.registerWorkflowDef(workflowDef);
String workflowId = startOrLoadWorkflowExecution(workflowDef.getName(), workflowDef.getVersion(), "", new HashMap<>(), null, null);
Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
Workflow workflow = workflowExecutor.getWorkflow(workflowId, true);
assertNotNull(workflow);
Task eventTask = workflow.getTasks().get(0);
assertEquals(TaskType.EVENT.name(), eventTask.getTaskType());
assertEquals(COMPLETED, eventTask.getStatus());
assertFalse(eventTask.getOutputData().isEmpty());
assertNotNull(eventTask.getOutputData().get("event_produced"));
Task task = workflowExecutionService.poll("junit_task_1", "test");
assertNotNull(task);
task.setStatus(Status.COMPLETED);
workflowExecutionService.updateTask(task);
workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertNotNull(workflow);
assertEquals("tasks:" + workflow.getTasks(), WorkflowStatus.COMPLETED, workflow.getStatus());
}
use of com.netflix.conductor.common.metadata.workflow.WorkflowTask in project conductor by Netflix.
the class WorkflowServiceTest method createWorkflowWithInlineSubWorkflow.
private WorkflowDef createWorkflowWithInlineSubWorkflow() {
WorkflowDef subWorkflowDef = createInlineSubWorkflow();
WorkflowTask subWfTask = new WorkflowTask();
subWfTask.setName("subWorkflowTask");
subWfTask.setType(SUB_WORKFLOW.name());
SubWorkflowParams swp = new SubWorkflowParams();
swp.setName("does-not-existing-wf");
swp.setWorkflowDefinition(subWorkflowDef);
subWfTask.setSubWorkflowParam(swp);
Map<String, Object> inputParam = new HashMap<>();
inputParam.put("test", "test value");
inputParam.put("param1", "sub workflow input param1");
inputParam.put("param2", subWorkflowDef.getVersion());
subWfTask.setInputParameters(inputParam);
subWfTask.setTaskReferenceName("sw1");
WorkflowDef main = new WorkflowDef();
main.setVersion(2);
main.setSchemaVersion(2);
main.setInputParameters(Arrays.asList("param1", "param2"));
main.setName(WF_WITH_INLINE_SUB_WF);
main.getTasks().add(subWfTask);
return main;
}
use of com.netflix.conductor.common.metadata.workflow.WorkflowTask in project conductor by Netflix.
the class WorkflowServiceTest method createWorkflowWithInlineSubWorkflowWithInlineSubWorkflow.
private void createWorkflowWithInlineSubWorkflowWithInlineSubWorkflow() {
WorkflowDef subWorkflowDef = createWorkflowWithInlineSubWorkflow();
WorkflowTask workflowTask = new WorkflowTask();
workflowTask.setName("subWorkflowTask");
workflowTask.setType(SUB_WORKFLOW.name());
SubWorkflowParams swp = new SubWorkflowParams();
swp.setName("dummy-name");
swp.setWorkflowDef(subWorkflowDef);
workflowTask.setSubWorkflowParam(swp);
Map<String, Object> input = new HashMap<>();
input.put("test", "test value");
input.put("param1", "sub workflow task input param1");
input.put("param2", 21);
workflowTask.setInputParameters(input);
workflowTask.setTaskReferenceName("sw2");
WorkflowDef main = new WorkflowDef();
main.setSchemaVersion(2);
main.setInputParameters(Arrays.asList("param1", "param2"));
main.setName(WF_WITH_INLINE_SUB_WF_WITH_INLINE_SUB_WF);
main.getTasks().add(workflowTask);
Map<String, Object> outputParameters = new HashMap<>();
outputParameters.put("o1", "${workflow.input.param1}");
outputParameters.put("o2", "${sw2.output.o2}");
main.setOutputParameters(outputParameters);
metadataService.updateWorkflowDef(Collections.singletonList(main));
}
use of com.netflix.conductor.common.metadata.workflow.WorkflowTask in project conductor by Netflix.
the class WorkflowServiceTest method createInlineSubWorkflow.
private WorkflowDef createInlineSubWorkflow() {
// create inline subworkflow
WorkflowDef subWorkflowDef = new WorkflowDef();
subWorkflowDef.setName("inline_sw_1");
subWorkflowDef.setDescription(subWorkflowDef.getName());
subWorkflowDef.setVersion(3);
subWorkflowDef.setSchemaVersion(2);
Map<String, Object> outputParameters = new HashMap<>();
outputParameters.put("o1", "${workflow.input.param1}");
outputParameters.put("o2", "${isw_t1.output.uuid}");
subWorkflowDef.setOutputParameters(outputParameters);
WorkflowTask wft1 = new WorkflowTask();
wft1.setName("junit_task_1");
wft1.setTaskReferenceName("isw_t1");
subWorkflowDef.setTasks(Collections.singletonList(wft1));
return subWorkflowDef;
}
Aggregations