diff options
author | emaclee <lee.anjella.macabuhay@est.tech> | 2022-06-17 17:42:56 +0100 |
---|---|---|
committer | emaclee <lee.anjella.macabuhay@est.tech> | 2022-06-30 12:08:14 +0100 |
commit | e1f73e264e2dca1f10c273620653f541c2f25d69 (patch) | |
tree | f9adc065420549de0368842ae1f4e7df30c4effe /cps-ncmp-rest | |
parent | f7c7848d4cd7654ab94d9c31b62a71ed2bc4b9e8 (diff) |
Add method to get YANG module sources for CM handle
- part of this commit includes renaming the enum SyncState to
DataStoreSyncState
Issue-ID: CPS-1064
Signed-off-by: emaclee <lee.anjella.macabuhay@est.tech>
Change-Id: I6bf419141a1b33f09871946445cdfff422c8c354
Diffstat (limited to 'cps-ncmp-rest')
9 files changed, 113 insertions, 5 deletions
diff --git a/cps-ncmp-rest/docs/openapi/components.yaml b/cps-ncmp-rest/docs/openapi/components.yaml index cf254e511e..8249a7a3d7 100644 --- a/cps-ncmp-rest/docs/openapi/components.yaml +++ b/cps-ncmp-rest/docs/openapi/components.yaml @@ -145,6 +145,30 @@ components: type: string example: my-module-revision + RestModuleDefinition: + type: object + title: Module definitions + properties: + moduleName: + type: string + example: my-module-name + revision: + type: string + example: 2020-09-15 + content: + type: string + example: | + module stores { + yang-version 1.1; + namespace "org:onap:ccsdk:sample"; + prefix book-store; + revision "2020-09-15" { + description + "Sample Model"; + } + } + + CmHandleQueryParameters: type: object title: Cm Handle query parameters for executing cm handle search diff --git a/cps-ncmp-rest/docs/openapi/ncmp.yml b/cps-ncmp-rest/docs/openapi/ncmp.yml index 8bdaa82d8c..aaf0d6a1ab 100755 --- a/cps-ncmp-rest/docs/openapi/ncmp.yml +++ b/cps-ncmp-rest/docs/openapi/ncmp.yml @@ -246,6 +246,31 @@ fetchModuleReferencesByCmHandle: 500: $ref: 'components.yaml#/components/responses/InternalServerError' +fetchModuleDefinitionsByCmHandle: + get: + description: Fetch all module definitions (name, revision, yang resource) for a given cm handle + tags: + - network-cm-proxy + summary: Fetch all module definitions (name, revision, yang resource) for a given cm handle + operationId: getModuleDefinitionsByCmHandleId + parameters: + - $ref: 'components.yaml#/components/parameters/cmHandleInPath' + responses: + 200: + description: OK + content: + application/json: + schema: + type: array + items: + $ref: 'components.yaml#/components/schemas/RestModuleDefinition' + 401: + $ref: 'components.yaml#/components/responses/Unauthorized' + 403: + $ref: 'components.yaml#/components/responses/Forbidden' + 500: + $ref: 'components.yaml#/components/responses/InternalServerError' + searchCmHandles: post: description: Execute cm handle query search, to be included in the result a cm-handle must fulfill ALL the conditions listed here, if one of the given module names does not exists, return with an empty collection. diff --git a/cps-ncmp-rest/docs/openapi/openapi.yml b/cps-ncmp-rest/docs/openapi/openapi.yml index ad7dd1d4f7..35be59a38c 100755 --- a/cps-ncmp-rest/docs/openapi/openapi.yml +++ b/cps-ncmp-rest/docs/openapi/openapi.yml @@ -35,6 +35,9 @@ paths: /v1/ch/{cm-handle}/modules: $ref: 'ncmp.yml#/fetchModuleReferencesByCmHandle' + /v1/ch/{cm-handle}/modules/definitions: + $ref: 'ncmp.yml#/fetchModuleDefinitionsByCmHandle' + /v1/ch/searches: $ref: 'ncmp.yml#/searchCmHandles' 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/controller/NcmpRestInputMapper.java index a9ec863d53..118fa45263 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/controller/NcmpRestInputMapper.java @@ -20,6 +20,7 @@ package org.onap.cps.ncmp.rest.controller; +import org.mapstruct.InheritConfiguration; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.NullValueCheckStrategy; @@ -28,7 +29,9 @@ import org.onap.cps.ncmp.api.models.DmiPluginRegistration; import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle; 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.spi.model.ModuleDefinition; import org.onap.cps.spi.model.ModuleReference; @Mapper(componentModel = "spring") @@ -52,4 +55,8 @@ public interface NcmpRestInputMapper { RestModuleReference toRestModuleReference( final ModuleReference moduleReference); + + @InheritConfiguration(name = "toRestModuleReference") + RestModuleDefinition toRestModuleDefinition( + final ModuleDefinition moduleDefinition); }
\ 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 e0488c2279..33355475d9 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 @@ -47,6 +47,7 @@ import org.onap.cps.ncmp.rest.executor.CpsNcmpTaskExecutor; import org.onap.cps.ncmp.rest.mapper.CmHandleStateMapper; import org.onap.cps.ncmp.rest.model.CmHandlePublicProperties; import org.onap.cps.ncmp.rest.model.CmHandleQueryParameters; +import org.onap.cps.ncmp.rest.model.RestModuleDefinition; import org.onap.cps.ncmp.rest.model.RestModuleReference; import org.onap.cps.ncmp.rest.model.RestOutputCmHandle; import org.onap.cps.ncmp.rest.model.RestOutputCmHandleCompositeState; @@ -290,6 +291,21 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { } /** + * Return module definitions for a cm handle. + * + * @param cmHandleId cm-handle identifier + * @return list of module definitions (module name, revision, yang resource content) + */ + @Override + public ResponseEntity<List<RestModuleDefinition>> getModuleDefinitionsByCmHandleId(final String cmHandleId) { + final List<RestModuleDefinition> restModuleDefinitions = + networkCmProxyDataService.getModuleDefinitionsByCmHandleId(cmHandleId).stream() + .map(ncmpRestInputMapper::toRestModuleDefinition) + .collect(Collectors.toList()); + return new ResponseEntity<>(restModuleDefinitions, HttpStatus.OK); + } + + /** * Return module references for a cm handle. * * @param cmHandle the cm handle 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/mapper/CmHandleStateMapper.java index 933ca88c9e..ca109d649c 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/mapper/CmHandleStateMapper.java @@ -55,7 +55,8 @@ public interface CmHandleStateMapper { if (compositeStateDataStore.getOperationalDataStore() != null) { final SyncState operationalSyncState = new SyncState(); - operationalSyncState.setState(compositeStateDataStore.getOperationalDataStore().getSyncState().name()); + operationalSyncState.setState(compositeStateDataStore.getOperationalDataStore() + .getDataStoreSyncState().name()); operationalSyncState.setLastSyncTime(compositeStateDataStore.getOperationalDataStore().getLastSyncTime()); dataStores.setOperational(operationalSyncState); } 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/controller/NcmpRestInputMapperSpec.groovy index bb762080d2..cd3770eb84 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/controller/NcmpRestInputMapperSpec.groovy @@ -24,7 +24,9 @@ import org.mapstruct.factory.Mappers import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle 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.spi.model.ModuleDefinition import org.onap.cps.spi.model.ModuleReference import spock.lang.Specification @@ -87,4 +89,19 @@ class NcmpRestInputMapperSpec extends Specification { then: 'the result is of the correct class RestModuleReference' result.class == RestModuleReference.class } + + def 'Convert a ModuleDefinition to a RestModuleDefinition'() { + given: 'a ModuleDefinition' + def moduleDefinition = new ModuleDefinition('moduleName','revision', 'content') + when: 'toRestModuleDefinition is called' + def result = objectUnderTest.toRestModuleDefinition(moduleDefinition) + then: 'the result is of the correct class RestModuleDefinition' + result.class == RestModuleDefinition.class + and: 'all contents are mapped correctly' + result.toString()=='class RestModuleDefinition {\n' + + ' moduleName: moduleName\n' + + ' revision: revision\n' + + ' content: content\n' + + '}' + } } 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 93d8358fe7..729df9ce4d 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 @@ -26,12 +26,13 @@ package org.onap.cps.ncmp.rest.controller import org.mapstruct.factory.Mappers import org.onap.cps.ncmp.api.inventory.CmHandleState import org.onap.cps.ncmp.api.inventory.CompositeState -import org.onap.cps.ncmp.api.inventory.SyncState import org.onap.cps.ncmp.api.inventory.LockReasonCategory +import org.onap.cps.ncmp.api.inventory.DataStoreSyncState import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle import org.onap.cps.ncmp.rest.mapper.CmHandleStateMapper import org.onap.cps.ncmp.rest.executor.CpsNcmpTaskExecutor import org.onap.cps.ncmp.rest.util.DeprecationHelper +import org.onap.cps.spi.model.ModuleDefinition import spock.lang.Shared import java.time.OffsetDateTime @@ -408,10 +409,24 @@ class NetworkCmProxyControllerSpec extends Specification { ':passthrough-running' | 'passthrough-running' } + def 'Get module definitions based on cmHandleId.' () { + when: 'get module definition request is performed' + def response = mvc.perform(get("$ncmpBasePathV1/ch/some-cmhandle/modules/definitions")) + .andReturn().response + then: 'ncmp service method to get module definitions is called' + mockNetworkCmProxyDataService.getModuleDefinitionsByCmHandleId('some-cmhandle') + >> [new ModuleDefinition('sampleModuleName', '2021-10-03', + String.format('module sampleModuleName{ %n sample module content %n }'))] + and: 'response contains an array with the module name, revision and content where content contains \\n for newlines' + response.getContentAsString() == '[{"moduleName":"sampleModuleName","revision":"2021-10-03","content":"module sampleModuleName{ \\n sample module content \\n }"}]' + and: 'response returns an OK http code' + response.status == HttpStatus.OK.value() + } + def dataStores() { DataStores.builder() .operationalDataStore(Operational.builder() - .syncState(SyncState.NONE_REQUESTED) + .dataStoreSyncState(DataStoreSyncState.NONE_REQUESTED) .lastSyncTime(formattedDateAndTime.toString()).build()).build() } diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/mapper/CmHandleStateMapperTest.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/mapper/CmHandleStateMapperTest.groovy index a6c1278d96..42fda770b7 100644 --- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/mapper/CmHandleStateMapperTest.groovy +++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/mapper/CmHandleStateMapperTest.groovy @@ -24,8 +24,8 @@ import org.mapstruct.factory.Mappers import org.onap.cps.ncmp.api.inventory.CmHandleState import org.onap.cps.ncmp.api.inventory.CompositeStateBuilder import org.onap.cps.ncmp.api.inventory.LockReasonCategory -import org.onap.cps.ncmp.api.inventory.SyncState import org.onap.cps.ncmp.rest.model.CmHandleCompositeState +import org.onap.cps.ncmp.api.inventory.DataStoreSyncState import spock.lang.Specification import java.time.OffsetDateTime @@ -44,7 +44,7 @@ class CmHandleStateMapperTest extends Specification { .withCmHandleState(CmHandleState.ADVISED) .withLastUpdatedTime(formattedDateAndTime.toString()) .withLockReason(LockReasonCategory.LOCKED_MISBEHAVING, 'locked other details') - .withOperationalDataStores(SyncState.SYNCHRONIZED, formattedDateAndTime).build() + .withOperationalDataStores(DataStoreSyncState.SYNCHRONIZED, formattedDateAndTime).build() compositeState.setDataSyncEnabled(false) when: 'mapper is called' def result = objectUnderTest.toCmHandleCompositeState(compositeState) |