Class: Wakame::Actions::RegisterAgent

Inherits:
Wakame::Action show all
Defined in:
lib/wakame/actions/register_agent.rb

Constant Summary

Constants included from AttributeHelper

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

Instance Attribute Summary

Attributes inherited from Wakame::Action

#action_manager

Instance Method Summary collapse

Methods inherited from Wakame::Action

#acquire_lock, #actor_request, #agent_monitor, #all_subactions_complete?, #flush_subactions, #master, #notes, #notify, #on_canceled, #on_failed, #service_cluster, #status=, #subactions, #sync_actor_request, #trigger_action, #walk_subactions

Methods included from ThreadImmutable

#bind_thread, included, #target_thread, #target_thread?, #thread_check

Methods included from AttributeHelper

#dump_attrs, #retrieve_attr_attribute

Constructor Details

#initialize(agent) ⇒ RegisterAgent

Returns a new instance of RegisterAgent.



4
5
6
# File 'lib/wakame/actions/register_agent.rb', line 4

def initialize(agent)
  @agent = agent
end

Instance Method Details

#on_failObject



35
36
37
38
39
# File 'lib/wakame/actions/register_agent.rb', line 35

def on_fail
  StatusDB.barrier {
    @agent.update_status(Service::Agent::STATUS_FAIL)
  }
end

#runObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/wakame/actions/register_agent.rb', line 8

def run
  Wakame.log.debug("#{self.class}: run() begin: #{@agent.id}")
  
  acquire_lock("Agent:#{@agent.id}")

  StatusDB.barrier {
    @agent.update_vm_attr
  }
  
  # Send monitoring conf
  if @agent.cloud_host_id
    Wakame.log.debug("#{self.class}: #{@agent.id} is to be set the monitor conf: #{@agent.cloud_host.live_monitors.inspect}")
    StatusDB.barrier {
      @agent.cloud_host.live_monitors.each { |path, data|
        master.actor_request(@agent.id, '/monitor/reload', path, data).request.wait
      }
    }
  end

  StatusDB.barrier {
    @agent.update_status(Service::Agent::STATUS_RUNNING)
    @agent.update_monitor_status(Service::Agent::STATUS_ONLINE)
    Models::AgentPool.instance.register(@agent)
  }
  Wakame.log.debug("#{self.class}: run() end: #{@agent.id}")
end