Search in sources :

Example 31 with Task

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

Example 32 with Task

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

the class TestWorkflowRepairService method verifyAndRepairSystemTask.

@Test
public void verifyAndRepairSystemTask() {
    Task task = new Task();
    task.setTaskType("TEST_SYS_TASK");
    task.setStatus(Task.Status.SCHEDULED);
    task.setTaskId("abcd");
    task.setCallbackAfterSeconds(60);
    // Create a Custom system task to init WorkflowSystemTask registry.
    WorkflowSystemTask workflowSystemTask = new WorkflowSystemTask("TEST_SYS_TASK") {

        @Override
        public boolean isAsync() {
            return true;
        }

        @Override
        public boolean isAsyncComplete(Task task) {
            return false;
        }

        @Override
        public void start(Workflow workflow, Task task, WorkflowExecutor executor) {
            super.start(workflow, task, executor);
        }
    };
    when(queueDAO.containsMessage(anyString(), anyString())).thenReturn(false);
    assertTrue(workflowRepairService.verifyAndRepairTask(task));
    // Verify that a new queue message is pushed for tasks that fails queue contains check.
    verify(queueDAO, times(1)).push(anyString(), anyString(), anyLong());
    // Verify a system task in IN_PROGRESS state can be recovered.
    Mockito.reset(queueDAO);
    task.setStatus(Task.Status.IN_PROGRESS);
    assertTrue(workflowRepairService.verifyAndRepairTask(task));
    // Verify that a new queue message is pushed for async System task in IN_PROGRESS state that fails queue contains check.
    verify(queueDAO, times(1)).push(anyString(), anyString(), anyLong());
}
Also used : WorkflowSystemTask(com.netflix.conductor.core.execution.tasks.WorkflowSystemTask) Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowSystemTask(com.netflix.conductor.core.execution.tasks.WorkflowSystemTask) SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) Workflow(com.netflix.conductor.common.run.Workflow) Test(org.junit.Test)

Example 33 with Task

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

the class TestWorkflowRepairService method assertAsyncCompleteSystemTasksAreNotCheckedAgainstQueue.

@Test
public void assertAsyncCompleteSystemTasksAreNotCheckedAgainstQueue() {
    Task task = new Task();
    task.setTaskType("SUB_WORKFLOW");
    task.setStatus(Task.Status.IN_PROGRESS);
    task.setTaskId("abcd");
    task.setCallbackAfterSeconds(60);
    WorkflowSystemTask workflowSystemTask = new SubWorkflow();
    assertTrue(workflowSystemTask.isAsyncComplete(task));
    assertFalse(workflowRepairService.verifyAndRepairTask(task));
    // Verify that queue message is never pushed for async complete system tasks
    verify(queueDAO, never()).containsMessage(anyString(), anyString());
    verify(queueDAO, never()).push(anyString(), anyString(), anyLong());
}
Also used : WorkflowSystemTask(com.netflix.conductor.core.execution.tasks.WorkflowSystemTask) SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowSystemTask(com.netflix.conductor.core.execution.tasks.WorkflowSystemTask) Test(org.junit.Test)

Example 34 with Task

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

the class TestEvent method testDynamicSinks.

@Test
public void testDynamicSinks() {
    Event event = new Event(eventQueues, parametersUtils, objectMapper);
    Workflow workflow = new Workflow();
    workflow.setWorkflowDefinition(testWorkflowDefinition);
    Task task = new Task();
    task.setReferenceTaskName("task0");
    task.setTaskId("task_id_0");
    task.setStatus(Status.IN_PROGRESS);
    task.getInputData().put("sink", "conductor:some_arbitary_queue");
    ObservableQueue queue = event.getQueue(workflow, task);
    assertEquals(Task.Status.IN_PROGRESS, task.getStatus());
    assertNotNull(queue);
    assertEquals("testWorkflow:some_arbitary_queue", queue.getName());
    assertEquals("testWorkflow:some_arbitary_queue", queue.getURI());
    assertEquals("conductor", queue.getType());
    assertEquals("conductor:testWorkflow:some_arbitary_queue", task.getOutputData().get("event_produced"));
    task.getInputData().put("sink", "conductor");
    queue = event.getQueue(workflow, task);
    assertEquals("not in progress: " + task.getReasonForIncompletion(), Task.Status.IN_PROGRESS, task.getStatus());
    assertNotNull(queue);
    assertEquals("testWorkflow:task0", queue.getName());
    task.getInputData().put("sink", "sqs:my_sqs_queue_name");
    queue = event.getQueue(workflow, task);
    assertEquals("not in progress: " + task.getReasonForIncompletion(), Task.Status.IN_PROGRESS, task.getStatus());
    assertNotNull(queue);
    assertEquals("my_sqs_queue_name", queue.getName());
    assertEquals("sqs", queue.getType());
    task.getInputData().put("sink", "sns:my_sqs_queue_name");
    queue = event.getQueue(workflow, task);
    assertEquals(Task.Status.FAILED, task.getStatus());
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) ObservableQueue(com.netflix.conductor.core.events.queue.ObservableQueue) Workflow(com.netflix.conductor.common.run.Workflow) Test(org.junit.Test)

Example 35 with Task

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

the class TestSubWorkflow method testExecuteWorkflowStatus.

@Test
public void testExecuteWorkflowStatus() {
    WorkflowDef workflowDef = new WorkflowDef();
    Workflow workflowInstance = new Workflow();
    Workflow subWorkflowInstance = new Workflow();
    workflowInstance.setWorkflowDefinition(workflowDef);
    Map<String, String> taskToDomain = new HashMap<String, String>() {

        {
            put("*", "unittest");
        }
    };
    Task task = new Task();
    Map<String, Object> outputData = new HashMap<>();
    task.setOutputData(outputData);
    task.setSubWorkflowId("sub-workflow-id");
    Map<String, Object> inputData = new HashMap<>();
    inputData.put("subWorkflowName", "UnitWorkFlow");
    inputData.put("subWorkflowVersion", 2);
    inputData.put("subWorkflowTaskToDomain", taskToDomain);
    task.setInputData(inputData);
    when(workflowExecutor.startWorkflow(eq("UnitWorkFlow"), eq(2), eq(inputData), eq(null), any(), any(), any(), eq(null), eq(taskToDomain))).thenReturn("workflow_1");
    when(workflowExecutor.getWorkflow(eq("sub-workflow-id"), eq(false))).thenReturn(subWorkflowInstance);
    subWorkflowInstance.setStatus(Workflow.WorkflowStatus.RUNNING);
    assertFalse(subWorkflow.execute(workflowInstance, task, workflowExecutor));
    assertNull(task.getStatus());
    assertNull(task.getReasonForIncompletion());
    subWorkflowInstance.setStatus(Workflow.WorkflowStatus.PAUSED);
    assertFalse(subWorkflow.execute(workflowInstance, task, workflowExecutor));
    assertNull(task.getStatus());
    assertNull(task.getReasonForIncompletion());
    subWorkflowInstance.setStatus(Workflow.WorkflowStatus.COMPLETED);
    assertTrue(subWorkflow.execute(workflowInstance, task, workflowExecutor));
    assertEquals(Task.Status.COMPLETED, task.getStatus());
    assertNull(task.getReasonForIncompletion());
    subWorkflowInstance.setStatus(Workflow.WorkflowStatus.FAILED);
    subWorkflowInstance.setReasonForIncompletion("unit1");
    assertTrue(subWorkflow.execute(workflowInstance, task, workflowExecutor));
    assertEquals(Task.Status.FAILED, task.getStatus());
    assertEquals("unit1", task.getReasonForIncompletion());
    subWorkflowInstance.setStatus(Workflow.WorkflowStatus.TIMED_OUT);
    subWorkflowInstance.setReasonForIncompletion("unit2");
    assertTrue(subWorkflow.execute(workflowInstance, task, workflowExecutor));
    assertEquals(Task.Status.TIMED_OUT, task.getStatus());
    assertEquals("unit2", task.getReasonForIncompletion());
    subWorkflowInstance.setStatus(Workflow.WorkflowStatus.TERMINATED);
    subWorkflowInstance.setReasonForIncompletion("unit3");
    assertTrue(subWorkflow.execute(workflowInstance, task, workflowExecutor));
    assertEquals(Task.Status.CANCELED, task.getStatus());
    assertEquals("unit3", task.getReasonForIncompletion());
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) HashMap(java.util.HashMap) Workflow(com.netflix.conductor.common.run.Workflow) 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