summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-rest/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ncmp-rest/src/main')
-rwxr-xr-xcps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java78
-rw-r--r--cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpCachedResourceRequestHandler.java70
-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.java53
-rw-r--r--cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastorePassthroughOperationalResourceRequestHandler.java51
-rw-r--r--cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastorePassthroughRunningResourceRequestHandler.java50
-rw-r--r--cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreRequestHandler.java116
-rw-r--r--cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreResourceRequestHandlerFactory.java41
-rw-r--r--cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpPassthroughResourceRequestHandler.java58
-rw-r--r--cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/TaskManagementDefaultHandler.java63
10 files changed, 338 insertions, 298 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 4da251f3cc..a8bc3aec76 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
@@ -23,10 +23,10 @@
package org.onap.cps.ncmp.rest.controller;
-import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.CREATE;
-import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.DELETE;
-import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.PATCH;
-import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.UPDATE;
+import static org.onap.cps.ncmp.api.impl.operations.OperationEnum.CREATE;
+import static org.onap.cps.ncmp.api.impl.operations.OperationEnum.DELETE;
+import static org.onap.cps.ncmp.api.impl.operations.OperationEnum.PATCH;
+import static org.onap.cps.ncmp.api.impl.operations.OperationEnum.UPDATE;
import java.util.Collection;
import java.util.List;
@@ -74,12 +74,12 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
/**
* Get resource data from datastore.
*
- * @param datastoreName name of the datastore
- * @param cmHandle cm handle identifier
- * @param resourceIdentifier resource identifier
- * @param optionsParamInQuery options query parameter
- * @param topicParamInQuery topic query parameter
- * @param includeDescendants whether include descendants
+ * @param datastoreName name of the datastore
+ * @param cmHandle cm handle identifier
+ * @param resourceIdentifier resource identifier
+ * @param optionsParamInQuery options query parameter
+ * @param topicParamInQuery topic query parameter
+ * @param includeDescendantsAsObject whether include descendants
* @return {@code ResponseEntity} response from dmi plugin
*/
@@ -89,25 +89,48 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
final String resourceIdentifier,
final String optionsParamInQuery,
final String topicParamInQuery,
- final Boolean includeDescendants) {
+ final Boolean includeDescendantsAsObject) {
final NcmpDatastoreRequestHandler ncmpDatastoreRequestHandler =
- ncmpDatastoreResourceRequestHandlerFactory.getNcmpDatastoreResourceRequestHandler(
+ ncmpDatastoreResourceRequestHandlerFactory.getNcmpResourceRequestHandler(
DatastoreType.fromDatastoreName(datastoreName));
+ final boolean includeDescendants = toPrimitiveFlag(includeDescendantsAsObject);
+
return ncmpDatastoreRequestHandler.executeRequest(cmHandle, resourceIdentifier,
optionsParamInQuery, topicParamInQuery, includeDescendants);
}
+ @Override
+ public ResponseEntity<Object> getResourceDataForCmHandleBatch(final String resourceIdentifier,
+ final String topicParamInQuery,
+ final String datastoreName,
+ final Object requestBody,
+ final String optionsParamInQuery,
+ final Boolean includeDescendantsAsObject) {
+
+ final NcmpDatastoreRequestHandler ncmpDatastoreRequestHandler =
+ ncmpDatastoreResourceRequestHandlerFactory.getNcmpResourceRequestHandler(
+ DatastoreType.fromDatastoreName(datastoreName));
+
+ final List<String> cmHandleIds = jsonObjectMapper.convertJsonString(jsonObjectMapper.asJsonString(requestBody),
+ List.class);
+
+ final boolean includeDescendants = toPrimitiveFlag(includeDescendantsAsObject);
+
+ return ncmpDatastoreRequestHandler.executeRequest(cmHandleIds, 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
+ * @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 includeDescendantsAsObject whether include descendants
* @return {@code ResponseEntity} response from dmi plugin
*/
@@ -117,13 +140,15 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
final String cpsPath,
final String optionsParamInQuery,
final String topicParamInQuery,
- final Boolean includeDescendants) {
+ final Boolean includeDescendantsAsObject) {
validateDataStore(DatastoreType.OPERATIONAL, datastoreName);
- final NcmpDatastoreRequestHandler ncmpDatastoreRequestHandler =
- ncmpDatastoreResourceRequestHandlerFactory.getNcmpDatastoreResourceQueryHandler();
+ final NcmpDatastoreRequestHandler ncmpCachedResourceRequestHandler =
+ ncmpDatastoreResourceRequestHandlerFactory.getNcmpResourceRequestHandler(
+ DatastoreType.fromDatastoreName(datastoreName));
- return ncmpDatastoreRequestHandler.executeRequest(cmHandle, cpsPath, optionsParamInQuery,
- topicParamInQuery, includeDescendants);
+ final boolean includeDescendants = toPrimitiveFlag(includeDescendantsAsObject);
+
+ return ncmpCachedResourceRequestHandler.executeRequest(cmHandle, cpsPath, includeDescendants);
}
/**
@@ -367,5 +392,12 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
throw new InvalidDatastoreException(requestedDatastoreName + " is not supported");
}
}
+
+ private static boolean toPrimitiveFlag(final Boolean includeDescendantsAsObject) {
+ if (includeDescendantsAsObject == null) {
+ return false;
+ }
+ return includeDescendantsAsObject.booleanValue();
+ }
}
diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpCachedResourceRequestHandler.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpCachedResourceRequestHandler.java
new file mode 100644
index 0000000000..620f64782b
--- /dev/null
+++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpCachedResourceRequestHandler.java
@@ -0,0 +1,70 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022-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.rest.controller.handlers;
+
+import java.util.function.Supplier;
+import lombok.RequiredArgsConstructor;
+import lombok.Setter;
+import org.onap.cps.ncmp.api.NetworkCmProxyQueryService;
+import org.onap.cps.spi.FetchDescendantsOption;
+import org.springframework.stereotype.Component;
+
+@RequiredArgsConstructor
+@Component
+public class NcmpCachedResourceRequestHandler extends NcmpDatastoreRequestHandler {
+
+ @Setter
+ private String dataStoreName;
+ private final NetworkCmProxyQueryService networkCmProxyQueryService;
+
+ @Override
+ public Supplier<Object> getTaskSupplierForGetRequest(final String cmHandleId,
+ final String resourceIdentifier,
+ final String optionsParamInQuery,
+ final String topicParamInQuery,
+ final String requestId,
+ final boolean includeDescendants) {
+
+ final FetchDescendantsOption fetchDescendantsOption =
+ TaskManagementDefaultHandler.getFetchDescendantsOption(includeDescendants);
+
+ return () -> networkCmProxyDataService.getResourceDataForCmHandle(dataStoreName, cmHandleId, resourceIdentifier,
+ fetchDescendantsOption);
+ }
+
+ /**
+ * Gets ncmp datastore query handler.
+ * Note. Currently only ncmp-datastore:operational supports query operations
+ * @return a ncmp datastore query handler.
+ */
+ @Override
+ public Supplier<Object> getTaskSupplierForQueryRequest(final String cmHandleId,
+ final String resourceIdentifier,
+ final boolean includeDescendants) {
+
+ final FetchDescendantsOption fetchDescendantsOption =
+ TaskManagementDefaultHandler.getFetchDescendantsOption(includeDescendants);
+
+ return () -> networkCmProxyQueryService.queryResourceDataOperational(cmHandleId, resourceIdentifier,
+ fetchDescendantsOption);
+ }
+
+}
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
deleted file mode 100644
index 0586d42625..0000000000
--- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreOperationalQueryHandler.java
+++ /dev/null
@@ -1,56 +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.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
deleted file mode 100644
index a4720b22ff..0000000000
--- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreOperationalResourceRequestHandler.java
+++ /dev/null
@@ -1,53 +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.function.Supplier;
-import lombok.extern.slf4j.Slf4j;
-import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
-import org.onap.cps.ncmp.rest.executor.CpsNcmpTaskExecutor;
-import org.onap.cps.spi.FetchDescendantsOption;
-
-@Slf4j
-public class NcmpDatastoreOperationalResourceRequestHandler extends NcmpDatastoreRequestHandler {
-
- public NcmpDatastoreOperationalResourceRequestHandler(final NetworkCmProxyDataService networkCmProxyDataService,
- final CpsNcmpTaskExecutor cpsNcmpTaskExecutor,
- final int timeOutInMilliSeconds,
- final boolean notificationFeatureEnabled) {
- super(networkCmProxyDataService, cpsNcmpTaskExecutor, timeOutInMilliSeconds, notificationFeatureEnabled);
- }
-
- @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 () -> 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
deleted file mode 100644
index 1445e3e271..0000000000
--- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastorePassthroughOperationalResourceRequestHandler.java
+++ /dev/null
@@ -1,51 +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.function.Supplier;
-import lombok.extern.slf4j.Slf4j;
-import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
-import org.onap.cps.ncmp.rest.executor.CpsNcmpTaskExecutor;
-
-@Slf4j
-public class NcmpDatastorePassthroughOperationalResourceRequestHandler extends NcmpDatastoreRequestHandler {
-
- public NcmpDatastorePassthroughOperationalResourceRequestHandler(
- final NetworkCmProxyDataService networkCmProxyDataService,
- final CpsNcmpTaskExecutor cpsNcmpTaskExecutor,
- final int timeOutInMilliSeconds,
- final boolean notificationFeatureEnabled) {
- super(networkCmProxyDataService, cpsNcmpTaskExecutor, timeOutInMilliSeconds, notificationFeatureEnabled);
- }
-
- @Override
- 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
deleted file mode 100644
index 8194ec9fd5..0000000000
--- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastorePassthroughRunningResourceRequestHandler.java
+++ /dev/null
@@ -1,50 +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.function.Supplier;
-import lombok.extern.slf4j.Slf4j;
-import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
-import org.onap.cps.ncmp.rest.executor.CpsNcmpTaskExecutor;
-
-@Slf4j
-public class NcmpDatastorePassthroughRunningResourceRequestHandler extends NcmpDatastoreRequestHandler {
-
- public NcmpDatastorePassthroughRunningResourceRequestHandler(
- final NetworkCmProxyDataService networkCmProxyDataService,
- final CpsNcmpTaskExecutor cpsNcmpTaskExecutor,
- final int timeOutInMilliSeconds,
- final boolean notificationFeatureEnabled) {
- super(networkCmProxyDataService, cpsNcmpTaskExecutor, timeOutInMilliSeconds, notificationFeatureEnabled);
- }
-
- @Override
- 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
index 850200396b..050e724b2c 100644
--- 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
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Nordix Foundation
+ * Copyright (C) 2022-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.
@@ -20,38 +20,37 @@
package org.onap.cps.ncmp.rest.controller.handlers;
+import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.function.Supplier;
-import lombok.RequiredArgsConstructor;
+import lombok.NoArgsConstructor;
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.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Service;
-@RequiredArgsConstructor
+@NoArgsConstructor
@Slf4j
-public abstract class NcmpDatastoreRequestHandler {
+@Service
+public class NcmpDatastoreRequestHandler implements TaskManagementDefaultHandler {
- 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);
+ @Value("${notification.async.executor.time-out-value-in-ms:2000}")
+ protected int timeOutInMilliSeconds;
+ @Value("${notification.enabled:true}")
+ protected boolean notificationFeatureEnabled;
+ @Autowired
+ protected NetworkCmProxyDataService networkCmProxyDataService;
+ @Autowired
+ protected CpsNcmpTaskExecutor cpsNcmpTaskExecutor;
/**
- * Execute a request on a datastore.
+ * Executes synchronous/asynchronous request for given cm handle.
*
* @param cmHandleId the cm handle
* @param resourceIdentifier the resource identifier
@@ -64,25 +63,62 @@ public abstract class NcmpDatastoreRequestHandler {
final String resourceIdentifier,
final String optionsParamInQuery,
final String topicParamInQuery,
- final Boolean includeDescendants) {
+ 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);
+ return executeAsyncTaskAndGetResponseEntity(cmHandleId, resourceIdentifier, optionsParamInQuery,
+ topicParamInQuery, includeDescendants, false);
}
if (asyncResponseRequested) {
log.warn("Asynchronous request is unavailable as notification feature is currently disabled, "
- + "will use synchronous operation.");
+ + "will use synchronous operation.");
}
- final Supplier<Object> taskSupplier = getTaskSupplier(cmHandleId, resourceIdentifier, optionsParamInQuery,
- NO_TOPIC, NO_REQUEST_ID, includeDescendants);
+ final Supplier<Object> taskSupplier = getTaskSupplierForGetRequest(cmHandleId,
+ resourceIdentifier, optionsParamInQuery, NO_TOPIC, NO_REQUEST_ID, includeDescendants);
return executeTaskSync(taskSupplier);
}
+ /**
+ * Executes a synchronous request for given cm handle.
+ * Note. Currently only ncmp-datastore:operational supports query operations.
+ *
+ * @param cmHandleId the cm handle
+ * @param resourceIdentifier the resource identifier
+ * @param includeDescendants whether include descendants
+ * @return the response entity
+ */
+ public ResponseEntity<Object> executeRequest(final String cmHandleId,
+ final String resourceIdentifier,
+ final boolean includeDescendants) {
+
+ final Supplier<Object> taskSupplier = getTaskSupplierForQueryRequest(cmHandleId, resourceIdentifier,
+ includeDescendants);
+ return executeTaskSync(taskSupplier);
+ }
+
+ /**
+ * Executes synchronous/asynchronous request for batch of cm handles.
+ *
+ * @param cmHandleIds list of cm handles
+ * @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 List<String> cmHandleIds,
+ final String resourceIdentifier,
+ final String optionsParamInQuery,
+ final String topicParamInQuery,
+ final boolean includeDescendants) {
+
+ return executeAsyncTaskAndGetResponseEntity(cmHandleIds, resourceIdentifier, optionsParamInQuery,
+ topicParamInQuery, includeDescendants, true);
+
+ }
+
protected ResponseEntity<Object> executeTaskAsync(final String topicParamInQuery,
final String requestId,
final Supplier<Object> taskSupplier) {
@@ -98,9 +134,25 @@ public abstract class NcmpDatastoreRequestHandler {
return ResponseEntity.ok(taskSupplier.get());
}
- protected static FetchDescendantsOption getFetchDescendantsOption(final Boolean includeDescendant) {
- return Boolean.TRUE.equals(includeDescendant) ? FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
- : FetchDescendantsOption.OMIT_DESCENDANTS;
+ private ResponseEntity<Object> executeAsyncTaskAndGetResponseEntity(final Object targetObject,
+ final String resourceIdentifier,
+ final String optionsParamInQuery,
+ final String topicParamInQuery,
+ final boolean includeDescendants,
+ final boolean isBulkRequest) {
+ final String requestId = UUID.randomUUID().toString();
+ final Supplier<Object> taskSupplier;
+ if (isBulkRequest) {
+ taskSupplier = getTaskSupplierForBulkRequest((List<String>) targetObject,
+ resourceIdentifier, optionsParamInQuery, topicParamInQuery, requestId, includeDescendants);
+ } else {
+ taskSupplier = getTaskSupplierForGetRequest(targetObject.toString(), resourceIdentifier,
+ optionsParamInQuery, topicParamInQuery, requestId, includeDescendants);
+ }
+ if (taskSupplier == NO_OBJECT_SUPPLIER) {
+ return new ResponseEntity<>(Map.of("status", "Unable to execute request as "
+ + "datastore is not implemented."), HttpStatus.NOT_IMPLEMENTED);
+ }
+ return executeTaskAsync(topicParamInQuery, requestId, taskSupplier);
}
-
}
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 ff7bda6a47..9a71798fa1 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
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Nordix Foundation
+ * Copyright (C) 2022-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.
@@ -21,24 +21,13 @@
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;
@Component
@RequiredArgsConstructor
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}")
- private int timeOutInMilliSeconds;
- @Value("${notification.enabled:true}")
- private boolean notificationFeatureEnabled;
+ private final NcmpCachedResourceRequestHandler ncmpCachedResourceRequestHandler;
+ private final NcmpPassthroughResourceRequestHandler ncmpPassthroughResourceRequestHandler;
/**
* Gets ncmp datastore handler.
@@ -46,31 +35,17 @@ public class NcmpDatastoreResourceRequestHandlerFactory {
* @param datastoreType the datastore type
* @return the ncmp datastore handler
*/
- public NcmpDatastoreRequestHandler getNcmpDatastoreResourceRequestHandler(
- final DatastoreType datastoreType) {
+ public NcmpDatastoreRequestHandler getNcmpResourceRequestHandler(final DatastoreType datastoreType) {
switch (datastoreType) {
case OPERATIONAL:
- return new NcmpDatastoreOperationalResourceRequestHandler(networkCmProxyDataService,
- cpsNcmpTaskExecutor, timeOutInMilliSeconds, notificationFeatureEnabled);
+ ncmpCachedResourceRequestHandler.setDataStoreName(datastoreType.getDatastoreName());
+ return ncmpCachedResourceRequestHandler;
case PASSTHROUGH_RUNNING:
- return new NcmpDatastorePassthroughRunningResourceRequestHandler(networkCmProxyDataService,
- cpsNcmpTaskExecutor, timeOutInMilliSeconds, notificationFeatureEnabled);
case PASSTHROUGH_OPERATIONAL:
default:
- return new NcmpDatastorePassthroughOperationalResourceRequestHandler(networkCmProxyDataService,
- cpsNcmpTaskExecutor, timeOutInMilliSeconds, notificationFeatureEnabled);
+ ncmpPassthroughResourceRequestHandler.setDataStoreName(datastoreType.getDatastoreName());
+ return ncmpPassthroughResourceRequestHandler;
}
}
-
- /**
- * 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);
- }
-
}
diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpPassthroughResourceRequestHandler.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpPassthroughResourceRequestHandler.java
new file mode 100644
index 0000000000..ab5d587e93
--- /dev/null
+++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpPassthroughResourceRequestHandler.java
@@ -0,0 +1,58 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022-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.rest.controller.handlers;
+
+import java.util.List;
+import java.util.function.Supplier;
+import lombok.Setter;
+import org.springframework.stereotype.Component;
+
+@Component
+public class NcmpPassthroughResourceRequestHandler extends NcmpDatastoreRequestHandler {
+
+ @Setter
+ private String dataStoreName;
+
+ @Override
+ public Supplier<Object> getTaskSupplierForGetRequest(final String cmHandleId,
+ final String resourceIdentifier,
+ final String optionsParamInQuery,
+ final String topicParamInQuery,
+ final String requestId,
+ final boolean includeDescendants) {
+
+ return () -> networkCmProxyDataService.getResourceDataForCmHandle(
+ dataStoreName, cmHandleId, resourceIdentifier, optionsParamInQuery, topicParamInQuery, requestId);
+ }
+
+ @Override
+ public Supplier<Object> getTaskSupplierForBulkRequest(final List<String> cmHandleIds,
+ final String resourceIdentifier,
+ final String optionsParamInQuery,
+ final String topicParamInQuery,
+ final String requestId,
+ final boolean includeDescendants) {
+
+ return () -> networkCmProxyDataService.getResourceDataForCmHandleBatch(
+ dataStoreName, cmHandleIds, resourceIdentifier, optionsParamInQuery, topicParamInQuery, requestId);
+ }
+
+}
diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/TaskManagementDefaultHandler.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/TaskManagementDefaultHandler.java
new file mode 100644
index 0000000000..08e8407c63
--- /dev/null
+++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/TaskManagementDefaultHandler.java
@@ -0,0 +1,63 @@
+/*
+ * ============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.rest.controller.handlers;
+
+import java.util.List;
+import java.util.function.Supplier;
+import org.onap.cps.spi.FetchDescendantsOption;
+
+public interface TaskManagementDefaultHandler {
+
+ String NO_REQUEST_ID = null;
+ String NO_TOPIC = null;
+ Supplier<Object> NO_OBJECT_SUPPLIER = null;
+
+ default Supplier<Object> getTaskSupplierForGetRequest(final String cmHandleId,
+ final String resourceIdentifier,
+ final String optionsParamInQuery,
+ final String topicParamInQuery,
+ final String requestId,
+ final boolean includeDescendant) {
+ return NO_OBJECT_SUPPLIER;
+
+ }
+
+ default Supplier<Object> getTaskSupplierForQueryRequest(final String cmHandleId,
+ final String resourceIdentifier,
+ final boolean includeDescendant) {
+ return NO_OBJECT_SUPPLIER;
+
+ }
+
+ default Supplier<Object> getTaskSupplierForBulkRequest(final List<String> cmHandleIds,
+ final String resourceIdentifier,
+ final String optionsParamInQuery,
+ final String topicParamInQuery,
+ final String requestId,
+ final boolean includeDescendant) {
+ return NO_OBJECT_SUPPLIER;
+ }
+
+ static FetchDescendantsOption getFetchDescendantsOption(final boolean includeDescendants) {
+ return includeDescendants ? FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
+ : FetchDescendantsOption.OMIT_DESCENDANTS;
+ }
+}