summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorRashmi Pujar <rashmi.pujar1@bell.ca>2022-03-31 11:52:53 -0400
committerRashmi Pujar <rashmi.pujar1@bell.ca>2022-03-31 12:45:23 -0400
commitd2be27372c1e3efb76e2edd648bcfab8945ea51f (patch)
treed137d765090e11de35dd32972b499718bc9f0fec /services
parent6c3a6abb7e18be81284866f61a54557474e643ed (diff)
Bug fixes for APEX PDP metrics
1. APEX engine metrics were being initialized to 0 in the constructor which caused them to reset to 0. Hence, initialization is removed, and updates are done to metrics only upon: engineStart/Stop, executionEnter/Exit stages. 2. APEX engine Uptime was only updated when engine stopped, hence always 0. Also, uptime is redundant since it can be derived from lastStart timestamp and hence is removed as a metric. 3. Fixed a corner case bug which occurs when all policies are undeployed the counters are not correct. 4. Fix Unit tests Issue-ID: POLICY-4044 Signed-off-by: Rashmi Pujar <rashmi.pujar1@bell.ca> Change-Id: I4d875ff288cf8c242a1851eb105e56dc69b97883
Diffstat (limited to 'services')
-rw-r--r--services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpUpdateMessageHandler.java19
1 files changed, 10 insertions, 9 deletions
diff --git a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpUpdateMessageHandler.java b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpUpdateMessageHandler.java
index f10a0b064..1bcb8970b 100644
--- a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpUpdateMessageHandler.java
+++ b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpUpdateMessageHandler.java
@@ -162,9 +162,10 @@ public class PdpUpdateMessageHandler {
final PdpMessageHandler pdpMessageHandler, ApexEngineHandler apexEngineHandler) {
PdpResponseDetails pdpResponseDetails = null;
if (null != apexEngineHandler && apexEngineHandler.isApexEngineRunning()) {
- final var runningPolicies = apexEngineHandler.getRunningPolicies();
+ List<ToscaConceptIdentifier> runningPolicies = apexEngineHandler.getRunningPolicies();
try {
apexEngineHandler.shutdown();
+ runningPolicies = apexEngineHandler.getRunningPolicies();
pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
PdpResponseStatus.SUCCESS, "Pdp update successful. No policies are running.");
} catch (final ApexStarterException e) {
@@ -180,7 +181,7 @@ public class PdpUpdateMessageHandler {
private PdpResponseDetails startApexEngineBasedOnPolicies(final PdpUpdate pdpUpdateMsg,
final PdpMessageHandler pdpMessageHandler, ApexEngineHandler apexEngineHandler) {
PdpResponseDetails pdpResponseDetails = null;
- List<ToscaConceptIdentifier> runningPolicies = null;
+ List<ToscaConceptIdentifier> runningPolicies = new ArrayList<>();
try {
if (null != apexEngineHandler && apexEngineHandler.isApexEngineRunning()) {
apexEngineHandler.updateApexEngine(pdpUpdateMsg.getPoliciesToBeDeployed(),
@@ -296,7 +297,7 @@ public class PdpUpdateMessageHandler {
private void updateDeploymentCounts(final List<ToscaConceptIdentifier> runningPolicies,
final PdpUpdate pdpUpdateMsg) {
final var statisticsManager = ApexPolicyStatisticsManager.getInstanceFromRegistry();
- if (statisticsManager != null) {
+ if (statisticsManager != null && runningPolicies != null) {
if (pdpUpdateMsg.getPoliciesToBeDeployed() != null && !pdpUpdateMsg.getPoliciesToBeDeployed().isEmpty()) {
var policiesToDeploy = pdpUpdateMsg.getPoliciesToBeDeployed().stream()
.map(ToscaWithTypeAndObjectProperties::getIdentifier).collect(Collectors.toList());
@@ -312,13 +313,13 @@ public class PdpUpdateMessageHandler {
var policiesToUndeploy = pdpUpdateMsg.getPoliciesToBeUndeployed();
if (policiesToUndeploy != null && !policiesToUndeploy.isEmpty()) {
- var policiesSuccessfullyUndeployed = new ArrayList<>(policiesToUndeploy);
- policiesSuccessfullyUndeployed.retainAll(runningPolicies);
- policiesSuccessfullyUndeployed.forEach(policy -> statisticsManager.updatePolicyUndeployCounter(true));
-
- var policiesFailedToUndeploy = new ArrayList<>(policiesToUndeploy);
- policiesFailedToUndeploy.removeIf(runningPolicies::contains);
+ var policiesFailedToUndeploy = new ArrayList<>(policiesToUndeploy);
+ policiesFailedToUndeploy.retainAll(runningPolicies);
policiesFailedToUndeploy.forEach(policy -> statisticsManager.updatePolicyUndeployCounter(false));
+
+ var policiesSuccessfullyUndeployed = new ArrayList<>(policiesToUndeploy);
+ policiesSuccessfullyUndeployed.removeIf(runningPolicies::contains);
+ policiesSuccessfullyUndeployed.forEach(policy -> statisticsManager.updatePolicyUndeployCounter(true));
}
}
}