use of com.netflix.conductor.common.metadata.tasks.TaskDef in project conductor by Netflix.
the class MetadataServiceImpl method registerTaskDef.
/**
* @param taskDefinitions Task Definitions to register
*/
@Service
public void registerTaskDef(List<TaskDef> taskDefinitions) {
for (TaskDef taskDefinition : taskDefinitions) {
taskDefinition.setCreatedBy(WorkflowContext.get().getClientApp());
taskDefinition.setCreateTime(System.currentTimeMillis());
taskDefinition.setUpdatedBy(null);
taskDefinition.setUpdateTime(null);
metadataDAO.createTaskDef(taskDefinition);
}
}
use of com.netflix.conductor.common.metadata.tasks.TaskDef in project conductor by Netflix.
the class TestDeciderService method testCheckTaskPollTimeout.
@Test
public void testCheckTaskPollTimeout() {
Counter counter = registry.counter("task_timeout", "class", "WorkflowMonitor", "taskType", "test");
long counterCount = counter.count();
TaskDef taskType = new TaskDef();
taskType.setName("test");
taskType.setTimeoutPolicy(TimeoutPolicy.RETRY);
taskType.setPollTimeoutSeconds(1);
Task task = new Task();
task.setTaskType(taskType.getName());
task.setScheduledTime(System.currentTimeMillis() - 2_000);
task.setStatus(Status.SCHEDULED);
deciderService.checkTaskPollTimeout(taskType, task);
assertEquals(++counterCount, counter.count());
assertEquals(Status.TIMED_OUT, task.getStatus());
assertNotNull(task.getReasonForIncompletion());
task.setScheduledTime(System.currentTimeMillis());
task.setReasonForIncompletion(null);
task.setStatus(Status.SCHEDULED);
deciderService.checkTaskPollTimeout(taskType, task);
assertEquals(counterCount, counter.count());
assertEquals(Status.SCHEDULED, task.getStatus());
assertNull(task.getReasonForIncompletion());
}
use of com.netflix.conductor.common.metadata.tasks.TaskDef 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.tasks.TaskDef in project conductor by Netflix.
the class TestDeciderService method testIsResponseTimedOut.
@Test
public void testIsResponseTimedOut() {
TaskDef taskDef = new TaskDef();
taskDef.setName("test_rt");
taskDef.setResponseTimeoutSeconds(10);
Task task = new Task();
task.setTaskDefName("test_rt");
task.setStatus(Status.IN_PROGRESS);
task.setTaskId("aa");
task.setTaskType(TaskType.TASK_TYPE_SIMPLE);
task.setUpdateTime(System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(11));
assertTrue(deciderService.isResponseTimedOut(taskDef, task));
// verify that sub workflow tasks are not response timed out
task.setTaskType(TaskType.TASK_TYPE_SUB_WORKFLOW);
assertFalse(deciderService.isResponseTimedOut(taskDef, task));
}
use of com.netflix.conductor.common.metadata.tasks.TaskDef 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;
}
Aggregations