public List<Agent> getAgents(List<String> groups) throws ServiceException { try { if (LOGGER.isDebugEnabled()) { LOGGER.debug("getAgents: groups=" + groups); } agentHeartbeatMapping = new HashMap<Agent, Heartbeat<Endpoint>>(); endpointAgentMapping = new HashMap<Endpoint, Agent>(); List<Agent> ret = new ArrayList<Agent>(); for (String group : groups) { List<Heartbeat<Endpoint>> beats = reader.list(group); for (Heartbeat<Endpoint> heartbeat : beats) { Agent agent = new Agent( heartbeat.getId(), heartbeat.getGroup(), heartbeat.getType(), heartbeat.getTags(), heartbeat.getData().getIdentifier()); agentHeartbeatMapping.put(agent, heartbeat); endpointAgentMapping.put(heartbeat.getData(), agent); ret.add(agent); if (LOGGER.isDebugEnabled()) { LOGGER.debug("getAgents: agent=" + agent); } } } if (LOGGER.isDebugEnabled()) { LOGGER.debug("getAgents: agent.size()=" + ret.size()); } return ret; } catch (Exception ex) { throw new ServiceException("Failed getting agents", ex); } }
private Endpoint getEndpoint(Agent agent) { if (agentHeartbeatMapping == null) { throw new RuntimeException("Agents not loaded"); } Heartbeat<Endpoint> heartbeat = agentHeartbeatMapping.get(agent); if (heartbeat == null) { throw new RuntimeException("No agent found: " + agent); } return heartbeat.getData(); }