hako 0.14.0 → 0.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/hako/schedulers/ecs.rb +47 -32
- data/lib/hako/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b73b66a504c37b90e3234870e6333263e7abfc8c
|
4
|
+
data.tar.gz: 1de7e857c4c8f40c275f72bd1822e211521d447b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 805980ec90386912e4e69423820f6a224203c52cf06210f67c677c41ecfe181db3285597a6749703e8d73fdff18235352d868d416f182e8e01ca2b85db5d1888
|
7
|
+
data.tar.gz: 01adc0732edc57ebab0304b4f2e95aa4f753038a6ac162def04688f7f8fb57c905948450ac50847b88f12abc190a19452e3b8e68a13a7603610fbb05320bd4fa
|
data/lib/hako/schedulers/ecs.rb
CHANGED
@@ -17,11 +17,9 @@ module Hako
|
|
17
17
|
def configure(options)
|
18
18
|
@cluster = options.fetch('cluster', DEFAULT_CLUSTER)
|
19
19
|
@desired_count = options.fetch('desired_count', nil)
|
20
|
-
region = options.fetch('region') { validation_error!('region must be set') }
|
20
|
+
@region = options.fetch('region') { validation_error!('region must be set') }
|
21
21
|
@role = options.fetch('role', nil)
|
22
|
-
@
|
23
|
-
@elb = EcsElb.new(@app_id, Aws::ElasticLoadBalancing::Client.new(region: region), options.fetch('elb', nil))
|
24
|
-
@ec2 = Aws::EC2::Client.new(region: region)
|
22
|
+
@ecs_elb_options = options.fetch('elb', nil)
|
25
23
|
@started_at = nil
|
26
24
|
@container_instance_arn = nil
|
27
25
|
end
|
@@ -44,7 +42,7 @@ module Hako
|
|
44
42
|
task_definition = register_task_definition(definitions)
|
45
43
|
if task_definition == :noop
|
46
44
|
Hako.logger.info "Task definition isn't changed"
|
47
|
-
task_definition =
|
45
|
+
task_definition = ecs_client.describe_task_definition(task_definition: @app_id).task_definition
|
48
46
|
else
|
49
47
|
Hako.logger.info "Registered task definition: #{task_definition.task_definition_arn}"
|
50
48
|
end
|
@@ -82,7 +80,7 @@ module Hako
|
|
82
80
|
task_definition = register_task_definition_for_oneshot(definitions)
|
83
81
|
if task_definition == :noop
|
84
82
|
Hako.logger.info "Task definition isn't changed"
|
85
|
-
task_definition =
|
83
|
+
task_definition = ecs_client.describe_task_definition(task_definition: "#{@app_id}-oneshot").task_definition
|
86
84
|
else
|
87
85
|
Hako.logger.info "Registered task definition: #{task_definition.task_definition_arn}"
|
88
86
|
end
|
@@ -97,7 +95,7 @@ module Hako
|
|
97
95
|
def stop_oneshot
|
98
96
|
if @task
|
99
97
|
Hako.logger.warn "Stopping #{@task.task_arn}"
|
100
|
-
|
98
|
+
ecs_client.stop_task(cluster: @cluster, task: @task.task_arn, reason: 'Stopped by hako stop_oneshot')
|
101
99
|
wait_for_oneshot_finish
|
102
100
|
end
|
103
101
|
end
|
@@ -112,7 +110,7 @@ module Hako
|
|
112
110
|
|
113
111
|
unless service.load_balancers.empty?
|
114
112
|
lb = service.load_balancers[0]
|
115
|
-
lb_detail =
|
113
|
+
lb_detail = ecs_elb_client.describe_load_balancer
|
116
114
|
puts 'Load balancer:'
|
117
115
|
lb_detail.listener_descriptions.each do |ld|
|
118
116
|
l = ld.listener
|
@@ -127,15 +125,15 @@ module Hako
|
|
127
125
|
end
|
128
126
|
|
129
127
|
puts 'Tasks:'
|
130
|
-
|
128
|
+
ecs_client.list_tasks(cluster: @cluster, service_name: service.service_arn).each do |page|
|
131
129
|
unless page.task_arns.empty?
|
132
|
-
tasks =
|
130
|
+
tasks = ecs_client.describe_tasks(cluster: @cluster, tasks: page.task_arns).tasks
|
133
131
|
container_instances = {}
|
134
|
-
|
132
|
+
ecs_client.describe_container_instances(cluster: @cluster, container_instances: tasks.map(&:container_instance_arn)).container_instances.each do |ci|
|
135
133
|
container_instances[ci.container_instance_arn] = ci
|
136
134
|
end
|
137
135
|
ec2_instances = {}
|
138
|
-
|
136
|
+
ec2_client.describe_instances(instance_ids: container_instances.values.map(&:ec2_instance_id)).reservations.each do |r|
|
139
137
|
r.instances.each do |i|
|
140
138
|
ec2_instances[i.instance_id] = i
|
141
139
|
end
|
@@ -165,20 +163,35 @@ module Hako
|
|
165
163
|
def remove
|
166
164
|
service = describe_service
|
167
165
|
if service
|
168
|
-
|
166
|
+
ecs_client.delete_service(cluster: @cluster, service: @app_id)
|
169
167
|
Hako.logger.info "#{service.service_arn} is deleted"
|
170
168
|
else
|
171
169
|
puts "Service #{@app_id} doesn't exist"
|
172
170
|
end
|
173
171
|
|
174
|
-
|
172
|
+
ecs_elb_client.destroy
|
175
173
|
end
|
176
174
|
|
177
175
|
private
|
178
176
|
|
177
|
+
# @return [Aws::ECS::Client]
|
178
|
+
def ecs_client
|
179
|
+
@ecs_client ||= Aws::ECS::Client.new(region: @region)
|
180
|
+
end
|
181
|
+
|
182
|
+
# @return [Aws::EC2::Client]
|
183
|
+
def ec2_client
|
184
|
+
@ec2_client ||= Aws::EC2::Client.new(region: @region)
|
185
|
+
end
|
186
|
+
|
187
|
+
# @return [EcsElb]
|
188
|
+
def ecs_elb_client
|
189
|
+
@ecs_elb_client ||= EcsElb.new(@app_id, Aws::ElasticLoadBalancing::Client.new(region: @region), @ecs_elb_options)
|
190
|
+
end
|
191
|
+
|
179
192
|
# @return [Aws::ECS::Types::Service, nil]
|
180
193
|
def describe_service
|
181
|
-
service =
|
194
|
+
service = ecs_client.describe_services(cluster: @cluster, services: [@app_id]).services[0]
|
182
195
|
if service && service.status != 'INACTIVE'
|
183
196
|
service
|
184
197
|
end
|
@@ -200,9 +213,9 @@ module Hako
|
|
200
213
|
# @return [Fixnum]
|
201
214
|
def new_front_port
|
202
215
|
max_port = -1
|
203
|
-
|
216
|
+
ecs_client.list_services(cluster: @cluster).each do |page|
|
204
217
|
unless page.service_arns.empty?
|
205
|
-
|
218
|
+
ecs_client.describe_services(cluster: @cluster, services: page.service_arns).services.each do |s|
|
206
219
|
if s.status != 'INACTIVE'
|
207
220
|
port = find_front_port(s)
|
208
221
|
if port
|
@@ -222,7 +235,7 @@ module Hako
|
|
222
235
|
# @param [Aws::ECS::Types::Service] service
|
223
236
|
# @return [Fixnum, nil]
|
224
237
|
def find_front_port(service)
|
225
|
-
task_definition =
|
238
|
+
task_definition = ecs_client.describe_task_definition(task_definition: service.task_definition).task_definition
|
226
239
|
container_definitions = {}
|
227
240
|
task_definition.container_definitions.each do |c|
|
228
241
|
container_definitions[c.name] = c
|
@@ -239,7 +252,7 @@ module Hako
|
|
239
252
|
if @force
|
240
253
|
return true
|
241
254
|
end
|
242
|
-
task_definition =
|
255
|
+
task_definition = ecs_client.describe_task_definition(task_definition: family).task_definition
|
243
256
|
container_definitions = {}
|
244
257
|
task_definition.container_definitions.each do |c|
|
245
258
|
container_definitions[c.name] = c
|
@@ -287,7 +300,7 @@ module Hako
|
|
287
300
|
# @return [Aws::ECS::Types::TaskDefinition, Symbol]
|
288
301
|
def register_task_definition(definitions)
|
289
302
|
if task_definition_changed?(@app_id, definitions)
|
290
|
-
|
303
|
+
ecs_client.register_task_definition(
|
291
304
|
family: @app_id,
|
292
305
|
container_definitions: definitions,
|
293
306
|
volumes: volumes_definition,
|
@@ -310,7 +323,7 @@ module Hako
|
|
310
323
|
def register_task_definition_for_oneshot(definitions)
|
311
324
|
family = "#{@app_id}-oneshot"
|
312
325
|
if task_definition_changed?(family, definitions)
|
313
|
-
|
326
|
+
ecs_client.register_task_definition(
|
314
327
|
family: "#{@app_id}-oneshot",
|
315
328
|
container_definitions: definitions,
|
316
329
|
volumes: volumes_definition,
|
@@ -355,7 +368,7 @@ module Hako
|
|
355
368
|
# @return [Aws::ECS::Types::Task]
|
356
369
|
def run_task(task_definition, commands, env)
|
357
370
|
environment = env.map { |k, v| { name: k, value: v } }
|
358
|
-
|
371
|
+
ecs_client.run_task(
|
359
372
|
cluster: @cluster,
|
360
373
|
task_definition: task_definition.task_definition_arn,
|
361
374
|
overrides: {
|
@@ -396,7 +409,7 @@ module Hako
|
|
396
409
|
def wait_for_task(task)
|
397
410
|
task_arn = task.task_arn
|
398
411
|
loop do
|
399
|
-
task =
|
412
|
+
task = ecs_client.describe_tasks(cluster: @cluster, tasks: [task_arn]).tasks[0]
|
400
413
|
if task.nil?
|
401
414
|
Hako.logger.debug "Task #{task_arn} could not be described"
|
402
415
|
sleep 1
|
@@ -431,8 +444,8 @@ module Hako
|
|
431
444
|
# @param [String] container_instance_arn
|
432
445
|
# @return [nil]
|
433
446
|
def report_container_instance(container_instance_arn)
|
434
|
-
container_instance =
|
435
|
-
|
447
|
+
container_instance = ecs_client.describe_container_instances(cluster: @cluster, container_instances: [container_instance_arn]).container_instances[0]
|
448
|
+
ec2_client.describe_tags(filters: [{ name: 'resource-id', values: [container_instance.ec2_instance_id] }]).each do |page|
|
436
449
|
tag = page.tags.find { |t| t.key == 'Name' }
|
437
450
|
if tag
|
438
451
|
Hako.logger.info "Container instance is #{container_instance_arn} (#{tag.value} #{container_instance.ec2_instance_id})"
|
@@ -455,7 +468,7 @@ module Hako
|
|
455
468
|
desired_count: @desired_count,
|
456
469
|
role: @role,
|
457
470
|
}
|
458
|
-
name =
|
471
|
+
name = ecs_elb_client.find_or_create_load_balancer(front_port)
|
459
472
|
if name
|
460
473
|
params[:load_balancers] = [
|
461
474
|
{
|
@@ -465,7 +478,7 @@ module Hako
|
|
465
478
|
},
|
466
479
|
]
|
467
480
|
end
|
468
|
-
|
481
|
+
ecs_client.create_service(params).service
|
469
482
|
else
|
470
483
|
params = {
|
471
484
|
cluster: @cluster,
|
@@ -474,7 +487,7 @@ module Hako
|
|
474
487
|
task_definition: task_definition_arn,
|
475
488
|
}
|
476
489
|
if service_changed?(service, params)
|
477
|
-
|
490
|
+
ecs_client.update_service(params).service
|
478
491
|
else
|
479
492
|
:noop
|
480
493
|
end
|
@@ -501,7 +514,7 @@ module Hako
|
|
501
514
|
latest_event_id = find_latest_event_id(service.events)
|
502
515
|
Hako.logger.debug " latest_event_id=#{latest_event_id}"
|
503
516
|
loop do
|
504
|
-
s =
|
517
|
+
s = ecs_client.describe_services(cluster: service.cluster_arn, services: [service.service_arn]).services[0]
|
505
518
|
s.events.each do |e|
|
506
519
|
if e.id == latest_event_id
|
507
520
|
break
|
@@ -509,9 +522,11 @@ module Hako
|
|
509
522
|
Hako.logger.info "#{e.created_at}: #{e.message}"
|
510
523
|
end
|
511
524
|
latest_event_id = find_latest_event_id(s.events)
|
512
|
-
|
513
|
-
|
514
|
-
|
525
|
+
Hako.logger.debug " latest_event_id=#{latest_event_id}, deployments=#{s.deployments}"
|
526
|
+
no_active = s.deployments.all? { |d| d.status != 'ACTIVE' }
|
527
|
+
primary = s.deployments.find { |d| d.status == 'PRIMARY' }
|
528
|
+
primary_ready = primary && primary.running_count == primary.desired_count
|
529
|
+
if no_active && primary_ready
|
515
530
|
return
|
516
531
|
else
|
517
532
|
sleep 1
|
data/lib/hako/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hako
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.14.
|
4
|
+
version: 0.14.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kohei Suzuki
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|