zookeeper 0.9.4-java → 1.0.0.beta.1-java
Sign up to get free protection for your applications and to get access to all the features.
- data/.dotfiles/rvmrc +1 -0
- data/.gitignore +3 -0
- data/.gitmodules +3 -0
- data/.travis.yml +22 -0
- data/CHANGELOG +38 -5
- data/Gemfile +18 -1
- data/README.markdown +2 -0
- data/Rakefile +47 -109
- data/ext/c_zookeeper.rb +10 -6
- data/ext/zookeeper_base.rb +23 -11
- data/ext/zookeeper_c.c +14 -10
- data/java/{zookeeper_base.rb → java_base.rb} +13 -12
- data/lib/zookeeper/acls.rb +17 -13
- data/lib/zookeeper/callbacks.rb +28 -11
- data/lib/zookeeper/client.rb +30 -0
- data/lib/zookeeper/client_methods.rb +241 -0
- data/lib/zookeeper/common/queue_with_pipe.rb +3 -7
- data/lib/zookeeper/common.rb +13 -12
- data/lib/zookeeper/compatibility.rb +135 -0
- data/lib/zookeeper/constants.rb +35 -1
- data/lib/zookeeper/em_client.rb +1 -1
- data/lib/zookeeper/exceptions.rb +117 -93
- data/lib/zookeeper/rake_tasks.rb +165 -0
- data/lib/zookeeper/stat.rb +16 -16
- data/lib/zookeeper/version.rb +2 -4
- data/lib/zookeeper.rb +32 -244
- data/scripts/upgrade-1.0-sed-alike.rb +46 -0
- data/spec/c_zookeeper_spec.rb +10 -9
- data/spec/chrooted_connection_spec.rb +2 -2
- data/spec/default_watcher_spec.rb +4 -4
- data/spec/em_spec.rb +1 -1
- data/spec/shared/connection_examples.rb +52 -37
- data/spec/spec_helper.rb +22 -84
- data/spec/support/00_spawn_zookeeper.rb +20 -0
- data/spec/support/zookeeper_spec_helpers.rb +84 -0
- data/spec/zookeeper_spec.rb +1 -1
- data/zookeeper.gemspec +9 -12
- metadata +50 -36
- data/examples/cloud_config.rb +0 -125
- data/test/test_basic.rb +0 -37
- data/test/test_callback1.rb +0 -36
- data/test/test_close.rb +0 -16
- data/test/test_esoteric.rb +0 -7
- data/test/test_watcher1.rb +0 -56
- data/test/test_watcher2.rb +0 -52
data/lib/zookeeper/exceptions.rb
CHANGED
@@ -1,100 +1,124 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
ZSYSTEMERROR = -1
|
5
|
-
ZRUNTIMEINCONSISTENCY = -2
|
6
|
-
ZDATAINCONSISTENCY = -3
|
7
|
-
ZCONNECTIONLOSS = -4
|
8
|
-
ZMARSHALLINGERROR = -5
|
9
|
-
ZUNIMPLEMENTED = -6
|
10
|
-
ZOPERATIONTIMEOUT = -7
|
11
|
-
ZBADARGUMENTS = -8
|
12
|
-
ZINVALIDSTATE = -9
|
13
|
-
|
14
|
-
# api errors
|
15
|
-
ZAPIERROR = -100
|
16
|
-
ZNONODE = -101
|
17
|
-
ZNOAUTH = -102
|
18
|
-
ZBADVERSION = -103
|
19
|
-
ZNOCHILDRENFOREPHEMERALS = -108
|
20
|
-
ZNODEEXISTS = -110
|
21
|
-
ZNOTEMPTY = -111
|
22
|
-
ZSESSIONEXPIRED = -112
|
23
|
-
ZINVALIDCALLBACK = -113
|
24
|
-
ZINVALIDACL = -114
|
25
|
-
ZAUTHFAILED = -115
|
26
|
-
ZCLOSING = -116
|
27
|
-
ZNOTHING = -117
|
28
|
-
ZSESSIONMOVED = -118
|
1
|
+
module Zookeeper
|
2
|
+
module Exceptions
|
3
|
+
include Constants
|
29
4
|
|
30
5
|
class ZookeeperException < StandardError
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
when ZRUNTIMEINCONSISTENCY then RunTimeInconsistency
|
70
|
-
when ZDATAINCONSISTENCY then DataInconsistency
|
71
|
-
when ZCONNECTIONLOSS then ConnectionLoss
|
72
|
-
when ZMARSHALLINGERROR then MarshallingError
|
73
|
-
when ZUNIMPLEMENTED then Unimplemented
|
74
|
-
when ZOPERATIONTIMEOUT then OperationTimeOut
|
75
|
-
when ZBADARGUMENTS then BadArguments
|
76
|
-
when ZINVALIDSTATE then InvalidState
|
77
|
-
when ZAPIERROR then ApiError
|
78
|
-
when ZNONODE then NoNode
|
79
|
-
when ZNOAUTH then NoAuth
|
80
|
-
when ZBADVERSION then BadVersion
|
81
|
-
when ZNOCHILDRENFOREPHEMERALS then NoChildrenForEphemerals
|
82
|
-
when ZNODEEXISTS then NodeExists
|
83
|
-
when ZNOTEMPTY then NotEmpty
|
84
|
-
when ZSESSIONEXPIRED then SessionExpired
|
85
|
-
when ZINVALIDCALLBACK then InvalidCallback
|
86
|
-
when ZINVALIDACL then InvalidACL
|
87
|
-
when ZAUTHFAILED then AuthFailed
|
88
|
-
when ZCLOSING then Closing
|
89
|
-
when ZNOTHING then Nothing
|
90
|
-
when ZSESSIONMOVED then SessionMoved
|
91
|
-
else Exception.new("no exception defined for code #{code}")
|
6
|
+
|
7
|
+
unless defined?(CONST_MISSING_WARNING)
|
8
|
+
|
9
|
+
CONST_MISSING_WARNING = <<-EOS
|
10
|
+
|
11
|
+
------------------------------------------------------------------------------------------
|
12
|
+
WARNING! THE ZOOKEEPER NAMESPACE HAS CHNAGED AS OF 1.0!
|
13
|
+
|
14
|
+
Please update your code to use the new heirarchy!
|
15
|
+
|
16
|
+
The constant that got you this was ZookeeperExceptions::ZookeeperException::%s
|
17
|
+
|
18
|
+
stacktrace:
|
19
|
+
%s
|
20
|
+
|
21
|
+
------------------------------------------------------------------------------------------
|
22
|
+
|
23
|
+
EOS
|
24
|
+
end
|
25
|
+
|
26
|
+
# NOTE(slyphon): Since 0.4 all of the ZookeeperException subclasses were
|
27
|
+
# defined inside of ZookeeperException, which always seemed well, icky.
|
28
|
+
# if someone references one of these we'll print out a warning and
|
29
|
+
# then give them the constant
|
30
|
+
#
|
31
|
+
def self.const_missing(const)
|
32
|
+
if Zookeeper::Exceptions.const_defined?(const)
|
33
|
+
|
34
|
+
stacktrace = caller[0..-2].reject {|n| n =~ %r%/rspec/% }.map { |n| "\t#{n}" }.join("\n")
|
35
|
+
|
36
|
+
Zookeeper.deprecation_warning(CONST_MISSING_WARNING % [const.to_s, stacktrace])
|
37
|
+
|
38
|
+
|
39
|
+
Zookeeper::Exceptions.const_get(const).tap do |const_val|
|
40
|
+
self.const_set(const, const_val)
|
41
|
+
end
|
42
|
+
else
|
43
|
+
super
|
92
44
|
end
|
93
45
|
end
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
class EverythingOk < ZookeeperException; end
|
50
|
+
class SystemError < ZookeeperException; end
|
51
|
+
class RunTimeInconsistency < ZookeeperException; end
|
52
|
+
class DataInconsistency < ZookeeperException; end
|
53
|
+
class ConnectionLoss < ZookeeperException; end
|
54
|
+
class MarshallingError < ZookeeperException; end
|
55
|
+
class Unimplemented < ZookeeperException; end
|
56
|
+
class OperationTimeOut < ZookeeperException; end
|
57
|
+
class BadArguments < ZookeeperException; end
|
58
|
+
class InvalidState < ZookeeperException; end
|
59
|
+
class ApiError < ZookeeperException; end
|
60
|
+
class NoNode < ZookeeperException; end
|
61
|
+
class NoAuth < ZookeeperException; end
|
62
|
+
class BadVersion < ZookeeperException; end
|
63
|
+
class NoChildrenForEphemerals < ZookeeperException; end
|
64
|
+
class NodeExists < ZookeeperException; end
|
65
|
+
class NotEmpty < ZookeeperException; end
|
66
|
+
class SessionExpired < ZookeeperException; end
|
67
|
+
class InvalidCallback < ZookeeperException; end
|
68
|
+
class InvalidACL < ZookeeperException; end
|
69
|
+
class AuthFailed < ZookeeperException; end
|
70
|
+
class Closing < ZookeeperException; end
|
71
|
+
class Nothing < ZookeeperException; end
|
72
|
+
class SessionMoved < ZookeeperException; end
|
73
|
+
|
74
|
+
# these are Ruby client exceptions
|
75
|
+
class ConnectionClosed < ZookeeperException; end
|
76
|
+
class NotConnected < ZookeeperException; end
|
77
|
+
class ShuttingDownException < ZookeeperException; end
|
78
|
+
class DataTooLargeException < ZookeeperException; end
|
79
|
+
|
80
|
+
# raised when the user tries to use a connection after a fork()
|
81
|
+
# without calling reopen() in the C client
|
82
|
+
#
|
83
|
+
# (h/t: @pletern http://git.io/zIsq1Q)
|
84
|
+
class InheritedConnectionError < ZookeeperException; end
|
85
|
+
|
86
|
+
# yes, make an alias, this is the way zookeeper refers to it
|
87
|
+
ExpiredSession = SessionExpired unless defined?(ExpiredSession)
|
94
88
|
|
95
|
-
|
96
|
-
|
97
|
-
|
89
|
+
def self.by_code(code)
|
90
|
+
case code
|
91
|
+
when ZOK then EverythingOk
|
92
|
+
when ZSYSTEMERROR then SystemError
|
93
|
+
when ZRUNTIMEINCONSISTENCY then RunTimeInconsistency
|
94
|
+
when ZDATAINCONSISTENCY then DataInconsistency
|
95
|
+
when ZCONNECTIONLOSS then ConnectionLoss
|
96
|
+
when ZMARSHALLINGERROR then MarshallingError
|
97
|
+
when ZUNIMPLEMENTED then Unimplemented
|
98
|
+
when ZOPERATIONTIMEOUT then OperationTimeOut
|
99
|
+
when ZBADARGUMENTS then BadArguments
|
100
|
+
when ZINVALIDSTATE then InvalidState
|
101
|
+
when ZAPIERROR then ApiError
|
102
|
+
when ZNONODE then NoNode
|
103
|
+
when ZNOAUTH then NoAuth
|
104
|
+
when ZBADVERSION then BadVersion
|
105
|
+
when ZNOCHILDRENFOREPHEMERALS then NoChildrenForEphemerals
|
106
|
+
when ZNODEEXISTS then NodeExists
|
107
|
+
when ZNOTEMPTY then NotEmpty
|
108
|
+
when ZSESSIONEXPIRED then SessionExpired
|
109
|
+
when ZINVALIDCALLBACK then InvalidCallback
|
110
|
+
when ZINVALIDACL then InvalidACL
|
111
|
+
when ZAUTHFAILED then AuthFailed
|
112
|
+
when ZCLOSING then Closing
|
113
|
+
when ZNOTHING then Nothing
|
114
|
+
when ZSESSIONMOVED then SessionMoved
|
115
|
+
else ZookeeperException.new("no exception defined for code #{code}")
|
98
116
|
end
|
99
117
|
end
|
100
|
-
|
118
|
+
|
119
|
+
def self.raise_on_error(code)
|
120
|
+
exc = self.by_code(code)
|
121
|
+
raise exc unless exc == EverythingOk
|
122
|
+
end
|
123
|
+
end # Exceptions
|
124
|
+
end # Zookeeper
|
@@ -0,0 +1,165 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/tasklib'
|
3
|
+
|
4
|
+
module Zookeeper
|
5
|
+
# @private
|
6
|
+
module RakeTasks
|
7
|
+
def self.define_test_tasks_for(*rubies)
|
8
|
+
rubies.each do |r|
|
9
|
+
|
10
|
+
TestOneRuby.new(:name => r) do |tor|
|
11
|
+
yield tor if block_given?
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class TestOneRuby < ::Rake::TaskLib
|
17
|
+
include ::Rake::DSL if defined?(::Rake::DSL)
|
18
|
+
|
19
|
+
DEFAULT_RVM_RUBY_NAME = '1.9.3'
|
20
|
+
|
21
|
+
# defaults to 'zk', test tasks will be built under this
|
22
|
+
attr_accessor :namespace
|
23
|
+
|
24
|
+
# the name of the task
|
25
|
+
# (tasks will be 'zk:1.9.3:run_rspec')
|
26
|
+
#
|
27
|
+
# this is mainly here so that the rvm ruby name rbx-2.0.testing
|
28
|
+
# will have its tasks defined as 'zk:rbx'
|
29
|
+
attr_accessor :name
|
30
|
+
|
31
|
+
# what is the rvm name we should use for testing? (i.e. could be an alias)
|
32
|
+
# defaults to {#name}
|
33
|
+
attr_accessor :rvm_ruby_name
|
34
|
+
|
35
|
+
# any extra environment variables?
|
36
|
+
attr_accessor :env
|
37
|
+
|
38
|
+
# gemset name to use, deafults to the name of the gemspec in the top of the
|
39
|
+
# project directory (minus the .gempsec)
|
40
|
+
attr_accessor :gemset_name
|
41
|
+
|
42
|
+
# @private
|
43
|
+
attr_reader :ruby_with_gemset,
|
44
|
+
:create_gemset_name,
|
45
|
+
:clobber_task_name,
|
46
|
+
:clean_task_name,
|
47
|
+
:build_task_name,
|
48
|
+
:bundle_task_name,
|
49
|
+
:rspec_task_name,
|
50
|
+
:phony_gemfile_link_name,
|
51
|
+
:phony_gemfile_lock_name
|
52
|
+
|
53
|
+
|
54
|
+
def self.default_gemset_name
|
55
|
+
ary = Dir['*.gemspec']
|
56
|
+
raise 'No gemspec found' if ary.empty?
|
57
|
+
ary.first[/(.+)\.gemspec\Z/, 1]
|
58
|
+
end
|
59
|
+
|
60
|
+
def initialize(opts={})
|
61
|
+
@namespace = 'zk'
|
62
|
+
@name = nil
|
63
|
+
@env = {}
|
64
|
+
@rvm_ruby_name = nil
|
65
|
+
@gemset_name = nil
|
66
|
+
|
67
|
+
opts.each { |k,v| __send__(:"#{k}=", v) }
|
68
|
+
|
69
|
+
yield self if block_given?
|
70
|
+
|
71
|
+
@gemset_name ||= self.class.default_gemset_name
|
72
|
+
|
73
|
+
# XXX: add an exception just for me in here (yes, i know this is naughty)
|
74
|
+
# or else i'd have to do this in every zk variant i want to test
|
75
|
+
# (like i have to now)
|
76
|
+
|
77
|
+
unless @rvm_ruby_name
|
78
|
+
@rvm_ruby_name = 'rbx-2.0.testing' if @name == 'rbx'
|
79
|
+
end
|
80
|
+
|
81
|
+
@rvm_ruby_name ||= name
|
82
|
+
|
83
|
+
@ruby_with_gemset = "#{@rvm_ruby_name}@#{@gemset_name}"
|
84
|
+
@create_gemset_name = "#{namespace}:#{name}:create_gemset"
|
85
|
+
@clobber_task_name = "#{namespace}:#{name}:clobber"
|
86
|
+
@clean_task_name = "#{namespace}:#{name}:clean"
|
87
|
+
@build_task_name = "#{namespace}:#{name}:build"
|
88
|
+
@bundle_task_name = "#{namespace}:#{name}:bundle_install"
|
89
|
+
@rspec_task_name = "#{namespace}:#{name}:run_rspec"
|
90
|
+
@phony_gemfile_link_name = "Gemfile.#{name}"
|
91
|
+
@phony_gemfile_lock_name = "#{phony_gemfile_link_name}.lock"
|
92
|
+
|
93
|
+
define_tasks
|
94
|
+
end
|
95
|
+
|
96
|
+
private
|
97
|
+
def need_ext_build?
|
98
|
+
name != 'jruby' && File.directory?('./ext')
|
99
|
+
end
|
100
|
+
|
101
|
+
def define_tasks
|
102
|
+
file phony_gemfile_link_name do
|
103
|
+
# apparently, rake doesn't deal with symlinks intelligently :P
|
104
|
+
ln_s('Gemfile', phony_gemfile_link_name) unless File.symlink?(phony_gemfile_link_name)
|
105
|
+
end
|
106
|
+
|
107
|
+
task :clean do
|
108
|
+
rm_rf [phony_gemfile_lock_name, phony_gemfile_lock_name]
|
109
|
+
end
|
110
|
+
|
111
|
+
task create_gemset_name do
|
112
|
+
sh "rvm #{rvm_ruby_name} do rvm gemset create #{gemset_name}"
|
113
|
+
end
|
114
|
+
|
115
|
+
task clobber_task_name do
|
116
|
+
if need_ext_build?
|
117
|
+
cd 'ext' do
|
118
|
+
sh "rake clobber"
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
task clean_task_name do
|
124
|
+
if need_ext_build?
|
125
|
+
cd 'ext' do
|
126
|
+
sh "rake clean"
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
task build_task_name => [create_gemset_name, clean_task_name] do
|
132
|
+
if need_ext_build?
|
133
|
+
cd 'ext' do
|
134
|
+
sh "rvm #{ruby_with_gemset} do rake build"
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
task bundle_task_name => [phony_gemfile_link_name, build_task_name] do
|
140
|
+
sh "rvm #{ruby_with_gemset} do bundle install --gemfile #{phony_gemfile_link_name}"
|
141
|
+
end
|
142
|
+
|
143
|
+
task rspec_task_name => bundle_task_name do
|
144
|
+
sh "rvm #{ruby_with_gemset} do env BUNDLE_GEMFILE=#{phony_gemfile_link_name} bundle exec rspec spec --fail-fast"
|
145
|
+
end
|
146
|
+
|
147
|
+
task "#{namespace}:#{name}" => rspec_task_name
|
148
|
+
|
149
|
+
task "#{namespace}:test_all_rubies" => rspec_task_name
|
150
|
+
|
151
|
+
unless Rake::Task.task_defined?("#{namespace}:test_all")
|
152
|
+
task "#{namespace}:test_all" do
|
153
|
+
require 'benchmark'
|
154
|
+
t = Benchmark.realtime do
|
155
|
+
Rake::Task["#{namespace}:test_all_rubies"].invoke
|
156
|
+
end
|
157
|
+
|
158
|
+
$stderr.puts "Test run took: #{t} s"
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
data/lib/zookeeper/stat.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
1
|
+
module Zookeeper
|
2
|
+
class Stat
|
3
|
+
attr_reader :version, :exists, :czxid, :mzxid, :ctime, :mtime, :cversion, :aversion, :ephemeralOwner, :dataLength, :numChildren, :pzxid
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
alias :ephemeral_owner :ephemeralOwner
|
6
|
+
alias :num_children :numChildren
|
7
|
+
alias :data_length :dataLength
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
9
|
+
def initialize(val)
|
10
|
+
@exists = !!val
|
11
|
+
@czxid, @mzxid, @ctime, @mtime, @version, @cversion, @aversion,
|
12
|
+
@ephemeralOwner, @dataLength, @numChildren, @pzxid = val if val.is_a?(Array)
|
13
|
+
val.each { |k,v| instance_variable_set "@#{k}", v } if val.is_a?(Hash)
|
14
|
+
raise ArgumentError unless (val.is_a?(Hash) or val.is_a?(Array) or val.nil?)
|
15
|
+
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
end
|
17
|
+
def exists?
|
18
|
+
@exists
|
20
19
|
end
|
21
20
|
end
|
21
|
+
end
|
data/lib/zookeeper/version.rb
CHANGED