Search in sources :

Example 86 with WorkflowTask

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");
}
Also used : ConstraintViolation(javax.validation.ConstraintViolation) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Test(org.junit.Test)

Example 87 with WorkflowTask

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"));
}
Also used : TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) ConstraintViolation(javax.validation.ConstraintViolation) ArrayList(java.util.ArrayList) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 88 with WorkflowTask

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);
}
Also used : WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) HashMap(java.util.HashMap) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) List(java.util.List) DynamicForkJoinTaskList(com.netflix.conductor.common.metadata.workflow.DynamicForkJoinTaskList) LinkedList(java.util.LinkedList)

Example 89 with WorkflowTask

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);
}
Also used : WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) HashMap(java.util.HashMap) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) List(java.util.List) DynamicForkJoinTaskList(com.netflix.conductor.common.metadata.workflow.DynamicForkJoinTaskList) LinkedList(java.util.LinkedList)

Example 90 with WorkflowTask

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));
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) UserTask(com.netflix.conductor.tests.utils.UserTask) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) HashMap(java.util.HashMap) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) Workflow(com.netflix.conductor.common.run.Workflow) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

WorkflowTask (com.netflix.conductor.common.metadata.workflow.WorkflowTask)244 Test (org.junit.Test)166 WorkflowDef (com.netflix.conductor.common.metadata.workflow.WorkflowDef)148 TaskDef (com.netflix.conductor.common.metadata.tasks.TaskDef)106 Workflow (com.netflix.conductor.common.run.Workflow)106 HashMap (java.util.HashMap)103 Task (com.netflix.conductor.common.metadata.tasks.Task)98 ArrayList (java.util.ArrayList)52 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)44 ConstraintViolation (javax.validation.ConstraintViolation)41 LinkedList (java.util.LinkedList)40 List (java.util.List)36 SubWorkflow (com.netflix.conductor.core.execution.tasks.SubWorkflow)32 Map (java.util.Map)26 SubWorkflowParams (com.netflix.conductor.common.metadata.workflow.SubWorkflowParams)25 DynamicForkJoinTaskList (com.netflix.conductor.common.metadata.workflow.DynamicForkJoinTaskList)18 WorkflowSystemTask (com.netflix.conductor.core.execution.tasks.WorkflowSystemTask)14 UserTask (com.netflix.conductor.tests.utils.UserTask)14 ValidatorFactory (javax.validation.ValidatorFactory)13 VisibleForTesting (com.google.common.annotations.VisibleForTesting)11