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/07/24 11:54:44 UTC
git commit: updated refs/heads/master to da55aff
Repository: cloudstack
Updated Branches:
refs/heads/master 786285ab5 -> da55aff64
CLOUDSTACK-7158 listCapacity API missing types for certain zones
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/da55aff6
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/da55aff6
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/da55aff6
Branch: refs/heads/master
Commit: da55aff64f1b8255daa7999b91672bd2195bb76b
Parents: 786285a
Author: Bharat Kumar <bh...@citrix.com>
Authored: Wed Jun 25 18:32:17 2014 +0530
Committer: Kishan Kavala <ki...@citrix.com>
Committed: Thu Jul 24 14:33:51 2014 +0530
----------------------------------------------------------------------
.../com/cloud/capacity/dao/CapacityDaoImpl.java | 79 +++++++++++++++++---
.../com/cloud/server/ManagementServerImpl.java | 4 +-
2 files changed, 69 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/da55aff6/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 b7784f2..9cae045 100755
--- a/engine/schema/src/com/cloud/capacity/dao/CapacityDaoImpl.java
+++ b/engine/schema/src/com/cloud/capacity/dao/CapacityDaoImpl.java
@@ -137,15 +137,15 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
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_CAPACITY_GROUP_BY_CAPACITY_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_CAPACITY_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_CAPACITY_PART2 = " GROUP BY capacity_type";
+ private static final String LIST_CAPACITY_GROUP_BY_CAPACITY_DATA_CENTER_POD_CLUSTER = " GROUP BY data_center_id, pod_id, cluster_id, capacity_type";
/* In the below query"LIST_CLUSTERS_CROSSING_THRESHOLD" the threshold value is getting from the cluster_details table if not present then it gets from the global configuration
*
@@ -403,7 +403,7 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
TransactionLegacy txn = TransactionLegacy.currentTxn();
PreparedStatement pstmt = null;
- List<SummedCapacity> result = new ArrayList<SummedCapacity>();
+ List<SummedCapacity> results = new ArrayList<SummedCapacity>();
StringBuilder sql = new StringBuilder(LIST_CAPACITY_GROUP_BY_CAPACITY_PART1);
List<Long> resourceIdList = new ArrayList<Long>();
@@ -425,7 +425,7 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
resourceIdList.add(capacityType.longValue());
}
- sql.append(LIST_CAPACITY_GROUP_BY_CAPACITY_PART2);
+ sql.append(LIST_CAPACITY_GROUP_BY_CAPACITY_DATA_CENTER_POD_CLUSTER);
try {
pstmt = txn.prepareAutoCloseStatement(sql.toString());
@@ -435,10 +435,49 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
}
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
- SummedCapacity summedCapacity = new SummedCapacity(rs.getLong(1), rs.getLong(2), rs.getLong(3), (short)rs.getLong(5), null, null, rs.getLong(6));
- result.add(summedCapacity);
+
+ Long capacityPodId = null;
+ Long capacityClusterId = null;
+
+ if(rs.getLong(7) != 0)
+ capacityPodId = rs.getLong(7);
+ if(rs.getLong(8) != 0)
+ capacityClusterId = rs.getLong(8);
+
+ 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);
+
+ results.add(summedCapacity);
}
- return result;
+ HashMap<String, SummedCapacity> capacityMap = new HashMap<String, SummedCapacity>();
+ for (SummedCapacity result: results) {
+ String key;
+ if (zoneId != null || podId!= null) {
+ key=String.valueOf(result.getCapacityType());
+ }
+ else {
+ // sum the values based on the zoneId.
+ key=String.valueOf(result.getDataCenterId())+String.valueOf(result.getCapacityType());
+ }
+ SummedCapacity tempCapacity=null;
+ if (capacityMap.containsKey(key)) {
+ tempCapacity = capacityMap.get(key);
+ tempCapacity.setUsedCapacity(tempCapacity.getUsedCapacity()+result.getUsedCapacity());
+ tempCapacity.setReservedCapacity(tempCapacity.getReservedCapacity()+result.getReservedCapacity());
+ tempCapacity.setSumTotal(tempCapacity.getTotalCapacity()+result.getTotalCapacity());
+ }else {
+ capacityMap.put(key, result);
+ }
+ tempCapacity = capacityMap.get(key);
+ tempCapacity.setPodId(podId);
+ tempCapacity.setClusterId(clusterId);
+ }
+ List<SummedCapacity> summedCapacityList = new ArrayList<SummedCapacity>();
+ for (String key : capacityMap.keySet()) {
+ summedCapacityList.add(capacityMap.get(key));
+ }
+ return summedCapacityList;
} catch (SQLException e) {
throw new CloudRuntimeException("DB Exception on: " + sql, e);
} catch (Throwable e) {
@@ -622,6 +661,22 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
public Float getPercentUsed() {
return percentUsed;
}
+ public void setUsedCapacity(long sumUsed) {
+ this.sumUsed= sumUsed;
+ }
+ public void setReservedCapacity(long sumReserved) {
+ this.sumReserved=sumReserved;
+ }
+ public void setSumTotal(long sumTotal) {
+ this.sumTotal=sumTotal;
+ }
+
+ public void setPodId(Long podId) {
+ this.podId=podId;
+ }
+ public void setClusterId(Long clusterId) {
+ this.clusterId=clusterId;
+ }
}
@Override
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/da55aff6/server/src/com/cloud/server/ManagementServerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java
index 99b12732..4dc6c19 100755
--- a/server/src/com/cloud/server/ManagementServerImpl.java
+++ b/server/src/com/cloud/server/ManagementServerImpl.java
@@ -2480,8 +2480,8 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
List<CapacityVO> capacities = new ArrayList<CapacityVO>();
for (SummedCapacity summedCapacity : summedCapacities) {
- CapacityVO capacity = new CapacityVO(null, summedCapacity.getDataCenterId(), podId, clusterId, summedCapacity.getUsedCapacity() + summedCapacity.getReservedCapacity(),
- summedCapacity.getTotalCapacity(), summedCapacity.getCapacityType());
+ CapacityVO capacity = new CapacityVO(null, summedCapacity.getDataCenterId(),summedCapacity.getPodId(), summedCapacity.getClusterId(), summedCapacity.getUsedCapacity()
+ + summedCapacity.getReservedCapacity(), summedCapacity.getTotalCapacity(), summedCapacity.getCapacityType());
capacities.add(capacity);
}