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));
}
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);
}
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)));
}
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)));
}
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;
}
Aggregations