use of org.codice.ddf.migration.MigrationWarning 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);
}
use of org.codice.ddf.migration.MigrationWarning in project ddf by codice.
the class ExportCommand method execute.
@Override
public Object execute() {
Path exportDirectory;
if (exportDirectoryArgument == null || exportDirectoryArgument.isEmpty()) {
exportDirectory = defaultExportDirectory;
} else {
exportDirectory = Paths.get(exportDirectoryArgument);
}
outputInfoMessage(String.format(STARTING_EXPORT_MESSAGE, exportDirectory));
try {
Collection<MigrationWarning> migrationWarnings = security.runWithSubjectOrElevate(() -> configurationMigrationService.export(exportDirectory));
if (migrationWarnings.isEmpty()) {
outputSuccessMessage(SUCCESSFUL_EXPORT_MESSAGE);
} else {
for (MigrationWarning migrationWarning : migrationWarnings) {
outputWarningMessage(migrationWarning.getMessage());
}
outputWarningMessage(String.format(FAILED_EXPORT_MESSAGE, exportDirectory));
}
} catch (SecurityServiceException e) {
outputErrorMessage(String.format(ERROR_EXPORT_MESSAGE, e.getMessage()));
} catch (InvocationTargetException e) {
outputErrorMessage(String.format(ERROR_EXPORT_MESSAGE, e.getCause().getMessage()));
}
return null;
}
use of org.codice.ddf.migration.MigrationWarning in project ddf by codice.
the class ConfigurationAdminMigrationTest method testGetFailedConfigurationFilesTwoFilesInFailedDirectory.
@Test
public void testGetFailedConfigurationFilesTwoFilesInFailedDirectory() throws Exception {
when(Files.newDirectoryStream(any(Path.class), anyString())).thenReturn(failedDirectoryStream);
setUpTwoConfigFileIterator(failedDirectoryStream);
ConfigurationAdminMigration configurationAdminMigration = new ConfigurationAdminMigration(configurationDirectoryStream, PROCESSED_DIRECTORY_PATH, FAILED_DIRECTORY_PATH, configurationFileFactory, configurationFilePoller, configurationAdmin, CONFIGURATION_FILE_EXTENSION);
Collection<MigrationWarning> configurationStatusMessages = configurationAdminMigration.getFailedConfigurationFiles();
Collection<String> actualPaths = new ArrayList<>();
for (MigrationWarning configStatus : configurationStatusMessages) {
actualPaths.add(configStatus.getMessage());
}
verifyStatic();
Files.newDirectoryStream(FAILED_DIRECTORY_PATH, FILE_FILTER);
assertThat("Incorrect number for files returned from configurationAdminMigration.getFailedConfigurationFiles()", configurationStatusMessages.size(), is(2));
}
use of org.codice.ddf.migration.MigrationWarning in project ddf by codice.
the class PlatformMigratableTest method testExportExceptionThrownWhenCopyingFileFromSystemPropertyValue.
@Test(expected = MigrationException.class)
public void testExportExceptionThrownWhenCopyingFileFromSystemPropertyValue() throws Exception {
// Setup
MigratableUtil mockMigratableUtil = mock(MigratableUtil.class);
doThrow(MigrationException.class).when(mockMigratableUtil).copyFileFromSystemPropertyValue(any(String.class), eq(exportDirectory), Matchers.<Collection<MigrationWarning>>any());
PlatformMigratable platformMigratable = new PlatformMigratable(DESCRIBABLE_BEAN, mockMigratableUtil);
// Perform test
platformMigratable.export(exportDirectory);
}
use of org.codice.ddf.migration.MigrationWarning 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));
}
Aggregations