Search in sources :

Example 1 with UnsupportedQueryException

use of ddf.catalog.source.UnsupportedQueryException in project ddf by codice.

the class MockFederationStrategy method federate.

@Override
public QueryResponse federate(List<Source> sources, QueryRequest query) throws FederationException {
    LOGGER.debug("entry");
    QueryResponseImpl resp = new QueryResponseImpl(query);
    for (Source src : sources) {
        try {
            resp.addResults(src.query(query).getResults(), false);
        } catch (UnsupportedQueryException e) {
            LOGGER.error("Doh!", e);
        }
    }
    resp.closeResultQueue();
    List<Result> results = resp.getResults();
    resp.setHits(results.size());
    LOGGER.debug("exit");
    return resp;
}
Also used : QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) Source(ddf.catalog.source.Source) Result(ddf.catalog.data.Result)

Example 2 with UnsupportedQueryException

use of ddf.catalog.source.UnsupportedQueryException in project ddf by codice.

the class ExceptionsTest method testUnsupportedQueryException.

@Test
public void testUnsupportedQueryException() {
    UnsupportedQueryException uqe = new UnsupportedQueryException();
    assertNotNull(uqe);
    uqe = new UnsupportedQueryException(msg);
    assertEquals(uqe.getMessage(), msg);
    uqe = new UnsupportedQueryException(testCause);
    assertEquals(uqe.getCause(), testCause);
    uqe = new UnsupportedQueryException(msg, testCause);
    assertEquals(uqe.getMessage(), msg);
    assertEquals(uqe.getCause(), testCause);
}
Also used : UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) Test(org.junit.Test)

Example 3 with UnsupportedQueryException

use of ddf.catalog.source.UnsupportedQueryException in project ddf by codice.

the class RemoveAllCommand method executeRemoveAllFromStore.

private Object executeRemoveAllFromStore() throws Exception {
    CatalogFacade catalog = getCatalog();
    QueryRequest firstQuery = getIntendedQuery(filterBuilder, true);
    QueryRequest subsequentQuery = getIntendedQuery(filterBuilder, false);
    long totalAmountDeleted = 0;
    long start = System.currentTimeMillis();
    SourceResponse response;
    try {
        response = catalog.query(firstQuery);
    } catch (UnsupportedQueryException e) {
        firstQuery = getAlternateQuery(filterBuilder, true);
        subsequentQuery = getAlternateQuery(filterBuilder, false);
        response = catalog.query(firstQuery);
    }
    if (response == null) {
        printErrorMessage("No response from Catalog.");
        return null;
    }
    if (needsAlternateQueryAndResponse(response)) {
        firstQuery = getAlternateQuery(filterBuilder, true);
        subsequentQuery = getAlternateQuery(filterBuilder, false);
        response = catalog.query(firstQuery);
    }
    String totalAmount = getTotalAmount(response.getHits());
    while (response.getResults().size() > 0) {
        // Add metacard ids to string array
        List<String> ids = response.getResults().stream().filter(Objects::nonNull).map(Result::getMetacard).filter(Objects::nonNull).map(Metacard::getId).collect(Collectors.toList());
        // Delete the records
        DeleteRequestImpl request = new DeleteRequestImpl(ids.toArray(new String[ids.size()]));
        DeleteResponse deleteResponse = catalog.delete(request);
        int amountDeleted = deleteResponse.getDeletedMetacards().size();
        totalAmountDeleted += amountDeleted;
        console.print(String.format(PROGRESS_FORMAT, totalAmountDeleted, totalAmount));
        console.flush();
        // Break out if there are no more records to delete
        if (amountDeleted < batchSize || batchSize < 1) {
            break;
        }
        // Re-query when necessary
        response = catalog.query(subsequentQuery);
    }
    long end = System.currentTimeMillis();
    String info = String.format(" %d file(s) removed in %3.3f seconds%n", totalAmountDeleted, (end - start) / MS_PER_SECOND);
    LOGGER.info(info);
    LOGGER.info(totalAmountDeleted + " files removed using cache:removeAll command");
    console.println();
    console.print(info);
    return null;
}
Also used : DeleteResponse(ddf.catalog.operation.DeleteResponse) QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponse(ddf.catalog.operation.SourceResponse) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) Objects(java.util.Objects) CatalogFacade(org.codice.ddf.commands.catalog.facade.CatalogFacade)

Example 4 with UnsupportedQueryException

use of ddf.catalog.source.UnsupportedQueryException in project ddf by codice.

the class MigrateCommand method query.

@Override
protected SourceResponse query(CatalogFacade framework, Filter filter, int startIndex, long querySize) {
    QueryImpl query = new QueryImpl(filter);
    query.setRequestsTotalResultsCount(true);
    query.setPageSize((int) querySize);
    query.setSortBy(new SortByImpl(Metacard.MODIFIED, SortOrder.DESCENDING));
    QueryRequest queryRequest = new QueryRequestImpl(query);
    query.setStartIndex(startIndex);
    SourceResponse response;
    try {
        LOGGER.debug("Querying with startIndex: {}", startIndex);
        response = framework.query(queryRequest);
    } catch (UnsupportedQueryException | SourceUnavailableException | FederationException e) {
        printErrorMessage(String.format("Received error from Frameworks: %s%n", e.getMessage()));
        return null;
    }
    if (response.getProcessingDetails() != null && !response.getProcessingDetails().isEmpty()) {
        for (SourceProcessingDetails details : response.getProcessingDetails()) {
            LOGGER.debug("Got Issues: {}", details.getWarnings());
        }
        return null;
    }
    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) SortByImpl(ddf.catalog.filter.impl.SortByImpl) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) FederationException(ddf.catalog.federation.FederationException) SourceProcessingDetails(ddf.catalog.operation.SourceProcessingDetails)

Example 5 with UnsupportedQueryException

use of ddf.catalog.source.UnsupportedQueryException in project ddf by codice.

the class FederationStrategyTest method testQueryTimeout.

/**
     * Tests that the framework properly times out using the default federation strategy.
     */
@Test
public void testQueryTimeout() throws Exception {
    long queryDelay = 100;
    UuidGenerator uuidGenerator = mock(UuidGenerator.class);
    when(uuidGenerator.generateUuid()).thenReturn(UUID.randomUUID().toString());
    MockDelayProvider provider = new MockDelayProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<ContentType>(), true, new Date());
    provider.setQueryDelayMillis(queryDelay);
    // Mock register the provider in the container
    SourcePollerRunner runner = new SourcePollerRunner();
    SourcePoller poller = new SourcePoller(runner);
    runner.bind(provider);
    // Must have more than one thread or sleeps will block the monitor
    SortedFederationStrategy fedStrategy = new SortedFederationStrategy(executor, new ArrayList<>(), new ArrayList<>());
    FrameworkProperties props = new FrameworkProperties();
    props.setCatalogProviders(Collections.singletonList(provider));
    props.setFederationStrategy(fedStrategy);
    props.setSourcePoller(poller);
    props.setQueryResponsePostProcessor(mock(QueryResponsePostProcessor.class));
    props.setFilterBuilder(new GeotoolsFilterBuilder());
    props.setDefaultAttributeValueRegistry(new DefaultAttributeValueRegistryImpl());
    OperationsSecuritySupport opsSecurity = new OperationsSecuritySupport();
    MetacardFactory metacardFactory = new MetacardFactory(props.getMimeTypeToTransformerMapper(), uuidGenerator);
    OperationsMetacardSupport opsMetacard = new OperationsMetacardSupport(props, metacardFactory);
    Historian historian = new Historian();
    historian.setHistoryEnabled(false);
    SourceOperations sourceOperations = new SourceOperations(props);
    QueryOperations queryOperations = new QueryOperations(props, sourceOperations, opsSecurity, opsMetacard);
    OperationsStorageSupport opsStorage = new OperationsStorageSupport(sourceOperations, queryOperations);
    OperationsCatalogStoreSupport opsCatStore = new OperationsCatalogStoreSupport(props, sourceOperations);
    CreateOperations createOperations = new CreateOperations(props, queryOperations, sourceOperations, opsSecurity, opsMetacard, opsCatStore, opsStorage);
    UpdateOperations updateOperations = new UpdateOperations(props, queryOperations, sourceOperations, opsSecurity, opsMetacard, opsCatStore, opsStorage);
    DeleteOperations deleteOperations = new DeleteOperations(props, queryOperations, sourceOperations, opsSecurity, opsMetacard);
    opsStorage.setHistorian(historian);
    updateOperations.setHistorian(historian);
    deleteOperations.setHistorian(historian);
    deleteOperations.setOpsCatStoreSupport(opsCatStore);
    CatalogFrameworkImpl framework = new CatalogFrameworkImpl(createOperations, updateOperations, deleteOperations, queryOperations, null, null, null);
    sourceOperations.bind(provider);
    List<Metacard> metacards = new ArrayList<Metacard>();
    MetacardImpl newCard = new MetacardImpl();
    newCard.setId(null);
    metacards.add(newCard);
    CreateResponse createResponse = null;
    try {
        try {
            createResponse = framework.create(new CreateRequestImpl(metacards, null));
        } catch (SourceUnavailableException e) {
            long timeout = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(10);
            //this is a hack because the unit test is flaky and should be removed once a better test is possible
            while (System.currentTimeMillis() < timeout) {
                Thread.sleep(1000);
                try {
                    createResponse = framework.create(new CreateRequestImpl(metacards, null));
                    break;
                } catch (SourceUnavailableException e1) {
                //ignore
                }
            }
        }
        if (createResponse == null) {
            fail();
        }
    } catch (IngestException e) {
        fail();
    }
    assertEquals(createResponse.getCreatedMetacards().size(), provider.size());
    for (Metacard curCard : createResponse.getCreatedMetacards()) {
        assertNotNull(curCard.getId());
    }
    QueryImpl query = new QueryImpl(filterFactory.equals(filterFactory.property(Metacard.ID), filterFactory.literal(createResponse.getCreatedMetacards().get(0).getId())));
    query.setTimeoutMillis(SHORT_TIMEOUT);
    query.setSortBy(new FilterFactoryImpl().sort(Result.RELEVANCE, SortOrder.ASCENDING));
    QueryRequest fedQueryRequest = new QueryRequestImpl(query);
    try {
        QueryResponse response = framework.query(fedQueryRequest);
        assertEquals("Timeout should happen before results return", 0, response.getHits());
    } catch (UnsupportedQueryException e) {
        fail();
    } catch (FederationException e) {
        LOGGER.error("Unexpected federation exception during test", e);
        fail();
    }
}
Also used : OperationsCatalogStoreSupport(ddf.catalog.impl.operations.OperationsCatalogStoreSupport) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) UuidGenerator(org.codice.ddf.platform.util.uuidgenerator.UuidGenerator) ContentType(ddf.catalog.data.ContentType) CreateResponse(ddf.catalog.operation.CreateResponse) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ArrayList(java.util.ArrayList) DeleteOperations(ddf.catalog.impl.operations.DeleteOperations) QueryResponsePostProcessor(ddf.catalog.impl.QueryResponsePostProcessor) SourcePoller(ddf.catalog.util.impl.SourcePoller) MetacardFactory(ddf.catalog.impl.operations.MetacardFactory) QueryImpl(ddf.catalog.operation.impl.QueryImpl) OperationsStorageSupport(ddf.catalog.impl.operations.OperationsStorageSupport) SourcePollerRunner(ddf.catalog.util.impl.SourcePollerRunner) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) IngestException(ddf.catalog.source.IngestException) Historian(ddf.catalog.history.Historian) FrameworkProperties(ddf.catalog.impl.FrameworkProperties) DefaultAttributeValueRegistryImpl(ddf.catalog.data.defaultvalues.DefaultAttributeValueRegistryImpl) MockDelayProvider(ddf.catalog.impl.MockDelayProvider) SourceOperations(ddf.catalog.impl.operations.SourceOperations) QueryRequest(ddf.catalog.operation.QueryRequest) FederationException(ddf.catalog.federation.FederationException) Date(java.util.Date) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) CatalogFrameworkImpl(ddf.catalog.impl.CatalogFrameworkImpl) Metacard(ddf.catalog.data.Metacard) QueryOperations(ddf.catalog.impl.operations.QueryOperations) UpdateOperations(ddf.catalog.impl.operations.UpdateOperations) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) OperationsSecuritySupport(ddf.catalog.impl.operations.OperationsSecuritySupport) CreateOperations(ddf.catalog.impl.operations.CreateOperations) OperationsMetacardSupport(ddf.catalog.impl.operations.OperationsMetacardSupport) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)85 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)34 FederationException (ddf.catalog.federation.FederationException)31 QueryRequest (ddf.catalog.operation.QueryRequest)31 Metacard (ddf.catalog.data.Metacard)28 QueryImpl (ddf.catalog.operation.impl.QueryImpl)27 Filter (org.opengis.filter.Filter)27 ArrayList (java.util.ArrayList)26 Result (ddf.catalog.data.Result)25 QueryResponse (ddf.catalog.operation.QueryResponse)25 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)25 Test (org.junit.Test)21 SourceResponse (ddf.catalog.operation.SourceResponse)16 IngestException (ddf.catalog.source.IngestException)15 IOException (java.io.IOException)15 Query (ddf.catalog.operation.Query)12 CreateResponse (ddf.catalog.operation.CreateResponse)10 GeotoolsFilterAdapterImpl (ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl)9 ResourceNotFoundException (ddf.catalog.resource.ResourceNotFoundException)9 Subject (ddf.security.Subject)9