Class: ZeevexCluster::Strategy::Static

Inherits:
Base
  • Object
show all
Defined in:
lib/zeevex_cluster/strategy/static.rb

Direct Known Subclasses

Unclustered

Instance Method Summary collapse

Methods inherited from Base

#has_master?, #member?, #online?, #started?, #state, #stopped?

Methods included from Util::Logging

#logger

Constructor Details

#initialize(options = {}) ⇒ Static

Returns a new instance of Static.



5
6
7
8
9
# File 'lib/zeevex_cluster/strategy/static.rb', line 5

def initialize(options = {})
  super
  @master_nodename = options[:master_nodename] || raise(ArgumentError, 'Must specify :master_nodename')
  @members = options[:members]
end

Instance Method Details

#am_i_master?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/zeevex_cluster/strategy/static.rb', line 30

def am_i_master?
  @state == :started && @my_cluster_status == :master
end

#can_view?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/zeevex_cluster/strategy/static.rb', line 58

def can_view?
  true
end

#master_nodeObject

FIXME: this is CAS-specific



35
36
37
# File 'lib/zeevex_cluster/strategy/static.rb', line 35

def master_node
  {:nodename => @master_nodename}
end

#membersObject



39
40
41
# File 'lib/zeevex_cluster/strategy/static.rb', line 39

def members
  @members || [@master_nodename, @nodename].select {|x| x != "none" }.uniq
end

#observeObject



62
63
64
# File 'lib/zeevex_cluster/strategy/static.rb', line 62

def observe
  true
end

#observing?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/zeevex_cluster/strategy/static.rb', line 54

def observing?
  true
end

#resign(delay = nil) ⇒ Object



43
44
45
46
47
# File 'lib/zeevex_cluster/strategy/static.rb', line 43

def resign(delay = nil)
  # master is currently fixed, so we can't resign
  logger.warn 'Current master cannot resign in this implementation.'
  false
end

#startObject



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/zeevex_cluster/strategy/static.rb', line 11

def start
  @state  = :started
  change_cluster_status :online
  if @nodename == @master_nodename
    change_my_status :master
    change_master_status :good
  else
    change_my_status :member
    change_master_status :unknown
  end
end

#steal_election!Object



49
50
51
52
# File 'lib/zeevex_cluster/strategy/static.rb', line 49

def steal_election!
  raise ClusterActionFailed, 'Can not change master' unless am_i_master?
  true
end

#stopObject



23
24
25
26
27
28
# File 'lib/zeevex_cluster/strategy/static.rb', line 23

def stop
  @state = :stopped
  change_my_status :nonmember
  change_master_status :unknown
  change_cluster_status :offline
end