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)
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
|