Search in sources :

Example 21 with EventHandler

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

the class MySQLMetadataDAO 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 22 with EventHandler

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

the class EventResourceTest method testGetEventHandlers.

@Test
public void testGetEventHandlers() {
    EventHandler eventHandler = new EventHandler();
    eventResource.addEventHandler(eventHandler);
    List<EventHandler> listOfEventHandler = new ArrayList<>();
    listOfEventHandler.add(eventHandler);
    when(mockEventService.getEventHandlers()).thenReturn(listOfEventHandler);
    assertEquals(listOfEventHandler, eventResource.getEventHandlers());
}
Also used : ArrayList(java.util.ArrayList) EventHandler(com.netflix.conductor.common.metadata.events.EventHandler) Test(org.junit.Test)

Example 23 with EventHandler

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

the class PostgresMetadataDAOTest method testEventHandlers.

@Test
public void testEventHandlers() {
    String event1 = "SQS::arn:account090:sqstest1";
    String event2 = "SQS::arn:account090:sqstest2";
    EventHandler eh = new EventHandler();
    eh.setName(UUID.randomUUID().toString());
    eh.setActive(false);
    EventHandler.Action action = new EventHandler.Action();
    action.setAction(EventHandler.Action.Type.start_workflow);
    action.setStart_workflow(new EventHandler.StartWorkflow());
    action.getStart_workflow().setName("workflow_x");
    eh.getActions().add(action);
    eh.setEvent(event1);
    dao.addEventHandler(eh);
    List<EventHandler> all = dao.getAllEventHandlers();
    assertNotNull(all);
    assertEquals(1, all.size());
    assertEquals(eh.getName(), all.get(0).getName());
    assertEquals(eh.getEvent(), all.get(0).getEvent());
    List<EventHandler> byEvents = dao.getEventHandlersForEvent(event1, true);
    assertNotNull(byEvents);
    // event is marked as in-active
    assertEquals(0, byEvents.size());
    eh.setActive(true);
    eh.setEvent(event2);
    dao.updateEventHandler(eh);
    all = dao.getAllEventHandlers();
    assertNotNull(all);
    assertEquals(1, all.size());
    byEvents = dao.getEventHandlersForEvent(event1, true);
    assertNotNull(byEvents);
    assertEquals(0, byEvents.size());
    byEvents = dao.getEventHandlersForEvent(event2, true);
    assertNotNull(byEvents);
    assertEquals(1, byEvents.size());
}
Also used : EventHandler(com.netflix.conductor.common.metadata.events.EventHandler) Test(org.junit.Test)

Example 24 with EventHandler

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

the class RedisEventHandlerDAO method removeEventHandler.

@Override
public void removeEventHandler(String name) {
    EventHandler existing = getEventHandler(name);
    if (existing == null) {
        throw new ApplicationException(Code.NOT_FOUND, "EventHandler with name " + name + " not found!");
    }
    dynoClient.hdel(nsKey(EVENT_HANDLERS), name);
    recordRedisDaoRequests("removeEventHandler");
    removeIndex(existing);
}
Also used : ApplicationException(com.netflix.conductor.core.execution.ApplicationException) EventHandler(com.netflix.conductor.common.metadata.events.EventHandler)

Example 25 with EventHandler

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

the class CassandraEventHandlerDAO method getAllEventHandlersFromDB.

@SuppressWarnings("unchecked")
private List<EventHandler> getAllEventHandlersFromDB() {
    try {
        ResultSet resultSet = session.execute(selectAllEventHandlersStatement.bind(HANDLERS_KEY));
        List<Row> rows = resultSet.all();
        if (rows.size() == 0) {
            LOGGER.info("No event handlers were found.");
            return Collections.EMPTY_LIST;
        }
        return rows.stream().map(row -> readValue(row.getString(EVENT_HANDLER_KEY), EventHandler.class)).collect(Collectors.toList());
    } catch (Exception e) {
        Monitors.error(CLASS_NAME, "getAllEventHandlersFromDB");
        String errorMsg = "Failed to get all event handlers";
        LOGGER.error(errorMsg, e);
        throw new ApplicationException(Code.BACKEND_ERROR, errorMsg, e);
    }
}
Also used : Row(com.datastax.driver.core.Row) LoggerFactory(org.slf4j.LoggerFactory) EVENT_HANDLER_KEY(com.netflix.conductor.util.Constants.EVENT_HANDLER_KEY) HashMap(java.util.HashMap) Singleton(javax.inject.Singleton) ArrayList(java.util.ArrayList) PreparedStatement(com.datastax.driver.core.PreparedStatement) Inject(javax.inject.Inject) CassandraConfiguration(com.netflix.conductor.cassandra.CassandraConfiguration) ResultSet(com.datastax.driver.core.ResultSet) Session(com.datastax.driver.core.Session) Map(java.util.Map) Code(com.netflix.conductor.core.execution.ApplicationException.Code) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) Logger(org.slf4j.Logger) Trace(com.netflix.conductor.annotations.Trace) EventHandlerDAO(com.netflix.conductor.dao.EventHandlerDAO) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) EventHandler(com.netflix.conductor.common.metadata.events.EventHandler) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) Monitors(com.netflix.conductor.metrics.Monitors) TimeUnit(java.util.concurrent.TimeUnit) HANDLERS_KEY(com.netflix.conductor.util.Constants.HANDLERS_KEY) List(java.util.List) Statements(com.netflix.conductor.util.Statements) Collections(java.util.Collections) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) ResultSet(com.datastax.driver.core.ResultSet) Row(com.datastax.driver.core.Row) ApplicationException(com.netflix.conductor.core.execution.ApplicationException)

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