summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-rest
diff options
context:
space:
mode:
authortragait <rahul.tyagi@est.tech>2021-08-16 15:12:36 +0100
committertragait <rahul.tyagi@est.tech>2021-08-19 12:46:37 +0100
commitc328551bdfd069343cc4c4e0249516d07938c78a (patch)
tree5beae0e58a123d67a4e89e904bc24d5239942437 /cps-ncmp-rest
parent24112c0a500e94dc6068be71105874f8d81678b7 (diff)
get resource data for operational passthrough
Issue-ID: CPS-487 Signed-off-by: tragait <rahul.tyagi@est.tech> Change-Id: Id1b761f3f6a388556d0cc334fd6f196c78badc39
Diffstat (limited to 'cps-ncmp-rest')
-rw-r--r--cps-ncmp-rest/docs/openapi/components.yaml30
-rwxr-xr-xcps-ncmp-rest/docs/openapi/ncmproxy.yml27
-rwxr-xr-xcps-ncmp-rest/docs/openapi/openapi.yml7
-rwxr-xr-xcps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java24
-rwxr-xr-xcps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandler.java14
-rw-r--r--cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy20
6 files changed, 120 insertions, 2 deletions
diff --git a/cps-ncmp-rest/docs/openapi/components.yaml b/cps-ncmp-rest/docs/openapi/components.yaml
index 9921041cf8..4f5a6a13e4 100644
--- a/cps-ncmp-rest/docs/openapi/components.yaml
+++ b/cps-ncmp-rest/docs/openapi/components.yaml
@@ -96,6 +96,36 @@ components:
schema:
type: string
default: /
+ resourceIdentifierInPath:
+ name: resourceIdentifier
+ in: path
+ description: Resource identifier to get/set the resource data
+ required: true
+ schema:
+ type: string
+ acceptParamInHeader:
+ name: accept
+ in: header
+ required: false
+ 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
responses:
diff --git a/cps-ncmp-rest/docs/openapi/ncmproxy.yml b/cps-ncmp-rest/docs/openapi/ncmproxy.yml
index 3ec7bfd115..ede0ec62f0 100755
--- a/cps-ncmp-rest/docs/openapi/ncmproxy.yml
+++ b/cps-ncmp-rest/docs/openapi/ncmproxy.yml
@@ -200,4 +200,29 @@ updateDmiRegistration:
401:
$ref: 'components.yaml#/components/responses/Unauthorized'
403:
- $ref: 'components.yaml#/components/responses/Forbidden' \ No newline at end of file
+ $ref: 'components.yaml#/components/responses/Forbidden'
+
+getResourceDataForPassthroughOperational:
+ get:
+ tags:
+ - network-cm-proxy
+ summary: Get resource data from pass-through operational for cm handle
+ description: Get resource data from pass-through operational for given cm handle
+ operationId: getResourceDataOperationalForCmHandle
+ parameters:
+ - $ref: 'components.yaml#/components/parameters/cmHandleInPath'
+ - $ref: 'components.yaml#/components/parameters/resourceIdentifierInPath'
+ - $ref: 'components.yaml#/components/parameters/acceptParamInHeader'
+ - $ref: 'components.yaml#/components/parameters/fieldsParamInQuery'
+ - $ref: 'components.yaml#/components/parameters/depthParamInQuery'
+ responses:
+ 200:
+ $ref: 'components.yaml#/components/responses/Ok'
+ 400:
+ $ref: 'components.yaml#/components/responses/BadRequest'
+ 401:
+ $ref: 'components.yaml#/components/responses/Unauthorized'
+ 403:
+ $ref: 'components.yaml#/components/responses/Forbidden'
+ 404:
+ $ref: 'components.yaml#/components/responses/NotFound' \ No newline at end of file
diff --git a/cps-ncmp-rest/docs/openapi/openapi.yml b/cps-ncmp-rest/docs/openapi/openapi.yml
index 64de9223fb..5b7c8d205b 100755
--- a/cps-ncmp-rest/docs/openapi/openapi.yml
+++ b/cps-ncmp-rest/docs/openapi/openapi.yml
@@ -38,4 +38,9 @@ paths:
$ref: 'ncmproxy.yml#/nodesByCmHandleAndXpath'
/ncmp-dmi/v1/ch:
- $ref: 'ncmproxy.yml#/updateDmiRegistration' \ No newline at end of file
+ $ref: 'ncmproxy.yml#/updateDmiRegistration'
+
+ /v1/ch/{cm-handle}/data/ds/ncmp-datastore:passthrough-operational/{resourceIdentifier}:
+ $ref: 'ncmproxy.yml#/getResourceDataForPassthroughOperational'
+
+ \ No newline at end of file
diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java
index 3d771b6c51..b35b245aab 100755
--- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java
+++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java
@@ -27,6 +27,7 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.util.Collection;
import javax.validation.Valid;
+import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
import org.onap.cps.ncmp.api.models.DmiPluginRegistration;
@@ -151,6 +152,29 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
return new ResponseEntity<>(HttpStatus.OK);
}
+ /**
+ * Get resource data for for operational datastore.
+ *
+ * @param cmHandle cm handle identifier
+ * @param resourceIdentifier resource identifier
+ * @param accept accept header parameter
+ * @param fields fields query parameter
+ * @param depth depth query parameter
+ * @return {@code ResponseEntity} response from dmi plugin
+ */
+ @Override
+ public ResponseEntity<Object> getResourceDataOperationalForCmHandle(final String cmHandle,
+ final String resourceIdentifier,
+ final String accept,
+ final @Valid String fields,
+ final @Min(1) @Valid Integer depth) {
+ final var responseObject = networkCmProxyDataService.getResourceDataOperationalFoCmHandle(cmHandle,
+ resourceIdentifier,
+ accept,
+ fields,
+ depth);
+ return ResponseEntity.ok(responseObject);
+ }
private DmiPluginRegistration convertRestObjectToJavaApiObject(
final RestDmiPluginRegistration restDmiPluginRegistration) {
diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandler.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandler.java
index c91b821d66..6729329779 100755
--- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandler.java
+++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandler.java
@@ -1,6 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2021 Pantheon.tech
+ * Modifications Copyright (C) 2021 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,6 +23,7 @@ package org.onap.cps.ncmp.rest.exceptions;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
+import org.onap.cps.ncmp.api.impl.exception.NcmpException;
import org.onap.cps.ncmp.rest.controller.NetworkCmProxyController;
import org.onap.cps.ncmp.rest.model.ErrorMessage;
import org.onap.cps.spi.exceptions.CpsException;
@@ -57,6 +59,11 @@ public class NetworkCmProxyRestExceptionHandler {
return buildErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, exception);
}
+ @ExceptionHandler({NcmpException.class})
+ public static ResponseEntity<Object> handleNcmpExceptions(final NcmpException exception) {
+ return buildErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, exception);
+ }
+
private static ResponseEntity<Object> buildErrorResponse(final HttpStatus status, final Exception exception) {
if (exception.getCause() != null || !(exception instanceof CpsException)) {
log.error("Exception occurred", exception);
@@ -64,6 +71,13 @@ public class NetworkCmProxyRestExceptionHandler {
final var errorMessage = new ErrorMessage();
errorMessage.setStatus(status.toString());
errorMessage.setMessage(exception.getMessage());
+ if (exception instanceof CpsException) {
+ errorMessage.setDetails(((CpsException) exception).getDetails());
+ } else if (exception instanceof NcmpException) {
+ errorMessage.setDetails(((NcmpException) exception).getDetails());
+ } else {
+ errorMessage.setDetails(CHECK_LOGS_FOR_DETAILS);
+ }
errorMessage.setDetails(exception instanceof CpsException ? ((CpsException) exception).getDetails() :
CHECK_LOGS_FOR_DETAILS);
return new ResponseEntity<>(errorMessage, status);
diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy
index f537980ac8..b2a060c278 100644
--- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy
+++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy
@@ -196,5 +196,25 @@ class NetworkCmProxyControllerSpec extends Specification {
response.status == HttpStatus.CREATED.value()
}
+ def 'Get Resource Data from pass-through operational.' () {
+ given: 'resource data url'
+ def getUrl = "$basePath/v1/ch/testCmHandle/data/ds/ncmp-datastore:passthrough-operational" +
+ "/testResourceIdentifier?fields=testFields&depth=5"
+ when: 'get data resource request is performed'
+ def response = mvc.perform(
+ get(getUrl)
+ .contentType(MediaType.APPLICATION_JSON)
+ .accept(MediaType.APPLICATION_JSON_VALUE)
+ ).andReturn().response
+ then: 'the NCMP data service is called with getResourceDataOperationalFoCmHandle'
+ 1 * mockNetworkCmProxyDataService.getResourceDataOperationalFoCmHandle('testCmHandle',
+ 'testResourceIdentifier',
+ 'application/json',
+ 'testFields',
+ 5)
+ and: 'response status is Ok'
+ response.status == HttpStatus.OK.value()
+ }
+
}