Search in sources :

Example 26 with CatalogProvider

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

the class MigrateCommand method executeWithSubject.

@Override
protected Object executeWithSubject() throws Exception {
    final List<CatalogProvider> providers = getCatalogProviders();
    if (listProviders) {
        if (providers.size() == 0) {
            console.println("There are no available Providers.");
            return null;
        }
        console.println("Available Providers:");
        providers.stream().map(p -> p.getClass().getSimpleName()).forEach(id -> console.println("\t" + id));
        return null;
    }
    if (batchSize > MAX_BATCH_SIZE || batchSize < 1) {
        console.println("Batch Size must be between 1 and " + MAX_BATCH_SIZE + ".");
        return null;
    }
    if (providers.isEmpty() || providers.size() < 2) {
        console.println("Not enough CatalogProviders installed to migrate.");
        return null;
    }
    final CatalogProvider fromProvider = promptForProvider("FROM", fromProviderId, providers);
    if (fromProvider == null) {
        console.println("Invalid \"FROM\" Provider id.");
        return null;
    }
    console.println("FROM Provider ID: " + fromProvider.getClass().getSimpleName());
    final CatalogProvider toProvider = promptForProvider("TO", toProviderId, providers);
    if (toProvider == null) {
        console.println("Invalid \"TO\" Provider id.");
        return null;
    }
    console.println("TO Provider ID: " + toProvider.getClass().getSimpleName());
    CatalogFacade queryProvider = new Provider(fromProvider);
    CatalogFacade ingestProvider = new Provider(toProvider);
    start = System.currentTimeMillis();
    console.println("Starting migration.");
    duplicateInBatches(queryProvider, ingestProvider, getFilter());
    console.println();
    long end = System.currentTimeMillis();
    String completed = String.format(" %d record(s) migrated; %d record(s) failed; completed in %3.3f seconds.", ingestedCount.get(), failedCount.get(), (end - start) / MS_PER_SECOND);
    LOGGER.debug("Migration Complete: {}", completed);
    console.println(completed);
    return null;
}
Also used : QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) StringUtils(org.apache.commons.lang.StringUtils) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) LoggerFactory(org.slf4j.LoggerFactory) ServiceComparator(ddf.catalog.util.impl.ServiceComparator) ArrayList(java.util.ArrayList) Command(org.apache.karaf.shell.api.action.Command) Metacard(ddf.catalog.data.Metacard) Map(java.util.Map) QueryRequest(ddf.catalog.operation.QueryRequest) SortByImpl(ddf.catalog.filter.impl.SortByImpl) SourceProcessingDetails(ddf.catalog.operation.SourceProcessingDetails) SortOrder(org.opengis.filter.sort.SortOrder) ServiceReference(org.osgi.framework.ServiceReference) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Logger(org.slf4j.Logger) IOException(java.io.IOException) FederationException(ddf.catalog.federation.FederationException) Collectors(java.util.stream.Collectors) Provider(org.codice.ddf.commands.catalog.facade.Provider) List(java.util.List) SourceResponse(ddf.catalog.operation.SourceResponse) TreeMap(java.util.TreeMap) CatalogProvider(ddf.catalog.source.CatalogProvider) Service(org.apache.karaf.shell.api.action.lifecycle.Service) CatalogFacade(org.codice.ddf.commands.catalog.facade.CatalogFacade) ServiceTracker(org.osgi.util.tracker.ServiceTracker) Filter(org.opengis.filter.Filter) Option(org.apache.karaf.shell.api.action.Option) CatalogProvider(ddf.catalog.source.CatalogProvider) CatalogFacade(org.codice.ddf.commands.catalog.facade.CatalogFacade) Provider(org.codice.ddf.commands.catalog.facade.Provider) CatalogProvider(ddf.catalog.source.CatalogProvider)

Example 27 with CatalogProvider

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

the class CachingFederationStrategy method sourceFederate.

private QueryResponse sourceFederate(List<Source> sources, final QueryRequest queryRequest) {
    if (LOGGER.isDebugEnabled()) {
        for (Source source : sources) {
            if (source != null) {
                LOGGER.debug("source to query: {}", source.getId());
            }
        }
    }
    Query originalQuery = queryRequest.getQuery();
    int offset = originalQuery.getStartIndex();
    final int pageSize = originalQuery.getPageSize();
    // limit offset to max value
    if (offset > this.maxStartIndex) {
        offset = this.maxStartIndex;
    }
    final QueryResponseImpl queryResponseQueue = new QueryResponseImpl(queryRequest, null);
    Map<Future<SourceResponse>, QueryRequest> futures = new HashMap<>();
    Query modifiedQuery = getModifiedQuery(originalQuery, sources.size(), offset, pageSize);
    QueryRequest modifiedQueryRequest = new QueryRequestImpl(modifiedQuery, queryRequest.isEnterprise(), queryRequest.getSourceIds(), queryRequest.getProperties());
    CompletionService<SourceResponse> queryCompletion = new ExecutorCompletionService<>(queryExecutorService);
    // Do NOT call source.isAvailable() when checking sources
    for (final Source source : sources) {
        if (source != null) {
            if (!futuresContainsSource(source, futures)) {
                LOGGER.debug("running query on source: {}", source.getId());
                QueryRequest sourceQueryRequest = new QueryRequestImpl(modifiedQuery, queryRequest.isEnterprise(), Collections.singleton(source.getId()), new HashMap<>(queryRequest.getProperties()));
                try {
                    for (PreFederatedQueryPlugin service : preQuery) {
                        try {
                            sourceQueryRequest = service.process(source, sourceQueryRequest);
                        } catch (PluginExecutionException e) {
                            LOGGER.info("Error executing PreFederatedQueryPlugin", e);
                        }
                    }
                } catch (StopProcessingException e) {
                    LOGGER.info("Plugin stopped processing", e);
                }
                if (source instanceof CatalogProvider && SystemInfo.getSiteName().equals(source.getId())) {
                    // TODO RAP 12 Jul 16: DDF-2294 - Extract into a new PreFederatedQueryPlugin
                    sourceQueryRequest = validationQueryFactory.getQueryRequestWithValidationFilter(sourceQueryRequest, showErrors, showWarnings);
                }
                futures.put(queryCompletion.submit(new CallableSourceResponse(source, sourceQueryRequest)), sourceQueryRequest);
            } else {
                LOGGER.info("Duplicate source found with name {}. Ignoring second one.", source.getId());
            }
        }
    }
    QueryResponseImpl offsetResults = null;
    // OffsetResultHandler does.
    if (offset > 1 && sources.size() > 1) {
        offsetResults = new QueryResponseImpl(queryRequest, null);
        queryExecutorService.submit(new OffsetResultHandler(queryResponseQueue, offsetResults, pageSize, offset));
    }
    queryExecutorService.submit(sortedQueryMonitorFactory.createMonitor(queryCompletion, futures, queryResponseQueue, modifiedQueryRequest, postQuery));
    QueryResponse queryResponse;
    if (offset > 1 && sources.size() > 1) {
        queryResponse = offsetResults;
        LOGGER.debug("returning offsetResults");
    } else {
        queryResponse = queryResponseQueue;
        LOGGER.debug("returning returnResults: {}", queryResponse);
    }
    LOGGER.debug("returning Query Results: {}", queryResponse);
    return queryResponse;
}
Also used : Query(ddf.catalog.operation.Query) QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponse(ddf.catalog.operation.SourceResponse) PreFederatedQueryPlugin(ddf.catalog.plugin.PreFederatedQueryPlugin) HashMap(java.util.HashMap) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) StopProcessingException(ddf.catalog.plugin.StopProcessingException) Source(ddf.catalog.source.Source) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) CatalogProvider(ddf.catalog.source.CatalogProvider) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) Future(java.util.concurrent.Future) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException)

Example 28 with CatalogProvider

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

the class MetacardValidityFilterPluginTest method mockCatalogProvider.

private static CatalogProvider mockCatalogProvider(String id) {
    CatalogProvider localSource = mock(CatalogProvider.class);
    when(localSource.getId()).thenReturn(id);
    return localSource;
}
Also used : CatalogProvider(ddf.catalog.source.CatalogProvider)

Example 29 with CatalogProvider

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

the class RemoteSolrCatalogProviderTest method testDescribableProperties.

@Test
public void testDescribableProperties() {
    CatalogProvider provider = new MockedRemoteSolrCatalogProvider(mock(SolrClient.class));
    assertNotNull(provider.getTitle());
    assertNotNull(provider.getDescription());
    assertNotNull(provider.getOrganization());
    assertNotNull(provider.getVersion());
}
Also used : CatalogProvider(ddf.catalog.source.CatalogProvider) SolrClient(org.codice.solr.client.solrj.SolrClient) Test(org.junit.Test)

Example 30 with CatalogProvider

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

the class RemoteSolrCatalogProviderTest method testId.

@Test
public void testId() {
    CatalogProvider provider = new MockedRemoteSolrCatalogProvider(mock(SolrClient.class));
    provider.maskId("myId");
    assertEquals("myId", provider.getId());
}
Also used : CatalogProvider(ddf.catalog.source.CatalogProvider) SolrClient(org.codice.solr.client.solrj.SolrClient) Test(org.junit.Test)

Aggregations

CatalogProvider (ddf.catalog.source.CatalogProvider)41 Test (org.junit.Test)26 QueryRequest (ddf.catalog.operation.QueryRequest)13 ArrayList (java.util.ArrayList)9 Result (ddf.catalog.data.Result)8 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)8 FederatedSource (ddf.catalog.source.FederatedSource)8 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)8 Metacard (ddf.catalog.data.Metacard)7 QueryResponse (ddf.catalog.operation.QueryResponse)7 CatalogFramework (ddf.catalog.CatalogFramework)6 GeotoolsFilterBuilder (ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder)6 Source (ddf.catalog.source.Source)6 ByteSource (com.google.common.io.ByteSource)5 FederationStrategy (ddf.catalog.federation.FederationStrategy)5 Query (ddf.catalog.operation.Query)5 QueryImpl (ddf.catalog.operation.impl.QueryImpl)5 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)4 FederationException (ddf.catalog.federation.FederationException)4 QueryOperations (ddf.catalog.impl.operations.QueryOperations)4