cpee-instantiation 1.0.24 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2b92cd471892d3eef55e68e3684b33cdeab451ca7844cc381a220fe10dd62e7a
4
- data.tar.gz: bb7ac9554eb9226c37c77937da6f32afe9b21187db9bef9a2b8460c90b03d086
3
+ metadata.gz: f6021132f4bec9ae574abbb13f9adfdc5806c5113ea3bdd3c563cef0db5694d8
4
+ data.tar.gz: 4fdbd5157ba88eb6c33b7e0eb413427530a75e4273ccbdad87bb0bc3ef6f40c1
5
5
  SHA512:
6
- metadata.gz: ea47cf96378fbd39c8661a7c1e5054d193a662deac7626e80777ebedbf8eb41520a17c734167581d9257946073cf6cc8b1d3efde4f1b895fff51d44c9768cbbe
7
- data.tar.gz: fcf4c3d6c298531f2cad59d75b4144cd618d17597f32bde9f52ae88959a120ce3d3c2873495a30cb76771b1554ca33fdf0c06bd0c10fa2863f37933b6ce61547
6
+ metadata.gz: d06cdffce5e269adc97c7f868b5751b9f132a49169e6b8f64c44648a3f155421042debbf0b96d1839400ae95fa245401c6c6ded9237151787ed84abe798287f7
7
+ data.tar.gz: 00d3a630016867cd29d4f467a136fc0c965f4557bdf4af8c87ede4148ff1997f9a25e1ec97a30a6c217f91edd12132c09b81ad15b39bce65e30d9de74c0a65a0
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "cpee-instantiation"
3
- s.version = "1.0.24"
3
+ s.version = "1.1.0"
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)"
@@ -23,5 +23,5 @@ Gem::Specification.new do |s|
23
23
  s.add_runtime_dependency 'riddl', '~> 1.0'
24
24
  s.add_runtime_dependency 'json', '~> 2.1'
25
25
  s.add_runtime_dependency 'redis', '~> 5.0'
26
- s.add_runtime_dependency 'cpee', '~> 2.1', '>= 2.1.4'
26
+ s.add_runtime_dependency 'cpee', '~> 2.1', '>= 2.1.74'
27
27
  end
@@ -25,6 +25,8 @@ require 'uri'
25
25
  require 'redis'
26
26
  require 'json'
27
27
 
28
+ require 'pry'
29
+
28
30
  require_relative 'utils'
29
31
 
30
32
  module CPEE
@@ -33,7 +35,8 @@ module CPEE
33
35
  SERVER = File.expand_path(File.join(__dir__,'instantiation.xml'))
34
36
 
35
37
  module Helpers #{{{
36
- def add_to_testset(tdoc,what,data)
38
+
39
+ def add_to_testset(tdoc,what,data) #{{{
37
40
  if data && !data.empty?
38
41
  JSON::parse(data).each do |k,v|
39
42
  ele = tdoc.find("/*/prop:#{what}/prop:#{k}")
@@ -50,9 +53,9 @@ module CPEE
50
53
  end
51
54
  end
52
55
  end
53
- end
56
+ end #}}}
54
57
 
55
- def augment_testset(tdoc,p)
58
+ def augment_testset(tdoc,p) #{{{
56
59
  tdoc = XML::Smart.string(tdoc)
57
60
  tdoc.register_namespace 'desc', 'http://cpee.org/ns/description/1.0'
58
61
  tdoc.register_namespace 'prop', 'http://cpee.org/ns/properties/2.0'
@@ -68,19 +71,9 @@ module CPEE
68
71
  add_to_testset(tdoc,'attributes',data)
69
72
  end
70
73
  tdoc
71
- end
72
-
73
- def load_testset(doc,cpee,name=nil,customization=nil) #{{{
74
- ins = -1
75
- uuid = nil
74
+ end #}}}
76
75
 
77
- srv = Riddl::Client.new(cpee, File.join(cpee,'?riddl-description'))
78
- res = srv.resource('/')
79
- if name
80
- doc.find('/*/prop:attributes/prop:info').each do |e|
81
- e.text = name
82
- end
83
- end
76
+ def customize_testset(customization,doc) #{{{
84
77
  if customization && !customization.empty?
85
78
  JSON.parse(customization).each do |e|
86
79
  begin
@@ -98,125 +91,76 @@ module CPEE
98
91
  end
99
92
  end
100
93
  end
94
+ end #}}}
101
95
 
102
- status, response, headers = res.post Riddl::Parameter::Simple.new('info',doc.find('string(/*/prop:attributes/prop:info)'))
103
-
104
- if status == 200
105
- ins = response.first.value
106
- uuid = headers['CPEE_INSTANCE_UUID']
96
+ def add_waiting_to_testset(behavior,cb,doc,selfurl) #{{{
97
+ ckb = nil
98
+ if behavior =~ /^wait/
99
+ condition = behavior.match(/_([^_]+)_/)&.[](1) || 'finished'
107
100
 
108
- inp = XML::Smart::string('<properties xmlns="http://cpee.org/ns/properties/2.0"/>')
109
- inp.register_namespace 'prop', 'http://cpee.org/ns/properties/2.0'
110
- %w{executionhandler positions dataelements endpoints attributes description transformation}.each do |item|
111
- ele = doc.find("/*/prop:#{item}")
112
- inp.root.add(ele.first) if ele.any?
101
+ if cb
102
+ cbk = '_instantiation_' + Digest::MD5.hexdigest(Kernel::rand().to_s)
103
+ n = doc.find('/*/sub:subscriptions') rescue []
104
+ if (n.empty?)
105
+ n = doc.root.add('subscriptions')
106
+ n.namespaces.add(nil,'http://riddl.org/ns/common-patterns/notifications-producer/2.0')
107
+ end
108
+ n.append('subscription', :id => cbk, :url => File.join(selfurl,'callback',cbk))
109
+ .append('topic', :id => 'state')
110
+ .append('event','change')
113
111
  end
112
+ end
113
+ [cbk, condition]
114
+ end #}}}
114
115
 
115
- res = srv.resource("/#{ins}/properties").put Riddl::Parameter::Complex.new('properties','application/xml',inp.to_s)
116
- # TODO new versions
117
- doc.find('/*/sub:subscriptions/sub:subscription').each do |s|
118
- parts = []
119
- if id = s.attributes['id']
120
- parts << Riddl::Parameter::Simple.new('id', id)
121
- end
122
- parts << Riddl::Parameter::Simple.new('url', s.attributes['url'])
123
- s.find('sub:topic').each do |t|
124
- if (evs = t.find('sub:event').map{ |e| e.text }.join(',')).length > 0
125
- parts << Riddl::Parameter::Simple.new('topic', t.attributes['id'])
126
- parts << Riddl::Parameter::Simple.new('events', evs)
127
- end
128
- if (vos = t.find('sub:vote').map{ |e| e.text }.join(',')).length > 0
129
- parts << Riddl::Parameter::Simple.new('topic', t.attributes['id'])
130
- parts << Riddl::Parameter::Simple.new('votes', vos)
131
- end
132
- end
133
- status,body = Riddl::Client::new(cpee+ins+'/notifications/subscriptions/').post parts
134
- end rescue nil # in case just no subs are there
116
+ def add_running_to_testset(behavior,doc) #{{{
117
+ if behavior =~ /_running$/
118
+ if ((doc.find('/*/prop:state')).empty?)
119
+ doc.root.append('prop:state','running')
120
+ else
121
+ doc.find('/*/prop:state').first.text = 'running'
122
+ end
135
123
  end
136
- [ins, uuid]
137
- end #}}}
138
- private :load_testset
139
- def handle_waiting(cpee,instance,uuid,behavior,selfurl,cblist) #{{{
140
- if behavior =~ /^wait/
141
- condition = behavior.match(/_([^_]+)_/)&.[](1) || 'finished'
142
- cb = @h['CPEE_CALLBACK']
124
+ end #}}}
143
125
 
144
- if cb
145
- cbk = SecureRandom.uuid
146
- srv = Riddl::Client.new(cpee, File.join(cpee,'?riddl-description'))
147
- status, response = srv.resource("/#{instance}/notifications/subscriptions/").post [
148
- Riddl::Parameter::Simple.new('url',File.join(selfurl,'callback',cbk)),
149
- Riddl::Parameter::Simple.new('topic','state'),
150
- Riddl::Parameter::Simple.new('events','change')
151
- ]
126
+ def instantiate_testset(cpee,doc,behavior,cblist,cbk,cb,condition) #{{{
127
+ status, res, headers = Riddl::Client.new(cpee).post Riddl::Parameter::Complex.new('testset', 'application/xml', doc.to_s)
128
+ if status == 200
129
+ instance = res.first.value
130
+ uuid = headers['CPEE_INSTANCE_UUID']
131
+
132
+ if cbk
152
133
  cblist.rpush(cbk, cb)
153
134
  cblist.rpush(cbk, condition)
154
135
  cblist.rpush(cbk, instance)
155
136
  cblist.rpush(cbk, uuid)
156
137
  cblist.rpush(cbk, File.join(cpee,instance))
138
+ @headers << Riddl::Header.new('CPEE-CALLBACK','true')
157
139
  end
140
+
141
+ send = {
142
+ 'CPEE-INSTANCE' => instance,
143
+ 'CPEE-INSTANCE-URL' => File.join(cpee,instance),
144
+ 'CPEE-INSTANCE-UUID' => uuid,
145
+ 'CPEE-BEHAVIOR' => behavior
146
+ }
147
+ @headers << Riddl::Header.new('CPEE-INSTANTIATION',JSON::generate(send))
148
+ Riddl::Parameter::Complex.new('instance','application/json',JSON::generate(send))
149
+ else
150
+ @status = 500
158
151
  end
159
152
  end #}}}
160
- private :handle_waiting
161
- def handle_starting(cpee,instance,behavior) #{{{
162
- if behavior =~ /_running$/
163
- sleep 0.5
164
- srv = Riddl::Client.new(cpee, File.join(cpee,'?riddl-description'))
165
- res = srv.resource("/#{instance}/properties/state")
166
- status, response = res.put [
167
- Riddl::Parameter::Simple.new('value','running')
168
- ]
169
- end
170
- end #}}}
171
- private :handle_starting
172
- def handle_data(cpee,instance,data) #{{{
173
- if data && !data.empty?
174
- content = XML::Smart.string('<dataelements xmlns="http://cpee.org/ns/properties/2.0"/>')
175
- JSON::parse(data).each do |k,v|
176
- content.root.add(k,CPEE::ValueHelper::generate(v))
177
- end
178
- srv = Riddl::Client.new(cpee, File.join(cpee,'?riddl-description'))
179
- res = srv.resource("/#{instance}/properties/dataelements/")
180
- status, response = res.patch [
181
- Riddl::Parameter::Complex.new('dataelements','text/xml',content.to_s)
182
- ]
183
- end rescue nil
184
- end #}}}
185
- def handle_endpoints(cpee,instance,data) #{{{
186
- if data && !data.empty?
187
- content = XML::Smart.string('<endpoints xmlns="http://cpee.org/ns/properties/2.0"/>')
188
- JSON::parse(data).each do |k,v|
189
- content.root.add(k,v)
190
- end
191
- srv = Riddl::Client.new(cpee, File.join(cpee,'?riddl-description'))
192
- res = srv.resource("/#{instance}/properties/endpoints/")
193
- status, response = res.patch [
194
- Riddl::Parameter::Complex.new('endpoints','text/xml',content.to_s)
195
- ]
196
- end rescue nil
197
- end #}}}
198
- def handle_attributes(cpee,instance,data) #{{{
199
- if data && !data.empty?
200
- content = XML::Smart.string('<attributes xmlns="http://cpee.org/ns/properties/2.0"/>')
201
- JSON::parse(data).each do |k,v|
202
- content.root.add(k,v)
203
- end
204
- srv = Riddl::Client.new(cpee, File.join(cpee,'?riddl-description'))
205
- res = srv.resource("/#{instance}/properties/attributes/")
206
- status, response = res.patch [
207
- Riddl::Parameter::Complex.new('attributes','text/xml',content.to_s)
208
- ]
209
- end rescue nil
210
- end #}}}
153
+
211
154
  end #}}}
212
155
 
213
156
  class InstantiateGit < Riddl::Implementation #{{{
214
157
  include Helpers
215
158
 
216
159
  def response
217
- cpee = @h['X_CPEE'] || @a[0]
218
- selfurl = @a[1]
219
- cblist = @a[2]
160
+ cpee = @h['X_CPEE'] || @a[0]
161
+ selfurl = @a[1]
162
+ cblist = @a[2]
163
+ behavior = @p[0].value
220
164
 
221
165
  status, res = Riddl::Client.new(File.join(@p[1].value,'raw',@p[2].value,@p[3].value).gsub(/ /,'%20')).get
222
166
  tdoc = if status >= 200 && status < 300
@@ -226,27 +170,12 @@ module CPEE
226
170
  end
227
171
  customization = @p.find{ |e| e.name == 'customization' }&.value
228
172
 
229
- tdoc = augment_testset(tdoc,@p)
230
- if (instance, uuid = load_testset(tdoc,cpee,nil,customization)).first == -1
231
- @status = 500
232
- else
233
- EM.defer do
234
- handle_waiting cpee, instance, uuid, @p[0].value, selfurl, cblist
235
- handle_starting cpee, instance, @p[0].value
236
- end
173
+ doc = augment_testset(tdoc,@p)
174
+ customize_testset(customization,doc)
175
+ cbk, condition = add_waiting_to_testset(behavior,@h['CPEE_CALLBACK'],doc,selfurl)
176
+ add_running_to_testset(behavior,doc)
237
177
 
238
- send = {
239
- 'CPEE-INSTANCE' => instance,
240
- 'CPEE-INSTANCE-URL' => File.join(cpee,instance),
241
- 'CPEE-INSTANCE-UUID' => uuid,
242
- 'CPEE-BEHAVIOR' => @p[0].value
243
- }
244
- if @p[0].value =~ /^wait/
245
- @headers << Riddl::Header.new('CPEE-CALLBACK','true')
246
- end
247
- @headers << Riddl::Header.new('CPEE-INSTANTIATION',JSON::generate(send))
248
- Riddl::Parameter::Complex.new('instance','application/json',JSON::generate(send))
249
- end
178
+ instantiate_testset(cpee,doc,@p[0].value,cblist,cbk,@h['CPEE_CALLBACK'],condition)
250
179
  end
251
180
  end #}}}
252
181
 
@@ -254,10 +183,11 @@ module CPEE
254
183
  include Helpers
255
184
 
256
185
  def response
257
- cpee = @h['X_CPEE'] || @a[0]
258
- selfurl = @a[1]
259
- cblist = @a[2]
260
- name = @a[3] ? @p.shift.value : nil
186
+ cpee = @h['X_CPEE'] || @a[0]
187
+ selfurl = @a[1]
188
+ cblist = @a[2]
189
+ name = @a[3] ? @p.shift.value : nil
190
+ behavior = @p[0].value
261
191
 
262
192
  status, res = Riddl::Client.new(@p[1].value.gsub(/ /,'%20')).get
263
193
  tdoc = if status >= 200 && status < 300
@@ -267,31 +197,16 @@ module CPEE
267
197
  end
268
198
  customization = @p.find{ |e| e.name == 'customization' }&.value
269
199
 
270
- tdoc = augment_testset(tdoc,@p)
271
- if (instance, uuid = load_testset(tdoc,cpee,name,customization)).first == -1
272
- @status = 500
273
- else
274
- EM.defer do
275
- handle_waiting cpee, instance, uuid, @p[0].value, selfurl, cblist
276
- handle_starting cpee, instance, @p[0].value
277
- end
200
+ doc = augment_testset(tdoc,@p)
201
+ customize_testset(customization,doc)
202
+ cbk, condition = add_waiting_to_testset(behavior,@h['CPEE_CALLBACK'],doc,selfurl)
203
+ add_running_to_testset(behavior,doc)
278
204
 
279
- send = {
280
- 'CPEE-INSTANCE' => instance,
281
- 'CPEE-INSTANCE-URL' => File.join(cpee,instance),
282
- 'CPEE-INSTANCE-UUID' => uuid,
283
- 'CPEE-BEHAVIOR' => @p[0].value
284
- }
285
- if @p[0].value =~ /^wait/
286
- @headers << Riddl::Header.new('CPEE-CALLBACK','true')
287
- end
288
- @headers << Riddl::Header.new('CPEE-INSTANTIATION',JSON::generate(send))
289
- Riddl::Parameter::Complex.new('instance','application/json',JSON::generate(send))
290
- end
205
+ instantiate_testset(cpee,doc,@p[0].value,cblist,cbk,@h['CPEE_CALLBACK'],condition)
291
206
  end
292
- end #}}}
207
+ end #}}}
293
208
 
294
- class InstantiateXML < Riddl::Implementation #{{{
209
+ class InstantiateXML < Riddl::Implementation #{{{
295
210
  include Helpers
296
211
 
297
212
  def response
@@ -301,71 +216,18 @@ class InstantiateXML < Riddl::Implementation #{{{
301
216
  data = @a[1] ? 0 : 1
302
217
  selfurl = @a[2]
303
218
  cblist = @a[3]
304
- puts "Received data: #{@p}"
305
- puts "p[data]: #{@p[data]}"
306
219
  tdoc = if @p[data].additional =~ /base64/
307
220
  Base64.decode64(@p[data].value.read)
308
221
  else
309
222
  @p[data].value.read
310
223
  end
311
224
 
312
- tdoc = augment_testset(tdoc,@p)
313
- if (instance, uuid = load_testset(tdoc,cpee)).first == -1
314
- @status = 500
315
- else
316
- EM.defer do
317
- handle_waiting cpee, instance, uuid, behavior, selfurl, cblist
318
- handle_starting cpee, instance, behavior
319
- end
225
+ doc = augment_testset(tdoc,@p)
226
+ customize_testset(customization,doc)
227
+ cbk, condition = add_waiting_to_testset(behavior,@h['CPEE_CALLBACK'],doc,selfurl)
228
+ add_running_to_testset(behavior,doc)
320
229
 
321
- send = {
322
- 'CPEE-INSTANCE' => instance,
323
- 'CPEE-INSTANCE-URL' => File.join(cpee,instance),
324
- 'CPEE-INSTANCE-UUID' => uuid,
325
- 'CPEE-BEHAVIOR' => behavior
326
- }
327
- if @p[0].value =~ /^wait/
328
- @headers << Riddl::Header.new('CPEE-CALLBACK','true')
329
- end
330
- @headers << Riddl::Header.new('CPEE-INSTANTIATION',JSON::generate(send))
331
- Riddl::Parameter::Complex.new('instance','application/json',JSON::generate(send))
332
- end
333
- end
334
- end #}}}
335
-
336
- class HandleInstance < Riddl::Implementation #{{{
337
- include Helpers
338
-
339
- def response
340
- cpee = @h['X_CPEE'] || @a[0]
341
- selfurl = @a[1]
342
- cblist = @a[2]
343
- instance = @p[1].value
344
-
345
- srv = Riddl::Client.new(cpee)
346
- res = srv.resource("/#{instance}/properties/attributes/uuid/")
347
- status, response = res.get
348
-
349
- if status >= 200 && status < 300
350
- uuid = response.first.value
351
- handle_data cpee, instance, @p[2]&.value
352
- handle_waiting cpee, instance, uuid, @p[0].value, selfurl, cblist
353
- handle_starting cpee, instance, @p[0].value
354
-
355
- send = {
356
- 'CPEE-INSTANCE' => instance,
357
- 'CPEE-INSTANCE-URL' => File.join(cpee,instance),
358
- 'CPEE-INSTANCE-UUID' => uuid,
359
- 'CPEE-BEHAVIOR' => @p[0].value
360
- }
361
-
362
- if @p[0].value =~ /^wait/
363
- @headers << Riddl::Header.new('CPEE-CALLBACK','true')
364
- end
365
- Riddl::Parameter::Complex.new('instance','application/json',JSON::generate(send))
366
- else
367
- @status = 500
368
- end
230
+ instantiate_testset(cpee,doc,@p[0].value,cblist,cbk,@h['CPEE_CALLBACK'],condition)
369
231
  end
370
232
  end #}}}
371
233
 
@@ -394,7 +256,7 @@ class InstantiateXML < Riddl::Implementation #{{{
394
256
 
395
257
  if notification['content']['state'] == condition
396
258
  cblist.del(key)
397
- srv = Riddl::Client.new(cpee, File.join(cpee,'?riddl-description'))
259
+ srv = Riddl::Client.new(cpee)
398
260
  res = srv.resource("/#{instance}/properties/dataelements")
399
261
  status, response = res.get
400
262
  if status >= 200 && status < 300
@@ -413,7 +275,7 @@ class InstantiateXML < Riddl::Implementation #{{{
413
275
  end
414
276
  end
415
277
 
416
- end #}}}
278
+ end #}}}
417
279
 
418
280
  def self::implementation(opts)
419
281
  opts[:cpee] ||= 'http://localhost:9298/'
@@ -454,9 +316,6 @@ end #}}}
454
316
  on resource 'git' do
455
317
  run InstantiateGit, opts[:cpee], opts[:self], opts[:redis] if post 'git'
456
318
  end
457
- on resource 'instance' do
458
- run HandleInstance, opts[:cpee], opts[:self], opts[:redis] if post 'instance'
459
- end
460
319
  on resource 'callback' do
461
320
  on resource do
462
321
  run ContinueTask, opts[:cpee], opts[:redis] if post
@@ -136,6 +136,9 @@
136
136
  <post in="url" out="result"/>
137
137
  <post in="url_info" out="result"/>
138
138
  </resource>
139
+ <resource relative="nurl">
140
+ <post in="url" out="result"/>
141
+ </resource>
139
142
  <resource relative="git">
140
143
  <post in="git" out="result"/>
141
144
  </resource>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cpee-instantiation
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.24
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juergen eTM Mangler
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: tools
11
11
  cert_chain: []
12
- date: 2025-01-08 00:00:00.000000000 Z
12
+ date: 2025-02-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: riddl
@@ -62,7 +62,7 @@ dependencies:
62
62
  version: '2.1'
63
63
  - - ">="
64
64
  - !ruby/object:Gem::Version
65
- version: 2.1.4
65
+ version: 2.1.74
66
66
  type: :runtime
67
67
  prerelease: false
68
68
  version_requirements: !ruby/object:Gem::Requirement
@@ -72,7 +72,7 @@ dependencies:
72
72
  version: '2.1'
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: 2.1.4
75
+ version: 2.1.74
76
76
  description: see http://cpee.org
77
77
  email: juergen.mangler@gmail.com
78
78
  executables: