Yair Zaslavsky has uploaded a new change for review.

Change subject: core: Adding engineSessionId on CommandContext
......................................................................

core: Adding engineSessionId on CommandContext

This patch adds engineSessionId on CommandContext.
In addition it handles passing command contex to
internal action invocations

Change-Id: I310f5f77fff78b3232ee77fe63791425fd521516
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/CommandBase.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MultipleActionsRunner.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/NetworkClusterAttachmentActionRunner.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveVmFromPoolRunner.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsEventListener.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/context/CommandContext.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/interfaces/BackendInternal.java
8 files changed, 69 insertions(+), 60 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/29/28829/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 a475d46..30ab731 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
@@ -510,7 +510,7 @@
             list.add(returnValue);
             return list;
         } else {
-            return runMultipleActionsImpl(actionType, parameters, false, 
isRunOnlyIfAllCanDoPass, waitForResult);
+            return runMultipleActionsImpl(actionType, parameters, false, 
isRunOnlyIfAllCanDoPass, waitForResult, null);
         }
     }
 
@@ -518,38 +518,30 @@
     @ExcludeClassInterceptors
     public ArrayList<VdcReturnValueBase> 
runInternalMultipleActions(VdcActionType actionType,
             ArrayList<VdcActionParametersBase> parameters) {
-        return runMultipleActionsImpl(actionType, parameters, true, false, 
false);
+        return runMultipleActionsImpl(actionType, parameters, true, false, 
false, null);
     }
 
-    public ArrayList<VdcReturnValueBase> runMultipleActionsImpl(VdcActionType 
actionType,
-            ArrayList<VdcActionParametersBase> parameters,
-            boolean isInternal,
-            boolean isRunOnlyIfAllCanDoPass,
-            boolean isWaitForResult,
-            ExecutionContext executionContext) {
-        MultipleActionsRunner runner = 
MultipleActionsRunnersFactory.createMultipleActionsRunner(actionType,
-                parameters, isInternal);
-        runner.setExecutionContext(executionContext);
-        runner.setIsRunOnlyIfAllCanDoPass(isRunOnlyIfAllCanDoPass);
-        runner.setIsWaitForResult(isWaitForResult);
-        return runner.execute();
-    }
 
     @Override
     @ExcludeClassInterceptors
     public ArrayList<VdcReturnValueBase> 
runInternalMultipleActions(VdcActionType actionType,
-            ArrayList<VdcActionParametersBase> parameters,
-            ExecutionContext executionContext) {
-        return runMultipleActionsImpl(actionType, parameters, true, false, 
false, executionContext);
+            ArrayList<VdcActionParametersBase> parameters, CommandContext 
commandContext) {
+        return runMultipleActionsImpl(actionType, parameters, true, false, 
false, commandContext);
+
     }
 
     private ArrayList<VdcReturnValueBase> runMultipleActionsImpl(VdcActionType 
actionType,
             ArrayList<VdcActionParametersBase> parameters,
             boolean isInternal,
             boolean isRunOnlyIfAllCanDoPass,
-            boolean isWaitForResult) {
-        return runMultipleActionsImpl(actionType, parameters, isInternal, 
isRunOnlyIfAllCanDoPass, isWaitForResult,
-                null);
+            boolean isWaitForResult,
+            CommandContext commandContext) {
+        MultipleActionsRunner runner = 
MultipleActionsRunnersFactory.createMultipleActionsRunner(actionType,
+                parameters, isInternal);
+        runner.setCommandContext(commandContext);
+        runner.setIsRunOnlyIfAllCanDoPass(isRunOnlyIfAllCanDoPass);
+        runner.setIsWaitForResult(isWaitForResult);
+        return runner.execute();
     }
 
     @Override
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 64cf761..d95203b 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
@@ -215,6 +215,7 @@
         if (canPerformRollbackUsingCommand(commandType, params)) {
             params.setExecutionReason(CommandExecutionReason.ROLLBACK_FLOW);
             
params.setTransactionScopeOption(TransactionScopeOption.RequiresNew);
+            entailContext(rollbackContext);
             return getBackend().runInternalAction(commandType, params, 
rollbackContext);
         }
         return new VdcReturnValueBase();
@@ -2144,24 +2145,47 @@
     }
 
     protected VdcReturnValueBase runInternalAction(VdcActionType actionType, 
VdcActionParametersBase parameters) {
-        return Backend.getInstance().runInternalAction(actionType, parameters);
+        return Backend.getInstance().runInternalAction(actionType, parameters, 
createInheritingContext());
     }
 
     protected VdcReturnValueBase runInternalAction(VdcActionType actionType,
             VdcActionParametersBase parameters,
-            CommandContext context) {
-        return Backend.getInstance().runInternalAction(actionType, parameters, 
context);
+            CommandContext inheritingContext) {
+        entailContext(inheritingContext);
+        return Backend.getInstance().runInternalAction(actionType, parameters, 
inheritingContext);
     }
 
     protected ArrayList<VdcReturnValueBase> 
runInternalMultipleActions(VdcActionType actionType,
             ArrayList<VdcActionParametersBase> parameters) {
-        return Backend.getInstance().runInternalMultipleActions(actionType, 
parameters);
+        return Backend.getInstance().runInternalMultipleActions(actionType, 
parameters, createInheritingContext());
     }
 
     protected ArrayList<VdcReturnValueBase> 
runInternalMultipleActions(VdcActionType actionType,
             ArrayList<VdcActionParametersBase> parameters,
             ExecutionContext executionContext) {
-        return Backend.getInstance().runInternalMultipleActions(actionType, 
parameters, executionContext);
+        return Backend.getInstance().runInternalMultipleActions(actionType, 
parameters, createInheritingContext(executionContext));
+    }
+
+    protected void entailContext(CommandContext inheritingContext) {
+        if (StringUtils.isEmpty(inheritingContext.getEngineSessionId())) {
+            inheritingContext.setEngineSessionId(context.getEngineSessionId());
+        }
+    }
+
+    protected void inheritContext(CommandContext inheritFromContext) {
+        if (StringUtils.isEmpty(inheritFromContext.getEngineSessionId())) {
+            
context.setEngineSessionId(inheritFromContext.getEngineSessionId());
+        }
+    }
+
+    private CommandContext createInheritingContext() {
+        return new CommandContext(context.getEngineSessionId());
+    }
+
+    private CommandContext createInheritingContext(ExecutionContext 
executionContext) {
+        CommandContext ctx = new CommandContext(executionContext);
+        ctx.setEngineSessionId(context.getEngineSessionId());
+        return ctx;
     }
 
 }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MultipleActionsRunner.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MultipleActionsRunner.java
index 701376a..93fba88 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MultipleActionsRunner.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MultipleActionsRunner.java
@@ -4,7 +4,7 @@
 import java.util.List;
 import java.util.concurrent.Callable;
 
-import org.ovirt.engine.core.bll.job.ExecutionContext;
+import org.ovirt.engine.core.bll.context.CommandContext;
 import org.ovirt.engine.core.bll.job.ExecutionHandler;
 import org.ovirt.engine.core.common.action.VdcActionParametersBase;
 import org.ovirt.engine.core.common.action.VdcActionType;
@@ -30,10 +30,7 @@
      */
     protected boolean isRunOnlyIfAllCanDoPass = false;
 
-    /**
-     * The context by which each command should be executed (monitored or 
non-monitored).
-     */
-    private ExecutionContext executionContext;
+    protected CommandContext commandContext;
 
     public MultipleActionsRunner(VdcActionType actionType, 
List<VdcActionParametersBase> parameters, boolean isInternal) {
         this.actionType = actionType;
@@ -179,18 +176,19 @@
      */
 
     protected void executeValidatedCommand(CommandBase<?> command) {
-        if (executionContext == null || executionContext.isMonitored()) {
+        if (commandContext == null || commandContext.getExecutionContext() == 
null || commandContext.getExecutionContext().isMonitored()) {
             ExecutionHandler.prepareCommandForMonitoring(command,
                     command.getActionType(),
                     command.isInternalExecution());
         }
         
ThreadLocalParamsContainer.setCorrelationId(command.getCorrelationId());
         command.insertAsyncTaskPlaceHolders();
+        command.inheritContext(commandContext);
         command.executeAction();
     }
 
-    public void setExecutionContext(ExecutionContext executionContext) {
-        this.executionContext = executionContext;
+    public void setCommandContext(CommandContext commandContext) {
+        this.commandContext = commandContext;
     }
 
     public void setIsRunOnlyIfAllCanDoPass(boolean isRunOnlyIfAllCanDoPass) {
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/NetworkClusterAttachmentActionRunner.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/NetworkClusterAttachmentActionRunner.java
index fa38690..03fd466 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/NetworkClusterAttachmentActionRunner.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/NetworkClusterAttachmentActionRunner.java
@@ -54,7 +54,7 @@
         // multiple networks can be either attached or detached from a single 
cluster
         if (!params.isEmpty()) {
             Backend.getInstance().runInternalAction(massAction,
-                    new 
ClusterNetworksParameters(params.get(0).getVdsGroupId(), params));
+                    new 
ClusterNetworksParameters(params.get(0).getVdsGroupId(), params), 
commandContext);
         }
     }
 }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveVmFromPoolRunner.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveVmFromPoolRunner.java
index 9a4c56c..b300c1b 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveVmFromPoolRunner.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveVmFromPoolRunner.java
@@ -45,7 +45,7 @@
         VmPoolParametersBase removePoolParam = new 
VmPoolParametersBase(poolId);
         removePoolParam.setSessionId(getSessionId());
 
-        Backend.getInstance().runInternalAction(VdcActionType.RemoveVmPool, 
removePoolParam);
+        Backend.getInstance().runInternalAction(VdcActionType.RemoveVmPool, 
removePoolParam, commandContext);
     }
 
     private boolean isPoolRemovalEnabled() {
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsEventListener.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsEventListener.java
index 8b83d27..772d328 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsEventListener.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsEventListener.java
@@ -13,6 +13,7 @@
 import javax.ejb.TransactionAttributeType;
 
 import org.apache.commons.lang.StringUtils;
+import org.ovirt.engine.core.bll.context.CommandContext;
 import org.ovirt.engine.core.bll.job.ExecutionContext;
 import org.ovirt.engine.core.bll.job.ExecutionHandler;
 import org.ovirt.engine.core.bll.scheduling.SchedulingManager;
@@ -239,7 +240,7 @@
                             executionContext.setMonitored(true);
                             
Backend.getInstance().runInternalMultipleActions(VdcActionType.MigrateVmToServer,
                                     new 
ArrayList<>(createMigrateVmToServerParametersList(vmsToMigrate, vds)),
-                                    executionContext);
+                                    new CommandContext(executionContext));
                         }
                     } catch (RuntimeException e) {
                         log.errorFormat("Failed to initialize Vds on up. 
Error: {0}", e);
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/context/CommandContext.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/context/CommandContext.java
index 5f1f609..48fd9c9 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/context/CommandContext.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/context/CommandContext.java
@@ -12,6 +12,16 @@
      */
     private CompensationContext compensationContext;
 
+    private String engineSessionId;
+
+    public String getEngineSessionId() {
+        return engineSessionId;
+    }
+
+    public void setEngineSessionId(String engineSessionId) {
+        this.engineSessionId = engineSessionId;
+    }
+
     /**
      * The Lock in the command context is used by the parent command to pass 
to the child command locks the child needs
      * to acquire.
@@ -26,6 +36,10 @@
     public CommandContext() {
     }
 
+    public CommandContext(String engineSessionId) {
+        this.engineSessionId = engineSessionId;
+    }
+
     /**
      * Create instance which holds the compensation context
      *
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..23d6597 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
@@ -3,7 +3,6 @@
 import java.util.ArrayList;
 
 import org.ovirt.engine.core.bll.context.CommandContext;
-import org.ovirt.engine.core.bll.job.ExecutionContext;
 import org.ovirt.engine.core.common.action.VdcActionParametersBase;
 import org.ovirt.engine.core.common.action.VdcActionType;
 import org.ovirt.engine.core.common.action.VdcReturnValueBase;
@@ -53,6 +52,9 @@
     ArrayList<VdcReturnValueBase> runInternalMultipleActions(VdcActionType 
actionType,
             ArrayList<VdcActionParametersBase> parameters);
 
+    ArrayList<VdcReturnValueBase> runInternalMultipleActions(VdcActionType 
actionType,
+            ArrayList<VdcActionParametersBase> parameters, CommandContext 
commandContext);
+
     DateTime getStartedAt();
 
     /**
@@ -60,26 +62,4 @@
      */
     void triggerPoolMonitoringJob();
 
-    /**
-     * Invokes multiple actions of the same action type with different 
parameters under a given execution context which
-     * determines the visibility of the action.<br>
-     * The context determines the monitoring of the action:
-     * <ul>
-     * <li>If {@code executionContext} is null, default implementation will 
create {@code Job} instance to monitor a
-     * command for non-internal invocations.
-     * <li>If {@code executionContext} is configured for monitoring, a {@code 
Job} entity will be created for each
-     * command which ends the validation successfully.
-     * <ul>
-     *
-     * @param actionType
-     *            The type of the action
-     * @param parameters
-     *            A list containing the parameters for creating the command
-     * @param executionContext
-     *            Determines the visibility of the actions.
-     * @return A collection of the results of each action validation.
-     */
-    ArrayList<VdcReturnValueBase> runInternalMultipleActions(VdcActionType 
actionType,
-            ArrayList<VdcActionParametersBase> parameters,
-            ExecutionContext executionContext);
 }


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

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