Search in sources :

Example 61 with ApplicationException

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());
}
Also used : GetResponse(org.elasticsearch.action.get.GetResponse) SortBuilders(org.elasticsearch.search.sort.SortBuilders) SearchHits(org.elasticsearch.search.SearchHits) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) Task(com.netflix.conductor.common.metadata.tasks.Task) QueryBuilders(org.elasticsearch.index.query.QueryBuilders) StringUtils(org.apache.commons.lang3.StringUtils) WorkflowSummary(com.netflix.conductor.common.run.WorkflowSummary) PreDestroy(javax.annotation.PreDestroy) DeleteRequest(org.elasticsearch.action.delete.DeleteRequest) IndexRequest(org.elasticsearch.action.index.IndexRequest) Settings(org.elasticsearch.common.settings.Settings) TypeFactory(com.fasterxml.jackson.databind.type.TypeFactory) UpdateResponse(org.elasticsearch.action.update.UpdateResponse) Workflow(com.netflix.conductor.common.run.Workflow) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) Map(java.util.Map) SearchResponse(org.elasticsearch.action.search.SearchResponse) EventExecution(com.netflix.conductor.common.metadata.events.EventExecution) DeleteResponse(org.elasticsearch.action.delete.DeleteResponse) MapType(com.fasterxml.jackson.databind.type.MapType) SearchHit(org.elasticsearch.search.SearchHit) Message(com.netflix.conductor.core.events.queue.Message) SearchResult(com.netflix.conductor.common.run.SearchResult) GetRequest(org.elasticsearch.action.get.GetRequest) Trace(com.netflix.conductor.annotations.Trace) TaskExecLog(com.netflix.conductor.common.metadata.tasks.TaskExecLog) TimeZone(java.util.TimeZone) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) Instant(java.time.Instant) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) List(java.util.List) LocalDate(java.time.LocalDate) SortOrder(org.elasticsearch.search.sort.SortOrder) ParserException(com.netflix.conductor.elasticsearch.query.parser.ParserException) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) BulkRequestBuilder(org.elasticsearch.action.bulk.BulkRequestBuilder) FetchSourceContext(org.elasticsearch.search.fetch.subphase.FetchSourceContext) IntStream(java.util.stream.IntStream) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) XContentType(org.elasticsearch.common.xcontent.XContentType) GetMappingsResponse(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Singleton(javax.inject.Singleton) ArrayList(java.util.ArrayList) ResourceAlreadyExistsException(org.elasticsearch.ResourceAlreadyExistsException) Strings(org.elasticsearch.common.Strings) Inject(javax.inject.Inject) CreateIndexRequest(org.elasticsearch.action.admin.indices.create.CreateIndexRequest) LinkedList(java.util.LinkedList) ExecutorService(java.util.concurrent.ExecutorService) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) Logger(org.slf4j.Logger) RetryUtil(com.netflix.conductor.common.utils.RetryUtil) TaskSummary(com.netflix.conductor.common.run.TaskSummary) Client(org.elasticsearch.client.Client) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DateTime(org.joda.time.DateTime) IOException(java.io.IOException) UpdateRequest(org.elasticsearch.action.update.UpdateRequest) DocWriteResponse(org.elasticsearch.action.DocWriteResponse) Monitors(com.netflix.conductor.metrics.Monitors) TimeUnit(java.util.concurrent.TimeUnit) GetIndexTemplatesResponse(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse) IndexDAO(com.netflix.conductor.dao.IndexDAO) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) ElasticSearchConfiguration(com.netflix.conductor.elasticsearch.ElasticSearchConfiguration) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) UpdateRequest(org.elasticsearch.action.update.UpdateRequest) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 62 with ApplicationException

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

Example 63 with ApplicationException

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

Example 64 with ApplicationException

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

Example 65 with ApplicationException

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

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