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