openwferu 0.9.5 → 0.9.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/examples/mano_tracker.rb +11 -13
  2. data/lib/openwfe.rb +2 -4
  3. data/lib/openwfe/contextual.rb +8 -2
  4. data/lib/openwfe/engine/engine.rb +118 -2
  5. data/lib/openwfe/expool/expressionpool.rb +148 -53
  6. data/lib/openwfe/expool/expstorage.rb +36 -4
  7. data/lib/openwfe/expool/yamlexpstorage.rb +18 -0
  8. data/lib/openwfe/expressions/environment.rb +1 -1
  9. data/lib/openwfe/expressions/fe_misc.rb +14 -2
  10. data/lib/openwfe/expressions/fe_raw.rb +27 -11
  11. data/lib/openwfe/expressions/fe_subprocess.rb +45 -12
  12. data/lib/openwfe/expressions/fe_utils.rb +1 -1
  13. data/lib/openwfe/expressions/flowexpression.rb +5 -1
  14. data/lib/openwfe/expressions/raw_prog.rb +80 -32
  15. data/lib/openwfe/expressions/raw_xml.rb +10 -0
  16. data/lib/openwfe/flowexpressionid.rb +28 -7
  17. data/lib/openwfe/listeners/listener.rb +106 -0
  18. data/lib/openwfe/listeners/listeners.rb +140 -0
  19. data/lib/openwfe/listeners/socketlisteners.rb +239 -0
  20. data/lib/openwfe/listeners/sqslisteners.rb +145 -0
  21. data/lib/openwfe/participants/{csvparticipant.rb → csvparticipants.rb} +0 -0
  22. data/lib/openwfe/participants/{enoparticipant.rb → enoparticipants.rb} +1 -1
  23. data/lib/openwfe/participants/participantmap.rb +33 -1
  24. data/lib/openwfe/participants/participants.rb +99 -11
  25. data/lib/openwfe/participants/soapparticipants.rb +28 -8
  26. data/lib/openwfe/participants/socketparticipants.rb +172 -0
  27. data/lib/openwfe/participants/sqsparticipants.rb +121 -0
  28. data/lib/openwfe/rest/definitions.rb +1 -1
  29. data/lib/openwfe/{osocket.rb → rest/osocket.rb} +16 -8
  30. data/lib/openwfe/rest/xmlcodec.rb +41 -5
  31. data/lib/openwfe/storage/yamlfilestorage.rb +10 -13
  32. data/lib/openwfe/util/dollar.rb +23 -2
  33. data/lib/openwfe/util/otime.rb +1 -1
  34. data/lib/openwfe/util/safe.rb +149 -0
  35. data/lib/openwfe/util/scheduler.rb +47 -5
  36. data/lib/openwfe/util/sqs.rb +582 -0
  37. data/lib/openwfe/utils.rb +23 -0
  38. data/lib/openwfe/version.rb +1 -1
  39. data/lib/openwfe/workitem.rb +86 -3
  40. data/lib/openwfe/worklist/storeparticipant.rb +44 -4
  41. data/test/csv_test.rb +1 -1
  42. data/test/eno_test.rb +1 -1
  43. data/test/fei_test.rb +2 -15
  44. data/test/flowtestbase.rb +6 -2
  45. data/test/ft_11_ppd.rb +31 -0
  46. data/test/ft_13_eno.rb +1 -1
  47. data/test/ft_14b_subprocess.rb +74 -0
  48. data/test/ft_15_iterator.rb +0 -1
  49. data/test/ft_19_csv.rb +1 -1
  50. data/test/ft_20_cron.rb +1 -1
  51. data/test/ft_21_cron.rb +1 -1
  52. data/test/ft_27_getflowpos.rb +89 -0
  53. data/test/ft_28_fileparticipant.rb +65 -0
  54. data/test/ft_29_httprb.rb +95 -0
  55. data/test/ft_30_socketlistener.rb +197 -0
  56. data/test/ft_4_misc.rb +2 -1
  57. data/test/hash_test.rb +75 -0
  58. data/test/rake_qtest.rb +5 -4
  59. data/test/raw_prog_test.rb +205 -0
  60. data/test/rutest_utils.rb +16 -0
  61. data/test/safely_test.rb +89 -0
  62. data/test/scheduler_test.rb +71 -0
  63. data/test/sqs_test.rb +103 -0
  64. metadata +21 -6
  65. data/test/journal_persistence_test.rb +0 -147
@@ -39,6 +39,10 @@
39
39
  # john.mettraux@openwfe.org
40
40
  #
41
41
 
42
+ require 'tmpdir'
43
+ require 'open-uri'
44
+
45
+
42
46
  module OpenWFE
43
47
 
44
48
  #
@@ -152,6 +156,18 @@ module OpenWFE
152
156
  string.gsub("_", "-")
153
157
  end
154
158
 
159
+ #
160
+ # Returns an URI if the string is one, else returns nil.
161
+ # No exception is thrown by this method.
162
+ #
163
+ def OpenWFE.parse_uri (string)
164
+ begin
165
+ return URI::parse(string)
166
+ rescue Exception => e
167
+ end
168
+ return nil
169
+ end
170
+
155
171
  #
156
172
  # Returns true if the given string starts with the 'start' string.
157
173
  #
@@ -209,9 +225,16 @@ module OpenWFE
209
225
  # end
210
226
  #
211
227
  def OpenWFE.call_in_thread (caller_name, caller_object=nil, &block)
228
+
212
229
  return unless block
230
+
213
231
  Thread.new do
214
232
  begin
233
+ #$SAFE = safe_level
234
+ #
235
+ # doesn't work : the block inherits the safety level
236
+ # of its surroundings, it's a closure, ne ?
237
+
215
238
  block.call
216
239
  rescue Exception => e
217
240
  msg = "#{caller_name} caught an exception\n" + exception_to_s(e)
@@ -34,5 +34,5 @@
34
34
  #
35
35
 
36
36
  module OpenWFE
37
- OPENWFERU_VERSION = '0.9.5'
37
+ OPENWFERU_VERSION = '0.9.6'
38
38
  end
@@ -71,6 +71,21 @@ module OpenWFE
71
71
  alias :fields :attributes
72
72
  alias :fields= :attributes=
73
73
 
74
+ def to_h
75
+ h = {}
76
+ h[:type] = self.class.name
77
+ h[:last_modified] = @last_modified
78
+ h[:attributes] = @attributes
79
+ h
80
+ end
81
+
82
+ def WorkItem.from_h (h)
83
+ wi = eval("#{h[:type]}.new")
84
+ wi.last_modified = h[:last_modified]
85
+ wi.attributes = h[:attributes]
86
+ wi
87
+ end
88
+
74
89
  #
75
90
  # In order to simplify code like :
76
91
  #
@@ -195,6 +210,20 @@ module OpenWFE
195
210
  #
196
211
  alias :fei :flow_expression_id
197
212
  alias :fei= :flow_expression_id=
213
+
214
+ def to_h
215
+ h = super
216
+ h[:flow_expression_id] = @flow_expression_id.to_h
217
+ h[:participant_name] = @participant_name
218
+ h
219
+ end
220
+
221
+ def InFlowItem.from_h (h)
222
+ wi = super
223
+ wi.flow_expression_id = FlowExpressionId.from_h(h[:flow_expression_id])
224
+ wi.participant_name = h[:participant_name]
225
+ wi
226
+ end
198
227
  end
199
228
 
200
229
  #
@@ -226,7 +255,30 @@ module OpenWFE
226
255
  s << " * '#{k}' --> '#{v}'\n"
227
256
  end
228
257
  s << " <<<#{self.class}<<<"
229
- return s
258
+ s
259
+ end
260
+
261
+ #
262
+ # For some easy YAML encoding, turns the workitem into a Hash
263
+ # (Any YAML-enabled platform can thus read it).
264
+ #
265
+ def to_h
266
+ h = super
267
+ h[:dispatch_time] = @dispatch_time
268
+ h[:history] = @history
269
+ h[:filter] = @filter
270
+ h
271
+ end
272
+
273
+ #
274
+ # Rebuilds an InFlowWorkItem from its hash version.
275
+ #
276
+ def InFlowWorkItem.from_h (h)
277
+ wi = super
278
+ wi.dispatch_time = h[:dispatch_time]
279
+ wi.history = h[:history]
280
+ wi.filter = h[:filter]
281
+ wi
230
282
  end
231
283
  end
232
284
 
@@ -251,9 +303,15 @@ module OpenWFE
251
303
  #
252
304
  class LaunchItem < WorkItem
253
305
 
306
+ DEF = "__definition"
307
+ FIELD_DEF = "field:#{DEF}"
308
+
254
309
  attr_accessor :workflow_definition_url
255
310
  #, :description_map
256
311
 
312
+ alias :wfdurl :workflow_definition_url
313
+ alias :wfdurl= :workflow_definition_url=
314
+
257
315
  #
258
316
  # This constructor will build an empty launchitem.
259
317
  # If the optional parameter process_definition is set, the
@@ -265,12 +323,37 @@ module OpenWFE
265
323
  super()
266
324
 
267
325
  if process_definition
268
- @workflow_definition_url = "field:__definition"
269
- @attributes['__definition'] = process_definition
326
+ @workflow_definition_url = FIELD_DEF
327
+ @attributes[DEF] = process_definition
270
328
  end
271
329
  end
330
+
331
+ #
332
+ # Turns the LaunchItem instance into a simple 'hash' (easily
333
+ # serializable to other formats).
334
+ #
335
+ def to_h
336
+ h = super
337
+ h[:workflow_definition_url] = @workflow_definition_url
338
+ h
339
+ end
340
+
341
+ def LaunchItem.from_h (h)
342
+ li = super
343
+ li.workflow_definition_url = h[:workflow_definition_url]
344
+ li
345
+ end
272
346
  end
273
347
 
348
+ #
349
+ # Turns a hash into its corresponding workitem (InFlowWorkItem, CancelItem,
350
+ # LaunchItem).
351
+ #
352
+ def OpenWFE.workitem_from_h (h)
353
+ wi_class = h[:type]
354
+ wi_class = eval(wi_class)
355
+ wi_class.from_h(h)
356
+ end
274
357
 
275
358
  #
276
359
  # HISTORY ITEM
@@ -39,6 +39,7 @@
39
39
  #
40
40
 
41
41
  require 'openwfe/utils'
42
+ require 'openwfe/rudefinitions'
42
43
  require 'openwfe/storage/yamlfilestorage'
43
44
  require 'openwfe/participants/participant'
44
45
 
@@ -135,12 +136,42 @@ module OpenWFE
135
136
 
136
137
  return result
137
138
  end
139
+
140
+ #
141
+ # Returns the first workitem at hand.
142
+ # As a StoreParticipant is usually implemented with a hash, two
143
+ # consecutive calls to this method might not return the same workitem
144
+ # (except if the store is empty or contains 1! workitem).
145
+ #
146
+ def first_workitem ()
147
+
148
+ result = nil
149
+
150
+ self.each_value do |workitem|
151
+ result = workitem
152
+ break
153
+ end
154
+
155
+ return result
156
+ end
138
157
  end
139
158
 
140
159
  #
141
160
  # The simplest workitem store possible, gathers the workitem in a
142
161
  # hash (this class is an extension of Hash).
143
162
  #
163
+ # Some examples :
164
+ #
165
+ # engine.register_participant(:alice, OpenWFE::HashParticipant)
166
+ # engine.register_participant("bob", OpenWFE::HashParticipant)
167
+ #
168
+ # hp = engine.register_participant(:charly, OpenWFE::HashParticipant)
169
+ # #...
170
+ # puts "there are currently #{hp.size} workitems for Charly"
171
+ #
172
+ # hp = OpenWFE::HashParticipant.new
173
+ # engine.register_participant("debbie", hp)
174
+ #
144
175
  class HashParticipant < Hash
145
176
  include StoreParticipantMixin
146
177
 
@@ -151,6 +182,15 @@ module OpenWFE
151
182
  # Implementation of a store participant stores the workitems in
152
183
  # yaml file in a dedicated directory.
153
184
  #
185
+ # It's quite easy to register a YamlParticipant :
186
+ #
187
+ # yp = engine.register_participant(:alex, YamlParticipant)
188
+ #
189
+ # puts yp.dirname
190
+ #
191
+ # should yield "./work/participants/alex/" (if the key :work_directory
192
+ # in engine.application_context is unset)
193
+ #
154
194
  class YamlParticipant < YamlFileStorage
155
195
  include StoreParticipantMixin
156
196
 
@@ -163,14 +203,14 @@ module OpenWFE
163
203
  #
164
204
  def initialize (dirname, application_context)
165
205
 
206
+ workdir = application_context[:work_directory]
207
+ workdir = OpenWFE::DEFAULT_WORK_DIRECTORY unless workdir
208
+
166
209
  @dirname = OpenWFE::ensure_for_filename(dirname.to_s)
167
210
 
168
211
  service_name = @self.class.name + "__" + @dirname
169
212
 
170
- path =
171
- application_context[:work_directory] +
172
- "/participants/" +
173
- @dirname
213
+ path = workdir + "/participants/" + @dirname
174
214
 
175
215
  super(service_name, application_context, path)
176
216
  end
@@ -11,7 +11,7 @@ require 'test/unit'
11
11
  #require 'pp'
12
12
 
13
13
  require 'openwfe/workitem'
14
- require 'openwfe/participants/csvparticipant'
14
+ require 'openwfe/participants/csvparticipants'
15
15
 
16
16
  #require 'rutest_utils'
17
17
 
@@ -11,7 +11,7 @@ require 'openwfe/workitem'
11
11
  require 'openwfe/engine/engine'
12
12
  require 'openwfe/expressions/raw_prog'
13
13
  require 'openwfe/participants/participants'
14
- require 'openwfe/participants/enoparticipant'
14
+ require 'openwfe/participants/enoparticipants'
15
15
  require 'flowtestbase'
16
16
 
17
17
  include OpenWFE
@@ -8,9 +8,10 @@
8
8
  #
9
9
 
10
10
  require 'test/unit'
11
+ require 'rutest_utils'
11
12
  require 'openwfe/workitem'
12
13
  require 'openwfe/flowexpressionid'
13
- require 'openwfe/rudefinitions'
14
+ #require 'openwfe/rudefinitions'
14
15
 
15
16
 
16
17
  class FeiTest < Test::Unit::TestCase
@@ -132,20 +133,6 @@ class FeiTest < Test::Unit::TestCase
132
133
 
133
134
  protected
134
135
 
135
- def new_fei ()
136
- fei = OpenWFE::FlowExpressionId.new()
137
- fei.owfe_version = OpenWFE::OPENWFERU_VERSION
138
- fei.engine_id = 'this'
139
- fei.initial_engine_id = 'that'
140
- fei.workflow_definition_url = 'http://test/test.xml'
141
- fei.workflow_definition_name = 'test'
142
- fei.workflow_definition_revision = '1.0'
143
- fei.workflow_instance_id = '123456'
144
- fei.expression_name = 'do-test'
145
- fei.expression_id = '0.0'
146
- return fei
147
- end
148
-
149
136
  def puts_hash (h)
150
137
  puts
151
138
  h.each do |k, v|
@@ -45,7 +45,7 @@ module FlowTestBase
45
45
 
46
46
  def setup
47
47
 
48
- @engine = eval("#{$WORKFLOW_ENGINE_CLASS}").new()
48
+ @engine = $WORKFLOW_ENGINE_CLASS.new()
49
49
 
50
50
  @tracer = Tracer.new
51
51
  @engine.application_context["__tracer"] = @tracer
@@ -102,7 +102,11 @@ module FlowTestBase
102
102
 
103
103
  # register unique tracing participant
104
104
 
105
- li = OpenWFE::LaunchItem.new(flowDef)
105
+ li = if flowDef.kind_of? OpenWFE::LaunchItem
106
+ flowDef
107
+ else
108
+ OpenWFE::LaunchItem.new(flowDef)
109
+ end
106
110
 
107
111
  @engine.launch(li)
108
112
 
@@ -388,5 +388,36 @@ toto
388
388
  toto""")
389
389
  end
390
390
 
391
+
392
+ #
393
+ # Test 11
394
+ #
395
+
396
+ class TestDefinition11 < ProcessDefinition
397
+ def make
398
+ sequence do
399
+ [ :b, :b, :b ].each do |p|
400
+ participant p
401
+ end
402
+ participant "b"
403
+ end
404
+ end
405
+ end
406
+
407
+ #def xxxx_ppd_11
408
+ def test_ppd_11
409
+
410
+ @engine.register_participant(:b) do |workitem|
411
+ @tracer << "b\n"
412
+ end
413
+
414
+ dotest(
415
+ TestDefinition11,
416
+ """b
417
+ b
418
+ b
419
+ b""")
420
+ end
421
+
391
422
  end
392
423
 
@@ -9,7 +9,7 @@
9
9
 
10
10
  require 'openwfe/expressions/raw_prog'
11
11
  require 'openwfe/participants/participants'
12
- require 'openwfe/participants/enoparticipant'
12
+ require 'openwfe/participants/enoparticipants'
13
13
  require 'flowtestbase'
14
14
 
15
15
 
@@ -7,6 +7,7 @@
7
7
  # Mon Oct 9 22:19:44 JST 2006
8
8
  #
9
9
 
10
+ require 'openwfe/def'
10
11
  require 'flowtestbase'
11
12
 
12
13
 
@@ -19,6 +20,10 @@ class FlowTest14b < Test::Unit::TestCase
19
20
  #def teardown
20
21
  #end
21
22
 
23
+
24
+ #
25
+ # TEST 0
26
+
22
27
  def test_subprocess_ref_0
23
28
  #def xxxx_subprocess_ref_0
24
29
  dotest(\
@@ -37,5 +42,74 @@ class FlowTest14b < Test::Unit::TestCase
37
42
  ABC''')
38
43
  end
39
44
 
45
+
46
+ #
47
+ # TEST 1
48
+
49
+ class SubTest1 < OpenWFE::ProcessDefinition
50
+ def make
51
+
52
+ sub1 "toto", :a => "A"
53
+
54
+ process_definition :name => :sub1 do
55
+ _print "${0} ${a}"
56
+ end
57
+ end
58
+ end
59
+
60
+ #def xxxx_sub_1
61
+ def test_sub_1
62
+ dotest(SubTest1, "toto A")
63
+ end
64
+
65
+
66
+ #
67
+ # TEST 1b
68
+
69
+ def test_subprocess_ref_1b
70
+ #def xxxx_subprocess_ref_1b
71
+ dotest(\
72
+ '''<process-definition name="subtest0" revision="0">
73
+
74
+ <sequence>
75
+ <subprocess ref="sub0" a="A">zero</subprocess>
76
+ <sub0 a="A">rei</sub0>
77
+ </sequence>
78
+
79
+ <process-definition name="sub0">
80
+ <print>${0} ${a}</print>
81
+ </process-definition>
82
+
83
+ </process-definition>''',
84
+ """zero A
85
+ rei A""")
86
+ end
87
+
88
+
89
+ #
90
+ # TEST 2
91
+
92
+ class SubTest2 < OpenWFE::ProcessDefinition
93
+ def make
94
+
95
+ sequence do
96
+ sub1 do
97
+ "a"
98
+ end
99
+ sub1 "c", "d"
100
+ end
101
+
102
+ process_definition :name => :sub1 do
103
+ _print "${0} ${1}"
104
+ end
105
+ end
106
+ end
107
+
108
+ #def xxxx_sub_2
109
+ def test_sub_2
110
+ dotest(SubTest2, """a
111
+ c d""")
112
+ end
113
+
40
114
  end
41
115