Ravi Nori has uploaded a new change for review. Change subject: engine : Add quartz to handle AsycCommands ......................................................................
engine : Add quartz to handle AsycCommands Adding a call back method checkUpdateCmdStatus to CommandCallBack which is responsible for updating the status of the command. The call back method is periodically called on commands that have not succeeded using the quartz framework Persisting call back and loading them on server restart will be introduced in latter patches Change-Id: I66b1e5945884aec412ba412e39266129004d7218 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/CommandExecutor.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/interfaces/CommandCallBack.java M packaging/dbscripts/upgrade/pre_upgrade/0000_config.sql 3 files changed, 49 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/60/28160/1 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 836dec6..5e511f6 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,10 +14,16 @@ import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.utils.log.Log; import org.ovirt.engine.core.utils.log.LogFactory; +import org.ovirt.engine.core.utils.timer.OnTimerMethodAnnotation; +import org.ovirt.engine.core.utils.timer.SchedulerUtil; +import org.ovirt.engine.core.utils.timer.SchedulerUtilQuartzImpl; import javax.naming.InitialContext; import javax.naming.NamingException; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.concurrent.TimeUnit; class CommandExecutor { @@ -27,9 +33,45 @@ private static final Log log = LogFactory.getLog(CommandExecutor.class); private final CommandCoordinator coco; + private final Map<Guid, CommandCallBack> cmdCallBackMap = new ConcurrentHashMap<>(); CommandExecutor(CommandCoordinator coco) { this.coco = coco; + + SchedulerUtil scheduler = SchedulerUtilQuartzImpl.getInstance(); + scheduler.scheduleAFixedDelayJob(this, "_timer_Elapsed", new Class[]{}, + new Object[]{}, Config.<Integer>getValue(ConfigValues.AsyncCommandPollingRate), + Config.<Integer>getValue(ConfigValues.AsyncCommandPollingRate), TimeUnit.SECONDS); + } + + @OnTimerMethodAnnotation("_timer_Elapsed") + public synchronized void _timer_Elapsed() { + clearSucceededCommands(); + if (thereAreCommandsToPoll()) { + for (Guid cmdId : cmdCallBackMap.keySet()) { + CommandCallBack callBack = cmdCallBackMap.get(cmdId); + CommandStatus status = coco.getCommandStatus(cmdId); + if (!CommandStatus.SUCCEEDED.equals(status) && !CommandStatus.FAILED.equals(status)) { + callBack.checkUpdateCmdStatus(cmdId); + } + } + } + } + + private void clearSucceededCommands() { + for (Guid cmdId : cmdCallBackMap.keySet()) { + if (CommandStatus.SUCCEEDED.equals(coco.getCommandStatus(cmdId))) { + cmdCallBackMap.remove(cmdId); + } + } + } + private boolean thereAreCommandsToPoll() { + for (Guid cmdId : cmdCallBackMap.keySet()) { + if (!CommandStatus.SUCCEEDED.equals(coco.getCommandStatus(cmdId))) { + return true; + } + } + return false; } public Guid executeAsyncCommand(final VdcActionType actionType, @@ -47,6 +89,10 @@ private void executeCommand(final CommandBase<?> command, final CommandCallBack callBack) { + if (callBack != null) { + command.persistCommand(command.getParameters().getParentCommand()); + cmdCallBackMap.put(command.getCommandId(), callBack); + } VdcReturnValueBase result = getBackendCommandObjectsHandler().runAction(command, null); if (callBack != null) { if (result.getSucceeded()) { diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/interfaces/CommandCallBack.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/interfaces/CommandCallBack.java index 77a1aa1..ab6979c 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/interfaces/CommandCallBack.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/interfaces/CommandCallBack.java @@ -1,7 +1,9 @@ package org.ovirt.engine.core.bll.tasks.interfaces; import org.ovirt.engine.core.common.action.VdcReturnValueBase; +import org.ovirt.engine.core.compat.Guid; public interface CommandCallBack { public abstract void setExecutionResult(VdcReturnValueBase result); + public abstract void checkUpdateCmdStatus(Guid cmdId); } diff --git a/packaging/dbscripts/upgrade/pre_upgrade/0000_config.sql b/packaging/dbscripts/upgrade/pre_upgrade/0000_config.sql index 7b98696..9d1aaa0 100644 --- a/packaging/dbscripts/upgrade/pre_upgrade/0000_config.sql +++ b/packaging/dbscripts/upgrade/pre_upgrade/0000_config.sql @@ -48,6 +48,7 @@ select fn_db_add_config_value('AllowDuplicateMacAddresses','false','general'); select fn_db_add_config_value('ApplicationMode','255','general'); select fn_db_add_config_value('AsyncTaskPollingRate','10','general'); +select fn_db_add_config_value('AsyncCommandPollingRate','10','general'); select fn_db_add_config_value('AsyncTaskStatusCacheRefreshRateInSeconds','30','general'); select fn_db_add_config_value('AsyncTaskStatusCachingTimeInMinutes','1','general'); select fn_db_add_config_value('AsyncTaskZombieTaskLifeInMinutes','300','general'); -- To view, visit http://gerrit.ovirt.org/28160 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I66b1e5945884aec412ba412e39266129004d7218 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