hadoop-zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maha...@apache.org
Subject svn commit: r741729 - in /hadoop/zookeeper/trunk: ./ src/java/main/org/apache/zookeeper/jmx/ src/java/main/org/apache/zookeeper/server/ src/java/main/org/apache/zookeeper/server/quorum/
Date Fri, 06 Feb 2009 21:19:03 GMT
Author: mahadev
Date: Fri Feb  6 21:19:03 2009
New Revision: 741729

URL: http://svn.apache.org/viewvc?rev=741729&view=rev
Log:
ZOOKEEPER-302. Quote values in JMX objectnames. (tom and pat via mahadev)

Modified:
    hadoop/zookeeper/trunk/CHANGES.txt
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/jmx/MBeanRegistry.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ConnectionBean.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerBean.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FollowerZooKeeperServer.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/LeaderZooKeeperServer.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java

Modified: hadoop/zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/CHANGES.txt?rev=741729&r1=741728&r2=741729&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/CHANGES.txt (original)
+++ hadoop/zookeeper/trunk/CHANGES.txt Fri Feb  6 21:19:03 2009
@@ -112,6 +112,8 @@
   ZOOKEEPER-293. zoo_set needs to be abi compatible (3.1 changed the
 signature), fix this by adding zoo_set2 (pat via mahadev)
 
+  ZOOKEEPER-302. Quote values in JMX objectnames. (tom and pat via mahadev)
+
 IMPROVEMENTS:
    
   ZOOKEEPER-64. Log system env information when initializing server and

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/jmx/MBeanRegistry.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/jmx/MBeanRegistry.java?rev=741729&r1=741728&r2=741729&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/jmx/MBeanRegistry.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/jmx/MBeanRegistry.java Fri Feb
 6 21:19:03 2009
@@ -22,7 +22,9 @@
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
+import javax.management.JMException;
 import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
 
 import org.apache.log4j.Logger;
@@ -54,7 +56,9 @@
      * @param parent if not null, the new bean will be registered as a child
      * node of this parent.
      */
-    public void register(ZKMBeanInfo bean, ZKMBeanInfo parent) {
+    public void register(ZKMBeanInfo bean, ZKMBeanInfo parent)
+        throws JMException
+    {
         assert bean != null;
         String path = null;
         if (parent != null) {
@@ -70,9 +74,9 @@
         ObjectName oname = makeObjectName(path, bean);
         try {
             mbs.registerMBean(bean, oname);
-        } catch (Exception e) {
-            LOG.error("Failed to register MBean " + bean.getName());
-            e.printStackTrace();
+        } catch (JMException e) {
+            LOG.warn("Failed to register MBean " + bean.getName());
+            throw e;
         }
     }
 
@@ -81,16 +85,16 @@
      * @param path
      * @param bean
      */
-    private void unregister(String path,ZKMBeanInfo bean){
+    private void unregister(String path,ZKMBeanInfo bean) throws JMException {
         if(path==null)
             return;
         if (!bean.isHidden()) {
             MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
             try {
                 mbs.unregisterMBean(makeObjectName(path, bean));
-            } catch (Exception e) {
-                LOG.error("Failed to unregister MBean " + bean.getName());
-                e.printStackTrace();
+            } catch (JMException e) {
+                LOG.warn("Failed to unregister MBean " + bean.getName());
+                throw e;
             }
         }        
     }
@@ -99,20 +103,28 @@
      * Unregister MBean.
      * @param bean
      */
-    public void unregister(ZKMBeanInfo bean){
+    public void unregister(ZKMBeanInfo bean) {
         if(bean==null)
             return;
         String path=mapBean2Path.get(bean);
-        unregister(path,bean);
+        try {
+            unregister(path,bean);
+        } catch (JMException e) {
+            LOG.warn("Error during unregister", e);
+        }
         mapBean2Path.remove(bean);
         mapName2Bean.remove(bean.getName());
     }
     /**
      * Unregister all currently registered MBeans
      */
-    public void unregisterAll(){
-        for(Map.Entry<ZKMBeanInfo,String> e: mapBean2Path.entrySet()){
-            unregister(e.getValue(),e.getKey());
+    public void unregisterAll() {
+        for(Map.Entry<ZKMBeanInfo,String> e: mapBean2Path.entrySet()) {
+            try {
+                unregister(e.getValue(), e.getKey());
+            } catch (JMException e1) {
+                LOG.warn("Error during unregister", e1);
+            }
         }
         mapBean2Path.clear();
         mapName2Bean.clear();
@@ -123,7 +135,7 @@
      * @param name path elements
      * @return absolute path
      */
-    public String makeFullPath(String prefix, String... name){
+    public String makeFullPath(String prefix, String... name) {
         StringBuilder sb=new StringBuilder(prefix == null ? "/" : (prefix.equals("/")?prefix:prefix+"/"));
         boolean first=true;
         for (String s : name) {
@@ -159,9 +171,11 @@
      * Builds an MBean path and creates an ObjectName instance using the path. 
      * @param path MBean path
      * @param bean the MBean instance
-     * @return ObjectName to be registered with the paltform MBean server
+     * @return ObjectName to be registered with the platform MBean server
      */
-    protected ObjectName makeObjectName(String path, ZKMBeanInfo bean) {
+    protected ObjectName makeObjectName(String path, ZKMBeanInfo bean)
+        throws MalformedObjectNameException
+    {
         if(path==null)
             return null;
         StringBuilder beanName = new StringBuilder(CommonNames.DOMAIN + ":");
@@ -171,10 +185,10 @@
         beanName.deleteCharAt(beanName.length()-1);
         try {
             return new ObjectName(beanName.toString());
-        } catch (Exception e) {
-            e.printStackTrace();
-            assert false;
+        } catch (MalformedObjectNameException e) {
+            LOG.warn("Invalid name \"" + beanName.toString() + "\" for class "
+                    + bean.getClass().toString());
+            throw e;
         }
-        return null;
     }
 }

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ConnectionBean.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ConnectionBean.java?rev=741729&r1=741728&r2=741729&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ConnectionBean.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ConnectionBean.java Fri
Feb  6 21:19:03 2009
@@ -18,9 +18,14 @@
 
 package org.apache.zookeeper.server;
 
+import java.net.Inet6Address;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
 import java.util.Arrays;
 import java.util.Date;
 
+import javax.management.ObjectName;
+
 import org.apache.log4j.Logger;
 import org.apache.zookeeper.jmx.MBeanRegistry;
 import org.apache.zookeeper.jmx.ZKMBeanInfo;
@@ -44,15 +49,20 @@
         return "0x" + Long.toHexString(connection.getSessionId());
     }
 
-    
     public String getSourceIP() {
-        return connection.getRemoteAddress().getAddress().getHostAddress()+
-            ":"+connection.getRemoteAddress().getPort();
+        InetSocketAddress sockAddr = connection.getRemoteAddress();
+        return sockAddr.getAddress().getHostAddress()
+            + ":" + sockAddr.getPort();
     }
-    
+
     public String getName() {
-        String ip=connection.getRemoteAddress().getAddress().getHostAddress();
-        return MBeanRegistry.getInstance().makeFullPath("Connections", ip,getSessionId());
+        InetAddress addr = connection.getRemoteAddress().getAddress();
+        String ip = addr.getHostAddress();
+        if (addr instanceof Inet6Address) {
+            ip = ObjectName.quote(ip);
+        }
+        return MBeanRegistry.getInstance().makeFullPath("Connections", ip,
+                getSessionId());
     }
     
     public boolean isHidden() {
@@ -61,7 +71,8 @@
     
     public String[] getEphemeralNodes() {
         if(zk.dataTree!=null){
-            String[] res=zk.dataTree.getEphemerals(connection.getSessionId()).toArray(new
String[0]);
+            String[] res=zk.dataTree.getEphemerals(connection.getSessionId())
+                .toArray(new String[0]);
             Arrays.sort(res);
             return res;
         }
@@ -84,10 +95,11 @@
     public void terminateConnection() {
         connection.close();
     }
-    
+
     @Override
     public String toString() {
-        return "ConnectionBean{ClientIP="+getSourceIP()+",SessionId=0x"+getSessionId()+"}";
+        return "ConnectionBean{ClientIP=" + ObjectName.quote(getSourceIP())
+            + ",SessionId=0x" + getSessionId() + "}";
     }
     
     public long getOutstandingRequests() {

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java?rev=741729&r1=741728&r2=741729&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java Fri
Feb  6 21:19:03 2009
@@ -861,6 +861,7 @@
             MBeanRegistry.getInstance().register(jmxConnectionBean, zk.jmxServerBean);
         } catch (Exception e) {
             LOG.warn("Failed to register with JMX", e);
+            jmxConnectionBean = null;
         }
 
         try {

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java?rev=741729&r1=741728&r2=741729&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java
(original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java
Fri Feb  6 21:19:03 2009
@@ -334,10 +334,17 @@
         try {
             jmxServerBean = new ZooKeeperServerBean(this);
             MBeanRegistry.getInstance().register(jmxServerBean, null);
-            jmxDataTreeBean = new DataTreeBean(dataTree);
-            MBeanRegistry.getInstance().register(jmxDataTreeBean, jmxServerBean);
+            
+            try {
+                jmxDataTreeBean = new DataTreeBean(dataTree);
+                MBeanRegistry.getInstance().register(jmxDataTreeBean, jmxServerBean);
+            } catch (Exception e) {
+                LOG.warn("Failed to register with JMX", e);
+                jmxDataTreeBean = null;
+            }
         } catch (Exception e) {
             LOG.warn("Failed to register with JMX", e);
+            jmxServerBean = null;
         }
     }
     
@@ -397,6 +404,10 @@
             if (jmxDataTreeBean != null) {
                 MBeanRegistry.getInstance().unregister(jmxDataTreeBean);
             }
+        } catch (Exception e) {
+            LOG.warn("Failed to unregister with JMX", e);
+        }
+        try {
             if (jmxServerBean != null) {
                 MBeanRegistry.getInstance().unregister(jmxServerBean);
             }

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerBean.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerBean.java?rev=741729&r1=741728&r2=741729&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerBean.java
(original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerBean.java
Fri Feb  6 21:19:03 2009
@@ -24,8 +24,6 @@
 
 import org.apache.zookeeper.Version;
 import org.apache.zookeeper.jmx.ZKMBeanInfo;
-import org.apache.zookeeper.server.ServerStats;
-import org.apache.zookeeper.server.ZooKeeperServer;
 
 /**
  * This class implements the ZooKeeper server MBean interface.
@@ -45,7 +43,7 @@
     public String getClientPort() {
         try {
             return InetAddress.getLocalHost().getHostAddress() + ":"
-                    + zks.getClientPort();
+                + zks.getClientPort();
         } catch (UnknownHostException e) {
             return "localhost:" + zks.getClientPort();
         }

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FollowerZooKeeperServer.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FollowerZooKeeperServer.java?rev=741729&r1=741728&r2=741729&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FollowerZooKeeperServer.java
(original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FollowerZooKeeperServer.java
Fri Feb  6 21:19:03 2009
@@ -187,6 +187,7 @@
             MBeanRegistry.getInstance().register(jmxDataTreeBean, jmxServerBean);
         } catch (Exception e) {
             LOG.warn("Failed to register with JMX", e);
+            jmxDataTreeBean = null;
         }
     }
 
@@ -194,14 +195,21 @@
             LocalPeerBean localPeerBean)
     {
         // register with JMX
-        try {
-            MBeanRegistry.getInstance().unregister(self.jmxLeaderElectionBean);
+        if (self.jmxLeaderElectionBean != null) {
+            try {
+                MBeanRegistry.getInstance().unregister(self.jmxLeaderElectionBean);
+            } catch (Exception e) {
+                LOG.warn("Failed to register with JMX", e);
+            }
             self.jmxLeaderElectionBean = null;
+        }
 
+        try {
             jmxServerBean = followerBean;
             MBeanRegistry.getInstance().register(followerBean, localPeerBean);
         } catch (Exception e) {
             LOG.warn("Failed to register with JMX", e);
+            jmxServerBean = null;
         }
     }
 

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/LeaderZooKeeperServer.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/LeaderZooKeeperServer.java?rev=741729&r1=741728&r2=741729&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/LeaderZooKeeperServer.java
(original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/LeaderZooKeeperServer.java
Fri Feb  6 21:19:03 2009
@@ -96,6 +96,7 @@
             MBeanRegistry.getInstance().register(jmxDataTreeBean, jmxServerBean);
         } catch (Exception e) {
             LOG.warn("Failed to register with JMX", e);
+            jmxDataTreeBean = null;
         }
     }
 
@@ -103,14 +104,21 @@
             LocalPeerBean localPeerBean)
     {
         // register with JMX
-        try {
-            MBeanRegistry.getInstance().unregister(self.jmxLeaderElectionBean);
+        if (self.jmxLeaderElectionBean != null) {
+            try {
+                MBeanRegistry.getInstance().unregister(self.jmxLeaderElectionBean);
+            } catch (Exception e) {
+                LOG.warn("Failed to register with JMX", e);
+            }
             self.jmxLeaderElectionBean = null;
+        }
 
+        try {
             jmxServerBean = leaderBean;
             MBeanRegistry.getInstance().register(leaderBean, localPeerBean);
         } catch (Exception e) {
             LOG.warn("Failed to register with JMX", e);
+            jmxServerBean = null;
         }
     }
 

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java?rev=741729&r1=741728&r2=741729&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java
(original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java
Fri Feb  6 21:19:03 2009
@@ -372,6 +372,7 @@
             MBeanRegistry.getInstance().register(jmxLeaderElectionBean, jmxLocalPeerBean);
       
         } catch (Exception e) {
             LOG.warn("Failed to register with JMX", e);
+            jmxLeaderElectionBean = null;
         }
 
         if(electionAlg==null)
@@ -407,13 +408,24 @@
                 ZKMBeanInfo p;
                 if (getId() == s.id) {
                     p = jmxLocalPeerBean = new LocalPeerBean(this);
+                    try {
+                        MBeanRegistry.getInstance().register(p, jmxQuorumBean);
+                    } catch (Exception e) {
+                        LOG.warn("Failed to register with JMX", e);
+                        jmxLocalPeerBean = null;
+                    }
                 } else {
                     p = new RemotePeerBean(s);
+                    try {
+                        MBeanRegistry.getInstance().register(p, jmxQuorumBean);
+                    } catch (Exception e) {
+                        LOG.warn("Failed to register with JMX", e);
+                    }
                 }
-                MBeanRegistry.getInstance().register(p, jmxQuorumBean);
             }
         } catch (Exception e) {
             LOG.warn("Failed to register with JMX", e);
+            jmxQuorumBean = null;
         }
 
         try {



Mime
View raw message