diff --git a/server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java b/server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java index ac2e92b665f..2a5258c3bd1 100755 --- a/server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java +++ b/server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java @@ -77,7 +77,6 @@ public class FirstFitAllocator implements HostAllocator { @Inject ConfigurationDao _configDao = null; @Inject GuestOSDao _guestOSDao = null; @Inject GuestOSCategoryDao _guestOSCategoryDao = null; - @Inject HypervisorCapabilitiesDao _hypervisorCapabilitiesDao = null; @Inject VMInstanceDao _vmInstanceDao = null; @Inject ResourceManager _resourceMgr; float _factor = 1; @@ -206,11 +205,9 @@ public class FirstFitAllocator implements HostAllocator { } //find number of guest VMs occupying capacity on this host. - Long vmCount = _vmInstanceDao.countRunningByHostId(host.getId()); - Long maxGuestLimit = getHostMaxGuestLimit(host); - if (vmCount.longValue() == maxGuestLimit.longValue()){ + if (_capacityMgr.checkIfHostReachMaxGuestLimit(host)){ if (s_logger.isDebugEnabled()) { - s_logger.debug("Host name: " + host.getName() + ", hostId: "+ host.getId() +" already has max Running VMs(count includes system VMs), limit is: " + maxGuestLimit + " , skipping this and trying other available hosts"); + s_logger.debug("Host name: " + host.getName() + ", hostId: "+ host.getId() +" already has max Running VMs(count includes system VMs), skipping this and trying other available hosts"); } continue; } @@ -393,15 +390,7 @@ public class FirstFitAllocator implements HostAllocator { GuestOSCategoryVO guestOSCategory = _guestOSCategoryDao.findById(guestOSCategoryId); return guestOSCategory.getName(); } - - protected Long getHostMaxGuestLimit(HostVO host) { - HypervisorType hypervisorType = host.getHypervisorType(); - String hypervisorVersion = host.getHypervisorVersion(); - Long maxGuestLimit = _hypervisorCapabilitiesDao.getMaxGuestsLimit(hypervisorType, hypervisorVersion); - return maxGuestLimit; - } - @Override public boolean configure(String name, Map params) throws ConfigurationException { _name = name; diff --git a/server/src/com/cloud/capacity/CapacityManager.java b/server/src/com/cloud/capacity/CapacityManager.java index aad0d46710e..fffb41f87e6 100755 --- a/server/src/com/cloud/capacity/CapacityManager.java +++ b/server/src/com/cloud/capacity/CapacityManager.java @@ -48,4 +48,11 @@ public interface CapacityManager extends Manager { * @return total allocated capacity for the storage pool */ long getAllocatedPoolCapacity(StoragePoolVO pool, VMTemplateVO templateForVmCreation); + + /** + * Check if specified host's running VM count has reach hypervisor limit + * @param host the host to be checked + * @return true if the count of host's running VMs >= hypervisor limit + */ + boolean checkIfHostReachMaxGuestLimit(HostVO host); } diff --git a/server/src/com/cloud/capacity/CapacityManagerImpl.java b/server/src/com/cloud/capacity/CapacityManagerImpl.java index f400e44b8b5..c410109b9ef 100755 --- a/server/src/com/cloud/capacity/CapacityManagerImpl.java +++ b/server/src/com/cloud/capacity/CapacityManagerImpl.java @@ -45,6 +45,8 @@ import com.cloud.exception.ConnectionException; import com.cloud.host.HostVO; import com.cloud.host.Status; import com.cloud.host.dao.HostDao; +import com.cloud.hypervisor.Hypervisor.HypervisorType; +import com.cloud.hypervisor.dao.HypervisorCapabilitiesDao; import com.cloud.offering.ServiceOffering; import com.cloud.org.Grouping.AllocationState; import com.cloud.resource.ResourceListener; @@ -104,6 +106,8 @@ public class CapacityManagerImpl implements CapacityManager, StateListener= maxGuestLimit.longValue()){ + if (s_logger.isDebugEnabled()) { + s_logger.debug("Host name: " + host.getName() + ", hostId: "+ host.getId() + + " already reached max Running VMs(count includes system VMs), limit is: " + maxGuestLimit + ",Running VM counts is: "+vmCount.longValue()); + } + return true; + } + return false; + } } diff --git a/server/src/com/cloud/deploy/FirstFitPlanner.java b/server/src/com/cloud/deploy/FirstFitPlanner.java index e70ea4de308..d22b55f7b50 100755 --- a/server/src/com/cloud/deploy/FirstFitPlanner.java +++ b/server/src/com/cloud/deploy/FirstFitPlanner.java @@ -196,6 +196,8 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner { s_logger.debug("The last host of this VM cannot be found"); }else if(avoid.shouldAvoid(host)){ s_logger.debug("The last host of this VM is in avoid set"); + }else if(_capacityMgr.checkIfHostReachMaxGuestLimit(host)){ + s_logger.debug("The last Host, hostId: "+ host.getId() +" already has max Running VMs(count includes system VMs), skipping this and trying other available hosts"); }else{ if (host.getStatus() == Status.Up && host.getResourceState() == ResourceState.Enabled) { if(_capacityMgr.checkIfHostHasCapacity(host.getId(), cpu_requested, ram_requested, true, cpuOverprovisioningFactor, true)){ diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 4a0a8d96281..a0da7080276 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -78,6 +78,7 @@ import com.cloud.async.AsyncJobExecutor; import com.cloud.async.AsyncJobManager; import com.cloud.async.AsyncJobVO; import com.cloud.async.BaseAsyncJobExecutor; +import com.cloud.capacity.CapacityManager; import com.cloud.configuration.Config; import com.cloud.configuration.ConfigurationManager; import com.cloud.configuration.Resource.ResourceType; @@ -326,9 +327,11 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager @Inject protected UserVmDetailsDao _vmDetailsDao; @Inject + protected HypervisorCapabilitiesDao _hypervisorCapabilitiesDao; + @Inject protected SecurityGroupDao _securityGroupDao; @Inject - protected HypervisorCapabilitiesDao _hypervisorCapabilitiesDao; + protected CapacityManager _capacityMgr;; @Inject protected VMInstanceDao _vmInstanceDao; @Inject @@ -3268,15 +3271,12 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager DeployDestination dest = new DeployDestination(dcVO, pod, cluster, destinationHost); //check max guest vm limit for the destinationHost - HypervisorType hypervisorType = destinationHost.getHypervisorType(); - String hypervisorVersion = destinationHost.getHypervisorVersion(); - Long maxGuestLimit = _hypervisorCapabilitiesDao.getMaxGuestsLimit(hypervisorType, hypervisorVersion); - Long vmCount = _vmInstanceDao.countRunningByHostId(destinationHost.getId()); - if (vmCount.longValue() == maxGuestLimit.longValue()){ + HostVO destinationHostVO = _hostDao.findById(destinationHost.getId()); + if(_capacityMgr.checkIfHostReachMaxGuestLimit(destinationHostVO)){ if (s_logger.isDebugEnabled()) { - s_logger.debug("Host name: " + destinationHost.getName() + ", hostId: "+ destinationHost.getId() +" already has max Running VMs(count includes system VMs), limit is: " + maxGuestLimit + " , cannot migrate to this host"); + s_logger.debug("Host name: " + destinationHost.getName() + ", hostId: "+ destinationHost.getId() +" already has max Running VMs(count includes system VMs), cannot migrate to this host"); } - throw new VirtualMachineMigrationException("Destination host, hostId: "+ destinationHost.getId() +" already has max Running VMs(count includes system VMs), limit is: " + maxGuestLimit + " , cannot migrate to this host"); + throw new VirtualMachineMigrationException("Destination host, hostId: "+ destinationHost.getId() +" already has max Running VMs(count includes system VMs), cannot migrate to this host"); } VMInstanceVO migratedVm = _itMgr.migrate(vm, srcHostId, dest);