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);
}
}
Aggregations