tap-server 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History +4 -0
- data/MIT-LICENSE +17 -15
- data/README +2 -11
- data/cmd/server.rb +27 -41
- data/lib/tap/controller.rb +22 -31
- data/lib/tap/controllers/app.rb +20 -116
- data/lib/tap/controllers/data.rb +16 -1
- data/lib/tap/controllers/server.rb +58 -15
- data/lib/tap/generator/generators/controller.rb +23 -0
- data/lib/tap/server.rb +75 -53
- data/lib/tap/tasks/echo.rb +1 -1
- data/templates/tap/generator/generators/controller/resource.erb +14 -0
- data/templates/tap/generator/generators/controller/test.erb +0 -0
- data/templates/tap/generator/generators/controller/view.erb +1 -0
- data/views/configurable/configurations.erb +57 -0
- data/views/configurable/default.erb +1 -0
- data/views/layout.erb +5 -2
- data/views/tap/{task → app/api}/help.erb +6 -4
- data/views/tap/controller/help.erb +4 -2
- data/views/tap/controllers/app/index.erb +47 -0
- data/views/tap/controllers/data/_upload.erb +1 -1
- data/views/tap/controllers/data/index.erb +16 -5
- data/views/tap/controllers/server/index.erb +10 -33
- data/views/tap/signals/signal/get.erb +1 -0
- data/views/tap/signals/signal/index.erb +4 -0
- data/views/tap/signals/signal/post.erb +1 -0
- metadata +18 -26
- data/lib/tap/controllers/schema.rb +0 -202
- data/lib/tap/server/runner.rb +0 -71
- data/public/javascripts/prototype.js +0 -4221
- data/public/javascripts/tap.js +0 -112
- data/views/configurable/_configs.erb +0 -33
- data/views/configurable/_flag.erb +0 -2
- data/views/configurable/_list_select.erb +0 -6
- data/views/configurable/_select.erb +0 -5
- data/views/configurable/_switch.erb +0 -2
- data/views/tap/controllers/app/_action.erb +0 -3
- data/views/tap/controllers/app/build.erb +0 -18
- data/views/tap/controllers/app/enque.erb +0 -13
- data/views/tap/controllers/app/info.erb +0 -21
- data/views/tap/controllers/app/tail.erb +0 -8
- data/views/tap/controllers/data/_index_entry.erb +0 -1
- data/views/tap/controllers/schema/_build.erb +0 -6
- data/views/tap/controllers/schema/_index_entry.erb +0 -6
- data/views/tap/controllers/schema/entry.erb +0 -144
- data/views/tap/task/input.erb +0 -17
- data/views/tap/tasks/load/input.erb +0 -11
data/History
CHANGED
data/MIT-LICENSE
CHANGED
@@ -1,19 +1,21 @@
|
|
1
1
|
Copyright (c) 2009, Regents of the University of Colorado.
|
2
2
|
|
3
|
-
|
4
|
-
software and associated documentation files (the "Software"), to deal in the Software
|
5
|
-
without restriction, including without limitation the rights to use, copy, modify, merge,
|
6
|
-
publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
7
|
-
to whom the Software is furnished to do so, subject to the following conditions:
|
3
|
+
Copyright (c) 2009, Simon Chiang.
|
8
4
|
|
9
|
-
|
10
|
-
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README
CHANGED
@@ -30,20 +30,11 @@ should not be considered stable.
|
|
30
30
|
|
31
31
|
== Installation
|
32
32
|
|
33
|
-
Tap Server is available as a gem on
|
33
|
+
Tap Server is available as a gem on Gemcutter[http://gemcutter.org/gems/tap-server].
|
34
34
|
|
35
35
|
% gem install tap-server
|
36
|
-
|
37
|
-
Tap requires an updated version of RubyGems[http://docs.rubygems.org/]
|
38
|
-
(>= 1.2.0). To check the version and update RubyGems:
|
39
|
-
|
40
|
-
% gem --version
|
41
|
-
% gem --update system
|
42
36
|
|
43
37
|
== Info
|
44
38
|
|
45
|
-
|
46
|
-
Developer:: {Simon Chiang}[http://bahuvrihi.wordpress.com], {Biomolecular Structure Program}[http://biomol.uchsc.edu/], {Hansen Lab}[http://hsc-proteomics.uchsc.edu/hansenlab/]
|
47
|
-
Support:: CU Denver School of Medicine Deans Academic Enrichment Fund
|
39
|
+
Developer:: {Simon Chiang}[http://bahuvrihi.wordpress.com]
|
48
40
|
License:: {MIT-Style}[link:files/MIT-LICENSE.html]
|
49
|
-
|
data/cmd/server.rb
CHANGED
@@ -3,52 +3,38 @@
|
|
3
3
|
# Initializes a tap server.
|
4
4
|
#
|
5
5
|
|
6
|
-
require 'tap'
|
7
6
|
require 'tap/server'
|
8
7
|
|
9
|
-
env = Tap::Env.instance
|
10
8
|
app = Tap::App.instance
|
9
|
+
opts = ConfigParser.new(app.config)
|
10
|
+
opts.separator ""
|
11
|
+
opts.separator "configurations:"
|
12
|
+
opts.add(Tap::Server.configurations)
|
13
|
+
opts.add(Tap::App.configurations)
|
11
14
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
opts.
|
17
|
-
|
18
|
-
opts.separator ""
|
19
|
-
opts.separator "options:"
|
20
|
-
|
21
|
-
opts.on('--config FILE', 'Specifies a config file') do |config_file|
|
22
|
-
opts.config.merge! Configurable::Utils.load_file(config_file)
|
23
|
-
end
|
24
|
-
|
25
|
-
opts.on("-h", "--help", "Show this message") do
|
26
|
-
puts Lazydoc.usage(__FILE__)
|
27
|
-
puts opts
|
28
|
-
exit
|
29
|
-
end
|
30
|
-
|
31
|
-
# (note defaults are not added so they will not
|
32
|
-
# conflict with string keys from a config file)
|
33
|
-
args = opts.parse!(ARGV, :clear_config => false, :add_defaults => false)
|
34
|
-
|
35
|
-
if args.empty?
|
36
|
-
args << 'server'
|
37
|
-
end
|
38
|
-
|
39
|
-
controller = env[:controller][args.shift]
|
40
|
-
|
41
|
-
unless args.empty?
|
42
|
-
warn "ignoring args: #{args.inspect}"
|
43
|
-
end
|
44
|
-
|
45
|
-
Tap::Server.new(controller, opts.nested_config).run!
|
46
|
-
rescue
|
47
|
-
raise if $DEBUG
|
48
|
-
puts $!.message
|
49
|
-
exit(1)
|
15
|
+
opts.separator ""
|
16
|
+
opts.separator "options:"
|
17
|
+
|
18
|
+
opts.on('--config FILE', 'Specifies a config file') do |config_file|
|
19
|
+
opts.config.merge! Configurable::Utils.load_file(config_file)
|
50
20
|
end
|
51
21
|
|
52
|
-
|
22
|
+
opts.on("-h", "--help", "Show this message") do
|
23
|
+
puts Lazydoc.usage(__FILE__)
|
24
|
+
puts opts
|
25
|
+
exit
|
26
|
+
end
|
27
|
+
|
28
|
+
# (note defaults are not added so they will not
|
29
|
+
# conflict with string keys from a config file)
|
30
|
+
args = opts.parse!(ARGV, :clear_config => false, :add_defaults => false)
|
53
31
|
|
32
|
+
server = Tap::Server.new(opts.nested_config)
|
33
|
+
server.bind(args.shift || 'tap-server:server')
|
54
34
|
|
35
|
+
unless args.empty?
|
36
|
+
warn "ignoring args: #{args.inspect}"
|
37
|
+
end
|
38
|
+
|
39
|
+
server.run!
|
40
|
+
exit(0)
|
data/lib/tap/controller.rb
CHANGED
@@ -26,14 +26,9 @@ module Tap
|
|
26
26
|
def inherited(child) # :nodoc:
|
27
27
|
super
|
28
28
|
|
29
|
-
unless child.instance_variable_defined?(:@source_file)
|
30
|
-
caller[0] =~ Lazydoc::CALLER_REGEXP
|
31
|
-
child.instance_variable_set(:@source_file, File.expand_path($1))
|
32
|
-
end
|
33
|
-
|
34
29
|
set_variables.each do |variable|
|
35
30
|
value = get(variable)
|
36
|
-
value = value.dup if Configurable::
|
31
|
+
value = value.dup if Configurable::Config.duplicable_value?(value)
|
37
32
|
child.set(variable, value)
|
38
33
|
end
|
39
34
|
|
@@ -146,10 +141,9 @@ module Tap
|
|
146
141
|
# not be actions in subclasses.
|
147
142
|
set :define_action, false
|
148
143
|
|
144
|
+
# References the Tap::Server running this controller.
|
149
145
|
attr_accessor :server
|
150
146
|
|
151
|
-
attr_accessor :controller_path
|
152
|
-
|
153
147
|
# A Rack::Request wrapping env, set during call.
|
154
148
|
attr_accessor :request
|
155
149
|
|
@@ -160,7 +154,7 @@ module Tap
|
|
160
154
|
|
161
155
|
# Initializes a new instance of self.
|
162
156
|
def initialize
|
163
|
-
@request = @response = @server =
|
157
|
+
@request = @response = @server = nil
|
164
158
|
end
|
165
159
|
|
166
160
|
# Returns true if action is registered as an action for self.
|
@@ -174,7 +168,7 @@ module Tap
|
|
174
168
|
# these to the uri.
|
175
169
|
def uri(action=nil, params=nil, options=nil)
|
176
170
|
if action.kind_of?(Hash)
|
177
|
-
unless params
|
171
|
+
unless params.nil? && options.nil?
|
178
172
|
raise "extra arguments specified for uri hash syntax"
|
179
173
|
end
|
180
174
|
|
@@ -185,9 +179,8 @@ module Tap
|
|
185
179
|
|
186
180
|
uri = []
|
187
181
|
|
188
|
-
if
|
189
|
-
uri << '
|
190
|
-
uri << controller_path
|
182
|
+
if request
|
183
|
+
uri << request.env['SCRIPT_NAME']
|
191
184
|
end
|
192
185
|
|
193
186
|
if action
|
@@ -195,7 +188,7 @@ module Tap
|
|
195
188
|
uri << action
|
196
189
|
end
|
197
190
|
|
198
|
-
unless params
|
191
|
+
unless params.nil? || params.empty?
|
199
192
|
uri << '?'
|
200
193
|
uri << build_query(params)
|
201
194
|
end
|
@@ -217,14 +210,6 @@ module Tap
|
|
217
210
|
uri.join
|
218
211
|
end
|
219
212
|
|
220
|
-
def template_path(path)
|
221
|
-
server.env.path(:views, path) {|file| File.file?(file) }
|
222
|
-
end
|
223
|
-
|
224
|
-
def module_path(path, klass=self.class)
|
225
|
-
server.env.module_path(:views, klass.ancestors, path) {|file| File.file?(file) }
|
226
|
-
end
|
227
|
-
|
228
213
|
# Routes the request to an action and returns the response. Routing is
|
229
214
|
# simple and fixed (see route):
|
230
215
|
#
|
@@ -253,8 +238,6 @@ module Tap
|
|
253
238
|
#
|
254
239
|
def call(env)
|
255
240
|
@server = env['tap.server']
|
256
|
-
@controller_path = env['tap.controller_path']
|
257
|
-
|
258
241
|
@request = Rack::Request.new(env)
|
259
242
|
@response = Rack::Response.new
|
260
243
|
|
@@ -269,8 +252,8 @@ module Tap
|
|
269
252
|
end
|
270
253
|
end
|
271
254
|
|
272
|
-
# Returns the action, args, and extname for the request.path_info.
|
273
|
-
# is simple and fixed:
|
255
|
+
# Returns the action, args, and extname for the request.path_info.
|
256
|
+
# Routing is simple and fixed:
|
274
257
|
#
|
275
258
|
# route returns
|
276
259
|
# / [:index, []]
|
@@ -284,6 +267,7 @@ module Tap
|
|
284
267
|
route
|
285
268
|
end
|
286
269
|
|
270
|
+
# Inputs a route like [action, *args] and dispatches it to the action.
|
287
271
|
def dispatch(route)
|
288
272
|
action, *args = route
|
289
273
|
|
@@ -292,7 +276,7 @@ module Tap
|
|
292
276
|
end
|
293
277
|
|
294
278
|
unless action?(action)
|
295
|
-
|
279
|
+
not_found
|
296
280
|
end
|
297
281
|
|
298
282
|
send(action, *args)
|
@@ -314,9 +298,9 @@ module Tap
|
|
314
298
|
when options[:file]
|
315
299
|
options[:file]
|
316
300
|
when options[:template]
|
317
|
-
|
301
|
+
server.template_path(options[:template])
|
318
302
|
else
|
319
|
-
|
303
|
+
server.module_path(path, self.class)
|
320
304
|
end
|
321
305
|
|
322
306
|
unless template_path
|
@@ -379,8 +363,7 @@ module Tap
|
|
379
363
|
end
|
380
364
|
|
381
365
|
def module_render(path, obj, options={})
|
382
|
-
|
383
|
-
options[:file] = module_path(path, obj) || module_path(path)
|
366
|
+
options[:file] = server.module_path(path, obj.class)
|
384
367
|
|
385
368
|
locals = options[:locals] ||= {}
|
386
369
|
locals[:obj] ||= obj
|
@@ -398,6 +381,14 @@ module Tap
|
|
398
381
|
response.finish
|
399
382
|
end
|
400
383
|
|
384
|
+
def not_found
|
385
|
+
error("404 Error: page not found", 404)
|
386
|
+
end
|
387
|
+
|
388
|
+
def error(msg, status=500)
|
389
|
+
raise ServerError.new(msg, status)
|
390
|
+
end
|
391
|
+
|
401
392
|
private
|
402
393
|
|
403
394
|
# Generates an empty binding to self without any locals assigned.
|
data/lib/tap/controllers/app.rb
CHANGED
@@ -1,135 +1,39 @@
|
|
1
1
|
require 'tap/controller'
|
2
|
-
require 'tap/controllers/schema'
|
3
2
|
|
4
3
|
module Tap
|
5
4
|
module Controllers
|
6
5
|
|
7
|
-
# :startdoc::controller
|
6
|
+
# :startdoc::controller dispatches signals to an app
|
8
7
|
class App < Tap::Controller
|
9
|
-
|
8
|
+
include RestRoutes
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
route.unshift rest_action(route)
|
14
|
-
super(route)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
# Returns the state of app.
|
19
|
-
def state
|
20
|
-
app.state.to_s
|
21
|
-
end
|
22
|
-
|
23
|
-
# Returns the controls and current application info.
|
24
|
-
def info
|
25
|
-
render 'info.erb', :locals => {
|
26
|
-
:actions => [:run, :stop, :terminate, :reset],
|
27
|
-
}, :layout => true
|
28
|
-
end
|
29
|
-
|
30
|
-
# Runs app on a separate thread (on post).
|
31
|
-
def run
|
32
|
-
if request.post?
|
33
|
-
server.thread ||= Thread.new { app.run; server.thread = nil; }
|
34
|
-
end
|
35
|
-
|
36
|
-
redirect uri(:info)
|
37
|
-
end
|
38
|
-
|
39
|
-
def reset
|
40
|
-
app.reset if request.post?
|
41
|
-
redirect uri(:info)
|
42
|
-
end
|
43
|
-
|
44
|
-
# Stops app (on post).
|
45
|
-
def stop
|
46
|
-
app.stop if request.post?
|
47
|
-
redirect uri(:info)
|
48
|
-
end
|
49
|
-
|
50
|
-
# Teminates app (on post).
|
51
|
-
def terminate
|
52
|
-
app.terminate if request.post?
|
53
|
-
redirect uri(:info)
|
10
|
+
def route
|
11
|
+
unescape(request.path_info)
|
54
12
|
end
|
55
13
|
|
56
|
-
def
|
57
|
-
|
58
|
-
|
59
|
-
unless request.post?
|
60
|
-
return render('build.erb', :schema => schema, :layout => true)
|
14
|
+
def dispatch(route)
|
15
|
+
if route == "/"
|
16
|
+
return render('index.erb', :layout => true)
|
61
17
|
end
|
62
18
|
|
63
|
-
|
64
|
-
|
65
|
-
end.validate!
|
66
|
-
|
67
|
-
if request[:reset] == "on"
|
68
|
-
app.reset
|
69
|
-
end
|
19
|
+
route =~ Tap::Parser::SIGNAL
|
20
|
+
signal = app.route($1, $2)
|
70
21
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
22
|
+
request_method = request.request_method
|
23
|
+
case request_method
|
24
|
+
when /GET/i
|
25
|
+
module_render('get.erb', signal)
|
26
|
+
when /POST/i
|
27
|
+
result = signal.call(request.params)
|
28
|
+
module_render('post.erb', signal, :locals => {:result => result})
|
75
29
|
else
|
76
|
-
|
30
|
+
error("cannot signal via: #{request_method}")
|
77
31
|
end
|
78
32
|
end
|
79
33
|
|
80
|
-
def
|
81
|
-
unless
|
82
|
-
|
83
|
-
end
|
84
|
-
|
85
|
-
queue = if request[:load]
|
86
|
-
YAML.load(request[:queue] || "{}")
|
87
|
-
else
|
88
|
-
request[:queue] || {}
|
89
|
-
end
|
90
|
-
|
91
|
-
queue.each do |(key, inputs)|
|
92
|
-
unless task = tasks[key]
|
93
|
-
raise "no task for: #{key}"
|
94
|
-
end
|
95
|
-
app.enq(task, *inputs)
|
96
|
-
end
|
97
|
-
|
98
|
-
redirect uri(:info)
|
99
|
-
end
|
100
|
-
|
101
|
-
def tail(id)
|
102
|
-
unless data.has?("#{id}.log")
|
103
|
-
raise Tap::ServerError.new("invalid id: #{id}", 404)
|
104
|
-
end
|
105
|
-
|
106
|
-
path = data.path("#{id}.log")
|
107
|
-
pos = request['pos'].to_i
|
108
|
-
if pos > File.size(path)
|
109
|
-
raise Tap::ServerError.new("tail position out of range (try update)", 500)
|
110
|
-
end
|
111
|
-
|
112
|
-
content = File.open(path) do |file|
|
113
|
-
file.pos = pos
|
114
|
-
file.read
|
115
|
-
end
|
116
|
-
|
117
|
-
if request.post?
|
118
|
-
content
|
119
|
-
else
|
120
|
-
render('tail.erb', :locals => {
|
121
|
-
:id => id,
|
122
|
-
:path => File.basename(path),
|
123
|
-
:update => true,
|
124
|
-
:content => content
|
125
|
-
}, :layout => true)
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
protected
|
130
|
-
|
131
|
-
def tasks
|
132
|
-
app.cache[:tasks] ||= {}
|
34
|
+
def uri(obj, sig=nil)
|
35
|
+
obj, sig = nil, obj unless sig
|
36
|
+
super(obj ? "#{obj}/#{sig}" : sig)
|
133
37
|
end
|
134
38
|
|
135
39
|
def app
|