Skip to content

Commit

Permalink
Add Preview components
Browse files Browse the repository at this point in the history
  • Loading branch information
mbloch1986 committed Jun 30, 2023
1 parent 0cee893 commit 4fdf365
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 1 deletion.
12 changes: 12 additions & 0 deletions lib/ruby_aem_aws/architecture/full_set_stack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
require_relative '../component/orchestrator'
require_relative '../component/publish_dispatcher'
require_relative '../component/publish'
require_relative '../component/preview_publish_dispatcher'
require_relative '../component/preview_publish'
require_relative '../mixins/metric_verifier'

module RubyAemAws
Expand Down Expand Up @@ -96,9 +98,19 @@ def publish
RubyAemAws::Component::Publish.new(@stack_prefix, @publish_aws_clients)
end

# @return new RubyAemAws::Component::PreviewPublish instance
def preview_publish
RubyAemAws::Component::PreviewPublish.new(@stack_prefix, @publish_aws_clients)
end

# @return new RubyAemAws::Component::PublishDispatcher instance
def publish_dispatcher
RubyAemAws::Component::PublishDispatcher.new(@stack_prefix, @dispatcher_aws_clients)
end

# @return new RubyAemAws::Component::PreviewPublishDispatcher instance
def preview_publish_dispatcher
RubyAemAws::Component::PreviewPublishDispatcher.new(@stack_prefix, @dispatcher_aws_clients)
end
end
end
79 changes: 79 additions & 0 deletions lib/ruby_aem_aws/component/preview_publish.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Copyright 2018-2021 Shine Solutions Group
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require_relative '../abstract/grouped_component'
require_relative '../abstract/snapshot'
require_relative '../constants'
require_relative '../mixins/healthy_resource_verifier'
require_relative '../mixins/metric_verifier'
require_relative '../mixins/snapshot_verifier'

module RubyAemAws
module Component
# Interface to the AWS instance running the Preview Publish component of a full-set AEM stack.
class PreviewPublish
attr_reader :descriptor, :ec2_resource, :cloud_watch_client, :asg_client, :cloud_watch_log_client

include AbstractGroupedComponent
include AbstractSnapshot
include HealthyResourceVerifier
include MetricVerifier
include SnapshotVerifier

EC2_COMPONENT = 'preview-publish'.freeze
EC2_NAME = 'AEM Preview Publish'.freeze

# @param stack_prefix AWS tag: StackPrefix
# @param params Array of AWS Clients and Resource connections:
# - AutoScalingClient: AWS AutoScalingGroup Client.
# - CloudWatchClient: AWS Cloudwatch Client.
# - CloudWatchLogsClient: AWS Cloudwatch Logs Client.
# - Ec2Resource: AWS EC2 Resource connection.
# @return new RubyAemAws::FullSet::PreviewPublish
def initialize(stack_prefix, params)
@descriptor = ComponentDescriptor.new(stack_prefix,
EC2Descriptor.new(EC2_COMPONENT, EC2_NAME))
@asg_client = params[:AutoScalingClient]
@cloud_watch_client = params[:CloudWatchClient]
@cloud_watch_log_client = params[:CloudWatchLogsClient]
@ec2_resource = params[:Ec2Resource]
end

def terminate_all_instances
get_all_instances.each do |i|
next if i.nil? || i.state.code != Constants::INSTANCE_STATE_CODE_RUNNING

i.terminate
i.wait_until_terminated
end
end

def terminate_random_instance
instance = get_random_instance
instance.terminate
instance.wait_until_terminated
end

def get_tags
tags = []
get_all_instances.each do |i|
next if i.nil? || i.state.code != Constants::INSTANCE_STATE_CODE_RUNNING

tags.push(i.tags)
end
tags
end
end
end
end
84 changes: 84 additions & 0 deletions lib/ruby_aem_aws/component/preview_publish_dispatcher.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Copyright 2018-2021 Shine Solutions Group
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require_relative '../abstract/grouped_component'
require_relative '../abstract/snapshot'
require_relative '../constants'
require_relative '../mixins/healthy_resource_verifier'
require_relative '../mixins/metric_verifier'
require_relative '../mixins/snapshot_verifier'

module RubyAemAws
module Component
# Interface to the AWS instance running the Preview PublishDispatcher component of a full-set AEM stack.
class PreviewPublishDispatcher
attr_reader :descriptor, :ec2_resource, :asg_client, :elb_client, :cloud_watch_client, :cloud_watch_log_client

include AbstractGroupedComponent
include AbstractSnapshot
include HealthyResourceVerifier
include MetricVerifier
include SnapshotVerifier

EC2_COMPONENT = 'preview-publish-dispatcher'.freeze
EC2_NAME = 'AEM Preview Publish Dispatcher'.freeze
ELB_ID = 'PreviewPublishDispatcherLoadBalancer'.freeze
ELB_NAME = 'AEM Preview Publish Dispatcher Load Balancer'.freeze

# @param stack_prefix AWS tag: StackPrefix
# @param params Array of AWS Clients and Resource connections:
# - AutoScalingClient: AWS AutoScalingGroup Client.
# - CloudWatchClient: AWS Cloudwatch Client.
# - CloudWatchLogsClient: AWS Cloudwatch Logs Client.
# - Ec2Resource: AWS EC2 Resource connection.
# - ElbClient: AWS ElasticLoadBalancer v2 Client.
# @return new RubyAemAws::FullSet::PreviewPublishDispatcher
def initialize(stack_prefix, params)
@descriptor = ComponentDescriptor.new(stack_prefix,
EC2Descriptor.new(EC2_COMPONENT, EC2_NAME),
ELBDescriptor.new(ELB_ID, ELB_NAME))
@asg_client = params[:AutoScalingClient]
@cloud_watch_client = params[:CloudWatchClient]
@cloud_watch_log_client = params[:CloudWatchLogsClient]
@ec2_resource = params[:Ec2Resource]
@elb_client = params[:ElbClient]
end

def terminate_all_instances
get_all_instances.each do |i|
next if i.nil? || i.state.code != Constants::INSTANCE_STATE_CODE_RUNNING

i.terminate
i.wait_until_terminated
end
end

def terminate_random_instance
instance = get_random_instance
instance.terminate
instance.wait_until_terminated
end

def get_tags
tags = []
get_all_instances.each do |i|
next if i.nil? || i.state.code != Constants::INSTANCE_STATE_CODE_RUNNING

tags.push(i.tags)
end
tags
end
end
end
end
2 changes: 1 addition & 1 deletion lib/ruby_aem_aws/component/publish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Publish
# - CloudWatchClient: AWS Cloudwatch Client.
# - CloudWatchLogsClient: AWS Cloudwatch Logs Client.
# - Ec2Resource: AWS EC2 Resource connection.
# @return new RubyAemAws::FullSet::AuthorPrimary
# @return new RubyAemAws::FullSet::Publish
def initialize(stack_prefix, params)
@descriptor = ComponentDescriptor.new(stack_prefix,
EC2Descriptor.new(EC2_COMPONENT, EC2_NAME))
Expand Down

0 comments on commit 4fdf365

Please sign in to comment.