You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ni...@apache.org on 2013/12/05 23:31:46 UTC

git commit: updated refs/heads/master to 98ee087

Updated Branches:
  refs/heads/master ee607646c -> 98ee087d3


CLOUDSTACK-4880:
check for host cpu capability while dynamic scaling a vm on the same host


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

Branch: refs/heads/master
Commit: 98ee087d310f8f84cb579730209bf212c8503808
Parents: ee607646
Author: Nitin Mehta <ni...@citrix.com>
Authored: Thu Dec 5 14:31:27 2013 -0800
Committer: Nitin Mehta <ni...@citrix.com>
Committed: Thu Dec 5 14:31:27 2013 -0800

----------------------------------------------------------------------
 .../src/com/cloud/capacity/CapacityManager.java |  9 ++++++++
 .../com/cloud/capacity/CapacityManagerImpl.java | 24 ++++++++++++++++++--
 server/src/com/cloud/vm/UserVmManagerImpl.java  |  9 ++++----
 3 files changed, 35 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/98ee087d/engine/components-api/src/com/cloud/capacity/CapacityManager.java
----------------------------------------------------------------------
diff --git a/engine/components-api/src/com/cloud/capacity/CapacityManager.java b/engine/components-api/src/com/cloud/capacity/CapacityManager.java
index 4332ede..13624e6 100755
--- a/engine/components-api/src/com/cloud/capacity/CapacityManager.java
+++ b/engine/components-api/src/com/cloud/capacity/CapacityManager.java
@@ -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);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/98ee087d/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 8ed2433..2358f92 100755
--- a/server/src/com/cloud/capacity/CapacityManagerImpl.java
+++ b/server/src/com/cloud/capacity/CapacityManagerImpl.java
@@ -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()) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/98ee087d/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 4e78ba1..1752c22 100755
--- a/server/src/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/com/cloud/vm/UserVmManagerImpl.java
@@ -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());
                     }