Ravi Nori has uploaded a new change for review.

Change subject: engine : Persist commands automatically
......................................................................

engine : Persist commands automatically

Persist async commands anc commands with callbacks
automatically

Change-Id: Ic4f56ec11d295baae513e7552f93a5bf9b81d384
Signed-off-by: Ravi Nori <rn...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java
1 file changed, 32 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/81/31681/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 1c6f1e7..a9cd99d 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
@@ -1183,6 +1183,11 @@
             processExceptionToClient(new VdcFault(e, VdcBllErrors.ENGINE));
             log.error(String.format("Command %1$s throw exception", 
getClass().getName()), e);
         } finally {
+            // persist command if it is an async command
+            if (!getReturnValue().getVdsmTaskIdList().isEmpty() &&
+                    CommandCoordinatorUtil.getCommandEntity(getCommandId()) == 
null) {
+                persistCommand(getParameters().getParentCommand(), 
getCallBack() != null);
+            }
             if (!exceptionOccurred) {
                 setCommandExecuted();
             }
@@ -1316,6 +1321,7 @@
 
     protected final void execute() {
         setCommandStatus(CommandStatus.ACTIVE);
+        checkPersistCommand();
         getReturnValue().setCanDoAction(true);
         getReturnValue().setIsSyncronious(true);
 
@@ -1352,6 +1358,32 @@
         }
     }
 
+    /**
+     * Automatically persists commands with command call backs or
+     * if the parent command has been persisted and the callback has
+     * been enabled
+     */
+    private void checkPersistCommand() {
+        // persist command if command provides custom callback
+        if (getCallBack() != null) {
+            persistCommand(getParameters().getParentCommand(), true);
+            return;
+        }
+
+        // persist command if parent command has been persisted and its
+        // callback has been enabled
+        if (getParameters().getParentParameters() != null) {
+            Guid parentCommandId = 
getParameters().getParentParameters().getCommandId();
+            if (!Guid.isNullOrEmpty(parentCommandId)) {
+                CommandEntity parentCmdEntity = 
CommandCoordinatorUtil.getCommandEntity(parentCommandId);
+                if (parentCmdEntity != null && 
parentCmdEntity.isCallBackEnabled()) {
+                    persistCommand(getParameters().getParentCommand(), 
getCallBack() != null);
+                    return;
+                }
+            }
+        }
+    }
+
     public boolean hasTasks() {
         return !getReturnValue().getVdsmTaskIdList().isEmpty();
     }


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

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

Reply via email to