Skip to content

Commit a30f9fa

Browse files
Harikrishna PatnalaAbhinandan Prateek
authored andcommitted
Fix for CLOUDSTACK-1704 and CLOUDSTACK-1622
Signed-off-by: Abhinandan Prateek <aprateek@apache.org>
1 parent 83fcba9 commit a30f9fa

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,27 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
116116
private static final String LIST_CAPACITY_GROUP_BY_CLUSTER_TYPE_PART2 = " GROUP BY cluster_id, capacity_type order by percent desc limit ";
117117
private static final String UPDATE_CAPACITY_STATE = "UPDATE `cloud`.`op_host_capacity` SET capacity_state = ? WHERE ";
118118

119+
/* 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
120+
*
121+
* CASE statement works like
122+
* if (cluster_details table has thershold value)
123+
* then
124+
* if (value from the cluster_details table is not null)
125+
* then
126+
* query from the cluster_details table
127+
* else
128+
* query from the configuration table
129+
* else
130+
* query from the configuration table
131+
*
132+
* */
119133
private static final String LIST_CLUSTERS_CROSSING_THRESHOLD = "SELECT clusterList.cluster_id " +
120134
"FROM ( SELECT cluster.cluster_id cluster_id, ( (sum(cluster.used) + sum(cluster.reserved) + ?)/sum(cluster.total) ) ratio, cluster.configValue value " +
121135
"FROM ( SELECT capacity.cluster_id cluster_id, capacity.used_capacity used, capacity.reserved_capacity reserved, capacity.total_capacity total, " +
122136
"CASE (SELECT count(*) FROM `cloud`.`cluster_details` details WHERE details.cluster_id = capacity.cluster_id AND details.name = ? ) " +
123-
"WHEN 1 THEN ( SELECT details.value FROM `cloud`.`cluster_details` details WHERE details.cluster_id = capacity.cluster_id AND details.name = ? ) " +
137+
"WHEN 1 THEN ( CASE WHEN (SELECT details.value FROM `cloud`.`cluster_details` details WHERE details.cluster_id = capacity.cluster_id AND details.name = ?) is NULL " +
138+
"THEN (SELECT config.value FROM `cloud`.`configuration` config WHERE config.name = ?)" +
139+
"ELSE (SELECT details.value FROM `cloud`.`cluster_details` details WHERE details.cluster_id = capacity.cluster_id AND details.name = ? ) END )" +
124140
"ELSE ( SELECT config.value FROM `cloud`.`configuration` config WHERE config.name = ?) " +
125141
"END configValue " +
126142
"FROM `cloud`.`op_host_capacity` capacity " +
@@ -168,8 +184,10 @@ public List<Long> listClustersCrossingThreshold(short capacityType, Long zoneId
168184
pstmt.setString(2, configName);
169185
pstmt.setString(3, configName);
170186
pstmt.setString(4, configName);
171-
pstmt.setLong(5,zoneId);
172-
pstmt.setShort(6,capacityType);
187+
pstmt.setString(5, configName);
188+
pstmt.setString(6, configName);
189+
pstmt.setLong(7,zoneId);
190+
pstmt.setShort(8,capacityType);
173191

174192
ResultSet rs = pstmt.executeQuery();
175193
while (rs.next()) {

0 commit comments

Comments
 (0)