bosh-director 1.2200.0 → 1.2291.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -71,6 +71,8 @@ require 'bosh/director/duration'
71
71
  require 'bosh/director/hash_string_vals'
72
72
  require 'bosh/director/instance_deleter'
73
73
  require 'bosh/director/instance_updater'
74
+ require 'bosh/director/instance_updater/preparer'
75
+ require 'bosh/director/instance_updater/network_updater'
74
76
  require 'bosh/director/job_runner'
75
77
  require 'bosh/director/job_updater'
76
78
  require 'bosh/director/job_queue'
@@ -8,9 +8,16 @@ module Bosh::Director
8
8
 
9
9
  def self.with_defaults(id, options = {})
10
10
  defaults = {
11
- retry_methods: { # in case of timeout errors
12
- get_state: 2,
13
- get_task: 2,
11
+ retry_methods: {
12
+ # in case of timeout errors
13
+ get_state: 2,
14
+
15
+ # get_task should retry at least once because some long running tasks
16
+ # (e.g. configure_networks) will restart the agent (current implementation)
17
+ # which most likely will result in first get_task message being lost
18
+ # because agent was not listening on NATS and second retry message
19
+ # will probably be received because agent came back up.
20
+ get_task: 2,
14
21
  }
15
22
  }
16
23
 
@@ -40,8 +47,17 @@ module Bosh::Director
40
47
  send_message(method_name, *args)
41
48
  end
42
49
 
43
- def get_state(*args)
44
- send_message(:get_state, *args)
50
+ # Define methods on this class to make instance_double more useful
51
+ [
52
+ :start,
53
+ :get_state,
54
+ :list_disk,
55
+ :prepare_network_change,
56
+ :prepare_configure_networks,
57
+ ].each do |message|
58
+ define_method(message) do |*args|
59
+ send_message(message, *args)
60
+ end
45
61
  end
46
62
 
47
63
  def prepare(*args)
@@ -84,6 +100,10 @@ module Bosh::Director
84
100
  send_long_running_message(:run_errand, *args)
85
101
  end
86
102
 
103
+ def configure_networks(*args)
104
+ send_long_running_message(:configure_networks, *args)
105
+ end
106
+
87
107
  def wait_until_ready(deadline = 600)
88
108
  old_timeout = @timeout
89
109
  @timeout = 1.0
@@ -216,9 +216,13 @@ module Bosh::Director
216
216
  "Invalid state `#{@job.state}' for `#{@job.name}', valid states are: #{Job::VALID_JOB_STATES.join(", ")}"
217
217
  end
218
218
 
219
+ if @job.lifecycle == 'errand'
220
+ @job.resource_pool.reserve_errand_capacity(job_size)
221
+ else
222
+ @job.resource_pool.reserve_capacity(job_size)
223
+ end
219
224
  job_size.times do |index|
220
225
  @job.instances[index] = Instance.new(@job, index)
221
- @job.resource_pool.reserve_capacity(1)
222
226
  end
223
227
  end
224
228
 
@@ -64,6 +64,7 @@ module Bosh::Director
64
64
  @allocated_vms = []
65
65
  @active_vm_count = 0
66
66
  @required_capacity = 0
67
+ @errand_capacity = 0
67
68
  end
68
69
 
69
70
  # Returns resource pools spec as Hash (usually for agent to serialize)
@@ -138,6 +139,15 @@ module Bosh::Director
138
139
  "#{@required_capacity} VMs needed, capacity is #{@size}"
139
140
  end
140
141
  end
142
+
143
+ def reserve_errand_capacity(n)
144
+ needed = n - @errand_capacity
145
+
146
+ if needed > 0
147
+ reserve_capacity(needed)
148
+ @errand_capacity = n
149
+ end
150
+ end
141
151
  end
142
152
  end
143
- end
153
+ end
@@ -1,4 +1,3 @@
1
- require 'bosh/director/instance_preparer'
2
1
  require 'bosh/director/rendered_job_templates_cleaner'
3
2
 
4
3
  module Bosh::Director
@@ -30,6 +29,8 @@ module Bosh::Director
30
29
  @vm = @instance.model.vm
31
30
 
32
31
  @current_state = {}
32
+
33
+ @network_updater = NetworkUpdater.new(@instance, @vm, agent, self, @cloud, @logger)
33
34
  end
34
35
 
35
36
  def instance_name
@@ -60,7 +61,7 @@ module Bosh::Director
60
61
  return
61
62
  end
62
63
 
63
- step { InstancePreparer.new(@instance, agent).prepare }
64
+ step { Preparer.new(@instance, agent).prepare }
64
65
  step { stop }
65
66
  step { take_snapshot }
66
67
 
@@ -428,32 +429,7 @@ module Bosh::Director
428
429
  end
429
430
 
430
431
  def update_networks
431
- return unless @instance.networks_changed?
432
-
433
- network_settings = @instance.network_settings
434
-
435
- begin
436
- # If configure_networks can't configure the network as
437
- # requested, e.g. when the security groups change on AWS,
438
- # configure_networks() will raise an exception and we'll
439
- # recreate the VM to work around it
440
- @cloud.configure_networks(@vm.cid, network_settings)
441
- rescue Bosh::Clouds::NotSupported => e
442
- @logger.info("configure_networks not supported: #{e.message}")
443
- @instance.recreate = true
444
- update_resource_pool
445
- return
446
- end
447
-
448
- # Once CPI has configured the vm and stored the new network settings at the registry,
449
- # we restart the agent via a 'prepare_network_change' message in order for the agent
450
- # to pick up the new network settings.
451
- agent.prepare_network_change(network_settings)
452
-
453
- # Give some time to the agent to restart before pinging if it's ready (race condition)
454
- sleep(5)
455
-
456
- agent.wait_until_ready
432
+ @network_updater.update
457
433
  end
458
434
 
459
435
  def agent
@@ -0,0 +1,110 @@
1
+ module Bosh::Director
2
+ class InstanceUpdater::NetworkUpdater
3
+ def initialize(instance, vm_model, agent_client, resource_pool_updater, cloud, logger)
4
+ @instance = instance
5
+ @vm_model = vm_model
6
+ @agent_client = agent_client
7
+ @resource_pool_updater = resource_pool_updater
8
+ @cloud = cloud
9
+ @logger = logger
10
+ end
11
+
12
+ def update
13
+ unless @instance.networks_changed?
14
+ @logger.info('Skipping network re-configuration')
15
+ return
16
+ end
17
+
18
+ network_settings = @instance.network_settings
19
+ @logger.info("Planning to reconfigure network with settings: #{network_settings}")
20
+
21
+ strategies = [
22
+ ConfigureNetworksStrategy.new(@agent_client, network_settings, @logger),
23
+ PrepareNetworkChangeStrategy.new(@agent_client, network_settings, @logger),
24
+ ]
25
+
26
+ selected_strategy = strategies.find { |s| s.before_configure_networks }
27
+
28
+ @cloud.configure_networks(@vm_model.cid, network_settings)
29
+
30
+ selected_strategy.after_configure_networks
31
+
32
+ rescue Bosh::Clouds::NotSupported => e
33
+ # If configure_networks can't configure the network as
34
+ # requested, e.g. when the security groups change on AWS,
35
+ # configure_networks() will raise an exception and we'll
36
+ # recreate the VM to work around it
37
+ @logger.info("configure_networks CPI call failed with error: #{e.inspect}")
38
+ configure_new_vm
39
+ end
40
+
41
+ private
42
+
43
+ def configure_new_vm
44
+ @logger.info('Creating VM with new network configurations')
45
+ @instance.recreate = true
46
+ @resource_pool_updater.update_resource_pool
47
+ end
48
+
49
+ # Newer agents support prepare_configure_networks/configure_networks messages
50
+ class ConfigureNetworksStrategy
51
+ def initialize(agent_client, network_settings, logger)
52
+ @agent_client = agent_client
53
+ @network_settings = network_settings
54
+ @logger = logger
55
+ end
56
+
57
+ def before_configure_networks
58
+ @agent_client.prepare_configure_networks(@network_settings)
59
+ true
60
+ rescue RpcRemoteException => e
61
+ @logger.info("Agent returned error from prepare_configure_networks: #{e.inspect}")
62
+ raise unless e.message =~ /unknown message/
63
+ false
64
+ end
65
+
66
+ def after_configure_networks
67
+ # Some CPIs might power off and then power on vm to reconfigure network adapters,
68
+ # so Director needs to wait for agent to become responsive
69
+ @logger.info('Waiting for agent to become responsive')
70
+ @agent_client.wait_until_ready
71
+
72
+ @agent_client.configure_networks(@network_settings)
73
+ end
74
+ end
75
+
76
+ # Older agents only support prepare_network_change
77
+ class PrepareNetworkChangeStrategy
78
+ def initialize(agent_client, network_settings, logger)
79
+ @agent_client = agent_client
80
+ @network_settings = network_settings
81
+ @logger = logger
82
+ end
83
+
84
+ def before_configure_networks
85
+ true
86
+ end
87
+
88
+ def after_configure_networks
89
+ # Some CPIs might power off and then power on vm to reconfigure network adapters,
90
+ # so Director needs to wait for agent to become responsive
91
+ @logger.info('Waiting for agent to become responsive')
92
+ @agent_client.wait_until_ready
93
+
94
+ # Once CPI has configured the vm and stored the new network settings at the registry,
95
+ # we restart the agent via a 'prepare_network_change' message in order for the agent
96
+ # to pick up the new network settings.
97
+ @agent_client.prepare_network_change(@network_settings)
98
+
99
+ # Since current implementation of prepare_network_change is to kill the agent
100
+ # we need to wait until the agent is ready. However, we want to avoid
101
+ # talking to the old agent, so we need to wait for it to die.
102
+ @logger.info('Sleeping after prepare_network_change message')
103
+ sleep(5)
104
+
105
+ @logger.info('Waiting for agent to become responsive')
106
+ @agent_client.wait_until_ready
107
+ end
108
+ end
109
+ end
110
+ end
@@ -1,7 +1,5 @@
1
- require 'bosh/director'
2
-
3
1
  module Bosh::Director
4
- class InstancePreparer
2
+ class InstanceUpdater::Preparer
5
3
  def initialize(instance, agent_client)
6
4
  @instance = instance
7
5
  @agent_client = agent_client
@@ -10,7 +8,7 @@ module Bosh::Director
10
8
  def prepare
11
9
  @agent_client.prepare(@instance.spec) unless detached?
12
10
  rescue RpcRemoteException => e
13
- raise unless e.message =~/unknown message/
11
+ raise unless e.message =~ /unknown message/
14
12
  end
15
13
 
16
14
  private
@@ -1,5 +1,5 @@
1
1
  module Bosh
2
2
  module Director
3
- VERSION = '1.2200.0'
3
+ VERSION = '1.2291.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bosh-director
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2200.0
4
+ version: 1.2291.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-14 00:00:00.000000000 Z
12
+ date: 2014-03-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bcrypt-ruby
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: 1.2200.0
37
+ version: 1.2291.0
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: 1.2200.0
45
+ version: 1.2291.0
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: bosh-core
48
48
  requirement: !ruby/object:Gem::Requirement
@@ -50,7 +50,7 @@ dependencies:
50
50
  requirements:
51
51
  - - ~>
52
52
  - !ruby/object:Gem::Version
53
- version: 1.2200.0
53
+ version: 1.2291.0
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
@@ -58,7 +58,7 @@ dependencies:
58
58
  requirements:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: 1.2200.0
61
+ version: 1.2291.0
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: bosh-director-core
64
64
  requirement: !ruby/object:Gem::Requirement
@@ -66,7 +66,7 @@ dependencies:
66
66
  requirements:
67
67
  - - ~>
68
68
  - !ruby/object:Gem::Version
69
- version: 1.2200.0
69
+ version: 1.2291.0
70
70
  type: :runtime
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
@@ -74,7 +74,7 @@ dependencies:
74
74
  requirements:
75
75
  - - ~>
76
76
  - !ruby/object:Gem::Version
77
- version: 1.2200.0
77
+ version: 1.2291.0
78
78
  - !ruby/object:Gem::Dependency
79
79
  name: bosh_common
80
80
  requirement: !ruby/object:Gem::Requirement
@@ -82,7 +82,7 @@ dependencies:
82
82
  requirements:
83
83
  - - ~>
84
84
  - !ruby/object:Gem::Version
85
- version: 1.2200.0
85
+ version: 1.2291.0
86
86
  type: :runtime
87
87
  prerelease: false
88
88
  version_requirements: !ruby/object:Gem::Requirement
@@ -90,7 +90,7 @@ dependencies:
90
90
  requirements:
91
91
  - - ~>
92
92
  - !ruby/object:Gem::Version
93
- version: 1.2200.0
93
+ version: 1.2291.0
94
94
  - !ruby/object:Gem::Dependency
95
95
  name: bosh_cpi
96
96
  requirement: !ruby/object:Gem::Requirement
@@ -98,7 +98,7 @@ dependencies:
98
98
  requirements:
99
99
  - - ~>
100
100
  - !ruby/object:Gem::Version
101
- version: 1.2200.0
101
+ version: 1.2291.0
102
102
  type: :runtime
103
103
  prerelease: false
104
104
  version_requirements: !ruby/object:Gem::Requirement
@@ -106,7 +106,7 @@ dependencies:
106
106
  requirements:
107
107
  - - ~>
108
108
  - !ruby/object:Gem::Version
109
- version: 1.2200.0
109
+ version: 1.2291.0
110
110
  - !ruby/object:Gem::Dependency
111
111
  name: bosh_openstack_cpi
112
112
  requirement: !ruby/object:Gem::Requirement
@@ -114,7 +114,7 @@ dependencies:
114
114
  requirements:
115
115
  - - ~>
116
116
  - !ruby/object:Gem::Version
117
- version: 1.2200.0
117
+ version: 1.2291.0
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
@@ -122,7 +122,7 @@ dependencies:
122
122
  requirements:
123
123
  - - ~>
124
124
  - !ruby/object:Gem::Version
125
- version: 1.2200.0
125
+ version: 1.2291.0
126
126
  - !ruby/object:Gem::Dependency
127
127
  name: bosh_aws_cpi
128
128
  requirement: !ruby/object:Gem::Requirement
@@ -130,7 +130,7 @@ dependencies:
130
130
  requirements:
131
131
  - - ~>
132
132
  - !ruby/object:Gem::Version
133
- version: 1.2200.0
133
+ version: 1.2291.0
134
134
  type: :runtime
135
135
  prerelease: false
136
136
  version_requirements: !ruby/object:Gem::Requirement
@@ -138,7 +138,7 @@ dependencies:
138
138
  requirements:
139
139
  - - ~>
140
140
  - !ruby/object:Gem::Version
141
- version: 1.2200.0
141
+ version: 1.2291.0
142
142
  - !ruby/object:Gem::Dependency
143
143
  name: bosh_vsphere_cpi
144
144
  requirement: !ruby/object:Gem::Requirement
@@ -146,7 +146,7 @@ dependencies:
146
146
  requirements:
147
147
  - - ~>
148
148
  - !ruby/object:Gem::Version
149
- version: 1.2200.0
149
+ version: 1.2291.0
150
150
  type: :runtime
151
151
  prerelease: false
152
152
  version_requirements: !ruby/object:Gem::Requirement
@@ -154,7 +154,7 @@ dependencies:
154
154
  requirements:
155
155
  - - ~>
156
156
  - !ruby/object:Gem::Version
157
- version: 1.2200.0
157
+ version: 1.2291.0
158
158
  - !ruby/object:Gem::Dependency
159
159
  name: bosh_vcloud_cpi
160
160
  requirement: !ruby/object:Gem::Requirement
@@ -493,7 +493,7 @@ dependencies:
493
493
  version: '1.0'
494
494
  description: ! 'BOSH Director
495
495
 
496
- 87cbf9'
496
+ 51a1bb'
497
497
  email: support@cloudfoundry.com
498
498
  executables:
499
499
  - bosh-director
@@ -636,8 +636,9 @@ files:
636
636
  - lib/bosh/director/ext.rb
637
637
  - lib/bosh/director/hash_string_vals.rb
638
638
  - lib/bosh/director/instance_deleter.rb
639
- - lib/bosh/director/instance_preparer.rb
640
639
  - lib/bosh/director/instance_updater.rb
640
+ - lib/bosh/director/instance_updater/network_updater.rb
641
+ - lib/bosh/director/instance_updater/preparer.rb
641
642
  - lib/bosh/director/ip_util.rb
642
643
  - lib/bosh/director/job_queue.rb
643
644
  - lib/bosh/director/job_renderer.rb
@@ -747,7 +748,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
747
748
  version: '0'
748
749
  segments:
749
750
  - 0
750
- hash: 1821926484481455025
751
+ hash: -4364815964196896981
751
752
  requirements: []
752
753
  rubyforge_project:
753
754
  rubygems_version: 1.8.23