Daniel Erez has uploaded a new change for review.

Change subject: core: seat compensate - prevent IndexOutOfBounds
......................................................................

core: seat compensate - prevent IndexOutOfBounds

CommandBase -> hasTaskHandlers:
* compensate: setExecutionReason to ROLLBACK_FLOW
  for ensuring internalEndWithFailure flow
  as in revertPreviousHandlers.
* internalEndWithFailure: verifying executionIndex >= 0
  to prevent index underflow.
* revertPreviousHandlers: when executionIndex < 0
  set command as succeeded (to ensure tasks clean up).

Change-Id: I7af9f3ab3bfce91b114d82145957909ba1ee7819
Bug-Url: https://bugzilla.redhat.com/966153
Bug-Url: https://bugzilla.redhat.com/966618
Bug-Url: https://bugzilla.redhat.com/966576
Bug-Url: https://bugzilla.redhat.com/962497
Signed-off-by: Daniel Erez <de...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java
1 file changed, 13 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/33/15133/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java
index 54e1777..cd77bc5 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java
@@ -348,6 +348,7 @@
      */
     protected void compensate() {
         if (hasTaskHandlers()) {
+            
getParameters().setExecutionReason(CommandExecutionReason.ROLLBACK_FLOW);
             getCurrentTaskHandler().compensate();
             revertPreviousHandlers();
         } else {
@@ -586,8 +587,10 @@
     private void internalEndWithFailure() {
         log.errorFormat("Ending command with failure: {0}", 
getClass().getName());
         if (hasTaskHandlers()) {
-            getCurrentTaskHandler().endWithFailure();
-            revertPreviousHandlers();
+            if (canRevertTasks()) {
+                getCurrentTaskHandler().endWithFailure();
+                revertPreviousHandlers();
+            }
             startPollingAsyncTasks();
         } else {
             endWithFailure();
@@ -644,7 +647,7 @@
 
     private void revertPreviousHandlers() {
         getParameters().decrementExecutionIndex();
-        if (getExecutionIndex() >= 0) {
+        if (canRevertTasks()) {
             logRollbackedTask();
             
getParameters().setExecutionReason(CommandExecutionReason.ROLLBACK_FLOW);
             getCurrentTaskHandler().compensate();
@@ -653,6 +656,9 @@
                 // If there is no task to take us onwards, just run the 
previous handler's revert
                 revertPreviousHandlers();
             }
+        }
+        else {
+            setSucceeded(true);
         }
     }
 
@@ -1828,6 +1834,10 @@
         return getParameters().getExecutionIndex();
     }
 
+    private boolean canRevertTasks() {
+        return getExecutionIndex() >= 0;
+    }
+
     public boolean isQuotaChanged() {
         return quotaChanged;
     }


--
To view, visit http://gerrit.ovirt.org/15133
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7af9f3ab3bfce91b114d82145957909ba1ee7819
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Daniel Erez <de...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to