Class: EcsDeploy::AutoScaler::AutoScalingGroupConfig
- Inherits:
-
Struct
- Object
- Struct
- EcsDeploy::AutoScaler::AutoScalingGroupConfig
- Includes:
- ConfigBase
- Defined in:
- lib/ecs_deploy/auto_scaler/auto_scaling_group_config.rb
Constant Summary collapse
- MAX_DETACHABLE_INSTANCE_COUNT =
20
Instance Attribute Summary collapse
-
#buffer ⇒ Object
Returns the value of attribute buffer.
-
#cluster ⇒ Object
Returns the value of attribute cluster.
-
#disable_draining ⇒ Object
Returns the value of attribute disable_draining.
-
#name ⇒ Object
Returns the value of attribute name.
-
#region ⇒ Object
Returns the value of attribute region.
-
#service_configs ⇒ Object
Returns the value of attribute service_configs.
Instance Method Summary collapse
- #cluster_resource_manager ⇒ Object
- #detach_instances(instance_ids:, should_decrement_desired_capacity:) ⇒ Object
-
#initialize(attributes = {}, logger) ⇒ AutoScalingGroupConfig
constructor
A new instance of AutoScalingGroupConfig.
- #update_desired_capacity(required_capacity) ⇒ Object
Methods included from ConfigBase
Constructor Details
#initialize(attributes = {}, logger) ⇒ AutoScalingGroupConfig
Returns a new instance of AutoScalingGroupConfig.
15 16 17 18 19 20 21 22 |
# File 'lib/ecs_deploy/auto_scaler/auto_scaling_group_config.rb', line 15 def initialize(attributes = {}, logger) attributes = attributes.dup services = attributes.delete("services") super(attributes, logger) self.service_configs = services.map do |s| ServiceConfig.new(s.merge("cluster" => cluster, "region" => region), logger) end end |
Instance Attribute Details
#buffer ⇒ Object
Returns the value of attribute buffer
10 11 12 |
# File 'lib/ecs_deploy/auto_scaler/auto_scaling_group_config.rb', line 10 def buffer @buffer end |
#cluster ⇒ Object
Returns the value of attribute cluster
10 11 12 |
# File 'lib/ecs_deploy/auto_scaler/auto_scaling_group_config.rb', line 10 def cluster @cluster end |
#disable_draining ⇒ Object
Returns the value of attribute disable_draining
10 11 12 |
# File 'lib/ecs_deploy/auto_scaler/auto_scaling_group_config.rb', line 10 def disable_draining @disable_draining end |
#name ⇒ Object
Returns the value of attribute name
10 11 12 |
# File 'lib/ecs_deploy/auto_scaler/auto_scaling_group_config.rb', line 10 def name @name end |
#region ⇒ Object
Returns the value of attribute region
10 11 12 |
# File 'lib/ecs_deploy/auto_scaler/auto_scaling_group_config.rb', line 10 def region @region end |
#service_configs ⇒ Object
Returns the value of attribute service_configs
10 11 12 |
# File 'lib/ecs_deploy/auto_scaler/auto_scaling_group_config.rb', line 10 def service_configs @service_configs end |
Instance Method Details
#cluster_resource_manager ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/ecs_deploy/auto_scaler/auto_scaling_group_config.rb', line 56 def cluster_resource_manager @cluster_resource_manager ||= EcsDeploy::AutoScaler::ClusterResourceManager.new( region: region, cluster: cluster, service_configs: service_configs, capacity_based_on: "instances", logger: @logger, ) end |
#detach_instances(instance_ids:, should_decrement_desired_capacity:) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/ecs_deploy/auto_scaler/auto_scaling_group_config.rb', line 66 def detach_instances(instance_ids:, should_decrement_desired_capacity:) return if instance_ids.empty? instance_ids.each_slice(MAX_DETACHABLE_INSTANCE_COUNT) do |ids| client.detach_instances( auto_scaling_group_name: name, instance_ids: ids, should_decrement_desired_capacity: should_decrement_desired_capacity, ) end @logger.info "#{log_prefix} Detached instances from ASG: #{instance_ids.inspect}" end |
#update_desired_capacity(required_capacity) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ecs_deploy/auto_scaler/auto_scaling_group_config.rb', line 24 def update_desired_capacity(required_capacity) detach_and_terminate_orphan_instances desired_capacity = (required_capacity + buffer.to_f).ceil current_asg = client.describe_auto_scaling_groups({ auto_scaling_group_names: [name], }).auto_scaling_groups[0] if current_asg.desired_capacity > desired_capacity decreased_capacity = decrease_desired_capacity(current_asg.desired_capacity - desired_capacity) if decreased_capacity > 0 new_desired_capacity = current_asg.desired_capacity - decreased_capacity cluster_resource_manager.trigger_capacity_update(current_asg.desired_capacity, new_desired_capacity) @logger.info "#{log_prefix} Updated desired_capacity to #{new_desired_capacity}" else @logger.info "#{log_prefix} Tried to Update desired_capacity but there were no deregisterable instances" end elsif current_asg.desired_capacity < desired_capacity client.update_auto_scaling_group( auto_scaling_group_name: name, min_size: 0, max_size: [current_asg.max_size, desired_capacity].max, desired_capacity: desired_capacity, ) cluster_resource_manager.trigger_capacity_update(current_asg.desired_capacity, desired_capacity) @logger.info "#{log_prefix} Updated desired_capacity to #{desired_capacity}" end rescue => e AutoScaler.error_logger.error(e) end |