@@ -117,7 +117,7 @@ default Double getImbalancePostMigration(ServiceOffering serviceOffering, Virtua
117117 private Pair <Long , Map <Long , Ternary <Long , Long , Long >>> getHostMetricsMapAndType (Long clusterId ,
118118 ServiceOffering serviceOffering , Map <Long , Ternary <Long , Long , Long >> hostCpuMap ,
119119 Map <Long , Ternary <Long , Long , Long >> hostMemoryMap ) throws ConfigurationException {
120- String metric = ClusterDrsMetric . valueIn (clusterId );
120+ String metric = getClusterDrsMetric (clusterId );
121121 Pair <Long , Map <Long , Ternary <Long , Long , Long >>> pair ;
122122 switch (metric ) {
123123 case "cpu" :
@@ -155,22 +155,26 @@ private Double getImbalance(List<Double> metricList) {
155155 return clusterStandardDeviation / clusterMeanMetric ;
156156 }
157157
158- private Double getMetricValue (Long clusterId , double used , double free , double total , Float skipThreshold ) {
159- boolean useRatio = ClusterDrsMetricUseRatio .valueIn (clusterId );
160- switch (ClusterDrsMetricType .valueIn (clusterId )) {
158+ default String getClusterDrsMetric (long clusterId ) {
159+ return ClusterDrsMetric .valueIn (clusterId );
160+ }
161+
162+ default Double getMetricValue (long clusterId , long used , long free , long total , Float skipThreshold ) {
163+ boolean useRatio = getDrsMetricUseRatio (clusterId );
164+ switch (getDrsMetricType (clusterId )) {
161165 case "free" :
162166 if (skipThreshold != null && free < skipThreshold * total ) return null ;
163167 if (useRatio ) {
164- return free / total ;
168+ return ( double ) free / total ;
165169 } else {
166- return free ;
170+ return ( double ) free ;
167171 }
168172 case "used" :
169173 if (skipThreshold != null && used > skipThreshold * total ) return null ;
170174 if (useRatio ) {
171- return used / total ;
175+ return ( double ) used / total ;
172176 } else {
173- return used ;
177+ return ( double ) used ;
174178 }
175179 }
176180 return null ;
@@ -206,6 +210,14 @@ default Double getClusterStandardDeviation(List<Double> metricList, Double mean)
206210 }
207211 }
208212
213+ default boolean getDrsMetricUseRatio (long clusterId ) {
214+ return ClusterDrsMetricUseRatio .valueIn (clusterId );
215+ }
216+
217+ default String getDrsMetricType (long clusterId ) {
218+ return ClusterDrsMetricType .valueIn (clusterId );
219+ }
220+
209221 /**
210222 * The cluster imbalance is defined as the percentage deviation from the mean
211223 * for a configured metric of the cluster. The standard deviation is used as a
@@ -218,7 +230,7 @@ default Double getClusterStandardDeviation(List<Double> metricList, Double mean)
218230 */
219231 default Double getClusterImbalance (Long clusterId , List <Ternary <Long , Long , Long >> cpuList ,
220232 List <Ternary <Long , Long , Long >> memoryList , Float skipThreshold ) throws ConfigurationException {
221- String metric = ClusterDrsMetric . valueIn (clusterId );
233+ String metric = getClusterDrsMetric (clusterId );
222234 List <Double > list ;
223235 switch (metric ) {
224236 case "cpu" :
0 commit comments