summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/main/java
diff options
context:
space:
mode:
authorleventecsanyi <levente.csanyi@est.tech>2023-09-08 15:52:24 +0200
committerleventecsanyi <levente.csanyi@est.tech>2023-09-18 18:05:38 +0200
commite5cdeae638105b2a3a191fc2273c63d73ff8503c (patch)
tree404c777717985eae23d6a34d1240b5207cdc28cf /cps-ncmp-service/src/main/java
parente2db79981081bc86cbb836d6cdca8720c9d21383 (diff)
Set lock state and reason upon request
- added new LockReasonCategories and improved SyncUtils.isReadyForRetry - refactored logic aroudn retry times - refactored unit tests Issue-ID: CPS-1860 Signed-off-by: leventecsanyi <levente.csanyi@est.tech> Change-Id: I4382d6ad1fa0a7d9dacb8c8281b0458a5afc0375
Diffstat (limited to 'cps-ncmp-service/src/main/java')
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/LockReasonCategory.java2
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncTasks.java4
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/SyncUtils.java25
3 files changed, 20 insertions, 11 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/LockReasonCategory.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/LockReasonCategory.java
index 16ae88193..35daa62e8 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/LockReasonCategory.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/LockReasonCategory.java
@@ -21,5 +21,5 @@
package org.onap.cps.ncmp.api.inventory;
public enum LockReasonCategory {
- LOCKED_MODULE_SYNC_FAILED
+ MODULE_SYNC_FAILED, MODULE_UPGRADE, MODULE_UPGRADE_FAILED
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncTasks.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncTasks.java
index 914b626e3..9ef75b3b0 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncTasks.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncTasks.java
@@ -73,7 +73,7 @@ public class ModuleSyncTasks {
} catch (final Exception e) {
log.warn("Processing of {} module sync failed due to reason {}.", cmHandleId, e.getMessage());
syncUtils.updateLockReasonDetailsAndAttempts(compositeState,
- LockReasonCategory.LOCKED_MODULE_SYNC_FAILED, e.getMessage());
+ LockReasonCategory.MODULE_SYNC_FAILED, e.getMessage());
setCmHandleStateLocked(yangModelCmHandle, compositeState.getLockReason());
cmHandelStatePerCmHandle.put(yangModelCmHandle, CmHandleState.LOCKED);
}
@@ -96,7 +96,7 @@ public class ModuleSyncTasks {
final Map<YangModelCmHandle, CmHandleState> cmHandleStatePerCmHandle = new HashMap<>(failedCmHandles.size());
for (final YangModelCmHandle failedCmHandle : failedCmHandles) {
final CompositeState compositeState = failedCmHandle.getCompositeState();
- final boolean isReadyForRetry = syncUtils.isReadyForRetry(compositeState);
+ final boolean isReadyForRetry = syncUtils.needsModuleSyncRetry(compositeState);
log.info("Retry for cmHandleId : {} is {}", failedCmHandle.getId(), isReadyForRetry);
if (isReadyForRetry) {
final String resetCmHandleId = failedCmHandle.getId();
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/SyncUtils.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/SyncUtils.java
index 53d8c797b..ce41e3339 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/SyncUtils.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/SyncUtils.java
@@ -102,13 +102,13 @@ public class SyncUtils {
}
/**
- * Query data nodes for cm handles with an "LOCKED" cm handle state with reason LOCKED_MODULE_SYNC_FAILED".
+ * Query data nodes for cm handles with an "LOCKED" cm handle state with reason MODULE_SYNC_FAILED".
*
* @return a random LOCKED yang model cm handle, return null if not found
*/
public List<YangModelCmHandle> getModuleSyncFailedCmHandles() {
final List<DataNode> lockedCmHandlesAsDataNodeList = cmHandleQueries.queryCmHandleDataNodesByCpsPath(
- "//lock-reason[@reason=\"LOCKED_MODULE_SYNC_FAILED\"]",
+ "//lock-reason[@reason=\"MODULE_SYNC_FAILED\"]",
FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS);
return convertCmHandlesDataNodesToYangModelCmHandles(lockedCmHandlesAsDataNodeList);
}
@@ -136,28 +136,37 @@ public class SyncUtils {
/**
- * Check if the retry mechanism should attempt to unlock the cm handle based on the last update time.
+ * Check if a module sync retry is needed.
*
* @param compositeState the composite state currently in the locked state
* @return if the retry mechanism should be attempted
*/
- public boolean isReadyForRetry(final CompositeState compositeState) {
- int timeInMinutesUntilNextAttempt = 1;
+ public boolean needsModuleSyncRetry(final CompositeState compositeState) {
final OffsetDateTime time =
OffsetDateTime.parse(compositeState.getLastUpdateTime(),
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ"));
final Matcher matcher = retryAttemptPattern.matcher(compositeState.getLockReason().getDetails());
+ final boolean failedDuringModuleSync = LockReasonCategory.MODULE_SYNC_FAILED
+ == compositeState.getLockReason().getLockReasonCategory();
+ if (!failedDuringModuleSync) {
+ log.info("Locked for other reason");
+ return false;
+ }
+ final int timeInMinutesUntilNextAttempt;
if (matcher.find()) {
timeInMinutesUntilNextAttempt = (int) Math.pow(2, Integer.parseInt(matcher.group(1)));
} else {
- log.debug("First Attempt: no current attempts found.");
+ timeInMinutesUntilNextAttempt = 1;
+ log.info("First Attempt: no current attempts found.");
}
final int timeSinceLastAttempt = (int) Duration.between(time, OffsetDateTime.now()).toMinutes();
if (timeInMinutesUntilNextAttempt >= timeSinceLastAttempt) {
log.info("Time until next attempt is {} minutes: ",
- timeInMinutesUntilNextAttempt - timeSinceLastAttempt);
+ timeInMinutesUntilNextAttempt - timeSinceLastAttempt);
+ return false;
}
- return timeSinceLastAttempt > timeInMinutesUntilNextAttempt;
+ log.info("Retry due now");
+ return true;
}
/**