use of com.spotify.docker.client.messages.swarm.PortConfig 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.PortConfig in project pravega by pravega.
the class HDFSDockerService method setServiceSpec.
private ServiceSpec setServiceSpec() {
Map<String, String> labels = new HashMap<>();
labels.put("com.docker.swarm.task.name", serviceName);
Mount mount = Mount.builder().type("volume").source("hadoop-logs-volume").target("/opt/hadoop/logs").build();
String env1 = "SSH_PORT=2222";
String env2 = "HDFS_HOST=" + serviceName;
final TaskSpec taskSpec = TaskSpec.builder().networks(NetworkAttachmentConfig.builder().target(DOCKER_NETWORK).aliases(serviceName).build()).containerSpec(ContainerSpec.builder().image(hdfsimage).env(Arrays.asList(env1, env2)).healthcheck(ContainerConfig.Healthcheck.create(null, Duration.ofSeconds(10).toNanos(), Duration.ofSeconds(10).toNanos(), 3)).mounts(mount).labels(labels).hostname(serviceName).build()).resources(ResourceRequirements.builder().reservations(Resources.builder().memoryBytes(setMemInBytes(mem)).nanoCpus(setNanoCpus(cpu)).build()).build()).build();
List<PortConfig> portConfigs = new ArrayList<>();
PortConfig port1 = PortConfig.builder().publishedPort(8020).targetPort(8020).publishMode(PortConfig.PortConfigPublishMode.HOST).name("hdfs").build();
PortConfig port2 = PortConfig.builder().publishedPort(50090).targetPort(50090).publishMode(PortConfig.PortConfigPublishMode.HOST).name("hdfs-secondary").build();
PortConfig port3 = PortConfig.builder().publishedPort(50010).targetPort(50010).publishMode(PortConfig.PortConfigPublishMode.HOST).name("hdfs-datanode").build();
PortConfig port4 = PortConfig.builder().publishedPort(50020).targetPort(50020).publishMode(PortConfig.PortConfigPublishMode.HOST).name("hdfs-datanode-ipc").build();
PortConfig port5 = PortConfig.builder().publishedPort(50075).targetPort(50075).publishMode(PortConfig.PortConfigPublishMode.HOST).name("hdfs-datanode-http").build();
PortConfig port6 = PortConfig.builder().publishedPort(50070).targetPort(50070).publishMode(PortConfig.PortConfigPublishMode.HOST).name("hdfs-web").build();
PortConfig port7 = PortConfig.builder().publishedPort(2222).targetPort(2222).publishMode(PortConfig.PortConfigPublishMode.HOST).name("hdfs-ssh").build();
portConfigs.add(port1);
portConfigs.add(port2);
portConfigs.add(port3);
portConfigs.add(port4);
portConfigs.add(port5);
portConfigs.add(port6);
portConfigs.add(port7);
ServiceSpec spec = ServiceSpec.builder().name(serviceName).taskTemplate(taskSpec).mode(ServiceMode.withReplicas(instances)).networks(NetworkAttachmentConfig.builder().target(DOCKER_NETWORK).aliases(serviceName).build()).endpointSpec(EndpointSpec.builder().ports(portConfigs).build()).build();
return spec;
}
Aggregations