Search in sources :

Example 6 with RUNNING

use of com.netflix.conductor.common.run.Workflow.WorkflowStatus.RUNNING 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);
}
Also used : TaskUtils(com.netflix.conductor.common.utils.TaskUtils) MethodSorters(org.junit.runners.MethodSorters) SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) Arrays(java.util.Arrays) TimeoutPolicy(com.netflix.conductor.common.metadata.tasks.TaskDef.TimeoutPolicy) TEMP_FILE_PATH(com.netflix.conductor.tests.utils.MockExternalPayloadStorage.TEMP_FILE_PATH) LoggerFactory(org.slf4j.LoggerFactory) Task(com.netflix.conductor.common.metadata.tasks.Task) StringUtils(org.apache.commons.lang3.StringUtils) Future(java.util.concurrent.Future) COMPLETED_WITH_ERRORS(com.netflix.conductor.common.metadata.tasks.Task.Status.COMPLETED_WITH_ERRORS) RerunWorkflowRequest(com.netflix.conductor.common.metadata.workflow.RerunWorkflowRequest) Workflow(com.netflix.conductor.common.run.Workflow) IN_PROGRESS(com.netflix.conductor.common.metadata.tasks.Task.Status.IN_PROGRESS) Map(java.util.Map) After(org.junit.After) PollData(com.netflix.conductor.common.metadata.tasks.PollData) WorkflowExecutor(com.netflix.conductor.core.execution.WorkflowExecutor) TASK_OUTPUT_PATH(com.netflix.conductor.tests.utils.MockExternalPayloadStorage.TASK_OUTPUT_PATH) Terminate(com.netflix.conductor.core.execution.tasks.Terminate) WorkflowRepairService(com.netflix.conductor.core.execution.WorkflowRepairService) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) WorkflowStatus(com.netflix.conductor.common.run.Workflow.WorkflowStatus) MetadataMapperService(com.netflix.conductor.core.metadata.MetadataMapperService) Predicate(java.util.function.Predicate) Set(java.util.Set) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Executors(java.util.concurrent.Executors) SCHEDULED(com.netflix.conductor.common.metadata.tasks.Task.Status.SCHEDULED) QueueDAO(com.netflix.conductor.dao.QueueDAO) INPUT_PAYLOAD_PATH(com.netflix.conductor.tests.utils.MockExternalPayloadStorage.INPUT_PAYLOAD_PATH) List(java.util.List) DynamicForkJoinTaskList(com.netflix.conductor.common.metadata.workflow.DynamicForkJoinTaskList) Assert.assertFalse(org.junit.Assert.assertFalse) TIMED_OUT(com.netflix.conductor.common.metadata.tasks.Task.Status.TIMED_OUT) COMPLETED(com.netflix.conductor.common.metadata.tasks.Task.Status.COMPLETED) ExecutionService(com.netflix.conductor.service.ExecutionService) FixMethodOrder(org.junit.FixMethodOrder) JsonMapperProvider(com.netflix.conductor.common.utils.JsonMapperProvider) MetadataService(com.netflix.conductor.service.MetadataService) WorkflowContext(com.netflix.conductor.core.WorkflowContext) BeforeClass(org.junit.BeforeClass) SubWorkflowParams(com.netflix.conductor.common.metadata.workflow.SubWorkflowParams) Status(com.netflix.conductor.common.metadata.tasks.Task.Status) HashMap(java.util.HashMap) TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult) Inject(javax.inject.Inject) SUB_WORKFLOW(com.netflix.conductor.common.metadata.workflow.TaskType.SUB_WORKFLOW) LinkedList(java.util.LinkedList) ExpectedException(org.junit.rules.ExpectedException) RUNNING(com.netflix.conductor.common.run.Workflow.WorkflowStatus.RUNNING) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) TERMINATED(com.netflix.conductor.common.run.Workflow.WorkflowStatus.TERMINATED) INITIAL_WORKFLOW_INPUT_PATH(com.netflix.conductor.tests.utils.MockExternalPayloadStorage.INITIAL_WORKFLOW_INPUT_PATH) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) Logger(org.slf4j.Logger) WorkflowSweeper(com.netflix.conductor.core.execution.WorkflowSweeper) Assert.assertNotNull(org.junit.Assert.assertNotNull) UserTask(com.netflix.conductor.tests.utils.UserTask) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Assert.assertTrue(org.junit.Assert.assertTrue) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) FileOutputStream(java.io.FileOutputStream) Test(org.junit.Test) FAILED(com.netflix.conductor.common.metadata.tasks.Task.Status.FAILED) WORKFLOW_OUTPUT_PATH(com.netflix.conductor.tests.utils.MockExternalPayloadStorage.WORKFLOW_OUTPUT_PATH) TimeUnit(java.util.concurrent.TimeUnit) DECISION(com.netflix.conductor.common.metadata.workflow.TaskType.DECISION) Assert.assertNull(org.junit.Assert.assertNull) Rule(org.junit.Rule) Ignore(org.junit.Ignore) RetryLogic(com.netflix.conductor.common.metadata.tasks.TaskDef.RetryLogic) TaskType(com.netflix.conductor.common.metadata.workflow.TaskType) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) UserTask(com.netflix.conductor.tests.utils.UserTask) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) HashMap(java.util.HashMap) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) Workflow(com.netflix.conductor.common.run.Workflow) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Test(org.junit.Test)

Example 7 with RUNNING

use of com.netflix.conductor.common.run.Workflow.WorkflowStatus.RUNNING in project conductor by Netflix.

the class AbstractWorkflowServiceTest method testSubWorkflowRetryLastFailedTask.

@Test
public void testSubWorkflowRetryLastFailedTask() {
    String taskName = "junit_task_2";
    TaskDef taskDef = notFoundSafeGetTaskDef(taskName);
    int retryCount = notFoundSafeGetTaskDef(taskName).getRetryCount();
    taskDef.setRetryCount(0);
    metadataService.updateTaskDef(taskDef);
    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);
    TaskDef subWorkflowTaskDef = new TaskDef();
    subWorkflowTaskDef.setRetryCount(0);
    subWorkflowTaskDef.setName("test_subworkflow_task");
    subWorkflowTaskDef.setOwnerEmail("test@qbc.com");
    workflowTask.setTaskDefinition(subWorkflowTaskDef);
    metadataService.updateWorkflowDef(found);
    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);
    Task task = workflowExecutionService.poll("junit_task_5", "test");
    assertNotNull(task);
    task.setStatus(COMPLETED);
    workflowExecutionService.updateTask(task);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    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());
    task = workflowExecutionService.poll("junit_task_1", "test");
    task.setStatus(COMPLETED);
    workflowExecutionService.updateTask(task);
    Workflow subWorkflow = workflowExecutionService.getExecutionStatus(subWorkflowId, true);
    task = workflowExecutionService.poll("junit_task_2", "test");
    task.setStatus(FAILED);
    workflowExecutionService.updateTask(task);
    subWorkflow = workflowExecutionService.getExecutionStatus(subWorkflowId, true);
    assertNotNull(subWorkflow);
    assertEquals(WorkflowStatus.FAILED, subWorkflow.getStatus());
    subWorkflow = workflowExecutionService.getExecutionStatus(subWorkflowId, true);
    assertNotNull(subWorkflow);
    task = subWorkflow.getTasks().stream().filter(t -> t.getTaskType().equals("junit_task_2")).findAny().orElse(null);
    assertNotNull(task);
    assertEquals(FAILED, task.getStatus());
    subWorkflow = workflowExecutionService.getExecutionStatus(subWorkflowId, true);
    assertNotNull(subWorkflow);
    assertEquals(WorkflowStatus.FAILED, subWorkflow.getStatus());
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals(WorkflowStatus.FAILED, workflow.getStatus());
    workflowExecutor.retry(workflowId, true);
    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"));
    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());
    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);
}
Also used : TaskUtils(com.netflix.conductor.common.utils.TaskUtils) MethodSorters(org.junit.runners.MethodSorters) SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) Arrays(java.util.Arrays) TimeoutPolicy(com.netflix.conductor.common.metadata.tasks.TaskDef.TimeoutPolicy) TEMP_FILE_PATH(com.netflix.conductor.tests.utils.MockExternalPayloadStorage.TEMP_FILE_PATH) LoggerFactory(org.slf4j.LoggerFactory) Task(com.netflix.conductor.common.metadata.tasks.Task) StringUtils(org.apache.commons.lang3.StringUtils) Future(java.util.concurrent.Future) COMPLETED_WITH_ERRORS(com.netflix.conductor.common.metadata.tasks.Task.Status.COMPLETED_WITH_ERRORS) RerunWorkflowRequest(com.netflix.conductor.common.metadata.workflow.RerunWorkflowRequest) Workflow(com.netflix.conductor.common.run.Workflow) IN_PROGRESS(com.netflix.conductor.common.metadata.tasks.Task.Status.IN_PROGRESS) Map(java.util.Map) After(org.junit.After) PollData(com.netflix.conductor.common.metadata.tasks.PollData) WorkflowExecutor(com.netflix.conductor.core.execution.WorkflowExecutor) TASK_OUTPUT_PATH(com.netflix.conductor.tests.utils.MockExternalPayloadStorage.TASK_OUTPUT_PATH) Terminate(com.netflix.conductor.core.execution.tasks.Terminate) WorkflowRepairService(com.netflix.conductor.core.execution.WorkflowRepairService) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) WorkflowStatus(com.netflix.conductor.common.run.Workflow.WorkflowStatus) MetadataMapperService(com.netflix.conductor.core.metadata.MetadataMapperService) Predicate(java.util.function.Predicate) Set(java.util.Set) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Executors(java.util.concurrent.Executors) SCHEDULED(com.netflix.conductor.common.metadata.tasks.Task.Status.SCHEDULED) QueueDAO(com.netflix.conductor.dao.QueueDAO) INPUT_PAYLOAD_PATH(com.netflix.conductor.tests.utils.MockExternalPayloadStorage.INPUT_PAYLOAD_PATH) List(java.util.List) DynamicForkJoinTaskList(com.netflix.conductor.common.metadata.workflow.DynamicForkJoinTaskList) Assert.assertFalse(org.junit.Assert.assertFalse) TIMED_OUT(com.netflix.conductor.common.metadata.tasks.Task.Status.TIMED_OUT) COMPLETED(com.netflix.conductor.common.metadata.tasks.Task.Status.COMPLETED) ExecutionService(com.netflix.conductor.service.ExecutionService) FixMethodOrder(org.junit.FixMethodOrder) JsonMapperProvider(com.netflix.conductor.common.utils.JsonMapperProvider) MetadataService(com.netflix.conductor.service.MetadataService) WorkflowContext(com.netflix.conductor.core.WorkflowContext) BeforeClass(org.junit.BeforeClass) SubWorkflowParams(com.netflix.conductor.common.metadata.workflow.SubWorkflowParams) Status(com.netflix.conductor.common.metadata.tasks.Task.Status) HashMap(java.util.HashMap) TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult) Inject(javax.inject.Inject) SUB_WORKFLOW(com.netflix.conductor.common.metadata.workflow.TaskType.SUB_WORKFLOW) LinkedList(java.util.LinkedList) ExpectedException(org.junit.rules.ExpectedException) RUNNING(com.netflix.conductor.common.run.Workflow.WorkflowStatus.RUNNING) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) TERMINATED(com.netflix.conductor.common.run.Workflow.WorkflowStatus.TERMINATED) INITIAL_WORKFLOW_INPUT_PATH(com.netflix.conductor.tests.utils.MockExternalPayloadStorage.INITIAL_WORKFLOW_INPUT_PATH) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) Logger(org.slf4j.Logger) WorkflowSweeper(com.netflix.conductor.core.execution.WorkflowSweeper) Assert.assertNotNull(org.junit.Assert.assertNotNull) UserTask(com.netflix.conductor.tests.utils.UserTask) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Assert.assertTrue(org.junit.Assert.assertTrue) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) FileOutputStream(java.io.FileOutputStream) Test(org.junit.Test) FAILED(com.netflix.conductor.common.metadata.tasks.Task.Status.FAILED) WORKFLOW_OUTPUT_PATH(com.netflix.conductor.tests.utils.MockExternalPayloadStorage.WORKFLOW_OUTPUT_PATH) TimeUnit(java.util.concurrent.TimeUnit) DECISION(com.netflix.conductor.common.metadata.workflow.TaskType.DECISION) Assert.assertNull(org.junit.Assert.assertNull) Rule(org.junit.Rule) Ignore(org.junit.Ignore) RetryLogic(com.netflix.conductor.common.metadata.tasks.TaskDef.RetryLogic) TaskType(com.netflix.conductor.common.metadata.workflow.TaskType) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) UserTask(com.netflix.conductor.tests.utils.UserTask) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) HashMap(java.util.HashMap) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) Workflow(com.netflix.conductor.common.run.Workflow) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Test(org.junit.Test)

Example 8 with RUNNING

use of com.netflix.conductor.common.run.Workflow.WorkflowStatus.RUNNING 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());
}
Also used : TaskUtils(com.netflix.conductor.common.utils.TaskUtils) MethodSorters(org.junit.runners.MethodSorters) SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) Arrays(java.util.Arrays) TimeoutPolicy(com.netflix.conductor.common.metadata.tasks.TaskDef.TimeoutPolicy) TEMP_FILE_PATH(com.netflix.conductor.tests.utils.MockExternalPayloadStorage.TEMP_FILE_PATH) LoggerFactory(org.slf4j.LoggerFactory) Task(com.netflix.conductor.common.metadata.tasks.Task) StringUtils(org.apache.commons.lang3.StringUtils) Future(java.util.concurrent.Future) COMPLETED_WITH_ERRORS(com.netflix.conductor.common.metadata.tasks.Task.Status.COMPLETED_WITH_ERRORS) RerunWorkflowRequest(com.netflix.conductor.common.metadata.workflow.RerunWorkflowRequest) Workflow(com.netflix.conductor.common.run.Workflow) IN_PROGRESS(com.netflix.conductor.common.metadata.tasks.Task.Status.IN_PROGRESS) Map(java.util.Map) After(org.junit.After) PollData(com.netflix.conductor.common.metadata.tasks.PollData) WorkflowExecutor(com.netflix.conductor.core.execution.WorkflowExecutor) TASK_OUTPUT_PATH(com.netflix.conductor.tests.utils.MockExternalPayloadStorage.TASK_OUTPUT_PATH) Terminate(com.netflix.conductor.core.execution.tasks.Terminate) WorkflowRepairService(com.netflix.conductor.core.execution.WorkflowRepairService) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) WorkflowStatus(com.netflix.conductor.common.run.Workflow.WorkflowStatus) MetadataMapperService(com.netflix.conductor.core.metadata.MetadataMapperService) Predicate(java.util.function.Predicate) Set(java.util.Set) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Executors(java.util.concurrent.Executors) SCHEDULED(com.netflix.conductor.common.metadata.tasks.Task.Status.SCHEDULED) QueueDAO(com.netflix.conductor.dao.QueueDAO) INPUT_PAYLOAD_PATH(com.netflix.conductor.tests.utils.MockExternalPayloadStorage.INPUT_PAYLOAD_PATH) List(java.util.List) DynamicForkJoinTaskList(com.netflix.conductor.common.metadata.workflow.DynamicForkJoinTaskList) Assert.assertFalse(org.junit.Assert.assertFalse) TIMED_OUT(com.netflix.conductor.common.metadata.tasks.Task.Status.TIMED_OUT) COMPLETED(com.netflix.conductor.common.metadata.tasks.Task.Status.COMPLETED) ExecutionService(com.netflix.conductor.service.ExecutionService) FixMethodOrder(org.junit.FixMethodOrder) JsonMapperProvider(com.netflix.conductor.common.utils.JsonMapperProvider) MetadataService(com.netflix.conductor.service.MetadataService) WorkflowContext(com.netflix.conductor.core.WorkflowContext) BeforeClass(org.junit.BeforeClass) SubWorkflowParams(com.netflix.conductor.common.metadata.workflow.SubWorkflowParams) Status(com.netflix.conductor.common.metadata.tasks.Task.Status) HashMap(java.util.HashMap) TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult) Inject(javax.inject.Inject) SUB_WORKFLOW(com.netflix.conductor.common.metadata.workflow.TaskType.SUB_WORKFLOW) LinkedList(java.util.LinkedList) ExpectedException(org.junit.rules.ExpectedException) RUNNING(com.netflix.conductor.common.run.Workflow.WorkflowStatus.RUNNING) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) TERMINATED(com.netflix.conductor.common.run.Workflow.WorkflowStatus.TERMINATED) INITIAL_WORKFLOW_INPUT_PATH(com.netflix.conductor.tests.utils.MockExternalPayloadStorage.INITIAL_WORKFLOW_INPUT_PATH) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) Logger(org.slf4j.Logger) WorkflowSweeper(com.netflix.conductor.core.execution.WorkflowSweeper) Assert.assertNotNull(org.junit.Assert.assertNotNull) UserTask(com.netflix.conductor.tests.utils.UserTask) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Assert.assertTrue(org.junit.Assert.assertTrue) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) FileOutputStream(java.io.FileOutputStream) Test(org.junit.Test) FAILED(com.netflix.conductor.common.metadata.tasks.Task.Status.FAILED) WORKFLOW_OUTPUT_PATH(com.netflix.conductor.tests.utils.MockExternalPayloadStorage.WORKFLOW_OUTPUT_PATH) TimeUnit(java.util.concurrent.TimeUnit) DECISION(com.netflix.conductor.common.metadata.workflow.TaskType.DECISION) Assert.assertNull(org.junit.Assert.assertNull) Rule(org.junit.Rule) Ignore(org.junit.Ignore) RetryLogic(com.netflix.conductor.common.metadata.tasks.TaskDef.RetryLogic) TaskType(com.netflix.conductor.common.metadata.workflow.TaskType) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) UserTask(com.netflix.conductor.tests.utils.UserTask) HashMap(java.util.HashMap) SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) Workflow(com.netflix.conductor.common.run.Workflow) TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult) Test(org.junit.Test)

Example 9 with RUNNING

use of com.netflix.conductor.common.run.Workflow.WorkflowStatus.RUNNING in project conductor by Netflix.

the class AbstractWorkflowServiceTest method testForkJoin.

@SuppressWarnings("ConstantConditions")
@Test
public void testForkJoin() throws Exception {
    createForkJoinWorkflow();
    String taskName = "junit_task_1";
    TaskDef taskDef = notFoundSafeGetTaskDef(taskName);
    taskDef.setRetryCount(0);
    taskDef.setTimeoutSeconds(0);
    metadataService.updateTaskDef(taskDef);
    taskName = "junit_task_2";
    taskDef = notFoundSafeGetTaskDef(taskName);
    taskDef.setRetryCount(0);
    taskDef.setTimeoutSeconds(0);
    metadataService.updateTaskDef(taskDef);
    taskName = "junit_task_3";
    taskDef = notFoundSafeGetTaskDef(taskName);
    taskDef.setRetryCount(0);
    taskDef.setTimeoutSeconds(0);
    metadataService.updateTaskDef(taskDef);
    taskName = "junit_task_4";
    taskDef = notFoundSafeGetTaskDef(taskName);
    taskDef.setRetryCount(0);
    taskDef.setTimeoutSeconds(0);
    metadataService.updateTaskDef(taskDef);
    Map<String, Object> input = new HashMap<>();
    String workflowId = startOrLoadWorkflowExecution(FORK_JOIN_WF, 1, "fanouttest", input, null, null);
    assertNotNull(workflowId);
    printTaskStatuses(workflowId, "initiated");
    Workflow workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals(RUNNING, workflow.getStatus());
    assertEquals(4, workflow.getTasks().size());
    Task task1 = workflowExecutionService.poll("junit_task_1", "test");
    assertNotNull(task1);
    assertTrue(workflowExecutionService.ackTaskReceived(task1.getTaskId()));
    Task task2 = workflowExecutionService.poll("junit_task_2", "test");
    assertNotNull(task2);
    assertTrue(workflowExecutionService.ackTaskReceived(task2.getTaskId()));
    Task task3 = workflowExecutionService.poll("junit_task_3", "test");
    assertNull(task3);
    task1.setStatus(COMPLETED);
    workflowExecutionService.updateTask(task1);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals("Found " + workflow.getTasks(), RUNNING, workflow.getStatus());
    printTaskStatuses(workflow, "T1 completed");
    task3 = workflowExecutionService.poll("junit_task_3", "test");
    assertNotNull(task3);
    task2.setStatus(COMPLETED);
    task3.setStatus(COMPLETED);
    ExecutorService executorService = Executors.newFixedThreadPool(2);
    Future<?> future1 = executorService.submit(() -> {
        try {
            workflowExecutionService.updateTask(task2);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    });
    future1.get();
    final Task _t3 = task3;
    Future<?> future2 = executorService.submit(() -> {
        try {
            workflowExecutionService.updateTask(_t3);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    });
    future2.get();
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    printTaskStatuses(workflow, "T2 T3 completed");
    assertEquals("Found " + workflow.getTasks(), RUNNING, workflow.getStatus());
    assertEquals("Found " + workflow.getTasks().stream().map(Task::getTaskType).collect(Collectors.toList()), 6, workflow.getTasks().size());
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals("Found " + workflow.getTasks(), RUNNING, workflow.getStatus());
    assertTrue("Found  " + workflow.getTasks().stream().map(t -> t.getReferenceTaskName() + "." + t.getStatus()).collect(Collectors.toList()), workflow.getTasks().stream().anyMatch(t -> t.getReferenceTaskName().equals("t4")));
    Task t4 = workflowExecutionService.poll("junit_task_4", "test");
    assertNotNull(t4);
    t4.setStatus(COMPLETED);
    workflowExecutionService.updateTask(t4);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals("Found " + workflow.getTasks(), WorkflowStatus.COMPLETED, workflow.getStatus());
    printTaskStatuses(workflow, "All completed");
}
Also used : TaskUtils(com.netflix.conductor.common.utils.TaskUtils) MethodSorters(org.junit.runners.MethodSorters) SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) Arrays(java.util.Arrays) TimeoutPolicy(com.netflix.conductor.common.metadata.tasks.TaskDef.TimeoutPolicy) TEMP_FILE_PATH(com.netflix.conductor.tests.utils.MockExternalPayloadStorage.TEMP_FILE_PATH) LoggerFactory(org.slf4j.LoggerFactory) Task(com.netflix.conductor.common.metadata.tasks.Task) StringUtils(org.apache.commons.lang3.StringUtils) Future(java.util.concurrent.Future) COMPLETED_WITH_ERRORS(com.netflix.conductor.common.metadata.tasks.Task.Status.COMPLETED_WITH_ERRORS) RerunWorkflowRequest(com.netflix.conductor.common.metadata.workflow.RerunWorkflowRequest) Workflow(com.netflix.conductor.common.run.Workflow) IN_PROGRESS(com.netflix.conductor.common.metadata.tasks.Task.Status.IN_PROGRESS) Map(java.util.Map) After(org.junit.After) PollData(com.netflix.conductor.common.metadata.tasks.PollData) WorkflowExecutor(com.netflix.conductor.core.execution.WorkflowExecutor) TASK_OUTPUT_PATH(com.netflix.conductor.tests.utils.MockExternalPayloadStorage.TASK_OUTPUT_PATH) Terminate(com.netflix.conductor.core.execution.tasks.Terminate) WorkflowRepairService(com.netflix.conductor.core.execution.WorkflowRepairService) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) WorkflowStatus(com.netflix.conductor.common.run.Workflow.WorkflowStatus) MetadataMapperService(com.netflix.conductor.core.metadata.MetadataMapperService) Predicate(java.util.function.Predicate) Set(java.util.Set) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Executors(java.util.concurrent.Executors) SCHEDULED(com.netflix.conductor.common.metadata.tasks.Task.Status.SCHEDULED) QueueDAO(com.netflix.conductor.dao.QueueDAO) INPUT_PAYLOAD_PATH(com.netflix.conductor.tests.utils.MockExternalPayloadStorage.INPUT_PAYLOAD_PATH) List(java.util.List) DynamicForkJoinTaskList(com.netflix.conductor.common.metadata.workflow.DynamicForkJoinTaskList) Assert.assertFalse(org.junit.Assert.assertFalse) TIMED_OUT(com.netflix.conductor.common.metadata.tasks.Task.Status.TIMED_OUT) COMPLETED(com.netflix.conductor.common.metadata.tasks.Task.Status.COMPLETED) ExecutionService(com.netflix.conductor.service.ExecutionService) FixMethodOrder(org.junit.FixMethodOrder) JsonMapperProvider(com.netflix.conductor.common.utils.JsonMapperProvider) MetadataService(com.netflix.conductor.service.MetadataService) WorkflowContext(com.netflix.conductor.core.WorkflowContext) BeforeClass(org.junit.BeforeClass) SubWorkflowParams(com.netflix.conductor.common.metadata.workflow.SubWorkflowParams) Status(com.netflix.conductor.common.metadata.tasks.Task.Status) HashMap(java.util.HashMap) TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult) Inject(javax.inject.Inject) SUB_WORKFLOW(com.netflix.conductor.common.metadata.workflow.TaskType.SUB_WORKFLOW) LinkedList(java.util.LinkedList) ExpectedException(org.junit.rules.ExpectedException) RUNNING(com.netflix.conductor.common.run.Workflow.WorkflowStatus.RUNNING) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) TERMINATED(com.netflix.conductor.common.run.Workflow.WorkflowStatus.TERMINATED) INITIAL_WORKFLOW_INPUT_PATH(com.netflix.conductor.tests.utils.MockExternalPayloadStorage.INITIAL_WORKFLOW_INPUT_PATH) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) Logger(org.slf4j.Logger) WorkflowSweeper(com.netflix.conductor.core.execution.WorkflowSweeper) Assert.assertNotNull(org.junit.Assert.assertNotNull) UserTask(com.netflix.conductor.tests.utils.UserTask) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Assert.assertTrue(org.junit.Assert.assertTrue) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) FileOutputStream(java.io.FileOutputStream) Test(org.junit.Test) FAILED(com.netflix.conductor.common.metadata.tasks.Task.Status.FAILED) WORKFLOW_OUTPUT_PATH(com.netflix.conductor.tests.utils.MockExternalPayloadStorage.WORKFLOW_OUTPUT_PATH) TimeUnit(java.util.concurrent.TimeUnit) DECISION(com.netflix.conductor.common.metadata.workflow.TaskType.DECISION) Assert.assertNull(org.junit.Assert.assertNull) Rule(org.junit.Rule) Ignore(org.junit.Ignore) RetryLogic(com.netflix.conductor.common.metadata.tasks.TaskDef.RetryLogic) TaskType(com.netflix.conductor.common.metadata.workflow.TaskType) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) UserTask(com.netflix.conductor.tests.utils.UserTask) HashMap(java.util.HashMap) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) ExecutorService(java.util.concurrent.ExecutorService) SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) Workflow(com.netflix.conductor.common.run.Workflow) ExpectedException(org.junit.rules.ExpectedException) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) Test(org.junit.Test)

Example 10 with RUNNING

use of com.netflix.conductor.common.run.Workflow.WorkflowStatus.RUNNING in project conductor by Netflix.

the class AbstractWorkflowServiceTest method testDynamicForkJoin.

@SuppressWarnings("unchecked")
@Test
public void testDynamicForkJoin() {
    createDynamicForkJoinWorkflowDefs();
    String taskName = "junit_task_2";
    TaskDef taskDef = notFoundSafeGetTaskDef(taskName);
    int retryCount = taskDef.getRetryCount();
    taskDef.setRetryCount(2);
    taskDef.setRetryDelaySeconds(0);
    taskDef.setRetryLogic(RetryLogic.FIXED);
    metadataService.updateTaskDef(taskDef);
    Map<String, Object> workflowInput = new HashMap<>();
    String workflowId = startOrLoadWorkflowExecution(DYNAMIC_FORK_JOIN_WF, 1, "dynfanouttest1", workflowInput, null, null);
    System.out.println("testDynamicForkJoin.wfid=" + workflowId);
    Workflow workflow = workflowExecutor.getWorkflow(workflowId, true);
    assertNotNull(workflow);
    assertEquals(workflow.getReasonForIncompletion(), RUNNING, workflow.getStatus());
    assertEquals(1, workflow.getTasks().size());
    Task task1 = workflowExecutionService.poll("junit_task_1", "test");
    assertNotNull(task1);
    assertTrue(workflowExecutionService.ackTaskReceived(task1.getTaskId()));
    assertEquals("dt1", task1.getReferenceTaskName());
    Map<String, Object> inputParams2 = new HashMap<>();
    inputParams2.put("k1", "v1");
    WorkflowTask workflowTask2 = new WorkflowTask();
    workflowTask2.setName("junit_task_2");
    workflowTask2.setTaskReferenceName("xdt1");
    Map<String, Object> inputParams3 = new HashMap<>();
    inputParams3.put("k2", "v2");
    WorkflowTask workflowTask3 = new WorkflowTask();
    workflowTask3.setName("junit_task_3");
    workflowTask3.setTaskReferenceName("xdt2");
    HashMap<String, Object> dynamicTasksInput = new HashMap<>();
    dynamicTasksInput.put("xdt1", inputParams2);
    dynamicTasksInput.put("xdt2", inputParams3);
    task1.getOutputData().put("dynamicTasks", Arrays.asList(workflowTask2, workflowTask3));
    task1.getOutputData().put("dynamicTasksInput", dynamicTasksInput);
    task1.setStatus(COMPLETED);
    workflowExecutionService.updateTask(task1);
    workflow = workflowExecutor.getWorkflow(workflowId, true);
    assertNotNull(workflow);
    assertEquals("Found " + workflow.getTasks().stream().map(Task::getTaskType).collect(Collectors.toList()), 5, workflow.getTasks().size());
    Task task2 = workflowExecutionService.poll("junit_task_2", "test");
    assertTrue(workflowExecutionService.ackTaskReceived(task2.getTaskId()));
    assertEquals("xdt1", task2.getReferenceTaskName());
    assertTrue(task2.getInputData().containsKey("k1"));
    assertEquals("v1", task2.getInputData().get("k1"));
    Map<String, Object> output = new HashMap<>();
    output.put("ok1", "ov1");
    task2.setOutputData(output);
    task2.setStatus(FAILED);
    workflowExecutionService.updateTask(task2);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals(workflow.getReasonForIncompletion(), RUNNING, workflow.getStatus());
    assertEquals(2, workflow.getTasks().stream().filter(t -> t.getTaskType().equals("junit_task_2")).count());
    assertTrue(workflow.getTasks().stream().filter(t -> t.getTaskType().equals("junit_task_2")).allMatch(t -> t.getWorkflowTask() != null));
    assertEquals("Found " + workflow.getTasks().stream().map(Task::getTaskType).collect(Collectors.toList()), 6, workflow.getTasks().size());
    task2 = workflowExecutionService.poll("junit_task_2", "test");
    assertTrue(workflowExecutionService.ackTaskReceived(task2.getTaskId()));
    assertEquals("xdt1", task2.getReferenceTaskName());
    assertTrue(task2.getInputData().containsKey("k1"));
    assertEquals("v1", task2.getInputData().get("k1"));
    task2.setOutputData(output);
    task2.setStatus(COMPLETED);
    workflowExecutionService.updateTask(task2);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals("Found " + workflow.getTasks().stream().map(Task::getTaskType).collect(Collectors.toList()), 6, workflow.getTasks().size());
    Task task3 = workflowExecutionService.poll("junit_task_3", "test");
    assertTrue(workflowExecutionService.ackTaskReceived(task3.getTaskId()));
    assertEquals("xdt2", task3.getReferenceTaskName());
    assertTrue(task3.getInputData().containsKey("k2"));
    assertEquals("v2", task3.getInputData().get("k2"));
    output = new HashMap<>();
    output.put("ok1", "ov1");
    task3.setOutputData(output);
    task3.setStatus(COMPLETED);
    workflowExecutionService.updateTask(task3);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals(workflow.getReasonForIncompletion(), RUNNING, workflow.getStatus());
    assertEquals("Found " + workflow.getTasks().stream().map(Task::getTaskType).collect(Collectors.toList()), 7, workflow.getTasks().size());
    Task task4 = workflowExecutionService.poll("junit_task_4", "test");
    assertTrue(workflowExecutionService.ackTaskReceived(task4.getTaskId()));
    assertEquals("task4", task4.getReferenceTaskName());
    task4.setStatus(COMPLETED);
    workflowExecutionService.updateTask(task4);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals(workflow.getReasonForIncompletion(), WorkflowStatus.COMPLETED, workflow.getStatus());
    assertEquals("Found " + workflow.getTasks().stream().map(Task::getTaskType).collect(Collectors.toList()), 7, workflow.getTasks().size());
    // Check the output
    Task joinTask = workflow.getTaskByRefName("dynamicfanouttask_join");
    assertEquals("Found:" + joinTask.getOutputData(), 2, joinTask.getOutputData().keySet().size());
    Set<String> joinTaskOutput = joinTask.getOutputData().keySet();
    System.out.println("joinTaskOutput=" + joinTaskOutput);
    for (String key : joinTask.getOutputData().keySet()) {
        assertTrue(key.equals("xdt1") || key.equals("xdt2"));
        assertEquals("ov1", ((Map<String, Object>) joinTask.getOutputData().get(key)).get("ok1"));
    }
    // reset the task def
    taskDef = notFoundSafeGetTaskDef(taskName);
    taskDef.setRetryCount(retryCount);
    taskDef.setRetryDelaySeconds(1);
    metadataService.updateTaskDef(taskDef);
}
Also used : TaskUtils(com.netflix.conductor.common.utils.TaskUtils) MethodSorters(org.junit.runners.MethodSorters) SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) Arrays(java.util.Arrays) TimeoutPolicy(com.netflix.conductor.common.metadata.tasks.TaskDef.TimeoutPolicy) TEMP_FILE_PATH(com.netflix.conductor.tests.utils.MockExternalPayloadStorage.TEMP_FILE_PATH) LoggerFactory(org.slf4j.LoggerFactory) Task(com.netflix.conductor.common.metadata.tasks.Task) StringUtils(org.apache.commons.lang3.StringUtils) Future(java.util.concurrent.Future) COMPLETED_WITH_ERRORS(com.netflix.conductor.common.metadata.tasks.Task.Status.COMPLETED_WITH_ERRORS) RerunWorkflowRequest(com.netflix.conductor.common.metadata.workflow.RerunWorkflowRequest) Workflow(com.netflix.conductor.common.run.Workflow) IN_PROGRESS(com.netflix.conductor.common.metadata.tasks.Task.Status.IN_PROGRESS) Map(java.util.Map) After(org.junit.After) PollData(com.netflix.conductor.common.metadata.tasks.PollData) WorkflowExecutor(com.netflix.conductor.core.execution.WorkflowExecutor) TASK_OUTPUT_PATH(com.netflix.conductor.tests.utils.MockExternalPayloadStorage.TASK_OUTPUT_PATH) Terminate(com.netflix.conductor.core.execution.tasks.Terminate) WorkflowRepairService(com.netflix.conductor.core.execution.WorkflowRepairService) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) WorkflowStatus(com.netflix.conductor.common.run.Workflow.WorkflowStatus) MetadataMapperService(com.netflix.conductor.core.metadata.MetadataMapperService) Predicate(java.util.function.Predicate) Set(java.util.Set) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Executors(java.util.concurrent.Executors) SCHEDULED(com.netflix.conductor.common.metadata.tasks.Task.Status.SCHEDULED) QueueDAO(com.netflix.conductor.dao.QueueDAO) INPUT_PAYLOAD_PATH(com.netflix.conductor.tests.utils.MockExternalPayloadStorage.INPUT_PAYLOAD_PATH) List(java.util.List) DynamicForkJoinTaskList(com.netflix.conductor.common.metadata.workflow.DynamicForkJoinTaskList) Assert.assertFalse(org.junit.Assert.assertFalse) TIMED_OUT(com.netflix.conductor.common.metadata.tasks.Task.Status.TIMED_OUT) COMPLETED(com.netflix.conductor.common.metadata.tasks.Task.Status.COMPLETED) ExecutionService(com.netflix.conductor.service.ExecutionService) FixMethodOrder(org.junit.FixMethodOrder) JsonMapperProvider(com.netflix.conductor.common.utils.JsonMapperProvider) MetadataService(com.netflix.conductor.service.MetadataService) WorkflowContext(com.netflix.conductor.core.WorkflowContext) BeforeClass(org.junit.BeforeClass) SubWorkflowParams(com.netflix.conductor.common.metadata.workflow.SubWorkflowParams) Status(com.netflix.conductor.common.metadata.tasks.Task.Status) HashMap(java.util.HashMap) TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult) Inject(javax.inject.Inject) SUB_WORKFLOW(com.netflix.conductor.common.metadata.workflow.TaskType.SUB_WORKFLOW) LinkedList(java.util.LinkedList) ExpectedException(org.junit.rules.ExpectedException) RUNNING(com.netflix.conductor.common.run.Workflow.WorkflowStatus.RUNNING) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) TERMINATED(com.netflix.conductor.common.run.Workflow.WorkflowStatus.TERMINATED) INITIAL_WORKFLOW_INPUT_PATH(com.netflix.conductor.tests.utils.MockExternalPayloadStorage.INITIAL_WORKFLOW_INPUT_PATH) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) Logger(org.slf4j.Logger) WorkflowSweeper(com.netflix.conductor.core.execution.WorkflowSweeper) Assert.assertNotNull(org.junit.Assert.assertNotNull) UserTask(com.netflix.conductor.tests.utils.UserTask) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Assert.assertTrue(org.junit.Assert.assertTrue) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) FileOutputStream(java.io.FileOutputStream) Test(org.junit.Test) FAILED(com.netflix.conductor.common.metadata.tasks.Task.Status.FAILED) WORKFLOW_OUTPUT_PATH(com.netflix.conductor.tests.utils.MockExternalPayloadStorage.WORKFLOW_OUTPUT_PATH) TimeUnit(java.util.concurrent.TimeUnit) DECISION(com.netflix.conductor.common.metadata.workflow.TaskType.DECISION) Assert.assertNull(org.junit.Assert.assertNull) Rule(org.junit.Rule) Ignore(org.junit.Ignore) RetryLogic(com.netflix.conductor.common.metadata.tasks.TaskDef.RetryLogic) TaskType(com.netflix.conductor.common.metadata.workflow.TaskType) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) UserTask(com.netflix.conductor.tests.utils.UserTask) HashMap(java.util.HashMap) SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) Workflow(com.netflix.conductor.common.run.Workflow) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) Test(org.junit.Test)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)15 Uninterruptibles (com.google.common.util.concurrent.Uninterruptibles)15 PollData (com.netflix.conductor.common.metadata.tasks.PollData)15 Task (com.netflix.conductor.common.metadata.tasks.Task)15 Status (com.netflix.conductor.common.metadata.tasks.Task.Status)15 COMPLETED (com.netflix.conductor.common.metadata.tasks.Task.Status.COMPLETED)15 COMPLETED_WITH_ERRORS (com.netflix.conductor.common.metadata.tasks.Task.Status.COMPLETED_WITH_ERRORS)15 FAILED (com.netflix.conductor.common.metadata.tasks.Task.Status.FAILED)15 IN_PROGRESS (com.netflix.conductor.common.metadata.tasks.Task.Status.IN_PROGRESS)15 SCHEDULED (com.netflix.conductor.common.metadata.tasks.Task.Status.SCHEDULED)15 TIMED_OUT (com.netflix.conductor.common.metadata.tasks.Task.Status.TIMED_OUT)15 TaskDef (com.netflix.conductor.common.metadata.tasks.TaskDef)15 RetryLogic (com.netflix.conductor.common.metadata.tasks.TaskDef.RetryLogic)15 TimeoutPolicy (com.netflix.conductor.common.metadata.tasks.TaskDef.TimeoutPolicy)15 TaskResult (com.netflix.conductor.common.metadata.tasks.TaskResult)15 DynamicForkJoinTaskList (com.netflix.conductor.common.metadata.workflow.DynamicForkJoinTaskList)15 RerunWorkflowRequest (com.netflix.conductor.common.metadata.workflow.RerunWorkflowRequest)15 SubWorkflowParams (com.netflix.conductor.common.metadata.workflow.SubWorkflowParams)15 TaskType (com.netflix.conductor.common.metadata.workflow.TaskType)15 DECISION (com.netflix.conductor.common.metadata.workflow.TaskType.DECISION)15