Search in sources :

Example 6 with DeciderOutcome

use of com.netflix.conductor.core.execution.DeciderService.DeciderOutcome in project conductor by Netflix.

the class TestDeciderOutcomes method testRetries.

@Test
public void testRetries() {
    WorkflowDef def = new WorkflowDef();
    def.setName("test");
    WorkflowTask workflowTask = new WorkflowTask();
    workflowTask.setName("test_task");
    workflowTask.setType("USER_TASK");
    workflowTask.setTaskReferenceName("t0");
    workflowTask.getInputParameters().put("taskId", "${CPEWF_TASK_ID}");
    workflowTask.getInputParameters().put("requestId", "${workflow.input.requestId}");
    workflowTask.setTaskDefinition(new TaskDef("test_task"));
    def.getTasks().add(workflowTask);
    def.setSchemaVersion(2);
    Workflow workflow = new Workflow();
    workflow.setWorkflowDefinition(def);
    workflow.getInput().put("requestId", 123);
    workflow.setStartTime(System.currentTimeMillis());
    DeciderOutcome outcome = deciderService.decide(workflow);
    assertNotNull(outcome);
    assertEquals(1, outcome.tasksToBeScheduled.size());
    assertEquals(workflowTask.getTaskReferenceName(), outcome.tasksToBeScheduled.get(0).getReferenceTaskName());
    String task1Id = outcome.tasksToBeScheduled.get(0).getTaskId();
    assertEquals(task1Id, outcome.tasksToBeScheduled.get(0).getInputData().get("taskId"));
    assertEquals(123, outcome.tasksToBeScheduled.get(0).getInputData().get("requestId"));
    outcome.tasksToBeScheduled.get(0).setStatus(Status.FAILED);
    workflow.getTasks().addAll(outcome.tasksToBeScheduled);
    outcome = deciderService.decide(workflow);
    assertNotNull(outcome);
    assertEquals(1, outcome.tasksToBeUpdated.size());
    assertEquals(1, outcome.tasksToBeScheduled.size());
    assertEquals(task1Id, outcome.tasksToBeUpdated.get(0).getTaskId());
    assertNotSame(task1Id, outcome.tasksToBeScheduled.get(0).getTaskId());
    assertEquals(outcome.tasksToBeScheduled.get(0).getTaskId(), outcome.tasksToBeScheduled.get(0).getInputData().get("taskId"));
    assertEquals(task1Id, outcome.tasksToBeScheduled.get(0).getRetriedTaskId());
    assertEquals(123, outcome.tasksToBeScheduled.get(0).getInputData().get("requestId"));
    WorkflowTask fork = new WorkflowTask();
    fork.setName("fork0");
    fork.setWorkflowTaskType(TaskType.FORK_JOIN_DYNAMIC);
    fork.setTaskReferenceName("fork0");
    fork.setDynamicForkTasksInputParamName("forkedInputs");
    fork.setDynamicForkTasksParam("forks");
    fork.getInputParameters().put("forks", "${workflow.input.forks}");
    fork.getInputParameters().put("forkedInputs", "${workflow.input.forkedInputs}");
    WorkflowTask join = new WorkflowTask();
    join.setName("join0");
    join.setType("JOIN");
    join.setTaskReferenceName("join0");
    def.getTasks().clear();
    def.getTasks().add(fork);
    def.getTasks().add(join);
    List<WorkflowTask> forks = new LinkedList<>();
    Map<String, Map<String, Object>> forkedInputs = new HashMap<>();
    for (int i = 0; i < 1; i++) {
        WorkflowTask wft = new WorkflowTask();
        wft.setName("f" + i);
        wft.setTaskReferenceName("f" + i);
        wft.setWorkflowTaskType(TaskType.SIMPLE);
        wft.getInputParameters().put("requestId", "${workflow.input.requestId}");
        wft.getInputParameters().put("taskId", "${CPEWF_TASK_ID}");
        wft.setTaskDefinition(new TaskDef("f" + i));
        forks.add(wft);
        Map<String, Object> input = new HashMap<>();
        input.put("k", "v");
        input.put("k1", 1);
        forkedInputs.put(wft.getTaskReferenceName(), input);
    }
    workflow = new Workflow();
    workflow.setWorkflowDefinition(def);
    workflow.getInput().put("requestId", 123);
    workflow.setStartTime(System.currentTimeMillis());
    workflow.getInput().put("forks", forks);
    workflow.getInput().put("forkedInputs", forkedInputs);
    outcome = deciderService.decide(workflow);
    assertNotNull(outcome);
    assertEquals(3, outcome.tasksToBeScheduled.size());
    assertEquals(0, outcome.tasksToBeUpdated.size());
    assertEquals("v", outcome.tasksToBeScheduled.get(1).getInputData().get("k"));
    assertEquals(1, outcome.tasksToBeScheduled.get(1).getInputData().get("k1"));
    assertEquals(outcome.tasksToBeScheduled.get(1).getTaskId(), outcome.tasksToBeScheduled.get(1).getInputData().get("taskId"));
    System.out.println(outcome.tasksToBeScheduled.get(1).getInputData());
    task1Id = outcome.tasksToBeScheduled.get(1).getTaskId();
    outcome.tasksToBeScheduled.get(1).setStatus(Status.FAILED);
    for (Task taskToBeScheduled : outcome.tasksToBeScheduled) {
        taskToBeScheduled.setUpdateTime(System.currentTimeMillis());
    }
    workflow.getTasks().addAll(outcome.tasksToBeScheduled);
    outcome = deciderService.decide(workflow);
    assertTrue(outcome.tasksToBeScheduled.stream().anyMatch(task1 -> task1.getReferenceTaskName().equals("f0")));
    // noinspection ConstantConditions
    Task task1 = outcome.tasksToBeScheduled.stream().filter(t -> t.getReferenceTaskName().equals("f0")).findFirst().get();
    assertEquals("v", task1.getInputData().get("k"));
    assertEquals(1, task1.getInputData().get("k1"));
    assertEquals(task1.getTaskId(), task1.getInputData().get("taskId"));
    assertNotSame(task1Id, task1.getTaskId());
    assertEquals(task1Id, task1.getRetriedTaskId());
    System.out.println(task1.getInputData());
}
Also used : Arrays(java.util.Arrays) TaskMapper(com.netflix.conductor.core.execution.mapper.TaskMapper) Join(com.netflix.conductor.core.execution.tasks.Join) ForkJoinDynamicTaskMapper(com.netflix.conductor.core.execution.mapper.ForkJoinDynamicTaskMapper) Assert.assertNotSame(org.junit.Assert.assertNotSame) Status(com.netflix.conductor.common.metadata.tasks.Task.Status) HashMap(java.util.HashMap) MetadataDAO(com.netflix.conductor.dao.MetadataDAO) Task(com.netflix.conductor.common.metadata.tasks.Task) SimpleTaskMapper(com.netflix.conductor.core.execution.mapper.SimpleTaskMapper) DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) ExternalPayloadStorageUtils(com.netflix.conductor.core.utils.ExternalPayloadStorageUtils) UserDefinedTaskMapper(com.netflix.conductor.core.execution.mapper.UserDefinedTaskMapper) WaitTaskMapper(com.netflix.conductor.core.execution.mapper.WaitTaskMapper) Workflow(com.netflix.conductor.common.run.Workflow) Map(java.util.Map) JoinTaskMapper(com.netflix.conductor.core.execution.mapper.JoinTaskMapper) LinkedList(java.util.LinkedList) Before(org.junit.Before) ForkJoinTaskMapper(com.netflix.conductor.core.execution.mapper.ForkJoinTaskMapper) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) SubWorkflowTaskMapper(com.netflix.conductor.core.execution.mapper.SubWorkflowTaskMapper) HTTPTaskMapper(com.netflix.conductor.core.execution.mapper.HTTPTaskMapper) DecisionTaskMapper(com.netflix.conductor.core.execution.mapper.DecisionTaskMapper) DynamicTaskMapper(com.netflix.conductor.core.execution.mapper.DynamicTaskMapper) Assert.assertNotNull(org.junit.Assert.assertNotNull) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Assert.assertTrue(org.junit.Assert.assertTrue) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) Include(com.fasterxml.jackson.annotation.JsonInclude.Include) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) DeciderOutcome(com.netflix.conductor.core.execution.DeciderService.DeciderOutcome) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) TaskType(com.netflix.conductor.common.metadata.workflow.TaskType) EventTaskMapper(com.netflix.conductor.core.execution.mapper.EventTaskMapper) Configuration(com.netflix.conductor.core.config.Configuration) JsonMapperProvider(com.netflix.conductor.common.utils.JsonMapperProvider) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.mock(org.mockito.Mockito.mock) InputStream(java.io.InputStream) Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) HashMap(java.util.HashMap) Workflow(com.netflix.conductor.common.run.Workflow) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) LinkedList(java.util.LinkedList) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) DeciderOutcome(com.netflix.conductor.core.execution.DeciderService.DeciderOutcome) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 7 with DeciderOutcome

use of com.netflix.conductor.core.execution.DeciderService.DeciderOutcome in project conductor by Netflix.

the class TestDeciderService method testDecideSuccessfulWorkflow.

@Test
public void testDecideSuccessfulWorkflow() {
    WorkflowDef workflowDef = createLinearWorkflow();
    Workflow workflow = new Workflow();
    workflow.setWorkflowDefinition(workflowDef);
    workflow.setStatus(WorkflowStatus.RUNNING);
    Task task1 = new Task();
    task1.setTaskType("junit_task_l1");
    task1.setReferenceTaskName("s1");
    task1.setSeq(1);
    task1.setRetried(false);
    task1.setExecuted(false);
    task1.setStatus(Status.COMPLETED);
    workflow.getTasks().add(task1);
    DeciderOutcome deciderOutcome = deciderService.decide(workflow);
    assertNotNull(deciderOutcome);
    assertFalse(workflow.getTaskByRefName("s1").isRetried());
    assertEquals(1, deciderOutcome.tasksToBeUpdated.size());
    assertEquals("s1", deciderOutcome.tasksToBeUpdated.get(0).getReferenceTaskName());
    assertEquals(1, deciderOutcome.tasksToBeScheduled.size());
    assertEquals("s2", deciderOutcome.tasksToBeScheduled.get(0).getReferenceTaskName());
    assertFalse(deciderOutcome.isComplete);
    Task task2 = new Task();
    task2.setTaskType("junit_task_l2");
    task2.setReferenceTaskName("s2");
    task2.setSeq(2);
    task2.setRetried(false);
    task2.setExecuted(false);
    task2.setStatus(Status.COMPLETED);
    workflow.getTasks().add(task2);
    deciderOutcome = deciderService.decide(workflow);
    assertNotNull(deciderOutcome);
    assertTrue(workflow.getTaskByRefName("s2").isExecuted());
    assertFalse(workflow.getTaskByRefName("s2").isRetried());
    assertEquals(1, deciderOutcome.tasksToBeUpdated.size());
    assertEquals("s2", deciderOutcome.tasksToBeUpdated.get(0).getReferenceTaskName());
    assertEquals(0, deciderOutcome.tasksToBeScheduled.size());
    assertTrue(deciderOutcome.isComplete);
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) Workflow(com.netflix.conductor.common.run.Workflow) DeciderOutcome(com.netflix.conductor.core.execution.DeciderService.DeciderOutcome) Test(org.junit.Test)

Example 8 with DeciderOutcome

use of com.netflix.conductor.core.execution.DeciderService.DeciderOutcome in project conductor by Netflix.

the class TestDeciderService method testCaseStatement.

@Test
public void testCaseStatement() {
    WorkflowDef def = createConditionalWF();
    Workflow wf = new Workflow();
    wf.setWorkflowDefinition(def);
    wf.setCreateTime(0L);
    wf.setWorkflowId("a");
    wf.setCorrelationId("b");
    wf.setStatus(WorkflowStatus.RUNNING);
    DeciderOutcome outcome = deciderService.decide(wf);
    List<Task> scheduledTasks = outcome.tasksToBeScheduled;
    assertNotNull(scheduledTasks);
    assertEquals(2, scheduledTasks.size());
    assertEquals(Status.IN_PROGRESS, scheduledTasks.get(0).getStatus());
    assertEquals(Status.SCHEDULED, scheduledTasks.get(1).getStatus());
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) Workflow(com.netflix.conductor.common.run.Workflow) DeciderOutcome(com.netflix.conductor.core.execution.DeciderService.DeciderOutcome) Test(org.junit.Test)

Example 9 with DeciderOutcome

use of com.netflix.conductor.core.execution.DeciderService.DeciderOutcome in project conductor by Netflix.

the class TestDeciderService method testDecideWithLoopTask.

@Test
public void testDecideWithLoopTask() {
    WorkflowDef workflowDef = createLinearWorkflow();
    Workflow workflow = new Workflow();
    workflow.setWorkflowDefinition(workflowDef);
    workflow.setStatus(WorkflowStatus.RUNNING);
    Task task1 = new Task();
    task1.setTaskType("junit_task_l1");
    task1.setReferenceTaskName("s1");
    task1.setSeq(1);
    task1.setIteration(1);
    task1.setRetried(false);
    task1.setExecuted(false);
    task1.setStatus(Status.COMPLETED);
    workflow.getTasks().add(task1);
    DeciderOutcome deciderOutcome = deciderService.decide(workflow);
    assertNotNull(deciderOutcome);
    assertFalse(workflow.getTaskByRefName("s1").isRetried());
    assertEquals(1, deciderOutcome.tasksToBeUpdated.size());
    assertEquals("s1", deciderOutcome.tasksToBeUpdated.get(0).getReferenceTaskName());
    assertEquals(1, deciderOutcome.tasksToBeScheduled.size());
    assertEquals("s2__1", deciderOutcome.tasksToBeScheduled.get(0).getReferenceTaskName());
    assertFalse(deciderOutcome.isComplete);
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) Workflow(com.netflix.conductor.common.run.Workflow) DeciderOutcome(com.netflix.conductor.core.execution.DeciderService.DeciderOutcome) Test(org.junit.Test)

Example 10 with DeciderOutcome

use of com.netflix.conductor.core.execution.DeciderService.DeciderOutcome in project conductor by Netflix.

the class TestDeciderService method testDecideFailedTask.

@Test
public void testDecideFailedTask() {
    WorkflowDef workflowDef = createLinearWorkflow();
    Workflow workflow = new Workflow();
    workflow.setWorkflowDefinition(workflowDef);
    workflow.setStatus(WorkflowStatus.RUNNING);
    Task task = new Task();
    task.setTaskType("junit_task_l1");
    task.setReferenceTaskName("s1");
    task.setSeq(1);
    task.setRetried(false);
    task.setExecuted(false);
    task.setStatus(Status.FAILED);
    WorkflowTask workflowTask = new WorkflowTask();
    workflowTask.setTaskReferenceName("s1");
    workflowTask.setName("junit_task_l1");
    workflowTask.setTaskDefinition(new TaskDef("junit_task_l1"));
    task.setWorkflowTask(workflowTask);
    workflow.getTasks().add(task);
    DeciderOutcome deciderOutcome = deciderService.decide(workflow);
    assertNotNull(deciderOutcome);
    assertFalse(workflow.getTaskByRefName("s1").isExecuted());
    assertTrue(workflow.getTaskByRefName("s1").isRetried());
    assertEquals(1, deciderOutcome.tasksToBeUpdated.size());
    assertEquals("s1", deciderOutcome.tasksToBeUpdated.get(0).getReferenceTaskName());
    assertEquals(1, deciderOutcome.tasksToBeScheduled.size());
    assertEquals("s1", deciderOutcome.tasksToBeScheduled.get(0).getReferenceTaskName());
    assertFalse(deciderOutcome.isComplete);
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) Workflow(com.netflix.conductor.common.run.Workflow) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) DeciderOutcome(com.netflix.conductor.core.execution.DeciderService.DeciderOutcome) Test(org.junit.Test)

Aggregations

Workflow (com.netflix.conductor.common.run.Workflow)10 DeciderOutcome (com.netflix.conductor.core.execution.DeciderService.DeciderOutcome)10 Test (org.junit.Test)10 WorkflowDef (com.netflix.conductor.common.metadata.workflow.WorkflowDef)9 WorkflowTask (com.netflix.conductor.common.metadata.workflow.WorkflowTask)8 Task (com.netflix.conductor.common.metadata.tasks.Task)6 TaskDef (com.netflix.conductor.common.metadata.tasks.TaskDef)5 InputStream (java.io.InputStream)4 Include (com.fasterxml.jackson.annotation.JsonInclude.Include)2 DeserializationFeature (com.fasterxml.jackson.databind.DeserializationFeature)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Status (com.netflix.conductor.common.metadata.tasks.Task.Status)2 TaskType (com.netflix.conductor.common.metadata.workflow.TaskType)2 JsonMapperProvider (com.netflix.conductor.common.utils.JsonMapperProvider)2 Configuration (com.netflix.conductor.core.config.Configuration)2 DecisionTaskMapper (com.netflix.conductor.core.execution.mapper.DecisionTaskMapper)2 DynamicTaskMapper (com.netflix.conductor.core.execution.mapper.DynamicTaskMapper)2 EventTaskMapper (com.netflix.conductor.core.execution.mapper.EventTaskMapper)2 ForkJoinDynamicTaskMapper (com.netflix.conductor.core.execution.mapper.ForkJoinDynamicTaskMapper)2 ForkJoinTaskMapper (com.netflix.conductor.core.execution.mapper.ForkJoinTaskMapper)2