Class: Bosh::Director::DeploymentPlan::Planner
- Extended by:
- Forwardable
- Includes:
- LockHelper, ValidationHelper
- Defined in:
- lib/bosh/director/deployment_plan/planner.rb
Instance Attribute Summary collapse
-
#canonical_name ⇒ String
readonly
Deployment canonical name (for DNS).
-
#cloud_planner ⇒ Object
writeonly
Sets the attribute cloud_planner.
-
#jobs ⇒ Array<Bosh::Director::DeploymentPlan::Job>
readonly
All jobs in the deployment.
-
#link_spec ⇒ Object
Hash of resolved links spec provided by deployment in format job_name > template_name > link_name > link_type used by LinksResolver.
-
#model ⇒ Models::Deployment
readonly
Deployment DB model.
-
#name ⇒ String
readonly
Deployment name.
-
#properties ⇒ Object
Returns the value of attribute properties.
-
#recreate ⇒ Boolean
readonly
Indicates whether VMs should be recreated.
-
#skip_drain ⇒ Boolean
readonly
Indicates whether VMs should be drained.
-
#stemcells ⇒ Object
readonly
Stemcells in deployment by alias.
-
#unneeded_instances ⇒ Object
readonly
Job instances from the old manifest that are not in the new manifest.
-
#update ⇒ Bosh::Director::DeploymentPlan::UpdateConfig
Default job update configuration.
Instance Method Summary collapse
-
#add_job(job) ⇒ Object
Adds a job by name.
-
#add_release(release) ⇒ Object
Adds a release by name.
- #add_stemcell(stemcell) ⇒ Object
- #bind_models(skip_links_binding = false) ⇒ Object
- #candidate_existing_instances ⇒ Object
- #compile_packages ⇒ Object
- #existing_instances ⇒ Object
-
#initialize(attrs, manifest_text, cloud_config, runtime_config, deployment_model, options = {}) ⇒ Planner
constructor
A new instance of Planner.
-
#instance_models ⇒ Array<Models::Instance>
Returns a list of Instances in the deployment (according to DB).
- #instance_plans_with_missing_vms ⇒ Object
-
#job(name) ⇒ Bosh::Director::DeploymentPlan::Job
Returns a named job.
- #jobs_starting_on_deploy ⇒ Object
- #mark_instance_for_deletion(instance) ⇒ Object
- #persist_updates! ⇒ Object
-
#release(name) ⇒ Bosh::Director::DeploymentPlan::ReleaseVersion
Returns a named release.
-
#releases ⇒ Array<Bosh::Director::DeploymentPlan::ReleaseVersion>
Returns all releases in a deployment plan.
- #skip_drain_for_job?(name) ⇒ Boolean
- #stemcell(name) ⇒ Object
- #update_stemcell_references! ⇒ Object
- #using_global_networking? ⇒ Boolean
Methods included from ValidationHelper
Methods included from LockHelper
#with_compile_lock, #with_deployment_lock, #with_release_lock, #with_release_locks, #with_stemcell_lock
Constructor Details
#initialize(attrs, manifest_text, cloud_config, runtime_config, deployment_model, options = {}) ⇒ Planner
Returns a new instance of Planner.
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 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 55 def initialize(attrs, manifest_text, cloud_config, runtime_config, deployment_model, = {}) @name = attrs.fetch(:name) @properties = attrs.fetch(:properties) @releases = {} @manifest_text = Bosh::Common::DeepCopy.copy(manifest_text) @cloud_config = cloud_config @runtime_config = runtime_config @model = deployment_model @stemcells = {} @jobs = [] @jobs_name_index = {} @jobs_canonical_name_index = Set.new @unneeded_vms = [] @unneeded_instances = [] @recreate = !!['recreate'] @link_spec = Hash.new{ |h,k| h[k] = Hash.new(&h.default_proc) } @skip_drain = SkipDrain.new(['skip_drain']) @logger = Config.logger end |
Instance Attribute Details
#canonical_name ⇒ String (readonly)
Returns Deployment canonical name (for DNS).
21 22 23 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 21 def canonical_name @canonical_name end |
#cloud_planner=(value) ⇒ Object (writeonly)
Sets the attribute cloud_planner
50 51 52 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 50 def cloud_planner=(value) @cloud_planner = value end |
#jobs ⇒ Array<Bosh::Director::DeploymentPlan::Job> (readonly)
Returns All jobs in the deployment.
39 40 41 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 39 def jobs @jobs end |
#link_spec ⇒ Object
Hash of resolved links spec provided by deployment in format job_name > template_name > link_name > link_type used by LinksResolver
31 32 33 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 31 def link_spec @link_spec end |
#model ⇒ Models::Deployment (readonly)
Returns Deployment DB model.
24 25 26 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 24 def model @model end |
#name ⇒ String (readonly)
Returns Deployment name.
18 19 20 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 18 def name @name end |
#properties ⇒ Object
Returns the value of attribute properties.
26 27 28 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 26 def properties @properties end |
#recreate ⇒ Boolean (readonly)
Returns Indicates whether VMs should be recreated.
48 49 50 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 48 def recreate @recreate end |
#skip_drain ⇒ Boolean (readonly)
Returns Indicates whether VMs should be drained.
53 54 55 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 53 def skip_drain @skip_drain end |
#stemcells ⇒ Object (readonly)
Stemcells in deployment by alias
42 43 44 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 42 def stemcells @stemcells end |
#unneeded_instances ⇒ Object (readonly)
Job instances from the old manifest that are not in the new manifest
45 46 47 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 45 def unneeded_instances @unneeded_instances end |
#update ⇒ Bosh::Director::DeploymentPlan::UpdateConfig
Returns Default job update configuration.
35 36 37 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 35 def update @update end |
Instance Method Details
#add_job(job) ⇒ Object
Adds a job by name
211 212 213 214 215 216 217 218 219 220 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 211 def add_job(job) if @jobs_canonical_name_index.include?(job.canonical_name) raise DeploymentCanonicalJobNameTaken, "Invalid instance group name '#{job.name}', canonical name already taken" end @jobs << job @jobs_name_index[job.name] = job @jobs_canonical_name_index << job.canonical_name end |
#add_release(release) ⇒ Object
Adds a release by name
179 180 181 182 183 184 185 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 179 def add_release(release) if @releases.has_key?(release.name) raise DeploymentDuplicateReleaseName, "Duplicate release name '#{release.name}'" end @releases[release.name] = release end |
#add_stemcell(stemcell) ⇒ Object
169 170 171 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 169 def add_stemcell(stemcell) @stemcells[stemcell.alias] = stemcell end |
#bind_models(skip_links_binding = false) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 103 def bind_models(skip_links_binding = false) stemcell_manager = Api::StemcellManager.new dns_manager = DnsManagerProvider.create assembler = DeploymentPlan::Assembler.new( self, stemcell_manager, dns_manager, Config.cloud, @logger ) assembler.bind_models(skip_links_binding) end |
#candidate_existing_instances ⇒ Object
155 156 157 158 159 160 161 162 163 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 155 def candidate_existing_instances desired_job_names = jobs.map(&:name) = jobs.map(&:migrated_from).flatten.map(&:name) existing_instances.select do |instance| desired_job_names.include?(instance.job) || .include?(instance.job) end end |
#compile_packages ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 117 def compile_packages validate_packages cloud = Config.cloud vm_deleter = VmDeleter.new(cloud, @logger) disk_manager = DiskManager.new(cloud, @logger) job_renderer = JobRenderer.create arp_flusher = ArpFlusher.new vm_creator = Bosh::Director::VmCreator.new(cloud, @logger, vm_deleter, disk_manager, job_renderer, arp_flusher) dns_manager = DnsManagerProvider.create instance_deleter = Bosh::Director::InstanceDeleter.new(ip_provider, dns_manager, disk_manager) compilation_instance_pool = CompilationInstancePool.new( InstanceReuser.new, vm_creator, self, @logger, instance_deleter, compilation.workers) package_compile_step = DeploymentPlan::Steps::PackageCompileStep.new( jobs, compilation, compilation_instance_pool, @logger, nil ) package_compile_step.perform end |
#existing_instances ⇒ Object
151 152 153 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 151 def existing_instances instance_models end |
#instance_models ⇒ Array<Models::Instance>
Returns a list of Instances in the deployment (according to DB)
147 148 149 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 147 def instance_models @model.instances end |
#instance_plans_with_missing_vms ⇒ Object
199 200 201 202 203 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 199 def instance_plans_with_missing_vms jobs_starting_on_deploy.collect_concat do |job| job.instance_plans_with_missing_vms end end |
#job(name) ⇒ Bosh::Director::DeploymentPlan::Job
Returns a named job
225 226 227 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 225 def job(name) @jobs_name_index[name] end |
#jobs_starting_on_deploy ⇒ Object
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 229 def jobs_starting_on_deploy jobs = [] @jobs.each do |job| if job.is_service? jobs << job elsif job.is_errand? if job.instances.any? { |i| nil != i.model && !i.model.vm_cid.to_s.empty? } jobs << job end end end jobs end |
#mark_instance_for_deletion(instance) ⇒ Object
205 206 207 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 205 def mark_instance_for_deletion(instance) @unneeded_instances << instance end |
#persist_updates! ⇒ Object
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 245 def persist_updates! #prior updates may have had release versions that we no longer use. #remove the references to these stale releases. stale_release_versions = (model.release_versions - releases.map(&:model)) stale_release_names = stale_release_versions.map {|version_model| version_model.release.name}.uniq with_release_locks(stale_release_names) do stale_release_versions.each do |release_version| model.remove_release_version(release_version) end end model.manifest = Psych.dump(@manifest_text) model.cloud_config = @cloud_config model.runtime_config = @runtime_config model.link_spec = @link_spec model.save end |
#release(name) ⇒ Bosh::Director::DeploymentPlan::ReleaseVersion
Returns a named release
195 196 197 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 195 def release(name) @releases[name] end |
#releases ⇒ Array<Bosh::Director::DeploymentPlan::ReleaseVersion>
Returns all releases in a deployment plan
189 190 191 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 189 def releases @releases.values end |
#skip_drain_for_job?(name) ⇒ Boolean
165 166 167 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 165 def skip_drain_for_job?(name) @skip_drain.nil? ? false : @skip_drain.for_job(name) end |
#stemcell(name) ⇒ Object
173 174 175 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 173 def stemcell(name) @stemcells[name] end |
#update_stemcell_references! ⇒ Object
263 264 265 266 267 268 269 270 271 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 263 def update_stemcell_references! current_stemcell_models = resource_pools.map { |pool| pool.stemcell.model } @stemcells.values.map(&:model).each do |stemcell| current_stemcell_models << stemcell end model.stemcells.each do |deployment_stemcell| deployment_stemcell.remove_deployment(model) unless current_stemcell_models.include?(deployment_stemcell) end end |
#using_global_networking? ⇒ Boolean
273 274 275 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 273 def using_global_networking? !@cloud_config.nil? end |