[GitHub] brooklyn-server pull request #192: Adds OnSubnetNetworkEnricher

2016-06-10 Thread neykov
Github user neykov commented on a diff in the pull request:

https://github.com/apache/brooklyn-server/pull/192#discussion_r66622693
  
--- Diff: 
core/src/main/java/org/apache/brooklyn/core/network/AbstractOnNetworkEnricher.java
 ---
@@ -0,0 +1,402 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.core.network;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Collection;
+
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.entity.EntityLocal;
+import org.apache.brooklyn.api.location.Location;
+import org.apache.brooklyn.api.location.MachineLocation;
+import org.apache.brooklyn.api.sensor.AttributeSensor;
+import org.apache.brooklyn.api.sensor.Sensor;
+import org.apache.brooklyn.api.sensor.SensorEvent;
+import org.apache.brooklyn.api.sensor.SensorEventListener;
+import org.apache.brooklyn.config.ConfigKey;
+import org.apache.brooklyn.core.config.ConfigKeys;
+import org.apache.brooklyn.core.enricher.AbstractEnricher;
+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.sensor.Sensors;
+import org.apache.brooklyn.util.core.flags.TypeCoercions;
+import org.apache.brooklyn.util.exceptions.Exceptions;
+import org.apache.brooklyn.util.guava.Maybe;
+import org.apache.brooklyn.util.net.Networking;
+import org.apache.brooklyn.util.text.StringPredicates;
+import org.apache.brooklyn.util.text.Strings;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.Function;
+import com.google.common.base.Optional;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Lists;
+import com.google.common.net.HostAndPort;
+import com.google.common.reflect.TypeToken;
+
+@Beta
+public abstract class AbstractOnNetworkEnricher extends AbstractEnricher {
+
+private static final Logger LOG = 
LoggerFactory.getLogger(AbstractOnNetworkEnricher.class);
+
+@SuppressWarnings("serial")
+public static ConfigKey>> 
SENSORS = ConfigKeys.newConfigKey(
+new TypeToken>>() {}, 
+"sensors",
+"The multiple sensors whose mapped values are to be 
re-published (with suffix \"mapped.networkName\"); "
++ "if 'sensors' is not specified, defaults to 
'mapMatching'");
+
+public static ConfigKey MAP_MATCHING = 
ConfigKeys.newStringConfigKey(
+"mapMatching",
+"Whether to map all, based on a sensor naming convention 
(re-published with suffix \"mapped.networkName\"); "
++ "if 'sensors' is not specified, defaults to matching 
case-insensitive suffix of "
++ "'port', 'uri', 'url', 'endpoint' or 'hostAndPort'",
+"(?i)(.+\\.)?(port|uri|url|endpoint|hostandport)");
+
+@SuppressWarnings("serial")
+public static ConfigKey> 
SENSOR_NAME_CONVERTER = ConfigKeys.newConfigKey(
+new TypeToken>() {},
+"sensorNameConverter",
+"The converter to use, to map from the original sensor name to 
the re-published sensor name");
+
+public static class SensorNameConverter implements Function {
+private final String network;
+
+public SensorNameConverter(String network) {
+this.network = network;
+}
+
+@Override
+public String apply(String input) {
+if (input == null) throw new NullPointerException("Sensor name 
must not be null");
+String lowerInput = input.toLowerCase();
+if (lowerInput.endsWith("uri")) {
+return input + ".mapped." + network;
+} els

[GitHub] brooklyn-server pull request #192: Adds OnSubnetNetworkEnricher

2016-06-10 Thread neykov
Github user neykov commented on a diff in the pull request:

https://github.com/apache/brooklyn-server/pull/192#discussion_r66622079
  
--- Diff: 
core/src/main/java/org/apache/brooklyn/core/network/AbstractOnNetworkEnricher.java
 ---
@@ -0,0 +1,407 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.core.network;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Collection;
+
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.entity.EntityLocal;
+import org.apache.brooklyn.api.location.Location;
+import org.apache.brooklyn.api.location.MachineLocation;
+import org.apache.brooklyn.api.sensor.AttributeSensor;
+import org.apache.brooklyn.api.sensor.Sensor;
+import org.apache.brooklyn.api.sensor.SensorEvent;
+import org.apache.brooklyn.api.sensor.SensorEventListener;
+import org.apache.brooklyn.config.ConfigKey;
+import org.apache.brooklyn.core.config.ConfigKeys;
+import org.apache.brooklyn.core.enricher.AbstractEnricher;
+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.sensor.Sensors;
+import org.apache.brooklyn.util.core.flags.TypeCoercions;
+import org.apache.brooklyn.util.exceptions.Exceptions;
+import org.apache.brooklyn.util.guava.Maybe;
+import org.apache.brooklyn.util.net.Networking;
+import org.apache.brooklyn.util.text.StringPredicates;
+import org.apache.brooklyn.util.text.Strings;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.Function;
+import com.google.common.base.Optional;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Lists;
+import com.google.common.net.HostAndPort;
+import com.google.common.reflect.TypeToken;
+
+@Beta
+public abstract class AbstractOnNetworkEnricher extends AbstractEnricher {
+
+private static final Logger LOG = 
LoggerFactory.getLogger(AbstractOnNetworkEnricher.class);
+
+@SuppressWarnings("serial")
+public static final ConfigKey> SENSOR = 
ConfigKeys.newConfigKey(
+new TypeToken>() {}, 
+"sensor",
+"The sensor whose mapped value is to be re-published (with 
suffix \"mapped.networkName\"); "
++ "either 'sensor' or 'sensors' should be specified");
+
+@SuppressWarnings("serial")
+public static ConfigKey>> 
SENSORS = ConfigKeys.newConfigKey(
+new TypeToken>>() {}, 
+"sensors",
+"The multiple sensors whose mapped values are to be 
re-published (with suffix \"mapped.networkName\"); "
++ "if neither 'sensor' or 'sensors' is specified, 
defaults to 'mapAll'");
+
+public static ConfigKey MAP_MATCHING = 
ConfigKeys.newStringConfigKey(
+"mapMatching",
+"Whether to map all, based on a sensor naming convention 
(re-published with suffix \"mapped.networkName\"); "
++ "if neither 'sensor' or 'sensors' is specified, 
defaults to matchin case-insensitive suffix of "
++ "'port', 'uri', 'url' or 'endpoint' ",
+"(?i).*(port|uri|url|endpoint)");
--- End diff --

It does, but that rules out sensors like `httpPort` which are used in the 
wild. Perhaps we should standardize on the sensor naming instead.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] brooklyn-server pull request #192: Adds OnSubnetNetworkEnricher

2016-06-10 Thread asfgit
Github user asfgit closed the pull request at:

https://github.com/apache/brooklyn-server/pull/192


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] brooklyn-server pull request #192: Adds OnSubnetNetworkEnricher

2016-06-10 Thread Graeme-Miller
Github user Graeme-Miller commented on a diff in the pull request:

https://github.com/apache/brooklyn-server/pull/192#discussion_r66616715
  
--- Diff: 
core/src/main/java/org/apache/brooklyn/core/network/AbstractOnNetworkEnricher.java
 ---
@@ -0,0 +1,407 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.core.network;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Collection;
+
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.entity.EntityLocal;
+import org.apache.brooklyn.api.location.Location;
+import org.apache.brooklyn.api.location.MachineLocation;
+import org.apache.brooklyn.api.sensor.AttributeSensor;
+import org.apache.brooklyn.api.sensor.Sensor;
+import org.apache.brooklyn.api.sensor.SensorEvent;
+import org.apache.brooklyn.api.sensor.SensorEventListener;
+import org.apache.brooklyn.config.ConfigKey;
+import org.apache.brooklyn.core.config.ConfigKeys;
+import org.apache.brooklyn.core.enricher.AbstractEnricher;
+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.sensor.Sensors;
+import org.apache.brooklyn.util.core.flags.TypeCoercions;
+import org.apache.brooklyn.util.exceptions.Exceptions;
+import org.apache.brooklyn.util.guava.Maybe;
+import org.apache.brooklyn.util.net.Networking;
+import org.apache.brooklyn.util.text.StringPredicates;
+import org.apache.brooklyn.util.text.Strings;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.Function;
+import com.google.common.base.Optional;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Lists;
+import com.google.common.net.HostAndPort;
+import com.google.common.reflect.TypeToken;
+
+@Beta
+public abstract class AbstractOnNetworkEnricher extends AbstractEnricher {
+
+private static final Logger LOG = 
LoggerFactory.getLogger(AbstractOnNetworkEnricher.class);
+
+@SuppressWarnings("serial")
+public static final ConfigKey> SENSOR = 
ConfigKeys.newConfigKey(
+new TypeToken>() {}, 
+"sensor",
+"The sensor whose mapped value is to be re-published (with 
suffix \"mapped.networkName\"); "
++ "either 'sensor' or 'sensors' should be specified");
+
+@SuppressWarnings("serial")
+public static ConfigKey>> 
SENSORS = ConfigKeys.newConfigKey(
+new TypeToken>>() {}, 
+"sensors",
+"The multiple sensors whose mapped values are to be 
re-published (with suffix \"mapped.networkName\"); "
++ "if neither 'sensor' or 'sensors' is specified, 
defaults to 'mapAll'");
+
+public static ConfigKey MAP_MATCHING = 
ConfigKeys.newStringConfigKey(
+"mapMatching",
+"Whether to map all, based on a sensor naming convention 
(re-published with suffix \"mapped.networkName\"); "
++ "if neither 'sensor' or 'sensors' is specified, 
defaults to matchin case-insensitive suffix of "
++ "'port', 'uri', 'url' or 'endpoint' ",
+"(?i).*(port|uri|url|endpoint)");
+
+@SuppressWarnings("serial")
+public static ConfigKey> 
SENSOR_NAME_CONVERTER = ConfigKeys.newConfigKey(
+new TypeToken>() {},
+"sensorNameConverter",
+"The converter to use, to map from the original sensor name to 
the re-published sensor name");
+
+public static class SensorNameConverter implements Function {
+private final String network;
+
+public SensorNameConverter(String network) {
+this.network = network;
+}

[GitHub] brooklyn-server pull request #192: Adds OnSubnetNetworkEnricher

2016-06-10 Thread aledsage
Github user aledsage commented on a diff in the pull request:

https://github.com/apache/brooklyn-server/pull/192#discussion_r66601272
  
--- Diff: 
core/src/main/java/org/apache/brooklyn/core/network/AbstractOnNetworkEnricher.java
 ---
@@ -0,0 +1,407 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.core.network;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Collection;
+
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.entity.EntityLocal;
+import org.apache.brooklyn.api.location.Location;
+import org.apache.brooklyn.api.location.MachineLocation;
+import org.apache.brooklyn.api.sensor.AttributeSensor;
+import org.apache.brooklyn.api.sensor.Sensor;
+import org.apache.brooklyn.api.sensor.SensorEvent;
+import org.apache.brooklyn.api.sensor.SensorEventListener;
+import org.apache.brooklyn.config.ConfigKey;
+import org.apache.brooklyn.core.config.ConfigKeys;
+import org.apache.brooklyn.core.enricher.AbstractEnricher;
+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.sensor.Sensors;
+import org.apache.brooklyn.util.core.flags.TypeCoercions;
+import org.apache.brooklyn.util.exceptions.Exceptions;
+import org.apache.brooklyn.util.guava.Maybe;
+import org.apache.brooklyn.util.net.Networking;
+import org.apache.brooklyn.util.text.StringPredicates;
+import org.apache.brooklyn.util.text.Strings;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.Function;
+import com.google.common.base.Optional;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Lists;
+import com.google.common.net.HostAndPort;
+import com.google.common.reflect.TypeToken;
+
+@Beta
+public abstract class AbstractOnNetworkEnricher extends AbstractEnricher {
+
+private static final Logger LOG = 
LoggerFactory.getLogger(AbstractOnNetworkEnricher.class);
+
+@SuppressWarnings("serial")
+public static final ConfigKey> SENSOR = 
ConfigKeys.newConfigKey(
+new TypeToken>() {}, 
+"sensor",
+"The sensor whose mapped value is to be re-published (with 
suffix \"mapped.networkName\"); "
++ "either 'sensor' or 'sensors' should be specified");
+
+@SuppressWarnings("serial")
+public static ConfigKey>> 
SENSORS = ConfigKeys.newConfigKey(
+new TypeToken>>() {}, 
+"sensors",
+"The multiple sensors whose mapped values are to be 
re-published (with suffix \"mapped.networkName\"); "
++ "if neither 'sensor' or 'sensors' is specified, 
defaults to 'mapAll'");
+
+public static ConfigKey MAP_MATCHING = 
ConfigKeys.newStringConfigKey(
+"mapMatching",
+"Whether to map all, based on a sensor naming convention 
(re-published with suffix \"mapped.networkName\"); "
++ "if neither 'sensor' or 'sensors' is specified, 
defaults to matchin case-insensitive suffix of "
++ "'port', 'uri', 'url' or 'endpoint' ",
+"(?i).*(port|uri|url|endpoint)");
--- End diff --

@geomacy yes, you're right. I checked what we're doing elsewhere and it 
does assume a ".port" suffix:

https://github.com/apache/brooklyn-server/blob/rel/apache-brooklyn-0.9.0/software/base/src/main/java/org/apache/brooklyn/entity/software/base/SoftwareProcess.java#L59-L61

https://github.com/apache/brooklyn-server/blob/rel/apache-brooklyn-0.9.0/software/base/src/main/java/org/apache/brooklyn/entity/software/base/InboundPortsUtils.java#L76-L96


---
If your project is set up for it, you can reply to this email and have your
rep

[GitHub] brooklyn-server pull request #192: Adds OnSubnetNetworkEnricher

2016-06-10 Thread aledsage
Github user aledsage commented on a diff in the pull request:

https://github.com/apache/brooklyn-server/pull/192#discussion_r66600837
  
--- Diff: 
core/src/main/java/org/apache/brooklyn/core/network/AbstractOnNetworkEnricher.java
 ---
@@ -0,0 +1,407 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.core.network;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Collection;
+
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.entity.EntityLocal;
+import org.apache.brooklyn.api.location.Location;
+import org.apache.brooklyn.api.location.MachineLocation;
+import org.apache.brooklyn.api.sensor.AttributeSensor;
+import org.apache.brooklyn.api.sensor.Sensor;
+import org.apache.brooklyn.api.sensor.SensorEvent;
+import org.apache.brooklyn.api.sensor.SensorEventListener;
+import org.apache.brooklyn.config.ConfigKey;
+import org.apache.brooklyn.core.config.ConfigKeys;
+import org.apache.brooklyn.core.enricher.AbstractEnricher;
+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.sensor.Sensors;
+import org.apache.brooklyn.util.core.flags.TypeCoercions;
+import org.apache.brooklyn.util.exceptions.Exceptions;
+import org.apache.brooklyn.util.guava.Maybe;
+import org.apache.brooklyn.util.net.Networking;
+import org.apache.brooklyn.util.text.StringPredicates;
+import org.apache.brooklyn.util.text.Strings;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.Function;
+import com.google.common.base.Optional;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Lists;
+import com.google.common.net.HostAndPort;
+import com.google.common.reflect.TypeToken;
+
+@Beta
+public abstract class AbstractOnNetworkEnricher extends AbstractEnricher {
+
+private static final Logger LOG = 
LoggerFactory.getLogger(AbstractOnNetworkEnricher.class);
+
+@SuppressWarnings("serial")
+public static final ConfigKey> SENSOR = 
ConfigKeys.newConfigKey(
--- End diff --

Yes, you're right. I'll delete `SENSOR` before this gets into any official 
release!


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] brooklyn-server pull request #192: Adds OnSubnetNetworkEnricher

2016-06-10 Thread aledsage
Github user aledsage commented on a diff in the pull request:

https://github.com/apache/brooklyn-server/pull/192#discussion_r66600767
  
--- Diff: 
core/src/main/java/org/apache/brooklyn/core/network/AbstractOnNetworkEnricher.java
 ---
@@ -0,0 +1,407 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.core.network;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Collection;
+
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.entity.EntityLocal;
+import org.apache.brooklyn.api.location.Location;
+import org.apache.brooklyn.api.location.MachineLocation;
+import org.apache.brooklyn.api.sensor.AttributeSensor;
+import org.apache.brooklyn.api.sensor.Sensor;
+import org.apache.brooklyn.api.sensor.SensorEvent;
+import org.apache.brooklyn.api.sensor.SensorEventListener;
+import org.apache.brooklyn.config.ConfigKey;
+import org.apache.brooklyn.core.config.ConfigKeys;
+import org.apache.brooklyn.core.enricher.AbstractEnricher;
+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.sensor.Sensors;
+import org.apache.brooklyn.util.core.flags.TypeCoercions;
+import org.apache.brooklyn.util.exceptions.Exceptions;
+import org.apache.brooklyn.util.guava.Maybe;
+import org.apache.brooklyn.util.net.Networking;
+import org.apache.brooklyn.util.text.StringPredicates;
+import org.apache.brooklyn.util.text.Strings;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.Function;
+import com.google.common.base.Optional;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Lists;
+import com.google.common.net.HostAndPort;
+import com.google.common.reflect.TypeToken;
+
+@Beta
+public abstract class AbstractOnNetworkEnricher extends AbstractEnricher {
+
+private static final Logger LOG = 
LoggerFactory.getLogger(AbstractOnNetworkEnricher.class);
+
+@SuppressWarnings("serial")
+public static final ConfigKey> SENSOR = 
ConfigKeys.newConfigKey(
+new TypeToken>() {}, 
+"sensor",
+"The sensor whose mapped value is to be re-published (with 
suffix \"mapped.networkName\"); "
++ "either 'sensor' or 'sensors' should be specified");
+
+@SuppressWarnings("serial")
+public static ConfigKey>> 
SENSORS = ConfigKeys.newConfigKey(
+new TypeToken>>() {}, 
+"sensors",
+"The multiple sensors whose mapped values are to be 
re-published (with suffix \"mapped.networkName\"); "
++ "if neither 'sensor' or 'sensors' is specified, 
defaults to 'mapAll'");
+
+public static ConfigKey MAP_MATCHING = 
ConfigKeys.newStringConfigKey(
+"mapMatching",
+"Whether to map all, based on a sensor naming convention 
(re-published with suffix \"mapped.networkName\"); "
++ "if neither 'sensor' or 'sensors' is specified, 
defaults to matchin case-insensitive suffix of "
++ "'port', 'uri', 'url' or 'endpoint' ",
+"(?i).*(port|uri|url|endpoint)");
+
+@SuppressWarnings("serial")
+public static ConfigKey> 
SENSOR_NAME_CONVERTER = ConfigKeys.newConfigKey(
+new TypeToken>() {},
+"sensorNameConverter",
+"The converter to use, to map from the original sensor name to 
the re-published sensor name");
+
+public static class SensorNameConverter implements Function {
+private final String network;
+
+public SensorNameConverter(String network) {
+this.network = network;
+}
+

[GitHub] brooklyn-server pull request #192: Adds OnSubnetNetworkEnricher

2016-06-10 Thread geomacy
Github user geomacy commented on a diff in the pull request:

https://github.com/apache/brooklyn-server/pull/192#discussion_r66598970
  
--- Diff: 
core/src/main/java/org/apache/brooklyn/core/network/AbstractOnNetworkEnricher.java
 ---
@@ -0,0 +1,407 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.core.network;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Collection;
+
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.entity.EntityLocal;
+import org.apache.brooklyn.api.location.Location;
+import org.apache.brooklyn.api.location.MachineLocation;
+import org.apache.brooklyn.api.sensor.AttributeSensor;
+import org.apache.brooklyn.api.sensor.Sensor;
+import org.apache.brooklyn.api.sensor.SensorEvent;
+import org.apache.brooklyn.api.sensor.SensorEventListener;
+import org.apache.brooklyn.config.ConfigKey;
+import org.apache.brooklyn.core.config.ConfigKeys;
+import org.apache.brooklyn.core.enricher.AbstractEnricher;
+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.sensor.Sensors;
+import org.apache.brooklyn.util.core.flags.TypeCoercions;
+import org.apache.brooklyn.util.exceptions.Exceptions;
+import org.apache.brooklyn.util.guava.Maybe;
+import org.apache.brooklyn.util.net.Networking;
+import org.apache.brooklyn.util.text.StringPredicates;
+import org.apache.brooklyn.util.text.Strings;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.Function;
+import com.google.common.base.Optional;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Lists;
+import com.google.common.net.HostAndPort;
+import com.google.common.reflect.TypeToken;
+
+@Beta
+public abstract class AbstractOnNetworkEnricher extends AbstractEnricher {
+
+private static final Logger LOG = 
LoggerFactory.getLogger(AbstractOnNetworkEnricher.class);
+
+@SuppressWarnings("serial")
+public static final ConfigKey> SENSOR = 
ConfigKeys.newConfigKey(
+new TypeToken>() {}, 
+"sensor",
+"The sensor whose mapped value is to be re-published (with 
suffix \"mapped.networkName\"); "
++ "either 'sensor' or 'sensors' should be specified");
+
+@SuppressWarnings("serial")
+public static ConfigKey>> 
SENSORS = ConfigKeys.newConfigKey(
+new TypeToken>>() {}, 
+"sensors",
+"The multiple sensors whose mapped values are to be 
re-published (with suffix \"mapped.networkName\"); "
++ "if neither 'sensor' or 'sensors' is specified, 
defaults to 'mapAll'");
+
+public static ConfigKey MAP_MATCHING = 
ConfigKeys.newStringConfigKey(
+"mapMatching",
+"Whether to map all, based on a sensor naming convention 
(re-published with suffix \"mapped.networkName\"); "
++ "if neither 'sensor' or 'sensors' is specified, 
defaults to matchin case-insensitive suffix of "
++ "'port', 'uri', 'url' or 'endpoint' ",
+"(?i).*(port|uri|url|endpoint)");
--- End diff --

Although that then won't match xyz.HostAndPort.  Hm. Would it be worth 
checking for that suffix explicitly?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] brooklyn-server pull request #192: Adds OnSubnetNetworkEnricher

2016-06-10 Thread geomacy
Github user geomacy commented on a diff in the pull request:

https://github.com/apache/brooklyn-server/pull/192#discussion_r66596473
  
--- Diff: 
core/src/main/java/org/apache/brooklyn/core/network/AbstractOnNetworkEnricher.java
 ---
@@ -0,0 +1,407 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.core.network;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Collection;
+
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.entity.EntityLocal;
+import org.apache.brooklyn.api.location.Location;
+import org.apache.brooklyn.api.location.MachineLocation;
+import org.apache.brooklyn.api.sensor.AttributeSensor;
+import org.apache.brooklyn.api.sensor.Sensor;
+import org.apache.brooklyn.api.sensor.SensorEvent;
+import org.apache.brooklyn.api.sensor.SensorEventListener;
+import org.apache.brooklyn.config.ConfigKey;
+import org.apache.brooklyn.core.config.ConfigKeys;
+import org.apache.brooklyn.core.enricher.AbstractEnricher;
+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.sensor.Sensors;
+import org.apache.brooklyn.util.core.flags.TypeCoercions;
+import org.apache.brooklyn.util.exceptions.Exceptions;
+import org.apache.brooklyn.util.guava.Maybe;
+import org.apache.brooklyn.util.net.Networking;
+import org.apache.brooklyn.util.text.StringPredicates;
+import org.apache.brooklyn.util.text.Strings;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.Function;
+import com.google.common.base.Optional;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Lists;
+import com.google.common.net.HostAndPort;
+import com.google.common.reflect.TypeToken;
+
+@Beta
+public abstract class AbstractOnNetworkEnricher extends AbstractEnricher {
+
+private static final Logger LOG = 
LoggerFactory.getLogger(AbstractOnNetworkEnricher.class);
+
+@SuppressWarnings("serial")
+public static final ConfigKey> SENSOR = 
ConfigKeys.newConfigKey(
+new TypeToken>() {}, 
+"sensor",
+"The sensor whose mapped value is to be re-published (with 
suffix \"mapped.networkName\"); "
++ "either 'sensor' or 'sensors' should be specified");
+
+@SuppressWarnings("serial")
+public static ConfigKey>> 
SENSORS = ConfigKeys.newConfigKey(
+new TypeToken>>() {}, 
+"sensors",
+"The multiple sensors whose mapped values are to be 
re-published (with suffix \"mapped.networkName\"); "
++ "if neither 'sensor' or 'sensors' is specified, 
defaults to 'mapAll'");
+
+public static ConfigKey MAP_MATCHING = 
ConfigKeys.newStringConfigKey(
+"mapMatching",
+"Whether to map all, based on a sensor naming convention 
(re-published with suffix \"mapped.networkName\"); "
++ "if neither 'sensor' or 'sensors' is specified, 
defaults to matchin case-insensitive suffix of "
++ "'port', 'uri', 'url' or 'endpoint' ",
+"(?i).*(port|uri|url|endpoint)");
+
+@SuppressWarnings("serial")
+public static ConfigKey> 
SENSOR_NAME_CONVERTER = ConfigKeys.newConfigKey(
+new TypeToken>() {},
+"sensorNameConverter",
+"The converter to use, to map from the original sensor name to 
the re-published sensor name");
+
+public static class SensorNameConverter implements Function {
+private final String network;
+
+public SensorNameConverter(String network) {
+this.network = network;
+}
+ 

[GitHub] brooklyn-server pull request #192: Adds OnSubnetNetworkEnricher

2016-06-10 Thread geomacy
Github user geomacy commented on a diff in the pull request:

https://github.com/apache/brooklyn-server/pull/192#discussion_r66594543
  
--- Diff: 
core/src/main/java/org/apache/brooklyn/core/network/AbstractOnNetworkEnricher.java
 ---
@@ -0,0 +1,407 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.core.network;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Collection;
+
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.entity.EntityLocal;
+import org.apache.brooklyn.api.location.Location;
+import org.apache.brooklyn.api.location.MachineLocation;
+import org.apache.brooklyn.api.sensor.AttributeSensor;
+import org.apache.brooklyn.api.sensor.Sensor;
+import org.apache.brooklyn.api.sensor.SensorEvent;
+import org.apache.brooklyn.api.sensor.SensorEventListener;
+import org.apache.brooklyn.config.ConfigKey;
+import org.apache.brooklyn.core.config.ConfigKeys;
+import org.apache.brooklyn.core.enricher.AbstractEnricher;
+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.sensor.Sensors;
+import org.apache.brooklyn.util.core.flags.TypeCoercions;
+import org.apache.brooklyn.util.exceptions.Exceptions;
+import org.apache.brooklyn.util.guava.Maybe;
+import org.apache.brooklyn.util.net.Networking;
+import org.apache.brooklyn.util.text.StringPredicates;
+import org.apache.brooklyn.util.text.Strings;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.Function;
+import com.google.common.base.Optional;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Lists;
+import com.google.common.net.HostAndPort;
+import com.google.common.reflect.TypeToken;
+
+@Beta
+public abstract class AbstractOnNetworkEnricher extends AbstractEnricher {
+
+private static final Logger LOG = 
LoggerFactory.getLogger(AbstractOnNetworkEnricher.class);
+
+@SuppressWarnings("serial")
+public static final ConfigKey> SENSOR = 
ConfigKeys.newConfigKey(
+new TypeToken>() {}, 
+"sensor",
+"The sensor whose mapped value is to be re-published (with 
suffix \"mapped.networkName\"); "
++ "either 'sensor' or 'sensors' should be specified");
+
+@SuppressWarnings("serial")
+public static ConfigKey>> 
SENSORS = ConfigKeys.newConfigKey(
+new TypeToken>>() {}, 
+"sensors",
+"The multiple sensors whose mapped values are to be 
re-published (with suffix \"mapped.networkName\"); "
++ "if neither 'sensor' or 'sensors' is specified, 
defaults to 'mapAll'");
+
+public static ConfigKey MAP_MATCHING = 
ConfigKeys.newStringConfigKey(
+"mapMatching",
+"Whether to map all, based on a sensor naming convention 
(re-published with suffix \"mapped.networkName\"); "
++ "if neither 'sensor' or 'sensors' is specified, 
defaults to matchin case-insensitive suffix of "
++ "'port', 'uri', 'url' or 'endpoint' ",
+"(?i).*(port|uri|url|endpoint)");
+
+@SuppressWarnings("serial")
+public static ConfigKey> 
SENSOR_NAME_CONVERTER = ConfigKeys.newConfigKey(
+new TypeToken>() {},
+"sensorNameConverter",
+"The converter to use, to map from the original sensor name to 
the re-published sensor name");
+
+public static class SensorNameConverter implements Function {
+private final String network;
+
+public SensorNameConverter(String network) {
+this.network = network;
+}
+ 

[GitHub] brooklyn-server pull request #192: Adds OnSubnetNetworkEnricher

2016-06-10 Thread geomacy
Github user geomacy commented on a diff in the pull request:

https://github.com/apache/brooklyn-server/pull/192#discussion_r66594302
  
--- Diff: 
core/src/main/java/org/apache/brooklyn/core/network/AbstractOnNetworkEnricher.java
 ---
@@ -0,0 +1,407 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.core.network;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Collection;
+
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.entity.EntityLocal;
+import org.apache.brooklyn.api.location.Location;
+import org.apache.brooklyn.api.location.MachineLocation;
+import org.apache.brooklyn.api.sensor.AttributeSensor;
+import org.apache.brooklyn.api.sensor.Sensor;
+import org.apache.brooklyn.api.sensor.SensorEvent;
+import org.apache.brooklyn.api.sensor.SensorEventListener;
+import org.apache.brooklyn.config.ConfigKey;
+import org.apache.brooklyn.core.config.ConfigKeys;
+import org.apache.brooklyn.core.enricher.AbstractEnricher;
+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.sensor.Sensors;
+import org.apache.brooklyn.util.core.flags.TypeCoercions;
+import org.apache.brooklyn.util.exceptions.Exceptions;
+import org.apache.brooklyn.util.guava.Maybe;
+import org.apache.brooklyn.util.net.Networking;
+import org.apache.brooklyn.util.text.StringPredicates;
+import org.apache.brooklyn.util.text.Strings;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.Function;
+import com.google.common.base.Optional;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Lists;
+import com.google.common.net.HostAndPort;
+import com.google.common.reflect.TypeToken;
+
+@Beta
+public abstract class AbstractOnNetworkEnricher extends AbstractEnricher {
+
+private static final Logger LOG = 
LoggerFactory.getLogger(AbstractOnNetworkEnricher.class);
+
+@SuppressWarnings("serial")
+public static final ConfigKey> SENSOR = 
ConfigKeys.newConfigKey(
+new TypeToken>() {}, 
+"sensor",
+"The sensor whose mapped value is to be re-published (with 
suffix \"mapped.networkName\"); "
++ "either 'sensor' or 'sensors' should be specified");
+
+@SuppressWarnings("serial")
+public static ConfigKey>> 
SENSORS = ConfigKeys.newConfigKey(
+new TypeToken>>() {}, 
+"sensors",
+"The multiple sensors whose mapped values are to be 
re-published (with suffix \"mapped.networkName\"); "
++ "if neither 'sensor' or 'sensors' is specified, 
defaults to 'mapAll'");
+
+public static ConfigKey MAP_MATCHING = 
ConfigKeys.newStringConfigKey(
+"mapMatching",
+"Whether to map all, based on a sensor naming convention 
(re-published with suffix \"mapped.networkName\"); "
++ "if neither 'sensor' or 'sensors' is specified, 
defaults to matchin case-insensitive suffix of "
++ "'port', 'uri', 'url' or 'endpoint' ",
+"(?i).*(port|uri|url|endpoint)");
--- End diff --

Maybe worth adding an explicit "." in front of the port|uri|url|endpoint?   
 Just in case e.g. "port" would unintentionally match a sensor called 
xyz_export or something?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] brooklyn-server pull request #192: Adds OnSubnetNetworkEnricher

2016-06-10 Thread Graeme-Miller
Github user Graeme-Miller commented on a diff in the pull request:

https://github.com/apache/brooklyn-server/pull/192#discussion_r66592324
  
--- Diff: 
core/src/main/java/org/apache/brooklyn/core/network/AbstractOnNetworkEnricher.java
 ---
@@ -0,0 +1,407 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.core.network;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Collection;
+
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.entity.EntityLocal;
+import org.apache.brooklyn.api.location.Location;
+import org.apache.brooklyn.api.location.MachineLocation;
+import org.apache.brooklyn.api.sensor.AttributeSensor;
+import org.apache.brooklyn.api.sensor.Sensor;
+import org.apache.brooklyn.api.sensor.SensorEvent;
+import org.apache.brooklyn.api.sensor.SensorEventListener;
+import org.apache.brooklyn.config.ConfigKey;
+import org.apache.brooklyn.core.config.ConfigKeys;
+import org.apache.brooklyn.core.enricher.AbstractEnricher;
+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.sensor.Sensors;
+import org.apache.brooklyn.util.core.flags.TypeCoercions;
+import org.apache.brooklyn.util.exceptions.Exceptions;
+import org.apache.brooklyn.util.guava.Maybe;
+import org.apache.brooklyn.util.net.Networking;
+import org.apache.brooklyn.util.text.StringPredicates;
+import org.apache.brooklyn.util.text.Strings;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.Function;
+import com.google.common.base.Optional;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Lists;
+import com.google.common.net.HostAndPort;
+import com.google.common.reflect.TypeToken;
+
+@Beta
+public abstract class AbstractOnNetworkEnricher extends AbstractEnricher {
+
+private static final Logger LOG = 
LoggerFactory.getLogger(AbstractOnNetworkEnricher.class);
+
+@SuppressWarnings("serial")
+public static final ConfigKey> SENSOR = 
ConfigKeys.newConfigKey(
--- End diff --

why have SENSOR and SENORS?
Would it not be simpler to just have SENSORS? If someone only wants one 
sensor to be mapped they can configure SENSORS with one entry.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] brooklyn-server pull request #192: Adds OnSubnetNetworkEnricher

2016-06-10 Thread Graeme-Miller
Github user Graeme-Miller commented on a diff in the pull request:

https://github.com/apache/brooklyn-server/pull/192#discussion_r66591368
  
--- Diff: 
core/src/main/java/org/apache/brooklyn/core/network/AbstractOnNetworkEnricher.java
 ---
@@ -0,0 +1,407 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.core.network;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Collection;
+
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.entity.EntityLocal;
+import org.apache.brooklyn.api.location.Location;
+import org.apache.brooklyn.api.location.MachineLocation;
+import org.apache.brooklyn.api.sensor.AttributeSensor;
+import org.apache.brooklyn.api.sensor.Sensor;
+import org.apache.brooklyn.api.sensor.SensorEvent;
+import org.apache.brooklyn.api.sensor.SensorEventListener;
+import org.apache.brooklyn.config.ConfigKey;
+import org.apache.brooklyn.core.config.ConfigKeys;
+import org.apache.brooklyn.core.enricher.AbstractEnricher;
+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.sensor.Sensors;
+import org.apache.brooklyn.util.core.flags.TypeCoercions;
+import org.apache.brooklyn.util.exceptions.Exceptions;
+import org.apache.brooklyn.util.guava.Maybe;
+import org.apache.brooklyn.util.net.Networking;
+import org.apache.brooklyn.util.text.StringPredicates;
+import org.apache.brooklyn.util.text.Strings;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.Function;
+import com.google.common.base.Optional;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Lists;
+import com.google.common.net.HostAndPort;
+import com.google.common.reflect.TypeToken;
+
+@Beta
+public abstract class AbstractOnNetworkEnricher extends AbstractEnricher {
+
+private static final Logger LOG = 
LoggerFactory.getLogger(AbstractOnNetworkEnricher.class);
+
+@SuppressWarnings("serial")
+public static final ConfigKey> SENSOR = 
ConfigKeys.newConfigKey(
+new TypeToken>() {}, 
+"sensor",
+"The sensor whose mapped value is to be re-published (with 
suffix \"mapped.networkName\"); "
++ "either 'sensor' or 'sensors' should be specified");
+
+@SuppressWarnings("serial")
+public static ConfigKey>> 
SENSORS = ConfigKeys.newConfigKey(
+new TypeToken>>() {}, 
+"sensors",
+"The multiple sensors whose mapped values are to be 
re-published (with suffix \"mapped.networkName\"); "
++ "if neither 'sensor' or 'sensors' is specified, 
defaults to 'mapAll'");
+
+public static ConfigKey MAP_MATCHING = 
ConfigKeys.newStringConfigKey(
+"mapMatching",
+"Whether to map all, based on a sensor naming convention 
(re-published with suffix \"mapped.networkName\"); "
++ "if neither 'sensor' or 'sensors' is specified, 
defaults to matchin case-insensitive suffix of "
++ "'port', 'uri', 'url' or 'endpoint' ",
+"(?i).*(port|uri|url|endpoint)");
+
+@SuppressWarnings("serial")
+public static ConfigKey> 
SENSOR_NAME_CONVERTER = ConfigKeys.newConfigKey(
+new TypeToken>() {},
+"sensorNameConverter",
+"The converter to use, to map from the original sensor name to 
the re-published sensor name");
+
+public static class SensorNameConverter implements Function {
+private final String network;
+
+public SensorNameConverter(String network) {
+this.network = network;
+}

[GitHub] brooklyn-server pull request #192: Adds OnSubnetNetworkEnricher

2016-06-09 Thread aledsage
GitHub user aledsage opened a pull request:

https://github.com/apache/brooklyn-server/pull/192

Adds OnSubnetNetworkEnricher

Some entities publish their endpoint using the public hostname (e.g. 
`MySqlNode` publishes `datastore.url` using the sensor `host.name`). If trying 
to connect to it from within the same subnet, this can fail if the public 
ip/hostname is not accessible.

This topic is covered in the "Working with Multiple Networks" proposal (see 
dev@brooklyn email thread). That suggests we should use the subnet address in 
things like the datastore.url. That will likely break things for some of our 
users. But while we discuss/finalise that proposal...

This enricher allows one to publish another sensor that definitely uses the 
subnet address. It will publish the sensor as things like 
`datastore.url.mapping.subnet`.

This is really a temporary solution (hence marking this as `@Beta`).

You can merge this pull request into a Git repository by running:

$ git pull https://github.com/aledsage/brooklyn-server 
OnSubnetNetworkEnricher

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/brooklyn-server/pull/192.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #192


commit 1660790c9c98b9993631f9107dd1c10c570de420
Author: Aled Sage 
Date:   2016-06-09T15:49:48Z

Adds OnSubnetNetworkEnricher




---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---