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).
This commit is contained in:
Sudhansu 2015-03-12 17:58:31 +05:30
parent f8e1ff12ab
commit b593657503
2 changed files with 29 additions and 12 deletions

View File

@ -61,6 +61,7 @@ public class RandomAllocator extends AdapterBase implements HostAllocator {
Long clusterId = plan.getClusterId(); Long clusterId = plan.getClusterId();
ServiceOffering offering = vmProfile.getServiceOffering(); ServiceOffering offering = vmProfile.getServiceOffering();
List<Host> suitableHosts = new ArrayList<Host>(); List<Host> suitableHosts = new ArrayList<Host>();
List<Host> hostsCopy = new ArrayList<Host>(hosts);
if (type == Host.Type.Storage) { if (type == Host.Type.Storage) {
return suitableHosts; 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 // list all computing hosts, regardless of whether they support routing...it's random after all
if (hostTag != null) { if (hostTag != null) {
hosts.retainAll(_hostDao.listByHostTag(type, clusterId, podId, dcId, hostTag)); hostsCopy.retainAll(_hostDao.listByHostTag(type, clusterId, podId, dcId, hostTag));
} else { } 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"); s_logger.debug("Random Allocator found " + hostsCopy.size() + " hosts");
if (hosts.size() == 0) { if (hostsCopy.size() == 0) {
return suitableHosts; return suitableHosts;
} }
Collections.shuffle(hosts); Collections.shuffle(hostsCopy);
for (Host host : hosts) { for (Host host : hostsCopy) {
if (suitableHosts.size() == returnUpTo) { if (suitableHosts.size() == returnUpTo) {
break; break;
} }

View File

@ -192,6 +192,7 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator {
VMTemplateVO template = (VMTemplateVO)vmProfile.getTemplate(); VMTemplateVO template = (VMTemplateVO)vmProfile.getTemplate();
Account account = vmProfile.getOwner(); Account account = vmProfile.getOwner();
List<Host> suitableHosts = new ArrayList<Host>(); List<Host> suitableHosts = new ArrayList<Host>();
List<Host> hostsCopy = new ArrayList<Host>(hosts);
if (type == Host.Type.Storage) { if (type == Host.Type.Storage) {
// FirstFitAllocator should be used for user VMs only since it won't care whether the host is capable of // 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); String haVmTag = (String)vmProfile.getParameter(VirtualMachineProfile.Param.HaTag);
if (haVmTag != null) { if (haVmTag != null) {
hosts.retainAll(_hostDao.listByHostTag(type, clusterId, podId, dcId, haVmTag)); hostsCopy.retainAll(_hostDao.listByHostTag(type, clusterId, podId, dcId, haVmTag));
} else { } else {
if (hostTagOnOffering == null && hostTagOnTemplate == null) { if (hostTagOnOffering == null && hostTagOnTemplate == null) {
hosts.retainAll(_resourceMgr.listAllUpAndEnabledNonHAHosts(type, clusterId, podId, dcId)); hostsCopy.retainAll(_resourceMgr.listAllUpAndEnabledNonHAHosts(type, clusterId, podId, dcId));
} else { } else {
if (hasSvcOfferingTag) { 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) { 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()) { if (!hostsCopy.isEmpty()) {
suitableHosts = allocateTo(plan, offering, template, avoid, hosts, returnUpTo, considerReservedCapacity, account); suitableHosts = allocateTo(plan, offering, template, avoid, hostsCopy, returnUpTo, considerReservedCapacity, account);
} }
return suitableHosts; return suitableHosts;