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 <rohit.yadav@shapeblue.com>
diff --git a/plugins/metrics/src/org/apache/cloudstack/metrics/MetricsServiceImpl.java b/plugins/metrics/src/org/apache/cloudstack/metrics/MetricsServiceImpl.java
index 07edba2..67e3ac9 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 @@
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 @@
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()));
}
}