Search in sources :

Example 36 with Task

use of com.netflix.conductor.common.metadata.tasks.Task in project conductor by Netflix.

the class TestSubWorkflow method testStartSubWorkflowTaskToDomain.

@Test
public void testStartSubWorkflowTaskToDomain() {
    WorkflowDef workflowDef = new WorkflowDef();
    Workflow workflowInstance = new Workflow();
    workflowInstance.setWorkflowDefinition(workflowDef);
    Map<String, String> taskToDomain = new HashMap<String, String>() {

        {
            put("*", "unittest");
        }
    };
    Task task = new Task();
    task.setOutputData(new HashMap<>());
    Map<String, Object> inputData = new HashMap<>();
    inputData.put("subWorkflowName", "UnitWorkFlow");
    inputData.put("subWorkflowVersion", 2);
    inputData.put("subWorkflowTaskToDomain", taskToDomain);
    task.setInputData(inputData);
    when(workflowExecutor.startWorkflow(eq("UnitWorkFlow"), eq(2), eq(inputData), eq(null), any(), any(), any(), eq(null), eq(taskToDomain))).thenReturn("workflow_1");
    subWorkflow.start(workflowInstance, task, workflowExecutor);
    assertEquals("workflow_1", task.getSubWorkflowId());
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) HashMap(java.util.HashMap) Workflow(com.netflix.conductor.common.run.Workflow) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 37 with Task

use of com.netflix.conductor.common.metadata.tasks.Task in project conductor by Netflix.

the class TestSubWorkflow method testStartSubWorkflowWithSubWorkflowDefinition.

@Test
public void testStartSubWorkflowWithSubWorkflowDefinition() {
    WorkflowDef workflowDef = new WorkflowDef();
    Workflow workflowInstance = new Workflow();
    workflowInstance.setWorkflowDefinition(workflowDef);
    WorkflowDef subWorkflowDef = new WorkflowDef();
    subWorkflowDef.setName("subWorkflow_1");
    Task task = new Task();
    task.setOutputData(new HashMap<>());
    Map<String, Object> inputData = new HashMap<>();
    inputData.put("subWorkflowName", "UnitWorkFlow");
    inputData.put("subWorkflowVersion", 2);
    inputData.put("subWorkflowDefinition", subWorkflowDef);
    task.setInputData(inputData);
    when(workflowExecutor.startWorkflow(eq(subWorkflowDef), eq(inputData), eq(null), any(), eq(0), any(), any(), eq(null), any())).thenReturn("workflow_1");
    subWorkflow.start(workflowInstance, task, workflowExecutor);
    assertEquals("workflow_1", task.getSubWorkflowId());
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) HashMap(java.util.HashMap) Workflow(com.netflix.conductor.common.run.Workflow) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 38 with Task

use of com.netflix.conductor.common.metadata.tasks.Task in project conductor by Netflix.

the class TestSubWorkflow method testStartSubWorkflowWithWorkflowInput.

@Test
public void testStartSubWorkflowWithWorkflowInput() {
    WorkflowDef workflowDef = new WorkflowDef();
    Workflow workflowInstance = new Workflow();
    workflowInstance.setWorkflowDefinition(workflowDef);
    Task task = new Task();
    task.setOutputData(new HashMap<>());
    Map<String, Object> inputData = new HashMap<>();
    inputData.put("subWorkflowName", "UnitWorkFlow");
    inputData.put("subWorkflowVersion", 3);
    Map<String, Object> workflowInput = new HashMap<>();
    workflowInput.put("test", "value");
    inputData.put("workflowInput", workflowInput);
    task.setInputData(inputData);
    when(workflowExecutor.startWorkflow(eq("UnitWorkFlow"), eq(3), eq(workflowInput), eq(null), any(), any(), any(), eq(null), any())).thenReturn("workflow_1");
    subWorkflow.start(workflowInstance, task, workflowExecutor);
    assertEquals("workflow_1", task.getSubWorkflowId());
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) HashMap(java.util.HashMap) Workflow(com.netflix.conductor.common.run.Workflow) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 39 with Task

use of com.netflix.conductor.common.metadata.tasks.Task in project conductor by Netflix.

the class JsonJQTransformTaskMapperTest method getMappedTasks.

@Test
public void getMappedTasks() throws Exception {
    WorkflowTask taskToSchedule = new WorkflowTask();
    taskToSchedule.setName("json_jq_transform_task");
    taskToSchedule.setType(TaskType.JSON_JQ_TRANSFORM.name());
    taskToSchedule.setTaskDefinition(new TaskDef("json_jq_transform_task"));
    Map<String, Object> taskInput = new HashMap<>();
    taskInput.put("in1", new String[] { "a", "b" });
    taskInput.put("in2", new String[] { "c", "d" });
    taskInput.put("queryExpression", "{ out: (.in1 + .in2) }");
    taskToSchedule.setInputParameters(taskInput);
    String taskId = 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(taskInput).withRetryCount(0).withTaskId(taskId).build();
    List<Task> mappedTasks = new JsonJQTransformTaskMapper(parametersUtils, metadataDAO).getMappedTasks(taskMapperContext);
    assertEquals(1, mappedTasks.size());
    assertNotNull(mappedTasks);
    assertEquals(TaskType.JSON_JQ_TRANSFORM.name(), 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) HashMap(java.util.HashMap) 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 40 with Task

use of com.netflix.conductor.common.metadata.tasks.Task in project conductor by Netflix.

the class JsonJQTransformTaskMapperTest method getMappedTasks_WithoutTaskDef.

@Test
public void getMappedTasks_WithoutTaskDef() throws Exception {
    WorkflowTask taskToSchedule = new WorkflowTask();
    taskToSchedule.setName("json_jq_transform_task");
    taskToSchedule.setType(TaskType.JSON_JQ_TRANSFORM.name());
    Map<String, Object> taskInput = new HashMap<>();
    taskInput.put("in1", new String[] { "a", "b" });
    taskInput.put("in2", new String[] { "c", "d" });
    taskInput.put("queryExpression", "{ out: (.in1 + .in2) }");
    taskToSchedule.setInputParameters(taskInput);
    String taskId = IDGenerator.generate();
    WorkflowDef wd = new WorkflowDef();
    Workflow w = new Workflow();
    w.setWorkflowDefinition(wd);
    TaskMapperContext taskMapperContext = TaskMapperContext.newBuilder().withWorkflowDefinition(wd).withWorkflowInstance(w).withTaskDefinition(null).withTaskToSchedule(taskToSchedule).withTaskInput(taskInput).withRetryCount(0).withTaskId(taskId).build();
    List<Task> mappedTasks = new JsonJQTransformTaskMapper(parametersUtils, metadataDAO).getMappedTasks(taskMapperContext);
    assertEquals(1, mappedTasks.size());
    assertNotNull(mappedTasks);
    assertEquals(TaskType.JSON_JQ_TRANSFORM.name(), 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) HashMap(java.util.HashMap) Workflow(com.netflix.conductor.common.run.Workflow) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Test(org.junit.Test)

Aggregations

Task (com.netflix.conductor.common.metadata.tasks.Task)357 Workflow (com.netflix.conductor.common.run.Workflow)249 Test (org.junit.Test)248 WorkflowTask (com.netflix.conductor.common.metadata.workflow.WorkflowTask)227 HashMap (java.util.HashMap)147 WorkflowDef (com.netflix.conductor.common.metadata.workflow.WorkflowDef)121 SubWorkflow (com.netflix.conductor.core.execution.tasks.SubWorkflow)110 TaskDef (com.netflix.conductor.common.metadata.tasks.TaskDef)95 UserTask (com.netflix.conductor.tests.utils.UserTask)73 Map (java.util.Map)53 LinkedList (java.util.LinkedList)51 WorkflowSystemTask (com.netflix.conductor.core.execution.tasks.WorkflowSystemTask)45 List (java.util.List)45 ApplicationException (com.netflix.conductor.core.execution.ApplicationException)41 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)39 TaskResult (com.netflix.conductor.common.metadata.tasks.TaskResult)38 Status (com.netflix.conductor.common.metadata.tasks.Task.Status)32 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)29 Collectors (java.util.stream.Collectors)29 TaskType (com.netflix.conductor.common.metadata.workflow.TaskType)28