Search in sources :

Example 11 with FederationException

use of ddf.catalog.federation.FederationException in project ddf by codice.

the class ResourceOperations method getResourceOptions.

public Map<String, Set<String>> getResourceOptions(String metacardId, String sourceId, boolean fanoutEnabled) throws ResourceNotFoundException {
    LOGGER.trace("ENTERING: getResourceOptions");
    Map<String, Set<String>> optionsMap;
    try {
        LOGGER.debug("source id to get options from: {}", sourceId);
        QueryRequest queryRequest = new QueryRequestImpl(createMetacardIdQuery(metacardId), false, Collections.singletonList(sourceId == null ? this.getId() : sourceId), null);
        QueryResponse queryResponse = queryOperations.query(queryRequest, null, false, fanoutEnabled);
        List<Result> results = queryResponse.getResults();
        if (!results.isEmpty()) {
            Metacard metacard = results.get(0).getMetacard();
            // or the local provider.
            if (StringUtils.isEmpty(sourceId) || sourceId.equals(getId())) {
                optionsMap = Collections.singletonMap(ResourceRequest.OPTION_ARGUMENT, getOptionsFromLocalProvider(metacard));
            } else {
                optionsMap = Collections.singletonMap(ResourceRequest.OPTION_ARGUMENT, getOptionsFromFederatedSource(metacard, sourceId));
            }
        } else {
            String message = "Could not find metacard " + metacardId + " on source " + sourceId;
            throw new ResourceNotFoundException(message);
        }
    } catch (UnsupportedQueryException e) {
        LOGGER.debug("Error finding metacard {}", metacardId, e);
        throw new ResourceNotFoundException("Error finding metacard due to Unsuppported Query", e);
    } catch (FederationException e) {
        LOGGER.debug("Error federating query for metacard {}", metacardId, e);
        throw new ResourceNotFoundException("Error finding metacard due to Federation issue", e);
    } catch (IllegalArgumentException e) {
        LOGGER.debug("Metacard couldn't be found {}", metacardId, e);
        throw new ResourceNotFoundException("Query returned null metacard", e);
    } finally {
        LOGGER.trace("EXITING: getResourceOptions");
    }
    return optionsMap;
}
Also used : Set(java.util.Set) QueryRequest(ddf.catalog.operation.QueryRequest) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) FederationException(ddf.catalog.federation.FederationException) Result(ddf.catalog.data.Result) Metacard(ddf.catalog.data.Metacard) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException)

Example 12 with FederationException

use of ddf.catalog.federation.FederationException in project ddf by codice.

the class ResourceOperations method getLocalResourceOptions.

public Map<String, Set<String>> getLocalResourceOptions(String metacardId, boolean fanoutEnabled) throws ResourceNotFoundException {
    LOGGER.trace("ENTERING: getLocalResourceOptions");
    Map<String, Set<String>> optionsMap;
    try {
        QueryRequest queryRequest = new QueryRequestImpl(createMetacardIdQuery(metacardId), false, Collections.singletonList(getId()), null);
        QueryResponse queryResponse = queryOperations.query(queryRequest, null, false, fanoutEnabled);
        List<Result> results = queryResponse.getResults();
        if (!results.isEmpty()) {
            Metacard metacard = results.get(0).getMetacard();
            optionsMap = Collections.singletonMap(ResourceRequest.OPTION_ARGUMENT, getOptionsFromLocalProvider(metacard));
        } else {
            String message = "Could not find metacard " + metacardId + " on local source";
            ResourceNotFoundException resourceNotFoundException = new ResourceNotFoundException(message);
            LOGGER.trace("EXITING: getLocalResourceOptions");
            throw resourceNotFoundException;
        }
    } catch (UnsupportedQueryException e) {
        LOGGER.debug("Error finding metacard {}", metacardId, e);
        LOGGER.trace("EXITING: getLocalResourceOptions");
        throw new ResourceNotFoundException("Error finding metacard due to Unsuppported Query", e);
    } catch (FederationException e) {
        LOGGER.debug("Error federating query for metacard {}", metacardId, e);
        LOGGER.trace("EXITING: getLocalResourceOptions");
        throw new ResourceNotFoundException("Error finding metacard due to Federation issue", e);
    } catch (IllegalArgumentException e) {
        LOGGER.debug("Metacard couldn't be found {}", metacardId, e);
        LOGGER.trace("EXITING: getLocalResourceOptions");
        throw new ResourceNotFoundException("Query returned null metacard", e);
    }
    LOGGER.trace("EXITING: getLocalResourceOptions");
    return optionsMap;
}
Also used : Set(java.util.Set) QueryRequest(ddf.catalog.operation.QueryRequest) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) FederationException(ddf.catalog.federation.FederationException) Result(ddf.catalog.data.Result) Metacard(ddf.catalog.data.Metacard) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException)

Example 13 with FederationException

use of ddf.catalog.federation.FederationException in project ddf by codice.

the class DuplicationValidator method query.

private SourceResponse query(Set<Attribute> attributes, String originalId) {
    final Filter filter = filterBuilder.allOf(filterBuilder.anyOf(buildFilters(attributes)), filterBuilder.not(filterBuilder.attribute(Metacard.ID).is().equalTo().text(originalId)));
    LOGGER.debug("filter {}", filter);
    QueryImpl query = new QueryImpl(filter);
    query.setRequestsTotalResultsCount(false);
    QueryRequest request = new QueryRequestImpl(query);
    SourceResponse response = null;
    try {
        response = catalogFramework.query(request);
    } catch (FederationException | SourceUnavailableException | UnsupportedQueryException e) {
        LOGGER.debug("Query failed ", e);
    }
    return response;
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) QueryImpl(ddf.catalog.operation.impl.QueryImpl) QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponse(ddf.catalog.operation.SourceResponse) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) FederationException(ddf.catalog.federation.FederationException)

Example 14 with FederationException

use of ddf.catalog.federation.FederationException in project ddf by codice.

the class ResourceCacheService method queryForMetacard.

private Optional<Metacard> queryForMetacard(String metacardId) {
    Filter filter = frameworkProperties.getFilterBuilder().attribute(Metacard.ID).is().equalTo().text(metacardId);
    QueryRequest queryRequest = new QueryRequestImpl(new QueryImpl(filter), true);
    QueryResponse queryResponse = null;
    try {
        queryResponse = catalogFramework.query(queryRequest);
    } catch (UnsupportedQueryException | SourceUnavailableException | FederationException e) {
        LOGGER.error("Unable to lookup metacard for metacard id [{}].", metacardId);
        return Optional.empty();
    }
    return queryResponse != null && queryResponse.getResults().size() == 1 ? Optional.of(queryResponse.getResults().get(0).getMetacard()) : Optional.empty();
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) QueryImpl(ddf.catalog.operation.impl.QueryImpl) QueryRequest(ddf.catalog.operation.QueryRequest) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) FederationException(ddf.catalog.federation.FederationException)

Example 15 with FederationException

use of ddf.catalog.federation.FederationException 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).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)

Aggregations

FederationException (ddf.catalog.federation.FederationException)39 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)31 QueryResponse (ddf.catalog.operation.QueryResponse)28 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)27 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)26 QueryRequest (ddf.catalog.operation.QueryRequest)20 Metacard (ddf.catalog.data.Metacard)18 QueryImpl (ddf.catalog.operation.impl.QueryImpl)18 Result (ddf.catalog.data.Result)14 IngestException (ddf.catalog.source.IngestException)11 Test (org.junit.Test)11 Filter (org.opengis.filter.Filter)10 ArrayList (java.util.ArrayList)9 CatalogFramework (ddf.catalog.CatalogFramework)8 CreateResponse (ddf.catalog.operation.CreateResponse)8 Set (java.util.Set)8 CreateRequestImpl (ddf.catalog.operation.impl.CreateRequestImpl)7 Serializable (java.io.Serializable)7 HashMap (java.util.HashMap)7 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)6