Skip to content

Commit

Permalink
Minor cleanup to the Marathon discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
cgray committed May 31, 2017
1 parent ce1ff21 commit 1ccd1f9
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,17 @@ private void constructMarathonClientConfigurationBuilderMap() {
public Collection<Instance> getInstanceList() throws Exception {
List<Instance> instances = new ArrayList<>();
marathonClientConfigurationBuilderMap.entrySet().parallelStream().forEach(entry -> {
Response response = entry.getValue().get();
if(response.getStatus() == HttpStatus.SC_OK) {
instances.addAll(createServiceInstanceList(response.readEntity(String.class), entry.getKey()));
Response response = null;
try {
response = entry.getValue().get();
if (response.getStatus() == HttpStatus.SC_OK) {
instances.addAll(createServiceInstanceList(response.readEntity(String.class), entry.getKey()));
}
} finally {
if (response != null) {
response.close();
}
}
response.close();
});
return instances;
}
Expand Down Expand Up @@ -80,9 +86,7 @@ public List<Instance> createServiceInstanceList(String marathonApiResponse,Marat

List<Task> tasks = marathonClientResponse.getApp().getTasks();
int finalPortIndex = portIndex;
List<Instance> instances = tasks.stream()
.map(task -> new Instance(task.getHost() + ":" + task.getPorts().get(finalPortIndex), marathonClientConfiguration.getCluster(), true)).collect(Collectors.toList());
return instances;
return tasks.stream().map(task -> new Instance(task.getHost() + ":" + task.getPorts().get(finalPortIndex), marathonClientConfiguration.getCluster(), true)).collect(Collectors.toList());
} else {
LOGGER.error("tasks not available for the given namespace");
return Collections.emptyList();
Expand Down

0 comments on commit 1ccd1f9

Please sign in to comment.