Search in sources :

Example 11 with ApplicationException

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

the class CassandraExecutionDAO method addEventExecution.

@Override
public boolean addEventExecution(EventExecution eventExecution) {
    try {
        String jsonPayload = toJson(eventExecution);
        recordCassandraDaoEventRequests("addEventExecution", eventExecution.getEvent());
        recordCassandraDaoPayloadSize("addEventExecution", jsonPayload.length(), eventExecution.getEvent(), "n/a");
        return session.execute(insertEventExecutionStatement.bind(eventExecution.getMessageId(), eventExecution.getName(), eventExecution.getId(), jsonPayload)).wasApplied();
    } catch (Exception e) {
        Monitors.error(CLASS_NAME, "addEventExecution");
        String errorMsg = String.format("Failed to add event execution for event: %s, handler: %s", eventExecution.getEvent(), eventExecution.getName());
        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 12 with ApplicationException

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

the class AzureBlobPayloadStorage method getLocation.

/**
 * @param operation   the type of {@link Operation} to be performed
 * @param payloadType the {@link PayloadType} that is being accessed
 * @return a {@link ExternalStorageLocation} object which contains the pre-signed URL and the azure blob name
 *  for the json payload
 */
@Override
public ExternalStorageLocation getLocation(Operation operation, PayloadType payloadType, String path) {
    try {
        ExternalStorageLocation externalStorageLocation = new ExternalStorageLocation();
        String objectKey;
        if (StringUtils.isNotBlank(path)) {
            objectKey = path;
        } else {
            objectKey = getObjectKey(payloadType);
        }
        externalStorageLocation.setPath(objectKey);
        BlockBlobClient blockBlobClient = blobContainerClient.getBlobClient(objectKey).getBlockBlobClient();
        String blobUrl = Utility.urlDecode(blockBlobClient.getBlobUrl());
        if (sasTokenCredential != null) {
            blobUrl = blobUrl + "?" + sasTokenCredential.getSasToken();
        } else {
            BlobSasPermission blobSASPermission = new BlobSasPermission();
            if (operation.equals(Operation.READ)) {
                blobSASPermission.setReadPermission(true);
            } else if (operation.equals(Operation.WRITE)) {
                blobSASPermission.setWritePermission(true);
                blobSASPermission.setCreatePermission(true);
            }
            BlobServiceSasSignatureValues blobServiceSasSignatureValues = new BlobServiceSasSignatureValues(OffsetDateTime.now(ZoneOffset.UTC).plusSeconds(expirationSec), blobSASPermission);
            blobUrl = blobUrl + "?" + blockBlobClient.generateSas(blobServiceSasSignatureValues);
        }
        externalStorageLocation.setUri(blobUrl);
        return externalStorageLocation;
    } catch (BlobStorageException e) {
        String msg = "Error communicating with Azure";
        logger.error(msg, e);
        throw new ApplicationException(ApplicationException.Code.BACKEND_ERROR, msg, e);
    }
}
Also used : BlobServiceSasSignatureValues(com.azure.storage.blob.sas.BlobServiceSasSignatureValues) BlockBlobClient(com.azure.storage.blob.specialized.BlockBlobClient) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) BlobSasPermission(com.azure.storage.blob.sas.BlobSasPermission) ExternalStorageLocation(com.netflix.conductor.common.run.ExternalStorageLocation) BlobStorageException(com.azure.storage.blob.models.BlobStorageException)

Example 13 with ApplicationException

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

the class CassandraMetadataDAO method getWorkflowDef.

@Override
public Optional<WorkflowDef> getWorkflowDef(String name, int version) {
    try {
        recordCassandraDaoRequests("getWorkflowDef");
        ResultSet resultSet = session.execute(selectWorkflowDefStatement.bind(name, version));
        WorkflowDef workflowDef = Optional.ofNullable(resultSet.one()).map(row -> readValue(row.getString(WORKFLOW_DEFINITION_KEY), WorkflowDef.class)).orElse(null);
        return Optional.ofNullable(workflowDef);
    } catch (Exception e) {
        Monitors.error(CLASS_NAME, "getTaskDef");
        String errorMsg = String.format("Error fetching workflow def: %s/%d", name, version);
        LOGGER.error(errorMsg, e);
        throw new ApplicationException(Code.BACKEND_ERROR, errorMsg, e);
    }
}
Also used : Row(com.datastax.driver.core.Row) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) MetadataDAO(com.netflix.conductor.dao.MetadataDAO) Singleton(javax.inject.Singleton) ArrayList(java.util.ArrayList) PreparedStatement(com.datastax.driver.core.PreparedStatement) Inject(javax.inject.Inject) CassandraConfiguration(com.netflix.conductor.cassandra.CassandraConfiguration) ResultSet(com.datastax.driver.core.ResultSet) Session(com.datastax.driver.core.Session) Map(java.util.Map) Code(com.netflix.conductor.core.execution.ApplicationException.Code) TASK_DEFINITION_KEY(com.netflix.conductor.util.Constants.TASK_DEFINITION_KEY) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) Logger(org.slf4j.Logger) Trace(com.netflix.conductor.annotations.Trace) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) TASK_DEFS_KEY(com.netflix.conductor.util.Constants.TASK_DEFS_KEY) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) Monitors(com.netflix.conductor.metrics.Monitors) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) WORKFLOW_DEF_NAME_VERSION_KEY(com.netflix.conductor.util.Constants.WORKFLOW_DEF_NAME_VERSION_KEY) Statements(com.netflix.conductor.util.Statements) WORKFLOW_DEFINITION_KEY(com.netflix.conductor.util.Constants.WORKFLOW_DEFINITION_KEY) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Comparator(java.util.Comparator) WORKFLOW_DEF_INDEX_KEY(com.netflix.conductor.util.Constants.WORKFLOW_DEF_INDEX_KEY) Collections(java.util.Collections) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) ResultSet(com.datastax.driver.core.ResultSet) ApplicationException(com.netflix.conductor.core.execution.ApplicationException)

Example 14 with ApplicationException

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

the class CassandraMetadataDAO method getTaskDefFromDB.

private TaskDef getTaskDefFromDB(String name) {
    try {
        ResultSet resultSet = session.execute(selectTaskDefStatement.bind(name));
        recordCassandraDaoRequests("getTaskDef");
        return Optional.ofNullable(resultSet.one()).map(row -> readValue(row.getString(TASK_DEFINITION_KEY), TaskDef.class)).orElse(null);
    } catch (Exception e) {
        Monitors.error(CLASS_NAME, "getTaskDef");
        String errorMsg = String.format("Failed to get task def: %s", name);
        LOGGER.error(errorMsg, e);
        throw new ApplicationException(Code.BACKEND_ERROR, errorMsg, e);
    }
}
Also used : Row(com.datastax.driver.core.Row) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) MetadataDAO(com.netflix.conductor.dao.MetadataDAO) Singleton(javax.inject.Singleton) ArrayList(java.util.ArrayList) PreparedStatement(com.datastax.driver.core.PreparedStatement) Inject(javax.inject.Inject) CassandraConfiguration(com.netflix.conductor.cassandra.CassandraConfiguration) ResultSet(com.datastax.driver.core.ResultSet) Session(com.datastax.driver.core.Session) Map(java.util.Map) Code(com.netflix.conductor.core.execution.ApplicationException.Code) TASK_DEFINITION_KEY(com.netflix.conductor.util.Constants.TASK_DEFINITION_KEY) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) Logger(org.slf4j.Logger) Trace(com.netflix.conductor.annotations.Trace) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) TASK_DEFS_KEY(com.netflix.conductor.util.Constants.TASK_DEFS_KEY) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) Monitors(com.netflix.conductor.metrics.Monitors) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) WORKFLOW_DEF_NAME_VERSION_KEY(com.netflix.conductor.util.Constants.WORKFLOW_DEF_NAME_VERSION_KEY) Statements(com.netflix.conductor.util.Statements) WORKFLOW_DEFINITION_KEY(com.netflix.conductor.util.Constants.WORKFLOW_DEFINITION_KEY) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Comparator(java.util.Comparator) WORKFLOW_DEF_INDEX_KEY(com.netflix.conductor.util.Constants.WORKFLOW_DEF_INDEX_KEY) Collections(java.util.Collections) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) ResultSet(com.datastax.driver.core.ResultSet) ApplicationException(com.netflix.conductor.core.execution.ApplicationException)

Example 15 with ApplicationException

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

the class CassandraMetadataDAO method removeWorkflowDef.

@Override
public void removeWorkflowDef(String name, Integer version) {
    try {
        session.execute(deleteWorkflowDefStatement.bind(name, version));
        session.execute(deleteWorkflowDefIndexStatement.bind(WORKFLOW_DEF_INDEX_KEY, getWorkflowDefIndexValue(name, version)));
    } catch (Exception e) {
        Monitors.error(CLASS_NAME, "removeWorkflowDef");
        String errorMsg = String.format("Failed to remove workflow definition: %s/%d", name, version);
        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)

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