Search in sources :

Example 1 with MigrationException

use of org.codice.ddf.migration.MigrationException 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);
}
Also used : MigrationWarning(org.codice.ddf.migration.MigrationWarning) Serializable(java.io.Serializable) ExportMigrationException(org.codice.ddf.migration.ExportMigrationException) QueryRequest(ddf.catalog.operation.QueryRequest) ArrayList(java.util.ArrayList) MigrationMetadata(org.codice.ddf.migration.MigrationMetadata) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) MigrationException(org.codice.ddf.migration.MigrationException) ExportMigrationException(org.codice.ddf.migration.ExportMigrationException) FederationException(ddf.catalog.federation.FederationException) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) NotNull(javax.validation.constraints.NotNull)

Example 2 with MigrationException

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

the class ExportCommandTest method testExecuteErrorOccurred.

@Test
public void testExecuteErrorOccurred() throws Exception {
    // Setup
    when(security.runWithSubjectOrElevate(any(Callable.class))).thenThrow(new InvocationTargetException(new MigrationException(MIGRATION_EXCEPTION_MESSAGE)));
    ExportCommand exportCommand = new ExportCommandUnderTest(mockConfigurationMigrationService, mockDefaultExportDirectory);
    // Perform Test
    exportCommand.execute();
    // Verify
    assertErrorMessage(MIGRATION_EXCEPTION_MESSAGE);
}
Also used : MigrationException(org.codice.ddf.migration.MigrationException) Callable(java.util.concurrent.Callable) InvocationTargetException(java.lang.reflect.InvocationTargetException) Test(org.junit.Test)

Example 3 with MigrationException

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

the class TestMigratable method exportWhenConfigurationAdminMigratorThrowsConfigurationFileException.

@Test(expected = MigrationException.class)
public void exportWhenConfigurationAdminMigratorThrowsConfigurationFileException() throws Exception {
    when(Files.createDirectories(exportPath)).thenReturn(exportPath);
    doThrow(new MigrationException("")).when(configurationAdminMigration).export(exportPath);
    ConfigurationMigrationManager configurationMigrationManager = createConfigurationMigrationManager();
    configurationMigrationManager.export(exportPath);
}
Also used : MigrationException(org.codice.ddf.migration.MigrationException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with MigrationException

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

the class TestMigratable method exportFailsWhenMigratableThrowsMigrationException.

@Test(expected = MigrationException.class)
public void exportFailsWhenMigratableThrowsMigrationException() throws Exception {
    ConfigurationMigrationManager configurationMigrationManager = createConfigurationMigrationManager();
    when(configurationMigratable.export(any(Path.class))).thenThrow(new MigrationException(""));
    when(dataMigratable.export(any(Path.class))).thenReturn(new MigrationMetadata(ImmutableList.of()));
    try {
        export(() -> configurationMigrationManager.export(exportPath));
    } finally {
        verify(configurationMigratable).export(exportPath);
        verify(dataMigratable, never()).export(any(Path.class));
    }
}
Also used : Path(java.nio.file.Path) MigrationException(org.codice.ddf.migration.MigrationException) MigrationMetadata(org.codice.ddf.migration.MigrationMetadata) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with MigrationException

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

the class MigratableUtil method copyFileFromSystemPropertyValue.

/**
     * Copies a file, whose path is taken from a {@link System} property value, 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 systemProperty  name of the {@link System} property that contains the path to the
     *                        source file
     * @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
     */
public void copyFileFromSystemPropertyValue(@NotNull String systemProperty, @NotNull Path exportDirectory, @NotNull Collection<MigrationWarning> warnings) throws MigrationException {
    String source = System.getProperty(systemProperty);
    notEmpty(source, String.format("Source path property [%s] is invalid: [%s]", systemProperty, source));
    Path sourcePath = Paths.get(source);
    copy(sourcePath, exportDirectory, warnings, () -> isSourceMigratable(sourcePath, (reason) -> new PathMigrationWarning(systemProperty, 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)

Aggregations

MigrationException (org.codice.ddf.migration.MigrationException)9 ExportMigrationException (org.codice.ddf.migration.ExportMigrationException)6 Test (org.junit.Test)5 MigrationWarning (org.codice.ddf.migration.MigrationWarning)4 IOException (java.io.IOException)3 Path (java.nio.file.Path)3 NotNull (javax.validation.constraints.NotNull)3 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 Files (java.nio.file.Files)2 Paths (java.nio.file.Paths)2 ArrayList (java.util.ArrayList)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 StringUtils (org.apache.commons.lang.StringUtils)2 Validate.notEmpty (org.apache.commons.lang.Validate.notEmpty)2 Validate.notNull (org.apache.commons.lang.Validate.notNull)2