Omer Frenkel has uploaded a new change for review.

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

core: Allow skipping vm command execution

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

in change-id: I75925d528cca52603660d5a7ec6c5c871304f3d0
there is an example of usage for the 'stop down vm' scenario.

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


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/02/35602/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmCommand.java
index 31fcab1..aaa60b5 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmCommand.java
@@ -57,6 +57,7 @@
     private static final int Kb = 1024;
 
     protected final OsRepository osRepository = 
SimpleDependecyInjector.getInstance().get(OsRepository.class);
+    private Boolean skipCommandExecution;
 
     public VmCommand(T parameters, CommandContext cmdContext) {
         super(parameters, cmdContext);
@@ -94,6 +95,10 @@
 
     @Override
     protected void executeCommand() {
+        if (shouldSkipCommandExecutionCached()) {
+            setSucceeded(true);
+            return;
+        }
         executeVmCommand();
     }
 
@@ -555,4 +560,25 @@
         return new MultipleStorageDomainsValidator(getVm().getStoragePoolId(),
                 ImagesHandler.getAllStorageIdsForImageIds(disksList));
     }
+
+    /**
+     * use this method to get the result of shouldSkipCommandExecution
+     * as it is also allow to cache the result for multiple calls
+     */
+    protected final boolean shouldSkipCommandExecutionCached() {
+        if (skipCommandExecution == null) {
+            skipCommandExecution = shouldSkipCommandExecution();
+        }
+        return skipCommandExecution;
+    }
+
+    /**
+     * check for special conditions that will cause the command to skip its 
canDoAction and execution
+     * this method should be overridden with specific logic for each command
+     * using the result should be done with shouldSkipCommandExecutionCached 
method that cache the result in the command
+     * @return true if the command should not execute any logic and should not 
return errors to the user
+     */
+    protected boolean shouldSkipCommandExecution() {
+        return false;
+    }
 }


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I290055f759afcc554d1f49fac12455ae18d2d194
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