sanford 0.4.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +16 -20
- data/Rakefile +0 -2
- data/bench/report.txt +30 -32
- data/bench/runner.rb +6 -5
- data/bench/services.rb +2 -2
- data/bench/tasks.rb +23 -0
- data/bin/sanford +7 -0
- data/lib/sanford.rb +2 -1
- data/lib/sanford/cli.rb +364 -0
- data/lib/sanford/error_handler.rb +1 -0
- data/lib/sanford/host.rb +18 -13
- data/lib/sanford/host_data.rb +21 -17
- data/lib/sanford/runner.rb +6 -3
- data/lib/sanford/server.rb +64 -12
- data/lib/sanford/service_handler.rb +19 -0
- data/lib/sanford/test_runner.rb +3 -4
- data/lib/sanford/version.rb +1 -1
- data/lib/sanford/worker.rb +4 -6
- data/sanford.gemspec +1 -2
- data/test/support/fake_connection.rb +12 -3
- data/test/support/helpers.rb +11 -34
- data/test/support/service_handlers.rb +9 -0
- data/test/support/services.rb +9 -8
- data/test/support/simple_client.rb +6 -0
- data/test/system/managing_test.rb +55 -66
- data/test/system/request_handling_test.rb +248 -36
- data/test/unit/config_test.rb +1 -1
- data/test/unit/host_configuration_test.rb +2 -6
- data/test/unit/host_data_test.rb +13 -30
- data/test/unit/host_test.rb +3 -3
- data/test/unit/manager_pid_file_test.rb +45 -0
- data/test/unit/manager_test.rb +133 -8
- data/test/unit/runner_test.rb +10 -0
- data/test/unit/server_test.rb +24 -5
- data/test/unit/service_handler_test.rb +19 -0
- data/test/unit/worker_test.rb +3 -192
- metadata +22 -36
- data/lib/sanford/exceptions.rb +0 -37
- data/lib/sanford/manager.rb +0 -49
- data/lib/sanford/rake.rb +0 -42
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sanford
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 6
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.6.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Collin Redding
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2013-
|
19
|
+
date: 2013-02-21 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
prerelease: false
|
@@ -25,32 +25,17 @@ dependencies:
|
|
25
25
|
requirements:
|
26
26
|
- - ~>
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
hash:
|
29
|
-
segments:
|
30
|
-
- 1
|
31
|
-
- 1
|
32
|
-
version: "1.1"
|
33
|
-
requirement: *id001
|
34
|
-
name: daemons
|
35
|
-
type: :runtime
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
prerelease: false
|
38
|
-
version_requirements: &id002 !ruby/object:Gem::Requirement
|
39
|
-
none: false
|
40
|
-
requirements:
|
41
|
-
- - ~>
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
hash: 9
|
28
|
+
hash: 15
|
44
29
|
segments:
|
45
30
|
- 0
|
46
|
-
-
|
47
|
-
version: "0.
|
48
|
-
requirement: *
|
31
|
+
- 2
|
32
|
+
version: "0.2"
|
33
|
+
requirement: *id001
|
49
34
|
name: dat-tcp
|
50
35
|
type: :runtime
|
51
36
|
- !ruby/object:Gem::Dependency
|
52
37
|
prerelease: false
|
53
|
-
version_requirements: &
|
38
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
54
39
|
none: false
|
55
40
|
requirements:
|
56
41
|
- - ~>
|
@@ -60,12 +45,12 @@ dependencies:
|
|
60
45
|
- 1
|
61
46
|
- 0
|
62
47
|
version: "1.0"
|
63
|
-
requirement: *
|
48
|
+
requirement: *id002
|
64
49
|
name: ns-options
|
65
50
|
type: :runtime
|
66
51
|
- !ruby/object:Gem::Dependency
|
67
52
|
prerelease: false
|
68
|
-
version_requirements: &
|
53
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
69
54
|
none: false
|
70
55
|
requirements:
|
71
56
|
- - ~>
|
@@ -75,12 +60,12 @@ dependencies:
|
|
75
60
|
- 0
|
76
61
|
- 5
|
77
62
|
version: "0.5"
|
78
|
-
requirement: *
|
63
|
+
requirement: *id003
|
79
64
|
name: sanford-protocol
|
80
65
|
type: :runtime
|
81
66
|
- !ruby/object:Gem::Dependency
|
82
67
|
prerelease: false
|
83
|
-
version_requirements: &
|
68
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
84
69
|
none: false
|
85
70
|
requirements:
|
86
71
|
- - ~>
|
@@ -90,12 +75,12 @@ dependencies:
|
|
90
75
|
- 1
|
91
76
|
- 0
|
92
77
|
version: "1.0"
|
93
|
-
requirement: *
|
78
|
+
requirement: *id004
|
94
79
|
name: assert
|
95
80
|
type: :development
|
96
81
|
- !ruby/object:Gem::Dependency
|
97
82
|
prerelease: false
|
98
|
-
version_requirements: &
|
83
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
99
84
|
none: false
|
100
85
|
requirements:
|
101
86
|
- - ~>
|
@@ -105,15 +90,15 @@ dependencies:
|
|
105
90
|
- 1
|
106
91
|
- 0
|
107
92
|
version: "1.0"
|
108
|
-
requirement: *
|
93
|
+
requirement: *id005
|
109
94
|
name: assert-mocha
|
110
95
|
type: :development
|
111
96
|
description: Simple hosts for Sanford services.
|
112
97
|
email:
|
113
98
|
- collin.redding@me.com
|
114
99
|
- kelly@kellyredding.com
|
115
|
-
executables:
|
116
|
-
|
100
|
+
executables:
|
101
|
+
- sanford
|
117
102
|
extensions: []
|
118
103
|
|
119
104
|
extra_rdoc_files: []
|
@@ -129,14 +114,13 @@ files:
|
|
129
114
|
- bench/runner.rb
|
130
115
|
- bench/services.rb
|
131
116
|
- bench/tasks.rb
|
117
|
+
- bin/sanford
|
132
118
|
- lib/sanford.rb
|
119
|
+
- lib/sanford/cli.rb
|
133
120
|
- lib/sanford/error_handler.rb
|
134
|
-
- lib/sanford/exceptions.rb
|
135
121
|
- lib/sanford/host.rb
|
136
122
|
- lib/sanford/host_data.rb
|
137
123
|
- lib/sanford/logger.rb
|
138
|
-
- lib/sanford/manager.rb
|
139
|
-
- lib/sanford/rake.rb
|
140
124
|
- lib/sanford/runner.rb
|
141
125
|
- lib/sanford/server.rb
|
142
126
|
- lib/sanford/service_handler.rb
|
@@ -160,6 +144,7 @@ files:
|
|
160
144
|
- test/unit/host_test.rb
|
161
145
|
- test/unit/host_version_group_test.rb
|
162
146
|
- test/unit/hosts_test.rb
|
147
|
+
- test/unit/manager_pid_file_test.rb
|
163
148
|
- test/unit/manager_test.rb
|
164
149
|
- test/unit/runner_test.rb
|
165
150
|
- test/unit/server_test.rb
|
@@ -214,6 +199,7 @@ test_files:
|
|
214
199
|
- test/unit/host_test.rb
|
215
200
|
- test/unit/host_version_group_test.rb
|
216
201
|
- test/unit/hosts_test.rb
|
202
|
+
- test/unit/manager_pid_file_test.rb
|
217
203
|
- test/unit/manager_test.rb
|
218
204
|
- test/unit/runner_test.rb
|
219
205
|
- test/unit/server_test.rb
|
data/lib/sanford/exceptions.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
module Sanford
|
2
|
-
|
3
|
-
BaseError = Class.new(RuntimeError)
|
4
|
-
|
5
|
-
NotFoundError = Class.new(RuntimeError)
|
6
|
-
|
7
|
-
class NoHostError < BaseError
|
8
|
-
|
9
|
-
def initialize(host_name)
|
10
|
-
message = if Sanford.hosts.empty?
|
11
|
-
"No hosts have been defined. Please define a host before trying to run Sanford."
|
12
|
-
else
|
13
|
-
"A host couldn't be found with the name #{host_name.inspect}. "
|
14
|
-
end
|
15
|
-
super message
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
class InvalidHostError < BaseError
|
21
|
-
|
22
|
-
def initialize(host)
|
23
|
-
super "A port must be configured or provided to run a server for '#{host}'"
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
class NoHandlerClassError < BaseError
|
29
|
-
|
30
|
-
def initialize(handler_class_name)
|
31
|
-
super "Sanford couldn't find the service handler '#{handler_class_name}'. " \
|
32
|
-
"It doesn't exist or hasn't been required in yet."
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
data/lib/sanford/manager.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'daemons'
|
2
|
-
|
3
|
-
require 'sanford/host_data'
|
4
|
-
require 'sanford/server'
|
5
|
-
|
6
|
-
module Sanford
|
7
|
-
|
8
|
-
class Manager
|
9
|
-
|
10
|
-
def self.call(action, options = nil)
|
11
|
-
options ||= {}
|
12
|
-
options[:ip] ||= ENV['SANFORD_IP']
|
13
|
-
options[:port] ||= ENV['SANFORD_PORT']
|
14
|
-
|
15
|
-
name = options.delete(:host) || ENV['SANFORD_HOST']
|
16
|
-
service_host = name ? Sanford.hosts.find(name) : Sanford.hosts.first
|
17
|
-
raise(Sanford::NoHostError.new(name)) if !service_host
|
18
|
-
|
19
|
-
self.new(service_host, options).call(action)
|
20
|
-
end
|
21
|
-
|
22
|
-
attr_reader :host_data, :process_name
|
23
|
-
|
24
|
-
def initialize(service_host, options = {})
|
25
|
-
@host_data = Sanford::HostData.new(service_host, options)
|
26
|
-
@process_name = [ self.host_data.ip, self.host_data.port, self.host_data.name ].join('_')
|
27
|
-
end
|
28
|
-
|
29
|
-
def call(action)
|
30
|
-
daemons_options = self.default_options.merge({ :ARGV => [ action.to_s ] })
|
31
|
-
FileUtils.mkdir_p(daemons_options[:dir])
|
32
|
-
::Daemons.run_proc(self.process_name, daemons_options) do
|
33
|
-
server = Sanford::Server.new(self.host_data)
|
34
|
-
server.start
|
35
|
-
server.join_thread
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
protected
|
40
|
-
|
41
|
-
def default_options
|
42
|
-
{ :dir_mode => :normal,
|
43
|
-
:dir => self.host_data.pid_dir
|
44
|
-
}
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
data/lib/sanford/rake.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
module Sanford::Rake
|
2
|
-
|
3
|
-
class Tasks
|
4
|
-
extend ::Rake::DSL
|
5
|
-
|
6
|
-
def self.load
|
7
|
-
namespace :sanford do
|
8
|
-
|
9
|
-
task :load_manager do
|
10
|
-
require 'sanford'
|
11
|
-
require 'sanford/manager'
|
12
|
-
Sanford.init
|
13
|
-
end
|
14
|
-
|
15
|
-
desc "Start a Sanford server and daemonize the process"
|
16
|
-
task :start => :load_manager do
|
17
|
-
Sanford::Manager.call :start
|
18
|
-
end
|
19
|
-
|
20
|
-
desc "Stop a daemonized Sanford server process"
|
21
|
-
task :stop => :load_manager do
|
22
|
-
Sanford::Manager.call :stop
|
23
|
-
end
|
24
|
-
|
25
|
-
desc "Restart a daemonized Sanford server process"
|
26
|
-
task :restart => :load_manager do
|
27
|
-
Sanford::Manager.call :restart
|
28
|
-
end
|
29
|
-
|
30
|
-
desc "Run a Sanford server (not daemonized)"
|
31
|
-
task :run => :load_manager do
|
32
|
-
Sanford::Manager.call :run
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
Sanford::Rake::Tasks.load
|