use of com.netflix.conductor.common.metadata.tasks.Task.Status.SCHEDULED in project conductor by Netflix.
the class AbstractWorkflowServiceTest method testSimpleWorkflowWithTaskSpecificDomain.
@Test
public void testSimpleWorkflowWithTaskSpecificDomain() throws Exception {
long startTimeTimestamp = System.currentTimeMillis();
clearWorkflows();
createWorkflowWithSubWorkflow();
metadataService.getWorkflowDef(LINEAR_WORKFLOW_T1_T2_SW, 1);
String correlationId = "unit_test_sw";
Map<String, Object> input = new HashMap<>();
String inputParam1 = "p1 value";
input.put("param1", inputParam1);
input.put("param2", "p2 value");
Map<String, String> taskToDomain = new HashMap<>();
taskToDomain.put("junit_task_3", "domain1");
taskToDomain.put("junit_task_2", "domain1");
// Poll before so that a polling for this task is "active"
Task task = workflowExecutionService.poll("junit_task_3", "task1.junit.worker", "domain1");
assertNull(task);
task = workflowExecutionService.poll("junit_task_2", "task1.junit.worker", "domain1");
assertNull(task);
String workflowId = startOrLoadWorkflowExecution("simpleWorkflowWithTaskSpecificDomain", LINEAR_WORKFLOW_T1_T2_SW, 1, correlationId, input, null, taskToDomain);
assertNotNull(workflowId);
Workflow workflow = workflowExecutor.getWorkflow(workflowId, false);
assertNotNull(workflow);
workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertNotNull(workflow);
assertEquals(workflow.getReasonForIncompletion(), RUNNING, workflow.getStatus());
assertEquals(RUNNING, workflow.getStatus());
// The very first task is the one that should be scheduled.
assertEquals(1, workflow.getTasks().size());
// Check Size
Map<String, Integer> sizes = workflowExecutionService.getTaskQueueSizes(Arrays.asList("domain1:junit_task_3", "junit_task_3"));
assertEquals(sizes.get("domain1:junit_task_3").intValue(), 1);
assertEquals(sizes.get("junit_task_3").intValue(), 0);
// Polling for the first task
task = workflowExecutionService.poll("junit_task_3", "task1.junit.worker");
assertNull(task);
task = workflowExecutionService.poll("junit_task_3", "task1.junit.worker", "domain1");
assertNotNull(task);
assertEquals("junit_task_3", task.getTaskType());
assertTrue(workflowExecutionService.ackTaskReceived(task.getTaskId()));
assertEquals(workflowId, task.getWorkflowInstanceId());
workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertNotNull(workflow);
List<Task> tasks = workflowExecutionService.getTasks(task.getTaskType(), null, 10);
assertNotNull(tasks);
assertEquals(1, tasks.size());
task = tasks.get(0);
assertEquals(workflowId, task.getWorkflowInstanceId());
String task1Op = "task1.Done";
task.getOutputData().put("op", task1Op);
task.setStatus(COMPLETED);
workflowExecutionService.updateTask(task);
workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertNotNull(workflow);
assertEquals(RUNNING, workflow.getStatus());
// Simulating SystemTaskWorkerCoordinator to execute async system tasks
String subWorkflowTaskId = workflow.getTaskByRefName("sw1").getTaskId();
workflowExecutor.executeSystemTask(dummySubWorkflowSystemTask, subWorkflowTaskId, 1);
task = workflowExecutionService.poll("junit_task_1", "task1.junit.worker");
assertNotNull(task);
assertEquals("junit_task_1", task.getTaskType());
workflow = workflowExecutionService.getExecutionStatus(workflowId, false);
assertTrue(workflowExecutionService.ackTaskReceived(task.getTaskId()));
assertNotNull(workflow.getTaskToDomain());
assertEquals(workflow.getTaskToDomain().size(), 2);
task.setStatus(COMPLETED);
task.setReasonForIncompletion("unit test failure");
workflowExecutionService.updateTask(task);
task = workflowExecutionService.poll("junit_task_2", "task2.junit.worker", "domain1");
assertNotNull(task);
assertEquals("junit_task_2", task.getTaskType());
assertTrue(workflowExecutionService.ackTaskReceived(task.getTaskId()));
task.setStatus(COMPLETED);
task.setReasonForIncompletion("unit test failure");
workflowExecutionService.updateTask(task);
// Execute again to re-evaluate the Subworkflow task.
workflowExecutor.executeSystemTask(dummySubWorkflowSystemTask, subWorkflowTaskId, 1);
workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertNotNull(workflow);
assertEquals(WorkflowStatus.COMPLETED, workflow.getStatus());
tasks = workflow.getTasks();
assertNotNull(tasks);
assertEquals(2, tasks.size());
assertTrue("Found " + workflow.getOutput().toString(), workflow.getOutput().containsKey("o3"));
assertEquals("task1.Done", workflow.getOutput().get("o3"));
Predicate<PollData> pollDataWithinTestTimes = pollData -> pollData.getLastPollTime() != 0 && pollData.getLastPollTime() > startTimeTimestamp;
List<PollData> pollData = workflowExecutionService.getPollData("junit_task_3").stream().filter(pollDataWithinTestTimes).collect(Collectors.toList());
assertEquals(2, pollData.size());
for (PollData pd : pollData) {
assertEquals(pd.getQueueName(), "junit_task_3");
assertEquals(pd.getWorkerId(), "task1.junit.worker");
assertTrue(pd.getLastPollTime() != 0);
if (pd.getDomain() != null) {
assertEquals(pd.getDomain(), "domain1");
}
}
List<PollData> pdList = workflowExecutionService.getAllPollData().stream().filter(pollDataWithinTestTimes).collect(Collectors.toList());
int count = 0;
for (PollData pd : pdList) {
if (pd.getQueueName().equals("junit_task_3")) {
count++;
}
}
assertEquals(2, count);
}
use of com.netflix.conductor.common.metadata.tasks.Task.Status.SCHEDULED in project conductor by Netflix.
the class AbstractWorkflowServiceTest method testSubWorkflowRetry.
@Test
public void testSubWorkflowRetry() {
String taskName = "junit_task_1";
TaskDef taskDef = notFoundSafeGetTaskDef(taskName);
int retryCount = notFoundSafeGetTaskDef(taskName).getRetryCount();
taskDef.setRetryCount(0);
metadataService.updateTaskDef(taskDef);
// create a workflow with sub-workflow
createSubWorkflow();
WorkflowDef found = metadataService.getWorkflowDef(WF_WITH_SUB_WF, 1);
WorkflowTask workflowTask = found.getTasks().stream().filter(t -> t.getType().equals(SUB_WORKFLOW.name())).findAny().orElse(null);
// Set subworkflow task retry count to 1.
TaskDef subWorkflowTaskDef = new TaskDef();
subWorkflowTaskDef.setRetryCount(1);
subWorkflowTaskDef.setName("test_subworkflow_task");
subWorkflowTaskDef.setOwnerEmail("test@qbc.com");
workflowTask.setTaskDefinition(subWorkflowTaskDef);
metadataService.updateWorkflowDef(found);
// start the workflow
Map<String, Object> workflowInputParams = new HashMap<>();
workflowInputParams.put("param1", "param 1");
workflowInputParams.put("param3", "param 2");
workflowInputParams.put("wfName", LINEAR_WORKFLOW_T1_T2);
String workflowId = startOrLoadWorkflowExecution(WF_WITH_SUB_WF, 1, "test", workflowInputParams, null, null);
assertNotNull(workflowId);
Workflow workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertNotNull(workflow);
// poll and complete first task
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());
assertEquals(2, workflow.getTasks().size());
task = workflow.getTasks().stream().filter(t -> t.getTaskType().equals(SUB_WORKFLOW.name())).findAny().orElse(null);
assertNotNull(task);
assertNotNull(task.getOutputData());
assertNotNull("Output: " + task.getOutputData().toString() + ", status: " + task.getStatus(), task.getSubWorkflowId());
String subWorkflowId = task.getSubWorkflowId();
workflow = workflowExecutionService.getExecutionStatus(subWorkflowId, true);
assertNotNull(workflow);
assertNotNull(workflow.getTasks());
assertEquals(workflowId, workflow.getParentWorkflowId());
assertEquals(RUNNING, workflow.getStatus());
// poll and fail the first task in sub-workflow
task = workflowExecutionService.poll("junit_task_1", "test");
task.setStatus(FAILED);
workflowExecutionService.updateTask(task);
Workflow subWorkflow = workflowExecutionService.getExecutionStatus(subWorkflowId, true);
assertNotNull(subWorkflow);
assertEquals(WorkflowStatus.FAILED, subWorkflow.getStatus());
subWorkflowTaskId = subWorkflow.getParentWorkflowTaskId();
workflowExecutor.executeSystemTask(subworkflow, subWorkflowTaskId, 1);
// Ensure failed Subworkflow task is rescheduled.
workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertNotNull(workflow);
assertEquals(RUNNING, workflow.getStatus());
task = workflow.getTasks().stream().filter(t -> t.getTaskType().equals(SUB_WORKFLOW.name())).filter(t -> t.getStatus().equals(SCHEDULED)).findAny().orElse(null);
assertNotNull(task);
subWorkflowTaskId = task.getTaskId();
workflowExecutor.executeSystemTask(subworkflow, task.getTaskId(), 1);
// Get the latest workflow and task, and then acquire latest subWorkflowId
workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertNotNull(workflow);
task = workflow.getTasks().stream().filter(t -> t.getTaskType().equals(SUB_WORKFLOW.name())).filter(t -> t.getStatus().equals(IN_PROGRESS)).findAny().orElse(null);
assertNotNull(task);
assertNotNull("Retried task in scheduled state shouldn't have a SubworkflowId yet", task.getSubWorkflowId());
subWorkflowId = task.getSubWorkflowId();
// poll and fail the first task in sub-workflow
task = workflowExecutionService.poll("junit_task_1", "test");
task.setStatus(FAILED);
workflowExecutionService.updateTask(task);
workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertNotNull(workflow);
assertEquals(WorkflowStatus.FAILED, workflow.getStatus());
// Retry the failed sub workflow
workflowExecutor.retry(subWorkflowId, false);
task = workflowExecutionService.poll("junit_task_1", "test");
task.setStatus(COMPLETED);
workflowExecutionService.updateTask(task);
subWorkflow = workflowExecutionService.getExecutionStatus(subWorkflowId, true);
assertNotNull(subWorkflow);
assertEquals(RUNNING, subWorkflow.getStatus());
task = workflowExecutionService.poll("junit_task_2", "test");
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"));
// Simulating SystemTaskWorkerCoordinator
workflowExecutor.executeSystemTask(subworkflow, subWorkflow.getParentWorkflowTaskId(), 1);
workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertNotNull(workflow);
assertEquals(RUNNING, workflow.getStatus());
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());
// reset retry count
taskDef = notFoundSafeGetTaskDef(taskName);
taskDef.setRetryCount(retryCount);
metadataService.updateTaskDef(taskDef);
workflowTask = found.getTasks().stream().filter(t -> t.getType().equals(SUB_WORKFLOW.name())).findAny().orElse(null);
workflowTask.setTaskDefinition(null);
metadataService.updateWorkflowDef(found);
}
use of com.netflix.conductor.common.metadata.tasks.Task.Status.SCHEDULED in project conductor by Netflix.
the class AbstractWorkflowServiceTest method testSimpleWorkflowWithOptionalTask.
@Test
public void testSimpleWorkflowWithOptionalTask() throws Exception {
createOptionalTaskWorkflow();
metadataService.getWorkflowDef(WORKFLOW_WITH_OPTIONAL_TASK, 1);
String correlationId = "unit_test_1";
Map<String, Object> workflowInput = new HashMap<>();
String inputParam1 = "p1 value";
workflowInput.put("param1", inputParam1);
workflowInput.put("param2", "p2 value");
String workflowId = startOrLoadWorkflowExecution(WORKFLOW_WITH_OPTIONAL_TASK, 1, correlationId, workflowInput, null, null);
logger.debug("testSimpleWorkflowWithOptionalTask.wfid=" + workflowId);
assertNotNull(workflowId);
Workflow workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertNotNull(workflow);
assertEquals(RUNNING, workflow.getStatus());
// The very first task is the one that should be scheduled.
assertEquals(1, workflow.getTasks().size());
assertEquals(1, queueDAO.getSize("task_optional"));
// Polling for the first task should return the first task
Task task = workflowExecutionService.poll("task_optional", "task1.junit.worker.optional");
assertNotNull(task);
assertEquals("task_optional", task.getTaskType());
assertTrue(workflowExecutionService.ackTaskReceived(task.getTaskId()));
assertEquals(workflowId, task.getWorkflowInstanceId());
// As the task_optional is out of the queue, the next poll should not get it
Task nullTask = workflowExecutionService.poll("task_optional", "task1.junit.worker.optional");
assertNull(nullTask);
TaskResult taskResult = new TaskResult(task);
taskResult.setReasonForIncompletion("NETWORK ERROR");
taskResult.setStatus(TaskResult.Status.FAILED);
workflowExecutionService.updateTask(taskResult);
workflowExecutor.decide(workflowId);
assertEquals(1, queueDAO.getSize("task_optional"));
// The first task would be failed and a new task will be scheduled
workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertNotNull(workflow);
assertEquals(RUNNING, workflow.getStatus());
assertEquals(2, workflow.getTasks().size());
assertTrue(workflow.getTasks().stream().allMatch(t -> t.getReferenceTaskName().equals("task_optional_t1")));
assertEquals(FAILED, workflow.getTasks().get(0).getStatus());
assertEquals(SCHEDULED, workflow.getTasks().get(1).getStatus());
// Polling now should get the same task back because it should have been put back in the queue
Task taskAgain = workflowExecutionService.poll("task_optional", "task1.junit.worker");
assertNotNull(taskAgain);
Thread.sleep(5000);
// The second task would be timed-out and completed with errors
workflowExecutor.decide(workflowId);
workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertNotNull(workflow);
assertEquals(0, queueDAO.getSize("task_optional"));
assertEquals(WorkflowStatus.RUNNING, workflow.getStatus());
System.out.println(workflow.getTasks());
System.out.println(workflow.getTasks().get(1));
System.out.println(workflow.getTasks().get(2));
assertEquals(3, workflow.getTasks().size());
assertEquals(COMPLETED_WITH_ERRORS, workflow.getTasks().get(1).getStatus());
// poll for next task
task = workflowExecutionService.poll("junit_task_2", "task2.junit.worker.testTimeout");
assertNotNull(task);
assertEquals("junit_task_2", task.getTaskType());
assertTrue(workflowExecutionService.ackTaskReceived(task.getTaskId()));
task.setStatus(COMPLETED);
task.setReasonForIncompletion("unit test failure");
workflowExecutionService.updateTask(task);
workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertNotNull(workflow);
assertEquals(WorkflowStatus.COMPLETED, workflow.getStatus());
}
Aggregations