cpee 2.1.139 → 2.1.141

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.
@@ -140,7 +140,9 @@ module CPEE
140
140
  doc.find('/p:properties/p:transformation/p:dataelements/@type').first.text = CPEE::Persistence::extract_item(id,opts,'transformation/dataelements/@type')
141
141
  doc.find('/p:properties/p:transformation/p:endpoints/@type').first.text = CPEE::Persistence::extract_item(id,opts,'transformation/endpoints/@type')
142
142
  doc.find('/p:properties/p:transformation/p:dslx').first.text = CPEE::Persistence::extract_item(id,opts,'transformation/dslx') || ''
143
- doc.find('/p:properties/p:transformation/p:dslx/@type').first.text = CPEE::Persistence::extract_item(id,opts,'transformation/dslx/@type') || 'copy' # instances from before dslx backtransformation
143
+ ttype, text = PutTransformation::stored_dslx(id,opts)
144
+ doc.find('/p:properties/p:transformation/p:dslx/@type').first.text = ttype
145
+ doc.find('/p:properties/p:transformation/p:dslx').first.attributes['extension'] = text
144
146
  Riddl::Parameter::Complex.new('properties','application/xml',doc.to_s)
145
147
  end
146
148
  end #}}}
@@ -159,7 +161,7 @@ module CPEE
159
161
  CPEE::Properties::PutStatus::set id, opts, node.first.dump
160
162
  end
161
163
  if (node = doc.find('/p:properties/p:executionhandler')).any?
162
- if doc.find('/p:properties/p:description/*').any?
164
+ if doc.find('/p:properties/p:description/* | /p:properties/p:dslx/*').any?
163
165
  CPEE::Properties::PutExecutionHandler::set id, opts, node.first.text, false
164
166
  else
165
167
  CPEE::Properties::PutExecutionHandler::set id, opts, node.first.text
@@ -173,9 +175,12 @@ module CPEE
173
175
  end
174
176
 
175
177
  if (node = doc.find('/p:properties/p:transformation')).any?
176
- CPEE::Properties::PutTransformation::set id, opts, node.first.dump, doc.find('/p:properties/p:description/*').empty?
178
+ CPEE::Properties::PutTransformation::set id, opts, node.first.dump, doc.find('/p:properties/p:description/* | /p:properties/p:dslx/*').empty?
179
+ CPEE::Persistence::wait(opts)
177
180
  end
178
- if (node = doc.find('/p:properties/p:description/*')).any?
181
+ if (node = doc.find('/p:properties/p:dslx/*')).any?
182
+ CPEE::Properties::PutDescription::set id, opts, node.first.dump, true
183
+ elsif (node = doc.find('/p:properties/p:description/*')).any?
179
184
  CPEE::Properties::PutDescription::set id, opts, node.first.dump
180
185
  end
181
186
 
@@ -208,9 +213,12 @@ module CPEE
208
213
  end
209
214
 
210
215
  if (node = doc.find('/*/p:transformation')).any?
211
- CPEE::Properties::PutTransformation::set id, opts, node.first.dump, doc.find('/*/p:description/*').empty?
216
+ CPEE::Properties::PutTransformation::set id, opts, node.first.dump, doc.find('/*/p:description/* | /*/p:dslx/*').empty?
217
+ CPEE::Persistence::wait(opts)
212
218
  end
213
- if (node = doc.find('/*/p:description/*')).any?
219
+ if (node = doc.find('/*/p:dslx/*')).any?
220
+ CPEE::Properties::PutDescription::set id, opts, node.first.dump, true
221
+ elsif (node = doc.find('/*/p:description/*')).any?
214
222
  CPEE::Properties::PutDescription::set id, opts, node.first.dump
215
223
  end
216
224
 
@@ -310,10 +318,27 @@ module CPEE
310
318
  end
311
319
  end #}}}
312
320
  class PutStatus < Riddl::Implementation #{{{
321
+ EXPOSITION_ONLY = 18510501
322
+
313
323
  def self::set(id,opts,xml)
314
324
  doc = XML::Smart::string(xml)
315
325
  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)'))
326
+ sid = doc.find('string(/p:status/p:id)').to_i
327
+ return if sid == EXPOSITION_ONLY
328
+ CPEE::Persistence::set_item(id,opts,'status',:id => sid, :message => doc.find('string(/p:status/p:message)'))
329
+ end
330
+
331
+ def self::expositions(id,opts,expositions)
332
+ return if expositions.empty?
333
+ attrs = CPEE::Persistence::extract_list(id,opts,'attributes').to_h
334
+ expositions.each do |info,body|
335
+ content = {
336
+ :exposition => body,
337
+ :info => info,
338
+ :attributes => attrs
339
+ }
340
+ CPEE::Message::send(:event,'status/exposition',File.join(opts[:url],'/'),id,attrs['uuid'],attrs['info'],content,opts[:redis])
341
+ end
317
342
  end
318
343
 
319
344
  def response
@@ -324,7 +349,16 @@ module CPEE
324
349
  elsif opts[:statemachine].final? id
325
350
  @status = 410
326
351
  else
352
+ begin
353
+ expositions = @p[1..-1].each_slice(2).map do |info,body|
354
+ [JSON.parse(info.value.read), body.value.read]
355
+ end
356
+ rescue JSON::ParserError => e
357
+ @status = 400
358
+ return Riddl::Parameter::Complex.new('error','text/plain','exposition_info is not valid JSON: ' + e.message)
359
+ end
327
360
  PutStatus::set id, opts, @p[0].value.read
361
+ PutStatus::expositions id, opts, expositions
328
362
  end
329
363
  nil
330
364
  end
@@ -844,7 +878,7 @@ module CPEE
844
878
  end
845
879
  end #}}}
846
880
 
847
- def self::set(id,opts,xml,exposition=[],copy=false)
881
+ def self::set(id,opts,xml,copy=false)
848
882
  dslx, dsl, de, ep = if copy
849
883
  PutDescription::transform(
850
884
  xml,
@@ -873,7 +907,7 @@ module CPEE
873
907
  )
874
908
  end
875
909
  tdslx = CPEE::Persistence::extract_item(id,opts,'transformation/dslx')
876
- tdslxtype = CPEE::Persistence::extract_item(id,opts,'transformation/dslx/@type')
910
+ tdslxtype = PutTransformation::stored_dslx(id,opts)[0]
877
911
  description = if copy && tdslxtype == 'rest'
878
912
  nil # slow (e.g. bpmn layout), done after storing, see backtransform_async
879
913
  elsif copy
@@ -905,14 +939,6 @@ module CPEE
905
939
  PutDescription::backtransform_async(id,opts,dslx,tdslx,tdslxtype) if copy && tdslxtype == 'rest'
906
940
  PatchItems::set_hash('dataelements',id,opts,de) unless de.empty?
907
941
  PatchItems::set_hash('endpoints',id,opts,ep) unless ep.empty?
908
- exposition.each do |exp|
909
- content = {
910
- :change_uuid => change_uuid,
911
- :exposition => exp.value.read,
912
- :attributes => attrs
913
- }
914
- CPEE::Message::send(:event,'description/exposition',File.join(opts[:url],'/'),id,attrs['uuid'],attrs['info'],content,opts[:redis])
915
- end
916
942
  end
917
943
 
918
944
  def self::validate(xml,opts) # dslx against t_dslx.rng, returns the errors
@@ -944,7 +970,7 @@ module CPEE
944
970
  return Riddl::Parameter::Complex.new('error','text/plain',errors.join("\n"))
945
971
  end
946
972
  begin
947
- PutDescription::set(id,opts,xml,@p[1..-1],copy)
973
+ PutDescription::set(id,opts,xml,copy)
948
974
  rescue => e
949
975
  puts e.message
950
976
  puts e.backtrace
@@ -969,29 +995,41 @@ module CPEE
969
995
  des.find('p:dataelements/@type').first.text = CPEE::Persistence::extract_item(id,opts,'transformation/dataelements/@type')
970
996
  des.find('p:endpoints/@type').first.text = CPEE::Persistence::extract_item(id,opts,'transformation/endpoints/@type')
971
997
  des.find('p:dslx').first.text = CPEE::Persistence::extract_item(id,opts,'transformation/dslx') || ''
972
- des.find('p:dslx/@type').first.text = CPEE::Persistence::extract_item(id,opts,'transformation/dslx/@type') || 'copy' # instances from before dslx backtransformation
998
+ ttype, text = PutTransformation::stored_dslx(id,opts)
999
+ des.find('p:dslx/@type').first.text = ttype
1000
+ des.find('p:dslx').first.attributes['extension'] = text
973
1001
  Riddl::Parameter::Complex.new('status','text/xml',des.to_doc.to_s)
974
1002
  end
975
1003
  end #}}}
976
1004
  class PutTransformation < Riddl::Implementation #{{{
1005
+ def self::stored_dslx(id,opts)
1006
+ ttype = CPEE::Persistence::extract_item(id,opts,'transformation/dslx/@type')
1007
+ text = CPEE::Persistence::extract_item(id,opts,'transformation/dslx/@extension')
1008
+ fallback = ttype.nil? && CPEE::Persistence::extract_item(id,opts,'transformation/description/@type') == 'copy'
1009
+ [ttype || (fallback ? 'copy' : 'none'), text || (fallback ? 'xml' : 'txt')]
1010
+ end
977
1011
  def self::set(id,opts,xml,backtrans=true)
978
1012
  doc = XML::Smart::string(xml)
979
1013
  doc.register_namespace 'p', 'http://cpee.org/ns/properties/2.0'
980
1014
  tdslx = doc.find('string(/p:transformation/p:dslx)')
981
- tdslxtype = (t = doc.find('string(/p:transformation/p:dslx/@type)')).empty? ? 'copy' : t # optional, missing means copy
1015
+ type = Proc.new { |item| (t = doc.find("string(/p:transformation/p:#{item}/@type)")).empty? ? 'none' : t }
1016
+ fallback = doc.find('string(/p:transformation/p:dslx/@type)').empty? && type.call('description') == 'copy'
1017
+ tdslxtype = fallback ? 'copy' : type.call('dslx')
1018
+ tdslxext = (t = doc.find('string(/p:transformation/p:dslx/@extension)')).empty? ? (fallback ? 'xml' : 'txt') : t
982
1019
  changed = tdslx != (CPEE::Persistence::extract_item(id,opts,'transformation/dslx') || '') ||
983
- tdslxtype != (CPEE::Persistence::extract_item(id,opts,'transformation/dslx/@type') || 'copy')
1020
+ tdslxtype != PutTransformation::stored_dslx(id,opts)[0]
984
1021
  dslx = CPEE::Persistence::extract_item(id,opts,'dslx')
985
1022
  dslx = nil if dslx&.empty?
986
1023
  CPEE::Persistence::set_item(id,opts,'transformation',
987
1024
  :description => doc.find('string(/p:transformation/p:description)'),
988
- :description_type => doc.find('string(/p:transformation/p:description/@type)'),
1025
+ :description_type => type.call('description'),
989
1026
  :dataelements =>doc.find('string(/p:transformation/p:dataelements)'),
990
- :dataelements_type => doc.find('string(/p:transformation/p:dataelements/@type)'),
1027
+ :dataelements_type => type.call('dataelements'),
991
1028
  :endpoints =>doc.find('string(/p:transformation/p:endpoints)'),
992
- :endpoints_type => doc.find('string(/p:transformation/p:endpoints/@type)'),
1029
+ :endpoints_type => type.call('endpoints'),
993
1030
  :dslx => tdslx,
994
1031
  :dslx_type => tdslxtype,
1032
+ :dslx_extension => tdslxext,
995
1033
  :change_uuid => dslx ? Digest::SHA1.hexdigest(dslx) : nil,
996
1034
  :change_pending => backtrans && changed && tdslxtype == 'rest' && !dslx.nil? # description follows with description/sync
997
1035
  )
data/lib/cpee/message.rb CHANGED
@@ -66,11 +66,13 @@ module CPEE
66
66
  wid = SecureRandom.hex(16)
67
67
  begin
68
68
  sub.subscribe_with_timeout(2,"event:#{target}:transaction/finished") do |on|
69
+ on.subscribe do
70
+ backend.publish("event:#{target}:transaction/start","#{wid} {}")
71
+ end
69
72
  on.message do |what,message|
70
73
  mess = message[0...message.index(' ')]
71
74
  sub.unsubscribe("event:#{target}:transaction/finished") if mess == wid
72
75
  end
73
- backend.publish("event:#{target}:transaction/start","#{wid} {}")
74
76
  end
75
77
  rescue => e
76
78
  puts "timeout error"
@@ -8,6 +8,7 @@
8
8
  <include href="endpoints.rng"/>
9
9
  <include href="attributes.rng"/>
10
10
  <include href="description.rng"/>
11
+ <include href="dslx.rng"/>
11
12
  <include href="transformation.rng"/>
12
13
 
13
14
  <start>
@@ -21,6 +22,9 @@
21
22
  <ref name="endpoints"/>
22
23
  <ref name="attributes"/>
23
24
  <ref name="description"/>
25
+ <optional>
26
+ <ref name="dslx"/>
27
+ </optional>
24
28
  <ref name="transformation"/>
25
29
  </element>
26
30
  </start>
@@ -8,6 +8,7 @@
8
8
  <include href="endpoints.rng"/>
9
9
  <include href="attributes.rng"/>
10
10
  <include href="description.rng"/>
11
+ <include href="dslx.rng"/>
11
12
  <include href="transformation.rng"/>
12
13
 
13
14
  <start>
@@ -40,6 +41,9 @@
40
41
  <optional>
41
42
  <ref name="description"/>
42
43
  </optional>
44
+ <optional>
45
+ <ref name="dslx"/>
46
+ </optional>
43
47
  <optional>
44
48
  <ref name="transformation"/>
45
49
  </optional>
@@ -8,6 +8,7 @@
8
8
  <include href="endpoints.rng"/>
9
9
  <include href="attributes.rng"/>
10
10
  <include href="description.rng"/>
11
+ <include href="dslx.rng"/>
11
12
  <include href="transformation.rng"/>
12
13
  <include href="subscriptions.rng"/>
13
14
 
@@ -44,6 +45,9 @@
44
45
  <optional>
45
46
  <ref name="description"/>
46
47
  </optional>
48
+ <optional>
49
+ <ref name="dslx"/>
50
+ </optional>
47
51
  <optional>
48
52
  <ref name="transformation"/>
49
53
  </optional>
@@ -1,40 +1,46 @@
1
1
  <grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
2
2
  <define name="transformation">
3
3
  <element name="transformation" ns="http://cpee.org/ns/properties/2.0">
4
- <element name="description">
5
- <attribute name="type">
6
- <choice>
7
- <value>copy</value>
8
- <value>rest</value>
9
- <value>xslt</value>
10
- <value>clean</value>
11
- <value>none</value>
12
- </choice>
13
- </attribute>
14
- <data type="anyURI"/>
15
- </element>
16
- <element name="dataelements">
17
- <attribute name="type">
18
- <choice>
19
- <value>rest</value>
20
- <value>xslt</value>
21
- <value>clean</value>
22
- <value>none</value>
23
- </choice>
24
- </attribute>
25
- <data type="anyURI"/>
26
- </element>
27
- <element name="endpoints">
28
- <attribute name="type">
29
- <choice>
30
- <value>rest</value>
31
- <value>xslt</value>
32
- <value>clean</value>
33
- <value>none</value>
34
- </choice>
35
- </attribute>
36
- <data type="anyURI"/>
37
- </element>
4
+ <optional>
5
+ <element name="description">
6
+ <attribute name="type">
7
+ <choice>
8
+ <value>copy</value>
9
+ <value>rest</value>
10
+ <value>xslt</value>
11
+ <value>clean</value>
12
+ <value>none</value>
13
+ </choice>
14
+ </attribute>
15
+ <data type="anyURI"/>
16
+ </element>
17
+ </optional>
18
+ <optional>
19
+ <element name="dataelements">
20
+ <attribute name="type">
21
+ <choice>
22
+ <value>rest</value>
23
+ <value>xslt</value>
24
+ <value>clean</value>
25
+ <value>none</value>
26
+ </choice>
27
+ </attribute>
28
+ <data type="anyURI"/>
29
+ </element>
30
+ </optional>
31
+ <optional>
32
+ <element name="endpoints">
33
+ <attribute name="type">
34
+ <choice>
35
+ <value>rest</value>
36
+ <value>xslt</value>
37
+ <value>clean</value>
38
+ <value>none</value>
39
+ </choice>
40
+ </attribute>
41
+ <data type="anyURI"/>
42
+ </element>
43
+ </optional>
38
44
  <optional>
39
45
  <!-- backtransformation: description from a directly set dslx. missing means copy -->
40
46
  <element name="dslx">
@@ -46,6 +52,9 @@
46
52
  <value>none</value>
47
53
  </choice>
48
54
  </attribute>
55
+ <optional>
56
+ <attribute name="extension"/>
57
+ </optional>
49
58
  <data type="anyURI"/>
50
59
  </element>
51
60
  </optional>
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"> <!--{{{-->
@@ -50,9 +50,13 @@ class Controller
50
50
 
51
51
  @callback_keys = {}
52
52
 
53
+ subscribed = WEEL::Continue.new
53
54
  @subs = Thread.new do
54
55
  @psredis = @opts[:redis_dyn].call "Instance #{@id} Callback Response"
55
56
  @psredis.psubscribe('callback-response:*','callback-end:*') do |on|
57
+ on.psubscribe do |pattern, count|
58
+ subscribed.continue if count == 2
59
+ end
56
60
  on.pmessage do |pat, what, message|
57
61
  if pat == 'callback-response:*'
58
62
  _, worker, identifier = what.split(':')
@@ -83,6 +87,7 @@ class Controller
83
87
  sleep 1
84
88
  retry
85
89
  end
90
+ subscribed.wait
86
91
  Thread.new do
87
92
  while true
88
93
  notify("status/resource_utilization", :mib => GetProcessMem.new.mb, **Process.times.to_h)
@@ -173,23 +178,22 @@ class Controller
173
178
  def vote(what,content={})
174
179
  topic, name = what.split('/')
175
180
  handler = File.join(topic,'vote',name)
176
- votes = []
181
+ pending = []
177
182
 
178
183
  @opts[:votes][handler]&.each do |client|
179
- voteid = SecureRandom.hex(16)
180
- content[:key] = voteid
181
- content[:attributes] = attributes
182
- content[:subscription] = client
183
- votes << voteid
184
- CPEE::Message::send(:vote,what,base,@id,uuid,info,content,@redis)
184
+ pending << content.merge(:key => SecureRandom.hex(16), :attributes => attributes, :subscription => client)
185
185
  end
186
+ votes = pending.map { |c| c[:key] }
186
187
 
187
188
  if votes.length > 0
188
189
  @votes += votes
189
190
  psredis = @opts[:redis_dyn].call "Instance #{@id} Vote"
190
191
  collect = []
191
192
  changes = []
192
- psredis.subscribe(votes.map{|e| ['vote-response:00:' + e.to_s] }.flatten) do |on|
193
+ psredis.subscribe(votes.map{|e| 'vote-response:00:' + e }) do |on|
194
+ on.subscribe do |channel, count|
195
+ pending.each { |c| CPEE::Message::send(:vote,what,base,@id,uuid,info,c,@redis) } if count == votes.length
196
+ end
193
197
  on.message do |what, message|
194
198
  index = message.index(' ')
195
199
  mess = message[index+1..-1]
@@ -17,6 +17,7 @@
17
17
  <event>instantiation</event>
18
18
  <event>take</event>
19
19
  <event>giveback</event>
20
+ <event>probe</event>
20
21
  </topic>
21
22
  <topic id="state">
22
23
  <event>change</event>
@@ -24,7 +25,11 @@
24
25
  <topic id="description">
25
26
  <event>change</event>
26
27
  </topic>
28
+ <topic id="status">
29
+ <event>exposition</event>
30
+ </topic>
27
31
  <topic id="gateway">
32
+ <event>split</event>
28
33
  <event>decide</event>
29
34
  <event>join</event>
30
35
  </topic>
@@ -1 +1 @@
1
- 3635871
1
+ 2228432
@@ -1 +1 @@
1
- 3635891
1
+ 2228450
@@ -1 +1 @@
1
- 3635884
1
+ 2228444
@@ -1 +1 @@
1
- 3635877
1
+ 2228438
@@ -140,6 +140,7 @@ Daemonite.new do |opts|
140
140
  multi.set("instance:#{instance}/transformation/endpoints/@type",mess.dig('content','endpoints_type'),keepttl: true)
141
141
  multi.set("instance:#{instance}/transformation/dslx",mess.dig('content','dslx'),keepttl: true)
142
142
  multi.set("instance:#{instance}/transformation/dslx/@type",mess.dig('content','dslx_type'),keepttl: true)
143
+ multi.set("instance:#{instance}/transformation/dslx/@extension",mess.dig('content','dslx_extension'),keepttl: true)
143
144
  if mess.dig('content','change_pending') # same dslx, but the description is no longer the one for it
144
145
  multi.del("instance:#{instance}/description/@change_uuid")
145
146
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cpee
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.139
4
+ version: 2.1.141
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juergen eTM Mangler