diff options
author | DylanB95EST <dylan.byrne@est.tech> | 2022-06-20 13:45:19 +0100 |
---|---|---|
committer | DylanB95EST <dylan.byrne@est.tech> | 2022-06-29 11:54:46 +0100 |
commit | 722701b8893e0f3c27aa63ab506a32b891dd64d0 (patch) | |
tree | 9914a796004c725b033a9653cf3ef3af055ca54b /cps-ncmp-service/src/main/java/org/onap | |
parent | 529f92c549a16ecd9ead36cc00d6f74f775ca638 (diff) |
Retry Module-Sync based on from last failure
Retry algorithm for module-sync based on last failure
Poll Lock Reason, check if lock has surpassed minimum time
based on last update time and lock reason
Issue-ID: CPS-1076
Change-Id: Ifbbabd2b403f88f1bbe3fae3f125b1e9cb2091aa
Signed-off-by: DylanB95EST <dylan.byrne@est.tech>
Diffstat (limited to 'cps-ncmp-service/src/main/java/org/onap')
3 files changed, 37 insertions, 8 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CompositeStateBuilder.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CompositeStateBuilder.java index 012ba5ede2..91e92ea6f9 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CompositeStateBuilder.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CompositeStateBuilder.java @@ -111,8 +111,9 @@ public class CompositeStateBuilder { * @return CompositeState */ public CompositeStateBuilder fromDataNode(final DataNode dataNode) { - this.cmHandleState = CmHandleState.valueOf((String) dataNode.getLeaves() - .get("cm-handle-state")); + this.cmHandleState = CmHandleState.valueOf((String) dataNode.getLeaves() + .get("cm-handle-state")); + this.lastUpdatedTime = (String) dataNode.getLeaves().get("last-update-time"); for (final DataNode stateChildNode : dataNode.getChildDataNodes()) { if (stateChildNode.getXpath().endsWith("/lock-reason")) { this.lockReason = getLockReason(stateChildNode); diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdog.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdog.java index e590ca1cd0..402f9f6b4f 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdog.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdog.java @@ -74,13 +74,16 @@ public class ModuleSyncWatchdog { * Execute Cm Handle poll which changes the cm handle state from 'LOCKED' to 'ADVISED'. */ @Scheduled(fixedDelayString = "${timers.locked-modules-sync.sleep-time-ms:300000}") - public void executeLockedMisbehavingCmHandlePoll() { + public void executeLockedCmHandlePoll() { final List<YangModelCmHandle> lockedMisbehavingCmHandles = syncUtils.getLockedMisbehavingYangModelCmHandles(); - for (final YangModelCmHandle lockedMisbehavingModelCmHandle : lockedMisbehavingCmHandles) { - final CompositeState compositeState = lockedMisbehavingModelCmHandle.getCompositeState(); - setCompositeStateToAdvisedAndRetainOldLockReasonDetails(compositeState); - log.debug("Locked misbehaving cm handle {} is being recycled", lockedMisbehavingModelCmHandle.getId()); - inventoryPersistence.saveCmHandleState(lockedMisbehavingModelCmHandle.getId(), compositeState); + for (final YangModelCmHandle moduleSyncFailedCmHandle : lockedMisbehavingCmHandles) { + final CompositeState compositeState = moduleSyncFailedCmHandle.getCompositeState(); + final boolean isReadyForRetry = syncUtils.isReadyForRetry(compositeState); + if (isReadyForRetry) { + setCompositeStateToAdvisedAndRetainOldLockReasonDetails(compositeState); + log.debug("Locked misbehaving cm handle {} is being recycled", moduleSyncFailedCmHandle.getId()); + inventoryPersistence.saveCmHandleState(moduleSyncFailedCmHandle.getId(), compositeState); + } } } 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 42edcb7ec8..8b7dfe6b81 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 @@ -24,6 +24,9 @@ package org.onap.cps.ncmp.api.inventory.sync; import com.fasterxml.jackson.databind.JsonNode; import com.google.common.collect.ImmutableMap; import java.security.SecureRandom; +import java.time.Duration; +import java.time.OffsetDateTime; +import java.time.format.DateTimeFormatter; import java.util.Collections; import java.util.Iterator; import java.util.List; @@ -140,6 +143,28 @@ public class SyncUtils { .lockReasonCategory(lockReasonCategory).build()); } + + /** + * Check if the retry mechanism should attempt to unlock the cm handle based on the last update time. + * + * @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 timeUntilNextAttempt = 1; + 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()); + if (matcher.find()) { + timeUntilNextAttempt = (int) Math.pow(2, Integer.parseInt(matcher.group(1))); + } else { + log.debug("First Attempt: no current attempts found."); + } + final int timeSinceLastAttempt = (int) Duration.between(time, OffsetDateTime.now()).toMinutes(); + return timeSinceLastAttempt > timeUntilNextAttempt; + } + /** * Get the Resourece Data from Node through DMI Passthrough service. * |