Skip to content

Commit a746871

Browse files
author
Mice Xia
committed
Fix bug CS-15679 Max guest limit of hypervisor capabilities does not work properly
1 parent bd2a130 commit a746871

5 files changed

Lines changed: 38 additions & 21 deletions

File tree

‎server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java‎

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ public class FirstFitAllocator implements HostAllocator {
7777
@Inject ConfigurationDao _configDao = null;
7878
@Inject GuestOSDao _guestOSDao = null;
7979
@Inject GuestOSCategoryDao _guestOSCategoryDao = null;
80-
@Inject HypervisorCapabilitiesDao _hypervisorCapabilitiesDao = null;
8180
@Inject VMInstanceDao _vmInstanceDao = null;
8281
@Inject ResourceManager _resourceMgr;
8382
float _factor = 1;
@@ -206,11 +205,9 @@ protected List<Host> allocateTo(DeploymentPlan plan, ServiceOffering offering, V
206205
}
207206

208207
//find number of guest VMs occupying capacity on this host.
209-
Long vmCount = _vmInstanceDao.countRunningByHostId(host.getId());
210-
Long maxGuestLimit = getHostMaxGuestLimit(host);
211-
if (vmCount.longValue() == maxGuestLimit.longValue()){
208+
if (_capacityMgr.checkIfHostReachMaxGuestLimit(host)){
212209
if (s_logger.isDebugEnabled()) {
213-
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");
210+
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");
214211
}
215212
continue;
216213
}
@@ -393,15 +390,7 @@ protected String getTemplateGuestOSCategory(VMTemplateVO template) {
393390
GuestOSCategoryVO guestOSCategory = _guestOSCategoryDao.findById(guestOSCategoryId);
394391
return guestOSCategory.getName();
395392
}
396-
397-
protected Long getHostMaxGuestLimit(HostVO host) {
398-
HypervisorType hypervisorType = host.getHypervisorType();
399-
String hypervisorVersion = host.getHypervisorVersion();
400393

401-
Long maxGuestLimit = _hypervisorCapabilitiesDao.getMaxGuestsLimit(hypervisorType, hypervisorVersion);
402-
return maxGuestLimit;
403-
}
404-
405394
@Override
406395
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
407396
_name = name;

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,11 @@ public interface CapacityManager extends Manager {
4848
* @return total allocated capacity for the storage pool
4949
*/
5050
long getAllocatedPoolCapacity(StoragePoolVO pool, VMTemplateVO templateForVmCreation);
51+
52+
/**
53+
* Check if specified host's running VM count has reach hypervisor limit
54+
* @param host the host to be checked
55+
* @return true if the count of host's running VMs >= hypervisor limit
56+
*/
57+
boolean checkIfHostReachMaxGuestLimit(HostVO host);
5158
}

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
import com.cloud.host.HostVO;
4646
import com.cloud.host.Status;
4747
import com.cloud.host.dao.HostDao;
48+
import com.cloud.hypervisor.Hypervisor.HypervisorType;
49+
import com.cloud.hypervisor.dao.HypervisorCapabilitiesDao;
4850
import com.cloud.offering.ServiceOffering;
4951
import com.cloud.org.Grouping.AllocationState;
5052
import com.cloud.resource.ResourceListener;
@@ -104,6 +106,8 @@ public class CapacityManagerImpl implements CapacityManager, StateListener<State
104106
SwiftManager _swiftMgr;
105107
@Inject
106108
ConfigurationManager _configMgr;
109+
@Inject
110+
HypervisorCapabilitiesDao _hypervisorCapabilitiesDao;
107111

108112
private int _vmCapacityReleaseInterval;
109113
private ScheduledExecutorService _executor;
@@ -827,4 +831,19 @@ public void processPrepareMaintenaceEventBefore(Long hostId) {
827831

828832
}
829833

834+
@Override
835+
public boolean checkIfHostReachMaxGuestLimit(HostVO host) {
836+
Long vmCount = _vmDao.countRunningByHostId(host.getId());
837+
HypervisorType hypervisorType = host.getHypervisorType();
838+
String hypervisorVersion = host.getHypervisorVersion();
839+
Long maxGuestLimit = _hypervisorCapabilitiesDao.getMaxGuestsLimit(hypervisorType, hypervisorVersion);
840+
if(vmCount.longValue() >= maxGuestLimit.longValue()){
841+
if (s_logger.isDebugEnabled()) {
842+
s_logger.debug("Host name: " + host.getName() + ", hostId: "+ host.getId() +
843+
" already reached max Running VMs(count includes system VMs), limit is: " + maxGuestLimit + ",Running VM counts is: "+vmCount.longValue());
844+
}
845+
return true;
846+
}
847+
return false;
848+
}
830849
}

‎server/src/com/cloud/deploy/FirstFitPlanner.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ public DeployDestination plan(VirtualMachineProfile<? extends VirtualMachine> vm
196196
s_logger.debug("The last host of this VM cannot be found");
197197
}else if(avoid.shouldAvoid(host)){
198198
s_logger.debug("The last host of this VM is in avoid set");
199+
}else if(_capacityMgr.checkIfHostReachMaxGuestLimit(host)){
200+
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");
199201
}else{
200202
if (host.getStatus() == Status.Up && host.getResourceState() == ResourceState.Enabled) {
201203
if(_capacityMgr.checkIfHostHasCapacity(host.getId(), cpu_requested, ram_requested, true, cpuOverprovisioningFactor, true)){

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
import com.cloud.async.AsyncJobManager;
7979
import com.cloud.async.AsyncJobVO;
8080
import com.cloud.async.BaseAsyncJobExecutor;
81+
import com.cloud.capacity.CapacityManager;
8182
import com.cloud.configuration.Config;
8283
import com.cloud.configuration.ConfigurationManager;
8384
import com.cloud.configuration.Resource.ResourceType;
@@ -326,9 +327,11 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
326327
@Inject
327328
protected UserVmDetailsDao _vmDetailsDao;
328329
@Inject
330+
protected HypervisorCapabilitiesDao _hypervisorCapabilitiesDao;
331+
@Inject
329332
protected SecurityGroupDao _securityGroupDao;
330333
@Inject
331-
protected HypervisorCapabilitiesDao _hypervisorCapabilitiesDao;
334+
protected CapacityManager _capacityMgr;;
332335
@Inject
333336
protected VMInstanceDao _vmInstanceDao;
334337
@Inject
@@ -3268,15 +3271,12 @@ public VirtualMachine migrateVirtualMachine(Long vmId, Host destinationHost) thr
32683271
DeployDestination dest = new DeployDestination(dcVO, pod, cluster, destinationHost);
32693272

32703273
//check max guest vm limit for the destinationHost
3271-
HypervisorType hypervisorType = destinationHost.getHypervisorType();
3272-
String hypervisorVersion = destinationHost.getHypervisorVersion();
3273-
Long maxGuestLimit = _hypervisorCapabilitiesDao.getMaxGuestsLimit(hypervisorType, hypervisorVersion);
3274-
Long vmCount = _vmInstanceDao.countRunningByHostId(destinationHost.getId());
3275-
if (vmCount.longValue() == maxGuestLimit.longValue()){
3274+
HostVO destinationHostVO = _hostDao.findById(destinationHost.getId());
3275+
if(_capacityMgr.checkIfHostReachMaxGuestLimit(destinationHostVO)){
32763276
if (s_logger.isDebugEnabled()) {
3277-
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");
3277+
s_logger.debug("Host name: " + destinationHost.getName() + ", hostId: "+ destinationHost.getId() +" already has max Running VMs(count includes system VMs), cannot migrate to this host");
32783278
}
3279-
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");
3279+
throw new VirtualMachineMigrationException("Destination host, hostId: "+ destinationHost.getId() +" already has max Running VMs(count includes system VMs), cannot migrate to this host");
32803280
}
32813281

32823282
VMInstanceVO migratedVm = _itMgr.migrate(vm, srcHostId, dest);

0 commit comments

Comments
 (0)