incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mc...@apache.org
Subject [12/50] [abbrv] Cloudstack-711: Cpu and Ram Overcommit Ratio.
Date Mon, 25 Feb 2013 20:46:46 GMT
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/23e54bb0/server/src/com/cloud/capacity/dao/CapacityDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/capacity/dao/CapacityDaoImpl.java b/server/src/com/cloud/capacity/dao/CapacityDaoImpl.java
index 3582614..3aef29b 100755
--- a/server/src/com/cloud/capacity/dao/CapacityDaoImpl.java
+++ b/server/src/com/cloud/capacity/dao/CapacityDaoImpl.java
@@ -55,10 +55,9 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
     private static final String ADD_ALLOCATED_SQL = "UPDATE `cloud`.`op_host_capacity` SET used_capacity = used_capacity + ? WHERE host_id = ? AND capacity_type = ?";
     private static final String SUBTRACT_ALLOCATED_SQL = "UPDATE `cloud`.`op_host_capacity` SET used_capacity = used_capacity - ? WHERE host_id = ? AND capacity_type = ?";
 
-    private static final String LIST_CLUSTERSINZONE_BY_HOST_CAPACITIES_PART1 = "SELECT DISTINCT capacity.cluster_id  FROM `cloud`.`op_host_capacity` capacity INNER JOIN `cloud`.`cluster` cluster on (cluster.id = capacity.cluster_id AND cluster.removed is NULL) WHERE ";
-    private static final String LIST_CLUSTERSINZONE_BY_HOST_CAPACITIES_PART2 = " AND capacity_type = ? AND ((total_capacity * ?) - used_capacity + reserved_capacity) >= ? " +
-            "AND cluster_id IN (SELECT distinct cluster_id  FROM `cloud`.`op_host_capacity` WHERE ";
-    private static final String LIST_CLUSTERSINZONE_BY_HOST_CAPACITIES_PART3 = " AND capacity_type = ? AND ((total_capacity * ?) - used_capacity + reserved_capacity) >= ?) ";
+    private static final String LIST_CLUSTERSINZONE_BY_HOST_CAPACITIES_PART1 = "SELECT DISTINCT capacity.cluster_id  FROM `cloud`.`op_host_capacity` capacity INNER JOIN `cloud`.`cluster` cluster on (cluster.id = capacity.cluster_id AND cluster.removed is NULL)   INNER JOIN `cloud`.`cluster_details` cluster_details ON (cluster.id = cluster_details.cluster_id ) WHERE ";
+    private static final String LIST_CLUSTERSINZONE_BY_HOST_CAPACITIES_PART2 = " AND capacity_type = ? AND cluster_details.name= ? AND ((total_capacity * cluster_details.value ) - used_capacity + reserved_capacity) >= ? AND capacity.cluster_id IN (SELECT distinct capacity.cluster_id  FROM `cloud`.`op_host_capacity` capacity INNER JOIN  `cloud`.`cluster_details` cluster_details ON (capacity.cluster_id = cluster_details.cluster_id ) WHERE ";
+    private static final String LIST_CLUSTERSINZONE_BY_HOST_CAPACITIES_PART3 = " AND capacity_type = ? AND cluster_details.name= ? AND ((total_capacity * cluster_details.value) - used_capacity + reserved_capacity) >= ?) ";
 
     private final SearchBuilder<CapacityVO> _hostIdTypeSearch;
     private final SearchBuilder<CapacityVO> _hostOrPoolIdSearch;
@@ -66,47 +65,54 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
     @Inject protected StoragePoolDao _storagePoolDao;
 
 
-    private static final String LIST_HOSTS_IN_CLUSTER_WITH_ENOUGH_CAPACITY = "SELECT a.host_id FROM (host JOIN op_host_capacity a ON host.id = a.host_id AND host.cluster_id = ? AND host.type = ? " +
-            "AND (a.total_capacity * ? - a.used_capacity) >= ? and a.capacity_type = 1) " +
-            "JOIN op_host_capacity b ON a.host_id = b.host_id AND b.total_capacity - b.used_capacity >= ? AND b.capacity_type = 0";
+    private static final String LIST_HOSTS_IN_CLUSTER_WITH_ENOUGH_CAPACITY = " SELECT  host_capacity.host_id FROM (`cloud`.`host` JOIN `cloud`.`op_host_capacity` host_capacity ON (host.id = host_capacity.host_id AND host.cluster_id = ?) JOIN `cloud`.`cluster_details` cluster_details ON (host_capacity.cluster_id = cluster_details.cluster_id) AND  host.type = ? AND cluster_details.name='cpuOvercommitRatio' AND ((host_capacity.total_capacity *cluster_details.value ) - host_capacity.used_capacity) >= ? and host_capacity.capacity_type = '1' " +
+               " AND  host_capacity.host_id IN (SELECT capacity.host_id FROM `cloud`.`op_host_capacity` capacity JOIN `cloud`.`cluster_details` cluster_details ON (capacity.cluster_id= cluster_details.cluster_id) where capacity_type='0' AND cluster_details.name='memoryOvercommitRatio' AND ((total_capacity* cluster_details.value) - used_capacity ) >= ?)) ";
 
-    private static final String ORDER_CLUSTERS_BY_AGGREGATE_CAPACITY_PART1 = "SELECT cluster_id, SUM(used_capacity+reserved_capacity)/SUM(total_capacity * ?) FROM `cloud`.`op_host_capacity` WHERE " ;
-    private static final String ORDER_CLUSTERS_BY_AGGREGATE_CAPACITY_PART2 = " AND capacity_type = ? GROUP BY cluster_id ORDER BY SUM(used_capacity+reserved_capacity)/SUM(total_capacity * ?) ASC";
+    private static final String ORDER_CLUSTERS_BY_AGGREGATE_CAPACITY_PART1= "SELECT capacity.cluster_id, SUM(used_capacity+reserved_capacity)/SUM(total_capacity ) FROM `cloud`.`op_host_capacity` capacity WHERE ";
 
-    private static final String LIST_PODSINZONE_BY_HOST_CAPACITIES = "SELECT DISTINCT capacity.pod_id  FROM `cloud`.`op_host_capacity` capacity INNER JOIN `cloud`.`host_pod_ref` pod " +
-            " ON (pod.id = capacity.pod_id AND pod.removed is NULL) WHERE " +
-            " capacity.data_center_id = ? AND capacity_type = ? AND ((total_capacity * ?) - used_capacity + reserved_capacity) >= ? " +
-            " AND pod_id IN (SELECT distinct pod_id  FROM `cloud`.`op_host_capacity` WHERE " +
-            " capacity.data_center_id = ? AND capacity_type = ? AND ((total_capacity * ?) - used_capacity + reserved_capacity) >= ?) ";
+    private static final String ORDER_CLUSTERS_BY_AGGREGATE_CAPACITY_PART2= " AND capacity_type = ?  AND cluster_details.name =? GROUP BY capacity.cluster_id ORDER BY SUM(used_capacity+reserved_capacity)/SUM(total_capacity * cluster_details.value) ASC";
 
-    private static final String ORDER_PODS_BY_AGGREGATE_CAPACITY = "SELECT pod_id, SUM(used_capacity+reserved_capacity)/SUM(total_capacity * ?) FROM `cloud`.`op_host_capacity` WHERE data_center_id = ? " +
-            " AND capacity_type = ? GROUP BY pod_id ORDER BY SUM(used_capacity+reserved_capacity)/SUM(total_capacity * ?) ASC";
+    private static final String ORDER_CLUSTERS_BY_AGGREGATE_OVERCOMMIT_CAPACITY_PART1= "SELECT capacity.cluster_id, SUM(used_capacity+reserved_capacity)/SUM(total_capacity * cluster_details.value) FROM `cloud`.`op_host_capacity` capacity INNER JOIN `cloud`.`cluster_details` cluster_details ON (capacity.cluster_id = cluster_details.cluster_id) WHERE ";
 
-    private static final String LIST_CAPACITY_BY_RESOURCE_STATE = "SELECT capacity.data_center_id, sum(capacity.used_capacity), sum(capacity.reserved_quantity), sum(capacity.total_capacity), capacity_capacity_type "+
-            "FROM `cloud`.`op_host_capacity` capacity INNER JOIN `cloud`.`data_center` dc ON (dc.id = capacity.data_center_id AND dc.removed is NULL)"+
-            "FROM `cloud`.`op_host_capacity` capacity INNER JOIN `cloud`.`host_pod_ref` pod ON (pod.id = capacity.pod_id AND pod.removed is NULL)"+
-            "FROM `cloud`.`op_host_capacity` capacity INNER JOIN `cloud`.`cluster` cluster ON (cluster.id = capacity.cluster_id AND cluster.removed is NULL)"+
-            "FROM `cloud`.`op_host_capacity` capacity INNER JOIN `cloud`.`host` host ON (host.id = capacity.host_id AND host.removed is NULL)"+
-            "WHERE dc.allocation_state = ? AND pod.allocation_state = ? AND cluster.allocation_state = ? AND host.resource_state = ? AND capacity_type not in (3,4) ";
+    private static final String ORDER_CLUSTERS_BY_AGGREGATE_OVERCOMMIT_CAPACITY_PART2= " AND capacity_type = ?  AND cluster_details.name =? GROUP BY capacity.cluster_id ORDER BY SUM(used_capacity+reserved_capacity)/SUM(total_capacity * cluster_details.value) ASC";
+
+    private static final String LIST_PODSINZONE_BY_HOST_CAPACITY_TYPE = "SELECT DISTINCT capacity.pod_id  FROM `cloud`.`op_host_capacity` capacity INNER JOIN `cloud`.`host_pod_ref` pod " +
+                                                          " ON (pod.id = capacity.pod_id AND pod.removed is NULL) INNER JOIN `cloud`.`cluster_details` cluster ON (capacity.cluster_id = cluster.cluster_id ) WHERE capacity.data_center_id = ? AND capacity_type = ? AND cluster_details.name= ? ((total_capacity * cluster.value ) - used_capacity + reserved_capacity) >= ? ";
+
+    private static final String ORDER_PODS_BY_AGGREGATE_CAPACITY = " SELECT capacity.pod_id, SUM(used_capacity+reserved_capacity)/SUM(total_capacity) FROM `cloud`.`op_host_capacity` capacity WHERE data_center_id= ? AND capacity_type = ? GROUP BY capacity.pod_id ORDER BY SUM(used_capacity+reserved_capacity)/SUM(total_capacity) ASC ";
+
+    private static final String ORDER_PODS_BY_AGGREGATE_OVERCOMMIT_CAPACITY ="SELECT capacity.pod_id, SUM(used_capacity+reserved_capacity)/SUM(total_capacity * cluster_details.value) FROM `cloud`.`op_host_capacity` capacity INNER JOIN `cloud`.`cluster_details` cluster_details ON (capacity.cluster_id = cluster_details.cluster_id) WHERE data_center_id=? AND capacity_type = ?  AND cluster_details.name = ? GROUP BY capacity.pod_id ORDER BY SUM(used_capacity+reserved_capacity)/SUM(total_capacity * cluster_details.value) ASC";
 
+    private static final String LIST_CAPACITY_BY_RESOURCE_STATE = "SELECT capacity.data_center_id, sum(capacity.used_capacity), sum(capacity.reserved_quantity), sum(capacity.total_capacity), capacity_capacity_type "+
+                                                                  "FROM `cloud`.`op_host_capacity` capacity INNER JOIN `cloud`.`data_center` dc ON (dc.id = capacity.data_center_id AND dc.removed is NULL)"+
+                                                                  "FROM `cloud`.`op_host_capacity` capacity INNER JOIN `cloud`.`host_pod_ref` pod ON (pod.id = capacity.pod_id AND pod.removed is NULL)"+
+                                                                  "FROM `cloud`.`op_host_capacity` capacity INNER JOIN `cloud`.`cluster` cluster ON (cluster.id = capacity.cluster_id AND cluster.removed is NULL)"+
+                                                                  "FROM `cloud`.`op_host_capacity` capacity INNER JOIN `cloud`.`host` host ON (host.id = capacity.host_id AND host.removed is NULL)"+
+                                                                  "WHERE dc.allocation_state = ? AND pod.allocation_state = ? AND cluster.allocation_state = ? AND host.resource_state = ? AND capacity_type not in (3,4) ";
+    
     private static final String LIST_CAPACITY_GROUP_BY_ZONE_TYPE_PART1 = "SELECT (sum(capacity.used_capacity) + sum(capacity.reserved_capacity)), (case capacity_type when 1 then (sum(total_capacity) * (select value from `cloud`.`configuration` where name like 'cpu.overprovisioning.factor')) else sum(total_capacity) end), " +
-            "((sum(capacity.used_capacity) + sum(capacity.reserved_capacity)) / (case capacity_type when 1 then (sum(total_capacity) * (select value from `cloud`.`configuration` where name like 'cpu.overprovisioning.factor')) else sum(total_capacity) end)) percent,"+
-            " capacity.capacity_type, capacity.data_center_id "+
-            "FROM `cloud`.`op_host_capacity` capacity "+
-            "WHERE  total_capacity > 0 AND data_center_id is not null AND capacity_state='Enabled'";
+                                                                         "((sum(capacity.used_capacity) + sum(capacity.reserved_capacity)) / (case capacity_type when 1 then (sum(total_capacity) * (select value from `cloud`.`configuration` where name like 'cpu.overprovisioning.factor')) else sum(total_capacity) end)) percent,"+
+                                                                         " capacity.capacity_type, capacity.data_center_id "+
+                                                                         "FROM `cloud`.`op_host_capacity` capacity "+
+                                                                         "WHERE  total_capacity > 0 AND data_center_id is not null AND capacity_state='Enabled'";
     private static final String LIST_CAPACITY_GROUP_BY_ZONE_TYPE_PART2 = " GROUP BY data_center_id, capacity_type order by percent desc limit ";
-    private static final String LIST_CAPACITY_GROUP_BY_POD_TYPE_PART1 = "SELECT (sum(capacity.used_capacity) + sum(capacity.reserved_capacity)), (case capacity_type when 1 then (sum(total_capacity) * (select value from `cloud`.`configuration` where name like 'cpu.overprovisioning.factor')) else sum(total_capacity) end), " +
-            "((sum(capacity.used_capacity) + sum(capacity.reserved_capacity)) / (case capacity_type when 1 then (sum(total_capacity) * (select value from `cloud`.`configuration` where name like 'cpu.overprovisioning.factor')) else sum(total_capacity) end)) percent,"+
-            " capacity.capacity_type, capacity.data_center_id, pod_id "+
-            "FROM `cloud`.`op_host_capacity` capacity "+
-            "WHERE  total_capacity > 0 AND pod_id is not null AND capacity_state='Enabled'";
+    private static final String LIST_CAPACITY_GROUP_BY_POD_TYPE_PART1 =  "SELECT (sum(capacity.used_capacity) + sum(capacity.reserved_capacity))," +
+            " (case capacity_type when 1 then (sum(total_capacity) * (select value from `cloud`.`cluster_details` where cluster_details.name= 'cpuOvercommitRatio' AND cluster_details.cluster_id=capacity.cluster_id)) " +
+            "when '0' then (sum(total_capacity) * (select value from `cloud`.`cluster_details` where cluster_details.name= 'memoryOvercommitRatio' AND cluster_details.cluster_id=capacity.cluster_id))else sum(total_capacity) end)," +
+            "((sum(capacity.used_capacity) + sum(capacity.reserved_capacity)) / ( case capacity_type when 1 then (sum(total_capacity) * (select value from `cloud`.`cluster_details` where cluster_details.name= 'cpuOvercommitRatio' AND cluster_details.cluster_id=capacity.cluster_id)) " +
+            "when '0' then (sum(total_capacity) * (select value from `cloud`.`cluster_details` where cluster_details.name= 'memoryOvercommitRatio' AND cluster_details.cluster_id=capacity.cluster_id))else sum(total_capacity) end)) percent," +
+            "capacity.capacity_type, capacity.data_center_id, pod_id FROM `cloud`.`op_host_capacity` capacity WHERE  total_capacity > 0 AND data_center_id is not null AND capacity_state='Enabled' ";
+
     private static final String LIST_CAPACITY_GROUP_BY_POD_TYPE_PART2 = " GROUP BY pod_id, capacity_type order by percent desc limit ";
 
-    private static final String LIST_CAPACITY_GROUP_BY_CLUSTER_TYPE_PART1 = "SELECT (sum(capacity.used_capacity) + sum(capacity.reserved_capacity)), (case capacity_type when 1 then (sum(total_capacity) * (select value from `cloud`.`configuration` where name like 'cpu.overprovisioning.factor')) else sum(total_capacity) end), " +
-            "((sum(capacity.used_capacity) + sum(capacity.reserved_capacity)) / (case capacity_type when 1 then (sum(total_capacity) * (select value from `cloud`.`configuration` where name like 'cpu.overprovisioning.factor')) else sum(total_capacity) end)) percent,"+
-            "capacity.capacity_type, capacity.data_center_id, pod_id, cluster_id "+
-            "FROM `cloud`.`op_host_capacity` capacity "+
-            "WHERE  total_capacity > 0 AND cluster_id is not null AND capacity_state='Enabled'";
+    private static final String LIST_CAPACITY_GROUP_BY_CLUSTER_TYPE_PART1 = "SELECT (sum(capacity.used_capacity) + sum(capacity.reserved_capacity))," +
+            " (case capacity_type when 1 then (sum(total_capacity) * (select value from `cloud`.`cluster_details` where cluster_details.name= 'cpuOvercommitRatio' AND cluster_details.cluster_id=capacity.cluster_id)) " +
+            "when '0' then (sum(total_capacity) * (select value from `cloud`.`cluster_details` where cluster_details.name= 'memoryOvercommitRatio' AND cluster_details.cluster_id=capacity.cluster_id))else sum(total_capacity) end)," +
+            "((sum(capacity.used_capacity) + sum(capacity.reserved_capacity)) / ( case capacity_type when 1 then (sum(total_capacity) * (select value from `cloud`.`cluster_details` where cluster_details.name= 'cpuOvercommitRatio' AND cluster_details.cluster_id=capacity.cluster_id)) " +
+            "when '0' then (sum(total_capacity) * (select value from `cloud`.`cluster_details` where cluster_details.name= 'memoryOvercommitRatio' AND cluster_details.cluster_id=capacity.cluster_id))else sum(total_capacity) end)) percent," +
+            "capacity.capacity_type, capacity.data_center_id, pod_id, cluster_id FROM `cloud`.`op_host_capacity` capacity WHERE  total_capacity > 0 AND data_center_id is not null AND capacity_state='Enabled' ";
+
+
     private static final String LIST_CAPACITY_GROUP_BY_CLUSTER_TYPE_PART2 = " GROUP BY cluster_id, capacity_type order by percent desc limit ";
     private static final String UPDATE_CAPACITY_STATE = "UPDATE `cloud`.`op_host_capacity` SET capacity_state = ? WHERE ";
     private static final String LIST_CLUSTERS_CROSSING_THRESHOLD = "SELECT cluster_id " +
@@ -138,34 +144,34 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
 
         _allFieldsSearch.done();
     }
-
+          
     @Override
-    public  List<Long> listClustersCrossingThreshold(short capacityType, Long zoneId, Float disableThreshold, long compute_requested, Float overProvFactor){
-
-        Transaction txn = Transaction.currentTxn();
-        PreparedStatement pstmt = null;
-        List<Long> result = new ArrayList<Long>();         
-        StringBuilder sql = new StringBuilder(LIST_CLUSTERS_CROSSING_THRESHOLD);
-
-
-        try {
-            pstmt = txn.prepareAutoCloseStatement(sql.toString());
-            pstmt.setLong(1, compute_requested);
-            pstmt.setLong(2, zoneId);
-            pstmt.setShort(3, capacityType);                          
-            pstmt.setFloat(4, disableThreshold*overProvFactor);             
-
-            ResultSet rs = pstmt.executeQuery();
-            while (rs.next()) {
-                result.add(rs.getLong(1));
-            }
-            return result;
-        } catch (SQLException e) {
-            throw new CloudRuntimeException("DB Exception on: " + sql, e);
-        } catch (Throwable e) {
-            throw new CloudRuntimeException("Caught: " + sql, e);
-        } 
-    }
+    public  List<Long> listClustersCrossingThreshold(short capacityType, Long zoneId, Float disableThreshold, long compute_requested){
+
+         Transaction txn = Transaction.currentTxn();
+         PreparedStatement pstmt = null;
+         List<Long> result = new ArrayList<Long>();         
+         StringBuilder sql = new StringBuilder(LIST_CLUSTERS_CROSSING_THRESHOLD);
+         
+ 
+         try {
+             pstmt = txn.prepareAutoCloseStatement(sql.toString());
+             pstmt.setLong(1,compute_requested);
+             pstmt.setShort(2,capacityType);
+             pstmt.setFloat(3,disableThreshold);
+             pstmt.setLong(4,zoneId);
+
+             ResultSet rs = pstmt.executeQuery();
+             while (rs.next()) {
+                 result.add(rs.getLong(1));
+             }
+             return result;
+         } catch (SQLException e) {
+             throw new CloudRuntimeException("DB Exception on: " + sql, e);
+         } catch (Throwable e) {
+        	 throw new CloudRuntimeException("Caught: " + sql, e);
+         } 
+     }
 
     /*public static String preparePlaceHolders(int length) {
         StringBuilder builder = new StringBuilder();
@@ -242,6 +248,8 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
         PreparedStatement pstmt = null;
         List<SummedCapacity> result = new ArrayList<SummedCapacity>();
 
+        List<Long> resourceIdList = new ArrayList<Long>();
+
         switch(level){
         case 1: // List all the capacities grouped by zone, capacity Type
             finalQuery.append(LIST_CAPACITY_GROUP_BY_ZONE_TYPE_PART1);
@@ -257,17 +265,21 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
         }
 
         if (zoneId != null){
-            finalQuery.append(" AND data_center_id="+zoneId);
+            finalQuery.append(" AND data_center_id = ?" );
+            resourceIdList.add(zoneId);
         }
         if (podId != null){
-            finalQuery.append(" AND pod_id="+podId);
+            finalQuery.append(" AND pod_id = ?" );
+            resourceIdList.add(podId);
         }
         if (clusterId != null){
-            finalQuery.append(" AND cluster_id="+clusterId);
+            finalQuery.append(" AND cluster_id = ?" );
+            resourceIdList.add(clusterId );
         }
         if (capacityType != null){
-            finalQuery.append(" AND capacity_type="+capacityType);   
-        }                
+            finalQuery.append(" AND capacity_type = ?");
+            resourceIdList.add(capacityType.longValue() );
+        }
 
         switch(level){
         case 1: // List all the capacities grouped by zone, capacity Type
@@ -283,12 +295,16 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
             break;
         }
 
-        finalQuery.append(limit.toString());
-
+        finalQuery.append("?");
+        resourceIdList.add((long) limit);
+        
         try {
-            pstmt = txn.prepareAutoCloseStatement(finalQuery.toString());        
+            pstmt = txn.prepareAutoCloseStatement(finalQuery.toString());
+            for (int i = 0; i < resourceIdList.size(); i++){
+                pstmt.setLong(1+i, resourceIdList.get(i));
+            }
             ResultSet rs = pstmt.executeQuery();
-            while (rs.next()) {                
+            while (rs.next()) {
                 SummedCapacity summedCapacity = new SummedCapacity( rs.getLong(1), rs.getLong(2), rs.getFloat(3),
                         (short)rs.getLong(4), rs.getLong(5),
                         level != 1 ? rs.getLong(6): null,
@@ -390,8 +406,8 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
     }  
 
     @Override
-    public List<Long> listClustersInZoneOrPodByHostCapacities(long id, int requiredCpu, long requiredRam, short capacityTypeForOrdering, boolean isZone, float cpuOverprovisioningFactor){
-        Transaction txn = Transaction.currentTxn();
+    public List<Long> listClustersInZoneOrPodByHostCapacities(long id, int requiredCpu, long requiredRam, short capacityTypeForOrdering, boolean isZone){
+    Transaction txn = Transaction.currentTxn();
         PreparedStatement pstmt = null;
         List<Long> result = new ArrayList<Long>();
 
@@ -414,11 +430,11 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
             pstmt = txn.prepareAutoCloseStatement(sql.toString());
             pstmt.setLong(1, id);
             pstmt.setShort(2, CapacityVO.CAPACITY_TYPE_CPU);
-            pstmt.setFloat(3, cpuOverprovisioningFactor);
+            pstmt.setString(3,"cpuOvercommitRatio");
             pstmt.setLong(4, requiredCpu);
             pstmt.setLong(5, id);
             pstmt.setShort(6, CapacityVO.CAPACITY_TYPE_MEMORY);
-            pstmt.setFloat(7, 1);
+            pstmt.setString(7,"memoryOvercommitRatio");
             pstmt.setLong(8, requiredRam);
 
             ResultSet rs = pstmt.executeQuery();
@@ -435,8 +451,8 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
 
 
     @Override
-    public List<Long> listHostsWithEnoughCapacity(int requiredCpu, long requiredRam, Long clusterId, String hostType, float cpuOverprovisioningFactor){
-        Transaction txn = Transaction.currentTxn();
+    public List<Long> listHostsWithEnoughCapacity(int requiredCpu, long requiredRam, Long clusterId, String hostType){
+    Transaction txn = Transaction.currentTxn();
         PreparedStatement pstmt = null;
         List<Long> result = new ArrayList<Long>();
 
@@ -445,9 +461,8 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
             pstmt = txn.prepareAutoCloseStatement(sql.toString());
             pstmt.setLong(1, clusterId);
             pstmt.setString(2, hostType);
-            pstmt.setFloat(3, cpuOverprovisioningFactor);
-            pstmt.setLong(4, requiredCpu);
-            pstmt.setLong(5, requiredRam);
+            pstmt.setLong(3, requiredCpu);
+            pstmt.setLong(4, requiredRam);
 
             ResultSet rs = pstmt.executeQuery();
             while (rs.next()) {
@@ -629,31 +644,44 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
     }
 
     @Override
-    public Pair<List<Long>, Map<Long, Double>> orderClustersByAggregateCapacity(long id, short capacityTypeForOrdering, boolean isZone, float cpuOverprovisioningFactor){
+    public Pair<List<Long>, Map<Long, Double>> orderClustersByAggregateCapacity(long id, short capacityTypeForOrdering, boolean isZone){
         Transaction txn = Transaction.currentTxn();
         PreparedStatement pstmt = null;
         List<Long> result = new ArrayList<Long>();
         Map<Long, Double> clusterCapacityMap = new HashMap<Long, Double>();
+        StringBuilder sql = new StringBuilder();
+        if (capacityTypeForOrdering != Capacity.CAPACITY_TYPE_CPU && capacityTypeForOrdering != Capacity.CAPACITY_TYPE_MEMORY)  {
+             sql.append(ORDER_CLUSTERS_BY_AGGREGATE_CAPACITY_PART1);
+        }
+        else {
+             sql.append(ORDER_CLUSTERS_BY_AGGREGATE_OVERCOMMIT_CAPACITY_PART1);
+        }
 
-        StringBuilder sql = new StringBuilder(ORDER_CLUSTERS_BY_AGGREGATE_CAPACITY_PART1);
 
         if(isZone){
-            sql.append("data_center_id = ?");
+            sql.append(" data_center_id = ?");
         }else{
-            sql.append("pod_id = ?");
+            sql.append(" pod_id = ?");
+        }
+        if (capacityTypeForOrdering != Capacity.CAPACITY_TYPE_CPU && capacityTypeForOrdering != Capacity.CAPACITY_TYPE_MEMORY){
+           sql.append(ORDER_CLUSTERS_BY_AGGREGATE_CAPACITY_PART2);
+        }
+        else {
+           sql.append(ORDER_CLUSTERS_BY_AGGREGATE_OVERCOMMIT_CAPACITY_PART2);
         }
-        sql.append(ORDER_CLUSTERS_BY_AGGREGATE_CAPACITY_PART2);
+
         try {
             pstmt = txn.prepareAutoCloseStatement(sql.toString());
-            if(capacityTypeForOrdering == CapacityVO.CAPACITY_TYPE_CPU){
-                pstmt.setFloat(1, cpuOverprovisioningFactor);
-                pstmt.setFloat(4, cpuOverprovisioningFactor);
-            }else{
-                pstmt.setFloat(1, 1);
-                pstmt.setFloat(4, 1);
+            pstmt.setLong(1, id);
+            pstmt.setShort(2,capacityTypeForOrdering);
+
+            if (capacityTypeForOrdering == Capacity.CAPACITY_TYPE_CPU){
+                pstmt.setString(3,"cpuOvercommitRatio");
             }
-            pstmt.setLong(2, id);
-            pstmt.setShort(3, capacityTypeForOrdering);
+            else if (capacityTypeForOrdering == Capacity.CAPACITY_TYPE_MEMORY){
+                pstmt.setString(3,"memoryOvercommitRatio");
+            }
+
             ResultSet rs = pstmt.executeQuery();
             while (rs.next()) {
                 Long clusterId = rs.getLong(1);
@@ -669,22 +697,25 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
     }
 
     @Override
-    public List<Long> listPodsByHostCapacities(long zoneId, int requiredCpu, long requiredRam, short capacityType, float cpuOverprovisioningFactor) {
+    public List<Long> listPodsByHostCapacities(long zoneId, int requiredCpu, long requiredRam, short capacityType) {
         Transaction txn = Transaction.currentTxn();
         PreparedStatement pstmt = null;
         List<Long> result = new ArrayList<Long>();
 
-        StringBuilder sql = new StringBuilder(LIST_PODSINZONE_BY_HOST_CAPACITIES);
+        StringBuilder sql = new StringBuilder(LIST_PODSINZONE_BY_HOST_CAPACITY_TYPE);
+                      sql.append("AND capacity.pod_id IN (");
+                      sql.append(LIST_PODSINZONE_BY_HOST_CAPACITY_TYPE);
+                      sql.append(")");
 
         try {
             pstmt = txn.prepareAutoCloseStatement(sql.toString());
             pstmt.setLong(1, zoneId);
             pstmt.setShort(2, CapacityVO.CAPACITY_TYPE_CPU);
-            pstmt.setFloat(3, cpuOverprovisioningFactor);
+            pstmt.setString(3, "cpuOvercommitRatio");
             pstmt.setLong(4, requiredCpu);
             pstmt.setLong(5, zoneId);
             pstmt.setShort(6, CapacityVO.CAPACITY_TYPE_MEMORY);
-            pstmt.setFloat(7, 1);
+            pstmt.setString(7,"memoryOvercommitRatio" );
             pstmt.setLong(8, requiredRam);
 
             ResultSet rs = pstmt.executeQuery();
@@ -700,26 +731,22 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
     }
 
     @Override
-    public Pair<List<Long>, Map<Long, Double>> orderPodsByAggregateCapacity(long zoneId, short capacityTypeForOrdering, float cpuOverprovisioningFactor) {
+    public Pair<List<Long>, Map<Long, Double>> orderPodsByAggregateCapacity(long zoneId, short capacityTypeForOrdering) {
         Transaction txn = Transaction.currentTxn();
         PreparedStatement pstmt = null;
         List<Long> result = new ArrayList<Long>();
         Map<Long, Double> podCapacityMap = new HashMap<Long, Double>();
-
+        
         StringBuilder sql = new StringBuilder(ORDER_PODS_BY_AGGREGATE_CAPACITY);
         try {
             pstmt = txn.prepareAutoCloseStatement(sql.toString());
             pstmt.setLong(2, zoneId);
             pstmt.setShort(3, capacityTypeForOrdering);
-
+            
             if(capacityTypeForOrdering == CapacityVO.CAPACITY_TYPE_CPU){
-                pstmt.setFloat(1, cpuOverprovisioningFactor);
-                pstmt.setFloat(4, cpuOverprovisioningFactor);
-            }else{
-                pstmt.setFloat(1, 1);
-                pstmt.setFloat(4, 1);
+                pstmt.setString(3, "cpuOvercommitRatio");
             }
-
+            
             ResultSet rs = pstmt.executeQuery();
             while (rs.next()) {
                 Long podId = rs.getLong(1);
@@ -737,7 +764,7 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
     @Override
     public void updateCapacityState(Long dcId, Long podId, Long clusterId, Long hostId, String capacityState) {
         Transaction txn = Transaction.currentTxn();
-        StringBuilder sql = new StringBuilder(UPDATE_CAPACITY_STATE); 
+        StringBuilder sql = new StringBuilder(UPDATE_CAPACITY_STATE);
         List<Long> resourceIdList = new ArrayList<Long>();
 
         if (dcId != null){

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/23e54bb0/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 b452da0..4933467 100755
--- a/server/src/com/cloud/deploy/FirstFitPlanner.java
+++ b/server/src/com/cloud/deploy/FirstFitPlanner.java
@@ -28,6 +28,7 @@ import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
+import com.cloud.dc.*;
 import org.apache.log4j.Logger;
 
 import com.cloud.agent.manager.allocator.HostAllocator;
@@ -38,11 +39,6 @@ import com.cloud.capacity.CapacityVO;
 import com.cloud.capacity.dao.CapacityDao;
 import com.cloud.configuration.Config;
 import com.cloud.configuration.dao.ConfigurationDao;
-import com.cloud.dc.ClusterVO;
-import com.cloud.dc.DataCenter;
-import com.cloud.dc.DataCenterVO;
-import com.cloud.dc.HostPodVO;
-import com.cloud.dc.Pod;
 import com.cloud.dc.dao.ClusterDao;
 import com.cloud.dc.dao.DataCenterDao;
 import com.cloud.dc.dao.HostPodDao;
@@ -100,6 +96,7 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner {
     @Inject protected AccountManager _accountMgr;
     @Inject protected StorageManager _storageMgr;
     @Inject DataStoreManager dataStoreMgr;
+    @Inject protected ClusterDetailsDao _clusterDetailsDao;
 
     //@com.cloud.utils.component.Inject(adapter=StoragePoolAllocator.class)
     @Inject protected List<StoragePoolAllocator> _storagePoolAllocators;
@@ -128,9 +125,6 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner {
         int cpu_requested = offering.getCpu() * offering.getSpeed();
         long ram_requested = offering.getRamSize() * 1024L * 1024L;
 
-        String opFactor = _configDao.getValue(Config.CPUOverprovisioningFactor.key());
-        float cpuOverprovisioningFactor = NumbersUtil.parseFloat(opFactor, 1);
-
 
         if (s_logger.isDebugEnabled()) {
             s_logger.debug("DeploymentPlanner allocation algorithm: "+_allocationAlgorithm);
@@ -199,7 +193,12 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner {
                 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)){
+                    long cluster_id = host.getClusterId();
+                    ClusterDetailsVO cluster_detail_cpu =  _clusterDetailsDao.findDetail(cluster_id,"cpuOvercommitRatio");
+                    ClusterDetailsVO cluster_detail_ram =  _clusterDetailsDao.findDetail(cluster_id,"memoryOvercommitRatio");
+                    Float cpuOvercommitRatio = Float.parseFloat(cluster_detail_cpu.getValue());
+                    Float memoryOvercommitRatio = Float.parseFloat(cluster_detail_ram.getValue());
+                    if(_capacityMgr.checkIfHostHasCapacity(host.getId(), cpu_requested, ram_requested, true, cpuOvercommitRatio, memoryOvercommitRatio, true)){
                         s_logger.debug("The last host of this VM is UP and has enough capacity");
                         s_logger.debug("Now checking for suitable pools under zone: "+host.getDataCenterId() +", pod: "+ host.getPodId()+", cluster: "+ host.getClusterId());
                         //search for storage under the zone, pod, cluster of the last host.
@@ -287,12 +286,9 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner {
         ServiceOffering offering = vmProfile.getServiceOffering();
         int requiredCpu = offering.getCpu() * offering.getSpeed();
         long requiredRam = offering.getRamSize() * 1024L * 1024L;
-        String opFactor = _configDao.getValue(Config.CPUOverprovisioningFactor.key());
-        float cpuOverprovisioningFactor = NumbersUtil.parseFloat(opFactor, 1);
-
         //list pods under this zone by cpu and ram capacity
         List<Long> prioritizedPodIds = new ArrayList<Long>();
-        Pair<List<Long>, Map<Long, Double>> podCapacityInfo = listPodsByCapacity(plan.getDataCenterId(), requiredCpu, requiredRam, cpuOverprovisioningFactor); 
+        Pair<List<Long>, Map<Long, Double>> podCapacityInfo = listPodsByCapacity(plan.getDataCenterId(), requiredCpu, requiredRam);
         List<Long> podsWithCapacity = podCapacityInfo.first();
 
         if(!podsWithCapacity.isEmpty()){
@@ -350,11 +346,9 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner {
         DataCenter dc = _dcDao.findById(vm.getDataCenterId());
         int requiredCpu = offering.getCpu() * offering.getSpeed();
         long requiredRam = offering.getRamSize() * 1024L * 1024L;
-        String opFactor = _configDao.getValue(Config.CPUOverprovisioningFactor.key());
-        float cpuOverprovisioningFactor = NumbersUtil.parseFloat(opFactor, 1);
 
         //list clusters under this zone by cpu and ram capacity
-        Pair<List<Long>, Map<Long, Double>> clusterCapacityInfo = listClustersByCapacity(id, requiredCpu, requiredRam, avoid, isZone, cpuOverprovisioningFactor);
+        Pair<List<Long>, Map<Long, Double>> clusterCapacityInfo = listClustersByCapacity(id, requiredCpu, requiredRam, avoid, isZone);
         List<Long> prioritizedClusterIds = clusterCapacityInfo.first();
         if(!prioritizedClusterIds.isEmpty()){
             if(avoid.getClustersToAvoid() != null){
@@ -468,30 +462,30 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner {
 
         // 	For each capacity get the cluster list crossing the threshold and remove it from the clusterList that will be used for vm allocation.
         for(short capacity : capacityList){
-
-            if (clusterListForVmAllocation == null || clusterListForVmAllocation.size() == 0){
-                return;
-            }
-
-            if (capacity == Capacity.CAPACITY_TYPE_CPU){
-                clustersCrossingThreshold = _capacityDao.listClustersCrossingThreshold(Capacity.CAPACITY_TYPE_CPU, plan.getDataCenterId(),
-                        capacityThresholdMap.get(capacity), cpu_requested, ApiDBUtils.getCpuOverprovisioningFactor());
-            }else{
+        	
+        	if (clusterListForVmAllocation == null || clusterListForVmAllocation.size() == 0){
+           		return;
+           	}
+            if (capacity == Capacity.CAPACITY_TYPE_CPU) {
+           		clustersCrossingThreshold = _capacityDao.listClustersCrossingThreshold(capacity, plan.getDataCenterId(),
+           				capacityThresholdMap.get(capacity), cpu_requested);
+            }
+            else if (capacity == Capacity.CAPACITY_TYPE_MEMORY ) {
                 clustersCrossingThreshold = _capacityDao.listClustersCrossingThreshold(capacity, plan.getDataCenterId(),
-                        capacityThresholdMap.get(capacity), ram_requested, 1.0f);//Mem overprov not supported yet
-            }
-
-
-            if (clustersCrossingThreshold != null && clustersCrossingThreshold.size() != 0){
-                // addToAvoid Set
-                avoid.addClusterList(clustersCrossingThreshold);
-                // Remove clusters crossing disabled threshold
-                clusterListForVmAllocation.removeAll(clustersCrossingThreshold);
-
-                s_logger.debug("Cannot allocate cluster list " + clustersCrossingThreshold.toString() + " for vm creation since their allocated percentage" +
-                        " crosses the disable capacity threshold: " + capacityThresholdMap.get(capacity) + " for capacity Type : " + capacity + ", skipping these clusters");           		
+                        capacityThresholdMap.get(capacity), ram_requested );
             }
 
+           	
+           	if (clustersCrossingThreshold != null && clustersCrossingThreshold.size() != 0){
+               	// addToAvoid Set
+           		avoid.addClusterList(clustersCrossingThreshold);
+           		// Remove clusters crossing disabled threshold
+               	clusterListForVmAllocation.removeAll(clustersCrossingThreshold);
+               	
+           		s_logger.debug("Cannot allocate cluster list " + clustersCrossingThreshold.toString() + " for vm creation since their allocated percentage" +
+           				" crosses the disable capacity threshold: " + capacityThresholdMap.get(capacity) + " for capacity Type : " + capacity + ", skipping these clusters");
+           	}
+           	           	           	
         }
     }
 
@@ -560,7 +554,7 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner {
     }
 
 
-    protected Pair<List<Long>, Map<Long, Double>> listClustersByCapacity(long id, int requiredCpu, long requiredRam, ExcludeList avoid, boolean isZone, float cpuOverprovisioningFactor){
+    protected Pair<List<Long>, Map<Long, Double>> listClustersByCapacity(long id, int requiredCpu, long requiredRam, ExcludeList avoid, boolean isZone){
         //look at the aggregate available cpu and ram per cluster
         //although an aggregate value may be false indicator that a cluster can host a vm, it will at the least eliminate those clusters which definitely cannot
 
@@ -574,14 +568,11 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner {
             capacityType = CapacityVO.CAPACITY_TYPE_MEMORY;
         }
 
-        if (s_logger.isDebugEnabled()) {
-            s_logger.debug("CPUOverprovisioningFactor considered: " + cpuOverprovisioningFactor);
-        }
-        List<Long> clusterIdswithEnoughCapacity = _capacityDao.listClustersInZoneOrPodByHostCapacities(id, requiredCpu, requiredRam, capacityType, isZone, cpuOverprovisioningFactor);
+        List<Long> clusterIdswithEnoughCapacity = _capacityDao.listClustersInZoneOrPodByHostCapacities(id, requiredCpu, requiredRam, capacityType, isZone);
         if (s_logger.isTraceEnabled()) {
             s_logger.trace("ClusterId List having enough CPU and RAM capacity: " + clusterIdswithEnoughCapacity);
         }
-        Pair<List<Long>, Map<Long, Double>> result = _capacityDao.orderClustersByAggregateCapacity(id, capacityType, isZone, cpuOverprovisioningFactor);
+        Pair<List<Long>, Map<Long, Double>> result = _capacityDao.orderClustersByAggregateCapacity(id, capacityType, isZone);
         List<Long> clusterIdsOrderedByAggregateCapacity = result.first();
         //only keep the clusters that have enough capacity to host this VM
         if (s_logger.isTraceEnabled()) {
@@ -597,7 +588,8 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner {
 
     }
 
-    protected Pair<List<Long>, Map<Long, Double>> listPodsByCapacity(long zoneId, int requiredCpu, long requiredRam, float cpuOverprovisioningFactor){
+
+    protected Pair<List<Long>, Map<Long, Double>> listPodsByCapacity(long zoneId, int requiredCpu, long requiredRam){
         //look at the aggregate available cpu and ram per pod
         //although an aggregate value may be false indicator that a pod can host a vm, it will at the least eliminate those pods which definitely cannot
 
@@ -611,14 +603,11 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner {
             capacityType = CapacityVO.CAPACITY_TYPE_MEMORY;
         }
 
-        if (s_logger.isDebugEnabled()) {
-            s_logger.debug("CPUOverprovisioningFactor considered: " + cpuOverprovisioningFactor);
-        }
-        List<Long> podIdswithEnoughCapacity = _capacityDao.listPodsByHostCapacities(zoneId, requiredCpu, requiredRam, capacityType, cpuOverprovisioningFactor);
+        List<Long> podIdswithEnoughCapacity = _capacityDao.listPodsByHostCapacities(zoneId, requiredCpu, requiredRam, capacityType);
         if (s_logger.isTraceEnabled()) {
             s_logger.trace("PodId List having enough CPU and RAM capacity: " + podIdswithEnoughCapacity);
         }
-        Pair<List<Long>, Map<Long, Double>> result = _capacityDao.orderPodsByAggregateCapacity(zoneId, capacityType, cpuOverprovisioningFactor);
+        Pair<List<Long>, Map<Long, Double>> result = _capacityDao.orderPodsByAggregateCapacity(zoneId, capacityType);
         List<Long> podIdsOrderedByAggregateCapacity = result.first();
         //only keep the clusters that have enough capacity to host this VM
         if (s_logger.isTraceEnabled()) {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/23e54bb0/server/src/com/cloud/hypervisor/HypervisorGuruBase.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/hypervisor/HypervisorGuruBase.java b/server/src/com/cloud/hypervisor/HypervisorGuruBase.java
index e158962..efe9396 100644
--- a/server/src/com/cloud/hypervisor/HypervisorGuruBase.java
+++ b/server/src/com/cloud/hypervisor/HypervisorGuruBase.java
@@ -76,9 +76,11 @@ public abstract class HypervisorGuruBase extends AdapterBase implements Hypervis
 
         ServiceOffering offering = vmProfile.getServiceOffering();  
         VirtualMachine vm = vmProfile.getVirtualMachine();
-
-        VirtualMachineTO to = new VirtualMachineTO(vm.getId(), vm.getInstanceName(), vm.getType(), offering.getCpu(), offering.getSpeed(), 
-                offering.getRamSize() * 1024l * 1024l, offering.getRamSize() * 1024l * 1024l, null, null, vm.isHaEnabled(), vm.limitCpuUse(), vm.getVncPassword());
+        Long minMemory = (long) (offering.getRamSize()/vmProfile.getCpuOvercommitRatio());
+        int  minspeed= (int)(offering.getSpeed()/vmProfile.getMemoryOvercommitRatio());
+        int  maxspeed = (offering.getSpeed());
+        VirtualMachineTO to = new VirtualMachineTO(vm.getId(), vm.getInstanceName(), vm.getType(), offering.getCpu(), minspeed, maxspeed,
+                minMemory * 1024l * 1024l, offering.getRamSize() * 1024l * 1024l, null, null, vm.isHaEnabled(), vm.limitCpuUse(), vm.getVncPassword());
         to.setBootArgs(vmProfile.getBootArgs());
 
         List<NicProfile> nicProfiles = vmProfile.getNics();

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/23e54bb0/server/src/com/cloud/resource/ResourceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/resource/ResourceManagerImpl.java b/server/src/com/cloud/resource/ResourceManagerImpl.java
index 98044fb..0df1563 100755
--- a/server/src/com/cloud/resource/ResourceManagerImpl.java
+++ b/server/src/com/cloud/resource/ResourceManagerImpl.java
@@ -30,6 +30,7 @@ import javax.ejb.Local;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
+import com.cloud.dc.*;
 import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.command.admin.cluster.AddClusterCmd;
 import org.apache.cloudstack.api.command.admin.cluster.DeleteClusterCmd;
@@ -72,12 +73,6 @@ import com.cloud.cluster.ManagementServerNode;
 import com.cloud.configuration.Config;
 import com.cloud.configuration.ConfigurationManager;
 import com.cloud.configuration.dao.ConfigurationDao;
-import com.cloud.dc.ClusterDetailsDao;
-import com.cloud.dc.ClusterVO;
-import com.cloud.dc.DataCenterIpAddressVO;
-import com.cloud.dc.DataCenterVO;
-import com.cloud.dc.HostPodVO;
-import com.cloud.dc.PodCluster;
 import com.cloud.dc.dao.ClusterDao;
 import com.cloud.dc.dao.ClusterVSMMapDao;
 import com.cloud.dc.dao.DataCenterDao;
@@ -483,6 +478,11 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
         clusterId = cluster.getId();
         result.add(cluster);
 
+           ClusterDetailsVO cluster_detail_cpu = new ClusterDetailsVO(clusterId, "cpuOvercommitRatio", Float.toString(cmd.getCpuOvercommitRatio()));
+           ClusterDetailsVO cluster_detail_ram = new ClusterDetailsVO(clusterId, "memoryOvercommitRatio", Float.toString(cmd.getMemoryOvercommitRaito()));
+           _clusterDetailsDao.persist(cluster_detail_cpu);
+           _clusterDetailsDao.persist(cluster_detail_ram);
+
         if (clusterType == Cluster.ClusterType.CloudManaged) {
             return result;
         }
@@ -494,6 +494,10 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
         details.put("password", password);
         _clusterDetailsDao.persist(cluster.getId(), details);
 
+        _clusterDetailsDao.persist(cluster_detail_cpu);
+        _clusterDetailsDao.persist(cluster_detail_ram);
+
+
         boolean success = false;
         try {
             try {
@@ -1061,7 +1065,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
     @Override
     @DB
 	public Cluster updateCluster(Cluster clusterToUpdate, String clusterType,
-			String hypervisor, String allocationState, String managedstate) {
+                                 String hypervisor, String allocationState, String managedstate, Float memoryOvercommitRaito, Float cpuOvercommitRatio) {
 
         ClusterVO cluster = (ClusterVO) clusterToUpdate;
         // Verify cluster information and update the cluster if needed

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/23e54bb0/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
index 2b70ff6..f8448c0 100755
--- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
+++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
@@ -37,6 +37,7 @@ import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
+import com.cloud.dc.*;
 import org.apache.log4j.Logger;
 
 import com.cloud.agent.AgentManager;
@@ -76,6 +77,7 @@ import com.cloud.configuration.dao.ConfigurationDao;
 import com.cloud.dc.DataCenter;
 import com.cloud.dc.DataCenterVO;
 import com.cloud.dc.HostPodVO;
+import com.cloud.consoleproxy.ConsoleProxyManager;
 import com.cloud.dc.dao.DataCenterDao;
 import com.cloud.dc.dao.HostPodDao;
 import com.cloud.deploy.DataCenterDeployment;
@@ -157,6 +159,7 @@ import com.cloud.vm.snapshot.VMSnapshot;
 import com.cloud.vm.snapshot.VMSnapshotManager;
 import com.cloud.vm.snapshot.VMSnapshotVO;
 import com.cloud.vm.snapshot.dao.VMSnapshotDao;
+import com.cloud.vm.dao.UserVmDetailsDao;
 
 @Local(value = VirtualMachineManager.class)
 public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMachineManager, Listener {
@@ -232,6 +235,10 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
     
     @Inject 
     protected VMSnapshotManager _vmSnapshotMgr = null;
+    @Inject
+    protected ClusterDetailsDao  _clusterDetailsDao;
+    @Inject
+    protected UserVmDetailsDao _uservmDetailsDao;
 
     @Inject
     protected ConfigurationDao _configDao;
@@ -398,6 +405,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
 
         VirtualMachineGuru<T> guru = getVmGuru(vm);
         guru.finalizeExpunge(vm);
+        //remove the overcommit detials from the uservm details
+        _uservmDetailsDao.deleteDetails(vm.getId());
 
         if (s_logger.isDebugEnabled()) {
             s_logger.debug("Expunged " + vm);
@@ -718,6 +727,11 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
 
                 long destHostId = dest.getHost().getId();
                 vm.setPodId(dest.getPod().getId());
+                Long cluster_id = dest.getCluster().getId();
+                ClusterDetailsVO cluster_detail_cpu =  _clusterDetailsDao.findDetail(cluster_id,"cpuOvercommitRatio");
+                ClusterDetailsVO cluster_detail_ram =  _clusterDetailsDao.findDetail(cluster_id,"memoryOvercommitRatio");
+                vmProfile.setcpuOvercommitRatio(Float.parseFloat(cluster_detail_cpu.getValue()));
+                vmProfile.setramOvercommitRatio(Float.parseFloat(cluster_detail_ram.getValue()));
 
                 try {
                     if (!changeState(vm, Event.OperationRetry, destHostId, work, Step.Prepare)) {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/23e54bb0/server/src/com/cloud/vm/VirtualMachineProfileImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/VirtualMachineProfileImpl.java b/server/src/com/cloud/vm/VirtualMachineProfileImpl.java
index eb9e5ad..24f44cb 100644
--- a/server/src/com/cloud/vm/VirtualMachineProfileImpl.java
+++ b/server/src/com/cloud/vm/VirtualMachineProfileImpl.java
@@ -43,13 +43,16 @@ public class VirtualMachineProfileImpl<T extends VMInstanceVO> implements Virtua
     T _vm;
     ServiceOfferingVO _offering;
     VMTemplateVO _template;
+    UserVmDetailVO _userVmDetails;
     Map<Param, Object> _params;
     List<NicProfile> _nics = new ArrayList<NicProfile>();
     List<VolumeTO> _disks = new ArrayList<VolumeTO>();
     StringBuilder _bootArgs = new StringBuilder();
     Account _owner;
     BootloaderType _bootloader;
-    
+    Float cpuOvercommitRatio = 1.0f;
+    Float memoryOvercommitRatio = 1.0f;
+
     VirtualMachine.Type _type;
     
     public VirtualMachineProfileImpl(T vm, VMTemplateVO template, ServiceOfferingVO offering, Account owner, Map<Param, Object> params) {
@@ -239,6 +242,25 @@ public class VirtualMachineProfileImpl<T extends VMInstanceVO> implements Virtua
 	public void setServiceOffering(ServiceOfferingVO offering) {
 		_offering = offering;
 	}
-	
-	
+
+    public void setcpuOvercommitRatio(Float cpuOvercommitRatio){
+        this.cpuOvercommitRatio= cpuOvercommitRatio;
+
+    }
+
+    public void setramOvercommitRatio(Float memoryOvercommitRatio){
+        this.memoryOvercommitRatio= memoryOvercommitRatio;
+
+    }
+    @Override
+   public Float getCpuOvercommitRatio(){
+        return  this.cpuOvercommitRatio;
+    }
+
+    @Override
+    public Float getMemoryOvercommitRatio(){
+        return this.memoryOvercommitRatio;
+    }
+
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/23e54bb0/server/test/com/cloud/capacity/CapacityManagerTest.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/capacity/CapacityManagerTest.java b/server/test/com/cloud/capacity/CapacityManagerTest.java
new file mode 100644
index 0000000..381d401
--- /dev/null
+++ b/server/test/com/cloud/capacity/CapacityManagerTest.java
@@ -0,0 +1,61 @@
+package com.cloud.capacity;
+import com.cloud.capacity.dao.CapacityDao;
+import com.cloud.dc.ClusterDetailsDao;
+import com.cloud.dc.ClusterDetailsVO;
+import com.cloud.service.ServiceOfferingVO;
+import com.cloud.service.dao.ServiceOfferingDao;
+import com.cloud.vm.UserVmDetailVO;
+import com.cloud.vm.VirtualMachine;
+import com.cloud.vm.dao.UserVmDetailsDao;
+import org.apache.log4j.Logger;
+import org.junit.*;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import static org.mockito.Mockito.*;
+
+
+public class CapacityManagerTest {
+    CapacityDao CDao = mock(CapacityDao.class);
+    ServiceOfferingDao SOfferingDao = mock(ServiceOfferingDao.class);
+    ClusterDetailsDao ClusterDetailsDao= mock(com.cloud.dc.ClusterDetailsDao.class);
+    CapacityManagerImpl capMgr;
+    private ServiceOfferingVO svo = mock(ServiceOfferingVO.class);
+    private CapacityVO cvo_cpu =    mock(CapacityVO.class);
+    private CapacityVO cvo_ram =    mock(CapacityVO.class);
+    private VirtualMachine vm =     mock(VirtualMachine.class);
+    private ClusterDetailsVO cluster_detail_cpu = mock(ClusterDetailsVO.class);
+    private ClusterDetailsVO cluster_detail_ram =  mock(ClusterDetailsVO.class);
+
+    public CapacityManagerImpl  setUp() {
+        CapacityManagerImpl  capMgr = new CapacityManagerImpl();
+        ((CapacityManagerImpl)capMgr)._clusterDetailsDao= ClusterDetailsDao;
+        capMgr._capacityDao = CDao;
+        capMgr._offeringsDao = SOfferingDao;
+        return capMgr;
+    }
+
+    @Test
+    public void allocateCapacityTest(){
+        capMgr=setUp();
+        when(vm.getHostId()).thenReturn(1l);
+        when(vm.getServiceOfferingId()).thenReturn(2l);
+        when(SOfferingDao.findById(anyLong())).thenReturn(svo);
+        when(CDao.findByHostIdType(anyLong(), eq(Capacity.CAPACITY_TYPE_CPU))).thenReturn(cvo_cpu);
+        when(CDao.findByHostIdType(anyLong(), eq(Capacity.CAPACITY_TYPE_MEMORY))).thenReturn(cvo_ram);
+        when(cvo_cpu.getUsedCapacity()).thenReturn(500l);
+        when(cvo_cpu.getTotalCapacity()).thenReturn(2000l);
+        when(cvo_ram.getUsedCapacity()).thenReturn(3000l);
+        when(cvo_ram.getTotalCapacity()).thenReturn((long) 1024*1024*1024);
+        when(svo.getCpu()).thenReturn(500);
+        when(svo.getRamSize()).thenReturn(512);
+        when(cvo_cpu.getReservedCapacity()).thenReturn(0l);
+        when(cvo_ram.getReservedCapacity()).thenReturn(0l);
+        when(cluster_detail_ram.getValue()).thenReturn("1.5");
+        when(cluster_detail_cpu.getValue()).thenReturn("2");
+        when(CDao.update(anyLong(), isA(CapacityVO.class))).thenReturn(true) ;
+        boolean hasCapacity=capMgr.checkIfHostHasCapacity(1l,500,1024*1024*1024,false,2,2,false);
+        Assert.assertTrue(hasCapacity);
+
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/23e54bb0/server/test/com/cloud/resource/MockResourceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/resource/MockResourceManagerImpl.java b/server/test/com/cloud/resource/MockResourceManagerImpl.java
index 889318b..e7ab858 100644
--- a/server/test/com/cloud/resource/MockResourceManagerImpl.java
+++ b/server/test/com/cloud/resource/MockResourceManagerImpl.java
@@ -53,7 +53,6 @@ import com.cloud.storage.S3;
 import com.cloud.storage.Swift;
 import com.cloud.template.VirtualMachineTemplate;
 import com.cloud.utils.Pair;
-import com.cloud.utils.component.Manager;
 import com.cloud.utils.component.ManagerBase;
 import com.cloud.utils.fsm.NoTransitionException;
 
@@ -111,7 +110,7 @@ public class MockResourceManagerImpl extends ManagerBase implements ResourceMana
      */
     @Override
     public Cluster updateCluster(Cluster cluster, String clusterType, String hypervisor, String allocationState,
-            String managedstate) {
+                                 String managedstate, Float memoryOvercommitRaito, Float cpuOvercommitRatio) {
         // TODO Auto-generated method stub
         return null;
     }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/23e54bb0/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareHelper.java
----------------------------------------------------------------------
diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareHelper.java b/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareHelper.java
index 47ff8e2..352c584 100644
--- a/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareHelper.java
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareHelper.java
@@ -539,7 +539,12 @@ public class VmwareHelper {
 
 		cpuInfo.setReservation((long)cpuReservedMhz);
 		vmConfig.setCpuAllocation(cpuInfo);
-		
+		 if (cpuSpeedMHz != cpuReservedMhz){
+             vmConfig.setCpuHotAddEnabled(true);
+         }
+        if (memoryMB != memoryReserveMB){
+            vmConfig.setMemoryHotAddEnabled(true);
+        }
 		ResourceAllocationInfo memInfo = new ResourceAllocationInfo();
 		memInfo.setLimit((long)memoryMB);
 		memInfo.setReservation((long)memoryReserveMB);


Mime
View raw message