simplews 1.7.3 → 1.8.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -4,6 +4,8 @@ This library simplifies the creation of SOAP web services. It is based on
4
4
  soap4r, and adds a DSL for serving methods that create automatically the WSDL.
5
5
  Additionally, it offers support for asynchronous jobs.
6
6
 
7
+ Documentation and detailed examples available at http://bioinfovm05.dacya.ucm.es/simplews/index.html
8
+
7
9
  == Note on Patches/Pull Requests
8
10
 
9
11
  * Fork the project.
data/bin/start_jobs_ws ADDED
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/ruby
2
+ require 'rubygems'
3
+ require 'simplews'
4
+ require "optparse"
5
+ require 'simplews/rake'
6
+
7
+ options = {}
8
+ OptionParser.new do |opts|
9
+ opts.banner = "Usage: #{ $_ } [options] <config_file>"
10
+
11
+ opts.on("-h", "--host HOST", String, "Select host interface, localhost by default") do |host|
12
+ options[:host] = host
13
+ end
14
+
15
+ opts.on("-p", "--port PORT", Integer, "Select interface port, 1984 by default") do |port|
16
+ options[:port] = port
17
+ end
18
+
19
+ opts.on("-n", "--name NAME", String, "Select the name of the web server interface, SimpleWS by default") do |name|
20
+ options[:name] = name
21
+ end
22
+
23
+ opts.on("-d", "--description DESCRIPTION", String, "Description of the service") do |description|
24
+ options[:description] = description
25
+ end
26
+
27
+ opts.on("-w", "--wsdl FILENAME", String, "Save the WSDL file") do |filename|
28
+ options[:wsdl] = filename
29
+ end
30
+
31
+ opts.on("-d", "--directory PATH", String, "Work directory for the WS") do |filename|
32
+ options[:wsdl] = filename
33
+ end
34
+
35
+ end.parse!
36
+
37
+ filename = ARGV[0]
38
+
39
+ server = SimpleWS::Jobs.new(options[:name], options[:description], options[:host], options[:port], options[:directory]) do
40
+ actions = File.open(filename)do |f| f.read end
41
+ eval actions
42
+ end
43
+
44
+ server.wsdl(options[:wsdl]) if options[:wsdl]
45
+
46
+ trap('INT'){
47
+ puts "Stopping server"
48
+ server.shutdown
49
+ }
50
+
51
+ server.start
52
+
53
+
data/lib/simplews/jobs.rb CHANGED
@@ -124,7 +124,7 @@ class SimpleWS::Jobs < SimpleWS
124
124
  name = @@pids.select{|name, p| p == pid}.first
125
125
  return if name.nil?
126
126
  name = name.first
127
- puts "Process #{ name } with pid #{ pid } finished with exitstatus #{$?.exitstatus}"
127
+ puts "Job #{ name } with pid #{ pid } finished with exitstatus #{$?.exitstatus}"
128
128
  state = Job.job_info(name)
129
129
  if ![:error, :done, :aborted].include?(state[:status])
130
130
  state[:status] = :error
@@ -268,6 +268,8 @@ class SimpleWS::Jobs < SimpleWS
268
268
 
269
269
  def write(file, contents)
270
270
  path = Job.path(file, @name)
271
+ directory = File.dirname(File.expand_path(path))
272
+ FileUtils.mkdir_p directory unless File.exists? directory
271
273
  File.open(path,'w') do |fout|
272
274
  fout.write contents
273
275
  end
@@ -369,6 +371,7 @@ class SimpleWS::Jobs < SimpleWS
369
371
 
370
372
  def task(name, params=[], types={}, results = [], &block)
371
373
  @@last_param_description['return'] ||= 'Job identifier' if @@last_param_description
374
+ @@last_param_description['suggested_name'] ||= 'Suggested job id' if @@last_param_description
372
375
 
373
376
  Scheduler.task name, results, block
374
377
  serve name.to_s, params + ['suggested_name'], types.merge(:suggested_name => 'string', :return => :string) do |*args|
@@ -464,7 +467,7 @@ class SimpleWS::Jobs < SimpleWS
464
467
  results.collect{|p| p[0]}
465
468
  end
466
469
 
467
- desc "Job management: Return the content of the result specified by the result identifier. These identifiers are retrieve using the 'results' operation"
470
+ desc "Job management: Return the content of the result specified by the result identifier. These identifiers are retrieve using the 'results' operation. Results are Base64 encoded to allow binary data"
468
471
  param_desc :result => "Result identifier", :return => "Content of the result file, in Base64 encoding for compatibility"
469
472
  serve :result, %w(result), :return => :binary do |result|
470
473
  path = @results[result]
data/lib/simplews/rake.rb CHANGED
@@ -46,8 +46,6 @@ class SimpleWS::Jobs::Scheduler::Job
46
46
  EOC
47
47
 
48
48
  load rakefile
49
- p workdir
50
- p @@steps
51
49
  @@steps.each{|step|
52
50
  step_dirname = File.join(workdir, step.to_s)
53
51
  FileUtils.mkdir_p step_dirname unless File.exists? step_dirname
data/lib/simplews.rb CHANGED
@@ -46,10 +46,8 @@ require 'builder'
46
46
 
47
47
 
48
48
  class SimpleWS < SOAP::RPC::StandaloneServer
49
- VERSION = "1.3.6"
50
-
51
49
  # Saves method defined in the class to be served by the instances
52
- INHERITED_METHODS = {}
50
+ INHERITED_METHODS = {} unless defined? INHERITED_METHODS
53
51
 
54
52
  # This is a helper function for clients. Given the +url+ where the
55
53
  # server is listening, as well as the name of the server, it can
@@ -216,10 +214,9 @@ class SimpleWS < SOAP::RPC::StandaloneServer
216
214
  wsdl.gsub!(/\$\{NAME\}/,@name)
217
215
  wsdl.gsub!(/\$\{DESCRIPTION\}/,@description)
218
216
  wsdl.gsub!(/\$\{LOCATION\}/,"http://#{ @host }:#{ @port }")
217
+
219
218
  if filename
220
- fwsdl = File.open(filename,'w')
221
- fwsdl.write(wsdl)
222
- fwsdl.close
219
+ File.open(filename,'w') {|f| f.write wsdl }
223
220
  nil
224
221
  else
225
222
  wsdl
@@ -237,17 +234,33 @@ class SimpleWS < SOAP::RPC::StandaloneServer
237
234
  end
238
235
  xml.tbody do
239
236
  @method_order.each do |method|
240
- xml.tr do
237
+ desc = @method_descriptions[method][:description] || ""
238
+ case
239
+ when method.to_s == 'wsdl' || method.to_s == 'documentation'
240
+ type = 'WS_documentation'
241
+ when desc =~ /^Job management:/
242
+ type = 'WS_job_management'
243
+ when @method_descriptions[method][:args].include?( :sugested_name )
244
+ type = 'WS_task'
245
+ else
246
+ type = 'WS_normal'
247
+ end
248
+ xml.tr :class => type, :id => "WS_method_#{method}" do
241
249
  xml.td method.to_s, :class => "WS_operation"
242
250
 
243
251
  xml.td :class => "WS_parameters" do
244
252
  description = @method_descriptions[method]
245
253
  method_parameters = description[:args]
246
- method_parameters.push 'return' unless description[:types][:return] == false || description[:types]['return'] == false
254
+ method_parameters += ['return'] unless description[:types][:return] == false || description[:types]['return'] == false
247
255
  if method_parameters.any?
248
256
  xml.dl :class => "WS_parameter_documentation" do
249
257
  method_parameters.each do |param|
250
- xml.dt param
258
+ if param.to_s == 'return'
259
+ xml.dt param, :class => 'WS_return'
260
+ else
261
+ xml.dt param
262
+ end
263
+
251
264
  if description[:param_descriptions]
252
265
  xml.dd description[:param_descriptions][param.to_s] || ""
253
266
  else
@@ -257,14 +270,18 @@ class SimpleWS < SOAP::RPC::StandaloneServer
257
270
  end
258
271
  end
259
272
  end
260
-
261
- xml.td description[:description] || "", :class => "WS_documentation"
273
+ xml.td desc, :class => "WS_documentation"
262
274
  end
263
275
  end
264
276
  end
265
277
  end
266
278
 
267
- html_table
279
+ if filename
280
+ File.open(filename,'w') {|f| f.write html_table }
281
+ nil
282
+ else
283
+ html_table
284
+ end
268
285
  end
269
286
 
270
287
  private
@@ -298,7 +315,6 @@ class SimpleWS < SOAP::RPC::StandaloneServer
298
315
  type = :string if type.nil?
299
316
  if type
300
317
  type = type.to_sym
301
-
302
318
  xml.part :name => 'return', :type => TYPES2WSDL[type] do
303
319
  param_descriptions = description[:param_descriptions]
304
320
 
@@ -306,7 +322,6 @@ class SimpleWS < SOAP::RPC::StandaloneServer
306
322
  xml.documentation param_descriptions['return']
307
323
  end
308
324
  end
309
-
310
325
  end
311
326
  end
312
327
  @messages << message
@@ -333,6 +348,7 @@ class SimpleWS < SOAP::RPC::StandaloneServer
333
348
  end
334
349
 
335
350
 
351
+ if ! defined? WSDL_STUB
336
352
  WSDL_STUB =<<EOT
337
353
  <?xml version="1.0"?>
338
354
  <definitions xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
@@ -382,15 +398,18 @@ ${BINDINGS}
382
398
 
383
399
  </definitions>
384
400
  EOT
401
+ end
385
402
 
386
- TYPES2WSDL = {
387
- :boolean => 'xsd:boolean',
388
- :string => 'xsd:string',
389
- :integer => 'xsd:integer',
390
- :float => 'xsd:float',
391
- :array => 'tns:ArrayOfString',
392
- :binary => 'xsd:base64Binary',
393
- }
403
+ if ! defined? TYPES2WSDL
404
+ TYPES2WSDL = {
405
+ :boolean => 'xsd:boolean',
406
+ :string => 'xsd:string',
407
+ :integer => 'xsd:integer',
408
+ :float => 'xsd:float',
409
+ :array => 'tns:ArrayOfString',
410
+ :binary => 'xsd:base64Binary',
411
+ }
412
+ end
394
413
 
395
414
 
396
415
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplews
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.3
4
+ version: 1.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Vazquez
@@ -9,8 +9,8 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-01 00:00:00 +01:00
13
- default_executable: start_ws
12
+ date: 2010-01-02 00:00:00 +01:00
13
+ default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: soap4r
@@ -45,6 +45,7 @@ dependencies:
45
45
  description: Generates WSDL automatically. It manages jobs as asynchronous processes
46
46
  email: miguel.vazquez@fdi.ucm.es
47
47
  executables:
48
+ - start_jobs_ws
48
49
  - start_ws
49
50
  extensions: []
50
51