Search in sources :

Example 76 with ApplicationException

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

the class CassandraEventHandlerDAO method insertOrUpdateEventHandler.

private void insertOrUpdateEventHandler(EventHandler eventHandler) {
    try {
        String handler = toJson(eventHandler);
        session.execute(insertEventHandlerStatement.bind(eventHandler.getName(), handler));
        recordCassandraDaoRequests("storeEventHandler");
        recordCassandraDaoPayloadSize("storeEventHandler", handler.length(), "n/a", "n/a");
    } catch (Exception e) {
        Monitors.error(CLASS_NAME, "insertOrUpdateEventHandler");
        String errorMsg = String.format("Error creating/updating event handler: %s/%s", eventHandler.getName(), eventHandler.getEvent());
        LOGGER.error(errorMsg, e);
        throw new ApplicationException(Code.BACKEND_ERROR, errorMsg, e);
    }
    refreshEventHandlersCache();
}
Also used : ApplicationException(com.netflix.conductor.core.execution.ApplicationException) ApplicationException(com.netflix.conductor.core.execution.ApplicationException)

Example 77 with ApplicationException

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

Example 78 with ApplicationException

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

the class CassandraExecutionDAO method getWorkflowMetadata.

@VisibleForTesting
WorkflowMetadata getWorkflowMetadata(String workflowId) {
    ResultSet resultSet = session.execute(selectTotalStatement.bind(UUID.fromString(workflowId)));
    recordCassandraDaoRequests("getWorkflowMetadata");
    return Optional.ofNullable(resultSet.one()).map(row -> {
        WorkflowMetadata workflowMetadata = new WorkflowMetadata();
        workflowMetadata.setTotalTasks(row.getInt(TOTAL_TASKS_KEY));
        workflowMetadata.setTotalPartitions(row.getInt(TOTAL_PARTITIONS_KEY));
        return workflowMetadata;
    }).orElseThrow(() -> new ApplicationException(Code.NOT_FOUND, String.format("Workflow with id: %s not found in data store", workflowId)));
}
Also used : DEFAULT_TOTAL_PARTITIONS(com.netflix.conductor.util.Constants.DEFAULT_TOTAL_PARTITIONS) Row(com.datastax.driver.core.Row) WORKFLOW_ID_KEY(com.netflix.conductor.util.Constants.WORKFLOW_ID_KEY) LoggerFactory(org.slf4j.LoggerFactory) ExecutionDAO(com.netflix.conductor.dao.ExecutionDAO) Task(com.netflix.conductor.common.metadata.tasks.Task) Singleton(javax.inject.Singleton) ArrayList(java.util.ArrayList) PreparedStatement(com.datastax.driver.core.PreparedStatement) Inject(javax.inject.Inject) ENTITY_KEY(com.netflix.conductor.util.Constants.ENTITY_KEY) CassandraConfiguration(com.netflix.conductor.cassandra.CassandraConfiguration) DEFAULT_SHARD_ID(com.netflix.conductor.util.Constants.DEFAULT_SHARD_ID) ResultSet(com.datastax.driver.core.ResultSet) TOTAL_PARTITIONS_KEY(com.netflix.conductor.util.Constants.TOTAL_PARTITIONS_KEY) Workflow(com.netflix.conductor.common.run.Workflow) IN_PROGRESS(com.netflix.conductor.common.metadata.tasks.Task.Status.IN_PROGRESS) Session(com.datastax.driver.core.Session) PollDataDAO(com.netflix.conductor.dao.PollDataDAO) PollData(com.netflix.conductor.common.metadata.tasks.PollData) EventExecution(com.netflix.conductor.common.metadata.events.EventExecution) LinkedList(java.util.LinkedList) BatchStatement(com.datastax.driver.core.BatchStatement) Code(com.netflix.conductor.core.execution.ApplicationException.Code) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) Logger(org.slf4j.Logger) Trace(com.netflix.conductor.annotations.Trace) RetryUtil(com.netflix.conductor.common.utils.RetryUtil) TASK_ID_KEY(com.netflix.conductor.util.Constants.TASK_ID_KEY) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) PAYLOAD_KEY(com.netflix.conductor.util.Constants.PAYLOAD_KEY) Monitors(com.netflix.conductor.metrics.Monitors) TOTAL_TASKS_KEY(com.netflix.conductor.util.Constants.TOTAL_TASKS_KEY) List(java.util.List) ENTITY_TYPE_WORKFLOW(com.netflix.conductor.util.Constants.ENTITY_TYPE_WORKFLOW) Statements(com.netflix.conductor.util.Statements) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ENTITY_TYPE_TASK(com.netflix.conductor.util.Constants.ENTITY_TYPE_TASK) Comparator(java.util.Comparator) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) ResultSet(com.datastax.driver.core.ResultSet) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 79 with ApplicationException

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

the class CassandraExecutionDAO method exceedsInProgressLimit.

/**
 * This is a dummy implementation and this feature is not implemented
 * for Cassandra backed Conductor
 */
@Override
public boolean exceedsInProgressLimit(Task task) {
    Optional<TaskDef> taskDefinition = task.getTaskDefinition();
    if (!taskDefinition.isPresent()) {
        return false;
    }
    int limit = taskDefinition.get().concurrencyLimit();
    if (limit <= 0) {
        return false;
    }
    try {
        recordCassandraDaoRequests("selectTaskDefLimit", task.getTaskType(), task.getWorkflowType());
        ResultSet resultSet = session.execute(selectTasksFromTaskDefLimitStatement.bind(task.getTaskDefName()));
        List<String> taskIds = resultSet.all().stream().map(row -> row.getUUID(TASK_ID_KEY).toString()).collect(Collectors.toList());
        long current = taskIds.size();
        if (!taskIds.contains(task.getTaskId()) && current >= limit) {
            LOGGER.info("Task execution count limited. task - {}:{}, limit: {}, current: {}", task.getTaskId(), task.getTaskDefName(), limit, current);
            Monitors.recordTaskConcurrentExecutionLimited(task.getTaskDefName(), limit);
            return true;
        }
    } catch (Exception e) {
        Monitors.error(CLASS_NAME, "exceedsInProgressLimit");
        String errorMsg = String.format("Failed to get in progress limit - %s:%s in workflow :%s", task.getTaskDefName(), task.getTaskId(), task.getWorkflowInstanceId());
        LOGGER.error(errorMsg, e);
        throw new ApplicationException(Code.BACKEND_ERROR, errorMsg);
    }
    return false;
}
Also used : DEFAULT_TOTAL_PARTITIONS(com.netflix.conductor.util.Constants.DEFAULT_TOTAL_PARTITIONS) Row(com.datastax.driver.core.Row) WORKFLOW_ID_KEY(com.netflix.conductor.util.Constants.WORKFLOW_ID_KEY) LoggerFactory(org.slf4j.LoggerFactory) ExecutionDAO(com.netflix.conductor.dao.ExecutionDAO) Task(com.netflix.conductor.common.metadata.tasks.Task) Singleton(javax.inject.Singleton) ArrayList(java.util.ArrayList) PreparedStatement(com.datastax.driver.core.PreparedStatement) Inject(javax.inject.Inject) ENTITY_KEY(com.netflix.conductor.util.Constants.ENTITY_KEY) CassandraConfiguration(com.netflix.conductor.cassandra.CassandraConfiguration) DEFAULT_SHARD_ID(com.netflix.conductor.util.Constants.DEFAULT_SHARD_ID) ResultSet(com.datastax.driver.core.ResultSet) TOTAL_PARTITIONS_KEY(com.netflix.conductor.util.Constants.TOTAL_PARTITIONS_KEY) Workflow(com.netflix.conductor.common.run.Workflow) IN_PROGRESS(com.netflix.conductor.common.metadata.tasks.Task.Status.IN_PROGRESS) Session(com.datastax.driver.core.Session) PollDataDAO(com.netflix.conductor.dao.PollDataDAO) PollData(com.netflix.conductor.common.metadata.tasks.PollData) EventExecution(com.netflix.conductor.common.metadata.events.EventExecution) LinkedList(java.util.LinkedList) BatchStatement(com.datastax.driver.core.BatchStatement) Code(com.netflix.conductor.core.execution.ApplicationException.Code) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) Logger(org.slf4j.Logger) Trace(com.netflix.conductor.annotations.Trace) RetryUtil(com.netflix.conductor.common.utils.RetryUtil) TASK_ID_KEY(com.netflix.conductor.util.Constants.TASK_ID_KEY) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) PAYLOAD_KEY(com.netflix.conductor.util.Constants.PAYLOAD_KEY) Monitors(com.netflix.conductor.metrics.Monitors) TOTAL_TASKS_KEY(com.netflix.conductor.util.Constants.TOTAL_TASKS_KEY) List(java.util.List) ENTITY_TYPE_WORKFLOW(com.netflix.conductor.util.Constants.ENTITY_TYPE_WORKFLOW) Statements(com.netflix.conductor.util.Statements) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ENTITY_TYPE_TASK(com.netflix.conductor.util.Constants.ENTITY_TYPE_TASK) Comparator(java.util.Comparator) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) ResultSet(com.datastax.driver.core.ResultSet) ApplicationException(com.netflix.conductor.core.execution.ApplicationException)

Example 80 with ApplicationException

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

the class CassandraExecutionDAO method removeEventExecution.

@Override
public void removeEventExecution(EventExecution eventExecution) {
    try {
        recordCassandraDaoEventRequests("removeEventExecution", eventExecution.getEvent());
        session.execute(deleteEventExecutionStatement.bind(eventExecution.getMessageId(), eventExecution.getName(), eventExecution.getId()));
    } catch (Exception e) {
        Monitors.error(CLASS_NAME, "removeEventExecution");
        String errorMsg = String.format("Failed to remove event execution for event: %s, handler: %s", eventExecution.getEvent(), eventExecution.getName());
        LOGGER.error(errorMsg, e);
        throw new ApplicationException(Code.BACKEND_ERROR, errorMsg);
    }
}
Also used : ApplicationException(com.netflix.conductor.core.execution.ApplicationException) ApplicationException(com.netflix.conductor.core.execution.ApplicationException)

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