use of com.spotify.docker.client.messages.swarm.Task in project pravega by pravega.
the class DockerBasedService method getServiceDetails.
@Override
public List<URI> getServiceDetails() {
Service.Criteria criteria = Service.Criteria.builder().serviceName(this.serviceName).build();
List<URI> uriList = new ArrayList<>();
try {
Task.Criteria taskCriteria = Task.Criteria.builder().taskName(serviceName).build();
List<Task> taskList = Exceptions.handleInterrupted(() -> dockerClient.listTasks(taskCriteria));
log.info("Task size {}", taskList.size());
if (!taskList.isEmpty()) {
log.info("Network addresses {}", taskList.get(0).networkAttachments().get(0).addresses().get(0));
List<Service> serviceList = Exceptions.handleInterrupted(() -> dockerClient.listServices(criteria));
log.info("Service list size {}", serviceList.size());
for (int i = 0; i < taskList.size(); i++) {
log.info("task {}", taskList.get(i).name());
if (taskList.get(i).status().state().equals(TaskStatus.TASK_STATE_RUNNING)) {
String[] uriArray = taskList.get(i).networkAttachments().get(0).addresses().get(0).split("/");
ImmutableList<PortConfig> numPorts = Exceptions.handleInterrupted(() -> dockerClient.inspectService(serviceList.get(0).id()).endpoint().spec().ports());
for (int k = 0; k < numPorts.size(); k++) {
int port = numPorts.get(k).publishedPort();
log.info("Port {}", port);
log.info("Uri list {}", uriArray[0]);
URI uri = URI.create("tcp://" + uriArray[0] + ":" + port);
uriList.add(uri);
}
}
}
}
} catch (DockerException e) {
log.error("Unable to list service details", e);
}
return uriList;
}
Aggregations