Github user aledsage commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/292#discussion_r74409198
--- 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) {
+ RangeSet<Integer> result = TreeRangeSet.create();
+ for (String portRule : portRules) {
+ if (portRule.contains("-")) {
+ String[] fromTo = portRule.split("-");
+ Preconditions.checkState(fromTo.length == 2);
--- End diff --
I know this came from @bostko 's commit, but if might merge it here...
I'd much prefer us to give a message. This will currently just throw an
`IllegalStateException` with no messsage. Someone would need to look at the
code to understand what went wrong. I'd change this to something like:
Preconditions.checkState(fromTo.length == 2, "Invalid port range '%s'",
portRule);
---
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.
---