use of com.netflix.conductor.core.execution.ApplicationException in project conductor by Netflix.
the class ElasticSearchDAOV6 method updateWorkflow.
@Override
public void updateWorkflow(String workflowInstanceId, String[] keys, Object[] values) {
if (keys.length != values.length) {
throw new ApplicationException(ApplicationException.Code.INVALID_INPUT, "Number of keys and values do not match");
}
long startTime = Instant.now().toEpochMilli();
UpdateRequest request = new UpdateRequest(workflowIndexName, WORKFLOW_DOC_TYPE, workflowInstanceId);
Map<String, Object> source = IntStream.range(0, keys.length).boxed().collect(Collectors.toMap(i -> keys[i], i -> values[i]));
request.doc(source);
LOGGER.debug("Updating workflow {} in elasticsearch index: {}", workflowInstanceId, workflowIndexName);
new RetryUtil<>().retryOnException(() -> elasticSearchClient.update(request).actionGet(), null, null, RETRY_COUNT, "Updating index for doc_type workflow", "updateWorkflow");
long endTime = Instant.now().toEpochMilli();
LOGGER.debug("Time taken {} for updating workflow: {}", endTime - startTime, workflowInstanceId);
Monitors.recordESIndexTime("update_workflow", WORKFLOW_DOC_TYPE, endTime - startTime);
Monitors.recordWorkerQueueSize("indexQueue", ((ThreadPoolExecutor) executorService).getQueue().size());
}
use of com.netflix.conductor.core.execution.ApplicationException in project conductor by Netflix.
the class WorkflowServiceImpl method startWorkflow.
@Override
public void startWorkflow(StartWorkflowRequestPb.StartWorkflowRequest pbRequest, StreamObserver<WorkflowServicePb.StartWorkflowResponse> response) {
// TODO: better handling of optional 'version'
final StartWorkflowRequest request = PROTO_MAPPER.fromProto(pbRequest);
try {
String id = workflowService.startWorkflow(pbRequest.getName(), GRPC_HELPER.optional(request.getVersion()), request.getCorrelationId(), request.getPriority(), request.getInput(), request.getExternalInputPayloadStoragePath(), request.getTaskToDomain(), request.getWorkflowDef());
response.onNext(WorkflowServicePb.StartWorkflowResponse.newBuilder().setWorkflowId(id).build());
response.onCompleted();
} catch (ApplicationException ae) {
if (ae.getCode().equals(ApplicationException.Code.NOT_FOUND)) {
response.onError(Status.NOT_FOUND.withDescription("No such workflow found by name=" + request.getName()).asRuntimeException());
} else {
GRPC_HELPER.onError(response, ae);
}
}
}
use of com.netflix.conductor.core.execution.ApplicationException in project conductor by Netflix.
the class GenericExceptionMapper method toResponse.
@Override
public Response toResponse(Throwable exception) {
LOGGER.error(String.format("Error %s url: '%s'", exception.getClass().getSimpleName(), uriInfo.getPath()), exception);
Monitors.error("error", "error");
ApplicationException applicationException = null;
if (exception instanceof IllegalArgumentException || exception instanceof InvalidFormatException) {
applicationException = new ApplicationException(Code.INVALID_INPUT, exception.getMessage(), exception);
} else {
applicationException = new ApplicationException(Code.INTERNAL_ERROR, exception.getMessage(), exception);
}
Map<String, Object> entityMap = applicationException.toMap();
entityMap.put("instance", host);
return Response.status(applicationException.getHttpStatusCode()).entity(entityMap).type(MediaType.APPLICATION_JSON_TYPE).build();
}
use of com.netflix.conductor.core.execution.ApplicationException in project conductor by Netflix.
the class Query method executeQuery.
/**
* Execute a query from the PreparedStatement and return the ResultSet.
* <p>
*
* <em>NOTE:</em> The returned ResultSet must be closed/managed by the calling methods.
*
* @return {@link PreparedStatement#executeQuery()}
*
* @throws ApplicationException If any SQL errors occur.
*/
public ResultSet executeQuery() {
Long start = null;
if (logger.isTraceEnabled()) {
start = System.currentTimeMillis();
}
try {
return this.statement.executeQuery();
} catch (SQLException ex) {
throw new ApplicationException(Code.BACKEND_ERROR, ex);
} finally {
if (null != start && logger.isTraceEnabled()) {
long end = System.currentTimeMillis();
logger.trace("[{}ms] {}", (end - start), rawQuery);
}
}
}
use of com.netflix.conductor.core.execution.ApplicationException in project conductor by Netflix.
the class Query method executeUpdate.
/**
* @return The result of {@link PreparedStatement#executeUpdate()}
*/
public int executeUpdate() {
try {
Long start = null;
if (logger.isTraceEnabled()) {
start = System.currentTimeMillis();
}
final int val = this.statement.executeUpdate();
if (null != start && logger.isTraceEnabled()) {
long end = System.currentTimeMillis();
logger.trace("[{}ms] {}: {}", (end - start), val, rawQuery);
}
return val;
} catch (SQLException ex) {
throw new ApplicationException(Code.BACKEND_ERROR, ex.getMessage(), ex);
}
}
Aggregations