CPS-2181 - #2 Included Module Set Tag as incoming param for Yang Module Resources... 37/137837/6
authordavid.mcweeney <david.mcweeney@est.tech>
Tue, 30 Apr 2024 09:24:41 +0000 (10:24 +0100)
committerdavid.mcweeney <david.mcweeney@est.tech>
Wed, 15 May 2024 12:55:01 +0000 (13:55 +0100)
Change-Id: I799159798d9c6018a1495c61924111610bbe2978
Signed-off-by: david.mcweeney <david.mcweeney@est.tech>
Issue-ID: CPS-2181

docs/api/swagger/openapi.yaml
openapi/components.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
src/test/resources/moduleResources.json

index 4e3ae89..f3516b5 100644 (file)
@@ -493,6 +493,7 @@ components:
       type: object
     ModuleResourcesReadRequest:
       example:
+        moduleSetTag: module-set-tag1
         data:
           modules:
             - name: my-name
index 00d7156..b7f6058 100644 (file)
@@ -101,6 +101,11 @@ components:
     ModuleResourcesReadRequest:
       type: object
       properties:
+        moduleSetTag:
+          type: string
+          description: Module set tag of the given cm handle
+          example: Module-set-tag-1
+          required: false
         data:
           type: object
           properties:
index 2ed1ebd..1dcc637 100644 (file)
@@ -87,6 +87,9 @@ public class DmiRestController implements DmiPluginApi, DmiPluginInternalApi {
         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());
+        }
         return new ResponseEntity<>(yangResources, HttpStatus.OK);
     }
 
index 7b2570b..a23902f 100644 (file)
 
 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
 import org.onap.cps.ncmp.dmi.TestUtils
 import org.onap.cps.ncmp.dmi.config.WebSecurityConfig
 import org.onap.cps.ncmp.dmi.exception.DmiException
@@ -34,6 +38,7 @@ import org.onap.cps.ncmp.dmi.notifications.async.AsyncTaskExecutor
 import org.onap.cps.ncmp.dmi.notifications.async.DmiAsyncRequestResponseEventProducer
 import org.onap.cps.ncmp.dmi.service.DmiService
 import org.onap.cps.ncmp.dmi.service.model.ModuleReference
+import org.slf4j.LoggerFactory
 import org.spockframework.spring.SpringBean
 import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.beans.factory.annotation.Value
@@ -75,6 +80,17 @@ class DmiRestControllerSpec extends Specification {
     @SpringBean
     AsyncTaskExecutor asyncTaskExecutor = new AsyncTaskExecutor(cpsAsyncRequestResponseEventProducer)
 
+    def logger = Spy(ListAppender<ILoggingEvent>)
+
+    void setup() {
+        ((Logger) LoggerFactory.getLogger(DmiRestController.class)).addAppender(logger)
+        logger.start()
+    }
+
+    void cleanup() {
+        ((Logger) LoggerFactory.getLogger(DmiRestController.class)).detachAndStopAllAppenders()
+    }
+
     @Value('${rest.api.dmi-base-path}/v1')
     def basePathV1
 
@@ -189,6 +205,27 @@ class DmiRestControllerSpec extends Specification {
             response.status == HttpStatus.NOT_FOUND.value()
     }
 
+    def 'Retrieve module resources and ensure module set tag is logged.'() {
+        given: 'URL to get module resources'
+            def getModulesEndpoint = "$basePathV1/ch/some-cm-handle/moduleResources"
+        and: 'request data to get some modules'
+            String jsonData = TestUtils.getResourceFileContent('moduleResources.json')
+        and: 'the DMI service returns the yang resources'
+            def moduleReferences = []
+            def yangResources = new YangResources()
+            def yangResource = new YangResource()
+            yangResources.add(yangResource)
+            mockDmiService.getModuleResources('some-cm-handle', moduleReferences) >> yangResources
+        when: 'the request is posted'
+            mvc.perform(post(getModulesEndpoint)
+                .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 'Get resource data for pass-through operational.'() {
         given: 'Get resource data url and some request data'
             def getResourceDataForCmHandleUrl = "${basePathV1}/ch/some-cmHandle/data/ds/ncmp-datastore:passthrough-operational" +
@@ -343,4 +380,8 @@ class DmiRestControllerSpec extends Specification {
         then: 'the resource data operation endpoint returns the not implemented response'
             assert response.status == 501
     }
+
+    def getLoggingEvent() {
+        return logger.list[0]
+    }
 }
\ No newline at end of file
index 57f5aef..23adfcb 100644 (file)
@@ -13,5 +13,6 @@
   },
   "cmHandleProperties": {
     "subsystemId": "system-001"
-  }
+  },
+  "moduleSetTag": "module-set-tag1"
 }