Class: Tapjoy::AutoscalingBootstrap::Autoscaling::Group
- Inherits:
-
Object
- Object
- Tapjoy::AutoscalingBootstrap::Autoscaling::Group
- Defined in:
- lib/tapjoy/autoscaling_bootstrap/autoscaling/group.rb
Overview
Class for Autoscaling groups
Instance Method Summary collapse
-
#create(config:, aws_env:, user_data:) ⇒ Object
Create autoscaling group.
-
#encode_user_data(user_data) ⇒ Object
Encode user data into required base64 form.
-
#exists ⇒ Object
Check if autoscale group exists.
-
#generate_tags(tags) ⇒ Object
Create tags array to pass to autoscaling group.
-
#initialize ⇒ Group
constructor
Initialize the class.
-
#scale(config) ⇒ Object
Scale auto scaling groups.
- #update(config:, aws_env:, user_data:) ⇒ Object
Constructor Details
#initialize ⇒ Group
Initialize the class
8 9 10 11 12 13 |
# File 'lib/tapjoy/autoscaling_bootstrap/autoscaling/group.rb', line 8 def initialize @scaler_name = Tapjoy::AutoscalingBootstrap.scaler_name @config_name = Tapjoy::AutoscalingBootstrap.config_name @elb_name = Tapjoy::AutoscalingBootstrap.elb_name @create_elb = Tapjoy::AutoscalingBootstrap.create_elb end |
Instance Method Details
#create(config:, aws_env:, user_data:) ⇒ Object
Create autoscaling group
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/tapjoy/autoscaling_bootstrap/autoscaling/group.rb', line 16 def create(config:, aws_env:, user_data:) if exists begin zero_autoscale_group rescue Aws::AutoScaling::Errors::ValidationError => err abort("Cannot remove existing AS group #{@scaler_name}. Error: #{err}") end else "Scaling group #{@scaler_name} does not exist, continuing..." end Tapjoy::AutoscalingBootstrap.config.create(config, aws_env, user_data) puts "Creating scaling group: #{@scaler_name}" Tapjoy::AutoscalingBootstrap::AWS::Autoscaling::Group.create(**config) end |
#encode_user_data(user_data) ⇒ Object
Encode user data into required base64 form
51 52 53 |
# File 'lib/tapjoy/autoscaling_bootstrap/autoscaling/group.rb', line 51 def encode_user_data(user_data) Base64.encode64("#{user_data}") end |
#exists ⇒ Object
Check if autoscale group exists
46 47 48 |
# File 'lib/tapjoy/autoscaling_bootstrap/autoscaling/group.rb', line 46 def exists Tapjoy::AutoscalingBootstrap::AWS::Autoscaling::Group.describe.nil? ? false : true end |
#generate_tags(tags) ⇒ Object
Create tags array to pass to autoscaling group
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/tapjoy/autoscaling_bootstrap/autoscaling/group.rb', line 56 def () tag_array = Array.new return [] if .nil? || .empty? .each do |t| return [] if t.nil? t.each_pair do |key, value| tag_array << { resource_id: @scaler_name, resource_type: 'auto-scaling-group', key: key.to_s, value: value, propagate_at_launch: true, } end end tag_array end |
#scale(config) ⇒ Object
Scale auto scaling groups
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/tapjoy/autoscaling_bootstrap/autoscaling/group.rb', line 75 def scale(config) if config[:scaling_type].eql?('dynamic') Tapjoy::AutoscalingBootstrap::AWS::Autoscaling::Group.resize( **config[:instance_counts]) elsif config[:scaling_type].eql?('static') scale_static(config) else abort('Unknown scaling type') end end |
#update(config:, aws_env:, user_data:) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/tapjoy/autoscaling_bootstrap/autoscaling/group.rb', line 34 def update(config:, aws_env:, user_data:) if exists puts "Updating launch config for scaling group: #{@scaler_name}" Tapjoy::AutoscalingBootstrap::LaunchConfiguration.new(config, aws_env, user_data) Tapjoy::AutoscalingBootstrap::AWS::Autoscaling::Group.update_launch_config(@scaler_name) # increment_autoscale_group else abort("Scaling group \"#{@scaler_name}\" doesn't exist, and therefore cannot be updated.") end end |