Omer Frenkel has uploaded a new change for review.

Change subject: core: Allow skipping command execution
......................................................................

core: Allow skipping command execution

Currently, when user try to execute command that has nothing to do (like
stopping a down vm), there are 2 options:
1. block the command with can-do-action notifying the user he is doing
something wrong.

2. add code in can-do-action and execute to skip execution

this patch adds an easy way to skip command execution,
by overriding 'shouldSkipCommandExecution' method, we can mark the
command no to run can-do-action and execute code.
the command will just finish as succeeded and operation will be logged.

in the following patch i have an example of usage for the 'stop down vm'
scenario.

Change-Id: Ib86226c3af0c245ec01c59ac650c9282d58f22bc
Signed-off-by: Omer Frenkel <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java
1 file changed, 18 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/35/34935/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 90a09bd..fc90b60 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
@@ -138,6 +138,7 @@
     private Map<Guid, CommandBase<?>> childCommandsMap = new HashMap<>();
     private Map<Guid, Pair<VdcActionType, VdcActionParametersBase>> 
childCommandInfoMap = new HashMap<>();
     private CommandStatus commandStatus = CommandStatus.NOT_STARTED;
+    private Boolean skipCommandExecution;
 
     public void addChildCommandInfo(Guid id, VdcActionType vdcActionType, 
VdcActionParametersBase parameters) {
         childCommandInfoMap.put(id, new Pair<>(vdcActionType, parameters));
@@ -740,7 +741,7 @@
             try {
                 returnValue =
                         isUserAuthorizedToRunAction() && 
isBackwardsCompatible() && validateInputs() && acquireLock()
-                                && canDoAction()
+                                && (getCachedShouldSkipCommandExecution() || 
canDoAction())
                                 && internalValidateAndSetQuota();
                 if (!returnValue && 
getReturnValue().getCanDoActionMessages().size() > 0) {
                     log.warn("CanDoAction of action '{}' failed. Reasons: {}", 
getActionType(),
@@ -761,6 +762,17 @@
             }
         }
         return returnValue;
+    }
+
+    protected final boolean getCachedShouldSkipCommandExecution() {
+        if (skipCommandExecution == null) {
+            skipCommandExecution = shouldSkipCommandExecution();
+        }
+        return skipCommandExecution;
+    }
+
+    protected boolean shouldSkipCommandExecution() {
+        return false;
     }
 
     private boolean internalValidateAndSetQuota() {
@@ -1159,7 +1171,11 @@
             if (hasTaskHandlers()) {
                 getCurrentTaskHandler().execute();
             } else {
-                executeCommand();
+                if (getCachedShouldSkipCommandExecution()) {
+                    setSucceeded(true);
+                } else {
+                    executeCommand();
+                }
             }
             functionReturnValue = getSucceeded();
             exceptionOccurred = false;


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib86226c3af0c245ec01c59ac650c9282d58f22bc
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Omer Frenkel <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to