Search in sources :

Example 1 with UnexpectedMigrationException

use of org.codice.ddf.migration.UnexpectedMigrationException 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);
    }
}
Also used : Path(java.nio.file.Path) ExportMigrationException(org.codice.ddf.migration.ExportMigrationException) Configuration(org.osgi.service.cm.Configuration) ConfigurationFileException(org.codice.ddf.configuration.status.ConfigurationFileException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) IOException(java.io.IOException) UnexpectedMigrationException(org.codice.ddf.migration.UnexpectedMigrationException)

Example 2 with UnexpectedMigrationException

use of org.codice.ddf.migration.UnexpectedMigrationException 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;
}
Also used : UnexpectedMigrationException(org.codice.ddf.migration.UnexpectedMigrationException) MigrationException(org.codice.ddf.migration.MigrationException) ExportMigrationException(org.codice.ddf.migration.ExportMigrationException) MigrationWarning(org.codice.ddf.migration.MigrationWarning) ExportMigrationException(org.codice.ddf.migration.ExportMigrationException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) UnexpectedMigrationException(org.codice.ddf.migration.UnexpectedMigrationException)

Aggregations

IOException (java.io.IOException)2 ExportMigrationException (org.codice.ddf.migration.ExportMigrationException)2 UnexpectedMigrationException (org.codice.ddf.migration.UnexpectedMigrationException)2 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 ConfigurationFileException (org.codice.ddf.configuration.status.ConfigurationFileException)1 MigrationException (org.codice.ddf.migration.MigrationException)1 MigrationWarning (org.codice.ddf.migration.MigrationWarning)1 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1 Configuration (org.osgi.service.cm.Configuration)1