|
@@ -45,6 +45,11 @@ public class Services {
|
|
|
private static final String YARN_RESOURCEMANAGER_HA_RM_IDS_KEY = "yarn.resourcemanager.ha.rm-ids";
|
|
|
private static final String YARN_RESOURCEMANAGER_HTTP_HA_PARTIAL_KEY = "yarn.resourcemanager.webapp.address.";
|
|
|
private static final String YARN_RESOURCEMANAGER_HTTPS_HA_PARTIAL_KEY = "yarn.resourcemanager.webapp.https.address.";
|
|
|
+ private static final String YARN_RESOURCEMANAGER_HOSTNAME_KEY = "yarn.resourcemanager.hostname";
|
|
|
+ private static final String YARN_RESOURCEMANAGER_HOSTNAME_PARTIAL_KEY = YARN_RESOURCEMANAGER_HOSTNAME_KEY + ".";
|
|
|
+ private static final String YARN_RESOURCEMANAGER_DEFAULT_HTTP_PORT = "8088";
|
|
|
+ private static final String YARN_RESOURCEMANAGER_DEFAULT_HTTPS_PORT = "8090";
|
|
|
+
|
|
|
|
|
|
private static final String YARN_ATS_URL = "yarn.timeline-server.url";
|
|
|
private final static String YARN_TIMELINE_WEBAPP_HTTP_ADDRESS_KEY = "yarn.timeline-service.webapp.address";
|
|
@@ -80,10 +85,9 @@ public class Services {
|
|
|
|
|
|
private String getRMUrlFromClusterConfig() {
|
|
|
String url;
|
|
|
- String protocol;
|
|
|
|
|
|
- String haEnabled = ambariApi.getCluster().getConfigurationValue(YARN_SITE, YARN_RESOURCEMANAGER_HA_ENABLED);
|
|
|
- String httpPolicy = ambariApi.getCluster().getConfigurationValue(YARN_SITE, YARN_HTTP_POLICY);
|
|
|
+ String haEnabled = getYarnConfig(YARN_RESOURCEMANAGER_HA_ENABLED);
|
|
|
+ String httpPolicy = getYarnConfig(YARN_HTTP_POLICY);
|
|
|
|
|
|
if (!(HTTP_ONLY.equals(httpPolicy) || HTTPS_ONLY.equals(httpPolicy))) {
|
|
|
LOG.error(String.format("RA030 Unknown value %s of yarn-site/yarn.http.policy. HTTP_ONLY assumed.", httpPolicy));
|
|
@@ -94,34 +98,32 @@ public class Services {
|
|
|
String[] urls = getRMHAUrls(httpPolicy);
|
|
|
url = getActiveRMUrl(urls);
|
|
|
} else {
|
|
|
- if (httpPolicy.equals(HTTPS_ONLY)) {
|
|
|
- protocol = "https";
|
|
|
- url = ambariApi.getCluster().getConfigurationValue(YARN_SITE, YARN_RESOURCEMANAGER_HTTPS_KEY);
|
|
|
- } else {
|
|
|
- protocol = "http";
|
|
|
- url = ambariApi.getCluster().getConfigurationValue(YARN_SITE, YARN_RESOURCEMANAGER_HTTP_KEY);
|
|
|
+ url = (httpPolicy.equals(HTTPS_ONLY)) ? getYarnConfig(YARN_RESOURCEMANAGER_HTTPS_KEY)
|
|
|
+ : getYarnConfig(YARN_RESOURCEMANAGER_HTTP_KEY);
|
|
|
+
|
|
|
+ if (url == null || url.isEmpty()) {
|
|
|
+ url = getYarnConfig(YARN_RESOURCEMANAGER_HOSTNAME_KEY).trim() + ":" + getDefaultRMPort(httpPolicy);
|
|
|
}
|
|
|
- url = addProtocolIfMissing(url, protocol);
|
|
|
+
|
|
|
+ url = addProtocolIfMissing(url, getProtocol(httpPolicy));
|
|
|
}
|
|
|
return url;
|
|
|
}
|
|
|
|
|
|
private String[] getRMHAUrls(String httpPolicy) {
|
|
|
- String haRmIds = ambariApi.getCluster().getConfigurationValue(YARN_SITE, YARN_RESOURCEMANAGER_HA_RM_IDS_KEY);
|
|
|
+ String haRmIds = getYarnConfig(YARN_RESOURCEMANAGER_HA_RM_IDS_KEY);
|
|
|
String[] ids = haRmIds.split(",");
|
|
|
int index = 0;
|
|
|
String[] urls = new String[ids.length];
|
|
|
for (String id : ids) {
|
|
|
- String url, protocol;
|
|
|
- if (HTTPS_ONLY.equals(httpPolicy)) {
|
|
|
- url = ambariApi.getCluster().getConfigurationValue(YARN_SITE, YARN_RESOURCEMANAGER_HTTPS_HA_PARTIAL_KEY + id);
|
|
|
- protocol = "https";
|
|
|
- } else {
|
|
|
- url = ambariApi.getCluster().getConfigurationValue(YARN_SITE, YARN_RESOURCEMANAGER_HTTP_HA_PARTIAL_KEY + id);
|
|
|
- protocol = "http";
|
|
|
+ String url = (HTTPS_ONLY.equals(httpPolicy)) ? getYarnConfig(YARN_RESOURCEMANAGER_HTTPS_HA_PARTIAL_KEY + id)
|
|
|
+ : getYarnConfig(YARN_RESOURCEMANAGER_HTTP_HA_PARTIAL_KEY + id);
|
|
|
+
|
|
|
+ if (url == null || url.isEmpty()) {
|
|
|
+ url = getYarnConfig(YARN_RESOURCEMANAGER_HOSTNAME_PARTIAL_KEY + id).trim() + ":" + getDefaultRMPort(httpPolicy);
|
|
|
}
|
|
|
|
|
|
- urls[index++] = addProtocolIfMissing(url.trim(), protocol);
|
|
|
+ urls[index++] = addProtocolIfMissing(url.trim(), getProtocol(httpPolicy));
|
|
|
}
|
|
|
return urls;
|
|
|
}
|
|
@@ -267,9 +269,8 @@ public class Services {
|
|
|
|
|
|
private String getATSUrlFromCluster() {
|
|
|
String url;
|
|
|
- String protocol;
|
|
|
|
|
|
- String httpPolicy = ambariApi.getCluster().getConfigurationValue(YARN_SITE, YARN_HTTP_POLICY);
|
|
|
+ String httpPolicy = getYarnConfig(YARN_HTTP_POLICY);
|
|
|
|
|
|
if (!(HTTP_ONLY.equals(httpPolicy) || HTTPS_ONLY.equals(httpPolicy))) {
|
|
|
LOG.error(String.format("RA030 Unknown value %s of yarn-site/yarn.http.policy. HTTP_ONLY assumed.", httpPolicy));
|
|
@@ -277,13 +278,11 @@ public class Services {
|
|
|
}
|
|
|
|
|
|
if (httpPolicy.equals(HTTPS_ONLY)) {
|
|
|
- protocol = "https";
|
|
|
- url = ambariApi.getCluster().getConfigurationValue(YARN_SITE, YARN_TIMELINE_WEBAPP_HTTPS_ADDRESS_KEY);
|
|
|
+ url = getYarnConfig(YARN_TIMELINE_WEBAPP_HTTPS_ADDRESS_KEY);
|
|
|
} else {
|
|
|
- protocol = "http";
|
|
|
- url = ambariApi.getCluster().getConfigurationValue(YARN_SITE, YARN_TIMELINE_WEBAPP_HTTP_ADDRESS_KEY);
|
|
|
+ url = getYarnConfig(YARN_TIMELINE_WEBAPP_HTTP_ADDRESS_KEY);
|
|
|
}
|
|
|
- url = addProtocolIfMissing(url, protocol);
|
|
|
+ url = addProtocolIfMissing(url, getProtocol(httpPolicy));
|
|
|
|
|
|
return url;
|
|
|
}
|
|
@@ -317,4 +316,20 @@ public class Services {
|
|
|
public static boolean hasProtocol(String url) {
|
|
|
return url.matches("^[^:]+://.*$");
|
|
|
}
|
|
|
+
|
|
|
+ private String getProtocol(String yarnHttpPolicyConfig) {
|
|
|
+ return HTTPS_ONLY.equals(yarnHttpPolicyConfig) ? "https" : "http";
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getYarnConfig(String key) {
|
|
|
+ return ambariApi.getCluster().getConfigurationValue(YARN_SITE, key);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param yarnHttpPolicy - The HTTP Policy configured in YARN site file
|
|
|
+ * @return The default resource manager port depending on the http policy
|
|
|
+ */
|
|
|
+ private String getDefaultRMPort(String yarnHttpPolicy) {
|
|
|
+ return (HTTPS_ONLY.equals(yarnHttpPolicy)) ? YARN_RESOURCEMANAGER_DEFAULT_HTTPS_PORT : YARN_RESOURCEMANAGER_DEFAULT_HTTP_PORT;
|
|
|
+ }
|
|
|
}
|