Add documentation for distribution S3P
[policy/parent.git] / docs / development / devtools / distribution-s3p.rst
index f448690..5596673 100644 (file)
 Policy Distribution component
 #############################
 
-72 Hours Stability Test of Distribution
-+++++++++++++++++++++++++++++++++++++++
+72h Stability and 4h Performance Tests of Distribution
+++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
-Introduction
+Common Setup
 ------------
-The 72 hour Stability Test for policy distribution has the goal of introducing a steady flow of transactions initiated from a test client server running JMeter. The policy distribution is configured with a special FileSystemReception plugin to monitor a local directory for newly added csar files to be processed by itself. The input CSAR will be added/removed by the test client(JMeter) and the result will be pulled from the backend(PAP and PolicyAPI) by the test client(JMeter).
 
+Update the ubuntu software installer
 
-The test will be performed in an environment where Jmeter will continuously add/remove a test csar into the special directory where policy distribuion is monitoring and will then get the processed results from PAP and PolicyAPI to verify the successful deployment of the policy. The policy will then be undeployed and the test will loop continuously until 72 hours have elapsed.
+.. code-block:: bash
 
-Setup details
--------------
+    sudo apt update
 
-The stability test is performed on VM's running in the OpenStack cloud environment in the ONAP integration lab. There are 2 separate VMs, one for running backend policy services which policy distribution needs, and the other is for policy distribution service itself and Jmeter.
+Install Java
 
-**OpenStack environment details**
+.. code-block:: bash
 
-Version: Windriver Titanium
+    sudo apt install -y openjdk-11-jdk
 
-**Policy Backend VM details(VM1)**
+Ensure that the Java version that is executing is OpenJDK version 11
 
-OS:Ubuntu 18.04.4 LTS
+.. code-block:: bash
 
-CPU: 8 core
+    $ java --version
+    openjdk 11.0.11 2021-04-20
+    OpenJDK Runtime Environment (build 11.0.11+9-Ubuntu-0ubuntu2.18.04)
+    OpenJDK 64-Bit Server VM (build 11.0.11+9-Ubuntu-0ubuntu2.18.04, mixed mode)
 
-RAM: 32 GB
+Install Docker and Docker Compose
 
-HardDisk: 160 GB
+.. code-block:: bash
 
-Docker version 19.03.8, build afacb8b7f0
+    # Add docker repository
+    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
 
-Java: openjdk version "11.0.7"
+    echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
+    $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
 
-**JMeter and Distribution VM details(VM2)**
+    sudo apt update
 
-OS: Ubuntu 18.04.4 LTS
+    # Install docker
+    sudo apt-get install docker-ce docker-ce-cli containerd.io
 
-CPU: 8 core
+Change the permissions of the Docker socket file
 
-RAM: 32 GB
+.. code-block:: bash
 
-HardDisk: 160 GB
+    sudo chmod 666 /var/run/docker.sock
 
-Docker version 19.03.8, build afacb8b7f0
+Check the status of the Docker service and ensure it is running correctly
 
-Java: openjdk version "11.0.7"
+.. code-block:: bash
 
-JMeter: 5.1.1
+    systemctl status --no-pager docker
+    docker.service - Docker Application Container Engine
+       Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
+       Active: active (running) since Wed 2020-10-14 13:59:40 UTC; 1 weeks 0 days ago
+       # ... (truncated for brevity)
 
-Install Docker in VM1 & VM2
----------------------------
-Make sure to execute below commands in VM1 & VM2 both.
+    docker ps
+    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
 
-Update the ubuntu software installer
+Install and verify docker-compose
 
 .. code-block:: bash
 
-    $ apt-get update
+    # Install compose (check if version is still available or update as necessary)
+    sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
+    sudo chmod +x /usr/local/bin/docker-compose
 
-Install and check Java
-
-.. code-block:: bash
+    # Check if install was successful
+    docker-compose --version
 
-    $ apt-get install -y openjdk-11-jdk
-    $ java -version
+Clone the policy-distribution repo to access the test scripts
 
-Ensure that the Java version that is executing is OpenJDK version 11
+.. code-block:: bash
 
-Install and check Docker
+    git clone https://gerrit.onap.org/r/policy/distribution
 
-.. code-block:: bash
+.. _setup-distribution-s3p-components:
 
-    $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
-    $ apt-get update
-    $ apt-cache policy docker-ce
-    $ apt-get install -y docker-ce
-    $ systemctl status docker
-    $ docker ps
+Start services for MariaDB, Policy API, PAP and Distribution
+------------------------------------------------------------
 
-Change the permissions of the Docker socket file
+Navigate to the main folder for scripts to setup services:
 
 .. code-block:: bash
 
-    $ sudo chmod 666 /var/run/docker.sock
+    cd ~/distribution/testsuites/stability/src/main/resources/setup
 
-Check the status of the Docker service and ensure it is running correctly
+Modify the versions.sh script to match all the versions being tested.
 
 .. code-block:: bash
 
-    $ service docker status
-    $ docker ps
+    vi ~/distribution/testsuites/stability/src/main/resources/setup/versions.sh
 
-Install Simulators, PAP, PolicyAPI and MariaDB in VM1
------------------------------------------------------
+Ensure the correct docker image versions are specified - e.g. for Kohn-M4
 
-To install all the components needed for Distribution, copy over the script and related files found within the simulatorsetup directory within $(REPOPATH)/distribution/testsuites/stability/src/main/resources
+- export POLICY_DIST_VERSION=2.8-SNAPSHOT
 
-Run setup_components.sh script to bring up the required docker containers
-
-After installation, ensure the following docker containers are up and running:
+Run the start.sh script to start the components. After installation, script will execute
+``docker ps`` and show the running containers.
 
 .. code-block:: bash
 
-    CONTAINER ID        IMAGE                                                  COMMAND                  CREATED              STATUS              PORTS                    NAMES
-    11195b01300a        nexus3.onap.org:10001/onap/policy-pap:2.2.2-SNAPSHOT   "bash ./policy-pap.sh"   13 seconds ago       Up 9 seconds        0.0.0.0:7000->6969/tcp   policy-pap
-    6266aa6b0137        nexus3.onap.org:10001/onap/policy-api:2.2.3-SNAPSHOT   "bash ./policy-api.sh"   25 seconds ago       Up 22 seconds       0.0.0.0:6969->6969/tcp   policy-api
-    6a85d155aa8a        pdp/simulator:latest                                   "bash pdp-sim.sh"        About a minute ago   Up About a minute                            pdp-simulator
-    0b41992ccfd7        dmaap/simulator:latest                                 "bash dmaap-sim.sh"      About a minute ago   Up About a minute   0.0.0.0:3904->3904/tcp   message-router
-    595056b2a094        mariadb:10.2.14                                        "docker-entrypoint.s…"   About a minute ago   Up About a minute   0.0.0.0:3306->3306/tcp   mariadb
-
-Install Distribution in VM2
----------------------------
-
-To install the Distribution service, copy over the script and related files found within the distributionsetup directory within $(REPOPATH)/distribution/testsuites/stability/src/main/resources
+    ./start.sh
 
-Run setup_distribution.sh script to install the distribution service, provide the IP of VM1 as the arguments to the script.
+    Creating network "setup_default" with the default driver
+    Creating policy-distribution ... done
+    Creating mariadb             ... done
+    Creating simulator           ... done
+    Creating policy-db-migrator  ... done
+    Creating policy-api          ... done
+    Creating policy-pap          ... done
 
-e.g
-.. code-block:: bash
+    fa4e9bd26e60   nexus3.onap.org:10001/onap/policy-pap:2.7-SNAPSHOT-latest                "/opt/app/policy/pap…"   1 second ago    Up Less than a second   6969/tcp             policy-pap
+    efb65dd95020   nexus3.onap.org:10001/onap/policy-api:2.7-SNAPSHOT-latest                "/opt/app/policy/api…"   1 second ago    Up Less than a second   6969/tcp             policy-api
+    cf602c2770ba   nexus3.onap.org:10001/onap/policy-db-migrator:2.5-SNAPSHOT-latest        "/opt/app/policy/bin…"   2 seconds ago   Up 1 second             6824/tcp             policy-db-migrator
+    99383d2fecf4   pdp/simulator                                                            "sh /opt/app/policy/…"   2 seconds ago   Up 1 second                                  pdp-simulator
+    3c0e205c5f47   nexus3.onap.org:10001/onap/policy-models-simulator:2.7-SNAPSHOT-latest   "simulators.sh"          3 seconds ago   Up 2 seconds            3904/tcp             simulator
+    3ad00d90d6a3   nexus3.onap.org:10001/onap/policy-distribution:2.8-SNAPSHOT-latest       "/opt/app/policy/bin…"   3 seconds ago   Up 2 seconds            6969/tcp, 9090/tcp   policy-distribution
+    bb0b915cdecc   nexus3.onap.org:10001/mariadb:10.5.8                                     "docker-entrypoint.s…"   3 seconds ago   Up 2 seconds            3306/tcp             mariadb
 
-    $ ./setup_distribution.sh 10.2.0.24 10.2.0.24
+.. note::
+    The containers on this docker-compose are running with HTTP configuration. For HTTPS, ports
+    and configurations will need to be changed, as well certificates and keys must be generated
+    for security.
 
-Ensure the distribution container is running.
 
-Install JMeter in VM2
----------------------
+Install JMeter
+--------------
 
-Download and install jMeter
+Download and install JMeter
 
 .. code-block:: bash
 
-    $ mkdir jMeter
-    $ cd jMeter
-    $ wget https://archive.apache.org/dist/jmeter/binaries/apache-jmeter-5.1.1.zip
-    $ unzip apache-jmeter-5.1.1.zip
+    # Install required packages
+    sudo apt install -y wget unzip
 
-Install & configure visualVM in VM2
------------------------------------
-VisualVM needs to be installed in the virtual machine running Distrbution. It will be used to monitor CPU, Memory and GC for Distribution while the stability tests are running.
+    # Install JMeter
+    mkdir -p jmeter
+    cd jmeter
+    wget https://dlcdn.apache.org//jmeter/binaries/apache-jmeter-5.5.zip # check if valid version
+    unzip -q apache-jmeter-5.5.zip
+    rm apache-jmeter-5.5.zip
 
-.. code-block:: bash
 
-    $ sudo apt-get install visualVM
+Install & configure visualVM
+--------------------------------------
 
-Run these commands to configure permissions
+VisualVM needs to be installed in the virtual machine running Distribution. It will be used to
+monitor CPU, Memory and GC for Distribution while the stability tests are running.
 
 .. code-block:: bash
 
-    $ cd /usr/lib/jvm/java-11-openjdk-amd64/bin/
-    $ sudo touch visualvm.policy
-    $ sudo chmod 777 visualvm.policy
+    sudo apt install -y visualvm
 
-    $ vi visualvm.policy
+Run these commands to configure permissions (if permission errors happens, use ``sudo su``)
 
-    Add the following in visualvm.policy
+.. code-block:: bash
+
+    # Set globally accessable permissions on policy file
+    sudo chmod 777 /usr/lib/jvm/java-11-openjdk-amd64/bin/visualvm.policy
 
-    grant codebase "file:/usr/lib/jvm/java-11-openjdk-amd64/lib/tools.jar" {
-    permission java.security.AllPermission;
+    # Create Java security policy file for VisualVM
+    sudo cat > /usr/lib/jvm/java-11-openjdk-amd64/bin/visualvm.policy << EOF
+    grant codebase "jrt:/jdk.jstatd" {
+       permission java.security.AllPermission;
+    };
+    grant codebase "jrt:/jdk.internal.jvmstat" {
+       permission java.security.AllPermission;
     };
+    EOF
 
-Run the following commands to start jstatd using port 1111
+Run the following command to start jstatd using port 1111
 
 .. code-block:: bash
 
-    $ cd /usr/lib/jvm/java-8-openjdk-amd64/bin/
-    $ ./jstatd -p 1111 -J-Djava.security.policy=visualvm.policy  &
+    /usr/lib/jvm/java-11-openjdk-amd64/bin/jstatd -p 1111 -J-Djava.security.policy=/usr/lib/jvm/java-11-openjdk-amd64/bin/visualvm.policy &
 
-Using the VM2 Desktop, run visualVM to connect to localhost:9090
-Run the command
+Run visualVM to connect to POLICY_DISTRIBUTION_IP:9090
 
 .. code-block:: bash
 
-    $ visualvm
+    # Get the Policy Distribution container IP
+    echo $(docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' policy-distribution)
+
+    # Start visual vm
+    visualvm &
 
 This will load up the visualVM GUI
 
 Connect to Distribution JMX Port.
 
-    1. Right click on "Local" in the left panel of the screen and select "Add JMX Connection"
-    2. Enter the Port 9090. this is the JMX port exposed by the dsitribution container
-    3. Double click on the newly added nodes under "Local" to start monitoring CPU, Memory & GC.
+    1. On the visualvm toolbar, click on "Add JMX Connection"
+    2. Enter the Distribution container IP and Port 9090. This is the JMX port exposed by the
+       distribution container
+    3. Double click on the newly added nodes under "Remotes" to start monitoring CPU, Memory & GC.
 
-Example Screenshot
+Example Screenshot of visualVM
 
-Sample Screenshot of visualVM
+.. image:: distribution-s3p-results/distribution-visualvm-snapshot.png
 
-.. image:: images/distribution-s3p-vvm-sample.png
 
-Test Plan Setup
----------------
+Stability Test of Policy Distribution
++++++++++++++++++++++++++++++++++++++
 
-The 72 hours stability test will run the following steps sequentially in a single threaded loop.
+Introduction
+------------
+
+The 72 hour Stability Test for policy distribution has the goal of introducing a steady flow of
+transactions initiated from a test client server running JMeter. The policy distribution is
+configured with a special FileSystemReception plugin to monitor a local directory for newly added
+csar files to be processed by itself. The input CSAR will be added/removed by the test client
+(JMeter) and the result will be pulled from the backend (PAP and PolicyAPI) by the test client
+(JMeter).
+
+The test will be performed in an environment where Jmeter will continuously add/remove a test csar
+into the special directory where policy distribution is monitoring and will then get the processed
+results from PAP and PolicyAPI to verify the successful deployment of the policy. The policy will
+then be undeployed and the test will loop continuously until 72 hours have elapsed.
+
+
+Test Plan Sequence
+------------------
+
+The 72h stability test will run the following steps sequentially in a single threaded loop.
 
 - **Delete Old CSAR** - Checks if CSAR already exists in the watched directory, if so it deletes it
 - **Add CSAR** - Adds CSAR to the directory that distribution is watching
 - **Get Healthcheck** - Ensures Healthcheck is returning 200 OK
 - **Get Statistics** - Ensures Statistics is returning 200 OK
-- **CheckPDPGroupQuery** - Checks that PDPGroupQuery contains the deployed policy
-- **CheckPolicyDeployed** - Checks that the policy is deployed
-- **Undeploy Policy** - Undeploys the policy
-- **Delete Policy** - Deletes the Policy for the next loop
-- **Check PDP Group for Deletion** - Ensures the policy has been removed and does not exist
+- **Get Metrics** - Ensures Metrics is returning 200 OK
+- **Assert PDP Group Query** - Checks that PDPGroupQuery contains the deployed policy
+- **Assert PoliciesDeployed** - Checks that the policy is deployed
+- **Undeploy/Delete Policy** - Undeploys and deletes the Policy for the next loop
+- **Assert PDP Group Query for Deleted Policy** - Ensures the policy has been removed and does not exist
 
 The following steps can be used to configure the parameters of the test plan.
 
@@ -228,45 +262,128 @@ The following steps can be used to configure the parameters of the test plan.
 
 Screenshot of Distribution stability test plan
 
-.. image:: images/distribution-s3p-testplan.png
+.. image:: distribution-s3p-results/distribution-jmeter-testcases.png
+
 
 Running the Test Plan
 ---------------------
 
-Copy the Test Plans folder onto VM2
-Edit the /tmp/ folder permissions to allow the Testplan to insert the CSAR into the /tmp/policydistribution/distributionmount/ folder
+Check if the /tmp/policydistribution/distributionmount exists as it was created during the start.sh
+script execution. If not, run the following commands to create folder and change folder permissions
+to allow the testplan to insert the CSAR into the /tmp/policydistribution/distributionmount folder.
+
+.. note::
+    Make sure that only csar file is being loaded in the watched folder and log generation is in a
+    logs folder, as any sort of zip file can be understood by distribution as a policy file. A
+    logback.xml configuration file is available under setup/distribution folder.
+
+.. code-block:: bash
+
+    sudo mkdir -p /tmp/policydistribution/distributionmount
+    sudo chmod -R a+trwx /tmp
+
+
+Navigate to the stability test folder.
 
 .. code-block:: bash
 
-    $ sudo chmod a+trwx /tmp
+    cd ~/distribution/testsuites/stability/src/main/resources/testplans/
 
-From the apache jMeter folder run the test, pointing it towards the stabiltiy.jmx file inside the testplans folder
+Execute the run_test.sh
 
 .. code-block:: bash
 
-    $ ./bin/jmeter -n -t /home/rossc/testplans/stability.jmx -Jduration=259200 -l testresults.jtl
+    ./run_test.sh
+
 
 Test Results
 ------------
 
 **Summary**
 
-Stability test plan was triggered for 72 hours.
+- Stability test plan was triggered for 72 hours.
+- No errors were reported
 
 **Test Statistics**
 
-=======================  =================  ==================  ==================================
-**Total # of requests**  **Success %**      **Error %**         **Average time taken per request**
-=======================  =================  ==================  ==================================
-194313                   100 %              0 %                 145 ms
-=======================  =================  ==================  ==================================
+.. image:: distribution-s3p-results/stability-statistics.png
+.. image:: distribution-s3p-results/stability-threshold.png
+
+**VisualVM Screenshots**
+
+.. image:: distribution-s3p-results/stability-monitor.png
+.. image:: distribution-s3p-results/stability-threads.png
+
+
+Performance Test of Policy Distribution
++++++++++++++++++++++++++++++++++++++++
+
+Introduction
+------------
+
+The 4h Performance Test of Policy Distribution 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.
+
+It also tests that distribution can handle multiple policy CSARs and that these are deployed within
+60 seconds consistently.
+
+
+Setup Details
+-------------
+
+The performance test is based on the same setup as the distribution stability tests.
+
+
+Test Plan Sequence
+------------------
+
+Performance test plan is different from the stability test plan.
+
+- Instead of handling one policy csar at a time, multiple csar's are deployed within the watched
+  folder at the exact same time.
+- We expect all policies from these csar's to be deployed within 60 seconds.
+- There are also multithreaded tests running towards the healthcheck and statistics endpoints of
+  the distribution service.
+
+
+Running the Test Plan
+---------------------
+
+Check if /tmp folder permissions to allow the Testplan to insert the CSAR into the
+/tmp/policydistribution/distributionmount folder.
+Clean up from previous run. If necessary, put containers down with script ``down.sh`` from setup
+folder mentioned on :ref:`Setup components <setup-distribution-s3p-components>`
+
+.. code-block:: bash
+
+    sudo mkdir -p /tmp/policydistribution/distributionmount
+    sudo chmod -R a+trwx /tmp
+
+Navigate to the testplan folder and execute the test script:
+
+.. code-block:: bash
+
+    cd ~/distribution/testsuites/performance/src/main/resources/testplans/
+    ./run_test.sh
+    
+
+Test Results
+------------
+
+**Summary**
+
+- Performance test plan was triggered for 4 hours.
+- No errors were reported
+
+**Test Statistics**
 
-**VisualVM Screenshot**
+.. image:: distribution-s3p-results/performance-statistics.png
+.. image:: distribution-s3p-results/performance-threshold.png
 
-.. image:: images/distribution-vvm-monitor.png
-.. image:: images/distribution-vvm-threads.png
+**VisualVM Screenshots**
 
-**JMeter Screenshot**
+.. image:: distribution-s3p-results/performance-monitor.png
+.. image:: distribution-s3p-results/performance-threads.png
 
-.. image:: images/distribution-summary-report.png
-.. image:: images/distribution-results-tree.png
+End of document