Example usage for org.apache.hadoop.yarn.client RMHAServiceTarget getAddress

List of usage examples for org.apache.hadoop.yarn.client RMHAServiceTarget getAddress

Introduction

In this page you can find the example usage for org.apache.hadoop.yarn.client RMHAServiceTarget getAddress.

Prototype

@Override
    public InetSocketAddress getAddress() 

Source Link

Usage

From source file:co.cask.cdap.operations.yarn.YarnInfo.java

License:Apache License

/**
 * Should only be called when HA is enabled.
 *//*from  www.ja v  a 2 s .com*/
private URL getHAWebURL() throws IOException {
    InetSocketAddress activeRM = null;
    Collection<String> rmIds = HAUtil.getRMHAIds(conf);
    if (rmIds.isEmpty()) {
        throw new IllegalStateException("Resource Manager HA web URL requested in non-HA mode.");
    }
    for (String rmId : rmIds) {
        YarnConfiguration yarnConf = new YarnConfiguration(conf);
        yarnConf.set(YarnConfiguration.RM_HA_ID, rmId);
        yarnConf.set(CommonConfigurationKeys.HADOOP_SECURITY_SERVICE_USER_NAME_KEY,
                conf.get(YarnConfiguration.RM_PRINCIPAL, ""));
        RMHAServiceTarget rmhaServiceTarget = new RMHAServiceTarget(yarnConf);
        HAServiceProtocol proxy = rmhaServiceTarget.getProxy(yarnConf, 10000);
        HAServiceStatus serviceStatus = proxy.getServiceStatus();
        if (HAServiceProtocol.HAServiceState.ACTIVE != serviceStatus.getState()) {
            continue;
        }
        activeRM = rmhaServiceTarget.getAddress();
    }
    if (activeRM == null) {
        throw new IllegalStateException("Could not find an active resource manager");
    }
    return adminToWebappAddress(activeRM);
}