diff --git a/engine/components-api/src/com/cloud/capacity/CapacityManager.java b/engine/components-api/src/com/cloud/capacity/CapacityManager.java index 4332ede20dd..13624e69453 100755 --- a/engine/components-api/src/com/cloud/capacity/CapacityManager.java +++ b/engine/components-api/src/com/cloud/capacity/CapacityManager.java @@ -82,4 +82,13 @@ public interface CapacityManager { * @return true if the count of host's running VMs >= hypervisor limit */ boolean checkIfHostReachMaxGuestLimit(Host host); + + /** + * Check if specified host has capability to support cpu cores and speed freq + * @param hostId the host to be checked + * @param cpuNum cpu number to check + * @param cpuSpeed cpu Speed to check + * @return true if the count of host's running VMs >= hypervisor limit + */ + boolean checkIfHostHasCpuCapability(long hostId, Integer cpuNum, Integer cpuSpeed); } diff --git a/server/src/com/cloud/capacity/CapacityManagerImpl.java b/server/src/com/cloud/capacity/CapacityManagerImpl.java index 8ed24338bf2..2358f92ade4 100755 --- a/server/src/com/cloud/capacity/CapacityManagerImpl.java +++ b/server/src/com/cloud/capacity/CapacityManagerImpl.java @@ -352,9 +352,29 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager, } } + public boolean checkIfHostHasCpuCapability(long hostId, Integer cpuNum, Integer cpuSpeed){ + + // Check host can support the Cpu Number and Speed. + Host host = _hostDao.findById(hostId); + boolean isCpuNumGood = host.getCpus().intValue() >= cpuNum; + boolean isCpuSpeedGood = host.getSpeed().intValue() >= cpuSpeed; + if(isCpuNumGood && isCpuSpeedGood){ + if (s_logger.isDebugEnabled()) { + s_logger.debug("Host: " + hostId + " has cpu capability (cpu:" +host.getCpus()+ ", speed:" + host.getSpeed() + + ") to support requested CPU: " + cpuNum + " and requested speed: " + cpuSpeed); + } + return true; + }else{ + if (s_logger.isDebugEnabled()) { + s_logger.debug("Host: " + hostId + " doesn't have cpu capability (cpu:" +host.getCpus()+ ", speed:" + host.getSpeed() + + ") to support requested CPU: " + cpuNum + " and requested speed: " + cpuSpeed); + } + return false; + } + } + @Override - public boolean checkIfHostHasCapacity(long hostId, Integer cpu, long ram, boolean checkFromReservedCapacity, float cpuOvercommitRatio, float memoryOvercommitRatio, - boolean considerReservedCapacity) { + public boolean checkIfHostHasCapacity(long hostId, Integer cpu, long ram, boolean checkFromReservedCapacity, float cpuOvercommitRatio, float memoryOvercommitRatio, boolean considerReservedCapacity) { boolean hasCapacity = false; if (s_logger.isDebugEnabled()) { diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 4e78ba14313..1752c22a1e3 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -1349,11 +1349,10 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir } // #1 Check existing host has capacity - if (!excludes.shouldAvoid(ApiDBUtils.findHostById(vmInstance.getHostId()))) { - existingHostHasCapacity = - _capacityMgr.checkIfHostHasCapacity(vmInstance.getHostId(), newServiceOffering.getSpeed() - currentServiceOffering.getSpeed(), - (newServiceOffering.getRamSize() - currentServiceOffering.getRamSize()) * 1024L * 1024L, false, - ApiDBUtils.getCpuOverprovisioningFactor(), 1f, false); // TO DO fill it with mem. + if( !excludes.shouldAvoid(ApiDBUtils.findHostById(vmInstance.getHostId())) ){ + existingHostHasCapacity = _capacityMgr.checkIfHostHasCpuCapability(vmInstance.getHostId(), newCpu, newSpeed) + && _capacityMgr.checkIfHostHasCapacity(vmInstance.getHostId(), newServiceOffering.getSpeed() - currentServiceOffering.getSpeed(), + (newServiceOffering.getRamSize() - currentServiceOffering.getRamSize()) * 1024L * 1024L, false, ApiDBUtils.getCpuOverprovisioningFactor(), 1f, false); // TO DO fill it with mem. excludes.addHost(vmInstance.getHostId()); }