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;
}
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;
}
Aggregations