Sha256: 6a78942370cb10bdc4de758839838f9f7cc9faba033d752d8dc4495f3f0cb426

Contents?: true

Size: 1.62 KB

Versions: 4

Compression:

Stored size: 1.62 KB

Contents

require 'aws/elasticache'
require 'cloud_formation/bridge/names'

module CloudFormation
  module Bridge
    module Resources
      module BaseElastiCacheResource

        UnknownCacheEngineError = Class.new(StandardError)

        include CloudFormation::Bridge::Names

        def replication_group_available?(replication_group_id)
          replication_group = client.describe_replication_groups(replication_group_id: replication_group_id)[:replication_groups][0]
          replication_group[:status] == ELASTI_CACHE::AVAILABLE
        end

        def find_cluster(cluster_id)
          client.describe_cache_clusters(
            cache_cluster_id: cluster_id,
            show_cache_node_info: true
          )[:cache_clusters][0]
        end

        def node_urls(cluster_id)
          cluster = find_cluster(cluster_id)

          cluster[:cache_nodes].map do |node|
            "#{node[:endpoint][:address]}:#{node[:endpoint][:port]}"
          end.join(",")
        end

        def config_endpoint(cluster_id)
          cluster = find_cluster(cluster_id)
          "#{cluster[:configuration_endpoint][:address]}:#{cluster[:configuration_endpoint][:port]}" if cluster[:engine] == 'memcached'
        end

        def wait_until_cluster_is_available(cluster_id)
          wait_until("replica #{cluster_id} to be available") do
            cluster = find_cluster(cluster_id)
            Util.logger.info("Cluster info is #{cluster.inspect}")
            cluster[:cache_cluster_status] == ELASTI_CACHE::AVAILABLE
          end
        end

        def client
          @client ||= AWS::ElastiCache.new.client
        end

      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cfn-bridge-0.0.16 lib/cloud_formation/bridge/resources/base_elasti_cache_resource.rb
cfn-bridge-0.0.15 lib/cloud_formation/bridge/resources/base_elasti_cache_resource.rb
cfn-bridge-0.0.14 lib/cloud_formation/bridge/resources/base_elasti_cache_resource.rb
cfn-bridge-0.0.13 lib/cloud_formation/bridge/resources/base_elasti_cache_resource.rb