aboutsummaryrefslogtreecommitdiffstats
path: root/feature-distributed-locking/src/main/java/org
diff options
context:
space:
mode:
authorjhh <jorge.hernandez-herrero@att.com>2022-10-18 12:08:45 -0500
committerjhh <jorge.hernandez-herrero@att.com>2022-10-19 08:31:02 -0500
commit6652164b384221018bf605b1d5fb809425b26a8e (patch)
tree6e440f5379010f5bbb20841384c55b86da37b533 /feature-distributed-locking/src/main/java/org
parente58a8c52dadfe14b8b77c8eb7c236697c710ddd5 (diff)
Support optional cluster name in policy engine
This allows also for correlation with running pod hostnames in the case of multiple drools pdp flavors coexist. Issue-ID: POLICY-4403 Signed-off-by: jhh <jorge.hernandez-herrero@att.com> Change-Id: I81affeeec622e6c0e9627651bf34c0775a796827 Signed-off-by: jhh <jorge.hernandez-herrero@att.com>
Diffstat (limited to 'feature-distributed-locking/src/main/java/org')
-rw-r--r--feature-distributed-locking/src/main/java/org/onap/policy/distributed/locking/DistributedLockManager.java32
1 files changed, 19 insertions, 13 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 04138eed..198b3303 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-2021 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2022 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.
@@ -87,17 +87,16 @@ public class DistributedLockManager extends LockManager<DistributedLockManager.D
@Setter(AccessLevel.PROTECTED)
private static DistributedLockManager latestInstance = null;
-
/**
* Name of the host on which this JVM is running.
*/
- @Getter
- private final String pdpName;
+ @Getter(AccessLevel.PUBLIC)
+ private String pdpName;
/**
* UUID of this object.
*/
- @Getter
+ @Getter(AccessLevel.PUBLIC)
private final String uuidString = UUID.randomUUID().toString();
/**
@@ -133,7 +132,6 @@ public class DistributedLockManager extends LockManager<DistributedLockManager.D
* Constructs the object.
*/
public DistributedLockManager() {
- this.pdpName = PolicyEngineConstants.PDP_NAME;
this.resource2lock = getResource2lock();
}
@@ -146,6 +144,7 @@ public class DistributedLockManager extends LockManager<DistributedLockManager.D
public PolicyResourceLockManager beforeCreateLockManager(PolicyEngine engine, Properties properties) {
try {
+ this.pdpName = PolicyEngineConstants.getManager().getPdpName();
this.featProps = new DistributedLockProperties(getProperties(CONFIGURATION_PROPERTIES_NAME));
this.dataSource = makeDataSource();
@@ -256,8 +255,9 @@ public class DistributedLockManager extends LockManager<DistributedLockManager.D
*/
private void checkExpired() {
try {
- logger.info("checking for expired locks");
Set<String> expiredIds = new HashSet<>(resource2lock.keySet());
+ logger.info("checking for expired locks: {}", this);
+
identifyDbLocks(expiredIds);
expireLocks(expiredIds);
@@ -337,7 +337,7 @@ public class DistributedLockManager extends LockManager<DistributedLockManager.D
DistributedLock lock = lockref.get();
if (lock != null) {
- logger.debug("removed lock from map {}", lock);
+ logger.info("lost lock: removed lock from map {}", lock);
lock.deny(FeatureLockImpl.LOCK_LOST_MSG);
}
}
@@ -704,7 +704,7 @@ public class DistributedLockManager extends LockManager<DistributedLockManager.D
* @throws SQLException if a DB error occurs
*/
protected boolean doDbInsert(Connection conn) throws SQLException {
- logger.debug("insert lock record {}", this);
+ logger.info("insert lock record {}", this);
try (var stmt = conn.prepareStatement("INSERT INTO pooling.locks (resourceId, host, owner, expirationTime) "
+ "values (?, ?, ?, timestampadd(second, ?, now()))")) {
@@ -731,7 +731,7 @@ public class DistributedLockManager extends LockManager<DistributedLockManager.D
* @throws SQLException if a DB error occurs
*/
protected boolean doDbUpdate(Connection conn) throws SQLException {
- logger.debug("update lock record {}", this);
+ logger.info("update lock record {}", this);
try (var stmt = conn.prepareStatement("UPDATE pooling.locks SET resourceId=?, host=?, owner=?,"
+ " expirationTime=timestampadd(second, ?, now()) WHERE resourceId=?"
+ " AND ((host=? AND owner=?) OR expirationTime < now())")) {
@@ -763,7 +763,7 @@ public class DistributedLockManager extends LockManager<DistributedLockManager.D
* @throws SQLException if a DB error occurs
*/
protected void doDbDelete(Connection conn) throws SQLException {
- logger.debug("delete lock record {}", this);
+ logger.info("delete lock record {}", this);
try (var stmt = conn
.prepareStatement("DELETE FROM pooling.locks WHERE resourceId=? AND host=? AND owner=?")) {
@@ -780,7 +780,7 @@ public class DistributedLockManager extends LockManager<DistributedLockManager.D
* thread.
*/
private void removeFromMap() {
- logger.debug("remove lock from map {}", this);
+ logger.info("remove lock from map {}", this);
feature.resource2lock.remove(getResourceId(), this);
synchronized (this) {
@@ -799,10 +799,16 @@ public class DistributedLockManager extends LockManager<DistributedLockManager.D
}
@FunctionalInterface
- private static interface RunnableWithEx {
+ private interface RunnableWithEx {
void run() throws SQLException;
}
+ @Override
+ public String toString() {
+ return "DistributedLockManager [" + "pdpName=" + pdpName + ", uuidString=" + uuidString
+ + ", resource2lock=" + resource2lock + "]";
+ }
+
// these may be overridden by junit tests
protected Properties getProperties(String fileName) {