rbbt-rest 1.3.2 → 1.3.3
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.
- checksums.yaml +4 -4
- data/lib/rbbt/rest/client.rb +8 -329
- data/lib/rbbt/rest/client/adaptor.rb +66 -0
- data/lib/rbbt/rest/client/get.rb +83 -0
- data/lib/rbbt/rest/client/step.rb +123 -0
- data/lib/rbbt/rest/common/misc.rb +1 -1
- data/lib/rbbt/rest/main.rb +4 -4
- data/lib/rbbt/rest/workflow.rb +18 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b556674b8552bf64d8680def41f2316821743b64
|
4
|
+
data.tar.gz: 3f1fb6faa193e793870d65706e3ca828b7de897f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8329fbef77bc84d70921839a9648e988a1d587a33de739c23dd1255e90bddbe33794a12dee8e51dc6e4bede70b7118690ea1afb5a1022ddc35dc995401303b4b
|
7
|
+
data.tar.gz: 233769daa035553e3a1d294f2cf1cb426bbc779605b24e1c357a65d6d3693f831c9d72014d1cf845ebe00c6f0b770d31a68810e47daa384e613dfd164709993b
|
data/lib/rbbt/rest/client.rb
CHANGED
@@ -4,174 +4,12 @@ require 'rbbt/workflow'
|
|
4
4
|
require 'rbbt/workflow/step'
|
5
5
|
require 'rbbt/util/misc'
|
6
6
|
|
7
|
-
|
7
|
+
require 'rbbt/rest/client/get'
|
8
|
+
require 'rbbt/rest/client/adaptor'
|
9
|
+
require 'rbbt/rest/client/step'
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
hash.each do |key, value|
|
12
|
-
fixed[key.to_sym] = case
|
13
|
-
when Hash === value
|
14
|
-
fix_hash(value)
|
15
|
-
when (fix_values and String === value)
|
16
|
-
value.to_sym
|
17
|
-
else
|
18
|
-
value
|
19
|
-
end
|
20
|
-
end
|
21
|
-
fixed
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.get_raw(url, params = {})
|
25
|
-
Log.debug{ "RestClient get_raw: #{ url } - #{Misc.fingerprint params}" }
|
26
|
-
params = params.merge({ :_format => 'raw' })
|
27
|
-
Misc.insist(2, 0.5) do
|
28
|
-
RestClient.get(URI.encode(url), :params => params)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.post_jobname(url, params = {})
|
33
|
-
Log.debug{ "RestClient post_jobname: #{ url } - #{Misc.fingerprint params}" }
|
34
|
-
params = params.merge({ :_format => 'jobname' })
|
35
|
-
RestClient.post(URI.encode(url), params)
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.get_json(url, params = {})
|
39
|
-
Log.debug{ "RestClient get_json: #{ url } - #{Misc.fingerprint params }" }
|
40
|
-
params = params.merge({ :_format => 'json' })
|
41
|
-
begin
|
42
|
-
res = RestClient.get(URI.encode(url), :params => params)
|
43
|
-
rescue => e
|
44
|
-
raise JSON.parse(e.response)["message"]
|
45
|
-
end
|
46
|
-
begin
|
47
|
-
JSON.parse(res)
|
48
|
-
rescue
|
49
|
-
res
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def self.post_json(url, params = {})
|
54
|
-
if url =~ /_cache_type=:exec/
|
55
|
-
JSON.parse(Open.open(url, :nocache => true))
|
56
|
-
else
|
57
|
-
params = params.merge({ :_format => 'json' })
|
58
|
-
res = RestClient.post(URI.encode(url), params)
|
59
|
-
begin
|
60
|
-
JSON.parse(res)
|
61
|
-
rescue
|
62
|
-
res
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
class RemoteStep < Step
|
68
|
-
|
69
|
-
attr_accessor :url, :base_url, :task, :name, :inputs, :result_type, :result_description
|
70
|
-
|
71
|
-
def name
|
72
|
-
(Array === @url ? @url.first : @url).split("/").last
|
73
|
-
end
|
74
|
-
|
75
|
-
def task_name
|
76
|
-
(Array === @url ? @url.first : @url).split("/")[-2]
|
77
|
-
end
|
78
|
-
|
79
|
-
def info
|
80
|
-
info = WorkflowRESTClient.get_json(File.join(url, 'info'))
|
81
|
-
info = WorkflowRESTClient.fix_hash(info)
|
82
|
-
info[:status] = info[:status].to_sym if String === info[:status]
|
83
|
-
info
|
84
|
-
end
|
85
|
-
|
86
|
-
def done?
|
87
|
-
status.to_s == 'done'
|
88
|
-
end
|
89
|
-
|
90
|
-
def fork
|
91
|
-
@name = WorkflowRESTClient.post_jobname(File.join(base_url, task.to_s), inputs.merge(:jobname => @name, :_cache_type => :asynchronous))
|
92
|
-
@url = File.join(base_url, task.to_s, @name)
|
93
|
-
self
|
94
|
-
end
|
95
|
-
|
96
|
-
def initialize(base_url, task = nil, name = nil, inputs = nil, result_type = nil, result_description = nil, exec = false)
|
97
|
-
if task.nil?
|
98
|
-
@url = base_url
|
99
|
-
else
|
100
|
-
@base_url, @task, @name, @inputs, @result_type, @result_description = base_url, task, name, inputs, result_type, result_description
|
101
|
-
if exec
|
102
|
-
@url = [File.join(base_url, task.to_s), inputs]
|
103
|
-
else
|
104
|
-
self.fork
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
def _exec(noload = false)
|
110
|
-
if Array === @url
|
111
|
-
url, params = @url
|
112
|
-
else
|
113
|
-
url, params = @url, {:_cache_type => :synchronous}
|
114
|
-
end
|
115
|
-
|
116
|
-
params[:jobname] = @name if @name
|
117
|
-
|
118
|
-
if noload and %w(boolean string tsv).include? result_type
|
119
|
-
WorkflowRESTClient.get_raw(url, params)
|
120
|
-
else
|
121
|
-
case result_type
|
122
|
-
when :string
|
123
|
-
WorkflowRESTClient.get_raw(url, params)
|
124
|
-
when :boolean
|
125
|
-
WorkflowRESTClient.get_raw(url, params) == "true"
|
126
|
-
when :tsv
|
127
|
-
TSV.open(StringIO.new(WorkflowRESTClient.get_raw(url, params)))
|
128
|
-
when :annotations
|
129
|
-
Annotated.load_tsv(TSV.open(StringIO.new(WorkflowRESTClient.get_raw(url, params))))
|
130
|
-
else
|
131
|
-
WorkflowRESTClient.get_json(url, params)
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
def exec
|
137
|
-
res = _exec
|
138
|
-
prepare_result(res, result_type)
|
139
|
-
end
|
140
|
-
|
141
|
-
def run(noload = false)
|
142
|
-
if noload
|
143
|
-
_exec(noload)
|
144
|
-
else
|
145
|
-
exec
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
def load
|
150
|
-
exec
|
151
|
-
end
|
152
|
-
|
153
|
-
def join
|
154
|
-
exec
|
155
|
-
self
|
156
|
-
end
|
157
|
-
|
158
|
-
def status
|
159
|
-
info[:status]
|
160
|
-
end
|
161
|
-
|
162
|
-
def clean
|
163
|
-
WorkflowRESTClient.get_raw(url, :_update => :clean)
|
164
|
-
self
|
165
|
-
end
|
166
|
-
|
167
|
-
def files
|
168
|
-
WorkflowRESTClient.get_json(File.join(url, 'files'))
|
169
|
-
end
|
170
|
-
|
171
|
-
def file(file)
|
172
|
-
WorkflowRESTClient.get_json(File.join(url, 'file', file))
|
173
|
-
end
|
174
|
-
end
|
11
|
+
class WorkflowRESTClient
|
12
|
+
include Workflow
|
175
13
|
|
176
14
|
attr_accessor :url, :name, :exec_exports, :asynchronous_exports, :synchronous_exports
|
177
15
|
|
@@ -185,103 +23,6 @@ class WorkflowRESTClient
|
|
185
23
|
name
|
186
24
|
end
|
187
25
|
|
188
|
-
def workflow_description
|
189
|
-
WorkflowRESTClient.get_raw(File.join(url, 'description'))
|
190
|
-
end
|
191
|
-
|
192
|
-
def documentation
|
193
|
-
@documention ||= IndiferentHash.setup(WorkflowRESTClient.get_json(File.join(url, "documentation"),{}))
|
194
|
-
end
|
195
|
-
|
196
|
-
def task_info(task)
|
197
|
-
@task_info ||= {}
|
198
|
-
@task_info[task]
|
199
|
-
|
200
|
-
if @task_info[task].nil?
|
201
|
-
task_info = WorkflowRESTClient.get_json(File.join(url, task.to_s, 'info'))
|
202
|
-
task_info = WorkflowRESTClient.fix_hash(task_info)
|
203
|
-
|
204
|
-
task_info[:result_type] = task_info[:result_type].to_sym
|
205
|
-
task_info[:export] = task_info[:export].to_sym
|
206
|
-
task_info[:input_types] = WorkflowRESTClient.fix_hash(task_info[:input_types], true)
|
207
|
-
task_info[:inputs] = task_info[:inputs].collect{|input| input.to_sym }
|
208
|
-
|
209
|
-
@task_info[task] = task_info
|
210
|
-
end
|
211
|
-
@task_info[task]
|
212
|
-
end
|
213
|
-
|
214
|
-
def exported_tasks
|
215
|
-
(@asynchronous_exports + @synchronous_exports + @exec_exports).compact.flatten
|
216
|
-
end
|
217
|
-
|
218
|
-
def tasks
|
219
|
-
@tasks ||= Hash.new do |hash,task_name|
|
220
|
-
info = task_info(task_name)
|
221
|
-
task = Task.setup info do |*args|
|
222
|
-
raise "This is a remote task"
|
223
|
-
end
|
224
|
-
task.name = task_name.to_sym
|
225
|
-
hash[task_name] = task
|
226
|
-
end
|
227
|
-
end
|
228
|
-
|
229
|
-
def load_tasks
|
230
|
-
exported_tasks.each{|name| tasks[name]}
|
231
|
-
nil
|
232
|
-
end
|
233
|
-
|
234
|
-
def task_dependencies
|
235
|
-
@task_dependencies ||= Hash.new do |hash,task|
|
236
|
-
hash[task] = if exported_tasks.include? task
|
237
|
-
WorkflowRESTClient.get_json(File.join(url, task.to_s, 'dependencies'))
|
238
|
-
else
|
239
|
-
[]
|
240
|
-
end
|
241
|
-
end
|
242
|
-
end
|
243
|
-
|
244
|
-
def rec_dependencies(taskname)
|
245
|
-
if task_dependencies.include? taskname
|
246
|
-
deps = task_dependencies[taskname].select{|dep| String === dep or Symbol === dep}
|
247
|
-
deps.concat deps.collect{|dep| rec_dependencies(dep)}.compact.flatten
|
248
|
-
deps.uniq
|
249
|
-
else
|
250
|
-
[]
|
251
|
-
end
|
252
|
-
end
|
253
|
-
|
254
|
-
def rec_inputs(taskname)
|
255
|
-
[taskname].concat(rec_dependencies(taskname)).inject([]){|acc, tn| acc.concat tasks[tn.to_sym].inputs}
|
256
|
-
end
|
257
|
-
|
258
|
-
def rec_input_defaults(taskname)
|
259
|
-
[taskname].concat(rec_dependencies(taskname)).inject({}){|acc, tn| acc.merge tasks[tn.to_sym].input_defaults}.
|
260
|
-
tap{|h| IndiferentHash.setup(h) }
|
261
|
-
end
|
262
|
-
|
263
|
-
def rec_input_types(taskname)
|
264
|
-
[taskname].concat(rec_dependencies(taskname)).inject({}){|acc, tn| acc.merge tasks[tn.to_sym].input_types}.
|
265
|
-
tap{|h| IndiferentHash.setup(h) }
|
266
|
-
end
|
267
|
-
|
268
|
-
def rec_input_descriptions(taskname)
|
269
|
-
[taskname].concat(rec_dependencies(taskname)).inject({}){|acc, tn| acc.merge tasks[tn.to_sym].input_descriptions}.
|
270
|
-
tap{|h| IndiferentHash.setup(h) }
|
271
|
-
end
|
272
|
-
|
273
|
-
def rec_input_options(taskname)
|
274
|
-
[taskname].concat(rec_dependencies(taskname)).inject({}){|acc, tn| acc.merge tasks[tn.to_sym].input_options}.
|
275
|
-
tap{|h| IndiferentHash.setup(h) }
|
276
|
-
end
|
277
|
-
|
278
|
-
def init_remote_tasks
|
279
|
-
task_exports = WorkflowRESTClient.get_json(url)
|
280
|
-
@asynchronous_exports = task_exports["asynchronous"].collect{|task| task.to_sym }
|
281
|
-
@synchronous_exports = task_exports["synchronous"].collect{|task| task.to_sym }
|
282
|
-
@exec_exports = task_exports["exec"].collect{|task| task.to_sym }
|
283
|
-
end
|
284
|
-
|
285
26
|
def job(task, name, inputs)
|
286
27
|
task_info = task_info(task)
|
287
28
|
fixed_inputs = {}
|
@@ -293,78 +34,16 @@ class WorkflowRESTClient
|
|
293
34
|
v
|
294
35
|
end
|
295
36
|
end
|
37
|
+
|
296
38
|
RemoteStep.new(url, task, name, fixed_inputs, task_info[:result_type], task_info[:result_description], @exec_exports.include?(task))
|
297
39
|
end
|
298
40
|
|
299
41
|
def load_id(id)
|
300
42
|
task, name = id.split("/")
|
301
|
-
step = RemoteStep.new
|
43
|
+
step = RemoteStep.new url, task, nil
|
44
|
+
step.name = name
|
302
45
|
step.result_type = task_info(task)[:result_type]
|
303
46
|
step.result_description = task_info(task)[:result_description]
|
304
47
|
step
|
305
48
|
end
|
306
|
-
|
307
|
-
def doc(task = nil)
|
308
|
-
|
309
|
-
if task.nil?
|
310
|
-
puts self.to_s
|
311
|
-
puts "=" * self.to_s.length
|
312
|
-
puts
|
313
|
-
|
314
|
-
puts "## TASKS"
|
315
|
-
puts
|
316
|
-
tasks.each do |name,task|
|
317
|
-
puts " * #{ name }:"
|
318
|
-
puts " " << task.description if task.description and not task.description.empty?
|
319
|
-
puts
|
320
|
-
end
|
321
|
-
else
|
322
|
-
|
323
|
-
if Task === task
|
324
|
-
task_name = task.name
|
325
|
-
else
|
326
|
-
task_name = task
|
327
|
-
task = self.tasks[task_name]
|
328
|
-
end
|
329
|
-
dependencies = self.rec_dependencies(task_name).collect{|dep_name| self.tasks[dep_name.to_sym]}
|
330
|
-
|
331
|
-
task.doc(dependencies)
|
332
|
-
end
|
333
|
-
end
|
334
|
-
|
335
|
-
def doc(task = nil)
|
336
|
-
|
337
|
-
if task.nil?
|
338
|
-
puts Log.color :magenta, self.to_s
|
339
|
-
puts Log.color :magenta, "=" * self.to_s.length
|
340
|
-
if self.documentation[:description] and not self.documentation[:description].empty?
|
341
|
-
puts
|
342
|
-
puts Misc.format_paragraph self.documentation[:description]
|
343
|
-
end
|
344
|
-
puts
|
345
|
-
|
346
|
-
puts Log.color :magenta, "## TASKS"
|
347
|
-
if self.documentation[:task_description] and not self.documentation[:task_description].empty?
|
348
|
-
puts
|
349
|
-
puts Misc.format_paragraph self.documentation[:task_description]
|
350
|
-
end
|
351
|
-
puts
|
352
|
-
|
353
|
-
tasks.each do |name,task|
|
354
|
-
puts Misc.format_definition_list_item(name.to_s, task.description || "", 80, 30, :yellow)
|
355
|
-
end
|
356
|
-
|
357
|
-
else
|
358
|
-
|
359
|
-
if Task === task
|
360
|
-
task_name = task.name
|
361
|
-
else
|
362
|
-
task_name = task
|
363
|
-
task = self.tasks[task_name]
|
364
|
-
end
|
365
|
-
dependencies = self.rec_dependencies(task_name).collect{|dep_name| self.tasks[dep_name.to_sym]}
|
366
|
-
|
367
|
-
task.doc(dependencies)
|
368
|
-
end
|
369
|
-
end
|
370
49
|
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
class WorkflowRESTClient
|
2
|
+
|
3
|
+
def workflow_description
|
4
|
+
WorkflowRESTClient.get_raw(File.join(url, 'description'))
|
5
|
+
end
|
6
|
+
|
7
|
+
def documentation
|
8
|
+
@documention ||= IndiferentHash.setup(WorkflowRESTClient.get_json(File.join(url, "documentation"),{}))
|
9
|
+
end
|
10
|
+
|
11
|
+
def task_info(task)
|
12
|
+
@task_info ||= {}
|
13
|
+
@task_info[task]
|
14
|
+
|
15
|
+
if @task_info[task].nil?
|
16
|
+
task_info = WorkflowRESTClient.get_json(File.join(url, task.to_s, 'info'))
|
17
|
+
task_info = WorkflowRESTClient.fix_hash(task_info)
|
18
|
+
|
19
|
+
task_info[:result_type] = task_info[:result_type].to_sym
|
20
|
+
task_info[:export] = task_info[:export].to_sym
|
21
|
+
task_info[:input_types] = WorkflowRESTClient.fix_hash(task_info[:input_types], true)
|
22
|
+
task_info[:inputs] = task_info[:inputs].collect{|input| input.to_sym }
|
23
|
+
|
24
|
+
@task_info[task] = task_info
|
25
|
+
end
|
26
|
+
@task_info[task]
|
27
|
+
end
|
28
|
+
|
29
|
+
def exported_tasks
|
30
|
+
(@asynchronous_exports + @synchronous_exports + @exec_exports).compact.flatten
|
31
|
+
end
|
32
|
+
|
33
|
+
def tasks
|
34
|
+
@tasks ||= Hash.new do |hash,task_name|
|
35
|
+
info = task_info(task_name)
|
36
|
+
task = Task.setup info do |*args|
|
37
|
+
raise "This is a remote task"
|
38
|
+
end
|
39
|
+
task.name = task_name.to_sym
|
40
|
+
hash[task_name] = task
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def load_tasks
|
45
|
+
exported_tasks.each{|name| tasks[name]}
|
46
|
+
nil
|
47
|
+
end
|
48
|
+
|
49
|
+
def task_dependencies
|
50
|
+
@task_dependencies ||= Hash.new do |hash,task|
|
51
|
+
hash[task] = if exported_tasks.include? task
|
52
|
+
WorkflowRESTClient.get_json(File.join(url, task.to_s, 'dependencies'))
|
53
|
+
else
|
54
|
+
[]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def init_remote_tasks
|
60
|
+
task_exports = WorkflowRESTClient.get_json(url)
|
61
|
+
@asynchronous_exports = task_exports["asynchronous"].collect{|task| task.to_sym }
|
62
|
+
@synchronous_exports = task_exports["synchronous"].collect{|task| task.to_sym }
|
63
|
+
@exec_exports = task_exports["exec"].collect{|task| task.to_sym }
|
64
|
+
nil
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
class WorkflowRESTClient
|
2
|
+
def self.fix_hash(hash, fix_values = false)
|
3
|
+
fixed = {}
|
4
|
+
hash.each do |key, value|
|
5
|
+
fixed[key.to_sym] = case
|
6
|
+
when Hash === value
|
7
|
+
fix_hash(value)
|
8
|
+
when (fix_values and String === value)
|
9
|
+
value.to_sym
|
10
|
+
else
|
11
|
+
value
|
12
|
+
end
|
13
|
+
end
|
14
|
+
fixed
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.capture_exception
|
18
|
+
begin
|
19
|
+
yield
|
20
|
+
rescue Exception => e
|
21
|
+
klass, message = e.response.split " => "
|
22
|
+
begin
|
23
|
+
klass = Kernel.const_get klass
|
24
|
+
rescue
|
25
|
+
raise message
|
26
|
+
end
|
27
|
+
raise klass.new message
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.get_raw(url, params = {})
|
32
|
+
Log.debug{ "RestClient get_raw: #{ url } - #{Misc.fingerprint params}" }
|
33
|
+
params = params.merge({ :_format => 'raw' })
|
34
|
+
capture_exception do
|
35
|
+
Misc.insist(2, 0.5) do
|
36
|
+
RestClient.get(URI.encode(url), :params => params)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.post_jobname(url, params = {})
|
42
|
+
Log.debug{ "RestClient post_jobname: #{ url } - #{Misc.fingerprint params}" }
|
43
|
+
params = params.merge({ :_format => 'jobname' })
|
44
|
+
|
45
|
+
capture_exception do
|
46
|
+
RestClient.post(URI.encode(url), params)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.get_json(url, params = {})
|
51
|
+
Log.debug{ "RestClient get_json: #{ url } - #{Misc.fingerprint params }" }
|
52
|
+
params = params.merge({ :_format => 'json' })
|
53
|
+
|
54
|
+
res = capture_exception do
|
55
|
+
RestClient.get(URI.encode(url), :params => params)
|
56
|
+
end
|
57
|
+
|
58
|
+
begin
|
59
|
+
JSON.parse(res)
|
60
|
+
rescue
|
61
|
+
res
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.post_json(url, params = {})
|
66
|
+
if url =~ /_cache_type=:exec/
|
67
|
+
JSON.parse(Open.open(url, :nocache => true))
|
68
|
+
else
|
69
|
+
params = params.merge({ :_format => 'json' })
|
70
|
+
|
71
|
+
res = capture_exception do
|
72
|
+
RestClient.post(URI.encode(url), params)
|
73
|
+
end
|
74
|
+
|
75
|
+
begin
|
76
|
+
JSON.parse(res)
|
77
|
+
rescue
|
78
|
+
res
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
class WorkflowRESTClient
|
2
|
+
class RemoteStep < Step
|
3
|
+
|
4
|
+
attr_accessor :url, :base_url, :task, :base_name, :inputs, :result_type, :result_description, :exec
|
5
|
+
|
6
|
+
def initialize(base_url, task = nil, name = nil, inputs = nil, result_type = nil, result_description = nil, exec = false)
|
7
|
+
if task.nil?
|
8
|
+
@url = base_url
|
9
|
+
else
|
10
|
+
@base_url, @task, @name, @inputs, @result_type, @result_description = base_url, task, name, inputs, result_type, result_description
|
11
|
+
if exec
|
12
|
+
@url = [File.join(base_url, task.to_s), inputs]
|
13
|
+
else
|
14
|
+
self.fork
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(base_url, task = nil, base_name = nil, inputs = nil, result_type = nil, result_description = nil, exec = false)
|
20
|
+
@base_url, @task, @base_name, @inputs, @result_type, @result_description, @exec = base_url, task, base_name, inputs, result_type, result_description, exec
|
21
|
+
end
|
22
|
+
|
23
|
+
def name
|
24
|
+
return nil if exec
|
25
|
+
(Array === @url ? @url.first : @url).split("/").last
|
26
|
+
end
|
27
|
+
|
28
|
+
def task_name
|
29
|
+
(Array === @url ? @url.first : @url).split("/")[-2]
|
30
|
+
end
|
31
|
+
|
32
|
+
def info
|
33
|
+
info = WorkflowRESTClient.get_json(File.join(url, 'info'))
|
34
|
+
info = WorkflowRESTClient.fix_hash(info)
|
35
|
+
info[:status] = info[:status].to_sym if String === info[:status]
|
36
|
+
info
|
37
|
+
end
|
38
|
+
|
39
|
+
def status
|
40
|
+
info[:status]
|
41
|
+
end
|
42
|
+
|
43
|
+
def done?
|
44
|
+
status.to_s == 'done'
|
45
|
+
end
|
46
|
+
|
47
|
+
def files
|
48
|
+
WorkflowRESTClient.get_json(File.join(url, 'files'))
|
49
|
+
end
|
50
|
+
|
51
|
+
def file(file)
|
52
|
+
WorkflowRESTClient.get_raw(File.join(url, 'file', file))
|
53
|
+
end
|
54
|
+
|
55
|
+
#{{{ MANAGEMENT
|
56
|
+
|
57
|
+
def init_job(cache_type = :asynchronous)
|
58
|
+
@name = WorkflowRESTClient.post_jobname(File.join(base_url, task.to_s), inputs.merge(:jobname => @name, :_cache_type => cache_type))
|
59
|
+
@url = File.join(base_url, task.to_s, @name)
|
60
|
+
nil
|
61
|
+
end
|
62
|
+
|
63
|
+
def load_res(res)
|
64
|
+
case result_type
|
65
|
+
when :string
|
66
|
+
res
|
67
|
+
when :boolean
|
68
|
+
res == "true"
|
69
|
+
when :tsv
|
70
|
+
TSV.open(StringIO.new(res))
|
71
|
+
when :annotations
|
72
|
+
Annotated.load_tsv(TSV.open(StringIO.new(res)))
|
73
|
+
else
|
74
|
+
JSON.parse res
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def get
|
79
|
+
params = params.merge(:_format => [:string, :boolean, :tsv, :annotations].include?(result_type) ? :raw : :json )
|
80
|
+
begin
|
81
|
+
WorkflowRESTClient.get_raw(url, params)
|
82
|
+
rescue => e
|
83
|
+
raise e.response
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def load
|
88
|
+
params = {}
|
89
|
+
load_res get
|
90
|
+
end
|
91
|
+
|
92
|
+
def exec_job
|
93
|
+
res = WorkflowRESTClient.capture_exception do
|
94
|
+
RestClient.post(URI.encode(File.join(base_url, task.to_s)), inputs.merge(:_cache_type => :exec, :_format => [:string, :boolean, :tsv, :annotations].include?(result_type) ? :raw : :json))
|
95
|
+
end
|
96
|
+
load_res res
|
97
|
+
end
|
98
|
+
|
99
|
+
def fork
|
100
|
+
init_job
|
101
|
+
end
|
102
|
+
|
103
|
+
def run(noload = false)
|
104
|
+
return exec_job if exec
|
105
|
+
init_job(:synchronous)
|
106
|
+
noload ? name : self.load
|
107
|
+
end
|
108
|
+
|
109
|
+
def exec
|
110
|
+
exec_job
|
111
|
+
end
|
112
|
+
|
113
|
+
def join
|
114
|
+
self.load
|
115
|
+
self
|
116
|
+
end
|
117
|
+
|
118
|
+
def clean
|
119
|
+
WorkflowRESTClient.get_raw(url, :_update => :clean) unless exec
|
120
|
+
self
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
data/lib/rbbt/rest/main.rb
CHANGED
@@ -26,6 +26,8 @@ module Sinatra
|
|
26
26
|
|
27
27
|
set :public_folder, Rbbt.share.views.public.find
|
28
28
|
|
29
|
+
set :environment, ENV["RACK_ENV"].to_sym if ENV["RACK_ENV"]
|
30
|
+
|
29
31
|
attr_accessor :ajax, :layout, :format, :size, :update, :cache_type, :_, :profile
|
30
32
|
|
31
33
|
if production?
|
@@ -135,10 +137,8 @@ module Sinatra
|
|
135
137
|
halt 404, e.message
|
136
138
|
end
|
137
139
|
|
138
|
-
|
139
|
-
|
140
|
-
halt 404, e.message
|
141
|
-
end
|
140
|
+
error Exception do |e|
|
141
|
+
halt 500, [e.class.to_s, e.message] * " => "
|
142
142
|
end
|
143
143
|
end
|
144
144
|
end
|
data/lib/rbbt/rest/workflow.rb
CHANGED
@@ -69,6 +69,8 @@ module Sinatra
|
|
69
69
|
get "/#{workflow.to_s}/:task/info" do
|
70
70
|
task = consume_parameter(:task)
|
71
71
|
|
72
|
+
raise Workflow::TaskNotFoundException.new workflow, task unless workflow.tasks.include? task.to_sym
|
73
|
+
|
72
74
|
case format
|
73
75
|
when :html
|
74
76
|
workflow_render('task_info', workflow)
|
@@ -83,6 +85,8 @@ module Sinatra
|
|
83
85
|
get "/#{workflow.to_s}/:task/dependencies" do
|
84
86
|
task = consume_parameter(:task)
|
85
87
|
|
88
|
+
raise Workflow::TaskNotFoundException.new workflow, task unless workflow.tasks.include? task.to_sym
|
89
|
+
|
86
90
|
case format
|
87
91
|
when :html
|
88
92
|
workflow_render('task_dependencies', workflow)
|
@@ -103,6 +107,8 @@ module Sinatra
|
|
103
107
|
task = consume_parameter(:task)
|
104
108
|
jobname = consume_parameter(:jobname)
|
105
109
|
|
110
|
+
raise Workflow::TaskNotFoundException.new workflow, task unless workflow.tasks.include? task.to_sym
|
111
|
+
|
106
112
|
task_parameters = consume_task_parameters(workflow, task, params)
|
107
113
|
|
108
114
|
if complete_input_set(workflow, task, task_parameters) or format != :html
|
@@ -116,6 +122,8 @@ module Sinatra
|
|
116
122
|
task = consume_parameter(:task)
|
117
123
|
jobname = consume_parameter(:jobname)
|
118
124
|
|
125
|
+
raise Workflow::TaskNotFoundException.new workflow, task unless workflow.tasks.include? task.to_sym
|
126
|
+
|
119
127
|
task_parameters = consume_task_parameters(workflow, task, params)
|
120
128
|
|
121
129
|
issue_job(workflow, task, jobname, task_parameters)
|
@@ -125,6 +133,8 @@ module Sinatra
|
|
125
133
|
task = consume_parameter(:task)
|
126
134
|
job = consume_parameter(:job)
|
127
135
|
|
136
|
+
raise Workflow::TaskNotFoundException.new workflow, task unless workflow.tasks.include? task.to_sym
|
137
|
+
|
128
138
|
job = workflow.load_id(File.join(task, job))
|
129
139
|
|
130
140
|
clean_job(workflow, job) if update == :clean
|
@@ -160,6 +170,8 @@ module Sinatra
|
|
160
170
|
task = consume_parameter(:task)
|
161
171
|
job = consume_parameter(:job)
|
162
172
|
|
173
|
+
raise Workflow::TaskNotFoundException.new workflow, task unless workflow.tasks.include? task.to_sym
|
174
|
+
|
163
175
|
job = workflow.load_id(File.join(task, job))
|
164
176
|
|
165
177
|
case format
|
@@ -177,6 +189,8 @@ module Sinatra
|
|
177
189
|
task = consume_parameter(:task)
|
178
190
|
job = consume_parameter(:job)
|
179
191
|
|
192
|
+
raise Workflow::TaskNotFoundException.new workflow, task unless workflow.tasks.include? task.to_sym
|
193
|
+
|
180
194
|
job = workflow.load_id(File.join(task, job))
|
181
195
|
|
182
196
|
case format
|
@@ -195,6 +209,8 @@ module Sinatra
|
|
195
209
|
job = consume_parameter(:job)
|
196
210
|
filename = params[:splat].first
|
197
211
|
|
212
|
+
raise Workflow::TaskNotFoundException.new workflow, task unless workflow.tasks.include? task.to_sym
|
213
|
+
|
198
214
|
job = workflow.load_id(File.join(task, job))
|
199
215
|
|
200
216
|
send_file job.file(filename)
|
@@ -205,6 +221,8 @@ module Sinatra
|
|
205
221
|
job = consume_parameter(:job)
|
206
222
|
job = workflow.load_id(File.join(task, job))
|
207
223
|
|
224
|
+
raise Workflow::TaskNotFoundException.new workflow, task unless workflow.tasks.include? task.to_sym
|
225
|
+
|
208
226
|
clean_job(workflow, job)
|
209
227
|
end
|
210
228
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbbt-rest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miguel Vazquez
|
@@ -175,6 +175,9 @@ files:
|
|
175
175
|
- Rakefile
|
176
176
|
- config.ru
|
177
177
|
- lib/rbbt/rest/client.rb
|
178
|
+
- lib/rbbt/rest/client/adaptor.rb
|
179
|
+
- lib/rbbt/rest/client/get.rb
|
180
|
+
- lib/rbbt/rest/client/step.rb
|
178
181
|
- lib/rbbt/rest/common/cache.rb
|
179
182
|
- lib/rbbt/rest/common/forms.rb
|
180
183
|
- lib/rbbt/rest/common/locate.rb
|