dryad 0.2.5 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +10 -10
  3. data/dryad.gemspec +2 -0
  4. data/lib/dryad/version.rb +1 -1
  5. metadata +8 -81
  6. data/.gitignore +0 -11
  7. data/.rspec +0 -3
  8. data/.travis.yml +0 -19
  9. data/dryad-cluster/.gitignore +0 -11
  10. data/dryad-cluster/.rspec +0 -3
  11. data/dryad-cluster/Gemfile +0 -4
  12. data/dryad-cluster/Gemfile.lock +0 -50
  13. data/dryad-cluster/LICENSE +0 -19
  14. data/dryad-cluster/README.md +0 -35
  15. data/dryad-cluster/Rakefile +0 -6
  16. data/dryad-cluster/bin/console +0 -14
  17. data/dryad-cluster/bin/setup +0 -8
  18. data/dryad-cluster/dryad-cluster.gemspec +0 -31
  19. data/dryad-cluster/lib/dryad/cluster.rb +0 -40
  20. data/dryad-cluster/lib/dryad/cluster/railtie.rb +0 -15
  21. data/dryad-cluster/lib/dryad/cluster/round_robin.rb +0 -22
  22. data/dryad-cluster/lib/dryad/cluster/version.rb +0 -5
  23. data/dryad-cluster/spec/dryad/cluster/round_robin_spec.rb +0 -21
  24. data/dryad-cluster/spec/dryad/cluster_spec.rb +0 -42
  25. data/dryad-cluster/spec/spec_helper.rb +0 -16
  26. data/dryad-consul/.gitignore +0 -11
  27. data/dryad-consul/.rspec +0 -3
  28. data/dryad-consul/Gemfile +0 -4
  29. data/dryad-consul/Gemfile.lock +0 -45
  30. data/dryad-consul/LICENSE +0 -19
  31. data/dryad-consul/README.md +0 -35
  32. data/dryad-consul/Rakefile +0 -6
  33. data/dryad-consul/bin/console +0 -14
  34. data/dryad-consul/bin/setup +0 -8
  35. data/dryad-consul/dryad-consul.gemspec +0 -30
  36. data/dryad-consul/lib/dryad/consul.rb +0 -23
  37. data/dryad-consul/lib/dryad/consul/config_provider.rb +0 -16
  38. data/dryad-consul/lib/dryad/consul/key_value_client.rb +0 -19
  39. data/dryad-consul/lib/dryad/consul/railtie.rb +0 -28
  40. data/dryad-consul/lib/dryad/consul/service.rb +0 -33
  41. data/dryad-consul/lib/dryad/consul/service_client.rb +0 -15
  42. data/dryad-consul/lib/dryad/consul/service_registry.rb +0 -46
  43. data/dryad-consul/lib/dryad/consul/version.rb +0 -5
  44. data/dryad-consul/spec/dryad/consul/config_provider_spec.rb +0 -18
  45. data/dryad-consul/spec/dryad/consul/key_value_client_spec.rb +0 -22
  46. data/dryad-consul/spec/dryad/consul/service_client_spec.rb +0 -6
  47. data/dryad-consul/spec/dryad/consul/service_registry_spec.rb +0 -33
  48. data/dryad-consul/spec/dryad/consul/service_spec.rb +0 -23
  49. data/dryad-consul/spec/dryad/consul_spec.rb +0 -11
  50. data/dryad-consul/spec/spec_helper.rb +0 -14
  51. data/dryad-core/.gitignore +0 -11
  52. data/dryad-core/.rspec +0 -3
  53. data/dryad-core/.travis.yml +0 -7
  54. data/dryad-core/Gemfile +0 -4
  55. data/dryad-core/Gemfile.lock +0 -35
  56. data/dryad-core/LICENSE +0 -19
  57. data/dryad-core/README.md +0 -35
  58. data/dryad-core/Rakefile +0 -6
  59. data/dryad-core/bin/console +0 -14
  60. data/dryad-core/bin/setup +0 -8
  61. data/dryad-core/dryad-core.gemspec +0 -27
  62. data/dryad-core/lib/dryad/core.rb +0 -15
  63. data/dryad-core/lib/dryad/core/config_desc.rb +0 -13
  64. data/dryad-core/lib/dryad/core/config_provider.rb +0 -9
  65. data/dryad-core/lib/dryad/core/load_balancing.rb +0 -8
  66. data/dryad-core/lib/dryad/core/portal.rb +0 -21
  67. data/dryad-core/lib/dryad/core/schema.rb +0 -9
  68. data/dryad-core/lib/dryad/core/service.rb +0 -39
  69. data/dryad-core/lib/dryad/core/service_instance.rb +0 -14
  70. data/dryad-core/lib/dryad/core/version.rb +0 -5
  71. data/dryad-core/spec/dryad/core/config_desc_spec.rb +0 -11
  72. data/dryad-core/spec/dryad/core/load_balancing_spec.rb +0 -6
  73. data/dryad-core/spec/dryad/core/portal_spec.rb +0 -13
  74. data/dryad-core/spec/dryad/core/schema_spec.rb +0 -7
  75. data/dryad-core/spec/dryad/core/service_instance_spec.rb +0 -7
  76. data/dryad-core/spec/dryad/core/service_spec.rb +0 -14
  77. data/dryad-core/spec/dryad/core_spec.rb +0 -14
  78. data/dryad-core/spec/spec_helper.rb +0 -14
@@ -1,40 +0,0 @@
1
- require 'concurrent'
2
- require "dryad/core"
3
- require "dryad/consul"
4
- require "dryad/cluster/railtie" if defined?(Rails)
5
- require "dryad/cluster/version"
6
- require "dryad/cluster/round_robin"
7
-
8
- module Dryad
9
- module Cluster
10
- class Error < StandardError; end
11
- class NoServicesError < Error; end
12
-
13
- class << self
14
- attr_accessor :configuration
15
- CLUSTERS = {}
16
-
17
- def round_robin(schema, service_name)
18
- groups = ['_global_', @configuration.group]
19
- full_name = Dryad::Core::Service.full_name(schema, service_name)
20
- if CLUSTERS[full_name].nil?
21
- CLUSTERS[full_name] = Dryad::Cluster::RoundRobin.new
22
- CLUSTERS[full_name].set_services(sorted_instances(service_name, schema, groups))
23
- end
24
- begin
25
- retries ||= 0
26
- CLUSTERS[full_name].service
27
- rescue Dryad::Cluster::NoServicesError
28
- CLUSTERS[full_name].set_services(sorted_instances(service_name, schema, groups))
29
- retry if (retries += 1) < 2
30
- end
31
- end
32
-
33
- def sorted_instances(service_name, schema, groups)
34
- registry = Object.const_get(@configuration.registry)
35
- sis = registry.service_instances(service_name, schema, groups)
36
- sis.sort {|a, b| "#{a.address}:#{a.port}" <=> "#{b.address}:#{b.port}"}
37
- end
38
- end
39
- end
40
- end
@@ -1,15 +0,0 @@
1
- require "rails"
2
- require "dryad"
3
-
4
- module Dryad
5
- module Cluster
6
- class Railtie < Rails::Railtie
7
- initializer "dryad_cluster.set_config" do
8
- ActiveSupport.on_load(:dryad_cluster) do
9
- Dryad::Cluster.configuration = Dryad.configuration
10
- end
11
- end
12
- end
13
- end
14
- ActiveSupport.run_load_hooks(:dryad_cluster, Cluster)
15
- end
@@ -1,22 +0,0 @@
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,5 +0,0 @@
1
- module Dryad
2
- module Cluster
3
- VERSION = '0.2.5'
4
- end
5
- end
@@ -1,21 +0,0 @@
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
@@ -1,42 +0,0 @@
1
- RSpec.describe Dryad::Cluster do
2
- before do
3
- config = OpenStruct.new({
4
- consul: { host: "127.0.0.1", port: 8500 },
5
- namespace: "growing-crm",
6
- group: "staging",
7
- registry: "Dryad::Consul::ServiceRegistry"
8
- })
9
- Dryad::Consul.configure_consul(config)
10
- Dryad::Cluster.configuration = config
11
-
12
- @portal = Dryad::Core::Portal.new(
13
- schema: Dryad::Core::Schema::HTTP,
14
- port: 3000,
15
- pattern: '/*',
16
- non_certifications: ['/*']
17
- )
18
- @service = Dryad::Consul::Service.new(
19
- name: 'rails',
20
- address: '127.0.0.1',
21
- group: 'staging',
22
- portals: [@portal],
23
- priority: 10,
24
- load_balancing: [Dryad::Core::LoadBalancing::URL_HASH]
25
- )
26
- end
27
-
28
- it "has a version number" do
29
- expect(Dryad::Cluster::VERSION).not_to be nil
30
- end
31
-
32
- it "rounds robin" do
33
- Dryad::Consul::ServiceRegistry.register(@service)
34
- service_instance = Dryad::Cluster.round_robin(
35
- Dryad::Core::Schema::HTTP,
36
- @service.name
37
- )
38
- expect(service_instance.name).to eq(@service.name)
39
- expect(service_instance.address).to eq(@service.address)
40
- Dryad::Consul::ServiceRegistry.deregister(@service)
41
- end
42
- end
@@ -1,16 +0,0 @@
1
- require "bundler/setup"
2
- require "dryad/core"
3
- require "dryad/consul"
4
- require "dryad/cluster"
5
-
6
- RSpec.configure do |config|
7
- # Enable flags like --only-failures and --next-failure
8
- config.example_status_persistence_file_path = ".rspec_status"
9
-
10
- # Disable RSpec exposing methods globally on `Module` and `main`
11
- config.disable_monkey_patching!
12
-
13
- config.expect_with :rspec do |c|
14
- c.syntax = :expect
15
- end
16
- end
@@ -1,11 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
-
10
- # rspec failure tracking
11
- .rspec_status
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
@@ -1,4 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in dryad-consul.gemspec
4
- gemspec
@@ -1,45 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- dryad-consul (0.2.5)
5
- diplomat (~> 2.2, >= 2.2.4)
6
- dryad-core (= 0.2.5)
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- deep_merge (1.2.1)
12
- diff-lcs (1.3)
13
- diplomat (2.2.5)
14
- deep_merge (~> 1.0, >= 1.0.1)
15
- faraday (~> 0.9)
16
- dryad-core (0.2.5)
17
- faraday (0.15.4)
18
- multipart-post (>= 1.2, < 3)
19
- multipart-post (2.1.1)
20
- rake (10.5.0)
21
- rspec (3.8.0)
22
- rspec-core (~> 3.8.0)
23
- rspec-expectations (~> 3.8.0)
24
- rspec-mocks (~> 3.8.0)
25
- rspec-core (3.8.0)
26
- rspec-support (~> 3.8.0)
27
- rspec-expectations (3.8.3)
28
- diff-lcs (>= 1.2.0, < 2.0)
29
- rspec-support (~> 3.8.0)
30
- rspec-mocks (3.8.0)
31
- diff-lcs (>= 1.2.0, < 2.0)
32
- rspec-support (~> 3.8.0)
33
- rspec-support (3.8.0)
34
-
35
- PLATFORMS
36
- ruby
37
-
38
- DEPENDENCIES
39
- bundler (~> 2.0)
40
- dryad-consul!
41
- rake (~> 10.0)
42
- rspec (~> 3.0)
43
-
44
- BUNDLED WITH
45
- 2.0.1
@@ -1,19 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy
4
- of this software and associated documentation files (the "Software"), to deal
5
- in the Software without restriction, including without limitation the rights
6
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- copies of the Software, and to permit persons to whom the Software is
8
- furnished to do so, subject to the following conditions:
9
-
10
- The above copyright notice and this permission notice shall be included in
11
- all copies or substantial portions of the Software.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- THE SOFTWARE.
@@ -1,35 +0,0 @@
1
- # Dryad::Consul
2
-
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/dryad/consul`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
6
-
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'dryad-consul'
13
- ```
14
-
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install dryad-consul
22
-
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
-
33
- ## Contributing
34
-
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/dryad-consul.
@@ -1,6 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "dryad/consul"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
@@ -1,30 +0,0 @@
1
-
2
- lib = File.expand_path("../lib", __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "dryad/consul/version"
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "dryad-consul"
8
- spec.version = Dryad::Consul::VERSION
9
- spec.authors = ["Pan Jie"]
10
- spec.email = ["panjie@growingio.com"]
11
-
12
- spec.summary = %q{Dryad consul library.}
13
- spec.description = %q{Dryad consul is the adapter for consul.}
14
- spec.homepage = "https://github.com/jack0pan/dryad.rb"
15
- spec.license = "MIT"
16
-
17
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
18
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
- end
20
- spec.bindir = "exe"
21
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
- spec.require_paths = ["lib"]
23
-
24
- spec.add_dependency "dryad-core", Dryad::Consul::VERSION
25
- spec.add_dependency "diplomat", "~> 2.2", ">= 2.2.4"
26
-
27
- spec.add_development_dependency "bundler", "~> 2.0"
28
- spec.add_development_dependency "rake", "~> 10.0"
29
- spec.add_development_dependency "rspec", "~> 3.0"
30
- end
@@ -1,23 +0,0 @@
1
- require "diplomat"
2
- require "dryad/core"
3
- require "dryad/consul/railtie" if defined?(Rails)
4
- require "dryad/consul/version"
5
- require "dryad/consul/service_client"
6
- require "dryad/consul/service_registry"
7
- require "dryad/consul/service"
8
- require "dryad/consul/key_value_client"
9
- require "dryad/consul/config_provider"
10
-
11
- module Dryad
12
- module Consul
13
- class Error < StandardError; end
14
- class << self
15
- def configure_consul(configuration)
16
- ::Diplomat.configure do |config|
17
- config.url = "http://#{configuration.consul[:host]}:#{configuration.consul[:port]}"
18
- config.options = { headers: { "X-Consul-Token" => configuration.consul[:token] } } if configuration.consul[:token]
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1,16 +0,0 @@
1
- module Dryad
2
- module Consul
3
- class ConfigProvider < Dryad::Core::ConfigProvider
4
- class << self
5
- def load(path, listener = nil)
6
- config = Dryad::Consul::KeyValueClient.get(path)
7
- if config.nil?
8
- raise Dryad::Core::ConfigurationNotFound, path
9
- else
10
- Dryad::Core::ConfigDesc.new(path, config.Value, config.ModifyIndex)
11
- end
12
- end
13
- end
14
- end
15
- end
16
- end
@@ -1,19 +0,0 @@
1
- require "ostruct"
2
-
3
- module Dryad
4
- module Consul
5
- class KeyValueClient
6
- class << self
7
-
8
- # Get a value by its key, potentially blocking for the first or next value
9
- # @param key [String] the key
10
- # @return [OpenStruct] The base64-decoded value associated with the key
11
- def get(path)
12
- OpenStruct.new ::Diplomat::Kv.get(path, decode_values: true).first
13
- rescue Diplomat::KeyNotFound
14
- nil
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,28 +0,0 @@
1
- require "rails"
2
- require "dryad"
3
-
4
- module Dryad
5
- module Consul
6
- class Railtie < Rails::Railtie
7
- initializer "dryad_consul.set_consul" do
8
- ActiveSupport.on_load(:dryad_consul) do
9
- Dryad::Consul.configure_consul(Dryad.configuration)
10
- end
11
- end
12
-
13
- initializer "dryad_consul.update_active_record_connection" do
14
- config.after_initialize do
15
- db_path = "#{Dryad.configuration.namespace}/#{Dryad.configuration.group}/database.yml"
16
- db_config = Dryad::Consul::ConfigProvider.load(db_path)
17
- ActiveRecord::Base.configurations = YAML.load(ERB.new(db_config.payload).result)
18
- ActiveRecord::Base.establish_connection(Rails.env.to_sym)
19
- rescue Dryad::Core::ConfigurationNotFound => e
20
- raise e
21
- rescue Exception => e
22
- Rails.logger.warn e.message
23
- end
24
- end
25
- end
26
- end
27
- ActiveSupport.run_load_hooks(:dryad_consul, Consul)
28
- end