Repository: hadoop Updated Branches: refs/heads/branch-3.0 6a547856e -> fa32269ce
HADOOP-15698. KMS log4j is not initialized properly at startup. Contributed by Kitti Nanasi. (cherry picked from commit 781437c219dc3422797a32dc7ba72cd4f5ee38e2) Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/fa32269c Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/fa32269c Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/fa32269c Branch: refs/heads/branch-3.0 Commit: fa32269cee5ec7125fb7e6d06c49716fdfe00af9 Parents: 6a54785 Author: Kitti Nanasi <knan...@cloudera.com> Authored: Wed Aug 29 22:06:36 2018 -0700 Committer: Xiao Chen <x...@apache.org> Committed: Wed Aug 29 22:09:13 2018 -0700 ---------------------------------------------------------------------- .../crypto/key/kms/server/KMSConfiguration.java | 31 ++++++++++++++++ .../hadoop/crypto/key/kms/server/KMSWebApp.java | 38 +------------------- .../crypto/key/kms/server/KMSWebServer.java | 1 + 3 files changed, 33 insertions(+), 37 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/fa32269c/hadoop-common-project/hadoop-kms/src/main/java/org/apache/hadoop/crypto/key/kms/server/KMSConfiguration.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-kms/src/main/java/org/apache/hadoop/crypto/key/kms/server/KMSConfiguration.java b/hadoop-common-project/hadoop-kms/src/main/java/org/apache/hadoop/crypto/key/kms/server/KMSConfiguration.java index 18eec19..35ffb42 100644 --- a/hadoop-common-project/hadoop-kms/src/main/java/org/apache/hadoop/crypto/key/kms/server/KMSConfiguration.java +++ b/hadoop-common-project/hadoop-kms/src/main/java/org/apache/hadoop/crypto/key/kms/server/KMSConfiguration.java @@ -20,6 +20,7 @@ package org.apache.hadoop.crypto.key.kms.server; import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; +import org.apache.log4j.PropertyConfigurator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -103,6 +104,8 @@ public class KMSConfiguration { public static final boolean KEY_AUTHORIZATION_ENABLE_DEFAULT = true; + private static final String LOG4J_PROPERTIES = "kms-log4j.properties"; + static { Configuration.addDefaultResource(KMS_DEFAULT_XML); Configuration.addDefaultResource(KMS_SITE_XML); @@ -159,4 +162,32 @@ public class KMSConfiguration { } return newer; } + + public static void initLogging() { + String confDir = System.getProperty(KMS_CONFIG_DIR); + if (confDir == null) { + throw new RuntimeException("System property '" + + KMSConfiguration.KMS_CONFIG_DIR + "' not defined"); + } + if (System.getProperty("log4j.configuration") == null) { + System.setProperty("log4j.defaultInitOverride", "true"); + boolean fromClasspath = true; + File log4jConf = new File(confDir, LOG4J_PROPERTIES).getAbsoluteFile(); + if (log4jConf.exists()) { + PropertyConfigurator.configureAndWatch(log4jConf.getPath(), 1000); + fromClasspath = false; + } else { + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + URL log4jUrl = cl.getResource(LOG4J_PROPERTIES); + if (log4jUrl != null) { + PropertyConfigurator.configure(log4jUrl); + } + } + LOG.debug("KMS log starting"); + if (fromClasspath) { + LOG.warn("Log4j configuration file '{}' not found", LOG4J_PROPERTIES); + LOG.warn("Logging with INFO level to standard output"); + } + } + } } http://git-wip-us.apache.org/repos/asf/hadoop/blob/fa32269c/hadoop-common-project/hadoop-kms/src/main/java/org/apache/hadoop/crypto/key/kms/server/KMSWebApp.java ---------------------------------------------------------------------- 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 9a71fa2..571d675 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 @@ -17,10 +17,8 @@ */ package org.apache.hadoop.crypto.key.kms.server; -import java.io.File; import java.io.IOException; import java.net.URI; -import java.net.URL; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; @@ -36,14 +34,13 @@ import org.apache.hadoop.crypto.key.KeyProviderCryptoExtension; import org.apache.hadoop.crypto.key.KeyProviderFactory; import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.util.VersionInfo; -import org.apache.log4j.PropertyConfigurator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @InterfaceAudience.Private public class KMSWebApp implements ServletContextListener { - private static final String LOG4J_PROPERTIES = "kms-log4j.properties"; + private static final Logger LOG = LoggerFactory.getLogger(KMSWebApp.class); private static final String METRICS_PREFIX = "hadoop.kms."; private static final String ADMIN_CALLS_METER = METRICS_PREFIX + @@ -65,7 +62,6 @@ public class KMSWebApp implements ServletContextListener { private static final String REENCRYPT_EEK_BATCH_METER = METRICS_PREFIX + "reencrypt_eek_batch.calls.meter"; - private static Logger LOG; private static MetricRegistry metricRegistry; private JmxReporter jmxReporter; @@ -83,42 +79,10 @@ public class KMSWebApp implements ServletContextListener { private static KMSAudit kmsAudit; private static KeyProviderCryptoExtension keyProviderCryptoExtension; - private void initLogging(String confDir) { - if (System.getProperty("log4j.configuration") == null) { - System.setProperty("log4j.defaultInitOverride", "true"); - boolean fromClasspath = true; - File log4jConf = new File(confDir, LOG4J_PROPERTIES).getAbsoluteFile(); - if (log4jConf.exists()) { - PropertyConfigurator.configureAndWatch(log4jConf.getPath(), 1000); - fromClasspath = false; - } else { - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - URL log4jUrl = cl.getResource(LOG4J_PROPERTIES); - if (log4jUrl != null) { - PropertyConfigurator.configure(log4jUrl); - } - } - LOG = LoggerFactory.getLogger(KMSWebApp.class); - LOG.debug("KMS log starting"); - if (fromClasspath) { - LOG.warn("Log4j configuration file '{}' not found", LOG4J_PROPERTIES); - LOG.warn("Logging with INFO level to standard output"); - } - } else { - LOG = LoggerFactory.getLogger(KMSWebApp.class); - } - } - @Override public void contextInitialized(ServletContextEvent sce) { try { - String confDir = System.getProperty(KMSConfiguration.KMS_CONFIG_DIR); - if (confDir == null) { - throw new RuntimeException("System property '" + - KMSConfiguration.KMS_CONFIG_DIR + "' not defined"); - } kmsConf = KMSConfiguration.getKMSConf(); - initLogging(confDir); UserGroupInformation.setConfiguration(kmsConf); LOG.info("-------------------------------------------------------------"); LOG.info(" Java runtime version : {}", System.getProperty( http://git-wip-us.apache.org/repos/asf/hadoop/blob/fa32269c/hadoop-common-project/hadoop-kms/src/main/java/org/apache/hadoop/crypto/key/kms/server/KMSWebServer.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-kms/src/main/java/org/apache/hadoop/crypto/key/kms/server/KMSWebServer.java b/hadoop-common-project/hadoop-kms/src/main/java/org/apache/hadoop/crypto/key/kms/server/KMSWebServer.java index 19f7227..036231d 100644 --- a/hadoop-common-project/hadoop-kms/src/main/java/org/apache/hadoop/crypto/key/kms/server/KMSWebServer.java +++ b/hadoop-common-project/hadoop-kms/src/main/java/org/apache/hadoop/crypto/key/kms/server/KMSWebServer.java @@ -166,6 +166,7 @@ public class KMSWebServer { } public static void main(String[] args) throws Exception { + KMSConfiguration.initLogging(); StringUtils.startupShutdownMessage(KMSWebServer.class, args, LOG); Configuration conf = new ConfigurationWithLogging( KMSConfiguration.getKMSConf()); --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-commits-h...@hadoop.apache.org