public FixedServiceInstance(String host) { if (resolveHosts) { try { InetAddress inetAddress = InetAddress.getByName(host); if (NetUtils.isLocalAddress(inetAddress)) { InetSocketAddress socketAddress = new InetSocketAddress(0); socketAddress = NetUtils.getConnectAddress(socketAddress); LOG.info("Adding host identified as local: " + host + " as " + socketAddress.getHostName()); host = socketAddress.getHostName(); } } catch (UnknownHostException e) { LOG.warn("Ignoring resolution issues for host: " + host, e); } } this.host = host; final URL serviceURL; try { serviceURL = new URL(LlapFixedRegistryImpl.this.webScheme, host, LlapFixedRegistryImpl.this.webPort, ""); this.serviceAddress = serviceURL.toString(); } catch (MalformedURLException e) { throw new RuntimeException(e); } }
@Override public boolean match(InetSocketAddress s) { return NetUtils.isLocalAddress(s.getAddress()); }; };
/** * Checks if name resolution was successful for the given address. If IP * address and host name are the same, then it means name resolution has * failed. As a special case, local addresses are also considered * acceptable. This is particularly important on Windows, where 127.0.0.1 does * not resolve to "localhost". * * @param address InetAddress to check * @return boolean true if name resolution successful or address is local */ private static boolean isNameResolved(InetAddress address) { String hostname = address.getHostName(); String ip = address.getHostAddress(); return !hostname.equals(ip) || NetUtils.isLocalAddress(address); }
@Override public boolean match(InetSocketAddress s) { return NetUtils.isLocalAddress(s.getAddress()); }; };
@Override public boolean match(InetSocketAddress s) { return NetUtils.isLocalAddress(s.getAddress()); }; };
/** * Checks if name resolution was successful for the given address. If IP * address and host name are the same, then it means name resolution has * failed. As a special case, local addresses are also considered * acceptable. This is particularly important on Windows, where 127.0.0.1 does * not resolve to "localhost". * * @param address InetAddress to check * @return boolean true if name resolution successful or address is local */ private static boolean isNameResolved(InetAddress address) { String hostname = address.getHostName(); String ip = address.getHostAddress(); return !hostname.equals(ip) || NetUtils.isLocalAddress(address); }
/** * Checks if name resolution was successful for the given address. If IP * address and host name are the same, then it means name resolution has * failed. As a special case, local addresses are also considered * acceptable. This is particularly important on Windows, where 127.0.0.1 does * not resolve to "localhost". * * @param address InetAddress to check * @return boolean true if name resolution successful or address is local */ private static boolean isNameResolved(InetAddress address) { String hostname = address.getHostName(); String ip = address.getHostAddress(); return !hostname.equals(ip) || NetUtils.isLocalAddress(address); }
public static boolean isLocalAddress(InetSocketAddress targetAddr) throws IOException { if (targetAddr.isUnresolved()) { throw new IOException("Unresolved host: " + targetAddr); } InetAddress addr = targetAddr.getAddress(); Boolean cached = localAddrMap.get(addr.getHostAddress()); if (cached != null) { LOG.trace("Address {} is {} local", targetAddr, (cached ? "" : "not")); return cached; } boolean local = NetUtils.isLocalAddress(addr); LOG.trace("Address {} is {} local", targetAddr, (local ? "" : "not")); localAddrMap.put(addr.getHostAddress(), local); return local; }
public static boolean isLocalAddress(InetSocketAddress targetAddr) { InetAddress addr = targetAddr.getAddress(); Boolean cached = localAddrMap.get(addr.getHostAddress()); if (cached != null) { if (LOG.isTraceEnabled()) { LOG.trace("Address " + targetAddr + (cached ? " is local" : " is not local")); } return cached; } boolean local = NetUtils.isLocalAddress(addr); if (LOG.isTraceEnabled()) { LOG.trace("Address " + targetAddr + (local ? " is local" : " is not local")); } localAddrMap.put(addr.getHostAddress(), local); return local; }
public FixedServiceInstance(String host) { if (resolveHosts) { try { InetAddress inetAddress = InetAddress.getByName(host); if (NetUtils.isLocalAddress(inetAddress)) { InetSocketAddress socketAddress = new InetSocketAddress(0); socketAddress = NetUtils.getConnectAddress(socketAddress); LOG.info("Adding host identified as local: " + host + " as " + socketAddress.getHostName()); host = socketAddress.getHostName(); } } catch (UnknownHostException e) { LOG.warn("Ignoring resolution issues for host: " + host, e); } } this.host = host; final URL serviceURL; try { serviceURL = new URL(LlapFixedRegistryImpl.this.webScheme, host, LlapFixedRegistryImpl.this.webPort, ""); this.serviceAddress = serviceURL.toString(); } catch (MalformedURLException e) { throw new RuntimeException(e); } }
private static ApplicationClientProtocol getRmClient(Token<?> token, Configuration conf) throws IOException { String[] services = token.getService().toString().split(","); for (String service : services) { InetSocketAddress addr = NetUtils.createSocketAddr(service); if (localSecretManager != null) { // return null if it's our token if (localServiceAddress.getAddress().isAnyLocalAddress()) { if (NetUtils.isLocalAddress(addr.getAddress()) && addr.getPort() == localServiceAddress.getPort()) { return null; } } else if (addr.equals(localServiceAddress)) { return null; } } } return ClientRMProxy.createRMProxy(conf, ApplicationClientProtocol.class); }
private static ApplicationClientProtocol getRmClient(Token<?> token, Configuration conf) throws IOException { String[] services = token.getService().toString().split(","); for (String service : services) { InetSocketAddress addr = NetUtils.createSocketAddr(service); if (localSecretManager != null) { // return null if it's our token if (localServiceAddress.getAddress().isAnyLocalAddress()) { if (NetUtils.isLocalAddress(addr.getAddress()) && addr.getPort() == localServiceAddress.getPort()) { return null; } } else if (addr.equals(localServiceAddress)) { return null; } } } return ClientRMProxy.createRMProxy(conf, ApplicationClientProtocol.class); }
private static ApplicationClientProtocol getRmClient(Token<?> token, Configuration conf) throws IOException { String[] services = token.getService().toString().split(","); for (String service : services) { InetSocketAddress addr = NetUtils.createSocketAddr(service); if (localSecretManager != null) { // return null if it's our token if (localServiceAddress.getAddress().isAnyLocalAddress()) { if (NetUtils.isLocalAddress(addr.getAddress()) && addr.getPort() == localServiceAddress.getPort()) { return null; } } else if (addr.equals(localServiceAddress)) { return null; } } } return ClientRMProxy.createRMProxy(conf, ApplicationClientProtocol.class); }
public static boolean isLocalAddress(InetSocketAddress targetAddr) { InetAddress addr = targetAddr.getAddress(); Boolean cached = localAddrMap.get(addr.getHostAddress()); if (cached != null) { if (LOG.isTraceEnabled()) { LOG.trace("Address " + targetAddr + (cached ? " is local" : " is not local")); } return cached; } boolean local = NetUtils.isLocalAddress(addr); if (LOG.isTraceEnabled()) { LOG.trace("Address " + targetAddr + (local ? " is local" : " is not local")); } localAddrMap.put(addr.getHostAddress(), local); return local; }
/** * Examine whether it is worth waiting for a node to restart. * @param index the node index */ boolean shouldWaitForRestart(int index) { // Only one node in the pipeline. if (nodes.length == 1) { return true; } /* * Treat all nodes as remote for test when skip enabled. */ if (DFSClientFaultInjector.get().skipRollingRestartWait()) { return false; } // Is it a local node? InetAddress addr = null; try { addr = InetAddress.getByName(nodes[index].getIpAddr()); } catch (java.net.UnknownHostException e) { // we are passing an ip address. this should not happen. assert false; } return addr != null && NetUtils.isLocalAddress(addr); }
/** * Examine whether it is worth waiting for a node to restart. * @param index the node index */ boolean shouldWaitForRestart(int index) { // Only one node in the pipeline. if (nodes.length == 1) { return true; } /* * Treat all nodes as remote for test when skip enabled. */ if (DFSClientFaultInjector.get().skipRollingRestartWait()) { return false; } // Is it a local node? InetAddress addr = null; try { addr = InetAddress.getByName(nodes[index].getIpAddr()); } catch (java.net.UnknownHostException e) { // we are passing an ip address. this should not happen. assert false; } if (addr != null && NetUtils.isLocalAddress(addr)) { return true; } return false; }
/** * Examine whether it is worth waiting for a node to restart. * @param index the node index */ boolean shouldWaitForRestart(int index) { // Only one node in the pipeline. if (nodes.length == 1) { return true; } /* * Treat all nodes as remote for test when skip enabled. */ if (DFSClientFaultInjector.get().skipRollingRestartWait()) { return false; } // Is it a local node? InetAddress addr = null; try { addr = InetAddress.getByName(nodes[index].getIpAddr()); } catch (java.net.UnknownHostException e) { // we are passing an ip address. this should not happen. assert false; } if (addr != null && NetUtils.isLocalAddress(addr)) { return true; } return false; }
private HashMap.SimpleEntry<String, ComponentContextPair<Stream, StreamContext>> deployBufferServerPublisher( String connIdentifier, StreamCodec<?> streamCodec, long finishedWindowId, int queueCapacity, OperatorDeployInfo.OutputDeployInfo nodi) throws UnknownHostException { String sinkIdentifier = "tcp://".concat(nodi.bufferServerHost).concat(":").concat(String.valueOf(nodi.bufferServerPort)).concat("/").concat(connIdentifier); StreamContext bssc = new StreamContext(nodi.declaredStreamId); bssc.setPortId(nodi.portName); bssc.setSourceId(connIdentifier); bssc.setSinkId(sinkIdentifier); bssc.setFinishedWindowId(finishedWindowId); bssc.put(StreamContext.CODEC, streamCodec); bssc.put(StreamContext.EVENT_LOOP, eventloop); bssc.setBufferServerAddress(InetSocketAddress.createUnresolved(nodi.bufferServerHost, nodi.bufferServerPort)); bssc.put(StreamContext.BUFFER_SERVER_TOKEN, nodi.bufferServerToken); InetAddress inetAddress = bssc.getBufferServerAddress().getAddress(); if (inetAddress != null && NetUtils.isLocalAddress(inetAddress)) { bssc.setBufferServerAddress(new InetSocketAddress(InetAddress.getByName(null), nodi.bufferServerPort)); } Stream publisher = fastPublisherSubscriber ? new FastPublisher(connIdentifier, queueCapacity * 256) : new BufferServerPublisher(connIdentifier, queueCapacity); return new HashMap.SimpleEntry<>(sinkIdentifier, new ComponentContextPair<>(publisher, bssc)); }
/** * Test for {@link NetUtils#isLocalAddress(java.net.InetAddress)} */ @Test public void testIsLocalAddress() throws Exception { // Test - local host is local address assertTrue(NetUtils.isLocalAddress(InetAddress.getLocalHost())); // Test - all addresses bound network interface is local address Enumeration<NetworkInterface> interfaces = NetworkInterface .getNetworkInterfaces(); if (interfaces != null) { // Iterate through all network interfaces while (interfaces.hasMoreElements()) { NetworkInterface i = interfaces.nextElement(); Enumeration<InetAddress> addrs = i.getInetAddresses(); if (addrs == null) { continue; } // Iterate through all the addresses of a network interface while (addrs.hasMoreElements()) { InetAddress addr = addrs.nextElement(); assertTrue(NetUtils.isLocalAddress(addr)); } } } assertFalse(NetUtils.isLocalAddress(InetAddress.getByName("8.8.8.8"))); }
/** * Test for {@link NetUtils#isLocalAddress(java.net.InetAddress)} */ @Test public void testIsLocalAddress() throws Exception { // Test - local host is local address assertTrue(NetUtils.isLocalAddress(InetAddress.getLocalHost())); // Test - all addresses bound network interface is local address Enumeration<NetworkInterface> interfaces = NetworkInterface .getNetworkInterfaces(); if (interfaces != null) { // Iterate through all network interfaces while (interfaces.hasMoreElements()) { NetworkInterface i = interfaces.nextElement(); Enumeration<InetAddress> addrs = i.getInetAddresses(); if (addrs == null) { continue; } // Iterate through all the addresses of a network interface while (addrs.hasMoreElements()) { InetAddress addr = addrs.nextElement(); assertTrue(NetUtils.isLocalAddress(addr)); } } } assertFalse(NetUtils.isLocalAddress(InetAddress.getByName("8.8.8.8"))); }