support configurable addresses
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-library/repo Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-library/commit/bbdda166 Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-library/tree/bbdda166 Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-library/diff/bbdda166 Branch: refs/heads/master Commit: bbdda166fdb4debdd83abf5c6a4fce9e95a6d5b2 Parents: 54db83d Author: Alex Heneveld <[email protected]> Authored: Thu Aug 25 16:44:02 2016 +0100 Committer: Alex Heneveld <[email protected]> Committed: Thu Aug 25 23:09:45 2016 +0100 ---------------------------------------------------------------------- .../entity/network/bind/BindDnsServer.java | 21 ++++++--- .../entity/network/bind/BindDnsServerImpl.java | 45 +++++++++++++++----- 2 files changed, 49 insertions(+), 17 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/brooklyn-library/blob/bbdda166/software/network/src/main/java/org/apache/brooklyn/entity/network/bind/BindDnsServer.java ---------------------------------------------------------------------- diff --git a/software/network/src/main/java/org/apache/brooklyn/entity/network/bind/BindDnsServer.java b/software/network/src/main/java/org/apache/brooklyn/entity/network/bind/BindDnsServer.java index 54754cb..3f3d30b 100644 --- a/software/network/src/main/java/org/apache/brooklyn/entity/network/bind/BindDnsServer.java +++ b/software/network/src/main/java/org/apache/brooklyn/entity/network/bind/BindDnsServer.java @@ -20,11 +20,6 @@ package org.apache.brooklyn.entity.network.bind; import java.util.Map; -import com.google.common.base.Predicate; -import com.google.common.base.Predicates; -import com.google.common.collect.Multimap; -import com.google.common.reflect.TypeToken; - import org.apache.brooklyn.api.catalog.Catalog; import org.apache.brooklyn.api.entity.Entity; import org.apache.brooklyn.api.entity.ImplementedBy; @@ -32,6 +27,7 @@ import org.apache.brooklyn.api.sensor.AttributeSensor; import org.apache.brooklyn.config.ConfigKey; import org.apache.brooklyn.core.annotation.Effector; import org.apache.brooklyn.core.config.ConfigKeys; +import org.apache.brooklyn.core.entity.Attributes; import org.apache.brooklyn.core.location.PortRanges; import org.apache.brooklyn.core.sensor.PortAttributeSensorAndConfigKey; import org.apache.brooklyn.core.sensor.Sensors; @@ -40,6 +36,11 @@ import org.apache.brooklyn.entity.software.base.SoftwareProcess; import org.apache.brooklyn.util.core.flags.SetFromFlag; import org.apache.brooklyn.util.net.Cidr; +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; +import com.google.common.collect.Multimap; +import com.google.common.reflect.TypeToken; + /** * This sets up a BIND DNS server. */ @@ -67,7 +68,15 @@ public interface BindDnsServer extends SoftwareProcess { @SetFromFlag("hostnameSensor") ConfigKey<AttributeSensor<String>> HOSTNAME_SENSOR = ConfigKeys.newConfigKey(new TypeToken<AttributeSensor<String>>() {}, - "bind.sensor.hostname", "Sensor on managed entities that reports the hostname"); + "bind.sensor.hostname", "Sensor on managed entities that reports the basename for the hostname"); + + @SetFromFlag("addressSensor") + ConfigKey<AttributeSensor<String>> ADDRESS_SENSOR = ConfigKeys.newConfigKey(new TypeToken<AttributeSensor<String>>() {}, + "bind.sensor.address", "Sensor on managed entities that reports the address to register;" + + " host.address or host.subnet.address are common choices;" + + " blank (deprecated default behaviour) will inspect machines attached to entities" + + " but for legacy compatibility only; blueprints should set this"); + // TODO in future might want to change default to Attributes.ADDRESS (and lose the "inspect machines" default behaviour) PortAttributeSensorAndConfigKey DNS_PORT = new PortAttributeSensorAndConfigKey("bind.port", "BIND DNS port for TCP and UDP", PortRanges.fromString("53")); http://git-wip-us.apache.org/repos/asf/brooklyn-library/blob/bbdda166/software/network/src/main/java/org/apache/brooklyn/entity/network/bind/BindDnsServerImpl.java ---------------------------------------------------------------------- diff --git a/software/network/src/main/java/org/apache/brooklyn/entity/network/bind/BindDnsServerImpl.java b/software/network/src/main/java/org/apache/brooklyn/entity/network/bind/BindDnsServerImpl.java index 834a371..ef53bc4 100644 --- a/software/network/src/main/java/org/apache/brooklyn/entity/network/bind/BindDnsServerImpl.java +++ b/software/network/src/main/java/org/apache/brooklyn/entity/network/bind/BindDnsServerImpl.java @@ -28,6 +28,7 @@ import java.util.Map; import org.apache.brooklyn.api.entity.Entity; import org.apache.brooklyn.api.entity.EntitySpec; import org.apache.brooklyn.api.policy.PolicySpec; +import org.apache.brooklyn.api.sensor.AttributeSensor; import org.apache.brooklyn.api.sensor.Sensor; import org.apache.brooklyn.core.entity.Attributes; import org.apache.brooklyn.core.entity.lifecycle.Lifecycle; @@ -105,6 +106,7 @@ public class BindDnsServerImpl extends SoftwareProcessImpl implements BindDnsSer super.init(); checkNotNull(getConfig(HOSTNAME_SENSOR), "%s requires value for %s", getClass().getName(), HOSTNAME_SENSOR); DynamicGroup entities = addChild(EntitySpec.create(DynamicGroup.class) + .displayName("BIND-managed entities") .configure(DynamicGroup.ENTITY_FILTER, getEntityFilter())); sensors().set(ENTITIES, entities); sensors().set(A_RECORDS, ImmutableMap.<String, String>of()); @@ -163,7 +165,7 @@ public class BindDnsServerImpl extends SoftwareProcessImpl implements BindDnsSer policies().add(PolicySpec.create(MemberTrackingPolicy.class) .displayName("Address tracker") - .configure(AbstractMembershipTrackingPolicy.SENSORS_TO_TRACK, ImmutableSet.<Sensor<?>>of(getConfig(HOSTNAME_SENSOR))) + .configure(AbstractMembershipTrackingPolicy.SENSORS_TO_TRACK, ImmutableSet.<Sensor<?>>of(getConfig(HOSTNAME_SENSOR), getConfig(ADDRESS_SENSOR))) .configure(AbstractMembershipTrackingPolicy.GROUP, getEntities())); } @@ -197,11 +199,14 @@ public class BindDnsServerImpl extends SoftwareProcessImpl implements BindDnsSer case STOPPING: case DESTROYED: return false; + default: + return input.getAttribute(getConfig(HOSTNAME_SENSOR)) != null; } - return input.getAttribute(getConfig(HOSTNAME_SENSOR)) != null; } } + private transient boolean hasLoggedDeprecationAboutAddressSensor = false; + public void update() { Lifecycle serverState = getAttribute(Attributes.SERVICE_STATE_ACTUAL); if (Lifecycle.STOPPED.equals(serverState) || Lifecycle.STOPPING.equals(serverState) @@ -222,17 +227,35 @@ public class BindDnsServerImpl extends SoftwareProcessImpl implements BindDnsSer Multimap<String, String> aRecordToCnames = MultimapBuilder.hashKeys().hashSetValues().build(); Multimap<String, String> ipToAllNames = MultimapBuilder.hashKeys().hashSetValues().build(); - for (Map.Entry<String, Entity> e : hostnameToEntity.entries()) { - String domainName = e.getKey(); - Maybe<SshMachineLocation> location = Machines.findUniqueMachineLocation(e.getValue().getLocations(), SshMachineLocation.class); - if (!location.isPresent()) { - LOG.debug("Member {} of {} does not have an SSH location so will not be configured", e.getValue(), this); - continue; - } else if (ipToARecord.inverse().containsKey(domainName)) { + 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; } - - String address = location.get().getAddress().getHostAddress(); + ipToAllNames.put(address, domainName); if (!ipToARecord.containsKey(address)) { ipToARecord.put(address, domainName);
