ruby_skynet 1.3.0.alpha3 → 2.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ruby_skynet.rb +5 -11
- data/lib/ruby_skynet/client.rb +15 -8
- data/lib/ruby_skynet/common.rb +54 -14
- data/lib/ruby_skynet/connection.rb +56 -16
- data/lib/ruby_skynet/doozer/service_registry.rb +14 -3
- data/lib/ruby_skynet/railties/ruby_skynet.rake +7 -10
- data/lib/ruby_skynet/ruby_skynet.rb +2 -9
- data/lib/ruby_skynet/server.rb +62 -75
- data/lib/ruby_skynet/service.rb +1 -4
- data/lib/ruby_skynet/version.rb +1 -1
- data/lib/ruby_skynet/zookeeper/service_registry.rb +14 -3
- metadata +32 -28
- data/Gemfile +0 -20
- data/Gemfile.lock +0 -45
- data/Rakefile +0 -44
- data/lib/ruby_skynet/base.rb +0 -47
- data/lib/ruby_skynet/static_service_registry.rb +0 -75
- data/ruby_skynet.gemspec +0 -25
- data/test/client_test.rb +0 -120
- data/test/service_registry_test.rb +0 -122
- data/test/service_test.rb +0 -71
- data/test/zookeeper_registry_test.rb +0 -209
data/lib/ruby_skynet/service.rb
CHANGED
@@ -11,13 +11,10 @@ module RubySkynet
|
|
11
11
|
module Service
|
12
12
|
|
13
13
|
def self.included(base)
|
14
|
-
base.extend ::RubySkynet::
|
14
|
+
base.extend ::RubySkynet::Common::ClassMethods
|
15
15
|
base.class_eval do
|
16
16
|
include SemanticLogger::Loggable
|
17
17
|
end
|
18
|
-
# Register the service with the Server
|
19
|
-
# The server will publish the server to services registry when the server is running
|
20
|
-
Server.register_service(base)
|
21
18
|
end
|
22
19
|
|
23
20
|
end
|
data/lib/ruby_skynet/version.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'semantic_logger'
|
2
2
|
require 'thread_safe'
|
3
|
+
require 'gene_pool'
|
3
4
|
require 'resolv'
|
4
5
|
|
5
6
|
#
|
@@ -75,6 +76,18 @@ module RubySkynet
|
|
75
76
|
uuid
|
76
77
|
end
|
77
78
|
|
79
|
+
# Return a server that implements the specified service
|
80
|
+
def server_for(name, version='*', region=RubySkynet.region)
|
81
|
+
if servers = servers_for(name, version, region)
|
82
|
+
# Randomly select one of the servers offering the service
|
83
|
+
servers[rand(servers.size)]
|
84
|
+
else
|
85
|
+
msg = "No servers available for service: #{name} with version: #{version} in region: #{region}"
|
86
|
+
logger.warn msg
|
87
|
+
raise ServiceUnavailable.new(msg)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
78
91
|
# Returns [Array<String>] a list of servers implementing the requested service
|
79
92
|
def servers_for(name, version='*', region=RubySkynet.region)
|
80
93
|
if version == '*'
|
@@ -87,11 +100,9 @@ module RubySkynet
|
|
87
100
|
end
|
88
101
|
end
|
89
102
|
end
|
90
|
-
|
103
|
+
if server_infos = @cache["#{name}/#{version}/#{region}"]
|
91
104
|
server_infos.first.servers
|
92
105
|
end
|
93
|
-
raise ServiceUnavailable.new("No servers available for service: #{name} with version: #{version} in region: #{region}") unless servers
|
94
|
-
servers
|
95
106
|
end
|
96
107
|
|
97
108
|
# Invokes registered callbacks when a specific server is shutdown or terminates
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_skynet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Reid Morrison
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: semantic_logger
|
@@ -39,47 +39,61 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.5.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: gene_pool
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 1.
|
47
|
+
version: 1.3.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 1.
|
54
|
+
version: 1.3.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: sync_attr
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 1.
|
61
|
+
version: 1.0.0
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 1.
|
68
|
+
version: 1.0.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: bson
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 2.0.0.rc3
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 2.0.0.rc3
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: thread_safe
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
87
|
- - '>='
|
74
88
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
89
|
+
version: '0'
|
76
90
|
type: :runtime
|
77
91
|
prerelease: false
|
78
92
|
version_requirements: !ruby/object:Gem::Requirement
|
79
93
|
requirements:
|
80
94
|
- - '>='
|
81
95
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
96
|
+
version: '0'
|
83
97
|
description: Ruby Client for invoking Skynet services
|
84
98
|
email:
|
85
99
|
- reidmo@gmail.com
|
@@ -87,17 +101,8 @@ executables: []
|
|
87
101
|
extensions: []
|
88
102
|
extra_rdoc_files: []
|
89
103
|
files:
|
90
|
-
- Gemfile
|
91
|
-
- Gemfile.lock
|
92
|
-
- LICENSE.txt
|
93
|
-
- README.md
|
94
|
-
- Rakefile
|
95
|
-
- examples/echo_client.rb
|
96
|
-
- examples/echo_server.rb
|
97
104
|
- lib/rails/generators/ruby_skynet/config/config_generator.rb
|
98
105
|
- lib/rails/generators/ruby_skynet/config/templates/ruby_skynet.yml
|
99
|
-
- lib/ruby_skynet.rb
|
100
|
-
- lib/ruby_skynet/base.rb
|
101
106
|
- lib/ruby_skynet/client.rb
|
102
107
|
- lib/ruby_skynet/common.rb
|
103
108
|
- lib/ruby_skynet/connection.rb
|
@@ -108,20 +113,19 @@ files:
|
|
108
113
|
- lib/ruby_skynet/ruby_skynet.rb
|
109
114
|
- lib/ruby_skynet/server.rb
|
110
115
|
- lib/ruby_skynet/service.rb
|
111
|
-
- lib/ruby_skynet/static_service_registry.rb
|
112
116
|
- lib/ruby_skynet/version.rb
|
113
|
-
- lib/ruby_skynet/zookeeper.rb
|
114
117
|
- lib/ruby_skynet/zookeeper/cached_registry.rb
|
115
118
|
- lib/ruby_skynet/zookeeper/extensions/java_base.rb
|
116
119
|
- lib/ruby_skynet/zookeeper/json/deserializer.rb
|
117
120
|
- lib/ruby_skynet/zookeeper/json/serializer.rb
|
118
121
|
- lib/ruby_skynet/zookeeper/registry.rb
|
119
122
|
- lib/ruby_skynet/zookeeper/service_registry.rb
|
120
|
-
- ruby_skynet.
|
121
|
-
-
|
122
|
-
-
|
123
|
-
-
|
124
|
-
-
|
123
|
+
- lib/ruby_skynet/zookeeper.rb
|
124
|
+
- lib/ruby_skynet.rb
|
125
|
+
- examples/echo_client.rb
|
126
|
+
- examples/echo_server.rb
|
127
|
+
- LICENSE.txt
|
128
|
+
- README.md
|
125
129
|
homepage: https://github.com/ClarityServices/ruby_skynet
|
126
130
|
licenses:
|
127
131
|
- Apache License V2.0
|
@@ -142,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
146
|
version: 1.3.1
|
143
147
|
requirements: []
|
144
148
|
rubyforge_project:
|
145
|
-
rubygems_version: 2.
|
149
|
+
rubygems_version: 2.0.3
|
146
150
|
signing_key:
|
147
151
|
specification_version: 4
|
148
152
|
summary: Skynet Ruby Client
|
data/Gemfile
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
group :test do
|
4
|
-
gem "shoulda"
|
5
|
-
end
|
6
|
-
|
7
|
-
gem "rake"
|
8
|
-
gem "semantic_logger", ">= 2.1"
|
9
|
-
gem "resilient_socket"
|
10
|
-
# Doozer Client
|
11
|
-
#gem "ruby_doozer"
|
12
|
-
# Zookeeper Client
|
13
|
-
#gem "zookeeper"
|
14
|
-
# Thread Safe Hash and Array
|
15
|
-
gem "thread_safe"
|
16
|
-
# For looking up Service entries in Service Registry
|
17
|
-
gem "multi_json"
|
18
|
-
# Wire format when communicating with services
|
19
|
-
gem "bson", '1.5.2'
|
20
|
-
gem "bson_ext", :platform => :ruby
|
data/Gemfile.lock
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
GEM
|
2
|
-
remote: https://rubygems.org/
|
3
|
-
specs:
|
4
|
-
activesupport (4.0.2)
|
5
|
-
i18n (~> 0.6, >= 0.6.4)
|
6
|
-
minitest (~> 4.2)
|
7
|
-
multi_json (~> 1.3)
|
8
|
-
thread_safe (~> 0.1)
|
9
|
-
tzinfo (~> 0.3.37)
|
10
|
-
atomic (1.1.14)
|
11
|
-
bson (1.5.2)
|
12
|
-
bson_ext (1.5.2)
|
13
|
-
bson (= 1.5.2)
|
14
|
-
i18n (0.6.9)
|
15
|
-
minitest (4.7.5)
|
16
|
-
multi_json (1.8.2)
|
17
|
-
rake (10.1.0)
|
18
|
-
resilient_socket (0.5.0)
|
19
|
-
semantic_logger (>= 2.1)
|
20
|
-
semantic_logger (2.6.1)
|
21
|
-
sync_attr (>= 1.0)
|
22
|
-
thread_safe (>= 0.1.0)
|
23
|
-
shoulda (3.5.0)
|
24
|
-
shoulda-context (~> 1.0, >= 1.0.1)
|
25
|
-
shoulda-matchers (>= 1.4.1, < 3.0)
|
26
|
-
shoulda-context (1.1.6)
|
27
|
-
shoulda-matchers (2.4.0)
|
28
|
-
activesupport (>= 3.0.0)
|
29
|
-
sync_attr (1.0.0)
|
30
|
-
thread_safe (0.1.3)
|
31
|
-
atomic
|
32
|
-
tzinfo (0.3.38)
|
33
|
-
|
34
|
-
PLATFORMS
|
35
|
-
ruby
|
36
|
-
|
37
|
-
DEPENDENCIES
|
38
|
-
bson (= 1.5.2)
|
39
|
-
bson_ext
|
40
|
-
multi_json
|
41
|
-
rake
|
42
|
-
resilient_socket
|
43
|
-
semantic_logger (>= 2.1)
|
44
|
-
shoulda
|
45
|
-
thread_safe
|
data/Rakefile
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
lib = File.expand_path('../lib/', __FILE__)
|
2
|
-
$:.unshift lib unless $:.include?(lib)
|
3
|
-
|
4
|
-
require 'rubygems'
|
5
|
-
require 'rubygems/package'
|
6
|
-
require 'rake/clean'
|
7
|
-
require 'rake/testtask'
|
8
|
-
require 'date'
|
9
|
-
require 'semantic_logger'
|
10
|
-
require 'ruby_skynet/version'
|
11
|
-
|
12
|
-
desc "Build gem"
|
13
|
-
task :gem do |t|
|
14
|
-
gemspec = Gem::Specification.new do |spec|
|
15
|
-
spec.name = 'ruby_skynet'
|
16
|
-
spec.version = RubySkynet::VERSION
|
17
|
-
spec.platform = Gem::Platform::RUBY
|
18
|
-
spec.authors = ['Reid Morrison']
|
19
|
-
spec.email = ['reidmo@gmail.com']
|
20
|
-
spec.homepage = 'https://github.com/ClarityServices/ruby_skynet'
|
21
|
-
spec.date = Date.today.to_s
|
22
|
-
spec.summary = "Skynet Ruby Client"
|
23
|
-
spec.description = "Ruby Client for invoking Skynet services"
|
24
|
-
spec.files = FileList["./**/*"].exclude(/\.gem$/, /\.log$/,/nbproject/).map{|f| f.sub(/^\.\//, '')}
|
25
|
-
spec.license = "Apache License V2.0"
|
26
|
-
spec.has_rdoc = true
|
27
|
-
spec.add_dependency 'semantic_logger', '>= 2.1.0'
|
28
|
-
spec.add_dependency 'resilient_socket', '>= 0.5.0'
|
29
|
-
spec.add_dependency 'bson', '>= 1.5.2'
|
30
|
-
spec.add_dependency 'gene_pool', '>= 1.3.0'
|
31
|
-
spec.add_dependency 'sync_attr', '>= 1.0.0'
|
32
|
-
end
|
33
|
-
Gem::Package.build gemspec
|
34
|
-
end
|
35
|
-
|
36
|
-
desc "Run Test Suite"
|
37
|
-
task :test do
|
38
|
-
Rake::TestTask.new(:functional) do |t|
|
39
|
-
t.test_files = FileList['test/*_test.rb']
|
40
|
-
t.verbose = true
|
41
|
-
end
|
42
|
-
|
43
|
-
Rake::Task['functional'].invoke
|
44
|
-
end
|
data/lib/ruby_skynet/base.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'semantic_logger'
|
2
|
-
|
3
|
-
# Base class for RubySkynet Clients and Services
|
4
|
-
module RubySkynet
|
5
|
-
module Base
|
6
|
-
def self.included(base)
|
7
|
-
base.extend ClassMethods
|
8
|
-
base.class_eval do
|
9
|
-
include SemanticLogger::Loggable
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
module ClassMethods
|
14
|
-
# Name of this service to Register with Skynet
|
15
|
-
# Default: class name
|
16
|
-
def skynet_name
|
17
|
-
@skynet_name ||= name.gsub('::', '.')
|
18
|
-
end
|
19
|
-
|
20
|
-
def skynet_name=(skynet_name)
|
21
|
-
@skynet_name = skynet_name
|
22
|
-
end
|
23
|
-
|
24
|
-
# Version of this service to register with Skynet
|
25
|
-
# Default: nil
|
26
|
-
def skynet_version
|
27
|
-
@skynet_version ||= nil
|
28
|
-
end
|
29
|
-
|
30
|
-
def skynet_version=(skynet_version)
|
31
|
-
@skynet_version = skynet_version
|
32
|
-
end
|
33
|
-
|
34
|
-
# Region within which this service is defined
|
35
|
-
# Default: RubySkynet.region
|
36
|
-
def skynet_region
|
37
|
-
@skynet_region || ::RubySkynet.region
|
38
|
-
end
|
39
|
-
|
40
|
-
def skynet_region=(skynet_region)
|
41
|
-
@skynet_region = skynet_region
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
47
|
-
end
|
@@ -1,75 +0,0 @@
|
|
1
|
-
require 'semantic_logger'
|
2
|
-
require 'thread_safe'
|
3
|
-
|
4
|
-
#
|
5
|
-
# RubySkynet Sevices Registry
|
6
|
-
#
|
7
|
-
# Loads a list of all services and which servers they are available on from a
|
8
|
-
# static YAML file
|
9
|
-
#
|
10
|
-
# Format of the YAML file
|
11
|
-
# key: [String] "<name>/<version>/<region>"
|
12
|
-
# value: [Array<String>] 'host:port', 'host:port'
|
13
|
-
#
|
14
|
-
module RubySkynet
|
15
|
-
class StaticServiceRegistry
|
16
|
-
include SemanticLogger::Loggable
|
17
|
-
|
18
|
-
# Create a service registry
|
19
|
-
def initialize(params = {})
|
20
|
-
@services = params[:registry]
|
21
|
-
raise "Missing :registry in config that must list the availables services" unless @services
|
22
|
-
end
|
23
|
-
|
24
|
-
# Returns the Service Registry as a Hash
|
25
|
-
def to_h
|
26
|
-
@services.dup
|
27
|
-
end
|
28
|
-
|
29
|
-
# Register the supplied service at this Skynet Server host and Port
|
30
|
-
# Returns the UUID for the service that was created
|
31
|
-
def register_service(name, version, region, hostname, port)
|
32
|
-
server = "#{hostname}:#{port}"
|
33
|
-
key = "#{name}/#{version}/#{region}"
|
34
|
-
(@services[key] ||= []) << server
|
35
|
-
key
|
36
|
-
end
|
37
|
-
|
38
|
-
# Deregister the supplied service from the Registry
|
39
|
-
def deregister_service(name, version, region, hostname, port)
|
40
|
-
server = "#{hostname}:#{port}"
|
41
|
-
key = "#{name}/#{version}/#{region}"
|
42
|
-
if servers = @services[key]
|
43
|
-
servers.delete_if {|s| s == server}
|
44
|
-
@services.delete(key) if servers.count == 0
|
45
|
-
end
|
46
|
-
key
|
47
|
-
end
|
48
|
-
|
49
|
-
# Returns [Array<String>] a list of servers implementing the requested service
|
50
|
-
def servers_for(name, version='*', region=RubySkynet.region)
|
51
|
-
if version == '*'
|
52
|
-
# Find the highest version for the named service in this region
|
53
|
-
version = -1
|
54
|
-
@services.keys.each do |key|
|
55
|
-
if match = key.match(/#{name}\/(\d+)\/#{region}/)
|
56
|
-
ver = match[1].to_i
|
57
|
-
version = ver if ver > version
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
servers = @services["#{name}/#{version}/#{region}"]
|
62
|
-
raise ServiceUnavailable.new("No servers available for service: #{name} with version: #{version} in region: #{region}") unless servers
|
63
|
-
servers
|
64
|
-
end
|
65
|
-
|
66
|
-
# Invokes registered callbacks when a specific server is shutdown or terminates
|
67
|
-
# Not when a server de-registers itself
|
68
|
-
# The callback will only be called once and will need to be re-registered
|
69
|
-
# after being called if future callbacks are required for that server
|
70
|
-
def on_server_removed(server, &block)
|
71
|
-
#nop
|
72
|
-
end
|
73
|
-
|
74
|
-
end
|
75
|
-
end
|
data/ruby_skynet.gemspec
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
lib = File.expand_path('../lib/', __FILE__)
|
2
|
-
$:.unshift lib unless $:.include?(lib)
|
3
|
-
|
4
|
-
require 'date'
|
5
|
-
require 'ruby_skynet/version'
|
6
|
-
|
7
|
-
Gem::Specification.new do |spec|
|
8
|
-
spec.name = 'ruby_skynet'
|
9
|
-
spec.version = RubySkynet::VERSION
|
10
|
-
spec.platform = Gem::Platform::RUBY
|
11
|
-
spec.authors = ['Reid Morrison']
|
12
|
-
spec.email = ['reidmo@gmail.com']
|
13
|
-
spec.homepage = 'https://github.com/ClarityServices/ruby_skynet'
|
14
|
-
spec.date = Date.today.to_s
|
15
|
-
spec.summary = "Skynet Ruby Client"
|
16
|
-
spec.description = "Ruby Client for invoking Skynet services"
|
17
|
-
spec.files = Dir.glob("lib/**/*") + Dir.glob("examples/**/*.rb") + %w(LICENSE.txt README.md)
|
18
|
-
spec.license = "Apache License V2.0"
|
19
|
-
spec.has_rdoc = true
|
20
|
-
spec.add_dependency 'semantic_logger', '>= 2.6.1'
|
21
|
-
spec.add_dependency 'resilient_socket', '>= 0.5.0'
|
22
|
-
spec.add_dependency 'sync_attr', '>= 1.0.0'
|
23
|
-
spec.add_dependency 'bson', '>= 1.5.2'
|
24
|
-
spec.add_dependency 'thread_safe'
|
25
|
-
end
|