Search in sources :

Example 1 with MigrationMetadata

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

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

the class MetacardsMigratableTest method exportWhenResultSetLargerThanExportPageSize.

@Test
public void exportWhenResultSetLargerThanExportPageSize() throws Exception {
    List<Result> result1 = Arrays.asList(mock(Result.class), mock(Result.class));
    List<Result> result2 = Collections.singletonList(mock(Result.class));
    List<Integer> startIndices = setupProviderResponses(result1, result2);
    MigrationMetadata metadata = migratable.export(EXPORT_PATH);
    verify(mockTaskManager).exportMetacardQuery(result1, 1);
    assertThat("Invalid start index for first query", startIndices.get(0), is(1));
    verify(mockTaskManager).exportMetacardQuery(result2, 2);
    assertThat("Invalid start index for second query", startIndices.get(1), is(config.getExportQueryPageSize() + 1));
    verify(mockTaskManager).close();
    assertThat(metadata.getMigrationWarnings(), is(empty()));
}
Also used : MigrationMetadata(org.codice.ddf.migration.MigrationMetadata) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Example 3 with MigrationMetadata

use of org.codice.ddf.migration.MigrationMetadata 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 4 with MigrationMetadata

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

the class SecurityMigratableTest method testExportCrlIsNull.

@Test
public void testExportCrlIsNull() {
    // Setup
    MigratableUtil mockMigratableUtil = mock(MigratableUtil.class);
    when(mockMigratableUtil.getJavaPropertyValue(SERVER_ENCRYPTION_PROPERTIES_PATH, CRL_PROP_KEY)).thenReturn(null);
    SecurityMigratable securityMigratable = new SecurityMigratable(DESCRIBABLE_BEAN, mockMigratableUtil);
    // Perform test
    MigrationMetadata migrationMetadata = securityMigratable.export(EXPORT_DIRECTORY);
    // Verify
    verify(mockMigratableUtil, never()).copyFile(eq(EXPECTED_SERVER_ENCRYPTION_CRL_PATH), eq(EXPORT_DIRECTORY), anyCollectionOf(MigrationWarning.class));
    assertThat(migrationMetadata.getMigrationWarnings().size(), is(0));
}
Also used : MigrationWarning(org.codice.ddf.migration.MigrationWarning) MigratableUtil(org.codice.ddf.migration.util.MigratableUtil) MigrationMetadata(org.codice.ddf.migration.MigrationMetadata) Test(org.junit.Test)

Example 5 with MigrationMetadata

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

the class SecurityMigratableTest method testWarningsReturned.

@Test
public void testWarningsReturned() throws Exception {
    MigratableUtil migratableUtil = mock(MigratableUtil.class);
    MigrationWarning expectedWarning = new MigrationWarning("Expected Warning");
    doAnswer(new MigrationWarningAnswer(expectedWarning)).when(migratableUtil).copyDirectory(eq(PDP_POLICIES_DIR_REL_PATH), eq(EXPORT_DIRECTORY), Matchers.<Collection<MigrationWarning>>any());
    SecurityMigratable securityMigratable = new SecurityMigratable(DESCRIBABLE_BEAN, migratableUtil);
    MigrationMetadata migrationMetadata = securityMigratable.export(EXPORT_DIRECTORY);
    assertThat(migrationMetadata.getMigrationWarnings(), containsInAnyOrder(expectedWarning));
}
Also used : MigrationWarning(org.codice.ddf.migration.MigrationWarning) MigratableUtil(org.codice.ddf.migration.util.MigratableUtil) MigrationMetadata(org.codice.ddf.migration.MigrationMetadata) Test(org.junit.Test)

Aggregations

MigrationMetadata (org.codice.ddf.migration.MigrationMetadata)11 Test (org.junit.Test)9 MigrationWarning (org.codice.ddf.migration.MigrationWarning)8 MigratableUtil (org.codice.ddf.migration.util.MigratableUtil)5 ArrayList (java.util.ArrayList)4 Path (java.nio.file.Path)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 MigrationException (org.codice.ddf.migration.MigrationException)2 Stopwatch (com.google.common.base.Stopwatch)1 Result (ddf.catalog.data.Result)1 FederationException (ddf.catalog.federation.FederationException)1 QueryRequest (ddf.catalog.operation.QueryRequest)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 ExportMigrationException (org.codice.ddf.migration.ExportMigrationException)1 Filter (org.opengis.filter.Filter)1