Search in sources :

Example 96 with TaskDef

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

the class TestDeciderService method testGetTaskInputV2WithInputTemplate.

@Test
public void testGetTaskInputV2WithInputTemplate() {
    TaskDef def = new TaskDef();
    Map<String, Object> inputTemplate = new HashMap<>();
    inputTemplate.put("url", "https://some_url:7004");
    inputTemplate.put("default_url", "https://default_url:7004");
    inputTemplate.put("someKey", "someValue");
    def.getInputTemplate().putAll(inputTemplate);
    Map<String, Object> workflowInput = new HashMap<>();
    workflowInput.put("some_new_url", "https://some_new_url:7004");
    workflowInput.put("workflow_input_url", "https://workflow_input_url:7004");
    workflowInput.put("some_other_key", "some_other_value");
    WorkflowDef workflowDef = new WorkflowDef();
    workflowDef.setName("testGetTaskInputV2WithInputTemplate");
    workflowDef.setVersion(1);
    Workflow workflow = new Workflow();
    workflow.setWorkflowDefinition(workflowDef);
    workflow.setInput(workflowInput);
    WorkflowTask workflowTask = new WorkflowTask();
    workflowTask.getInputParameters().put("url", "${workflow.input.some_new_url}");
    workflowTask.getInputParameters().put("workflow_input_url", "${workflow.input.workflow_input_url}");
    workflowTask.getInputParameters().put("someKey", "${workflow.input.someKey}");
    workflowTask.getInputParameters().put("someOtherKey", "${workflow.input.some_other_key}");
    workflowTask.getInputParameters().put("someNowhereToBeFoundKey", "${workflow.input.some_ne_key}");
    Map<String, Object> taskInput = parametersUtils.getTaskInputV2(workflowTask.getInputParameters(), workflow, null, def);
    assertTrue(taskInput.containsKey("url"));
    assertTrue(taskInput.containsKey("default_url"));
    assertEquals(taskInput.get("url"), "https://some_new_url:7004");
    assertEquals(taskInput.get("default_url"), "https://default_url:7004");
    assertEquals(taskInput.get("workflow_input_url"), "https://workflow_input_url:7004");
    assertEquals("some_other_value", taskInput.get("someOtherKey"));
    assertEquals("someValue", taskInput.get("someKey"));
    assertNull(taskInput.get("someNowhereToBeFoundKey"));
}
Also used : 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) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 97 with TaskDef

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

the class TestDeciderService method testDecideFailedTask.

@Test
public void testDecideFailedTask() {
    WorkflowDef workflowDef = createLinearWorkflow();
    Workflow workflow = new Workflow();
    workflow.setWorkflowDefinition(workflowDef);
    workflow.setStatus(WorkflowStatus.RUNNING);
    Task task = new Task();
    task.setTaskType("junit_task_l1");
    task.setReferenceTaskName("s1");
    task.setSeq(1);
    task.setRetried(false);
    task.setExecuted(false);
    task.setStatus(Status.FAILED);
    WorkflowTask workflowTask = new WorkflowTask();
    workflowTask.setTaskReferenceName("s1");
    workflowTask.setName("junit_task_l1");
    workflowTask.setTaskDefinition(new TaskDef("junit_task_l1"));
    task.setWorkflowTask(workflowTask);
    workflow.getTasks().add(task);
    DeciderOutcome deciderOutcome = deciderService.decide(workflow);
    assertNotNull(deciderOutcome);
    assertFalse(workflow.getTaskByRefName("s1").isExecuted());
    assertTrue(workflow.getTaskByRefName("s1").isRetried());
    assertEquals(1, deciderOutcome.tasksToBeUpdated.size());
    assertEquals("s1", deciderOutcome.tasksToBeUpdated.get(0).getReferenceTaskName());
    assertEquals(1, deciderOutcome.tasksToBeScheduled.size());
    assertEquals("s1", deciderOutcome.tasksToBeScheduled.get(0).getReferenceTaskName());
    assertFalse(deciderOutcome.isComplete);
}
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) DeciderOutcome(com.netflix.conductor.core.execution.DeciderService.DeciderOutcome) Test(org.junit.Test)

Example 98 with TaskDef

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

the class TestDeciderService method setup.

@Before
public void setup() {
    metadataDAO = mock(MetadataDAO.class);
    externalPayloadStorageUtils = mock(ExternalPayloadStorageUtils.class);
    MetadataDAO metadataDAO = mock(MetadataDAO.class);
    Configuration config = mock(Configuration.class);
    TaskDef taskDef = new TaskDef();
    WorkflowDef workflowDef = new WorkflowDef();
    workflowDef.setName("TestDeciderService");
    workflowDef.setVersion(1);
    when(metadataDAO.getTaskDef(any())).thenReturn(taskDef);
    when(metadataDAO.getLatestWorkflowDef(any())).thenReturn(Optional.of(workflowDef));
    parametersUtils = new ParametersUtils();
    Map<String, TaskMapper> taskMappers = new HashMap<>();
    taskMappers.put("DECISION", new DecisionTaskMapper());
    taskMappers.put("DYNAMIC", new DynamicTaskMapper(parametersUtils, metadataDAO));
    taskMappers.put("FORK_JOIN", new ForkJoinTaskMapper());
    taskMappers.put("JOIN", new JoinTaskMapper());
    taskMappers.put("FORK_JOIN_DYNAMIC", new ForkJoinDynamicTaskMapper(parametersUtils, objectMapper, metadataDAO));
    taskMappers.put("USER_DEFINED", new UserDefinedTaskMapper(parametersUtils, metadataDAO));
    taskMappers.put("SIMPLE", new SimpleTaskMapper(parametersUtils));
    taskMappers.put("SUB_WORKFLOW", new SubWorkflowTaskMapper(parametersUtils, metadataDAO));
    taskMappers.put("EVENT", new EventTaskMapper(parametersUtils));
    taskMappers.put("WAIT", new WaitTaskMapper(parametersUtils));
    taskMappers.put("HTTP", new HTTPTaskMapper(parametersUtils, metadataDAO));
    taskMappers.put("LAMBDA", new LambdaTaskMapper(parametersUtils, metadataDAO));
    deciderService = new DeciderService(parametersUtils, metadataDAO, externalPayloadStorageUtils, taskMappers, config);
}
Also used : Configuration(com.netflix.conductor.core.config.Configuration) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) HashMap(java.util.HashMap) ExternalPayloadStorageUtils(com.netflix.conductor.core.utils.ExternalPayloadStorageUtils) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) MetadataDAO(com.netflix.conductor.dao.MetadataDAO) Before(org.junit.Before)

Example 99 with TaskDef

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

the class JoinTaskMapperTest method getMappedTasks.

@Test
public void getMappedTasks() throws Exception {
    WorkflowTask taskToSchedule = new WorkflowTask();
    taskToSchedule.setType(TaskType.JOIN.name());
    taskToSchedule.setJoinOn(Arrays.asList("task1", "task2"));
    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).withRetryCount(0).withTaskId(taskId).build();
    List<Task> mappedTasks = new JoinTaskMapper().getMappedTasks(taskMapperContext);
    assertNotNull(mappedTasks);
    assertEquals(SystemTaskType.JOIN.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) 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 100 with TaskDef

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

the class DoWhileTaskMapperTest method setup.

@Before
public void setup() {
    taskToSchedule = new WorkflowTask();
    taskToSchedule.setType(TaskType.DO_WHILE.name());
    taskToSchedule.setTaskReferenceName("Test");
    task1 = new Task();
    task1.setReferenceTaskName("task1");
    task2 = new Task();
    task2.setReferenceTaskName("task2");
    workflowTask1 = new WorkflowTask();
    workflowTask1.setTaskReferenceName("task1");
    workflowTask2 = new WorkflowTask();
    workflowTask2.setTaskReferenceName("task2");
    task1.setWorkflowTask(workflowTask1);
    task2.setWorkflowTask(workflowTask2);
    taskToSchedule.setLoopOver(Arrays.asList(task1.getWorkflowTask(), task2.getWorkflowTask()));
    taskToSchedule.setLoopCondition("if ($.second_task + $.first_task > 10) { false; } else { true; }");
    String taskId = IDGenerator.generate();
    workflowDef = new WorkflowDef();
    workflow = new Workflow();
    workflow.setWorkflowDefinition(workflowDef);
    deciderService = Mockito.mock(DeciderService.class);
    metadataDAO = Mockito.mock(MetadataDAO.class);
    taskMapperContext = TaskMapperContext.newBuilder().withWorkflowDefinition(workflowDef).withDeciderService(deciderService).withWorkflowInstance(workflow).withTaskDefinition(new TaskDef()).withTaskToSchedule(taskToSchedule).withRetryCount(0).withTaskId(taskId).build();
}
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) DeciderService(com.netflix.conductor.core.execution.DeciderService) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) Workflow(com.netflix.conductor.common.run.Workflow) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) MetadataDAO(com.netflix.conductor.dao.MetadataDAO) Before(org.junit.Before)

Aggregations

TaskDef (com.netflix.conductor.common.metadata.tasks.TaskDef)172 Test (org.junit.Test)128 WorkflowTask (com.netflix.conductor.common.metadata.workflow.WorkflowTask)121 Task (com.netflix.conductor.common.metadata.tasks.Task)77 Workflow (com.netflix.conductor.common.run.Workflow)76 WorkflowDef (com.netflix.conductor.common.metadata.workflow.WorkflowDef)73 HashMap (java.util.HashMap)56 ArrayList (java.util.ArrayList)32 ConstraintViolation (javax.validation.ConstraintViolation)31 SubWorkflow (com.netflix.conductor.core.execution.tasks.SubWorkflow)30 UserTask (com.netflix.conductor.tests.utils.UserTask)28 LinkedList (java.util.LinkedList)28 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)27 List (java.util.List)22 Map (java.util.Map)19 ApplicationException (com.netflix.conductor.core.execution.ApplicationException)18 Before (org.junit.Before)14 ExpectedException (org.junit.rules.ExpectedException)13 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)12 Collectors (java.util.stream.Collectors)11