bosh-director 1.5.0.pre.1391 → 1.5.0.pre.1435

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ Sequel.migration do
2
+ change do
3
+ drop_table(:rendered_templates_archives)
4
+
5
+ create_table(:rendered_templates_archives) do
6
+ primary_key :id
7
+ foreign_key :instance_id, :instances, null: false
8
+
9
+ String :blobstore_id, null: false
10
+ String :sha1, null: false
11
+ String :content_sha1, null: false
12
+ Time :created_at, null: false
13
+
14
+ index :created_at
15
+ end
16
+ end
17
+ end
@@ -1,10 +1,28 @@
1
+ require 'tmpdir'
2
+ require 'digest/sha1'
3
+
1
4
  module Bosh::Director
2
5
  class CompressedRenderedJobTemplates
3
- def initialize(rendered_job_templates)
6
+ def initialize(path)
7
+ @path = path
8
+ end
9
+
10
+ def write(rendered_templates)
11
+ Dir.mktmpdir do |dir|
12
+ writer = RenderedTemplatesWriter.new
13
+ writer.write(rendered_templates, dir)
14
+
15
+ tar_gzipper = TarGzipper.new
16
+ tar_gzipper.compress(dir, %w(.), @path)
17
+ end
4
18
  end
5
19
 
6
20
  def contents
7
- 'contents of fake-compressed-job-templates.tgz'
21
+ File.open(@path, 'r')
22
+ end
23
+
24
+ def sha1
25
+ Digest::SHA1.file(@path).hexdigest
8
26
  end
9
27
  end
10
28
  end
@@ -1,5 +1,3 @@
1
- # Copyright (c) 2009-2012 VMware, Inc.
2
-
3
1
  module Bosh::Director
4
2
  # DeploymentPlan::Assembler is used to populate deployment plan with information
5
3
  # about existing deployment and information from director DB
@@ -15,6 +13,7 @@ module Bosh::Director
15
13
  @logger = Config.logger
16
14
  @event_log = Config.event_log
17
15
  @stemcell_manager = Api::StemcellManager.new
16
+ @blobstore = App.instance.blobstores.blobstore
18
17
  end
19
18
 
20
19
  # Binds deployment DB record to a plan
@@ -322,7 +321,7 @@ module Bosh::Director
322
321
  # @return [void]
323
322
  def bind_configuration
324
323
  @deployment_plan.jobs.each do |job|
325
- JobRenderer.new(job).render_job_instances
324
+ JobRenderer.new(job).render_job_instances(@blobstore)
326
325
  end
327
326
  end
328
327
 
@@ -425,8 +424,7 @@ module Bosh::Director
425
424
  unneeded_instances = @deployment_plan.unneeded_instances
426
425
  return if unneeded_instances.empty?
427
426
 
428
- @event_log.begin_stage("Deleting unneeded instances",
429
- unneeded_instances.size)
427
+ @event_log.begin_stage("Deleting unneeded instances", unneeded_instances.size)
430
428
  InstanceDeleter.new(@deployment_plan).delete_instances(unneeded_instances)
431
429
  @logger.info("Deleted no longer needed instances")
432
430
  end
@@ -1,5 +1,3 @@
1
- # Copyright (c) 2009-2012 VMware, Inc.
2
-
3
1
  module Bosh::Director
4
2
  # Coordinates the safe deletion of an instance and all associates resources.
5
3
  class InstanceDeleter
@@ -10,6 +8,7 @@ module Bosh::Director
10
8
  @cloud = Config.cloud
11
9
  @logger = Config.logger
12
10
  @event_log = Config.event_log
11
+ @blobstore = App.instance.blobstores.blobstore
13
12
  end
14
13
 
15
14
  # Deletes a list of instances
@@ -39,6 +38,8 @@ module Bosh::Director
39
38
  delete_persistent_disks(instance.persistent_disks)
40
39
  delete_dns(instance.job, instance.index)
41
40
 
41
+ RenderedJobTemplatesCleaner.new(instance, @blobstore).clean_all
42
+
42
43
  vm.db.transaction do
43
44
  instance.destroy
44
45
  vm.destroy
@@ -1,4 +1,5 @@
1
1
  require 'bosh/director/instance_preparer'
2
+ require 'bosh/director/rendered_job_templates_cleaner'
2
3
 
3
4
  module Bosh::Director
4
5
  class InstanceUpdater
@@ -15,6 +16,7 @@ module Bosh::Director
15
16
  @cloud = Config.cloud
16
17
  @logger = Config.logger
17
18
  @ticker = event_ticker
19
+ @blobstore = App.instance.blobstores.blobstore
18
20
 
19
21
  @instance = instance
20
22
  @job = instance.job
@@ -78,6 +80,8 @@ module Bosh::Director
78
80
 
79
81
  step { apply_state(@instance.spec) }
80
82
 
83
+ RenderedJobTemplatesCleaner.new(@instance.model, @blobstore).clean
84
+
81
85
  start! if need_start?
82
86
 
83
87
  step { wait_until_running }
@@ -1,6 +1,5 @@
1
1
  module Bosh::Director
2
2
  class JobInstanceRenderer
3
-
4
3
  def initialize(job, job_template_loader)
5
4
  @job = job
6
5
  @job_template_loader = job_template_loader
@@ -1,7 +1,7 @@
1
1
  require 'bosh/director/job_template_loader'
2
2
  require 'bosh/director/job_instance_renderer'
3
3
  require 'bosh/director/rendered_job_instance_hasher'
4
- require 'bosh/director/rendered_templates_uploader'
4
+ require 'bosh/director/rendered_job_templates_persister'
5
5
 
6
6
  module Bosh::Director
7
7
  class JobRenderer
@@ -12,16 +12,16 @@ module Bosh::Director
12
12
  @instance_renderer = JobInstanceRenderer.new(@job, job_template_loader)
13
13
  end
14
14
 
15
- def render_job_instances
15
+ def render_job_instances(blobstore)
16
16
  @job.instances.each do |instance|
17
17
  rendered_templates = @instance_renderer.render(instance)
18
18
 
19
- uploader = RenderedTemplatesUploader.new
20
- uploader.upload(rendered_templates)
21
-
22
19
  hasher = RenderedJobInstanceHasher.new(rendered_templates)
23
20
  instance.configuration_hash = hasher.configuration_hash
24
21
  instance.template_hashes = hasher.template_hashes
22
+
23
+ persister = RenderedJobTemplatesPersister.new(blobstore)
24
+ persister.persist(instance, rendered_templates)
25
25
  end
26
26
  end
27
27
  end
@@ -1,9 +1,5 @@
1
- # Copyright (c) 2009-2012 VMware, Inc.
2
-
3
1
  module Bosh::Director
4
-
5
2
  class JobUpdater
6
-
7
3
  # @param [Bosh::Director::DeploymentPlan] deployment_plan
8
4
  # @param [DeploymentPlan::Job] job
9
5
  def initialize(deployment_plan, job)
@@ -20,11 +16,9 @@ module Bosh::Director
20
16
 
21
17
  return if unneeded_instances.empty?
22
18
 
23
- @event_log.begin_stage("Deleting unneeded instances",
24
- unneeded_instances.size, [@job.name])
25
- InstanceDeleter.new(@deployment_plan).
26
- delete_instances(unneeded_instances,
27
- :max_threads => @job.update.max_in_flight)
19
+ @event_log.begin_stage("Deleting unneeded instances", unneeded_instances.size, [@job.name])
20
+ deleter = InstanceDeleter.new(@deployment_plan)
21
+ deleter.delete_instances(unneeded_instances, max_threads: @job.update.max_in_flight)
28
22
 
29
23
  @logger.info("Deleted no longer needed instances")
30
24
  end
@@ -1,5 +1,3 @@
1
- # Copyright (c) 2009-2012 VMware, Inc.
2
-
3
1
  module Bosh::Director
4
2
  module Jobs
5
3
  class DeleteDeployment < BaseJob
@@ -18,6 +16,7 @@ module Bosh::Director
18
16
  @keep_snapshots = options["keep_snapshots"]
19
17
  @cloud = Config.cloud
20
18
  @deployment_manager = Api::DeploymentManager.new
19
+ @blobstore = App.instance.blobstores.blobstore
21
20
  end
22
21
 
23
22
  def perform
@@ -144,6 +143,10 @@ module Bosh::Director
144
143
  disk.destroy
145
144
  end
146
145
 
146
+ ignoring_errors_when_forced do
147
+ RenderedJobTemplatesCleaner.new(instance, @blobstore).clean_all
148
+ end
149
+
147
150
  instance.destroy
148
151
 
149
152
  delete_vm(vm) if vm
@@ -160,7 +163,6 @@ module Bosh::Director
160
163
  @cloud.delete_vm(vm.cid)
161
164
  end
162
165
  end
163
-
164
166
  vm.destroy
165
167
  end
166
168
 
@@ -18,6 +18,7 @@ require 'bosh/director/models/user'
18
18
  require 'bosh/director/models/vm'
19
19
  require 'bosh/director/models/persistent_disk'
20
20
  require 'bosh/director/models/director_attribute'
21
+ require 'bosh/director/models/rendered_templates_archive'
21
22
 
22
23
  module Bosh::Director
23
24
  module Models
@@ -1,5 +1,3 @@
1
- # Copyright (c) 2009-2012 VMware, Inc.
2
-
3
1
  module Bosh::Director::Models
4
2
  class Instance < Sequel::Model(Bosh::Director::Config.db)
5
3
  many_to_one :deployment
@@ -25,5 +23,18 @@ module Bosh::Director::Models
25
23
  return disk.disk_cid if disk
26
24
  nil
27
25
  end
26
+
27
+ def latest_rendered_templates_archive
28
+ rendered_templates_archives_dataset.order(:created_at).last
29
+ end
30
+
31
+ def stale_rendered_templates_archives
32
+ stale_archives = rendered_templates_archives_dataset
33
+ if latest = latest_rendered_templates_archive
34
+ stale_archives.exclude(id: latest.id)
35
+ else
36
+ stale_archives
37
+ end
38
+ end
28
39
  end
29
40
  end
@@ -0,0 +1,22 @@
1
+ module Bosh::Director
2
+ class RenderedJobTemplatesCleaner
3
+ def initialize(instance_model, blobstore)
4
+ @instance_model = instance_model
5
+ @blobstore = blobstore
6
+ end
7
+
8
+ def clean
9
+ @instance_model.stale_rendered_templates_archives.each do |archive|
10
+ @blobstore.delete(archive.blobstore_id)
11
+ archive.delete
12
+ end
13
+ end
14
+
15
+ def clean_all
16
+ @instance_model.rendered_templates_archives.each do |archive|
17
+ @blobstore.delete(archive.blobstore_id)
18
+ archive.delete
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,36 @@
1
+ require 'tempfile'
2
+ require 'bosh/director/rendered_templates_writer'
3
+ require 'bosh/director/compressed_rendered_job_templates'
4
+
5
+ module Bosh::Director
6
+ class RenderedJobTemplatesPersister
7
+ def initialize(blobstore)
8
+ @blobstore = blobstore
9
+ end
10
+
11
+ def persist(instance, rendered_job_templates)
12
+ current_archive = instance.model.latest_rendered_templates_archive
13
+ if !current_archive || current_archive.content_sha1 != instance.configuration_hash
14
+ persist_without_checking(instance, rendered_job_templates)
15
+ end
16
+ end
17
+
18
+ def persist_without_checking(instance, rendered_job_templates)
19
+ file = Tempfile.new('compressed-rendered-job-templates')
20
+
21
+ compressed_archive = CompressedRenderedJobTemplates.new(file.path)
22
+ compressed_archive.write(rendered_job_templates)
23
+
24
+ blobstore_id = @blobstore.create(compressed_archive.contents)
25
+
26
+ instance.model.add_rendered_templates_archive(
27
+ blobstore_id: blobstore_id,
28
+ sha1: compressed_archive.sha1,
29
+ content_sha1: instance.configuration_hash,
30
+ created_at: Time.now,
31
+ )
32
+ ensure
33
+ file.close!
34
+ end
35
+ end
36
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Bosh
4
4
  module Director
5
- VERSION = '1.5.0.pre.1391'
5
+ VERSION = '1.5.0.pre.1435'
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.1391
4
+ version: 1.5.0.pre.1435
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-22 00:00:00.000000000 Z
12
+ date: 2013-11-27 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.1391
37
+ version: 1.5.0.pre.1435
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.1391
45
+ version: 1.5.0.pre.1435
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.1391
53
+ version: 1.5.0.pre.1435
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.1391
61
+ version: 1.5.0.pre.1435
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.1391
69
+ version: 1.5.0.pre.1435
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.1391
77
+ version: 1.5.0.pre.1435
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.1391
85
+ version: 1.5.0.pre.1435
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.1391
93
+ version: 1.5.0.pre.1435
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.1391
101
+ version: 1.5.0.pre.1435
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.1391
109
+ version: 1.5.0.pre.1435
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.1391
117
+ version: 1.5.0.pre.1435
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.1391
125
+ version: 1.5.0.pre.1435
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.1391
133
+ version: 1.5.0.pre.1435
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.1391
141
+ version: 1.5.0.pre.1435
142
142
  - !ruby/object:Gem::Dependency
143
143
  name: eventmachine
144
144
  requirement: !ruby/object:Gem::Requirement
@@ -461,7 +461,7 @@ dependencies:
461
461
  version: '0'
462
462
  description: ! 'BOSH Director
463
463
 
464
- a7d75a'
464
+ 496235'
465
465
  email: support@cloudfoundry.com
466
466
  executables:
467
467
  - bosh-director
@@ -500,6 +500,7 @@ files:
500
500
  - db/migrations/director/20130530164918_add_paused_flag_to_instance.rb
501
501
  - db/migrations/director/20130531172604_add_director_attributes.rb
502
502
  - db/migrations/director/20131121182231_add_rendered_templates_archives.rb
503
+ - db/migrations/director/20131125232201_rename_rendered_templates_archives_blob_id_and_checksum_columns.rb
503
504
  - db/migrations/dns/20120123234908_initial.rb
504
505
  - lib/bosh/director.rb
505
506
  - lib/bosh/director/agent_client.rb
@@ -663,7 +664,8 @@ files:
663
664
  - lib/bosh/director/problem_scanner.rb
664
665
  - lib/bosh/director/rendered_job_instance_hasher.rb
665
666
  - lib/bosh/director/rendered_job_template.rb
666
- - lib/bosh/director/rendered_templates_uploader.rb
667
+ - lib/bosh/director/rendered_job_templates_cleaner.rb
668
+ - lib/bosh/director/rendered_job_templates_persister.rb
667
669
  - lib/bosh/director/rendered_templates_writer.rb
668
670
  - lib/bosh/director/resource_pool_updater.rb
669
671
  - lib/bosh/director/scheduler.rb
@@ -1,16 +0,0 @@
1
- require 'bosh/director/rendered_templates_writer'
2
- require 'bosh/director/compressed_rendered_job_templates'
3
- require 'blobstore_client/null_blobstore_client'
4
-
5
- module Bosh::Director
6
- class RenderedTemplatesUploader
7
- def initialize(blobstore = Bosh::Blobstore::NullBlobstoreClient.new)
8
- @blobstore = blobstore
9
- end
10
-
11
- def upload(rendered_job_templates)
12
- compressed_archive = CompressedRenderedJobTemplates.new(rendered_job_templates)
13
- @blobstore.create(compressed_archive.contents)
14
- end
15
- end
16
- end