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)));
}
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));
}
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);
}
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);
}
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);
}
Aggregations