Search in sources :

Example 6 with ParametersUtils

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());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) MetadataService(com.netflix.conductor.service.MetadataService) TestConfiguration(com.netflix.conductor.core.execution.TestConfiguration) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Action(com.netflix.conductor.common.metadata.events.EventHandler.Action) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ArgumentMatchers.anyMap(org.mockito.ArgumentMatchers.anyMap) HashMap(java.util.HashMap) Task(com.netflix.conductor.common.metadata.tasks.Task) StartWorkflow(com.netflix.conductor.common.metadata.events.EventHandler.StartWorkflow) Observable(rx.Observable) ParametersUtils(com.netflix.conductor.core.execution.ParametersUtils) JsonUtils(com.netflix.conductor.core.utils.JsonUtils) LinkedHashMap(java.util.LinkedHashMap) Answer(org.mockito.stubbing.Answer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Workflow(com.netflix.conductor.common.run.Workflow) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Map(java.util.Map) WorkflowExecutor(com.netflix.conductor.core.execution.WorkflowExecutor) EventExecution(com.netflix.conductor.common.metadata.events.EventExecution) Before(org.junit.Before) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) Message(com.netflix.conductor.core.events.queue.Message) Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) 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) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) EventHandler(com.netflix.conductor.common.metadata.events.EventHandler) UUID(java.util.UUID) Type(com.netflix.conductor.common.metadata.events.EventHandler.Action.Type) Mockito.verify(org.mockito.Mockito.verify) TimeUnit(java.util.concurrent.TimeUnit) Mockito.never(org.mockito.Mockito.never) Assert.assertNull(org.junit.Assert.assertNull) Mockito.atMost(org.mockito.Mockito.atMost) TaskDetails(com.netflix.conductor.common.metadata.events.EventHandler.TaskDetails) ExecutionService(com.netflix.conductor.service.ExecutionService) JsonMapperProvider(com.netflix.conductor.common.utils.JsonMapperProvider) ObservableQueue(com.netflix.conductor.core.events.queue.ObservableQueue) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) Action(com.netflix.conductor.common.metadata.events.EventHandler.Action) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) TestConfiguration(com.netflix.conductor.core.execution.TestConfiguration) EventHandler(com.netflix.conductor.common.metadata.events.EventHandler) LinkedHashMap(java.util.LinkedHashMap) StartWorkflow(com.netflix.conductor.common.metadata.events.EventHandler.StartWorkflow) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test)

Example 7 with ParametersUtils

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());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) MetadataService(com.netflix.conductor.service.MetadataService) TestConfiguration(com.netflix.conductor.core.execution.TestConfiguration) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Action(com.netflix.conductor.common.metadata.events.EventHandler.Action) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ArgumentMatchers.anyMap(org.mockito.ArgumentMatchers.anyMap) HashMap(java.util.HashMap) Task(com.netflix.conductor.common.metadata.tasks.Task) StartWorkflow(com.netflix.conductor.common.metadata.events.EventHandler.StartWorkflow) Observable(rx.Observable) ParametersUtils(com.netflix.conductor.core.execution.ParametersUtils) JsonUtils(com.netflix.conductor.core.utils.JsonUtils) LinkedHashMap(java.util.LinkedHashMap) Answer(org.mockito.stubbing.Answer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Workflow(com.netflix.conductor.common.run.Workflow) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Map(java.util.Map) WorkflowExecutor(com.netflix.conductor.core.execution.WorkflowExecutor) EventExecution(com.netflix.conductor.common.metadata.events.EventExecution) Before(org.junit.Before) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) Message(com.netflix.conductor.core.events.queue.Message) Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) 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) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) EventHandler(com.netflix.conductor.common.metadata.events.EventHandler) UUID(java.util.UUID) Type(com.netflix.conductor.common.metadata.events.EventHandler.Action.Type) Mockito.verify(org.mockito.Mockito.verify) TimeUnit(java.util.concurrent.TimeUnit) Mockito.never(org.mockito.Mockito.never) Assert.assertNull(org.junit.Assert.assertNull) Mockito.atMost(org.mockito.Mockito.atMost) TaskDetails(com.netflix.conductor.common.metadata.events.EventHandler.TaskDetails) ExecutionService(com.netflix.conductor.service.ExecutionService) JsonMapperProvider(com.netflix.conductor.common.utils.JsonMapperProvider) ObservableQueue(com.netflix.conductor.core.events.queue.ObservableQueue) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) Action(com.netflix.conductor.common.metadata.events.EventHandler.Action) Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TestConfiguration(com.netflix.conductor.core.execution.TestConfiguration) EventHandler(com.netflix.conductor.common.metadata.events.EventHandler) StartWorkflow(com.netflix.conductor.common.metadata.events.EventHandler.StartWorkflow) Workflow(com.netflix.conductor.common.run.Workflow) StartWorkflow(com.netflix.conductor.common.metadata.events.EventHandler.StartWorkflow) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TaskDetails(com.netflix.conductor.common.metadata.events.EventHandler.TaskDetails) Test(org.junit.Test)

Example 8 with ParametersUtils

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();
}
Also used : DeciderService(com.netflix.conductor.core.execution.DeciderService) ParametersUtils(com.netflix.conductor.core.execution.ParametersUtils) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Before(org.junit.Before)

Example 9 with ParametersUtils

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());
}
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) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) Workflow(com.netflix.conductor.common.run.Workflow) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) ParametersUtils(com.netflix.conductor.core.execution.ParametersUtils) Test(org.junit.Test)

Example 10 with ParametersUtils

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());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) TestConfiguration(com.netflix.conductor.core.execution.TestConfiguration) Status(com.netflix.conductor.common.metadata.tasks.Task.Status) HashMap(java.util.HashMap) Task(com.netflix.conductor.common.metadata.tasks.Task) ParametersUtils(com.netflix.conductor.core.execution.ParametersUtils) Answer(org.mockito.stubbing.Answer) EventQueueProvider(com.netflix.conductor.core.events.EventQueueProvider) Workflow(com.netflix.conductor.common.run.Workflow) Map(java.util.Map) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Schedulers(rx.schedulers.Schedulers) LinkedList(java.util.LinkedList) Before(org.junit.Before) Message(com.netflix.conductor.core.events.queue.Message) MockQueueProvider(com.netflix.conductor.core.events.MockQueueProvider) DynoEventQueueProvider(com.netflix.conductor.core.events.queue.dyno.DynoEventQueueProvider) Assert.assertNotNull(org.junit.Assert.assertNotNull) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) EventQueues(com.netflix.conductor.core.events.EventQueues) Executors(java.util.concurrent.Executors) QueueDAO(com.netflix.conductor.dao.QueueDAO) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) TaskType(com.netflix.conductor.common.metadata.workflow.TaskType) JsonMapperProvider(com.netflix.conductor.common.utils.JsonMapperProvider) ObservableQueue(com.netflix.conductor.core.events.queue.ObservableQueue) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) Task(com.netflix.conductor.common.metadata.tasks.Task) DynoEventQueueProvider(com.netflix.conductor.core.events.queue.dyno.DynoEventQueueProvider) Message(com.netflix.conductor.core.events.queue.Message) HashMap(java.util.HashMap) EventQueueProvider(com.netflix.conductor.core.events.EventQueueProvider) DynoEventQueueProvider(com.netflix.conductor.core.events.queue.dyno.DynoEventQueueProvider) TestConfiguration(com.netflix.conductor.core.execution.TestConfiguration) Workflow(com.netflix.conductor.common.run.Workflow) LinkedList(java.util.LinkedList) QueueDAO(com.netflix.conductor.dao.QueueDAO) EventQueues(com.netflix.conductor.core.events.EventQueues) LinkedList(java.util.LinkedList) List(java.util.List) Test(org.junit.Test)

Aggregations

ParametersUtils (com.netflix.conductor.core.execution.ParametersUtils)11 HashMap (java.util.HashMap)10 Task (com.netflix.conductor.common.metadata.tasks.Task)8 WorkflowDef (com.netflix.conductor.common.metadata.workflow.WorkflowDef)8 Workflow (com.netflix.conductor.common.run.Workflow)8 Before (org.junit.Before)8 Test (org.junit.Test)7 WorkflowTask (com.netflix.conductor.common.metadata.workflow.WorkflowTask)5 Message (com.netflix.conductor.core.events.queue.Message)5 ObservableQueue (com.netflix.conductor.core.events.queue.ObservableQueue)5 Map (java.util.Map)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 JsonMapperProvider (com.netflix.conductor.common.utils.JsonMapperProvider)4 TestConfiguration (com.netflix.conductor.core.execution.TestConfiguration)4 Collections (java.util.Collections)4 Assert.assertEquals (org.junit.Assert.assertEquals)4 Assert.assertNotNull (org.junit.Assert.assertNotNull)4 Assert.assertNull (org.junit.Assert.assertNull)4 Assert.assertTrue (org.junit.Assert.assertTrue)4 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)4