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

Returns a new instance of JobUpdater.

Parameters:



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

def initialize(deployment_plan, job, links_resolver, disk_manager)
  @deployment_plan = deployment_plan
  @job = job
  @links_resolver = links_resolver

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

Instance Method Details

#updateObject



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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/bosh/director/job_updater.rb', line 16

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

  instance_plans = @job.needed_instance_plans.select do | instance_plan |
    if instance_plan.should_be_ignored?
      false
    elsif instance_plan.changed?
      true
    else
      # no changes necessary for the agent, but some metadata may have
      # changed (i.e. vm_type.name), so push state to the db regardless
      instance_plan.persist_current_spec
      false
    end
  end

  if instance_plans.empty?
    @logger.info("No instances to update for '#{@job.name}'")
    return
  else
    @job.did_change = true
  end

  instance_plans.each do |instance_plan|
    changes = instance_plan.changes
    @logger.debug("Need to update instance '#{instance_plan.instance}', changes: #{changes.to_a.join(', ').inspect}")
  end

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

  ordered_azs = []
  instance_plans.each do | instance_plan |
    unless ordered_azs.include?(instance_plan.instance.availability_zone)
      ordered_azs.push(instance_plan.instance.availability_zone)
    end
  end

  instance_plans_by_az = instance_plans.group_by{ |instance_plan| instance_plan.instance.availability_zone }
  canaries_done = false

  ordered_azs.each do | az |
    az_instance_plans = instance_plans_by_az[az]
    @logger.info("Starting to update az '#{az}'")
    ThreadPool.new(:max_threads => @job.update.max_in_flight).wrap do |pool|
      unless canaries_done
        num_canaries = [@job.update.canaries, az_instance_plans.size].min
        @logger.info("Starting canary update num_canaries=#{num_canaries}")
        update_canaries(pool, az_instance_plans, num_canaries, event_log_stage)

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

        @logger.info('Finished canary update')

        canaries_done = true
      end

      @logger.info('Continuing the rest of the update')
      update_instances(pool, az_instance_plans, event_log_stage)
      @logger.info('Finished the rest of the update')
    end
    @logger.info("Finished updating az '#{az}'")
  end
end