|
@@ -18,17 +18,12 @@
|
|
|
|
|
|
package org.apache.hadoop.yarn.server.webproxy.amfilter;
|
|
|
|
|
|
-import java.io.IOException;
|
|
|
-import java.net.InetAddress;
|
|
|
-import java.net.MalformedURLException;
|
|
|
-import java.net.URL;
|
|
|
-import java.net.UnknownHostException;
|
|
|
-import java.net.HttpURLConnection;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.HashSet;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Set;
|
|
|
-import java.util.Collection;
|
|
|
+import com.google.common.annotations.VisibleForTesting;
|
|
|
+import org.apache.hadoop.classification.InterfaceAudience.Public;
|
|
|
+import org.apache.hadoop.yarn.server.webproxy.ProxyUtils;
|
|
|
+import org.apache.hadoop.yarn.server.webproxy.WebAppProxyServlet;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
|
|
import javax.servlet.Filter;
|
|
|
import javax.servlet.FilterChain;
|
|
@@ -39,15 +34,16 @@ import javax.servlet.ServletResponse;
|
|
|
import javax.servlet.http.Cookie;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
-
|
|
|
-import com.google.common.annotations.VisibleForTesting;
|
|
|
-import org.apache.hadoop.classification.InterfaceAudience.Public;
|
|
|
-import org.apache.hadoop.yarn.conf.HAUtil;
|
|
|
-import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
|
|
-import org.apache.hadoop.yarn.server.webproxy.ProxyUtils;
|
|
|
-import org.apache.hadoop.yarn.server.webproxy.WebAppProxyServlet;
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
+import java.io.IOException;
|
|
|
+import java.net.HttpURLConnection;
|
|
|
+import java.net.InetAddress;
|
|
|
+import java.net.MalformedURLException;
|
|
|
+import java.net.URL;
|
|
|
+import java.net.UnknownHostException;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
|
|
|
@Public
|
|
|
public class AmIpFilter implements Filter {
|
|
@@ -70,6 +66,7 @@ public class AmIpFilter implements Filter {
|
|
|
private long lastUpdate;
|
|
|
@VisibleForTesting
|
|
|
Map<String, String> proxyUriBases;
|
|
|
+ String rmUrls[] = null;
|
|
|
|
|
|
@Override
|
|
|
public void init(FilterConfig conf) throws ServletException {
|
|
@@ -95,6 +92,10 @@ public class AmIpFilter implements Filter {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ if (conf.getInitParameter(AmFilterInitializer.RM_HA_URLS) != null) {
|
|
|
+ rmUrls = conf.getInitParameter(AmFilterInitializer.RM_HA_URLS).split(",");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
protected Set<String> getProxyAddresses() throws ServletException {
|
|
@@ -196,13 +197,11 @@ public class AmIpFilter implements Filter {
|
|
|
if (proxyUriBases.size() == 1) {
|
|
|
// external proxy or not RM HA
|
|
|
addr = proxyUriBases.values().iterator().next();
|
|
|
- } else {
|
|
|
- // RM HA
|
|
|
- YarnConfiguration conf = new YarnConfiguration();
|
|
|
- for (String rmId : getRmIds(conf)) {
|
|
|
- String url = getUrlByRmId(conf, rmId);
|
|
|
- if (isValidUrl(url)) {
|
|
|
- addr = url;
|
|
|
+ } else if (rmUrls != null) {
|
|
|
+ for (String url : rmUrls) {
|
|
|
+ String host = proxyUriBases.get(url);
|
|
|
+ if (isValidUrl(host)) {
|
|
|
+ addr = host;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -215,26 +214,12 @@ public class AmIpFilter implements Filter {
|
|
|
return addr;
|
|
|
}
|
|
|
|
|
|
- @VisibleForTesting
|
|
|
- Collection<String> getRmIds(YarnConfiguration conf) {
|
|
|
- return conf.getStringCollection(YarnConfiguration.RM_HA_IDS);
|
|
|
- }
|
|
|
-
|
|
|
- @VisibleForTesting
|
|
|
- String getUrlByRmId(YarnConfiguration conf, String rmId) {
|
|
|
- String addressPropertyPrefix = YarnConfiguration.useHttps(conf) ?
|
|
|
- YarnConfiguration.RM_WEBAPP_HTTPS_ADDRESS :
|
|
|
- YarnConfiguration.RM_WEBAPP_ADDRESS;
|
|
|
- String host = conf.get(HAUtil.addSuffix(addressPropertyPrefix, rmId));
|
|
|
- return proxyUriBases.get(host);
|
|
|
- }
|
|
|
-
|
|
|
@VisibleForTesting
|
|
|
public boolean isValidUrl(String url) {
|
|
|
boolean isValid = false;
|
|
|
try {
|
|
|
- HttpURLConnection conn =
|
|
|
- (HttpURLConnection) new URL(url).openConnection();
|
|
|
+ HttpURLConnection conn = (HttpURLConnection) new URL(url)
|
|
|
+ .openConnection();
|
|
|
conn.connect();
|
|
|
isValid = conn.getResponseCode() == HttpURLConnection.HTTP_OK;
|
|
|
} catch (Exception e) {
|