Update S3P documentation
[policy/parent.git] / docs / development / devtools / devtools.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 .. _policy-development-tools-label:
6
7 Policy Platform Development Tools
8 #################################
9
10 .. contents::
11     :depth: 3
12
13
14 This article explains how to build the ONAP Policy Framework for development purposes and how to run stability/performance tests for a variety of components. To start, the developer should consult the latest ONAP Wiki to familiarize themselves with developer best practices and how-tos to setup their environment, see `https://wiki.onap.org/display/DW/Developer+Best+Practices`.
15
16 This article assumes that:
17
18 * You are using a *\*nix* operating system such as linux or macOS.
19 * You are using a directory called *git* off your home directory *(~/git)* for your git repositories
20 * Your local maven repository is in the location *~/.m2/repository*
21 * You have copied the settings.xml from oparent to *~/.m2/* directory
22 * You have added settings to access the ONAP Nexus to your M2 configuration, see `Maven Settings Example <https://wiki.onap.org/display/DW/Setting+Up+Your+Development+Environment>`_ (bottom of the linked page)
23
24 The procedure documented in this article has been verified to work on a MacBook laptop running macOS Mojave Version 10.14.6 and an Ubuntu 18.06 VM.
25
26 Cloning All The Policy Repositories
27 ***********************************
28
29 Run a script such as the script below to clone the required modules from the `ONAP git repository <https://gerrit.onap.org/r/admin/repos/q/filter:policy>`_. This script clones all the ONAP Policy Framework repositories.
30
31 ONAP Policy Framework has dependencies to the ONAP Parent *oparent* module, the ONAP ECOMP SDK *ecompsdkos* module, and the A&AI Schema module.
32
33
34 .. code-block:: bash
35    :caption: Typical ONAP Policy Framework Clone Script
36    :linenos:
37
38     #!/usr/bin/env bash
39
40     ## script name for output
41     MOD_SCRIPT_NAME=`basename $0`
42
43     ## the ONAP clone directory, defaults to "onap"
44     clone_dir="onap"
45
46     ## the ONAP repos to clone
47     onap_repos="\
48     policy/parent \
49     policy/common \
50     policy/models \
51     policy/docker \
52     policy/api \
53     policy/pap \
54     policy/apex-pdp \
55     policy/drools-pdp \
56     policy/drools-applications \
57     policy/xacml-pdp \
58     policy/distribution \
59     policy/gui \
60     policy/clamp "
61
62     ##
63     ## Help screen and exit condition (i.e. too few arguments)
64     ##
65     Help()
66     {
67         echo ""
68         echo "$MOD_SCRIPT_NAME - clones all required ONAP git repositories"
69         echo ""
70         echo "       Usage:  $MOD_SCRIPT_NAME [-options]"
71         echo ""
72         echo "       Options"
73         echo "         -d          - the ONAP clone directory, defaults to '.'"
74         echo "         -h          - this help screen"
75         echo ""
76         exit 255;
77     }
78
79     ##
80     ## read command line
81     ##
82     while [ $# -gt 0 ]
83     do
84         case $1 in
85             #-d ONAP clone directory
86             -d)
87                 shift
88                 if [ -z "$1" ]; then
89                     echo "$MOD_SCRIPT_NAME: no clone directory"
90                     exit 1
91                 fi
92                 clone_dir=$1
93                 shift
94             ;;
95
96             #-h prints help and exists
97             -h)
98                 Help;exit 0;;
99
100             *)    echo "$MOD_SCRIPT_NAME: undefined CLI option - $1"; exit 255;;
101         esac
102     done
103
104     if [ -f "$clone_dir" ]; then
105         echo "$MOD_SCRIPT_NAME: requested clone directory '$clone_dir' exists as file"
106         exit 2
107     fi
108     if [ -d "$clone_dir" ]; then
109         echo "$MOD_SCRIPT_NAME: requested clone directory '$clone_dir' exists as directory"
110         exit 2
111     fi
112
113     mkdir $clone_dir
114     if [ $? != 0 ]
115     then
116         echo cannot clone ONAP repositories, could not create directory '"'$clone_dir'"'
117         exit 3
118     fi
119
120     for repo in $onap_repos
121     do
122         repoDir=`dirname "$repo"`
123         repoName=`basename "$repo"`
124
125         if [ ! -z $dirName ]
126         then
127             mkdir "$clone_dir/$repoDir"
128             if [ $? != 0 ]
129             then
130                 echo cannot clone ONAP repositories, could not create directory '"'$clone_dir/repoDir'"'
131                 exit 4
132             fi
133         fi
134
135         git clone https://gerrit.onap.org/r/${repo} $clone_dir/$repo
136     done
137
138     echo ONAP has been cloned into '"'$clone_dir'"'
139
140
141 Execution of the script above results in the following directory hierarchy in your *~/git* directory:
142
143     *  ~/git/onap
144     *  ~/git/onap/policy
145     *  ~/git/onap/policy/parent
146     *  ~/git/onap/policy/common
147     *  ~/git/onap/policy/models
148     *  ~/git/onap/policy/api
149     *  ~/git/onap/policy/pap
150     *  ~/git/onap/policy/gui
151     *  ~/git/onap/policy/docker
152     *  ~/git/onap/policy/drools-applications
153     *  ~/git/onap/policy/drools-pdp
154     *  ~/git/onap/policy/clamp
155     *  ~/git/onap/policy/apex-pdp
156     *  ~/git/onap/policy/xacml-pdp
157     *  ~/git/onap/policy/distribution
158
159
160 Building ONAP Policy Framework Components
161 *****************************************
162
163 **Step 1:** Optionally, for a completely clean build, remove the ONAP built modules from your local repository.
164
165     .. code-block:: bash
166
167         rm -fr ~/.m2/repository/org/onap
168
169
170 **Step 2:**  A pom such as the one below can be used to build the ONAP Policy Framework modules. Create the *pom.xml* file in the directory *~/git/onap/policy*.
171
172 .. code-block:: xml
173    :caption: Typical pom.xml to build the ONAP Policy Framework
174    :linenos:
175
176     <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
177         <modelVersion>4.0.0</modelVersion>
178         <groupId>org.onap</groupId>
179         <artifactId>onap-policy</artifactId>
180         <version>1.0.0-SNAPSHOT</version>
181         <packaging>pom</packaging>
182         <name>${project.artifactId}</name>
183         <inceptionYear>2017</inceptionYear>
184         <organization>
185             <name>ONAP</name>
186         </organization>
187
188         <modules>
189             <module>parent</module>
190             <module>common</module>
191             <module>models</module>
192             <module>api</module>
193             <module>pap</module>
194             <module>apex-pdp</module>
195             <module>xacml-pdp</module>
196             <module>drools-pdp</module>
197             <module>drools-applications</module>
198             <module>distribution</module>
199             <module>gui</module>
200             <module>clamp</module>
201         </modules>
202     </project>
203
204 **Policy Architecture/API Transition**
205
206 In Dublin, a new Policy Architecture was introduced. The legacy architecture runs in parallel with the new architecture. It will be deprecated after Frankfurt release.
207 If the developer is only interested in working with the new architecture components, the engine sub-module can be ommitted.
208
209
210 **Step 3:** You can now build the Policy framework.
211
212 Java artifacts only:
213
214     .. code-block:: bash
215
216        cd ~/git/onap
217        mvn clean install
218
219 With docker images:
220
221     .. code-block:: bash
222
223        cd ~/git/onap
224        mvn clean install -P docker
225
226 Developing and Debugging each Policy Component
227 **********************************************
228
229 Running a MariaDb Instance
230 ++++++++++++++++++++++++++
231
232 The Policy Framework requires a MariaDb instance running. The easiest way to do this is to run a docker image locally.
233
234 One example on how to do this is to use the scripts used by the policy/api S3P tests.
235
236 `Simulator Setup Script Example <https://gerrit.onap.org/r/gitweb?p=policy/api.git;a=tree;f=testsuites/stability/src/main/resources/simulatorsetup;h=9038413f67cff2e2a79d6345f198f96ee0c57de1;hb=refs/heads/master>`_
237
238     .. code-block:: bash
239
240        cd ~/git/onap/api/testsuites/stability/src/main/resources/simulatorsetup
241        ./setup_components.sh
242
243 Another example on how to run the MariaDb is using the docker compose file used by the Policy API CSITs:
244
245 `Example Compose Script to run MariaDB <https://gerrit.onap.org/r/gitweb?p=integration/csit.git;a=blob;f=scripts/policy/docker-compose-api.yml;h=e32190f1e6cb6d9b64ddf53a2db2c746723a0c6a;hb=refs/heads/master>`_
246
247 Running the API component standalone
248 ++++++++++++++++++++++++++++++++++++
249
250 Assuming you have successfully built the codebase using the instructions above. The only requirement for the API component to run is a
251 running MariaDb database instance. The easiest way to do this is to run the docker image, please see the mariadb documentation for the latest
252 information on doing so. Once the mariadb is up and running, a configuration file must be provided to the api in order for it to know how to
253 connect to the mariadb. You can locate the default configuration file in the packaging of the api component:
254
255 `Default Policy API Configuration <https://gerrit.onap.org/r/gitweb?p=policy/api.git;a=blob;f=packages/policy-api-tarball/src/main/resources/etc/apiParameters.yaml;h=2c19199a8a889cb0ab203334182662fe15e1635e;hb=refs/heads/master>`_
256
257 You will want to change the fields pertaining to "host", "port" and "databaseUrl" to your local environment settings and start the
258 policy-api springboot application either using your IDE of choice or using the run goal from Spring Boot Maven plugin: *mvn spring-boot:run*.
259
260 Running the API component using Docker Compose
261 ++++++++++++++++++++++++++++++++++++++++++++++
262
263 An example of running the api using a docker compose script is located in the Policy Integration CSIT test repository.
264
265 `Policy CSIT API Docker Compose <https://gerrit.onap.org/r/gitweb?p=integration/csit.git;a=blob;f=scripts/policy/docker-compose-api.yml;h=e32190f1e6cb6d9b64ddf53a2db2c746723a0c6a;hb=refs/heads/master>`_
266
267 Running the PAP component standalone
268 ++++++++++++++++++++++++++++++++++++
269
270 Once you have successfully built the PAP codebase, a running MariaDb database and DMaaP instance will also be required to start up the application.
271 For MariaDb instance, the easiest way is to run the docker image, please see the mariadb documentation for the latest
272 information on doing so. For DMaaP, the easiest way during development is to run the DMaaP simulator which is explained in the below sections.
273 Once the mariadb and DMaaP are running, a configuration file must be provided to the PAP component in order for it to know how to
274 connect to the mariadb and DMaaP along with other relevant configuration details. You can locate the default configuration file in the packaging of the PAP component:
275
276 `Default PAP Configuration <https://gerrit.onap.org/r/gitweb?p=policy/pap.git;a=blob;f=packages/policy-pap-tarball/src/main/resources/etc/papParameters.yaml;h=06dd45f4946fd0a11ed8ef859f8fc5bcf409a3f0;hb=HEAD>`_
277
278 Update the fields related to MariaDB, DMaaP and the RestServer for the application as per your local environment settings.
279 Then to start the application, just run the Spring Boot application using IDE or command line.
280
281 Running the Smoke Tests
282 ***********************
283
284 The following links contain instructions on how to run the smoke tests. These may be helpful to developers to become
285 familiar with the Policy Framework components and test any local changes.
286
287 .. toctree::
288    :maxdepth: 1
289
290    policy-gui-acm-smoke.rst
291    db-migrator-smoke.rst
292    acm-participants-smoke.rst
293    clamp-smoke.rst
294    clamp-cl-participant-protocol-smoke.rst
295    policy-participant-smoke.rst
296    api-smoke.rst
297    pap-smoke.rst
298    apex-smoke.rst
299    drools-smoke.rst
300    xacml-smoke.rst
301    distribution-smoke.rst
302
303
304 Running the Stability/Performance Tests
305 ***************************************
306
307 The following links contain instructions on how to run the S3P Stability and Performance tests. These may be helpful to developers to become
308 familiar with the Policy Framework components and test any local changes.
309
310 .. toctree::
311    :maxdepth: 1
312
313    run-s3p.rst
314    api-s3p.rst
315    pap-s3p.rst
316    apex-s3p.rst
317    drools-s3p.rst
318    xacml-s3p.rst
319    distribution-s3p.rst
320    clamp-s3p.rst
321
322 Running the Pairwise Tests
323 **************************
324
325 The following links contain instructions on how to run the pairwise tests. These may be helpful to developers check that
326 the Policy Framework works in a full ONAP deployment.
327
328 .. toctree::
329    :maxdepth: 1
330
331    clamp-policy.rst
332
333    clamp-dcae.rst
334
335    policy-cds.rst
336
337    clamp-sdc.rst
338
339 ..
340    api-pairwise.rst
341
342 ..
343    pap-pairwise.rst
344
345 ..
346    apex-pairwise.rst
347
348 ..
349    drools-pairwise.rst
350
351 ..
352    xacml-pairwise.rst
353
354 ..
355    distribution-pairwise.rst
356
357
358 Testing OpenSuse docker images
359 ******************************
360
361 Policy Framework offers docker images in two flavors: Alpine and OpenSuse.
362 Alpine images are used in OOM for ONAP deployments.
363 The OpenSuse images are built manually if needed, by running Maven with the -Pdockersuse profile.
364 To test these images, CSITs will be run.
365
366 1. Build the OpenSuse image you want by running Maven with -Pdockersuse:
367
368     .. code-block:: bash
369
370         cd policy/apex-pdp
371         mvn clean install -Pdockersuse
372
373     The image onap/policy-apex-pdp:latest will be produced.
374
375 2. To avoid ambiguity, tag the image as opensuse:
376
377     .. code-block:: bash
378
379         docker tag onap/policy-apex-pdp:latest onap/policy-apex-pdp:opensuse
380
381 3. Clone policy/docker repo.
382
383 4. Modify docker/csit/docker-compose-all.yml to use the tagged OpenSuse image.
384
385     Replace:
386
387     .. code-block:: yaml
388
389         apex-pdp:
390           image: nexus3.onap.org:10001/onap/policy-apex-pdp:${POLICY_APEX_PDP_VERSION}
391
392     with:
393
394     .. code-block:: yaml
395
396         apex-pdp:
397           image: onap/policy-apex-pdp:opensuse
398
399 5. Run the project CSIT. For apex-pdp:
400
401     .. code-block:: bash
402
403         cd docker/csit
404         ./run-project-csit.sh apex-pdp
405
406     Automated tests will be run, and log files displayed.
407
408
409 Generating Swagger Documentation
410 ********************************
411
412 1. Accessing Swagger documentation for springboot based policy applications
413 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
414
415 Springfox Swagger2 maven dependency aids with auto-generation of Swagger documentation.
416
417 Using the Swagger-UI maven dependency Swagger HTML documentation can be accessed at the root url.
418
419 - The generated swagger.json can be accessed at: *https://service_IP:service_port/v2/api-docs*
420 - Swagger UI can be accessed at: *https://service_IP:service_port/swagger-ui/index.html*
421
422 Running the DMaaP Simulator during Development
423 **********************************************
424 It is sometimes convenient to run the DMaaP simulator during development. You can run it from the command line using Maven or from within your IDE.
425
426 Running on the Command Line
427 +++++++++++++++++++++++++++
428 1. Check out the policy models repository
429 2. Go to the *models-sim/policy-models-simulators* subdirectory in the policy-models repo
430 3. Run the following Maven command:
431
432    .. code-block:: bash
433
434       mvn exec:java  -Dexec.mainClass=org.onap.policy.models.simulators.Main -Dexec.args="src/test/resources/simParameters.json"
435
436 Running in Eclipse
437 ++++++++++++++++++
438 1. Check out the policy models repository
439 2. Go to the *models-sim/policy-models-simulators* module in the policy-models repo
440 3. Specify a run configuration using the class *org.onap.policy.models.simulators.Main* as the main class
441 4. Specify an argument of *src/test/resources/simParameters.json* to the run configuration
442 5. Run the configuration
443
444 Specifying a local configuration file
445 +++++++++++++++++++++++++++++++++++++
446
447 You may specify a local configuration file instead of *src/test/resources/simParameters.json* on the command line or as an argument in the run configuration in eclipse:
448
449 .. code-block:: json
450
451    {
452      "dmaapProvider": {
453        "name": "DMaaP simulator",
454        "topicSweepSec": 900
455      },
456      "restServers": [
457        {
458          "name": "DMaaP simulator",
459          "providerClass": "org.onap.policy.models.sim.dmaap.rest.DmaapSimRestControllerV1",
460          "host": "localhost",
461          "port": 3904,
462          "https": false
463        }
464      ]
465    }
466
467 Bringing up Strimzi-Kafka Deploment with Policy Framework
468 *********************************************************
469
470 This page will explain how to setup a local Kubernetes cluster and minimal helm setup to run and deploy Policy Framework on a single host.
471
472 This is meant for a development purpose only as we are going to use microk8s in this page
473
474 .. toctree::
475    :maxdepth: 1
476
477    strimzi-policy.rst