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/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`.
17 This article assumes that:
19 * You are using a *\*nix* operating system such as linux or macOS.
20 * You are using a directory called *git* off your home directory *(~/git)* for your git repositories
21 * Your local maven repository is in the location *~/.m2/repository*
22 * You have copied the settings.xml from oparent to *~/.m2/* directory
23 * 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)
25 The procedure documented in this article has been verified to work on a MacBook laptop running macOS Mojave Version 10.14.6 and an Unbuntu 18.06 VM.
27 Cloning All The Policy Repositories
28 ***********************************
30 Run a script such as the script below to clone the required modules from the `ONAP git repository <https://gerrit.onap.org/r/#/admin/projects/?filter=policy>`_. This script clones all the ONAP Policy Framework repositories.
32 ONAP Policy Framework has dependencies to the ONAP Parent *oparent* module, the ONAP ECOMP SDK *ecompsdkos* module, and the A&AI Schema module.
36 :caption: Typical ONAP Policy Framework Clone Script
41 ## script name for output
42 MOD_SCRIPT_NAME=`basename $0`
44 ## the ONAP clone directory, defaults to "onap"
47 ## the ONAP repos to clone
57 policy/drools-applications \
64 ## Help screen and exit condition (i.e. too few arguments)
69 echo "$MOD_SCRIPT_NAME - clones all required ONAP git repositories"
71 echo " Usage: $MOD_SCRIPT_NAME [-options]"
74 echo " -d - the ONAP clone directory, defaults to '.'"
75 echo " -h - this help screen"
86 #-d ONAP clone directory
90 echo "$MOD_SCRIPT_NAME: no clone directory"
97 #-h prints help and exists
101 *) echo "$MOD_SCRIPT_NAME: undefined CLI option - $1"; exit 255;;
105 if [ -f "$clone_dir" ]; then
106 echo "$MOD_SCRIPT_NAME: requested clone directory '$clone_dir' exists as file"
109 if [ -d "$clone_dir" ]; then
110 echo "$MOD_SCRIPT_NAME: requested clone directory '$clone_dir' exists as directory"
117 echo cannot clone ONAP repositories, could not create directory '"'$clone_dir'"'
121 for repo in $onap_repos
123 repoDir=`dirname "$repo"`
124 repoName=`basename "$repo"`
128 mkdir "$clone_dir/$repoDir"
131 echo cannot clone ONAP repositories, could not create directory '"'$clone_dir/repoDir'"'
136 git clone https://gerrit.onap.org/r/${repo} $clone_dir/$repo
139 echo ONAP has been cloned into '"'$clone_dir'"'
142 Execution of the script above results in the following directory hierarchy in your *~/git* directory:
146 * ~/git/onap/policy/parent
147 * ~/git/onap/policy/common
148 * ~/git/onap/policy/models
149 * ~/git/onap/policy/api
150 * ~/git/onap/policy/pap
151 * ~/git/onap/policy/gui
152 * ~/git/onap/policy/docker
153 * ~/git/onap/policy/drools-applications
154 * ~/git/onap/policy/drools-pdp
155 * ~/git/onap/policy/clamp
156 * ~/git/onap/policy/apex-pdp
157 * ~/git/onap/policy/xacml-pdp
158 * ~/git/onap/policy/distribution
161 Building ONAP Policy Framework Components
162 *****************************************
164 **Step 1:** Optionally, for a completely clean build, remove the ONAP built modules from your local repository.
168 rm -fr ~/.m2/repository/org/onap
171 **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*.
174 :caption: Typical pom.xml to build the ONAP Policy Framework
177 <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">
178 <modelVersion>4.0.0</modelVersion>
179 <groupId>org.onap</groupId>
180 <artifactId>onap-policy</artifactId>
181 <version>1.0.0-SNAPSHOT</version>
182 <packaging>pom</packaging>
183 <name>${project.artifactId}</name>
184 <inceptionYear>2017</inceptionYear>
190 <module>parent</module>
191 <module>common</module>
192 <module>models</module>
195 <module>apex-pdp</module>
196 <module>xacml-pdp</module>
197 <module>drools-pdp</module>
198 <module>drools-applications</module>
199 <module>distribution</module>
201 <module>clamp</module>
205 **Policy Architecture/API Transition**
207 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.
208 If the developer is only interested in working with the new architecture components, the engine sub-module can be ommitted.
211 **Step 3:** You can now build the Policy framework.
225 mvn clean install -P docker
227 Developing and Debugging each Policy Component
228 **********************************************
230 Running a MariaDb Instance
231 ++++++++++++++++++++++++++
233 The Policy Framework requires a MariaDb instance running. The easiest way to do this is to run a docker image locally.
235 One example on how to do this is to use the scripts used by the policy/api S3P tests.
237 `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>`_
241 cd ~/git/onap/api/testsuites/stability/src/main/resources/simulatorsetup
242 ./setup_components.sh
244 Another example on how to run the MariaDb is using the docker compose file used by the Policy API CSITs:
246 `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>`_
248 Running the API component standalone
249 +++++++++++++++++++++++++++++++++++++
251 Assuming you have successfully built the codebase using the instructions above. The only requirement for the API component to run is a
252 running MariaDb database instance. The easiest way to do this is to run the docker image, please see the mariadb documentation for the latest
253 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
254 connect to the mariadb. You can locate the default configuration file in the packaging of the api component:
256 `Default API Configuration <https://gerrit.onap.org/r/gitweb?p=policy/api.git;a=blob;f=packages/policy-api-tarball/src/main/resources/etc/defaultConfig.json;h=042fb9d54c79ce4dad517e2564636632a8ecc550;hb=refs/heads/master>`_
258 You will want to change the fields pertaining to "host", "port" and "databaseUrl" to your local environment settings.
260 Running the API component using Docker Compose
261 ++++++++++++++++++++++++++++++++++++++++++++++
263 An example of running the api using a docker compose script is located in the Policy Integration CSIT test repository.
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>`_
267 Running the Smoke Tests
268 ***********************
270 The following links contain instructions on how to run the smoke tests. These may be helpful to developers to become
271 familiar with the Policy Framework components and test any local changes.
276 policy-gui-controlloop-smoke.rst
277 db-migrator-smoke.rst
278 cl-participants-smoke.rst
280 clamp-cl-participant-protocol-smoke.rst
281 policy-participant-smoke.rst
299 distribution-smoke.rst
302 Running the Stability/Performance Tests
303 ***************************************
305 The following links contain instructions on how to run the S3P Stability and Performance tests. These may be helpful to developers to become
306 familiar with the Policy Framework components and test any local changes.
319 Running the Pairwise Tests
320 **************************
322 The following links contain instructions on how to run the pairwise tests. These may be helpful to developers check that
323 the Policy Framework works in a full ONAP deployment.
348 distribution-pairwise.rst
351 Generating Swagger Documentation
352 ********************************
353 The `Policy Parent Integration POM <https://github.com/onap/policy-parent/blob/master/integration/pom.xml>`_ contains a *generateSwaggerDocs* profile. This
354 profile can be activated on any module that has a Swagger endopint. When active, this profile creates a tarball in Nexus with the name
355 *<project-artifactId>-swagger-docs.tar.gz*. The tarball contains the fillowing files:
363 The profile is activated when:
365 1. The following property is defined at the top of the *pom.xml* file for a module
369 <!-- This property triggers generation of the Swagger documents -->
370 <swagger.generation.phase>post-integration-test</swagger.generation.phase>
372 See the `CLAMP runtime POM <https://github.com/onap/policy-clamp/blob/master/runtime/pom.xml>`_ for an example of the usage of this property.
374 2. Unit tests are being executed in the build, in other wirds when the *skipTests* flag is *false*.
376 You **must** create a unit test in your module that generates the following file:
380 src/test/resources/swagger/swagger.json
382 Typically, you do this by starting your REST endpoint in a unit test, issuing a REST call to get the Swagger API documentation. The test case below is an example
388 public void testSwaggerJson() throws Exception {
389 ResponseEntity<String> httpsEntity = getRestTemplate()
390 .getForEntity("https://localhost:" + this.httpsPort + "/restservices/clds/api-doc", String.class);
391 assertThat(httpsEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
392 assertThat(httpsEntity.getBody()).contains("swagger");
393 FileUtils.writeStringToFile(new File("target/swagger/swagger.json"), httpsEntity.getBody(),
394 Charset.defaultCharset());
397 See `this unit test case <https://github.com/onap/policy-clamp/blob/master/runtime/src/test/java/org/onap/policy/clamp/clds/it/HttpsItCase.java>`_
398 for the full example.
400 Running the DMaaP Simulator during Development
401 **********************************************
402 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.
404 Running on the Command Line
405 +++++++++++++++++++++++++++
406 1. Check out the policy models repository
407 2. Go to the *models-sim/policy-models-simulators* subdirectory in the policy-models repo
408 3. Run the following Maven command:
412 mvn exec:java -Dexec.mainClass=org.onap.policy.models.simulators.Main -Dexec.args="src/test/resources/simParameters.json"
416 1. Check out the policy models repository
417 2. Go to the *models-sim/policy-models-simulators* module in the policy-models repo
418 3. Specify a run configuration using the class *org.onap.policy.models.simulators.Main* as the main class
419 4. Specify an argument of *src/test/resources/simParameters.json* to the run configuration
420 5. Run the configuration
422 Specifying a local configuration file
423 +++++++++++++++++++++++++++++++++++++
425 You may specify a local configuration file instead of *src/test/resources/simParameters.json* on the command line or as an arument in the run configuration in eclipse:
431 "name": "DMaaP simulator",
436 "name": "DMaaP simulator",
437 "providerClass": "org.onap.policy.models.sim.dmaap.rest.DmaapSimRestControllerV1",