Author: rgs
Date: Mon Dec 7 05:27:58 2015
New Revision: 1718256
URL: http://svn.apache.org/viewvc?rev=1718256&view=rev
Log:
ZOOKEEPER-2300: Expose SecureClientPort and SecureClientAddress JMX properties
(Arshad Mohammad via rgs)
Added:
zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/ZooKeeperServerBeanTest.java
Modified:
zookeeper/branches/branch-3.5/CHANGES.txt
zookeeper/branches/branch-3.5/src/java/main/org/apache/zookeeper/server/ZooKeeperServerBean.java
zookeeper/branches/branch-3.5/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMXBean.java
Modified: zookeeper/branches/branch-3.5/CHANGES.txt
URL:
http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/CHANGES.txt?rev=1718256&r1=1718255&r2=1718256&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/CHANGES.txt (original)
+++ zookeeper/branches/branch-3.5/CHANGES.txt Mon Dec 7 05:27:58 2015
@@ -103,6 +103,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.1 - 07/27/2015
NEW FEATURES:
Modified:
zookeeper/branches/branch-3.5/src/java/main/org/apache/zookeeper/server/ZooKeeperServerBean.java
URL:
http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/main/org/apache/zookeeper/server/ZooKeeperServerBean.java?rev=1718256&r1=1718255&r2=1718256&view=diff
==============================================================================
---
zookeeper/branches/branch-3.5/src/java/main/org/apache/zookeeper/server/ZooKeeperServerBean.java
(original)
+++
zookeeper/branches/branch-3.5/src/java/main/org/apache/zookeeper/server/ZooKeeperServerBean.java
Mon Dec 7 05:27:58 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/branches/branch-3.5/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMXBean.java
URL:
http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMXBean.java?rev=1718256&r1=1718255&r2=1718256&view=diff
==============================================================================
---
zookeeper/branches/branch-3.5/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMXBean.java
(original)
+++
zookeeper/branches/branch-3.5/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMXBean.java
Mon Dec 7 05:27:58 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/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/ZooKeeperServerBeanTest.java
URL:
http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/ZooKeeperServerBeanTest.java?rev=1718256&view=auto
==============================================================================
---
zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/ZooKeeperServerBeanTest.java
(added)
+++
zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/ZooKeeperServerBeanTest.java
Mon Dec 7 05:27:58 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();
+ }
+
+}