diff options
Diffstat (limited to 'cps-ncmp-rest/src/main/java/org')
7 files changed, 101 insertions, 133 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 a8bc3aec76..324c1ae2d4 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,8 +39,9 @@ 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.NcmpCachedResourceRequestHandler; import org.onap.cps.ncmp.rest.controller.handlers.NcmpDatastoreRequestHandler; -import org.onap.cps.ncmp.rest.controller.handlers.NcmpDatastoreResourceRequestHandlerFactory; +import org.onap.cps.ncmp.rest.controller.handlers.NcmpPassthroughResourceRequestHandler; import org.onap.cps.ncmp.rest.exceptions.InvalidDatastoreException; import org.onap.cps.ncmp.rest.mapper.CmHandleStateMapper; import org.onap.cps.ncmp.rest.model.CmHandlePublicProperties; @@ -69,17 +70,18 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { private final DeprecationHelper deprecationHelper; private final NcmpRestInputMapper ncmpRestInputMapper; private final CmHandleStateMapper cmHandleStateMapper; - private final NcmpDatastoreResourceRequestHandlerFactory ncmpDatastoreResourceRequestHandlerFactory; + private final NcmpCachedResourceRequestHandler ncmpCachedResourceRequestHandler; + private final NcmpPassthroughResourceRequestHandler ncmpPassthroughResourceRequestHandler; /** * 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 includeDescendantsAsObject 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 includeDescendants whether to include descendants or not * @return {@code ResponseEntity} response from dmi plugin */ @@ -89,15 +91,11 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { final String resourceIdentifier, final String optionsParamInQuery, final String topicParamInQuery, - final Boolean includeDescendantsAsObject) { + final Boolean includeDescendants) { - final NcmpDatastoreRequestHandler ncmpDatastoreRequestHandler = - ncmpDatastoreResourceRequestHandlerFactory.getNcmpResourceRequestHandler( - DatastoreType.fromDatastoreName(datastoreName)); - final boolean includeDescendants = toPrimitiveFlag(includeDescendantsAsObject); - - return ncmpDatastoreRequestHandler.executeRequest(cmHandle, resourceIdentifier, + final NcmpDatastoreRequestHandler ncmpDatastoreRequestHandler = getNcmpDatastoreRequestHandler(datastoreName); + return ncmpDatastoreRequestHandler.executeRequest(datastoreName, cmHandle, resourceIdentifier, optionsParamInQuery, topicParamInQuery, includeDescendants); } @@ -107,30 +105,25 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { final String datastoreName, final Object requestBody, final String optionsParamInQuery, - final Boolean includeDescendantsAsObject) { + final Boolean includeDescendants) { - final NcmpDatastoreRequestHandler ncmpDatastoreRequestHandler = - ncmpDatastoreResourceRequestHandlerFactory.getNcmpResourceRequestHandler( - DatastoreType.fromDatastoreName(datastoreName)); + final NcmpDatastoreRequestHandler ncmpDatastoreRequestHandler = getNcmpDatastoreRequestHandler(datastoreName); final List<String> cmHandleIds = jsonObjectMapper.convertJsonString(jsonObjectMapper.asJsonString(requestBody), List.class); - - final boolean includeDescendants = toPrimitiveFlag(includeDescendantsAsObject); - - return ncmpDatastoreRequestHandler.executeRequest(cmHandleIds, resourceIdentifier, + return ncmpDatastoreRequestHandler.executeRequest(datastoreName, 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 includeDescendantsAsObject 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 includeDescendants whether to include descendants or not * @return {@code ResponseEntity} response from dmi plugin */ @@ -140,14 +133,8 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { final String cpsPath, final String optionsParamInQuery, final String topicParamInQuery, - final Boolean includeDescendantsAsObject) { + final Boolean includeDescendants) { validateDataStore(DatastoreType.OPERATIONAL, datastoreName); - final NcmpDatastoreRequestHandler ncmpCachedResourceRequestHandler = - ncmpDatastoreResourceRequestHandlerFactory.getNcmpResourceRequestHandler( - DatastoreType.fromDatastoreName(datastoreName)); - - final boolean includeDescendants = toPrimitiveFlag(includeDescendantsAsObject); - return ncmpCachedResourceRequestHandler.executeRequest(cmHandle, cpsPath, includeDescendants); } @@ -393,11 +380,13 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { } } - private static boolean toPrimitiveFlag(final Boolean includeDescendantsAsObject) { - if (includeDescendantsAsObject == null) { - return false; + private NcmpDatastoreRequestHandler getNcmpDatastoreRequestHandler(final String datastoreName) { + if (DatastoreType.OPERATIONAL.equals(DatastoreType.fromDatastoreName(datastoreName))) { + return ncmpCachedResourceRequestHandler; } - return includeDescendantsAsObject.booleanValue(); + return ncmpPassthroughResourceRequestHandler; } + + } 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 index 620f64782b..76946d3af2 100644 --- 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 @@ -21,22 +21,36 @@ 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.NetworkCmProxyDataService; import org.onap.cps.ncmp.api.NetworkCmProxyQueryService; +import org.onap.cps.ncmp.rest.executor.CpsNcmpTaskExecutor; import org.onap.cps.spi.FetchDescendantsOption; import org.springframework.stereotype.Component; -@RequiredArgsConstructor @Component public class NcmpCachedResourceRequestHandler extends NcmpDatastoreRequestHandler { - @Setter - private String dataStoreName; + private final NetworkCmProxyDataService networkCmProxyDataService; private final NetworkCmProxyQueryService networkCmProxyQueryService; + /** + * Constructor. + * + * @param cpsNcmpTaskExecutor @see org.onap.cps.ncmp.rest.executor.CpsNcmpTaskExecutor + * @param networkCmProxyDataService @see org.onap.cps.ncmp.api.NetworkCmProxyDataService + * @param networkCmProxyQueryService @see org.onap.cps.ncmp.api.NetworkCmProxyQueryService + */ + public NcmpCachedResourceRequestHandler(final CpsNcmpTaskExecutor cpsNcmpTaskExecutor, + final NetworkCmProxyDataService networkCmProxyDataService, + final NetworkCmProxyQueryService networkCmProxyQueryService) { + super(cpsNcmpTaskExecutor); + this.networkCmProxyDataService = networkCmProxyDataService; + this.networkCmProxyQueryService = networkCmProxyQueryService; + } + @Override - public Supplier<Object> getTaskSupplierForGetRequest(final String cmHandleId, + public Supplier<Object> getTaskSupplierForGetRequest(final String datastoreName, + final String cmHandleId, final String resourceIdentifier, final String optionsParamInQuery, final String topicParamInQuery, @@ -46,7 +60,7 @@ public class NcmpCachedResourceRequestHandler extends NcmpDatastoreRequestHandle final FetchDescendantsOption fetchDescendantsOption = TaskManagementDefaultHandler.getFetchDescendantsOption(includeDescendants); - return () -> networkCmProxyDataService.getResourceDataForCmHandle(dataStoreName, cmHandleId, resourceIdentifier, + return () -> networkCmProxyDataService.getResourceDataForCmHandle(datastoreName, cmHandleId, resourceIdentifier, fetchDescendantsOption); } 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 050e724b2c..a32c462e76 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 @@ -24,34 +24,32 @@ import java.util.List; import java.util.Map; import java.util.UUID; import java.util.function.Supplier; -import lombok.NoArgsConstructor; +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.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; -@NoArgsConstructor @Slf4j @Service +@RequiredArgsConstructor public class NcmpDatastoreRequestHandler implements TaskManagementDefaultHandler { @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; + + private final CpsNcmpTaskExecutor cpsNcmpTaskExecutor; /** * Executes synchronous/asynchronous request for given cm handle. * + * @param datastoreName the name of the datastore * @param cmHandleId the cm handle * @param resourceIdentifier the resource identifier * @param optionsParamInQuery the options param in query @@ -59,7 +57,8 @@ public class NcmpDatastoreRequestHandler implements TaskManagementDefaultHandler * @param includeDescendants whether include descendants * @return the response entity */ - public ResponseEntity<Object> executeRequest(final String cmHandleId, + public ResponseEntity<Object> executeRequest(final String datastoreName, + final String cmHandleId, final String resourceIdentifier, final String optionsParamInQuery, final String topicParamInQuery, @@ -67,15 +66,15 @@ public class NcmpDatastoreRequestHandler implements TaskManagementDefaultHandler final boolean asyncResponseRequested = topicParamInQuery != null; if (asyncResponseRequested && notificationFeatureEnabled) { - return executeAsyncTaskAndGetResponseEntity(cmHandleId, resourceIdentifier, optionsParamInQuery, - topicParamInQuery, includeDescendants, false); + return executeAsyncTaskAndGetResponseEntity(datastoreName, cmHandleId, resourceIdentifier, + optionsParamInQuery, topicParamInQuery, includeDescendants, false); } if (asyncResponseRequested) { log.warn("Asynchronous request is unavailable as notification feature is currently disabled, " + "will use synchronous operation."); } - final Supplier<Object> taskSupplier = getTaskSupplierForGetRequest(cmHandleId, + final Supplier<Object> taskSupplier = getTaskSupplierForGetRequest(datastoreName, cmHandleId, resourceIdentifier, optionsParamInQuery, NO_TOPIC, NO_REQUEST_ID, includeDescendants); return executeTaskSync(taskSupplier); } @@ -101,20 +100,22 @@ public class NcmpDatastoreRequestHandler implements TaskManagementDefaultHandler /** * Executes synchronous/asynchronous request for batch of cm handles. * + * @param datastoreName the name of the datastore * @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 + * @param includeDescendants whether to include descendants or not * @return the response entity */ - public ResponseEntity<Object> executeRequest(final List<String> cmHandleIds, + public ResponseEntity<Object> executeRequest(final String datastoreName, + final List<String> cmHandleIds, final String resourceIdentifier, final String optionsParamInQuery, final String topicParamInQuery, final boolean includeDescendants) { - return executeAsyncTaskAndGetResponseEntity(cmHandleIds, resourceIdentifier, optionsParamInQuery, + return executeAsyncTaskAndGetResponseEntity(datastoreName, cmHandleIds, resourceIdentifier, optionsParamInQuery, topicParamInQuery, includeDescendants, true); } @@ -134,7 +135,8 @@ public class NcmpDatastoreRequestHandler implements TaskManagementDefaultHandler return ResponseEntity.ok(taskSupplier.get()); } - private ResponseEntity<Object> executeAsyncTaskAndGetResponseEntity(final Object targetObject, + private ResponseEntity<Object> executeAsyncTaskAndGetResponseEntity(final String datastoreName, + final Object targetObject, final String resourceIdentifier, final String optionsParamInQuery, final String topicParamInQuery, @@ -143,10 +145,10 @@ public class NcmpDatastoreRequestHandler implements TaskManagementDefaultHandler final String requestId = UUID.randomUUID().toString(); final Supplier<Object> taskSupplier; if (isBulkRequest) { - taskSupplier = getTaskSupplierForBulkRequest((List<String>) targetObject, + taskSupplier = getTaskSupplierForBulkRequest(datastoreName, (List<String>) targetObject, resourceIdentifier, optionsParamInQuery, topicParamInQuery, requestId, includeDescendants); } else { - taskSupplier = getTaskSupplierForGetRequest(targetObject.toString(), resourceIdentifier, + taskSupplier = getTaskSupplierForGetRequest(datastoreName, targetObject.toString(), resourceIdentifier, optionsParamInQuery, topicParamInQuery, requestId, includeDescendants); } if (taskSupplier == NO_OBJECT_SUPPLIER) { 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 deleted file mode 100644 index 9a71798fa1..0000000000 --- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreResourceRequestHandlerFactory.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * ============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 lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Component; - -@Component -@RequiredArgsConstructor -public class NcmpDatastoreResourceRequestHandlerFactory { - private final NcmpCachedResourceRequestHandler ncmpCachedResourceRequestHandler; - private final NcmpPassthroughResourceRequestHandler ncmpPassthroughResourceRequestHandler; - - /** - * Gets ncmp datastore handler. - * - * @param datastoreType the datastore type - * @return the ncmp datastore handler - */ - public NcmpDatastoreRequestHandler getNcmpResourceRequestHandler(final DatastoreType datastoreType) { - - switch (datastoreType) { - case OPERATIONAL: - ncmpCachedResourceRequestHandler.setDataStoreName(datastoreType.getDatastoreName()); - return ncmpCachedResourceRequestHandler; - case PASSTHROUGH_RUNNING: - case PASSTHROUGH_OPERATIONAL: - default: - ncmpPassthroughResourceRequestHandler.setDataStoreName(datastoreType.getDatastoreName()); - return ncmpPassthroughResourceRequestHandler; - } - } -} 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 index ab5d587e93..18e5a9f5ac 100644 --- 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 @@ -22,17 +22,30 @@ package org.onap.cps.ncmp.rest.controller.handlers; import java.util.List; import java.util.function.Supplier; -import lombok.Setter; +import org.onap.cps.ncmp.api.NetworkCmProxyDataService; +import org.onap.cps.ncmp.rest.executor.CpsNcmpTaskExecutor; import org.springframework.stereotype.Component; @Component public class NcmpPassthroughResourceRequestHandler extends NcmpDatastoreRequestHandler { - @Setter - private String dataStoreName; + private final NetworkCmProxyDataService networkCmProxyDataService; + + /** + * Constructor. + * + * @param cpsNcmpTaskExecutor @see org.onap.cps.ncmp.rest.executor.CpsNcmpTaskExecutor + * @param networkCmProxyDataService @see org.onap.cps.ncmp.api.NetworkCmProxyDataService + */ + public NcmpPassthroughResourceRequestHandler(final CpsNcmpTaskExecutor cpsNcmpTaskExecutor, + final NetworkCmProxyDataService networkCmProxyDataService) { + super(cpsNcmpTaskExecutor); + this.networkCmProxyDataService = networkCmProxyDataService; + } @Override - public Supplier<Object> getTaskSupplierForGetRequest(final String cmHandleId, + public Supplier<Object> getTaskSupplierForGetRequest(final String datastoreName, + final String cmHandleId, final String resourceIdentifier, final String optionsParamInQuery, final String topicParamInQuery, @@ -40,19 +53,20 @@ public class NcmpPassthroughResourceRequestHandler extends NcmpDatastoreRequestH final boolean includeDescendants) { return () -> networkCmProxyDataService.getResourceDataForCmHandle( - dataStoreName, cmHandleId, resourceIdentifier, optionsParamInQuery, topicParamInQuery, requestId); + 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) { + public Supplier<Object> getTaskSupplierForBulkRequest(final String datastoreName, + 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); + 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 index 08e8407c63..6d68f76802 100644 --- 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 @@ -30,24 +30,24 @@ public interface TaskManagementDefaultHandler { String NO_TOPIC = null; Supplier<Object> NO_OBJECT_SUPPLIER = null; - default Supplier<Object> getTaskSupplierForGetRequest(final String cmHandleId, + default Supplier<Object> getTaskSupplierForGetRequest(final String datastoreName, + 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, + default Supplier<Object> getTaskSupplierForBulkRequest(final String datastoreName, + final List<String> cmHandleIds, final String resourceIdentifier, final String optionsParamInQuery, final String topicParamInQuery, diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/executor/CpsNcmpTaskExecutor.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/executor/CpsNcmpTaskExecutor.java index 5adbb252a0..0543c4fba3 100644 --- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/executor/CpsNcmpTaskExecutor.java +++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/executor/CpsNcmpTaskExecutor.java @@ -32,7 +32,7 @@ import org.springframework.stereotype.Service; public class CpsNcmpTaskExecutor { /** - * Execute task asynchronously and publish response to supplied topic. + * Execute a task asynchronously. * * @param taskSupplier functional method is get() task need to executed asynchronously * @param timeOutInMillis the time out value in milliseconds |