use of com.netflix.conductor.core.execution.ApplicationException in project conductor by Netflix.
the class ElasticSearchRestDAOV7 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, 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, RequestOptions.DEFAULT);
} 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 QueueManager method startMonitor.
private void startMonitor(Status status, ObservableQueue queue) {
queue.observe().subscribe((Message msg) -> {
try {
logger.debug("Got message {}", msg.getPayload());
String payload = msg.getPayload();
JsonNode payloadJSON = objectMapper.readTree(payload);
String externalId = getValue("externalId", payloadJSON);
if (externalId == null || "".equals(externalId)) {
logger.error("No external Id found in the payload {}", payload);
queue.ack(Collections.singletonList(msg));
return;
}
JsonNode json = objectMapper.readTree(externalId);
String workflowId = getValue("workflowId", json);
String taskRefName = getValue("taskRefName", json);
String taskId = getValue("taskId", json);
if (workflowId == null || "".equals(workflowId)) {
// This is a bad message, we cannot process it
logger.error("No workflow id found in the message. {}", payload);
queue.ack(Collections.singletonList(msg));
return;
}
Workflow workflow = executionService.getExecutionStatus(workflowId, true);
Optional<Task> taskOptional;
if (StringUtils.isNotEmpty(taskId)) {
taskOptional = workflow.getTasks().stream().filter(task -> !task.getStatus().isTerminal() && task.getTaskId().equals(taskId)).findFirst();
} else if (StringUtils.isEmpty(taskRefName)) {
logger.error("No taskRefName found in the message. If there is only one WAIT task, will mark it as completed. {}", payload);
taskOptional = workflow.getTasks().stream().filter(task -> !task.getStatus().isTerminal() && task.getTaskType().equals(Wait.NAME)).findFirst();
} else {
taskOptional = workflow.getTasks().stream().filter(task -> !task.getStatus().isTerminal() && task.getReferenceTaskName().equals(taskRefName)).findFirst();
}
if (!taskOptional.isPresent()) {
logger.error("No matching tasks found to be marked as completed for workflow {}, taskRefName {}, taskId {}", workflowId, taskRefName, taskId);
queue.ack(Collections.singletonList(msg));
return;
}
Task task = taskOptional.get();
task.setStatus(status);
task.getOutputData().putAll(objectMapper.convertValue(payloadJSON, _mapType));
executionService.updateTask(task);
List<String> failures = queue.ack(Collections.singletonList(msg));
if (!failures.isEmpty()) {
logger.error("Not able to ack the messages {}", failures.toString());
}
} catch (JsonParseException e) {
logger.error("Bad message? : {} ", msg, e);
queue.ack(Collections.singletonList(msg));
} catch (ApplicationException e) {
if (e.getCode().equals(Code.NOT_FOUND)) {
logger.error("Workflow ID specified is not valid for this environment");
queue.ack(Collections.singletonList(msg));
}
logger.error("Error processing message: {}", msg, e);
} catch (Exception e) {
logger.error("Error processing message: {}", msg, e);
}
}, (Throwable t) -> {
logger.error(t.getMessage(), t);
});
logger.info("QueueListener::STARTED...listening for " + queue.getName());
}
use of com.netflix.conductor.core.execution.ApplicationException in project conductor by Netflix.
the class ElasticSearchDAOV5 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 fq = QueryBuilders.boolQuery().must(stringQuery).must(filterQuery);
final SearchRequestBuilder srb = elasticSearchClient.prepareSearch(logIndexPrefix + "*").setQuery(fq).setTypes(EVENT_DOC_TYPE).addSort(SortBuilders.fieldSort("created").order(SortOrder.ASC));
return mapEventExecutionsResponse(srb.execute().actionGet());
} catch (Exception e) {
String errorMsg = String.format("Failed to get executions for event: %s", event);
logger.error(errorMsg, e);
throw new ApplicationException(Code.BACKEND_ERROR, errorMsg, e);
}
}
use of com.netflix.conductor.core.execution.ApplicationException in project conductor by Netflix.
the class ElasticSearchDAOV5 method updateWorkflow.
@Override
public void updateWorkflow(String workflowInstanceId, String[] keys, Object[] values) {
if (keys.length != values.length) {
throw new 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 {} in elasticsearch index: {}", workflowInstanceId, indexName);
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 ElasticSearchDAOV5 method search.
private SearchResult<String> search(String indexName, String structuredQuery, int start, int size, List<String> sortOptions, String freeTextQuery, String docType) {
try {
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);
final SearchRequestBuilder srb = elasticSearchClient.prepareSearch(indexName).setQuery(fq).setTypes(docType).storedFields("_id").setFrom(start).setSize(size);
if (sortOptions != null) {
sortOptions.forEach(sortOption -> addSortOptionToSearchRequest(srb, sortOption));
}
SearchResponse response = srb.get();
LinkedList<String> result = StreamSupport.stream(response.getHits().spliterator(), false).map(SearchHit::getId).collect(Collectors.toCollection(LinkedList::new));
long count = response.getHits().getTotalHits();
return new SearchResult<>(count, result);
} catch (ParserException e) {
String errorMsg = String.format("Error performing search on index:%s with docType:%s", indexName, docType);
logger.error(errorMsg);
throw new ApplicationException(Code.BACKEND_ERROR, errorMsg, e);
}
}
Aggregations