bosh-director 1.5.0.pre.1284 → 1.5.0.pre.1302
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/bosh/director/api/controllers/compiled_packages_controller.rb +16 -0
- data/lib/bosh/director/compiled_package/blob_sha_mismatch_error.rb +6 -0
- data/lib/bosh/director/compiled_package/compiled_package.rb +33 -0
- data/lib/bosh/director/compiled_package/compiled_package_inserter.rb +22 -0
- data/lib/bosh/director/compiled_package/compiled_packages_export.rb +37 -0
- data/lib/bosh/director/compiled_package.rb +4 -0
- data/lib/bosh/director/compiled_package_group.rb +2 -0
- data/lib/bosh/director/compiled_package_manifest.rb +4 -0
- data/lib/bosh/director/jobs/import_compiled_packages.rb +59 -0
- data/lib/bosh/director/version.rb +1 -1
- metadata +23 -17
@@ -1,9 +1,11 @@
|
|
1
1
|
require 'json'
|
2
|
+
require 'tempfile'
|
2
3
|
require 'bosh/director/api/controllers/base_controller'
|
3
4
|
require 'bosh/director/api/stemcell_manager'
|
4
5
|
require 'bosh/director/compiled_package_group'
|
5
6
|
require 'bosh/director/compiled_packages_exporter'
|
6
7
|
require 'bosh/director/stale_file_killer'
|
8
|
+
require 'bosh/director/jobs/import_compiled_packages'
|
7
9
|
|
8
10
|
module Bosh::Director
|
9
11
|
module Api::Controllers
|
@@ -28,6 +30,20 @@ module Bosh::Director
|
|
28
30
|
send_file(output_path, type: :tgz)
|
29
31
|
end
|
30
32
|
|
33
|
+
post '/compiled_package_groups/import', consumes: [:tgz] do
|
34
|
+
tempdir = Dir.mktmpdir
|
35
|
+
export_path = File.join(tempdir, 'compiled_packages_export.tgz')
|
36
|
+
# the job is responsible for cleaning this up
|
37
|
+
File.open(export_path, 'w') do |f|
|
38
|
+
while buf = request.body.read(4096)
|
39
|
+
f.write(buf)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
task = JobQueue.new.enqueue(@user, Jobs::ImportCompiledPackages, 'import compiled packages', [tempdir])
|
44
|
+
redirect "/tasks/#{task.id}"
|
45
|
+
end
|
46
|
+
|
31
47
|
def find_stemcell_by_name_and_version
|
32
48
|
stemcell_manager = Api::StemcellManager.new
|
33
49
|
stemcell_manager.find_by_name_and_version(
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'digest/sha1'
|
2
|
+
|
3
|
+
require 'bosh/director/compiled_package'
|
4
|
+
require 'bosh/director/compiled_package/blob_sha_mismatch_error'
|
5
|
+
|
6
|
+
module Bosh::Director::CompiledPackage
|
7
|
+
|
8
|
+
class CompiledPackage
|
9
|
+
attr_reader :package_name, :package_fingerprint, :sha1, :stemcell_sha1, :blobstore_id, :blob_path
|
10
|
+
|
11
|
+
def initialize(options = {})
|
12
|
+
@package_name = options.fetch(:package_name)
|
13
|
+
@package_fingerprint = options.fetch(:package_fingerprint)
|
14
|
+
@sha1 = options.fetch(:sha1)
|
15
|
+
@stemcell_sha1 = options.fetch(:stemcell_sha1)
|
16
|
+
@blobstore_id = options.fetch(:blobstore_id)
|
17
|
+
@blob_path = options.fetch(:blob_path)
|
18
|
+
end
|
19
|
+
|
20
|
+
def check_blob_sha
|
21
|
+
if sha1 != actual_sha
|
22
|
+
raise BlobShaMismatchError, "Blob SHA mismatch in file #{blob_path}: expected: #{sha1}, got #{actual_sha}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def actual_sha
|
29
|
+
@actual_sha ||= Digest::SHA1.file(blob_path).hexdigest
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'bosh/director/compiled_package'
|
2
|
+
|
3
|
+
module Bosh::Director::CompiledPackage
|
4
|
+
|
5
|
+
class CompiledPackageInserter
|
6
|
+
|
7
|
+
def insert(compiled_package, release_version)
|
8
|
+
package = Bosh::Director::Models::Package[fingerprint: compiled_package.package_fingerprint]
|
9
|
+
stemcell = Bosh::Director::Models::Stemcell[sha1: compiled_package.stemcell_sha1]
|
10
|
+
|
11
|
+
Bosh::Director::Models::CompiledPackage.create(
|
12
|
+
blobstore_id: compiled_package.blobstore_id,
|
13
|
+
package_id: package.id,
|
14
|
+
stemcell_id: stemcell.id,
|
15
|
+
sha1: compiled_package.sha1,
|
16
|
+
dependency_key: release_version.package_dependency_key(package.name),
|
17
|
+
build: Bosh::Director::Models::CompiledPackage.generate_build_number(package, stemcell),
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'bosh/director/compiled_package'
|
2
|
+
require 'bosh/director/compiled_package/compiled_package'
|
3
|
+
|
4
|
+
module Bosh::Director::CompiledPackage
|
5
|
+
class CompiledPackagesExport
|
6
|
+
|
7
|
+
def initialize(options={})
|
8
|
+
@file = options.fetch(:file)
|
9
|
+
@exec = options.fetch(:exec, Bosh::Exec)
|
10
|
+
end
|
11
|
+
|
12
|
+
def extract(tempdir=nil)
|
13
|
+
tempdir ||= Dir.mktmpdir
|
14
|
+
exec.sh("tar -C #{tempdir} -xf #{file}")
|
15
|
+
manifest = YAML.load_file("#{tempdir}/compiled_packages.MF")
|
16
|
+
packages = []
|
17
|
+
manifest['compiled_packages'].each do |p|
|
18
|
+
packages << CompiledPackage.new(
|
19
|
+
package_name: p['package_name'],
|
20
|
+
package_fingerprint: p['package_fingerprint'],
|
21
|
+
sha1: p['compiled_package_sha1'],
|
22
|
+
stemcell_sha1: p['stemcell_sha1'],
|
23
|
+
blobstore_id: p['blobstore_id'],
|
24
|
+
blob_path: File.join(tempdir, 'compiled_packages', 'blobs', p['blobstore_id']))
|
25
|
+
end
|
26
|
+
|
27
|
+
yield manifest, packages
|
28
|
+
|
29
|
+
FileUtils.rm_rf(tempdir)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
attr_reader :file, :exec
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -9,10 +9,14 @@ module Bosh::Director
|
|
9
9
|
|
10
10
|
def to_h
|
11
11
|
{
|
12
|
+
'release_name' => @compiled_package_group.release_version.release.name,
|
13
|
+
'release_version' => @compiled_package_group.release_version.version,
|
14
|
+
'release_commit_hash' => @compiled_package_group.release_version.commit_hash,
|
12
15
|
'compiled_packages' => @compiled_package_group.compiled_packages.map do |compiled_package|
|
13
16
|
{
|
14
17
|
'package_name' => compiled_package.package.name,
|
15
18
|
'package_fingerprint' => compiled_package.package.fingerprint,
|
19
|
+
'compiled_package_sha1' => compiled_package.sha1,
|
16
20
|
'stemcell_sha1' => @compiled_package_group.stemcell_sha1,
|
17
21
|
'blobstore_id' => compiled_package.blobstore_id,
|
18
22
|
}
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'bosh/director/compiled_package/compiled_packages_export'
|
2
|
+
require 'bosh/director/compiled_package/compiled_package_inserter'
|
3
|
+
|
4
|
+
module Bosh::Director
|
5
|
+
module Jobs
|
6
|
+
class ImportCompiledPackages < BaseJob
|
7
|
+
@queue = :normal
|
8
|
+
|
9
|
+
def self.job_type
|
10
|
+
:import_compiled_packages
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(export_dir, options={})
|
14
|
+
@export_dir = export_dir
|
15
|
+
|
16
|
+
@blobstore_client = options.fetch(:blobstore_client) { Bosh::Director::App.instance.blobstores.blobstore }
|
17
|
+
end
|
18
|
+
|
19
|
+
def perform
|
20
|
+
export = Bosh::Director::CompiledPackage::CompiledPackagesExport.new(file: export_path)
|
21
|
+
|
22
|
+
export.extract do |manifest, packages|
|
23
|
+
packages.each { |p| p.check_blob_sha }
|
24
|
+
|
25
|
+
packages.each do |package|
|
26
|
+
File.open(package.blob_path) do |f|
|
27
|
+
blobstore_client.create(f, package.blobstore_id)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
release_name = manifest.fetch('release_name')
|
32
|
+
release_version = manifest.fetch('release_version')
|
33
|
+
|
34
|
+
release = Bosh::Director::Models::Release[name: release_name]
|
35
|
+
release_version = Bosh::Director::Models::ReleaseVersion[release_id: release.id, version: release_version]
|
36
|
+
|
37
|
+
inserter = Bosh::Director::CompiledPackage::CompiledPackageInserter.new
|
38
|
+
|
39
|
+
Bosh::Director::Config.db.transaction do
|
40
|
+
packages.each do |package|
|
41
|
+
inserter.insert(package, release_version)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
ensure
|
46
|
+
FileUtils.rm_rf(@export_dir)
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def export_path
|
52
|
+
File.join(@export_dir, 'compiled_packages_export.tgz')
|
53
|
+
end
|
54
|
+
|
55
|
+
attr_reader :blobstore_client
|
56
|
+
attr_reader :export_dir
|
57
|
+
end
|
58
|
+
end
|
59
|
+
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.1302
|
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-
|
12
|
+
date: 2013-11-11 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.
|
37
|
+
version: 1.5.0.pre.1302
|
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.1302
|
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.1302
|
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.1302
|
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.1302
|
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.1302
|
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.1302
|
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.1302
|
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.1302
|
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.1302
|
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.1302
|
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.1302
|
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.1302
|
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.1302
|
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
|
+
64af4e'
|
449
449
|
email: support@cloudfoundry.com
|
450
450
|
executables:
|
451
451
|
- bosh-director
|
@@ -525,6 +525,11 @@ files:
|
|
525
525
|
- lib/bosh/director/blobstores.rb
|
526
526
|
- lib/bosh/director/cloudcheck_helper.rb
|
527
527
|
- lib/bosh/director/compile_task.rb
|
528
|
+
- lib/bosh/director/compiled_package.rb
|
529
|
+
- lib/bosh/director/compiled_package/blob_sha_mismatch_error.rb
|
530
|
+
- lib/bosh/director/compiled_package/compiled_package.rb
|
531
|
+
- lib/bosh/director/compiled_package/compiled_package_inserter.rb
|
532
|
+
- lib/bosh/director/compiled_package/compiled_packages_export.rb
|
528
533
|
- lib/bosh/director/compiled_package_downloader.rb
|
529
534
|
- lib/bosh/director/compiled_package_group.rb
|
530
535
|
- lib/bosh/director/compiled_package_manifest.rb
|
@@ -586,6 +591,7 @@ files:
|
|
586
591
|
- lib/bosh/director/jobs/delete_snapshots.rb
|
587
592
|
- lib/bosh/director/jobs/delete_stemcell.rb
|
588
593
|
- lib/bosh/director/jobs/fetch_logs.rb
|
594
|
+
- lib/bosh/director/jobs/import_compiled_packages.rb
|
589
595
|
- lib/bosh/director/jobs/scheduled_backup.rb
|
590
596
|
- lib/bosh/director/jobs/snapshot_deployment.rb
|
591
597
|
- lib/bosh/director/jobs/snapshot_deployments.rb
|