/ technology

ZooInspector on OS X

Apache ZooKeeper is a project that aims to provide reliable coordination for distributed systems. Data in ZooKeeper is stored hierarchically (similar to a filesystem) in data registers called znodes. Like a file system, browsing hierarchical data can be tedious if done via a command line interface. As much as it pains me to admit, a GUI may be more suitable if you're browsing a large or unknown hierarchy of data.

ZooInspector provides a GUI for browsing a ZooKeeper cluster. It is one of the contrib projects to Apache ZooKeeper. However, the distribution that comes with Homebrew (brew) does not work without some modification.

Prerequisite

First we need to install ZooKeeper using brew:

$ brew install zookeeper
==> Downloading http://www.apache.org/dyn/closer.cgi?path=zookeeper/zookeeper-3.4.5/zookeeper-3.4.5.tar.gz
/usr/local/Cellar/zookeeper/3.4.5: 193 files, 12M, built in 2 seconds

Getting ZooInspector working

There are a couple of steps we need to do in order to get ZooInspector running.

Fix the config

The default defaultNodeVeiwers.cfg (typo intentional) has an Apache license prepended to it. Because ZooInspector will actually read this config in order to do dependency injection (doh!), the comment lines will end up causing exceptions. Here's a one-liner to fix it:

$ sed -i '.bak' -n '/^#.*$/!p' "`dirname $(brew ls zookeeper | head -n1)`/../libexec/contrib/ZooInspector/config/defaultNodeVeiwers.cfg"

That one-liner will remove all comment lines from the config file in place. The file will be backed up as defaultNodeVeiwers.cfg.bak.

Create a script to launch ZooInspector

The distribution doesn't come with a binary for launching ZooInspector since it's a contrib project. Therefore, we'll need to create a script to easily launch ZooInspector.

Place the following script somewhere in your $PATH:

#!/bin/sh
ZOOVERSION=$(brew list zookeeper --versions | sed -E 's/.*([0-9]+\.[0-9]+\.[0-9]+).*/\1/' | head -n1)
ZOOBINDIR=`dirname $(brew ls zookeeper | head -n1)`
ZOOCONTRIBDIR="$ZOOBINDIR/../libexec/contrib"
ZOOFATJAR="$ZOOCONTRIBDIR/fatjar/zookeeper-$ZOOVERSION-fatjar.jar"
ZOOINSPECTORDIR="$ZOOCONTRIBDIR/ZooInspector"
ZOOINSPECTOR="$ZOOINSPECTORDIR/zookeeper-$ZOOVERSION-ZooInspector.jar"
 
. "$ZOOBINDIR"/../libexec/bin/zkEnv.sh
CLASSPATH="$ZOOFATJAR:$ZOOINSPECTOR:$CLASSPATH"
 
cd $ZOOINSPECTORDIR
$JAVA "-Dzookeeper.log.dir=${ZOO_LOG_DIR}" "-Dzookeeper.root.logger=${ZOO_LOG4J_PROP}" \
     -cp "$CLASSPATH" $CLIENT_JVMFLAGS $JVMFLAGS \
     org.apache.zookeeper.inspector.ZooInspector "$@"

All the script does is set up some environmental variables and sets up the JVM classpath.

What success looks like

Update

I updated the launch script to account for the deprecation of brew which. Thanks to Gary Ogden for pointing that out!