Class: Bosh::Director::Jobs::CloudCheck::ScanAndFix

Inherits:
BaseJob show all
Includes:
LockHelper
Defined in:
lib/bosh/director/jobs/cloud_check/scan_and_fix.rb

Instance Attribute Summary collapse

Attributes inherited from BaseJob

#task_id

Class Method Summary collapse

Instance Method Summary collapse

Methods included from LockHelper

#with_compile_lock, #with_deployment_lock, #with_release_lock, #with_release_locks, #with_stemcell_lock

Methods inherited from BaseJob

#begin_stage, #event_log, #logger, perform, #result_file, #single_step_stage, #task_cancelled?, #task_checkpoint, #track_and_log

Constructor Details

#initialize(deployment_name, jobs, fix_stateful_jobs = false) ⇒ ScanAndFix

Returns a new instance of ScanAndFix.



18
19
20
21
22
23
24
# File 'lib/bosh/director/jobs/cloud_check/scan_and_fix.rb', line 18

def initialize(deployment_name, jobs, fix_stateful_jobs=false)
  @deployment_manager = Api::DeploymentManager.new
  @instance_manager = Bosh::Director::Api::InstanceManager.new
  @deployment = @deployment_manager.find_by_name(deployment_name)
  @jobs = jobs # [[j1, i1], [j1, i2], [j2, i1], [j2, i2], ...]
  @fix_stateful_jobs = fix_stateful_jobs
end

Instance Attribute Details

#filtered_jobsObject (readonly)

Returns the value of attribute filtered_jobs.



10
11
12
# File 'lib/bosh/director/jobs/cloud_check/scan_and_fix.rb', line 10

def filtered_jobs
  @filtered_jobs
end

Class Method Details

.job_typeObject



14
15
16
# File 'lib/bosh/director/jobs/cloud_check/scan_and_fix.rb', line 14

def self.job_type
  :cck_scan_and_fix
end

Instance Method Details

#performObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/bosh/director/jobs/cloud_check/scan_and_fix.rb', line 26

def perform
  jobs = filtered_jobs

  begin
    with_deployment_lock(@deployment, :timeout => 0) do

      scanner = ProblemScanner::Scanner.new(@deployment)
      scanner.reset(jobs)
      scanner.scan_vms(jobs)

      resolver = ProblemResolver.new(@deployment)
      resolver.apply_resolutions(resolutions(jobs))

      "scan and fix complete"
    end
  rescue Lock::TimeoutError
    raise "Unable to get deployment lock, maybe a deployment is in progress. Try again later."
  end
end

#resolutions(jobs) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/bosh/director/jobs/cloud_check/scan_and_fix.rb', line 46

def resolutions(jobs)
  all_resolutions = {}
  jobs.each do |job, index|
    instance = @instance_manager.find_by_name(@deployment.name, job, index)
    next if instance.resurrection_paused
    problems = Models::DeploymentProblem.filter(deployment: @deployment, resource_id: instance.vm.id, state: 'open')
    problems.each do |problem|
      if problem.type == 'unresponsive_agent' || problem.type == 'missing_vm'
        all_resolutions[problem.id.to_s] = :recreate_vm
      end
    end
  end

  all_resolutions
end