Use unique name in xacml-pdp PdpStatus messages 40/122340/1
authorJim Hahn <jrh3@att.com>
Mon, 28 Jun 2021 18:47:42 +0000 (14:47 -0400)
committerJim Hahn <jrh3@att.com>
Mon, 28 Jun 2021 19:39:29 +0000 (15:39 -0400)
Added unique name to PdpStatus and HealthCheckReports.

Issue-ID: POLICY-3410
Change-Id: Ife2248ffee9afae76f3eaab7f8b33dba8bdb4019
Signed-off-by: Jim Hahn <jrh3@att.com>
main/src/main/java/org/onap/policy/pdpx/main/XacmlState.java
main/src/main/java/org/onap/policy/pdpx/main/rest/provider/HealthCheckProvider.java
main/src/test/java/org/onap/policy/pdpx/main/XacmlStateTest.java
main/src/test/java/org/onap/policy/pdpx/main/rest/TestXacmlPdpRestServer.java

index 8ec5ed2..857047b 100644 (file)
@@ -43,6 +43,11 @@ 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 +65,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());
index bc79187..01c4997 100644 (file)
@@ -21,6 +21,7 @@
 package org.onap.policy.pdpx.main.rest.provider;
 
 import org.onap.policy.common.endpoints.report.HealthCheckReport;
+import org.onap.policy.pdpx.main.XacmlState;
 import org.onap.policy.pdpx.main.startstop.XacmlPdpActivator;
 
 /**
@@ -32,7 +33,6 @@ public class HealthCheckProvider {
     private static final String NOT_ALIVE = "not alive";
     private static final String ALIVE = "alive";
     private static final String URL = "self";
-    private static final String NAME = "Policy Xacml PDP";
 
     /**
      * Performs the health check of xacml pdp service.
@@ -41,7 +41,7 @@ public class HealthCheckProvider {
      */
     public HealthCheckReport performHealthCheck() {
         final var report = new HealthCheckReport();
-        report.setName(NAME);
+        report.setName(XacmlState.PDP_NAME);
         report.setUrl(URL);
 
         boolean alive = XacmlPdpActivator.getCurrent().isAlive();
index 43ccab0..5ff3d5c 100644 (file)
@@ -35,7 +35,6 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.junit.MockitoJUnitRunner;
-import org.onap.policy.common.utils.network.NetworkUtil;
 import org.onap.policy.models.pdp.concepts.PdpResponseDetails;
 import org.onap.policy.models.pdp.concepts.PdpStateChange;
 import org.onap.policy.models.pdp.concepts.PdpStatus;
@@ -59,7 +58,7 @@ public class XacmlStateTest {
     @Mock
     private XacmlPdpActivator act;
 
-    private String hostName;
+    private String pdpName;
 
     private XacmlState state;
 
@@ -68,7 +67,7 @@ public class XacmlStateTest {
      */
     @Before
     public void setUp() {
-        hostName = NetworkUtil.getHostname();
+        pdpName = XacmlState.PDP_NAME;
 
         XacmlPdpActivator.setCurrent(act);
 
@@ -85,7 +84,7 @@ public class XacmlStateTest {
         PdpUpdate msg = new PdpUpdate();
         assertFalse(state.shouldHandle(msg));
 
-        msg.setName(NetworkUtil.getHostname());
+        msg.setName(XacmlState.PDP_NAME);
         assertTrue(state.shouldHandle(msg));
     }
 
@@ -94,7 +93,7 @@ public class XacmlStateTest {
         // not healthy
         PdpStatus status = state.genHeartbeat();
         assertEquals(PdpHealthStatus.NOT_HEALTHY, status.getHealthy());
-        assertEquals(hostName, status.getName());
+        assertEquals(pdpName, status.getName());
         assertEquals(GROUP, status.getPdpGroup());
         assertEquals(PDP_TYPE, status.getPdpType());
         assertEquals(PdpState.PASSIVE, status.getState());
@@ -110,7 +109,7 @@ public class XacmlStateTest {
     @Test
     public void testUpdateInternalStatePdpStateChange() {
         PdpStateChange req = new PdpStateChange();
-        req.setName(hostName);
+        req.setName(pdpName);
         req.setPdpGroup("wrong-pdp-group");
         req.setPdpSubgroup(SUBGROUP);
         req.setState(STATE);
index 7865851..a8a7b84 100644 (file)
@@ -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.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -26,6 +26,7 @@ import javax.ws.rs.client.Invocation;
 import org.junit.Test;
 import org.onap.policy.common.endpoints.report.HealthCheckReport;
 import org.onap.policy.pdpx.main.CommonRest;
+import org.onap.policy.pdpx.main.XacmlState;
 import org.onap.policy.pdpx.main.rest.model.StatisticsReport;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -40,7 +41,7 @@ public class TestXacmlPdpRestServer extends CommonRest {
     private static final String NOT_ALIVE = "not alive";
     private static final String ALIVE = "alive";
     private static final String SELF = "self";
-    private static final String NAME = "Policy Xacml PDP";
+    private static final String NAME = XacmlState.PDP_NAME;
     private static final String HEALTHCHECK_ENDPOINT = "healthcheck";
     private static final String STATISTICS_ENDPOINT = "statistics";