Search in sources :

Example 66 with QueryResponse

use of ddf.catalog.operation.QueryResponse in project ddf by codice.

the class SourceMetricsImplTest method testNullInput.

@Test
public void testNullInput() throws PluginExecutionException, StopProcessingException {
    QueryResponse output = sourceMetricsImpl.process(null);
    assertThat(output, is(nullValue(QueryResponse.class)));
}
Also used : QueryResponse(ddf.catalog.operation.QueryResponse) Test(org.junit.Test)

Example 67 with QueryResponse

use of ddf.catalog.operation.QueryResponse in project ddf by codice.

the class CatalogMetricsTest method catalogQueryExceptionMetric.

@Test
public void catalogQueryExceptionMetric() throws Exception {
    Iterable<Tag> unsupportedQueryExceptionTags = Tags.of("type", UnsupportedQueryException.class.getName(), "source", "source1");
    QueryResponse response = new QueryResponseImpl(new QueryRequestImpl(new QueryImpl(idFilter)), Collections.emptyList(), true, 0, Collections.emptyMap(), Collections.singleton(new ProcessingDetailsImpl("source1", new ExecutionException(new UnsupportedQueryException()))));
    catalogMetrics.process(response);
    assertThat(meterRegistry.counter("ddf.catalog.query.exceptions", unsupportedQueryExceptionTags).count(), is(1.0));
}
Also used : QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) QueryImpl(ddf.catalog.operation.impl.QueryImpl) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) QueryResponse(ddf.catalog.operation.QueryResponse) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Tag(io.micrometer.core.instrument.Tag) ExecutionException(java.util.concurrent.ExecutionException) ProcessingDetailsImpl(ddf.catalog.operation.impl.ProcessingDetailsImpl) Test(org.junit.Test)

Example 68 with QueryResponse

use of ddf.catalog.operation.QueryResponse in project ddf by codice.

the class QueryOperations method doQuery.

/**
 * Executes a query using the specified {@link QueryRequest} and {@link FederationStrategy}. Based
 * on the isEnterprise and sourceIds list in the query request, the federated query may include
 * the local provider and {@link ConnectedSource}s.
 *
 * @param queryRequest the {@link QueryRequest}
 * @param strategy the {@link FederationStrategy}
 * @return the {@link QueryResponse}
 * @throws FederationException
 */
QueryResponse doQuery(QueryRequest queryRequest, FederationStrategy strategy) throws FederationException {
    Set<String> sourceIds = getCombinedIdSet(queryRequest);
    LOGGER.debug("source ids: {}", sourceIds);
    QuerySources querySources = new QuerySources(frameworkProperties, securityLogger).initializeSources(this, queryRequest, sourceIds).addConnectedSources(this, frameworkProperties).addCatalogProvider(this);
    if (querySources.isEmpty()) {
        // TODO change to SourceUnavailableException
        throw new FederationException("SiteNames could not be resolved due to invalid site names, none of the sites " + "were available, or the current subject doesn't have permission to access the sites.");
    }
    LOGGER.debug("Calling strategy.federate()");
    Query originalQuery = queryRequest.getQuery();
    if (originalQuery != null && originalQuery.getTimeoutMillis() <= 0) {
        Query modifiedQuery = new QueryImpl(originalQuery, originalQuery.getStartIndex(), originalQuery.getPageSize(), originalQuery.getSortBy(), originalQuery.requestsTotalResultsCount(), queryTimeoutMillis);
        queryRequest = new QueryRequestImpl(modifiedQuery, queryRequest.isEnterprise(), queryRequest.getSourceIds(), queryRequest.getProperties());
    }
    QueryResponse response = strategy.federate(querySources.sourcesToQuery, queryRequest);
    frameworkProperties.getQueryResponsePostProcessor().processResponse(response);
    return addProcessingDetails(querySources.exceptions, response);
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) Query(ddf.catalog.operation.Query) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) FederationException(ddf.catalog.federation.FederationException)

Example 69 with QueryResponse

use of ddf.catalog.operation.QueryResponse in project ddf by codice.

the class ResourceOperations method getEnterpriseResourceOptions.

public Map<String, Set<String>> getEnterpriseResourceOptions(String metacardId, boolean fanoutEnabled) throws ResourceNotFoundException {
    LOGGER.trace(ENTERING_STR, GET_ENTERPRISE_RESOURCE_OPTIONS);
    Set<String> supportedOptions = Collections.emptySet();
    try {
        QueryRequest queryRequest = new QueryRequestImpl(createMetacardIdQuery(metacardId), true, null, null);
        QueryResponse queryResponse = queryOperations.query(queryRequest, null, false, fanoutEnabled);
        List<Result> results = queryResponse.getResults();
        if (!results.isEmpty()) {
            Metacard metacard = results.get(0).getMetacard();
            String sourceIdOfResult = metacard.getSourceId();
            if (sourceIdOfResult != null && sourceIdOfResult.equals(getId())) {
                // found entry on local source
                supportedOptions = getOptionsFromLocalProvider(metacard);
            } else if (sourceIdOfResult != null && !sourceIdOfResult.equals(getId())) {
                // found entry on federated source
                supportedOptions = getOptionsFromFederatedSource(metacard, sourceIdOfResult);
            }
        } else {
            String message = "Unable to find metacard " + metacardId + " on enterprise.";
            LOGGER.debug(message);
            LOGGER.trace(EXITING_STR, GET_ENTERPRISE_RESOURCE_OPTIONS);
            throw new ResourceNotFoundException(message);
        }
    } catch (UnsupportedQueryException e) {
        LOGGER.debug(ERR_FINDING_MC, metacardId, e);
        LOGGER.trace(EXITING_STR, GET_ENTERPRISE_RESOURCE_OPTIONS);
        throw new ResourceNotFoundException(ERR_FINDING_MC_UNSUPPORTED, e);
    } catch (FederationException e) {
        LOGGER.debug(ERR_FEDERATING_QUERY, metacardId, e);
        LOGGER.trace(EXITING_STR, GET_ENTERPRISE_RESOURCE_OPTIONS);
        throw new ResourceNotFoundException(ERR_FINDING_MC_FEDERATION, e);
    } catch (IllegalArgumentException e) {
        LOGGER.debug(NO_MC_FOUND, metacardId, e);
        LOGGER.trace(EXITING_STR, GET_ENTERPRISE_RESOURCE_OPTIONS);
        throw new ResourceNotFoundException(QUERY_RETURNED_NULL, e);
    }
    LOGGER.trace(EXITING_STR, GET_ENTERPRISE_RESOURCE_OPTIONS);
    return Collections.singletonMap(ResourceRequest.OPTION_ARGUMENT, supportedOptions);
}
Also used : Metacard(ddf.catalog.data.Metacard) QueryRequest(ddf.catalog.operation.QueryRequest) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException) FederationException(ddf.catalog.federation.FederationException) Result(ddf.catalog.data.Result)

Example 70 with QueryResponse

use of ddf.catalog.operation.QueryResponse in project ddf by codice.

the class ResourceOperations method getResourceInfo.

private ResourceInfo getResourceInfo(QueryRequest queryRequest, URI uri, Map<String, Serializable> requestProperties, StringBuilder federatedSite, boolean fanoutEnabled) throws ResourceNotFoundException, UnsupportedQueryException, FederationException {
    Metacard metacard;
    URI resourceUri = uri;
    QueryResponse queryResponse = queryOperations.query(queryRequest, null, true, fanoutEnabled);
    if (queryResponse.getResults().isEmpty()) {
        throw new ResourceNotFoundException("Could not resolve source id for URI by doing a URI based query.");
    }
    metacard = queryResponse.getResults().get(0).getMetacard();
    if (uri != null && queryResponse.getResults().size() > 1) {
        for (Result result : queryResponse.getResults()) {
            if (uri.equals(result.getMetacard().getResourceURI())) {
                metacard = result.getMetacard();
                break;
            }
        }
    }
    if (resourceUri == null) {
        resourceUri = metacard.getResourceURI();
    }
    federatedSite.append(metacard.getSourceId());
    LOGGER.debug("Trying to lookup resource URI {} for metacardId: {}", resourceUri, metacard.getId());
    if (!requestProperties.containsKey(Metacard.ID)) {
        requestProperties.put(Metacard.ID, metacard.getId());
    }
    if (!requestProperties.containsKey(Metacard.RESOURCE_URI)) {
        requestProperties.put(Metacard.RESOURCE_URI, metacard.getResourceURI());
    }
    return new ResourceInfo(metacard, resourceUri);
}
Also used : Metacard(ddf.catalog.data.Metacard) QueryResponse(ddf.catalog.operation.QueryResponse) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException) URI(java.net.URI) Result(ddf.catalog.data.Result)

Aggregations

QueryResponse (ddf.catalog.operation.QueryResponse)187 QueryRequest (ddf.catalog.operation.QueryRequest)130 Test (org.junit.Test)113 Metacard (ddf.catalog.data.Metacard)91 Result (ddf.catalog.data.Result)85 ArrayList (java.util.ArrayList)73 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)70 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)55 QueryImpl (ddf.catalog.operation.impl.QueryImpl)48 QueryResponseImpl (ddf.catalog.operation.impl.QueryResponseImpl)43 FederationException (ddf.catalog.federation.FederationException)40 ResultImpl (ddf.catalog.data.impl.ResultImpl)39 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)39 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)33 Filter (org.opengis.filter.Filter)33 HashMap (java.util.HashMap)31 Serializable (java.io.Serializable)30 Source (ddf.catalog.source.Source)28 HashSet (java.util.HashSet)28 CatalogFramework (ddf.catalog.CatalogFramework)26