hadoop-zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maha...@apache.org
Subject svn commit: r728825 - in /hadoop/zookeeper/trunk: ./ src/java/jmx/org/apache/zookeeper/server/ src/java/jmx/org/apache/zookeeper/server/quorum/
Date Mon, 22 Dec 2008 23:47:52 GMT
Author: mahadev
Date: Mon Dec 22 15:47:51 2008
New Revision: 728825

URL: http://svn.apache.org/viewvc?rev=728825&view=rev
Log:
ZOOKEEPER-256. support use of JMX to manage log4j configuration at runtime. (pat via mahadev)

Added:
    hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/server/ManagedUtil.java
Modified:
    hadoop/zookeeper/trunk/CHANGES.txt
    hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/server/ManagedZooKeeperServerMain.java
    hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/server/quorum/ManagedQuorumPeerMain.java

Modified: hadoop/zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/CHANGES.txt?rev=728825&r1=728824&r2=728825&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/CHANGES.txt (original)
+++ hadoop/zookeeper/trunk/CHANGES.txt Mon Dec 22 15:47:51 2008
@@ -88,6 +88,9 @@
    ZOOKEEPER-246. review error code definition in both source and docs. (pat
 via mahadev)
 
+   ZOOKEEPER-256. support use of JMX to manage log4j configuration at runtime.
+(pat via mahadev)
+
 Release 3.0.0 - 2008-10-21
 
 Non-backward compatible changes:

Added: hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/server/ManagedUtil.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/server/ManagedUtil.java?rev=728825&view=auto
==============================================================================
--- hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/server/ManagedUtil.java (added)
+++ hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/server/ManagedUtil.java Mon Dec
22 15:47:51 2008
@@ -0,0 +1,72 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.zookeeper.server;
+
+import java.lang.management.ManagementFactory;
+import java.util.Enumeration;
+
+import javax.management.JMException;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
+import org.apache.log4j.jmx.HierarchyDynamicMBean;
+import org.apache.log4j.spi.LoggerRepository;
+
+/**
+ * Shared utilities
+ */
+public class ManagedUtil {
+    /**
+     * Register the log4j JMX mbeans. Set environment variable
+     * "zookeeper.jmx.log4j.disable" to true to disable registration.
+     * @see http://logging.apache.org/log4j/1.2/apidocs/index.html?org/apache/log4j/jmx/package-summary.html
+     * @throws JMException if registration fails
+     */
+    public static void registerLog4jMBeans() throws JMException {
+        if (Boolean.getBoolean("zookeeper.jmx.log4j.disable") == true) {
+            return;
+        }
+        
+        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+
+        // Create and Register the top level Log4J MBean
+        HierarchyDynamicMBean hdm = new HierarchyDynamicMBean();
+
+        ObjectName mbo = new ObjectName("log4j:hiearchy=default");
+        mbs.registerMBean(hdm, mbo);
+
+        // Add the root logger to the Hierarchy MBean
+        Logger rootLogger = Logger.getRootLogger();
+        hdm.addLoggerMBean(rootLogger.getName());
+
+        // Get each logger from the Log4J Repository and add it to
+        // the Hierarchy MBean created above.
+        LoggerRepository r = LogManager.getLoggerRepository();
+        Enumeration enumer = r.getCurrentLoggers();
+        Logger logger = null;
+
+        while (enumer.hasMoreElements()) {
+           logger = (Logger) enumer.nextElement();
+           hdm.addLoggerMBean(logger.getName());
+        }
+    }
+
+}

Modified: hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/server/ManagedZooKeeperServerMain.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/server/ManagedZooKeeperServerMain.java?rev=728825&r1=728824&r2=728825&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/server/ManagedZooKeeperServerMain.java
(original)
+++ hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/server/ManagedZooKeeperServerMain.java
Mon Dec 22 15:47:51 2008
@@ -23,11 +23,12 @@
 import java.io.File;
 import java.io.IOException;
 
+import javax.management.JMException;
+
 import org.apache.log4j.Logger;
 import org.apache.zookeeper.jmx.server.ConnectionMXBean;
 import org.apache.zookeeper.jmx.server.DataTreeMXBean;
 import org.apache.zookeeper.jmx.server.ZooKeeperServerMXBean;
-import org.apache.zookeeper.server.persistence.FileTxnLog;
 import org.apache.zookeeper.server.persistence.FileTxnSnapLog;
 import org.apache.zookeeper.server.util.ZooKeeperObserverManager;
 
@@ -63,6 +64,12 @@
      */
     public static void main(String[] args) {
         try {
+            ManagedUtil.registerLog4jMBeans();
+        } catch (JMException e) {
+            LOG.warn("Unable to register log4j JMX control", e);
+        }
+
+        try {
             ServerConfig.parse(args);
         } catch(Exception e) {
             LOG.fatal("Error in config", e);

Modified: hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/server/quorum/ManagedQuorumPeerMain.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/server/quorum/ManagedQuorumPeerMain.java?rev=728825&r1=728824&r2=728825&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/server/quorum/ManagedQuorumPeerMain.java
(original)
+++ hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/server/quorum/ManagedQuorumPeerMain.java
Mon Dec 22 15:47:51 2008
@@ -23,6 +23,8 @@
 import java.io.File;
 import java.io.IOException;
 
+import javax.management.JMException;
+
 import org.apache.log4j.Logger;
 import org.apache.zookeeper.jmx.server.ConnectionMXBean;
 import org.apache.zookeeper.jmx.server.DataTreeMXBean;
@@ -31,18 +33,12 @@
 import org.apache.zookeeper.jmx.server.quorum.LocalPeerMXBean;
 import org.apache.zookeeper.jmx.server.quorum.QuorumMXBean;
 import org.apache.zookeeper.jmx.server.quorum.RemotePeerMXBean;
+import org.apache.zookeeper.server.ManagedUtil;
 import org.apache.zookeeper.server.ManagedZooKeeperServerMain;
 import org.apache.zookeeper.server.NIOServerCnxn;
 import org.apache.zookeeper.server.ObservableNIOServerCnxn;
 import org.apache.zookeeper.server.ServerConfig;
-import org.apache.zookeeper.server.ZooKeeperServer;
-import org.apache.zookeeper.server.ZooTrace;
-import org.apache.zookeeper.server.persistence.FileTxnLog;
 import org.apache.zookeeper.server.persistence.FileTxnSnapLog;
-import org.apache.zookeeper.server.util.ConnectionObserver;
-import org.apache.zookeeper.server.util.ObserverManager;
-import org.apache.zookeeper.server.util.QuorumPeerObserver;
-import org.apache.zookeeper.server.util.ServerObserver;
 import org.apache.zookeeper.server.util.ZooKeeperObserverManager;
 
 /**
@@ -92,6 +88,12 @@
             System.exit(2);
         }
         if (!QuorumPeerConfig.isStandalone()) {
+            try {
+                ManagedUtil.registerLog4jMBeans();
+            } catch (JMException e) {
+                LOG.warn("Unable to register log4j JMX control", e);
+            }
+
             ZooKeeperObserverManager.setAsConcrete();
             runPeer(new QuorumPeer.Factory() {
                 public QuorumPeer create(NIOServerCnxn.Factory cnxnFactory)



Mime
View raw message