summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsourabh_sourabh <sourabh.sourabh@est.tech>2023-03-13 15:49:35 +0000
committersourabh_sourabh <sourabh.sourabh@est.tech>2023-03-15 11:36:00 +0000
commite648aba2d39855337b6a5c39000dc6c611d09191 (patch)
tree8f64e9c8b07ffcaffdc6f3d5d741e1ac30dd9115
parentf07370606ca12b70566cfbe663c9801d41044f34 (diff)
Merge existing dmi-plugin of data access passthrough endpoints
- Introduced datastore enum and execute existing method based on given datastore. Issue-ID: CPS-1550 Signed-off-by: sourabh_sourabh <sourabh.sourabh@est.tech> Change-Id: Idf908a89dce2f5f1a155d630e04ba7869328b94d Signed-off-by: sourabh_sourabh <sourabh.sourabh@est.tech>
-rw-r--r--openapi/components.yml8
-rw-r--r--openapi/openapi.yml55
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/exception/InvalidDatastoreException.java32
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java46
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/rest/controller/handlers/DatastoreType.java65
5 files changed, 137 insertions, 69 deletions
diff --git a/openapi/components.yml b/openapi/components.yml
index 6124d647..1e35c028 100644
--- a/openapi/components.yml
+++ b/openapi/components.yml
@@ -213,6 +213,14 @@ components:
examples:
sample1:
value: my-topic-name
+ datastoreName:
+ name: datastore-name
+ in: path
+ description: The type of the requested data
+ required: true
+ schema:
+ type: string
+ example: ncmp-datastore:passthrough-operational or ncmp-datastore:passthrough-running
security:
- basicAuth: [] \ No newline at end of file
diff --git a/openapi/openapi.yml b/openapi/openapi.yml
index 6e0e8ae6..38d5cef5 100644
--- a/openapi/openapi.yml
+++ b/openapi/openapi.yml
@@ -115,20 +115,21 @@ paths:
'500':
$ref: 'components.yml#/components/responses/ServerError'
- /v1/ch/{cmHandle}/data/ds/ncmp-datastore:passthrough-operational:
+ /v1/ch/{cmHandle}/data/ds/{datastore-name}:
post:
tags:
- dmi-plugin
- summary: Get resource data from passthrough-operational for cm handle
- description: Get resource data from passthrough-operational for cm handle. Will support read operations only.
- operationId: dataAccessPassthroughOperational
+ summary: Get resource data from passthrough operational or running for cm handles
+ description: Get resource data from passthrough operational or running for cm handles
+ operationId: dataAccessPassthrough
parameters:
+ - $ref: 'components.yml#/components/parameters/datastoreName'
- $ref: 'components.yml#/components/parameters/cmHandleInPath'
- $ref: 'components.yml#/components/parameters/resourceIdentifierInQuery'
- $ref: 'components.yml#/components/parameters/optionsParamInQuery'
- $ref: 'components.yml#/components/parameters/topicParamInQuery'
requestBody:
- description: Operational body
+ description: Contains collection of cm handles with it's private properties and requestId
content:
application/json:
schema:
@@ -147,46 +148,4 @@ paths:
'400':
$ref: 'components.yml#/components/responses/BadRequest'
'500':
- $ref: 'components.yml#/components/responses/ServerError'
-
- /v1/ch/{cmHandle}/data/ds/ncmp-datastore:passthrough-running:
- post:
- tags:
- - dmi-plugin
- summary: Get, Create or Update request for data passthrough-running for a cm-handle
- description: Post request to Get, Create or to Update resource data for a cm-handle. Since all requests need to include additional information in a request body HTTP Post is used for all use cases and the actual operation is defined in the request body instead.
- operationId: dataAccessPassthroughRunning
- parameters:
- - $ref: 'components.yml#/components/parameters/cmHandleInPath'
- - $ref: 'components.yml#/components/parameters/resourceIdentifierInQuery'
- - $ref: 'components.yml#/components/parameters/optionsParamInQuery'
- - $ref: 'components.yml#/components/parameters/topicParamInQuery'
- requestBody:
- content:
- application/json:
- schema:
- $ref: 'components.yml#/components/schemas/DataAccessRequest'
- responses:
- '200':
- description: OK
- content:
- application/json:
- schema:
- type: object
- example:
- - yangSource: my-yang-source
- moduleName: my-module-name
- revision: my-revision
- '201':
- description: Created
- content:
- text/plain:
- schema:
- type: string
- example: my-resource
- '204':
- $ref: 'components.yml#/components/responses/NoContent'
- '400':
- $ref: 'components.yml#/components/responses/BadRequest'
- '500':
- $ref: 'components.yml#/components/responses/ServerError'
+ $ref: 'components.yml#/components/responses/ServerError' \ No newline at end of file
diff --git a/src/main/java/org/onap/cps/ncmp/dmi/exception/InvalidDatastoreException.java b/src/main/java/org/onap/cps/ncmp/dmi/exception/InvalidDatastoreException.java
new file mode 100644
index 00000000..aa5b0cb7
--- /dev/null
+++ b/src/main/java/org/onap/cps/ncmp/dmi/exception/InvalidDatastoreException.java
@@ -0,0 +1,32 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2023 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.ncmp.dmi.exception;
+
+public class InvalidDatastoreException extends RuntimeException {
+ /**
+ * Instantiates a new Invalid datastore exception.
+ *
+ * @param message the message
+ */
+ public InvalidDatastoreException(final String message) {
+ super(message);
+ }
+}
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 bdd1fff6..f952e224 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
@@ -40,6 +40,7 @@ import org.onap.cps.ncmp.dmi.model.YangResources;
import org.onap.cps.ncmp.dmi.notifications.async.AsyncTaskExecutor;
import org.onap.cps.ncmp.dmi.rest.api.DmiPluginApi;
import org.onap.cps.ncmp.dmi.rest.api.DmiPluginInternalApi;
+import org.onap.cps.ncmp.dmi.rest.controller.handlers.DatastoreType;
import org.onap.cps.ncmp.dmi.service.DmiService;
import org.onap.cps.ncmp.dmi.service.model.ModuleReference;
import org.springframework.beans.factory.annotation.Value;
@@ -104,10 +105,12 @@ public class DmiRestController implements DmiPluginApi, DmiPluginInternalApi {
}
/**
- * This method fetches the resource for given cm handle using pass through operational datastore. It filters the
- * response on the basis of options query parameters and returns response. Does not support write operations.
+ * This method fetches the resource for given cm handle using pass through operational or running datastore.
+ * It filters the response on the basis of options query parameters and returns response. Passthrough Running
+ * supports both read and write operation whereas passthrough operational does not support write operations.
*
* @param resourceIdentifier resource identifier to fetch data
+ * @param datastoreName name of the datastore
* @param cmHandle cm handle identifier
* @param dataAccessRequest data Access Request
* @param optionsParamInQuery options query parameter
@@ -115,10 +118,24 @@ public class DmiRestController implements DmiPluginApi, DmiPluginInternalApi {
* @return {@code ResponseEntity} response entity
*/
@Override
- public ResponseEntity<Object> dataAccessPassthroughOperational(final String resourceIdentifier,
+ public ResponseEntity<Object> dataAccessPassthrough(final String resourceIdentifier,
+ final String datastoreName,
+ final String cmHandle,
+ final DataAccessRequest dataAccessRequest,
+ final String optionsParamInQuery,
+ final String topicParamInQuery) {
+ if (DatastoreType.PASSTHROUGH_OPERATIONAL == DatastoreType.fromDatastoreName(datastoreName)) {
+ return dataAccessPassthroughOperational(resourceIdentifier, cmHandle, dataAccessRequest,
+ optionsParamInQuery, topicParamInQuery);
+ }
+ return dataAccessPassthroughRunning(resourceIdentifier, cmHandle, dataAccessRequest,
+ optionsParamInQuery, topicParamInQuery);
+ }
+
+ private ResponseEntity<Object> dataAccessPassthroughOperational(final String resourceIdentifier,
final String cmHandle,
- final @Valid DataAccessRequest dataAccessRequest,
- final @Valid String optionsParamInQuery,
+ final DataAccessRequest dataAccessRequest,
+ final String optionsParamInQuery,
final String topicParamInQuery) {
if (isReadOperation(dataAccessRequest)) {
if (hasTopic(topicParamInQuery)) {
@@ -133,23 +150,10 @@ public class DmiRestController implements DmiPluginApi, DmiPluginInternalApi {
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
- /**
- * This method fetches the resource for given cm handle using pass through running datastore. It filters the
- * response on the basis of options query parameters and returns response. It supports both read and write
- * operation.
- *
- * @param resourceIdentifier resource identifier to fetch data
- * @param cmHandle cm handle identifier
- * @param dataAccessRequest data Access Request
- * @param optionsParamInQuery options query parameter
- * @param topicParamInQuery topic name for (triggering) async responses
- * @return {@code ResponseEntity} response entity
- */
- @Override
- public ResponseEntity<Object> dataAccessPassthroughRunning(final String resourceIdentifier,
+ private ResponseEntity<Object> dataAccessPassthroughRunning(final String resourceIdentifier,
final String cmHandle,
- final @Valid DataAccessRequest dataAccessRequest,
- final @Valid String optionsParamInQuery,
+ final DataAccessRequest dataAccessRequest,
+ final String optionsParamInQuery,
final String topicParamInQuery) {
if (hasTopic(topicParamInQuery)) {
asyncTaskExecutor.executeAsyncTask(() ->
diff --git a/src/main/java/org/onap/cps/ncmp/dmi/rest/controller/handlers/DatastoreType.java b/src/main/java/org/onap/cps/ncmp/dmi/rest/controller/handlers/DatastoreType.java
new file mode 100644
index 00000000..3f280403
--- /dev/null
+++ b/src/main/java/org/onap/cps/ncmp/dmi/rest/controller/handlers/DatastoreType.java
@@ -0,0 +1,65 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2023 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.ncmp.dmi.rest.controller.handlers;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import lombok.Getter;
+import org.onap.cps.ncmp.dmi.exception.InvalidDatastoreException;
+
+@Getter
+public enum DatastoreType {
+
+ PASSTHROUGH_RUNNING("ncmp-datastore:passthrough-running"),
+ PASSTHROUGH_OPERATIONAL("ncmp-datastore:passthrough-operational");
+
+ DatastoreType(final String datastoreName) {
+ this.datastoreName = datastoreName;
+ }
+
+ private final String datastoreName;
+ private static final Map<String, DatastoreType> datastoreNameToDatastoreType = new HashMap<>();
+
+ static {
+ Arrays.stream(DatastoreType.values()).forEach(
+ type -> datastoreNameToDatastoreType.put(type.getDatastoreName(), type));
+ }
+
+ /**
+ * From datastore name get datastore type.
+ *
+ * @param datastoreName the datastore name
+ * @return the datastore type
+ */
+ public static DatastoreType fromDatastoreName(final String datastoreName) {
+
+ final DatastoreType datastoreType = datastoreNameToDatastoreType.get(datastoreName);
+
+ if (null == datastoreType) {
+ throw new InvalidDatastoreException(datastoreName + " is an invalid datastore name");
+ }
+
+ return datastoreType;
+ }
+
+}
+