t2-server 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -41,25 +41,23 @@ require 'optparse'
41
41
  # server seems to be rather sensitive to slashes, hence
42
42
  # all the [...] mucking about.
43
43
  def get_outputs(run, pout, dir="")
44
- outputs = run.ls("out#{dir}")
45
- outputs.each do |out|
46
- if out.include? "/"
47
- get_outputs(run, pout, "#{dir}/#{out[0...-1]}")
44
+ dirs, files = run.ls("out#{dir}")
45
+ dirs.each {|d| get_outputs(run, pout, "#{dir}/#{d}")}
46
+ files.each do |out|
47
+ print " #{dir}/#{out} -> "
48
+ output_name = "#{dir[1..-1]}/#{out}"
49
+ data = run.get_output(output_name)
50
+ if pout
51
+ p data
48
52
  else
49
- print " #{dir}/#{out} -> "
50
- data = run.get_output("#{dir[1..-1]}/#{out}")
51
- if pout
52
- p data
53
- else
54
- filename = "#{dir[1..-1]}/#{out}".gsub('/','-')
55
- File.open(filename, "w") do |file|
56
- file.syswrite(data)
57
- end
58
- puts "written to file: #{filename}"
53
+ filename = output_name.gsub('/', '-')
54
+ File.open(filename, "w") do |file|
55
+ file.syswrite(data)
59
56
  end
57
+ puts "written to file: #{filename}"
60
58
  end
61
59
  end
62
- end
60
+ end
63
61
 
64
62
  # set up options
65
63
  inputs = {}
@@ -113,6 +111,7 @@ end
113
111
  # create run and set inputs
114
112
  run = T2Server::Run.create(uri, wkf)
115
113
  puts "Created run with uuid: #{run.uuid}"
114
+ puts "Created at #{run.create_time}"
116
115
 
117
116
  inputs.each do |input, value|
118
117
  puts "Set input '#{input}' to #{value}"
@@ -120,8 +119,11 @@ inputs.each do |input, value|
120
119
  end
121
120
 
122
121
  # start run and wait until it is finished
122
+ run.start
123
+ puts "Started at #{run.start_time}"
123
124
  print "Running"
124
- run.start_and_wait(:progress => true)
125
+ run.wait(:progress => true)
126
+ puts "Finished at #{run.finish_time}"
125
127
 
126
128
  # get outputs
127
129
  stdout = run.stdout
@@ -35,6 +35,6 @@ require 't2server/server'
35
35
  require 't2server/run'
36
36
 
37
37
  module T2Server
38
- GEM_VERSION = "0.0.1"
38
+ GEM_VERSION = "0.0.2"
39
39
  API_VERSION = "2.2.0a1"
40
40
  end
@@ -113,13 +113,14 @@ module T2Server
113
113
  @server.set_run_attribute(@uuid, @links[:status], STATE[:running])
114
114
  end
115
115
 
116
- def start_and_wait(params={})
116
+ def wait(params={})
117
+ return unless running?
118
+
117
119
  interval = params[:interval] || 1
118
120
  progress = params[:progress] || false
119
121
  keepalive = params[:keepalive] || false ### TODO maybe move out of params
120
122
 
121
- # start run and wait
122
- start
123
+ # wait
123
124
  until finished?
124
125
  sleep(interval)
125
126
  if progress
@@ -172,10 +173,11 @@ module T2Server
172
173
 
173
174
  # compile a list of directory entries stripping the
174
175
  # directory name from the front of each filename
175
- entries = []
176
- XPath.each(doc, "//nss:dir", Namespaces::MAP) {|e| entries << "#{e.text.split('/')[-1]}/"}
177
- XPath.each(doc, "//nss:file", Namespaces::MAP) {|e| entries << e.text.split('/')[-1]}
178
- entries
176
+ dirs = []
177
+ files = []
178
+ XPath.each(doc, "//nss:dir", Namespaces::MAP) {|e| dirs << e.text.split('/')[-1]}
179
+ XPath.each(doc, "//nss:file", Namespaces::MAP) {|e| files << e.text.split('/')[-1]}
180
+ [dirs, files]
179
181
  end
180
182
 
181
183
  def initialized?
@@ -189,6 +191,18 @@ module T2Server
189
191
  def finished?
190
192
  status == STATE[:finished]
191
193
  end
194
+
195
+ def create_time
196
+ @server.get_run_attribute(@uuid, @links[:createtime])
197
+ end
198
+
199
+ def start_time
200
+ @server.get_run_attribute(@uuid, @links[:starttime])
201
+ end
202
+
203
+ def finish_time
204
+ @server.get_run_attribute(@uuid, @links[:finishtime])
205
+ end
192
206
 
193
207
  private
194
208
  def get_attributes(desc)
@@ -214,14 +228,17 @@ module T2Server
214
228
  doc = Document.new(desc)
215
229
  nsmap = Namespaces::MAP
216
230
  {
217
- :expiry => XPath.first(doc, "//nsr:expiry", nsmap).attributes["href"].split('/')[-1],
218
- :workflow => XPath.first(doc, "//nsr:creationWorkflow", nsmap).attributes["href"].split('/')[-1],
219
- :status => XPath.first(doc, "//nsr:status", nsmap).attributes["href"].split('/')[-1],
220
- :wdir => XPath.first(doc, "//nsr:workingDirectory", nsmap).attributes["href"].split('/')[-1],
221
- :inputs => XPath.first(doc, "//nsr:inputs", nsmap).attributes["href"].split('/')[-1],
222
- :output => XPath.first(doc, "//nsr:output", nsmap).attributes["href"].split('/')[-1],
223
- :securectx => XPath.first(doc, "//nsr:securityContext", nsmap).attributes["href"].split('/')[-1],
224
- :listeners => XPath.first(doc, "//nsr:listeners", nsmap).attributes["href"].split('/')[-1]
231
+ :expiry => XPath.first(doc, "//nsr:expiry", nsmap).attributes["href"].split('/')[-1],
232
+ :workflow => XPath.first(doc, "//nsr:creationWorkflow", nsmap).attributes["href"].split('/')[-1],
233
+ :status => XPath.first(doc, "//nsr:status", nsmap).attributes["href"].split('/')[-1],
234
+ :createtime => XPath.first(doc, "//nsr:createTime", nsmap).attributes["href"].split('/')[-1],
235
+ :starttime => XPath.first(doc, "//nsr:startTime", nsmap).attributes["href"].split('/')[-1],
236
+ :finishtime => XPath.first(doc, "//nsr:finishTime", nsmap).attributes["href"].split('/')[-1],
237
+ :wdir => XPath.first(doc, "//nsr:workingDirectory", nsmap).attributes["href"].split('/')[-1],
238
+ :inputs => XPath.first(doc, "//nsr:inputs", nsmap).attributes["href"].split('/')[-1],
239
+ :output => XPath.first(doc, "//nsr:output", nsmap).attributes["href"].split('/')[-1],
240
+ :securectx => XPath.first(doc, "//nsr:securityContext", nsmap).attributes["href"].split('/')[-1],
241
+ :listeners => XPath.first(doc, "//nsr:listeners", nsmap).attributes["href"].split('/')[-1]
225
242
  }
226
243
  end
227
244
  end
@@ -59,7 +59,7 @@ module T2Server
59
59
 
60
60
  # initialise run list
61
61
  @runs = {}
62
- @runs = runs
62
+ @runs = get_runs
63
63
  end
64
64
 
65
65
  def Server.connect(uri)
@@ -101,38 +101,13 @@ module T2Server
101
101
  ""
102
102
  end
103
103
  end
104
-
104
+
105
105
  def runs
106
- request = Net::HTTP::Get.new("#{@links[:runs]}")
107
- response = Net::HTTP.new(@host, @port).start {|http| http.request(request)}
108
-
109
- case response
110
- when Net::HTTPOK
111
- doc = Document.new(response.body)
112
-
113
- # get list of run uuids
114
- uuids = []
115
- XPath.each(doc, "//nsr:run", Namespaces::MAP) do |run|
116
- uuids << run.attributes["href"].split('/')[-1]
117
- end
118
-
119
- # add new runs
120
- uuids.each do |uuid|
121
- if !@runs.has_key? uuid
122
- description = get_run_description(uuid)
123
- @runs[uuid] = Run.create(self, "", uuid)
124
- end
125
- end
126
-
127
- # clear out the expired runs
128
- if @runs.length > @run_limit
129
- @runs.delete_if {|key, val| !uuids.member? key}
130
- end
131
-
132
- @runs
133
- else
134
- response_error(response)
135
- end
106
+ get_runs.values
107
+ end
108
+
109
+ def run(uuid)
110
+ get_runs[uuid]
136
111
  end
137
112
 
138
113
  def delete_run(uuid)
@@ -154,7 +129,7 @@ module T2Server
154
129
 
155
130
  def delete_all_runs
156
131
  # first refresh run list
157
- runs.each_value {|run| run.delete}
132
+ runs.each {|run| run.delete}
158
133
  end
159
134
 
160
135
  def set_run_input(run, input, value)
@@ -320,5 +295,37 @@ module T2Server
320
295
  false
321
296
  end
322
297
 
298
+ def get_runs
299
+ request = Net::HTTP::Get.new("#{@links[:runs]}")
300
+ response = Net::HTTP.new(@host, @port).start {|http| http.request(request)}
301
+
302
+ case response
303
+ when Net::HTTPOK
304
+ doc = Document.new(response.body)
305
+
306
+ # get list of run uuids
307
+ uuids = []
308
+ XPath.each(doc, "//nsr:run", Namespaces::MAP) do |run|
309
+ uuids << run.attributes["href"].split('/')[-1]
310
+ end
311
+
312
+ # add new runs
313
+ uuids.each do |uuid|
314
+ if !@runs.has_key? uuid
315
+ description = get_run_description(uuid)
316
+ @runs[uuid] = Run.create(self, "", uuid)
317
+ end
318
+ end
319
+
320
+ # clear out the expired runs
321
+ if @runs.length > @run_limit
322
+ @runs.delete_if {|key, val| !uuids.member? key}
323
+ end
324
+
325
+ @runs
326
+ else
327
+ response_error(response)
328
+ end
329
+ end
323
330
  end
324
331
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: t2-server
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Robert Haines
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-21 00:00:00 +01:00
18
+ date: 2010-07-22 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies: []
21
21