Class: Bosh::Director::DeploymentPlan::CompilationInstancePool
- Defined in:
- lib/bosh/director/deployment_plan/compilation_instance_pool.rb
Instance Method Summary collapse
- #delete_instances(number_of_workers) ⇒ Object
-
#initialize(instance_reuser, vm_creator, deployment_plan, logger, instance_deleter) ⇒ CompilationInstancePool
constructor
A new instance of CompilationInstancePool.
- #with_reused_vm(stemcell) ⇒ Object
- #with_single_use_vm(stemcell) ⇒ Object
Constructor Details
#initialize(instance_reuser, vm_creator, deployment_plan, logger, instance_deleter) ⇒ CompilationInstancePool
Returns a new instance of CompilationInstancePool.
4 5 6 7 8 9 10 |
# File 'lib/bosh/director/deployment_plan/compilation_instance_pool.rb', line 4 def initialize(instance_reuser, vm_creator, deployment_plan, logger, instance_deleter) @instance_reuser = instance_reuser @vm_creator = vm_creator @deployment_plan = deployment_plan @logger = logger @instance_deleter = instance_deleter end |
Instance Method Details
#delete_instances(number_of_workers) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/bosh/director/deployment_plan/compilation_instance_pool.rb', line 57 def delete_instances(number_of_workers) ThreadPool.new(:max_threads => number_of_workers).wrap do |pool| @instance_reuser.each do |instance| pool.process do @instance_reuser.remove_instance(instance) instance_plan = DeploymentPlan::InstancePlan.new( existing_instance: instance.model, instance: instance, desired_instance: DeploymentPlan::DesiredInstance.new, network_plans: [] ) delete_instance(instance_plan) end end end end |
#with_reused_vm(stemcell) ⇒ Object
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 |
# File 'lib/bosh/director/deployment_plan/compilation_instance_pool.rb', line 12 def with_reused_vm(stemcell) begin instance = @instance_reuser.get_instance(stemcell) if instance.nil? instance_plan, instance = create_instance_plan(stemcell) configure_instance_plan(instance_plan) @instance_reuser.add_in_use_instance(instance_plan.instance, stemcell) else @logger.info("Reusing compilation VM `#{instance.model.vm_cid}' for stemcell `#{stemcell.model.desc}'") end yield instance @instance_reuser.release_instance(instance) rescue => e unless instance.nil? || instance_plan.nil? @instance_reuser.remove_instance(instance) if Config.keep_unreachable_vms @logger.info('Keeping reused compilation VM for debugging') else delete_instance(instance_plan) end end raise e end end |
#with_single_use_vm(stemcell) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/bosh/director/deployment_plan/compilation_instance_pool.rb', line 40 def with_single_use_vm(stemcell) begin keep_failing_vm = false instance_plan, instance = create_instance_plan(stemcell) configure_instance_plan(instance_plan) yield instance rescue => e @logger.info('Keeping single-use compilation VM for debugging') keep_failing_vm = Config.keep_unreachable_vms raise e ensure unless instance.nil? || keep_failing_vm delete_instance(instance_plan) end end end |