Search in sources :

Example 21 with WorkflowDef

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

the class TestWorkflowExecutor method testQueueExceptionsIgnoredDuringTerminateWorkflow.

@Test
@SuppressWarnings("unchecked")
public void testQueueExceptionsIgnoredDuringTerminateWorkflow() {
    WorkflowDef def = new WorkflowDef();
    def.setName("test");
    def.setWorkflowStatusListenerEnabled(true);
    Workflow workflow = new Workflow();
    workflow.setWorkflowDefinition(def);
    workflow.setWorkflowId("1");
    workflow.setStatus(Workflow.WorkflowStatus.RUNNING);
    workflow.setOwnerApp("junit_test");
    workflow.setStartTime(10L);
    workflow.setEndTime(100L);
    workflow.setOutput(Collections.EMPTY_MAP);
    when(executionDAOFacade.getWorkflowById(anyString(), anyBoolean())).thenReturn(workflow);
    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());
    doThrow(new RuntimeException()).when(queueDAO).remove(anyString(), anyString());
    workflowExecutor.terminateWorkflow("workflowId", "reason");
    assertEquals(Workflow.WorkflowStatus.TERMINATED, workflow.getStatus());
    assertEquals(1, updateWorkflowCalledCounter.get());
    verify(workflowStatusListener, times(1)).onWorkflowTerminatedIfEnabled(any(Workflow.class));
}
Also used : 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) Test(org.junit.Test)

Example 22 with WorkflowDef

use of com.netflix.conductor.common.metadata.workflow.WorkflowDef 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 23 with WorkflowDef

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

the class TestWorkflowExecutor method testRerunWorkflow.

@Test
public void testRerunWorkflow() {
    // setup
    Workflow workflow = new Workflow();
    workflow.setWorkflowId("testRerunWorkflowId");
    workflow.setWorkflowType("testRerunWorkflowId");
    workflow.setVersion(1);
    workflow.setOwnerApp("junit_testRerunWorkflowId");
    workflow.setStartTime(10L);
    workflow.setEndTime(100L);
    // noinspection unchecked
    workflow.setOutput(Collections.EMPTY_MAP);
    workflow.setStatus(Workflow.WorkflowStatus.FAILED);
    workflow.setReasonForIncompletion("task1 failed");
    workflow.setFailedReferenceTaskNames(new HashSet<String>() {

        {
            add("task1_ref1");
        }
    });
    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.setRetried(true);
    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");
    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));
    RerunWorkflowRequest rerunWorkflowRequest = new RerunWorkflowRequest();
    rerunWorkflowRequest.setReRunFromWorkflowId(workflow.getWorkflowId());
    workflowExecutor.rerun(rerunWorkflowRequest);
    // when:
    when(executionDAOFacade.getWorkflowById(anyString(), anyBoolean())).thenReturn(workflow);
    assertEquals(Workflow.WorkflowStatus.RUNNING, workflow.getStatus());
    assertEquals(null, workflow.getReasonForIncompletion());
    assertEquals(new HashSet<>(), workflow.getFailedReferenceTaskNames());
}
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) RerunWorkflowRequest(com.netflix.conductor.common.metadata.workflow.RerunWorkflowRequest) Test(org.junit.Test)

Example 24 with WorkflowDef

use of com.netflix.conductor.common.metadata.workflow.WorkflowDef 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 25 with WorkflowDef

use of com.netflix.conductor.common.metadata.workflow.WorkflowDef 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)

Aggregations

WorkflowDef (com.netflix.conductor.common.metadata.workflow.WorkflowDef)246 Test (org.junit.Test)185 WorkflowTask (com.netflix.conductor.common.metadata.workflow.WorkflowTask)172 Workflow (com.netflix.conductor.common.run.Workflow)128 HashMap (java.util.HashMap)122 Task (com.netflix.conductor.common.metadata.tasks.Task)100 TaskDef (com.netflix.conductor.common.metadata.tasks.TaskDef)71 SubWorkflow (com.netflix.conductor.core.execution.tasks.SubWorkflow)49 ArrayList (java.util.ArrayList)42 LinkedList (java.util.LinkedList)37 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)35 List (java.util.List)33 UserTask (com.netflix.conductor.tests.utils.UserTask)28 Map (java.util.Map)25 SubWorkflowParams (com.netflix.conductor.common.metadata.workflow.SubWorkflowParams)20 ConstraintViolation (javax.validation.ConstraintViolation)14 ApplicationException (com.netflix.conductor.core.execution.ApplicationException)13 ValidatorFactory (javax.validation.ValidatorFactory)13 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)12 DynamicForkJoinTaskList (com.netflix.conductor.common.metadata.workflow.DynamicForkJoinTaskList)12