Class: Chef::Expander::Node
- Inherits:
-
Object
- Object
- Chef::Expander::Node
- Includes:
- Loggable
- Defined in:
- lib/chef/expander/node.rb
Constant Summary
Constants included from Loggable
Instance Attribute Summary collapse
-
#guid ⇒ Object
readonly
Returns the value of attribute guid.
-
#hostname_f ⇒ Object
readonly
Returns the value of attribute hostname_f.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #attach_to_queue(queue, colloquial_name, &message_handler) ⇒ Object
- #broadcast_control_exchange ⇒ Object
- #broadcast_control_exchange_name ⇒ Object
-
#broadcast_control_queue ⇒ Object
The broadcast control queue is for 1 to N messaging, i.e., messages that go to every node.
- #broadcast_control_queue_name ⇒ Object
- #broadcast_message(message) ⇒ Object
- #direct_message(message) ⇒ Object
- #eql?(other) ⇒ Boolean
-
#exclusive_control_queue ⇒ Object
The exclusive control queue is for point-to-point messaging, i.e., messages directly addressed to this node.
- #exclusive_control_queue_name ⇒ Object
- #hash ⇒ Object
- #identifier ⇒ Object
-
#initialize(guid, hostname_f, pid) ⇒ Node
constructor
A new instance of Node.
-
#shared_control_queue ⇒ Object
The shared control queue is for 1 to (1 of N) messaging, i.e., messages that can go to any one node.
- #shared_control_queue_name ⇒ Object
- #shared_message(message) ⇒ Object
- #start(&message_handler) ⇒ Object
- #stop ⇒ Object
- #to_hash ⇒ Object
Methods included from Loggable
Constructor Details
#initialize(guid, hostname_f, pid) ⇒ Node
Returns a new instance of Node.
57 58 59 |
# File 'lib/chef/expander/node.rb', line 57 def initialize(guid, hostname_f, pid) @guid, @hostname_f, @pid = guid, hostname_f, pid end |
Instance Attribute Details
#guid ⇒ Object (readonly)
Returns the value of attribute guid.
51 52 53 |
# File 'lib/chef/expander/node.rb', line 51 def guid @guid end |
#hostname_f ⇒ Object (readonly)
Returns the value of attribute hostname_f.
53 54 55 |
# File 'lib/chef/expander/node.rb', line 53 def hostname_f @hostname_f end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
55 56 57 |
# File 'lib/chef/expander/node.rb', line 55 def pid @pid end |
Class Method Details
.from_hash(node_info) ⇒ Object
34 35 36 |
# File 'lib/chef/expander/node.rb', line 34 def self.from_hash(node_info) new(node_info[:guid], node_info[:hostname_f], node_info[:pid]) end |
.guid ⇒ Object
42 43 44 45 |
# File 'lib/chef/expander/node.rb', line 42 def self.guid return @guid if @guid @guid = UUIDTools::UUID.random_create.to_s end |
.hostname_f ⇒ Object
47 48 49 |
# File 'lib/chef/expander/node.rb', line 47 def self.hostname_f @hostname ||= Open3.popen3("hostname -f") {|stdin, stdout, stderr| stdout.read }.strip end |
.local_node ⇒ Object
38 39 40 |
# File 'lib/chef/expander/node.rb', line 38 def self.local_node new(guid, hostname_f, Process.pid) end |
Instance Method Details
#==(other) ⇒ Object
158 159 160 161 |
# File 'lib/chef/expander/node.rb', line 158 def ==(other) other.respond_to?(:guid) && other.respond_to?(:hostname_f) && other.respond_to?(:pid) && (other.guid == guid) && (other.hostname_f == hostname_f) && (other.pid == pid) end |
#attach_to_queue(queue, colloquial_name, &message_handler) ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/chef/expander/node.rb', line 67 def attach_to_queue(queue, colloquial_name, &) queue.subscribe(:ack => true) do |headers, payload| log.debug { "received message on #{colloquial_name} queue: #{payload}" } .call(payload) headers.ack end end |
#broadcast_control_exchange ⇒ Object
131 132 133 134 135 136 |
# File 'lib/chef/expander/node.rb', line 131 def broadcast_control_exchange @broadcast_control_exchange ||= begin log.debug { "declaring broadcast control exchange opscode-platfrom-control--broadcast" } MQ.fanout(broadcast_control_exchange_name, :nowait => false) end end |
#broadcast_control_exchange_name ⇒ Object
146 147 148 |
# File 'lib/chef/expander/node.rb', line 146 def broadcast_control_exchange_name BROADCAST_CONTROL_EXCHANGE_NAME end |
#broadcast_control_queue ⇒ Object
The broadcast control queue is for 1 to N messaging, i.e., messages that go to every node
121 122 123 124 125 126 127 128 129 |
# File 'lib/chef/expander/node.rb', line 121 def broadcast_control_queue @broadcast_control_queue ||= begin log.debug { "declaring broadcast control queue #{broadcast_control_queue_name}"} q = MQ.queue(broadcast_control_queue_name) log.debug { "binding broadcast control queue to broadcast control exchange"} q.bind(broadcast_control_exchange) q end end |
#broadcast_control_queue_name ⇒ Object
142 143 144 |
# File 'lib/chef/expander/node.rb', line 142 def broadcast_control_queue_name @broadcast_control_queue_name ||= "#{identifier}--broadcast" end |
#broadcast_message(message) ⇒ Object
96 97 98 99 |
# File 'lib/chef/expander/node.rb', line 96 def () log.debug { "publishing broadcast message #{}" } broadcast_control_exchange.publish() end |
#direct_message(message) ⇒ Object
86 87 88 89 |
# File 'lib/chef/expander/node.rb', line 86 def () log.debug { "publishing direct message to node #{identifier}: #{}" } exclusive_control_queue.publish() end |
#eql?(other) ⇒ Boolean
163 164 165 |
# File 'lib/chef/expander/node.rb', line 163 def eql?(other) (other.class == self.class) && (other.hash == hash) end |
#exclusive_control_queue ⇒ Object
The exclusive control queue is for point-to-point messaging, i.e., messages directly addressed to this node
103 104 105 106 107 108 |
# File 'lib/chef/expander/node.rb', line 103 def exclusive_control_queue @exclusive_control_queue ||= begin log.debug { "declaring exclusive control queue #{exclusive_control_queue_name}" } MQ.queue(exclusive_control_queue_name) end end |
#exclusive_control_queue_name ⇒ Object
150 151 152 |
# File 'lib/chef/expander/node.rb', line 150 def exclusive_control_queue_name @exclusive_control_queue_name ||= "#{identifier}--exclusive-control" end |
#hash ⇒ Object
167 168 169 |
# File 'lib/chef/expander/node.rb', line 167 def hash identifier.hash end |
#identifier ⇒ Object
154 155 156 |
# File 'lib/chef/expander/node.rb', line 154 def identifier "#{hostname_f}--#{pid}--#{guid}" end |
#shared_control_queue ⇒ Object
The shared control queue is for 1 to (1 of N) messaging, i.e., messages that can go to any one node.
112 113 114 115 116 117 |
# File 'lib/chef/expander/node.rb', line 112 def shared_control_queue @shared_control_queue ||= begin log.debug { "declaring shared control queue #{shared_control_queue_name}" } MQ.queue(shared_control_queue_name) end end |
#shared_control_queue_name ⇒ Object
138 139 140 |
# File 'lib/chef/expander/node.rb', line 138 def shared_control_queue_name SHARED_CONTROL_QUEUE_NAME end |
#shared_message(message) ⇒ Object
91 92 93 94 |
# File 'lib/chef/expander/node.rb', line 91 def () log.debug { "publishing shared message #{}"} shared_control_queue.publish() end |
#start(&message_handler) ⇒ Object
61 62 63 64 65 |
# File 'lib/chef/expander/node.rb', line 61 def start(&) attach_to_queue(exclusive_control_queue, "exclusive control", &) attach_to_queue(shared_control_queue, "shared_control", &) attach_to_queue(broadcast_control_queue, "broadcast control", &) end |
#stop ⇒ Object
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/chef/expander/node.rb', line 75 def stop log.debug { "unsubscribing from broadcast control queue"} broadcast_control_queue.unsubscribe(:nowait => false) log.debug { "unsubscribing from shared control queue" } shared_control_queue.unsubscribe(:nowait => false) log.debug { "unsubscribing from exclusive control queue" } exclusive_control_queue.unsubscribe(:nowait => false) end |
#to_hash ⇒ Object
171 172 173 |
# File 'lib/chef/expander/node.rb', line 171 def to_hash {:guid => @guid, :hostname_f => @hostname_f, :pid => @pid} end |