Class: ZeevexCluster::Strategy::Zookeeper
- Inherits:
-
Base
- Object
- Base
- ZeevexCluster::Strategy::Zookeeper
show all
- Defined in:
- lib/zeevex_cluster/strategy/zookeeper.rb
Instance Method Summary
collapse
Methods inherited from Base
#am_i_master?, #has_master?, #member?, #online?, #started?, #state, #stopped?
#logger
Constructor Details
#initialize(options = {}) ⇒ Zookeeper
Returns a new instance of Zookeeper.
8
9
10
11
|
# File 'lib/zeevex_cluster/strategy/zookeeper.rb', line 8
def initialize(options = {})
super
ZK.logger = logger
end
|
Instance Method Details
#cluster_key ⇒ Object
66
67
68
|
# File 'lib/zeevex_cluster/strategy/zookeeper.rb', line 66
def cluster_key
[@namespace, @cluster_name].reject {|x| x.nil? || x.empty? }.join(':')
end
|
#data_for_grouper_members(*members) ⇒ Object
50
51
52
53
54
55
|
# File 'lib/zeevex_cluster/strategy/zookeeper.rb', line 50
def data_for_grouper_members(*members)
root = @grouper.path
Array(members).flatten.map do |name|
@zk.get(root + '/' + name)[0]
end
end
|
#master_node ⇒ Object
def am_i_master?
@state == :started && @elector.leader?
end
33
34
35
|
# File 'lib/zeevex_cluster/strategy/zookeeper.rb', line 33
def master_node
@state == :started && {:nodename => @elector.leader_data}
end
|
#members ⇒ Object
46
47
48
|
# File 'lib/zeevex_cluster/strategy/zookeeper.rb', line 46
def members
@state == :started && @members
end
|
#members_via_election ⇒ Object
37
38
39
40
41
42
43
44
|
# File 'lib/zeevex_cluster/strategy/zookeeper.rb', line 37
def members_via_election
return unless @state == :started
root = @elector.root_vote_path
@zk.children(root).select {|f| f.start_with? "ballot" }.map do |name|
@zk.get(root + '/' + name)[0]
end
end
|
#resign(delay = nil) ⇒ Object
57
58
59
|
# File 'lib/zeevex_cluster/strategy/zookeeper.rb', line 57
def resign(delay = nil)
return false
end
|
#start ⇒ Object
13
14
15
16
17
|
# File 'lib/zeevex_cluster/strategy/zookeeper.rb', line 13
def start
return true if @state == :started
setup
@state = :started
end
|
#steal_election! ⇒ Object
61
62
63
64
|
# File 'lib/zeevex_cluster/strategy/zookeeper.rb', line 61
def steal_election!
raise ClusterActionFailed, 'Can not change master' unless am_i_master?
true
end
|
#stop ⇒ Object
19
20
21
22
23
24
25
26
27
|
# File 'lib/zeevex_cluster/strategy/zookeeper.rb', line 19
def stop
return true unless @state == :started
@elector.close
@grouper.close
@zk.close
exited_cluster
@state = :stopped
true
end
|