Fix documentation warnings
[policy/parent.git] / docs / development / devtools / policy-participant-smoke.rst
1 .. This work is licensed under a
2 .. Creative Commons Attribution 4.0 International License.
3 .. http://creativecommons.org/licenses/by/4.0
4
5 CLAMP Policy Participant Smoke Tests
6 ------------------------------------
7
8 1. Introduction
9 ***************
10
11 The Smoke testing of the policy participant is executed in a local CLAMP/Policy environment. The CLAMP-Controlloop interfaces interact with the Policy Framework to perform actions based on the state of the policy participant. The goal of the Smoke tests is the ensure that CLAMP Policy Participant and Policy Framework work together as expected.
12
13 2. Setup Guide
14 **************
15
16 This section will show the developer how to set up their environment to start testing in GUI with some instruction on how to carry out the tests. There are a number of prerequisites. Note that this guide is written by a Linux user - although the majority of the steps show will be exactly the same in Windows or other systems.
17
18 2.1 Prerequisites
19 =================
20
21 - Java 11
22 - Maven 3
23 - Git
24 - Refer to this guide for basic environment setup `Setting up dev environment <https://wiki.onap.org/display/DW/Setting+Up+Your+Development+Environment>`_
25
26 2.2 Assumptions
27 ===============
28
29 - You are accessing the policy repositories through gerrit
30 - You are using "git review".
31
32 The following repositories are required for development in this project. These repositories should be present on your machine and you should run "mvn clean install" on all of them so that the packages are present in your .m2 repository.
33
34 - policy/parent
35 - policy/common
36 - policy/models
37 - policy/clamp
38 - policy/docker
39 - policy/gui
40 - policy/api
41
42 In this setup guide, we will be setting up all the components technically required for a working convenient dev environment.
43
44 2.3 Setting up the components
45 =============================
46
47 2.3.1 MariaDB Setup
48 ^^^^^^^^^^^^^^^^^^^
49
50 We will be using Docker to run our mariadb instance. It will have a total of two databases running in it.
51
52 - controlloop: the runtime-controlloop db
53 - policyadmin: the policy-api db
54
55 The easiest way to do this is to perform a small alteration on an SQL script provided by the clamp backend in the file "runtime/extra/sql/bulkload/create-db.sql"
56
57 .. code-block:: mysql
58
59     CREATE DATABASE `controlloop`;
60     USE `controlloop`;
61     DROP USER 'policy';
62     CREATE USER 'policy';
63     GRANT ALL on controlloop.* to 'policy' identified by 'P01icY' with GRANT OPTION;
64     CREATE DATABASE `policyadmin`;
65     USE `policyadmin`;
66     DROP USER 'policy_user';
67     CREATE USER 'policy_user';
68     GRANT ALL on controlloop.* to 'policy_user' identified by 'policy_user' with GRANT OPTION;
69     FLUSH PRIVILEGES;
70
71 Once this has been done, we can run the bash script provided here: "runtime/extra/bin-for-dev/start-db.sh"
72
73 .. code-block:: bash
74
75     ./start-db.sh
76
77 This will setup the two databases needed. The database will be exposed locally on port 3306 and will be backed by an anonymous docker volume.
78
79 2.3.2 DMAAP Simulator
80 ^^^^^^^^^^^^^^^^^^^^^
81
82 For convenience, a dmaap simulator has been provided in the policy/models repository. To start the simulator, you can do the following:
83 1. Navigate to /models-sim/policy-models-simulators in the policy/models repository.
84 2. Add a configuration file to src/test/resources with the following contents:
85
86 .. code-block:: json
87
88     {
89        "dmaapProvider":{
90           "name":"DMaaP simulator",
91           "topicSweepSec":900
92        },
93        "restServers":[
94           {
95              "name":"DMaaP simulator",
96              "providerClass":"org.onap.policy.models.sim.dmaap.rest.DmaapSimRestControllerV1",
97              "host":"localhost",
98              "port":3904,
99              "https":false
100           }
101        ]
102     }
103
104 3. You can then start dmaap with:
105
106 .. code-block:: bash
107
108     mvn exec:java  -Dexec.mainClass=org.onap.policy.models.simulators.Main -Dexec.args="src/test/resources/YOUR_CONF_FILE.json"
109
110 At this stage the dmaap simulator should be running on your local machine on port 3904.
111
112 2.3.3 Policy API
113 ^^^^^^^^^^^^^^^^
114
115 In the policy-api repo, you should find the file "src/main/resources/etc/defaultConfig.json". This file must be altered slightly - as below with the restServerParameters and databaseProviderParameters shown. Note how the database parameters match-up with what you setup in Mariadb:
116
117 .. code-block:: json
118
119     {
120         "restServerParameters": {
121             "host": "0.0.0.0",
122             "port": 6970,
123             "userName": "healthcheck",
124             "password": "zb!XztG34",
125             "prometheus": true,
126             "https": false,
127             "aaf": false
128         },
129         "databaseProviderParameters": {
130             "name": "PolicyProviderParameterGroup",
131             "implementation": "org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl",
132             "databaseDriver": "org.mariadb.jdbc.Driver",
133             "databaseUrl": "jdbc:mariadb://mariadb:3306/policyadmin",
134             "databaseUser": "policy_user",
135             "databasePassword": "policy_user",
136             "persistenceUnit": "PolicyMariaDb"
137         },
138     }
139
140 Next, navigate to the "/main" directory. You can then run the following command to start the policy api:
141
142 .. code-block:: bash
143
144     mvn exec:java -Dexec.mainClass=org.onap.policy.api.main.startstop.Main -Dexec.args=" -c ../packages/policy-api-tarball/src/main/resources/etc/defaultConfig.json"
145
146 2.3.4 Policy PAP
147 ^^^^^^^^^^^^^^^^
148
149 In the policy-pap repo, you should find the file 'main/src/test/resources/parameters/PapConfigParameters.json'. This file may need to be altered slightly as below:
150
151 .. code-block:: json
152
153     {
154         "name": "PapGroup",
155         "restServerParameters": {
156             "host": "0.0.0.0",
157             "port": 6968,
158             "userName": "healthcheck",
159             "password": "zb!XztG34",
160             "https": false
161         },
162         "pdpParameters": {
163             "heartBeatMs": 60000,
164             "updateParameters": {
165                 "maxRetryCount": 1,
166                 "maxWaitMs": 30000
167             },
168             "stateChangeParameters": {
169                 "maxRetryCount": 1,
170                 "maxWaitMs": 30000
171             }
172         },
173         "databaseProviderParameters": {
174             "name": "PolicyProviderParameterGroup",
175             "implementation": "org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl",
176             "databaseDriver": "org.mariadb.jdbc.Driver",
177             "databaseUrl": "jdbc:mariadb://localhost:3306/policyadmin",
178             "databaseUser": "policy_user",
179             "databasePassword": "policy_user",
180             "persistenceUnit": "PolicyMariaDb"
181         },
182         "topicParameterGroup": {
183             "topicSources" : [{
184                 "topic" : "POLICY-PDP-PAP",
185                 "servers" : [ "localhost:3904" ],
186                 "topicCommInfrastructure" : "dmaap"
187             }],
188             "topicSinks" : [{
189                 "topic" : "POLICY-PDP-PAP",
190                 "servers" : [ "localhost:3904" ],
191                 "topicCommInfrastructure" : "dmaap"
192             },{
193                 "topic" : "POLICY-NOTIFICATION",
194                 "servers" : [ "localhost:3904" ],
195                 "topicCommInfrastructure" : "dmaap"
196             }]
197         },
198         "healthCheckRestClientParameters":[{
199             "clientName": "api",
200             "hostname": "policy-api",
201             "port": 6968,
202             "userName": "healthcheck",
203             "password": "zb!XztG34",
204             "useHttps": false,
205             "basePath": "policy/api/v1/healthcheck"
206         },
207         {
208             "clientName": "distribution",
209             "hostname": "policy-distribution",
210             "port": 6970,
211             "userName": "healthcheck",
212             "password": "zb!XztG34",
213             "useHttps": false,
214             "basePath": "healthcheck"
215         }]
216     }
217
218 Next, navigate to the "/main" directory. You can then run the following command to start the policy pap
219
220 .. code-block:: bash
221
222     mvn -q -e clean compile exec:java -Dexec.mainClass="org.onap.policy.pap.main.startstop.Main" -Dexec.args="-c /src/test/resources/parameters/PapConfigParameters.json"
223
224 2.3.5 Controlloop Runtime
225 ^^^^^^^^^^^^^^^^^^^^^^^^^
226
227 To start the controlloop runtime we need to go the "runtime-controlloop" directory in the clamp repo. There is a config file that is used, by default, for the controlloop runtime. That config file is here: "src/main/resources/application.yaml". For development in your local environment, it shouldn't need any adjustment and we can just run the controlloop runtime with:
228
229 .. code-block:: bash
230
231     mvn spring-boot:run
232
233 2.3.6 Controlloop Policy Participant
234 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
235
236 To start the policy participant we need to go to the "participant-impl/participant-impl-policy" directory in the clamp repo. There is a config file under "src/main/resources/config/application.yaml". For development in your local environment, we will need to adjust this file slightly:
237
238 .. code-block:: yaml
239
240     server:
241         port: 8082
242
243     participant:
244       pdpGroup: defaultGroup
245       pdpType: apex
246       policyApiParameters:
247         clientName: api
248         hostname: localhost
249         port: 6970
250         userName: healthcheck
251         password: zb!XztG34
252         https: true
253         allowSelfSignedCerts: true
254       policyPapParameters:
255         clientName: pap
256         hostname: localhost
257         port: 6968
258         userName: healthcheck
259         password: zb!XztG34
260         https: true
261         allowSelfSignedCerts: true
262       intermediaryParameters:
263         reportingTimeIntervalMs: 120000
264         description: Participant Description
265         participantId:
266           name: org.onap.PM_Policy
267           version: 1.0.0
268         participantType:
269           name: org.onap.policy.controlloop.PolicyControlLoopParticipant
270           version: 2.3.1
271         clampControlLoopTopics:
272           topicSources:
273             -
274               topic: POLICY-CLRUNTIME-PARTICIPANT
275               servers:
276                 - ${topicServer:localhost}
277               topicCommInfrastructure: dmaap
278               fetchTimeout: 15000
279           topicSinks:
280             -
281               topic: POLICY-CLRUNTIME-PARTICIPANT
282               servers:
283                 - ${topicServer:localhost}
284               topicCommInfrastructure: dmaap
285
286 Navigate to the participant-impl/particpant-impl-policy/main directory. We can then run the policy-participant with the following command:
287
288 .. code-block:: bash
289
290     mvn spring-boot:run -Dspring-boot.run.arguments="--server.port=8082 --topicServer=localhost"
291
292 3. Testing Procedure
293 ====================
294
295 3.1 Testing Outline
296 ^^^^^^^^^^^^^^^^^^^
297
298 To perform the Smoke testing of the policy-participant we will be verifying the behaviours of the participant when the control loop changes state. The scenarios are:
299
300 - UNINITIALISED to PASSIVE: participant creates policies and policyTypes specified in the ToscaServiceTemplate using policy-api
301 - PASSIVE to RUNNING: participant deploys created policies specified in the ToscaServiceTemplate
302 - RUNNING to PASSIVE: participant undeploys policies which have been deployed
303 - PASSIVE to UNINITIALISED: participant deletes policies and policyTypes which has been created
304
305 3.2 Testing Steps
306 ^^^^^^^^^^^^^^^^^
307
308 Creation of Controlloop:
309 ************************
310
311 A Control Loop is created by commissioning a Tosca template with Control loop definitions and instantiating the Control Loop with the state "UNINITIALISED".
312 Using postman, commision a TOSCA template and instantiate using the following template:
313
314 :download:`Tosca Service Template <tosca/tosca_service_template_pptnt_smoke.yaml>`
315
316 :download:`Instantiate Controlloop <tosca/instantiation_pptnt_smoke.json>`
317
318 To verify this, we check that the Controlloop has been created and is in state UNINITIALISED.
319
320     .. image:: images/pol-part-controlloop-creation-ver.png
321
322 Creation of policies and policyTypes:
323 *************************************
324
325 The Controlloop STATE is changed from UNINITIALISED to PASSIVE using postman:
326
327 .. code-block:: json
328
329     {
330         "orderedState": "PASSIVE",
331         "controlLoopIdentifierList": [
332             {
333                 "name": "PMSHInstance0",
334                 "version": "1.0.1"
335             }
336         ]
337     }
338
339 This state change will trigger the creation of policies and policyTypes using the policy-api. To verify this we will check, using policy-api endpoints, that the "Sirisha" policyType, which is specified in the service template, has been created.
340
341     .. image:: images/pol-part-controlloop-sirisha-ver.png
342
343 We can also check that the pm-control policy has been created.
344
345     .. image:: images/pol-part-controlloop-pmcontrol-ver.png
346
347 Deployment of policies:
348 ***********************
349
350 The Controlloop STATE is changed from PASSIVE to RUNNING using postman:
351
352 .. code-block:: json
353
354     {
355         "orderedState": "RUNNING",
356         "controlLoopIdentifierList": [
357             {
358                 "name": "PMSHInstance0",
359                 "version": "1.0.1"
360             }
361         ]
362     }
363
364 This state change will trigger the deployment of the policies specified in the ToscaServiceTemplate. To verify this, we will check that the apex pmcontrol policy has been deployed to the defaultGroup. We check this using pap:
365
366     .. image:: images/pol-part-controlloop-pmcontrol-deploy-ver.png
367
368 Undeployment of policies:
369 *************************
370
371 The Controlloop STATE is changed from RUNNING to PASSIVE using postman:
372
373 .. code-block:: json
374
375     {
376         "orderedState": "PASSIVE",
377         "controlLoopIdentifierList": [
378             {
379                 "name": "PMSHInstance0",
380                 "version": "1.0.1"
381             }
382         ]
383     }
384
385 This state change will trigger the undeployment of the pmcontrol policy which was deployed previously. To verifiy this we do a PdpGroup Query as before and check that the pmcontrol policy has been undeployed and removed from the defaultGroup:
386
387     .. image:: images/pol-part-controlloop-pmcontrol-undep-ver.png
388
389 Deletion of policies and policyTypes:
390 *************************************
391
392 The Controlloop STATE is changed from PASSIVE to UNINITIALISED using postman:
393
394 .. code-block:: json
395
396     {
397         "orderedState": "UNINITIALISED",
398         "controlLoopIdentifierList": [
399             {
400                 "name": "PMSHInstance0",
401                 "version": "1.0.1"
402             }
403         ]
404     }
405
406 This state change will trigger the deletion of the previously created policies and policyTypes. To verify this, as before, we can check that the Sirisha policyType is not found this time and likewise for the pmcontrol policy:
407
408     .. image:: images/pol-part-controlloop-sirisha-nf.png
409
410     .. image:: images/pol-part-controlloop-pmcontrol-nf.png