diff options
4 files changed, 16 insertions, 11 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 8ec5ed2b..857047bf 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 @@ -44,6 +44,11 @@ public class XacmlState { 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. */ private final XacmlPdpApplicationManager appManager; @@ -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()); diff --git a/main/src/main/java/org/onap/policy/pdpx/main/rest/provider/HealthCheckProvider.java b/main/src/main/java/org/onap/policy/pdpx/main/rest/provider/HealthCheckProvider.java index bc791872..01c4997c 100644 --- a/main/src/main/java/org/onap/policy/pdpx/main/rest/provider/HealthCheckProvider.java +++ b/main/src/main/java/org/onap/policy/pdpx/main/rest/provider/HealthCheckProvider.java @@ -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(); 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..5ff3d5c7 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 @@ -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); diff --git a/main/src/test/java/org/onap/policy/pdpx/main/rest/TestXacmlPdpRestServer.java b/main/src/test/java/org/onap/policy/pdpx/main/rest/TestXacmlPdpRestServer.java index 7865851d..a8a7b84d 100644 --- a/main/src/test/java/org/onap/policy/pdpx/main/rest/TestXacmlPdpRestServer.java +++ b/main/src/test/java/org/onap/policy/pdpx/main/rest/TestXacmlPdpRestServer.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. * ================================================================================ * 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"; |