From dcbbab576511cea2cbac6b7f8f40dfa6492fa6ca Mon Sep 17 00:00:00 2001 From: Mao Geng Date: Tue, 12 May 2015 13:55:33 -0700 Subject: [PATCH 1/2] Use base64 encoding to support dump and import binary data --- usr/share/zookeeper-util/bin/zk_import.rb | 2 +- usr/share/zookeeper-util/bin/zookeeper.rb | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/usr/share/zookeeper-util/bin/zk_import.rb b/usr/share/zookeeper-util/bin/zk_import.rb index fc67aee..64427c8 100644 --- a/usr/share/zookeeper-util/bin/zk_import.rb +++ b/usr/share/zookeeper-util/bin/zk_import.rb @@ -71,7 +71,7 @@ zk.create_path(a[0].chomp) elsif(a.size == 2) puts "# Writing data '#{a[1]}' to Path #{a[0]}" if options[:verbose] - zk.set_data(a[0].chomp, a[1].chomp) + zk.set_data(a[0].chomp, javax.xml.bind.DatatypeConverter.parseBase64Binary(a[1])) else puts "#{line} is broken" end diff --git a/usr/share/zookeeper-util/bin/zookeeper.rb b/usr/share/zookeeper-util/bin/zookeeper.rb index af9f5af..b933fd1 100644 --- a/usr/share/zookeeper-util/bin/zookeeper.rb +++ b/usr/share/zookeeper-util/bin/zookeeper.rb @@ -87,10 +87,13 @@ def dump(path, separator=DEFAULT_SEPARATOR) next if path.eql?('/') && node.eql?('zookeeper') stat = Stat.new new_path = File.join(path, node) - d = @zk.get_data(new_path, false, stat) || ''.to_java_bytes - node_data = "#{String.from_java_bytes(d)}" - puts node_data.to_s.empty? ? "#{new_path}" : "#{new_path}#{separator}#{node_data}" - + d = @zk.get_data(new_path, false, stat) + if d == nil or d.length == 0 + puts "#{new_path}" + else + node_data = "#{javax.xml.bind.DatatypeConverter.printBase64Binary(d)}" + puts "#{new_path}#{separator}#{node_data}" + end dump(new_path, separator) unless (stat.getNumChildren == 0) end end From 5aa9e2644e6025531259b00be874bc631af050fd Mon Sep 17 00:00:00 2001 From: Mao Geng Date: Wed, 4 Nov 2015 14:18:14 -0800 Subject: [PATCH 2/2] Add a dockerfile --- Dockerfile | 9 +++++++++ README.textile | 28 ++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..000e9ad --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM java:openjdk-8 + +COPY usr /usr + +ADD https://s3.amazonaws.com/jruby.org/downloads/1.7.22/jruby-complete-1.7.22.jar /usr/share/java/zookeeper-util/ + +ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64 + +ENTRYPOINT ["/usr/bin/zkutil"] diff --git a/README.textile b/README.textile index 7f49f97..3dcd324 100644 --- a/README.textile +++ b/README.textile @@ -60,3 +60,31 @@ Usage: zk_purge.rb [options] -c -v, --verbose Output more information -h, --help Display this screen +h5. Docker + +A Dockerfile is added to easy package and use this tool. You can checkout this repo and build a docker image like this: + +bc. $ docker build -t gengmao/zookeeper-util . +Sending build context to Docker daemon 17.85 MB +Step 0 : FROM java:openjdk-8 + ---> c1ccce98b537 +Step 1 : COPY usr /usr + ---> Using cache + ---> ce7c545aa779 +Step 2 : ADD https://s3.amazonaws.com/jruby.org/downloads/1.7.22/jruby-complete-1.7.22.jar /usr/share/java/zookeeper-util/ +Downloading [==================================================>] 23.72 MB/23.72 MB + ---> Using cache + ---> c2e854f67dc7 +Step 3 : ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64 + ---> Using cache + ---> 0e4583859950 +Step 4 : ENTRYPOINT /usr/bin/zkutil + ---> Using cache + ---> da8f8a8c682d +Successfully built da8f8a8c682d + +Then you can use the image like this: + +bc. $ docker run -it gengmao/zookeeper-util +Usage: zkutil -c host:port [options] +