aboutsummaryrefslogtreecommitdiffstats
path: root/a1-policy-management/src
diff options
context:
space:
mode:
authorPatrikBuhr <patrik.buhr@est.tech>2022-02-10 11:17:34 +0100
committerPatrikBuhr <patrik.buhr@est.tech>2022-02-10 11:17:34 +0100
commit31639ac11cc90c554b5303199c2da6fedc008d7b (patch)
tree74789e9eb57c472ae4c39eed76b70b503218ff75 /a1-policy-management/src
parent82a6252d3d3008c1ee568b1eb85de0701600918d (diff)
NONRTRIC Improved traces
Improved traces Issue-ID: CCSDK-3560 Signed-off-by: PatrikBuhr <patrik.buhr@est.tech> Change-Id: I1ef76b859e24f4ea503c8e28e503528c98de4342
Diffstat (limited to 'a1-policy-management/src')
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Lock.java34
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Ric.java3
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/LockTest.java4
3 files changed, 30 insertions, 11 deletions
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Lock.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Lock.java
index 18507ac2..46033a4a 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Lock.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Lock.java
@@ -45,6 +45,7 @@ public class Lock {
private int lockCounter = 0;
final Queue<LockRequest> lockRequestQueue = new LinkedList<>();
private static AsynchCallbackExecutor callbackProcessor = new AsynchCallbackExecutor();
+ private final String label;
public enum LockType {
EXCLUSIVE, SHARED
@@ -63,6 +64,7 @@ public class Lock {
Grant(Lock lock, String label) {
this.lock = lock;
this.label = label;
+ logger.trace("Lock granted {}:{}", lock.label, this.label);
}
/**
@@ -71,27 +73,42 @@ public class Lock {
* @return the lock
*/
public Mono<Lock> unlock() {
- check();
- return this.lock.unlock();
+ if (!isUnlocked()) {
+ logger.trace("Unlocking lock {}:{}", lock.label, this.label);
+ return this.lock.unlock();
+ }
+ return Mono.just(this.lock);
}
/**
* Synchronuous unlocking
*/
public void unlockBlocking() {
- check();
- this.lock.unlockBlocking();
+ if (!isUnlocked()) {
+ logger.trace("Unlocking lock {}:{}", lock.label, this.label);
+ this.lock.unlockBlocking();
+ }
}
- private void check() {
+ private boolean isUnlocked() {
if (unlocked) {
- logger.error("Lock already unlocked");
+ logger.debug("Lock {}:{} already unlocked", lock.label, this.label);
+ return true;
}
unlocked = true;
+ return false;
}
}
/**
+ *
+ * @param label a label attached to the lock. For troubleshooting.
+ */
+ public Lock(String label) {
+ this.label = label;
+ }
+
+ /**
* Reactive lock. The Lock will be emitted when the lock is granted
*
* @param lockType type of lock (exclusive/shared)
@@ -140,7 +157,7 @@ public class Lock {
@Override
public synchronized String toString() {
- return "Lock cnt: " + this.lockCounter + " exclusive: " + this.isExclusive + " queued: "
+ return "Lock " + this.label + ", cnt: " + this.lockCounter + ", exclusive: " + this.isExclusive + ", queued: "
+ this.lockRequestQueue.size();
}
@@ -164,6 +181,7 @@ public class Lock {
}
private synchronized void addToQueue(MonoSink<Grant> callback, LockType lockType, String label) {
+ logger.trace("Lock request queued {}:{}", label, this.label);
lockRequestQueue.add(new LockRequest(callback, lockType, this, label));
}
@@ -172,7 +190,7 @@ public class Lock {
try {
this.wait();
} catch (InterruptedException e) {
- logger.warn("waitForUnlock interrupted", e);
+ logger.warn("waitForUnlock interrupted " + this.label, e);
Thread.currentThread().interrupt();
}
}
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Ric.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Ric.java
index 8eca6be9..f43737f5 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Ric.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Ric.java
@@ -45,7 +45,7 @@ public class Ric {
private A1ProtocolType protocolVersion = A1ProtocolType.UNKNOWN;
@Getter
- private final Lock lock = new Lock();
+ private final Lock lock;
/**
* Creates the Ric. Initial state is {@link RicState.UNDEFINED}.
@@ -54,6 +54,7 @@ public class Ric {
*/
public Ric(RicConfig ricConfig) {
this.ricConfig = ricConfig;
+ this.lock = new Lock(ricConfig.ricId());
}
public String id() {
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/LockTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/LockTest.java
index 79879446..3ea0fe53 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/LockTest.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/LockTest.java
@@ -65,7 +65,7 @@ class LockTest {
@Test
void testLock() throws IOException, ServiceException {
- Lock lock = new Lock();
+ Lock lock = new Lock("l1");
Lock.Grant grant = lock.lockBlocking(LockType.SHARED, "test");
grant.unlockBlocking();
assertThat(grant.getLabel()).isEqualTo("test");
@@ -81,7 +81,7 @@ class LockTest {
@Test
void testReactiveLock() {
- Lock lock = new Lock();
+ Lock lock = new Lock("l1");
Mono<?> l0 = lock.lock(LockType.EXCLUSIVE, "1").doOnNext(grant -> asynchUnlock(grant, lock));
Mono<?> l1 = lock.lock(LockType.SHARED, "2").doOnNext(grant -> asynchUnlock(grant, lock));