Search in sources :

Example 96 with WorkflowTask

use of com.netflix.conductor.common.metadata.workflow.WorkflowTask 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 97 with WorkflowTask

use of com.netflix.conductor.common.metadata.workflow.WorkflowTask 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)

Example 98 with WorkflowTask

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

the class WorkflowServiceTest method createWorkflowWithInlineSubWorkflow.

private WorkflowDef createWorkflowWithInlineSubWorkflow() {
    WorkflowDef subWorkflowDef = createInlineSubWorkflow();
    WorkflowTask subWfTask = new WorkflowTask();
    subWfTask.setName("subWorkflowTask");
    subWfTask.setType(SUB_WORKFLOW.name());
    SubWorkflowParams swp = new SubWorkflowParams();
    swp.setName("does-not-existing-wf");
    swp.setWorkflowDefinition(subWorkflowDef);
    subWfTask.setSubWorkflowParam(swp);
    Map<String, Object> inputParam = new HashMap<>();
    inputParam.put("test", "test value");
    inputParam.put("param1", "sub workflow input param1");
    inputParam.put("param2", subWorkflowDef.getVersion());
    subWfTask.setInputParameters(inputParam);
    subWfTask.setTaskReferenceName("sw1");
    WorkflowDef main = new WorkflowDef();
    main.setVersion(2);
    main.setSchemaVersion(2);
    main.setInputParameters(Arrays.asList("param1", "param2"));
    main.setName(WF_WITH_INLINE_SUB_WF);
    main.getTasks().add(subWfTask);
    return main;
}
Also used : SubWorkflowParams(com.netflix.conductor.common.metadata.workflow.SubWorkflowParams) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) HashMap(java.util.HashMap) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask)

Example 99 with WorkflowTask

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

the class WorkflowServiceTest method createWorkflowWithInlineSubWorkflowWithInlineSubWorkflow.

private void createWorkflowWithInlineSubWorkflowWithInlineSubWorkflow() {
    WorkflowDef subWorkflowDef = createWorkflowWithInlineSubWorkflow();
    WorkflowTask workflowTask = new WorkflowTask();
    workflowTask.setName("subWorkflowTask");
    workflowTask.setType(SUB_WORKFLOW.name());
    SubWorkflowParams swp = new SubWorkflowParams();
    swp.setName("dummy-name");
    swp.setWorkflowDef(subWorkflowDef);
    workflowTask.setSubWorkflowParam(swp);
    Map<String, Object> input = new HashMap<>();
    input.put("test", "test value");
    input.put("param1", "sub workflow task input param1");
    input.put("param2", 21);
    workflowTask.setInputParameters(input);
    workflowTask.setTaskReferenceName("sw2");
    WorkflowDef main = new WorkflowDef();
    main.setSchemaVersion(2);
    main.setInputParameters(Arrays.asList("param1", "param2"));
    main.setName(WF_WITH_INLINE_SUB_WF_WITH_INLINE_SUB_WF);
    main.getTasks().add(workflowTask);
    Map<String, Object> outputParameters = new HashMap<>();
    outputParameters.put("o1", "${workflow.input.param1}");
    outputParameters.put("o2", "${sw2.output.o2}");
    main.setOutputParameters(outputParameters);
    metadataService.updateWorkflowDef(Collections.singletonList(main));
}
Also used : SubWorkflowParams(com.netflix.conductor.common.metadata.workflow.SubWorkflowParams) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) HashMap(java.util.HashMap) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask)

Example 100 with WorkflowTask

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

the class WorkflowServiceTest method createInlineSubWorkflow.

private WorkflowDef createInlineSubWorkflow() {
    // create inline subworkflow
    WorkflowDef subWorkflowDef = new WorkflowDef();
    subWorkflowDef.setName("inline_sw_1");
    subWorkflowDef.setDescription(subWorkflowDef.getName());
    subWorkflowDef.setVersion(3);
    subWorkflowDef.setSchemaVersion(2);
    Map<String, Object> outputParameters = new HashMap<>();
    outputParameters.put("o1", "${workflow.input.param1}");
    outputParameters.put("o2", "${isw_t1.output.uuid}");
    subWorkflowDef.setOutputParameters(outputParameters);
    WorkflowTask wft1 = new WorkflowTask();
    wft1.setName("junit_task_1");
    wft1.setTaskReferenceName("isw_t1");
    subWorkflowDef.setTasks(Collections.singletonList(wft1));
    return subWorkflowDef;
}
Also used : WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) HashMap(java.util.HashMap) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask)

Aggregations

WorkflowTask (com.netflix.conductor.common.metadata.workflow.WorkflowTask)240 Test (org.junit.Test)166 WorkflowDef (com.netflix.conductor.common.metadata.workflow.WorkflowDef)147 TaskDef (com.netflix.conductor.common.metadata.tasks.TaskDef)106 Workflow (com.netflix.conductor.common.run.Workflow)106 HashMap (java.util.HashMap)102 Task (com.netflix.conductor.common.metadata.tasks.Task)98 ArrayList (java.util.ArrayList)51 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)44 ConstraintViolation (javax.validation.ConstraintViolation)41 LinkedList (java.util.LinkedList)40 List (java.util.List)33 SubWorkflow (com.netflix.conductor.core.execution.tasks.SubWorkflow)32 Map (java.util.Map)25 SubWorkflowParams (com.netflix.conductor.common.metadata.workflow.SubWorkflowParams)24 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