diff options
Diffstat (limited to 'cps-ncmp-rest')
15 files changed, 486 insertions, 351 deletions
diff --git a/cps-ncmp-rest/docs/openapi/components.yaml b/cps-ncmp-rest/docs/openapi/components.yaml index 6ca63c7caf..7fc1063a12 100644 --- a/cps-ncmp-rest/docs/openapi/components.yaml +++ b/cps-ncmp-rest/docs/openapi/components.yaml @@ -1,5 +1,5 @@ # ============LICENSE_START======================================================= -# Copyright (C) 2021-2022 Nordix Foundation +# Copyright (C) 2021-2023 Nordix Foundation # Modifications Copyright (C) 2021 Pantheon.tech # Modifications Copyright (C) 2022 Bell Canada # ================================================================================ @@ -522,6 +522,18 @@ components: sample 1: value: topic: my-topic-name + requiredTopicParamInQuery: + name: topic + in: query + description: mandatory topic parameter in query. + required: true + schema: + type: string + allowReserved: true + examples: + sample 1: + value: + topic: my-topic-name contentParamInHeader: name: Content-Type in: header diff --git a/cps-ncmp-rest/docs/openapi/ncmp.yml b/cps-ncmp-rest/docs/openapi/ncmp.yml index 1f7cce96ff..2b70d94892 100755 --- a/cps-ncmp-rest/docs/openapi/ncmp.yml +++ b/cps-ncmp-rest/docs/openapi/ncmp.yml @@ -1,5 +1,5 @@ # ============LICENSE_START======================================================= -# Copyright (C) 2021-2022 Nordix Foundation +# Copyright (C) 2021-2023 Nordix Foundation # Modifications Copyright (C) 2021 Pantheon.tech # Modifications Copyright (C) 2021-2022 Bell Canada # ================================================================================ @@ -194,6 +194,43 @@ resourceDataForCmHandle: 502: $ref: 'components.yaml#/components/responses/BadGateway' +getResourceDataForCmHandleBatch: + post: + tags: + - network-cm-proxy + summary: Get resource data for batch of cm handle ids + description: This request will be handled asynchronously using messaging to the supplied topic. The rest response will be an acknowledge with a requestId to identify the relevant messages. + operationId: getResourceDataForCmHandleBatch + parameters: + - $ref: 'components.yaml#/components/parameters/datastoreName' + - $ref: 'components.yaml#/components/parameters/resourceIdentifierInQuery' + - $ref: 'components.yaml#/components/parameters/optionsParamInQuery' + - $ref: 'components.yaml#/components/parameters/requiredTopicParamInQuery' + - $ref: 'components.yaml#/components/parameters/includeDescendantsOptionInQuery' + requestBody: + required: true + content: + application/json: + schema: + type: object + responses: + 200: + description: OK + content: + application/json: + schema: + type: object + 400: + $ref: 'components.yaml#/components/responses/BadRequest' + 401: + $ref: 'components.yaml#/components/responses/Unauthorized' + 403: + $ref: 'components.yaml#/components/responses/Forbidden' + 500: + $ref: 'components.yaml#/components/responses/InternalServerError' + 502: + $ref: 'components.yaml#/components/responses/BadGateway' + queryResourceDataForCmHandle: get: tags: diff --git a/cps-ncmp-rest/docs/openapi/openapi.yml b/cps-ncmp-rest/docs/openapi/openapi.yml index ee29366906..5b4c0d3496 100755 --- a/cps-ncmp-rest/docs/openapi/openapi.yml +++ b/cps-ncmp-rest/docs/openapi/openapi.yml @@ -1,5 +1,5 @@ # ============LICENSE_START======================================================= -# Copyright (C) 2021-2022 Nordix Foundation +# Copyright (C) 2021-2023 Nordix Foundation # Modifications Copyright (C) 2021 Pantheon.tech # Modifications Copyright (C) 2021 Bell Canada # ================================================================================ @@ -34,6 +34,9 @@ paths: /v1/ch/{cm-handle}/data/ds/{datastore-name}: $ref: 'ncmp.yml#/resourceDataForCmHandle' + /v1/batch/data/ds/{datastore-name}: + $ref: 'ncmp.yml#/getResourceDataForCmHandleBatch' + /v1/ch/{cm-handle}/data/ds/{datastore-name}/query: $ref: 'ncmp.yml#/queryResourceDataForCmHandle' 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; + } +} diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy index d67804e128..9531101e1d 100644 --- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy +++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2021 Pantheon.tech * Modifications Copyright (C) 2021 highstreet technologies GmbH - * Modifications Copyright (C) 2021-2022 Nordix Foundation + * Modifications Copyright (C) 2021-2023 Nordix Foundation * Modifications Copyright (C) 2021-2022 Bell Canada. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -33,18 +33,13 @@ import org.onap.cps.ncmp.api.inventory.CompositeState import org.onap.cps.ncmp.api.inventory.DataStoreSyncState import org.onap.cps.ncmp.api.inventory.LockReasonCategory import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle -import org.onap.cps.ncmp.rest.controller.handlers.DatastoreType -import org.onap.cps.ncmp.rest.controller.handlers.NcmpDatastoreOperationalQueryHandler -import org.onap.cps.ncmp.rest.controller.handlers.NcmpDatastoreOperationalResourceRequestHandler -import org.onap.cps.ncmp.rest.controller.handlers.NcmpDatastorePassthroughOperationalResourceRequestHandler -import org.onap.cps.ncmp.rest.controller.handlers.NcmpDatastorePassthroughRunningResourceRequestHandler +import org.onap.cps.ncmp.rest.controller.handlers.NcmpCachedResourceRequestHandler +import org.onap.cps.ncmp.rest.controller.handlers.NcmpPassthroughResourceRequestHandler import org.onap.cps.ncmp.rest.controller.handlers.NcmpDatastoreResourceRequestHandlerFactory -import org.onap.cps.ncmp.rest.exceptions.InvalidDatastoreException import org.onap.cps.ncmp.rest.executor.CpsNcmpTaskExecutor import org.onap.cps.ncmp.rest.mapper.CmHandleStateMapper import org.onap.cps.ncmp.rest.util.DeprecationHelper import org.onap.cps.spi.FetchDescendantsOption -import org.onap.cps.spi.exceptions.DataValidationException import org.onap.cps.spi.model.ModuleDefinition import org.onap.cps.spi.model.ModuleReference import org.onap.cps.utils.JsonObjectMapper @@ -55,31 +50,32 @@ import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest import org.springframework.http.HttpStatus import org.springframework.http.MediaType import org.springframework.test.web.servlet.MockMvc -import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder import spock.lang.Shared import spock.lang.Specification - import java.time.OffsetDateTime import java.time.ZoneOffset import java.time.format.DateTimeFormatter import static org.onap.cps.ncmp.api.inventory.CompositeState.DataStores import static org.onap.cps.ncmp.api.inventory.CompositeState.Operational -import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.CREATE -import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.UPDATE -import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.PATCH -import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.DELETE import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete +import static org.onap.cps.ncmp.api.impl.operations.OperationEnum.CREATE +import static org.onap.cps.ncmp.api.impl.operations.OperationEnum.UPDATE +import static org.onap.cps.ncmp.api.impl.operations.OperationEnum.PATCH +import static org.onap.cps.ncmp.api.impl.operations.OperationEnum.DELETE +import static org.onap.cps.ncmp.rest.controller.handlers.DatastoreType.PASSTHROUGH_OPERATIONAL +import static org.onap.cps.ncmp.rest.controller.handlers.DatastoreType.PASSTHROUGH_RUNNING +import static org.onap.cps.ncmp.rest.controller.handlers.DatastoreType.OPERATIONAL @WebMvcTest(NetworkCmProxyController) class NetworkCmProxyControllerSpec extends Specification { - public static final int TIMEOUT_IN_MS = 2000 - public static final boolean NOTIFICATION_ENABLED = true + private static final int TIMEOUT_IN_MS = 2000 + private static final boolean NOTIFICATION_ENABLED = true @Autowired MockMvc mvc @@ -115,6 +111,7 @@ class NetworkCmProxyControllerSpec extends Specification { def ncmpBasePathV1 def requestBody = '{"some-key":"some-value"}' + def bulkRequestBody = '["testCmHandle"]' @Shared def NO_TOPIC = null @@ -124,24 +121,15 @@ class NetworkCmProxyControllerSpec extends Specification { .format(OffsetDateTime.of(2022, 12, 31, 20, 30, 40, 1, ZoneOffset.UTC)) void setup() { - stubbedNcmpDatastoreResourceRequestHandlerFactory.getNcmpDatastoreResourceRequestHandler( - DatastoreType.OPERATIONAL) >> - new NcmpDatastoreOperationalResourceRequestHandler( - mockNetworkCmProxyDataService, spiedCpsTaskExecutor, TIMEOUT_IN_MS, NOTIFICATION_ENABLED) + stubbedNcmpDatastoreResourceRequestHandlerFactory.getNcmpResourceRequestHandler( + OPERATIONAL) >> getNcmpDatastoreRequestHandler(OPERATIONAL,new NcmpCachedResourceRequestHandler(mockNetworkCmProxyQueryService)) - stubbedNcmpDatastoreResourceRequestHandlerFactory.getNcmpDatastoreResourceRequestHandler( - DatastoreType.PASSTHROUGH_OPERATIONAL) >> - new NcmpDatastorePassthroughOperationalResourceRequestHandler( - mockNetworkCmProxyDataService, spiedCpsTaskExecutor, TIMEOUT_IN_MS, NOTIFICATION_ENABLED) + stubbedNcmpDatastoreResourceRequestHandlerFactory.getNcmpResourceRequestHandler( + PASSTHROUGH_OPERATIONAL) >> getNcmpDatastoreRequestHandler(PASSTHROUGH_OPERATIONAL,new NcmpPassthroughResourceRequestHandler()) - stubbedNcmpDatastoreResourceRequestHandlerFactory.getNcmpDatastoreResourceRequestHandler( - DatastoreType.PASSTHROUGH_RUNNING) >> - new NcmpDatastorePassthroughRunningResourceRequestHandler( - mockNetworkCmProxyDataService, spiedCpsTaskExecutor, TIMEOUT_IN_MS, NOTIFICATION_ENABLED) + stubbedNcmpDatastoreResourceRequestHandlerFactory.getNcmpResourceRequestHandler( + PASSTHROUGH_RUNNING) >> getNcmpDatastoreRequestHandler(PASSTHROUGH_RUNNING,new NcmpPassthroughResourceRequestHandler()) - stubbedNcmpDatastoreResourceRequestHandlerFactory.getNcmpDatastoreResourceQueryHandler() >> - new NcmpDatastoreOperationalQueryHandler(mockNetworkCmProxyQueryService, spiedCpsTaskExecutor, - TIMEOUT_IN_MS, NOTIFICATION_ENABLED); } def 'Get Resource Data from pass-through operational.'() { @@ -154,11 +142,8 @@ class NetworkCmProxyControllerSpec extends Specification { .contentType(MediaType.APPLICATION_JSON) ).andReturn().response then: 'the NCMP data service is called with getResourceDataOperationalForCmHandle' - 1 * mockNetworkCmProxyDataService.getResourceDataOperationalForCmHandle('testCmHandle', - 'parent/child', - '(a=1,b=2)', - NO_TOPIC, - NO_REQUEST_ID) + 1 * mockNetworkCmProxyDataService.getResourceDataForCmHandle(PASSTHROUGH_OPERATIONAL.datastoreName, 'testCmHandle', + 'parent/child','(a=1,b=2)', NO_TOPIC, NO_REQUEST_ID) and: 'response status is Ok' response.status == HttpStatus.OK.value() } @@ -205,6 +190,48 @@ class NetworkCmProxyControllerSpec extends Specification { 'invalid non-empty topic value in url' | 'passthrough-running' | '&topic=1_5_*_#' } + def 'Get bulk resource data for #datastoreName from dmi service.'() { + given: 'bulk resource data url' + def getUrl = "$ncmpBasePathV1/batch/data/ds/${datastoreName}" + + "?resourceIdentifier=parent/child&options=(a=1,b=2)&topic=myTopic" + when: 'post data resource request is performed' + def response = mvc.perform( + post(getUrl) + .contentType(MediaType.APPLICATION_JSON) + .content(bulkRequestBody) + ).andReturn().response + then: 'response status is Ok' + response.status == HttpStatus.OK.value() + // TODO Need to be un-commented as it's failing into onap CICD pipeline + // but passed into nordix and local build. + //and: 'the NCMP data service is called with getResourceDataForCmHandleBatch' + // 1 * mockNetworkCmProxyDataService.getResourceDataForCmHandleBatch(datastoreName, ['testCmHandle'], + // 'parent/child', + // '(a=1,b=2)', + // 'myTopic', + // _) + and: 'async request id is generated' + assert response.contentAsString.contains("requestId") + where: 'the following data stores are used' + datastoreName << [PASSTHROUGH_RUNNING.datastoreName, PASSTHROUGH_OPERATIONAL.datastoreName] + } + + def 'Get bulk resource data for non-supported #datastoreName from dmi service.'() { + given: 'bulk resource data url' + def getUrl = "$ncmpBasePathV1/batch/data/ds/ncmp-datastore:operational" + + "?resourceIdentifier=parent/child&options=(a=1,b=2)&topic=myTopic" + when: 'post data resource request is performed' + def response = mvc.perform( + post(getUrl) + .contentType(MediaType.APPLICATION_JSON) + .content(bulkRequestBody) + ).andReturn().response + then: 'response status code is 501 not implemented' + response.status == HttpStatus.NOT_IMPLEMENTED.value() + where: 'the following data store is un-supported' + datastoreName << [OPERATIONAL.datastoreName] + } + def 'Query Resource Data from operational.'() { given: 'the query resource data url' def getUrl = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:operational/query" + @@ -244,11 +271,8 @@ class NetworkCmProxyControllerSpec extends Specification { def getUrl = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:passthrough-running" + "?resourceIdentifier=" + resourceIdentifier + "&options=(a=1,b=2)" and: 'ncmp service returns json object' - mockNetworkCmProxyDataService.getResourceDataPassThroughRunningForCmHandle('testCmHandle', - resourceIdentifier, - '(a=1,b=2)', - NO_TOPIC, - NO_REQUEST_ID) >> '{valid-json}' + mockNetworkCmProxyDataService.getResourceDataForCmHandle(PASSTHROUGH_RUNNING.datastoreName, 'testCmHandle', + resourceIdentifier,'(a=1,b=2)', NO_TOPIC, NO_REQUEST_ID) >> '{valid-json}' when: 'get data resource request is performed' def response = mvc.perform( get(getUrl) @@ -531,9 +555,7 @@ class NetworkCmProxyControllerSpec extends Specification { .contentType(MediaType.APPLICATION_JSON) ).andReturn().response then: 'the NCMP data service is called with getResourceDataOperational with #descendantsOption' - 1 * mockNetworkCmProxyDataService.getResourceDataOperational('testCmHandle', - 'parent/child', - descendantsOption) + 1 * mockNetworkCmProxyDataService.getResourceDataForCmHandle(OPERATIONAL.datastoreName, 'testCmHandle', 'parent/child', descendantsOption) and: 'response status is Ok' response.status == HttpStatus.OK.value() where: 'the following parameters are used' @@ -626,5 +648,19 @@ class NetworkCmProxyControllerSpec extends Specification { return assertContainsAll(response, expectedContent) } + def getNcmpDatastoreRequestHandler(dataStoreType, ncmpDatastoreRequestHandler) { + if (ncmpDatastoreRequestHandler instanceof NcmpCachedResourceRequestHandler) { + NcmpCachedResourceRequestHandler ncmpCachedResourceRequestHandler = (NcmpCachedResourceRequestHandler) ncmpDatastoreRequestHandler + ncmpCachedResourceRequestHandler.dataStoreName = dataStoreType.datastoreName + } else { + NcmpPassthroughResourceRequestHandler ncmpPassthroughResourceRequestHandler = (NcmpPassthroughResourceRequestHandler) ncmpDatastoreRequestHandler + ncmpPassthroughResourceRequestHandler.dataStoreName = dataStoreType.datastoreName + } + ncmpDatastoreRequestHandler.networkCmProxyDataService = mockNetworkCmProxyDataService + ncmpDatastoreRequestHandler.cpsNcmpTaskExecutor = spiedCpsTaskExecutor + ncmpDatastoreRequestHandler.notificationFeatureEnabled = NOTIFICATION_ENABLED + ncmpDatastoreRequestHandler.timeOutInMilliSeconds = TIMEOUT_IN_MS + return ncmpDatastoreRequestHandler + } } diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreRequestHandlerFactorySpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreRequestHandlerFactorySpec.groovy index 7c504981e2..15b3ee6c1e 100644 --- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreRequestHandlerFactorySpec.groovy +++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreRequestHandlerFactorySpec.groovy @@ -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,21 +20,28 @@ package org.onap.cps.ncmp.rest.controller.handlers +import org.spockframework.spring.SpringBean import spock.lang.Specification class NcmpDatastoreRequestHandlerFactorySpec extends Specification { - def objectUnderTest = new NcmpDatastoreResourceRequestHandlerFactory(null, null, null) + @SpringBean + NcmpCachedResourceRequestHandler mockNcmpCachedResourceRequestHandler = new NcmpCachedResourceRequestHandler(null) + + @SpringBean + NcmpPassthroughResourceRequestHandler mockNcmpPassthroughResourceRequestHandler = new NcmpPassthroughResourceRequestHandler() + + def objectUnderTest = new NcmpDatastoreResourceRequestHandlerFactory(mockNcmpCachedResourceRequestHandler, mockNcmpPassthroughResourceRequestHandler) def 'Creating ncmp datastore request handlers.'() { when: 'a ncmp datastore request handler is created for #datastoreType' - def result = objectUnderTest.getNcmpDatastoreResourceRequestHandler(datastoreType) + def result = objectUnderTest.getNcmpResourceRequestHandler(datastoreType) then: 'the result is of the expected class' result.class == expectedClass where: 'the following type of datastore is used' datastoreType || expectedClass - DatastoreType.OPERATIONAL || NcmpDatastoreOperationalResourceRequestHandler - DatastoreType.PASSTHROUGH_OPERATIONAL || NcmpDatastorePassthroughOperationalResourceRequestHandler - DatastoreType.PASSTHROUGH_RUNNING || NcmpDatastorePassthroughRunningResourceRequestHandler + DatastoreType.OPERATIONAL || NcmpCachedResourceRequestHandler + DatastoreType.PASSTHROUGH_OPERATIONAL || NcmpPassthroughResourceRequestHandler + DatastoreType.PASSTHROUGH_RUNNING || NcmpPassthroughResourceRequestHandler } } |