use of com.cloud.deploy.DeploymentPlanner.ExcludeList in project cosmic by MissionCriticalCloud.
the class ExplicitDedicationProcessor method updateAvoidList.
private ExcludeList updateAvoidList(final List<DedicatedResourceVO> dedicatedResources, final ExcludeList avoidList, final Zone zone) {
final ExcludeList includeList = new ExcludeList();
for (final DedicatedResourceVO dr : dedicatedResources) {
if (dr.getHostId() != null) {
includeList.addHost(dr.getHostId());
final HostVO dedicatedHost = _hostDao.findById(dr.getHostId());
includeList.addCluster(dedicatedHost.getClusterId());
includeList.addPod(dedicatedHost.getPodId());
}
if (dr.getClusterId() != null) {
includeList.addCluster(dr.getClusterId());
// add all hosts inside this in includeList
final List<HostVO> hostList = _hostDao.findByClusterId(dr.getClusterId());
for (final HostVO host : hostList) {
final DedicatedResourceVO dHost = _dedicatedDao.findByHostId(host.getId());
if (dHost != null && !dedicatedResources.contains(dHost)) {
avoidList.addHost(host.getId());
} else {
includeList.addHost(host.getId());
}
}
final ClusterVO dedicatedCluster = _clusterDao.findById(dr.getClusterId());
includeList.addPod(dedicatedCluster.getPodId());
}
if (dr.getPodId() != null) {
includeList.addPod(dr.getPodId());
// add all cluster under this pod in includeList
final List<ClusterVO> clusterList = _clusterDao.listByPodId(dr.getPodId());
for (final ClusterVO cluster : clusterList) {
final DedicatedResourceVO dCluster = _dedicatedDao.findByClusterId(cluster.getId());
if (dCluster != null && !dedicatedResources.contains(dCluster)) {
avoidList.addCluster(cluster.getId());
} else {
includeList.addCluster(cluster.getId());
}
}
// add all hosts inside this pod in includeList
final List<HostVO> hostList = _hostDao.findByPodId(dr.getPodId());
for (final HostVO host : hostList) {
final DedicatedResourceVO dHost = _dedicatedDao.findByHostId(host.getId());
if (dHost != null && !dedicatedResources.contains(dHost)) {
avoidList.addHost(host.getId());
} else {
includeList.addHost(host.getId());
}
}
}
if (dr.getDataCenterId() != null) {
includeList.addZone(dr.getDataCenterId());
// add all Pod under this data center in includeList
final List<HostPodVO> podList = _podDao.listByDataCenterId(dr.getDataCenterId());
for (final HostPodVO pod : podList) {
final DedicatedResourceVO dPod = _dedicatedDao.findByPodId(pod.getId());
if (dPod != null && !dedicatedResources.contains(dPod)) {
avoidList.addPod(pod.getId());
} else {
includeList.addPod(pod.getId());
}
}
final List<ClusterVO> clusterList = _clusterDao.listClustersByDcId(dr.getDataCenterId());
for (final ClusterVO cluster : clusterList) {
final DedicatedResourceVO dCluster = _dedicatedDao.findByClusterId(cluster.getId());
if (dCluster != null && !dedicatedResources.contains(dCluster)) {
avoidList.addCluster(cluster.getId());
} else {
includeList.addCluster(cluster.getId());
}
}
// add all hosts inside this in includeList
final List<HostVO> hostList = _hostDao.listByDataCenterId(dr.getDataCenterId());
for (final HostVO host : hostList) {
final DedicatedResourceVO dHost = _dedicatedDao.findByHostId(host.getId());
if (dHost != null && !dedicatedResources.contains(dHost)) {
avoidList.addHost(host.getId());
} else {
includeList.addHost(host.getId());
}
}
}
}
// Update avoid list using includeList.
// add resources in avoid list which are not in include list.
final List<HostPodVO> pods = _podDao.listByDataCenterId(zone.getId());
final List<ClusterVO> clusters = _clusterDao.listClustersByDcId(zone.getId());
final List<HostVO> hosts = _hostDao.listByDataCenterId(zone.getId());
final Set<Long> podsInIncludeList = includeList.getPodsToAvoid();
final Set<Long> clustersInIncludeList = includeList.getClustersToAvoid();
final Set<Long> hostsInIncludeList = includeList.getHostsToAvoid();
for (final HostPodVO pod : pods) {
if (podsInIncludeList != null && !podsInIncludeList.contains(pod.getId())) {
avoidList.addPod(pod.getId());
}
}
for (final ClusterVO cluster : clusters) {
if (clustersInIncludeList != null && !clustersInIncludeList.contains(cluster.getId())) {
avoidList.addCluster(cluster.getId());
}
}
for (final HostVO host : hosts) {
if (hostsInIncludeList != null && !hostsInIncludeList.contains(host.getId())) {
avoidList.addHost(host.getId());
}
}
return avoidList;
}
use of com.cloud.deploy.DeploymentPlanner.ExcludeList in project cloudstack by apache.
the class VolumeOrchestrator method findStoragePool.
@Override
public StoragePool findStoragePool(DiskProfile dskCh, DataCenter dc, Pod pod, Long clusterId, Long hostId, VirtualMachine vm, final Set<StoragePool> avoid) {
Long podId = null;
if (pod != null) {
podId = pod.getId();
} else if (clusterId != null) {
Cluster cluster = _entityMgr.findById(Cluster.class, clusterId);
if (cluster != null) {
podId = cluster.getPodId();
}
}
VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm);
for (StoragePoolAllocator allocator : _storagePoolAllocators) {
ExcludeList avoidList = new ExcludeList();
for (StoragePool pool : avoid) {
avoidList.addPool(pool.getId());
}
DataCenterDeployment plan = new DataCenterDeployment(dc.getId(), podId, clusterId, hostId, null, null);
final List<StoragePool> poolList = allocator.allocateToPool(dskCh, profile, plan, avoidList, StoragePoolAllocator.RETURN_UPTO_ALL);
if (poolList != null && !poolList.isEmpty()) {
// Check if the preferred storage pool can be used. If yes, use it.
Optional<StoragePool> storagePool = getPreferredStoragePool(poolList, vm);
return (storagePool.isPresent()) ? (StoragePool) this.dataStoreMgr.getDataStore(storagePool.get().getId(), DataStoreRole.Primary) : (StoragePool) dataStoreMgr.getDataStore(poolList.get(0).getId(), DataStoreRole.Primary);
}
}
return null;
}
use of com.cloud.deploy.DeploymentPlanner.ExcludeList in project cloudstack by apache.
the class VolumeOrchestrator method findStoragePoolsForVolumeWithNewDiskOffering.
public List<StoragePool> findStoragePoolsForVolumeWithNewDiskOffering(DiskProfile dskCh, DataCenter dc, Pod pod, Long clusterId, Long hostId, VirtualMachine vm, final Set<StoragePool> avoid) {
Long podId = null;
if (pod != null) {
podId = pod.getId();
} else if (clusterId != null) {
Cluster cluster = _entityMgr.findById(Cluster.class, clusterId);
if (cluster != null) {
podId = cluster.getPodId();
}
}
VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm);
List<StoragePool> suitablePools = new ArrayList<>();
for (StoragePoolAllocator allocator : _storagePoolAllocators) {
ExcludeList avoidList = new ExcludeList();
for (StoragePool pool : avoid) {
avoidList.addPool(pool.getId());
}
DataCenterDeployment plan = new DataCenterDeployment(dc.getId(), podId, clusterId, hostId, null, null);
final List<StoragePool> poolList = allocator.allocateToPool(dskCh, profile, plan, avoidList, StoragePoolAllocator.RETURN_UPTO_ALL);
if (CollectionUtils.isEmpty(poolList)) {
continue;
}
suitablePools.addAll(poolList);
}
return suitablePools;
}
use of com.cloud.deploy.DeploymentPlanner.ExcludeList in project cloudstack by apache.
the class DeploymentPlanningManagerImpl method canAvoidCluster.
private boolean canAvoidCluster(Cluster clusterVO, ExcludeList avoids, ExcludeList plannerAvoidOutput, VirtualMachineProfile 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;
boolean avoidAllPools = true;
boolean avoidAllLocalPools = true;
boolean avoidAllSharedPools = 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;
}
// 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
avoidAllSharedPools = 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
avoidAllLocalPools = false;
break;
}
}
}
if (vmRequiresSharedStorage && vmRequiresLocalStorege) {
avoidAllPools = (avoidAllLocalPools || avoidAllSharedPools) ? true : false;
} else if (vmRequiresSharedStorage) {
avoidAllPools = avoidAllSharedPools;
} else if (vmRequiresLocalStorege) {
avoidAllPools = avoidAllLocalPools;
}
}
if (avoidAllHosts || avoidAllPools) {
return true;
}
return false;
}
use of com.cloud.deploy.DeploymentPlanner.ExcludeList in project cloudstack by apache.
the class DeploymentPlanningManagerImpl method findSuitablePoolsForVolumes.
protected Pair<Map<Volume, List<StoragePool>>, List<Volume>> findSuitablePoolsForVolumes(VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo) {
List<VolumeVO> volumesTobeCreated = _volsDao.findUsableVolumesForInstance(vmProfile.getId());
Map<Volume, List<StoragePool>> suitableVolumeStoragePools = new HashMap<Volume, List<StoragePool>>();
List<Volume> readyAndReusedVolumes = new ArrayList<Volume>();
// There should be atleast the ROOT volume of the VM in usable state
if (volumesTobeCreated.isEmpty()) {
// OfflineVmwareMigration: find out what is wrong with the id of the vm we try to start
throw new CloudRuntimeException("Unable to create deployment, no usable volumes found for the VM: " + vmProfile.getId());
}
// don't allow to start vm that doesn't have a root volume
if (_volsDao.findByInstanceAndType(vmProfile.getId(), Volume.Type.ROOT).isEmpty()) {
throw new CloudRuntimeException("Unable to prepare volumes for vm as ROOT volume is missing");
}
// for each volume find list of suitable storage pools by calling the
// allocators
Set<Long> originalAvoidPoolSet = avoid.getPoolsToAvoid();
if (originalAvoidPoolSet == null) {
originalAvoidPoolSet = new HashSet<Long>();
}
Set<Long> poolsToAvoidOutput = new HashSet<Long>(originalAvoidPoolSet);
for (VolumeVO toBeCreated : volumesTobeCreated) {
s_logger.debug("Checking suitable pools for volume (Id, Type): (" + toBeCreated.getId() + "," + toBeCreated.getVolumeType().name() + ")");
// be reused.
if (plan.getPoolId() != null || (toBeCreated.getVolumeType() == Volume.Type.DATADISK && toBeCreated.getPoolId() != null && toBeCreated.getState() == Volume.State.Ready)) {
s_logger.debug("Volume has pool already allocated, checking if pool can be reused, poolId: " + toBeCreated.getPoolId());
List<StoragePool> suitablePools = new ArrayList<StoragePool>();
StoragePool pool = null;
if (toBeCreated.getPoolId() != null) {
pool = (StoragePool) dataStoreMgr.getPrimaryDataStore(toBeCreated.getPoolId());
} else {
pool = (StoragePool) dataStoreMgr.getPrimaryDataStore(plan.getPoolId());
}
if (!pool.isInMaintenance()) {
if (!avoid.shouldAvoid(pool)) {
long exstPoolDcId = pool.getDataCenterId();
long exstPoolPodId = pool.getPodId() != null ? pool.getPodId() : -1;
long exstPoolClusterId = pool.getClusterId() != null ? pool.getClusterId() : -1;
boolean canReusePool = false;
if (plan.getDataCenterId() == exstPoolDcId && plan.getPodId() == exstPoolPodId && plan.getClusterId() == exstPoolClusterId) {
canReusePool = true;
} else if (plan.getDataCenterId() == exstPoolDcId) {
DataStore dataStore = dataStoreMgr.getPrimaryDataStore(pool.getId());
if (dataStore != null && dataStore.getScope() != null && dataStore.getScope().getScopeType() == ScopeType.ZONE) {
canReusePool = true;
}
} else {
s_logger.debug("Pool of the volume does not fit the specified plan, need to reallocate a pool for this volume");
canReusePool = false;
}
if (canReusePool) {
s_logger.debug("Planner need not allocate a pool for this volume since its READY");
suitablePools.add(pool);
suitableVolumeStoragePools.put(toBeCreated, suitablePools);
if (!(toBeCreated.getState() == Volume.State.Allocated || toBeCreated.getState() == Volume.State.Creating)) {
readyAndReusedVolumes.add(toBeCreated);
}
continue;
}
} else {
s_logger.debug("Pool of the volume is in avoid set, need to reallocate a pool for this volume");
}
} else {
s_logger.debug("Pool of the volume is in maintenance, need to reallocate a pool for this volume");
}
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("We need to allocate new storagepool for this volume");
}
if (!isRootAdmin(vmProfile)) {
if (!isEnabledForAllocation(plan.getDataCenterId(), plan.getPodId(), plan.getClusterId())) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Cannot allocate new storagepool for this volume in this cluster, allocation state is disabled");
s_logger.debug("Cannot deploy to this specified plan, allocation state is disabled, returning.");
}
// Cannot find suitable storage pools under this cluster for
// this volume since allocation_state is disabled.
// - remove any suitable pools found for other volumes.
// All volumes should get suitable pools under this cluster;
// else we cant use this cluster.
suitableVolumeStoragePools.clear();
break;
}
}
s_logger.debug("Calling StoragePoolAllocators to find suitable pools");
DiskOfferingVO diskOffering = _diskOfferingDao.findById(toBeCreated.getDiskOfferingId());
// FR123 check how is it different for service offering getTagsArray and disk offering's
// if ((vmProfile.getTemplate().getFormat() == Storage.ImageFormat.ISO || toBeCreated.getVolumeType() == Volume.Type.ROOT)
// && vmProfile.getServiceOffering().getTagsArray().length != 0) {
// diskOffering.setTagsArray(Arrays.asList(vmProfile.getServiceOffering().getTagsArray()));
// }
DiskProfile diskProfile = new DiskProfile(toBeCreated, diskOffering, vmProfile.getHypervisorType());
boolean useLocalStorage = false;
if (vmProfile.getType() != VirtualMachine.Type.User) {
DataCenterVO zone = _dcDao.findById(plan.getDataCenterId());
assert (zone != null) : "Invalid zone in deployment plan";
Boolean useLocalStorageForSystemVM = ConfigurationManagerImpl.SystemVMUseLocalStorage.valueIn(zone.getId());
if (useLocalStorageForSystemVM != null) {
useLocalStorage = useLocalStorageForSystemVM.booleanValue();
s_logger.debug("System VMs will use " + (useLocalStorage ? "local" : "shared") + " storage for zone id=" + plan.getDataCenterId());
}
} else {
useLocalStorage = diskOffering.isUseLocalStorage();
}
diskProfile.setUseLocalStorage(useLocalStorage);
boolean foundPotentialPools = false;
for (StoragePoolAllocator allocator : _storagePoolAllocators) {
final List<StoragePool> suitablePools = allocator.allocateToPool(diskProfile, vmProfile, plan, avoid, returnUpTo);
if (suitablePools != null && !suitablePools.isEmpty()) {
checkForPreferredStoragePool(suitablePools, vmProfile.getVirtualMachine(), suitableVolumeStoragePools, toBeCreated);
foundPotentialPools = true;
break;
}
}
if (avoid.getPoolsToAvoid() != null) {
poolsToAvoidOutput.addAll(avoid.getPoolsToAvoid());
avoid.getPoolsToAvoid().retainAll(originalAvoidPoolSet);
}
if (!foundPotentialPools) {
s_logger.debug("No suitable pools found for volume: " + toBeCreated + " under cluster: " + plan.getClusterId());
// No suitable storage pools found under this cluster for this
// volume. - remove any suitable pools found for other volumes.
// All volumes should get suitable pools under this cluster;
// else we cant use this cluster.
suitableVolumeStoragePools.clear();
break;
}
}
HashSet<Long> toRemove = new HashSet<Long>();
for (List<StoragePool> lsp : suitableVolumeStoragePools.values()) {
for (StoragePool sp : lsp) {
toRemove.add(sp.getId());
}
}
poolsToAvoidOutput.removeAll(toRemove);
if (avoid.getPoolsToAvoid() != null) {
avoid.getPoolsToAvoid().addAll(poolsToAvoidOutput);
}
if (suitableVolumeStoragePools.isEmpty()) {
s_logger.debug("No suitable pools found");
}
return new Pair<Map<Volume, List<StoragePool>>, List<Volume>>(suitableVolumeStoragePools, readyAndReusedVolumes);
}
Aggregations