add print statements so user is aware of what is happening

This commit is contained in:
Anuj Biyani 2013-06-03 19:08:56 -07:00
parent 07fc0390f7
commit 8c24fa8dbf
4 changed files with 51 additions and 9 deletions

View File

@ -16,33 +16,61 @@ class AwsHaRelease
@max_size_change = 0 @max_size_change = 0
@inservice_polling_time = 10 @inservice_polling_time = 10
@opts = opts @opts = opts
@processes_to_suspend = %w(ReplaceUnhealthy AlarmNotification ScheduledActions AZRebalance)
end end
def execute! def execute!
@group.suspend_processes 'ReplaceUnhealthy', 'AlarmNotification', 'ScheduledActions', 'AZRebalance' @group.suspend_processes @processes_to_suspend
if @group.max_size == @group.desired_capacity 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) @group.update(max_size: @group.max_size + 1)
@max_size_change = 1 @max_size_change = 1
end end
@group.update(desired_capacity: @group.desired_capacity + 1) @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| @group.ec2_instances.each do |instance|
Timeout::timeout(@opts[:inservice_time_allowed]) do time_taken = 0
until all_instances_inservice?(@group.load_balancers)
sleep @inservice_polling_time 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 end
deregister_instance instance, @group.load_balancers raise
sleep @opts[:elb_timeout]
instance.terminate false
end end
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) @group.update(desired_capacity: @group.desired_capacity - 1)
if @max_size_change > 0 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) @group.update(max_size: @group.max_size - @max_size_change)
@max_size_change = 0 @max_size_change = 0
end end
@ -58,7 +86,11 @@ class AwsHaRelease
def instances_inservice?(load_balancer) def instances_inservice?(load_balancer)
load_balancer.instances.health.each do |health| 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 end
true true

View File

@ -16,6 +16,7 @@ describe 'aws-ha-release' do
before do before do
AWS::AutoScaling.stub(:new).and_return(as) AWS::AutoScaling.stub(:new).and_return(as)
IO.any_instance.stub(:puts)
end end
describe '#initialize' do describe '#initialize' do
@ -41,10 +42,12 @@ describe 'aws-ha-release' do
it 'suspends certain autoscaling processes' do it 'suspends certain autoscaling processes' do
AWS::FakeAutoScaling::Group.any_instance.should_receive(:suspend_processes) AWS::FakeAutoScaling::Group.any_instance.should_receive(:suspend_processes)
.with('ReplaceUnhealthy', 'AlarmNotification', 'ScheduledActions', 'AZRebalance') .with(%w(ReplaceUnhealthy AlarmNotification ScheduledActions AZRebalance))
@aws_ha_release.execute! @aws_ha_release.execute!
end 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 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) @group.update(max_size: 1, desired_capacity: 1)

View File

@ -9,6 +9,10 @@ module AWS
def terminate(decrement_desired_capacity) def terminate(decrement_desired_capacity)
end end
def id
'i-test'
end
end end
end end
end end

View File

@ -4,7 +4,10 @@ module AWS
end end
class LoadBalancer class LoadBalancer
attr_reader :name
def initialize(name, options = {}) def initialize(name, options = {})
@name = name
end end
def instances def instances