Class: Wakame::Service::Agent

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from AttributeHelper

#dump_attrs

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_idObject

Returns the value of attribute agent_id.



32
33
34
# File 'lib/wakame/service.rb', line 32

def agent_id
  @agent_id
end

#attrObject

Returns the value of attribute attr.



32
33
34
# File 'lib/wakame/service.rb', line 32

def attr
  @attr
end

#last_ping_atObject

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_pathObject

Returns the value of attribute root_path.



32
33
34
# File 'lib/wakame/service.rb', line 32

def root_path
  @root_path
end

#servicesObject

Returns the value of attribute services.



32
33
34
# File 'lib/wakame/service.rb', line 32

def services
  @services
end

#statusObject

Returns the value of attribute status.



51
52
53
# File 'lib/wakame/service.rb', line 51

def status
  @status
end

#uptimeObject

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_ipObject



43
44
45
# File 'lib/wakame/service.rb', line 43

def agent_ip
  attr[:local_ipv4]
end

#dump_statusObject



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

Returns:

  • (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