Class: CloudFormation::Bridge::Executor

Inherits:
Object
  • Object
show all
Includes:
Names
Defined in:
lib/cloud_formation/bridge/executor.rb

Constant Summary collapse

DEFAULT_REGISTRY =
{
  "Custom::SubscribeSQSQueueToSNSTopic" =>
    CloudFormation::Bridge::Resources::SubscribeQueueToTopic.new,
  "Custom::CloudFormationOutputs" =>
    CloudFormation::Bridge::Resources::CloudFormationOutputs.new,
  "Custom::ElastiCacheReplicationGroup" =>
    CloudFormation::Bridge::Resources::ElastiCacheReplicationGroup.new,
  "Custom::ElastiCacheReplicaCluster" =>
    CloudFormation::Bridge::Resources::ElastiCacheReplicaCluster.new,
  "Custom::ElastiCacheNodeURLs" =>
    CloudFormation::Bridge::Resources::ElastiCacheNodeUrls.new,
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(registry = DEFAULT_REGISTRY) ⇒ Executor

Returns a new instance of Executor.



30
31
32
# File 'lib/cloud_formation/bridge/executor.rb', line 30

def initialize(registry = DEFAULT_REGISTRY)
  @registry = registry
end

Instance Attribute Details

#registryObject (readonly)

Returns the value of attribute registry.



28
29
30
# File 'lib/cloud_formation/bridge/executor.rb', line 28

def registry
  @registry
end

Instance Method Details

#execute(request) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/cloud_formation/bridge/executor.rb', line 34

def execute(request)

  begin
    if resource = registry[request.resource_type]
      response = if request.create?
        resource.create(request)
      elsif request.update?
        resource.update(request)
      else
        resource.delete(request)
      end

      request.succeed!(response)
    elsif request.delete?
      request.succeed!
    else
      request.fail!("Don't know what to do with resource #{request.resource_type}")
    end
  rescue Exception => ex
    ExceptionNotifier.report_exception(ex, request.request)
    request.fail!("#{ex.class.name} - #{ex.message}")
  end

end