Class: Bosh::Director::CompiledPackage::CompiledPackageInserter

Inherits:
Object
  • Object
show all
Defined in:
lib/bosh/director/compiled_package/compiled_package_inserter.rb

Instance Method Summary collapse

Constructor Details

#initialize(blobstore_client) ⇒ CompiledPackageInserter

Returns a new instance of CompiledPackageInserter.



5
6
7
# File 'lib/bosh/director/compiled_package/compiled_package_inserter.rb', line 5

def initialize(blobstore_client)
  @blobstore_client = blobstore_client
end

Instance Method Details

#insert(compiled_package, release_version) ⇒ Object

Raises:

  • (ArgumentError)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/bosh/director/compiled_package/compiled_package_inserter.rb', line 9

def insert(compiled_package, release_version)
  package = Bosh::Director::Models::Package[fingerprint: compiled_package.package_fingerprint]
  stemcell = Bosh::Director::Models::Stemcell[sha1: compiled_package.stemcell_sha1]

  raise ArgumentError, [compiled_package.inspect, release_version.inspect].inspect unless package

  unless Bosh::Director::Models::CompiledPackage[
    package: package,
    stemcell: stemcell,
    dependency_key: release_version.package_dependency_key(package.name),
  ]

    oid = File.open(compiled_package.blob_path) do |f|
      @blobstore_client.create(f)
    end

    begin
      Bosh::Director::Models::CompiledPackage.create(
        blobstore_id: oid,
        package: package,
        stemcell: stemcell,
        sha1: compiled_package.sha1,
        dependency_key: release_version.package_dependency_key(package.name),
        build: Bosh::Director::Models::CompiledPackage.generate_build_number(package, stemcell),
      )
    rescue
      @blobstore_client.delete(oid)
      raise
    end
  end
end