add print statements so user is aware of what is happening
This commit is contained in:
parent
07fc0390f7
commit
8c24fa8dbf
|
@ -16,33 +16,61 @@ class AwsHaRelease
|
|||
@max_size_change = 0
|
||||
@inservice_polling_time = 10
|
||||
@opts = opts
|
||||
@processes_to_suspend = %w(ReplaceUnhealthy AlarmNotification ScheduledActions AZRebalance)
|
||||
end
|
||||
|
||||
def execute!
|
||||
@group.suspend_processes 'ReplaceUnhealthy', 'AlarmNotification', 'ScheduledActions', 'AZRebalance'
|
||||
@group.suspend_processes @processes_to_suspend
|
||||
|
||||
if @group.max_size == @group.desired_capacity
|
||||
puts "#{@group.name} has a max-size of #{@group.max_size}. In order to recycle instances max-size will be temporarily increased by 1."
|
||||
@group.update(max_size: @group.max_size + 1)
|
||||
@max_size_change = 1
|
||||
end
|
||||
|
||||
@group.update(desired_capacity: @group.desired_capacity + 1)
|
||||
|
||||
puts "The list of Instances in Auto Scaling Group $asg_group_name that will be terminated is:\n#{@group.ec2_instances.map(&:id)}"
|
||||
@group.ec2_instances.each do |instance|
|
||||
Timeout::timeout(@opts[:inservice_time_allowed]) do
|
||||
until all_instances_inservice?(@group.load_balancers)
|
||||
sleep @inservice_polling_time
|
||||
time_taken = 0
|
||||
|
||||
begin
|
||||
Timeout::timeout(@opts[:inservice_time_allowed]) do
|
||||
|
||||
until all_instances_inservice?(@group.load_balancers)
|
||||
puts "#{time_taken} seconds have elapsed while waiting for an Instance to reach InService status."
|
||||
|
||||
time_taken += @inservice_polling_time
|
||||
sleep @inservice_polling_time
|
||||
end
|
||||
|
||||
deregister_instance instance, @group.load_balancers
|
||||
sleep @opts[:elb_timeout]
|
||||
instance.terminate false
|
||||
end
|
||||
rescue Timeout::Error => e
|
||||
puts "\nDuring the last #{time_taken} seconds, a new AutoScaling instance failed to become healthy."
|
||||
puts "The following settings were changed and will not be changed back by this script:\n"
|
||||
|
||||
puts "AutoScaling processes #{@processes_to_suspend} were suspended."
|
||||
puts "The desired capacity was changed from #{@group.desired_capacity - 1} to #{@group.desired_capacity}."
|
||||
|
||||
if @max_size_change > 0
|
||||
puts "The maximum size was changed from #{@group.max_size - @max_size_change} to #{@group.max_size}"
|
||||
end
|
||||
|
||||
deregister_instance instance, @group.load_balancers
|
||||
sleep @opts[:elb_timeout]
|
||||
instance.terminate false
|
||||
raise
|
||||
end
|
||||
end
|
||||
|
||||
puts "#{@group.name} had its desired-capacity increased temporarily by 1 to a desired-capacity of #{@group.desired_capacity}."
|
||||
puts "$app_name will now return the desired-capacity of #{@group.name} to its original desired-capacity of #{@group.desired_capacity - 1}."
|
||||
@group.update(desired_capacity: @group.desired_capacity - 1)
|
||||
|
||||
if @max_size_change > 0
|
||||
puts "\n#{@group.name} had its max_size increased temporarily by #{@max_size_change} to a max_size of #{@group.max_size}."
|
||||
puts "The max_size of #{@group.name} will now be returned to its original max_size of #{@group.max_size - @max_size_change}."
|
||||
|
||||
@group.update(max_size: @group.max_size - @max_size_change)
|
||||
@max_size_change = 0
|
||||
end
|
||||
|
@ -58,7 +86,11 @@ class AwsHaRelease
|
|||
|
||||
def instances_inservice?(load_balancer)
|
||||
load_balancer.instances.health.each do |health|
|
||||
return false unless health[:state] == 'InService'
|
||||
unless health[:state] == 'InService'
|
||||
puts "Instance #{health[:instance].id} is currently #{health[:state]} on load balancer #{load_balancer.name}."
|
||||
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
true
|
||||
|
|
|
@ -16,6 +16,7 @@ describe 'aws-ha-release' do
|
|||
|
||||
before do
|
||||
AWS::AutoScaling.stub(:new).and_return(as)
|
||||
IO.any_instance.stub(:puts)
|
||||
end
|
||||
|
||||
describe '#initialize' do
|
||||
|
@ -41,10 +42,12 @@ describe 'aws-ha-release' do
|
|||
|
||||
it 'suspends certain autoscaling processes' do
|
||||
AWS::FakeAutoScaling::Group.any_instance.should_receive(:suspend_processes)
|
||||
.with('ReplaceUnhealthy', 'AlarmNotification', 'ScheduledActions', 'AZRebalance')
|
||||
.with(%w(ReplaceUnhealthy AlarmNotification ScheduledActions AZRebalance))
|
||||
@aws_ha_release.execute!
|
||||
end
|
||||
|
||||
it 'requires certain autoscaling processes to not be suspended'
|
||||
|
||||
it 'adjusts the max size as well as the desired capacity if the desired capacity is equal to it' do
|
||||
@group.update(max_size: 1, desired_capacity: 1)
|
||||
|
||||
|
|
|
@ -9,6 +9,10 @@ module AWS
|
|||
|
||||
def terminate(decrement_desired_capacity)
|
||||
end
|
||||
|
||||
def id
|
||||
'i-test'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,7 +4,10 @@ module AWS
|
|||
end
|
||||
|
||||
class LoadBalancer
|
||||
attr_reader :name
|
||||
|
||||
def initialize(name, options = {})
|
||||
@name = name
|
||||
end
|
||||
|
||||
def instances
|
||||
|
|
Loading…
Reference in New Issue
Block a user