From f6da9a3bafb6f4c30e7bb3accd4e17fdaaf5ce92 Mon Sep 17 00:00:00 2001 From: "a.sreekumar" Date: Thu, 25 Apr 2019 12:29:06 +0000 Subject: Changes to fix PDP-A not going to ACTIVE state PDP-A state will now change to ACTIVE even when the policy list is empty. When the state is ACTIVE and PAP sends a PDP_UPDATE with policies, PDP-A will start executing the policies. Change-Id: Icb5b139939698920d4fa3991dcca33536c6caefc Issue-ID: POLICY-1674 Signed-off-by: a.sreekumar --- .../onappf/handler/PdpStateChangeMessageHandler.java | 14 +++++++++++--- .../services/onappf/handler/PdpUpdateMessageHandler.java | 12 ++++++++---- 2 files changed, 19 insertions(+), 7 deletions(-) (limited to 'services/services-onappf/src/main') diff --git a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpStateChangeMessageHandler.java b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpStateChangeMessageHandler.java index d2c7786ca..9c53fb196 100644 --- a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpStateChangeMessageHandler.java +++ b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpStateChangeMessageHandler.java @@ -90,8 +90,9 @@ public class PdpStateChangeMessageHandler { } else { final List policies = Registry.get(ApexStarterConstants.REG_APEX_TOSCA_POLICY_LIST); if (policies.isEmpty()) { + pdpStatusContext.setState(PdpState.ACTIVE); pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpStateChangeMsg.getRequestId(), - PdpResponseStatus.SUCCESS, "No policies found. Apex engine not running."); + PdpResponseStatus.SUCCESS, "State changed to active. No policies found."); } else { try { // assumed that the apex policies list contains only one entry. @@ -126,9 +127,16 @@ public class PdpStateChangeMessageHandler { pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpStateChangeMsg.getRequestId(), PdpResponseStatus.SUCCESS, "Pdp already in passive state"); } else { - final ApexEngineHandler apexEngineHandler = Registry.get(ApexStarterConstants.REG_APEX_ENGINE_HANDLER); + ApexEngineHandler apexEngineHandler = null; try { - apexEngineHandler.shutdown(); + apexEngineHandler = Registry.get(ApexStarterConstants.REG_APEX_ENGINE_HANDLER); + } catch (final IllegalArgumentException e) { + LOGGER.debug("ApenEngineHandler not in registry.", e); + } + try { + if (null != apexEngineHandler && apexEngineHandler.isApexEngineRunning()) { + apexEngineHandler.shutdown(); + } pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpStateChangeMsg.getRequestId(), PdpResponseStatus.SUCCESS, "Apex pdp state changed from Active to Passive."); pdpStatusContext.setState(PdpState.PASSIVE); 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 31963ddc0..478d1c757 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 @@ -99,9 +99,14 @@ public class PdpUpdateMessageHandler { private PdpResponseDetails startOrStopApexEngineBasedOnPolicies(final PdpUpdate pdpUpdateMsg, final PdpMessageHandler pdpMessageHandler) { PdpResponseDetails pdpResponseDetails = null; + ApexEngineHandler apexEngineHandler = null; + try { + apexEngineHandler = Registry.get(ApexStarterConstants.REG_APEX_ENGINE_HANDLER); + } catch (final IllegalArgumentException e) { + LOGGER.debug("ApenEngineHandler not in registry.", e); + } if (pdpUpdateMsg.getPolicies().isEmpty()) { - final ApexEngineHandler apexEngineHandler = Registry.get(ApexStarterConstants.REG_APEX_ENGINE_HANDLER); - if (apexEngineHandler.isApexEngineRunning()) { + if (null != apexEngineHandler && apexEngineHandler.isApexEngineRunning()) { try { apexEngineHandler.shutdown(); } catch (final ApexStarterException e) { @@ -112,8 +117,7 @@ public class PdpUpdateMessageHandler { } } else { try { - ApexEngineHandler apexEngineHandler = Registry.get(ApexStarterConstants.REG_APEX_ENGINE_HANDLER); - if (apexEngineHandler.isApexEngineRunning()) { + if (null != apexEngineHandler && apexEngineHandler.isApexEngineRunning()) { apexEngineHandler.shutdown(); } apexEngineHandler = new ApexEngineHandler( -- cgit 1.2.3-korg