Class: Bosh::Director::DeploymentPlan::Steps::PackageCompileStep
- Includes:
- LockHelper
- Defined in:
- lib/bosh/director/deployment_plan/steps/package_compile_step.rb
Instance Attribute Summary collapse
-
#compilations_performed ⇒ Object
readonly
Returns the value of attribute compilations_performed.
Instance Method Summary collapse
- #compile_package(task) ⇒ Object
- #compile_tasks_count ⇒ Object
-
#initialize(jobs_to_compile, compilation_config, compilation_instance_pool, logger, director_job) ⇒ PackageCompileStep
constructor
A new instance of PackageCompileStep.
- #perform ⇒ Object
-
#prepare_vm(stemcell) {|DeploymentPlan::Instance| ... } ⇒ Object
This method will create a VM for each stemcell in the stemcells array passed in.
- #ready_tasks_count ⇒ Object
Methods included from LockHelper
#with_compile_lock, #with_deployment_lock, #with_release_lock, #with_release_locks, #with_stemcell_lock
Constructor Details
#initialize(jobs_to_compile, compilation_config, compilation_instance_pool, logger, director_job) ⇒ PackageCompileStep
Returns a new instance of PackageCompileStep.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/bosh/director/deployment_plan/steps/package_compile_step.rb', line 12 def initialize(jobs_to_compile, compilation_config, compilation_instance_pool, logger, director_job) @event_log_stage = nil @logger = logger @director_job = director_job @tasks_mutex = Mutex.new @counter_mutex = Mutex.new @compilation_instance_pool = compilation_instance_pool @compile_tasks = {} @ready_tasks = [] @compilations_performed = 0 @jobs_to_compile = jobs_to_compile @compilation_config = compilation_config end |
Instance Attribute Details
#compilations_performed ⇒ Object (readonly)
Returns the value of attribute compilations_performed.
10 11 12 |
# File 'lib/bosh/director/deployment_plan/steps/package_compile_step.rb', line 10 def compilations_performed @compilations_performed end |
Instance Method Details
#compile_package(task) ⇒ Object
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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/bosh/director/deployment_plan/steps/package_compile_step.rb', line 55 def compile_package(task) package = task.package stemcell = task.stemcell with_compile_lock(package.id, stemcell.id) do # Check if the package was compiled in a parallel deployment compiled_package = task.find_compiled_package(@logger, @event_log_stage) if compiled_package.nil? build = Models::CompiledPackage.generate_build_number(package, stemcell.model., stemcell.model.version) task_result = nil prepare_vm(stemcell) do |instance| .update(instance.model, :compiling => package.name) agent_task = instance.agent_client.compile_package( package.blobstore_id, package.sha1, package.name, "#{package.version}.#{build}", task.dependency_spec ) task_result = agent_task['result'] end compiled_package = Models::CompiledPackage.create do |p| p.package = package p.stemcell_os = stemcell.os p.stemcell_version = stemcell.version p.sha1 = task_result['sha1'] p.build = build p.blobstore_id = task_result['blobstore_id'] p.dependency_key = task.dependency_key end if Config.use_compiled_package_cache? if BlobUtil.exists_in_global_cache?(package, task.cache_key) @logger.info('Already exists in global package cache, skipping upload') else @logger.info('Uploading to global package cache') BlobUtil.save_to_global_cache(compiled_package, task.cache_key) end else @logger.info('Global blobstore not configured, skipping upload') end @counter_mutex.synchronize { @compilations_performed += 1 } end task.use_compiled_package(compiled_package) end end |
#compile_tasks_count ⇒ Object
47 48 49 |
# File 'lib/bosh/director/deployment_plan/steps/package_compile_step.rb', line 47 def compile_tasks_count @compile_tasks.size end |
#perform ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/bosh/director/deployment_plan/steps/package_compile_step.rb', line 28 def perform @logger.info('Generating a list of compile tasks') prepare_tasks @compile_tasks.each_value do |task| if task.ready_to_compile? @logger.info("Package '#{task.package.desc}' is ready to be compiled for stemcell '#{task.stemcell.desc}'") @ready_tasks << task end end if @ready_tasks.empty? @logger.info('All packages are already compiled') else compile_packages director_job_checkpoint end end |
#prepare_vm(stemcell) {|DeploymentPlan::Instance| ... } ⇒ Object
This method will create a VM for each stemcell in the stemcells array passed in. The VMs are yielded and their destruction is ensured.
113 114 115 116 117 118 119 |
# File 'lib/bosh/director/deployment_plan/steps/package_compile_step.rb', line 113 def prepare_vm(stemcell) if @compilation_config.reuse_compilation_vms @compilation_instance_pool.with_reused_vm(stemcell, &Proc.new) else @compilation_instance_pool.with_single_use_vm(stemcell, &Proc.new) end end |
#ready_tasks_count ⇒ Object
51 52 53 |
# File 'lib/bosh/director/deployment_plan/steps/package_compile_step.rb', line 51 def ready_tasks_count @tasks_mutex.synchronize { @ready_tasks.size } end |