Class: Bosh::Director::JobRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/bosh/director/job_renderer.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(blobstore, logger) ⇒ JobRenderer

Returns a new instance of JobRenderer.



10
11
12
13
# File 'lib/bosh/director/job_renderer.rb', line 10

def initialize(blobstore, logger)
  @blobstore = blobstore
  @logger = logger
end

Class Method Details

.createObject



6
7
8
# File 'lib/bosh/director/job_renderer.rb', line 6

def self.create
  new(App.instance.blobstores.blobstore, Config.logger)
end

Instance Method Details

#render_job_instance(instance_plan) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/bosh/director/job_renderer.rb', line 19

def render_job_instance(instance_plan)
  instance = instance_plan.instance

  if instance_plan.templates.empty?
    @logger.debug("Skipping rendering templates for '#{instance}', no templates")
    return
  end

  @logger.debug("Rendering templates for instance #{instance}")

  job_template_loader = Core::Templates::JobTemplateLoader.new(@logger)

  instance_renderer = Core::Templates::JobInstanceRenderer.new(instance_plan.templates, job_template_loader)
  rendered_job_instance = instance_renderer.render(instance_plan.spec.as_template_spec)

  configuration_hash = rendered_job_instance.configuration_hash

  archive_model = instance.model.latest_rendered_templates_archive

  if archive_model && archive_model.content_sha1 == configuration_hash
    unless @blobstore.exists?(archive_model.blobstore_id)
      # If rendered template file in blobstore crashed, we re-upload it and update database with new blobstore_id
      rendered_templates_archive = rendered_job_instance.persist(@blobstore)
      archive_model.update({:blobstore_id => rendered_templates_archive.blobstore_id, :sha1 => rendered_templates_archive.sha1})
    end
    rendered_templates_archive = Core::Templates::RenderedTemplatesArchive.new(
      archive_model.blobstore_id,
      archive_model.sha1,
    )
  else
    rendered_templates_archive = rendered_job_instance.persist(@blobstore)
    instance.model.add_rendered_templates_archive(
      blobstore_id: rendered_templates_archive.blobstore_id,
      sha1: rendered_templates_archive.sha1,
      content_sha1: configuration_hash,
      created_at: Time.now,
    )
  end

  instance.configuration_hash = configuration_hash
  instance.template_hashes    = rendered_job_instance.template_hashes
  instance.rendered_templates_archive = rendered_templates_archive
end

#render_job_instances(instance_plans) ⇒ Object



15
16
17
# File 'lib/bosh/director/job_renderer.rb', line 15

def render_job_instances(instance_plans)
  instance_plans.each { |instance_plan| render_job_instance(instance_plan) }
end