Get resource data for pass-through running (dmi-impl) 83/123383/1
authortragait <rahul.tyagi@est.tech>
Thu, 19 Aug 2021 10:19:54 +0000 (11:19 +0100)
committertragait <rahul.tyagi@est.tech>
Thu, 19 Aug 2021 10:19:59 +0000 (11:19 +0100)
Issue-ID: CPS-561
Signed-off-by: tragait <rahul.tyagi@est.tech>
Change-Id: Ia92a97296e2c3e84d0b6f6d9d1d0daf1e8f46b55

docs/openapi/components.yml
docs/openapi/openapi.yml
src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java
src/main/java/org/onap/cps/ncmp/dmi/service/DmiService.java
src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java
src/main/java/org/onap/cps/ncmp/dmi/service/operation/SdncOperations.java
src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy
src/test/groovy/org/onap/cps/ncmp/dmi/service/DmiServiceImplSpec.groovy
src/test/groovy/org/onap/cps/ncmp/dmi/service/operation/SdncOperationsSpec.groovy

index 3d8aa2c..cb39fa4 100644 (file)
@@ -123,4 +123,37 @@ components:
       description: The identifier for a network function, network element, subnetwork, or any other cm object by managed Network CM Proxy
       required: true
       schema:
-        type: string
\ No newline at end of file
+        type: string
+
+    resourceIdentifierInPath:
+      name: resourceIdentifier
+      in: path
+      description: Resource identifier to get/set the resource data
+      required: true
+      schema:
+        type: string
+
+    acceptParamInHeader:
+      name: accept
+      in: header
+      description: Accept parameter for response, if accept parameter is null, that means client can accept any format.
+      schema:
+        type: string
+        enum: [ application/json, application/yang-data+json ]
+
+    fieldsParamInQuery:
+      name: fields
+      in: query
+      description: Fields parameter to filter resource
+      required: false
+      schema:
+        type: string
+
+    depthParamInQuery:
+      name: depth
+      in: query
+      description: Depth parameter for response
+      required: false
+      schema:
+        type: integer
+        minimum: 1
\ No newline at end of file
index 114c521..af285f4 100644 (file)
@@ -122,36 +122,44 @@ paths:
     put:
       tags:
         - dmi-plugin
-      summary: Get resource data for cm handle
-      description: Get resource data for given cm handle
+      summary: Get resource data from passthrough-operational for cm handle
+      description: Get resource data from passthrough-operational for cm handle
       operationId: getResourceDataOperationalForCmHandle
       parameters:
         - $ref: 'components.yml#/components/parameters/cmHandleInPath'
-        - name: resourceIdentifier
-          in: path
-          description: Resource identifier to fetch the resource data
-          required: true
-          schema:
-            type: string
-        - name: accept
-          in: header
-          description: Accept parameter for response, if accept parameter is null, that means client can accept any format.
-          schema:
-            type: string
-            enum: [ application/json, application/yang-data+json ]
-        - name: fields
-          in: query
-          description: Fields parameter to filter resource
-          required: false
-          schema:
-            type: string
-        - name: depth
-          in: query
-          description: Depth parameter for response
-          required: false
-          schema:
-            type: integer
-            minimum: 1
+        - $ref: 'components.yml#/components/parameters/resourceIdentifierInPath'
+        - $ref: 'components.yml#/components/parameters/acceptParamInHeader'
+        - $ref: 'components.yml#/components/parameters/fieldsParamInQuery'
+        - $ref: 'components.yml#/components/parameters/depthParamInQuery'
+      requestBody:
+        description: Operational body
+        content:
+          application/json:
+            schema:
+              $ref: 'components.yml#/components/schemas/OperationalRequest'
+      responses:
+        '200':
+          $ref: 'components.yml#/components/responses/Ok'
+        '400':
+          $ref: 'components.yml#/components/responses/BadRequest'
+        '401':
+          $ref: 'components.yml#/components/responses/Unauthorized'
+        '403':
+          $ref: 'components.yml#/components/responses/Forbidden'
+
+  /v1/ch/{cmHandle}/data/ds/ncmp-datastore:passthrough-running/{resourceIdentifier}:
+    put:
+      tags:
+        - dmi-plugin
+      summary: Get resource data from passthrough-running for cm handle
+      description: Get resource data from passthrough-running for cm handle
+      operationId: getResourceDataPassthroughRunningForCmHandle
+      parameters:
+        - $ref: 'components.yml#/components/parameters/cmHandleInPath'
+        - $ref: 'components.yml#/components/parameters/resourceIdentifierInPath'
+        - $ref: 'components.yml#/components/parameters/acceptParamInHeader'
+        - $ref: 'components.yml#/components/parameters/fieldsParamInQuery'
+        - $ref: 'components.yml#/components/parameters/depthParamInQuery'
       requestBody:
         description: Operational body
         content:
index 3d49b78..79c11a4 100644 (file)
@@ -24,6 +24,7 @@ import com.fasterxml.jackson.core.type.TypeReference;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import java.util.List;
 import javax.validation.Valid;
+import javax.validation.constraints.Min;
 import lombok.extern.slf4j.Slf4j;
 import org.onap.cps.ncmp.dmi.model.CmHandles;
 import org.onap.cps.ncmp.dmi.model.ModuleReference;
@@ -89,7 +90,7 @@ public class DmiRestController implements DmiPluginApi, DmiPluginInternalApi {
 
     /**
      * This method fetches the resource for given cm handle using pass
-     * through option. It filters the response on the basis of depth and field
+     * through operational. It filters the response on the basis of depth and field
      * query parameters and returns response.
      *
      * @param cmHandle cm handle identifier
@@ -106,7 +107,7 @@ public class DmiRestController implements DmiPluginApi, DmiPluginInternalApi {
                                                                         final @Valid OperationalRequest body,
                                                                         final String accept,
                                                                         final @Valid String fields,
-                                                                        final @Valid Integer depth) {
+                                                                        final @Min(1) @Valid Integer depth) {
         final var modulesListAsJson = dmiService.getResourceDataOperationalForCmHandle(cmHandle,
                 resourceIdentifier,
                 accept,
@@ -116,6 +117,35 @@ public class DmiRestController implements DmiPluginApi, DmiPluginInternalApi {
         return ResponseEntity.ok(modulesListAsJson);
     }
 
+    /**
+     * This method fetches the resource for given cm handle using pass
+     * through running. It filters the response on the basis of depth and field
+     * query parameters and returns response.
+     *
+     * @param cmHandle cm handle identifier
+     * @param resourceIdentifier resource identifier to fetch data
+     * @param body operational body
+     * @param accept accept header parameter
+     * @param fields fields to filter the response data
+     * @param depth depth parameter for the response
+     * @return {@code ResponseEntity} response entity
+     */
+    @Override
+    public ResponseEntity<Object> getResourceDataPassthroughRunningForCmHandle(final String cmHandle,
+                                                                               final String resourceIdentifier,
+                                                                               final @Valid OperationalRequest body,
+                                                                               final String accept,
+                                                                               final @Valid String fields,
+                                                                               final @Min(1) @Valid Integer depth) {
+        final var modulesListAsJson = dmiService.getResourceDataPassThroughRunningForCmHandle(cmHandle,
+                resourceIdentifier,
+                accept,
+                fields,
+                depth,
+                body.getCmHandleProperties());
+        return ResponseEntity.ok(modulesListAsJson);
+    }
+
     private List<ModuleReference> convertRestObjectToJavaApiObject(final ModuleRequestParent moduleRequestParent) {
         return objectMapper
             .convertValue(moduleRequestParent.getData().getModules(), new TypeReference<List<ModuleReference>>() {
index a7c9434..8330127 100644 (file)
@@ -60,7 +60,7 @@ public interface DmiService {
 
     /**
      * This method use to fetch the resource data from cm handle
-     * for given datasource and Identifier. Fields and depths query
+     * for datastore pass-through operational and resource Identifier. Fields and depths query
      * parameter are used to filter the response from network resource.
      *
      * @param cmHandle cm handle identifier
@@ -78,4 +78,25 @@ public interface DmiService {
                                       String fieldsQuery,
                                       Integer depthQuery,
                                       Map<String, String> cmHandlePropertyMap);
+
+    /**
+     * This method use to fetch the resource data from cm handle
+     * for datastore pass-through running and resource Identifier. Fields and depths query
+     * parameter are used to filter the response from network resource.
+     *
+     * @param cmHandle cm handle identifier
+     * @param resourceIdentifier resource identifier
+     * @param acceptParam accept header parameter
+     * @param fieldsQuery fields query parameter
+     * @param depthQuery depth query parameter
+     * @param cmHandlePropertyMap cm handle properties
+     *
+     * @return {@code Object} response from network function
+     */
+    Object getResourceDataPassThroughRunningForCmHandle(@NotNull String cmHandle,
+                                                 @NotNull String resourceIdentifier,
+                                                 String acceptParam,
+                                                 String fieldsQuery,
+                                                 Integer depthQuery,
+                                                 Map<String, String> cmHandlePropertyMap);
 }
\ No newline at end of file
index 94bd97d..1ee5acf 100644 (file)
@@ -26,10 +26,10 @@ import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import javax.validation.constraints.NotNull;
 import lombok.extern.slf4j.Slf4j;
 import net.minidev.json.JSONArray;
 import org.apache.groovy.parser.antlr4.util.StringUtils;
-import org.jetbrains.annotations.NotNull;
 import org.onap.cps.ncmp.dmi.config.DmiPluginConfig.DmiPluginProperties;
 import org.onap.cps.ncmp.dmi.exception.CmHandleRegistrationException;
 import org.onap.cps.ncmp.dmi.exception.DmiException;
@@ -57,6 +57,8 @@ public class DmiServiceImpl implements DmiService {
     private NcmpRestClient ncmpRestClient;
     private ObjectMapper objectMapper;
     private DmiPluginProperties dmiPluginProperties;
+    private static final String CONTENT_QUERY_PASSTHROUGH_OPERATIONAL = "content=all";
+    private static final String CONTENT_QUERY_PASSTHROUGH_RUNNING = "content=config";
 
     /**
      * Constructor.
@@ -172,11 +174,29 @@ public class DmiServiceImpl implements DmiService {
                                              final Integer depthQuery,
                                              final Map<String, String> cmHandlePropertyMap) {
         // not using cmHandlePropertyMap of onap dmi impl , other dmi impl might use this.
-        final ResponseEntity<String> responseEntity = sdncOperations.getResouceDataForOperational(cmHandle,
+        final ResponseEntity<String> responseEntity = sdncOperations.getResouceDataForOperationalAndRunning(cmHandle,
                 resourceIdentifier,
                 fieldsQuery,
                 depthQuery,
-                acceptParam);
+                acceptParam,
+                CONTENT_QUERY_PASSTHROUGH_OPERATIONAL);
+        return prepareAndSendResponse(responseEntity, cmHandle);
+    }
+
+    @Override
+    public Object getResourceDataPassThroughRunningForCmHandle(final @NotNull String cmHandle,
+                                                               final @NotNull String resourceIdentifier,
+                                                               final String acceptParam,
+                                                               final String fieldsQuery,
+                                                               final Integer depthQuery,
+                                                               final Map<String, String> cmHandlePropertyMap) {
+        // not using cmHandlePropertyMap of onap dmi impl , other dmi impl might use this.
+        final ResponseEntity<String> responseEntity = sdncOperations.getResouceDataForOperationalAndRunning(cmHandle,
+                resourceIdentifier,
+                fieldsQuery,
+                depthQuery,
+                acceptParam,
+                CONTENT_QUERY_PASSTHROUGH_RUNNING);
         return prepareAndSendResponse(responseEntity, cmHandle);
     }
 
index 358da59..2e1faf4 100644 (file)
@@ -94,14 +94,15 @@ public class SdncOperations {
      * @param acceptParam accept parameter
      * @return {@code ResponseEntity} response entity
      */
-    public ResponseEntity<String> getResouceDataForOperational(final String nodeId,
-                                                               final String resourceId,
-                                                               final String fieldsValue,
-                                                               final Integer depthValue,
-                                                               final String acceptParam) {
+    public ResponseEntity<String> getResouceDataForOperationalAndRunning(final String nodeId,
+                                                                         final String resourceId,
+                                                                         final String fieldsValue,
+                                                                         final Integer depthValue,
+                                                                         final String acceptParam,
+                                                                         final String contentQuery) {
         final String getResourceDataUrl = prepareResourceDataUrl(nodeId,
                 resourceId,
-                getQueryList(fieldsValue, depthValue, "content=all"));
+                getQueryList(fieldsValue, depthValue, contentQuery));
         final HttpHeaders httpHeaders = new HttpHeaders();
         if (!StringUtils.isEmpty(acceptParam)) {
             httpHeaders.set(HttpHeaders.ACCEPT, acceptParam);
index f24f65a..b1528c7 100644 (file)
@@ -186,12 +186,12 @@ class DmiRestControllerSpec extends Specification {
             response.status == HttpStatus.NOT_FOUND.value()
     }
 
-    def 'Get resource data for cm handle.'() {
+    def 'Get resource data for pass-through operational from cm handle.'() {
         given: 'Get resource data url'
             def getResourceDataForCmHandleUrl = "${basePathV1}/ch/some-cmHandle/data/ds/ncmp-datastore:passthrough-operational" +
                     "/resourceIdentifier?fields=myfields&depth=5"
             def json = '{"cmHandleProperties" : { "prop1" : "value1", "prop2" : "value2"}}'
-        when: 'get resource data GET api is invoked'
+        when: 'get resource data PUT api is invoked'
             def response = mvc.perform(
                     put(getResourceDataForCmHandleUrl).contentType(MediaType.APPLICATION_JSON)
                             .accept(MediaType.APPLICATION_JSON).content(json)
@@ -206,4 +206,25 @@ class DmiRestControllerSpec extends Specification {
                     5,
                     ['prop1':'value1', 'prop2':'value2'])
     }
+
+    def 'Get resource data for pass-through running from cm handle.'() {
+        given: 'Get resource data url'
+            def getResourceDataForCmHandleUrl = "${basePathV1}/ch/some-cmHandle/data/ds/ncmp-datastore:passthrough-running" +
+                     "/testResourceIdentifier?fields=testFields&depth=5"
+            def json = '{"cmHandleProperties" : { "prop1" : "value1", "prop2" : "value2"}}'
+        when: 'get resource data PUT api is invoked'
+            def response = mvc.perform(
+                    put(getResourceDataForCmHandleUrl).contentType(MediaType.APPLICATION_JSON)
+                            .accept(MediaType.APPLICATION_JSON).content(json)
+            ).andReturn().response
+        then: 'response status is ok'
+            response.status == HttpStatus.OK.value()
+        and: 'dmi service called with get resource data for cm handle'
+            1 * mockDmiService.getResourceDataPassThroughRunningForCmHandle('some-cmHandle',
+                    'testResourceIdentifier',
+                    'application/json',
+                    'testFields',
+                    5,
+                    ['prop1':'value1', 'prop2':'value2'])
+    }
 }
\ No newline at end of file
index e456d41..31b60a7 100644 (file)
@@ -30,8 +30,6 @@ import org.onap.cps.ncmp.dmi.exception.ModuleResourceNotFoundException
 import org.onap.cps.ncmp.dmi.exception.ModulesNotFoundException
 import org.onap.cps.ncmp.dmi.exception.ResourceDataNotFound
 import org.onap.cps.ncmp.dmi.model.ModuleReference
-import org.onap.cps.ncmp.dmi.model.ModuleSchemaList
-import org.onap.cps.ncmp.dmi.model.ModuleSchemas
 import org.onap.cps.ncmp.dmi.service.client.NcmpRestClient
 import org.onap.cps.ncmp.dmi.service.operation.SdncOperations
 import org.springframework.http.HttpStatus
@@ -166,15 +164,17 @@ class DmiServiceImplSpec extends Specification {
             thrown(ModuleResourceNotFoundException)
     }
 
-    def 'Get resource data from cm handle.'() {
+    def 'Get resource data for pass through operational from cm handle.'() {
         given: 'cm-handle, pass through parameter, resourceId, accept header, fields, depth'
             def cmHandle = 'testCmHandle'
             def resourceId = 'testResourceId'
             def acceptHeaderParam = 'testAcceptParam'
             def fieldsParam = 'testFields'
             def depthParam = 10
+            def contentQuery = 'content=all'
         and: 'sdnc operation returns OK response'
-            mockSdncOperations.getResouceDataForOperational(cmHandle, resourceId, fieldsParam, depthParam, acceptHeaderParam ) >> new ResponseEntity<>('response json', HttpStatus.OK)
+            mockSdncOperations.getResouceDataForOperationalAndRunning(cmHandle, resourceId, fieldsParam,
+                    depthParam, acceptHeaderParam,  contentQuery) >> new ResponseEntity<>('response json', HttpStatus.OK)
         when: 'get resource data from cm handles service method invoked'
             def response = objectUnderTest.getResourceDataOperationalForCmHandle(cmHandle,
                     resourceId, acceptHeaderParam,
@@ -191,8 +191,8 @@ class DmiServiceImplSpec extends Specification {
             def fieldsParam = 'testFields'
             def depthParam = 10
         and: 'sdnc operation returns "NOT_FOUND" response'
-            mockSdncOperations.getResouceDataForOperational(cmHandle, resourceId, fieldsParam, depthParam, acceptHeaderParam )
-                    >> new ResponseEntity<>(HttpStatus.NOT_FOUND)
+            mockSdncOperations.getResouceDataForOperationalAndRunning(cmHandle, resourceId, fieldsParam,
+                    depthParam, acceptHeaderParam, _ as String) >> new ResponseEntity<>(HttpStatus.NOT_FOUND)
         when: 'get resource data from cm handles service method invoked'
             objectUnderTest.getResourceDataOperationalForCmHandle(cmHandle,
                     resourceId, acceptHeaderParam,
@@ -200,4 +200,23 @@ class DmiServiceImplSpec extends Specification {
         then: 'resource data not found'
             thrown(ResourceDataNotFound.class)
     }
+
+    def 'Get resource data for pass through running from cm handle.'() {
+        given: 'cm-handle, pass through parameter, resourceId, accept header, fields, depth'
+            def cmHandle = 'testCmHandle'
+            def resourceId = 'testResourceId'
+            def acceptHeaderParam = 'testAcceptParam'
+            def fieldsParam = 'testFields'
+            def depthParam = 10
+            def contentQuery = 'content=config'
+        and: 'sdnc operation returns OK response'
+            mockSdncOperations.getResouceDataForOperationalAndRunning(cmHandle, resourceId, fieldsParam,
+                    depthParam, acceptHeaderParam,  contentQuery) >> new ResponseEntity<>('response json', HttpStatus.OK)
+        when: 'get resource data from cm handles service method invoked'
+            def response = objectUnderTest.getResourceDataPassThroughRunningForCmHandle(cmHandle,
+                    resourceId, acceptHeaderParam,
+                    fieldsParam, depthParam, null)
+        then: 'response have expected json'
+            response == 'response json'
+    }
 }
\ No newline at end of file
index 8a415c8..3557bc1 100644 (file)
@@ -61,9 +61,10 @@ class SdncOperationsSpec extends Specification {
 
     def 'Get resource data from node to SDNC.'() {
         given: 'excpected url, topology-id, sdncOperation object'
-            def expectedUrl = '/rests/data/network-topology:network-topology/topology=test-topology/node=node1/yang-ext:mount/testResourceId?fields=testFields&depth=10&content=all'
+            def expectedUrl = '/rests/data/network-topology:network-topology/topology=test-topology/node=node1/yang-ext:mount/testResourceId?fields=testFields&depth=10&content=testContent'
         when: 'called get modules from node'
-            objectUnderTest.getResouceDataForOperational('node1', 'testResourceId',  'testFields', 10,'testAcceptParam')
+            objectUnderTest.getResouceDataForOperationalAndRunning('node1', 'testResourceId',
+                    'testFields', 10, 'testAcceptParam', 'content=testContent')
         then: 'the get operation is executed with the correct URL'
             1 * mockSdncRestClient.getOperation(expectedUrl, _ as HttpHeaders)
     }