ApiServiceClient extends AppAdminClient { String getRMWebAddress() throws IOException { Configuration conf = getConfig(); String scheme = "http: String path = "/app/v1/services/version"; String rmAddress = conf .get("yarn.resourcemanager.webapp.address"); if (YarnConfiguration.useHttps(conf)) { scheme = "https: rmAddress = conf .get("yarn.resourcemanager.webapp.https.address"); } if (HAUtil.isHAEnabled(conf)) { boolean useKerberos = UserGroupInformation.isSecurityEnabled(); List<String> rmServers = getRMHAWebAddresses(conf); StringBuilder diagnosticsMsg = new StringBuilder(); for (String host : rmServers) { try { Client client = Client.create(); client.setFollowRedirects(false); StringBuilder sb = new StringBuilder(); sb.append(scheme) .append(host) .append(path); if (!useKerberos) { try { String username = UserGroupInformation.getCurrentUser() .getShortUserName(); sb.append("?user.name=") .append(username); } catch (IOException e) { LOG.debug("Fail to resolve username: {}", e); } } Builder builder = client .resource(sb.toString()).type(MediaType.APPLICATION_JSON); if (useKerberos) { String[] server = host.split(":"); String challenge = YarnClientUtils.generateToken(server[0]); builder.header(HttpHeaders.AUTHORIZATION, "Negotiate " + challenge); LOG.debug("Authorization: Negotiate {}", challenge); } ClientResponse test = builder.get(ClientResponse.class); if (test.getStatus() == 200) { return scheme + host; } } catch (Exception e) { LOG.info("Fail to connect to: " + host); LOG.debug("Root cause: ", e); diagnosticsMsg.append("Error connecting to " + host + " due to " + e.getMessage() + "\n"); } } throw new IOException(diagnosticsMsg.toString()); } return scheme+rmAddress; } ApiServiceClient();  ApiServiceClient(Configuration c); String getServicePath(String appName); Builder getApiClient(); Builder getApiClient(String requestPath); Service loadAppJsonFromLocalFS(String fileName, String serviceName,
      Long lifetime, String queue); @Override int actionLaunch(String fileName, String appName, Long lifetime,
      String queue); @Override int actionStop(String appName); @Override int actionStart(String appName); @Override int actionSave(String fileName, String appName, Long lifetime,
      String queue); @Override int actionDestroy(String appName); @Override int actionFlex(String appName, Map<String, String> componentCounts); @Override int enableFastLaunch(String destinationFolder); @Override String getStatusString(String appIdOrName); @Override int actionUpgradeExpress(String appName, File path); @Override int initiateUpgrade(String appName,
      String fileName, boolean autoFinalize); @Override int actionUpgradeInstances(String appName, List<String> compInstances); @Override int actionUpgradeComponents(String appName, List<String> components); @Override int actionCleanUp(String appName, String userName); @Override String getInstances(String appName, List<String> components,
      String version, List<String> containerStates); @Override int actionCancelUpgrade(
      String appName); @Override int actionDecommissionInstances(String appName, List<String>
      componentInstances);  }
@Test public void testGetRMWebAddress() throws Exception { Configuration conf = new Configuration(); conf.setBoolean(YarnConfiguration.RM_HA_ENABLED, true); conf.set(YarnConfiguration.RM_HA_IDS, "rm1"); conf.set(YarnConfiguration.RM_HA_ID, "rm1"); conf.set("yarn.resourcemanager.webapp.address.rm1", "localhost:0"); ApiServiceClient asc1 = new ApiServiceClient(conf); boolean exceptionCaught = false; String diagnosticsMsg = null; try { String rmWebAddress = asc1.getRMWebAddress(); } catch (IOException e){ exceptionCaught = true; diagnosticsMsg = e.getMessage(); } assertTrue("ApiServiceClient failed to throw exception", exceptionCaught); assertTrue("Exception Message does not match", diagnosticsMsg.contains("Error connecting to localhost:0")); }