From 2a6307f27208111f0173534c4b26b12d34df8b6b Mon Sep 17 00:00:00 2001 From: Kelven Yang Date: Wed, 15 Jun 2011 18:36:51 -0700 Subject: [PATCH] 1) Remove customer field applied to virtual machine in VMware. 2) always track VM host change in VMware regardless whether or not native HA is enabled --- .../com/cloud/hypervisor/HypervisorGuru.java | 7 ++++ server/src/com/cloud/hypervisor/KVMGuru.java | 5 +++ .../com/cloud/hypervisor/XenServerGuru.java | 5 +++ .../cloud/vm/VirtualMachineManagerImpl.java | 36 +++++++++---------- 4 files changed, 35 insertions(+), 18 deletions(-) diff --git a/api/src/com/cloud/hypervisor/HypervisorGuru.java b/api/src/com/cloud/hypervisor/HypervisorGuru.java index f5a6a40968b..7fee7cb51c3 100644 --- a/api/src/com/cloud/hypervisor/HypervisorGuru.java +++ b/api/src/com/cloud/hypervisor/HypervisorGuru.java @@ -43,4 +43,11 @@ public interface HypervisorGuru extends Adapter { * @return delegated host id if the command will be delegated */ long getCommandHostDelegation(long hostId, Command cmd); + + /** + * @return true if VM can be migrated independently with CloudStack, and therefore CloudStack needs to track and reflect host change + * into CloudStack database, false if CloudStack enforces VM sync logic + * + */ + boolean trackVmHostChange(); } diff --git a/server/src/com/cloud/hypervisor/KVMGuru.java b/server/src/com/cloud/hypervisor/KVMGuru.java index 55562e3e4ee..6af94661df6 100644 --- a/server/src/com/cloud/hypervisor/KVMGuru.java +++ b/server/src/com/cloud/hypervisor/KVMGuru.java @@ -52,4 +52,9 @@ public class KVMGuru extends HypervisorGuruBase implements HypervisorGuru { return to; } + + @Override + public boolean trackVmHostChange() { + return false; + } } diff --git a/server/src/com/cloud/hypervisor/XenServerGuru.java b/server/src/com/cloud/hypervisor/XenServerGuru.java index 0702c4f9b42..7926e7d1c0b 100644 --- a/server/src/com/cloud/hypervisor/XenServerGuru.java +++ b/server/src/com/cloud/hypervisor/XenServerGuru.java @@ -58,4 +58,9 @@ public class XenServerGuru extends HypervisorGuruBase implements HypervisorGuru return to; } + + @Override + public boolean trackVmHostChange() { + return false; + } } diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java index 6b0827bc941..d3c18c5f205 100755 --- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -1416,8 +1416,6 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene Map states = convertToInfos(newStates); Commands commands = new Commands(OnError.Continue); - boolean nativeHA = _agentMgr.isHostNativeHAEnabled(hostId); - for (Map.Entry entry : states.entrySet()) { AgentVmInfo info = entry.getValue(); @@ -1425,7 +1423,8 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene Command command = null; if (vm != null) { - command = compareState(vm, info, false, nativeHA); + HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vm.getHypervisorType()); + command = compareState(vm, info, false, hvGuru.trackVmHostChange()); } else { if (s_logger.isDebugEnabled()) { s_logger.debug("Cleaning up a VM that is no longer found: " + info.name); @@ -1638,8 +1637,6 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene Map infos = convertToInfos(newStates); - boolean nativeHA = _agentMgr.isHostNativeHAEnabled(hostId); - for (VMInstanceVO vm : vms) { AgentVmInfo info = infos.remove(vm.getId()); @@ -1650,30 +1647,33 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene } else { castedVm = info.vm; } + + HypervisorGuru hvGuru = _hvGuruMgr.getGuru(castedVm.getHypervisorType()); - Command command = compareState(castedVm, info, true, nativeHA); + Command command = compareState(castedVm, info, true, hvGuru.trackVmHostChange()); if (command != null) { commands.addCommand(command); } } for (final AgentVmInfo left : infos.values()) { - if (nativeHA) { - for (VirtualMachineGuru vmGuru : _vmGurus.values()) { - VMInstanceVO vm = vmGuru.findByName(left.name); - if (vm == null) { + for (VirtualMachineGuru vmGuru : _vmGurus.values()) { + VMInstanceVO vm = vmGuru.findByName(left.name); + if (vm == null) { + s_logger.warn("Stopping a VM that we have no record of: " + left.name); + commands.addCommand(cleanup(left.name)); + } else { + HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vm.getHypervisorType()); + if(hvGuru.trackVmHostChange()) { + Command command = compareState(vm, left, true, true); + if (command != null) { + commands.addCommand(command); + } + } else { s_logger.warn("Stopping a VM that we have no record of: " + left.name); commands.addCommand(cleanup(left.name)); - } else { - Command command = compareState(vm, left, true, nativeHA); - if (command != null) { - commands.addCommand(command); - } } } - } else { - s_logger.warn("Stopping a VM that we have no record of: " + left.name); - commands.addCommand(cleanup(left.name)); } }