Class: Bosh::Director::CompileTask

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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_keyString (readonly)

Returns A unique checksum based on the dependencies in this task.

Returns:

  • (String)

    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_packageModels::CompiledPackage (readonly)

Returns Compiled package DB model.

Returns:



13
14
15
# File 'lib/bosh/director/compile_task.rb', line 13

def compiled_package
  @compiled_package
end

#dependenciesArray<CompileTask> (readonly)

Returns Tasks this task depends on.

Returns:



20
21
22
# File 'lib/bosh/director/compile_task.rb', line 20

def dependencies
  @dependencies
end

#dependency_keyString

Returns Dependency key (changing it will trigger recompilation even when package bits haven’t changed).

Returns:

  • (String)

    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_tasksArray<CompileTask> (readonly)

Returns Tasks depending on this task.

Returns:



23
24
25
# File 'lib/bosh/director/compile_task.rb', line 23

def dependent_tasks
  @dependent_tasks
end

#jobsArray<DeploymentPlan::Job> (readonly)

Returns Jobs interested in this package.

Returns:



10
11
12
# File 'lib/bosh/director/compile_task.rb', line 10

def jobs
  @jobs
end

#packageModels::Package (readonly)

Returns What package is being compiled.

Returns:



4
5
6
# File 'lib/bosh/director/compile_task.rb', line 4

def package
  @package
end

#stemcellModels::Stemcell (readonly)

Returns What stemcell package is compiled for.

Returns:



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

Note:

Cycle detection performed elsewhere

This method returns an undefined value.

Adds a compilation task to the list of dependencies

Parameters:

  • task (CompileTask)

    Compilation task

  • reciprocate (Boolean) (defaults to: true)

    If true, add self as dependent task to other



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

Note:

Cycle detection performed elsewhere

This method returns an undefined value.

Adds a compilation task to the list of dependent tasks

Parameters:

  • task (CompileTask)

    Compilation task

  • reciprocate (Boolean) (defaults to: true)

    If true, add self as dependency to to other



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

Note:

Cycle detection is done elsewhere

This method returns an undefined value.

Adds job to a list of job requiring this compiled package

Parameters:



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

Returns:

  • (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

Returns:

  • (Boolean)


52
53
54
# File 'lib/bosh/director/compile_task.rb', line 52

def compiled?
  !@compiled_package.nil?
end

#dependency_specHash

This call only makes sense if all dependencies have already been compiled, otherwise it raises an exception

Returns:

  • (Hash)

    Hash representation of all package dependencies. Agent uses that to download package dependencies before compiling the package on a compilation VM.



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) ⇒ Models::CompiledPackage

Parameters:

Returns:



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
163
164
165
166
# File 'lib/bosh/director/compile_task.rb', line 136

def find_compiled_package(logger, event_log)
  # Check if this package is already compiled
  compiled_package = Models::CompiledPackage[
    :package_id => package.id,
    :stemcell_id => stemcell.id,
    :dependency_key => dependency_key
  ]
  if compiled_package
    logger.info("Found compiled version of package `#{package.desc}' " +
                   "for stemcell `#{stemcell.desc}'")
  else
    if Config.use_compiled_package_cache?
      if BlobUtil.exists_in_global_cache?(package, cache_key)
        event_log.track("Downloading '#{package.desc}' from global cache") do
          # has side effect of putting CompiledPackage model in db
          compiled_package = BlobUtil.fetch_from_global_cache(package, stemcell, cache_key, dependency_key)
        end
      end
    end

    if compiled_package
      logger.info("Package `Found compiled version of package `#{package.desc}'" +
                     "for stemcell `#{stemcell.desc}' in global cache")
    else
      logger.info("Package `#{package.desc}' " +
                     "needs to be compiled on `#{stemcell.desc}'")
    end
  end

  compiled_package
end

#ready_to_compile?Boolean

Returns Whether this task is ready to be compiled.

Returns:

  • (Boolean)

    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

Parameters:



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