CPS-2187 - #5 Add module Set Tag to dmi (single cm handle) data request 42/137842/16
authordavid.mcweeney <david.mcweeney@est.tech>
Thu, 2 May 2024 14:14:52 +0000 (15:14 +0100)
committerdavid.mcweeney <david.mcweeney@est.tech>
Thu, 16 May 2024 13:14:21 +0000 (14:14 +0100)
Change-Id: Iae7e3bac67bb8e5bbb50e4157fdf7daf9fc2220f
Signed-off-by: david.mcweeney <david.mcweeney@est.tech>
Issue-ID: CPS-2187

docs/api/swagger/openapi.yaml
openapi/components.yml
openapi/openapi.yml
src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java
src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy

index f3516b5..5782a9c 100644 (file)
@@ -209,6 +209,15 @@ paths:
           required: false
           schema:
             type: string
+        - name: moduleSetTag
+          description: Module set tag of the given cm handle.
+          in: query
+          examples:
+            sample1:
+              value: module-set-tag1
+          required: false
+          schema:
+            type: string
       requestBody:
         content:
           application/json:
@@ -379,6 +388,16 @@ components:
       required: false
       schema:
         type: string
+    moduleSetTagParamInQuery:
+      name: moduleSetTag
+      in: query
+      description: Module set tag of the given cm handle.
+      required: false
+      schema:
+        type: string
+      examples:
+        sample1:
+          value: module-set-tag1
     requiredTopicParamInQuery:
       allowReserved: true
       description: mandatory topic name passed from client(NCMP).
index b7f6058..e011b16 100644 (file)
@@ -297,6 +297,17 @@ components:
           value:
             topic: my-topic-name
 
+    moduleSetTagParamInQuery:
+      name: moduleSetTag
+      in: query
+      description: Module set tag of the given cm handle.
+      required: false
+      schema:
+        type: string
+      examples:
+        sample1:
+          value: tag1
+
     requiredRequestIdParamInQuery:
       name: requestId
       in: query
index 6dbc19f..38f21c1 100644 (file)
@@ -128,6 +128,7 @@ paths:
         - $ref: 'components.yml#/components/parameters/resourceIdentifierInQuery'
         - $ref: 'components.yml#/components/parameters/optionsParamInQuery'
         - $ref: 'components.yml#/components/parameters/topicParamInQuery'
+        - $ref: 'components.yml#/components/parameters/moduleSetTagParamInQuery'
       requestBody:
         description: Contains collection of cm handles with it's private properties and requestId
         content:
index 1dcc637..47b9fc3 100644 (file)
@@ -80,16 +80,13 @@ public class DmiRestController implements DmiPluginApi, DmiPluginInternalApi {
         return ResponseEntity.ok(moduleSet);
     }
 
-
     @Override
     public ResponseEntity<YangResources> retrieveModuleResources(
         final String cmHandle,
         final ModuleResourcesReadRequest moduleResourcesReadRequest) {
         final List<ModuleReference> moduleReferences = convertRestObjectToJavaApiObject(moduleResourcesReadRequest);
         final YangResources yangResources = dmiService.getModuleResources(cmHandle, moduleReferences);
-        if (moduleResourcesReadRequest.getModuleSetTag() != null) {
-            log.info("Module set tag received: {}", moduleResourcesReadRequest.getModuleSetTag());
-        }
+        log.info("Module set tag received: {}", moduleResourcesReadRequest.getModuleSetTag());
         return new ResponseEntity<>(yangResources, HttpStatus.OK);
     }
 
@@ -141,7 +138,10 @@ public class DmiRestController implements DmiPluginApi, DmiPluginInternalApi {
                                                         final String resourceIdentifier,
                                                         final String optionsParamInQuery,
                                                         final String topicParamInQuery,
+                                                        final String moduleSetTagParamInQuery,
                                                         final DataAccessRequest dataAccessRequest) {
+
+        log.info("Module set tag received: {}", moduleSetTagParamInQuery);
         if (DatastoreType.PASSTHROUGH_OPERATIONAL == DatastoreType.fromDatastoreName(datastoreName)) {
             return dataAccessPassthroughOperational(resourceIdentifier, cmHandle, dataAccessRequest,
                     optionsParamInQuery, topicParamInQuery);
index a23902f..520e76a 100644 (file)
@@ -21,7 +21,7 @@
 
 package org.onap.cps.ncmp.dmi.rest.controller
 
-import ch.qos.logback.classic.Level
+
 import ch.qos.logback.classic.Logger
 import ch.qos.logback.classic.spi.ILoggingEvent
 import ch.qos.logback.core.read.ListAppender
@@ -221,9 +221,8 @@ class DmiRestControllerSpec extends Specification {
                 .contentType(MediaType.APPLICATION_JSON)
                 .content(jsonData))
         then: 'the module set tag is logged'
-            def loggingEvent = getLoggingEvent()
-            assert loggingEvent.level == Level.INFO
-            assert loggingEvent.formattedMessage.contains('Module set tag received: module-set-tag1')
+            def loggingMessage = getLoggingMessage(0)
+            assert loggingMessage.contains('module-set-tag1')
     }
 
     def 'Get resource data for pass-through operational.'() {
@@ -339,6 +338,19 @@ class DmiRestControllerSpec extends Specification {
             resourceIdentifier << ['passthrough-operational', 'passthrough-running']
     }
 
+    def 'PassThrough logs module set tag'(){
+        given: 'Passthrough read URL and request data with a module set tag (parameter)'
+            def readPassThroughUrl ="${basePathV1}/ch/some-cmHandle/data/ds/ncmp-datastore:" +
+                'passthrough-running?resourceIdentifier=some-resourceIdentifier&moduleSetTag=module-set-tag1'
+            def jsonData = TestUtils.getResourceFileContent('readData.json')
+        when: 'the request is posted'
+            mvc.perform(
+                post(readPassThroughUrl).contentType(MediaType.APPLICATION_JSON).content(jsonData))
+        then: 'response status is OK'
+            def loggingMessage = getLoggingMessage(0)
+            assert loggingMessage.contains('module-set-tag1')
+    }
+
     def 'Get resource data for pass-through running with #scenario value in resource identifier param.'() {
         given: 'Get resource data url'
             def getResourceDataForCmHandleUrl = "${basePathV1}/ch/some-cmHandle/data/ds/ncmp-datastore:passthrough-running" +
@@ -381,7 +393,7 @@ class DmiRestControllerSpec extends Specification {
             assert response.status == 501
     }
 
-    def getLoggingEvent() {
-        return logger.list[0]
+    def getLoggingMessage(int index) {
+        return logger.list[index].formattedMessage
     }
 }
\ No newline at end of file