Search in sources :

Example 6 with ProcessingDetails

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);
    }
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) SortBy(org.opengis.filter.sort.SortBy) ArrayList(java.util.ArrayList) Result(ddf.catalog.data.Result) ProcessingDetails(ddf.catalog.operation.ProcessingDetails) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException) ExecutionException(java.util.concurrent.ExecutionException) PropertyName(org.opengis.filter.expression.PropertyName) QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponse(ddf.catalog.operation.SourceResponse) SortOrder(org.opengis.filter.sort.SortOrder) TemporalResultComparator(ddf.catalog.util.impl.TemporalResultComparator) QueryResponse(ddf.catalog.operation.QueryResponse) RelevanceResultComparator(ddf.catalog.util.impl.RelevanceResultComparator) DistanceResultComparator(ddf.catalog.util.impl.DistanceResultComparator)

Example 7 with ProcessingDetails

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));
}
Also used : ProcessingDetails(ddf.catalog.operation.ProcessingDetails) SourceResponse(ddf.catalog.operation.SourceResponse) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) Test(org.junit.Test)

Example 8 with ProcessingDetails

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());
        }
    });
}
Also used : ProcessingDetails(ddf.catalog.operation.ProcessingDetails) UpdateRequest(ddf.catalog.operation.UpdateRequest) MetacardMarshaller(org.codice.ddf.registry.schemabindings.helper.MetacardMarshaller) CreateRequest(ddf.catalog.operation.CreateRequest) DeleteRequest(ddf.catalog.operation.DeleteRequest) Callable(java.util.concurrent.Callable) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) FederationAdminException(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException) ParserException(org.codice.ddf.parser.ParserException) InvocationTargetException(java.lang.reflect.InvocationTargetException) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) IngestException(ddf.catalog.source.IngestException) FederationException(ddf.catalog.federation.FederationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Before(org.junit.Before)

Example 9 with ProcessingDetails

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;
}
Also used : ProcessingDetails(ddf.catalog.operation.ProcessingDetails) Set(java.util.Set)

Example 10 with ProcessingDetails

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);
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) CreateResponse(ddf.catalog.operation.CreateResponse) ProcessingDetailsImpl(ddf.catalog.operation.impl.ProcessingDetailsImpl) ProcessingDetails(ddf.catalog.operation.ProcessingDetails) CatalogStore(ddf.catalog.source.CatalogStore) InternalIngestException(ddf.catalog.source.InternalIngestException) IngestException(ddf.catalog.source.IngestException) HashSet(java.util.HashSet) CreateResponseImpl(ddf.catalog.operation.impl.CreateResponseImpl)

Aggregations

ProcessingDetails (ddf.catalog.operation.ProcessingDetails)15 ProcessingDetailsImpl (ddf.catalog.operation.impl.ProcessingDetailsImpl)8 HashMap (java.util.HashMap)7 IngestException (ddf.catalog.source.IngestException)6 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)6 Serializable (java.io.Serializable)6 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)5 Metacard (ddf.catalog.data.Metacard)3 FederationException (ddf.catalog.federation.FederationException)3 SourceResponse (ddf.catalog.operation.SourceResponse)3 CatalogStore (ddf.catalog.source.CatalogStore)3 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)3 Result (ddf.catalog.data.Result)2 QueryResponse (ddf.catalog.operation.QueryResponse)2 CreateResponseImpl (ddf.catalog.operation.impl.CreateResponseImpl)2 QueryResponseImpl (ddf.catalog.operation.impl.QueryResponseImpl)2 UpdateResponseImpl (ddf.catalog.operation.impl.UpdateResponseImpl)2 InternalIngestException (ddf.catalog.source.InternalIngestException)2 Subject (ddf.security.Subject)2