Search in sources :

Example 1 with ExportMigrationException

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

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

the class MigrationTaskManager method exportMetacardQuery.

/**
     * Creates a sublist from the given results and a destination file for metacards based on
     * the {@link CatalogMigratableConfig} object used by this task manager. An asynchronous
     * task is started for exporting the metacards and is deferred to the appropriate instance
     * of {@link MigrationFileWriter} for processing.
     *
     * @param results          The results of a catalog query that need to be exported.
     * @param exportGroupCount The group or page number of the query. This value is not monitored
     *                         or audited for repeats and is strictly for record keeping by naming
     *                         the resulting export files appropriately.
     * @throws MigrationException Thrown if one of the writing threads fails or throws an exception
     *                            itself.
     */
public void exportMetacardQuery(final List<Result> results, long exportGroupCount) throws MigrationException {
    for (int i = 0; i < results.size(); i += catalogConfig.getExportCardsPerFile()) {
        final List<Result> fileResults = results.subList(i, Math.min((i + catalogConfig.getExportCardsPerFile()), results.size()));
        final File exportFile = catalogConfig.getExportPath().resolve(makeFileName(exportGroupCount, i)).toFile();
        Callable<Void> writerCallable = () -> {
            fileWriter.writeMetacards(exportFile, fileResults);
            return null;
        };
        ListenableFuture<Void> task = taskExecutor.submit(writerCallable);
        Futures.addCallback(task, createFutureCallback());
        if (failureFlag) {
            throw new ExportMigrationException("Error in file writing thread");
        }
    }
}
Also used : ExportMigrationException(org.codice.ddf.migration.ExportMigrationException) File(java.io.File) Result(ddf.catalog.data.Result)

Example 3 with ExportMigrationException

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

the class MigratableUtil method copyDirectory.

/**
     * Recursively copies a directory to a destination directory. The directory to
     * copy must be a relative path under {@code ddf.home}, and its path must not contain any
     * symbolic link, otherwise the directory will not be copied and a {@link MigrationWarning}
     * will be returned.
     *
     * @param source          relative path to the directory to copy
     * @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
     * @throws MigrationException thrown if file system error prevents the directory to be copied
     */
public void copyDirectory(@NotNull Path source, @NotNull Path exportDirectory, @NotNull Collection<MigrationWarning> warnings) throws MigrationException {
    notNull(source, "Source cannot be null");
    notNull(exportDirectory, "Destination cannot be null");
    notNull(warnings, "Warning collection cannot be null");
    try {
        if (isSourceMigratable(source, (reason) -> new PathMigrationWarning(source, reason), warnings)) {
            FileUtils.copyDirectory(source.toFile(), exportDirectory.resolve(source).toFile());
        }
    } catch (IOException e) {
        String message = String.format("Unable to copy [%s] to [%s].", source.toString(), exportDirectory.toString());
        LOGGER.info(message, e);
        throw new ExportMigrationException(message, e);
    }
}
Also used : ExportMigrationException(org.codice.ddf.migration.ExportMigrationException) IOException(java.io.IOException)

Example 4 with ExportMigrationException

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

the class MigratableUtil method copy.

private void copy(Path sourceFile, Path exportDirectory, Collection<MigrationWarning> warnings, BooleanSupplier isSourceMigratable) throws MigrationException {
    notNull(sourceFile, "Source file cannot be null");
    notNull(exportDirectory, "Destination cannot be null");
    notNull(warnings, "Warning collection cannot be null");
    try {
        if (isSourceMigratable.getAsBoolean()) {
            FileUtils.copyFile(sourceFile.toFile(), exportDirectory.resolve(sourceFile).toFile());
        }
    } catch (IOException e) {
        String message = String.format("Unable to copy [%s] to [%s]", sourceFile.toString(), exportDirectory.toString());
        LOGGER.info(message, e);
        throw new ExportMigrationException(message, e);
    }
}
Also used : ExportMigrationException(org.codice.ddf.migration.ExportMigrationException) IOException(java.io.IOException)

Example 5 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)

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