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"));
}
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);
}
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);
}
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());
}
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();
}
Aggregations