use of com.netflix.conductor.common.run.Workflow.WorkflowStatus.RUNNING in project conductor by Netflix.
the class AbstractWorkflowServiceTest method testSubWorkflowFailure.
@Test
public void testSubWorkflowFailure() {
TaskDef taskDef = notFoundSafeGetTaskDef("junit_task_1");
assertNotNull(taskDef);
taskDef.setRetryCount(0);
taskDef.setTimeoutSeconds(2);
metadataService.updateTaskDef(taskDef);
createSubWorkflow();
metadataService.getWorkflowDef(WF_WITH_SUB_WF, 1);
Map<String, Object> input = new HashMap<>();
input.put("param1", "param 1 value");
input.put("param3", "param 2 value");
input.put("wfName", LINEAR_WORKFLOW_T1_T2);
String workflowId = startOrLoadWorkflowExecution(WF_WITH_SUB_WF, 1, "test", input, null, null);
assertNotNull(workflowId);
Workflow workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertNotNull(workflow);
Task task = workflowExecutionService.poll("junit_task_5", "test");
assertNotNull(task);
task.setStatus(COMPLETED);
workflowExecutionService.updateTask(task);
workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
// Simulating SystemTaskWorkerCoordinator to execute async system tasks
String subWorkflowTaskId = workflow.getTaskByRefName("a2").getTaskId();
workflowExecutor.executeSystemTask(dummySubWorkflowSystemTask, subWorkflowTaskId, 1);
workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertNotNull(workflow);
assertNotNull(workflow.getTasks());
task = workflow.getTasks().stream().filter(t -> t.getTaskType().equals(SUB_WORKFLOW.name())).findAny().get();
assertNotNull(task);
assertNotNull(task.getOutputData());
assertNotNull(task.getSubWorkflowId());
String subWorkflowId = task.getSubWorkflowId();
Workflow subWorkflow = workflowExecutionService.getExecutionStatus(subWorkflowId, true);
assertNotNull(subWorkflow);
assertNotNull(subWorkflow.getTasks());
assertEquals(workflowId, subWorkflow.getParentWorkflowId());
assertEquals(RUNNING, subWorkflow.getStatus());
task = workflowExecutionService.poll("junit_task_1", "test");
assertNotNull(task);
task.setStatus(FAILED);
workflowExecutionService.updateTask(task);
subWorkflow = workflowExecutionService.getExecutionStatus(subWorkflowId, true);
assertNotNull(subWorkflow);
assertEquals(WorkflowStatus.FAILED, subWorkflow.getStatus());
workflowExecutor.executeSystemTask(subworkflow, subWorkflow.getParentWorkflowTaskId(), 1);
workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertEquals(WorkflowStatus.FAILED, workflow.getStatus());
task = workflow.getTasks().stream().filter(t -> t.getTaskType().equals(SUB_WORKFLOW.name())).findAny().get();
assertEquals(FAILED, task.getStatus());
}
use of com.netflix.conductor.common.run.Workflow.WorkflowStatus.RUNNING in project conductor by Netflix.
the class AbstractWorkflowServiceTest method testSubWorkflowFailureInverse.
@Test
public void testSubWorkflowFailureInverse() {
TaskDef taskDef = notFoundSafeGetTaskDef("junit_task_1");
assertNotNull(taskDef);
taskDef.setRetryCount(0);
taskDef.setTimeoutSeconds(2);
metadataService.updateTaskDef(taskDef);
createSubWorkflow();
WorkflowDef found = metadataService.getWorkflowDef(WF_WITH_SUB_WF, 1);
assertNotNull(found);
Map<String, Object> input = new HashMap<>();
input.put("param1", "param 1 value");
input.put("param3", "param 2 value");
input.put("wfName", LINEAR_WORKFLOW_T1_T2);
String workflowId = startOrLoadWorkflowExecution(WF_WITH_SUB_WF, 1, "test", input, null, null);
assertNotNull(workflowId);
Workflow workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertNotNull(workflow);
Task task = workflowExecutionService.poll("junit_task_5", "test");
assertNotNull(task);
task.setStatus(COMPLETED);
workflowExecutionService.updateTask(task);
workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
// Simulating SystemTaskWorkerCoordinator to execute async system tasks
String subWorkflowTaskId = workflow.getTaskByRefName("a2").getTaskId();
workflowExecutor.executeSystemTask(dummySubWorkflowSystemTask, subWorkflowTaskId, 1);
workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertNotNull(workflow);
assertNotNull(workflow.getTasks());
task = workflow.getTasks().stream().filter(t -> t.getTaskType().equals(SUB_WORKFLOW.name())).findAny().get();
assertNotNull(task);
assertNotNull(task.getOutputData());
assertNotNull(task.getSubWorkflowId());
String subWorkflowId = task.getSubWorkflowId();
workflow = workflowExecutionService.getExecutionStatus(subWorkflowId, true);
assertNotNull(workflow);
assertNotNull(workflow.getTasks());
assertEquals(workflowId, workflow.getParentWorkflowId());
assertEquals(RUNNING, workflow.getStatus());
workflowExecutor.terminateWorkflow(workflowId, "fail");
workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertEquals(WorkflowStatus.TERMINATED, workflow.getStatus());
workflow = workflowExecutionService.getExecutionStatus(subWorkflowId, true);
assertEquals(WorkflowStatus.TERMINATED, workflow.getStatus());
}
use of com.netflix.conductor.common.run.Workflow.WorkflowStatus.RUNNING in project conductor by Netflix.
the class AbstractWorkflowServiceTest method testForkJoinNestedWithSubWorkflow.
@Test
public void testForkJoinNestedWithSubWorkflow() {
createForkJoinNestedWorkflowWithSubworkflow(1);
Map<String, Object> input = new HashMap<>();
// This should execute t16 and t19
input.put("case", "a");
String wfid = startOrLoadWorkflowExecution(FORK_JOIN_NESTED_WF, 1, "fork_join_nested_test", input, null, null);
System.out.println("testForkJoinNested.wfid=" + wfid);
Workflow workflow = workflowExecutionService.getExecutionStatus(wfid, true);
assertNotNull(workflow);
assertEquals(RUNNING, workflow.getStatus());
assertTrue(workflow.getTasks().stream().anyMatch(t -> t.getReferenceTaskName().equals("t11")));
assertTrue(workflow.getTasks().stream().anyMatch(t -> t.getReferenceTaskName().equals("t12")));
assertTrue(workflow.getTasks().stream().anyMatch(t -> t.getReferenceTaskName().equals("t13")));
assertTrue(workflow.getTasks().stream().anyMatch(t -> t.getReferenceTaskName().equals("sw1")));
assertTrue(workflow.getTasks().stream().anyMatch(t -> t.getReferenceTaskName().equals("fork1")));
assertTrue(workflow.getTasks().stream().anyMatch(t -> t.getReferenceTaskName().equals("fork2")));
assertFalse(workflow.getTasks().stream().anyMatch(t -> t.getReferenceTaskName().equals("t16")));
assertFalse(workflow.getTasks().stream().anyMatch(t -> t.getReferenceTaskName().equals("t1")));
assertFalse(workflow.getTasks().stream().anyMatch(t -> t.getReferenceTaskName().equals("t2")));
Task t1 = workflowExecutionService.poll("junit_task_11", "test");
assertTrue(workflowExecutionService.ackTaskReceived(t1.getTaskId()));
Task t2 = workflowExecutionService.poll("junit_task_12", "test");
assertTrue(workflowExecutionService.ackTaskReceived(t2.getTaskId()));
Task t3 = workflowExecutionService.poll("junit_task_13", "test");
assertTrue(workflowExecutionService.ackTaskReceived(t3.getTaskId()));
assertNotNull(t1);
assertNotNull(t2);
assertNotNull(t3);
t1.setStatus(COMPLETED);
t2.setStatus(COMPLETED);
t3.setStatus(COMPLETED);
workflowExecutionService.updateTask(t1);
workflowExecutionService.updateTask(t2);
workflowExecutionService.updateTask(t3);
Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
// Simulating SystemTaskWorkerCoordinator to execute async system tasks
String subWorkflowTaskId = workflow.getTaskByRefName("sw1").getTaskId();
workflowExecutor.executeSystemTask(dummySubWorkflowSystemTask, subWorkflowTaskId, 1);
workflow = workflowExecutionService.getExecutionStatus(wfid, true);
assertTrue(workflow.getTasks().stream().anyMatch(t -> t.getReferenceTaskName().equals("t16")));
assertTrue(workflow.getTasks().stream().anyMatch(t -> t.getReferenceTaskName().equals("t14")));
String[] tasks = new String[] { "junit_task_1", "junit_task_2", "junit_task_14", "junit_task_16" };
for (String tt : tasks) {
Task polled = workflowExecutionService.poll(tt, "test");
assertNotNull("poll resulted empty for task: " + tt, polled);
polled.setStatus(COMPLETED);
workflowExecutionService.updateTask(polled);
}
// Execute again to complete the Subworkflow task.
workflowExecutor.executeSystemTask(dummySubWorkflowSystemTask, subWorkflowTaskId, 1);
workflow = workflowExecutionService.getExecutionStatus(wfid, true);
assertNotNull(workflow);
assertEquals(RUNNING, workflow.getStatus());
assertTrue(workflow.getTasks().stream().anyMatch(t -> t.getReferenceTaskName().equals("t19")));
// Not there yet
assertFalse(workflow.getTasks().stream().anyMatch(t -> t.getReferenceTaskName().equals("t15")));
// Not there yet
assertFalse(workflow.getTasks().stream().anyMatch(t -> t.getReferenceTaskName().equals("t20")));
Task task19 = workflowExecutionService.poll("junit_task_19", "test");
assertNotNull(task19);
task19.setStatus(COMPLETED);
workflowExecutionService.updateTask(task19);
Task task20 = workflowExecutionService.poll("junit_task_20", "test");
assertNotNull(task20);
task20.setStatus(COMPLETED);
workflowExecutionService.updateTask(task20);
Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
workflow = workflowExecutionService.getExecutionStatus(wfid, true);
assertNotNull(workflow);
assertEquals(RUNNING, workflow.getStatus());
Set<String> pendingTasks = workflow.getTasks().stream().filter(t -> !t.getStatus().isTerminal()).map(t -> t.getReferenceTaskName()).collect(Collectors.toSet());
assertTrue("Found only this: " + pendingTasks, workflow.getTasks().stream().anyMatch(t -> t.getReferenceTaskName().equals("join1")));
pendingTasks = workflow.getTasks().stream().filter(t -> !t.getStatus().isTerminal()).map(t -> t.getReferenceTaskName()).collect(Collectors.toSet());
assertTrue("Found only this: " + pendingTasks, workflow.getTasks().stream().anyMatch(t -> t.getReferenceTaskName().equals("t15")));
Task task15 = workflowExecutionService.poll("junit_task_15", "test");
assertNotNull(task15);
task15.setStatus(COMPLETED);
workflowExecutionService.updateTask(task15);
workflow = workflowExecutionService.getExecutionStatus(wfid, true);
assertNotNull(workflow);
assertEquals(WorkflowStatus.COMPLETED, workflow.getStatus());
}
use of com.netflix.conductor.common.run.Workflow.WorkflowStatus.RUNNING in project conductor by Netflix.
the class AbstractWorkflowServiceTest method testSubWorkflowTaskToDomain.
@Test
public void testSubWorkflowTaskToDomain() {
Map<String, String> taskToDomain = new HashMap<>();
taskToDomain.put("junit_task_1", "unittest1");
taskToDomain.put("junit_task_2", "unittest2");
createSubWorkflow(taskToDomain);
metadataService.getWorkflowDef(WF_WITH_SUB_WF, 1);
Map<String, Object> input = new HashMap<>();
input.put("param1", "param 1 value");
input.put("param3", "param 2 value");
input.put("wfName", LINEAR_WORKFLOW_T1_T2);
String workflowId = startOrLoadWorkflowExecution(WF_WITH_SUB_WF, 1, "test", input, null, null);
assertNotNull(workflowId);
Workflow workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertNotNull(workflow);
Task task = workflowExecutionService.poll("junit_task_5", "test");
assertNotNull(task);
task.setStatus(COMPLETED);
workflowExecutionService.updateTask(task);
Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertNotNull(workflow);
assertNotNull(workflow.getTasks());
// Simulating SystemTaskWorkerCoordinator to execute async system tasks
String subWorkflowTaskId = workflow.getTaskByRefName("a2").getTaskId();
workflowExecutor.executeSystemTask(dummySubWorkflowSystemTask, subWorkflowTaskId, 1);
workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
task = workflow.getTasks().stream().filter(t -> t.getTaskType().equals(SUB_WORKFLOW.name())).findAny().get();
assertNotNull(task);
assertNotNull(task.getOutputData());
assertNotNull("Output: " + task.getOutputData().toString() + ", status: " + task.getStatus(), task.getSubWorkflowId());
assertNotNull(task.getInputData());
assertTrue(task.getInputData().containsKey("workflowInput"));
assertEquals(42, ((Map<String, Object>) task.getInputData().get("workflowInput")).get("param2"));
String subWorkflowId = task.getSubWorkflowId();
Workflow subWorkflow = workflowExecutionService.getExecutionStatus(subWorkflowId, true);
assertNotNull(subWorkflow);
assertNotNull(subWorkflow.getTasks());
assertEquals(workflowId, subWorkflow.getParentWorkflowId());
assertEquals(RUNNING, subWorkflow.getStatus());
task = workflowExecutionService.poll("junit_task_1", "test", "unittest1");
task.setStatus(COMPLETED);
workflowExecutionService.updateTask(task);
task = workflowExecutionService.poll("junit_task_2", "test", "unittest2");
assertEquals(subWorkflowId, task.getWorkflowInstanceId());
String uuid = UUID.randomUUID().toString();
task.getOutputData().put("uuid", uuid);
task.setStatus(COMPLETED);
workflowExecutionService.updateTask(task);
subWorkflow = workflowExecutionService.getExecutionStatus(subWorkflowId, true);
assertNotNull(subWorkflow);
assertEquals(WorkflowStatus.COMPLETED, subWorkflow.getStatus());
assertNotNull(subWorkflow.getOutput());
assertTrue(subWorkflow.getOutput().containsKey("o1"));
assertTrue(subWorkflow.getOutput().containsKey("o2"));
assertEquals("sub workflow input param1", subWorkflow.getOutput().get("o1"));
assertEquals(uuid, subWorkflow.getOutput().get("o2"));
assertEquals(taskToDomain, subWorkflow.getTaskToDomain());
// Execute again to re-evaluate the Subworkflow task.
workflowExecutor.executeSystemTask(dummySubWorkflowSystemTask, subWorkflowTaskId, 1);
task = workflowExecutionService.poll("junit_task_6", "test");
assertNotNull(task);
task.setStatus(COMPLETED);
workflowExecutionService.updateTask(task);
workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertNotNull(workflow);
assertEquals(WorkflowStatus.COMPLETED, workflow.getStatus());
}
use of com.netflix.conductor.common.run.Workflow.WorkflowStatus.RUNNING in project conductor by Netflix.
the class AbstractWorkflowServiceTest method clearWorkflows.
@After
public void clearWorkflows() throws Exception {
List<String> workflowsWithVersion = metadataService.getWorkflowDefs().stream().map(def -> def.getName() + ":" + def.getVersion()).collect(Collectors.toList());
for (String workflowWithVersion : workflowsWithVersion) {
String workflowName = StringUtils.substringBefore(workflowWithVersion, ":");
int version = Integer.parseInt(StringUtils.substringAfter(workflowWithVersion, ":"));
List<String> running = workflowExecutionService.getRunningWorkflows(workflowName, version);
for (String wfid : running) {
Workflow workflow = workflowExecutor.getWorkflow(wfid, false);
if (!workflow.getStatus().isTerminal()) {
workflowExecutor.terminateWorkflow(wfid, "cleanup");
}
}
}
queueDAO.queuesDetail().keySet().forEach(queueDAO::flush);
new FileOutputStream(this.getClass().getResource(TEMP_FILE_PATH).getPath()).close();
}
Aggregations