From 4ffe26f9b811ff505a7137a340105ad2ceb419fa Mon Sep 17 00:00:00 2001 From: Szilard Nemeth Date: Mon, 31 Aug 2020 16:00:39 +0200 Subject: [PATCH] [UI1] Provide a way to hide Tools section in Web UIv1. Contributed by Andras Gyori --- .../mapreduce/v2/hs/webapp/HsNavBlock.java | 22 +++++++----- .../hadoop/yarn/conf/YarnConfiguration.java | 2 ++ .../src/main/resources/yarn-default.xml | 6 ++++ .../webapp/NavBlock.java | 21 +++++++++--- .../yarn/server/webapp/WebPageUtils.java | 34 ++++++++++++++++++- .../server/nodemanager/webapp/NavBlock.java | 24 +++++++------ .../resourcemanager/webapp/NavBlock.java | 25 ++++++++++---- 7 files changed, 102 insertions(+), 32 deletions(-) diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/main/java/org/apache/hadoop/mapreduce/v2/hs/webapp/HsNavBlock.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/main/java/org/apache/hadoop/mapreduce/v2/hs/webapp/HsNavBlock.java index 9ef5a0f8cf..fb077dd784 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/main/java/org/apache/hadoop/mapreduce/v2/hs/webapp/HsNavBlock.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/main/java/org/apache/hadoop/mapreduce/v2/hs/webapp/HsNavBlock.java @@ -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 @@ */ 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> tools = WebPageUtils.appendToolSection(nav, conf); + + if (tools != null) { + tools.__().__(); + } } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java index 6c1be0e34a..2dbbfbf6d8 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java @@ -362,6 +362,8 @@ private static void addDeprecatedKeys() { + "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 = diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/resources/yarn-default.xml b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/resources/yarn-default.xml index 47f123918b..23c56e79c5 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/resources/yarn-default.xml +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/resources/yarn-default.xml @@ -256,6 +256,12 @@ false + + Enable tools section in all ui1 webapp. + yarn.webapp.ui1.tools.enable + true + + Explicitly provide WAR file path for ui2 if needed. diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/NavBlock.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/NavBlock.java index 915af4a996..10d3b52c7e 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/NavBlock.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/NavBlock.java @@ -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 @@ 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 void render(Block html) { __(). __(); - Hamlet.UL> 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> tools = WebPageUtils.appendToolSection(nav, conf); + + if (tools == null) { + return; + } if (addErrorsAndWarningsLink) { tools.li().a(url("errors-and-warnings"), "Errors/Warnings").__(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/webapp/WebPageUtils.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/webapp/WebPageUtils.java index 311462bd11..12c73c1242 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/webapp/WebPageUtils.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/webapp/WebPageUtils.java @@ -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 static String resourceRequestsTableInit() { .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> appendToolSection( + Hamlet.DIV section, Configuration conf) { + boolean isToolsEnabled = conf.getBoolean( + YarnConfiguration.YARN_WEBAPP_UI1_ENABLE_TOOLS, true); + + Hamlet.DIV tools = null; + Hamlet.UL> 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; + } + +} \ No newline at end of file diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/webapp/NavBlock.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/webapp/NavBlock.java index 5cbcff5ee0..86d9ae7687 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/webapp/NavBlock.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/webapp/NavBlock.java @@ -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 @@ protected void render(Block html) { String RMWebAppURL = WebAppUtils.getResolvedRMWebAppURLWithScheme(this.conf); - Hamlet.UL> ul = html + Hamlet.DIV ul = html .div("#nav") .h3().__("ResourceManager").__() .ul() @@ -65,17 +67,17 @@ protected void render(Block html) { .__() .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> tools = WebPageUtils.appendToolSection(ul, conf); + + if (tools == null) { + return; } - ul.__().__(); + if (addErrorsAndWarningsLink) { + tools.li().a(url("errors-and-warnings"), "Errors/Warnings").__(); + } + tools.__().__(); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/NavBlock.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/NavBlock.java index 3107644f64..d6d7e54c34 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/NavBlock.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/NavBlock.java @@ -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 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> 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 sectionBefore = mainList. + li().a(url("scheduler"), "Scheduler").__().__(); + UL> tools = WebPageUtils.appendToolSection(sectionBefore, conf); + + if (tools == null) { + return; + } if (addErrorsAndWarningsLink) { tools.li().a(url("errors-and-warnings"), "Errors/Warnings").__();