aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2021-08-06 16:57:45 -0400
committerJorge Hernandez <jorge.hernandez-herrero@att.com>2021-08-07 19:57:09 +0000
commit2670cce1b59839033aa233d72e51f0f31cc4b6e1 (patch)
treeffc40a715dcd892d2377fdd5606ce905ff9f0161
parentc640bfeee6bb9f8062704acc151dc63377963bc6 (diff)
Leave xacml-pdp REST server always running
Liveness checks depend on the xacml-pdp REST server being available. However, the REST server is only running when PAP puts it in an active state. Modified the code to always leave it running. In a subsequent review, we should split the healthcheck REST service onto its own port so it can be left running, while the other services are started/stopped in response to PAP active/passive requests. Issue-ID: POLICY-3531 Change-Id: I412064abaf91bb966d40adc46cee771b3a0a5dfc Signed-off-by: Jim Hahn <jrh3@att.com> (cherry picked from commit 031a0fe51dff21445034befc8a6d8732622acd07)
-rw-r--r--main/src/main/java/org/onap/policy/pdpx/main/XacmlState.java27
-rw-r--r--main/src/main/java/org/onap/policy/pdpx/main/startstop/XacmlPdpActivator.java5
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/XacmlStateTest.java3
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/startstop/TestXacmlPdpActivator.java32
4 files changed, 20 insertions, 47 deletions
diff --git a/main/src/main/java/org/onap/policy/pdpx/main/XacmlState.java b/main/src/main/java/org/onap/policy/pdpx/main/XacmlState.java
index 5ca75a62..db83b716 100644
--- a/main/src/main/java/org/onap/policy/pdpx/main/XacmlState.java
+++ b/main/src/main/java/org/onap/policy/pdpx/main/XacmlState.java
@@ -33,16 +33,11 @@ import org.onap.policy.models.pdp.enums.PdpResponseStatus;
import org.onap.policy.models.pdp.enums.PdpState;
import org.onap.policy.pdpx.main.rest.XacmlPdpApplicationManager;
import org.onap.policy.pdpx.main.startstop.XacmlPdpActivator;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* Current state of this XACML PDP.
*/
public class XacmlState {
- // The logger for this class
- private static final Logger LOGGER = LoggerFactory.getLogger(XacmlState.class);
-
/**
* The application manager.
*/
@@ -107,9 +102,6 @@ public class XacmlState {
PdpStatus status2 = makeResponse(message, "");
- // start/stop rest controller based on state change
- handleXacmlRestController();
-
// these fields aren't needed in the response, so clear them out to avoid sending
status2.setPolicies(null);
@@ -162,23 +154,4 @@ public class XacmlState {
status2.setResponse(resp);
return status2;
}
-
- /**
- * Manages the Xacml-Pdp rest controller based on the Xacml-Pdp State.
- * Current supported states:
- * ACTIVE - rest service is running and handling requests
- * PASSIVE - rest service is not running
- */
- private void handleXacmlRestController() {
- if (status.getState() == PdpState.ACTIVE) {
- LOGGER.info("State change: {} - Starting rest controller", status.getState());
- XacmlPdpActivator.getCurrent().startXacmlRestController();
- } else if (status.getState() == PdpState.PASSIVE) {
- LOGGER.info("State change: {} - Stopping rest controller", status.getState());
- XacmlPdpActivator.getCurrent().stopXacmlRestController();
- } else {
- // unsupported state
- LOGGER.warn("Unsupported state: {}", status.getState());
- }
- }
}
diff --git a/main/src/main/java/org/onap/policy/pdpx/main/startstop/XacmlPdpActivator.java b/main/src/main/java/org/onap/policy/pdpx/main/startstop/XacmlPdpActivator.java
index 0a32d234..6e596999 100644
--- a/main/src/main/java/org/onap/policy/pdpx/main/startstop/XacmlPdpActivator.java
+++ b/main/src/main/java/org/onap/policy/pdpx/main/startstop/XacmlPdpActivator.java
@@ -139,11 +139,16 @@ public class XacmlPdpActivator extends ServiceManagerContainer {
addAction("Terminate PDP",
() -> { },
() -> sendTerminateMessage(sinkClient, state));
+
// initial heart beats act as registration messages
addAction("Heartbeat Publisher",
heartbeat::start,
heartbeat::terminate);
+ addAction("REST Server",
+ restServer::start,
+ restServer::stop);
+
// @formatter:on
}
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/XacmlStateTest.java b/main/src/test/java/org/onap/policy/pdpx/main/XacmlStateTest.java
index 43ccab04..5fdc264e 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/XacmlStateTest.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/XacmlStateTest.java
@@ -26,7 +26,6 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.junit.AfterClass;
@@ -131,12 +130,10 @@ public class XacmlStateTest {
req.setState(PdpState.ACTIVE);
status = state.updateInternalState(req);
assertEquals(PdpState.ACTIVE, status.getState());
- verify(act).startXacmlRestController();
req.setState(PdpState.PASSIVE);
status = state.updateInternalState(req);
assertEquals(PdpState.PASSIVE, status.getState());
- verify(act).stopXacmlRestController();
}
@Test
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestXacmlPdpActivator.java b/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestXacmlPdpActivator.java
index bb814d37..4286ccf5 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestXacmlPdpActivator.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestXacmlPdpActivator.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -70,6 +70,17 @@ public class TestXacmlPdpActivator extends CommonRest {
activator = new XacmlPdpActivator(parGroup);
}
+ /**
+ * Teardown tests.
+ * @throws PolicyXacmlPdpException on termination errors
+ */
+ @After
+ public void teardown() throws PolicyXacmlPdpException {
+ if (activator != null && activator.isAlive()) {
+ activator.stop();
+ }
+ }
+
@Test
public void testXacmlPdpActivator() throws Exception {
assertFalse(activator.isAlive());
@@ -77,17 +88,15 @@ public class TestXacmlPdpActivator extends CommonRest {
activator.start();
assertTrue(activator.isAlive());
- // XacmlPdp starts in PASSIVE state so the rest controller should not be alive
- assertFalse(activator.isXacmlRestControllerAlive());
assertTrue(activator.getParameterGroup().isValid());
assertEquals(CommonTestData.PDPX_PARAMETER_GROUP_NAME, activator.getParameterGroup().getName());
assertEquals(CommonTestData.PDPX_GROUP, activator.getParameterGroup().getPdpGroup());
- activator.startXacmlRestController();
- assertTrue(activator.isXacmlRestControllerAlive());
-
activator.stopXacmlRestController();
assertFalse(activator.isXacmlRestControllerAlive());
+
+ activator.startXacmlRestController();
+ assertTrue(activator.isXacmlRestControllerAlive());
}
@Test
@@ -102,15 +111,4 @@ public class TestXacmlPdpActivator extends CommonRest {
activator.stop();
assertFalse(activator.isAlive());
}
-
- /**
- * Teardown tests.
- * @throws PolicyXacmlPdpException on termination errors
- */
- @After
- public void teardown() throws PolicyXacmlPdpException {
- if (activator != null && activator.isAlive()) {
- activator.stop();
- }
- }
}