cpee-instantiation 1.0.14 → 1.0.15

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3fe76889766f1a2333a1cf46f15b9edc35742ff55f2abbc5afadf59e4222ee00
4
- data.tar.gz: 4e92630e731a9b196415c69dbd647145fda7a76873e6c8f8a7afb738cb563692
3
+ metadata.gz: 5c23817dd7f311a2fb3aebbc31f9ed5f1932e25e22488130d7addda9f2f15b8f
4
+ data.tar.gz: 6c5c351281740cfcd40ae78fb9ce67d142b9d83b25cdfbdb47827644193043f2
5
5
  SHA512:
6
- metadata.gz: 551718de37d55ab2795370c873d310067e010877cfd915554cd34470fdcbd710c01b0afca5d50827e0098e33037bc3dc7f30147b6413c266932b189eaf31ccae
7
- data.tar.gz: 01c916c086d25d62e1ce5c0e63d2455d082dc8da74c3ec000a66c1c915f9dd47b0db0499effc1bc306ac411f9e8dfc969e7bb2307d47ebc63101e06a48d6f0f1
6
+ metadata.gz: 577f3fba43cf9b01fc05ecabf80c0a77b66badb079fafacbd134aeb9eeb672659ef9b7b2f92bca8c3de68c169c3ddb00addd7a6384f19b7c7550a8a93aae794b
7
+ data.tar.gz: 6940775373011a269261141becf5dd1772992ed8a3d30717654d934210a4d5e4f79942473ba7ce3c3b0e18867bfeb3fcf4a8ff4524d7730f00edf9c378f01614
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "cpee-instantiation"
3
- s.version = "1.0.14"
3
+ s.version = "1.0.15"
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.license = "LGPL-3.0"
6
6
  s.summary = "Subprocess instantiation service for the cloud process execution engine (cpee.org)"
@@ -30,72 +30,100 @@ module CPEE
30
30
  SERVER = File.expand_path(File.join(__dir__,'instantiation.xml'))
31
31
 
32
32
  module Helpers #{{{
33
- def load_testset(tdoc,cpee,name=nil,customization=nil) #{{{
33
+ def add_to_testset(tdoc,what,data)
34
+ if data && !data.empty?
35
+ JSON::parse(data).each do |k,v|
36
+ ele = tdoc.find("/*/prop:#{what}/prop:#{k}")
37
+ if ele.any?
38
+ ele.first.text = CPEE::ValueHelper::generate(v)
39
+ else
40
+ ele = tdoc.find("/*/prop:#{what}")
41
+ ele.first.add(k,CPEE::ValueHelper::generate(v)) if ele.any?
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ def augment_testset(tdoc,p)
48
+ tdoc = XML::Smart.string(tdoc)
49
+ tdoc.register_namespace 'desc', 'http://cpee.org/ns/description/1.0'
50
+ tdoc.register_namespace 'prop', 'http://cpee.org/ns/properties/2.0'
51
+ tdoc.register_namespace 'sub', 'http://riddl.org/ns/common-patterns/notifications-producer/2.0'
52
+
53
+ if data = p.find{ |e| e.name == 'init' }&.value
54
+ add_to_testset(tdoc,'dataelements',data)
55
+ end
56
+ if data = p.find{ |e| e.name == 'endpoints' }&.value
57
+ add_to_testset(tdoc,'endpoints',data)
58
+ end
59
+ if data = p.find{ |e| e.name == 'attributes' }&.value
60
+ add_to_testset(tdoc,'attributes',data)
61
+ end
62
+ tdoc
63
+ end
64
+
65
+ def load_testset(doc,cpee,name=nil,customization=nil) #{{{
34
66
  ins = -1
35
67
  uuid = nil
36
- XML::Smart.string(tdoc) do |doc|
37
- doc.register_namespace 'desc', 'http://cpee.org/ns/description/1.0'
38
- doc.register_namespace 'prop', 'http://cpee.org/ns/properties/2.0'
39
- doc.register_namespace 'sub', 'http://riddl.org/ns/common-patterns/notifications-producer/2.0'
40
68
 
41
- srv = Riddl::Client.new(cpee, File.join(cpee,'?riddl-description'))
42
- res = srv.resource('/')
43
- if name
44
- doc.find('/*/prop:attributes/prop:info').each do |e|
45
- e.text = name
46
- end
69
+ srv = Riddl::Client.new(cpee, File.join(cpee,'?riddl-description'))
70
+ res = srv.resource('/')
71
+ if name
72
+ doc.find('/*/prop:attributes/prop:info').each do |e|
73
+ e.text = name
47
74
  end
48
- if customization && !customization.empty?
49
- JSON.parse(customization).each do |e|
50
- begin
51
- customization = Typhoeus.get e['url']
52
- if customization.success?
53
- XML::Smart::string(customization.response_body) do |str|
54
- doc.find("//desc:call[@id=\"#{e['id']}\"]/desc:parameters/desc:customization").each do |ele|
55
- ele.replace_by str.root
56
- end
75
+ end
76
+ if customization && !customization.empty?
77
+ JSON.parse(customization).each do |e|
78
+ begin
79
+ customization = Typhoeus.get e['url']
80
+ if customization.success?
81
+ XML::Smart::string(customization.response_body) do |str|
82
+ doc.find("//desc:call[@id=\"#{e['id']}\"]/desc:parameters/desc:customization").each do |ele|
83
+ ele.replace_by str.root
57
84
  end
58
85
  end
59
- rescue => e
60
- puts e.message
61
- puts e.backtrace
62
86
  end
87
+ rescue => e
88
+ puts e.message
89
+ puts e.backtrace
63
90
  end
64
91
  end
92
+ end
65
93
 
66
- status, response, headers = res.post Riddl::Parameter::Simple.new('info',doc.find('string(/*/prop:attributes/prop:info)'))
94
+ status, response, headers = res.post Riddl::Parameter::Simple.new('info',doc.find('string(/*/prop:attributes/prop:info)'))
67
95
 
68
- if status == 200
69
- ins = response.first.value
70
- uuid = headers['CPEE_INSTANCE_UUID']
96
+ if status == 200
97
+ ins = response.first.value
98
+ uuid = headers['CPEE_INSTANCE_UUID']
71
99
 
72
- inp = XML::Smart::string('<properties xmlns="http://cpee.org/ns/properties/2.0"/>')
73
- inp.register_namespace 'prop', 'http://cpee.org/ns/properties/2.0'
74
- %w{executionhandler positions dataelements endpoints attributes description transformation}.each do |item|
75
- ele = doc.find("/*/prop:#{item}")
76
- inp.root.add(ele.first) if ele.any?
100
+ inp = XML::Smart::string('<properties xmlns="http://cpee.org/ns/properties/2.0"/>')
101
+ inp.register_namespace 'prop', 'http://cpee.org/ns/properties/2.0'
102
+ %w{executionhandler positions dataelements endpoints attributes description transformation}.each do |item|
103
+ ele = doc.find("/*/prop:#{item}")
104
+ inp.root.add(ele.first) if ele.any?
105
+ end
106
+
107
+ res = srv.resource("/#{ins}/properties").put Riddl::Parameter::Complex.new('properties','application/xml',inp.to_s)
108
+ # TODO new versions
109
+ doc.find('/*/sub:subscriptions/sub:subscription').each do |s|
110
+ parts = []
111
+ if id = s.attributes['id']
112
+ parts << Riddl::Parameter::Simple.new('id', id)
77
113
  end
78
- res = srv.resource("/#{ins}/properties").put Riddl::Parameter::Complex.new('properties','application/xml',inp.to_s)
79
- # TODO new versions
80
- doc.find('/*/sub:subscriptions/sub:subscription').each do |s|
81
- parts = []
82
- if id = s.attributes['id']
83
- parts << Riddl::Parameter::Simple.new('id', id)
114
+ parts << Riddl::Parameter::Simple.new('url', s.attributes['url'])
115
+ s.find('sub:topic').each do |t|
116
+ if (evs = t.find('sub:event').map{ |e| e.text }.join(',')).length > 0
117
+ parts << Riddl::Parameter::Simple.new('topic', t.attributes['id'])
118
+ parts << Riddl::Parameter::Simple.new('events', evs)
84
119
  end
85
- parts << Riddl::Parameter::Simple.new('url', s.attributes['url'])
86
- s.find('sub:topic').each do |t|
87
- if (evs = t.find('sub:event').map{ |e| e.text }.join(',')).length > 0
88
- parts << Riddl::Parameter::Simple.new('topic', t.attributes['id'])
89
- parts << Riddl::Parameter::Simple.new('events', evs)
90
- end
91
- if (vos = t.find('sub:vote').map{ |e| e.text }.join(',')).length > 0
92
- parts << Riddl::Parameter::Simple.new('topic', t.attributes['id'])
93
- parts << Riddl::Parameter::Simple.new('votes', vos)
94
- end
120
+ if (vos = t.find('sub:vote').map{ |e| e.text }.join(',')).length > 0
121
+ parts << Riddl::Parameter::Simple.new('topic', t.attributes['id'])
122
+ parts << Riddl::Parameter::Simple.new('votes', vos)
95
123
  end
96
- status,body = Riddl::Client::new(cpee+ins+'/notifications/subscriptions/').post parts
97
- end rescue nil # in case just no subs are there
98
- end
124
+ end
125
+ status,body = Riddl::Client::new(cpee+ins+'/notifications/subscriptions/').post parts
126
+ end rescue nil # in case just no subs are there
99
127
  end
100
128
  [ins, uuid]
101
129
  end #}}}
@@ -124,6 +152,7 @@ module CPEE
124
152
  private :handle_waiting
125
153
  def handle_starting(cpee,instance,behavior) #{{{
126
154
  if behavior =~ /_running$/
155
+ sleep 0.5
127
156
  srv = Riddl::Client.new(cpee, File.join(cpee,'?riddl-description'))
128
157
  res = srv.resource("/#{instance}/properties/state")
129
158
  status, response = res.put [
@@ -188,20 +217,12 @@ module CPEE
188
217
  (@status = 500) && return
189
218
  end
190
219
  customization = @p.find{ |e| e.name == 'customization' }&.value
220
+
221
+ tdoc = augment_testset(tdoc,@p)
191
222
  if (instance, uuid = load_testset(tdoc,cpee,nil,customization)).first == -1
192
223
  @status = 500
193
224
  else
194
225
  EM.defer do
195
- if x = @p.find{ |e| e.name == 'init' }&.value
196
- handle_data cpee, instance, x
197
- end
198
- if x = @p.find{ |e| e.name == 'endpoints' }&.value
199
- handle_endpoints cpee, instance, x
200
- end
201
- if x = @p.find{ |e| e.name == 'attributes' }&.value
202
- handle_attributes cpee, instance, x
203
- end
204
-
205
226
  handle_waiting cpee, instance, uuid, @p[0].value, selfurl, cblist
206
227
  handle_starting cpee, instance, @p[0].value
207
228
  end
@@ -237,20 +258,12 @@ module CPEE
237
258
  (@status = 500) && return
238
259
  end
239
260
  customization = @p.find{ |e| e.name == 'customization' }&.value
261
+
262
+ tdoc = augment_testset(tdoc,@p)
240
263
  if (instance, uuid = load_testset(tdoc,cpee,name,customization)).first == -1
241
264
  @status = 500
242
265
  else
243
266
  EM.defer do
244
- if x = @p.find{ |e| e.name == 'init' }&.value
245
- handle_data cpee, instance, x
246
- end
247
- if x = @p.find{ |e| e.name == 'endpoints' }&.value
248
- handle_endpoints cpee, instance, x
249
- end
250
- if x = @p.find{ |e| e.name == 'attributes' }&.value
251
- handle_attributes cpee, instance, x
252
- end
253
-
254
267
  handle_waiting cpee, instance, uuid, @p[0].value, selfurl, cblist
255
268
  handle_starting cpee, instance, @p[0].value
256
269
  end
@@ -285,11 +298,11 @@ module CPEE
285
298
  @p[data].value.read
286
299
  end
287
300
 
301
+ tdoc = augment_testset(tdoc,@p)
288
302
  if (instance, uuid = load_testset(tdoc,cpee)).first == -1
289
303
  @status = 500
290
304
  else
291
305
  EM.defer do
292
- handle_data cpee, instance, @p[data+1]&.value
293
306
  handle_waiting cpee, instance, uuid, behavior, selfurl, cblist
294
307
  handle_starting cpee, instance, behavior
295
308
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cpee-instantiation
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.14
4
+ version: 1.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juergen eTM Mangler
8
8
  autorequire:
9
9
  bindir: tools
10
10
  cert_chain: []
11
- date: 2022-06-08 00:00:00.000000000 Z
11
+ date: 2022-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: riddl