Class: StackMate::StackExecutor

Inherits:
Stacker
  • Object
show all
Includes:
Logging
Defined in:
lib/stackmate/stack_executor.rb

Instance Attribute Summary

Attributes inherited from Stacker

#templ

Instance Method Summary collapse

Methods included from Logging

configure_logger_for, #logger, logger_for

Methods inherited from Stacker

#find_refs, #resolve_dependencies, #tsort_each_child, #tsort_each_node, #validate_param_values

Constructor Details

#initialize(templatefile, stackname, params, engine, create_wait_conditions, api_opts) ⇒ StackExecutor

Returns a new instance of StackExecutor.



14
15
16
17
18
19
20
# File 'lib/stackmate/stack_executor.rb', line 14

def initialize(templatefile, stackname, params, engine, create_wait_conditions, api_opts)
    stackstr = File.read(templatefile)
    super(stackstr, stackname, resolve_param_refs(params, stackname))
    @engine = engine
    @create_wait_conditions = create_wait_conditions
    @api_opts = api_opts
end

Instance Method Details

#launchObject



58
59
60
61
62
# File 'lib/stackmate/stack_executor.rb', line 58

def launch
    wfid = @engine.launch( pdef, @templ)
    @engine.wait_for(wfid)
    logger.error { "engine error : #{@engine.errors.first.message}"} if @engine.errors.first
end

#pdefObject



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

def pdef
    participants = self.strongly_connected_components.flatten
    #if we want to skip creating wait conditions (useful for automated tests)
    participants = participants.select { |p|
        StackMate.class_for(@templ['Resources'][p]['Type']) != 'StackMate::WaitCondition'
    } if !@create_wait_conditions

    logger.info("Ordered list of participants: #{participants}")

    participants.each do |p|
        t = @templ['Resources'][p]['Type']
        throw :unknown, t if !StackMate.class_for(t)
        @engine.register_participant p, StackMate.class_for(t), @api_opts
    end

    @engine.register_participant 'Output', StackMate.class_for('Outputs')
    participants << 'Output'
    @pdef = Ruote.define @stackname.to_s() do
        cursor :timeout => '300s' do
            participants.collect{ |name| __send__(name) }
        end
    end
end

#resolve_param_refs(params, stackname) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/stackmate/stack_executor.rb', line 22

def resolve_param_refs(params, stackname)
    resolved_params = {}
    params.split(';').each do |p|
       i = p.split('=')
       resolved_params[i[0]] = i[1]
    end
    resolved_params['AWS::Region'] = 'us-east-1' #TODO handle this better
    resolved_params['AWS::StackName'] = stackname
    resolved_params['AWS::StackId'] = stackname
    resolved_params
end