use of com.netflix.conductor.core.execution.ApplicationException in project conductor by Netflix.
the class CassandraExecutionDAO method removeWorkflow.
@Override
public boolean removeWorkflow(String workflowId) {
Workflow workflow = getWorkflow(workflowId, true);
boolean removed = false;
// TODO: calculate number of shards and iterate
if (workflow != null) {
try {
recordCassandraDaoRequests("removeWorkflow", "n/a", workflow.getWorkflowName());
ResultSet resultSet = session.execute(deleteWorkflowStatement.bind(UUID.fromString(workflowId), DEFAULT_SHARD_ID));
removed = resultSet.wasApplied();
} catch (Exception e) {
Monitors.error(CLASS_NAME, "removeWorkflow");
String errorMsg = String.format("Failed to remove workflow: %s", workflowId);
LOGGER.error(errorMsg, e);
throw new ApplicationException(Code.BACKEND_ERROR, errorMsg);
}
workflow.getTasks().forEach(this::removeTaskLookup);
}
return removed;
}
use of com.netflix.conductor.core.execution.ApplicationException in project conductor by Netflix.
the class CassandraExecutionDAO method updateTask.
@Override
public void updateTask(Task task) {
try {
// TODO: calculate the shard number the task belongs to
String taskPayload = toJson(task);
recordCassandraDaoRequests("updateTask", task.getTaskType(), task.getWorkflowType());
recordCassandraDaoPayloadSize("updateTask", taskPayload.length(), task.getTaskType(), task.getWorkflowType());
session.execute(insertTaskStatement.bind(UUID.fromString(task.getWorkflowInstanceId()), DEFAULT_SHARD_ID, task.getTaskId(), taskPayload));
if (task.getTaskDefinition().isPresent() && task.getTaskDefinition().get().concurrencyLimit() > 0) {
updateTaskDefLimit(task, false);
}
} catch (Exception e) {
Monitors.error(CLASS_NAME, "updateTask");
String errorMsg = String.format("Error updating task: %s in workflow: %s", task.getTaskId(), task.getWorkflowInstanceId());
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 updateTaskDefLimit.
@VisibleForTesting
void updateTaskDefLimit(Task task, boolean forceRemove) {
try {
if (task.getStatus().isTerminal() || forceRemove) {
recordCassandraDaoRequests("removeTaskDefLimit", task.getTaskType(), task.getWorkflowType());
session.execute(deleteTaskDefLimitStatement.bind(task.getTaskDefName(), UUID.fromString(task.getTaskId())));
new RetryUtil<>().retryOnException(() -> session.execute(deleteTaskDefLimitStatement.bind(task.getTaskDefName(), UUID.fromString(task.getTaskId()))), null, null, 3, "Deleting taskDefLimit", "removeTaskDefLimit");
} else if (task.getStatus().equals(IN_PROGRESS)) {
recordCassandraDaoRequests("addTaskDefLimit", task.getTaskType(), task.getWorkflowType());
new RetryUtil<>().retryOnException(() -> session.execute(updateTaskDefLimitStatement.bind(UUID.fromString(task.getWorkflowInstanceId()), task.getTaskDefName(), UUID.fromString(task.getTaskId()))), null, null, 3, "Adding taskDefLimit", "addTaskDefLimit");
}
} catch (Exception e) {
Monitors.error(CLASS_NAME, "updateTaskDefLimit");
String errorMsg = String.format("Error updating taskDefLimit for task - %s:%s in workflow: %s", task.getTaskDefName(), task.getTaskId(), task.getWorkflowInstanceId());
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 AzureBlobPayloadStorage method download.
/**
* Downloads the payload stored in an azure blob.
*
* @param path the path of the blob
* @return an input stream containing the contents of the object
* Caller is expected to close the input stream.
*/
@Override
public InputStream download(String path) {
try {
BlockBlobClient blockBlobClient = blobContainerClient.getBlobClient(path).getBlockBlobClient();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
// Avoid another call to the api to get the blob size
// ByteArrayOutputStream outputStream = new ByteArrayOutputStream(blockBlobClient.getProperties().value().blobSize());
blockBlobClient.download(outputStream);
return new ByteArrayInputStream(outputStream.toByteArray());
} catch (BlobStorageException | UncheckedIOException | NullPointerException e) {
String msg = "Error communicating with Azure";
logger.error(msg, e);
throw new ApplicationException(ApplicationException.Code.BACKEND_ERROR, msg, e);
}
}
use of com.netflix.conductor.core.execution.ApplicationException in project conductor by Netflix.
the class AzureBlobPayloadStorage method upload.
/**
* Uploads the payload to the given azure blob name.
* It is expected that the caller retrieves the blob name
* using {@link #getLocation(Operation, PayloadType, String)} before making this call.
*
* @param path the name of the blob to be uploaded
* @param payload an {@link InputStream} containing the json payload which is to be uploaded
* @param payloadSize the size of the json payload in bytes
*/
@Override
public void upload(String path, InputStream payload, long payloadSize) {
try {
BlockBlobClient blockBlobClient = blobContainerClient.getBlobClient(path).getBlockBlobClient();
BlobHttpHeaders blobHttpHeaders = new BlobHttpHeaders().setContentType(CONTENT_TYPE);
blockBlobClient.uploadWithResponse(payload, payloadSize, blobHttpHeaders, null, null, null, null, null, Context.NONE);
} catch (BlobStorageException | UncheckedIOException | UnexpectedLengthException e) {
String msg = "Error communicating with Azure";
logger.error(msg, e);
throw new ApplicationException(ApplicationException.Code.BACKEND_ERROR, msg, e);
}
}
Aggregations