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>
This commit is contained in:
Rohit Yadav 2017-12-06 16:05:41 +05:30 committed by Rohit Yadav
parent 02dee6a029
commit 260b523a4b
1 changed files with 13 additions and 4 deletions

View File

@ -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()));
}
}