t2-server 0.0.3 → 0.0.4

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.
@@ -1,21 +1,50 @@
1
1
  = Taverna[http://www.taverna.org.uk/] 2 Server Interaction Gem
2
2
 
3
- Authors:: Robert Haines
4
- Version:: 0.1
5
- Contact:: mailto:rhaines@manchester.ac.uk
6
- URL:: http://taverna.sourceforge.net/
7
- Licence:: BSD (See LICENCE or http://www.opensource.org/licenses/bsd-license.php)
8
- Copyright:: (c) 2010 The University of Manchester, UK
3
+ Authors:: Robert Haines
4
+ Gem Version:: 0.0.4
5
+ API Version:: 2.2a1
6
+ Contact:: mailto:rhaines@manchester.ac.uk
7
+ URL:: http://taverna.sourceforge.net/
8
+ Licence:: BSD (See LICENCE or http://www.opensource.org/licenses/bsd-license.php)
9
+ Copyright:: (c) 2010 The University of Manchester, UK
9
10
 
10
11
 
11
12
  == Synopsis
12
13
 
13
- This is a Ruby library to interface with the Taverna 2 Server REST interface.
14
+ This is a Ruby library to interface with the Taverna 2 Server REST API.
14
15
 
15
16
  == Installation
16
17
 
17
- [sudo] gem install t2-server
18
+ Ensure that gem itself is up to date:
19
+ [sudo] gem update --system
20
+
21
+ Then simply install as you would any other gem:
22
+ [sudo] gem install t2-server
23
+
24
+ In case of problems with the above the gem is available for download here:
25
+ http://rubygems.org/gems/t2-server
26
+
27
+ You can also download the source code from here:
28
+ http://github.com/myGrid/t2-server-gem
18
29
 
19
30
  == Usage
20
31
 
21
- TBC
32
+ As well as the library there are also a couple of example scripts which
33
+ demonstrate good use of the T2Server API. These are available in the
34
+ <tt>bin</tt> directory:
35
+ * run_workflow
36
+ * server_info
37
+ * delete_all_runs
38
+ Running any of these scripts with a <tt>-h</tt> or <tt>--help</tt>
39
+ switch will show how to use them, e.g.:
40
+ run_workflow --help
41
+
42
+ == Support
43
+
44
+ Please email mailto:support@mygrid.org.uk for any questions relating to
45
+ this Ruby gem.
46
+
47
+ == References
48
+
49
+ Taverna 2 Server:: http://www.taverna.org.uk/documentation/taverna-2-x/server/
50
+ REST API Documentation:: http://www.taverna.org.uk/documentation/taverna-2-x/server/rest-api/
@@ -38,23 +38,17 @@ require 'optparse'
38
38
  # out or save them to a file.
39
39
  # if the output is a list, it appears as a directory so
40
40
  # all the individual entries must be grabbed from there.
41
- # server seems to be rather sensitive to slashes, hence
42
- # all the [...] mucking about.
43
41
  def get_outputs(run, pout, dir="")
44
42
  dirs, files = run.ls("out#{dir}")
45
43
  dirs.each {|d| get_outputs(run, pout, "#{dir}/#{d}")}
46
44
  files.each do |out|
47
45
  print " #{dir}/#{out} -> "
48
- if dir == ""
49
- output_name = out
50
- else
51
- output_name = "#{dir[1..-1]}/#{out}"
52
- end
53
- data = run.get_output(output_name)
46
+ data = run.get_output("#{dir}/#{out}")
54
47
  if pout
55
48
  p data
56
49
  else
57
- filename = output_name.gsub('/', '-')
50
+ # remove leading slash
51
+ filename = "#{dir[1..-1]}/#{out}".gsub('/', '-')
58
52
  File.open(filename, "w") do |file|
59
53
  file.syswrite(data)
60
54
  end
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env ruby
2
+ # Copyright (c) 2010, The University of Manchester, UK.
3
+ #
4
+ # All rights reserved.
5
+ #
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted provided that the following conditions are met:
8
+ #
9
+ # * Redistributions of source code must retain the above copyright notice,
10
+ # this list of conditions and the following disclaimer.
11
+ #
12
+ # * Redistributions in binary form must reproduce the above copyright notice,
13
+ # this list of conditions and the following disclaimer in the documentation
14
+ # and/or other materials provided with the distribution.
15
+ #
16
+ # * Neither the names of The University of Manchester nor the names of its
17
+ # contributors may be used to endorse or promote products derived from this
18
+ # software without specific prior written permission.
19
+ #
20
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
+ # POSSIBILITY OF SUCH DAMAGE.
31
+ #
32
+ # Author: Robert Haines
33
+
34
+ require 't2server'
35
+ require 'optparse'
36
+
37
+ opts = OptionParser.new do |opt|
38
+ opt.banner = "Usage: server_info [options] server-address"
39
+ opt.separator ""
40
+ opt.separator " Where server-address is the full URI of the server to"
41
+ opt.separator " connect to, e.g.: http://example.com:8080/taverna"
42
+ opt.separator " and [options] can be:"
43
+ opt.on_tail("-h", "-?", "--help", "Show this message") do
44
+ puts opt
45
+ exit
46
+ end
47
+ opt.on_tail("-v", "--version", "Show the version") do
48
+ puts "Taverna 2 Server Ruby Gem version: #{T2Server::GEM_VERSION}"
49
+ puts "Taverna 2 Server REST API version: #{T2Server::API_VERSION}"
50
+ exit
51
+ end
52
+ end
53
+
54
+ # parse options
55
+ opts.parse!
56
+
57
+ # read and check server address
58
+ uri = ARGV.shift
59
+ if uri == nil
60
+ puts opts
61
+ exit 1
62
+ end
63
+
64
+ # connect to server and output information
65
+ server = T2Server::Server.connect(uri)
66
+ print " Server: #{uri}\n"
67
+ print " Run limit: #{server.run_limit}\n"
68
+ runs = server.runs
69
+ print "No. of runs: #{runs.length}\n"
70
+ if runs.length > 0
71
+ print " Run list: #{runs[0].uuid} - #{runs[0].expiry}\n"
72
+ runs[1..-1].each do |run|
73
+ print " #{run.uuid} - #{run.expiry}\n"
74
+ end
75
+ end
@@ -35,6 +35,6 @@ require 't2server/server'
35
35
  require 't2server/run'
36
36
 
37
37
  module T2Server
38
- GEM_VERSION = "0.0.3"
39
- API_VERSION = "2.2.0a1"
38
+ GEM_VERSION = "0.0.4"
39
+ API_VERSION = "2.2a1"
40
40
  end
@@ -51,7 +51,7 @@ module T2Server
51
51
  @port = uri.port
52
52
  @base_path = uri.path
53
53
  @rest_path = uri.path + "/rest"
54
- @links = get_server_description
54
+ @links = parse_description(get_attribute(@rest_path))
55
55
  #@links.each {|key, val| puts "#{key}: #{val}"}
56
56
 
57
57
  # get max runs
@@ -81,7 +81,7 @@ module T2Server
81
81
  end
82
82
 
83
83
  def initialize_run(workflow)
84
- request = Net::HTTP::Post.new("#{@links[:runs]}")
84
+ request = Net::HTTP::Post.new("#{@links[:runs]}".gsub("//", "/"))
85
85
  request.content_type = "application/xml"
86
86
  response = Net::HTTP.new(@host, @port).start do |http|
87
87
  http.request(request, Fragments::WORKFLOW % workflow)
@@ -111,7 +111,7 @@ module T2Server
111
111
  end
112
112
 
113
113
  def delete_run(uuid)
114
- request = Net::HTTP::Delete.new("#{@links[:runs]}/#{uuid}")
114
+ request = Net::HTTP::Delete.new("#{@links[:runs]}/#{uuid}".gsub("//", "/"))
115
115
  response = Net::HTTP.new(@host, @port).start {|http| http.request(request)}
116
116
 
117
117
  case response
@@ -133,7 +133,7 @@ module T2Server
133
133
  end
134
134
 
135
135
  def set_run_input(run, input, value)
136
- request = Net::HTTP::Put.new("#{@links[:runs]}/#{run.uuid}/#{run.inputs}/input/#{input}")
136
+ request = Net::HTTP::Put.new("#{@links[:runs]}/#{run.uuid}/#{run.inputs}/input/#{input}".gsub("//", "/"))
137
137
  request.content_type = "application/xml"
138
138
  response = Net::HTTP.new(@host, @port).start do |http|
139
139
  http.request(request, Fragments::RUNINPUTVALUE % value)
@@ -149,7 +149,7 @@ module T2Server
149
149
  end
150
150
 
151
151
  def set_run_input_file(run, input, filename)
152
- request = Net::HTTP::Put.new("#{@links[:runs]}/#{run.uuid}/#{run.inputs}/input/#{input}")
152
+ request = Net::HTTP::Put.new("#{@links[:runs]}/#{run.uuid}/#{run.inputs}/input/#{input}".gsub("//", "/"))
153
153
  request.content_type = "application/xml"
154
154
  response = Net::HTTP.new(@host, @port).start do |http|
155
155
  http.request(request, Fragments::RUNINPUTFILE % filename)
@@ -165,7 +165,7 @@ module T2Server
165
165
  end
166
166
 
167
167
  def make_run_dir(uuid, root, dir)
168
- request = Net::HTTP::Post.new("#{@links[:runs]}/#{uuid}/#{root}")
168
+ request = Net::HTTP::Post.new("#{@links[:runs]}/#{uuid}/#{root}".gsub("//", "/"))
169
169
  request.content_type = "application/xml"
170
170
  response = Net::HTTP.new(@host, @port).start do |http|
171
171
  http.request(request, Fragments::MKDIR % dir)
@@ -189,7 +189,7 @@ module T2Server
189
189
  def upload_run_file(uuid, filename, location, rename)
190
190
  contents = Base64.encode64(IO.read(filename))
191
191
  rename = filename.split('/')[-1] if rename == ""
192
- request = Net::HTTP::Post.new("#{@links[:runs]}/#{uuid}/#{location}")
192
+ request = Net::HTTP::Post.new("#{@links[:runs]}/#{uuid}/#{location}".gsub("//", "/"))
193
193
  request.content_type = "application/xml"
194
194
  response = Net::HTTP.new(@host, @port).start do |http|
195
195
  http.request(request, Fragments::UPLOAD % [rename, contents])
@@ -211,7 +211,7 @@ module T2Server
211
211
  end
212
212
 
213
213
  def set_run_attribute(uuid, path, value)
214
- request = Net::HTTP::Put.new("#{@links[:runs]}/#{uuid}/#{path}")
214
+ request = Net::HTTP::Put.new("#{@links[:runs]}/#{uuid}/#{path}".gsub("//", "/"))
215
215
  request.content_type = "text/plain"
216
216
  response = Net::HTTP.new(@host, @port).start {|http| http.request(request, value)}
217
217
 
@@ -231,9 +231,9 @@ module T2Server
231
231
  end
232
232
  end
233
233
 
234
- protected
234
+ private
235
235
  def get_attribute(path)
236
- request = Net::HTTP::Get.new(path)
236
+ request = Net::HTTP::Get.new(path.gsub("//", "/"))
237
237
  response = Net::HTTP.new(@host, @port).start {|http| http.request(request)}
238
238
 
239
239
  case response
@@ -241,19 +241,8 @@ module T2Server
241
241
  return response.body
242
242
  when Net::HTTPNotFound
243
243
  puts "Cannot find attribute #{path}."
244
- else
245
- response_error(response)
246
- end
247
- end
248
-
249
- private
250
- def get_server_description
251
- request = Net::HTTP::Get.new(@rest_path)
252
- response = Net::HTTP.new(@host, @port).start {|http| http.request(request)}
253
-
254
- case response
255
- when Net::HTTPOK
256
- parse_description(response.body)
244
+ when Net::HTTPForbidden
245
+ puts "Verboten!"
257
246
  else
258
247
  response_error(response)
259
248
  end
@@ -269,20 +258,6 @@ module T2Server
269
258
  :permlisteners => URI.parse(XPath.first(doc, "//nsr:permittedListeners", nsmap).attributes["href"]).path
270
259
  }
271
260
  end
272
-
273
- def get_run_description(uuid)
274
- request = Net::HTTP::Get.new("#{@links[:runs]}/#{uuid}")
275
- response = Net::HTTP.new(@host, @port).start {|http| http.request(request)}
276
-
277
- case response
278
- when Net::HTTPOK
279
- return response.body
280
- when Net::HTTPNotFound
281
- puts "Cannot find run #{uuid}."
282
- else
283
- response_error(response)
284
- end
285
- end
286
261
 
287
262
  def response_error(response)
288
263
  puts "Unnexpected response from Taverna Server!"
@@ -296,36 +271,29 @@ module T2Server
296
271
  end
297
272
 
298
273
  def get_runs
299
- request = Net::HTTP::Get.new("#{@links[:runs]}")
300
- response = Net::HTTP.new(@host, @port).start {|http| http.request(request)}
301
-
302
- case response
303
- when Net::HTTPOK
304
- doc = Document.new(response.body)
305
-
306
- # get list of run uuids
307
- uuids = []
308
- XPath.each(doc, "//nsr:run", Namespaces::MAP) do |run|
309
- uuids << run.attributes["href"].split('/')[-1]
310
- end
311
-
312
- # add new runs
313
- uuids.each do |uuid|
314
- if !@runs.has_key? uuid
315
- description = get_run_description(uuid)
316
- @runs[uuid] = Run.create(self, "", uuid)
317
- end
318
- end
319
-
320
- # clear out the expired runs
321
- if @runs.length > @run_limit
322
- @runs.delete_if {|key, val| !uuids.member? key}
274
+ run_list = get_attribute("#{@links[:runs]}")
275
+
276
+ doc = Document.new(run_list)
277
+
278
+ # get list of run uuids
279
+ uuids = []
280
+ XPath.each(doc, "//nsr:run", Namespaces::MAP) do |run|
281
+ uuids << run.attributes["href"].split('/')[-1]
282
+ end
283
+
284
+ # add new runs
285
+ uuids.each do |uuid|
286
+ if !@runs.has_key? uuid
287
+ @runs[uuid] = Run.create(self, "", uuid)
323
288
  end
289
+ end
324
290
 
325
- @runs
326
- else
327
- response_error(response)
291
+ # clear out the expired runs
292
+ if @runs.length > @run_limit
293
+ @runs.delete_if {|key, val| !uuids.member? key}
328
294
  end
295
+
296
+ @runs
329
297
  end
330
298
  end
331
299
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: t2-server
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Robert Haines
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-26 00:00:00 +01:00
18
+ date: 2010-07-30 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -29,6 +29,7 @@ extra_rdoc_files:
29
29
  - README.rdoc
30
30
  - LICENCE
31
31
  files:
32
+ - bin/server_info
32
33
  - bin/run_workflow
33
34
  - bin/delete_all_runs
34
35
  - lib/t2server.rb