right_agent 2.0.7-x86-mingw32 → 2.0.8-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
@@ -193,11 +193,7 @@ module RightScale
193
193
  @history.update("start")
194
194
  now = Time.now
195
195
  Log.info("[start] Agent #{@identity} starting; time: #{now.utc}; utc_offset: #{now.utc_offset}")
196
- Log.debug("Start options:")
197
- log_opts = @options.inject([]) do |t, (k, v)|
198
- t << "- #{k}: #{k.to_s =~ /pass/ ? '****' : (v.respond_to?(:each) ? v.inspect : v)}"
199
- end
200
- log_opts.each { |l| Log.debug(l) }
196
+ @options.each { |k, v| Log.info("- #{k}: #{k.to_s =~ /pass/ ? '****' : (v.respond_to?(:each) ? v.inspect : v)}") }
201
197
 
202
198
  begin
203
199
  # Capture process id in file after optional daemonize
@@ -495,7 +491,7 @@ module RightScale
495
491
  if @mode == :http
496
492
  stats.merge!(@client.stats(reset))
497
493
  else
498
- stats["broker"] = @client.stats(reset)
494
+ stats["brokers"] = @client.stats(reset)
499
495
  end
500
496
  result = OperationResult.success(stats)
501
497
  @last_stat_reset_time = now if reset
@@ -529,7 +525,7 @@ module RightScale
529
525
  "request failures" => @request_failure_stats.all,
530
526
  "response failures" => @response_failure_stats.all
531
527
  }
532
- unless @mode == :http
528
+ if @mode != :http
533
529
  stats["connect requests"] = @connect_request_stats.all
534
530
  stats["non-deliveries"] = @non_delivery_stats.all
535
531
  end
@@ -610,7 +606,7 @@ module RightScale
610
606
  load_actors
611
607
  setup_traps
612
608
  setup_status
613
- unless @mode == :http
609
+ if @mode != :http
614
610
  setup_non_delivery
615
611
  setup_queues
616
612
  end
@@ -731,7 +727,7 @@ module RightScale
731
727
  Dir["#{dir}/*.rb"].each do |file|
732
728
  actor = File.basename(file, ".rb")
733
729
  next if actors && !actors.include?(actor)
734
- Log.info("[setup] loading actor #{file}")
730
+ Log.info("[setup] Loading actor #{file}")
735
731
  require file
736
732
  actors.delete(actor)
737
733
  end
@@ -740,7 +736,7 @@ module RightScale
740
736
 
741
737
  # Perform agent-specific initialization including actor creation and registration
742
738
  if (init_file = AgentConfig.init_file)
743
- Log.info("[setup] initializing agent from #{init_file}")
739
+ Log.info("[setup] Initializing agent from #{init_file}")
744
740
  instance_eval(File.read(init_file), init_file)
745
741
  else
746
742
  Log.error("No agent init.rb file found in init directory of #{AgentConfig.root_dir.inspect}")
@@ -794,12 +790,14 @@ module RightScale
794
790
  # true:: Always return true
795
791
  def setup_status
796
792
  @status = {}
797
- if @mode == :http
798
- @status = @client.status { |type, state| update_status(type, state) }.dup
799
- else
800
- @client.connection_status { |state| update_status(:broker, state) }
801
- @status[:broker] = :connected
802
- @status[:auth] = @auth_client.status { |type, state| update_status(type, state) } if @auth_client
793
+ if @client
794
+ if @mode == :http
795
+ @status = @client.status { |type, state| update_status(type, state) }.dup
796
+ else
797
+ @client.connection_status { |state| update_status(:broker, state) }
798
+ @status[:broker] = :connected
799
+ @status[:auth] = @auth_client.status { |type, state| update_status(type, state) } if @auth_client
800
+ end
803
801
  end
804
802
  true
805
803
  end
@@ -976,7 +974,7 @@ module RightScale
976
974
  # true:: Always return true
977
975
  def setup_status_checks(interval)
978
976
  @check_status_count = 0
979
- @check_status_brokers = @client.all unless @mode == :http
977
+ @check_status_brokers = @client.all if @mode != :http
980
978
  @check_status_timer = EM::PeriodicTimer.new(interval) { check_status }
981
979
  true
982
980
  end
@@ -45,7 +45,7 @@ module RightScale
45
45
  # true:: Always return true
46
46
  def tags(options = {})
47
47
  # TODO remove use of agent identity when fully drop AMQP
48
- do_query(nil, @agent.self_href || @agent.identity, options) do |result|
48
+ do_query(nil, @agent.mode == :http ? @agent.self_href : @agent.identity, options) do |result|
49
49
  if result.kind_of?(Hash)
50
50
  yield(result.size == 1 ? result.values.first['tags'] : [])
51
51
  else
@@ -168,7 +168,12 @@ module RightScale
168
168
  agent_check
169
169
  payload = {:agent_identity => @agent.identity}
170
170
  payload[:tags] = ensure_flat_array_value(tags) unless tags.nil? || tags.empty?
171
- payload[:hrefs] = ensure_flat_array_value(hrefs) unless hrefs.nil? || hrefs.empty?
171
+ # TODO remove use of agent identity when fully drop AMQP
172
+ if @agent.mode == :http
173
+ payload[:hrefs] = ensure_flat_array_value(hrefs) unless hrefs.nil? || hrefs.empty?
174
+ else
175
+ payload[:agent_ids] = ensure_flat_array_value(hrefs) unless hrefs.nil? || hrefs.empty?
176
+ end
172
177
  request = RightScale::RetryableRequest.new("/router/query_tags", payload, request_options)
173
178
  request.callback { |result| yield raw ? request.raw_response : result }
174
179
  request.errback do |message|
@@ -154,6 +154,21 @@ module RightScale
154
154
  state
155
155
  end
156
156
 
157
+ # Set callback for each successful communication excluding health checks
158
+ # Multiple callbacks are supported
159
+ #
160
+ # @yield [] required block executed after successful communication
161
+ #
162
+ # @return [TrueClass] always true
163
+ #
164
+ # @raise [ArgumentError] block missing
165
+ def communicated(&callback)
166
+ raise ArgumentError, "Block missing" unless callback
167
+ @communicated_callbacks ||= []
168
+ @communicated_callbacks << callback
169
+ true
170
+ end
171
+
157
172
  # Current statistics for this client
158
173
  #
159
174
  # @param [Boolean] reset the statistics after getting the current ones
@@ -88,7 +88,6 @@ module RightScale
88
88
  @auth_client = auth_client
89
89
  @http_client = nil
90
90
  @status_callbacks = []
91
- @communicated_callbacks = []
92
91
  @options = options.dup
93
92
  @options[:server_name] ||= type.to_s
94
93
  @options[:open_timeout] ||= DEFAULT_OPEN_TIMEOUT
@@ -122,8 +121,12 @@ module RightScale
122
121
  # @yield [] required block executed after successful communication
123
122
  #
124
123
  # @return [TrueClass] always true
124
+ #
125
+ # @raise [ArgumentError] block missing
125
126
  def communicated(&callback)
126
- @communicated_callbacks << callback if callback
127
+ raise ArgumentError, "Block missing" unless callback
128
+ @communicated_callbacks ||= []
129
+ @communicated_callbacks << callback
127
130
  true
128
131
  end
129
132
 
@@ -350,7 +353,7 @@ module RightScale
350
353
  request_uuid ? retry : raise
351
354
  end
352
355
  end
353
- @communicated_callbacks.each { |callback| callback.call }
356
+ @communicated_callbacks.each { |callback| callback.call } if @communicated_callbacks
354
357
  result
355
358
  end
356
359
 
@@ -209,17 +209,18 @@ module RightScale
209
209
 
210
210
  # Set callback for each successful communication excluding health checks
211
211
  #
212
- # @param [Symbol] type of server: :api or :router; defaults to all
212
+ # @param [Array] types of server: :auth, :api, or :router; defaults to all
213
213
  #
214
214
  # @yield [] required block executed after successful communication
215
215
  #
216
216
  # @return [TrueClass] always true
217
217
  #
218
218
  # @raise [RuntimeError] init was not called
219
- def communicated(type = nil, &callback)
219
+ def communicated(types = [], &callback)
220
220
  raise RuntimeError, "#{self.class.name}#init was not called" unless @auth
221
- @api.communicated(&callback) if @api && [nil, :api].include?(type)
222
- @router.communicated(&callback) if @router && [nil, :router].include?(type)
221
+ @auth.communicated(&callback) if types.empty? || types.include?(:auth)
222
+ @api.communicated(&callback) if @api && (types.empty? || types.include?(:api))
223
+ @router.communicated(&callback) if @router && (types.empty? || types.include?(:router))
223
224
  true
224
225
  end
225
226
 
@@ -397,6 +397,7 @@ module RightScale
397
397
  Log.info("Sending EVENT <#{result[:uuid]}> #{result[:type]} #{result[:path]} to #{result[:from]}")
398
398
  @websocket.send(JSON.dump({:event => result, :routing_keys => [event[:from]]}))
399
399
  end
400
+ @communicated_callbacks.each { |callback| callback.call } if @communicated_callbacks
400
401
  rescue Exception => e
401
402
  Log.error("Failed handling WebSocket event", e, :trace)
402
403
  @stats["exceptions"].track("event", e)
@@ -420,6 +421,7 @@ module RightScale
420
421
  begin
421
422
  result = long_poll(routing_keys, uuids, &handler)
422
423
  @reconnect_interval = RECONNECT_INTERVAL
424
+ @communicated_callbacks.each { |callback| callback.call } if @communicated_callbacks
423
425
  rescue Exceptions::Unauthorized, Exceptions::ConnectivityFailure, Exceptions::RetryableError => e
424
426
  Log.error("Failed long-polling", e, :no_trace)
425
427
  sleep(backoff_reconnect_interval)
@@ -89,7 +89,7 @@ module RightScale
89
89
  # === Return
90
90
  # true:: Always return true
91
91
  def check(id = nil, max_ping_timeouts = MAX_PING_TIMEOUTS)
92
- unless @terminating || @ping_timer || (id && !@sender.client.connected?(id))
92
+ unless @terminating || @ping_timer || (id && !@sender.agent.client.connected?(id))
93
93
  @ping_id = id
94
94
  @ping_timer = EM::Timer.new(PING_TIMEOUT) do
95
95
  if @ping_id
data/right_agent.gemspec CHANGED
@@ -25,8 +25,8 @@ require 'rbconfig'
25
25
 
26
26
  Gem::Specification.new do |spec|
27
27
  spec.name = 'right_agent'
28
- spec.version = '2.0.7'
29
- spec.date = '2014-02-28'
28
+ spec.version = '2.0.8'
29
+ spec.date = '2014-03-03'
30
30
  spec.authors = ['Lee Kirchhoff', 'Raphael Simon', 'Tony Spataro', 'Scott Messier']
31
31
  spec.email = 'lee@rightscale.com'
32
32
  spec.homepage = 'https://github.com/rightscale/right_agent'
@@ -40,7 +40,7 @@ Gem::Specification.new do |spec|
40
40
 
41
41
  spec.add_dependency('right_support', ['>= 2.4.1', '< 3.0'])
42
42
  spec.add_dependency('right_amqp', '~> 0.7')
43
- spec.add_dependency('rest-client', '1.7.0.alpha')
43
+ spec.add_dependency('rest-client', '1.7.0.1')
44
44
  spec.add_dependency('faye-websocket', '0.7.0')
45
45
  spec.add_dependency('eventmachine', ['>= 0.12.10', '< 2.0'])
46
46
  spec.add_dependency('net-ssh', '~> 2.0')
@@ -32,7 +32,7 @@ describe RightScale::AgentTagManager do
32
32
  @identity = "rs-agent-1-1"
33
33
  @agent_href = "/api/clouds/1/instances/1"
34
34
  @agent_href2 = "/api/clouds/2/instances/2"
35
- @agent = flexmock("agent", :self_href => @agent_href, :identity => @identity)
35
+ @agent = flexmock("agent", :self_href => @agent_href, :identity => @identity, :mode => :http).by_default
36
36
  @hrefs = [@agent_href, @agent_href2]
37
37
  @manager = RightScale::AgentTagManager.instance
38
38
  @manager.agent = @agent
@@ -60,6 +60,15 @@ describe RightScale::AgentTagManager do
60
60
  @result.should == [@tag]
61
61
  end
62
62
 
63
+ it "retrieves current agent tags using agent ID if not in :http mode" do
64
+ @agent.should_receive(:mode).and_return(:amqp)
65
+ @retryable_request.should_receive(:new).with("/router/query_tags",
66
+ {:agent_identity => @identity, :agent_ids => [@identity]}, {}).and_return(@request).once
67
+ @request.should_receive(:callback).and_yield({@agent_href => {"tags" => [@tag]}}).once
68
+ @manager.tags { |r| @result = r }
69
+ @result.should == [@tag]
70
+ end
71
+
63
72
  it "returns empty array when there is no results hash" do
64
73
  @request.should_receive(:callback).and_yield({}).once
65
74
  @manager.tags { |r| @result = r }
@@ -189,6 +189,20 @@ describe RightScale::AuthClient do
189
189
  end
190
190
  end
191
191
 
192
+ context :communicated do
193
+ it "stores callback" do
194
+ callback = lambda { |_, _| }
195
+ @client.instance_variable_get(:@communicated_callbacks).should be_nil
196
+ @client.communicated(&callback)
197
+ @client.instance_variable_get(:@communicated_callbacks).size.should == 1
198
+ @client.instance_variable_get(:@communicated_callbacks)[0].should == callback
199
+ end
200
+
201
+ it "requires callback block" do
202
+ lambda { @client.communicated }.should raise_error(ArgumentError, "Block missing")
203
+ end
204
+ end
205
+
192
206
  context :check_authorized do
193
207
  it "raises retryable error if state is :expired" do
194
208
  @client.send(:state=, :authorized)
@@ -136,11 +136,15 @@ describe RightScale::BaseRetryClient do
136
136
  context :communicated do
137
137
  it "stores callback" do
138
138
  callback = lambda { |_, _| }
139
- @client.instance_variable_get(:@communicated_callbacks).size.should == 0
139
+ @client.instance_variable_get(:@communicated_callbacks).should be_nil
140
140
  @client.communicated(&callback)
141
141
  @client.instance_variable_get(:@communicated_callbacks).size.should == 1
142
142
  @client.instance_variable_get(:@communicated_callbacks)[0].should == callback
143
143
  end
144
+
145
+ it "requires callback block" do
146
+ lambda { @client.communicated }.should raise_error(ArgumentError, "Block missing")
147
+ end
144
148
  end
145
149
 
146
150
  context :close do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: right_agent
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.7
4
+ version: 2.0.8
5
5
  prerelease:
6
6
  platform: x86-mingw32
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2014-02-28 00:00:00.000000000 Z
15
+ date: 2014-03-03 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: right_support
@@ -59,7 +59,7 @@ dependencies:
59
59
  requirements:
60
60
  - - '='
61
61
  - !ruby/object:Gem::Version
62
- version: 1.7.0.alpha
62
+ version: 1.7.0.1
63
63
  type: :runtime
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
@@ -67,7 +67,7 @@ dependencies:
67
67
  requirements:
68
68
  - - '='
69
69
  - !ruby/object:Gem::Version
70
- version: 1.7.0.alpha
70
+ version: 1.7.0.1
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: faye-websocket
73
73
  requirement: !ruby/object:Gem::Requirement
@@ -437,7 +437,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
437
437
  version: '0'
438
438
  segments:
439
439
  - 0
440
- hash: -1817530941733034469
440
+ hash: -1395793302884247070
441
441
  requirements: []
442
442
  rubyforge_project:
443
443
  rubygems_version: 1.8.26