aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller')
-rwxr-xr-xcps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java62
-rwxr-xr-xcps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryController.java12
-rw-r--r--cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpCachedResourceRequestHandler.java91
-rw-r--r--cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreRequestHandler.java105
-rw-r--r--cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpPassthroughResourceRequestHandler.java118
5 files changed, 36 insertions, 352 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 5b54ac243..726f4e4e2 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
@@ -38,7 +38,8 @@ import java.util.Map;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
-import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
+import org.onap.cps.ncmp.api.impl.NetworkCmProxyFacade;
+import org.onap.cps.ncmp.api.impl.NetworkCmProxyInventoryFacade;
import org.onap.cps.ncmp.api.impl.config.embeddedcache.TrustLevelCacheConfig;
import org.onap.cps.ncmp.api.impl.exception.InvalidDatastoreException;
import org.onap.cps.ncmp.api.impl.inventory.CompositeState;
@@ -48,9 +49,6 @@ import org.onap.cps.ncmp.api.models.CmHandleQueryApiParameters;
import org.onap.cps.ncmp.api.models.CmResourceAddress;
import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
import org.onap.cps.ncmp.rest.api.NetworkCmProxyApi;
-import org.onap.cps.ncmp.rest.controller.handlers.NcmpCachedResourceRequestHandler;
-import org.onap.cps.ncmp.rest.controller.handlers.NcmpDatastoreRequestHandler;
-import org.onap.cps.ncmp.rest.controller.handlers.NcmpPassthroughResourceRequestHandler;
import org.onap.cps.ncmp.rest.mapper.CmHandleStateMapper;
import org.onap.cps.ncmp.rest.mapper.DataOperationRequestMapper;
import org.onap.cps.ncmp.rest.model.CmHandlePublicProperties;
@@ -62,6 +60,7 @@ import org.onap.cps.ncmp.rest.model.RestOutputCmHandle;
import org.onap.cps.ncmp.rest.model.RestOutputCmHandleCompositeState;
import org.onap.cps.ncmp.rest.model.RestOutputCmHandlePublicProperties;
import org.onap.cps.ncmp.rest.util.DeprecationHelper;
+import org.onap.cps.spi.model.DataNode;
import org.onap.cps.spi.model.ModuleDefinition;
import org.onap.cps.utils.JsonObjectMapper;
import org.springframework.beans.factory.annotation.Qualifier;
@@ -78,14 +77,15 @@ import org.springframework.web.bind.annotation.RestController;
public class NetworkCmProxyController implements NetworkCmProxyApi {
private static final String NO_BODY = null;
- private final NetworkCmProxyDataService networkCmProxyDataService;
+ private final NetworkCmProxyFacade networkCmProxyFacade;
+ private final NetworkCmProxyInventoryFacade networkCmProxyInventoryFacade;
private final JsonObjectMapper jsonObjectMapper;
private final DeprecationHelper deprecationHelper;
private final NcmpRestInputMapper ncmpRestInputMapper;
private final CmHandleStateMapper cmHandleStateMapper;
- private final NcmpCachedResourceRequestHandler ncmpCachedResourceRequestHandler;
- private final NcmpPassthroughResourceRequestHandler ncmpPassthroughResourceRequestHandler;
+
private final DataOperationRequestMapper dataOperationRequestMapper;
+
@Qualifier(TrustLevelCacheConfig.TRUST_LEVEL_PER_CM_HANDLE)
private final Map<String, TrustLevel> trustLevelPerCmHandle;
@@ -110,18 +110,19 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
final String topicParamInQuery,
final Boolean includeDescendants,
final String authorization) {
- final NcmpDatastoreRequestHandler ncmpDatastoreRequestHandler = getNcmpDatastoreRequestHandler(datastoreName);
final CmResourceAddress cmResourceAddress = new CmResourceAddress(datastoreName, cmHandle, resourceIdentifier);
- return ncmpDatastoreRequestHandler.executeRequest(cmResourceAddress, optionsParamInQuery, topicParamInQuery,
- includeDescendants, authorization);
+ final Object result = networkCmProxyFacade.getResourceDataForCmHandle(cmResourceAddress, optionsParamInQuery,
+ topicParamInQuery, includeDescendants, authorization);
+ return ResponseEntity.ok(result);
}
@Override
public ResponseEntity<Object> executeDataOperationForCmHandles(final String topicParamInQuery,
final DataOperationRequest dataOperationRequest,
final String authorization) {
- return ncmpPassthroughResourceRequestHandler.executeRequest(topicParamInQuery,
+ final Object result = networkCmProxyFacade.executeDataOperationForCmHandles(topicParamInQuery,
dataOperationRequestMapper.toDataOperationRequest(dataOperationRequest), authorization);
+ return ResponseEntity.ok(result);
}
/**
@@ -133,7 +134,7 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
* @param optionsParamInQuery options query parameter
* @param topicParamInQuery topic query parameter
* @param includeDescendants whether to include descendants or not
- * @return {@code ResponseEntity} response from dmi plugin
+ * @return {@code ResponseEntity} response. Body contains a collection of DataNodes
*/
@Override
@@ -144,7 +145,9 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
final String topicParamInQuery,
final Boolean includeDescendants) {
validateDataStore(OPERATIONAL, datastoreName);
- return ncmpCachedResourceRequestHandler.executeRequest(cmHandle, cpsPath, includeDescendants);
+ final Collection<DataNode> dataNodes = networkCmProxyFacade.queryResourceDataForCmHandle(cmHandle, cpsPath,
+ includeDescendants);
+ return ResponseEntity.ok(dataNodes);
}
/**
@@ -169,7 +172,7 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
validateDataStore(PASSTHROUGH_RUNNING, datastoreName);
- final Object responseObject = networkCmProxyDataService
+ final Object responseObject = networkCmProxyFacade
.writeResourceDataPassThroughRunningForCmHandle(
cmHandle, resourceIdentifier, PATCH,
jsonObjectMapper.asJsonString(requestBody), contentType, authorization);
@@ -196,7 +199,7 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
final String authorization) {
validateDataStore(PASSTHROUGH_RUNNING, datastoreName);
- networkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle(cmHandle,
+ networkCmProxyFacade.writeResourceDataPassThroughRunningForCmHandle(cmHandle,
resourceIdentifier, CREATE, jsonObjectMapper.asJsonString(requestBody), contentType, authorization);
return new ResponseEntity<>(HttpStatus.CREATED);
}
@@ -222,7 +225,7 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
final String authorization) {
validateDataStore(PASSTHROUGH_RUNNING, datastoreName);
- networkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle(cmHandle,
+ networkCmProxyFacade.writeResourceDataPassThroughRunningForCmHandle(cmHandle,
resourceIdentifier, UPDATE, jsonObjectMapper.asJsonString(requestBody), contentType, authorization);
return new ResponseEntity<>(HttpStatus.OK);
}
@@ -246,7 +249,7 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
validateDataStore(PASSTHROUGH_RUNNING, datastoreName);
- networkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle(cmHandle,
+ networkCmProxyFacade.writeResourceDataPassThroughRunningForCmHandle(cmHandle,
resourceIdentifier, DELETE, NO_BODY, contentType, authorization);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@@ -263,7 +266,7 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
final CmHandleQueryParameters cmHandleQueryParameters) {
final CmHandleQueryApiParameters cmHandleQueryApiParameters =
deprecationHelper.mapOldConditionProperties(cmHandleQueryParameters);
- final Collection<NcmpServiceCmHandle> cmHandles = networkCmProxyDataService
+ final Collection<NcmpServiceCmHandle> cmHandles = networkCmProxyInventoryFacade
.executeCmHandleSearch(cmHandleQueryApiParameters);
final List<RestOutputCmHandle> outputCmHandles =
cmHandles.stream().map(this::toRestOutputCmHandle).collect(Collectors.toList());
@@ -282,7 +285,7 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
final CmHandleQueryApiParameters cmHandleQueryApiParameters =
jsonObjectMapper.convertToValueType(cmHandleQueryParameters, CmHandleQueryApiParameters.class);
final Collection<String> cmHandleIds
- = networkCmProxyDataService.executeCmHandleIdSearch(cmHandleQueryApiParameters);
+ = networkCmProxyInventoryFacade.executeCmHandleIdSearch(cmHandleQueryApiParameters);
return ResponseEntity.ok(List.copyOf(cmHandleIds));
}
@@ -294,7 +297,8 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
*/
@Override
public ResponseEntity<RestOutputCmHandle> retrieveCmHandleDetailsById(final String cmHandleId) {
- final NcmpServiceCmHandle ncmpServiceCmHandle = networkCmProxyDataService.getNcmpServiceCmHandle(cmHandleId);
+ final NcmpServiceCmHandle ncmpServiceCmHandle
+ = networkCmProxyInventoryFacade.getNcmpServiceCmHandle(cmHandleId);
final RestOutputCmHandle restOutputCmHandle = toRestOutputCmHandle(ncmpServiceCmHandle);
return ResponseEntity.ok(restOutputCmHandle);
}
@@ -309,7 +313,7 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
public ResponseEntity<RestOutputCmHandlePublicProperties> getCmHandlePublicPropertiesByCmHandleId(
final String cmHandleId) {
final CmHandlePublicProperties cmHandlePublicProperties = new CmHandlePublicProperties();
- cmHandlePublicProperties.add(networkCmProxyDataService.getCmHandlePublicProperties(cmHandleId));
+ cmHandlePublicProperties.add(networkCmProxyInventoryFacade.getCmHandlePublicProperties(cmHandleId));
final RestOutputCmHandlePublicProperties restOutputCmHandlePublicProperties =
new RestOutputCmHandlePublicProperties();
restOutputCmHandlePublicProperties.setPublicCmHandleProperties(cmHandlePublicProperties);
@@ -325,7 +329,7 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
@Override
public ResponseEntity<RestOutputCmHandleCompositeState> getCmHandleStateByCmHandleId(
final String cmHandleId) {
- final CompositeState cmHandleState = networkCmProxyDataService.getCmHandleCompositeState(cmHandleId);
+ final CompositeState cmHandleState = networkCmProxyInventoryFacade.getCmHandleCompositeState(cmHandleId);
final RestOutputCmHandleCompositeState restOutputCmHandleCompositeState =
new RestOutputCmHandleCompositeState();
restOutputCmHandleCompositeState.setState(
@@ -348,9 +352,9 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
final Collection<ModuleDefinition> moduleDefinitions;
if (StringUtils.hasText(moduleName)) {
moduleDefinitions =
- networkCmProxyDataService.getModuleDefinitionsByCmHandleAndModule(cmHandleId, moduleName, revision);
+ networkCmProxyInventoryFacade.getModuleDefinitionsByCmHandleAndModule(cmHandleId, moduleName, revision);
} else {
- moduleDefinitions = networkCmProxyDataService.getModuleDefinitionsByCmHandleId(cmHandleId);
+ moduleDefinitions = networkCmProxyInventoryFacade.getModuleDefinitionsByCmHandleId(cmHandleId);
if (StringUtils.hasText(revision)) {
log.warn("Ignoring revision filter as no module name is provided");
}
@@ -370,7 +374,7 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
*/
public ResponseEntity<List<RestModuleReference>> getModuleReferencesByCmHandle(final String cmHandle) {
final List<RestModuleReference> restModuleReferences =
- networkCmProxyDataService.getYangResourcesModuleReferences(cmHandle).stream()
+ networkCmProxyInventoryFacade.getYangResourcesModuleReferences(cmHandle).stream()
.map(ncmpRestInputMapper::toRestModuleReference)
.collect(Collectors.toList());
return new ResponseEntity<>(restModuleReferences, HttpStatus.OK);
@@ -386,7 +390,7 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
@Override
public ResponseEntity<Object> setDataSyncEnabledFlagForCmHandle(final String cmHandleId,
final Boolean dataSyncEnabledFlag) {
- networkCmProxyDataService.setDataSyncEnabled(cmHandleId, dataSyncEnabledFlag);
+ networkCmProxyInventoryFacade.setDataSyncEnabled(cmHandleId, dataSyncEnabledFlag);
return new ResponseEntity<>(HttpStatus.OK);
}
@@ -417,11 +421,5 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
}
}
- private NcmpDatastoreRequestHandler getNcmpDatastoreRequestHandler(final String datastoreName) {
- if (OPERATIONAL.equals(DatastoreType.fromDatastoreName(datastoreName))) {
- return ncmpCachedResourceRequestHandler;
- }
- return ncmpPassthroughResourceRequestHandler;
- }
}
diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryController.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryController.java
index 5467eeffc..5185b47bb 100755
--- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryController.java
+++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryController.java
@@ -27,7 +27,7 @@ import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
-import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
+import org.onap.cps.ncmp.api.impl.NetworkCmProxyInventoryFacade;
import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters;
import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse;
import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse.Status;
@@ -47,7 +47,7 @@ import org.springframework.web.bind.annotation.RestController;
@RequiredArgsConstructor
public class NetworkCmProxyInventoryController implements NetworkCmProxyInventoryApi {
- private final NetworkCmProxyDataService networkCmProxyDataService;
+ private final NetworkCmProxyInventoryFacade networkCmProxyInventoryFacade;
private final NcmpRestInputMapper ncmpRestInputMapper;
@Override
@@ -55,8 +55,8 @@ public class NetworkCmProxyInventoryController implements NetworkCmProxyInventor
final CmHandleQueryServiceParameters cmHandleQueryServiceParameters = ncmpRestInputMapper
.toCmHandleQueryServiceParameters(cmHandleQueryParameters);
- final Collection<String> cmHandleIds = networkCmProxyDataService
- .executeCmHandleIdSearchForInventory(cmHandleQueryServiceParameters);
+ final Collection<String> cmHandleIds = networkCmProxyInventoryFacade
+ .executeParameterizedCmHandleIdSearch(cmHandleQueryServiceParameters);
return ResponseEntity.ok(List.copyOf(cmHandleIds));
}
@@ -69,7 +69,7 @@ public class NetworkCmProxyInventoryController implements NetworkCmProxyInventor
@Override
public ResponseEntity<List<String>> getAllCmHandleIdsForRegisteredDmi(final String dmiPluginIdentifier) {
final Collection<String> cmHandleIds =
- networkCmProxyDataService.getAllCmHandleIdsByDmiPluginIdentifier(dmiPluginIdentifier);
+ networkCmProxyInventoryFacade.getAllCmHandleIdsByDmiPluginIdentifier(dmiPluginIdentifier);
return ResponseEntity.ok(List.copyOf(cmHandleIds));
}
@@ -84,7 +84,7 @@ public class NetworkCmProxyInventoryController implements NetworkCmProxyInventor
public ResponseEntity updateDmiPluginRegistration(
final @Valid RestDmiPluginRegistration restDmiPluginRegistration) {
final DmiPluginRegistrationResponse dmiPluginRegistrationResponse =
- networkCmProxyDataService.updateDmiRegistrationAndSyncModule(
+ networkCmProxyInventoryFacade.updateDmiRegistrationAndSyncModule(
ncmpRestInputMapper.toDmiPluginRegistration(restDmiPluginRegistration));
final DmiPluginRegistrationErrorResponse failedRegistrationErrorResponse =
getFailureRegistrationResponse(dmiPluginRegistrationResponse);
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
deleted file mode 100644
index 80e1c442e..000000000
--- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpCachedResourceRequestHandler.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2022-2024 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.Collection;
-import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
-import org.onap.cps.ncmp.api.NetworkCmProxyQueryService;
-import org.onap.cps.ncmp.api.models.CmResourceAddress;
-import org.onap.cps.spi.FetchDescendantsOption;
-import org.onap.cps.spi.model.DataNode;
-import org.springframework.http.ResponseEntity;
-import org.springframework.stereotype.Component;
-import reactor.core.publisher.Mono;
-
-@Component
-public class NcmpCachedResourceRequestHandler extends NcmpDatastoreRequestHandler {
-
- private final NetworkCmProxyDataService networkCmProxyDataService;
- private final NetworkCmProxyQueryService networkCmProxyQueryService;
-
- /**
- * Constructor.
- *
- * @param networkCmProxyDataService @see org.onap.cps.ncmp.api.NetworkCmProxyDataService
- * @param networkCmProxyQueryService @see org.onap.cps.ncmp.api.NetworkCmProxyQueryService
- */
- public NcmpCachedResourceRequestHandler(final NetworkCmProxyDataService networkCmProxyDataService,
- final NetworkCmProxyQueryService networkCmProxyQueryService) {
- this.networkCmProxyDataService = networkCmProxyDataService;
- this.networkCmProxyQueryService = networkCmProxyQueryService;
- }
-
- /**
- * Executes a synchronous query 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 Collection<DataNode> dataNodes = getTaskSupplierForQueryRequest(cmHandleId, resourceIdentifier,
- includeDescendants);
- return ResponseEntity.ok(dataNodes);
- }
-
- @Override
- protected Mono<Object> getResourceDataForCmHandle(final CmResourceAddress cmResourceAddress,
- final String optionsParamInQuery,
- final String topicParamInQuery,
- final String requestId,
- final boolean includeDescendants,
- final String authorization) {
- final FetchDescendantsOption fetchDescendantsOption = getFetchDescendantsOption(includeDescendants);
- return Mono.fromSupplier(
- () -> networkCmProxyDataService.getResourceDataForCmHandle(cmResourceAddress, fetchDescendantsOption));
- }
-
- private Collection<DataNode> getTaskSupplierForQueryRequest(final String cmHandleId,
- final String resourceIdentifier,
- final boolean includeDescendants) {
- final FetchDescendantsOption fetchDescendantsOption = getFetchDescendantsOption(includeDescendants);
- return networkCmProxyQueryService.queryResourceDataOperational(cmHandleId, resourceIdentifier,
- fetchDescendantsOption);
- }
-
- private static FetchDescendantsOption getFetchDescendantsOption(final boolean includeDescendants) {
- return includeDescendants ? FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
- : FetchDescendantsOption.OMIT_DESCENDANTS;
- }
-}
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
deleted file mode 100644
index 20059e20f..000000000
--- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreRequestHandler.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2022-2024 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 lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.onap.cps.ncmp.api.models.CmResourceAddress;
-import org.onap.cps.ncmp.rest.util.TopicValidator;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.http.ResponseEntity;
-import org.springframework.stereotype.Service;
-import reactor.core.publisher.Mono;
-
-@Slf4j
-@Service
-@RequiredArgsConstructor
-public abstract class NcmpDatastoreRequestHandler {
-
- private static final String NO_REQUEST_ID = null;
- private static final String NO_TOPIC = null;
-
- @Value("${notification.async.executor.time-out-value-in-ms:60000}")
- protected int timeOutInMilliSeconds;
- @Value("${notification.enabled:true}")
- protected boolean notificationFeatureEnabled;
-
- /**
- * Executes synchronous/asynchronous get request for given cm handle.
- *
- * @param cmResourceAddress the name of the datastore, cm handle and resource identifier
- * @param optionsParamInQuery the options param in query
- * @param topicParamInQuery the topic param in query
- * @param includeDescendants whether include descendants
- * @param authorization contents of Authorization header, or null if not present
- * @return the response entity
- */
- public ResponseEntity<Object> executeRequest(final CmResourceAddress cmResourceAddress,
- final String optionsParamInQuery,
- final String topicParamInQuery,
- final boolean includeDescendants,
- final String authorization) {
-
- final boolean asyncResponseRequested = topicParamInQuery != null;
- if (asyncResponseRequested && notificationFeatureEnabled) {
- return fetchResourceDataAsynchronously(cmResourceAddress, optionsParamInQuery, topicParamInQuery,
- includeDescendants, authorization);
- }
-
- if (asyncResponseRequested) {
- log.warn("Asynchronous request is unavailable as notification feature is currently disabled, "
- + "will use synchronous operation.");
- }
- final Mono<Object> resourceDataMono = getResourceDataForCmHandle(cmResourceAddress, optionsParamInQuery,
- NO_TOPIC, NO_REQUEST_ID, includeDescendants, authorization);
- return fetchResourceDataSynchronously(resourceDataMono);
- }
-
- private ResponseEntity<Object> fetchResourceDataSynchronously(final Mono<Object> resourceDataMono) {
- return ResponseEntity.ok(resourceDataMono.block());
- }
-
- private ResponseEntity<Object> fetchResourceDataAsynchronously(final CmResourceAddress cmResourceAddress,
- final String optionsParamInQuery,
- final String topicParamInQuery,
- final boolean includeDescendants,
- final String authorization) {
- TopicValidator.validateTopicName(topicParamInQuery);
- final String requestId = UUID.randomUUID().toString();
- getResourceDataForCmHandle(cmResourceAddress, optionsParamInQuery, topicParamInQuery, requestId,
- includeDescendants, authorization)
- .doOnSuccess(result -> log.debug("Async operation succeeded for request id {}: {}", requestId, result))
- .doOnError(error ->
- log.error("Async operation failed for request id {}: {}", requestId, error.getMessage()))
- .subscribe();
- log.debug("Received Async request with id {}", requestId);
- return ResponseEntity.ok(Map.of("requestId", requestId));
- }
-
- protected abstract Mono<Object> getResourceDataForCmHandle(final CmResourceAddress cmResourceAddress,
- final String optionsParamInQuery,
- final String topicParamInQuery,
- final String requestId,
- final boolean includeDescendant,
- final String authorization);
-}
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
deleted file mode 100644
index 53e374d30..000000000
--- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpPassthroughResourceRequestHandler.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2022-2024 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 static org.onap.cps.ncmp.api.impl.operations.DatastoreType.OPERATIONAL;
-import static org.onap.cps.ncmp.api.impl.operations.OperationType.READ;
-
-import java.util.Map;
-import java.util.UUID;
-import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
-import org.onap.cps.ncmp.api.impl.exception.InvalidDatastoreException;
-import org.onap.cps.ncmp.api.impl.operations.DatastoreType;
-import org.onap.cps.ncmp.api.impl.operations.OperationType;
-import org.onap.cps.ncmp.api.models.CmResourceAddress;
-import org.onap.cps.ncmp.api.models.DataOperationRequest;
-import org.onap.cps.ncmp.rest.exceptions.OperationNotSupportedException;
-import org.onap.cps.ncmp.rest.exceptions.PayloadTooLargeException;
-import org.onap.cps.ncmp.rest.util.TopicValidator;
-import org.springframework.http.ResponseEntity;
-import org.springframework.stereotype.Service;
-import reactor.core.publisher.Mono;
-
-@Service
-public class NcmpPassthroughResourceRequestHandler extends NcmpDatastoreRequestHandler {
-
- private final NetworkCmProxyDataService networkCmProxyDataService;
- private static final int MAXIMUM_CM_HANDLES_PER_OPERATION = 200;
- private static final String PAYLOAD_TOO_LARGE_TEMPLATE = "Operation '%s' affects too many (%d) cm handles";
-
- /**
- * Constructor.
- *
- * @param networkCmProxyDataService @see org.onap.cps.ncmp.api.NetworkCmProxyDataService
- */
- public NcmpPassthroughResourceRequestHandler(final NetworkCmProxyDataService networkCmProxyDataService) {
- this.networkCmProxyDataService = networkCmProxyDataService;
- }
-
- /**
- * Executes asynchronous request for group of cm handles to resource data.
- *
- * @param topicParamInQuery the topic param in query
- * @param dataOperationRequest data operation request details for resource data
- * @param authorization contents of Authorization header, or null if not present
- * @return the response entity
- */
- public ResponseEntity<Object> executeRequest(final String topicParamInQuery,
- final DataOperationRequest dataOperationRequest,
- final String authorization) {
- validateDataOperationRequest(topicParamInQuery, dataOperationRequest);
- if (!notificationFeatureEnabled) {
- return ResponseEntity.ok(Map.of("status",
- "Asynchronous request is unavailable as notification feature is currently disabled."));
- }
- return getRequestIdAndSendDataOperationRequestToDmiService(topicParamInQuery, dataOperationRequest,
- authorization);
- }
-
- @Override
- protected Mono<Object> getResourceDataForCmHandle(final CmResourceAddress cmResourceAddress,
- final String optionsParamInQuery,
- final String topicParamInQuery,
- final String requestId,
- final boolean includeDescendants,
- final String authorization) {
- return networkCmProxyDataService.getResourceDataForCmHandle(cmResourceAddress, optionsParamInQuery,
- topicParamInQuery, requestId, authorization);
- }
-
- private ResponseEntity<Object> getRequestIdAndSendDataOperationRequestToDmiService(
- final String topicParamInQuery,
- final DataOperationRequest dataOperationRequest,
- final String authorization) {
- final String requestId = UUID.randomUUID().toString();
- networkCmProxyDataService.executeDataOperationForCmHandles(topicParamInQuery, dataOperationRequest, requestId,
- authorization);
- return ResponseEntity.ok(Map.of("requestId", requestId));
- }
-
- private void validateDataOperationRequest(final String topicParamInQuery,
- final DataOperationRequest dataOperationRequest) {
- TopicValidator.validateTopicName(topicParamInQuery);
- dataOperationRequest.getDataOperationDefinitions().forEach(dataOperationDetail -> {
- if (OperationType.fromOperationName(dataOperationDetail.getOperation()) != READ) {
- throw new OperationNotSupportedException(
- dataOperationDetail.getOperation() + " operation not yet supported");
- }
- if (DatastoreType.fromDatastoreName(dataOperationDetail.getDatastore()) == OPERATIONAL) {
- throw new InvalidDatastoreException(dataOperationDetail.getDatastore()
- + " datastore is not supported");
- }
- if (dataOperationDetail.getCmHandleIds().size() > MAXIMUM_CM_HANDLES_PER_OPERATION) {
- final String errorMessage = String.format(PAYLOAD_TOO_LARGE_TEMPLATE,
- dataOperationDetail.getOperationId(),
- dataOperationDetail.getCmHandleIds().size());
- throw new PayloadTooLargeException(errorMessage);
- }
- });
- }
-}