From: Joseph Keenan Date: Mon, 4 Jul 2022 09:11:58 +0000 (+0000) Subject: Merge "Simplified 'External' lock reason Mapping" X-Git-Tag: 3.1.0~79 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=d797b35547c24f3ebd6bd5ad53eed1891d5783b3;hp=-c;p=cps.git Merge "Simplified 'External' lock reason Mapping" --- d797b35547c24f3ebd6bd5ad53eed1891d5783b3 diff --combined cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy index 2cb397ded,7b123e8a6..23263c9aa --- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy +++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy @@@ -416,9 -416,9 +416,9 @@@ class NetworkCmProxyControllerSpec exte then: 'ncmp service method to get module definitions is called' mockNetworkCmProxyDataService.getModuleDefinitionsByCmHandleId('some-cmhandle') >> [new ModuleDefinition('sampleModuleName', '2021-10-03', - String.format('module sampleModuleName{ %n sample module content %n }'))] - and: 'response contains an array with the module name, revision and content where content contains \\n for newlines' - response.getContentAsString() == '[{"moduleName":"sampleModuleName","revision":"2021-10-03","content":"module sampleModuleName{ \\n sample module content \\n }"}]' + 'module sampleModuleName{ sample module content }')] + and: 'response contains an array with the module name, revision and content' + response.getContentAsString() == '[{"moduleName":"sampleModuleName","revision":"2021-10-03","content":"module sampleModuleName{ sample module content }"}]' and: 'response returns an OK http code' response.status == HttpStatus.OK.value() } @@@ -432,7 -432,7 +432,7 @@@ def compositeStateTestObject() { new CompositeState(cmHandleState: CmHandleState.ADVISED, - lockReason: CompositeState.LockReason.builder().lockReasonCategory(LockReasonCategory.LOCKED_MISBEHAVING).details("lock misbehaving details").build(), + lockReason: CompositeState.LockReason.builder().lockReasonCategory(LockReasonCategory.LOCKED_MODULE_SYNC_FAILED).details("lock details").build(), lastUpdateTime: formattedDateAndTime.toString(), dataSyncEnabled: false, dataStores: dataStores()) @@@ -448,7 -448,7 +448,7 @@@ '"state":', '"cmHandleState":"ADVISED"', '"reason":"LOCKED_MISBEHAVING"', - '"details":"lock misbehaving details"', + '"details":"lock details"', '"lastUpdateTime":"2022-12-31T20:30:40.000+0000"', '"dataSyncEnabled":false', '"dataSyncState":', diff --combined cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/SyncUtils.java index 8c30b590e,e742b8c0f..046a116ef --- 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 @@@ -109,13 -109,13 +109,13 @@@ public class SyncUtils } /** - * Query data nodes for cm handles with an "LOCKED" cm handle state with reason LOCKED_MISBEHAVING". + * Query data nodes for cm handles with an "LOCKED" cm handle state with reason LOCKED_MODULE_SYNC_FAILED". * - * @return a random yang model cm handle with an ADVISED state, return null if not found + * @return a random LOCKED yang model cm handle, return null if not found */ - public List getLockedMisbehavingYangModelCmHandles() { + public List getModuleSyncFailedCmHandles() { final List lockedCmHandleAsDataNodeList = inventoryPersistence.getCmHandleDataNodesByCpsPath( - "//lock-reason[@reason=\"LOCKED_MISBEHAVING\"]/ancestor::cm-handles", + "//lock-reason[@reason=\"LOCKED_MODULE_SYNC_FAILED\"]/ancestor::cm-handles", FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS); return lockedCmHandleAsDataNodeList.stream() .map(cmHandle -> YangDataConverter.convertCmHandleToYangModel(cmHandle, @@@ -151,22 -151,18 +151,22 @@@ * @return if the retry mechanism should be attempted */ public boolean isReadyForRetry(final CompositeState compositeState) { - int timeUntilNextAttempt = 1; + int timeInMinutesUntilNextAttempt = 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))); + timeInMinutesUntilNextAttempt = (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; + if (timeInMinutesUntilNextAttempt >= timeSinceLastAttempt) { + log.info("Time until next attempt is {} minutes: ", + timeInMinutesUntilNextAttempt - timeSinceLastAttempt); + } + return timeSinceLastAttempt > timeInMinutesUntilNextAttempt; } /**