You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by ph...@apache.org on 2014/07/18 02:19:03 UTC
svn commit: r1611516 [1/3] - in /zookeeper/trunk: ./ docs/
src/docs/src/documentation/content/xdocs/
src/java/main/org/apache/zookeeper/server/
src/java/main/org/apache/zookeeper/server/admin/
src/java/main/org/apache/zookeeper/server/quorum/ src/java/...
Author: phunt
Date: Fri Jul 18 00:19:01 2014
New Revision: 1611516
URL: http://svn.apache.org/r1611516
Log:
ZOOKEEPER-1346. Add Jetty HTTP server support for four letter words. (Skye Wanderman-Milne, Bill Havanki via phunt)
Added:
zookeeper/trunk/src/java/main/org/apache/zookeeper/server/WatchesPathReport.java
zookeeper/trunk/src/java/main/org/apache/zookeeper/server/WatchesReport.java
zookeeper/trunk/src/java/main/org/apache/zookeeper/server/WatchesSummary.java
zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerConf.java
zookeeper/trunk/src/java/main/org/apache/zookeeper/server/admin/
zookeeper/trunk/src/java/main/org/apache/zookeeper/server/admin/AdminServer.java
zookeeper/trunk/src/java/main/org/apache/zookeeper/server/admin/AdminServerFactory.java
zookeeper/trunk/src/java/main/org/apache/zookeeper/server/admin/Command.java
zookeeper/trunk/src/java/main/org/apache/zookeeper/server/admin/CommandBase.java
zookeeper/trunk/src/java/main/org/apache/zookeeper/server/admin/CommandOutputter.java
zookeeper/trunk/src/java/main/org/apache/zookeeper/server/admin/CommandResponse.java
zookeeper/trunk/src/java/main/org/apache/zookeeper/server/admin/Commands.java
zookeeper/trunk/src/java/main/org/apache/zookeeper/server/admin/DummyAdminServer.java
zookeeper/trunk/src/java/main/org/apache/zookeeper/server/admin/JettyAdminServer.java
zookeeper/trunk/src/java/main/org/apache/zookeeper/server/admin/JsonOutputter.java
zookeeper/trunk/src/java/test/org/apache/zookeeper/server/WatchesPathReportTest.java
zookeeper/trunk/src/java/test/org/apache/zookeeper/server/WatchesReportTest.java
zookeeper/trunk/src/java/test/org/apache/zookeeper/server/WatchesSummaryTest.java
zookeeper/trunk/src/java/test/org/apache/zookeeper/server/ZooKeeperServerConfTest.java
zookeeper/trunk/src/java/test/org/apache/zookeeper/server/admin/
zookeeper/trunk/src/java/test/org/apache/zookeeper/server/admin/CommandResponseTest.java
zookeeper/trunk/src/java/test/org/apache/zookeeper/server/admin/CommandsTest.java
zookeeper/trunk/src/java/test/org/apache/zookeeper/server/admin/JettyAdminServerTest.java
Modified:
zookeeper/trunk/CHANGES.txt
zookeeper/trunk/docs/index.pdf
zookeeper/trunk/docs/javaExample.pdf
zookeeper/trunk/docs/linkmap.pdf
zookeeper/trunk/docs/recipes.pdf
zookeeper/trunk/docs/releasenotes.pdf
zookeeper/trunk/docs/zookeeperAdmin.html
zookeeper/trunk/docs/zookeeperAdmin.pdf
zookeeper/trunk/docs/zookeeperHierarchicalQuorums.pdf
zookeeper/trunk/docs/zookeeperInternals.pdf
zookeeper/trunk/docs/zookeeperJMX.pdf
zookeeper/trunk/docs/zookeeperObservers.pdf
zookeeper/trunk/docs/zookeeperOver.pdf
zookeeper/trunk/docs/zookeeperProgrammers.pdf
zookeeper/trunk/docs/zookeeperQuotas.pdf
zookeeper/trunk/docs/zookeeperStarted.pdf
zookeeper/trunk/docs/zookeeperTutorial.pdf
zookeeper/trunk/ivy.xml
zookeeper/trunk/src/docs/src/documentation/content/xdocs/zookeeperAdmin.xml
zookeeper/trunk/src/java/main/org/apache/zookeeper/server/DataTree.java
zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ExpiryQueue.java
zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NIOServerCnxnFactory.java
zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NettyServerCnxnFactory.java
zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerCnxn.java
zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerCnxnFactory.java
zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerStats.java
zookeeper/trunk/src/java/main/org/apache/zookeeper/server/SessionTracker.java
zookeeper/trunk/src/java/main/org/apache/zookeeper/server/SessionTrackerImpl.java
zookeeper/trunk/src/java/main/org/apache/zookeeper/server/WatchManager.java
zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZKDatabase.java
zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java
zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMain.java
zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooTrace.java
zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/Leader.java
zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/LeaderSessionTracker.java
zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/Learner.java
zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/LearnerSessionTracker.java
zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java
zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerMain.java
zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/ReadOnlyZooKeeperServer.java
zookeeper/trunk/src/java/test/org/apache/zookeeper/ZKTestCase.java
zookeeper/trunk/src/java/test/org/apache/zookeeper/server/PrepRequestProcessorTest.java
zookeeper/trunk/src/java/test/org/apache/zookeeper/server/quorum/QuorumPeerMainTest.java
zookeeper/trunk/src/java/test/org/apache/zookeeper/server/quorum/QuorumPeerTestBase.java
zookeeper/trunk/src/java/test/org/apache/zookeeper/server/quorum/Zab1_0Test.java
Modified: zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/trunk/CHANGES.txt?rev=1611516&r1=1611515&r2=1611516&view=diff
==============================================================================
--- zookeeper/trunk/CHANGES.txt (original)
+++ zookeeper/trunk/CHANGES.txt Fri Jul 18 00:19:01 2014
@@ -34,6 +34,9 @@ NEW FEATURES:
ZOOKEEPER-827. enable r/o mode in C client library (rgs via fpj)
+ ZOOKEEPER-1346. Add Jetty HTTP server support for four letter words.
+ (Skye Wanderman-Milne, Bill Havanki via phunt)
+
BUGFIXES:
ZOOKEEPER-1900. NullPointerException in truncate (Camille Fournier)
Modified: zookeeper/trunk/docs/index.pdf
URL: http://svn.apache.org/viewvc/zookeeper/trunk/docs/index.pdf?rev=1611516&r1=1611515&r2=1611516&view=diff
==============================================================================
Binary files - no diff available.
Modified: zookeeper/trunk/docs/javaExample.pdf
URL: http://svn.apache.org/viewvc/zookeeper/trunk/docs/javaExample.pdf?rev=1611516&r1=1611515&r2=1611516&view=diff
==============================================================================
Binary files - no diff available.
Modified: zookeeper/trunk/docs/linkmap.pdf
URL: http://svn.apache.org/viewvc/zookeeper/trunk/docs/linkmap.pdf?rev=1611516&r1=1611515&r2=1611516&view=diff
==============================================================================
Binary files - no diff available.
Modified: zookeeper/trunk/docs/recipes.pdf
URL: http://svn.apache.org/viewvc/zookeeper/trunk/docs/recipes.pdf?rev=1611516&r1=1611515&r2=1611516&view=diff
==============================================================================
Binary files - no diff available.
Modified: zookeeper/trunk/docs/releasenotes.pdf
URL: http://svn.apache.org/viewvc/zookeeper/trunk/docs/releasenotes.pdf?rev=1611516&r1=1611515&r2=1611516&view=diff
==============================================================================
Binary files - no diff available.
Modified: zookeeper/trunk/docs/zookeeperAdmin.html
URL: http://svn.apache.org/viewvc/zookeeper/trunk/docs/zookeeperAdmin.html?rev=1611516&r1=1611515&r2=1611516&view=diff
==============================================================================
--- zookeeper/trunk/docs/zookeeperAdmin.html (original)
+++ zookeeper/trunk/docs/zookeeperAdmin.html Fri Jul 18 00:19:01 2014
@@ -290,10 +290,21 @@ document.write("Last Published: " + docu
<li>
<a href="#Communication+using+the+Netty+framework">Communication using the Netty framework</a>
</li>
+<li>
+<a href="#sc_adminserver_config">AdminServer configuration</a>
+</li>
</ul>
</li>
<li>
-<a href="#sc_zkCommands">ZooKeeper Commands: The Four Letter Words</a>
+<a href="#sc_zkCommands">ZooKeeper Commands</a>
+<ul class="minitoc">
+<li>
+<a href="#The+Four+Letter+Words">The Four Letter Words</a>
+</li>
+<li>
+<a href="#sc_adminserver">The AdminServer</a>
+</li>
+</ul>
</li>
<li>
<a href="#sc_dataFileManagement">Data File Management</a>
@@ -730,7 +741,7 @@ server.3=zoo3:2888:3888</pre>
<li>
<p>
-<a href="#sc_zkCommands">ZooKeeper Commands: The Four Letter Words</a>
+<a href="#sc_zkCommands">ZooKeeper Commands</a>
</p>
</li>
@@ -1648,59 +1659,97 @@ server.3=zoo3:2888:3888</pre>
<p>
TBD - how to manage certificates
</p>
+<a name="sc_adminserver_config"></a>
+<h4>AdminServer configuration</h4>
+<p>
+<strong>New in 3.5.0:</strong> The following
+ options are used to configure the <a href="#sc_adminserver">AdminServer</a>.</p>
+<dl>
+
+<dt>
+<term>admin.enableServer</term>
+</dt>
+<dd>
+<p>(Java system property: <strong>zookeeper.admin.enableServer</strong>)</p>
+<p>Set to "false" to disable the AdminServer. By default the
+ AdminServer is enabled.</p>
+</dd>
+
+
+<dt>
+<term>admin.serverPort</term>
+</dt>
+<dd>
+<p>(Java system property: <strong>zookeeper.admin.serverPort</strong>)</p>
+<p>The port the embedded Jetty server listens on. Defaults to 8080.</p>
+</dd>
+
+
+<dt>
+<term>admin.commandURL</term>
+</dt>
+<dd>
+<p>(Java system property: <strong>zookeeper.admin.commandURL</strong>)</p>
+<p>The URL for listing and issuing commands relative to the
+ root URL. Defaults to "/commands".</p>
+</dd>
+
+</dl>
<a name="sc_zkCommands"></a>
-<h3 class="h4">ZooKeeper Commands: The Four Letter Words</h3>
+<h3 class="h4">ZooKeeper Commands</h3>
+<a name="The+Four+Letter+Words"></a>
+<h4>The Four Letter Words</h4>
<p>ZooKeeper responds to a small set of commands. Each command is
- composed of four letters. You issue the commands to ZooKeeper via telnet
- or nc, at the client port.</p>
+ composed of four letters. You issue the commands to ZooKeeper via telnet
+ or nc, at the client port.</p>
<p>Three of the more interesting commands: "stat" gives some
- general information about the server and connected clients,
- while "srvr" and "cons" give extended details on server and
- connections respectively.</p>
+ general information about the server and connected clients,
+ while "srvr" and "cons" give extended details on server and
+ connections respectively.</p>
<dl>
-
+
<dt>
<term>conf</term>
</dt>
<dd>
<p>
<strong>New in 3.3.0:</strong> Print
- details about serving configuration.</p>
+ details about serving configuration.</p>
</dd>
-
+
<dt>
<term>cons</term>
</dt>
<dd>
<p>
<strong>New in 3.3.0:</strong> List
- full connection/session details for all clients connected
- to this server. Includes information on numbers of packets
- received/sent, session id, operation latencies, last
- operation performed, etc...</p>
+ full connection/session details for all clients connected
+ to this server. Includes information on numbers of packets
+ received/sent, session id, operation latencies, last
+ operation performed, etc...</p>
</dd>
-
+
<dt>
<term>crst</term>
</dt>
<dd>
<p>
<strong>New in 3.3.0:</strong> Reset
- connection/session statistics for all connections.</p>
+ connection/session statistics for all connections.</p>
</dd>
-
+
<dt>
<term>dump</term>
</dt>
<dd>
<p>Lists the outstanding sessions and ephemeral nodes. This
- only works on the leader.</p>
+ only works on the leader.</p>
</dd>
-
+
<dt>
<term>envi</term>
</dt>
@@ -1708,21 +1757,21 @@ server.3=zoo3:2888:3888</pre>
<p>Print details about serving environment</p>
</dd>
-
+
<dt>
<term>ruok</term>
</dt>
<dd>
<p>Tests if server is running in a non-error state. The server
- will respond with imok if it is running. Otherwise it will not
- respond at all.</p>
+ will respond with imok if it is running. Otherwise it will not
+ respond at all.</p>
<p>A response of "imok" does not necessarily indicate that the
- server has joined the quorum, just that the server process is active
- and bound to the specified client port. Use "stat" for details on
- state wrt quorum and client connection information.</p>
+ server has joined the quorum, just that the server process is active
+ and bound to the specified client port. Use "stat" for details on
+ state wrt quorum and client connection information.</p>
</dd>
-
+
<dt>
<term>srst</term>
</dt>
@@ -1730,105 +1779,136 @@ server.3=zoo3:2888:3888</pre>
<p>Reset server statistics.</p>
</dd>
-
+
<dt>
<term>srvr</term>
</dt>
<dd>
<p>
<strong>New in 3.3.0:</strong> Lists
- full details for the server.</p>
+ full details for the server.</p>
</dd>
-
+
<dt>
<term>stat</term>
</dt>
<dd>
<p>Lists brief details for the server and connected
- clients.</p>
+ clients.</p>
</dd>
-
+
<dt>
<term>wchs</term>
</dt>
<dd>
<p>
<strong>New in 3.3.0:</strong> Lists
- brief information on watches for the server.</p>
+ brief information on watches for the server.</p>
</dd>
-
+
<dt>
<term>wchc</term>
</dt>
<dd>
<p>
<strong>New in 3.3.0:</strong> Lists
- detailed information on watches for the server, by
- session. This outputs a list of sessions(connections)
- with associated watches (paths). Note, depending on the
- number of watches this operation may be expensive (ie
- impact server performance), use it carefully.</p>
+ detailed information on watches for the server, by
+ session. This outputs a list of sessions(connections)
+ with associated watches (paths). Note, depending on the
+ number of watches this operation may be expensive (ie
+ impact server performance), use it carefully.</p>
</dd>
-
+
<dt>
<term>wchp</term>
</dt>
<dd>
<p>
<strong>New in 3.3.0:</strong> Lists
- detailed information on watches for the server, by path.
- This outputs a list of paths (znodes) with associated
- sessions. Note, depending on the number of watches this
- operation may be expensive (ie impact server performance),
- use it carefully.</p>
+ detailed information on watches for the server, by path.
+ This outputs a list of paths (znodes) with associated
+ sessions. Note, depending on the number of watches this
+ operation may be expensive (ie impact server performance),
+ use it carefully.</p>
</dd>
-
+
<dt>
<term>mntr</term>
</dt>
<dd>
<p>
<strong>New in 3.4.0:</strong> Outputs a list
- of variables that could be used for monitoring the health of the cluster.</p>
+ of variables that could be used for monitoring the health of the cluster.</p>
<pre class="code">$ echo mntr | nc localhost 2185
-zk_version 3.4.0
-zk_avg_latency 0
-zk_max_latency 0
-zk_min_latency 0
-zk_packets_received 70
-zk_packets_sent 69
-zk_outstanding_requests 0
-zk_server_state leader
-zk_znode_count 4
-zk_watch_count 0
-zk_ephemerals_count 0
-zk_approximate_data_size 27
-zk_followers 4 - only exposed by the Leader
-zk_synced_followers 4 - only exposed by the Leader
-zk_pending_syncs 0 - only exposed by the Leader
-zk_open_file_descriptor_count 23 - only available on Unix platforms
-zk_max_file_descriptor_count 1024 - only available on Unix platforms
-</pre>
+ zk_version 3.4.0
+ zk_avg_latency 0
+ zk_max_latency 0
+ zk_min_latency 0
+ zk_packets_received 70
+ zk_packets_sent 69
+ zk_outstanding_requests 0
+ zk_server_state leader
+ zk_znode_count 4
+ zk_watch_count 0
+ zk_ephemerals_count 0
+ zk_approximate_data_size 27
+ zk_followers 4 - only exposed by the Leader
+ zk_synced_followers 4 - only exposed by the Leader
+ zk_pending_syncs 0 - only exposed by the Leader
+ zk_open_file_descriptor_count 23 - only available on Unix platforms
+ zk_max_file_descriptor_count 1024 - only available on Unix platforms
+ </pre>
<p>The output is compatible with java properties format and the content
- may change over time (new keys added). Your scripts should expect changes.</p>
+ may change over time (new keys added). Your scripts should expect changes.</p>
<p>ATTENTION: Some of the keys are platform specific and some of the keys are only exported by the Leader. </p>
<p>The output contains multiple lines with the following format:</p>
<pre class="code">key \t value</pre>
</dd>
-
+
</dl>
<p>Here's an example of the <strong>ruok</strong>
- command:</p>
+ command:</p>
<pre class="code">$ echo ruok | nc 127.0.0.1 5111
-imok
-</pre>
+ imok
+ </pre>
+<a name="sc_adminserver"></a>
+<h4>The AdminServer</h4>
+<p>
+<strong>New in 3.5.0: </strong>The AdminServer is
+ an embedded Jetty server that provides an HTTP interface to the four
+ letter word commands. By default, the server is started on port 8080,
+ and commands are issued by going to the URL "/commands/[command name]",
+ e.g., http://localhost:8080/commands/stat. The command response is
+ returned as JSON. Unlike the original protocol, commands are not
+ restricted to four-letter names, and commands can have multiple names;
+ for instance, "stmk" can also be referred to as "set_trace_mask". To
+ view a list of all available commands, point a browser to the URL
+ /commands (e.g., http://localhost:8080/commands). See the <a href="#sc_adminserver_config">AdminServer configuration options</a>
+ for how to change the port and URLs.</p>
+<p>The AdminServer is enabled by default, but can be disabled by either:</p>
+<ul>
+
+<li>
+<p>Setting the zookeeper.admin.enableServer system
+ property to false.</p>
+</li>
+
+<li>
+<p>Removing Jetty from the classpath. (This option is
+ useful if you would like to override ZooKeeper's jetty
+ dependency.)</p>
+</li>
+
+</ul>
+<p>Note that the TCP four letter word interface is still available if
+ the AdminServer is disabled.</p>
<a name="sc_dataFileManagement"></a>
<h3 class="h4">Data File Management</h3>
<p>ZooKeeper stores its data in a data directory and its transaction
Modified: zookeeper/trunk/docs/zookeeperAdmin.pdf
URL: http://svn.apache.org/viewvc/zookeeper/trunk/docs/zookeeperAdmin.pdf?rev=1611516&r1=1611515&r2=1611516&view=diff
==============================================================================
Binary files - no diff available.
Modified: zookeeper/trunk/docs/zookeeperHierarchicalQuorums.pdf
URL: http://svn.apache.org/viewvc/zookeeper/trunk/docs/zookeeperHierarchicalQuorums.pdf?rev=1611516&r1=1611515&r2=1611516&view=diff
==============================================================================
Files zookeeper/trunk/docs/zookeeperHierarchicalQuorums.pdf (original) and zookeeper/trunk/docs/zookeeperHierarchicalQuorums.pdf Fri Jul 18 00:19:01 2014 differ
Modified: zookeeper/trunk/docs/zookeeperInternals.pdf
URL: http://svn.apache.org/viewvc/zookeeper/trunk/docs/zookeeperInternals.pdf?rev=1611516&r1=1611515&r2=1611516&view=diff
==============================================================================
Binary files - no diff available.
Modified: zookeeper/trunk/docs/zookeeperJMX.pdf
URL: http://svn.apache.org/viewvc/zookeeper/trunk/docs/zookeeperJMX.pdf?rev=1611516&r1=1611515&r2=1611516&view=diff
==============================================================================
Files zookeeper/trunk/docs/zookeeperJMX.pdf (original) and zookeeper/trunk/docs/zookeeperJMX.pdf Fri Jul 18 00:19:01 2014 differ
Modified: zookeeper/trunk/docs/zookeeperObservers.pdf
URL: http://svn.apache.org/viewvc/zookeeper/trunk/docs/zookeeperObservers.pdf?rev=1611516&r1=1611515&r2=1611516&view=diff
==============================================================================
Files zookeeper/trunk/docs/zookeeperObservers.pdf (original) and zookeeper/trunk/docs/zookeeperObservers.pdf Fri Jul 18 00:19:01 2014 differ
Modified: zookeeper/trunk/docs/zookeeperOver.pdf
URL: http://svn.apache.org/viewvc/zookeeper/trunk/docs/zookeeperOver.pdf?rev=1611516&r1=1611515&r2=1611516&view=diff
==============================================================================
Binary files - no diff available.
Modified: zookeeper/trunk/docs/zookeeperProgrammers.pdf
URL: http://svn.apache.org/viewvc/zookeeper/trunk/docs/zookeeperProgrammers.pdf?rev=1611516&r1=1611515&r2=1611516&view=diff
==============================================================================
Binary files - no diff available.
Modified: zookeeper/trunk/docs/zookeeperQuotas.pdf
URL: http://svn.apache.org/viewvc/zookeeper/trunk/docs/zookeeperQuotas.pdf?rev=1611516&r1=1611515&r2=1611516&view=diff
==============================================================================
Files zookeeper/trunk/docs/zookeeperQuotas.pdf (original) and zookeeper/trunk/docs/zookeeperQuotas.pdf Fri Jul 18 00:19:01 2014 differ
Modified: zookeeper/trunk/docs/zookeeperStarted.pdf
URL: http://svn.apache.org/viewvc/zookeeper/trunk/docs/zookeeperStarted.pdf?rev=1611516&r1=1611515&r2=1611516&view=diff
==============================================================================
Binary files - no diff available.
Modified: zookeeper/trunk/docs/zookeeperTutorial.pdf
URL: http://svn.apache.org/viewvc/zookeeper/trunk/docs/zookeeperTutorial.pdf?rev=1611516&r1=1611515&r2=1611516&view=diff
==============================================================================
Binary files - no diff available.
Modified: zookeeper/trunk/ivy.xml
URL: http://svn.apache.org/viewvc/zookeeper/trunk/ivy.xml?rev=1611516&r1=1611515&r2=1611516&view=diff
==============================================================================
--- zookeeper/trunk/ivy.xml (original)
+++ zookeeper/trunk/ivy.xml Fri Jul 18 00:19:01 2014
@@ -76,5 +76,8 @@
rev="3.2.1" conf="releaseaudit->default"/>
<dependency org="net.java.dev.javacc" name="javacc" rev="5.0" />
+
+ <dependency org="org.mortbay.jetty" name="jetty" rev="6.1.26" />
+ <dependency org="org.codehaus.jackson" name="jackson-mapper-asl" rev="1.9.11" />
</dependencies>
</ivy-module>
Modified: zookeeper/trunk/src/docs/src/documentation/content/xdocs/zookeeperAdmin.xml
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/docs/src/documentation/content/xdocs/zookeeperAdmin.xml?rev=1611516&r1=1611515&r2=1611516&view=diff
==============================================================================
--- zookeeper/trunk/src/docs/src/documentation/content/xdocs/zookeeperAdmin.xml (original)
+++ zookeeper/trunk/src/docs/src/documentation/content/xdocs/zookeeperAdmin.xml Fri Jul 18 00:19:01 2014
@@ -1320,194 +1320,266 @@ server.3=zoo3:2888:3888</programlisting>
</section>
+ <section id="sc_adminserver_config">
+ <title>AdminServer configuration</title>
+ <para><emphasis role="bold">New in 3.5.0:</emphasis> The following
+ options are used to configure the <ulink
+ url="#sc_adminserver">AdminServer</ulink>.</para>
+
+ <variablelist>
+ <varlistentry>
+ <term>admin.enableServer</term>
+
+ <listitem>
+ <para>(Java system property: <emphasis
+ role="bold">zookeeper.admin.enableServer</emphasis>)</para>
+
+ <para>Set to "false" to disable the AdminServer. By default the
+ AdminServer is enabled.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>admin.serverPort</term>
+
+ <listitem>
+ <para>(Java system property: <emphasis
+ role="bold">zookeeper.admin.serverPort</emphasis>)</para>
+
+ <para>The port the embedded Jetty server listens on. Defaults to 8080.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>admin.commandURL</term>
+
+ <listitem>
+ <para>(Java system property: <emphasis
+ role="bold">zookeeper.admin.commandURL</emphasis>)</para>
+
+ <para>The URL for listing and issuing commands relative to the
+ root URL. Defaults to "/commands".</para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+
</section>
<section id="sc_zkCommands">
- <title>ZooKeeper Commands: The Four Letter Words</title>
-
- <para>ZooKeeper responds to a small set of commands. Each command is
- composed of four letters. You issue the commands to ZooKeeper via telnet
- or nc, at the client port.</para>
-
- <para>Three of the more interesting commands: "stat" gives some
- general information about the server and connected clients,
- while "srvr" and "cons" give extended details on server and
- connections respectively.</para>
-
- <variablelist>
- <varlistentry>
- <term>conf</term>
-
- <listitem>
- <para><emphasis role="bold">New in 3.3.0:</emphasis> Print
- details about serving configuration.</para>
- </listitem>
-
- </varlistentry>
-
- <varlistentry>
- <term>cons</term>
-
- <listitem>
- <para><emphasis role="bold">New in 3.3.0:</emphasis> List
- full connection/session details for all clients connected
- to this server. Includes information on numbers of packets
- received/sent, session id, operation latencies, last
- operation performed, etc...</para>
- </listitem>
-
- </varlistentry>
-
- <varlistentry>
- <term>crst</term>
-
- <listitem>
- <para><emphasis role="bold">New in 3.3.0:</emphasis> Reset
- connection/session statistics for all connections.</para>
- </listitem>
- </varlistentry>
-
- <varlistentry>
- <term>dump</term>
-
- <listitem>
- <para>Lists the outstanding sessions and ephemeral nodes. This
- only works on the leader.</para>
- </listitem>
- </varlistentry>
-
- <varlistentry>
- <term>envi</term>
-
- <listitem>
- <para>Print details about serving environment</para>
- </listitem>
- </varlistentry>
-
- <varlistentry>
- <term>ruok</term>
-
- <listitem>
- <para>Tests if server is running in a non-error state. The server
- will respond with imok if it is running. Otherwise it will not
- respond at all.</para>
-
- <para>A response of "imok" does not necessarily indicate that the
- server has joined the quorum, just that the server process is active
- and bound to the specified client port. Use "stat" for details on
- state wrt quorum and client connection information.</para>
- </listitem>
- </varlistentry>
-
- <varlistentry>
- <term>srst</term>
-
- <listitem>
- <para>Reset server statistics.</para>
- </listitem>
- </varlistentry>
+ <title>ZooKeeper Commands</title>
- <varlistentry>
- <term>srvr</term>
-
- <listitem>
- <para><emphasis role="bold">New in 3.3.0:</emphasis> Lists
- full details for the server.</para>
- </listitem>
- </varlistentry>
-
- <varlistentry>
- <term>stat</term>
-
- <listitem>
- <para>Lists brief details for the server and connected
- clients.</para>
- </listitem>
- </varlistentry>
-
- <varlistentry>
- <term>wchs</term>
-
- <listitem>
- <para><emphasis role="bold">New in 3.3.0:</emphasis> Lists
- brief information on watches for the server.</para>
- </listitem>
- </varlistentry>
-
- <varlistentry>
- <term>wchc</term>
-
- <listitem>
- <para><emphasis role="bold">New in 3.3.0:</emphasis> Lists
- detailed information on watches for the server, by
- session. This outputs a list of sessions(connections)
- with associated watches (paths). Note, depending on the
- number of watches this operation may be expensive (ie
- impact server performance), use it carefully.</para>
- </listitem>
- </varlistentry>
-
- <varlistentry>
- <term>wchp</term>
-
- <listitem>
- <para><emphasis role="bold">New in 3.3.0:</emphasis> Lists
- detailed information on watches for the server, by path.
- This outputs a list of paths (znodes) with associated
- sessions. Note, depending on the number of watches this
- operation may be expensive (ie impact server performance),
- use it carefully.</para>
- </listitem>
- </varlistentry>
-
-
- <varlistentry>
- <term>mntr</term>
-
- <listitem>
- <para><emphasis role="bold">New in 3.4.0:</emphasis> Outputs a list
- of variables that could be used for monitoring the health of the cluster.</para>
-
- <programlisting>$ echo mntr | nc localhost 2185
-
-zk_version 3.4.0
-zk_avg_latency 0
-zk_max_latency 0
-zk_min_latency 0
-zk_packets_received 70
-zk_packets_sent 69
-zk_outstanding_requests 0
-zk_server_state leader
-zk_znode_count 4
-zk_watch_count 0
-zk_ephemerals_count 0
-zk_approximate_data_size 27
-zk_followers 4 - only exposed by the Leader
-zk_synced_followers 4 - only exposed by the Leader
-zk_pending_syncs 0 - only exposed by the Leader
-zk_open_file_descriptor_count 23 - only available on Unix platforms
-zk_max_file_descriptor_count 1024 - only available on Unix platforms
-</programlisting>
-
- <para>The output is compatible with java properties format and the content
- may change over time (new keys added). Your scripts should expect changes.</para>
-
- <para>ATTENTION: Some of the keys are platform specific and some of the keys are only exported by the Leader. </para>
-
- <para>The output contains multiple lines with the following format:</para>
- <programlisting>key \t value</programlisting>
- </listitem>
- </varlistentry>
- </variablelist>
-
- <para>Here's an example of the <emphasis role="bold">ruok</emphasis>
- command:</para>
+ <section>
+ <title>The Four Letter Words</title>
+ <para>ZooKeeper responds to a small set of commands. Each command is
+ composed of four letters. You issue the commands to ZooKeeper via telnet
+ or nc, at the client port.</para>
+
+ <para>Three of the more interesting commands: "stat" gives some
+ general information about the server and connected clients,
+ while "srvr" and "cons" give extended details on server and
+ connections respectively.</para>
+
+ <variablelist>
+ <varlistentry>
+ <term>conf</term>
+
+ <listitem>
+ <para><emphasis role="bold">New in 3.3.0:</emphasis> Print
+ details about serving configuration.</para>
+ </listitem>
+
+ </varlistentry>
+
+ <varlistentry>
+ <term>cons</term>
+
+ <listitem>
+ <para><emphasis role="bold">New in 3.3.0:</emphasis> List
+ full connection/session details for all clients connected
+ to this server. Includes information on numbers of packets
+ received/sent, session id, operation latencies, last
+ operation performed, etc...</para>
+ </listitem>
+
+ </varlistentry>
+
+ <varlistentry>
+ <term>crst</term>
+
+ <listitem>
+ <para><emphasis role="bold">New in 3.3.0:</emphasis> Reset
+ connection/session statistics for all connections.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>dump</term>
+
+ <listitem>
+ <para>Lists the outstanding sessions and ephemeral nodes. This
+ only works on the leader.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>envi</term>
+
+ <listitem>
+ <para>Print details about serving environment</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>ruok</term>
+
+ <listitem>
+ <para>Tests if server is running in a non-error state. The server
+ will respond with imok if it is running. Otherwise it will not
+ respond at all.</para>
+
+ <para>A response of "imok" does not necessarily indicate that the
+ server has joined the quorum, just that the server process is active
+ and bound to the specified client port. Use "stat" for details on
+ state wrt quorum and client connection information.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>srst</term>
+
+ <listitem>
+ <para>Reset server statistics.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>srvr</term>
+
+ <listitem>
+ <para><emphasis role="bold">New in 3.3.0:</emphasis> Lists
+ full details for the server.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>stat</term>
+
+ <listitem>
+ <para>Lists brief details for the server and connected
+ clients.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>wchs</term>
+
+ <listitem>
+ <para><emphasis role="bold">New in 3.3.0:</emphasis> Lists
+ brief information on watches for the server.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>wchc</term>
+
+ <listitem>
+ <para><emphasis role="bold">New in 3.3.0:</emphasis> Lists
+ detailed information on watches for the server, by
+ session. This outputs a list of sessions(connections)
+ with associated watches (paths). Note, depending on the
+ number of watches this operation may be expensive (ie
+ impact server performance), use it carefully.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>wchp</term>
+
+ <listitem>
+ <para><emphasis role="bold">New in 3.3.0:</emphasis> Lists
+ detailed information on watches for the server, by path.
+ This outputs a list of paths (znodes) with associated
+ sessions. Note, depending on the number of watches this
+ operation may be expensive (ie impact server performance),
+ use it carefully.</para>
+ </listitem>
+ </varlistentry>
+
+
+ <varlistentry>
+ <term>mntr</term>
+
+ <listitem>
+ <para><emphasis role="bold">New in 3.4.0:</emphasis> Outputs a list
+ of variables that could be used for monitoring the health of the cluster.</para>
+
+ <programlisting>$ echo mntr | nc localhost 2185
+
+ zk_version 3.4.0
+ zk_avg_latency 0
+ zk_max_latency 0
+ zk_min_latency 0
+ zk_packets_received 70
+ zk_packets_sent 69
+ zk_outstanding_requests 0
+ zk_server_state leader
+ zk_znode_count 4
+ zk_watch_count 0
+ zk_ephemerals_count 0
+ zk_approximate_data_size 27
+ zk_followers 4 - only exposed by the Leader
+ zk_synced_followers 4 - only exposed by the Leader
+ zk_pending_syncs 0 - only exposed by the Leader
+ zk_open_file_descriptor_count 23 - only available on Unix platforms
+ zk_max_file_descriptor_count 1024 - only available on Unix platforms
+ </programlisting>
+
+ <para>The output is compatible with java properties format and the content
+ may change over time (new keys added). Your scripts should expect changes.</para>
+
+ <para>ATTENTION: Some of the keys are platform specific and some of the keys are only exported by the Leader. </para>
+
+ <para>The output contains multiple lines with the following format:</para>
+ <programlisting>key \t value</programlisting>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+
+ <para>Here's an example of the <emphasis role="bold">ruok</emphasis>
+ command:</para>
+
+ <programlisting>$ echo ruok | nc 127.0.0.1 5111
+ imok
+ </programlisting>
- <programlisting>$ echo ruok | nc 127.0.0.1 5111
-imok
-</programlisting>
+ </section>
+ <section id="sc_adminserver">
+ <title>The AdminServer</title>
+ <para><emphasis role="bold">New in 3.5.0: </emphasis>The AdminServer is
+ an embedded Jetty server that provides an HTTP interface to the four
+ letter word commands. By default, the server is started on port 8080,
+ and commands are issued by going to the URL "/commands/[command name]",
+ e.g., http://localhost:8080/commands/stat. The command response is
+ returned as JSON. Unlike the original protocol, commands are not
+ restricted to four-letter names, and commands can have multiple names;
+ for instance, "stmk" can also be referred to as "set_trace_mask". To
+ view a list of all available commands, point a browser to the URL
+ /commands (e.g., http://localhost:8080/commands). See the <ulink
+ url="#sc_adminserver_config">AdminServer configuration options</ulink>
+ for how to change the port and URLs.</para>
-
+ <para>The AdminServer is enabled by default, but can be disabled by either:</para>
+ <itemizedlist>
+ <listitem><para>Setting the zookeeper.admin.enableServer system
+ property to false.</para></listitem>
+ <listitem><para>Removing Jetty from the classpath. (This option is
+ useful if you would like to override ZooKeeper's jetty
+ dependency.)</para></listitem>
+ </itemizedlist>
+ <para>Note that the TCP four letter word interface is still available if
+ the AdminServer is disabled.</para>
+ </section>
</section>
<section id="sc_dataFileManagement">
Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/server/DataTree.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/DataTree.java?rev=1611516&r1=1611515&r2=1611516&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/server/DataTree.java (original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/server/DataTree.java Fri Jul 18 00:19:01 2014
@@ -27,6 +27,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
@@ -223,7 +224,7 @@ public class DataTree {
return dataWatches.size() + childWatches.size();
}
- int getEphemeralsCount() {
+ public int getEphemeralsCount() {
int result = 0;
for (HashSet<String> set : ephemerals.values()) {
result += set.size();
@@ -1264,6 +1265,36 @@ public class DataTree {
}
/**
+ * Returns a watch report.
+ *
+ * @return watch report
+ * @see WatchesReport
+ */
+ public synchronized WatchesReport getWatches() {
+ return dataWatches.getWatches();
+ }
+
+ /**
+ * Returns a watch report by path.
+ *
+ * @return watch report
+ * @see WatchesPathReport
+ */
+ public synchronized WatchesPathReport getWatchesByPath() {
+ return dataWatches.getWatchesByPath();
+ }
+
+ /**
+ * Returns a watch summary.
+ *
+ * @return watch summary
+ * @see WatchesSummary
+ */
+ public synchronized WatchesSummary getWatchesSummary() {
+ return dataWatches.getWatchesSummary();
+ }
+
+ /**
* Write a text dump of all the ephemerals in the datatree.
* @param pwriter the output to write to
*/
@@ -1285,6 +1316,21 @@ public class DataTree {
}
}
+ /**
+ * Returns a mapping of session ID to ephemeral znodes.
+ *
+ * @return map of session ID to sets of ephemeral znodes
+ */
+ public Map<Long, Set<String>> getEphemerals() {
+ HashMap<Long, Set<String>> ephemeralsCopy = new HashMap<Long, Set<String>>();
+ for (Entry<Long, HashSet<String>> e : ephemerals.entrySet()) {
+ synchronized (e.getValue()) {
+ ephemeralsCopy.put(e.getKey(), new HashSet<String>(e.getValue()));
+ }
+ }
+ return ephemeralsCopy;
+ }
+
public void removeCnxn(Watcher watcher) {
dataWatches.removeWatcher(watcher);
childWatches.removeWatcher(watcher);
Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ExpiryQueue.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ExpiryQueue.java?rev=1611516&r1=1611515&r2=1611516&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ExpiryQueue.java (original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ExpiryQueue.java Fri Jul 18 00:19:01 2014
@@ -22,6 +22,7 @@ import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
+import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.ConcurrentHashMap;
@@ -176,5 +177,12 @@ public class ExpiryQueue<E> {
}
}
}
+
+ /**
+ * Returns an unmodifiable view of the expiration time -> elements mapping.
+ */
+ public Map<Long, Set<E>> getExpiryMap() {
+ return Collections.unmodifiableMap(expiryMap);
+ }
}
Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NIOServerCnxnFactory.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NIOServerCnxnFactory.java?rev=1611516&r1=1611515&r2=1611516&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NIOServerCnxnFactory.java (original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NIOServerCnxnFactory.java Fri Jul 18 00:19:01 2014
@@ -31,10 +31,10 @@ import java.nio.channels.SocketChannel;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Queue;
+import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.LinkedBlockingQueue;
@@ -938,4 +938,21 @@ public class NIOServerCnxnFactory extend
cnxnExpiryQueue.dump(pwriter);
}
+ @Override
+ public void resetAllConnectionStats() {
+ // No need to synchronize since cnxns is backed by a ConcurrentHashMap
+ for(ServerCnxn c : cnxns){
+ c.resetStats();
+ }
+ }
+
+ @Override
+ public Iterable<Map<String, Object>> getAllConnectionInfo(boolean brief) {
+ HashSet<Map<String,Object>> info = new HashSet<Map<String,Object>>();
+ // No need to synchronize since cnxns is backed by a ConcurrentHashMap
+ for (ServerCnxn c : cnxns) {
+ info.add(c.getConnectionInfo(brief));
+ }
+ return info;
+ }
}
Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NettyServerCnxnFactory.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NettyServerCnxnFactory.java?rev=1611516&r1=1611515&r2=1611516&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NettyServerCnxnFactory.java (original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NettyServerCnxnFactory.java Fri Jul 18 00:19:01 2014
@@ -25,11 +25,10 @@ import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
import java.util.concurrent.Executors;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
@@ -44,6 +43,8 @@ import org.jboss.netty.channel.WriteComp
import org.jboss.netty.channel.group.ChannelGroup;
import org.jboss.netty.channel.group.DefaultChannelGroup;
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class NettyServerCnxnFactory extends ServerCnxnFactory {
private static final Logger LOG = LoggerFactory.getLogger(NettyServerCnxnFactory.class);
@@ -260,23 +261,20 @@ public class NettyServerCnxnFactory exte
if (LOG.isDebugEnabled()) {
LOG.debug("closeAll()");
}
-
- NettyServerCnxn[] allCnxns = null;
- synchronized (cnxns) {
- allCnxns = cnxns.toArray(new NettyServerCnxn[cnxns.size()]);
- }
- // got to clear all the connections that we have in the selector
- for (NettyServerCnxn cnxn : allCnxns) {
+ // clear all the connections on which we are selecting
+ int length = cnxns.size();
+ for (ServerCnxn cnxn : cnxns) {
try {
+ // This will remove the cnxn from cnxns
cnxn.close();
} catch (Exception e) {
LOG.warn("Ignoring exception closing cnxn sessionid 0x"
- + Long.toHexString(cnxn.getSessionId()), e);
+ + Long.toHexString(cnxn.getSessionId()), e);
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("allChannels size:" + allChannels.size() + " cnxns size:"
- + allCnxns.length);
+ + length);
}
}
@@ -285,11 +283,7 @@ public class NettyServerCnxnFactory exte
if (LOG.isDebugEnabled()) {
LOG.debug("closeSession sessionid:0x" + sessionId);
}
- NettyServerCnxn[] allCnxns = null;
- synchronized (cnxns) {
- allCnxns = cnxns.toArray(new NettyServerCnxn[cnxns.size()]);
- }
- for (NettyServerCnxn cnxn : allCnxns) {
+ for (ServerCnxn cnxn : cnxns) {
if (cnxn.getSessionId() == sessionId) {
try {
cnxn.close();
@@ -393,20 +387,36 @@ public class NettyServerCnxnFactory exte
}
private void addCnxn(NettyServerCnxn cnxn) {
- synchronized (cnxns) {
- cnxns.add(cnxn);
- synchronized (ipMap){
- InetAddress addr =
- ((InetSocketAddress)cnxn.channel.getRemoteAddress())
- .getAddress();
- Set<NettyServerCnxn> s = ipMap.get(addr);
- if (s == null) {
- s = new HashSet<NettyServerCnxn>();
- }
- s.add(cnxn);
- ipMap.put(addr,s);
+ cnxns.add(cnxn);
+ synchronized (ipMap){
+ InetAddress addr =
+ ((InetSocketAddress)cnxn.channel.getRemoteAddress())
+ .getAddress();
+ Set<NettyServerCnxn> s = ipMap.get(addr);
+ if (s == null) {
+ s = new HashSet<NettyServerCnxn>();
}
+ s.add(cnxn);
+ ipMap.put(addr,s);
+ }
+ }
+
+ @Override
+ public void resetAllConnectionStats() {
+ // No need to synchronize since cnxns is backed by a ConcurrentHashMap
+ for(ServerCnxn c : cnxns){
+ c.resetStats();
+ }
+ }
+
+ @Override
+ public Iterable<Map<String, Object>> getAllConnectionInfo(boolean brief) {
+ HashSet<Map<String,Object>> info = new HashSet<Map<String,Object>>();
+ // No need to synchronize since cnxns is backed by a ConcurrentHashMap
+ for (ServerCnxn c : cnxns) {
+ info.add(c.getConnectionInfo(brief));
}
+ return info;
}
}
Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerCnxn.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerCnxn.java?rev=1611516&r1=1611515&r2=1611516&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerCnxn.java (original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerCnxn.java Fri Jul 18 00:19:01 2014
@@ -27,7 +27,9 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
import org.apache.jute.Record;
@@ -458,4 +460,26 @@ public abstract class ServerCnxn impleme
pwriter.print(")");
}
+ public synchronized Map<String, Object> getConnectionInfo(boolean brief) {
+ Map<String, Object> info = new LinkedHashMap<String, Object>();
+ info.put("remote_socket_address", getRemoteSocketAddress());
+ info.put("interest_ops", getInterestOps());
+ info.put("outstanding_requests", getOutstandingRequests());
+ info.put("packets_received", getPacketsReceived());
+ info.put("packets_sent", getPacketsSent());
+ if (!brief) {
+ info.put("session_id", getSessionId());
+ info.put("last_operation", getLastOperation());
+ info.put("established", getEstablished());
+ info.put("session_timeout", getSessionTimeout());
+ info.put("last_cxid", getLastCxid());
+ info.put("last_zxid", getLastZxid());
+ info.put("last_response_time", getLastResponseTime());
+ info.put("last_latency", getLastLatency());
+ info.put("min_latency", getMinLatency());
+ info.put("avg_latency", getAvgLatency());
+ info.put("max_latency", getMaxLatency());
+ }
+ return info;
+ }
}
Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerCnxnFactory.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerCnxnFactory.java?rev=1611516&r1=1611515&r2=1611516&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerCnxnFactory.java (original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerCnxnFactory.java Fri Jul 18 00:19:01 2014
@@ -23,6 +23,8 @@ import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.util.Collections;
import java.util.Set;
+import java.util.HashSet;
+import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.management.JMException;
@@ -61,6 +63,10 @@ public abstract class ServerCnxnFactory
return cnxns.size();
}
+ public ZooKeeperServer getZooKeeperServer() {
+ return zkServer;
+ }
+
public abstract void closeSession(long sessionId);
public abstract void configure(InetSocketAddress addr,
@@ -130,6 +136,10 @@ public abstract class ServerCnxnFactory
public abstract InetSocketAddress getLocalAddress();
+ public abstract void resetAllConnectionStats();
+
+ public abstract Iterable<Map<String, Object>> getAllConnectionInfo(boolean brief);
+
private final ConcurrentHashMap<ServerCnxn, ConnectionBean> connectionBeans =
new ConcurrentHashMap<ServerCnxn, ConnectionBean>();
Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerStats.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerStats.java?rev=1611516&r1=1611515&r2=1611516&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerStats.java (original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerStats.java Fri Jul 18 00:19:01 2014
@@ -85,6 +85,10 @@ public class ServerStats {
return provider.getNumAliveConnections();
}
+ public boolean isProviderNull() {
+ return provider == null;
+ }
+
@Override
public String toString(){
StringBuilder sb = new StringBuilder();
Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/server/SessionTracker.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/SessionTracker.java?rev=1611516&r1=1611515&r2=1611516&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/server/SessionTracker.java (original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/server/SessionTracker.java Fri Jul 18 00:19:01 2014
@@ -19,6 +19,8 @@
package org.apache.zookeeper.server;
import java.io.PrintWriter;
+import java.util.Map;
+import java.util.Set;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.KeeperException.SessionExpiredException;
@@ -125,4 +127,9 @@ public interface SessionTracker {
* @param pwriter the output writer
*/
void dumpSessions(PrintWriter pwriter);
+
+ /**
+ * Returns a mapping of time to session IDs that expire at that time.
+ */
+ Map<Long, Set<Long>> getSessionExpiryMap();
}
Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/server/SessionTrackerImpl.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/SessionTrackerImpl.java?rev=1611516&r1=1611515&r2=1611516&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/server/SessionTrackerImpl.java (original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/server/SessionTrackerImpl.java Fri Jul 18 00:19:01 2014
@@ -20,9 +20,13 @@ package org.apache.zookeeper.server;
import java.io.PrintWriter;
import java.io.StringWriter;
+import java.util.HashSet;
+import java.util.Map;
import java.util.Map.Entry;
+import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
+import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicLong;
import org.apache.zookeeper.KeeperException;
@@ -103,7 +107,24 @@ public class SessionTrackerImpl extends
pwriter.print("Session ");
sessionExpiryQueue.dump(pwriter);
}
-
+
+ /**
+ * Returns a mapping from time to session IDs of sessions expiring at that time.
+ */
+ synchronized public Map<Long, Set<Long>> getSessionExpiryMap() {
+ // Convert time -> sessions map to time -> session IDs map
+ Map<Long, Set<SessionImpl>> expiryMap = sessionExpiryQueue.getExpiryMap();
+ Map<Long, Set<Long>> sessionExpiryMap = new TreeMap<Long, Set<Long>>();
+ for (Entry<Long, Set<SessionImpl>> e : expiryMap.entrySet()) {
+ Set<Long> ids = new HashSet<Long>();
+ sessionExpiryMap.put(e.getKey(), ids);
+ for (SessionImpl s : e.getValue()) {
+ ids.add(s.sessionId);
+ }
+ }
+ return sessionExpiryMap;
+ }
+
@Override
public String toString() {
StringWriter sw = new StringWriter();
Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/server/WatchManager.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/WatchManager.java?rev=1611516&r1=1611515&r2=1611516&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/server/WatchManager.java (original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/server/WatchManager.java Fri Jul 18 00:19:01 2014
@@ -21,15 +21,17 @@ package org.apache.zookeeper.server;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Set;
+import java.util.LinkedHashMap;
+import java.util.Map;
import java.util.Map.Entry;
+import java.util.Set;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.Watcher.Event.EventType;
import org.apache.zookeeper.Watcher.Event.KeeperState;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* This class manages watches. It allows watches to be associated with a string
@@ -212,4 +214,53 @@ class WatchManager {
return true;
}
+
+ /**
+ * Returns a watch report.
+ *
+ * @return watch report
+ * @see WatchesReport
+ */
+ synchronized WatchesReport getWatches() {
+ Map<Long, Set<String>> id2paths = new HashMap<Long, Set<String>>();
+ for (Entry<Watcher, HashSet<String>> e: watch2Paths.entrySet()) {
+ Long id = ((ServerCnxn) e.getKey()).getSessionId();
+ HashSet<String> paths = new HashSet<String>(e.getValue());
+ id2paths.put(id, paths);
+ }
+ return new WatchesReport(id2paths);
+ }
+
+ /**
+ * Returns a watch report by path.
+ *
+ * @return watch report
+ * @see WatchesPathReport
+ */
+ synchronized WatchesPathReport getWatchesByPath() {
+ Map<String, Set<Long>> path2ids = new HashMap<String, Set<Long>>();
+ for (Entry<String, HashSet<Watcher>> e : watchTable.entrySet()) {
+ Set<Long> ids = new HashSet<Long>(e.getValue().size());
+ path2ids.put(e.getKey(), ids);
+ for (Watcher watcher : e.getValue()) {
+ ids.add(((ServerCnxn) watcher).getSessionId());
+ }
+ }
+ return new WatchesPathReport(path2ids);
+ }
+
+ /**
+ * Returns a watch summary.
+ *
+ * @return watch summary
+ * @see WatchesSummary
+ */
+ synchronized WatchesSummary getWatchesSummary() {
+ int totalWatches = 0;
+ for (HashSet<String> paths : watch2Paths.values()) {
+ totalWatches += paths.size();
+ }
+ return new WatchesSummary (watch2Paths.size(), watchTable.size(),
+ totalWatches);
+ }
}
Added: zookeeper/trunk/src/java/main/org/apache/zookeeper/server/WatchesPathReport.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/WatchesPathReport.java?rev=1611516&view=auto
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/server/WatchesPathReport.java (added)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/server/WatchesPathReport.java Fri Jul 18 00:19:01 2014
@@ -0,0 +1,83 @@
+/*
+ * 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.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * A watch report, essentially a mapping of path to session IDs of sessions that
+ * have set a watch on that path. This class is immutable.
+ */
+public class WatchesPathReport {
+
+ private final Map<String, Set<Long>> path2Ids;
+
+ /**
+ * Creates a new report.
+ *
+ * @param path2Ids map of paths to session IDs of sessions that have set a
+ * watch on that path
+ */
+ WatchesPathReport(Map<String, Set<Long>> path2Ids) {
+ this.path2Ids = Collections.unmodifiableMap(deepCopy(path2Ids));
+ }
+
+ private static Map<String, Set<Long>> deepCopy(Map<String, Set<Long>> m) {
+ Map<String, Set<Long>> m2 = new HashMap<String, Set<Long>>();
+ for (Map.Entry<String, Set<Long>> e : m.entrySet()) {
+ m2.put(e.getKey(), new HashSet<Long>(e.getValue()));
+ }
+ return m2;
+ }
+
+ /**
+ * Checks if the given path has watches set.
+ *
+ * @param path path
+ * @return true if path has watch set
+ */
+ public boolean hasSessions(String path) {
+ return path2Ids.containsKey(path);
+ }
+ /**
+ * Gets the session IDs of sessions that have set watches on the given path.
+ * The returned set is immutable.
+ *
+ * @param path session ID
+ * @return session IDs of sessions that have set watches on the path, or
+ * null if none
+ */
+ public Set<Long> getSessions(String path) {
+ Set<Long> s = path2Ids.get(path);
+ return s != null ? Collections.unmodifiableSet(s) : null;
+ }
+
+ /**
+ * Converts this report to a map. The returned map is mutable, and changes
+ * to it do not reflect back into this report.
+ *
+ * @return map representation of report
+ */
+ public Map<String, Set<Long>> toMap() {
+ return deepCopy(path2Ids);
+ }
+}
Added: zookeeper/trunk/src/java/main/org/apache/zookeeper/server/WatchesReport.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/WatchesReport.java?rev=1611516&view=auto
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/server/WatchesReport.java (added)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/server/WatchesReport.java Fri Jul 18 00:19:01 2014
@@ -0,0 +1,83 @@
+/*
+ * 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.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * A watch report, essentially a mapping of session ID to paths that the session
+ * has set a watch on. This class is immutable.
+ */
+public class WatchesReport {
+
+ private final Map<Long, Set<String>> id2paths;
+
+ /**
+ * Creates a new report.
+ *
+ * @param id2paths map of session IDs to paths that each session has set
+ * a watch on
+ */
+ WatchesReport(Map<Long, Set<String>> id2paths) {
+ this.id2paths = Collections.unmodifiableMap(deepCopy(id2paths));
+ }
+
+ private static Map<Long, Set<String>> deepCopy(Map<Long, Set<String>> m) {
+ Map<Long, Set<String>> m2 = new HashMap<Long, Set<String>>();
+ for (Map.Entry<Long, Set<String>> e : m.entrySet()) {
+ m2.put(e.getKey(), new HashSet<String>(e.getValue()));
+ }
+ return m2;
+ }
+
+ /**
+ * Checks if the given session has watches set.
+ *
+ * @param sessionId session ID
+ * @return true if session has paths with watches set
+ */
+ public boolean hasPaths(long sessionId) {
+ return id2paths.containsKey(sessionId);
+ }
+
+ /**
+ * Gets the paths that the given session has set watches on. The returned
+ * set is immutable.
+ *
+ * @param sessionId session ID
+ * @return paths that have watches set by the session, or null if none
+ */
+ public Set<String> getPaths(long sessionId) {
+ Set<String> s = id2paths.get(sessionId);
+ return s != null ? Collections.unmodifiableSet(s) : null;
+ }
+
+ /**
+ * Converts this report to a map. The returned map is mutable, and changes
+ * to it do not reflect back into this report.
+ *
+ * @return map representation of report
+ */
+ public Map<Long, Set<String>> toMap() {
+ return deepCopy(id2paths);
+ }
+}
Added: zookeeper/trunk/src/java/main/org/apache/zookeeper/server/WatchesSummary.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/WatchesSummary.java?rev=1611516&view=auto
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/server/WatchesSummary.java (added)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/server/WatchesSummary.java Fri Jul 18 00:19:01 2014
@@ -0,0 +1,98 @@
+/*
+ * 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.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ * A summary of watch information. This class is immutable.
+ */
+public class WatchesSummary {
+
+ /**
+ * The key in the map returned by {@link #toMap()} for the number of
+ * connections.
+ */
+ public static final String KEY_NUM_CONNECTIONS = "num_connections";
+ /**
+ * The key in the map returned by {@link #toMap()} for the number of paths.
+ */
+ public static final String KEY_NUM_PATHS = "num_paths";
+ /**
+ * The key in the map returned by {@link #toMap()} for the total number of
+ * watches.
+ */
+ public static final String KEY_NUM_TOTAL_WATCHES = "num_total_watches";
+
+ private final int numConnections;
+ private final int numPaths;
+ private final int totalWatches;
+
+ /**
+ * Creates a new summary.
+ *
+ * @param numConnections the number of sessions that have set watches
+ * @param numPaths the number of paths that have watches set on them
+ * @param totalWatches the total number of watches set
+ */
+ WatchesSummary(int numConnections, int numPaths, int totalWatches) {
+ this.numConnections = numConnections;
+ this.numPaths = numPaths;
+ this.totalWatches = totalWatches;
+ }
+
+ /**
+ * Gets the number of connections (sessions) that have set watches.
+ *
+ * @return number of connections
+ */
+ public int getNumConnections() {
+ return numConnections;
+ }
+ /**
+ * Gets the number of paths that have watches set on them.
+ *
+ * @return number of paths
+ */
+ public int getNumPaths() {
+ return numPaths;
+ }
+ /**
+ * Gets the total number of watches set.
+ *
+ * @return total watches
+ */
+ public int getTotalWatches() {
+ return totalWatches;
+ }
+
+ /**
+ * Converts this summary to a map. The returned map is mutable, and changes
+ * to it do not reflect back into this summary.
+ *
+ * @return map representation of summary
+ */
+ public Map<String, Object> toMap() {
+ Map<String, Object> summary = new LinkedHashMap<String, Object>();
+ summary.put(KEY_NUM_CONNECTIONS, numConnections);
+ summary.put(KEY_NUM_PATHS, numPaths);
+ summary.put(KEY_NUM_TOTAL_WATCHES, totalWatches);
+ return summary;
+ }
+}
Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZKDatabase.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZKDatabase.java?rev=1611516&r1=1611515&r2=1611516&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZKDatabase.java (original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZKDatabase.java Fri Jul 18 00:19:01 2014
@@ -25,6 +25,7 @@ import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReentrantReadWriteLock;
@@ -359,6 +360,10 @@ public class ZKDatabase {
dataTree.dumpEphemerals(pwriter);
}
+ public Map<Long, Set<String>> getEphemerals() {
+ return dataTree.getEphemerals();
+ }
+
/**
* the node count of the datatree
* @return the node count of datatree
Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java?rev=1611516&r1=1611515&r2=1611516&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java (original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java Fri Jul 18 00:19:01 2014
@@ -27,11 +27,14 @@ import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
+import java.util.Set;
import javax.security.sasl.SaslException;
@@ -188,6 +191,18 @@ public class ZooKeeperServer implements
pwriter.println(getServerId());
}
+ public ZooKeeperServerConf getConf() {
+ return new ZooKeeperServerConf
+ (getClientPort(),
+ zkDb.snapLog.getSnapDir().getAbsolutePath(),
+ zkDb.snapLog.getDataDir().getAbsolutePath(),
+ getTickTime(),
+ serverCnxnFactory.getMaxClientCnxnsPerHost(),
+ getMinSessionTimeout(),
+ getMaxSessionTimeout(),
+ getServerId());
+ }
+
/**
* This constructor is for backward compatibility with the existing unit
* test code.
@@ -795,6 +810,10 @@ public class ZooKeeperServer implements
zkDb.dumpEphemerals(pwriter);
}
+ public Map<Long, Set<String>> getEphemerals() {
+ return zkDb.getEphemerals();
+ }
+
public void processConnectRequest(ServerCnxn cnxn, ByteBuffer incomingBuffer) throws IOException {
BinaryInputArchive bia = BinaryInputArchive.getArchive(new ByteBufferInputStream(incomingBuffer));
ConnectRequest connReq = new ConnectRequest();
@@ -1022,4 +1041,8 @@ public class ZooKeeperServer implements
return rc;
}
+ public Map<Long, Set<Long>> getSessionExpiryMap() {
+ return sessionTracker.getSessionExpiryMap();
+ }
+
}
Added: zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerConf.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerConf.java?rev=1611516&view=auto
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerConf.java (added)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerConf.java Fri Jul 18 00:19:01 2014
@@ -0,0 +1,189 @@
+/*
+ * 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.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ * Configuration data for a {@link ZooKeeperServer}. This class is immutable.
+ */
+public class ZooKeeperServerConf {
+ /**
+ * The key in the map returned by {@link #toMap()} for the client port.
+ */
+ public static final String KEY_CLIENT_PORT = "client_port";
+ /**
+ * The key in the map returned by {@link #toMap()} for the data directory.
+ */
+ public static final String KEY_DATA_DIR = "data_dir";
+ /**
+ * The key in the map returned by {@link #toMap()} for the data log
+ * directory.
+ */
+ public static final String KEY_DATA_LOG_DIR = "data_log_dir";
+ /**
+ * The key in the map returned by {@link #toMap()} for the tick time.
+ */
+ public static final String KEY_TICK_TIME = "tick_time";
+ /**
+ * The key in the map returned by {@link #toMap()} for the maximum
+ * client connections per host.
+ */
+ public static final String KEY_MAX_CLIENT_CNXNS = "max_client_cnxns";
+ /**
+ * The key in the map returned by {@link #toMap()} for the minimum session
+ * timeout.
+ */
+ public static final String KEY_MIN_SESSION_TIMEOUT = "min_session_timeout";
+ /**
+ * The key in the map returned by {@link #toMap()} for the maximum session
+ * timeout.
+ */
+ public static final String KEY_MAX_SESSION_TIMEOUT = "max_session_timeout";
+ /**
+ * The key in the map returned by {@link #toMap()} for the server ID.
+ */
+ public static final String KEY_SERVER_ID = "server_id";
+
+ private final int clientPort;
+ private final String dataDir;
+ private final String dataLogDir;
+ private final int tickTime;
+ private final int maxClientCnxnsPerHost;
+ private final int minSessionTimeout;
+ private final int maxSessionTimeout;
+ private final long serverId;
+
+ /**
+ * Creates a new configuration.
+ *
+ * @param clientPort client port
+ * @param dataDir absolute path to data directory
+ * @param dataLogDir absolute path to data log directory
+ * @param tickTime tick time
+ * @param maxClientCnxnsPerHost maximum number of client connections
+ * @param minSessionTimeout minimum session timeout
+ * @param maxSessionTimeout maximum session timeout
+ * @param serverId server ID
+ */
+ ZooKeeperServerConf(int clientPort, String dataDir, String dataLogDir,
+ int tickTime, int maxClientCnxnsPerHost,
+ int minSessionTimeout, int maxSessionTimeout,
+ long serverId) {
+ this.clientPort = clientPort;
+ this.dataDir = dataDir;
+ this.dataLogDir = dataLogDir;
+ this.tickTime = tickTime;
+ this.maxClientCnxnsPerHost = maxClientCnxnsPerHost;
+ this.minSessionTimeout = minSessionTimeout;
+ this.maxSessionTimeout = maxSessionTimeout;
+ this.serverId = serverId;
+ }
+
+ /**
+ * Gets the client port.
+ *
+ * @return client port
+ */
+ public int getClientPort() {
+ return clientPort;
+ }
+
+ /**
+ * Gets the data directory.
+ *
+ * @return data directory
+ */
+ public String getDataDir() {
+ return dataDir;
+ }
+
+ /**
+ * Gets the data log directory.
+ *
+ * @return data log directory
+ */
+ public String getDataLogDir() {
+ return dataLogDir;
+ }
+
+ /**
+ * Gets the tick time.
+ *
+ * @return tick time
+ */
+ public int getTickTime() {
+ return tickTime;
+ }
+
+ /**
+ * Gets the maximum client connections per host.
+ *
+ * @return maximum client connections per host
+ */
+ public int getMaxClientCnxnsPerHost() {
+ return maxClientCnxnsPerHost;
+ }
+
+ /**
+ * Gets the minimum session timeout.
+ *
+ * @return minimum session timeout
+ */
+ public int getMinSessionTimeout() {
+ return minSessionTimeout;
+ }
+
+ /**
+ * Gets the maximum session timeout.
+ *
+ * @return maximum session timeout
+ */
+ public int getMaxSessionTimeout() {
+ return maxSessionTimeout;
+ }
+
+ /**
+ * Gets the server ID.
+ *
+ * @return server ID
+ */
+ public long getServerId() {
+ return serverId;
+ }
+
+ /**
+ * Converts this configuration to a map. The returned map is mutable, and
+ * changes to it do not reflect back into this configuration.
+ *
+ * @return map representation of configuration
+ */
+ public Map<String, Object> toMap() {
+ Map<String, Object> conf = new LinkedHashMap<String, Object>();
+ conf.put(KEY_CLIENT_PORT, clientPort);
+ conf.put(KEY_DATA_DIR, dataDir);
+ conf.put(KEY_DATA_LOG_DIR, dataLogDir);
+ conf.put(KEY_TICK_TIME, tickTime);
+ conf.put(KEY_MAX_CLIENT_CNXNS, maxClientCnxnsPerHost);
+ conf.put(KEY_MIN_SESSION_TIMEOUT, minSessionTimeout);
+ conf.put(KEY_MAX_SESSION_TIMEOUT, maxSessionTimeout);
+ conf.put(KEY_SERVER_ID, serverId);
+ return conf;
+ }
+}
Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMain.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMain.java?rev=1611516&r1=1611515&r2=1611516&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMain.java (original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMain.java Fri Jul 18 00:19:01 2014
@@ -23,6 +23,9 @@ import java.io.IOException;
import javax.management.JMException;
import org.apache.zookeeper.jmx.ManagedUtil;
+import org.apache.zookeeper.server.admin.AdminServer;
+import org.apache.zookeeper.server.admin.AdminServer.AdminServerException;
+import org.apache.zookeeper.server.admin.AdminServerFactory;
import org.apache.zookeeper.server.persistence.FileTxnSnapLog;
import org.apache.zookeeper.server.persistence.FileTxnSnapLog.DatadirException;
import org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException;
@@ -41,6 +44,8 @@ public class ZooKeeperServerMain {
private ServerCnxnFactory cnxnFactory;
+ private AdminServer adminServer;
+
/*
* Start up the ZooKeeper server.
*
@@ -63,6 +68,10 @@ public class ZooKeeperServerMain {
LOG.error("Unable to access datadir, exiting abnormally", e);
System.err.println("Unable to access datadir, exiting abnormally");
System.exit(3);
+ } catch (AdminServerException e) {
+ LOG.error("Unable to start AdminServer, exiting abnormally", e);
+ System.err.println("Unable to start AdminServer, exiting abnormally");
+ System.exit(4);
} catch (Exception e) {
LOG.error("Unexpected exception, exiting abnormally", e);
System.exit(1);
@@ -72,7 +81,7 @@ public class ZooKeeperServerMain {
}
protected void initializeAndRun(String[] args)
- throws ConfigException, IOException
+ throws ConfigException, IOException, AdminServerException
{
try {
ManagedUtil.registerLog4jMBeans();
@@ -94,8 +103,9 @@ public class ZooKeeperServerMain {
* Run from a ServerConfig.
* @param config ServerConfig to use.
* @throws IOException
+ * @throws AdminServerException
*/
- public void runFromConfig(ServerConfig config) throws IOException {
+ public void runFromConfig(ServerConfig config) throws IOException, AdminServerException {
LOG.info("Starting server");
FileTxnSnapLog txnLog = null;
try {
@@ -107,6 +117,11 @@ public class ZooKeeperServerMain {
ZooKeeperServer zkServer = new ZooKeeperServer( txnLog,
config.tickTime, config.minSessionTimeout, config.maxSessionTimeout, null);
+ // Start Admin server
+ adminServer = AdminServerFactory.createAdminServer();
+ adminServer.setZooKeeperServer(zkServer);
+ adminServer.start();
+
cnxnFactory = ServerCnxnFactory.createFactory();
cnxnFactory.configure(config.getClientPortAddress(),
config.getMaxClientCnxns());
@@ -130,5 +145,10 @@ public class ZooKeeperServerMain {
*/
protected void shutdown() {
cnxnFactory.shutdown();
+ try {
+ adminServer.shutdown();
+ } catch (AdminServerException e) {
+ LOG.warn("Problem stopping AdminServer", e);
+ }
}
}
Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooTrace.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooTrace.java?rev=1611516&r1=1611515&r2=1611516&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooTrace.java (original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooTrace.java Fri Jul 18 00:19:01 2014
@@ -52,17 +52,17 @@ public class ZooTrace {
| SERVER_PACKET_TRACE_MASK | SESSION_TRACE_MASK
| WARNING_TRACE_MASK;
- public static long getTextTraceLevel() {
+ public static synchronized long getTextTraceLevel() {
return traceMask;
}
- public static void setTextTraceLevel(long mask) {
+ public static synchronized void setTextTraceLevel(long mask) {
traceMask = mask;
final Logger LOG = LoggerFactory.getLogger(ZooTrace.class);
LOG.info("Set text trace mask to 0x" + Long.toHexString(mask));
}
- public static boolean isTraceEnabled(Logger log, long mask) {
+ public static synchronized boolean isTraceEnabled(Logger log, long mask) {
return log.isTraceEnabled() && (mask & traceMask) != 0;
}
Added: zookeeper/trunk/src/java/main/org/apache/zookeeper/server/admin/AdminServer.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/admin/AdminServer.java?rev=1611516&view=auto
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/server/admin/AdminServer.java (added)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/server/admin/AdminServer.java Fri Jul 18 00:19:01 2014
@@ -0,0 +1,41 @@
+/**
+ * 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.admin;
+
+import org.apache.zookeeper.server.ZooKeeperServer;
+
+/**
+ * Interface for an embedded admin server that runs Commands. There is only one
+ * functional implementation, JettyAdminServer. DummyAdminServer, which does
+ * nothing, is used when we do not wish to run a server.
+ */
+public interface AdminServer {
+ public void start() throws AdminServerException;
+ public void shutdown() throws AdminServerException;
+ public void setZooKeeperServer(ZooKeeperServer zkServer);
+
+ public class AdminServerException extends Exception {
+ public AdminServerException(String message, Throwable cause) {
+ super(message, cause);
+ }
+ public AdminServerException(Throwable cause) {
+ super(cause);
+ }
+ }
+}