Search in sources :

Example 81 with TaskDef

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

the class UserDefinedTaskMapper method getMappedTasks.

/**
 * This method maps a {@link WorkflowTask} of type {@link TaskType#USER_DEFINED}
 * to a {@link Task} in a {@link Task.Status#SCHEDULED} state
 *
 * @param taskMapperContext: A wrapper class containing the {@link WorkflowTask}, {@link WorkflowDef}, {@link Workflow} and a string representation of the TaskId
 * @return a List with just one User defined task
 * @throws TerminateWorkflowException In case if the task definition does not exist
 */
@Override
public List<Task> getMappedTasks(TaskMapperContext taskMapperContext) throws TerminateWorkflowException {
    logger.debug("TaskMapperContext {} in UserDefinedTaskMapper", taskMapperContext);
    WorkflowTask taskToSchedule = taskMapperContext.getTaskToSchedule();
    Workflow workflowInstance = taskMapperContext.getWorkflowInstance();
    String taskId = taskMapperContext.getTaskId();
    int retryCount = taskMapperContext.getRetryCount();
    TaskDef taskDefinition = Optional.ofNullable(taskMapperContext.getTaskDefinition()).orElseGet(() -> Optional.ofNullable(metadataDAO.getTaskDef(taskToSchedule.getName())).orElseThrow(() -> {
        String reason = String.format("Invalid task specified. Cannot find task by name %s in the task definitions", taskToSchedule.getName());
        return new TerminateWorkflowException(reason);
    }));
    Map<String, Object> input = parametersUtils.getTaskInputV2(taskToSchedule.getInputParameters(), workflowInstance, taskId, taskDefinition);
    Task userDefinedTask = new Task();
    userDefinedTask.setTaskType(taskToSchedule.getType());
    userDefinedTask.setTaskDefName(taskToSchedule.getName());
    userDefinedTask.setReferenceTaskName(taskToSchedule.getTaskReferenceName());
    userDefinedTask.setWorkflowInstanceId(workflowInstance.getWorkflowId());
    userDefinedTask.setWorkflowType(workflowInstance.getWorkflowName());
    userDefinedTask.setCorrelationId(workflowInstance.getCorrelationId());
    userDefinedTask.setScheduledTime(System.currentTimeMillis());
    userDefinedTask.setTaskId(taskId);
    userDefinedTask.setInputData(input);
    userDefinedTask.setStatus(Task.Status.SCHEDULED);
    userDefinedTask.setRetryCount(retryCount);
    userDefinedTask.setCallbackAfterSeconds(taskToSchedule.getStartDelay());
    userDefinedTask.setWorkflowTask(taskToSchedule);
    userDefinedTask.setWorkflowPriority(workflowInstance.getPriority());
    userDefinedTask.setRateLimitPerFrequency(taskDefinition.getRateLimitPerFrequency());
    userDefinedTask.setRateLimitFrequencyInSeconds(taskDefinition.getRateLimitFrequencyInSeconds());
    return Collections.singletonList(userDefinedTask);
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) TerminateWorkflowException(com.netflix.conductor.core.execution.TerminateWorkflowException) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) Workflow(com.netflix.conductor.common.run.Workflow) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask)

Example 82 with TaskDef

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

the class TestDeciderOutcomes method init.

@Before
public void init() {
    MetadataDAO metadataDAO = mock(MetadataDAO.class);
    ExternalPayloadStorageUtils externalPayloadStorageUtils = mock(ExternalPayloadStorageUtils.class);
    Configuration configuration = mock(Configuration.class);
    when(configuration.getTaskInputPayloadSizeThresholdKB()).thenReturn(10L);
    when(configuration.getMaxTaskInputPayloadSizeThresholdKB()).thenReturn(10240L);
    TaskDef taskDef = new TaskDef();
    taskDef.setRetryCount(1);
    taskDef.setName("mockTaskDef");
    taskDef.setResponseTimeoutSeconds(60 * 60);
    when(metadataDAO.getTaskDef(anyString())).thenReturn(taskDef);
    ParametersUtils 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));
    this.deciderService = new DeciderService(parametersUtils, metadataDAO, externalPayloadStorageUtils, taskMappers, configuration);
}
Also used : Configuration(com.netflix.conductor.core.config.Configuration) SubWorkflowTaskMapper(com.netflix.conductor.core.execution.mapper.SubWorkflowTaskMapper) HashMap(java.util.HashMap) WaitTaskMapper(com.netflix.conductor.core.execution.mapper.WaitTaskMapper) ExternalPayloadStorageUtils(com.netflix.conductor.core.utils.ExternalPayloadStorageUtils) SimpleTaskMapper(com.netflix.conductor.core.execution.mapper.SimpleTaskMapper) UserDefinedTaskMapper(com.netflix.conductor.core.execution.mapper.UserDefinedTaskMapper) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ForkJoinTaskMapper(com.netflix.conductor.core.execution.mapper.ForkJoinTaskMapper) DecisionTaskMapper(com.netflix.conductor.core.execution.mapper.DecisionTaskMapper) HTTPTaskMapper(com.netflix.conductor.core.execution.mapper.HTTPTaskMapper) ForkJoinDynamicTaskMapper(com.netflix.conductor.core.execution.mapper.ForkJoinDynamicTaskMapper) DynamicTaskMapper(com.netflix.conductor.core.execution.mapper.DynamicTaskMapper) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) JoinTaskMapper(com.netflix.conductor.core.execution.mapper.JoinTaskMapper) ForkJoinTaskMapper(com.netflix.conductor.core.execution.mapper.ForkJoinTaskMapper) ForkJoinDynamicTaskMapper(com.netflix.conductor.core.execution.mapper.ForkJoinDynamicTaskMapper) MetadataDAO(com.netflix.conductor.dao.MetadataDAO) TaskMapper(com.netflix.conductor.core.execution.mapper.TaskMapper) ForkJoinDynamicTaskMapper(com.netflix.conductor.core.execution.mapper.ForkJoinDynamicTaskMapper) SimpleTaskMapper(com.netflix.conductor.core.execution.mapper.SimpleTaskMapper) UserDefinedTaskMapper(com.netflix.conductor.core.execution.mapper.UserDefinedTaskMapper) WaitTaskMapper(com.netflix.conductor.core.execution.mapper.WaitTaskMapper) JoinTaskMapper(com.netflix.conductor.core.execution.mapper.JoinTaskMapper) ForkJoinTaskMapper(com.netflix.conductor.core.execution.mapper.ForkJoinTaskMapper) SubWorkflowTaskMapper(com.netflix.conductor.core.execution.mapper.SubWorkflowTaskMapper) HTTPTaskMapper(com.netflix.conductor.core.execution.mapper.HTTPTaskMapper) DecisionTaskMapper(com.netflix.conductor.core.execution.mapper.DecisionTaskMapper) DynamicTaskMapper(com.netflix.conductor.core.execution.mapper.DynamicTaskMapper) EventTaskMapper(com.netflix.conductor.core.execution.mapper.EventTaskMapper) EventTaskMapper(com.netflix.conductor.core.execution.mapper.EventTaskMapper) Before(org.junit.Before)

Example 83 with TaskDef

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

the class TestDeciderOutcomes method testDecisionCases.

@Test
public void testDecisionCases() {
    WorkflowDef def = new WorkflowDef();
    def.setName("test");
    WorkflowTask even = new WorkflowTask();
    even.setName("even");
    even.setType("SIMPLE");
    even.setTaskReferenceName("even");
    even.setTaskDefinition(new TaskDef("even"));
    WorkflowTask odd = new WorkflowTask();
    odd.setName("odd");
    odd.setType("SIMPLE");
    odd.setTaskReferenceName("odd");
    odd.setTaskDefinition(new TaskDef("odd"));
    WorkflowTask defaultt = new WorkflowTask();
    defaultt.setName("defaultt");
    defaultt.setType("SIMPLE");
    defaultt.setTaskReferenceName("defaultt");
    defaultt.setTaskDefinition(new TaskDef("defaultt"));
    WorkflowTask decide = new WorkflowTask();
    decide.setName("decide");
    decide.setWorkflowTaskType(TaskType.DECISION);
    decide.setTaskReferenceName("d0");
    decide.getInputParameters().put("Id", "${workflow.input.Id}");
    decide.getInputParameters().put("location", "${workflow.input.location}");
    decide.setCaseExpression("if ($.Id == null) 'bad input'; else if ( ($.Id != null && $.Id % 2 == 0) || $.location == 'usa') 'even'; else 'odd'; ");
    decide.getDecisionCases().put("even", Arrays.asList(even));
    decide.getDecisionCases().put("odd", Arrays.asList(odd));
    decide.setDefaultCase(Arrays.asList(defaultt));
    def.getTasks().add(decide);
    def.setSchemaVersion(2);
    Workflow workflow = new Workflow();
    workflow.setWorkflowDefinition(def);
    workflow.setStartTime(System.currentTimeMillis());
    DeciderOutcome outcome = deciderService.decide(workflow);
    assertNotNull(outcome);
    System.out.println("Schedule after starting: " + outcome.tasksToBeScheduled);
    assertEquals(2, outcome.tasksToBeScheduled.size());
    assertEquals(decide.getTaskReferenceName(), outcome.tasksToBeScheduled.get(0).getReferenceTaskName());
    // default
    assertEquals(defaultt.getTaskReferenceName(), outcome.tasksToBeScheduled.get(1).getReferenceTaskName());
    System.out.println(outcome.tasksToBeScheduled.get(0).getOutputData().get("caseOutput"));
    assertEquals(Arrays.asList("bad input"), outcome.tasksToBeScheduled.get(0).getOutputData().get("caseOutput"));
    workflow.getInput().put("Id", 9);
    workflow.getInput().put("location", "usa");
    outcome = deciderService.decide(workflow);
    assertEquals(2, outcome.tasksToBeScheduled.size());
    assertEquals(decide.getTaskReferenceName(), outcome.tasksToBeScheduled.get(0).getReferenceTaskName());
    // even because of location == usa
    assertEquals(even.getTaskReferenceName(), outcome.tasksToBeScheduled.get(1).getReferenceTaskName());
    assertEquals(Arrays.asList("even"), outcome.tasksToBeScheduled.get(0).getOutputData().get("caseOutput"));
    workflow.getInput().put("Id", 9);
    workflow.getInput().put("location", "canada");
    outcome = deciderService.decide(workflow);
    assertEquals(2, outcome.tasksToBeScheduled.size());
    assertEquals(decide.getTaskReferenceName(), outcome.tasksToBeScheduled.get(0).getReferenceTaskName());
    // odd
    assertEquals(odd.getTaskReferenceName(), outcome.tasksToBeScheduled.get(1).getReferenceTaskName());
    assertEquals(Arrays.asList("odd"), outcome.tasksToBeScheduled.get(0).getOutputData().get("caseOutput"));
}
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) DeciderOutcome(com.netflix.conductor.core.execution.DeciderService.DeciderOutcome) Test(org.junit.Test)

Example 84 with TaskDef

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

the class TestDeciderOutcomes method testRetries.

@Test
public void testRetries() {
    WorkflowDef def = new WorkflowDef();
    def.setName("test");
    WorkflowTask workflowTask = new WorkflowTask();
    workflowTask.setName("test_task");
    workflowTask.setType("USER_TASK");
    workflowTask.setTaskReferenceName("t0");
    workflowTask.getInputParameters().put("taskId", "${CPEWF_TASK_ID}");
    workflowTask.getInputParameters().put("requestId", "${workflow.input.requestId}");
    workflowTask.setTaskDefinition(new TaskDef("test_task"));
    def.getTasks().add(workflowTask);
    def.setSchemaVersion(2);
    Workflow workflow = new Workflow();
    workflow.setWorkflowDefinition(def);
    workflow.getInput().put("requestId", 123);
    workflow.setStartTime(System.currentTimeMillis());
    DeciderOutcome outcome = deciderService.decide(workflow);
    assertNotNull(outcome);
    assertEquals(1, outcome.tasksToBeScheduled.size());
    assertEquals(workflowTask.getTaskReferenceName(), outcome.tasksToBeScheduled.get(0).getReferenceTaskName());
    String task1Id = outcome.tasksToBeScheduled.get(0).getTaskId();
    assertEquals(task1Id, outcome.tasksToBeScheduled.get(0).getInputData().get("taskId"));
    assertEquals(123, outcome.tasksToBeScheduled.get(0).getInputData().get("requestId"));
    outcome.tasksToBeScheduled.get(0).setStatus(Status.FAILED);
    workflow.getTasks().addAll(outcome.tasksToBeScheduled);
    outcome = deciderService.decide(workflow);
    assertNotNull(outcome);
    assertEquals(1, outcome.tasksToBeUpdated.size());
    assertEquals(1, outcome.tasksToBeScheduled.size());
    assertEquals(task1Id, outcome.tasksToBeUpdated.get(0).getTaskId());
    assertNotSame(task1Id, outcome.tasksToBeScheduled.get(0).getTaskId());
    assertEquals(outcome.tasksToBeScheduled.get(0).getTaskId(), outcome.tasksToBeScheduled.get(0).getInputData().get("taskId"));
    assertEquals(task1Id, outcome.tasksToBeScheduled.get(0).getRetriedTaskId());
    assertEquals(123, outcome.tasksToBeScheduled.get(0).getInputData().get("requestId"));
    WorkflowTask fork = new WorkflowTask();
    fork.setName("fork0");
    fork.setWorkflowTaskType(TaskType.FORK_JOIN_DYNAMIC);
    fork.setTaskReferenceName("fork0");
    fork.setDynamicForkTasksInputParamName("forkedInputs");
    fork.setDynamicForkTasksParam("forks");
    fork.getInputParameters().put("forks", "${workflow.input.forks}");
    fork.getInputParameters().put("forkedInputs", "${workflow.input.forkedInputs}");
    WorkflowTask join = new WorkflowTask();
    join.setName("join0");
    join.setType("JOIN");
    join.setTaskReferenceName("join0");
    def.getTasks().clear();
    def.getTasks().add(fork);
    def.getTasks().add(join);
    List<WorkflowTask> forks = new LinkedList<>();
    Map<String, Map<String, Object>> forkedInputs = new HashMap<>();
    for (int i = 0; i < 1; i++) {
        WorkflowTask wft = new WorkflowTask();
        wft.setName("f" + i);
        wft.setTaskReferenceName("f" + i);
        wft.setWorkflowTaskType(TaskType.SIMPLE);
        wft.getInputParameters().put("requestId", "${workflow.input.requestId}");
        wft.getInputParameters().put("taskId", "${CPEWF_TASK_ID}");
        wft.setTaskDefinition(new TaskDef("f" + i));
        forks.add(wft);
        Map<String, Object> input = new HashMap<>();
        input.put("k", "v");
        input.put("k1", 1);
        forkedInputs.put(wft.getTaskReferenceName(), input);
    }
    workflow = new Workflow();
    workflow.setWorkflowDefinition(def);
    workflow.getInput().put("requestId", 123);
    workflow.setStartTime(System.currentTimeMillis());
    workflow.getInput().put("forks", forks);
    workflow.getInput().put("forkedInputs", forkedInputs);
    outcome = deciderService.decide(workflow);
    assertNotNull(outcome);
    assertEquals(3, outcome.tasksToBeScheduled.size());
    assertEquals(0, outcome.tasksToBeUpdated.size());
    assertEquals("v", outcome.tasksToBeScheduled.get(1).getInputData().get("k"));
    assertEquals(1, outcome.tasksToBeScheduled.get(1).getInputData().get("k1"));
    assertEquals(outcome.tasksToBeScheduled.get(1).getTaskId(), outcome.tasksToBeScheduled.get(1).getInputData().get("taskId"));
    System.out.println(outcome.tasksToBeScheduled.get(1).getInputData());
    task1Id = outcome.tasksToBeScheduled.get(1).getTaskId();
    outcome.tasksToBeScheduled.get(1).setStatus(Status.FAILED);
    for (Task taskToBeScheduled : outcome.tasksToBeScheduled) {
        taskToBeScheduled.setUpdateTime(System.currentTimeMillis());
    }
    workflow.getTasks().addAll(outcome.tasksToBeScheduled);
    outcome = deciderService.decide(workflow);
    assertTrue(outcome.tasksToBeScheduled.stream().anyMatch(task1 -> task1.getReferenceTaskName().equals("f0")));
    // noinspection ConstantConditions
    Task task1 = outcome.tasksToBeScheduled.stream().filter(t -> t.getReferenceTaskName().equals("f0")).findFirst().get();
    assertEquals("v", task1.getInputData().get("k"));
    assertEquals(1, task1.getInputData().get("k1"));
    assertEquals(task1.getTaskId(), task1.getInputData().get("taskId"));
    assertNotSame(task1Id, task1.getTaskId());
    assertEquals(task1Id, task1.getRetriedTaskId());
    System.out.println(task1.getInputData());
}
Also used : Arrays(java.util.Arrays) TaskMapper(com.netflix.conductor.core.execution.mapper.TaskMapper) Join(com.netflix.conductor.core.execution.tasks.Join) ForkJoinDynamicTaskMapper(com.netflix.conductor.core.execution.mapper.ForkJoinDynamicTaskMapper) Assert.assertNotSame(org.junit.Assert.assertNotSame) Status(com.netflix.conductor.common.metadata.tasks.Task.Status) HashMap(java.util.HashMap) MetadataDAO(com.netflix.conductor.dao.MetadataDAO) Task(com.netflix.conductor.common.metadata.tasks.Task) SimpleTaskMapper(com.netflix.conductor.core.execution.mapper.SimpleTaskMapper) DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) ExternalPayloadStorageUtils(com.netflix.conductor.core.utils.ExternalPayloadStorageUtils) UserDefinedTaskMapper(com.netflix.conductor.core.execution.mapper.UserDefinedTaskMapper) WaitTaskMapper(com.netflix.conductor.core.execution.mapper.WaitTaskMapper) Workflow(com.netflix.conductor.common.run.Workflow) Map(java.util.Map) JoinTaskMapper(com.netflix.conductor.core.execution.mapper.JoinTaskMapper) LinkedList(java.util.LinkedList) Before(org.junit.Before) ForkJoinTaskMapper(com.netflix.conductor.core.execution.mapper.ForkJoinTaskMapper) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) SubWorkflowTaskMapper(com.netflix.conductor.core.execution.mapper.SubWorkflowTaskMapper) HTTPTaskMapper(com.netflix.conductor.core.execution.mapper.HTTPTaskMapper) DecisionTaskMapper(com.netflix.conductor.core.execution.mapper.DecisionTaskMapper) DynamicTaskMapper(com.netflix.conductor.core.execution.mapper.DynamicTaskMapper) Assert.assertNotNull(org.junit.Assert.assertNotNull) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Assert.assertTrue(org.junit.Assert.assertTrue) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) Include(com.fasterxml.jackson.annotation.JsonInclude.Include) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) DeciderOutcome(com.netflix.conductor.core.execution.DeciderService.DeciderOutcome) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) TaskType(com.netflix.conductor.common.metadata.workflow.TaskType) EventTaskMapper(com.netflix.conductor.core.execution.mapper.EventTaskMapper) Configuration(com.netflix.conductor.core.config.Configuration) JsonMapperProvider(com.netflix.conductor.common.utils.JsonMapperProvider) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.mock(org.mockito.Mockito.mock) InputStream(java.io.InputStream) 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) LinkedList(java.util.LinkedList) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) DeciderOutcome(com.netflix.conductor.core.execution.DeciderService.DeciderOutcome) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 85 with TaskDef

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

the class DecisionTaskMapperTest method getMappedTasks.

@Test
public void getMappedTasks() {
    // Given
    // Task Definition
    TaskDef taskDef = new TaskDef();
    Map<String, Object> inputMap = new HashMap<>();
    inputMap.put("Id", "${workflow.input.Id}");
    List<Map<String, Object>> taskDefinitionInput = new LinkedList<>();
    taskDefinitionInput.add(inputMap);
    // Decision task instance
    WorkflowTask decisionTask = new WorkflowTask();
    decisionTask.setType(TaskType.DECISION.name());
    decisionTask.setName("Decision");
    decisionTask.setTaskReferenceName("decisionTask");
    decisionTask.setDefaultCase(Arrays.asList(task1));
    decisionTask.setCaseValueParam("case");
    decisionTask.getInputParameters().put("Id", "${workflow.input.Id}");
    decisionTask.setCaseExpression("if ($.Id == null) 'bad input'; else if ( ($.Id != null && $.Id % 2 == 0)) 'even'; else 'odd'; ");
    Map<String, List<WorkflowTask>> decisionCases = new HashMap<>();
    decisionCases.put("even", Arrays.asList(task2));
    decisionCases.put("odd", Arrays.asList(task3));
    decisionTask.setDecisionCases(decisionCases);
    // Workflow instance
    WorkflowDef workflowDef = new WorkflowDef();
    workflowDef.setSchemaVersion(2);
    Workflow workflowInstance = new Workflow();
    workflowInstance.setWorkflowDefinition(workflowDef);
    Map<String, Object> workflowInput = new HashMap<>();
    workflowInput.put("Id", "22");
    workflowInstance.setInput(workflowInput);
    Map<String, Object> body = new HashMap<>();
    body.put("input", taskDefinitionInput);
    taskDef.getInputTemplate().putAll(body);
    Map<String, Object> input = parametersUtils.getTaskInput(decisionTask.getInputParameters(), workflowInstance, null, null);
    Task theTask = new Task();
    theTask.setReferenceTaskName("Foo");
    theTask.setTaskId(IDGenerator.generate());
    when(deciderService.getTasksToBeScheduled(workflowInstance, task2, 0, null)).thenReturn(Arrays.asList(theTask));
    TaskMapperContext taskMapperContext = TaskMapperContext.newBuilder().withWorkflowDefinition(workflowDef).withWorkflowInstance(workflowInstance).withTaskToSchedule(decisionTask).withTaskInput(input).withRetryCount(0).withTaskId(IDGenerator.generate()).withDeciderService(deciderService).build();
    // When
    List<Task> mappedTasks = decisionTaskMapper.getMappedTasks(taskMapperContext);
    // Then
    assertEquals(2, mappedTasks.size());
    assertEquals("decisionTask", mappedTasks.get(0).getReferenceTaskName());
    assertEquals("Foo", mappedTasks.get(1).getReferenceTaskName());
}
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) LinkedList(java.util.LinkedList) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) List(java.util.List) LinkedList(java.util.LinkedList) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

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