cpee-instantiation 1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4da02ad96d0a1feb31755f5217286eed93f5f1beabe3f535a7d749ab55eb8cb3
4
+ data.tar.gz: 6b9b6f3ad0f463f050a81759f0685eea7ac69d57f282ec8c9b1f83a0a5bce17f
5
+ SHA512:
6
+ metadata.gz: 48cfa7f1a307aabe48cfa73b08d0e9a0d79dc989ecaf30a2d4c871dffe6fcdfd6bb4563bec9da70d2c44c07efe248fe6f2d2a450c96eae47f0d89a791c9852b3
7
+ data.tar.gz: 885d19ca953bd56e72cf43ea2fe27ea98f3575a0689dc37293b9f0348111d2735a91fbc909f98d541030308eea4278d631667e24b966baa569000e85fad43af0
data/AUTHORS ADDED
@@ -0,0 +1 @@
1
+ Jürgen Mangler <juergen.mangler@gmail.com>
data/LICENSE ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
@@ -0,0 +1,35 @@
1
+ # CPEE Instantiation
2
+
3
+ To install the instatiation service go to the commandline
4
+
5
+ ```bash
6
+ gem install cpee-instantiation
7
+ cpee-instantiation instantiation
8
+ cd instantiation
9
+ ./instantiation start
10
+ ```
11
+
12
+ The service is running under port 9296. If this port has to be changed (or the
13
+ host, or local-only access, ...), create a file instatiation.conf and add one
14
+ or many of the following yaml keys:
15
+
16
+ ```yaml
17
+ :port: 9250
18
+ :host: cpee.org
19
+ :bind: 127.0.0.1
20
+ :cpee: http://localhost:9298/
21
+ :redis_path: /tmp/redis.sock
22
+ :redis_db: 14
23
+ ```
24
+
25
+ To use the service try one of the following:
26
+
27
+ ```bash
28
+ curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "behavior=wait_running&url=http%3A%2F%2Flink%2Fto%2Ftestset.xml" http://localhost:9296/url
29
+ curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "behavior=fork_running&url=http%3A%2F%2Flink%2Fto%2Ftestset.xml&init=%7B%20%22a%22%3A%2037%2C%20%22b%22%3A%20%22test%22%20%7D" http://localhost:9296/url
30
+ curl -X POST -F "behavior=wait_running" -F "xml=@testset.xml" http://localhost:9296/xml
31
+ ```
32
+
33
+ The behavior can be either: the process parent process is waiting (wait_) or is
34
+ running in parallel (fork_), the subprocesss is either immediately starting
35
+ (_running), or waiting for manual start (_ready).
@@ -0,0 +1,21 @@
1
+ require 'rake'
2
+ require 'rubygems/package_task'
3
+
4
+ spec = eval(File.read('cpee-instantiation.gemspec'))
5
+ Gem::PackageTask.new(spec) do |pkg|
6
+ pkg.need_zip = true
7
+ pkg.need_tar = true
8
+ FileUtils.mkdir 'pkg' rescue nil
9
+ FileUtils.rm_rf Dir.glob('pkg/*')
10
+ FileUtils.ln_sf "#{pkg.name}.gem", "pkg/#{spec.name}.gem"
11
+ end
12
+
13
+ task :default => [:gem]
14
+
15
+ task :push => :gem do |r|
16
+ `gem push pkg/cpee-instantiation.gem`
17
+ end
18
+
19
+ task :install => :gem do |r|
20
+ `gem install pkg/cpee-instantiation.gem`
21
+ end
@@ -0,0 +1,27 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "cpee-instantiation"
3
+ s.version = "1.0"
4
+ s.platform = Gem::Platform::RUBY
5
+ s.license = "LGPL-3.0"
6
+ s.summary = "Subprocess instantiation service for the cloud process execution engine (cpee.org)"
7
+
8
+ s.description = "see http://cpee.org"
9
+
10
+ s.files = Dir['{server/**/*,tools/**/*,lib/**/*}'] + %w(LICENSE Rakefile cpee-instantiation.gemspec README.md AUTHORS)
11
+ s.require_path = 'lib'
12
+ s.extra_rdoc_files = ['README.md']
13
+ s.bindir = 'tools'
14
+ s.executables = ['cpee-instantiation']
15
+
16
+ s.required_ruby_version = '>=2.4.0'
17
+
18
+ s.authors = ['Juergen eTM Mangler']
19
+
20
+ s.email = 'juergen.mangler@gmail.com'
21
+ s.homepage = 'http://cpee.org/'
22
+
23
+ s.add_runtime_dependency 'riddl', '~> 0.99'
24
+ s.add_runtime_dependency 'json', '~> 2.1'
25
+ s.add_runtime_dependency 'redis', '~> 4.1'
26
+ s.add_runtime_dependency 'cpee', '~> 1', '>= 1.5'
27
+ end
@@ -0,0 +1,365 @@
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 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.
7
+ #
8
+ # CPEE-INSTANTIATION is distributed in the hope that it will be useful, but
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.
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/>.
16
+
17
+ require 'rubygems'
18
+ require 'cpee/value_helper'
19
+ require 'xml/smart'
20
+ require 'riddl/server'
21
+ require 'securerandom'
22
+ require 'base64'
23
+ require 'uri'
24
+ require 'redis'
25
+ require 'json'
26
+
27
+ module CPEE
28
+ module Instantiation
29
+
30
+ SERVER = File.expand_path(File.join(__dir__,'instantiation.xml'))
31
+
32
+ module Helpers #{{{
33
+ def load_testset(tdoc,cpee,name=nil,stream=nil) #{{{
34
+ ins = -1
35
+ 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
+
40
+ srv = Riddl::Client.new(cpee, cpee + '?riddl-description')
41
+ res = srv.resource('/')
42
+ if name
43
+ doc.find('/*/prop:attributes/prop:info').each do |e|
44
+ e.text = name
45
+ end
46
+ end
47
+ if stream && !stream.empty?
48
+ JSON.parse(stream).each do |e|
49
+ begin
50
+ stream = Typhoeus.get e['url']
51
+ if stream.success?
52
+ XML::Smart::string(stream.response_body) do |str|
53
+ doc.find("//desc:call[@id=\"#{e['id']}\"]/desc:parameters/desc:stream").each do |ele|
54
+ ele.replace_by str.root
55
+ end
56
+ end
57
+ end
58
+ rescue => e
59
+ puts e.message
60
+ puts e.backtrace
61
+ end
62
+ end
63
+ end
64
+
65
+ status, response, headers = res.post Riddl::Parameter::Simple.new('info',doc.find('string(/*/prop:attributes/prop:info)'))
66
+
67
+ if status == 200
68
+ ins = response.first.value
69
+ uuid = headers['CPEE_INSTANCE_UUID']
70
+
71
+ inp = XML::Smart::string('<properties xmlns="http://cpee.org/ns/properties/2.0"/>')
72
+ inp.register_namespace 'prop', 'http://cpee.org/ns/properties/2.0'
73
+ %w{handlerwrapper positions dataelements endpoints attributes description transformation}.each do |item|
74
+ ele = doc.find("/*/prop:#{item}")
75
+ inp.root.add(ele.first) if ele.any?
76
+ end
77
+ res = srv.resource("/#{ins}/properties").put Riddl::Parameter::Complex.new('properties','application/xml',inp.to_s)
78
+ doc.find('/*/prop:handlers/prop:handler').each do |han|
79
+ url = han.attributes['url']
80
+ inp = 'url=' + URI.encode_www_form_component(url)
81
+ inp = inp + '&topic=' + han.children.first.attributes['topic']
82
+ inp = inp + '&' + han.children.first.qname.to_s + '=' + han.children.first.to_s
83
+ status,body = Riddl::Client::new(cpee+ins+'/notifications/subscriptions/').post(
84
+ [
85
+ Riddl::Parameter::Simple.new('url',han.attributes['url']),
86
+ Riddl::Parameter::Simple.new('topic',han.children.first.attributes['topic']),
87
+ Riddl::Parameter::Simple.new(han.children.first.qname.to_s,han.children.first.to_s)
88
+ ]
89
+ )
90
+ end
91
+ end
92
+ end
93
+ [ins, uuid]
94
+ end #}}}
95
+ private :load_testset
96
+ def handle_waiting(cpee,instance,uuid,behavior,selfurl,cblist) #{{{
97
+ if behavior =~ /^wait/
98
+ condition = behavior.match(/_([^_]+)_/)&.[](1) || 'finished'
99
+ @headers << Riddl::Header.new('CPEE-CALLBACK','true')
100
+ cb = @h['CPEE_CALLBACK']
101
+
102
+ if cb
103
+ cbk = SecureRandom.uuid
104
+ srv = Riddl::Client.new(cpee, cpee + '?riddl-description')
105
+ status, response = srv.resource("/#{instance}/notifications/subscriptions/").post [
106
+ Riddl::Parameter::Simple.new('url',File.join(selfurl,'callback',cbk)),
107
+ Riddl::Parameter::Simple.new('topic','state'),
108
+ Riddl::Parameter::Simple.new('events','change')
109
+ ]
110
+ cblist.rpush(cbk, cb)
111
+ cblist.rpush(cbk, condition)
112
+ cblist.rpush(cbk, instance)
113
+ cblist.rpush(cbk, uuid)
114
+ cblist.rpush(cbk, File.join(cpee,instance))
115
+ end
116
+ end
117
+ end #}}}
118
+ private :handle_waiting
119
+ def handle_starting(cpee,instance,behavior) #{{{
120
+ if behavior =~ /_running$/
121
+ srv = Riddl::Client.new(cpee, cpee + '?riddl-description')
122
+ res = srv.resource("/#{instance}/properties/state")
123
+ status, response = res.put [
124
+ Riddl::Parameter::Simple.new('value','running')
125
+ ]
126
+ end
127
+ end #}}}
128
+ private :handle_starting
129
+ def handle_data(cpee,instance,data) #{{{
130
+ if data && !data.empty?
131
+ content = XML::Smart.string('<dataelements xmlns="http://cpee.org/ns/properties/2.0">')
132
+ JSON::parse(data).each do |k,v|
133
+ content.root.add(k,v)
134
+ end
135
+ srv = Riddl::Client.new(cpee, cpee + "?riddl-description")
136
+ res = srv.resource("/#{instance}/properties/dataelements/")
137
+ status, response = res.patch [
138
+ Riddl::Parameter::Complex.new('dataelements','text/xml',content.to_s)
139
+ ]
140
+ end rescue nil
141
+ end #}}}
142
+ def handle_endpoints(cpee,instance,data) #{{{
143
+ if data && !data.empty?
144
+ content = XML::Smart.string('<endpoints xmlns="http://cpee.org/ns/properties/2.0">')
145
+ JSON::parse(data).each do |k,v|
146
+ content.root.add(k,v)
147
+ end
148
+ srv = Riddl::Client.new(cpee, cpee + "?riddl-description")
149
+ res = srv.resource("/#{instance}/properties/endpoints/")
150
+ status, response = res.patch [
151
+ Riddl::Parameter::Complex.new('endpoints','text/xml',content.to_s)
152
+ ]
153
+ end rescue nil
154
+ end #}}}
155
+ end #}}}
156
+
157
+ class InstantiateGit < Riddl::Implementation #{{{
158
+ include Helpers
159
+
160
+ def response
161
+ cpee = @h['X_CPEE'] || @a[0]
162
+ selfurl = @a[1]
163
+ cblist = @a[2]
164
+
165
+ status, res = Riddl::Client.new(File.join(@p[1].value,'raw',@p[2].value,@p[3].value).gsub(/ /,'%20')).get
166
+ tdoc = if status >= 200 && status < 300
167
+ res[0].value.read
168
+ else
169
+ (@status = 500) && return
170
+ end
171
+ stream = @p.find{ |e| e.name == 'stream' }&.value
172
+ if (instance, uuid = load_testset(tdoc,cpee,nil,stream)).first == -1
173
+ @status = 500
174
+ else
175
+ handle_data cpee, instance, @p[4]&.value if @p[4]&.name == 'init'
176
+ handle_endpoints cpee, instance, @p[4]&.value if @p[4]&.name == 'endpoints'
177
+ handle_endpoints cpee, instance, @p[5]&.value if @p[5]&.name == 'endpoints'
178
+
179
+ handle_waiting cpee, instance, uuid, @p[0].value, selfurl, cblist
180
+ handle_starting cpee, instance, @p[0].value
181
+
182
+ send = {
183
+ 'CPEE-INSTANCE' => instance,
184
+ 'CPEE-INSTANCE-URL' => File.join(cpee,instance),
185
+ 'CPEE-INSTANCE-UUID' => uuid,
186
+ 'CPEE-BEHAVIOR' => @p[0].value
187
+ }
188
+ @headers << Riddl::Header.new('CPEE-INSTANTIATION',JSON::generate(send))
189
+ Riddl::Parameter::Complex.new('instance','application/json',JSON::generate(send))
190
+ end
191
+ end
192
+ end #}}}
193
+
194
+ class InstantiateUrl < Riddl::Implementation #{{{
195
+ include Helpers
196
+
197
+ def response
198
+ cpee = @h['X_CPEE'] || @a[0]
199
+ selfurl = @a[1]
200
+ cblist = @a[2]
201
+ name = @a[3] ? @p.shift.value : nil
202
+
203
+ status, res = Riddl::Client.new(@p[1].value.gsub(/ /,'%20')).get
204
+ tdoc = if status >= 200 && status < 300
205
+ res[0].value.read
206
+ else
207
+ (@status = 500) && return
208
+ end
209
+ stream = @p.find{ |e| e.name == 'stream' }&.value
210
+ if (instance, uuid = load_testset(tdoc,cpee,name,stream)).first == -1
211
+ @status = 500
212
+ else
213
+ handle_data cpee, instance, @p[2]&.value if @p[2]&.name == 'init'
214
+ handle_endpoints cpee, instance, @p[2]&.value if @p[2]&.name == 'endpoints'
215
+ handle_endpoints cpee, instance, @p[3]&.value if @p[3]&.name == 'endpoints'
216
+
217
+ handle_waiting cpee, instance, uuid, @p[0].value, selfurl, cblist
218
+ handle_starting cpee, instance, @p[0].value
219
+
220
+ send = {
221
+ 'CPEE-INSTANCE' => instance,
222
+ 'CPEE-INSTANCE-URL' => File.join(cpee,instance),
223
+ 'CPEE-INSTANCE-UUID' => uuid,
224
+ 'CPEE-BEHAVIOR' => @p[0].value
225
+ }
226
+ @headers << Riddl::Header.new('CPEE-INSTANTIATION',JSON::generate(send))
227
+ Riddl::Parameter::Complex.new('instance','application/json',JSON::generate(send))
228
+ end
229
+ end
230
+ end #}}}
231
+
232
+ class InstantiateXML < Riddl::Implementation #{{{
233
+ include Helpers
234
+
235
+ def response
236
+ cpee = @h['X_CPEE'] || @a[0]
237
+ behavior = @a[1] ? 'fork_ready' : @p[0].value
238
+ data = @a[1] ? 0 : 1
239
+ selfurl = @a[2]
240
+ cblist = @a[3]
241
+ tdoc = if @p[data].additional =~ /base64/
242
+ Base64.decode64(@p[data].value.read)
243
+ else
244
+ @p[data].value.read
245
+ end
246
+
247
+ if (instance, uuid = load_testset(tdoc,cpee)).first == -1
248
+ @status = 500
249
+ else
250
+ handle_data cpee, instance, @p[data+1]&.value
251
+ handle_waiting cpee, instance, uuid, behavior, selfurl, cblist
252
+ handle_starting cpee, instance, behavior
253
+
254
+ send = {
255
+ 'CPEE-INSTANCE' => instance,
256
+ 'CPEE-INSTANCE-URL' => File.join(cpee,instance),
257
+ 'CPEE-INSTANCE-UUID' => uuid,
258
+ 'CPEE-BEHAVIOR' => behavior
259
+ }
260
+ Riddl::Parameter::Complex.new('instance','application/json',JSON::generate(send))
261
+ end
262
+ end
263
+ end #}}}
264
+
265
+ class HandleInstance < Riddl::Implementation #{{{
266
+ include Helpers
267
+
268
+ def response
269
+ cpee = @h['X_CPEE'] || @a[0]
270
+ selfurl = @a[1]
271
+ cblist = @a[2]
272
+ instance = @p[1].value
273
+
274
+ srv = Riddl::Client.new(cpee, cpee + "?riddl-description")
275
+ res = srv.resource("/#{instance}/properties/attributes/uuid")
276
+ status, response = res.get
277
+
278
+ if status >= 200 && status < 300
279
+ uuid = XML::Smart::string(response.first.value).root.text
280
+ handle_data cpee, instance, @p[2]&.value
281
+ handle_waiting cpee, instance, uuid, @p[0].value, selfurl, cblist
282
+ handle_starting cpee, instance, @p[0].value
283
+ return Riddl::Parameter::Simple.new("url",cpee + instance)
284
+ end
285
+ end
286
+ end #}}}
287
+
288
+ class ContinueTask < Riddl::Implementation #{{{
289
+ def response
290
+ cblist = @a[1]
291
+ topic = @p[1].value
292
+ event_name = @p[2].value
293
+ notification = if @p[3].class === Riddl::Parameter::Simple
294
+ JSON.parse(@p[3].value)
295
+ else
296
+ JSON.parse(@p[3].value.read)
297
+ end
298
+
299
+ key = @r.last
300
+ cb, condition, instance, uuid, instance_url = cblist.lrange(key,0,-1)
301
+
302
+ cpee = File.dirname(instance_url)
303
+
304
+ send = {
305
+ 'CPEE-INSTANCE' => instance,
306
+ 'CPEE-INSTANCE-URL' => instance_url,
307
+ 'CPEE-INSTANCE-UUID' => uuid,
308
+ 'CPEE-STATE' => notification['content']['state']
309
+ }
310
+
311
+ if notification['content']['state'] == condition
312
+ cblist.del(key)
313
+ srv = Riddl::Client.new(cpee, cpee + "?riddl-description")
314
+ res = srv.resource("/#{instance}/properties/dataelements")
315
+ status, response = res.get
316
+ if status >= 200 && status < 300
317
+ doc = XML::Smart.string(response[0].value.read)
318
+ doc.register_namespace 'p', 'http://cpee.org/ns/properties/2.0'
319
+ doc.find('/p:dataelements/*').each do |e|
320
+ send[e.qname.name] = CPEE::ValueHelper::parse(e.text)
321
+ end
322
+ end
323
+ Riddl::Client.new(cb).put Riddl::Parameter::Complex.new('dataelements','application/json',JSON::generate(send))
324
+ else
325
+ Riddl::Client.new(cb).put [
326
+ Riddl::Header.new('CPEE-UPDATE','true'),
327
+ Riddl::Parameter::Complex.new('dataelements','application/json',JSON::generate(send))
328
+ ]
329
+ end
330
+ end
331
+ end #}}}
332
+
333
+ def self::implementation(opts)
334
+ opts[:cpee] ||= 'http://localhost:9298/'
335
+ opts[:redis_path] ||= '/tmp/redis.sock'
336
+ opts[:redis_db] ||= 14
337
+ opts[:self] ||= "http#{opts[:secure] ? 's' : ''}://#{opts[:host]}:#{opts[:port]}/"
338
+ opts[:cblist] = Redis.new(path: opts[:redis_path], db: opts[:redis_db])
339
+ Proc.new do
340
+ on resource do
341
+ run InstantiateXML, opts[:cpee], true if post 'xmlsimple'
342
+ on resource 'xml' do
343
+ run InstantiateXML, opts[:cpee], false if post 'xml'
344
+ end
345
+ on resource 'url' do
346
+ run InstantiateUrl, opts[:cpee], opts[:self], opts[:cblist], false if post 'url'
347
+ run InstantiateUrl, opts[:cpee], opts[:self], opts[:cblist], true if post 'url_info'
348
+ end
349
+ on resource 'git' do
350
+ run InstantiateGit, opts[:cpee], opts[:self], opts[:cblist] if post 'git'
351
+ end
352
+ on resource 'instance' do
353
+ run HandleInstance, opts[:cpee] if post 'instance'
354
+ end
355
+ on resource 'callback' do
356
+ on resource do
357
+ run ContinueTask, opts[:cpee], opts[:cblist] if post
358
+ end
359
+ end
360
+ end
361
+ end
362
+ end
363
+
364
+ end
365
+ end
@@ -0,0 +1,125 @@
1
+ <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
+ <message name="xmlsimple">
3
+ <parameter name="xml" mimetype="*/xml"/>
4
+ </message>
5
+ <message name="xml">
6
+ <parameter name="behavior" type="string">
7
+ <choice>
8
+ <value>fork_ready</value>
9
+ <value>fork_running</value>
10
+ <value>wait_ready</value>
11
+ <value>wait_running</value>
12
+ </choice>
13
+ </parameter>
14
+ <parameter name="xml" mimetype="*/xml"/>
15
+ <optional>
16
+ <parameter name="init" type="string"/>
17
+ </optional>
18
+ </message>
19
+ <message name="url_info">
20
+ <parameter name="info" type="string"/>
21
+ <parameter name="behavior" type="string">
22
+ <choice>
23
+ <value>fork_ready</value>
24
+ <value>fork_running</value>
25
+ <value>wait_ready</value>
26
+ <value>wait_running</value>
27
+ </choice>
28
+ </parameter>
29
+ <parameter name="url" type="string"/>
30
+ <optional>
31
+ <parameter name="init" type="string"/>
32
+ </optional>
33
+ <optional>
34
+ <parameter name="endpoints" type="string"/>
35
+ </optional>
36
+ <optional>
37
+ <parameter name="stream" type="string"/>
38
+ </optional>
39
+ </message>
40
+ <message name="url">
41
+ <parameter name="behavior" type="string">
42
+ <choice>
43
+ <value>fork_ready</value>
44
+ <value>fork_running</value>
45
+ <value>wait_ready</value>
46
+ <value>wait_running</value>
47
+ </choice>
48
+ </parameter>
49
+ <parameter name="url" type="string"/>
50
+ <optional>
51
+ <parameter name="init" type="string"/>
52
+ </optional>
53
+ <optional>
54
+ <parameter name="endpoints" type="string"/>
55
+ </optional>
56
+ <optional>
57
+ <parameter name="stream" type="string"/>
58
+ </optional>
59
+ </message>
60
+ <message name="git">
61
+ <parameter name="behavior" type="string">
62
+ <choice>
63
+ <value>fork_ready</value>
64
+ <value>fork_running</value>
65
+ <value>wait_ready</value>
66
+ <value>wait_running</value>
67
+ </choice>
68
+ </parameter>
69
+ <parameter name="repo" type="string"/>
70
+ <parameter name="branch" type="string"/>
71
+ <parameter name="path" type="string"/>
72
+ <optional>
73
+ <parameter name="init" type="string"/>
74
+ </optional>
75
+ <optional>
76
+ <parameter name="endpoints" type="string"/>
77
+ </optional>
78
+ <optional>
79
+ <parameter name="stream" type="string"/>
80
+ </optional>
81
+ </message>
82
+ <message name="instance">
83
+ <parameter name="behavior" type="string">
84
+ <choice>
85
+ <value>fork_ready</value>
86
+ <value>fork_running</value>
87
+ <value>wait_ready</value>
88
+ <value>wait_running</value>
89
+ <value>wait_stopped_running</value>
90
+ <value>wait_finished_running</value>
91
+ </choice>
92
+ </parameter>
93
+ <parameter name="instance" type="integer"/>
94
+ <optional>
95
+ <parameter name="init" type="string"/>
96
+ </optional>
97
+ </message>
98
+
99
+ <message name="result">
100
+ <parameter name="instance" mimetype="application/json"/>
101
+ </message>
102
+
103
+ <resource>
104
+ <post in="xmlsimple" out="result"/>
105
+ <resource relative="xml">
106
+ <post in="xml" out="result"/>
107
+ </resource>
108
+ <resource relative="instance">
109
+ <post in="instance" out="result"/>
110
+ </resource>
111
+ <resource relative="url">
112
+ <post in="url" out="result"/>
113
+ <post in="url_info" out="result"/>
114
+ </resource>
115
+ <resource relative="git">
116
+ <post in="git" out="result"/>
117
+ </resource>
118
+ <resource relative="callback">
119
+ <resource>
120
+ <post/>
121
+ </resource>
122
+ </resource>
123
+ </resource>
124
+
125
+ </description>
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/ruby
2
+ require 'rubygems'
3
+ require 'cpee-instantiation/instantiation'
4
+
5
+ options = {
6
+ :host => 'localhost',
7
+ :port => 9296,
8
+ :secure => false
9
+ }
10
+
11
+ Riddl::Server.new(CPEE::Instantiation::SERVER, options) do
12
+ accessible_description true
13
+ cross_site_xhr true
14
+
15
+ @riddl_opts[:cpee] ||= 'http://localhost:8298/'
16
+
17
+ use CPEE::Instantiation::implementation(@riddl_opts)
18
+ end.loop!
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/ruby
2
+ curpath = __dir__
3
+ require 'rubygems'
4
+ require 'optparse'
5
+ require 'fileutils'
6
+ require 'xml/smart'
7
+
8
+ def wrap(s, width=78, indent=18)
9
+ lines = []
10
+ line, s = s[0..indent-2], s[indent..-1]
11
+ s.split(/\n/).each do |ss|
12
+ ss.split(/[ \t]+/).each do |word|
13
+ if line.size + word.size >= width
14
+ lines << line
15
+ line = (" " * (indent)) + word
16
+ else
17
+ line << " " << word
18
+ end
19
+ end
20
+ lines << line if line
21
+ line = (" " * (indent-1))
22
+ end
23
+ return lines.join "\n"
24
+ end
25
+
26
+ ARGV.options { |opt|
27
+ opt.summary_indent = ' ' * 2
28
+ opt.summary_width = 15
29
+ opt.banner = "Usage:\n#{opt.summary_indent}#{File.basename($0)} [DIR]\n"
30
+ opt.on("Options:")
31
+ opt.on("--help", "-h", "This text") { puts opt; exit }
32
+ opt.on("")
33
+ opt.on(wrap("[DIR] scaffolds a sample instantiation service. Post a testset to a model to keep going in one operation."))
34
+ opt.parse!
35
+ }
36
+ if (ARGV.length != 1)
37
+ puts ARGV.options
38
+ exit
39
+ else
40
+ p1 = ARGV[0]
41
+ end
42
+
43
+ if !File.exists?(p1)
44
+ FileUtils.cp_r("#{curpath}/../server/",p1)
45
+ else
46
+ puts 'Directory already exists.'
47
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cpee-instantiation
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Juergen eTM Mangler
8
+ autorequire:
9
+ bindir: tools
10
+ cert_chain: []
11
+ date: 2020-09-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: riddl
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.99'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.99'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: redis
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: cpee
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1'
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '1.5'
65
+ type: :runtime
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: '1'
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '1.5'
75
+ description: see http://cpee.org
76
+ email: juergen.mangler@gmail.com
77
+ executables:
78
+ - cpee-instantiation
79
+ extensions: []
80
+ extra_rdoc_files:
81
+ - README.md
82
+ files:
83
+ - AUTHORS
84
+ - LICENSE
85
+ - README.md
86
+ - Rakefile
87
+ - cpee-instantiation.gemspec
88
+ - lib/cpee-instantiation/instantiation.rb
89
+ - lib/cpee-instantiation/instantiation.xml
90
+ - server/instantiation
91
+ - tools/cpee-instantiation
92
+ homepage: http://cpee.org/
93
+ licenses:
94
+ - LGPL-3.0
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: 2.4.0
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubygems_version: 3.1.2
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Subprocess instantiation service for the cloud process execution engine (cpee.org)
115
+ test_files: []