Added code to send Termination message to PAP 62/86662/5
authorMichael Mokry <michael.mokry@att.com>
Tue, 30 Apr 2019 18:04:12 +0000 (13:04 -0500)
committerMichael Mokry <michael.mokry@att.com>
Wed, 1 May 2019 00:44:34 +0000 (19:44 -0500)
Fixed checkstyle issues
Made changes to include PdpGroup and PdpSubGroup in termination message

Change-Id: I772404adbbe9be18001554616eb0c935317bdaba
Issue-ID: POLICY-1645
Signed-off-by: Michael Mokry <michael.mokry@att.com>
main/src/main/java/org/onap/policy/pdpx/main/XacmlState.java
main/src/main/java/org/onap/policy/pdpx/main/startstop/XacmlPdpActivator.java

index 521413c..f672ccd 100644 (file)
@@ -124,6 +124,16 @@ public class XacmlState {
         return makeResponse(message);
     }
 
+    /**
+     * Updates the internal state to Terminated.
+     *
+     * @return the current PdpStatus with Terminated state
+     */
+    public PdpStatus terminatePdpMessage() {
+        status.setState(PdpState.TERMINATED);
+        return status;
+    }
+
     /**
      * Makes a response to the given message, based on the current state.
      *
index 2a881d4..e763367 100644 (file)
@@ -22,6 +22,7 @@ package org.onap.policy.pdpx.main.startstop;
 
 import java.nio.file.Paths;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.Properties;
 import lombok.Getter;
 import lombok.Setter;
@@ -31,9 +32,11 @@ import org.onap.policy.common.endpoints.event.comm.client.TopicSinkClient;
 import org.onap.policy.common.endpoints.event.comm.client.TopicSinkClientException;
 import org.onap.policy.common.endpoints.listeners.MessageTypeDispatcher;
 import org.onap.policy.common.parameters.ParameterService;
+import org.onap.policy.common.utils.network.NetworkUtil;
 import org.onap.policy.common.utils.services.ServiceManagerContainer;
 import org.onap.policy.models.pdp.concepts.PdpStatus;
 import org.onap.policy.models.pdp.enums.PdpMessageType;
+import org.onap.policy.models.pdp.enums.PdpState;
 import org.onap.policy.pdpx.main.PolicyXacmlPdpRuntimeException;
 import org.onap.policy.pdpx.main.XacmlState;
 import org.onap.policy.pdpx.main.comm.XacmlPdpHearbeatPublisher;
@@ -89,6 +92,8 @@ public class XacmlPdpActivator extends ServiceManagerContainer {
         TopicEndpoint.manager.addTopicSources(topicProperties);
 
         XacmlPdpHearbeatPublisher heartbeat;
+        TopicSinkClient sinkClient;
+        final XacmlState state;
 
         try {
             XacmlPdpApplicationManager appmgr =
@@ -99,12 +104,12 @@ public class XacmlPdpActivator extends ServiceManagerContainer {
             XacmlPdpStatisticsManager.setCurrent(stats);
             stats.setTotalPolicyTypesCount(appmgr.getPolicyTypeCount());
 
-            XacmlState state = new XacmlState(appmgr);
+            state = new XacmlState(appmgr);
 
             this.xacmlPdpParameterGroup = xacmlPdpParameterGroup;
             this.msgDispatcher = new MessageTypeDispatcher(MSG_TYPE_NAMES);
 
-            TopicSinkClient sinkClient = new TopicSinkClient(TOPIC);
+            sinkClient = new TopicSinkClient(TOPIC);
             heartbeat = new XacmlPdpHearbeatPublisher(sinkClient, state);
 
             /*
@@ -135,6 +140,9 @@ public class XacmlPdpActivator extends ServiceManagerContainer {
             TopicEndpoint.manager::start,
             TopicEndpoint.manager::shutdown);
 
+        addAction("Terminate PDP",
+            () -> { },
+            () -> sendTerminateMessage(sinkClient, state));
         // initial heart beats act as registration messages
         addAction("Heartbeat Publisher",
             heartbeat::start,
@@ -147,9 +155,18 @@ public class XacmlPdpActivator extends ServiceManagerContainer {
         addAction("REST server",
             () -> restServer.start(),
             () -> restServer.stop());
+
         // @formatter:on
     }
 
+    /*
+     * Method used to send a terminate message to the PAP.
+     */
+    private void sendTerminateMessage(TopicSinkClient sinkClient, XacmlState state) {
+        PdpStatus terminateStatus = state.terminatePdpMessage();
+        sinkClient.send(terminateStatus);
+    }
+
     /**
      * Get the parameters used by the activator.
      *