Changes to fix PDP-A not going to ACTIVE state 72/86272/2
authora.sreekumar <ajith.sreekumar@est.tech>
Thu, 25 Apr 2019 12:29:06 +0000 (12:29 +0000)
committera.sreekumar <ajith.sreekumar@est.tech>
Thu, 25 Apr 2019 12:29:06 +0000 (12:29 +0000)
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 <ajith.sreekumar@est.tech>
services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpStateChangeMessageHandler.java
services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpUpdateMessageHandler.java

index d2c7786..9c53fb1 100644 (file)
@@ -90,8 +90,9 @@ public class PdpStateChangeMessageHandler {
         } else {
             final List<ToscaPolicy> 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);
index 31963dd..478d1c7 100644 (file)
@@ -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(