Search in sources :

Example 1 with Provider

use of org.codice.ddf.commands.catalog.facade.Provider in project ddf by codice.

the class MigrateCommand method promptForProvider.

private CatalogProvider promptForProvider(String whichProvider, String id, List<CatalogProvider> providers) throws IOException {
    List<String> providersIdList = providers.stream().map(p -> p.getClass().getSimpleName()).collect(Collectors.toList());
    while (true) {
        if (StringUtils.isBlank(id) || !providersIdList.contains(id)) {
            console.println("Please enter the Source ID of the \"" + whichProvider + "\" Provider:");
        } else {
            break;
        }
        id = getInput(whichProvider + " Provider ID: ");
    }
    final String providerId = id;
    final CatalogProvider provider = providers.stream().filter(p -> p.getClass().getSimpleName().equals(providerId)).findFirst().orElse(null);
    return provider;
}
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)

Example 2 with Provider

use of org.codice.ddf.commands.catalog.facade.Provider 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)

Aggregations

Metacard (ddf.catalog.data.Metacard)2 FederationException (ddf.catalog.federation.FederationException)2 SortByImpl (ddf.catalog.filter.impl.SortByImpl)2 QueryRequest (ddf.catalog.operation.QueryRequest)2 SourceProcessingDetails (ddf.catalog.operation.SourceProcessingDetails)2 SourceResponse (ddf.catalog.operation.SourceResponse)2 QueryImpl (ddf.catalog.operation.impl.QueryImpl)2 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)2 CatalogProvider (ddf.catalog.source.CatalogProvider)2 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)2 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)2 ServiceComparator (ddf.catalog.util.impl.ServiceComparator)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 Collectors (java.util.stream.Collectors)2 StringUtils (org.apache.commons.lang.StringUtils)2 Command (org.apache.karaf.shell.api.action.Command)2