dryad 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/DRYAD_VERSION +1 -1
- data/Gemfile.lock +13 -11
- data/dryad-cluster/Gemfile.lock +9 -7
- data/dryad-cluster/dryad-cluster.gemspec +1 -0
- data/dryad-cluster/lib/dryad/cluster/round_robin.rb +22 -0
- data/dryad-cluster/lib/dryad/cluster/version.rb +1 -1
- data/dryad-cluster/lib/dryad/cluster.rb +21 -1
- data/dryad-cluster/spec/dryad/cluster/round_robin_spec.rb +21 -0
- data/dryad-consul/Gemfile.lock +5 -5
- data/dryad-consul/dryad-consul.gemspec +1 -1
- data/dryad-consul/lib/dryad/consul/service_registry.rb +16 -7
- data/dryad-consul/lib/dryad/consul/version.rb +1 -1
- data/dryad-core/lib/dryad/core/version.rb +1 -1
- metadata +10 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d9594581141bcb13f995274f1c0595bfc9a8c484f3771c93ca670f5d2ccb307
|
4
|
+
data.tar.gz: 0daaea2d4d0ae211b295e95f00102454301c895472100b17bd7bfa75ed205139
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a849308bd935c9baff26091a94285f4856196db8e376c64b16f57bfed4274dfbc82f5f2492574f5b545a08872e48ef60dbe1b3afc1a7dbeb4c93af9d5b773fb0
|
7
|
+
data.tar.gz: 70bf1b581b64e1924cb340620b8e93a556ea8d1a0465eb83f641bdc1cdf966241717260bfcc0ae6e37d39aedd80d7b4c30e543eb5b12d0ffb6f226586455f2e9
|
data/DRYAD_VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/Gemfile.lock
CHANGED
@@ -1,20 +1,22 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
dryad (0.1.
|
5
|
-
dryad-cluster (= 0.1.
|
6
|
-
dryad-consul (= 0.1.
|
7
|
-
dryad-core (= 0.1.
|
8
|
-
dryad-cluster (0.1.
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
4
|
+
dryad (0.1.1)
|
5
|
+
dryad-cluster (= 0.1.1)
|
6
|
+
dryad-consul (= 0.1.1)
|
7
|
+
dryad-core (= 0.1.1)
|
8
|
+
dryad-cluster (0.1.1)
|
9
|
+
concurrent-ruby (~> 1.1, >= 1.1.5)
|
10
|
+
dryad-core (= 0.1.1)
|
11
|
+
dryad-consul (0.1.1)
|
12
|
+
diplomat (~> 2.2, >= 2.2.4)
|
13
|
+
dryad-core (= 0.1.1)
|
14
|
+
dryad-core (0.1.1)
|
14
15
|
|
15
16
|
GEM
|
16
17
|
remote: https://rubygems.org/
|
17
18
|
specs:
|
19
|
+
concurrent-ruby (1.1.5)
|
18
20
|
deep_merge (1.2.1)
|
19
21
|
diff-lcs (1.3)
|
20
22
|
diplomat (2.2.4)
|
@@ -22,7 +24,7 @@ GEM
|
|
22
24
|
faraday (~> 0.9)
|
23
25
|
faraday (0.15.4)
|
24
26
|
multipart-post (>= 1.2, < 3)
|
25
|
-
multipart-post (2.1.
|
27
|
+
multipart-post (2.1.1)
|
26
28
|
rake (10.5.0)
|
27
29
|
rspec (3.8.0)
|
28
30
|
rspec-core (~> 3.8.0)
|
data/dryad-cluster/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)
|
@@ -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"
|
@@ -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
|
@@ -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,21 @@
|
|
1
|
+
RSpec.describe Dryad::Cluster::RoundRobin do
|
2
|
+
before do
|
3
|
+
@services = Array.new(10) {|index| index + 1}
|
4
|
+
@round_robin = Dryad::Cluster::RoundRobin.new
|
5
|
+
end
|
6
|
+
|
7
|
+
it "set services and get service correctly" do
|
8
|
+
@round_robin.set_services(@services)
|
9
|
+
10.times do |i|
|
10
|
+
expect(@round_robin.service).to eq(@services[(i + 1) % 10])
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it "raises no services error when services are empty" do
|
15
|
+
begin
|
16
|
+
@round_robin.service
|
17
|
+
rescue StandardError => e
|
18
|
+
expect(e.class).to eq(Dryad::Cluster::NoServicesError)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/dryad-consul/Gemfile.lock
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
dryad-consul (0.1.
|
5
|
-
diplomat
|
6
|
-
dryad-core (= 0.1.
|
4
|
+
dryad-consul (0.1.1)
|
5
|
+
diplomat (~> 2.2, >= 2.2.4)
|
6
|
+
dryad-core (= 0.1.1)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
@@ -13,10 +13,10 @@ GEM
|
|
13
13
|
diplomat (2.2.4)
|
14
14
|
deep_merge (~> 1.0, >= 1.0.1)
|
15
15
|
faraday (~> 0.9)
|
16
|
-
dryad-core (0.1.
|
16
|
+
dryad-core (0.1.1)
|
17
17
|
faraday (0.15.4)
|
18
18
|
multipart-post (>= 1.2, < 3)
|
19
|
-
multipart-post (2.1.
|
19
|
+
multipart-post (2.1.1)
|
20
20
|
rake (10.5.0)
|
21
21
|
rspec (3.8.0)
|
22
22
|
rspec-core (~> 3.8.0)
|
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
24
|
spec.add_dependency "dryad-core", Dryad::Consul::VERSION
|
25
|
-
spec.add_dependency "diplomat"
|
25
|
+
spec.add_dependency "diplomat", "~> 2.2", ">= 2.2.4"
|
26
26
|
|
27
27
|
spec.add_development_dependency "bundler", "~> 2.0"
|
28
28
|
spec.add_development_dependency "rake", "~> 10.0"
|
@@ -15,19 +15,28 @@ module Dryad
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def service_instances(name, schema, groups)
|
18
|
-
all_services =
|
19
|
-
|
18
|
+
all_services = ::Diplomat::Health.service(Dryad::Core::Service.full_name(schema, name))
|
19
|
+
service_instances = []
|
20
20
|
all_services.each do |service|
|
21
|
-
|
22
|
-
|
21
|
+
service_hash = service.Service
|
22
|
+
if !service_hash["Meta"].nil? && service_hash["Meta"].has_key?("group") &&
|
23
|
+
groups.include?(service_hash["Meta"]["group"])
|
24
|
+
service_instances << service_hash
|
25
|
+
else
|
26
|
+
groups.each do |group|
|
27
|
+
if service_hash["Tags"].include?("group = \"#{group}\"")
|
28
|
+
service_instances << service_hash
|
29
|
+
break
|
30
|
+
end
|
31
|
+
end
|
23
32
|
end
|
24
33
|
end
|
25
|
-
|
34
|
+
service_instances.map do |service|
|
26
35
|
Dryad::Core::ServiceInstance.new(
|
27
36
|
name: name,
|
28
37
|
schema: schema,
|
29
|
-
address: service
|
30
|
-
port: service
|
38
|
+
address: service["Address"],
|
39
|
+
port: service["Port"]
|
31
40
|
)
|
32
41
|
end
|
33
42
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dryad
|
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,42 +16,42 @@ 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
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: dryad-consul
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - '='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.1.
|
33
|
+
version: 0.1.1
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - '='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.1.
|
40
|
+
version: 0.1.1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: dryad-cluster
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - '='
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.1.
|
47
|
+
version: 0.1.1
|
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: 0.1.
|
54
|
+
version: 0.1.1
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,7 +122,9 @@ files:
|
|
122
122
|
- dryad-cluster/bin/setup
|
123
123
|
- dryad-cluster/dryad-cluster.gemspec
|
124
124
|
- dryad-cluster/lib/dryad/cluster.rb
|
125
|
+
- dryad-cluster/lib/dryad/cluster/round_robin.rb
|
125
126
|
- dryad-cluster/lib/dryad/cluster/version.rb
|
127
|
+
- dryad-cluster/spec/dryad/cluster/round_robin_spec.rb
|
126
128
|
- dryad-cluster/spec/dryad/cluster_spec.rb
|
127
129
|
- dryad-cluster/spec/dummy/config/dryad.yml
|
128
130
|
- dryad-cluster/spec/spec_helper.rb
|