class Asg::Rebooter::Wrappers::TargetGroup

Constants

POLL_TIMEOUT
TARGET_GROUP_INSTANCE_HEALTHY

Attributes

arn[R]

Public Class Methods

new(arn) click to toggle source
# File lib/asg/rebooter/wrappers/target_group.rb, line 12
def initialize(arn)
  raise TargetGroupArnRequiredError unless arn

  @arn = arn
end

Public Instance Methods

attributes() click to toggle source
# File lib/asg/rebooter/wrappers/target_group.rb, line 18
def attributes
  target_group_attributes = client.describe_target_group_attributes(target_group_arn: arn)
  target_group_attributes.attributes.map(&:to_hash)
end
health_for_instance(instance) click to toggle source
# File lib/asg/rebooter/wrappers/target_group.rb, line 37
def health_for_instance(instance)
  #
  # TODO: Write specs and error handling
  #
  health_description_for_instance = target_health_descriptions.keep_if do |target_health_description|
    target_health_description.target.id == instance.id
  end

  if health_description_for_instance.any?
    health_description_for_instance.first.target_health.state
  else
    'unknown'
  end
end
restore_attributes() click to toggle source
# File lib/asg/rebooter/wrappers/target_group.rb, line 23
def restore_attributes
  update_attributes(original_attributes)
end
target_health_descriptions() click to toggle source
# File lib/asg/rebooter/wrappers/target_group.rb, line 33
def target_health_descriptions
  client.describe_target_health(target_group_arn: arn).target_health_descriptions
end
update_attributes(attributes_to_update) click to toggle source
# File lib/asg/rebooter/wrappers/target_group.rb, line 27
def update_attributes(attributes_to_update)
  client.modify_target_group_attributes \
    target_group_arn: arn,
    attributes: attributes_to_update
end
wait_for_healthy(instance) click to toggle source
# File lib/asg/rebooter/wrappers/target_group.rb, line 52
def wait_for_healthy(instance)
  loop do
    healthy = health_for_instance(instance) == TARGET_GROUP_INSTANCE_HEALTHY

    break if healthy

    sleep(POLL_TIMEOUT)
  end

  true
end

Private Instance Methods

client() click to toggle source
# File lib/asg/rebooter/wrappers/target_group.rb, line 66
def client
  @client ||= Aws::ElasticLoadBalancingV2::Client.new
end