Module: Wakame::Actions::Util

Included in:
MigrateService, PropagateInstances
Defined in:
lib/wakame/actions/util.rb

Instance Method Summary collapse

Instance Method Details

#arrange_agent(svc_prop) ⇒ Object

Arrange an agent for the paticular service instance from agent pool.



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/wakame/actions/util.rb', line 33

def arrange_agent(svc_prop)
  agent = nil
  agent_monitor.each_online { |ag|
    if test_agent_candidate(svc_prop, ag)
      agent = ag
      break
    end
  }
  agent = agent[1] if agent

  agent
end

#deploy_configuration(service_instance) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/wakame/actions/util.rb', line 5

def deploy_configuration(service_instance)
  Wakame.log.debug("Begin: #{self}.deploy_configuration(#{service_instance.property.class})")
  
  begin
    tmpl = Wakame::Template.new(service_instance)
    tmpl.render_config
    
    agent = service_instance.agent
    src_path = tmpl.tmp_basedir.dup
    src_path.sub!('/$', '') if File.directory? src_path
    
    dest_path = File.expand_path("tmp/config/" + File.basename(tmpl.basedir), service_instance.agent.root_path)
    Wakame::Util.exec("rsync -e 'ssh -i #{Wakame.config.ssh_private_key} -o \"UserKnownHostsFile #{Wakame.config.ssh_known_hosts}\"' -au #{src_path}/ root@#{agent.agent_ip}:#{dest_path}")
    #Util.exec("rsync -au #{src_path}/ #{dest_path}")
    
  ensure
    tmpl.cleanup if tmpl
  end

  Wakame.log.debug("End: #{self}.deploy_configuration(#{service_instance.property.class})")
end

#start_instance(image_id, attr = {}) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/wakame/actions/util.rb', line 47

def start_instance(image_id, attr={})
  Wakame.log.debug("#{self.class} called start_instance(#{image_id})")
  
  attr[:user_data] = "node=agent\namqp_server=amqp://#{master.attr[:local_ipv4]}/"
  Wakame.log.debug("user_data: #{attr[:user_data]}")
  vm_manipulator = VmManipulator.create
  res = vm_manipulator.start_instance(image_id, attr)
  inst_id = res[:instance_id]
  
  ConditionalWait.wait { | cond |
    cond.wait_event(Event::AgentMonitored) { |event|
      event.agent.attr[:instance_id] == inst_id
    }
    
    cond.poll(5, 100) {
      vm_manipulator.check_status(inst_id, :online)
    }
  }
  
  inst_id
end

#test_agent_candidate(svc_prop, agent) ⇒ Object



27
28
29
30
# File 'lib/wakame/actions/util.rb', line 27

def test_agent_candidate(svc_prop, agent)
  return false if agent.has_service_type?(svc_prop.class)
  svc_prop.vm_spec.current.satisfy?(agent) 
end