From c309f24909510ebd11737efc3eadb055c91e304e Mon Sep 17 00:00:00 2001 From: niamhcore Date: Tue, 7 Sep 2021 10:27:18 +0100 Subject: P2 - Get module names and revisions rest layer Issue-ID: CPS-485 Signed-off-by: niamhcore Change-Id: I1bcf45902207d0dba6b5dfe8277cb06571694db3 --- cps-ncmp-rest/docs/openapi/ncmproxy.yml | 27 ++++++++++++++++++++++ cps-ncmp-rest/docs/openapi/openapi.yml | 5 +++- .../rest/controller/NetworkCmProxyController.java | 8 +++++++ .../controller/NetworkCmProxyControllerSpec.groovy | 16 +++++++++++++ .../cps/ncmp/api/NetworkCmProxyDataService.java | 9 ++++++++ .../api/impl/NetworkCmProxyDataServiceImpl.java | 7 +++++- .../impl/NetworkCmProxyDataServiceImplSpec.groovy | 2 +- .../spi/impl/CpsModulePersistenceServiceImpl.java | 4 ++-- ...sModulePersistenceServiceIntegrationSpec.groovy | 4 ++-- .../java/org/onap/cps/api/CpsModuleService.java | 13 +++++++++-- .../onap/cps/api/impl/CpsModuleServiceImpl.java | 9 ++++++-- .../onap/cps/spi/CpsModulePersistenceService.java | 9 ++++---- .../cps/api/impl/CpsModuleServiceImplSpec.groovy | 14 +++++++++-- 13 files changed, 109 insertions(+), 18 deletions(-) diff --git a/cps-ncmp-rest/docs/openapi/ncmproxy.yml b/cps-ncmp-rest/docs/openapi/ncmproxy.yml index 138337d24..5e2957f34 100755 --- a/cps-ncmp-rest/docs/openapi/ncmproxy.yml +++ b/cps-ncmp-rest/docs/openapi/ncmproxy.yml @@ -279,5 +279,32 @@ resourceDataForPassthroughRunning: $ref: 'components.yaml#/components/responses/Unauthorized' 403: $ref: 'components.yaml#/components/responses/Forbidden' + 404: + $ref: 'components.yaml#/components/responses/NotFound' + +fetchModuleReferencesByCmHandle: + get: + description: fetch all module references (name and revision) for a given cm handle + tags: + - network-cm-proxy + summary: Fetch all module references (name and revision) for a given cm handle + operationId: getModuleReferencesByCmHandle + parameters: + - $ref: 'components.yaml#/components/parameters/cmHandleInPath' + responses: + 200: + description: OK + content: + application/json: + schema: + type: string + example: [{"moduleName": "nc-notifications", "revision": "2008-07-14"}] + $ref: 'components.yaml#/components/responses/Ok' + 400: + $ref: 'components.yaml#/components/responses/BadRequest' + 401: + $ref: 'components.yaml#/components/responses/Unauthorized' + 403: + $ref: 'components.yaml#/components/responses/Forbidden' 404: $ref: 'components.yaml#/components/responses/NotFound' \ No newline at end of file diff --git a/cps-ncmp-rest/docs/openapi/openapi.yml b/cps-ncmp-rest/docs/openapi/openapi.yml index 8d8684a35..12356b588 100755 --- a/cps-ncmp-rest/docs/openapi/openapi.yml +++ b/cps-ncmp-rest/docs/openapi/openapi.yml @@ -45,4 +45,7 @@ paths: $ref: 'ncmproxy.yml#/getResourceDataForPassthroughOperational' /v1/ch/{cm-handle}/data/ds/ncmp-datastore:passthrough-running/{resourceIdentifier}: - $ref: 'ncmproxy.yml#/resourceDataForPassthroughRunning' \ No newline at end of file + $ref: 'ncmproxy.yml#/resourceDataForPassthroughRunning' + + /v1/ch/{cm-handle}/modules: + $ref: 'ncmproxy.yml#/fetchModuleReferencesByCmHandle' \ No newline at end of file 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 f5ffdbeb9..b78241662 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 @@ -35,6 +35,7 @@ import org.onap.cps.ncmp.rest.api.NetworkCmProxyApi; import org.onap.cps.ncmp.rest.model.RestDmiPluginRegistration; import org.onap.cps.spi.FetchDescendantsOption; import org.onap.cps.spi.model.DataNode; +import org.onap.cps.spi.model.ModuleReference; import org.onap.cps.utils.DataMapUtils; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -220,6 +221,13 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { return new ResponseEntity<>(HttpStatus.CREATED); } + @Override + public ResponseEntity getModuleReferencesByCmHandle(final String cmHandle) { + final Collection + moduleReferences = networkCmProxyDataService.getYangResourcesModuleReferences(cmHandle); + return new ResponseEntity<>(new Gson().toJson(moduleReferences), HttpStatus.OK); + } + private DmiPluginRegistration convertRestObjectToJavaApiObject( final RestDmiPluginRegistration restDmiPluginRegistration) { return objectMapper.convertValue(restDmiPluginRegistration, DmiPluginRegistration.class); 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 73ccd6e3c..613243e28 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 @@ -22,6 +22,8 @@ package org.onap.cps.ncmp.rest.controller +import org.onap.cps.spi.model.ModuleReference + 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.get @@ -246,5 +248,19 @@ class NetworkCmProxyControllerSpec extends Specification { and: 'resource is created' response.status == HttpStatus.CREATED.value() } + + def 'Get module references for the given dataspace and cm handle.' () { + given: 'get module references url' + def getUrl = "$ncmpBasePathV1/ch/some-cmhandle/modules" + 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: 'some-revision1')] + and: 'response contains an array with the module name and revision' + response.getContentAsString() == '[{"moduleName":"some-name1","revision":"some-revision1"}]' + and: 'response returns an OK http code' + response.status == HttpStatus.OK.value() + } } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java index 0693f61e4..60669b916 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java @@ -28,6 +28,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.onap.cps.ncmp.api.models.DmiPluginRegistration; import org.onap.cps.spi.FetchDescendantsOption; import org.onap.cps.spi.model.DataNode; +import org.onap.cps.spi.model.ModuleReference; /* * Datastore interface for handling CPS data. @@ -154,4 +155,12 @@ public interface NetworkCmProxyDataService { @NotNull String resourceIdentifier, @NotNull Object requestBody, String contentType); + + /** + * Retrieve module references for the given cm handle. + * + * @param cmHandle cm handle + * @return a collection of modules names and revisions + */ + Collection getYangResourcesModuleReferences(@NotNull String cmHandle); } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java index 6e1e7275b..871d8806b 100755 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java @@ -223,6 +223,11 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService handleResponseForPost(responseEntity); } + @Override + public Collection getYangResourcesModuleReferences(final String cmHandle) { + return cpsModuleService.getYangResourcesModuleReferences(NF_PROXY_DATASPACE_NAME, cmHandle); + } + private DataNode fetchDataNodeFromDmiRegistryForCmHandle(final String cmHandle) { final String xpathForDmiRegistryToFetchCmHandle = "/dmi-registry/cm-handles[@id='" + cmHandle + "']"; return cpsDataService.getDataNode(NCMP_DATASPACE_NAME, @@ -352,7 +357,7 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService final List moduleReferencesFromDmiForCmHandle = getModuleReferences(modulesForCmHandle); final var knownModuleReferencesInCps = - cpsModuleService.getAllYangResourceModuleReferences(NF_PROXY_DATASPACE_NAME); + cpsModuleService.getYangResourceModuleReferences(NF_PROXY_DATASPACE_NAME); final List existingModuleReferences = new ArrayList<>(); for (final ModuleReference moduleReferenceFromDmiForCmHandle : moduleReferencesFromDmiForCmHandle) { diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy index ff3e0cd15..e94544225 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy @@ -360,7 +360,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { def knownModule1 = new ModuleReference('module1', '1') def knownOtherModule = new ModuleReference('some other module', 'some revision') and: 'CPS-Core returns list of known modules' - mockCpsModuleService.getAllYangResourceModuleReferences(_) >> [knownModule1, knownOtherModule] + mockCpsModuleService.getYangResourceModuleReferences(_) >> [knownModule1, knownOtherModule] and: 'DMI-Plugin returns resource(s) for "new" module(s)' def moduleResources = new ResponseEntity(sdncReponseBody, HttpStatus.OK) mockDmiOperations.getResourceFromDmi(_, cmHandleForModelSync.getId(), 'moduleResources') >> moduleResources diff --git a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java index d7b882f6e..e0f54265a 100755 --- a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java +++ b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java @@ -116,7 +116,7 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ } @Override - public Collection getAllYangResourceModuleReferences(final String dataspaceName) { + public Collection getYangResourceModuleReferences(final String dataspaceName) { final Set yangResourceModuleReferenceList = yangResourceRepository.findAllModuleReferences(dataspaceName); return yangResourceModuleReferenceList.stream().map(CpsModulePersistenceServiceImpl::toModuleReference) @@ -124,7 +124,7 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ } @Override - public Collection getAllYangResourceModuleReferences(final String dataspaceName, + public Collection getYangResourceModuleReferences(final String dataspaceName, final String anchorName) { final Set yangResourceModuleReferenceList = yangResourceRepository diff --git a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsModulePersistenceServiceIntegrationSpec.groovy b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsModulePersistenceServiceIntegrationSpec.groovy index a139830a2..7e4220079 100644 --- a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsModulePersistenceServiceIntegrationSpec.groovy +++ b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsModulePersistenceServiceIntegrationSpec.groovy @@ -140,7 +140,7 @@ class CpsModulePersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase given: 'a dataspace name' def dataspaceName = 'DATASPACE-002' when: 'all yang resources module references are retrieved for the given dataspace name' - def result = objectUnderTest.getAllYangResourceModuleReferences(dataspaceName) + def result = objectUnderTest.getYangResourceModuleReferences(dataspaceName) then: 'the correct resources are returned' result.sort() == [new ModuleReference(moduleName: 'MODULE-NAME-005', revision: 'REVISION-002'), new ModuleReference(moduleName: 'MODULE-NAME-006', revision: 'REVISION-006')] @@ -152,7 +152,7 @@ class CpsModulePersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase def dataspaceName = 'DATASPACE-001' def anchorName = 'ANCHOR1' when: 'all yang resources module references are retrieved for the given anchor' - def result = objectUnderTest.getAllYangResourceModuleReferences(dataspaceName, anchorName) + def result = objectUnderTest.getYangResourceModuleReferences(dataspaceName, anchorName) then: 'the correct module names and revisions are returned' result.sort() == [new ModuleReference(moduleName: null, revision: null), new ModuleReference(moduleName: 'MODULE-NAME-002', revision: 'REVISION-002'), new ModuleReference(moduleName: 'MODULE-NAME-003', revision: 'REVISION-002'), diff --git a/cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java b/cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java index 218a236f1..1dccf49c9 100644 --- a/cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java +++ b/cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java @@ -81,10 +81,19 @@ public interface CpsModuleService { @NonNull CascadeDeleteAllowed cascadeDeleteAllowed); /** - * Retrieve all modules and revisions known by CPS for all Yang Resources. + * Retrieve module references for the given dataspace name. * * @param dataspaceName dataspace name * @return a list of ModuleReference objects */ - Collection getAllYangResourceModuleReferences(final String dataspaceName); + Collection getYangResourceModuleReferences(String dataspaceName); + + /** + * Retrieve module references for the given dataspace name and anchor name. + * + * @param dataspaceName dataspace name + * @param anchorName anchor name + * @return a list of ModuleReference objects + */ + Collection getYangResourcesModuleReferences(String dataspaceName, String anchorName); } diff --git a/cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java b/cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java index 17ad78cbe..10326413c 100644 --- a/cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java +++ b/cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java @@ -75,8 +75,13 @@ public class CpsModuleServiceImpl implements CpsModuleService { } @Override - public Collection getAllYangResourceModuleReferences(final String dataspaceName) { - return cpsModulePersistenceService.getAllYangResourceModuleReferences(dataspaceName); + public Collection getYangResourceModuleReferences(final String dataspaceName) { + return cpsModulePersistenceService.getYangResourceModuleReferences(dataspaceName); } + @Override + public Collection getYangResourcesModuleReferences(final String dataspaceName, + final String anchorName) { + return cpsModulePersistenceService.getYangResourceModuleReferences(dataspaceName, anchorName); + } } diff --git a/cps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java b/cps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java index 4f46c0dac..9b50f9e91 100755 --- a/cps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java +++ b/cps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java @@ -90,20 +90,19 @@ public interface CpsModulePersistenceService { @NonNull String anchorName); /** - * Returns all YANG resources module references for the given dataspace name. + * Returns YANG resources module references for the given dataspace name. * * @param dataspaceName dataspace name * @return Collection of all YANG resources module information in the database */ - Collection getAllYangResourceModuleReferences(final String dataspaceName); + Collection getYangResourceModuleReferences(String dataspaceName); /** - * Get all YANG resource module references for the given anchor name and dataspace name. + * Get YANG resource module references for the given anchor name and dataspace name. * * @param dataspaceName dataspace name * @param anchorName anchor name * @return a collection of module names and revisions */ - Collection getAllYangResourceModuleReferences(final String dataspaceName, - final String anchorName); + Collection getYangResourceModuleReferences(String dataspaceName, String anchorName); } diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy index 31df479e4..2c23aa1bc 100644 --- a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy @@ -26,6 +26,7 @@ import org.onap.cps.TestUtils import org.onap.cps.spi.CpsModulePersistenceService import org.onap.cps.spi.exceptions.ModelValidationException import org.onap.cps.spi.model.ExtendedModuleReference +import org.onap.cps.spi.model.ModuleReference import org.spockframework.spring.SpringBean import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.context.SpringBootTest @@ -118,8 +119,17 @@ class CpsModuleServiceImplSpec extends Specification { def 'Get all yang resources module references.'(){ given: 'an already present module reference' def moduleReferences = [new ExtendedModuleReference()] - mockModuleStoreService.getAllYangResourceModuleReferences('someDataspaceName') >> moduleReferences + mockModuleStoreService.getYangResourceModuleReferences('someDataspaceName') >> moduleReferences expect: 'the list provided by persistence service is returned as result' - objectUnderTest.getAllYangResourceModuleReferences('someDataspaceName') == moduleReferences + objectUnderTest.getYangResourceModuleReferences('someDataspaceName') == moduleReferences + } + + + def 'Get all yang resources module references for the given dataspace name and anchor name.'(){ + given: 'the module store service service returns a list module references' + def moduleReferences = [new ModuleReference()] + mockModuleStoreService.getYangResourceModuleReferences('someDataspaceName', 'someAnchorName') >> moduleReferences + expect: 'the list provided by persistence service is returned as result' + objectUnderTest.getYangResourcesModuleReferences('someDataspaceName', 'someAnchorName') == moduleReferences } } -- cgit 1.2.3-korg