blob: 9646ffa963738f81a588dc56ed60261aef678ffb [file] [log] [blame]
Rashmi Pujar451a53a2019-12-10 17:10:55 -05001.. This work is licensed under a
2.. Creative Commons Attribution 4.0 International License.
3.. http://creativecommons.org/licenses/by/4.0
4
5
6Policy Platform Development Tools
7#################################
8
9.. contents::
10 :depth: 3
11
12
13This 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`.
14
15
16This 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*
Pamela Dragoshba45dc62020-04-16 09:27:44 -040021* You have copied the settings.xml from oparent to *~/.m2/* directory
Rashmi Pujar451a53a2019-12-10 17:10:55 -050022* 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
Pamela Dragoshba45dc62020-04-16 09:27:44 -040024The 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.
Rashmi Pujar451a53a2019-12-10 17:10:55 -050025
26Cloning All The Policy Repositories
27***********************************
28
29Run 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.
30
31ONAP 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 \
Pamela Dragoshba45dc62020-04-16 09:27:44 -040058 policy/distribution \
59 policy/gui \
60 policy/engine "
Rashmi Pujar451a53a2019-12-10 17:10:55 -050061
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
141Execution 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
Pamela Dragoshba45dc62020-04-16 09:27:44 -0400150 * ~/git/onap/policy/gui
Rashmi Pujar451a53a2019-12-10 17:10:55 -0500151 * ~/git/onap/policy/docker
152 * ~/git/onap/policy/drools-applications
153 * ~/git/onap/policy/drools-pdp
154 * ~/git/onap/policy/engine
155 * ~/git/onap/policy/apex-pdp
156 * ~/git/onap/policy/xacml-pdp
157 * ~/git/onap/policy/distribution
158
159
160Building 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>
Pamela Dragoshba45dc62020-04-16 09:27:44 -0400198 <module>distribution</module>
199 <module>gui</module>
Rashmi Pujar451a53a2019-12-10 17:10:55 -0500200 <!-- The engine repo is being deprecated,
201 and can be ommitted if not working with
202 legacy api and components. -->
203 <module>engine</module>
Rashmi Pujar451a53a2019-12-10 17:10:55 -0500204 </modules>
205 </project>
206
207**Policy Architecture/API Transition**
208
209In Dublin, a new Policy Architecture was introduced. The legacy architecture runs in parallel with the new architecture. It will be deprecated after Frankfurt release.
210If the developer is only interested in working with the new architecture components, the engine sub-module can be ommitted.
211
212
Pamela Dragoshba45dc62020-04-16 09:27:44 -0400213**Step 3:** You can now build the Policy framework.
214
215Java artifacts only:
Rashmi Pujar451a53a2019-12-10 17:10:55 -0500216
217 .. code-block:: bash
218
219 cd ~/git/onap
220 mvn clean install
221
Pamela Dragoshba45dc62020-04-16 09:27:44 -0400222With docker images:
223
224 .. code-block:: bash
225
226 cd ~/git/onap
227 mvn clean install -P docker
228
229Developing and Debugging each Policy Component
230**********************************************
231
232Running a MariaDb Instance
233++++++++++++++++++++++++++
234
235The Policy Framework requires a MariaDb instance running. The easiest way to do this is to run a docker image locally.
236
237One example on how to do this is to use the scripts used by the policy/api S3P tests.
238
239`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>`_
240
241 .. code-block:: bash
242
243 cd ~/git/onap/api/testsuites/stability/src/main/resources/simulatorsetup
244 ./setup_components.sh
245
246Another example on how to run the MariaDb is using the docker compose file used by the Policy API CSITs:
247
248`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>`_
249
250Running the API component standalone
251+++++++++++++++++++++++++++++++++++++
252
253Assuming you have successfully built the codebase using the instructions above. The only requirement for the API component to run is a
254running MariaDb database instance. The easiest way to do this is to run the docker image, please see the mariadb documentation for the latest
255information 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
256connect to the mariadb. You can locate the default configuration file in the packaging of the api component:
257
258`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>`_
259
260You will want to change the fields pertaining to "host", "port" and "databaseUrl" to your local environment settings.
261
262Running the API component using Docker Compose
263++++++++++++++++++++++++++++++++++++++++++++++
264
265An example of running the api using a docker compose script is located in the Policy Integration CSIT test repository.
266
267`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>`_
Rashmi Pujar451a53a2019-12-10 17:10:55 -0500268
269Running the Stability/Performance Tests
270***************************************
271
Pamela Dragoshba45dc62020-04-16 09:27:44 -0400272The following links contain instructions on how to run the S3P Stability and Performance tests. These may be helpful to developers to become
273familiar with the Policy Framework components and test any local changes.
Rashmi Pujar451a53a2019-12-10 17:10:55 -0500274
Pamela Dragoshba45dc62020-04-16 09:27:44 -0400275.. toctree::
276 :maxdepth: 1
Rashmi Pujar451a53a2019-12-10 17:10:55 -0500277
Pamela Dragoshba45dc62020-04-16 09:27:44 -0400278 api-s3p.rst
279 pap-s3p.rst
280 apex-s3p.rst
281 drools-s3p.rst
282 xacml-s3p.rst