Class: Wakame::Service::Agent
- Inherits:
-
Object
- Object
- Wakame::Service::Agent
- Includes:
- AttributeHelper, ThreadImmutable
- Defined in:
- lib/wakame/service.rb
Constant Summary collapse
- STATUS_OFFLINE =
0
- STATUS_ONLINE =
1
- STATUS_UNKNOWN =
2
- STATUS_TIMEOUT =
3
Constants included from AttributeHelper
AttributeHelper::CONVERT_CLASSES, AttributeHelper::PRIMITIVE_CLASSES
Instance Attribute Summary collapse
-
#agent_id ⇒ Object
Returns the value of attribute agent_id.
-
#attr ⇒ Object
Returns the value of attribute attr.
-
#last_ping_at ⇒ Object
Returns the value of attribute last_ping_at.
-
#root_path ⇒ Object
Returns the value of attribute root_path.
-
#services ⇒ Object
Returns the value of attribute services.
-
#status ⇒ Object
Returns the value of attribute status.
-
#uptime ⇒ Object
Returns the value of attribute uptime.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #agent_ip ⇒ Object
- #dump_status ⇒ Object
- #has_service_type?(key) ⇒ Boolean
-
#initialize(agent_id = nil) ⇒ Agent
constructor
A new instance of Agent.
Methods included from AttributeHelper
Methods included from ThreadImmutable
#bind_thread, included, #target_thread, #target_thread?, #thread_check
Constructor Details
#initialize(agent_id = nil) ⇒ Agent
Returns a new instance of Agent.
35 36 37 38 39 40 41 |
# File 'lib/wakame/service.rb', line 35 def initialize(agent_id=nil) bind_thread @services = {} @agent_id = agent_id @last_ping_at = Time.now @status = STATUS_ONLINE end |
Instance Attribute Details
#agent_id ⇒ Object
Returns the value of attribute agent_id.
32 33 34 |
# File 'lib/wakame/service.rb', line 32 def agent_id @agent_id end |
#attr ⇒ Object
Returns the value of attribute attr.
32 33 34 |
# File 'lib/wakame/service.rb', line 32 def attr @attr end |
#last_ping_at ⇒ Object
Returns the value of attribute last_ping_at.
32 33 34 |
# File 'lib/wakame/service.rb', line 32 def last_ping_at @last_ping_at end |
#root_path ⇒ Object
Returns the value of attribute root_path.
32 33 34 |
# File 'lib/wakame/service.rb', line 32 def root_path @root_path end |
#services ⇒ Object
Returns the value of attribute services.
32 33 34 |
# File 'lib/wakame/service.rb', line 32 def services @services end |
#status ⇒ Object
Returns the value of attribute status.
51 52 53 |
# File 'lib/wakame/service.rb', line 51 def status @status end |
#uptime ⇒ Object
Returns the value of attribute uptime.
32 33 34 |
# File 'lib/wakame/service.rb', line 32 def uptime @uptime end |
Instance Method Details
#[](key) ⇒ Object
47 48 49 |
# File 'lib/wakame/service.rb', line 47 def [](key) attr[key] end |
#agent_ip ⇒ Object
43 44 45 |
# File 'lib/wakame/service.rb', line 43 def agent_ip attr[:local_ipv4] end |
#dump_status ⇒ Object
87 88 89 90 91 |
# File 'lib/wakame/service.rb', line 87 def dump_status {:agent_id => @agent_id, :status => @status, :last_ping_at => @last_ping_at, :attr => attr.dup, :services => services.keys.dup } end |
#has_service_type?(key) ⇒ Boolean
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/wakame/service.rb', line 67 def has_service_type?(key) svc_class = case key when Service::ServiceInstance key.resource.class when Service::Resource key.class when Class key else raise ArgumentError end services.any? { |k, v| Wakame.log.debug( "#{agent_id} of service #{v.resource.class}. v.resource.class == svc_class result to #{v.resource.class == svc_class}") v.property.class == svc_class } end |