Search in sources :

Example 1 with ParametersUtils

use of com.netflix.conductor.core.execution.ParametersUtils in project conductor by Netflix.

the class DoWhileTest method setup.

@Before
public void setup() {
    workflow = Mockito.mock(Workflow.class);
    deciderService = Mockito.mock(DeciderService.class);
    metadataDAO = Mockito.mock(MetadataDAO.class);
    queueDAO = Mockito.mock(QueueDAO.class);
    parametersUtils = Mockito.mock(ParametersUtils.class);
    metadataMapperService = Mockito.mock(MetadataMapperService.class);
    workflowStatusListener = Mockito.mock(WorkflowStatusListener.class);
    executionDAOFacade = Mockito.mock(ExecutionDAOFacade.class);
    executionLockService = Mockito.mock(ExecutionLockService.class);
    config = Mockito.mock(Configuration.class);
    provider = spy(new WorkflowExecutor(deciderService, metadataDAO, queueDAO, metadataMapperService, workflowStatusListener, executionDAOFacade, config, executionLockService, parametersUtils));
    loopWorkflowTask1 = new WorkflowTask();
    loopWorkflowTask1.setTaskReferenceName("task1");
    loopWorkflowTask1.setName("task1");
    loopWorkflowTask2 = new WorkflowTask();
    loopWorkflowTask2.setTaskReferenceName("task2");
    loopWorkflowTask2.setName("task2");
    task1 = new Task();
    task1.setWorkflowTask(loopWorkflowTask1);
    task1.setReferenceTaskName("task1");
    task1.setStatus(Task.Status.COMPLETED);
    task1.setTaskType(TaskType.HTTP.name());
    task1.setInputData(new HashMap<>());
    task1.setIteration(1);
    task2 = new Task();
    task2.setWorkflowTask(loopWorkflowTask2);
    task2.setReferenceTaskName("task2");
    task2.setStatus(Task.Status.COMPLETED);
    task2.setTaskType(TaskType.HTTP.name());
    task2.setInputData(new HashMap<>());
    task2.setIteration(1);
    loopTask = new Task();
    loopTask.setReferenceTaskName("loopTask");
    loopTask.setTaskType(TaskType.DO_WHILE.name());
    loopTask.setInputData(new HashMap<>());
    loopTask.setIteration(1);
    loopWorkflowTask = new WorkflowTask();
    loopWorkflowTask.setTaskReferenceName("loopTask");
    loopWorkflowTask.setType(TaskType.DO_WHILE.name());
    loopWorkflowTask.setName("loopTask");
    loopWorkflowTask.setLoopCondition("if ($.loopTask['iteration'] < 1) { false; } else { true; }");
    loopWorkflowTask.setLoopOver(Arrays.asList(task1.getWorkflowTask(), task2.getWorkflowTask()));
    loopTask.setWorkflowTask(loopWorkflowTask);
    doWhile = new DoWhile();
    loopTaskDef = Mockito.mock(TaskDef.class);
    Mockito.doReturn(loopTaskDef).when(provider).getTaskDefinition(loopTask);
    Mockito.doReturn(task1).when(workflow).getTaskByRefName(task1.getReferenceTaskName());
    Mockito.doReturn(task2).when(workflow).getTaskByRefName(task2.getReferenceTaskName());
    Mockito.doReturn(task1).when(workflow).getTaskByRefName("task1__2");
    Mockito.doReturn(task2).when(workflow).getTaskByRefName("task2__2");
    Mockito.doReturn(new HashMap<>()).when(parametersUtils).getTaskInputV2(isA(Map.class), isA(Workflow.class), isA(String.class), isA(TaskDef.class));
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Configuration(com.netflix.conductor.core.config.Configuration) DeciderService(com.netflix.conductor.core.execution.DeciderService) Workflow(com.netflix.conductor.common.run.Workflow) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) ExecutionLockService(com.netflix.conductor.service.ExecutionLockService) QueueDAO(com.netflix.conductor.dao.QueueDAO) MetadataMapperService(com.netflix.conductor.core.metadata.MetadataMapperService) WorkflowStatusListener(com.netflix.conductor.core.execution.WorkflowStatusListener) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) ParametersUtils(com.netflix.conductor.core.execution.ParametersUtils) WorkflowExecutor(com.netflix.conductor.core.execution.WorkflowExecutor) ExecutionDAOFacade(com.netflix.conductor.core.orchestration.ExecutionDAOFacade) HashMap(java.util.HashMap) Map(java.util.Map) MetadataDAO(com.netflix.conductor.dao.MetadataDAO) Before(org.junit.Before)

Example 2 with ParametersUtils

use of com.netflix.conductor.core.execution.ParametersUtils in project conductor by Netflix.

the class TestEvent method setup.

@Before
public void setup() {
    Map<String, EventQueueProvider> providers = new HashMap<>();
    providers.put("sqs", new MockQueueProvider("sqs"));
    providers.put("conductor", new MockQueueProvider("conductor"));
    parametersUtils = new ParametersUtils();
    eventQueues = new EventQueues(providers, parametersUtils);
    testWorkflowDefinition = new WorkflowDef();
    testWorkflowDefinition.setName("testWorkflow");
    testWorkflowDefinition.setVersion(2);
}
Also used : WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) HashMap(java.util.HashMap) EventQueues(com.netflix.conductor.core.events.EventQueues) EventQueueProvider(com.netflix.conductor.core.events.EventQueueProvider) DynoEventQueueProvider(com.netflix.conductor.core.events.queue.dyno.DynoEventQueueProvider) ParametersUtils(com.netflix.conductor.core.execution.ParametersUtils) MockQueueProvider(com.netflix.conductor.core.events.MockQueueProvider) Before(org.junit.Before)

Example 3 with ParametersUtils

use of com.netflix.conductor.core.execution.ParametersUtils in project conductor by Netflix.

the class TestEvent method test.

@SuppressWarnings("unchecked")
@Test
public void test() {
    Workflow workflow = new Workflow();
    workflow.setWorkflowDefinition(testWorkflowDefinition);
    Task task = new Task();
    task.getInputData().put("sink", "conductor");
    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<Boolean>) invocation -> {
        String messageId = invocation.getArgument(1, String.class);
        if (publishedMessages.get(0).getId().equals(messageId)) {
            publishedMessages.remove(0);
            return true;
        }
        return null;
    }).when(dao).ack(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(Task.Status.COMPLETED, 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());
    event.cancel(workflow, task, null);
    assertTrue(publishedMessages.isEmpty());
}
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)

Example 4 with ParametersUtils

use of com.netflix.conductor.core.execution.ParametersUtils in project conductor by Netflix.

the class EventTaskMapperTest method getMappedTasks.

@Test
public void getMappedTasks() throws Exception {
    ParametersUtils parametersUtils = Mockito.mock(ParametersUtils.class);
    EventTaskMapper eventTaskMapper = new EventTaskMapper(parametersUtils);
    WorkflowTask taskToBeScheduled = new WorkflowTask();
    taskToBeScheduled.setSink("SQSSINK");
    String taskId = IDGenerator.generate();
    Map<String, Object> eventTaskInput = new HashMap<>();
    eventTaskInput.put("sink", "SQSSINK");
    when(parametersUtils.getTaskInput(anyMap(), any(Workflow.class), any(TaskDef.class), anyString())).thenReturn(eventTaskInput);
    WorkflowDef wd = new WorkflowDef();
    Workflow w = new Workflow();
    w.setWorkflowDefinition(wd);
    TaskMapperContext taskMapperContext = TaskMapperContext.newBuilder().withWorkflowDefinition(wd).withWorkflowInstance(w).withTaskDefinition(new TaskDef()).withTaskToSchedule(taskToBeScheduled).withRetryCount(0).withTaskId(taskId).build();
    List<Task> mappedTasks = eventTaskMapper.getMappedTasks(taskMapperContext);
    assertEquals(1, mappedTasks.size());
    Task eventTask = mappedTasks.get(0);
    assertEquals(taskId, eventTask.getTaskId());
}
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) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) ParametersUtils(com.netflix.conductor.core.execution.ParametersUtils) Test(org.junit.Test)

Example 5 with ParametersUtils

use of com.netflix.conductor.core.execution.ParametersUtils in project conductor by Netflix.

the class TestSimpleEventProcessor method setup.

@Before
public void setup() {
    event = "sqs:arn:account090:sqstest1";
    queueURI = "arn:account090:sqstest1";
    metadataService = mock(MetadataService.class);
    executionService = mock(ExecutionService.class);
    workflowExecutor = mock(WorkflowExecutor.class);
    actionProcessor = mock(SimpleActionProcessor.class);
    parametersUtils = new ParametersUtils();
    jsonUtils = new JsonUtils();
    EventQueueProvider provider = mock(EventQueueProvider.class);
    queue = mock(ObservableQueue.class);
    Message[] messages = new Message[1];
    messages[0] = new Message("t0", "{\"Type\":\"Notification\",\"MessageId\":\"7e4e6415-01e9-5caf-abaa-37fd05d446ff\",\"Message\":\"{\\n    \\\"testKey1\\\": \\\"level1\\\",\\n    \\\"metadata\\\": {\\n      \\\"testKey2\\\": 123456 }\\n  }\",\"Timestamp\":\"2018-08-10T21:22:05.029Z\",\"SignatureVersion\":\"1\"}", "t0");
    Observable<Message> msgObservable = Observable.from(messages);
    when(queue.observe()).thenReturn(msgObservable);
    when(queue.getURI()).thenReturn(queueURI);
    when(queue.getName()).thenReturn(queueURI);
    when(queue.getType()).thenReturn("sqs");
    when(provider.getQueue(queueURI)).thenReturn(queue);
    Map<String, EventQueueProvider> providers = new HashMap<>();
    providers.put("sqs", provider);
    eventQueues = new EventQueues(providers, parametersUtils);
}
Also used : Message(com.netflix.conductor.core.events.queue.Message) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ObservableQueue(com.netflix.conductor.core.events.queue.ObservableQueue) ExecutionService(com.netflix.conductor.service.ExecutionService) MetadataService(com.netflix.conductor.service.MetadataService) JsonUtils(com.netflix.conductor.core.utils.JsonUtils) WorkflowExecutor(com.netflix.conductor.core.execution.WorkflowExecutor) ParametersUtils(com.netflix.conductor.core.execution.ParametersUtils) Before(org.junit.Before)

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