@Override public List getNodes() throws MonitorException { List<ResourceNode> nodes = new Vector<ResourceNode>(); if (this.gmetaAdapters != null) { for (GangliaAdapter adapter : this.gmetaAdapters.values()) { Map<String, Map<String, String>> aNodes = adapter.getResourceNodeStatus(); for (Map<String, String> map : aNodes.values()) { try { nodes.add(this.nodeFromMap(map)); } catch (MalformedURLException e) { LOG.log(Level.SEVERE, e.getMessage()); throw new MonitorException(e.getMessage()); } } } } return nodes; }
private Map<String, String> locateNode(String nodeId) { if (this.gmetaAdapters != null && this.gmetaAdapters.size() > 0) { for (Map.Entry<String, GangliaAdapter> nId : this.gmetaAdapters.entrySet()) { GangliaAdapter adapter = nId.getValue(); try { System.out.println("Querying gmetad: [" + adapter.getUrlString() + "]"); Map<String, Map<String, String>> nodeStatus = adapter.getResourceNodeStatus(); System.out.println("Looking for nodeid: [" + nodeId + "]"); if (nodeStatus.containsKey(nodeId)) { System.out.println("NODE met: " + nodeStatus.get(nodeId)); return nodeStatus.get(nodeId); } } catch (MonitorException e) { LOG.log( Level.WARNING, "MonitorException contacting Ganglia: [" + adapter.getUrlString() + "]"); LOG.log(Level.SEVERE, e.getMessage()); } } } return null; }
@Override public ResourceNode getNodeByURL(URL ipAddr) throws MonitorException { if (this.gmetaAdapters != null) { for (GangliaAdapter adapter : this.gmetaAdapters.values()) { Map<String, Map<String, String>> aNodes = adapter.getResourceNodeStatus(); for (Map.Entry<String, Map<String, String>> aNodeId : aNodes.entrySet()) { String host = ipAddr.getHost(); int port = ipAddr.getPort(); Map<String, String> nodeProps = aNodeId.getValue(); if (aNodeId.getKey().equals(host) && nodeProps.get(DEFAULT_PORT).equals(String.valueOf(port))) { try { return this.nodeFromMap(aNodeId.getValue()); } catch (MalformedURLException e) { LOG.log(Level.SEVERE, e.getMessage()); throw new MonitorException(e.getMessage()); } } } } } return null; }