Search in sources :

Example 16 with WorkflowTask

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

the class SimpleTaskMapperTest method getMappedTasksException.

@Test
public void getMappedTasksException() throws Exception {
    // Given
    WorkflowTask taskToSchedule = new WorkflowTask();
    taskToSchedule.setName("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();
    // then
    expectedException.expect(TerminateWorkflowException.class);
    expectedException.expectMessage(String.format("Invalid task. Task %s does not have a definition", taskToSchedule.getName()));
    // when
    simpleTaskMapper.getMappedTasks(taskMapperContext);
}
Also used : 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 17 with WorkflowTask

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

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

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

the class SubWorkflowTaskMapperTest method getExceptionWhenNoSubWorkflowParamsPassed.

@Test
public void getExceptionWhenNoSubWorkflowParamsPassed() {
    WorkflowTask workflowTask = new WorkflowTask();
    workflowTask.setName("FooWorkFLow");
    expectedException.expect(TerminateWorkflowException.class);
    expectedException.expectMessage(String.format("Task %s is defined as sub-workflow and is missing subWorkflowParams. " + "Please check the blueprint", workflowTask.getName()));
    subWorkflowTaskMapper.getSubWorkflowParams(workflowTask);
}
Also used : WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Test(org.junit.Test)

Example 20 with WorkflowTask

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

the class TerminateTaskMapperTest method getMappedTasks.

@Test
public void getMappedTasks() throws Exception {
    WorkflowTask taskToSchedule = new WorkflowTask();
    taskToSchedule.setType(TaskType.TASK_TYPE_TERMINATE);
    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 TerminateTaskMapper(parametersUtils).getMappedTasks(taskMapperContext);
    Assert.assertNotNull(mappedTasks);
    Assert.assertEquals(1, mappedTasks.size());
    Assert.assertEquals(TaskType.TASK_TYPE_TERMINATE, 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)

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