Class: Bosh::Director::Core::Templates::JobInstanceRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/bosh/director/core/templates/job_instance_renderer.rb

Instance Method Summary collapse

Constructor Details

#initialize(templates, job_template_loader) ⇒ JobInstanceRenderer

Returns a new instance of JobInstanceRenderer.



6
7
8
9
# File 'lib/bosh/director/core/templates/job_instance_renderer.rb', line 6

def initialize(templates, job_template_loader)
  @templates = templates
  @job_template_loader = job_template_loader
end

Instance Method Details

#render(spec) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/bosh/director/core/templates/job_instance_renderer.rb', line 11

def render(spec)
  errors = []

  rendered_templates = @templates.map do |template|
    job_template_renderer = job_template_renderers[template.name]

    begin
      job_template_renderer.render(spec)
    rescue Exception => e
      errors.push e
    end
  end

  if errors.length > 0
    message = "Unable to render jobs for instance group '#{spec['job']['name']}'. Errors are:"

    errors.each do |e|
      message = "#{message}\n   - #{e.message.gsub(/\n/, "\n  ")}"
    end

    raise message
  end

  RenderedJobInstance.new(rendered_templates)
end