Merge "Simplified 'External' lock reason Mapping"
authorJoseph Keenan <joseph.keenan@est.tech>
Mon, 4 Jul 2022 09:11:58 +0000 (09:11 +0000)
committerGerrit Code Review <gerrit@onap.org>
Mon, 4 Jul 2022 09:11:58 +0000 (09:11 +0000)
1  2 
cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/SyncUtils.java

@@@ -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()
      }
  
      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())
              '"state":',
              '"cmHandleState":"ADVISED"',
              '"reason":"LOCKED_MISBEHAVING"',
-             '"details":"lock misbehaving details"',
+             '"details":"lock details"',
              '"lastUpdateTime":"2022-12-31T20:30:40.000+0000"',
              '"dataSyncEnabled":false',
              '"dataSyncState":',
@@@ -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<YangModelCmHandle> getLockedMisbehavingYangModelCmHandles() {
+     public List<YangModelCmHandle> getModuleSyncFailedCmHandles() {
          final List<DataNode> 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,
       * @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;
      }
  
      /**