Class: Rollo::Commands::Hosts
- Inherits:
-
Thor
- Object
- Thor
- Rollo::Commands::Hosts
- Defined in:
- lib/rollo/commands/hosts.rb
Overview
rubocop:disable Metrics/ClassLength
Class Method Summary collapse
Instance Method Summary collapse
-
#contract(region, asg_name, ecs_cluster_name, host_cluster = nil, service_cluster = nil) ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength.
-
#expand(region, asg_name, _, host_cluster = nil) ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength.
-
#terminate(region, asg_name, ecs_cluster_name, instance_ids, host_cluster = nil, service_cluster = nil) ⇒ Object
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize rubocop:disable Metrics/ParameterLists.
Class Method Details
.exit_on_failure? ⇒ Boolean
12 13 14 |
# File 'lib/rollo/commands/hosts.rb', line 12 def self.exit_on_failure? true end |
Instance Method Details
#contract(region, asg_name, ecs_cluster_name, host_cluster = nil, service_cluster = nil) ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/rollo/commands/hosts.rb', line 82 def contract( region, asg_name, ecs_cluster_name, host_cluster = nil, service_cluster = nil ) batch_size = [:batch_size] host_cluster ||= Rollo::Model::HostCluster.new(asg_name, region) service_cluster ||= Rollo::Model::ServiceCluster.new( ecs_cluster_name, region ) say("Decreasing host cluster desired capacity by #{batch_size}...") # rubocop:disable Metrics/BlockLength with_padding do host_cluster.decrease_capacity_by(batch_size) do |on| on.prepare do |current, target| say( "Changing desired capacity from #{current} to " \ "#{target}..." ) end on.waiting_for_start do |attempt| say( 'Waiting for capacity change to start ' \ "(attempt #{attempt})..." ) end on.waiting_for_end do |attempt| say( 'Waiting for capacity change to complete ' \ "(attempt #{attempt})..." ) end on.waiting_for_health do |attempt| say( 'Waiting for host cluster to reach healthy state ' \ "(attempt #{attempt})..." ) end end service_cluster.with_replica_services do |services| services.each_service do |service| service.wait_for_service_health do |on| on.waiting_for_health do |attempt| say( "Waiting for service #{service.name} to reach a " \ "steady state (attempt #{attempt})..." ) end end end end end # rubocop:enable Metrics/BlockLength say 'Host cluster desired capacity decreased, continuing...' end |
#expand(region, asg_name, _, host_cluster = nil) ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength
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 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/rollo/commands/hosts.rb', line 29 def ( region, asg_name, _, host_cluster = nil ) batch_size = [:batch_size] host_cluster ||= Rollo::Model::HostCluster.new(asg_name, region) say("Increasing host cluster desired capacity by #{batch_size}...") with_padding do host_cluster.increase_capacity_by(batch_size) do |on| on.prepare do |current, target| say( "Changing desired capacity from #{current} to " \ "#{target}..." ) end on.waiting_for_start do |attempt| say( 'Waiting for capacity change to start ' \ "(attempt #{attempt})..." ) end on.waiting_for_end do |attempt| say( 'Waiting for capacity change to complete ' \ "(attempt #{attempt})..." ) end on.waiting_for_health do |attempt| say("Waiting for a healthy state (attempt #{attempt})") end end end say 'Host cluster desired capacity increased, continuing...' end |
#terminate(region, asg_name, ecs_cluster_name, instance_ids, host_cluster = nil, service_cluster = nil) ⇒ Object
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize rubocop:disable Metrics/ParameterLists
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/rollo/commands/hosts.rb', line 163 def terminate( region, asg_name, ecs_cluster_name, instance_ids, host_cluster = nil, service_cluster = nil ) batch_size = [:batch_size] service_start_wait_minutes = [:startup_time] service_start_wait_seconds = 60 * service_start_wait_minutes host_cluster ||= Rollo::Model::HostCluster.new(asg_name, region) service_cluster ||= Rollo::Model::ServiceCluster.new(ecs_cluster_name, region) hosts = host_cluster.hosts.select { |h| instance_ids.include?(h.id) } host_batches = hosts.each_slice(batch_size).to_a say( 'Terminating old hosts in host cluster in batches of ' \ "#{batch_size}..." ) # rubocop:disable Metrics/BlockLength with_padding do host_batches.each_with_index do |host_batch, index| say( "Batch #{index + 1} contains hosts: " \ "\n\t\t[#{host_batch.map(&:id).join(",\n\t\t ")}]\n" \ 'Terminating...' ) host_batch.each(&:terminate) host_cluster.wait_for_capacity_health do |on| on.waiting_for_health do |attempt| say( 'Waiting for host cluster to reach healthy state ' \ "(attempt #{attempt})" ) end end service_cluster.with_replica_services do |services| services.each_service do |service| service.wait_for_service_health do |on| on.waiting_for_health do |attempt| say( "Waiting for service #{service.name} to reach a " \ "steady state (attempt #{attempt})..." ) end end end end say( "Waiting #{service_start_wait_minutes} minute(s) for " \ 'services to finish starting...' ) sleep(service_start_wait_seconds) say( "Waited #{service_start_wait_minutes} minute(s). " \ 'Continuing...' ) end end # rubocop:enable Metrics/BlockLength end |