Search in sources :

Example 1 with ObservableQueue

use of com.netflix.conductor.core.events.queue.ObservableQueue in project conductor by Netflix.

the class ContribsModule method getQueues.

@Provides
public Map<Status, ObservableQueue> getQueues(Configuration config, AWSCredentialsProvider acp) {
    String stack = "";
    if (config.getStack() != null && config.getStack().length() > 0) {
        stack = config.getStack() + "_";
    }
    Status[] statuses = new Status[] { Status.COMPLETED, Status.FAILED };
    Map<Status, ObservableQueue> queues = new HashMap<>();
    for (Status status : statuses) {
        String queueName = config.getProperty("workflow.listener.queue.prefix", config.getAppId() + "_sqs_notify_" + stack + status.name());
        AmazonSQSClient client = new AmazonSQSClient(acp);
        Builder builder = new SQSObservableQueue.Builder().withClient(client).withQueueName(queueName);
        String auth = config.getProperty("workflow.listener.queue.authorizedAccounts", "");
        String[] accounts = auth.split(",");
        for (String accountToAuthorize : accounts) {
            accountToAuthorize = accountToAuthorize.trim();
            if (accountToAuthorize.length() > 0) {
                builder.addAccountToAuthorize(accountToAuthorize.trim());
            }
        }
        ObservableQueue queue = builder.build();
        queues.put(status, queue);
    }
    return queues;
}
Also used : Status(com.netflix.conductor.common.metadata.tasks.Task.Status) HashMap(java.util.HashMap) SQSObservableQueue(com.netflix.conductor.contribs.queue.sqs.SQSObservableQueue) ObservableQueue(com.netflix.conductor.core.events.queue.ObservableQueue) Builder(com.netflix.conductor.contribs.queue.sqs.SQSObservableQueue.Builder) AmazonSQSClient(com.amazonaws.services.sqs.AmazonSQSClient) Provides(com.google.inject.Provides)

Example 2 with ObservableQueue

use of com.netflix.conductor.core.events.queue.ObservableQueue in project conductor by Netflix.

the class TestEvent method testSinkParam.

@Test
public void testSinkParam() {
    String sink = "sqs:queue_name";
    WorkflowDef def = new WorkflowDef();
    def.setName("wf0");
    Workflow workflow = new Workflow();
    workflow.setWorkflowDefinition(def);
    Task task1 = new Task();
    task1.setReferenceTaskName("t1");
    task1.getOutputData().put("q", "t1_queue");
    workflow.getTasks().add(task1);
    Task task2 = new Task();
    task2.setReferenceTaskName("t2");
    task2.getOutputData().put("q", "task2_queue");
    workflow.getTasks().add(task2);
    Task task = new Task();
    task.setReferenceTaskName("event");
    task.getInputData().put("sink", sink);
    task.setTaskType(TaskType.EVENT.name());
    workflow.getTasks().add(task);
    Event event = new Event(eventQueues, parametersUtils, objectMapper);
    ObservableQueue queue = event.getQueue(workflow, task);
    assertNotNull(task.getReasonForIncompletion(), queue);
    assertEquals("queue_name", queue.getName());
    assertEquals("sqs", queue.getType());
    sink = "sqs:${t1.output.q}";
    task.getInputData().put("sink", sink);
    queue = event.getQueue(workflow, task);
    assertNotNull(queue);
    assertEquals("t1_queue", queue.getName());
    assertEquals("sqs", queue.getType());
    System.out.println(task.getOutputData().get("event_produced"));
    sink = "sqs:${t2.output.q}";
    task.getInputData().put("sink", sink);
    queue = event.getQueue(workflow, task);
    assertNotNull(queue);
    assertEquals("task2_queue", queue.getName());
    assertEquals("sqs", queue.getType());
    System.out.println(task.getOutputData().get("event_produced"));
    sink = "conductor";
    task.getInputData().put("sink", sink);
    queue = event.getQueue(workflow, task);
    assertNotNull(queue);
    assertEquals(workflow.getWorkflowName() + ":" + task.getReferenceTaskName(), queue.getName());
    assertEquals("conductor", queue.getType());
    System.out.println(task.getOutputData().get("event_produced"));
    sink = "sqs:static_value";
    task.getInputData().put("sink", sink);
    queue = event.getQueue(workflow, task);
    assertNotNull(queue);
    assertEquals("static_value", queue.getName());
    assertEquals("sqs", queue.getType());
    assertEquals(sink, task.getOutputData().get("event_produced"));
    System.out.println(task.getOutputData().get("event_produced"));
    sink = "bad:queue";
    task.getInputData().put("sink", sink);
    queue = event.getQueue(workflow, task);
    assertNull(queue);
    assertEquals(Task.Status.FAILED, task.getStatus());
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) ObservableQueue(com.netflix.conductor.core.events.queue.ObservableQueue) Workflow(com.netflix.conductor.common.run.Workflow) Test(org.junit.Test)

Example 3 with ObservableQueue

use of com.netflix.conductor.core.events.queue.ObservableQueue in project conductor by Netflix.

the class TestEvent method testDynamicSinks.

@Test
public void testDynamicSinks() {
    Event event = new Event(eventQueues, parametersUtils, objectMapper);
    Workflow workflow = new Workflow();
    workflow.setWorkflowDefinition(testWorkflowDefinition);
    Task task = new Task();
    task.setReferenceTaskName("task0");
    task.setTaskId("task_id_0");
    task.setStatus(Status.IN_PROGRESS);
    task.getInputData().put("sink", "conductor:some_arbitary_queue");
    ObservableQueue queue = event.getQueue(workflow, task);
    assertEquals(Task.Status.IN_PROGRESS, task.getStatus());
    assertNotNull(queue);
    assertEquals("testWorkflow:some_arbitary_queue", queue.getName());
    assertEquals("testWorkflow:some_arbitary_queue", queue.getURI());
    assertEquals("conductor", queue.getType());
    assertEquals("conductor:testWorkflow:some_arbitary_queue", task.getOutputData().get("event_produced"));
    task.getInputData().put("sink", "conductor");
    queue = event.getQueue(workflow, task);
    assertEquals("not in progress: " + task.getReasonForIncompletion(), Task.Status.IN_PROGRESS, task.getStatus());
    assertNotNull(queue);
    assertEquals("testWorkflow:task0", queue.getName());
    task.getInputData().put("sink", "sqs:my_sqs_queue_name");
    queue = event.getQueue(workflow, task);
    assertEquals("not in progress: " + task.getReasonForIncompletion(), Task.Status.IN_PROGRESS, task.getStatus());
    assertNotNull(queue);
    assertEquals("my_sqs_queue_name", queue.getName());
    assertEquals("sqs", queue.getType());
    task.getInputData().put("sink", "sns:my_sqs_queue_name");
    queue = event.getQueue(workflow, task);
    assertEquals(Task.Status.FAILED, task.getStatus());
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) ObservableQueue(com.netflix.conductor.core.events.queue.ObservableQueue) Workflow(com.netflix.conductor.common.run.Workflow) Test(org.junit.Test)

Example 4 with ObservableQueue

use of com.netflix.conductor.core.events.queue.ObservableQueue in project conductor by Netflix.

the class AMQPEventQueueProviderTest method testAMQPEventQueueProvider_defaultconfig_queue.

@Test
public void testAMQPEventQueueProvider_defaultconfig_queue() {
    String exchangestring = "amqp_queue:myQueueName?deliveryMode=2&durable=false&autoDelete=true&exclusive=true";
    Mockito.when(config.getProperty(Mockito.anyString(), Mockito.anyString())).thenAnswer(invocation -> invocation.getArgument(1));
    Mockito.when(config.getBooleanProperty(Mockito.anyString(), Mockito.anyBoolean())).thenAnswer(invocation -> invocation.getArgument(1));
    Mockito.when(config.getIntProperty(Mockito.anyString(), Mockito.anyInt())).thenAnswer(invocation -> invocation.getArgument(1));
    AMQPEventQueueProvider eventqProvider = new AMQPEventQueueProvider(config, false);
    ObservableQueue queue = eventqProvider.getQueue(exchangestring);
    Assert.assertNotNull(queue);
    Assert.assertEquals(exchangestring, queue.getName());
    Assert.assertEquals(AMQPConstants.AMQP_QUEUE_TYPE, queue.getType());
}
Also used : ObservableQueue(com.netflix.conductor.core.events.queue.ObservableQueue) Test(org.junit.Test)

Example 5 with ObservableQueue

use of com.netflix.conductor.core.events.queue.ObservableQueue in project conductor by Netflix.

the class TestQueueManager method testFailure.

@Test(expected = IllegalArgumentException.class)
public void testFailure() throws Exception {
    Map<Status, ObservableQueue> queues = new HashMap<>();
    queues.put(Status.COMPLETED, queue);
    QueueManager qm = new QueueManager(queues, es, objectMapper);
    qm.updateByTaskRefName("v_1", "t1", new HashMap<>(), Status.CANCELED);
    Uninterruptibles.sleepUninterruptibly(1_000, TimeUnit.MILLISECONDS);
}
Also used : Status(com.netflix.conductor.common.metadata.tasks.Task.Status) HashMap(java.util.HashMap) ObservableQueue(com.netflix.conductor.core.events.queue.ObservableQueue) QueueManager(com.netflix.conductor.contribs.queue.QueueManager) Test(org.junit.Test)

Aggregations

ObservableQueue (com.netflix.conductor.core.events.queue.ObservableQueue)14 HashMap (java.util.HashMap)10 Test (org.junit.Test)7 Task (com.netflix.conductor.common.metadata.tasks.Task)6 Status (com.netflix.conductor.common.metadata.tasks.Task.Status)6 Workflow (com.netflix.conductor.common.run.Workflow)5 Message (com.netflix.conductor.core.events.queue.Message)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 QueueManager (com.netflix.conductor.contribs.queue.QueueManager)3 Wait (com.netflix.conductor.core.execution.tasks.Wait)3 ExecutionService (com.netflix.conductor.service.ExecutionService)3 List (java.util.List)3 Map (java.util.Map)3 Uninterruptibles (com.google.common.util.concurrent.Uninterruptibles)2 Provides (com.google.inject.Provides)2 JsonMapperProvider (com.netflix.conductor.common.utils.JsonMapperProvider)2 ApplicationException (com.netflix.conductor.core.execution.ApplicationException)2 LinkedList (java.util.LinkedList)2 TimeUnit (java.util.concurrent.TimeUnit)2 Assert.assertNotNull (org.junit.Assert.assertNotNull)2