package io.hops.hopsworks.kmon.cluster;

import io.hops.hopsworks.common.dao.kagent.HostServices;
import io.hops.hopsworks.common.dao.kagent.HostServicesFacade;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import io.hops.hopsworks.kmon.struct.ClusterInfo;

@ManagedBean
@RequestScoped
public class ClustersController {

  @EJB
  private HostServicesFacade hostServicesFacade;
  private static final Logger LOGGER = Logger.getLogger(ClustersController.class.getName());
  private List<ClusterInfo> clusters;

  public ClustersController() {
  }

  @PostConstruct
  public void init() {
    LOGGER.info("init ClustersController");
    clusters = new ArrayList<>();
    loadClusters();
  }

  public List<ClusterInfo> getClusters() {
    return clusters;
  }

  private void loadClusters() {
    for (String cluster : hostServicesFacade.findClusters()) {
      ClusterInfo clusterInfo = new ClusterInfo(cluster);
      clusterInfo.setNumberOfHosts(hostServicesFacade.countHosts(cluster));
      clusterInfo.setTotalCores(hostServicesFacade.totalCores(cluster));
      clusterInfo.setTotalMemoryCapacity(hostServicesFacade.totalMemoryCapacity(cluster));
      clusterInfo.setTotalDiskCapacity(hostServicesFacade.totalDiskCapacity(cluster));
      clusterInfo.addServices(hostServicesFacade.findHostServicesByCluster(cluster));
      clusters.add(clusterInfo);
    }
  }
 
  public String getNameNodesString() {
    String hosts = "";
    List<HostServices> hostServices = hostServicesFacade.findServices("namenode");
    if (hostServices != null && !hostServices.isEmpty()) {
      hosts = hosts + hostServices.get(0).getHost();
      for (int i = 1; i < hostServices.size(); i++) {
        hosts = hosts + "," + hostServices.get(i).getHost();
      }
    }
    return hosts;
  }
}

@@ -1586,16 +1586,23 @@
   String
+Builder
  hosts =
@@ -1606,10 +1606,27 @@
 s = 
-%22%22
+new StringBuilder()
 ;%0A  
@@ -1776,27 +1776,24 @@
    hosts
- = hosts + 
+.append(
 hostServ
@@ -1805,32 +1805,47 @@
 get(0).getHost()
+.getHostname())
 ;%0A      for (int
@@ -1901,25 +1901,28 @@
 osts
- = hosts + %22,%22 + 
+.append(%22,%22).append(
 host
@@ -1946,16 +1946,31 @@
 etHost()
+.getHostname())
 ;%0A      
@@ -1993,16 +1993,27 @@
 rn hosts
+.toString()
 ;%0A  %7D%0A%7D%0A

Fix namenode metrics collection/visualisation (#860)