Class: Bosh::Director::DeploymentPlan::Planner

Inherits:
Object
  • Object
show all
Includes:
Bosh::Director::DnsHelper, ValidationHelper
Defined in:
lib/bosh/director/deployment_plan/planner.rb

Constant Summary

Constants included from Bosh::Director::DnsHelper

Bosh::Director::DnsHelper::SOA, Bosh::Director::DnsHelper::TTL_4H, Bosh::Director::DnsHelper::TTL_5M

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ValidationHelper

#invalid_type, #safe_property

Methods included from Bosh::Director::DnsHelper

#add_default_dns_server, #canonical, #default_dns_server, #delete_dns_records, #delete_empty_domain, #dns_domain_name, #dns_ns_record, #dns_servers, #invalid_dns, #reverse_domain, #reverse_host, #update_dns_a_record, #update_dns_ptr_record

Constructor Details

#initialize(name, options = {}) ⇒ Planner

Returns a new instance of Planner.

Raises:

  • (ArgumentError)


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/bosh/director/deployment_plan/planner.rb', line 54

def initialize(name, options = {})
  raise ArgumentError, 'name must not be nil' unless name
  @name = name
  @model = nil

  @properties = {}
  @releases = {}
  @networks = {}
  @networks_canonical_name_index = Set.new

  @resource_pools = {}

  @jobs = []
  @jobs_name_index = {}
  @jobs_canonical_name_index = Set.new

  @unneeded_vms = []
  @unneeded_instances = []
  @dns_domain = nil

  @job_rename = safe_property(options, 'job_rename',
    :class => Hash, :default => {})

  @recreate = !!options['recreate']
end

Instance Attribute Details

#canonical_nameString (readonly)

Returns Deployment canonical name (for DNS).

Returns:

  • (String)

    Deployment canonical name (for DNS)



15
16
17
# File 'lib/bosh/director/deployment_plan/planner.rb', line 15

def canonical_name
  @canonical_name
end

#compilationBosh::Director::DeploymentPlan::CompilationConfig

Returns Resource pool and other configuration for compilation workers.

Returns:



24
25
26
# File 'lib/bosh/director/deployment_plan/planner.rb', line 24

def compilation
  @compilation
end

#dns_domainObject

Returns the value of attribute dns_domain.



36
37
38
# File 'lib/bosh/director/deployment_plan/planner.rb', line 36

def dns_domain
  @dns_domain
end

#job_renameObject (readonly)

Returns the value of attribute job_rename.



38
39
40
# File 'lib/bosh/director/deployment_plan/planner.rb', line 38

def job_rename
  @job_rename
end

#jobsArray<Bosh::Director::DeploymentPlan::Job> (readonly)

Returns All jobs in the deployment.

Returns:



32
33
34
# File 'lib/bosh/director/deployment_plan/planner.rb', line 32

def jobs
  @jobs
end

#modelModels::Deployment (readonly)

Returns Deployment DB model.

Returns:



18
19
20
# File 'lib/bosh/director/deployment_plan/planner.rb', line 18

def model
  @model
end

#nameString (readonly)

Returns Deployment name.

Returns:

  • (String)

    Deployment name



12
13
14
# File 'lib/bosh/director/deployment_plan/planner.rb', line 12

def name
  @name
end

#propertiesObject

Returns the value of attribute properties.



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

def properties
  @properties
end

#recreateBoolean (readonly)

Returns Indicates whether VMs should be recreated.

Returns:

  • (Boolean)

    Indicates whether VMs should be recreated



41
42
43
# File 'lib/bosh/director/deployment_plan/planner.rb', line 41

def recreate
  @recreate
end

#unneeded_instancesObject

Returns the value of attribute unneeded_instances.



34
35
36
# File 'lib/bosh/director/deployment_plan/planner.rb', line 34

def unneeded_instances
  @unneeded_instances
end

#unneeded_vmsObject

Returns the value of attribute unneeded_vms.



35
36
37
# File 'lib/bosh/director/deployment_plan/planner.rb', line 35

def unneeded_vms
  @unneeded_vms
end

#updateBosh::Director::DeploymentPlan::UpdateConfig

Returns Default job update configuration.

Returns:



28
29
30
# File 'lib/bosh/director/deployment_plan/planner.rb', line 28

def update
  @update
end

Class Method Details

.parse(manifest, event_log, options) ⇒ Bosh::Director::DeploymentPlan::Planner

Parameters:

  • manifest (Hash)

    Raw deployment manifest

  • event_log (Bosh::Director::EventLog::Log)

    Event log for recording deprecations

  • options (Hash)

    Additional options for deployment (e.g. job_states, job_rename)

Returns:



49
50
51
52
# File 'lib/bosh/director/deployment_plan/planner.rb', line 49

def self.parse(manifest, event_log, options)
  parser = DeploymentSpecParser.new(event_log)
  parser.parse(manifest, options)
end

Instance Method Details

#add_job(job) ⇒ Object

Adds a job by name



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/bosh/director/deployment_plan/planner.rb', line 206

def add_job(job)
  if rename_in_progress? && @job_rename['old_name'] == job.name
    raise DeploymentRenamedJobNameStillUsed,
      "Renamed job `#{job.name}' is still referenced in " +
        'deployment manifest'
  end

  if @jobs_canonical_name_index.include?(job.canonical_name)
    raise DeploymentCanonicalJobNameTaken,
      "Invalid job 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_network(network) ⇒ Object

Adds a network by name



119
120
121
122
123
124
125
126
127
128
# File 'lib/bosh/director/deployment_plan/planner.rb', line 119

def add_network(network)
  if @networks_canonical_name_index.include?(network.canonical_name)
    raise DeploymentCanonicalNetworkNameTaken,
      "Invalid network name `#{network.name}', " +
        'canonical name already taken'
  end

  @networks[network.name] = network
  @networks_canonical_name_index << network.canonical_name
end

#add_release(release) ⇒ Object

Adds a release by name



168
169
170
171
172
173
174
# File 'lib/bosh/director/deployment_plan/planner.rb', line 168

def add_release(release)
  if @releases.has_key?(release.name)
    raise DeploymentDuplicateReleaseName,
      "Duplicate release name `#{release.name}'"
  end
  @releases[release.name] = release
end

#add_resource_pool(resource_pool) ⇒ Object

Adds a resource pool by name

Parameters:



145
146
147
148
149
150
151
# File 'lib/bosh/director/deployment_plan/planner.rb', line 145

def add_resource_pool(resource_pool)
  if @resource_pools[resource_pool.name]
    raise DeploymentDuplicateResourcePoolName,
      "Duplicate resource pool name `#{resource_pool.name}'"
  end
  @resource_pools[resource_pool.name] = resource_pool
end

#bind_modelvoid

This method returns an undefined value.

Looks up deployment model in DB or creates one if needed



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/planner.rb', line 86

def bind_model
  attrs = {:name => @name}

  Models::Deployment.db.transaction do
    deployment = Models::Deployment.find(attrs)

    # Canonical uniqueness is not enforced in the DB
    if deployment.nil?
      Models::Deployment.each do |other|
        if canonical(other.name) == canonical_name
          raise DeploymentCanonicalNameTaken,
                "Invalid deployment name `#{@name}', " +
                  'canonical name already taken'
        end
      end
      deployment = Models::Deployment.create(attrs)
    end

    @model = deployment
  end
end

#delete_instance(instance) ⇒ Object

Adds instance to deletion queue

Parameters:



196
197
198
199
200
201
202
# File 'lib/bosh/director/deployment_plan/planner.rb', line 196

def delete_instance(instance)
  if @jobs_name_index.has_key?(instance.job)
    @jobs_name_index[instance.job].unneeded_instances << instance
  else
    @unneeded_instances << instance
  end
end

#delete_vm(vm) ⇒ Object

Adds a VM to deletion queue

Parameters:



190
191
192
# File 'lib/bosh/director/deployment_plan/planner.rb', line 190

def delete_vm(vm)
  @unneeded_vms << vm
end

#job(name) ⇒ Bosh::Director::DeploymentPlan::Job

Returns a named job

Parameters:

  • name (String)

    Job name

Returns:



226
227
228
# File 'lib/bosh/director/deployment_plan/planner.rb', line 226

def job(name)
  @jobs_name_index[name]
end

#jobs_starting_on_deployObject



230
231
232
# File 'lib/bosh/director/deployment_plan/planner.rb', line 230

def jobs_starting_on_deploy
  @jobs.select(&:starts_on_deploy?)
end

#network(name) ⇒ Bosh::Director::DeploymentPlan::Network

Returns a named network

Parameters:

  • name (String)

Returns:



139
140
141
# File 'lib/bosh/director/deployment_plan/planner.rb', line 139

def network(name)
  @networks[name]
end

#networksArray<Bosh::Director::DeploymentPlan::Network>

Returns all networks in a deployment plan



132
133
134
# File 'lib/bosh/director/deployment_plan/planner.rb', line 132

def networks
  @networks.values
end

#release(name) ⇒ Bosh::Director::DeploymentPlan::ReleaseVersion

Returns a named release



184
185
186
# File 'lib/bosh/director/deployment_plan/planner.rb', line 184

def release(name)
  @releases[name]
end

#releasesArray<Bosh::Director::DeploymentPlan::ReleaseVersion>

Returns all releases in a deployment plan



178
179
180
# File 'lib/bosh/director/deployment_plan/planner.rb', line 178

def releases
  @releases.values
end

#rename_in_progress?Boolean

Returns:

  • (Boolean)


234
235
236
# File 'lib/bosh/director/deployment_plan/planner.rb', line 234

def rename_in_progress?
  @job_rename['old_name'] && @job_rename['new_name']
end

#resource_pool(name) ⇒ Bosh::Director::DeploymentPlan::ResourcePool

Returns a named resource pool spec

Parameters:

  • name (String)

    Resource pool name

Returns:



162
163
164
# File 'lib/bosh/director/deployment_plan/planner.rb', line 162

def resource_pool(name)
  @resource_pools[name]
end

#resource_poolsArray<Bosh::Director::DeploymentPlan::ResourcePool>

Returns all resource pools in a deployment plan



155
156
157
# File 'lib/bosh/director/deployment_plan/planner.rb', line 155

def resource_pools
  @resource_pools.values
end

#vmsArray<Models::Vm>

Returns a list of VMs in the deployment (according to DB)

Returns:



110
111
112
113
114
115
# File 'lib/bosh/director/deployment_plan/planner.rb', line 110

def vms
  if @model.nil?
    raise DirectorError, "Can't get VMs list, deployment model is unbound"
  end
  @model.vms
end