Search in sources :

Example 11 with EventHandler

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

the class PostgresMetadataDAO method updateEventHandler.

@Override
public void updateEventHandler(EventHandler eventHandler) {
    Preconditions.checkNotNull(eventHandler.getName(), "EventHandler name cannot be null");
    // @formatter:off
    final String UPDATE_EVENT_HANDLER_QUERY = "UPDATE meta_event_handler SET " + "event = ?, active = ?, json_data = ?, " + "modified_on = CURRENT_TIMESTAMP WHERE name = ?";
    // @formatter:on
    withTransaction(tx -> {
        EventHandler existing = getEventHandler(tx, eventHandler.getName());
        if (existing == null) {
            throw new ApplicationException(ApplicationException.Code.NOT_FOUND, "EventHandler with name " + eventHandler.getName() + " not found!");
        }
        execute(tx, UPDATE_EVENT_HANDLER_QUERY, q -> q.addParameter(eventHandler.getEvent()).addParameter(eventHandler.isActive()).addJsonParameter(eventHandler).addParameter(eventHandler.getName()).executeUpdate());
    });
}
Also used : ApplicationException(com.netflix.conductor.core.execution.ApplicationException) EventHandler(com.netflix.conductor.common.metadata.events.EventHandler)

Example 12 with EventHandler

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

the class PostgresMetadataDAO method removeEventHandler.

@Override
public void removeEventHandler(String name) {
    final String DELETE_EVENT_HANDLER_QUERY = "DELETE FROM meta_event_handler WHERE name = ?";
    withTransaction(tx -> {
        EventHandler existing = getEventHandler(tx, name);
        if (existing == null) {
            throw new ApplicationException(ApplicationException.Code.NOT_FOUND, "EventHandler with name " + name + " not found!");
        }
        execute(tx, DELETE_EVENT_HANDLER_QUERY, q -> q.addParameter(name).executeDelete());
    });
}
Also used : ApplicationException(com.netflix.conductor.core.execution.ApplicationException) EventHandler(com.netflix.conductor.common.metadata.events.EventHandler)

Example 13 with EventHandler

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

the class RedisEventHandlerDAO method getEventHandlersForEvent.

@Override
public List<EventHandler> getEventHandlersForEvent(String event, boolean activeOnly) {
    String key = nsKey(EVENT_HANDLERS_BY_EVENT, event);
    Set<String> names = dynoClient.smembers(key);
    List<EventHandler> handlers = new LinkedList<>();
    for (String name : names) {
        try {
            EventHandler eventHandler = getEventHandler(name);
            recordRedisDaoEventRequests("getEventHandler", event);
            if (eventHandler.getEvent().equals(event) && (!activeOnly || eventHandler.isActive())) {
                handlers.add(eventHandler);
            }
        } catch (ApplicationException ae) {
            if (ae.getCode() == Code.NOT_FOUND) {
                LOGGER.info("No matching event handler found for event: {}", event);
            }
            throw ae;
        }
    }
    return handlers;
}
Also used : ApplicationException(com.netflix.conductor.core.execution.ApplicationException) EventHandler(com.netflix.conductor.common.metadata.events.EventHandler) LinkedList(java.util.LinkedList)

Example 14 with EventHandler

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

the class RedisEventHandlerDAO method updateEventHandler.

@Override
public void updateEventHandler(EventHandler eventHandler) {
    Preconditions.checkNotNull(eventHandler.getName(), "Missing Name");
    EventHandler existing = getEventHandler(eventHandler.getName());
    if (existing == null) {
        throw new ApplicationException(Code.NOT_FOUND, "EventHandler with name " + eventHandler.getName() + " not found!");
    }
    index(eventHandler);
    dynoClient.hset(nsKey(EVENT_HANDLERS), eventHandler.getName(), toJson(eventHandler));
    recordRedisDaoRequests("updateEventHandler");
}
Also used : ApplicationException(com.netflix.conductor.core.execution.ApplicationException) EventHandler(com.netflix.conductor.common.metadata.events.EventHandler)

Example 15 with EventHandler

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

the class RedisEventHandlerDAO method getAllEventHandlers.

@Override
public List<EventHandler> getAllEventHandlers() {
    Map<String, String> all = dynoClient.hgetAll(nsKey(EVENT_HANDLERS));
    List<EventHandler> handlers = new LinkedList<>();
    all.forEach((key, json) -> {
        EventHandler eventHandler = readValue(json, EventHandler.class);
        handlers.add(eventHandler);
    });
    recordRedisDaoRequests("getAllEventHandlers");
    return handlers;
}
Also used : EventHandler(com.netflix.conductor.common.metadata.events.EventHandler) LinkedList(java.util.LinkedList)

Aggregations

EventHandler (com.netflix.conductor.common.metadata.events.EventHandler)26 Test (org.junit.Test)14 ApplicationException (com.netflix.conductor.core.execution.ApplicationException)13 Action (com.netflix.conductor.common.metadata.events.EventHandler.Action)6 ArrayList (java.util.ArrayList)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 TaskDetails (com.netflix.conductor.common.metadata.events.EventHandler.TaskDetails)4 TestConfiguration (com.netflix.conductor.core.execution.TestConfiguration)4 Collections (java.util.Collections)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 TimeUnit (java.util.concurrent.TimeUnit)4 EventExecution (com.netflix.conductor.common.metadata.events.EventExecution)3 StartWorkflow (com.netflix.conductor.common.metadata.events.EventHandler.StartWorkflow)3 Message (com.netflix.conductor.core.events.queue.Message)3 ObservableQueue (com.netflix.conductor.core.events.queue.ObservableQueue)3 JsonUtils (com.netflix.conductor.core.utils.JsonUtils)3 ExecutionService (com.netflix.conductor.service.ExecutionService)3 MetadataService (com.netflix.conductor.service.MetadataService)3 LinkedList (java.util.LinkedList)3