Search in sources :

Example 1 with Service

use of com.spotify.docker.client.messages.swarm.Service in project pravega by pravega.

the class DockerBasedService method scaleService.

@Override
public CompletableFuture<Void> scaleService(final int instanceCount) {
    try {
        Preconditions.checkArgument(instanceCount >= 0, "negative value: %s", instanceCount);
        Service.Criteria criteria = Service.Criteria.builder().serviceName(this.serviceName).build();
        TaskSpec taskSpec = Exceptions.handleInterrupted(() -> dockerClient.listServices(criteria).get(0).spec().taskTemplate());
        String serviceId = Exceptions.handleInterrupted(() -> dockerClient.listServices(criteria).get(0).id());
        EndpointSpec endpointSpec = Exceptions.handleInterrupted(() -> dockerClient.inspectService(serviceId).spec().endpointSpec());
        Service service = Exceptions.handleInterrupted(() -> dockerClient.inspectService(serviceId));
        Exceptions.handleInterrupted(() -> dockerClient.updateService(serviceId, service.version().index(), ServiceSpec.builder().endpointSpec(endpointSpec).mode(ServiceMode.withReplicas(instanceCount)).taskTemplate(taskSpec).name(serviceName).build()));
        return Exceptions.handleInterrupted(() -> waitUntilServiceRunning());
    } catch (DockerException e) {
        throw new TestFrameworkException(TestFrameworkException.Type.RequestFailed, "Test failure: Unable to scale service to given instances=" + instanceCount, e);
    }
}
Also used : DockerException(com.spotify.docker.client.exceptions.DockerException) TestFrameworkException(io.pravega.test.system.framework.TestFrameworkException) TaskSpec(com.spotify.docker.client.messages.swarm.TaskSpec) EndpointSpec(com.spotify.docker.client.messages.swarm.EndpointSpec) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Service(com.spotify.docker.client.messages.swarm.Service)

Example 2 with Service

use of com.spotify.docker.client.messages.swarm.Service 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)

Example 3 with Service

use of com.spotify.docker.client.messages.swarm.Service in project pravega by pravega.

the class DockerBasedService method stop.

@Override
public void stop() {
    try {
        Service.Criteria criteria = Service.Criteria.builder().serviceName(this.serviceName).build();
        List<Service> serviceList = Exceptions.handleInterrupted(() -> dockerClient.listServices(criteria));
        for (int i = 0; i < serviceList.size(); i++) {
            String serviceId = serviceList.get(i).id();
            Exceptions.handleInterrupted(() -> dockerClient.removeService(serviceId));
        }
    } catch (DockerException e) {
        throw new TestFrameworkException(TestFrameworkException.Type.RequestFailed, "Unable to remove service.", e);
    }
}
Also used : DockerException(com.spotify.docker.client.exceptions.DockerException) TestFrameworkException(io.pravega.test.system.framework.TestFrameworkException) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Service(com.spotify.docker.client.messages.swarm.Service)

Example 4 with Service

use of com.spotify.docker.client.messages.swarm.Service in project pravega by pravega.

the class DockerBasedService method getID.

@Override
public String getID() {
    Service.Criteria criteria = Service.Criteria.builder().serviceName(this.serviceName).build();
    String serviceId = null;
    try {
        List<Service> serviceList = Exceptions.handleInterrupted(() -> dockerClient.listServices(criteria));
        serviceId = serviceList.get(0).id();
    } catch (DockerException e) {
        throw new TestFrameworkException(TestFrameworkException.Type.RequestFailed, "Unable to get service id", e);
    }
    return serviceId;
}
Also used : DockerException(com.spotify.docker.client.exceptions.DockerException) TestFrameworkException(io.pravega.test.system.framework.TestFrameworkException) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Service(com.spotify.docker.client.messages.swarm.Service)

Aggregations

DockerException (com.spotify.docker.client.exceptions.DockerException)4 Service (com.spotify.docker.client.messages.swarm.Service)4 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)4 TestFrameworkException (io.pravega.test.system.framework.TestFrameworkException)3 EndpointSpec (com.spotify.docker.client.messages.swarm.EndpointSpec)1 PortConfig (com.spotify.docker.client.messages.swarm.PortConfig)1 Task (com.spotify.docker.client.messages.swarm.Task)1 TaskSpec (com.spotify.docker.client.messages.swarm.TaskSpec)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1