zookeeper git commit: ZOOKEEPER-3123: MetricsProvider Lifecycle in ZooKeeper Server

2018-09-11 Thread andor
Repository: zookeeper
Updated Branches:
  refs/heads/master 4ad2341c1 -> ef8b5ab26


ZOOKEEPER-3123: MetricsProvider Lifecycle in ZooKeeper Server

Manage the lifecycle of a MetricsProvider inside a ZooKeeper server.
- handle configuration
- start and configure the MetricsProvider
- notify shutdown to the MetricsProvider

This is an early preview, because there are some points to discuss:
- We have to throw an IOException in case of failure (in order not to change 
the current signature of main methods used to start the server)
- The patch only provides the lifecycle, it introduces some dead fields (root 
metrics context), this is expected as the real instrumentation will be done in 
a further step, is it okay ?
- Test cases cover only standalone mode, do we need to add a new suite for 
testing configuration and boot errors on QuorumPeer mode ? (the answer should 
be YES)
- MetricsProvider configuration is not subject to dynamic 'reconfig'

Configuration to the MetricsProvider is not yet handled, the idea is to let the 
user configure properties like
metricsProvider.className=o.a.z.metrics.prometheus.PrometheusMetricsProvider
metricsProvider.customParam1=value1
metricsProvider.customParam2=value2

in this case the MetricsProvider will receive {customParam1=value1, 
customParam2=value2} as parameter in configure()

is it okay ?

Author: Enrico Olivelli 

Reviewers: fang...@apache.org, an...@apache.org

Closes #601 from eolivelli/fix/boot-provider and squashes the following commits:

8964ed17 [Enrico Olivelli] Fix tests, use getters in order to support Mock 
QuorumPeerConfig
93749f6a [Enrico Olivelli] fix imports
7ad552db [Enrico Olivelli] Add testcases around QuorumPeerMain
22f79eb8 [Enrico Olivelli] clean up
c92450e4 [Enrico Olivelli] implement MetricsProvider configuration, fix some 
review comments
f4f66ecb [Enrico Olivelli] ZOOKEEPER-3123 MetricsProvider Lifecycle in 
ZooKeeper Server


Project: http://git-wip-us.apache.org/repos/asf/zookeeper/repo
Commit: http://git-wip-us.apache.org/repos/asf/zookeeper/commit/ef8b5ab2
Tree: http://git-wip-us.apache.org/repos/asf/zookeeper/tree/ef8b5ab2
Diff: http://git-wip-us.apache.org/repos/asf/zookeeper/diff/ef8b5ab2

Branch: refs/heads/master
Commit: ef8b5ab263270e41504dddc5fcc8c6b3419e5b4b
Parents: 4ad2341
Author: Enrico Olivelli 
Authored: Tue Sep 11 15:23:32 2018 +0200
Committer: Andor Molnar 
Committed: Tue Sep 11 15:23:32 2018 +0200

--
 .../metrics/impl/MetricsProviderBootstrap.java  |  50 +++
 .../metrics/impl/NullMetricsProvider.java   | 100 +
 .../apache/zookeeper/server/ServerConfig.java   |   9 +
 .../zookeeper/server/ZooKeeperServer.java   |  11 +
 .../zookeeper/server/ZooKeeperServerMain.java   |  23 +-
 .../zookeeper/server/quorum/QuorumPeer.java |   8 +
 .../server/quorum/QuorumPeerConfig.java |  20 +-
 .../zookeeper/server/quorum/QuorumPeerMain.java |  23 ++
 .../metrics/BaseTestMetricsProvider.java| 137 +++
 .../server/ZooKeeperServerMainTest.java | 197 ++
 .../server/quorum/QuorumPeerMainTest.java   | 375 +++
 11 files changed, 950 insertions(+), 3 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/zookeeper/blob/ef8b5ab2/src/java/main/org/apache/zookeeper/metrics/impl/MetricsProviderBootstrap.java
--
diff --git 
a/src/java/main/org/apache/zookeeper/metrics/impl/MetricsProviderBootstrap.java 
b/src/java/main/org/apache/zookeeper/metrics/impl/MetricsProviderBootstrap.java
new file mode 100644
index 000..85716b2
--- /dev/null
+++ 
b/src/java/main/org/apache/zookeeper/metrics/impl/MetricsProviderBootstrap.java
@@ -0,0 +1,50 @@
+/**
+ * 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.metrics.impl;
+
+import java.util.Properties;
+import org.apache.zookeeper.metrics.MetricsProvider;
+import org.apache.zookeeper.metrics.MetricsProviderLifeCycleException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Utility for bootstrap process of MetricsProviders
+ */
+public abstr

zookeeper git commit: ZOOKEEPER-2261: When only secureClientPort is configured connections, configuration, connection_stat_reset, and stats admin commands throw NullPointerException

2018-09-11 Thread hanm
Repository: zookeeper
Updated Branches:
  refs/heads/branch-3.5 5bcbb2ca6 -> 14d0aaab8


ZOOKEEPER-2261: When only secureClientPort is configured connections, 
configuration, connection_stat_reset, and stats admin commands throw 
NullPointerException

Root cause of the issue is that property getter returns the non-secure 
ServerCnxnFactory instance always. When Quorum SSL is enabled, we set a 
separate field which is the secure instance.

Property getter should detect the scenario and return the proper instance.

First commit contains some refactoring: shuffling the existing ZooKeeperServer 
tests to relevant places.
Second commit is the actual fix + new unit tests.

Sorry about indentation changes, but `FileTxnLogTest.java` was indented by 2 
spaces instead of 4.

Author: Andor Molnar 
Author: Andor Molnar 

Reviewers: breed, hanm, nkalmar

Closes #545 from anmolnar/ZOOKEEPER-2261


Project: http://git-wip-us.apache.org/repos/asf/zookeeper/repo
Commit: http://git-wip-us.apache.org/repos/asf/zookeeper/commit/14d0aaab
Tree: http://git-wip-us.apache.org/repos/asf/zookeeper/tree/14d0aaab
Diff: http://git-wip-us.apache.org/repos/asf/zookeeper/diff/14d0aaab

Branch: refs/heads/branch-3.5
Commit: 14d0aaab853d535be268a1d7a234c9c47bf4cd25
Parents: 5bcbb2c
Author: Andor Molnar 
Authored: Mon Sep 10 15:17:45 2018 -0700
Committer: Michael Han 
Committed: Tue Sep 11 13:09:50 2018 -0700

--
 .../zookeeper/server/ZooKeeperServer.java   |  4 
 .../apache/zookeeper/server/admin/Commands.java | 16 -
 .../zookeeper/server/admin/CommandsTest.java| 25 ++--
 3 files changed, 42 insertions(+), 3 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/zookeeper/blob/14d0aaab/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java
--
diff --git a/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java 
b/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java
index 4934203..eb93478 100644
--- a/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java
+++ b/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java
@@ -864,6 +864,10 @@ public class ZooKeeperServer implements SessionExpirer, 
ServerStats.Provider {
 return serverCnxnFactory;
 }
 
+public ServerCnxnFactory getSecureServerCnxnFactory() {
+return secureServerCnxnFactory;
+}
+
 public void setSecureServerCnxnFactory(ServerCnxnFactory factory) {
 secureServerCnxnFactory = factory;
 }

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/14d0aaab/src/java/main/org/apache/zookeeper/server/admin/Commands.java
--
diff --git a/src/java/main/org/apache/zookeeper/server/admin/Commands.java 
b/src/java/main/org/apache/zookeeper/server/admin/Commands.java
index 4712261..f83b2f4 100644
--- a/src/java/main/org/apache/zookeeper/server/admin/Commands.java
+++ b/src/java/main/org/apache/zookeeper/server/admin/Commands.java
@@ -18,7 +18,9 @@
 
 package org.apache.zookeeper.server.admin;
 
+import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -29,6 +31,7 @@ import org.apache.zookeeper.Environment;
 import org.apache.zookeeper.Environment.Entry;
 import org.apache.zookeeper.Version;
 import org.apache.zookeeper.server.DataTree;
+import org.apache.zookeeper.server.ServerCnxnFactory;
 import org.apache.zookeeper.server.ServerStats;
 import org.apache.zookeeper.server.ZKDatabase;
 import org.apache.zookeeper.server.ZooKeeperServer;
@@ -174,7 +177,18 @@ public class Commands {
 @Override
 public CommandResponse run(ZooKeeperServer zkServer, Map kwargs) {
 CommandResponse response = initializeResponse();
-response.put("connections", 
zkServer.getServerCnxnFactory().getAllConnectionInfo(false));
+ServerCnxnFactory serverCnxnFactory = 
zkServer.getServerCnxnFactory();
+if (serverCnxnFactory != null) {
+response.put("connections", 
serverCnxnFactory.getAllConnectionInfo(false));
+} else {
+response.put("connections", Collections.emptyList());
+}
+ServerCnxnFactory secureServerCnxnFactory = 
zkServer.getSecureServerCnxnFactory();
+if (secureServerCnxnFactory != null) {
+response.put("secure_connections", 
secureServerCnxnFactory.getAllConnectionInfo(false));
+} else {
+response.put("secure_connections", Collections.emptyList());
+}
 return response;
 }
 }

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/14d0aaab/src/java/test/org/apache/zookeeper/server/admin/CommandsTest.java