Search in sources :

Example 36 with ApplicationException

use of com.netflix.conductor.core.execution.ApplicationException in project conductor by Netflix.

the class MySQLMetadataDAO 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 37 with ApplicationException

use of com.netflix.conductor.core.execution.ApplicationException in project conductor by Netflix.

the class Query method executeQuery.

/**
 * Execute a query from the PreparedStatement and return the ResultSet.
 * <p>
 *
 * <em>NOTE:</em> The returned ResultSet must be closed/managed by the calling methods.
 *
 * @return {@link PreparedStatement#executeQuery()}
 *
 * @throws ApplicationException If any SQL errors occur.
 */
public ResultSet executeQuery() {
    Long start = null;
    if (logger.isTraceEnabled()) {
        start = System.currentTimeMillis();
    }
    try {
        return this.statement.executeQuery();
    } catch (SQLException ex) {
        throw new ApplicationException(Code.BACKEND_ERROR, ex);
    } finally {
        if (null != start && logger.isTraceEnabled()) {
            long end = System.currentTimeMillis();
            logger.trace("[{}ms] {}", (end - start), rawQuery);
        }
    }
}
Also used : ApplicationException(com.netflix.conductor.core.execution.ApplicationException) SQLException(java.sql.SQLException)

Example 38 with ApplicationException

use of com.netflix.conductor.core.execution.ApplicationException in project conductor by Netflix.

the class PostgresExecutionDAO method getAllPollData.

@Override
public List<PollData> getAllPollData() {
    try (Connection tx = dataSource.getConnection()) {
        boolean previousAutoCommitMode = tx.getAutoCommit();
        tx.setAutoCommit(true);
        try {
            String GET_ALL_POLL_DATA = "SELECT json_data FROM poll_data ORDER BY queue_name";
            return query(tx, GET_ALL_POLL_DATA, q -> q.executeAndFetch(PollData.class));
        } catch (Throwable th) {
            throw new ApplicationException(BACKEND_ERROR, th.getMessage(), th);
        } finally {
            tx.setAutoCommit(previousAutoCommitMode);
        }
    } catch (SQLException ex) {
        throw new ApplicationException(BACKEND_ERROR, ex.getMessage(), ex);
    }
}
Also used : ApplicationException(com.netflix.conductor.core.execution.ApplicationException) SQLException(java.sql.SQLException) PollData(com.netflix.conductor.common.metadata.tasks.PollData) Connection(java.sql.Connection)

Example 39 with ApplicationException

use of com.netflix.conductor.core.execution.ApplicationException 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 40 with ApplicationException

use of com.netflix.conductor.core.execution.ApplicationException 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)

Aggregations

ApplicationException (com.netflix.conductor.core.execution.ApplicationException)93 Task (com.netflix.conductor.common.metadata.tasks.Task)22 Workflow (com.netflix.conductor.common.run.Workflow)22 HashMap (java.util.HashMap)19 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)16 IOException (java.io.IOException)16 Map (java.util.Map)15 ArrayList (java.util.ArrayList)14 List (java.util.List)14 Inject (javax.inject.Inject)14 Singleton (javax.inject.Singleton)14 Logger (org.slf4j.Logger)14 LoggerFactory (org.slf4j.LoggerFactory)14 Trace (com.netflix.conductor.annotations.Trace)13 EventExecution (com.netflix.conductor.common.metadata.events.EventExecution)13 Monitors (com.netflix.conductor.metrics.Monitors)13 Collectors (java.util.stream.Collectors)13 ResultSet (com.datastax.driver.core.ResultSet)12 EventHandler (com.netflix.conductor.common.metadata.events.EventHandler)12 TimeUnit (java.util.concurrent.TimeUnit)12