use of org.codice.ddf.migration.ExportMigrationException in project ddf by codice.
the class MigrationFileWriter method createExportDirectory.
/**
* Creates the directory for the catalog export if it doesn't exist.
* <p>
* If the directory does exist, work based on the assumption it was cleaned by the parent
* process in the management logic of inport and export. There is no point to delegate
* low level directory operations to each and every migratable when they can be abstracted
* into the base logic.
*
* @param exportPath The path representing the directory to create.
* @throws MigrationException thrown if the export directory doesn't exist and could not be created
*/
public void createExportDirectory(Path exportPath) throws MigrationException {
try {
final File exportDir = exportPath.toFile();
FileUtils.forceMkdir(exportDir);
} catch (IOException e) {
LOGGER.info("IO Exception during FileUtils.forceMkdir", e.getMessage(), e);
throw new ExportMigrationException(e.getMessage());
}
}
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);
}
use of org.codice.ddf.migration.ExportMigrationException in project ddf by codice.
the class ConfigurationAdminMigration method export.
public void export(@NotNull Path exportDirectory) throws MigrationException, IOException {
notNull(exportDirectory, "exportDirectory cannot be null");
Path etcDirectory = createEtcDirectory(exportDirectory);
try {
Configuration[] configurations = configurationAdmin.listConfigurations(FILTER);
if (configurations != null) {
for (Configuration configuration : configurations) {
Path exportedFilePath = etcDirectory.resolve(configuration.getPid() + configurationFileExtension);
try {
configurationFileFactory.createConfigurationFile(configuration.getProperties()).exportConfig(exportedFilePath.toString());
} catch (ConfigurationFileException e) {
LOGGER.info("Could not create configuration file {} for configuration {}.", exportedFilePath, configuration.getPid());
throw new ExportMigrationException(e);
} catch (IOException e) {
LOGGER.info("Could not export configuration {} to {}.", configuration.getPid(), exportedFilePath);
throw new ExportMigrationException(e);
}
}
}
} catch (InvalidSyntaxException e) {
LOGGER.info("Invalid filter string {}", FILTER, e);
throw new UnexpectedMigrationException("Export failed", e);
} catch (IOException e) {
LOGGER.info("There was an issue retrieving configurations from ConfigurationAdmin: {}", e.getMessage());
throw new UnexpectedMigrationException("Export failed", e);
}
}
use of org.codice.ddf.migration.ExportMigrationException in project ddf by codice.
the class ConfigurationMigrationManager method export.
@Override
public Collection<MigrationWarning> export(@NotNull Path exportDirectory) throws MigrationException {
notNull(exportDirectory, "Export directory cannot be null");
Collection<MigrationWarning> migrationWarnings = new ArrayList<>();
try {
Files.createDirectories(exportDirectory);
configurationAdminMigration.export(exportDirectory);
migrationWarnings.addAll(exportMigratables(exportDirectory));
} catch (IOException e) {
LOGGER.info("Unable to create export directories", e);
throw new ExportMigrationException("Unable to create export directories", e);
} catch (MigrationException e) {
LOGGER.info("Export operation failed", e);
throw e;
} catch (RuntimeException e) {
LOGGER.info("Failure to export, internal error occurred", e);
throw new UnexpectedMigrationException("Export failed", e);
}
return migrationWarnings;
}
Aggregations