Search in sources :

Example 16 with SubWorkflow

use of com.netflix.conductor.core.execution.tasks.SubWorkflow in project conductor by Netflix.

the class AbstractWorkflowServiceTest method testForkJoinWithOptionalSubworkflows.

@Test
public void testForkJoinWithOptionalSubworkflows() {
    createForkJoinWorkflowWithOptionalSubworkflowForks();
    Map<String, Object> workflowInput = new HashMap<>();
    workflowInput.put("param1", "p1 value");
    workflowInput.put("param2", "p2 value");
    String workflowId = startOrLoadWorkflowExecution(WORKFLOW_FORK_JOIN_OPTIONAL_SW, 1, "", workflowInput, null, null);
    assertNotNull(workflowId);
    Workflow workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals(RUNNING, workflow.getStatus());
    assertEquals("found " + workflow.getTasks().stream().map(Task::toString).collect(Collectors.toList()), 4, workflow.getTasks().size());
    // Simulating SystemTaskWorkerCoordinator to execute async system tasks
    String subWorkflowTaskId1 = workflow.getTaskByRefName("st1").getTaskId();
    workflowExecutor.executeSystemTask(dummySubWorkflowSystemTask, subWorkflowTaskId1, 1);
    String subWorkflowTaskId2 = workflow.getTaskByRefName("st2").getTaskId();
    workflowExecutor.executeSystemTask(dummySubWorkflowSystemTask, subWorkflowTaskId2, 1);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    String subWorkflowId1 = workflow.getTasks().get(1).getSubWorkflowId();
    Workflow subWorkflow1 = workflowExecutionService.getExecutionStatus(subWorkflowId1, true);
    assertNotNull(subWorkflow1);
    assertEquals(RUNNING, subWorkflow1.getStatus());
    assertEquals(1, subWorkflow1.getTasks().size());
    String subWorkflowId2 = workflow.getTasks().get(2).getSubWorkflowId();
    Workflow subWorkflow2 = workflowExecutionService.getExecutionStatus(subWorkflowId2, true);
    assertNotNull(subWorkflow2);
    assertEquals(RUNNING, subWorkflow2.getStatus());
    assertEquals(1, subWorkflow2.getTasks().size());
    // fail sub-workflow 1
    Task task = new Task();
    while (!subWorkflowId1.equals(task.getWorkflowInstanceId())) {
        task = workflowExecutionService.poll("simple_task_in_sub_wf", "junit.worker");
    }
    assertNotNull(task);
    assertEquals("simple_task_in_sub_wf", task.getTaskType());
    assertTrue(workflowExecutionService.ackTaskReceived(task.getTaskId()));
    assertEquals(subWorkflowId1, task.getWorkflowInstanceId());
    TaskResult taskResult = new TaskResult(task);
    taskResult.setReasonForIncompletion("fail task 1");
    taskResult.setStatus(TaskResult.Status.FAILED);
    workflowExecutionService.updateTask(taskResult);
    subWorkflow1 = workflowExecutionService.getExecutionStatus(subWorkflowId1, true);
    assertNotNull(subWorkflow1);
    assertEquals(WorkflowStatus.FAILED, subWorkflow1.getStatus());
    subWorkflow2 = workflowExecutionService.getExecutionStatus(subWorkflowId2, true);
    assertNotNull(subWorkflow2);
    assertEquals(RUNNING, subWorkflow2.getStatus());
    // Execute again to re-evaluate the Subworkflow task.
    workflowExecutor.executeSystemTask(dummySubWorkflowSystemTask, subWorkflowTaskId1, 1);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals(RUNNING, workflow.getStatus());
    assertEquals(COMPLETED_WITH_ERRORS, workflow.getTasks().get(1).getStatus());
    assertEquals(IN_PROGRESS, workflow.getTasks().get(2).getStatus());
    // fail sub workflow 2
    task = new Task();
    while (!subWorkflowId2.equals(task.getWorkflowInstanceId())) {
        task = workflowExecutionService.poll("simple_task_in_sub_wf", "junit.worker");
    }
    assertNotNull(task);
    assertEquals("simple_task_in_sub_wf", task.getTaskType());
    assertTrue(workflowExecutionService.ackTaskReceived(task.getTaskId()));
    assertEquals(subWorkflowId2, task.getWorkflowInstanceId());
    taskResult = new TaskResult(task);
    taskResult.setReasonForIncompletion("fail task 2");
    taskResult.setStatus(TaskResult.Status.FAILED);
    workflowExecutionService.updateTask(taskResult);
    subWorkflow1 = workflowExecutionService.getExecutionStatus(subWorkflowId1, true);
    assertNotNull(subWorkflow1);
    assertEquals(WorkflowStatus.FAILED, subWorkflow1.getStatus());
    subWorkflow2 = workflowExecutionService.getExecutionStatus(subWorkflowId2, true);
    assertNotNull(subWorkflow2);
    assertEquals(WorkflowStatus.FAILED, subWorkflow2.getStatus());
    // Execute again to re-evaluate the Subworkflow task.
    workflowExecutor.executeSystemTask(dummySubWorkflowSystemTask, subWorkflowTaskId2, 1);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals(WorkflowStatus.COMPLETED, workflow.getStatus());
    assertEquals(4, workflow.getTasks().size());
    assertEquals(COMPLETED_WITH_ERRORS, workflow.getTasks().get(1).getStatus());
    assertEquals(COMPLETED_WITH_ERRORS, workflow.getTasks().get(2).getStatus());
}
Also used : 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 17 with SubWorkflow

use of com.netflix.conductor.core.execution.tasks.SubWorkflow 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());
}
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) SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) Workflow(com.netflix.conductor.common.run.Workflow) Test(org.junit.Test)

Example 18 with SubWorkflow

use of com.netflix.conductor.core.execution.tasks.SubWorkflow 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());
}
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) Test(org.junit.Test)

Example 19 with SubWorkflow

use of com.netflix.conductor.core.execution.tasks.SubWorkflow 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());
}
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) Test(org.junit.Test)

Example 20 with SubWorkflow

use of com.netflix.conductor.core.execution.tasks.SubWorkflow in project conductor by Netflix.

the class WorkflowExecutor method updateParentWorkflow.

private boolean updateParentWorkflow(Workflow subWorkflow) {
    Task subWorkflowTask = executionDAOFacade.getTaskById(subWorkflow.getParentWorkflowTaskId());
    Workflow parentWorkflow = executionDAOFacade.getWorkflowById(subWorkflow.getParentWorkflowId(), false);
    return updateParentWorkflow(subWorkflowTask, subWorkflow, parentWorkflow);
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowSystemTask(com.netflix.conductor.core.execution.tasks.WorkflowSystemTask) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) Workflow(com.netflix.conductor.common.run.Workflow)

Aggregations

SubWorkflow (com.netflix.conductor.core.execution.tasks.SubWorkflow)21 Task (com.netflix.conductor.common.metadata.tasks.Task)20 WorkflowTask (com.netflix.conductor.common.metadata.workflow.WorkflowTask)19 Workflow (com.netflix.conductor.common.run.Workflow)19 Test (org.junit.Test)16 UserTask (com.netflix.conductor.tests.utils.UserTask)13 HashMap (java.util.HashMap)13 WorkflowDef (com.netflix.conductor.common.metadata.workflow.WorkflowDef)12 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 TaskResult (com.netflix.conductor.common.metadata.tasks.TaskResult)8 RerunWorkflowRequest (com.netflix.conductor.common.metadata.workflow.RerunWorkflowRequest)8 SubWorkflowParams (com.netflix.conductor.common.metadata.workflow.SubWorkflowParams)8 JsonMapperProvider (com.netflix.conductor.common.utils.JsonMapperProvider)8 Uninterruptibles (com.google.common.util.concurrent.Uninterruptibles)7 PollData (com.netflix.conductor.common.metadata.tasks.PollData)7 Status (com.netflix.conductor.common.metadata.tasks.Task.Status)7 COMPLETED (com.netflix.conductor.common.metadata.tasks.Task.Status.COMPLETED)7 COMPLETED_WITH_ERRORS (com.netflix.conductor.common.metadata.tasks.Task.Status.COMPLETED_WITH_ERRORS)7 FAILED (com.netflix.conductor.common.metadata.tasks.Task.Status.FAILED)7 IN_PROGRESS (com.netflix.conductor.common.metadata.tasks.Task.Status.IN_PROGRESS)7