You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by sv...@apache.org on 2016/10/12 06:47:22 UTC
[1/3] brooklyn-server git commit: Adds
OnSubnetNetworkEnricherTest.testTransformWithDefaultPorts (broken)
Repository: brooklyn-server
Updated Branches:
refs/heads/master 01fe89134 -> a77b33878
Adds OnSubnetNetworkEnricherTest.testTransformWithDefaultPorts (broken)
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/ebbd3771
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/ebbd3771
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/ebbd3771
Branch: refs/heads/master
Commit: ebbd37710fecf90e2e5f1af1cb20987159d8c8b5
Parents: 01fe891
Author: Aled Sage <al...@gmail.com>
Authored: Tue Oct 11 22:56:36 2016 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Tue Oct 11 22:56:36 2016 +0100
----------------------------------------------------------------------
.../core/network/OnSubnetNetworkEnricherTest.java | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/ebbd3771/core/src/test/java/org/apache/brooklyn/core/network/OnSubnetNetworkEnricherTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/network/OnSubnetNetworkEnricherTest.java b/core/src/test/java/org/apache/brooklyn/core/network/OnSubnetNetworkEnricherTest.java
index 4f7dac5..0a896ab 100644
--- a/core/src/test/java/org/apache/brooklyn/core/network/OnSubnetNetworkEnricherTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/network/OnSubnetNetworkEnricherTest.java
@@ -196,6 +196,22 @@ public class OnSubnetNetworkEnricherTest extends BrooklynAppUnitTestSupport {
assertAttributeEqualsEventually("stringHostAndPort.endpoint.mapped.subnet", ""+privateIp+":1234");
}
+ @Test(groups="Broken")
+ public <T> void testTransformsWithDefaultPorts() throws Exception {
+ AttributeSensor<String> stringUriWithHttpNoPort = Sensors.newStringSensor("string.uriWithHttpNoPort");
+ AttributeSensor<String> stringUriWithHttpsNoPort = Sensors.newStringSensor("string.uriWithHttpsNoPort");
+
+ entity.sensors().set(Attributes.SUBNET_ADDRESS, privateIp);
+ entity.sensors().set(stringUriWithHttpNoPort, "http://"+publicIp+"/my/path");
+ entity.sensors().set(stringUriWithHttpsNoPort, "https://"+publicIp+"/my/path");
+ entity.addLocations(ImmutableList.of(machine));
+
+ entity.enrichers().add(EnricherSpec.create(OnSubnetNetworkEnricher.class));
+
+ assertAttributeEqualsEventually("string.uriWithHttpNoPort.mapped.subnet", "http://"+privateIp+"/my/path");
+ assertAttributeEqualsEventually("string.uriWithHttpsNoPort.mapped.subnet", "https://"+privateIp+"/my/path");
+ }
+
@Test
public <T> void testIgnoresNonMatchingSensors() throws Exception {
AttributeSensor<URI> sensor1 = Sensors.newSensor(URI.class, "my.different");
[3/3] brooklyn-server git commit: Closes #379
Posted by sv...@apache.org.
Closes #379
OnPublicNetworkEnricher config with sensor
I'm not entirely sure what the best way is to wire in and use the `OnPublicNetworkEnricher`. Two of the use-cases are:
1. in an environment with port-mappings (e.g. cloud's DNAT, or docker), look up the registered port mapping in the `PortForwardManager`. This is the existing behaviour.
2. Where a sensor (e.g. URI or hostAndPort) has been published with the subnet-address, publish an equivalent sensor using the public IP (so using the same port).
It is this second use-case that this PR enables.
For "normal clouds" (i.e. without DNAT), then option 2 is an obvious way to go. However:
* what if there isn't a public address? The "host.address" sensor would normally be populated with the private ip instead, so that would be used for the public url - but is that too misleading for a value of `main.uri.mapped.public`?
* what if there really is a DNAT rule set up for accessing this VM's port? Should our `OnPublicNetworkEnricher` prefer the DNAT rule (i.e. the entry in `PortForwardManager`) if it exists, but fall back to the "host.address" if it's not?
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/a77b3387
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/a77b3387
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/a77b3387
Branch: refs/heads/master
Commit: a77b338782c0241e1aa6f0c43e49f5af4c72efef
Parents: 01fe891 2a4e6ea
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Authored: Wed Oct 12 09:47:03 2016 +0300
Committer: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Committed: Wed Oct 12 09:47:03 2016 +0300
----------------------------------------------------------------------
.../core/network/OnPublicNetworkEnricher.java | 23 +++++++++-
.../network/OnPublicNetworkEnricherTest.java | 45 ++++++++++++++++++++
.../network/OnSubnetNetworkEnricherTest.java | 16 +++++++
3 files changed, 82 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
[2/3] brooklyn-server git commit: Adds
OnPublicNetworkEnricher.addressSensor config
Posted by sv...@apache.org.
Adds OnPublicNetworkEnricher.addressSensor config
If set, it will advertise the public address based on the IP/hostname
advertised in this sensor, rather than using he PortForwardManager.
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/2a4e6eac
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/2a4e6eac
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/2a4e6eac
Branch: refs/heads/master
Commit: 2a4e6eac6a330f4b7d16f2fb5b1653c519298b47
Parents: ebbd377
Author: Aled Sage <al...@gmail.com>
Authored: Tue Oct 11 22:57:57 2016 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Tue Oct 11 22:57:57 2016 +0100
----------------------------------------------------------------------
.../core/network/OnPublicNetworkEnricher.java | 23 +++++++++-
.../network/OnPublicNetworkEnricherTest.java | 45 ++++++++++++++++++++
2 files changed, 66 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/2a4e6eac/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 d37aa6d..878c1d5 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
@@ -21,11 +21,13 @@ package org.apache.brooklyn.core.network;
import org.apache.brooklyn.api.entity.Entity;
import org.apache.brooklyn.api.entity.EntityLocal;
import org.apache.brooklyn.api.location.MachineLocation;
+import org.apache.brooklyn.api.sensor.AttributeSensor;
import org.apache.brooklyn.config.ConfigKey;
import org.apache.brooklyn.core.config.ConfigKeys;
import org.apache.brooklyn.core.location.access.PortForwardManager;
import org.apache.brooklyn.core.location.access.PortForwardManagerLocationResolver;
import org.apache.brooklyn.util.guava.Maybe;
+import org.apache.brooklyn.util.text.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -34,6 +36,7 @@ import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.base.Predicates;
import com.google.common.net.HostAndPort;
+import com.google.common.reflect.TypeToken;
/**
* Can be added to an entity so that it advertises its mapped ports (according to the port-mappings
@@ -90,6 +93,12 @@ public class OnPublicNetworkEnricher extends AbstractOnNetworkEnricher {
"portForwardManager",
"The PortForwardManager storing the port-mappings; if null, the global instance will be used");
+ @SuppressWarnings("serial")
+ public static final ConfigKey<AttributeSensor<String>> ADDRESS_SENSOR = ConfigKeys.newConfigKey(
+ new TypeToken<AttributeSensor<String>>() {},
+ "addressSensor",
+ "The sensor to use to retrieve the entity's public address; if null (default), then use the PortForwardManager instead");
+
protected PortForwardManager.AssociationListener pfmListener;
@Override
@@ -137,8 +146,18 @@ public class OnPublicNetworkEnricher extends AbstractOnNetworkEnricher {
@Override
protected Optional<HostAndPort> getMappedEndpoint(Entity source, MachineLocation machine, int port) {
- HostAndPort publicTarget = getPortForwardManager().lookup(machine, port);
- return Optional.fromNullable(publicTarget);
+ AttributeSensor<String> sensor = config().get(ADDRESS_SENSOR);
+ if (sensor == null) {
+ HostAndPort publicTarget = getPortForwardManager().lookup(machine, port);
+ return Optional.fromNullable(publicTarget);
+ } else {
+ String address = source.sensors().get(sensor);
+ if (Strings.isNonBlank(address)) {
+ return Optional.of(HostAndPort.fromParts(address, port));
+ } else {
+ return Optional.absent();
+ }
+ }
}
protected PortForwardManager getPortForwardManager() {
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/2a4e6eac/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 f1c001b..3d5d3e0 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
@@ -303,6 +303,51 @@ public class OnPublicNetworkEnricherTest extends BrooklynAppUnitTestSupport {
}
@Test
+ public <T> void testTransformsToAddressInSensor() throws Exception {
+ AttributeSensor<String> stringUri = Sensors.newStringSensor("string.uri");
+
+ entity.sensors().set(Attributes.ADDRESS, "1.1.1.1");
+ entity.sensors().set(stringUri, "http://127.0.0.1:1234/my/path");
+ entity.addLocations(ImmutableList.of(machine));
+
+ entity.enrichers().add(EnricherSpec.create(OnPublicNetworkEnricher.class)
+ .configure(OnPublicNetworkEnricher.ADDRESS_SENSOR, Attributes.ADDRESS));
+
+ assertAttributeEqualsEventually("string.uri.mapped.public", "http://1.1.1.1:1234/my/path");
+ }
+
+ @Test
+ public <T> void testTransformsToAddressInSensorIsNoopIfSensorNull() throws Exception {
+ AttributeSensor<String> stringUri = Sensors.newStringSensor("string.uri");
+
+ entity.sensors().set(Attributes.ADDRESS, null);
+ entity.sensors().set(stringUri, "http://127.0.0.1:1234/my/path");
+ entity.addLocations(ImmutableList.of(machine));
+
+ entity.enrichers().add(EnricherSpec.create(OnPublicNetworkEnricher.class)
+ .configure(OnPublicNetworkEnricher.ADDRESS_SENSOR, Attributes.ADDRESS));
+
+ assertAttributeEqualsContinually("string.uri.mapped.public", null, Duration.millis(250));
+ }
+
+ @Test(groups="Broken")
+ public <T> void testTransformsToAddressInSensorWithDefaultPorts() throws Exception {
+ AttributeSensor<String> stringUriWithHttpNoPort = Sensors.newStringSensor("string.uriWithHttpNoPort");
+ AttributeSensor<String> stringUriWithHttpsNoPort = Sensors.newStringSensor("string.uriWithHttpsNoPort");
+
+ entity.sensors().set(Attributes.ADDRESS, "1.1.1.1");
+ entity.sensors().set(stringUriWithHttpNoPort, "http://127.0.0.1/my/path");
+ entity.sensors().set(stringUriWithHttpsNoPort, "https://127.0.0.1/my/path");
+ entity.addLocations(ImmutableList.of(machine));
+
+ entity.enrichers().add(EnricherSpec.create(OnPublicNetworkEnricher.class)
+ .configure(OnPublicNetworkEnricher.ADDRESS_SENSOR, Attributes.ADDRESS));
+
+ assertAttributeEqualsEventually("string.uriWithHttpNoPort.mapped.public", "http://1.1.1.1/my/path");
+ assertAttributeEqualsEventually("string.uriWithHttspNoPort.mapped.public", "https://1.1.1.1/my/path");
+ }
+
+ @Test
public <T> void testDoesNotDoRegexMatchingWhenSensorsSpecified() throws Exception {
AttributeSensor<String> sensor = Sensors.newStringSensor("mysensor");
AttributeSensor<Integer> intPort = Sensors.newIntegerSensor("int.port");