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:14:31 -08:00
parent dd34ae97fd
commit 1cdc064c43
4 changed files with 35 additions and 3 deletions

View File

@ -75,4 +75,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

@ -362,6 +362,28 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager,
}
}
@Override
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) {
boolean hasCapacity = false;

View File

@ -3433,9 +3433,9 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
}
protected boolean sendCommandsToRouter(final VirtualRouter router, Commands cmds) throws AgentUnavailableException {
if(!checkRouterVersion(router)){
/*if(!checkRouterVersion(router)){
throw new CloudRuntimeException("Router requires upgrade. Unable to send command to router:" + router.getId());
}
} */
Answer[] answers = null;
try {
answers = _agentMgr.send(router.getHostId(), cmds);

View File

@ -1371,7 +1371,8 @@ 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(),
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());
}