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());
}
}
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();
}
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);
}
}
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);
}
}
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);
}
}
Aggregations