From 0fd8bf5f6b2cd7af351a5a9ebdc98cb12d6a82aa Mon Sep 17 00:00:00 2001 From: Sunil G Date: Thu, 12 Mar 2020 15:03:12 +0530 Subject: [PATCH] YARN-10191. FS-CS converter: call System.exit function call for every code path in main method. Contributed by Peter Bacsko. --- .../fair/converter/FSConfigToCSConfigConverterMain.java | 3 ++- .../converter/TestFSConfigToCSConfigConverterMain.java | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/converter/FSConfigToCSConfigConverterMain.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/converter/FSConfigToCSConfigConverterMain.java index af1998ce1da..3953dcd357c 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/converter/FSConfigToCSConfigConverterMain.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/converter/FSConfigToCSConfigConverterMain.java @@ -42,8 +42,9 @@ public class FSConfigToCSConfigConverterMain { LOG.error(FATAL, "Error while starting FS configuration conversion, " + "see previous error messages for details!"); - System.exit(exitCode); } + + System.exit(exitCode); } catch (Throwable t) { LOG.error(FATAL, "Error while starting FS configuration conversion!", t); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/converter/TestFSConfigToCSConfigConverterMain.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/converter/TestFSConfigToCSConfigConverterMain.java index 0e2be72bf66..383a4bcfe97 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/converter/TestFSConfigToCSConfigConverterMain.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/converter/TestFSConfigToCSConfigConverterMain.java @@ -22,6 +22,7 @@ import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.conve import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.converter.FSConfigConverterTestCommons.YARN_SITE_XML; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.converter.FSConfigConverterTestCommons.setupFSConfigConversionFiles; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertEquals; import java.io.File; import java.io.IOException; @@ -40,11 +41,13 @@ import org.junit.Test; public class TestFSConfigToCSConfigConverterMain { private FSConfigConverterTestCommons converterTestCommons; private SecurityManager originalSecurityManager; + private ExitHandlerSecurityManager exitHandlerSecurityManager; @Before public void setUp() throws Exception { originalSecurityManager = System.getSecurityManager(); - System.setSecurityManager(new ExitHandlerSecurityManager()); + exitHandlerSecurityManager = new ExitHandlerSecurityManager(); + System.setSecurityManager(exitHandlerSecurityManager); converterTestCommons = new FSConfigConverterTestCommons(); converterTestCommons.setUp(); } @@ -82,6 +85,7 @@ public class TestFSConfigToCSConfigConverterMain { assertTrue("capacity-scheduler.xml was not generated", csConfigExists); assertTrue("yarn-site.xml was not generated", yarnSiteConfigExists); + assertEquals("Exit code", 0, exitHandlerSecurityManager.exitCode); } @Test @@ -141,12 +145,15 @@ public class TestFSConfigToCSConfigConverterMain { } class ExitHandlerSecurityManager extends SecurityManager { + int exitCode = Integer.MIN_VALUE; + @Override public void checkExit(int status) { if (status != 0) { throw new IllegalStateException( "Exit code is not 0, it was " + status); } + exitCode = status; } @Override