lib/t2-server/server.rb in t2-server-0.6.0 vs lib/t2-server/server.rb in t2-server-0.6.1
- old
+ new
@@ -1,6 +1,6 @@
-# Copyright (c) 2010, The University of Manchester, UK.
+# Copyright (c) 2010, 2011 The University of Manchester, UK.
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
@@ -43,11 +43,11 @@
class Server
include LibXML
private_class_method :new
- # The URI of this server instance as a String.
+ # The URI of this server instance.
attr_reader :uri
# The maximum number of runs that this server will allow at any one time.
# Runs in any state (+Initialized+, +Running+ and +Finished+) are counted
# against this maximum.
@@ -57,25 +57,24 @@
@@servers = []
# :stopdoc:
# New is private but rdoc does not get it right! Hence :stopdoc: section.
def initialize(uri, username, password)
- @uri = uri.strip_path
- uri = URI.parse(@uri)
- @host = uri.host
- @port = uri.port
- @base_path = uri.path
- @rest_path = uri.path + "/rest"
+ @uri = uri
+ @host = @uri.host
+ @port = @uri.port
+ @base_path = @uri.path
+ @rest_path = @uri.path + "/rest"
# set up http connection
@http = Net::HTTP.new(@host, @port)
# use ssl?
@ssl = uri.scheme == "https"
if ssl?
- @username = uri.user || username
- @password = uri.password || password
+ @username = username
+ @password = password
@http.use_ssl = true
@http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
@@ -100,16 +99,27 @@
# http://example.com:8888/blah or https://user:pass@example.com:8888/blah
#
# The username and password can also be passed in separately.
# A Server instance is returned that represents the connection.
def Server.connect(uri, username="", password="")
+ # we want to use URIs here but strings can be passed in
+ if !uri.instance_of? URI
+ uri = URI.parse(uri.strip_path);
+ end
+
+ # strip username and password from the URI if present
+ username = uri.user || username
+ password = uri.password || password
+ new_uri = URI::HTTP.new(uri.scheme, nil, uri.host, uri.port, nil,
+ uri.path, nil, nil, nil);
+
# see if we've already got this server
- server = @@servers.find {|s| s.uri == uri}
+ server = @@servers.find {|s| s.uri == new_uri}
if !server
# no, so create new one and return it
- server = new(uri, username, password)
+ server = new(new_uri, username, password)
@@servers << server
end
server
end
@@ -233,12 +243,13 @@
# get the run from the uuid if that is what is passed in
if not run.instance_of? Run
run = run(run)
end
+ xml_value = XML::Node.new_text(value)
path = "#{@links[:runs]}/#{run.uuid}/#{run.inputs}/input/#{input}"
- set_attribute(path, Fragments::RUNINPUTVALUE % value, "application/xml")
+ set_attribute(path, Fragments::RUNINPUTVALUE % xml_value, "application/xml")
rescue AttributeNotFoundError => e
if get_runs.has_key? run.uuid
raise e
else
raise RunNotFoundError.new(run.uuid)
@@ -254,11 +265,12 @@
# get the run from the uuid if that is what is passed in
if not run.instance_of? Run
run = run(run)
end
+ xml_value = XML::Node.new_text(filename)
path = "#{@links[:runs]}/#{run.uuid}/#{run.inputs}/input/#{input}"
- set_attribute(path, Fragments::RUNINPUTFILE % filename, "application/xml")
+ set_attribute(path, Fragments::RUNINPUTFILE % xml_value, "application/xml")
rescue AttributeNotFoundError => e
if get_runs.has_key? run.uuid
raise e
else
raise RunNotFoundError.new(run.uuid)