Class: Bosh::Director::Jobs::DeleteOrphanDisks

Inherits:
BaseJob show all
Defined in:
lib/bosh/director/jobs/delete_orphan_disks.rb

Instance Attribute Summary

Attributes inherited from BaseJob

#task_id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseJob

#begin_stage, #dns_manager, #event_manager, #logger, perform, #result_file, schedule_message, #single_step_stage, #task_cancelled?, #task_checkpoint, #track_and_log, #username

Constructor Details

#initialize(orphan_disk_cids) ⇒ DeleteOrphanDisks

Returns a new instance of DeleteOrphanDisks.



22
23
24
25
# File 'lib/bosh/director/jobs/delete_orphan_disks.rb', line 22

def initialize(orphan_disk_cids)
  @orphan_disk_cids = orphan_disk_cids
  @disk_manager = Bosh::Director::DiskManager.new(Config.cloud, Config.logger)
end

Class Method Details

.enqueue(username, orphan_disk_cids, job_queue) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/bosh/director/jobs/delete_orphan_disks.rb', line 11

def self.enqueue(username, orphan_disk_cids, job_queue)
  persistent_disk_cids = orphan_disk_cids.select do |disk_cid|
    Bosh::Director::Models::PersistentDisk.where(disk_cid: disk_cid).any?
  end
  if persistent_disk_cids.any?
    raise DeletingPersistentDiskError, "Deleting persistent disk is not supported: #{persistent_disk_cids}"
  end

  job_queue.enqueue(username, Jobs::DeleteOrphanDisks, 'delete orphan disks', [orphan_disk_cids])
end

.job_typeObject



7
8
9
# File 'lib/bosh/director/jobs/delete_orphan_disks.rb', line 7

def self.job_type
  :delete_orphan_disks
end

Instance Method Details

#performObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/bosh/director/jobs/delete_orphan_disks.rb', line 27

def perform
  event_log_stage = Config.event_log.begin_stage('Deleting orphaned disks', @orphan_disk_cids.count)

  ThreadPool.new(:max_threads => Config.max_threads).wrap do |pool|
    @orphan_disk_cids.each do |orphan_disk_cid|
      pool.process do
        event_log_stage.advance_and_track("Deleting orphaned disk #{orphan_disk_cid}") do
          @disk_manager.delete_orphan_disk_by_disk_cid(orphan_disk_cid)
        end
      end
    end
  end

  "orphaned disk(s) #{@orphan_disk_cids.join(', ')} deleted"
end