Search in sources :

Example 91 with WorkflowDef

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

the class AbstractWorkflowServiceTest method createDynamicForkJoinWorkflowDefs.

private void createDynamicForkJoinWorkflowDefs() {
    WorkflowDef def = new WorkflowDef();
    def.setName(DYNAMIC_FORK_JOIN_WF);
    def.setDescription(def.getName());
    def.setVersion(1);
    def.setSchemaVersion(2);
    def.setInputParameters(Arrays.asList("param1", "param2"));
    WorkflowTask workflowTask1 = new WorkflowTask();
    workflowTask1.setName("junit_task_1");
    Map<String, Object> ip1 = new HashMap<>();
    ip1.put("p1", "${workflow.input.param1}");
    ip1.put("p2", "${workflow.input.param2}");
    workflowTask1.setInputParameters(ip1);
    workflowTask1.setTaskReferenceName("dt1");
    WorkflowTask fanout = new WorkflowTask();
    fanout.setType(TaskType.FORK_JOIN_DYNAMIC.name());
    fanout.setTaskReferenceName("dynamicfanouttask");
    fanout.setDynamicForkTasksParam("dynamicTasks");
    fanout.setDynamicForkTasksInputParamName("dynamicTasksInput");
    fanout.getInputParameters().put("dynamicTasks", "${dt1.output.dynamicTasks}");
    fanout.getInputParameters().put("dynamicTasksInput", "${dt1.output.dynamicTasksInput}");
    WorkflowTask join = new WorkflowTask();
    join.setType(TaskType.JOIN.name());
    join.setTaskReferenceName("dynamicfanouttask_join");
    WorkflowTask workflowTask4 = new WorkflowTask();
    workflowTask4.setName("junit_task_4");
    workflowTask4.setTaskReferenceName("task4");
    def.getTasks().add(workflowTask1);
    def.getTasks().add(fanout);
    def.getTasks().add(join);
    def.getTasks().add(workflowTask4);
    metadataMapperService.populateTaskDefinitions(def);
    metadataService.updateWorkflowDef(def);
}
Also used : WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) HashMap(java.util.HashMap) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask)

Example 92 with WorkflowDef

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

the class AbstractWorkflowServiceTest method testWorkflowWithConditionalSystemTaskUsingExternalPayloadStorage.

@Test
public void testWorkflowWithConditionalSystemTaskUsingExternalPayloadStorage() {
    createConditionalWFWithSystemTask();
    WorkflowDef workflowDef = metadataService.getWorkflowDef(CONDITIONAL_SYSTEM_WORKFLOW, 1);
    assertNotNull(workflowDef);
    String workflowInputPath = INITIAL_WORKFLOW_INPUT_PATH;
    String correlationId = "conditional_http_external_storage";
    String workflowId = workflowExecutor.startWorkflow(CONDITIONAL_SYSTEM_WORKFLOW, 1, correlationId, null, workflowInputPath, null, null);
    assertNotNull(workflowId);
    Workflow workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertTrue("The workflow input should not be persisted", workflow.getInput().isEmpty());
    assertEquals(workflowInputPath, workflow.getExternalInputPayloadStoragePath());
    assertEquals(workflow.getReasonForIncompletion(), WorkflowStatus.RUNNING, workflow.getStatus());
    assertEquals(1, workflow.getTasks().size());
    // Polling for the first task
    Task task = workflowExecutionService.poll("junit_task_1", "junit.worker.task_1");
    assertNotNull(task);
    assertEquals("junit_task_1", task.getTaskType());
    assertTrue(workflowExecutionService.ackTaskReceived(task.getTaskId()));
    assertEquals(workflowId, task.getWorkflowInstanceId());
    // update first task with COMPLETED and using external payload storage for output data
    String taskOutputPath = TASK_OUTPUT_PATH;
    task.setOutputData(null);
    task.setExternalOutputPayloadStoragePath(taskOutputPath);
    task.setStatus(COMPLETED);
    workflowExecutionService.updateTask(task);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals(workflow.getReasonForIncompletion(), WorkflowStatus.RUNNING, workflow.getStatus());
    assertEquals(3, workflow.getTasks().size());
    assertEquals(DECISION.name(), workflow.getTasks().get(1).getTaskType());
    assertEquals(UserTask.NAME, workflow.getTasks().get(2).getTaskType());
    assertEquals(0, workflow.getTasks().get(2).getPollCount());
    // simulate the SystemTaskWorkerCoordinator action
    String taskId = workflow.getTaskByRefName("user_task").getTaskId();
    workflowExecutor.executeSystemTask(userTask, taskId, 1);
    task = workflowExecutionService.getTask(taskId);
    assertEquals(COMPLETED, task.getStatus());
    assertEquals(0, workflow.getTasks().get(2).getPollCount());
    assertTrue("The task input should not be persisted", task.getInputData().isEmpty());
    assertEquals(INPUT_PAYLOAD_PATH, task.getExternalInputPayloadStoragePath());
    assertEquals(104, task.getOutputData().get("size"));
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals(workflow.getReasonForIncompletion(), WorkflowStatus.RUNNING, workflow.getStatus());
    assertEquals(4, workflow.getTasks().size());
    // Polling for the last task
    task = workflowExecutionService.poll("junit_task_3", "junit.worker.task_3");
    assertNotNull(task);
    assertEquals("junit_task_3", task.getTaskType());
    assertTrue(workflowExecutionService.ackTaskReceived(task.getTaskId()));
    assertEquals(workflowId, task.getWorkflowInstanceId());
    // update final task with COMPLETED
    task.getOutputData().put("op", "success_task3");
    task.setStatus(COMPLETED);
    workflowExecutionService.updateTask(task);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertTrue("The workflow input should not be persisted", workflow.getInput().isEmpty());
    assertEquals(workflowInputPath, workflow.getExternalInputPayloadStoragePath());
    assertEquals(WorkflowStatus.COMPLETED, workflow.getStatus());
    assertEquals(4, workflow.getTasks().size());
    assertTrue(workflow.getOutput().isEmpty());
    assertNotNull(workflow.getExternalOutputPayloadStoragePath());
    assertEquals(WORKFLOW_OUTPUT_PATH, workflow.getExternalOutputPayloadStoragePath());
}
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) SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) Workflow(com.netflix.conductor.common.run.Workflow) Test(org.junit.Test)

Example 93 with WorkflowDef

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

the class AbstractWorkflowServiceTest method createDoWhileWorkflowWithIteration.

private void createDoWhileWorkflowWithIteration(int iteration, boolean isInputParameter, boolean useTaskDef) {
    WorkflowDef workflowDef = new WorkflowDef();
    if (isInputParameter) {
        workflowDef.setName(DO_WHILE_WF + "_3");
    } else {
        workflowDef.setName(DO_WHILE_WF + "_" + iteration);
    }
    workflowDef.setDescription(workflowDef.getName());
    workflowDef.setVersion(1);
    workflowDef.setInputParameters(Arrays.asList("param1", "param2"));
    WorkflowTask loopTask = new WorkflowTask();
    loopTask.setType(TaskType.DO_WHILE.name());
    loopTask.setTaskReferenceName("loopTask");
    loopTask.setName("loopTask");
    loopTask.setWorkflowTaskType(TaskType.DO_WHILE);
    Map<String, Object> input = new HashMap<>();
    input.put("value", "${workflow.input.loop}");
    loopTask.setInputParameters(input);
    if (useTaskDef) {
        TaskDef taskDef = new TaskDef();
        taskDef.setName("loopTask");
        taskDef.setTimeoutSeconds(200);
        taskDef.setRetryCount(1);
        taskDef.setTimeoutPolicy(TimeoutPolicy.RETRY);
        taskDef.setRetryDelaySeconds(10);
        metadataService.registerTaskDef(Arrays.asList(taskDef));
    }
    Map<String, Object> inputParams1 = new HashMap<>();
    inputParams1.put("p1", "workflow.input.param1");
    inputParams1.put("p2", "workflow.input.param2");
    WorkflowTask http1 = new WorkflowTask();
    http1.setName("http1");
    http1.setInputParameters(inputParams1);
    http1.setTaskReferenceName("http1");
    http1.setWorkflowTaskType(TaskType.HTTP);
    WorkflowTask http2 = new WorkflowTask();
    http2.setName("http2");
    http2.setInputParameters(inputParams1);
    http2.setTaskReferenceName("http2");
    http2.setWorkflowTaskType(TaskType.HTTP);
    WorkflowTask fork = new WorkflowTask();
    fork.setName("fork");
    fork.setInputParameters(inputParams1);
    fork.setTaskReferenceName("fork");
    fork.setWorkflowTaskType(TaskType.FORK_JOIN);
    fork.setForkTasks(Arrays.asList(Arrays.asList(http1), Arrays.asList(http2)));
    WorkflowTask join = new WorkflowTask();
    join.setName("join");
    join.setInputParameters(inputParams1);
    join.setTaskReferenceName("join");
    join.setWorkflowTaskType(TaskType.JOIN);
    WorkflowTask http0 = new WorkflowTask();
    http0.setName("http0");
    http0.setInputParameters(inputParams1);
    http0.setTaskReferenceName("http0");
    http0.setWorkflowTaskType(TaskType.HTTP);
    loopTask.getLoopOver().add(http0);
    loopTask.getLoopOver().add(fork);
    loopTask.getLoopOver().add(join);
    if (isInputParameter) {
        loopTask.setLoopCondition("if ($.loopTask['iteration'] < $.value) { true; } else { false; }");
    } else {
        loopTask.setLoopCondition("if ($.loopTask['iteration'] < " + iteration + " ) { true;} else {false;} ");
    }
    workflowDef.getTasks().add(loopTask);
    if (iteration == 2 && isInputParameter == false) {
        if (useTaskDef) {
            TaskDef taskDef2 = new TaskDef();
            taskDef2.setName("loopTask2");
            taskDef2.setTimeoutSeconds(200);
            taskDef2.setRetryCount(3);
            taskDef2.setTimeoutPolicy(TimeoutPolicy.RETRY);
            taskDef2.setRetryDelaySeconds(10);
            metadataService.registerTaskDef(Arrays.asList(taskDef2));
        }
        WorkflowTask loopTask2 = new WorkflowTask();
        loopTask2.setType(TaskType.DO_WHILE.name());
        loopTask2.setTaskReferenceName("loopTask2");
        loopTask2.setName("loopTask2");
        loopTask2.setWorkflowTaskType(TaskType.DO_WHILE);
        loopTask2.setInputParameters(input);
        WorkflowTask http3 = new WorkflowTask();
        http3.setName("http3");
        http3.setInputParameters(inputParams1);
        http3.setTaskReferenceName("http3");
        http3.setWorkflowTaskType(TaskType.HTTP);
        loopTask2.setLoopCondition("if ($.loopTask2['iteration'] < 1) { true; } else { false; }");
        loopTask2.getLoopOver().add(http3);
        workflowDef.getTasks().add(loopTask2);
    }
    metadataService.registerWorkflowDef(workflowDef);
}
Also used : WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) HashMap(java.util.HashMap) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask)

Example 94 with WorkflowDef

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

the class AbstractWorkflowServiceTest method testExecutionTimes.

@Test
public void testExecutionTimes() {
    String taskName = "junit_task_1";
    TaskDef taskDef = notFoundSafeGetTaskDef(taskName);
    taskDef.setTimeoutSeconds(10);
    metadataService.updateTaskDef(taskDef);
    metadataService.registerTaskDef(Collections.singletonList(taskDef));
    WorkflowDef workflowDef = new WorkflowDef();
    workflowDef.setName("test_execution_times_wf");
    workflowDef.setSchemaVersion(2);
    WorkflowTask workflowTask1 = new WorkflowTask();
    workflowTask1.setName("junit_task_1");
    workflowTask1.setTaskReferenceName("task1");
    WorkflowTask workflowTask2 = new WorkflowTask();
    workflowTask2.setName("junit_task_1");
    workflowTask2.setTaskReferenceName("task2");
    WorkflowTask workflowTask3 = new WorkflowTask();
    workflowTask3.setName("junit_task_1");
    workflowTask3.setTaskReferenceName("task3");
    WorkflowTask forkTask = new WorkflowTask();
    forkTask.setType(TaskType.FORK_JOIN.name());
    forkTask.setName("forktask1");
    forkTask.setTaskReferenceName("forktask1");
    forkTask.getForkTasks().add(Collections.singletonList(workflowTask2));
    forkTask.getForkTasks().add(Collections.singletonList(workflowTask3));
    WorkflowTask joinTask = new WorkflowTask();
    joinTask.setType(TaskType.JOIN.name());
    joinTask.setTaskReferenceName("jointask");
    joinTask.setJoinOn(Arrays.asList("task2", "task3"));
    Map<String, Object> decisionInputParameters = new HashMap<>();
    decisionInputParameters.put("case", "a");
    WorkflowTask decisionTask = new WorkflowTask();
    decisionTask.setType(TaskType.DECISION.name());
    decisionTask.setName("decision1");
    decisionTask.setTaskReferenceName("decision1");
    decisionTask.setInputParameters(decisionInputParameters);
    decisionTask.setDefaultCase(Collections.singletonList(workflowTask1));
    decisionTask.setCaseValueParam("case");
    Map<String, List<WorkflowTask>> decisionCases = new HashMap<>();
    decisionCases.put("a", Arrays.asList(forkTask, joinTask));
    decisionTask.setDecisionCases(decisionCases);
    workflowDef.getTasks().add(decisionTask);
    assertNotNull(workflowDef);
    metadataService.registerWorkflowDef(workflowDef);
    Map workflowInput = Collections.emptyMap();
    // noinspection unchecked
    String workflowId = startOrLoadWorkflowExecution(workflowDef.getName(), workflowDef.getVersion(), "test", workflowInput, null, null);
    Workflow workflow = workflowExecutor.getWorkflow(workflowId, true);
    assertNotNull(workflow);
    assertEquals(5, workflow.getTasks().size());
    Task task = workflowExecutionService.poll("junit_task_1", "test");
    assertNotNull(task);
    task.setStatus(Status.COMPLETED);
    workflowExecutionService.updateTask(task);
    task = workflowExecutionService.poll("junit_task_1", "test");
    assertNotNull(task);
    task.setStatus(Status.COMPLETED);
    workflowExecutionService.updateTask(task);
    workflowExecutor.decide(workflowId);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals(WorkflowStatus.COMPLETED, workflow.getStatus());
    workflow.getTasks().forEach(workflowTask -> {
        assertTrue(workflowTask.getScheduledTime() <= workflowTask.getStartTime());
        assertTrue("" + (workflowTask.getStartTime() - workflowTask.getEndTime()), workflowTask.getStartTime() <= workflowTask.getEndTime());
    });
    assertEquals("decision1", workflow.getTasks().get(0).getReferenceTaskName());
    assertEquals("forktask1", workflow.getTasks().get(1).getReferenceTaskName());
    assertEquals("task2", workflow.getTasks().get(2).getReferenceTaskName());
    assertEquals("task3", workflow.getTasks().get(3).getReferenceTaskName());
    assertEquals("jointask", workflow.getTasks().get(4).getReferenceTaskName());
    metadataService.unregisterWorkflowDef(workflowDef.getName(), 1);
}
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) List(java.util.List) DynamicForkJoinTaskList(com.netflix.conductor.common.metadata.workflow.DynamicForkJoinTaskList) LinkedList(java.util.LinkedList) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 95 with WorkflowDef

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

the class AbstractWorkflowServiceTest method testEventWorkflow.

@Test
public void testEventWorkflow() {
    TaskDef taskDef = new TaskDef();
    taskDef.setName("eventX");
    taskDef.setTimeoutSeconds(1);
    metadataService.registerTaskDef(Collections.singletonList(taskDef));
    WorkflowDef workflowDef = new WorkflowDef();
    workflowDef.setName("test_event");
    workflowDef.setSchemaVersion(2);
    WorkflowTask eventWorkflowTask = new WorkflowTask();
    eventWorkflowTask.setWorkflowTaskType(TaskType.EVENT);
    eventWorkflowTask.setName("eventX");
    eventWorkflowTask.setTaskReferenceName("wait0");
    eventWorkflowTask.setSink("conductor");
    WorkflowTask workflowTask = new WorkflowTask();
    workflowTask.setName("junit_task_1");
    workflowTask.setTaskReferenceName("t1");
    workflowDef.getTasks().add(eventWorkflowTask);
    workflowDef.getTasks().add(workflowTask);
    metadataService.registerWorkflowDef(workflowDef);
    String workflowId = startOrLoadWorkflowExecution(workflowDef.getName(), workflowDef.getVersion(), "", new HashMap<>(), null, null);
    Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
    Workflow workflow = workflowExecutor.getWorkflow(workflowId, true);
    assertNotNull(workflow);
    Task eventTask = workflow.getTasks().get(0);
    assertEquals(TaskType.EVENT.name(), eventTask.getTaskType());
    assertEquals(COMPLETED, eventTask.getStatus());
    assertFalse(eventTask.getOutputData().isEmpty());
    assertNotNull(eventTask.getOutputData().get("event_produced"));
    Task task = workflowExecutionService.poll("junit_task_1", "test");
    assertNotNull(task);
    task.setStatus(Status.COMPLETED);
    workflowExecutionService.updateTask(task);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals("tasks:" + workflow.getTasks(), WorkflowStatus.COMPLETED, workflow.getStatus());
}
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) 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) Test(org.junit.Test)

Aggregations

WorkflowDef (com.netflix.conductor.common.metadata.workflow.WorkflowDef)247 Test (org.junit.Test)185 WorkflowTask (com.netflix.conductor.common.metadata.workflow.WorkflowTask)173 Workflow (com.netflix.conductor.common.run.Workflow)128 HashMap (java.util.HashMap)123 Task (com.netflix.conductor.common.metadata.tasks.Task)100 TaskDef (com.netflix.conductor.common.metadata.tasks.TaskDef)71 SubWorkflow (com.netflix.conductor.core.execution.tasks.SubWorkflow)49 ArrayList (java.util.ArrayList)43 LinkedList (java.util.LinkedList)37 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)35 List (java.util.List)33 UserTask (com.netflix.conductor.tests.utils.UserTask)28 Map (java.util.Map)25 SubWorkflowParams (com.netflix.conductor.common.metadata.workflow.SubWorkflowParams)20 ConstraintViolation (javax.validation.ConstraintViolation)14 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)13 ApplicationException (com.netflix.conductor.core.execution.ApplicationException)13 ValidatorFactory (javax.validation.ValidatorFactory)13 DynamicForkJoinTaskList (com.netflix.conductor.common.metadata.workflow.DynamicForkJoinTaskList)12