Search in sources :

Example 1 with Operation

use of org.codice.ddf.admin.configurator.Operation in project ddf by codice.

the class ConfiguratorImpl method rollback.

private void rollback(UUID failedStep, OperationReport configReport, ConfiguratorException exception) {
    configReport.putResult(failedStep, ResultImpl.fail(exception));
    Deque<Map.Entry<UUID, Operation>> undoStack = new ArrayDeque<>();
    boolean skipRest = false;
    for (Map.Entry<UUID, Operation> row : configHandlers.entrySet()) {
        if (failedStep.equals(row.getKey())) {
            skipRest = true;
        }
        if (!skipRest) {
            undoStack.push(row);
        } else if (!failedStep.equals(row.getKey())) {
            configReport.putResult(row.getKey(), ResultImpl.skip());
        }
    }
    for (Map.Entry<UUID, Operation> row : undoStack) {
        try {
            Result result = row.getValue().rollback();
            configReport.putResult(row.getKey(), result);
        } catch (ConfiguratorException e) {
            Optional operationData = configReport.getResult(row.getKey()).getOperationData();
            if (operationData.isPresent()) {
                configReport.putResult(row.getKey(), ResultImpl.rollbackFailWithData(e, operationData.get()));
            } else {
                configReport.putResult(row.getKey(), ResultImpl.rollbackFail(e));
            }
        }
    }
}
Also used : Optional(java.util.Optional) Operation(org.codice.ddf.admin.configurator.Operation) UUID(java.util.UUID) ConfiguratorException(org.codice.ddf.admin.configurator.ConfiguratorException) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ArrayDeque(java.util.ArrayDeque) Result(org.codice.ddf.admin.configurator.Result)

Example 2 with Operation

use of org.codice.ddf.admin.configurator.Operation in project ddf by codice.

the class ConfiguratorImpl method commit.

/**
 * Sequentially invokes all the {@link Operation}s, committing their changes. If a failure occurs
 * during the processing, a rollback is attempted of those handlers that had already been
 * committed.
 *
 * @return report of the commit status, whether successful, successfully rolled back, or partially
 *     rolled back with errors
 */
private OperationReport commit() {
    OperationReport configReport = new OperationReportImpl();
    for (Map.Entry<UUID, Operation> row : configHandlers.entrySet()) {
        try {
            Result result = row.getValue().commit();
            configReport.putResult(row.getKey(), result);
        } catch (ConfiguratorException e) {
            LOGGER.debug("Error committing configuration change", e);
            // On failure, attempt to rollback any config changes that have already been made
            // and then break out of loop processing, only reporting the remaining as skipped
            rollback(row.getKey(), configReport, e);
            break;
        }
    }
    return configReport;
}
Also used : OperationReport(org.codice.ddf.admin.configurator.OperationReport) Operation(org.codice.ddf.admin.configurator.Operation) UUID(java.util.UUID) ConfiguratorException(org.codice.ddf.admin.configurator.ConfiguratorException) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Result(org.codice.ddf.admin.configurator.Result)

Aggregations

LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 UUID (java.util.UUID)2 ConfiguratorException (org.codice.ddf.admin.configurator.ConfiguratorException)2 Operation (org.codice.ddf.admin.configurator.Operation)2 Result (org.codice.ddf.admin.configurator.Result)2 ArrayDeque (java.util.ArrayDeque)1 Optional (java.util.Optional)1 OperationReport (org.codice.ddf.admin.configurator.OperationReport)1