use of com.netflix.conductor.common.metadata.workflow.WorkflowDef in project conductor by Netflix.
the class TestSimpleEventProcessor method testEventHandlerWithCondition.
@Test
public void testEventHandlerWithCondition() {
EventHandler eventHandler = new EventHandler();
eventHandler.setName("cms_intermediate_video_ingest_handler");
eventHandler.setActive(true);
eventHandler.setEvent("sqs:dev_cms_asset_ingest_queue");
eventHandler.setCondition("$.Message.testKey1 == 'level1' && $.Message.metadata.testKey2 == 123456");
Map<String, Object> startWorkflowInput = new LinkedHashMap<>();
startWorkflowInput.put("param1", "${Message.metadata.testKey2}");
startWorkflowInput.put("param2", "SQS-${MessageId}");
Action startWorkflowAction = new Action();
startWorkflowAction.setAction(Type.start_workflow);
startWorkflowAction.setStart_workflow(new StartWorkflow());
startWorkflowAction.getStart_workflow().setName("cms_artwork_automation");
startWorkflowAction.getStart_workflow().setVersion(1);
startWorkflowAction.getStart_workflow().setInput(startWorkflowInput);
startWorkflowAction.setExpandInlineJSON(true);
eventHandler.getActions().add(startWorkflowAction);
eventHandler.setEvent(event);
when(metadataService.getAllEventHandlers()).thenReturn(Collections.singletonList(eventHandler));
when(metadataService.getEventHandlersForEvent(event, true)).thenReturn(Collections.singletonList(eventHandler));
when(executionService.addEventExecution(any())).thenReturn(true);
when(queue.rePublishIfNoAck()).thenReturn(false);
String id = UUID.randomUUID().toString();
AtomicBoolean started = new AtomicBoolean(false);
doAnswer((Answer<String>) invocation -> {
started.set(true);
return id;
}).when(workflowExecutor).startWorkflow(eq(startWorkflowAction.getStart_workflow().getName()), eq(startWorkflowAction.getStart_workflow().getVersion()), eq(startWorkflowAction.getStart_workflow().getCorrelationId()), anyMap(), eq(null), eq(event), eq(null));
WorkflowDef workflowDef = new WorkflowDef();
workflowDef.setName(startWorkflowAction.getStart_workflow().getName());
when(metadataService.getWorkflowDef(any(), any())).thenReturn(workflowDef);
SimpleActionProcessor actionProcessor = new SimpleActionProcessor(workflowExecutor, parametersUtils, jsonUtils);
SimpleEventProcessor eventProcessor = new SimpleEventProcessor(executionService, metadataService, actionProcessor, eventQueues, jsonUtils, new TestConfiguration(), objectMapper);
assertNotNull(eventProcessor.getQueues());
assertEquals(1, eventProcessor.getQueues().size());
Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
assertTrue(started.get());
}
use of com.netflix.conductor.common.metadata.workflow.WorkflowDef in project conductor by Netflix.
the class TestDeciderOutcomes method testOptional.
@Test
public void testOptional() {
WorkflowDef def = new WorkflowDef();
def.setName("test");
WorkflowTask task1 = new WorkflowTask();
task1.setName("task0");
task1.setType("SIMPLE");
task1.setTaskReferenceName("t0");
task1.getInputParameters().put("taskId", "${CPEWF_TASK_ID}");
task1.setOptional(true);
task1.setTaskDefinition(new TaskDef("task0"));
WorkflowTask task2 = new WorkflowTask();
task2.setName("task1");
task2.setType("SIMPLE");
task2.setTaskReferenceName("t1");
task2.setTaskDefinition(new TaskDef("task1"));
def.getTasks().add(task1);
def.getTasks().add(task2);
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(1, outcome.tasksToBeScheduled.size());
assertEquals(task1.getTaskReferenceName(), outcome.tasksToBeScheduled.get(0).getReferenceTaskName());
System.out.println("TaskId of the scheduled task in input: " + outcome.tasksToBeScheduled.get(0).getInputData());
for (int i = 0; i < 3; i++) {
String task1Id = outcome.tasksToBeScheduled.get(0).getTaskId();
assertEquals(task1Id, outcome.tasksToBeScheduled.get(0).getInputData().get("taskId"));
workflow.getTasks().clear();
workflow.getTasks().addAll(outcome.tasksToBeScheduled);
workflow.getTasks().get(0).setStatus(Status.FAILED);
outcome = deciderService.decide(workflow);
assertNotNull(outcome);
System.out.println("Schedule: " + outcome.tasksToBeScheduled);
System.out.println("Update: " + outcome.tasksToBeUpdated);
assertEquals(1, outcome.tasksToBeUpdated.size());
assertEquals(1, outcome.tasksToBeScheduled.size());
assertEquals(Task.Status.FAILED, workflow.getTasks().get(0).getStatus());
assertEquals(task1Id, outcome.tasksToBeUpdated.get(0).getTaskId());
assertEquals(task1.getTaskReferenceName(), outcome.tasksToBeScheduled.get(0).getReferenceTaskName());
assertEquals(i + 1, outcome.tasksToBeScheduled.get(0).getRetryCount());
}
String task1Id = outcome.tasksToBeScheduled.get(0).getTaskId();
workflow.getTasks().clear();
workflow.getTasks().addAll(outcome.tasksToBeScheduled);
workflow.getTasks().get(0).setStatus(Status.FAILED);
outcome = deciderService.decide(workflow);
assertNotNull(outcome);
System.out.println("Schedule: " + outcome.tasksToBeScheduled);
System.out.println("Update: " + outcome.tasksToBeUpdated);
assertEquals(1, outcome.tasksToBeUpdated.size());
assertEquals(1, outcome.tasksToBeScheduled.size());
assertEquals(Task.Status.COMPLETED_WITH_ERRORS, workflow.getTasks().get(0).getStatus());
assertEquals(task1Id, outcome.tasksToBeUpdated.get(0).getTaskId());
assertEquals(task2.getTaskReferenceName(), outcome.tasksToBeScheduled.get(0).getReferenceTaskName());
}
use of com.netflix.conductor.common.metadata.workflow.WorkflowDef in project conductor by Netflix.
the class TestDeciderOutcomes method testOptionalWithDynamicFork.
@Test
public void testOptionalWithDynamicFork() {
WorkflowDef def = new WorkflowDef();
def.setName("test");
WorkflowTask task1 = new WorkflowTask();
task1.setName("fork0");
task1.setWorkflowTaskType(TaskType.FORK_JOIN_DYNAMIC);
task1.setTaskReferenceName("fork0");
task1.setDynamicForkTasksInputParamName("forkedInputs");
task1.setDynamicForkTasksParam("forks");
task1.getInputParameters().put("forks", "${workflow.input.forks}");
task1.getInputParameters().put("forkedInputs", "${workflow.input.forkedInputs}");
WorkflowTask task2 = new WorkflowTask();
task2.setName("join0");
task2.setType("JOIN");
task2.setTaskReferenceName("join0");
def.getTasks().add(task1);
def.getTasks().add(task2);
def.setSchemaVersion(2);
Workflow workflow = new Workflow();
workflow.setWorkflowDefinition(def);
List<WorkflowTask> forks = new LinkedList<>();
Map<String, Map<String, Object>> forkedInputs = new HashMap<>();
for (int i = 0; i < 3; i++) {
WorkflowTask workflowTask = new WorkflowTask();
workflowTask.setName("f" + i);
workflowTask.setTaskReferenceName("f" + i);
workflowTask.setWorkflowTaskType(TaskType.SIMPLE);
workflowTask.setOptional(true);
workflowTask.setTaskDefinition(new TaskDef("f" + i));
forks.add(workflowTask);
forkedInputs.put(workflowTask.getTaskReferenceName(), new HashMap<>());
}
workflow.getInput().put("forks", forks);
workflow.getInput().put("forkedInputs", forkedInputs);
workflow.setStartTime(System.currentTimeMillis());
DeciderOutcome outcome = deciderService.decide(workflow);
assertNotNull(outcome);
assertEquals(5, outcome.tasksToBeScheduled.size());
assertEquals(0, outcome.tasksToBeUpdated.size());
assertEquals(SystemTaskType.FORK.name(), outcome.tasksToBeScheduled.get(0).getTaskType());
assertEquals(Task.Status.COMPLETED, outcome.tasksToBeScheduled.get(0).getStatus());
for (int retryCount = 0; retryCount < 4; retryCount++) {
for (Task taskToBeScheduled : outcome.tasksToBeScheduled) {
if (taskToBeScheduled.getTaskDefName().equals("join0")) {
assertEquals(Task.Status.IN_PROGRESS, taskToBeScheduled.getStatus());
} else if (taskToBeScheduled.getTaskType().matches("(f0|f1|f2)")) {
assertEquals(Task.Status.SCHEDULED, taskToBeScheduled.getStatus());
taskToBeScheduled.setStatus(Status.FAILED);
}
taskToBeScheduled.setUpdateTime(System.currentTimeMillis());
}
workflow.getTasks().addAll(outcome.tasksToBeScheduled);
outcome = deciderService.decide(workflow);
assertNotNull(outcome);
}
assertEquals(SystemTaskType.JOIN.name(), outcome.tasksToBeScheduled.get(0).getTaskType());
for (int i = 0; i < 3; i++) {
assertEquals(Task.Status.COMPLETED_WITH_ERRORS, outcome.tasksToBeUpdated.get(i).getStatus());
assertEquals("f" + (i), outcome.tasksToBeUpdated.get(i).getTaskDefName());
}
assertEquals(Task.Status.IN_PROGRESS, outcome.tasksToBeScheduled.get(0).getStatus());
new Join().execute(workflow, outcome.tasksToBeScheduled.get(0), null);
assertEquals(Task.Status.COMPLETED, outcome.tasksToBeScheduled.get(0).getStatus());
outcome.tasksToBeScheduled.stream().map(task -> task.getStatus() + ":" + task.getTaskType() + ":").forEach(System.out::println);
outcome.tasksToBeUpdated.stream().map(task -> task.getStatus() + ":" + task.getTaskType() + ":").forEach(System.out::println);
}
use of com.netflix.conductor.common.metadata.workflow.WorkflowDef in project conductor by Netflix.
the class TestDeciderService method testGetTaskInput.
@SuppressWarnings("unchecked")
@Test
public void testGetTaskInput() {
Map<String, Object> ip = new HashMap<>();
ip.put("workflowInputParam", "${workflow.input.requestId}");
ip.put("taskOutputParam", "${task2.output.location}");
List<Map<String, Object>> json = new LinkedList<>();
Map<String, Object> m1 = new HashMap<>();
m1.put("name", "person name");
m1.put("city", "New York");
m1.put("phone", 2120001234);
m1.put("status", "${task2.output.isPersonActive}");
Map<String, Object> m2 = new HashMap<>();
m2.put("employer", "City Of New York");
m2.put("color", "purple");
m2.put("requestId", "${workflow.input.requestId}");
json.add(m1);
json.add(m2);
ip.put("complexJson", json);
WorkflowDef def = new WorkflowDef();
def.setName("testGetTaskInput");
def.setSchemaVersion(2);
Workflow workflow = new Workflow();
workflow.setWorkflowDefinition(def);
workflow.getInput().put("requestId", "request id 001");
Task task = new Task();
task.setReferenceTaskName("task2");
task.getOutputData().put("location", "http://location");
task.getOutputData().put("isPersonActive", true);
workflow.getTasks().add(task);
Map<String, Object> taskInput = parametersUtils.getTaskInput(ip, workflow, null, null);
assertNotNull(taskInput);
assertTrue(taskInput.containsKey("workflowInputParam"));
assertTrue(taskInput.containsKey("taskOutputParam"));
assertEquals("request id 001", taskInput.get("workflowInputParam"));
assertEquals("http://location", taskInput.get("taskOutputParam"));
assertNotNull(taskInput.get("complexJson"));
assertTrue(taskInput.get("complexJson") instanceof List);
List<Map<String, Object>> resolvedInput = (List<Map<String, Object>>) taskInput.get("complexJson");
assertEquals(2, resolvedInput.size());
}
use of com.netflix.conductor.common.metadata.workflow.WorkflowDef in project conductor by Netflix.
the class TestDeciderService method testDeciderGetNextTask.
@Test
public void testDeciderGetNextTask() {
WorkflowDef workflowDef = createDoWhileInForkWorkflow();
Workflow workflow = new Workflow();
workflow.setWorkflowDefinition(workflowDef);
Task task1 = new Task();
task1.setReferenceTaskName("fork");
task1.setStatus(Status.COMPLETED);
task1.setTaskId("task1");
Task task2 = new Task();
task2.setReferenceTaskName("loopTask");
task2.setStatus(Status.SCHEDULED);
task2.setTaskId("task2");
task2.setIteration(1);
Task task3 = new Task();
task3.setReferenceTaskName("junit_task_0__1");
task3.setStatus(Status.COMPLETED);
task3.setTaskId("task3");
task3.setIteration(1);
Task task4 = new Task();
task4.setReferenceTaskName("junit_task_3");
task4.setStatus(Status.COMPLETED);
task4.setTaskId("task4");
Task task5 = new Task();
task5.setReferenceTaskName("join");
task5.setStatus(Status.IN_PROGRESS);
task5.setTaskId("task5");
workflow.setTasks(Arrays.asList(task1, task2, task3, task4, task5));
// verify the next task of first task in DoWhile
List<Task> nextTask1 = deciderService.getNextTask(workflow, task3);
assertEquals(1, nextTask1.size());
assertEquals("junit_task_1", nextTask1.get(0).getReferenceTaskName());
Task task6 = new Task();
task6.setReferenceTaskName("junit_task_1__1");
task6.setStatus(Status.COMPLETED);
task6.setTaskId("task6");
task6.setIteration(1);
workflow.setTasks(Arrays.asList(task1, task2, task3, task4, task5, task6));
// verify the next task of last task in DoWhile
List<Task> nextTask2 = deciderService.getNextTask(workflow, task6);
assertEquals(0, nextTask2.size());
task2.setStatus(Status.COMPLETED);
task2.setIteration(10);
// verify the next task of DoWhile
List<Task> nextTask3 = deciderService.getNextTask(workflow, task2);
assertEquals(1, nextTask3.size());
assertEquals("junit_task_2", nextTask3.get(0).getReferenceTaskName());
}
Aggregations