Class: Bosh::Director::ProblemScanner::ProblemRegister

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

Instance Method Summary collapse

Constructor Details

#initialize(deployment, logger) ⇒ ProblemRegister

Returns a new instance of ProblemRegister.



3
4
5
6
7
8
# File 'lib/bosh/director/problem_scanner/problem_register.rb', line 3

def initialize(deployment, logger)
  @deployment = deployment
  @logger = logger

  @problem_lock = Mutex.new
end

Instance Method Details

#get_disk(instance) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/bosh/director/problem_scanner/problem_register.rb', line 43

def get_disk(instance)
  mounted_disk_cid = nil

  @problem_lock.synchronize do
    mounted_disk_cid = instance.persistent_disk_cid if instance
  end

  mounted_disk_cid
end

#problem_found(type, resource, data = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/bosh/director/problem_scanner/problem_register.rb', line 10

def problem_found(type, resource, data = {})
  @problem_lock.synchronize do
    similar_open_problems = Bosh::Director::Models::DeploymentProblem.
      filter(deployment_id: @deployment.id, type: type.to_s,
      resource_id: resource.id, state: 'open').all

    if similar_open_problems.size > 1
      raise Bosh::Director::CloudcheckTooManySimilarProblems,
        "More than one problem of type '#{type}' " +
          "exists for resource #{type} #{resource.id}"
    end

    if similar_open_problems.empty?
      problem = Bosh::Director::Models::DeploymentProblem.
        create(type: type.to_s, resource_id: resource.id,
        state: 'open', deployment_id: @deployment.id,
        data: data, counter: 1)

      @logger.info("Created problem #{problem.id} (#{problem.type})")
    else
      # This assumes we are running with deployment lock acquired,
      # so there is no possible update conflict
      problem = similar_open_problems[0]
      problem.data = data
      problem.last_seen_at = Time.now
      problem.counter += 1
      problem.save
      @logger.info("Updated problem #{problem.id} (#{problem.type}), " +
        "count is now #{problem.counter}")
    end
  end
end