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

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

Introduction

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

Prototype

public RMHAServiceTarget(YarnConfiguration conf) throws IOException 

Source Link

Usage

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

License:Apache License

/**
 * Should only be called when HA is enabled.
 *///w ww .  j a v a  2s  .  c  o  m
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);
}