Search in sources :

Example 16 with MigrationWarning

use of org.codice.ddf.migration.MigrationWarning in project ddf by codice.

the class ConfigurationAdminMigration method getFailedConfigurationFiles.

public Collection<MigrationWarning> getFailedConfigurationFiles() throws IOException {
    Collection<MigrationWarning> migrationWarnings = new ArrayList<>();
    try (DirectoryStream<Path> stream = getFailedDirectoryStream()) {
        for (Path path : stream) {
            migrationWarnings.add(new MigrationWarning(path.getFileName().toString()));
            LOGGER.debug("Adding [{}] to the failed imports list.", path.toString());
        }
    }
    return migrationWarnings;
}
Also used : Path(java.nio.file.Path) MigrationWarning(org.codice.ddf.migration.MigrationWarning) ArrayList(java.util.ArrayList)

Example 17 with MigrationWarning

use of org.codice.ddf.migration.MigrationWarning 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)

Example 18 with MigrationWarning

use of org.codice.ddf.migration.MigrationWarning in project ddf by codice.

the class ConfigurationMigrationManager method exportMigratables.

private Collection<MigrationWarning> exportMigratables(Path exportDirectory) throws IOException {
    List<MigrationWarning> warnings = new LinkedList<>();
    for (ConfigurationMigratable configMigratable : configurationMigratables) {
        warnings.addAll(exportMigratable(configMigratable, exportDirectory));
    }
    for (DataMigratable dataMigratable : dataMigratables) {
        Path dataMigratableDirectory = exportDirectory.resolve(dataMigratable.getId());
        Files.createDirectories(dataMigratableDirectory);
        warnings.addAll(exportMigratable(dataMigratable, exportDirectory));
    }
    return warnings;
}
Also used : Path(java.nio.file.Path) MigrationWarning(org.codice.ddf.migration.MigrationWarning) ConfigurationMigratable(org.codice.ddf.migration.ConfigurationMigratable) DataMigratable(org.codice.ddf.migration.DataMigratable) LinkedList(java.util.LinkedList)

Example 19 with MigrationWarning

use of org.codice.ddf.migration.MigrationWarning in project ddf by codice.

the class MigratableUtil method copyFileFromJavaPropertyValue.

/**
     * Copies a file, whose path is taken from the value a Java properties file, to a destination.
     * directory. The file to copy must be a relative path under {@code ddf.home}, and its path
     * must not contain any symbolic link, otherwise the file will not be copied and a
     * {@link MigrationWarning} will be returned.
     *
     * @param propertyFilePath path to the Java properties file that contains the path to the
     *                         source file to copy
     * @param javaProperty     name of the property inside the Java properties file that contains
     *                         the path to the source file
     * @param exportDirectory  path to the destination
     * @param warnings         any warnings generated during this operation (e.g., source file
     *                         outside of {@code ddf.home}) will be added to this collection
     */
public void copyFileFromJavaPropertyValue(@NotNull Path propertyFilePath, @NotNull String javaProperty, @NotNull Path exportDirectory, @NotNull Collection<MigrationWarning> warnings) throws MigrationException {
    notNull(propertyFilePath, "Java properties file cannot be null");
    Properties properties = readPropertiesFile(ddfHome.resolve(propertyFilePath));
    String source = (String) properties.get(javaProperty);
    notEmpty(source, String.format("Source path property [%s] is invalid: [%s]", javaProperty, source));
    Path sourcePath = Paths.get(source);
    copy(sourcePath, exportDirectory, warnings, () -> isSourceMigratable(sourcePath, (reason) -> new PathMigrationWarning(propertyFilePath, javaProperty, sourcePath, reason), warnings));
}
Also used : Path(java.nio.file.Path) StringUtils(org.apache.commons.lang.StringUtils) Validate.notEmpty(org.apache.commons.lang.Validate.notEmpty) Properties(java.util.Properties) Logger(org.slf4j.Logger) Files(java.nio.file.Files) MigrationWarning(org.codice.ddf.migration.MigrationWarning) ExportMigrationException(org.codice.ddf.migration.ExportMigrationException) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) FileInputStream(java.io.FileInputStream) NotNull(javax.validation.constraints.NotNull) Function(java.util.function.Function) Validate.notNull(org.apache.commons.lang.Validate.notNull) BooleanSupplier(java.util.function.BooleanSupplier) Paths(java.nio.file.Paths) Path(java.nio.file.Path) MigrationException(org.codice.ddf.migration.MigrationException) InputStream(java.io.InputStream) Properties(java.util.Properties)

Aggregations

MigrationWarning (org.codice.ddf.migration.MigrationWarning)19 Path (java.nio.file.Path)12 Test (org.junit.Test)12 MigratableUtil (org.codice.ddf.migration.util.MigratableUtil)9 ArrayList (java.util.ArrayList)7 MigrationMetadata (org.codice.ddf.migration.MigrationMetadata)7 ExportMigrationException (org.codice.ddf.migration.ExportMigrationException)4 MigrationException (org.codice.ddf.migration.MigrationException)4 IOException (java.io.IOException)3 NotNull (javax.validation.constraints.NotNull)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 Files (java.nio.file.Files)2 Paths (java.nio.file.Paths)2 Collection (java.util.Collection)2 Properties (java.util.Properties)2 BooleanSupplier (java.util.function.BooleanSupplier)2 Function (java.util.function.Function)2 FileUtils (org.apache.commons.io.FileUtils)2