use of com.netflix.conductor.common.run.Workflow in project conductor by Netflix.
the class TestDeciderService method testDeciderGetNextTask.
@Test
public void testDeciderGetNextTask() {
WorkflowDef workflowDef = createDoWhileInForkWorkflow();
Workflow workflow = new Workflow();
workflow.setWorkflowDefinition(workflowDef);
Task task1 = new Task();
task1.setReferenceTaskName("fork");
task1.setStatus(Status.COMPLETED);
task1.setTaskId("task1");
Task task2 = new Task();
task2.setReferenceTaskName("loopTask");
task2.setStatus(Status.SCHEDULED);
task2.setTaskId("task2");
task2.setIteration(1);
Task task3 = new Task();
task3.setReferenceTaskName("junit_task_0__1");
task3.setStatus(Status.COMPLETED);
task3.setTaskId("task3");
task3.setIteration(1);
Task task4 = new Task();
task4.setReferenceTaskName("junit_task_3");
task4.setStatus(Status.COMPLETED);
task4.setTaskId("task4");
Task task5 = new Task();
task5.setReferenceTaskName("join");
task5.setStatus(Status.IN_PROGRESS);
task5.setTaskId("task5");
workflow.setTasks(Arrays.asList(task1, task2, task3, task4, task5));
// verify the next task of first task in DoWhile
List<Task> nextTask1 = deciderService.getNextTask(workflow, task3);
assertEquals(1, nextTask1.size());
assertEquals("junit_task_1", nextTask1.get(0).getReferenceTaskName());
Task task6 = new Task();
task6.setReferenceTaskName("junit_task_1__1");
task6.setStatus(Status.COMPLETED);
task6.setTaskId("task6");
task6.setIteration(1);
workflow.setTasks(Arrays.asList(task1, task2, task3, task4, task5, task6));
// verify the next task of last task in DoWhile
List<Task> nextTask2 = deciderService.getNextTask(workflow, task6);
assertEquals(0, nextTask2.size());
task2.setStatus(Status.COMPLETED);
task2.setIteration(10);
// verify the next task of DoWhile
List<Task> nextTask3 = deciderService.getNextTask(workflow, task2);
assertEquals(1, nextTask3.size());
assertEquals("junit_task_2", nextTask3.get(0).getReferenceTaskName());
}
use of com.netflix.conductor.common.run.Workflow in project conductor by Netflix.
the class TestDeciderService method testFork.
@Test
public void testFork() throws IOException {
InputStream stream = TestDeciderService.class.getResourceAsStream("/test.json");
Workflow workflow = objectMapper.readValue(stream, Workflow.class);
DeciderOutcome outcome = deciderService.decide(workflow);
assertFalse(outcome.isComplete);
assertEquals(5, outcome.tasksToBeScheduled.size());
assertEquals(1, outcome.tasksToBeUpdated.size());
}
use of com.netflix.conductor.common.run.Workflow in project conductor by Netflix.
the class TestDeciderService method testGetTaskInputV2.
@Test
public void testGetTaskInputV2() {
Workflow workflow = createDefaultWorkflow();
workflow.getWorkflowDefinition().setSchemaVersion(2);
Map<String, Object> ip = new HashMap<>();
ip.put("workflowInputParam", "${workflow.input.requestId}");
ip.put("taskOutputParam", "${task2.output.location}");
ip.put("taskOutputParam2", "${task2.output.locationBad}");
ip.put("taskOutputParam3", "${task3.output.location}");
ip.put("constParam", "Some String value");
ip.put("nullValue", null);
ip.put("task2Status", "${task2.status}");
ip.put("channelMap", "${workflow.input.channelMapping}");
Map<String, Object> taskInput = parametersUtils.getTaskInput(ip, workflow, null, null);
assertNotNull(taskInput);
assertTrue(taskInput.containsKey("workflowInputParam"));
assertTrue(taskInput.containsKey("taskOutputParam"));
assertTrue(taskInput.containsKey("taskOutputParam2"));
assertTrue(taskInput.containsKey("taskOutputParam3"));
assertNull(taskInput.get("taskOutputParam2"));
assertNotNull(taskInput.get("channelMap"));
assertEquals(5, taskInput.get("channelMap"));
assertEquals("request id 001", taskInput.get("workflowInputParam"));
assertEquals("http://location", taskInput.get("taskOutputParam"));
assertNull(taskInput.get("taskOutputParam3"));
assertNull(taskInput.get("nullValue"));
// task2 and task3 are the tasks respectively
assertEquals(workflow.getTasks().get(0).getStatus().name(), taskInput.get("task2Status"));
}
use of com.netflix.conductor.common.run.Workflow in project conductor by Netflix.
the class TestDeciderService method testCheckForWorkflowCompletion.
@Test
public void testCheckForWorkflowCompletion() {
WorkflowDef conditionalWorkflowDef = createConditionalWF();
WorkflowTask terminateWT = new WorkflowTask();
terminateWT.setType(TaskType.TERMINATE.name());
terminateWT.setTaskReferenceName("terminate");
terminateWT.setName("terminate");
terminateWT.getInputParameters().put("terminationStatus", "COMPLETED");
conditionalWorkflowDef.getTasks().add(terminateWT);
// when workflow has no tasks
Workflow workflow = new Workflow();
workflow.setWorkflowDefinition(conditionalWorkflowDef);
// then workflow completion check returns false
assertFalse(deciderService.checkForWorkflowCompletion(workflow));
// when only part of the tasks are completed
Task decTask = new Task();
decTask.setTaskType(TaskType.DECISION.name());
decTask.setReferenceTaskName("conditional2");
decTask.setStatus(Status.COMPLETED);
Task task1 = new Task();
decTask.setTaskType(TaskType.SIMPLE.name());
task1.setReferenceTaskName("t1");
task1.setStatus(Status.COMPLETED);
workflow.getTasks().addAll(Arrays.asList(decTask, task1));
// then workflow completion check returns false
assertFalse(deciderService.checkForWorkflowCompletion(workflow));
// when the terminate task is COMPLETED
Task task2 = new Task();
decTask.setTaskType(TaskType.SIMPLE.name());
task2.setReferenceTaskName("t2");
task2.setStatus(Status.SCHEDULED);
Task terminateTask = new Task();
decTask.setTaskType(TaskType.TERMINATE.name());
terminateTask.setReferenceTaskName("terminate");
terminateTask.setStatus(Status.COMPLETED);
workflow.getTasks().addAll(Arrays.asList(task2, terminateTask));
// then the workflow completion check returns true
assertTrue(deciderService.checkForWorkflowCompletion(workflow));
}
use of com.netflix.conductor.common.run.Workflow in project conductor by Netflix.
the class TestDeciderService method testCustomRetryWithWorkflowTask.
@Test
public void testCustomRetryWithWorkflowTask() {
Workflow workflow = createDefaultWorkflow();
Task task = new Task();
task.setStatus(Status.FAILED);
task.setTaskId("t1");
task.setStartDelayInSeconds(30);
TaskDef taskDef = new TaskDef();
taskDef.setRetryDelaySeconds(60);
taskDef.setRetryLogic(TaskDef.RetryLogic.CUSTOM);
WorkflowTask workflowTask = new WorkflowTask();
workflowTask.setRetryLogic(RetryLogic.FIXED);
workflowTask.setStartDelay(80);
// Retry delay from the task as tasDef retry policy is CUSTOM,
// but workflow task would be preferred which is FIXED (retryDelay will come from workflowTask)
Optional<Task> task2 = deciderService.retry(taskDef, workflowTask, task, workflow);
assertEquals(80, task2.get().getStartDelayInSeconds());
// Retry delay from the task as tasDef retry policy is CUSTOM,
// but workflow task would be preferred which is CUSTOM (retryDelay will be 0 since task.retryDelay = -1)
task2.get().setStartDelayInSeconds(-1);
workflowTask.setRetryLogic(RetryLogic.CUSTOM);
workflowTask.setStartDelay(90);
// Custom retry policy from Workflow,
Optional<Task> task3 = deciderService.retry(taskDef, workflowTask, task2.get(), workflow);
assertEquals(0, task3.get().getStartDelayInSeconds());
// Retry delay from the task as tasDef retry policy is CUSTOM,
// workflow task would be preferred which is CUSTOM (retryDelay will come from the workflowTask,
// since task.retryDelay = 0)
task3.get().setStartDelayInSeconds(0);
Optional<Task> task4 = deciderService.retry(taskDef, workflowTask, task3.get(), workflow);
assertEquals(90, task4.get().getCallbackAfterSeconds());
}
Aggregations