use of com.netflix.conductor.core.execution.ParametersUtils 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.core.execution.ParametersUtils in project conductor by Netflix.
the class TestSimpleEventProcessor method testEventProcessor.
@Test
public void testEventProcessor() {
// setup event handler
EventHandler eventHandler = new EventHandler();
eventHandler.setName(UUID.randomUUID().toString());
eventHandler.setActive(true);
Map<String, String> taskToDomain = new HashMap<>();
taskToDomain.put("*", "dev");
Action startWorkflowAction = new Action();
startWorkflowAction.setAction(Type.start_workflow);
startWorkflowAction.setStart_workflow(new StartWorkflow());
startWorkflowAction.getStart_workflow().setName("workflow_x");
startWorkflowAction.getStart_workflow().setVersion(1);
startWorkflowAction.getStart_workflow().setTaskToDomain(taskToDomain);
eventHandler.getActions().add(startWorkflowAction);
Action completeTaskAction = new Action();
completeTaskAction.setAction(Type.complete_task);
completeTaskAction.setComplete_task(new TaskDetails());
completeTaskAction.getComplete_task().setTaskRefName("task_x");
completeTaskAction.getComplete_task().setWorkflowId(UUID.randomUUID().toString());
completeTaskAction.getComplete_task().setOutput(new HashMap<>());
eventHandler.getActions().add(completeTaskAction);
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), anyMap());
AtomicBoolean completed = new AtomicBoolean(false);
doAnswer((Answer<String>) invocation -> {
completed.set(true);
return null;
}).when(workflowExecutor).updateTask(any());
Task task = new Task();
task.setReferenceTaskName(completeTaskAction.getComplete_task().getTaskRefName());
Workflow workflow = new Workflow();
workflow.setTasks(Collections.singletonList(task));
when(workflowExecutor.getWorkflow(completeTaskAction.getComplete_task().getWorkflowId(), true)).thenReturn(workflow);
WorkflowDef workflowDef = new WorkflowDef();
workflowDef.setVersion(startWorkflowAction.getStart_workflow().getVersion());
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());
String queueEvent = eventProcessor.getQueues().keySet().iterator().next();
assertEquals(eventHandler.getEvent(), queueEvent);
String eventProcessorQueue = eventProcessor.getQueues().values().iterator().next();
assertEquals(queueURI, eventProcessorQueue);
Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
assertTrue(started.get());
assertTrue(completed.get());
verify(queue, atMost(1)).ack(any());
verify(queue, never()).publish(any());
}
use of com.netflix.conductor.core.execution.ParametersUtils in project conductor by Netflix.
the class DecisionTaskMapperTest method setUp.
@Before
public void setUp() {
parametersUtils = new ParametersUtils();
ip1 = new HashMap<>();
ip1.put("p1", "${workflow.input.param1}");
ip1.put("p2", "${workflow.input.param2}");
ip1.put("case", "${workflow.input.case}");
task1 = new WorkflowTask();
task1.setName("Test1");
task1.setInputParameters(ip1);
task1.setTaskReferenceName("t1");
task2 = new WorkflowTask();
task2.setName("Test2");
task2.setInputParameters(ip1);
task2.setTaskReferenceName("t2");
task3 = new WorkflowTask();
task3.setName("Test3");
task3.setInputParameters(ip1);
task3.setTaskReferenceName("t3");
deciderService = mock(DeciderService.class);
decisionTaskMapper = new DecisionTaskMapper();
}
use of com.netflix.conductor.core.execution.ParametersUtils in project conductor by Netflix.
the class WaitTaskMapperTest method getMappedTasks.
@Test
public void getMappedTasks() {
// Given
WorkflowTask taskToSchedule = new WorkflowTask();
taskToSchedule.setName("Wait_task");
taskToSchedule.setType(TaskType.WAIT.name());
String taskId = IDGenerator.generate();
ParametersUtils parametersUtils = new ParametersUtils();
Workflow workflow = new Workflow();
WorkflowDef workflowDef = new WorkflowDef();
workflow.setWorkflowDefinition(workflowDef);
TaskMapperContext taskMapperContext = TaskMapperContext.newBuilder().withWorkflowDefinition(workflowDef).withWorkflowInstance(workflow).withTaskDefinition(new TaskDef()).withTaskToSchedule(taskToSchedule).withTaskInput(new HashMap<>()).withRetryCount(0).withTaskId(taskId).build();
WaitTaskMapper waitTaskMapper = new WaitTaskMapper(parametersUtils);
// When
List<Task> mappedTasks = waitTaskMapper.getMappedTasks(taskMapperContext);
// Then
assertEquals(1, mappedTasks.size());
assertEquals(Wait.NAME, mappedTasks.get(0).getTaskType());
}
use of com.netflix.conductor.core.execution.ParametersUtils in project conductor by Netflix.
the class TestEvent method testAsyncComplete.
@Test
public void testAsyncComplete() throws Exception {
Workflow workflow = new Workflow();
workflow.setWorkflowDefinition(testWorkflowDefinition);
Task task = new Task();
task.getInputData().put("sink", "conductor");
task.getInputData().put("asyncComplete", true);
task.setReferenceTaskName("task0");
task.setTaskId("task_id_0");
QueueDAO dao = mock(QueueDAO.class);
String[] publishedQueue = new String[1];
List<Message> publishedMessages = new LinkedList<>();
doAnswer((Answer<Void>) invocation -> {
String queueName = invocation.getArgument(0, String.class);
System.out.println(queueName);
publishedQueue[0] = queueName;
List<Message> messages = invocation.getArgument(1, List.class);
publishedMessages.addAll(messages);
return null;
}).when(dao).push(any(), any());
doAnswer((Answer<List<String>>) invocation -> {
String messageId = invocation.getArgument(1, String.class);
if (publishedMessages.get(0).getId().equals(messageId)) {
publishedMessages.remove(0);
return Collections.singletonList(messageId);
}
return null;
}).when(dao).remove(any(), any());
Map<String, EventQueueProvider> providers = new HashMap<>();
providers.put("conductor", new DynoEventQueueProvider(dao, new TestConfiguration(), Schedulers.from(Executors.newSingleThreadExecutor())));
eventQueues = new EventQueues(providers, parametersUtils);
Event event = new Event(eventQueues, parametersUtils, objectMapper);
event.start(workflow, task, null);
assertEquals(Status.IN_PROGRESS, task.getStatus());
assertNotNull(task.getOutputData());
assertEquals("conductor:" + workflow.getWorkflowName() + ":" + task.getReferenceTaskName(), task.getOutputData().get("event_produced"));
assertEquals(task.getOutputData().get("event_produced"), "conductor:" + publishedQueue[0]);
assertEquals(1, publishedMessages.size());
assertEquals(task.getTaskId(), publishedMessages.get(0).getId());
assertNotNull(publishedMessages.get(0).getPayload());
}
Aggregations