Search in sources :

Example 6 with ExportMigrationException

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());
    }
}
Also used : ExportMigrationException(org.codice.ddf.migration.ExportMigrationException) IOException(java.io.IOException) File(java.io.File)

Example 7 with ExportMigrationException

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);
}
Also used : Path(java.nio.file.Path) ExportMigrationException(org.codice.ddf.migration.ExportMigrationException)

Example 8 with ExportMigrationException

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);
    }
}
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 9 with ExportMigrationException

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

ExportMigrationException (org.codice.ddf.migration.ExportMigrationException)9 IOException (java.io.IOException)5 Result (ddf.catalog.data.Result)2 File (java.io.File)2 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 MigrationException (org.codice.ddf.migration.MigrationException)2 MigrationWarning (org.codice.ddf.migration.MigrationWarning)2 UnexpectedMigrationException (org.codice.ddf.migration.UnexpectedMigrationException)2 FederationException (ddf.catalog.federation.FederationException)1 QueryRequest (ddf.catalog.operation.QueryRequest)1 SourceResponse (ddf.catalog.operation.SourceResponse)1 QueryImpl (ddf.catalog.operation.impl.QueryImpl)1 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)1 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)1 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)1 Serializable (java.io.Serializable)1 NotNull (javax.validation.constraints.NotNull)1 ConfigurationFileException (org.codice.ddf.configuration.status.ConfigurationFileException)1 MigrationMetadata (org.codice.ddf.migration.MigrationMetadata)1