bosh-director 1.1858.0 → 1.1868.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/bosh/director.rb +0 -1
- data/lib/bosh/director/compiled_packages_exporter.rb +2 -2
- data/lib/bosh/director/deployment_plan.rb +0 -1
- data/lib/bosh/director/deployment_plan/instance.rb +1 -1
- data/lib/bosh/director/deployment_plan/job.rb +8 -2
- data/lib/bosh/director/job_renderer.rb +5 -5
- data/lib/bosh/director/jobs/backup.rb +3 -1
- data/lib/bosh/director/version.rb +1 -1
- metadata +34 -27
- data/lib/bosh/director/compressed_rendered_job_templates.rb +0 -30
- data/lib/bosh/director/deployment_plan/rendered_templates_archive.rb +0 -14
- data/lib/bosh/director/job_instance_renderer.rb +0 -30
- data/lib/bosh/director/job_template_loader.rb +0 -56
- data/lib/bosh/director/job_template_renderer.rb +0 -50
- data/lib/bosh/director/rendered_job_instance.rb +0 -48
- data/lib/bosh/director/rendered_job_template.rb +0 -21
- data/lib/bosh/director/rendered_templates_writer.rb +0 -24
- data/lib/bosh/director/tar_gzipper.rb +0 -46
data/lib/bosh/director.rb
CHANGED
@@ -73,7 +73,6 @@ require 'bosh/director/instance_updater'
|
|
73
73
|
require 'bosh/director/job_runner'
|
74
74
|
require 'bosh/director/job_updater'
|
75
75
|
require 'bosh/director/job_queue'
|
76
|
-
require 'bosh/director/tar_gzipper'
|
77
76
|
require 'bosh/director/lock'
|
78
77
|
require 'bosh/director/nats_rpc'
|
79
78
|
require 'bosh/director/network_reservation'
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'bosh/director/tar_gzipper'
|
1
|
+
require 'bosh/director/core/tar_gzipper'
|
2
2
|
require 'bosh/director/compiled_package_downloader'
|
3
3
|
|
4
4
|
module Bosh::Director
|
@@ -15,7 +15,7 @@ module Bosh::Director
|
|
15
15
|
manifest = CompiledPackageManifest.new(@compiled_package_group)
|
16
16
|
manifest.write(File.join(download_dir, 'compiled_packages.MF'))
|
17
17
|
|
18
|
-
archiver = TarGzipper.new
|
18
|
+
archiver = Core::TarGzipper.new
|
19
19
|
archiver.compress(download_dir, ['compiled_packages', 'compiled_packages.MF'], output_path)
|
20
20
|
ensure
|
21
21
|
downloader.cleanup
|
@@ -10,7 +10,6 @@ require 'bosh/director/deployment_plan/job'
|
|
10
10
|
require 'bosh/director/deployment_plan/network'
|
11
11
|
require 'bosh/director/deployment_plan/network_subnet'
|
12
12
|
require 'bosh/director/deployment_plan/compiled_package'
|
13
|
-
require 'bosh/director/deployment_plan/rendered_templates_archive'
|
14
13
|
require 'bosh/director/deployment_plan/preparer'
|
15
14
|
require 'bosh/director/deployment_plan/resource_pools'
|
16
15
|
require 'bosh/director/deployment_plan/multi_job_updater'
|
@@ -19,7 +19,7 @@ module Bosh::Director
|
|
19
19
|
# @return [Hash] A hash of template SHA1 hashes
|
20
20
|
attr_accessor :template_hashes
|
21
21
|
|
22
|
-
# @return [
|
22
|
+
# @return [Bosh::Director::Core::Templates::RenderedTemplatesArchive]
|
23
23
|
attr_accessor :rendered_templates_archive
|
24
24
|
|
25
25
|
# @return [Hash<String, NetworkReservation>] network reservations
|
@@ -215,9 +215,15 @@ module Bosh::Director
|
|
215
215
|
|
216
216
|
releases_by_package_names.each do |package_name, releases|
|
217
217
|
if releases.size > 1
|
218
|
+
release1, release2 = releases.to_a[0..1]
|
219
|
+
offending_template1 = templates.find { |t| t.release == release1 }
|
220
|
+
offending_template2 = templates.find { |t| t.release == release2 }
|
221
|
+
|
218
222
|
raise JobPackageCollision,
|
219
|
-
"
|
220
|
-
'
|
223
|
+
"Package name collision detected in job `#{@name}': "\
|
224
|
+
"template `#{release1.name}/#{offending_template1.name}' depends on package `#{release1.name}/#{package_name}', "\
|
225
|
+
"template `#{release2.name}/#{offending_template2.name}' depends on `#{release2.name}/#{package_name}'. " +
|
226
|
+
'BOSH cannot currently collocate two packages with identical names from separate releases.'
|
221
227
|
end
|
222
228
|
end
|
223
229
|
end
|
@@ -1,13 +1,13 @@
|
|
1
|
-
require 'bosh/director/job_template_loader'
|
2
|
-
require 'bosh/director/job_instance_renderer'
|
1
|
+
require 'bosh/director/core/templates/job_template_loader'
|
2
|
+
require 'bosh/director/core/templates/job_instance_renderer'
|
3
3
|
|
4
4
|
module Bosh::Director
|
5
5
|
class JobRenderer
|
6
6
|
# @param [DeploymentPlan::Job]
|
7
7
|
def initialize(job)
|
8
8
|
@job = job
|
9
|
-
job_template_loader = JobTemplateLoader.new(Config.logger)
|
10
|
-
@instance_renderer = JobInstanceRenderer.new(@job, job_template_loader)
|
9
|
+
job_template_loader = Core::Templates::JobTemplateLoader.new(Config.logger)
|
10
|
+
@instance_renderer = Core::Templates::JobInstanceRenderer.new(@job, job_template_loader)
|
11
11
|
end
|
12
12
|
|
13
13
|
def render_job_instances(blobstore)
|
@@ -18,7 +18,7 @@ module Bosh::Director
|
|
18
18
|
|
19
19
|
archive_model = instance.model.latest_rendered_templates_archive
|
20
20
|
if archive_model && archive_model.content_sha1 == configuration_hash
|
21
|
-
rendered_templates_archive =
|
21
|
+
rendered_templates_archive = Core::Templates::RenderedTemplatesArchive.new(archive_model.blobstore_id, archive_model.sha1)
|
22
22
|
else
|
23
23
|
rendered_templates_archive = rendered_job_instance.persist(blobstore)
|
24
24
|
instance.model.add_rendered_templates_archive(
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'bosh/director/core/tar_gzipper'
|
2
|
+
|
1
3
|
module Bosh::Director
|
2
4
|
module Jobs
|
3
5
|
class Backup < BaseJob
|
@@ -11,7 +13,7 @@ module Bosh::Director
|
|
11
13
|
|
12
14
|
def initialize(dest, options={})
|
13
15
|
@backup_file = dest
|
14
|
-
@tar_gzipper = options.fetch(:tar_gzipper) { TarGzipper.new }
|
16
|
+
@tar_gzipper = options.fetch(:tar_gzipper) { Core::TarGzipper.new }
|
15
17
|
@blobstore_client = options.fetch(:blobstore) { App.instance.blobstores.blobstore }
|
16
18
|
@db_adapter = options.fetch(:db_adapter) { Bosh::Director::DbBackup.create(Config.db_config) }
|
17
19
|
@base_dir = options.fetch(:base_dir) { Config.base_dir }
|
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.
|
4
|
+
version: 1.1868.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-
|
12
|
+
date: 2014-01-29 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.
|
37
|
+
version: 1.1868.0
|
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.
|
45
|
+
version: 1.1868.0
|
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.
|
53
|
+
version: 1.1868.0
|
54
54
|
type: :runtime
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -58,7 +58,23 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 1.
|
61
|
+
version: 1.1868.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: bosh-director-core
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.1868.0
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.1868.0
|
62
78
|
- !ruby/object:Gem::Dependency
|
63
79
|
name: bosh_common
|
64
80
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,7 +82,7 @@ dependencies:
|
|
66
82
|
requirements:
|
67
83
|
- - ~>
|
68
84
|
- !ruby/object:Gem::Version
|
69
|
-
version: 1.
|
85
|
+
version: 1.1868.0
|
70
86
|
type: :runtime
|
71
87
|
prerelease: false
|
72
88
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -74,7 +90,7 @@ dependencies:
|
|
74
90
|
requirements:
|
75
91
|
- - ~>
|
76
92
|
- !ruby/object:Gem::Version
|
77
|
-
version: 1.
|
93
|
+
version: 1.1868.0
|
78
94
|
- !ruby/object:Gem::Dependency
|
79
95
|
name: bosh_cpi
|
80
96
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,7 +98,7 @@ dependencies:
|
|
82
98
|
requirements:
|
83
99
|
- - ~>
|
84
100
|
- !ruby/object:Gem::Version
|
85
|
-
version: 1.
|
101
|
+
version: 1.1868.0
|
86
102
|
type: :runtime
|
87
103
|
prerelease: false
|
88
104
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -90,7 +106,7 @@ dependencies:
|
|
90
106
|
requirements:
|
91
107
|
- - ~>
|
92
108
|
- !ruby/object:Gem::Version
|
93
|
-
version: 1.
|
109
|
+
version: 1.1868.0
|
94
110
|
- !ruby/object:Gem::Dependency
|
95
111
|
name: bosh_openstack_cpi
|
96
112
|
requirement: !ruby/object:Gem::Requirement
|
@@ -98,7 +114,7 @@ dependencies:
|
|
98
114
|
requirements:
|
99
115
|
- - ~>
|
100
116
|
- !ruby/object:Gem::Version
|
101
|
-
version: 1.
|
117
|
+
version: 1.1868.0
|
102
118
|
type: :runtime
|
103
119
|
prerelease: false
|
104
120
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -106,7 +122,7 @@ dependencies:
|
|
106
122
|
requirements:
|
107
123
|
- - ~>
|
108
124
|
- !ruby/object:Gem::Version
|
109
|
-
version: 1.
|
125
|
+
version: 1.1868.0
|
110
126
|
- !ruby/object:Gem::Dependency
|
111
127
|
name: bosh_aws_cpi
|
112
128
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,7 +130,7 @@ dependencies:
|
|
114
130
|
requirements:
|
115
131
|
- - ~>
|
116
132
|
- !ruby/object:Gem::Version
|
117
|
-
version: 1.
|
133
|
+
version: 1.1868.0
|
118
134
|
type: :runtime
|
119
135
|
prerelease: false
|
120
136
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -122,7 +138,7 @@ dependencies:
|
|
122
138
|
requirements:
|
123
139
|
- - ~>
|
124
140
|
- !ruby/object:Gem::Version
|
125
|
-
version: 1.
|
141
|
+
version: 1.1868.0
|
126
142
|
- !ruby/object:Gem::Dependency
|
127
143
|
name: bosh_vsphere_cpi
|
128
144
|
requirement: !ruby/object:Gem::Requirement
|
@@ -130,7 +146,7 @@ dependencies:
|
|
130
146
|
requirements:
|
131
147
|
- - ~>
|
132
148
|
- !ruby/object:Gem::Version
|
133
|
-
version: 1.
|
149
|
+
version: 1.1868.0
|
134
150
|
type: :runtime
|
135
151
|
prerelease: false
|
136
152
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -138,7 +154,7 @@ dependencies:
|
|
138
154
|
requirements:
|
139
155
|
- - ~>
|
140
156
|
- !ruby/object:Gem::Version
|
141
|
-
version: 1.
|
157
|
+
version: 1.1868.0
|
142
158
|
- !ruby/object:Gem::Dependency
|
143
159
|
name: eventmachine
|
144
160
|
requirement: !ruby/object:Gem::Requirement
|
@@ -461,7 +477,7 @@ dependencies:
|
|
461
477
|
version: '1.0'
|
462
478
|
description: ! 'BOSH Director
|
463
479
|
|
464
|
-
|
480
|
+
f69423'
|
465
481
|
email: support@cloudfoundry.com
|
466
482
|
executables:
|
467
483
|
- bosh-director
|
@@ -556,7 +572,6 @@ files:
|
|
556
572
|
- lib/bosh/director/compiled_package_group.rb
|
557
573
|
- lib/bosh/director/compiled_package_manifest.rb
|
558
574
|
- lib/bosh/director/compiled_packages_exporter.rb
|
559
|
-
- lib/bosh/director/compressed_rendered_job_templates.rb
|
560
575
|
- lib/bosh/director/config.rb
|
561
576
|
- lib/bosh/director/cycle_helper.rb
|
562
577
|
- lib/bosh/director/db_backup.rb
|
@@ -581,7 +596,6 @@ files:
|
|
581
596
|
- lib/bosh/director/deployment_plan/planner.rb
|
582
597
|
- lib/bosh/director/deployment_plan/preparer.rb
|
583
598
|
- lib/bosh/director/deployment_plan/release_version.rb
|
584
|
-
- lib/bosh/director/deployment_plan/rendered_templates_archive.rb
|
585
599
|
- lib/bosh/director/deployment_plan/resource_pool.rb
|
586
600
|
- lib/bosh/director/deployment_plan/resource_pools.rb
|
587
601
|
- lib/bosh/director/deployment_plan/stemcell.rb
|
@@ -601,12 +615,9 @@ files:
|
|
601
615
|
- lib/bosh/director/instance_preparer.rb
|
602
616
|
- lib/bosh/director/instance_updater.rb
|
603
617
|
- lib/bosh/director/ip_util.rb
|
604
|
-
- lib/bosh/director/job_instance_renderer.rb
|
605
618
|
- lib/bosh/director/job_queue.rb
|
606
619
|
- lib/bosh/director/job_renderer.rb
|
607
620
|
- lib/bosh/director/job_runner.rb
|
608
|
-
- lib/bosh/director/job_template_loader.rb
|
609
|
-
- lib/bosh/director/job_template_renderer.rb
|
610
621
|
- lib/bosh/director/job_updater.rb
|
611
622
|
- lib/bosh/director/jobs/backup.rb
|
612
623
|
- lib/bosh/director/jobs/base_job.rb
|
@@ -669,15 +680,11 @@ files:
|
|
669
680
|
- lib/bosh/director/problem_handlers/unresponsive_agent.rb
|
670
681
|
- lib/bosh/director/problem_resolver.rb
|
671
682
|
- lib/bosh/director/problem_scanner.rb
|
672
|
-
- lib/bosh/director/rendered_job_instance.rb
|
673
|
-
- lib/bosh/director/rendered_job_template.rb
|
674
683
|
- lib/bosh/director/rendered_job_templates_cleaner.rb
|
675
|
-
- lib/bosh/director/rendered_templates_writer.rb
|
676
684
|
- lib/bosh/director/resource_pool_updater.rb
|
677
685
|
- lib/bosh/director/scheduler.rb
|
678
686
|
- lib/bosh/director/sequel.rb
|
679
687
|
- lib/bosh/director/stale_file_killer.rb
|
680
|
-
- lib/bosh/director/tar_gzipper.rb
|
681
688
|
- lib/bosh/director/task_result_file.rb
|
682
689
|
- lib/bosh/director/thread_pool.rb
|
683
690
|
- lib/bosh/director/validation_helper.rb
|
@@ -715,7 +722,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
715
722
|
version: '0'
|
716
723
|
segments:
|
717
724
|
- 0
|
718
|
-
hash:
|
725
|
+
hash: -2788441104523827358
|
719
726
|
requirements: []
|
720
727
|
rubyforge_project:
|
721
728
|
rubygems_version: 1.8.23
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'tmpdir'
|
2
|
-
require 'digest/sha1'
|
3
|
-
require 'bosh/director/tar_gzipper'
|
4
|
-
require 'bosh/director/rendered_templates_writer'
|
5
|
-
|
6
|
-
module Bosh::Director
|
7
|
-
class CompressedRenderedJobTemplates
|
8
|
-
def initialize(path)
|
9
|
-
@path = path
|
10
|
-
end
|
11
|
-
|
12
|
-
def write(rendered_templates)
|
13
|
-
Dir.mktmpdir do |dir|
|
14
|
-
writer = RenderedTemplatesWriter.new
|
15
|
-
writer.write(rendered_templates, dir)
|
16
|
-
|
17
|
-
tar_gzipper = TarGzipper.new
|
18
|
-
tar_gzipper.compress(dir, %w(.), @path)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def contents
|
23
|
-
File.open(@path, 'r')
|
24
|
-
end
|
25
|
-
|
26
|
-
def sha1
|
27
|
-
Digest::SHA1.file(@path).hexdigest
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module Bosh::Director::DeploymentPlan
|
2
|
-
class RenderedTemplatesArchive
|
3
|
-
attr_reader :blobstore_id, :sha1
|
4
|
-
|
5
|
-
def initialize(blobstore_id, sha1)
|
6
|
-
@blobstore_id = blobstore_id
|
7
|
-
@sha1 = sha1
|
8
|
-
end
|
9
|
-
|
10
|
-
def spec
|
11
|
-
{ 'blobstore_id' => @blobstore_id, 'sha1' => @sha1 }
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'bosh/director/rendered_job_instance'
|
2
|
-
|
3
|
-
module Bosh::Director
|
4
|
-
class JobInstanceRenderer
|
5
|
-
def initialize(job, job_template_loader)
|
6
|
-
@job = job
|
7
|
-
@job_template_loader = job_template_loader
|
8
|
-
end
|
9
|
-
|
10
|
-
def render(instance)
|
11
|
-
rendered_templates = job.templates.map do |template|
|
12
|
-
job_template_renderer = job_template_renderers[template.name]
|
13
|
-
job_template_renderer.render(job.name, instance)
|
14
|
-
end
|
15
|
-
|
16
|
-
RenderedJobInstance.new(rendered_templates)
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def job_template_renderers
|
22
|
-
@job_template_renderers ||= job.templates.reduce({}) do |hash, template|
|
23
|
-
hash[template.name] = job_template_loader.process(template)
|
24
|
-
hash
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
attr_reader :job_template_loader, :job
|
29
|
-
end
|
30
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'bosh/director/job_template_renderer'
|
2
|
-
|
3
|
-
module Bosh::Director
|
4
|
-
SrcFileTemplate = Struct.new(:src_name, :dest_name, :erb_file)
|
5
|
-
|
6
|
-
class JobTemplateLoader
|
7
|
-
def initialize(logger)
|
8
|
-
@logger = logger
|
9
|
-
end
|
10
|
-
|
11
|
-
def process(job_template)
|
12
|
-
template_dir = extract_template(job_template)
|
13
|
-
manifest = Psych.load_file(File.join(template_dir, 'job.MF'))
|
14
|
-
|
15
|
-
monit_template = erb(File.join(template_dir, 'monit'))
|
16
|
-
monit_template.filename = File.join(job_template.name, 'monit')
|
17
|
-
|
18
|
-
templates = []
|
19
|
-
|
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)
|
24
|
-
end
|
25
|
-
|
26
|
-
JobTemplateRenderer.new(job_template.name, monit_template, templates, logger)
|
27
|
-
ensure
|
28
|
-
FileUtils.rm_rf(template_dir) if template_dir
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
attr_reader :logger
|
34
|
-
|
35
|
-
def extract_template(job_template)
|
36
|
-
temp_path = job_template.download_blob
|
37
|
-
template_dir = Dir.mktmpdir('template_dir')
|
38
|
-
|
39
|
-
output = `tar -C #{template_dir} -xzf #{temp_path} 2>&1`
|
40
|
-
if $?.exitstatus != 0
|
41
|
-
raise JobTemplateUnpackFailed,
|
42
|
-
"Cannot unpack `#{job_template.name}' job template, " +
|
43
|
-
"tar returned #{$?.exitstatus}, " +
|
44
|
-
"tar output: #{output}"
|
45
|
-
end
|
46
|
-
|
47
|
-
template_dir
|
48
|
-
ensure
|
49
|
-
FileUtils.rm_f(temp_path) if temp_path
|
50
|
-
end
|
51
|
-
|
52
|
-
def erb(path)
|
53
|
-
ERB.new(File.read(path))
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'bosh/director/rendered_job_template'
|
2
|
-
|
3
|
-
module Bosh::Director
|
4
|
-
RenderedFileTemplate = Struct.new(:src_name, :dest_name, :contents)
|
5
|
-
class JobTemplateRenderer
|
6
|
-
|
7
|
-
attr_reader :monit_template, :templates
|
8
|
-
|
9
|
-
def initialize(name, monit_template, templates, logger)
|
10
|
-
@name = name
|
11
|
-
@monit_template = monit_template
|
12
|
-
@templates = templates
|
13
|
-
@logger = logger
|
14
|
-
end
|
15
|
-
|
16
|
-
def render(job_name, instance)
|
17
|
-
template_context = Bosh::Common::TemplateEvaluationContext.new(instance.spec)
|
18
|
-
|
19
|
-
monit = render_erb(job_name, monit_template, template_context, instance.index)
|
20
|
-
|
21
|
-
rendered_templates = templates.map do |template_file|
|
22
|
-
file_contents = render_erb(job_name, template_file.erb_file, template_context, instance.index)
|
23
|
-
RenderedFileTemplate.new(template_file.src_name, template_file.dest_name, file_contents)
|
24
|
-
end
|
25
|
-
|
26
|
-
RenderedJobTemplate.new(name, monit, rendered_templates)
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
attr_reader :name, :logger
|
32
|
-
|
33
|
-
def render_erb(job_name, template, template_context, index)
|
34
|
-
template.result(template_context.get_binding)
|
35
|
-
rescue Exception => e
|
36
|
-
logger.debug(e.inspect)
|
37
|
-
job_desc = "#{job_name}/#{index}"
|
38
|
-
line_index = e.backtrace.index { |l| l.include?(template.filename) }
|
39
|
-
line = line_index ? e.backtrace[line_index] : '(unknown):(unknown)'
|
40
|
-
template_name, line = line.split(':')
|
41
|
-
|
42
|
-
message = "Error filling in template `#{File.basename(template_name)}' " +
|
43
|
-
"for `#{job_desc}' (line #{line}: #{e})"
|
44
|
-
|
45
|
-
logger.debug("#{message}\n#{e.backtrace.join("\n")}")
|
46
|
-
|
47
|
-
raise JobTemplateBindingFailed, "#{message}"
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
require 'bosh/director/deployment_plan/rendered_templates_archive'
|
2
|
-
require 'bosh/director/compressed_rendered_job_templates'
|
3
|
-
require 'digest/sha1'
|
4
|
-
require 'tempfile'
|
5
|
-
|
6
|
-
module Bosh::Director
|
7
|
-
class RenderedJobInstance
|
8
|
-
def initialize(job_templates)
|
9
|
-
@job_templates = job_templates
|
10
|
-
end
|
11
|
-
|
12
|
-
def configuration_hash
|
13
|
-
instance_digest = Digest::SHA1.new
|
14
|
-
job_templates.sort { |x, y| x.name <=> y.name }.each do |rendered_job_template|
|
15
|
-
bound_templates = ''
|
16
|
-
bound_templates << rendered_job_template.monit
|
17
|
-
|
18
|
-
rendered_job_template.templates.sort { |x, y| x.src_name <=> y.src_name }.each do |template_file|
|
19
|
-
bound_templates << template_file.contents
|
20
|
-
instance_digest << bound_templates
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
instance_digest.hexdigest
|
25
|
-
end
|
26
|
-
|
27
|
-
def template_hashes
|
28
|
-
job_templates.reduce({}) do |h, rendered_job_template|
|
29
|
-
h.merge(rendered_job_template.name => rendered_job_template.template_hash)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def persist(blobstore)
|
34
|
-
file = Tempfile.new('compressed-rendered-job-templates')
|
35
|
-
|
36
|
-
compressed_archive = CompressedRenderedJobTemplates.new(file.path)
|
37
|
-
compressed_archive.write(job_templates)
|
38
|
-
|
39
|
-
blobstore_id = blobstore.create(compressed_archive.contents)
|
40
|
-
DeploymentPlan::RenderedTemplatesArchive.new(blobstore_id, compressed_archive.sha1)
|
41
|
-
ensure
|
42
|
-
file.close!
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
46
|
-
attr_reader :job_templates
|
47
|
-
end
|
48
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module Bosh::Director
|
2
|
-
class RenderedJobTemplate
|
3
|
-
attr_reader :name, :monit, :templates
|
4
|
-
|
5
|
-
def initialize(name, monit, templates)
|
6
|
-
@name = name
|
7
|
-
@monit = monit
|
8
|
-
@templates = templates
|
9
|
-
end
|
10
|
-
|
11
|
-
def template_hash
|
12
|
-
template_digest = Digest::SHA1.new
|
13
|
-
template_digest << monit
|
14
|
-
templates.sort { |x, y| x.src_name <=> y.src_name }.each do |template_file|
|
15
|
-
template_digest << template_file.contents
|
16
|
-
end
|
17
|
-
|
18
|
-
template_digest.hexdigest
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
|
3
|
-
module Bosh::Director
|
4
|
-
class RenderedTemplatesWriter
|
5
|
-
def write(rendered_templates, output_dir)
|
6
|
-
rendered_templates.each do |job_template|
|
7
|
-
job_template_dir = File.join(output_dir, job_template.name)
|
8
|
-
Dir.mkdir(job_template_dir)
|
9
|
-
|
10
|
-
File.open(File.join(job_template_dir, 'monit'), 'w') do |f|
|
11
|
-
f.write(job_template.monit)
|
12
|
-
end
|
13
|
-
|
14
|
-
job_template.templates.each do |file_template|
|
15
|
-
file_template_dest = File.join(job_template_dir, file_template.dest_name)
|
16
|
-
FileUtils.mkdir_p(File.dirname(file_template_dest))
|
17
|
-
File.open(file_template_dest, 'w') do |f|
|
18
|
-
f.write(file_template.contents)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'tmpdir'
|
2
|
-
require 'open3'
|
3
|
-
|
4
|
-
module Bosh::Director
|
5
|
-
class TarGzipper
|
6
|
-
# @param [String] base_dir the directory from which the tar command is run
|
7
|
-
# @param [String, Array] sources the relative paths to include
|
8
|
-
# @param [String] dest the destination filename for the tgz output
|
9
|
-
# @param [Hash] options the options for compress
|
10
|
-
# @option options [Boolean] :copy_first copy the source to a temp dir before archiving
|
11
|
-
def compress(base_dir, sources, dest, options={})
|
12
|
-
sources = [*sources]
|
13
|
-
|
14
|
-
sources.each do |source|
|
15
|
-
raise "Sources must have a path depth of 1 and contain no '#{File::SEPARATOR}'" if source.include?(File::SEPARATOR)
|
16
|
-
end
|
17
|
-
|
18
|
-
base_dir_path = Pathname.new(base_dir)
|
19
|
-
|
20
|
-
unless base_dir_path.exist?
|
21
|
-
raise "The base directory #{base_dir} could not be found."
|
22
|
-
end
|
23
|
-
|
24
|
-
unless base_dir_path.absolute?
|
25
|
-
raise "The base directory #{base_dir} is not an absolute path."
|
26
|
-
end
|
27
|
-
|
28
|
-
if options[:copy_first]
|
29
|
-
Dir.mktmpdir do |tmpdir|
|
30
|
-
FileUtils.cp_r(sources.map { |s| File.join(base_dir, s) }, "#{tmpdir}/")
|
31
|
-
tar(tmpdir, dest, sources)
|
32
|
-
end
|
33
|
-
else
|
34
|
-
tar(base_dir, dest, sources)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def tar(base_dir, dest, sources)
|
41
|
-
out, err, status = Open3.capture3('tar', '-C', base_dir, '-czf', dest, *sources)
|
42
|
-
raise("tar exited #{status.exitstatus}, output: '#{out}', error: '#{err}'") unless status.success?
|
43
|
-
out
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|