use of com.netflix.conductor.core.execution.ApplicationException in project conductor by Netflix.
the class ElasticSearchRestDAOV5 method searchObjectIdsViaExpression.
private SearchResult<String> searchObjectIdsViaExpression(String structuredQuery, int start, int size, List<String> sortOptions, String freeTextQuery, String docType) {
try {
// Build query
QueryBuilder queryBuilder = QueryBuilders.matchAllQuery();
if (StringUtils.isNotEmpty(structuredQuery)) {
Expression expression = Expression.fromString(structuredQuery);
queryBuilder = expression.getFilterBuilder();
}
BoolQueryBuilder filterQuery = QueryBuilders.boolQuery().must(queryBuilder);
QueryStringQueryBuilder stringQuery = QueryBuilders.queryStringQuery(freeTextQuery);
BoolQueryBuilder fq = QueryBuilders.boolQuery().must(stringQuery).must(filterQuery);
return searchObjectIds(indexName, fq, start, size, sortOptions, docType);
} catch (Exception e) {
throw new ApplicationException(ApplicationException.Code.BACKEND_ERROR, e.getMessage(), e);
}
}
use of com.netflix.conductor.core.execution.ApplicationException in project conductor by Netflix.
the class ElasticSearchRestDAOV5 method getEventExecutions.
@Override
public List<EventExecution> getEventExecutions(String event) {
try {
Expression expression = Expression.fromString("event='" + event + "'");
QueryBuilder queryBuilder = expression.getFilterBuilder();
BoolQueryBuilder filterQuery = QueryBuilders.boolQuery().must(queryBuilder);
QueryStringQueryBuilder stringQuery = QueryBuilders.queryStringQuery("*");
BoolQueryBuilder query = QueryBuilders.boolQuery().must(stringQuery).must(filterQuery);
// Create the searchObjectIdsViaExpression source
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.query(query);
searchSourceBuilder.sort(new FieldSortBuilder("created").order(SortOrder.ASC));
// Generate the actual request to send to ES.
SearchRequest searchRequest = new SearchRequest(logIndexPrefix + "*");
searchRequest.types(EVENT_DOC_TYPE);
searchRequest.source(searchSourceBuilder);
SearchResponse response = elasticSearchClient.search(searchRequest);
return mapEventExecutionsResponse(response);
} catch (Exception e) {
logger.error("Failed to get executions for event: {}", event, e);
throw new ApplicationException(ApplicationException.Code.BACKEND_ERROR, e.getMessage(), e);
}
}
use of com.netflix.conductor.core.execution.ApplicationException in project conductor by Netflix.
the class ElasticSearchRestDAOV5 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(indexName, 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 {} with {}", workflowInstanceId, source);
new RetryUtil<UpdateResponse>().retryOnException(() -> {
try {
return elasticSearchClient.update(request);
} catch (IOException e) {
throw new RuntimeException(e);
}
}, null, null, RETRY_COUNT, "Updating workflow document: " + workflowInstanceId, "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 ElasticSearchRestDAOV6 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();
String docType = StringUtils.isBlank(docTypeOverride) ? WORKFLOW_DOC_TYPE : docTypeOverride;
UpdateRequest request = new UpdateRequest(workflowIndexName, docType, 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 {} with {}", workflowInstanceId, source);
new RetryUtil<UpdateResponse>().retryOnException(() -> {
try {
return elasticSearchClient.update(request);
} catch (IOException e) {
throw new RuntimeException(e);
}
}, null, null, RETRY_COUNT, "Updating workflow document: " + workflowInstanceId, "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 ElasticSearchDAOV6 method search.
private SearchResult<String> search(String structuredQuery, int start, int size, List<String> sortOptions, String freeTextQuery, String docType) {
try {
docType = StringUtils.isBlank(docTypeOverride) ? docType : docTypeOverride;
BoolQueryBuilder fq = boolQueryBuilder(structuredQuery, freeTextQuery);
final SearchRequestBuilder srb = elasticSearchClient.prepareSearch(getIndexName(docType)).setQuery(fq).setTypes(docType).storedFields("_id").setFrom(start).setSize(size);
addSortOptions(srb, sortOptions);
return mapSearchResult(srb.get());
} catch (ParserException e) {
throw new ApplicationException(ApplicationException.Code.BACKEND_ERROR, e.getMessage(), e);
}
}
Aggregations