Class: Wakame::Service::Agent

Inherits:
Wakame::StatusDB::Model show all
Defined in:
lib/wakame/service.rb

Overview

Data model for agent Status life cycle: STATUS_INIT -> [STATUS_ONLINE|STATUS_OFFLINE|STATUS_TIMEOUT] -> STATUS_END

Constant Summary collapse

STATUS_END =
-1
STATUS_INIT =
-2
STATUS_OFFLINE =
0
STATUS_ONLINE =
1
STATUS_UNKNOWN =
2
STATUS_TIMEOUT =
3

Constants included from AttributeHelper

AttributeHelper::CLASS_TYPE_KEY, AttributeHelper::CONVERT_CLASSES, AttributeHelper::PRIMITIVE_CLASSES

Instance Method Summary collapse

Methods inherited from Wakame::StatusDB::Model

#delete, #dirty?, inherited, #new_record?, #on_after_delete, #on_after_load, #on_before_delete, #on_before_load, #reload, #save

Methods included from AttributeHelper

#dump_attrs, #retrieve_attr_attribute

Instance Method Details

#agent_ipObject



58
59
60
# File 'lib/wakame/service.rb', line 58

def agent_ip
  vm_attr[:local_ipv4]
end

#has_resource_type?(key) ⇒ Boolean

Returns:

  • (Boolean)


94
95
96
97
98
99
100
101
# File 'lib/wakame/service.rb', line 94

def has_resource_type?(key)
  res_id = key.is_a?(ServiceInstance) ? key.resource.id : Resource.id(key)

  reported_services.keys.any? { |k|
    svc = ServiceInstance.find(k)
    svc.resource.id == res_id
  }
end

#idObject



54
55
56
# File 'lib/wakame/service.rb', line 54

def id
  @id || raise("Agent.id is unset: #{self}")
end

#id=(agent_id) ⇒ Object



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

def id=(agent_id)
  @id = agent_id
end

#last_ping_at_timeObject

Tentative…



67
68
69
70
# File 'lib/wakame/service.rb', line 67

def last_ping_at_time
  require 'time'
  Time.parse(last_ping_at)
end

#mapped?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/wakame/service.rb', line 46

def mapped?
  !self.cloud_host_id.nil?
end

#renew_reported_services(svc_id_list) ⇒ Object



87
88
89
90
91
92
# File 'lib/wakame/service.rb', line 87

def renew_reported_services(svc_id_list)
  reported_services.clear
  svc_id_list.each { |svc_id, data|
    reported_services[svc_id] = data
  }
end

#terminateObject



103
104
# File 'lib/wakame/service.rb', line 103

def terminate
end

#update_status(new_status) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/wakame/service.rb', line 72

def update_status(new_status)
  if @status != new_status
    @status = new_status
    self.save

    ED.fire_event(Event::AgentStatusChanged.new(self))
    # Send status specific event
    case @status
    when STATUS_TIMEOUT
      ED.fire_event(Event::AgentTimedOut.new(self))
    end
  end
end

#vm_idObject



62
63
64
# File 'lib/wakame/service.rb', line 62

def vm_id
  vm_attr[:instance_id]
end