Search in sources :

Example 1 with EndpointSpec

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

Aggregations

DockerException (com.spotify.docker.client.exceptions.DockerException)1 EndpointSpec (com.spotify.docker.client.messages.swarm.EndpointSpec)1 Service (com.spotify.docker.client.messages.swarm.Service)1 TaskSpec (com.spotify.docker.client.messages.swarm.TaskSpec)1 TestFrameworkException (io.pravega.test.system.framework.TestFrameworkException)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1