cpee 2.1.25 → 2.1.30

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/cockpit/css/ui.css +1 -1
  3. data/cockpit/templates/Subprocess.xml +79 -0
  4. data/cockpit/templates/Subprocess.xml.attrs +13 -0
  5. data/cockpit/templates/Track Test.xml +31 -28
  6. data/cockpit/templates/Track Test.xml.attrs +11 -0
  7. data/cockpit/templates/Wait.xml +73 -0
  8. data/cockpit/templates/Wait.xml.attrs +13 -0
  9. data/cockpit/templates/Worklist.xml +47 -18
  10. data/cockpit/templates/instantiate/Take_Perf.xml +13 -10
  11. data/cockpit/templates/instantiate/Take_Sub.xml +4 -8
  12. data/cockpit/templates/instantiate/Take_X.xml +12 -9
  13. data/cockpit/themes/compact/theme.js +4 -2
  14. data/cockpit/themes/control/theme.js +4 -2
  15. data/cockpit/themes/default/theme.js +4 -2
  16. data/cockpit/themes/extended/theme.js +4 -2
  17. data/cockpit/themes/model/theme.js +4 -2
  18. data/cockpit/themes/packed/theme.js +4 -2
  19. data/cockpit/themes/preset/theme.js +4 -2
  20. data/cpee.gemspec +1 -1
  21. data/lib/cpee/fail.rb +23 -0
  22. data/lib/cpee/implementation.rb +34 -18
  23. data/lib/cpee/implementation_callbacks.rb +20 -15
  24. data/lib/cpee/implementation_notifications.rb +22 -17
  25. data/lib/cpee/implementation_properties.rb +65 -60
  26. data/lib/cpee/message.rb +15 -13
  27. data/lib/cpee/persistence.rb +33 -10
  28. data/server/executionhandlers/ruby/connection.rb +7 -7
  29. data/server/executionhandlers/ruby/controller.rb +5 -3
  30. data/server/executionhandlers/ruby/dsl_to_dslx.xsl +40 -20
  31. data/server/executionhandlers/ruby/test.xml +43 -0
  32. data/server/routing/end.pid +1 -0
  33. data/server/routing/forward-events.pid +1 -0
  34. data/server/routing/forward-events.rb +6 -0
  35. data/server/routing/forward-votes.pid +1 -0
  36. data/server/routing/persist.pid +1 -0
  37. data/server/routing/persist.rb +4 -2
  38. data/server/server.conf +1 -1
  39. data/tools/cpee +14 -6
  40. metadata +13 -6
  41. data/cockpit/templates/Coopis 2010.xml.active +0 -1
  42. data/cockpit/templates/Coopis 2010.xml.active-uuid +0 -1
  43. data/cockpit/templates/UR-VUE 2020 Solution Baseline.xml.active +0 -1
  44. data/cockpit/templates/UR-VUE 2020 Solution Baseline.xml.active-uuid +0 -1
data/lib/cpee/fail.rb ADDED
@@ -0,0 +1,23 @@
1
+
2
+ # This file is part of CPEE.
3
+ #
4
+ # CPEE is free software: you can redistribute it and/or modify it under the terms
5
+ # of the GNU General Public License as published by the Free Software Foundation,
6
+ # either version 3 of the License, or (at your option) any later version.
7
+ #
8
+ # CPEE is distributed in the hope that it will be useful, but WITHOUT ANY
9
+ # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
10
+ # PARTICULAR PURPOSE. See the GNU General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU General Public License along with
13
+ # CPEE (file COPYING in the main directory). If not, see
14
+ # <http://www.gnu.org/licenses/>.
15
+
16
+ module CPEE
17
+ class FAIL < Riddl::Implementation #{{{
18
+ def response
19
+ @status = 404
20
+ nil
21
+ end
22
+ end #}}}
23
+ end
@@ -16,6 +16,7 @@ require 'fileutils'
16
16
  require 'redis'
17
17
  require 'riddl/server'
18
18
  require 'riddl/client'
19
+ require_relative 'fail'
19
20
  require_relative 'redis'
20
21
  require_relative 'message'
21
22
  require_relative 'persistence'
@@ -83,7 +84,7 @@ module CPEE
83
84
  opts[:sse_connections] = {}
84
85
 
85
86
  opts[:statemachine] = CPEE::StateMachine.new opts[:states], %w{running simulating replaying finishing stopping abandoned finished} do |id|
86
- opts[:redis].get("instance:#{id}/state")
87
+ CPEE::Persistence::extract_item(id,opts,"state")
87
88
  end
88
89
 
89
90
  opts[:runtime_cmds] << [
@@ -176,16 +177,14 @@ module CPEE
176
177
 
177
178
  class Instances < Riddl::Implementation #{{{
178
179
  def response
179
- redis = @a[0][:redis]
180
+ opts = @a[0]
180
181
  Riddl::Parameter::Complex.new("wis","text/xml") do
181
182
  ins = XML::Smart::string('<instances/>')
182
- redis.zrevrange('instances',0,-1).each do |instance|
183
- statekey = "instance:#{instance}/state"
184
- attributes = "instance:#{instance}/attributes/"
185
- info = redis.get(attributes + 'info')
186
- uuid = redis.get(attributes + 'uuid')
187
- state = redis.get(statekey)
188
- state_changed = redis.get(File.join(statekey,'@changed'))
183
+ CPEE::Persistence::each_object(opts) do |instance|
184
+ info = CPEE::Persistence::extract_item(instance,opts,'attributes/info')
185
+ uuid = CPEE::Persistence::extract_item(instance,opts,'attributes/uuid')
186
+ state = CPEE::Persistence::extract_item(instance,opts,'state')
187
+ state_changed = CPEE::Persistence::extract_item(instance,opts,'state/@changed')
189
188
  ins.root.add('instance', info, 'uuid' => uuid, 'id' => instance, 'state' => state, 'state_changed' => state_changed )
190
189
  end
191
190
  ins.to_s
@@ -209,9 +208,9 @@ module CPEE
209
208
  doc = XML::Smart::open_unprotected(opts[:properties_init])
210
209
  doc.register_namespace 'p', 'http://cpee.org/ns/properties/2.0'
211
210
  name = @p[0].value
212
- id = redis.zrevrange('instances', 0, 0).first.to_i + 1
211
+ id = CPEE::Persistence::new_object(opts)
213
212
  uuid = SecureRandom.uuid
214
- instance = 'instance:' + id.to_s
213
+ instance = CPEE::Persistence::OBJ + ':' + id.to_s
215
214
  redis.multi do |multi|
216
215
  multi.zadd('instances',id,id)
217
216
  doc.root.find(PROPERTIES_PATHS_FULL.join(' | ')).each do |e|
@@ -235,12 +234,12 @@ module CPEE
235
234
  doc.register_namespace 'np', 'http://riddl.org/ns/common-patterns/notifications-producer/2.0'
236
235
  key = File.basename(File.dirname(f))
237
236
  url = doc.find('string(/np:subscription/@url)')
238
- multi.sadd("instance:#{id}/handlers",key)
239
- multi.set("instance:#{id}/handlers/#{key}/url",url)
237
+ multi.sadd(CPEE::Persistence::OBJ + ":#{id}/handlers",key)
238
+ multi.set(CPEE::Persistence::OBJ + ":#{id}/handlers/#{key}/url",url)
240
239
  doc.find('/np:subscription/np:topic/*').each do |e|
241
240
  c = File.join(e.parent.attributes['id'],e.qname.name,e.text)
242
- multi.sadd("instance:#{id}/handlers/#{key}",c)
243
- multi.sadd("instance:#{id}/handlers/#{c}",key)
241
+ multi.sadd(CPEE::Persistence::OBJ + ":#{id}/handlers/#{key}",c)
242
+ multi.sadd(CPEE::Persistence::OBJ + ":#{id}/handlers/#{c}",key)
244
243
  end
245
244
  end rescue nil # all the ones that are not ok, are ignored
246
245
  end
@@ -251,6 +250,12 @@ module CPEE
251
250
  multi.set(File.join(instance, 'state', '@changed'), Time.now.xmlschema(3))
252
251
  end
253
252
 
253
+ content = {
254
+ :state => 'ready',
255
+ :attributes => CPEE::Persistence::extract_list(id,opts,'attributes').to_h
256
+ }
257
+ CPEE::Message::send(:event,'state/change',File.join(opts[:url],'/'),id,uuid,name,content,redis)
258
+
254
259
  @headers << Riddl::Header.new("CPEE-INSTANCE", id.to_s)
255
260
  @headers << Riddl::Header.new("CPEE-INSTANCE-URL", File.join(opts[:url].to_s,id.to_s,'/'))
256
261
  @headers << Riddl::Header.new("CPEE-INSTANCE-UUID", uuid)
@@ -263,7 +268,7 @@ module CPEE
263
268
  def response
264
269
  opts = @a[0]
265
270
  id = @r[0].to_i
266
- unless opts[:redis].exists?("instance:#{id}/state")
271
+ unless CPEE::Persistence::exists?(id,opts)
267
272
  @status = 404
268
273
  return
269
274
  end
@@ -285,11 +290,22 @@ module CPEE
285
290
  opts = @a[0]
286
291
  redis = opts[:redis]
287
292
  id = @r[0].to_i
288
- unless redis.exists?("instance:#{id}/state")
293
+ unless CPEE::Persistence::exists?(id,opts)
289
294
  @status = 404
290
295
  return
291
296
  end
292
- empt = redis.keys("instance:#{id}/*").to_a
297
+
298
+ content = {
299
+ :state => 'purged',
300
+ :attributes => CPEE::Persistence::extract_list(id,opts,'attributes').to_h
301
+ }
302
+ state = CPEE::Persistence::extract_item(id,opts,'state')
303
+ if state == 'stopped' || state == 'ready'
304
+ CPEE::Message::send(:event,'state/change',File.join(opts[:url],'/'),id,content[:attributes]['uuid'],content[:attributes]['info'],content,redis)
305
+ end
306
+
307
+ empt = CPEE::Persistence::keys(id,opts).to_a
308
+ empt.delete_if{|e| e =~ /\/handlers/ }
293
309
  redis.multi do |multi|
294
310
  multi.del empt
295
311
  multi.zrem 'instances', id
@@ -13,17 +13,22 @@
13
13
  # <http://www.gnu.org/licenses/>.
14
14
 
15
15
  require 'json'
16
+ require_relative 'fail'
16
17
 
17
18
  module CPEE
18
19
  module Callbacks
19
20
 
20
21
  def self::implementation(id,opts)
21
22
  Proc.new do
22
- run CPEE::Callbacks::Callbacks, id, opts if get
23
- on resource do
24
- run CPEE::Callbacks::GetCallback, id, opts if get
25
- run CPEE::Callbacks::DelCallback, id, opts if delete
26
- run CPEE::Callbacks::ExCallback, id, opts if put
23
+ if CPEE::Persistence::exists?(id,opts)
24
+ run CPEE::Callbacks::Callbacks, id, opts if get
25
+ on resource do
26
+ run CPEE::Callbacks::GetCallback, id, opts if get
27
+ run CPEE::Callbacks::DelCallback, id, opts if delete
28
+ run CPEE::Callbacks::ExCallback, id, opts if put
29
+ end
30
+ else
31
+ run CPEE::FAIL
27
32
  end
28
33
  end
29
34
  end
@@ -50,13 +55,13 @@ module CPEE
50
55
  opts = @a[1]
51
56
  callback = @r[-1]
52
57
 
53
- if opts[:redis].sismember("instance:#{id}/callbacks",callback)
58
+ if CPEE::Persistence::is_member?(id,opts,'callbacks',callback)
54
59
  res = {}
55
- res[:uuid] = opts[:redis].get("instance:#{id}/callback/#{callback}/uuid")
56
- res[:type] = opts[:redis].get("instance:#{id}/callback/#{callback}/type")
57
- res[:position] = opts[:redis].get("instance:#{id}/callback/#{callback}/position")
58
- res[:label] = opts[:redis].get("instance:#{id}/callback/#{callback}/label")
59
- if sub = opts[:redis].get("instance:#{id}/callback/#{callback}/subscription")
60
+ res[:uuid] = CPEE::Persistence::extract_item(id,opts,"callback/#{callback}/uuid")
61
+ res[:type] = CPEE::Persistence::extract_item(id,opts,"callback/#{callback}/type")
62
+ res[:position] = CPEE::Persistence::extract_item(id,opts,"callback/#{callback}/position")
63
+ res[:label] = CPEE::Persistence::extract_item(id,opts,"callback/#{callback}/label")
64
+ if sub = CPEE::Persistence::extract_item(id,opts,"callback/#{callback}/subscription")
60
65
  res[:subscription] = sub
61
66
  end
62
67
 
@@ -73,7 +78,7 @@ module CPEE
73
78
  opts = @a[1]
74
79
  callback = @r[-1]
75
80
 
76
- if opts[:redis].get("instance:#{id}/callback/#{callback}/type") == 'callback'
81
+ if CPEE::Persistence::extract_item(id,opts,"callback/#{callback}/type") == 'callback'
77
82
  CPEE::Message::send(
78
83
  :'callback-end',
79
84
  callback,
@@ -84,7 +89,7 @@ module CPEE
84
89
  {},
85
90
  opts[:redis]
86
91
  )
87
- elsif opts[:redis].get("instance:#{id}/callback/#{callback}/type") == 'vote'
92
+ elsif CPEE::Persistence::extract_item(id,opts,"callback/#{callback}/type") == 'vote'
88
93
  CPEE::Message::send(
89
94
  :'vote-response',
90
95
  callback,
@@ -108,7 +113,7 @@ module CPEE
108
113
  opts = @a[1]
109
114
  callback = @r[-1]
110
115
 
111
- if opts[:redis].get("instance:#{id}/callback/#{callback}/type") == 'callback'
116
+ if CPEE::Persistence::extract_item(id,opts,"callback/#{callback}/type") == 'callback'
112
117
  ret = {}
113
118
  ret['values'] = @p.map{ |e|
114
119
  [e.name, e.class == Riddl::Parameter::Simple ? [:simple,e.value] : [:complex,e.mimetype,e.value.path] ]
@@ -125,7 +130,7 @@ module CPEE
125
130
  ret,
126
131
  opts[:redis]
127
132
  )
128
- elsif opts[:redis].get("instance:#{id}/callback/#{callback}/type") == 'vote'
133
+ elsif CPEE::Persistence::extract_item(id,opts,"callback/#{callback}/type") == 'vote'
129
134
  if @p.length == 1 && @p[0].name == 'continue' && @p[0].class == Riddl::Parameter::Simple
130
135
  CPEE::Message::send(
131
136
  :'vote-response',
@@ -13,29 +13,34 @@
13
13
  # <http://www.gnu.org/licenses/>.
14
14
 
15
15
  require 'json'
16
+ require_relative 'fail'
16
17
 
17
18
  module CPEE
18
19
  module Notifications
19
20
 
20
21
  def self::implementation(id,opts)
21
22
  Proc.new do
22
- on resource "notifications" do
23
- run CPEE::Notifications::Overview if get
24
- on resource "topics" do
25
- run CPEE::Notifications::Topics, opts if get
26
- end
27
- on resource "subscriptions" do
28
- run CPEE::Notifications::Subscriptions, id, opts if get
29
- run CPEE::Notifications::CreateSubscription, id, opts if post 'create_subscription'
30
- on resource do
31
- run CPEE::Notifications::Subscription, id, opts if get
32
- run CPEE::Notifications::UpdateSubscription, id, opts if put 'change_subscription'
33
- run CPEE::Notifications::DeleteSubscription, id, opts if delete
34
- on resource 'sse' do
35
- run CPEE::Notifications::SSE, id, opts if sse
23
+ if CPEE::Persistence::exists?(id,opts)
24
+ on resource "notifications" do
25
+ run CPEE::Notifications::Overview if get
26
+ on resource "topics" do
27
+ run CPEE::Notifications::Topics, opts if get
28
+ end
29
+ on resource "subscriptions" do
30
+ run CPEE::Notifications::Subscriptions, id, opts if get
31
+ run CPEE::Notifications::CreateSubscription, id, opts if post 'create_subscription'
32
+ on resource do
33
+ run CPEE::Notifications::Subscription, id, opts if get
34
+ run CPEE::Notifications::UpdateSubscription, id, opts if put 'change_subscription'
35
+ run CPEE::Notifications::DeleteSubscription, id, opts if delete
36
+ on resource 'sse' do
37
+ run CPEE::Notifications::SSE, id, opts if sse
38
+ end
36
39
  end
37
40
  end
38
41
  end
42
+ else
43
+ run CPEE::FAIL
39
44
  end
40
45
  end
41
46
  end
@@ -184,7 +189,7 @@ module CPEE
184
189
  on.pmessage do |pat, what, message|
185
190
  if pat == 'forward:*'
186
191
  id, key = what.match(/forward:([^\/]+)\/(.+)/).captures
187
- if sse = opts.dig(:sse_connections,id.to_i,key)
192
+ if sse = opts.dig(:sse_connections,id,key)
188
193
  sse.send message
189
194
  else
190
195
  DeleteSubscription::set(id,opts,key)
@@ -193,7 +198,7 @@ module CPEE
193
198
  mess = JSON.parse(message[message.index(' ')+1..-1])
194
199
  state = mess.dig('content','state')
195
200
  if state == 'finished' || state == 'abandoned'
196
- opts.dig(:sse_connections,mess.dig('instance').to_i)&.each do |key,sse|
201
+ opts.dig(:sse_connections,mess.dig('instance').to_s)&.each do |key,sse|
197
202
  EM.add_timer(10) do # just to be sure that all messages arrived. 10 seconds should be enough ... we think ... therefore we are (not sure)
198
203
  sse.close
199
204
  end
@@ -214,7 +219,7 @@ module CPEE
214
219
  class SSE < Riddl::SSEImplementation #{{{
215
220
  def onopen
216
221
  @opts = @a[1]
217
- @id = @a[0]
222
+ @id = @a[0].to_s
218
223
  @key = @r[-2]
219
224
  if CPEE::Persistence::exists_handler?(@id,@opts,@key)
220
225
  @opts[:sse_connections][@id] ||= {}
@@ -13,6 +13,7 @@
13
13
  # <http://www.gnu.org/licenses/>.
14
14
 
15
15
  require_relative 'attributes_helper'
16
+ require_relative 'fail'
16
17
  require_relative 'value_helper'
17
18
  require 'json'
18
19
  require 'erb'
@@ -25,71 +26,75 @@ module CPEE
25
26
 
26
27
  def self::implementation(id,opts)
27
28
  Proc.new do
28
- run CPEE::Properties::Get, id, opts if get
29
- run CPEE::Properties::Patch, id, opts if patch 'set-some-properties'
30
- run CPEE::Properties::Put, id, opts if put 'set-some-properties'
31
- on resource 'state' do
32
- run CPEE::Properties::GetStateMachine, id, opts if get 'machine'
33
- run CPEE::Properties::GetState, id, opts if get
34
- run CPEE::Properties::PutState, id, opts if put 'state'
35
- on resource '@changed' do
36
- run CPEE::Properties::GetStateChanged, id, opts if get
37
- end
38
- end
39
- on resource 'status' do
40
- run CPEE::Properties::GetStatus, id, opts if get
41
- run CPEE::Properties::PutStatus, id, opts if put 'status'
42
- on resource 'id' do
43
- run CPEE::Properties::GetStatusID, id, opts if get
44
- end
45
- on resource 'message' do
46
- run CPEE::Properties::GetStatusMessage, id, opts if get
47
- end
48
- end
49
- on resource 'executionhandler' do
50
- run CPEE::Properties::GetExecutionHandler, id, opts if get
51
- run CPEE::Properties::PutExecutionHandler, id, opts if put 'executionhandler'
52
- end
53
- on resource 'positions' do
54
- run CPEE::Properties::GetPositions, id, opts if get
55
- run CPEE::Properties::PatchPositions, id, opts if patch 'positions'
56
- run CPEE::Properties::PutPositions, id, opts if put 'positions'
57
- run CPEE::Properties::PostPositions, id, opts if post 'position'
58
- on resource do
59
- run CPEE::Properties::GetDetail, 'positions', id, opts if get
60
- run CPEE::Properties::SetDetail, id, opts if put 'detail'
61
- run CPEE::Properties::DelDetail, id, opts if delete
62
- on resource '@passthrough' do
63
- run CPEE::Properties::GetPt, id, opts if get
29
+ if CPEE::Persistence::exists?(id,opts)
30
+ run CPEE::Properties::Get, id, opts if get
31
+ run CPEE::Properties::Patch, id, opts if patch 'set-some-properties'
32
+ run CPEE::Properties::Put, id, opts if put 'set-some-properties'
33
+ on resource 'state' do
34
+ run CPEE::Properties::GetStateMachine, id, opts if get 'machine'
35
+ run CPEE::Properties::GetState, id, opts if get
36
+ run CPEE::Properties::PutState, id, opts if put 'state'
37
+ on resource '@changed' do
38
+ run CPEE::Properties::GetStateChanged, id, opts if get
64
39
  end
65
40
  end
66
- end
67
- %w{dataelements endpoints attributes}.each do |ele|
68
- on resource ele do
69
- run CPEE::Properties::GetItems, ele, id, opts if get
70
- run CPEE::Properties::PatchItems, ele, id, opts if patch ele
71
- run CPEE::Properties::PutItems, ele, id, opts if put ele
72
- run CPEE::Properties::PostItem, ele, id, opts if post ele[0..-2]
41
+ on resource 'status' do
42
+ run CPEE::Properties::GetStatus, id, opts if get
43
+ run CPEE::Properties::PutStatus, id, opts if put 'status'
44
+ on resource 'id' do
45
+ run CPEE::Properties::GetStatusID, id, opts if get
46
+ end
47
+ on resource 'message' do
48
+ run CPEE::Properties::GetStatusMessage, id, opts if get
49
+ end
50
+ end
51
+ on resource 'executionhandler' do
52
+ run CPEE::Properties::GetExecutionHandler, id, opts if get
53
+ run CPEE::Properties::PutExecutionHandler, id, opts if put 'executionhandler'
54
+ end
55
+ on resource 'positions' do
56
+ run CPEE::Properties::GetPositions, id, opts if get
57
+ run CPEE::Properties::PatchPositions, id, opts if patch 'positions'
58
+ run CPEE::Properties::PutPositions, id, opts if put 'positions'
59
+ run CPEE::Properties::PostPositions, id, opts if post 'position'
73
60
  on resource do
74
- run CPEE::Properties::GetItem, ele, id, opts if get
75
- run CPEE::Properties::SetItem, ele, id, opts if put 'string'
76
- run CPEE::Properties::DelItem, ele, id, opts if delete
61
+ run CPEE::Properties::GetDetail, 'positions', id, opts if get
62
+ run CPEE::Properties::SetDetail, id, opts if put 'detail'
63
+ run CPEE::Properties::DelDetail, id, opts if delete
64
+ on resource '@passthrough' do
65
+ run CPEE::Properties::GetPt, id, opts if get
66
+ end
77
67
  end
78
68
  end
79
- end
80
- on resource 'dsl' do
81
- run CPEE::Properties::GetComplex, 'dsl', 'text/plain', id, opts if get
82
- end
83
- on resource 'dslx' do
84
- run CPEE::Properties::GetComplex, 'dslx', 'text/xml', id, opts if get
85
- end
86
- on resource 'description' do
87
- run CPEE::Properties::GetComplex, 'description', 'text/xml', id, opts if get
88
- run CPEE::Properties::PutDescription, id, opts if put 'description'
89
- end
90
- on resource 'transformation' do
91
- run CPEE::Properties::GetTransformation, id, opts if get
92
- run CPEE::Properties::PutTransformation, id, opts if put 'transformation'
69
+ %w{dataelements endpoints attributes}.each do |ele|
70
+ on resource ele do
71
+ run CPEE::Properties::GetItems, ele, id, opts if get
72
+ run CPEE::Properties::PatchItems, ele, id, opts if patch ele
73
+ run CPEE::Properties::PutItems, ele, id, opts if put ele
74
+ run CPEE::Properties::PostItem, ele, id, opts if post ele[0..-2]
75
+ on resource do
76
+ run CPEE::Properties::GetItem, ele, id, opts if get
77
+ run CPEE::Properties::SetItem, ele, id, opts if put 'string'
78
+ run CPEE::Properties::DelItem, ele, id, opts if delete
79
+ end
80
+ end
81
+ end
82
+ on resource 'dsl' do
83
+ run CPEE::Properties::GetComplex, 'dsl', 'text/plain', id, opts if get
84
+ end
85
+ on resource 'dslx' do
86
+ run CPEE::Properties::GetComplex, 'dslx', 'text/xml', id, opts if get
87
+ end
88
+ on resource 'description' do
89
+ run CPEE::Properties::GetComplex, 'description', 'text/xml', id, opts if get
90
+ run CPEE::Properties::PutDescription, id, opts if put 'description'
91
+ end
92
+ on resource 'transformation' do
93
+ run CPEE::Properties::GetTransformation, id, opts if get
94
+ run CPEE::Properties::PutTransformation, id, opts if put 'transformation'
95
+ end
96
+ else
97
+ run CPEE::FAIL
93
98
  end
94
99
  end
95
100
  end
data/lib/cpee/message.rb CHANGED
@@ -15,25 +15,27 @@
15
15
  module CPEE
16
16
 
17
17
  module Message
18
+ WHO = 'cpee'
19
+ TYPE = 'instance'
18
20
 
19
21
  def self::send(type, event, cpee, instance, instance_uuid, instance_name, content={}, backend)
20
22
  topic = ::File::dirname(event)
21
23
  name = ::File::basename(event)
24
+ payload = {
25
+ WHO => cpee,
26
+ TYPE + '-url' => File.join(cpee,instance.to_s),
27
+ TYPE => instance,
28
+ 'topic' => topic,
29
+ 'type' => type,
30
+ 'name' => name,
31
+ 'timestamp' => Time.now.xmlschema(3),
32
+ 'content' => content
33
+ }
34
+ payload[TYPE + '-uuid'] = instance_uuid if instance_uuid
35
+ payload[TYPE + '-name'] = instance_name if instance_name
22
36
  backend.publish(type.to_s + ':' + event,
23
37
  instance.to_s + ' ' +
24
- JSON::generate(
25
- { 'cpee' => cpee,
26
- 'instance-url' => File.join(cpee,instance.to_s),
27
- 'instance-uuid' => instance_uuid,
28
- 'instance-name' => instance_name,
29
- 'instance' => instance,
30
- 'topic' => topic,
31
- 'type' => type,
32
- 'name' => name,
33
- 'timestamp' => Time.now.xmlschema(3),
34
- 'content' => content
35
- }
36
- )
38
+ JSON::generate(payload)
37
39
  )
38
40
  end
39
41
 
@@ -15,6 +15,8 @@
15
15
  module CPEE
16
16
 
17
17
  module Persistence
18
+ OBJ = 'instance'
19
+
18
20
  def self::set_list(id,opts,item,values,deleted=[]) #{{{
19
21
  ah = AttributesHelper.new
20
22
  attributes = Persistence::extract_list(id,opts,'attributes').to_h
@@ -37,13 +39,13 @@ module CPEE
37
39
  )
38
40
  end #}}}
39
41
  def self::extract_set(id,opts,item) #{{{
40
- opts[:redis].smembers("instance:#{id}/#{item}").map do |e|
41
- [e,opts[:redis].get("instance:#{id}/#{item}/#{e}")]
42
+ opts[:redis].smembers(OBJ + ":#{id}/#{item}").map do |e|
43
+ [e,opts[:redis].get(OBJ + ":#{id}/#{item}/#{e}")]
42
44
  end
43
45
  end #}}}
44
46
  def self::extract_list(id,opts,item) #{{{
45
- opts[:redis].zrange("instance:#{id}/#{item}",0,-1).map do |e|
46
- [e,opts[:redis].get("instance:#{id}/#{item}/#{e}")]
47
+ opts[:redis].zrange(OBJ + ":#{id}/#{item}",0,-1).map do |e|
48
+ [e,opts[:redis].get(OBJ + ":#{id}/#{item}/#{e}")]
47
49
  end
48
50
  end #}}}
49
51
 
@@ -60,11 +62,32 @@ module CPEE
60
62
  )
61
63
  end #}}}
62
64
  def self::extract_item(id,opts,item) #{{{
63
- opts[:redis].get("instance:#{id}/#{item}")
65
+ opts[:redis].get(OBJ + ":#{id}/#{item}")
66
+ end #}}}
67
+
68
+ def self::exists?(id,opts) #{{{
69
+ opts[:redis].exists?(OBJ + ":#{id}/state")
64
70
  end #}}}
71
+ def self::is_member?(id,opts,item,value) #{{{
72
+ opts[:redis].sismember(OBJ + ":#{id}/#{item}",value)
73
+ end #}}}
74
+
75
+ def self::each_object(opts)
76
+ opts[:redis].zrevrange(OBJ + 's',0,-1).each do |instance|
77
+ yield instance
78
+ end
79
+ end
80
+
81
+ def self::new_object(opts)
82
+ opts[:redis].zrevrange(OBJ + 's', 0, 0).first.to_i + 1
83
+ end
84
+
85
+ def self::keys(id,opts,item=nil)
86
+ opts[:redis].keys(File.join(OBJ + ":#{id}",item.to_s,'*'))
87
+ end
65
88
 
66
89
  def self::set_handler(id,opts,key,url,values,update=false) #{{{
67
- exis = opts[:redis].smembers("instance:#{id}/handlers/#{key}")
90
+ exis = opts[:redis].smembers(OBJ + ":#{id}/handlers/#{key}")
68
91
 
69
92
  if update == false && exis.length > 0
70
93
  return 405
@@ -97,14 +120,14 @@ module CPEE
97
120
  200
98
121
  end #}}}
99
122
  def self::extract_handler(id,opts,key) #{{{
100
- opts[:redis].smembers("instance:#{id}/handlers/#{key}")
123
+ opts[:redis].smembers(OBJ + ":#{id}/handlers/#{key}")
101
124
  end #}}}
102
125
  def self::exists_handler?(id,opts,key) #{{{
103
- opts[:redis].exists?("instance:#{id}/handlers/#{key}")
126
+ opts[:redis].exists?(OBJ + ":#{id}/handlers/#{key}")
104
127
  end #}}}
105
128
  def self::extract_handlers(id,opts) #{{{
106
- opts[:redis].smembers("instance:#{id}/handlers").map do |e|
107
- [e, opts[:redis].get("instance:#{id}/handlers/#{e}/url")]
129
+ opts[:redis].smembers(OBJ + ":#{id}/handlers").map do |e|
130
+ [e, opts[:redis].get(OBJ + ":#{id}/handlers/#{e}/url")]
108
131
  end
109
132
  end #}}}
110
133
  end
@@ -149,10 +149,8 @@ class ConnectionWrapper < WEEL::ConnectionWrapperBase
149
149
  def activity_handle(passthrough, parameters) # {{{
150
150
  raise "Wrong endpoint" if @handler_endpoint.nil? || @handler_endpoint.empty?
151
151
  @label = parameters[:label]
152
- @sensors = parameters.dig(:stream,:sensors)
153
- @aggregators = parameters.dig(:stream,:aggregators)
154
- @costs = parameters.dig(:stream,:costs)
155
- @controller.notify("activity/calling", :'activity-uuid' => @handler_activity_uuid, :label => @label, :activity => @handler_position, :passthrough => passthrough, :endpoint => @handler_endpoint, :parameters => parameters)
152
+ @anno = parameters.delete(:annotations) rescue nil
153
+ @controller.notify("activity/calling", :'activity-uuid' => @handler_activity_uuid, :label => @label, :activity => @handler_position, :passthrough => passthrough, :endpoint => @handler_endpoint, :parameters => parameters, :annotations => @anno)
156
154
  if passthrough.to_s.empty?
157
155
  proto_curl parameters
158
156
  else
@@ -200,7 +198,7 @@ class ConnectionWrapper < WEEL::ConnectionWrapperBase
200
198
  @controller.notify("status/change", :'activity-uuid' => @handler_activity_uuid, :endpoint => @handler_endpoint, :label => @label, :activity => @handler_position, :id => status.id, :message => status.message)
201
199
  end
202
200
  unless changed_dataelements.nil? || changed_dataelements.empty?
203
- de = dataelements.slice(*changed_dataelements).transform_values { |v| enc = detect_encoding(v); (enc == 'OTHER' ? v.inspect : (v.encode('UTF-8',enc) rescue convert_to_base64(v))) }
201
+ de = dataelements.slice(*changed_dataelements).transform_values { |v| enc = detect_encoding(v); (enc == 'OTHER' ? v : (v.encode('UTF-8',enc) rescue convert_to_base64(v))) }
204
202
  @controller.notify("dataelements/change", :'activity-uuid' => @handler_activity_uuid, :endpoint => @handler_endpoint, :label => @label, :activity => @handler_position, :changed => changed_dataelements, :values => de)
205
203
  end
206
204
  unless changed_endpoints.nil? || changed_endpoints.empty?
@@ -222,6 +220,8 @@ class ConnectionWrapper < WEEL::ConnectionWrapperBase
222
220
  elsif result[0].is_a? Riddl::Parameter::Complex
223
221
  if result[0].mimetype == 'application/json'
224
222
  result = JSON::parse(result[0].value.read) rescue nil
223
+ elsif result[0].mimetype == 'text/yaml'
224
+ result = YAML::load(result[0].value.read) rescue nil
225
225
  elsif result[0].mimetype == 'application/xml' || result[0].mimetype == 'text/xml'
226
226
  result = XML::Smart::string(result[0].value.read) rescue nil
227
227
  elsif result[0].mimetype == 'text/plain'
@@ -278,7 +278,7 @@ class ConnectionWrapper < WEEL::ConnectionWrapperBase
278
278
  ''
279
279
  else
280
280
  enc = detect_encoding(ttt)
281
- enc == 'OTHER' ? ttt.inspect : (ttt.encode('UTF-8',enc) rescue convert_to_base64(ttt))
281
+ enc == 'OTHER' ? ttt : (ttt.encode('UTF-8',enc) rescue convert_to_base64(ttt))
282
282
  end
283
283
  elsif r.mimetype == 'text/plain' || r.mimetype == 'text/html'
284
284
  ttt = r.value.read
@@ -303,7 +303,7 @@ class ConnectionWrapper < WEEL::ConnectionWrapperBase
303
303
  end
304
304
 
305
305
  def callback(result=nil,options={})
306
- @controller.notify("activity/receiving", :'activity-uuid' => @handler_activity_uuid, :label => @label, :activity => @handler_position, :endpoint => @handler_endpoint, :received => structurize_result(result), :sensors => @sensors, :aggregators => @aggregators, :costs => @costs)
306
+ @controller.notify("activity/receiving", :'activity-uuid' => @handler_activity_uuid, :label => @label, :activity => @handler_position, :endpoint => @handler_endpoint, :received => structurize_result(result), :annotations => @anno)
307
307
  @guard_files += result
308
308
  @handler_returnValue = simplify_result(result)
309
309
  @handler_returnOptions = options
@@ -21,6 +21,7 @@ require 'cpee/value_helper'
21
21
  require 'cpee/attributes_helper'
22
22
  require 'cpee/message'
23
23
  require 'cpee/redis'
24
+ require 'cpee/persistence'
24
25
 
25
26
  require 'ostruct'
26
27
  class ParaStruct < OpenStruct
@@ -41,8 +42,8 @@ class Controller
41
42
  @id = id
42
43
 
43
44
  @attributes = {}
44
- @redis.keys("instance:#{id}/attributes/*").each do |key|
45
- @attributes[File.basename(key)] = @redis.get(key)
45
+ CPEE::Persistence::extract_list(id,opts,'attributes').each do |de|
46
+ @attributes[de[0]] = de[1]
46
47
  end
47
48
 
48
49
  @attributes_helper = AttributesHelper.new
@@ -152,7 +153,8 @@ class Controller
152
153
  topic, name = what.split('/')
153
154
  handler = File.join(topic,'vote',name)
154
155
  votes = []
155
- @redis.smembers("instance:#{id}/handlers/#{handler}").each do |client|
156
+
157
+ CPEE::Persistence::extract_handler(id,@opts,handler).each do |client|
156
158
  voteid = Digest::MD5.hexdigest(Kernel::rand().to_s)
157
159
  content[:key] = voteid
158
160
  content[:attributes] = attributes_translated