summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/openapi/components.yml35
-rw-r--r--docs/openapi/openapi.yml62
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java34
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/service/DmiService.java23
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java26
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/service/operation/SdncOperations.java13
-rw-r--r--src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy25
-rw-r--r--src/test/groovy/org/onap/cps/ncmp/dmi/service/DmiServiceImplSpec.groovy31
-rw-r--r--src/test/groovy/org/onap/cps/ncmp/dmi/service/operation/SdncOperationsSpec.groovy5
9 files changed, 204 insertions, 50 deletions
diff --git a/docs/openapi/components.yml b/docs/openapi/components.yml
index 3d8aa2cf..cb39fa4e 100644
--- a/docs/openapi/components.yml
+++ b/docs/openapi/components.yml
@@ -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
diff --git a/docs/openapi/openapi.yml b/docs/openapi/openapi.yml
index 114c521e..af285f4e 100644
--- a/docs/openapi/openapi.yml
+++ b/docs/openapi/openapi.yml
@@ -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:
diff --git a/src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java b/src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java
index 3d49b78e..79c11a4e 100644
--- a/src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java
+++ b/src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java
@@ -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>>() {
diff --git a/src/main/java/org/onap/cps/ncmp/dmi/service/DmiService.java b/src/main/java/org/onap/cps/ncmp/dmi/service/DmiService.java
index a7c94349..83301270 100644
--- a/src/main/java/org/onap/cps/ncmp/dmi/service/DmiService.java
+++ b/src/main/java/org/onap/cps/ncmp/dmi/service/DmiService.java
@@ -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
diff --git a/src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java b/src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java
index 94bd97d7..1ee5acf0 100644
--- a/src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java
+++ b/src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java
@@ -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);
}
diff --git a/src/main/java/org/onap/cps/ncmp/dmi/service/operation/SdncOperations.java b/src/main/java/org/onap/cps/ncmp/dmi/service/operation/SdncOperations.java
index 358da590..2e1faf48 100644
--- a/src/main/java/org/onap/cps/ncmp/dmi/service/operation/SdncOperations.java
+++ b/src/main/java/org/onap/cps/ncmp/dmi/service/operation/SdncOperations.java
@@ -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);
diff --git a/src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy b/src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy
index f24f65a8..b1528c71 100644
--- a/src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy
+++ b/src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy
@@ -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
diff --git a/src/test/groovy/org/onap/cps/ncmp/dmi/service/DmiServiceImplSpec.groovy b/src/test/groovy/org/onap/cps/ncmp/dmi/service/DmiServiceImplSpec.groovy
index e456d411..31b60a7c 100644
--- a/src/test/groovy/org/onap/cps/ncmp/dmi/service/DmiServiceImplSpec.groovy
+++ b/src/test/groovy/org/onap/cps/ncmp/dmi/service/DmiServiceImplSpec.groovy
@@ -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
diff --git a/src/test/groovy/org/onap/cps/ncmp/dmi/service/operation/SdncOperationsSpec.groovy b/src/test/groovy/org/onap/cps/ncmp/dmi/service/operation/SdncOperationsSpec.groovy
index 8a415c82..3557bc1b 100644
--- a/src/test/groovy/org/onap/cps/ncmp/dmi/service/operation/SdncOperationsSpec.groovy
+++ b/src/test/groovy/org/onap/cps/ncmp/dmi/service/operation/SdncOperationsSpec.groovy
@@ -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)
}