bosh-director 1.5.0.pre.1335 → 1.5.0.pre.1336

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,20 +1,20 @@
1
1
  require 'bosh/director/job_template_loader'
2
+ require 'bosh/director/job_instance_renderer'
2
3
 
3
4
  module Bosh::Director
4
5
  class ConfigurationHasher
5
6
  # @param [DeploymentPlan::Job]
6
7
  def initialize(job)
7
8
  @job = job
8
- @job_template_loader = JobTemplateLoader.new
9
9
  end
10
10
 
11
11
  def hash
12
- job_renders = @job.templates.sort { |x, y| x.name <=> y.name }.map do |job_template|
13
- [job_template.name, @job_template_loader.process(job_template)]
14
- end
12
+ job_template_loader = JobTemplateLoader.new
13
+ job_instance_renderer = JobInstanceRenderer.new(@job, job_template_loader)
15
14
 
16
15
  @job.instances.each do |instance|
17
- instance_digest, template_digests = render_digest(instance, job_renders)
16
+ rendered_job_templates = job_instance_renderer.render(instance)
17
+ instance_digest, template_digests = render_digest(rendered_job_templates)
18
18
  instance.configuration_hash = instance_digest.hexdigest
19
19
  instance.template_hashes = template_digests
20
20
  end
@@ -22,22 +22,20 @@ module Bosh::Director
22
22
 
23
23
  private
24
24
 
25
- def render_digest(instance, job_renderers)
25
+ def render_digest(rendered_job_templates)
26
26
  instance_digest = Digest::SHA1.new
27
27
  template_digests = {}
28
- job_renderers.each do |job_template_name, template_renderer|
29
- rendered_template = template_renderer.render(@job.name, instance)
30
-
28
+ rendered_job_templates.each do |rendered_job_template|
31
29
  bound_templates = ''
32
- bound_templates << rendered_template.monit
30
+ bound_templates << rendered_job_template.monit
33
31
 
34
- template_renderer.templates.keys.sort.each do |template_name|
35
- bound_templates << rendered_template.templates[template_name]
32
+ rendered_job_template.templates.keys.sort.each do |src_name|
33
+ bound_templates << rendered_job_template.templates[src_name]
36
34
  instance_digest << bound_templates
37
35
 
38
36
  template_digest = Digest::SHA1.new
39
37
  template_digest << bound_templates
40
- template_digests[job_template_name] = template_digest.hexdigest
38
+ template_digests[rendered_job_template.name] = template_digest.hexdigest
41
39
  end
42
40
  end
43
41
  return instance_digest, template_digests
@@ -0,0 +1,27 @@
1
+ module Bosh::Director
2
+ class JobInstanceRenderer
3
+
4
+ def initialize(job, job_template_loader)
5
+ @job = job
6
+ @job_template_loader = job_template_loader
7
+ end
8
+
9
+ def render(instance)
10
+ job.templates.map do |template|
11
+ job_template_renderer = job_template_renderers[template.name]
12
+ job_template_renderer.render(job.name, instance)
13
+ end.sort { |x, y| x.name <=> y.name }
14
+ end
15
+
16
+ private
17
+
18
+ def job_template_renderers
19
+ @job_template_renderers ||= job.templates.reduce({}) do |hash, template|
20
+ hash[template.name] = job_template_loader.process(template)
21
+ hash
22
+ end
23
+ end
24
+
25
+ attr_reader :job_template_loader, :job
26
+ end
27
+ end
@@ -2,38 +2,38 @@ require 'bosh/director/job_template_renderer'
2
2
 
3
3
  module Bosh::Director
4
4
  class JobTemplateLoader
5
- def process(job)
6
- template_dir = extract_template(job)
5
+ def process(job_template)
6
+ template_dir = extract_template(job_template)
7
7
  manifest = Psych.load_file(File.join(template_dir, 'job.MF'))
8
8
 
9
9
  monit_template = erb(File.join(template_dir, 'monit'))
10
- monit_template.filename = File.join(job.name, 'monit')
10
+ monit_template.filename = File.join(job_template.name, 'monit')
11
11
 
12
12
  templates = {}
13
13
 
14
14
  if manifest['templates']
15
15
  manifest['templates'].each_key do |template_name|
16
16
  template = erb(File.join(template_dir, 'templates', template_name))
17
- template.filename = File.join(job.name, template_name)
17
+ template.filename = File.join(job_template.name, template_name)
18
18
  templates[template_name] = template
19
19
  end
20
20
  end
21
21
 
22
- JobTemplateRenderer.new(monit_template, templates)
22
+ JobTemplateRenderer.new(job_template.name, monit_template, templates)
23
23
  ensure
24
24
  FileUtils.rm_rf(template_dir) if template_dir
25
25
  end
26
26
 
27
27
  private
28
28
 
29
- def extract_template(template)
30
- temp_path = template.download_blob
29
+ def extract_template(job_template)
30
+ temp_path = job_template.download_blob
31
31
  template_dir = Dir.mktmpdir('template_dir')
32
32
 
33
33
  output = `tar -C #{template_dir} -xzf #{temp_path} 2>&1`
34
34
  if $?.exitstatus != 0
35
35
  raise JobTemplateUnpackFailed,
36
- "Cannot unpack `#{template.name}' job template, " +
36
+ "Cannot unpack `#{job_template.name}' job template, " +
37
37
  "tar returned #{$?.exitstatus}, " +
38
38
  "tar output: #{output}"
39
39
  end
@@ -3,7 +3,8 @@ module Bosh::Director
3
3
 
4
4
  attr_reader :monit_template, :templates
5
5
 
6
- def initialize(monit_template, templates)
6
+ def initialize(name, monit_template, templates)
7
+ @name = name
7
8
  @monit_template = monit_template
8
9
  @templates = templates
9
10
  @logger = Config.logger
@@ -14,14 +15,18 @@ module Bosh::Director
14
15
 
15
16
  monit = render_erb(job_name, monit_template, template_context, instance.index)
16
17
  rendered_templates = {}
17
- templates.keys.sort.each do |name|
18
- rendered_templates[name] = render_erb(job_name, templates[name], template_context, instance.index)
18
+ templates.keys.sort.each do |src_name|
19
+ rendered_templates[src_name] = render_erb(job_name, templates[src_name], template_context, instance.index)
19
20
  end
20
- return RenderedJobTemplate.new(monit, rendered_templates)
21
+ return RenderedJobTemplate.new(name, monit, rendered_templates)
21
22
  end
22
23
 
23
24
  private
24
25
 
26
+ private
27
+
28
+ attr_reader :name
29
+
25
30
  def render_erb(job_name, template, template_context, index)
26
31
  template.result(template_context.get_binding)
27
32
  rescue Exception => e
@@ -39,5 +44,5 @@ module Bosh::Director
39
44
  end
40
45
  end
41
46
 
42
- RenderedJobTemplate = Struct.new(:monit, :templates)
47
+ RenderedJobTemplate = Struct.new(:name, :monit, :templates)
43
48
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Bosh
4
4
  module Director
5
- VERSION = '1.5.0.pre.1335'
5
+ VERSION = '1.5.0.pre.1336'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bosh-director
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0.pre.1335
4
+ version: 1.5.0.pre.1336
5
5
  prerelease: 6
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: 2013-11-14 00:00:00.000000000 Z
12
+ date: 2013-11-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bcrypt-ruby
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: 1.5.0.pre.1335
37
+ version: 1.5.0.pre.1336
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: 1.5.0.pre.1335
45
+ version: 1.5.0.pre.1336
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: bosh-core
48
48
  requirement: !ruby/object:Gem::Requirement
@@ -50,7 +50,7 @@ dependencies:
50
50
  requirements:
51
51
  - - ~>
52
52
  - !ruby/object:Gem::Version
53
- version: 1.5.0.pre.1335
53
+ version: 1.5.0.pre.1336
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
@@ -58,7 +58,7 @@ dependencies:
58
58
  requirements:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: 1.5.0.pre.1335
61
+ version: 1.5.0.pre.1336
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: bosh_common
64
64
  requirement: !ruby/object:Gem::Requirement
@@ -66,7 +66,7 @@ dependencies:
66
66
  requirements:
67
67
  - - ~>
68
68
  - !ruby/object:Gem::Version
69
- version: 1.5.0.pre.1335
69
+ version: 1.5.0.pre.1336
70
70
  type: :runtime
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
@@ -74,7 +74,7 @@ dependencies:
74
74
  requirements:
75
75
  - - ~>
76
76
  - !ruby/object:Gem::Version
77
- version: 1.5.0.pre.1335
77
+ version: 1.5.0.pre.1336
78
78
  - !ruby/object:Gem::Dependency
79
79
  name: bosh_cpi
80
80
  requirement: !ruby/object:Gem::Requirement
@@ -82,7 +82,7 @@ dependencies:
82
82
  requirements:
83
83
  - - ~>
84
84
  - !ruby/object:Gem::Version
85
- version: 1.5.0.pre.1335
85
+ version: 1.5.0.pre.1336
86
86
  type: :runtime
87
87
  prerelease: false
88
88
  version_requirements: !ruby/object:Gem::Requirement
@@ -90,7 +90,7 @@ dependencies:
90
90
  requirements:
91
91
  - - ~>
92
92
  - !ruby/object:Gem::Version
93
- version: 1.5.0.pre.1335
93
+ version: 1.5.0.pre.1336
94
94
  - !ruby/object:Gem::Dependency
95
95
  name: bosh_openstack_cpi
96
96
  requirement: !ruby/object:Gem::Requirement
@@ -98,7 +98,7 @@ dependencies:
98
98
  requirements:
99
99
  - - ~>
100
100
  - !ruby/object:Gem::Version
101
- version: 1.5.0.pre.1335
101
+ version: 1.5.0.pre.1336
102
102
  type: :runtime
103
103
  prerelease: false
104
104
  version_requirements: !ruby/object:Gem::Requirement
@@ -106,7 +106,7 @@ dependencies:
106
106
  requirements:
107
107
  - - ~>
108
108
  - !ruby/object:Gem::Version
109
- version: 1.5.0.pre.1335
109
+ version: 1.5.0.pre.1336
110
110
  - !ruby/object:Gem::Dependency
111
111
  name: bosh_aws_cpi
112
112
  requirement: !ruby/object:Gem::Requirement
@@ -114,7 +114,7 @@ dependencies:
114
114
  requirements:
115
115
  - - ~>
116
116
  - !ruby/object:Gem::Version
117
- version: 1.5.0.pre.1335
117
+ version: 1.5.0.pre.1336
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
@@ -122,7 +122,7 @@ dependencies:
122
122
  requirements:
123
123
  - - ~>
124
124
  - !ruby/object:Gem::Version
125
- version: 1.5.0.pre.1335
125
+ version: 1.5.0.pre.1336
126
126
  - !ruby/object:Gem::Dependency
127
127
  name: bosh_vsphere_cpi
128
128
  requirement: !ruby/object:Gem::Requirement
@@ -130,7 +130,7 @@ dependencies:
130
130
  requirements:
131
131
  - - ~>
132
132
  - !ruby/object:Gem::Version
133
- version: 1.5.0.pre.1335
133
+ version: 1.5.0.pre.1336
134
134
  type: :runtime
135
135
  prerelease: false
136
136
  version_requirements: !ruby/object:Gem::Requirement
@@ -138,7 +138,7 @@ dependencies:
138
138
  requirements:
139
139
  - - ~>
140
140
  - !ruby/object:Gem::Version
141
- version: 1.5.0.pre.1335
141
+ version: 1.5.0.pre.1336
142
142
  - !ruby/object:Gem::Dependency
143
143
  name: eventmachine
144
144
  requirement: !ruby/object:Gem::Requirement
@@ -445,7 +445,7 @@ dependencies:
445
445
  version: '1.0'
446
446
  description: ! 'BOSH Director
447
447
 
448
- a3d938'
448
+ c42ba6'
449
449
  email: support@cloudfoundry.com
450
450
  executables:
451
451
  - bosh-director
@@ -576,6 +576,7 @@ files:
576
576
  - lib/bosh/director/instance_preparer.rb
577
577
  - lib/bosh/director/instance_updater.rb
578
578
  - lib/bosh/director/ip_util.rb
579
+ - lib/bosh/director/job_instance_renderer.rb
579
580
  - lib/bosh/director/job_queue.rb
580
581
  - lib/bosh/director/job_runner.rb
581
582
  - lib/bosh/director/job_template_loader.rb