Search in sources :

Example 26 with EventExecution

use of com.netflix.conductor.common.metadata.events.EventExecution in project conductor by Netflix.

the class CassandraDAOTest method testEventExecutionCRUD.

@Test
public void testEventExecutionCRUD() throws Exception {
    String event = "test-event";
    String executionId1 = "id_1";
    String messageId1 = "message1";
    String eventHandler1 = "test_eh_1";
    EventExecution eventExecution1 = getEventExecution(executionId1, messageId1, eventHandler1, event);
    // create event execution explicitly in test
    // since, embedded Cassandra server does not support LWT required for this API.
    addEventExecution(eventExecution1);
    // fetch executions
    List<EventExecution> eventExecutionList = executionDAO.getEventExecutions(eventHandler1, event, messageId1);
    assertNotNull(eventExecutionList);
    assertEquals(1, eventExecutionList.size());
    assertEquals(eventExecution1, eventExecutionList.get(0));
    // add a different execution for same message
    String executionId2 = "id_2";
    EventExecution eventExecution2 = getEventExecution(executionId2, messageId1, eventHandler1, event);
    addEventExecution(eventExecution2);
    // fetch executions
    eventExecutionList = executionDAO.getEventExecutions(eventHandler1, event, messageId1);
    assertNotNull(eventExecutionList);
    assertEquals(2, eventExecutionList.size());
    assertEquals(eventExecution1, eventExecutionList.get(0));
    assertEquals(eventExecution2, eventExecutionList.get(1));
    // update the second execution
    eventExecution2.setStatus(COMPLETED);
    executionDAO.updateEventExecution(eventExecution2);
    // fetch executions
    eventExecutionList = executionDAO.getEventExecutions(eventHandler1, event, messageId1);
    assertNotNull(eventExecutionList);
    assertEquals(2, eventExecutionList.size());
    assertEquals(COMPLETED, eventExecutionList.get(1).getStatus());
    // sleep for 5 seconds (TTL)
    Thread.sleep(5000L);
    eventExecutionList = executionDAO.getEventExecutions(eventHandler1, event, messageId1);
    assertNotNull(eventExecutionList);
    assertEquals(1, eventExecutionList.size());
    // delete event execution
    executionDAO.removeEventExecution(eventExecution1);
    eventExecutionList = executionDAO.getEventExecutions(eventHandler1, event, messageId1);
    assertNotNull(eventExecutionList);
    assertEquals(0, eventExecutionList.size());
}
Also used : EventExecution(com.netflix.conductor.common.metadata.events.EventExecution) Test(org.junit.Test)

Example 27 with EventExecution

use of com.netflix.conductor.common.metadata.events.EventExecution in project conductor by Netflix.

the class CassandraDAOTest method getEventExecution.

private EventExecution getEventExecution(String id, String msgId, String name, String event) {
    EventExecution eventExecution = new EventExecution(id, msgId);
    eventExecution.setName(name);
    eventExecution.setEvent(event);
    eventExecution.setStatus(EventExecution.Status.IN_PROGRESS);
    return eventExecution;
}
Also used : EventExecution(com.netflix.conductor.common.metadata.events.EventExecution)

Example 28 with EventExecution

use of com.netflix.conductor.common.metadata.events.EventExecution in project conductor by Netflix.

the class SimpleEventProcessor method executeActionsForEventHandler.

/**
 * @param eventHandler the {@link EventHandler} for which the actions are to be executed
 * @param msg          the {@link Message} that triggered the event
 * @return a {@link CompletableFuture} holding a list of {@link EventExecution}s for the {@link Action}s executed in the event handler
 */
protected CompletableFuture<List<EventExecution>> executeActionsForEventHandler(EventHandler eventHandler, Message msg) {
    List<CompletableFuture<EventExecution>> futuresList = new ArrayList<>();
    int i = 0;
    for (Action action : eventHandler.getActions()) {
        String id = msg.getId() + "_" + i++;
        EventExecution eventExecution = new EventExecution(id, msg.getId());
        eventExecution.setCreated(System.currentTimeMillis());
        eventExecution.setEvent(eventHandler.getEvent());
        eventExecution.setName(eventHandler.getName());
        eventExecution.setAction(action.getAction());
        eventExecution.setStatus(Status.IN_PROGRESS);
        if (executionService.addEventExecution(eventExecution)) {
            futuresList.add(CompletableFuture.supplyAsync(() -> execute(eventExecution, action, getPayloadObject(msg.getPayload())), executorService));
        } else {
            logger.warn("Duplicate delivery/execution of message: {}", msg.getId());
        }
    }
    return CompletableFutures.allAsList(futuresList);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) Action(com.netflix.conductor.common.metadata.events.EventHandler.Action) EventExecution(com.netflix.conductor.common.metadata.events.EventExecution) ArrayList(java.util.ArrayList)

Aggregations

EventExecution (com.netflix.conductor.common.metadata.events.EventExecution)28 Test (org.junit.Test)13 ApplicationException (com.netflix.conductor.core.execution.ApplicationException)7 ArrayList (java.util.ArrayList)7 SearchHit (org.elasticsearch.search.SearchHit)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 Action (com.netflix.conductor.common.metadata.events.EventHandler.Action)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 EventHandler (com.netflix.conductor.common.metadata.events.EventHandler)4 Message (com.netflix.conductor.core.events.queue.Message)4 ObservableQueue (com.netflix.conductor.core.events.queue.ObservableQueue)4 JsonUtils (com.netflix.conductor.core.utils.JsonUtils)4 ExecutionService (com.netflix.conductor.service.ExecutionService)4 MetadataService (com.netflix.conductor.service.MetadataService)4 Collections (java.util.Collections)4 TimeUnit (java.util.concurrent.TimeUnit)4 Uninterruptibles (com.google.common.util.concurrent.Uninterruptibles)3 Type (com.netflix.conductor.common.metadata.events.EventHandler.Action.Type)3 StartWorkflow (com.netflix.conductor.common.metadata.events.EventHandler.StartWorkflow)3