diff options
Diffstat (limited to 'cps-ncmp-rest')
28 files changed, 314 insertions, 1041 deletions
diff --git a/cps-ncmp-rest/docs/openapi/components.yaml b/cps-ncmp-rest/docs/openapi/components.yaml index a9311d0861..112dddf61c 100644 --- a/cps-ncmp-rest/docs/openapi/components.yaml +++ b/cps-ncmp-rest/docs/openapi/components.yaml @@ -505,6 +505,14 @@ components: schema: type: string example: my-cm-handle + cmHandleReferenceInPath: + name: cm-handle + in: path + description: The identifier (cmHandle or alternate) for a network function, network element, subnetwork or any other cm object by managed Network CM Proxy + required: true + schema: + type: string + example: my-cm-handle-reference moduleNameInQuery: name: module-name in: query diff --git a/cps-ncmp-rest/docs/openapi/ncmp.yml b/cps-ncmp-rest/docs/openapi/ncmp.yml index d0b1f35eaa..adb2419c8a 100755 --- a/cps-ncmp-rest/docs/openapi/ncmp.yml +++ b/cps-ncmp-rest/docs/openapi/ncmp.yml @@ -27,7 +27,7 @@ resourceDataForCmHandle: operationId: getResourceDataForCmHandle parameters: - $ref: 'components.yaml#/components/parameters/datastoreName' - - $ref: 'components.yaml#/components/parameters/cmHandleInPath' + - $ref: 'components.yaml#/components/parameters/cmHandleReferenceInPath' - $ref: 'components.yaml#/components/parameters/resourceIdentifierInQuery' - $ref: 'components.yaml#/components/parameters/optionsParamInQuery' - $ref: 'components.yaml#/components/parameters/topicParamInQuery' @@ -60,7 +60,7 @@ resourceDataForCmHandle: operationId: createResourceDataRunningForCmHandle parameters: - $ref: 'components.yaml#/components/parameters/datastoreName' - - $ref: 'components.yaml#/components/parameters/cmHandleInPath' + - $ref: 'components.yaml#/components/parameters/cmHandleReferenceInPath' - $ref: 'components.yaml#/components/parameters/resourceIdentifierInQuery' - $ref: 'components.yaml#/components/parameters/contentParamInHeader' - $ref: 'components.yaml#/components/parameters/authorizationParamInHeader' @@ -99,7 +99,7 @@ resourceDataForCmHandle: operationId: updateResourceDataRunningForCmHandle parameters: - $ref: 'components.yaml#/components/parameters/datastoreName' - - $ref: 'components.yaml#/components/parameters/cmHandleInPath' + - $ref: 'components.yaml#/components/parameters/cmHandleReferenceInPath' - $ref: 'components.yaml#/components/parameters/resourceIdentifierInQuery' - $ref: 'components.yaml#/components/parameters/contentParamInHeader' - $ref: 'components.yaml#/components/parameters/authorizationParamInHeader' @@ -138,7 +138,7 @@ resourceDataForCmHandle: operationId: patchResourceDataRunningForCmHandle parameters: - $ref: 'components.yaml#/components/parameters/datastoreName' - - $ref: 'components.yaml#/components/parameters/cmHandleInPath' + - $ref: 'components.yaml#/components/parameters/cmHandleReferenceInPath' - $ref: 'components.yaml#/components/parameters/resourceIdentifierInQuery' - $ref: 'components.yaml#/components/parameters/contentParamInHeader' - $ref: 'components.yaml#/components/parameters/authorizationParamInHeader' @@ -171,7 +171,7 @@ resourceDataForCmHandle: operationId: deleteResourceDataRunningForCmHandle parameters: - $ref: 'components.yaml#/components/parameters/datastoreName' - - $ref: 'components.yaml#/components/parameters/cmHandleInPath' + - $ref: 'components.yaml#/components/parameters/cmHandleReferenceInPath' - $ref: 'components.yaml#/components/parameters/resourceIdentifierInQuery' - $ref: 'components.yaml#/components/parameters/contentParamInHeader' - $ref: 'components.yaml#/components/parameters/authorizationParamInHeader' @@ -194,7 +194,7 @@ dataOperationForCmHandle: tags: - network-cm-proxy summary: Execute a data operation for group 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. A maximum of 50 cm handles per operation is supported. + 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. A maximum of 200 cm handles per operation is supported. operationId: executeDataOperationForCmHandles parameters: - $ref: 'components.yaml#/components/parameters/requiredTopicParamInQuery' @@ -264,7 +264,7 @@ fetchModuleReferencesByCmHandle: summary: Fetch all module references (name and revision) for a given cm handle operationId: getModuleReferencesByCmHandle parameters: - - $ref: 'components.yaml#/components/parameters/cmHandleInPath' + - $ref: 'components.yaml#/components/parameters/cmHandleReferenceInPath' responses: 200: description: OK @@ -289,7 +289,7 @@ getModuleDefinitions: description: Get module definitions (module name, revision, yang resource) with options to filter on module name and revision operationId: getModuleDefinitions parameters: - - $ref: 'components.yaml#/components/parameters/cmHandleInPath' + - $ref: 'components.yaml#/components/parameters/cmHandleReferenceInPath' - $ref: 'components.yaml#/components/parameters/moduleNameInQuery' - $ref: 'components.yaml#/components/parameters/revisionInQuery' responses: @@ -354,7 +354,7 @@ retrieveCmHandleDetailsById: summary: Retrieve CM handle details operationId: retrieveCmHandleDetailsById parameters: - - $ref: 'components.yaml#/components/parameters/cmHandleInPath' + - $ref: 'components.yaml#/components/parameters/cmHandleReferenceInPath' responses: 200: description: OK @@ -377,7 +377,7 @@ getCmHandlePropertiesById: summary: Get CM handle properties operationId: getCmHandlePublicPropertiesByCmHandleId parameters: - - $ref: 'components.yaml#/components/parameters/cmHandleInPath' + - $ref: 'components.yaml#/components/parameters/cmHandleReferenceInPath' responses: 200: description: OK @@ -400,7 +400,7 @@ getCmHandleStateById: summary: Get CM handle state operationId: getCmHandleStateByCmHandleId parameters: - - $ref: 'components.yaml#/components/parameters/cmHandleInPath' + - $ref: 'components.yaml#/components/parameters/cmHandleReferenceInPath' responses: 200: description: OK diff --git a/cps-ncmp-rest/docs/openapi/openapi-inventory.yml b/cps-ncmp-rest/docs/openapi/openapi-inventory.yml index b794082875..8c0ad41705 100755 --- a/cps-ncmp-rest/docs/openapi/openapi-inventory.yml +++ b/cps-ncmp-rest/docs/openapi/openapi-inventory.yml @@ -21,7 +21,7 @@ openapi: 3.0.3 info: title: NCMP Inventory API description: NCMP Inventory API - version: "1.0" + version: "3.5.2" servers: - url: /ncmpInventory components: @@ -40,4 +40,4 @@ paths: $ref: 'ncmp-inventory.yml#/searchCmHandleIds' security: - - basicAuth: []
\ No newline at end of file + - basicAuth: [] diff --git a/cps-ncmp-rest/docs/openapi/openapi.yml b/cps-ncmp-rest/docs/openapi/openapi.yml index dd6d7c8baa..78fb141820 100755 --- a/cps-ncmp-rest/docs/openapi/openapi.yml +++ b/cps-ncmp-rest/docs/openapi/openapi.yml @@ -22,7 +22,7 @@ openapi: 3.0.3 info: title: NCMP to CPS Proxy API description: NCMP to CPS Proxy API - version: "1.0" + version: "3.5.2" servers: - url: /ncmp components: @@ -64,4 +64,4 @@ paths: /v1/ch/{cm-handle}/data-sync: $ref: 'ncmp.yml#/setDataSyncEnabledFlag' security: - - basicAuth: []
\ No newline at end of file + - basicAuth: [] diff --git a/cps-ncmp-rest/pom.xml b/cps-ncmp-rest/pom.xml index e333344798..adac504eae 100644 --- a/cps-ncmp-rest/pom.xml +++ b/cps-ncmp-rest/pom.xml @@ -27,7 +27,7 @@ <parent> <groupId>org.onap.cps</groupId> <artifactId>cps-parent</artifactId> - <version>3.5.0-SNAPSHOT</version> + <version>3.5.3-SNAPSHOT</version> <relativePath>../cps-parent/pom.xml</relativePath> </parent> 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 5b54ac243e..42f709dcf5 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,36 +23,29 @@ package org.onap.cps.ncmp.rest.controller; -import static org.onap.cps.ncmp.api.impl.operations.DatastoreType.OPERATIONAL; -import static org.onap.cps.ncmp.api.impl.operations.DatastoreType.PASSTHROUGH_RUNNING; -import static org.onap.cps.ncmp.api.impl.operations.OperationType.CREATE; -import static org.onap.cps.ncmp.api.impl.operations.OperationType.DELETE; -import static org.onap.cps.ncmp.api.impl.operations.OperationType.PATCH; -import static org.onap.cps.ncmp.api.impl.operations.OperationType.UPDATE; +import static org.onap.cps.ncmp.api.data.models.DatastoreType.OPERATIONAL; +import static org.onap.cps.ncmp.api.data.models.DatastoreType.PASSTHROUGH_RUNNING; +import static org.onap.cps.ncmp.api.data.models.OperationType.CREATE; +import static org.onap.cps.ncmp.api.data.models.OperationType.DELETE; +import static org.onap.cps.ncmp.api.data.models.OperationType.PATCH; +import static org.onap.cps.ncmp.api.data.models.OperationType.UPDATE; import io.micrometer.core.annotation.Timed; import java.util.ArrayList; import java.util.Collection; import java.util.List; -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.config.embeddedcache.TrustLevelCacheConfig; -import org.onap.cps.ncmp.api.impl.exception.InvalidDatastoreException; -import org.onap.cps.ncmp.api.impl.inventory.CompositeState; -import org.onap.cps.ncmp.api.impl.operations.DatastoreType; -import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevel; -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.api.data.exceptions.InvalidDatastoreException; +import org.onap.cps.ncmp.api.data.models.CmResourceAddress; +import org.onap.cps.ncmp.api.data.models.DatastoreType; +import org.onap.cps.ncmp.api.inventory.NetworkCmProxyInventoryFacade; +import org.onap.cps.ncmp.api.inventory.models.CmHandleQueryApiParameters; +import org.onap.cps.ncmp.api.inventory.models.CompositeState; +import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle; +import org.onap.cps.ncmp.impl.data.NetworkCmProxyFacade; 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; import org.onap.cps.ncmp.rest.model.CmHandleQueryParameters; import org.onap.cps.ncmp.rest.model.DataOperationRequest; @@ -61,10 +54,13 @@ import org.onap.cps.ncmp.rest.model.RestModuleReference; 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.CmHandleStateMapper; +import org.onap.cps.ncmp.rest.util.DataOperationRequestMapper; import org.onap.cps.ncmp.rest.util.DeprecationHelper; +import org.onap.cps.ncmp.rest.util.NcmpRestInputMapper; +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; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.util.StringUtils; @@ -78,22 +74,19 @@ 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; /** * Get resource data from datastore. * * @param datastoreName name of the datastore - * @param cmHandle cm handle identifier + * @param cmHandleReference cm handle or alternate id identifier * @param resourceIdentifier resource identifier * @param optionsParamInQuery options query parameter * @param topicParamInQuery topic query parameter @@ -104,36 +97,38 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { @Override @Timed(value = "cps.ncmp.controller.get", description = "Time taken to get resource data from datastore") public ResponseEntity<Object> getResourceDataForCmHandle(final String datastoreName, - final String cmHandle, + final String cmHandleReference, final String resourceIdentifier, final String optionsParamInQuery, 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 CmResourceAddress cmResourceAddress = new CmResourceAddress(datastoreName, cmHandleReference, + resourceIdentifier); + 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); } /** * Query resource data from datastore. * - * @param datastoreName name of the datastore + * @param datastoreName name of the datastore (currently only supports "ncmp-datastore:operational") * @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 + * @return {@code ResponseEntity} response. Body contains a collection of DataNodes */ @Override @@ -144,14 +139,16 @@ 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); } /** - * Patch resource data from passthrough-running. + * Patch resource data. * - * @param datastoreName name of the datastore - * @param cmHandle cm handle identifier + * @param datastoreName name of the datastore (currently only supports "ncmp-datastore:passthrough-running") + * @param cmHandleReference cm handle or alternate identifier * @param resourceIdentifier resource identifier * @param requestBody the request body * @param contentType content type of body @@ -161,7 +158,7 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { @Override public ResponseEntity<Object> patchResourceDataRunningForCmHandle(final String datastoreName, - final String cmHandle, + final String cmHandleReference, final String resourceIdentifier, final Object requestBody, final String contentType, @@ -169,18 +166,18 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { validateDataStore(PASSTHROUGH_RUNNING, datastoreName); - final Object responseObject = networkCmProxyDataService + final Object responseObject = networkCmProxyFacade .writeResourceDataPassThroughRunningForCmHandle( - cmHandle, resourceIdentifier, PATCH, + cmHandleReference, resourceIdentifier, PATCH, jsonObjectMapper.asJsonString(requestBody), contentType, authorization); return ResponseEntity.ok(responseObject); } /** - * Create resource data in datastore pass-through running for given cm-handle. + * Create resource data for given cm-handle. * - * @param datastoreName name of the datastore - * @param cmHandle cm handle identifier + * @param datastoreName name of the datastore (currently only supports "ncmp-datastore:passthrough-running") + * @param cmHandleReference cm handle or alternate identifier * @param resourceIdentifier resource identifier * @param requestBody the request body * @param contentType content type of body @@ -189,23 +186,23 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { */ @Override public ResponseEntity<Void> createResourceDataRunningForCmHandle(final String datastoreName, - final String cmHandle, + final String cmHandleReference, final String resourceIdentifier, final Object requestBody, final String contentType, final String authorization) { validateDataStore(PASSTHROUGH_RUNNING, datastoreName); - networkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle(cmHandle, + networkCmProxyFacade.writeResourceDataPassThroughRunningForCmHandle(cmHandleReference, resourceIdentifier, CREATE, jsonObjectMapper.asJsonString(requestBody), contentType, authorization); return new ResponseEntity<>(HttpStatus.CREATED); } /** - * Update resource data in datastore pass-through running for given cm-handle. + * Update resource data for given cm-handle. * - * @param datastoreName name of the datastore - * @param cmHandle cm handle identifier + * @param datastoreName name of the datastore (currently only supports "ncmp-datastore:passthrough-running") + * @param cmHandleReference cm handle or alternate identifier * @param resourceIdentifier resource identifier * @param requestBody the request body * @param contentType content type of the body @@ -215,23 +212,23 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { @Override public ResponseEntity<Object> updateResourceDataRunningForCmHandle(final String datastoreName, - final String cmHandle, + final String cmHandleReference, final String resourceIdentifier, final Object requestBody, final String contentType, final String authorization) { validateDataStore(PASSTHROUGH_RUNNING, datastoreName); - networkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle(cmHandle, + networkCmProxyFacade.writeResourceDataPassThroughRunningForCmHandle(cmHandleReference, resourceIdentifier, UPDATE, jsonObjectMapper.asJsonString(requestBody), contentType, authorization); return new ResponseEntity<>(HttpStatus.OK); } /** - * Delete resource data in datastore pass-through running for a given cm-handle. + * Delete resource data for a given cm-handle. * - * @param datastoreName name of the datastore - * @param cmHandle cm handle identifier + * @param datastoreName name of the datastore (currently only supports "ncmp-datastore:passthrough-running") + * @param cmHandleReference cm handle or alternate identifier * @param resourceIdentifier resource identifier * @param contentType content type of the body * @param authorization contents of Authorization header, or null if not present @@ -239,14 +236,14 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { */ @Override public ResponseEntity<Void> deleteResourceDataRunningForCmHandle(final String datastoreName, - final String cmHandle, + final String cmHandleReference, final String resourceIdentifier, final String contentType, final String authorization) { validateDataStore(PASSTHROUGH_RUNNING, datastoreName); - networkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle(cmHandle, + networkCmProxyFacade.writeResourceDataPassThroughRunningForCmHandle(cmHandleReference, resourceIdentifier, DELETE, NO_BODY, contentType, authorization); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } @@ -263,11 +260,11 @@ 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 = + final List<RestOutputCmHandle> restOutputCmHandles = cmHandles.stream().map(this::toRestOutputCmHandle).collect(Collectors.toList()); - return ResponseEntity.ok(outputCmHandles); + return ResponseEntity.ok(restOutputCmHandles); } /** @@ -282,34 +279,35 @@ 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)); } /** * Search for Cm Handle and Properties by Name. * - * @param cmHandleId cm-handle identifier + * @param cmHandleReference cm-handle or alternate identifier * @return cm handle and its properties */ @Override - public ResponseEntity<RestOutputCmHandle> retrieveCmHandleDetailsById(final String cmHandleId) { - final NcmpServiceCmHandle ncmpServiceCmHandle = networkCmProxyDataService.getNcmpServiceCmHandle(cmHandleId); + public ResponseEntity<RestOutputCmHandle> retrieveCmHandleDetailsById(final String cmHandleReference) { + final NcmpServiceCmHandle ncmpServiceCmHandle + = networkCmProxyInventoryFacade.getNcmpServiceCmHandle(cmHandleReference); final RestOutputCmHandle restOutputCmHandle = toRestOutputCmHandle(ncmpServiceCmHandle); return ResponseEntity.ok(restOutputCmHandle); } /** - * Get Cm Handle Properties by Cm Handle Id. + * Get Cm Handle Properties by Cm Handle or alternate Identifier. * - * @param cmHandleId cm-handle identifier + * @param cmHandleReference cm-handle or alternate identifier * @return cm handle properties */ @Override public ResponseEntity<RestOutputCmHandlePublicProperties> getCmHandlePublicPropertiesByCmHandleId( - final String cmHandleId) { + final String cmHandleReference) { final CmHandlePublicProperties cmHandlePublicProperties = new CmHandlePublicProperties(); - cmHandlePublicProperties.add(networkCmProxyDataService.getCmHandlePublicProperties(cmHandleId)); + cmHandlePublicProperties.add(networkCmProxyInventoryFacade.getCmHandlePublicProperties(cmHandleReference)); final RestOutputCmHandlePublicProperties restOutputCmHandlePublicProperties = new RestOutputCmHandlePublicProperties(); restOutputCmHandlePublicProperties.setPublicCmHandleProperties(cmHandlePublicProperties); @@ -319,13 +317,13 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { /** * Get Cm Handle State by Cm Handle Id. * - * @param cmHandleId cm-handle identifier + * @param cmHandleReference cm-handle or alternate identifier * @return cm handle state */ @Override public ResponseEntity<RestOutputCmHandleCompositeState> getCmHandleStateByCmHandleId( - final String cmHandleId) { - final CompositeState cmHandleState = networkCmProxyDataService.getCmHandleCompositeState(cmHandleId); + final String cmHandleReference) { + final CompositeState cmHandleState = networkCmProxyInventoryFacade.getCmHandleCompositeState(cmHandleReference); final RestOutputCmHandleCompositeState restOutputCmHandleCompositeState = new RestOutputCmHandleCompositeState(); restOutputCmHandleCompositeState.setState( @@ -336,21 +334,23 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { /** * Return module definitions. * - * @param cmHandleId cm-handle identifier - * @param moduleName module name - * @param revision the revision of the module + * @param cmHandleReference cm handle or alternate id identifier + * @param moduleName module name + * @param revision the revision of the module * @return list of module definitions (module name, revision, yang resource content) */ @Override - public ResponseEntity<List<RestModuleDefinition>> getModuleDefinitions(final String cmHandleId, + public ResponseEntity<List<RestModuleDefinition>> getModuleDefinitions(final String cmHandleReference, final String moduleName, final String revision) { final Collection<ModuleDefinition> moduleDefinitions; if (StringUtils.hasText(moduleName)) { moduleDefinitions = - networkCmProxyDataService.getModuleDefinitionsByCmHandleAndModule(cmHandleId, moduleName, revision); + networkCmProxyInventoryFacade.getModuleDefinitionsByCmHandleAndModule(cmHandleReference, + moduleName, revision); } else { - moduleDefinitions = networkCmProxyDataService.getModuleDefinitionsByCmHandleId(cmHandleId); + moduleDefinitions = + networkCmProxyInventoryFacade.getModuleDefinitionsByCmHandleReference(cmHandleReference); if (StringUtils.hasText(revision)) { log.warn("Ignoring revision filter as no module name is provided"); } @@ -365,12 +365,12 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { /** * Return module references for a cm handle. * - * @param cmHandle the cm handle + * @param cmHandleReference cm handle or alternate id identifier * @return module references for cm handle. Namespace will be always blank because restConf does not include this. */ - public ResponseEntity<List<RestModuleReference>> getModuleReferencesByCmHandle(final String cmHandle) { + public ResponseEntity<List<RestModuleReference>> getModuleReferencesByCmHandle(final String cmHandleReference) { final List<RestModuleReference> restModuleReferences = - networkCmProxyDataService.getYangResourcesModuleReferences(cmHandle).stream() + networkCmProxyInventoryFacade.getYangResourcesModuleReferences(cmHandleReference).stream() .map(ncmpRestInputMapper::toRestModuleReference) .collect(Collectors.toList()); return new ResponseEntity<>(restModuleReferences, HttpStatus.OK); @@ -386,22 +386,20 @@ 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); } - private RestOutputCmHandle toRestOutputCmHandle(final NcmpServiceCmHandle ncmpServiceCmHandle) { final RestOutputCmHandle restOutputCmHandle = new RestOutputCmHandle(); final CmHandlePublicProperties cmHandlePublicProperties = new CmHandlePublicProperties(); - final TrustLevel cmHandleCurrentTrustLevel = trustLevelPerCmHandle.get(ncmpServiceCmHandle.getCmHandleId()); restOutputCmHandle.setCmHandle(ncmpServiceCmHandle.getCmHandleId()); cmHandlePublicProperties.add(ncmpServiceCmHandle.getPublicProperties()); restOutputCmHandle.setPublicCmHandleProperties(cmHandlePublicProperties); restOutputCmHandle.setState(cmHandleStateMapper.toCmHandleCompositeStateExternalLockReason( ncmpServiceCmHandle.getCompositeState())); - if (cmHandleCurrentTrustLevel != null) { - restOutputCmHandle.setTrustLevel(cmHandleCurrentTrustLevel.toString()); + if (ncmpServiceCmHandle.getCurrentTrustLevel() != null) { + restOutputCmHandle.setTrustLevel(ncmpServiceCmHandle.getCurrentTrustLevel().toString()); } restOutputCmHandle.setModuleSetTag(ncmpServiceCmHandle.getModuleSetTag()); restOutputCmHandle.setAlternateId(ncmpServiceCmHandle.getAlternateId()); @@ -417,11 +415,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 5467eeffca..8aa86ade36 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,16 +27,17 @@ 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.models.CmHandleQueryServiceParameters; -import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse; -import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse.Status; -import org.onap.cps.ncmp.api.models.DmiPluginRegistrationResponse; +import org.onap.cps.ncmp.api.inventory.NetworkCmProxyInventoryFacade; +import org.onap.cps.ncmp.api.inventory.models.CmHandleQueryServiceParameters; +import org.onap.cps.ncmp.api.inventory.models.CmHandleRegistrationResponse; +import org.onap.cps.ncmp.api.inventory.models.CmHandleRegistrationResponse.Status; +import org.onap.cps.ncmp.api.inventory.models.DmiPluginRegistrationResponse; import org.onap.cps.ncmp.rest.api.NetworkCmProxyInventoryApi; import org.onap.cps.ncmp.rest.model.CmHandleQueryParameters; import org.onap.cps.ncmp.rest.model.CmHandlerRegistrationErrorResponse; import org.onap.cps.ncmp.rest.model.DmiPluginRegistrationErrorResponse; import org.onap.cps.ncmp.rest.model.RestDmiPluginRegistration; +import org.onap.cps.ncmp.rest.util.NcmpRestInputMapper; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RequestMapping; @@ -47,7 +48,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 +56,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 +70,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 +85,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/exceptions/NetworkCmProxyRestExceptionHandler.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyRestExceptionHandler.java index 7263000896..6910003c54 100755..100644 --- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandler.java +++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyRestExceptionHandler.java @@ -18,19 +18,21 @@ * ============LICENSE_END========================================================= */ -package org.onap.cps.ncmp.rest.exceptions; +package org.onap.cps.ncmp.rest.controller; import lombok.AccessLevel; import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.onap.cps.ncmp.api.impl.exception.DmiClientRequestException; -import org.onap.cps.ncmp.api.impl.exception.DmiRequestException; -import org.onap.cps.ncmp.api.impl.exception.InvalidDatastoreException; -import org.onap.cps.ncmp.api.impl.exception.InvalidDmiResourceUrlException; -import org.onap.cps.ncmp.api.impl.exception.NcmpException; -import org.onap.cps.ncmp.api.impl.exception.ServerNcmpException; -import org.onap.cps.ncmp.rest.controller.NetworkCmProxyController; -import org.onap.cps.ncmp.rest.controller.NetworkCmProxyInventoryController; +import org.onap.cps.ncmp.api.data.exceptions.InvalidDatastoreException; +import org.onap.cps.ncmp.api.data.exceptions.InvalidOperationException; +import org.onap.cps.ncmp.api.data.exceptions.OperationNotSupportedException; +import org.onap.cps.ncmp.api.exceptions.DmiClientRequestException; +import org.onap.cps.ncmp.api.exceptions.DmiRequestException; +import org.onap.cps.ncmp.api.exceptions.InvalidTopicException; +import org.onap.cps.ncmp.api.exceptions.NcmpException; +import org.onap.cps.ncmp.api.exceptions.PayloadTooLargeException; +import org.onap.cps.ncmp.api.exceptions.PolicyExecutorException; +import org.onap.cps.ncmp.api.exceptions.ServerNcmpException; import org.onap.cps.ncmp.rest.model.DmiErrorMessage; import org.onap.cps.ncmp.rest.model.DmiErrorMessageDmiResponse; import org.onap.cps.ncmp.rest.model.ErrorMessage; @@ -76,15 +78,15 @@ public class NetworkCmProxyRestExceptionHandler { return wrapDmiErrorResponse(dmiClientRequestException); } - @ExceptionHandler({DmiRequestException.class, DataValidationException.class, OperationNotSupportedException.class, - HttpMessageNotReadableException.class, InvalidTopicException.class, InvalidDatastoreException.class, - InvalidDmiResourceUrlException.class}) + @ExceptionHandler({DmiRequestException.class, DataValidationException.class, InvalidOperationException.class, + OperationNotSupportedException.class, HttpMessageNotReadableException.class, InvalidTopicException.class, + InvalidDatastoreException.class}) public static ResponseEntity<Object> handleDmiRequestExceptions(final Exception exception) { return buildErrorResponse(HttpStatus.BAD_REQUEST, exception); } - @ExceptionHandler({AlreadyDefinedException.class}) - public static ResponseEntity<Object> handleAlreadyDefinedExceptions(final Exception exception) { + @ExceptionHandler({AlreadyDefinedException.class, PolicyExecutorException.class}) + public static ResponseEntity<Object> handleConflictExceptions(final Exception exception) { return buildErrorResponse(HttpStatus.CONFLICT, exception); } @@ -112,8 +114,6 @@ public class NetworkCmProxyRestExceptionHandler { } else { errorMessage.setDetails(CHECK_LOGS_FOR_DETAILS); } - errorMessage.setDetails( - exception instanceof CpsException ? ((CpsException) exception).getDetails() : CHECK_LOGS_FOR_DETAILS); return new ResponseEntity<>(errorMessage, status); } 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 80e1c442e9..0000000000 --- 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 20059e20f4..0000000000 --- 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 53e374d30a..0000000000 --- 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); - } - }); - } -} diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/exceptions/InvalidTopicException.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/exceptions/InvalidTopicException.java deleted file mode 100644 index 6a52d5861e..0000000000 --- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/exceptions/InvalidTopicException.java +++ /dev/null @@ -1,40 +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.exceptions; - -import lombok.Getter; - -public class InvalidTopicException extends RuntimeException { - - @Getter - final String details; - - /** - * Constructor. - * - * @param message the error message - * @param details the error details - */ - public InvalidTopicException(final String message, final String details) { - super(message); - this.details = details; - } -} diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/exceptions/OperationNotSupportedException.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/exceptions/OperationNotSupportedException.java deleted file mode 100644 index e1daf3df6f..0000000000 --- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/exceptions/OperationNotSupportedException.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * ============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.exceptions; - -public class OperationNotSupportedException extends RuntimeException { - /** - * Instantiates a new not implemented operation exception. - * - * @param message the message - */ - public OperationNotSupportedException(final String message) { - super(message); - } -} diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/exceptions/PayloadTooLargeException.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/exceptions/PayloadTooLargeException.java deleted file mode 100644 index cddbd08379..0000000000 --- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/exceptions/PayloadTooLargeException.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 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.exceptions; - -public class PayloadTooLargeException extends RuntimeException { - - /** - * Instantiates a new payload too large exception. - */ - public PayloadTooLargeException(final String message) { - super(message); - } -} diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/mapper/CmHandleStateMapper.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/util/CmHandleStateMapper.java index b436540fc2..4abcb72308 100644 --- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/mapper/CmHandleStateMapper.java +++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/util/CmHandleStateMapper.java @@ -18,16 +18,16 @@ * ============LICENSE_END========================================================= */ -package org.onap.cps.ncmp.rest.mapper; +package org.onap.cps.ncmp.rest.util; -import static org.onap.cps.ncmp.api.impl.inventory.LockReasonCategory.LOCKED_MISBEHAVING; +import static org.onap.cps.ncmp.impl.inventory.models.LockReasonCategory.LOCKED_MISBEHAVING; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.Named; import org.mapstruct.NullValueCheckStrategy; import org.mapstruct.NullValuePropertyMappingStrategy; -import org.onap.cps.ncmp.api.impl.inventory.CompositeState; +import org.onap.cps.ncmp.api.inventory.models.CompositeState; import org.onap.cps.ncmp.rest.model.CmHandleCompositeState; import org.onap.cps.ncmp.rest.model.DataStores; import org.onap.cps.ncmp.rest.model.LockReason; diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/mapper/DataOperationRequestMapper.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/util/DataOperationRequestMapper.java index 51ee8ca174..42622a2ca2 100644 --- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/mapper/DataOperationRequestMapper.java +++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/util/DataOperationRequestMapper.java @@ -18,14 +18,14 @@ * ============LICENSE_END========================================================= */ -package org.onap.cps.ncmp.rest.mapper; +package org.onap.cps.ncmp.rest.util; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.NullValueCheckStrategy; import org.mapstruct.NullValuePropertyMappingStrategy; -import org.onap.cps.ncmp.api.models.DataOperationDefinition; -import org.onap.cps.ncmp.api.models.DataOperationRequest; +import org.onap.cps.ncmp.api.data.models.DataOperationDefinition; +import org.onap.cps.ncmp.api.data.models.DataOperationRequest; @Mapper(componentModel = "spring", nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.SET_TO_DEFAULT) diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/util/DeprecationHelper.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/util/DeprecationHelper.java index 573491ca3f..7492c1fcac 100644 --- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/util/DeprecationHelper.java +++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/util/DeprecationHelper.java @@ -23,8 +23,8 @@ package org.onap.cps.ncmp.rest.util; import java.util.ArrayList; import java.util.Collections; import lombok.RequiredArgsConstructor; -import org.onap.cps.ncmp.api.models.CmHandleQueryApiParameters; -import org.onap.cps.ncmp.api.models.ConditionApiProperties; +import org.onap.cps.ncmp.api.inventory.models.CmHandleQueryApiParameters; +import org.onap.cps.ncmp.api.inventory.models.ConditionApiProperties; import org.onap.cps.ncmp.rest.model.CmHandleQueryParameters; import org.onap.cps.utils.JsonObjectMapper; import org.springframework.stereotype.Component; diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapper.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/util/NcmpRestInputMapper.java index 045b8a7414..b9a814dce4 100644 --- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapper.java +++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/util/NcmpRestInputMapper.java @@ -18,16 +18,16 @@ * ============LICENSE_END========================================================= */ -package org.onap.cps.ncmp.rest.controller; +package org.onap.cps.ncmp.rest.util; import org.mapstruct.InheritConfiguration; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.NullValueCheckStrategy; import org.mapstruct.NullValuePropertyMappingStrategy; -import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters; -import org.onap.cps.ncmp.api.models.DmiPluginRegistration; -import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle; +import org.onap.cps.ncmp.api.inventory.models.CmHandleQueryServiceParameters; +import org.onap.cps.ncmp.api.inventory.models.DmiPluginRegistration; +import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle; import org.onap.cps.ncmp.rest.model.CmHandleQueryParameters; import org.onap.cps.ncmp.rest.model.RestDmiPluginRegistration; import org.onap.cps.ncmp.rest.model.RestInputCmHandle; diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/util/TopicValidator.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/util/TopicValidator.java deleted file mode 100644 index 6a46fbd638..0000000000 --- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/util/TopicValidator.java +++ /dev/null @@ -1,47 +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.util; - -import java.util.regex.Pattern; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import org.onap.cps.ncmp.rest.exceptions.InvalidTopicException; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class TopicValidator { - - private static final Pattern TOPIC_NAME_PATTERN = Pattern.compile("^[a-zA-Z0-9]([._-](?![._-])|" - + "[a-zA-Z0-9]){0,120}[a-zA-Z0-9]$"); - - /** - * Validate kafka topic name pattern. - * - * @param topicName name of the topic to be validated - * - * @throws InvalidTopicException if the topic is not valid - */ - public static void validateTopicName(final String topicName) { - if (!TOPIC_NAME_PATTERN.matcher(topicName).matches()) { - throw new InvalidTopicException("Topic name " + topicName + " is invalid", "invalid topic"); - } - } - -} 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 3a5748f002..43403fa890 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 @@ -23,48 +23,30 @@ package org.onap.cps.ncmp.rest.controller -import static org.onap.cps.ncmp.api.impl.inventory.CompositeState.DataStores -import static org.onap.cps.ncmp.api.impl.inventory.CompositeState.Operational -import static org.onap.cps.ncmp.api.impl.operations.DatastoreType.OPERATIONAL -import static org.onap.cps.ncmp.api.impl.operations.DatastoreType.PASSTHROUGH_OPERATIONAL -import static org.onap.cps.ncmp.api.impl.operations.DatastoreType.PASSTHROUGH_RUNNING -import static org.onap.cps.ncmp.api.impl.operations.OperationType.CREATE -import static org.onap.cps.ncmp.api.impl.operations.OperationType.DELETE -import static org.onap.cps.ncmp.api.impl.operations.OperationType.PATCH -import static org.onap.cps.ncmp.api.impl.operations.OperationType.UPDATE -import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS -import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put - import ch.qos.logback.classic.Level import ch.qos.logback.classic.Logger import ch.qos.logback.classic.spi.ILoggingEvent import ch.qos.logback.core.read.ListAppender import com.fasterxml.jackson.databind.ObjectMapper +import groovy.json.JsonSlurper import org.mapstruct.factory.Mappers import org.onap.cps.TestUtils import org.onap.cps.events.EventsPublisher -import org.onap.cps.ncmp.api.NetworkCmProxyDataService -import org.onap.cps.ncmp.api.NetworkCmProxyQueryService -import org.onap.cps.ncmp.api.impl.inventory.CmHandleState -import org.onap.cps.ncmp.api.impl.inventory.CompositeState -import org.onap.cps.ncmp.api.impl.inventory.DataStoreSyncState -import org.onap.cps.ncmp.api.impl.inventory.LockReasonCategory -import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevel -import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle -import org.onap.cps.ncmp.api.models.CmResourceAddress -import org.onap.cps.ncmp.rest.controller.handlers.NcmpCachedResourceRequestHandler -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.api.inventory.NetworkCmProxyInventoryFacade +import org.onap.cps.ncmp.api.inventory.models.CompositeState +import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle +import org.onap.cps.ncmp.api.inventory.models.TrustLevel +import org.onap.cps.ncmp.impl.data.NetworkCmProxyFacade +import org.onap.cps.ncmp.impl.inventory.DataStoreSyncState +import org.onap.cps.ncmp.impl.inventory.models.CmHandleState +import org.onap.cps.ncmp.impl.inventory.models.LockReasonCategory +import org.onap.cps.ncmp.impl.utils.AlternateIdMatcher import org.onap.cps.ncmp.rest.model.DataOperationDefinition import org.onap.cps.ncmp.rest.model.DataOperationRequest +import org.onap.cps.ncmp.rest.util.CmHandleStateMapper +import org.onap.cps.ncmp.rest.util.DataOperationRequestMapper import org.onap.cps.ncmp.rest.util.DeprecationHelper -import org.onap.cps.spi.FetchDescendantsOption +import org.onap.cps.ncmp.rest.util.NcmpRestInputMapper import org.onap.cps.spi.model.ModuleDefinition import org.onap.cps.spi.model.ModuleReference import org.onap.cps.utils.JsonObjectMapper @@ -75,15 +57,29 @@ import org.springframework.beans.factory.annotation.Value import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest import org.springframework.http.HttpStatus import org.springframework.http.MediaType +import org.springframework.http.ResponseEntity import org.springframework.test.web.servlet.MockMvc +import reactor.core.publisher.Mono import spock.lang.Shared import spock.lang.Specification + import java.time.OffsetDateTime import java.time.ZoneOffset import java.time.format.DateTimeFormatter -import groovy.json.JsonSlurper -import org.springframework.http.ResponseEntity -import reactor.core.publisher.Mono + +import static org.onap.cps.ncmp.api.data.models.DatastoreType.PASSTHROUGH_OPERATIONAL +import static org.onap.cps.ncmp.api.data.models.DatastoreType.PASSTHROUGH_RUNNING +import static org.onap.cps.ncmp.api.data.models.OperationType.CREATE +import static org.onap.cps.ncmp.api.data.models.OperationType.DELETE +import static org.onap.cps.ncmp.api.data.models.OperationType.PATCH +import static org.onap.cps.ncmp.api.data.models.OperationType.UPDATE +import static org.onap.cps.ncmp.api.inventory.models.CompositeState.DataStores +import static org.onap.cps.ncmp.api.inventory.models.CompositeState.Operational +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put @WebMvcTest(NetworkCmProxyController) class NetworkCmProxyControllerSpec extends Specification { @@ -92,10 +88,13 @@ class NetworkCmProxyControllerSpec extends Specification { MockMvc mvc @SpringBean - NetworkCmProxyDataService mockNetworkCmProxyDataService = Mock() + NetworkCmProxyFacade mockNetworkCmProxyFacade = Mock() @SpringBean - NetworkCmProxyQueryService mockNetworkCmProxyQueryService = Mock() + NetworkCmProxyInventoryFacade mockNetworkCmProxyInventoryFacade = Mock() + + @SpringBean + AlternateIdMatcher mockAlternateIdMatcher = Mock() @SpringBean ObjectMapper objectMapper = new ObjectMapper() @@ -113,17 +112,8 @@ class NetworkCmProxyControllerSpec extends Specification { DataOperationRequestMapper dataOperationRequestMapper = Mappers.getMapper(DataOperationRequestMapper) @SpringBean - Map<String, TrustLevel> trustLevelPerCmHandle = [:] - - @SpringBean DeprecationHelper stubbedDeprecationHelper = Stub() - @SpringBean - NcmpCachedResourceRequestHandler ncmpCachedResourceRequestHandler = new NcmpCachedResourceRequestHandler(mockNetworkCmProxyDataService, mockNetworkCmProxyQueryService) - - @SpringBean - NcmpPassthroughResourceRequestHandler ncmpPassthroughResourceRequestHandler = new NcmpPassthroughResourceRequestHandler(mockNetworkCmProxyDataService) - @Value('${rest.api.ncmp-base-path}/v1') def ncmpBasePathV1 @@ -133,17 +123,12 @@ class NetworkCmProxyControllerSpec extends Specification { @Shared def NO_TOPIC = null - def NO_REQUEST_ID = null + def NO_OPTIONS = null def NO_AUTH_HEADER = null - def TIMEOUT_FOR_TEST = 1234 def logger = Spy(ListAppender<ILoggingEvent>) def setup() { - ncmpCachedResourceRequestHandler.notificationFeatureEnabled = true - ncmpCachedResourceRequestHandler.timeOutInMilliSeconds = TIMEOUT_FOR_TEST - ncmpPassthroughResourceRequestHandler.notificationFeatureEnabled = true - ncmpPassthroughResourceRequestHandler.timeOutInMilliSeconds = TIMEOUT_FOR_TEST setupLogger() } @@ -154,12 +139,10 @@ class NetworkCmProxyControllerSpec extends Specification { def 'Get Resource Data from pass-through operational.'() { given: 'resource data url' def getUrl = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:passthrough-operational?resourceIdentifier=parent/child&options=(a=1,b=2)" - and: 'the expected cm resource address' - def expectedCmResourceAddress = new CmResourceAddress(PASSTHROUGH_OPERATIONAL.datastoreName, 'testCmHandle', 'parent/child') when: 'get data resource request is performed' def response = mvc.perform(get(getUrl).contentType(MediaType.APPLICATION_JSON)).andReturn().response then: 'the NCMP data service is called with correct parameters' - 1 * mockNetworkCmProxyDataService.getResourceDataForCmHandle(expectedCmResourceAddress, '(a=1,b=2)', NO_TOPIC, NO_REQUEST_ID, NO_AUTH_HEADER) >> Mono.just(new ResponseEntity<Object>(HttpStatus.OK)) + 1 * mockNetworkCmProxyFacade.getResourceDataForCmHandle(_, '(a=1,b=2)', NO_TOPIC, false, NO_AUTH_HEADER) >> Mono.just(new ResponseEntity<Object>(HttpStatus.OK)) and: 'response status is Ok' assert response.status == HttpStatus.OK.value() } @@ -168,21 +151,19 @@ class NetworkCmProxyControllerSpec extends Specification { given: 'resource data url' def getUrl = "$ncmpBasePathV1/ch/h123/data/ds/ncmp-datastore:operational?resourceIdentifier=parent/child${additionalUrlParam}" and: 'the expected cm resource address' - def expectedCmResourceAddress = new CmResourceAddress('ncmp-datastore:operational', 'h123', 'parent/child') when: 'get data resource request is performed' def response = mvc.perform(get(getUrl).contentType(MediaType.APPLICATION_JSON)).andReturn().response then: 'the NCMP data service is called with correct parameters' - 1 * mockNetworkCmProxyDataService.getResourceDataForCmHandle(expectedCmResourceAddress, expectedIncludeDescendants) + 1 * mockNetworkCmProxyFacade.getResourceDataForCmHandle(_, NO_OPTIONS, NO_TOPIC, expectedIncludeDescendants, NO_AUTH_HEADER) and: 'response status is OK' assert response.status == HttpStatus.OK.value() where: 'the following parameters are used' scenario | additionalUrlParam || expectedIncludeDescendants - 'no additional param' | '' || OMIT_DESCENDANTS - 'include descendants true' | '&include-descendants=true' || INCLUDE_ALL_DESCENDANTS - 'include descendants TRUE' | '&include-descendants=true' || INCLUDE_ALL_DESCENDANTS - 'include descendants false' | '&include-descendants=false' || OMIT_DESCENDANTS - 'include descendants FALSE' | '&include-descendants=FALSE' || OMIT_DESCENDANTS - 'options (ignored)' | '&options=(a-=1)' || OMIT_DESCENDANTS + 'no additional param' | '' || false + 'include descendants true' | '&include-descendants=true' || true + 'include descendants TRUE' | '&include-descendants=true' || true + 'include descendants false' | '&include-descendants=false' || false + 'include descendants FALSE' | '&include-descendants=FALSE' || false } def 'Execute (async) data operation to read data from dmi service.'() { @@ -193,45 +174,19 @@ class NetworkCmProxyControllerSpec extends Specification { def response = mvc.perform(post(getUrl).contentType(MediaType.APPLICATION_JSON).content(dataOperationRequestJsonData)).andReturn().response then: 'response status is Ok' assert response.status == HttpStatus.OK.value() - and: 'async request id is generated' - assert response.contentAsString.contains('requestId') then: 'the request for (async) data operation invoked once' - 1 * mockNetworkCmProxyDataService.executeDataOperationForCmHandles('my-topic-name', _, _, null) + 1 * mockNetworkCmProxyFacade.executeDataOperationForCmHandles('my-topic-name', _, NO_AUTH_HEADER) where: 'the following data stores are used' datastore << [PASSTHROUGH_RUNNING, PASSTHROUGH_OPERATIONAL] } - def 'Execute (async) data operation with some validation error.'() { - given: 'data operation url' - def getUrl = "$ncmpBasePathV1/data?topic=my-topic-name" - def dataOperationRequestJsonData = jsonObjectMapper.asJsonString(getDataOperationRequest('read', 'invalid datastore')) - when: 'post data resource request is performed' - def response = mvc.perform(post(getUrl).contentType(MediaType.APPLICATION_JSON).content(dataOperationRequestJsonData)).andReturn().response - then: 'response status is BAD_REQUEST' - assert response.status == HttpStatus.BAD_REQUEST.value() - } - - def 'Get data operation resource data when notification feature is disabled for datastore: #datastore.'() { - given: 'data operation url' - def getUrl = "$ncmpBasePathV1/data?topic=my-topic-name" - def dataOperationRequestJsonData = jsonObjectMapper.asJsonString(getDataOperationRequest("read", PASSTHROUGH_RUNNING.datastoreName)) - ncmpPassthroughResourceRequestHandler.notificationFeatureEnabled = false - when: 'post data resource request is performed' - def response = mvc.perform(post(getUrl).contentType(MediaType.APPLICATION_JSON).content(dataOperationRequestJsonData) - ).andReturn().response - then: 'response status is Ok' - assert response.status == HttpStatus.OK.value() - and: 'async request id is unavailable' - assert response.contentAsString == '{"status":"Asynchronous request is unavailable as notification feature is currently disabled."}' - } - def 'Query Resource Data from operational.'() { given: 'the query resource data url' - def getUrl = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:operational/query?cps-path=/cps/path" + def getUrl = "$ncmpBasePathV1/ch/ch-1/data/ds/ncmp-datastore:operational/query?cps-path=/cps/path" when: 'the query data resource request is performed' def response = mvc.perform(get(getUrl).contentType(MediaType.APPLICATION_JSON)).andReturn().response then: 'the NCMP query service is called with queryResourceDataOperationalForCmHandle' - 1 * mockNetworkCmProxyQueryService.queryResourceDataOperational('testCmHandle','/cps/path',FetchDescendantsOption.OMIT_DESCENDANTS) + 1 * mockNetworkCmProxyFacade.queryResourceDataForCmHandle('ch-1','/cps/path', false) and: 'response status is Ok' assert response.status == HttpStatus.OK.value() } @@ -249,11 +204,10 @@ class NetworkCmProxyControllerSpec extends Specification { def 'Get Resource Data from pass-through running with #scenario value in resource identifier param.'() { given: 'resource data url' - def getUrl = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:passthrough-running?resourceIdentifier=$resourceIdentifier&options=(a=1,b=2)" + def getUrl = "$ncmpBasePathV1/ch/ch-1/data/ds/ncmp-datastore:passthrough-running?resourceIdentifier=$resourceIdentifier&options=(a=1)" and: 'ncmp service returns json object' - def expectedCmResourceAddress = new CmResourceAddress(PASSTHROUGH_RUNNING.datastoreName, 'testCmHandle', resourceIdentifier) - 1 * mockNetworkCmProxyDataService.getResourceDataForCmHandle(expectedCmResourceAddress, '(a=1,b=2)', NO_TOPIC, NO_REQUEST_ID, NO_AUTH_HEADER) - >> Mono.just(new ResponseEntity<Object>('{valid-json}', HttpStatus.OK)) + 1 * mockNetworkCmProxyFacade.getResourceDataForCmHandle(_, '(a=1)', NO_TOPIC, false, NO_AUTH_HEADER) + >> new ResponseEntity<Object>('{valid-json}', HttpStatus.OK) when: 'get data resource request is performed' def response = mvc.perform(get(getUrl).contentType(MediaType.APPLICATION_JSON)).andReturn().response then: 'response status is Ok' @@ -277,7 +231,7 @@ class NetworkCmProxyControllerSpec extends Specification { when: 'update data resource request is performed' def response = mvc.perform(put(updateUrl).contentType(MediaType.APPLICATION_JSON_VALUE).content(requestBody)).andReturn().response then: 'ncmp service method to update resource is called' - 1 * mockNetworkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle('testCmHandle','parent/child', UPDATE, requestBody, 'application/json;charset=UTF-8', NO_AUTH_HEADER) + 1 * mockNetworkCmProxyFacade.writeResourceDataPassThroughRunningForCmHandle('testCmHandle','parent/child', UPDATE, requestBody, 'application/json;charset=UTF-8', NO_AUTH_HEADER) and: 'the response status is OK' assert response.status == HttpStatus.OK.value() } @@ -288,7 +242,7 @@ class NetworkCmProxyControllerSpec extends Specification { when: 'create resource request is performed' def response = mvc.perform(post(url).contentType(MediaType.APPLICATION_JSON_VALUE).content(requestBody)).andReturn().response then: 'ncmp service method to create resource called' - 1 * mockNetworkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle('testCmHandle', 'parent/child', CREATE, requestBody, 'application/json;charset=UTF-8', NO_AUTH_HEADER) + 1 * mockNetworkCmProxyFacade.writeResourceDataPassThroughRunningForCmHandle('testCmHandle', 'parent/child', CREATE, requestBody, 'application/json;charset=UTF-8', NO_AUTH_HEADER) and: 'resource is created' assert response.status == HttpStatus.CREATED.value() } @@ -299,7 +253,7 @@ class NetworkCmProxyControllerSpec extends Specification { when: 'get module resource request is performed' def response = mvc.perform(get(getUrl)).andReturn().response then: 'ncmp service method to get yang resource module references is called' - mockNetworkCmProxyDataService.getYangResourcesModuleReferences('some-cmhandle') >> [new ModuleReference(moduleName: 'some-name1', revision: '2021-10-03')] + mockNetworkCmProxyInventoryFacade.getYangResourcesModuleReferences('some-cmhandle') >> [new ModuleReference(moduleName: 'some-name1', revision: '2021-10-03')] and: 'response contains an array with the module name and revision' response.getContentAsString() == '[{"moduleName":"some-name1","revision":"2021-10-03"}]' and: 'response returns an OK http code' @@ -314,15 +268,14 @@ class NetworkCmProxyControllerSpec extends Specification { def cmHandle1 = new NcmpServiceCmHandle() cmHandle1.cmHandleId = 'ch-1' cmHandle1.publicProperties = [color: 'yellow'] + cmHandle1.currentTrustLevel = TrustLevel.NONE def cmHandle2 = new NcmpServiceCmHandle() cmHandle2.cmHandleId = 'ch-2' cmHandle2.publicProperties = [color: 'green'] cmHandle2.alternateId = 'someAlternateId' cmHandle2.moduleSetTag = 'someModuleSetTag' cmHandle2.dataProducerIdentifier = 'someDataProducerIdentifier' - mockNetworkCmProxyDataService.executeCmHandleSearch(_) >> [cmHandle1, cmHandle2] - and: 'map for trust level per cmHandle has value for only one cm handle' - trustLevelPerCmHandle.put('ch-1', TrustLevel.NONE) + mockNetworkCmProxyInventoryFacade.executeCmHandleSearch(_) >> [cmHandle1, cmHandle2] when: 'the searches api is invoked' def response = mvc.perform(post(searchesEndpoint).contentType(MediaType.APPLICATION_JSON).content(jsonString)).andReturn().response then: 'response status returns OK' @@ -331,19 +284,18 @@ class NetworkCmProxyControllerSpec extends Specification { assert response.contentAsString == '[{"cmHandle":"ch-1","publicCmHandleProperties":[{"color":"yellow"}],"state":null,"trustLevel":"NONE","moduleSetTag":null,"alternateId":null,"dataProducerIdentifier":null},{"cmHandle":"ch-2","publicCmHandleProperties":[{"color":"green"}],"state":null,"trustLevel":null,"moduleSetTag":"someModuleSetTag","alternateId":"someAlternateId","dataProducerIdentifier":"someDataProducerIdentifier"}]' } - def 'Get complete Cm Handle details by Cm Handle id.'() { - given: 'an endpoint and a cm handle' - def cmHandleDetailsEndpoint = "$ncmpBasePathV1/ch/some-cm-handle" + def 'Get complete Cm Handle details by Cm Handle Reference.'() { + given: 'an endpoint and a cm handle reference' + def cmHandleDetailsEndpoint = "$ncmpBasePathV1/ch/some-cm-handle-reference" and: 'an existing ncmp service cm handle' def cmHandleId = 'some-cm-handle' + def alternateId = 'some-alternate-id' def dmiProperties = [prop: 'some DMI property'] def publicProperties = ["public prop": 'some public property'] def compositeState = compositeStateTestObject() - def ncmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: cmHandleId, dmiProperties: dmiProperties, publicProperties: publicProperties, compositeState: compositeState) - and: 'the service method is invoked with the cm handle id' - 1 * mockNetworkCmProxyDataService.getNcmpServiceCmHandle('some-cm-handle') >> ncmpServiceCmHandle - and: 'map for trust level per cmHandle has values' - trustLevelPerCmHandle.get('some-cm-handle') >> { TrustLevel.COMPLETE } + def ncmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: cmHandleId, alternateId: alternateId, dmiProperties: dmiProperties, publicProperties: publicProperties, compositeState: compositeState, currentTrustLevel: TrustLevel.COMPLETE) + and: 'the service method is invoked with the cm handle reference' + 1 * mockNetworkCmProxyInventoryFacade.getNcmpServiceCmHandle('some-cm-handle-reference') >> ncmpServiceCmHandle when: 'the cm handle details api is invoked' def response = mvc.perform( get(cmHandleDetailsEndpoint)).andReturn().response @@ -357,13 +309,13 @@ class NetworkCmProxyControllerSpec extends Specification { assert !response.contentAsString.contains("some DMI property") } - def 'Get Cm Handle public properties by Cm Handle id.'() { + def 'Get Cm Handle public properties by Cm Handle Reference.'() { given: 'a cm handle properties endpoint' - def cmHandlePropertiesEndpoint = "$ncmpBasePathV1/ch/some-cm-handle/properties" + def cmHandlePropertiesEndpoint = "$ncmpBasePathV1/ch/some-cm-handle-reference/properties" and: 'some cm handle public properties' def publicProperties = ['public prop': 'some public property'] and: 'the service method is invoked with the cm handle id returning the cm handle public properties' - 1 * mockNetworkCmProxyDataService.getCmHandlePublicProperties('some-cm-handle') >> publicProperties + 1 * mockNetworkCmProxyInventoryFacade.getCmHandlePublicProperties('some-cm-handle-reference') >> publicProperties when: 'the cm handle properties api is invoked' def response = mvc.perform(get(cmHandlePropertiesEndpoint)).andReturn().response then: 'the correct response is returned' @@ -372,13 +324,13 @@ class NetworkCmProxyControllerSpec extends Specification { assertContainsPublicProperties(response) } - def 'Get Cm Handle composite state by Cm Handle id.'() { + def 'Get Cm Handle composite state by Cm Handle Reference.'() { given: 'a cm handle state endpoint' - def cmHandlePropertiesEndpoint = "$ncmpBasePathV1/ch/some-cm-handle/state" + def cmHandlePropertiesEndpoint = "$ncmpBasePathV1/ch/some-cm-handle-reference/state" and: 'some cm handle composite state' def compositeState = compositeStateTestObject() and: 'the service method is invoked with the cm handle id returning the cm handle composite state' - 1 * mockNetworkCmProxyDataService.getCmHandleCompositeState('some-cm-handle') >> compositeState + 1 * mockNetworkCmProxyInventoryFacade.getCmHandleCompositeState('some-cm-handle-reference') >> compositeState when: 'the cm handle state api is invoked' def response = mvc.perform(get(cmHandlePropertiesEndpoint)).andReturn().response then: 'the correct response is returned' @@ -392,16 +344,15 @@ class NetworkCmProxyControllerSpec extends Specification { def searchesEndpoint = "$ncmpBasePathV1/ch/searches" String jsonString = TestUtils.getResourceFileContent('invalid-cmhandle-search.json') and: 'the service method is invoked with module names and returns two cm handles' - def cmHandel1 = new NcmpServiceCmHandle() - cmHandel1.cmHandleId = 'ch-1' - cmHandel1.publicProperties = [color: 'yellow'] - def cmHandel2 = new NcmpServiceCmHandle() - cmHandel2.cmHandleId = 'ch-2' - cmHandel2.publicProperties = [color: 'green'] - mockNetworkCmProxyDataService.executeCmHandleSearch(_) >> [cmHandel1, cmHandel2] - and: 'map for trust level per cmHandle has values' - trustLevelPerCmHandle.put('ch-1', TrustLevel.COMPLETE) - trustLevelPerCmHandle.put('ch-2', TrustLevel.NONE) + def cmHandle1 = new NcmpServiceCmHandle() + cmHandle1.cmHandleId = 'ch-1' + cmHandle1.publicProperties = [color: 'yellow'] + cmHandle1.currentTrustLevel = TrustLevel.COMPLETE + def cmHandle2 = new NcmpServiceCmHandle() + cmHandle2.cmHandleId = 'ch-2' + cmHandle2.publicProperties = [color: 'green'] + cmHandle2.currentTrustLevel = TrustLevel.NONE + mockNetworkCmProxyInventoryFacade.executeCmHandleSearch(_) >> [cmHandle1, cmHandle2] when: 'the searches api is invoked' def response = mvc.perform(post(searchesEndpoint).contentType(MediaType.APPLICATION_JSON).content(jsonString)).andReturn().response then: 'an empty cm handle identifier is returned' @@ -412,7 +363,7 @@ class NetworkCmProxyControllerSpec extends Specification { given: 'an endpoint and json data' def searchesEndpoint = "$ncmpBasePathV1/ch/id-searches" and: 'the service method is invoked with module names and returns cm handle ids' - 1 * mockNetworkCmProxyDataService.executeCmHandleIdSearch(_) >> ['ch-1', 'ch-2'] + 1 * mockNetworkCmProxyInventoryFacade.executeCmHandleIdSearch(_) >> ['ch-1', 'ch-2'] when: 'the searches api is invoked' def response = mvc.perform(post(searchesEndpoint).contentType(MediaType.APPLICATION_JSON).content('{}')).andReturn().response then: 'cm handle ids are returned' @@ -434,7 +385,7 @@ class NetworkCmProxyControllerSpec extends Specification { when: 'patch data resource request is performed' def response = mvc.perform(patch(url).contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON).content(requestBody)).andReturn().response then: 'ncmp service method to update resource is called' - 1 * mockNetworkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle('testCmHandle', 'parent/child', PATCH, requestBody, 'application/json;charset=UTF-8', NO_AUTH_HEADER) + 1 * mockNetworkCmProxyFacade.writeResourceDataPassThroughRunningForCmHandle('testCmHandle', 'parent/child', PATCH, requestBody, 'application/json;charset=UTF-8', NO_AUTH_HEADER) and: 'the response status is OK' assert response.status == HttpStatus.OK.value() } @@ -445,31 +396,16 @@ class NetworkCmProxyControllerSpec extends Specification { when: 'delete data resource request is performed' def response = mvc.perform(delete(url).contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)).andReturn().response then: 'the ncmp service method to delete resource is called (with null as body)' - 1 * mockNetworkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle('testCmHandle', 'parent/child', DELETE, null, 'application/json;charset=UTF-8', NO_AUTH_HEADER) + 1 * mockNetworkCmProxyFacade.writeResourceDataPassThroughRunningForCmHandle('testCmHandle', 'parent/child', DELETE, null, 'application/json;charset=UTF-8', NO_AUTH_HEADER) and: 'the response is No Content' assert response.status == HttpStatus.NO_CONTENT.value() } - def 'Get resource data from DMI with valid topic i.e. async request for #scenario'() { - given: 'resource data url' - def getUrl = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:${datastoreInUrl}?resourceIdentifier=parent/child&options=(a=1,b=2)&topic=my-topic-name" - and: 'the NCMP data service is called with correct parameters' - 1 * mockNetworkCmProxyDataService.getResourceDataForCmHandle(_, '(a=1,b=2)', 'my-topic-name', _, NO_AUTH_HEADER) >> Mono.just(new ResponseEntity<Object>(HttpStatus.OK)) - when: 'get data resource request is performed' - def response = mvc.perform(get(getUrl).contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON_VALUE)).andReturn().response - then: 'async request id is generated' - assert response.contentAsString.contains("requestId") - where: 'the following parameters are used' - scenario | datastoreInUrl - ':passthrough-operational' | 'passthrough-operational' - ':passthrough-running' | 'passthrough-running' - } - def 'Getting module definitions for a module'() { when: 'get module definition request is performed with module name' def response = mvc.perform(get("$ncmpBasePathV1/ch/some-cmhandle/modules/definitions?module-name=sampleModuleName")).andReturn().response then: 'ncmp service method is invoked with correct parameters' - mockNetworkCmProxyDataService.getModuleDefinitionsByCmHandleAndModule('some-cmhandle', 'sampleModuleName', _) + mockNetworkCmProxyInventoryFacade.getModuleDefinitionsByCmHandleAndModule('some-cmhandle', 'sampleModuleName', _) >> [new ModuleDefinition('sampleModuleName', '2021-10-03','module sampleModuleName{ sample module content }')] and: 'response contains an array with the module name, revision and content' response.getContentAsString() == '[{"moduleName":"sampleModuleName","revision":"2021-10-03","content":"module sampleModuleName{ sample module content }"}]' @@ -480,12 +416,12 @@ class NetworkCmProxyControllerSpec extends Specification { def 'Getting module definitions filtering on #scenario'() { when: 'get module definition request is performed' def response = mvc.perform( - get("$ncmpBasePathV1/ch/some-cmhandle/modules/definitions?module-name=" + moduleName + "&revision=" + revision)) + get("$ncmpBasePathV1/ch/some-cmhandle-reference/modules/definitions?module-name=" + moduleName + "&revision=" + revision)) .andReturn().response - then: 'ncmp service method to get definitions by cm handle is invoked when needed' - numberOfCallsToByCmHandleId * mockNetworkCmProxyDataService.getModuleDefinitionsByCmHandleId('some-cmhandle') >> [] + then: 'ncmp service method to get definitions by cm handle reference is invoked when needed' + numberOfCallsToByCmHandleId * mockNetworkCmProxyInventoryFacade.getModuleDefinitionsByCmHandleReference('some-cmhandle-reference') >> [] and: 'ncmp service method to get definitions by module is invoked when needed' - numberOfCallsToByModule * mockNetworkCmProxyDataService.getModuleDefinitionsByCmHandleAndModule('some-cmhandle', moduleName, revision) >> [] + numberOfCallsToByModule * mockNetworkCmProxyInventoryFacade.getModuleDefinitionsByCmHandleAndModule('some-cmhandle-reference', moduleName, revision) >> [] and: 'response returns an OK http code' response.status == HttpStatus.OK.value() and: 'the correct message is logged when needed' @@ -508,7 +444,7 @@ class NetworkCmProxyControllerSpec extends Specification { put("$ncmpBasePathV1/ch/some-cm-handle-id/data-sync?dataSyncEnabled=" + dataSyncEnabledFlag)) .andReturn().response then: 'method to set data sync enabled is called' - 1 * mockNetworkCmProxyDataService.setDataSyncEnabled('some-cm-handle-id', dataSyncEnabledFlag) + 1 * mockNetworkCmProxyInventoryFacade.setDataSyncEnabled('some-cm-handle-id', dataSyncEnabledFlag) and: 'the response returns an OK http code' response.status == HttpStatus.OK.value() where: 'the following parameters are used' @@ -517,23 +453,6 @@ class NetworkCmProxyControllerSpec extends Specification { 'disabled' | false } - def 'Get Resource Data from operational with or without descendants'() { - given: 'resource data url with descendants #enabled' - def getUrl = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:operational?resourceIdentifier=parent/child&include-descendants=${booleanValue}" - and: 'the expected target' - def expectedCmResourceAddress = new CmResourceAddress(OPERATIONAL.datastoreName, 'testCmHandle', 'parent/child') - when: 'get data resource request is performed' - def response = mvc.perform(get(getUrl).contentType(MediaType.APPLICATION_JSON)).andReturn().response - then: 'the NCMP data service is called with getResourceDataOperational with #descendantsOption' - 1 * mockNetworkCmProxyDataService.getResourceDataForCmHandle(expectedCmResourceAddress, descendantsOption) - and: 'response status is Ok' - assert response.status == HttpStatus.OK.value() - where: 'the following parameters are used' - booleanValue | descendantsOption - false | OMIT_DESCENDANTS - true | INCLUDE_ALL_DESCENDANTS - } - def 'Attempt execute #operation rest operation on resource data with #scenario'() { given: 'resource data url' def url = "$ncmpBasePathV1/ch/testCmHandle/data/ds/${datastoreInUrl}?resourceIdentifier=parent/child" diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryControllerSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryControllerSpec.groovy index 7b850a7fff..97c68f08f3 100644 --- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryControllerSpec.groovy +++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryControllerSpec.groovy @@ -23,15 +23,16 @@ package org.onap.cps.ncmp.rest.controller import com.fasterxml.jackson.databind.ObjectMapper import org.onap.cps.TestUtils -import org.onap.cps.ncmp.api.NetworkCmProxyDataService -import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse -import org.onap.cps.ncmp.api.models.DmiPluginRegistration -import org.onap.cps.ncmp.api.models.DmiPluginRegistrationResponse +import org.onap.cps.ncmp.api.inventory.NetworkCmProxyInventoryFacade +import org.onap.cps.ncmp.api.inventory.models.CmHandleQueryServiceParameters +import org.onap.cps.ncmp.api.inventory.models.CmHandleRegistrationResponse +import org.onap.cps.ncmp.api.inventory.models.DmiPluginRegistration +import org.onap.cps.ncmp.api.inventory.models.DmiPluginRegistrationResponse import org.onap.cps.ncmp.rest.model.CmHandleQueryParameters import org.onap.cps.ncmp.rest.model.CmHandlerRegistrationErrorResponse import org.onap.cps.ncmp.rest.model.DmiPluginRegistrationErrorResponse import org.onap.cps.ncmp.rest.model.RestDmiPluginRegistration -import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters +import org.onap.cps.ncmp.rest.util.NcmpRestInputMapper import org.onap.cps.utils.JsonObjectMapper import org.spockframework.spring.SpringBean import org.springframework.beans.factory.annotation.Autowired @@ -54,7 +55,7 @@ class NetworkCmProxyInventoryControllerSpec extends Specification { MockMvc mvc @SpringBean - NetworkCmProxyDataService mockNetworkCmProxyDataService = Mock() + NetworkCmProxyInventoryFacade mockNetworkCmProxyInventoryFacade = Mock() @SpringBean NcmpRestInputMapper ncmpRestInputMapper = Mock() @@ -83,7 +84,7 @@ class NetworkCmProxyInventoryControllerSpec extends Specification { .content(jsonData) ).andReturn().response then: 'the converted object is forwarded to the registration service' - 1 * mockNetworkCmProxyDataService.updateDmiRegistrationAndSyncModule(mockDmiPluginRegistration) >> new DmiPluginRegistrationResponse() + 1 * mockNetworkCmProxyInventoryFacade.updateDmiRegistrationAndSyncModule(mockDmiPluginRegistration) >> new DmiPluginRegistrationResponse() and: 'response status is no content' response.status == HttpStatus.OK.value() where: 'the following registration json is used' @@ -112,7 +113,7 @@ class NetworkCmProxyInventoryControllerSpec extends Specification { and: 'the mapper service returns a converted object' ncmpRestInputMapper.toCmHandleQueryServiceParameters(_) >> cmHandleQueryServiceParameters and: 'the service returns the desired results' - mockNetworkCmProxyDataService.executeCmHandleIdSearchForInventory(cmHandleQueryServiceParameters) >> serviceMockResponse + mockNetworkCmProxyInventoryFacade.executeParameterizedCmHandleIdSearch(cmHandleQueryServiceParameters) >> serviceMockResponse when: 'post request is performed & search is called with the given request parameters' def response = mvc.perform( post("$ncmpBasePathV1/ch/searches") @@ -135,7 +136,7 @@ class NetworkCmProxyInventoryControllerSpec extends Specification { and: 'the mapper service returns a converted object' ncmpRestInputMapper.toCmHandleQueryServiceParameters(_) >> cmHandleQueryServiceParameters and: 'the service returns the desired results' - mockNetworkCmProxyDataService.executeCmHandleIdSearchForInventory(cmHandleQueryServiceParameters) >> serviceMockResponse + mockNetworkCmProxyInventoryFacade.executeParameterizedCmHandleIdSearch(cmHandleQueryServiceParameters) >> serviceMockResponse when: 'post request is performed & search is called with the given request parameters' def response = mvc.perform( post("$ncmpBasePathV1/ch/searches") @@ -156,7 +157,7 @@ class NetworkCmProxyInventoryControllerSpec extends Specification { given: 'the mapper service returns a converted object' ncmpRestInputMapper.toCmHandleQueryServiceParameters(_) >> cmHandleQueryServiceParameters and: 'the service returns the desired results' - mockNetworkCmProxyDataService.executeCmHandleIdSearchForInventory(cmHandleQueryServiceParameters) >> [] + mockNetworkCmProxyInventoryFacade.executeParameterizedCmHandleIdSearch(cmHandleQueryServiceParameters) >> [] when: 'post request is performed & search is called with the given request parameters' def response = mvc.perform( post("$ncmpBasePathV1/ch/searches") @@ -180,7 +181,7 @@ class NetworkCmProxyInventoryControllerSpec extends Specification { updatedCmHandles: [CmHandleRegistrationResponse.createSuccessResponse('cm-handle-2')], removedCmHandles: [CmHandleRegistrationResponse.createSuccessResponse('cm-handle-3')] ) - mockNetworkCmProxyDataService.updateDmiRegistrationAndSyncModule(*_) >> dmiRegistrationResponse + mockNetworkCmProxyInventoryFacade.updateDmiRegistrationAndSyncModule(*_) >> dmiRegistrationResponse when: 'registration endpoint is invoked' def response = mvc.perform( post("$ncmpBasePathV1/ch") @@ -204,7 +205,7 @@ class NetworkCmProxyInventoryControllerSpec extends Specification { removedCmHandles: [removeCmHandleResponse], upgradedCmHandles: [upgradeCmHandleResponse] ) - mockNetworkCmProxyDataService.updateDmiRegistrationAndSyncModule(*_) >> dmiRegistrationResponse + mockNetworkCmProxyInventoryFacade.updateDmiRegistrationAndSyncModule(*_) >> dmiRegistrationResponse when: 'registration endpoint is invoked' def response = mvc.perform( post("$ncmpBasePathV1/ch") @@ -237,7 +238,7 @@ class NetworkCmProxyInventoryControllerSpec extends Specification { given: 'an endpoint for returning cm handle IDs for a registered dmi plugin' def getUrl = "$ncmpBasePathV1/ch/cmHandles?dmi-plugin-identifier=some-dmi-plugin-identifier" and: 'a collection of cm handle IDs are returned' - 1 * mockNetworkCmProxyDataService.getAllCmHandleIdsByDmiPluginIdentifier('some-dmi-plugin-identifier') + 1 * mockNetworkCmProxyInventoryFacade.getAllCmHandleIdsByDmiPluginIdentifier('some-dmi-plugin-identifier') >> ['cm-handle-id-1','cm-handle-id-2'] when: 'the endpoint is invoked' def response = mvc.perform( diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandlerSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyRestExceptionHandlerSpec.groovy index 33eb48ffa2..9d36d106c7 100644 --- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandlerSpec.groovy +++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyRestExceptionHandlerSpec.groovy @@ -19,33 +19,28 @@ * ============LICENSE_END========================================================= */ -package org.onap.cps.ncmp.rest.exceptions - -import static org.springframework.http.HttpStatus.BAD_GATEWAY -import static org.springframework.http.HttpStatus.BAD_REQUEST -import static org.springframework.http.HttpStatus.CONFLICT -import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR -import static org.springframework.http.HttpStatus.NOT_FOUND -import static org.springframework.http.HttpStatus.PAYLOAD_TOO_LARGE -import static org.onap.cps.ncmp.rest.exceptions.NetworkCmProxyRestExceptionHandlerSpec.ApiType.NCMP -import static org.onap.cps.ncmp.rest.exceptions.NetworkCmProxyRestExceptionHandlerSpec.ApiType.NCMPINVENTORY -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post -import static org.onap.cps.ncmp.api.NcmpResponseStatus.UNABLE_TO_READ_RESOURCE_DATA +package org.onap.cps.ncmp.rest.controller import groovy.json.JsonSlurper import org.mapstruct.factory.Mappers import org.onap.cps.TestUtils -import org.onap.cps.ncmp.api.NetworkCmProxyDataService -import org.onap.cps.ncmp.api.impl.exception.DmiRequestException -import org.onap.cps.ncmp.api.impl.exception.DmiClientRequestException -import org.onap.cps.ncmp.api.impl.exception.ServerNcmpException -import org.onap.cps.ncmp.rest.controller.NcmpRestInputMapper -import org.onap.cps.ncmp.rest.controller.handlers.NcmpCachedResourceRequestHandler -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.api.data.exceptions.InvalidOperationException +import org.onap.cps.ncmp.api.data.exceptions.OperationNotSupportedException +import org.onap.cps.ncmp.api.exceptions.DmiClientRequestException +import org.onap.cps.ncmp.api.exceptions.DmiRequestException +import org.onap.cps.ncmp.api.exceptions.PayloadTooLargeException +import org.onap.cps.ncmp.api.exceptions.PolicyExecutorException +import org.onap.cps.ncmp.api.exceptions.ServerNcmpException +import org.onap.cps.ncmp.api.inventory.NetworkCmProxyInventoryFacade +import org.onap.cps.ncmp.impl.data.NcmpCachedResourceRequestHandler +import org.onap.cps.ncmp.impl.data.NcmpPassthroughResourceRequestHandler +import org.onap.cps.ncmp.impl.data.NetworkCmProxyFacade +import org.onap.cps.ncmp.impl.data.policyexecutor.PolicyExecutor +import org.onap.cps.ncmp.impl.inventory.InventoryPersistence +import org.onap.cps.ncmp.rest.util.CmHandleStateMapper +import org.onap.cps.ncmp.rest.util.DataOperationRequestMapper import org.onap.cps.ncmp.rest.util.DeprecationHelper +import org.onap.cps.ncmp.rest.util.NcmpRestInputMapper import org.onap.cps.spi.exceptions.AlreadyDefinedException import org.onap.cps.spi.exceptions.CpsException import org.onap.cps.spi.exceptions.DataNodeNotFoundException @@ -60,6 +55,18 @@ import org.springframework.test.web.servlet.MockMvc import spock.lang.Shared import spock.lang.Specification +import static org.onap.cps.ncmp.api.NcmpResponseStatus.UNABLE_TO_READ_RESOURCE_DATA +import static org.onap.cps.ncmp.rest.controller.NetworkCmProxyRestExceptionHandlerSpec.ApiType.NCMP +import static org.onap.cps.ncmp.rest.controller.NetworkCmProxyRestExceptionHandlerSpec.ApiType.NCMPINVENTORY +import static org.springframework.http.HttpStatus.BAD_GATEWAY +import static org.springframework.http.HttpStatus.BAD_REQUEST +import static org.springframework.http.HttpStatus.CONFLICT +import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR +import static org.springframework.http.HttpStatus.NOT_FOUND +import static org.springframework.http.HttpStatus.PAYLOAD_TOO_LARGE +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post + @WebMvcTest class NetworkCmProxyRestExceptionHandlerSpec extends Specification { @@ -67,7 +74,13 @@ class NetworkCmProxyRestExceptionHandlerSpec extends Specification { MockMvc mvc @SpringBean - NetworkCmProxyDataService mockNetworkCmProxyDataService = Mock() + NetworkCmProxyFacade mockNetworkCmProxyFacade = Mock() + + @SpringBean + NetworkCmProxyInventoryFacade mockNetworkCmProxyInventoryFacade = Mock() + + @SpringBean + InventoryPersistence mockInventoryPersistence = Mock() @SpringBean JsonObjectMapper stubbedJsonObjectMapper = Stub() @@ -109,23 +122,26 @@ class NetworkCmProxyRestExceptionHandlerSpec extends Specification { dataNodeBaseEndpointNcmpInventory = "$basePathNcmpInventory/v1" } - def 'Get request with #scenario exception returns correct HTTP Status with #scenario'() { + def 'Get request with #scenario exception returns correct HTTP Status with #scenario exception'() { when: 'an exception is thrown by the service' setupTestException(exception, NCMP) def response = performTestRequest(NCMP) then: 'an HTTP response is returned with correct message and details' assertTestResponse(response, expectedErrorCode, expectedErrorMessage, expectedErrorDetails) where: - scenario | exception || expectedErrorCode | expectedErrorMessage | expectedErrorDetails - 'CPS' | new CpsException(sampleErrorMessage, sampleErrorDetails) || INTERNAL_SERVER_ERROR | sampleErrorMessage | sampleErrorDetails - 'NCMP-server' | new ServerNcmpException(sampleErrorMessage, sampleErrorDetails) || INTERNAL_SERVER_ERROR | sampleErrorMessage | null - 'NCMP-client' | new DmiRequestException(sampleErrorMessage, sampleErrorDetails) || BAD_REQUEST | sampleErrorMessage | null - 'DataNode Validation' | new DataNodeNotFoundException('myDataspaceName', 'myAnchorName') || NOT_FOUND | 'DataNode not found' | null - 'other' | new IllegalStateException(sampleErrorMessage) || INTERNAL_SERVER_ERROR | sampleErrorMessage | null - 'Data Node Not Found' | new DataNodeNotFoundException('myDataspaceName', 'myAnchorName') || NOT_FOUND | 'DataNode not found' | 'DataNode not found' - 'Existing entry' | new AlreadyDefinedException('name',null) || CONFLICT | 'Already defined exception' | 'name already exists' - 'Existing entries' | AlreadyDefinedException.forDataNodes(['A', 'B'], 'myAnchorName') || CONFLICT | 'Already defined exception' | '2 data node(s) already exist' - 'Operation too large' | new PayloadTooLargeException(sampleErrorMessage) || PAYLOAD_TOO_LARGE | sampleErrorMessage | 'Check logs' + scenario | exception || expectedErrorCode | expectedErrorMessage | expectedErrorDetails + 'CPS' | new CpsException(sampleErrorMessage, sampleErrorDetails) || INTERNAL_SERVER_ERROR | sampleErrorMessage | sampleErrorDetails + 'NCMP-server' | new ServerNcmpException(sampleErrorMessage, sampleErrorDetails) || INTERNAL_SERVER_ERROR | sampleErrorMessage | null + 'DMI Request' | new DmiRequestException(sampleErrorMessage, sampleErrorDetails) || BAD_REQUEST | sampleErrorMessage | null + 'Invalid Operation' | new InvalidOperationException('some reason') || BAD_REQUEST | 'some reason' | null + 'Unsupported Operation' | new OperationNotSupportedException('not yet') || BAD_REQUEST | 'not yet' | null + 'DataNode Validation' | new DataNodeNotFoundException('myDataspaceName', 'myAnchorName') || NOT_FOUND | 'DataNode not found' | null + 'other' | new IllegalStateException(sampleErrorMessage) || INTERNAL_SERVER_ERROR | sampleErrorMessage | null + 'Data Node Not Found' | new DataNodeNotFoundException('myDataspaceName', 'myAnchorName') || NOT_FOUND | 'DataNode not found' | 'DataNode not found' + 'Existing entry' | new AlreadyDefinedException('name',null) || CONFLICT | 'Already defined exception' | 'name already exists' + 'Existing entries' | AlreadyDefinedException.forDataNodes(['A', 'B'], 'myAnchorName') || CONFLICT | 'Already defined exception' | '2 data node(s) already exist' + 'Operation too large' | new PayloadTooLargeException(sampleErrorMessage) || PAYLOAD_TOO_LARGE | sampleErrorMessage | 'Check logs' + 'Policy Executor' | new PolicyExecutorException(sampleErrorMessage, sampleErrorDetails) || CONFLICT | sampleErrorMessage | sampleErrorDetails } def 'Post request with exception returns correct HTTP Status.'() { @@ -152,9 +168,9 @@ class NetworkCmProxyRestExceptionHandlerSpec extends Specification { def setupTestException(exception, apiType) { if (NCMP == apiType) { - mockNetworkCmProxyDataService.getYangResourcesModuleReferences(*_) >> { throw exception } + mockNetworkCmProxyInventoryFacade.getYangResourcesModuleReferences(*_) >> { throw exception } } - mockNetworkCmProxyDataService.updateDmiRegistrationAndSyncModule(*_) >> { throw exception } + mockNetworkCmProxyInventoryFacade.updateDmiRegistrationAndSyncModule(*_) >> { throw exception } } def performTestRequest(apiType) { @@ -173,8 +189,5 @@ class NetworkCmProxyRestExceptionHandlerSpec extends Specification { assert expectedErrorDetails == null || content['details'].toString().contains(expectedErrorDetails) } - enum ApiType { - NCMP, - NCMPINVENTORY; - } + enum ApiType { NCMP, NCMPINVENTORY } } diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreRequestHandlerSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreRequestHandlerSpec.groovy deleted file mode 100644 index 00b0cb04c5..0000000000 --- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreRequestHandlerSpec.groovy +++ /dev/null @@ -1,152 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2023-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 org.onap.cps.ncmp.api.NetworkCmProxyDataService -import org.onap.cps.ncmp.api.impl.exception.InvalidDatastoreException -import org.onap.cps.ncmp.api.impl.exception.InvalidOperationException -import org.onap.cps.ncmp.api.models.DataOperationDefinition -import org.onap.cps.ncmp.api.models.DataOperationRequest -import org.onap.cps.ncmp.api.models.CmResourceAddress -import org.onap.cps.ncmp.rest.exceptions.OperationNotSupportedException -import org.onap.cps.ncmp.rest.exceptions.PayloadTooLargeException -import org.springframework.http.HttpStatus -import reactor.core.publisher.Mono -import spock.lang.Specification -import spock.util.concurrent.PollingConditions - -class NcmpDatastoreRequestHandlerSpec extends Specification { - - def mockNetworkCmProxyDataService = Mock(NetworkCmProxyDataService) - - def objectUnderTest = new NcmpPassthroughResourceRequestHandler(mockNetworkCmProxyDataService) - - def NO_AUTH_HEADER = null - - def setup() { - objectUnderTest.timeOutInMilliSeconds = 100 - } - - def 'Attempt to execute async get request with #scenario.'() { - given: 'notification feature is turned on/off' - objectUnderTest.notificationFeatureEnabled = notificationFeatureEnabled - and: 'a CM resource address' - def cmResourceAddress = new CmResourceAddress('ds', 'ch1', 'resource1') - and: 'the (mocked) service is called with the correct parameters returns OK' - 1 * mockNetworkCmProxyDataService.getResourceDataForCmHandle(cmResourceAddress, 'options', _, _, NO_AUTH_HEADER) >> Mono.just(HttpStatus.OK) - when: 'get request is executed with topic = #topic' - def response= objectUnderTest.executeRequest(cmResourceAddress, 'options', topic, false, NO_AUTH_HEADER) - then: 'a successful response with/without request id is returned' - assert response.statusCode.value == 200 - assert response.body instanceof Map == expectedResponseBodyIsMap - where: 'the following parameters are used' - scenario | notificationFeatureEnabled | topic || expectedCalls | expectedResponseBodyIsMap - 'feature on, valid topic' | true | 'valid' || 1 | true - 'feature on, no topic' | true | null || 0 | false - 'feature off, valid topic' | false | 'valid' || 0 | false - 'feature off, no topic' | false | null || 0 | false - } - - def 'Attempt to execute async data operation request with feature #scenario.'() { - given: 'a extended request handler that supports bulk requests' - def objectUnderTest = new NcmpPassthroughResourceRequestHandler(mockNetworkCmProxyDataService) - and: 'notification feature is turned on/off' - objectUnderTest.notificationFeatureEnabled = notificationFeatureEnabled - when: 'data operation request is executed' - objectUnderTest.executeRequest('someTopic', new DataOperationRequest(), NO_AUTH_HEADER) - then: 'the task is executed in an async fashion or not' - expectedCalls * mockNetworkCmProxyDataService.executeDataOperationForCmHandles('someTopic', _, _, null) - where: 'the following parameters are used' - scenario | notificationFeatureEnabled || expectedCalls - 'on' | true || 1 - 'off' | false || 0 - } - - def 'Execute async data operation request with datastore #datastore.'() { - given: 'notification feature is turned on' - objectUnderTest.notificationFeatureEnabled = true - and: 'a data operation request with datastore: #datastore' - def dataOperationDefinition = new DataOperationDefinition(operation: 'read', datastore: datastore) - def dataOperationRequest = new DataOperationRequest(dataOperationDefinitions: [dataOperationDefinition]) - and: ' a flag to track the network service call' - def networkServiceMethodCalled = false - and: 'the (mocked) service will use the flag to indicate it is called' - mockNetworkCmProxyDataService.executeDataOperationForCmHandles('myTopic', dataOperationRequest, _, NO_AUTH_HEADER) >> { - networkServiceMethodCalled = true - } - when: 'data operation request is executed' - def response = objectUnderTest.executeRequest('myTopic', dataOperationRequest, NO_AUTH_HEADER) - and: 'a successful response with request id is returned' - assert response.statusCode.value == 200 - assert response.body.requestId != null - then: 'the network service is invoked' - new PollingConditions().within(1) { - assert networkServiceMethodCalled == true - } - where: 'the following datastores are used' - datastore << ['ncmp-datastore:passthrough-running', 'ncmp-datastore:passthrough-operational'] - } - - def 'Attempt to execute async data operation request with error #scenario'() { - given: 'a data operation definition with datastore: #datastore' - def dataOperationDefinition = new DataOperationDefinition(operation: 'read', datastore: datastore) - when: 'data operation request is executed' - def dataOperationRequest = new DataOperationRequest(dataOperationDefinitions: [dataOperationDefinition]) - objectUnderTest.executeRequest('myTopic', dataOperationRequest, NO_AUTH_HEADER) - then: 'the correct error is thrown' - def thrown = thrown(InvalidDatastoreException) - assert thrown.message.contains(expectedErrorMessage) - where: 'the following datastore names are used' - scenario | datastore || expectedErrorMessage - 'unsupported datastore' | 'ncmp-datastore:operational' || 'not supported' - 'invalid datastore' | 'invalid' || 'invalid datastore name' - } - - def 'Attempt to execute async data operation request with #scenario operation: #operation.'() { - given: 'a data operation definition with operation: #operation' - def dataOperationDefinition = new DataOperationDefinition(operation: operation, datastore: 'ncmp-datastore:passthrough-running') - when: 'data operation request is executed' - objectUnderTest.executeRequest('someTopic', new DataOperationRequest(dataOperationDefinitions:[dataOperationDefinition]), NO_AUTH_HEADER) - then: 'the expected type of exception is thrown' - thrown(expectedException) - where: 'the following operations are used' - scenario | operation || expectedException - 'invalid' | 'invalid' || InvalidOperationException - 'unsupported' | 'create' || OperationNotSupportedException - 'unsupported' | 'update' || OperationNotSupportedException - 'unsupported' | 'patch' || OperationNotSupportedException - 'unsupported' | 'delete' || OperationNotSupportedException - } - - def 'Attempt to execute async data operation request with too many cm handles.'() { - given: 'a data operation definition with too many cm handles' - def tooMany = objectUnderTest.MAXIMUM_CM_HANDLES_PER_OPERATION+1 - def cmHandleIds = new String[tooMany] - def dataOperationDefinition = new DataOperationDefinition(operationId: 'abc', operation: 'read', datastore: 'ncmp-datastore:passthrough-running', cmHandleIds: cmHandleIds) - when: 'data operation request is executed' - objectUnderTest.executeRequest('someTopic', new DataOperationRequest(dataOperationDefinitions:[dataOperationDefinition]), NO_AUTH_HEADER) - then: 'a payload too large exception is thrown' - def exceptionThrown = thrown(PayloadTooLargeException) - and: 'the error message contains the offending number of cm handles' - assert exceptionThrown.message == "Operation 'abc' affects too many (${tooMany}) cm handles" - } - -} diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/mapper/CmHandleStateMapperSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/util/CmHandleStateMapperSpec.groovy index b5f7f0edeb..24f45ad8a1 100644 --- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/mapper/CmHandleStateMapperSpec.groovy +++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/util/CmHandleStateMapperSpec.groovy @@ -18,21 +18,22 @@ * ============LICENSE_END========================================================= */ -package org.onap.cps.ncmp.rest.mapper - -import static org.onap.cps.ncmp.api.impl.inventory.LockReasonCategory.LOCKED_MISBEHAVING -import static org.onap.cps.ncmp.api.impl.inventory.LockReasonCategory.MODULE_SYNC_FAILED +package org.onap.cps.ncmp.rest.util import org.mapstruct.factory.Mappers -import org.onap.cps.ncmp.api.impl.inventory.CmHandleState -import org.onap.cps.ncmp.api.impl.inventory.CompositeStateBuilder +import org.onap.cps.ncmp.api.inventory.models.CompositeStateBuilder +import org.onap.cps.ncmp.impl.inventory.DataStoreSyncState +import org.onap.cps.ncmp.impl.inventory.models.CmHandleState import org.onap.cps.ncmp.rest.model.CmHandleCompositeState -import org.onap.cps.ncmp.api.impl.inventory.DataStoreSyncState import spock.lang.Specification + import java.time.OffsetDateTime import java.time.ZoneOffset import java.time.format.DateTimeFormatter +import static org.onap.cps.ncmp.impl.inventory.models.LockReasonCategory.LOCKED_MISBEHAVING +import static org.onap.cps.ncmp.impl.inventory.models.LockReasonCategory.MODULE_SYNC_FAILED + class CmHandleStateMapperSpec extends Specification { def formattedDateAndTime = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ") diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/util/DeprecationHelperSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/util/DeprecationHelperSpec.groovy index 8c212d3531..b63cd7a802 100644 --- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/util/DeprecationHelperSpec.groovy +++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/util/DeprecationHelperSpec.groovy @@ -21,8 +21,8 @@ package org.onap.cps.ncmp.rest.util import com.fasterxml.jackson.databind.ObjectMapper -import org.onap.cps.ncmp.api.models.CmHandleQueryApiParameters -import org.onap.cps.ncmp.api.models.ConditionApiProperties +import org.onap.cps.ncmp.api.inventory.models.CmHandleQueryApiParameters +import org.onap.cps.ncmp.api.inventory.models.ConditionApiProperties import org.onap.cps.ncmp.rest.model.CmHandleQueryParameters import org.onap.cps.ncmp.rest.model.ConditionProperties import org.onap.cps.ncmp.rest.model.ModuleNameAsJsonObject diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapperSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/util/NcmpRestInputMapperSpec.groovy index b5f61adc58..3fd7e40345 100644 --- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapperSpec.groovy +++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/util/NcmpRestInputMapperSpec.groovy @@ -18,18 +18,18 @@ * ============LICENSE_END========================================================= */ -package org.onap.cps.ncmp.rest.controller +package org.onap.cps.ncmp.rest.util import org.mapstruct.factory.Mappers -import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevel -import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle +import org.onap.cps.ncmp.api.inventory.models.CmHandleQueryServiceParameters +import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle +import org.onap.cps.ncmp.api.inventory.models.TrustLevel import org.onap.cps.ncmp.rest.model.CmHandleQueryParameters import org.onap.cps.ncmp.rest.model.ConditionProperties import org.onap.cps.ncmp.rest.model.RestDmiPluginRegistration import org.onap.cps.ncmp.rest.model.RestInputCmHandle import org.onap.cps.ncmp.rest.model.RestModuleDefinition import org.onap.cps.ncmp.rest.model.RestModuleReference -import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters import org.onap.cps.spi.model.ModuleDefinition import org.onap.cps.spi.model.ModuleReference import spock.lang.Specification diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/util/TopicValidatorSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/util/TopicValidatorSpec.groovy deleted file mode 100644 index 15e2c1c6a0..0000000000 --- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/util/TopicValidatorSpec.groovy +++ /dev/null @@ -1,46 +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.util - -import org.onap.cps.ncmp.rest.exceptions.InvalidTopicException -import spock.lang.Specification - -class TopicValidatorSpec extends Specification { - - def 'Valid topic name validation.'() { - when: 'a valid topic name is validated' - TopicValidator.validateTopicName('my-valid-topic') - then: 'no exception is thrown' - noExceptionThrown() - } - - def 'Validating invalid topic names.'() { - when: 'the invalid topic name is validated' - TopicValidator.validateTopicName(topicName) - then: 'boolean response will be returned for #scenario' - thrown(InvalidTopicException) - where: 'the following names are used' - scenario | topicName - 'empty topic' | '' - 'blank topic' | ' ' - 'invalid non empty topic' | '1_5_*_#' - } -} diff --git a/cps-ncmp-rest/src/test/resources/application.yml b/cps-ncmp-rest/src/test/resources/application.yml index 9df1e580f6..aa5716716b 100644 --- a/cps-ncmp-rest/src/test/resources/application.yml +++ b/cps-ncmp-rest/src/test/resources/application.yml @@ -26,4 +26,4 @@ notification: enabled: true async: executor: - time-out-value-in-ms: 2000
\ No newline at end of file + time-out-value-in-ms: 2000 |