blob: 52337fcfc34cabcbd81e4e40a46bfbaebc8e7a9b [file] [log] [blame]
Sarah Abouzainahf8c5f582021-01-12 14:47:21 +02001.. This work is licensed under a Creative Commons Attribution 4.0 International License.
2.. http://creativecommons.org/licenses/by/4.0
3.. Copyright (C) 2019 IBM.
4
5.. _hello_world_script_executor_cba:
6
7How to create a Hello World Package with CDS Designer UI? The Script Executor Type
8====================================================================================
9
10.. toctree::
11 :maxdepth: 2
12
13.. note::
14 **How to Get Started with CDS Designer UI**
15
16 If youre new to CDS Designer UI and need to get set up, the following guides may be helpful:
17
18 - :ref:`running_cds_ui_locally`
19 - :ref:`designer_guide`
20
21.. note::
22 **NOTE:**
23
24 In order to see the latest version described below in the tutorial, we will need to use the latest cds-ui-server docker image:
25 nexus3.onap.org:10001/onap/ccsdk-cds-ui-server:1.1.0-STAGING-latest
26
27
28Create New CBA Package
29~~~~~~~~~~~~~~~~~~~~~~
30
31In the Package List, click on the **Create Package** button.
32
33|image1|
34
35Define Package MetaData
36~~~~~~~~~~~~~~~~~~~~~~~
37
38In METADATA Tab:
39
401. Package name (Required), type **"Hello-world-package-kotlin"**
412. Package version (Required), type **"1.0.0"**
423. Package description (Required), type **"just description"**
434. Package Tags (Required), type **"kotlin"** then use the **Enter** key on the keyboard
445. In the Custom Key section, add Key name **"template_type"** and
456. For Key Value **"DEFAULT"**
46
47|image2|
48
49Once you enter all fields you will be able to save your package. Click on the **Save** button and continue to define your package.
50
51|image3|
52
53Define Scripts
54~~~~~~~~~~~~~~
55
56In the SCRIPTS Tab:
57
581. Click on the **Create Script** button
59
60|image4|
61
62In the **Create Script File** modal:
63
64|image5|
65
661. Enter script file name **"Test"**
672. Choose the script type **"Kotlin"**
683. Type or copy and paste the below script in the code editor
69
70.. code-block:: kotlin
71
72 /*
73 \* Copyright © 2020, Orange
74 \*
75 \* Licensed under the Apache License, Version 2.0 (the "License");
76 \* you may not use this file except in compliance with the License.
77 \* You may obtain a copy of the License at
78 \*
79 \* http://www.apache.org/licenses/LICENSE-2.0
80 \*
81 \* Unless required by applicable law or agreed to in writing, software
82 \* distributed under the License is distributed on an "AS IS" BASIS,
83 \* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
84 \* See the License for the specific language governing permissions and
85 \* limitations under the License.
86 */
87
88 package org.onap.ccsdk.cds.blueprintsprocessor.services.execution.scripts
89
90 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
91 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractScriptComponentFunction
92 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ComponentRemoteScriptExecutor
93 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
94 import org.slf4j.LoggerFactory
95
96 open class HelloWorld : AbstractScriptComponentFunction() {
97 private val log = LoggerFactory.getLogger(HelloWorld::class.java)!!
98
99 override fun getName(): String {
100 return "Check"
101 }
102
103 override suspend fun processNB(executionRequest: ExecutionServiceInput) {
104 log.info("executing hello world script ")
105 val username = getDynamicProperties("username").asText()
106 log.info("username : $username")
107 //executionRequest.payload.put("Action1-response","hello from $username")
108 setAttribute("response-data", "Hello, $username".asJsonPrimitive())
109 }
110
111 override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
112 log.info("Executing Recovery")
KAPIL SINGALadcd4f22021-01-22 11:49:51 -0500113 bluePrintRuntimeService.getBlueprintError().addError("${runtimeException.message}")
Sarah Abouzainahf8c5f582021-01-12 14:47:21 +0200114 }
115 }
116
1174. Click on the **Create Script** button to save the script file
118
119|image6|
120
121Now, you can view and edit your script file.
122
123|image7|
124
125After the new script is added to the **scripts list**, click on the **Save** button to save the package updates.
126
127|image8|
128
129Define DSL Properties
130~~~~~~~~~~~~~~~~~~~~~
131
132In the DSL PROPERTIES Tab:
133
1341. Copy and paste the below DSL definition
135
136.. code-block::
137
138 {
139 "Action1-properties": {
140 "username": {
141 "get_input": "username"
142 }
143 }
144 }
145
146|image9|
147
148Then click on the **Save** button to update the package.
149
150|image10|
151
152Create An Action
153~~~~~~~~~~~~~~~~~
154
155From the Package information box on top, click on the **Designer Mode** button.
156
157|image11|
158
159Click on the **Skip to Designer Canvas** button to go directly to Designer Mode.
160
161|image12|
162
163Now the designer has zero action added. Let's start adding the first Action.
164
165|image13|
166
167Go to the left side of the designer screen and in the **ACTIONS tab**, click on the **+ New Action** button.
168
169|image14|
170
171Now, the first Action **Action1** is added to the **Actions list** and in the **Workflow canvas**.
172
173|image15|
174
175Add Script Executor Function To The Action
176~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
177
178On the left side of the designer screen, Click on the **FUNCTIONS tab** to view all the **Functions List.**
179
180|image16|
181
182**Drag** the function type **"component-script-executor"**
183
184|image17|
185
186**Drop** the function to the **"Action1"** Action container.
187
188|image18|
189
190Define Action Attributes
191~~~~~~~~~~~~~~~~~~~~~~~~
192
193Click on **Action1** from the ACTIONS tab to open **the ACTION ATTRIBUTES** section on designer screens’ right side.
194
195|image19|
196
197Let's customize the first action's attribute by click on the **+ Create Custom** button to open **Add Custom Attributes** modal window.
198
199|image20|
200
201In the **Add Custom Attributes** **Window**, and the **INPUTS tab** starts to add the first input attribute for **Action1**.
202**INPUTS Tab:** Enter the required properties for the inputs’ attribute:
203
2041. Name: **"username"**
2052. Type: **"Other"**
2063. Attribute type name: **"dt-resource-assignment-properties"**
2074. Required: **"True"**
208
209|image21|
210
211After you add the **username** input's attribute, click on In the OUTPUT Tab to create the output attribute too.
212
213|image22|
214
215**OUTPUTS Tab:** Enter the required properties for the output attribute:
216
2171. Name: **"hello-world-output"**
2182. Required: **"True"**
2193. Type: **"Other"**
2204. Type name: **"json"**
2215. Value (get_attribute): From the **Functions list**, select **"component-script-executor"** that will show all attributes included in this function
2226. Select parameter name **"response-data"**
2237. Click on the **Submit Attributes** button to add input and output attributes to **Actions' Attributes list**
2248. Click on the **Close** button to close the modal window and go back to the designer screen.
225
226|image23|
227
228Now, you can see all the added attributes listed in the **ACTION ATTRIBUTES** area.
229
230|image24|
231
232Define Function Attributes
233~~~~~~~~~~~~~~~~~~~~~~~~~~
234
235From **ACTIONS** List, Click on the function nam **"component-script-executor"**.
236
237|image25|
238
239When you click on the **component-script-executor** function, the **FUNCTION ATTRIBUTES** section will be open on the right side of the designers' screen.
240Now, you need to add the values of **Inputs** required attributes in **the Interfaces** **section**.
241
242|image26|
243
2441. **script-type:** **"kotlin"**
2452. **script-class-reference: "org.onap.ccsdk.cds.blueprintsprocessor.services.execution.scripts.HelloWorld"**
2463. Add optional attribute by click on **Add Optional Attributes** button, add **"dynamic-properties"** then enter the value **"*Action1-properties"**
247
248|image27|
249
Sarah Abouzainahf8c5f582021-01-12 14:47:21 +0200250From the page header and inside **the Save** **menu**, click on the **Save** button to save all the changes.
251
252|image29|
253
254Enrich And Deploy The CBA Package
255~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
256
257From the page header and inside the **Save menu**, click on the **Enrich & Deploy** button.
258
259|image30|
260
261Once the process is done, a confirmation message will appear.
262
263|image31|
264
265Test The CBA package With CDS REST API
266~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
267
268To test the CDS hello_world package we created, we can use the REST API shown below to run the **script executor** workflow in the **Hello-world-package-kotlin** package, which will resolve the value of the "username" resource from the REST Call input, and will send it back to the user in the form of "Hello, $username!".
269
270**CURL Request to RUN CBA Package**
271
272.. code-block:: bash
273
274 curl --location --request POST 'http://10.1.1.9:8080/api/v1/execution-service/process' \
275 --header 'Content-Type: application/json;charset=UTF-8' \
276 --header 'Accept: application/json;charset=UTF-8,application/json' \
277 --header 'Authorization: Basic Y2NzZGthcHBzOmNjc2RrYXBwcw==' \
278 --header 'Host: cds-blueprints-processor-http:8080' \
279 --header 'Cookie: JSESSIONID=7E69BC3F752FD5A3D7D1663FE583ED71' \
280 --data-raw '{
281 "actionIdentifiers": {
282 "mode": "sync",
283 "blueprintName": "Hello-world-package-kotlin",
284 "blueprintVersion": "1.0.0",
285 "actionName": "Action1"
286 },
287 "payload": {
288 "Action1-request": {
289 "username":"Orange Egypt"
290 }
291 },
292 "commonHeader": {
293 "subRequestId": "143748f9-3cd5-4910-81c9-a4601ff2ea58",
294 "requestId": "e5eb1f1e-3386-435d-b290-d49d8af8db4c",
295 "originatorId": "SDNC_DG"
296 }
297 }'
298
299
300**CDS Response showing result of running package**
301
302.. code-block:: bash
303
304 200 OK
305 {
306 "correlationUUID": null,
307 "commonHeader": {
308 "timestamp": "2021-01-12T13:22:26.518Z",
309 "originatorId": "SDNC_DG",
310 "requestId": "e5eb1f1e-3386-435d-b290-d49d8af8db4c",
311 "subRequestId": "143748f9-3cd5-4910-81c9-a4601ff2ea58",
312 "flags": null
313 },
314 "actionIdentifiers": {
315 "blueprintName": "Hello-world-package-kotlin",
316 "blueprintVersion": "1.0.0",
317 "actionName": "Action1",
318 "mode": "sync"
319 },
320 "status": {
321 "code": 200,
322 "eventType": "EVENT_COMPONENT_EXECUTED",
323 "timestamp": "2021-01-12T13:22:56.144Z",
324 "errorMessage": null,
325 "message": "success"
326 },
327 "payload": {
328 "Action1-response": {
329 "hello-world-output": {
330 "hello_world_template": "Hello, Orange Egypt"
331 }
332 }
333 }
334 }
335
336Screenshot from POSTMAN showing how to run the **Hello_world-package-kotlin** package, and the CDS Response:
337
338|image32|
339
340.. |image1| image:: https://wiki.onap.org/download/attachments/93006316/1.png?version=1&modificationDate=1610364491000&api=v2
341 :width: 1000pt
342.. |image2| image:: https://wiki.onap.org/download/attachments/93006316/02.png?version=1&modificationDate=1610390913000&api=v2
343 :width: 1000pt
344.. |image3| image:: https://wiki.onap.org/download/attachments/93006316/03.png?version=1&modificationDate=1610390934000&api=v2
345 :width: 1000pt
346.. |image4| image:: https://wiki.onap.org/download/attachments/93006316/04.png?version=1&modificationDate=1610391083000&api=v2
347 :width: 1000pt
348.. |image5| image:: https://wiki.onap.org/download/attachments/93006316/05.png?version=1&modificationDate=1610391137000&api=v2
349 :width: 1000pt
350.. |image6| image:: https://wiki.onap.org/download/attachments/93006316/06.png?version=1&modificationDate=1610391364000&api=v2
351 :width: 1000pt
352.. |image7| image:: https://wiki.onap.org/download/attachments/93006316/07.png?version=1&modificationDate=1610391427000&api=v2
353 :width: 1000pt
354.. |image8| image:: https://wiki.onap.org/download/attachments/93006316/08.png?version=1&modificationDate=1610391642000&api=v2
355 :width: 1000pt
356.. |image9| image:: https://wiki.onap.org/download/attachments/93006316/09.png?version=1&modificationDate=1610391749000&api=v2
357 :width: 1000pt
358.. |image10| image:: https://wiki.onap.org/download/attachments/93006316/10.png?version=2&modificationDate=1610391971000&api=v2
359 :width: 1000pt
360.. |image11| image:: https://wiki.onap.org/download/attachments/84650426/Create%20Package.jpg?version=1&modificationDate=1591034193000&api=v2
361 :width: 1000pt
362.. |image12| image:: https://wiki.onap.org/download/attachments/93006316/11.png?version=1&modificationDate=1610364492000&api=v2
363 :width: 1000pt
364.. |image13| image:: https://wiki.onap.org/download/attachments/93006316/12.png?version=2&modificationDate=1610392150000&api=v2
365 :width: 1000pt
366.. |image14| image:: https://wiki.onap.org/download/attachments/93006316/13.png?version=2&modificationDate=1610392171000&api=v2
367 :width: 300pt
368.. |image15| image:: https://wiki.onap.org/download/attachments/93006316/14.png?version=2&modificationDate=1610392192000&api=v2
369 :width: 1000pt
370.. |image16| image:: https://wiki.onap.org/download/attachments/93006316/15.png?version=2&modificationDate=1610392224000&api=v2
371 :width: 300pt
372.. |image17| image:: https://wiki.onap.org/download/attachments/93006316/16.png?version=2&modificationDate=1610392392000&api=v2
373 :width: 800pt
374.. |image18| image:: https://wiki.onap.org/download/attachments/93006316/17.png?version=3&modificationDate=1610392589000&api=v2
375 :width: 800pt
376.. |image19| image:: https://wiki.onap.org/download/attachments/93006316/18.png?version=2&modificationDate=1610392609000&api=v2
377 :width: 300pt
378.. |image20| image:: https://wiki.onap.org/download/attachments/93006316/19.png?version=1&modificationDate=1610364492000&api=v2
379 :width: 300pt
380.. |image21| image:: https://wiki.onap.org/download/attachments/93006316/20.png?version=2&modificationDate=1610392718000&api=v2
381 :width: 700pt
382.. |image22| image:: https://wiki.onap.org/download/attachments/93006316/21.png?version=2&modificationDate=1610392773000&api=v2
383 :width: 800pt
384.. |image23| image:: https://wiki.onap.org/download/attachments/93006316/22.png?version=2&modificationDate=1610392886000&api=v2
385 :width: 400pt
386.. |image24| image:: https://wiki.onap.org/download/attachments/93006316/23.png?version=2&modificationDate=1610392915000&api=v2
387 :width: 300pt
388.. |image25| image:: https://wiki.onap.org/download/attachments/93006316/24.png?version=2&modificationDate=1610392939000&api=v2
389 :width: 300pt
Sarah Abouzainahb08b7fb2021-02-10 13:55:02 +0200390.. |image26| image:: https://wiki.onap.org/download/attachments/93006316/25.png?version=4&modificationDate=1612796837000&api=v2
Sarah Abouzainahf8c5f582021-01-12 14:47:21 +0200391 :width: 378pt
Sarah Abouzainahb08b7fb2021-02-10 13:55:02 +0200392.. |image27| image:: https://wiki.onap.org/download/attachments/93006316/26.png?version=5&modificationDate=1612796934000&api=v2
Sarah Abouzainahf8c5f582021-01-12 14:47:21 +0200393 :width: 300pt
394.. |image28| image:: https://wiki.onap.org/download/attachments/93006316/26.png?version=4&modificationDate=1610393629000&api=v2
395 :width: 200pt
Sarah Abouzainahb08b7fb2021-02-10 13:55:02 +0200396.. |image29| image:: https://wiki.onap.org/download/attachments/93006316/28.png?version=5&modificationDate=1612797010000&api=v2
Sarah Abouzainahf8c5f582021-01-12 14:47:21 +0200397 :width: 1000pt
Sarah Abouzainahb08b7fb2021-02-10 13:55:02 +0200398.. |image30| image:: https://wiki.onap.org/download/attachments/93006316/29.png?version=5&modificationDate=1612797073000&api=v2
Sarah Abouzainahf8c5f582021-01-12 14:47:21 +0200399 :width: 1000pt
Sarah Abouzainahb08b7fb2021-02-10 13:55:02 +0200400.. |image31| image:: https://wiki.onap.org/download/attachments/93006316/30.png?version=2&modificationDate=1612797108000&api=v2
Sarah Abouzainahf8c5f582021-01-12 14:47:21 +0200401 :width: 1000pt
402.. |image32| image:: https://wiki.onap.org/download/attachments/93006316/31.png?version=1&modificationDate=1610459101000&api=v2
403 :width: 1000pt