Class: Bosh::Director::ProblemResolver

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(deployment) ⇒ ProblemResolver

Returns a new instance of ProblemResolver.



6
7
8
9
10
11
12
13
# File 'lib/bosh/director/problem_resolver.rb', line 6

def initialize(deployment)
  @deployment = deployment
  @resolved_count = 0

  #temp
  @event_log = Config.event_log
  @logger = Config.logger
end

Instance Attribute Details

#event_logObject (readonly)

Returns the value of attribute event_log.



4
5
6
# File 'lib/bosh/director/problem_resolver.rb', line 4

def event_log
  @event_log
end

#loggerObject (readonly)

Returns the value of attribute logger.



4
5
6
# File 'lib/bosh/director/problem_resolver.rb', line 4

def logger
  @logger
end

Instance Method Details

#apply_resolution(problem) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/bosh/director/problem_resolver.rb', line 48

def apply_resolution(problem)
  handler = ProblemHandlers::Base.create_from_model(problem)
  handler.job = self

  resolution = @resolutions[problem.id.to_s] || handler.auto_resolution
  problem_summary = "#{problem.type} #{problem.resource_id}"
  resolution_summary = handler.resolution_plan(resolution)
  resolution_summary ||= "no resolution"

  begin
    track_and_log("#{problem_summary}: #{resolution_summary}") do
      handler.apply_resolution(resolution)
    end
  rescue Bosh::Director::ProblemHandlerError => e
    log_resolution_error(problem, e)
  end

  problem.state = "resolved"
  problem.save
  @resolved_count += 1

rescue => e
  log_resolution_error(problem, e)
end

#apply_resolutions(resolutions) ⇒ Object



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

def apply_resolutions(resolutions)
  @resolutions = resolutions
  problems = Models::DeploymentProblem.where(id: resolutions.keys)

  begin_stage('Applying problem resolutions', problems.count)

  problems.each do |problem|
    if problem.state != 'open'
      reason = "state is '#{problem.state}'"
      track_and_log("Ignoring problem #{problem.id} (#{reason})")
    elsif problem.deployment_id != @deployment.id
      reason = 'not a part of this deployment'
      track_and_log("Ignoring problem #{problem.id} (#{reason})")

    else
      apply_resolution(problem)
    end
  end
  @resolved_count
end

#begin_stage(stage_name, n_steps) ⇒ Object



15
16
17
18
# File 'lib/bosh/director/problem_resolver.rb', line 15

def begin_stage(stage_name, n_steps)
  event_log.begin_stage(stage_name, n_steps)
  logger.info(stage_name)
end

#track_and_log(task, log = true) ⇒ Object



20
21
22
23
24
25
# File 'lib/bosh/director/problem_resolver.rb', line 20

def track_and_log(task, log = true)
  event_log.track(task) do |ticker|
    logger.info(task) if log
    yield ticker if block_given?
  end
end