Skip to content

Commit

Permalink
Fake list inputs with baclava.
Browse files Browse the repository at this point in the history
If a workflow has any ports of depth > 0 then the inputs are converted to
baclava format and uploaded as a single document. This includes local files but
remote files can not be handled this way.

Tests have been updated to include checks for mixed input depth workflows.
  • Loading branch information
hainesr committed Mar 13, 2012
1 parent 758f430 commit 8b21c53
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 1 deletion.
1 change: 1 addition & 0 deletions Rakefile
Expand Up @@ -67,6 +67,7 @@ spec = Gem::Specification.new do |s|
s.add_development_dependency('libxml-ruby', '>= 1.1.4')
s.add_development_dependency('nokogiri', '>= 1.5.0')
s.add_development_dependency('rdoc', '>= 3.9.4')
s.add_runtime_dependency('taverna-baclava', '~> 1.0.0')
s.add_runtime_dependency('hirb', '>= 0.4.0')
end

Expand Down
45 changes: 44 additions & 1 deletion lib/t2-server/run.rb
Expand Up @@ -32,6 +32,8 @@

require 'base64'
require 'time'
require 'rubygems'
require 'taverna-baclava'

module T2Server

Expand Down Expand Up @@ -328,7 +330,7 @@ def start
raise RunStateError.new(state, :initialized) if state != :initialized

# set all the inputs
_set_all_inputs unless baclava_input?
_check_and_set_inputs unless baclava_input?

@server.set_run_attribute(@identifier, @links[:status],
state_to_text(:running), "text/plain", @credentials)
Expand Down Expand Up @@ -877,6 +879,20 @@ def download_output_data(path, range = nil)

private

# Check each input to see if it requires a list input and call the
# requisite upload method for the entire set of inputs.
def _check_and_set_inputs
lists = false
input_ports.each_value do |port|
if port.depth > 0
lists = true
break
end
end

lists ? _fake_lists : _set_all_inputs
end

# Set all the inputs on the server. The inputs must have been set prior to
# this call using the InputPort API.
def _set_all_inputs
Expand Down Expand Up @@ -906,6 +922,33 @@ def _set_all_inputs
end
end

# Fake being able to handle lists as inputs by converting everything into
# one big baclava document and uploading that. This has to be done for all
# inputs or none at all. The inputs must have been set prior to this call
# using the InputPort API.
def _fake_lists
data_map = {}

input_ports.each_value do |port|
next unless port.set?

if port.file?
unless port.remote_file?
file = File.read(port.file)
data_map[port.name] = Taverna::Baclava::Node.new(file)
end
else
data_map[port.name] = Taverna::Baclava::Node.new(port.value)
end
end

# Create and upload the baclava data.
baclava = Taverna::Baclava::Writer.write(data_map)
upload_data(baclava, "in.baclava")
@server.set_run_attribute(@identifier, @links[:baclava], "in.baclava",
"text/plain", @credentials)
end

# Check that the uri passed in is suitable for credential use:
# * rserve uris must not have a path.
# * http(s) uris must have at least "/" as their path.
Expand Down
35 changes: 35 additions & 0 deletions test/tc_run.rb
Expand Up @@ -79,6 +79,41 @@ def test_status_codes
end
end

# Test run with list inputs
def test_run_list_input
T2Server::Run.create($uri, $wkf_lists, $creds, $conn_params) do |run|
many = [[["boo"]], [["", "Hello"]], [], [[], ["test"], []]]
single = [1, 2, 3, 4, 5]
single_out = single.map { |v| v.to_s } # Taverna outputs strings!

run.input_port("SINGLE_IN").value = single
run.input_port("MANY_IN").value = many
assert_nothing_raised { run.start }
assert(run.running?)
run.wait

assert_equal(run.output_port("MANY").value, many)
assert_equal(run.output_port("SINGLE").value, single_out)
end
end

# Test run with a list and file input
def test_run_list_and_file
T2Server::Run.create($uri, $wkf_l_v, $creds, $conn_params) do |run|
list = ["one", 2, :three]
list_out = list.map { |v| v.to_s }

run.input_port("list_in").value = list
run.input_port("singleton_in").file = $file_input
assert_nothing_raised { run.start }
assert(run.running?)
run.wait

assert_equal(run.output_port("list_out").value, list_out)
assert_equal(run.output_port("singleton_out").value, "Hello, World!")
end
end

# Test run with xml input
def test_run_xml_input
T2Server::Run.create($uri, $wkf_xml, $creds, $conn_params) do |run|
Expand Down
1 change: 1 addition & 0 deletions test/ts_t2server.rb
Expand Up @@ -77,6 +77,7 @@

$wkf_pass = File.read("test/workflows/pass_through.t2flow")
$wkf_lists = File.read("test/workflows/empty_list.t2flow")
$wkf_l_v = File.read("test/workflows/list_and_value.t2flow")
$wkf_xml = File.read("test/workflows/xml_xpath.t2flow")
$wkf_fail = File.read("test/workflows/always_fail.t2flow")
$wkf_errors = File.read("test/workflows/list_with_errors.t2flow")
Expand Down
12 changes: 12 additions & 0 deletions test/workflows/list_and_value.t2flow
@@ -0,0 +1,12 @@
<workflow xmlns="http://taverna.sf.net/2008/xml/t2flow" version="1" producedBy="taverna-2.3.0"><dataflow id="2d5f4961-acc0-43c4-989d-c0249e9695a6" role="top"><name>Workflow3</name><inputPorts><port><name>singleton_in</name><depth>0</depth><granularDepth>0</granularDepth><annotations /></port><port><name>list_in</name><depth>1</depth><granularDepth>1</granularDepth><annotations /></port></inputPorts><outputPorts><port><name>list_out</name><annotations /></port><port><name>singleton_out</name><annotations /></port></outputPorts><processors /><conditions /><datalinks><datalink><sink type="dataflow"><port>list_out</port></sink><source type="dataflow"><port>list_in</port></source></datalink><datalink><sink type="dataflow"><port>singleton_out</port></sink><source type="dataflow"><port>singleton_in</port></source></datalink></datalinks><annotations><annotation_chain_2_2 encoding="xstream"><net.sf.taverna.t2.annotation.AnnotationChainImpl xmlns="">
<annotationAssertions>
<net.sf.taverna.t2.annotation.AnnotationAssertionImpl>
<annotationBean class="net.sf.taverna.t2.annotation.annotationbeans.IdentificationAssertion">
<identification>2d5f4961-acc0-43c4-989d-c0249e9695a6</identification>
</annotationBean>
<date>2012-03-13 17:05:40.688 GMT</date>
<creators />
<curationEventList />
</net.sf.taverna.t2.annotation.AnnotationAssertionImpl>
</annotationAssertions>
</net.sf.taverna.t2.annotation.AnnotationChainImpl></annotation_chain_2_2></annotations></dataflow></workflow>

0 comments on commit 8b21c53

Please sign in to comment.