You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by bh...@apache.org on 2015/01/20 11:20:24 UTC
[2/4] git commit: updated refs/heads/4.5 to 45ebdf3
CLOUDSTACK-7571 changing value of cpu/mem.overprovisioning.factor for xen cluster is not affecting total memory at zone level
(cherry picked from commit 476733cb92634c8494fe64762d7fbc178292a754)
Signed-off-by: Rohit Yadav <ro...@shapeblue.com>
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/bf8db0c7
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/bf8db0c7
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/bf8db0c7
Branch: refs/heads/4.5
Commit: bf8db0c743c94c4540dab2f069d253f1a859eb10
Parents: 45108fd
Author: Bharat Kumar <bh...@citrix.com>
Authored: Wed Sep 17 14:30:33 2014 +0530
Committer: Rohit Yadav <ro...@shapeblue.com>
Committed: Tue Jan 20 14:39:21 2015 +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/bf8db0c7/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 cea18bd..85740a2 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) {