dryad-cluster 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +9 -7
- data/dryad-cluster.gemspec +1 -0
- data/lib/dryad/cluster.rb +21 -1
- data/lib/dryad/cluster/round_robin.rb +22 -0
- data/lib/dryad/cluster/version.rb +1 -1
- metadata +25 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4e41d97f7f444f717e1eb18d83be6d91ad8bc2193614e30f3a89ae32db76ac5
|
4
|
+
data.tar.gz: 4414921185b93261f6fd4480b20269db784e2be38630bce346d291ff2c9ee579
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82491e5a318d0a607119a0ff486d9a054309f6167e90e39da2592e453277e25eeb7a10df706bfbfe9576aa4159206f687dcdd99fdbb96e614bf5d71828df5b99
|
7
|
+
data.tar.gz: 9d318d37a0f10da3787301ab060f7c4863a2f3bdc3f0d998662d7bc75326be438be882b9870154e766acc8d52572d4317bf46c2c49796d85f8397137818a5431
|
data/Gemfile.lock
CHANGED
@@ -1,24 +1,26 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
dryad-cluster (0.1.
|
5
|
-
|
4
|
+
dryad-cluster (0.1.1)
|
5
|
+
concurrent-ruby (~> 1.1, >= 1.1.5)
|
6
|
+
dryad-core (= 0.1.1)
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
9
10
|
specs:
|
11
|
+
concurrent-ruby (1.1.5)
|
10
12
|
deep_merge (1.2.1)
|
11
13
|
diff-lcs (1.3)
|
12
14
|
diplomat (2.2.4)
|
13
15
|
deep_merge (~> 1.0, >= 1.0.1)
|
14
16
|
faraday (~> 0.9)
|
15
|
-
dryad-consul (0.1.
|
16
|
-
diplomat
|
17
|
-
dryad-core (= 0.1.
|
18
|
-
dryad-core (0.1.
|
17
|
+
dryad-consul (0.1.1)
|
18
|
+
diplomat (~> 2.2, >= 2.2.4)
|
19
|
+
dryad-core (= 0.1.1)
|
20
|
+
dryad-core (0.1.1)
|
19
21
|
faraday (0.15.4)
|
20
22
|
multipart-post (>= 1.2, < 3)
|
21
|
-
multipart-post (2.1.
|
23
|
+
multipart-post (2.1.1)
|
22
24
|
rake (10.5.0)
|
23
25
|
rspec (3.8.0)
|
24
26
|
rspec-core (~> 3.8.0)
|
data/dryad-cluster.gemspec
CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
24
|
spec.add_dependency "dryad-core", Dryad::Cluster::VERSION
|
25
|
+
spec.add_dependency "concurrent-ruby", "~> 1.1", ">= 1.1.5"
|
25
26
|
|
26
27
|
spec.add_development_dependency "bundler", "~> 2.0"
|
27
28
|
spec.add_development_dependency "rake", "~> 10.0"
|
data/lib/dryad/cluster.rb
CHANGED
@@ -1,16 +1,36 @@
|
|
1
|
+
require 'concurrent'
|
1
2
|
require "dryad"
|
2
3
|
require "dryad/cluster/version"
|
4
|
+
require "dryad/cluster/round_robin"
|
3
5
|
|
4
6
|
module Dryad
|
5
7
|
module Cluster
|
6
8
|
class Error < StandardError; end
|
9
|
+
class NoServicesError < Error; end
|
7
10
|
|
8
11
|
class << self
|
9
12
|
REGISTRY = Object.const_get(Dryad.configuration.registry)
|
13
|
+
CLUSTERS = {}
|
10
14
|
|
11
15
|
def round_robin(schema, service_name)
|
12
16
|
groups = ['_global_', Dryad.configuration.group]
|
13
|
-
|
17
|
+
full_name = Dryad::Core::Service.full_name(schema, service_name)
|
18
|
+
if CLUSTERS[full_name].nil?
|
19
|
+
CLUSTERS[full_name] = Dryad::Cluster::RoundRobin.new
|
20
|
+
CLUSTERS[full_name].set_services(sorted_instances(service_name, schema, groups))
|
21
|
+
end
|
22
|
+
begin
|
23
|
+
retries ||= 0
|
24
|
+
CLUSTERS[full_name].service
|
25
|
+
rescue Dryad::Cluster::NoServicesError
|
26
|
+
CLUSTERS[full_name].set_services(sorted_instances(service_name, schema, groups))
|
27
|
+
retry if (retries += 1) < 2
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def sorted_instances(service_name, schema, groups)
|
32
|
+
sis = REGISTRY.service_instances(service_name, schema, groups)
|
33
|
+
sis.sort {|a, b| "#{a.address}:#{a.port}" <=> "#{b.address}:#{b.port}"}
|
14
34
|
end
|
15
35
|
end
|
16
36
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Dryad
|
2
|
+
module Cluster
|
3
|
+
class RoundRobin
|
4
|
+
def initialize
|
5
|
+
@index = Concurrent::AtomicFixnum.new
|
6
|
+
@services = Concurrent::AtomicReference.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def set_services(instances)
|
10
|
+
@services.set(instances)
|
11
|
+
end
|
12
|
+
|
13
|
+
def service
|
14
|
+
instances = @services.get()
|
15
|
+
if instances.nil? || instances.empty?
|
16
|
+
raise Dryad::Cluster::NoServicesError, "Round robin nodes are empty."
|
17
|
+
end
|
18
|
+
instances[@index.increment % instances.size]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dryad-cluster
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pan Jie
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-05-
|
11
|
+
date: 2019-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dryad-core
|
@@ -16,14 +16,34 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.1.
|
19
|
+
version: 0.1.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.1.
|
26
|
+
version: 0.1.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: concurrent-ruby
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.1'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 1.1.5
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '1.1'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 1.1.5
|
27
47
|
- !ruby/object:Gem::Dependency
|
28
48
|
name: bundler
|
29
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -84,6 +104,7 @@ files:
|
|
84
104
|
- bin/setup
|
85
105
|
- dryad-cluster.gemspec
|
86
106
|
- lib/dryad/cluster.rb
|
107
|
+
- lib/dryad/cluster/round_robin.rb
|
87
108
|
- lib/dryad/cluster/version.rb
|
88
109
|
homepage: https://github.com/jack0pan/dryad.rb
|
89
110
|
licenses:
|