Skip to content

Commit 1cdc064

Browse files
committed
CLOUDSTACK-4880:
check for host cpu capability while dynamic scaling a vm on the same host
1 parent dd34ae9 commit 1cdc064

4 files changed

Lines changed: 35 additions & 3 deletions

File tree

‎engine/components-api/src/com/cloud/capacity/CapacityManager.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,13 @@ public interface CapacityManager {
7575
* @return true if the count of host's running VMs >= hypervisor limit
7676
*/
7777
boolean checkIfHostReachMaxGuestLimit(Host host);
78+
79+
/**
80+
* Check if specified host has capability to support cpu cores and speed freq
81+
* @param hostId the host to be checked
82+
* @param cpuNum cpu number to check
83+
* @param cpuSpeed cpu Speed to check
84+
* @return true if the count of host's running VMs >= hypervisor limit
85+
*/
86+
boolean checkIfHostHasCpuCapability(long hostId, Integer cpuNum, Integer cpuSpeed);
7887
}

‎server/src/com/cloud/capacity/CapacityManagerImpl.java‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,28 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
362362
}
363363
}
364364

365+
@Override
366+
public boolean checkIfHostHasCpuCapability(long hostId, Integer cpuNum, Integer cpuSpeed){
367+
368+
// Check host can support the Cpu Number and Speed.
369+
Host host = _hostDao.findById(hostId);
370+
boolean isCpuNumGood = host.getCpus().intValue() >= cpuNum;
371+
boolean isCpuSpeedGood = host.getSpeed().intValue() >= cpuSpeed;
372+
if(isCpuNumGood && isCpuSpeedGood){
373+
if (s_logger.isDebugEnabled()) {
374+
s_logger.debug("Host: " + hostId + " has cpu capability (cpu:" +host.getCpus()+ ", speed:" + host.getSpeed() +
375+
") to support requested CPU: " + cpuNum + " and requested speed: " + cpuSpeed);
376+
}
377+
return true;
378+
}else{
379+
if (s_logger.isDebugEnabled()) {
380+
s_logger.debug("Host: " + hostId + " doesn't have cpu capability (cpu:" +host.getCpus()+ ", speed:" + host.getSpeed() +
381+
") to support requested CPU: " + cpuNum + " and requested speed: " + cpuSpeed);
382+
}
383+
return false;
384+
}
385+
}
386+
365387
@Override
366388
public boolean checkIfHostHasCapacity(long hostId, Integer cpu, long ram, boolean checkFromReservedCapacity, float cpuOvercommitRatio, float memoryOvercommitRatio, boolean considerReservedCapacity) {
367389
boolean hasCapacity = false;

‎server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3433,9 +3433,9 @@ private void createDhcpEntryCommandsForVMs(DomainRouterVO router, Commands cmds,
34333433
}
34343434

34353435
protected boolean sendCommandsToRouter(final VirtualRouter router, Commands cmds) throws AgentUnavailableException {
3436-
if(!checkRouterVersion(router)){
3436+
/*if(!checkRouterVersion(router)){
34373437
throw new CloudRuntimeException("Router requires upgrade. Unable to send command to router:" + router.getId());
3438-
}
3438+
} */
34393439
Answer[] answers = null;
34403440
try {
34413441
answers = _agentMgr.send(router.getHostId(), cmds);

‎server/src/com/cloud/vm/UserVmManagerImpl.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1371,7 +1371,8 @@ private boolean upgradeRunningVirtualMachine(Long vmId, Long newServiceOfferingI
13711371

13721372
// #1 Check existing host has capacity
13731373
if( !excludes.shouldAvoid(ApiDBUtils.findHostById(vmInstance.getHostId())) ){
1374-
existingHostHasCapacity = _capacityMgr.checkIfHostHasCapacity(vmInstance.getHostId(), newServiceOffering.getSpeed() - currentServiceOffering.getSpeed(),
1374+
existingHostHasCapacity = _capacityMgr.checkIfHostHasCpuCapability(vmInstance.getHostId(), newCpu, newSpeed)
1375+
&& _capacityMgr.checkIfHostHasCapacity(vmInstance.getHostId(), newServiceOffering.getSpeed() - currentServiceOffering.getSpeed(),
13751376
(newServiceOffering.getRamSize() - currentServiceOffering.getRamSize()) * 1024L * 1024L, false, ApiDBUtils.getCpuOverprovisioningFactor(), 1f, false); // TO DO fill it with mem.
13761377
excludes.addHost(vmInstance.getHostId());
13771378
}

0 commit comments

Comments
 (0)