[UI1] Provide a way to hide Tools section in Web UIv1. Contributed by Andras Gyori

This commit is contained in:
Szilard Nemeth 2020-08-31 16:00:39 +02:00
parent 60de592a88
commit 4ffe26f9b8
7 changed files with 102 additions and 32 deletions

View File

@ -18,8 +18,11 @@
package org.apache.hadoop.mapreduce.v2.hs.webapp; package org.apache.hadoop.mapreduce.v2.hs.webapp;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.mapreduce.v2.app.webapp.App; import org.apache.hadoop.mapreduce.v2.app.webapp.App;
import org.apache.hadoop.mapreduce.v2.util.MRApps; import org.apache.hadoop.mapreduce.v2.util.MRApps;
import org.apache.hadoop.yarn.conf.YarnConfiguration;
import org.apache.hadoop.yarn.server.webapp.WebPageUtils;
import org.apache.hadoop.yarn.webapp.hamlet2.Hamlet; import org.apache.hadoop.yarn.webapp.hamlet2.Hamlet;
import org.apache.hadoop.yarn.webapp.hamlet2.Hamlet.DIV; import org.apache.hadoop.yarn.webapp.hamlet2.Hamlet.DIV;
import org.apache.hadoop.yarn.webapp.view.HtmlBlock; import org.apache.hadoop.yarn.webapp.view.HtmlBlock;
@ -31,8 +34,12 @@
*/ */
public class HsNavBlock extends HtmlBlock { public class HsNavBlock extends HtmlBlock {
final App app; final App app;
private Configuration conf;
@Inject HsNavBlock(App app) { this.app = app; } @Inject HsNavBlock(App app, Configuration conf) {
this.app = app;
this.conf = conf;
}
/* /*
* (non-Javadoc) * (non-Javadoc)
@ -64,12 +71,11 @@ public class HsNavBlock extends HtmlBlock {
li().a(url("taskcounters", taskid), "Counters").__().__(); li().a(url("taskcounters", taskid), "Counters").__().__();
} }
} }
nav.
h3("Tools"). Hamlet.UL<DIV<Hamlet>> tools = WebPageUtils.appendToolSection(nav, conf);
ul().
li().a("/conf", "Configuration").__(). if (tools != null) {
li().a("/logs", "Local logs").__(). tools.__().__();
li().a("/stacks", "Server stacks").__(). }
li().a("/jmx?qry=Hadoop:*", "Server metrics").__().__().__();
} }
} }

View File

@ -362,6 +362,8 @@ private static void addDeprecatedKeys() {
+ "webapp.ui2.war-file-path"; + "webapp.ui2.war-file-path";
public static final String YARN_API_SERVICES_ENABLE = "yarn." public static final String YARN_API_SERVICES_ENABLE = "yarn."
+ "webapp.api-service.enable"; + "webapp.api-service.enable";
public static final String YARN_WEBAPP_UI1_ENABLE_TOOLS = "yarn."
+ "webapp.ui1.tools.enable";
@Private @Private
public static final String DEFAULT_YARN_API_SYSTEM_SERVICES_CLASS = public static final String DEFAULT_YARN_API_SYSTEM_SERVICES_CLASS =

View File

@ -256,6 +256,12 @@
<value>false</value> <value>false</value>
</property> </property>
<property>
<description>Enable tools section in all ui1 webapp.</description>
<name>yarn.webapp.ui1.tools.enable</name>
<value>true</value>
</property>
<property> <property>
<description> <description>
Explicitly provide WAR file path for ui2 if needed. Explicitly provide WAR file path for ui2 if needed.

View File

@ -18,7 +18,11 @@
package org.apache.hadoop.yarn.server.applicationhistoryservice.webapp; package org.apache.hadoop.yarn.server.applicationhistoryservice.webapp;
import com.google.inject.Inject;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.yarn.api.records.YarnApplicationState; import org.apache.hadoop.yarn.api.records.YarnApplicationState;
import org.apache.hadoop.yarn.conf.YarnConfiguration;
import org.apache.hadoop.yarn.server.webapp.WebPageUtils;
import org.apache.hadoop.yarn.util.Log4jWarningErrorMetricsAppender; import org.apache.hadoop.yarn.util.Log4jWarningErrorMetricsAppender;
import org.apache.hadoop.yarn.webapp.hamlet2.Hamlet; import org.apache.hadoop.yarn.webapp.hamlet2.Hamlet;
import org.apache.hadoop.yarn.webapp.view.HtmlBlock; import org.apache.hadoop.yarn.webapp.view.HtmlBlock;
@ -27,6 +31,13 @@
public class NavBlock extends HtmlBlock { public class NavBlock extends HtmlBlock {
private Configuration conf;
@Inject
public NavBlock(Configuration conf) {
this.conf = conf;
}
@Override @Override
public void render(Block html) { public void render(Block html) {
boolean addErrorsAndWarningsLink = false; boolean addErrorsAndWarningsLink = false;
@ -61,11 +72,11 @@ public void render(Block html) {
__(). __().
__(); __();
Hamlet.UL<Hamlet.DIV<Hamlet>> tools = nav.h3("Tools").ul(); Hamlet.UL<Hamlet.DIV<Hamlet>> tools = WebPageUtils.appendToolSection(nav, conf);
tools.li().a("/conf", "Configuration").__()
.li().a("/logs", "Local logs").__() if (tools == null) {
.li().a("/stacks", "Server stacks").__() return;
.li().a("/jmx?qry=Hadoop:*", "Server metrics").__(); }
if (addErrorsAndWarningsLink) { if (addErrorsAndWarningsLink) {
tools.li().a(url("errors-and-warnings"), "Errors/Warnings").__(); tools.li().a(url("errors-and-warnings"), "Errors/Warnings").__();

View File

@ -18,6 +18,10 @@
package org.apache.hadoop.yarn.server.webapp; package org.apache.hadoop.yarn.server.webapp;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.yarn.conf.YarnConfiguration;
import org.apache.hadoop.yarn.webapp.hamlet2.Hamlet;
import static org.apache.hadoop.yarn.webapp.view.JQueryUI.tableInit; import static org.apache.hadoop.yarn.webapp.view.JQueryUI.tableInit;
@ -112,4 +116,32 @@ public static String resourceRequestsTableInit() {
.toString(); .toString();
} }
/**
* Creates the tool section after a closed section. If it is not enabled,
* the section is created without any links.
* @param section a closed HTML div section
* @param conf configuration object
* @return the tool section, if it is enabled, null otherwise
*/
public static Hamlet.UL<Hamlet.DIV<Hamlet>> appendToolSection(
Hamlet.DIV<Hamlet> section, Configuration conf) {
boolean isToolsEnabled = conf.getBoolean(
YarnConfiguration.YARN_WEBAPP_UI1_ENABLE_TOOLS, true);
Hamlet.DIV<Hamlet> tools = null;
Hamlet.UL<Hamlet.DIV<Hamlet>> enabledTools = null;
if (isToolsEnabled) {
tools = section.h3("Tools");
enabledTools = tools.ul().li().a("/conf", "Configuration").__().
li().a("/logs", "Local logs").__().
li().a("/stacks", "Server stacks").__().
li().a("/jmx?qry=Hadoop:*", "Server metrics").__();
} else {
section.h4("Tools (DISABLED)").__();
}
return enabledTools;
}
} }

View File

@ -19,6 +19,8 @@
package org.apache.hadoop.yarn.server.nodemanager.webapp; package org.apache.hadoop.yarn.server.nodemanager.webapp;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.yarn.conf.YarnConfiguration;
import org.apache.hadoop.yarn.server.webapp.WebPageUtils;
import org.apache.hadoop.yarn.util.Log4jWarningErrorMetricsAppender; import org.apache.hadoop.yarn.util.Log4jWarningErrorMetricsAppender;
import org.apache.hadoop.yarn.webapp.YarnWebParams; import org.apache.hadoop.yarn.webapp.YarnWebParams;
import org.apache.hadoop.yarn.webapp.hamlet2.Hamlet; import org.apache.hadoop.yarn.webapp.hamlet2.Hamlet;
@ -51,7 +53,7 @@ protected void render(Block html) {
String RMWebAppURL = String RMWebAppURL =
WebAppUtils.getResolvedRMWebAppURLWithScheme(this.conf); WebAppUtils.getResolvedRMWebAppURLWithScheme(this.conf);
Hamlet.UL<Hamlet.DIV<Hamlet>> ul = html Hamlet.DIV<Hamlet> ul = html
.div("#nav") .div("#nav")
.h3().__("ResourceManager").__() .h3().__("ResourceManager").__()
.ul() .ul()
@ -65,17 +67,17 @@ protected void render(Block html) {
.__() .__()
.li() .li()
.a(url("allContainers"), "List of Containers").__() .a(url("allContainers"), "List of Containers").__()
.__() .__();
.h3("Tools")
.ul() Hamlet.UL<Hamlet.DIV<Hamlet>> tools = WebPageUtils.appendToolSection(ul, conf);
.li().a("/conf", "Configuration").__()
.li().a("/logs", "Local logs").__() if (tools == null) {
.li().a("/stacks", "Server stacks").__() return;
.li().a("/jmx?qry=Hadoop:*", "Server metrics").__();
if (addErrorsAndWarningsLink) {
ul.li().a(url("errors-and-warnings"), "Errors/Warnings").__();
} }
ul.__().__(); if (addErrorsAndWarningsLink) {
tools.li().a(url("errors-and-warnings"), "Errors/Warnings").__();
}
tools.__().__();
} }
} }

View File

@ -18,7 +18,11 @@
package org.apache.hadoop.yarn.server.resourcemanager.webapp; package org.apache.hadoop.yarn.server.resourcemanager.webapp;
import com.google.inject.Inject;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.yarn.api.records.YarnApplicationState; import org.apache.hadoop.yarn.api.records.YarnApplicationState;
import org.apache.hadoop.yarn.conf.YarnConfiguration;
import org.apache.hadoop.yarn.server.webapp.WebPageUtils;
import org.apache.hadoop.yarn.util.Log4jWarningErrorMetricsAppender; import org.apache.hadoop.yarn.util.Log4jWarningErrorMetricsAppender;
import org.apache.hadoop.yarn.webapp.hamlet2.Hamlet; import org.apache.hadoop.yarn.webapp.hamlet2.Hamlet;
import org.apache.hadoop.yarn.webapp.hamlet2.Hamlet.DIV; import org.apache.hadoop.yarn.webapp.hamlet2.Hamlet.DIV;
@ -29,6 +33,12 @@
import static org.apache.hadoop.util.GenericsUtil.isLog4jLogger; import static org.apache.hadoop.util.GenericsUtil.isLog4jLogger;
public class NavBlock extends HtmlBlock { public class NavBlock extends HtmlBlock {
private Configuration conf;
@Inject
public NavBlock(Configuration conf) {
this.conf = conf;
}
@Override public void render(Block html) { @Override public void render(Block html) {
boolean addErrorsAndWarningsLink = false; boolean addErrorsAndWarningsLink = false;
@ -55,13 +65,14 @@ public class NavBlock extends HtmlBlock {
li().a(url("apps", state.toString()), state.toString()).__(); li().a(url("apps", state.toString()), state.toString()).__();
} }
subAppsList.__().__(); subAppsList.__().__();
UL<DIV<Hamlet>> tools = mainList.
li().a(url("scheduler"), "Scheduler").__().__(). DIV<Hamlet> sectionBefore = mainList.
h3("Tools").ul(); li().a(url("scheduler"), "Scheduler").__().__();
tools.li().a("/conf", "Configuration").__(). UL<DIV<Hamlet>> tools = WebPageUtils.appendToolSection(sectionBefore, conf);
li().a("/logs", "Local logs").__().
li().a("/stacks", "Server stacks").__(). if (tools == null) {
li().a("/jmx?qry=Hadoop:*", "Server metrics").__(); return;
}
if (addErrorsAndWarningsLink) { if (addErrorsAndWarningsLink) {
tools.li().a(url("errors-and-warnings"), "Errors/Warnings").__(); tools.li().a(url("errors-and-warnings"), "Errors/Warnings").__();