Class: Wakame::Actions::DestroyInstances

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

Constant Summary

Constants included from AttributeHelper

AttributeHelper::CONVERT_CLASSES, AttributeHelper::PRIMITIVE_CLASSES

Instance Attribute Summary

Attributes inherited from Wakame::Action

#trigger

Instance Method Summary collapse

Methods inherited from Wakame::Action

#actor_request, #agent_monitor, #all_subactions_complete?, #bind_triggered_rule, #flush_subactions, #master, #notes, #notify, #notify_queue, #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

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

#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
# File 'lib/wakame/actions/destroy_instances.rb', line 8

def run
  svc_to_stop=[]

  EM.barrier {
    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