summaryrefslogtreecommitdiffstats
path: root/main/src
diff options
context:
space:
mode:
authorRam Krishna Verma <ram_krishna.verma@bell.ca>2021-06-29 17:01:21 -0400
committerRam Krishna Verma <ram_krishna.verma@bell.ca>2021-06-30 13:19:08 -0400
commit15d89d8bfee2a56e5db53203983f20173a4165bb (patch)
tree2775109df4094a9f40f72fd3b3fda4d94b5269a3 /main/src
parent209f0357e93fd45b859f1f854a5331461b08bd2a (diff)
Add ability to turn on/off pdp statistics
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> (cherry picked from commit 57e39b87ac53c128502110b64b06947e9e380d4e) Signed-off-by: Ram Krishna Verma <ram_krishna.verma@bell.ca>
Diffstat (limited to 'main/src')
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/comm/PdpHeartbeatListener.java8
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/comm/PdpStatusMessageHandler.java24
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/parameters/PapParameterGroup.java2
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java4
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/comm/PdpHeartbeatListenerTest.java33
-rw-r--r--main/src/test/resources/parameters/MinimumParameters.json1
-rw-r--r--main/src/test/resources/parameters/PapConfigParameters.json1
-rw-r--r--main/src/test/resources/parameters/PapConfigParametersStd.json1
8 files changed, 60 insertions, 14 deletions
diff --git a/main/src/main/java/org/onap/policy/pap/main/comm/PdpHeartbeatListener.java b/main/src/main/java/org/onap/policy/pap/main/comm/PdpHeartbeatListener.java
index 512609a4..aaca9dcc 100644
--- a/main/src/main/java/org/onap/policy/pap/main/comm/PdpHeartbeatListener.java
+++ b/main/src/main/java/org/onap/policy/pap/main/comm/PdpHeartbeatListener.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
* Modifications Copyright (C) 2020 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 PdpStatusMessageHandler handler = new PdpStatusMessageHandler(params);
+ final PdpStatusMessageHandler handler = new PdpStatusMessageHandler(params, savePdpStatistics);
handler.handlePdpStatus(message);
}
}
diff --git a/main/src/main/java/org/onap/policy/pap/main/comm/PdpStatusMessageHandler.java b/main/src/main/java/org/onap/policy/pap/main/comm/PdpStatusMessageHandler.java
index 5ec9aba0..bf5fc12a 100644
--- a/main/src/main/java/org/onap/policy/pap/main/comm/PdpStatusMessageHandler.java
+++ b/main/src/main/java/org/onap/policy/pap/main/comm/PdpStatusMessageHandler.java
@@ -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;
}
/**
@@ -249,12 +252,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);
@@ -265,6 +266,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);
diff --git a/main/src/main/java/org/onap/policy/pap/main/parameters/PapParameterGroup.java b/main/src/main/java/org/onap/policy/pap/main/parameters/PapParameterGroup.java
index 9a50cf0f..2b5e9869 100644
--- a/main/src/main/java/org/onap/policy/pap/main/parameters/PapParameterGroup.java
+++ b/main/src/main/java/org/onap/policy/pap/main/parameters/PapParameterGroup.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
* Modifications Copyright (C) 2019 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.
@@ -43,6 +44,7 @@ public class PapParameterGroup extends ParameterGroupImpl {
private RestServerParameters restServerParameters;
private PdpParameters pdpParameters;
private PolicyModelsProviderParameters databaseProviderParameters;
+ private boolean savePdpStatisticsInDb;
private TopicParameterGroup topicParameterGroup;
// API, Distribution Health Check restClient parameters.
private List<BusTopicParams> healthCheckRestClientParameters;
diff --git a/main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java b/main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java
index 4272e491..7b5c2f0e 100644
--- a/main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java
+++ b/main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
* Modifications Copyright (C) 2019-2020 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.
@@ -111,7 +112,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);
diff --git a/main/src/test/java/org/onap/policy/pap/main/comm/PdpHeartbeatListenerTest.java b/main/src/test/java/org/onap/policy/pap/main/comm/PdpHeartbeatListenerTest.java
index d2dc1955..ce34993d 100644
--- a/main/src/test/java/org/onap/policy/pap/main/comm/PdpHeartbeatListenerTest.java
+++ b/main/src/test/java/org/onap/policy/pap/main/comm/PdpHeartbeatListenerTest.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2020 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.
@@ -26,11 +27,9 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import java.text.ParseException;
-import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import org.junit.Test;
@@ -71,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();
@@ -224,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",
null, policies, policies, polsUndep);
@@ -237,7 +236,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
@@ -348,6 +347,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 {
diff --git a/main/src/test/resources/parameters/MinimumParameters.json b/main/src/test/resources/parameters/MinimumParameters.json
index 69492e9b..e479adbc 100644
--- a/main/src/test/resources/parameters/MinimumParameters.json
+++ b/main/src/test/resources/parameters/MinimumParameters.json
@@ -26,6 +26,7 @@
"databasePassword": "P01icY",
"persistenceUnit": "PdpGroupTest"
},
+ "savePdpStatisticsInDb": true,
"topicParameterGroup": {
"topicSources" : [{
"topic" : "POLICY-PDP-PAP",
diff --git a/main/src/test/resources/parameters/PapConfigParameters.json b/main/src/test/resources/parameters/PapConfigParameters.json
index 111a6352..54d72e01 100644
--- a/main/src/test/resources/parameters/PapConfigParameters.json
+++ b/main/src/test/resources/parameters/PapConfigParameters.json
@@ -27,6 +27,7 @@
"databasePassword": "UDAxaWNZ",
"persistenceUnit": "ToscaConceptTest"
},
+ "savePdpStatisticsInDb": true,
"topicParameterGroup": {
"topicSources" : [{
"topic" : "POLICY-PDP-PAP",
diff --git a/main/src/test/resources/parameters/PapConfigParametersStd.json b/main/src/test/resources/parameters/PapConfigParametersStd.json
index a11782bc..05413262 100644
--- a/main/src/test/resources/parameters/PapConfigParametersStd.json
+++ b/main/src/test/resources/parameters/PapConfigParametersStd.json
@@ -28,6 +28,7 @@
"databasePassword": "UDAxaWNZ",
"persistenceUnit": "ToscaConceptTest"
},
+ "savePdpStatisticsInDb": true,
"topicParameterGroup": {
"topicSources" : [{
"topic" : "POLICY-PDP-PAP",