Class: Bosh::Director::BlobUtil
- Defined in:
- lib/bosh/director/blob_util.rb
Class Method Summary collapse
- .copy_blob(blobstore_id) ⇒ Object
-
.create_blob(path) ⇒ String
Created blob id.
- .exists_in_global_cache?(package, cache_key) ⇒ Boolean
- .fetch_from_global_cache(package, stemcell, cache_key, dependency_key) ⇒ Object
- .save_to_global_cache(compiled_package, cache_key) ⇒ Object
Class Method Details
.copy_blob(blobstore_id) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/bosh/director/blob_util.rb', line 11 def self.copy_blob(blobstore_id) # Create a copy of the given blob Dir.mktmpdir do |path| temp_path = File.join(path, "blob") File.open(temp_path, 'w') do |file| blobstore.get(blobstore_id, file) end File.open(temp_path, 'r') do |file| blobstore_id = blobstore.create(file) end end blobstore_id end |
.create_blob(path) ⇒ String
Returns Created blob id.
7 8 9 |
# File 'lib/bosh/director/blob_util.rb', line 7 def self.create_blob(path) File.open(path) { |f| blobstore.create(f) } end |
.exists_in_global_cache?(package, cache_key) ⇒ Boolean
39 40 41 42 |
# File 'lib/bosh/director/blob_util.rb', line 39 def self.exists_in_global_cache?(package, cache_key) global_cache_filename = [package.name, cache_key].join('-') compiled_package_cache_blobstore.exists?(global_cache_filename) end |
.fetch_from_global_cache(package, stemcell, cache_key, dependency_key) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/bosh/director/blob_util.rb', line 44 def self.fetch_from_global_cache(package, stemcell, cache_key, dependency_key) global_cache_filename = [package.name, cache_key].join('-') blobstore_id = nil compiled_package_sha1 = nil Dir.mktmpdir do |path| blob_path = File.join(path, 'blob') begin File.open(blob_path, 'wb') do |file| compiled_package_cache_blobstore.get(global_cache_filename, file) end rescue Bosh::Blobstore::NotFound => e # if the object is not found in the cache, we ignore it and return nil return nil end File.open(blob_path) do |file| blobstore_id = blobstore.create(file) compiled_package_sha1 = Digest::SHA1.file(blob_path).hexdigest end end Models::CompiledPackage.create do |p| p.package = package p.stemcell = stemcell p.sha1 = compiled_package_sha1 p.build = Models::CompiledPackage.generate_build_number(package, stemcell) p.blobstore_id = blobstore_id p.dependency_key = dependency_key end end |
.save_to_global_cache(compiled_package, cache_key) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/bosh/director/blob_util.rb', line 25 def self.save_to_global_cache(compiled_package, cache_key) global_cache_filename = [compiled_package.package.name, cache_key].join('-') Dir.mktmpdir do |path| temp_path = File.join(path, 'blob') File.open(temp_path, 'wb') do |file| blobstore.get(compiled_package.blobstore_id, file) end File.open(temp_path) do |file| compiled_package_cache_blobstore.create(file, global_cache_filename) end end end |