Search in sources :

Example 21 with Task

use of com.netflix.conductor.common.metadata.tasks.Task in project conductor by Netflix.

the class TestWorkflowExecutor method testRestartWorkflow.

@Test
public void testRestartWorkflow() {
    WorkflowTask workflowTask = new WorkflowTask();
    workflowTask.setName("test_task");
    workflowTask.setTaskReferenceName("task_ref");
    WorkflowDef workflowDef = new WorkflowDef();
    workflowDef.setName("testDef");
    workflowDef.setVersion(1);
    workflowDef.setRestartable(true);
    workflowDef.getTasks().addAll(Collections.singletonList(workflowTask));
    Task task_1 = new Task();
    task_1.setTaskId(UUID.randomUUID().toString());
    task_1.setSeq(1);
    task_1.setStatus(Status.FAILED);
    task_1.setTaskDefName(workflowTask.getName());
    task_1.setReferenceTaskName(workflowTask.getTaskReferenceName());
    Task task_2 = new Task();
    task_2.setTaskId(UUID.randomUUID().toString());
    task_2.setSeq(2);
    task_2.setStatus(Status.FAILED);
    task_2.setTaskDefName(workflowTask.getName());
    task_2.setReferenceTaskName(workflowTask.getTaskReferenceName());
    Workflow workflow = new Workflow();
    workflow.setWorkflowDefinition(workflowDef);
    workflow.setWorkflowId("test-workflow-id");
    workflow.getTasks().addAll(Arrays.asList(task_1, task_2));
    workflow.setStatus(Workflow.WorkflowStatus.FAILED);
    when(executionDAOFacade.getWorkflowById(anyString(), anyBoolean())).thenReturn(workflow);
    doNothing().when(executionDAOFacade).removeTask(any());
    when(metadataDAO.getWorkflowDef(workflow.getWorkflowName(), workflow.getWorkflowVersion())).thenReturn(Optional.of(workflowDef));
    when(metadataDAO.getTaskDef(workflowTask.getName())).thenReturn(new TaskDef());
    when(executionDAOFacade.updateWorkflow(any())).thenReturn("");
    workflowExecutor.rewind(workflow.getWorkflowId(), false);
    assertEquals(Workflow.WorkflowStatus.RUNNING, workflow.getStatus());
    verify(metadataDAO, never()).getLatestWorkflowDef(any());
    ArgumentCaptor<Workflow> argumentCaptor = ArgumentCaptor.forClass(Workflow.class);
    verify(executionDAOFacade, times(1)).createWorkflow(argumentCaptor.capture());
    assertEquals(workflow.getWorkflowId(), argumentCaptor.getAllValues().get(0).getWorkflowId());
    assertEquals(workflow.getWorkflowDefinition(), argumentCaptor.getAllValues().get(0).getWorkflowDefinition());
    // add a new version of the workflow definition and restart with latest
    workflow.setStatus(Workflow.WorkflowStatus.COMPLETED);
    workflowDef = new WorkflowDef();
    workflowDef.setName("testDef");
    workflowDef.setVersion(2);
    workflowDef.setRestartable(true);
    workflowDef.getTasks().addAll(Collections.singletonList(workflowTask));
    when(metadataDAO.getLatestWorkflowDef(workflow.getWorkflowName())).thenReturn(Optional.of(workflowDef));
    workflowExecutor.rewind(workflow.getWorkflowId(), true);
    assertEquals(Workflow.WorkflowStatus.RUNNING, workflow.getStatus());
    verify(metadataDAO, times(1)).getLatestWorkflowDef(anyString());
    argumentCaptor = ArgumentCaptor.forClass(Workflow.class);
    verify(executionDAOFacade, times(2)).createWorkflow(argumentCaptor.capture());
    assertEquals(workflow.getWorkflowId(), argumentCaptor.getAllValues().get(1).getWorkflowId());
    assertEquals(workflowDef, argumentCaptor.getAllValues().get(1).getWorkflowDefinition());
}
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) 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 22 with Task

use of com.netflix.conductor.common.metadata.tasks.Task in project conductor by Netflix.

the class TestWorkflowExecutor method testRetryWorkflowNoFailedTasks.

@Test(expected = ApplicationException.class)
public void testRetryWorkflowNoFailedTasks() {
    // 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);
    // 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(1);
    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.setReferenceTaskName("task1_ref1");
    Task task_1_2 = new Task();
    task_1_2.setTaskId(UUID.randomUUID().toString());
    task_1_2.setSeq(2);
    task_1_2.setRetryCount(1);
    task_1_2.setTaskType(TaskType.SIMPLE.toString());
    task_1_2.setStatus(Status.COMPLETED);
    task_1_2.setTaskDefName("task1");
    task_1_2.setReferenceTaskName("task1_ref1");
    workflow.getTasks().addAll(Arrays.asList(task_1_1, task_1_2));
    // 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);
}
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) Test(org.junit.Test)

Example 23 with Task

use of com.netflix.conductor.common.metadata.tasks.Task in project conductor by Netflix.

the class TestWorkflowExecutor method testCancelNonTerminalTasks.

@Test
public void testCancelNonTerminalTasks() {
    WorkflowDef def = new WorkflowDef();
    def.setWorkflowStatusListenerEnabled(true);
    Workflow workflow = generateSampleWorkflow();
    workflow.setWorkflowDefinition(def);
    Task subWorkflowTask = new Task();
    subWorkflowTask.setTaskId(UUID.randomUUID().toString());
    subWorkflowTask.setTaskType(TaskType.SUB_WORKFLOW.name());
    subWorkflowTask.setStatus(Status.IN_PROGRESS);
    Task lambdaTask = new Task();
    lambdaTask.setTaskId(UUID.randomUUID().toString());
    lambdaTask.setTaskType(TaskType.LAMBDA.name());
    lambdaTask.setStatus(Status.SCHEDULED);
    Task simpleTask = new Task();
    simpleTask.setTaskId(UUID.randomUUID().toString());
    simpleTask.setTaskType(TaskType.SIMPLE.name());
    simpleTask.setStatus(Status.COMPLETED);
    workflow.getTasks().addAll(Arrays.asList(subWorkflowTask, lambdaTask, simpleTask));
    List<String> erroredTasks = workflowExecutor.cancelNonTerminalTasks(workflow);
    assertTrue(erroredTasks.isEmpty());
    ArgumentCaptor<Task> argumentCaptor = ArgumentCaptor.forClass(Task.class);
    verify(executionDAOFacade, times(2)).updateTask(argumentCaptor.capture());
    assertEquals(2, argumentCaptor.getAllValues().size());
    assertEquals(TaskType.SUB_WORKFLOW.name(), argumentCaptor.getAllValues().get(0).getTaskType());
    assertEquals(Status.CANCELED, argumentCaptor.getAllValues().get(0).getStatus());
    assertEquals(TaskType.LAMBDA.name(), argumentCaptor.getAllValues().get(1).getTaskType());
    assertEquals(Status.CANCELED, argumentCaptor.getAllValues().get(1).getStatus());
    verify(workflowStatusListener, times(1)).onWorkflowFinalizedIfEnabled(any(Workflow.class));
}
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) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 24 with Task

use of com.netflix.conductor.common.metadata.tasks.Task in project conductor by Netflix.

the class TestWorkflowExecutor method testScheduleTaskFailure.

@Test(expected = TerminateWorkflowException.class)
public void testScheduleTaskFailure() {
    Workflow workflow = new Workflow();
    workflow.setWorkflowId("wid_01");
    List<Task> tasks = new LinkedList<>();
    Task task1 = new Task();
    task1.setTaskType(TaskType.TASK_TYPE_SIMPLE);
    task1.setTaskDefName("task_1");
    task1.setReferenceTaskName("task_1");
    task1.setWorkflowInstanceId(workflow.getWorkflowId());
    task1.setTaskId("tid_01");
    task1.setStatus(Status.SCHEDULED);
    task1.setRetryCount(0);
    tasks.add(task1);
    when(executionDAOFacade.createTasks(tasks)).thenThrow(new RuntimeException());
    workflowExecutor.scheduleTask(workflow, tasks);
}
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) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 25 with Task

use of com.netflix.conductor.common.metadata.tasks.Task in project conductor by Netflix.

the class TestWorkflowExecutor method testScheduleNextIteration.

@Test
public void testScheduleNextIteration() {
    Workflow workflow = generateSampleWorkflow();
    workflow.setTaskToDomain(new HashMap<String, String>() {

        {
            put("TEST", "domain1");
        }
    });
    Task loopTask = mock(Task.class);
    WorkflowTask loopWfTask = mock(WorkflowTask.class);
    when(loopTask.getWorkflowTask()).thenReturn(loopWfTask);
    List<WorkflowTask> loopOver = new ArrayList<WorkflowTask>() {

        {
            WorkflowTask e = new WorkflowTask();
            e.setType(TaskType.TASK_TYPE_SIMPLE);
            e.setName("TEST");
            e.setTaskDefinition(new TaskDef());
            add(e);
        }
    };
    when(loopWfTask.getLoopOver()).thenReturn(loopOver);
    workflowExecutor.scheduleNextIteration(loopTask, workflow);
    verify(executionDAOFacade).getTaskPollDataByDomain("TEST", "domain1");
}
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) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) ArrayList(java.util.ArrayList) 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

Task (com.netflix.conductor.common.metadata.tasks.Task)357 Workflow (com.netflix.conductor.common.run.Workflow)249 Test (org.junit.Test)248 WorkflowTask (com.netflix.conductor.common.metadata.workflow.WorkflowTask)227 HashMap (java.util.HashMap)147 WorkflowDef (com.netflix.conductor.common.metadata.workflow.WorkflowDef)121 SubWorkflow (com.netflix.conductor.core.execution.tasks.SubWorkflow)110 TaskDef (com.netflix.conductor.common.metadata.tasks.TaskDef)95 UserTask (com.netflix.conductor.tests.utils.UserTask)73 Map (java.util.Map)53 LinkedList (java.util.LinkedList)51 WorkflowSystemTask (com.netflix.conductor.core.execution.tasks.WorkflowSystemTask)45 List (java.util.List)45 ApplicationException (com.netflix.conductor.core.execution.ApplicationException)41 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)39 TaskResult (com.netflix.conductor.common.metadata.tasks.TaskResult)38 Status (com.netflix.conductor.common.metadata.tasks.Task.Status)32 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)29 Collectors (java.util.stream.Collectors)29 TaskType (com.netflix.conductor.common.metadata.workflow.TaskType)28