bosh-director-core 1.3202.0 → 1.3213.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bb842b11e8c46b11cb2d49b58dd34c6714e471f6
4
- data.tar.gz: e66c1c493c6f4783480f228cabaa22ed3401c5e0
3
+ metadata.gz: d8ddd09c19af85516dfc14db1177d92f41409417
4
+ data.tar.gz: 14d761f6bd1b68ab2b68506e7cf8c9151b2a28be
5
5
  SHA512:
6
- metadata.gz: 20b4320641f249a0647afd1a98f6701a0fb615b822cbbcbf93b11a054e4a6959ac39b4650fb4511caf46d91b9b81c6bbec129f6449bcd212d381277d4c600584
7
- data.tar.gz: 5b7d7b27d93162c93e00682e29ac7e7a923b5530097d40777fb9cb8b84f4804555a6ef6d5e56ebedbd7e18408d0a394cd4b749a14096564c7ec302892c6abce4
6
+ metadata.gz: 5985cf33c89328de20ed3102745b890d851721345e3ac5bb7aff4a3e75cf82f2aa31a948895332a86045de2d160c31322aea1f495a6f74b7dd600d241a9bd86f
7
+ data.tar.gz: 576571f5435a45f8d8595f7b20f1030e745cf7fd01f0f8418f75b8e07d80745bb561aebca559f97dddddd8775ed50e368a8242f6fef9d84e5de86c0a8647d5a6
@@ -9,9 +9,26 @@ module Bosh::Director::Core::Templates
9
9
  end
10
10
 
11
11
  def render(spec)
12
+ errors = []
13
+
12
14
  rendered_templates = @templates.map do |template|
13
15
  job_template_renderer = job_template_renderers[template.name]
14
- job_template_renderer.render(spec)
16
+
17
+ begin
18
+ job_template_renderer.render(spec)
19
+ rescue Exception => e
20
+ errors.push e
21
+ end
22
+ end
23
+
24
+ if errors.length > 0
25
+ message = "Unable to render jobs for instance group '#{spec['job']['name']}'. Errors are:"
26
+
27
+ errors.each do |e|
28
+ message = "#{message}\n - #{e.message.gsub(/\n/, "\n ")}"
29
+ end
30
+
31
+ raise message
15
32
  end
16
33
 
17
34
  RenderedJobInstance.new(rendered_templates)
@@ -2,6 +2,7 @@ require 'bosh/director/core/templates'
2
2
  require 'bosh/director/core/templates/rendered_job_template'
3
3
  require 'bosh/director/core/templates/rendered_file_template'
4
4
  require 'bosh/template/evaluation_context'
5
+ require 'common/deep_copy'
5
6
 
6
7
  module Bosh::Director::Core::Templates
7
8
  class JobTemplateRenderer
@@ -15,18 +16,60 @@ module Bosh::Director::Core::Templates
15
16
  end
16
17
 
17
18
  def render(spec)
18
- template_context = Bosh::Template::EvaluationContext.new(spec)
19
- job_name = spec['job']['name']
20
- index = spec['index']
19
+ template_context = Bosh::Template::EvaluationContext.new(adjust_template_properties(spec,@name))
21
20
 
22
- monit = monit_erb.render(template_context, job_name, index, @logger)
21
+ monit = monit_erb.render(template_context, @logger)
22
+
23
+ errors = []
23
24
 
24
25
  rendered_files = source_erbs.map do |source_erb|
25
- file_contents = source_erb.render(template_context, job_name, index, @logger)
26
+ begin
27
+ file_contents = source_erb.render(template_context, @logger)
28
+ rescue Exception => e
29
+ errors.push e
30
+ end
31
+
26
32
  RenderedFileTemplate.new(source_erb.src_name, source_erb.dest_name, file_contents)
27
33
  end
28
34
 
35
+ if errors.length > 0
36
+ message = "Unable to render templates for job '#{@name}'. Errors are:"
37
+
38
+ errors.each do |e|
39
+ message = "#{message}\n - #{e.message.gsub(/\n/, "\n ")}"
40
+ end
41
+
42
+ raise message
43
+ end
44
+
29
45
  RenderedJobTemplate.new(@name, monit, rendered_files)
30
46
  end
47
+
48
+ private
49
+
50
+ # This method will check if the current template has any properties that were
51
+ # defined at the template level in the deployment manifest; if yes, it will make
52
+ # a deep copy of the spec and change the spec.properties to <current-template>.template_scoped_properties.
53
+ # This is due to the requirement that limits the available properties for a template
54
+ # by the properties defined in the template scope in the deployment manifest, if they exist.
55
+ # We make a deep copy of the spec to be safe, as we are modifying it.
56
+ def adjust_template_properties(spec, current_template_name)
57
+ result = spec
58
+ if spec['job'].is_a?(Hash) && !spec['job']['templates'].nil?
59
+ current_template = spec['job']['templates'].find {|template| template['name'] == current_template_name }
60
+
61
+ if !current_template['template_scoped_properties'].nil?
62
+ # Make a deep copy of the spec and replace the properties with
63
+ # the specific template properties.
64
+ altered_spec = Bosh::Common::DeepCopy.copy(spec)
65
+ altered_spec['properties'] = Bosh::Common::DeepCopy.copy(
66
+ current_template['template_scoped_properties']
67
+ )
68
+ result = altered_spec
69
+ end
70
+ end
71
+ result
72
+ end
73
+
31
74
  end
32
75
  end
@@ -13,20 +13,18 @@ module Bosh::Director::Core::Templates
13
13
  @erb = erb
14
14
  end
15
15
 
16
- def render(context, job_name, index, logger)
16
+ def render(context, logger)
17
17
  erb.result(context.get_binding)
18
18
  # rubocop:disable RescueException
19
19
  rescue Exception => e
20
20
  # rubocop:enable RescueException
21
21
 
22
22
  logger.debug(e.inspect)
23
- job_desc = "#{job_name}/#{index}"
24
23
  line_index = e.backtrace.index { |l| l.include?(erb.filename) }
25
24
  line = line_index ? e.backtrace[line_index] : '(unknown):(unknown)'
26
25
  template_name, line = line.split(':')
27
26
 
28
- message = "Error filling in template `#{File.basename(template_name)}' " +
29
- "for `#{job_desc}' (line #{line}: #{e})"
27
+ message = "Error filling in template '#{File.basename(template_name)}' (line #{line}: #{e})"
30
28
 
31
29
  logger.debug("#{message}\n#{e.backtrace.join("\n")}")
32
30
  raise message
@@ -1,7 +1,7 @@
1
1
  module Bosh
2
2
  module Director
3
3
  module Core
4
- VERSION = '1.3202.0'
4
+ VERSION = '1.3213.0'
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bosh-director-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3202.0
4
+ version: 1.3213.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pivotal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-23 00:00:00.000000000 Z
11
+ date: 2016-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bosh_common
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.3202.0
19
+ version: 1.3213.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.3202.0
26
+ version: 1.3213.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bosh-template
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.3202.0
33
+ version: 1.3213.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.3202.0
40
+ version: 1.3213.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement