ruby_aem_aws 0.9.3 → 1.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/lib/ruby_aem_aws/abstract/cloudwatch.rb +81 -0
- data/lib/ruby_aem_aws/{component/abstract_component.rb → abstract/component.rb} +4 -2
- data/lib/ruby_aem_aws/{component/abstract_grouped_component.rb → abstract/grouped_component.rb} +1 -1
- data/lib/ruby_aem_aws/{component/abstract_single_component.rb → abstract/single_component.rb} +1 -1
- data/lib/ruby_aem_aws/{component/abstract_snapshot.rb → abstract/snapshot.rb} +1 -1
- data/lib/ruby_aem_aws/{component/abstract_stackmanager.rb → abstract/stackmanager.rb} +10 -0
- data/lib/ruby_aem_aws/{consolidated_stack.rb → architecture/consolidated_stack.rb} +21 -7
- data/lib/ruby_aem_aws/architecture/full_set_stack.rb +141 -0
- data/lib/ruby_aem_aws/architecture/stack_manager.rb +44 -0
- data/lib/ruby_aem_aws/client/cloudwatch.rb +87 -0
- data/lib/ruby_aem_aws/{component/mixins → client}/dynamo_db.rb +0 -0
- data/lib/ruby_aem_aws/{component/mixins → client}/s3.rb +1 -1
- data/lib/ruby_aem_aws/{component/mixins → client}/sns_topic.rb +0 -0
- data/lib/ruby_aem_aws/component/author.rb +16 -8
- data/lib/ruby_aem_aws/component/author_dispatcher.rb +19 -16
- data/lib/ruby_aem_aws/component/author_primary.rb +14 -11
- data/lib/ruby_aem_aws/component/author_publish_dispatcher.rb +14 -12
- data/lib/ruby_aem_aws/component/author_standby.rb +14 -12
- data/lib/ruby_aem_aws/component/chaos_monkey.rb +16 -13
- data/lib/ruby_aem_aws/component/orchestrator.rb +16 -13
- data/lib/ruby_aem_aws/component/publish.rb +17 -15
- data/lib/ruby_aem_aws/component/publish_dispatcher.rb +19 -16
- data/lib/ruby_aem_aws/component/stack_manager_resources.rb +19 -11
- data/lib/ruby_aem_aws/error.rb +7 -0
- data/lib/ruby_aem_aws/mixins/healthy_count_verifier.rb +148 -0
- data/lib/ruby_aem_aws/{component/mixins/healthy_count_verifier.rb → mixins/healthy_resource_verifier.rb} +29 -43
- data/lib/ruby_aem_aws/{component/mixins → mixins}/healthy_state_verifier.rb +1 -1
- data/lib/ruby_aem_aws/{component/mixins → mixins}/instance_describer.rb +0 -0
- data/lib/ruby_aem_aws/mixins/metric_verifier.rb +186 -0
- data/lib/ruby_aem_aws/{component/mixins → mixins}/snapshot_verifier.rb +0 -0
- data/lib/ruby_aem_aws.rb +60 -19
- metadata +21 -18
- data/lib/ruby_aem_aws/component/mixins/metric_verifier.rb +0 -43
- data/lib/ruby_aem_aws/full_set_stack.rb +0 -69
- data/lib/ruby_aem_aws/stack_manager.rb +0 -31
@@ -12,16 +12,22 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
-
require_relative '
|
15
|
+
require_relative '../constants'
|
16
16
|
|
17
17
|
module RubyAemAws
|
18
18
|
# Mixin for checking health of a component via ELB 'healthy' count vs ASG desired_capacity.
|
19
19
|
# Add this to a component to make it capable of determining its own health.
|
20
|
-
module
|
20
|
+
module HealthyResourceVerifier
|
21
21
|
# Aggregate health_states considered healthy.
|
22
|
-
# @return
|
23
|
-
def
|
24
|
-
%i[ready scaling].include?
|
22
|
+
# @return health_state_elb is ready or scaling.
|
23
|
+
def healthy_elb?
|
24
|
+
%i[ready scaling].include? health_state_elb
|
25
|
+
end
|
26
|
+
|
27
|
+
# Aggregate health_states considered healthy.
|
28
|
+
# @return health_state_asg is ready or scaling.
|
29
|
+
def healthy_asg?
|
30
|
+
%i[ready scaling].include? health_state_asg
|
25
31
|
end
|
26
32
|
|
27
33
|
# Provides detail of the state of the instances comprising the component.
|
@@ -32,7 +38,7 @@ module RubyAemAws
|
|
32
38
|
# - recovering: ELB running instance count is less than AutoScalingGroup.desired_capacity.
|
33
39
|
# - scaling: ELB running instance count is more than AutoScalingGroup.desired_capacity.
|
34
40
|
# - ready: ELB running instance count is equal to AutoScalingGroup.desired_capacity.
|
35
|
-
def
|
41
|
+
def health_state_elb
|
36
42
|
asg = find_auto_scaling_group(asg_client)
|
37
43
|
return :no_asg if asg.nil?
|
38
44
|
|
@@ -47,9 +53,11 @@ module RubyAemAws
|
|
47
53
|
elb = find_elb(elb_client)
|
48
54
|
return :no_elb if elb.nil?
|
49
55
|
|
56
|
+
elb_instance_state = elb_client.describe_instance_health(load_balancer_name: elb.load_balancer_name)
|
57
|
+
|
50
58
|
elb_running_instances = 0
|
51
|
-
|
52
|
-
elb_running_instances += 1 if i
|
59
|
+
elb_instance_state.instance_states.each do |i|
|
60
|
+
elb_running_instances += 1 if i.state == RubyAemAws::Constants::ELB_INSTANCE_INSERVICE
|
53
61
|
end
|
54
62
|
|
55
63
|
desired_capacity = asg.desired_capacity
|
@@ -63,12 +71,11 @@ module RubyAemAws
|
|
63
71
|
# Provides detail of the state of the instances comprising the component.
|
64
72
|
# @return one of:
|
65
73
|
# - no_asg: AutoScalingGroup could not be located (by StackPrefix and Component tags).
|
66
|
-
# - no_elb: ElasticLoadBalancer could not be located (by StackPrefix and aws:cloudformation:logical-id tags).
|
67
74
|
# - misconfigured: AutoScalingGroup.desired_capacity is less than 1.
|
68
75
|
# - recovering: ELB running instance count is less than AutoScalingGroup.desired_capacity.
|
69
76
|
# - scaling: ELB running instance count is more than AutoScalingGroup.desired_capacity.
|
70
77
|
# - ready: ELB running instance count is equal to AutoScalingGroup.desired_capacity.
|
71
|
-
def
|
78
|
+
def health_state_asg
|
72
79
|
asg = find_auto_scaling_group(asg_client)
|
73
80
|
return :no_asg if asg.nil?
|
74
81
|
|
@@ -80,31 +87,18 @@ module RubyAemAws
|
|
80
87
|
# end
|
81
88
|
# end
|
82
89
|
|
83
|
-
elb = find_elb(elb_client)
|
84
|
-
return :no_elb if elb.nil?
|
85
|
-
|
86
|
-
elb_instance_state = elb_client.describe_instance_health(load_balancer_name: elb.load_balancer_name)
|
87
|
-
|
88
|
-
elb_running_instances = 0
|
89
|
-
elb_instance_state.instance_states.each do |i|
|
90
|
-
elb_running_instances += 1 if i.state == RubyAemAws::Constants::ELB_INSTANCE_INSERVICE
|
91
|
-
end
|
92
|
-
|
93
90
|
desired_capacity = asg.desired_capacity
|
91
|
+
instances_inservice = 0
|
92
|
+
asg.instances.each do |instances|
|
93
|
+
instances_inservice += 1 if instances.health_status.eql? 'Healthy'
|
94
|
+
end
|
94
95
|
|
95
96
|
return :misconfigured if desired_capacity < 1
|
96
|
-
return :recovering if
|
97
|
-
return :scaling if
|
97
|
+
return :recovering if instances_inservice < desired_capacity
|
98
|
+
return :scaling if instances_inservice > desired_capacity
|
98
99
|
:ready
|
99
100
|
end
|
100
101
|
|
101
|
-
# @return true, if all EC2 instances within the ELB are running
|
102
|
-
def wait_until_healthy
|
103
|
-
raise ELBMisconfiguration if health_state.eql?(:misconfigured)
|
104
|
-
sleep 60 while health_state.eql?(:recovering) || health_state.eql?(:scaling)
|
105
|
-
return true if health_state.eql?(:ready)
|
106
|
-
end
|
107
|
-
|
108
102
|
# @return true, if all instances within the ELB are inService
|
109
103
|
def wait_until_healthy_elb
|
110
104
|
raise ELBMisconfiguration if health_state_elb.eql?(:misconfigured)
|
@@ -112,6 +106,12 @@ module RubyAemAws
|
|
112
106
|
return true if health_state_elb.eql?(:ready)
|
113
107
|
end
|
114
108
|
|
109
|
+
def wait_until_healthy_asg
|
110
|
+
raise ASGMisconfiguration if health_state_asg.eql?(:misconfigured)
|
111
|
+
sleep 60 while health_state_asg.eql?(:recovering) || health_state_asg.eql?(:scaling)
|
112
|
+
return true if health_state_asg.eql?(:ready)
|
113
|
+
end
|
114
|
+
|
115
115
|
private
|
116
116
|
|
117
117
|
# @return AutoScalingGroup by StackPrefix and Component tags.
|
@@ -175,19 +175,5 @@ module RubyAemAws
|
|
175
175
|
end
|
176
176
|
nil
|
177
177
|
end
|
178
|
-
|
179
|
-
def get_instances_state_from_elb(elb)
|
180
|
-
stack_prefix_instances = []
|
181
|
-
elb.instances.each do |i|
|
182
|
-
instance = get_instance_by_id(i.instance_id)
|
183
|
-
next if instance.nil?
|
184
|
-
instance.tags.each do |tag|
|
185
|
-
next if tag.key != 'StackPrefix'
|
186
|
-
break if tag.value != descriptor.stack_prefix
|
187
|
-
stack_prefix_instances.push(id: i.instance_id, state: instance.state.name)
|
188
|
-
end
|
189
|
-
end
|
190
|
-
stack_prefix_instances
|
191
|
-
end
|
192
178
|
end
|
193
179
|
end
|
@@ -12,7 +12,7 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
-
require_relative '
|
15
|
+
require_relative '../constants'
|
16
16
|
|
17
17
|
module RubyAemAws
|
18
18
|
# Mixin for checking health of a component via EC2 instance state.
|
File without changes
|
@@ -0,0 +1,186 @@
|
|
1
|
+
# Copyright 2018 Shine Solutions
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require_relative '../abstract/cloudwatch'
|
16
|
+
require_relative '../client/cloudwatch'
|
17
|
+
|
18
|
+
module RubyAemAws
|
19
|
+
# Mixin for checking that an instance has associated CloudWatch metrics.
|
20
|
+
module MetricVerifier
|
21
|
+
include CloudwatchClient
|
22
|
+
include AbstractCloudwatch
|
23
|
+
|
24
|
+
# @param alarm_name name of the Cloudwatch alarm
|
25
|
+
# @return True if Cloudwatch alarm exists for component
|
26
|
+
def component_alarm?(alarm_name)
|
27
|
+
alarm?(alarm_name)
|
28
|
+
end
|
29
|
+
|
30
|
+
# @param namespace Cloudwatch metric namespace
|
31
|
+
# @param metric_name Cloudwatch metric name
|
32
|
+
# @return True if Cloudwatch metric exists for component
|
33
|
+
def component_metric?(namespace, metric_name)
|
34
|
+
dimensions_name = 'FixedDimension'
|
35
|
+
dimensions_value = "#{@descriptor.stack_prefix_in}-#{@descriptor.ec2.component}"
|
36
|
+
response = metric?(namespace, metric_name, dimensions_name, dimensions_value)
|
37
|
+
return true if response.eql? true
|
38
|
+
end
|
39
|
+
|
40
|
+
# @param metric_name Cloudwatch EC2 metric name
|
41
|
+
# @return True if Cloudwatch EC2 metric exists for all component instances
|
42
|
+
def component_ec2_metric?(metric_name)
|
43
|
+
namespace = 'AWS/EC2'
|
44
|
+
dimensions_name = 'InstanceId'
|
45
|
+
instances_with_metric = []
|
46
|
+
instances = get_all_instances
|
47
|
+
instances_found = instances.count
|
48
|
+
|
49
|
+
instances.each do |instance|
|
50
|
+
next if instance.nil?
|
51
|
+
instance_id = instance.instance_id
|
52
|
+
dimensions_value = instance.instance_id
|
53
|
+
|
54
|
+
response = metric?(namespace, metric_name, dimensions_name, dimensions_value)
|
55
|
+
|
56
|
+
instances_with_metric.push(instance_id) if response.eql? true
|
57
|
+
end
|
58
|
+
|
59
|
+
instances_with_metric = instances_with_metric.count
|
60
|
+
|
61
|
+
return true unless instances_with_metric < instances_found
|
62
|
+
end
|
63
|
+
|
64
|
+
# @param log_stream_name Cloudwatch log stream name
|
65
|
+
# @param log_message name of the logfile of the log stream
|
66
|
+
# @return True if log message exists in Cloudwatch log stream for all component instances
|
67
|
+
def component_log_event?(log_stream_name, log_message)
|
68
|
+
instances_with_log_stream = []
|
69
|
+
loggroup_name = "#{@descriptor.stack_prefix_in}#{log_stream_name}"
|
70
|
+
|
71
|
+
instances = get_all_instances
|
72
|
+
instances_found = instances.count
|
73
|
+
|
74
|
+
instances.each do |instance|
|
75
|
+
next if instance.nil?
|
76
|
+
instance_id = instance.instance_id
|
77
|
+
log_stream_name = "#{@descriptor.ec2.component}/#{instance_id}"
|
78
|
+
|
79
|
+
response = log_event?(loggroup_name, log_stream_name, log_message)
|
80
|
+
|
81
|
+
instances_with_log_stream.push(instance_id) if response.eql? true
|
82
|
+
end
|
83
|
+
instances_with_log_stream = instances_with_log_stream.count
|
84
|
+
|
85
|
+
return true unless instances_with_log_stream < instances_found
|
86
|
+
end
|
87
|
+
|
88
|
+
# @param log_stream_name Cloudwatch log stream name
|
89
|
+
# @return True if Cloudwatch loggroup exists for component
|
90
|
+
def component_loggroup?(log_stream_name)
|
91
|
+
loggroup_name = "#{@descriptor.stack_prefix_in}#{log_stream_name}"
|
92
|
+
|
93
|
+
response = loggroup?(loggroup_name)
|
94
|
+
|
95
|
+
return true if response.eql? true
|
96
|
+
end
|
97
|
+
|
98
|
+
# @param log_stream_name Cloudwatch log stream name
|
99
|
+
# @return True if Cloudwatch log stream exists for all component instances
|
100
|
+
def component_log_stream?(log_stream_name)
|
101
|
+
instances_with_log_stream = []
|
102
|
+
loggroup_name = "#{@descriptor.stack_prefix_in}#{log_stream_name}"
|
103
|
+
|
104
|
+
instances = get_all_instances
|
105
|
+
instances_found = instances.count
|
106
|
+
|
107
|
+
instances.each do |instance|
|
108
|
+
next if instance.nil?
|
109
|
+
instance_id = instance.instance_id
|
110
|
+
log_stream_name = "#{@descriptor.ec2.component}/#{instance_id}"
|
111
|
+
|
112
|
+
response = log_stream?(loggroup_name, log_stream_name)
|
113
|
+
|
114
|
+
instances_with_log_stream.push(instance_id) if response.eql? true
|
115
|
+
end
|
116
|
+
instances_with_log_stream = instances_with_log_stream.count
|
117
|
+
|
118
|
+
return true unless instances_with_log_stream < instances_found
|
119
|
+
end
|
120
|
+
|
121
|
+
# @param alarm_name name of the Cloudwatch alarm
|
122
|
+
# @return True if Cloudwatch alarm exists
|
123
|
+
def alarm?(alarm_name)
|
124
|
+
response = get_alarm(alarm_name)
|
125
|
+
|
126
|
+
return true unless response.metric_alarms.empty?
|
127
|
+
end
|
128
|
+
|
129
|
+
# @param namespace Cloudwatch metric namespace
|
130
|
+
# @param metric_name Cloudwatch metric name
|
131
|
+
# @param dimensions_name Cloudwatch metric dimension name
|
132
|
+
# @param dimensions_value Cloudwatch metric dimension value
|
133
|
+
# @return True if Cloudwatch metric exists
|
134
|
+
def metric?(namespace, metric_name, dimensions_name, dimensions_value)
|
135
|
+
dimension_values = dimensions_value_filter_for_cloudwatch_metric(dimensions_name, dimensions_value)
|
136
|
+
dimension_filter = dimensions_filter_for_cloudwatch_metric(dimension_values)
|
137
|
+
|
138
|
+
response = get_metrics(namespace, metric_name, dimension_filter)
|
139
|
+
|
140
|
+
return true unless response.metrics.empty?
|
141
|
+
end
|
142
|
+
|
143
|
+
# @param loggroup_name Cloudwatch loggroup name
|
144
|
+
# @param log_stream_name Cloudwatch log stream name
|
145
|
+
# @return True if Cloudwatch log stream exists
|
146
|
+
def log_stream?(loggroup_name, log_stream_name)
|
147
|
+
response = loggroup?(loggroup_name)
|
148
|
+
return false unless response.eql? true
|
149
|
+
|
150
|
+
response = get_log_streams(loggroup_name, log_stream_name)
|
151
|
+
|
152
|
+
return true unless response.log_streams.empty?
|
153
|
+
end
|
154
|
+
|
155
|
+
# @param loggroup_name Cloudwatch loggroup name
|
156
|
+
# @param log_stream_name Cloudwatch log stream name
|
157
|
+
# @param log_message name of the logfile of the log stream
|
158
|
+
# @return True if Cloudwatch log event exists
|
159
|
+
def log_event?(loggroup_name, log_stream_name, log_message)
|
160
|
+
response = loggroup?(loggroup_name)
|
161
|
+
return false unless response.eql? true
|
162
|
+
|
163
|
+
response = log_stream?(loggroup_name, log_stream_name)
|
164
|
+
return false unless response.eql? true
|
165
|
+
|
166
|
+
response = get_log_event(loggroup_name, log_stream_name, log_message)
|
167
|
+
return true unless response.events.empty?
|
168
|
+
end
|
169
|
+
|
170
|
+
# @param loggroup Cloudwatch loggroup name
|
171
|
+
# @return True if Cloudwatch loggroup exists
|
172
|
+
def loggroup?(loggroup_name)
|
173
|
+
namespace = 'AWS/Logs'
|
174
|
+
metric_name = 'IncomingLogEvents'
|
175
|
+
dimensions_name = 'LogGroupName'
|
176
|
+
dimensions_value = loggroup_name
|
177
|
+
|
178
|
+
dimension_values = dimensions_value_filter_for_cloudwatch_metric(dimensions_name, dimensions_value)
|
179
|
+
dimension_filter = dimensions_filter_for_cloudwatch_metric(dimension_values)
|
180
|
+
|
181
|
+
response = get_metrics(namespace, metric_name, dimension_filter)
|
182
|
+
|
183
|
+
return true unless response.metrics.empty?
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
File without changes
|
data/lib/ruby_aem_aws.rb
CHANGED
@@ -12,9 +12,9 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
-
require_relative 'ruby_aem_aws/consolidated_stack'
|
16
|
-
require_relative 'ruby_aem_aws/full_set_stack'
|
17
|
-
require_relative 'ruby_aem_aws/stack_manager'
|
15
|
+
require_relative 'ruby_aem_aws/architecture/consolidated_stack'
|
16
|
+
require_relative 'ruby_aem_aws/architecture/full_set_stack'
|
17
|
+
require_relative 'ruby_aem_aws/architecture/stack_manager'
|
18
18
|
|
19
19
|
module RubyAemAws
|
20
20
|
# AemAws class represents the AWS stack for AEM.
|
@@ -39,17 +39,7 @@ module RubyAemAws
|
|
39
39
|
raise RubyAemAws::ArgumentError unless defined? credentials
|
40
40
|
Aws.config.update(credentials: credentials)
|
41
41
|
|
42
|
-
aws = AwsCreator.create_aws
|
43
|
-
@ec2_client = aws[:Ec2Client]
|
44
|
-
@ec2_resource = aws[:Ec2Resource]
|
45
|
-
@elb_client = aws[:ElbClient]
|
46
|
-
@auto_scaling_client = aws[:AutoScalingClient]
|
47
|
-
# The V2 API only supports Application ELBs, and we currently use Classic.
|
48
|
-
# @elb_client = Aws::ElasticLoadBalancingV2::Client.new(region: conf[:region])
|
49
|
-
@cloud_watch_client = aws[:CloudWatchClient]
|
50
|
-
@dynamodb_client = aws[:DynamoDBClient]
|
51
|
-
@s3_client = aws[:S3Client]
|
52
|
-
@s3_resource = aws[:S3Resource]
|
42
|
+
@aws = AwsCreator.create_aws
|
53
43
|
end
|
54
44
|
|
55
45
|
# Test connection to Amazon AWS
|
@@ -57,7 +47,8 @@ module RubyAemAws
|
|
57
47
|
# @return One or more regions that are currently available.
|
58
48
|
def test_connection
|
59
49
|
result = []
|
60
|
-
|
50
|
+
ec2_client = @aws[:Ec2Client]
|
51
|
+
ec2_client.describe_regions.regions.each do |region|
|
61
52
|
result.push("Region #{region.region_name} (#{region.endpoint})")
|
62
53
|
end
|
63
54
|
!result.empty?
|
@@ -66,25 +57,69 @@ module RubyAemAws
|
|
66
57
|
# Create a consolidated instance.
|
67
58
|
#
|
68
59
|
# @param stack_prefix AWS tag: StackPrefix
|
60
|
+
# @param aws_clients Array of AWS Clients and Resource connections:
|
61
|
+
# - CloudFormationClient: AWS Cloudformation Client.
|
62
|
+
# - CloudWatchClient: AWS Cloudwatch Client.
|
63
|
+
# - CloudWatchLogsClient: AWS Cloudwatch Logs Client.
|
64
|
+
# - Ec2Resource: AWS EC2 Resource connection.
|
69
65
|
# @return new RubyAemAws::ConsolidatedStack instance
|
70
66
|
def consolidated(stack_prefix)
|
71
|
-
|
67
|
+
aws_clients = {
|
68
|
+
CloudFormationClient: @aws[:CloudFormationClient],
|
69
|
+
CloudWatchClient: @aws[:CloudWatchClient],
|
70
|
+
CloudWatchLogsClient: @aws[:CloudWatchLogsClient],
|
71
|
+
Ec2Resource: @aws[:Ec2Resource]
|
72
|
+
}
|
73
|
+
|
74
|
+
RubyAemAws::ConsolidatedStack.new(stack_prefix, aws_clients)
|
72
75
|
end
|
73
76
|
|
74
77
|
# Create a full set instance.
|
75
78
|
#
|
76
79
|
# @param stack_prefix AWS tag: StackPrefix
|
80
|
+
# @param aws_clients Array of AWS Clients and Resource connections:
|
81
|
+
# - AutoScalingClient: AWS AutoScalingGroup Client.
|
82
|
+
# - CloudFormationClient: AWS Cloudformation Client.
|
83
|
+
# - CloudWatchClient: AWS Cloudwatch Client.
|
84
|
+
# - CloudWatchLogsClient: AWS Cloudwatch Logs Client.
|
85
|
+
# - Ec2Resource: AWS EC2 Resource connection.
|
86
|
+
# - ElbClient: AWS ElasticLoadBalancer Client.
|
77
87
|
# @return new RubyAemAws::FullSetStack instance
|
78
88
|
def full_set(stack_prefix)
|
79
|
-
|
89
|
+
aws_clients = {
|
90
|
+
AutoScalingClient: @aws[:AutoScalingClient],
|
91
|
+
CloudFormationClient: @aws[:CloudFormationClient],
|
92
|
+
CloudWatchClient: @aws[:CloudWatchClient],
|
93
|
+
CloudWatchLogsClient: @aws[:CloudWatchLogsClient],
|
94
|
+
Ec2Resource: @aws[:Ec2Resource],
|
95
|
+
ElbClient: @aws[:ElbClient]
|
96
|
+
}
|
97
|
+
|
98
|
+
RubyAemAws::FullSetStack.new(stack_prefix, aws_clients)
|
80
99
|
end
|
81
100
|
|
82
101
|
# Create Stack Manager resources
|
83
102
|
#
|
84
103
|
# @param stack_prefix AWS tag: StackPrefix
|
104
|
+
# @param aws_clients Array of AWS Clients and Resource connections:
|
105
|
+
# - CloudFormationClient: AWS Cloudformation Client.
|
106
|
+
# - CloudWatchClient: AWS Cloudwatch Client.
|
107
|
+
# - CloudWatchLogsClient: AWS Cloudwatch Logs Client.
|
108
|
+
# - DynamoDBClient: AWS DynamoDB Client.
|
109
|
+
# - S3Client: AWS S3 Client.
|
110
|
+
# - S3Resource: AWS S3 Resource connection.
|
85
111
|
# @return new RubyAemAws::StackManager instance
|
86
112
|
def stack_manager(stack_prefix)
|
87
|
-
|
113
|
+
aws_clients = {
|
114
|
+
CloudFormationClient: @aws[:CloudFormationClient],
|
115
|
+
CloudWatchClient: @aws[:CloudWatchClient],
|
116
|
+
CloudWatchLogsClient: @aws[:CloudWatchLogsClient],
|
117
|
+
DynamoDBClient: @aws[:DynamoDBClient],
|
118
|
+
S3Client: @aws[:S3Client],
|
119
|
+
S3Resource: @aws[:S3Resource]
|
120
|
+
}
|
121
|
+
|
122
|
+
RubyAemAws::StackManager.new(stack_prefix, aws_clients)
|
88
123
|
end
|
89
124
|
end
|
90
125
|
|
@@ -100,7 +135,13 @@ module RubyAemAws
|
|
100
135
|
AutoScalingClient: Aws::AutoScaling::Client.new(
|
101
136
|
retry_limit: 20
|
102
137
|
),
|
103
|
-
|
138
|
+
CloudFormationClient: Aws::CloudFormation::Client.new,
|
139
|
+
CloudWatchClient: Aws::CloudWatch::Client.new(
|
140
|
+
retry_limit: 20
|
141
|
+
),
|
142
|
+
CloudWatchLogsClient: Aws::CloudWatchLogs::Client.new(
|
143
|
+
retry_limit: 20
|
144
|
+
),
|
104
145
|
DynamoDBClient: Aws::DynamoDB::Client.new,
|
105
146
|
S3Client: Aws::S3::Client.new,
|
106
147
|
S3Resource: Aws::S3::Resource.new
|
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: 0.
|
4
|
+
version: 1.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: 2018-
|
11
|
+
date: 2018-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
@@ -75,11 +75,19 @@ extensions: []
|
|
75
75
|
extra_rdoc_files: []
|
76
76
|
files:
|
77
77
|
- lib/ruby_aem_aws.rb
|
78
|
-
- lib/ruby_aem_aws/
|
79
|
-
- lib/ruby_aem_aws/component
|
80
|
-
- lib/ruby_aem_aws/
|
81
|
-
- lib/ruby_aem_aws/
|
82
|
-
- lib/ruby_aem_aws/
|
78
|
+
- lib/ruby_aem_aws/abstract/cloudwatch.rb
|
79
|
+
- lib/ruby_aem_aws/abstract/component.rb
|
80
|
+
- lib/ruby_aem_aws/abstract/grouped_component.rb
|
81
|
+
- lib/ruby_aem_aws/abstract/single_component.rb
|
82
|
+
- lib/ruby_aem_aws/abstract/snapshot.rb
|
83
|
+
- lib/ruby_aem_aws/abstract/stackmanager.rb
|
84
|
+
- lib/ruby_aem_aws/architecture/consolidated_stack.rb
|
85
|
+
- lib/ruby_aem_aws/architecture/full_set_stack.rb
|
86
|
+
- lib/ruby_aem_aws/architecture/stack_manager.rb
|
87
|
+
- lib/ruby_aem_aws/client/cloudwatch.rb
|
88
|
+
- lib/ruby_aem_aws/client/dynamo_db.rb
|
89
|
+
- lib/ruby_aem_aws/client/s3.rb
|
90
|
+
- lib/ruby_aem_aws/client/sns_topic.rb
|
83
91
|
- lib/ruby_aem_aws/component/author.rb
|
84
92
|
- lib/ruby_aem_aws/component/author_dispatcher.rb
|
85
93
|
- lib/ruby_aem_aws/component/author_primary.rb
|
@@ -87,23 +95,18 @@ files:
|
|
87
95
|
- lib/ruby_aem_aws/component/author_standby.rb
|
88
96
|
- lib/ruby_aem_aws/component/chaos_monkey.rb
|
89
97
|
- lib/ruby_aem_aws/component/component_descriptor.rb
|
90
|
-
- lib/ruby_aem_aws/component/mixins/dynamo_db.rb
|
91
|
-
- lib/ruby_aem_aws/component/mixins/healthy_count_verifier.rb
|
92
|
-
- lib/ruby_aem_aws/component/mixins/healthy_state_verifier.rb
|
93
|
-
- lib/ruby_aem_aws/component/mixins/instance_describer.rb
|
94
|
-
- lib/ruby_aem_aws/component/mixins/metric_verifier.rb
|
95
|
-
- lib/ruby_aem_aws/component/mixins/s3.rb
|
96
|
-
- lib/ruby_aem_aws/component/mixins/snapshot_verifier.rb
|
97
|
-
- lib/ruby_aem_aws/component/mixins/sns_topic.rb
|
98
98
|
- lib/ruby_aem_aws/component/orchestrator.rb
|
99
99
|
- lib/ruby_aem_aws/component/publish.rb
|
100
100
|
- lib/ruby_aem_aws/component/publish_dispatcher.rb
|
101
101
|
- lib/ruby_aem_aws/component/stack_manager_resources.rb
|
102
|
-
- lib/ruby_aem_aws/consolidated_stack.rb
|
103
102
|
- lib/ruby_aem_aws/constants.rb
|
104
103
|
- lib/ruby_aem_aws/error.rb
|
105
|
-
- lib/ruby_aem_aws/
|
106
|
-
- lib/ruby_aem_aws/
|
104
|
+
- lib/ruby_aem_aws/mixins/healthy_count_verifier.rb
|
105
|
+
- lib/ruby_aem_aws/mixins/healthy_resource_verifier.rb
|
106
|
+
- lib/ruby_aem_aws/mixins/healthy_state_verifier.rb
|
107
|
+
- lib/ruby_aem_aws/mixins/instance_describer.rb
|
108
|
+
- lib/ruby_aem_aws/mixins/metric_verifier.rb
|
109
|
+
- lib/ruby_aem_aws/mixins/snapshot_verifier.rb
|
107
110
|
homepage: https://github.com/shinesolutions/ruby_aem_aws
|
108
111
|
licenses:
|
109
112
|
- Apache-2.0
|
@@ -1,43 +0,0 @@
|
|
1
|
-
# Copyright 2018 Shine Solutions
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
module RubyAemAws
|
16
|
-
# Mixin for checking that an instance has associated CloudWatch metrics.
|
17
|
-
module MetricVerifier
|
18
|
-
# @param metric_name the name of the metric to check for.
|
19
|
-
# @return true if the instance has a metric with @metric_name.
|
20
|
-
def metric?(metric_name)
|
21
|
-
!metric_instances(metric_name).empty?
|
22
|
-
end
|
23
|
-
|
24
|
-
# @param metric_name the name of the metric to check for.
|
25
|
-
# @return an array of instance_ids that have a metric with @metric_name.
|
26
|
-
def metric_instances(metric_name)
|
27
|
-
instances_with_metric = []
|
28
|
-
instances = get_all_instances
|
29
|
-
instances.each do |instance|
|
30
|
-
next if instance.nil?
|
31
|
-
instance_id = instance.instance_id
|
32
|
-
metrics = @cloud_watch_client.list_metrics(namespace: 'AWS/EC2',
|
33
|
-
metric_name: metric_name,
|
34
|
-
dimensions: [
|
35
|
-
name: 'InstanceId',
|
36
|
-
value: instance_id
|
37
|
-
]).metrics
|
38
|
-
instances_with_metric.push(instance_id) unless metrics.empty?
|
39
|
-
end
|
40
|
-
instances_with_metric
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
# Copyright 2018 Shine Solutions
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
require_relative 'component/author_dispatcher'
|
16
|
-
require_relative 'component/author'
|
17
|
-
require_relative 'component/chaos_monkey'
|
18
|
-
require_relative 'component/orchestrator'
|
19
|
-
require_relative 'component/publish_dispatcher'
|
20
|
-
require_relative 'component/publish'
|
21
|
-
|
22
|
-
module RubyAemAws
|
23
|
-
# Factory for the full-set AEM stack component interfaces.
|
24
|
-
class FullSetStack
|
25
|
-
# @param stack_prefix AWS tag: StackPrefix
|
26
|
-
# @param ec2_resource AWS EC2 resource
|
27
|
-
# @param elb_client AWS ELB client
|
28
|
-
# @param auto_scaling_client AWS AutoScaling client
|
29
|
-
# @param cloud_watch_client AWS CloudWatch client
|
30
|
-
# @return new RubyAemAws::FullSetStack instance
|
31
|
-
def initialize(stack_prefix, ec2_resource, elb_client, auto_scaling_client, cloud_watch_client)
|
32
|
-
@stack_prefix = stack_prefix
|
33
|
-
@ec2_resource = ec2_resource
|
34
|
-
@elb_client = elb_client
|
35
|
-
@auto_scaling_client = auto_scaling_client
|
36
|
-
@cloud_watch_client = cloud_watch_client
|
37
|
-
end
|
38
|
-
|
39
|
-
# @return new RubyAemAws::Component::AuthorDispatcher instance
|
40
|
-
def author_dispatcher
|
41
|
-
RubyAemAws::Component::AuthorDispatcher.new(@stack_prefix, @ec2_resource, @auto_scaling_client, @elb_client, @cloud_watch_client)
|
42
|
-
end
|
43
|
-
|
44
|
-
# @return new RubyAemAws::Component::Author instance
|
45
|
-
def author
|
46
|
-
RubyAemAws::Component::Author.new(@stack_prefix, @ec2_resource, @elb_client, @cloud_watch_client)
|
47
|
-
end
|
48
|
-
|
49
|
-
# @return new RubyAemAws::Component::ChaosMonkey instance
|
50
|
-
def chaos_monkey
|
51
|
-
RubyAemAws::Component::ChaosMonkey.new(@stack_prefix, @ec2_resource, @auto_scaling_client, @cloud_watch_client)
|
52
|
-
end
|
53
|
-
|
54
|
-
# @return new RubyAemAws::Component::Orchestrator instance
|
55
|
-
def orchestrator
|
56
|
-
RubyAemAws::Component::Orchestrator.new(@stack_prefix, @ec2_resource, @auto_scaling_client, @cloud_watch_client)
|
57
|
-
end
|
58
|
-
|
59
|
-
# @return new RubyAemAws::Component::Publish instance
|
60
|
-
def publish
|
61
|
-
RubyAemAws::Component::Publish.new(@stack_prefix, @ec2_resource, @auto_scaling_client, @cloud_watch_client)
|
62
|
-
end
|
63
|
-
|
64
|
-
# @return new RubyAemAws::Component::PublishDispatcher instance
|
65
|
-
def publish_dispatcher
|
66
|
-
RubyAemAws::Component::PublishDispatcher.new(@stack_prefix, @ec2_resource, @auto_scaling_client, @elb_client, @cloud_watch_client)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# Copyright 2018 Shine Solutions
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
require_relative 'component/stack_manager_resources'
|
16
|
-
|
17
|
-
module RubyAemAws
|
18
|
-
# Interface to interact with AEM StackManager
|
19
|
-
class StackManager
|
20
|
-
attr_reader :sm_resources
|
21
|
-
# @param stack_prefix AWS tag: StackPrefix
|
22
|
-
# @param dynamodb_client AWS DynamoDB client
|
23
|
-
# @param s3_client AWS S3 client
|
24
|
-
# @param s3_resource AWS S3 resource
|
25
|
-
# @return new RubyAemAws::StackManager instance
|
26
|
-
def initialize(stack_prefix, dynamodb_client, s3_client, s3_resource)
|
27
|
-
@sm_resources = RubyAemAws::Component::StackManagerResources.new(dynamodb_client, s3_client, s3_resource)
|
28
|
-
@stack_prefix = stack_prefix
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|