Search in sources :

Example 1 with SubWorkflowParams

use of com.netflix.conductor.common.metadata.workflow.SubWorkflowParams in project conductor by Netflix.

the class SubWorkflowParamsTest method testWorkflowDefJson.

@Test
public void testWorkflowDefJson() throws Exception {
    // name is null
    SubWorkflowParams subWorkflowParams = new SubWorkflowParams();
    subWorkflowParams.setName("dummy-name");
    WorkflowDef def = new WorkflowDef();
    def.setName("test_workflow");
    def.setVersion(1);
    WorkflowTask task = new WorkflowTask();
    task.setName("test_task");
    task.setTaskReferenceName("t1");
    def.getTasks().add(task);
    subWorkflowParams.setWorkflowDefinition(def);
    String expected = "{\n" + "  \"name\" : \"test_workflow\",\n" + "  \"version\" : 1,\n" + "  \"workflowDefinition\" : {\n" + "    \"inputParameters\" : [ ],\n" + "    \"name\" : \"test_workflow\",\n" + "    \"outputParameters\" : { },\n" + "    \"restartable\" : true,\n" + "    \"schemaVersion\" : 2,\n" + "    \"tasks\" : [ {\n" + "      \"asyncComplete\" : false,\n" + "      \"decisionCases\" : { },\n" + "      \"defaultCase\" : [ ],\n" + "      \"defaultExclusiveJoinTask\" : [ ],\n" + "      \"forkTasks\" : [ ],\n" + "      \"inputParameters\" : { },\n" + "      \"joinOn\" : [ ],\n" + "      \"loopOver\" : [ ],\n" + "      \"name\" : \"test_task\",\n" + "      \"optional\" : false,\n" + "      \"retryLogic\" : \"UNSPECIFIED\",\n" + "      \"startDelay\" : 0,\n" + "      \"taskReferenceName\" : \"t1\",\n" + "      \"type\" : \"SIMPLE\"\n" + "    } ],\n" + "    \"timeoutPolicy\" : \"ALERT_ONLY\",\n" + "    \"timeoutSeconds\" : 0,\n" + "    \"variables\" : { },\n" + "    \"version\" : 1,\n" + "    \"workflowStatusListenerEnabled\" : false\n" + "  }\n" + "}";
    ObjectMapper objectMapper = new JsonMapperProvider().get();
    objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
    objectMapper.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY);
    objectMapper.enable(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS);
    assertEquals(expected, objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(subWorkflowParams));
    SubWorkflowParams actualSubWorkflowParam = objectMapper.readValue(expected, SubWorkflowParams.class);
    assertEquals(subWorkflowParams, actualSubWorkflowParam);
    assertEquals(def, actualSubWorkflowParam.getWorkflowDefinition());
    assertEquals(def, actualSubWorkflowParam.getWorkflowDef());
}
Also used : SubWorkflowParams(com.netflix.conductor.common.metadata.workflow.SubWorkflowParams) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonMapperProvider(com.netflix.conductor.common.utils.JsonMapperProvider) Test(org.junit.Test)

Example 2 with SubWorkflowParams

use of com.netflix.conductor.common.metadata.workflow.SubWorkflowParams in project conductor by Netflix.

the class SubWorkflowParamsTest method testWorkflowTaskName.

@Test
public void testWorkflowTaskName() {
    // name is null
    SubWorkflowParams subWorkflowParams = new SubWorkflowParams();
    ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
    Validator validator = factory.getValidator();
    Set<ConstraintViolation<Object>> result = validator.validate(subWorkflowParams);
    assertEquals(2, result.size());
    List<String> validationErrors = new ArrayList<>();
    result.forEach(e -> validationErrors.add(e.getMessage()));
    assertTrue(validationErrors.contains("SubWorkflowParams name cannot be null"));
    assertTrue(validationErrors.contains("SubWorkflowParams name cannot be empty"));
}
Also used : SubWorkflowParams(com.netflix.conductor.common.metadata.workflow.SubWorkflowParams) ValidatorFactory(javax.validation.ValidatorFactory) ConstraintViolation(javax.validation.ConstraintViolation) Validator(javax.validation.Validator) Test(org.junit.Test)

Example 3 with SubWorkflowParams

use of com.netflix.conductor.common.metadata.workflow.SubWorkflowParams in project conductor by Netflix.

the class SubWorkflowTaskMapperTest method getSubWorkflowParams.

@Test
public void getSubWorkflowParams() {
    WorkflowTask workflowTask = new WorkflowTask();
    SubWorkflowParams subWorkflowParams = new SubWorkflowParams();
    subWorkflowParams.setName("Foo");
    subWorkflowParams.setVersion(2);
    workflowTask.setSubWorkflowParam(subWorkflowParams);
    assertEquals(subWorkflowParams, subWorkflowTaskMapper.getSubWorkflowParams(workflowTask));
}
Also used : SubWorkflowParams(com.netflix.conductor.common.metadata.workflow.SubWorkflowParams) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Test(org.junit.Test)

Example 4 with SubWorkflowParams

use of com.netflix.conductor.common.metadata.workflow.SubWorkflowParams in project conductor by Netflix.

the class SubWorkflowTaskMapperTest method getMappedTasks.

@SuppressWarnings("unchecked")
@Test
public void getMappedTasks() {
    // Given
    WorkflowDef workflowDef = new WorkflowDef();
    Workflow workflowInstance = new Workflow();
    workflowInstance.setWorkflowDefinition(workflowDef);
    WorkflowTask taskToSchedule = new WorkflowTask();
    SubWorkflowParams subWorkflowParams = new SubWorkflowParams();
    subWorkflowParams.setName("Foo");
    subWorkflowParams.setVersion(2);
    taskToSchedule.setSubWorkflowParam(subWorkflowParams);
    Map<String, Object> taskInput = new HashMap<>();
    Map<String, String> taskToDomain = new HashMap<String, String>() {

        {
            put("*", "unittest");
        }
    };
    Map<String, Object> subWorkflowParamMap = new HashMap<>();
    subWorkflowParamMap.put("name", "FooWorkFlow");
    subWorkflowParamMap.put("version", 2);
    subWorkflowParamMap.put("taskToDomain", taskToDomain);
    when(parametersUtils.getTaskInputV2(anyMap(), any(Workflow.class), any(), any())).thenReturn(subWorkflowParamMap);
    // When
    TaskMapperContext taskMapperContext = TaskMapperContext.newBuilder().withWorkflowDefinition(workflowDef).withWorkflowInstance(workflowInstance).withTaskToSchedule(taskToSchedule).withTaskInput(taskInput).withRetryCount(0).withTaskId(IDGenerator.generate()).withDeciderService(deciderService).build();
    List<Task> mappedTasks = subWorkflowTaskMapper.getMappedTasks(taskMapperContext);
    // Then
    assertTrue(!mappedTasks.isEmpty());
    assertEquals(1, mappedTasks.size());
    Task subWorkFlowTask = mappedTasks.get(0);
    assertEquals(Task.Status.SCHEDULED, subWorkFlowTask.getStatus());
    assertEquals(SubWorkflow.NAME, subWorkFlowTask.getTaskType());
    assertEquals(taskToDomain, subWorkFlowTask.getInputData().get("subWorkflowTaskToDomain"));
}
Also used : SubWorkflowParams(com.netflix.conductor.common.metadata.workflow.SubWorkflowParams) Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) HashMap(java.util.HashMap) SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) Workflow(com.netflix.conductor.common.run.Workflow) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Test(org.junit.Test)

Example 5 with SubWorkflowParams

use of com.netflix.conductor.common.metadata.workflow.SubWorkflowParams 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;
}
Also used : WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SubWorkflowParams(com.netflix.conductor.common.metadata.workflow.SubWorkflowParams) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

Aggregations

SubWorkflowParams (com.netflix.conductor.common.metadata.workflow.SubWorkflowParams)26 WorkflowTask (com.netflix.conductor.common.metadata.workflow.WorkflowTask)21 WorkflowDef (com.netflix.conductor.common.metadata.workflow.WorkflowDef)17 Test (org.junit.Test)13 HashMap (java.util.HashMap)12 LinkedList (java.util.LinkedList)5 Task (com.netflix.conductor.common.metadata.tasks.Task)4 Workflow (com.netflix.conductor.common.run.Workflow)4 SubWorkflow (com.netflix.conductor.core.execution.tasks.SubWorkflow)4 TaskDef (com.netflix.conductor.common.metadata.tasks.TaskDef)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 ConstraintViolation (javax.validation.ConstraintViolation)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DynamicForkJoinTaskList (com.netflix.conductor.common.metadata.workflow.DynamicForkJoinTaskList)1 JsonMapperProvider (com.netflix.conductor.common.utils.JsonMapperProvider)1 ApplicationException (com.netflix.conductor.core.execution.ApplicationException)1 TerminateWorkflowException (com.netflix.conductor.core.execution.TerminateWorkflowException)1