This is an automated email from the ASF dual-hosted git repository.

dahn pushed a commit to branch 4.20
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/4.20 by this push:
     new 0b7aef7a0f7 enhancement: iterate directly on HostJoinVO (#10613)
0b7aef7a0f7 is described below

commit 0b7aef7a0f7e5b4a86110a32d243e199517d7cdc
Author: Phsm Qwerty <[email protected]>
AuthorDate: Thu Mar 27 10:17:28 2025 +0100

    enhancement: iterate directly on HostJoinVO (#10613)
---
 .../cloudstack/metrics/MetricsServiceImpl.java     | 26 +++++-----------------
 1 file changed, 6 insertions(+), 20 deletions(-)

diff --git 
a/plugins/metrics/src/main/java/org/apache/cloudstack/metrics/MetricsServiceImpl.java
 
b/plugins/metrics/src/main/java/org/apache/cloudstack/metrics/MetricsServiceImpl.java
index 4f96b490291..479c2d7b673 100644
--- 
a/plugins/metrics/src/main/java/org/apache/cloudstack/metrics/MetricsServiceImpl.java
+++ 
b/plugins/metrics/src/main/java/org/apache/cloudstack/metrics/MetricsServiceImpl.java
@@ -188,13 +188,6 @@ public class MetricsServiceImpl extends 
MutualExclusiveIdsManagerBase implements
         super();
     }
 
-    private Double findRatioValue(final String value) {
-        if (value != null) {
-            return Double.valueOf(value);
-        }
-        return 1.0;
-    }
-
     private void updateHostMetrics(final HostMetrics hostMetrics, final 
HostJoinVO host) {
         hostMetrics.addCpuAllocated(host.getCpuReservedCapacity() + 
host.getCpuUsedCapacity());
         hostMetrics.addMemoryAllocated(host.getMemReservedCapacity() + 
host.getMemUsedCapacity());
@@ -764,14 +757,10 @@ public class MetricsServiceImpl extends 
MutualExclusiveIdsManagerBase implements
             if (AllowListMetricsComputation.value()) {
                 List<Ternary<Long, Long, Long>> cpuList = new ArrayList<>();
                 List<Ternary<Long, Long, Long>> memoryList = new ArrayList<>();
-                for (final Host host : hostDao.findByClusterId(clusterId)) {
-                    if (host == null || host.getType() != Host.Type.Routing) {
-                        continue;
-                    }
-                    updateHostMetrics(hostMetrics, 
hostJoinDao.findById(host.getId()));
-                    HostJoinVO hostJoin = hostJoinDao.findById(host.getId());
-                    cpuList.add(new Ternary<>(hostJoin.getCpuUsedCapacity(), 
hostJoin.getCpuReservedCapacity(), hostJoin.getCpus() * hostJoin.getSpeed()));
-                    memoryList.add(new 
Ternary<>(hostJoin.getMemUsedCapacity(), hostJoin.getMemReservedCapacity(), 
hostJoin.getTotalMemory()));
+                for (final HostJoinVO host : 
hostJoinDao.findByClusterId(clusterId, Host.Type.Routing)) {
+                    updateHostMetrics(hostMetrics, host);
+                    cpuList.add(new Ternary<>(host.getCpuUsedCapacity(), 
host.getCpuReservedCapacity(), host.getCpus() * host.getSpeed()));
+                    memoryList.add(new Ternary<>(host.getMemUsedCapacity(), 
host.getMemReservedCapacity(), host.getTotalMemory()));
                 }
                 try {
                     Double imbalance = 
ClusterDrsAlgorithm.getClusterImbalance(clusterId, cpuList, memoryList, null);
@@ -950,11 +939,8 @@ public class MetricsServiceImpl extends 
MutualExclusiveIdsManagerBase implements
                     if (cluster == null) {
                         continue;
                     }
-                    for (final Host host: 
hostDao.findByClusterId(cluster.getId())) {
-                        if (host == null || host.getType() != 
Host.Type.Routing) {
-                            continue;
-                        }
-                        updateHostMetrics(hostMetrics, 
hostJoinDao.findById(host.getId()));
+                    for (final HostJoinVO host: 
hostJoinDao.findByClusterId(cluster.getId(), Host.Type.Routing)) {
+                        updateHostMetrics(hostMetrics, host);
                     }
                 }
             } else {

Reply via email to