Search in sources :

Example 11 with ObservableQueue

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

the class Event method start.

@Override
public void start(Workflow workflow, Task task, WorkflowExecutor provider) {
    Map<String, Object> payload = new HashMap<>(task.getInputData());
    payload.put("workflowInstanceId", workflow.getWorkflowId());
    payload.put("workflowType", workflow.getWorkflowName());
    payload.put("workflowVersion", workflow.getWorkflowVersion());
    payload.put("correlationId", workflow.getCorrelationId());
    String payloadJson;
    try {
        payloadJson = objectMapper.writeValueAsString(payload);
    } catch (JsonProcessingException e) {
        String msg = String.format("Error serializing JSON payload for task: %s, workflow: %s", task.getTaskId(), workflow.getWorkflowId());
        throw new ApplicationException(INTERNAL_ERROR, msg);
    }
    Message message = new Message(task.getTaskId(), payloadJson, task.getTaskId());
    ObservableQueue queue = getQueue(workflow, task);
    if (queue != null) {
        queue.publish(Collections.singletonList(message));
        logger.debug("Published message:{} to queue:{}", message.getId(), queue.getName());
        task.getOutputData().putAll(payload);
        if (isAsyncComplete(task)) {
            task.setStatus(Status.IN_PROGRESS);
        } else {
            task.setStatus(Status.COMPLETED);
        }
    } else {
        task.setReasonForIncompletion("No queue found to publish.");
        task.setStatus(Status.FAILED);
    }
}
Also used : ApplicationException(com.netflix.conductor.core.execution.ApplicationException) Message(com.netflix.conductor.core.events.queue.Message) HashMap(java.util.HashMap) ObservableQueue(com.netflix.conductor.core.events.queue.ObservableQueue) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 12 with ObservableQueue

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

the class AMQPModule method getQueues.

@Provides
public Map<Task.Status, ObservableQueue> getQueues(Configuration config) {
    String stack = "";
    if (config.getStack() != null && config.getStack().length() > 0) {
        stack = config.getStack() + "_";
    }
    final boolean useExchange = config.getBooleanProperty("workflow.listener.queue.useExchange", USE_EXCHANGE_BY_DEFAULT);
    Task.Status[] statuses = new Task.Status[] { Task.Status.COMPLETED, Task.Status.FAILED };
    Map<Task.Status, ObservableQueue> queues = new HashMap<>();
    for (Task.Status status : statuses) {
        String queueName = config.getProperty("workflow.listener.queue.prefix", config.getAppId() + "_amqp_notify_" + stack + status.name());
        final ObservableQueue queue = new AMQPObservableQueue.Builder(config).build(useExchange, queueName);
        queues.put(status, queue);
    }
    return queues;
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) AMQPObservableQueue(com.netflix.conductor.contribs.queue.amqp.AMQPObservableQueue) HashMap(java.util.HashMap) AMQPObservableQueue(com.netflix.conductor.contribs.queue.amqp.AMQPObservableQueue) ObservableQueue(com.netflix.conductor.core.events.queue.ObservableQueue) Provides(com.google.inject.Provides)

Example 13 with ObservableQueue

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

the class QueueManager method update.

private void update(Map<String, Object> externalIdMap, Map<String, Object> output, Status status) throws Exception {
    Map<String, Object> outputMap = new HashMap<>();
    outputMap.put("externalId", objectMapper.writeValueAsString(externalIdMap));
    outputMap.putAll(output);
    Message msg = new Message(UUID.randomUUID().toString(), objectMapper.writeValueAsString(outputMap), null);
    ObservableQueue queue = queues.get(status);
    if (queue == null) {
        throw new IllegalArgumentException("There is no queue for handling " + status.toString() + " status");
    }
    queue.publish(Arrays.asList(msg));
}
Also used : Message(com.netflix.conductor.core.events.queue.Message) HashMap(java.util.HashMap) ObservableQueue(com.netflix.conductor.core.events.queue.ObservableQueue)

Example 14 with ObservableQueue

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

the class AMQPEventQueueProviderTest method testAMQPEventQueueProvider_defaultconfig_exchange.

@Test
public void testAMQPEventQueueProvider_defaultconfig_exchange() {
    String exchangestring = "amqp_exchange:myExchangeName?exchangeType=topic&routingKey=test&deliveryMode=2";
    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, true);
    ObservableQueue queue = eventqProvider.getQueue(exchangestring);
    Assert.assertNotNull(queue);
    Assert.assertEquals(exchangestring, queue.getName());
    Assert.assertEquals(AMQPConstants.AMQP_EXCHANGE_TYPE, queue.getType());
}
Also used : ObservableQueue(com.netflix.conductor.core.events.queue.ObservableQueue) 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