1 .. This work is licensed under a
2 .. Creative Commons Attribution 4.0 International License.
3 .. http://creativecommons.org/licenses/by/4.0
5 .. _policy-development-tools-label:
7 Policy Platform Development Tools
8 #################################
14 This article explains how to build the ONAP Policy Framework for development purposes and how to run stability/
15 performance tests for a variety of components. To start, the developer should consult the latest ONAP Wiki to
16 familiarize themselves with developer best practices and how-tos to setup their environment,
17 see `https://wiki.onap.org/display/DW/Developer+Best+Practices`.
19 This article assumes that:
21 * You are using a *\*nix* operating system such as linux or macOS.
22 * You are using a directory called *git* off your home directory *(~/git)* for your git repositories
23 * Your local maven repository is in the location *~/.m2/repository*
24 * You have copied the settings.xml from oparent to *~/.m2/* directory
25 * You have added settings to access the ONAP Nexus to your M2 configuration,
26 see `Maven Settings Example <https://wiki.onap.org/display/DW/Setting+Up+Your+Development+Environment>`_
27 (bottom of the linked page)
29 The procedure documented in this article has been verified to work on a MacBook laptop running macOS Mojave Version
30 10.14.6 and an Ubuntu 18.06 VM.
32 Cloning All The Policy Repositories
33 ***********************************
35 Run a script such as the script below to clone the required modules from the
36 `ONAP git repository <https://gerrit.onap.org/r/admin/repos/q/filter:policy>`_.
37 This script clones all the ONAP Policy Framework repositories.
39 ONAP Policy Framework has dependencies to the ONAP Parent *oparent* module, the ONAP ECOMP SDK *ecompsdkos* module,
40 and the A&AI Schema module.
44 :caption: Typical ONAP Policy Framework Clone Script
49 ## script name for output
50 MOD_SCRIPT_NAME=`basename $0`
52 ## the ONAP clone directory, defaults to "onap"
55 ## the ONAP repos to clone
65 policy/drools-applications \
72 ## Help screen and exit condition (i.e. too few arguments)
77 echo "$MOD_SCRIPT_NAME - clones all required ONAP git repositories"
79 echo " Usage: $MOD_SCRIPT_NAME [-options]"
82 echo " -d - the ONAP clone directory, defaults to '.'"
83 echo " -h - this help screen"
94 #-d ONAP clone directory
98 echo "$MOD_SCRIPT_NAME: no clone directory"
105 #-h prints help and exists
109 *) echo "$MOD_SCRIPT_NAME: undefined CLI option - $1"; exit 255;;
113 if [ -f "$clone_dir" ]; then
114 echo "$MOD_SCRIPT_NAME: requested clone directory '$clone_dir' exists as file"
117 if [ -d "$clone_dir" ]; then
118 echo "$MOD_SCRIPT_NAME: requested clone directory '$clone_dir' exists as directory"
125 echo cannot clone ONAP repositories, could not create directory '"'$clone_dir'"'
129 for repo in $onap_repos
131 repoDir=`dirname "$repo"`
132 repoName=`basename "$repo"`
136 mkdir "$clone_dir/$repoDir"
139 echo cannot clone ONAP repositories, could not create directory '"'$clone_dir/repoDir'"'
144 git clone https://gerrit.onap.org/r/${repo} $clone_dir/$repo
147 echo ONAP has been cloned into '"'$clone_dir'"'
150 Execution of the script above results in the following directory hierarchy in your *~/git* directory:
154 * ~/git/onap/policy/parent
155 * ~/git/onap/policy/common
156 * ~/git/onap/policy/models
157 * ~/git/onap/policy/api
158 * ~/git/onap/policy/pap
159 * ~/git/onap/policy/gui
160 * ~/git/onap/policy/docker
161 * ~/git/onap/policy/drools-applications
162 * ~/git/onap/policy/drools-pdp
163 * ~/git/onap/policy/clamp
164 * ~/git/onap/policy/apex-pdp
165 * ~/git/onap/policy/xacml-pdp
166 * ~/git/onap/policy/distribution
169 Building ONAP Policy Framework Components
170 *****************************************
172 **Step 1:** Optionally, for a completely clean build, remove the ONAP built modules from your local repository.
176 rm -fr ~/.m2/repository/org/onap
179 **Step 2:** A pom such as the one below can be used to build the ONAP Policy Framework modules. Create the *pom.xml*
180 file in the directory *~/git/onap/policy*.
183 :caption: Typical pom.xml to build the ONAP Policy Framework
186 <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">
187 <modelVersion>4.0.0</modelVersion>
188 <groupId>org.onap</groupId>
189 <artifactId>onap-policy</artifactId>
190 <version>1.0.0-SNAPSHOT</version>
191 <packaging>pom</packaging>
192 <name>${project.artifactId}</name>
193 <inceptionYear>2017</inceptionYear>
199 <module>parent</module>
200 <module>common</module>
201 <module>models</module>
204 <module>apex-pdp</module>
205 <module>xacml-pdp</module>
206 <module>drools-pdp</module>
207 <module>drools-applications</module>
208 <module>distribution</module>
210 <module>clamp</module>
214 **Policy Architecture/API Transition**
216 In Dublin, a new Policy Architecture was introduced. The legacy architecture runs in parallel with the new
217 architecture. It will be deprecated after Frankfurt release. If the developer is only interested in working with the
218 new architecture components, the engine sub-module can be ommitted.
221 **Step 3:** You can now build the Policy framework.
235 mvn clean install -P docker
237 Developing and Debugging each Policy Component
238 **********************************************
240 Running a MariaDb Instance
241 ++++++++++++++++++++++++++
243 The Policy Framework requires a MariaDb instance running. The easiest way to do this is to run a docker image locally.
245 One example on how to do this is to use the scripts used by the policy/api S3P tests.
247 `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>`_
251 cd ~/git/onap/api/testsuites/stability/src/main/resources/simulatorsetup
252 ./setup_components.sh
254 Another example on how to run the MariaDb is using the docker compose file used by the Policy API CSITs:
256 `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>`_
258 Running the API component standalone
259 ++++++++++++++++++++++++++++++++++++
261 Assuming you have successfully built the codebase using the instructions above. The only requirement for the API
262 component to run is a running MariaDb database instance. The easiest way to do this is to run the docker image, please
263 see the mariadb documentation for the latest information on doing so. Once the mariadb is up and running, a
264 configuration file must be provided to the api in order for it to know how to connect to the mariadb. You can locate
265 the default configuration file in the packaging of the api component:
267 `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>`_
269 You will want to change the fields pertaining to "host", "port" and "databaseUrl" to your local environment settings
270 and start the policy-api springboot application either using your IDE of choice or using the run goal from Spring Boot
271 Maven plugin: *mvn spring-boot:run*.
273 Running the API component using Docker Compose
274 ++++++++++++++++++++++++++++++++++++++++++++++
276 An example of running the api using a docker compose script is located in the Policy Integration CSIT test repository.
278 `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>`_
280 Running the PAP component standalone
281 ++++++++++++++++++++++++++++++++++++
283 Once you have successfully built the PAP codebase, a running MariaDb database and DMaaP instance will also be required
284 to start up the application. For MariaDb instance, the easiest way is to run the docker image, please see the mariadb
285 documentation for the latest information on doing so. For DMaaP, the easiest way during development is to run the DMaaP
286 simulator which is explained in the below sections. Once the mariadb and DMaaP are running, a configuration file must
287 be provided to the PAP component in order for it to know how to connect to the mariadb and DMaaP along with other
288 relevant configuration details. You can locate the default configuration file in the packaging of the PAP component:
290 `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>`_
292 Update the fields related to MariaDB, DMaaP and the RestServer for the application as per your local environment settings.
293 Then to start the application, just run the Spring Boot application using IDE or command line.
296 Running the Smoke Tests
297 ***********************
299 The following links contain instructions on how to run the smoke tests. These may be helpful to developers to become
300 familiar with the Policy Framework components and test any local changes.
305 smoke/policy-gui-acm-smoke.rst
306 smoke/db-migrator-smoke.rst
307 smoke/acm-participants-smoke.rst
308 smoke/clamp-smoke.rst
309 smoke/clamp-ac-participant-protocol-smoke.rst
310 smoke/policy-participant-smoke.rst
314 smoke/drools-smoke.rst
315 smoke/xacml-smoke.rst
316 smoke/distribution-smoke.rst
319 Running the Stability/Performance Tests
320 ***************************************
322 The following links contain instructions on how to run the S3P Stability and Performance tests. These may be helpful to developers to become
323 familiar with the Policy Framework components and test any local changes.
328 testing/s3p/run-s3p.rst
329 testing/s3p/api-s3p.rst
330 testing/s3p/pap-s3p.rst
331 testing/s3p/apex-s3p.rst
332 testing/s3p/drools-s3p.rst
333 testing/s3p/xacml-s3p.rst
334 testing/s3p/distribution-s3p.rst
335 testing/s3p/clamp-s3p.rst
338 Running the Pairwise Tests
339 **************************
341 The following links contain instructions on how to run the pairwise tests. These may be helpful to developers check that
342 the Policy Framework works in a full ONAP deployment.
371 distribution-pairwise.rst
374 Testing OpenSuse docker images
375 ******************************
377 Policy Framework offers docker images in two flavors: Alpine and OpenSuse.
378 Alpine images are used in OOM for ONAP deployments.
379 The OpenSuse images are built manually if needed, by running Maven with the -Pdockersuse profile.
380 To test these images, CSITs will be run.
382 1. Build the OpenSuse image you want by running Maven with -Pdockersuse:
387 mvn clean install -Pdockersuse
389 The image onap/policy-apex-pdp:latest will be produced.
391 2. To avoid ambiguity, tag the image as opensuse:
395 docker tag onap/policy-apex-pdp:latest onap/policy-apex-pdp:opensuse
397 3. Clone policy/docker repo.
399 4. Modify docker/csit/docker-compose.yml to use the tagged OpenSuse image.
406 image: nexus3.onap.org:10001/onap/policy-apex-pdp:${POLICY_APEX_PDP_VERSION}
413 image: onap/policy-apex-pdp:opensuse
415 5. Run the project CSIT. For apex-pdp:
420 ./run-project-csit.sh apex-pdp
422 Automated tests will be run, and log files displayed.
424 Running Policy Components Locally
425 *********************************
427 The following page outlines how to run the policy framework components locally use IntelliJ, Eclipse and the Command Line.
432 local-installation.rst
435 Generating Swagger Documentation
436 ********************************
438 1. Accessing Swagger documentation for springboot based policy applications
439 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
441 Springfox Swagger2 maven dependency aids with auto-generation of Swagger documentation.
443 Using the Swagger-UI maven dependency Swagger HTML documentation can be accessed at the root url.
445 - The generated swagger.json can be accessed at: *https://service_IP:service_port/v2/api-docs*
446 - Swagger UI can be accessed at: *https://service_IP:service_port/swagger-ui/index.html*
448 Running the DMaaP Simulator during Development
449 **********************************************
450 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.
452 Running on the Command Line
453 +++++++++++++++++++++++++++
454 1. Check out the policy models repository
455 2. Go to the *models-sim/policy-models-simulators* subdirectory in the policy-models repo
456 3. Run the following Maven command:
460 mvn exec:java -Dexec.mainClass=org.onap.policy.models.simulators.Main -Dexec.args="src/test/resources/simParameters.json"
464 1. Check out the policy models repository
465 2. Go to the *models-sim/policy-models-simulators* module in the policy-models repo
466 3. Specify a run configuration using the class *org.onap.policy.models.simulators.Main* as the main class
467 4. Specify an argument of *src/test/resources/simParameters.json* to the run configuration
468 5. Run the configuration
470 Specifying a local configuration file
471 +++++++++++++++++++++++++++++++++++++
473 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:
479 "name": "DMaaP simulator",
484 "name": "DMaaP simulator",
485 "providerClass": "org.onap.policy.models.sim.dmaap.rest.DmaapSimRestControllerV1",
493 Bringing up Strimzi-Kafka Deploment with Policy Framework
494 *********************************************************
496 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.
498 This is meant for a development purpose only as we are going to use microk8s in this page