ruby_aem_aws 1.2.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.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/conf/gem.yaml +1 -0
  3. data/lib/ruby_aem_aws.rb +5 -23
  4. data/lib/ruby_aem_aws/abstract/cloudwatch.rb +2 -2
  5. data/lib/ruby_aem_aws/abstract/component.rb +0 -1
  6. data/lib/ruby_aem_aws/abstract/single_component.rb +1 -0
  7. data/lib/ruby_aem_aws/abstract/stackmanager.rb +1 -1
  8. data/lib/ruby_aem_aws/architecture/consolidated_stack.rb +0 -5
  9. data/lib/ruby_aem_aws/architecture/full_set_stack.rb +1 -39
  10. data/lib/ruby_aem_aws/component/author.rb +8 -1
  11. data/lib/ruby_aem_aws/component/author_dispatcher.rb +14 -2
  12. data/lib/ruby_aem_aws/component/author_primary.rb +5 -0
  13. data/lib/ruby_aem_aws/component/author_publish_dispatcher.rb +5 -0
  14. data/lib/ruby_aem_aws/component/author_standby.rb +6 -1
  15. data/lib/ruby_aem_aws/component/chaos_monkey.rb +13 -1
  16. data/lib/ruby_aem_aws/component/component_descriptor.rb +1 -0
  17. data/lib/ruby_aem_aws/component/orchestrator.rb +13 -1
  18. data/lib/ruby_aem_aws/component/publish.rb +13 -1
  19. data/lib/ruby_aem_aws/component/publish_dispatcher.rb +14 -2
  20. data/lib/ruby_aem_aws/component/stack_manager_resources.rb +0 -1
  21. data/lib/ruby_aem_aws/constants.rb +20 -5
  22. data/lib/ruby_aem_aws/error.rb +0 -7
  23. data/lib/ruby_aem_aws/mixins/healthy_count_verifier.rb +55 -19
  24. data/lib/ruby_aem_aws/mixins/healthy_resource_verifier.rb +58 -22
  25. data/lib/ruby_aem_aws/mixins/healthy_state_verifier.rb +4 -2
  26. data/lib/ruby_aem_aws/mixins/instance_describer.rb +1 -0
  27. data/lib/ruby_aem_aws/mixins/metric_verifier.rb +4 -1
  28. data/lib/ruby_aem_aws/mixins/snapshot_verifier.rb +1 -0
  29. metadata +31 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ff1811700428fb65c37eb7e1483880d021409248
4
- data.tar.gz: 0a9a738540c1b4ef71c36b4a7d87720f92dc21ca
3
+ metadata.gz: 3509ae25ef1a37f800a95eec009bddb1280cbc0c
4
+ data.tar.gz: 0676f7a857483a52a78c0ab13efd389bdd5f6250
5
5
  SHA512:
6
- metadata.gz: dde9e65199958cda617db9e1c0025c572afd05b66233773ac642dc424003d5913b9b88ee20492ae63dc24c011e082e914ffa58aaaf7ee63b629e4ffd8fc4ac99
7
- data.tar.gz: '0342921e2739eb702196395a0f2a9bcbe89395fb631a352ebb7a211453f42a435b3513a8c6b680ddfa7cfdd265e60263d4544bdc4ea40cf5cf37084d5b38f5c4'
6
+ metadata.gz: 8ec2ccf3f5b781fd7f191e7a0835d4f65d82fd6a8e396dad43c8f47d8b68c8e754c68d0afb51474fbefa8e30b03301c62b6a85cb122f24370e1e250f4ec820b4
7
+ data.tar.gz: 1ec2dabe8d7b26d741b25cecec676121e7ebb9e6dc824c65f8b5a4bf8944a706658bfe0ad07b433665b9e0e0ccf7bfede7a5ba29d19d170c384541ffb7722ad9
@@ -0,0 +1 @@
1
+ version: 2.0.0
@@ -20,23 +20,24 @@ module RubyAemAws
20
20
  # AemAws class represents the AWS stack for AEM.
21
21
  class AemAws
22
22
  # @param conf configuration hash of the following configuration values:
23
- # - region: the AWS region (eg ap-southeast-2)
23
+ # - aws_region: the AWS region (eg ap-southeast-2)
24
24
  # - aws_access_key_id: the AWS access key
25
25
  # - aws_secret_access_key: the AWS secret access key
26
26
  # - aws_profile: AWS profile name
27
27
  # @return new RubyAemAws::AemAws instance
28
28
  def initialize(conf = {})
29
- conf[:region] ||= Constants::REGION_DEFAULT
29
+ conf[:aws_region] ||= Constants::REGION_DEFAULT
30
30
  conf[:aws_access_key_id] ||= Constants::ACCESS_KEY_ID
31
31
  conf[:aws_secret_access_key] ||= Constants::SECRET_ACCESS_KEY
32
32
  conf[:aws_profile] ||= Constants::PROFILE
33
33
 
34
- Aws.config.update(region: conf[:region])
34
+ Aws.config.update(region: conf[:aws_region])
35
35
 
36
36
  credentials = Aws::Credentials.new(conf[:aws_access_key_id], conf[:aws_secret_access_key]) unless conf[:aws_access_key_id].nil?
37
37
  credentials = Aws::SharedCredentials.new(profile_name: conf[:aws_profile]) unless conf[:aws_profile].nil?
38
38
  credentials = Aws::InstanceProfileCredentials.new if conf[:aws_profile].nil? && conf[:aws_access_key_id].nil?
39
39
  raise RubyAemAws::ArgumentError unless defined? credentials
40
+
40
41
  Aws.config.update(credentials: credentials)
41
42
 
42
43
  @aws = AwsCreator.create_aws
@@ -57,11 +58,6 @@ module RubyAemAws
57
58
  # Create a consolidated instance.
58
59
  #
59
60
  # @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.
65
61
  # @return new RubyAemAws::ConsolidatedStack instance
66
62
  def consolidated(stack_prefix)
67
63
  aws_clients = {
@@ -77,13 +73,6 @@ module RubyAemAws
77
73
  # Create a full set instance.
78
74
  #
79
75
  # @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.
87
76
  # @return new RubyAemAws::FullSetStack instance
88
77
  def full_set(stack_prefix)
89
78
  aws_clients = {
@@ -101,13 +90,6 @@ module RubyAemAws
101
90
  # Create Stack Manager resources
102
91
  #
103
92
  # @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.
111
93
  # @return new RubyAemAws::StackManager instance
112
94
  def stack_manager(stack_prefix)
113
95
  aws_clients = {
@@ -129,7 +111,7 @@ module RubyAemAws
129
111
  {
130
112
  Ec2Client: Aws::EC2::Client.new,
131
113
  Ec2Resource: Aws::EC2::Resource.new,
132
- ElbClient: Aws::ElasticLoadBalancing::Client.new(
114
+ ElbClient: Aws::ElasticLoadBalancingV2::Client.new(
133
115
  retry_limit: 20
134
116
  ),
135
117
  AutoScalingClient: Aws::AutoScaling::Client.new(
@@ -39,7 +39,7 @@ module RubyAemAws
39
39
  }
40
40
  end
41
41
 
42
- # @param loggroup_name Cloudwatch loggroup name
42
+ # @param log_group_name Cloudwatch loggroup name
43
43
  # @param log_stream_name Cloudwatch logstream name
44
44
  # @return Array of a Cloudwatch log stream filter to filter for a specific Cloudwatch log stream
45
45
  def filter_for_cloudwatch_log_stream(log_group_name, log_stream_name)
@@ -71,7 +71,7 @@ module RubyAemAws
71
71
  end
72
72
 
73
73
  # @param dimensions_name Cloudwatch Dimension name
74
- # @param dimension_values Cloudwatch Dimension value
74
+ # @param dimensions_value Cloudwatch Dimension value
75
75
  # @return Array of a Cloudwatch Dimension value filter for the Cloudwatch dimension filter
76
76
  def dimensions_value_filter_for_cloudwatch_metric(dimensions_name, dimensions_value)
77
77
  {
@@ -33,7 +33,6 @@ module RubyAemAws
33
33
  filters: [
34
34
  { name: 'tag:StackPrefix', values: [@descriptor.stack_prefix] },
35
35
  { name: 'tag:Component', values: [@descriptor.ec2.component] },
36
- { name: 'tag:Name', values: [@descriptor.ec2.name] },
37
36
  { name: 'instance-state-name', values: ['running'] }
38
37
  ]
39
38
  }
@@ -25,6 +25,7 @@ module RubyAemAws
25
25
  count = instances.count
26
26
  raise RubyAemAws::ExpectedSingleInstanceError if count > 1
27
27
  return nil if count.zero?
28
+
28
29
  instances.first
29
30
  end
30
31
 
@@ -35,7 +35,7 @@ module RubyAemAws
35
35
  end
36
36
 
37
37
  # @param dynamodb_tablename AWS DynamoDB table name
38
- # @param attkey_attribute_valueribute_value Key value to query for
38
+ # @param key_attribute_value Key value to query for
39
39
  # @return Array of a DynamoDB filter to query for a specific value
40
40
  def filter_for_db_query(dynamodb_tablename, key_attribute_value)
41
41
  {
@@ -36,11 +36,6 @@ module RubyAemAws
36
36
  @stack_prefix = stack_prefix
37
37
  end
38
38
 
39
- # @param stack_prefix AWS tag: StackPrefix
40
- # @param consolidated_aws_clients Array of AWS Clients and Resource connections:
41
- # - CloudWatchClient: AWS Cloudwatch Client.
42
- # - CloudWatchLogsClient: AWS Cloudwatch Logs Client.
43
- # - Ec2Resource: AWS EC2 Resource connection.
44
39
  # @return new RubyAemAws::Component::AuthorPublishDispatcher instance
45
40
  def author_publish_dispatcher
46
41
  RubyAemAws::Component::AuthorPublishDispatcher.new(@stack_prefix, @consolidated_aws_clients)
@@ -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 = {
@@ -70,69 +70,31 @@ module RubyAemAws
70
70
  @stack_prefix = stack_prefix
71
71
  end
72
72
 
73
- # @param stack_prefix AWS tag: StackPrefix
74
- # @param dispatcher_aws_clients Array of AWS Clients and Resource connections:
75
- # - AutoScalingClient: AWS AutoScalingGroup Client.
76
- # - CloudWatchClient: AWS Cloudwatch Client.
77
- # - CloudWatchLogsClient: AWS Cloudwatch Logs Client.
78
- # - Ec2Resource: AWS EC2 Resource connection.
79
- # - ElbClient: AWS ElasticLoadBalancer Client.
80
73
  # @return new RubyAemAws::Component::AuthorDispatcher instance
81
74
  def author_dispatcher
82
75
  RubyAemAws::Component::AuthorDispatcher.new(@stack_prefix, @dispatcher_aws_clients)
83
76
  end
84
77
 
85
- # @param stack_prefix AWS tag: StackPrefix
86
- # @param author_aws_clients Array of AWS Clients and Resource connections:
87
- # - CloudWatchClient: AWS Cloudwatch Client.
88
- # - CloudWatchLogsClient: AWS Cloudwatch Logs Client.
89
- # - Ec2Resource: AWS EC2 Resource connection.
90
- # - ElbClient: AWS ElasticLoadBalancer Client.
91
78
  # @return new RubyAemAws::Component::Author instance
92
79
  def author
93
80
  RubyAemAws::Component::Author.new(@stack_prefix, @author_aws_clients)
94
81
  end
95
82
 
96
- # @param stack_prefix AWS tag: StackPrefix
97
- # @param chaos_monkey_aws_clients Array of AWS Clients and Resource connections:
98
- # - AutoScalingClient: AWS AutoScalingGroup Client.
99
- # - CloudWatchClient: AWS Cloudwatch Client.
100
- # - CloudWatchLogsClient: AWS Cloudwatch Logs Client.
101
- # - Ec2Resource: AWS EC2 Resource connection.
102
83
  # @return new RubyAemAws::Component::ChaosMonkey instance
103
84
  def chaos_monkey
104
85
  RubyAemAws::Component::ChaosMonkey.new(@stack_prefix, @aem_java_aws_clients)
105
86
  end
106
87
 
107
- # @param stack_prefix AWS tag: StackPrefix
108
- # @param orchestrator_aws_clients Array of AWS Clients and Resource connections:
109
- # - AutoScalingClient: AWS AutoScalingGroup Client.
110
- # - CloudWatchClient: AWS Cloudwatch Client.
111
- # - CloudWatchLogsClient: AWS Cloudwatch Logs Client.
112
- # - Ec2Resource: AWS EC2 Resource connection.
113
88
  # @return new RubyAemAws::Component::Orchestrator instance
114
89
  def orchestrator
115
90
  RubyAemAws::Component::Orchestrator.new(@stack_prefix, @aem_java_aws_clients)
116
91
  end
117
92
 
118
- # @param stack_prefix AWS tag: StackPrefix
119
- # @param publish_aws_clients Array of AWS Clients and Resource connections:
120
- # - AutoScalingClient: AWS AutoScalingGroup Client.
121
- # - CloudWatchClient: AWS Cloudwatch Client.
122
- # - CloudWatchLogsClient: AWS Cloudwatch Logs Client.
123
- # - Ec2Resource: AWS EC2 Resource connection.
124
93
  # @return new RubyAemAws::Component::Publish instance
125
94
  def publish
126
95
  RubyAemAws::Component::Publish.new(@stack_prefix, @publish_aws_clients)
127
96
  end
128
97
 
129
- # @param stack_prefix AWS tag: StackPrefix
130
- # @param dispatcher_aws_clients Array of AWS Clients and Resource connections:
131
- # - AutoScalingClient: AWS AutoScalingGroup Client.
132
- # - CloudWatchClient: AWS Cloudwatch Client.
133
- # - CloudWatchLogsClient: AWS Cloudwatch Logs Client.
134
- # - Ec2Resource: AWS EC2 Resource connection.
135
- # - ElbClient: AWS ElasticLoadBalancer Client.
136
98
  # @return new RubyAemAws::Component::PublishDispatcher instance
137
99
  def publish_dispatcher
138
100
  RubyAemAws::Component::PublishDispatcher.new(@stack_prefix, @dispatcher_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 = {
@@ -59,6 +59,13 @@ module RubyAemAws
59
59
  instance += 1 if author_standby.wait_until_healthy.eql? true
60
60
  return true unless instance < 2
61
61
  end
62
+
63
+ def get_tags
64
+ tags = []
65
+ tags.push(author_primary.get_tags)
66
+ tags.push(author_standby.get_tags)
67
+ tags
68
+ end
62
69
  end
63
70
  end
64
71
  end
@@ -14,6 +14,7 @@
14
14
 
15
15
  require_relative '../abstract/grouped_component'
16
16
  require_relative '../abstract/snapshot'
17
+ require_relative '../constants'
17
18
  require_relative '../mixins/healthy_resource_verifier'
18
19
  require_relative '../mixins/metric_verifier'
19
20
  require_relative 'component_descriptor'
@@ -41,7 +42,7 @@ module RubyAemAws
41
42
  # - CloudWatchClient: AWS Cloudwatch Client.
42
43
  # - CloudWatchLogsClient: AWS Cloudwatch Logs Client.
43
44
  # - Ec2Resource: AWS EC2 Resource connection.
44
- # - ElbClient: AWS ElasticLoadBalancer Client.
45
+ # - ElbClient: AWS ElasticLoadBalancer v2 Client.
45
46
  # @return new RubyAemAws::FullSet::AuthorDispatcher
46
47
  def initialize(stack_prefix, params)
47
48
  @descriptor = ComponentDescriptor.new(stack_prefix,
@@ -56,7 +57,8 @@ module RubyAemAws
56
57
 
57
58
  def terminate_all_instances
58
59
  get_all_instances.each do |i|
59
- next if i.nil?
60
+ next if i.nil? || i.state.code != Constants::INSTANCE_STATE_CODE_RUNNING
61
+
60
62
  i.terminate
61
63
  i.wait_until_terminated
62
64
  end
@@ -67,6 +69,16 @@ module RubyAemAws
67
69
  instance.terminate
68
70
  instance.wait_until_terminated
69
71
  end
72
+
73
+ def get_tags
74
+ tags = []
75
+ get_all_instances.each do |i|
76
+ next if i.nil? || i.state.code != Constants::INSTANCE_STATE_CODE_RUNNING
77
+
78
+ tags.push(i.tags)
79
+ end
80
+ tags
81
+ end
70
82
  end
71
83
  end
72
84
  end
@@ -52,6 +52,11 @@ module RubyAemAws
52
52
  instance.terminate
53
53
  instance.wait_until_terminated
54
54
  end
55
+
56
+ def get_tags
57
+ instance = get_instance
58
+ instance.tags
59
+ end
55
60
  end
56
61
  end
57
62
  end
@@ -46,6 +46,11 @@ module RubyAemAws
46
46
  @cloud_watch_log_client = params[:CloudWatchLogsClient]
47
47
  @ec2_resource = params[:Ec2Resource]
48
48
  end
49
+
50
+ def get_tags
51
+ instance = get_instance
52
+ instance.tags
53
+ end
49
54
  end
50
55
  end
51
56
  end
@@ -23,7 +23,7 @@ module RubyAemAws
23
23
  # Interface to the AWS instance running the Author-Standby component of a full-set AEM stack.
24
24
  class AuthorStandby
25
25
  attr_reader :descriptor, :ec2_resource, :cloud_watch_client, :cloud_watch_log_client
26
- include AbstractGroupedComponent
26
+ include AbstractSingleComponent
27
27
  include AbstractSnapshot
28
28
  include HealthyStateVerifier
29
29
  include MetricVerifier
@@ -52,6 +52,11 @@ module RubyAemAws
52
52
  instance.terminate
53
53
  instance.wait_until_terminated
54
54
  end
55
+
56
+ def get_tags
57
+ instance = get_instance
58
+ instance.tags
59
+ end
55
60
  end
56
61
  end
57
62
  end
@@ -14,6 +14,7 @@
14
14
 
15
15
  require_relative '../abstract/grouped_component'
16
16
  require_relative '../abstract/snapshot'
17
+ require_relative '../constants'
17
18
  require_relative '../mixins/healthy_resource_verifier'
18
19
  require_relative '../mixins/metric_verifier'
19
20
  require_relative '../mixins/snapshot_verifier'
@@ -50,7 +51,8 @@ module RubyAemAws
50
51
 
51
52
  def terminate_all_instances
52
53
  get_all_instances.each do |i|
53
- next if i.nil?
54
+ next if i.nil? || i.state.code != Constants::INSTANCE_STATE_CODE_RUNNING
55
+
54
56
  i.terminate
55
57
  i.wait_until_terminated
56
58
  end
@@ -61,6 +63,16 @@ module RubyAemAws
61
63
  instance.terminate
62
64
  instance.wait_until_terminated
63
65
  end
66
+
67
+ def get_tags
68
+ tags = []
69
+ get_all_instances.each do |i|
70
+ next if i.nil? || i.state.code != Constants::INSTANCE_STATE_CODE_RUNNING
71
+
72
+ tags.push(i.tags)
73
+ end
74
+ tags
75
+ end
64
76
  end
65
77
  end
66
78
  end
@@ -18,6 +18,7 @@ module RubyAemAws
18
18
  def stack_prefix
19
19
  # Unwrap from {:stack_prefix = value} to the value if necessary.
20
20
  return stack_prefix_in[:stack_prefix] if stack_prefix_in.is_a? Hash
21
+
21
22
  stack_prefix_in
22
23
  end
23
24
  end
@@ -14,6 +14,7 @@
14
14
 
15
15
  require_relative '../abstract/grouped_component'
16
16
  require_relative '../abstract/snapshot'
17
+ require_relative '../constants'
17
18
  require_relative '../mixins/healthy_resource_verifier'
18
19
  require_relative '../mixins/metric_verifier'
19
20
  require_relative '../mixins/snapshot_verifier'
@@ -50,7 +51,8 @@ module RubyAemAws
50
51
 
51
52
  def terminate_all_instances
52
53
  get_all_instances.each do |i|
53
- next if i.nil?
54
+ next if i.nil? || i.state.code != Constants::INSTANCE_STATE_CODE_RUNNING
55
+
54
56
  i.terminate
55
57
  i.wait_until_terminated
56
58
  end
@@ -61,6 +63,16 @@ module RubyAemAws
61
63
  instance.terminate
62
64
  instance.wait_until_terminated
63
65
  end
66
+
67
+ def get_tags
68
+ tags = []
69
+ get_all_instances.each do |i|
70
+ next if i.nil? || i.state.code != Constants::INSTANCE_STATE_CODE_RUNNING
71
+
72
+ tags.push(i.tags)
73
+ end
74
+ tags
75
+ end
64
76
  end
65
77
  end
66
78
  end
@@ -14,6 +14,7 @@
14
14
 
15
15
  require_relative '../abstract/grouped_component'
16
16
  require_relative '../abstract/snapshot'
17
+ require_relative '../constants'
17
18
  require_relative '../mixins/healthy_resource_verifier'
18
19
  require_relative '../mixins/metric_verifier'
19
20
  require_relative '../mixins/snapshot_verifier'
@@ -50,7 +51,8 @@ module RubyAemAws
50
51
 
51
52
  def terminate_all_instances
52
53
  get_all_instances.each do |i|
53
- next if i.nil?
54
+ next if i.nil? || i.state.code != Constants::INSTANCE_STATE_CODE_RUNNING
55
+
54
56
  i.terminate
55
57
  i.wait_until_terminated
56
58
  end
@@ -61,6 +63,16 @@ module RubyAemAws
61
63
  instance.terminate
62
64
  instance.wait_until_terminated
63
65
  end
66
+
67
+ def get_tags
68
+ tags = []
69
+ get_all_instances.each do |i|
70
+ next if i.nil? || i.state.code != Constants::INSTANCE_STATE_CODE_RUNNING
71
+
72
+ tags.push(i.tags)
73
+ end
74
+ tags
75
+ end
64
76
  end
65
77
  end
66
78
  end
@@ -14,6 +14,7 @@
14
14
 
15
15
  require_relative '../abstract/grouped_component'
16
16
  require_relative '../abstract/snapshot'
17
+ require_relative '../constants'
17
18
  require_relative '../mixins/healthy_resource_verifier'
18
19
  require_relative '../mixins/metric_verifier'
19
20
  require_relative '../mixins/snapshot_verifier'
@@ -40,7 +41,7 @@ module RubyAemAws
40
41
  # - CloudWatchClient: AWS Cloudwatch Client.
41
42
  # - CloudWatchLogsClient: AWS Cloudwatch Logs Client.
42
43
  # - Ec2Resource: AWS EC2 Resource connection.
43
- # - ElbClient: AWS ElasticLoadBalancer Client.
44
+ # - ElbClient: AWS ElasticLoadBalancer v2 Client.
44
45
  # @return new RubyAemAws::FullSet::PublishDispatcher
45
46
  def initialize(stack_prefix, params)
46
47
  @descriptor = ComponentDescriptor.new(stack_prefix,
@@ -55,7 +56,8 @@ module RubyAemAws
55
56
 
56
57
  def terminate_all_instances
57
58
  get_all_instances.each do |i|
58
- next if i.nil?
59
+ next if i.nil? || i.state.code != Constants::INSTANCE_STATE_CODE_RUNNING
60
+
59
61
  i.terminate
60
62
  i.wait_until_terminated
61
63
  end
@@ -66,6 +68,16 @@ module RubyAemAws
66
68
  instance.terminate
67
69
  instance.wait_until_terminated
68
70
  end
71
+
72
+ def get_tags
73
+ tags = []
74
+ get_all_instances.each do |i|
75
+ next if i.nil? || i.state.code != Constants::INSTANCE_STATE_CODE_RUNNING
76
+
77
+ tags.push(i.tags)
78
+ end
79
+ tags
80
+ end
69
81
  end
70
82
  end
71
83
  end
@@ -29,7 +29,6 @@ module RubyAemAws
29
29
  include SNSTopic
30
30
  include S3Access
31
31
 
32
- # @param dynamodb_client AWS DynamoDB client connection
33
32
  # @param params Array of AWS Clients and Resource connections:
34
33
  # - CloudWatchClient: AWS Cloudwatch Client.
35
34
  # - CloudWatchLogsClient: AWS Cloudwatch Logs Client.
@@ -24,19 +24,34 @@ module RubyAemAws
24
24
  ALL_ACTIVE = [PENDING, RUNNING, SHUTTING_DOWN, STOPPING, STOPPED].freeze
25
25
  end
26
26
 
27
+ # API InstanceState codes https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_InstanceState.html
28
+ class InstanceStateCode
29
+ PENDING = 0
30
+ RUNNING = 16
31
+ SHUTTING_DOWN = 32
32
+ TERMINATED = 48
33
+ STOPPING = 64
34
+ STOPPED = 80
35
+ end
36
+
27
37
  class ELBInstanceState
28
- INSERVICE = 'InService'.freeze
29
- OUTOFSERVICE = 'OutOfService'.freeze
38
+ DRAINING = 'draining'.freeze
39
+ HEALTHY = 'healthy'.freeze
40
+ INITIAL = 'initial'.freeze
41
+ UNAVAILABLE = 'unavailable'.freeze
42
+ UNHEALTHY = 'unhealthy'.freeze
43
+ UNUSED = 'unused'.freeze
30
44
 
31
- ALL_ACTIVE = [INSERVICE, OUTOFSERVICE].freeze
45
+ ALL_ACTIVE = [HEALTHY, INITIAL, UNAVAILABLE, UNUSED].freeze
32
46
  end
33
47
 
34
48
  class Constants
35
- REGION_DEFAULT = 'ap-southeast-2'.freeze
49
+ REGION_DEFAULT = ENV['AWS_DEFAULT_REGION'] || ENV['aws_default_region'] || ENV['AWS_REGION'] || ENV['aws_region'] || 'ap-southeast-2'.freeze
36
50
  ACCESS_KEY_ID = ENV['AWS_ACCESS_KEY_ID'] || ENV['aws_access_key_id']
37
51
  SECRET_ACCESS_KEY = ENV['AWS_SECRET_ACCESS_KEY'] || ENV['aws_scret_access_key']
38
52
  PROFILE = ENV['AWS_PROFILE']
39
53
  INSTANCE_STATE_HEALTHY = RubyAemAws::InstanceState::RUNNING.freeze
40
- ELB_INSTANCE_INSERVICE = RubyAemAws::ELBInstanceState::INSERVICE.freeze
54
+ INSTANCE_STATE_CODE_RUNNING = RubyAemAws::InstanceStateCode::RUNNING
55
+ ELB_INSTANCE_INSERVICE = RubyAemAws::ELBInstanceState::HEALTHY.freeze
41
56
  end
42
57
  end
@@ -43,13 +43,6 @@ module RubyAemAws
43
43
 
44
44
  # Raise this when a component unexpectedly has more than one instance.
45
45
  class ExpectedSingleInstanceError < StandardError
46
- # def initialize(count, descriptor)
47
- # message << 'Expected exactly one instance'
48
- # message << " but got #{count}" unless count.nil?
49
- # message << "for (#{descriptor.stack_prefix}, #{descriptor.ec2.component}, #{descriptor.ec2.name})" unless descriptor.nil?
50
- # super(message)
51
- # end
52
-
53
46
  def initialize(msg = 'Expected exactly one instance')
54
47
  super
55
48
  end
@@ -48,7 +48,10 @@ module RubyAemAws
48
48
  return :no_elb if elb.nil?
49
49
 
50
50
  elb_running_instances = 0
51
- get_instances_state_from_elb(elb).each do |i|
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
 
@@ -57,12 +60,14 @@ module RubyAemAws
57
60
  return :misconfigured if desired_capacity < 1
58
61
  return :recovering if elb_running_instances < desired_capacity
59
62
  return :scaling if elb_running_instances > desired_capacity
63
+
60
64
  :ready
61
65
  end
62
66
 
63
67
  # @return true, if all EC2 instances within the ELB are running
64
68
  def wait_until_healthy
65
69
  raise ELBMisconfiguration if health_state.eql?(:misconfigured)
70
+
66
71
  sleep 60 while health_state.eql?(:recovering) || health_state.eql?(:scaling)
67
72
  return true if health_state.eql?(:ready)
68
73
  end
@@ -93,6 +98,7 @@ module RubyAemAws
93
98
  if tag.key == 'StackPrefix' && tag.value == descriptor.stack_prefix
94
99
  asg_matches_stack_prefix = true
95
100
  break if asg_matches_component
101
+
96
102
  next
97
103
  end
98
104
  if tag.key == 'Component' && tag.value == descriptor.ec2.component
@@ -105,41 +111,71 @@ module RubyAemAws
105
111
  nil
106
112
  end
107
113
 
108
- # @return ElasticLoadBalancer by StackPrefix and logical-id tags.
114
+ # @return ElasticLoadBalancer Arn.
109
115
  def find_elb(elb_client)
110
- elbs = elb_client.describe_load_balancers.load_balancer_descriptions
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)
111
131
  elbs.each do |elb|
112
132
  elb_matches_stack_prefix = false
113
- elb_matches_logical_id = false
114
- tag_descriptions = elb_client.describe_tags(load_balancer_names: [elb.load_balancer_name]).tag_descriptions
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
+
115
140
  next if tag_descriptions.empty?
116
141
 
117
142
  tags = tag_descriptions[0].tags
118
143
  tags.each do |tag|
119
- if tag.key == 'StackPrefix' && tag.value == descriptor.stack_prefix
120
- elb_matches_stack_prefix = true
121
- break if elb_matches_logical_id
122
- next
123
- end
124
- if tag.key == 'aws:cloudformation:logical-id' && tag.value == descriptor.elb.id
125
- elb_matches_logical_id = true
126
- break if elb_matches_stack_prefix
127
- end
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
146
+
147
+ return elb.load_balancer_arn if elb_matches_stack_prefix && elb_matches_name
148
+
149
+ next
128
150
  end
129
- return elb if elb_matches_stack_prefix && elb_matches_logical_id
130
151
  end
131
152
  nil
132
153
  end
133
154
 
134
- def get_instances_state_from_elb(elb)
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
+
135
169
  stack_prefix_instances = []
136
- elb.instances.each do |i|
137
- instance = get_instance_by_id(i.instance_id)
170
+ targets.each do |t|
171
+ instance = get_instance_by_id(t.target.id)
138
172
  next if instance.nil?
173
+
139
174
  instance.tags.each do |tag|
140
175
  next if tag.key != 'StackPrefix'
141
176
  break if tag.value != descriptor.stack_prefix
142
- stack_prefix_instances.push(id: i.instance_id, state: instance.state.name)
177
+
178
+ stack_prefix_instances.push(id: t.target.id, state: instance.state.name)
143
179
  end
144
180
  end
145
181
  stack_prefix_instances
@@ -53,18 +53,19 @@ 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.describe_instance_health(load_balancer_name: elb.load_balancer_name)
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.instance_states.each do |i|
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
68
+
68
69
  :ready
69
70
  end
70
71
 
@@ -86,28 +87,34 @@ module RubyAemAws
86
87
  # puts(" Instance #{i.instance_id}: #{i.health_status}")
87
88
  # end
88
89
  # end
89
-
90
- desired_capacity = asg.desired_capacity
91
90
  instances_inservice = 0
92
- asg.instances.each do |instances|
93
- instances_inservice += 1 if instances.health_status.eql? 'Healthy'
91
+ desired_capacity = asg.desired_capacity
92
+
93
+ get_all_instances.each do |i|
94
+ next if i.nil? || i.state.code != Constants::INSTANCE_STATE_CODE_RUNNING
95
+ return false if i.state.name != Constants::INSTANCE_STATE_HEALTHY
96
+
97
+ instances_inservice += 1
94
98
  end
95
99
 
96
100
  return :misconfigured if desired_capacity < 1
97
101
  return :recovering if instances_inservice < desired_capacity
98
102
  return :scaling if instances_inservice > desired_capacity
103
+
99
104
  :ready
100
105
  end
101
106
 
102
107
  # @return true, if all instances within the ELB are inService
103
108
  def wait_until_healthy_elb
104
109
  raise ELBMisconfiguration if health_state_elb.eql?(:misconfigured)
110
+
105
111
  sleep 60 while health_state_elb.eql?(:recovering) || health_state_elb.eql?(:scaling)
106
112
  return true if health_state_elb.eql?(:ready)
107
113
  end
108
114
 
109
115
  def wait_until_healthy_asg
110
116
  raise ASGMisconfiguration if health_state_asg.eql?(:misconfigured)
117
+
111
118
  sleep 60 while health_state_asg.eql?(:recovering) || health_state_asg.eql?(:scaling)
112
119
  return true if health_state_asg.eql?(:ready)
113
120
  end
@@ -138,6 +145,7 @@ module RubyAemAws
138
145
  if tag.key == 'StackPrefix' && tag.value == descriptor.stack_prefix
139
146
  asg_matches_stack_prefix = true
140
147
  break if asg_matches_component
148
+
141
149
  next
142
150
  end
143
151
  if tag.key == 'Component' && tag.value == descriptor.ec2.component
@@ -150,30 +158,58 @@ module RubyAemAws
150
158
  nil
151
159
  end
152
160
 
153
- # @return ElasticLoadBalancer by StackPrefix and logical-id tags.
161
+ # @return ElasticLoadBalancer Arn.
154
162
  def find_elb(elb_client)
155
- elbs = elb_client.describe_load_balancers.load_balancer_descriptions
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)
156
178
  elbs.each do |elb|
157
179
  elb_matches_stack_prefix = false
158
- elb_matches_logical_id = false
159
- tag_descriptions = elb_client.describe_tags(load_balancer_names: [elb.load_balancer_name]).tag_descriptions
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
+
160
187
  next if tag_descriptions.empty?
161
188
 
162
189
  tags = tag_descriptions[0].tags
163
190
  tags.each do |tag|
164
- if tag.key == 'StackPrefix' && tag.value == descriptor.stack_prefix
165
- elb_matches_stack_prefix = true
166
- break if elb_matches_logical_id
167
- next
168
- end
169
- if tag.key == 'aws:cloudformation:logical-id' && tag.value == descriptor.elb.id
170
- elb_matches_logical_id = true
171
- break if elb_matches_stack_prefix
172
- end
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
193
+
194
+ return elb.load_balancer_arn if elb_matches_stack_prefix && elb_matches_name
173
195
  end
174
- return elb if elb_matches_stack_prefix && elb_matches_logical_id
175
196
  end
176
197
  nil
177
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
178
214
  end
179
215
  end
@@ -22,7 +22,8 @@ module RubyAemAws
22
22
  def healthy?
23
23
  has_instance = false
24
24
  get_all_instances.each do |i|
25
- next if i.nil? || i.state.code != 16
25
+ next if i.nil? || i.state.code != Constants::INSTANCE_STATE_CODE_RUNNING
26
+
26
27
  has_instance = true
27
28
  return false if i.state.name != Constants::INSTANCE_STATE_HEALTHY
28
29
  end
@@ -32,7 +33,8 @@ module RubyAemAws
32
33
  def wait_until_healthy
33
34
  instance_healthy = false
34
35
  get_all_instances.each do |i|
35
- next if i.nil? || i.state.code != 16
36
+ next if i.nil? || i.state.code != Constants::INSTANCE_STATE_CODE_RUNNING
37
+
36
38
  i.wait_until_running
37
39
  instance_healthy = true
38
40
  return false if i.state.name != Constants::INSTANCE_STATE_HEALTHY
@@ -21,6 +21,7 @@ module RubyAemAws
21
21
  descriptions = []
22
22
  get_all_instances.each do |i|
23
23
  next if i.nil?
24
+
24
25
  descriptions.push(describe_instance(i))
25
26
  end
26
27
  descriptions.join(', ')
@@ -48,6 +48,7 @@ module RubyAemAws
48
48
 
49
49
  instances.each do |instance|
50
50
  next if instance.nil?
51
+
51
52
  instance_id = instance.instance_id
52
53
  dimensions_value = instance.instance_id
53
54
 
@@ -73,6 +74,7 @@ module RubyAemAws
73
74
 
74
75
  instances.each do |instance|
75
76
  next if instance.nil?
77
+
76
78
  instance_id = instance.instance_id
77
79
  log_stream_name = "#{@descriptor.ec2.component}/#{instance_id}"
78
80
 
@@ -106,6 +108,7 @@ module RubyAemAws
106
108
 
107
109
  instances.each do |instance|
108
110
  next if instance.nil?
111
+
109
112
  instance_id = instance.instance_id
110
113
  log_stream_name = "#{@descriptor.ec2.component}/#{instance_id}"
111
114
 
@@ -167,7 +170,7 @@ module RubyAemAws
167
170
  return true unless response.events.empty?
168
171
  end
169
172
 
170
- # @param loggroup Cloudwatch loggroup name
173
+ # @param loggroup_name Cloudwatch loggroup name
171
174
  # @return True if Cloudwatch loggroup exists
172
175
  def loggroup?(loggroup_name)
173
176
  namespace = 'AWS/Logs'
@@ -28,6 +28,7 @@ module RubyAemAws
28
28
  has_snapshot = false
29
29
  get_snapshots_by_type(snapshot_type).each do |s|
30
30
  next if s.nil?
31
+
31
32
  has_snapshot = true
32
33
  end
33
34
  has_snapshot
metadata CHANGED
@@ -1,71 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_aem_aws
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
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: 2019-04-03 00:00:00.000000000 Z
11
+ date: 2020-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: '3.0'
19
+ version: 3.0.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: '3.0'
26
+ version: 3.0.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: retries
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - '='
32
32
  - !ruby/object:Gem::Version
33
33
  version: 0.0.5
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - '='
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.0.5
41
+ - !ruby/object:Gem::Dependency
42
+ name: tuples
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.1.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.1.0
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rspec
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - "~>"
59
+ - - '='
46
60
  - !ruby/object:Gem::Version
47
- version: '3.4'
61
+ version: 3.8.0
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - "~>"
66
+ - - '='
53
67
  - !ruby/object:Gem::Version
54
- version: '3.4'
68
+ version: 3.8.0
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: yard
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
- - - "~>"
73
+ - - '='
60
74
  - !ruby/object:Gem::Version
61
- version: 0.9.5
75
+ version: 0.9.20
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
- - - "~>"
80
+ - - '='
67
81
  - !ruby/object:Gem::Version
68
- version: 0.9.5
82
+ version: 0.9.20
69
83
  description: ruby_aem_aws is a Ruby client for Shine Solutions Adobe Experience Manager
70
84
  (AEM) Platform on AWS
71
85
  email:
@@ -74,6 +88,7 @@ executables: []
74
88
  extensions: []
75
89
  extra_rdoc_files: []
76
90
  files:
91
+ - conf/gem.yaml
77
92
  - lib/ruby_aem_aws.rb
78
93
  - lib/ruby_aem_aws/abstract/cloudwatch.rb
79
94
  - lib/ruby_aem_aws/abstract/component.rb