Search in sources :

Example 6 with ApplicationException

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

the class CassandraExecutionDAO method updateWorkflow.

@Override
public String updateWorkflow(Workflow workflow) {
    try {
        List<Task> tasks = workflow.getTasks();
        workflow.setTasks(new LinkedList<>());
        String payload = toJson(workflow);
        recordCassandraDaoRequests("updateWorkflow", "n/a", workflow.getWorkflowName());
        recordCassandraDaoPayloadSize("updateWorkflow", payload.length(), "n/a", workflow.getWorkflowName());
        session.execute(updateWorkflowStatement.bind(payload, UUID.fromString(workflow.getWorkflowId())));
        workflow.setTasks(tasks);
        return workflow.getWorkflowId();
    } catch (Exception e) {
        Monitors.error(CLASS_NAME, "updateWorkflow");
        String errorMsg = String.format("Failed to update workflow: %s", workflow.getWorkflowId());
        LOGGER.error(errorMsg, e);
        throw new ApplicationException(Code.BACKEND_ERROR, errorMsg);
    }
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) ApplicationException(com.netflix.conductor.core.execution.ApplicationException)

Example 7 with ApplicationException

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

the class CassandraExecutionDAO method updateEventExecution.

@Override
public void updateEventExecution(EventExecution eventExecution) {
    try {
        String jsonPayload = toJson(eventExecution);
        recordCassandraDaoEventRequests("updateEventExecution", eventExecution.getEvent());
        recordCassandraDaoPayloadSize("updateEventExecution", jsonPayload.length(), eventExecution.getEvent(), "n/a");
        session.execute(updateEventExecutionStatement.bind(eventExecutionsTTL, jsonPayload, eventExecution.getMessageId(), eventExecution.getName(), eventExecution.getId()));
    } catch (Exception e) {
        Monitors.error(CLASS_NAME, "updateEventExecution");
        String errorMsg = String.format("Failed to update 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)

Example 8 with ApplicationException

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

the class CassandraExecutionDAO method getTask.

@Override
public Task getTask(String taskId) {
    try {
        String workflowId = lookupWorkflowIdFromTaskId(taskId);
        if (workflowId == null) {
            return null;
        }
        // TODO: implement for query against multiple shards
        ResultSet resultSet = session.execute(selectTaskStatement.bind(UUID.fromString(workflowId), DEFAULT_SHARD_ID, taskId));
        return Optional.ofNullable(resultSet.one()).map(row -> {
            Task task = readValue(row.getString(PAYLOAD_KEY), Task.class);
            recordCassandraDaoRequests("getTask", task.getTaskType(), task.getWorkflowType());
            recordCassandraDaoPayloadSize("getTask", toJson(task).length(), task.getTaskType(), task.getWorkflowType());
            return task;
        }).orElse(null);
    } catch (ApplicationException ae) {
        throw ae;
    } catch (Exception e) {
        Monitors.error(CLASS_NAME, "getTask");
        String errorMsg = String.format("Error getting task by id: %s", taskId);
        LOGGER.error(errorMsg, e);
        throw new ApplicationException(Code.BACKEND_ERROR, errorMsg);
    }
}
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) Task(com.netflix.conductor.common.metadata.tasks.Task) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) ResultSet(com.datastax.driver.core.ResultSet) ApplicationException(com.netflix.conductor.core.execution.ApplicationException)

Example 9 with ApplicationException

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

the class CassandraExecutionDAO method createWorkflow.

@Override
public String createWorkflow(Workflow workflow) {
    try {
        List<Task> tasks = workflow.getTasks();
        workflow.setTasks(new LinkedList<>());
        String payload = toJson(workflow);
        recordCassandraDaoRequests("createWorkflow", "n/a", workflow.getWorkflowName());
        recordCassandraDaoPayloadSize("createWorkflow", payload.length(), "n/a", workflow.getWorkflowName());
        session.execute(insertWorkflowStatement.bind(UUID.fromString(workflow.getWorkflowId()), 1, "", payload, 0, 1));
        workflow.setTasks(tasks);
        return workflow.getWorkflowId();
    } catch (Exception e) {
        Monitors.error(CLASS_NAME, "createWorkflow");
        String errorMsg = String.format("Error creating workflow: %s", workflow.getWorkflowId());
        LOGGER.error(errorMsg, e);
        throw new ApplicationException(Code.BACKEND_ERROR, errorMsg, e);
    }
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) ApplicationException(com.netflix.conductor.core.execution.ApplicationException)

Example 10 with ApplicationException

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

the class CassandraExecutionDAO method removeTask.

private boolean removeTask(Task task) {
    // TODO: calculate shard number based on seq and maxTasksPerShard
    try {
        // get total tasks for this workflow
        WorkflowMetadata workflowMetadata = getWorkflowMetadata(task.getWorkflowInstanceId());
        int totalTasks = workflowMetadata.getTotalTasks();
        // remove from task_lookup table
        removeTaskLookup(task);
        recordCassandraDaoRequests("removeTask", task.getTaskType(), task.getWorkflowType());
        // delete task from workflows table and decrement total tasks by 1
        BatchStatement batchStatement = new BatchStatement();
        batchStatement.add(deleteTaskStatement.bind(UUID.fromString(task.getWorkflowInstanceId()), DEFAULT_SHARD_ID, task.getTaskId()));
        batchStatement.add(updateTotalTasksStatement.bind(totalTasks - 1, UUID.fromString(task.getWorkflowInstanceId()), DEFAULT_SHARD_ID));
        ResultSet resultSet = session.execute(batchStatement);
        if (task.getTaskDefinition().isPresent() && task.getTaskDefinition().get().concurrencyLimit() > 0) {
            updateTaskDefLimit(task, true);
        }
        return resultSet.wasApplied();
    } catch (Exception e) {
        Monitors.error(CLASS_NAME, "removeTask");
        String errorMsg = String.format("Failed to remove task: %s", task.getTaskId());
        LOGGER.error(errorMsg, e);
        throw new ApplicationException(Code.BACKEND_ERROR, errorMsg);
    }
}
Also used : ApplicationException(com.netflix.conductor.core.execution.ApplicationException) BatchStatement(com.datastax.driver.core.BatchStatement) ResultSet(com.datastax.driver.core.ResultSet) 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