summaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
Diffstat (limited to 'main')
-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/PdpModifyRequestMap.java3
-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/parameters/PdpModifyRequestMapParams.java2
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java5
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/comm/PdpHeartbeatListenerTest.java31
-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
10 files changed, 65 insertions, 13 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 1a58ad96..027436a4 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-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);
}
}
diff --git a/main/src/main/java/org/onap/policy/pap/main/comm/PdpModifyRequestMap.java b/main/src/main/java/org/onap/policy/pap/main/comm/PdpModifyRequestMap.java
index bf9f290a..beef4750 100644
--- a/main/src/main/java/org/onap/policy/pap/main/comm/PdpModifyRequestMap.java
+++ b/main/src/main/java/org/onap/policy/pap/main/comm/PdpModifyRequestMap.java
@@ -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());
}
/**
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 b430bb33..45febe95 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;
}
/**
@@ -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);
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 f7943454..2078bbfe 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, 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.
diff --git a/main/src/main/java/org/onap/policy/pap/main/parameters/PdpModifyRequestMapParams.java b/main/src/main/java/org/onap/policy/pap/main/parameters/PdpModifyRequestMapParams.java
index 65e3dc11..4cf5ace8 100644
--- a/main/src/main/java/org/onap/policy/pap/main/parameters/PdpModifyRequestMapParams.java
+++ b/main/src/main/java/org/onap/policy/pap/main/parameters/PdpModifyRequestMapParams.java
@@ -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.
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 ed73c3e1..617275b4 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-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());
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 31d4af46..2344c4f3 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-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 {
diff --git a/main/src/test/resources/parameters/MinimumParameters.json b/main/src/test/resources/parameters/MinimumParameters.json
index 0c23006c..1e4457f2 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 c9eb3a3a..452bc9a7 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 211ab4e2..0868aa41 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",