GG-11028 Fixed resolving of host name.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/d88f422a Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/d88f422a Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/d88f422a Branch: refs/heads/ignite-4242 Commit: d88f422aeb02738d676d86ce416551b805ad154e Parents: 5a3a1960 Author: Andrey Novikov <[email protected]> Authored: Wed Nov 9 14:25:38 2016 +0700 Committer: Andrey Novikov <[email protected]> Committed: Wed Nov 9 14:28:54 2016 +0700 ---------------------------------------------------------------------- bin/ignite.bat | 5 +++ .../ignite/internal/util/IgniteUtils.java | 47 +++++++++++++++----- .../visor/misc/VisorResolveHostNameTask.java | 4 +- 3 files changed, 44 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/d88f422a/bin/ignite.bat ---------------------------------------------------------------------- diff --git a/bin/ignite.bat b/bin/ignite.bat index b999b86..db686cc 100644 --- a/bin/ignite.bat +++ b/bin/ignite.bat @@ -184,6 +184,11 @@ if %ERRORLEVEL% equ 0 ( :: set JVM_OPTS=%JVM_OPTS% -Djava.net.preferIPv4Stack=true :: +:: Uncomment to enable reverse DNS lookup. +:: +:: set JVM_OPTS=%JVM_OPTS% -Dsun.net.spi.nameservice.provider.1=default -Dsun.net.spi.nameservice.provider.2=dns,sun + +:: :: Assertions are disabled by default since version 3.5. :: If you want to enable them - set 'ENABLE_ASSERTIONS' flag to '1'. :: http://git-wip-us.apache.org/repos/asf/ignite/blob/d88f422a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java index 1e8d648..7b011dd 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java @@ -477,6 +477,9 @@ public abstract class IgniteUtils { private static volatile IgniteBiTuple<Collection<String>, Collection<String>> cachedLocalAddr; /** */ + private static volatile IgniteBiTuple<Collection<String>, Collection<String>> cachedLocalAddrAllHostNames; + + /** */ private static final ConcurrentMap<ClassLoader, ConcurrentMap<String, Class>> classCache = new ConcurrentHashMap8<>(); @@ -1845,41 +1848,61 @@ public abstract class IgniteUtils { */ public static IgniteBiTuple<Collection<String>, Collection<String>> resolveLocalAddresses(InetAddress locAddr) throws IOException, IgniteCheckedException { + return resolveLocalAddresses(locAddr, false); + } + + /** + * Returns host names consistent with {@link #resolveLocalHost(String)}. So when it returns + * a common address this method returns single host name, and when a wildcard address passed + * this method tries to collect addresses of all available interfaces. + * + * @param locAddr Local address to resolve. + * @param allHostNames If {@code true} then include host names for all addresses. + * @return Resolved available addresses and host names of given local address. + * @throws IOException If failed. + * @throws IgniteCheckedException If no network interfaces found. + */ + public static IgniteBiTuple<Collection<String>, Collection<String>> resolveLocalAddresses(InetAddress locAddr, + boolean allHostNames) throws IOException, IgniteCheckedException { assert locAddr != null; Collection<String> addrs = new ArrayList<>(); Collection<String> hostNames = new ArrayList<>(); if (locAddr.isAnyLocalAddress()) { - IgniteBiTuple<Collection<String>, Collection<String>> res = cachedLocalAddr; + IgniteBiTuple<Collection<String>, Collection<String>> res = + allHostNames ? cachedLocalAddrAllHostNames : cachedLocalAddr; if (res == null) { - List<InetAddress> localAddrs = new ArrayList<>(); + List<InetAddress> locAddrs = new ArrayList<>(); for (NetworkInterface itf : asIterable(NetworkInterface.getNetworkInterfaces())) { for (InetAddress addr : asIterable(itf.getInetAddresses())) { if (!addr.isLinkLocalAddress()) - localAddrs.add(addr); + locAddrs.add(addr); } } - localAddrs = filterReachable(localAddrs); + locAddrs = filterReachable(locAddrs); - for (InetAddress addr : localAddrs) - addresses(addr, addrs, hostNames); + for (InetAddress addr : locAddrs) + addresses(addr, addrs, hostNames, allHostNames); if (F.isEmpty(addrs)) throw new IgniteCheckedException("No network addresses found (is networking enabled?)."); res = F.t(addrs, hostNames); - cachedLocalAddr = res; + if (allHostNames) + cachedLocalAddrAllHostNames = res; + else + cachedLocalAddr = res; } return res; } - addresses(locAddr, addrs, hostNames); + addresses(locAddr, addrs, hostNames, allHostNames); return F.t(addrs, hostNames); } @@ -1887,16 +1910,20 @@ public abstract class IgniteUtils { /** * @param addr Address. * @param addrs Addresses. + * @param allHostNames If {@code true} then include host names for all addresses. * @param hostNames Host names. */ - private static void addresses(InetAddress addr, Collection<String> addrs, Collection<String> hostNames) { + private static void addresses(InetAddress addr, Collection<String> addrs, Collection<String> hostNames, + boolean allHostNames) { String hostName = addr.getHostName(); String ipAddr = addr.getHostAddress(); addrs.add(ipAddr); - if (!F.isEmpty(hostName) && !addr.isLoopbackAddress()) + if (allHostNames) + hostNames.add(hostName); + else if (!F.isEmpty(hostName) && !addr.isLoopbackAddress()) hostNames.add(hostName); } http://git-wip-us.apache.org/repos/asf/ignite/blob/d88f422a/modules/core/src/main/java/org/apache/ignite/internal/visor/misc/VisorResolveHostNameTask.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/misc/VisorResolveHostNameTask.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/misc/VisorResolveHostNameTask.java index 0f9e038..f851e26 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/visor/misc/VisorResolveHostNameTask.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/misc/VisorResolveHostNameTask.java @@ -66,7 +66,7 @@ public class VisorResolveHostNameTask extends VisorOneNodeTask<Void, Map<String, try { IgniteBiTuple<Collection<String>, Collection<String>> addrs = - IgniteUtils.resolveLocalAddresses(InetAddress.getByName("0.0.0.0")); + IgniteUtils.resolveLocalAddresses(InetAddress.getByName("0.0.0.0"), true); assert (addrs.get1() != null); assert (addrs.get2() != null); @@ -104,4 +104,4 @@ public class VisorResolveHostNameTask extends VisorOneNodeTask<Void, Map<String, return S.toString(VisorResolveHostNameJob.class, this); } } -} \ No newline at end of file +}
