in software/webapp/src/main/java/org/apache/brooklyn/entity/dns/AbstractGeoDnsServiceImpl.java [239:311]
protected boolean addTargetHost(Entity entity) {
try {
HostGeoInfo oldGeo = targetHosts.get(entity);
String hostname = inferHostname(entity);
String ip = inferIp(entity);
String addr = (getConfig(USE_HOSTNAMES) || ip == null) ? hostname : ip;
if (addr==null) addr = ip;
if (addr == null) {
if (entitiesWithoutHostname.add(entity)) {
log.debug("GeoDns ignoring {} (no hostname/ip/URL info yet available)", entity);
}
return false;
}
// prefer the geo from the entity (or location parent), but fall back to inferring
// e.g. if it supplies a URL
HostGeoInfo geo = HostGeoInfo.fromEntity(entity);
if (geo==null) geo = inferHostGeoInfo(hostname, ip);
if (Networking.isPrivateSubnet(addr) && ip!=null && !Networking.isPrivateSubnet(ip)) {
// fix for #1216
log.debug("GeoDns using IP "+ip+" for "+entity+" as addr "+addr+" resolves to private subnet");
addr = ip;
}
if (Networking.isPrivateSubnet(addr)) {
if (getConfig(INCLUDE_HOMELESS_ENTITIES)) {
if (entitiesWithoutGeoInfo.add(entity)) {
log.info("GeoDns including {}, even though {} is a private subnet (homeless entities included)", entity, addr);
}
} else {
if (entitiesWithoutGeoInfo.add(entity)) {
log.warn("GeoDns ignoring {} (private subnet detected for {})", entity, addr);
}
return false;
}
}
if (geo == null) {
if (getConfig(INCLUDE_HOMELESS_ENTITIES)) {
if (entitiesWithoutGeoInfo.add(entity)) {
log.info("GeoDns including {}, even though no geography info available for {})", entity, addr);
}
geo = HostGeoInfo.create(addr, "unknownLocation("+addr+")", 0, 0);
} else {
if (entitiesWithoutGeoInfo.add(entity)) {
log.warn("GeoDns ignoring {} (no geography info available for {})", entity, addr);
}
return false;
}
}
if (!addr.equals(geo.getAddress())) {
// if the location provider did not have an address, create a new one with it
geo = HostGeoInfo.create(addr, geo.displayName, geo.latitude, geo.longitude);
}
// If we already knew about it, and it hasn't changed, then nothing to do
if (oldGeo != null && geo.getAddress().equals(oldGeo.getAddress())) {
return false;
}
entitiesWithoutHostname.remove(entity);
entitiesWithoutGeoInfo.remove(entity);
log.info("GeoDns adding "+entity+" at "+geo+(oldGeo != null ? " (previously "+oldGeo+")" : ""));
targetHosts.put(entity, geo);
return true;
} catch (Exception ee) {
log.warn("GeoDns ignoring "+entity+" (error analysing location): "+ee, ee);
return false;
}
}