Update developer and s3p docs
[policy/parent.git] / docs / development / devtools / api-s3p.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 .. _api-s3p-label:
6
7 .. toctree::
8    :maxdepth: 2
9
10 Policy API S3P Tests
11 ####################
12
13
14 72 Hours Stability Test of Policy API
15 +++++++++++++++++++++++++++++++++++++
16
17 Introduction
18 ------------
19
20 The 72 hour stability test of policy API has the goal of verifying the stability of running policy design API REST service by 
21 ingesting a steady flow of transactions of policy design API calls in a multi-thread fashion to simulate multiple clients' behaviors. 
22 All the transaction flows are initiated from a test client server running JMeter for the duration of 72+ hours.
23
24 Setup Details
25 -------------
26
27 The stability test is performed on VMs running in Intel Wind River Lab environment.
28 There are 2 seperate VMs. One for running API while the other running JMeter & other necessary components, e.g. MariaDB, to simulate steady flow of transactions.
29 For simplicity, let's assume:
30
31 VM1 will be running JMeter, MariaDB.
32 VM2 will be running API REST service and visualVM.
33
34 **Lab Environment**
35
36 Intel ONAP Integration and Deployment Labs 
37 `Physical Labs <https://wiki.onap.org/display/DW/Physical+Labs>`_,
38 `Wind River <https://www.windriver.com/>`_
39
40 **API VM Details (VM2)**
41
42 OS: Ubuntu 18.04 LTS
43
44 CPU: 4 core
45
46 RAM: 8 GB
47
48 HardDisk: 91 GB
49
50 Docker Version: 18.09.8
51
52 Java: OpenJDK 1.8.0_212
53
54 **JMeter VM Details (VM1)**
55
56 OS: Ubuntu 18.04 LTS
57
58 CPU: 4 core
59
60 RAM: 8GB
61
62 HardDisk: 91GB
63
64 Docker Version: 18.09.8
65
66 Java: OpenJDK 1.8.0_212
67
68 JMeter: 5.1.1
69
70 **Software Installation & Configuration**
71
72 **VM1 & VM2 in lab**
73
74 **Install Java & Docker**
75
76 Make the etc/hosts entries
77
78 .. code-block:: bash
79    
80     $ echo $(hostname -I | cut -d\  -f1) $(hostname) | sudo tee -a /etc/hosts
81     
82 Update the Ubuntu software installer
83
84 .. code-block:: bash
85    
86     $ sudo apt-get update
87     
88 Check and install Java
89
90 .. code-block:: bash
91    
92     $ sudo apt-get install -y openjdk-8-jdk
93     $ java -version
94     
95 Ensure that the Java version executing is OpenJDK version 8
96     
97 Check and install docker
98
99 .. code-block:: bash
100     
101     $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
102     $ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
103     $ sudo apt-get update
104     $ sudo apt-cache policy docker-ce
105     $ sudo apt-get install -y docker-ce
106     $ systemctl status docker
107     $ docker ps
108
109 Change the permissions of the Docker socket file
110
111 .. code-block:: bash
112    
113     $ sudo chmod 777 /var/run/docker.sock
114
115 Check the status of the Docker service and ensure it is running correctly
116
117 .. code-block:: bash
118    
119     $ service docker status
120     $ docker ps
121     
122 **VM1 in lab**
123
124 **Install JMeter**
125
126 Download & install JMeter
127
128 .. code-block:: bash
129    
130     $ mkdir jMeter
131     $ cd jMeter
132     $ wget http://mirrors.whoishostingthis.com/apache//jmeter/binaries/apache-jmeter-5.1.1.zip
133     $ unzip apache-jmeter-5.1.1.zip
134     
135 **Install other necessary components**
136
137 Pull api code & run setup components script
138
139 .. code-block:: bash
140    
141     $ cd ~
142     $ git clone https://git.onap.org/policy/api
143     $ cd api/testsuites/stability/src/main/resources/simulatorsetup
144     $ ./setup_components.sh
145     
146 After installation, make sure the following mariadb container is up and running
147
148 .. code-block:: bash
149    
150     ubuntu@test:~/api/testsuites/stability/src/main/resources/simulatorsetup$ docker ps
151     CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
152     3849ce44b86d        mariadb:10.2.14     "docker-entrypoint.s…"   11 days ago         Up 11 days          0.0.0.0:3306->3306/tcp   mariadb
153
154 **VM2 in lab**
155
156 **Install policy-api**
157
158 Pull api code & run setup api script
159
160 .. code-block:: bash
161    
162     $ cd ~
163     $ git clone https://git.onap.org/policy/api
164     $ cd api/testsuites/stability/src/main/resources/apisetup
165     $ ./setup_api.sh <host ip running api> <host ip running mariadb>
166
167 After installation, make sure the following api container is up and running
168
169 .. code-block:: bash
170    
171     ubuntu@tools-2:~/api/testsuites/stability/src/main/resources/apisetup$ docker ps
172     CONTAINER ID        IMAGE                                                  COMMAND                  CREATED             STATUS              PORTS                                          NAMES
173     4f08f9972e55        nexus3.onap.org:10001/onap/policy-api:2.1.1-SNAPSHOT   "bash ./policy-api.sh"   11 days ago         Up 11 days          0.0.0.0:6969->6969/tcp, 0.0.0.0:9090->9090/tcp   policy-api
174
175 **Install & configure visualVM**
176
177 VisualVM needs to be installed in the virtual machine having API up and running. It will be used to monitor CPU, Memory, GC for API while stability test is running.
178
179 Install visualVM
180
181 .. code-block:: bash
182    
183     $ sudo apt-get install visualvm
184     
185 Run few commands to configure permissions
186
187 .. code-block:: bash
188    
189     $ cd /usr/lib/jvm/java-8-openjdk-amd64/bin/
190     $ sudo touch visualvm.policy
191     $ sudo chmod 777 visualvm.policy
192       
193     $ vi visualvm.policy
194       
195     Add the following in visualvm.policy
196       
197       
198     grant codebase "file:/usr/lib/jvm/java-8-openjdk-amd64/lib/tools.jar" {
199        permission java.security.AllPermission;
200     };
201
202 Run following commands to start jstatd using port 1111
203
204 .. code-block:: bash
205    
206     $ cd /usr/lib/jvm/java-8-openjdk-amd64/bin/
207     $ ./jstatd -p 1111 -J-Djava.security.policy=visualvm.policy  &
208     
209 **Local Machine**
210
211 **Run & configure visualVM**
212
213 Run visualVM by typing
214
215 .. code-block:: bash
216    
217     $ jvisualvm
218     
219 Connect to jstatd & remote policy-api JVM
220
221     1. Right click on "Remote" in the left panel of the screen and select "Add Remote Host..."
222     2. Enter the IP address of VM2 (running policy-api)
223     3. Right click on IP address, select "Add JMX Connection..."
224     4. Enter the VM2 IP Address (from step 2) <IP address>:9090 ( for example, 10.12.6.151:9090) and click OK.
225     5. Double click on the newly added nodes under "Remote" to start monitoring CPU, Memory & GC.
226
227 Sample Screenshot of visualVM
228
229 .. image:: images/results-5.png
230
231 Test Plan
232 ---------
233
234 The 72+ hours stability test will be running the following steps sequentially in multi-threaded loops.
235 Thread number is set to 5 to simulate 5 API clients' behaviors (they can be calling the same policy CRUD API simultaneously).
236
237 **Setup Thread (will be running only once)**
238     
239 - Get policy-api Healthcheck
240 - Get API Counter Statistics
241 - Get Preloaded Policy Types
242
243 **API Test Flow (5 threads running the same steps in the same loop)**
244
245 - Create a new TCA Policy Type with Version 1.0.0
246 - Create a new TCA Policy Type with Version 2.0.0
247 - Create a new TCA Policy Type with Version 3.0.0
248 - Create a new TCA Policy Type with Version 4.0.0
249 - Create a new TCA Policy Type with Version 5.0.0
250 - Create a new TCA Policy Type with Version 6.0.0
251 - Create a new TCA Policy Type with Version 7.0.0
252 - Create a new TCA Policy Type with Version 8.0.0
253 - Create a new TCA Policy Type with Version 9.0.0
254 - Create a new TCA Policy Type with Version 10.0.0
255 - Create a new TCA Policy Type with Version 11.0.0
256 - A 10 sec timer
257 - Get All Existing Policy Types
258 - Get All Existing Versions of the New TCA Policy Type
259 - Get Version 1.0.0 of the New TCA Policy Type
260 - Get Version 2.0.0 of the New TCA Policy Type
261 - Get Version 3.0.0 of the New TCA Policy Type
262 - Get Version 4.0.0 of the New TCA Policy Type
263 - Get Version 5.0.0 of the New TCA Policy Type
264 - Get Version 6.0.0 of the New TCA Policy Type
265 - Get Version 7.0.0 of the New TCA Policy Type
266 - Get Version 8.0.0 of the New TCA Policy Type
267 - Get Version 9.0.0 of the New TCA Policy Type
268 - Get Version 10.0.0 of the New TCA Policy Type
269 - Get Version 11.0.0 of the New TCA Policy Type
270 - Get the Latest Version of the New TCA Policy Type
271 - A 10 sec timer
272 - Create a New TCA Policy with Version 1.0.0 over the New TCA Policy Type Version 2.0.0
273 - Create a New TCA Policy with Version 2.0.0 over the New TCA Policy Type Version 2.0.0
274 - Create a New TCA Policy with Version 3.0.0 over the New TCA Policy Type Version 2.0.0
275 - Create a New TCA Policy with Version 4.0.0 over the New TCA Policy Type Version 2.0.0
276 - Create a New TCA Policy with Version 5.0.0 over the New TCA Policy Type Version 2.0.0
277 - Create a New TCA Policy with Version 6.0.0 over the New TCA Policy Type Version 2.0.0
278 - Create a New TCA Policy with Version 7.0.0 over the New TCA Policy Type Version 2.0.0
279 - Create a New TCA Policy with Version 8.0.0 over the New TCA Policy Type Version 2.0.0
280 - Create a New TCA Policy with Version 9.0.0 over the New TCA Policy Type Version 2.0.0
281 - Create a New TCA Policy with Version 10.0.0 over the New TCA Policy Type Version 2.0.0
282 - Create a New TCA Policy with Version 11.0.0 over the New TCA Policy Type Version 2.0.0
283 - A 10 sec Timer
284 - Get All Existing TCA Policies
285 - Get All Existing Versions of TCA Policies
286 - Get Version 1.0.0 of the New TCA Policy
287 - Get Version 2.0.0 of the New TCA Policy
288 - Get Version 3.0.0 of the New TCA Policy
289 - Get Version 4.0.0 of the New TCA Policy
290 - Get Version 5.0.0 of the New TCA Policy
291 - Get Version 6.0.0 of the New TCA Policy
292 - Get Version 7.0.0 of the New TCA Policy
293 - Get Version 8.0.0 of the New TCA Policy
294 - Get Version 9.0.0 of the New TCA Policy
295 - Get Version 10.0.0 of the New TCA Policy
296 - Get Version 11.0.0 of the New TCA Policy
297 - Get the Latest Version of the New TCA Policy
298 - A 10 sec Timer
299 - Create a New Guard Policy with Version 1
300 - Create a New Guard Policy with Version 5
301 - Create a New Guard Policy with Version 9
302 - Create a New Guard Policy with Version 12
303 - A 10 sec Timer
304 - Get Version 1 of the New Guard Policy
305 - Get Version 5 of the New Guard Policy
306 - Get Version 9 of the New Guard Policy
307 - Get Version 12 of the New Guard Policy
308 - Get the Latest Version of the New Guard Policy
309 - A 10 sec Timer
310
311 **TearDown Thread (will only be running after API Test Flow is completed)**
312
313 - Delete Version 2.0.0 of the New TCA Policy Type (suppose to return 409-Conflict)
314 - Delete Version 3.0.0 of the New TCA Policy Type
315 - Delete Version 4.0.0 of the New TCA Policy Type
316 - Delete Version 5.0.0 of the New TCA Policy Type
317 - Delete Version 6.0.0 of the New TCA Policy Type
318 - Delete Version 7.0.0 of the New TCA Policy Type
319 - Delete Version 8.0.0 of the New TCA Policy Type
320 - Delete Version 9.0.0 of the New TCA Policy Type
321 - Delete Version 10.0.0 of the New TCA Policy Type
322 - Delete Version 11.0.0 of the New TCA Policy Type
323 - Delete Version 1.0.0 of the New TCA Policy
324 - Delete Version 2.0.0 of the New TCA Policy
325 - Delete Version 3.0.0 of the New TCA Policy
326 - Delete Version 4.0.0 of the New TCA Policy
327 - Delete Version 5.0.0 of the New TCA Policy
328 - Delete Version 6.0.0 of the New TCA Policy
329 - Delete Version 7.0.0 of the New TCA Policy
330 - Delete Version 8.0.0 of the New TCA Policy
331 - Delete Version 9.0.0 of the New TCA Policy
332 - Delete Version 10.0.0 of the New TCA Policy
333 - Delete Version 11.0.0 of the New TCA Policy
334 - Re-Delete Version 2.0.0 of the New TCA Policy Type (will return 200 now since all TCA policies created over have been deleted)
335 - Delete Version 1 of the new Guard Policy
336 - Delete Version 5 of the new Guard Policy
337 - Delete Version 9 of the new Guard Policy
338 - Delete Version 12 of the new Guard Policy
339
340 Run Test
341 --------
342
343 **Local Machine**
344
345 Connect to lab VPN
346
347 .. code-block:: bash
348     
349     $ sudo openvpn --config <path to lab ovpn key file>
350     
351 SSH into JMeter VM (VM1)
352
353 .. code-block:: bash
354
355     $ ssh -i <path to lab ssh key file> ubuntu@<host ip of JMeter VM>
356
357 Run JMeter test in background for 72+ hours
358
359 .. code-block:: bash
360   
361     $ mkdir s3p
362     $ nohup ./jMeter/apache-jmeter-5.1.1/bin/jmeter.sh -n -t ~/api/testsuites/stability/src/main/resources/testplans/policy_api_stability.jmx &
363
364 (Optional) Monitor JMeter test that is running in background (anytime after re-logging into JMeter VM - VM1)
365
366 .. code-block:: bash
367
368     $ tail -f s3p/stability.log nohup.out
369
370
371 Test Results
372 ------------
373
374 **Summary**
375
376 Policy API stability test plan was triggered and running for 72+ hours without any error occurred.
377
378 **Test Statistics**
379
380 =======================  =============  ===========  ===============================  ===============================  ===============================
381 **Total # of requests**  **Success %**  **Error %**  **Avg. time taken per request**  **Min. time taken per request**  **Max. time taken per request**
382 =======================  =============  ===========  ===============================  ===============================  ===============================
383     49723                    100%           0%              86 ms                               4 ms                            795 ms
384 =======================  =============  ===========  ===============================  ===============================  ===============================
385
386 **VisualVM Results**
387
388 .. image:: images/results-5.png
389 .. image:: images/results-6.png
390
391 **JMeter Results**
392
393 .. image:: images/results-1.png
394 .. image:: images/results-2.png
395 .. image:: images/results-3.png
396 .. image:: images/results-4.png
397
398
399
400 Performance Test of Policy API
401 ++++++++++++++++++++++++++++++
402
403 Introduction
404 ------------
405
406 Performance test of policy-api has the goal of testing the min/avg/max processing time and rest call throughput for all the requests when the number of requests are large enough to saturate the resource and find the bottleneck. 
407
408 Setup Details
409 -------------
410
411 The performance test is performed on OOM-based deployment of ONAP Policy framework components in Intel Wind River Lab environment.
412 In addition, we use another VM with JMeter installed to generate the transactions.
413 The JMeter VM will be sending large number of REST requests to the policy-api component and collecting the statistics.
414 Policy-api component already knows how to communicate with MariaDB component if OOM-based deployment is working correctly.
415
416 Test Plan
417 ---------
418
419 Performance test plan is the same as stability test plan above.
420 Only differences are, in performance test, we increase the number of threads up to 20 (simulating 20 users' behaviors at the same time) whereas reducing the test time down to 1 hour. 
421
422 Run Test
423 --------
424
425 Running/Triggering performance test will be the same as stability test. That is, launch JMeter pointing to corresponding *.jmx* test plan. The *API_HOST* and *API_PORT* are already set up in *.jmx*.
426
427 Test Results
428 ------------
429
430 Test results are shown as below. Overall, the test was running smoothly and successfully. We do see some minor failed transactions, especially in POST calls which intend to write into DB simultaneously in a multi-threaded fashion . All GET calls (reading from DB) were succeeded.
431
432 .. image:: images/summary-1.png
433 .. image:: images/summary-2.png
434 .. image:: images/summary-3.png
435 .. image:: images/result-1.png
436 .. image:: images/result-2.png
437 .. image:: images/result-3.png
438 .. image:: images/result-4.png
439 .. image:: images/result-5.png
440 .. image:: images/result-6.png
441