use of com.netflix.conductor.core.execution.ApplicationException in project conductor by Netflix.
the class Event method start.
@Override
public void start(Workflow workflow, Task task, WorkflowExecutor provider) {
Map<String, Object> payload = new HashMap<>(task.getInputData());
payload.put("workflowInstanceId", workflow.getWorkflowId());
payload.put("workflowType", workflow.getWorkflowName());
payload.put("workflowVersion", workflow.getWorkflowVersion());
payload.put("correlationId", workflow.getCorrelationId());
String payloadJson;
try {
payloadJson = objectMapper.writeValueAsString(payload);
} catch (JsonProcessingException e) {
String msg = String.format("Error serializing JSON payload for task: %s, workflow: %s", task.getTaskId(), workflow.getWorkflowId());
throw new ApplicationException(INTERNAL_ERROR, msg);
}
Message message = new Message(task.getTaskId(), payloadJson, task.getTaskId());
ObservableQueue queue = getQueue(workflow, task);
if (queue != null) {
queue.publish(Collections.singletonList(message));
logger.debug("Published message:{} to queue:{}", message.getId(), queue.getName());
task.getOutputData().putAll(payload);
if (isAsyncComplete(task)) {
task.setStatus(Status.IN_PROGRESS);
} else {
task.setStatus(Status.COMPLETED);
}
} else {
task.setReasonForIncompletion("No queue found to publish.");
task.setStatus(Status.FAILED);
}
}
use of com.netflix.conductor.core.execution.ApplicationException in project conductor by Netflix.
the class ExecutionDAOFacade method resetWorkflow.
/**
* Reset the workflow state by removing from the {@link ExecutionDAO} and
* removing this workflow from the {@link IndexDAO}.
*
* @param workflowId the workflow id to be reset
*/
public void resetWorkflow(String workflowId) {
try {
getWorkflowById(workflowId, true);
executionDAO.removeWorkflow(workflowId);
if (config.enableAsyncIndexing()) {
indexDAO.asyncRemoveWorkflow(workflowId);
} else {
indexDAO.removeWorkflow(workflowId);
}
} catch (ApplicationException ae) {
throw ae;
} catch (Exception e) {
throw new ApplicationException(ApplicationException.Code.BACKEND_ERROR, "Error resetting workflow state: " + workflowId, e);
}
}
use of com.netflix.conductor.core.execution.ApplicationException in project conductor by Netflix.
the class ExecutionDAOFacade method removeWorkflow.
/**
* Removes the workflow from the data store.
*
* @param workflowId the id of the workflow to be removed
* @param archiveWorkflow if true, the workflow will be archived in the {@link IndexDAO} after removal from {@link ExecutionDAO}
*/
public void removeWorkflow(String workflowId, boolean archiveWorkflow) {
try {
Workflow workflow = getWorkflowById(workflowId, true);
removeWorkflowIndex(workflow, archiveWorkflow);
// remove workflow from DAO
try {
executionDAO.removeWorkflow(workflowId);
} catch (Exception ex) {
Monitors.recordDaoError("executionDao", "removeWorkflow");
throw ex;
}
} catch (ApplicationException ae) {
throw ae;
} catch (Exception e) {
throw new ApplicationException(ApplicationException.Code.BACKEND_ERROR, "Error removing workflow: " + workflowId, e);
}
}
use of com.netflix.conductor.core.execution.ApplicationException in project conductor by Netflix.
the class ExternalPayloadStorageUtils method verifyAndUpload.
/**
* Verify the payload size and upload to external storage if necessary.
*
* @param entity the task or workflow for which the payload is to be verified and uploaded
* @param payloadType the {@link PayloadType} of the payload
* @param <T> {@link Task} or {@link Workflow}
* @throws ApplicationException in case of JSON parsing errors or upload errors
* @throws TerminateWorkflowException if the payload size is bigger than permissible limit as per {@link Configuration}
*/
public <T> void verifyAndUpload(T entity, PayloadType payloadType) {
long threshold = 0L;
long maxThreshold = 0L;
Map<String, Object> payload = new HashMap<>();
String workflowId = "";
switch(payloadType) {
case TASK_INPUT:
threshold = configuration.getTaskInputPayloadSizeThresholdKB();
maxThreshold = configuration.getMaxTaskInputPayloadSizeThresholdKB();
payload = ((Task) entity).getInputData();
workflowId = ((Task) entity).getWorkflowInstanceId();
break;
case TASK_OUTPUT:
threshold = configuration.getTaskOutputPayloadSizeThresholdKB();
maxThreshold = configuration.getMaxTaskOutputPayloadSizeThresholdKB();
payload = ((Task) entity).getOutputData();
workflowId = ((Task) entity).getWorkflowInstanceId();
break;
case WORKFLOW_INPUT:
threshold = configuration.getWorkflowInputPayloadSizeThresholdKB();
maxThreshold = configuration.getMaxWorkflowInputPayloadSizeThresholdKB();
payload = ((Workflow) entity).getInput();
workflowId = ((Workflow) entity).getWorkflowId();
break;
case WORKFLOW_OUTPUT:
threshold = configuration.getWorkflowOutputPayloadSizeThresholdKB();
maxThreshold = configuration.getMaxWorkflowOutputPayloadSizeThresholdKB();
payload = ((Workflow) entity).getOutput();
workflowId = ((Workflow) entity).getWorkflowId();
break;
}
try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
objectMapper.writeValue(byteArrayOutputStream, payload);
byte[] payloadBytes = byteArrayOutputStream.toByteArray();
long payloadSize = payloadBytes.length;
if (payloadSize > maxThreshold * 1024) {
if (entity instanceof Task) {
String errorMsg = String.format("The payload size: %dB of task: %s in workflow: %s is greater than the permissible limit: %dKB", payloadSize, ((Task) entity).getTaskId(), ((Task) entity).getWorkflowInstanceId(), maxThreshold);
failTask(((Task) entity), payloadType, errorMsg);
} else {
String errorMsg = String.format("The output payload size: %dB of workflow: %s is greater than the permissible limit: %dKB", payloadSize, ((Workflow) entity).getWorkflowId(), maxThreshold);
failWorkflow(errorMsg);
}
} else if (payloadSize > threshold * 1024) {
switch(payloadType) {
case TASK_INPUT:
((Task) entity).setInputData(null);
((Task) entity).setExternalInputPayloadStoragePath(uploadHelper(payloadBytes, payloadSize, PayloadType.TASK_INPUT));
Monitors.recordExternalPayloadStorageUsage(((Task) entity).getTaskDefName(), ExternalPayloadStorage.Operation.WRITE.toString(), PayloadType.TASK_INPUT.toString());
break;
case TASK_OUTPUT:
((Task) entity).setOutputData(null);
((Task) entity).setExternalOutputPayloadStoragePath(uploadHelper(payloadBytes, payloadSize, PayloadType.TASK_OUTPUT));
Monitors.recordExternalPayloadStorageUsage(((Task) entity).getTaskDefName(), ExternalPayloadStorage.Operation.WRITE.toString(), PayloadType.TASK_OUTPUT.toString());
break;
case WORKFLOW_INPUT:
((Workflow) entity).setInput(null);
((Workflow) entity).setExternalInputPayloadStoragePath(uploadHelper(payloadBytes, payloadSize, PayloadType.WORKFLOW_INPUT));
Monitors.recordExternalPayloadStorageUsage(((Workflow) entity).getWorkflowName(), ExternalPayloadStorage.Operation.WRITE.toString(), PayloadType.WORKFLOW_INPUT.toString());
break;
case WORKFLOW_OUTPUT:
((Workflow) entity).setOutput(null);
((Workflow) entity).setExternalOutputPayloadStoragePath(uploadHelper(payloadBytes, payloadSize, PayloadType.WORKFLOW_OUTPUT));
Monitors.recordExternalPayloadStorageUsage(((Workflow) entity).getWorkflowName(), ExternalPayloadStorage.Operation.WRITE.toString(), PayloadType.WORKFLOW_OUTPUT.toString());
break;
}
}
} catch (IOException e) {
logger.error("Unable to upload payload to external storage for workflow: {}", workflowId, e);
throw new ApplicationException(ApplicationException.Code.INTERNAL_ERROR, e);
}
}
use of com.netflix.conductor.core.execution.ApplicationException in project conductor by Netflix.
the class S3PayloadStorage method upload.
/**
* Uploads the payload to the given s3 object key.
* It is expected that the caller retrieves the object key using {@link #getLocation(Operation, PayloadType, String)} before making this call.
*
* @param path the s3 key of the object 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 {
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentType(CONTENT_TYPE);
objectMetadata.setContentLength(payloadSize);
PutObjectRequest request = new PutObjectRequest(bucketName, path, payload, objectMetadata);
s3Client.putObject(request);
} catch (SdkClientException e) {
String msg = "Error communicating with S3";
logger.error(msg, e);
throw new ApplicationException(ApplicationException.Code.BACKEND_ERROR, msg, e);
}
}
Aggregations