use of org.codice.ddf.migration.ExportMigrationException in project ddf by codice.
the class MetacardsMigratable method export.
/**
* Exports all the metacards currently stored in the catalog framework.
* <p>
* {@inheritDoc}
*/
@Override
@NotNull
public MigrationMetadata export(@NotNull Path exportPath) throws MigrationException {
config.setExportPath(exportPath.resolve(this.getId()));
fileWriter.createExportDirectory(config.getExportPath());
Collection<MigrationWarning> warnings = new ArrayList<>();
Map<String, Serializable> props = createMapWithNativeQueryMode();
Filter dumpFilter = filterBuilder.attribute(Metacard.ANY_TEXT).is().like().text("*");
QueryImpl exportQuery = new QueryImpl(dumpFilter);
exportQuery.setPageSize(config.getExportQueryPageSize());
exportQuery.setRequestsTotalResultsCount(false);
QueryRequest exportQueryRequest = new QueryRequestImpl(exportQuery, props);
try {
executeQueryLoop(exportQuery, exportQueryRequest);
} catch (Exception e) {
LOGGER.info("Internal error occurred when exporting catalog: {}", e);
throw new ExportMigrationException(DEFAULT_FAILURE_MESSAGE);
} finally {
cleanup();
}
return new MigrationMetadata(warnings);
}
use of org.codice.ddf.migration.ExportMigrationException in project ddf by codice.
the class MigrationTaskManager method exportMetacardQuery.
/**
* Creates a sublist from the given results and a destination file for metacards based on
* the {@link CatalogMigratableConfig} object used by this task manager. An asynchronous
* task is started for exporting the metacards and is deferred to the appropriate instance
* of {@link MigrationFileWriter} for processing.
*
* @param results The results of a catalog query that need to be exported.
* @param exportGroupCount The group or page number of the query. This value is not monitored
* or audited for repeats and is strictly for record keeping by naming
* the resulting export files appropriately.
* @throws MigrationException Thrown if one of the writing threads fails or throws an exception
* itself.
*/
public void exportMetacardQuery(final List<Result> results, long exportGroupCount) throws MigrationException {
for (int i = 0; i < results.size(); i += catalogConfig.getExportCardsPerFile()) {
final List<Result> fileResults = results.subList(i, Math.min((i + catalogConfig.getExportCardsPerFile()), results.size()));
final File exportFile = catalogConfig.getExportPath().resolve(makeFileName(exportGroupCount, i)).toFile();
Callable<Void> writerCallable = () -> {
fileWriter.writeMetacards(exportFile, fileResults);
return null;
};
ListenableFuture<Void> task = taskExecutor.submit(writerCallable);
Futures.addCallback(task, createFutureCallback());
if (failureFlag) {
throw new ExportMigrationException("Error in file writing thread");
}
}
}
use of org.codice.ddf.migration.ExportMigrationException in project ddf by codice.
the class MigratableUtil method copyDirectory.
/**
* Recursively copies a directory to a destination directory. The directory to
* copy must be a relative path under {@code ddf.home}, and its path must not contain any
* symbolic link, otherwise the directory will not be copied and a {@link MigrationWarning}
* will be returned.
*
* @param source relative path to the directory to copy
* @param exportDirectory root directory where the file will be copied. If the file'
* relative path included any directories, those will be re-created
* under this directory.
* @param warnings any warnings generated during this operation (e.g., source file outside
* of {@code ddf.home}) will be added to this collection
* @throws MigrationException thrown if file system error prevents the directory to be copied
*/
public void copyDirectory(@NotNull Path source, @NotNull Path exportDirectory, @NotNull Collection<MigrationWarning> warnings) throws MigrationException {
notNull(source, "Source cannot be null");
notNull(exportDirectory, "Destination cannot be null");
notNull(warnings, "Warning collection cannot be null");
try {
if (isSourceMigratable(source, (reason) -> new PathMigrationWarning(source, reason), warnings)) {
FileUtils.copyDirectory(source.toFile(), exportDirectory.resolve(source).toFile());
}
} catch (IOException e) {
String message = String.format("Unable to copy [%s] to [%s].", source.toString(), exportDirectory.toString());
LOGGER.info(message, e);
throw new ExportMigrationException(message, e);
}
}
use of org.codice.ddf.migration.ExportMigrationException in project ddf by codice.
the class MigratableUtil method copy.
private void copy(Path sourceFile, Path exportDirectory, Collection<MigrationWarning> warnings, BooleanSupplier isSourceMigratable) throws MigrationException {
notNull(sourceFile, "Source file cannot be null");
notNull(exportDirectory, "Destination cannot be null");
notNull(warnings, "Warning collection cannot be null");
try {
if (isSourceMigratable.getAsBoolean()) {
FileUtils.copyFile(sourceFile.toFile(), exportDirectory.resolve(sourceFile).toFile());
}
} catch (IOException e) {
String message = String.format("Unable to copy [%s] to [%s]", sourceFile.toString(), exportDirectory.toString());
LOGGER.info(message, e);
throw new ExportMigrationException(message, e);
}
}
use of org.codice.ddf.migration.ExportMigrationException in project ddf by codice.
the class SecurityMigratable method exportCrlFile.
private void exportCrlFile(Path propertiesPath, Path exportDirectory, Collection<MigrationWarning> migrationWarnings) throws MigrationException {
LOGGER.debug("Exporting CRL from property [{}] in file [{}]...", CRL_PROP_KEY, propertiesPath.toString());
String crlPathStr = migratableUtil.getJavaPropertyValue(propertiesPath, CRL_PROP_KEY);
if (crlPathStr == null) {
return;
}
if (StringUtils.isWhitespace(crlPathStr)) {
String error = String.format("Failed to export CRL. No CRL path found in file [%s]. Property [%s] from properties file [%s] has a blank value.", propertiesPath, CRL_PROP_KEY, propertiesPath);
throw new ExportMigrationException(error);
}
Path crlPath = Paths.get(crlPathStr);
migratableUtil.copyFile(crlPath, exportDirectory, migrationWarnings);
}
Aggregations