Search in sources :

Example 81 with ApplicationException

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;
}
Also used : ApplicationException(com.netflix.conductor.core.execution.ApplicationException) ResultSet(com.datastax.driver.core.ResultSet) Workflow(com.netflix.conductor.common.run.Workflow) ApplicationException(com.netflix.conductor.core.execution.ApplicationException)

Example 82 with ApplicationException

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);
    }
}
Also used : ApplicationException(com.netflix.conductor.core.execution.ApplicationException) ApplicationException(com.netflix.conductor.core.execution.ApplicationException)

Example 83 with ApplicationException

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);
    }
}
Also used : ApplicationException(com.netflix.conductor.core.execution.ApplicationException) RetryUtil(com.netflix.conductor.common.utils.RetryUtil) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 84 with ApplicationException

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);
    }
}
Also used : BlockBlobClient(com.azure.storage.blob.specialized.BlockBlobClient) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) ByteArrayInputStream(java.io.ByteArrayInputStream) UncheckedIOException(java.io.UncheckedIOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BlobStorageException(com.azure.storage.blob.models.BlobStorageException)

Example 85 with ApplicationException

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);
    }
}
Also used : BlobHttpHeaders(com.azure.storage.blob.models.BlobHttpHeaders) BlockBlobClient(com.azure.storage.blob.specialized.BlockBlobClient) UnexpectedLengthException(com.azure.core.exception.UnexpectedLengthException) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) UncheckedIOException(java.io.UncheckedIOException) BlobStorageException(com.azure.storage.blob.models.BlobStorageException)

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