zk 0.6.4 → 0.6.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +1 -1
- data/LICENSE +19 -0
- data/lib/z_k/client.rb +16 -12
- data/lib/z_k/find.rb +28 -0
- data/lib/z_k/version.rb +1 -1
- data/lib/z_k.rb +17 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/threadpool_spec.rb +1 -1
- data/zk.gemspec +1 -1
- metadata +9 -7
data/Gemfile
CHANGED
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (C) 2011 by Hewlett Packard Development Company, L.P.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/lib/z_k/client.rb
CHANGED
@@ -269,7 +269,7 @@ module ZK
|
|
269
269
|
end
|
270
270
|
end
|
271
271
|
|
272
|
-
rv = check_rc(@cnx.create(h))
|
272
|
+
rv = check_rc(@cnx.create(h), h)
|
273
273
|
|
274
274
|
h[:callback] ? rv : rv[:path]
|
275
275
|
end
|
@@ -323,7 +323,7 @@ module ZK
|
|
323
323
|
|
324
324
|
setup_watcher!(:data, h)
|
325
325
|
|
326
|
-
rv = check_rc(@cnx.get(h))
|
326
|
+
rv = check_rc(@cnx.get(h), h)
|
327
327
|
|
328
328
|
opts[:callback] ? rv : rv.values_at(:data, :stat)
|
329
329
|
end
|
@@ -372,7 +372,7 @@ module ZK
|
|
372
372
|
def set(path, data, opts={})
|
373
373
|
h = { :path => path, :data => data }.merge(opts)
|
374
374
|
|
375
|
-
rv = check_rc(@cnx.set(h))
|
375
|
+
rv = check_rc(@cnx.set(h), h)
|
376
376
|
|
377
377
|
opts[:callback] ? nil : rv[:stat]
|
378
378
|
end
|
@@ -436,7 +436,7 @@ module ZK
|
|
436
436
|
when Zookeeper::ZOK, Zookeeper::ZNONODE
|
437
437
|
rv[:stat]
|
438
438
|
else
|
439
|
-
check_rc(rv) # throws the appropriate error
|
439
|
+
check_rc(rv, h) # throws the appropriate error
|
440
440
|
end
|
441
441
|
end
|
442
442
|
|
@@ -514,7 +514,7 @@ module ZK
|
|
514
514
|
#++
|
515
515
|
def delete(path, opts={})
|
516
516
|
h = { :path => path, :version => -1 }.merge(opts)
|
517
|
-
rv = check_rc(@cnx.delete(h))
|
517
|
+
rv = check_rc(@cnx.delete(h), h)
|
518
518
|
nil
|
519
519
|
end
|
520
520
|
|
@@ -571,7 +571,7 @@ module ZK
|
|
571
571
|
|
572
572
|
setup_watcher!(:child, h)
|
573
573
|
|
574
|
-
rv = check_rc(@cnx.get_children(h))
|
574
|
+
rv = check_rc(@cnx.get_children(h), h)
|
575
575
|
opts[:callback] ? nil : rv[:children]
|
576
576
|
end
|
577
577
|
|
@@ -615,7 +615,7 @@ module ZK
|
|
615
615
|
#++
|
616
616
|
def get_acl(path, opts={})
|
617
617
|
h = { :path => path }.merge(opts)
|
618
|
-
rv = check_rc(@cnx.get_acl(h))
|
618
|
+
rv = check_rc(@cnx.get_acl(h), h)
|
619
619
|
opts[:callback] ? nil : rv.values_at(:children, :stat)
|
620
620
|
end
|
621
621
|
|
@@ -645,12 +645,10 @@ module ZK
|
|
645
645
|
#
|
646
646
|
def set_acl(path, acls, opts={})
|
647
647
|
h = { :path => path, :acl => acls }.merge(opts)
|
648
|
-
rv = check_rc(@cnx.set_acl(h))
|
648
|
+
rv = check_rc(@cnx.set_acl(h), h)
|
649
649
|
opts[:callback] ? nil : rv[:stat]
|
650
650
|
end
|
651
651
|
|
652
|
-
|
653
|
-
|
654
652
|
#--
|
655
653
|
#
|
656
654
|
# EXTENSIONS
|
@@ -705,6 +703,11 @@ module ZK
|
|
705
703
|
end
|
706
704
|
end
|
707
705
|
|
706
|
+
# see ZK::Find for explanation
|
707
|
+
def find(*paths, &block)
|
708
|
+
ZK::Find.find(self, *paths, &block)
|
709
|
+
end
|
710
|
+
|
708
711
|
# will block the caller until +abs_node_path+ has been removed
|
709
712
|
#
|
710
713
|
# NOTE: this is dangerous to use in callbacks! there is only one
|
@@ -890,10 +893,11 @@ module ZK
|
|
890
893
|
false
|
891
894
|
end
|
892
895
|
|
893
|
-
def check_rc(hash)
|
896
|
+
def check_rc(hash, inputs=nil)
|
894
897
|
hash.tap do |h|
|
895
898
|
if code = h[:rc]
|
896
|
-
|
899
|
+
msg = inputs ? "inputs: #{inputs.inspect}" : nil
|
900
|
+
raise Exceptions::KeeperException.by_code(code), msg unless code == Zookeeper::ZOK
|
897
901
|
end
|
898
902
|
end
|
899
903
|
end
|
data/lib/z_k/find.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
module ZK
|
2
|
+
module Find
|
3
|
+
# like ruby's Find module, will call the given block with each _absolute_ znode path
|
4
|
+
# under +paths+. you can call ZK::Find.prune if you want to not recurse
|
5
|
+
# deeper under the current directory path.
|
6
|
+
def find(zk, *paths) #:yield: znode_path
|
7
|
+
paths.collect!{|d| d.dup}
|
8
|
+
|
9
|
+
while p = paths.shift
|
10
|
+
catch(:prune) do
|
11
|
+
yield p.dup.taint
|
12
|
+
next unless zk.exists?(p)
|
13
|
+
|
14
|
+
zk.children(p).each do |ch|
|
15
|
+
paths.unshift ZK.join(p, ch).untaint
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def prune
|
22
|
+
throw :prune
|
23
|
+
end
|
24
|
+
|
25
|
+
module_function :find, :prune
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
data/lib/z_k/version.rb
CHANGED
data/lib/z_k.rb
CHANGED
@@ -21,6 +21,7 @@ require 'z_k/election'
|
|
21
21
|
require 'z_k/mongoid'
|
22
22
|
require 'z_k/client'
|
23
23
|
require 'z_k/pool'
|
24
|
+
require 'z_k/find'
|
24
25
|
|
25
26
|
module ZK
|
26
27
|
ZK_ROOT = File.expand_path('../..', __FILE__)
|
@@ -69,5 +70,21 @@ module ZK
|
|
69
70
|
def self.new_pool(host, opts={})
|
70
71
|
ZK::Pool::Bounded.new(host, opts)
|
71
72
|
end
|
73
|
+
|
74
|
+
# Eventually this will implement proper File.join-like behavior, but only
|
75
|
+
# using the '/' char for a separator. for right now, this simply delegates to
|
76
|
+
# File.join
|
77
|
+
#--
|
78
|
+
# like File.join but ignores $INPUT_RECORD_SEPARATOR (i.e. $/, which is
|
79
|
+
# platform dependent) and only uses the '/' character
|
80
|
+
def self.join(*paths)
|
81
|
+
File.join(*paths)
|
82
|
+
end
|
83
|
+
|
84
|
+
protected
|
85
|
+
def self.chomp_sep(str)
|
86
|
+
p = (p[0] == ?/ ) ? p[1..-1] : p
|
87
|
+
p = (p[-1] == ?/) ? p[0..-2] : p
|
88
|
+
end
|
72
89
|
end
|
73
90
|
|
data/spec/spec_helper.rb
CHANGED
data/spec/threadpool_spec.rb
CHANGED
@@ -33,7 +33,7 @@ describe ZK::Threadpool do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
it %[should barf if the argument is not callable] do
|
36
|
-
bad_obj =
|
36
|
+
bad_obj = flexmock(:not_callable)
|
37
37
|
bad_obj.should_not respond_to(:call)
|
38
38
|
|
39
39
|
lambda { @threadpool.defer(bad_obj) }.should raise_error(ArgumentError)
|
data/zk.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.summary = %q{A high-level wrapper around the zookeeper driver}
|
13
13
|
s.description = s.summary
|
14
14
|
|
15
|
-
s.add_runtime_dependency 'slyphon-zookeeper', '~> 0.1.
|
15
|
+
s.add_runtime_dependency 'slyphon-zookeeper', '~> 0.1.7'
|
16
16
|
s.add_development_dependency 'rspec', '~> 2.4.0'
|
17
17
|
s.add_development_dependency 'wirble'
|
18
18
|
s.add_development_dependency 'flexmock', '~> 0.8.10'
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 13
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 6
|
9
|
-
-
|
10
|
-
version: 0.6.
|
9
|
+
- 5
|
10
|
+
version: 0.6.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jonathan D. Simms
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-05-
|
19
|
+
date: 2011-05-24 00:00:00 +00:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -27,12 +27,12 @@ dependencies:
|
|
27
27
|
requirements:
|
28
28
|
- - ~>
|
29
29
|
- !ruby/object:Gem::Version
|
30
|
-
hash:
|
30
|
+
hash: 21
|
31
31
|
segments:
|
32
32
|
- 0
|
33
33
|
- 1
|
34
|
-
-
|
35
|
-
version: 0.1.
|
34
|
+
- 7
|
35
|
+
version: 0.1.7
|
36
36
|
type: :runtime
|
37
37
|
version_requirements: *id001
|
38
38
|
- !ruby/object:Gem::Dependency
|
@@ -94,6 +94,7 @@ extra_rdoc_files: []
|
|
94
94
|
files:
|
95
95
|
- .gitignore
|
96
96
|
- Gemfile
|
97
|
+
- LICENSE
|
97
98
|
- Rakefile
|
98
99
|
- lib/z_k.rb
|
99
100
|
- lib/z_k/client.rb
|
@@ -102,6 +103,7 @@ files:
|
|
102
103
|
- lib/z_k/event_handler_subscription.rb
|
103
104
|
- lib/z_k/exceptions.rb
|
104
105
|
- lib/z_k/extensions.rb
|
106
|
+
- lib/z_k/find.rb
|
105
107
|
- lib/z_k/locker.rb
|
106
108
|
- lib/z_k/logging.rb
|
107
109
|
- lib/z_k/message_queue.rb
|