YARN-6476. Advanced Federation UI based on YARN UI v2. (#5920) Contributed by Shilun Fan.

Reviewed-by: Inigo Goiri <inigoiri@apache.org>
Signed-off-by: Shilun Fan <slfan1989@apache.org>
This commit is contained in:
slfan1989 2023-09-11 13:28:31 +08:00 committed by GitHub
parent 3bd6a751ed
commit e4550e1aef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 50 additions and 2 deletions

View File

@ -20,6 +20,7 @@
import java.io.IOException; import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.URL;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.ScheduledThreadPoolExecutor;
@ -38,6 +39,7 @@
import org.apache.hadoop.util.JvmPauseMonitor; import org.apache.hadoop.util.JvmPauseMonitor;
import org.apache.hadoop.util.ShutdownHookManager; import org.apache.hadoop.util.ShutdownHookManager;
import org.apache.hadoop.util.StringUtils; import org.apache.hadoop.util.StringUtils;
import org.apache.hadoop.util.VersionInfo;
import org.apache.hadoop.yarn.YarnUncaughtExceptionHandler; import org.apache.hadoop.yarn.YarnUncaughtExceptionHandler;
import org.apache.hadoop.yarn.conf.YarnConfiguration; import org.apache.hadoop.yarn.conf.YarnConfiguration;
import org.apache.hadoop.yarn.exceptions.YarnRuntimeException; import org.apache.hadoop.yarn.exceptions.YarnRuntimeException;
@ -55,6 +57,7 @@
import org.apache.hadoop.yarn.webapp.WebApps.Builder; import org.apache.hadoop.yarn.webapp.WebApps.Builder;
import org.apache.hadoop.yarn.webapp.util.WebAppUtils; import org.apache.hadoop.yarn.webapp.util.WebAppUtils;
import org.apache.hadoop.yarn.webapp.util.WebServiceClient; import org.apache.hadoop.yarn.webapp.util.WebServiceClient;
import org.eclipse.jetty.webapp.WebAppContext;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -106,6 +109,8 @@ public class Router extends CompositeService {
private static final String METRICS_NAME = "Router"; private static final String METRICS_NAME = "Router";
private static final String UI2_WEBAPP_NAME = "/ui2";
private ScheduledThreadPoolExecutor scheduledExecutorService; private ScheduledThreadPoolExecutor scheduledExecutorService;
private SubClusterCleaner subClusterCleaner; private SubClusterCleaner subClusterCleaner;
@ -226,7 +231,50 @@ public void startWepApp() {
String[] proxyParts = proxyHostAndPort.split(":"); String[] proxyParts = proxyHostAndPort.split(":");
builder.withAttribute(WebAppProxy.PROXY_HOST_ATTRIBUTE, proxyParts[0]); builder.withAttribute(WebAppProxy.PROXY_HOST_ATTRIBUTE, proxyParts[0]);
} }
webApp = builder.start(new RouterWebApp(this)); webApp = builder.start(new RouterWebApp(this), getUIWebAppContext());
}
private WebAppContext getUIWebAppContext() {
WebAppContext uiWebAppContext = null;
boolean isWebUI2Enabled = conf.getBoolean(YarnConfiguration.YARN_WEBAPP_UI2_ENABLE,
YarnConfiguration.DEFAULT_YARN_WEBAPP_UI2_ENABLE);
if(isWebUI2Enabled) {
String onDiskPath = conf.get(YarnConfiguration.YARN_WEBAPP_UI2_WARFILE_PATH);
uiWebAppContext = new WebAppContext();
uiWebAppContext.setContextPath(UI2_WEBAPP_NAME);
if (null == onDiskPath) {
String war = "hadoop-yarn-ui-" + VersionInfo.getVersion() + ".war";
URL url = getClass().getClassLoader().getResource(war);
if (null == url) {
onDiskPath = getWebAppsPath("ui2");
} else {
onDiskPath = url.getFile();
}
}
if (onDiskPath == null || onDiskPath.isEmpty()) {
LOG.error("No war file or webapps found for yarn federation!");
} else {
if (onDiskPath.endsWith(".war")) {
uiWebAppContext.setWar(onDiskPath);
LOG.info("Using war file at: {}.", onDiskPath);
} else {
uiWebAppContext.setResourceBase(onDiskPath);
LOG.info("Using webapps at: {}.", onDiskPath);
}
}
}
return uiWebAppContext;
}
private String getWebAppsPath(String appName) {
URL url = getClass().getClassLoader().getResource("webapps/" + appName);
if (url == null) {
return "";
}
return url.toString();
} }
public static String getProxyHostAndPort(Configuration conf) { public static String getProxyHostAndPort(Configuration conf) {

View File

@ -143,7 +143,7 @@ public void testRouterSupportCrossOrigin() throws ServletException, IOException
WebAppContext webAppContext = httpServer2.getWebAppContext(); WebAppContext webAppContext = httpServer2.getWebAppContext();
ServletHandler servletHandler = webAppContext.getServletHandler(); ServletHandler servletHandler = webAppContext.getServletHandler();
FilterHolder holder = servletHandler.getFilter("Cross Origin Filter"); FilterHolder holder = servletHandler.getFilter("Cross Origin Filter");
CrossOriginFilter filter = CrossOriginFilter.class.cast(holder.getFilter()); CrossOriginFilter filter = (CrossOriginFilter) holder.getFilter();
// 1. Simulate [example.com] for access // 1. Simulate [example.com] for access
HttpServletRequest mockReq = Mockito.mock(HttpServletRequest.class); HttpServletRequest mockReq = Mockito.mock(HttpServletRequest.class);