BUG-ID: CLOUDSTACK-8484 - Hosts without tag are not listed while listing the hosts for migration for instance with tag
While preparing the suitable hosts we are accidentally removing the incompatible (host does not have host tag) hosts from otherhost list( incorrect use of List.retainAll). Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/b5936575 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/b5936575 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/b5936575 Branch: refs/heads/reporter Commit: b593657503c4743c6e74c76c083df744ed0bb2ae Parents: f8e1ff1 Author: Sudhansu <sudhansu.s...@citrix.com> Authored: Thu Mar 12 17:58:31 2015 +0530 Committer: Sudhansu <sudhansu.s...@citrix.com> Committed: Fri Jul 3 11:41:55 2015 +0530 ---------------------------------------------------------------------- .../manager/allocator/impl/RandomAllocator.java | 13 ++++----- .../allocator/impl/FirstFitAllocator.java | 28 +++++++++++++++----- 2 files changed, 29 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b5936575/plugins/host-allocators/random/src/com/cloud/agent/manager/allocator/impl/RandomAllocator.java ---------------------------------------------------------------------- diff --git a/plugins/host-allocators/random/src/com/cloud/agent/manager/allocator/impl/RandomAllocator.java b/plugins/host-allocators/random/src/com/cloud/agent/manager/allocator/impl/RandomAllocator.java index 5bdf4f1..390a8af 100755 --- a/plugins/host-allocators/random/src/com/cloud/agent/manager/allocator/impl/RandomAllocator.java +++ b/plugins/host-allocators/random/src/com/cloud/agent/manager/allocator/impl/RandomAllocator.java @@ -61,6 +61,7 @@ public class RandomAllocator extends AdapterBase implements HostAllocator { Long clusterId = plan.getClusterId(); ServiceOffering offering = vmProfile.getServiceOffering(); List<Host> suitableHosts = new ArrayList<Host>(); + List<Host> hostsCopy = new ArrayList<Host>(hosts); if (type == Host.Type.Storage) { return suitableHosts; @@ -75,18 +76,18 @@ public class RandomAllocator extends AdapterBase implements HostAllocator { // list all computing hosts, regardless of whether they support routing...it's random after all if (hostTag != null) { - hosts.retainAll(_hostDao.listByHostTag(type, clusterId, podId, dcId, hostTag)); + hostsCopy.retainAll(_hostDao.listByHostTag(type, clusterId, podId, dcId, hostTag)); } else { - hosts.retainAll(_resourceMgr.listAllUpAndEnabledHosts(type, clusterId, podId, dcId)); + hostsCopy.retainAll(_resourceMgr.listAllUpAndEnabledHosts(type, clusterId, podId, dcId)); } - s_logger.debug("Random Allocator found " + hosts.size() + " hosts"); - if (hosts.size() == 0) { + s_logger.debug("Random Allocator found " + hostsCopy.size() + " hosts"); + if (hostsCopy.size() == 0) { return suitableHosts; } - Collections.shuffle(hosts); - for (Host host : hosts) { + Collections.shuffle(hostsCopy); + for (Host host : hostsCopy) { if (suitableHosts.size() == returnUpTo) { break; } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b5936575/server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java b/server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java index a746eb7..990b77b 100755 --- a/server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java +++ b/server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java @@ -192,6 +192,7 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator { VMTemplateVO template = (VMTemplateVO)vmProfile.getTemplate(); Account account = vmProfile.getOwner(); List<Host> suitableHosts = new ArrayList<Host>(); + List<Host> hostsCopy = new ArrayList<Host>(hosts); if (type == Host.Type.Storage) { // FirstFitAllocator should be used for user VMs only since it won't care whether the host is capable of @@ -206,23 +207,38 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator { String haVmTag = (String)vmProfile.getParameter(VirtualMachineProfile.Param.HaTag); if (haVmTag != null) { - hosts.retainAll(_hostDao.listByHostTag(type, clusterId, podId, dcId, haVmTag)); + hostsCopy.retainAll(_hostDao.listByHostTag(type, clusterId, podId, dcId, haVmTag)); } else { if (hostTagOnOffering == null && hostTagOnTemplate == null) { - hosts.retainAll(_resourceMgr.listAllUpAndEnabledNonHAHosts(type, clusterId, podId, dcId)); + hostsCopy.retainAll(_resourceMgr.listAllUpAndEnabledNonHAHosts(type, clusterId, podId, dcId)); } else { if (hasSvcOfferingTag) { - hosts.retainAll(_hostDao.listByHostTag(type, clusterId, podId, dcId, hostTagOnOffering)); + if (s_logger.isDebugEnabled()) { + s_logger.debug("Looking for hosts having tag specified on SvcOffering:" + hostTagOnOffering); + } + hostsCopy.retainAll(_hostDao.listByHostTag(type, clusterId, podId, dcId, hostTagOnOffering)); + + if (s_logger.isDebugEnabled()) { + s_logger.debug("Hosts with tag '" + hostTagOnOffering + "' are:" + hostsCopy); + } } if (hasTemplateTag) { - hosts.retainAll(_hostDao.listByHostTag(type, clusterId, podId, dcId, hostTagOnTemplate)); + if (s_logger.isDebugEnabled()) { + s_logger.debug("Looking for hosts having tag specified on Template:" + hostTagOnTemplate); + } + + hostsCopy.retainAll(_hostDao.listByHostTag(type, clusterId, podId, dcId, hostTagOnTemplate)); + + if (s_logger.isDebugEnabled()) { + s_logger.debug("Hosts with tag '" + hostTagOnTemplate + "' are:" + hostsCopy); + } } } } - if (!hosts.isEmpty()) { - suitableHosts = allocateTo(plan, offering, template, avoid, hosts, returnUpTo, considerReservedCapacity, account); + if (!hostsCopy.isEmpty()) { + suitableHosts = allocateTo(plan, offering, template, avoid, hostsCopy, returnUpTo, considerReservedCapacity, account); } return suitableHosts;