Module: RubyAemAws::HealthyCountVerifier
- Defined in:
- lib/ruby_aem_aws/mixins/healthy_count_verifier.rb
Overview
Mixin for checking health of a component via ELB ‘healthy’ count vs ASG desired_capacity. Add this to a component to make it capable of determining its own health.
Instance Method Summary collapse
-
#health_state ⇒ Object
Provides detail of the state of the instances comprising the component.
-
#healthy? ⇒ Boolean
Aggregate health_states considered healthy.
-
#wait_until_healthy ⇒ Object
True, if all EC2 instances within the ELB are running.
Instance Method Details
#health_state ⇒ Object
Provides detail of the state of the instances comprising the component.
-
no_asg: AutoScalingGroup could not be located (by StackPrefix and Component tags).
-
no_elb: ElasticLoadBalancer could not be located (by StackPrefix and aws:cloudformation:logical-id tags).
-
misconfigured: AutoScalingGroup.desired_capacity is less than 1.
-
recovering: ELB running instance count is less than AutoScalingGroup.desired_capacity.
-
scaling: ELB running instance count is more than AutoScalingGroup.desired_capacity.
-
ready: ELB running instance count is equal to AutoScalingGroup.desired_capacity.
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 |
# File 'lib/ruby_aem_aws/mixins/healthy_count_verifier.rb', line 35 def health_state asg = find_auto_scaling_group(asg_client) return :no_asg if asg.nil? # Debug: # unless asg.nil? # puts("ASG: #{asg} #{asg.auto_scaling_group_name} (#{asg.desired_capacity})") # asg.instances.each do |i| # puts(" Instance #{i.instance_id}: #{i.health_status}") # end # end elb = find_elb(elb_client) return :no_elb if elb.nil? elb_running_instances = 0 elb_instances = get_instances_state(elb_client, elb) return :no_elb_targets if elb_instances.nil? elb_instances.each do |i| elb_running_instances += 1 if i[:state] == RubyAemAws::Constants::INSTANCE_STATE_HEALTHY end desired_capacity = asg.desired_capacity return :misconfigured if desired_capacity < 1 return :recovering if elb_running_instances < desired_capacity return :scaling if elb_running_instances > desired_capacity :ready end |
#healthy? ⇒ Boolean
Aggregate health_states considered healthy.
23 24 25 |
# File 'lib/ruby_aem_aws/mixins/healthy_count_verifier.rb', line 23 def healthy? %i[ready scaling].include? health_state end |
#wait_until_healthy ⇒ Object
Returns true, if all EC2 instances within the ELB are running.
68 69 70 71 72 73 |
# File 'lib/ruby_aem_aws/mixins/healthy_count_verifier.rb', line 68 def wait_until_healthy raise ELBMisconfiguration if health_state.eql?(:misconfigured) sleep 60 while health_state.eql?(:recovering) || health_state.eql?(:scaling) return true if health_state.eql?(:ready) end |