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));
}
}
}
}
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;
}
Aggregations