use of ddf.catalog.operation.ProcessingDetails in project ddf by codice.
the class SortedQueryMonitor method run.
@Override
public void run() {
SortBy sortBy = query.getSortBy();
// Prepare the Comparators that we will use
Comparator<Result> coreComparator = CachingFederationStrategy.DEFAULT_COMPARATOR;
if (sortBy != null && sortBy.getPropertyName() != null) {
PropertyName sortingProp = sortBy.getPropertyName();
String sortType = sortingProp.getPropertyName();
SortOrder sortOrder = (sortBy.getSortOrder() == null) ? SortOrder.DESCENDING : sortBy.getSortOrder();
LOGGER.debug("Sorting type: {}", sortType);
LOGGER.debug("Sorting order: {}", sortBy.getSortOrder());
// Temporal searches are currently sorted by the effective time
if (Metacard.EFFECTIVE.equals(sortType) || Result.TEMPORAL.equals(sortType)) {
coreComparator = new TemporalResultComparator(sortOrder);
} else if (Result.DISTANCE.equals(sortType)) {
coreComparator = new DistanceResultComparator(sortOrder);
} else if (Result.RELEVANCE.equals(sortType)) {
coreComparator = new RelevanceResultComparator(sortOrder);
}
}
List<Result> resultList = new ArrayList<>();
long totalHits = 0;
Set<ProcessingDetails> processingDetails = returnResults.getProcessingDetails();
Map<String, Serializable> returnProperties = returnResults.getProperties();
HashMap<String, Long> hitsPerSource = new HashMap<>();
for (int i = futures.size(); i > 0; i--) {
String sourceId = "Unknown Source";
QueryRequest queryRequest = null;
SourceResponse sourceResponse = null;
try {
Future<SourceResponse> future;
if (query.getTimeoutMillis() < 1) {
future = completionService.take();
} else {
future = completionService.poll(getTimeRemaining(deadline), TimeUnit.MILLISECONDS);
if (future == null) {
timeoutRemainingSources(processingDetails);
break;
}
}
queryRequest = futures.remove(future);
sourceId = getSourceIdFromRequest(queryRequest);
sourceResponse = future.get();
if (sourceResponse == null) {
LOGGER.debug("Source {} returned null response", sourceId);
executePostFederationQueryPluginsWithSourceError(queryRequest, sourceId, new NullPointerException(), processingDetails);
} else {
sourceResponse = executePostFederationQueryPlugins(sourceResponse, queryRequest);
resultList.addAll(sourceResponse.getResults());
long hits = sourceResponse.getHits();
totalHits += hits;
hitsPerSource.merge(sourceId, hits, (l1, l2) -> l1 + l2);
Map<String, Serializable> properties = sourceResponse.getProperties();
returnProperties.putAll(properties);
}
} catch (InterruptedException e) {
if (queryRequest != null) {
// First, add interrupted processing detail for this source
LOGGER.debug("Search interrupted for {}", sourceId);
executePostFederationQueryPluginsWithSourceError(queryRequest, sourceId, e, processingDetails);
}
// Then add the interrupted exception for the remaining sources
interruptRemainingSources(processingDetails, e);
break;
} catch (ExecutionException e) {
LOGGER.info("Couldn't get results from completed federated query. {}, {}", sourceId, Exceptions.getFullMessage(e), e);
executePostFederationQueryPluginsWithSourceError(queryRequest, sourceId, e, processingDetails);
}
}
returnProperties.put("hitsPerSource", hitsPerSource);
LOGGER.debug("All sources finished returning results: {}", resultList.size());
returnResults.setHits(totalHits);
if (CachingFederationStrategy.INDEX_QUERY_MODE.equals(request.getPropertyValue(CachingFederationStrategy.QUERY_MODE))) {
QueryResponse result = cachingFederationStrategy.queryCache(request);
returnResults.addResults(result.getResults(), true);
} else {
returnResults.addResults(sortedResults(resultList, coreComparator), true);
}
}
use of ddf.catalog.operation.ProcessingDetails in project ddf by codice.
the class SolrCacheSourceTest method badQuery.
@Test
public void badQuery() throws Exception {
when(solrCache.query(queryRequest)).thenThrow(new UnsupportedQueryException("Failed"));
SourceResponse queryResponse = solrCacheSource.query(queryRequest);
assertThat(queryResponse.getProcessingDetails().size(), greaterThan(0));
ProcessingDetails processingDetail = queryResponse.getProcessingDetails().stream().filter(ProcessingDetails.class::isInstance).map(ProcessingDetails.class::cast).filter(pd -> pd.getSourceId().equals(solrCacheSource.getId())).findFirst().orElse(null);
assertThat(processingDetail, notNullValue());
assertThat(processingDetail.getException(), instanceOf(UnsupportedQueryException.class));
}
use of ddf.catalog.operation.ProcessingDetails in project ddf by codice.
the class FederationAdminServiceImplTest method setUp.
@Before
public void setUp() throws Exception {
when(parser.configureParser(anyList(), any(ClassLoader.class))).thenReturn(configurator);
federationAdminServiceImpl = Mockito.spy(new FederationAdminServiceImpl(security));
federationAdminServiceImpl.setRegistryTransformer(registryTransformer);
federationAdminServiceImpl.setCatalogFramework(catalogFramework);
federationAdminServiceImpl.setMetacardMarshaller(new MetacardMarshaller(parser));
federationAdminServiceImpl.setFilterBuilder(filterBuilder);
System.setProperty(SystemInfo.SITE_NAME, TEST_SITE_NAME);
System.setProperty(SystemInfo.VERSION, TEST_VERSION);
testMetacard = getPopulatedTestRegistryMetacard();
when(deleteResponse.getProcessingErrors()).thenReturn(new HashSet<ProcessingDetails>());
when(createResponse.getProcessingErrors()).thenReturn(new HashSet<ProcessingDetails>());
when(updateResponse.getProcessingErrors()).thenReturn(new HashSet<ProcessingDetails>());
when(catalogFramework.update(any(UpdateRequest.class))).thenReturn(updateResponse);
when(catalogFramework.delete(any(DeleteRequest.class))).thenReturn(deleteResponse);
when(catalogFramework.create(any(CreateRequest.class))).thenReturn(createResponse);
when(security.runWithSubjectOrElevate(any(Callable.class))).thenAnswer(invocation -> {
try {
return ((Callable) invocation.getArguments()[0]).call();
} catch (Exception e) {
throw new InvocationTargetException(e.getCause());
}
});
}
use of ddf.catalog.operation.ProcessingDetails in project ddf by codice.
the class RemoveAllCommand method needsAlternateQueryAndResponse.
private boolean needsAlternateQueryAndResponse(SourceResponse response) {
Set<ProcessingDetails> processingDetails = (Set<ProcessingDetails>) response.getProcessingDetails();
if (processingDetails == null || processingDetails.iterator() == null) {
return false;
}
Iterator<ProcessingDetails> iterator = processingDetails.iterator();
while (iterator.hasNext()) {
ProcessingDetails next = iterator.next();
if (next != null && next.getException() != null && next.getException().getMessage() != null && next.getException().getMessage().contains(UnsupportedQueryException.class.getSimpleName())) {
return true;
}
}
return false;
}
use of ddf.catalog.operation.ProcessingDetails in project ddf by codice.
the class CreateOperations method doRemoteCreate.
private CreateResponse doRemoteCreate(CreateRequest createRequest) {
HashSet<ProcessingDetails> exceptions = new HashSet<>();
Map<String, Serializable> properties = new HashMap<>();
List<CatalogStore> stores = opsCatStoreSupport.getCatalogStoresForRequest(createRequest, exceptions);
for (CatalogStore store : stores) {
try {
if (!store.isAvailable()) {
exceptions.add(new ProcessingDetailsImpl(store.getId(), null, "CatalogStore is not available"));
} else {
CreateResponse response = store.create(createRequest);
properties.put(store.getId(), new ArrayList<>(response.getCreatedMetacards()));
}
} catch (IngestException e) {
INGEST_LOGGER.error("Error creating metacards for CatalogStore {}", store.getId(), e);
exceptions.add(new ProcessingDetailsImpl(store.getId(), e));
}
}
return new CreateResponseImpl(createRequest, properties, createRequest.getMetacards(), exceptions);
}
Aggregations