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