right_agent 0.9.4 → 0.9.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/right_agent/agent.rb +3 -1
- data/lib/right_agent/minimal.rb +1 -0
- data/lib/right_agent/platform/darwin.rb +1 -1
- data/lib/right_agent/sender.rb +22 -18
- data/lib/right_agent.rb +0 -1
- data/right_agent.gemspec +2 -2
- data/spec/agent_spec.rb +6 -0
- data/spec/sender_spec.rb +17 -0
- metadata +4 -4
data/lib/right_agent/agent.rb
CHANGED
@@ -174,6 +174,8 @@ module RightScale
|
|
174
174
|
Log.init(@identity, @options[:log_path], :print => true)
|
175
175
|
Log.level = @options[:log_level] if @options[:log_level]
|
176
176
|
RightSupport::Log::Mixin.default_logger = Log
|
177
|
+
now = Time.now
|
178
|
+
Log.info("[start] Agent #{@identity} starting; time: #{now.utc}; utc_offset: #{now.utc_offset}")
|
177
179
|
Log.debug("Start options:")
|
178
180
|
log_opts = @options.inject([]){ |t, (k, v)| t << "- #{k}: #{v}" }
|
179
181
|
log_opts.each { |l| Log.debug(l) }
|
@@ -343,7 +345,7 @@ module RightScale
|
|
343
345
|
end
|
344
346
|
end
|
345
347
|
rescue Exception => e
|
346
|
-
res = Log.format("Failed to connect to broker #{
|
348
|
+
res = Log.format("Failed to connect to broker at host #{host.inspect} and port #{port.inspect}", e)
|
347
349
|
@exceptions.track("connect", e)
|
348
350
|
end
|
349
351
|
Log.error(res) if res
|
data/lib/right_agent/minimal.rb
CHANGED
data/lib/right_agent/sender.rb
CHANGED
@@ -444,23 +444,26 @@ module RightScale
|
|
444
444
|
# true:: Always return true
|
445
445
|
def check(id = nil, max_ping_timeouts = MAX_PING_TIMEOUTS)
|
446
446
|
unless @terminating || @ping_timer || (id && !@sender.broker.connected?(id))
|
447
|
+
@ping_id = id
|
447
448
|
@ping_timer = EM::Timer.new(PING_TIMEOUT) do
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
449
|
+
if @ping_id
|
450
|
+
begin
|
451
|
+
@ping_stats.update("timeout")
|
452
|
+
@ping_timer = nil
|
453
|
+
@ping_timeouts[@ping_id] = (@ping_timeouts[@ping_id] || 0) + 1
|
454
|
+
if @ping_timeouts[@ping_id] >= max_ping_timeouts
|
455
|
+
Log.error("Mapper ping via broker #{@ping_id} timed out after #{PING_TIMEOUT} seconds and now " +
|
456
|
+
"reached maximum of #{max_ping_timeouts} timeout#{max_ping_timeouts > 1 ? 's' : ''}, " +
|
457
|
+
"attempting to reconnect")
|
458
|
+
host, port, index, priority = @sender.broker.identity_parts(@ping_id)
|
459
|
+
@sender.agent.connect(host, port, index, priority, force = true)
|
460
|
+
else
|
461
|
+
Log.warning("Mapper ping via broker #{@ping_id} timed out after #{PING_TIMEOUT} seconds")
|
462
|
+
end
|
463
|
+
rescue Exception => e
|
464
|
+
Log.error("Failed to reconnect to broker #{@ping_id}", e, :trace)
|
465
|
+
@exception_stats.track("ping timeout", e)
|
460
466
|
end
|
461
|
-
rescue Exception => e
|
462
|
-
Log.error("Failed to reconnect to broker #{id}", e, :trace)
|
463
|
-
@exception_stats.track("ping timeout", e)
|
464
467
|
end
|
465
468
|
end
|
466
469
|
|
@@ -470,7 +473,8 @@ module RightScale
|
|
470
473
|
@ping_stats.update("success")
|
471
474
|
@ping_timer.cancel
|
472
475
|
@ping_timer = nil
|
473
|
-
@ping_timeouts[
|
476
|
+
@ping_timeouts[@ping_id] = 0
|
477
|
+
@ping_id = nil
|
474
478
|
end
|
475
479
|
rescue Exception => e
|
476
480
|
Log.error("Failed to cancel mapper ping", e, :trace)
|
@@ -479,8 +483,8 @@ module RightScale
|
|
479
483
|
end
|
480
484
|
request = Request.new("/mapper/ping", nil, {:from => @sender.identity, :token => AgentIdentity.generate})
|
481
485
|
@sender.pending_requests[request.token] = PendingRequest.new(:send_persistent_request, Time.now, handler)
|
482
|
-
ids = [
|
483
|
-
|
486
|
+
ids = [@ping_id] if @ping_id
|
487
|
+
@ping_id = @sender.publish(request, ids).first
|
484
488
|
end
|
485
489
|
true
|
486
490
|
end
|
data/lib/right_agent.rb
CHANGED
data/right_agent.gemspec
CHANGED
@@ -24,8 +24,8 @@ require 'rubygems'
|
|
24
24
|
|
25
25
|
Gem::Specification.new do |spec|
|
26
26
|
spec.name = 'right_agent'
|
27
|
-
spec.version = '0.9.
|
28
|
-
spec.date = '2012-03-
|
27
|
+
spec.version = '0.9.5'
|
28
|
+
spec.date = '2012-03-17'
|
29
29
|
spec.authors = ['Lee Kirchhoff', 'Raphael Simon', 'Tony Spataro']
|
30
30
|
spec.email = 'lee@rightscale.com'
|
31
31
|
spec.homepage = 'https://github.com/rightscale/right_agent'
|
data/spec/agent_spec.rb
CHANGED
@@ -441,6 +441,7 @@ describe RightScale::Agent do
|
|
441
441
|
|
442
442
|
it "should tune heartbeat for all broker connections" do
|
443
443
|
run_in_em do
|
444
|
+
@log.should_receive(:info).with(/\[start\] Agent #{@identity} starting; time: .*$/).once
|
444
445
|
@log.should_receive(:info).with(/Reconnecting each broker to tune heartbeat to 45/).once
|
445
446
|
@log.should_receive(:info).with(/Tuned heartbeat to 45 seconds for broker/).twice
|
446
447
|
@agent = RightScale::Agent.new(:user => "me", :identity => @identity)
|
@@ -458,6 +459,7 @@ describe RightScale::Agent do
|
|
458
459
|
|
459
460
|
it "should tune heartbeat for all broker connections as deferred task" do
|
460
461
|
run_in_em do
|
462
|
+
@log.should_receive(:info).with(/\[start\] Agent #{@identity} starting; time: .*$/).once
|
461
463
|
@log.should_receive(:info).with(/Reconnecting each broker to tune heartbeat to 45/).once
|
462
464
|
@log.should_receive(:info).with(/Tuned heartbeat to 45 seconds for broker/).twice
|
463
465
|
@agent = RightScale::Agent.new(:user => "me", :identity => @identity)
|
@@ -478,6 +480,7 @@ describe RightScale::Agent do
|
|
478
480
|
|
479
481
|
it "should disable heartbeat for all broker connections" do
|
480
482
|
run_in_em do
|
483
|
+
@log.should_receive(:info).with(/\[start\] Agent #{@identity} starting; time: .*$/).once
|
481
484
|
@log.should_receive(:info).with(/Reconnecting each broker to tune heartbeat to 0/).once
|
482
485
|
@log.should_receive(:info).with(/Disabled heartbeat for broker/).twice
|
483
486
|
@agent = RightScale::Agent.new(:user => "me", :identity => @identity)
|
@@ -495,6 +498,7 @@ describe RightScale::Agent do
|
|
495
498
|
|
496
499
|
it "should log error if any broker connect attempts fail" do
|
497
500
|
run_in_em do
|
501
|
+
@log.should_receive(:info).with(/\[start\] Agent #{@identity} starting; time: .*$/).once
|
498
502
|
@log.should_receive(:info).with(/Reconnecting each broker to tune heartbeat to 45/).once
|
499
503
|
@log.should_receive(:info).with(/Tuned heartbeat to 45 seconds for broker #{@broker_id2}/).once
|
500
504
|
@log.should_receive(:error).with("Failed to reconnect to broker #{@broker_id} to tune heartbeat", Exception, :trace).once
|
@@ -513,6 +517,7 @@ describe RightScale::Agent do
|
|
513
517
|
|
514
518
|
it "should log error if any brokers do not connect" do
|
515
519
|
run_in_em do
|
520
|
+
@log.should_receive(:info).with(/\[start\] Agent #{@identity} starting; time: .*$/).once
|
516
521
|
@log.should_receive(:info).with(/Reconnecting each broker to tune heartbeat to 45/).once
|
517
522
|
@log.should_receive(:info).with(/Tuned heartbeat to 45 seconds for broker #{@broker_id2}/).once
|
518
523
|
@log.should_receive(:error).with(/Failed to reconnect to broker #{@broker_id} to tune heartbeat, status/).once
|
@@ -533,6 +538,7 @@ describe RightScale::Agent do
|
|
533
538
|
|
534
539
|
it "should log error if any broker queue setup fails" do
|
535
540
|
run_in_em do
|
541
|
+
@log.should_receive(:info).with(/\[start\] Agent #{@identity} starting; time: .*$/).once
|
536
542
|
@log.should_receive(:info).with(/Reconnecting each broker to tune heartbeat to 45/).once
|
537
543
|
@log.should_receive(:info).with(/Tuned heartbeat to 45 seconds for broker #{@broker_id2}/).once
|
538
544
|
@log.should_receive(:error).with(/Failed to setup queues for broker #{@broker_id} when tuning heartbeat/, Exception, :trace).once
|
data/spec/sender_spec.rb
CHANGED
@@ -133,6 +133,23 @@ describe RightScale::Sender do
|
|
133
133
|
instance.connectivity_checker.check(broker_id)
|
134
134
|
end
|
135
135
|
|
136
|
+
it "should ignore ping timeout if never successfully publish ping" do
|
137
|
+
@agent.should_receive(:options).and_return(:ping_interval => 1000)
|
138
|
+
old_ping_timeout = RightScale::Sender::ConnectivityChecker::PING_TIMEOUT
|
139
|
+
begin
|
140
|
+
RightScale::Sender::ConnectivityChecker.const_set(:PING_TIMEOUT, 0.5)
|
141
|
+
EM.run do
|
142
|
+
EM.add_timer(1) { EM.stop }
|
143
|
+
RightScale::Sender.new(@agent)
|
144
|
+
instance = RightScale::Sender.instance
|
145
|
+
flexmock(instance).should_receive(:publish).and_return([]).once
|
146
|
+
instance.connectivity_checker.check(id = nil)
|
147
|
+
end
|
148
|
+
ensure
|
149
|
+
RightScale::Sender::ConnectivityChecker.const_set(:PING_TIMEOUT, old_ping_timeout)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
136
153
|
it "should ignore messages received if ping disabled" do
|
137
154
|
@agent.should_receive(:options).and_return(:ping_interval => 0)
|
138
155
|
flexmock(EM::Timer).should_receive(:new).never
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: right_agent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 49
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
|
-
-
|
10
|
-
version: 0.9.
|
9
|
+
- 5
|
10
|
+
version: 0.9.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Lee Kirchhoff
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2012-03-
|
20
|
+
date: 2012-03-17 00:00:00 -07:00
|
21
21
|
default_executable:
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|