Class: Bosh::Director::Jobs::Helpers::ReleaseDeleter

Inherits:
Object
  • Object
show all
Defined in:
lib/bosh/director/jobs/helpers/release_deleter.rb

Instance Method Summary collapse

Constructor Details

#initialize(package_deleter, template_deleter, event_log, logger) ⇒ ReleaseDeleter

Returns a new instance of ReleaseDeleter.



5
6
7
8
9
10
# File 'lib/bosh/director/jobs/helpers/release_deleter.rb', line 5

def initialize(package_deleter, template_deleter, event_log, logger)
  @package_deleter = package_deleter
  @template_deleter = template_deleter
  @event_log = event_log
  @logger = logger
end

Instance Method Details

#delete(release, force) ⇒ Object



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
40
# File 'lib/bosh/director/jobs/helpers/release_deleter.rb', line 12

def delete(release, force)
  errors = []

  stage = @event_log.begin_stage('Deleting packages', release.packages.count)
  release.packages.each do |package|
    track_and_log(stage, "#{package.name}/#{package.version}") do
      errors += @package_deleter.delete(package, force)
    end
  end

  stage = @event_log.begin_stage('Deleting jobs', release.templates.count)
  release.templates.each do |template|
    track_and_log(stage, "#{template.name}/#{template.version}") do
      errors += @template_deleter.delete(template, force)
    end
  end

  if errors.empty? || force
    stage = @event_log.begin_stage('Deleting release versions', release.versions.count)
    release.versions.each do |release_version|
      track_and_log(stage, "#{release.name}/#{release_version.version}") do
        release_version.destroy
      end
    end
    release.destroy
  end

  errors
end