You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by al...@apache.org on 2012/08/10 19:50:03 UTC

[9/36] git commit: Fix bug CS-15679 Max guest limit of hypervisor capabilities does not work properly

Fix bug CS-15679 Max guest limit of hypervisor capabilities does not work properly


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/a7468712
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/a7468712
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/a7468712

Branch: refs/heads/vpc
Commit: a74687128e41b708bf80085ab8942a195747145c
Parents: bd2a130
Author: Mice Xia <mi...@apache.org>
Authored: Fri Aug 10 16:50:47 2012 +0800
Committer: Mice Xia <mi...@apache.org>
Committed: Fri Aug 10 16:50:47 2012 +0800

----------------------------------------------------------------------
 .../manager/allocator/impl/FirstFitAllocator.java  |   15 +----------
 server/src/com/cloud/capacity/CapacityManager.java |    7 +++++
 .../com/cloud/capacity/CapacityManagerImpl.java    |   19 +++++++++++++++
 server/src/com/cloud/deploy/FirstFitPlanner.java   |    2 +
 server/src/com/cloud/vm/UserVmManagerImpl.java     |   16 ++++++------
 5 files changed, 38 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a7468712/server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java b/server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java
index ac2e92b..2a5258c 100755
--- a/server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java
+++ b/server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java
@@ -77,7 +77,6 @@ public class FirstFitAllocator implements HostAllocator {
     @Inject ConfigurationDao _configDao = null;
     @Inject GuestOSDao _guestOSDao = null; 
     @Inject GuestOSCategoryDao _guestOSCategoryDao = null;
-    @Inject HypervisorCapabilitiesDao _hypervisorCapabilitiesDao = null;
     @Inject VMInstanceDao _vmInstanceDao = null;
     @Inject ResourceManager _resourceMgr;
     float _factor = 1;
@@ -206,11 +205,9 @@ public class FirstFitAllocator implements HostAllocator {
             }
                         
             //find number of guest VMs occupying capacity on this host.
-            Long vmCount = _vmInstanceDao.countRunningByHostId(host.getId());
-            Long maxGuestLimit = getHostMaxGuestLimit(host);
-            if (vmCount.longValue() == maxGuestLimit.longValue()){
+            if (_capacityMgr.checkIfHostReachMaxGuestLimit(host)){
                 if (s_logger.isDebugEnabled()) {
-                    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");
+                    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");
                 }
                 continue;
             }
@@ -393,15 +390,7 @@ public class FirstFitAllocator implements HostAllocator {
     	GuestOSCategoryVO guestOSCategory = _guestOSCategoryDao.findById(guestOSCategoryId);
     	return guestOSCategory.getName();
     }
-    
-    protected Long getHostMaxGuestLimit(HostVO host) {
-        HypervisorType hypervisorType = host.getHypervisorType();
-        String hypervisorVersion = host.getHypervisorVersion();
 
-        Long maxGuestLimit = _hypervisorCapabilitiesDao.getMaxGuestsLimit(hypervisorType, hypervisorVersion);
-        return maxGuestLimit;
-    }
-    
     @Override
     public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
         _name = name;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a7468712/server/src/com/cloud/capacity/CapacityManager.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/capacity/CapacityManager.java b/server/src/com/cloud/capacity/CapacityManager.java
index aad0d46..fffb41f 100755
--- a/server/src/com/cloud/capacity/CapacityManager.java
+++ b/server/src/com/cloud/capacity/CapacityManager.java
@@ -48,4 +48,11 @@ public interface CapacityManager extends Manager {
      * @return total allocated capacity for the storage pool
      */
     long getAllocatedPoolCapacity(StoragePoolVO pool, VMTemplateVO templateForVmCreation);
+    
+    /**
+     * Check if specified host's running VM count has reach hypervisor limit
+     * @param host the host to be checked
+     * @return true if the count of host's running VMs >= hypervisor limit
+     */
+    boolean checkIfHostReachMaxGuestLimit(HostVO host);
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a7468712/server/src/com/cloud/capacity/CapacityManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/capacity/CapacityManagerImpl.java b/server/src/com/cloud/capacity/CapacityManagerImpl.java
index f400e44..c410109 100755
--- a/server/src/com/cloud/capacity/CapacityManagerImpl.java
+++ b/server/src/com/cloud/capacity/CapacityManagerImpl.java
@@ -45,6 +45,8 @@ import com.cloud.exception.ConnectionException;
 import com.cloud.host.HostVO;
 import com.cloud.host.Status;
 import com.cloud.host.dao.HostDao;
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.hypervisor.dao.HypervisorCapabilitiesDao;
 import com.cloud.offering.ServiceOffering;
 import com.cloud.org.Grouping.AllocationState;
 import com.cloud.resource.ResourceListener;
@@ -104,6 +106,8 @@ public class CapacityManagerImpl implements CapacityManager, StateListener<State
     SwiftManager _swiftMgr; 
     @Inject
     ConfigurationManager _configMgr;   
+    @Inject
+    HypervisorCapabilitiesDao _hypervisorCapabilitiesDao;
 
     private int _vmCapacityReleaseInterval;
     private ScheduledExecutorService _executor;
@@ -827,4 +831,19 @@ public class CapacityManagerImpl implements CapacityManager, StateListener<State
 		
 	}
 
+    @Override
+    public boolean checkIfHostReachMaxGuestLimit(HostVO host) {
+        Long vmCount = _vmDao.countRunningByHostId(host.getId());
+        HypervisorType hypervisorType = host.getHypervisorType();
+        String hypervisorVersion = host.getHypervisorVersion();
+        Long maxGuestLimit = _hypervisorCapabilitiesDao.getMaxGuestsLimit(hypervisorType, hypervisorVersion);
+        if(vmCount.longValue() >= maxGuestLimit.longValue()){
+            if (s_logger.isDebugEnabled()) {
+                s_logger.debug("Host name: " + host.getName() + ", hostId: "+ host.getId() + 
+                        " already reached max Running VMs(count includes system VMs), limit is: " + maxGuestLimit + ",Running VM counts is: "+vmCount.longValue());
+            }
+            return true;
+        }
+        return false;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a7468712/server/src/com/cloud/deploy/FirstFitPlanner.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/deploy/FirstFitPlanner.java b/server/src/com/cloud/deploy/FirstFitPlanner.java
index e70ea4d..d22b55f 100755
--- a/server/src/com/cloud/deploy/FirstFitPlanner.java
+++ b/server/src/com/cloud/deploy/FirstFitPlanner.java
@@ -196,6 +196,8 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner {
                 s_logger.debug("The last host of this VM cannot be found");
             }else if(avoid.shouldAvoid(host)){
                 s_logger.debug("The last host of this VM is in avoid set");
+            }else if(_capacityMgr.checkIfHostReachMaxGuestLimit(host)){
+                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");
             }else{
                 if (host.getStatus() == Status.Up && host.getResourceState() == ResourceState.Enabled) {
                     if(_capacityMgr.checkIfHostHasCapacity(host.getId(), cpu_requested, ram_requested, true, cpuOverprovisioningFactor, true)){

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a7468712/server/src/com/cloud/vm/UserVmManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java
index 4a0a8d9..a0da708 100755
--- a/server/src/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/com/cloud/vm/UserVmManagerImpl.java
@@ -78,6 +78,7 @@ import com.cloud.async.AsyncJobExecutor;
 import com.cloud.async.AsyncJobManager;
 import com.cloud.async.AsyncJobVO;
 import com.cloud.async.BaseAsyncJobExecutor;
+import com.cloud.capacity.CapacityManager;
 import com.cloud.configuration.Config;
 import com.cloud.configuration.ConfigurationManager;
 import com.cloud.configuration.Resource.ResourceType;
@@ -326,9 +327,11 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
     @Inject
     protected UserVmDetailsDao _vmDetailsDao;
     @Inject
+    protected HypervisorCapabilitiesDao _hypervisorCapabilitiesDao;
+    @Inject
     protected SecurityGroupDao _securityGroupDao;
     @Inject 
-    protected HypervisorCapabilitiesDao _hypervisorCapabilitiesDao;
+    protected CapacityManager _capacityMgr;;
     @Inject 
     protected VMInstanceDao _vmInstanceDao;
     @Inject
@@ -3268,15 +3271,12 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
         DeployDestination dest = new DeployDestination(dcVO, pod, cluster, destinationHost);
 
         //check max guest vm limit for the destinationHost
-        HypervisorType hypervisorType = destinationHost.getHypervisorType();
-        String hypervisorVersion = destinationHost.getHypervisorVersion();
-        Long maxGuestLimit = _hypervisorCapabilitiesDao.getMaxGuestsLimit(hypervisorType, hypervisorVersion);        
-        Long vmCount = _vmInstanceDao.countRunningByHostId(destinationHost.getId());
-        if (vmCount.longValue() == maxGuestLimit.longValue()){
+        HostVO destinationHostVO = _hostDao.findById(destinationHost.getId());
+        if(_capacityMgr.checkIfHostReachMaxGuestLimit(destinationHostVO)){
             if (s_logger.isDebugEnabled()) {
-                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");
+                s_logger.debug("Host name: " + destinationHost.getName() + ", hostId: "+ destinationHost.getId() +" already has max Running VMs(count includes system VMs), cannot migrate to this host");
             }
-            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");
+            throw new VirtualMachineMigrationException("Destination host, hostId: "+ destinationHost.getId() +" already has max Running VMs(count includes system VMs), cannot migrate to this host");
         }
 
         VMInstanceVO migratedVm = _itMgr.migrate(vm, srcHostId, dest);