Search in sources :

Example 21 with WorkflowTask

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

the class DoWhileTest method setup.

@Before
public void setup() {
    workflow = Mockito.mock(Workflow.class);
    deciderService = Mockito.mock(DeciderService.class);
    metadataDAO = Mockito.mock(MetadataDAO.class);
    queueDAO = Mockito.mock(QueueDAO.class);
    parametersUtils = Mockito.mock(ParametersUtils.class);
    metadataMapperService = Mockito.mock(MetadataMapperService.class);
    workflowStatusListener = Mockito.mock(WorkflowStatusListener.class);
    executionDAOFacade = Mockito.mock(ExecutionDAOFacade.class);
    executionLockService = Mockito.mock(ExecutionLockService.class);
    config = Mockito.mock(Configuration.class);
    provider = spy(new WorkflowExecutor(deciderService, metadataDAO, queueDAO, metadataMapperService, workflowStatusListener, executionDAOFacade, config, executionLockService, parametersUtils));
    loopWorkflowTask1 = new WorkflowTask();
    loopWorkflowTask1.setTaskReferenceName("task1");
    loopWorkflowTask1.setName("task1");
    loopWorkflowTask2 = new WorkflowTask();
    loopWorkflowTask2.setTaskReferenceName("task2");
    loopWorkflowTask2.setName("task2");
    task1 = new Task();
    task1.setWorkflowTask(loopWorkflowTask1);
    task1.setReferenceTaskName("task1");
    task1.setStatus(Task.Status.COMPLETED);
    task1.setTaskType(TaskType.HTTP.name());
    task1.setInputData(new HashMap<>());
    task1.setIteration(1);
    task2 = new Task();
    task2.setWorkflowTask(loopWorkflowTask2);
    task2.setReferenceTaskName("task2");
    task2.setStatus(Task.Status.COMPLETED);
    task2.setTaskType(TaskType.HTTP.name());
    task2.setInputData(new HashMap<>());
    task2.setIteration(1);
    loopTask = new Task();
    loopTask.setReferenceTaskName("loopTask");
    loopTask.setTaskType(TaskType.DO_WHILE.name());
    loopTask.setInputData(new HashMap<>());
    loopTask.setIteration(1);
    loopWorkflowTask = new WorkflowTask();
    loopWorkflowTask.setTaskReferenceName("loopTask");
    loopWorkflowTask.setType(TaskType.DO_WHILE.name());
    loopWorkflowTask.setName("loopTask");
    loopWorkflowTask.setLoopCondition("if ($.loopTask['iteration'] < 1) { false; } else { true; }");
    loopWorkflowTask.setLoopOver(Arrays.asList(task1.getWorkflowTask(), task2.getWorkflowTask()));
    loopTask.setWorkflowTask(loopWorkflowTask);
    doWhile = new DoWhile();
    loopTaskDef = Mockito.mock(TaskDef.class);
    Mockito.doReturn(loopTaskDef).when(provider).getTaskDefinition(loopTask);
    Mockito.doReturn(task1).when(workflow).getTaskByRefName(task1.getReferenceTaskName());
    Mockito.doReturn(task2).when(workflow).getTaskByRefName(task2.getReferenceTaskName());
    Mockito.doReturn(task1).when(workflow).getTaskByRefName("task1__2");
    Mockito.doReturn(task2).when(workflow).getTaskByRefName("task2__2");
    Mockito.doReturn(new HashMap<>()).when(parametersUtils).getTaskInputV2(isA(Map.class), isA(Workflow.class), isA(String.class), isA(TaskDef.class));
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Configuration(com.netflix.conductor.core.config.Configuration) DeciderService(com.netflix.conductor.core.execution.DeciderService) Workflow(com.netflix.conductor.common.run.Workflow) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) ExecutionLockService(com.netflix.conductor.service.ExecutionLockService) QueueDAO(com.netflix.conductor.dao.QueueDAO) MetadataMapperService(com.netflix.conductor.core.metadata.MetadataMapperService) WorkflowStatusListener(com.netflix.conductor.core.execution.WorkflowStatusListener) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) ParametersUtils(com.netflix.conductor.core.execution.ParametersUtils) WorkflowExecutor(com.netflix.conductor.core.execution.WorkflowExecutor) ExecutionDAOFacade(com.netflix.conductor.core.orchestration.ExecutionDAOFacade) HashMap(java.util.HashMap) Map(java.util.Map) MetadataDAO(com.netflix.conductor.dao.MetadataDAO) Before(org.junit.Before)

Example 22 with WorkflowTask

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

the class TestWorkflowExecutor method testRerunWorkflowWithTaskId.

@Test
public void testRerunWorkflowWithTaskId() {
    // 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());
    rerunWorkflowRequest.setReRunFromTaskId(task_1_1.getTaskId());
    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 23 with WorkflowTask

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

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

Example 25 with WorkflowTask

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

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