Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,24 @@ public final <T> T applyChange(Function<ExecutionRuntime, T> changeApplier, Exec
return changeApplier.apply(executionRuntime);
}

/**
* Rolls back (reverts) a previously applied change with session-scoped dependency injection.
* <p>
* This method is the entry point for non-transactional rollback execution.
* It calls {@link #enhanceExecutionRuntime(ExecutionRuntime, boolean)} to allow
* subclasses to inject session-scoped dependencies before executing the rollback.
*
* @param <T> the return type of the rollback operation
* @param changeRollbacker the function that executes the actual rollback
* @param executionRuntime the runtime context for dependency resolution
* @return the result of the rollback operation
*/
public final <T> T rollbackChange(Function<ExecutionRuntime, T> changeRollbacker, ExecutionRuntime executionRuntime) {
enhanceExecutionRuntime(executionRuntime, false);
return changeRollbacker.apply(executionRuntime);
}


/**
* Hook for injecting session-scoped dependencies into the execution runtime.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,23 @@ public interface TargetSystemOps extends TargetSystem {
*/
<T> T applyChange(Function<ExecutionRuntime, T> changeApplier, ExecutionRuntime executionRuntime);

/**
* Rolls back (reverts) a previously applied change in this target system.
* <p>
* This method coordinates the execution of a rollback by:
* <ul>
* <li>Injecting session-scoped dependencies via the target system</li>
* <li>Executing the rollback function with the enhanced runtime</li>
* </ul>
* <p>
* Implementations should strive for idempotency: invoking the rollback more than
* once should not produce side effects beyond the first successful revert.
*
* @param <T> the return type of the rollback operation
* @param changeRollbacker the function that executes the actual rollback
* @param executionRuntime the runtime context for dependency resolution
* @return the result of the rollback operation
*/
<T> T rollbackChange(Function<ExecutionRuntime, T> changeRollbacker, ExecutionRuntime executionRuntime);

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ public final <T> T applyChange(Function<ExecutionRuntime, T> changeApplier, Exec
return targetSystem.applyChange(changeApplier, executionRuntime);
}

@Override
public final <T> T rollbackChange(Function<ExecutionRuntime, T> changeRollbacker, ExecutionRuntime executionRuntime) {
executionRuntime.addContextLayer(targetSystem.getContext());
return targetSystem.rollbackChange(changeRollbacker, executionRuntime);
}

@Override
public String getId() {
return targetSystem.getId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ protected ChangeProcessResult doApplyChange() {

private void rollbackActualChangeAndChain(FailedAfterExecutionAuditStep rollableFailedStep, ExecutionContext executionContext) {
rollableFailedStep.getRollbackSteps().forEach(rollableStep -> {
ManualRolledBackStep rolledBack = rollableStep.rollback(buildExecutionRuntime());
ManualRolledBackStep rolledBack = targetSystemOps.rollbackChange(rollableStep::rollback, buildExecutionRuntime());
stepLogger.logManualRollbackResult(rolledBack);
summarizer.add(rolledBack);
auditAndLogManualRollback(rolledBack, executionContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private void rollbackChain(RollableFailedStep rollableFailedStep, ExecutionConte
rollableFailedStep.getRollbackSteps()
.stream().skip(1)
.forEach(rollableStep -> {
ManualRolledBackStep rolledBack = rollableStep.rollback(buildExecutionRuntime());
ManualRolledBackStep rolledBack = targetSystemOps.rollbackChange(rollableStep::rollback, buildExecutionRuntime());
stepLogger.logManualRollbackResult(rolledBack);
summarizer.add(rolledBack);
auditAndLogManualRollback(rolledBack, executionContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ private void rollbackChain(RollableFailedStep rollableFailedStep, ExecutionConte
rollableFailedStep.getRollbackSteps()
.stream().skip(1)
.forEach(rollableStep -> {
ManualRolledBackStep rolledBack = rollableStep.rollback(buildExecutionRuntime());
ManualRolledBackStep rolledBack = targetSystemOps.rollbackChange(rollableStep::rollback, buildExecutionRuntime());
stepLogger.logManualRollbackResult(rolledBack);
summarizer.add(rolledBack);
auditAndLogManualRollback(rolledBack, executionContext);
Expand Down
Loading