CLOUDSTACK-4880:

check for host cpu capability while dynamic scaling a vm on the same host
This commit is contained in:
Nitin Mehta 2013-12-05 14:31:27 -08:00
parent ee607646c9
commit 98ee087d31
3 changed files with 35 additions and 7 deletions

View File

@ -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);
}

View File

@ -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()) {

View File

@ -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());
}