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.
-
#instance_groups ⇒ Array<Bosh::Director::DeploymentPlan::Job>
readonly
All instance_groups 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.
-
#manifest_text ⇒ Object
readonly
Returns the value of attribute manifest_text.
-
#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_instance_group(instance_group) ⇒ 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_group(name) ⇒ Bosh::Director::DeploymentPlan::InstanceGroup
Returns a named instance_group.
-
#instance_models ⇒ Array<Models::Instance>
Returns a list of Instances in the deployment (according to DB).
- #instance_plans_with_missing_vms ⇒ Object
- #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.
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 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 57 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 = {} @instance_groups = [] @instance_groups_name_index = {} @instance_groups_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 |
#instance_groups ⇒ Array<Bosh::Director::DeploymentPlan::Job> (readonly)
Returns All instance_groups in the deployment.
39 40 41 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 39 def instance_groups @instance_groups 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 |
#manifest_text ⇒ Object (readonly)
Returns the value of attribute manifest_text.
55 56 57 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 55 def manifest_text @manifest_text 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_instance_group(instance_group) ⇒ Object
Adds a job by name
213 214 215 216 217 218 219 220 221 222 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 213 def add_instance_group(instance_group) if @instance_groups_canonical_name_index.include?(instance_group.canonical_name) raise DeploymentCanonicalJobNameTaken, "Invalid instance group name '#{instance_group.name}', canonical name already taken" end @instance_groups << instance_group @instance_groups_name_index[instance_group.name] = instance_group @instance_groups_canonical_name_index << instance_group.canonical_name end |
#add_release(release) ⇒ Object
Adds a release by name
181 182 183 184 185 186 187 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 181 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
171 172 173 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 171 def add_stemcell(stemcell) @stemcells[stemcell.alias] = stemcell end |
#bind_models(skip_links_binding = false) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 105 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
157 158 159 160 161 162 163 164 165 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 157 def candidate_existing_instances desired_job_names = instance_groups.map(&:name) = instance_groups.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
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 144 145 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 119 def compile_packages validate_packages cloud = Config.cloud vm_deleter = VmDeleter.new(cloud, @logger, false, Config.enable_virtual_delete_vms) 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( instance_groups, compilation, compilation_instance_pool, @logger, nil ) package_compile_step.perform end |
#existing_instances ⇒ Object
153 154 155 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 153 def existing_instances instance_models end |
#instance_group(name) ⇒ Bosh::Director::DeploymentPlan::InstanceGroup
Returns a named instance_group
227 228 229 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 227 def instance_group(name) @instance_groups_name_index[name] end |
#instance_models ⇒ Array<Models::Instance>
Returns a list of Instances in the deployment (according to DB)
149 150 151 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 149 def instance_models @model.instances end |
#instance_plans_with_missing_vms ⇒ Object
201 202 203 204 205 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 201 def instance_plans_with_missing_vms jobs_starting_on_deploy.collect_concat do |job| job.instance_plans_with_missing_vms end end |
#jobs_starting_on_deploy ⇒ Object
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 231 def jobs_starting_on_deploy instance_groups = [] @instance_groups.each do |instance_group| if instance_group.is_service? instance_groups << instance_group elsif instance_group.is_errand? if instance_group.instances.any? { |i| nil != i.model && !i.model.vm_cid.to_s.empty? } instance_groups << instance_group end end end instance_groups end |
#mark_instance_for_deletion(instance) ⇒ Object
207 208 209 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 207 def mark_instance_for_deletion(instance) @unneeded_instances << instance end |
#persist_updates! ⇒ Object
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 247 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
197 198 199 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 197 def release(name) @releases[name] end |
#releases ⇒ Array<Bosh::Director::DeploymentPlan::ReleaseVersion>
Returns all releases in a deployment plan
191 192 193 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 191 def releases @releases.values end |
#skip_drain_for_job?(name) ⇒ Boolean
167 168 169 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 167 def skip_drain_for_job?(name) @skip_drain.nil? ? false : @skip_drain.for_job(name) end |
#stemcell(name) ⇒ Object
175 176 177 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 175 def stemcell(name) @stemcells[name] end |
#update_stemcell_references! ⇒ Object
265 266 267 268 269 270 271 272 273 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 265 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
275 276 277 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 275 def using_global_networking? !@cloud_config.nil? end |