Search in sources :

Example 26 with WorkflowTask

use of com.netflix.conductor.common.metadata.workflow.WorkflowTask in project conductor by Netflix.

the class TestWorkflowExecutor method testRollbackTasks.

@Test
public void testRollbackTasks() {
    String workflowId = "workflow-id";
    Task task1 = new Task();
    task1.setTaskType(TaskType.SIMPLE.name());
    task1.setTaskDefName("simpleTask");
    task1.setReferenceTaskName("simpleTask");
    task1.setWorkflowInstanceId(workflowId);
    task1.setScheduledTime(System.currentTimeMillis());
    task1.setTaskId(IDGenerator.generate());
    task1.setStatus(Status.SCHEDULED);
    WorkflowTask waitTask = new WorkflowTask();
    waitTask.setWorkflowTaskType(TaskType.WAIT);
    waitTask.setType(TaskType.WAIT.name());
    waitTask.setTaskReferenceName("wait");
    Task task2 = new Task();
    task2.setTaskType(waitTask.getType());
    task2.setTaskDefName(waitTask.getName());
    task2.setReferenceTaskName(waitTask.getTaskReferenceName());
    task2.setWorkflowInstanceId(workflowId);
    task2.setScheduledTime(System.currentTimeMillis());
    task2.setTaskId(IDGenerator.generate());
    task2.setStatus(Status.IN_PROGRESS);
    task2.setRetryCount(0);
    task2.setWorkflowTask(waitTask);
    WorkflowTask subWorkflowTask = new WorkflowTask();
    subWorkflowTask.setWorkflowTaskType(TaskType.SUB_WORKFLOW);
    subWorkflowTask.setType(TaskType.SUB_WORKFLOW.name());
    subWorkflowTask.setTaskReferenceName("sub-workflow");
    Task task3 = new Task();
    task3.setTaskType(subWorkflowTask.getType());
    task3.setTaskDefName(subWorkflowTask.getName());
    task3.setReferenceTaskName(subWorkflowTask.getTaskReferenceName());
    task3.setWorkflowInstanceId(workflowId);
    task3.setScheduledTime(System.currentTimeMillis());
    task3.setTaskId(IDGenerator.generate());
    task3.setStatus(Status.IN_PROGRESS);
    task3.setRetryCount(0);
    task3.setWorkflowTask(subWorkflowTask);
    task3.setOutputData(new HashMap<>());
    task3.setSubWorkflowId(IDGenerator.generate());
    AtomicInteger removeWorkflowCalledCounter = new AtomicInteger(0);
    doAnswer(invocation -> {
        removeWorkflowCalledCounter.incrementAndGet();
        return null;
    }).when(executionDAOFacade).removeWorkflow(anyString(), anyBoolean());
    AtomicInteger removeTaskCalledCounter = new AtomicInteger(0);
    doAnswer(invocation -> {
        removeTaskCalledCounter.incrementAndGet();
        return null;
    }).when(executionDAOFacade).removeTask(anyString());
    workflowExecutor.rollbackTasks(workflowId, Arrays.asList(task1, task2, task3));
    assertEquals(1, removeWorkflowCalledCounter.get());
    assertEquals(3, removeTaskCalledCounter.get());
}
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) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 27 with WorkflowTask

use of com.netflix.conductor.common.metadata.workflow.WorkflowTask in project conductor by Netflix.

the class TestWorkflowExecutor method testRetryWorkflowWithJoinTask.

@Test
public void testRetryWorkflowWithJoinTask() {
    // setup
    Workflow workflow = new Workflow();
    workflow.setWorkflowId("testRetryWorkflowId");
    workflow.setWorkflowType("testRetryWorkflowId");
    workflow.setVersion(1);
    workflow.setOwnerApp("junit_testRetryWorkflowId");
    workflow.setStartTime(10L);
    workflow.setEndTime(100L);
    // noinspection unchecked
    workflow.setOutput(Collections.EMPTY_MAP);
    workflow.setStatus(Workflow.WorkflowStatus.FAILED);
    Task forkTask = new Task();
    forkTask.setTaskType(TaskType.FORK_JOIN.toString());
    forkTask.setTaskId(UUID.randomUUID().toString());
    forkTask.setSeq(1);
    forkTask.setRetryCount(1);
    forkTask.setStatus(Status.COMPLETED);
    forkTask.setReferenceTaskName("task_fork");
    Task task_1_1 = new Task();
    task_1_1.setTaskId(UUID.randomUUID().toString());
    task_1_1.setSeq(20);
    task_1_1.setRetryCount(1);
    task_1_1.setTaskType(TaskType.SIMPLE.toString());
    task_1_1.setStatus(Status.FAILED);
    task_1_1.setTaskDefName("task1");
    task_1_1.setWorkflowTask(new WorkflowTask());
    task_1_1.setReferenceTaskName("task1_ref1");
    Task task_2_1 = new Task();
    task_2_1.setTaskId(UUID.randomUUID().toString());
    task_2_1.setSeq(22);
    task_2_1.setRetryCount(1);
    task_2_1.setStatus(Status.CANCELED);
    task_2_1.setTaskType(TaskType.SIMPLE.toString());
    task_2_1.setTaskDefName("task2");
    task_2_1.setWorkflowTask(new WorkflowTask());
    task_2_1.setReferenceTaskName("task2_ref1");
    Task joinTask = new Task();
    joinTask.setTaskType(TaskType.JOIN.toString());
    joinTask.setTaskId(UUID.randomUUID().toString());
    joinTask.setSeq(25);
    joinTask.setRetryCount(1);
    joinTask.setStatus(Status.CANCELED);
    joinTask.setReferenceTaskName("task_join");
    joinTask.getInputData().put("joinOn", Arrays.asList(task_1_1.getReferenceTaskName(), task_2_1.getReferenceTaskName()));
    workflow.getTasks().addAll(Arrays.asList(forkTask, task_1_1, task_2_1, joinTask));
    // end of setup
    // when:
    when(executionDAOFacade.getWorkflowById(anyString(), anyBoolean())).thenReturn(workflow);
    WorkflowDef workflowDef = new WorkflowDef();
    when(metadataDAO.getWorkflowDef(anyString(), anyInt())).thenReturn(Optional.of(workflowDef));
    workflowExecutor.retry(workflow.getWorkflowId(), false);
    assertEquals(6, workflow.getTasks().size());
    assertEquals(Workflow.WorkflowStatus.RUNNING, workflow.getStatus());
}
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) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) 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 28 with WorkflowTask

use of com.netflix.conductor.common.metadata.workflow.WorkflowTask in project conductor by Netflix.

the class TestWorkflowExecutor method testRetryWorkflow.

@Test
public void testRetryWorkflow() {
    // setup
    Workflow workflow = new Workflow();
    workflow.setWorkflowId("testRetryWorkflowId");
    workflow.setWorkflowType("testRetryWorkflowId");
    workflow.setVersion(1);
    workflow.setOwnerApp("junit_testRetryWorkflowId");
    workflow.setStartTime(10L);
    workflow.setEndTime(100L);
    // noinspection unchecked
    workflow.setOutput(Collections.EMPTY_MAP);
    workflow.setStatus(Workflow.WorkflowStatus.FAILED);
    AtomicInteger updateWorkflowCalledCounter = new AtomicInteger(0);
    doAnswer(invocation -> {
        updateWorkflowCalledCounter.incrementAndGet();
        return null;
    }).when(executionDAOFacade).updateWorkflow(any());
    AtomicInteger updateTasksCalledCounter = new AtomicInteger(0);
    doAnswer(invocation -> {
        updateTasksCalledCounter.incrementAndGet();
        return null;
    }).when(executionDAOFacade).updateTasks(any());
    AtomicInteger updateTaskCalledCounter = new AtomicInteger(0);
    doAnswer(invocation -> {
        updateTaskCalledCounter.incrementAndGet();
        return null;
    }).when(executionDAOFacade).updateTask(any());
    // add 2 failed task in 2 forks and 1 cancelled in the 3rd fork
    Task task_1_1 = new Task();
    task_1_1.setTaskId(UUID.randomUUID().toString());
    task_1_1.setSeq(20);
    task_1_1.setRetryCount(1);
    task_1_1.setTaskType(TaskType.SIMPLE.toString());
    task_1_1.setStatus(Status.CANCELED);
    task_1_1.setRetried(true);
    task_1_1.setTaskDefName("task1");
    task_1_1.setWorkflowTask(new WorkflowTask());
    task_1_1.setReferenceTaskName("task1_ref1");
    Task task_1_2 = new Task();
    task_1_2.setTaskId(UUID.randomUUID().toString());
    task_1_2.setSeq(21);
    task_1_2.setRetryCount(1);
    task_1_2.setTaskType(TaskType.SIMPLE.toString());
    task_1_2.setStatus(Status.FAILED);
    task_1_2.setTaskDefName("task1");
    task_1_2.setWorkflowTask(new WorkflowTask());
    task_1_2.setReferenceTaskName("task1_ref1");
    Task task_2_1 = new Task();
    task_2_1.setTaskId(UUID.randomUUID().toString());
    task_2_1.setSeq(22);
    task_2_1.setRetryCount(1);
    task_2_1.setStatus(Status.FAILED);
    task_2_1.setTaskType(TaskType.SIMPLE.toString());
    task_2_1.setTaskDefName("task2");
    task_2_1.setWorkflowTask(new WorkflowTask());
    task_2_1.setReferenceTaskName("task2_ref1");
    Task task_3_1 = new Task();
    task_3_1.setTaskId(UUID.randomUUID().toString());
    task_3_1.setSeq(23);
    task_3_1.setRetryCount(1);
    task_3_1.setStatus(Status.CANCELED);
    task_3_1.setTaskType(TaskType.SIMPLE.toString());
    task_3_1.setTaskDefName("task3");
    task_3_1.setWorkflowTask(new WorkflowTask());
    task_3_1.setReferenceTaskName("task3_ref1");
    Task task_4_1 = new Task();
    task_4_1.setTaskId(UUID.randomUUID().toString());
    task_4_1.setSeq(122);
    task_4_1.setRetryCount(1);
    task_4_1.setStatus(Status.FAILED);
    task_4_1.setTaskType(TaskType.SIMPLE.toString());
    task_4_1.setTaskDefName("task1");
    task_4_1.setWorkflowTask(new WorkflowTask());
    task_4_1.setReferenceTaskName("task4_refABC");
    workflow.getTasks().addAll(Arrays.asList(task_1_1, task_1_2, task_2_1, task_3_1, task_4_1));
    // end of setup
    // when:
    when(executionDAOFacade.getWorkflowById(anyString(), anyBoolean())).thenReturn(workflow);
    WorkflowDef workflowDef = new WorkflowDef();
    when(metadataDAO.getWorkflowDef(anyString(), anyInt())).thenReturn(Optional.of(workflowDef));
    workflowExecutor.retry(workflow.getWorkflowId(), false);
    // when:
    when(executionDAOFacade.getWorkflowById(anyString(), anyBoolean())).thenReturn(workflow);
    assertEquals(Workflow.WorkflowStatus.RUNNING, workflow.getStatus());
    assertEquals(1, updateWorkflowCalledCounter.get());
    assertEquals(1, updateTasksCalledCounter.get());
    assertEquals(0, updateTaskCalledCounter.get());
}
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) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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 29 with WorkflowTask

use of com.netflix.conductor.common.metadata.workflow.WorkflowTask in project conductor by Netflix.

the class TestWorkflowExecutor method testRetryWorkflowMultipleRetries.

@Test
public void testRetryWorkflowMultipleRetries() {
    // setup
    Workflow workflow = new Workflow();
    workflow.setWorkflowId("testRetryWorkflowId");
    workflow.setWorkflowType("testRetryWorkflowId");
    workflow.setVersion(1);
    workflow.setOwnerApp("junit_testRetryWorkflowId");
    workflow.setStartTime(10L);
    workflow.setEndTime(100L);
    // noinspection unchecked
    workflow.setOutput(Collections.EMPTY_MAP);
    workflow.setStatus(Workflow.WorkflowStatus.FAILED);
    Task task_1_1 = new Task();
    task_1_1.setTaskId(UUID.randomUUID().toString());
    task_1_1.setSeq(10);
    task_1_1.setRetryCount(0);
    task_1_1.setTaskType(TaskType.SIMPLE.toString());
    task_1_1.setStatus(Status.FAILED);
    task_1_1.setTaskDefName("task1");
    task_1_1.setWorkflowTask(new WorkflowTask());
    task_1_1.setReferenceTaskName("task1_ref1");
    Task task_2_1 = new Task();
    task_2_1.setTaskId(UUID.randomUUID().toString());
    task_2_1.setSeq(20);
    task_2_1.setRetryCount(0);
    task_2_1.setTaskType(TaskType.SIMPLE.toString());
    task_2_1.setStatus(Status.CANCELED);
    task_2_1.setTaskDefName("task1");
    task_2_1.setWorkflowTask(new WorkflowTask());
    task_2_1.setReferenceTaskName("task2_ref1");
    workflow.getTasks().addAll(Arrays.asList(task_1_1, task_2_1));
    // end of setup
    // when:
    when(executionDAOFacade.getWorkflowById(anyString(), anyBoolean())).thenReturn(workflow);
    WorkflowDef workflowDef = new WorkflowDef();
    when(metadataDAO.getWorkflowDef(anyString(), anyInt())).thenReturn(Optional.of(workflowDef));
    workflowExecutor.retry(workflow.getWorkflowId(), false);
    assertEquals(4, workflow.getTasks().size());
    // Reset Last Workflow Task to FAILED.
    Task lastTask = workflow.getTasks().stream().filter(t -> t.getReferenceTaskName().equals("task1_ref1")).collect(groupingBy(Task::getReferenceTaskName, maxBy(comparingInt(Task::getSeq)))).values().stream().map(Optional::get).collect(Collectors.toList()).get(0);
    lastTask.setStatus(Status.FAILED);
    workflow.setStatus(Workflow.WorkflowStatus.FAILED);
    workflowExecutor.retry(workflow.getWorkflowId(), false);
    assertEquals(5, workflow.getTasks().size());
    // Reset Last Workflow Task to FAILED.
    // Reset Last Workflow Task to FAILED.
    Task lastTask2 = workflow.getTasks().stream().filter(t -> t.getReferenceTaskName().equals("task1_ref1")).collect(groupingBy(Task::getReferenceTaskName, maxBy(comparingInt(Task::getSeq)))).values().stream().map(Optional::get).collect(Collectors.toList()).get(0);
    lastTask2.setStatus(Status.FAILED);
    workflow.setStatus(Workflow.WorkflowStatus.FAILED);
    workflowExecutor.retry(workflow.getWorkflowId(), false);
    assertEquals(6, workflow.getTasks().size());
}
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) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) Optional(java.util.Optional) 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 30 with WorkflowTask

use of com.netflix.conductor.common.metadata.workflow.WorkflowTask in project conductor by Netflix.

the class TestWorkflowExecutor method testUpdateParentWorkflow.

@Test
public void testUpdateParentWorkflow() {
    // Case 1: When Subworkflow is in terminal state
    // 1A: Parent Workflow is IN_PROGRESS
    // Expectation: Parent workflow's Subworkflow task should complete
    String workflowId = "test-workflow-Id";
    String subWorkflowId = "test-subWorkflow-Id";
    String parentWorkflowSubWFTaskId = "test-subworkflow-taskId";
    WorkflowTask subWorkflowTask = new WorkflowTask();
    subWorkflowTask.setWorkflowTaskType(TaskType.SUB_WORKFLOW);
    subWorkflowTask.setType(TaskType.SUB_WORKFLOW.name());
    subWorkflowTask.setTaskReferenceName("sub-workflow");
    Task task = new Task();
    task.setTaskType(subWorkflowTask.getType());
    task.setTaskDefName(subWorkflowTask.getName());
    task.setReferenceTaskName(subWorkflowTask.getTaskReferenceName());
    task.setWorkflowInstanceId(workflowId);
    task.setScheduledTime(System.currentTimeMillis());
    task.setTaskId(parentWorkflowSubWFTaskId);
    task.setStatus(Status.IN_PROGRESS);
    task.setRetryCount(0);
    task.setWorkflowTask(subWorkflowTask);
    task.setOutputData(new HashMap<>());
    task.setSubWorkflowId(subWorkflowId);
    WorkflowDef def = new WorkflowDef();
    def.setName("test");
    Workflow parentWorkflow = new Workflow();
    parentWorkflow.setWorkflowId(workflowId);
    parentWorkflow.setWorkflowDefinition(def);
    parentWorkflow.setStatus(Workflow.WorkflowStatus.RUNNING);
    parentWorkflow.setTasks(Arrays.asList(task));
    Workflow subWorkflow = new Workflow();
    subWorkflow.setWorkflowId("subworkflowId");
    subWorkflow.setStatus(Workflow.WorkflowStatus.COMPLETED);
    subWorkflow.setParentWorkflowTaskId(parentWorkflowSubWFTaskId);
    subWorkflow.setWorkflowId(subWorkflowId);
    when(executionDAOFacade.getTaskById(anyString())).thenReturn(task);
    when(workflowExecutor.getWorkflow(subWorkflowId, false)).thenReturn(subWorkflow);
    workflowExecutor.updateParentWorkflow(task, subWorkflow, parentWorkflow);
    assertEquals(Status.COMPLETED, task.getStatus());
    assertEquals(Workflow.WorkflowStatus.COMPLETED, subWorkflow.getStatus());
    // updateParentWorkflow shouldn't call the decide on workflow, and hence it should still remain IN_PROGRESS
    assertEquals(Workflow.WorkflowStatus.RUNNING, parentWorkflow.getStatus());
    // 1B: Parent Workflow is in FAILED state
    // Expectation: return false
    parentWorkflow.setStatus(Workflow.WorkflowStatus.FAILED);
    assertFalse(workflowExecutor.updateParentWorkflow(task, subWorkflow, parentWorkflow));
    // Case 2: When Subworkflow is in non-terminal state
    // 2A: Parent Workflow is in terminal state
    // Expectation: Parent workflow and subworkflow task should be reset to IN_PROGRESS and RUNNING state respectively.
    subWorkflow.setStatus(Workflow.WorkflowStatus.RUNNING);
    parentWorkflow.setStatus(Workflow.WorkflowStatus.FAILED);
    workflowExecutor.updateParentWorkflow(task, subWorkflow, parentWorkflow);
    assertEquals(Workflow.WorkflowStatus.RUNNING, subWorkflow.getStatus());
    assertEquals(Status.IN_PROGRESS, task.getStatus());
    assertEquals(Workflow.WorkflowStatus.RUNNING, parentWorkflow.getStatus());
    // 2B: Parent Workflow is in non-terminal state
    // Expectation: Parent workflow, Subworkflow and subworkflow task should remain in same state.
    subWorkflow.setStatus(Workflow.WorkflowStatus.RUNNING);
    parentWorkflow.setStatus(Workflow.WorkflowStatus.RUNNING);
    task.setStatus(Status.IN_PROGRESS);
    workflowExecutor.updateParentWorkflow(task, subWorkflow, parentWorkflow);
    assertEquals(Workflow.WorkflowStatus.RUNNING, subWorkflow.getStatus());
    assertEquals(Status.IN_PROGRESS, task.getStatus());
    assertEquals(Workflow.WorkflowStatus.RUNNING, parentWorkflow.getStatus());
}
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) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) Workflow(com.netflix.conductor.common.run.Workflow) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

WorkflowTask (com.netflix.conductor.common.metadata.workflow.WorkflowTask)240 Test (org.junit.Test)166 WorkflowDef (com.netflix.conductor.common.metadata.workflow.WorkflowDef)147 TaskDef (com.netflix.conductor.common.metadata.tasks.TaskDef)106 Workflow (com.netflix.conductor.common.run.Workflow)106 HashMap (java.util.HashMap)102 Task (com.netflix.conductor.common.metadata.tasks.Task)98 ArrayList (java.util.ArrayList)51 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)44 ConstraintViolation (javax.validation.ConstraintViolation)41 LinkedList (java.util.LinkedList)40 List (java.util.List)33 SubWorkflow (com.netflix.conductor.core.execution.tasks.SubWorkflow)32 Map (java.util.Map)25 SubWorkflowParams (com.netflix.conductor.common.metadata.workflow.SubWorkflowParams)24 DynamicForkJoinTaskList (com.netflix.conductor.common.metadata.workflow.DynamicForkJoinTaskList)18 WorkflowSystemTask (com.netflix.conductor.core.execution.tasks.WorkflowSystemTask)14 UserTask (com.netflix.conductor.tests.utils.UserTask)14 ValidatorFactory (javax.validation.ValidatorFactory)13 VisibleForTesting (com.google.common.annotations.VisibleForTesting)11