throws InterruptedException {
final ServiceRegistration.Builder builder = ServiceRegistration.newBuilder();
for (final Map.Entry<ServiceEndpoint, ServicePorts> entry :
job.getRegistration().entrySet()) {
final ServiceEndpoint registration = entry.getKey();
final ServicePorts servicePorts = entry.getValue();
for (String portName : servicePorts.getPorts().keySet()) {
final PortMapping mapping = job.getPorts().get(portName);
if (mapping == null) {
log.error("no '{}' port mapped for registration: '{}'", portName, registration);
continue;
}
final Integer externalPort;
if (mapping.getExternalPort() != null) {
// Use the statically assigned port if one is specified
externalPort = mapping.getExternalPort();
} else {
// Otherwise use the dynamically allocated port
externalPort = ports.get(portName);
}
if (externalPort == null) {
log.error("no external '{}' port for registration: '{}'", portName, registration);
continue;
}
builder.endpoint(registration.getName(), registration.getProtocol(), externalPort,
fullyQualifiedRegistrationDomain(), host);
}
}
return builder.build();