CPS-2187 - Move Module Set Tag into request body for dmi data access passthrough... 89/138089/6
authordavid.mcweeney <david.mcweeney@est.tech>
Tue, 28 May 2024 11:48:38 +0000 (12:48 +0100)
committerdavid.mcweeney <david.mcweeney@est.tech>
Wed, 29 May 2024 08:58:40 +0000 (09:58 +0100)
Change-Id: I9c807d2ef5b3712bf3f8ee5db7663d9628eef3bb
Signed-off-by: david.mcweeney <david.mcweeney@est.tech>
Issue-ID: CPS-2187

cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiDataOperations.java
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/DmiServiceUrlBuilder.java
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiDataOperationsSpec.groovy
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/DmiServiceUrlBuilderSpec.groovy
dmi-plugin-demo-and-csit-stub/dmi-plugin-demo-and-csit-stub-service/src/main/java/org/onap/cps/ncmp/dmi/rest/stub/controller/DmiRestStubController.java
dmi-plugin-demo-and-csit-stub/dmi-plugin-demo-and-csit-stub-service/src/main/java/org/onap/cps/ncmp/dmi/rest/stub/model/data/operational/DmiDataOperationRequest.java

index 1e92bfe..49894de 100644 (file)
@@ -90,8 +90,7 @@ public class DmiDataOperations extends DmiOperations {
         final String jsonRequestBody = getDmiRequestBody(READ, requestId, null, null, yangModelCmHandle);
 
         final MultiValueMap<String, String> uriQueryParamsMap = getUriQueryParamsMap(
-                cmResourceAddress.resourceIdentifier(), optionsParamInQuery,
-                topicParamInQuery, yangModelCmHandle.getModuleSetTag());
+                cmResourceAddress.resourceIdentifier(), optionsParamInQuery, topicParamInQuery);
         final Map<String, Object> uriVariableParamsMap = getUriVariableParamsMap(cmResourceAddress.datastoreName(),
                 yangModelCmHandle.resolveDmiServiceName(RequiredDmiService.DATA), cmResourceAddress.cmHandleId());
         final String dmiResourceDataUrl = getDmiRequestUrl(uriQueryParamsMap, uriVariableParamsMap);
@@ -115,8 +114,7 @@ public class DmiDataOperations extends DmiOperations {
         final String jsonRequestBody = getDmiRequestBody(READ, requestId, null, null,
                 yangModelCmHandle);
 
-        final MultiValueMap<String, String> uriQueryParamsMap = getUriQueryParamsMap("/", null,
-                null, yangModelCmHandle.getModuleSetTag());
+        final MultiValueMap<String, String> uriQueryParamsMap = getUriQueryParamsMap("/", null, null);
         final Map<String, Object> uriVariableParamsMap = getUriVariableParamsMap(dataStoreName,
                 yangModelCmHandle.resolveDmiServiceName(RequiredDmiService.DATA), cmHandleId);
         final String dmiResourceDataUrl = getDmiRequestUrl(uriQueryParamsMap, uriVariableParamsMap);
@@ -176,8 +174,7 @@ public class DmiDataOperations extends DmiOperations {
         final String jsonRequestBody = getDmiRequestBody(operationType, null, requestData, dataType,
                 yangModelCmHandle);
 
-        final MultiValueMap<String, String> uriQueryParamsMap = getUriQueryParamsMap(resourceId, null,
-                null, yangModelCmHandle.getModuleSetTag());
+        final MultiValueMap<String, String> uriQueryParamsMap = getUriQueryParamsMap(resourceId, null, null);
         final Map<String, Object> uriVariableParamsMap = getUriVariableParamsMap(PASSTHROUGH_RUNNING.getDatastoreName(),
                 yangModelCmHandle.resolveDmiServiceName(RequiredDmiService.DATA), cmHandleId);
         final String dmiUrl = getDmiRequestUrl(uriQueryParamsMap, uriVariableParamsMap);
@@ -201,6 +198,7 @@ public class DmiDataOperations extends DmiOperations {
                 .requestId(requestId)
                 .data(requestData)
                 .dataType(dataType)
+                .moduleSetTag(yangModelCmHandle.getModuleSetTag())
                 .build();
         dmiRequestBody.asDmiProperties(yangModelCmHandle.getDmiProperties());
         return jsonObjectMapper.asJsonString(dmiRequestBody);
@@ -213,10 +211,9 @@ public class DmiDataOperations extends DmiOperations {
 
     private MultiValueMap<String, String> getUriQueryParamsMap(final String resourceId,
                                                                final String optionsParamInQuery,
-                                                               final String topicParamInQuery,
-                                                               final String moduleSetTagParamInQuery) {
+                                                               final String topicParamInQuery) {
         return dmiServiceUrlBuilder.populateQueryParams(resourceId, optionsParamInQuery,
-                topicParamInQuery, moduleSetTagParamInQuery);
+                topicParamInQuery);
     }
 
     private Map<String, Object> getUriVariableParamsMap(final String dataStoreName,
index 9234d3c..15f1eff 100644 (file)
@@ -136,22 +136,17 @@ public class DmiServiceUrlBuilder {
      * @param resourceId          unique id of response for valid topic
      * @param optionsParamInQuery options as provided by client
      * @param topicParamInQuery   topic as provided by client
-     * @param moduleSetTag   module set tag associated with the given cm handle
      * @return all valid query params as map
      */
     public MultiValueMap<String, String> populateQueryParams(final String resourceId,
                                                              final String optionsParamInQuery,
-                                                             final String topicParamInQuery,
-                                                             final String moduleSetTag) {
+                                                             final String topicParamInQuery) {
         final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<>();
         getQueryParamConsumer().accept("resourceIdentifier", resourceId, queryParams);
         getQueryParamConsumer().accept("options", optionsParamInQuery, queryParams);
         if (Strings.isNotEmpty(topicParamInQuery)) {
             getQueryParamConsumer().accept("topic", topicParamInQuery, queryParams);
         }
-        if (Strings.isNotEmpty(moduleSetTag)) {
-            getQueryParamConsumer().accept("moduleSetTag", moduleSetTag, queryParams);
-        }
         return queryParams;
     }
 
index d04052f..9dafd9e 100644 (file)
@@ -84,13 +84,13 @@ class DmiDataOperationsSpec extends DmiOperationsBaseSpec {
         then: 'the result is the response from the DMI service'
             assert result == responseFromDmi
         where: 'the following parameters are used'
-            scenario                               | dmiProperties               | dataStore               | options       || expectedJson                                                 | expectedDatastoreInUrl    | expectedOptionsInUrl
-            'without properties'                   | []                          | PASSTHROUGH_OPERATIONAL | OPTIONS_PARAM || '{"operation":"read","cmHandleProperties":{}}'               | 'passthrough-operational' | '&options=(a=1,b=2)'
-            'with properties'                      | [yangModelCmHandleProperty] | PASSTHROUGH_OPERATIONAL | OPTIONS_PARAM || '{"operation":"read","cmHandleProperties":{"prop1":"val1"}}' | 'passthrough-operational' | '&options=(a=1,b=2)'
-            'null options'                         | [yangModelCmHandleProperty] | PASSTHROUGH_OPERATIONAL | null          || '{"operation":"read","cmHandleProperties":{"prop1":"val1"}}' | 'passthrough-operational' | ''
-            'empty options'                        | [yangModelCmHandleProperty] | PASSTHROUGH_OPERATIONAL | ''            || '{"operation":"read","cmHandleProperties":{"prop1":"val1"}}' | 'passthrough-operational' | ''
-            'datastore running without properties' | []                          | PASSTHROUGH_RUNNING     | OPTIONS_PARAM || '{"operation":"read","cmHandleProperties":{}}'               | 'passthrough-running'     | '&options=(a=1,b=2)'
-            'datastore running with properties'    | [yangModelCmHandleProperty] | PASSTHROUGH_RUNNING     | OPTIONS_PARAM || '{"operation":"read","cmHandleProperties":{"prop1":"val1"}}' | 'passthrough-running'     | '&options=(a=1,b=2)'
+            scenario                               | dmiProperties               | dataStore               | options       || expectedJson                                                                   | expectedDatastoreInUrl    | expectedOptionsInUrl
+            'without properties'                   | []                          | PASSTHROUGH_OPERATIONAL | OPTIONS_PARAM || '{"operation":"read","cmHandleProperties":{},"moduleSetTag":""}'               | 'passthrough-operational' | '&options=(a=1,b=2)'
+            'with properties'                      | [yangModelCmHandleProperty] | PASSTHROUGH_OPERATIONAL | OPTIONS_PARAM || '{"operation":"read","cmHandleProperties":{"prop1":"val1"},"moduleSetTag":""}' | 'passthrough-operational' | '&options=(a=1,b=2)'
+            'null options'                         | [yangModelCmHandleProperty] | PASSTHROUGH_OPERATIONAL | null          || '{"operation":"read","cmHandleProperties":{"prop1":"val1"},"moduleSetTag":""}' | 'passthrough-operational' | ''
+            'empty options'                        | [yangModelCmHandleProperty] | PASSTHROUGH_OPERATIONAL | ''            || '{"operation":"read","cmHandleProperties":{"prop1":"val1"},"moduleSetTag":""}' | 'passthrough-operational' | ''
+            'datastore running without properties' | []                          | PASSTHROUGH_RUNNING     | OPTIONS_PARAM || '{"operation":"read","cmHandleProperties":{},"moduleSetTag":""}'               | 'passthrough-running'     | '&options=(a=1,b=2)'
+            'datastore running with properties'    | [yangModelCmHandleProperty] | PASSTHROUGH_RUNNING     | OPTIONS_PARAM || '{"operation":"read","cmHandleProperties":{"prop1":"val1"},"moduleSetTag":""}' | 'passthrough-running'     | '&options=(a=1,b=2)'
     }
 
     def 'Execute (async) data operation from DMI service.'() {
@@ -130,12 +130,13 @@ class DmiDataOperationsSpec extends DmiOperationsBaseSpec {
     }
 
     def 'call get all resource data.'() {
-        given: 'the system returns a cm handle with a sample property'
-            mockYangModelCmHandleRetrieval([yangModelCmHandleProperty])
+        given: 'the system returns a cm handle with a sample property and sample module set tag'
+            def sampleModuleSetTag = "mod-tag-1"
+            mockYangModelCmHandleRetrieval([yangModelCmHandleProperty], sampleModuleSetTag)
         and: 'a positive response from DMI service when it is called with the expected parameters'
             def responseFromDmi = new ResponseEntity<Object>(HttpStatus.OK)
             def expectedUrl = dmiServiceBaseUrl + "passthrough-operational?resourceIdentifier=/"
-            mockDmiRestClient.postOperationWithJsonData(expectedUrl, '{"operation":"read","cmHandleProperties":{"prop1":"val1"}}', READ, null) >> responseFromDmi
+            mockDmiRestClient.postOperationWithJsonData(expectedUrl, '{"operation":"read","cmHandleProperties":{"prop1":"val1"},"moduleSetTag":"'+sampleModuleSetTag+'"}', READ, null) >> responseFromDmi
             dmiServiceUrlBuilder.getDmiDatastoreUrl(_, _) >> expectedUrl
         when: 'get resource data is invoked'
             def result = objectUnderTest.getResourceDataFromDmi( PASSTHROUGH_OPERATIONAL.datastoreName, cmHandleId, NO_REQUEST_ID)
@@ -148,7 +149,7 @@ class DmiDataOperationsSpec extends DmiOperationsBaseSpec {
             mockYangModelCmHandleRetrieval([yangModelCmHandleProperty])
         and: 'a positive response from DMI service when it is called with the expected parameters'
             def expectedUrl = dmiServiceBaseUrl + "passthrough-running?resourceIdentifier=${resourceIdentifier}"
-            def expectedJson = '{"operation":"' + expectedOperationInUrl + '","dataType":"some data type","data":"requestData","cmHandleProperties":{"prop1":"val1"}}'
+            def expectedJson = '{"operation":"' + expectedOperationInUrl + '","dataType":"some data type","data":"requestData","cmHandleProperties":{"prop1":"val1"},"moduleSetTag":""}'
             def responseFromDmi = new ResponseEntity<Object>(HttpStatus.OK)
             dmiServiceUrlBuilder.getDmiDatastoreUrl(_, _) >> expectedUrl
             mockDmiRestClient.postOperationWithJsonData(expectedUrl, expectedJson, operation, NO_AUTH_HEADER) >> responseFromDmi
index 2c7fa65..827f448 100644 (file)
@@ -48,19 +48,17 @@ class DmiServiceUrlBuilderSpec extends Specification {
         given: 'uri variables'
             def uriVars = objectUnderTest.populateUriVariables(PASSTHROUGH_RUNNING.datastoreName, yangModelCmHandle.resolveDmiServiceName(RequiredDmiService.DATA), 'cmHandle')
         and: 'query params'
-            def uriQueries = objectUnderTest.populateQueryParams(resourceId, 'optionsParamInQuery', topic, moduleSetTag)
+            def uriQueries = objectUnderTest.populateQueryParams(resourceId, 'optionsParamInQuery', topic)
         when: 'a dmi datastore service url is generated'
             def dmiServiceUrl = objectUnderTest.getDmiDatastoreUrl(uriQueries, uriVars)
         then: 'service url is generated as expected'
             assert dmiServiceUrl == expectedDmiServiceUrl
         where: 'the following parameters are used'
-            scenario                       | topic               | moduleSetTag | resourceId   || expectedDmiServiceUrl
-            'With valid resourceId'        | 'topicParamInQuery' | ''                | 'resourceId' || 'dmiServiceName/dmi/v1/ch/cmHandle/data/ds/ncmp-datastore:passthrough-running?resourceIdentifier=resourceId&options=optionsParamInQuery&topic=topicParamInQuery'
-            'With Empty resourceId'        | 'topicParamInQuery' | ''                | ''           || 'dmiServiceName/dmi/v1/ch/cmHandle/data/ds/ncmp-datastore:passthrough-running?options=optionsParamInQuery&topic=topicParamInQuery'
-            'With valid moduleSetTag'      | 'topicParamInQuery' | 'module-set-tag1' | 'resourceId' || 'dmiServiceName/dmi/v1/ch/cmHandle/data/ds/ncmp-datastore:passthrough-running?resourceIdentifier=resourceId&options=optionsParamInQuery&topic=topicParamInQuery&moduleSetTag=module-set-tag1'
-            'With Empty moduleSetTag'      | 'topicParamInQuery' | ''                | 'resourceId' || 'dmiServiceName/dmi/v1/ch/cmHandle/data/ds/ncmp-datastore:passthrough-running?resourceIdentifier=resourceId&options=optionsParamInQuery&topic=topicParamInQuery'
-            'With Empty dmi base path'     | 'topicParamInQuery' | ''                | 'resourceId' || 'dmiServiceName/dmi/v1/ch/cmHandle/data/ds/ncmp-datastore:passthrough-running?resourceIdentifier=resourceId&options=optionsParamInQuery&topic=topicParamInQuery'
-            'With Empty topicParamInQuery' | ''                  | ''                | 'resourceId' || 'dmiServiceName/dmi/v1/ch/cmHandle/data/ds/ncmp-datastore:passthrough-running?resourceIdentifier=resourceId&options=optionsParamInQuery'
+            scenario                       | topic               | resourceId   || expectedDmiServiceUrl
+            'With valid resourceId'        | 'topicParamInQuery' | 'resourceId' || 'dmiServiceName/dmi/v1/ch/cmHandle/data/ds/ncmp-datastore:passthrough-running?resourceIdentifier=resourceId&options=optionsParamInQuery&topic=topicParamInQuery'
+            'With Empty resourceId'        | 'topicParamInQuery' | ''           || 'dmiServiceName/dmi/v1/ch/cmHandle/data/ds/ncmp-datastore:passthrough-running?options=optionsParamInQuery&topic=topicParamInQuery'
+            'With Empty dmi base path'     | 'topicParamInQuery' | 'resourceId' || 'dmiServiceName/dmi/v1/ch/cmHandle/data/ds/ncmp-datastore:passthrough-running?resourceIdentifier=resourceId&options=optionsParamInQuery&topic=topicParamInQuery'
+            'With Empty topicParamInQuery' | ''                  | 'resourceId' || 'dmiServiceName/dmi/v1/ch/cmHandle/data/ds/ncmp-datastore:passthrough-running?resourceIdentifier=resourceId&options=optionsParamInQuery'
     }
 
     def 'Populate dmi data store url #scenario.'() {
@@ -68,7 +66,7 @@ class DmiServiceUrlBuilderSpec extends Specification {
             dmiProperties.dmiBasePath = dmiBasePath
             def uriVars = objectUnderTest.populateUriVariables(PASSTHROUGH_RUNNING.datastoreName, yangModelCmHandle.resolveDmiServiceName(RequiredDmiService.DATA), 'cmHandle')
         and: 'null query params'
-            def uriQueries = objectUnderTest.populateQueryParams(null, null, null, null)
+            def uriQueries = objectUnderTest.populateQueryParams(null, null, null)
         when: 'a dmi datastore service url is generated'
             def dmiServiceUrl = objectUnderTest.getDmiDatastoreUrl(uriQueries, uriVars)
         then: 'the created dmi service url matches the expected'
index a596afd..005aa22 100644 (file)
@@ -205,11 +205,11 @@ public class DmiRestStubController {
             @RequestParam(value = "resourceIdentifier") final String resourceIdentifier,
             @RequestParam(value = "options", required = false) final String options,
             @RequestParam(value = "topic", required = false) final String topic,
-            @RequestParam(value = "moduleSetTag", required = false) final String moduleSetTag,
-            @RequestHeader(value = "Authorization", required = false) final String authorization) {
+            @RequestHeader(value = "Authorization", required = false) final String authorization,
+            @RequestBody final String requestBody) {
         log.info("DMI AUTH HEADER: {}", authorization);
         delay(dataForCmHandleDelayMs);
-        log.info("Module set tag received: {}", moduleSetTag);
+        log.info("Logging request body {}", requestBody);
 
         final String sampleJson = ResourceFileReaderUtil.getResourceFileContent(applicationContext.getResource(
                 ResourceLoader.CLASSPATH_URL_PREFIX + "data/operational/ietf-network-topology-sample-rfc8345.json"));