cpee-instantiation 1.0.16 → 1.1.5

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: d556a9e76088551f9335eb97aa22db0b851198d4d5f58f78035841513a43ac80
4
- data.tar.gz: 4d11049fba6354acad20244af8300859c21d293e3d41ba87253628a4d332fff7
3
+ metadata.gz: e8e16d204b34a37277bd75a4971eb72716af21f4c6792f6f4281d15c61d53bd6
4
+ data.tar.gz: 1e34b02335ca3242cc7c915ccceb8422b0653e057877afd385ad20717ce08785
5
5
  SHA512:
6
- metadata.gz: 697a43f1f77571d08284745129b3645be9050155dcb0abfa88a62755111278cd6a18271bfc27379286ae8f44ba17e7b8954bc260c1593459c567e7641dab05a7
7
- data.tar.gz: 9b1e2bc53ed83ea3fd9b6042b710fd1d69ee6676aa5b56716c59bf6507cab432ff2ff0d8bb8206873ca0d5047fbdb3f8ce609cb52942bb454a5b1cde97c89f12
6
+ metadata.gz: 26b3f9c3f8cabc8fca64353fc267a6b6a5cfd0249a7f10f63d863f621b098e8809c231819fa44aba5083cccaae2a7158c7e950314f93ee84b3d8c7e735e8d449
7
+ data.tar.gz: 659bd9d0d59e35f75fe7b2e7d762322870ac934f1a3769b9e89a1185936531adfdd6ddf82bfe12c7f4e51eaaa5d4cfc826c2d866d126e64b6a97273f81f4beff
data/AUTHORS CHANGED
@@ -1 +1,2 @@
1
1
  Jürgen Mangler <juergen.mangler@gmail.com>
2
+ Heinrich Fenkart <hnrch02@gmail.com>
data/README.md CHANGED
@@ -4,7 +4,7 @@ To install the instatiation service go to the commandline
4
4
 
5
5
  ```bash
6
6
  gem install cpee-instantiation
7
- cpee-instantiation instantiation
7
+ cpee-instantiation new instantiation
8
8
  cd instantiation
9
9
  ./instantiation start
10
10
  ```
@@ -1,8 +1,8 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "cpee-instantiation"
3
- s.version = "1.0.16"
3
+ s.version = "1.1.5"
4
4
  s.platform = Gem::Platform::RUBY
5
- s.license = "LGPL-3.0"
5
+ s.license = "LGPL-3.0-or-later"
6
6
  s.summary = "Subprocess instantiation service for the cloud process execution engine (cpee.org)"
7
7
 
8
8
  s.description = "see http://cpee.org"
@@ -15,13 +15,13 @@ Gem::Specification.new do |s|
15
15
 
16
16
  s.required_ruby_version = '>=2.4.0'
17
17
 
18
- s.authors = ['Juergen eTM Mangler']
18
+ s.authors = ['Juergen eTM Mangler', 'Heinrich Fenkart']
19
19
 
20
20
  s.email = 'juergen.mangler@gmail.com'
21
21
  s.homepage = 'http://cpee.org/'
22
22
 
23
- s.add_runtime_dependency 'riddl', '~> 0.99'
23
+ s.add_runtime_dependency 'riddl', '~> 1.0'
24
24
  s.add_runtime_dependency 'json', '~> 2.1'
25
- s.add_runtime_dependency 'redis', '~> 4.1'
26
- s.add_runtime_dependency 'cpee', '~> 2.1', '>= 2.1.4'
25
+ s.add_runtime_dependency 'redis', '~> 5.0'
26
+ s.add_runtime_dependency 'cpee', '~> 2.1', '>= 2.1.74'
27
27
  end
@@ -1,21 +1,22 @@
1
1
  # This file is part of CPEE-INSTANTIATION.
2
2
  #
3
3
  # CPEE-INSTANTIATION is free software: you can redistribute it and/or modify it
4
- # under the terms of the GNU General Public License as published by the Free
5
- # Software Foundation, either version 3 of the License, or (at your option) any
6
- # later version.
4
+ # under the terms of the GNU Lesser General Public License as published by the
5
+ # Free Software Foundation, either version 3 of the License, or (at your
6
+ # option) any later version.
7
7
  #
8
8
  # CPEE-INSTANTIATION is distributed in the hope that it will be useful, but
9
9
  # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
- # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11
- # more details.
10
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
11
+ # for more details.
12
12
  #
13
- # You should have received a copy of the GNU General Public License along with
14
- # CPEE-INSTANTIATION (file LICENSE in the main directory). If not, see
15
- # <http://www.gnu.org/licenses/>.
13
+ # You should have received a copy of the GNU Lesser General Public License
14
+ # along with CPEE-INSTANTIATION (file LICENSE in the main directory). If not,
15
+ # see <http://www.gnu.org/licenses/>.
16
16
 
17
17
  require 'rubygems'
18
18
  require 'cpee/value_helper'
19
+ require 'cpee/redis'
19
20
  require 'xml/smart'
20
21
  require 'riddl/server'
21
22
  require 'securerandom'
@@ -24,27 +25,36 @@ require 'uri'
24
25
  require 'redis'
25
26
  require 'json'
26
27
 
28
+ require_relative 'utils'
29
+
27
30
  module CPEE
28
31
  module Instantiation
29
32
 
30
33
  SERVER = File.expand_path(File.join(__dir__,'instantiation.xml'))
31
34
 
32
35
  module Helpers #{{{
33
- def add_to_testset(tdoc,what,data)
36
+
37
+ def add_to_testset(tdoc,what,data) #{{{
34
38
  if data && !data.empty?
35
- JSON::parse(data).each do |k,v|
39
+ data = JSON::parse(data) if data.is_a? String
40
+ data.each do |k,v|
36
41
  ele = tdoc.find("/*/prop:#{what}/prop:#{k}")
37
42
  if ele.any?
38
43
  ele.first.text = CPEE::ValueHelper::generate(v)
39
44
  else
40
45
  ele = tdoc.find("/*/prop:#{what}")
41
- ele.first.add(k,CPEE::ValueHelper::generate(v)) if ele.any?
46
+ ele = if ele.any?
47
+ ele.first
48
+ else
49
+ tdoc.root.add("prop:#{what}")
50
+ end
51
+ ele.add(k,CPEE::ValueHelper::generate(v))
42
52
  end
43
53
  end
44
54
  end
45
- end
55
+ end #}}}
46
56
 
47
- def augment_testset(tdoc,p)
57
+ def augment_testset(tdoc,p,h) #{{{
48
58
  tdoc = XML::Smart.string(tdoc)
49
59
  tdoc.register_namespace 'desc', 'http://cpee.org/ns/description/1.0'
50
60
  tdoc.register_namespace 'prop', 'http://cpee.org/ns/properties/2.0'
@@ -59,20 +69,17 @@ module CPEE
59
69
  if data = p.find{ |e| e.name == 'attributes' }&.value
60
70
  add_to_testset(tdoc,'attributes',data)
61
71
  end
72
+ data = {}
73
+ data['parent_instance'] = h['CPEE_INSTANCE'] if h['CPEE_INSTANCE']
74
+ data['parent_instance_uuid'] = h['CPEE_INSTANCE_UUID'] if h['CPEE_INSTANCE_UUID']
75
+ data['parent_instance_model'] = h['CPEE_ATTR_INFO'] if h['CPEE_ATTR_INFO']
76
+ data['parent_instance_task_id'] = h['CPEE_ACTIVITY'] if h['CPEE_ACTIVITY']
77
+ data['parent_instance_task_label'] = h['CPEE_LABEL'] if h['CPEE_LABEL']
78
+ add_to_testset(tdoc,'attributes',data)
62
79
  tdoc
63
- end
64
-
65
- def load_testset(doc,cpee,name=nil,customization=nil) #{{{
66
- ins = -1
67
- uuid = nil
80
+ end #}}}
68
81
 
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
74
- end
75
- end
82
+ def customize_testset(customization,doc) #{{{
76
83
  if customization && !customization.empty?
77
84
  JSON.parse(customization).each do |e|
78
85
  begin
@@ -90,125 +97,78 @@ module CPEE
90
97
  end
91
98
  end
92
99
  end
100
+ end #}}}
93
101
 
94
- status, response, headers = res.post Riddl::Parameter::Simple.new('info',doc.find('string(/*/prop:attributes/prop:info)'))
95
-
96
- if status == 200
97
- ins = response.first.value
98
- uuid = headers['CPEE_INSTANCE_UUID']
102
+ def add_waiting_to_testset(behavior,cb,doc,selfurl) #{{{
103
+ ckb = nil
104
+ if behavior =~ /^wait/
105
+ condition = behavior.match(/_([^_]+)_/)&.[](1) || 'finished'
99
106
 
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?
107
+ if cb
108
+ cbk = 'instantiation_' + Digest::MD5.hexdigest(Kernel::rand().to_s)
109
+ n = doc.find('/*/sub:subscriptions') rescue []
110
+ if (n.empty?)
111
+ n = doc.root.add('subscriptions')
112
+ n.namespaces.add(nil,'http://riddl.org/ns/common-patterns/notifications-producer/2.0')
113
+ else
114
+ n = n.first
115
+ end
116
+ n.append('subscription', :id => cbk, :url => File.join(selfurl,'callback',cbk))
117
+ .append('topic', :id => 'state')
118
+ .append('event','change')
105
119
  end
120
+ end
121
+ [cbk, condition]
122
+ end #}}}
106
123
 
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)
113
- end
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)
119
- 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)
123
- 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
124
+ def add_running_to_testset(behavior,doc) #{{{
125
+ if behavior =~ /_running$/
126
+ if ((doc.find('/*/prop:state')).empty?)
127
+ doc.root.append('prop:state','running')
128
+ else
129
+ doc.find('/*/prop:state').first.text = 'running'
130
+ end
127
131
  end
128
- [ins, uuid]
129
- end #}}}
130
- private :load_testset
131
- def handle_waiting(cpee,instance,uuid,behavior,selfurl,cblist) #{{{
132
- if behavior =~ /^wait/
133
- condition = behavior.match(/_([^_]+)_/)&.[](1) || 'finished'
134
- cb = @h['CPEE_CALLBACK']
132
+ end #}}}
135
133
 
136
- if cb
137
- cbk = SecureRandom.uuid
138
- srv = Riddl::Client.new(cpee, File.join(cpee,'?riddl-description'))
139
- status, response = srv.resource("/#{instance}/notifications/subscriptions/").post [
140
- Riddl::Parameter::Simple.new('url',File.join(selfurl,'callback',cbk)),
141
- Riddl::Parameter::Simple.new('topic','state'),
142
- Riddl::Parameter::Simple.new('events','change')
143
- ]
134
+ def instantiate_testset(cpee,doc,behavior,cblist,cbk,cb,condition) #{{{
135
+ status, res, headers = Riddl::Client.new(cpee).post Riddl::Parameter::Complex.new('testset', 'application/xml', doc.to_s)
136
+ if status == 200
137
+ instance = res.first.value
138
+ uuid = headers['CPEE_INSTANCE_UUID']
139
+
140
+ if cbk
144
141
  cblist.rpush(cbk, cb)
145
142
  cblist.rpush(cbk, condition)
146
143
  cblist.rpush(cbk, instance)
147
144
  cblist.rpush(cbk, uuid)
148
145
  cblist.rpush(cbk, File.join(cpee,instance))
146
+ @headers << Riddl::Header.new('CPEE-CALLBACK','true')
149
147
  end
148
+
149
+ send = {
150
+ 'CPEE-INSTANCE' => instance,
151
+ 'CPEE-INSTANCE-URL' => File.join(cpee,instance),
152
+ 'CPEE-INSTANCE-UUID' => uuid,
153
+ 'CPEE-BEHAVIOR' => behavior
154
+ }
155
+ @headers << Riddl::Header.new('CPEE-INSTANTIATION',JSON::generate(send))
156
+ Riddl::Parameter::Complex.new('instance','application/json',JSON::generate(send))
157
+ else
158
+ @status = 500
150
159
  end
151
160
  end #}}}
152
- private :handle_waiting
153
- def handle_starting(cpee,instance,behavior) #{{{
154
- if behavior =~ /_running$/
155
- sleep 0.5
156
- srv = Riddl::Client.new(cpee, File.join(cpee,'?riddl-description'))
157
- res = srv.resource("/#{instance}/properties/state")
158
- status, response = res.put [
159
- Riddl::Parameter::Simple.new('value','running')
160
- ]
161
- end
162
- end #}}}
163
- private :handle_starting
164
- def handle_data(cpee,instance,data) #{{{
165
- if data && !data.empty?
166
- content = XML::Smart.string('<dataelements xmlns="http://cpee.org/ns/properties/2.0"/>')
167
- JSON::parse(data).each do |k,v|
168
- content.root.add(k,CPEE::ValueHelper::generate(v))
169
- end
170
- srv = Riddl::Client.new(cpee, File.join(cpee,'?riddl-description'))
171
- res = srv.resource("/#{instance}/properties/dataelements/")
172
- status, response = res.patch [
173
- Riddl::Parameter::Complex.new('dataelements','text/xml',content.to_s)
174
- ]
175
- end rescue nil
176
- end #}}}
177
- def handle_endpoints(cpee,instance,data) #{{{
178
- if data && !data.empty?
179
- content = XML::Smart.string('<endpoints xmlns="http://cpee.org/ns/properties/2.0"/>')
180
- JSON::parse(data).each do |k,v|
181
- content.root.add(k,v)
182
- end
183
- srv = Riddl::Client.new(cpee, File.join(cpee,'?riddl-description'))
184
- res = srv.resource("/#{instance}/properties/endpoints/")
185
- status, response = res.patch [
186
- Riddl::Parameter::Complex.new('endpoints','text/xml',content.to_s)
187
- ]
188
- end rescue nil
189
- end #}}}
190
- def handle_attributes(cpee,instance,data) #{{{
191
- if data && !data.empty?
192
- content = XML::Smart.string('<attributes xmlns="http://cpee.org/ns/properties/2.0"/>')
193
- JSON::parse(data).each do |k,v|
194
- content.root.add(k,v)
195
- end
196
- srv = Riddl::Client.new(cpee, File.join(cpee,'?riddl-description'))
197
- res = srv.resource("/#{instance}/properties/attributes/")
198
- status, response = res.patch [
199
- Riddl::Parameter::Complex.new('attributes','text/xml',content.to_s)
200
- ]
201
- end rescue nil
202
- end #}}}
161
+
203
162
  end #}}}
204
163
 
205
164
  class InstantiateGit < Riddl::Implementation #{{{
206
165
  include Helpers
207
166
 
208
167
  def response
209
- cpee = @h['X_CPEE'] || @a[0]
210
- selfurl = @a[1]
211
- cblist = @a[2]
168
+ cpee = @h['X_CPEE'] || @a[0]
169
+ selfurl = @a[1]
170
+ cblist = @a[2]
171
+ behavior = @p[0].value
212
172
 
213
173
  status, res = Riddl::Client.new(File.join(@p[1].value,'raw',@p[2].value,@p[3].value).gsub(/ /,'%20')).get
214
174
  tdoc = if status >= 200 && status < 300
@@ -218,27 +178,12 @@ module CPEE
218
178
  end
219
179
  customization = @p.find{ |e| e.name == 'customization' }&.value
220
180
 
221
- tdoc = augment_testset(tdoc,@p)
222
- if (instance, uuid = load_testset(tdoc,cpee,nil,customization)).first == -1
223
- @status = 500
224
- else
225
- EM.defer do
226
- handle_waiting cpee, instance, uuid, @p[0].value, selfurl, cblist
227
- handle_starting cpee, instance, @p[0].value
228
- end
181
+ doc = augment_testset(tdoc,@p,@h)
182
+ customize_testset(customization,doc)
183
+ cbk, condition = add_waiting_to_testset(behavior,@h['CPEE_CALLBACK'],doc,selfurl)
184
+ add_running_to_testset(behavior,doc)
229
185
 
230
- send = {
231
- 'CPEE-INSTANCE' => instance,
232
- 'CPEE-INSTANCE-URL' => File.join(cpee,instance),
233
- 'CPEE-INSTANCE-UUID' => uuid,
234
- 'CPEE-BEHAVIOR' => @p[0].value
235
- }
236
- if @p[0].value =~ /^wait/
237
- @headers << Riddl::Header.new('CPEE-CALLBACK','true')
238
- end
239
- @headers << Riddl::Header.new('CPEE-INSTANTIATION',JSON::generate(send))
240
- Riddl::Parameter::Complex.new('instance','application/json',JSON::generate(send))
241
- end
186
+ instantiate_testset(cpee,doc,@p[0].value,cblist,cbk,@h['CPEE_CALLBACK'],condition)
242
187
  end
243
188
  end #}}}
244
189
 
@@ -246,10 +191,11 @@ module CPEE
246
191
  include Helpers
247
192
 
248
193
  def response
249
- cpee = @h['X_CPEE'] || @a[0]
250
- selfurl = @a[1]
251
- cblist = @a[2]
252
- name = @a[3] ? @p.shift.value : nil
194
+ cpee = @h['X_CPEE'] || @a[0]
195
+ selfurl = @a[1]
196
+ cblist = @a[2]
197
+ name = @a[3] ? @p.shift.value : nil
198
+ behavior = @p[0].value
253
199
 
254
200
  status, res = Riddl::Client.new(@p[1].value.gsub(/ /,'%20')).get
255
201
  tdoc = if status >= 200 && status < 300
@@ -259,29 +205,14 @@ module CPEE
259
205
  end
260
206
  customization = @p.find{ |e| e.name == 'customization' }&.value
261
207
 
262
- tdoc = augment_testset(tdoc,@p)
263
- if (instance, uuid = load_testset(tdoc,cpee,name,customization)).first == -1
264
- @status = 500
265
- else
266
- EM.defer do
267
- handle_waiting cpee, instance, uuid, @p[0].value, selfurl, cblist
268
- handle_starting cpee, instance, @p[0].value
269
- end
208
+ doc = augment_testset(tdoc,@p,@h)
209
+ customize_testset(customization,doc)
210
+ cbk, condition = add_waiting_to_testset(behavior,@h['CPEE_CALLBACK'],doc,selfurl)
211
+ add_running_to_testset(behavior,doc)
270
212
 
271
- send = {
272
- 'CPEE-INSTANCE' => instance,
273
- 'CPEE-INSTANCE-URL' => File.join(cpee,instance),
274
- 'CPEE-INSTANCE-UUID' => uuid,
275
- 'CPEE-BEHAVIOR' => @p[0].value
276
- }
277
- if @p[0].value =~ /^wait/
278
- @headers << Riddl::Header.new('CPEE-CALLBACK','true')
279
- end
280
- @headers << Riddl::Header.new('CPEE-INSTANTIATION',JSON::generate(send))
281
- Riddl::Parameter::Complex.new('instance','application/json',JSON::generate(send))
282
- end
213
+ instantiate_testset(cpee,doc,@p[0].value,cblist,cbk,@h['CPEE_CALLBACK'],condition)
283
214
  end
284
- end #}}}
215
+ end #}}}
285
216
 
286
217
  class InstantiateXML < Riddl::Implementation #{{{
287
218
  include Helpers
@@ -298,62 +229,11 @@ module CPEE
298
229
  @p[data].value.read
299
230
  end
300
231
 
301
- tdoc = augment_testset(tdoc,@p)
302
- if (instance, uuid = load_testset(tdoc,cpee)).first == -1
303
- @status = 500
304
- else
305
- EM.defer do
306
- handle_waiting cpee, instance, uuid, behavior, selfurl, cblist
307
- handle_starting cpee, instance, behavior
308
- end
309
-
310
- send = {
311
- 'CPEE-INSTANCE' => instance,
312
- 'CPEE-INSTANCE-URL' => File.join(cpee,instance),
313
- 'CPEE-INSTANCE-UUID' => uuid,
314
- 'CPEE-BEHAVIOR' => behavior
315
- }
316
- if @p[0].value =~ /^wait/
317
- @headers << Riddl::Header.new('CPEE-CALLBACK','true')
318
- end
319
- Riddl::Parameter::Complex.new('instance','application/json',JSON::generate(send))
320
- end
321
- end
322
- end #}}}
323
-
324
- class HandleInstance < Riddl::Implementation #{{{
325
- include Helpers
326
-
327
- def response
328
- cpee = @h['X_CPEE'] || @a[0]
329
- selfurl = @a[1]
330
- cblist = @a[2]
331
- instance = @p[1].value
332
-
333
- srv = Riddl::Client.new(cpee)
334
- res = srv.resource("/#{instance}/properties/attributes/uuid/")
335
- status, response = res.get
232
+ doc = augment_testset(tdoc,@p,@h)
233
+ cbk, condition = add_waiting_to_testset(behavior,@h['CPEE_CALLBACK'],doc,selfurl)
234
+ add_running_to_testset(behavior,doc)
336
235
 
337
- if status >= 200 && status < 300
338
- uuid = response.first.value
339
- handle_data cpee, instance, @p[2]&.value
340
- handle_waiting cpee, instance, uuid, @p[0].value, selfurl, cblist
341
- handle_starting cpee, instance, @p[0].value
342
-
343
- send = {
344
- 'CPEE-INSTANCE' => instance,
345
- 'CPEE-INSTANCE-URL' => File.join(cpee,instance),
346
- 'CPEE-INSTANCE-UUID' => uuid,
347
- 'CPEE-BEHAVIOR' => @p[0].value
348
- }
349
-
350
- if @p[0].value =~ /^wait/
351
- @headers << Riddl::Header.new('CPEE-CALLBACK','true')
352
- end
353
- Riddl::Parameter::Complex.new('instance','application/json',JSON::generate(send))
354
- else
355
- @status = 500
356
- end
236
+ instantiate_testset(cpee,doc,@p[0].value,cblist,cbk,@h['CPEE_CALLBACK'],condition)
357
237
  end
358
238
  end #}}}
359
239
 
@@ -371,6 +251,8 @@ module CPEE
371
251
  key = @r.last
372
252
  cb, condition, instance, uuid, instance_url = cblist.lrange(key,0,-1)
373
253
 
254
+ return if cb.nil?
255
+
374
256
  cpee = File.dirname(instance_url)
375
257
 
376
258
  send = {
@@ -382,7 +264,7 @@ module CPEE
382
264
 
383
265
  if notification['content']['state'] == condition
384
266
  cblist.del(key)
385
- srv = Riddl::Client.new(cpee, File.join(cpee,'?riddl-description'))
267
+ srv = Riddl::Client.new(cpee)
386
268
  res = srv.resource("/#{instance}/properties/dataelements")
387
269
  status, response = res.get
388
270
  if status >= 200 && status < 300
@@ -400,33 +282,51 @@ module CPEE
400
282
  ]
401
283
  end
402
284
  end
285
+
403
286
  end #}}}
404
287
 
405
288
  def self::implementation(opts)
406
289
  opts[:cpee] ||= 'http://localhost:9298/'
407
- opts[:redis_path] ||= '/tmp/redis.sock'
408
- opts[:redis_db] ||= 14
409
290
  opts[:self] ||= "http#{opts[:secure] ? 's' : ''}://#{opts[:host]}:#{opts[:port]}/"
410
- opts[:cblist] = Redis.new(path: opts[:redis_path], db: opts[:redis_db])
291
+
292
+ opts[:watchdog_frequency] ||= 7
293
+ opts[:watchdog_start_off] ||= false
294
+
295
+ ### set redis_cmd to nil if you want to do global
296
+ ### at least redis_path or redis_url and redis_db have to be set if you do global
297
+ opts[:redis_path] ||= 'redis.sock' # use e.g. /tmp/redis.sock for global stuff. Look it up in your redis config
298
+ opts[:redis_db] ||= 0
299
+ ### optional redis stuff
300
+ opts[:redis_url] ||= nil
301
+ opts[:redis_cmd] ||= 'redis-server --port 0 --unixsocket #redis_path# --unixsocketperm 600 --pidfile #redis_pid# --dir #redis_db_dir# --dbfilename #redis_db_name# --databases 1 --save 900 1 --save 300 10 --save 60 10000 --rdbcompression yes --daemonize yes'
302
+ opts[:redis_pid] ||= 'redis.pid' # use e.g. /var/run/redis.pid if you do global. Look it up in your redis config
303
+ opts[:redis_db_name] ||= 'redis.rdb' # use e.g. /var/lib/redis.rdb for global stuff. Look it up in your redis config
304
+
305
+ CPEE::redis_connect opts, 'Instantiation'
306
+
411
307
  Proc.new do
308
+ parallel do
309
+ CPEE::Instantiation::watch_services(opts[:watchdog_start_off],opts[:redis_url],File.join(opts[:basepath],opts[:redis_path]),opts[:redis_db])
310
+ EM.add_periodic_timer(opts[:watchdog_frequency]) do ### start services
311
+ CPEE::Instantiation::watch_services(opts[:watchdog_start_off],opts[:redis_url],File.join(opts[:basepath],opts[:redis_path]),opts[:redis_db])
312
+ end
313
+ end
314
+
412
315
  on resource do
413
316
  run InstantiateXML, opts[:cpee], true if post 'xmlsimple'
414
317
  on resource 'xml' do
415
318
  run InstantiateXML, opts[:cpee], false if post 'xml'
416
319
  end
417
320
  on resource 'url' do
418
- run InstantiateUrl, opts[:cpee], opts[:self], opts[:cblist], false if post 'url'
419
- run InstantiateUrl, opts[:cpee], opts[:self], opts[:cblist], true if post 'url_info'
321
+ run InstantiateUrl, opts[:cpee], opts[:self], opts[:redis], false if post 'url'
322
+ run InstantiateUrl, opts[:cpee], opts[:self], opts[:redis], true if post 'url_info'
420
323
  end
421
324
  on resource 'git' do
422
- run InstantiateGit, opts[:cpee], opts[:self], opts[:cblist] if post 'git'
423
- end
424
- on resource 'instance' do
425
- run HandleInstance, opts[:cpee], opts[:self], opts[:cblist] if post 'instance'
325
+ run InstantiateGit, opts[:cpee], opts[:self], opts[:redis] if post 'git'
426
326
  end
427
327
  on resource 'callback' do
428
328
  on resource do
429
- run ContinueTask, opts[:cpee], opts[:cblist] if post
329
+ run ContinueTask, opts[:cpee], opts[:redis] if post
430
330
  end
431
331
  end
432
332
  end
@@ -1,3 +1,21 @@
1
+ <!--
2
+ This file is part of CPEE-INSTANTIATION.
3
+
4
+ CPEE-INSTANTIATION is free software: you can redistribute it and/or modify it
5
+ under the terms of the GNU Lesser General Public License as published by the
6
+ Free Software Foundation, either version 3 of the License, or (at your
7
+ option) any later version.
8
+
9
+ CPEE-INSTANTIATION is distributed in the hope that it will be useful, but
10
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
12
+ for more details.
13
+
14
+ You should have received a copy of the GNU Lesser General Public License
15
+ along with CPEE-INSTANTIATION (file LICENSE in the main directory). If not,
16
+ see <http://www.gnu.org/licenses/>.
17
+ -->
18
+
1
19
  <description datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes" xmlns="http://riddl.org/ns/description/1.0" xmlns:xi="http://www.w3.org/2001/XInclude">
2
20
  <message name="xmlsimple">
3
21
  <parameter name="xml" mimetype="*/xml"/>
@@ -118,6 +136,9 @@
118
136
  <post in="url" out="result"/>
119
137
  <post in="url_info" out="result"/>
120
138
  </resource>
139
+ <resource relative="nurl">
140
+ <post in="url" out="result"/>
141
+ </resource>
121
142
  <resource relative="git">
122
143
  <post in="git" out="result"/>
123
144
  </resource>
@@ -0,0 +1,52 @@
1
+ # This file is part of CPEE-INSTANTIATION
2
+ #
3
+ # CPEE-INSTANTIATION is free software: you can redistribute it and/or modify it
4
+ # under the terms of the GNU Lesser General Public License as published by the
5
+ # Free Software Foundation, either version 3 of the License, or (at your
6
+ # option) any later version.
7
+ #
8
+ # CPEE-INSTANTIATION is distributed in the hope that it will be useful, but WITHOUT
9
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10
+ # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11
+ # details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public License
14
+ # along with CPEE-INSTANTIATION (file LICENSE in the main directory). If not, see
15
+ # <http://www.gnu.org/licenses/>.
16
+
17
+ module CPEE
18
+ module Instantiation
19
+
20
+ def self::watch_services(watchdog_start_off,url,path,db)
21
+ return if watchdog_start_off
22
+ EM.defer do
23
+ Dir[File.join(__dir__,'routing','*.rb')].each do |s|
24
+ s = s.sub(/\.rb$/,'')
25
+ pid = (File.read(s + '.pid').to_i rescue nil)
26
+ cmd = if url.nil?
27
+ "-p \"#{path}\" -d #{db} restart"
28
+ else
29
+ "-u \"#{url}\" -d #{db} restart"
30
+ end
31
+ if (pid.nil? || !(Process.kill(0, pid) rescue false)) && !File.exist?(s + '.lock')
32
+ system "#{s}.rb " + cmd + " 1>/dev/null 2>&1"
33
+ puts "➡ Service #{File.basename(s)} (-v #{cmd}) started ..."
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ def self::cleanup_services(watchdog_start_off)
40
+ return if watchdog_start_off
41
+ Dir[File.join(__dir__,'routing','*.rb')].each do |s|
42
+ s = s.sub(/\.rb$/,'')
43
+ pid = (File.read(s + '.pid').to_i rescue nil)
44
+ if !pid.nil? || (Process.kill(0, pid) rescue false)
45
+ system "#{s}.rb stop 1>/dev/null 2>&1"
46
+ puts "➡ Service #{File.basename(s,'.rb')} stopped ..."
47
+ end
48
+ end
49
+ end
50
+
51
+ end
52
+ end
data/server/instantiation CHANGED
@@ -1,4 +1,21 @@
1
1
  #!/usr/bin/ruby
2
+ #
3
+ # This file is part of CPEE-INSTANTIATION.
4
+ #
5
+ # CPEE-INSTANTIATION is free software: you can redistribute it and/or modify it
6
+ # under the terms of the GNU General Public License as published by the Free
7
+ # Software Foundation, either version 3 of the License, or (at your option) any
8
+ # later version.
9
+ #
10
+ # CPEE-INSTANTIATION is distributed in the hope that it will be useful, but
11
+ # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13
+ # more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License along with
16
+ # CPEE-INSTANTIATION (file LICENSE in the main directory). If not, see
17
+ # <http://www.gnu.org/licenses/>.
18
+
2
19
  require 'rubygems'
3
20
  require 'cpee-instantiation/instantiation'
4
21
 
@@ -1,4 +1,21 @@
1
1
  #!/usr/bin/ruby
2
+ #
3
+ # This file is part of CPEE-INSTANTIATION.
4
+ #
5
+ # CPEE-INSTANTIATION is free software: you can redistribute it and/or modify it
6
+ # under the terms of the GNU General Public License as published by the Free
7
+ # Software Foundation, either version 3 of the License, or (at your option) any
8
+ # later version.
9
+ #
10
+ # CPEE-INSTANTIATION is distributed in the hope that it will be useful, but
11
+ # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13
+ # more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License along with
16
+ # CPEE-INSTANTIATION (file LICENSE in the main directory). If not, see
17
+ # <http://www.gnu.org/licenses/>.
18
+
2
19
  curpath = __dir__
3
20
  require 'rubygems'
4
21
  require 'optparse'
@@ -26,24 +43,28 @@ end
26
43
  ARGV.options { |opt|
27
44
  opt.summary_indent = ' ' * 2
28
45
  opt.summary_width = 15
29
- opt.banner = "Usage:\n#{opt.summary_indent}#{File.basename($0)} [DIR]\n"
46
+ opt.banner = "Usage:\n#{opt.summary_indent}#{File.basename($0)} [options] new DIR\n"
30
47
  opt.on("Options:")
31
48
  opt.on("--help", "-h", "This text") { puts opt; exit }
32
49
  opt.on("")
33
- opt.on(wrap("[DIR] scaffolds a sample instantiation service. Post a testset to a model to keep going in one operation."))
50
+ opt.on(wrap("[new DIR] scaffolds a sample instantiation service. Post a testset to a model to keep going in one operation."))
34
51
  opt.parse!
35
52
  }
36
- if (ARGV.length != 1)
53
+ if (ARGV.length < 2) ||
54
+ (ARGV.length == 2 && !(%w(new).include?(ARGV[0]))) ||
55
+ (ARGV.length > 2)
37
56
  puts ARGV.options
38
57
  exit
39
- else
40
- p1 = ARGV[0]
41
58
  end
59
+ command = ARGV[0]
60
+ p1 = ARGV[1]
42
61
 
43
- insta = "#{curpath}/../server/"
44
- if !File.exist?(p1)
45
- FileUtils.cp_r(insta,p1)
46
- else
47
- FileUtils.cp_r(Dir.glob(File.join(insta,'*')).delete_if{|e| e =~ /\.conf/ },p1,remove_destination: true)
48
- puts 'Directory already exists, updating ...'
62
+ if command == 'new'
63
+ insta = "#{curpath}/../server/"
64
+ if !File.exist?(p1)
65
+ FileUtils.cp_r(insta,p1)
66
+ else
67
+ FileUtils.cp_r(Dir.glob(File.join(insta,'*')).delete_if{|e| e =~ /\.conf/ },p1,remove_destination: true)
68
+ puts 'Directory already exists, updating ...'
69
+ end
49
70
  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.16
4
+ version: 1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juergen eTM Mangler
8
- autorequire:
8
+ - Heinrich Fenkart
9
9
  bindir: tools
10
10
  cert_chain: []
11
- date: 2023-03-16 00:00:00.000000000 Z
11
+ date: 1980-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: riddl
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.99'
19
+ version: '1.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.99'
26
+ version: '1.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: json
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '4.1'
47
+ version: '5.0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '4.1'
54
+ version: '5.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: cpee
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -61,7 +61,7 @@ dependencies:
61
61
  version: '2.1'
62
62
  - - ">="
63
63
  - !ruby/object:Gem::Version
64
- version: 2.1.4
64
+ version: 2.1.74
65
65
  type: :runtime
66
66
  prerelease: false
67
67
  version_requirements: !ruby/object:Gem::Requirement
@@ -71,7 +71,7 @@ dependencies:
71
71
  version: '2.1'
72
72
  - - ">="
73
73
  - !ruby/object:Gem::Version
74
- version: 2.1.4
74
+ version: 2.1.74
75
75
  description: see http://cpee.org
76
76
  email: juergen.mangler@gmail.com
77
77
  executables:
@@ -87,13 +87,13 @@ files:
87
87
  - cpee-instantiation.gemspec
88
88
  - lib/cpee-instantiation/instantiation.rb
89
89
  - lib/cpee-instantiation/instantiation.xml
90
+ - lib/cpee-instantiation/utils.rb
90
91
  - server/instantiation
91
92
  - tools/cpee-instantiation
92
93
  homepage: http://cpee.org/
93
94
  licenses:
94
- - LGPL-3.0
95
+ - LGPL-3.0-or-later
95
96
  metadata: {}
96
- post_install_message:
97
97
  rdoc_options: []
98
98
  require_paths:
99
99
  - lib
@@ -108,8 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0'
110
110
  requirements: []
111
- rubygems_version: 3.4.6
112
- signing_key:
111
+ rubygems_version: 3.6.7
113
112
  specification_version: 4
114
113
  summary: Subprocess instantiation service for the cloud process execution engine (cpee.org)
115
114
  test_files: []