aboutsummaryrefslogtreecommitdiffstats
path: root/docs/developerguide/running-bp-processor-in-ide.rst
blob: 05c8251019fe3d6ae2cb777bc0199e78834d2df0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
.. This work is a derivative of https://wiki.onap.org/display/DW/Running+Blueprints+Processor+Microservice+in+an+IDE
.. This work is licensed under a Creative Commons Attribution 4.0
.. International License. http://creativecommons.org/licenses/by/4.0
.. Copyright (C) 2020 Deutsche Telekom AG.

Running Blueprints Processor Microservice in an IDE
====================================================

Objective
~~~~~~~~~~~~

Have the processor running locally is to use the IDE to run the code, while having the database running in a container. 
This way, code changes can be conveniently tested and debugged.


Check out the code
~~~~~~~~~~~~~~~~~~~

Check out the code from Gerrit: https://gerrit.onap.org/r/#/admin/projects/ccsdk/cds

Build it locally
~~~~~~~~~~~~~~~~~~

In the checked out directory, type

.. code-block:: bash

   mvn clean install -DskipTests=true -Dmaven.test.skip=true -Dmaven.javadoc.skip=true -Dadditionalparam=-Xdoclint:none

Spin up a Docker container with the database
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The Blueprints Processor project uses a database to store information about the blueprints 
and therefore it needs to be online before attempting to run it.

One way to create the database is by using the :file:`docker-compose.yaml` 
file present on the distribution module. This database will require a local directory to mount a volume, before running docker-compose remember to create following directory:

.. code-block:: bash

   mkdir -p -m 755 /opt/app/cds/mysql/data

Navigate to the docker-compose file in the distribution module:

.. tabs::

   .. group-tab:: Latest

      .. code-block:: bash

         cd ms/blueprintsprocessor/application/src/main/dc

   .. group-tab:: Frankfurt

      .. code-block:: bash

         cd ms/blueprintsprocessor/application/src/main/dc

   .. group-tab:: El Alto

      .. code-block:: bash

         ms/blueprintsprocessor/distribution/src/main/dc

   .. group-tab:: Dublin

      .. code-block:: bash

         ms/blueprintsprocessor/distribution/src/main/dc

And run docker-composer:

.. code-block:: bash

    docker-compose up -d db

This should spin up a container of the MariaDB image in the background.
To check if it has worked, this command can be used:

.. code-block:: bash

    docker-compose logs -f

The phrase ``mysqld: ready for connections`` indicates that the database was started correctly.

From now on, the Docker container will be available on the computer; if it ever gets stopped,
it can be started again by the command:

.. code-block:: bash

   docker start <id of mariadb container>


Set permissions on the local file system
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Blueprints processor uses the local file system for some operations and, therefore,
need some existing and accessible paths to run properly.

Execute the following commands to create the needed directories, and grant access to the current user to modify them:

.. code-block:: bash

   mkdir -p -m 755 /opt/app/onap/blueprints/archive
   mkdir -p -m 755 /opt/app/onap/blueprints/deploy
   mkdir -p -m 755 /opt/app/onap/scripts
   sudo chown -R $(id -u):$(id -g) /opt/app/onap/

Import the project on the IDE
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

For this page, the chosen IDE is IntelliJ, but the instructions present here can
be adapted to be used in other IDEs as well.

Go to *File | Open* and choose the :file:`pom.xml` file of the cds directory:

|imageImportProject|

Sometimes it may be necessary to reimport Maven project:

|imageReimportMaven|


Override some application properties
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

After the project is compiled, a Run Configuration profile overriding some application properties
with custom values needs to be created, to reflect the local environment characteristics.

.. tabs::

   .. group-tab:: Latest

      Navigate to the main class of the Blueprints Processor, the BlueprintProcessorApplication class:

      ``ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintProcessorApplication.kt``.

      Right-click inside it, at any point, to load the context menu and select create 
      BlueprintProcessorApplication configuration from context:

      |imageCreateRunConfigkt|

      **The following window will open:**

      |imageRunConfigKt|

      **Add the following in the field `VM Options`:**

      .. code-block:: bash
         :caption: **Custom values for properties**

         -Dspring.profiles.active=dev

      You can override any value from **application-dev.properties** file here. Use the following pattern:

      .. code-block:: java

         -D<application-dev.properties key>=<application-dev.properties value>

   .. group-tab:: Frankfurt

      Navigate to the main class of the Blueprints Processor, the BlueprintProcessorApplication class:

      ``ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintProcessorApplication.kt``.

      Right-click inside it, at any point, to load the context menu and select create 
      BlueprintProcessorApplication configuration from context:

      |imageCreateRunConfigkt|

      **The following window will open:**

      |imageRunConfigKt|

      **Add the following in the field `VM Options`:**

      .. code-block:: bash
         :caption: **Custom values for properties**

         -Dspring.profiles.active=dev

      You can override any value from **application-dev.properties** file here. Use the following pattern:

      .. code-block:: java

         -D<application-dev.properties key>=<application-dev.properties value>

   .. group-tab:: El Alto

      Navigate to the main class of the Blueprints Processor, the BlueprintProcessorApplication class:

      ``ms/blueprintsprocessor/application/src/main/java/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintProcessorApplication.java.``

      Right-click inside it, at any point, to load the context menu and select create 
      BlueprintProcessorApplication configuration from context:

      |imageCreateRunConfigJava|

      **The following window will open:**

      |imageRunConfigJava|

      **Add the following in the field `VM Options`:**

      .. code-block:: bash
         :caption: **Custom values for properties**

         -Dspring.profiles.active=dev

      You can override any value from **application-dev.properties** file here. Use the following pattern:

      .. code-block:: java

         -D<application-dev.properties key>=<application-dev.properties value>

   .. group-tab:: Dublin

      Navigate to the main class of the Blueprints Processor, the BlueprintProcessorApplication class:

      ``ms/blueprintsprocessor/application/src/main/java/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintProcessorApplication.java``.

      Right-click inside it, at any point, to load the context menu and select create
      BlueprintProcessorApplication configuration from context:

      |imageCreateRunConfigJava|

      **The following window will open:**

      |imageRunConfigJava|

      **Add the following in that field:**

      .. code-block:: java
         :caption: **Custom values for properties**

         -DappName=ControllerBluePrints
         -Dms_name=org.onap.ccsdk.apps.controllerblueprints
         -DappVersion=1.0.0
         -Dspring.config.location=opt/app/onap/config/
         -Dspring.datasource.url=jdbc:mysql://127.0.0.1:3306/sdnctl
         -Dspring.datasource.username=sdnctl
         -Dspring.datasource.password=sdnctl
         -Dcontrollerblueprints.loadInitialData=true
         -Dblueprintsprocessor.restclient.sdncodl.url=http://localhost:8282/
         -Dblueprintsprocessor.db.primary.url=jdbc:mysql://localhost:3306/sdnctl
         -Dblueprintsprocessor.db.primary.username=sdnctl
         -Dblueprintsprocessor.db.primary.password=sdnctl
         -Dblueprintsprocessor.db.primary.driverClassName=org.mariadb.jdbc.Driver
         -Dblueprintsprocessor.db.primary.hibernateHbm2ddlAuto=update
         -Dblueprintsprocessor.db.primary.hibernateDDLAuto=none
         -Dblueprintsprocessor.db.primary.hibernateNamingStrategy=org.hibernate.cfg.ImprovedNamingStrategy
         -Dblueprintsprocessor.db.primary.hibernateDialect=org.hibernate.dialect.MySQL5InnoDBDialect
         -Dblueprints.processor.functions.python.executor.executionPath=./components/scripts/python/ccsdk_blueprints
         -Dblueprints.processor.functions.python.executor.modulePaths=./components/scripts/python/ccsdk_blueprints,./components/scripts/python/ccsdk_netconf,./components/scripts/python/ccsdk_restconf
         -Dblueprintsprocessor.restconfEnabled=true
         -Dblueprintsprocessor.restclient.sdncodl.type=basic-auth
         -Dblueprintsprocessor.restclient.sdncodl.url=http://localhost:8282/
         -Dblueprintsprocessor.restclient.sdncodl.username=admin
         -Dblueprintsprocessor.restclient.sdncodl.password=Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U
         -Dblueprintsprocessor.grpcEnable=false
         -Dblueprintsprocessor.grpcPort=9111
         -Dblueprintsprocessor.blueprintDeployPath=/opt/app/onap/blueprints/deploy
         -Dblueprintsprocessor.blueprintArchivePath=/opt/app/onap/blueprints/archive
         -Dblueprintsprocessor.blueprintWorkingPath=/opt/app/onap/blueprints/work
         -Dsecurity.user.password={bcrypt}$2a$10$duaUzVUVW0YPQCSIbGEkQOXwafZGwQ/b32/Ys4R1iwSSawFgz7QNu
         -Dsecurity.user.name=ccsdkapps
         -Dblueprintsprocessor.messageclient.self-service-api.kafkaEnable=false
         -Dblueprintsprocessor.messageclient.self-service-api.topic=producer.t
         -Dblueprintsprocessor.messageclient.self-service-api.type=kafka-basic-auth
         -Dblueprintsprocessor.messageclient.self-service-api.bootstrapServers=127.0.0.1:9092
         -Dblueprintsprocessor.messageclient.self-service-api.consumerTopic=receiver.t
         -Dblueprintsprocessor.messageclient.self-service-api.groupId=receiver-id
         -Dblueprintsprocessor.messageclient.self-service-api.clientId=default-client-id
         -Dspring.profiles.active=dev
         -Dblueprintsprocessor.httpPort=8080
         -Dserver.port=55555


Add/replace the following in Blueprint's application-dev.properties file:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code-block:: java

   blueprintsprocessor.grpcclient.remote-python.type=token-auth
   blueprintsprocessor.grpcclient.remote-python.host=localhost
   blueprintsprocessor.grpcclient.remote-python.port=50051
   blueprintsprocessor.grpcclient.remote-python.token=Basic Y2NzZGthcHBzOmNjc2RrYXBwcw==

   blueprintprocessor.remoteScriptCommand.enabled=true


Run the application
~~~~~~~~~~~~~~~~~~~

Select either run or debug for this Run Configuration to start the Blueprints Processor:

|imageRunDebug|

|imageBuildLogs|


Testing the application
~~~~~~~~~~~~~~~~~~~~~~~~~

There are two main features of the Blueprints Processor that can be of interest of a developer:
blueprint upload and blueprint process.

To upload custom blueprints,  the endpoint ``api/v1/execution-service/upload`` is used.

To process, the endpoint is ``api/v1/execution-service/process``.

Postman is a software that can be used to send these request, and an example of
them is present on https://www.getpostman.com/collections/b99863b0cde7565a32fc.


Possible Fixes
~~~~~~~~~~~~~~~~~~~

Imported packages or annotiations are not found, Run Config not available?
*****************************************************************************

1. Rebuild with ``maven install ...`` (see above)
2. Potentially change Maven home directory in Settings
3. Maven reimport in IDE

Compilation error?
********************

* Change Java Version to 11 or 8

.. |imageRunConfigJava| image:: media/run_config_java.png
   :scale: 100 %
   :align: middle

.. |imageRunConfigKt| image:: media/run_config_kt.png
   :scale: 100 %
   :align: middle

.. |imageCreateRunConfigJava| image:: media/create_run_config_java.png
   :scale: 100 %
   :align: middle

.. |imageCreateRunConfigKt| image:: media/create_run_config_kt.png
   :scale: 100 %
   :align: middle

.. |imageImportProject| image:: media/import_project.png
   :scale: 100 %
   :align: middle

.. |imageReimportMaven| image:: media/reimport_maven.png
   :scale: 70 %
   :align: middle

.. |imageRunDebug| image:: media/run_debug.png
   :scale: 100 %
   :align: middle

.. |imageRunDebug| image:: media/run_debug.png
   :align: middle
   :scale: 100 %

.. |imageBuildLogs| image:: media/build_logs.png
   :align: middle
   :scale: 100 %