use of com.netflix.conductor.common.metadata.tasks.TaskDef in project conductor by Netflix.
the class AbstractWorkflowServiceTest method createConditionalWFWithSystemTask.
private void createConditionalWFWithSystemTask() {
WorkflowDef defConditionalHttp = new WorkflowDef();
defConditionalHttp.setName(CONDITIONAL_SYSTEM_WORKFLOW);
defConditionalHttp.setDescription(defConditionalHttp.getName());
defConditionalHttp.setVersion(1);
defConditionalHttp.setInputParameters(Arrays.asList("param1", "param2"));
Map<String, Object> outputParameters = new HashMap<>();
outputParameters.put("o2", "${t1.output.op}");
defConditionalHttp.setOutputParameters(outputParameters);
defConditionalHttp.setSchemaVersion(2);
LinkedList<WorkflowTask> wftasks = new LinkedList<>();
WorkflowTask wft1 = new WorkflowTask();
wft1.setName("junit_task_1");
Map<String, Object> ip1 = new HashMap<>();
ip1.put("tp11", "${workflow.input.param1}");
ip1.put("tp12", "${workflow.input.param2}");
wft1.setInputParameters(ip1);
wft1.setTaskReferenceName("t1");
TaskDef taskDef = new TaskDef();
taskDef.setName("user_task");
taskDef.setTimeoutSeconds(20);
taskDef.setRetryCount(1);
taskDef.setTimeoutPolicy(TimeoutPolicy.RETRY);
taskDef.setRetryDelaySeconds(10);
metadataService.registerTaskDef(Collections.singletonList(taskDef));
WorkflowTask userTask = new WorkflowTask();
userTask.setName(taskDef.getName());
userTask.setType(UserTask.NAME);
Map<String, Object> userIP = new HashMap<>();
userIP.put("largeInput", "${t1.output.op}");
userTask.setInputParameters(userIP);
userTask.setTaskReferenceName("user_task");
WorkflowTask wft2 = new WorkflowTask();
wft2.setName("junit_task_2");
Map<String, Object> ip2 = new HashMap<>();
ip2.put("tp21", "${workflow.input.param1}");
wft2.setInputParameters(ip2);
wft2.setTaskReferenceName("t2");
WorkflowTask decisionTask = new WorkflowTask();
decisionTask.setType(TaskType.DECISION.name());
decisionTask.setCaseValueParam("case");
decisionTask.setName("conditional2");
decisionTask.setTaskReferenceName("conditional2");
Map<String, Object> decisionIP = new HashMap<>();
decisionIP.put("case", "${t1.output.case}");
decisionTask.setInputParameters(decisionIP);
Map<String, List<WorkflowTask>> decisionCases = new HashMap<>();
decisionCases.put("one", Collections.singletonList(wft2));
decisionCases.put("two", Collections.singletonList(userTask));
decisionTask.setDecisionCases(decisionCases);
WorkflowTask wft3 = new WorkflowTask();
wft3.setName("junit_task_3");
Map<String, Object> ip3 = new HashMap<>();
ip3.put("tp31", "${workflow.input.param2}");
wft3.setInputParameters(ip3);
wft3.setTaskReferenceName("t3");
wftasks.add(wft1);
wftasks.add(decisionTask);
wftasks.add(wft3);
defConditionalHttp.setTasks(wftasks);
metadataService.updateWorkflowDef(defConditionalHttp);
}
use of com.netflix.conductor.common.metadata.tasks.TaskDef in project conductor by Netflix.
the class AbstractWorkflowServiceTest method testSubWorkflowRetryLastFailedTask.
@Test
public void testSubWorkflowRetryLastFailedTask() {
String taskName = "junit_task_2";
TaskDef taskDef = notFoundSafeGetTaskDef(taskName);
int retryCount = notFoundSafeGetTaskDef(taskName).getRetryCount();
taskDef.setRetryCount(0);
metadataService.updateTaskDef(taskDef);
createSubWorkflow();
WorkflowDef found = metadataService.getWorkflowDef(WF_WITH_SUB_WF, 1);
WorkflowTask workflowTask = found.getTasks().stream().filter(t -> t.getType().equals(SUB_WORKFLOW.name())).findAny().orElse(null);
TaskDef subWorkflowTaskDef = new TaskDef();
subWorkflowTaskDef.setRetryCount(0);
subWorkflowTaskDef.setName("test_subworkflow_task");
subWorkflowTaskDef.setOwnerEmail("test@qbc.com");
workflowTask.setTaskDefinition(subWorkflowTaskDef);
metadataService.updateWorkflowDef(found);
Map<String, Object> workflowInputParams = new HashMap<>();
workflowInputParams.put("param1", "param 1");
workflowInputParams.put("param3", "param 2");
workflowInputParams.put("wfName", LINEAR_WORKFLOW_T1_T2);
String workflowId = startOrLoadWorkflowExecution(WF_WITH_SUB_WF, 1, "test", workflowInputParams, null, null);
assertNotNull(workflowId);
Workflow workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertNotNull(workflow);
Task task = workflowExecutionService.poll("junit_task_5", "test");
assertNotNull(task);
task.setStatus(COMPLETED);
workflowExecutionService.updateTask(task);
workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
String subWorkflowTaskId = workflow.getTaskByRefName("a2").getTaskId();
workflowExecutor.executeSystemTask(dummySubWorkflowSystemTask, subWorkflowTaskId, 1);
workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertNotNull(workflow);
assertNotNull(workflow.getTasks());
assertEquals(2, workflow.getTasks().size());
task = workflow.getTasks().stream().filter(t -> t.getTaskType().equals(SUB_WORKFLOW.name())).findAny().orElse(null);
assertNotNull(task);
assertNotNull(task.getOutputData());
assertNotNull("Output: " + task.getOutputData().toString() + ", status: " + task.getStatus(), task.getSubWorkflowId());
String subWorkflowId = task.getSubWorkflowId();
workflow = workflowExecutionService.getExecutionStatus(subWorkflowId, true);
assertNotNull(workflow);
assertNotNull(workflow.getTasks());
assertEquals(workflowId, workflow.getParentWorkflowId());
assertEquals(RUNNING, workflow.getStatus());
task = workflowExecutionService.poll("junit_task_1", "test");
task.setStatus(COMPLETED);
workflowExecutionService.updateTask(task);
Workflow subWorkflow = workflowExecutionService.getExecutionStatus(subWorkflowId, true);
task = workflowExecutionService.poll("junit_task_2", "test");
task.setStatus(FAILED);
workflowExecutionService.updateTask(task);
subWorkflow = workflowExecutionService.getExecutionStatus(subWorkflowId, true);
assertNotNull(subWorkflow);
assertEquals(WorkflowStatus.FAILED, subWorkflow.getStatus());
subWorkflow = workflowExecutionService.getExecutionStatus(subWorkflowId, true);
assertNotNull(subWorkflow);
task = subWorkflow.getTasks().stream().filter(t -> t.getTaskType().equals("junit_task_2")).findAny().orElse(null);
assertNotNull(task);
assertEquals(FAILED, task.getStatus());
subWorkflow = workflowExecutionService.getExecutionStatus(subWorkflowId, true);
assertNotNull(subWorkflow);
assertEquals(WorkflowStatus.FAILED, subWorkflow.getStatus());
workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertNotNull(workflow);
assertEquals(WorkflowStatus.FAILED, workflow.getStatus());
workflowExecutor.retry(workflowId, true);
subWorkflow = workflowExecutionService.getExecutionStatus(subWorkflowId, true);
assertNotNull(subWorkflow);
assertEquals(RUNNING, subWorkflow.getStatus());
task = workflowExecutionService.poll("junit_task_2", "test");
assertEquals(subWorkflowId, task.getWorkflowInstanceId());
String uuid = UUID.randomUUID().toString();
task.getOutputData().put("uuid", uuid);
task.setStatus(COMPLETED);
workflowExecutionService.updateTask(task);
subWorkflow = workflowExecutionService.getExecutionStatus(subWorkflowId, true);
assertNotNull(subWorkflow);
assertEquals(WorkflowStatus.COMPLETED, subWorkflow.getStatus());
assertNotNull(subWorkflow.getOutput());
assertTrue(subWorkflow.getOutput().containsKey("o1"));
assertTrue(subWorkflow.getOutput().containsKey("o2"));
assertEquals("sub workflow input param1", subWorkflow.getOutput().get("o1"));
assertEquals(uuid, subWorkflow.getOutput().get("o2"));
workflowExecutor.executeSystemTask(subworkflow, subWorkflow.getParentWorkflowTaskId(), 1);
workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertNotNull(workflow);
assertEquals(RUNNING, workflow.getStatus());
task = workflowExecutionService.poll("junit_task_6", "test");
assertNotNull(task);
task.setStatus(COMPLETED);
workflowExecutionService.updateTask(task);
workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertNotNull(workflow);
assertEquals(WorkflowStatus.COMPLETED, workflow.getStatus());
taskDef = notFoundSafeGetTaskDef(taskName);
taskDef.setRetryCount(retryCount);
metadataService.updateTaskDef(taskDef);
workflowTask = found.getTasks().stream().filter(t -> t.getType().equals(SUB_WORKFLOW.name())).findAny().orElse(null);
workflowTask.setTaskDefinition(null);
metadataService.updateWorkflowDef(found);
}
use of com.netflix.conductor.common.metadata.tasks.TaskDef in project conductor by Netflix.
the class AbstractEndToEndTest method createTaskDefinition.
protected TaskDef createTaskDefinition(String name) {
TaskDef taskDefinition = new TaskDef();
taskDefinition.setName(name);
return taskDefinition;
}
use of com.netflix.conductor.common.metadata.tasks.TaskDef in project conductor by Netflix.
the class AbstractEndToEndTest method testEphemeralWorkflowsWithEphemeralAndStoredTasks.
@Test
public void testEphemeralWorkflowsWithEphemeralAndStoredTasks() {
createAndRegisterTaskDefinitions("storedTask", 1);
WorkflowDef workflowDefinition = createWorkflowDefinition("testEphemeralWorkflowsWithEphemeralAndStoredTasks");
WorkflowTask workflowTask1 = createWorkflowTask("ephemeralTask1");
TaskDef taskDefinition1 = createTaskDefinition("ephemeralTaskDef1");
workflowTask1.setTaskDefinition(taskDefinition1);
WorkflowTask workflowTask2 = createWorkflowTask("storedTask0");
workflowDefinition.getTasks().add(workflowTask1);
workflowDefinition.getTasks().add(workflowTask2);
String workflowExecutionName = "ephemeralWorkflowWithEphemeralAndStoredTasks";
String workflowId = startWorkflow(workflowExecutionName, workflowDefinition);
assertNotNull(workflowId);
Workflow workflow = getWorkflow(workflowId, true);
WorkflowDef ephemeralWorkflow = workflow.getWorkflowDefinition();
assertNotNull(ephemeralWorkflow);
assertEquals(workflowDefinition, ephemeralWorkflow);
TaskDef storedTaskDefinition = getTaskDefinition("storedTask0");
List<WorkflowTask> tasks = ephemeralWorkflow.getTasks();
assertEquals(2, tasks.size());
assertEquals(workflowTask1, tasks.get(0));
TaskDef currentStoredTaskDefinition = tasks.get(1).getTaskDefinition();
assertNotNull(currentStoredTaskDefinition);
assertEquals(storedTaskDefinition, currentStoredTaskDefinition);
}
use of com.netflix.conductor.common.metadata.tasks.TaskDef in project conductor by Netflix.
the class MetadataServiceImpl method updateTaskDef.
/*
* @param taskDefinition Task Definition to be updated
*/
@Service
public void updateTaskDef(TaskDef taskDefinition) {
TaskDef existing = metadataDAO.getTaskDef(taskDefinition.getName());
if (existing == null) {
throw new ApplicationException(Code.NOT_FOUND, "No such task by name " + taskDefinition.getName());
}
taskDefinition.setUpdatedBy(WorkflowContext.get().getClientApp());
taskDefinition.setUpdateTime(System.currentTimeMillis());
metadataDAO.updateTaskDef(taskDefinition);
}
Aggregations