Ravi Nori has uploaded a new change for review.

Change subject: engine : Introduction of CommandScheduler and 
AsyncCommandCallBack
......................................................................

engine : Introduction of CommandScheduler and AsyncCommandCallBack

Introduces CommandScheduler that execute the given action with
the given parameters using an ExecuterService in a seperate
thread. The results of the command execution is passed back
to the AsyncCommandCallBack interface.

Change-Id: I70922b5b836971eca76dee26ba67b7023d546fe6
Bug-Url: https://bugzilla.redhat.com/1083769
Signed-off-by: Ravi Nori <rn...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/CommandCoordinatorImpl.java
A 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/interfaces/AsyncCommandCallBack.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/interfaces/CommandCoordinator.java
A 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/interfaces/CommandScheduler.java
M 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/BackwardCompatibilityTaskCreationTest.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java
M packaging/dbscripts/upgrade/pre_upgrade/0000_config.sql
7 files changed, 46 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/54/28154/1

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 660cf06..4e1202f 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
@@ -3,6 +3,8 @@
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+
 import org.ovirt.engine.core.bll.Backend;
 import org.ovirt.engine.core.bll.CommandBase;
 import org.ovirt.engine.core.bll.CommandsFactory;
@@ -10,6 +12,7 @@
 import org.ovirt.engine.core.bll.interfaces.BackendInternal;
 import org.ovirt.engine.core.bll.job.ExecutionContext;
 import org.ovirt.engine.core.bll.job.ExecutionHandler;
+import org.ovirt.engine.core.bll.tasks.interfaces.AsyncCommandCallBack;
 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;
@@ -24,6 +27,8 @@
 import org.ovirt.engine.core.common.businessentities.AsyncTaskStatusEnum;
 import org.ovirt.engine.core.common.businessentities.AsyncTasks;
 import org.ovirt.engine.core.common.businessentities.CommandEntity;
+import org.ovirt.engine.core.common.config.Config;
+import org.ovirt.engine.core.common.config.ConfigValues;
 import org.ovirt.engine.core.common.job.ExternalSystemType;
 import org.ovirt.engine.core.common.job.Step;
 import org.ovirt.engine.core.common.job.StepEnum;
@@ -46,6 +51,7 @@
 public class CommandCoordinatorImpl extends CommandCoordinator {
 
     private static final Log log = LogFactory.getLog(CommandCoordinator.class);
+    private static final ScheduledThreadPoolExecutor executor = new 
ScheduledThreadPoolExecutor(Config.<Integer> 
getValue(ConfigValues.CommandCoordinatorThreadPoolSize));
     private CommandsCache commandsCache;
 
     CommandCoordinatorImpl() {
@@ -244,6 +250,24 @@
     }
 
     /**
+     * Executes the action using a Thread Pool. Used when the calling function
+     * would like the execute the command with no delay
+     */
+    public void executeAsyncCommand(final VdcActionType actionType,
+                                    final VdcActionParametersBase parameters,
+                                    final AsyncCommandCallBack callBack) {
+        executor.execute(new Runnable() {
+            @Override
+            public void run() {
+                VdcReturnValueBase result = 
Backend.getInstance().runAction(actionType, parameters);
+                if (callBack != null) {
+                    callBack.setExecutionResult(result);
+                }
+            }
+        });
+    }
+
+    /**
      * Create the {@link SPMAsyncTask} object to be run
      * @param taskId the id of the async task place holder in the database
      * @param asyncTaskCreationInfo Info on how to create the task
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/interfaces/AsyncCommandCallBack.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/interfaces/AsyncCommandCallBack.java
new file mode 100644
index 0000000..2749738
--- /dev/null
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/interfaces/AsyncCommandCallBack.java
@@ -0,0 +1,7 @@
+package org.ovirt.engine.core.bll.tasks.interfaces;
+
+import org.ovirt.engine.core.common.action.VdcReturnValueBase;
+
+public interface AsyncCommandCallBack {
+    public abstract void setExecutionResult(VdcReturnValueBase result);
+}
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/interfaces/CommandCoordinator.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/interfaces/CommandCoordinator.java
index 8c1741f..f3f75fa 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/interfaces/CommandCoordinator.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/interfaces/CommandCoordinator.java
@@ -1,4 +1,4 @@
 package org.ovirt.engine.core.bll.tasks.interfaces;
 
-public abstract class CommandCoordinator implements EndActionCallBack, 
TaskHelper, Poller, CommandCRUDOperations, AsyncTaskCRUDOperations {
+public abstract class CommandCoordinator implements EndActionCallBack, 
TaskHelper, Poller, CommandCRUDOperations, AsyncTaskCRUDOperations, 
CommandScheduler {
 }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/interfaces/CommandScheduler.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/interfaces/CommandScheduler.java
new file mode 100644
index 0000000..a6ecb94
--- /dev/null
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/interfaces/CommandScheduler.java
@@ -0,0 +1,8 @@
+package org.ovirt.engine.core.bll.tasks.interfaces;
+
+import org.ovirt.engine.core.common.action.VdcActionParametersBase;
+import org.ovirt.engine.core.common.action.VdcActionType;
+
+public interface CommandScheduler {
+    public abstract void executeAsyncCommand(VdcActionType actionType, 
VdcActionParametersBase parameters, AsyncCommandCallBack callBack);
+}
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/BackwardCompatibilityTaskCreationTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/BackwardCompatibilityTaskCreationTest.java
index a893ce3..e84f354 100644
--- 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/BackwardCompatibilityTaskCreationTest.java
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/BackwardCompatibilityTaskCreationTest.java
@@ -68,7 +68,8 @@
     public static final MockConfigRule mcr = new MockConfigRule(
             mockConfig(ConfigValues.AsyncTaskPollingRate, 10),
             mockConfig(ConfigValues.AsyncTaskStatusCacheRefreshRateInSeconds, 
10),
-            mockConfig(ConfigValues.AsyncTaskStatusCachingTimeInMinutes, 10)
+            mockConfig(ConfigValues.AsyncTaskStatusCachingTimeInMinutes, 10),
+            mockConfig(ConfigValues.CommandCoordinatorThreadPoolSize, 10)
             );
 
     @ClassRule
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java
index 6b346f4..6ff05c7 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java
@@ -91,6 +91,9 @@
     @TypeConverterAttribute(Integer.class)
     @DefaultValueAttribute("30")
     AuditLogAgingThreshold,
+    @TypeConverterAttribute(Integer.class)
+    @DefaultValueAttribute("10")
+    CommandCoordinatorThreadPoolSize,
     @TypeConverterAttribute(Date.class)
     @DefaultValueAttribute("03:35:35")
     CommandEntityCleanupTime,
diff --git a/packaging/dbscripts/upgrade/pre_upgrade/0000_config.sql 
b/packaging/dbscripts/upgrade/pre_upgrade/0000_config.sql
index 0812219..7b98696 100644
--- a/packaging/dbscripts/upgrade/pre_upgrade/0000_config.sql
+++ b/packaging/dbscripts/upgrade/pre_upgrade/0000_config.sql
@@ -54,6 +54,7 @@
 select fn_db_add_config_value('AuditLogAgingThreshold','30','general');
 select fn_db_add_config_value('AuditLogCleanupTime','03:35:35','general');
 select fn_db_add_config_value('BootstrapMinimalVdsmVersion','4.9','general');
+select 
fn_db_add_config_value('CommandCoordinatorThreadPoolSize','10','general');
 select fn_db_add_config_value('CommandEntityAgingThreshold','30','general');
 select fn_db_add_config_value('CommandEntityCleanupTime','03:35:35','general');
 select fn_db_add_config_value('CpuPinMigrationEnabled','true','general');


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

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