Java Code Examples for org.apache.hadoop.yarn.conf.YarnConfiguration#getSocketAddr()

The following examples show how to use org.apache.hadoop.yarn.conf.YarnConfiguration#getSocketAddr() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClientRMProxy.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Private
@Override
protected InetSocketAddress getRMAddress(YarnConfiguration conf,
    Class<?> protocol) throws IOException {
  if (protocol == ApplicationClientProtocol.class) {
    return conf.getSocketAddr(YarnConfiguration.RM_ADDRESS,
        YarnConfiguration.DEFAULT_RM_ADDRESS,
        YarnConfiguration.DEFAULT_RM_PORT);
  } else if (protocol == ResourceManagerAdministrationProtocol.class) {
    return conf.getSocketAddr(
        YarnConfiguration.RM_ADMIN_ADDRESS,
        YarnConfiguration.DEFAULT_RM_ADMIN_ADDRESS,
        YarnConfiguration.DEFAULT_RM_ADMIN_PORT);
  } else if (protocol == ApplicationMasterProtocol.class) {
    setAMRMTokenService(conf);
    return conf.getSocketAddr(YarnConfiguration.RM_SCHEDULER_ADDRESS,
        YarnConfiguration.DEFAULT_RM_SCHEDULER_ADDRESS,
        YarnConfiguration.DEFAULT_RM_SCHEDULER_PORT);
  } else {
    String message = "Unsupported protocol found when creating the proxy " +
        "connection to ResourceManager: " +
        ((protocol != null) ? protocol.getClass().getName() : "null");
    LOG.error(message);
    throw new IllegalStateException(message);
  }
}
 
Example 2
Source File: ServerRMProxy.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@InterfaceAudience.Private
@Override
protected InetSocketAddress getRMAddress(YarnConfiguration conf,
                                         Class<?> protocol) {
  if (protocol == ResourceTracker.class) {
    return conf.getSocketAddr(
      YarnConfiguration.RM_RESOURCE_TRACKER_ADDRESS,
      YarnConfiguration.DEFAULT_RM_RESOURCE_TRACKER_ADDRESS,
      YarnConfiguration.DEFAULT_RM_RESOURCE_TRACKER_PORT);
  } else {
    String message = "Unsupported protocol found when creating the proxy " +
        "connection to ResourceManager: " +
        ((protocol != null) ? protocol.getClass().getName() : "null");
    LOG.error(message);
    throw new IllegalStateException(message);
  }
}
 
Example 3
Source File: RMWebApp.java    From hadoop with Apache License 2.0 6 votes vote down vote up
private String buildRedirectPath() {
  // make a copy of the original configuration so not to mutate it. Also use
  // an YarnConfiguration to force loading of yarn-site.xml.
  YarnConfiguration yarnConf = new YarnConfiguration(rm.getConfig());
  String activeRMHAId = RMHAUtils.findActiveRMHAId(yarnConf);
  String path = "";
  if (activeRMHAId != null) {
    yarnConf.set(YarnConfiguration.RM_HA_ID, activeRMHAId);

    InetSocketAddress sock = YarnConfiguration.useHttps(yarnConf)
        ? yarnConf.getSocketAddr(YarnConfiguration.RM_WEBAPP_HTTPS_ADDRESS,
            YarnConfiguration.DEFAULT_RM_WEBAPP_HTTPS_ADDRESS,
            YarnConfiguration.DEFAULT_RM_WEBAPP_HTTPS_PORT)
        : yarnConf.getSocketAddr(YarnConfiguration.RM_WEBAPP_ADDRESS,
            YarnConfiguration.DEFAULT_RM_WEBAPP_ADDRESS,
            YarnConfiguration.DEFAULT_RM_WEBAPP_PORT);

    path = sock.getHostName() + ":" + Integer.toString(sock.getPort());
    path = YarnConfiguration.useHttps(yarnConf)
        ? "https://" + path
        : "http://" + path;
  }
  return path;
}
 
Example 4
Source File: ClientRMProxy.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Private
@Override
protected InetSocketAddress getRMAddress(YarnConfiguration conf,
    Class<?> protocol) throws IOException {
  if (protocol == ApplicationClientProtocol.class) {
    return conf.getSocketAddr(YarnConfiguration.RM_ADDRESS,
        YarnConfiguration.DEFAULT_RM_ADDRESS,
        YarnConfiguration.DEFAULT_RM_PORT);
  } else if (protocol == ResourceManagerAdministrationProtocol.class) {
    return conf.getSocketAddr(
        YarnConfiguration.RM_ADMIN_ADDRESS,
        YarnConfiguration.DEFAULT_RM_ADMIN_ADDRESS,
        YarnConfiguration.DEFAULT_RM_ADMIN_PORT);
  } else if (protocol == ApplicationMasterProtocol.class) {
    setAMRMTokenService(conf);
    return conf.getSocketAddr(YarnConfiguration.RM_SCHEDULER_ADDRESS,
        YarnConfiguration.DEFAULT_RM_SCHEDULER_ADDRESS,
        YarnConfiguration.DEFAULT_RM_SCHEDULER_PORT);
  } else {
    String message = "Unsupported protocol found when creating the proxy " +
        "connection to ResourceManager: " +
        ((protocol != null) ? protocol.getClass().getName() : "null");
    LOG.error(message);
    throw new IllegalStateException(message);
  }
}
 
Example 5
Source File: RMWebApp.java    From big-c with Apache License 2.0 6 votes vote down vote up
private String buildRedirectPath() {
  // make a copy of the original configuration so not to mutate it. Also use
  // an YarnConfiguration to force loading of yarn-site.xml.
  YarnConfiguration yarnConf = new YarnConfiguration(rm.getConfig());
  String activeRMHAId = RMHAUtils.findActiveRMHAId(yarnConf);
  String path = "";
  if (activeRMHAId != null) {
    yarnConf.set(YarnConfiguration.RM_HA_ID, activeRMHAId);

    InetSocketAddress sock = YarnConfiguration.useHttps(yarnConf)
        ? yarnConf.getSocketAddr(YarnConfiguration.RM_WEBAPP_HTTPS_ADDRESS,
            YarnConfiguration.DEFAULT_RM_WEBAPP_HTTPS_ADDRESS,
            YarnConfiguration.DEFAULT_RM_WEBAPP_HTTPS_PORT)
        : yarnConf.getSocketAddr(YarnConfiguration.RM_WEBAPP_ADDRESS,
            YarnConfiguration.DEFAULT_RM_WEBAPP_ADDRESS,
            YarnConfiguration.DEFAULT_RM_WEBAPP_PORT);

    path = sock.getHostName() + ":" + Integer.toString(sock.getPort());
    path = YarnConfiguration.useHttps(yarnConf)
        ? "https://" + path
        : "http://" + path;
  }
  return path;
}
 
Example 6
Source File: ServerRMProxy.java    From big-c with Apache License 2.0 6 votes vote down vote up
@InterfaceAudience.Private
@Override
protected InetSocketAddress getRMAddress(YarnConfiguration conf,
                                         Class<?> protocol) {
  if (protocol == ResourceTracker.class) {
    return conf.getSocketAddr(
      YarnConfiguration.RM_RESOURCE_TRACKER_ADDRESS,
      YarnConfiguration.DEFAULT_RM_RESOURCE_TRACKER_ADDRESS,
      YarnConfiguration.DEFAULT_RM_RESOURCE_TRACKER_PORT);
  } else {
    String message = "Unsupported protocol found when creating the proxy " +
        "connection to ResourceManager: " +
        ((protocol != null) ? protocol.getClass().getName() : "null");
    LOG.error(message);
    throw new IllegalStateException(message);
  }
}
 
Example 7
Source File: ResourceMgrDelegate.java    From tez with Apache License 2.0 5 votes vote down vote up
/**
 * Delegate responsible for communicating with the Resource Manager's {@link ApplicationClientProtocol}.
 * @param conf the configuration object.
 */
public ResourceMgrDelegate(YarnConfiguration conf) {
  super();
  this.conf = conf;
  client = YarnClient.createYarnClient();
  client.init(conf);
  this.rmAddress = conf.getSocketAddr(YarnConfiguration.RM_ADDRESS,
      YarnConfiguration.DEFAULT_RM_ADDRESS,
      YarnConfiguration.DEFAULT_RM_PORT);
  client.start();
}
 
Example 8
Source File: StramClientUtils.java    From Bats with Apache License 2.0 5 votes vote down vote up
/**
 * Connect to the Resource Manager/Applications Manager<p>
 *
 * @return Handle to communicate with the ASM
 * @throws IOException
 */
public ApplicationClientProtocol connectToASM() throws IOException
{
  YarnConfiguration yarnConf = new YarnConfiguration(conf);
  InetSocketAddress rmAddress = yarnConf.getSocketAddr(
      YarnConfiguration.RM_ADDRESS,
      YarnConfiguration.DEFAULT_RM_ADDRESS,
      YarnConfiguration.DEFAULT_RM_PORT);
  LOG.debug("Connecting to ResourceManager at " + rmAddress);
  return ((ApplicationClientProtocol)rpc.getProxy(ApplicationClientProtocol.class, rmAddress, conf));
}
 
Example 9
Source File: ResourceMgrDelegate.java    From incubator-tez with Apache License 2.0 5 votes vote down vote up
/**
 * Delegate responsible for communicating with the Resource Manager's {@link ApplicationClientProtocol}.
 * @param conf the configuration object.
 */
public ResourceMgrDelegate(YarnConfiguration conf) {
  super();
  this.conf = conf;
  client = YarnClient.createYarnClient();
  client.init(conf);
  this.rmAddress = conf.getSocketAddr(YarnConfiguration.RM_ADDRESS,
      YarnConfiguration.DEFAULT_RM_ADDRESS,
      YarnConfiguration.DEFAULT_RM_PORT);
  client.start();
}
 
Example 10
Source File: StramClientUtils.java    From attic-apex-core with Apache License 2.0 5 votes vote down vote up
public InetSocketAddress getRMHAAddress(String rmId)
{
  YarnConfiguration yarnConf = StramClientUtils.getYarnConfiguration(conf);
  yarnConf.set(ConfigUtils.RM_HA_ID, rmId);
  InetSocketAddress socketAddr = yarnConf.getSocketAddr(YarnConfiguration.RM_ADDRESS, YarnConfiguration.DEFAULT_RM_ADDRESS, YarnConfiguration.DEFAULT_RM_PORT);
  yarnConf.unset(ConfigUtils.RM_HA_ID);
  return socketAddr;
}
 
Example 11
Source File: StramClientUtils.java    From attic-apex-core with Apache License 2.0 5 votes vote down vote up
/**
 * Connect to the Resource Manager/Applications Manager<p>
 *
 * @return Handle to communicate with the ASM
 * @throws IOException
 */
public ApplicationClientProtocol connectToASM() throws IOException
{
  YarnConfiguration yarnConf = new YarnConfiguration(conf);
  InetSocketAddress rmAddress = yarnConf.getSocketAddr(
      YarnConfiguration.RM_ADDRESS,
      YarnConfiguration.DEFAULT_RM_ADDRESS,
      YarnConfiguration.DEFAULT_RM_PORT);
  LOG.debug("Connecting to ResourceManager at " + rmAddress);
  return ((ApplicationClientProtocol)rpc.getProxy(ApplicationClientProtocol.class, rmAddress, conf));
}
 
Example 12
Source File: SCMAdmin.java    From big-c with Apache License 2.0 5 votes vote down vote up
protected SCMAdminProtocol createSCMAdminProtocol() throws IOException {
  // Get the current configuration
  final YarnConfiguration conf = new YarnConfiguration(getConf());

  // Create the admin client
  final InetSocketAddress addr = conf.getSocketAddr(
      YarnConfiguration.SCM_ADMIN_ADDRESS,
      YarnConfiguration.DEFAULT_SCM_ADMIN_ADDRESS,
      YarnConfiguration.DEFAULT_SCM_ADMIN_PORT);
  final YarnRPC rpc = YarnRPC.create(conf);
  SCMAdminProtocol scmAdminProtocol =
      (SCMAdminProtocol) rpc.getProxy(SCMAdminProtocol.class, addr, conf);
  return scmAdminProtocol;
}
 
Example 13
Source File: RMHAServiceTarget.java    From big-c with Apache License 2.0 5 votes vote down vote up
public RMHAServiceTarget(YarnConfiguration conf)
    throws IOException {
  autoFailoverEnabled = HAUtil.isAutomaticFailoverEnabled(conf);
  haAdminServiceAddress = conf.getSocketAddr(
      YarnConfiguration.RM_ADMIN_ADDRESS,
      YarnConfiguration.DEFAULT_RM_ADMIN_ADDRESS,
      YarnConfiguration.DEFAULT_RM_ADMIN_PORT);
}
 
Example 14
Source File: SCMAdmin.java    From hadoop with Apache License 2.0 5 votes vote down vote up
protected SCMAdminProtocol createSCMAdminProtocol() throws IOException {
  // Get the current configuration
  final YarnConfiguration conf = new YarnConfiguration(getConf());

  // Create the admin client
  final InetSocketAddress addr = conf.getSocketAddr(
      YarnConfiguration.SCM_ADMIN_ADDRESS,
      YarnConfiguration.DEFAULT_SCM_ADMIN_ADDRESS,
      YarnConfiguration.DEFAULT_SCM_ADMIN_PORT);
  final YarnRPC rpc = YarnRPC.create(conf);
  SCMAdminProtocol scmAdminProtocol =
      (SCMAdminProtocol) rpc.getProxy(SCMAdminProtocol.class, addr, conf);
  return scmAdminProtocol;
}
 
Example 15
Source File: RMHAServiceTarget.java    From hadoop with Apache License 2.0 5 votes vote down vote up
public RMHAServiceTarget(YarnConfiguration conf)
    throws IOException {
  autoFailoverEnabled = HAUtil.isAutomaticFailoverEnabled(conf);
  haAdminServiceAddress = conf.getSocketAddr(
      YarnConfiguration.RM_ADMIN_ADDRESS,
      YarnConfiguration.DEFAULT_RM_ADMIN_ADDRESS,
      YarnConfiguration.DEFAULT_RM_ADMIN_PORT);
}
 
Example 16
Source File: StramClientUtils.java    From Bats with Apache License 2.0 5 votes vote down vote up
public InetSocketAddress getRMHAAddress(String rmId)
{
  YarnConfiguration yarnConf = StramClientUtils.getYarnConfiguration(conf);
  yarnConf.set(ConfigUtils.RM_HA_ID, rmId);
  InetSocketAddress socketAddr = yarnConf.getSocketAddr(YarnConfiguration.RM_ADDRESS, YarnConfiguration.DEFAULT_RM_ADDRESS, YarnConfiguration.DEFAULT_RM_PORT);
  yarnConf.unset(ConfigUtils.RM_HA_ID);
  return socketAddr;
}
 
Example 17
Source File: Hadoop23YarnAppClient.java    From twill with Apache License 2.0 4 votes vote down vote up
/**
 * Overrides parent method to adds RM delegation token to the given context. If YARN is running with HA RM,
 * delegation tokens for each RM service will be added.
 */
protected void addRMToken(ContainerLaunchContext context, YarnClient yarnClient, ApplicationId appId) {
  if (!UserGroupInformation.isSecurityEnabled()) {
    return;
  }

  try {
    Text renewer = new Text(UserGroupInformation.getCurrentUser().getShortUserName());
    org.apache.hadoop.yarn.api.records.Token rmDelegationToken = yarnClient.getRMDelegationToken(renewer);

    // The following logic is copied from ClientRMProxy.getRMDelegationTokenService, which is not available in
    // YARN older than 2.4
    List<String> services = new ArrayList<>();
    if (HAUtil.isHAEnabled(configuration)) {
      // If HA is enabled, we need to enumerate all RM hosts
      // and add the corresponding service name to the token service
      // Copy the yarn conf since we need to modify it to get the RM addresses
      YarnConfiguration yarnConf = new YarnConfiguration(configuration);
      for (String rmId : HAUtil.getRMHAIds(configuration)) {
        yarnConf.set(YarnConfiguration.RM_HA_ID, rmId);
        InetSocketAddress address = yarnConf.getSocketAddr(YarnConfiguration.RM_ADDRESS,
                                                           YarnConfiguration.DEFAULT_RM_ADDRESS,
                                                           YarnConfiguration.DEFAULT_RM_PORT);
        services.add(SecurityUtil.buildTokenService(address).toString());
      }
    } else {
      services.add(SecurityUtil.buildTokenService(YarnUtils.getRMAddress(configuration)).toString());
    }

    Credentials credentials = YarnUtils.decodeCredentials(context.getTokens());

    // casting needed for later Hadoop version
    @SuppressWarnings("RedundantCast")
    Token<TokenIdentifier> token = ConverterUtils.convertFromYarn(rmDelegationToken, (InetSocketAddress) null);

    token.setService(new Text(Joiner.on(',').join(services)));
    credentials.addToken(new Text(token.getService()), token);

    LOG.debug("Added RM delegation token {} for application {}", token, appId);
    credentials.addToken(token.getService(), token);

    context.setTokens(YarnUtils.encodeCredentials(credentials));

  } catch (Exception e) {
    throw Throwables.propagate(e);
  }
}
 
Example 18
Source File: ConfigUtils.java    From attic-apex-core with Apache License 2.0 4 votes vote down vote up
public static InetSocketAddress getRMAddress(YarnConfiguration conf)
{
  return conf.getSocketAddr(YarnConfiguration.RM_ADDRESS,
      YarnConfiguration.DEFAULT_RM_ADDRESS,
      YarnConfiguration.DEFAULT_RM_PORT);
}
 
Example 19
Source File: ConfigUtils.java    From Bats with Apache License 2.0 4 votes vote down vote up
public static InetSocketAddress getRMAddress(YarnConfiguration conf)
{
  return conf.getSocketAddr(YarnConfiguration.RM_ADDRESS,
      YarnConfiguration.DEFAULT_RM_ADDRESS,
      YarnConfiguration.DEFAULT_RM_PORT);
}