Github user aledsage commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/292#discussion_r74410202
--- Diff:
core/src/main/java/org/apache/brooklyn/util/core/BrooklynNetworkUtils.java ---
@@ -19,24 +19,52 @@
package org.apache.brooklyn.util.core;
import java.net.InetAddress;
+import java.util.Collection;
import org.apache.brooklyn.core.location.geo.LocalhostExternalIpLoader;
import org.apache.brooklyn.core.server.BrooklynServiceAttributes;
import org.apache.brooklyn.util.JavaGroovyEquivalents;
import org.apache.brooklyn.util.core.flags.TypeCoercions;
import org.apache.brooklyn.util.net.Networking;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Range;
+import com.google.common.collect.RangeSet;
+import com.google.common.collect.TreeRangeSet;
+
public class BrooklynNetworkUtils {
- /** returns the externally-facing IP address from which this host
comes, or 127.0.0.1 if not resolvable */
+ /**
+ * returns the externally-facing IP address from which this host
comes, or 127.0.0.1 if not resolvable
+ */
public static String getLocalhostExternalIp() {
return LocalhostExternalIpLoader.getLocalhostIpQuicklyOrDefault();
}
- /** returns a IP address for localhost paying attention to a system
property to prevent lookup in some cases */
+ /**
+ * returns a IP address for localhost paying attention to a system
property to prevent lookup in some cases
+ */
public static InetAddress getLocalhostInetAddress() {
- return
TypeCoercions.coerce(JavaGroovyEquivalents.elvis(BrooklynServiceAttributes.LOCALHOST_IP_ADDRESS.getValue(),
+ return
TypeCoercions.coerce(JavaGroovyEquivalents.elvis(BrooklynServiceAttributes.LOCALHOST_IP_ADDRESS.getValue(),
Networking.getLocalHost()), InetAddress.class);
}
+ public static RangeSet<Integer> portRulesToRanges(Collection<String>
portRules) {
--- End diff --
This should probably go in `Networking` instead of `BrooklynNetworkUtils`.
The difference between the two classes seems to be:
* `Networking` is for generic network utility methods.
* `BrooklynNetworkUtils` is for utility methods that rely on some other
part(s) of Brooklyn, or seem too custom in how they are used/configured to be
considered a "common utility". For example `getLocalhostExternalIp()` will load
the resource `external-ip-address-resolvers.txt` that tells us about external
service(s) to use, such as http://jsonip.com/, and will contact that in a
time-limited way to get + cache the ip).
Worth adding javadoc to the two classes to that affect, and to include in
the latter a reference to `{@link org.apache.brooklyn.util.net.Networking}`.
---
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 [email protected] or file a JIRA ticket
with INFRA.
---