Class: Bosh::Director::CompiledReleaseDownloader

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

Instance Method Summary collapse

Constructor Details

#initialize(compiled_packages_group, templates, blobstore_client) ⇒ CompiledReleaseDownloader

Returns a new instance of CompiledReleaseDownloader.



7
8
9
10
11
# File 'lib/bosh/director/compiled_release_downloader.rb', line 7

def initialize(compiled_packages_group, templates, blobstore_client)
  @compiled_packages_group = compiled_packages_group
  @templates = templates
  @blobstore_client = blobstore_client
end

Instance Method Details

#cleanupObject



49
50
51
# File 'lib/bosh/director/compiled_release_downloader.rb', line 49

def cleanup
  FileUtils.rm_rf(@download_dir)
end

#downloadObject



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
40
41
42
43
44
45
46
47
# File 'lib/bosh/director/compiled_release_downloader.rb', line 13

def download
  @download_dir = Dir.mktmpdir

  path = File.join(@download_dir, 'compiled_packages')
  FileUtils.mkpath(path)

  compiled_packages = @compiled_packages_group.compiled_packages
  event_log_stage = event_log.begin_stage("copying packages", compiled_packages.count)

  compiled_packages.each do |compiled_package|
    desc = "#{compiled_package.package.name}/#{compiled_package.package.version}"
    event_log_stage.advance_and_track(desc) do
      blobstore_id = compiled_package.blobstore_id
      File.open(File.join(path, "#{compiled_package.package.name}.tgz"), 'w') do |f|
        @blobstore_client.get(blobstore_id, f, sha1: compiled_package.sha1)
      end
    end
  end

  path = File.join(@download_dir, 'jobs')
  FileUtils.mkpath(path)

  event_log_stage = event_log.begin_stage("copying jobs", @templates.count)
  @templates.each do |template|
    desc = "#{template.name}/#{template.version}"
    event_log_stage.advance_and_track(desc) do
      blobstore_id = template.blobstore_id
      File.open(File.join(path, "#{template.name}.tgz"), 'w') do |f|
        @blobstore_client.get(blobstore_id, f, sha1: template.sha1)
      end
    end
  end

  @download_dir
end

#event_logObject



53
54
55
# File 'lib/bosh/director/compiled_release_downloader.rb', line 53

def event_log
  @event_log ||= Config.event_log
end