Arik Hadas has uploaded a new change for review.

Change subject: core: extract common scheduling code for run & migration
......................................................................

core: extract common scheduling code for run & migration

RunVmCommandBase should be the place for common code for asynchronous
running VM processes. Most of the running VM processes need the
SchedulingManager to select VDS for them, so the call to the
SchedulingManager should reside in RunVmCommandBase.

Change-Id: I84c213d29b5f2193b7bc3eb31b52cfd021e1362c
Signed-off-by: Arik Hadas <aha...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MigrateVmCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommandBase.java
3 files changed, 51 insertions(+), 45 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/02/22102/17

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MigrateVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MigrateVmCommand.java
index 1452c03..bf7577e 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MigrateVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MigrateVmCommand.java
@@ -6,7 +6,6 @@
 
 import org.ovirt.engine.core.bll.job.ExecutionHandler;
 import org.ovirt.engine.core.bll.scheduling.SchedulingManager;
-import org.ovirt.engine.core.bll.scheduling.VdsFreeMemoryChecker;
 import org.ovirt.engine.core.bll.snapshots.SnapshotsValidator;
 import org.ovirt.engine.core.bll.validator.DiskImagesValidator;
 import org.ovirt.engine.core.bll.validator.LocalizedVmStatus;
@@ -99,25 +98,13 @@
 
     protected void initVdss() {
         setVdsIdRef(getVm().getRunOnVds());
-        VDS destVds = getDestinationVds();
-        Guid vdsToRunOn =
-                SchedulingManager.getInstance().schedule(getVdsGroup(),
-                        getVm(),
-                        getVdsBlackList(),
-                        getVdsWhiteList(),
-                        destVds == null ? null : destVds.getId(),
-                        new ArrayList<String>(),
-                        new VdsFreeMemoryChecker(this),
-                        getCorrelationId());
-        setVdsDestinationId(vdsToRunOn);
-        if (vdsToRunOn != null && !Guid.Empty.equals(vdsToRunOn)) {
-            getRunVdssList().add(vdsToRunOn);
-        }
-        VmHandler.updateVmGuestAgentVersion(getVm());
-        // make _destinationVds null in order to refresh it from db in case it
-        // changed.
+        // make _destinationVds null in order to refresh it from
+        // db in case it changed.
         _destinationVds = null;
-        if (vdsDestinationId != null && vdsDestinationId.equals(Guid.Empty)) {
+
+        setVdsDestinationId(schedule());
+
+        if (Guid.isNullOrEmpty(vdsDestinationId)) {
             throw new 
VdcBLLException(VdcBllErrors.RESOURCE_MANAGER_CANT_ALLOC_VDS_MIGRATION);
         }
 
@@ -128,6 +115,7 @@
 
     @Override
     protected void executeVmCommand() {
+        VmHandler.updateVmGuestAgentVersion(getVm());
         initVdss();
         perform();
         setSucceeded(true);
@@ -425,8 +413,11 @@
         return builder.toString();
     }
 
-    // hosts that cannot be selected for scheduling (failed hosts + VM source 
host)
-    private List<Guid> getVdsBlackList() {
+    /**
+     *  hosts that cannot be selected for scheduling (failed hosts + VM source 
host)
+     */
+    @Override
+    protected List<Guid> getVdsBlackList() {
         List<Guid> blackList = new ArrayList<Guid>(getRunVdssList());
         if (getVdsId() != null) {
             blackList.add(getVdsId());
@@ -434,8 +425,11 @@
         return blackList;
     }
 
-    // initial hosts list picked for scheduling, currently
-    // passed by load balancing process.
+    /**
+     * initial hosts list picked for scheduling, currently
+     * passed by load balancing process.
+     */
+    @Override
     protected List<Guid> getVdsWhiteList() {
         return getParameters().getInitialHosts();
     }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java
index 2d3947a..7e4d280 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java
@@ -20,8 +20,6 @@
 import org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter;
 import org.ovirt.engine.core.bll.quota.QuotaVdsDependent;
 import org.ovirt.engine.core.bll.quota.QuotaVdsGroupConsumptionParameter;
-import org.ovirt.engine.core.bll.scheduling.SchedulingManager;
-import org.ovirt.engine.core.bll.scheduling.VdsFreeMemoryChecker;
 import org.ovirt.engine.core.bll.utils.PermissionSubject;
 import org.ovirt.engine.core.bll.utils.VmDeviceUtils;
 import org.ovirt.engine.core.bll.validator.RunVmValidator;
@@ -641,8 +639,10 @@
         disksFetched = true;
     }
 
-    protected void initVds() {
-        initVds(schedule());
+    protected Guid initVds() {
+        Guid selectedVdsId = schedule();
+        initVds(selectedVdsId);
+        return selectedVdsId;
     }
 
     protected void initVds(Guid vdsId) {
@@ -657,22 +657,6 @@
         if (getVds() == null) {
             throw new 
VdcBLLException(VdcBllErrors.RESOURCE_MANAGER_VDS_NOT_FOUND);
         }
-    }
-
-    protected Guid schedule() {
-        Guid vdsId = SchedulingManager.getInstance().schedule(
-                getVdsGroup(),
-                getVm(),
-                getRunVdssList(),
-                getVdsWhiteList(),
-                getDestinationVds() != null ? getDestinationVds().getId() : 
null,
-                new ArrayList<String>(),
-                new VdsFreeMemoryChecker(this),
-                getCorrelationId());
-        if (!Guid.isNullOrEmpty(vdsId)) {
-            getRunVdssList().add(vdsId);
-        }
-        return vdsId;
     }
 
     /**
@@ -771,7 +755,7 @@
         if (!runVmValidator.canRunVm(
                 getReturnValue().getCanDoActionMessages(),
                 getStoragePool(),
-                getRunVdssList(),
+                getVdsBlackList(),
                 getVdsWhiteList(),
                 getDestinationVds() != null ? getDestinationVds().getId() : 
null,
                 getVdsGroup())) {
@@ -985,8 +969,16 @@
         }
     }
 
-    // initial white list (null == all hosts)
+    /**
+     * initial white list (null == all hosts)
+     */
+    @Override
     protected List<Guid> getVdsWhiteList() {
         return null;
     }
+
+    @Override
+    protected List<Guid> getVdsBlackList() {
+        return getRunVdssList();
+    }
 }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommandBase.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommandBase.java
index c34ba90..39da430 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommandBase.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommandBase.java
@@ -15,6 +15,8 @@
 import org.ovirt.engine.core.bll.job.ExecutionHandler;
 import org.ovirt.engine.core.bll.job.JobRepositoryFactory;
 import org.ovirt.engine.core.bll.scheduling.RunVmDelayer;
+import org.ovirt.engine.core.bll.scheduling.SchedulingManager;
+import org.ovirt.engine.core.bll.scheduling.VdsFreeMemoryChecker;
 import org.ovirt.engine.core.bll.snapshots.SnapshotsValidator;
 import org.ovirt.engine.core.bll.storage.StorageHelperDirector;
 import 
org.ovirt.engine.core.common.action.RemoveVmHibernationVolumesParameters;
@@ -69,6 +71,8 @@
     }
 
     protected abstract VDS getDestinationVds();
+    protected abstract List<Guid> getVdsWhiteList();
+    protected abstract List<Guid> getVdsBlackList();
 
     public SnapshotsValidator getSnapshotsValidator() {
         return snapshotsValidator;
@@ -81,6 +85,22 @@
         return runVdsList;
     }
 
+    protected Guid schedule() {
+        Guid vdsId = SchedulingManager.getInstance().schedule(
+                getVdsGroup(),
+                getVm(),
+                getVdsBlackList(),
+                getVdsWhiteList(),
+                getDestinationVds() != null ? getDestinationVds().getId() : 
null,
+                new ArrayList<String>(),
+                new VdsFreeMemoryChecker(this),
+                getCorrelationId());
+        if (!Guid.isNullOrEmpty(vdsId)) {
+            getRunVdssList().add(vdsId);
+        }
+        return vdsId;
+    }
+
     @Override
     public void rerun() {
         Guid vdsId = getDestinationVds() != null ? getDestinationVds().getId() 
: getCurrentVdsId();


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I84c213d29b5f2193b7bc3eb31b52cfd021e1362c
Gerrit-PatchSet: 17
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Arik Hadas <aha...@redhat.com>
Gerrit-Reviewer: Arik Hadas <aha...@redhat.com>
Gerrit-Reviewer: Gilad Chaplik <gchap...@redhat.com>
Gerrit-Reviewer: Omer Frenkel <ofren...@redhat.com>
Gerrit-Reviewer: Roy Golan <rgo...@redhat.com>
Gerrit-Reviewer: oVirt Jenkins CI Server
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to