Eli Mesika has uploaded a new change for review.

Change subject: core: move VM status handling to VdsManager.
......................................................................

core: move VM status handling to VdsManager.

VMs get stuck in 'Unknown' state when power management is not working

Move the VM state change to 'UnKnown' done in
VdsNotRespondingTreatmentCommand::MoveVMsToUnknown to VdsManager code

The only change is that in order to prevent nested locks we should run
the call to destroyVmOnDestination(vm) method in a separate thread and
then we will have two independent locks.

Change-Id: I7304109b49a0fb8441f9fdc9aee6edb0c654ab0e
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1064860
Signed-off-by: Eli Mesika <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsNotRespondingTreatmentCommand.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsManager.java
2 files changed, 61 insertions(+), 32 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/14/28114/1

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 cfdbc5b..4ba6427 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
@@ -11,13 +11,7 @@
 import org.ovirt.engine.core.common.action.SetStoragePoolStatusParameters;
 import org.ovirt.engine.core.common.action.VdcActionType;
 import org.ovirt.engine.core.common.businessentities.StoragePoolStatus;
-import org.ovirt.engine.core.common.businessentities.VM;
-import org.ovirt.engine.core.common.businessentities.VMStatus;
 import org.ovirt.engine.core.common.businessentities.VdsSpmStatus;
-import 
org.ovirt.engine.core.common.vdscommands.SetVmStatusVDSCommandParameters;
-import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
-import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogDirector;
-import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableBase;
 
 /**
  * @see RestartVdsCommand on why this command is requiring a lock
@@ -92,7 +86,6 @@
 
     @Override
     protected void handleError() {
-        MoveVMsToUnknown();
         // if fence failed on spm, move storage pool to non operational
         if (getVds().getSpmStatus() != VdsSpmStatus.None) {
             log.infoFormat("Fence failed on vds {0} which is spm of pool {1} - 
moving pool to non operational",
@@ -111,31 +104,6 @@
     public AuditLogType getAuditLogTypeValue() {
         return getSucceeded() ? _vmsMovedToUnknown ? 
AuditLogType.VDS_RECOVER_FAILED_VMS_UNKNOWN
                 : AuditLogType.VDS_RECOVER : AuditLogType.VDS_RECOVER_FAILED;
-    }
-
-    private void MoveVMsToUnknown() {
-        addMigratedVmsNotUpYet();
-        for (VM vm : getVmList()) {
-            destroyVmOnDestination(vm);
-            Backend.getInstance()
-                    .getResourceManager()
-                    .RunVdsCommand(VDSCommandType.SetVmStatus,
-                            new SetVmStatusVDSCommandParameters(vm.getId(), 
VMStatus.Unknown));
-            // log VM transition to unknown status
-            AuditLogableBase logable = new AuditLogableBase();
-            logable.setVmId(vm.getId());
-            AuditLogDirector.log(logable, 
AuditLogType.VM_SET_TO_UNKNOWN_STATUS);
-        }
-    }
-
-    private void addMigratedVmsNotUpYet() {
-        for (VM incomingVm : getVmDAO().getAllMigratingToHost(getVdsId())) {
-            if (incomingVm.getStatus() == VMStatus.MigratingTo) {
-                // this VM is finished the migration handover and is running 
on this host now
-                // and should be treated as well.
-                getVmList().add(incomingVm);
-            }
-        }
     }
 
     @Override
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsManager.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsManager.java
index f7cd9e7..4a85fcc 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsManager.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsManager.java
@@ -20,6 +20,8 @@
 import org.ovirt.engine.core.common.businessentities.VDS;
 import org.ovirt.engine.core.common.businessentities.VDSDomainsData;
 import org.ovirt.engine.core.common.businessentities.VDSStatus;
+import org.ovirt.engine.core.common.businessentities.VM;
+import org.ovirt.engine.core.common.businessentities.VMStatus;
 import org.ovirt.engine.core.common.businessentities.VdsDynamic;
 import org.ovirt.engine.core.common.businessentities.VdsNumaNode;
 import org.ovirt.engine.core.common.businessentities.VdsSpmStatus;
@@ -29,7 +31,9 @@
 import org.ovirt.engine.core.common.config.ConfigValues;
 import org.ovirt.engine.core.common.locks.LockingGroup;
 import org.ovirt.engine.core.common.utils.Pair;
+import org.ovirt.engine.core.common.vdscommands.DestroyVmVDSCommandParameters;
 import 
org.ovirt.engine.core.common.vdscommands.SetVdsStatusVDSCommandParameters;
+import 
org.ovirt.engine.core.common.vdscommands.SetVmStatusVDSCommandParameters;
 import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
 import org.ovirt.engine.core.common.vdscommands.VDSReturnValue;
 import 
org.ovirt.engine.core.common.vdscommands.VdsIdAndVdsVDSCommandParametersBase;
@@ -45,6 +49,7 @@
 import org.ovirt.engine.core.utils.lock.LockManagerFactory;
 import org.ovirt.engine.core.utils.log.Log;
 import org.ovirt.engine.core.utils.log.LogFactory;
+import org.ovirt.engine.core.utils.threadpool.ThreadPoolUtil;
 import org.ovirt.engine.core.utils.timer.OnTimerMethodAnnotation;
 import org.ovirt.engine.core.utils.timer.SchedulerUtil;
 import org.ovirt.engine.core.utils.timer.SchedulerUtilQuartzImpl;
@@ -85,6 +90,7 @@
     private boolean isSetNonOperationalExecuted;
     private MonitoringStrategy monitoringStrategy;
     private EngineLock monitoringLock;
+    protected List<VM> mVmList = null;
     public Object getLockObj() {
         return _lockObj;
     }
@@ -695,6 +701,7 @@
                 return true;
             }
             setStatus(VDSStatus.NonResponsive, vds);
+            MoveVMsToUnknown();
             log.infoFormat(
                     "Server failed to respond, vds_id = {0}, vds_name = {1}, 
vm_count = {2}, " +
                     "spm_status = {3}, non-responsive_timeout (seconds) = {4}, 
error = {5}",
@@ -798,4 +805,58 @@
     public boolean isTimeToRetryMaintenance() {
         return System.currentTimeMillis() > nextMaintenanceAttemptTime;
     }
+
+    private void MoveVMsToUnknown() {
+        addMigratedVmsNotUpYet();
+        List<VM> vmList = 
DbFacade.getInstance().getVmDao().getAllRunningForVds(getVdsId());
+        for (VM vm : vmList) {
+            destroyVmOnDestination(vm);
+            ResourceManager.getInstance()
+                    .runVdsCommand(VDSCommandType.SetVmStatus,
+                            new SetVmStatusVDSCommandParameters(vm.getId(), 
VMStatus.Unknown));
+            // log VM transition to unknown status
+            AuditLogableBase logable = new AuditLogableBase();
+            logable.setVmId(vm.getId());
+            AuditLogDirector.log(logable, 
AuditLogType.VM_SET_TO_UNKNOWN_STATUS);
+        }
+    }
+
+    private void destroyVmOnDestination(final VM vm) {
+        // avoid nested locks by doing this in a separate thread
+        ThreadPoolUtil.execute(new Runnable() {
+            @Override
+            public void run() {
+                if (vm.getStatus() == VMStatus.MigratingFrom) {
+                    try {
+                        if (vm.getMigratingToVds() != null) {
+                            ResourceManager.getInstance()
+                                    .runVdsCommand(
+                                            VDSCommandType.DestroyVm,
+                                            new 
DestroyVmVDSCommandParameters(new Guid(vm.getMigratingToVds().toString()), vm
+                                                    .getId(), true, false, 0)
+                                    );
+                            log.infoFormat("Stopped migrating vm: {0} on vds: 
{1}", vm.getName(), vm.getMigratingToVds());
+                        }
+                    } catch (RuntimeException ex) {
+                        log.infoFormat("Could not stop migrating vm: {0} on 
vds: {1}, Error: {2}", vm.getName(),
+                                vm.getMigratingToVds(), ex.getMessage());
+                        // intentionally ignored
+                    }
+                }
+
+            }
+        });
+    }
+
+    private void addMigratedVmsNotUpYet() {
+        List<VM> vmList = 
DbFacade.getInstance().getVmDao().getAllRunningForVds(getVdsId());
+        for (VM incomingVm : vmList) {
+            if (incomingVm.getStatus() == VMStatus.MigratingTo) {
+                // this VM is finished the migration handover and is running 
on this host now
+                // and should be treated as well.
+                vmList.add(incomingVm);
+            }
+        }
+    }
+
 }


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7304109b49a0fb8441f9fdc9aee6edb0c654ab0e
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Eli Mesika <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to