Class: CfDeployer::Driver::AutoScalingGroup
- Inherits:
-
Object
- Object
- CfDeployer::Driver::AutoScalingGroup
- Extended by:
- Forwardable
- Defined in:
- lib/cf_deployer/driver/auto_scaling_group.rb
Instance Attribute Summary collapse
-
#group ⇒ Object
readonly
Returns the value of attribute group.
-
#group_name ⇒ Object
readonly
Returns the value of attribute group_name.
Instance Method Summary collapse
- #cool_down ⇒ Object
- #describe ⇒ Object
- #desired_capacity_reached? ⇒ Boolean
- #healthy_instance_count ⇒ Object
- #healthy_instance_ids ⇒ Object
- #in_service_instance_ids ⇒ Object
-
#initialize(name, timeout = CfDeployer::Defaults::Timeout) ⇒ AutoScalingGroup
constructor
A new instance of AutoScalingGroup.
- #instance_statuses ⇒ Object
- #wait_for_desired_capacity ⇒ Object
- #warm_up(desired) ⇒ Object
- #warm_up_cooled_group(options) ⇒ Object
Constructor Details
#initialize(name, timeout = CfDeployer::Defaults::Timeout) ⇒ AutoScalingGroup
Returns a new instance of AutoScalingGroup.
10 11 12 13 |
# File 'lib/cf_deployer/driver/auto_scaling_group.rb', line 10 def initialize name, timeout = CfDeployer::Defaults::Timeout @group_name = name @timeout = timeout end |
Instance Attribute Details
#group ⇒ Object (readonly)
Returns the value of attribute group.
8 9 10 |
# File 'lib/cf_deployer/driver/auto_scaling_group.rb', line 8 def group @group end |
#group_name ⇒ Object (readonly)
Returns the value of attribute group_name.
8 9 10 |
# File 'lib/cf_deployer/driver/auto_scaling_group.rb', line 8 def group_name @group_name end |
Instance Method Details
#cool_down ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/cf_deployer/driver/auto_scaling_group.rb', line 37 def cool_down Log.info "Cooling down #{group_name}" CfDeployer::Driver::DryRun.guard "Skipping ASG cooldown" do aws_group.update :min_size => 0, :max_size => 0 aws_group.set_desired_capacity 0 end end |
#describe ⇒ Object
15 16 17 |
# File 'lib/cf_deployer/driver/auto_scaling_group.rb', line 15 def describe { desired: aws_group.desired_capacity, min: aws_group.min_size, max: aws_group.max_size } end |
#desired_capacity_reached? ⇒ Boolean
61 62 63 |
# File 'lib/cf_deployer/driver/auto_scaling_group.rb', line 61 def desired_capacity_reached? healthy_instance_count >= desired_capacity end |
#healthy_instance_count ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/cf_deployer/driver/auto_scaling_group.rb', line 87 def healthy_instance_count AWS.memoize do instances = healthy_instance_ids instances &= in_service_instance_ids unless load_balancers.empty? Log.info "Healthy instance count: #{instances.count}" instances.count end rescue => e Log.error "Unable to determine healthy instance count due to error: #{e.message}" -1 end |
#healthy_instance_ids ⇒ Object
65 66 67 68 69 70 |
# File 'lib/cf_deployer/driver/auto_scaling_group.rb', line 65 def healthy_instance_ids instances = auto_scaling_instances.select do |instance| 'HEALTHY'.casecmp(instance.health_status) == 0 end instances.map(&:id) end |
#in_service_instance_ids ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/cf_deployer/driver/auto_scaling_group.rb', line 72 def in_service_instance_ids elbs = load_balancers return [] if elbs.empty? ids = elbs.collect(&:instances) .collect(&:health) .to_a .collect { |elb_healths| elb_healths.select { |health| health[:state] == 'InService' } .map { |health| health[:instance].id } } ids.inject(:&) end |
#instance_statuses ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/cf_deployer/driver/auto_scaling_group.rb', line 45 def instance_statuses instance_info = {} ec2_instances.each do |instance| instance_info[instance.id] = CfDeployer::Driver::Instance.new(instance).status end instance_info end |
#wait_for_desired_capacity ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/cf_deployer/driver/auto_scaling_group.rb', line 53 def wait_for_desired_capacity Timeout::timeout(@timeout){ until desired_capacity_reached? sleep 15 end } end |
#warm_up(desired) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/cf_deployer/driver/auto_scaling_group.rb', line 19 def warm_up desired return if desired < aws_group.min_size desired = aws_group.max_size if desired > aws_group.max_size Log.info "warming up auto scaling group #{group_name} to #{desired}" CfDeployer::Driver::DryRun.guard "Skipping ASG warmup" do aws_group.set_desired_capacity desired wait_for_desired_capacity end end |
#warm_up_cooled_group(options) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/cf_deployer/driver/auto_scaling_group.rb', line 30 def warm_up_cooled_group CfDeployer::Driver::DryRun.guard 'Skipping update of ASG min & max instance count' do aws_group.update :min_size => [:min], :max_size => [:max] end warm_up [:desired] end |