Skip to content

Commit 0da243d

Browse files
authored
Fix issue with allocator not considering subsequent clusters (#10603)
* Fix issue with allocator not considering subsequent clusters * add missing return * remove unused import * update as per inputs
1 parent 0af887b commit 0da243d

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,17 @@ private List<Host> findSuitableHosts(VirtualMachineProfile vmProfile, Deployment
9494
return suitableHosts;
9595
}
9696
String offeringHostTag = offering.getHostTag();
97+
9798
VMTemplateVO template = (VMTemplateVO)vmProfile.getTemplate();
9899
String templateTag = template.getTemplateTag();
99100
String hostTag = null;
100-
if (ObjectUtils.anyNull(offeringHostTag, templateTag)) {
101-
hostTag = offeringHostTag;
102-
hostTag = hostTag == null ? templateTag : String.format("%s, %s", hostTag, templateTag);
103-
logger.debug(String.format("Looking for hosts in dc [%s], pod [%s], cluster [%s] and complying with host tag(s): [%s]", dcId, podId, clusterId, hostTag));
101+
if (ObjectUtils.anyNotNull(offeringHostTag, templateTag)) {
102+
hostTag = ObjectUtils.allNotNull(offeringHostTag, templateTag) ?
103+
String.format("%s, %s", offeringHostTag, templateTag) :
104+
ObjectUtils.firstNonNull(offeringHostTag, templateTag);
105+
logger.debug("Looking for hosts in dc [{}], pod [{}], cluster [{}] and complying with host tag(s): [{}]", dcId, podId, clusterId, hostTag);
104106
} else {
105-
logger.debug("Looking for hosts in dc: " + dcId + " pod:" + podId + " cluster:" + clusterId);
107+
logger.debug("Looking for hosts in dc: {} pod: {} cluster: {}", dcId , podId, clusterId);
106108
}
107109
if (hosts != null) {
108110
// retain all computing hosts, regardless of whether they support routing...it's random after all

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import javax.inject.Inject;
2626
import javax.naming.ConfigurationException;
2727

28-
import com.cloud.utils.exception.CloudRuntimeException;
2928
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
3029
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
3130
import org.springframework.stereotype.Component;
@@ -130,8 +129,8 @@ public List<Host> allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan pla
130129
// FirstFitAllocator should be used for user VMs only since it won't care whether the host is capable of routing or not
131130
return new ArrayList<>();
132131
}
133-
134-
logger.debug("Looking for hosts in zone [{}], pod [{}], cluster [{}]", dcId, podId, clusterId);
132+
String paramAsStringToLog = String.format("zone [%s], pod [%s], cluster [%s]", dcId, podId, clusterId);
133+
logger.debug("Looking for hosts in {}", paramAsStringToLog);
135134

136135
String hostTagOnOffering = offering.getHostTag();
137136
String hostTagOnTemplate = template.getTemplateTag();
@@ -203,8 +202,8 @@ public List<Host> allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan pla
203202

204203

205204
if (clusterHosts.isEmpty()) {
206-
logger.error("No suitable host found for vm [{}] with tags [{}].", vmProfile, hostTagOnOffering);
207-
throw new CloudRuntimeException(String.format("No suitable host found for vm [%s].", vmProfile));
205+
logger.warn("No suitable host found for VM [{}] with tags {} in {}.", vmProfile, hostTagOnOffering, paramAsStringToLog);
206+
return null;
208207
}
209208
// add all hosts that we are not considering to the avoid list
210209
List<HostVO> allhostsInCluster = _hostDao.listAllUpAndEnabledNonHAHosts(type, clusterId, podId, dcId, null);

0 commit comments

Comments
 (0)