From 3d4767c94c613be9bc0eebefa71e53fc74b2df42 Mon Sep 17 00:00:00 2001 From: prachi Date: Sat, 20 Aug 2011 21:02:09 -0700 Subject: [PATCH] Merge Bug 11186 from 2.2.8mango Bug 11186- Cannot restart existing VM if the cluster is disabled after the VM has been created Changes: - We should not check for the cluster 'allocation_state' while starting an existing VM provided it has storage already allocated. But if volumes are deleted and new storage needs to be allocated, then we will not allow the VM start. - However we should still prohibit adding new VMs in that cluster. --- .../src/com/cloud/deploy/FirstFitPlanner.java | 82 +++++++++---------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/server/src/com/cloud/deploy/FirstFitPlanner.java b/server/src/com/cloud/deploy/FirstFitPlanner.java index 88478595d75..ead384e53b7 100644 --- a/server/src/com/cloud/deploy/FirstFitPlanner.java +++ b/server/src/com/cloud/deploy/FirstFitPlanner.java @@ -106,7 +106,7 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner { @Override public DeployDestination plan(VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid) - throws InsufficientServerCapacityException { + throws InsufficientServerCapacityException { String _allocationAlgorithm = _configDao.getValue(Config.VmAllocationAlgorithm.key()); VirtualMachine vm = vmProfile.getVirtualMachine(); ServiceOffering offering = vmProfile.getServiceOffering(); @@ -179,38 +179,35 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner { 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); + 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; + 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 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()); @@ -220,11 +217,6 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner { 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(); @@ -365,13 +357,6 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner { 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()); @@ -595,6 +580,21 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner { } } + if(s_logger.isDebugEnabled()){ + s_logger.debug("We need to allocate new storagepool for this volume"); + } + 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());