YARN-6627. Use deployed webapp folder to launch new YARN UI. Contributed by Sunil G

This commit is contained in:
Jian He 2017-05-19 20:12:06 -07:00
parent 9855225a79
commit e135c0b207
2 changed files with 29 additions and 10 deletions

View File

@ -180,7 +180,7 @@
</fileSet> </fileSet>
<fileSet> <fileSet>
<directory>hadoop-yarn/hadoop-yarn-ui/target/hadoop-yarn-ui-${project.version}</directory> <directory>hadoop-yarn/hadoop-yarn-ui/target/hadoop-yarn-ui-${project.version}</directory>
<outputDirectory>/share/hadoop/${hadoop.component}/webapps/rm</outputDirectory> <outputDirectory>/share/hadoop/${hadoop.component}/webapps/ui2</outputDirectory>
<includes> <includes>
<include>**/*</include> <include>**/*</include>
</includes> </includes>
@ -188,6 +188,9 @@
</fileSets> </fileSets>
<moduleSets> <moduleSets>
<moduleSet> <moduleSet>
<excludes>
<exclude>org.apache.hadoop:hadoop-yarn-ui</exclude>
</excludes>
<binaries> <binaries>
<outputDirectory>share/hadoop/${hadoop.component}</outputDirectory> <outputDirectory>share/hadoop/${hadoop.component}</outputDirectory>
<includeDependencies>false</includeDependencies> <includeDependencies>false</includeDependencies>

View File

@ -113,6 +113,8 @@
import org.eclipse.jetty.webapp.WebAppContext; import org.eclipse.jetty.webapp.WebAppContext;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.PrintStream; import java.io.PrintStream;
@ -1068,33 +1070,47 @@ protected void startWepApp() {
WebAppContext uiWebAppContext = null; WebAppContext uiWebAppContext = null;
if (getConfig().getBoolean(YarnConfiguration.YARN_WEBAPP_UI2_ENABLE, if (getConfig().getBoolean(YarnConfiguration.YARN_WEBAPP_UI2_ENABLE,
YarnConfiguration.DEFAULT_YARN_WEBAPP_UI2_ENABLE)) { YarnConfiguration.DEFAULT_YARN_WEBAPP_UI2_ENABLE)) {
String webPath = UI2_WEBAPP_NAME;
String onDiskPath = getConfig() String onDiskPath = getConfig()
.get(YarnConfiguration.YARN_WEBAPP_UI2_WARFILE_PATH); .get(YarnConfiguration.YARN_WEBAPP_UI2_WARFILE_PATH);
uiWebAppContext = new WebAppContext();
uiWebAppContext.setContextPath(UI2_WEBAPP_NAME);
if (null == onDiskPath) { if (null == onDiskPath) {
String war = "hadoop-yarn-ui-" + VersionInfo.getVersion() + ".war"; String war = "hadoop-yarn-ui-" + VersionInfo.getVersion() + ".war";
URLClassLoader cl = (URLClassLoader) ClassLoader.getSystemClassLoader(); URLClassLoader cl = (URLClassLoader) ClassLoader.getSystemClassLoader();
URL url = cl.findResource(war); URL url = cl.findResource(war);
if (null == url) { if (null == url) {
onDiskPath = ""; onDiskPath = getWebAppsPath("ui2");
} else { } else {
onDiskPath = url.getFile(); onDiskPath = url.getFile();
} }
LOG.info(
"New web UI war file name:" + war + ", and path:" + onDiskPath);
} }
if (onDiskPath == null || onDiskPath.isEmpty()) {
uiWebAppContext = new WebAppContext(); LOG.error("No war file or webapps found for ui2 !");
uiWebAppContext.setContextPath(webPath); } else {
if (onDiskPath.endsWith(".war")) {
uiWebAppContext.setWar(onDiskPath); uiWebAppContext.setWar(onDiskPath);
LOG.info("Using war file at: " + onDiskPath);
} else {
uiWebAppContext.setResourceBase(onDiskPath);
LOG.info("Using webapps at: " + onDiskPath);
}
}
} }
webApp = builder.start(new RMWebApp(this), uiWebAppContext); webApp = builder.start(new RMWebApp(this), uiWebAppContext);
} }
private String getWebAppsPath(String appName) {
URL url = getClass().getClassLoader().getResource("webapps/" + appName);
if (url == null) {
return "";
}
return url.toString();
}
/** /**
* Helper method to create and init {@link #activeServices}. This creates an * Helper method to create and init {@link #activeServices}. This creates an
* instance of {@link RMActiveServices} and initializes it. * instance of {@link RMActiveServices} and initializes it.