Skip to content

Commit b593657

Browse files
author
Sudhansu
committed
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).
1 parent f8e1ff1 commit b593657

2 files changed

Lines changed: 29 additions & 12 deletions

File tree

plugins/host-allocators/random/src/com/cloud/agent/manager/allocator/impl/RandomAllocator.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public List<Host> allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan pla
6161
Long clusterId = plan.getClusterId();
6262
ServiceOffering offering = vmProfile.getServiceOffering();
6363
List<Host> suitableHosts = new ArrayList<Host>();
64+
List<Host> hostsCopy = new ArrayList<Host>(hosts);
6465

6566
if (type == Host.Type.Storage) {
6667
return suitableHosts;
@@ -75,18 +76,18 @@ public List<Host> allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan pla
7576

7677
// list all computing hosts, regardless of whether they support routing...it's random after all
7778
if (hostTag != null) {
78-
hosts.retainAll(_hostDao.listByHostTag(type, clusterId, podId, dcId, hostTag));
79+
hostsCopy.retainAll(_hostDao.listByHostTag(type, clusterId, podId, dcId, hostTag));
7980
} else {
80-
hosts.retainAll(_resourceMgr.listAllUpAndEnabledHosts(type, clusterId, podId, dcId));
81+
hostsCopy.retainAll(_resourceMgr.listAllUpAndEnabledHosts(type, clusterId, podId, dcId));
8182
}
8283

83-
s_logger.debug("Random Allocator found " + hosts.size() + " hosts");
84-
if (hosts.size() == 0) {
84+
s_logger.debug("Random Allocator found " + hostsCopy.size() + " hosts");
85+
if (hostsCopy.size() == 0) {
8586
return suitableHosts;
8687
}
8788

88-
Collections.shuffle(hosts);
89-
for (Host host : hosts) {
89+
Collections.shuffle(hostsCopy);
90+
for (Host host : hostsCopy) {
9091
if (suitableHosts.size() == returnUpTo) {
9192
break;
9293
}

server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ public List<Host> allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan pla
192192
VMTemplateVO template = (VMTemplateVO)vmProfile.getTemplate();
193193
Account account = vmProfile.getOwner();
194194
List<Host> suitableHosts = new ArrayList<Host>();
195+
List<Host> hostsCopy = new ArrayList<Host>(hosts);
195196

196197
if (type == Host.Type.Storage) {
197198
// FirstFitAllocator should be used for user VMs only since it won't care whether the host is capable of
@@ -206,23 +207,38 @@ public List<Host> allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan pla
206207

207208
String haVmTag = (String)vmProfile.getParameter(VirtualMachineProfile.Param.HaTag);
208209
if (haVmTag != null) {
209-
hosts.retainAll(_hostDao.listByHostTag(type, clusterId, podId, dcId, haVmTag));
210+
hostsCopy.retainAll(_hostDao.listByHostTag(type, clusterId, podId, dcId, haVmTag));
210211
} else {
211212
if (hostTagOnOffering == null && hostTagOnTemplate == null) {
212-
hosts.retainAll(_resourceMgr.listAllUpAndEnabledNonHAHosts(type, clusterId, podId, dcId));
213+
hostsCopy.retainAll(_resourceMgr.listAllUpAndEnabledNonHAHosts(type, clusterId, podId, dcId));
213214
} else {
214215
if (hasSvcOfferingTag) {
215-
hosts.retainAll(_hostDao.listByHostTag(type, clusterId, podId, dcId, hostTagOnOffering));
216+
if (s_logger.isDebugEnabled()) {
217+
s_logger.debug("Looking for hosts having tag specified on SvcOffering:" + hostTagOnOffering);
218+
}
219+
hostsCopy.retainAll(_hostDao.listByHostTag(type, clusterId, podId, dcId, hostTagOnOffering));
220+
221+
if (s_logger.isDebugEnabled()) {
222+
s_logger.debug("Hosts with tag '" + hostTagOnOffering + "' are:" + hostsCopy);
223+
}
216224
}
217225

218226
if (hasTemplateTag) {
219-
hosts.retainAll(_hostDao.listByHostTag(type, clusterId, podId, dcId, hostTagOnTemplate));
227+
if (s_logger.isDebugEnabled()) {
228+
s_logger.debug("Looking for hosts having tag specified on Template:" + hostTagOnTemplate);
229+
}
230+
231+
hostsCopy.retainAll(_hostDao.listByHostTag(type, clusterId, podId, dcId, hostTagOnTemplate));
232+
233+
if (s_logger.isDebugEnabled()) {
234+
s_logger.debug("Hosts with tag '" + hostTagOnTemplate + "' are:" + hostsCopy);
235+
}
220236
}
221237
}
222238
}
223239

224-
if (!hosts.isEmpty()) {
225-
suitableHosts = allocateTo(plan, offering, template, avoid, hosts, returnUpTo, considerReservedCapacity, account);
240+
if (!hostsCopy.isEmpty()) {
241+
suitableHosts = allocateTo(plan, offering, template, avoid, hostsCopy, returnUpTo, considerReservedCapacity, account);
226242
}
227243

228244
return suitableHosts;

0 commit comments

Comments
 (0)