Leave xacml-pdp REST server always running
[policy/xacml-pdp.git] / main / src / main / java / org / onap / policy / pdpx / main / XacmlState.java
index 8ec5ed2..0b6f30c 100644 (file)
@@ -33,15 +33,15 @@ 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);
+    /**
+     * Unique name for the xacml-pdp JVM, used in PdpStatus messages.
+     */
+    public static final String PDP_NAME = NetworkUtil.genUniqueName("xacml");
 
     /**
      * The application manager.
@@ -60,7 +60,7 @@ public class XacmlState {
         this.appManager = appManager;
 
         this.status = new PdpStatus();
-        this.status.setName(NetworkUtil.getHostname());
+        this.status.setName(PDP_NAME);
         this.status.setPdpType(pdpType);
         this.status.setState(PdpState.PASSIVE);
         this.status.setPolicies(Collections.emptyList());
@@ -107,9 +107,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 +159,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());
-        }
-    }
 }