markbates-distribunaut 0.1.20090407 → 0.2.1.20090624214017
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/distribunaut.rb +3 -2
- data/lib/distribunaut/distributable.rb +23 -27
- data/lib/distribunaut/extensions/drb_object.rb +2 -0
- data/lib/distribunaut/tasks/ring_server_tasks.rake +9 -8
- data/lib/distribunaut/tuple.rb +4 -0
- data/lib/distribunaut/utils/rinda.rb +55 -35
- data/lib/distribunaut_tasks.rb +1 -3
- metadata +9 -9
data/lib/distribunaut.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'configatron'
|
2
|
-
require 'cachetastic'
|
3
2
|
require 'drb/drb'
|
4
3
|
require 'drb/acl'
|
5
4
|
require 'rinda/ring'
|
@@ -9,7 +8,6 @@ require 'activesupport'
|
|
9
8
|
|
10
9
|
base = File.join(File.dirname(__FILE__), 'distribunaut')
|
11
10
|
|
12
|
-
configatron.distribunaut.set_default(:share_objects, false)
|
13
11
|
configatron.distribunaut.set_default(:app_name, nil)
|
14
12
|
configatron.distribunaut.set_default(:timeout, 0)
|
15
13
|
|
@@ -18,3 +16,6 @@ Dir.glob(File.join(base, "**", "*.rb")).each do |f|
|
|
18
16
|
require(f)
|
19
17
|
end
|
20
18
|
|
19
|
+
# Make sure no one can call eval() and related
|
20
|
+
# methods remotely!
|
21
|
+
$SAFE = 1 unless $SAFE > 0
|
@@ -17,35 +17,31 @@ module Distribunaut # :nodoc:
|
|
17
17
|
module Distributable
|
18
18
|
|
19
19
|
def self.included(base) # :nodoc:
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
20
|
+
base.class_eval do
|
21
|
+
include ::DRbUndumped
|
22
|
+
end
|
23
|
+
c_name = base.name.gsub('::', '_')
|
24
|
+
eval %{
|
25
|
+
class ::Distribunaut::Distributed::#{c_name}Proxy
|
26
|
+
include Singleton
|
27
|
+
include DRbUndumped
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
def inspect
|
34
|
-
#{base}.inspect
|
35
|
-
end
|
36
|
-
|
37
|
-
def to_s
|
38
|
-
#{base}.to_s
|
39
|
-
end
|
40
|
-
|
29
|
+
def method_missing(sym, *args)
|
30
|
+
#{base}.send(sym, *args)
|
41
31
|
end
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
32
|
+
|
33
|
+
undef :id if method_defined?(:id)
|
34
|
+
undef :inspect if method_defined?(:inspect)
|
35
|
+
undef :to_s if method_defined?(:to_s)
|
36
|
+
|
37
|
+
end
|
38
|
+
}
|
39
|
+
obj = "Distribunaut::Distributed::#{c_name}Proxy".constantize.instance
|
40
|
+
raise Distribunaut::Distributed::Errors::ApplicationNameUndefined.new if configatron.distribunaut.app_name.nil?
|
41
|
+
Distribunaut::Utils::Rinda.register_or_renew(:space => "#{base}".to_sym,
|
42
|
+
:object => obj,
|
43
|
+
:description => "#{base} Service",
|
44
|
+
:app_name => configatron.distribunaut.app_name.to_sym)
|
49
45
|
end
|
50
46
|
|
51
47
|
end # Distributable
|
@@ -12,22 +12,23 @@ namespace :distribunaut do
|
|
12
12
|
`distribunaut_ring_server stop`
|
13
13
|
end
|
14
14
|
|
15
|
+
desc "Restart the Rinda ring server"
|
16
|
+
task :restart => [:stop, :start]
|
17
|
+
|
15
18
|
namespace :services do
|
16
19
|
|
17
20
|
desc "Lists all services on the ring server"
|
18
21
|
task :list do
|
19
|
-
|
20
|
-
|
21
|
-
services =
|
22
|
-
puts "Services on #{ring_server.__drburi}"
|
22
|
+
require 'distribunaut'
|
23
|
+
puts "Services on #{Distribunaut::Utils::Rinda.ring_server.__drburi}"
|
24
|
+
services = Distribunaut::Utils::Rinda.available_services
|
23
25
|
services.each do |service|
|
24
|
-
puts "#{service[0]}: #{service[1]} on #{service[2].__drburi} - #{service[3]}"
|
26
|
+
# puts "#{service[0]}: #{service[1]} on #{service[2].__drburi} - #{service[3]}"
|
27
|
+
puts "#{service.app_name}: #{service.space} on #{service.object.__drburi} - #{service.description}"
|
25
28
|
end
|
26
29
|
end
|
27
30
|
|
28
31
|
end # services
|
29
32
|
|
30
33
|
end # ring_server
|
31
|
-
end # distribunaut
|
32
|
-
|
33
|
-
alias_task "distribunaut:ring_server:restart", "distribunaut:ring_server:stop", "distribunaut:ring_server:start"
|
34
|
+
end # distribunaut
|
data/lib/distribunaut/tuple.rb
CHANGED
@@ -2,43 +2,63 @@ module Distribunaut
|
|
2
2
|
module Utils # :nodoc:
|
3
3
|
module Rinda
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def register_or_renew(values = {})
|
8
|
+
tuple = build_tuple(values)
|
9
|
+
begin
|
10
|
+
ring_server.take(tuple.to_search_array, tuple.timeout)
|
11
|
+
rescue ::Rinda::RequestExpiredError => e
|
12
|
+
# it's ok that it expired. It could be that it was never registered.
|
13
|
+
end
|
14
|
+
register(values)
|
11
15
|
end
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
DRb.
|
16
|
+
|
17
|
+
def register(values = {})
|
18
|
+
tuple = build_tuple(values)
|
19
|
+
ring_server.write(tuple.to_array, ::Rinda::SimpleRenewer.new)
|
20
|
+
end
|
21
|
+
|
22
|
+
def ring_server
|
23
|
+
if configatron.distribunaut.retrieve(:acl, nil)
|
24
|
+
acl = ACL.new(configatron.distribunaut.acl)
|
25
|
+
DRb.install_acl(acl)
|
26
|
+
end
|
27
|
+
::DRb.start_service
|
28
|
+
rs = ::Rinda::RingFinger.primary
|
29
|
+
rs
|
24
30
|
end
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
31
|
+
|
32
|
+
def read(values = {})
|
33
|
+
tuple = build_tuple(values)
|
34
|
+
results = ring_server.read(tuple.to_array, tuple.timeout)
|
35
|
+
tuple = Distribunaut::Tuple.from_array(results)
|
36
|
+
tuple.object
|
37
|
+
end
|
38
|
+
|
39
|
+
def available_services
|
40
|
+
ring_server = self.ring_server
|
41
|
+
all = ring_server.read_all([nil, nil, nil, nil])
|
42
|
+
services = []
|
43
|
+
all.each do |service|
|
44
|
+
services << Distribunaut::Tuple.from_array(service)
|
45
|
+
end
|
46
|
+
services
|
47
|
+
end
|
48
|
+
|
49
|
+
def remove_all_services!
|
50
|
+
available_services.each do |service|
|
51
|
+
ring_server.take(service.to_array)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
def build_tuple(values = {})
|
57
|
+
return values if values.is_a?(Distribunaut::Tuple)
|
58
|
+
Distribunaut::Tuple.new({:timeout => configatron.distribunaut.timeout}.merge(values))
|
59
|
+
end
|
60
|
+
|
61
|
+
end # class << self
|
42
62
|
|
43
63
|
end
|
44
64
|
end
|
data/lib/distribunaut_tasks.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'gems')
|
2
|
-
|
3
1
|
# load tasks
|
4
|
-
Dir.glob(File.join(File.dirname(__FILE__), 'distribunaut
|
2
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'distribunaut', 'tasks', '*.rake')).each do |f|
|
5
3
|
load(f)
|
6
4
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: markbates-distribunaut
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.2.1.20090624214017
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- markbates
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-06-24 00:00:00 -07:00
|
13
13
|
default_executable: distribunaut_ring_server
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,37 +20,37 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version:
|
23
|
+
version: 2.3.0
|
24
24
|
version:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
|
-
name:
|
26
|
+
name: addressable
|
27
27
|
type: :runtime
|
28
28
|
version_requirement:
|
29
29
|
version_requirements: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 2.0.0
|
34
34
|
version:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
|
-
name:
|
36
|
+
name: daemons
|
37
37
|
type: :runtime
|
38
38
|
version_requirement:
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
40
40
|
requirements:
|
41
41
|
- - ">="
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version:
|
43
|
+
version: 1.0.10
|
44
44
|
version:
|
45
45
|
- !ruby/object:Gem::Dependency
|
46
|
-
name:
|
46
|
+
name: activesupport
|
47
47
|
type: :runtime
|
48
48
|
version_requirement:
|
49
49
|
version_requirements: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
51
|
- - ">="
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
53
|
+
version: 2.3.0
|
54
54
|
version:
|
55
55
|
description: "distribunaut was developed by: markbates"
|
56
56
|
email: mark@mackframework.com
|