bosh-director 1.5.0.pre.1332 → 1.5.0.pre.1333
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,114 +1,46 @@
|
|
1
|
-
|
1
|
+
require 'bosh/director/job_template_loader'
|
2
2
|
|
3
3
|
module Bosh::Director
|
4
4
|
class ConfigurationHasher
|
5
5
|
# @param [DeploymentPlan::Job]
|
6
6
|
def initialize(job)
|
7
7
|
@job = job
|
8
|
-
@
|
9
|
-
end
|
10
|
-
|
11
|
-
# @param [DeploymentPlan::Template] template Template to extract
|
12
|
-
# @return [String] Path to a directory where template has been extracted
|
13
|
-
def extract_template(template)
|
14
|
-
temp_path = template.download_blob
|
15
|
-
template_dir = Dir.mktmpdir("template_dir")
|
16
|
-
|
17
|
-
output = `tar -C #{template_dir} -xzf #{temp_path} 2>&1`
|
18
|
-
if $?.exitstatus != 0
|
19
|
-
raise JobTemplateUnpackFailed,
|
20
|
-
"Cannot unpack `#{template.name}' job template, " +
|
21
|
-
"tar returned #{$?.exitstatus}, " +
|
22
|
-
"tar output: #{output}"
|
23
|
-
end
|
24
|
-
|
25
|
-
template_dir
|
26
|
-
ensure
|
27
|
-
FileUtils.rm_f(temp_path) if temp_path
|
28
|
-
end
|
29
|
-
|
30
|
-
# @param [DeploymentPlan::Template]
|
31
|
-
def process_template(job_template)
|
32
|
-
template_dir = extract_template(job_template)
|
33
|
-
manifest = Psych.load_file(File.join(template_dir, "job.MF"))
|
34
|
-
|
35
|
-
monit_template = erb(File.join(template_dir, "monit"))
|
36
|
-
monit_template.filename = File.join(job_template.name, "monit")
|
37
|
-
|
38
|
-
templates = {}
|
39
|
-
|
40
|
-
if manifest["templates"]
|
41
|
-
manifest["templates"].each_key do |template_name|
|
42
|
-
template = erb(File.join(template_dir, "templates", template_name))
|
43
|
-
templates[template_name] = template
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
@cached_templates[job_template.name] = {
|
48
|
-
"templates" => templates,
|
49
|
-
"monit_template" => monit_template
|
50
|
-
}
|
51
|
-
ensure
|
52
|
-
FileUtils.rm_rf(template_dir) if template_dir
|
8
|
+
@job_template_loader = JobTemplateLoader.new
|
53
9
|
end
|
54
10
|
|
55
11
|
def hash
|
56
|
-
|
57
|
-
|
58
|
-
sorted_jobs.each do |job_template|
|
59
|
-
process_template(job_template)
|
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)]
|
60
14
|
end
|
61
|
-
@job.instances.each do |instance|
|
62
|
-
instance_digest = Digest::SHA1.new
|
63
|
-
template_digests = {}
|
64
|
-
sorted_jobs.each do |job_template|
|
65
|
-
templates = @cached_templates[job_template.name]["templates"]
|
66
|
-
monit_template =
|
67
|
-
@cached_templates[job_template.name]["monit_template"]
|
68
|
-
|
69
|
-
binding_helper = Bosh::Common::TemplateEvaluationContext.new(
|
70
|
-
instance.spec)
|
71
15
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
templates.keys.sort.each do |template_name|
|
76
|
-
template = templates[template_name]
|
77
|
-
template.filename = File.join(job_template.name, template_name)
|
78
|
-
bound_templates << bind_template(template, binding_helper,
|
79
|
-
instance.index)
|
80
|
-
template_digest = Digest::SHA1.new
|
81
|
-
template_digest << bound_templates
|
82
|
-
instance_digest << bound_templates
|
83
|
-
template_digests[job_template.name] = template_digest.hexdigest
|
84
|
-
end
|
85
|
-
end
|
16
|
+
@job.instances.each do |instance|
|
17
|
+
instance_digest, template_digests = render_digest(instance, job_renders)
|
86
18
|
instance.configuration_hash = instance_digest.hexdigest
|
87
19
|
instance.template_hashes = template_digests
|
88
20
|
end
|
89
21
|
end
|
90
22
|
|
91
|
-
|
92
|
-
template.result(binding_helper.get_binding)
|
93
|
-
rescue Exception => e
|
94
|
-
@logger.debug(e.inspect)
|
95
|
-
job_desc = "#{@job.name}/#{index}"
|
96
|
-
line_index = e.backtrace.index{ |l| l.include?(template.filename) }
|
97
|
-
line = line_index ? e.backtrace[line_index] : '(unknown):(unknown)'
|
98
|
-
template_name, line = line.split(':')
|
23
|
+
private
|
99
24
|
|
100
|
-
|
101
|
-
|
25
|
+
def render_digest(instance, job_renderers)
|
26
|
+
instance_digest = Digest::SHA1.new
|
27
|
+
template_digests = {}
|
28
|
+
job_renderers.each do |job_template_name, template_renderer|
|
29
|
+
rendered_template = template_renderer.render(@job.name, instance)
|
102
30
|
|
103
|
-
|
104
|
-
|
105
|
-
end
|
31
|
+
bound_templates = ''
|
32
|
+
bound_templates << rendered_template.monit
|
106
33
|
|
107
|
-
|
34
|
+
template_renderer.templates.keys.sort.each do |template_name|
|
35
|
+
bound_templates << rendered_template.templates[template_name]
|
36
|
+
instance_digest << bound_templates
|
108
37
|
|
109
|
-
|
110
|
-
|
38
|
+
template_digest = Digest::SHA1.new
|
39
|
+
template_digest << bound_templates
|
40
|
+
template_digests[job_template_name] = template_digest.hexdigest
|
41
|
+
end
|
42
|
+
end
|
43
|
+
return instance_digest, template_digests
|
111
44
|
end
|
112
|
-
|
113
45
|
end
|
114
46
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'bosh/director/job_template_renderer'
|
2
|
+
|
3
|
+
module Bosh::Director
|
4
|
+
class JobTemplateLoader
|
5
|
+
def process(job)
|
6
|
+
template_dir = extract_template(job)
|
7
|
+
manifest = Psych.load_file(File.join(template_dir, 'job.MF'))
|
8
|
+
|
9
|
+
monit_template = erb(File.join(template_dir, 'monit'))
|
10
|
+
monit_template.filename = File.join(job.name, 'monit')
|
11
|
+
|
12
|
+
templates = {}
|
13
|
+
|
14
|
+
if manifest['templates']
|
15
|
+
manifest['templates'].each_key do |template_name|
|
16
|
+
template = erb(File.join(template_dir, 'templates', template_name))
|
17
|
+
template.filename = File.join(job.name, template_name)
|
18
|
+
templates[template_name] = template
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
JobTemplateRenderer.new(monit_template, templates)
|
23
|
+
ensure
|
24
|
+
FileUtils.rm_rf(template_dir) if template_dir
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def extract_template(template)
|
30
|
+
temp_path = template.download_blob
|
31
|
+
template_dir = Dir.mktmpdir('template_dir')
|
32
|
+
|
33
|
+
output = `tar -C #{template_dir} -xzf #{temp_path} 2>&1`
|
34
|
+
if $?.exitstatus != 0
|
35
|
+
raise JobTemplateUnpackFailed,
|
36
|
+
"Cannot unpack `#{template.name}' job template, " +
|
37
|
+
"tar returned #{$?.exitstatus}, " +
|
38
|
+
"tar output: #{output}"
|
39
|
+
end
|
40
|
+
|
41
|
+
template_dir
|
42
|
+
ensure
|
43
|
+
FileUtils.rm_f(temp_path) if temp_path
|
44
|
+
end
|
45
|
+
|
46
|
+
def erb(path)
|
47
|
+
ERB.new(File.read(path))
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Bosh::Director
|
2
|
+
class JobTemplateRenderer
|
3
|
+
|
4
|
+
attr_reader :monit_template, :templates
|
5
|
+
|
6
|
+
def initialize(monit_template, templates)
|
7
|
+
@monit_template = monit_template
|
8
|
+
@templates = templates
|
9
|
+
@logger = Config.logger
|
10
|
+
end
|
11
|
+
|
12
|
+
def render(job_name, instance)
|
13
|
+
template_context = Bosh::Common::TemplateEvaluationContext.new(instance.spec)
|
14
|
+
|
15
|
+
monit = render_erb(job_name, monit_template, template_context, instance.index)
|
16
|
+
rendered_templates = {}
|
17
|
+
templates.keys.sort.each do |name|
|
18
|
+
rendered_templates[name] = render_erb(job_name, templates[name], template_context, instance.index)
|
19
|
+
end
|
20
|
+
return RenderedJobTemplate.new(monit, rendered_templates)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def render_erb(job_name, template, template_context, index)
|
26
|
+
template.result(template_context.get_binding)
|
27
|
+
rescue Exception => e
|
28
|
+
@logger.debug(e.inspect)
|
29
|
+
job_desc = "#{job_name}/#{index}"
|
30
|
+
line_index = e.backtrace.index{ |l| l.include?(template.filename) }
|
31
|
+
line = line_index ? e.backtrace[line_index] : '(unknown):(unknown)'
|
32
|
+
template_name, line = line.split(':')
|
33
|
+
|
34
|
+
message = "Error filling in template `#{File.basename(template_name)}' " +
|
35
|
+
"for `#{job_desc}' (line #{line}: #{e})"
|
36
|
+
|
37
|
+
@logger.debug("#{message}\n#{e.backtrace.join("\n")}")
|
38
|
+
raise JobTemplateBindingFailed, "#{message}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
RenderedJobTemplate = Struct.new(:monit, :templates)
|
43
|
+
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.
|
4
|
+
version: 1.5.0.pre.1333
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
requirements:
|
35
35
|
- - ~>
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: 1.5.0.pre.
|
37
|
+
version: 1.5.0.pre.1333
|
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.
|
45
|
+
version: 1.5.0.pre.1333
|
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.
|
53
|
+
version: 1.5.0.pre.1333
|
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.
|
61
|
+
version: 1.5.0.pre.1333
|
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.
|
69
|
+
version: 1.5.0.pre.1333
|
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.
|
77
|
+
version: 1.5.0.pre.1333
|
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.
|
85
|
+
version: 1.5.0.pre.1333
|
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.
|
93
|
+
version: 1.5.0.pre.1333
|
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.
|
101
|
+
version: 1.5.0.pre.1333
|
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.
|
109
|
+
version: 1.5.0.pre.1333
|
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.
|
117
|
+
version: 1.5.0.pre.1333
|
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.
|
125
|
+
version: 1.5.0.pre.1333
|
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.
|
133
|
+
version: 1.5.0.pre.1333
|
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.
|
141
|
+
version: 1.5.0.pre.1333
|
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
|
-
|
448
|
+
063aca'
|
449
449
|
email: support@cloudfoundry.com
|
450
450
|
executables:
|
451
451
|
- bosh-director
|
@@ -578,6 +578,8 @@ files:
|
|
578
578
|
- lib/bosh/director/ip_util.rb
|
579
579
|
- lib/bosh/director/job_queue.rb
|
580
580
|
- lib/bosh/director/job_runner.rb
|
581
|
+
- lib/bosh/director/job_template_loader.rb
|
582
|
+
- lib/bosh/director/job_template_renderer.rb
|
581
583
|
- lib/bosh/director/job_updater.rb
|
582
584
|
- lib/bosh/director/jobs/backup.rb
|
583
585
|
- lib/bosh/director/jobs/base_job.rb
|