nofxx-nanite 0.4.1.2 → 0.4.1.15
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +3 -2
- data/bin/nanite-agent +3 -0
- data/lib/nanite.rb +8 -2
- data/lib/nanite/agent.rb +19 -11
- data/lib/nanite/amqp.rb +18 -1
- data/lib/nanite/cluster.rb +34 -14
- data/lib/nanite/config.rb +1 -1
- data/lib/nanite/daemonize.rb +4 -4
- data/lib/nanite/local_state.rb +4 -0
- data/lib/nanite/log.rb +1 -1
- data/lib/nanite/mapper.rb +34 -21
- data/lib/nanite/mapper_proxy.rb +4 -4
- data/lib/nanite/{dispatcher.rb → nanite_dispatcher.rb} +1 -1
- data/lib/nanite/packets.rb +4 -2
- data/lib/nanite/reaper.rb +15 -14
- data/lib/nanite/security/signature.rb +1 -1
- data/lib/nanite/serializer.rb +31 -18
- data/lib/nanite/state.rb +7 -3
- metadata +63 -59
- data/spec/actor_registry_spec.rb +0 -60
- data/spec/actor_spec.rb +0 -77
- data/spec/agent_spec.rb +0 -240
- data/spec/cached_certificate_store_proxy_spec.rb +0 -34
- data/spec/certificate_cache_spec.rb +0 -49
- data/spec/certificate_spec.rb +0 -27
- data/spec/cluster_spec.rb +0 -485
- data/spec/dispatcher_spec.rb +0 -136
- data/spec/distinguished_name_spec.rb +0 -24
- data/spec/encrypted_document_spec.rb +0 -21
- data/spec/job_spec.rb +0 -251
- data/spec/local_state_spec.rb +0 -112
- data/spec/packet_spec.rb +0 -220
- data/spec/rsa_key_pair_spec.rb +0 -33
- data/spec/secure_serializer_spec.rb +0 -41
- data/spec/serializer_spec.rb +0 -107
- data/spec/signature_spec.rb +0 -30
- data/spec/spec_helper.rb +0 -33
- data/spec/static_certificate_store_spec.rb +0 -30
- data/spec/util_spec.rb +0 -63
data/lib/nanite/mapper_proxy.rb
CHANGED
@@ -31,23 +31,23 @@ module Nanite
|
|
31
31
|
# Send request to given agent through the mapper
|
32
32
|
def request(type, payload = '', opts = {}, &blk)
|
33
33
|
raise "Mapper proxy not initialized" unless identity && options
|
34
|
-
request = Request.new(type, payload, opts)
|
34
|
+
request = Request.new(type, payload, nil, opts)
|
35
35
|
request.from = identity
|
36
36
|
request.token = Identity.generate
|
37
37
|
request.persistent = opts.key?(:persistent) ? opts[:persistent] : options[:persistent]
|
38
38
|
pending_requests[request.token] =
|
39
39
|
{ :intermediate_handler => opts[:intermediate_handler], :result_handler => blk }
|
40
|
-
Nanite::Log.
|
40
|
+
Nanite::Log.debug("SEND #{request.to_s([:tags, :target])}")
|
41
41
|
amqp.fanout('request', :no_declare => options[:secure]).publish(serializer.dump(request))
|
42
42
|
end
|
43
43
|
|
44
44
|
def push(type, payload = '', opts = {})
|
45
45
|
raise "Mapper proxy not initialized" unless identity && options
|
46
|
-
push = Push.new(type, payload, opts)
|
46
|
+
push = Push.new(type, payload, nil, opts)
|
47
47
|
push.from = identity
|
48
48
|
push.token = Identity.generate
|
49
49
|
push.persistent = opts.key?(:persistent) ? opts[:persistent] : options[:persistent]
|
50
|
-
Nanite::Log.
|
50
|
+
Nanite::Log.debug("SEND #{push.to_s([:tags, :target])}")
|
51
51
|
amqp.fanout('request', :no_declare => options[:secure]).publish(serializer.dump(push))
|
52
52
|
end
|
53
53
|
|
@@ -32,7 +32,7 @@ module Nanite
|
|
32
32
|
callback = lambda do |r|
|
33
33
|
if deliverable.kind_of?(Request)
|
34
34
|
r = Result.new(deliverable.token, deliverable.reply_to, r, identity)
|
35
|
-
Nanite::Log.
|
35
|
+
Nanite::Log.debug("SEND #{r.to_s([])}")
|
36
36
|
amq.queue(deliverable.reply_to, :no_declare => options[:secure]).publish(serializer.dump(r))
|
37
37
|
end
|
38
38
|
r # For unit tests
|
data/lib/nanite/packets.rb
CHANGED
@@ -350,9 +350,11 @@ module Nanite
|
|
350
350
|
# when worker initially comes online to advertise
|
351
351
|
# it's services
|
352
352
|
class Advertise < Packet
|
353
|
-
|
354
|
-
|
353
|
+
attr_accessor :target
|
354
|
+
|
355
|
+
def initialize(size = nil, target = nil)
|
355
356
|
@size = size
|
357
|
+
@target = target
|
356
358
|
end
|
357
359
|
|
358
360
|
def self.json_create(o)
|
data/lib/nanite/reaper.rb
CHANGED
@@ -1,23 +1,29 @@
|
|
1
1
|
module Nanite
|
2
2
|
class Reaper
|
3
|
-
|
3
|
+
attr_reader :timeouts
|
4
4
|
def initialize(frequency=2)
|
5
5
|
@timeouts = {}
|
6
6
|
EM.add_periodic_timer(frequency) { EM.next_tick { reap } }
|
7
7
|
end
|
8
8
|
|
9
|
-
|
9
|
+
# Add the specified token to the internal timeout hash.
|
10
|
+
# The reaper will then check this instance on every reap.
|
11
|
+
def register(token, seconds, &blk)
|
10
12
|
@timeouts[token] = {:timestamp => Time.now + seconds, :seconds => seconds, :callback => blk}
|
11
13
|
end
|
14
|
+
|
15
|
+
def unregister(token)
|
16
|
+
@timeouts.delete(token)
|
17
|
+
end
|
12
18
|
|
13
|
-
|
19
|
+
# Updates the timeout timestamp for the given token. If the token is
|
20
|
+
# unknown to this reaper instance it will be auto-registered, usually
|
21
|
+
# happening when you have several mappers and not all of them know
|
22
|
+
# this agent yet, but received a ping from it.
|
23
|
+
def update(token, seconds, &blk)
|
14
24
|
unless @timeouts[token]
|
15
|
-
|
25
|
+
register(token, seconds, &blk)
|
16
26
|
end
|
17
|
-
reset(token)
|
18
|
-
end
|
19
|
-
|
20
|
-
def reset(token)
|
21
27
|
@timeouts[token][:timestamp] = Time.now + @timeouts[token][:seconds]
|
22
28
|
end
|
23
29
|
|
@@ -26,12 +32,7 @@ module Nanite
|
|
26
32
|
def reap
|
27
33
|
time = Time.now
|
28
34
|
@timeouts.reject! do |token, data|
|
29
|
-
|
30
|
-
data[:callback].call
|
31
|
-
true
|
32
|
-
else
|
33
|
-
false
|
34
|
-
end
|
35
|
+
time > data[:timestamp] and data[:callback].call
|
35
36
|
end
|
36
37
|
end
|
37
38
|
end
|
data/lib/nanite/serializer.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
module Nanite
|
2
2
|
class Serializer
|
3
|
+
SERIALIZERS = {:json => JSON, :marshal => Marshal, :yaml => YAML}.freeze
|
3
4
|
|
5
|
+
attr_reader :preferred_format
|
6
|
+
|
4
7
|
class SerializationError < StandardError
|
5
8
|
attr_accessor :action, :packet
|
6
9
|
def initialize(action, packet, serializers, msg = nil)
|
@@ -11,42 +14,52 @@ module Nanite
|
|
11
14
|
end # SerializationError
|
12
15
|
|
13
16
|
# The secure serializer should not be part of the cascading
|
14
|
-
def initialize(preferred_format =
|
15
|
-
preferred_format
|
16
|
-
if preferred_format.to_s == 'secure'
|
17
|
+
def initialize(preferred_format = nil)
|
18
|
+
@preferred_format = preferred_format || :marshal
|
19
|
+
if @preferred_format.to_s == 'secure'
|
17
20
|
@serializers = [ SecureSerializer ]
|
18
21
|
else
|
19
|
-
preferred_serializer = SERIALIZERS[preferred_format.to_sym]
|
22
|
+
preferred_serializer = SERIALIZERS[@preferred_format.to_sym]
|
20
23
|
@serializers = SERIALIZERS.values.clone
|
21
24
|
@serializers.unshift(@serializers.delete(preferred_serializer)) if preferred_serializer
|
22
25
|
end
|
23
26
|
end
|
24
27
|
|
25
|
-
def dump(packet)
|
26
|
-
cascade_serializers(:dump, packet)
|
28
|
+
def dump(packet, format = nil)
|
29
|
+
cascade_serializers(:dump, packet, format)
|
27
30
|
end
|
28
31
|
|
29
|
-
def load(packet)
|
30
|
-
cascade_serializers(:load, packet)
|
32
|
+
def load(packet, format = nil)
|
33
|
+
cascade_serializers(:load, packet, format)
|
31
34
|
end
|
32
35
|
|
33
36
|
private
|
34
37
|
|
35
|
-
|
36
|
-
|
37
|
-
def cascade_serializers(action, packet)
|
38
|
+
def cascade_serializers(action, packet, format)
|
38
39
|
errors = []
|
39
|
-
|
40
|
+
determine_serializers(format).map do |serializer|
|
40
41
|
begin
|
41
|
-
|
42
|
+
serialized = serializer.send(action, packet)
|
42
43
|
rescue Exception => e
|
43
|
-
|
44
|
+
serialized = nil
|
44
45
|
errors << "#{e.message}\n\t#{e.backtrace[0]}"
|
45
46
|
end
|
46
|
-
return
|
47
|
+
return serialized if serialized
|
47
48
|
end
|
48
49
|
raise SerializationError.new(action, packet, @serializers, errors.join("\n"))
|
49
50
|
end
|
50
|
-
|
51
|
-
|
52
|
-
|
51
|
+
|
52
|
+
def determine_serializers(format)
|
53
|
+
if secure_serialization? and format == :insecure
|
54
|
+
SERIALIZERS.values
|
55
|
+
else
|
56
|
+
@serializers
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def secure_serialization?
|
61
|
+
@preferred_format.to_s == 'secure'
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
data/lib/nanite/state.rb
CHANGED
@@ -55,9 +55,9 @@ module Nanite
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
-
def []=(nanite,
|
58
|
+
def []=(nanite, attributes)
|
59
59
|
log_redis_error("[]=") do
|
60
|
-
update_state(nanite,
|
60
|
+
update_state(nanite, attributes[:status], attributes[:services], attributes[:tags])
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
@@ -124,8 +124,12 @@ module Nanite
|
|
124
124
|
@redis.set_add("tg-#{name}", tag)
|
125
125
|
@redis.set_add("nanitetags", tag)
|
126
126
|
end
|
127
|
+
update_status(name, status)
|
128
|
+
end
|
129
|
+
|
130
|
+
def update_status(name, status)
|
127
131
|
@redis[name] = status
|
128
|
-
@redis["t-#{name}"] = Time.now.to_i
|
132
|
+
@redis["t-#{name}"] = Time.now.utc.to_i
|
129
133
|
end
|
130
134
|
|
131
135
|
def list_nanites
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nofxx-nanite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 4
|
8
|
+
- 1
|
9
|
+
- 15
|
10
|
+
version: 0.4.1.15
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Ezra Zygmuntowicz
|
@@ -9,19 +15,37 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date:
|
18
|
+
date: 2010-03-02 00:00:00 -03:00
|
13
19
|
default_executable:
|
14
20
|
dependencies:
|
15
21
|
- !ruby/object:Gem::Dependency
|
16
22
|
name: amqp
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
25
|
requirements:
|
21
26
|
- - ">="
|
22
27
|
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
- 6
|
31
|
+
- 0
|
23
32
|
version: 0.6.0
|
24
|
-
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: json
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 1
|
44
|
+
- 1
|
45
|
+
- 7
|
46
|
+
version: 1.1.7
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
25
49
|
description: self assembling fabric of ruby daemons
|
26
50
|
email: ezra@engineyard.com
|
27
51
|
executables:
|
@@ -40,69 +64,47 @@ files:
|
|
40
64
|
- Rakefile
|
41
65
|
- TODO
|
42
66
|
- lib/nanite.rb
|
43
|
-
- lib/nanite
|
44
|
-
- lib/nanite/
|
45
|
-
- lib/nanite/
|
67
|
+
- lib/nanite/log/formatter.rb
|
68
|
+
- lib/nanite/agent.rb
|
69
|
+
- lib/nanite/local_state.rb
|
70
|
+
- lib/nanite/cluster.rb
|
71
|
+
- lib/nanite/reaper.rb
|
72
|
+
- lib/nanite/config.rb
|
46
73
|
- lib/nanite/pid_file.rb
|
47
|
-
- lib/nanite/mapper.rb
|
48
74
|
- lib/nanite/daemonize.rb
|
75
|
+
- lib/nanite/nanite_dispatcher.rb
|
76
|
+
- lib/nanite/console.rb
|
49
77
|
- lib/nanite/mapper_proxy.rb
|
50
|
-
- lib/nanite/
|
51
|
-
- lib/nanite/security/
|
52
|
-
- lib/nanite/security/
|
53
|
-
- lib/nanite/security/certificate_cache.rb
|
78
|
+
- lib/nanite/job.rb
|
79
|
+
- lib/nanite/security/rsa_key_pair.rb
|
80
|
+
- lib/nanite/security/encrypted_document.rb
|
54
81
|
- lib/nanite/security/signature.rb
|
82
|
+
- lib/nanite/security/distinguished_name.rb
|
83
|
+
- lib/nanite/security/cached_certificate_store_proxy.rb
|
55
84
|
- lib/nanite/security/certificate.rb
|
56
|
-
- lib/nanite/security/encrypted_document.rb
|
57
|
-
- lib/nanite/security/rsa_key_pair.rb
|
58
85
|
- lib/nanite/security/static_certificate_store.rb
|
59
|
-
- lib/nanite/security/
|
60
|
-
- lib/nanite/
|
61
|
-
- lib/nanite/
|
62
|
-
- lib/nanite/
|
63
|
-
- lib/nanite/log
|
64
|
-
- lib/nanite/state.rb
|
65
|
-
- lib/nanite/cluster.rb
|
66
|
-
- lib/nanite/dispatcher.rb
|
67
|
-
- lib/nanite/security_provider.rb
|
68
|
-
- lib/nanite/packets.rb
|
86
|
+
- lib/nanite/security/certificate_cache.rb
|
87
|
+
- lib/nanite/security/secure_serializer.rb
|
88
|
+
- lib/nanite/streaming.rb
|
89
|
+
- lib/nanite/serializer.rb
|
90
|
+
- lib/nanite/log.rb
|
69
91
|
- lib/nanite/actor.rb
|
70
|
-
- lib/nanite/
|
92
|
+
- lib/nanite/identity.rb
|
71
93
|
- lib/nanite/admin.rb
|
94
|
+
- lib/nanite/state.rb
|
95
|
+
- lib/nanite/util.rb
|
72
96
|
- lib/nanite/amqp.rb
|
73
|
-
- lib/nanite/
|
74
|
-
- lib/nanite/local_state.rb
|
75
|
-
- lib/nanite/identity.rb
|
97
|
+
- lib/nanite/security_provider.rb
|
76
98
|
- lib/nanite/actor_registry.rb
|
77
|
-
- lib/nanite/
|
78
|
-
- lib/nanite/
|
79
|
-
- lib/nanite/job.rb
|
80
|
-
- bin/nanite-agent
|
99
|
+
- lib/nanite/packets.rb
|
100
|
+
- lib/nanite/mapper.rb
|
81
101
|
- bin/nanite-admin
|
102
|
+
- bin/nanite-agent
|
82
103
|
- bin/nanite-mapper
|
83
|
-
- spec/util_spec.rb
|
84
|
-
- spec/encrypted_document_spec.rb
|
85
|
-
- spec/agent_spec.rb
|
86
|
-
- spec/certificate_cache_spec.rb
|
87
|
-
- spec/cached_certificate_store_proxy_spec.rb
|
88
|
-
- spec/dispatcher_spec.rb
|
89
|
-
- spec/rsa_key_pair_spec.rb
|
90
|
-
- spec/cluster_spec.rb
|
91
|
-
- spec/spec_helper.rb
|
92
|
-
- spec/actor_registry_spec.rb
|
93
|
-
- spec/actor_spec.rb
|
94
|
-
- spec/packet_spec.rb
|
95
|
-
- spec/local_state_spec.rb
|
96
|
-
- spec/static_certificate_store_spec.rb
|
97
|
-
- spec/job_spec.rb
|
98
|
-
- spec/signature_spec.rb
|
99
|
-
- spec/secure_serializer_spec.rb
|
100
|
-
- spec/serializer_spec.rb
|
101
|
-
- spec/certificate_spec.rb
|
102
|
-
- spec/distinguished_name_spec.rb
|
103
104
|
has_rdoc: true
|
104
105
|
homepage: http://github.com/ezmobius/nanite
|
105
|
-
licenses:
|
106
|
+
licenses: []
|
107
|
+
|
106
108
|
post_install_message:
|
107
109
|
rdoc_options: []
|
108
110
|
|
@@ -112,20 +114,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
112
114
|
requirements:
|
113
115
|
- - ">="
|
114
116
|
- !ruby/object:Gem::Version
|
117
|
+
segments:
|
118
|
+
- 0
|
115
119
|
version: "0"
|
116
|
-
version:
|
117
120
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
121
|
requirements:
|
119
122
|
- - ">="
|
120
123
|
- !ruby/object:Gem::Version
|
124
|
+
segments:
|
125
|
+
- 0
|
121
126
|
version: "0"
|
122
|
-
version:
|
123
127
|
requirements: []
|
124
128
|
|
125
129
|
rubyforge_project:
|
126
|
-
rubygems_version: 1.3.
|
130
|
+
rubygems_version: 1.3.6
|
127
131
|
signing_key:
|
128
|
-
specification_version:
|
132
|
+
specification_version: 3
|
129
133
|
summary: self assembling fabric of ruby daemons
|
130
134
|
test_files: []
|
131
135
|
|
data/spec/actor_registry_spec.rb
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
-
|
3
|
-
describe Nanite::ActorRegistry do
|
4
|
-
|
5
|
-
class ::WebDocumentImporter
|
6
|
-
include Nanite::Actor
|
7
|
-
expose :import, :cancel
|
8
|
-
|
9
|
-
def import
|
10
|
-
1
|
11
|
-
end
|
12
|
-
def cancel
|
13
|
-
0
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
module ::Actors
|
18
|
-
class ComedyActor
|
19
|
-
include Nanite::Actor
|
20
|
-
expose :fun_tricks
|
21
|
-
def fun_tricks
|
22
|
-
:rabbit_in_the_hat
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
before(:each) do
|
28
|
-
Nanite::Log.stub!(:info)
|
29
|
-
@registry = Nanite::ActorRegistry.new
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should know about all services" do
|
33
|
-
@registry.register(WebDocumentImporter.new, nil)
|
34
|
-
@registry.register(Actors::ComedyActor.new, nil)
|
35
|
-
@registry.services.sort.should == ["/actors/comedy_actor/fun_tricks", "/web_document_importer/cancel", "/web_document_importer/import"]
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should not register anything except Nanite::Actor" do
|
39
|
-
lambda { @registry.register(String.new, nil) }.should raise_error(ArgumentError)
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should register an actor" do
|
43
|
-
importer = WebDocumentImporter.new
|
44
|
-
@registry.register(importer, nil)
|
45
|
-
@registry.actors['web_document_importer'].should == importer
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should log info message that actor was registered" do
|
49
|
-
importer = WebDocumentImporter.new
|
50
|
-
Nanite::Log.should_receive(:info).with("[actor] #{importer.class.to_s}")
|
51
|
-
@registry.register(importer, nil)
|
52
|
-
end
|
53
|
-
|
54
|
-
it "should handle actors registered with a custom prefix" do
|
55
|
-
importer = WebDocumentImporter.new
|
56
|
-
@registry.register(importer, 'monkey')
|
57
|
-
@registry.actor_for('monkey').should == importer
|
58
|
-
end
|
59
|
-
|
60
|
-
end # Nanite::ActorRegistry
|