Class: Bosh::Director::CompileTask
- Defined in:
- lib/bosh/director/compile_task.rb
Instance Attribute Summary collapse
-
#cache_key ⇒ String
readonly
A unique checksum based on the dependencies in this task.
-
#compiled_package ⇒ Models::CompiledPackage
readonly
Compiled package DB model.
-
#dependencies ⇒ Array<CompileTask>
readonly
Tasks this task depends on.
-
#dependency_key ⇒ String
Dependency key (changing it will trigger recompilation even when package bits haven’t changed).
-
#dependent_tasks ⇒ Array<CompileTask>
readonly
Tasks depending on this task.
-
#jobs ⇒ Array<DeploymentPlan::Job>
readonly
Jobs interested in this package.
-
#package ⇒ Models::Package
readonly
What package is being compiled.
-
#stemcell ⇒ Models::Stemcell
readonly
What stemcell package is compiled for.
Instance Method Summary collapse
-
#add_dependency(task, reciprocate = true) ⇒ void
Adds a compilation task to the list of dependencies.
-
#add_dependent_task(task, reciprocate = true) ⇒ void
Adds a compilation task to the list of dependent tasks.
-
#add_job(job) ⇒ void
Adds job to a list of job requiring this compiled package.
- #all_dependencies_compiled? ⇒ Boolean
- #compiled? ⇒ Boolean
-
#dependency_spec ⇒ Hash
This call only makes sense if all dependencies have already been compiled, otherwise it raises an exception.
- #find_compiled_package(logger, event_log_stage) ⇒ Models::CompiledPackage
-
#initialize(package, stemcell, initial_job, dependency_key, cache_key) ⇒ CompileTask
constructor
A new instance of CompileTask.
-
#ready_to_compile? ⇒ Boolean
Whether this task is ready to be compiled.
-
#use_compiled_package(compiled_package) ⇒ void
Makes compiled package available to all jobs waiting for it.
Constructor Details
#initialize(package, stemcell, initial_job, dependency_key, cache_key) ⇒ CompileTask
Returns a new instance of CompileTask.
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/bosh/director/compile_task.rb', line 28 def initialize(package, stemcell, initial_job, dependency_key, cache_key) @package = package @stemcell = stemcell @jobs = [] add_job(initial_job) @dependencies = [] @dependent_tasks = [] @dependency_key = dependency_key @cache_key = cache_key end |
Instance Attribute Details
#cache_key ⇒ String (readonly)
Returns A unique checksum based on the dependencies in this task.
26 27 28 |
# File 'lib/bosh/director/compile_task.rb', line 26 def cache_key @cache_key end |
#compiled_package ⇒ Models::CompiledPackage (readonly)
Returns Compiled package DB model.
13 14 15 |
# File 'lib/bosh/director/compile_task.rb', line 13 def compiled_package @compiled_package end |
#dependencies ⇒ Array<CompileTask> (readonly)
Returns Tasks this task depends on.
20 21 22 |
# File 'lib/bosh/director/compile_task.rb', line 20 def dependencies @dependencies end |
#dependency_key ⇒ String
Returns Dependency key (changing it will trigger recompilation even when package bits haven’t changed).
17 18 19 |
# File 'lib/bosh/director/compile_task.rb', line 17 def dependency_key @dependency_key end |
#dependent_tasks ⇒ Array<CompileTask> (readonly)
Returns Tasks depending on this task.
23 24 25 |
# File 'lib/bosh/director/compile_task.rb', line 23 def dependent_tasks @dependent_tasks end |
#jobs ⇒ Array<DeploymentPlan::Job> (readonly)
Returns Jobs interested in this package.
10 11 12 |
# File 'lib/bosh/director/compile_task.rb', line 10 def jobs @jobs end |
#package ⇒ Models::Package (readonly)
Returns What package is being compiled.
4 5 6 |
# File 'lib/bosh/director/compile_task.rb', line 4 def package @package end |
#stemcell ⇒ Models::Stemcell (readonly)
Returns What stemcell package is compiled for.
7 8 9 |
# File 'lib/bosh/director/compile_task.rb', line 7 def stemcell @stemcell end |
Instance Method Details
#add_dependency(task, reciprocate = true) ⇒ void
Cycle detection performed elsewhere
This method returns an undefined value.
Adds a compilation task to the list of dependencies
86 87 88 89 90 91 |
# File 'lib/bosh/director/compile_task.rb', line 86 def add_dependency(task, reciprocate=true) @dependencies << task if reciprocate task.add_dependent_task(self, false) end end |
#add_dependent_task(task, reciprocate = true) ⇒ void
Cycle detection performed elsewhere
This method returns an undefined value.
Adds a compilation task to the list of dependent tasks
98 99 100 101 102 103 |
# File 'lib/bosh/director/compile_task.rb', line 98 def add_dependent_task(task, reciprocate=true) @dependent_tasks << task if reciprocate task.add_dependency(self, false) end end |
#add_job(job) ⇒ void
Cycle detection is done elsewhere
This method returns an undefined value.
Adds job to a list of job requiring this compiled package
71 72 73 74 75 76 77 78 79 |
# File 'lib/bosh/director/compile_task.rb', line 71 def add_job(job) return if @jobs.include?(job) @jobs << job if @compiled_package # If package is already compiled we can make it available to job # immediately, otherwise it will be done by #use_compiled_package job.use_compiled_package(@compiled_package) end end |
#all_dependencies_compiled? ⇒ Boolean
47 48 49 |
# File 'lib/bosh/director/compile_task.rb', line 47 def all_dependencies_compiled? @dependencies.all? { |task| task.compiled? } end |
#compiled? ⇒ Boolean
52 53 54 |
# File 'lib/bosh/director/compile_task.rb', line 52 def compiled? !@compiled_package.nil? end |
#dependency_spec ⇒ Hash
This call only makes sense if all dependencies have already been compiled, otherwise it raises an exception
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/bosh/director/compile_task.rb', line 110 def dependency_spec spec = {} @dependencies.each do |dep_task| unless dep_task.compiled? raise DirectorError, "Cannot generate package dependency spec " + "for '#{@package.name}', " + "'#{dep_task.package.name}' hasn't been compiled yet" end compiled_package = dep_task.compiled_package spec[compiled_package.name] = { "name" => compiled_package.name, "version" => "#{compiled_package.version}.#{compiled_package.build}", "sha1" => compiled_package.sha1, "blobstore_id" => compiled_package.blobstore_id } end spec end |
#find_compiled_package(logger, event_log_stage) ⇒ Models::CompiledPackage
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/bosh/director/compile_task.rb', line 136 def find_compiled_package(logger, event_log_stage) # if `package` has source associated with it (blobstore_id and sha1) # then we need an exact match in find_compiled_package package_already_compiled = !@package.blobstore_id.nil? if package_already_compiled compiled_package = Models::CompiledPackage[ :package_id => package.id, :stemcell_os => stemcell.os, :stemcell_version => stemcell.version, :dependency_key => dependency_key ] else compiled_package = find_best_compiled_package_by_version end if compiled_package logger.info("Found compiled version of package '#{package.desc}' for stemcell '#{stemcell.desc}'") else compiled_package = fetch_from_global_cache(logger, event_log_stage) end logger.info("Package '#{package.desc}' needs to be compiled on '#{stemcell.desc}'") if compiled_package.nil? compiled_package end |
#ready_to_compile? ⇒ Boolean
Returns Whether this task is ready to be compiled.
42 43 44 |
# File 'lib/bosh/director/compile_task.rb', line 42 def ready_to_compile? !compiled? && all_dependencies_compiled? end |
#use_compiled_package(compiled_package) ⇒ void
This method returns an undefined value.
Makes compiled package available to all jobs waiting for it
59 60 61 62 63 64 65 |
# File 'lib/bosh/director/compile_task.rb', line 59 def use_compiled_package(compiled_package) @compiled_package = compiled_package @jobs.each do |job| job.use_compiled_package(@compiled_package) end end |