bosh-director 1.2743.0 → 1.2744.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 245617054defdaf1d59d62a2b911b652e0fe0bfd
4
- data.tar.gz: 4080e6dd55fee17cd7191966fdba543e23020657
3
+ metadata.gz: e4cee2bd6e3bb7adc796a8186393aa66fe2ee576
4
+ data.tar.gz: 445106e21d6cab923712ce39ba8361a281cdcf4c
5
5
  SHA512:
6
- metadata.gz: ee0ea8231bbf7a7c7424f774d6dee192daa0ec4bf0a04af82dfbb180abaed049b5942dbb6dfc7ed0db8c980528e7f7bd7cbef816686456acb46837a2aa198107
7
- data.tar.gz: 0a1291cad3c5c220f7c06d3ae4f7bc1fdf5125bb8a5d132b570803a2781c6993dc3197d11c3efa9706817ac17c77762357e3fe028f4f2ce5ec30d0e236bcce1e
6
+ metadata.gz: 95f7010920733b0a152213bdb828adf68bc37a0e2292ff9c475878a012864b8b60054d1ccc5688c7232058eaafca5dc4ec17f79d661b46f67111a5121585ddfd
7
+ data.tar.gz: 74911aeb27b67a599232fc92936961d8e4d54666888d246c3e03330b555cd50089159be5afc861a89e6bd917b42912d0fc8509bd4b824cc54d4af80dbca821d3
@@ -67,8 +67,14 @@ rescue Resque::NoQueueError
67
67
  end
68
68
 
69
69
  Resque.after_fork do
70
- EM.error_handler { |e| puts "Error raised during event loop: #{e.message}" }
71
- Thread.new { EM.run }
70
+ EM.error_handler { |e| puts "Error raised during event loop: #{e.inspect}, backtrace: #{e.backtrace}" }
71
+ Thread.new do
72
+ EM.run do
73
+ # connect to NATS on EM thread
74
+ # EM::connect will throw unbound errors if run from a different thread.
75
+ Bosh::Director::Config.nats
76
+ end
77
+ end
72
78
  end
73
79
 
74
80
  Resque::Failure.backend = Resque::Failure::Backtrace
@@ -273,6 +273,21 @@ module Bosh::Director
273
273
 
274
274
  redirect "/tasks/#{task.id}"
275
275
  end
276
+
277
+ get '/:deployment_name/errands' do
278
+ deployment = @deployment_manager.find_by_name(params[:deployment_name])
279
+
280
+ manifest = Psych.load(deployment.manifest)
281
+ deployment_plan = DeploymentPlan::Planner.parse(manifest, {}, Config.event_log, Config.logger)
282
+
283
+ errands = deployment_plan.jobs.select(&:can_run_as_errand?)
284
+
285
+ errand_data = errands.map do |errand|
286
+ { "name" => errand.name }
287
+ end
288
+
289
+ json_encode(errand_data)
290
+ end
276
291
  end
277
292
  end
278
293
  end
@@ -35,6 +35,7 @@ module Bosh::Director
35
35
  :fix_stateful_nodes,
36
36
  :enable_snapshots,
37
37
  :max_vm_create_tries,
38
+ :nats_uri,
38
39
  ]
39
40
 
40
41
  CONFIG_OPTIONS.each do |option|
@@ -226,19 +227,13 @@ module Bosh::Director
226
227
  end
227
228
  end
228
229
 
229
- def nats
230
- @lock.synchronize do
231
- if @nats.nil?
232
- @nats = NATS.connect(:uri => @nats_uri, :autostart => false)
233
- end
234
- end
235
- @nats
236
- end
237
-
238
230
  def nats_rpc
239
- @lock.synchronize do
240
- if @nats_rpc.nil?
241
- @nats_rpc = NatsRpc.new
231
+ # double-check locking to reduce synchronization
232
+ if @nats_rpc.nil?
233
+ @lock.synchronize do
234
+ if @nats_rpc.nil?
235
+ @nats_rpc = NatsRpc.new(@nats_uri)
236
+ end
242
237
  end
243
238
  end
244
239
  @nats_rpc
@@ -42,18 +42,14 @@ module Bosh::Director
42
42
  ERROR = 3
43
43
 
44
44
  def send_alert(instance, message)
45
- nats = Bosh::Director::Config.nats
46
- payload = Yajl::Encoder.encode(
47
- {
48
- "id" => 'director',
49
- "severity" => ERROR,
50
- "title" => "director - snapshot failure",
51
- "summary" => "failed to snapshot #{instance.job}/#{instance.index}: #{message}",
52
- "created_at" => Time.now.to_i
53
- }
54
- )
55
-
56
- nats.publish('hm.director.alert', payload)
45
+ payload = {
46
+ 'id' => 'director',
47
+ 'severity' => ERROR,
48
+ 'title' => 'director - snapshot failure',
49
+ 'summary' => "failed to snapshot #{instance.job}/#{instance.index}: #{message}",
50
+ 'created_at' => Time.now.to_i
51
+ }
52
+ Bosh::Director::Config.nats_rpc.send_message('hm.director.alert', payload)
57
53
  end
58
54
  end
59
55
  end
@@ -1,47 +1,46 @@
1
- # Copyright (c) 2009-2012 VMware, Inc.
2
-
3
1
  module Bosh::Director
2
+ # Remote procedure call client wrapping NATS
4
3
  class NatsRpc
5
4
 
6
- def initialize
7
- @nats = Config.nats
5
+ def initialize(nats_uri)
6
+ @nats_uri = nats_uri
8
7
  @logger = Config.logger
9
8
  @lock = Mutex.new
10
9
  @inbox_name = "director.#{Config.process_uuid}"
11
10
  @requests = {}
12
- subscribe_inbox
13
11
  end
14
12
 
15
- def subscribe_inbox
16
- @nats.subscribe("#{@inbox_name}.>") do |message, _, subject|
17
- @logger.debug("RECEIVED: #{subject} #{message}")
18
- begin
19
- request_id = subject.split(".").last
20
- callback = @lock.synchronize { @requests.delete(request_id) }
21
- if callback
22
- message = Yajl::Parser.new.parse(message)
23
- callback.call(message)
24
- end
25
- rescue Exception => e
26
- @logger.warn(e.message)
27
- end
13
+ # Returns a lazily connected NATS client
14
+ def nats
15
+ @nats ||= connect
16
+ end
17
+
18
+ # Publishes a payload (encoded as JSON) without expecting a response
19
+ def send_message(client, payload)
20
+ message = Yajl::Encoder.encode(request)
21
+ @logger.debug("SENT: #{client} #{message}")
22
+ EM.schedule do
23
+ nats.publish(client, payload)
28
24
  end
29
25
  end
30
26
 
31
- def send_request(client, request, &block)
27
+ # Sends a request (encoded as JSON) and listens for the response
28
+ def send_request(client, request, &callback)
32
29
  request_id = generate_request_id
33
30
  request["reply_to"] = "#{@inbox_name}.#{request_id}"
34
31
  @lock.synchronize do
35
- @requests[request_id] = block
32
+ @requests[request_id] = callback
36
33
  end
37
34
  message = Yajl::Encoder.encode(request)
38
35
  @logger.debug("SENT: #{client} #{message}")
39
- EM.next_tick do
40
- @nats.publish(client, message)
36
+ EM.schedule do
37
+ subscribe_inbox
38
+ nats.publish(client, message)
41
39
  end
42
40
  request_id
43
41
  end
44
42
 
43
+ # Stops listening for a response
45
44
  def cancel_request(request_id)
46
45
  @lock.synchronize { @requests.delete(request_id) }
47
46
  end
@@ -50,5 +49,49 @@ module Bosh::Director
50
49
  SecureRandom.uuid
51
50
  end
52
51
 
52
+ private
53
+
54
+ def connect
55
+ # double-check locking to reduce synchronization
56
+ if @nats.nil?
57
+ @lock.synchronize do
58
+ if @nats.nil?
59
+ @nats = NATS.connect(:uri => @nats_uri, :autostart => false)
60
+ end
61
+ end
62
+ end
63
+ @nats
64
+ end
65
+
66
+ # subscribe to an inbox, if not already subscribed
67
+ def subscribe_inbox
68
+ # double-check locking to reduce synchronization
69
+ if @subject_id.nil?
70
+ # nats lazy-load needs to be outside the synchronized block
71
+ client = nats
72
+ @lock.synchronize do
73
+ if @subject_id.nil?
74
+ @subject_id = client.subscribe("#{@inbox_name}.>") do |message, _, subject|
75
+ handle_response(message, subject)
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+
82
+ def handle_response(message, subject)
83
+ @logger.debug("RECEIVED: #{subject} #{message}")
84
+ begin
85
+ request_id = subject.split(".").last
86
+ callback = @lock.synchronize { @requests.delete(request_id) }
87
+ if callback
88
+ message = Yajl::Parser.new.parse(message)
89
+ callback.call(message)
90
+ end
91
+ rescue Exception => e
92
+ @logger.warn(e.message)
93
+ end
94
+ end
95
+
53
96
  end
54
97
  end
@@ -1,5 +1,5 @@
1
1
  module Bosh
2
2
  module Director
3
- VERSION = '1.2743.0'
3
+ VERSION = '1.2744.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bosh-director
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2743.0
4
+ version: 1.2744.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - VMware
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-14 00:00:00.000000000 Z
11
+ date: 2014-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bcrypt-ruby
@@ -30,154 +30,154 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.2743.0
33
+ version: 1.2744.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.2743.0
40
+ version: 1.2744.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bosh-core
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 1.2743.0
47
+ version: 1.2744.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 1.2743.0
54
+ version: 1.2744.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bosh-director-core
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 1.2743.0
61
+ version: 1.2744.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 1.2743.0
68
+ version: 1.2744.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: bosh_common
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 1.2743.0
75
+ version: 1.2744.0
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 1.2743.0
82
+ version: 1.2744.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: bosh-template
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 1.2743.0
89
+ version: 1.2744.0
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 1.2743.0
96
+ version: 1.2744.0
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: bosh_cpi
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 1.2743.0
103
+ version: 1.2744.0
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 1.2743.0
110
+ version: 1.2744.0
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: bosh_openstack_cpi
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: 1.2743.0
117
+ version: 1.2744.0
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: 1.2743.0
124
+ version: 1.2744.0
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: bosh_aws_cpi
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: 1.2743.0
131
+ version: 1.2744.0
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: 1.2743.0
138
+ version: 1.2744.0
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: bosh_vsphere_cpi
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: 1.2743.0
145
+ version: 1.2744.0
146
146
  type: :runtime
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: 1.2743.0
152
+ version: 1.2744.0
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: bosh_warden_cpi
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: 1.2743.0
159
+ version: 1.2744.0
160
160
  type: :runtime
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
- version: 1.2743.0
166
+ version: 1.2744.0
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: bosh_vcloud_cpi
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
171
  - - "~>"
172
172
  - !ruby/object:Gem::Version
173
- version: 0.7.0
173
+ version: 0.7.1
174
174
  type: :runtime
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
178
  - - "~>"
179
179
  - !ruby/object:Gem::Version
180
- version: 0.7.0
180
+ version: 0.7.1
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: eventmachine
183
183
  requirement: !ruby/object:Gem::Requirement
@@ -460,7 +460,7 @@ dependencies:
460
460
  version: '0'
461
461
  description: |-
462
462
  BOSH Director
463
- 01851c
463
+ 7460f0
464
464
  email: support@cloudfoundry.com
465
465
  executables:
466
466
  - bosh-director
@@ -522,7 +522,6 @@ files:
522
522
  - lib/bosh/director/api/controllers/base_controller.rb
523
523
  - lib/bosh/director/api/controllers/compiled_packages_controller.rb
524
524
  - lib/bosh/director/api/controllers/deployments_controller.rb
525
- - lib/bosh/director/api/controllers/errands_controller.rb
526
525
  - lib/bosh/director/api/controllers/info_controller.rb
527
526
  - lib/bosh/director/api/controllers/locks_controller.rb
528
527
  - lib/bosh/director/api/controllers/packages_controller.rb
@@ -1,41 +0,0 @@
1
- require 'json'
2
- require 'bosh/director/api/controllers/base_controller'
3
-
4
- module Bosh::Director
5
- module Api::Controllers
6
- class ErrandsController < BaseController
7
- get '/deployments/:deployment_name/errands' do
8
- deployment = @deployment_manager.find_by_name(params[:deployment_name])
9
-
10
- manifest = Psych.load(deployment.manifest)
11
- deployment_plan = DeploymentPlan::Planner.parse(manifest, {}, Config.event_log, Config.logger)
12
-
13
- errands = deployment_plan.jobs.select(&:can_run_as_errand?)
14
-
15
- errand_data = errands.map do |errand|
16
- { "name" => errand.name }
17
- end
18
-
19
- json_encode(errand_data)
20
- end
21
-
22
- post '/deployments/:deployment_name/errands/:errand_name/runs' do
23
- deployment_name = params[:deployment_name]
24
- errand_name = params[:errand_name]
25
-
26
- task = JobQueue.new.enqueue(
27
- @user,
28
- Jobs::RunErrand,
29
- "run errand #{errand_name} from deployment #{deployment_name}",
30
- [deployment_name, errand_name],
31
- )
32
-
33
- redirect "/tasks/#{task.id}"
34
- end
35
-
36
- def body_params
37
- @body_params ||= JSON.load(request.body)
38
- end
39
- end
40
- end
41
- end