openwferu 0.9.6 → 0.9.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. data/bin/validate-workflow.rb +1 -0
  2. data/examples/openwferu.rb +57 -0
  3. data/lib/openwfe/contextual.rb +2 -0
  4. data/lib/openwfe/engine/engine.rb +109 -17
  5. data/lib/openwfe/engine/file_persisted_engine.rb +11 -1
  6. data/lib/openwfe/exceptions.rb +53 -0
  7. data/lib/openwfe/expool/expressionpool.rb +195 -137
  8. data/lib/openwfe/expool/journal.rb +175 -0
  9. data/lib/openwfe/expool/journal_replay.rb +121 -0
  10. data/lib/openwfe/expool/wfidgen.rb +318 -0
  11. data/lib/openwfe/expool/yamlexpstorage.rb +23 -54
  12. data/lib/openwfe/expressions/condition.rb +14 -2
  13. data/lib/openwfe/expressions/environment.rb +47 -37
  14. data/lib/openwfe/expressions/expressionmap.rb +73 -67
  15. data/lib/openwfe/expressions/fe_cancel.rb +2 -0
  16. data/lib/openwfe/expressions/fe_concurrence.rb +14 -1
  17. data/lib/openwfe/expressions/fe_cron.rb +186 -0
  18. data/lib/openwfe/expressions/fe_cursor.rb +6 -0
  19. data/lib/openwfe/expressions/fe_define.rb +2 -0
  20. data/lib/openwfe/expressions/fe_fqv.rb +2 -0
  21. data/lib/openwfe/expressions/fe_iterator.rb +2 -0
  22. data/lib/openwfe/expressions/fe_losfor.rb +4 -0
  23. data/lib/openwfe/expressions/fe_misc.rb +16 -1
  24. data/lib/openwfe/expressions/fe_participant.rb +7 -0
  25. data/lib/openwfe/expressions/fe_raw.rb +125 -8
  26. data/lib/openwfe/expressions/fe_sequence.rb +2 -0
  27. data/lib/openwfe/expressions/fe_sleep.rb +213 -0
  28. data/lib/openwfe/expressions/fe_subprocess.rb +2 -0
  29. data/lib/openwfe/expressions/fe_value.rb +8 -0
  30. data/lib/openwfe/expressions/fe_when.rb +205 -0
  31. data/lib/openwfe/expressions/flowexpression.rb +62 -9
  32. data/lib/openwfe/expressions/raw_prog.rb +147 -45
  33. data/lib/openwfe/expressions/raw_xml.rb +50 -5
  34. data/lib/openwfe/expressions/timeout.rb +32 -5
  35. data/lib/openwfe/flowexpressionid.rb +6 -4
  36. data/lib/openwfe/listeners/listeners.rb +4 -3
  37. data/lib/openwfe/listeners/socketlisteners.rb +30 -4
  38. data/lib/openwfe/logging.rb +9 -1
  39. data/lib/openwfe/participants/participants.rb +9 -9
  40. data/lib/openwfe/participants/socketparticipants.rb +41 -8
  41. data/lib/openwfe/rudefinitions.rb +21 -0
  42. data/lib/openwfe/storage/yamlextras.rb +115 -0
  43. data/lib/openwfe/storage/yamlfilestorage.rb +23 -4
  44. data/lib/openwfe/util/csvtable.rb +76 -6
  45. data/lib/openwfe/util/dollar.rb +5 -0
  46. data/lib/openwfe/util/kotoba.rb +236 -0
  47. data/lib/openwfe/util/ometa.rb +64 -0
  48. data/lib/openwfe/util/safe.rb +2 -0
  49. data/lib/openwfe/util/scheduler.rb +58 -11
  50. data/lib/openwfe/utils.rb +27 -0
  51. data/lib/openwfe/version.rb +1 -1
  52. data/lib/openwfe/worklist/storeparticipant.rb +2 -3
  53. data/test/csv_test.rb +57 -0
  54. data/test/expmap_test.rb +54 -0
  55. data/test/file_persistence_test.rb +9 -9
  56. data/test/flowtestbase.rb +19 -1
  57. data/test/ft_11_ppd.rb +18 -0
  58. data/test/ft_15_iterator.rb +27 -0
  59. data/test/ft_23b_when.rb +2 -2
  60. data/test/ft_27_getflowpos.rb +19 -9
  61. data/test/ft_29_httprb.rb +31 -2
  62. data/test/ft_30_socketlistener.rb +3 -5
  63. data/test/ft_31_flowname.rb +40 -0
  64. data/test/ft_32_journal.rb +60 -0
  65. data/test/ft_33_description.rb +100 -0
  66. data/test/ft_34_cancelwfid.rb +69 -0
  67. data/test/ft_35_localdefs.rb +63 -0
  68. data/test/ft_7_lose.rb +0 -61
  69. data/test/ft_7b_lose.rb +85 -0
  70. data/test/ft_tests.rb +49 -0
  71. data/test/kotoba_test.rb +72 -0
  72. data/test/misc_test.rb +4 -12
  73. data/test/param_test.rb +284 -0
  74. data/test/rake_qtest.rb +13 -35
  75. data/test/rake_test.rb +2 -3
  76. data/test/raw_prog_test.rb +9 -7
  77. data/test/restart_cron_test.rb +9 -5
  78. data/test/restart_sleep_test.rb +104 -0
  79. data/test/restart_tests.rb +15 -0
  80. data/test/restart_when_test.rb +105 -0
  81. data/test/scheduler_test.rb +2 -2
  82. data/test/sec_test.rb +163 -0
  83. data/test/wfid_test.rb +69 -13
  84. metadata +31 -16
  85. data/lib/openwfe/expressions/fe_time.rb +0 -454
  86. data/test/restart_test.rb +0 -79
@@ -10,6 +10,7 @@
10
10
  require 'net/http'
11
11
  require 'optparse'
12
12
  require 'uri'
13
+
13
14
  # From the gems archive
14
15
  require 'rubygems'
15
16
  require 'xml/libxml'
@@ -0,0 +1,57 @@
1
+
2
+ require 'rubygems'
3
+ require 'openwfe/def'
4
+ require 'openwfe/workitem'
5
+ require 'openwfe/engine/engine'
6
+
7
+ #
8
+ # instantiating an engine
9
+
10
+ engine = OpenWFE::Engine.new
11
+
12
+ #
13
+ # adding some participants
14
+
15
+ engine.register_participant :alice do |workitem|
16
+ puts "alice got a workitem..."
17
+ workitem.alice_comment = "this thing looks interesting"
18
+ end
19
+
20
+ engine.register_participant :bob do |workitem|
21
+ puts "bob got a workitem..."
22
+ workitem.bob_comment = "not for me, I prefer VB"
23
+ workitem.bob_comment2 = "Bob rules"
24
+ end
25
+
26
+ engine.register_participant :summarize do |workitem|
27
+ puts
28
+ puts "summary of process #{workitem.fei.workflow_instance_id}"
29
+ workitem.attributes.each do |k, v|
30
+ next unless k.match ".*_comment$"
31
+ puts " - #{k} : '#{v}'"
32
+ end
33
+ end
34
+
35
+ #
36
+ # a process definition
37
+
38
+ class TheProcessDefinition0 < OpenWFE::ProcessDefinition
39
+ def make
40
+ sequence do
41
+ concurrence do
42
+ participant :alice
43
+ participant :bob
44
+ end
45
+ participant :summarize
46
+ end
47
+ end
48
+ end
49
+
50
+ #
51
+ # launching the process
52
+
53
+ li = OpenWFE::LaunchItem.new(TheProcessDefinition0)
54
+
55
+ li.initial_comment = "please give your impressions about http://ruby-lang.org"
56
+
57
+ engine.launch(li)
@@ -50,6 +50,8 @@ module OpenWFE
50
50
 
51
51
  attr_accessor :application_context
52
52
 
53
+ alias :ac :application_context
54
+
53
55
  #
54
56
  # Looks up something in the application context, if the given
55
57
  # key is a class, then the first value in the context of that
@@ -47,6 +47,7 @@ require 'openwfe/rudefinitions'
47
47
  require 'openwfe/service'
48
48
  require 'openwfe/util/scheduler'
49
49
  require 'openwfe/util/schedulers'
50
+ require 'openwfe/expool/wfidgen'
50
51
  require 'openwfe/expool/expressionpool'
51
52
  require 'openwfe/expool/expstorage'
52
53
  require 'openwfe/expressions/expressionmap'
@@ -82,20 +83,41 @@ module OpenWFE
82
83
 
83
84
  build_expression_map()
84
85
 
86
+ build_wfid_generator()
85
87
  build_expression_pool()
86
88
  build_expression_storage()
87
89
 
88
90
  build_participant_map()
89
91
 
90
- #
91
- # engine components are ready for operation, it's time to
92
- # check persisted expressions (if any) to see if something
93
- # has to be rescheduled (like a long time sleep expression or
94
- # a cron)
92
+ #get_expression_pool.reschedule()
93
+
94
+ linfo { "new() --- engine started --- #{self.object_id}" }
95
+ end
95
96
 
97
+ #
98
+ # Call this method once the participant for a persisted engine
99
+ # have been [re]added.
100
+ # If you call this method too soon, missing participants will
101
+ # cause troubles... Call this method after all the participants
102
+ # have been added.
103
+ #
104
+ def reschedule
96
105
  get_expression_pool.reschedule()
106
+ end
97
107
 
98
- linfo { "new() --- engine started --- #{self.object_id}" }
108
+ alias :reload :reschedule
109
+
110
+ #
111
+ # When 'parameters' are used at the top of a process definition, this
112
+ # method can be used to assert a launchitem before launch.
113
+ # An expression will get raised if the parameters do not match the
114
+ # requirements.
115
+ #
116
+ # Note that the launch method will raise those exceptions as well.
117
+ # This method can be useful in some scenarii though.
118
+ #
119
+ def pre_launch_check (launchitem)
120
+ get_expression_pool.prepare_raw_expression(launchitem)
99
121
  end
100
122
 
101
123
  #
@@ -137,16 +159,6 @@ module OpenWFE
137
159
  get_expression_pool.launch(launchitem, async)
138
160
  end
139
161
 
140
- #
141
- # Returns the list of applied expressions belonging to a given
142
- # workflow instance.
143
- # May be used to determine where a process instance currently is.
144
- #
145
- def get_flow_position (workflow_instance_id)
146
-
147
- get_expression_pool.get_flow_position(workflow_instance_id)
148
- end
149
-
150
162
  #
151
163
  # This method is used to feed a workitem back to the engine (after
152
164
  # it got sent to a worklist or wherever by a participant).
@@ -282,8 +294,11 @@ module OpenWFE
282
294
  linfo { "stop() stopping engine '#{@service_name}'" }
283
295
 
284
296
  @application_context.each do |name, service|
297
+
285
298
  next if name == self.service_name
299
+
286
300
  #service.stop if service.respond_to? :stop
301
+
287
302
  if service.kind_of? ServiceMixin
288
303
  service.stop
289
304
  linfo do
@@ -294,6 +309,67 @@ module OpenWFE
294
309
  end
295
310
  end
296
311
 
312
+ #
313
+ # METHODS FROM THE EXPRESSION POOL
314
+ #
315
+ # These methods are 'proxy' to method found in the expression pool.
316
+ # They are made available here for a simpler model.
317
+ #
318
+
319
+ #
320
+ # Returns the list of applied expressions belonging to a given
321
+ # workflow instance.
322
+ # May be used to determine where a process instance currently is.
323
+ #
324
+ def get_flow_position (workflow_instance_id)
325
+ get_expression_pool.get_flow_position(workflow_instance_id)
326
+ end
327
+ alias :get_process_position :get_flow_position
328
+
329
+ #
330
+ # Lists all workflows (processes) currently in the expool (in
331
+ # the engine).
332
+ # This method will return a list of "process-definition" expressions
333
+ # (root of flows).
334
+ #
335
+ # If consider_subprocesses is set to true, "process-definition"
336
+ # expressions of subprocesses will be returned as well.
337
+ #
338
+ # "wfid_prefix" allows your to query for specific workflow instance
339
+ # id prefixes.
340
+ #
341
+ def list_workflows (consider_subprocesses=false, wfid_prefix=nil)
342
+
343
+ get_expression_pool.list_workflows(
344
+ consider_subprocesses, wfid_prefix)
345
+ end
346
+ alias :list_processes :list_workflows
347
+
348
+ #
349
+ # Given any expression of a process, cancels the complete process
350
+ # instance.
351
+ #
352
+ def cancel_flow (exp_or_wfid)
353
+ get_expression_pool.cancel_flow(exp_or_wfid)
354
+ end
355
+ alias :cancel_process :cancel_flow
356
+
357
+ #
358
+ # Cancels the given expression (and its children if any)
359
+ # (warning : advanced method)
360
+ #
361
+ def cancel_expression (exp_or_fei)
362
+ get_expression_pool.cancel(exp_or_fei)
363
+ end
364
+
365
+ #
366
+ # Forgets the given expression (make it an orphan)
367
+ # (warning : advanced method)
368
+ #
369
+ def forget_expression (exp_or_fei)
370
+ get_expression_pool.forget(exp_or_fei)
371
+ end
372
+
297
373
  protected
298
374
 
299
375
  #
@@ -303,7 +379,23 @@ module OpenWFE
303
379
 
304
380
  def build_expression_map ()
305
381
 
306
- init_service(S_EXPRESSION_MAP, ExpressionMap)
382
+ @application_context[S_EXPRESSION_MAP] = ExpressionMap.new
383
+ #
384
+ # the expression map is not a Service anymore,
385
+ # it's a simple instance (that will be reused in other
386
+ # OpenWFEru components)
387
+
388
+ #ldebug do
389
+ # "build_expression_map() :\n" +
390
+ # get_expression_map.to_s
391
+ #end
392
+ end
393
+
394
+ def build_wfid_generator ()
395
+
396
+ #init_service(S_WFID_GENERATOR, DefaultWfidGenerator)
397
+ #init_service(S_WFID_GENERATOR, UuidWfidGenerator)
398
+ init_service(S_WFID_GENERATOR, KotobaWfidGenerator)
307
399
  end
308
400
 
309
401
  def build_expression_pool ()
@@ -47,7 +47,12 @@ require 'openwfe/expool/yamlexpstorage'
47
47
  module OpenWFE
48
48
 
49
49
  #
50
- # An engine persisted to a tree of yaml files
50
+ # An engine persisted to a tree of yaml files.
51
+ #
52
+ # Remember that once you have added the participants to a persisted
53
+ # engine, you should call its reload method, to reschedule expressions
54
+ # like 'sleep', 'cron', ... But if you do it before registering the
55
+ # participants you'll end up with broken processes.
51
56
  #
52
57
  class FilePersistedEngine < Engine
53
58
 
@@ -68,6 +73,11 @@ module OpenWFE
68
73
  #
69
74
  # An engine with a cache in front of its file persisted expression storage.
70
75
  #
76
+ # Remember that once you have added the participants to a persisted
77
+ # engine, you should call its reload method, to reschedule expressions
78
+ # like 'sleep', 'cron', ... But if you do it before registering the
79
+ # participants you'll end up with broken processes.
80
+ #
71
81
  class CachedFilePersistedEngine < Engine
72
82
 
73
83
  protected
@@ -0,0 +1,53 @@
1
+ #
2
+ #--
3
+ # Copyright (c) 2007, John Mettraux, OpenWFE.org
4
+ # All rights reserved.
5
+ #
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted provided that the following conditions are met:
8
+ #
9
+ # . Redistributions of source code must retain the above copyright notice, this
10
+ # list of conditions and the following disclaimer.
11
+ #
12
+ # . Redistributions in binary form must reproduce the above copyright notice,
13
+ # this list of conditions and the following disclaimer in the documentation
14
+ # and/or other materials provided with the distribution.
15
+ #
16
+ # . Neither the name of the "OpenWFE" nor the names of its contributors may be
17
+ # used to endorse or promote products derived from this software without
18
+ # specific prior written permission.
19
+ #
20
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
+ # POSSIBILITY OF SUCH DAMAGE.
31
+ #++
32
+ #
33
+ # $Id: workitem.rb 3555 2006-11-13 00:47:53Z jmettraux $
34
+ #
35
+
36
+ #
37
+ # Made in Japan
38
+ #
39
+ # john.mettraux@openwfe.org
40
+ #
41
+
42
+
43
+ module OpenWFE
44
+
45
+ #
46
+ # The exception thrown at launch time, when there are parameter missing
47
+ # or whose value isn't matching what is required.
48
+ #
49
+ class ParameterException < Exception
50
+ end
51
+
52
+ end
53
+