Roy Golan has uploaded a new change for review.

Change subject: core: on handing over a VM mark it as MigratingTo
......................................................................

core: on handing over a VM mark it as MigratingTo

This patch aims to reflect the VM handover more clear so instead of
moving a VM to Unknown it will move to MigratingTo (unless the host is
*already* NonResponging) so tracking a VM status transition wouldn't
puzzle users (at least would be less confusing and more script friendly
as the script won't discover a VM is suddenly Uknown)

Non responding treatment has been changed to collect also VMs that are
migrating to the host (i.e status MigratingTo and run_on_vds == 
nonRespongindVds)

Change-Id: I0cc072b445ef2616e209fd9dfb30f65abc0ad3da
Signed-off-by: Roy Golan <rgo...@redhat.com>
Bug-Url: https://bugzilla.redhat.com/909932
---
M backend/manager/dbscripts/vms_sp.sql
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsNotRespondingTreatmentCommand.java
M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAO.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAODbFacadeImpl.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java
5 files changed, 55 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/60/13560/1

diff --git a/backend/manager/dbscripts/vms_sp.sql 
b/backend/manager/dbscripts/vms_sp.sql
index 9d27e1e..773e677 100644
--- a/backend/manager/dbscripts/vms_sp.sql
+++ b/backend/manager/dbscripts/vms_sp.sql
@@ -826,9 +826,6 @@
 LANGUAGE plpgsql;
 
 
-
-
-
 Create or replace FUNCTION GetVmsRunningOnVds(v_vds_id UUID) RETURNS SETOF vms
    AS $procedure$
 BEGIN
@@ -840,8 +837,16 @@
 LANGUAGE plpgsql;
 
 
+Create or replace FUNCTION GetVmsMigratingToVds(v_vds_id UUID) RETURNS SETOF 
vms
+   AS $procedure$
+BEGIN
+RETURN QUERY SELECT DISTINCT vms.*
+   FROM vms
+   WHERE migrating_to_vds = v_vds_id
+   AND status = 6;
 
-
+END; $procedure$
+LANGUAGE plpgsql;
 
 
 Create or replace FUNCTION GetVmsRunningOnOrMigratingToVds(v_vds_id UUID) 
RETURNS SETOF vms
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsNotRespondingTreatmentCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsNotRespondingTreatmentCommand.java
index 1ddd3cd..cced02b 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsNotRespondingTreatmentCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsNotRespondingTreatmentCommand.java
@@ -111,6 +111,7 @@
     }
 
     private void MoveVMsToUnknown() {
+        getVmList().addAll(getVmDAO().getAllMigratingToHost(getVdsId()));
         for (VM vm : getVmList()) {
             DestroyVmOnDestination(vm);
             Backend.getInstance()
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAO.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAO.java
index d806755..f845573 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAO.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAO.java
@@ -249,4 +249,11 @@
      * @return
      */
     List<VM> getAllForVmPool(NGuid vmPoolId);
+
+    /**
+     * Retrieves all VMS that are migrating to a certain Host
+     * @param vdsId
+     *            The Host id
+     */
+    List<VM> getAllMigratingToHost(Guid vdsId);
 }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAODbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAODbFacadeImpl.java
index 525156f..5b5572e 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAODbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAODbFacadeImpl.java
@@ -280,6 +280,14 @@
                 .addValue("vm_pool_id", vmPoolId));
     }
 
+    @Override
+    public List<VM> getAllMigratingToHost(Guid vdsId) {
+        return getCallsHandler().executeReadList("GetVmsMigratingToVds",
+                VMRowMapper.instance,
+                getCustomMapSqlParameterSource()
+                        .addValue("vds_id", vdsId));
+    }
+
     static final class VMRowMapper implements RowMapper<VM> {
         public static final VMRowMapper instance = new VMRowMapper();
 
@@ -433,4 +441,5 @@
             return entity;
         }
     }
+
 }
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java
index d90985d..7f34ae1 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java
@@ -52,6 +52,7 @@
 import org.ovirt.engine.core.common.vdscommands.GetVmStatsVDSCommandParameters;
 import 
org.ovirt.engine.core.common.vdscommands.VdsIdAndVdsVDSCommandParametersBase;
 import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.compat.NGuid;
 import org.ovirt.engine.core.compat.RefObject;
 import org.ovirt.engine.core.compat.TransactionScopeOption;
 import org.ovirt.engine.core.dal.dbbroker.DbFacade;
@@ -1520,12 +1521,7 @@
             boolean isInMigration = false;
             if (vmToRemove.getStatus() == VMStatus.MigratingFrom) {
                 isInMigration = true;
-                vmToRemove.setRunOnVds(vmToRemove.getMigratingToVds());
-                log.infoFormat("Setting VM {0} {1} to status unknown", 
vmToRemove.getName(), vmToRemove.getId());
-                ResourceManager.getInstance().InternalSetVmStatus(vmToRemove, 
VMStatus.Unknown);
-                addVmDynamicToList(vmToRemove.getDynamicData());
-                addVmStatisticsToList(vmToRemove.getStatisticsData());
-                addVmInterfaceStatisticsToList(vmToRemove.getInterfaces());
+                handOverVM(vmToRemove);
             } else {
                 clearVm(vmToRemove,
                         VmExitStatus.Error,
@@ -1554,6 +1550,33 @@
         }
     }
 
+    private void handOverVM(VM vmToRemove) {
+        NGuid destinationHostId = vmToRemove.getMigratingToVds();
+
+        // when the destination VDS is NonResponsive put the VM to Uknown like 
the rest of its VMs, else MigratingTo
+        VMStatus newVmStatus =
+                (VDSStatus.NonResponsive == 
getDbFacade().getVdsDao().get(destinationHostId).getStatus())
+                        ? VMStatus.Unknown
+                        : VMStatus.MigratingTo;
+
+        // handing over the VM to the DST by marking it running on it. it will 
now be its SRC host.
+        vmToRemove.setRunOnVds(destinationHostId);
+
+        log.infoFormat("Handing over VM {0} {1} to Host {2}. Setting VM to 
status {3}",
+                vmToRemove.getName(),
+                vmToRemove.getId(),
+                destinationHostId,
+                newVmStatus);
+
+        // if the DST host goes unresponsive it will take care all MigratingTo 
and unknown VMs
+        ResourceManager.getInstance().InternalSetVmStatus(vmToRemove, 
newVmStatus);
+
+        // save the VM state
+        addVmDynamicToList(vmToRemove.getDynamicData());
+        addVmStatisticsToList(vmToRemove.getStatisticsData());
+        addVmInterfaceStatisticsToList(vmToRemove.getInterfaces());
+    }
+
     private boolean inMigrationTo(VmDynamic runningVm, VM vmToUpdate) {
         boolean returnValue = false;
         if (runningVm.getStatus() == VMStatus.MigratingTo) {


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0cc072b445ef2616e209fd9dfb30f65abc0ad3da
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Roy Golan <rgo...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to