ruby_aem_aws 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/ruby_aem_aws.rb +74 -0
- data/lib/ruby_aem_aws/component/abstract_component.rb +39 -0
- data/lib/ruby_aem_aws/component/abstract_grouped_component.rb +39 -0
- data/lib/ruby_aem_aws/component/abstract_single_component.rb +35 -0
- data/lib/ruby_aem_aws/component/author.rb +44 -0
- data/lib/ruby_aem_aws/component/author_dispatcher.rb +55 -0
- data/lib/ruby_aem_aws/component/author_primary.rb +42 -0
- data/lib/ruby_aem_aws/component/author_publish_dispatcher.rb +45 -0
- data/lib/ruby_aem_aws/component/author_standby.rb +44 -0
- data/lib/ruby_aem_aws/component/chaos_monkey.rb +50 -0
- data/lib/ruby_aem_aws/component/component_descriptor.rb +27 -0
- data/lib/ruby_aem_aws/component/mixins/healthy_count_verifier.rb +135 -0
- data/lib/ruby_aem_aws/component/mixins/healthy_state_verifier.rb +36 -0
- data/lib/ruby_aem_aws/component/mixins/instance_describer.rb +33 -0
- data/lib/ruby_aem_aws/component/mixins/metric_verifier.rb +43 -0
- data/lib/ruby_aem_aws/component/orchestrator.rb +50 -0
- data/lib/ruby_aem_aws/component/publish.rb +50 -0
- data/lib/ruby_aem_aws/component/publish_dispatcher.rb +53 -0
- data/lib/ruby_aem_aws/consolidated_stack.rb +35 -0
- data/lib/ruby_aem_aws/constants.rb +32 -0
- data/lib/ruby_aem_aws/error.rb +36 -0
- data/lib/ruby_aem_aws/full_set_stack.rb +69 -0
- metadata +123 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 39ea851d8557738c522f0f06fd811dee54378d83
|
4
|
+
data.tar.gz: 931e7372b825518b9e0ad3b23498b0013831c0bb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: da5c388b8803836046e97f8af7ce3308fbd419b230a7fa86483d54508c0f8f0bfdbeb149cc6a3c41dffb2577ddd8387c3a3443b09835f64a75221b86eb53c312
|
7
|
+
data.tar.gz: f66ff53f11b7f035fa337ce3524f5c9630c489b453e799887b09e6e56f6e7ec2237c90e9a7acc88a0332d6241b66a23ead413f9eaa94e2d30aa09c12bb229535
|
data/lib/ruby_aem_aws.rb
ADDED
@@ -0,0 +1,74 @@
|
|
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 'ruby_aem_aws/consolidated_stack'
|
16
|
+
require_relative 'ruby_aem_aws/full_set_stack'
|
17
|
+
|
18
|
+
module RubyAemAws
|
19
|
+
# AemAws class represents the AWS stack for AEM.
|
20
|
+
class AemAws
|
21
|
+
# @param conf configuration hash of the following configuration values:
|
22
|
+
# - region: the AWS region (eg ap-southeast-2)
|
23
|
+
# @return new RubyAemAws::AemAws instance
|
24
|
+
def initialize(conf = {})
|
25
|
+
conf[:region] ||= Constants::REGION_DEFAULT
|
26
|
+
|
27
|
+
aws = AwsCreator.create_aws
|
28
|
+
@ec2_client = aws[:Ec2Client]
|
29
|
+
@ec2_resource = aws[:Ec2Resource]
|
30
|
+
@elb_client = aws[:ElbClient]
|
31
|
+
@auto_scaling_client = aws[:AutoScalingClient]
|
32
|
+
# The V2 API only supports Application ELBs, and we currently use Classic.
|
33
|
+
# @elb_client = Aws::ElasticLoadBalancingV2::Client.new(region: conf[:region])
|
34
|
+
@cloud_watch_client = aws[:CloudWatchClient]
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_connection
|
38
|
+
result = []
|
39
|
+
@ec2_client.describe_regions.regions.each do |region|
|
40
|
+
result.push("Region #{region.region_name} (#{region.endpoint})")
|
41
|
+
end
|
42
|
+
!result.empty?
|
43
|
+
end
|
44
|
+
|
45
|
+
# Create a consolidated instance.
|
46
|
+
#
|
47
|
+
# @param stack_prefix AWS tag: StackPrefix
|
48
|
+
# @return new RubyAemAws::ConsolidatedStack instance
|
49
|
+
def consolidated(stack_prefix)
|
50
|
+
RubyAemAws::ConsolidatedStack.new(stack_prefix, @ec2_resource, @cloud_watch_client)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Create a full set instance.
|
54
|
+
#
|
55
|
+
# @param stack_prefix AWS tag: StackPrefix
|
56
|
+
# @return new RubyAemAws::FullSetStack instance
|
57
|
+
def full_set(stack_prefix)
|
58
|
+
RubyAemAws::FullSetStack.new(stack_prefix, @ec2_resource, @elb_client, @auto_scaling_client, @cloud_watch_client)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# Encapsulate AWS class creation for mocking.
|
63
|
+
class AwsCreator
|
64
|
+
def self.create_aws(region = Constants::REGION_DEFAULT)
|
65
|
+
{
|
66
|
+
Ec2Client: Aws::EC2::Client.new(region: region),
|
67
|
+
Ec2Resource: Aws::EC2::Resource.new(region: region),
|
68
|
+
ElbClient: Aws::ElasticLoadBalancing::Client.new(region: region),
|
69
|
+
AutoScalingClient: Aws::AutoScaling::Client.new(region: region),
|
70
|
+
CloudWatchClient: Aws::CloudWatch::Client.new(region: region)
|
71
|
+
}
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,39 @@
|
|
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_descriptor'
|
16
|
+
require_relative 'mixins/instance_describer'
|
17
|
+
require_relative '../error'
|
18
|
+
|
19
|
+
module RubyAemAws
|
20
|
+
# Add common methods to all Components.
|
21
|
+
module AbstractComponent
|
22
|
+
include Component
|
23
|
+
include InstanceDescriber
|
24
|
+
|
25
|
+
def to_s
|
26
|
+
"#{self.class.name.split('::').last}(#{@descriptor.stack_prefix unless @descriptor.nil?})"
|
27
|
+
end
|
28
|
+
|
29
|
+
private def filter_for_descriptor
|
30
|
+
{
|
31
|
+
filters: [
|
32
|
+
{ name: 'tag:StackPrefix', values: [@descriptor.stack_prefix] },
|
33
|
+
{ name: 'tag:Component', values: [@descriptor.ec2.component] },
|
34
|
+
{ name: 'tag:Name', values: [@descriptor.ec2.name] }
|
35
|
+
]
|
36
|
+
}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,39 @@
|
|
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 'aws-sdk'
|
16
|
+
require_relative 'abstract_component'
|
17
|
+
|
18
|
+
module RubyAemAws
|
19
|
+
# Add common methods to all Components.
|
20
|
+
module AbstractGroupedComponent
|
21
|
+
include AbstractComponent
|
22
|
+
|
23
|
+
def get_all_instances
|
24
|
+
ec2_resource.instances(filter_for_descriptor)
|
25
|
+
end
|
26
|
+
|
27
|
+
def get_instance_by_id(instance_id)
|
28
|
+
ec2_resource.instance(instance_id)
|
29
|
+
end
|
30
|
+
|
31
|
+
def get_num_of_instances
|
32
|
+
get_all_instances.entries.length
|
33
|
+
end
|
34
|
+
|
35
|
+
def get_random_instance
|
36
|
+
get_all_instances.entries.sample
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,35 @@
|
|
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 'aws-sdk'
|
16
|
+
require_relative 'abstract_component'
|
17
|
+
|
18
|
+
module RubyAemAws
|
19
|
+
# Add common methods to all Components.
|
20
|
+
module AbstractSingleComponent
|
21
|
+
include AbstractComponent
|
22
|
+
|
23
|
+
def get_instance
|
24
|
+
instances = ec2_resource.instances(filter_for_descriptor).select { |instance| InstanceState::ALL_ACTIVE.include?(instance.state.name) }
|
25
|
+
count = instances.count
|
26
|
+
raise RubyAemAws::ExpectedSingleInstanceError if count > 1
|
27
|
+
return nil if count.zero?
|
28
|
+
instances.first
|
29
|
+
end
|
30
|
+
|
31
|
+
def get_all_instances
|
32
|
+
[get_instance]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,44 @@
|
|
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 'author_primary'
|
16
|
+
require_relative 'author_standby'
|
17
|
+
|
18
|
+
module RubyAemAws
|
19
|
+
module Component
|
20
|
+
# Interface to the AWS instances running the Author components of a full-set AEM stack.
|
21
|
+
class Author
|
22
|
+
attr_reader :author_primary, :author_standby
|
23
|
+
|
24
|
+
# ELB_ID = 'AuthorLoadBalancer'.freeze
|
25
|
+
# ELB_NAME = 'AEM Author Load Balancer'.freeze
|
26
|
+
|
27
|
+
# @param stack_prefix AWS tag: StackPrefix
|
28
|
+
# @param ec2_resource AWS EC2 resource
|
29
|
+
# @return new RubyAemAws::FullSet::Author
|
30
|
+
def initialize(stack_prefix, ec2_resource, cloud_watch_client)
|
31
|
+
@author_primary = Component::AuthorPrimary.new(stack_prefix, ec2_resource, cloud_watch_client)
|
32
|
+
@author_standby = Component::AuthorStandby.new(stack_prefix, ec2_resource, cloud_watch_client)
|
33
|
+
end
|
34
|
+
|
35
|
+
# def terminate_primary_instance
|
36
|
+
|
37
|
+
# def terminate_standby_instance
|
38
|
+
|
39
|
+
# def wait_until_healthy
|
40
|
+
# - wait until both primary and standby are healthy
|
41
|
+
# end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,55 @@
|
|
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_grouped_component'
|
16
|
+
require_relative 'mixins/healthy_count_verifier'
|
17
|
+
require_relative 'mixins/metric_verifier'
|
18
|
+
require_relative 'component_descriptor'
|
19
|
+
|
20
|
+
module RubyAemAws
|
21
|
+
module Component
|
22
|
+
# Interface to the AWS instances playing and supporting the AuthorDispatcher role in a full-set AEM stack.
|
23
|
+
class AuthorDispatcher
|
24
|
+
attr_reader :descriptor, :ec2_resource, :asg_client, :elb_client, :cloud_watch_client
|
25
|
+
include AbstractGroupedComponent
|
26
|
+
include HealthyCountVerifier
|
27
|
+
include MetricVerifier
|
28
|
+
|
29
|
+
EC2_COMPONENT = 'author-dispatcher'.freeze
|
30
|
+
EC2_NAME = 'AEM Author Dispatcher'.freeze
|
31
|
+
ELB_ID = 'AuthorDispatcherLoadBalancer'.freeze
|
32
|
+
ELB_NAME = 'AEM Author Dispatcher Load Balancer'.freeze
|
33
|
+
|
34
|
+
# @param stack_prefix AWS tag: StackPrefix
|
35
|
+
# @param ec2_resource AWS EC2 resource
|
36
|
+
# @param asg_client AWS AutoScalingGroup client
|
37
|
+
# @param elb_client AWS ElasticLoadBalancer client
|
38
|
+
# @param cloud_watch_client AWS CloudWatch client
|
39
|
+
# @return new RubyAemAws::FullSet::AuthorDispatcher
|
40
|
+
def initialize(stack_prefix, ec2_resource, asg_client, elb_client, cloud_watch_client)
|
41
|
+
@descriptor = ComponentDescriptor.new(stack_prefix,
|
42
|
+
EC2Descriptor.new(EC2_COMPONENT, EC2_NAME),
|
43
|
+
ELBDescriptor.new(ELB_ID, ELB_NAME))
|
44
|
+
@ec2_resource = ec2_resource
|
45
|
+
@elb_client = elb_client
|
46
|
+
@asg_client = asg_client
|
47
|
+
@cloud_watch_client = cloud_watch_client
|
48
|
+
end
|
49
|
+
|
50
|
+
# def terminate_all_instances
|
51
|
+
|
52
|
+
# def terminate_random_instance
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,42 @@
|
|
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_single_component'
|
16
|
+
require_relative 'mixins/healthy_state_verifier'
|
17
|
+
require_relative 'mixins/metric_verifier'
|
18
|
+
|
19
|
+
module RubyAemAws
|
20
|
+
module Component
|
21
|
+
# Interface to the AWS instance running the Author-Primary component of a full-set AEM stack.
|
22
|
+
class AuthorPrimary
|
23
|
+
attr_reader :descriptor, :ec2_resource, :cloud_watch_client
|
24
|
+
include AbstractSingleComponent
|
25
|
+
include HealthyStateVerifier
|
26
|
+
include MetricVerifier
|
27
|
+
|
28
|
+
EC2_COMPONENT = 'author-primary'.freeze
|
29
|
+
EC2_NAME = 'AEM Author - Primary'.freeze
|
30
|
+
|
31
|
+
# @param stack_prefix AWS tag: StackPrefix
|
32
|
+
# @param ec2_resource AWS EC2 resource
|
33
|
+
# @return new RubyAemAws::FullSet::AuthorPrimary
|
34
|
+
def initialize(stack_prefix, ec2_resource, cloud_watch_client)
|
35
|
+
@descriptor = ComponentDescriptor.new(stack_prefix,
|
36
|
+
EC2Descriptor.new(EC2_COMPONENT, EC2_NAME))
|
37
|
+
@ec2_resource = ec2_resource
|
38
|
+
@cloud_watch_client = cloud_watch_client
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,45 @@
|
|
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 'aws-sdk'
|
16
|
+
require_relative 'abstract_single_component'
|
17
|
+
require_relative 'mixins/healthy_state_verifier'
|
18
|
+
require_relative 'mixins/metric_verifier'
|
19
|
+
require_relative 'component_descriptor'
|
20
|
+
|
21
|
+
module RubyAemAws
|
22
|
+
module Component
|
23
|
+
# Interface to a single AWS instance running all three AEM components as a consolidated stack.
|
24
|
+
class AuthorPublishDispatcher
|
25
|
+
attr_reader :descriptor, :ec2_resource, :cloud_watch_client
|
26
|
+
include AbstractSingleComponent
|
27
|
+
include HealthyStateVerifier
|
28
|
+
include MetricVerifier
|
29
|
+
|
30
|
+
EC2_COMPONENT = 'author-publish-dispatcher'.freeze
|
31
|
+
EC2_NAME = 'AuthorPublishDispatcher'.freeze
|
32
|
+
|
33
|
+
# @param stack_prefix AWS tag: StackPrefix
|
34
|
+
# @param ec2_resource AWS EC2 resource
|
35
|
+
# @param cloud_watch_client AWS CloudWatch client
|
36
|
+
# @return new RubyAemAws::Consolidated::AuthorPublishDispatcher instance
|
37
|
+
def initialize(stack_prefix, ec2_resource, cloud_watch_client)
|
38
|
+
@descriptor = ComponentDescriptor.new(stack_prefix,
|
39
|
+
EC2Descriptor.new(EC2_COMPONENT, EC2_NAME))
|
40
|
+
@ec2_resource = ec2_resource
|
41
|
+
@cloud_watch_client = cloud_watch_client
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,44 @@
|
|
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_grouped_component'
|
16
|
+
require_relative 'mixins/healthy_state_verifier'
|
17
|
+
require_relative 'mixins/metric_verifier'
|
18
|
+
|
19
|
+
module RubyAemAws
|
20
|
+
module Component
|
21
|
+
# Interface to the AWS instance running the Author-Standby component of a full-set AEM stack.
|
22
|
+
class AuthorStandby
|
23
|
+
attr_reader :descriptor, :ec2_resource, :cloud_watch_client
|
24
|
+
include AbstractGroupedComponent
|
25
|
+
# Can't verify state by count as there's no ASG.
|
26
|
+
include HealthyStateVerifier
|
27
|
+
include MetricVerifier
|
28
|
+
|
29
|
+
EC2_COMPONENT = 'author-standby'.freeze
|
30
|
+
EC2_NAME = 'AEM Author - Standby'.freeze
|
31
|
+
|
32
|
+
# @param stack_prefix AWS tag: StackPrefix
|
33
|
+
# @param ec2_resource AWS EC2 resource
|
34
|
+
# @param cloud_watch_client AWS CloudWatch client
|
35
|
+
# @return new RubyAemAws::FullSet::AuthorStandby
|
36
|
+
def initialize(stack_prefix, ec2_resource, cloud_watch_client)
|
37
|
+
@descriptor = ComponentDescriptor.new(stack_prefix,
|
38
|
+
EC2Descriptor.new(EC2_COMPONENT, EC2_NAME))
|
39
|
+
@ec2_resource = ec2_resource
|
40
|
+
@cloud_watch_client = cloud_watch_client
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,50 @@
|
|
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_single_component'
|
16
|
+
require_relative 'mixins/healthy_state_verifier'
|
17
|
+
require_relative 'mixins/metric_verifier'
|
18
|
+
|
19
|
+
module RubyAemAws
|
20
|
+
module Component
|
21
|
+
# Interface to the AWS instance running the ChaosMonkey component of a full-set AEM stack.
|
22
|
+
class ChaosMonkey
|
23
|
+
attr_reader :descriptor, :ec2_resource, :asg_client, :cloud_watch_client
|
24
|
+
include AbstractSingleComponent
|
25
|
+
# Can't verify state by count as there's no ELB.
|
26
|
+
include HealthyStateVerifier
|
27
|
+
include MetricVerifier
|
28
|
+
|
29
|
+
EC2_COMPONENT = 'chaos-monkey'.freeze
|
30
|
+
EC2_NAME = 'AEM Chaos Monkey'.freeze
|
31
|
+
|
32
|
+
# @param stack_prefix AWS tag: StackPrefix
|
33
|
+
# @param ec2_resource AWS EC2 resource
|
34
|
+
# @param asg_client AWS AutoScalingGroup client
|
35
|
+
# @param cloud_watch_client AWS CloudWatch client
|
36
|
+
# @return new RubyAemAws::FullSet::ChaosMonkey
|
37
|
+
def initialize(stack_prefix, ec2_resource, asg_client, cloud_watch_client)
|
38
|
+
@descriptor = ComponentDescriptor.new(stack_prefix,
|
39
|
+
EC2Descriptor.new(EC2_COMPONENT, EC2_NAME))
|
40
|
+
@ec2_resource = ec2_resource
|
41
|
+
@asg_client = asg_client
|
42
|
+
@cloud_watch_client = cloud_watch_client
|
43
|
+
end
|
44
|
+
|
45
|
+
# def terminate_all_instances
|
46
|
+
|
47
|
+
# def terminate_random_instance
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,27 @@
|
|
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
|
+
module Component
|
17
|
+
ComponentDescriptor = Struct.new(:stack_prefix_in, :ec2, :elb) do
|
18
|
+
def stack_prefix
|
19
|
+
# Unwrap from {:stack_prefix = value} to the value if necessary.
|
20
|
+
return stack_prefix_in[:stack_prefix] if stack_prefix_in.is_a? Hash
|
21
|
+
stack_prefix_in
|
22
|
+
end
|
23
|
+
end
|
24
|
+
EC2Descriptor = Struct.new(:component, :name)
|
25
|
+
ELBDescriptor = Struct.new(:id, :name)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,135 @@
|
|
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 '../../constants'
|
16
|
+
|
17
|
+
module RubyAemAws
|
18
|
+
# Mixin for checking health of a component via ELB 'healthy' count vs ASG desired_capacity.
|
19
|
+
# Add this to a component to make it capable of determining its own health.
|
20
|
+
module HealthyCountVerifier
|
21
|
+
# Aggregate health_states considered healthy.
|
22
|
+
# @return health_state is ready or scaling.
|
23
|
+
def healthy?
|
24
|
+
%i[ready scaling].include? health_state
|
25
|
+
end
|
26
|
+
|
27
|
+
# Provides detail of the state of the instances comprising the component.
|
28
|
+
# @return one of:
|
29
|
+
# - no_asg: AutoScalingGroup could not be located (by StackPrefix and Component tags).
|
30
|
+
# - no_elb: ElasticLoadBalancer could not be located (by StackPrefix and aws:cloudformation:logical-id tags).
|
31
|
+
# - misconfigured: AutoScalingGroup.desired_capacity is less than 1.
|
32
|
+
# - recovering: ELB running instance count is less than AutoScalingGroup.desired_capacity.
|
33
|
+
# - scaling: ELB running instance count is more than AutoScalingGroup.desired_capacity.
|
34
|
+
# - ready: ELB running instance count is equal to AutoScalingGroup.desired_capacity.
|
35
|
+
def health_state
|
36
|
+
asg = find_auto_scaling_group(asg_client)
|
37
|
+
return :no_asg if asg.nil?
|
38
|
+
|
39
|
+
# Debug:
|
40
|
+
# unless asg.nil?
|
41
|
+
# puts("ASG: #{asg} #{asg.auto_scaling_group_name} (#{asg.desired_capacity})")
|
42
|
+
# asg.instances.each do |i|
|
43
|
+
# puts(" Instance #{i.instance_id}: #{i.health_status}")
|
44
|
+
# end
|
45
|
+
# end
|
46
|
+
|
47
|
+
elb = find_elb(elb_client)
|
48
|
+
return :no_elb if elb.nil?
|
49
|
+
|
50
|
+
elb_running_instances = 0
|
51
|
+
# puts("ELB: #{elb.load_balancer_name} (#{elb.instances.length})")
|
52
|
+
get_instances_state_from_elb(elb).each do |i|
|
53
|
+
# puts(" Instance #{i[:id]}: #{i[:state]}")
|
54
|
+
elb_running_instances += 1 if i[:state] == RubyAemAws::Constants::INSTANCE_STATE_HEALTHY
|
55
|
+
end
|
56
|
+
|
57
|
+
desired_capacity = asg.desired_capacity
|
58
|
+
# puts("calc health_state: #{elb_running_instances} / #{desired_capacity}")
|
59
|
+
return :misconfigured if desired_capacity < 1
|
60
|
+
|
61
|
+
return :recovering if elb_running_instances < desired_capacity
|
62
|
+
return :scaling if elb_running_instances > desired_capacity
|
63
|
+
:ready
|
64
|
+
end
|
65
|
+
|
66
|
+
def wait_until_healthy
|
67
|
+
raise NotYetImplementedError
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
# @return AutoScalingGroup by StackPrefix and Component tags.
|
73
|
+
def find_auto_scaling_group(asg_client)
|
74
|
+
autoscaling_groups = asg_client.describe_auto_scaling_groups
|
75
|
+
autoscaling_groups.auto_scaling_groups.each do |autoscaling_group|
|
76
|
+
asg_matches_stack_prefix = false
|
77
|
+
asg_matches_component = false
|
78
|
+
tags = autoscaling_group.tags
|
79
|
+
tags.each do |tag|
|
80
|
+
if tag.key == 'StackPrefix' && tag.value == descriptor.stack_prefix
|
81
|
+
asg_matches_stack_prefix = true
|
82
|
+
break if asg_matches_component
|
83
|
+
next
|
84
|
+
end
|
85
|
+
if tag.key == 'Component' && tag.value == descriptor.ec2.component
|
86
|
+
asg_matches_component = true
|
87
|
+
break if asg_matches_stack_prefix
|
88
|
+
end
|
89
|
+
end
|
90
|
+
return autoscaling_group if asg_matches_stack_prefix && asg_matches_component
|
91
|
+
end
|
92
|
+
nil
|
93
|
+
end
|
94
|
+
|
95
|
+
# @return ElasticLoadBalancer by StackPrefix and logical-id tags.
|
96
|
+
def find_elb(elb_client)
|
97
|
+
elbs = elb_client.describe_load_balancers.load_balancer_descriptions
|
98
|
+
elbs.each do |elb|
|
99
|
+
elb_matches_stack_prefix = false
|
100
|
+
elb_matches_logical_id = false
|
101
|
+
tag_descriptions = elb_client.describe_tags(load_balancer_names: [elb.load_balancer_name]).tag_descriptions
|
102
|
+
next if tag_descriptions.empty?
|
103
|
+
|
104
|
+
tags = tag_descriptions[0].tags
|
105
|
+
tags.each do |tag|
|
106
|
+
if tag.key == 'StackPrefix' && tag.value == descriptor.stack_prefix
|
107
|
+
elb_matches_stack_prefix = true
|
108
|
+
break if elb_matches_logical_id
|
109
|
+
next
|
110
|
+
end
|
111
|
+
if tag.key == 'aws:cloudformation:logical-id' && tag.value == descriptor.elb.id
|
112
|
+
elb_matches_logical_id = true
|
113
|
+
break if elb_matches_stack_prefix
|
114
|
+
end
|
115
|
+
end
|
116
|
+
return elb if elb_matches_stack_prefix && elb_matches_logical_id
|
117
|
+
end
|
118
|
+
nil
|
119
|
+
end
|
120
|
+
|
121
|
+
def get_instances_state_from_elb(elb)
|
122
|
+
stack_prefix_instances = []
|
123
|
+
elb.instances.each do |i|
|
124
|
+
instance = get_instance_by_id(i.instance_id)
|
125
|
+
next if instance.nil?
|
126
|
+
instance.tags.each do |tag|
|
127
|
+
next if tag.key != 'StackPrefix'
|
128
|
+
break if tag.value != descriptor.stack_prefix
|
129
|
+
stack_prefix_instances.push(id: i.instance_id, state: instance.state.name)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
stack_prefix_instances
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,36 @@
|
|
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 '../../constants'
|
16
|
+
|
17
|
+
module RubyAemAws
|
18
|
+
# Mixin for checking health of a component via EC2 instance state.
|
19
|
+
# Add this to a component to make it capable of determining its own health.
|
20
|
+
module HealthyStateVerifier
|
21
|
+
# @return true if there are one or more instances matching the descriptor and they are all healthy.
|
22
|
+
def healthy?
|
23
|
+
has_instance = false
|
24
|
+
get_all_instances.each do |i|
|
25
|
+
next if i.nil?
|
26
|
+
has_instance = true
|
27
|
+
return false if i.state.name != Constants::INSTANCE_STATE_HEALTHY
|
28
|
+
end
|
29
|
+
has_instance
|
30
|
+
end
|
31
|
+
|
32
|
+
def wait_until_healthy
|
33
|
+
raise NotYetImplementedError
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,33 @@
|
|
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 describing component EC2 instance state.
|
17
|
+
# Add this to a component to make it capable of describing its instances.
|
18
|
+
module InstanceDescriber
|
19
|
+
# @return a string containing instance descriptions.
|
20
|
+
def describe_instances
|
21
|
+
descriptions = []
|
22
|
+
get_all_instances.each do |i|
|
23
|
+
next if i.nil?
|
24
|
+
descriptions.push(describe_instance(i))
|
25
|
+
end
|
26
|
+
descriptions.join(', ')
|
27
|
+
end
|
28
|
+
|
29
|
+
def describe_instance(instance)
|
30
|
+
"#{instance.instance_id} (#{instance.state.name})"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,43 @@
|
|
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
|
@@ -0,0 +1,50 @@
|
|
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_single_component'
|
16
|
+
require_relative 'mixins/healthy_state_verifier'
|
17
|
+
require_relative 'mixins/metric_verifier'
|
18
|
+
|
19
|
+
module RubyAemAws
|
20
|
+
module Component
|
21
|
+
# Interface to the AWS instance running the Orchestrator component of a full-set AEM stack.
|
22
|
+
class Orchestrator
|
23
|
+
attr_reader :descriptor, :ec2_resource, :asg_client, :cloud_watch_client
|
24
|
+
include AbstractSingleComponent
|
25
|
+
# Can't verify state by count as there's no ELB.
|
26
|
+
include HealthyStateVerifier
|
27
|
+
include MetricVerifier
|
28
|
+
|
29
|
+
EC2_COMPONENT = 'orchestrator'.freeze
|
30
|
+
EC2_NAME = 'AEM Orchestrator'.freeze
|
31
|
+
|
32
|
+
# @param stack_prefix AWS tag: StackPrefix
|
33
|
+
# @param ec2_resource AWS EC2 resource
|
34
|
+
# @param asg_client AWS AutoScalingGroup client
|
35
|
+
# @param cloud_watch_client AWS CloudWatch client
|
36
|
+
# @return new RubyAemAws::FullSet::Orchestrator
|
37
|
+
def initialize(stack_prefix, ec2_resource, asg_client, cloud_watch_client)
|
38
|
+
@descriptor = ComponentDescriptor.new(stack_prefix,
|
39
|
+
EC2Descriptor.new(EC2_COMPONENT, EC2_NAME))
|
40
|
+
@ec2_resource = ec2_resource
|
41
|
+
@asg_client = asg_client
|
42
|
+
@cloud_watch_client = cloud_watch_client
|
43
|
+
end
|
44
|
+
|
45
|
+
# def terminate_all_instances
|
46
|
+
|
47
|
+
# def terminate_random_instance
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,50 @@
|
|
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_grouped_component'
|
16
|
+
require_relative 'mixins/healthy_state_verifier'
|
17
|
+
require_relative 'mixins/metric_verifier'
|
18
|
+
|
19
|
+
module RubyAemAws
|
20
|
+
module Component
|
21
|
+
# Interface to the AWS instance running the Publish component of a full-set AEM stack.
|
22
|
+
class Publish
|
23
|
+
attr_reader :descriptor, :ec2_resource, :cloud_watch_client, :asg_client
|
24
|
+
include AbstractGroupedComponent
|
25
|
+
# Can't verify state by count as there's no ELB.
|
26
|
+
include HealthyStateVerifier
|
27
|
+
include MetricVerifier
|
28
|
+
|
29
|
+
EC2_COMPONENT = 'publish'.freeze
|
30
|
+
EC2_NAME = 'AEM Publish'.freeze
|
31
|
+
|
32
|
+
# @param stack_prefix AWS tag: StackPrefix
|
33
|
+
# @param ec2_resource AWS EC2 resource
|
34
|
+
# @param asg_client AWS AutoScalingGroup client
|
35
|
+
# @param cloud_watch_client AWS CloudWatch client
|
36
|
+
# @return new RubyAemAws::FullSet::AuthorPrimary
|
37
|
+
def initialize(stack_prefix, ec2_resource, asg_client, cloud_watch_client)
|
38
|
+
@descriptor = ComponentDescriptor.new(stack_prefix,
|
39
|
+
EC2Descriptor.new(EC2_COMPONENT, EC2_NAME))
|
40
|
+
@ec2_resource = ec2_resource
|
41
|
+
@asg_client = asg_client
|
42
|
+
@cloud_watch_client = cloud_watch_client
|
43
|
+
end
|
44
|
+
|
45
|
+
# def terminate_all_instances
|
46
|
+
|
47
|
+
# def terminate_random_instance
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,53 @@
|
|
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_grouped_component'
|
16
|
+
require_relative 'mixins/healthy_count_verifier'
|
17
|
+
require_relative 'mixins/metric_verifier'
|
18
|
+
|
19
|
+
module RubyAemAws
|
20
|
+
module Component
|
21
|
+
# Interface to the AWS instance running the PublishDispatcher component of a full-set AEM stack.
|
22
|
+
class PublishDispatcher
|
23
|
+
attr_reader :descriptor, :ec2_resource, :asg_client, :elb_client, :cloud_watch_client
|
24
|
+
include AbstractGroupedComponent
|
25
|
+
include HealthyCountVerifier
|
26
|
+
include MetricVerifier
|
27
|
+
|
28
|
+
EC2_COMPONENT = 'publish-dispatcher'.freeze
|
29
|
+
EC2_NAME = 'AEM Publish Dispatcher'.freeze
|
30
|
+
ELB_ID = 'PublishDispatcherLoadBalancer'.freeze
|
31
|
+
ELB_NAME = 'AEM Publish Dispatcher Load Balancer'.freeze
|
32
|
+
|
33
|
+
# @param stack_prefix AWS tag: StackPrefix
|
34
|
+
# @param ec2_resource AWS EC2 resource
|
35
|
+
# @param asg_client AWS AutoScalingGroup client
|
36
|
+
# @param cloud_watch_client AWS CloudWatch client
|
37
|
+
# @return new RubyAemAws::FullSet::PublishDispatcher
|
38
|
+
def initialize(stack_prefix, ec2_resource, asg_client, elb_client, cloud_watch_client)
|
39
|
+
@descriptor = ComponentDescriptor.new(stack_prefix,
|
40
|
+
EC2Descriptor.new(EC2_COMPONENT, EC2_NAME),
|
41
|
+
ELBDescriptor.new(ELB_ID, ELB_NAME))
|
42
|
+
@ec2_resource = ec2_resource
|
43
|
+
@asg_client = asg_client
|
44
|
+
@elb_client = elb_client
|
45
|
+
@cloud_watch_client = cloud_watch_client
|
46
|
+
end
|
47
|
+
|
48
|
+
# def terminate_all_instances
|
49
|
+
|
50
|
+
# def terminate_random_instance
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,35 @@
|
|
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_publish_dispatcher'
|
16
|
+
|
17
|
+
module RubyAemAws
|
18
|
+
# Factory for the consolidated AEM stack component interface.
|
19
|
+
class ConsolidatedStack
|
20
|
+
# @param stack_prefix AWS tag: StackPrefix
|
21
|
+
# @param ec2_resource AWS EC2 client
|
22
|
+
# @param cloud_watch_client AWS CloudWatch client
|
23
|
+
# @return new RubyAemAws::ConsolidatedStack instance
|
24
|
+
def initialize(stack_prefix, ec2_resource, cloud_watch_client)
|
25
|
+
@stack_prefix = stack_prefix
|
26
|
+
@ec2_resource = ec2_resource
|
27
|
+
@cloud_watch_client = cloud_watch_client
|
28
|
+
end
|
29
|
+
|
30
|
+
# @return new RubyAemAws::Component::AuthorPublishDispatcher instance
|
31
|
+
def author_publish_dispatcher
|
32
|
+
RubyAemAws::Component::AuthorPublishDispatcher.new(@stack_prefix, @ec2_resource, @cloud_watch_client)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,32 @@
|
|
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
|
+
class InstanceState
|
17
|
+
PENDING = 'pending'.freeze
|
18
|
+
RUNNING = 'running'.freeze
|
19
|
+
SHUTTING_DOWN = 'shutting_down'.freeze
|
20
|
+
TERMINATED = 'terminated'.freeze
|
21
|
+
STOPPING = 'stopping'.freeze
|
22
|
+
STOPPED = 'stopped'.freeze
|
23
|
+
|
24
|
+
ALL_ACTIVE = [PENDING, RUNNING, SHUTTING_DOWN, STOPPING, STOPPED].freeze
|
25
|
+
end
|
26
|
+
|
27
|
+
class Constants
|
28
|
+
REGION_DEFAULT = 'ap-southeast-2'.freeze
|
29
|
+
|
30
|
+
INSTANCE_STATE_HEALTHY = RubyAemAws::InstanceState::RUNNING.freeze
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,36 @@
|
|
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
|
+
# Raise this when a method is not yet implemented.
|
17
|
+
class NotYetImplementedError < StandardError
|
18
|
+
def initialize(msg = 'Not yet implemented')
|
19
|
+
super
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Raise this when a component unexpectedly has more than one instance.
|
24
|
+
class ExpectedSingleInstanceError < StandardError
|
25
|
+
# def initialize(count, descriptor)
|
26
|
+
# message << 'Expected exactly one instance'
|
27
|
+
# message << " but got #{count}" unless count.nil?
|
28
|
+
# message << "for (#{descriptor.stack_prefix}, #{descriptor.ec2.component}, #{descriptor.ec2.name})" unless descriptor.nil?
|
29
|
+
# super(message)
|
30
|
+
# end
|
31
|
+
|
32
|
+
def initialize(msg = 'Expected exactly one instance')
|
33
|
+
super
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,69 @@
|
|
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, @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
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby_aem_aws
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Shine Solutions
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-03-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: aws-sdk
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: retries
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.0.5
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.0.5
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.4'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.4'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: yard
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.9.5
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.9.5
|
69
|
+
description: ruby_aem_aws is a Ruby client for Shine Solutions Adobe Experience Manager
|
70
|
+
(AEM) Platform on AWS
|
71
|
+
email:
|
72
|
+
- opensource@shinesolutions.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- lib/ruby_aem_aws.rb
|
78
|
+
- lib/ruby_aem_aws/component/abstract_component.rb
|
79
|
+
- lib/ruby_aem_aws/component/abstract_grouped_component.rb
|
80
|
+
- lib/ruby_aem_aws/component/abstract_single_component.rb
|
81
|
+
- lib/ruby_aem_aws/component/author.rb
|
82
|
+
- lib/ruby_aem_aws/component/author_dispatcher.rb
|
83
|
+
- lib/ruby_aem_aws/component/author_primary.rb
|
84
|
+
- lib/ruby_aem_aws/component/author_publish_dispatcher.rb
|
85
|
+
- lib/ruby_aem_aws/component/author_standby.rb
|
86
|
+
- lib/ruby_aem_aws/component/chaos_monkey.rb
|
87
|
+
- lib/ruby_aem_aws/component/component_descriptor.rb
|
88
|
+
- lib/ruby_aem_aws/component/mixins/healthy_count_verifier.rb
|
89
|
+
- lib/ruby_aem_aws/component/mixins/healthy_state_verifier.rb
|
90
|
+
- lib/ruby_aem_aws/component/mixins/instance_describer.rb
|
91
|
+
- lib/ruby_aem_aws/component/mixins/metric_verifier.rb
|
92
|
+
- lib/ruby_aem_aws/component/orchestrator.rb
|
93
|
+
- lib/ruby_aem_aws/component/publish.rb
|
94
|
+
- lib/ruby_aem_aws/component/publish_dispatcher.rb
|
95
|
+
- lib/ruby_aem_aws/consolidated_stack.rb
|
96
|
+
- lib/ruby_aem_aws/constants.rb
|
97
|
+
- lib/ruby_aem_aws/error.rb
|
98
|
+
- lib/ruby_aem_aws/full_set_stack.rb
|
99
|
+
homepage: https://github.com/shinesolutions/ruby_aem_aws
|
100
|
+
licenses:
|
101
|
+
- Apache-2.0
|
102
|
+
metadata: {}
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '2.1'
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 2.6.14
|
120
|
+
signing_key:
|
121
|
+
specification_version: 4
|
122
|
+
summary: AEM API Ruby client
|
123
|
+
test_files: []
|