Search in sources :

Example 6 with EventExecution

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

the class TestElasticSearchRestDAOV5 method addEventExecution.

@Test
public void addEventExecution() {
    String messageId = "some-message-id";
    EventExecution eventExecution = new EventExecution();
    eventExecution.setId("some-id");
    eventExecution.setMessageId(messageId);
    eventExecution.setAction(Type.complete_task);
    eventExecution.setEvent("some-event");
    eventExecution.setStatus(EventExecution.Status.COMPLETED);
    indexDAO.addEventExecution(eventExecution);
    await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> {
        SearchResponse searchResponse = searchObjectIdsViaExpression(LOG_INDEX_PREFIX + "*", "messageId='" + messageId + "'", 0, 10000, null, "*", EVENT_DOC_TYPE);
        assertTrue("should return 1 or more search results", searchResponse.getHits().getTotalHits() > 0);
        SearchHit searchHit = searchResponse.getHits().getAt(0);
        String resourcePath = String.format("/%s/%s/%s", searchHit.getIndex(), EVENT_DOC_TYPE, searchHit.getId());
        Response response = restClient.performRequest(HttpMethod.GET, resourcePath);
        String responseBody = IOUtils.toString(response.getEntity().getContent());
        TypeReference<HashMap<String, Object>> typeRef = new TypeReference<HashMap<String, Object>>() {
        };
        Map<String, Object> responseMap = objectMapper.readValue(responseBody, typeRef);
        Map<String, Object> sourceMap = (Map<String, Object>) responseMap.get("_source");
        assertEquals("indexed id should match", "some-id", sourceMap.get("id"));
        assertEquals("indexed message id should match", messageId, sourceMap.get("messageId"));
        assertEquals("indexed action should match", Type.complete_task.name(), sourceMap.get("action"));
        assertEquals("indexed event should match", "some-event", sourceMap.get("event"));
        assertEquals("indexed status should match", EventExecution.Status.COMPLETED.name(), sourceMap.get("status"));
    });
    List<EventExecution> events = indexDAO.getEventExecutions("some-event");
    assertEquals(1, events.size());
    assertEquals(eventExecution, events.get(0));
}
Also used : SearchResponse(org.elasticsearch.action.search.SearchResponse) Response(org.elasticsearch.client.Response) SearchHit(org.elasticsearch.search.SearchHit) HashMap(java.util.HashMap) EventExecution(com.netflix.conductor.common.metadata.events.EventExecution) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Map(java.util.Map) HashMap(java.util.HashMap) SearchResponse(org.elasticsearch.action.search.SearchResponse) Test(org.junit.Test)

Example 7 with EventExecution

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

the class SimpleEventProcessor method executeEvent.

/**
 * Executes all the actions configured on all the event handlers triggered by the {@link Message} on the queue
 * If any of the actions on an event handler fails due to a transient failure, the execution is not persisted such that it can be retried
 *
 * @return a list of {@link EventExecution} that failed due to transient failures.
 */
protected List<EventExecution> executeEvent(String event, Message msg) throws Exception {
    List<EventHandler> eventHandlerList = metadataService.getEventHandlersForEvent(event, true);
    Object payloadObject = getPayloadObject(msg.getPayload());
    List<EventExecution> transientFailures = new ArrayList<>();
    for (EventHandler eventHandler : eventHandlerList) {
        String condition = eventHandler.getCondition();
        if (StringUtils.isNotEmpty(condition)) {
            logger.debug("Checking condition: {} for event: {}", condition, event);
            Boolean success = ScriptEvaluator.evalBool(condition, jsonUtils.expand(payloadObject));
            if (!success) {
                String id = msg.getId() + "_" + 0;
                EventExecution eventExecution = new EventExecution(id, msg.getId());
                eventExecution.setCreated(System.currentTimeMillis());
                eventExecution.setEvent(eventHandler.getEvent());
                eventExecution.setName(eventHandler.getName());
                eventExecution.setStatus(Status.SKIPPED);
                eventExecution.getOutput().put("msg", msg.getPayload());
                eventExecution.getOutput().put("condition", condition);
                executionService.addEventExecution(eventExecution);
                logger.debug("Condition: {} not successful for event: {} with payload: {}", condition, eventHandler.getEvent(), msg.getPayload());
                continue;
            }
        }
        CompletableFuture<List<EventExecution>> future = executeActionsForEventHandler(eventHandler, msg);
        future.whenComplete((result, error) -> result.forEach(eventExecution -> {
            if (error != null || eventExecution.getStatus() == Status.IN_PROGRESS) {
                transientFailures.add(eventExecution);
            } else {
                executionService.updateEventExecution(eventExecution);
            }
        })).get();
    }
    return processTransientFailures(transientFailures);
}
Also used : MetadataService(com.netflix.conductor.service.MetadataService) Action(com.netflix.conductor.common.metadata.events.EventHandler.Action) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) JsonUtils(com.netflix.conductor.core.utils.JsonUtils) Inject(javax.inject.Inject) Map(java.util.Map) Status(com.netflix.conductor.common.metadata.events.EventExecution.Status) EventExecution(com.netflix.conductor.common.metadata.events.EventExecution) LinkedList(java.util.LinkedList) ExecutorService(java.util.concurrent.ExecutorService) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) CompletableFutures(com.spotify.futures.CompletableFutures) Message(com.netflix.conductor.core.events.queue.Message) Logger(org.slf4j.Logger) RetryUtil(com.netflix.conductor.common.utils.RetryUtil) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) EventHandler(com.netflix.conductor.common.metadata.events.EventHandler) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) Monitors(com.netflix.conductor.metrics.Monitors) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ExecutionService(com.netflix.conductor.service.ExecutionService) Configuration(com.netflix.conductor.core.config.Configuration) ObservableQueue(com.netflix.conductor.core.events.queue.ObservableQueue) Collections(java.util.Collections) EventExecution(com.netflix.conductor.common.metadata.events.EventExecution) ArrayList(java.util.ArrayList) EventHandler(com.netflix.conductor.common.metadata.events.EventHandler) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List)

Example 8 with EventExecution

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

the class TestElasticSearchDAOV6 method shouldAddEventExecution.

@Test
public void shouldAddEventExecution() {
    String event = "event";
    EventExecution execution1 = createEventExecution(event);
    EventExecution execution2 = createEventExecution(event);
    indexDAO.addEventExecution(execution1);
    indexDAO.addEventExecution(execution2);
    List<EventExecution> indexedExecutions = tryFindResults(() -> indexDAO.getEventExecutions(event), 2);
    assertEquals(2, indexedExecutions.size());
    assertTrue("Not all event executions was indexed", indexedExecutions.containsAll(Arrays.asList(execution1, execution2)));
}
Also used : EventExecution(com.netflix.conductor.common.metadata.events.EventExecution) Test(org.junit.Test)

Example 9 with EventExecution

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

the class TestElasticSearchDAOV6 method shouldAsyncAddEventExecution.

@Test
public void shouldAsyncAddEventExecution() throws Exception {
    String event = "event2";
    EventExecution execution1 = createEventExecution(event);
    EventExecution execution2 = createEventExecution(event);
    indexDAO.asyncAddEventExecution(execution1).get();
    indexDAO.asyncAddEventExecution(execution2).get();
    List<EventExecution> indexedExecutions = tryFindResults(() -> indexDAO.getEventExecutions(event), 2);
    assertEquals(2, indexedExecutions.size());
    assertTrue("Not all event executions was indexed", indexedExecutions.containsAll(Arrays.asList(execution1, execution2)));
}
Also used : EventExecution(com.netflix.conductor.common.metadata.events.EventExecution) Test(org.junit.Test)

Example 10 with EventExecution

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

the class ElasticSearchDAOV5 method mapEventExecutionsResponse.

private List<EventExecution> mapEventExecutionsResponse(SearchResponse response) throws IOException {
    SearchHit[] hits = response.getHits().getHits();
    List<EventExecution> executions = new ArrayList<>(hits.length);
    for (SearchHit hit : hits) {
        String source = hit.getSourceAsString();
        EventExecution tel = objectMapper.readValue(source, EventExecution.class);
        executions.add(tel);
    }
    return executions;
}
Also used : SearchHit(org.elasticsearch.search.SearchHit) 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