Class: Bosh::Director::DeploymentPlan::ResourcePools

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

Instance Method Summary collapse

Constructor Details

#initialize(event_log, resource_pool_updaters) ⇒ ResourcePools

Returns a new instance of ResourcePools.



4
5
6
7
# File 'lib/bosh/director/deployment_plan/resource_pools.rb', line 4

def initialize(event_log, resource_pool_updaters)
  @event_log = event_log
  @resource_pool_updaters = resource_pool_updaters
end

Instance Method Details

#refillObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/bosh/director/deployment_plan/resource_pools.rb', line 38

def refill
  # Instance updaters might have added some idle vms
  # so they can be returned to resource pool. In that case
  # we need to pre-allocate network settings for all of them.
  resource_pool_updaters.each do |resource_pool_updater|
    resource_pool_updater.reserve_networks
  end

  event_log.begin_stage('Refilling resource pools', sum_across_pools(:missing_vm_count))
  ThreadPool.new(:max_threads => Config.max_threads).wrap do |thread_pool|
    # Create missing VMs across resource pools phase 2:
    # should be called after all instance updaters are finished to
    # create additional VMs in order to balance resource pools
    resource_pool_updaters.each do |resource_pool_updater|
      resource_pool_updater.create_missing_vms(thread_pool)
    end
  end
end

#updateObject



9
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
# File 'lib/bosh/director/deployment_plan/resource_pools.rb', line 9

def update
  ThreadPool.new(:max_threads => Config.max_threads).wrap do |thread_pool|
    # Delete extra VMs across resource pools
    event_log.begin_stage('Deleting extra VMs', sum_across_pools(:extra_vm_count))
    resource_pool_updaters.each do |updater|
      updater.delete_extra_vms(thread_pool)
    end
    thread_pool.wait

    # Delete outdated idle vms across resource pools, outdated allocated
    # VMs are handled by instance updater
    event_log.begin_stage('Deleting outdated idle VMs', sum_across_pools(:outdated_idle_vm_count))

    resource_pool_updaters.each do |updater|
      updater.delete_outdated_idle_vms(thread_pool)
    end
    thread_pool.wait

    # Create missing VMs across resource pools phase 1:
    # only creates VMs that have been bound to instances
    # to avoid refilling the resource pool before instances
    # that are no longer needed have been deleted.
    event_log.begin_stage('Creating bound missing VMs', sum_across_pools(:bound_missing_vm_count))
    resource_pool_updaters.each do |updater|
      updater.create_bound_missing_vms(thread_pool)
    end
  end
end