Class: CloudFormation::Bridge::Resources::ElastiCacheReplicaCluster

Inherits:
Base
  • Object
show all
Includes:
BaseElastiCacheResource
Defined in:
lib/cloud_formation/bridge/resources/elasti_cache_replica_cluster.rb

Constant Summary collapse

REQUIRED_FIELDS =
[
  ELASTI_CACHE::REPLICATION_GROUP_ID,
  ELASTI_CACHE::REPLICA_CLUSTER_ID,
]

Constants included from BaseElastiCacheResource

BaseElastiCacheResource::UnknownCacheEngineError

Instance Method Summary collapse

Methods included from BaseElastiCacheResource

#client, #config_endpoint, #find_cluster, #node_urls, #replication_group_available?, #wait_until_cluster_is_available

Methods inherited from Base

#require_fields, #update, #wait_until

Instance Method Details

#create(request) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/cloud_formation/bridge/resources/elasti_cache_replica_cluster.rb', line 18

def create(request)
  require_fields(request, REQUIRED_FIELDS)

  cluster_id = request.resource_properties[ELASTI_CACHE::REPLICA_CLUSTER_ID]
  replication_id = request.resource_properties[ELASTI_CACHE::REPLICATION_GROUP_ID]

  client.create_cache_cluster(cache_cluster_id: cluster_id, replication_group_id: replication_id)

  wait_until_cluster_is_available(cluster_id)

  {
    FIELDS::DATA => {
      ELASTI_CACHE::REPLICA_CLUSTER_ID => cluster_id,
      ELASTI_CACHE::NODE_URLS => node_urls(cluster_id),
    },
    FIELDS::PHYSICAL_RESOURCE_ID => cluster_id,
  }
end

#delete(request) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/cloud_formation/bridge/resources/elasti_cache_replica_cluster.rb', line 37

def delete(request)
  require_fields(request, ELASTI_CACHE::REPLICA_CLUSTER_ID)

  cluster_id = request.resource_properties[ELASTI_CACHE::REPLICA_CLUSTER_ID]

  begin
    wait_until_cluster_is_available(cluster_id)

    client.delete_cache_cluster(cache_cluster_id: cluster_id)

    wait_until("cluster #{cluster_id} to be gone") do
      begin
        find_cluster(cluster_id)
        false
      rescue AWS::ElastiCache::Errors::CacheClusterNotFound
        true
      end
    end

  rescue AWS::ElastiCache::Errors::CacheClusterNotFound
    # no cache cluster? ignore
    Util.logger.info("Could not find cache cluster for #{cluster_id}, ignoring")
  end
end