brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sjcorb...@apache.org
Subject [7/9] incubator-brooklyn git commit: BindDnsServer handles entities that generate the same domain name
Date Fri, 09 Jan 2015 13:11:51 GMT
BindDnsServer handles entities that generate the same domain name

i.e. it prevents duplicate names appearing in A and CNAME records.


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

Branch: refs/heads/master
Commit: abcf43e8815b0ac9a74a5853dcd2205d1cf9f1b9
Parents: efbd2c4
Author: Sam Corbett <sam.corbett@cloudsoftcorp.com>
Authored: Thu Nov 27 19:12:57 2014 +0000
Committer: Sam Corbett <sam.corbett@cloudsoftcorp.com>
Committed: Wed Jan 7 17:15:22 2015 +0000

----------------------------------------------------------------------
 .../entity/network/bind/BindDnsServerImpl.java  |  8 ++-
 .../bind/BindDnsServerIntegrationTest.java      | 68 ++++++++++++++++++--
 2 files changed, 70 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/abcf43e8/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 abbb80f..f02d71a 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
@@ -213,10 +213,11 @@ public class BindDnsServerImpl extends SoftwareProcessImpl implements
BindDnsSer
             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().arrayListValues().build();
-            Multimap<String, String> ipToAllNames = MultimapBuilder.hashKeys().arrayListValues().build();
+            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();
@@ -224,7 +225,10 @@ public class BindDnsServerImpl extends SoftwareProcessImpl implements
BindDnsSer
                 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)) {
+                    continue;
                 }
+
                 String address = location.get().getAddress().getHostAddress();
                 ipToAllNames.put(address, domainName);
                 if (!ipToARecord.containsKey(address)) {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/abcf43e8/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 0305727..8aaf9f5 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,6 +24,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.testng.annotations.Test;
 
+import com.google.common.base.Functions;
 import com.google.common.base.Joiner;
 import com.google.common.base.Predicate;
 import com.google.common.base.Predicates;
@@ -32,6 +33,7 @@ import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Iterables;
 
+import brooklyn.enricher.Enrichers;
 import brooklyn.entity.Entity;
 import brooklyn.entity.basic.ApplicationBuilder;
 import brooklyn.entity.basic.Attributes;
@@ -70,6 +72,58 @@ public class BindDnsServerIntegrationTest extends RebindTestFixture<TestApplicat
     }
 
     @Test(groups = "Integration")
+    public void testOneARecordAndNoCnameRecordsWhenEntitiesHaveSameName() {
+        TestApplication app = ApplicationBuilder.newManagedApp(TestApplication.class, origManagementContext);
+        EnricherSpec<?> dnsEnricher = Enrichers.builder().transforming(Attributes.HOSTNAME)
+                .computing(Functions.constant("my-name"))
+                .publishing(PrefixAndIdEnricher.SENSOR)
+                .build();
+        EntitySpec<EmptySoftwareProcess> emptySoftwareProcessSpec = EntitySpec.create(EmptySoftwareProcess.class)
+                .enricher(dnsEnricher);
+        dns = app.createAndManageChild(EntitySpec.create(BindDnsServer.class, TestBindDnsServerImpl.class)
+                .configure(BindDnsServer.HOSTNAME_SENSOR, PrefixAndIdEnricher.SENSOR));
+
+        // App DNS will listen to
+        cluster = app.createAndManageChild(EntitySpec.create(DynamicCluster.class)
+                .configure(DynamicCluster.MEMBER_SPEC, emptySoftwareProcessSpec)
+                .configure(DynamicCluster.INITIAL_SIZE, 3));
+
+        app.start(ImmutableList.of(app.newLocalhostProvisioningLocation()));
+
+        assertDnsEntityEventuallyHasActiveMembers(1);
+        // All of the entities publish the same domain name so there should be a single DNS
entry and no CNAMEs.
+        assertMapSizes(1, 1, 0, 1);
+    }
+
+    @Test(groups = "Integration")
+    public void testDuplicateAAndCnameRecordsAreIgnored() {
+        TestApplication app = ApplicationBuilder.newManagedApp(TestApplication.class, origManagementContext);
+        EnricherSpec<?> enricher1 = Enrichers.builder().transforming(Attributes.HOSTNAME)
+                .computing(Functions.constant("my-name-1"))
+                .publishing(PrefixAndIdEnricher.SENSOR)
+                .build();
+        EnricherSpec<?> enricher2 = Enrichers.builder().transforming(Attributes.HOSTNAME)
+                .computing(Functions.constant("my-name-2"))
+                .publishing(PrefixAndIdEnricher.SENSOR)
+                .build();
+        dns = app.createAndManageChild(EntitySpec.create(BindDnsServer.class, TestBindDnsServerImpl.class)
+                .configure(BindDnsServer.HOSTNAME_SENSOR, PrefixAndIdEnricher.SENSOR));
+
+        // Expect one of my-name-{1,2} to be used as the A record the other to be used as
the CNAME.
+        // Expect all duplicate records to be ignored.
+        app.createAndManageChild(EntitySpec.create(EmptySoftwareProcess.class).enricher(enricher1));
+        app.createAndManageChild(EntitySpec.create(EmptySoftwareProcess.class).enricher(enricher1));
+        app.createAndManageChild(EntitySpec.create(EmptySoftwareProcess.class).enricher(enricher1));
+        app.createAndManageChild(EntitySpec.create(EmptySoftwareProcess.class).enricher(enricher2));
+        app.createAndManageChild(EntitySpec.create(EmptySoftwareProcess.class).enricher(enricher2));
+        app.createAndManageChild(EntitySpec.create(EmptySoftwareProcess.class).enricher(enricher2));
+        app.start(ImmutableList.of(app.newLocalhostProvisioningLocation()));
+
+        assertDnsEntityEventuallyHasActiveMembers(2);
+        assertMapSizes(2, 1, 1, 1);
+    }
+
+    @Test(groups = "Integration")
     public void testStripsInvalidCharactersFromHostname() {
         origApp.start(ImmutableList.of(origApp.newLocalhostProvisioningLocation()));
         cluster.resize(1);
@@ -122,6 +176,12 @@ public class BindDnsServerIntegrationTest extends RebindTestFixture<TestApplicat
         logDnsMappings();
         assertEquals(dns.getAttribute(BindDnsServer.ADDRESS_MAPPINGS).keySet().size(), 1);
         assertMapSizes(3, 1, 2, 1);
+
+        cluster.resize(4);
+        EntityTestUtils.assertAttributeEqualsEventually(cluster, DynamicCluster.GROUP_SIZE,
4);
+        assertDnsEntityEventuallyHasActiveMembers(4);
+        assertMapSizes(4, 1, 3, 1);
+
     }
 
     @Test(invocationCount=1, groups = "Integration")
@@ -174,10 +234,10 @@ public class BindDnsServerIntegrationTest extends RebindTestFixture<TestApplicat
     }
 
     private void assertMapSizes(int addresses, int aRecords, int cnameRecords, int ptrRecords)
{
-        assertEquals(dns.getAttribute(BindDnsServer.ADDRESS_MAPPINGS).entries().size(), addresses);
-        assertEquals(dns.getAttribute(BindDnsServer.A_RECORDS).size(), aRecords);
-        assertEquals(dns.getAttribute(BindDnsServer.CNAME_RECORDS).size(), cnameRecords);
-        assertEquals(dns.getAttribute(BindDnsServer.PTR_RECORDS).size(), ptrRecords);
+        assertEquals(dns.getAttribute(BindDnsServer.ADDRESS_MAPPINGS).entries().size(), addresses,
"Mismatched address mappings");
+        assertEquals(dns.getAttribute(BindDnsServer.A_RECORDS).size(), aRecords, "Mismatched
A records");
+        assertEquals(dns.getAttribute(BindDnsServer.CNAME_RECORDS).size(), cnameRecords,
"Mismatched CNAME records");
+        assertEquals(dns.getAttribute(BindDnsServer.PTR_RECORDS).size(), ptrRecords, "Mismatched
PTR records");
     }
 
     private void logDnsMappings() {


Mime
View raw message