cpee 2.1.136 → 2.1.140

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/cockpit/compliance-view.html +0 -7
  3. data/cockpit/compliance.html +0 -7
  4. data/cockpit/css/ui.css +1 -1
  5. data/cockpit/edit.html +0 -7
  6. data/cockpit/graph.html +0 -5
  7. data/cockpit/index.html +0 -7
  8. data/cockpit/js/instance.js +27 -4
  9. data/cockpit/js/llm.js +79 -21
  10. data/cockpit/js/wfadaptor.js +10 -4
  11. data/cockpit/llm.html +0 -7
  12. data/cockpit/llmmodel.html +0 -7
  13. data/cockpit/model.html +0 -7
  14. data/cockpit/only_llm.html +0 -7
  15. data/cockpit/themes/THEMES.MD +4 -0
  16. data/cockpit/themes/presetlr/symbols/loop_end_pre.svg +1 -1
  17. data/cockpit/track.html +0 -5
  18. data/cpee.gemspec +2 -2
  19. data/lib/cpee/implementation.rb +5 -0
  20. data/lib/cpee/implementation_callbacks.rb +2 -2
  21. data/lib/cpee/implementation_notifications.rb +4 -1
  22. data/lib/cpee/implementation_properties.rb +63 -19
  23. data/lib/cpee/json_pointer.rb +110 -0
  24. data/lib/cpee/message.rb +22 -2
  25. data/lib/cpee/persistence.rb +4 -0
  26. data/lib/cpee/redis.rb +8 -0
  27. data/lib/properties/t_dslx.rng +11 -1
  28. data/lib/properties.xml +4 -7
  29. data/server/executionhandlers/eval/connection.rb +12 -3
  30. data/server/executionhandlers/ruby/connection.rb +12 -3
  31. data/server/executionhandlers/ruby/controller.rb +17 -2
  32. data/server/routing/end.pid +1 -1
  33. data/server/routing/forward-events-00.pid +1 -1
  34. data/server/routing/forward-events.rb +30 -19
  35. data/server/routing/forward-votes.pid +1 -1
  36. data/server/routing/forward-votes.rb +56 -43
  37. data/server/routing/persist.pid +1 -1
  38. data/server/routing/persist.rb +49 -28
  39. metadata +8 -2
  40. data/cockpit/js/build-bpmn2.js +0 -302
@@ -24,16 +24,11 @@
24
24
 
25
25
  <!-- libs, do not modify. When local than load local libs. -->
26
26
  <script type="text/javascript" src="/js_libs/jquery.min.js"></script>
27
- <script type="text/javascript" src="/js_libs/jquery.browser.js"></script>
28
- <script type="text/javascript" src="/js_libs/jquery.svg.min.js"></script>
29
- <script type="text/javascript" src="/js_libs/jquery.svgdom.min.js"></script>
30
- <script type="text/javascript" src="/js_libs/vkbeautify.js"></script>
31
27
  <script type="text/javascript" src="/js_libs/uidash_util.js"></script>
32
28
  <script type="text/javascript" src="/js_libs/printf.js"></script>
33
29
  <script type="text/javascript" src="/js_libs/strftime.min.js"></script>
34
30
  <script type="text/javascript" src="/js_libs/parsequery.js"></script>
35
31
  <script type="text/javascript" src="/js_libs/underscore.min.js"></script>
36
- <script type="text/javascript" src="/js_libs/jquery.caret.min.js"></script>
37
32
  <script type="text/javascript" src="/js_libs/jquery.cookie.js"></script>
38
33
 
39
34
  <script type="text/javascript" src="/js_libs/relaxngui.js"></script>
@@ -41,8 +36,6 @@
41
36
  <script type="text/javascript" src="/js_libs/uidash.js"></script>
42
37
  <script type="text/javascript" src="/js_libs/uidash_custommenu.js"></script>
43
38
 
44
- <script type="text/javascript" src="js/build-bpmn2.js"></script>
45
-
46
39
  <link rel="stylesheet" href="/js_libs/uidash_custommenu.css" type="text/css"/>
47
40
  <link rel="stylesheet" href="/js_libs/uidash.css" type="text/css"/>
48
41
 
@@ -173,6 +173,9 @@ noted; unset booleans behave as `false`/absent.
173
173
  | `info` | `function(node) → {attrName: value, ...}` | Extra HTML attributes stamped onto the drawn element (e.g. `element-endpoint`, `element-alt_id`), consumed later for lookups/menu icon rendering. |
174
174
  | `final` | `true` | Marks this element as a true dead-end (used by `terminate`) — downstream connection logic skips drawing anything past a `final` endpoint. |
175
175
  | `rotatelabels` | `true \| false` | Per-element opt-out/opt-in for the manifestation-level `rotated_labels` flag. |
176
+ | `mark_position` | `'left' \| 'right'` | Corner of the icon where the engine puts the hover/mark marker (the circle with the checkmark), top left by default. Use `'right'` when the icon's label is on its left, e.g. presetlr's `loop_finish`. |
177
+ | `implied` | `{ type, x, y }` | The icon also draws another symbol in a neighbouring cell, `x`/`y` cells away in the icon's own coordinates (lr mirrors the icon, the engine accounts for it). It changes nothing in the drawing, but `get_svg_metrics` records a symbol of that `type` (with the icon's `eid`) there, unless a real symbol is in that cell. E.g. `parallel_branch_event` draws the start circle of the branch: `{ type: 'event_start', x: 1 }`, presetlr below the signal with `y: 1`. |
178
+ | `hidelabel` | `true \| false` | The label is drawn invisible (`.label.invisible`), but still takes its space, e.g. presetlr's `loop_tail` uses the condition only to make the outgoing arrow as long as the label. It is not in the metrics (`get_svg_metrics`). |
176
179
  | `noindent` | `true` | Per-element opt-out of the default indent-first-column behavior in horizontal expansions. |
177
180
 
178
181
  `border: 'structural'` is the mechanism built for subprocesses. When an element's `border` is
@@ -348,6 +351,7 @@ one-off tweaks, e.g. `style="fill:none;"`).
348
351
  | `.label` (on `<text>`) | The node label text style. Put this on the `<text>` inside `part-middle`; leave its content empty, it's filled in at render time. |
349
352
  | `.label.standalone` | Adds a background-colored outline stroke behind the label text (for readability over busy backgrounds) — used e.g. on `loop.svg`'s inline label. |
350
353
  | `.label.rotate` | Applied automatically when the manifestation's `rotated_labels`/an element's `rotatelabels` is active. |
354
+ | `.label.invisible` | Applied automatically when an element's `hidelabel` is set; `visibility: hidden`, so the label keeps its space. |
351
355
  | `.duration` | Stroke color for duration-annotation strokes. |
352
356
  | `.super` / `tspan.exec` / `.active` / `.vote` / `.colon` / `.necessary` | The small execution-count indicator (`▶ 0,0`) appended automatically above every icon unless `addition` is suppressed at draw time. |
353
357
  | `.stripe.even` / `.stripe.odd` | Alternating row backgrounds, only drawn when the manifestation sets `this.striped = true`. |
@@ -10,6 +10,6 @@
10
10
  <line x1="10.5" y1="10.5" x2="20.5" y2="20.5" class="stand"/>
11
11
  </g>
12
12
  <g class="part-middle">
13
- <text transform="translate(0,49)" class="label standalone"></text>
13
+ <text transform="translate(3,49)" class="label standalone"></text>
14
14
  </g>
15
15
  </svg>
data/cockpit/track.html CHANGED
@@ -23,16 +23,11 @@
23
23
 
24
24
  <!-- libs, do not modify. When local than load local libs. -->
25
25
  <script type="text/javascript" src="/js_libs/jquery.min.js"></script>
26
- <script type="text/javascript" src="/js_libs/jquery.browser.js"></script>
27
- <script type="text/javascript" src="/js_libs/jquery.svg.min.js"></script>
28
- <script type="text/javascript" src="/js_libs/jquery.svgdom.min.js"></script>
29
- <script type="text/javascript" src="/js_libs/vkbeautify.js"></script>
30
26
  <script type="text/javascript" src="/js_libs/uidash_util.js"></script>
31
27
  <script type="text/javascript" src="/js_libs/printf.js"></script>
32
28
  <script type="text/javascript" src="/js_libs/strftime.min.js"></script>
33
29
  <script type="text/javascript" src="/js_libs/parsequery.js"></script>
34
30
  <script type="text/javascript" src="/js_libs/underscore.min.js"></script>
35
- <script type="text/javascript" src="/js_libs/jquery.caret.min.js"></script>
36
31
  <script type="text/javascript" src="/js_libs/jquery.cookie.js"></script>
37
32
 
38
33
  <script type="text/javascript" src="/js_libs/relaxngui.js"></script>
data/cpee.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "cpee"
3
- s.version = "2.1.136"
3
+ s.version = "2.1.140"
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.license = "LGPL-3.0-or-later"
6
6
  s.summary = "The cloud process execution engine (cpee.org). If you just need workflow execution, without a rest service exposing it, then use WEEL."
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
21
21
  s.email = 'juergen.mangler@gmail.com'
22
22
  s.homepage = 'http://cpee.org/'
23
23
 
24
- s.add_runtime_dependency 'riddl', '~> 1.0'
24
+ s.add_runtime_dependency 'riddl', '~> 1.0', '>= 1.0.21'
25
25
  s.add_runtime_dependency 'weel', '~> 1.99', '>= 1.99.158'
26
26
  s.add_runtime_dependency 'highline', '~> 2.0'
27
27
  s.add_runtime_dependency 'redis', '~> 5.4'
@@ -466,6 +466,11 @@ module CPEE
466
466
  @status = 404
467
467
  return
468
468
  end
469
+ # only ready, stopped, finished, abandoned; a running controller would keep writing into expiring keys
470
+ if opts[:statemachine].readonly? id
471
+ @status = 423
472
+ return
473
+ end
469
474
 
470
475
  content = {
471
476
  :state => 'purged',
@@ -160,7 +160,7 @@ module CPEE
160
160
  opts[:redis]
161
161
  )
162
162
  elsif CPEE::Persistence::extract_item(id,opts,"callbacks/#{callback}/type") == 'vote'
163
- if @p.length == 1 && @p[0].name == 'continue' && @p[0].class == Riddl::Parameter::Simple
163
+ if @p.length == 1 && (@p[0].name == 'continue' || (@p[0].name == '' && @p[0].class == Riddl::Parameter::Complex))
164
164
  CPEE::Message::send(
165
165
  :'vote-response',
166
166
  callback,
@@ -168,7 +168,7 @@ module CPEE
168
168
  id,
169
169
  {},
170
170
  {},
171
- @p[0].value,
171
+ @p[0].class == Riddl::Parameter::Simple ? @p[0].value : @p[0].value.read,
172
172
  opts[:redis]
173
173
  )
174
174
  else
@@ -201,7 +201,10 @@ module CPEE
201
201
  if pat == 'forward:*'
202
202
  id, key = what.match(/forward:([^\/]+)\/(.+)/).captures
203
203
  if sse = opts.dig(:sse_connections,id,key)
204
- sse.send message
204
+ # message is "seq,sseq {json}"; numbers go into the standard SSE id field (lastEventId), data stays pure json
205
+ # riddl's send_with_id(field,value) writes "field: value\n\n", so id and data are combined into one event
206
+ index = message.index(' ')
207
+ sse.send_with_id 'id', message[0...index] + "\ndata: " + message[index+1..-1]
205
208
  else
206
209
  DeleteSubscription::set(id,opts,key)
207
210
  end
@@ -310,10 +310,29 @@ module CPEE
310
310
  end
311
311
  end #}}}
312
312
  class PutStatus < Riddl::Implementation #{{{
313
+ EXPOSITION_ONLY = 18510501 # status id that only carries expositions, the status stays as it is
314
+
313
315
  def self::set(id,opts,xml)
314
316
  doc = XML::Smart::string(xml)
315
317
  doc.register_namespace 'p', 'http://cpee.org/ns/properties/2.0'
316
- CPEE::Persistence::set_item(id,opts,'status',:id => doc.find('string(/p:status/p:id)').to_i, :message => doc.find('string(/p:status/p:message)'))
318
+ sid = doc.find('string(/p:status/p:id)').to_i
319
+ return if sid == EXPOSITION_ONLY
320
+ CPEE::Persistence::set_item(id,opts,'status',:id => sid, :message => doc.find('string(/p:status/p:message)'))
321
+ end
322
+
323
+ def self::expositions(id,opts,expositions) # [[info,body],...]
324
+ return if expositions.empty?
325
+ attrs = CPEE::Persistence::extract_list(id,opts,'attributes').to_h
326
+ change_uuid = CPEE::Persistence::extract_item(id,opts,'dslx/@change_uuid')
327
+ expositions.each do |info,body|
328
+ content = {
329
+ :change_uuid => change_uuid,
330
+ :exposition => body,
331
+ :info => info,
332
+ :attributes => attrs
333
+ }
334
+ CPEE::Message::send(:event,'description/exposition',File.join(opts[:url],'/'),id,attrs['uuid'],attrs['info'],content,opts[:redis])
335
+ end
317
336
  end
318
337
 
319
338
  def response
@@ -324,7 +343,16 @@ module CPEE
324
343
  elsif opts[:statemachine].final? id
325
344
  @status = 410
326
345
  else
346
+ begin
347
+ expositions = @p[1..-1].each_slice(2).map do |info,body|
348
+ [JSON.parse(info.value.read), body.value.read]
349
+ end
350
+ rescue JSON::ParserError => e
351
+ @status = 400
352
+ return Riddl::Parameter::Complex.new('error','text/plain','exposition_info is not valid JSON: ' + e.message)
353
+ end
327
354
  PutStatus::set id, opts, @p[0].value.read
355
+ PutStatus::expositions id, opts, expositions
328
356
  end
329
357
  nil
330
358
  end
@@ -532,6 +560,7 @@ module CPEE
532
560
  id = @a[2]
533
561
  opts = @a[3]
534
562
  if val = CPEE::Persistence::extract_item(id,opts,@r.join('/'))
563
+ mime = 'text/plain' if mime == 'text/xml' && (XML::Smart::string(val) rescue nil).nil? # a description can be any model type, e.g. text
535
564
  Riddl::Parameter::Complex.new(item,mime,val)
536
565
  else
537
566
  @status = 404
@@ -826,7 +855,24 @@ module CPEE
826
855
  end
827
856
  end #}}}
828
857
 
829
- def self::set(id,opts,xml,exposition=[],copy=false)
858
+ def self::backtransform_async(id,opts,dslx,tdslx,tdslxtype) #{{{
859
+ change_uuid = Digest::SHA1.hexdigest(dslx)
860
+ Thread.new do
861
+ attrs = CPEE::Persistence::extract_list(id,opts,'attributes').to_h
862
+ begin
863
+ description = PutDescription::backtransform(dslx,dslx,tdslx,tdslxtype)
864
+ unless description.nil?
865
+ CPEE::Message::send(:event,'description/sync',File.join(opts[:url],'/'),id,attrs['uuid'],attrs['info'],{ :change_uuid => change_uuid, :description => description },opts[:redis])
866
+ end
867
+ rescue => e # description stays as it is
868
+ puts e.message
869
+ puts e.backtrace
870
+ CPEE::Message::send(:event,'description/error',File.join(opts[:url],'/'),id,attrs['uuid'],attrs['info'],{ :message => 'backtransformation failed: ' + e.message, :change_uuid => change_uuid, :attributes => attrs },opts[:redis])
871
+ end
872
+ end
873
+ end #}}}
874
+
875
+ def self::set(id,opts,xml,copy=false)
830
876
  dslx, dsl, de, ep = if copy
831
877
  PutDescription::transform(
832
878
  xml,
@@ -854,14 +900,13 @@ module CPEE
854
900
  opts
855
901
  )
856
902
  end
857
- description = if copy
903
+ tdslx = CPEE::Persistence::extract_item(id,opts,'transformation/dslx')
904
+ tdslxtype = CPEE::Persistence::extract_item(id,opts,'transformation/dslx/@type')
905
+ description = if copy && tdslxtype == 'rest'
906
+ nil # slow (e.g. bpmn layout), done after storing, see backtransform_async
907
+ elsif copy
858
908
  begin
859
- PutDescription::backtransform(
860
- xml,
861
- dslx,
862
- CPEE::Persistence::extract_item(id,opts,'transformation/dslx'),
863
- CPEE::Persistence::extract_item(id,opts,'transformation/dslx/@type')
864
- )
909
+ PutDescription::backtransform(xml,dslx,tdslx,tdslxtype)
865
910
  rescue => e # dslx is stored anyway, description stays as it is
866
911
  puts e.message
867
912
  puts e.backtrace
@@ -878,22 +923,16 @@ module CPEE
878
923
  :description => description,
879
924
  :dslx => dslx,
880
925
  :change_uuid => change_uuid,
926
+ :change_pending => copy && tdslxtype == 'rest', # description follows with description/sync
881
927
  :dsl => dsl,
882
928
  :dataelements => CPEE::Persistence::extract_list(id,opts,'dataelements').to_h,
883
929
  :documents => dos,
884
930
  :endpoints => CPEE::Persistence::extract_list(id,opts,'endpoints').to_h,
885
931
  :attributes => attrs
886
932
  )
933
+ PutDescription::backtransform_async(id,opts,dslx,tdslx,tdslxtype) if copy && tdslxtype == 'rest'
887
934
  PatchItems::set_hash('dataelements',id,opts,de) unless de.empty?
888
935
  PatchItems::set_hash('endpoints',id,opts,ep) unless ep.empty?
889
- exposition.each do |exp|
890
- content = {
891
- :change_uuid => change_uuid,
892
- :exposition => exp.value.read,
893
- :attributes => attrs
894
- }
895
- CPEE::Message::send(:event,'description/exposition',File.join(opts[:url],'/'),id,attrs['uuid'],attrs['info'],content,opts[:redis])
896
- end
897
936
  end
898
937
 
899
938
  def self::validate(xml,opts) # dslx against t_dslx.rng, returns the errors
@@ -925,7 +964,7 @@ module CPEE
925
964
  return Riddl::Parameter::Complex.new('error','text/plain',errors.join("\n"))
926
965
  end
927
966
  begin
928
- PutDescription::set(id,opts,xml,@p[1..-1],copy)
967
+ PutDescription::set(id,opts,xml,copy)
929
968
  rescue => e
930
969
  puts e.message
931
970
  puts e.backtrace
@@ -962,6 +1001,8 @@ module CPEE
962
1001
  tdslxtype = (t = doc.find('string(/p:transformation/p:dslx/@type)')).empty? ? 'copy' : t # optional, missing means copy
963
1002
  changed = tdslx != (CPEE::Persistence::extract_item(id,opts,'transformation/dslx') || '') ||
964
1003
  tdslxtype != (CPEE::Persistence::extract_item(id,opts,'transformation/dslx/@type') || 'copy')
1004
+ dslx = CPEE::Persistence::extract_item(id,opts,'dslx')
1005
+ dslx = nil if dslx&.empty?
965
1006
  CPEE::Persistence::set_item(id,opts,'transformation',
966
1007
  :description => doc.find('string(/p:transformation/p:description)'),
967
1008
  :description_type => doc.find('string(/p:transformation/p:description/@type)'),
@@ -970,7 +1011,9 @@ module CPEE
970
1011
  :endpoints =>doc.find('string(/p:transformation/p:endpoints)'),
971
1012
  :endpoints_type => doc.find('string(/p:transformation/p:endpoints/@type)'),
972
1013
  :dslx => tdslx,
973
- :dslx_type => tdslxtype
1014
+ :dslx_type => tdslxtype,
1015
+ :change_uuid => dslx ? Digest::SHA1.hexdigest(dslx) : nil,
1016
+ :change_pending => backtrans && changed && tdslxtype == 'rest' && !dslx.nil? # description follows with description/sync
974
1017
  )
975
1018
  PutTransformation::backtransform(id,opts,tdslx,tdslxtype) if backtrans && changed
976
1019
  end
@@ -979,6 +1022,7 @@ module CPEE
979
1022
  # directly, as redis is only updated asynchronously by persist.rb
980
1023
  dslx = CPEE::Persistence::extract_item(id,opts,'dslx')
981
1024
  return if dslx.nil? || dslx.empty?
1025
+ return PutDescription::backtransform_async(id,opts,dslx,tdslx,tdslxtype) if tdslxtype == 'rest'
982
1026
  description = begin
983
1027
  PutDescription::backtransform(dslx,dslx,tdslx,tdslxtype)
984
1028
  rescue => e # description stays as it is
@@ -0,0 +1,110 @@
1
+ # This file is part of CPEE.
2
+ #
3
+ # CPEE is free software: you can redistribute it and/or modify it under the terms
4
+ # of the GNU Lesser General Public License as published by the Free Software Foundation,
5
+ # either version 3 of the License, or (at your option) any later version.
6
+ #
7
+ # CPEE is distributed in the hope that it will be useful, but WITHOUT ANY
8
+ # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
9
+ # PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
10
+ #
11
+ # You should have received a copy of the GNU Lesser General Public License along with
12
+ # CPEE (file LICENSE in the main directory). If not, see
13
+ # <http://www.gnu.org/licenses/>.
14
+
15
+ require 'ostruct'
16
+
17
+ module CPEE
18
+
19
+ module JSONPointer
20
+
21
+ def self::parse(pointer) #{{{
22
+ raise ArgumentError, "invalid JSON pointer #{pointer.inspect}" unless pointer.is_a?(String) && pointer.start_with?('/')
23
+ pointer[1..-1].split('/',-1).map { |s| s.gsub('~1','/').gsub('~0','~') }
24
+ end #}}}
25
+
26
+ def self::symbolize(value) #{{{
27
+ case value
28
+ when Hash; value.each_with_object({}) { |(k,v),h| h[k.to_sym] = symbolize(v) }
29
+ when Array; value.map { |v| symbolize(v) }
30
+ else value
31
+ end
32
+ end #}}}
33
+
34
+ def self::container?(node) #{{{
35
+ node.is_a?(Hash) || node.is_a?(Array) || node.is_a?(OpenStruct)
36
+ end #}}}
37
+
38
+ def self::array_index(node, seg) #{{{
39
+ return node.length if seg == '-'
40
+ raise ArgumentError, "invalid array index #{seg.inspect}" unless seg =~ /\A(0|[1-9]\d*)\z/
41
+ i = seg.to_i
42
+ raise ArgumentError, "array index #{i} out of range" if i > node.length
43
+ i
44
+ end #}}}
45
+
46
+ def self::get(node, seg) #{{{
47
+ case node
48
+ when Hash
49
+ node.key?(seg.to_sym) ? node[seg.to_sym] : node[seg]
50
+ when Array
51
+ node[array_index(node, seg)]
52
+ when OpenStruct
53
+ node[seg.to_sym]
54
+ end
55
+ end #}}}
56
+
57
+ def self::put(node, seg, value) #{{{
58
+ case node
59
+ when Hash
60
+ node[node.key?(seg) && !node.key?(seg.to_sym) ? seg : seg.to_sym] = value
61
+ when Array
62
+ node[array_index(node, seg)] = value
63
+ when OpenStruct
64
+ node[seg.to_sym] = value
65
+ end
66
+ end #}}}
67
+
68
+ def self::argument(value) #{{{
69
+ return value unless value.is_a?(Hash)
70
+ (defined?(::ParaStruct) ? ::ParaStruct : OpenStruct).new(:name => value[:name].to_s.to_sym, :value => value[:value])
71
+ end #}}}
72
+
73
+ # /arguments/<name>/... -> /arguments/<index>/value/... (argument is created if missing)
74
+ def self::argument_by_name(root, segs) #{{{
75
+ return segs unless segs.length >= 2 && segs[0] == 'arguments' && segs[1] !~ /\A(\d+|-)\z/
76
+ args = (get(root, 'arguments') || []).dup
77
+ put(root, 'arguments', args)
78
+ idx = args.index { |a| a.respond_to?(:name) && a.name.to_s == segs[1] }
79
+ if idx.nil?
80
+ args << argument(:name => segs[1], :value => nil)
81
+ idx = args.length - 1
82
+ end
83
+ ['arguments', idx.to_s, 'value'] + segs[2..-1]
84
+ end #}}}
85
+
86
+ # containers on the path are copied before writing, only root is modified in place
87
+ def self::set(root, pointer, value) #{{{
88
+ raise ArgumentError, 'root is not a Hash' unless root.is_a?(Hash)
89
+ segs = argument_by_name(root, parse(pointer))
90
+ value = symbolize(value)
91
+ value = value.to_s.sub(/^:/,'').to_sym if segs == ['method'] && !value.nil?
92
+ value = argument(value) if segs.length == 2 && segs[0] == 'arguments'
93
+ value = value.map { |a| argument(a) } if segs == ['arguments'] && value.is_a?(Array)
94
+
95
+ node = root
96
+ segs[0..-2].each do |seg|
97
+ child = get(node, seg)
98
+ child = {} if child.nil?
99
+ raise ArgumentError, "#{pointer}: #{seg.inspect} is not a container" unless container?(child)
100
+ child = child.dup
101
+ put(node, seg, child)
102
+ node = child
103
+ end
104
+ put(node, segs.last, value)
105
+ root
106
+ end #}}}
107
+
108
+ end
109
+
110
+ end
data/lib/cpee/message.rb CHANGED
@@ -12,9 +12,27 @@
12
12
  # CPEE (file LICENSE in the main directory). If not, see
13
13
  # <http://www.gnu.org/licenses/>.
14
14
 
15
+ require 'digest/sha1'
16
+ require_relative 'redis'
17
+
15
18
  module CPEE
16
19
 
17
20
  module Message
21
+ # INCR the per-instance sequence and PUBLISH in one round trip. The seq is
22
+ # appended to the prefix ("instance,uuid,seq {json}") so that routing
23
+ # workers can read it without parsing the JSON, and added to the JSON for
24
+ # consumers that only see the body. The payload is always a JSON object.
25
+ # Only count while the instance exists (KEYS[2] is its state), so late
26
+ # messages for a deleted instance do not recreate the counter (seq 0).
27
+ # INCR keeps the TTL that DeleteInstance set while the key expires.
28
+ SEQ_PUBLISH = <<~LUA.freeze
29
+ local s = 0
30
+ if redis.call('EXISTS', KEYS[2]) == 1 then s = redis.call('INCR', KEYS[1]) end
31
+ redis.call('PUBLISH', ARGV[1], ARGV[2] .. ',' .. s .. ' ' .. string.sub(ARGV[3], 1, -2) .. ',"seq":' .. s .. '}')
32
+ return s
33
+ LUA
34
+ SEQ_PUBLISH_SHA = Digest::SHA1.hexdigest(SEQ_PUBLISH).freeze
35
+
18
36
  @@mutex = Mutex.new
19
37
  @@who = 'cpee'
20
38
  @@type = 'instance'
@@ -35,7 +53,7 @@ module CPEE
35
53
  end #}}}
36
54
 
37
55
  def self::set_workers(workers)
38
- @@tworkers = (workers < 1 && workers > 99 ? 1 : workers).freeze
56
+ @@tworkers = (workers < 1 || workers > 99 ? 1 : workers).freeze
39
57
  @@last = -1
40
58
  end
41
59
 
@@ -77,7 +95,9 @@ module CPEE
77
95
  payload["#{@@type}-uuid"] = instance_uuid if instance_uuid
78
96
  payload["#{@@type}-name"] = instance_name if instance_name
79
97
 
80
- backend.publish("#{type}:#{target}:#{event}", "#{instance},#{instance_uuid} #{JSON::generate(payload)}")
98
+ keys = ["#{@@type}:#{instance}/seq", "#{@@type}:#{instance}/state"]
99
+ argv = ["#{type}:#{target}:#{event}", "#{instance},#{instance_uuid}", JSON::generate(payload)]
100
+ CPEE::redis_script(backend, SEQ_PUBLISH_SHA, SEQ_PUBLISH, keys, argv)
81
101
  end
82
102
 
83
103
  def self::send_url(type, event, cpee, content={}, backend)
@@ -183,6 +183,7 @@ module CPEE
183
183
  res += Persistence::keys_extract_name(opts,id,'handlers')
184
184
  hnd.each do |h|
185
185
  res << File.join(h,'url')
186
+ res << File.join(h,'seq')
186
187
  res += Persistence::keys_extract_set_raw(opts,h)
187
188
  end
188
189
  cbs = Persistence::keys_extract_set(opts,id,'callbacks')
@@ -197,12 +198,15 @@ module CPEE
197
198
  end
198
199
  res += Persistence::keys_extract_name(opts,id,'dsl')
199
200
  res += Persistence::keys_extract_name(opts,id,'dslx')
201
+ res += Persistence::keys_extract_name(opts,id,'dslx','@change_uuid')
200
202
  res += Persistence::keys_extract_name(opts,id,'status','message')
201
203
  res += Persistence::keys_extract_name(opts,id,'status','id')
202
204
  res += Persistence::keys_extract_name(opts,id,'executionhandler')
203
205
  res += Persistence::keys_extract_name(opts,id,'description')
206
+ res += Persistence::keys_extract_name(opts,id,'description','@change_uuid')
204
207
  res += Persistence::keys_extract_name(opts,id,'state')
205
208
  res += Persistence::keys_extract_name(opts,id,'state','@changed')
209
+ res += Persistence::keys_extract_name(opts,id,'seq')
206
210
  res += Persistence::keys_extract_name(opts,id,'transformation','endpoints')
207
211
  res += Persistence::keys_extract_name(opts,id,'transformation','endpoints','@type')
208
212
  res += Persistence::keys_extract_name(opts,id,'transformation','description')
data/lib/cpee/redis.rb CHANGED
@@ -16,6 +16,14 @@ require 'redis'
16
16
  require 'uri'
17
17
 
18
18
  module CPEE
19
+ # run a lua script by its sha (cached in redis), send the full script only if redis does not know it (yet)
20
+ def self::redis_script(backend,sha,script,keys,argv)
21
+ backend.evalsha(sha, keys: keys, argv: argv)
22
+ rescue Redis::CommandError => e
23
+ raise unless e.message.start_with?('NOSCRIPT')
24
+ backend.eval(script, keys: keys, argv: argv)
25
+ end
26
+
19
27
  def self::redis_connect(opts,name=nil)
20
28
  if opts[:redis_cmd].nil?
21
29
  begin
@@ -7,7 +7,17 @@
7
7
 
8
8
  <start>
9
9
  <element name="description">
10
- <ref name="dslx_attributes"/>
10
+ <optional> <!-- layout direction of the theme, e.g. for the bpmn export -->
11
+ <attribute name="dir">
12
+ <choice>
13
+ <value>td</value>
14
+ <value>lr</value>
15
+ </choice>
16
+ </attribute>
17
+ </optional>
18
+ <zeroOrMore>
19
+ <attribute><anyName><except><name ns="">dir</name></except></anyName></attribute>
20
+ </zeroOrMore>
11
21
  <ref name="dslx_block"/>
12
22
  </element>
13
23
  </start>
data/lib/properties.xml CHANGED
@@ -54,6 +54,10 @@
54
54
  <parameter name="status" mimetype="*/xml" handler="http://riddl.org/ns/handlers/relaxng">
55
55
  <xi:include href="properties/t_status.rng"/>
56
56
  </parameter>
57
+ <zeroOrMore>
58
+ <parameter name="exposition_info" mimetype="application/json"/>
59
+ <parameter name="exposition_body" mimetype="*"/>
60
+ </zeroOrMore>
57
61
  </message> <!--}}}-->
58
62
  <message name="integer"> <!--{{{-->
59
63
  <parameter name="value" type="integer"/>
@@ -141,16 +145,9 @@
141
145
  </message> <!--}}}-->
142
146
  <message name="dslx"> <!--{{{-->
143
147
  <parameter name="dslx" mimetype="*/xml"/>
144
-
145
- <zeroOrMore>
146
- <parameter name="exposition" mimetype="*"/>
147
- </zeroOrMore>
148
148
  </message> <!--}}}-->
149
149
  <message name="description"> <!--{{{-->
150
150
  <parameter name="description" mimetype="*"/>
151
- <zeroOrMore>
152
- <parameter name="exposition" mimetype="*"/>
153
- </zeroOrMore>
154
151
  </message> <!--}}}-->
155
152
 
156
153
  <message name="transformation"> <!--{{{-->
@@ -17,6 +17,7 @@ require 'mimemagic'
17
17
  require 'base64'
18
18
  require 'securerandom'
19
19
  require 'cpee-eval-ruby/translation'
20
+ require 'cpee/json_pointer'
20
21
 
21
22
  class ConnectionWrapper < WEEL::ConnectionWrapperBase
22
23
  def self::loop_guard(arguments,id,count) # {{{
@@ -288,7 +289,15 @@ class ConnectionWrapper < WEEL::ConnectionWrapperBase
288
289
  @controller.vote("activity/syncing_after", :'activity-uuid' => @handler_activity_uuid, :endpoint => @handler_endpoint, :activity => @handler_position, :label => @label)
289
290
  end # }}}
290
291
  def vote_sync_before(parameters=nil) # {{{
291
- @controller.vote("activity/syncing_before", :'activity-uuid' => @handler_activity_uuid, :endpoint => @handler_endpoint, :activity => @handler_position, :label => @label, :parameters => parameters)
292
+ @label = parameters[:label] if parameters.is_a?(Hash) && parameters[:label]
293
+ @controller.vote("activity/syncing_before", :'activity-uuid' => @handler_activity_uuid, :endpoint => @handler_endpoint, :activity => @handler_position, :label => @label, :parameters => parameters) do |changes|
294
+ next unless parameters.is_a?(Hash)
295
+ changes.each do |pointer,value|
296
+ CPEE::JSONPointer::set(parameters, pointer, value)
297
+ rescue => e
298
+ puts "vote change #{pointer} ignored: #{e.message}"
299
+ end
300
+ end
292
301
  end # }}}
293
302
 
294
303
  def callback(result=nil,options={}, dataelements) #{{{
@@ -388,13 +397,13 @@ class ConnectionWrapper < WEEL::ConnectionWrapperBase
388
397
  end
389
398
  __params
390
399
  end #}}}
391
- def test_condition(__eid,__dataelements,__endpoints,__local,__additional,__code,__args={}) #{{{
400
+ def test_condition(__eid,__dataelements,__endpoints,__local,__additional,__code,__args={},__props={}) #{{{
392
401
  __struct = WEEL::ReadStructure.new(__dataelements,__endpoints,__local,__additional).instance_eval(__code,'Condition',1)
393
402
 
394
403
  __struct = 'false' unless __struct
395
404
  __struct = (__struct == 'false' || __struct == 'null' || __struct == 'nil' || __struct == false ? false : true)
396
405
 
397
- @controller.notify("gateway/decide", :eid => __eid, :instance_uuid => @controller.uuid, :code => __code, :condition => __struct)
406
+ @controller.notify("gateway/decide", :eid => __eid, :instance_uuid => @controller.uuid, :code => __code, :condition => __struct, **__props)
398
407
  @controller.notify("gateway/annotation", :eid => __eid, :'activity-uuid' => @handler_activity_uuid, :label => @label, :activity => @handler_position, :annotations => {})
399
408
  __struct
400
409
  end #}}}
@@ -17,6 +17,7 @@ require 'mimemagic'
17
17
  require 'base64'
18
18
  require 'securerandom'
19
19
  require 'cpee-eval-ruby/translation'
20
+ require 'cpee/json_pointer'
20
21
 
21
22
  class ConnectionWrapper < WEEL::ConnectionWrapperBase
22
23
  def self::loop_guard(arguments,id,count) # {{{
@@ -288,7 +289,15 @@ class ConnectionWrapper < WEEL::ConnectionWrapperBase
288
289
  @controller.vote("activity/syncing_after", :'activity-uuid' => @handler_activity_uuid, :endpoint => @handler_endpoint, :activity => @handler_position, :label => @label)
289
290
  end # }}}
290
291
  def vote_sync_before(parameters=nil) # {{{
291
- @controller.vote("activity/syncing_before", :'activity-uuid' => @handler_activity_uuid, :endpoint => @handler_endpoint, :activity => @handler_position, :label => @label, :parameters => parameters)
292
+ @label = parameters[:label] if parameters.is_a?(Hash) && parameters[:label]
293
+ @controller.vote("activity/syncing_before", :'activity-uuid' => @handler_activity_uuid, :endpoint => @handler_endpoint, :activity => @handler_position, :label => @label, :parameters => parameters) do |changes|
294
+ next unless parameters.is_a?(Hash)
295
+ changes.each do |pointer,value|
296
+ CPEE::JSONPointer::set(parameters, pointer, value)
297
+ rescue => e
298
+ puts "vote change #{pointer} ignored: #{e.message}"
299
+ end
300
+ end
292
301
  end # }}}
293
302
 
294
303
  def callback(result=nil,options={}, dataelements) #{{{
@@ -422,7 +431,7 @@ class ConnectionWrapper < WEEL::ConnectionWrapperBase
422
431
  end
423
432
  __params
424
433
  end #}}}
425
- def test_condition(__eid,__dataelements,__endpoints,__local,__additional,__code,__args={}) #{{{
434
+ def test_condition(__eid,__dataelements,__endpoints,__local,__additional,__code,__args={},__props={}) #{{{
426
435
  send = []
427
436
  send.push Riddl::Parameter::Simple::new('code',__code)
428
437
  send.push Riddl::Parameter::Complex::new('dataelements','application/json', JSON::generate(__dataelements))
@@ -439,7 +448,7 @@ class ConnectionWrapper < WEEL::ConnectionWrapperBase
439
448
  __struct = 'false' unless __struct
440
449
  __struct = (__struct == 'false' || __struct == 'null' || __struct == 'nil' || __struct == false ? false : true)
441
450
 
442
- @controller.notify("gateway/decide", :eid => __eid, :instance_uuid => @controller.uuid, :code => __code, :condition => __struct)
451
+ @controller.notify("gateway/decide", :eid => __eid, :instance_uuid => @controller.uuid, :code => __code, :condition => __struct, **__props)
443
452
  @controller.notify("gateway/annotation", :eid => __eid, :'activity-uuid' => @handler_activity_uuid, :label => @label, :activity => @handler_position, :annotations => {})
444
453
  __struct
445
454
  end #}}}