in software/network/src/main/java/org/apache/brooklyn/entity/network/bind/BindDnsServerImpl.java [211:279]
public void update() {
Lifecycle serverState = getAttribute(Attributes.SERVICE_STATE_ACTUAL);
if (Lifecycle.STOPPED.equals(serverState) || Lifecycle.STOPPING.equals(serverState)
|| Lifecycle.DESTROYED.equals(serverState) || !getAttribute(Attributes.SERVICE_UP)) {
LOG.debug("Skipped update of {} when service state is {} and running is {}",
new Object[]{this, getAttribute(Attributes.SERVICE_STATE_ACTUAL), getAttribute(SERVICE_UP)});
return;
}
synchronized (this) {
Iterable<Entity> availableEntities = FluentIterable.from(getEntities().getMembers())
.filter(new HasHostnameAndValidLifecycle());
LOG.debug("{} updating with entities: {}", this, Iterables.toString(availableEntities));
ImmutableListMultimap<String, Entity> hostnameToEntity = Multimaps.index(availableEntities,
new HostnameTransformer());
Map<String, String> octetToName = Maps.newHashMap();
BiMap<String, String> ipToARecord = HashBiMap.create();
Multimap<String, String> aRecordToCnames = MultimapBuilder.hashKeys().hashSetValues().build();
Multimap<String, String> ipToAllNames = MultimapBuilder.hashKeys().hashSetValues().build();
for (Map.Entry<String, Entity> entry : hostnameToEntity.entries()) {
String domainName = entry.getKey();
Entity entity = entry.getValue();
String address = null;
AttributeSensor<String> addressSensor = getConfig(ADDRESS_SENSOR);
if (addressSensor!=null) {
address = entity.getAttribute(addressSensor);
} else {
if (!hasLoggedDeprecationAboutAddressSensor) {
LOG.warn("BIND entity "+this+" is using legacy machine inspection to determine IP address; set the "+ADDRESS_SENSOR.getName()+" config to ensure compatibility with future versions");
hasLoggedDeprecationAboutAddressSensor = true;
}
Maybe<SshMachineLocation> location = Machines.findUniqueMachineLocation(entity.getLocations(), SshMachineLocation.class);
if (!location.isPresent()) {
LOG.debug("Member {} of {} does not have an hostname so will not be configured", entity, this);
} else if (ipToARecord.inverse().containsKey(domainName)) {
// already has a hostname, ignore (could log if domain is different?)
} else {
address = location.get().getAddress().getHostAddress();
}
}
if (Strings.isBlank(address)) {
continue;
}
ipToAllNames.put(address, domainName);
if (!ipToARecord.containsKey(address)) {
ipToARecord.put(address, domainName);
if (getReverseLookupNetwork().contains(new Cidr(address + "/32"))) {
String octet = Iterables.get(Splitter.on('.').split(address), 3);
if (!octetToName.containsKey(octet)) octetToName.put(octet, domainName);
}
} else {
aRecordToCnames.put(ipToARecord.get(address), domainName);
}
}
sensors().set(A_RECORDS, ImmutableMap.copyOf(ipToARecord.inverse()));
sensors().set(PTR_RECORDS, ImmutableMap.copyOf(octetToName));
sensors().set(CNAME_RECORDS, Multimaps.unmodifiableMultimap(aRecordToCnames));
sensors().set(ADDRESS_MAPPINGS, Multimaps.unmodifiableMultimap(ipToAllNames));
// Update Bind configuration files and restart the service
getDriver().updateBindConfiguration();
}
}