Class: Hako::Schedulers::EcsAutoscaling::Policy

Inherits:
Object
  • Object
show all
Defined in:
lib/hako/schedulers/ecs_autoscaling.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Policy

Returns a new instance of Policy.

Parameters:

  • options (Hash)


170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/hako/schedulers/ecs_autoscaling.rb', line 170

def initialize(options)
  @policy_type = options.fetch('policy_type', 'StepScaling')
  case @policy_type
  when 'StepScaling'
    @alarms = required_option(options, 'alarms')
    @cooldown = required_option(options, 'cooldown')
    @adjustment_type = required_option(options, 'adjustment_type')
    @scaling_adjustment = required_option(options, 'scaling_adjustment')
    @metric_interval_lower_bound = options.fetch('metric_interval_lower_bound', nil)
    @metric_interval_upper_bound = options.fetch('metric_interval_upper_bound', nil)
    @metric_aggregation_type = required_option(options, 'metric_aggregation_type')
  when 'TargetTrackingScaling'
    @name = required_option(options, 'name')
    @target_value = required_option(options, 'target_value')
    @predefined_metric_type = required_option(options, 'predefined_metric_type')
    @scale_out_cooldown = options.fetch('scale_out_cooldown', nil)
    @scale_in_cooldown = options.fetch('scale_in_cooldown', nil)
    @disable_scale_in = options.fetch('disable_scale_in', nil)
  else
    raise Error.new("scheduler.autoscaling.policies.#{policy_type} must be either 'StepScaling' or 'TargetTrackingScaling'")
  end
end

Instance Attribute Details

#adjustment_typeObject (readonly)

Returns the value of attribute adjustment_type.



166
167
168
# File 'lib/hako/schedulers/ecs_autoscaling.rb', line 166

def adjustment_type
  @adjustment_type
end

#alarmsObject (readonly)

Returns the value of attribute alarms.



166
167
168
# File 'lib/hako/schedulers/ecs_autoscaling.rb', line 166

def alarms
  @alarms
end

#cooldownObject (readonly)

Returns the value of attribute cooldown.



166
167
168
# File 'lib/hako/schedulers/ecs_autoscaling.rb', line 166

def cooldown
  @cooldown
end

#disable_scale_inObject (readonly)

Returns the value of attribute disable_scale_in.



167
168
169
# File 'lib/hako/schedulers/ecs_autoscaling.rb', line 167

def disable_scale_in
  @disable_scale_in
end

#metric_aggregation_typeObject (readonly)

Returns the value of attribute metric_aggregation_type.



166
167
168
# File 'lib/hako/schedulers/ecs_autoscaling.rb', line 166

def metric_aggregation_type
  @metric_aggregation_type
end

#metric_interval_lower_boundObject (readonly)

Returns the value of attribute metric_interval_lower_bound.



166
167
168
# File 'lib/hako/schedulers/ecs_autoscaling.rb', line 166

def metric_interval_lower_bound
  @metric_interval_lower_bound
end

#metric_interval_upper_boundObject (readonly)

Returns the value of attribute metric_interval_upper_bound.



166
167
168
# File 'lib/hako/schedulers/ecs_autoscaling.rb', line 166

def metric_interval_upper_bound
  @metric_interval_upper_bound
end

#policy_typeObject (readonly)

Returns the value of attribute policy_type.



165
166
167
# File 'lib/hako/schedulers/ecs_autoscaling.rb', line 165

def policy_type
  @policy_type
end

#predefined_metric_typeObject (readonly)

Returns the value of attribute predefined_metric_type.



167
168
169
# File 'lib/hako/schedulers/ecs_autoscaling.rb', line 167

def predefined_metric_type
  @predefined_metric_type
end

#scale_in_cooldownObject (readonly)

Returns the value of attribute scale_in_cooldown.



167
168
169
# File 'lib/hako/schedulers/ecs_autoscaling.rb', line 167

def scale_in_cooldown
  @scale_in_cooldown
end

#scale_out_cooldownObject (readonly)

Returns the value of attribute scale_out_cooldown.



167
168
169
# File 'lib/hako/schedulers/ecs_autoscaling.rb', line 167

def scale_out_cooldown
  @scale_out_cooldown
end

#scaling_adjustmentObject (readonly)

Returns the value of attribute scaling_adjustment.



166
167
168
# File 'lib/hako/schedulers/ecs_autoscaling.rb', line 166

def scaling_adjustment
  @scaling_adjustment
end

#target_valueObject (readonly)

Returns the value of attribute target_value.



167
168
169
# File 'lib/hako/schedulers/ecs_autoscaling.rb', line 167

def target_value
  @target_value
end

Instance Method Details

#nameString

Returns:

  • (String)


194
195
196
197
198
199
200
# File 'lib/hako/schedulers/ecs_autoscaling.rb', line 194

def name
  if policy_type == 'StepScaling'
    alarms.join('-and-')
  else
    @name
  end
end

#required_option(options, key) ⇒ Object (private)

Parameters:

  • options (Hash)
  • key (String)

Returns:

  • (Object)


207
208
209
# File 'lib/hako/schedulers/ecs_autoscaling.rb', line 207

def required_option(options, key)
  options.fetch(key) { raise Error.new("scheduler.autoscaling.policies.#{key} must be set") }
end