use of ddf.catalog.plugin.StopProcessingException in project ddf by codice.
the class QueryOperations method populateQueryRequestPolicyMap.
private QueryRequest populateQueryRequestPolicyMap(QueryRequest queryReq) throws FederationException {
HashMap<String, Set<String>> requestPolicyMap = new HashMap<>();
Map<String, Serializable> unmodifiableProperties = Collections.unmodifiableMap(queryReq.getProperties());
for (PolicyPlugin plugin : frameworkProperties.getPolicyPlugins()) {
try {
PolicyResponse policyResponse = plugin.processPreQuery(queryReq.getQuery(), unmodifiableProperties);
opsSecuritySupport.buildPolicyMap(requestPolicyMap, policyResponse.operationPolicy().entrySet());
} catch (StopProcessingException e) {
throw new FederationException(QUERY_FAILURE_MSG, e);
}
}
queryReq.getProperties().put(PolicyPlugin.OPERATION_SECURITY, requestPolicyMap);
return queryReq;
}
use of ddf.catalog.plugin.StopProcessingException in project ddf by codice.
the class SortedQueryMonitor method executePostFederationQueryPlugins.
private SourceResponse executePostFederationQueryPlugins(SourceResponse sourceResponse, QueryRequest queryRequest, String sourceId, Set<ProcessingDetails> processingDetails) {
final HashSet<ProcessingDetails> newProcessingDetails = new HashSet<>(processingDetails);
newProcessingDetails.addAll(sourceProcessingDetailsToProcessingDetails(sourceId, sourceResponse));
QueryResponse queryResponse = new QueryResponseImpl(queryRequest, sourceResponse.getResults(), true, sourceResponse.getHits(), sourceResponse.getProperties(), newProcessingDetails);
try {
for (PostFederatedQueryPlugin service : postQuery) {
try {
queryResponse = service.process(queryResponse);
} catch (PluginExecutionException e) {
LOGGER.info("Error executing PostFederatedQueryPlugin", e);
}
}
} catch (StopProcessingException e) {
LOGGER.info("Plugin stopped processing", e);
}
Set<SourceProcessingDetails> detailsOfResponseAfterPlugins = new HashSet<>(queryResponse.getProcessingDetails());
return new SourceResponseImpl(queryRequest, sourceResponse.getProperties(), queryResponse.getResults(), queryResponse.getHits(), detailsOfResponseAfterPlugins);
}
use of ddf.catalog.plugin.StopProcessingException in project ddf by codice.
the class SourceMetricsImplTest method testExceptionCounterForQueryResponse.
@Test
public void testExceptionCounterForQueryResponse() throws PluginExecutionException, StopProcessingException {
QueryResponse queryResponse = mock(QueryResponse.class);
Set<ProcessingDetails> processingDetails = Stream.of(new ProcessingDetailsImpl("testSource", new Exception())).collect(Collectors.toSet());
when(queryResponse.getProcessingDetails()).thenReturn(processingDetails);
sourceMetricsImpl.process(queryResponse);
String suffix = METRICS_PREFIX + "." + QUERY_SCOPE + "." + EXCEPTION_TYPE;
assertThat(meterRegistry.counter(suffix, "source", "testSource").count(), is(1.0));
}
use of ddf.catalog.plugin.StopProcessingException in project ddf by codice.
the class SortedFederationStrategy method federate.
@Override
public QueryResponse federate(List<Source> sources, QueryRequest queryRequest) {
Validate.noNullElements(sources, "Cannot federate with null sources.");
Validate.notNull(queryRequest, "Cannot federate with null QueryRequest.");
if (LOGGER.isDebugEnabled()) {
for (Source source : sources) {
if (source != null) {
LOGGER.debug("source to query: {}", source.getId());
}
}
}
Query originalQuery = queryRequest.getQuery();
int offset = originalQuery.getStartIndex();
final int pageSize = originalQuery.getPageSize();
// limit offset to max value
if (offset > this.maxStartIndex) {
offset = this.maxStartIndex;
}
final Map<String, Serializable> properties = Collections.synchronizedMap(new HashMap<>());
final QueryResponseImpl queryResponseQueue = new QueryResponseImpl(queryRequest, properties);
Map<Future<SourceResponse>, QueryRequest> futures = new HashMap<>();
Query modifiedQuery = getModifiedQuery(originalQuery, sources.size(), offset, pageSize);
QueryRequest modifiedQueryRequest = new QueryRequestImpl(modifiedQuery, queryRequest.isEnterprise(), queryRequest.getSourceIds(), queryRequest.getProperties());
CompletionService<SourceResponse> queryCompletion = new ExecutorCompletionService<>(queryExecutorService);
// Do NOT call source.isAvailable() when checking sources
for (final Source source : sources) {
if (source != null) {
LOGGER.debug("running query on source: {}", source.getId());
QueryRequest sourceQueryRequest = new QueryRequestImpl(modifiedQuery, queryRequest.isEnterprise(), Collections.singleton(source.getId()), new HashMap<>(queryRequest.getProperties()));
try {
for (PreFederatedQueryPlugin service : preQuery) {
try {
sourceQueryRequest = service.process(source, sourceQueryRequest);
} catch (PluginExecutionException e) {
LOGGER.info("Error executing PreFederatedQueryPlugin", e);
}
}
} catch (StopProcessingException e) {
LOGGER.info("Plugin stopped processing", e);
}
QueryRequest finalSourceQueryRequest = sourceQueryRequest;
futures.put(queryCompletion.submit(() -> new TimedSource(source).query(finalSourceQueryRequest)), sourceQueryRequest);
}
}
QueryResponseImpl offsetResults = null;
// OffsetResultHandler does.
if (offset > 1 && sources.size() > 1) {
offsetResults = new QueryResponseImpl(queryRequest, properties);
queryExecutorService.submit(new QueryResponseRunnableMonitor(new OffsetResultHandler(queryResponseQueue, offsetResults, pageSize, offset), offsetResults));
}
queryExecutorService.submit(new QueryResponseRunnableMonitor(sortedQueryMonitorFactory.createMonitor(queryCompletion, futures, queryResponseQueue, modifiedQueryRequest, postQuery), queryResponseQueue));
QueryResponse queryResponse;
if (offset > 1 && sources.size() > 1) {
queryResponse = offsetResults;
LOGGER.debug("returning offsetResults");
} else {
queryResponse = queryResponseQueue;
LOGGER.debug("returning returnResults: {}", queryResponse);
}
LOGGER.debug("returning Query Results: {}", queryResponse);
return queryResponse;
}
use of ddf.catalog.plugin.StopProcessingException in project ddf by codice.
the class FacetAttributeAccessPlugin method processPreQuery.
@Override
public QueryRequest processPreQuery(QueryRequest input) throws StopProcessingException {
if (input.getProperties().get(EXPERIMENTAL_FACET_PROPERTIES_KEY) instanceof TermFacetProperties) {
TermFacetProperties facetProperties = (TermFacetProperties) input.getProperties().get(EXPERIMENTAL_FACET_PROPERTIES_KEY);
Set<String> facetAttributes = facetProperties.getFacetAttributes();
for (String attr : facetAttributes) {
if (!config.getFacetAttributeWhitelist().contains(attr)) {
throw new StopProcessingException("Invalid Facet Attribute Detected: " + attr);
}
}
}
return input;
}
Aggregations