zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@apache.org
Subject svn commit: r1718255 - in /zookeeper/trunk: ./ src/java/main/org/apache/zookeeper/server/ src/java/test/org/apache/zookeeper/server/
Date Mon, 07 Dec 2015 05:26:28 GMT
Author: rgs
Date: Mon Dec  7 05:26:27 2015
New Revision: 1718255

URL: http://svn.apache.org/viewvc?rev=1718255&view=rev
Log:
ZOOKEEPER-2300: Expose SecureClientPort and SecureClientAddress JMX properties
(Arshad Mohammad via rgs)

Added:
    zookeeper/trunk/src/java/test/org/apache/zookeeper/server/ZooKeeperServerBeanTest.java
Modified:
    zookeeper/trunk/CHANGES.txt
    zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerBean.java
    zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMXBean.java

Modified: zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/trunk/CHANGES.txt?rev=1718255&r1=1718254&r2=1718255&view=diff
==============================================================================
--- zookeeper/trunk/CHANGES.txt (original)
+++ zookeeper/trunk/CHANGES.txt Mon Dec  7 05:26:27 2015
@@ -339,6 +339,9 @@ IMPROVEMENTS:
   ZOOKEEPER-2306: Remove file delete duplicate code from test code
   (Arshad Mohammad via rgs)
 
+  ZOOKEEPER-2300: Expose SecureClientPort and SecureClientAddress JMX properties
+  (Arshad Mohammad via rgs)
+
 Release 3.5.0 - 8/4/2014
 
 NEW FEATURES:

Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerBean.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerBean.java?rev=1718255&r1=1718254&r2=1718255&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerBean.java (original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerBean.java Mon
Dec  7 05:26:27 2015
@@ -144,4 +144,22 @@ public class ZooKeeperServerBean impleme
     public long getNumAliveConnections() {
         return zks.getNumAliveConnections();
     }
+
+    @Override
+    public String getSecureClientPort() {
+        if (zks.secureServerCnxnFactory != null) {
+            return Integer.toString(zks.secureServerCnxnFactory.getLocalPort());
+        }
+        return "";
+    }
+
+    @Override
+    public String getSecureClientAddress() {
+        if (zks.secureServerCnxnFactory != null) {
+            return String.format("%s:%d", zks.secureServerCnxnFactory
+                    .getLocalAddress().getHostString(),
+                    zks.secureServerCnxnFactory.getLocalPort());
+        }
+        return "";
+    }
 }

Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMXBean.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMXBean.java?rev=1718255&r1=1718254&r2=1718255&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMXBean.java (original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMXBean.java Mon
Dec  7 05:26:27 2015
@@ -116,4 +116,13 @@ public interface ZooKeeperServerMXBean {
      * @return estimated size of log directory in bytes
      */
     public long getLogDirSize();
+
+    /**
+     * @return secure client port
+    */
+    public String getSecureClientPort();
+    /**
+     * @return secure client address
+     */
+    public String getSecureClientAddress();
 }

Added: zookeeper/trunk/src/java/test/org/apache/zookeeper/server/ZooKeeperServerBeanTest.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/test/org/apache/zookeeper/server/ZooKeeperServerBeanTest.java?rev=1718255&view=auto
==============================================================================
--- zookeeper/trunk/src/java/test/org/apache/zookeeper/server/ZooKeeperServerBeanTest.java
(added)
+++ zookeeper/trunk/src/java/test/org/apache/zookeeper/server/ZooKeeperServerBeanTest.java
Mon Dec  7 05:26:27 2015
@@ -0,0 +1,102 @@
+/**
+ * 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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ZooKeeperServerBeanTest {
+    @Before
+    public void setup() {
+        System.setProperty(ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY,
+                "org.apache.zookeeper.server.NettyServerCnxnFactory");
+    }
+
+    @After
+    public void teardown() throws Exception {
+        System.clearProperty(ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY);
+    }
+
+    @Test
+    public void testGetSecureClientPort() throws IOException {
+        ZooKeeperServer zks = new ZooKeeperServer();
+        /**
+         * case 1: When secure client is not configured GetSecureClientPort
+         * should return empty string
+         */
+        ZooKeeperServerBean serverBean = new ZooKeeperServerBean(zks);
+        String result = serverBean.getSecureClientPort();
+        assertEquals("", result);
+
+        /**
+         * case 2: When secure client is configured GetSecureClientPort should
+         * return configured port
+         */
+
+        ServerCnxnFactory cnxnFactory = ServerCnxnFactory.createFactory();
+        int secureClientPort = 8443;
+        InetSocketAddress address = new InetSocketAddress(secureClientPort);
+        cnxnFactory.configure(address, 5, true);
+        zks.setSecureServerCnxnFactory(cnxnFactory);
+
+        result = serverBean.getSecureClientPort();
+        assertEquals(Integer.toString(secureClientPort), result);
+
+        // cleanup
+        cnxnFactory.shutdown();
+
+    }
+
+    @Test
+    public void testGetSecureClientAddress() throws IOException {
+        ZooKeeperServer zks = new ZooKeeperServer();
+        /**
+         * case 1: When secure client is not configured getSecureClientAddress
+         * should return empty string
+         */
+        ZooKeeperServerBean serverBean = new ZooKeeperServerBean(zks);
+        String result = serverBean.getSecureClientPort();
+        assertEquals("", result);
+
+        /**
+         * case 2: When secure client is configured getSecureClientAddress
+         * should return configured SecureClientAddress
+         */
+
+        ServerCnxnFactory cnxnFactory = ServerCnxnFactory.createFactory();
+        int secureClientPort = 8443;
+        InetSocketAddress address = new InetSocketAddress(secureClientPort);
+        cnxnFactory.configure(address, 5, true);
+        zks.setSecureServerCnxnFactory(cnxnFactory);
+
+        result = serverBean.getSecureClientAddress();
+        String ipv4 = "0.0.0.0:" + secureClientPort;
+        String ipv6 = "0:0:0:0:0:0:0:0:" + secureClientPort;
+        assertTrue(result.equals(ipv4) || result.equals(ipv6));
+
+        // cleanup
+        cnxnFactory.shutdown();
+    }
+
+}



Mime
View raw message