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, job_renderer) ⇒ JobUpdater

Returns a new instance of JobUpdater.



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

def initialize(deployment_plan, job, job_renderer)
  @deployment_plan = deployment_plan
  @job = job
  @job_renderer = job_renderer

  @logger = Config.logger
  @event_log = Config.event_log
end

Instance Method Details

#updateObject



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
# File 'lib/bosh/director/job_updater.rb', line 15

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")

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

  @logger.info("Finished the rest of the update")
end