}
private boolean canAvoidCluster(Cluster clusterVO, ExcludeList avoids, ExcludeList plannerAvoidOutput,
VirtualMachineProfile<? extends VirtualMachine> vmProfile) {
ExcludeList allocatorAvoidOutput = new ExcludeList(avoids.getDataCentersToAvoid(), avoids.getPodsToAvoid(),
avoids.getClustersToAvoid(), avoids.getHostsToAvoid(), avoids.getPoolsToAvoid());
// remove any hosts/pools that the planners might have added
// to get the list of hosts/pools that Allocators flagged as 'avoid'
resetAvoidSet(allocatorAvoidOutput, plannerAvoidOutput);
// 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<HostVO> allhostsInCluster = _hostDao.listAllUpAndEnabledNonHAHosts(Host.Type.Routing, clusterVO.getId(),
clusterVO.getPodId(), clusterVO.getDataCenterId(), null);
for (HostVO host : allhostsInCluster) {
if (!allocatorAvoidOutput.shouldAvoid(host)) {
// there's some host in the cluster that is not yet in avoid set
avoidAllHosts = false;
break;
}
}
// all hosts in avoid set, avoid the cluster. Otherwise check the pools
if (avoidAllHosts) {
return true;
}
// Cluster can be put in avoid set in following scenarios:
// 1. If storage allocators haven't put any pools in avoid set means either no pools in cluster
// or pools not suitable for the allocators to handle or there is no
// linkage of any suitable host to any of the pools in cluster
// 2. If all 'shared' or 'local' pools are in avoid set
if (allocatorAvoidOutput.getPoolsToAvoid() != null && !allocatorAvoidOutput.getPoolsToAvoid().isEmpty()) {
Pair<Boolean, Boolean> storageRequirements = findVMStorageRequirements(vmProfile);
boolean vmRequiresSharedStorage = storageRequirements.first();
boolean vmRequiresLocalStorege = storageRequirements.second();
if (vmRequiresSharedStorage) {
// check shared pools
List<StoragePoolVO> allPoolsInCluster = _storagePoolDao.findPoolsByTags(clusterVO.getDataCenterId(),
clusterVO.getPodId(), clusterVO.getId(), null);
for (StoragePoolVO pool : allPoolsInCluster) {
if (!allocatorAvoidOutput.shouldAvoid(pool)) {
// there's some pool in the cluster that is not yet in avoid set
avoidAllPools = false;
break;
}
}
}
if (vmRequiresLocalStorege) {
// check local pools
List<StoragePoolVO> allLocalPoolsInCluster = _storagePoolDao.findLocalStoragePoolsByTags(
clusterVO.getDataCenterId(), clusterVO.getPodId(), clusterVO.getId(), null);
for (StoragePoolVO pool : allLocalPoolsInCluster) {
if (!allocatorAvoidOutput.shouldAvoid(pool)) {
// there's some pool in the cluster that is not yet
// in avoid set
avoidAllPools = false;
break;
}