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, #dns_manager, #event_manager, #logger, perform, #result_file, schedule_message, #single_step_stage, #task_cancelled?, #task_checkpoint, #track_and_log, #username

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
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/bosh/director/jobs/cloud_check/scan_and_fix.rb', line 26

def perform
  jobs = filtered_jobs

  resolved_problems = 0
  error_message = nil

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

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

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

      if resolved_problems > 0
        PostDeploymentScriptRunner.run_post_deploys_after_resurrection(@deployment)
      end
    end

    if error_message
      raise Bosh::Director::ProblemHandlerError, error_message
    end

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

#resolutions(jobs) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/bosh/director/jobs/cloud_check/scan_and_fix.rb', line 57

def resolutions(jobs)
  all_resolutions = {}
  jobs.each do |job, index|
    instance = @instance_manager.find_by_name(@deployment, job, index)
    next if instance.resurrection_paused || instance.ignore
    problems = Models::DeploymentProblem.filter(deployment: @deployment, resource_id: instance.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