/** * Set the socket address a client can use to connect for the * <code>name</code> property as a <code>host:port</code>. The wildcard * address is replaced with the local host's address. * @param name property name. * @param addr InetSocketAddress of a listener to store in the given property * @return InetSocketAddress for clients to connect */ public InetSocketAddress updateConnectAddr(String name, InetSocketAddress addr) { final InetSocketAddress connectAddr = NetUtils.getConnectAddress(addr); setSocketAddr(name, connectAddr); return connectAddr; }
/** * Set the socket address a client can use to connect for the * <code>name</code> property as a <code>host:port</code>. The wildcard * address is replaced with the local host's address. * @param name property name. * @param addr InetSocketAddress of a listener to store in the given property * @return InetSocketAddress for clients to connect */ public InetSocketAddress updateConnectAddr(String name, InetSocketAddress addr) { final InetSocketAddress connectAddr = NetUtils.getConnectAddress(addr); setSocketAddr(name, connectAddr); return connectAddr; }
/** * Returns InetSocketAddress that a client can use to * connect to the server. Server.getListenerAddress() is not correct when * the server binds to "0.0.0.0". This returns "hostname:port" of the server, * or "127.0.0.1:port" when the getListenerAddress() returns "0.0.0.0:port". * * @param server * @return socket address that a client can use to connect to the server. */ public static InetSocketAddress getConnectAddress(Server server) { return getConnectAddress(server.getListenerAddress()); }
/** * Set the socket address a client can use to connect for the * <code>name</code> property as a <code>host:port</code>. The wildcard * address is replaced with the local host's address. * @param name property name. * @param addr InetSocketAddress of a listener to store in the given property * @return InetSocketAddress for clients to connect */ public InetSocketAddress updateConnectAddr(String name, InetSocketAddress addr) { final InetSocketAddress connectAddr = NetUtils.getConnectAddress(addr); setSocketAddr(name, connectAddr); return connectAddr; }
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); } }
public static RPC.Server startProtocolServer(int srvPort, int numHandlers, AtomicReference<InetSocketAddress> bindAddress, Configuration conf, BlockingService impl, Class<?> protocolClass, SecretManager<?> secretManager, PolicyProvider provider, ConfVars... aclVars) { InetSocketAddress addr = new InetSocketAddress(srvPort); RPC.Server server; try { server = createRpcServer(protocolClass, addr, conf, numHandlers, impl, secretManager, provider, aclVars); server.start(); } catch (IOException e) { LOG.error("Failed to run RPC Server on port: " + srvPort, e); throw new RuntimeException(e); } InetSocketAddress serverBindAddress = NetUtils.getConnectAddress(server); InetSocketAddress bindAddressVal = NetUtils.createSocketAddrForHost( serverBindAddress.getAddress().getCanonicalHostName(), serverBindAddress.getPort()); if (bindAddress != null) { bindAddress.set(bindAddressVal); } LOG.info("Instantiated " + protocolClass.getSimpleName() + " at " + bindAddressVal); return server; }
@Override public void start() { LOG.info("Starting application message server"); RPC.Builder builder = new RPC.Builder(getConfig()); builder.setProtocol(ApplicationMessageProtocol.class); builder.setInstance(this); builder.setBindAddress("0.0.0.0"); builder.setPort(0); Server server; try { server = builder.build(); } catch (Exception e) { LOG.error("Error starting message server!", e); e.printStackTrace(); return; } server.start(); serverAddress = NetUtils.getConnectAddress(server); LOG.info("Started application message server at " + serverAddress); }
public LlapTaskUmbilicalServer(Configuration conf, LlapTaskUmbilicalProtocol umbilical, int numHandlers) throws IOException { jobTokenSecretManager = new JobTokenSecretManager(); server = new RPC.Builder(conf) .setProtocol(LlapTaskUmbilicalProtocol.class) .setBindAddress("0.0.0.0") .setPort(0) .setInstance(umbilical) .setNumHandlers(numHandlers) .setSecretManager(jobTokenSecretManager).build(); if (conf.getBoolean(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHORIZATION, false)) { server.refreshServiceAcl(conf, new LlapUmbilicalExternalPolicyProvider()); } server.start(); this.address = NetUtils.getConnectAddress(server); LOG.info( "Started TaskUmbilicalServer: " + umbilical.getClass().getName() + " at address: " + address + " with numHandlers=" + numHandlers); }
@Override protected void startRpcServer() { Configuration conf = getConf(); try { JobTokenSecretManager jobTokenSecretManager = new JobTokenSecretManager(); jobTokenSecretManager.addTokenForJob(tokenIdentifier, sessionToken); int numHandlers = HiveConf.getIntVar(conf, ConfVars.LLAP_TASK_COMMUNICATOR_LISTENER_THREAD_COUNT); server = new RPC.Builder(conf) .setProtocol(LlapTaskUmbilicalProtocol.class) .setBindAddress("0.0.0.0") .setPort(0) .setInstance(umbilical) .setNumHandlers(numHandlers) .setSecretManager(jobTokenSecretManager).build(); if (conf.getBoolean(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHORIZATION, false)) { server.refreshServiceAcl(conf, new LlapUmbilicalPolicyProvider()); } server.start(); this.address = NetUtils.getConnectAddress(server); this.amHost = LlapUtil.getAmHostNameFromAddress(address, conf); LOG.info("Started LlapUmbilical: " + umbilical.getClass().getName() + " at address: " + address + " with numHandlers=" + numHandlers + " using the host name " + amHost); } catch (IOException e) { throw new TezUncheckedException(e); } }
/** * Sets address of namenode for use by servlets. * * @param nameNodeAddress InetSocketAddress to set */ void setNameNodeAddress(InetSocketAddress nameNodeAddress) { httpServer.setAttribute(NAMENODE_ADDRESS_ATTRIBUTE_KEY, NetUtils.getConnectAddress(nameNodeAddress)); }
/** * Get the socket address of this server * @return the address this server is listening on */ public InetSocketAddress getConnectAddress() { return NetUtils.getConnectAddress(server); }
private String getServiceAddress(InetSocketAddress address) { InetSocketAddress socketAddress = NetUtils.getConnectAddress(address); return socketAddress.getAddress().getHostAddress() + ":" + socketAddress.getPort(); }
private NodeId buildNodeId(InetSocketAddress connectAddress, String hostOverride) { if (hostOverride != null) { connectAddress = NetUtils.getConnectAddress( new InetSocketAddress(hostOverride, connectAddress.getPort())); } return NodeId.newInstance( connectAddress.getAddress().getCanonicalHostName(), connectAddress.getPort()); }
/** * Returns InetSocketAddress that a client can use to * connect to the server. Server.getListenerAddress() is not correct when * the server binds to "0.0.0.0". This returns "hostname:port" of the server, * or "127.0.0.1:port" when the getListenerAddress() returns "0.0.0.0:port". * * @param server * @return socket address that a client can use to connect to the server. */ public static InetSocketAddress getConnectAddress(Server server) { return getConnectAddress(server.getListenerAddress()); }
/** * Returns InetSocketAddress that a client can use to * connect to the server. Server.getListenerAddress() is not correct when * the server binds to "0.0.0.0". This returns "hostname:port" of the server, * or "127.0.0.1:port" when the getListenerAddress() returns "0.0.0.0:port". * * @param server * @return socket address that a client can use to connect to the server. */ public static InetSocketAddress getConnectAddress(Server server) { return getConnectAddress(server.getListenerAddress()); }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { LongWritable param = new LongWritable(RANDOM.nextLong()); LongWritable value = (LongWritable) client.call(param, NetUtils.getConnectAddress(server), null, null, 0, conf); if (retry++ < total) { throw new IOException("Fake IOException"); } else { return value; } }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { LongWritable param = new LongWritable(RANDOM.nextLong()); LongWritable value = (LongWritable) client.call(param, NetUtils.getConnectAddress(server), null, null, 0, conf); if (retry++ < total) { throw new IOException("Fake IOException"); } else { return value; } }
@Test public void testGetConnectAddress() throws IOException { NetUtils.addStaticResolution("host", "127.0.0.1"); InetSocketAddress addr = NetUtils.createSocketAddrForHost("host", 1); InetSocketAddress connectAddr = NetUtils.getConnectAddress(addr); assertEquals(addr.getHostName(), connectAddr.getHostName()); addr = new InetSocketAddress(1); connectAddr = NetUtils.getConnectAddress(addr); assertEquals(InetAddress.getLocalHost().getHostName(), connectAddr.getHostName()); }
@BeforeClass public static void start() { InetSocketAddress address = new InetSocketAddress(0); Configuration configuration = new Configuration(); ResourceTracker instance = new ResourceTrackerTestImpl(); server = RpcServerFactoryPBImpl.get().getServer(ResourceTracker.class, instance, address, configuration, null, 1); server.start(); client = (ResourceTracker) RpcClientFactoryPBImpl.get().getClient( ResourceTracker.class, 1, NetUtils.getConnectAddress(server), configuration); }
@Override public Void run() throws IOException { proxy = RPC.getProxy( TestProtocol.class, TestProtocol.versionID, NetUtils.getConnectAddress(server), conf); Assert.assertEquals(ugi.toString(), proxy.aMethod()); Assert.assertEquals(ugi.toString(), proxy.getServerRemoteUser()); return null; } });