bosh-director-core 1.1868.0 → 1.1975.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,15 +3,15 @@ require 'bosh/director/core/templates/rendered_job_instance'
3
3
 
4
4
  module Bosh::Director::Core::Templates
5
5
  class JobInstanceRenderer
6
- def initialize(job, job_template_loader)
7
- @job = job
6
+ def initialize(templates, job_template_loader)
7
+ @templates = templates
8
8
  @job_template_loader = job_template_loader
9
9
  end
10
10
 
11
- def render(instance)
12
- rendered_templates = job.templates.map do |template|
11
+ def render(spec)
12
+ rendered_templates = templates.map do |template|
13
13
  job_template_renderer = job_template_renderers[template.name]
14
- job_template_renderer.render(job.name, instance)
14
+ job_template_renderer.render(spec)
15
15
  end
16
16
 
17
17
  RenderedJobInstance.new(rendered_templates)
@@ -20,12 +20,12 @@ module Bosh::Director::Core::Templates
20
20
  private
21
21
 
22
22
  def job_template_renderers
23
- @job_template_renderers ||= job.templates.reduce({}) do |hash, template|
23
+ @job_template_renderers ||= templates.reduce({}) do |hash, template|
24
24
  hash[template.name] = job_template_loader.process(template)
25
25
  hash
26
26
  end
27
27
  end
28
28
 
29
- attr_reader :job_template_loader, :job
29
+ attr_reader :job_template_loader, :templates
30
30
  end
31
31
  end
@@ -1,6 +1,6 @@
1
1
  require 'bosh/director/core/templates'
2
2
  require 'bosh/director/core/templates/job_template_renderer'
3
- require 'bosh/director/core/templates/src_file_template'
3
+ require 'bosh/director/core/templates/source_erb'
4
4
 
5
5
  module Bosh::Director::Core::Templates
6
6
  class JobTemplateLoader
@@ -12,18 +12,17 @@ module Bosh::Director::Core::Templates
12
12
  template_dir = extract_template(job_template)
13
13
  manifest = Psych.load_file(File.join(template_dir, 'job.MF'))
14
14
 
15
- monit_template = erb(File.join(template_dir, 'monit'))
16
- monit_template.filename = File.join(job_template.name, 'monit')
15
+ monit_erb_file = File.read(File.join(template_dir, 'monit'))
16
+ monit_source_erb = SourceErb.new('monit', 'monit', monit_erb_file, job_template.name)
17
17
 
18
- templates = []
18
+ source_erbs = []
19
19
 
20
20
  manifest.fetch('templates', {}).each_pair do |src_name, dest_name|
21
- erb_file = erb(File.join(template_dir, 'templates', src_name))
22
- erb_file.filename = File.join(job_template.name, src_name)
23
- templates << SrcFileTemplate.new(src_name, dest_name, erb_file)
21
+ erb_file = File.read(File.join(template_dir, 'templates', src_name))
22
+ source_erbs << SourceErb.new(src_name, dest_name, erb_file, job_template.name)
24
23
  end
25
24
 
26
- JobTemplateRenderer.new(job_template.name, monit_template, templates, logger)
25
+ JobTemplateRenderer.new(job_template.name, monit_source_erb, source_erbs, logger)
27
26
  ensure
28
27
  FileUtils.rm_rf(template_dir) if template_dir
29
28
  end
@@ -48,9 +47,5 @@ module Bosh::Director::Core::Templates
48
47
  ensure
49
48
  FileUtils.rm_f(temp_path) if temp_path
50
49
  end
51
-
52
- def erb(path)
53
- ERB.new(File.read(path))
54
- end
55
50
  end
56
51
  end
@@ -6,48 +6,32 @@ require 'common/properties'
6
6
  module Bosh::Director::Core::Templates
7
7
  class JobTemplateRenderer
8
8
 
9
- attr_reader :monit_template, :templates
9
+ attr_reader :monit_erb, :source_erbs
10
10
 
11
- def initialize(name, monit_template, templates, logger)
11
+ def initialize(name, monit_erb, source_erbs, logger)
12
12
  @name = name
13
- @monit_template = monit_template
14
- @templates = templates
13
+ @monit_erb = monit_erb
14
+ @source_erbs = source_erbs
15
15
  @logger = logger
16
16
  end
17
17
 
18
- def render(job_name, instance)
19
- template_context = Bosh::Common::TemplateEvaluationContext.new(instance.spec)
18
+ def render(spec)
19
+ template_context = Bosh::Common::TemplateEvaluationContext.new(spec)
20
+ job_name = spec['job']['name']
21
+ index = spec['index']
20
22
 
21
- monit = render_erb(job_name, monit_template, template_context, instance.index)
23
+ monit = monit_erb.render(template_context, job_name, index, logger)
22
24
 
23
- rendered_templates = templates.map do |template_file|
24
- file_contents = render_erb(job_name, template_file.erb_file, template_context, instance.index)
25
- RenderedFileTemplate.new(template_file.src_name, template_file.dest_name, file_contents)
25
+ rendered_files = source_erbs.map do |source_erb|
26
+ file_contents = source_erb.render(template_context, job_name, index, logger)
27
+ RenderedFileTemplate.new(source_erb.src_name, source_erb.dest_name, file_contents)
26
28
  end
27
29
 
28
- RenderedJobTemplate.new(name, monit, rendered_templates)
30
+ RenderedJobTemplate.new(name, monit, rendered_files)
29
31
  end
30
32
 
31
33
  private
32
34
 
33
35
  attr_reader :name, :logger
34
-
35
- def render_erb(job_name, template, template_context, index)
36
- template.result(template_context.get_binding)
37
- # rubocop:disable RescueException
38
- rescue Exception => e
39
- logger.debug(e.inspect)
40
- job_desc = "#{job_name}/#{index}"
41
- line_index = e.backtrace.index { |l| l.include?(template.filename) }
42
- line = line_index ? e.backtrace[line_index] : '(unknown):(unknown)'
43
- template_name, line = line.split(':')
44
-
45
- message = "Error filling in template `#{File.basename(template_name)}' " +
46
- "for `#{job_desc}' (line #{line}: #{e})"
47
-
48
- logger.debug("#{message}\n#{e.backtrace.join("\n")}")
49
- raise message
50
- end
51
- # rubocop:enable RescueException
52
36
  end
53
37
  end
@@ -0,0 +1,35 @@
1
+ require 'bosh/director/core/templates'
2
+ require 'common/properties'
3
+
4
+ module Bosh::Director::Core::Templates
5
+ class SourceErb
6
+ attr_reader :src_name, :dest_name, :erb
7
+
8
+ def initialize(src_name, dest_name, erb_contents, template_name)
9
+ @src_name = src_name
10
+ @dest_name = dest_name
11
+ erb = ERB.new(erb_contents)
12
+ erb.filename = File.join(template_name, src_name)
13
+ @erb = erb
14
+ end
15
+
16
+ def render(context, job_name, index, logger)
17
+ erb.result(context.get_binding)
18
+ # rubocop:disable RescueException
19
+ rescue Exception => e
20
+ # rubocop:enable RescueException
21
+
22
+ logger.debug(e.inspect)
23
+ job_desc = "#{job_name}/#{index}"
24
+ line_index = e.backtrace.index { |l| l.include?(erb.filename) }
25
+ line = line_index ? e.backtrace[line_index] : '(unknown):(unknown)'
26
+ template_name, line = line.split(':')
27
+
28
+ message = "Error filling in template `#{File.basename(template_name)}' " +
29
+ "for `#{job_desc}' (line #{line}: #{e})"
30
+
31
+ logger.debug("#{message}\n#{e.backtrace.join("\n")}")
32
+ raise message
33
+ end
34
+ end
35
+ end
@@ -1,7 +1,7 @@
1
1
  module Bosh
2
2
  module Director
3
3
  module Core
4
- VERSION = '1.1868.0'
4
+ VERSION = '1.1975.0'
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bosh-director-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1868.0
4
+ version: 1.1975.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-01-29 00:00:00.000000000 Z
12
+ date: 2014-02-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bosh_common
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 1.1868.0
21
+ version: 1.1975.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 1.1868.0
29
+ version: 1.1975.0
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: rake
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -94,7 +94,7 @@ files:
94
94
  - lib/bosh/director/core/templates/rendered_job_template.rb
95
95
  - lib/bosh/director/core/templates/rendered_templates_archive.rb
96
96
  - lib/bosh/director/core/templates/rendered_templates_writer.rb
97
- - lib/bosh/director/core/templates/src_file_template.rb
97
+ - lib/bosh/director/core/templates/source_erb.rb
98
98
  - lib/bosh/director/core/version.rb
99
99
  homepage: https://github.com/cloudfoundry/bosh
100
100
  licenses:
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  version: '0'
118
118
  segments:
119
119
  - 0
120
- hash: -2612646582658106641
120
+ hash: -3606702560231579831
121
121
  requirements: []
122
122
  rubyforge_project:
123
123
  rubygems_version: 1.8.23
@@ -1,5 +0,0 @@
1
- require 'bosh/director/core/templates'
2
-
3
- module Bosh::Director::Core::Templates
4
- SrcFileTemplate = Struct.new(:src_name, :dest_name, :erb_file)
5
- end