Search in sources :

Example 1 with ApplicationException

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

the class MetadataServiceImpl method getWorkflow.

@Override
public void getWorkflow(MetadataServicePb.GetWorkflowRequest req, StreamObserver<MetadataServicePb.GetWorkflowResponse> response) {
    try {
        WorkflowDef workflowDef = service.getWorkflowDef(req.getName(), GRPC_HELPER.optional(req.getVersion()));
        WorkflowDefPb.WorkflowDef workflow = PROTO_MAPPER.toProto(workflowDef);
        response.onNext(MetadataServicePb.GetWorkflowResponse.newBuilder().setWorkflow(workflow).build());
        response.onCompleted();
    } catch (ApplicationException e) {
        // TODO replace this with gRPC exception interceptor.
        response.onError(Status.NOT_FOUND.withDescription("No such workflow found by name=" + req.getName()).asRuntimeException());
    }
}
Also used : ApplicationException(com.netflix.conductor.core.execution.ApplicationException) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) WorkflowDefPb(com.netflix.conductor.proto.WorkflowDefPb)

Example 2 with ApplicationException

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

the class CassandraEventHandlerDAO method removeEventHandler.

@Override
public void removeEventHandler(String name) {
    try {
        recordCassandraDaoRequests("removeEventHandler");
        session.execute(deleteEventHandlerStatement.bind(name));
    } catch (Exception e) {
        Monitors.error(CLASS_NAME, "removeEventHandler");
        String errorMsg = String.format("Failed to remove event handler: %s", name);
        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 3 with ApplicationException

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

the class CassandraExecutionDAO method getWorkflow.

@Override
public Workflow getWorkflow(String workflowId, boolean includeTasks) {
    Workflow workflow = null;
    try {
        ResultSet resultSet;
        if (includeTasks) {
            resultSet = session.execute(selectWorkflowWithTasksStatement.bind(UUID.fromString(workflowId), DEFAULT_SHARD_ID));
            List<Task> tasks = new ArrayList<>();
            List<Row> rows = resultSet.all();
            if (rows.size() == 0) {
                LOGGER.info("Workflow {} not found in datastore", workflowId);
                return null;
            }
            for (Row row : rows) {
                String entityKey = row.getString(ENTITY_KEY);
                if (ENTITY_TYPE_WORKFLOW.equals(entityKey)) {
                    workflow = readValue(row.getString(PAYLOAD_KEY), Workflow.class);
                } else if (ENTITY_TYPE_TASK.equals(entityKey)) {
                    Task task = readValue(row.getString(PAYLOAD_KEY), Task.class);
                    tasks.add(task);
                } else {
                    throw new ApplicationException(ApplicationException.Code.INTERNAL_ERROR, String.format("Invalid row with entityKey: %s found in datastore for workflow: %s", entityKey, workflowId));
                }
            }
            if (workflow != null) {
                recordCassandraDaoRequests("getWorkflow", "n/a", workflow.getWorkflowName());
                tasks.sort(Comparator.comparingInt(Task::getSeq));
                workflow.setTasks(tasks);
            }
        } else {
            resultSet = session.execute(selectWorkflowStatement.bind(UUID.fromString(workflowId)));
            workflow = Optional.ofNullable(resultSet.one()).map(row -> {
                Workflow wf = readValue(row.getString(PAYLOAD_KEY), Workflow.class);
                recordCassandraDaoRequests("getWorkflow", "n/a", wf.getWorkflowName());
                return wf;
            }).orElse(null);
        }
        return workflow;
    } catch (ApplicationException e) {
        throw e;
    } catch (IllegalArgumentException e) {
        Monitors.error(CLASS_NAME, "getWorkflow");
        String errorMsg = String.format("Invalid workflow id: %s", workflowId);
        LOGGER.error(errorMsg, e);
        throw new ApplicationException(Code.INVALID_INPUT, errorMsg, e);
    } catch (Exception e) {
        Monitors.error(CLASS_NAME, "getWorkflow");
        String errorMsg = String.format("Failed to get workflow: %s", workflowId);
        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) ResultSet(com.datastax.driver.core.ResultSet) ArrayList(java.util.ArrayList) Workflow(com.netflix.conductor.common.run.Workflow) Row(com.datastax.driver.core.Row) ApplicationException(com.netflix.conductor.core.execution.ApplicationException)

Example 4 with ApplicationException

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

the class CassandraExecutionDAO method removeTaskLookup.

private void removeTaskLookup(Task task) {
    try {
        recordCassandraDaoRequests("removeTaskLookup", task.getTaskType(), task.getWorkflowType());
        if (task.getTaskDefinition().isPresent() && task.getTaskDefinition().get().concurrencyLimit() > 0) {
            updateTaskDefLimit(task, true);
        }
        session.execute(deleteTaskLookupStatement.bind(UUID.fromString(task.getTaskId())));
    } catch (ApplicationException ae) {
    // no-op
    } catch (Exception e) {
        Monitors.error(CLASS_NAME, "removeTaskLookup");
        String errorMsg = String.format("Failed to remove task lookup: %s", task.getTaskId());
        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 5 with ApplicationException

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

the class CassandraExecutionDAO method createTasks.

/**
 * Inserts tasks into the Cassandra datastore.
 * <b>Note:</b>
 * Creates the task_id to workflow_id mapping in the task_lookup table first.
 * Once this succeeds, inserts the tasks into the workflows table. Tasks belonging to the same shard are created using batch statements.
 *
 * @param tasks tasks to be created
 */
@Override
public List<Task> createTasks(List<Task> tasks) {
    validateTasks(tasks);
    String workflowId = tasks.get(0).getWorkflowInstanceId();
    try {
        WorkflowMetadata workflowMetadata = getWorkflowMetadata(workflowId);
        int totalTasks = workflowMetadata.getTotalTasks() + tasks.size();
        // TODO: write into multiple shards based on number of tasks
        // update the task_lookup table
        tasks.forEach(task -> {
            task.setScheduledTime(System.currentTimeMillis());
            session.execute(updateTaskLookupStatement.bind(UUID.fromString(workflowId), UUID.fromString(task.getTaskId())));
        });
        // update all the tasks in the workflow using batch
        BatchStatement batchStatement = new BatchStatement();
        tasks.forEach(task -> {
            String taskPayload = toJson(task);
            batchStatement.add(insertTaskStatement.bind(UUID.fromString(workflowId), DEFAULT_SHARD_ID, task.getTaskId(), taskPayload));
            recordCassandraDaoRequests("createTask", task.getTaskType(), task.getWorkflowType());
            recordCassandraDaoPayloadSize("createTask", taskPayload.length(), task.getTaskType(), task.getWorkflowType());
        });
        batchStatement.add(updateTotalTasksStatement.bind(totalTasks, UUID.fromString(workflowId), DEFAULT_SHARD_ID));
        session.execute(batchStatement);
        // update the total tasks and partitions for the workflow
        session.execute(updateTotalPartitionsStatement.bind(DEFAULT_TOTAL_PARTITIONS, totalTasks, UUID.fromString(workflowId)));
        return tasks;
    } catch (ApplicationException e) {
        throw e;
    } catch (Exception e) {
        Monitors.error(CLASS_NAME, "createTasks");
        String errorMsg = String.format("Error creating %d tasks for workflow: %s", tasks.size(), workflowId);
        LOGGER.error(errorMsg, e);
        throw new ApplicationException(Code.BACKEND_ERROR, errorMsg, e);
    }
}
Also used : ApplicationException(com.netflix.conductor.core.execution.ApplicationException) BatchStatement(com.datastax.driver.core.BatchStatement) 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