When a VM is force deleted and the host is not available then CS simply marks the state in db as "Destroyed/Expunging". The VM is still running on the host and once it becomes available again there is a discrepancy in state of the VM. In this scenario the VM is removed from the host when the next full cluster sync happens.

This commit is contained in:
Koushik Das 2012-09-13 16:34:53 +05:30 committed by Abhinandan Prateek
parent 5532f58bbc
commit a9559cbb67

View File

@ -1745,7 +1745,6 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
set_vms.addAll(_vmDao.listLHByClusterId(clusterId)); set_vms.addAll(_vmDao.listLHByClusterId(clusterId));
for (VMInstanceVO vm : set_vms) { for (VMInstanceVO vm : set_vms) {
if (vm.isRemoved() || vm.getState() == State.Destroyed || vm.getState() == State.Expunging) continue;
AgentVmInfo info = infos.remove(vm.getId()); AgentVmInfo info = infos.remove(vm.getId());
VMInstanceVO castedVm = null; VMInstanceVO castedVm = null;
if ((info == null && (vm.getState() == State.Running || vm.getState() == State.Starting)) if ((info == null && (vm.getState() == State.Running || vm.getState() == State.Starting))
@ -1789,23 +1788,26 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
e.printStackTrace(); e.printStackTrace();
} }
} }
else if (info != null && (vm.getState() == State.Stopped || vm.getState() == State.Stopping)) { else if (info != null && (vm.getState() == State.Stopped || vm.getState() == State.Stopping
Host host = _hostDao.findByGuid(info.getHostUuid()); || vm.isRemoved() || vm.getState() == State.Destroyed || vm.getState() == State.Expunging)) {
if (host != null){ Host host = _hostDao.findByGuid(info.getHostUuid());
s_logger.warn("Stopping a VM which is stopped/stopping " + info.name); if (host != null){
vm.setState(State.Stopped); // set it as stop and clear it from host s_logger.warn("Stopping a VM which is stopped/stopping/destroyed/expunging " + info.name);
vm.setHostId(null); if (vm.getState() == State.Stopped || vm.getState() == State.Stopping) {
_vmDao.persist(vm); vm.setState(State.Stopped); // set it as stop and clear it from host
try { vm.setHostId(null);
Answer answer = _agentMgr.send(host.getId(), cleanup(info.name)); _vmDao.persist(vm);
if (!answer.getResult()) { }
s_logger.warn("Unable to stop a VM due to " + answer.getDetails()); try {
} Answer answer = _agentMgr.send(host.getId(), cleanup(info.name));
} if (!answer.getResult()) {
catch (Exception e) { s_logger.warn("Unable to stop a VM due to " + answer.getDetails());
s_logger.warn("Unable to stop a VM due to " + e.getMessage()); }
} }
} catch (Exception e) {
s_logger.warn("Unable to stop a VM due to " + e.getMessage());
}
}
} }
else else
// host id can change // host id can change
@ -1831,7 +1833,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
} }
for (final AgentVmInfo left : infos.values()) { for (final AgentVmInfo left : infos.values()) {
if (VirtualMachineName.isValidVmName(left.name)) continue; // if the vm follows cloudstack naming ignore it for stopping if (!VirtualMachineName.isValidVmName(left.name)) continue; // if the vm doesn't follow CS naming ignore it for stopping
try { try {
Host host = _hostDao.findByGuid(left.getHostUuid()); Host host = _hostDao.findByGuid(left.getHostUuid());
if (host != null){ if (host != null){