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 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
- if configatron.distribunaut.share_objects
21
- base.class_eval do
22
- include ::DRbUndumped
23
- end
24
- eval %{
25
- class ::Distribunaut::Distributed::#{base}Proxy
26
- include Singleton
27
- include DRbUndumped
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
- def method_missing(sym, *args)
30
- #{base}.send(sym, *args)
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
- obj = "Distribunaut::Distributed::#{base}Proxy".constantize.instance
44
- raise Distribunaut::Distributed::Errors::ApplicationNameUndefined.new if configatron.distribunaut.app_name.nil?
45
- Distribunaut::Utils::Rinda.register_or_renew(:space => "#{base}".to_sym,
46
- :object => obj,
47
- :app_name => configatron.distribunaut.app_name)
48
- end
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
@@ -8,6 +8,8 @@ module DRb # :nodoc:
8
8
  end
9
9
 
10
10
  undef :id if method_defined?(:id)
11
+ undef :kind_of? if method_defined?(:kind_of?)
12
+ undef :is_a? if method_defined?(:is_a?)
11
13
 
12
14
  end
13
15
  end
@@ -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
- DRb.start_service
20
- ring_server = Rinda::RingFinger.primary
21
- services = ring_server.read_all([nil, nil, nil, nil])
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
@@ -21,6 +21,10 @@ module Distribunaut # :nodoc:
21
21
  [self.app_name, self.space, nil, nil]
22
22
  end
23
23
 
24
+ def to_s
25
+ self.to_array.inspect
26
+ end
27
+
24
28
  class << self
25
29
 
26
30
  def from_array(ar)
@@ -2,43 +2,63 @@ module Distribunaut
2
2
  module Utils # :nodoc:
3
3
  module Rinda
4
4
 
5
- def self.register_or_renew(values = {})
6
- tuple = build_tuple(values)
7
- begin
8
- ring_server.take(tuple.to_search_array, tuple.timeout)
9
- rescue ::Rinda::RequestExpiredError => e
10
- # it's ok that it expired. It could be that it was never registered.
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
- register(values)
13
- end
14
-
15
- def self.register(values = {})
16
- tuple = build_tuple(values)
17
- ring_server.write(tuple.to_array, ::Rinda::SimpleRenewer.new)
18
- end
19
-
20
- def self.ring_server
21
- if configatron.distribunaut.retrieve(:acl, nil)
22
- acl = ACL.new(configatron.distribunaut.acl)
23
- DRb.install_acl(acl)
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
- ::DRb.start_service
26
- rs = ::Rinda::RingFinger.primary
27
- rs
28
- end
29
-
30
- def self.read(values = {})
31
- tuple = build_tuple(values)
32
- results = ring_server.read(tuple.to_array, tuple.timeout)
33
- tuple = Distribunaut::Tuple.from_array(results)
34
- tuple.object
35
- end
36
-
37
- private
38
- def self.build_tuple(values = {})
39
- return values if values.is_a?(Distribunaut::Tuple)
40
- Distribunaut::Tuple.new({:timeout => configatron.distribunaut.timeout}.merge(values))
41
- end
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
@@ -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-distributed', 'tasks', '*.rake')).each do |f|
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.20090407
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-04-06 00:00:00 -07:00
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: "0"
23
+ version: 2.3.0
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
- name: cachetastic
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: "0"
33
+ version: 2.0.0
34
34
  version:
35
35
  - !ruby/object:Gem::Dependency
36
- name: addressable
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: "0"
43
+ version: 1.0.10
44
44
  version:
45
45
  - !ruby/object:Gem::Dependency
46
- name: daemons
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: "0"
53
+ version: 2.3.0
54
54
  version:
55
55
  description: "distribunaut was developed by: markbates"
56
56
  email: mark@mackframework.com