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());
}
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);
}
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());
}
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);
}
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);
}
Aggregations