use of org.codice.ddf.commands.catalog.facade.CatalogFacade 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;
}
use of org.codice.ddf.commands.catalog.facade.CatalogFacade in project ddf by codice.
the class DumpCommand method executeWithSubject.
@Override
protected final Object executeWithSubject() throws Exception {
if (signer == null) {
signer = new DigitalSignature(security);
}
if (FilenameUtils.getExtension(dirPath).equals("") && !dirPath.endsWith(File.separator)) {
dirPath += File.separator;
}
final File dumpDir = new File(dirPath);
if (!dumpDir.exists()) {
printErrorMessage("Directory [" + dirPath + "] must exist.");
console.println("If the directory does indeed exist, try putting the path in quotes.");
return null;
}
if (!dumpDir.isDirectory()) {
printErrorMessage("Path [" + dirPath + "] must be a directory.");
return null;
}
if (!SERIALIZED_OBJECT_ID.matches(transformerId)) {
transformers = getTransformers();
if (transformers == null) {
console.println(transformerId + " is an invalid metacard transformer.");
return null;
}
}
if (StringUtils.isNotBlank(zipFileName) && new File(dirPath + zipFileName).exists()) {
console.println("Cannot dump Catalog. Zip file " + zipFileName + " already exists.");
return null;
}
if (StringUtils.isNotBlank(zipFileName) && !zipFileName.endsWith(".zip")) {
zipFileName = zipFileName + ".zip";
}
securityLogger.audit("Called catalog:dump command with path : {}", dirPath);
CatalogFacade catalog = getCatalog();
SortBy sort = new SortByImpl(Core.ID, SortOrder.ASCENDING);
QueryImpl query = new QueryImpl(getFilter());
query.setRequestsTotalResultsCount(true);
query.setPageSize(pageSize);
query.setSortBy(sort);
final AtomicLong resultCount = new AtomicLong(0);
long start = System.currentTimeMillis();
BlockingQueue<Runnable> blockingQueue = new ArrayBlockingQueue<>(multithreaded);
RejectedExecutionHandler rejectedExecutionHandler = new ThreadPoolExecutor.CallerRunsPolicy();
final ExecutorService executorService = new ThreadPoolExecutor(multithreaded, multithreaded, 0L, TimeUnit.MILLISECONDS, blockingQueue, StandardThreadFactoryBuilder.newThreadFactory("dumpCommandThread"), rejectedExecutionHandler);
QueryRequest queryRequest = new QueryRequestImpl(query);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Hits for Search: {}", catalog.query(queryRequest).getHits());
}
if (StringUtils.isNotBlank(zipFileName)) {
File outputFile = new File(dirPath + zipFileName);
createZip(catalog, queryRequest, outputFile, resultCount);
String alias = AccessController.doPrivileged((PrivilegedAction<String>) () -> System.getProperty(SystemBaseUrl.EXTERNAL_HOST));
String password = AccessController.doPrivileged((PrivilegedAction<String>) () -> System.getProperty("javax.net.ssl.keyStorePassword"));
try (InputStream inputStream = new FileInputStream(outputFile)) {
byte[] signature = signer.createDigitalSignature(inputStream, alias, password);
if (signature != null) {
String epoch = Long.toString(Instant.now().getEpochSecond());
String signatureFilepath = String.format("%sdump_%s.sig", dirPath, epoch);
FileUtils.writeByteArrayToFile(new File(signatureFilepath), signature);
}
}
} else {
ResultIterable.resultIterable(catalog::query, queryRequest).stream().map(Collections::singletonList).map(result -> new SourceResponseImpl(queryRequest, result)).forEach(response -> handleResult(response, executorService, dumpDir, resultCount));
}
executorService.shutdown();
boolean interrupted = false;
try {
while (!executorService.isTerminated()) {
try {
TimeUnit.MILLISECONDS.sleep(100);
} catch (InterruptedException e) {
interrupted = true;
}
}
} finally {
if (interrupted) {
Thread.currentThread().interrupt();
}
}
long end = System.currentTimeMillis();
String elapsedTime = timeFormatter.print(new Period(start, end).withMillis(0));
console.printf(" %d file(s) dumped in %s\t%n", resultCount.get(), elapsedTime);
LOGGER.debug("{} file(s) dumped in {}", resultCount.get(), elapsedTime);
console.println();
securityLogger.audit("Exported {} files to {}", resultCount.get(), dirPath);
return null;
}
use of org.codice.ddf.commands.catalog.facade.CatalogFacade in project ddf by codice.
the class DescribeCommand method executeWithSubject.
@Override
protected Object executeWithSubject() throws Exception {
CatalogFacade catalog = getCatalog();
console.printf(FORMAT_STR, "title", catalog.getTitle());
console.printf(FORMAT_STR, "description", catalog.getDescription());
console.printf(FORMAT_STR, "id", catalog.getId());
console.printf(FORMAT_STR, "version", catalog.getVersion());
return null;
}
Aggregations