Sha256: 74c9a4c8e26204b11c01fb21b03780f3c94adb7bad2530b9e8c9c72561268d5e

Contents?: true

Size: 1.36 KB

Versions: 5

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true

require 'aws-sdk'
require 'hollerback'

require_relative 'service'

module Rollo
  module Model
    class ServiceCluster
      def initialize(ecs_cluster_name, region, ecs_resource = nil)
        @region = region
        @ecs_cluster_name = ecs_cluster_name
        @ecs_resource = ecs_resource || Aws::ECS::Resource.new(region: region)
        @ecs_cluster = ecs_cluster
      end

      def name
        @ecs_cluster_name
      end

      def replica_services
        ecs_service_arns
          .collect { |arn| Service.new(@ecs_cluster_name, arn, @region) }
          .select(&:replica?)
      end

      def with_replica_services(&block)
        all_replica_services = replica_services

        callbacks = Hollerback::Callbacks.new(block)
        callbacks.try_respond_with(
          :start, all_replica_services
        )

        all_replica_services.each do |service|
          callbacks.try_respond_with(:each_service, service)
        end
      end

      private

      def ecs_cluster
        @ecs_resource
          .client
          .describe_clusters(clusters: [@ecs_cluster_name])
          .clusters[0]
      end

      def ecs_service_arns
        @ecs_resource
          .client
          .list_services(cluster: @ecs_cluster.cluster_name)
          .inject([]) { |arns, response| arns + response.service_arns }
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rollo-0.9.0.pre.6 lib/rollo/model/service_cluster.rb
rollo-0.9.0.pre.5 lib/rollo/model/service_cluster.rb
rollo-0.9.0.pre.4 lib/rollo/model/service_cluster.rb
rollo-0.9.0.pre.3 lib/rollo/model/service_cluster.rb
rollo-0.9.0.pre.2 lib/rollo/model/service_cluster.rb