t2-server 0.6.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/.rvmrc +1 -0
  2. data/CHANGES.rdoc +48 -0
  3. data/LICENCE.rdoc +2 -2
  4. data/README.rdoc +245 -10
  5. data/Rakefile +108 -0
  6. data/bin/t2-delete-runs +21 -34
  7. data/bin/t2-get-output +134 -0
  8. data/bin/t2-run-workflow +121 -109
  9. data/bin/t2-server-admin +128 -0
  10. data/bin/t2-server-info +25 -38
  11. data/lib/t2-server-cli.rb +116 -0
  12. data/lib/t2-server.rb +16 -27
  13. data/lib/t2-server/admin.rb +147 -0
  14. data/lib/t2-server/connection-parameters.rb +144 -0
  15. data/lib/t2-server/connection.rb +352 -0
  16. data/lib/t2-server/credentials.rb +84 -0
  17. data/lib/t2-server/exceptions.rb +42 -21
  18. data/lib/t2-server/port.rb +472 -0
  19. data/lib/t2-server/run.rb +822 -227
  20. data/lib/t2-server/server.rb +313 -317
  21. data/lib/t2-server/util.rb +71 -0
  22. data/lib/t2-server/xml/libxml.rb +87 -0
  23. data/lib/t2-server/xml/nokogiri.rb +85 -0
  24. data/lib/t2-server/xml/rexml.rb +85 -0
  25. data/lib/t2-server/xml/xml.rb +111 -0
  26. data/lib/t2server.rb +4 -1
  27. data/t2-server.gemspec +112 -0
  28. data/test/tc_admin.rb +63 -0
  29. data/test/{tc_paths.rb → tc_params.rb} +11 -25
  30. data/test/tc_perms.rb +132 -0
  31. data/test/tc_run.rb +200 -67
  32. data/test/tc_secure.rb +191 -0
  33. data/test/tc_server.rb +25 -23
  34. data/test/tc_util.rb +74 -0
  35. data/test/ts_t2server.rb +57 -12
  36. data/test/workflows/always_fail.t2flow +69 -0
  37. data/test/workflows/list_and_value.t2flow +12 -0
  38. data/test/workflows/list_with_errors.t2flow +107 -0
  39. data/test/workflows/secure/basic-http.t2flow +74 -0
  40. data/test/workflows/secure/basic-https.t2flow +74 -0
  41. data/test/workflows/secure/client-https.t2flow +162 -0
  42. data/test/workflows/secure/digest-http.t2flow +129 -0
  43. data/test/workflows/secure/digest-https.t2flow +107 -0
  44. data/test/workflows/secure/heater-pk.pem +20 -0
  45. data/test/workflows/secure/user-cert.p12 +0 -0
  46. data/test/workflows/secure/ws-http.t2flow +180 -0
  47. data/test/workflows/secure/ws-https.t2flow +180 -0
  48. data/test/workflows/strings.txt +10 -0
  49. data/test/workflows/xml_xpath.t2flow +136 -136
  50. data/version.yml +4 -0
  51. metadata +132 -34
  52. data/lib/t2-server/xml.rb +0 -86
data/bin/t2-delete-runs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- # Copyright (c) 2010, 2011 The University of Manchester, UK.
2
+ # Copyright (c) 2010-2012 The University of Manchester, UK.
3
3
  #
4
4
  # All rights reserved.
5
5
  #
@@ -15,7 +15,7 @@
15
15
  #
16
16
  # * Neither the names of The University of Manchester nor the names of its
17
17
  # contributors may be used to endorse or promote products derived from this
18
- # software without specific prior written permission.
18
+ # software without specific prior written permission.
19
19
  #
20
20
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
21
  # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -32,34 +32,24 @@
32
32
  # Author: Robert Haines
33
33
 
34
34
  require 'rubygems'
35
- require 't2-server'
36
- require 'optparse'
35
+ require 't2-server-cli'
36
+
37
+ include T2Server::CLI
37
38
 
38
39
  # set up options
39
- delete_all = false
40
- opts = OptionParser.new do |opt|
41
- opt.banner = "Usage: t2-delete-runs [options] server-address [run-ids...]"
42
- opt.separator ""
43
- opt.separator " Where server-address is the full URI of the server to connect to,"
44
- opt.separator " e.g.: http://example.com:8080/taverna, run-ids are the id numbers"
40
+ options = {}
41
+ conn_params, creds = register_options("Usage: t2-delete-runs [options] " +
42
+ "server-address [run-ids...]") do |opt|
43
+ opt.separator " Where server-address is the full URI of the server to " +
44
+ "connect to,"
45
+ opt.separator " e.g.: http://example.com:8080/taverna, run-ids are the " +
46
+ "id numbers"
45
47
  opt.separator " of the runs you want to delete and [options] can be:"
46
48
  opt.on("--all", "Delete all runs on the server") do
47
- delete_all = true
48
- end
49
- opt.on_tail("-h", "-?", "--help", "Show this message") do
50
- puts opt
51
- exit
52
- end
53
- opt.on_tail("-v", "--version", "Show the version") do
54
- puts "Taverna 2 Server Ruby Gem version: #{T2Server::GEM_VERSION}"
55
- puts "Taverna 2 Server REST API version: #{T2Server::API_VERSION}"
56
- exit
49
+ options[:all] = true
57
50
  end
58
51
  end
59
52
 
60
- # parse options
61
- opts.parse!
62
-
63
53
  # get runs and server address from the arguments
64
54
  runs = []
65
55
  address = ""
@@ -71,33 +61,30 @@ for arg in ARGV
71
61
  end
72
62
  end
73
63
 
74
- # can't do anything without a server address
75
- if address == ""
76
- puts opts
77
- exit 1
78
- end
64
+ uri, creds = parse_address(address, creds)
79
65
 
80
66
  # connect...
81
67
  begin
82
- server = T2Server::Server.connect(ARGV[0])
83
- rescue T2Server::T2ServerError => e
68
+ server = T2Server::Server.new(uri, conn_params)
69
+ rescue RuntimeError => e
84
70
  puts e
85
71
  exit 1
86
72
  end
87
73
 
88
74
  # ...and delete them!
89
- if delete_all
75
+ if options[:all]
90
76
  begin
91
- server.delete_all_runs
77
+ server.delete_all_runs(creds)
92
78
  rescue T2Server::AuthorizationError => ae
93
79
  puts "You are not authorized to delete runs on this server."
94
80
  rescue T2Server::T2ServerError => e
95
- puts "There was a problem while deleting runs. Some may remain on the server."
81
+ puts "There was a problem while deleting runs. " +
82
+ "Some may remain on the server."
96
83
  end
97
84
  else
98
85
  for run in runs
99
86
  begin
100
- server.delete_run(run)
87
+ server.delete_run(run, creds)
101
88
  rescue T2Server::RunNotFoundError => rnf
102
89
  puts "Run '#{run}' not found - skipping."
103
90
  next
data/bin/t2-get-output ADDED
@@ -0,0 +1,134 @@
1
+ #!/usr/bin/env ruby
2
+ # Copyright (c) 2010-2012 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 'rubygems'
35
+ require 't2-server-cli'
36
+
37
+ include T2Server::CLI
38
+
39
+ # set up options
40
+ options = {}
41
+ ports = []
42
+ conn_params, creds = register_options("Usage: t2-get-output [options] " +
43
+ "server-address run-id") do |opt|
44
+ opt.separator " Where server-address is the full URI of the server to"
45
+ opt.separator " connect to, e.g.: http://example.com:8080/taverna, run-ids"
46
+ opt.separator " are the id numbers of the runs you want to collect output"
47
+ opt.separator " from and [options] can be:"
48
+ opt.on("-r", "--refs", "Return references to the output data rather than " +
49
+ "the data itself.") do
50
+ options[:refs] = true
51
+ end
52
+ opt.on("-o", "--output=OUTPUT", "Return the named output port. If none " +
53
+ "are specified then list all the output ports.") do |val|
54
+ ports << val.chomp
55
+ end
56
+ opt.on("-x", "--exitcode", "Return the exitcode of the run.") do
57
+ options[:exitcode] = true
58
+ end
59
+ opt.on("-e", "--stderr", 'Return the "standard error" output of the run.') do
60
+ options[:stderr] = true
61
+ end
62
+ opt.on("-s", "--stdout", 'Return the "standard out" output of the run.') do
63
+ options[:stdout] = true
64
+ end
65
+ opt.on("-t", "--total-size", "Return the total size of the data in the " +
66
+ "output.") do
67
+ options[:tsize] = true
68
+ end
69
+ opt.on("-T", "--types", "Return the mime types of singleton ports.") do
70
+ options[:types] = true
71
+ end
72
+ end
73
+
74
+ # get run id and server address from the arguments
75
+ run_id = ""
76
+ address = ""
77
+ for arg in ARGV
78
+ argc = arg.chomp
79
+ if argc.match(/https?:\/\//).nil?
80
+ run_id = argc
81
+ else
82
+ address = argc
83
+ end
84
+ end
85
+
86
+ uri, creds = parse_address(address, creds)
87
+
88
+ if run_id.empty?
89
+ puts opts
90
+ exit 1
91
+ end
92
+
93
+ # connect...
94
+ begin
95
+ server = T2Server::Server.new(uri, conn_params)
96
+ run = server.run(run_id, creds)
97
+
98
+ ports = run.output_ports.keys if ports.empty?
99
+ ports.each do |p|
100
+ port = run.output_port(p)
101
+ puts "#{port.name}"
102
+ if options[:refs]
103
+ print " Reference: "
104
+ p port.reference
105
+ else
106
+ print " Value: "
107
+ p port.value
108
+ end
109
+
110
+ if options[:types]
111
+ print " Type: "
112
+ p port.type
113
+ end
114
+
115
+ if options[:tsize]
116
+ puts " Total data size: #{port.total_size}"
117
+ end
118
+ end
119
+
120
+ if options[:exitcode]
121
+ puts "Exitcode: #{run.exitcode}"
122
+ end
123
+
124
+ if options[:stdout]
125
+ puts "Stdout: #{run.stdout}"
126
+ end
127
+
128
+ if options[:stderr]
129
+ puts "Stderr: #{run.stderr}"
130
+ end
131
+ rescue RuntimeError => e
132
+ puts e
133
+ exit 1
134
+ end
data/bin/t2-run-workflow CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- # Copyright (c) 2010, 2011 The University of Manchester, UK.
2
+ # Copyright (c) 2010-2012 The University of Manchester, UK.
3
3
  #
4
4
  # All rights reserved.
5
5
  #
@@ -15,7 +15,7 @@
15
15
  #
16
16
  # * Neither the names of The University of Manchester nor the names of its
17
17
  # contributors may be used to endorse or promote products derived from this
18
- # software without specific prior written permission.
18
+ # software without specific prior written permission.
19
19
  #
20
20
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
21
  # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -32,156 +32,168 @@
32
32
  # Author: Robert Haines
33
33
 
34
34
  require 'rubygems'
35
- require 't2-server'
36
- require 'optparse'
35
+ require 't2-server-cli'
36
+
37
+ include T2Server::CLI
37
38
 
38
39
  # set up options
39
40
  inputs = {}
40
41
  files = {}
41
- wkf_file = ""
42
- output_refs = false
43
- baclava_out = ""
44
- delete_run = false
45
- no_wait = false
46
- opts = OptionParser.new do |opt|
47
- opt.banner = "Usage: t2-run-workflow [options] server-address"
48
- opt.separator ""
42
+ options = {}
43
+ conn_params, creds = register_options("Usage: t2-run-workflow [options] " +
44
+ "server-address") do |opt|
49
45
  opt.separator " Where server-address is the full URI of the server to"
50
46
  opt.separator " connect to, e.g.: http://example.com:8080/taverna"
51
47
  opt.separator " and [options] can be:"
52
- opt.on("-w WORKFLOW", "--workflow=WORKFLOW", "The workflow to run. If this is not " +
53
- "specified then the workflow is read from standard input") do |val|
54
- wkf_file = val
48
+ opt.on("-w WORKFLOW", "--workflow=WORKFLOW", "The workflow to run. If " +
49
+ "this is not specified then the workflow is read from standard " +
50
+ "input") do |val|
51
+ options[:wkf_file] = val.chomp
55
52
  end
56
- opt.on("-i INPUT:VALUE", "--input=INPUT:VALUE", "Set input port INPUT to VALUE") do |val|
57
- input, value = val.chomp.split(':', 2)
58
- inputs[input] = value
53
+ opt.on("-i INPUT:VALUE", "--input=INPUT:VALUE", "Set input port INPUT to " +
54
+ "VALUE") do |val|
55
+ input, value = val.chomp.split(':', 2)
56
+ inputs[input] = value
59
57
  end
60
58
  opt.on("-f INPUT:FILE", "--input-file=INPUT:FILE",
61
59
  "Set input port INPUT to use the contents of FILE as its input") do |val|
62
60
  input, filename = val.chomp.split(':', 2)
63
61
  files[input] = filename
64
- end
65
- opt.on("-b BACLAVA", "--baclava-in=BACLAVA", "Set baclava file for input port values") do |val|
66
- inputs[:baclava] = val
67
62
  end
68
- opt.on("-o", "--baclava-out[=BACLAVA]", "Return outputs in baclava format." +
63
+ opt.on("-e EXPIRY", "--expiry=EXPIRY", "Set the expiry date/time of this " +
64
+ "run") do |val|
65
+ options[:expiry] = Time.parse(val.chomp)
66
+ end
67
+ opt.on("-b BACLAVA", "--baclava-in=BACLAVA", "Set baclava file for input " +
68
+ "port values") do |val|
69
+ inputs[:baclava] = val
70
+ end
71
+ opt.on("-o", "--baclava-out=BACLAVA", "Return outputs in baclava format." +
69
72
  " A filename may be specified or 'out.xml' is used") do |val|
70
- if val != nil and val.include? "."
71
- baclava_out = val
72
- else
73
- baclava_out = "out.xml"
74
- end
73
+ options[:baclava_out] = val.chomp
75
74
  end
76
75
  opt.on("-n", "--no-wait", "Do not wait for workflow to finish, return " +
77
76
  "once it has started running") do |val|
78
- no_wait = true
77
+ options[:no_wait] = true
79
78
  end
80
79
  opt.on("-r", "--output-refs", "Return URIs that point to the data items " +
81
80
  "of the output rather than the data items themselves.") do |val|
82
- output_refs = val
81
+ options[:output_refs] = val
83
82
  end
84
83
  opt.on("-D", "--delete", "Delete the run from the server when it is " +
85
84
  "complete. By default the run and its results are preserved. Note that " +
86
85
  "the run will still be deleted when its expiry time is reached") do |val|
87
- delete_run = val
86
+ options[:delete] = val
88
87
  end
89
- opt.on_tail("-h", "-?", "--help", "Show this message") do
90
- puts opt
91
- exit
92
- end
93
- opt.on_tail("-v", "--version", "Show the version") do
94
- puts "Taverna 2 Server Ruby Gem version: #{T2Server::GEM_VERSION}"
95
- puts "Taverna 2 Server REST API version: #{T2Server::API_VERSION}"
96
- exit
88
+ opt.on("-z", "--zip=FILE", "Get the entire working directory of the run " +
89
+ "in zip format and save it to the provided filename.") do |val|
90
+ options[:zip_out] = val.chomp
97
91
  end
98
92
  end
99
93
 
100
- # parse options
101
- opts.parse!
102
-
103
94
  # read and check server address
104
- uri = ARGV.shift
105
- if uri == nil
106
- puts opts
107
- exit 1
108
- end
95
+ uri, creds = parse_address(ARGV.shift, creds)
109
96
 
110
- # read workflow
111
- if wkf_file == ""
112
- wkf = ARGF.read
97
+ # read workflow and ensure that it is not empty
98
+ if options[:wkf_file]
99
+ wkf = IO.read(options[:wkf_file])
113
100
  else
114
- wkf = IO.read(wkf_file)
101
+ wkf = ARGF.read
115
102
  end
103
+ exit 1 if wkf == ""
116
104
 
117
- # create run
118
105
  begin
119
- run = T2Server::Run.create(uri, wkf)
120
- rescue T2Server::T2ServerError => e
121
- puts e
122
- exit 1
123
- end
124
- puts "Created run with uuid: #{run.uuid}"
125
- puts "Created at #{run.create_time}"
106
+ T2Server::Run.create(uri, wkf, creds, conn_params) do |run|
107
+ puts "Created run with identifier: #{run.identifier}"
108
+ puts "Created at #{run.create_time}"
126
109
 
127
- # set inputs
128
- if inputs.has_key?(:baclava)
129
- run.upload_baclava_file(inputs[:baclava])
130
- puts "Uploaded baclava input file"
131
- else
132
- inputs.each do |input, value|
133
- puts "Set input '#{input}' to #{value}"
134
- run.set_input(input, value)
135
- end
136
-
137
- files.each do |input, file|
138
- name = file.split("/")[-1];
139
- puts "Set input '#{input}' to use file '#{name}'"
140
- run.upload_input_file(input, file)
141
- end
142
- end
110
+ # set run expiry
111
+ if options[:expiry]
112
+ run.expiry=(options[:expiry])
113
+ puts "Expiry time set to #{run.expiry}"
114
+ end
115
+
116
+ # set inputs
117
+ in_ports = run.input_ports
118
+ if inputs.has_key?(:baclava)
119
+ run.baclava_input = inputs[:baclava]
120
+ puts "Uploaded baclava input file"
121
+ else
122
+ in_ports.each_value do |port|
123
+ input = port.name
124
+ if inputs.include? input
125
+ port.value = inputs[input]
126
+ puts "Input '#{input}' set to #{port.value}"
127
+ elsif files.include? input
128
+ port.file = files[input]
129
+ puts "Input '#{input}' set to use file '#{port.file}'"
130
+ else
131
+ puts "Input '#{input}' has not been set."
132
+ run.delete
133
+ exit 1
134
+ end
135
+ end
136
+ end
143
137
 
144
- # output baclava?
145
- run.set_baclava_output(baclava_out) unless baclava_out == ""
138
+ # output baclava?
139
+ run.request_baclava_output if options[:baclava_out]
146
140
 
147
- # start run and wait until it is finished
148
- run.start
149
- puts "Started at #{run.start_time}"
141
+ # start run and wait until it is finished
142
+ run.start
143
+ puts "Started at #{run.start_time}"
150
144
 
151
- # bail out if user doesn't want to wait
152
- exit 0 if no_wait
145
+ # bail out if user doesn't want to wait
146
+ exit 0 if options[:no_wait]
153
147
 
154
- # otherwise wait
155
- print "Running"
156
- run.wait(:progress => true)
157
- puts "Finished at #{run.finish_time}"
148
+ # otherwise wait
149
+ print "Running"
150
+ until run.finished?
151
+ sleep(1)
152
+ print "."
153
+ $stdout.flush
154
+ end
155
+ puts "\nFinished at #{run.finish_time}"
158
156
 
159
- # get outputs
160
- stdout = run.stdout
161
- stderr = run.stderr
162
- exitcd = run.exitcode
163
- puts "Exitcode: #{exitcd}"
164
- if stdout != "" then puts "Stdout:\n#{stdout}" end
165
- if stderr != "" then puts "Stderr:\n#{stderr}" end
157
+ # get outputs
158
+ stdout = run.stdout
159
+ stderr = run.stderr
160
+ exitcd = run.exitcode
161
+ puts "Exitcode: #{exitcd}"
162
+ if stdout != "" then puts "Stdout:\n#{stdout}" end
163
+ if stderr != "" then puts "Stderr:\n#{stderr}" end
166
164
 
167
- if exitcd == 0
168
- if baclava_out != ""
169
- File.open(baclava_out, "w") do |file|
170
- file.syswrite(run.get_baclava_output)
165
+ if exitcd == 0
166
+ if options[:baclava_out]
167
+ File.open(options[:baclava_out], "w") do |file|
168
+ file.syswrite(run.baclava_output)
169
+ end
170
+ puts "Baclava file written to '#{options[:baclava_out]}'"
171
+ elsif options[:zip_out]
172
+ File.open(options[:zip_out],"w") do |file|
173
+ file.syswrite(run.zip_output)
174
+ end
175
+ puts "Zip file written to '#{options[:zip_out]}'"
176
+ else
177
+ # go through the outputs and print them out
178
+ puts "Outputs:"
179
+ run.output_ports.each_value do |port|
180
+ print " #{port.name} (#{port.depth}) -> "
181
+ if options[:output_refs]
182
+ p port.reference
183
+ else
184
+ p port.value
185
+ end
186
+ end
187
+ end
171
188
  end
172
- puts "Baclava file written to '#{baclava_out}'"
173
- else
174
- # go through the outputs and print them out
175
- puts "Outputs:"
176
- run.get_output_ports.each do |o|
177
- print " #{o} -> "
178
- p run.get_output("#{o}", output_refs)
189
+
190
+ # delete run?
191
+ if options[:delete]
192
+ run.delete
193
+ puts "Run deleted"
179
194
  end
180
195
  end
181
- end
182
-
183
- # delete run?
184
- if delete_run
185
- run.delete
186
- puts "Run deleted"
196
+ rescue RuntimeError => e
197
+ puts e
198
+ exit 1
187
199
  end