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)
cps-ncmp-rest-stub/src/main/java/org/onap/cps/ncmp/rest/stub/controller/NetworkCmProxyStubController.java
cps-ncmp-rest-stub/src/main/resources/stubs/cmHandlesSearch.json
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
pom.xml

index 6362cf1..45408b0 100644 (file)
@@ -24,6 +24,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 import java.io.IOException;
 import java.io.InputStream;
 import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -32,9 +33,7 @@ import javax.validation.Valid;
 import javax.validation.constraints.NotNull;
 import lombok.extern.slf4j.Slf4j;
 import org.onap.cps.ncmp.rest.api.NetworkCmProxyApi;
-import org.onap.cps.ncmp.rest.model.CmHandleQueryRestParameters;
-import org.onap.cps.ncmp.rest.model.CmHandles;
-import org.onap.cps.ncmp.rest.model.Conditions;
+import org.onap.cps.ncmp.rest.model.CmHandleQueryParameters;
 import org.onap.cps.ncmp.rest.model.RestModuleReference;
 import org.onap.cps.ncmp.rest.model.RestOutputCmHandle;
 import org.onap.cps.ncmp.rest.model.RestOutputCmHandlePublicProperties;
@@ -68,18 +67,26 @@ public class NetworkCmProxyStubController implements NetworkCmProxyApi {
     }
 
     @Override
-    public ResponseEntity<CmHandles> executeCmHandleSearch(@Valid final Conditions body) {
-        final ObjectMapper mapper = new ObjectMapper();
-        CmHandles cmHandles = new CmHandles();
+    public ResponseEntity<List<RestOutputCmHandle>> searchCmHandles(
+        final CmHandleQueryParameters cmHandleQueryParameters) {
+        List<RestOutputCmHandle> restOutputCmHandles = null;
         // read JSON file and map/convert to java POJO
         final ClassPathResource resource = new ClassPathResource(pathToResponseFiles + "cmHandlesSearch.json");
         try (InputStream inputStream = resource.getInputStream()) {
             final String string = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
-            cmHandles = mapper.readValue(string, CmHandles.class);
+            final ObjectMapper mapper = new ObjectMapper();
+            restOutputCmHandles = Arrays.asList(mapper.readValue(string, RestOutputCmHandle[].class));
         } catch (final IOException exception) {
             log.error("Error reading the file.", exception);
+            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
         }
-        return ResponseEntity.ok(cmHandles);
+        return ResponseEntity.ok(restOutputCmHandles);
+    }
+
+    @Override
+    public ResponseEntity<List<String>> searchCmHandleIds(
+        final CmHandleQueryParameters cmHandleQueryParameters) {
+        return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
     }
 
     @Override
@@ -107,16 +114,17 @@ public class NetworkCmProxyStubController implements NetworkCmProxyApi {
         final String resourceIdentifier, final String optionsParamInQuery, final String topicParamInQuery) {
         final ResponseEntity<Map<String, Object>> asyncResponse = populateAsyncResponse(topicParamInQuery);
         final Map<String, Object> asyncResponseData = asyncResponse.getBody();
-        final ObjectMapper mapper = new ObjectMapper();
         Object responseObject = null;
         // read JSON file and map/convert to java POJO
         final ClassPathResource resource = new ClassPathResource(pathToResponseFiles
             + "passthrough-operational-example.json");
         try (InputStream inputStream = resource.getInputStream()) {
             final String string = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
+            final ObjectMapper mapper = new ObjectMapper();
             responseObject = mapper.readValue(string, Object.class);
         } catch (final IOException exception) {
             log.error("Error reading the file.", exception);
+            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
         }
         if (asyncResponseData == null) {
             return ResponseEntity.ok(responseObject);
@@ -137,11 +145,6 @@ public class NetworkCmProxyStubController implements NetworkCmProxyApi {
         return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
     }
 
-    @Override
-    public ResponseEntity<List<String>> queryCmHandles(final CmHandleQueryRestParameters body) {
-        return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
-    }
-
     @Override
     public ResponseEntity<RestOutputCmHandle> retrieveCmHandleDetailsById(final String cmHandleId) {
         return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
index 409d56f..9a2e1ed 100644 (file)
@@ -1,10 +1,8 @@
-{
-  "cmHandles": [
+[
     {
-      "cmHandleId": "stub-cm-handle-id"
+      "cmHandle": "stub-cm-handle-id"
     },
     {
-      "cmHandleId": "stub-cm-handle-id2"
+      "cmHandle": "stub-cm-handle-id2"
     }
-  ]
-}
\ No newline at end of file
+  ]
\ No newline at end of file
index 7b123e8..23263c9 100644 (file)
@@ -416,9 +416,9 @@ class NetworkCmProxyControllerSpec extends Specification {
         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()
     }
index e742b8c..046a116 100644 (file)
@@ -151,18 +151,22 @@ public class SyncUtils {
      * @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;
     }
 
     /**
diff --git a/pom.xml b/pom.xml
index 12d8a1f..bb3553b 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
   Copyright (c) 2020 Linux Foundation.\r
   Modifications Copyright (C) 2020-2021 Nordix Foundation\r
   Modifications Copyright (C) 2020-2021 Pantheon.tech\r
-  Modifications Copyright (C) 2021 Bell Canada.\r
+  Modifications Copyright (C) 2021-2022 Bell Canada.\r
   ================================================================================\r
   Licensed under the Apache License, Version 2.0 (the "License");\r
   you may not use this file except in compliance with the License.\r
@@ -58,6 +58,7 @@
         <module>cps-ncmp-events</module>\r
         <module>cps-ncmp-service</module>\r
         <module>cps-ncmp-rest</module>\r
+        <module>cps-ncmp-rest-stub</module>\r
         <module>cps-path-parser</module>\r
         <module>cps-ri</module>\r
         <module>checkstyle</module>\r