|
@@ -44,6 +44,7 @@ import org.apache.hadoop.yarn.api.records.ApplicationReport;
|
|
|
import org.apache.hadoop.yarn.client.api.AppAdminClient;
|
|
|
import org.apache.hadoop.yarn.client.api.YarnClient;
|
|
|
import org.apache.hadoop.yarn.client.util.YarnClientUtils;
|
|
|
+import org.apache.hadoop.yarn.conf.HAUtil;
|
|
|
import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
|
|
import org.apache.hadoop.yarn.exceptions.YarnException;
|
|
|
import org.apache.hadoop.yarn.service.api.records.Component;
|
|
@@ -94,7 +95,7 @@ public class ApiServiceClient extends AppAdminClient {
|
|
|
/**
|
|
|
* Calculate Resource Manager address base on working REST API.
|
|
|
*/
|
|
|
- String getRMWebAddress() {
|
|
|
+ String getRMWebAddress() throws IOException {
|
|
|
Configuration conf = getConfig();
|
|
|
String scheme = "http://";
|
|
|
String path = "/app/v1/services/version";
|
|
@@ -105,43 +106,50 @@ public class ApiServiceClient extends AppAdminClient {
|
|
|
rmAddress = conf
|
|
|
.get("yarn.resourcemanager.webapp.https.address");
|
|
|
}
|
|
|
- boolean useKerberos = UserGroupInformation.isSecurityEnabled();
|
|
|
- List<String> rmServers = getRMHAWebAddresses(conf);
|
|
|
- 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);
|
|
|
+
|
|
|
+ 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");
|
|
|
}
|
|
|
- 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) {
|
|
|
- rmAddress = host;
|
|
|
- break;
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- LOG.info("Fail to connect to: "+host);
|
|
|
- LOG.debug("Root cause: {}", e);
|
|
|
}
|
|
|
+ throw new IOException(diagnosticsMsg.toString());
|
|
|
}
|
|
|
return scheme+rmAddress;
|
|
|
}
|