Class: Bosh::Director::JobUpdater

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

Instance Method Summary collapse

Constructor Details

#initialize(deployment_plan, job) ⇒ JobUpdater

Returns a new instance of JobUpdater.

Parameters:



5
6
7
8
9
10
11
# File 'lib/bosh/director/job_updater.rb', line 5

def initialize(deployment_plan, job)
  @deployment_plan = deployment_plan
  @job = job
  @cloud = Config.cloud
  @logger = Config.logger
  @event_log = Config.event_log
end

Instance Method Details

#haltObject



55
56
57
# File 'lib/bosh/director/job_updater.rb', line 55

def halt
  raise(@job.halt_exception || RuntimeError.new("Deployment has been halted"))
end

#updateObject



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
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/bosh/director/job_updater.rb', line 13

def update
  @logger.info("Deleting no longer needed instances")
  delete_unneeded_instances

  instances = []
  @job.instances.each do |instance|
    instances << instance if instance.changed?
  end

  if instances.empty?
    @logger.info("No instances to update for `#{@job.name}'")
    return
  end

  @logger.info("Found #{instances.size} instances to update")
  event_log_stage = @event_log.begin_stage("Updating job", instances.size, [ @job.name ])

  ThreadPool.new(:max_threads => @job.update.max_in_flight).wrap do |pool|
    num_canaries = [ @job.update.canaries, instances.size ].min
    @logger.info("Starting canary update num_canaries=#{num_canaries}")
    update_canaries(pool, instances, num_canaries, event_log_stage)

    @logger.info("Waiting for canaries to update")
    pool.wait

    @logger.info("Finished canary update")
    if @job.should_halt?
      @logger.warn("Halting deployment due to a canary failure")
      halt
    end

    @logger.info("Continuing the rest of the update")
    update_instances(pool, instances, event_log_stage)
  end

  @logger.info("Finished the rest of the update")
  if @job.should_halt?
    @logger.warn("Halting deployment due to an update failure")
    halt
  end
end