hako 0.20.3 → 0.21.0
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_definition_comparator.rb +51 -50
- data/lib/hako/schema.rb +9 -0
- data/lib/hako/schema/boolean.rb +14 -0
- data/lib/hako/schema/integer.rb +14 -0
- data/lib/hako/schema/nullable.rb +24 -0
- data/lib/hako/schema/ordered_array.rb +27 -0
- data/lib/hako/schema/string.rb +14 -0
- data/lib/hako/schema/structure.rb +35 -0
- data/lib/hako/schema/table.rb +33 -0
- data/lib/hako/schema/unordered_array.rb +32 -0
- data/lib/hako/version.rb +1 -1
- metadata +11 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c6e02b9939541f56711b9225a74381d7473376b
|
4
|
+
data.tar.gz: a43209df25791df32037b123f21255c8f4ed98d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a727aaff0caded43aeda3477d6f2819c44d9285e7f296c4d1eb4738ffab649326e966377c59c7cf1d1e932fe480465663387e1e14191cc5da8c652e223130a73
|
7
|
+
data.tar.gz: affac360aeef705b05799af8dbd66a9af5b093ab1f8847227c886bed2e52dce52bd02900c84d6c91f49b346b62dfdfda835b1d37c569e32aecacc8f605ba7d71
|
@@ -1,75 +1,76 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
require 'hako/schema'
|
3
|
+
|
2
4
|
module Hako
|
3
5
|
module Schedulers
|
4
6
|
class EcsDefinitionComparator
|
5
7
|
# @param [Hash] expected_container
|
6
8
|
def initialize(expected_container)
|
7
9
|
@expected_container = expected_container
|
10
|
+
@schema = definition_schema
|
8
11
|
end
|
9
12
|
|
10
|
-
CONTAINER_KEYS = %i[image cpu memory memory_reservation links docker_labels user log_configuration].freeze
|
11
|
-
PORT_MAPPING_KEYS = %i[container_port host_port protocol].freeze
|
12
|
-
ENVIRONMENT_KEYS = %i[name value].freeze
|
13
|
-
MOUNT_POINT_KEYS = %i[source_volume container_path read_only].freeze
|
14
|
-
VOLUMES_FROM_KEYS = %i[source_container read_only].freeze
|
15
|
-
|
16
13
|
# @param [Aws::ECS::Types::ContainerDefinition] actual_container
|
17
14
|
# @return [Boolean]
|
18
15
|
def different?(actual_container)
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
16
|
+
!@schema.same?(actual_container.to_h, @expected_container)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def definition_schema
|
22
|
+
Schema::Structure.new.tap do |struct|
|
23
|
+
struct.member(:image, Schema::String.new)
|
24
|
+
struct.member(:cpu, Schema::Integer.new)
|
25
|
+
struct.member(:memory, Schema::Integer.new)
|
26
|
+
struct.member(:memory_reservation, Schema::Nullable.new(Schema::Integer.new))
|
27
|
+
struct.member(:links, Schema::UnorderedArray.new(Schema::String.new))
|
28
|
+
struct.member(:port_mappings, Schema::UnorderedArray.new(port_mapping_schema))
|
29
|
+
struct.member(:environment, Schema::UnorderedArray.new(environment_schema))
|
30
|
+
struct.member(:docker_labels, Schema::Table.new(Schema::String.new, Schema::String.new))
|
31
|
+
struct.member(:mount_points, Schema::UnorderedArray.new(mount_point_schema))
|
32
|
+
struct.member(:command, Schema::Nullable.new(Schema::OrderedArray.new(Schema::String.new)))
|
33
|
+
struct.member(:volumes_from, Schema::UnorderedArray.new(volumes_from_schema))
|
34
|
+
struct.member(:user, Schema::Nullable.new(Schema::String.new))
|
35
|
+
struct.member(:log_configuration, Schema::Nullable.new(log_configuration_schema))
|
37
36
|
end
|
37
|
+
end
|
38
38
|
|
39
|
-
|
39
|
+
def port_mapping_schema
|
40
|
+
Schema::Structure.new.tap do |struct|
|
41
|
+
struct.member(:container_port, Schema::Integer.new)
|
42
|
+
struct.member(:host_port, Schema::Integer.new)
|
43
|
+
struct.member(:protocol, Schema::String.new)
|
44
|
+
end
|
40
45
|
end
|
41
46
|
|
42
|
-
|
47
|
+
def environment_schema
|
48
|
+
Schema::Structure.new.tap do |struct|
|
49
|
+
struct.member(:name, Schema::String.new)
|
50
|
+
struct.member(:value, Schema::String.new)
|
51
|
+
end
|
52
|
+
end
|
43
53
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
keys.each do |key|
|
50
|
-
if actual[key] != expected[key]
|
51
|
-
return true
|
52
|
-
end
|
54
|
+
def mount_point_schema
|
55
|
+
Schema::Structure.new.tap do |struct|
|
56
|
+
struct.member(:source_volume, Schema::String.new)
|
57
|
+
struct.member(:container_path, Schema::String.new)
|
58
|
+
struct.member(:read_only, Schema::Boolean.new)
|
53
59
|
end
|
54
|
-
false
|
55
60
|
end
|
56
61
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
def different_array?(expected, actual, key, keys)
|
62
|
-
if expected[key].size != actual[key].size
|
63
|
-
return true
|
62
|
+
def volumes_from_schema
|
63
|
+
Schema::Structure.new.tap do |struct|
|
64
|
+
struct.member(:source_container, Schema::String.new)
|
65
|
+
struct.member(:read_only, Schema::Boolean.new)
|
64
66
|
end
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
67
|
+
end
|
68
|
+
|
69
|
+
def log_configuration_schema
|
70
|
+
Schema::Structure.new.tap do |struct|
|
71
|
+
struct.member(:log_driver, Schema::String.new)
|
72
|
+
struct.member(:options, Schema::Table.new(Schema::String.new, Schema::String.new))
|
71
73
|
end
|
72
|
-
false
|
73
74
|
end
|
74
75
|
end
|
75
76
|
end
|
data/lib/hako/schema.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'hako/schema/boolean'
|
3
|
+
require 'hako/schema/integer'
|
4
|
+
require 'hako/schema/nullable'
|
5
|
+
require 'hako/schema/ordered_array'
|
6
|
+
require 'hako/schema/string'
|
7
|
+
require 'hako/schema/structure'
|
8
|
+
require 'hako/schema/table'
|
9
|
+
require 'hako/schema/unordered_array'
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Hako
|
3
|
+
module Schema
|
4
|
+
class Nullable
|
5
|
+
def initialize(schema)
|
6
|
+
@schema = schema
|
7
|
+
end
|
8
|
+
|
9
|
+
def valid?(object)
|
10
|
+
object.nil? || @schema.valid?(object)
|
11
|
+
end
|
12
|
+
|
13
|
+
def same?(x, y)
|
14
|
+
if x.nil? && y.nil?
|
15
|
+
true
|
16
|
+
elsif x.nil? || y.nil?
|
17
|
+
false
|
18
|
+
else
|
19
|
+
@schema.same?(x, y)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Hako
|
3
|
+
module Schema
|
4
|
+
class OrderedArray
|
5
|
+
def initialize(schema)
|
6
|
+
@schema = schema
|
7
|
+
end
|
8
|
+
|
9
|
+
def valid?(object)
|
10
|
+
object.is_a?(Array) && object.all? { |e| @schema.valid?(e) }
|
11
|
+
end
|
12
|
+
|
13
|
+
def same?(xs, ys)
|
14
|
+
if xs.size != ys.size
|
15
|
+
return false
|
16
|
+
end
|
17
|
+
|
18
|
+
xs.zip(ys) do |x, y|
|
19
|
+
unless @schema.same?(x, y)
|
20
|
+
return false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Hako
|
3
|
+
module Schema
|
4
|
+
class Structure
|
5
|
+
def initialize
|
6
|
+
@members = {}
|
7
|
+
end
|
8
|
+
|
9
|
+
def valid?(object)
|
10
|
+
unless object.is_a?(::Hash)
|
11
|
+
return false
|
12
|
+
end
|
13
|
+
@members.each do |key, val_schema|
|
14
|
+
unless val_schema.valid?(object[key])
|
15
|
+
return false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
true
|
19
|
+
end
|
20
|
+
|
21
|
+
def same?(x, y)
|
22
|
+
@members.each do |key, val_schema|
|
23
|
+
unless val_schema.same?(x[key], y[key])
|
24
|
+
return false
|
25
|
+
end
|
26
|
+
end
|
27
|
+
true
|
28
|
+
end
|
29
|
+
|
30
|
+
def member(key, schema)
|
31
|
+
@members[key] = schema
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Hako
|
3
|
+
module Schema
|
4
|
+
class Table
|
5
|
+
def initialize(key_schema, val_schema)
|
6
|
+
@key_schema = key_schema
|
7
|
+
@val_schema = val_schema
|
8
|
+
end
|
9
|
+
|
10
|
+
def valid?(object)
|
11
|
+
object.is_a?(::Hash) && object.all? { |k, v| @key_schema.valid?(k) && @val_schema.valid?(v) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def same?(xs, ys)
|
15
|
+
if xs.size != ys.size
|
16
|
+
return false
|
17
|
+
end
|
18
|
+
|
19
|
+
t = xs.dup
|
20
|
+
ys.each do |yk, yv|
|
21
|
+
xk, = xs.find { |k, v| @key_schema.same?(k, yk) && @val_schema.same?(v, yv) }
|
22
|
+
if xk
|
23
|
+
t.delete(xk)
|
24
|
+
else
|
25
|
+
return false
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
t.empty?
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Hako
|
3
|
+
module Schema
|
4
|
+
class UnorderedArray
|
5
|
+
def initialize(schema)
|
6
|
+
@schema = schema
|
7
|
+
end
|
8
|
+
|
9
|
+
def valid?(object)
|
10
|
+
object.is_a?(Array) && object.all? { |e| @schema.valid?(e) }
|
11
|
+
end
|
12
|
+
|
13
|
+
def same?(xs, ys)
|
14
|
+
if xs.size != ys.size
|
15
|
+
return false
|
16
|
+
end
|
17
|
+
|
18
|
+
t = xs.dup
|
19
|
+
ys.each do |y|
|
20
|
+
i = t.index { |x| @schema.same?(x, y) }
|
21
|
+
if i
|
22
|
+
t.delete_at(i)
|
23
|
+
else
|
24
|
+
return false
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
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.
|
4
|
+
version: 0.21.0
|
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-
|
11
|
+
date: 2016-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
@@ -144,6 +144,15 @@ files:
|
|
144
144
|
- lib/hako/schedulers/ecs_definition_comparator.rb
|
145
145
|
- lib/hako/schedulers/ecs_elb.rb
|
146
146
|
- lib/hako/schedulers/ecs_elb_v2.rb
|
147
|
+
- lib/hako/schema.rb
|
148
|
+
- lib/hako/schema/boolean.rb
|
149
|
+
- lib/hako/schema/integer.rb
|
150
|
+
- lib/hako/schema/nullable.rb
|
151
|
+
- lib/hako/schema/ordered_array.rb
|
152
|
+
- lib/hako/schema/string.rb
|
153
|
+
- lib/hako/schema/structure.rb
|
154
|
+
- lib/hako/schema/table.rb
|
155
|
+
- lib/hako/schema/unordered_array.rb
|
147
156
|
- lib/hako/script.rb
|
148
157
|
- lib/hako/scripts.rb
|
149
158
|
- lib/hako/scripts/nginx_front.rb
|