From eced5bec68d16b9a66ebff85fa4893406ace3270 Mon Sep 17 00:00:00 2001 From: Szilard Nemeth Date: Sun, 8 May 2022 23:05:08 +0200 Subject: [PATCH] YARN-11123. ResourceManager webapps test failures due to org.apache.hadoop.metrics2.MetricsException and subsequent java.net.BindException: Address already in use. Contributed by Szilard Nemeth --- .../org/apache/hadoop/yarn/webapp/WebAppException.java | 10 ++++++++++ .../java/org/apache/hadoop/yarn/webapp/WebApps.java | 2 +- .../yarn/server/resourcemanager/ResourceManager.java | 8 +++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/WebAppException.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/WebAppException.java index dbede94f295..10d94739219 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/WebAppException.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/WebAppException.java @@ -25,6 +25,11 @@ import org.apache.hadoop.yarn.exceptions.YarnRuntimeException; public class WebAppException extends YarnRuntimeException { private static final long serialVersionUID = 1L; + private WebApp webApp; + + public WebApp getWebApp() { + return webApp; + } public WebAppException(String msg) { super(msg); @@ -35,6 +40,11 @@ public class WebAppException extends YarnRuntimeException { } public WebAppException(String msg, Throwable cause) { + this(msg, cause, null); + } + + public WebAppException(String msg, Throwable cause, WebApp webApp) { super(msg, cause); + this.webApp = webApp; } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/WebApps.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/WebApps.java index 6bd22b24719..9fef076196e 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/WebApps.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/WebApps.java @@ -476,7 +476,7 @@ public class WebApps { LOG.info("Web app " + name + " started at " + httpServer.getConnectorAddress(0).getPort()); } catch (IOException e) { - throw new WebAppException("Error starting http server", e); + throw new WebAppException("Error starting http server", e, webApp); } return webApp; } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/ResourceManager.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/ResourceManager.java index 3bd6a0fe43a..8adcff42a69 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/ResourceManager.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/ResourceManager.java @@ -23,6 +23,7 @@ import org.apache.hadoop.classification.VisibleForTesting; import com.sun.jersey.spi.container.servlet.ServletContainer; import org.apache.hadoop.yarn.metrics.GenericEventTypeMetrics; +import org.apache.hadoop.yarn.webapp.WebAppException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.slf4j.Marker; @@ -1440,7 +1441,12 @@ public class ResourceManager extends CompositeService IsResourceManagerActiveServlet.PATH_SPEC, IsResourceManagerActiveServlet.class); - webApp = builder.start(new RMWebApp(this), uiWebAppContext); + try { + webApp = builder.start(new RMWebApp(this), uiWebAppContext); + } catch (WebAppException e) { + webApp = e.getWebApp(); + throw e; + } } private String getWebAppsPath(String appName) {