Yair Zaslavsky has uploaded a new change for review.

Change subject: 1. core: Add createAction and runAction(commandBase) methods
......................................................................

1. core: Add createAction and runAction(commandBase) methods

Adding this methods as going to introduce a future change that will
need to create a command object, run a state altering method on it
and then use this command object for execution

Change-Id: I9c420aba7a95ec7264dad31a6bca9d11edf3a607
Signed-off-by: Yair Zaslavsky <yzasl...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/Backend.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/interfaces/BackendInternal.java
2 files changed, 55 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/95/15795/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/Backend.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/Backend.java
index f1b2745..ace5247 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/Backend.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/Backend.java
@@ -314,6 +314,29 @@
             VdcActionParametersBase parameters,
             boolean runAsInternal,
             CommandContext context) {
+        CommandBase<?> command = CommandsFactory.CreateCommand(actionType, 
parameters);
+        return runAction(command, runAsInternal, context);
+    }
+
+    protected VdcReturnValueBase runAction(CommandBase<?> command,
+            boolean runAsInternal,
+            CommandContext context) {
+        VdcReturnValueBase returnValue =
+                evaluateCorrelationId(command.getActionType(), 
command.getParameters());
+        if (returnValue != null) {
+            return returnValue;
+        }
+        command.setInternalExecution(runAsInternal);
+        command.setContext(context);
+        ExecutionHandler.prepareCommandForMonitoring(command, 
command.getActionType(), runAsInternal);
+
+        returnValue = command.executeAction();
+        
returnValue.setCorrelationId(command.getParameters().getCorrelationId());
+        returnValue.setJobId(command.getJobId());
+        return returnValue;
+    }
+
+    protected VdcReturnValueBase evaluateCorrelationId(VdcActionType 
actionType, VdcActionParametersBase parameters) {
         VdcReturnValueBase returnValue = null;
 
         // Evaluate and set the correlationId on the parameters, fails on 
invalid correlation id
@@ -321,17 +344,8 @@
         if (returnValue != null) {
             log.warnFormat("CanDoAction of action {0} failed. Reasons: {1}", 
actionType,
                     StringUtils.join(returnValue.getCanDoActionMessages(), 
','));
-            return returnValue;
+
         }
-
-        CommandBase<?> command = CommandsFactory.CreateCommand(actionType, 
parameters);
-        command.setInternalExecution(runAsInternal);
-        command.setContext(context);
-        ExecutionHandler.prepareCommandForMonitoring(command, actionType, 
runAsInternal);
-
-        returnValue = command.executeAction();
-        returnValue.setCorrelationId(parameters.getCorrelationId());
-        returnValue.setJobId(command.getJobId());
         return returnValue;
     }
 
@@ -567,5 +581,17 @@
         SchedulerUtilQuartzImpl.getInstance().triggerJob(poolMonitoringJobId);
     }
 
+    @Override
+    public CommandBase<?> createAction(VdcActionType actionType, 
VdcActionParametersBase parameters) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public VdcReturnValueBase runAction(CommandBase<?> action) {
+        return runAction(action, true, null);
+    }
+
     private static final Log log = LogFactory.getLog(Backend.class);
+
 }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/interfaces/BackendInternal.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/interfaces/BackendInternal.java
index 5377f94..bc9714e 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/interfaces/BackendInternal.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/interfaces/BackendInternal.java
@@ -2,6 +2,7 @@
 
 import java.util.ArrayList;
 
+import org.ovirt.engine.core.bll.CommandBase;
 import org.ovirt.engine.core.bll.context.CommandContext;
 import org.ovirt.engine.core.bll.job.ExecutionContext;
 import org.ovirt.engine.core.common.action.VdcActionParametersBase;
@@ -82,4 +83,22 @@
     ArrayList<VdcReturnValueBase> runInternalMultipleActions(VdcActionType 
actionType,
             ArrayList<VdcActionParametersBase> parameters,
             ExecutionContext executionContext);
+
+    /**
+     * Creates an instance of the action.
+     * This should be used by {@code CommandBase} to insert place holders for 
tasks
+     * @param actionType the type of the command to run
+     * @param parameters parameters of the command
+     * @return object of the created command
+     */
+    CommandBase<?> createAction(VdcActionType actionType, 
VdcActionParametersBase parameters);
+
+    /**
+     * Executes the instance of the action.
+     * This should be used by parent/root commands in order to execute child 
commands that
+     * place holders were created for them.
+     * @param action
+     * @return
+     */
+    VdcReturnValueBase runAction(CommandBase<?> action);
 }


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

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

Reply via email to