Class: Etcd::Node
- Inherits:
-
Object
- Object
- Etcd::Node
- Includes:
- Constants, Requestable
- Defined in:
- lib/etcd/node.rb
Constant Summary
Constants included from Constants
Constants::S_ACTION, Constants::S_AND, Constants::S_DIR, Constants::S_EXPIRATION, Constants::S_INDEX, Constants::S_KEY, Constants::S_KEYS, Constants::S_LOCATION, Constants::S_NEW_KEY, Constants::S_PREV_VALUE, Constants::S_SLASH, Constants::S_TTL, Constants::S_VALUE, Constants::S_WATCH
Instance Attribute Summary collapse
-
#etcd ⇒ Object
Returns the value of attribute etcd.
-
#is_leader ⇒ Object
Returns the value of attribute is_leader.
-
#name ⇒ Object
Returns the value of attribute name.
-
#raft ⇒ Object
Returns the value of attribute raft.
-
#status ⇒ Object
possible values: :unknown, :running, :down.
Instance Method Summary collapse
- #check_required(opts) ⇒ Object
-
#initialize(opts = {}) ⇒ Node
constructor
A new instance of Node.
- #inspect ⇒ Object
- #leader_uri ⇒ Object
- #name_with_status ⇒ Object
- #update_status ⇒ Object
Methods included from Requestable
#http_client, #request, #request_data, #reset_http_client!
Methods included from Loggable
Constructor Details
#initialize(opts = {}) ⇒ Node
Returns a new instance of Node.
10 11 12 13 14 15 16 |
# File 'lib/etcd/node.rb', line 10 def initialize(opts={}) check_required(opts) @name = opts[:name] @etcd = URI.decode(opts[:etcd]) @raft = URI.decode(opts[:raft]) @status = :unknown end |
Instance Attribute Details
#etcd ⇒ Object
Returns the value of attribute etcd.
5 6 7 |
# File 'lib/etcd/node.rb', line 5 def etcd @etcd end |
#is_leader ⇒ Object
Returns the value of attribute is_leader.
8 9 10 |
# File 'lib/etcd/node.rb', line 8 def is_leader @is_leader end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/etcd/node.rb', line 5 def name @name end |
#raft ⇒ Object
Returns the value of attribute raft.
5 6 7 |
# File 'lib/etcd/node.rb', line 5 def raft @raft end |
#status ⇒ Object
possible values: :unknown, :running, :down
7 8 9 |
# File 'lib/etcd/node.rb', line 7 def status @status end |
Instance Method Details
#check_required(opts) ⇒ Object
18 19 20 |
# File 'lib/etcd/node.rb', line 18 def check_required(opts) raise ArgumentError, "etcd URL is required!" unless opts[:etcd] end |
#inspect ⇒ Object
36 37 38 |
# File 'lib/etcd/node.rb', line 36 def inspect %Q(<#{self.class} - #{name_with_status} - #{etcd}>) end |
#leader_uri ⇒ Object
32 33 34 |
# File 'lib/etcd/node.rb', line 32 def leader_uri "#{@etcd}/v1/leader" end |
#name_with_status ⇒ Object
40 41 42 43 |
# File 'lib/etcd/node.rb', line 40 def name_with_status print_status = @is_leader ? "leader" : status "#{name} (#{print_status})" end |
#update_status ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/etcd/node.rb', line 22 def update_status begin response = request(:get, leader_uri) @status = :running @is_leader = (response.body == @raft) rescue HTTPClient::TimeoutError, Errno::ECONNREFUSED => e @status = :down end end |