bosh-director 1.2411.0 → 1.2416.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -49,11 +49,13 @@ module Bosh::Director
49
49
 
50
50
  # Define methods on this class to make instance_double more useful
51
51
  [
52
- :start,
52
+ :cancel_task,
53
53
  :get_state,
54
+ :get_task,
54
55
  :list_disk,
55
56
  :prepare_network_change,
56
57
  :prepare_configure_networks,
58
+ :start,
57
59
  ].each do |message|
58
60
  define_method(message) do |*args|
59
61
  send_message(message, *args)
@@ -96,8 +98,20 @@ module Bosh::Director
96
98
  send_long_running_message(:stop, *args)
97
99
  end
98
100
 
99
- def run_errand(*args)
100
- send_long_running_message(:run_errand, *args)
101
+ def start_errand(*args)
102
+ start_long_running_task(:run_errand, *args)
103
+ end
104
+
105
+ def wait_for_task(agent_task_id, &blk)
106
+ task = get_task_status(agent_task_id)
107
+
108
+ while task['state'] == 'running'
109
+ blk.call if block_given?
110
+ sleep(DEFAULT_POLL_INTERVAL)
111
+ task = get_task_status(agent_task_id)
112
+ end
113
+
114
+ task['value']
101
115
  end
102
116
 
103
117
  def configure_networks(*args)
@@ -235,13 +249,17 @@ module Bosh::Director
235
249
  end
236
250
  end
237
251
 
238
- def send_long_running_message(method_name, *args)
239
- task = AgentMessageConverter.convert_old_message_to_new(send_message(method_name, *args))
240
- while task['state'] == 'running'
241
- sleep(DEFAULT_POLL_INTERVAL)
242
- task = AgentMessageConverter.convert_old_message_to_new(get_task(task['agent_task_id']))
243
- end
244
- task['value']
252
+ def send_long_running_message(method_name, *args, &blk)
253
+ task = start_long_running_task(method_name, *args)
254
+ wait_for_task(task['agent_task_id'], &blk)
255
+ end
256
+
257
+ def start_long_running_task(method_name, *args)
258
+ AgentMessageConverter.convert_old_message_to_new(send_message(method_name, *args))
259
+ end
260
+
261
+ def get_task_status(agent_task_id)
262
+ AgentMessageConverter.convert_old_message_to_new(get_task(agent_task_id))
245
263
  end
246
264
  end
247
265
  end
@@ -45,12 +45,12 @@ module Bosh::Director
45
45
  @result_file = result_file
46
46
  @instance_manager = instance_manager
47
47
  @event_log = event_log
48
+ @agent_task_id = nil
48
49
  end
49
50
 
50
51
  # Runs errand on job instances
51
52
  # @return [String] short description of the errand result
52
- def run
53
- instance = @job.instances.first
53
+ def run(&blk)
54
54
  unless instance
55
55
  raise DirectorError, 'Must have at least one job instance to run an errand'
56
56
  end
@@ -58,22 +58,48 @@ module Bosh::Director
58
58
  agent_task_result = nil
59
59
 
60
60
  event_log_stage = @event_log.begin_stage('Running errand', 1)
61
- event_log_stage.advance_and_track("#{@job.name}/#{instance.index}") do
62
- agent = @instance_manager.agent_client_for(instance.model)
63
- agent_task_result = agent.run_errand
61
+ begin
62
+ event_log_stage.advance_and_track("#{@job.name}/#{instance.index}") do
63
+ start_errand_result = agent.start_errand
64
+ @agent_task_id = start_errand_result['agent_task_id']
65
+ agent_task_result = agent.wait_for_task(agent_task_id, &blk)
66
+ end
67
+ rescue TaskCancelled => e
68
+ agent_task_result = agent.wait_for_task(agent_task_id)
69
+ raise e
70
+ ensure
71
+ if agent_task_result
72
+ errand_result = ErrandResult.from_agent_task_result(agent_task_result)
73
+ @result_file.write(JSON.dump(errand_result.to_hash) + "\n")
74
+ end
64
75
  end
65
76
 
66
- errand_result = ErrandResult.from_agent_task_result(agent_task_result)
67
- @result_file.write(JSON.dump(errand_result.to_hash) + "\n")
68
-
69
- title_prefix = "Errand `#{@job.name}' completed"
77
+ title_prefix = "Errand `#{@job.name}'"
70
78
  exit_code_suffix = "(exit code #{errand_result.exit_code})"
71
79
 
72
80
  if errand_result.exit_code == 0
73
- "#{title_prefix} successfully #{exit_code_suffix}"
81
+ "#{title_prefix} completed successfully #{exit_code_suffix}"
82
+ elsif errand_result.exit_code > 128
83
+ "#{title_prefix} was canceled #{exit_code_suffix}"
74
84
  else
75
- "#{title_prefix} with error #{exit_code_suffix}"
85
+ "#{title_prefix} completed with error #{exit_code_suffix}"
76
86
  end
77
87
  end
88
+
89
+ def cancel
90
+ agent.cancel_task(agent_task_id) if agent_task_id
91
+ end
92
+
93
+ private
94
+
95
+ attr_reader :agent_task_id
96
+
97
+ def agent
98
+ @agent ||= @instance_manager.agent_client_for(instance.model)
99
+ end
100
+
101
+ def instance
102
+ @instance ||= @job.instances.first
103
+ end
78
104
  end
79
105
  end
@@ -28,7 +28,7 @@ module Bosh::Director
28
28
  def task_cancelled?
29
29
  return false if task_id.nil?
30
30
  task = task_manager.find_task(task_id)
31
- task && (task.state == "cancelling" || task.state == "timeout")
31
+ task && (task.state == 'cancelling' || task.state == 'timeout')
32
32
  end
33
33
 
34
34
  def task_checkpoint
@@ -32,7 +32,7 @@ module Bosh::Director
32
32
  unless job.can_run_as_errand?
33
33
  raise RunErrandError,
34
34
  "Job `#{job.name}' is not an errand. To mark a job as an errand " +
35
- "set its lifecycle to 'errand' in the deployment manifest."
35
+ "set its lifecycle to 'errand' in the deployment manifest."
36
36
  end
37
37
 
38
38
  if job.instances.empty?
@@ -43,35 +43,41 @@ module Bosh::Director
43
43
 
44
44
  with_updated_instances(deployment, job) do
45
45
  logger.info('Starting to run errand')
46
- runner.run
46
+
47
+ runner.run do
48
+ begin
49
+ task_checkpoint
50
+ rescue TaskCancelled => e
51
+ runner.cancel
52
+ raise e
53
+ end
54
+ end
47
55
  end
48
56
  end
49
57
 
50
58
  private
51
59
 
52
60
  def with_updated_instances(deployment, job, &blk)
53
- result = nil
54
-
55
61
  with_deployment_lock(deployment) do
56
- logger.info('Starting to prepare for deployment')
57
- prepare_deployment(deployment, job)
58
-
59
- logger.info('Starting to update resource pool')
60
- rp_manager = update_resource_pool(job)
62
+ begin
63
+ logger.info('Starting to prepare for deployment')
64
+ prepare_deployment(deployment, job)
61
65
 
62
- logger.info('Starting to update job instances')
63
- job_manager = update_instances(deployment, job)
66
+ logger.info('Starting to update resource pool')
67
+ rp_manager(job).update
64
68
 
65
- result = blk.call
69
+ logger.info('Starting to update job instances')
70
+ job_manager(deployment, job).update_instances
66
71
 
67
- logger.info('Starting to delete job instances')
68
- job_manager.delete_instances
72
+ blk.call
73
+ ensure
74
+ logger.info('Starting to delete job instances')
75
+ job_manager(deployment, job).delete_instances
69
76
 
70
- logger.info('Starting to refill resource pool')
71
- rp_manager.refill
77
+ logger.info('Starting to refill resource pool')
78
+ rp_manager(job).refill
79
+ end
72
80
  end
73
-
74
- result
75
81
  end
76
82
 
77
83
  def prepare_deployment(deployment, job)
@@ -82,20 +88,13 @@ module Bosh::Director
82
88
  deployment_preparer.prepare_job
83
89
  end
84
90
 
85
- def update_resource_pool(job)
91
+ def rp_manager(job)
86
92
  rp_updaters = [ResourcePoolUpdater.new(job.resource_pool)]
87
- rp_manager = DeploymentPlan::ResourcePools.new(event_log, rp_updaters)
88
-
89
- rp_manager.update
90
- rp_manager
93
+ DeploymentPlan::ResourcePools.new(event_log, rp_updaters)
91
94
  end
92
95
 
93
- def update_instances(deployment, job)
94
- job_manager = Errand::JobManager.new(
95
- deployment, job, @blobstore, event_log)
96
-
97
- job_manager.update_instances
98
- job_manager
96
+ def job_manager(deployment, job)
97
+ Errand::JobManager.new(deployment, job, @blobstore, event_log)
99
98
  end
100
99
  end
101
100
  end
@@ -1,5 +1,5 @@
1
1
  module Bosh
2
2
  module Director
3
- VERSION = '1.2411.0'
3
+ VERSION = '1.2416.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.2411.0
4
+ version: 1.2416.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-04-16 00:00:00.000000000 Z
12
+ date: 2014-04-17 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.2411.0
37
+ version: 1.2416.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.2411.0
45
+ version: 1.2416.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.2411.0
53
+ version: 1.2416.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.2411.0
61
+ version: 1.2416.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.2411.0
69
+ version: 1.2416.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.2411.0
77
+ version: 1.2416.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.2411.0
85
+ version: 1.2416.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.2411.0
93
+ version: 1.2416.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.2411.0
101
+ version: 1.2416.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.2411.0
109
+ version: 1.2416.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.2411.0
117
+ version: 1.2416.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.2411.0
125
+ version: 1.2416.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.2411.0
133
+ version: 1.2416.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.2411.0
141
+ version: 1.2416.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.2411.0
149
+ version: 1.2416.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.2411.0
157
+ version: 1.2416.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
- a126f7'
496
+ 7ca225'
497
497
  email: support@cloudfoundry.com
498
498
  executables:
499
499
  - bosh-director
@@ -749,7 +749,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
749
749
  version: '0'
750
750
  segments:
751
751
  - 0
752
- hash: 2845903689003096789
752
+ hash: -1414793112666498170
753
753
  requirements: []
754
754
  rubyforge_project:
755
755
  rubygems_version: 1.8.23