amiral 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/amiral/version.rb +1 -1
  2. data/lib/amiral.rb +29 -90
  3. metadata +2 -2
@@ -1,3 +1,3 @@
1
1
  module Amiral
2
- VERSION = '0.1.5'
2
+ VERSION = '0.1.6'
3
3
  end
data/lib/amiral.rb CHANGED
@@ -101,7 +101,6 @@ module Amiral
101
101
  status = POpen4::popen4("service #{service} #{action}"){|stdout, stderr, stdin, pid|
102
102
  out = stdout.read
103
103
  err = stderr.read
104
-
105
104
  }
106
105
  {
107
106
  :exit => status.exitstatus,
@@ -289,35 +288,41 @@ module Amiral
289
288
  end
290
289
 
291
290
  def listen
292
- prefix = @settings[:prefix]
293
- @redis_in.subscribe "#{prefix}req" do |on|
291
+ begin
292
+ prefix = @settings[:prefix]
293
+ @redis_in.subscribe "#{prefix}req" do |on|
294
294
 
295
- on.message do |x, payload|
295
+ on.message do |x, payload|
296
296
 
297
- @logger.debug "incoming message"
298
- message = deserialize payload
297
+ @logger.debug "incoming message"
298
+ message = deserialize payload
299
299
 
300
- if agent_matches? message['match']
301
- @logger.info "valid request type: #{message['command']['provider']}"
302
- uuid = uuidgen
303
- send_ack(:in_reply_to => message['reply_to'],
304
- :uuid => uuid,
305
- :status => "start")
306
- begin
307
- out = execute message
308
- rescue Exception => e
309
- @logger.error "provider crashed: #{e}"
310
- @logger.error e
300
+ if agent_matches? message['match']
301
+ @logger.info "valid request type: #{message['command']['provider']}"
302
+ uuid = uuidgen
303
+ send_ack(:in_reply_to => message['reply_to'],
304
+ :uuid => uuid,
305
+ :status => "start")
306
+ begin
307
+ out = execute message
308
+ rescue Exception => e
309
+ @logger.error "provider crashed: #{e}"
310
+ @logger.error e
311
+ end
312
+ send_response(:in_reply_to => message['reply_to'],
313
+ :uuid => uuid,
314
+ :status => "complete",
315
+ :output => out)
316
+ else
317
+ send_ack(:in_reply_to => message['reply_to'],
318
+ :status => "noop")
311
319
  end
312
- send_response(:in_reply_to => message['reply_to'],
313
- :uuid => uuid,
314
- :status => "complete",
315
- :output => out)
316
- else
317
- send_ack(:in_reply_to => message['reply_to'],
318
- :status => "noop")
319
320
  end
320
321
  end
322
+ rescue Redis::BaseConnectionError => error
323
+ @logger.error "connection hung up: #{error}"
324
+ sleep 1
325
+ retry
321
326
  end
322
327
  end
323
328
 
@@ -340,7 +345,6 @@ module Amiral
340
345
  end
341
346
 
342
347
  def send_payload type, response
343
- puts "response: #{response}"
344
348
  uuid = response[:in_reply_to]
345
349
  response[:hostname] = @settings[:hostname]
346
350
  prefix = @settings[:prefix]
@@ -348,69 +352,4 @@ module Amiral
348
352
  end
349
353
  end
350
354
 
351
- class Controller
352
- include Message
353
-
354
- def initialize settings
355
- @settings = {
356
- :redis => Redis.new,
357
- :prefix => "amiral:",
358
- :ack_timeout => 2,
359
- :response_timeout => 5,
360
- :match_spec => {:all => true},
361
- :keytype => :dss,
362
- }.merge settings
363
-
364
- raise "need key path" unless @settings[:keypath]
365
-
366
- @privkey = File.open @settings[:keypath] do |file|
367
- KEYTYPES[@settings[:keytype]].new file
368
- end
369
-
370
- @redis = @settings[:redis]
371
- end
372
-
373
- def run args
374
- provider = args.shift
375
- request provider, {}
376
- end
377
-
378
- def request provider, args
379
-
380
- uuid = uuidgen
381
- request = {
382
- :command => {
383
- :provider => provider,
384
- :args => args
385
- },
386
- :reply_to => uuid,
387
- :match => @settings[:match_spec]
388
- }
389
-
390
- @redis.publish @settings[:exchange], serialize(request)
391
-
392
- # pop items for 2 seconds
393
- acks = {}
394
- resps = {}
395
- puts "accepting acknowledgements for #{@settings[:ack_timeout]} seconds"
396
- limit = timestamp + @settings[:ack_timeout]
397
-
398
- ## XXX: broken for now
399
- @responses = []
400
-
401
- puts "got #{@responses.length}/#{pos_acks.length} responses"
402
- @responses
403
- end
404
-
405
- def show
406
- @responses.map do |node|
407
- if node['output']['exit'] == 0
408
- printf "%20s: %s\n", node['hostname'], node['output']['short']
409
- else
410
- printf "%20s: failed!\n", node['hostname']
411
- ap node
412
- end
413
- end
414
- end
415
- end
416
355
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amiral
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
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: 2012-11-14 00:00:00.000000000 Z
12
+ date: 2012-11-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redis