Skip to content

Commit 476733c

Browse files
bvbharatkishankavala
authored andcommitted
CLOUDSTACK-7571 changing value of cpu/mem.overprovisioning.factor for xen cluster is not affecting total memory at zone level
1 parent c55bc0b commit 476733c

1 file changed

Lines changed: 24 additions & 8 deletions

File tree

engine/schema/src/com/cloud/capacity/dao/CapacityDaoImpl.java

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
113113
+ "else sum(total_capacity) end),"
114114
+ "((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))"
115115
+ "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,"
116-
+ "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'";
116+
+ "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'";
117117

118118
private static final String LIST_CAPACITY_GROUP_BY_ZONE_TYPE_PART2 = " GROUP BY data_center_id, capacity_type order by percent desc limit ";
119119
private static final String LIST_CAPACITY_GROUP_BY_POD_TYPE_PART1 =
@@ -122,7 +122,7 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
122122
+ "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),"
123123
+ "((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)) "
124124
+ "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,"
125-
+ "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' ";
125+
+ "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' ";
126126

127127
private static final String LIST_CAPACITY_GROUP_BY_POD_TYPE_PART2 = " GROUP BY pod_id, capacity_type order by percent desc limit ";
128128

@@ -134,7 +134,7 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
134134
+ "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,"
135135
+ "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' ";
136136

137-
private static final String LIST_CAPACITY_GROUP_BY_CLUSTER_TYPE_PART2 = " GROUP BY cluster_id, capacity_type order by percent desc limit ";
137+
private static final String LIST_CAPACITY_GROUP_BY_CLUSTER_TYPE_PART2 = " GROUP BY cluster_id, capacity_type, pod_id order by percent desc limit ";
138138
private static final String UPDATE_CAPACITY_STATE = "UPDATE `cloud`.`op_host_capacity` SET capacity_state = ? WHERE ";
139139

140140
private static final String LIST_CAPACITY_GROUP_BY_CAPACITY_PART1= "SELECT sum(capacity.used_capacity), sum(capacity.reserved_capacity)," +
@@ -317,7 +317,7 @@ public List<SummedCapacity> listCapacitiesGroupedByLevelAndType(Integer capacity
317317
StringBuilder finalQuery = new StringBuilder();
318318
TransactionLegacy txn = TransactionLegacy.currentTxn();
319319
PreparedStatement pstmt = null;
320-
List<SummedCapacity> result = new ArrayList<SummedCapacity>();
320+
List<SummedCapacity> results = new ArrayList<SummedCapacity>();
321321

322322
List<Long> resourceIdList = new ArrayList<Long>();
323323

@@ -354,11 +354,11 @@ public List<SummedCapacity> listCapacitiesGroupedByLevelAndType(Integer capacity
354354

355355
switch (level) {
356356
case 1: // List all the capacities grouped by zone, capacity Type
357-
finalQuery.append(LIST_CAPACITY_GROUP_BY_ZONE_TYPE_PART2);
357+
finalQuery.append(LIST_CAPACITY_GROUP_BY_CLUSTER_TYPE_PART2);
358358
break;
359359

360360
case 2: // List all the capacities grouped by pod, capacity Type
361-
finalQuery.append(LIST_CAPACITY_GROUP_BY_POD_TYPE_PART2);
361+
finalQuery.append(LIST_CAPACITY_GROUP_BY_CLUSTER_TYPE_PART2);
362362
break;
363363

364364
case 3: // List all the capacities grouped by cluster, capacity Type
@@ -387,9 +387,25 @@ public List<SummedCapacity> listCapacitiesGroupedByLevelAndType(Integer capacity
387387
SummedCapacity summedCapacity =
388388
new SummedCapacity(rs.getLong(1), rs.getLong(2), rs.getLong(3), rs.getFloat(4), (short)rs.getLong(5), rs.getLong(6), capacityPodId, capacityClusterId);
389389

390-
result.add(summedCapacity);
390+
results.add(summedCapacity);
391391
}
392-
return result;
392+
393+
HashMap<Integer, SummedCapacity> capacityMap = new HashMap<Integer, SummedCapacity>();
394+
for (SummedCapacity result: results) {
395+
if (capacityMap.containsKey(result.getCapacityType().intValue())) {
396+
SummedCapacity tempCapacity = capacityMap.get(result.getCapacityType().intValue());
397+
tempCapacity.setUsedCapacity(tempCapacity.getUsedCapacity()+result.getUsedCapacity());
398+
tempCapacity.setReservedCapacity(tempCapacity.getReservedCapacity()+result.getReservedCapacity());
399+
tempCapacity.setSumTotal(tempCapacity.getTotalCapacity()+result.getTotalCapacity());
400+
}else {
401+
capacityMap.put(result.getCapacityType().intValue(),result);
402+
}
403+
}
404+
List<SummedCapacity> summedCapacityList = new ArrayList<SummedCapacity>();
405+
for (Integer capacity_type : capacityMap.keySet()) {
406+
summedCapacityList.add(capacityMap.get(capacity_type));
407+
}
408+
return summedCapacityList;
393409
} catch (SQLException e) {
394410
throw new CloudRuntimeException("DB Exception on: " + finalQuery, e);
395411
} catch (Throwable e) {

0 commit comments

Comments
 (0)