diff --git a/api/src/com/cloud/deploy/DeploymentPlanner.java b/api/src/com/cloud/deploy/DeploymentPlanner.java index a17fabed572..eb56a591f6b 100644 --- a/api/src/com/cloud/deploy/DeploymentPlanner.java +++ b/api/src/com/cloud/deploy/DeploymentPlanner.java @@ -105,10 +105,22 @@ public interface DeploymentPlanner extends Adapter { } public ExcludeList(Set _dcIds, Set _podIds, Set _clusterIds, Set _hostIds, Set _poolIds) { - this._dcIds = _dcIds; - this._podIds = _podIds; - this._clusterIds = _clusterIds; - this._poolIds = _poolIds; + if (_dcIds != null) { + this._dcIds = new HashSet(_dcIds); + } + if (_podIds != null) { + this._podIds = new HashSet(_podIds); + } + if (_clusterIds != null) { + this._clusterIds = new HashSet(_clusterIds); + } + + if (_hostIds != null) { + this._hostIds = new HashSet(_hostIds); + } + if (_poolIds != null) { + this._poolIds = new HashSet(_poolIds); + } } public boolean add(InsufficientCapacityException e) { diff --git a/server/src/com/cloud/deploy/DeploymentPlanningManagerImpl.java b/server/src/com/cloud/deploy/DeploymentPlanningManagerImpl.java index c096bfd473a..6f673c6a5a6 100644 --- a/server/src/com/cloud/deploy/DeploymentPlanningManagerImpl.java +++ b/server/src/com/cloud/deploy/DeploymentPlanningManagerImpl.java @@ -256,7 +256,7 @@ public class DeploymentPlanningManagerImpl extends ManagerBase implements Deploy suitableHosts.add(host); Pair> potentialResources = findPotentialDeploymentResources( - suitableHosts, suitableVolumeStoragePools, getPlannerUsage(planner)); + suitableHosts, suitableVolumeStoragePools, avoids, getPlannerUsage(planner)); if (potentialResources != null) { Pod pod = _podDao.findById(host.getPodId()); Cluster cluster = _clusterDao.findById(host.getClusterId()); @@ -316,7 +316,7 @@ public class DeploymentPlanningManagerImpl extends ManagerBase implements Deploy suitableHosts.add(host); Pair> potentialResources = findPotentialDeploymentResources( - suitableHosts, suitableVolumeStoragePools, getPlannerUsage(planner)); + suitableHosts, suitableVolumeStoragePools, avoids, getPlannerUsage(planner)); if (potentialResources != null) { Pod pod = _podDao.findById(host.getPodId()); Cluster cluster = _clusterDao.findById(host.getClusterId()); @@ -351,11 +351,13 @@ public class DeploymentPlanningManagerImpl extends ManagerBase implements Deploy while (true) { if (planner instanceof DeploymentClusterPlanner) { - clusterList = ((DeploymentClusterPlanner) planner).orderClusters(vmProfile, plan, avoids); + ExcludeList PlannerAvoidInput = new ExcludeList(avoids.getDataCentersToAvoid(), avoids.getPodsToAvoid(), avoids.getClustersToAvoid(), avoids.getHostsToAvoid(), avoids.getPoolsToAvoid()); + clusterList = ((DeploymentClusterPlanner) planner).orderClusters(vmProfile, plan, avoids); + if (clusterList != null && !clusterList.isEmpty()) { // planner refactoring. call allocators to list hosts ExcludeList PlannerAvoidOutput = new ExcludeList(avoids.getDataCentersToAvoid(), @@ -595,7 +597,7 @@ public class DeploymentPlanningManagerImpl extends ManagerBase implements Deploy // choose the potential host and pool for the VM if (!suitableVolumeStoragePools.isEmpty()) { Pair> potentialResources = findPotentialDeploymentResources( - suitableHosts, suitableVolumeStoragePools, resourceUsageRequired); + suitableHosts, suitableVolumeStoragePools, avoid, resourceUsageRequired); if (potentialResources != null) { Pod pod = _podDao.findById(clusterVO.getPodId()); @@ -641,31 +643,37 @@ public class DeploymentPlanningManagerImpl extends ManagerBase implements Deploy // if all hosts or all pools in the cluster are in avoid set after this // pass, then put the cluster in avoid set. + boolean avoidAllHosts = true, avoidAllPools = true; List allhostsInCluster = _hostDao.listAllUpAndEnabledNonHAHosts(Host.Type.Routing, clusterVO.getId(), clusterVO.getPodId(), clusterVO.getDataCenterId(), null); - for (HostVO host : allhostsInCluster) { - if (!allocatorAvoidOutput.getHostsToAvoid().contains(host.getId())) { + if (allocatorAvoidOutput.getHostsToAvoid() == null + || !allocatorAvoidOutput.getHostsToAvoid().contains(host.getId())) { // there's some host in the cluster that is not yet in avoid set - return false; + avoidAllHosts = false; } } List allPoolsInCluster = _storagePoolDao.findPoolsByTags(clusterVO.getDataCenterId(), clusterVO.getPodId(), clusterVO.getId(), null); for (StoragePoolVO pool : allPoolsInCluster) { - if (!allocatorAvoidOutput.getPoolsToAvoid().contains(pool.getId())) { + if (allocatorAvoidOutput.getPoolsToAvoid() == null + || !allocatorAvoidOutput.getPoolsToAvoid().contains(pool.getId())) { // there's some pool in the cluster that is not yet in avoid set - return false; + avoidAllPools = false; } } - return true; + if (avoidAllHosts || avoidAllPools) { + return true; + } + return false; } protected Pair> findPotentialDeploymentResources(List suitableHosts, - Map> suitableVolumeStoragePools, DeploymentPlanner.PlannerResourceUsage resourceUsageRequired) { + Map> suitableVolumeStoragePools, ExcludeList avoid, + DeploymentPlanner.PlannerResourceUsage resourceUsageRequired) { s_logger.debug("Trying to find a potenial host and associated storage pools from the suitable host/pool lists for this VM"); boolean hostCanAccessPool = false; @@ -718,13 +726,13 @@ public class DeploymentPlanningManagerImpl extends ManagerBase implements Deploy break; } } - if (hostCanAccessPool && haveEnoughSpace) { - // check the planner host reservation - if (checkIfHostFitsPlannerUsage(potentialHost.getId(), resourceUsageRequired)) { - s_logger.debug("Found a potential host " + "id: " + potentialHost.getId() + " name: " - + potentialHost.getName() + " and associated storage pools for this VM"); - return new Pair>(potentialHost, storage); - } + if (hostCanAccessPool && haveEnoughSpace + && checkIfHostFitsPlannerUsage(potentialHost.getId(), resourceUsageRequired)) { + s_logger.debug("Found a potential host " + "id: " + potentialHost.getId() + " name: " + + potentialHost.getName() + " and associated storage pools for this VM"); + return new Pair>(potentialHost, storage); + } else { + avoid.addHost(potentialHost.getId()); } } s_logger.debug("Could not find a potential host that has associated storage pools from the suitable host/pool lists for this VM"); diff --git a/server/src/com/cloud/deploy/FirstFitPlanner.java b/server/src/com/cloud/deploy/FirstFitPlanner.java index 0fa5d6a9560..fd41e271c41 100755 --- a/server/src/com/cloud/deploy/FirstFitPlanner.java +++ b/server/src/com/cloud/deploy/FirstFitPlanner.java @@ -129,8 +129,12 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentClusterPla s_logger.debug("Searching resources only under specified Cluster: "+ clusterIdSpecified); ClusterVO cluster = _clusterDao.findById(plan.getClusterId()); if (cluster != null ){ - clusterList.add(clusterIdSpecified); - removeClustersCrossingThreshold(clusterList, avoid, vmProfile, plan); + if (avoid.shouldAvoid(cluster)) { + s_logger.debug("The specified cluster is in avoid set, returning."); + } else { + clusterList.add(clusterIdSpecified); + removeClustersCrossingThreshold(clusterList, avoid, vmProfile, plan); + } return clusterList; }else{ s_logger.debug("The specified cluster cannot be found, returning."); @@ -144,9 +148,13 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentClusterPla HostPodVO pod = _podDao.findById(podIdSpecified); if (pod != null) { - clusterList = scanClustersForDestinationInZoneOrPod(podIdSpecified, false, vmProfile, plan, avoid); - if (clusterList == null) { - avoid.addPod(plan.getPodId()); + if (avoid.shouldAvoid(pod)) { + s_logger.debug("The specified pod is in avoid set, returning."); + } else { + clusterList = scanClustersForDestinationInZoneOrPod(podIdSpecified, false, vmProfile, plan, avoid); + if (clusterList == null) { + avoid.addPod(plan.getPodId()); + } } return clusterList; } else {