summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--feature-distributed-locking/src/main/java/org/onap/policy/distributed/locking/DistributedLockManager.java19
-rw-r--r--feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/DistributedLockManagerTest.java10
-rw-r--r--feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java5
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmTest.java4
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmUpdateTest.java4
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActivePoliciesTest.java6
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActiveTest.java4
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStatePassiveTest.java8
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateTerminatedTest.java8
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineConstants.java10
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<DistributedLockManager.D
* Name of the host on which this JVM is running.
*/
@Getter
- private final String hostName;
+ private final String pdpName;
/**
* UUID of this object.
@@ -135,7 +134,7 @@ public class DistributedLockManager extends LockManager<DistributedLockManager.D
* Constructs the object.
*/
public DistributedLockManager() {
- this.hostName = NetworkUtil.getHostname();
+ this.pdpName = PolicyEngineConstants.PDP_NAME;
this.resource2lock = getResource2lock();
}
@@ -305,7 +304,7 @@ public class DistributedLockManager extends LockManager<DistributedLockManager.D
"SELECT resourceId FROM pooling.locks WHERE host=? AND owner=? AND expirationTime > 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<DistributedLockManager.D
super(state, resourceId, ownerKey, holdSec, callback);
this.feature = feature;
- this.hostName = feature.hostName;
+ this.hostName = feature.pdpName;
this.uuidString = feature.uuidString;
}
@@ -713,13 +712,13 @@ public class DistributedLockManager extends LockManager<DistributedLockManager.D
+ "values (?, ?, ?, timestampadd(second, ?, now()))")) {
stmt.setString(1, getResourceId());
- stmt.setString(2, feature.hostName);
+ stmt.setString(2, feature.pdpName);
stmt.setString(3, feature.uuidString);
stmt.setInt(4, getHoldSec());
stmt.executeUpdate();
- this.hostName = feature.hostName;
+ this.hostName = feature.pdpName;
this.uuidString = feature.uuidString;
return true;
@@ -742,7 +741,7 @@ public class DistributedLockManager extends LockManager<DistributedLockManager.D
+ " AND ((host=? AND owner=?) OR expirationTime < now())")) {
stmt.setString(1, getResourceId());
- stmt.setString(2, feature.hostName);
+ stmt.setString(2, feature.pdpName);
stmt.setString(3, feature.uuidString);
stmt.setInt(4, getHoldSec());
@@ -754,7 +753,7 @@ public class DistributedLockManager extends LockManager<DistributedLockManager.D
return false;
}
- this.hostName = feature.hostName;
+ this.hostName = feature.pdpName;
this.uuidString = feature.uuidString;
return true;
diff --git a/feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/DistributedLockManagerTest.java b/feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/DistributedLockManagerTest.java
index d36fbe1f..2fbdb26b 100644
--- a/feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/DistributedLockManagerTest.java
+++ b/feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/DistributedLockManagerTest.java
@@ -441,13 +441,13 @@ public class DistributedLockManagerTest {
assertEquals(5, getRecordCount());
// expire one record
- updateRecord(RESOURCE, feature.getHostName(), feature.getUuidString(), -1);
+ updateRecord(RESOURCE, feature.getPdpName(), feature.getUuidString(), -1);
// change host of another record
updateRecord(RESOURCE3, OTHER_HOST, feature.getUuidString(), HOLD_SEC);
// change uuid of another record
- updateRecord(RESOURCE5, feature.getHostName(), OTHER_OWNER, HOLD_SEC);
+ updateRecord(RESOURCE5, feature.getPdpName(), OTHER_OWNER, HOLD_SEC);
// run the checker
@@ -569,7 +569,7 @@ public class DistributedLockManagerTest {
assertEquals(3, getRecordCount());
// expire one record
- updateRecord(RESOURCE, feature.getHostName(), feature.getUuidString(), -1);
+ updateRecord(RESOURCE, feature.getPdpName(), feature.getUuidString(), -1);
// arrange to free lock4 while the checker is running
freeLock.set(lock4);
@@ -1578,7 +1578,7 @@ public class DistributedLockManagerTest {
+ " WHERE resourceId=? AND host=? AND owner=?")) {
stmt.setString(1, resourceId);
- stmt.setString(2, feature.getHostName());
+ stmt.setString(2, feature.getPdpName());
stmt.setString(3, uuidString);
try (ResultSet result = stmt.executeQuery()) {
@@ -1603,7 +1603,7 @@ public class DistributedLockManagerTest {
* @throws SQLException if an error occurs accessing the DB
*/
private void insertRecord(String resourceId, String uuidString, int expireOffset) throws SQLException {
- this.insertRecord(resourceId, feature.getHostName(), uuidString, expireOffset);
+ this.insertRecord(resourceId, feature.getPdpName(), uuidString, expireOffset);
}
private void insertRecord(String resourceId, String hostName, String uuidString, int expireOffset)
diff --git a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java
index 0e602ec5..3cec7451 100644
--- a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java
+++ b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java
@@ -53,7 +53,6 @@ import org.onap.policy.common.endpoints.listeners.MessageTypeDispatcher;
import org.onap.policy.common.endpoints.listeners.ScoListener;
import org.onap.policy.common.gson.annotation.GsonJsonIgnore;
import org.onap.policy.common.utils.coder.StandardCoderObject;
-import org.onap.policy.common.utils.network.NetworkUtil;
import org.onap.policy.drools.metrics.Metric;
import org.onap.policy.drools.persistence.SystemPersistenceConstants;
import org.onap.policy.drools.policies.DomainMaker;
@@ -112,7 +111,7 @@ public class LifecycleFsm implements Startable {
protected TopicSinkClient client;
@Getter
- protected final String name = NetworkUtil.getHostname();
+ protected final String name = PolicyEngineConstants.PDP_NAME;
protected LifecycleState state = new LifecycleStateTerminated(this);
@@ -179,7 +178,7 @@ public class LifecycleFsm implements Startable {
logger.info("The mandatory Policy Types are {}. Compliance is {}",
mandatoryPolicyTypes, isMandatoryPolicyTypesCompliant());
- stats.setPdpInstanceId(Metric.HOSTNAME);
+ stats.setPdpInstanceId(PolicyEngineConstants.PDP_NAME);
}
@GsonJsonIgnore
diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmTest.java
index 73d265c2..4479aa12 100644
--- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmTest.java
+++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmTest.java
@@ -232,7 +232,7 @@ public class LifecycleFsmTest {
assertEquals(fsm.getGroup(), status.getStatistics().getPdpGroupName());
assertEquals(fsm.getSubGroup(), status.getStatistics().getPdpSubGroupName());
- assertEquals(NetworkUtil.getHostname(), status.getStatistics().getPdpInstanceId());
+ assertEquals(PolicyEngineConstants.PDP_NAME, status.getStatistics().getPdpInstanceId());
assertEquals(6, status.getStatistics().getPolicyDeploySuccessCount());
assertEquals(2, status.getStatistics().getPolicyDeployFailCount());
assertEquals(8, status.getStatistics().getPolicyDeployCount());
@@ -291,4 +291,4 @@ public class LifecycleFsmTest {
return serviceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyName);
}
-} \ No newline at end of file
+}
diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmUpdateTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmUpdateTest.java
index 1927c513..253ca5db 100644
--- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmUpdateTest.java
+++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmUpdateTest.java
@@ -46,7 +46,6 @@ import org.onap.policy.common.endpoints.event.comm.bus.NoopTopicFactories;
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.common.utils.resources.ResourceUtils;
import org.onap.policy.common.utils.time.PseudoScheduledExecutorService;
import org.onap.policy.common.utils.time.TestTimeMulti;
@@ -54,6 +53,7 @@ import org.onap.policy.drools.domain.models.artifact.NativeArtifactPolicy;
import org.onap.policy.drools.domain.models.controller.ControllerPolicy;
import org.onap.policy.drools.persistence.SystemPersistenceConstants;
import org.onap.policy.drools.system.PolicyControllerConstants;
+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;
@@ -363,7 +363,7 @@ public class LifecycleFsmUpdateTest {
protected PdpUpdate getPdpUpdate(List<ToscaPolicy> policiesToDeploy, List<ToscaPolicy> 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.
@@ -40,6 +41,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.
*/
@Getter