Github user neykov commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/332#discussion_r79595174
  
    --- Diff: 
locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java
 ---
    @@ -2862,15 +2863,61 @@ protected String 
getFirstReachableAddress(NodeMetadata node, ConfigBag setup) {
             String result;
             if (enabled) {
                 Duration timeout = "true".equals(pollForFirstReachable) ? 
Duration.FIVE_MINUTES : Duration.of(pollForFirstReachable);
    -            result = JcloudsUtil.getFirstReachableAddress(node, timeout);
    -            LOG.debug("Using first-reachable address "+result+" for node 
"+node+" in "+this);
    +
    +            Predicate<HostAndPort> 
pollForFirstReachableHostAndPortPredicate;
    +            if (setup.get(POLL_FOR_FIRST_REACHABLE_ADDRESS_PREDICATE) != 
null) {
    +                LOG.debug("Using pollForFirstReachableAddress.predicate 
supplied from config for location " + this + " "
    +                        + 
POLL_FOR_FIRST_REACHABLE_ADDRESS_PREDICATE.getName() + " : " + 
setup.get(POLL_FOR_FIRST_REACHABLE_ADDRESS_PREDICATE));
    +                pollForFirstReachableHostAndPortPredicate = 
setup.get(POLL_FOR_FIRST_REACHABLE_ADDRESS_PREDICATE);
    +            } else {
    +                LOG.debug("Using 
pollForFirstReachableAddress.predicate.type supplied from config for location " 
+ this + " " + POLL_FOR_FIRST_REACHABLE_ADDRESS_PREDICATE_TYPE.getName()
    +                        + " : " + 
setup.get(POLL_FOR_FIRST_REACHABLE_ADDRESS_PREDICATE_TYPE));
    +
    +                List<Constructor<?>> constructors = 
Arrays.asList(setup.get(POLL_FOR_FIRST_REACHABLE_ADDRESS_PREDICATE_TYPE).getConstructors());
    +                Optional<Constructor<?>> emptyConstructor= 
Iterables.tryFind(constructors, new Predicate<Constructor<?>>() {
    +                    @Override public boolean apply(Constructor<?> 
constructor) {
    +                        return constructor.getParameterTypes().length == 0;
    +                    }
    +                });
    +                Optional<Constructor<?>> mapConstructor = 
Iterables.tryFind(constructors, new Predicate<Constructor<?>>() {
    +                    @Override public boolean apply(Constructor<?> 
constructor) {
    +                        if (constructor.getParameterTypes().length == 1) {
    +                            return 
constructor.getParameterTypes()[0].isAssignableFrom(Map.class);
    +                        } else {
    +                            return false;
    +                        }
    +                    }
    +                });
    +                if (mapConstructor.isPresent()) {
    +                    Map<String, Object> args = MutableMap.of();
    +                    
ConfigUtils.addUnprefixedConfigKeyInConfigBack(POLL_FOR_FIRST_REACHABLE_ADDRESS_PREDICATE.getName()
 + ".", setup, args);
    +                    try {
    +                        pollForFirstReachableHostAndPortPredicate = 
setup.get(POLL_FOR_FIRST_REACHABLE_ADDRESS_PREDICATE_TYPE).getConstructor(Map.class).newInstance(args);
    +                    } catch (ReflectiveOperationException e) {
    +                        throw Exceptions.propagate(e);
    +                    }
    +                } else {
    +                    try {
    +                        pollForFirstReachableHostAndPortPredicate = 
(Predicate<HostAndPort>)emptyConstructor.get().newInstance();
    +                    } catch (ReflectiveOperationException e) {
    +                        throw Exceptions.propagate(e);
    +                    }
    +                }
    +            }
    +
    +            try {
    +                result = JcloudsUtil.getFirstReachableAddress(node, 
timeout, pollForFirstReachableHostAndPortPredicate);
    +            } catch (Exception e) {
    +                throw Exceptions.propagate("Problem instantiating 
reachability checker for " + this
    +                        + " pollForFirstReachableHostAndPortPredicate: " + 
pollForFirstReachableHostAndPortPredicate, e);
    +            }
             } else {
                 result = 
Iterables.getFirst(Iterables.concat(node.getPublicAddresses(), 
node.getPrivateAddresses()), null);
                 if (result == null) {
                     throw new IllegalStateException("No addresses available 
for node "+node+" in "+this);
                 }
    -            LOG.debug("Using first address "+result+" for node "+node+" in 
"+this);
    --- End diff --
    
    This is an important distinction for troubleshooting. Leave both the first 
and first-reachable log statements.


---
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.
---

Reply via email to