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