From 260b523a4b47baf5d94bcd9c5f81c8d56accb151 Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Wed, 6 Dec 2017 16:05:41 +0530 Subject: [PATCH] APPLE-512: Use host table to iterate for zone/cluster metrics (CW-1592) Per Ilya's reply, host_view may contain duplicate entries when hosts have tags. Changing the host_view may cause unseen regressions so to fix the issues we've modified the zone/cluster metrics code to use the `host` table (hostdao) to iterate through the list of hosts in a cluster during zone/cluster metrics listing. Signed-off-by: Rohit Yadav --- .../cloudstack/metrics/MetricsServiceImpl.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/plugins/metrics/src/org/apache/cloudstack/metrics/MetricsServiceImpl.java b/plugins/metrics/src/org/apache/cloudstack/metrics/MetricsServiceImpl.java index 07edba20c23..67e3ac910ed 100644 --- a/plugins/metrics/src/org/apache/cloudstack/metrics/MetricsServiceImpl.java +++ b/plugins/metrics/src/org/apache/cloudstack/metrics/MetricsServiceImpl.java @@ -321,12 +321,15 @@ public class MetricsServiceImpl extends ComponentLifecycleBase implements Metric final CapacityDaoImpl.SummedCapacity memoryCapacity = getCapacity((int) Capacity.CAPACITY_TYPE_MEMORY, null, clusterId); final Metrics metrics = new Metrics(cpuCapacity, memoryCapacity); - for (final HostJoinVO host: hostJoinDao.findByClusterId(clusterId, Host.Type.Routing)) { + for (final Host host: hostDao.findByClusterId(clusterId)) { + if (host == null || host.getType() != Host.Type.Routing) { + continue; + } if (host.getStatus() == Status.Up) { metrics.incrUpResources(); } metrics.incrTotalResources(); - updateHostMetrics(metrics, host); + updateHostMetrics(metrics, hostJoinDao.findById(host.getId())); } metricsResponse.setState(clusterResponse.getAllocationState(), clusterResponse.getManagedState()); @@ -391,14 +394,20 @@ public class MetricsServiceImpl extends ComponentLifecycleBase implements Metric final Metrics metrics = new Metrics(cpuCapacity, memoryCapacity); for (final Cluster cluster : clusterDao.listClustersByDcId(zoneId)) { + if (cluster == null) { + continue; + } metrics.incrTotalResources(); if (cluster.getAllocationState() == Grouping.AllocationState.Enabled && cluster.getManagedState() == Managed.ManagedState.Managed) { metrics.incrUpResources(); } - for (final HostJoinVO host: hostJoinDao.findByClusterId(cluster.getId(), Host.Type.Routing)) { - updateHostMetrics(metrics, host); + for (final Host host: hostDao.findByClusterId(cluster.getId())) { + if (host == null || host.getType() != Host.Type.Routing) { + continue; + } + updateHostMetrics(metrics, hostJoinDao.findById(host.getId())); } }