From 9664b9c7a65d943e815c119e94234d3bf0b68dd4 Mon Sep 17 00:00:00 2001 From: Wei-Chiu Chuang Date: Mon, 18 Nov 2019 13:50:07 -0800 Subject: [PATCH] HADOOP-15686. Supress bogus AbstractWadlGeneratorGrammarGenerator in KMS stderr. Contributed by Wei-Chiu Chuang. Reviewed-by: Xiaoyu Yao --- .../hadoop/crypto/key/kms/server/KMSWebApp.java | 6 ++++++ .../hadoop/crypto/key/kms/server/TestKMS.java | 13 ++++++++++++- .../hadoop-kms/src/test/resources/log4j.properties | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/hadoop-common-project/hadoop-kms/src/main/java/org/apache/hadoop/crypto/key/kms/server/KMSWebApp.java b/hadoop-common-project/hadoop-kms/src/main/java/org/apache/hadoop/crypto/key/kms/server/KMSWebApp.java index 0640e25b76..da597b4da5 100644 --- a/hadoop-common-project/hadoop-kms/src/main/java/org/apache/hadoop/crypto/key/kms/server/KMSWebApp.java +++ b/hadoop-common-project/hadoop-kms/src/main/java/org/apache/hadoop/crypto/key/kms/server/KMSWebApp.java @@ -37,6 +37,7 @@ import org.apache.hadoop.util.VersionInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.slf4j.bridge.SLF4JBridgeHandler; @InterfaceAudience.Private public class KMSWebApp implements ServletContextListener { @@ -80,6 +81,11 @@ public class KMSWebApp implements ServletContextListener { private static KMSAudit kmsAudit; private static KeyProviderCryptoExtension keyProviderCryptoExtension; + static { + SLF4JBridgeHandler.removeHandlersForRootLogger(); + SLF4JBridgeHandler.install(); + } + @Override public void contextInitialized(ServletContextEvent sce) { try { diff --git a/hadoop-common-project/hadoop-kms/src/test/java/org/apache/hadoop/crypto/key/kms/server/TestKMS.java b/hadoop-common-project/hadoop-kms/src/test/java/org/apache/hadoop/crypto/key/kms/server/TestKMS.java index e37f2753d1..3b511a1c5c 100644 --- a/hadoop-common-project/hadoop-kms/src/test/java/org/apache/hadoop/crypto/key/kms/server/TestKMS.java +++ b/hadoop-common-project/hadoop-kms/src/test/java/org/apache/hadoop/crypto/key/kms/server/TestKMS.java @@ -614,7 +614,18 @@ public Void run() throws Exception { @Test public void testStartStopHttpPseudo() throws Exception { - testStartStop(false, false); + // Make sure bogus errors don't get emitted. + GenericTestUtils.LogCapturer logs = + GenericTestUtils.LogCapturer.captureLogs(LoggerFactory.getLogger( + "com.sun.jersey.server.wadl.generators.AbstractWadlGeneratorGrammarGenerator")); + try { + testStartStop(false, false); + } finally { + logs.stopCapturing(); + } + assertFalse(logs.getOutput().contains( + "Couldn't find grammar element for class")); + } @Test diff --git a/hadoop-common-project/hadoop-kms/src/test/resources/log4j.properties b/hadoop-common-project/hadoop-kms/src/test/resources/log4j.properties index b8e6353b39..73c48534a0 100644 --- a/hadoop-common-project/hadoop-kms/src/test/resources/log4j.properties +++ b/hadoop-common-project/hadoop-kms/src/test/resources/log4j.properties @@ -26,6 +26,7 @@ log4j.rootLogger=INFO, stdout log4j.logger.org.apache.hadoop.conf=ERROR log4j.logger.org.apache.hadoop.crytpo.key.kms.server=ALL log4j.logger.com.sun.jersey.server.wadl.generators.WadlGeneratorJAXBGrammarGenerator=OFF +log4j.logger.com.sun.jersey.server.wadl.generators.AbstractWadlGeneratorGrammarGenerator=OFF log4j.logger.org.apache.hadoop.security=OFF log4j.logger.org.apache.directory.server.core=OFF log4j.logger.org.apache.hadoop.util.NativeCodeLoader=OFF