Example usage for org.apache.hadoop.ha HAServiceProtocol getServiceStatus

List of usage examples for org.apache.hadoop.ha HAServiceProtocol getServiceStatus

Introduction

In this page you can find the example usage for org.apache.hadoop.ha HAServiceProtocol getServiceStatus.

Prototype

@Idempotent
public HAServiceStatus getServiceStatus() throws AccessControlException, IOException;

Source Link

Document

Return the current status of the service.

Usage

From source file:co.cask.cdap.operations.hdfs.HDFSInfo.java

License:Apache License

@Nullable
private URL getHAWebURL() throws IOException {
    String activeNamenode = null;
    String nameService = getNameService();
    HdfsConfiguration hdfsConf = new HdfsConfiguration(conf);
    String nameNodePrincipal = conf.get(DFSConfigKeys.DFS_NAMENODE_USER_NAME_KEY, "");

    hdfsConf.set(CommonConfigurationKeys.HADOOP_SECURITY_SERVICE_USER_NAME_KEY, nameNodePrincipal);

    for (String nnId : DFSUtil.getNameNodeIds(conf, nameService)) {
        HAServiceTarget haServiceTarget = new NNHAServiceTarget(hdfsConf, nameService, nnId);
        HAServiceProtocol proxy = haServiceTarget.getProxy(hdfsConf, 10000);
        HAServiceStatus serviceStatus = proxy.getServiceStatus();
        if (HAServiceProtocol.HAServiceState.ACTIVE != serviceStatus.getState()) {
            continue;
        }// ww w.  j  av a2  s .  c o m
        activeNamenode = DFSUtil.getNamenodeServiceAddr(hdfsConf, nameService, nnId);
    }
    if (activeNamenode == null) {
        throw new IllegalStateException("Could not find an active namenode");
    }
    return rpcToHttpAddress(URI.create(activeNamenode));
}

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

License:Apache License

/**
 * Should only be called when HA is enabled.
 */// w  w  w . java  2s .c om
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);
}