From 6c2ce3d56b14ce4139cbecc1cfe026e5a838f319 Mon Sep 17 00:00:00 2001 From: Prabhu Joseph Date: Thu, 6 Aug 2020 19:15:16 +0530 Subject: [PATCH] YARN-10389. Option to override RMWebServices with custom WebService class Contributed by Tanu Ajmera. Reviewed by Bilwa ST and Sunil G. --- .../hadoop/yarn/conf/YarnConfiguration.java | 3 +++ .../src/main/resources/yarn-default.xml | 9 +++++++++ .../server/resourcemanager/webapp/RMWebApp.java | 17 ++++++++++------- 3 files changed, 22 insertions(+), 7 deletions(-) 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 19ce6221b0..6c1be0e34a 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 @@ -2406,6 +2406,9 @@ public static boolean isAclEnabled(Configuration conf) { public static final String YARN_HTTP_WEBAPP_CUSTOM_UNWRAPPED_DAO_CLASSES = "yarn.http.rmwebapp.custom.unwrapped.dao.classes"; + public static final String YARN_WEBAPP_CUSTOM_WEBSERVICE_CLASS = + "yarn.webapp.custom.webservice.class"; + /** * Whether or not users are allowed to request that Docker containers honor * the debug deletion delay. This is useful for troubleshooting Docker 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 2208b00d8a..47f123918b 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 @@ -3376,6 +3376,15 @@ + + + Used to specify custom WebServices class to bind with RMWebApp overriding + the default RMWebServices. + + yarn.webapp.custom.webservice.class + + + The Node Label script to run. Script output Line starting with "NODE_PARTITION:" will be considered as Node Label Partition. In case of 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/RMWebApp.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/RMWebApp.java index 5075d25056..3ed53f6dcc 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/RMWebApp.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/RMWebApp.java @@ -22,6 +22,7 @@ import java.net.InetSocketAddress; +import org.apache.hadoop.conf.Configuration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.apache.hadoop.ha.HAServiceProtocol.HAServiceState; @@ -44,6 +45,7 @@ public class RMWebApp extends WebApp implements YarnWebParams { LoggerFactory.getLogger(RMWebApp.class.getName()); private final ResourceManager rm; private boolean standby = false; + private Configuration conf; public RMWebApp(ResourceManager rm) { this.rm = rm; @@ -51,15 +53,17 @@ public RMWebApp(ResourceManager rm) { @Override public void setup() { + conf = rm.getConfig(); bind(JAXBContextResolver.class); - bind(RMWebServices.class); + Class webService = conf.getClass( + YarnConfiguration.YARN_WEBAPP_CUSTOM_WEBSERVICE_CLASS, + RMWebServices.class); + bind(webService); bind(GenericExceptionHandler.class); bind(RMWebApp.class).toInstance(this); bindExternalClasses(); + bind(ResourceManager.class).toInstance(rm); - if (rm != null) { - bind(ResourceManager.class).toInstance(rm); - } route("/", RmController.class); route(pajoin("/nodes", NODE_STATE), RmController.class, "nodes"); route(pajoin("/apps", APP_STATE), RmController.class); @@ -99,8 +103,7 @@ public String getRedirectPath() { } private void bindExternalClasses() { - YarnConfiguration yarnConf = new YarnConfiguration(rm.getConfig()); - Class[] externalClasses = yarnConf + Class[] externalClasses = conf .getClasses(YarnConfiguration.YARN_HTTP_WEBAPP_EXTERNAL_CLASSES); for (Class c : externalClasses) { bind(c); @@ -111,7 +114,7 @@ private void bindExternalClasses() { private String buildRedirectPath() { // make a copy of the original configuration so not to mutate it. Also use // an YarnConfiguration to force loading of yarn-site.xml. - YarnConfiguration yarnConf = new YarnConfiguration(rm.getConfig()); + YarnConfiguration yarnConf = new YarnConfiguration(conf); String activeRMHAId = RMHAUtils.findActiveRMHAId(yarnConf); String path = ""; if (activeRMHAId != null) {