aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ncmp-rest/src/main/java/org
diff options
context:
space:
mode:
authorlukegleeson <luke.gleeson@est.tech>2022-10-20 10:14:00 +0100
committerlukegleeson <luke.gleeson@est.tech>2022-11-15 17:18:39 +0000
commit20e7a733d8a3657fd9932eaf8144f47777965533 (patch)
tree0776eaf8cb4de6689bdeae4ea7a1f688b29d56c8 /cps-ncmp-rest/src/main/java/org
parentb99f0f00cb964af7b88a85c09bbb11f6c0b1f04d (diff)
Query data NCMP-Operational with CPSpath
New GET Endpoint: /v1/ch/{cm-handle}/data/ds/{ncmp-datastore-name}/query?cps-path={CPSPath} Implemented error for {ncmp-datastore-name} other than operational - (Toine) Refactored and renamed (abstract) handler for better re-use Mainly by introducing a separate handler for OperationalQuery Reviewers Toine, Sourabh, Priyank Issue-ID: CPS-1002 Signed-off-by: lukegleeson <luke.gleeson@est.tech> Change-Id: Iaca018869d95d4ce800072431baa190050a6dad0
Diffstat (limited to 'cps-ncmp-rest/src/main/java/org')
-rwxr-xr-xcps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java49
-rw-r--r--cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreOperationalQueryHandler.java56
-rw-r--r--cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreOperationalResourceRequestHandler.java20
-rw-r--r--cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastorePassthroughOperationalResourceRequestHandler.java14
-rw-r--r--cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastorePassthroughRunningResourceRequestHandler.java14
-rw-r--r--cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreRequestHandler.java106
-rw-r--r--cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreResourceRequestHandler.java92
-rw-r--r--cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreResourceRequestHandlerFactory.java15
8 files changed, 237 insertions, 129 deletions
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 2f6668a35..9f171f609 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
@@ -39,7 +39,7 @@ import org.onap.cps.ncmp.api.models.CmHandleQueryApiParameters;
import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
import org.onap.cps.ncmp.rest.api.NetworkCmProxyApi;
import org.onap.cps.ncmp.rest.controller.handlers.DatastoreType;
-import org.onap.cps.ncmp.rest.controller.handlers.NcmpDatastoreResourceRequestHandler;
+import org.onap.cps.ncmp.rest.controller.handlers.NcmpDatastoreRequestHandler;
import org.onap.cps.ncmp.rest.controller.handlers.NcmpDatastoreResourceRequestHandlerFactory;
import org.onap.cps.ncmp.rest.exceptions.InvalidDatastoreException;
import org.onap.cps.ncmp.rest.mapper.CmHandleStateMapper;
@@ -91,15 +91,42 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
final String topicParamInQuery,
final Boolean includeDescendants) {
- final NcmpDatastoreResourceRequestHandler ncmpDatastoreResourceRequestHandler =
+ final NcmpDatastoreRequestHandler ncmpDatastoreRequestHandler =
ncmpDatastoreResourceRequestHandlerFactory.getNcmpDatastoreResourceRequestHandler(
DatastoreType.fromDatastoreName(datastoreName));
- return ncmpDatastoreResourceRequestHandler.getResourceData(cmHandle, resourceIdentifier,
+ return ncmpDatastoreRequestHandler.executeRequest(cmHandle, resourceIdentifier,
optionsParamInQuery, topicParamInQuery, includeDescendants);
}
/**
+ * Query resource data from datastore.
+ *
+ * @param datastoreName name of the datastore
+ * @param cmHandle cm handle identifier
+ * @param cpsPath CPS Path
+ * @param optionsParamInQuery options query parameter
+ * @param topicParamInQuery topic query parameter
+ * @param includeDescendants whether include descendants
+ * @return {@code ResponseEntity} response from dmi plugin
+ */
+
+ @Override
+ public ResponseEntity<Object> queryResourceDataForCmHandle(final String datastoreName,
+ final String cmHandle,
+ final String cpsPath,
+ final String optionsParamInQuery,
+ final String topicParamInQuery,
+ final Boolean includeDescendants) {
+ validateDataStore(DatastoreType.OPERATIONAL, datastoreName);
+ final NcmpDatastoreRequestHandler ncmpDatastoreRequestHandler =
+ ncmpDatastoreResourceRequestHandlerFactory.getNcmpDatastoreResourceQueryHandler();
+
+ return ncmpDatastoreRequestHandler.executeRequest(cmHandle, cpsPath, optionsParamInQuery,
+ topicParamInQuery, includeDescendants);
+ }
+
+ /**
* Patch resource data from passthrough-running.
*
* @param resourceIdentifier resource identifier
@@ -117,7 +144,7 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
final Object requestBody,
final String contentType) {
- acceptPassthroughRunningOnly(datastoreName);
+ validateDataStore(DatastoreType.PASSTHROUGH_RUNNING, datastoreName);
final Object responseObject = networkCmProxyDataService
.writeResourceDataPassThroughRunningForCmHandle(
@@ -143,7 +170,7 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
final Object requestBody,
final String contentType) {
- acceptPassthroughRunningOnly(datastoreName);
+ validateDataStore(DatastoreType.PASSTHROUGH_RUNNING, datastoreName);
networkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle(cmHandle,
resourceIdentifier, CREATE, jsonObjectMapper.asJsonString(requestBody), contentType);
@@ -167,7 +194,7 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
final String cmHandle,
final Object requestBody,
final String contentType) {
- acceptPassthroughRunningOnly(datastoreName);
+ validateDataStore(DatastoreType.PASSTHROUGH_RUNNING, datastoreName);
networkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle(cmHandle,
resourceIdentifier, UPDATE, jsonObjectMapper.asJsonString(requestBody), contentType);
@@ -189,7 +216,7 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
final String resourceIdentifier,
final String contentType) {
- acceptPassthroughRunningOnly(datastoreName);
+ validateDataStore(DatastoreType.PASSTHROUGH_RUNNING, datastoreName);
networkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle(cmHandle,
resourceIdentifier, DELETE, NO_BODY, contentType);
@@ -332,11 +359,11 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
return restOutputCmHandle;
}
- private void acceptPassthroughRunningOnly(final String datastoreName) {
- final DatastoreType datastoreType = DatastoreType.fromDatastoreName(datastoreName);
+ private void validateDataStore(final DatastoreType acceptableDataStoreType, final String requestedDatastoreName) {
+ final DatastoreType datastoreType = DatastoreType.fromDatastoreName(requestedDatastoreName);
- if (DatastoreType.PASSTHROUGH_RUNNING != datastoreType) {
- throw new InvalidDatastoreException(datastoreName + " is not supported");
+ if (acceptableDataStoreType != datastoreType) {
+ throw new InvalidDatastoreException(requestedDatastoreName + " is not supported");
}
}
}
diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreOperationalQueryHandler.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreOperationalQueryHandler.java
new file mode 100644
index 000000000..0586d4262
--- /dev/null
+++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreOperationalQueryHandler.java
@@ -0,0 +1,56 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 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.rest.controller.handlers;
+
+import java.util.function.Supplier;
+import lombok.extern.slf4j.Slf4j;
+import org.onap.cps.ncmp.api.NetworkCmProxyQueryService;
+import org.onap.cps.ncmp.rest.executor.CpsNcmpTaskExecutor;
+import org.onap.cps.spi.FetchDescendantsOption;
+
+@Slf4j
+public class NcmpDatastoreOperationalQueryHandler extends NcmpDatastoreRequestHandler {
+
+ private final NetworkCmProxyQueryService networkCmProxyQueryService;
+
+ public NcmpDatastoreOperationalQueryHandler(final NetworkCmProxyQueryService networkCmProxyQueryService,
+ final CpsNcmpTaskExecutor cpsNcmpTaskExecutor,
+ final int timeOutInMilliSeconds,
+ final boolean notificationFeatureEnabled) {
+ super(null, cpsNcmpTaskExecutor, timeOutInMilliSeconds, notificationFeatureEnabled);
+ this.networkCmProxyQueryService = networkCmProxyQueryService;
+ }
+
+ @Override
+ public Supplier<Object> getTaskSupplier(final String cmHandle,
+ final String resourceIdentifier,
+ final String optionsParamInQuery,
+ final String topicParamInQuery,
+ final String requestId,
+ final Boolean includeDescendant) {
+
+ final FetchDescendantsOption fetchDescendantsOption = getFetchDescendantsOption(includeDescendant);
+
+ return () -> networkCmProxyQueryService.queryResourceDataOperational(cmHandle, resourceIdentifier,
+ fetchDescendantsOption);
+ }
+
+}
diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreOperationalResourceRequestHandler.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreOperationalResourceRequestHandler.java
index 6ed9b8c4d..a4720b22f 100644
--- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreOperationalResourceRequestHandler.java
+++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreOperationalResourceRequestHandler.java
@@ -27,7 +27,7 @@ import org.onap.cps.ncmp.rest.executor.CpsNcmpTaskExecutor;
import org.onap.cps.spi.FetchDescendantsOption;
@Slf4j
-public class NcmpDatastoreOperationalResourceRequestHandler extends NcmpDatastoreResourceRequestHandler {
+public class NcmpDatastoreOperationalResourceRequestHandler extends NcmpDatastoreRequestHandler {
public NcmpDatastoreOperationalResourceRequestHandler(final NetworkCmProxyDataService networkCmProxyDataService,
final CpsNcmpTaskExecutor cpsNcmpTaskExecutor,
@@ -37,16 +37,14 @@ public class NcmpDatastoreOperationalResourceRequestHandler extends NcmpDatastor
}
@Override
- public Supplier<Object> getTask(final String cmHandle,
- final String resourceIdentifier,
- final String optionsParamInQuery,
- final String topicParamInQuery,
- final String requestId,
- final Boolean includeDescendant) {
-
- final FetchDescendantsOption fetchDescendantsOption =
- Boolean.TRUE.equals(includeDescendant) ? FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
- : FetchDescendantsOption.OMIT_DESCENDANTS;
+ public Supplier<Object> getTaskSupplier(final String cmHandle,
+ final String resourceIdentifier,
+ final String optionsParamInQuery,
+ final String topicParamInQuery,
+ final String requestId,
+ final Boolean includeDescendant) {
+
+ final FetchDescendantsOption fetchDescendantsOption = getFetchDescendantsOption(includeDescendant);
return () -> networkCmProxyDataService.getResourceDataOperational(cmHandle, resourceIdentifier,
fetchDescendantsOption);
diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastorePassthroughOperationalResourceRequestHandler.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastorePassthroughOperationalResourceRequestHandler.java
index 196e5bd33..1445e3e27 100644
--- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastorePassthroughOperationalResourceRequestHandler.java
+++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastorePassthroughOperationalResourceRequestHandler.java
@@ -26,7 +26,7 @@ import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
import org.onap.cps.ncmp.rest.executor.CpsNcmpTaskExecutor;
@Slf4j
-public class NcmpDatastorePassthroughOperationalResourceRequestHandler extends NcmpDatastoreResourceRequestHandler {
+public class NcmpDatastorePassthroughOperationalResourceRequestHandler extends NcmpDatastoreRequestHandler {
public NcmpDatastorePassthroughOperationalResourceRequestHandler(
final NetworkCmProxyDataService networkCmProxyDataService,
@@ -37,12 +37,12 @@ public class NcmpDatastorePassthroughOperationalResourceRequestHandler extends N
}
@Override
- public Supplier<Object> getTask(final String cmHandle,
- final String resourceIdentifier,
- final String optionsParamInQuery,
- final String topicParamInQuery,
- final String requestId,
- final Boolean includeDescendant) {
+ public Supplier<Object> getTaskSupplier(final String cmHandle,
+ final String resourceIdentifier,
+ final String optionsParamInQuery,
+ final String topicParamInQuery,
+ final String requestId,
+ final Boolean includeDescendant) {
return () -> networkCmProxyDataService.getResourceDataOperationalForCmHandle(
cmHandle, resourceIdentifier, optionsParamInQuery, topicParamInQuery, requestId);
diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastorePassthroughRunningResourceRequestHandler.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastorePassthroughRunningResourceRequestHandler.java
index 5bf16b749..8194ec9fd 100644
--- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastorePassthroughRunningResourceRequestHandler.java
+++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastorePassthroughRunningResourceRequestHandler.java
@@ -26,7 +26,7 @@ import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
import org.onap.cps.ncmp.rest.executor.CpsNcmpTaskExecutor;
@Slf4j
-public class NcmpDatastorePassthroughRunningResourceRequestHandler extends NcmpDatastoreResourceRequestHandler {
+public class NcmpDatastorePassthroughRunningResourceRequestHandler extends NcmpDatastoreRequestHandler {
public NcmpDatastorePassthroughRunningResourceRequestHandler(
final NetworkCmProxyDataService networkCmProxyDataService,
@@ -37,12 +37,12 @@ public class NcmpDatastorePassthroughRunningResourceRequestHandler extends NcmpD
}
@Override
- public Supplier<Object> getTask(final String cmHandle,
- final String resourceIdentifier,
- final String optionsParamInQuery,
- final String topicParamInQuery,
- final String requestId,
- final Boolean includeDescendant) {
+ public Supplier<Object> getTaskSupplier(final String cmHandle,
+ final String resourceIdentifier,
+ final String optionsParamInQuery,
+ final String topicParamInQuery,
+ final String requestId,
+ final Boolean includeDescendant) {
return () -> networkCmProxyDataService.getResourceDataPassThroughRunningForCmHandle(
cmHandle, resourceIdentifier, optionsParamInQuery, topicParamInQuery, requestId);
diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreRequestHandler.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreRequestHandler.java
new file mode 100644
index 000000000..850200396
--- /dev/null
+++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreRequestHandler.java
@@ -0,0 +1,106 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 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.rest.controller.handlers;
+
+import java.util.Map;
+import java.util.UUID;
+import java.util.function.Supplier;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
+import org.onap.cps.ncmp.rest.executor.CpsNcmpTaskExecutor;
+import org.onap.cps.ncmp.rest.util.TopicValidator;
+import org.onap.cps.spi.FetchDescendantsOption;
+import org.springframework.http.ResponseEntity;
+
+@RequiredArgsConstructor
+@Slf4j
+public abstract class NcmpDatastoreRequestHandler {
+
+ private static final String NO_REQUEST_ID = null;
+ private static final String NO_TOPIC = null;
+
+ protected final NetworkCmProxyDataService networkCmProxyDataService;
+ protected final CpsNcmpTaskExecutor cpsNcmpTaskExecutor;
+ protected final int timeOutInMilliSeconds;
+ protected final boolean notificationFeatureEnabled;
+
+ protected abstract Supplier<Object> getTaskSupplier(final String cmHandle,
+ final String resourceIdentifier,
+ final String optionsParamInQuery,
+ final String topicParamInQuery,
+ final String requestId,
+ final Boolean includeDescendant);
+
+ /**
+ * Execute a request on a datastore.
+ *
+ * @param cmHandleId the cm handle
+ * @param resourceIdentifier the resource identifier
+ * @param optionsParamInQuery the options param in query
+ * @param topicParamInQuery the topic param in query
+ * @param includeDescendants whether include descendants
+ * @return the response entity
+ */
+ public ResponseEntity<Object> executeRequest(final String cmHandleId,
+ final String resourceIdentifier,
+ final String optionsParamInQuery,
+ final String topicParamInQuery,
+ final Boolean includeDescendants) {
+
+ final boolean asyncResponseRequested = topicParamInQuery != null;
+ if (asyncResponseRequested && notificationFeatureEnabled) {
+ final String requestId = UUID.randomUUID().toString();
+ final Supplier<Object> taskSupplier = getTaskSupplier(cmHandleId, resourceIdentifier, optionsParamInQuery,
+ topicParamInQuery, requestId, includeDescendants);
+ return executeTaskAsync(topicParamInQuery, requestId, taskSupplier);
+ }
+
+ if (asyncResponseRequested) {
+ log.warn("Asynchronous request is unavailable as notification feature is currently disabled, "
+ + "will use synchronous operation.");
+ }
+ final Supplier<Object> taskSupplier = getTaskSupplier(cmHandleId, resourceIdentifier, optionsParamInQuery,
+ NO_TOPIC, NO_REQUEST_ID, includeDescendants);
+ return executeTaskSync(taskSupplier);
+ }
+
+ protected ResponseEntity<Object> executeTaskAsync(final String topicParamInQuery,
+ final String requestId,
+ final Supplier<Object> taskSupplier) {
+
+ TopicValidator.validateTopicName(topicParamInQuery);
+ log.debug("Received Async request with id {}", requestId);
+ cpsNcmpTaskExecutor.executeTask(taskSupplier, timeOutInMilliSeconds);
+
+ return ResponseEntity.ok(Map.of("requestId", requestId));
+ }
+
+ protected ResponseEntity<Object> executeTaskSync(final Supplier<Object> taskSupplier) {
+ return ResponseEntity.ok(taskSupplier.get());
+ }
+
+ protected static FetchDescendantsOption getFetchDescendantsOption(final Boolean includeDescendant) {
+ return Boolean.TRUE.equals(includeDescendant) ? FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
+ : FetchDescendantsOption.OMIT_DESCENDANTS;
+ }
+
+}
diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreResourceRequestHandler.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreResourceRequestHandler.java
deleted file mode 100644
index a6d313b05..000000000
--- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreResourceRequestHandler.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2022 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.rest.controller.handlers;
-
-import java.util.Map;
-import java.util.UUID;
-import java.util.function.Supplier;
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
-import org.onap.cps.ncmp.rest.executor.CpsNcmpTaskExecutor;
-import org.onap.cps.ncmp.rest.util.TopicValidator;
-import org.springframework.http.ResponseEntity;
-
-@RequiredArgsConstructor
-@Slf4j
-public abstract class NcmpDatastoreResourceRequestHandler {
-
- private static final String NO_REQUEST_ID = null;
- private static final String NO_TOPIC = null;
-
- protected final NetworkCmProxyDataService networkCmProxyDataService;
- protected final CpsNcmpTaskExecutor cpsNcmpTaskExecutor;
- protected final int timeOutInMilliSeconds;
- protected final boolean notificationFeatureEnabled;
-
- protected abstract Supplier<Object> getTask(final String cmHandle,
- final String resourceIdentifier,
- final String optionsParamInQuery,
- final String topicParamInQuery,
- final String requestId,
- final Boolean includeDescendant);
-
-
- /**
- * Get resource data from datastore.
- *
- * @param cmHandleId the cm handle
- * @param resourceIdentifier the resource identifier
- * @param optionsParamInQuery the options param in query
- * @param topicParamInQuery the topic param in query
- * @param includeDescendants whether include descendants
- * @return the response entity
- */
- public ResponseEntity<Object> getResourceData(final String cmHandleId,
- final String resourceIdentifier,
- final String optionsParamInQuery,
- final String topicParamInQuery,
- final Boolean includeDescendants) {
-
- final String requestId = UUID.randomUUID().toString();
- final boolean asyncResponseRequested = topicParamInQuery != null;
-
- if (asyncResponseRequested && notificationFeatureEnabled) {
- TopicValidator.validateTopicName(topicParamInQuery);
- log.debug("Received Async request with id {}", requestId);
- cpsNcmpTaskExecutor.executeTask(
- getTask(cmHandleId, resourceIdentifier, optionsParamInQuery, topicParamInQuery, requestId,
- includeDescendants), timeOutInMilliSeconds);
-
- return ResponseEntity.ok(Map.of("requestId", requestId));
- }
-
- if (asyncResponseRequested) {
- log.warn("Asynchronous messaging is currently disabled, will use synchronous operation.");
- }
-
- final Object responseObject =
- getTask(cmHandleId, resourceIdentifier, optionsParamInQuery, NO_TOPIC, NO_REQUEST_ID,
- includeDescendants).get();
-
- return ResponseEntity.ok(responseObject);
- }
-}
diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreResourceRequestHandlerFactory.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreResourceRequestHandlerFactory.java
index 7db754279..ff7bda6a4 100644
--- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreResourceRequestHandlerFactory.java
+++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreResourceRequestHandlerFactory.java
@@ -22,6 +22,7 @@ package org.onap.cps.ncmp.rest.controller.handlers;
import lombok.RequiredArgsConstructor;
import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
+import org.onap.cps.ncmp.api.NetworkCmProxyQueryService;
import org.onap.cps.ncmp.rest.executor.CpsNcmpTaskExecutor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@@ -31,6 +32,7 @@ import org.springframework.stereotype.Component;
public class NcmpDatastoreResourceRequestHandlerFactory {
private final NetworkCmProxyDataService networkCmProxyDataService;
+ private final NetworkCmProxyQueryService networkCmProxyQueryService;
private final CpsNcmpTaskExecutor cpsNcmpTaskExecutor;
@Value("${notification.async.executor.time-out-value-in-ms:2000}")
@@ -44,7 +46,7 @@ public class NcmpDatastoreResourceRequestHandlerFactory {
* @param datastoreType the datastore type
* @return the ncmp datastore handler
*/
- public NcmpDatastoreResourceRequestHandler getNcmpDatastoreResourceRequestHandler(
+ public NcmpDatastoreRequestHandler getNcmpDatastoreResourceRequestHandler(
final DatastoreType datastoreType) {
switch (datastoreType) {
@@ -60,4 +62,15 @@ public class NcmpDatastoreResourceRequestHandlerFactory {
cpsNcmpTaskExecutor, timeOutInMilliSeconds, notificationFeatureEnabled);
}
}
+
+ /**
+ * Gets ncmp datastore query handler.
+ * Note. Currently only ncmp-datastore:operational supports query operations
+ * @return a ncmp datastore query handler.
+ */
+ public NcmpDatastoreRequestHandler getNcmpDatastoreResourceQueryHandler() {
+ return new NcmpDatastoreOperationalQueryHandler(networkCmProxyQueryService, cpsNcmpTaskExecutor,
+ timeOutInMilliSeconds, notificationFeatureEnabled);
+ }
+
}