Skip to content

Commit 557d1b8

Browse files
committed
enhancement: iterate directly on HostJoinVO
instead of Host by cluster, and then find each host by id additional: removed unused method
1 parent 16b7b71 commit 557d1b8

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

plugins/metrics/src/main/java/org/apache/cloudstack/metrics/MetricsServiceImpl.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,6 @@ protected MetricsServiceImpl() {
188188
super();
189189
}
190190

191-
private Double findRatioValue(final String value) {
192-
if (value != null) {
193-
return Double.valueOf(value);
194-
}
195-
return 1.0;
196-
}
197-
198191
private void updateHostMetrics(final HostMetrics hostMetrics, final HostJoinVO host) {
199192
hostMetrics.addCpuAllocated(host.getCpuReservedCapacity() + host.getCpuUsedCapacity());
200193
hostMetrics.addMemoryAllocated(host.getMemReservedCapacity() + host.getMemUsedCapacity());
@@ -764,14 +757,13 @@ public List<ClusterMetricsResponse> listClusterMetrics(Pair<List<ClusterResponse
764757
if (AllowListMetricsComputation.value()) {
765758
List<Ternary<Long, Long, Long>> cpuList = new ArrayList<>();
766759
List<Ternary<Long, Long, Long>> memoryList = new ArrayList<>();
767-
for (final Host host : hostDao.findByClusterId(clusterId)) {
768-
if (host == null || host.getType() != Host.Type.Routing) {
760+
for (final HostJoinVO host : hostJoinDao.findByClusterId(clusterId, Host.Type.Routing)) {
761+
if (host == null) {
769762
continue;
770763
}
771-
updateHostMetrics(hostMetrics, hostJoinDao.findById(host.getId()));
772-
HostJoinVO hostJoin = hostJoinDao.findById(host.getId());
773-
cpuList.add(new Ternary<>(hostJoin.getCpuUsedCapacity(), hostJoin.getCpuReservedCapacity(), hostJoin.getCpus() * hostJoin.getSpeed()));
774-
memoryList.add(new Ternary<>(hostJoin.getMemUsedCapacity(), hostJoin.getMemReservedCapacity(), hostJoin.getTotalMemory()));
764+
updateHostMetrics(hostMetrics, host);
765+
cpuList.add(new Ternary<>(host.getCpuUsedCapacity(), host.getCpuReservedCapacity(), host.getCpus() * host.getSpeed()));
766+
memoryList.add(new Ternary<>(host.getMemUsedCapacity(), host.getMemReservedCapacity(), host.getTotalMemory()));
775767
}
776768
try {
777769
Double imbalance = ClusterDrsAlgorithm.getClusterImbalance(clusterId, cpuList, memoryList, null);
@@ -950,11 +942,11 @@ public List<ZoneMetricsResponse> listZoneMetrics(List<ZoneResponse> zoneResponse
950942
if (cluster == null) {
951943
continue;
952944
}
953-
for (final Host host: hostDao.findByClusterId(cluster.getId())) {
954-
if (host == null || host.getType() != Host.Type.Routing) {
945+
for (final HostJoinVO host: hostJoinDao.findByClusterId(cluster.getId(), Host.Type.Routing)) {
946+
if (host == null) {
955947
continue;
956948
}
957-
updateHostMetrics(hostMetrics, hostJoinDao.findById(host.getId()));
949+
updateHostMetrics(hostMetrics, host);
958950
}
959951
}
960952
} else {

0 commit comments

Comments
 (0)