diff options
Diffstat (limited to 'cps-ncmp-service/src/main')
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 16ae881935..35daa62e89 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 914b626e33..9ef75b3b0c 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 53d8c797b8..ce41e3339d 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; } /** |