Class: Rollo::Commands::Hosts
- Inherits:
-
Thor
- Object
- Thor
- Rollo::Commands::Hosts
- Defined in:
- lib/rollo/commands/hosts.rb
Class Method Summary collapse
Instance Method Summary collapse
- #contract(region, asg_name, ecs_cluster_name, host_cluster = nil, service_cluster = nil) ⇒ Object
- #expand(region, asg_name, _, host_cluster = nil) ⇒ Object
- #terminate(region, asg_name, ecs_cluster_name, instance_ids, host_cluster = nil, service_cluster = nil) ⇒ Object
Class Method Details
.exit_on_failure? ⇒ Boolean
9 10 11 |
# File 'lib/rollo/commands/hosts.rb', line 9 def self.exit_on_failure? true end |
Instance Method Details
#contract(region, asg_name, ecs_cluster_name, host_cluster = nil, service_cluster = nil) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 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 |
# File 'lib/rollo/commands/hosts.rb', line 65 def contract( region, asg_name, ecs_cluster_name, host_cluster = nil, service_cluster = nil) batch_size = [:batch_size] host_cluster = host_cluster || Rollo::Model::HostCluster.new(asg_name, region) service_cluster = service_cluster || Rollo::Model::ServiceCluster.new(ecs_cluster_name, region) say("Decreasing host cluster desired capacity by #{batch_size}...") 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 |on| on.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 say "Host cluster desired capacity decreased, continuing..." end |
#expand(region, asg_name, _, host_cluster = nil) ⇒ Object
22 23 24 25 26 27 28 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 |
# File 'lib/rollo/commands/hosts.rb', line 22 def ( region, asg_name, _, host_cluster = nil) batch_size = [:batch_size] host_cluster = 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
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/rollo/commands/hosts.rb', line 129 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 = host_cluster || Rollo::Model::HostCluster.new(asg_name, region) service_cluster = 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}...") 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 |on| on.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 end |