summaryrefslogtreecommitdiffstats
path: root/services/services-onappf/src/main
diff options
context:
space:
mode:
authora.sreekumar <ajith.sreekumar@est.tech>2019-08-08 08:57:34 +0000
committera.sreekumar <ajith.sreekumar@est.tech>2019-08-08 08:57:34 +0000
commitd7f9574986345d5a3eafe097c1c2afd15fb8930c (patch)
treee3598f05eb5abfefa05c97aced4d1fec91aec4ff /services/services-onappf/src/main
parentd7a0af78ec30aee100043816d382bb27eeb700e5 (diff)
Change to fix PDP-A incorrectly going into ACTIVE state even during APEX engine failure
PDP-A goes to ACTIVE state even when the APEX engine failed to start. This is fixed. Change-Id: Iad4b45abf257f68267dd2526a624dc6d882c84af Issue-ID: POLICY-1980 Signed-off-by: a.sreekumar <ajith.sreekumar@est.tech>
Diffstat (limited to 'services/services-onappf/src/main')
-rw-r--r--services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/ApexEngineHandler.java2
-rw-r--r--services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpStateChangeMessageHandler.java10
-rw-r--r--services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpUpdateMessageHandler.java58
3 files changed, 46 insertions, 24 deletions
diff --git a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/ApexEngineHandler.java b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/ApexEngineHandler.java
index 699f26c66..4f68b90ae 100644
--- a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/ApexEngineHandler.java
+++ b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/ApexEngineHandler.java
@@ -96,7 +96,7 @@ public class ApexEngineHandler {
* Method to check whether the apex engine is running or not.
*/
public boolean isApexEngineRunning() {
- return null != apexMain;
+ return null != apexMain && apexMain.isAlive();
}
/**
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 495bceccd..8658150c0 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
@@ -21,7 +21,6 @@
package org.onap.policy.apex.services.onappf.handler;
import java.util.List;
-
import org.onap.policy.apex.services.onappf.ApexStarterConstants;
import org.onap.policy.apex.services.onappf.comm.PdpStatusPublisher;
import org.onap.policy.apex.services.onappf.exception.ApexStarterException;
@@ -99,9 +98,14 @@ public class PdpStateChangeMessageHandler {
final ApexEngineHandler apexEngineHandler =
new ApexEngineHandler(policies.get(0).getProperties().get("content"));
Registry.registerOrReplace(ApexStarterConstants.REG_APEX_ENGINE_HANDLER, apexEngineHandler);
- pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpStateChangeMsg.getRequestId(),
+ if (apexEngineHandler.isApexEngineRunning()) {
+ pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpStateChangeMsg.getRequestId(),
PdpResponseStatus.SUCCESS, "Apex engine started. State changed to active.");
- pdpStatusContext.setState(PdpState.ACTIVE);
+ pdpStatusContext.setState(PdpState.ACTIVE);
+ } else {
+ pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpStateChangeMsg.getRequestId(),
+ PdpResponseStatus.FAIL, "Apex engine failed to start. State cannot be changed to active.");
+ }
} catch (final ApexStarterException e) {
LOGGER.error("Pdp update failed as the policies couldn't be undeployed.", e);
pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpStateChangeMsg.getRequestId(),
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 64d465784..d807dc50e 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
@@ -21,7 +21,6 @@
package org.onap.policy.apex.services.onappf.handler;
import java.util.List;
-
import org.onap.policy.apex.services.onappf.ApexStarterConstants;
import org.onap.policy.apex.services.onappf.comm.PdpStatusPublisher;
import org.onap.policy.apex.services.onappf.exception.ApexStarterException;
@@ -106,30 +105,49 @@ public class PdpUpdateMessageHandler {
LOGGER.debug("ApenEngineHandler not in registry.", e);
}
if (pdpUpdateMsg.getPolicies().isEmpty()) {
- if (null != apexEngineHandler && apexEngineHandler.isApexEngineRunning()) {
- try {
- apexEngineHandler.shutdown();
- } catch (final ApexStarterException e) {
- LOGGER.error("Pdp update failed as the policies couldn't be undeployed.", e);
- pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
- PdpResponseStatus.FAIL, "Pdp update failed as the policies couldn't be undeployed.");
- }
- }
+ pdpResponseDetails = stopApexEngineBasedOnPolicies(pdpUpdateMsg, pdpMessageHandler, apexEngineHandler);
} else {
+ pdpResponseDetails = startApexEngineBasedOnPolicies(pdpUpdateMsg, pdpMessageHandler, apexEngineHandler);
+ }
+ return pdpResponseDetails;
+ }
+
+ private PdpResponseDetails stopApexEngineBasedOnPolicies(final PdpUpdate pdpUpdateMsg,
+ final PdpMessageHandler pdpMessageHandler, ApexEngineHandler apexEngineHandler) {
+ PdpResponseDetails pdpResponseDetails = null;
+ if (null != apexEngineHandler && apexEngineHandler.isApexEngineRunning()) {
try {
- if (null != apexEngineHandler && apexEngineHandler.isApexEngineRunning()) {
- apexEngineHandler.shutdown();
- }
- apexEngineHandler =
- new ApexEngineHandler(pdpUpdateMsg.getPolicies().get(0).getProperties().get("content"));
- Registry.registerOrReplace(ApexStarterConstants.REG_APEX_ENGINE_HANDLER, apexEngineHandler);
- pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
- PdpResponseStatus.SUCCESS, "Apex engine started and policies are running.");
+ apexEngineHandler.shutdown();
} catch (final ApexStarterException e) {
- LOGGER.error("Apex engine service running failed. ", e);
+ LOGGER.error("Pdp update failed as the policies couldn't be undeployed.", e);
+ pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
+ PdpResponseStatus.FAIL, "Pdp update failed as the policies couldn't be undeployed.");
+ }
+ }
+ return pdpResponseDetails;
+ }
+
+ private PdpResponseDetails startApexEngineBasedOnPolicies(final PdpUpdate pdpUpdateMsg,
+ final PdpMessageHandler pdpMessageHandler, ApexEngineHandler apexEngineHandler) {
+ PdpResponseDetails pdpResponseDetails = null;
+ try {
+ if (null != apexEngineHandler && apexEngineHandler.isApexEngineRunning()) {
+ apexEngineHandler.shutdown();
+ }
+ apexEngineHandler =
+ new ApexEngineHandler(pdpUpdateMsg.getPolicies().get(0).getProperties().get("content"));
+ Registry.registerOrReplace(ApexStarterConstants.REG_APEX_ENGINE_HANDLER, apexEngineHandler);
+ if (apexEngineHandler.isApexEngineRunning()) {
+ pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
+ PdpResponseStatus.SUCCESS, "Apex engine started and policies are running.");
+ } else {
pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
- PdpResponseStatus.FAIL, "Apex engine service running failed. " + e.getMessage());
+ PdpResponseStatus.FAIL, "Apex engine failed to start.");
}
+ } catch (final ApexStarterException e) {
+ LOGGER.error("Apex engine service running failed. ", e);
+ pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
+ PdpResponseStatus.FAIL, "Apex engine service running failed. " + e.getMessage());
}
return pdpResponseDetails;
}