class Bosh::Director::ProblemHandlers::Base

Attributes

handlers[RW]
resolutions[R]
data[R]
job[RW]

Public Class Methods

action(&block) click to toggle source
# File lib/bosh/director/problem_handlers/base.rb, line 130
def self.action(&block)
  @actions[@pending_name.to_s] = block
end
action_for(resolution) click to toggle source
# File lib/bosh/director/problem_handlers/base.rb, line 122
def self.action_for(resolution)
  @actions[resolution.to_s]
end
auto_resolution(name) click to toggle source
# File lib/bosh/director/problem_handlers/base.rb, line 138
def self.auto_resolution(name)
  @auto_resolution = name
end
create_by_type(type, resource_id, data) click to toggle source

create_by_type might not be able to initialize problem handler if some part of its state or dependencies is invalid. In this case it just substitutes a generic “invalid_problem” handler that reports the fact that the original problem is invalid and offers closing it as the only solution.

# File lib/bosh/director/problem_handlers/base.rb, line 23
def self.create_by_type(type, resource_id, data)
  handler_class = Base.handlers[type.to_s]
  if handler_class.nil?
    raise "Cannot find handler for '#{type}' problem"
  end

  handler_class.new(resource_id, data)
rescue ProblemHandlerError => e
  create_by_type(:invalid_problem, resource_id,
                 {"error" => e, "original_type" => type.to_s})
end
create_from_model(model) click to toggle source
# File lib/bosh/director/problem_handlers/base.rb, line 12
def self.create_from_model(model)
  create_by_type(model.type, model.resource_id, model.data)
end
get_auto_resolution() click to toggle source
# File lib/bosh/director/problem_handlers/base.rb, line 134
def self.get_auto_resolution
  @auto_resolution
end
inherited(base) click to toggle source
# File lib/bosh/director/problem_handlers/base.rb, line 114
def self.inherited(base)
  base.class_eval { init_dsl_data }
end
init_dsl_data() click to toggle source
# File lib/bosh/director/problem_handlers/base.rb, line 105
def self.init_dsl_data
  @resolutions = []
  @plans = {}
  @actions = {}
  @auto_resolution = nil
end
new(resource_id, data) click to toggle source

Problem state is described by constructor parameters. Problem handler can reach out to check if the problem is still present and attempt to fix it by applying a potential resolution tagged with one or more labels.

# File lib/bosh/director/problem_handlers/base.rb, line 39
def initialize(resource_id, data)
  @logger = Config.logger
  @event_log = Config.event_log
  @job = nil
end
plan(&block) click to toggle source
# File lib/bosh/director/problem_handlers/base.rb, line 126
def self.plan(&block)
  @plans[@pending_name.to_s] = block
end
plan_for(resolution) click to toggle source
# File lib/bosh/director/problem_handlers/base.rb, line 118
def self.plan_for(resolution)
  @plans[resolution.to_s]
end
register_as(type) click to toggle source
# File lib/bosh/director/problem_handlers/base.rb, line 95
def self.register_as(type)
  Base.handlers ||= {}
  Base.handlers[type.to_s] = self
end
resolution(name, &block) click to toggle source
# File lib/bosh/director/problem_handlers/base.rb, line 142
def self.resolution(name, &block)
  @resolutions << name
  @pending_name = name
  instance_eval(&block)
ensure
  @pending_name = nil
end

Public Instance Methods

apply_resolution(resolution) click to toggle source

@param resolution desired resolution

# File lib/bosh/director/problem_handlers/base.rb, line 78
def apply_resolution(resolution)
  action = self.class.action_for(resolution)
  if action.nil?
    handler_error("Cannot find '#{resolution}' resolution for '#{self.class}'")
  end
  instance_eval(&action)
end
auto_resolution() click to toggle source
# File lib/bosh/director/problem_handlers/base.rb, line 73
def auto_resolution
  self.class.get_auto_resolution
end
auto_resolve() click to toggle source
# File lib/bosh/director/problem_handlers/base.rb, line 86
def auto_resolve
  apply_resolution(auto_resolution)
end
checkpoint() click to toggle source
# File lib/bosh/director/problem_handlers/base.rb, line 45
def checkpoint
  @job.task_checkpoint if @job
end
cloud() click to toggle source

Talking to cloud should only be possible in the context of DJ job

Calls superclass method Bosh::Director::CloudcheckHelper#cloud
# File lib/bosh/director/problem_handlers/base.rb, line 51
def cloud
  if @job.nil?
    handler_error("Cannot talk to cloud outside of job context")
  end
  super
end
description() click to toggle source

Problem description

# File lib/bosh/director/problem_handlers/base.rb, line 59
def description; end
resolution_plan(resolution) click to toggle source
# File lib/bosh/director/problem_handlers/base.rb, line 67
def resolution_plan(resolution)
  plan = self.class.plan_for(resolution)
  return nil if plan.nil?
  instance_eval(&plan)
end
resolutions() click to toggle source
# File lib/bosh/director/problem_handlers/base.rb, line 61
def resolutions
  self.class.resolutions.map do |name|
    { :name => name.to_s, :plan => resolution_plan(name) }
  end
end