Class: Wakame::Actions::StartService
- Inherits:
-
Wakame::Action
- Object
- Wakame::Action
- Wakame::Actions::StartService
- Defined in:
- lib/wakame/actions/start_service.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
Instance Method Summary collapse
-
#initialize(svc) ⇒ StartService
constructor
A new instance of StartService.
- #on_failed ⇒ Object
- #run ⇒ Object
Methods inherited from Wakame::Action
#acquire_lock, #actor_request, #agent_monitor, #all_subactions_complete?, #flush_subactions, #master, #notes, #notify, #on_canceled, #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(svc) ⇒ StartService
Returns a new instance of StartService.
5 6 7 |
# File 'lib/wakame/actions/start_service.rb', line 5 def initialize(svc) @svc = svc end |
Instance Method Details
#on_failed ⇒ Object
92 93 94 95 96 |
# File 'lib/wakame/actions/start_service.rb', line 92 def on_failed StatusDB. { @svc.update_status(Service::STATUS_FAIL) } end |
#run ⇒ Object
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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/wakame/actions/start_service.rb', line 9 def run acquire_lock(@svc.resource.class.to_s) @svc.reload # Skip to act when the service is having below status. if @svc.status == Service::STATUS_RUNNING && @svc.monitor_status == Service::STATUS_ONLINE Wakame.log.info("Ignore to start the service as is being or already Online: #{@svc.resource.class}") return end if @svc.resource.require_agent raise "The service is not bound cloud host object: #{@svc.id}" if @svc.cloud_host_id.nil? unless @svc.cloud_host.mapped? acquire_lock(Models::AgentPool.to_s) # Try to arrange agent from existing agent pool. StatusDB. { next if Models::AgentPool.group_active.empty? agent2host = cluster.agents.invert Models::AgentPool.group_active.each { |agent_id| agent = Service::Agent.find(agent_id) if !agent.has_resource_type?(@svc.resource) && agent2host[agent_id].nil? && # This agent is not mapped to any cloud hosts. @svc.cloud_host.vm_spec.satisfy?(agent.vm_attr) @svc.cloud_host.map_agent(agent) break end } } # Start new VM when the target agent is still nil. unless @svc.cloud_host.mapped? inst_id_key = "new_inst_id_" + Wakame::Util.gen_id trigger_action(LaunchVM.new(inst_id_key, @svc.cloud_host.vm_spec)) flush_subactions StatusDB. { agent = Service::Agent.find(notes[inst_id_key]) raise "Cound not find the specified VM instance \"#{notes[inst_id_key]}\"" if agent.nil? @svc.cloud_host.map_agent(agent) } end raise "Could not find the agent to be assigned to : #{@svc.resource.class}" unless @svc.cloud_host.mapped? end raise "The assigned agent \"#{@svc.cloud_host.agent_id}\" for the service instance #{@svc.id} is not online." unless @svc.cloud_host.agent.monitor_status == Service::Agent::STATUS_ONLINE StatusDB. { @svc.update_status(Service::STATUS_ENTERING) } @svc.resource.on_enter_agent(@svc, self) end StatusDB. { @svc.update_status(Service::STATUS_STARTING) } if @svc.resource.require_agent trigger_action(DeployConfig.new(@svc)) flush_subactions end @svc.reload Wakame.log.debug("#{@svc.resource.class}: svc.monitor_status == Wakame::Service::STATUS_ONLINE => #{@svc.monitor_status == Wakame::Service::STATUS_ONLINE}") if @svc.monitor_status != Wakame::Service::STATUS_ONLINE @svc.resource.start(@svc, self) end StatusDB. { @svc.update_status(Service::STATUS_RUNNING) } trigger_action(NotifyParentChanged.new(@svc)) flush_subactions end |