bosh-director 1.3173.0 → 1.3177.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/db/migrations/director/20151229184742_add_vm_attributes_to_instance.rb +25 -0
- data/db/migrations/director/20160108191637_drop_vm_env_json_from_instance.rb +7 -0
- data/lib/bosh/director/api/controllers/base_controller.rb +1 -1
- data/lib/bosh/director/api/controllers/deployments_controller.rb +1 -1
- data/lib/bosh/director/api/deployment_manager.rb +10 -12
- data/lib/bosh/director/api/instance_manager.rb +5 -6
- data/lib/bosh/director/api/snapshot_manager.rb +1 -2
- data/lib/bosh/director/cloudcheck_helper.rb +30 -52
- data/lib/bosh/director/config.rb +2 -1
- data/lib/bosh/director/deployment_deleter.rb +0 -21
- data/lib/bosh/director/deployment_plan.rb +1 -1
- data/lib/bosh/director/deployment_plan/agent_state_migrator.rb +7 -19
- data/lib/bosh/director/deployment_plan/assembler.rb +6 -30
- data/lib/bosh/director/deployment_plan/compilation_instance_pool.rb +2 -4
- data/lib/bosh/director/deployment_plan/dynamic_network.rb +1 -1
- data/lib/bosh/director/deployment_plan/instance.rb +6 -46
- data/lib/bosh/director/deployment_plan/instance_network_reservations.rb +13 -13
- data/lib/bosh/director/deployment_plan/instance_plan.rb +3 -3
- data/lib/bosh/director/deployment_plan/instance_plan_factory.rb +12 -4
- data/lib/bosh/director/deployment_plan/instance_planner.rb +5 -4
- data/lib/bosh/director/deployment_plan/instance_repository.rb +7 -14
- data/lib/bosh/director/deployment_plan/instance_spec.rb +2 -2
- data/lib/bosh/director/deployment_plan/ip_provider/database_ip_repo.rb +7 -7
- data/lib/bosh/director/deployment_plan/ip_provider/in_memory_ip_repo.rb +6 -3
- data/lib/bosh/director/deployment_plan/ip_provider/ip_provider.rb +4 -4
- data/lib/bosh/director/deployment_plan/job.rb +0 -7
- data/lib/bosh/director/deployment_plan/job_migrator.rb +3 -2
- data/lib/bosh/director/deployment_plan/manual_network_subnet.rb +1 -1
- data/lib/bosh/director/deployment_plan/network_planner/planner.rb +2 -2
- data/lib/bosh/director/deployment_plan/network_reservation_repository.rb +20 -0
- data/lib/bosh/director/deployment_plan/placement_planner/static_ips_availability_zone_picker.rb +2 -1
- data/lib/bosh/director/deployment_plan/planner.rb +2 -17
- data/lib/bosh/director/deployment_plan/steps/package_compile_step.rb +1 -1
- data/lib/bosh/director/deployment_plan/steps/update_step.rb +1 -21
- data/lib/bosh/director/disk_manager.rb +8 -8
- data/lib/bosh/director/dns/dns_manager.rb +76 -20
- data/lib/bosh/director/errand/job_manager.rb +1 -1
- data/lib/bosh/director/instance_deleter.rb +1 -3
- data/lib/bosh/director/instance_updater.rb +4 -3
- data/lib/bosh/director/job_updater.rb +10 -2
- data/lib/bosh/director/jobs/base_job.rb +1 -1
- data/lib/bosh/director/jobs/cloud_check/scan_and_fix.rb +3 -3
- data/lib/bosh/director/jobs/create_snapshot.rb +1 -1
- data/lib/bosh/director/jobs/delete_deployment.rb +1 -1
- data/lib/bosh/director/jobs/delete_deployment_snapshots.rb +1 -1
- data/lib/bosh/director/jobs/snapshot_deployment.rb +2 -2
- data/lib/bosh/director/jobs/vm_state.rb +16 -17
- data/lib/bosh/director/models.rb +0 -1
- data/lib/bosh/director/models/deployment.rb +0 -3
- data/lib/bosh/director/models/instance.rb +17 -10
- data/lib/bosh/director/network_reservation.rb +15 -16
- data/lib/bosh/director/problem_handlers/inactive_disk.rb +4 -6
- data/lib/bosh/director/problem_handlers/missing_disk.rb +3 -5
- data/lib/bosh/director/problem_handlers/missing_vm.rb +8 -10
- data/lib/bosh/director/problem_handlers/mount_info_mismatch.rb +8 -3
- data/lib/bosh/director/problem_handlers/unresponsive_agent.rb +14 -29
- data/lib/bosh/director/problem_scanner/disk_scan_stage.rb +1 -4
- data/lib/bosh/director/problem_scanner/problem_register.rb +2 -4
- data/lib/bosh/director/problem_scanner/scanner.rb +1 -1
- data/lib/bosh/director/problem_scanner/vm_scan_stage.rb +17 -35
- data/lib/bosh/director/stopper.rb +2 -2
- data/lib/bosh/director/version.rb +1 -1
- data/lib/bosh/director/vm_creator.rb +15 -33
- data/lib/bosh/director/vm_deleter.rb +6 -8
- data/lib/bosh/director/vm_metadata_updater.rb +5 -7
- data/lib/bosh/director/vm_recreator.rb +3 -2
- metadata +19 -18
- data/lib/bosh/director/deployment_plan/vm.rb +0 -22
- data/lib/bosh/director/models/vm.rb +0 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f90717cdc69804b0c839e2796bdadba05432eacb
|
4
|
+
data.tar.gz: c52beb6a4f72061cbc9715f40a7721df52d19f8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aedd24032d99e4ac6dc32f3657d317cc9e47219f6fa9fcfd1e4668d5c5d198ea66efaa83c8d1bb5c548be2c105146b9ba83a03bd3af3f952d9914d004e72ffc8
|
7
|
+
data.tar.gz: 074ecb54fefc49921a885a05ade03855cac05c8061da2594cae67607781afdb3258a0d9f17abf032ca58e4f30ee2b79b4769c5b009e26efe0f64b3d05886b02f
|
@@ -0,0 +1,25 @@
|
|
1
|
+
Sequel.migration do
|
2
|
+
change do
|
3
|
+
alter_table(:instances) do
|
4
|
+
add_column :vm_cid, String, unique: true
|
5
|
+
add_column :agent_id, String, unique: true
|
6
|
+
add_column :credentials_json, String, :text => true
|
7
|
+
add_column :vm_env_json, String, :text => true
|
8
|
+
add_column :trusted_certs_sha1, String, { :default => Digest::SHA1.hexdigest('') }
|
9
|
+
end
|
10
|
+
|
11
|
+
self[:instances].each do |instance|
|
12
|
+
next unless instance[:vm_id]
|
13
|
+
|
14
|
+
vm = self[:vms].filter(id: instance[:vm_id]).first
|
15
|
+
|
16
|
+
self[:instances].filter(id: instance[:id]).update(
|
17
|
+
vm_cid: vm[:cid],
|
18
|
+
agent_id: vm[:agent_id],
|
19
|
+
vm_env_json: vm[:env_json],
|
20
|
+
trusted_certs_sha1: vm[:trusted_certs_sha1],
|
21
|
+
credentials_json: vm[:credentials_json]
|
22
|
+
)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -22,7 +22,7 @@ module Bosh::Director
|
|
22
22
|
@stemcell_manager = StemcellManager.new
|
23
23
|
@task_manager = TaskManager.new
|
24
24
|
@vm_state_manager = VmStateManager.new
|
25
|
-
@dns_manager =
|
25
|
+
@dns_manager = DnsManagerProvider.create
|
26
26
|
@disk_manager = DiskManager.new(nil, @logger)
|
27
27
|
end
|
28
28
|
|
@@ -176,7 +176,7 @@ module Bosh::Director
|
|
176
176
|
task = @vm_state_manager.fetch_vm_state(current_user, deployment, format)
|
177
177
|
redirect "/tasks/#{task.id}"
|
178
178
|
else
|
179
|
-
@deployment_manager.
|
179
|
+
@deployment_manager.deployment_instances_to_json(deployment)
|
180
180
|
end
|
181
181
|
end
|
182
182
|
|
@@ -38,22 +38,20 @@ module Bosh::Director
|
|
38
38
|
Yajl::Encoder.encode(result)
|
39
39
|
end
|
40
40
|
|
41
|
-
def
|
42
|
-
|
41
|
+
def deployment_instances_to_json(deployment)
|
42
|
+
instances = []
|
43
43
|
filters = {:deployment_id => deployment.id}
|
44
|
-
Models::
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
'
|
49
|
-
'
|
50
|
-
'
|
51
|
-
'index' => instance ? instance.index : nil,
|
52
|
-
'id' => instance ? instance.uuid : nil
|
44
|
+
Models::Instance.filter(filters).exclude(vm_cid: nil).each do |instance|
|
45
|
+
instances << {
|
46
|
+
'agent_id' => instance.agent_id,
|
47
|
+
'cid' => instance.vm_cid,
|
48
|
+
'job' => instance.job,
|
49
|
+
'index' => instance.index,
|
50
|
+
'id' => instance.uuid
|
53
51
|
}
|
54
52
|
end
|
55
53
|
|
56
|
-
Yajl::Encoder.encode(
|
54
|
+
Yajl::Encoder.encode(instances)
|
57
55
|
end
|
58
56
|
end
|
59
57
|
end
|
@@ -31,17 +31,16 @@ module Bosh::Director
|
|
31
31
|
# @param [Models::Instance] instance Instance
|
32
32
|
# @return [AgentClient] Agent client to talk to instance
|
33
33
|
def agent_client_for(instance)
|
34
|
-
|
35
|
-
if vm.nil?
|
34
|
+
unless instance.vm_cid
|
36
35
|
raise InstanceVmMissing,
|
37
|
-
"`#{instance
|
36
|
+
"`#{instance}' doesn't reference a VM"
|
38
37
|
end
|
39
38
|
|
40
|
-
|
41
|
-
raise VmAgentIdMissing, "VM `#{
|
39
|
+
unless instance.agent_id
|
40
|
+
raise VmAgentIdMissing, "VM `#{instance.vm_cid}' doesn't have an agent id"
|
42
41
|
end
|
43
42
|
|
44
|
-
AgentClient.with_vm_credentials_and_agent_id(
|
43
|
+
AgentClient.with_vm_credentials_and_agent_id(instance.credentials, instance.agent_id)
|
45
44
|
end
|
46
45
|
|
47
46
|
def fetch_logs(username, deployment_name, job, index_or_id, options = {})
|
@@ -76,8 +76,7 @@ module Bosh::Director
|
|
76
76
|
index: instance.index,
|
77
77
|
director_name: Config.name,
|
78
78
|
director_uuid: Config.uuid,
|
79
|
-
agent_id: instance.
|
80
|
-
instance_id: instance.vm_id
|
79
|
+
agent_id: instance.agent_id
|
81
80
|
}
|
82
81
|
|
83
82
|
instance.persistent_disks.each do |disk|
|
@@ -13,10 +13,10 @@ module Bosh::Director
|
|
13
13
|
# still be pretty generous interval for agent to respond.
|
14
14
|
DEFAULT_AGENT_TIMEOUT = 10
|
15
15
|
|
16
|
-
def reboot_vm(
|
17
|
-
cloud.reboot_vm(
|
16
|
+
def reboot_vm(instance)
|
17
|
+
cloud.reboot_vm(instance.vm_cid)
|
18
18
|
begin
|
19
|
-
agent_client(
|
19
|
+
agent_client(instance.credentials, instance.agent_id).wait_until_ready
|
20
20
|
rescue Bosh::Director::RpcTimeout
|
21
21
|
handler_error('Agent still unresponsive after reboot')
|
22
22
|
rescue Bosh::Director::TaskCancelled
|
@@ -24,47 +24,36 @@ module Bosh::Director
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
def delete_vm(
|
27
|
+
def delete_vm(instance)
|
28
28
|
# Paranoia: don't blindly delete VMs with persistent disk
|
29
|
-
disk_list = agent_timeout_guard(
|
29
|
+
disk_list = agent_timeout_guard(instance.vm_cid, instance.credentials, instance.agent_id) { |agent| agent.list_disk }
|
30
30
|
if disk_list.size != 0
|
31
31
|
handler_error('VM has persistent disk attached')
|
32
32
|
end
|
33
33
|
|
34
|
-
vm_deleter.
|
34
|
+
vm_deleter.delete_for_instance(instance)
|
35
35
|
end
|
36
36
|
|
37
|
-
def delete_vm_reference(
|
38
|
-
|
39
|
-
handler_error('VM has a CID')
|
40
|
-
end
|
41
|
-
|
42
|
-
vm.destroy
|
37
|
+
def delete_vm_reference(instance)
|
38
|
+
instance.update(vm_cid: nil, agent_id: nil, trusted_certs_sha1: nil, credentials: nil)
|
43
39
|
end
|
44
40
|
|
45
|
-
def recreate_vm(
|
46
|
-
@logger.debug("Recreating Vm: #{
|
47
|
-
|
48
|
-
handler_error('VM does not have an associated instance')
|
49
|
-
end
|
50
|
-
instance_model = vm.instance
|
51
|
-
vm_env = vm.env
|
41
|
+
def recreate_vm(instance)
|
42
|
+
@logger.debug("Recreating Vm: #{@instance})")
|
43
|
+
existing_vm_env = instance.vm_env
|
52
44
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
validate_spec(vm.instance.spec)
|
57
|
-
validate_env(vm.env)
|
45
|
+
validate_spec(instance.spec)
|
46
|
+
validate_env(instance.vm_env)
|
58
47
|
|
59
48
|
instance_plan_to_delete = DeploymentPlan::InstancePlan.new(
|
60
|
-
existing_instance:
|
49
|
+
existing_instance: instance,
|
61
50
|
instance: nil,
|
62
51
|
desired_instance: nil,
|
63
52
|
network_plans: []
|
64
53
|
)
|
65
54
|
|
66
55
|
begin
|
67
|
-
vm_deleter.
|
56
|
+
vm_deleter.delete_for_instance(instance_plan_to_delete.existing_instance)
|
68
57
|
rescue Bosh::Clouds::VMNotFound
|
69
58
|
# One situation where this handler is actually useful is when
|
70
59
|
# VM has already been deleted but something failed after that
|
@@ -72,32 +61,32 @@ module Bosh::Director
|
|
72
61
|
# to ignore "VM not found" errors in `delete_vm' and let the method
|
73
62
|
# proceed creating a new VM. Other errors are not forgiven.
|
74
63
|
|
75
|
-
@logger.warn("VM '#{
|
64
|
+
@logger.warn("VM '#{instance.vm_cid}' might have already been deleted from the cloud")
|
76
65
|
end
|
77
66
|
|
78
|
-
instance_plan_to_create = create_instance_plan(
|
67
|
+
instance_plan_to_create = create_instance_plan(instance, existing_vm_env)
|
79
68
|
|
80
69
|
vm_creator.create_for_instance_plan(
|
81
70
|
instance_plan_to_create,
|
82
|
-
Array(
|
71
|
+
Array(instance.persistent_disk_cid)
|
83
72
|
)
|
84
73
|
|
85
|
-
dns_manager =
|
74
|
+
dns_manager = DnsManagerProvider.create
|
86
75
|
dns_names_to_ip = {}
|
87
76
|
|
88
77
|
instance_plan_to_create.existing_instance.spec['networks'].each do |network_name, network|
|
89
|
-
index_dns_name = dns_manager.dns_record_name(
|
78
|
+
index_dns_name = dns_manager.dns_record_name(instance.index, instance.job, network_name, instance.deployment.name)
|
90
79
|
dns_names_to_ip[index_dns_name] = network['ip']
|
91
|
-
id_dns_name = dns_manager.dns_record_name(
|
80
|
+
id_dns_name = dns_manager.dns_record_name(instance.uuid, instance.job, network_name, instance.deployment.name)
|
92
81
|
dns_names_to_ip[id_dns_name] = network['ip']
|
93
82
|
end
|
94
83
|
|
95
|
-
@logger.debug("Updating DNS record for instance: #{
|
96
|
-
dns_manager.update_dns_record_for_instance(
|
84
|
+
@logger.debug("Updating DNS record for instance: #{instance.inspect}; to: #{dns_names_to_ip.inspect}")
|
85
|
+
dns_manager.update_dns_record_for_instance(instance, dns_names_to_ip)
|
97
86
|
dns_manager.flush_dns_cache
|
98
87
|
|
99
|
-
cleaner = RenderedJobTemplatesCleaner.new(
|
100
|
-
InstanceUpdater::StateApplier.new(instance_plan_to_create, agent_client(
|
88
|
+
cleaner = RenderedJobTemplatesCleaner.new(instance, App.instance.blobstores.blobstore, @logger)
|
89
|
+
InstanceUpdater::StateApplier.new(instance_plan_to_create, agent_client(instance.credentials, instance.agent_id), cleaner, @logger).apply
|
101
90
|
end
|
102
91
|
|
103
92
|
private
|
@@ -140,28 +129,19 @@ module Bosh::Director
|
|
140
129
|
raise Bosh::Director::ProblemHandlerError, message
|
141
130
|
end
|
142
131
|
|
143
|
-
def
|
144
|
-
instance = vm.instance
|
145
|
-
return "Unknown VM" if instance.nil?
|
146
|
-
|
147
|
-
job = instance.job || "unknown job"
|
148
|
-
index = instance.index || "unknown index"
|
149
|
-
"#{job}/#{index}"
|
150
|
-
end
|
151
|
-
|
152
|
-
def agent_client(vm, timeout = DEFAULT_AGENT_TIMEOUT, retries = 0)
|
132
|
+
def agent_client(vm_credentials, agent_id, timeout = DEFAULT_AGENT_TIMEOUT, retries = 0)
|
153
133
|
options = {
|
154
134
|
:timeout => timeout,
|
155
135
|
:retry_methods => { :get_state => retries }
|
156
136
|
}
|
157
137
|
@clients ||= {}
|
158
|
-
@clients[
|
138
|
+
@clients[agent_id] ||= AgentClient.with_vm_credentials_and_agent_id(vm_credentials, agent_id, options)
|
159
139
|
end
|
160
140
|
|
161
|
-
def agent_timeout_guard(
|
162
|
-
yield agent_client(
|
141
|
+
def agent_timeout_guard(vm_cid, vm_credentials, agent_id, &block)
|
142
|
+
yield agent_client(vm_credentials, agent_id)
|
163
143
|
rescue Bosh::Director::RpcTimeout
|
164
|
-
handler_error("VM `#{
|
144
|
+
handler_error("VM `#{vm_cid}' is not responding")
|
165
145
|
end
|
166
146
|
|
167
147
|
def vm_deleter
|
@@ -183,8 +163,6 @@ module Bosh::Director
|
|
183
163
|
end
|
184
164
|
|
185
165
|
def validate_env(env)
|
186
|
-
handler_error('Unable to look up VM environment') unless env
|
187
|
-
|
188
166
|
unless env.kind_of?(Hash)
|
189
167
|
handler_error('Invalid VM environment format')
|
190
168
|
end
|
data/lib/bosh/director/config.rb
CHANGED
@@ -13,6 +13,7 @@ module Bosh::Director
|
|
13
13
|
:db,
|
14
14
|
:dns,
|
15
15
|
:dns_db,
|
16
|
+
# @todo @for-a-refactorer according to grep of "Config.dns_domain_name" I'm pretty sure this can be removed
|
16
17
|
:dns_domain_name,
|
17
18
|
:event_log,
|
18
19
|
:logger,
|
@@ -149,7 +150,7 @@ module Bosh::Director
|
|
149
150
|
end
|
150
151
|
end
|
151
152
|
|
152
|
-
@dns_manager =
|
153
|
+
@dns_manager = DnsManagerProvider.create
|
153
154
|
@uuid = override_uuid || Bosh::Director::Models::DirectorAttribute.find_or_create_uuid(@logger)
|
154
155
|
@logger.info("Director UUID: #{@uuid}")
|
155
156
|
|
@@ -19,10 +19,6 @@ module Bosh::Director
|
|
19
19
|
event_log_stage = @event_log.begin_stage('Deleting instances', instance_plans.size)
|
20
20
|
instance_deleter.delete_instance_plans(instance_plans, event_log_stage, max_threads: @max_threads)
|
21
21
|
|
22
|
-
# For backwards compatibility for VMs that did not have instances
|
23
|
-
deployment_model.reload
|
24
|
-
delete_vms(vm_deleter, deployment_model.vms)
|
25
|
-
|
26
22
|
@event_log.begin_stage('Removing deployment artifacts', 3)
|
27
23
|
|
28
24
|
@event_log.track('Detaching stemcells') do
|
@@ -48,22 +44,5 @@ module Bosh::Director
|
|
48
44
|
deployment_model.destroy
|
49
45
|
end
|
50
46
|
end
|
51
|
-
|
52
|
-
private
|
53
|
-
|
54
|
-
def delete_vms(vm_deleter, vms)
|
55
|
-
ThreadPool.new(max_threads: @max_threads).wrap do |pool|
|
56
|
-
@event_log.begin_stage('Deleting idle VMs', vms.count)
|
57
|
-
|
58
|
-
vms.each do |vm|
|
59
|
-
pool.process do
|
60
|
-
@event_log.track("#{vm.cid}") do
|
61
|
-
@logger.info("Deleting idle vm #{vm.cid}")
|
62
|
-
vm_deleter.delete_vm(vm)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
47
|
end
|
69
48
|
end
|
@@ -5,7 +5,6 @@ end
|
|
5
5
|
|
6
6
|
require 'bosh/director/deployment_plan/availability_zone'
|
7
7
|
require 'bosh/director/deployment_plan/compilation_config'
|
8
|
-
require 'bosh/director/deployment_plan/vm'
|
9
8
|
require 'bosh/director/deployment_plan/desired_instance'
|
10
9
|
require 'bosh/director/deployment_plan/deployment_validator'
|
11
10
|
require 'bosh/director/deployment_plan/instance'
|
@@ -56,6 +55,7 @@ require 'bosh/director/deployment_plan/job_migrator'
|
|
56
55
|
require 'bosh/director/deployment_plan/instance_plan_sorter'
|
57
56
|
require 'bosh/director/deployment_plan/instance_plan_factory'
|
58
57
|
require 'bosh/director/deployment_plan/instance_repository'
|
58
|
+
require 'bosh/director/deployment_plan/network_reservation_repository'
|
59
59
|
require 'bosh/director/deployment_plan/job_network_parser'
|
60
60
|
require 'bosh/director/deployment_plan/job_availability_zone_parser'
|
61
61
|
require 'bosh/director/deployment_plan/placement_planner'
|
@@ -6,13 +6,13 @@ module Bosh::Director
|
|
6
6
|
@logger = logger
|
7
7
|
end
|
8
8
|
|
9
|
-
def get_state(
|
10
|
-
@logger.debug("Requesting current VM state for: #{
|
11
|
-
agent = AgentClient.with_vm_credentials_and_agent_id(
|
9
|
+
def get_state(instance)
|
10
|
+
@logger.debug("Requesting current VM state for: #{instance.agent_id}")
|
11
|
+
agent = AgentClient.with_vm_credentials_and_agent_id(instance.credentials, instance.agent_id)
|
12
12
|
state = agent.get_state
|
13
13
|
|
14
14
|
@logger.debug("Received VM state: #{state.pretty_inspect}")
|
15
|
-
verify_state(
|
15
|
+
verify_state(instance, state)
|
16
16
|
@logger.debug('Verified VM state')
|
17
17
|
|
18
18
|
state.delete('release')
|
@@ -22,25 +22,13 @@ module Bosh::Director
|
|
22
22
|
state
|
23
23
|
end
|
24
24
|
|
25
|
-
def verify_state(
|
26
|
-
instance = vm_model.instance
|
27
|
-
|
25
|
+
def verify_state(instance, state)
|
28
26
|
unless state.kind_of?(Hash)
|
29
|
-
@logger.error("Invalid state for `#{
|
27
|
+
@logger.error("Invalid state for `#{instance.vm_cid}': #{state.pretty_inspect}")
|
30
28
|
raise AgentInvalidStateFormat,
|
31
|
-
"VM `#{
|
29
|
+
"VM `#{instance.vm_cid}' returns invalid state: " +
|
32
30
|
"expected Hash, got #{state.class}"
|
33
31
|
end
|
34
|
-
|
35
|
-
actual_job = state['job'].is_a?(Hash) ? state['job']['name'] : nil
|
36
|
-
actual_index = state['index']
|
37
|
-
|
38
|
-
if instance.nil? && !actual_job.nil?
|
39
|
-
raise AgentUnexpectedJob,
|
40
|
-
"VM `#{vm_model.cid}' is out of sync: " +
|
41
|
-
"it reports itself as `#{actual_job}/#{actual_index}' but " +
|
42
|
-
'there is no instance reference in DB'
|
43
|
-
end
|
44
32
|
end
|
45
33
|
end
|
46
34
|
end
|
@@ -18,11 +18,11 @@ module Bosh::Director
|
|
18
18
|
bind_releases
|
19
19
|
|
20
20
|
migrate_legacy_dns_records
|
21
|
-
|
22
|
-
instance_repo = Bosh::Director::DeploymentPlan::InstanceRepository.new(@logger)
|
21
|
+
network_reservation_repository = Bosh::Director::DeploymentPlan::NetworkReservationRepository.new(@deployment_plan, @logger)
|
22
|
+
instance_repo = Bosh::Director::DeploymentPlan::InstanceRepository.new(network_reservation_repository, @logger)
|
23
23
|
states_by_existing_instance = current_states_by_instance(@deployment_plan.candidate_existing_instances)
|
24
24
|
index_assigner = Bosh::Director::DeploymentPlan::PlacementPlanner::IndexAssigner.new(@deployment_plan.model)
|
25
|
-
instance_plan_factory = Bosh::Director::DeploymentPlan::InstancePlanFactory.new(instance_repo, states_by_existing_instance, @deployment_plan.skip_drain, index_assigner, {'recreate' => @deployment_plan.recreate})
|
25
|
+
instance_plan_factory = Bosh::Director::DeploymentPlan::InstancePlanFactory.new(instance_repo, states_by_existing_instance, @deployment_plan.skip_drain, index_assigner, network_reservation_repository, {'recreate' => @deployment_plan.recreate})
|
26
26
|
instance_planner = Bosh::Director::DeploymentPlan::InstancePlanner.new(instance_plan_factory, @logger)
|
27
27
|
desired_jobs = @deployment_plan.jobs
|
28
28
|
|
@@ -38,12 +38,9 @@ module Bosh::Director
|
|
38
38
|
instance_plans_for_obsolete_jobs = instance_planner.plan_obsolete_jobs(desired_jobs, @deployment_plan.existing_instances)
|
39
39
|
instance_plans_for_obsolete_jobs.map(&:existing_instance).each { |existing_instance| @deployment_plan.mark_instance_for_deletion(existing_instance) }
|
40
40
|
|
41
|
-
mark_unknown_vms_for_deletion
|
42
|
-
|
43
41
|
bind_stemcells
|
44
42
|
bind_templates
|
45
43
|
bind_properties
|
46
|
-
bind_unallocated_vms
|
47
44
|
bind_instance_networks
|
48
45
|
bind_dns
|
49
46
|
bind_links
|
@@ -67,11 +64,11 @@ module Bosh::Director
|
|
67
64
|
current_states_by_existing_instance = {}
|
68
65
|
ThreadPool.new(:max_threads => Config.max_threads).wrap do |pool|
|
69
66
|
existing_instances.each do |existing_instance|
|
70
|
-
if existing_instance.
|
67
|
+
if existing_instance.vm_cid
|
71
68
|
pool.process do
|
72
|
-
with_thread_name("binding agent state for (#{existing_instance
|
69
|
+
with_thread_name("binding agent state for (#{existing_instance}") do
|
73
70
|
# getting current state to obtain IP of dynamic networks
|
74
|
-
state = DeploymentPlan::AgentStateMigrator.new(@deployment_plan, @logger).get_state(existing_instance
|
71
|
+
state = DeploymentPlan::AgentStateMigrator.new(@deployment_plan, @logger).get_state(existing_instance)
|
75
72
|
lock.synchronize do
|
76
73
|
current_states_by_existing_instance.merge!(existing_instance => state)
|
77
74
|
end
|
@@ -83,27 +80,6 @@ module Bosh::Director
|
|
83
80
|
current_states_by_existing_instance
|
84
81
|
end
|
85
82
|
|
86
|
-
def mark_unknown_vms_for_deletion
|
87
|
-
@deployment_plan.vm_models.select { |vm| vm.instance.nil? }.each do |vm_model|
|
88
|
-
# VM without an instance should not exist any more. But we still
|
89
|
-
# delete those VMs for backwards compatibility in case if it was ever
|
90
|
-
# created incorrectly.
|
91
|
-
# It also means that it was created before global networking
|
92
|
-
# and should not have any network reservations in DB,
|
93
|
-
# so we don't worry about releasing its IPs.
|
94
|
-
@logger.debug('Marking VM for deletion')
|
95
|
-
@deployment_plan.mark_vm_for_deletion(vm_model)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
# Looks at every job instance in the deployment plan and binds it to the
|
100
|
-
# instance database model (idle VM is also created in the appropriate
|
101
|
-
# resource pool if necessary)
|
102
|
-
# @return [void]
|
103
|
-
def bind_unallocated_vms
|
104
|
-
@deployment_plan.jobs_starting_on_deploy.each(&:bind_unallocated_vms)
|
105
|
-
end
|
106
|
-
|
107
83
|
def bind_instance_networks
|
108
84
|
# CHANGEME: something about instance plan's new network plans
|
109
85
|
@deployment_plan.jobs_starting_on_deploy.each do |job|
|