use of com.netflix.conductor.common.metadata.workflow.WorkflowTask in project conductor by Netflix.
the class WorkflowTaskTypeConstraintTest method testWorkflowTaskMissingReferenceName.
@Test
public void testWorkflowTaskMissingReferenceName() {
WorkflowTask workflowTask = createSampleWorkflowTask();
workflowTask.setDynamicForkTasksParam("taskList");
workflowTask.setDynamicForkTasksInputParamName("ForkTaskInputParam");
workflowTask.setTaskReferenceName(null);
Set<ConstraintViolation<Object>> result = validator.validate(workflowTask);
assertEquals(1, result.size());
assertEquals(result.iterator().next().getMessage(), "WorkflowTask taskReferenceName name cannot be empty or null");
}
use of com.netflix.conductor.common.metadata.workflow.WorkflowTask in project conductor by Netflix.
the class WorkflowTaskTypeConstraintTest method testWorkflowTaskTypeForJoinDynamicWithForJoinTaskParam.
@Test
public void testWorkflowTaskTypeForJoinDynamicWithForJoinTaskParam() {
WorkflowTask workflowTask = createSampleWorkflowTask();
workflowTask.setType("FORK_JOIN_DYNAMIC");
workflowTask.setDynamicForkJoinTasksParam("taskList");
workflowTask.setDynamicForkTasksInputParamName("ForkTaskInputParam");
when(mockMetadataDao.getTaskDef(anyString())).thenReturn(new TaskDef());
Set<ConstraintViolation<WorkflowTask>> result = validator.validate(workflowTask);
assertEquals(1, result.size());
List<String> validationErrors = new ArrayList<>();
result.forEach(e -> validationErrors.add(e.getMessage()));
assertTrue(validationErrors.contains("dynamicForkJoinTasksParam or combination of dynamicForkTasksInputParamName and dynamicForkTasksParam cam be used for taskType: FORK_JOIN_DYNAMIC taskName: encode"));
}
use of com.netflix.conductor.common.metadata.workflow.WorkflowTask in project conductor by Netflix.
the class AbstractWorkflowServiceTest method createDecisionWorkflow.
private void createDecisionWorkflow() {
WorkflowDef workflowDef = new WorkflowDef();
workflowDef.setName(DECISION_WF);
workflowDef.setDescription(workflowDef.getName());
workflowDef.setVersion(1);
Map<String, Object> inputParams = new HashMap<>();
inputParams.put("p1", "${workflow.input.param1}");
inputParams.put("p2", "${workflow.input.param2}");
// left decision
WorkflowTask leftCaseTask1 = new WorkflowTask();
leftCaseTask1.setName("junit_task_1");
leftCaseTask1.setInputParameters(inputParams);
leftCaseTask1.setTaskReferenceName("t1");
WorkflowTask leftCaseTask2 = new WorkflowTask();
leftCaseTask2.setName("junit_task_2");
leftCaseTask2.setInputParameters(inputParams);
leftCaseTask2.setTaskReferenceName("t2");
// default decision
WorkflowTask defaultCaseTask5 = new WorkflowTask();
defaultCaseTask5.setName("junit_task_5");
defaultCaseTask5.setInputParameters(inputParams);
defaultCaseTask5.setTaskReferenceName("t5");
// decision task
Map<String, Object> decisionInput = new HashMap<>();
decisionInput.put("case", "${workflow.input.case}");
WorkflowTask decisionTask = new WorkflowTask();
decisionTask.setType(TaskType.DECISION.name());
decisionTask.setCaseValueParam("case");
decisionTask.setName("decisionTask");
decisionTask.setTaskReferenceName("decisionTask");
decisionTask.setInputParameters(decisionInput);
Map<String, List<WorkflowTask>> decisionCases = new HashMap<>();
decisionCases.put("c", Arrays.asList(leftCaseTask1, leftCaseTask2));
decisionTask.setDefaultCase(Collections.singletonList(defaultCaseTask5));
decisionTask.setDecisionCases(decisionCases);
WorkflowTask workflowTask20 = new WorkflowTask();
workflowTask20.setName("junit_task_20");
workflowTask20.setInputParameters(inputParams);
workflowTask20.setTaskReferenceName("t20");
workflowDef.getTasks().add(decisionTask);
workflowDef.getTasks().add(workflowTask20);
metadataService.updateWorkflowDef(workflowDef);
}
use of com.netflix.conductor.common.metadata.workflow.WorkflowTask in project conductor by Netflix.
the class AbstractWorkflowServiceTest method createForkJoinDecisionWorkflow.
private void createForkJoinDecisionWorkflow() {
WorkflowDef workflowDef = new WorkflowDef();
workflowDef.setName(FORK_JOIN_DECISION_WF);
workflowDef.setDescription(workflowDef.getName());
workflowDef.setVersion(1);
Map<String, Object> inputParams = new HashMap<>();
inputParams.put("p1", "${workflow.input.param1}");
inputParams.put("p2", "${workflow.input.param2}");
// left decision
WorkflowTask leftCaseTask1 = new WorkflowTask();
leftCaseTask1.setName("junit_task_1");
leftCaseTask1.setInputParameters(inputParams);
leftCaseTask1.setTaskReferenceName("t1");
WorkflowTask leftCaseTask2 = new WorkflowTask();
leftCaseTask2.setName("junit_task_2");
leftCaseTask2.setInputParameters(inputParams);
leftCaseTask2.setTaskReferenceName("t2");
// default decision
WorkflowTask defaultCaseTask5 = new WorkflowTask();
defaultCaseTask5.setName("junit_task_5");
defaultCaseTask5.setInputParameters(inputParams);
defaultCaseTask5.setTaskReferenceName("t5");
// left fork
// decision task
Map<String, Object> decisionInput = new HashMap<>();
decisionInput.put("case", "${workflow.input.case}");
WorkflowTask decisionTask = new WorkflowTask();
decisionTask.setType(TaskType.DECISION.name());
decisionTask.setCaseValueParam("case");
decisionTask.setName("decisionTask");
decisionTask.setTaskReferenceName("decisionTask");
decisionTask.setInputParameters(decisionInput);
Map<String, List<WorkflowTask>> decisionCases = new HashMap<>();
decisionCases.put("c", Arrays.asList(leftCaseTask1, leftCaseTask2));
decisionTask.setDefaultCase(Collections.singletonList(defaultCaseTask5));
decisionTask.setDecisionCases(decisionCases);
WorkflowTask workflowTask20 = new WorkflowTask();
workflowTask20.setName("junit_task_20");
workflowTask20.setInputParameters(inputParams);
workflowTask20.setTaskReferenceName("t20");
// right fork
WorkflowTask rightForkTask10 = new WorkflowTask();
rightForkTask10.setName("junit_task_10");
rightForkTask10.setInputParameters(inputParams);
rightForkTask10.setTaskReferenceName("t10");
// fork task
WorkflowTask forkTask = new WorkflowTask();
forkTask.setName("forkTask");
forkTask.setType(TaskType.FORK_JOIN.name());
forkTask.setTaskReferenceName("forkTask");
forkTask.getForkTasks().add(Arrays.asList(decisionTask, workflowTask20));
forkTask.getForkTasks().add(Collections.singletonList(rightForkTask10));
// join task
WorkflowTask joinTask = new WorkflowTask();
joinTask.setName("joinTask");
joinTask.setType(TaskType.JOIN.name());
joinTask.setTaskReferenceName("joinTask");
joinTask.setJoinOn(Arrays.asList("t20", "t10"));
workflowDef.getTasks().add(forkTask);
workflowDef.getTasks().add(joinTask);
metadataService.updateWorkflowDef(workflowDef);
}
use of com.netflix.conductor.common.metadata.workflow.WorkflowTask in project conductor by Netflix.
the class AbstractWorkflowServiceTest method testTaskDefTemplate.
@Test
public void testTaskDefTemplate() throws Exception {
System.setProperty("STACK2", "test_stack");
TaskDef templatedTask = new TaskDef();
templatedTask.setName("templated_task");
Map<String, Object> httpRequest = new HashMap<>();
httpRequest.put("method", "GET");
httpRequest.put("vipStack", "${STACK2}");
httpRequest.put("uri", "/get/something");
Map<String, Object> body = new HashMap<>();
body.put("inputPaths", Arrays.asList("${workflow.input.path1}", "${workflow.input.path2}"));
body.put("requestDetails", "${workflow.input.requestDetails}");
body.put("outputPath", "${workflow.input.outputPath}");
httpRequest.put("body", body);
templatedTask.getInputTemplate().put("http_request", httpRequest);
metadataService.registerTaskDef(Arrays.asList(templatedTask));
WorkflowDef templateWf = new WorkflowDef();
templateWf.setName("template_workflow");
WorkflowTask wft = new WorkflowTask();
wft.setName(templatedTask.getName());
wft.setWorkflowTaskType(TaskType.SIMPLE);
wft.setTaskReferenceName("t0");
templateWf.getTasks().add(wft);
templateWf.setSchemaVersion(2);
metadataService.registerWorkflowDef(templateWf);
Map<String, Object> requestDetails = new HashMap<>();
requestDetails.put("key1", "value1");
requestDetails.put("key2", 42);
Map<String, Object> input = new HashMap<>();
input.put("path1", "file://path1");
input.put("path2", "file://path2");
input.put("outputPath", "s3://bucket/outputPath");
input.put("requestDetails", requestDetails);
String id = startOrLoadWorkflowExecution(templateWf.getName(), 1, "testTaskDefTemplate", input, null, null);
assertNotNull(id);
Workflow workflow = workflowExecutionService.getExecutionStatus(id, true);
assertNotNull(workflow);
assertTrue(workflow.getReasonForIncompletion(), !workflow.getStatus().isTerminal());
assertEquals(1, workflow.getTasks().size());
Task task = workflow.getTasks().get(0);
Map<String, Object> taskInput = task.getInputData();
assertNotNull(taskInput);
assertTrue(taskInput.containsKey("http_request"));
assertTrue(taskInput.get("http_request") instanceof Map);
// Use the commented sysout to get the string value
// System.out.println(om.writeValueAsString(om.writeValueAsString(taskInput)));
String expected = "{\"http_request\":{\"method\":\"GET\",\"vipStack\":\"test_stack\",\"body\":{\"requestDetails\":{\"key1\":\"value1\",\"key2\":42},\"outputPath\":\"s3://bucket/outputPath\",\"inputPaths\":[\"file://path1\",\"file://path2\"]},\"uri\":\"/get/something\"}}";
assertEquals(expected, objectMapper.writeValueAsString(taskInput));
}
Aggregations