[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;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.mapreduce.v2.app.webapp.App;
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.DIV;
import org.apache.hadoop.yarn.webapp.view.HtmlBlock;
@ -31,8 +34,12 @@ import com.google.inject.Inject;
*/
public class HsNavBlock extends HtmlBlock {
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)
@ -64,12 +71,11 @@ public class HsNavBlock extends HtmlBlock {
li().a(url("taskcounters", taskid), "Counters").__().__();
}
}
nav.
h3("Tools").
ul().
li().a("/conf", "Configuration").__().
li().a("/logs", "Local logs").__().
li().a("/stacks", "Server stacks").__().
li().a("/jmx?qry=Hadoop:*", "Server metrics").__().__().__();
Hamlet.UL<DIV<Hamlet>> tools = WebPageUtils.appendToolSection(nav, conf);
if (tools != null) {
tools.__().__();
}
}
}

View File

@ -362,6 +362,8 @@ public class YarnConfiguration extends Configuration {
+ "webapp.ui2.war-file-path";
public static final String YARN_API_SERVICES_ENABLE = "yarn."
+ "webapp.api-service.enable";
public static final String YARN_WEBAPP_UI1_ENABLE_TOOLS = "yarn."
+ "webapp.ui1.tools.enable";
@Private
public static final String DEFAULT_YARN_API_SYSTEM_SERVICES_CLASS =

View File

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

View File

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

View File

@ -18,6 +18,10 @@
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;
@ -112,4 +116,32 @@ public class WebPageUtils {
.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;
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.webapp.YarnWebParams;
import org.apache.hadoop.yarn.webapp.hamlet2.Hamlet;
@ -51,7 +53,7 @@ public class NavBlock extends HtmlBlock implements YarnWebParams {
String RMWebAppURL =
WebAppUtils.getResolvedRMWebAppURLWithScheme(this.conf);
Hamlet.UL<Hamlet.DIV<Hamlet>> ul = html
Hamlet.DIV<Hamlet> ul = html
.div("#nav")
.h3().__("ResourceManager").__()
.ul()
@ -65,17 +67,17 @@ public class NavBlock extends HtmlBlock implements YarnWebParams {
.__()
.li()
.a(url("allContainers"), "List of Containers").__()
.__()
.h3("Tools")
.ul()
.li().a("/conf", "Configuration").__()
.li().a("/logs", "Local logs").__()
.li().a("/stacks", "Server stacks").__()
.li().a("/jmx?qry=Hadoop:*", "Server metrics").__();
if (addErrorsAndWarningsLink) {
ul.li().a(url("errors-and-warnings"), "Errors/Warnings").__();
.__();
Hamlet.UL<Hamlet.DIV<Hamlet>> tools = WebPageUtils.appendToolSection(ul, conf);
if (tools == null) {
return;
}
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;
import com.google.inject.Inject;
import org.apache.hadoop.conf.Configuration;
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.webapp.hamlet2.Hamlet;
import org.apache.hadoop.yarn.webapp.hamlet2.Hamlet.DIV;
@ -29,6 +33,12 @@ import org.apache.hadoop.yarn.webapp.view.HtmlBlock;
import static org.apache.hadoop.util.GenericsUtil.isLog4jLogger;
public class NavBlock extends HtmlBlock {
private Configuration conf;
@Inject
public NavBlock(Configuration conf) {
this.conf = conf;
}
@Override public void render(Block html) {
boolean addErrorsAndWarningsLink = false;
@ -55,13 +65,14 @@ public class NavBlock extends HtmlBlock {
li().a(url("apps", state.toString()), state.toString()).__();
}
subAppsList.__().__();
UL<DIV<Hamlet>> tools = mainList.
li().a(url("scheduler"), "Scheduler").__().__().
h3("Tools").ul();
tools.li().a("/conf", "Configuration").__().
li().a("/logs", "Local logs").__().
li().a("/stacks", "Server stacks").__().
li().a("/jmx?qry=Hadoop:*", "Server metrics").__();
DIV<Hamlet> sectionBefore = mainList.
li().a(url("scheduler"), "Scheduler").__().__();
UL<DIV<Hamlet>> tools = WebPageUtils.appendToolSection(sectionBefore, conf);
if (tools == null) {
return;
}
if (addErrorsAndWarningsLink) {
tools.li().a(url("errors-and-warnings"), "Errors/Warnings").__();