Merge "Adding documentation for Prometheus metrics in Xacml-PDP."
[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-ACM 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 several 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 - clampacm: the runtime-clampacm 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 `clampacm`;
60     USE `clampacm`;
61     DROP USER 'policy';
62     CREATE USER 'policy';
63     GRANT ALL on clampacm.* 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 clampacm.* 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:: yaml
118
119     server:
120       port: 6969
121     spring:
122       security.user:
123         name: policyadmin
124         password: zb!XztG34
125       mvc.converters.preferred-json-mapper: gson
126       datasource:
127         url: jdbc:mariadb://mariadb:3306/policyadmin
128         driverClassName: org.mariadb.jdbc.Driver
129         username: policy_user
130         password: policy_user
131       jpa:
132         properties:
133           hibernate:
134             dialect: org.hibernate.dialect.MariaDB103Dialect
135         hibernate:
136           ddl-auto: none
137           naming:
138             physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
139             implicit-strategy: org.onap.policy.common.spring.utils.CustomImplicitNamingStrategy
140     policy-api:
141       name: ApiGroup
142       aaf: false
143     database:
144       name: PolicyProviderParameterGroup
145       implementation: org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl
146       driver: org.mariadb.jdbc.Driver
147       url: jdbc:mariadb://mariadb:3306/policyadmin
148       user: policy_user
149       password: policy_user
150       persistenceUnit: PolicyDb
151     policy-preload:
152       policyTypes:
153         - policytypes/onap.policies.monitoring.tcagen2.yaml
154         - policytypes/onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server.yaml
155         - policytypes/onap.policies.monitoring.dcae-restconfcollector.yaml
156         - policytypes/onap.policies.monitoring.dcae-pm-subscription-handler.yaml
157         - policytypes/onap.policies.monitoring.dcae-pm-mapper.yaml
158         - policytypes/onap.policies.Optimization.yaml
159         - policytypes/onap.policies.optimization.Resource.yaml
160         - policytypes/onap.policies.controlloop.operational.common.Drools.yaml
161       policies:
162         - policies/sdnc.policy.naming.input.tosca.yaml
163     management:
164       endpoints:
165         web:
166           base-path: /
167           exposure:
168             include: health,metrics,prometheus
169           path-mapping.prometheus: metrics
170
171 Next, navigate to the "/main" directory. You can then run the following command to start the policy api:
172
173 .. code-block:: bash
174
175     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"
176
177 2.3.4 Policy PAP
178 ^^^^^^^^^^^^^^^^
179
180 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:
181
182 .. code-block:: yaml
183
184     spring:
185       security:
186         user:
187           name: policyadmin
188           password: zb!XztG34
189       http:
190         converters:
191           preferred-json-mapper: gson
192       datasource:
193         url: jdbc:mariadb://mariadb:3306/policyadmin
194         driverClassName: org.mariadb.jdbc.Driver
195         username: policy_user
196         password: policy_user
197       jpa:
198         properties:
199           hibernate:
200             dialect: org.hibernate.dialect.MySQL5InnoDBDialect
201         hibernate:
202           ddl-auto: none
203           naming:
204             physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
205             implicit-strategy: org.onap.policy.pap.main.CustomImplicitNamingStrategy
206     server:
207       port: 6969
208     pap:
209       name: PapGroup
210       pdpParameters:
211         heartBeatMs: 120000
212         updateParameters:
213           maxRetryCount: 1
214
215 Next, navigate to the "/main" directory. You can then run the following command to start the policy pap
216
217 .. code-block:: bash
218
219     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"
220
221 2.3.5 ACM Runtime
222 ^^^^^^^^^^^^^^^^^^^^^^^^^
223
224 To start the clampacm runtime we need to go the "runtime-clampacm" directory in the clamp repo. There is a config file that is used, by default, for the clampacm 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 clampacm runtime with:
225
226 .. code-block:: bash
227
228     mvn spring-boot:run
229
230 2.3.6 ACM Policy Participant
231 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
232
233 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:
234
235 .. code-block:: yaml
236
237     server:
238         port: 8082
239
240     participant:
241       pdpGroup: defaultGroup
242       pdpType: apex
243       policyApiParameters:
244         clientName: api
245         hostname: localhost
246         port: 6970
247         userName: healthcheck
248         password: zb!XztG34
249         https: true
250         allowSelfSignedCerts: true
251       policyPapParameters:
252         clientName: pap
253         hostname: localhost
254         port: 6968
255         userName: healthcheck
256         password: zb!XztG34
257         https: true
258         allowSelfSignedCerts: true
259       intermediaryParameters:
260         reportingTimeIntervalMs: 120000
261         description: Participant Description
262         participantId:
263           name: org.onap.PM_Policy
264           version: 1.0.0
265         participantType:
266           name: org.onap.policy.clampacm.PolicyControlLoopParticipant
267           version: 2.3.1
268         clampControlLoopTopics:
269           topicSources:
270             -
271               topic: POLICY-CLRUNTIME-PARTICIPANT
272               servers:
273                 - ${topicServer:localhost}
274               topicCommInfrastructure: dmaap
275               fetchTimeout: 15000
276           topicSinks:
277             -
278               topic: POLICY-CLRUNTIME-PARTICIPANT
279               servers:
280                 - ${topicServer:localhost}
281               topicCommInfrastructure: dmaap
282
283 Navigate to the participant-impl/particpant-impl-policy/main directory. We can then run the policy-participant with the following command:
284
285 .. code-block:: bash
286
287     mvn spring-boot:run -Dspring-boot.run.arguments="--server.port=8082 --topicServer=localhost"
288
289 3. Testing Procedure
290 ====================
291
292 3.1 Testing Outline
293 ^^^^^^^^^^^^^^^^^^^
294
295 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:
296
297 - UNINITIALISED to PASSIVE: participant creates policies and policyTypes specified in the ToscaServiceTemplate using policy-api and deploys the policies using pap.
298 - PASSIVE to RUNNING: participant changes state to RUNNING. No operation performed.
299 - RUNNING to PASSIVE: participant changes state to PASSIVE. No operation performed.
300 - PASSIVE to UNINITIALISED: participant undeploys deployed policies and deletes policies and policyTypes which have been created.
301
302 3.2 Testing Steps
303 ^^^^^^^^^^^^^^^^^
304
305 Creation of ACM:
306 ************************
307
308 An ACM is created by commissioning a Tosca template with ACM definitions and instantiating the ACM with the state "UNINITIALISED".
309 Using postman, commission a TOSCA template and instantiate using the following template:
310
311 :download:`Tosca Service Template <tosca/tosca_service_template_pptnt_smoke.yaml>`
312
313 :download:`Instantiate ACM <tosca/instantiation_pptnt_smoke.json>`
314
315 To verify this, we check that the ACM has been created and is in state UNINITIALISED.
316
317     .. image:: images/pol-part-clampacm-creation-ver.png
318
319 Creation of policies and policyTypes:
320 *************************************
321
322 The ACM STATE is changed from UNINITIALISED to PASSIVE using postman:
323
324 .. code-block:: json
325
326     {
327         "orderedState": "PASSIVE",
328         "controlLoopIdentifierList": [
329             {
330                 "name": "PMSHInstance0",
331                 "version": "1.0.1"
332             }
333         ]
334     }
335
336 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 "Test Policy" policyType, which is specified in the service template, has been created.
337
338     .. image:: images/pol-part-clampacm-test-policy-ver.png
339
340 We can also check that the pm-control policy has been created.
341
342     .. image:: images/pol-part-clampacm-pmcontrol-ver.png
343
344 Deployment of policies:
345 ***********************
346
347 The ACM STATE is changed from UNINITIALISED to PASSIVE using postman:
348
349 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:
350
351     .. image:: images/pol-part-clampacm-pmcontrol-deploy-ver.png
352
353 Undeployment of policies:
354 *************************
355
356 The ACM STATE is changed from PASSIVE to UNINITIALISED using postman:
357
358 .. code-block:: json
359
360     {
361         "orderedState": "UNINITIALISED",
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 verify 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-clampacm-pmcontrol-undep-ver.png
373
374 Deletion of policies and policyTypes:
375 *************************************
376
377 The ACM STATE is changed from PASSIVE to UNINITIALISED using postman:
378
379 This state change will trigger the deletion of the previously created policies and policyTypes. To verify this, as before, we can check that the Test Policy policyType is not found this time and likewise for the pmcontrol policy:
380
381     .. image:: images/pol-part-clampacm-test-policy-nf.png
382
383     .. image:: images/pol-part-clampacm-pmcontrol-nf.png