Class: Wakame::Actions::DeployApplication

Inherits:
Wakame::Action show all
Defined in:
lib/wakame/actions/deploy_application.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(app_name) ⇒ DeployApplication

Returns a new instance of DeployApplication.



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

def initialize(app_name)
  @app_name = app_name
end

Instance Method Details

#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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/wakame/actions/deploy_application.rb', line 8

def run
  Wakame.log.debug("#{self.class}: run() Begin:")
  #raise "CloudHost is not mapped Agent: CloudHost.id=#{@svc.cloud_host.id}" unless @svc.cloud_host.mapped?

  repo_data = Models::ApplicationRepository.find(:app_name=>@app_name) || raise
  deploy_opts={}
  if repo_data[:repo_type] == 's3'
    deploy_opts[:aws_access_key] ||= Wakame.config.aws_access_key
    deploy_opts[:aws_secret_key] ||= Wakame.config.aws_secret_key
  end
  deploy_ticket = Wakame::Util.gen_id


  resclass_names = []
  svc_lst = []
  cluster.each_instance { |svc|
    next  unless svc.resource.tags.member?(repo_data.resource_tag.to_sym)
    resclass_names << svc.resource.class.to_s
    svc_lst << svc
  }

  if svc_lst.empty?
    return
  end

  resclass_names.uniq!
  acquire_lock(resclass_names)
  
  # Checkout apps from each repository
  svc_lst.each { |svc|
    trigger_action {|action|
      action.actor_request(svc.cloud_host.agent_id, '/deploy/checkout',
                           deploy_ticket,
                           repo_data[:repo_type],
                           repo_data[:repo_uri],
                           repo_data[:revision],
                           svc.resource.application_root_path,
                           repo_data[:app_name],
                           deploy_opts
                           ).request.wait
    }
  }
  flush_subactions

  # Reload Appserver
  svc_lst.each { |svc|
    actor_request(svc.cloud_host.agent_id, '/deploy/swap_current_link', svc.resource.application_root_path, repo_data[:app_name]).request.wait
    svc.resource.on_reload_application(svc, self, repo_data)
  }
end