Search in sources :

Example 36 with WorkflowDef

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

the class SetVariableTaskMapperTest method getMappedTasks.

@Test
public void getMappedTasks() throws Exception {
    WorkflowTask taskToSchedule = new WorkflowTask();
    taskToSchedule.setType(TaskType.TASK_TYPE_SET_VARIABLE);
    String taskId = IDGenerator.generate();
    WorkflowDef workflowDef = new WorkflowDef();
    Workflow workflow = new Workflow();
    workflow.setWorkflowDefinition(workflowDef);
    TaskMapperContext taskMapperContext = TaskMapperContext.newBuilder().withWorkflowDefinition(workflowDef).withWorkflowInstance(workflow).withTaskDefinition(new TaskDef()).withTaskToSchedule(taskToSchedule).withRetryCount(0).withTaskId(taskId).build();
    List<Task> mappedTasks = new SetVariableTaskMapper().getMappedTasks(taskMapperContext);
    Assert.assertNotNull(mappedTasks);
    Assert.assertEquals(1, mappedTasks.size());
    Assert.assertEquals(TaskType.TASK_TYPE_SET_VARIABLE, mappedTasks.get(0).getTaskType());
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) Workflow(com.netflix.conductor.common.run.Workflow) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Test(org.junit.Test)

Example 37 with WorkflowDef

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

the class SimpleTaskMapperTest method getMappedTasks.

@Test
public void getMappedTasks() throws Exception {
    WorkflowTask taskToSchedule = new WorkflowTask();
    taskToSchedule.setName("simple_task");
    taskToSchedule.setTaskDefinition(new TaskDef("simple_task"));
    String taskId = IDGenerator.generate();
    String retriedTaskId = IDGenerator.generate();
    WorkflowDef wd = new WorkflowDef();
    Workflow w = new Workflow();
    w.setWorkflowDefinition(wd);
    TaskMapperContext taskMapperContext = TaskMapperContext.newBuilder().withWorkflowDefinition(wd).withWorkflowInstance(w).withTaskDefinition(new TaskDef()).withTaskToSchedule(taskToSchedule).withTaskInput(new HashMap<>()).withRetryCount(0).withRetryTaskId(retriedTaskId).withTaskId(taskId).build();
    List<Task> mappedTasks = simpleTaskMapper.getMappedTasks(taskMapperContext);
    assertNotNull(mappedTasks);
    assertEquals(1, mappedTasks.size());
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) Workflow(com.netflix.conductor.common.run.Workflow) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Test(org.junit.Test)

Example 38 with WorkflowDef

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

the class EventTaskMapperTest method getMappedTasks.

@Test
public void getMappedTasks() throws Exception {
    ParametersUtils parametersUtils = Mockito.mock(ParametersUtils.class);
    EventTaskMapper eventTaskMapper = new EventTaskMapper(parametersUtils);
    WorkflowTask taskToBeScheduled = new WorkflowTask();
    taskToBeScheduled.setSink("SQSSINK");
    String taskId = IDGenerator.generate();
    Map<String, Object> eventTaskInput = new HashMap<>();
    eventTaskInput.put("sink", "SQSSINK");
    when(parametersUtils.getTaskInput(anyMap(), any(Workflow.class), any(TaskDef.class), anyString())).thenReturn(eventTaskInput);
    WorkflowDef wd = new WorkflowDef();
    Workflow w = new Workflow();
    w.setWorkflowDefinition(wd);
    TaskMapperContext taskMapperContext = TaskMapperContext.newBuilder().withWorkflowDefinition(wd).withWorkflowInstance(w).withTaskDefinition(new TaskDef()).withTaskToSchedule(taskToBeScheduled).withRetryCount(0).withTaskId(taskId).build();
    List<Task> mappedTasks = eventTaskMapper.getMappedTasks(taskMapperContext);
    assertEquals(1, mappedTasks.size());
    Task eventTask = mappedTasks.get(0);
    assertEquals(taskId, eventTask.getTaskId());
}
Also used : 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) Workflow(com.netflix.conductor.common.run.Workflow) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) ParametersUtils(com.netflix.conductor.core.execution.ParametersUtils) Test(org.junit.Test)

Example 39 with WorkflowDef

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

the class ForkJoinDynamicTaskMapperTest method testDynamicTaskDuplicateTaskRefName.

@Test
public void testDynamicTaskDuplicateTaskRefName() {
    WorkflowDef def = new WorkflowDef();
    def.setName("DYNAMIC_FORK_JOIN_WF");
    def.setDescription(def.getName());
    def.setVersion(1);
    def.setInputParameters(Arrays.asList("param1", "param2"));
    Workflow workflowInstance = new Workflow();
    workflowInstance.setWorkflowDefinition(def);
    WorkflowTask dynamicForkJoinToSchedule = new WorkflowTask();
    dynamicForkJoinToSchedule.setType(TaskType.FORK_JOIN_DYNAMIC.name());
    dynamicForkJoinToSchedule.setTaskReferenceName("dynamicfanouttask");
    dynamicForkJoinToSchedule.setDynamicForkTasksParam("dynamicTasks");
    dynamicForkJoinToSchedule.setDynamicForkTasksInputParamName("dynamicTasksInput");
    dynamicForkJoinToSchedule.getInputParameters().put("dynamicTasks", "dt1.output.dynamicTasks");
    dynamicForkJoinToSchedule.getInputParameters().put("dynamicTasksInput", "dt1.output.dynamicTasksInput");
    WorkflowTask join = new WorkflowTask();
    join.setType(TaskType.JOIN.name());
    join.setTaskReferenceName("dynamictask_join");
    def.getTasks().add(dynamicForkJoinToSchedule);
    def.getTasks().add(join);
    Map<String, Object> input1 = new HashMap<>();
    input1.put("k1", "v1");
    WorkflowTask wt2 = new WorkflowTask();
    wt2.setName("junit_task_2");
    wt2.setTaskReferenceName("xdt1");
    Map<String, Object> input2 = new HashMap<>();
    input2.put("k2", "v2");
    WorkflowTask wt3 = new WorkflowTask();
    wt3.setName("junit_task_3");
    wt3.setTaskReferenceName("xdt2");
    HashMap<String, Object> dynamicTasksInput = new HashMap<>();
    dynamicTasksInput.put("xdt1", input1);
    dynamicTasksInput.put("xdt2", input2);
    dynamicTasksInput.put("dynamicTasks", Arrays.asList(wt2, wt3));
    dynamicTasksInput.put("dynamicTasksInput", dynamicTasksInput);
    // dynamic
    when(parametersUtils.getTaskInput(anyMap(), any(Workflow.class), any(), any())).thenReturn(dynamicTasksInput);
    when(objectMapper.convertValue(any(), any(TypeReference.class))).thenReturn(Arrays.asList(wt2, wt3));
    Task simpleTask1 = new Task();
    simpleTask1.setReferenceTaskName("xdt1");
    // Empty list, this is a bad state, workflow should terminate
    when(deciderService.getTasksToBeScheduled(workflowInstance, wt2, 0)).thenReturn(Lists.newArrayList());
    String taskId = IDGenerator.generate();
    TaskMapperContext taskMapperContext = TaskMapperContext.newBuilder().withWorkflowDefinition(def).withWorkflowInstance(workflowInstance).withTaskToSchedule(dynamicForkJoinToSchedule).withRetryCount(0).withTaskId(taskId).withDeciderService(deciderService).build();
    expectedException.expect(TerminateWorkflowException.class);
    forkJoinDynamicTaskMapper.getMappedTasks(taskMapperContext);
}
Also used : 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) Workflow(com.netflix.conductor.common.run.Workflow) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Test(org.junit.Test)

Example 40 with WorkflowDef

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

the class ForkJoinDynamicTaskMapperTest method getMappedTasksException.

@Test
public void getMappedTasksException() {
    WorkflowDef def = new WorkflowDef();
    def.setName("DYNAMIC_FORK_JOIN_WF");
    def.setDescription(def.getName());
    def.setVersion(1);
    def.setInputParameters(Arrays.asList("param1", "param2"));
    Workflow workflowInstance = new Workflow();
    workflowInstance.setWorkflowDefinition(def);
    WorkflowTask dynamicForkJoinToSchedule = new WorkflowTask();
    dynamicForkJoinToSchedule.setType(TaskType.FORK_JOIN_DYNAMIC.name());
    dynamicForkJoinToSchedule.setTaskReferenceName("dynamicfanouttask");
    dynamicForkJoinToSchedule.setDynamicForkTasksParam("dynamicTasks");
    dynamicForkJoinToSchedule.setDynamicForkTasksInputParamName("dynamicTasksInput");
    dynamicForkJoinToSchedule.getInputParameters().put("dynamicTasks", "dt1.output.dynamicTasks");
    dynamicForkJoinToSchedule.getInputParameters().put("dynamicTasksInput", "dt1.output.dynamicTasksInput");
    WorkflowTask join = new WorkflowTask();
    join.setType(TaskType.JOIN.name());
    join.setTaskReferenceName("dynamictask_join");
    def.getTasks().add(dynamicForkJoinToSchedule);
    Map<String, Object> input1 = new HashMap<>();
    input1.put("k1", "v1");
    WorkflowTask wt2 = new WorkflowTask();
    wt2.setName("junit_task_2");
    wt2.setTaskReferenceName("xdt1");
    Map<String, Object> input2 = new HashMap<>();
    input2.put("k2", "v2");
    WorkflowTask wt3 = new WorkflowTask();
    wt3.setName("junit_task_3");
    wt3.setTaskReferenceName("xdt2");
    HashMap<String, Object> dynamicTasksInput = new HashMap<>();
    dynamicTasksInput.put("xdt1", input1);
    dynamicTasksInput.put("xdt2", input2);
    dynamicTasksInput.put("dynamicTasks", Arrays.asList(wt2, wt3));
    dynamicTasksInput.put("dynamicTasksInput", dynamicTasksInput);
    // when
    when(parametersUtils.getTaskInput(anyMap(), any(Workflow.class), any(), any())).thenReturn(dynamicTasksInput);
    when(objectMapper.convertValue(any(), any(TypeReference.class))).thenReturn(Arrays.asList(wt2, wt3));
    Task simpleTask1 = new Task();
    simpleTask1.setReferenceTaskName("xdt1");
    Task simpleTask2 = new Task();
    simpleTask2.setReferenceTaskName("xdt2");
    when(deciderService.getTasksToBeScheduled(workflowInstance, wt2, 0)).thenReturn(Arrays.asList(simpleTask1));
    when(deciderService.getTasksToBeScheduled(workflowInstance, wt3, 0)).thenReturn(Arrays.asList(simpleTask2));
    String taskId = IDGenerator.generate();
    TaskMapperContext taskMapperContext = TaskMapperContext.newBuilder().withWorkflowDefinition(def).withWorkflowInstance(workflowInstance).withTaskToSchedule(dynamicForkJoinToSchedule).withRetryCount(0).withTaskId(taskId).withDeciderService(deciderService).build();
    // then
    expectedException.expect(TerminateWorkflowException.class);
    forkJoinDynamicTaskMapper.getMappedTasks(taskMapperContext);
}
Also used : 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) Workflow(com.netflix.conductor.common.run.Workflow) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) TypeReference(com.fasterxml.jackson.core.type.TypeReference) 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