You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by sj...@apache.org on 2014/12/03 16:55:58 UTC

[1/2] incubator-brooklyn git commit: BindDnsServer strips invalid characters from domain names

Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master c2451f3e3 -> 5de642ecf


BindDnsServer strips invalid characters from domain names

As per RFCs 952 and 1123.


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/e11b8f7b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/e11b8f7b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/e11b8f7b

Branch: refs/heads/master
Commit: e11b8f7bd9f359723dbe332aea8c24706a118dae
Parents: 0f2f632
Author: Sam Corbett <sa...@cloudsoftcorp.com>
Authored: Wed Dec 3 16:45:20 2014 +0100
Committer: Sam Corbett <sa...@cloudsoftcorp.com>
Committed: Wed Dec 3 16:45:20 2014 +0100

----------------------------------------------------------------------
 .../entity/network/bind/BindDnsServerImpl.java  | 26 ++++++++++-
 .../bind/BindDnsServerIntegrationTest.java      | 46 +++++++++++++++-----
 2 files changed, 59 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e11b8f7b/software/network/src/main/java/brooklyn/entity/network/bind/BindDnsServerImpl.java
----------------------------------------------------------------------
diff --git a/software/network/src/main/java/brooklyn/entity/network/bind/BindDnsServerImpl.java b/software/network/src/main/java/brooklyn/entity/network/bind/BindDnsServerImpl.java
index 5eb12a7..ccdb484 100644
--- a/software/network/src/main/java/brooklyn/entity/network/bind/BindDnsServerImpl.java
+++ b/software/network/src/main/java/brooklyn/entity/network/bind/BindDnsServerImpl.java
@@ -29,6 +29,8 @@ import java.util.Map;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.base.CharMatcher;
+import com.google.common.base.Function;
 import com.google.common.base.Joiner;
 import com.google.common.base.Predicate;
 import com.google.common.base.Splitter;
@@ -50,7 +52,6 @@ import com.google.common.collect.Multimaps;
 import brooklyn.entity.Entity;
 import brooklyn.entity.basic.Attributes;
 import brooklyn.entity.basic.DynamicGroup;
-import brooklyn.entity.basic.EntityFunctions;
 import brooklyn.entity.basic.Lifecycle;
 import brooklyn.entity.basic.SoftwareProcessImpl;
 import brooklyn.entity.group.AbstractMembershipTrackingPolicy;
@@ -73,6 +74,27 @@ public class BindDnsServerImpl extends SoftwareProcessImpl implements BindDnsSer
 
     private static final Logger LOG = LoggerFactory.getLogger(BindDnsServerImpl.class);
 
+    // As per RFC 952 and RFC 1123.
+    private static final CharMatcher DOMAIN_NAME_FIRST_CHAR_MATCHER = CharMatcher.inRange('a', 'z')
+                .or(CharMatcher.inRange('A', 'Z'))
+                .or(CharMatcher.inRange('0', '9'));
+    private static final CharMatcher DOMAIN_NAME_MATCHER = DOMAIN_NAME_FIRST_CHAR_MATCHER
+            .or(CharMatcher.is('-'));
+
+
+    private class HostnameTransformer implements Function<Entity, String> {
+        @Override
+        public String apply(Entity input) {
+            String hostname = input.getAttribute(getConfig(HOSTNAME_SENSOR));
+            hostname = DOMAIN_NAME_FIRST_CHAR_MATCHER.negate().trimFrom(hostname);
+            hostname = DOMAIN_NAME_MATCHER.negate().trimAndCollapseFrom(hostname, '-');
+            if (hostname.length() > 63) {
+                hostname = hostname.substring(0, 63);
+            }
+            return hostname;
+        }
+    }
+
     public BindDnsServerImpl() {
         super();
     }
@@ -222,7 +244,7 @@ public class BindDnsServerImpl extends SoftwareProcessImpl implements BindDnsSer
                     .filter(new HasHostnameAndValidLifecycle());
             LOG.debug("{} updating with entities: {}", this, Iterables.toString(availableEntities));
             ImmutableListMultimap<String, Entity> hostnameToEntity = Multimaps.index(availableEntities,
-                    EntityFunctions.attribute(getConfig(HOSTNAME_SENSOR)));
+                    new HostnameTransformer());
             Map<String, String> octetToName = Maps.newHashMap();
             BiMap<String, String> ipToARecord = HashBiMap.create();
             Multimap<String, String> aRecordToCnames = MultimapBuilder.hashKeys().arrayListValues().build();

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e11b8f7b/software/network/src/test/java/brooklyn/entity/network/bind/BindDnsServerIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/network/src/test/java/brooklyn/entity/network/bind/BindDnsServerIntegrationTest.java b/software/network/src/test/java/brooklyn/entity/network/bind/BindDnsServerIntegrationTest.java
index b6b9aba..d354e6e 100644
--- a/software/network/src/test/java/brooklyn/entity/network/bind/BindDnsServerIntegrationTest.java
+++ b/software/network/src/test/java/brooklyn/entity/network/bind/BindDnsServerIntegrationTest.java
@@ -24,26 +24,29 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.testng.annotations.Test;
 
+import com.google.common.base.Joiner;
+import com.google.common.base.Predicate;
+import com.google.common.base.Predicates;
+import com.google.common.base.Strings;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Iterables;
+
+import brooklyn.entity.Entity;
 import brooklyn.entity.basic.ApplicationBuilder;
 import brooklyn.entity.basic.Attributes;
 import brooklyn.entity.basic.EmptySoftwareProcess;
 import brooklyn.entity.basic.Entities;
+import brooklyn.entity.basic.EntityLocal;
+import brooklyn.entity.basic.EntityPredicates;
 import brooklyn.entity.group.DynamicCluster;
 import brooklyn.entity.proxying.EntitySpec;
 import brooklyn.entity.rebind.RebindOptions;
 import brooklyn.entity.rebind.RebindTestFixture;
-import brooklyn.location.LocationSpec;
-import brooklyn.location.basic.LocalhostMachineProvisioningLocation;
 import brooklyn.policy.EnricherSpec;
 import brooklyn.test.EntityTestUtils;
 import brooklyn.test.entity.TestApplication;
 
-import com.google.common.base.Joiner;
-import com.google.common.base.Predicate;
-import com.google.common.base.Predicates;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
-
 public class BindDnsServerIntegrationTest extends RebindTestFixture<TestApplication> {
 
     private static final Logger LOG = LoggerFactory.getLogger(BindDnsServerIntegrationTest.class);
@@ -67,9 +70,30 @@ public class BindDnsServerIntegrationTest extends RebindTestFixture<TestApplicat
     }
 
     @Test(groups = "Integration")
+    public void testStripsInvalidCharactersFromHostname() {
+        origApp.start(ImmutableList.of(origApp.newLocalhostProvisioningLocation()));
+        cluster.resize(1);
+        assertDnsEntityEventuallyHasActiveMembers(1);
+        EntityLocal e = (EntityLocal) Iterables.getOnlyElement(cluster.getMembers());
+        e.setAttribute(PrefixAndIdEnricher.SENSOR, " _-pretend.hostname.10.0.0.7.my-cloud.com");
+        EntityTestUtils.assertAttributeEqualsEventually(dns, BindDnsServer.A_RECORDS,
+                ImmutableMap.of("pretend-hostname-10-0-0-7-my-cloud-com", e.getAttribute(Attributes.ADDRESS)));
+    }
+
+    @Test(groups = "Integration")
+    public void testHostnameTruncatedTo63Characters() {
+        origApp.start(ImmutableList.of(origApp.newLocalhostProvisioningLocation()));
+        cluster.resize(1);
+        assertDnsEntityEventuallyHasActiveMembers(1);
+        EntityLocal e = (EntityLocal) Iterables.getOnlyElement(cluster.getMembers());
+        e.setAttribute(PrefixAndIdEnricher.SENSOR, Strings.repeat("a", 171));
+        EntityTestUtils.assertAttributeEqualsEventually(dns, BindDnsServer.A_RECORDS,
+                ImmutableMap.of(Strings.repeat("a", 63), e.getAttribute(Attributes.ADDRESS)));
+    }
+
+    @Test(groups = "Integration")
     public void testRebindDns() throws Throwable {
-        LocationSpec.create(LocalhostMachineProvisioningLocation.class);
-        origApp.start(ImmutableList.of(new LocalhostMachineProvisioningLocation()));
+        origApp.start(ImmutableList.of(origApp.newLocalhostProvisioningLocation()));
         logDnsMappings();
         assertEquals(dns.getAttribute(BindDnsServer.ADDRESS_MAPPINGS).keySet().size(), 1);
         assertMapSizes(3, 1, 2, 1);
@@ -103,7 +127,7 @@ public class BindDnsServerIntegrationTest extends RebindTestFixture<TestApplicat
 
     @Test(groups = "Integration")
     public void testMapsSeveralEntitiesOnOneMachine() {
-        origApp.start(ImmutableList.of(new LocalhostMachineProvisioningLocation()));
+        origApp.start(ImmutableList.of(origApp.newLocalhostProvisioningLocation()));
         EntityTestUtils.assertAttributeEqualsEventually(dns, Attributes.SERVICE_UP, true);
         logDnsMappings();
 


[2/2] incubator-brooklyn git commit: This closes #357

Posted by sj...@apache.org.
This closes #357


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/5de642ec
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/5de642ec
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/5de642ec

Branch: refs/heads/master
Commit: 5de642ecf18f8a3e1ef1593e475a9bcef321f2cb
Parents: c2451f3 e11b8f7
Author: Sam Corbett <sa...@cloudsoftcorp.com>
Authored: Wed Dec 3 16:54:39 2014 +0100
Committer: Sam Corbett <sa...@cloudsoftcorp.com>
Committed: Wed Dec 3 16:54:39 2014 +0100

----------------------------------------------------------------------
 .../entity/network/bind/BindDnsServerImpl.java  | 26 ++++++++++-
 .../bind/BindDnsServerIntegrationTest.java      | 46 +++++++++++++++-----
 2 files changed, 59 insertions(+), 13 deletions(-)
----------------------------------------------------------------------