Class: ZeevexCluster::Strategy::Zookeeper

Inherits:
Base
  • Object
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?

Methods included from Util::Logging

#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

#can_view?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/zeevex_cluster/strategy/zookeeper.rb', line 79

def can_view?
  observing?
end

#cluster_keyObject



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_nodeObject

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

#membersObject



46
47
48
# File 'lib/zeevex_cluster/strategy/zookeeper.rb', line 46

def members
  @state == :started && @members
end

#members_via_electionObject



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

#observeObject

Raises:

  • (NotImplementedError)


70
71
72
73
# File 'lib/zeevex_cluster/strategy/zookeeper.rb', line 70

def observe
  return true if @state == :started
  raise NotImplementedError, "Can't observe zookeeper cluster yet"
end

#observing?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/zeevex_cluster/strategy/zookeeper.rb', line 75

def observing?
  @state == :started
end

#resign(delay = nil) ⇒ Object



57
58
59
# File 'lib/zeevex_cluster/strategy/zookeeper.rb', line 57

def resign(delay = nil)
  return false
end

#startObject



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

#stopObject



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