@Override
public List<Instance> listAgents()
{
ImmutableList.Builder<Instance> instances = ImmutableList.builder();
for (Entry<String, String> entry : agents.entrySet()) {
String instanceId = entry.getKey();
String agentUri = entry.getValue();
URI uri = UriBuilder.fromUri(agentUri).path("/v1/agent").build();
Request request = RequestBuilder.prepareGet()
.setUri(uri)
.build();
try {
AgentStatusRepresentation agent = httpClient.execute(request, createJsonResponseHandler(agentCodec));
instances.add(new Instance(instanceId,
firstNonNull(agent.getInstanceType(), "unknown"),
firstNonNull(agent.getLocation(), "/static/" + uri.getHost() + "/agent"),
agent.getSelf(),
agent.getExternalUri()));
}
catch (Exception e) {
instances.add(new Instance(instanceId,
"unknown",
"/static/" + uri.getHost() + "/agent",
uri,
uri));
}
}
return ImmutableList.copyOf(instances.build());
}