Search in sources :

Example 1 with ProcessingDetailsImpl

use of ddf.catalog.operation.impl.ProcessingDetailsImpl in project ddf by codice.

the class CatalogMetricsTest method catalogExceptionMetric.

@Test
public void catalogExceptionMetric() throws Exception {
    QueryResponse response = new QueryResponseImpl(new QueryRequestImpl(new QueryImpl(idFilter)));
    Set<ProcessingDetails> details = response.getProcessingDetails();
    details.addAll(new HashSet<ProcessingDetails>() {

        {
            add(new ProcessingDetailsImpl("source1", new UnsupportedQueryException()));
            add(new ProcessingDetailsImpl("source2", new SourceUnavailableException()));
            add(new ProcessingDetailsImpl("source3", new FederationException()));
            add(new ProcessingDetailsImpl("source4", new Exception()));
        }
    });
    underTest.process(response);
    assertThat(underTest.exceptions.getCount(), is(4L));
    assertThat(underTest.unsupportedQueryExceptions.getCount(), is(1L));
    assertThat(underTest.sourceUnavailableExceptions.getCount(), is(1L));
    assertThat(underTest.federationExceptions.getCount(), is(1L));
}
Also used : ProcessingDetails(ddf.catalog.operation.ProcessingDetails) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) QueryImpl(ddf.catalog.operation.impl.QueryImpl) QueryResponse(ddf.catalog.operation.QueryResponse) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) FederationException(ddf.catalog.federation.FederationException) ProcessingDetailsImpl(ddf.catalog.operation.impl.ProcessingDetailsImpl) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) FederationException(ddf.catalog.federation.FederationException) Test(org.junit.Test)

Example 2 with ProcessingDetailsImpl

use of ddf.catalog.operation.impl.ProcessingDetailsImpl in project ddf by codice.

the class QueryRunnable method queryCatalog.

protected QueryResponse queryCatalog(String sourceId, SearchRequest searchRequest, Subject subject, Map<String, Serializable> properties) {
    Query query = searchRequest.getQuery();
    QueryResponse response = getEmptyResponse(sourceId);
    long startTime = System.currentTimeMillis();
    try {
        if (query != null) {
            List<String> sourceIds;
            if (sourceId == null) {
                sourceIds = new ArrayList<>(searchRequest.getSourceIds());
            } else {
                sourceIds = Collections.singletonList(sourceId);
            }
            QueryRequest request = new QueryRequestImpl(query, false, sourceIds, properties);
            if (subject != null) {
                LOGGER.debug("Adding {} property with value {} to request.", SecurityConstants.SECURITY_SUBJECT, subject);
                request.getProperties().put(SecurityConstants.SECURITY_SUBJECT, subject);
            }
            LOGGER.debug("Sending query: {}", query);
            response = searchController.getFramework().query(request);
        }
    } catch (UnsupportedQueryException | FederationException e) {
        LOGGER.info("Error executing query. {}. Set log level to DEBUG for more information", e.getMessage());
        LOGGER.debug("Error executing query", e);
        response.getProcessingDetails().add(new ProcessingDetailsImpl(sourceId, e));
    } catch (SourceUnavailableException e) {
        LOGGER.info("Error executing query because the underlying source was unavailable. {}. Set log level to DEBUG for more information", e.getMessage());
        LOGGER.debug("Error executing query because the underlying source was unavailable.", e);
        response.getProcessingDetails().add(new ProcessingDetailsImpl(sourceId, e));
    } catch (RuntimeException e) {
        // Account for any runtime exceptions and send back a server error
        // this prevents full stacktraces returning to the client
        // this allows for a graceful server error to be returned
        LOGGER.info("RuntimeException on executing query. {}. Set log level to DEBUG for more information", e.getMessage());
        LOGGER.debug("RuntimeException on executing query", e);
        response.getProcessingDetails().add(new ProcessingDetailsImpl(sourceId, e));
    }
    long estimatedTime = System.currentTimeMillis() - startTime;
    response.getProperties().put("elapsed", estimatedTime);
    return response;
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) Query(ddf.catalog.operation.Query) QueryRequest(ddf.catalog.operation.QueryRequest) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) FederationException(ddf.catalog.federation.FederationException) ProcessingDetailsImpl(ddf.catalog.operation.impl.ProcessingDetailsImpl) QueryResponse(ddf.catalog.operation.QueryResponse) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl)

Example 3 with ProcessingDetailsImpl

use of ddf.catalog.operation.impl.ProcessingDetailsImpl in project ddf by codice.

the class QueryMonitorPluginImpl method process.

/**
     * Method that is implemented for {@link PostFederatedQueryPlugin}. Uses the given {@link QueryResponse} information
     * to remove the {@link ActiveSearch} from the {@link ActiveSearch} {@link Map}.
     *
     * @param input {@link QueryResponse} that corresponds to response from the source that was queried
     *              by the user's original {@link QueryRequest}
     * @return {@link QueryResponse} that was given as a parameter
     */
@Override
public QueryResponse process(QueryResponse input) throws PluginExecutionException, StopProcessingException {
    if (!removeSearchAfterComplete) {
        LOGGER.debug("Not removing active search from map due to catalog:removeSearchAfterComplete false. To enable removing searches as searches finish, use command catalog:removesearchaftercomplete true.");
        return input;
    }
    if (input == null) {
        LOGGER.debug("Cannot remove ActiveSearch from the ActiveSearch Map. QueryResponse received in QueryMonitorPluginImpl was null.");
        return null;
    }
    if (!removeActiveSearch((UUID) input.getRequest().getPropertyValue(SEARCH_ID))) {
        QueryResponseImpl queryResponse = new QueryResponseImpl(input.getRequest(), new ArrayList<>(), 0);
        queryResponse.closeResultQueue();
        Set<ProcessingDetails> processingDetails = Collections.singleton(new ProcessingDetailsImpl(QueryMonitorPlugin.class.getCanonicalName(), new StopProcessingException("Query was cancelled by administrator")));
        queryResponse.setProcessingDetails(processingDetails);
        return queryResponse;
    }
    return input;
}
Also used : ProcessingDetails(ddf.catalog.operation.ProcessingDetails) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) StopProcessingException(ddf.catalog.plugin.StopProcessingException) UUID(java.util.UUID) ProcessingDetailsImpl(ddf.catalog.operation.impl.ProcessingDetailsImpl)

Example 4 with ProcessingDetailsImpl

use of ddf.catalog.operation.impl.ProcessingDetailsImpl in project ddf by codice.

the class SortedQueryMonitor method timeoutRemainingSources.

private void timeoutRemainingSources(Set<ProcessingDetails> processingDetails) {
    for (QueryRequest expiredSource : futures.values()) {
        if (expiredSource != null) {
            String sourceId = getSourceIdFromRequest(expiredSource);
            LOGGER.info("Search timed out for {}", sourceId);
            processingDetails.add(new ProcessingDetailsImpl(sourceId, new TimeoutException()));
        }
    }
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) ProcessingDetailsImpl(ddf.catalog.operation.impl.ProcessingDetailsImpl) TimeoutException(java.util.concurrent.TimeoutException)

Example 5 with ProcessingDetailsImpl

use of ddf.catalog.operation.impl.ProcessingDetailsImpl in project ddf by codice.

the class ProcessingDetailsImplTest method testInequalityOfWarnings.

@Test
public void testInequalityOfWarnings() {
    String sourceId = "test source";
    Exception exception = new UnsupportedQueryException("We do not support this query");
    List<String> warning = Collections.singletonList("warning");
    List<String> differentWarning = Collections.singletonList("different warning");
    ProcessingDetails processingDetails = new ProcessingDetailsImpl(sourceId, exception, warning);
    ProcessingDetails processingDetailsWithDifferentWarnings = new ProcessingDetailsImpl(sourceId, exception, differentWarning);
    assertThat(processingDetails, is(not(processingDetailsWithDifferentWarnings)));
}
Also used : UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ProcessingDetailsImpl(ddf.catalog.operation.impl.ProcessingDetailsImpl) Test(org.junit.Test)

Aggregations

ProcessingDetailsImpl (ddf.catalog.operation.impl.ProcessingDetailsImpl)37 Test (org.junit.Test)19 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)18 ProcessingDetails (ddf.catalog.operation.ProcessingDetails)13 QueryResponseImpl (ddf.catalog.operation.impl.QueryResponseImpl)8 IngestException (ddf.catalog.source.IngestException)8 HashSet (java.util.HashSet)8 QueryRequest (ddf.catalog.operation.QueryRequest)7 SourceResponse (ddf.catalog.operation.SourceResponse)6 Serializable (java.io.Serializable)6 HashMap (java.util.HashMap)6 Tag (io.micrometer.core.instrument.Tag)5 ArrayList (java.util.ArrayList)5 Metacard (ddf.catalog.data.Metacard)4 QueryResponse (ddf.catalog.operation.QueryResponse)4 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)4 CatalogStore (ddf.catalog.source.CatalogStore)3 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)3 ExecutionException (java.util.concurrent.ExecutionException)3 TimeoutException (java.util.concurrent.TimeoutException)3