You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ki...@apache.org on 2014/09/24 13:29:52 UTC

git commit: updated refs/heads/master to 476733c

Repository: cloudstack
Updated Branches:
  refs/heads/master c55bc0b2d -> 476733cb9


CLOUDSTACK-7571 changing value of cpu/mem.overprovisioning.factor for xen cluster is not affecting total memory at zone level


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

Branch: refs/heads/master
Commit: 476733cb92634c8494fe64762d7fbc178292a754
Parents: c55bc0b
Author: Bharat Kumar <bh...@citrix.com>
Authored: Wed Sep 17 14:30:33 2014 +0530
Committer: Kishan Kavala <ki...@apache.org>
Committed: Wed Sep 24 16:45:28 2014 +0530

----------------------------------------------------------------------
 .../com/cloud/capacity/dao/CapacityDaoImpl.java | 32 +++++++++++++++-----
 1 file changed, 24 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/476733cb/engine/schema/src/com/cloud/capacity/dao/CapacityDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/capacity/dao/CapacityDaoImpl.java b/engine/schema/src/com/cloud/capacity/dao/CapacityDaoImpl.java
index 9cae045..8636857 100755
--- a/engine/schema/src/com/cloud/capacity/dao/CapacityDaoImpl.java
+++ b/engine/schema/src/com/cloud/capacity/dao/CapacityDaoImpl.java
@@ -113,7 +113,7 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
             + "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 FROM `cloud`.`op_host_capacity` capacity WHERE  total_capacity > 0 AND data_center_id is not null AND capacity_state='Enabled'";
+            + "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_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 =
@@ -122,7 +122,7 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
             + "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' ";
+            + "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_POD_TYPE_PART2 = " GROUP BY pod_id, capacity_type order by percent desc limit ";
 
@@ -134,7 +134,7 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
             + "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 LIST_CAPACITY_GROUP_BY_CLUSTER_TYPE_PART2 = " GROUP BY cluster_id, capacity_type, pod_id 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_CAPACITY_GROUP_BY_CAPACITY_PART1= "SELECT sum(capacity.used_capacity), sum(capacity.reserved_capacity)," +
@@ -317,7 +317,7 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
         StringBuilder finalQuery = new StringBuilder();
         TransactionLegacy txn = TransactionLegacy.currentTxn();
         PreparedStatement pstmt = null;
-        List<SummedCapacity> result = new ArrayList<SummedCapacity>();
+        List<SummedCapacity> results = new ArrayList<SummedCapacity>();
 
         List<Long> resourceIdList = new ArrayList<Long>();
 
@@ -354,11 +354,11 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
 
         switch (level) {
             case 1: // List all the capacities grouped by zone, capacity Type
-                finalQuery.append(LIST_CAPACITY_GROUP_BY_ZONE_TYPE_PART2);
+            finalQuery.append(LIST_CAPACITY_GROUP_BY_CLUSTER_TYPE_PART2);
                 break;
 
             case 2: // List all the capacities grouped by pod, capacity Type
-                finalQuery.append(LIST_CAPACITY_GROUP_BY_POD_TYPE_PART2);
+            finalQuery.append(LIST_CAPACITY_GROUP_BY_CLUSTER_TYPE_PART2);
                 break;
 
             case 3: // List all the capacities grouped by cluster, capacity Type
@@ -387,9 +387,25 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
                 SummedCapacity summedCapacity =
                     new SummedCapacity(rs.getLong(1), rs.getLong(2), rs.getLong(3), rs.getFloat(4), (short)rs.getLong(5), rs.getLong(6), capacityPodId, capacityClusterId);
 
-                result.add(summedCapacity);
+                results.add(summedCapacity);
             }
-            return result;
+
+            HashMap<Integer, SummedCapacity> capacityMap = new HashMap<Integer, SummedCapacity>();
+            for (SummedCapacity result: results) {
+                 if (capacityMap.containsKey(result.getCapacityType().intValue())) {
+                     SummedCapacity tempCapacity = capacityMap.get(result.getCapacityType().intValue());
+                     tempCapacity.setUsedCapacity(tempCapacity.getUsedCapacity()+result.getUsedCapacity());
+                     tempCapacity.setReservedCapacity(tempCapacity.getReservedCapacity()+result.getReservedCapacity());
+                     tempCapacity.setSumTotal(tempCapacity.getTotalCapacity()+result.getTotalCapacity());
+                 }else {
+                     capacityMap.put(result.getCapacityType().intValue(),result);
+                 }
+            }
+            List<SummedCapacity> summedCapacityList = new ArrayList<SummedCapacity>();
+            for (Integer capacity_type : capacityMap.keySet()) {
+                summedCapacityList.add(capacityMap.get(capacity_type));
+            }
+            return summedCapacityList;
         } catch (SQLException e) {
             throw new CloudRuntimeException("DB Exception on: " + finalQuery, e);
         } catch (Throwable e) {