Add ability to turn on/off pdp statistics 50/122350/3
authorRam Krishna Verma <ram_krishna.verma@bell.ca>
Tue, 29 Jun 2021 21:01:21 +0000 (17:01 -0400)
committerAjith Sreekumar <ajith.sreekumar@bell.ca>
Wed, 30 Jun 2021 09:18:52 +0000 (09:18 +0000)
Adding an ability in pap to turn on/off processing of pdp statistics.
By default it will be turned on and can be changed via configuration.

Issue-ID: POLICY-3450
Change-Id: I093fe3f1390769f9acf2cfe85dd0d4edf0539de8
Signed-off-by: Ram Krishna Verma <ram_krishna.verma@bell.ca>
12 files changed:
main/src/main/java/org/onap/policy/pap/main/comm/PdpHeartbeatListener.java
main/src/main/java/org/onap/policy/pap/main/comm/PdpModifyRequestMap.java
main/src/main/java/org/onap/policy/pap/main/comm/PdpStatusMessageHandler.java
main/src/main/java/org/onap/policy/pap/main/parameters/PapParameterGroup.java
main/src/main/java/org/onap/policy/pap/main/parameters/PdpModifyRequestMapParams.java
main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java
main/src/test/java/org/onap/policy/pap/main/comm/PdpHeartbeatListenerTest.java
main/src/test/resources/parameters/MinimumParameters.json
main/src/test/resources/parameters/PapConfigParameters.json
main/src/test/resources/parameters/PapConfigParametersStd.json
packages/policy-pap-tarball/src/main/resources/etc/defaultConfig.json
packages/policy-pap-tarball/src/main/resources/etc/s3pConfig.json [deleted file]

index 1a58ad9..027436a 100644 (file)
@@ -2,6 +2,7 @@
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
  *  Modifications Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
+ *  Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -35,19 +36,22 @@ public class PdpHeartbeatListener implements TypedMessageListener<PdpStatus> {
 
     private final PdpParameters params;
 
+    private final boolean savePdpStatistics;
+
     /**
      * Constructs the object.
      *
      * @param params PDP parameters
      */
-    public PdpHeartbeatListener(PdpParameters params) {
+    public PdpHeartbeatListener(PdpParameters params, boolean savePdpStatistics) {
         this.params = params;
+        this.savePdpStatistics = savePdpStatistics;
     }
 
     @Override
     public void onTopicEvent(final CommInfrastructure infra, final String topic, final PdpStatus message) {
 
-        final var handler = new PdpStatusMessageHandler(params);
+        final var handler = new PdpStatusMessageHandler(params, savePdpStatistics);
         handler.handlePdpStatus(message);
     }
 }
index bf9f290..beef475 100644 (file)
@@ -4,6 +4,7 @@
  * ================================================================================
  * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2021 Nordix Foundation.
+ * Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -356,7 +357,7 @@ public class PdpModifyRequestMap {
      * @return a response handler
      */
     protected PdpStatusMessageHandler makePdpResponseHandler() {
-        return new PdpStatusMessageHandler(params.getParams());
+        return new PdpStatusMessageHandler(params.getParams(), params.isSavePdpStatistics());
     }
 
     /**
index b430bb3..45febe9 100644 (file)
@@ -62,6 +62,8 @@ public class PdpStatusMessageHandler extends PdpMessageGenerator {
 
     private final PdpParameters params;
 
+    private final boolean savePdpStatistics;
+
     /**
      * List to store policies present in db.
      */
@@ -82,9 +84,10 @@ public class PdpStatusMessageHandler extends PdpMessageGenerator {
      *
      * @param params PDP parameters
      */
-    public PdpStatusMessageHandler(PdpParameters params) {
+    public PdpStatusMessageHandler(PdpParameters params, boolean savePdpStatistics) {
         super(true);
         this.params = params;
+        this.savePdpStatistics = savePdpStatistics;
     }
 
     /**
@@ -286,12 +289,10 @@ public class PdpStatusMessageHandler extends PdpMessageGenerator {
             LOGGER.debug("PdpInstance details are correct. Saving current state in DB - {}", pdpInstance);
             updatePdpHealthStatus(message, pdpSubGroup, pdpInstance, pdpGroup, databaseProvider);
 
-            if (validatePdpStatisticsDetails(message, pdpInstance, pdpGroup, pdpSubGroup)) {
-                LOGGER.debug("PdpStatistics details are correct. Saving current statistics in DB - {}",
-                        message.getStatistics());
-                createPdpStatistics(message.getStatistics(), databaseProvider);
+            if (savePdpStatistics) {
+                processPdpStatistics(message, pdpSubGroup, pdpInstance, pdpGroup, databaseProvider);
             } else {
-                LOGGER.debug("PdpStatistics details are not correct - {}", message.getStatistics());
+                LOGGER.debug("Not processing PdpStatistics - {}", message.getStatistics());
             }
         } else {
             LOGGER.debug("PdpInstance details are not correct. Sending PdpUpdate message - {}", pdpInstance);
@@ -303,6 +304,17 @@ public class PdpStatusMessageHandler extends PdpMessageGenerator {
         }
     }
 
+    private void processPdpStatistics(final PdpStatus message, final PdpSubGroup pdpSubGroup, final Pdp pdpInstance,
+                    final PdpGroup pdpGroup, final PolicyModelsProvider databaseProvider) throws PfModelException {
+        if (validatePdpStatisticsDetails(message, pdpInstance, pdpGroup, pdpSubGroup)) {
+            LOGGER.debug("PdpStatistics details are correct. Saving current statistics in DB - {}",
+                    message.getStatistics());
+            createPdpStatistics(message.getStatistics(), databaseProvider);
+        } else {
+            LOGGER.debug("PdpStatistics details are not correct - {}", message.getStatistics());
+        }
+    }
+
     private void processPdpTermination(final PdpSubGroup pdpSubGroup, final Pdp pdpInstance, final PdpGroup pdpGroup,
             final PolicyModelsProvider databaseProvider) throws PfModelException {
         pdpSubGroup.getPdpInstances().remove(pdpInstance);
index f794345..2078bbf 100644 (file)
@@ -2,6 +2,7 @@
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
  *  Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property.
+ *  Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -47,6 +48,7 @@ public class PapParameterGroup extends ParameterGroupImpl {
     private PdpParameters pdpParameters;
     @Valid
     private PolicyModelsProviderParameters databaseProviderParameters;
+    private boolean savePdpStatisticsInDb;
     @Valid
     private TopicParameterGroup topicParameterGroup;
     // API, Distribution Health Check restClient parameters.
index 65e3dc1..4cf5ace 100644 (file)
@@ -3,6 +3,7 @@
  * ONAP PAP
  * ================================================================================
  * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -46,6 +47,7 @@ public class PdpModifyRequestMapParams {
     private TimerManager stateChangeTimers;
     private PolicyModelsProviderFactoryWrapper daoFactory;
     private PolicyNotifier policyNotifier;
+    private boolean savePdpStatistics;
 
     /**
      * Validates the parameters.
index ed73c3e..617275b 100644 (file)
@@ -2,6 +2,7 @@
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
  *  Modifications Copyright (C) 2019-2021 AT&T Intellectual Property.
+ *  Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -112,7 +113,8 @@ public class PapActivator extends ServiceManagerContainer {
             this.papParameterGroup = papParameterGroup;
             this.msgDispatcher = new MessageTypeDispatcher(MSG_TYPE_NAMES);
             this.reqIdDispatcher = new RequestIdDispatcher<>(PdpStatus.class, REQ_ID_NAMES);
-            this.pdpHeartbeatListener = new PdpHeartbeatListener(papParameterGroup.getPdpParameters());
+            this.pdpHeartbeatListener = new PdpHeartbeatListener(papParameterGroup.getPdpParameters(),
+                            papParameterGroup.isSavePdpStatisticsInDb());
 
         } catch (final RuntimeException e) {
             throw new PolicyPapRuntimeException(e);
@@ -216,6 +218,7 @@ public class PapActivator extends ServiceManagerContainer {
                                     .responseDispatcher(reqIdDispatcher)
                                     .stateChangeTimers(pdpStChgTimers.get())
                                     .updateTimers(pdpUpdTimers.get())
+                                    .savePdpStatistics(papParameterGroup.isSavePdpStatisticsInDb())
                                     .build()));
                 Registry.register(PapConstants.REG_PDP_MODIFY_MAP, requestMap.get());
 
index 31d4af4..2344c4f 100644 (file)
@@ -2,6 +2,7 @@
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019-2021 Nordix Foundation.
  *  Modifications Copyright (C) 2020-2021 AT&T Intellectual Property.
+ *  Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -69,7 +70,7 @@ public class PdpHeartbeatListenerTest extends End2EndBase {
     @Test
     public void testPdpHeartbeatListener() throws CoderException, PfModelException {
         addGroups("PdpGroups.json");
-        pdpHeartbeatListener = new PdpHeartbeatListener(new PdpParameters());
+        pdpHeartbeatListener = new PdpHeartbeatListener(new PdpParameters(), true);
 
         // Testing pdp registration success case
         final PdpStatus status1 = new PdpStatus();
@@ -222,7 +223,7 @@ public class PdpHeartbeatListenerTest extends End2EndBase {
         PdpParameters params = testData.getPapParameterGroup(1).getPdpParameters();
         List<ToscaConceptIdentifier> polsUndep = policies.stream().map(ToscaPolicy::getIdentifier)
                 .collect(Collectors.toList());
-        PdpStatusMessageHandler handler = new PdpStatusMessageHandler(params);
+        PdpStatusMessageHandler handler = new PdpStatusMessageHandler(params, true);
         PdpUpdate update10 = handler.createPdpUpdateMessage(
                 status3.getPdpGroup(), new PdpSubGroup(), "pdp_2",
                 policies, polsUndep);
@@ -234,7 +235,7 @@ public class PdpHeartbeatListenerTest extends End2EndBase {
     @Test
     public void testPdpStatistics() throws CoderException, PfModelException, ParseException {
         addGroups("PdpGroups.json");
-        pdpHeartbeatListener = new PdpHeartbeatListener(new PdpParameters());
+        pdpHeartbeatListener = new PdpHeartbeatListener(new PdpParameters(), true);
         timeStamp = Instant.parse("2021-02-12T17:48:01.029211400Z");
 
         // init default pdp group
@@ -345,6 +346,30 @@ public class PdpHeartbeatListenerTest extends End2EndBase {
 
         pdpHeartbeatListener.onTopicEvent(INFRA, TOPIC, status5);
         verifyPdpStatistics(null, DEFAULT_GROUP, null, 1);
+
+        // Test pdp statistics save disabled case, sending valid pdp status but count should still remain 1
+        pdpHeartbeatListener = new PdpHeartbeatListener(new PdpParameters(), false);
+        timeStamp = Instant.parse("2021-02-12T17:48:05.029211400Z");
+        final PdpStatus status7 = new PdpStatus();
+        status7.setName(PDP_NAME);
+        status7.setState(PdpState.ACTIVE);
+        status7.setPdpGroup(DEFAULT_GROUP);
+        status7.setPdpType(APEX_TYPE);
+        status7.setHealthy(PdpHealthStatus.HEALTHY);
+        status7.setPdpSubgroup(APEX_TYPE);
+        final List<ToscaConceptIdentifier> idents7 =
+                Arrays.asList(new ToscaConceptIdentifier(POLICY_NAME, POLICY_VERSION));
+        status7.setPolicies(idents7);
+
+        PdpStatistics pdpStatistics07 = new PdpStatistics();
+        pdpStatistics07.setPdpInstanceId(PDP_NAME);
+        pdpStatistics07.setPdpGroupName(DEFAULT_GROUP);
+        pdpStatistics07.setPdpSubGroupName(APEX_TYPE);
+        pdpStatistics07.setTimeStamp(timeStamp);
+        status7.setStatistics(pdpStatistics07);
+        pdpHeartbeatListener.onTopicEvent(INFRA, TOPIC, status7);
+        verifyPdpStatistics(PDP_NAME, DEFAULT_GROUP, null, 1);
+
     }
 
     private void verifyPdpGroup(final String name, final int count) throws PfModelException {
index 0c23006..1e4457f 100644 (file)
@@ -26,6 +26,7 @@
         "databasePassword": "P01icY",
         "persistenceUnit": "PdpGroupTest"
     },
+    "savePdpStatisticsInDb": true,
     "topicParameterGroup": {
         "topicSources" : [{
             "topic" : "POLICY-PDP-PAP",
index c9eb3a3..452bc9a 100644 (file)
@@ -27,6 +27,7 @@
         "databasePassword": "UDAxaWNZ",
         "persistenceUnit": "ToscaConceptTest"
     },
+    "savePdpStatisticsInDb": true,
     "topicParameterGroup": {
         "topicSources" : [{
             "topic" : "POLICY-PDP-PAP",
index 211ab4e..0868aa4 100644 (file)
@@ -28,6 +28,7 @@
         "databasePassword": "UDAxaWNZ",
         "persistenceUnit": "ToscaConceptTest"
     },
+    "savePdpStatisticsInDb": true,
     "topicParameterGroup": {
         "topicSources" : [{
             "topic" : "POLICY-PDP-PAP",
index f0bee8a..2f37cb6 100644 (file)
@@ -28,6 +28,7 @@
         "databasePassword": "policy_user",
         "persistenceUnit": "PolicyMariaDb"
     },
+    "savePdpStatisticsInDb": true,
     "topicParameterGroup": {
         "topicSources" : [{
             "topic" : "POLICY-PDP-PAP",
diff --git a/packages/policy-pap-tarball/src/main/resources/etc/s3pConfig.json b/packages/policy-pap-tarball/src/main/resources/etc/s3pConfig.json
deleted file mode 100644 (file)
index cc06793..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-{
-    "name": "PapGroup",
-    "restServerParameters": {
-        "host": "0.0.0.0",
-        "port": 6969,
-        "userName": "healthcheck",
-        "password": "zb!XztG34",
-        "https": true,
-        "aaf": false
-    },
-    "topicParameterGroup": {
-        "topicSources" : [{
-            "topic" : "POLICY-PDP-PAP",
-            "servers" : [ "message-router" ],
-            "topicCommInfrastructure" : "dmaap"
-        }],
-        "topicSinks" : [{
-            "topic" : "POLICY-PDP-PAP",
-            "servers" : [ "message-router" ],
-            "topicCommInfrastructure" : "dmaap"
-        }]
-    }
-}
\ No newline at end of file