Class: Tapjoy::AutoscalingBootstrap::ELB

Inherits:
Object
  • Object
show all
Defined in:
lib/tapjoy/autoscaling_bootstrap/elb.rb

Overview

This class configures elastic load balancers

Instance Method Summary collapse

Constructor Details

#initialize(elb_hash, clobber_elb, zones, security_groups) ⇒ ELB

Returns a new instance of ELB.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/tapjoy/autoscaling_bootstrap/elb.rb', line 5

def initialize(elb_hash, clobber_elb, zones, security_groups)
  elb_config = build_config(elb_hash, zones, security_groups)
  check_valid_config(elb_config)

  if exists && clobber_elb
    delete
    create(elb_config)
  elsif exists
    Tapjoy::AutoscalingBootstrap::AWS::Autoscaling::Group.attach_elb(
      Tapjoy::AutoscalingBootstrap.elb_name)
  else
    create(elb_config)
  end
end

Instance Method Details

#build_config(elb_hash, zones, security_groups) ⇒ Object

Build config hash



21
22
23
24
25
26
# File 'lib/tapjoy/autoscaling_bootstrap/elb.rb', line 21

def build_config(elb_hash, zones, security_groups)
  elb_config = elb_hash[Tapjoy::AutoscalingBootstrap.elb_name]
  elb_config[:elb_protocol] ||= elb_config[:instance_protocol]
  elb_config[:elb_health_target] ||= "#{elb_config[:instance_protocol]}:#{elb_config[:instance_port]}/healthz"
  elb_config.merge!({zones: zones, groups: security_groups})
end

#create(config) ⇒ Object

Create load balancer



29
30
31
32
# File 'lib/tapjoy/autoscaling_bootstrap/elb.rb', line 29

def create(config)
  Tapjoy::AutoscalingBootstrap::AWS::ELB.create(**config)
  health_check(config)
end

#deleteObject

Delete ELB



57
58
59
60
# File 'lib/tapjoy/autoscaling_bootstrap/elb.rb', line 57

def delete
  puts 'Removing existing ELB'
  Tapjoy::AutoscalingBootstrap::AWS::ELB.delete
end

#existsObject

Check if ELB exists



46
47
48
49
50
51
52
53
54
# File 'lib/tapjoy/autoscaling_bootstrap/elb.rb', line 46

def exists
  begin
    Tapjoy::AutoscalingBootstrap::AWS::ELB.describe
    return true
  rescue Aws::ElasticLoadBalancing::Errors::LoadBalancerNotFound => err
    STDERR.puts "Warning: #{err}"
    return false
  end
end

#health_check(config) ⇒ Object

Configure health check



35
36
37
38
39
40
41
42
43
# File 'lib/tapjoy/autoscaling_bootstrap/elb.rb', line 35

def health_check(config)
  abort('Target must be specified') if config[:elb_health_target].nil?

  begin
    Tapjoy::AutoscalingBootstrap::AWS::ELB.health_check(**config)
  rescue Aws::ElasticLoadBalancing::Errors::ValidationError => err
    abort("Fatal! Invalid ELB Configuration: #{err}")
  end
end