aboutsummaryrefslogtreecommitdiffstats
path: root/feature-distributed-locking/src
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2021-06-28 15:04:36 -0400
committerJim Hahn <jrh3@att.com>2021-06-29 10:21:49 -0400
commit4d4547ee4b3a6be75cf2c01f3065b129fddcfd3b (patch)
treec98e2237ab5565ba4af267814fb484fbae14dd64 /feature-distributed-locking/src
parentd2b5424c17ef26d5e71b3014234cfd02f7854eca (diff)
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 <jrh3@att.com>
Diffstat (limited to 'feature-distributed-locking/src')
-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
2 files changed, 14 insertions, 15 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)