From 4d4547ee4b3a6be75cf2c01f3065b129fddcfd3b Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Mon, 28 Jun 2021 15:04:36 -0400 Subject: Use unique name in drools PdpMessages Also modified distributed locking to use the unique name, in case the DB is shared. Issue-ID: POLICY-3410 Change-Id: I046a9ffdcb62f3d84d7d388a1e64bcf025fbbf75 Signed-off-by: Jim Hahn --- .../distributed/locking/DistributedLockManager.java | 19 +++++++++---------- .../locking/DistributedLockManagerTest.java | 10 +++++----- .../onap/policy/drools/lifecycle/LifecycleFsm.java | 5 ++--- .../policy/drools/lifecycle/LifecycleFsmTest.java | 4 ++-- .../drools/lifecycle/LifecycleFsmUpdateTest.java | 4 ++-- .../lifecycle/LifecycleStateActivePoliciesTest.java | 6 +++--- .../drools/lifecycle/LifecycleStateActiveTest.java | 4 ++-- .../drools/lifecycle/LifecycleStatePassiveTest.java | 8 ++++---- .../lifecycle/LifecycleStateTerminatedTest.java | 8 ++++---- .../policy/drools/system/PolicyEngineConstants.java | 10 ++++++++-- 10 files changed, 41 insertions(+), 37 deletions(-) diff --git a/feature-distributed-locking/src/main/java/org/onap/policy/distributed/locking/DistributedLockManager.java b/feature-distributed-locking/src/main/java/org/onap/policy/distributed/locking/DistributedLockManager.java index c114d26a..93a63754 100644 --- a/feature-distributed-locking/src/main/java/org/onap/policy/distributed/locking/DistributedLockManager.java +++ b/feature-distributed-locking/src/main/java/org/onap/policy/distributed/locking/DistributedLockManager.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2019-2020 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. @@ -41,7 +41,6 @@ import lombok.Getter; import lombok.Setter; import org.apache.commons.dbcp2.BasicDataSource; import org.apache.commons.dbcp2.BasicDataSourceFactory; -import org.onap.policy.common.utils.network.NetworkUtil; import org.onap.policy.drools.core.lock.LockCallback; import org.onap.policy.drools.core.lock.LockState; import org.onap.policy.drools.core.lock.PolicyResourceLockManager; @@ -94,7 +93,7 @@ public class DistributedLockManager extends LockManager now()")) { // @formatter:on - stmt.setString(1, hostName); + stmt.setString(1, pdpName); stmt.setString(2, uuidString); try (ResultSet resultSet = stmt.executeQuery()) { @@ -415,7 +414,7 @@ public class DistributedLockManager extends LockManager policiesToDeploy, List policiesToUndeploy) { PdpUpdate update = new PdpUpdate(); - update.setName(NetworkUtil.getHostname()); + update.setName(PolicyEngineConstants.PDP_NAME); update.setPdpGroup("A"); update.setPdpSubgroup("a"); update.setPoliciesToBeDeployed(policiesToDeploy); diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActivePoliciesTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActivePoliciesTest.java index b56d21fa..f37e8ef7 100644 --- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActivePoliciesTest.java +++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActivePoliciesTest.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -40,7 +40,7 @@ import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager; import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; -import org.onap.policy.common.utils.network.NetworkUtil; +import org.onap.policy.drools.system.PolicyEngineConstants; import org.onap.policy.models.pdp.concepts.PdpStateChange; import org.onap.policy.models.pdp.concepts.PdpUpdate; import org.onap.policy.models.pdp.enums.PdpState; @@ -116,7 +116,7 @@ public class LifecycleStateActivePoliciesTest extends LifecycleStateRunningTest getPolicyFromFile(EXAMPLE_NATIVE_DROOLS_POLICY_JSON, EXAMPLE_NATIVE_DROOLS_CONTROLLER_POLICY_NAME); PdpUpdate update = new PdpUpdate(); - update.setName(NetworkUtil.getHostname()); + update.setName(PolicyEngineConstants.PDP_NAME); update.setPdpGroup("W"); update.setPdpSubgroup("w"); update.setPoliciesToBeDeployed(List.of(policyNativeController)); diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActiveTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActiveTest.java index 2efaa496..f4c33140 100644 --- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActiveTest.java +++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActiveTest.java @@ -40,7 +40,7 @@ import org.junit.Before; import org.junit.Test; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; -import org.onap.policy.common.utils.network.NetworkUtil; +import org.onap.policy.drools.system.PolicyEngineConstants; import org.onap.policy.models.pdp.concepts.PdpStateChange; import org.onap.policy.models.pdp.concepts.PdpStatus; import org.onap.policy.models.pdp.concepts.PdpUpdate; @@ -189,7 +189,7 @@ public class LifecycleStateActiveTest extends LifecycleStateRunningTest { // TODO: extract repeated similar assertion blocks into their own helper methods PdpUpdate update = new PdpUpdate(); - update.setName(NetworkUtil.getHostname()); + update.setName(PolicyEngineConstants.PDP_NAME); update.setPdpGroup("W"); update.setPdpSubgroup("w"); diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStatePassiveTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStatePassiveTest.java index 9c4c8ab5..d99f011d 100644 --- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStatePassiveTest.java +++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStatePassiveTest.java @@ -35,7 +35,7 @@ import org.junit.Before; import org.junit.Test; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; -import org.onap.policy.common.utils.network.NetworkUtil; +import org.onap.policy.drools.system.PolicyEngineConstants; import org.onap.policy.models.pdp.concepts.PdpStateChange; import org.onap.policy.models.pdp.concepts.PdpStatus; import org.onap.policy.models.pdp.concepts.PdpUpdate; @@ -143,7 +143,7 @@ public class LifecycleStatePassiveTest extends LifecycleStateRunningTest { assertEquals(0, controllerSupport.getController().getDrools().factCount("junits")); PdpUpdate update = new PdpUpdate(); - update.setName(NetworkUtil.getHostname()); + update.setName(PolicyEngineConstants.PDP_NAME); update.setPdpGroup("Z"); update.setPdpSubgroup("z"); @@ -269,7 +269,7 @@ public class LifecycleStatePassiveTest extends LifecycleStateRunningTest { assertNull(fsm.getSubGroup()); PdpUpdate update = new PdpUpdate(); - update.setName(NetworkUtil.getHostname()); + update.setName(PolicyEngineConstants.PDP_NAME); update.setPdpGroup("A"); update.setPdpSubgroup("a"); @@ -330,7 +330,7 @@ public class LifecycleStatePassiveTest extends LifecycleStateRunningTest { assertEquals("foo", status.getPdpType()); assertEquals(PdpState.TERMINATED, status.getState()); assertEquals(PdpHealthStatus.HEALTHY, status.getHealthy()); - assertEquals(NetworkUtil.getHostname(), status.getName()); + assertEquals(PolicyEngineConstants.PDP_NAME, status.getName()); assertEquals(fsm.getName(), status.getName()); assertEquals(PdpMessageType.PDP_STATUS, status.getMessageName()); } diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateTerminatedTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateTerminatedTest.java index e17f43a2..cf6f451a 100644 --- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateTerminatedTest.java +++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateTerminatedTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -33,8 +33,8 @@ import java.util.Collections; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; -import org.onap.policy.common.utils.network.NetworkUtil; import org.onap.policy.drools.persistence.SystemPersistenceConstants; +import org.onap.policy.drools.system.PolicyEngineConstants; import org.onap.policy.drools.utils.logging.LoggerUtil; import org.onap.policy.models.pdp.concepts.PdpStateChange; import org.onap.policy.models.pdp.concepts.PdpUpdate; @@ -139,7 +139,7 @@ public class LifecycleStateTerminatedTest { @Test public void testUpdate() { PdpUpdate update = new PdpUpdate(); - update.setName(NetworkUtil.getHostname()); + update.setName(PolicyEngineConstants.PDP_NAME); update.setPdpGroup("A"); update.setPdpSubgroup("a"); update.setPoliciesToBeDeployed(Collections.emptyList()); @@ -190,4 +190,4 @@ public class LifecycleStateTerminatedTest { assertFalse(fsm.statusTask.isCancelled()); assertFalse(fsm.statusTask.isDone()); } -} \ No newline at end of file +} diff --git a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineConstants.java b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineConstants.java index 4d18d6b8..2173687a 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineConstants.java +++ b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineConstants.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-management * ================================================================================ - * 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. @@ -21,8 +21,9 @@ package org.onap.policy.drools.system; import lombok.Getter; +import org.onap.policy.common.utils.network.NetworkUtil; -public class PolicyEngineConstants { +public final class PolicyEngineConstants { /** * Default Telemetry Server Port. @@ -39,6 +40,11 @@ public class PolicyEngineConstants { */ public static final String TELEMETRY_SERVER_DEFAULT_NAME = "TELEMETRY"; + /** + * Unique name of this drools-pdp JVM. + */ + public static final String PDP_NAME = NetworkUtil.genUniqueName("drools"); + /** * Policy Engine Manager. */ -- cgit 1.2.3-korg