Class: Chef::Expander::VNodeTable
- Inherits:
-
Object
- Object
- Chef::Expander::VNodeTable
show all
- Includes:
- Loggable
- Defined in:
- lib/chef/expander/vnode_table.rb
Defined Under Namespace
Classes: InvalidVNodeTableUpdate
Constant Summary
Constants included
from Loggable
Loggable::LOGGER
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Loggable
#log
Constructor Details
#initialize(vnode_supervisor) ⇒ VNodeTable
Returns a new instance of VNodeTable.
35
36
37
38
39
|
# File 'lib/chef/expander/vnode_table.rb', line 35
def initialize(vnode_supervisor)
@node_update_mutex = Mutex.new
@vnode_supervisor = vnode_supervisor
@vnodes_by_node = {}
end
|
Instance Attribute Details
#vnodes_by_node ⇒ Object
Returns the value of attribute vnodes_by_node.
33
34
35
|
# File 'lib/chef/expander/vnode_table.rb', line 33
def vnodes_by_node
@vnodes_by_node
end
|
Instance Method Details
#leader_node ⇒ Object
69
70
71
72
73
74
75
|
# File 'lib/chef/expander/vnode_table.rb', line 69
def leader_node
if @vnodes_by_node.empty?
nil
else
Array(@vnodes_by_node).reject { |node| node[1].empty? }.sort { |a,b| a[1].min <=> b[1].min }.first[0]
end
end
|
#local_node_is_leader? ⇒ Boolean
77
78
79
|
# File 'lib/chef/expander/vnode_table.rb', line 77
def local_node_is_leader?
(Node.local_node == leader_node) || (@vnodes_by_node[Node.local_node].include?(0))
end
|
#nodes ⇒ Object
41
42
43
|
# File 'lib/chef/expander/vnode_table.rb', line 41
def nodes
@vnodes_by_node.keys
end
|
#remove_node(node_info) ⇒ Object
63
64
65
66
67
|
# File 'lib/chef/expander/vnode_table.rb', line 63
def remove_node(node_info)
@node_update_mutex.synchronize do
@vnodes_by_node.delete(Node.from_hash(node_info))
end
end
|
#update_node(node_info) ⇒ Object
57
58
59
60
61
|
# File 'lib/chef/expander/vnode_table.rb', line 57
def update_node(node_info)
@node_update_mutex.synchronize do
@vnodes_by_node[Node.from_hash(node_info)] = node_info[:vnodes]
end
end
|
#update_table(table_update) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/chef/expander/vnode_table.rb', line 45
def update_table(table_update)
case table_update[:update]
when "add", "update"
update_node(table_update)
when "remove"
remove_node(table_update)
else
raise InvalidVNodeTableUpdate, "no action or action not acceptable: #{table_update.inspect}"
end
log.debug { "current vnode table: #{@vnodes_by_node.inspect}" }
end
|