From d2be27372c1e3efb76e2edd648bcfab8945ea51f Mon Sep 17 00:00:00 2001 From: Rashmi Pujar Date: Thu, 31 Mar 2022 11:52:53 -0400 Subject: 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 Change-Id: I4d875ff288cf8c242a1851eb105e56dc69b97883 --- .../onappf/handler/PdpUpdateMessageHandler.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'services/services-onappf/src/main/java/org') 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 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 runningPolicies = null; + List 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 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)); } } } -- cgit 1.2.3-korg