ruby_aem_aws 1.5.0 → 2.0.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/conf/gem.yaml +1 -1
- data/lib/ruby_aem_aws.rb +1 -1
- data/lib/ruby_aem_aws/architecture/full_set_stack.rb +1 -1
- data/lib/ruby_aem_aws/component/author.rb +1 -1
- data/lib/ruby_aem_aws/component/author_dispatcher.rb +1 -1
- data/lib/ruby_aem_aws/component/publish_dispatcher.rb +1 -1
- data/lib/ruby_aem_aws/constants.rb +8 -4
- data/lib/ruby_aem_aws/mixins/healthy_count_verifier.rb +49 -19
- data/lib/ruby_aem_aws/mixins/healthy_resource_verifier.rb +45 -18
- 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: 3509ae25ef1a37f800a95eec009bddb1280cbc0c
|
4
|
+
data.tar.gz: 0676f7a857483a52a78c0ab13efd389bdd5f6250
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ec2ccf3f5b781fd7f191e7a0835d4f65d82fd6a8e396dad43c8f47d8b68c8e754c68d0afb51474fbefa8e30b03301c62b6a85cb122f24370e1e250f4ec820b4
|
7
|
+
data.tar.gz: 1ec2dabe8d7b26d741b25cecec676121e7ebb9e6dc824c65f8b5a4bf8944a706658bfe0ad07b433665b9e0e0ccf7bfede7a5ba29d19d170c384541ffb7722ad9
|
data/conf/gem.yaml
CHANGED
@@ -1 +1 @@
|
|
1
|
-
version:
|
1
|
+
version: 2.0.0
|
data/lib/ruby_aem_aws.rb
CHANGED
@@ -111,7 +111,7 @@ module RubyAemAws
|
|
111
111
|
{
|
112
112
|
Ec2Client: Aws::EC2::Client.new,
|
113
113
|
Ec2Resource: Aws::EC2::Resource.new,
|
114
|
-
ElbClient: Aws::
|
114
|
+
ElbClient: Aws::ElasticLoadBalancingV2::Client.new(
|
115
115
|
retry_limit: 20
|
116
116
|
),
|
117
117
|
AutoScalingClient: Aws::AutoScaling::Client.new(
|
@@ -33,7 +33,7 @@ module RubyAemAws
|
|
33
33
|
# - CloudWatchClient: AWS Cloudwatch Client.
|
34
34
|
# - CloudWatchLogsClient: AWS Cloudwatch Logs Client.
|
35
35
|
# - Ec2Resource: AWS EC2 Resource connection.
|
36
|
-
# - ElbClient: AWS ElasticLoadBalancer Client.
|
36
|
+
# - ElbClient: AWS ElasticLoadBalancer v2 Client.
|
37
37
|
# @return new RubyAemAws::FullSetStack instance
|
38
38
|
def initialize(stack_prefix, params)
|
39
39
|
@author_aws_clients = {
|
@@ -29,7 +29,7 @@ module RubyAemAws
|
|
29
29
|
# - CloudWatchClient: AWS Cloudwatch Client.
|
30
30
|
# - CloudWatchLogsClient: AWS Cloudwatch Logs Client.
|
31
31
|
# - Ec2Resource: AWS EC2 Resource connection.
|
32
|
-
# - ElbClient: AWS ElasticLoadBalancer Client.
|
32
|
+
# - ElbClient: AWS ElasticLoadBalancer v2 Client.
|
33
33
|
# @return new RubyAemAws::FullSet::Author
|
34
34
|
def initialize(stack_prefix, params)
|
35
35
|
author_aws_clients = {
|
@@ -42,7 +42,7 @@ module RubyAemAws
|
|
42
42
|
# - CloudWatchClient: AWS Cloudwatch Client.
|
43
43
|
# - CloudWatchLogsClient: AWS Cloudwatch Logs Client.
|
44
44
|
# - Ec2Resource: AWS EC2 Resource connection.
|
45
|
-
# - ElbClient: AWS ElasticLoadBalancer Client.
|
45
|
+
# - ElbClient: AWS ElasticLoadBalancer v2 Client.
|
46
46
|
# @return new RubyAemAws::FullSet::AuthorDispatcher
|
47
47
|
def initialize(stack_prefix, params)
|
48
48
|
@descriptor = ComponentDescriptor.new(stack_prefix,
|
@@ -41,7 +41,7 @@ module RubyAemAws
|
|
41
41
|
# - CloudWatchClient: AWS Cloudwatch Client.
|
42
42
|
# - CloudWatchLogsClient: AWS Cloudwatch Logs Client.
|
43
43
|
# - Ec2Resource: AWS EC2 Resource connection.
|
44
|
-
# - ElbClient: AWS ElasticLoadBalancer Client.
|
44
|
+
# - ElbClient: AWS ElasticLoadBalancer v2 Client.
|
45
45
|
# @return new RubyAemAws::FullSet::PublishDispatcher
|
46
46
|
def initialize(stack_prefix, params)
|
47
47
|
@descriptor = ComponentDescriptor.new(stack_prefix,
|
@@ -35,10 +35,14 @@ module RubyAemAws
|
|
35
35
|
end
|
36
36
|
|
37
37
|
class ELBInstanceState
|
38
|
-
|
39
|
-
|
38
|
+
DRAINING = 'draining'.freeze
|
39
|
+
HEALTHY = 'healthy'.freeze
|
40
|
+
INITIAL = 'initial'.freeze
|
41
|
+
UNAVAILABLE = 'unavailable'.freeze
|
42
|
+
UNHEALTHY = 'unhealthy'.freeze
|
43
|
+
UNUSED = 'unused'.freeze
|
40
44
|
|
41
|
-
ALL_ACTIVE = [
|
45
|
+
ALL_ACTIVE = [HEALTHY, INITIAL, UNAVAILABLE, UNUSED].freeze
|
42
46
|
end
|
43
47
|
|
44
48
|
class Constants
|
@@ -48,6 +52,6 @@ module RubyAemAws
|
|
48
52
|
PROFILE = ENV['AWS_PROFILE']
|
49
53
|
INSTANCE_STATE_HEALTHY = RubyAemAws::InstanceState::RUNNING.freeze
|
50
54
|
INSTANCE_STATE_CODE_RUNNING = RubyAemAws::InstanceStateCode::RUNNING
|
51
|
-
ELB_INSTANCE_INSERVICE = RubyAemAws::ELBInstanceState::
|
55
|
+
ELB_INSTANCE_INSERVICE = RubyAemAws::ELBInstanceState::HEALTHY.freeze
|
52
56
|
end
|
53
57
|
end
|
@@ -48,7 +48,10 @@ module RubyAemAws
|
|
48
48
|
return :no_elb if elb.nil?
|
49
49
|
|
50
50
|
elb_running_instances = 0
|
51
|
-
|
51
|
+
elb_instances = get_instances_state(elb_client, elb)
|
52
|
+
return :no_elb_targets if elb_instances.nil?
|
53
|
+
|
54
|
+
elb_instances.each do |i|
|
52
55
|
elb_running_instances += 1 if i[:state] == RubyAemAws::Constants::INSTANCE_STATE_HEALTHY
|
53
56
|
end
|
54
57
|
|
@@ -108,44 +111,71 @@ module RubyAemAws
|
|
108
111
|
nil
|
109
112
|
end
|
110
113
|
|
111
|
-
# @return ElasticLoadBalancer
|
114
|
+
# @return ElasticLoadBalancer Arn.
|
112
115
|
def find_elb(elb_client)
|
113
|
-
elbs = elb_client.describe_load_balancers
|
116
|
+
elbs = elb_client.describe_load_balancers(page_size: 50)
|
117
|
+
elb_arn = find_elb_arn(elbs.load_balancers)
|
118
|
+
|
119
|
+
return elb_arn unless elb_arn.nil?
|
120
|
+
|
121
|
+
until elbs.last_page?
|
122
|
+
elbs = elb_client.describe_load_balancers(page_size: 50, marker: elbs.next_marker)
|
123
|
+
elb_arn = find_elb_arn(elbs.load_balancers)
|
124
|
+
return elb_arn unless elb_arn.nil?
|
125
|
+
end
|
126
|
+
nil
|
127
|
+
end
|
128
|
+
|
129
|
+
# @return ElasticLoadBalancer Arn by StackPrefix tag & ELB name.
|
130
|
+
def find_elb_arn(elbs)
|
114
131
|
elbs.each do |elb|
|
115
132
|
elb_matches_stack_prefix = false
|
116
|
-
|
117
|
-
|
133
|
+
elb_matches_name = false
|
134
|
+
begin
|
135
|
+
tag_descriptions = elb_client.describe_tags(resource_arns: [elb.load_balancer_arn]).tag_descriptions
|
136
|
+
rescue Aws::ElasticLoadBalancingV2::Errors::LoadBalancerNotFound
|
137
|
+
next
|
138
|
+
end
|
139
|
+
|
118
140
|
next if tag_descriptions.empty?
|
119
141
|
|
120
142
|
tags = tag_descriptions[0].tags
|
121
143
|
tags.each do |tag|
|
122
|
-
if tag.key == 'StackPrefix' && tag.value == descriptor.stack_prefix
|
123
|
-
|
124
|
-
break if elb_matches_logical_id
|
144
|
+
elb_matches_stack_prefix = true if tag.key == 'StackPrefix' && tag.value == descriptor.stack_prefix
|
145
|
+
elb_matches_name = true if tag.key == 'Name' && tag.value == descriptor.elb.name
|
125
146
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
elb_matches_logical_id = true
|
130
|
-
break if elb_matches_stack_prefix
|
131
|
-
end
|
147
|
+
return elb.load_balancer_arn if elb_matches_stack_prefix && elb_matches_name
|
148
|
+
|
149
|
+
next
|
132
150
|
end
|
133
|
-
return elb if elb_matches_stack_prefix && elb_matches_logical_id
|
134
151
|
end
|
135
152
|
nil
|
136
153
|
end
|
137
154
|
|
138
|
-
def
|
155
|
+
def get_instances_state(elb_client, elb_arn)
|
156
|
+
described_target_groups = elb_client.describe_target_groups(load_balancer_arn: elb_arn)
|
157
|
+
|
158
|
+
return nil if described_target_groups.target_groups.empty?
|
159
|
+
|
160
|
+
target_group = described_target_groups.target_groups[0]
|
161
|
+
target_group_arn = target_group.target_group_arn
|
162
|
+
|
163
|
+
described_target_health = elb_client.describe_target_health(target_group_arn: target_group_arn)
|
164
|
+
|
165
|
+
return nil if described_target_health.target_health_descriptions.empty?
|
166
|
+
|
167
|
+
targets = described_target_health.target_health_descriptions
|
168
|
+
|
139
169
|
stack_prefix_instances = []
|
140
|
-
|
141
|
-
instance = get_instance_by_id(
|
170
|
+
targets.each do |t|
|
171
|
+
instance = get_instance_by_id(t.target.id)
|
142
172
|
next if instance.nil?
|
143
173
|
|
144
174
|
instance.tags.each do |tag|
|
145
175
|
next if tag.key != 'StackPrefix'
|
146
176
|
break if tag.value != descriptor.stack_prefix
|
147
177
|
|
148
|
-
stack_prefix_instances.push(id:
|
178
|
+
stack_prefix_instances.push(id: t.target.id, state: instance.state.name)
|
149
179
|
end
|
150
180
|
end
|
151
181
|
stack_prefix_instances
|
@@ -53,15 +53,15 @@ module RubyAemAws
|
|
53
53
|
elb = find_elb(elb_client)
|
54
54
|
return :no_elb if elb.nil?
|
55
55
|
|
56
|
-
elb_instance_state = elb_client
|
56
|
+
elb_instance_state = get_instances_elb_state(elb_client, elb)
|
57
|
+
return :no_elb_targets if elb_instance_state.nil?
|
57
58
|
|
58
59
|
elb_running_instances = 0
|
59
|
-
elb_instance_state.
|
60
|
-
elb_running_instances += 1 if i.state == RubyAemAws::Constants::ELB_INSTANCE_INSERVICE
|
60
|
+
elb_instance_state.each do |i|
|
61
|
+
elb_running_instances += 1 if i.target_health.state == RubyAemAws::Constants::ELB_INSTANCE_INSERVICE
|
61
62
|
end
|
62
63
|
|
63
64
|
desired_capacity = asg.desired_capacity
|
64
|
-
|
65
65
|
return :misconfigured if desired_capacity < 1
|
66
66
|
return :recovering if elb_running_instances < desired_capacity
|
67
67
|
return :scaling if elb_running_instances > desired_capacity
|
@@ -158,31 +158,58 @@ module RubyAemAws
|
|
158
158
|
nil
|
159
159
|
end
|
160
160
|
|
161
|
-
# @return ElasticLoadBalancer
|
161
|
+
# @return ElasticLoadBalancer Arn.
|
162
162
|
def find_elb(elb_client)
|
163
|
-
elbs = elb_client.describe_load_balancers
|
163
|
+
elbs = elb_client.describe_load_balancers(page_size: 50)
|
164
|
+
elb_arn = find_elb_arn(elbs.load_balancers)
|
165
|
+
|
166
|
+
return elb_arn unless elb_arn.nil?
|
167
|
+
|
168
|
+
until elbs.last_page?
|
169
|
+
elbs = elb_client.describe_load_balancers(page_size: 50, marker: elbs.next_marker)
|
170
|
+
elb_arn = find_elb_arn(elbs.load_balancers)
|
171
|
+
return elb_arn unless elb_arn.nil?
|
172
|
+
end
|
173
|
+
nil
|
174
|
+
end
|
175
|
+
|
176
|
+
# @return ElasticLoadBalancer Arn by StackPrefix tag & ELB name.
|
177
|
+
def find_elb_arn(elbs)
|
164
178
|
elbs.each do |elb|
|
165
179
|
elb_matches_stack_prefix = false
|
166
|
-
|
167
|
-
|
180
|
+
elb_matches_name = false
|
181
|
+
begin
|
182
|
+
tag_descriptions = elb_client.describe_tags(resource_arns: [elb.load_balancer_arn]).tag_descriptions
|
183
|
+
rescue Aws::ElasticLoadBalancingV2::Errors::LoadBalancerNotFound
|
184
|
+
next
|
185
|
+
end
|
186
|
+
|
168
187
|
next if tag_descriptions.empty?
|
169
188
|
|
170
189
|
tags = tag_descriptions[0].tags
|
171
190
|
tags.each do |tag|
|
172
|
-
if tag.key == 'StackPrefix' && tag.value == descriptor.stack_prefix
|
173
|
-
|
174
|
-
break if elb_matches_logical_id
|
191
|
+
elb_matches_stack_prefix = true if tag.key == 'StackPrefix' && tag.value == descriptor.stack_prefix
|
192
|
+
elb_matches_name = true if tag.key == 'Name' && tag.value == descriptor.elb.name
|
175
193
|
|
176
|
-
|
177
|
-
end
|
178
|
-
if tag.key == 'aws:cloudformation:logical-id' && tag.value == descriptor.elb.id
|
179
|
-
elb_matches_logical_id = true
|
180
|
-
break if elb_matches_stack_prefix
|
181
|
-
end
|
194
|
+
return elb.load_balancer_arn if elb_matches_stack_prefix && elb_matches_name
|
182
195
|
end
|
183
|
-
return elb if elb_matches_stack_prefix && elb_matches_logical_id
|
184
196
|
end
|
185
197
|
nil
|
186
198
|
end
|
199
|
+
|
200
|
+
def get_instances_elb_state(elb_client, elb_arn)
|
201
|
+
described_target_groups = elb_client.describe_target_groups(load_balancer_arn: elb_arn)
|
202
|
+
|
203
|
+
return nil if described_target_groups.target_groups.empty?
|
204
|
+
|
205
|
+
target_group = described_target_groups.target_groups[0]
|
206
|
+
target_group_arn = target_group.target_group_arn
|
207
|
+
|
208
|
+
described_target_health = elb_client.describe_target_health(target_group_arn: target_group_arn)
|
209
|
+
|
210
|
+
return nil if described_target_health.target_health_descriptions.empty?
|
211
|
+
|
212
|
+
described_target_health.target_health_descriptions
|
213
|
+
end
|
187
214
|
end
|
188
215
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_aem_aws
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shine Solutions
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|