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.
- data/lib/bosh/director/core/templates/job_instance_renderer.rb +7 -7
- data/lib/bosh/director/core/templates/job_template_loader.rb +7 -12
- data/lib/bosh/director/core/templates/job_template_renderer.rb +13 -29
- data/lib/bosh/director/core/templates/source_erb.rb +35 -0
- data/lib/bosh/director/core/version.rb +1 -1
- metadata +6 -6
- data/lib/bosh/director/core/templates/src_file_template.rb +0 -5
@@ -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(
|
7
|
-
@
|
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(
|
12
|
-
rendered_templates =
|
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(
|
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 ||=
|
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, :
|
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/
|
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
|
-
|
16
|
-
|
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
|
-
|
18
|
+
source_erbs = []
|
19
19
|
|
20
20
|
manifest.fetch('templates', {}).each_pair do |src_name, dest_name|
|
21
|
-
erb_file =
|
22
|
-
|
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,
|
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 :
|
9
|
+
attr_reader :monit_erb, :source_erbs
|
10
10
|
|
11
|
-
def initialize(name,
|
11
|
+
def initialize(name, monit_erb, source_erbs, logger)
|
12
12
|
@name = name
|
13
|
-
@
|
14
|
-
@
|
13
|
+
@monit_erb = monit_erb
|
14
|
+
@source_erbs = source_erbs
|
15
15
|
@logger = logger
|
16
16
|
end
|
17
17
|
|
18
|
-
def render(
|
19
|
-
template_context = Bosh::Common::TemplateEvaluationContext.new(
|
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 =
|
23
|
+
monit = monit_erb.render(template_context, job_name, index, logger)
|
22
24
|
|
23
|
-
|
24
|
-
file_contents =
|
25
|
-
RenderedFileTemplate.new(
|
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,
|
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
|
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.
|
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-
|
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.
|
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.
|
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/
|
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: -
|
120
|
+
hash: -3606702560231579831
|
121
121
|
requirements: []
|
122
122
|
rubyforge_project:
|
123
123
|
rubygems_version: 1.8.23
|