brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [7/8] brooklyn-server git commit: OnPublicNetworkEnricher: incorporate comments
Date Wed, 08 Jun 2016 20:23:37 GMT
OnPublicNetworkEnricher: incorporate comments

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

Branch: refs/heads/master
Commit: b3b89c87819a488f77d8ba91eea601a787a22b58
Parents: 70aceb3
Author: Aled Sage <aled.sage@gmail.com>
Authored: Wed Jun 8 21:19:01 2016 +0100
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Wed Jun 8 21:19:01 2016 +0100

----------------------------------------------------------------------
 .../core/network/OnPublicNetworkEnricher.java   | 10 ++++------
 .../network/OnPublicNetworkEnricherTest.java    | 21 ++++++++++++++++++++
 2 files changed, 25 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/b3b89c87/core/src/main/java/org/apache/brooklyn/core/network/OnPublicNetworkEnricher.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/network/OnPublicNetworkEnricher.java
b/core/src/main/java/org/apache/brooklyn/core/network/OnPublicNetworkEnricher.java
index 5013ebb..ca9e140 100644
--- a/core/src/main/java/org/apache/brooklyn/core/network/OnPublicNetworkEnricher.java
+++ b/core/src/main/java/org/apache/brooklyn/core/network/OnPublicNetworkEnricher.java
@@ -38,8 +38,6 @@ import org.apache.brooklyn.core.entity.AbstractEntity;
 import org.apache.brooklyn.core.location.Machines;
 import org.apache.brooklyn.core.location.access.PortForwardManager;
 import org.apache.brooklyn.core.location.access.PortForwardManagerLocationResolver;
-import org.apache.brooklyn.core.location.access.PortForwardManager.AssociationListener;
-import org.apache.brooklyn.core.location.access.PortForwardManager.AssociationMetadata;
 import org.apache.brooklyn.core.sensor.Sensors;
 import org.apache.brooklyn.util.core.flags.TypeCoercions;
 import org.apache.brooklyn.util.exceptions.Exceptions;
@@ -61,9 +59,9 @@ import com.google.common.reflect.TypeToken;
 
 /**
  * Can be added to an entity so that it advertises its mapped ports (according to the port-mappings
- * recorded in the PortForwardManager). This can be used with sensors of type URI, HostAndPort
+ * recorded in the {@link PortForwardManager}). This can be used with sensors of type URI,
HostAndPort
  * or plain integer port values. The port-mappings is retrieved by looking up the entity's
machine
- * and the private port, in the PortForwardManager's recorded port-mappings.
+ * and the private port, in the {@link PortForwardManager}'s recorded port-mappings.
  * 
  * For example, to configure each Tomcat node to publish its mapped uri, and to use that
sensor
  * in Nginx for the target servers:
@@ -77,7 +75,7 @@ import com.google.common.reflect.TypeToken;
  *      $brooklyn:entitySpec:
  *        type: org.apache.brooklyn.entity.webapp.tomcat.TomcatServer
  *        brooklyn.enrichers:
- *        - type: org.apache.brooklyn.core.location.access.PublicNetworkFaceEnricher
+ *        - type: org.apache.brooklyn.core.network.OnPublicNetworkEnricher
  *          brooklyn.config:
  *            sensor: main.uri
  * - type: org.apache.brooklyn.entity.proxy.nginx.NginxController
@@ -454,7 +452,7 @@ public class OnPublicNetworkEnricher extends AbstractEnricher {
         Maybe<Object> rawMapMatching = config().getRaw(MAP_MATCHING);
         String mapMatching = config().get(MAP_MATCHING);
         
-        if (sensor != null && sensors != null && sensors.isEmpty()) {
+        if (sensor != null && sensors != null && !sensors.isEmpty()) {
             throw new IllegalStateException(this+" must not have both 'sensor' and 'sensors'
config");
         } else if (sensor == null && (sensors == null || sensors.isEmpty())) {
             if (Strings.isBlank(mapMatching)) {

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/b3b89c87/core/src/test/java/org/apache/brooklyn/core/network/OnPublicNetworkEnricherTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/network/OnPublicNetworkEnricherTest.java
b/core/src/test/java/org/apache/brooklyn/core/network/OnPublicNetworkEnricherTest.java
index 354bd2f..0b1bb80 100644
--- a/core/src/test/java/org/apache/brooklyn/core/network/OnPublicNetworkEnricherTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/network/OnPublicNetworkEnricherTest.java
@@ -323,4 +323,25 @@ public class OnPublicNetworkEnricherTest extends BrooklynAppUnitTestSupport
{
             assertEquals(converter.apply(entry.getKey()), entry.getValue(), "input="+entry.getKey());
         }
     }
+    
+    @Test(expectedExceptions=IllegalStateException.class, expectedExceptionsMessageRegExp=".*must
not have both 'sensor' and 'sensors'.*")
+    public void testFailsIfSensorAndSensorsConfigured() throws Exception {
+        entity.enrichers().add(EnricherSpec.create(OnPublicNetworkEnricher.class)
+                .configure(OnPublicNetworkEnricher.SENSOR, Attributes.HTTP_PORT)
+                .configure(OnPublicNetworkEnricher.SENSORS, ImmutableList.of(Attributes.HTTPS_PORT)));
+    }
+    
+    @Test(expectedExceptions=IllegalStateException.class, expectedExceptionsMessageRegExp=".*must
not have explicit 'mapMatching', and either of 'sensor' or 'sensors'.*")
+    public void testFailsIfSensorAndMapMatchingConfigured() throws Exception {
+        entity.enrichers().add(EnricherSpec.create(OnPublicNetworkEnricher.class)
+                .configure(OnPublicNetworkEnricher.SENSOR, Attributes.HTTP_PORT)
+                .configure(OnPublicNetworkEnricher.MAP_MATCHING, ".*uri"));
+    }
+    
+    @Test(expectedExceptions=IllegalStateException.class, expectedExceptionsMessageRegExp=".*must
not have explicit 'mapMatching', and either of 'sensor' or 'sensors'.*")
+    public void testFailsIfSensorsAndMapMatchingConfigured() throws Exception {
+        entity.enrichers().add(EnricherSpec.create(OnPublicNetworkEnricher.class)
+                .configure(OnPublicNetworkEnricher.SENSORS, ImmutableList.of(Attributes.HTTPS_PORT))
+                .configure(OnPublicNetworkEnricher.MAP_MATCHING, ".*uri"));
+    }
 }


Mime
View raw message