/** * Util method to build socket addr from either: * <host> * <host>:<port> * <fs>://<host>:<port>/<path> */ public static InetSocketAddress createSocketAddr(String target, int defaultPort) { return createSocketAddr(target, defaultPort, null); }
/** * Util method to build socket addr from either: * <host>:<port> * <fs>://<host>:<port>/<path> */ public static InetSocketAddress createSocketAddr(String target) { return createSocketAddr(target, -1); }
@Override public InetSocketAddress getResourceManagerAddress(Configuration conf) { String addr = conf.get("yarn.resourcemanager.address", "localhost:8032"); return NetUtils.createSocketAddr(addr); }
/** * Get the socket address for <code>name</code> property as a * <code>InetSocketAddress</code>. * @param name property name. * @param defaultAddress the default value * @param defaultPort the default port * @return InetSocketAddress */ public InetSocketAddress getSocketAddr( String name, String defaultAddress, int defaultPort) { final String address = getTrimmed(name, defaultAddress); return NetUtils.createSocketAddr(address, defaultPort, name); }
/** * Get the socket address for <code>name</code> property as a * <code>InetSocketAddress</code>. * @param name property name. * @param defaultAddress the default value * @param defaultPort the default port * @return InetSocketAddress */ public InetSocketAddress getSocketAddr( String name, String defaultAddress, int defaultPort) { final String address = getTrimmed(name, defaultAddress); return NetUtils.createSocketAddr(address, defaultPort, name); }
public LlapManagementProtocolClientImpl(Configuration conf, String hostname, int port, @Nullable RetryPolicy retryPolicy, @Nullable SocketFactory socketFactory) { this.conf = conf; this.serverAddr = NetUtils.createSocketAddr(hostname, port); this.retryPolicy = retryPolicy; if (socketFactory == null) { this.socketFactory = NetUtils.getDefaultSocketFactory(conf); } else { this.socketFactory = socketFactory; } }
/** * Decode the given token's service field into an InetAddress * @param token from which to obtain the service * @return InetAddress for the service */ public static InetSocketAddress getTokenServiceAddr(Token<?> token) { return NetUtils.createSocketAddr(token.getService().toString()); }
/** * Construct the service key for a token * @param uri of remote connection with a token * @return "ip:port" or "host:port" depending on the value of * hadoop.security.token.service.use_ip */ public static Text buildTokenService(URI uri) { return buildTokenService(NetUtils.createSocketAddr(uri.getAuthority())); }
public ProtobufProxy(Configuration conf, UserGroupInformation ugi, String hostname, int port, @Nullable RetryPolicy retryPolicy, @Nullable SocketFactory socketFactory, Class<?> blockingInterfaceClass) { this.conf = conf; this.serverAddr = NetUtils.createSocketAddr(hostname, port); this.retryPolicy = retryPolicy; if (socketFactory == null) { this.socketFactory = NetUtils.getDefaultSocketFactory(conf); } else { this.socketFactory = socketFactory; } this.blockingInterfaceClass = blockingInterfaceClass; this.ugi = ugi; }
/** * Get the socket address for <code>name</code> property as a * <code>InetSocketAddress</code>. * @param name property name. * @param defaultAddress the default value * @param defaultPort the default port * @return InetSocketAddress */ public InetSocketAddress getSocketAddr( String name, String defaultAddress, int defaultPort) { final String address = getTrimmed(name, defaultAddress); return NetUtils.createSocketAddr(address, defaultPort, name); }
/** * Get the socket address for <code>hostProperty</code> as a * <code>InetSocketAddress</code>. If <code>hostProperty</code> is * <code>null</code>, <code>addressProperty</code> will be used. This * is useful for cases where we want to differentiate between host * bind address and address clients should use to establish connection. * * @param hostProperty bind host property name. * @param addressProperty address property name. * @param defaultAddressValue the default value * @param defaultPort the default port * @return InetSocketAddress */ public InetSocketAddress getSocketAddr( String hostProperty, String addressProperty, String defaultAddressValue, int defaultPort) { InetSocketAddress bindAddr = getSocketAddr( addressProperty, defaultAddressValue, defaultPort); final String host = get(hostProperty); if (host == null || host.isEmpty()) { return bindAddr; } return NetUtils.createSocketAddr( host, bindAddr.getPort(), hostProperty); }
/** * Get the socket address for <code>hostProperty</code> as a * <code>InetSocketAddress</code>. If <code>hostProperty</code> is * <code>null</code>, <code>addressProperty</code> will be used. This * is useful for cases where we want to differentiate between host * bind address and address clients should use to establish connection. * * @param hostProperty bind host property name. * @param addressProperty address property name. * @param defaultAddressValue the default value * @param defaultPort the default port * @return InetSocketAddress */ public InetSocketAddress getSocketAddr( String hostProperty, String addressProperty, String defaultAddressValue, int defaultPort) { InetSocketAddress bindAddr = getSocketAddr( addressProperty, defaultAddressValue, defaultPort); final String host = get(hostProperty); if (host == null || host.isEmpty()) { return bindAddr; } return NetUtils.createSocketAddr( host, bindAddr.getPort(), hostProperty); }
public LlapProtocolClientImpl(Configuration conf, String hostname, int port, UserGroupInformation ugi, @Nullable RetryPolicy retryPolicy, @Nullable SocketFactory socketFactory) { // Technically, methods run on a threadpool that is created externally with the UGI. // However, that is brittle, so we'd save the UGI explicitly here. this.ugi = ugi; this.conf = conf; this.serverAddr = NetUtils.createSocketAddr(hostname, port); this.retryPolicy = retryPolicy; if (socketFactory == null) { this.socketFactory = NetUtils.getDefaultSocketFactory(conf); } else { this.socketFactory = socketFactory; } }
/** * create the service name for a Delegation token * @param uri of the service * @param defPort is used if the uri lacks a port * @return the token service, or null if no authority * @see #buildTokenService(InetSocketAddress) */ public static String buildDTServiceName(URI uri, int defPort) { String authority = uri.getAuthority(); if (authority == null) { return null; } InetSocketAddress addr = NetUtils.createSocketAddr(authority, defPort); return buildTokenService(addr).toString(); }
private static Text getMRTokenRenewerInternal(JobConf jobConf) throws IOException { String servicePrincipal = jobConf.get(YARN_RESOURCEMANAGER_PRINCIPAL, jobConf.get(JTConfig.JT_USER_NAME)); Text renewer; if (servicePrincipal != null) { String target = jobConf.get(YARN_RESOURCEMANAGER_ADDRESS, jobConf.get(MAPREDUCE_JOBTRACKER_ADDRESS)); if (target == null) { target = jobConf.get(MAPRED_JOB_TRACKER); } String addr = NetUtils.createSocketAddr(target).getHostName(); renewer = new Text(SecurityUtil.getServerPrincipal(servicePrincipal, addr)); } else { // No security renewer = new Text("azkaban mr tokens"); } return renewer; } }
public static String getURL(JobConf conf) throws IOException { String infoAddr = ShimLoader.getHadoopShims().getJobLauncherHttpAddress(conf); if (infoAddr == null) { throw new IOException("Unable to find job tracker info port."); } InetSocketAddress infoSocAddr = NetUtils.createSocketAddr(infoAddr); int infoPort = infoSocAddr.getPort(); String jobTrackerStr = ShimLoader.getHadoopShims().getJobLauncherRpcAddress(conf); InetSocketAddress jobTrackerSocAddr = NetUtils.createSocketAddr(jobTrackerStr); String tracker = "http://" + jobTrackerSocAddr.getHostName() + ":" + infoPort; return tracker; }
public int getDataNodePort() { HdfsConfiguration.init(); Configuration dnConf = new HdfsConfiguration(masterServices.getConfiguration()); int dnPort = NetUtils.createSocketAddr( dnConf.get(DFSConfigKeys.DFS_DATANODE_ADDRESS_KEY, DFSConfigKeys.DFS_DATANODE_ADDRESS_DEFAULT)).getPort(); LOG.debug("Loaded default datanode port for FN: " + datanodeDataTransferPort); return dnPort; }
public static String getURL(JobConf conf) throws IOException { String infoAddr = ShimLoader.getHadoopShims().getJobLauncherHttpAddress(conf); if (infoAddr == null) { throw new IOException("Unable to find job tracker info port."); } InetSocketAddress infoSocAddr = NetUtils.createSocketAddr(infoAddr); int infoPort = infoSocAddr.getPort(); String jobTrackerStr = ShimLoader.getHadoopShims().getJobLauncherRpcAddress(conf); InetSocketAddress jobTrackerSocAddr = NetUtils.createSocketAddr(jobTrackerStr); String tracker = "http://" + jobTrackerSocAddr.getHostName() + ":" + infoPort; return tracker; }
protected void checkHdfsUriForTimeout(Configuration config) throws IOException { URI hdfsUri = FileSystem.getDefaultUri(config); String address = hdfsUri.getAuthority(); int port = hdfsUri.getPort(); if (address == null || address.isEmpty() || port < 0) { return; } InetSocketAddress namenode = NetUtils.createSocketAddr(address, port); SocketFactory socketFactory = NetUtils.getDefaultSocketFactory(config); Socket socket = null; try { socket = socketFactory.createSocket(); NetUtils.connect(socket, namenode, 1000); // 1 second timeout } finally { IOUtils.closeQuietly(socket); } }
private static void getJhToken(Configuration conf, Credentials cred) throws IOException { YarnRPC rpc = YarnRPC.create(conf); final String serviceAddr = conf.get(JHAdminConfig.MR_HISTORY_ADDRESS); LOG.debug("Connecting to HistoryServer at: " + serviceAddr); HSClientProtocol hsProxy = (HSClientProtocol) rpc.getProxy(HSClientProtocol.class, NetUtils.createSocketAddr(serviceAddr), conf); LOG.info("Pre-fetching JH token from job history server"); Token<?> jhToken = null; try { jhToken = getDelegationTokenFromHS(hsProxy, conf); } catch (Exception exc) { throw new IOException("Failed to fetch JH token.", exc); } if (jhToken == null) { LOG.error("getDelegationTokenFromHS() returned null"); throw new IOException("Unable to fetch JH token."); } LOG.info("Created JH token: " + jhToken.toString()); LOG.info("Token kind: " + jhToken.getKind()); LOG.info("Token id: " + Arrays.toString(jhToken.getIdentifier())); LOG.info("Token service: " + jhToken.getService()); cred.addToken(jhToken.getService(), jhToken); }