Class: Wakame::Actions::DestroyInstances
- Inherits:
-
Wakame::Action
- Object
- Wakame::Action
- Wakame::Actions::DestroyInstances
- Defined in:
- lib/wakame/actions/destroy_instances.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_prop) ⇒ DestroyInstances
constructor
A new instance of DestroyInstances.
- #run ⇒ Object
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(svc_prop) ⇒ DestroyInstances
Returns a new instance of DestroyInstances.
4 5 6 |
# File 'lib/wakame/actions/destroy_instances.rb', line 4 def initialize(svc_prop) @svc_prop = svc_prop end |
Instance Method Details
#run ⇒ Object
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 |
# File 'lib/wakame/actions/destroy_instances.rb', line 8 def run svc_to_stop=[] EM. { online_svc = [] service_cluster.each_instance(@svc_prop.class) { |svc_inst| if svc_inst.status == Service::STATUS_ONLINE online_svc << svc_inst end } svc_count = service_cluster.instance_count(@svc_prop) if svc_count < online_svc.size online_svc.delete_if { |svc| svc.agent.agent_id == master.attr[:instance_id] } ((online_svc.size - svc_count) + 1).times { svc_to_stop << online_svc.shift } Wakame.log.debug("#{self.class}: online_svc.size=#{online_svc.size}, svc_to_stop.size=#{svc_to_stop.size}") end } svc_to_stop.each { |svc_inst| trigger_action(StopService.new(svc_inst)) } flush_subactions end |