Skip to content

Commit d544c95

Browse files
BryanMLimadhslove
authored andcommitted
Fix allocation of VMs with multiple clusters (apache#8611)
* Fix allocation of VMs with multiple clusters * Readd debug guard
1 parent fc3cd05 commit d544c95

File tree

5 files changed

+16
-23
lines changed

5 files changed

+16
-23
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
3737
import com.cloud.host.Host;
3838
import com.cloud.host.Host.Type;
39-
import com.cloud.host.HostVO;
4039
import com.cloud.host.dao.HostDao;
4140
import com.cloud.offering.ServiceOffering;
4241
import com.cloud.resource.ResourceManager;
@@ -88,8 +87,7 @@ private List<Host> findSuitableHosts(VirtualMachineProfile vmProfile, Deployment
8887
Long podId = plan.getPodId();
8988
Long clusterId = plan.getClusterId();
9089
ServiceOffering offering = vmProfile.getServiceOffering();
91-
List<? extends Host> hostsCopy = null;
92-
List<Host> suitableHosts = new ArrayList<Host>();
90+
List<Host> suitableHosts = new ArrayList<>();
9391

9492
if (type == Host.Type.Storage) {
9593
return suitableHosts;
@@ -132,6 +130,7 @@ private List<Host> findSuitableHosts(VirtualMachineProfile vmProfile, Deployment
132130
if (hostsCopy.size() == 0) {
133131
return suitableHosts;
134132
}
133+
135134
Collections.shuffle(hostsCopy);
136135
for (Host host : hostsCopy) {
137136
if (suitableHosts.size() == returnUpTo) {

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

Lines changed: 1 addition & 4 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;
@@ -138,9 +137,7 @@ public List<Host> allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan pla
138137
return new ArrayList<Host>();
139138
}
140139

141-
if (logger.isDebugEnabled()) {
142-
logger.debug("Looking for hosts in dc: " + dcId + " pod:" + podId + " cluster:" + clusterId);
143-
}
140+
logger.debug("Looking for hosts in zone [{}], pod [{}], cluster [{}]", dcId, podId, clusterId);
144141

145142
String hostTagOnOffering = offering.getHostTag();
146143
String hostTagOnTemplate = template.getTemplateTag();

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import javax.inject.Inject;
2727
import javax.naming.ConfigurationException;
2828

29+
import org.apache.commons.collections.CollectionUtils;
2930
import org.springframework.stereotype.Component;
3031

3132
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
@@ -73,7 +74,7 @@ public class RecreateHostAllocator extends FirstFitRoutingAllocator {
7374
public List<Host> allocateTo(VirtualMachineProfile vm, DeploymentPlan plan, Type type, ExcludeList avoid, int returnUpTo) {
7475

7576
List<Host> hosts = super.allocateTo(vm, plan, type, avoid, returnUpTo);
76-
if (hosts != null && !hosts.isEmpty()) {
77+
if (CollectionUtils.isNotEmpty(hosts)) {
7778
return hosts;
7879
}
7980

server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,7 +1307,7 @@ private DeployDestination checkClustersforDestination(List<Long> clusterList, Vi
13071307
List<Host> suitableHosts = findSuitableHosts(vmProfile, potentialPlan, avoid, HostAllocator.RETURN_UPTO_ALL);
13081308
// if found suitable hosts in this cluster, find suitable storage
13091309
// pools for each volume of the VM
1310-
if (suitableHosts != null && !suitableHosts.isEmpty()) {
1310+
if (CollectionUtils.isNotEmpty(suitableHosts)) {
13111311
if (vmProfile.getHypervisorType() == HypervisorType.BareMetal) {
13121312
DeployDestination dest = new DeployDestination(dc, pod, clusterVO, suitableHosts.get(0));
13131313
return dest;
@@ -1658,18 +1658,17 @@ protected List<Host> findSuitableHosts(VirtualMachineProfile vmProfile, Deployme
16581658
List<Host> suitableHosts = new ArrayList<Host>();
16591659
for (HostAllocator allocator : _hostAllocators) {
16601660
suitableHosts = allocator.allocateTo(vmProfile, plan, Host.Type.Routing, avoid, returnUpTo);
1661-
if (suitableHosts != null && !suitableHosts.isEmpty()) {
1661+
if (CollectionUtils.isNotEmpty(suitableHosts)) {
16621662
break;
16631663
}
16641664
}
16651665

1666-
if (suitableHosts.isEmpty()) {
1667-
logger.debug("No suitable hosts found");
1666+
if (CollectionUtils.isEmpty(suitableHosts)) {
1667+
s_logger.debug("No suitable hosts found.");
1668+
} else {
1669+
reorderHostsByPriority(plan.getHostPriorities(), suitableHosts);
16681670
}
16691671

1670-
// re-order hosts by priority
1671-
reorderHostsByPriority(plan.getHostPriorities(), suitableHosts);
1672-
16731672
return suitableHosts;
16741673
}
16751674

server/src/main/java/com/cloud/server/ManagementServerImpl.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,20 +1647,17 @@ public Ternary<Pair<List<? extends Host>, Integer>, List<? extends Host>, Map<Ho
16471647
suitableHosts = allocator.allocateTo(vmProfile, plan, Host.Type.Routing, excludes, HostAllocator.RETURN_UPTO_ALL, false);
16481648
}
16491649

1650-
if (suitableHosts != null && !suitableHosts.isEmpty()) {
1650+
if (CollectionUtils.isNotEmpty(suitableHosts)) {
16511651
break;
16521652
}
16531653
}
16541654

1655-
// re-order hosts by priority
16561655
_dpMgr.reorderHostsByPriority(plan.getHostPriorities(), suitableHosts);
16571656

1658-
if (logger.isDebugEnabled()) {
1659-
if (suitableHosts.isEmpty()) {
1660-
logger.debug("No suitable hosts found");
1661-
} else {
1662-
logger.debug("Hosts having capacity and suitable for migration: " + suitableHosts);
1663-
}
1657+
if (suitableHosts.isEmpty()) {
1658+
logger.warn("No suitable hosts found.");
1659+
} else {
1660+
logger.debug("Hosts having capacity and suitable for migration: " + suitableHosts);
16641661
}
16651662

16661663
return new Ternary<>(otherHosts, suitableHosts, requiresStorageMotion);

0 commit comments

Comments
 (0)