Search in sources :

Example 31 with StopProcessingException

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;
}
Also used : Serializable(java.io.Serializable) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) PolicyPlugin(ddf.catalog.plugin.PolicyPlugin) StopProcessingException(ddf.catalog.plugin.StopProcessingException) FederationException(ddf.catalog.federation.FederationException) PolicyResponse(ddf.catalog.plugin.PolicyResponse)

Example 32 with StopProcessingException

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);
}
Also used : SourceProcessingDetails(ddf.catalog.operation.SourceProcessingDetails) ProcessingDetails(ddf.catalog.operation.ProcessingDetails) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) QueryResponse(ddf.catalog.operation.QueryResponse) StopProcessingException(ddf.catalog.plugin.StopProcessingException) PostFederatedQueryPlugin(ddf.catalog.plugin.PostFederatedQueryPlugin) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException) HashSet(java.util.HashSet) SourceProcessingDetails(ddf.catalog.operation.SourceProcessingDetails)

Example 33 with StopProcessingException

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));
}
Also used : ProcessingDetails(ddf.catalog.operation.ProcessingDetails) QueryResponse(ddf.catalog.operation.QueryResponse) ProcessingDetailsImpl(ddf.catalog.operation.impl.ProcessingDetailsImpl) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException) StopProcessingException(ddf.catalog.plugin.StopProcessingException) Test(org.junit.Test)

Example 34 with StopProcessingException

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;
}
Also used : Serializable(java.io.Serializable) Query(ddf.catalog.operation.Query) QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponse(ddf.catalog.operation.SourceResponse) PreFederatedQueryPlugin(ddf.catalog.plugin.PreFederatedQueryPlugin) HashMap(java.util.HashMap) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) StopProcessingException(ddf.catalog.plugin.StopProcessingException) Source(ddf.catalog.source.Source) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) Future(java.util.concurrent.Future) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException)

Example 35 with StopProcessingException

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;
}
Also used : StopProcessingException(ddf.catalog.plugin.StopProcessingException) TermFacetProperties(ddf.catalog.operation.TermFacetProperties)

Aggregations

StopProcessingException (ddf.catalog.plugin.StopProcessingException)38 QueryResponse (ddf.catalog.operation.QueryResponse)11 Metacard (ddf.catalog.data.Metacard)10 PluginExecutionException (ddf.catalog.plugin.PluginExecutionException)10 QueryRequest (ddf.catalog.operation.QueryRequest)9 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)8 Attribute (ddf.catalog.data.Attribute)7 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)7 QueryResponseImpl (ddf.catalog.operation.impl.QueryResponseImpl)7 Serializable (java.io.Serializable)7 HashMap (java.util.HashMap)7 Result (ddf.catalog.data.Result)6 Query (ddf.catalog.operation.Query)6 PreFederatedQueryPlugin (ddf.catalog.plugin.PreFederatedQueryPlugin)6 Source (ddf.catalog.source.Source)6 Map (java.util.Map)6 Subject (org.apache.shiro.subject.Subject)6 KeyValueCollectionPermission (ddf.security.permission.KeyValueCollectionPermission)5 List (java.util.List)5