summaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-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
3 files changed, 122 insertions, 21 deletions
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;
+ }
+
+}
+