t2-server 0.9.3 → 1.0.0
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.
- data/CHANGES.rdoc +79 -0
- data/LICENCE.rdoc +1 -1
- data/README.rdoc +94 -26
- data/Rakefile +6 -5
- data/bin/t2-delete-runs +25 -23
- data/bin/t2-get-output +11 -13
- data/bin/t2-run-workflow +91 -29
- data/bin/t2-server-info +29 -12
- data/extras/t2-server-stress +184 -0
- data/lib/t2-server-cli.rb +48 -23
- data/lib/t2-server.rb +2 -1
- data/lib/t2-server/admin.rb +7 -4
- data/lib/t2-server/exceptions.rb +23 -4
- data/lib/t2-server/interaction.rb +241 -0
- data/lib/t2-server/net/connection.rb +90 -60
- data/lib/t2-server/net/credentials.rb +25 -9
- data/lib/t2-server/net/parameters.rb +21 -6
- data/lib/t2-server/port.rb +229 -140
- data/lib/t2-server/run-cache.rb +99 -0
- data/lib/t2-server/run.rb +349 -332
- data/lib/t2-server/server.rb +115 -164
- data/lib/t2-server/util.rb +11 -9
- data/lib/t2-server/xml/libxml.rb +3 -2
- data/lib/t2-server/xml/nokogiri.rb +4 -3
- data/lib/t2-server/xml/rexml.rb +3 -2
- data/lib/t2-server/xml/xml.rb +47 -36
- data/lib/{t2server.rb → t2-server/xml/xpath_cache.rb} +29 -7
- data/t2-server.gemspec +16 -5
- data/test/tc_misc.rb +61 -0
- data/test/tc_perms.rb +17 -1
- data/test/tc_run.rb +164 -34
- data/test/tc_secure.rb +11 -2
- data/test/tc_server.rb +23 -2
- data/test/ts_t2server.rb +10 -8
- data/test/workflows/missing_outputs.t2flow +440 -0
- data/version.yml +3 -3
- metadata +42 -4
data/lib/t2-server/xml/libxml.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2010-
|
1
|
+
# Copyright (c) 2010-2013 The University of Manchester, UK.
|
2
2
|
#
|
3
3
|
# All rights reserved.
|
4
4
|
#
|
@@ -80,7 +80,8 @@ module T2Server
|
|
80
80
|
end
|
81
81
|
|
82
82
|
def xpath_attr(doc, expr, attribute)
|
83
|
-
doc
|
83
|
+
node = xpath_first(doc, expr)
|
84
|
+
node.nil? ? nil : node.attributes[attribute]
|
84
85
|
end
|
85
86
|
end
|
86
87
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2010-
|
1
|
+
# Copyright (c) 2010-2013 The University of Manchester, UK.
|
2
2
|
#
|
3
3
|
# All rights reserved.
|
4
4
|
#
|
@@ -50,7 +50,7 @@ module T2Server
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def xml_children(doc, &block)
|
53
|
-
doc.children.each
|
53
|
+
doc.children.each(&block)
|
54
54
|
end
|
55
55
|
|
56
56
|
def xml_node_name(node)
|
@@ -78,7 +78,8 @@ module T2Server
|
|
78
78
|
end
|
79
79
|
|
80
80
|
def xpath_attr(doc, expr, attribute)
|
81
|
-
doc
|
81
|
+
node = xpath_first(doc, expr)
|
82
|
+
node.nil? ? nil : node[attribute]
|
82
83
|
end
|
83
84
|
end
|
84
85
|
end
|
data/lib/t2-server/xml/rexml.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2010-
|
1
|
+
# Copyright (c) 2010-2013 The University of Manchester, UK.
|
2
2
|
#
|
3
3
|
# All rights reserved.
|
4
4
|
#
|
@@ -78,7 +78,8 @@ module T2Server
|
|
78
78
|
end
|
79
79
|
|
80
80
|
def xpath_attr(doc, expr, attribute)
|
81
|
-
|
81
|
+
node = xpath_first(doc, expr)
|
82
|
+
node.nil? ? nil : node.attributes[attribute]
|
82
83
|
end
|
83
84
|
end
|
84
85
|
end
|
data/lib/t2-server/xml/xml.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2010-
|
1
|
+
# Copyright (c) 2010-2013 The University of Manchester, UK.
|
2
2
|
#
|
3
3
|
# All rights reserved.
|
4
4
|
#
|
@@ -39,6 +39,7 @@ rescue LoadError
|
|
39
39
|
require 't2-server/xml/rexml'
|
40
40
|
end
|
41
41
|
end
|
42
|
+
require 't2-server/xml/xpath_cache'
|
42
43
|
|
43
44
|
module T2Server
|
44
45
|
module XML
|
@@ -58,54 +59,64 @@ module T2Server
|
|
58
59
|
end
|
59
60
|
|
60
61
|
module Fragments
|
61
|
-
WORKFLOW = "<t2s:workflow xmlns:t2s=\"#{Namespaces::SERVER}\">\n"
|
62
|
-
|
63
|
-
RUNINPUT = "<t2sr:runInput xmlns:t2sr=\"#{Namespaces::REST}\">\n"
|
64
|
-
|
62
|
+
WORKFLOW = "<t2s:workflow xmlns:t2s=\"#{Namespaces::SERVER}\">\n"\
|
63
|
+
" %s\n</t2s:workflow>"
|
64
|
+
RUNINPUT = "<t2sr:runInput xmlns:t2sr=\"#{Namespaces::REST}\">\n"\
|
65
|
+
" %s\n</t2sr:runInput>"
|
65
66
|
RUNINPUTVALUE = RUNINPUT % "<t2sr:value>%s</t2sr:value>"
|
66
67
|
RUNINPUTFILE = RUNINPUT % "<t2sr:file>%s</t2sr:file>"
|
67
|
-
UPLOAD = "<t2sr:upload xmlns:t2sr=\"#{Namespaces::REST}\" "
|
68
|
+
UPLOAD = "<t2sr:upload xmlns:t2sr=\"#{Namespaces::REST}\" "\
|
68
69
|
"t2sr:name=\"%s\">\n %s\n</t2sr:upload>"
|
69
|
-
MKDIR = "<t2sr:mkdir xmlns:t2sr=\"#{Namespaces::REST}\" "
|
70
|
+
MKDIR = "<t2sr:mkdir xmlns:t2sr=\"#{Namespaces::REST}\" "\
|
70
71
|
"t2sr:name=\"%s\" />"
|
71
72
|
|
72
|
-
PERMISSION = "<t2sr:userName>%s</t2sr:userName>"
|
73
|
+
PERMISSION = "<t2sr:userName>%s</t2sr:userName>"\
|
73
74
|
"<t2sr:permission>%s</t2sr:permission>"
|
74
|
-
PERM_UPDATE = "<t2sr:permissionUpdate "
|
75
|
-
|
76
|
-
|
75
|
+
PERM_UPDATE = "<t2sr:permissionUpdate "\
|
76
|
+
"xmlns:t2sr=\"#{Namespaces::REST}\">"\
|
77
|
+
"#{PERMISSION}</t2sr:permissionUpdate>"
|
77
78
|
|
78
79
|
SERVICE_URI = "<t2s:serviceURI>%s</t2s:serviceURI>"
|
79
|
-
CREDENTIAL = "<t2sr:credential xmlns:t2sr=\"#{Namespaces::REST}\""
|
80
|
-
" xmlns:t2s=\"#{Namespaces::SERVER}\">\n"
|
81
|
-
|
82
|
-
USERPASS_CRED = "<t2s:userpass>\n"
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
80
|
+
CREDENTIAL = "<t2sr:credential xmlns:t2sr=\"#{Namespaces::REST}\""\
|
81
|
+
" xmlns:t2s=\"#{Namespaces::SERVER}\">\n"\
|
82
|
+
"%s\n</t2sr:credential>"
|
83
|
+
USERPASS_CRED = "<t2s:userpass>\n"\
|
84
|
+
" #{SERVICE_URI}\n"\
|
85
|
+
" <t2s:username>%s</t2s:username>\n"\
|
86
|
+
" <t2s:password>%s</t2s:password>\n"\
|
87
|
+
"</t2s:userpass>"
|
87
88
|
|
88
|
-
KEYPAIR_CRED = "<t2s:keypair>\n"
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
89
|
+
KEYPAIR_CRED = "<t2s:keypair>\n"\
|
90
|
+
" #{SERVICE_URI}\n"\
|
91
|
+
" <t2s:credentialName>%s</t2s:credentialName>\n"\
|
92
|
+
" <t2s:credentialBytes>%s</t2s:credentialBytes>\n"\
|
93
|
+
" <t2s:fileType>%s</t2s:fileType>\n"\
|
94
|
+
" <t2s:unlockPassword>%s</t2s:unlockPassword>\n"\
|
95
|
+
"</t2s:keypair>"
|
95
96
|
|
96
|
-
TRUST = "<t2s:trustedIdentity "
|
97
|
-
"xmlns:t2s=\"#{Namespaces::SERVER}\">\n"
|
98
|
-
|
99
|
-
|
100
|
-
|
97
|
+
TRUST = "<t2s:trustedIdentity "\
|
98
|
+
"xmlns:t2s=\"#{Namespaces::SERVER}\">\n"\
|
99
|
+
" <t2s:certificateBytes>%s</t2s:certificateBytes>\n"\
|
100
|
+
" <t2s:fileType>%s</t2s:fileType>\n"\
|
101
|
+
"</t2s:trustedIdentity>"
|
101
102
|
end
|
102
103
|
|
103
104
|
module Methods
|
104
|
-
#
|
105
|
-
# library selected above.
|
106
|
-
|
107
|
-
#
|
108
|
-
|
105
|
+
# Most methods in this module are provided by the particular XML
|
106
|
+
# library selected above.
|
107
|
+
|
108
|
+
# Given a list of xpath keys, extract the href URIs from those elements.
|
109
|
+
def get_uris_from_doc(doc, keys)
|
110
|
+
cache = XPathCache.instance
|
111
|
+
uris = {}
|
112
|
+
|
113
|
+
keys.each do |key|
|
114
|
+
uri = xpath_attr(doc, cache[key], "href")
|
115
|
+
uris[key] = uri.nil? ? nil : URI.parse(uri)
|
116
|
+
end
|
117
|
+
|
118
|
+
uris
|
119
|
+
end
|
109
120
|
end
|
110
121
|
end
|
111
122
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2010
|
1
|
+
# Copyright (c) 2010-2013 The University of Manchester, UK.
|
2
2
|
#
|
3
3
|
# All rights reserved.
|
4
4
|
#
|
@@ -30,9 +30,31 @@
|
|
30
30
|
#
|
31
31
|
# Author: Robert Haines
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
33
|
+
require 'singleton'
|
34
|
+
|
35
|
+
module T2Server
|
36
|
+
module XML
|
37
|
+
class XPathCache
|
38
|
+
include Singleton
|
39
|
+
include XML::Methods
|
40
|
+
|
41
|
+
def initialize
|
42
|
+
@cache = {}
|
43
|
+
@xpaths = {}
|
44
|
+
end
|
45
|
+
|
46
|
+
def [](key)
|
47
|
+
return nil unless @xpaths.has_key? key
|
48
|
+
return @cache[key] if @cache.has_key? key
|
49
|
+
|
50
|
+
xpath = @xpaths[key]
|
51
|
+
@cache[key] = xpath_compile(xpath)
|
52
|
+
end
|
53
|
+
|
54
|
+
def register_xpaths(xpaths)
|
55
|
+
@xpaths.merge! xpaths
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/t2-server.gemspec
CHANGED
@@ -5,13 +5,13 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "t2-server"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "1.0.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Robert Haines"]
|
12
|
-
s.date = "2013-05
|
11
|
+
s.authors = ["Robert Haines", "Finn Bacall"]
|
12
|
+
s.date = "2013-11-05"
|
13
13
|
s.description = "This gem provides access to the Taverna 2 Server REST interface from Ruby."
|
14
|
-
s.email = ["
|
14
|
+
s.email = ["support@mygrid.org.uk"]
|
15
15
|
s.executables = ["t2-delete-runs", "t2-run-workflow", "t2-server-info", "t2-get-output", "t2-server-admin"]
|
16
16
|
s.extra_rdoc_files = [
|
17
17
|
"CHANGES.rdoc",
|
@@ -28,14 +28,17 @@ Gem::Specification.new do |s|
|
|
28
28
|
"bin/t2-run-workflow",
|
29
29
|
"bin/t2-server-admin",
|
30
30
|
"bin/t2-server-info",
|
31
|
+
"extras/t2-server-stress",
|
31
32
|
"lib/t2-server-cli.rb",
|
32
33
|
"lib/t2-server.rb",
|
33
34
|
"lib/t2-server/admin.rb",
|
34
35
|
"lib/t2-server/exceptions.rb",
|
36
|
+
"lib/t2-server/interaction.rb",
|
35
37
|
"lib/t2-server/net/connection.rb",
|
36
38
|
"lib/t2-server/net/credentials.rb",
|
37
39
|
"lib/t2-server/net/parameters.rb",
|
38
40
|
"lib/t2-server/port.rb",
|
41
|
+
"lib/t2-server/run-cache.rb",
|
39
42
|
"lib/t2-server/run.rb",
|
40
43
|
"lib/t2-server/server.rb",
|
41
44
|
"lib/t2-server/util.rb",
|
@@ -43,9 +46,10 @@ Gem::Specification.new do |s|
|
|
43
46
|
"lib/t2-server/xml/nokogiri.rb",
|
44
47
|
"lib/t2-server/xml/rexml.rb",
|
45
48
|
"lib/t2-server/xml/xml.rb",
|
46
|
-
"lib/
|
49
|
+
"lib/t2-server/xml/xpath_cache.rb",
|
47
50
|
"t2-server.gemspec",
|
48
51
|
"test/tc_admin.rb",
|
52
|
+
"test/tc_misc.rb",
|
49
53
|
"test/tc_params.rb",
|
50
54
|
"test/tc_perms.rb",
|
51
55
|
"test/tc_run.rb",
|
@@ -59,6 +63,7 @@ Gem::Specification.new do |s|
|
|
59
63
|
"test/workflows/in.txt",
|
60
64
|
"test/workflows/list_and_value.t2flow",
|
61
65
|
"test/workflows/list_with_errors.t2flow",
|
66
|
+
"test/workflows/missing_outputs.t2flow",
|
62
67
|
"test/workflows/no-ports.t2flow",
|
63
68
|
"test/workflows/pass_through.t2flow",
|
64
69
|
"test/workflows/secure/basic-http.t2flow",
|
@@ -90,8 +95,10 @@ Gem::Specification.new do |s|
|
|
90
95
|
s.add_development_dependency(%q<nokogiri>, [">= 1.5.0"])
|
91
96
|
s.add_development_dependency(%q<rdoc>, [">= 3.9.4"])
|
92
97
|
s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
|
98
|
+
s.add_development_dependency(%q<launchy>, ["~> 2.2.0"])
|
93
99
|
s.add_runtime_dependency(%q<net-http-persistent>, ["~> 2.6"])
|
94
100
|
s.add_runtime_dependency(%q<taverna-baclava>, ["~> 1.0.0"])
|
101
|
+
s.add_runtime_dependency(%q<ratom>, ["~> 0.8.2"])
|
95
102
|
s.add_runtime_dependency(%q<hirb>, [">= 0.4.0"])
|
96
103
|
else
|
97
104
|
s.add_dependency(%q<rake>, ["~> 0.9.2"])
|
@@ -99,8 +106,10 @@ Gem::Specification.new do |s|
|
|
99
106
|
s.add_dependency(%q<nokogiri>, [">= 1.5.0"])
|
100
107
|
s.add_dependency(%q<rdoc>, [">= 3.9.4"])
|
101
108
|
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
109
|
+
s.add_dependency(%q<launchy>, ["~> 2.2.0"])
|
102
110
|
s.add_dependency(%q<net-http-persistent>, ["~> 2.6"])
|
103
111
|
s.add_dependency(%q<taverna-baclava>, ["~> 1.0.0"])
|
112
|
+
s.add_dependency(%q<ratom>, ["~> 0.8.2"])
|
104
113
|
s.add_dependency(%q<hirb>, [">= 0.4.0"])
|
105
114
|
end
|
106
115
|
else
|
@@ -109,8 +118,10 @@ Gem::Specification.new do |s|
|
|
109
118
|
s.add_dependency(%q<nokogiri>, [">= 1.5.0"])
|
110
119
|
s.add_dependency(%q<rdoc>, [">= 3.9.4"])
|
111
120
|
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
121
|
+
s.add_dependency(%q<launchy>, ["~> 2.2.0"])
|
112
122
|
s.add_dependency(%q<net-http-persistent>, ["~> 2.6"])
|
113
123
|
s.add_dependency(%q<taverna-baclava>, ["~> 1.0.0"])
|
124
|
+
s.add_dependency(%q<ratom>, ["~> 0.8.2"])
|
114
125
|
s.add_dependency(%q<hirb>, [">= 0.4.0"])
|
115
126
|
end
|
116
127
|
end
|
data/test/tc_misc.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# Copyright (c) 2013 The University of Manchester, UK.
|
2
|
+
#
|
3
|
+
# All rights reserved.
|
4
|
+
#
|
5
|
+
# Redistribution and use in source and binary forms, with or without
|
6
|
+
# modification, are permitted provided that the following conditions are met:
|
7
|
+
#
|
8
|
+
# * Redistributions of source code must retain the above copyright notice,
|
9
|
+
# this list of conditions and the following disclaimer.
|
10
|
+
#
|
11
|
+
# * Redistributions in binary form must reproduce the above copyright notice,
|
12
|
+
# this list of conditions and the following disclaimer in the documentation
|
13
|
+
# and/or other materials provided with the distribution.
|
14
|
+
#
|
15
|
+
# * Neither the names of The University of Manchester nor the names of its
|
16
|
+
# contributors may be used to endorse or promote products derived from this
|
17
|
+
# software without specific prior written permission.
|
18
|
+
#
|
19
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
20
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
21
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
22
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
23
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
24
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
25
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
26
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
27
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
28
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
29
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
30
|
+
#
|
31
|
+
# Author: Robert Haines
|
32
|
+
|
33
|
+
require 't2-server'
|
34
|
+
|
35
|
+
class TestMisc < Test::Unit::TestCase
|
36
|
+
|
37
|
+
# Test a run with the missing output data bug to check that the library can
|
38
|
+
# workaround it ok. Bug is: http://dev.mygrid.org.uk/issues/browse/T2-2100
|
39
|
+
def test_missing_ports
|
40
|
+
T2Server::Run.create($uri, $wkf_miss_o, $creds, $conn_params) do |run|
|
41
|
+
assert_nothing_raised { run.start }
|
42
|
+
assert(run.running?)
|
43
|
+
run.wait
|
44
|
+
|
45
|
+
run.output_ports.each do |_, port|
|
46
|
+
# Check that outputs are the correct depth
|
47
|
+
assert_equal(port.depth, 2)
|
48
|
+
|
49
|
+
# Check that output lists are the correct length
|
50
|
+
assert_equal(port.value.length, 3)
|
51
|
+
assert_equal(port[0].length, 10)
|
52
|
+
|
53
|
+
# Check that there are empty lists in the correct places
|
54
|
+
assert_equal(port.value[1], [])
|
55
|
+
end
|
56
|
+
|
57
|
+
assert(run.delete)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
data/test/tc_perms.rb
CHANGED
@@ -34,19 +34,27 @@ require 't2-server'
|
|
34
34
|
|
35
35
|
class TestPermissions < Test::Unit::TestCase
|
36
36
|
|
37
|
-
def
|
37
|
+
def test_ownership_and_revokation
|
38
38
|
server = T2Server::Server.new($uri, $conn_params)
|
39
39
|
|
40
40
|
server.create_run($wkf_pass, $creds) do |run|
|
41
41
|
assert(run.owner?)
|
42
42
|
assert_equal(run.owner, $creds.username)
|
43
43
|
|
44
|
+
assert_equal(run.permission($creds1.username), :none)
|
44
45
|
run.grant_permission($creds1.username, :read)
|
46
|
+
assert_equal(run.permission($creds1.username), :read)
|
45
47
|
run_id = run.identifier
|
46
48
|
run1 = server.run(run_id, $creds1)
|
47
49
|
|
48
50
|
assert(!run1.owner?)
|
49
51
|
assert_not_equal(run1.owner, $creds1.username)
|
52
|
+
|
53
|
+
assert(run.revoke_permission($creds1.username))
|
54
|
+
assert_equal(run.permission($creds1.username), :none)
|
55
|
+
assert(run.revoke_permission($creds1.username))
|
56
|
+
|
57
|
+
assert(run.delete)
|
50
58
|
end
|
51
59
|
end
|
52
60
|
|
@@ -81,6 +89,10 @@ class TestPermissions < Test::Unit::TestCase
|
|
81
89
|
assert_raise(T2Server::AccessForbiddenError) do
|
82
90
|
run1.delete
|
83
91
|
end
|
92
|
+
|
93
|
+
assert_nothing_raised(T2Server::AccessForbiddenError) do
|
94
|
+
run.delete
|
95
|
+
end
|
84
96
|
end
|
85
97
|
end
|
86
98
|
|
@@ -106,6 +118,10 @@ class TestPermissions < Test::Unit::TestCase
|
|
106
118
|
assert_raise(T2Server::AccessForbiddenError) do
|
107
119
|
run1.delete
|
108
120
|
end
|
121
|
+
|
122
|
+
assert_nothing_raised(T2Server::AccessForbiddenError) do
|
123
|
+
run.delete
|
124
|
+
end
|
109
125
|
end
|
110
126
|
end
|
111
127
|
|
data/test/tc_run.rb
CHANGED
@@ -32,12 +32,38 @@
|
|
32
32
|
|
33
33
|
require 't2-server'
|
34
34
|
|
35
|
+
# A class to test data streaming.
|
36
|
+
class TestCache
|
37
|
+
attr_reader :data
|
38
|
+
|
39
|
+
def initialize
|
40
|
+
@data = ""
|
41
|
+
end
|
42
|
+
|
43
|
+
def write(data)
|
44
|
+
@data += data
|
45
|
+
data.size
|
46
|
+
end
|
47
|
+
|
48
|
+
def size
|
49
|
+
return @data.size
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
35
53
|
class TestRun < Test::Unit::TestCase
|
36
54
|
|
37
55
|
# Test run connection
|
38
|
-
def
|
56
|
+
def test_run_create_and_delete
|
39
57
|
assert_nothing_raised(T2Server::ConnectionError) do
|
40
|
-
T2Server::Run.create($uri, $wkf_pass, $creds, $conn_params)
|
58
|
+
run = T2Server::Run.create($uri, $wkf_pass, $creds, $conn_params)
|
59
|
+
assert_equal(run.status, :initialized)
|
60
|
+
assert(run.delete)
|
61
|
+
assert(run.deleted?)
|
62
|
+
assert_equal(run.status, :deleted)
|
63
|
+
assert_nothing_raised(T2Server::AttributeNotFoundError) do
|
64
|
+
assert(run.delete) # Should still return true, not raise 404
|
65
|
+
end
|
66
|
+
assert(run.delete) # Should still return true
|
41
67
|
end
|
42
68
|
end
|
43
69
|
|
@@ -71,7 +97,23 @@ class TestRun < Test::Unit::TestCase
|
|
71
97
|
|
72
98
|
# get zip file
|
73
99
|
assert_nothing_raised(T2Server::T2ServerError) do
|
74
|
-
|
100
|
+
zip_out = run.zip_output
|
101
|
+
assert_not_equal(zip_out, "")
|
102
|
+
end
|
103
|
+
|
104
|
+
# test streaming zip data
|
105
|
+
assert_nothing_raised(T2Server::T2ServerError) do
|
106
|
+
zip_cache = TestCache.new
|
107
|
+
run.zip_output(zip_cache)
|
108
|
+
end
|
109
|
+
|
110
|
+
# show getting a zip file of a singleton port does nothing
|
111
|
+
assert_nothing_raised(T2Server::T2ServerError) do
|
112
|
+
assert_nil(run.output_port("OUT").zip)
|
113
|
+
|
114
|
+
zip_cache = TestCache.new
|
115
|
+
run.output_port("OUT").zip(zip_cache)
|
116
|
+
assert_equal(zip_cache.data, "")
|
75
117
|
end
|
76
118
|
|
77
119
|
# deletion
|
@@ -79,14 +121,53 @@ class TestRun < Test::Unit::TestCase
|
|
79
121
|
end
|
80
122
|
end
|
81
123
|
|
82
|
-
# Test run
|
124
|
+
# Test run naming. This is different for different versions of server.
|
125
|
+
def test_run_naming
|
126
|
+
T2Server::Server.new($uri, $conn_params) do |server|
|
127
|
+
vc = server.version_components
|
128
|
+
v250plus = vc[0] > 2 || (vc[0] == 2 && vc[1] >= 5)
|
129
|
+
server.create_run($wkf_no_io, $creds) do |run|
|
130
|
+
if v250plus
|
131
|
+
# Read initial name.
|
132
|
+
assert(run.name.length > 0)
|
133
|
+
assert_equal("Workflow1", run.name[0...9])
|
134
|
+
|
135
|
+
# Set a new name and test.
|
136
|
+
name = "No input or output"
|
137
|
+
assert(run.name = name)
|
138
|
+
assert(run.name.length == 18)
|
139
|
+
assert_equal(name, run.name)
|
140
|
+
|
141
|
+
# Set a name that is too long
|
142
|
+
long_name = "0123456789012345678901234567890123456789ABCDEFGHIJ"
|
143
|
+
assert(run.name = long_name)
|
144
|
+
assert(run.name.length == 48)
|
145
|
+
assert_equal(long_name[0...48], run.name)
|
146
|
+
else
|
147
|
+
# Read initial name.
|
148
|
+
assert(run.name.length == 0)
|
149
|
+
assert_equal("", run.name)
|
150
|
+
|
151
|
+
# "Set" a new name and test.
|
152
|
+
assert(run.name = "test")
|
153
|
+
assert(run.name.length == 0)
|
154
|
+
assert_equal("", run.name)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
# Test run with no input or output. Also, pre-load workflow into a String.
|
83
161
|
def test_run_no_ports
|
84
|
-
|
162
|
+
workflow = File.read($wkf_no_io)
|
163
|
+
|
164
|
+
T2Server::Run.create($uri, workflow, $creds, $conn_params) do |run|
|
85
165
|
assert_nothing_raised { run.input_ports }
|
86
166
|
assert_nothing_raised { run.start }
|
87
167
|
assert(run.running?)
|
88
168
|
run.wait
|
89
169
|
assert_nothing_raised { run.output_ports }
|
170
|
+
assert(run.delete)
|
90
171
|
end
|
91
172
|
end
|
92
173
|
|
@@ -105,6 +186,19 @@ class TestRun < Test::Unit::TestCase
|
|
105
186
|
|
106
187
|
assert_equal(run.output_port("MANY").value, many)
|
107
188
|
assert_equal(run.output_port("SINGLE").value, single_out)
|
189
|
+
|
190
|
+
# get zip file of a single port and test streaming
|
191
|
+
assert_nothing_raised(T2Server::T2ServerError) do
|
192
|
+
zip_out = run.output_port("MANY").zip
|
193
|
+
assert_not_equal(zip_out, "")
|
194
|
+
end
|
195
|
+
|
196
|
+
assert_nothing_raised(T2Server::T2ServerError) do
|
197
|
+
zip_cache = TestCache.new
|
198
|
+
run.output_port("MANY").zip(zip_cache)
|
199
|
+
end
|
200
|
+
|
201
|
+
assert(run.delete)
|
108
202
|
end
|
109
203
|
end
|
110
204
|
|
@@ -122,6 +216,19 @@ class TestRun < Test::Unit::TestCase
|
|
122
216
|
|
123
217
|
assert_equal(run.output_port("list_out").value, list_out)
|
124
218
|
assert_equal(run.output_port("singleton_out").value, "Hello, World!")
|
219
|
+
|
220
|
+
# Get the log file
|
221
|
+
assert_nothing_raised(T2Server::T2ServerError) do
|
222
|
+
assert_not_equal(run.log, "")
|
223
|
+
end
|
224
|
+
|
225
|
+
assert_nothing_raised(T2Server::T2ServerError) do
|
226
|
+
log_cache = TestCache.new
|
227
|
+
run.log(log_cache)
|
228
|
+
assert_not_equal(log_cache.size, 0)
|
229
|
+
end
|
230
|
+
|
231
|
+
assert(run.delete)
|
125
232
|
end
|
126
233
|
end
|
127
234
|
|
@@ -134,11 +241,14 @@ class TestRun < Test::Unit::TestCase
|
|
134
241
|
run.start
|
135
242
|
run.wait
|
136
243
|
assert_equal(run.output_port("nodes").value, ["hello", "world"])
|
244
|
+
assert(run.delete)
|
137
245
|
end
|
138
246
|
end
|
139
247
|
|
248
|
+
# Test run with file input. Also pass workflow as File object.
|
140
249
|
def test_run_file_input
|
141
|
-
|
250
|
+
workflow = File.open($wkf_pass, "r")
|
251
|
+
|
142
252
|
T2Server::Run.create($uri, $wkf_pass, $creds, $conn_params) do |run|
|
143
253
|
|
144
254
|
assert_nothing_raised(T2Server::AttributeNotFoundError) do
|
@@ -149,7 +259,10 @@ class TestRun < Test::Unit::TestCase
|
|
149
259
|
assert(run.running?)
|
150
260
|
assert_nothing_raised(T2Server::RunStateError) { run.wait }
|
151
261
|
assert_equal(run.output_port("OUT").value, "Hello, World!")
|
262
|
+
assert(run.delete)
|
152
263
|
end
|
264
|
+
|
265
|
+
workflow.close
|
153
266
|
end
|
154
267
|
|
155
268
|
# Test run that returns list of lists, some empty, using baclava for input
|
@@ -171,11 +284,14 @@ class TestRun < Test::Unit::TestCase
|
|
171
284
|
assert_nothing_raised(T2Server::RunStateError) { run.wait }
|
172
285
|
assert_equal(run.output_ports.keys.sort, ["MANY", "SINGLE"])
|
173
286
|
assert_equal(run.output_port("SINGLE").value, [])
|
287
|
+
assert(!run.output_port("SINGLE").empty?)
|
174
288
|
assert_equal(run.output_port("MANY").value,
|
175
289
|
[[["boo"]], [["", "Hello"]], [], [[], ["test"], []]])
|
176
290
|
assert_equal(run.output_port("MANY").total_size, 12)
|
291
|
+
assert(run.output_port("MANY")[1][0][0].empty?)
|
177
292
|
assert_equal(run.output_port("MANY")[1][0][1].value(1..3), "ell")
|
178
293
|
assert_raise(NoMethodError) { run.output_port("SINGLE")[0].value }
|
294
|
+
assert(run.delete)
|
179
295
|
end
|
180
296
|
end
|
181
297
|
|
@@ -192,9 +308,18 @@ class TestRun < Test::Unit::TestCase
|
|
192
308
|
assert(run.running?)
|
193
309
|
assert_nothing_raised(T2Server::RunStateError) { run.wait }
|
194
310
|
|
311
|
+
# Test normal and streamed output
|
195
312
|
assert_nothing_raised(T2Server::AccessForbiddenError) do
|
196
313
|
output = run.baclava_output
|
314
|
+
|
315
|
+
out_stream = ""
|
316
|
+
run.baclava_output do |chunk|
|
317
|
+
out_stream += chunk
|
318
|
+
end
|
319
|
+
assert_equal(output, out_stream)
|
197
320
|
end
|
321
|
+
|
322
|
+
assert(run.delete)
|
198
323
|
end
|
199
324
|
end
|
200
325
|
|
@@ -209,44 +334,44 @@ class TestRun < Test::Unit::TestCase
|
|
209
334
|
run.start
|
210
335
|
run.wait
|
211
336
|
|
212
|
-
#
|
337
|
+
# Get total data size (without downloading the data).
|
213
338
|
assert_equal(run.output_port("OUT").total_size, 100)
|
214
339
|
assert_equal(run.output_port("OUT").size, 100)
|
215
340
|
|
216
|
-
#
|
217
|
-
|
341
|
+
# Stream just the first 10 bytes.
|
342
|
+
stream = ""
|
343
|
+
run.output_port("OUT").value(0...10) do |chunk|
|
344
|
+
stream += chunk
|
345
|
+
end
|
346
|
+
assert_equal(stream, "123456789\n")
|
218
347
|
|
219
|
-
#
|
220
|
-
assert_equal(run.output_port("OUT").value(
|
221
|
-
"
|
348
|
+
# Get just the second 10 bytes.
|
349
|
+
assert_equal(run.output_port("OUT").value(10...20),
|
350
|
+
"223456789\n")
|
222
351
|
|
223
|
-
#
|
224
|
-
|
225
|
-
|
352
|
+
# Stream the first 20 bytes.
|
353
|
+
stream = ""
|
354
|
+
run.output_port("OUT").value(0...20) do |chunk|
|
355
|
+
stream += chunk
|
356
|
+
end
|
357
|
+
assert_equal(stream, "123456789\n223456789\n")
|
226
358
|
|
227
|
-
#
|
228
|
-
assert_equal(run.output_port("OUT").value(
|
359
|
+
# Get a bad range - should return the first 10 bytes.
|
360
|
+
assert_equal(run.output_port("OUT").value(-10...10),
|
229
361
|
"123456789\n")
|
230
362
|
|
231
|
-
#
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
assert_equal(
|
237
|
-
"123456789\n223456789\n323456789\n")
|
238
|
-
|
239
|
-
# ask for a range that we already have
|
240
|
-
assert_equal(run.output_port("OUT").value(5..25),
|
241
|
-
"6789\n223456789\n323456")
|
242
|
-
|
243
|
-
# confirm that no more has actually been downloaded
|
244
|
-
assert_equal(run.output_port("OUT").value(:debug),
|
245
|
-
"123456789\n223456789\n323456789\n")
|
363
|
+
# Stream the lot and check total length. There should be two chunks.
|
364
|
+
stream = ""
|
365
|
+
run.output_port("OUT").value do |chunk|
|
366
|
+
stream += chunk
|
367
|
+
end
|
368
|
+
assert_equal(stream.length, 100)
|
246
369
|
|
247
|
-
#
|
370
|
+
# Now get the lot and check its size.
|
248
371
|
out = run.output_port("OUT").value
|
249
372
|
assert_equal(out.length, 100)
|
373
|
+
|
374
|
+
assert(run.delete)
|
250
375
|
end
|
251
376
|
end
|
252
377
|
|
@@ -255,16 +380,21 @@ class TestRun < Test::Unit::TestCase
|
|
255
380
|
T2Server::Run.create($uri, $wkf_fail, $creds, $conn_params) do |run|
|
256
381
|
run.start
|
257
382
|
run.wait
|
258
|
-
|
383
|
+
assert_not_nil(run.output_port("OUT").value)
|
259
384
|
assert(run.output_port("OUT").error?)
|
385
|
+
assert(run.delete)
|
260
386
|
end
|
261
387
|
end
|
262
388
|
|
263
389
|
def test_errors
|
264
390
|
T2Server::Run.create($uri, $wkf_errors, $creds, $conn_params) do |run|
|
265
391
|
run.start
|
392
|
+
assert(!run.error?)
|
266
393
|
run.wait
|
394
|
+
assert_not_nil(run.output_port("OUT").value)
|
267
395
|
assert(run.output_port("OUT").error?)
|
396
|
+
assert(run.error?)
|
397
|
+
assert(run.delete)
|
268
398
|
end
|
269
399
|
end
|
270
400
|
end
|