use of com.netflix.conductor.common.metadata.workflow.WorkflowDef 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.metadata.workflow.WorkflowDef in project conductor by Netflix.
the class TestDeciderService method createDefaultWorkflow.
private Workflow createDefaultWorkflow() {
WorkflowDef workflowDef = new WorkflowDef();
workflowDef.setName("TestDeciderService");
workflowDef.setVersion(1);
Workflow workflow = new Workflow();
workflow.setWorkflowDefinition(workflowDef);
workflow.getInput().put("requestId", "request id 001");
workflow.getInput().put("hasAwards", true);
workflow.getInput().put("channelMapping", 5);
Map<String, Object> name = new HashMap<>();
name.put("name", "The Who");
name.put("year", 1970);
Map<String, Object> name2 = new HashMap<>();
name2.put("name", "The Doors");
name2.put("year", 1975);
List<Object> names = new LinkedList<>();
names.add(name);
names.add(name2);
workflow.getOutput().put("name", name);
workflow.getOutput().put("names", names);
workflow.getOutput().put("awards", 200);
Task task = new Task();
task.setReferenceTaskName("task2");
task.getOutputData().put("location", "http://location");
task.setStatus(Status.COMPLETED);
Task task2 = new Task();
task2.setReferenceTaskName("task3");
task2.getOutputData().put("refId", "abcddef_1234_7890_aaffcc");
task2.setStatus(Status.SCHEDULED);
workflow.getTasks().add(task);
workflow.getTasks().add(task2);
return workflow;
}
use of com.netflix.conductor.common.metadata.workflow.WorkflowDef in project conductor by Netflix.
the class TestDeciderService method createNestedWorkflow.
private WorkflowDef createNestedWorkflow() {
WorkflowDef workflowDef = new WorkflowDef();
workflowDef.setName("Nested Workflow");
workflowDef.setDescription(workflowDef.getName());
workflowDef.setVersion(1);
workflowDef.setInputParameters(Arrays.asList("param1", "param2"));
Map<String, Object> inputParams = new HashMap<>();
inputParams.put("p1", "workflow.input.param1");
inputParams.put("p2", "workflow.input.param2");
List<WorkflowTask> tasks = new ArrayList<>(10);
for (int i = 0; i < 10; i++) {
WorkflowTask workflowTask = new WorkflowTask();
workflowTask.setName("junit_task_" + i);
workflowTask.setInputParameters(inputParams);
workflowTask.setTaskReferenceName("t" + i);
workflowTask.setTaskDefinition(new TaskDef("junit_task_" + i));
tasks.add(workflowTask);
}
WorkflowTask decisionTask = new WorkflowTask();
decisionTask.setType(TaskType.DECISION.name());
decisionTask.setName("Decision");
decisionTask.setTaskReferenceName("d1");
decisionTask.setDefaultCase(Collections.singletonList(tasks.get(8)));
decisionTask.setCaseValueParam("case");
Map<String, List<WorkflowTask>> decisionCases = new HashMap<>();
decisionCases.put("a", Arrays.asList(tasks.get(6), tasks.get(9)));
decisionCases.put("b", Collections.singletonList(tasks.get(7)));
decisionTask.setDecisionCases(decisionCases);
WorkflowDef subWorkflowDef = createLinearWorkflow();
WorkflowTask subWorkflow = new WorkflowTask();
subWorkflow.setType(TaskType.SUB_WORKFLOW.name());
subWorkflow.setName("sw1");
SubWorkflowParams subWorkflowParams = new SubWorkflowParams();
subWorkflowParams.setName(subWorkflowDef.getName());
subWorkflow.setSubWorkflowParam(subWorkflowParams);
subWorkflow.setTaskReferenceName("sw1");
WorkflowTask forkTask2 = new WorkflowTask();
forkTask2.setType(TaskType.FORK_JOIN.name());
forkTask2.setName("second fork");
forkTask2.setTaskReferenceName("fork2");
forkTask2.getForkTasks().add(Arrays.asList(tasks.get(2), tasks.get(4)));
forkTask2.getForkTasks().add(Arrays.asList(tasks.get(3), decisionTask));
WorkflowTask joinTask2 = new WorkflowTask();
joinTask2.setName("join2");
joinTask2.setType(TaskType.JOIN.name());
joinTask2.setTaskReferenceName("join2");
joinTask2.setJoinOn(Arrays.asList("t4", "d1"));
WorkflowTask forkTask1 = new WorkflowTask();
forkTask1.setType(TaskType.FORK_JOIN.name());
forkTask1.setName("fork1");
forkTask1.setTaskReferenceName("fork1");
forkTask1.getForkTasks().add(Collections.singletonList(tasks.get(1)));
forkTask1.getForkTasks().add(Arrays.asList(forkTask2, joinTask2));
forkTask1.getForkTasks().add(Collections.singletonList(subWorkflow));
WorkflowTask joinTask1 = new WorkflowTask();
joinTask1.setName("join1");
joinTask1.setType(TaskType.JOIN.name());
joinTask1.setTaskReferenceName("join1");
joinTask1.setJoinOn(Arrays.asList("t1", "fork2"));
workflowDef.getTasks().add(forkTask1);
workflowDef.getTasks().add(joinTask1);
workflowDef.getTasks().add(tasks.get(5));
return workflowDef;
}
use of com.netflix.conductor.common.metadata.workflow.WorkflowDef in project conductor by Netflix.
the class TestDeciderService method createConditionalWF.
private WorkflowDef createConditionalWF() {
WorkflowTask workflowTask1 = new WorkflowTask();
workflowTask1.setName("junit_task_1");
Map<String, Object> inputParams1 = new HashMap<>();
inputParams1.put("p1", "workflow.input.param1");
inputParams1.put("p2", "workflow.input.param2");
workflowTask1.setInputParameters(inputParams1);
workflowTask1.setTaskReferenceName("t1");
workflowTask1.setTaskDefinition(new TaskDef("junit_task_1"));
WorkflowTask workflowTask2 = new WorkflowTask();
workflowTask2.setName("junit_task_2");
Map<String, Object> inputParams2 = new HashMap<>();
inputParams2.put("tp1", "workflow.input.param1");
workflowTask2.setInputParameters(inputParams2);
workflowTask2.setTaskReferenceName("t2");
workflowTask2.setTaskDefinition(new TaskDef("junit_task_2"));
WorkflowTask workflowTask3 = new WorkflowTask();
workflowTask3.setName("junit_task_3");
Map<String, Object> inputParams3 = new HashMap<>();
inputParams2.put("tp3", "workflow.input.param2");
workflowTask3.setInputParameters(inputParams3);
workflowTask3.setTaskReferenceName("t3");
workflowTask3.setTaskDefinition(new TaskDef("junit_task_3"));
WorkflowDef workflowDef = new WorkflowDef();
workflowDef.setName("Conditional Workflow");
workflowDef.setDescription("Conditional Workflow");
workflowDef.setInputParameters(Arrays.asList("param1", "param2"));
WorkflowTask decisionTask2 = new WorkflowTask();
decisionTask2.setType(TaskType.DECISION.name());
decisionTask2.setCaseValueParam("case");
decisionTask2.setName("conditional2");
decisionTask2.setTaskReferenceName("conditional2");
Map<String, List<WorkflowTask>> dc = new HashMap<>();
dc.put("one", Arrays.asList(workflowTask1, workflowTask3));
dc.put("two", Collections.singletonList(workflowTask2));
decisionTask2.setDecisionCases(dc);
decisionTask2.getInputParameters().put("case", "workflow.input.param2");
WorkflowTask decisionTask = new WorkflowTask();
decisionTask.setType(TaskType.DECISION.name());
decisionTask.setCaseValueParam("case");
decisionTask.setName("conditional");
decisionTask.setTaskReferenceName("conditional");
Map<String, List<WorkflowTask>> decisionCases = new HashMap<>();
decisionCases.put("nested", Collections.singletonList(decisionTask2));
decisionCases.put("three", Collections.singletonList(workflowTask3));
decisionTask.setDecisionCases(decisionCases);
decisionTask.getInputParameters().put("case", "workflow.input.param1");
decisionTask.getDefaultCase().add(workflowTask2);
workflowDef.getTasks().add(decisionTask);
WorkflowTask notifyTask = new WorkflowTask();
notifyTask.setName("junit_task_4");
notifyTask.setTaskReferenceName("junit_task_4");
notifyTask.setTaskDefinition(new TaskDef("junit_task_4"));
WorkflowTask finalDecisionTask = new WorkflowTask();
finalDecisionTask.setName("finalcondition");
finalDecisionTask.setTaskReferenceName("tf");
finalDecisionTask.setType(TaskType.DECISION.name());
finalDecisionTask.setCaseValueParam("finalCase");
Map<String, Object> fi = new HashMap<>();
fi.put("finalCase", "workflow.input.finalCase");
finalDecisionTask.setInputParameters(fi);
finalDecisionTask.getDecisionCases().put("notify", Collections.singletonList(notifyTask));
workflowDef.getTasks().add(finalDecisionTask);
return workflowDef;
}
use of com.netflix.conductor.common.metadata.workflow.WorkflowDef in project conductor by Netflix.
the class ExecutionService method requeuePendingTasks.
public int requeuePendingTasks() {
long threshold = System.currentTimeMillis() - taskRequeueTimeout;
List<WorkflowDef> workflowDefs = metadataDAO.getAllWorkflowDefs();
int count = 0;
for (WorkflowDef workflowDef : workflowDefs) {
List<Workflow> workflows = workflowExecutor.getRunningWorkflows(workflowDef.getName(), workflowDef.getVersion());
for (Workflow workflow : workflows) {
count += requeuePendingTasks(workflow, threshold);
}
}
return count;
}
Aggregations