brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sjcorbett <...@git.apache.org>
Subject [GitHub] brooklyn-server pull request #497: Add findOpenSocketsOnNode to ReachableSoc...
Date Wed, 18 Jan 2017 11:15:47 GMT
Github user sjcorbett commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/497#discussion_r96612584
  
    --- Diff: locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsUtil.java
---
    @@ -354,30 +355,60 @@ public static String getFirstReachableAddress(ComputeServiceContext
context, Nod
             return getFirstReachableAddress(node, Duration.FIVE_MINUTES);
         }
         
    +    /**
    +     * Uses {@link Networking#isReachablePredicate()} to determine reachability.
    +     * @see #getReachableAddresses(NodeMetadata, Duration, Predicate)
    +     */
         public static String getFirstReachableAddress(NodeMetadata node, Duration timeout)
{
    -        return getFirstReachableAddress(node, timeout, new Networking.IsReachablePredicate());
    +        return getFirstReachableAddress(node, timeout, Networking.isReachablePredicate());
         }
     
    +    /** @see #getReachableAddresses(NodeMetadata, Duration, Predicate) */
         public static String getFirstReachableAddress(NodeMetadata node, Duration timeout,
Predicate<? super HostAndPort> socketTester) {
    +        Iterable<HostAndPort> addresses = getReachableAddresses(node, timeout,
socketTester);
    +        HostAndPort address = Iterables.getFirst(addresses, null);
    +        if (address != null) {
    +            return address.getHostText();
    +        } else {
    +            throw new IllegalStateException("No reachable IPs for " + node + "; check
whether the node is " +
    +                    "reachable and whether it meets the requirements of the HostAndPort
tester: " + socketTester);
    +        }
    +    }
    +
    +    /**
    +     * @return The public and private addresses of node that are reachable.
    +     * @see #getReachableAddresses(Iterable, Duration, Predicate)
    +     */
    +    public static Iterable<HostAndPort> getReachableAddresses(NodeMetadata node,
Duration timeout, Predicate<? super HostAndPort> socketTester) {
             final int port = node.getLoginPort();
    -        List<HostAndPort> sockets = FluentIterable
    -                .from(Iterables.concat(node.getPublicAddresses(), node.getPrivateAddresses()))
    +        return getReachableAddresses(Iterables.concat(node.getPublicAddresses(), node.getPrivateAddresses()),
port, timeout, socketTester);
    +    }
    +
    +    /** @see #getReachableAddresses(Iterable, Duration, Predicate) */
    +    public static Iterable<HostAndPort> getReachableAddresses(Iterable<String>
hosts, final int port, Duration timeout, Predicate<? super HostAndPort> socketTester)
{
    +        FluentIterable<HostAndPort> sockets = FluentIterable
    +                .from(hosts)
                     .transform(new Function<String, HostAndPort>() {
                             @Override public HostAndPort apply(String input) {
                                 return HostAndPort.fromParts(input, port);
    -                        }})
    -                .toList();
    -        
    +                        }});
    +        return getReachableAddresses(sockets, timeout, socketTester);
    +    }
    +
    +    /**
    +     * Uses {@link ReachableSocketFinder} to determine which sockets are reachable. Iterators
    +     * are unmodifiable and are lazily evaluated.
    +     * @param sockets The host-and-ports to test
    +     * @param timeout Max time to try to connect to the ip:port
    +     * @param socketTester A predicate determining reachability.
    +     */
    +    public static Iterable<HostAndPort> getReachableAddresses(Iterable<HostAndPort>
sockets, Duration timeout, Predicate<? super HostAndPort> socketTester) {
             ListeningExecutorService executor = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool());
             try {
                 ReachableSocketFinder finder = new ReachableSocketFinder(socketTester, executor);
    -            HostAndPort result = finder.findOpenSocketOnNode(sockets, timeout);
    -            return result.getHostText();
    -        } catch (Exception e) {
    --- End diff --
    
    No exception is thrown here any more. The deleted section applied to `getFirstReachableAddress`
which still throws with a helpful message if no address if found. `getReachableAddresses`
returns an empty iterable.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message