From 18fa544da141e1a1fe3eca3beb9533fcd29905ad Mon Sep 17 00:00:00 2001 From: Alex Huang Date: Fri, 22 Jul 2011 18:12:27 -0700 Subject: [PATCH] changed a bunch of map logs to trace --- .../src/com/cloud/deploy/FirstFitPlanner.java | 1094 ++++++++--------- 1 file changed, 547 insertions(+), 547 deletions(-) diff --git a/server/src/com/cloud/deploy/FirstFitPlanner.java b/server/src/com/cloud/deploy/FirstFitPlanner.java index 472e6e3009a..afd580a5c4d 100644 --- a/server/src/com/cloud/deploy/FirstFitPlanner.java +++ b/server/src/com/cloud/deploy/FirstFitPlanner.java @@ -79,13 +79,13 @@ import com.cloud.vm.dao.VMInstanceDao; @Local(value=DeploymentPlanner.class) public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner { - private static final Logger s_logger = Logger.getLogger(FirstFitPlanner.class); - @Inject protected HostDao _hostDao; - @Inject protected DataCenterDao _dcDao; - @Inject protected HostPodDao _podDao; - @Inject protected ClusterDao _clusterDao; - @Inject protected HostDetailsDao _hostDetailsDao = null; - @Inject protected GuestOSDao _guestOSDao = null; + private static final Logger s_logger = Logger.getLogger(FirstFitPlanner.class); + @Inject protected HostDao _hostDao; + @Inject protected DataCenterDao _dcDao; + @Inject protected HostPodDao _podDao; + @Inject protected ClusterDao _clusterDao; + @Inject protected HostDetailsDao _hostDetailsDao = null; + @Inject protected GuestOSDao _guestOSDao = null; @Inject protected GuestOSCategoryDao _guestOSCategoryDao = null; @Inject protected DiskOfferingDao _diskOfferingDao; @Inject protected StoragePoolHostDao _poolHostDao; @@ -96,585 +96,585 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner { @Inject protected ConfigurationDao _configDao; @Inject protected StoragePoolDao _storagePoolDao; @Inject protected CapacityDao _capacityDao; - + @Inject(adapter=StoragePoolAllocator.class) protected Adapters _storagePoolAllocators; @Inject(adapter=HostAllocator.class) protected Adapters _hostAllocators; - + private static int RETURN_UPTO_ALL = -1; - - @Override - public DeployDestination plan(VirtualMachineProfile vmProfile, - DeploymentPlan plan, ExcludeList avoid) - throws InsufficientServerCapacityException { - String _allocationAlgorithm = _configDao.getValue(Config.VmAllocationAlgorithm.key()); - VirtualMachine vm = vmProfile.getVirtualMachine(); - ServiceOffering offering = vmProfile.getServiceOffering(); - DataCenter dc = _dcDao.findById(vm.getDataCenterIdToDeployIn()); - int cpu_requested = offering.getCpu() * offering.getSpeed(); - long ram_requested = offering.getRamSize() * 1024L * 1024L; - + + @Override + public DeployDestination plan(VirtualMachineProfile vmProfile, + DeploymentPlan plan, ExcludeList avoid) + throws InsufficientServerCapacityException { + String _allocationAlgorithm = _configDao.getValue(Config.VmAllocationAlgorithm.key()); + VirtualMachine vm = vmProfile.getVirtualMachine(); + ServiceOffering offering = vmProfile.getServiceOffering(); + DataCenter dc = _dcDao.findById(vm.getDataCenterIdToDeployIn()); + int cpu_requested = offering.getCpu() * offering.getSpeed(); + long ram_requested = offering.getRamSize() * 1024L * 1024L; + String opFactor = _configDao.getValue(Config.CPUOverprovisioningFactor.key()); float cpuOverprovisioningFactor = NumbersUtil.parseFloat(opFactor, 1); - + if (s_logger.isDebugEnabled()) { - s_logger.debug("In FirstFitPlanner:: plan"); - - s_logger.debug("Trying to allocate a host and storage pools from dc:" + plan.getDataCenterId() + ", pod:" + plan.getPodId() + ",cluster:" + plan.getClusterId() + - ", requested cpu: " + cpu_requested + ", requested ram: " + ram_requested); - - s_logger.debug("Is ROOT volume READY (pool already allocated)?: " + (plan.getPoolId()!=null ? "Yes": "No")); + s_logger.debug("In FirstFitPlanner:: plan"); + + s_logger.debug("Trying to allocate a host and storage pools from dc:" + plan.getDataCenterId() + ", pod:" + plan.getPodId() + ",cluster:" + plan.getClusterId() + + ", requested cpu: " + cpu_requested + ", requested ram: " + ram_requested); + + s_logger.debug("Is ROOT volume READY (pool already allocated)?: " + (plan.getPoolId()!=null ? "Yes": "No")); } - - if(plan.getHostId() != null){ - Long hostIdSpecified = plan.getHostId(); - if (s_logger.isDebugEnabled()){ - s_logger.debug("DeploymentPlan has host_id specified, making no checks on this host, looks like admin test: "+hostIdSpecified); - } - HostVO host = _hostDao.findById(hostIdSpecified); - if (s_logger.isDebugEnabled()) { - if(host == null){ - s_logger.debug("The specified host cannot be found"); - }else{ - s_logger.debug("Looking for suitable pools for this host under zone: "+host.getDataCenterId() +", pod: "+ host.getPodId()+", cluster: "+ host.getClusterId()); - } + + if(plan.getHostId() != null){ + Long hostIdSpecified = plan.getHostId(); + if (s_logger.isDebugEnabled()){ + s_logger.debug("DeploymentPlan has host_id specified, making no checks on this host, looks like admin test: "+hostIdSpecified); + } + HostVO host = _hostDao.findById(hostIdSpecified); + if (s_logger.isDebugEnabled()) { + if(host == null){ + s_logger.debug("The specified host cannot be found"); + }else{ + s_logger.debug("Looking for suitable pools for this host under zone: "+host.getDataCenterId() +", pod: "+ host.getPodId()+", cluster: "+ host.getClusterId()); + } } - - //search for storage under the zone, pod, cluster of the host. - DataCenterDeployment lastPlan = new DataCenterDeployment(host.getDataCenterId(), host.getPodId(), host.getClusterId(), hostIdSpecified, plan.getPoolId()); - - Pair>, List> result = findSuitablePoolsForVolumes(vmProfile, lastPlan, avoid, RETURN_UPTO_ALL); - Map> suitableVolumeStoragePools = result.first(); - List readyAndReusedVolumes = result.second(); - - //choose the potential pool for this VM for this host - if(!suitableVolumeStoragePools.isEmpty()){ - List suitableHosts = new ArrayList(); - suitableHosts.add(host); - - Pair> potentialResources = findPotentialDeploymentResources(suitableHosts, suitableVolumeStoragePools); - if(potentialResources != null){ - Pod pod = _podDao.findById(host.getPodId()); - Cluster cluster = _clusterDao.findById(host.getClusterId()); - Map storageVolMap = potentialResources.second(); - // remove the reused vol<->pool from destination, since we don't have to prepare this volume. - for(Volume vol : readyAndReusedVolumes){ - storageVolMap.remove(vol); - } - DeployDestination dest = new DeployDestination(dc, pod, cluster, host, storageVolMap); - s_logger.debug("Returning Deployment Destination: "+ dest); - return dest; - } - } - s_logger.debug("Cannnot deploy to specified host, returning."); - return null; - } - - if (vm.getLastHostId() != null) { - s_logger.debug("This VM has last host_id specified, trying to choose the same host: " +vm.getLastHostId()); - HostVO host = _hostDao.findById(vm.getLastHostId()); - if(host == null){ - s_logger.debug("The last host of this VM cannot be found"); - }else{ - if (host.getStatus() == Status.Up && host.getHostAllocationState() == Host.HostAllocationState.Enabled) { - //check zone/pod/cluster are enabled - if(isEnabledForAllocation(host.getDataCenterId(), host.getPodId(), host.getClusterId())){ - if(_capacityMgr.checkIfHostHasCapacity(host.getId(), cpu_requested, ram_requested, true, cpuOverprovisioningFactor)){ - s_logger.debug("The last host of this VM is UP and has enough capacity"); - s_logger.debug("Now checking for suitable pools under zone: "+host.getDataCenterId() +", pod: "+ host.getPodId()+", cluster: "+ host.getClusterId()); - //search for storage under the zone, pod, cluster of the last host. - DataCenterDeployment lastPlan = new DataCenterDeployment(host.getDataCenterId(), host.getPodId(), host.getClusterId(), host.getId(), plan.getPoolId()); - Pair>, List> result = findSuitablePoolsForVolumes(vmProfile, lastPlan, avoid, RETURN_UPTO_ALL); - Map> suitableVolumeStoragePools = result.first(); - List readyAndReusedVolumes = result.second(); - //choose the potential pool for this VM for this host - if(!suitableVolumeStoragePools.isEmpty()){ - List suitableHosts = new ArrayList(); - suitableHosts.add(host); - - Pair> potentialResources = findPotentialDeploymentResources(suitableHosts, suitableVolumeStoragePools); - if(potentialResources != null){ - Pod pod = _podDao.findById(host.getPodId()); - Cluster cluster = _clusterDao.findById(host.getClusterId()); - Map storageVolMap = potentialResources.second(); - // remove the reused vol<->pool from destination, since we don't have to prepare this volume. - for(Volume vol : readyAndReusedVolumes){ - storageVolMap.remove(vol); - } - DeployDestination dest = new DeployDestination(dc, pod, cluster, host, storageVolMap); - s_logger.debug("Returning Deployment Destination: "+ dest); - return dest; - } - } - }else{ - s_logger.debug("The last host of this VM does not have enough capacity"); - } - } - }else{ - s_logger.debug("The last host of this VM is not UP or is not enabled, host status is: "+host.getStatus().name() + ", host allocation state is: "+host.getHostAllocationState().name()); - } - } - - s_logger.debug("Cannot choose the last host to deploy this VM "); - } - - if(!isEnabledForAllocation(plan.getDataCenterId(), plan.getPodId(), plan.getClusterId())){ - s_logger.debug("Cannot deploy to specified plan, allocation state is disabled, returning."); - return null; - } + //search for storage under the zone, pod, cluster of the host. + DataCenterDeployment lastPlan = new DataCenterDeployment(host.getDataCenterId(), host.getPodId(), host.getClusterId(), hostIdSpecified, plan.getPoolId()); - List clusterList = new ArrayList(); - if (plan.getClusterId() != null) { - Long clusterIdSpecified = plan.getClusterId(); - s_logger.debug("Searching resources only under specified Cluster: "+ clusterIdSpecified); - ClusterVO cluster = _clusterDao.findById(plan.getClusterId()); - if (cluster != null ){ - clusterList.add(clusterIdSpecified); - return checkClustersforDestination(clusterList, vmProfile, plan, avoid, dc, _allocationAlgorithm); - }else{ - s_logger.debug("The specified cluster cannot be found, returning."); - avoid.addPod(plan.getClusterId()); - return null; - } - }else if (plan.getPodId() != null) { - //consider clusters under this pod only - Long podIdSpecified = plan.getPodId(); - s_logger.debug("Searching resources only under specified Pod: "+ podIdSpecified); - - HostPodVO pod = _podDao.findById(podIdSpecified); - if (pod != null) { - //list clusters under this pod by cpu and ram capacity - clusterList = listClustersByCapacity(podIdSpecified, cpu_requested, ram_requested, avoid, false, cpuOverprovisioningFactor); - if(!clusterList.isEmpty()){ - if(avoid.getClustersToAvoid() != null){ - if (s_logger.isDebugEnabled()) { - s_logger.debug("Removing from the clusterId list these clusters from avoid set: "+ avoid.getClustersToAvoid()); - } - clusterList.removeAll(avoid.getClustersToAvoid()); - } - - List disabledClusters = listDisabledClusters(plan.getDataCenterId(), podIdSpecified); - if(!disabledClusters.isEmpty()){ - if (s_logger.isDebugEnabled()) { - s_logger.debug("Removing from the clusterId list these clusters that are disabled: "+ disabledClusters); - } - clusterList.removeAll(disabledClusters); - } - - DeployDestination dest = checkClustersforDestination(clusterList, vmProfile, plan, avoid, dc, _allocationAlgorithm); - if(dest == null){ - avoid.addPod(plan.getPodId()); - } - return dest; - }else{ - if (s_logger.isDebugEnabled()) { - s_logger.debug("No clusters found under this pod, having a host with enough capacity, returning."); - } - avoid.addPod(plan.getPodId()); - return null; - } - } else { - s_logger.debug("The specified Pod cannot be found, returning."); - avoid.addPod(plan.getPodId()); - return null; - } - }else{ - //consider all clusters under this zone. - s_logger.debug("Searching all possible resources under this Zone: "+ plan.getDataCenterId()); - //list clusters under this zone by cpu and ram capacity - List prioritizedClusterIds = listClustersByCapacity(plan.getDataCenterId(), cpu_requested, ram_requested, avoid, true, cpuOverprovisioningFactor); - if(!prioritizedClusterIds.isEmpty()){ - if(avoid.getClustersToAvoid() != null){ - if (s_logger.isDebugEnabled()) { - s_logger.debug("Removing from the clusterId list these clusters from avoid set: "+ avoid.getClustersToAvoid()); - } - prioritizedClusterIds.removeAll(avoid.getClustersToAvoid()); - } - List disabledClusters = listDisabledClusters(plan.getDataCenterId(), null); - if(!disabledClusters.isEmpty()){ - if (s_logger.isDebugEnabled()) { - s_logger.debug("Removing from the clusterId list these clusters that are disabled/clusters under disabled pods: "+ disabledClusters); - } - prioritizedClusterIds.removeAll(disabledClusters); - } - }else{ - if (s_logger.isDebugEnabled()) { - s_logger.debug("No clusters found having a host with enough capacity, returning."); - } - return null; - } - if(!prioritizedClusterIds.isEmpty()){ - boolean applyUserConcentrationPodHeuristic = Boolean.parseBoolean(_configDao.getValue(Config.UseUserConcentratedPodAllocation.key())); - if(applyUserConcentrationPodHeuristic && vmProfile.getOwner() != null){ - //user has VMs in certain pods. - prioritize those pods first - //UserConcentratedPod strategy - long accountId = vmProfile.getOwner().getAccountId(); - List podIds = listPodsByUserConcentration(plan.getDataCenterId(), accountId); - if(!podIds.isEmpty()){ - if(avoid.getPodsToAvoid() != null){ - if (s_logger.isDebugEnabled()) { - s_logger.debug("Removing from the pod list these pods from avoid set: "+ avoid.getPodsToAvoid()); - } - podIds.removeAll(avoid.getPodsToAvoid()); - } - clusterList = reorderClustersByPods(prioritizedClusterIds, podIds); - }else{ - clusterList = prioritizedClusterIds; - } - }else{ - clusterList = prioritizedClusterIds; - } - return checkClustersforDestination(clusterList, vmProfile, plan, avoid, dc, _allocationAlgorithm); - }else{ - if (s_logger.isDebugEnabled()) { - s_logger.debug("No clusters found after removing disabled clusters and clusters in avoid list, returning."); - } - return null; - } - } + Pair>, List> result = findSuitablePoolsForVolumes(vmProfile, lastPlan, avoid, RETURN_UPTO_ALL); + Map> suitableVolumeStoragePools = result.first(); + List readyAndReusedVolumes = result.second(); - } - - private List listDisabledClusters(long zoneId, Long podId){ - List disabledClusters = _clusterDao.listDisabledClusters(zoneId, podId); - if(podId == null){ - //list all disabled clusters under this zone + clusters under any disabled pod of this zone - List clustersWithDisabledPods = _clusterDao.listClustersWithDisabledPods(zoneId); - disabledClusters.addAll(clustersWithDisabledPods); - } - return disabledClusters; - } - - - - private DeployDestination checkClustersforDestination(List clusterList, VirtualMachineProfile vmProfile, - DeploymentPlan plan, ExcludeList avoid, DataCenter dc, String _allocationAlgorithm){ - - if (s_logger.isDebugEnabled()) { - s_logger.debug("ClusterId List to consider: "+clusterList ); - } - - for(Long clusterId : clusterList){ - Cluster clusterVO = _clusterDao.findById(clusterId); + //choose the potential pool for this VM for this host + if(!suitableVolumeStoragePools.isEmpty()){ + List suitableHosts = new ArrayList(); + suitableHosts.add(host); + + Pair> potentialResources = findPotentialDeploymentResources(suitableHosts, suitableVolumeStoragePools); + if(potentialResources != null){ + Pod pod = _podDao.findById(host.getPodId()); + Cluster cluster = _clusterDao.findById(host.getClusterId()); + Map storageVolMap = potentialResources.second(); + // remove the reused vol<->pool from destination, since we don't have to prepare this volume. + for(Volume vol : readyAndReusedVolumes){ + storageVolMap.remove(vol); + } + DeployDestination dest = new DeployDestination(dc, pod, cluster, host, storageVolMap); + s_logger.debug("Returning Deployment Destination: "+ dest); + return dest; + } + } + s_logger.debug("Cannnot deploy to specified host, returning."); + return null; + } + + if (vm.getLastHostId() != null) { + s_logger.debug("This VM has last host_id specified, trying to choose the same host: " +vm.getLastHostId()); + + HostVO host = _hostDao.findById(vm.getLastHostId()); + if(host == null){ + s_logger.debug("The last host of this VM cannot be found"); + }else{ + if (host.getStatus() == Status.Up && host.getHostAllocationState() == Host.HostAllocationState.Enabled) { + //check zone/pod/cluster are enabled + if(isEnabledForAllocation(host.getDataCenterId(), host.getPodId(), host.getClusterId())){ + if(_capacityMgr.checkIfHostHasCapacity(host.getId(), cpu_requested, ram_requested, true, cpuOverprovisioningFactor)){ + s_logger.debug("The last host of this VM is UP and has enough capacity"); + s_logger.debug("Now checking for suitable pools under zone: "+host.getDataCenterId() +", pod: "+ host.getPodId()+", cluster: "+ host.getClusterId()); + //search for storage under the zone, pod, cluster of the last host. + DataCenterDeployment lastPlan = new DataCenterDeployment(host.getDataCenterId(), host.getPodId(), host.getClusterId(), host.getId(), plan.getPoolId()); + Pair>, List> result = findSuitablePoolsForVolumes(vmProfile, lastPlan, avoid, RETURN_UPTO_ALL); + Map> suitableVolumeStoragePools = result.first(); + List readyAndReusedVolumes = result.second(); + //choose the potential pool for this VM for this host + if(!suitableVolumeStoragePools.isEmpty()){ + List suitableHosts = new ArrayList(); + suitableHosts.add(host); + + Pair> potentialResources = findPotentialDeploymentResources(suitableHosts, suitableVolumeStoragePools); + if(potentialResources != null){ + Pod pod = _podDao.findById(host.getPodId()); + Cluster cluster = _clusterDao.findById(host.getClusterId()); + Map storageVolMap = potentialResources.second(); + // remove the reused vol<->pool from destination, since we don't have to prepare this volume. + for(Volume vol : readyAndReusedVolumes){ + storageVolMap.remove(vol); + } + DeployDestination dest = new DeployDestination(dc, pod, cluster, host, storageVolMap); + s_logger.debug("Returning Deployment Destination: "+ dest); + return dest; + } + } + }else{ + s_logger.debug("The last host of this VM does not have enough capacity"); + } + } + }else{ + s_logger.debug("The last host of this VM is not UP or is not enabled, host status is: "+host.getStatus().name() + ", host allocation state is: "+host.getHostAllocationState().name()); + } + } + + s_logger.debug("Cannot choose the last host to deploy this VM "); + } + + if(!isEnabledForAllocation(plan.getDataCenterId(), plan.getPodId(), plan.getClusterId())){ + s_logger.debug("Cannot deploy to specified plan, allocation state is disabled, returning."); + return null; + } + + List clusterList = new ArrayList(); + if (plan.getClusterId() != null) { + Long clusterIdSpecified = plan.getClusterId(); + s_logger.debug("Searching resources only under specified Cluster: "+ clusterIdSpecified); + ClusterVO cluster = _clusterDao.findById(plan.getClusterId()); + if (cluster != null ){ + clusterList.add(clusterIdSpecified); + return checkClustersforDestination(clusterList, vmProfile, plan, avoid, dc, _allocationAlgorithm); + }else{ + s_logger.debug("The specified cluster cannot be found, returning."); + avoid.addPod(plan.getClusterId()); + return null; + } + }else if (plan.getPodId() != null) { + //consider clusters under this pod only + Long podIdSpecified = plan.getPodId(); + s_logger.debug("Searching resources only under specified Pod: "+ podIdSpecified); + + HostPodVO pod = _podDao.findById(podIdSpecified); + if (pod != null) { + //list clusters under this pod by cpu and ram capacity + clusterList = listClustersByCapacity(podIdSpecified, cpu_requested, ram_requested, avoid, false, cpuOverprovisioningFactor); + if(!clusterList.isEmpty()){ + if(avoid.getClustersToAvoid() != null){ + if (s_logger.isDebugEnabled()) { + s_logger.debug("Removing from the clusterId list these clusters from avoid set: "+ avoid.getClustersToAvoid()); + } + clusterList.removeAll(avoid.getClustersToAvoid()); + } + + List disabledClusters = listDisabledClusters(plan.getDataCenterId(), podIdSpecified); + if(!disabledClusters.isEmpty()){ + if (s_logger.isDebugEnabled()) { + s_logger.debug("Removing from the clusterId list these clusters that are disabled: "+ disabledClusters); + } + clusterList.removeAll(disabledClusters); + } + + DeployDestination dest = checkClustersforDestination(clusterList, vmProfile, plan, avoid, dc, _allocationAlgorithm); + if(dest == null){ + avoid.addPod(plan.getPodId()); + } + return dest; + }else{ + if (s_logger.isDebugEnabled()) { + s_logger.debug("No clusters found under this pod, having a host with enough capacity, returning."); + } + avoid.addPod(plan.getPodId()); + return null; + } + } else { + s_logger.debug("The specified Pod cannot be found, returning."); + avoid.addPod(plan.getPodId()); + return null; + } + }else{ + //consider all clusters under this zone. + s_logger.debug("Searching all possible resources under this Zone: "+ plan.getDataCenterId()); + //list clusters under this zone by cpu and ram capacity + List prioritizedClusterIds = listClustersByCapacity(plan.getDataCenterId(), cpu_requested, ram_requested, avoid, true, cpuOverprovisioningFactor); + if(!prioritizedClusterIds.isEmpty()){ + if(avoid.getClustersToAvoid() != null){ + if (s_logger.isDebugEnabled()) { + s_logger.debug("Removing from the clusterId list these clusters from avoid set: "+ avoid.getClustersToAvoid()); + } + prioritizedClusterIds.removeAll(avoid.getClustersToAvoid()); + } + List disabledClusters = listDisabledClusters(plan.getDataCenterId(), null); + if(!disabledClusters.isEmpty()){ + if (s_logger.isDebugEnabled()) { + s_logger.debug("Removing from the clusterId list these clusters that are disabled/clusters under disabled pods: "+ disabledClusters); + } + prioritizedClusterIds.removeAll(disabledClusters); + } + }else{ + if (s_logger.isDebugEnabled()) { + s_logger.debug("No clusters found having a host with enough capacity, returning."); + } + return null; + } + if(!prioritizedClusterIds.isEmpty()){ + boolean applyUserConcentrationPodHeuristic = Boolean.parseBoolean(_configDao.getValue(Config.UseUserConcentratedPodAllocation.key())); + if(applyUserConcentrationPodHeuristic && vmProfile.getOwner() != null){ + //user has VMs in certain pods. - prioritize those pods first + //UserConcentratedPod strategy + long accountId = vmProfile.getOwner().getAccountId(); + List podIds = listPodsByUserConcentration(plan.getDataCenterId(), accountId); + if(!podIds.isEmpty()){ + if(avoid.getPodsToAvoid() != null){ + if (s_logger.isDebugEnabled()) { + s_logger.debug("Removing from the pod list these pods from avoid set: "+ avoid.getPodsToAvoid()); + } + podIds.removeAll(avoid.getPodsToAvoid()); + } + clusterList = reorderClustersByPods(prioritizedClusterIds, podIds); + }else{ + clusterList = prioritizedClusterIds; + } + }else{ + clusterList = prioritizedClusterIds; + } + return checkClustersforDestination(clusterList, vmProfile, plan, avoid, dc, _allocationAlgorithm); + }else{ + if (s_logger.isDebugEnabled()) { + s_logger.debug("No clusters found after removing disabled clusters and clusters in avoid list, returning."); + } + return null; + } + } + + } + + private List listDisabledClusters(long zoneId, Long podId){ + List disabledClusters = _clusterDao.listDisabledClusters(zoneId, podId); + if(podId == null){ + //list all disabled clusters under this zone + clusters under any disabled pod of this zone + List clustersWithDisabledPods = _clusterDao.listClustersWithDisabledPods(zoneId); + disabledClusters.addAll(clustersWithDisabledPods); + } + return disabledClusters; + } + + + + private DeployDestination checkClustersforDestination(List clusterList, VirtualMachineProfile vmProfile, + DeploymentPlan plan, ExcludeList avoid, DataCenter dc, String _allocationAlgorithm){ + + if (s_logger.isTraceEnabled()) { + s_logger.trace("ClusterId List to consider: " + clusterList); + } + + for(Long clusterId : clusterList){ + Cluster clusterVO = _clusterDao.findById(clusterId); + + if (clusterVO.getHypervisorType() != vmProfile.getHypervisorType()) { + s_logger.debug("Cluster: "+clusterId + " has HyperVisorType that does not match the VM, skipping this cluster"); + avoid.addCluster(clusterVO.getId()); + continue; + } - if (clusterVO.getHypervisorType() != vmProfile.getHypervisorType()) { - s_logger.debug("Cluster: "+clusterId + " has HyperVisorType that does not match the VM, skipping this cluster"); - avoid.addCluster(clusterVO.getId()); - continue; - } - if(clusterVO.getAllocationState() != Grouping.AllocationState.Enabled){ if (s_logger.isDebugEnabled()) { s_logger.debug("Cluster name: " + clusterVO.getName() + ", clusterId: "+ clusterId +" is in " + clusterVO.getAllocationState().name() + " state, skipping this and trying other clusters"); } continue; } - - s_logger.debug("Checking resources in Cluster: "+clusterId + " under Pod: "+clusterVO.getPodId()); - //search for resources(hosts and storage) under this zone, pod, cluster. - DataCenterDeployment potentialPlan = new DataCenterDeployment(plan.getDataCenterId(), clusterVO.getPodId(), clusterVO.getId(), null, plan.getPoolId()); - //find suitable hosts under this cluster, need as many hosts as we get. - List suitableHosts = findSuitableHosts(vmProfile, potentialPlan, avoid, RETURN_UPTO_ALL); - //if found suitable hosts in this cluster, find suitable storage pools for each volume of the VM - if(suitableHosts != null && !suitableHosts.isEmpty()){ - if (vmProfile.getHypervisorType() == HypervisorType.BareMetal) { - Pod pod = _podDao.findById(clusterVO.getPodId()); - DeployDestination dest = new DeployDestination(dc, pod, clusterVO, suitableHosts.get(0)); - return dest; - } - - if (_allocationAlgorithm != null && _allocationAlgorithm.equalsIgnoreCase("random")) { - Collections.shuffle(suitableHosts); - } - Pair>, List> result = findSuitablePoolsForVolumes(vmProfile, potentialPlan, avoid, RETURN_UPTO_ALL); - Map> suitableVolumeStoragePools = result.first(); - List readyAndReusedVolumes = result.second(); - - //choose the potential host and pool for the VM - if(!suitableVolumeStoragePools.isEmpty()){ - Pair> potentialResources = findPotentialDeploymentResources(suitableHosts, suitableVolumeStoragePools); - - if(potentialResources != null){ - Pod pod = _podDao.findById(clusterVO.getPodId()); - Host host = _hostDao.findById(potentialResources.first().getId()); - Map storageVolMap = potentialResources.second(); - // remove the reused vol<->pool from destination, since we don't have to prepare this volume. - for(Volume vol : readyAndReusedVolumes){ - storageVolMap.remove(vol); - } - DeployDestination dest = new DeployDestination(dc, pod, clusterVO, host, storageVolMap ); - s_logger.debug("Returning Deployment Destination: "+ dest); - return dest; - } - }else{ - s_logger.debug("No suitable storagePools found under this Cluster: "+clusterId); - } - }else{ - s_logger.debug("No suitable hosts found under this Cluster: "+clusterId); - } - avoid.addCluster(clusterVO.getId()); - } - s_logger.debug("Could not find suitable Deployment Destination for this VM under any clusters, returning. "); - return null; - } - - private List reorderClustersByPods(List clusterIds, List podIds) { - - if (s_logger.isDebugEnabled()) { - s_logger.debug("Reordering cluster list as per pods ordered by user concentration"); - } - - Map> podClusterMap = _clusterDao.getPodClusterIdMap(clusterIds); - - if (s_logger.isTraceEnabled()) { - s_logger.trace("Pod To cluster Map is: "+podClusterMap ); - } - - List reorderedClusters = new ArrayList(); - for (Long pod : podIds){ - if(podClusterMap.containsKey(pod)){ - List clustersOfThisPod = podClusterMap.get(pod); - if(clustersOfThisPod != null){ - for(Long clusterId : clusterIds){ - if(clustersOfThisPod.contains(clusterId)){ - reorderedClusters.add(clusterId); - } - } - clusterIds.removeAll(clustersOfThisPod); - } - } - } - reorderedClusters.addAll(clusterIds); - - if (s_logger.isDebugEnabled()) { - s_logger.debug("Reordered cluster list: "+reorderedClusters ); - } - return reorderedClusters; - } + s_logger.debug("Checking resources in Cluster: "+clusterId + " under Pod: "+clusterVO.getPodId()); + //search for resources(hosts and storage) under this zone, pod, cluster. + DataCenterDeployment potentialPlan = new DataCenterDeployment(plan.getDataCenterId(), clusterVO.getPodId(), clusterVO.getId(), null, plan.getPoolId()); - protected List listPodsByUserConcentration(long zoneId, long accountId){ + //find suitable hosts under this cluster, need as many hosts as we get. + List suitableHosts = findSuitableHosts(vmProfile, potentialPlan, avoid, RETURN_UPTO_ALL); + //if found suitable hosts in this cluster, find suitable storage pools for each volume of the VM + if(suitableHosts != null && !suitableHosts.isEmpty()){ + if (vmProfile.getHypervisorType() == HypervisorType.BareMetal) { + Pod pod = _podDao.findById(clusterVO.getPodId()); + DeployDestination dest = new DeployDestination(dc, pod, clusterVO, suitableHosts.get(0)); + return dest; + } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Applying UserConcentratedPod heuristic for account: "+ accountId); - } - - List prioritizedPods = _vmDao.listPodIdsHavingVmsforAccount(zoneId, accountId); - - if (s_logger.isDebugEnabled()) { - s_logger.debug("List of pods to be considered, after applying UserConcentratedPod heuristic: "+ prioritizedPods); - } - - return prioritizedPods; - } - - protected List listClustersByCapacity(long id, int requiredCpu, long requiredRam, ExcludeList avoid, boolean isZone, float cpuOverprovisioningFactor){ - //look at the aggregate available cpu and ram per cluster - //although an aggregate value may be false indicator that a cluster can host a vm, it will at the least eliminate those clusters which definitely cannot - - //we need clusters having enough cpu AND RAM - if (s_logger.isDebugEnabled()) { - s_logger.debug("Listing clusters that have enough aggregate CPU and RAM capacity under this "+(isZone ? "Zone: " : "Pod: " )+id); - } - String capacityTypeToOrder = _configDao.getValue(Config.HostCapacityTypeToOrderClusters.key()); - short capacityType = CapacityVO.CAPACITY_TYPE_CPU; - if("RAM".equalsIgnoreCase(capacityTypeToOrder)){ - capacityType = CapacityVO.CAPACITY_TYPE_MEMORY; - } + if (_allocationAlgorithm != null && _allocationAlgorithm.equalsIgnoreCase("random")) { + Collections.shuffle(suitableHosts); + } + Pair>, List> result = findSuitablePoolsForVolumes(vmProfile, potentialPlan, avoid, RETURN_UPTO_ALL); + Map> suitableVolumeStoragePools = result.first(); + List readyAndReusedVolumes = result.second(); + + //choose the potential host and pool for the VM + if(!suitableVolumeStoragePools.isEmpty()){ + Pair> potentialResources = findPotentialDeploymentResources(suitableHosts, suitableVolumeStoragePools); + + if(potentialResources != null){ + Pod pod = _podDao.findById(clusterVO.getPodId()); + Host host = _hostDao.findById(potentialResources.first().getId()); + Map storageVolMap = potentialResources.second(); + // remove the reused vol<->pool from destination, since we don't have to prepare this volume. + for(Volume vol : readyAndReusedVolumes){ + storageVolMap.remove(vol); + } + DeployDestination dest = new DeployDestination(dc, pod, clusterVO, host, storageVolMap ); + s_logger.debug("Returning Deployment Destination: "+ dest); + return dest; + } + }else{ + s_logger.debug("No suitable storagePools found under this Cluster: "+clusterId); + } + }else{ + s_logger.debug("No suitable hosts found under this Cluster: "+clusterId); + } + avoid.addCluster(clusterVO.getId()); + } + s_logger.debug("Could not find suitable Deployment Destination for this VM under any clusters, returning. "); + return null; + } + + private List reorderClustersByPods(List clusterIds, List podIds) { + + if (s_logger.isDebugEnabled()) { + s_logger.debug("Reordering cluster list as per pods ordered by user concentration"); + } + + Map> podClusterMap = _clusterDao.getPodClusterIdMap(clusterIds); + + if (s_logger.isTraceEnabled()) { + s_logger.trace("Pod To cluster Map is: "+podClusterMap ); + } + + List reorderedClusters = new ArrayList(); + for (Long pod : podIds){ + if(podClusterMap.containsKey(pod)){ + List clustersOfThisPod = podClusterMap.get(pod); + if(clustersOfThisPod != null){ + for(Long clusterId : clusterIds){ + if(clustersOfThisPod.contains(clusterId)){ + reorderedClusters.add(clusterId); + } + } + clusterIds.removeAll(clustersOfThisPod); + } + } + } + reorderedClusters.addAll(clusterIds); + + if (s_logger.isTraceEnabled()) { + s_logger.trace("Reordered cluster list: " + reorderedClusters); + } + return reorderedClusters; + } + + protected List listPodsByUserConcentration(long zoneId, long accountId){ + + if (s_logger.isDebugEnabled()) { + s_logger.debug("Applying UserConcentratedPod heuristic for account: "+ accountId); + } + + List prioritizedPods = _vmDao.listPodIdsHavingVmsforAccount(zoneId, accountId); + + if (s_logger.isDebugEnabled()) { + s_logger.debug("List of pods to be considered, after applying UserConcentratedPod heuristic: "+ prioritizedPods); + } + + return prioritizedPods; + } + + protected List listClustersByCapacity(long id, int requiredCpu, long requiredRam, ExcludeList avoid, boolean isZone, float cpuOverprovisioningFactor){ + //look at the aggregate available cpu and ram per cluster + //although an aggregate value may be false indicator that a cluster can host a vm, it will at the least eliminate those clusters which definitely cannot + + //we need clusters having enough cpu AND RAM + if (s_logger.isDebugEnabled()) { + s_logger.debug("Listing clusters that have enough aggregate CPU and RAM capacity under this "+(isZone ? "Zone: " : "Pod: " )+id); + } + String capacityTypeToOrder = _configDao.getValue(Config.HostCapacityTypeToOrderClusters.key()); + short capacityType = CapacityVO.CAPACITY_TYPE_CPU; + if("RAM".equalsIgnoreCase(capacityTypeToOrder)){ + capacityType = CapacityVO.CAPACITY_TYPE_MEMORY; + } if (s_logger.isDebugEnabled()) { s_logger.debug("CPUOverprovisioningFactor considered: " + cpuOverprovisioningFactor); } - List clusterIdswithEnoughCapacity = _capacityDao.orderClustersInZoneOrPodByHostCapacities(id, requiredCpu, requiredRam, capacityType, isZone, cpuOverprovisioningFactor); - if (s_logger.isDebugEnabled()) { - s_logger.debug("ClusterId List having enough aggregate capacity: "+clusterIdswithEnoughCapacity ); - } - return clusterIdswithEnoughCapacity; - - } - - protected Pair> findPotentialDeploymentResources(List suitableHosts, Map> suitableVolumeStoragePools){ - 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; - Map storage = new HashMap(); - for(Host potentialHost : suitableHosts){ - for(Volume vol : suitableVolumeStoragePools.keySet()){ - s_logger.debug("Checking if host: "+potentialHost.getId() +" can access any suitable storage pool for volume: "+ vol.getVolumeType()); - List volumePoolList = suitableVolumeStoragePools.get(vol); - hostCanAccessPool = false; - for(StoragePool potentialSPool : volumePoolList){ - if(hostCanAccessSPool(potentialHost, potentialSPool)){ - storage.put(vol, potentialSPool); - hostCanAccessPool = true; - break; - } - } - if(!hostCanAccessPool){ - break; - } - } - if(hostCanAccessPool){ - s_logger.debug("Found a potential host and associated storage pools for this VM"); - return new Pair>(potentialHost, storage); - } - } - s_logger.debug("Could not find a potential host that has associated storage pools from the suitable host/pool lists for this VM"); - return null; - } - - protected boolean hostCanAccessSPool(Host host, StoragePool pool){ - boolean hostCanAccessSPool = false; - - StoragePoolHostVO hostPoolLinkage = _poolHostDao.findByPoolHost(pool.getId(), host.getId()); - if(hostPoolLinkage != null){ - hostCanAccessSPool = true; - } - - s_logger.debug("Host: "+ host.getId() + (hostCanAccessSPool ?" can" : " cannot") + " access pool: "+ pool.getId()); - return hostCanAccessSPool; - } + List clusterIdswithEnoughCapacity = _capacityDao.orderClustersInZoneOrPodByHostCapacities(id, requiredCpu, requiredRam, capacityType, isZone, cpuOverprovisioningFactor); + if (s_logger.isTraceEnabled()) { + s_logger.trace("ClusterId List having enough aggregate capacity: " + clusterIdswithEnoughCapacity); + } + return clusterIdswithEnoughCapacity; - protected List findSuitableHosts(VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo){ - List suitableHosts = new ArrayList(); - Enumeration enHost = _hostAllocators.enumeration(); - s_logger.debug("Calling HostAllocators to find suitable hosts"); - - while (enHost.hasMoreElements()) { - final HostAllocator allocator = enHost.nextElement(); - suitableHosts = allocator.allocateTo(vmProfile, plan, Host.Type.Routing, avoid, returnUpTo); - if (suitableHosts != null && !suitableHosts.isEmpty()) { - break; - } - } - - if(suitableHosts.isEmpty()){ - s_logger.debug("No suitable hosts found"); - } - return suitableHosts; - } - - protected Pair>, List> findSuitablePoolsForVolumes(VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo){ - List volumesTobeCreated = _volsDao.findUsableVolumesForInstance(vmProfile.getId()); - Map> suitableVolumeStoragePools = new HashMap>(); - List readyAndReusedVolumes = new ArrayList(); - - //for each volume find list of suitable storage pools by calling the allocators - for (VolumeVO toBeCreated : volumesTobeCreated) { - s_logger.debug("Checking suitable pools for volume (Id, Type): ("+toBeCreated.getId() +"," +toBeCreated.getVolumeType().name() + ")"); - - //If the plan specifies a poolId, it means that this VM's ROOT volume is ready and the pool should be reused. - //In this case, also check if rest of the volumes are ready and can be reused. - if(plan.getPoolId() != null){ - if (toBeCreated.getState() == Volume.State.Ready && toBeCreated.getPoolId() != null) { - s_logger.debug("Volume is in READY state and has pool already allocated, checking if pool can be reused, poolId: "+toBeCreated.getPoolId()); - List suitablePools = new ArrayList(); - StoragePoolVO pool = _storagePoolDao.findById(toBeCreated.getPoolId()); - if(!pool.isInMaintenance()){ - if(!avoid.shouldAvoid(pool)){ - long exstPoolDcId = pool.getDataCenterId(); + } + + protected Pair> findPotentialDeploymentResources(List suitableHosts, Map> suitableVolumeStoragePools){ + 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; + Map storage = new HashMap(); + for(Host potentialHost : suitableHosts){ + for(Volume vol : suitableVolumeStoragePools.keySet()){ + s_logger.debug("Checking if host: "+potentialHost.getId() +" can access any suitable storage pool for volume: "+ vol.getVolumeType()); + List volumePoolList = suitableVolumeStoragePools.get(vol); + hostCanAccessPool = false; + for(StoragePool potentialSPool : volumePoolList){ + if(hostCanAccessSPool(potentialHost, potentialSPool)){ + storage.put(vol, potentialSPool); + hostCanAccessPool = true; + break; + } + } + if(!hostCanAccessPool){ + break; + } + } + if(hostCanAccessPool){ + s_logger.debug("Found a potential host and associated storage pools for this VM"); + return new Pair>(potentialHost, storage); + } + } + s_logger.debug("Could not find a potential host that has associated storage pools from the suitable host/pool lists for this VM"); + return null; + } + + protected boolean hostCanAccessSPool(Host host, StoragePool pool){ + boolean hostCanAccessSPool = false; + + StoragePoolHostVO hostPoolLinkage = _poolHostDao.findByPoolHost(pool.getId(), host.getId()); + if(hostPoolLinkage != null){ + hostCanAccessSPool = true; + } + + s_logger.debug("Host: "+ host.getId() + (hostCanAccessSPool ?" can" : " cannot") + " access pool: "+ pool.getId()); + return hostCanAccessSPool; + } + + protected List findSuitableHosts(VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo){ + List suitableHosts = new ArrayList(); + Enumeration enHost = _hostAllocators.enumeration(); + s_logger.debug("Calling HostAllocators to find suitable hosts"); + + while (enHost.hasMoreElements()) { + final HostAllocator allocator = enHost.nextElement(); + suitableHosts = allocator.allocateTo(vmProfile, plan, Host.Type.Routing, avoid, returnUpTo); + if (suitableHosts != null && !suitableHosts.isEmpty()) { + break; + } + } + + if(suitableHosts.isEmpty()){ + s_logger.debug("No suitable hosts found"); + } + return suitableHosts; + } + + protected Pair>, List> findSuitablePoolsForVolumes(VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo){ + List volumesTobeCreated = _volsDao.findUsableVolumesForInstance(vmProfile.getId()); + Map> suitableVolumeStoragePools = new HashMap>(); + List readyAndReusedVolumes = new ArrayList(); + + //for each volume find list of suitable storage pools by calling the allocators + for (VolumeVO toBeCreated : volumesTobeCreated) { + s_logger.debug("Checking suitable pools for volume (Id, Type): ("+toBeCreated.getId() +"," +toBeCreated.getVolumeType().name() + ")"); + + //If the plan specifies a poolId, it means that this VM's ROOT volume is ready and the pool should be reused. + //In this case, also check if rest of the volumes are ready and can be reused. + if(plan.getPoolId() != null){ + if (toBeCreated.getState() == Volume.State.Ready && toBeCreated.getPoolId() != null) { + s_logger.debug("Volume is in READY state and has pool already allocated, checking if pool can be reused, poolId: "+toBeCreated.getPoolId()); + List suitablePools = new ArrayList(); + StoragePoolVO pool = _storagePoolDao.findById(toBeCreated.getPoolId()); + if(!pool.isInMaintenance()){ + if(!avoid.shouldAvoid(pool)){ + long exstPoolDcId = pool.getDataCenterId(); Long exstPoolPodId = pool.getPodId(); Long exstPoolClusterId = pool.getClusterId(); - if(plan.getDataCenterId() == exstPoolDcId && plan.getPodId() == exstPoolPodId && plan.getClusterId() == exstPoolClusterId){ - s_logger.debug("Planner need not allocate a pool for this volume since its READY"); - suitablePools.add(pool); - suitableVolumeStoragePools.put(toBeCreated, suitablePools); - readyAndReusedVolumes.add(toBeCreated); - continue; - }else{ - s_logger.debug("Pool of the volume does not fit the specified plan, need to reallocate a pool for this volume"); - } - }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"); - } - } - } - - s_logger.debug("Calling StoragePoolAllocators to find suitable pools"); - - DiskOfferingVO diskOffering = _diskOfferingDao.findById(toBeCreated.getDiskOfferingId()); - DiskProfile diskProfile = new DiskProfile(toBeCreated, diskOffering, vmProfile.getHypervisorType()); + if(plan.getDataCenterId() == exstPoolDcId && plan.getPodId() == exstPoolPodId && plan.getClusterId() == exstPoolClusterId){ + s_logger.debug("Planner need not allocate a pool for this volume since its READY"); + suitablePools.add(pool); + suitableVolumeStoragePools.put(toBeCreated, suitablePools); + readyAndReusedVolumes.add(toBeCreated); + continue; + }else{ + s_logger.debug("Pool of the volume does not fit the specified plan, need to reallocate a pool for this volume"); + } + }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"); + } + } + } - boolean useLocalStorage = false; - if (vmProfile.getType() != VirtualMachine.Type.User) { - String ssvmUseLocalStorage = _configDao.getValue(Config.SystemVMUseLocalStorage.key()); - if (ssvmUseLocalStorage.equalsIgnoreCase("true")) { - useLocalStorage = true; - } - } else { - useLocalStorage = diskOffering.getUseLocalStorage(); - } - diskProfile.setUseLocalStorage(useLocalStorage); - - - boolean foundPotentialPools = false; - - Enumeration enPool = _storagePoolAllocators.enumeration(); - while (enPool.hasMoreElements()) { - final StoragePoolAllocator allocator = enPool.nextElement(); - final List suitablePools = allocator.allocateToPool(diskProfile, vmProfile.getTemplate(), plan, avoid, returnUpTo); - if (suitablePools != null && !suitablePools.isEmpty()) { - suitableVolumeStoragePools.put(toBeCreated, suitablePools); - foundPotentialPools = true; - break; - } - } - - 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; - } - } + s_logger.debug("Calling StoragePoolAllocators to find suitable pools"); - if(suitableVolumeStoragePools.isEmpty()){ - s_logger.debug("No suitable pools found"); - } + DiskOfferingVO diskOffering = _diskOfferingDao.findById(toBeCreated.getDiskOfferingId()); + DiskProfile diskProfile = new DiskProfile(toBeCreated, diskOffering, vmProfile.getHypervisorType()); - return new Pair>, List>(suitableVolumeStoragePools, readyAndReusedVolumes); - } + boolean useLocalStorage = false; + if (vmProfile.getType() != VirtualMachine.Type.User) { + String ssvmUseLocalStorage = _configDao.getValue(Config.SystemVMUseLocalStorage.key()); + if (ssvmUseLocalStorage.equalsIgnoreCase("true")) { + useLocalStorage = true; + } + } else { + useLocalStorage = diskOffering.getUseLocalStorage(); + } + diskProfile.setUseLocalStorage(useLocalStorage); - - @Override - public boolean check(VirtualMachineProfile vm, DeploymentPlan plan, - DeployDestination dest, ExcludeList exclude) { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean canHandle(VirtualMachineProfile vm, DeploymentPlan plan, ExcludeList avoid) { - return vm.getHypervisorType() != HypervisorType.BareMetal; + + boolean foundPotentialPools = false; + + Enumeration enPool = _storagePoolAllocators.enumeration(); + while (enPool.hasMoreElements()) { + final StoragePoolAllocator allocator = enPool.nextElement(); + final List suitablePools = allocator.allocateToPool(diskProfile, vmProfile.getTemplate(), plan, avoid, returnUpTo); + if (suitablePools != null && !suitablePools.isEmpty()) { + suitableVolumeStoragePools.put(toBeCreated, suitablePools); + foundPotentialPools = true; + break; + } + } + + 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; + } + } + + if(suitableVolumeStoragePools.isEmpty()){ + s_logger.debug("No suitable pools found"); + } + + return new Pair>, List>(suitableVolumeStoragePools, readyAndReusedVolumes); } - + + + @Override + public boolean check(VirtualMachineProfile vm, DeploymentPlan plan, + DeployDestination dest, ExcludeList exclude) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean canHandle(VirtualMachineProfile vm, DeploymentPlan plan, ExcludeList avoid) { + return vm.getHypervisorType() != HypervisorType.BareMetal; + } + private boolean isEnabledForAllocation(long zoneId, Long podId, Long clusterId){ - // Check if the zone exists in the system - DataCenterVO zone = _dcDao.findById(zoneId); - if(zone != null && Grouping.AllocationState.Disabled == zone.getAllocationState()){ - s_logger.info("Zone is currently disabled, cannot allocate to this zone: "+ zoneId); - return false; - } + // Check if the zone exists in the system + DataCenterVO zone = _dcDao.findById(zoneId); + if(zone != null && Grouping.AllocationState.Disabled == zone.getAllocationState()){ + s_logger.info("Zone is currently disabled, cannot allocate to this zone: "+ zoneId); + return false; + } - Pod pod = _podDao.findById(podId); - if(pod != null && Grouping.AllocationState.Disabled == pod.getAllocationState()){ - s_logger.info("Pod is currently disabled, cannot allocate to this pod: "+ podId); - return false; - } + Pod pod = _podDao.findById(podId); + if(pod != null && Grouping.AllocationState.Disabled == pod.getAllocationState()){ + s_logger.info("Pod is currently disabled, cannot allocate to this pod: "+ podId); + return false; + } - Cluster cluster = _clusterDao.findById(clusterId); - if(cluster != null && Grouping.AllocationState.Disabled == cluster.getAllocationState()){ - s_logger.info("Cluster is currently disabled, cannot allocate to this cluster: "+ clusterId); - return false; - } + Cluster cluster = _clusterDao.findById(clusterId); + if(cluster != null && Grouping.AllocationState.Disabled == cluster.getAllocationState()){ + s_logger.info("Cluster is currently disabled, cannot allocate to this cluster: "+ clusterId); + return false; + } - return true; + return true; } }