An interface for easily running jobs on a Taverna 2 Server with minimal setup and configuration required.
A run can be in one of three states:
:initialized - The run has been accepted by the server. It may not yet be ready to run though as its input port may not have been set.
:running - The run is being run by the server.
:finished - The run has finished running and its outputs are available for download.
The identifier of this run on the server.
The identifier of this run on the server.
The server instance that this run is hosted on.
Create a new run in the :initialized state. The run will be created on the
server with address supplied by server. This can either be a
String of the form http://example.com:8888/blah
or an already
created instance of T2Server::Server. The
workflow must also be supplied as a string in t2flow or scufl
format. User credentials and connection parameters can be supplied if
required but are both optional. If server is an instance of T2Server::Server then connection_parameters
will be ignored.
This method will yield the newly created Run if a block is given.
# File lib/t2-server/run.rb, line 140 def Run.create(server, workflow, *rest) credentials = nil id = nil conn_params = nil rest.each do |param| case param when String id = param when ConnectionParameters conn_params = param when HttpCredentials credentials = param end end if server.class != Server server = Server.new(server, conn_params) end if id.nil? id = server.initialize_run(workflow, credentials) end run = new(server, id, credentials) yield(run) if block_given? run end
Provide a client certificate credential for the secure service at the
specified URI. You will need to provide the password to unlock the private
key. You will also need to provide the ‘alias’ or ‘friendlyName’ of the key
you wish to use if it differs from the default. The id of the credential on
the server is returned. Only the owner of a run may supply credentials for
it. nil
is returned if a user other than the owner uses this
method.
# File lib/t2-server/run.rb, line 734 def add_keypair_credential(uri, filename, password, name = "Imported Certificate", type = :pkcs12) return unless owner? type = type.to_s.upcase contents = Base64.encode64(IO.read(filename)) # basic uri checks uri = _check_cred_uri(uri) cred = XML::Fragments::KEYPAIR_CRED % [uri, name, contents, type, password] value = XML::Fragments::CREDENTIAL % cred @server.create_run_attribute(@identifier, links[:sec_creds], value, "application/xml", @credentials) end
Provide a username and password credential for the secure service at the
specified URI. The id of the credential on the server is returned. Only the
owner of a run may supply credentials for it. nil
is returned
if a user other than the owner uses this method.
# File lib/t2-server/run.rb, line 701 def add_password_credential(uri, username, password) return unless owner? # Is this a new credential, or an update? id = credential(uri) # basic uri checks uri = _check_cred_uri(uri) cred = XML::Fragments::USERPASS_CRED % [uri, username, password] value = XML::Fragments::CREDENTIAL % cred if id.nil? @server.create_run_attribute(@identifier, links[:sec_creds], value, "application/xml", @credentials) else path = "#{links[:sec_creds]}/#{id}" @server.set_run_attribute(@identifier, path, value, "application/xml", @credentials) end end
Add a trusted identity (server public key) to verify peers when using https
connections to Web Services. The id of the trust on the server is returned.
Only the owner of a run may add a trust. nil
is returned if a
user other than the owner uses this method.
# File lib/t2-server/run.rb, line 819 def add_trust(filename, type = :x509) return unless owner? type = type.to_s.upcase contents = Base64.encode64(IO.read(filename)) value = XML::Fragments::TRUST % [contents, type] @server.create_run_attribute(@identifier, links[:sec_trusts], value, "application/xml", @credentials) end
Use a baclava file for the workflow inputs.
# File lib/t2-server/run.rb, line 468 def baclava_input=(filename) state = status raise RunStateError.new(state, :initialized) if state != :initialized rename = upload_file(filename) result = @server.set_run_attribute(@identifier, links[:baclava], rename, "text/plain", @credentials) @baclava_in = true if result result end
Have the inputs to this run been set by a baclava document?
# File lib/t2-server/run.rb, line 521 def baclava_input? @baclava_in end
Get the outputs of this run in baclava format. This can only be done if the output has been requested in baclava format by set_baclava_output before starting the run.
# File lib/t2-server/run.rb, line 539 def baclava_output state = status raise RunStateError.new(state, :finished) if state != :finished raise AccessForbiddenError.new("baclava output") if !@baclava_out @server.get_run_attribute(@identifier, "#{links[:wdir]}/#{BACLAVA_FILE}", "*/*", @credentials) end
Has this run been set to return results in baclava format?
# File lib/t2-server/run.rb, line 529 def baclava_output? @baclava_out end
Get the creation time of this run as an instance of class Time.
# File lib/t2-server/run.rb, line 597 def create_time Time.parse(@server.get_run_attribute(@identifier, links[:createtime], "text/plain", @credentials)) end
Return the identifier of the credential set for the supplied service, if
any. Only the owner of a run may query its credentials. nil
is
returned if a user other than the owner uses this method.
# File lib/t2-server/run.rb, line 780 def credential(uri) return unless owner? credentials[uri] end
Return a hash (service_uri => identifier) of all the credentials
provided for this run. Only the owner of a run may query its credentials.
nil
is returned if a user other than the owner uses this
method.
# File lib/t2-server/run.rb, line 758 def credentials return unless owner? creds = {} doc = xml_document(@server.get_run_attribute(@identifier, links[:sec_creds], "application/xml", @credentials)) xpath_find(doc, XPaths[:sec_cred]).each do |c| uri = xml_node_content(xpath_first(c, XPaths[:sec_suri])) id = xml_node_attribute(c, "href").split('/')[-1] creds[uri] = id end creds end
Delete this run from the server.
# File lib/t2-server/run.rb, line 192 def delete @server.delete_run(@identifier, @credentials) end
Delete all credentials associated with this workflow run. Only the owner of
a run may delete its credentials. nil
is returned if a user
other than the owner uses this method.
# File lib/t2-server/run.rb, line 805 def delete_all_credentials return unless owner? @server.delete_run_attribute(@identifier, links[:sec_creds], @credentials) end
Delete all trusted identities associated with this workflow run. Only the
owner of a run may delete its trusts. nil
is returned if a
user other than the owner uses this method.
# File lib/t2-server/run.rb, line 872 def delete_all_trusts return unless owner? @server.delete_run_attribute(@identifier, links[:sec_trusts], @credentials) end
Delete the credential that has been provided for the specified service.
Only the owner of a run may delete its credentials. nil
is
returned if a user other than the owner uses this method.
# File lib/t2-server/run.rb, line 792 def delete_credential(uri) return unless owner? path = "#{links[:sec_creds]}/#{credentials[uri]}" @server.delete_run_attribute(@identifier, path, @credentials) end
Delete the trust with the provided id. Only the owner of a run may delete
its trusts. nil
is returned if a user other than the owner
uses this method.
# File lib/t2-server/run.rb, line 859 def delete_trust(id) return unless owner? path = "#{links[:sec_trusts]}/#{id}" @server.delete_run_attribute(@identifier, path, @credentials) end
Get the return code of the run. Zero indicates success.
# File lib/t2-server/run.rb, line 381 def exitcode @server.get_run_attribute(@identifier, links[:exitcode], "text/plain", @credentials).to_i end
Return the expiry time of this run as an instance of class Time.
# File lib/t2-server/run.rb, line 284 def expiry Time.parse(@server.get_run_attribute(@identifier, links[:expiry], "text/plain", @credentials)) end
Set the expiry time of this run to time. time should either be a Time object or something that the Time class can parse. If the value given does not specify a date then today’s date will be assumed. If a time/date in the past is specified, the expiry time will not be changed.
# File lib/t2-server/run.rb, line 296 def expiry=(time) unless time.instance_of? Time time = Time.parse(time) end # need to massage the xmlschema format slightly as the server cannot # parse timezone offsets with a colon (eg +00:00) date_str = time.xmlschema(2) date_str = date_str[0..-4] + date_str[-2..-1] @server.set_run_attribute(@identifier, links[:expiry], date_str, "text/plain", @credentials) end
Get the finish time of this run as an instance of class Time.
# File lib/t2-server/run.rb, line 615 def finish_time Time.parse(@server.get_run_attribute(@identifier, links[:finishtime], "text/plain", @credentials)) end
Is this run in the :finished state?
# File lib/t2-server/run.rb, line 589 def finished? status == :finished end
Grant the user the stated permission. A permission can be one of
:none
, :read
, :update
or
:destroy
. Only the owner of a run may grant permissions on it.
nil
is returned if a user other than the owner uses this
method.
# File lib/t2-server/run.rb, line 639 def grant_permission(username, permission) return unless owner? value = XML::Fragments::PERM_UPDATE % [username, permission.to_s] @server.create_run_attribute(@identifier, links[:sec_perms], value, "application/xml", @credentials) end
Is this run in the :initialized state?
# File lib/t2-server/run.rb, line 573 def initialized? status == :initialized end
Get port.
# File lib/t2-server/run.rb, line 234 def input_port(port) input_ports[port] end
Return a hash (name, port) of all the input ports this run expects.
# File lib/t2-server/run.rb, line 224 def input_ports @input_ports = _get_input_port_info if @input_ports.nil? @input_ports end
Create a directory in the run’s working directory on the server. This could be used to store input data.
# File lib/t2-server/run.rb, line 409 def mkdir(dir) dir = Util.strip_path_slashes(dir) if dir.include? // # if a path is given then separate the leaf from the # end and add the rest of the path to the wdir link leaf = dir.split("/")[-1] path = dir[0...-(leaf.length + 1)] @server.create_dir(@identifier, "#{links[:wdir]}/#{path}", leaf, @credentials) else @server.create_dir(@identifier, links[:wdir], dir, @credentials) end end
Get output port port.
# File lib/t2-server/run.rb, line 255 def output_port(port) output_ports[port] if finished? end
Return a hash (name, port) of all the output ports this run has. Until the run is finished this method will return nil.
# File lib/t2-server/run.rb, line 243 def output_ports if finished? and @output_ports.nil? @output_ports = _get_output_port_info end @output_ports end
Get the username of the owner of this run. The owner is the user who created the run on the server.
# File lib/t2-server/run.rb, line 182 def owner @owner = _get_run_owner if @owner.nil? @owner end
Are the credentials being used to access this run those of the owner? The owner of the run can give other users certain access rights to their runs but only the owner can change these rights - or even see what they are. Sometimes it is useful to know if the user accessing the run is actually the owner of it or not.
# File lib/t2-server/run.rb, line 628 def owner? @credentials.username == owner end
Return the permission granted to the supplied username, if any. Only the
owner of a run may query its permissions. nil
is returned if a
user other than the owner uses this method.
# File lib/t2-server/run.rb, line 675 def permission(username) return unless owner? permissions[username] end
Return a hash (username => permission) of all the permissions set for
this run. Only the owner of a run may query its permissions.
nil
is returned if a user other than the owner uses this
method.
# File lib/t2-server/run.rb, line 653 def permissions return unless owner? perms = {} doc = xml_document(@server.get_run_attribute(@identifier, links[:sec_perms], "application/xml", @credentials)) xpath_find(doc, XPaths[:sec_perm]).each do |p| user = xml_node_content(xpath_first(p, XPaths[:sec_uname])) perm = xml_node_content(xpath_first(p, XPaths[:sec_uperm])).to_sym perms[user] = perm end perms end
Set the server to save the outputs of this run in baclava format. This must be done before the run is started.
# File lib/t2-server/run.rb, line 500 def request_baclava_output return if @baclava_out state = status raise RunStateError.new(state, :initialized) if state != :initialized @baclava_out = @server.set_run_attribute(@identifier, links[:output], BACLAVA_FILE, "text/plain", @credentials) end
Revoke whatever permissions that have been granted to the user. Only the
owner of a run may revoke permissions on it. nil
is returned
if a user other than the owner uses this method.
# File lib/t2-server/run.rb, line 687 def revoke_permission(username) return unless owner? path = "#{links[:sec_perms]}/#{username}" @server.delete_run_attribute(@identifier, path, @credentials) end
Is this run in the :running state?
# File lib/t2-server/run.rb, line 581 def running? status == :running end
Start this run on the server.
Raises RunStateError if the run is not in the :initialized state.
# File lib/t2-server/run.rb, line 337 def start state = status raise RunStateError.new(state, :initialized) if state != :initialized # set all the inputs _check_and_set_inputs unless baclava_input? @server.set_run_attribute(@identifier, links[:status], state_to_text(:running), "text/plain", @credentials) end
Get the start time of this run as an instance of class Time.
# File lib/t2-server/run.rb, line 606 def start_time Time.parse(@server.get_run_attribute(@identifier, links[:starttime], "text/plain", @credentials)) end
Get the status of this run. Status can be one of :initialized, :running or :finished.
# File lib/t2-server/run.rb, line 326 def status text_to_state(@server.get_run_attribute(@identifier, links[:status], "text/plain", @credentials)) end
Get anything that the run printed to the standard error stream.
# File lib/t2-server/run.rb, line 399 def stderr @server.get_run_attribute(@identifier, links[:stderr], "text/plain", @credentials) end
Get anything that the run printed to the standard out stream.
# File lib/t2-server/run.rb, line 390 def stdout @server.get_run_attribute(@identifier, links[:stdout], "text/plain", @credentials) end
Return a list of all the ids of trusts that have been registered for this
run. At present there is no way to differentiate between trusts without
noting the id returned when originally uploaded. Only the owner of a run
may query its trusts. nil
is returned if a user other than the
owner uses this method.
# File lib/t2-server/run.rb, line 839 def trusts return unless owner? t_ids = [] doc = xml_document(@server.get_run_attribute(@identifier, links[:sec_trusts], "application/xml", @credentials)) xpath_find(doc, XPaths[:sec_trust]). each do |t| t_ids << xml_node_attribute(t, "href").split('/')[-1] end t_ids end
Upload data to the server and store it in remote_file
. The
remote directory to put this file in can also be specified, but if it is it
must first have been created by a call to #mkdir.
# File lib/t2-server/run.rb, line 447 def upload_data(data, remote_name, remote_directory = "") location = "#{links[:wdir]}/#{remote_directory}" @server.upload_data(@identifier, data, remote_name, location, @credentials) end
Upload a file, with name filename, to the server. Possible values that can be passed in via params are:
:dir - The directory to upload to. If this is not left blank the corresponding directory will need to have been created by #mkdir.
:rename - Save the file on the server with a different name.
The name of the file on the server is returned.
# File lib/t2-server/run.rb, line 433 def upload_file(filename, params={}) location = params[:dir] || "" location = "#{links[:wdir]}/#{location}" rename = params[:rename] || "" @server.upload_file(@identifier, filename, location, rename, @credentials) end
Wait (block) for this run to finish. How often (in seconds) the run is tested for completion can be specified with check_interval.
Raises RunStateError if the run is still in the :initialised state.
# File lib/t2-server/run.rb, line 355 def wait(*params) state = status raise RunStateError.new(state, :running) if state == :initialized interval = 1 params.each do |param| case param when Hash warn "[DEPRECATION] 'Run#wait(params={})' is deprecated and will " + "be removed in 1.0. Please use Run#wait(check_interval) instead." interval = param[:interval] || 1 when Integer interval = param end end # wait until finished? sleep(interval) end end
Get the workflow that this run represents.
# File lib/t2-server/run.rb, line 313 def workflow if @workflow == "" @workflow = @server.get_run_attribute(@identifier, links[:workflow], "application/xml", @credentials) end @workflow end
Get the working directory of this run directly from the server in zip format.
# File lib/t2-server/run.rb, line 561 def zip_output state = status raise RunStateError.new(state, :finished) if state != :finished @server.get_run_attribute(@identifier, "#{links[:wdir]}/out", "application/zip", @credentials) end