Class: T2Server::Run
- Inherits:
-
Object
- Object
- T2Server::Run
- Includes:
- XML::Methods
- Defined in:
- lib/t2-server/run.rb
Overview
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.
Defined Under Namespace
Classes: Status
Constant Summary collapse
- XPATHS =
:stopdoc:
{ # Run XPath queries :run_desc => "/nsr:runDescription", :dir => "//nss:dir", :file => "//nss:file", :expiry => "//nsr:expiry", :workflow => "//nsr:creationWorkflow", :status => "//nsr:status", :createtime => "//nsr:createTime", :starttime => "//nsr:startTime", :finishtime => "//nsr:finishTime", :wdir => "//nsr:workingDirectory", :inputs => "//nsr:inputs", :output => "//nsr:output", :securectx => "//nsr:securityContext", :listeners => "//nsr:listeners", :baclava => "//nsr:baclava", :inputexp => "//nsr:expected", :name => "//nsr:name", :feed => "//nsr:interaction", :gen_prov => "//nsr:generate-provenance", :run_bundle => "//nsr:run-bundle", # Port descriptions XPath queries :port_in => "//port:input", :port_out => "//port:output", # Run security XPath queries :sec_creds => "//nsr:credentials", :sec_perms => "//nsr:permissions", :sec_trusts => "//nsr:trusts", :sec_perm => "/nsr:permissionsDescriptor/nsr:permission", :sec_uname => "nsr:userName", :sec_uperm => "nsr:permission", :sec_cred => "/nsr:credential", :sec_suri => "nss:serviceURI", :sec_trust => "/nsr:trustedIdentities/nsr:trust" }
- BACLAVA_FILE =
The name to be used internally for retrieving results via baclava
"out.xml"
- @@xpaths =
XML::XPathCache.instance
Instance Attribute Summary collapse
-
#identifier ⇒ Object
(also: #id)
readonly
The identifier of this run on the server.
-
#server ⇒ Object
readonly
The server instance that this run is hosted on.
Class Method Summary collapse
-
.create(server, workflow, *rest) {|run| ... } ⇒ Object
:call-seq: Run.create(server, workflow) -> run Run.create(server, workflow, connection_parameters) -> run Run.create(server, workflow, user_credentials) -> run Run.create(server, workflow, …) {|run| …}.
Instance Method Summary collapse
-
#add_keypair_credential(uri, filename, password, name = "Imported Certificate", type = :pkcs12) ⇒ Object
:call-seq: add_keypair_credential(service_uri, filename, password, alias = “Imported Certificate”, type = :pkcs12) -> URI.
-
#add_password_credential(uri, username, password) ⇒ Object
:call-seq: add_password_credential(service_uri, username, password) -> URI.
-
#add_trust(filename, type = :x509) ⇒ Object
:call-seq: add_trust(filename, type = :x509) -> URI.
-
#baclava_input=(filename) ⇒ Object
:call-seq: baclava_input = filename -> true or false.
-
#baclava_input? ⇒ Boolean
:call-seq: baclava_input? -> true or false.
-
#baclava_output(param = nil, &block) ⇒ Object
:call-seq: baclava_output -> string baclava_output(filename) -> fixnum baclava_output(stream) -> fixnum baclava_output {|chunk| …}.
-
#baclava_output? ⇒ Boolean
:stopdoc:.
-
#create_time ⇒ Object
:call-seq: create_time -> string.
-
#credential(uri) ⇒ Object
:call-seq: credential(service_uri) -> URI.
-
#credentials ⇒ Object
:call-seq: credentials -> hash.
-
#delete ⇒ Object
:call-seq: delete.
-
#delete_all_credentials ⇒ Object
:call-seq: delete_all_credentials -> true or false.
-
#delete_all_trusts ⇒ Object
:call-seq: delete_all_trusts -> true or false.
-
#delete_credential(uri) ⇒ Object
:call-seq: delete_credential(service_uri) -> true or false.
-
#delete_trust(uri) ⇒ Object
:call-seq: delete_trust(URI) -> true or false.
-
#deleted? ⇒ Boolean
:call-seq: deleted? -> true or false.
-
#download_output_data(uri, range = nil, &block) ⇒ Object
:stopdoc: Outputs are represented as a directory structure with the eventual list items (leaves) as files.
-
#error? ⇒ Boolean
:call-seq: error? -> true or false.
-
#exitcode ⇒ Object
:call-seq: exitcode -> fixnum.
-
#expiry ⇒ Object
:call-seq: expiry -> string.
-
#expiry=(time) ⇒ Object
:call-seq: expiry = time -> true or false.
-
#finish_time ⇒ Object
:call-seq: finish_time -> string.
-
#finished? ⇒ Boolean
:call-seq: finished? -> true or false.
-
#generate_baclava_output ⇒ Object
:call-seq: generate_baclava_output -> true or false.
-
#generate_baclava_output? ⇒ Boolean
:call-seq: generate_baclava_output? -> true or false.
-
#generate_provenance(toggle = true) ⇒ Object
:call-seq: generate_provenance(toggle = true) -> true or false.
-
#generate_provenance? ⇒ Boolean
:call-seq: generate_provenance? -> true or false.
-
#grant_permission(username, permission) ⇒ Object
:call-seq: grant_permission(username, permission) -> username.
-
#initialize(server, uri, credentials = nil) ⇒ Run
constructor
New is private but rdoc does not get it right! Hence :stopdoc: section.
-
#initialized? ⇒ Boolean
:call-seq: initialized? -> true or false.
-
#input_port(port) ⇒ Object
:call-seq: input_port(port) -> port.
-
#input_ports ⇒ Object
:call-seq: input_ports -> hash.
-
#interactions_uri ⇒ Object
This is a slightly unpleasant hack to help proxy interaction communications through a third party.
-
#log(param = nil, &block) ⇒ Object
:call-seq: log -> string log(filename) -> fixnum log(stream) -> fixnum log {|chunk| …}.
-
#mkdir(dir) ⇒ Object
:call-seq: mkdir(dir) -> true or false.
-
#name ⇒ Object
:call-seq: name -> String.
-
#name=(name) ⇒ Object
:call-seq: name = new_name -> bool.
-
#notifications(type = :new_requests) ⇒ Object
:call-seq: notifications(type = :new_requests) -> array.
-
#notifications_uri ⇒ Object
This is a slightly unpleasant hack to help proxy notification communications through a third party.
-
#output_port(port) ⇒ Object
:call-seq: output_port(port) -> port.
-
#output_ports ⇒ Object
:call-seq: output_ports -> hash.
-
#owner ⇒ Object
:call-seq: owner -> string.
-
#owner? ⇒ Boolean
:call-seq: owner? -> true or false.
-
#permission(username) ⇒ Object
:call-seq: permission(username) -> permission.
-
#permissions ⇒ Object
:call-seq: permissions -> hash.
-
#provenance(param = nil, &block) ⇒ Object
:call-seq: provenance -> binary blob provenance(filename) -> fixnum provenance(stream) -> fixnum provenance {|chunk| …}.
-
#read_interaction_data(name) ⇒ Object
Read a file from the interactions directory for this run on the server.
-
#read_notification_feed ⇒ Object
Read from the run’s notification feed.
-
#request_baclava_output ⇒ Object
:stopdoc:.
-
#revoke_permission(username) ⇒ Object
:call-seq: revoke_permission(username) -> true or false.
-
#running? ⇒ Boolean
:call-seq: running? -> true or false.
-
#start ⇒ Object
:call-seq: start -> true or false.
-
#start_time ⇒ Object
:call-seq: start_time -> string.
-
#status ⇒ Object
:call-seq: status -> string.
-
#stderr ⇒ Object
:call-seq: stderr -> string.
-
#stdout ⇒ Object
:call-seq: stdout -> string.
-
#trusts ⇒ Object
:call-seq: trusts -> array.
-
#upload_data(data, remote_name, remote_directory = "") ⇒ Object
:call-seq: upload_data(data, remote_name, remote_directory = “”) -> true or false.
-
#upload_file(filename, params = {}) ⇒ Object
:call-seq: upload_file(filename, params={}) -> string.
-
#wait(interval = 1) ⇒ Object
:call-seq: wait(check_interval = 1).
-
#workflow ⇒ Object
:call-seq: workflow -> string.
-
#write_interaction_data(name, data) ⇒ Object
Write a file to the interactions directory for this run on the server.
-
#write_notification(entry) ⇒ Object
Write to the run’s notification feed.
-
#zip_output(param = nil, port = "", &block) ⇒ Object
:call-seq: zip_output -> binary blob zip_output(filename) -> fixnum zip_output(stream) -> fixnum zip_output {|chunk| …}.
Methods included from XML::Methods
#get_uris_from_doc, #xml_children, #xml_document, #xml_first_child, #xml_node_attribute, #xml_node_content, #xml_node_name, #xml_text_node, #xpath_attr, #xpath_compile, #xpath_find, #xpath_first
Constructor Details
#initialize(server, uri, credentials = nil) ⇒ Run
New is private but rdoc does not get it right! Hence :stopdoc: section.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/t2-server/run.rb', line 107 def initialize(server, uri, credentials = nil) @server = server @uri = uri @identifier = Util.get_path_leaf_from_uri(@uri) @workflow = "" @baclava_in = false @baclava_out = false @provenance = false @credentials = credentials # Has this Run object been deleted from the server? @deleted = false # The following three fields hold cached data about the run that is only # downloaded the first time it is requested. @run_doc = nil @owner = nil @links = nil # initialize ports lists to nil as an empty list means no inputs/outputs @input_ports = nil @output_ports = nil # The interaction reader to use for this run, if required. @interaction_reader = nil end |
Instance Attribute Details
#identifier ⇒ Object (readonly) Also known as: id
The identifier of this run on the server.
54 55 56 |
# File 'lib/t2-server/run.rb', line 54 def identifier @identifier end |
#server ⇒ Object (readonly)
The server instance that this run is hosted on.
58 59 60 |
# File 'lib/t2-server/run.rb', line 58 def server @server end |
Class Method Details
.create(server, workflow, *rest) {|run| ... } ⇒ Object
:call-seq:
Run.create(server, workflow) -> run
Run.create(server, workflow, connection_parameters) -> run
Run.create(server, workflow, user_credentials) -> run
Run.create(server, workflow, ...) {|run| ...}
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 may be supplied as a string in t2flow format, a filename or a File or IO object. 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.
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/t2-server/run.rb', line 152 def Run.create(server, workflow, *rest) credentials = nil uri = nil conn_params = nil rest.each do |param| case param when URI uri = param when ConnectionParameters conn_params = param when HttpCredentials credentials = param end end # If server is not a Server object, get one. server = Server.new(server, conn_params) if server.class != Server # If we are not given a URI to a run then we know we need to create one. uri ||= server.initialize_run(workflow, credentials) # Create the run object and yield it if necessary. run = new(server, uri, credentials) yield(run) if block_given? run end |
Instance Method Details
#add_keypair_credential(uri, filename, password, name = "Imported Certificate", type = :pkcs12) ⇒ Object
:call-seq:
add_keypair_credential(service_uri, filename, password,
alias = "Imported Certificate", type = :pkcs12) -> URI
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 URI 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.
822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 |
# File 'lib/t2-server/run.rb', line 822 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(links[:sec_creds], value, "application/xml", @credentials) end |
#add_password_credential(uri, username, password) ⇒ Object
:call-seq:
add_password_credential(service_uri, username, password) -> URI
Provide a username and password credential for the secure service at the specified URI. The URI 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.
791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 |
# File 'lib/t2-server/run.rb', line 791 def add_password_credential(uri, username, password) return unless owner? # Is this a new credential, or an update? cred_uri = credential(uri) # basic uri checks uri = _check_cred_uri(uri) cred = XML::Fragments::USERPASS_CRED % [uri, username, password] value = XML::Fragments::CREDENTIAL % cred if cred_uri.nil? @server.create(links[:sec_creds], value, "application/xml", @credentials) else @server.update(cred_uri, value, "application/xml", @credentials) end end |
#add_trust(filename, type = :x509) ⇒ Object
:call-seq:
add_trust(filename, type = :x509) -> URI
Add a trusted identity (server public key) to verify peers when using https connections to Web Services. The URI 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.
904 905 906 907 908 909 910 911 912 913 |
# File 'lib/t2-server/run.rb', line 904 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(links[:sec_trusts], value, "application/xml", @credentials) end |
#baclava_input=(filename) ⇒ Object
:call-seq:
baclava_input = filename -> true or false
Use a baclava file for the workflow inputs.
458 459 460 461 462 463 464 465 466 467 468 |
# File 'lib/t2-server/run.rb', line 458 def baclava_input=(filename) state = status raise RunStateError.new(state, :initialized) if state != :initialized file = upload_file(filename) result = @server.update(links[:baclava], file, "text/plain", @credentials) @baclava_in = true if result result end |
#baclava_input? ⇒ Boolean
:call-seq:
baclava_input? -> true or false
Have the inputs to this run been set by a baclava document?
498 499 500 |
# File 'lib/t2-server/run.rb', line 498 def baclava_input? @baclava_in end |
#baclava_output(param = nil, &block) ⇒ Object
:call-seq:
baclava_output -> string
baclava_output(filename) -> fixnum
baclava_output(stream) -> fixnum
baclava_output {|chunk| ...}
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.
Calling this method with no parameters will simply return a blob of XML data. Providing a filename will stream the data directly to that file and return the number of bytes written. Passing in an object that has a write
method (for example, an instance of File or IO) will stream the XML data directly to that object and return the number of bytes that were streamed. Passing in a block will allow access to the underlying data stream:
run.baclava_output do |chunk|
print chunk
end
Raises RunStateError if the run has not finished running.
542 543 544 545 546 547 548 549 550 551 552 553 |
# File 'lib/t2-server/run.rb', line 542 def baclava_output(param = nil, &block) raise ArgumentError, 'both a parameter and block given for baclava_output' if param && block state = status raise RunStateError.new(state, :finished) if state != :finished raise AccessForbiddenError.new("baclava output") if !@baclava_out baclava_uri = Util.append_to_uri_path(links[:wdir], BACLAVA_FILE) download_or_stream(param, baclava_uri, "*/*", &block) end |
#baclava_output? ⇒ Boolean
:stopdoc:
511 512 513 514 515 516 517 |
# File 'lib/t2-server/run.rb', line 511 def baclava_output? warn "[DEPRECATED] Run#baclava_output? is deprecated and will be "\ "removed in the next major release. Please use "\ "Run#generate_baclava_output? instead." generate_baclava_output? end |
#create_time ⇒ Object
:call-seq:
create_time -> string
Get the creation time of this run as an instance of class Time.
691 692 693 |
# File 'lib/t2-server/run.rb', line 691 def create_time Time.parse(@server.read(links[:createtime], "text/plain", @credentials)) end |
#credential(uri) ⇒ Object
:call-seq:
credential(service_uri) -> URI
Return the URI 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.
867 868 869 870 871 |
# File 'lib/t2-server/run.rb', line 867 def credential(uri) return unless owner? credentials[uri] end |
#credentials ⇒ Object
:call-seq:
credentials -> hash
Return a hash (service_uri => credential_uri) 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.
845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 |
# File 'lib/t2-server/run.rb', line 845 def credentials return unless owner? creds = {} doc = xml_document(@server.read(links[:sec_creds], "application/xml", @credentials)) xpath_find(doc, @@xpaths[:sec_cred]).each do |c| uri = URI.parse(xml_node_content(xpath_first(c, @@xpaths[:sec_suri]))) cred_uri = URI.parse(xml_node_attribute(c, "href")) creds[uri] = cred_uri end creds end |
#delete ⇒ Object
:call-seq:
delete
Delete this run from the server.
227 228 229 230 |
# File 'lib/t2-server/run.rb', line 227 def delete @server.delete(@uri, @credentials) @deleted = true end |
#delete_all_credentials ⇒ Object
:call-seq:
delete_all_credentials -> true or false
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.
891 892 893 894 895 |
# File 'lib/t2-server/run.rb', line 891 def delete_all_credentials return unless owner? @server.delete(links[:sec_creds], @credentials) end |
#delete_all_trusts ⇒ Object
:call-seq:
delete_all_trusts -> true or false
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.
955 956 957 958 959 |
# File 'lib/t2-server/run.rb', line 955 def delete_all_trusts return unless owner? @server.delete(links[:sec_trusts], @credentials) end |
#delete_credential(uri) ⇒ Object
:call-seq:
delete_credential(service_uri) -> true or false
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.
879 880 881 882 883 |
# File 'lib/t2-server/run.rb', line 879 def delete_credential(uri) return unless owner? @server.delete(credentials[uri], @credentials) end |
#delete_trust(uri) ⇒ Object
:call-seq:
delete_trust(URI) -> true or false
Delete the trust with the provided URI. Only the owner of a run may delete its trusts. nil
is returned if a user other than the owner uses this method.
943 944 945 946 947 |
# File 'lib/t2-server/run.rb', line 943 def delete_trust(uri) return unless owner? @server.delete(uri, @credentials) end |
#deleted? ⇒ Boolean
:call-seq:
deleted? -> true or false
Has this run been deleted from the server?
236 237 238 |
# File 'lib/t2-server/run.rb', line 236 def deleted? @deleted end |
#download_output_data(uri, range = nil, &block) ⇒ Object
:stopdoc: Outputs are represented as a directory structure with the eventual list items (leaves) as files. This method (not part of the public API) downloads a file from the run’s working directory.
965 966 967 968 |
# File 'lib/t2-server/run.rb', line 965 def download_output_data(uri, range = nil, &block) @server.read(uri, "application/octet-stream", range, @credentials, &block) end |
#error? ⇒ Boolean
:call-seq:
error? -> true or false
Are there errors in this run’s outputs? Returns false if the run is not finished yet.
677 678 679 680 681 682 683 684 685 |
# File 'lib/t2-server/run.rb', line 677 def error? return false unless finished? output_ports.values.each do |output| return true if output.error? end false end |
#exitcode ⇒ Object
:call-seq:
exitcode -> fixnum
Get the return code of the run. Zero indicates success.
369 370 371 |
# File 'lib/t2-server/run.rb', line 369 def exitcode @server.read(links[:exitcode], "text/plain", @credentials).to_i end |
#expiry ⇒ Object
:call-seq:
expiry -> string
Return the expiry time of this run as an instance of class Time.
281 282 283 |
# File 'lib/t2-server/run.rb', line 281 def expiry Time.parse(@server.read(links[:expiry], "text/plain", @credentials)) end |
#expiry=(time) ⇒ Object
:call-seq:
expiry = time -> true or false
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.
292 293 294 295 296 297 298 299 300 301 302 |
# File 'lib/t2-server/run.rb', line 292 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.update(links[:expiry], date_str, "text/plain", @credentials) end |
#finish_time ⇒ Object
:call-seq:
finish_time -> string
Get the finish time of this run as an instance of class Time.
707 708 709 |
# File 'lib/t2-server/run.rb', line 707 def finish_time Time.parse(@server.read(links[:finishtime], "text/plain", @credentials)) end |
#finished? ⇒ Boolean
:call-seq:
finished? -> true or false
Is this run in the :finished state?
668 669 670 |
# File 'lib/t2-server/run.rb', line 668 def finished? status == :finished end |
#generate_baclava_output ⇒ Object
:call-seq:
generate_baclava_output -> true or false
Set the server to save the outputs of this run in baclava format. This must be done before the run is started.
475 476 477 478 479 480 481 482 |
# File 'lib/t2-server/run.rb', line 475 def generate_baclava_output return if @baclava_out state = status raise RunStateError.new(state, :initialized) if state != :initialized @baclava_out = @server.update(links[:output], BACLAVA_FILE, "text/plain", @credentials) end |
#generate_baclava_output? ⇒ Boolean
:call-seq:
generate_baclava_output? -> true or false
Has this run been set to return results in baclava format?
506 507 508 |
# File 'lib/t2-server/run.rb', line 506 def generate_baclava_output? @baclava_out end |
#generate_provenance(toggle = true) ⇒ Object
:call-seq:
generate_provenance(toggle = true) -> true or false
Toggle the generation of provenance for this run on or off. This must be done before the run is started. Once the run has completed provenance can be retrieved with Run#provenance.
Requesting baclava output for a run will override this setting.
563 564 565 566 567 568 569 570 571 572 573 574 |
# File 'lib/t2-server/run.rb', line 563 def generate_provenance(toggle = true) return @provenance if @provenance == toggle || links[:gen_prov].nil? state = status raise RunStateError.new(state, :initialized) if state != :initialized result = @server.update(links[:gen_prov], toggle.to_s, "text/plain", @credentials) # If changing the setting worked then return the new setting, otherwise # return the old one. @provenance = result ? toggle : @provenance end |
#generate_provenance? ⇒ Boolean
:call-seq:
generate_provenance? -> true or false
Has this run been set to generate provenance output?
580 581 582 |
# File 'lib/t2-server/run.rb', line 580 def generate_provenance? @provenance end |
#grant_permission(username, permission) ⇒ Object
:call-seq:
grant_permission(username, permission) -> username
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.
730 731 732 733 734 735 |
# File 'lib/t2-server/run.rb', line 730 def (username, ) return unless owner? value = XML::Fragments::PERM_UPDATE % [username, .to_s] @server.create(links[:sec_perms], value, "application/xml", @credentials) end |
#initialized? ⇒ Boolean
:call-seq:
initialized? -> true or false
Is this run in the :initialized state?
652 653 654 |
# File 'lib/t2-server/run.rb', line 652 def initialized? status == :initialized end |
#input_port(port) ⇒ Object
:call-seq:
input_port(port) -> port
Get port.
252 253 254 |
# File 'lib/t2-server/run.rb', line 252 def input_port(port) input_ports[port] end |
#input_ports ⇒ Object
:call-seq:
input_ports -> hash
Return a hash (name, port) of all the input ports this run expects.
244 245 246 |
# File 'lib/t2-server/run.rb', line 244 def input_ports @input_ports ||= _get_input_port_info end |
#interactions_uri ⇒ Object
This is a slightly unpleasant hack to help proxy interaction communications through a third party.
1000 1001 1002 |
# File 'lib/t2-server/run.rb', line 1000 def interactions_uri links[:feeddir] || "" end |
#log(param = nil, &block) ⇒ Object
:call-seq:
log -> string
log(filename) -> fixnum
log(stream) -> fixnum
log {|chunk| ...}
Get the internal Taverna Server log from this run.
Calling this method with no parameters will simply return a text string. Providing a filename will stream the data directly to that file and return the number of bytes written. Passing in an object that has a write
method (for example, an instance of File or IO) will stream the text directly to that object and return the number of bytes that were streamed. Passing in a block will allow access to the underlying data stream:
run.log do |chunk|
print chunk
end
407 408 409 410 411 412 |
# File 'lib/t2-server/run.rb', line 407 def log(param = nil, &block) raise ArgumentError, 'both a parameter and block given for baclava_output' if param && block download_or_stream(param, links[:logfile], "text/plain", &block) end |
#mkdir(dir) ⇒ Object
:call-seq:
mkdir(dir) -> true or false
Create a directory in the run’s working directory on the server. This could be used to store input data.
419 420 421 422 423 |
# File 'lib/t2-server/run.rb', line 419 def mkdir(dir) dir = Util.strip_path_slashes(dir) @server.mkdir(links[:wdir], dir, @credentials) end |
#name ⇒ Object
:call-seq:
name -> String
Get the name of this run.
Initially this name is derived by Taverna Server from the name annotation in the workflow file and the time at which the run was initialized. It can be set with the name=
method.
For Taverna Server versions prior to version 2.5.0 this is a no-op and the empty string is returned for consistency.
200 201 202 203 |
# File 'lib/t2-server/run.rb', line 200 def name return "" if links[:name].nil? @server.read(links[:name], "text/plain", @credentials) end |
#name=(name) ⇒ Object
:call-seq:
name = new_name -> bool
Set the name of this run. true
is returned upon success. The maximum length of names supported by the server is 48 characters. Anything longer than 48 characters will be truncated before upload.
Initially this name is derived by Taverna Server from the name annotation in the workflow file and the time at which the run was initialized.
For Taverna Server versions prior to version 2.5.0 this is a no-op but true
is still returned for consistency.
218 219 220 221 |
# File 'lib/t2-server/run.rb', line 218 def name=(name) return true if links[:name].nil? @server.update(links[:name], name[0...48], "text/plain", @credentials) end |
#notifications(type = :new_requests) ⇒ Object
:call-seq:
notifications(type = :new_requests) -> array
Poll the server for notifications and return them in a list. Returns the empty list if there are none, or if the server does not support the Interaction Service.
The type
parameter is used to select which types of notifications are returned as follows:
-
:requests
- Interaction requests. -
:replies
- Interaction replies. -
:new_requests
- Interaction requests that are new since the last time they were polled (default). -
:all
- All interaction requests and replies.
1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 |
# File 'lib/t2-server/run.rb', line 1019 def notifications(type = :new_requests) return [] if links[:feed].nil? @interaction_reader ||= Interaction::Feed.new(self) if type == :new_requests @interaction_reader.new_requests else @interaction_reader.notifications(type) end end |
#notifications_uri ⇒ Object
This is a slightly unpleasant hack to help proxy notification communications through a third party.
994 995 996 |
# File 'lib/t2-server/run.rb', line 994 def notifications_uri links[:feed] || "" end |
#output_port(port) ⇒ Object
:call-seq:
output_port(port) -> port
Get output port port.
273 274 275 |
# File 'lib/t2-server/run.rb', line 273 def output_port(port) output_ports[port] if finished? end |
#output_ports ⇒ Object
:call-seq:
output_ports -> hash
Return a hash (name, port) of all the output ports this run has. Until the run is finished this method will return nil.
261 262 263 264 265 266 267 |
# File 'lib/t2-server/run.rb', line 261 def output_ports if finished? && @output_ports.nil? @output_ports = _get_output_port_info end @output_ports end |
#owner ⇒ Object
:call-seq:
owner -> string
Get the username of the owner of this run. The owner is the user who created the run on the server.
185 186 187 |
# File 'lib/t2-server/run.rb', line 185 def owner @owner ||= _get_run_owner end |
#owner? ⇒ Boolean
:call-seq:
owner? -> true or false
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.
719 720 721 |
# File 'lib/t2-server/run.rb', line 719 def owner? @credentials.username == owner end |
#permission(username) ⇒ Object
:call-seq:
permission(username) -> permission
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.
765 766 767 768 769 |
# File 'lib/t2-server/run.rb', line 765 def (username) return unless owner? [username] || :none end |
#permissions ⇒ Object
:call-seq:
permissions -> hash
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.
743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 |
# File 'lib/t2-server/run.rb', line 743 def return unless owner? perms = {} doc = xml_document(@server.read(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 |
#provenance(param = nil, &block) ⇒ Object
:call-seq:
provenance -> binary blob
provenance(filename) -> fixnum
provenance(stream) -> fixnum
provenance {|chunk| ...}
Get the provenance of this run from the server in zip format.
Calling this method with no parameters will simply return a blob of zipped data. Providing a filename will stream the data directly to that file and return the number of bytes written. Passing in an object that has a write
method (for example, an instance of File or IO) will stream the data directly to that object and return the number of bytes that were streamed. Passing in a block will allow access to the underlying data stream:
run.provenance do |chunk|
print chunk
end
Raises RunStateError if the run has not finished running.
604 605 606 607 608 609 610 611 612 613 |
# File 'lib/t2-server/run.rb', line 604 def provenance(param = nil, &block) raise ArgumentError, 'both a parameter and block given for provenance' if param && block state = status raise RunStateError.new(state, :finished) if state != :finished raise AccessForbiddenError.new("provenance") unless @provenance download_or_stream(param, links[:run_bundle], "*/*", &block) end |
#read_interaction_data(name) ⇒ Object
Read a file from the interactions directory for this run on the server.
981 982 983 984 |
# File 'lib/t2-server/run.rb', line 981 def read_interaction_data(name) uri = Util.append_to_uri_path(links[:feeddir], name) @server.read(uri, "*/*", @credentials) end |
#read_notification_feed ⇒ Object
Read from the run’s notification feed.
971 972 973 |
# File 'lib/t2-server/run.rb', line 971 def read_notification_feed @server.read(links[:feed], "application/atom+xml", @credentials) end |
#request_baclava_output ⇒ Object
:stopdoc:
485 486 487 488 489 490 491 |
# File 'lib/t2-server/run.rb', line 485 def request_baclava_output warn "[DEPRECATED] Run#request_baclava_output is deprecated and will "\ "be removed in the next major release. Please use "\ "Run#generate_baclava_output instead." generate_baclava_output end |
#revoke_permission(username) ⇒ Object
:call-seq:
revoke_permission(username) -> true or false
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.
777 778 779 780 781 782 |
# File 'lib/t2-server/run.rb', line 777 def (username) return unless owner? uri = Util.append_to_uri_path(links[:sec_perms], username) @server.delete(uri, @credentials) end |
#running? ⇒ Boolean
:call-seq:
running? -> true or false
Is this run in the :running state?
660 661 662 |
# File 'lib/t2-server/run.rb', line 660 def running? status == :running end |
#start ⇒ Object
:call-seq:
start -> true or false
Start this run on the server. Returns true if the run was started, false otherwise.
Raises RunStateError if the run is not in the :initialized state.
333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
# File 'lib/t2-server/run.rb', line 333 def start state = status raise RunStateError.new(state, :initialized) if state != :initialized # set all the inputs _check_and_set_inputs unless baclava_input? begin @server.update(links[:status], Status.to_text(:running), "text/plain", @credentials) rescue ServerAtCapacityError => sace false end end |
#start_time ⇒ Object
:call-seq:
start_time -> string
Get the start time of this run as an instance of class Time.
699 700 701 |
# File 'lib/t2-server/run.rb', line 699 def start_time Time.parse(@server.read(links[:starttime], "text/plain", @credentials)) end |
#status ⇒ Object
:call-seq:
status -> string
Get the status of this run. Status can be one of :initialized, :running or :finished.
321 322 323 324 |
# File 'lib/t2-server/run.rb', line 321 def status return :deleted if @deleted Status.to_sym(@server.read(links[:status], "text/plain", @credentials)) end |
#stderr ⇒ Object
:call-seq:
stderr -> string
Get anything that the run printed to the standard error stream.
385 386 387 |
# File 'lib/t2-server/run.rb', line 385 def stderr @server.read(links[:stderr], "text/plain", @credentials) end |
#stdout ⇒ Object
:call-seq:
stdout -> string
Get anything that the run printed to the standard out stream.
377 378 379 |
# File 'lib/t2-server/run.rb', line 377 def stdout @server.read(links[:stdout], "text/plain", @credentials) end |
#trusts ⇒ Object
:call-seq:
trusts -> array
Return a list of all the URIs of trusts that have been registered for this run. At present there is no way to differentiate between trusts without noting the URI 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.
923 924 925 926 927 928 929 930 931 932 933 934 935 |
# File 'lib/t2-server/run.rb', line 923 def trusts return unless owner? t_uris = [] doc = xml_document(@server.read(links[:sec_trusts], "application/xml", @credentials)) xpath_find(doc, @@xpaths[:sec_trust]). each do |t| t_uris << URI.parse(xml_node_attribute(t, "href")) end t_uris end |
#upload_data(data, remote_name, remote_directory = "") ⇒ Object
:call-seq:
upload_data(data, remote_name, remote_directory = "") -> true or false
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 Run#mkdir.
449 450 451 452 |
# File 'lib/t2-server/run.rb', line 449 def upload_data(data, remote_name, remote_directory = "") location_uri = Util.append_to_uri_path(links[:wdir], remote_directory) @server.upload_data(data, remote_name, location_uri, @credentials) end |
#upload_file(filename, params = {}) ⇒ Object
:call-seq:
upload_file(filename, params={}) -> string
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 Run#mkdir.
-
:rename - Save the file on the server with a different name.
The name of the file on the server is returned.
435 436 437 438 439 440 441 |
# File 'lib/t2-server/run.rb', line 435 def upload_file(filename, params={}) location = params[:dir] || "" uri = Util.append_to_uri_path(links[:wdir], location) rename = params[:rename] || "" file_uri = @server.upload_file(filename, uri, rename, @credentials) Util.get_path_leaf_from_uri(file_uri) end |
#wait(interval = 1) ⇒ Object
:call-seq:
wait(check_interval = 1)
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 :initialized state.
355 356 357 358 359 360 361 362 363 |
# File 'lib/t2-server/run.rb', line 355 def wait(interval = 1) state = status raise RunStateError.new(state, :running) if state == :initialized # wait until finished? sleep(interval) end end |
#workflow ⇒ Object
:call-seq:
workflow -> string
Get the workflow that this run represents.
308 309 310 311 312 313 314 |
# File 'lib/t2-server/run.rb', line 308 def workflow if @workflow == "" @workflow = @server.read(links[:workflow], "application/xml", @credentials) end @workflow end |
#write_interaction_data(name, data) ⇒ Object
Write a file to the interactions directory for this run on the server.
987 988 989 990 |
# File 'lib/t2-server/run.rb', line 987 def write_interaction_data(name, data) uri = Util.append_to_uri_path(links[:feeddir], name) @server.update(uri, data, "*/*", @credentials) end |
#write_notification(entry) ⇒ Object
Write to the run’s notification feed.
976 977 978 |
# File 'lib/t2-server/run.rb', line 976 def write_notification(entry) @server.create(links[:feed], entry, "application/atom+xml", @credentials) end |
#zip_output(param = nil, port = "", &block) ⇒ Object
:call-seq:
zip_output -> binary blob
zip_output(filename) -> fixnum
zip_output(stream) -> fixnum
zip_output {|chunk| ...}
Get the working directory of this run directly from the server in zip format.
Calling this method with no parameters will simply return a blob of zipped data. Providing a filename will stream the data directly to that file and return the number of bytes written. Passing in an object that has a write
method (for example, an instance of File or IO) will stream the zip data directly to that object and return the number of bytes that were streamed. Passing in a block will allow access to the underlying data stream:
run.zip_output do |chunk|
print chunk
end
Raises RunStateError if the run has not finished running.
636 637 638 639 640 641 642 643 644 645 646 |
# File 'lib/t2-server/run.rb', line 636 def zip_output(param = nil, port = "", &block) raise ArgumentError, "both a parameter and block given for zip_output" if param && block state = status raise RunStateError.new(state, :finished) if state != :finished path = port.empty? ? "out" : "out/#{port}" output_uri = Util.append_to_uri_path(links[:wdir], path) download_or_stream(param, output_uri, "application/zip", &block) end |