Search in sources :

Example 1 with Task

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;
}
Also used : DockerException(com.spotify.docker.client.exceptions.DockerException) Task(com.spotify.docker.client.messages.swarm.Task) ArrayList(java.util.ArrayList) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Service(com.spotify.docker.client.messages.swarm.Service) URI(java.net.URI) PortConfig(com.spotify.docker.client.messages.swarm.PortConfig)

Aggregations

DockerException (com.spotify.docker.client.exceptions.DockerException)1 PortConfig (com.spotify.docker.client.messages.swarm.PortConfig)1 Service (com.spotify.docker.client.messages.swarm.Service)1 Task (com.spotify.docker.client.messages.swarm.Task)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1