Class: Villein::Client
- Inherits:
-
Object
- Object
- Villein::Client
- Defined in:
- lib/villein/client.rb
Overview
Villein::Client allows you to order existing serf agent. You will need RPC address and agent name to command.
Direct Known Subclasses
Defined Under Namespace
Classes: LengthExceedsLimitError, SerfConnectionError, SerfError
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#rpc_addr ⇒ Object
readonly
Returns the value of attribute rpc_addr.
-
#serf ⇒ Object
readonly
Returns the value of attribute serf.
-
#silence ⇒ Object
writeonly
Sets the attribute silence.
Instance Method Summary collapse
-
#delete_tag(key) ⇒ Object
Remove tag from the agent.
- #event(name, payload, coalesce: true) ⇒ Object
- #force_leave(node) ⇒ Object
-
#get_tags ⇒ Object
Get tag from the agent.
-
#initialize(rpc_addr, name: nil, serf: 'serf', silence: true) ⇒ Client
constructor
A new instance of Client.
- #join(addr, replay: false) ⇒ Object
- #leave ⇒ Object
- #members(status: nil, name: nil, tags: {}) ⇒ Object
-
#set_tag(key, val) ⇒ Object
Set tag to the agent.
- #silence? ⇒ Boolean
-
#tags ⇒ Object
Returns Villein::Tags object for the current agent.
Constructor Details
#initialize(rpc_addr, name: nil, serf: 'serf', silence: true) ⇒ Client
Returns a new instance of Client.
22 23 24 25 26 27 |
# File 'lib/villein/client.rb', line 22 def initialize(rpc_addr, name: nil, serf: 'serf', silence: true) @rpc_addr = rpc_addr @name = name @serf = serf @silence = true end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
32 33 34 |
# File 'lib/villein/client.rb', line 32 def name @name end |
#rpc_addr ⇒ Object (readonly)
Returns the value of attribute rpc_addr.
32 33 34 |
# File 'lib/villein/client.rb', line 32 def rpc_addr @rpc_addr end |
#serf ⇒ Object (readonly)
Returns the value of attribute serf.
32 33 34 |
# File 'lib/villein/client.rb', line 32 def serf @serf end |
#silence=(value) ⇒ Object (writeonly)
Sets the attribute silence
30 31 32 |
# File 'lib/villein/client.rb', line 30 def silence=(value) @silence = value end |
Instance Method Details
#delete_tag(key) ⇒ Object
Remove tag from the agent. Using Villein::Client#tags method is recommended. It provides high-level API via Villein::Tags.
96 97 98 |
# File 'lib/villein/client.rb', line 96 def delete_tag(key) call_serf 'tags', '-delete', key end |
#event(name, payload, coalesce: true) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/villein/client.rb', line 34 def event(name, payload, coalesce: true) = [] unless coalesce << '-coalesce=false' end call_serf 'event', *, name, payload end |
#force_leave(node) ⇒ Object
58 59 60 |
# File 'lib/villein/client.rb', line 58 def force_leave(node) call_serf 'force-leave', node end |
#get_tags ⇒ Object
Get tag from the agent. Using Villein::Client#tags method is recommended. It provides high-level API via Villein::Tags.
88 89 90 91 |
# File 'lib/villein/client.rb', line 88 def me = members(name: self.name)[0] me["tags"] end |
#join(addr, replay: false) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/villein/client.rb', line 44 def join(addr, replay: false) = [] if replay << '-replay' end call_serf 'join', *, addr end |
#leave ⇒ Object
54 55 56 |
# File 'lib/villein/client.rb', line 54 def leave call_serf 'leave' end |
#members(status: nil, name: nil, tags: {}) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/villein/client.rb', line 62 def members(status: nil, name: nil, tags: {}) = ['-format', 'json'] .push('-status', status.to_s) if status .push('-name', name.to_s) if name .each do |tag, val| .push('-tag', "#{tag}=#{val}") end json = call_serf('members', *) response = JSON.parse(json) response["members"] end |
#set_tag(key, val) ⇒ Object
Set tag to the agent. Using Villein::Client#tags method is recommended. It provides high-level API via Villein::Tags.
103 104 105 |
# File 'lib/villein/client.rb', line 103 def set_tag(key, val) call_serf 'tags', '-set', "#{key}=#{val}" end |
#silence? ⇒ Boolean
29 |
# File 'lib/villein/client.rb', line 29 def silence?() !!@silence; end |
#tags ⇒ Object
Returns Villein::Tags object for the current agent. Villein::Tags provides high-level API for tagging agents.
81 82 83 |
# File 'lib/villein/client.rb', line 81 def ||= Tags.new(self) end |