gv-bedrock 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b784823a6fd0a8a4c439b669fb61f3813298ad36
4
+ data.tar.gz: e1eda3a6198eedfea9fdf0f86c994ee67ddd16c9
5
+ SHA512:
6
+ metadata.gz: ce47748967e65c541f73afeae4cd8920c0c833c1a3ce8fce0d99eb617923aa417c2f41aec07a03cf754ab814c8f08e34f0f91f2cdc8545661eabe55fec4e1791
7
+ data.tar.gz: 0229aa5da62e39a5ba7851726c81638e431f191d1f22f535f9ceb80e7434572593772f6a6025a59f179849c88605bade422740bb412e05010d6a974a2ca9f71e
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gv-bedrock.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,24 @@
1
+ This is free and unencumbered software released into the public domain.
2
+
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
7
+
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ For more information, please refer to <http://unlicense.org>
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # GV::Bedrock
2
+
3
+ Simple Rinda/Ring Network
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'gv-bedrock'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install gv-bedrock
18
+
19
+ ## Usage
20
+
21
+ gv-bedrock run
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/gv-bedrock/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.test_files = FileList['test/**/test*.rb']
7
+ end
8
+
9
+ task :default => :test
data/bin/gv-bedrock ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'gv/common/cli/server'
4
+ GV::Common::CLI::Server.gen "bedrock", %w(gv/bedrock/server gv/bedrock/config)
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gv/bedrock/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gv-bedrock"
8
+ spec.version = GV::Bedrock::VERSION
9
+ spec.authors = ["Onur Uyar"]
10
+ spec.email = ["me@onuruyar.com"]
11
+ spec.summary = %q{Simple Rinda/Ring Network}
12
+ spec.homepage = "https://github.com/green-valley/gv-bedrock"
13
+ spec.license = "Unlicense"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.5"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "minitest"
23
+ spec.add_dependency "gv-common"
24
+ end
@@ -0,0 +1,54 @@
1
+ require 'gv/bedrock/service'
2
+ require 'gv/common/host_helper'
3
+
4
+ module GV
5
+ module Bedrock
6
+
7
+ ##
8
+ # Etcd Client Service
9
+ #
10
+
11
+ class Config < Service
12
+
13
+ CONFIG_DIR = "/etc/greenvalley/config"
14
+
15
+ include GV::Common::HostHelper
16
+
17
+ def initialize
18
+ super
19
+
20
+ # set tuple space as api
21
+ @api = self.class.space
22
+
23
+ # set default config values
24
+ # by reading files in CONFIG_DIR
25
+ # likely created on server setup
26
+ Dir.glob("#{CONFIG_DIR}/*").each do |config_file|
27
+ key = File.basename(config_file)
28
+ value = (File.read(config_file).chomp rescue nil)
29
+ set key,value
30
+ end
31
+
32
+ end
33
+
34
+ # non blocking tuple reading
35
+ def get key
36
+ @api.read([:config,key,nil],0)[2] rescue nil
37
+ end
38
+
39
+ def set key, value
40
+ @api.write([:config,key,value])
41
+ end
42
+
43
+ def rem key
44
+ @api.take([:config,key,value],0) rescue nil
45
+ end
46
+
47
+ def clear
48
+ rem(nil) while get(nil)
49
+ end
50
+
51
+ end
52
+
53
+ end
54
+ end
@@ -0,0 +1,34 @@
1
+ require 'gv/bedrock'
2
+ require 'drb'
3
+ require 'rinda/ring'
4
+ require 'rinda/tuplespace'
5
+
6
+ module GV
7
+ module Bedrock
8
+ class Server
9
+
10
+ def self.provide
11
+ server = new
12
+ server.start
13
+ end
14
+
15
+ def start
16
+
17
+ DRb.start_service
18
+
19
+ begin
20
+ @ts = Rinda::TupleSpace.new
21
+ @rs = Rinda::RingServer.new(@ts)
22
+ info "#{self.class.name} started on #{DRb.uri}"
23
+ DRb.thread.join
24
+ rescue Errno::EADDRINUSE => e
25
+ error e.inspect
26
+ ensure
27
+ DRb.stop_service
28
+ end
29
+
30
+ end
31
+
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,83 @@
1
+ require 'drb'
2
+ require 'rinda/ring'
3
+ require 'active_support/inflector'
4
+
5
+ module GV
6
+ module Bedrock
7
+
8
+ ##
9
+ # Base class of distributed services
10
+ #
11
+
12
+ class Service
13
+
14
+ include DRb::DRbUndumped
15
+
16
+ class << self
17
+
18
+ ##
19
+ # advertises service into primary tuple space
20
+
21
+ def provide
22
+ DRb.start_service
23
+ provider.provide
24
+ info "Service #{self.name} started on #{DRb.uri}"
25
+ DRb.thread.join
26
+ end
27
+
28
+ ##
29
+ # Default Service Provider
30
+
31
+ def provider
32
+ @@provider ||= Rinda::RingProvider.new(self.name.underscore,self,self.new,nil)
33
+ end
34
+
35
+ ##
36
+ # Retrives service instance
37
+
38
+ def service
39
+ self.find self.name.underscore
40
+ end
41
+
42
+ ##
43
+ # Retrives random service instance
44
+
45
+ def random_service
46
+ services.sample
47
+ end
48
+
49
+ ##
50
+ # Retrives all service instances
51
+
52
+ def services
53
+ space.read_all([:name,self.name.underscore,nil,nil]).map{|s| s[3]} rescue []
54
+ end
55
+
56
+ ##
57
+ # Finds previously provided service, blocks if there isn't any
58
+
59
+ def find name
60
+ space.read([:name,name,nil,nil])[3] rescue nil
61
+ end
62
+
63
+ ##
64
+ # Primary remote tuple space
65
+
66
+ def space
67
+ @@space ||= Rinda::TupleSpaceProxy.new(Rinda::RingFinger.primary)
68
+ end
69
+
70
+ end
71
+
72
+ def method_missing name, *args, &block
73
+ if @api.respond_to? name
74
+ @api.public_send name, *args, &block
75
+ else
76
+ super name, *args, &block
77
+ end
78
+ end
79
+
80
+ end
81
+
82
+ end
83
+ end
@@ -0,0 +1,5 @@
1
+ module GV
2
+ module Bedrock
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
data/lib/gv/bedrock.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "gv/common/logging"
2
+ require "gv/bedrock/version"
3
+ require "gv/bedrock/service"
4
+
5
+ module GV
6
+ module Bedrock
7
+ end
8
+ end
@@ -0,0 +1,45 @@
1
+ require 'minitest_helper'
2
+ require 'gv/bedrock/config'
3
+
4
+ module GV
5
+ module Bedrock
6
+ class TestConfig < Minitest::Test
7
+
8
+ def setup
9
+ start_server
10
+ end
11
+
12
+ def stop
13
+ stop_server
14
+ end
15
+
16
+ def test_discovery
17
+ pid = provide GV::Bedrock::Config
18
+
19
+ DRb.start_service
20
+
21
+ service = GV::Bedrock::Config.service
22
+ refute_nil service
23
+
24
+ refute_nil service.set("key", "value")
25
+ assert_equal "value", service.get("key")
26
+
27
+ refute_nil service.get("domain")
28
+ refute_nil service.get("home")
29
+ refute_nil service.get("user")
30
+
31
+ service.clear
32
+ # clear all services
33
+ GV::Bedrock::Service.space.read_all([nil,nil,nil,nil]).each do |t|
34
+ GV::Bedrock::Service.space.take(t)
35
+ end
36
+
37
+ DRb.stop_service
38
+
39
+ kll pid
40
+
41
+ end
42
+
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,35 @@
1
+ require 'minitest_helper'
2
+
3
+ module GV
4
+ module Bedrock
5
+ class TestService < Minitest::Test
6
+
7
+ def setup
8
+ start_server
9
+ end
10
+
11
+ def stop
12
+ stop_server
13
+ end
14
+
15
+ def test_discovery
16
+ pid = provide GV::Bedrock::Service
17
+
18
+ DRb.start_service
19
+
20
+ refute_nil GV::Bedrock::Service.find("gv/bedrock/service")
21
+
22
+ # clear all services
23
+ GV::Bedrock::Service.space.read_all([nil,nil,nil,nil]).each do |t|
24
+ GV::Bedrock::Service.space.take(t)
25
+ end
26
+
27
+ DRb.stop_service
28
+
29
+ kll pid
30
+
31
+ end
32
+
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,7 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'gv/bedrock'
3
+
4
+ require 'minitest/autorun'
5
+ require 'minitest/pride'
6
+
7
+ require 'gv/common/minitest_helper'
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gv-bedrock
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Onur Uyar
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: gv-common
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - me@onuruyar.com
72
+ executables:
73
+ - gv-bedrock
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - .travis.yml
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/gv-bedrock
84
+ - gv-bedrock.gemspec
85
+ - lib/gv/bedrock.rb
86
+ - lib/gv/bedrock/config.rb
87
+ - lib/gv/bedrock/server.rb
88
+ - lib/gv/bedrock/service.rb
89
+ - lib/gv/bedrock/version.rb
90
+ - test/gv/test_config.rb
91
+ - test/gv/test_service.rb
92
+ - test/minitest_helper.rb
93
+ homepage: https://github.com/green-valley/gv-bedrock
94
+ licenses:
95
+ - Unlicense
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.2.2
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Simple Rinda/Ring Network
117
+ test_files:
118
+ - test/gv/test_config.rb
119
+ - test/gv/test_service.rb
120
+ - test/minitest_helper.rb