Ravi Nori has uploaded a new change for review.

Change subject: engine : Save CommandContext in ContextCache
......................................................................

engine : Save CommandContext in ContextCache

Persist the command context in ContextCache
which is backed by a map.

Change-Id: I6b968f787b60f83cf96411a97dd6380421f724b9
Bug-Url: https://bugzilla.redhat.com/1115127
Signed-off-by: Ravi Nori <rn...@redhat.com>
---
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/context/CompensationContext.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/context/EngineContext.java
A 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/CommandContextsCacheImpl.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/CommandCoordinatorImpl.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/CommandExecutor.java
A 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/interfaces/CommandContextsCache.java
M 
backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/lock/EngineLock.java
8 files changed, 79 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/01/29501/1

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 d091f41..6e9e8e8 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
@@ -3,10 +3,13 @@
 import org.ovirt.engine.core.bll.job.ExecutionContext;
 import org.ovirt.engine.core.utils.lock.EngineLock;
 
+import java.io.Serializable;
+
 /**
  * Holds the context for execution of the command.
  */
-public final class CommandContext implements Cloneable {
+public final class CommandContext implements Cloneable, Serializable {
+    private static final long serialVersionUID = -5244313240304556051L;
     /**
      * The compensation context holds the required information for 
compensating the failed command.
      */
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/context/CompensationContext.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/context/CompensationContext.java
index ea842ae..75f9a16 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/context/CompensationContext.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/context/CompensationContext.java
@@ -1,5 +1,6 @@
 package org.ovirt.engine.core.bll.context;
 
+import java.io.Serializable;
 import java.util.Collection;
 
 import org.ovirt.engine.core.common.businessentities.BusinessEntity;
@@ -8,7 +9,7 @@
 /**
  * The compensation context contains information needed for compensating 
failed command executions.
  */
-public interface CompensationContext {
+public interface CompensationContext extends Serializable {
 
     /**
      * Save a snapshot of the entire entity before it is changed/deleted in 
the DB, so that it can be restored later on
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/context/EngineContext.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/context/EngineContext.java
index 3a1a7be..5bd234d 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/context/EngineContext.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/context/EngineContext.java
@@ -1,7 +1,10 @@
 package org.ovirt.engine.core.bll.context;
 
-public final class EngineContext implements Cloneable {
+import java.io.Serializable;
 
+public final class EngineContext implements Cloneable, Serializable {
+
+    private static final long serialVersionUID = 8109581539555057631L;
     private String sessionId;
 
     public EngineContext() {
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/CommandContextsCacheImpl.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/CommandContextsCacheImpl.java
new file mode 100644
index 0000000..b1d3fac
--- /dev/null
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/CommandContextsCacheImpl.java
@@ -0,0 +1,33 @@
+package org.ovirt.engine.core.bll.tasks;
+
+import org.ovirt.engine.core.bll.context.CommandContext;
+import org.ovirt.engine.core.bll.tasks.interfaces.CommandContextsCache;
+import org.ovirt.engine.core.compat.Guid;
+
+public class CommandContextsCacheImpl implements CommandContextsCache {
+
+    private static final String COMMAND_CONTEXT_MAP_NAME = "commandContextMap";
+    CacheWrapper<Guid, CommandContext> contextsMap;
+    private volatile boolean cacheInitialized;
+    private Object LOCK = new Object();
+
+    public CommandContextsCacheImpl() {
+        contextsMap = CacheProviderFactory.<Guid, CommandContext> 
getCacheWrapper(COMMAND_CONTEXT_MAP_NAME);
+    }
+
+    @Override
+    public CommandContext get(Guid commandId) {
+        return contextsMap.get(commandId);
+    }
+
+    @Override
+    public void remove(final Guid commandId) {
+        contextsMap.remove(commandId);
+    }
+
+    @Override
+    public void put(final Guid cmdId, final CommandContext context) {
+        contextsMap.put(cmdId, context);
+    }
+
+}
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/CommandCoordinatorImpl.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/CommandCoordinatorImpl.java
index a71e5fc..67a5a76 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/CommandCoordinatorImpl.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/CommandCoordinatorImpl.java
@@ -13,6 +13,7 @@
 import org.ovirt.engine.core.bll.context.CommandContext;
 import org.ovirt.engine.core.bll.interfaces.BackendInternal;
 import org.ovirt.engine.core.bll.job.ExecutionContext;
+import org.ovirt.engine.core.bll.tasks.interfaces.CommandContextsCache;
 import org.ovirt.engine.core.bll.tasks.interfaces.CommandCoordinator;
 import org.ovirt.engine.core.bll.tasks.interfaces.SPMTask;
 import org.ovirt.engine.core.common.VdcObjectType;
@@ -40,6 +41,7 @@
 
     private static final Log log = LogFactory.getLog(CommandCoordinator.class);
     private final CommandsCache commandsCache;
+    private final CommandContextsCache contextsCache;
     private final CoCoAsyncTaskHelper coCoAsyncTaskHelper;
     private final CommandExecutor cmdExecutor;
     private Object LOCK = new Object();
@@ -48,6 +50,7 @@
 
     CommandCoordinatorImpl() {
         commandsCache = new CommandsCacheImpl();
+        contextsCache = new CommandContextsCacheImpl();
         coCoAsyncTaskHelper = new CoCoAsyncTaskHelper(this);
         cmdExecutor = new CommandExecutor(this);
     }
@@ -65,6 +68,16 @@
                 cmdExecutor.addToCallBackMap(cmdEntity);
             }
         }
+    }
+
+    void persistCommandContext(Guid cmdId, CommandContext cmdContext) {
+        if (cmdContext != null) {
+            contextsCache.put(cmdId, cmdContext);
+        }
+    }
+
+    CommandContext getCommandContext(Guid cmdId) {
+        return contextsCache.get(cmdId);
     }
 
     /**
@@ -97,13 +110,13 @@
 
     @Override
     public CommandBase<?> retrieveCommand(Guid commandId) {
-        return buildCommand(commandsCache.get(commandId));
+        return buildCommand(commandsCache.get(commandId), 
contextsCache.get(commandId));
     }
 
-    private CommandBase<?> buildCommand(CommandEntity cmdEntity) {
+    private CommandBase<?> buildCommand(CommandEntity cmdEntity, 
CommandContext cmdContext) {
         CommandBase<?> command = null;
         if (cmdEntity != null) {
-            command = 
CommandsFactory.createCommand(cmdEntity.getCommandType(), 
cmdEntity.getActionParameters());
+            command = 
CommandsFactory.createCommand(cmdEntity.getCommandType(), 
cmdEntity.getActionParameters(), cmdContext);
             command.setCommandStatus(cmdEntity.getCommandStatus(), false);
             if (!Guid.isNullOrEmpty(cmdEntity.getRootCommandId()) &&
                     ! cmdEntity.getRootCommandId().equals(cmdEntity.getId()) &&
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/CommandExecutor.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/CommandExecutor.java
index bcf65d0..e6326f6 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/CommandExecutor.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/CommandExecutor.java
@@ -14,7 +14,6 @@
 import org.ovirt.engine.core.bll.CommandsFactory;
 import org.ovirt.engine.core.bll.context.CommandContext;
 import org.ovirt.engine.core.bll.tasks.interfaces.CommandCallBack;
-import org.ovirt.engine.core.bll.tasks.interfaces.CommandCoordinator;
 import org.ovirt.engine.core.bll.utils.BackendUtils;
 import org.ovirt.engine.core.common.action.VdcActionParametersBase;
 import org.ovirt.engine.core.common.action.VdcActionType;
@@ -35,12 +34,12 @@
     private static final ExecutorService executor = 
Executors.newFixedThreadPool(Config.<Integer>getValue(ConfigValues.CommandCoordinatorThreadPoolSize));
     private static final Log log = LogFactory.getLog(CommandExecutor.class);
 
-    private final CommandCoordinator coco;
+    private final CommandCoordinatorImpl coco;
     private final Map<Guid, CommandCallBack> cmdCallBackMap = new 
ConcurrentHashMap<>();
     private Object LOCK = new Object();
     private volatile boolean cmdExecutorInitialized;
 
-    CommandExecutor(CommandCoordinator coco) {
+    CommandExecutor(CommandCoordinatorImpl coco) {
         this.coco = coco;
         SchedulerUtil scheduler = SchedulerUtilQuartzImpl.getInstance();
         scheduler.scheduleAFixedDelayJob(this, "invokeCallbackMethods", new 
Class[]{},
@@ -109,6 +108,7 @@
                                                           final 
VdcActionParametersBase parameters,
                                                           final CommandContext 
cmdContext) {
         final CommandBase<?> command = 
CommandsFactory.createCommand(actionType, parameters, cmdContext);
+        coco.persistCommandContext(command.getCommandId(), cmdContext);
         return executor.submit(new Callable<VdcReturnValueBase>() {
 
             @Override
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/interfaces/CommandContextsCache.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/interfaces/CommandContextsCache.java
new file mode 100644
index 0000000..d64d809
--- /dev/null
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/interfaces/CommandContextsCache.java
@@ -0,0 +1,14 @@
+package org.ovirt.engine.core.bll.tasks.interfaces;
+
+import org.ovirt.engine.core.bll.context.CommandContext;
+import org.ovirt.engine.core.compat.Guid;
+
+public interface CommandContextsCache {
+
+    public CommandContext get(Guid commandId);
+
+    public void remove(Guid commandId);
+
+    public void put(Guid commandId, CommandContext context);
+
+}
diff --git 
a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/lock/EngineLock.java
 
b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/lock/EngineLock.java
index ffe2ee8..1fdc1a2 100644
--- 
a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/lock/EngineLock.java
+++ 
b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/lock/EngineLock.java
@@ -1,5 +1,6 @@
 package org.ovirt.engine.core.utils.lock;
 
+import java.io.Serializable;
 import java.util.Map;
 
 import org.ovirt.engine.core.common.utils.Pair;
@@ -7,8 +8,9 @@
 /**
  *The following class is represent a lock which is used in the system
  */
-public class EngineLock implements AutoCloseable {
+public class EngineLock implements AutoCloseable, Serializable {
 
+    private static final long serialVersionUID = 2961242889564770381L;
     private Map<String, Pair<String, String>> exclusiveLocks;
     private Map<String, Pair<String, String>> sharedLocks;
 


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

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