summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cps-application/src/main/resources/application.yml2
-rw-r--r--cps-ncmp-rest/docs/openapi/components.yaml24
-rwxr-xr-xcps-ncmp-rest/docs/openapi/ncmp.yml25
-rwxr-xr-xcps-ncmp-rest/docs/openapi/openapi.yml3
-rw-r--r--cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapper.java7
-rwxr-xr-xcps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java16
-rw-r--r--cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/mapper/CmHandleStateMapper.java3
-rw-r--r--cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapperSpec.groovy17
-rw-r--r--cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy19
-rw-r--r--cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/mapper/CmHandleStateMapperTest.groovy4
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java9
-rwxr-xr-xcps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java7
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CompositeState.java2
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CompositeStateBuilder.java9
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/DataStoreSyncState.java (renamed from cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/SyncState.java)2
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java41
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/DataSyncWatchdog.java19
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncService.java19
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdog.java40
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/SyncUtils.java4
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy2
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy12
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CompositeStateBuilderSpec.groovy4
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CompositeStateSpec.groovy2
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceSpec.groovy19
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/DataSyncSpec.groovy4
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncServiceSpec.groovy44
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdogSpec.groovy (renamed from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncSpec.groovy)4
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/SyncUtilsSpec.groovy4
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/YangModelCmHandleSpec.groovy4
-rwxr-xr-xcps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java26
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/repository/YangResourceRepository.java11
-rw-r--r--cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsModulePersistenceServiceIntegrationSpec.groovy10
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java10
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java8
-rwxr-xr-xcps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java12
-rw-r--r--cps-service/src/main/java/org/onap/cps/spi/model/ModuleDefinition.java37
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy8
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/utils/JsonObjectMapperSpec.groovy7
39 files changed, 434 insertions, 66 deletions
diff --git a/cps-application/src/main/resources/application.yml b/cps-application/src/main/resources/application.yml
index 14abebb2be..d16e977704 100644
--- a/cps-application/src/main/resources/application.yml
+++ b/cps-application/src/main/resources/application.yml
@@ -82,6 +82,8 @@ spring:
jackson:
default-property-inclusion: NON_NULL
+ serialization:
+ FAIL_ON_EMPTY_BEANS: false
app:
ncmp:
async-m2m:
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)
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 1ad61e6a6d..ea27d4a1e9 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
@@ -33,6 +33,7 @@ import org.onap.cps.ncmp.api.models.CmHandleQueryApiParameters;
import org.onap.cps.ncmp.api.models.DmiPluginRegistration;
import org.onap.cps.ncmp.api.models.DmiPluginRegistrationResponse;
import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
+import org.onap.cps.spi.model.ModuleDefinition;
import org.onap.cps.spi.model.ModuleReference;
/*
@@ -107,6 +108,14 @@ public interface NetworkCmProxyDataService {
Collection<ModuleReference> getYangResourcesModuleReferences(String cmHandleId);
/**
+ * Retrieve module definitions for the given cm handle.
+ *
+ * @param cmHandleId cm handle identifier
+ * @return a collection of module definition (moduleName, revision and yang resource content)
+ */
+ Collection<ModuleDefinition> getModuleDefinitionsByCmHandleId(String cmHandleId);
+
+ /**
* Query cm handle details by cm handle's name.
*
* @param cmHandleId cm handle identifier
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 e118bf1e58..044a5a44f9 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
@@ -63,6 +63,7 @@ import org.onap.cps.spi.exceptions.DataNodeNotFoundException;
import org.onap.cps.spi.exceptions.DataValidationException;
import org.onap.cps.spi.exceptions.SchemaSetNotFoundException;
import org.onap.cps.spi.model.CmHandleQueryServiceParameters;
+import org.onap.cps.spi.model.ModuleDefinition;
import org.onap.cps.spi.model.ModuleReference;
import org.onap.cps.utils.CpsValidator;
import org.onap.cps.utils.JsonObjectMapper;
@@ -153,6 +154,12 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
return cpsModuleService.getYangResourcesModuleReferences(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandleId);
}
+ @Override
+ public Collection<ModuleDefinition> getModuleDefinitionsByCmHandleId(final String cmHandleId) {
+ CpsValidator.validateNameCharacters(cmHandleId);
+ return inventoryPersistence.getModuleDefinitionsByCmHandleId(cmHandleId);
+ }
+
/**
* Retrieve cm handles with details for the given query parameters.
*
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CompositeState.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CompositeState.java
index df303b5daa..e8fcaabe91 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CompositeState.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CompositeState.java
@@ -94,7 +94,7 @@ public class CompositeState {
public static class Operational {
@JsonProperty("sync-state")
- private SyncState syncState;
+ private DataStoreSyncState dataStoreSyncState;
@JsonProperty("last-sync-time")
private String lastSyncTime;
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CompositeStateBuilder.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CompositeStateBuilder.java
index 91e92ea6f9..a0fc0c3a91 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CompositeStateBuilder.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CompositeStateBuilder.java
@@ -94,13 +94,14 @@ public class CompositeStateBuilder {
/**
* To use attributes for creating {@link CompositeState}.
*
- * @param syncState for the locked state
+ * @param dataStoreSyncState for the locked state
* @param lastSyncTime for the locked state
* @return CompositeStateBuilder
*/
- public CompositeStateBuilder withOperationalDataStores(final SyncState syncState, final String lastSyncTime) {
+ public CompositeStateBuilder withOperationalDataStores(final DataStoreSyncState dataStoreSyncState,
+ final String lastSyncTime) {
this.datastores = DataStores.builder().operationalDataStore(
- Operational.builder().syncState(syncState).lastSyncTime(lastSyncTime).build()).build();
+ Operational.builder().dataStoreSyncState(dataStoreSyncState).lastSyncTime(lastSyncTime).build()).build();
return this;
}
@@ -133,7 +134,7 @@ public class CompositeStateBuilder {
private Operational getOperationalDataStore(final DataNode dataStoreNodes) {
return Operational.builder()
- .syncState(SyncState.valueOf((String) dataStoreNodes.getLeaves().get("sync-state")))
+ .dataStoreSyncState(DataStoreSyncState.valueOf((String) dataStoreNodes.getLeaves().get("sync-state")))
.lastSyncTime((String) dataStoreNodes.getLeaves().get("last-sync-time"))
.build();
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/SyncState.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/DataStoreSyncState.java
index 9c7a476183..4dbedf5f1c 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/SyncState.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/DataStoreSyncState.java
@@ -20,6 +20,6 @@
package org.onap.cps.ncmp.api.inventory;
-public enum SyncState {
+public enum DataStoreSyncState {
SYNCHRONIZED, UNSYNCHRONIZED, NONE_REQUESTED
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java
index c24063cb45..d47da6c0cf 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java
@@ -21,15 +21,20 @@
package org.onap.cps.ncmp.api.inventory;
+import static org.onap.cps.ncmp.api.impl.constants.DmiRegistryConstants.NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME;
+
import java.time.OffsetDateTime;
+import java.util.Collection;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.onap.cps.api.CpsDataService;
+import org.onap.cps.api.CpsModuleService;
import org.onap.cps.ncmp.api.impl.utils.YangDataConverter;
import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle;
import org.onap.cps.spi.CpsDataPersistenceService;
import org.onap.cps.spi.FetchDescendantsOption;
import org.onap.cps.spi.model.DataNode;
+import org.onap.cps.spi.model.ModuleDefinition;
import org.onap.cps.utils.CpsValidator;
import org.onap.cps.utils.JsonObjectMapper;
import org.springframework.stereotype.Component;
@@ -42,15 +47,17 @@ public class InventoryPersistence {
private static final String NCMP_DMI_REGISTRY_ANCHOR = "ncmp-dmi-registry";
- private static final String XPATH_TO_CM_HANDLE = "/dmi-registry/cm-handles[@id='" + "%s" + "']";
+ private String xpathCmHandle = "/dmi-registry/cm-handles[@id='" + "%s" + "']";
+
+ private static final String ANCESTOR_CM_HANDLES = "\"]/ancestor::cm-handles";
private final JsonObjectMapper jsonObjectMapper;
private final CpsDataService cpsDataService;
- private final CpsDataPersistenceService cpsDataPersistenceService;
+ private final CpsModuleService cpsModuleService;
- private static final CompositeStateBuilder compositeStateBuilder = new CompositeStateBuilder();
+ private final CpsDataPersistenceService cpsDataPersistenceService;
/**
* Get the Cm Handle Composite State from the data node.
@@ -60,9 +67,9 @@ public class InventoryPersistence {
*/
public CompositeState getCmHandleState(final String cmHandleId) {
final DataNode stateAsDataNode = cpsDataService.getDataNode(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
- String.format(XPATH_TO_CM_HANDLE, cmHandleId) + "/state",
+ String.format(xpathCmHandle, cmHandleId) + "/state",
FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS);
- return compositeStateBuilder.fromDataNode(stateAsDataNode).build();
+ return new CompositeStateBuilder().fromDataNode(stateAsDataNode).build();
}
/**
@@ -75,7 +82,7 @@ public class InventoryPersistence {
final String cmHandleJsonData = String.format("{\"state\":%s}",
jsonObjectMapper.asJsonString(compositeState));
cpsDataService.replaceNodeTree(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
- String.format(XPATH_TO_CM_HANDLE, cmHandleId),
+ String.format(xpathCmHandle, cmHandleId),
cmHandleJsonData, OffsetDateTime.now());
}
@@ -88,7 +95,7 @@ public class InventoryPersistence {
public List<DataNode> getCmHandlesByState(final CmHandleState cmHandleState) {
return cpsDataPersistenceService.queryDataNodes(NCMP_DATASPACE_NAME,
NCMP_DMI_REGISTRY_ANCHOR, "//state[@cm-handle-state=\""
- + cmHandleState + "\"]/ancestor::cm-handles",
+ + cmHandleState + ANCESTOR_CM_HANDLES,
FetchDescendantsOption.OMIT_DESCENDANTS);
}
@@ -114,19 +121,19 @@ public class InventoryPersistence {
public List<DataNode> getCmHandlesByIdAndState(final String cmHandleId, final CmHandleState cmHandleState) {
return cpsDataPersistenceService.queryDataNodes(NCMP_DATASPACE_NAME,
NCMP_DMI_REGISTRY_ANCHOR, "//cm-handles[@id='" + cmHandleId + "']/state[@cm-handle-state=\""
- + cmHandleState + "\"]/ancestor::cm-handles",
+ + cmHandleState + ANCESTOR_CM_HANDLES,
FetchDescendantsOption.OMIT_DESCENDANTS);
}
/**
* Method which returns cm handles by the operational sync state of cm handle.
- * @param syncState sync state
+ * @param dataStoreSyncState sync state
* @return a list of cm handles
*/
- public List<DataNode> getCmHandlesByOperationalSyncState(final SyncState syncState) {
+ public List<DataNode> getCmHandlesByOperationalSyncState(final DataStoreSyncState dataStoreSyncState) {
return cpsDataPersistenceService.queryDataNodes(NCMP_DATASPACE_NAME,
NCMP_DMI_REGISTRY_ANCHOR, "//state/datastores"
- + "/operational[@sync-state=\"" + syncState + "\"]/ancestor::cm-handles",
+ + "/operational[@sync-state=\"" + dataStoreSyncState + ANCESTOR_CM_HANDLES,
FetchDescendantsOption.OMIT_DESCENDANTS);
}
@@ -140,10 +147,20 @@ public class InventoryPersistence {
return YangDataConverter.convertCmHandleToYangModel(getCmHandleDataNode(cmHandleId), cmHandleId);
}
+ /**
+ * Method to return module definitions by cmHandleId.
+ *
+ * @param cmHandleId cm handle ID
+ * @return a collection of module definitions (moduleName, revision and yang resource content)
+ */
+ public Collection<ModuleDefinition> getModuleDefinitionsByCmHandleId(final String cmHandleId) {
+ return cpsModuleService.getModuleDefinitionsByAnchorName(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandleId);
+ }
+
private DataNode getCmHandleDataNode(final String cmHandle) {
return cpsDataService.getDataNode(NCMP_DATASPACE_NAME,
NCMP_DMI_REGISTRY_ANCHOR,
- String.format(XPATH_TO_CM_HANDLE, cmHandle),
+ String.format(xpathCmHandle, cmHandle),
FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS);
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/DataSyncWatchdog.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/DataSyncWatchdog.java
index 553db65dd0..adfa33ad81 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/DataSyncWatchdog.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/DataSyncWatchdog.java
@@ -21,13 +21,14 @@
package org.onap.cps.ncmp.api.inventory.sync;
import java.time.OffsetDateTime;
+import java.util.function.Consumer;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.onap.cps.api.CpsDataService;
import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle;
import org.onap.cps.ncmp.api.inventory.CompositeState;
+import org.onap.cps.ncmp.api.inventory.DataStoreSyncState;
import org.onap.cps.ncmp.api.inventory.InventoryPersistence;
-import org.onap.cps.ncmp.api.inventory.SyncState;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
@@ -60,15 +61,21 @@ public class DataSyncWatchdog {
} else {
cpsDataService.saveData("NFP-Operational", cmHandleId,
resourceData, OffsetDateTime.now());
+ setSyncStateToSynchronized().accept(compositeState);
+ inventoryPersistence.saveCmHandleState(cmHandleId, compositeState);
}
+ unSynchronizedReadyCmHandle = syncUtils.getAnUnSynchronizedReadyCmHandle();
+ }
+ log.debug("No Cm-Handles currently found in an READY State and Operational Sync State is UNSYNCHRONIZED");
+ }
+
+ private Consumer<CompositeState> setSyncStateToSynchronized() {
+ return compositeState -> {
compositeState.setLastUpdateTimeNow();
compositeState.getDataStores()
.setOperationalDataStore(CompositeState.Operational.builder()
- .syncState(SyncState.SYNCHRONIZED)
+ .dataStoreSyncState(DataStoreSyncState.SYNCHRONIZED)
.lastSyncTime(CompositeState.nowInSyncTimeFormat()).build());
- inventoryPersistence.saveCmHandleState(cmHandleId, compositeState);
- unSynchronizedReadyCmHandle = syncUtils.getAnUnSynchronizedReadyCmHandle();
- }
- log.debug("No Cm-Handles currently found in an READY State and Operational Sync State is UNSYNCHRONIZED");
+ };
}
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncService.java
index 58e2bf3450..c574aa61d9 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncService.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncService.java
@@ -32,6 +32,8 @@ import org.onap.cps.api.CpsAdminService;
import org.onap.cps.api.CpsModuleService;
import org.onap.cps.ncmp.api.impl.operations.DmiModelOperations;
import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle;
+import org.onap.cps.spi.CascadeDeleteAllowed;
+import org.onap.cps.spi.exceptions.SchemaSetNotFoundException;
import org.onap.cps.spi.model.ModuleReference;
import org.springframework.stereotype.Service;
@@ -83,4 +85,21 @@ public class ModuleSyncService {
schemaSetAndAnchorName);
}
+ /**
+ * Deletes the SchemaSet for provided cmHandle if the SchemaSet Exists.
+ *
+ * @param yangModelCmHandle the yang model of cm handle.
+ */
+ public void deleteSchemaSetIfExists(final YangModelCmHandle yangModelCmHandle) {
+ final String schemaSetAndAnchorName = yangModelCmHandle.getId();
+ try {
+ cpsModuleService.deleteSchemaSet(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, schemaSetAndAnchorName,
+ CascadeDeleteAllowed.CASCADE_DELETE_ALLOWED);
+ log.debug("SchemaSet for {} has been deleted. Ready to be recreated.", schemaSetAndAnchorName);
+ } catch (final SchemaSetNotFoundException e) {
+ log.debug("No SchemaSet for {}. Assuming CmHandle has not been previously Module Synced.",
+ schemaSetAndAnchorName);
+ }
+ }
+
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdog.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdog.java
index 402f9f6b4f..6ec44197d2 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdog.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdog.java
@@ -22,11 +22,13 @@
package org.onap.cps.ncmp.api.inventory.sync;
import java.util.List;
+import java.util.function.Consumer;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle;
import org.onap.cps.ncmp.api.inventory.CmHandleState;
import org.onap.cps.ncmp.api.inventory.CompositeState;
+import org.onap.cps.ncmp.api.inventory.DataStoreSyncState;
import org.onap.cps.ncmp.api.inventory.InventoryPersistence;
import org.onap.cps.ncmp.api.inventory.LockReasonCategory;
import org.springframework.scheduling.annotation.Scheduled;
@@ -53,18 +55,16 @@ public class ModuleSyncWatchdog {
final String cmHandleId = advisedCmHandle.getId();
final CompositeState compositeState = inventoryPersistence.getCmHandleState(cmHandleId);
try {
+ moduleSyncService.deleteSchemaSetIfExists(advisedCmHandle);
moduleSyncService.syncAndCreateSchemaSetAndAnchor(advisedCmHandle);
- compositeState.setCmHandleState(CmHandleState.READY);
+ setCompositeStateToReadyWithInitialDataStoreSyncState().accept(compositeState);
} catch (final Exception e) {
- compositeState.setCmHandleState(CmHandleState.LOCKED);
+ setCompositeStateToLocked().accept(compositeState);
syncUtils.updateLockReasonDetailsAndAttempts(compositeState,
- LockReasonCategory.LOCKED_MISBEHAVING,
- e.getMessage());
+ LockReasonCategory.LOCKED_MISBEHAVING, e.getMessage());
}
- compositeState.setLastUpdateTimeNow();
inventoryPersistence.saveCmHandleState(cmHandleId, compositeState);
- log.info("{} is now in {} state", cmHandleId,
- advisedCmHandle.getCompositeState().getCmHandleState());
+ log.debug("{} is now in {} state", cmHandleId, compositeState.getCmHandleState().name());
advisedCmHandle = syncUtils.getAnAdvisedCmHandle();
}
log.debug("No Cm-Handles currently found in an ADVISED state");
@@ -87,11 +87,33 @@ public class ModuleSyncWatchdog {
}
}
+ private Consumer<CompositeState> setCompositeStateToLocked() {
+ return compositeState -> {
+ compositeState.setCmHandleState(CmHandleState.LOCKED);
+ compositeState.setLastUpdateTimeNow();
+ };
+ }
+
+ private Consumer<CompositeState> setCompositeStateToReadyWithInitialDataStoreSyncState() {
+ return compositeState -> {
+ compositeState.setCmHandleState(CmHandleState.READY);
+ final CompositeState.Operational operational = CompositeState.Operational.builder()
+ .dataStoreSyncState(DataStoreSyncState.UNSYNCHRONIZED)
+ .lastSyncTime(CompositeState.nowInSyncTimeFormat())
+ .build();
+ final CompositeState.DataStores dataStores = CompositeState.DataStores.builder()
+ .operationalDataStore(operational)
+ .build();
+ compositeState.setDataStores(dataStores);
+ };
+ }
+
private void setCompositeStateToAdvisedAndRetainOldLockReasonDetails(final CompositeState compositeState) {
compositeState.setCmHandleState(CmHandleState.ADVISED);
compositeState.setLastUpdateTimeNow();
final String oldLockReasonDetails = compositeState.getLockReason().getDetails();
- compositeState.setLockReason(CompositeState.LockReason.builder()
- .details(oldLockReasonDetails).build());
+ final CompositeState.LockReason lockReason = CompositeState.LockReason.builder()
+ .details(oldLockReasonDetails).build();
+ compositeState.setLockReason(lockReason);
}
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/SyncUtils.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/SyncUtils.java
index 8b7dfe6b81..0c3af6aaeb 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/SyncUtils.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/SyncUtils.java
@@ -43,9 +43,9 @@ import org.onap.cps.ncmp.api.impl.utils.YangDataConverter;
import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle;
import org.onap.cps.ncmp.api.inventory.CmHandleState;
import org.onap.cps.ncmp.api.inventory.CompositeState;
+import org.onap.cps.ncmp.api.inventory.DataStoreSyncState;
import org.onap.cps.ncmp.api.inventory.InventoryPersistence;
import org.onap.cps.ncmp.api.inventory.LockReasonCategory;
-import org.onap.cps.ncmp.api.inventory.SyncState;
import org.onap.cps.spi.FetchDescendantsOption;
import org.onap.cps.spi.model.DataNode;
import org.onap.cps.utils.JsonObjectMapper;
@@ -92,7 +92,7 @@ public class SyncUtils {
*/
public YangModelCmHandle getAnUnSynchronizedReadyCmHandle() {
final List<DataNode> unSynchronizedCmHandles = inventoryPersistence
- .getCmHandlesByOperationalSyncState(SyncState.UNSYNCHRONIZED);
+ .getCmHandlesByOperationalSyncState(DataStoreSyncState.UNSYNCHRONIZED);
if (unSynchronizedCmHandles.isEmpty()) {
return null;
}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy
index c11d09d5a2..02e6419c34 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy
@@ -23,7 +23,6 @@ package org.onap.cps.ncmp.api.impl
import com.fasterxml.jackson.databind.ObjectMapper
import org.onap.cps.ncmp.api.NetworkCmProxyCmHandlerQueryService
-import org.onap.cps.api.CpsAdminService
import org.onap.cps.api.CpsDataService
import org.onap.cps.api.CpsModuleService
import org.onap.cps.ncmp.api.impl.exception.DmiRequestException
@@ -32,7 +31,6 @@ import org.onap.cps.ncmp.api.inventory.InventoryPersistence
import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse
import org.onap.cps.ncmp.api.models.DmiPluginRegistration
import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle
-import org.onap.cps.ncmp.api.inventory.sync.ModuleSyncService
import org.onap.cps.spi.exceptions.AlreadyDefinedException
import org.onap.cps.spi.exceptions.DataNodeNotFoundException
import org.onap.cps.spi.exceptions.DataValidationException
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 48c28a8952..2e333b5070 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
@@ -28,7 +28,7 @@ import org.onap.cps.ncmp.api.inventory.CmHandleState
import org.onap.cps.ncmp.api.inventory.CompositeState
import org.onap.cps.ncmp.api.inventory.InventoryPersistence
import org.onap.cps.ncmp.api.inventory.LockReasonCategory
-import org.onap.cps.ncmp.api.inventory.SyncState
+import org.onap.cps.ncmp.api.inventory.DataStoreSyncState
import org.onap.cps.ncmp.api.models.CmHandleQueryApiParameters
import org.onap.cps.ncmp.api.models.ConditionApiProperties
import org.onap.cps.ncmp.api.models.DmiPluginRegistration
@@ -297,10 +297,18 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
assert result == ['cm-handle-id-1'] as Set
}
+ def 'Getting module definitions.'() {
+ when: 'get module definitions method is called with a valid cm handle ID'
+ objectUnderTest.getModuleDefinitionsByCmHandleId('some-cm-handle')
+ then: 'CPS module services is invoked once'
+ 1 * mockInventoryPersistence.getModuleDefinitionsByCmHandleId('some-cm-handle')
+ }
+
+
def dataStores() {
CompositeState.DataStores.builder()
.operationalDataStore(CompositeState.Operational.builder()
- .syncState(SyncState.NONE_REQUESTED)
+ .dataStoreSyncState(DataStoreSyncState.NONE_REQUESTED)
.lastSyncTime('some-timestamp').build()).build()
}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CompositeStateBuilderSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CompositeStateBuilderSpec.groovy
index 60fec6f867..8670948598 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CompositeStateBuilderSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CompositeStateBuilderSpec.groovy
@@ -47,11 +47,11 @@ class CompositeStateBuilderSpec extends Specification {
def "Composite State Specification"() {
when: 'using composite state builder '
def compositeState = new CompositeStateBuilder().withCmHandleState(CmHandleState.ADVISED)
- .withLockReason(LockReasonCategory.LOCKED_MISBEHAVING,"").withOperationalDataStores(SyncState.UNSYNCHRONIZED,
+ .withLockReason(LockReasonCategory.LOCKED_MISBEHAVING,"").withOperationalDataStores(DataStoreSyncState.UNSYNCHRONIZED,
formattedDateAndTime.toString()).withLastUpdatedTime(formattedDateAndTime).build()
then: 'it matches expected cm handle state and data store sync state'
assert compositeState.cmHandleState == CmHandleState.ADVISED
- assert compositeState.dataStores.operationalDataStore.syncState == SyncState.UNSYNCHRONIZED
+ assert compositeState.dataStores.operationalDataStore.dataStoreSyncState == DataStoreSyncState.UNSYNCHRONIZED
}
def "Build composite state from DataNode "() {
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CompositeStateSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CompositeStateSpec.groovy
index 0a6f8c350a..bf42fbfeea 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CompositeStateSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CompositeStateSpec.groovy
@@ -54,7 +54,7 @@ class CompositeStateSpec extends Specification {
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-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceSpec.groovy
index 46bd047ab7..638af32e2c 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceSpec.groovy
@@ -23,11 +23,13 @@ package org.onap.cps.ncmp.api.inventory
import com.fasterxml.jackson.databind.ObjectMapper
import org.onap.cps.api.CpsDataService
+import org.onap.cps.api.CpsModuleService
import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle
import org.onap.cps.spi.CpsDataPersistenceService
import org.onap.cps.spi.FetchDescendantsOption
import org.onap.cps.spi.exceptions.DataValidationException
import org.onap.cps.spi.model.DataNode
+import org.onap.cps.spi.model.ModuleDefinition
import org.onap.cps.utils.JsonObjectMapper
import spock.lang.Shared
import spock.lang.Specification
@@ -45,10 +47,11 @@ class InventoryPersistenceSpec extends Specification {
def mockCpsDataService = Mock(CpsDataService)
- def mockCpsDataPersistenceService = Mock(CpsDataPersistenceService)
+ def mockCpsModuleService = Mock(CpsModuleService)
+ def mockCpsDataPersistenceService = Mock(CpsDataPersistenceService)
- def objectUnderTest = new InventoryPersistence(spiedJsonObjectMapper, mockCpsDataService, mockCpsDataPersistenceService)
+ def objectUnderTest = new InventoryPersistence(spiedJsonObjectMapper, mockCpsDataService, mockCpsModuleService, mockCpsDataPersistenceService)
def formattedDateAndTime = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
.format(OffsetDateTime.of(2022, 12, 31, 20, 30, 40, 1, ZoneOffset.UTC))
@@ -178,7 +181,7 @@ class InventoryPersistenceSpec extends Specification {
mockCpsDataPersistenceService.queryDataNodes('NCMP-Admin', 'ncmp-dmi-registry',
'//state/datastores/operational[@sync-state="'+'UNSYNCHRONIZED'+'"]/ancestor::cm-handles', OMIT_DESCENDANTS) >> sampleDataNodes
when: 'get cm handles by operational sync state as UNSYNCHRONIZED is invoked'
- def result = objectUnderTest.getCmHandlesByOperationalSyncState(SyncState.UNSYNCHRONIZED)
+ def result = objectUnderTest.getCmHandlesByOperationalSyncState(DataStoreSyncState.UNSYNCHRONIZED)
then: 'the returned result is a list of data nodes returned by cps data service'
assert result == sampleDataNodes
}
@@ -197,4 +200,14 @@ class InventoryPersistenceSpec extends Specification {
assert result.contains(cmHandleDataNode)
}
+ def 'Get module definitions'() {
+ given: 'cps module service returns a collection of module definitions'
+ def moduleDefinitions = [new ModuleDefinition('moduleName','revision','content')]
+ mockCpsModuleService.getModuleDefinitionsByAnchorName('NFP-Operational','some-cmHandle-Id') >> moduleDefinitions
+ when: 'get module definitions by cmHandle is invoked'
+ def result = objectUnderTest.getModuleDefinitionsByCmHandleId('some-cmHandle-Id')
+ then: 'the returned result are the same module definitions as returned from the module service'
+ assert result == moduleDefinitions
+ }
+
}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/DataSyncSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/DataSyncSpec.groovy
index b062635db0..20880ca3b3 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/DataSyncSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/DataSyncSpec.groovy
@@ -25,7 +25,7 @@ import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle
import org.onap.cps.ncmp.api.inventory.CmHandleState
import org.onap.cps.ncmp.api.inventory.CompositeState
import org.onap.cps.ncmp.api.inventory.InventoryPersistence
-import org.onap.cps.ncmp.api.inventory.SyncState
+import org.onap.cps.ncmp.api.inventory.DataStoreSyncState
import spock.lang.Specification
class DataSyncSpec extends Specification {
@@ -94,7 +94,7 @@ class DataSyncSpec extends Specification {
def cmHandleState = CmHandleState.READY
def compositeState = new CompositeState(cmHandleState: cmHandleState)
compositeState.setDataStores(CompositeState.DataStores.builder()
- .operationalDataStore(CompositeState.Operational.builder().syncState(SyncState.SYNCHRONIZED)
+ .operationalDataStore(CompositeState.Operational.builder().dataStoreSyncState(DataStoreSyncState.SYNCHRONIZED)
.build()).build())
return compositeState
}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncServiceSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncServiceSpec.groovy
index f93b3a73ed..6a2fbe8e7b 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncServiceSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncServiceSpec.groovy
@@ -1,5 +1,5 @@
/*
- * ============LICENSE_START=======================================================
+ * ============LICENSE_START=======================================================
* Copyright (C) 2022 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,7 +24,11 @@ import org.onap.cps.api.CpsAdminService
import org.onap.cps.api.CpsModuleService
import org.onap.cps.ncmp.api.impl.operations.DmiModelOperations
import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle
+import org.onap.cps.ncmp.api.inventory.CmHandleState
+import org.onap.cps.ncmp.api.inventory.CompositeState
import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle
+import org.onap.cps.spi.CascadeDeleteAllowed
+import org.onap.cps.spi.exceptions.SchemaSetNotFoundException
import org.onap.cps.spi.model.ModuleReference
import spock.lang.Specification
@@ -67,6 +71,44 @@ class ModuleSyncServiceSpec extends Specification {
'no new module' | [['module1' : '1'], ['module2' : '2']] | [] | [:] | [new ModuleReference(moduleName:'module1',revision:'1'), new ModuleReference(moduleName:'module2',revision:'2')]
}
+ def 'Delete Schema Set for CmHandle' () {
+ given: 'a CmHandle in the advised state'
+ def cmHandle = new YangModelCmHandle(id: 'some-cmhandle-id', compositeState: new CompositeState(cmHandleState: CmHandleState.ADVISED))
+ and: 'the Schema Set exists for the CmHandle'
+ 1 * mockCpsModuleService.deleteSchemaSet(_ as String, 'some-cmhandle-id',
+ CascadeDeleteAllowed.CASCADE_DELETE_ALLOWED)
+ when: 'delete schema set if exists is called'
+ objectUnderTest.deleteSchemaSetIfExists(cmHandle)
+ then: 'there are no exceptions'
+ noExceptionThrown()
+ }
+
+ def 'Delete a non-existing Schema Set for CmHandle' () {
+ given: 'a CmHandle in the advised state'
+ def cmHandle = new YangModelCmHandle(id: 'some-cmhandle-id', compositeState: new CompositeState(cmHandleState: CmHandleState.ADVISED))
+ and: 'the DB throws an exception because its Schema Set does not exist'
+ 1 * mockCpsModuleService.deleteSchemaSet(_ as String, 'some-cmhandle-id',
+ CascadeDeleteAllowed.CASCADE_DELETE_ALLOWED) >> { throw new SchemaSetNotFoundException('some-dataspace-name', 'some-cmhandle-id') }
+ when: 'delete schema set if exists is called'
+ objectUnderTest.deleteSchemaSetIfExists(cmHandle)
+ then: 'there are no exceptions'
+ noExceptionThrown()
+ }
+
+ def 'Delete Schema Set for CmHandle with other exception' () {
+ given: 'a CmHandle in the advised state'
+ def cmHandle = new YangModelCmHandle(id: 'some-cmhandle-id', compositeState: new CompositeState(cmHandleState: CmHandleState.ADVISED))
+ and: 'an exception other than SchemaSetNotFoundException is thrown'
+ UnsupportedOperationException unsupportedOperationException = new UnsupportedOperationException();
+ 1 * mockCpsModuleService.deleteSchemaSet(_ as String, 'some-cmhandle-id',
+ CascadeDeleteAllowed.CASCADE_DELETE_ALLOWED) >> { throw unsupportedOperationException }
+ when: 'delete schema set if exists is called'
+ objectUnderTest.deleteSchemaSetIfExists(cmHandle)
+ then: 'an exception is thrown'
+ def result = thrown(UnsupportedOperationException)
+ result == unsupportedOperationException
+ }
+
def toModuleReference(moduleReferenceAsMap) {
def moduleReferences = [].withDefault { [:] }
moduleReferenceAsMap.forEach(property ->
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdogSpec.groovy
index 0f89a428b4..b7eb133bf0 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdogSpec.groovy
@@ -29,7 +29,7 @@ import org.onap.cps.ncmp.api.inventory.LockReasonCategory
import org.onap.cps.ncmp.api.inventory.CompositeStateBuilder
import spock.lang.Specification
-class ModuleSyncSpec extends Specification {
+class ModuleSyncWatchdogSpec extends Specification {
def mockInventoryPersistence = Mock(InventoryPersistence)
@@ -53,6 +53,8 @@ class ModuleSyncSpec extends Specification {
objectUnderTest.executeAdvisedCmHandlePoll()
then: 'the inventory persistence cm handle returns a composite state for the first cm handle'
1 * mockInventoryPersistence.getCmHandleState('some-cm-handle') >> compositeState1
+ and: 'module sync service deletes schema set of cm handle if it exists'
+ 1 * mockModuleSyncService.deleteSchemaSetIfExists(yangModelCmHandle1)
and: 'module sync service syncs the first cm handle and creates a schema set'
1 * mockModuleSyncService.syncAndCreateSchemaSetAndAnchor(yangModelCmHandle1)
and: 'the composite state cm handle state is now READY'
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/SyncUtilsSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/SyncUtilsSpec.groovy
index dd299146f7..051172ca23 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/SyncUtilsSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/SyncUtilsSpec.groovy
@@ -28,9 +28,9 @@ import org.onap.cps.ncmp.api.impl.operations.DmiOperations
import org.onap.cps.ncmp.api.inventory.CmHandleState
import org.onap.cps.ncmp.api.inventory.CompositeState
import org.onap.cps.ncmp.api.inventory.CompositeStateBuilder
+import org.onap.cps.ncmp.api.inventory.DataStoreSyncState
import org.onap.cps.ncmp.api.inventory.InventoryPersistence
import org.onap.cps.ncmp.api.inventory.LockReasonCategory
-import org.onap.cps.ncmp.api.inventory.SyncState
import org.onap.cps.spi.FetchDescendantsOption
import org.onap.cps.spi.model.DataNode
import org.onap.cps.utils.JsonObjectMapper
@@ -118,7 +118,7 @@ class SyncUtilsSpec extends Specification{
def 'Get a Cm-Handle where Operational Sync state is UnSynchronized and Cm-handle state is READY and #scenario'() {
given: 'the inventory persistence service returns a collection of data nodes'
- mockInventoryPersistence.getCmHandlesByOperationalSyncState(SyncState.UNSYNCHRONIZED) >> unSynchronizedDataNodes
+ mockInventoryPersistence.getCmHandlesByOperationalSyncState(DataStoreSyncState.UNSYNCHRONIZED) >> unSynchronizedDataNodes
mockInventoryPersistence.getCmHandlesByIdAndState("cm-handle-123", CmHandleState.READY) >> readyDataNodes
when: 'get advised cm handle is called'
objectUnderTest.getAnUnSynchronizedReadyCmHandle()
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/YangModelCmHandleSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/YangModelCmHandleSpec.groovy
index cf9c6bbcfa..5903b12117 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/YangModelCmHandleSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/YangModelCmHandleSpec.groovy
@@ -24,7 +24,7 @@ import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle
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.api.inventory.DataStoreSyncState
import spock.lang.Specification
import static org.onap.cps.ncmp.api.impl.operations.RequiredDmiService.DATA
@@ -43,7 +43,7 @@ class YangModelCmHandleSpec extends Specification {
.withCmHandleState(CmHandleState.LOCKED)
.withLastUpdatedTime('some-update-time')
.withLockReason(LockReasonCategory.LOCKED_MISBEHAVING, 'locked other details')
- .withOperationalDataStores(SyncState.SYNCHRONIZED, 'some-sync-time').build()
+ .withOperationalDataStores(DataStoreSyncState.SYNCHRONIZED, 'some-sync-time').build()
ncmpServiceCmHandle.setCompositeState(compositeState)
when: 'it is converted to a yang model cm handle'
def objectUnderTest = YangModelCmHandle.toYangModelCmHandle('', '', '', ncmpServiceCmHandle)
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 cbeb1b76f7..806e7ccaba 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
@@ -53,6 +53,7 @@ import org.onap.cps.spi.entities.YangResourceModuleReference;
import org.onap.cps.spi.exceptions.AlreadyDefinedException;
import org.onap.cps.spi.exceptions.DuplicatedYangResourceException;
import org.onap.cps.spi.exceptions.ModelValidationException;
+import org.onap.cps.spi.model.ModuleDefinition;
import org.onap.cps.spi.model.ModuleReference;
import org.onap.cps.spi.repository.DataspaceRepository;
import org.onap.cps.spi.repository.ModuleReferenceRepository;
@@ -114,12 +115,22 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
@Override
public Collection<ModuleReference> getYangResourceModuleReferences(final String dataspaceName,
- final String anchorName) {
+ final String anchorName) {
final Set<YangResourceModuleReference> yangResourceModuleReferenceList =
- yangResourceRepository
- .findAllModuleReferencesByDataspaceAndAnchor(dataspaceName, anchorName);
+ yangResourceRepository
+ .findAllModuleReferencesByDataspaceAndAnchor(dataspaceName, anchorName);
return yangResourceModuleReferenceList.stream().map(CpsModulePersistenceServiceImpl::toModuleReference)
- .collect(Collectors.toList());
+ .collect(Collectors.toList());
+ }
+
+ @Override
+ public Collection<ModuleDefinition> getYangResourceDefinitions(final String dataspaceName,
+ final String anchorName) {
+ final Set<YangResourceEntity> yangResourceEntities =
+ yangResourceRepository
+ .findAllModuleDefinitionsByDataspaceAndAnchor(dataspaceName, anchorName);
+ return yangResourceEntities.stream().map(CpsModulePersistenceServiceImpl::toModuleDefinition)
+ .collect(Collectors.toList());
}
@Override
@@ -343,4 +354,11 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
.revision(yangResourceModuleReference.getRevision())
.build();
}
+
+ private static ModuleDefinition toModuleDefinition(final YangResourceEntity yangResourceEntity) {
+ return new ModuleDefinition(
+ yangResourceEntity.getModuleName(),
+ yangResourceEntity.getRevision(),
+ yangResourceEntity.getContent());
+ }
}
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/repository/YangResourceRepository.java b/cps-ri/src/main/java/org/onap/cps/spi/repository/YangResourceRepository.java
index 5e9c47429b..98306d8684 100644
--- a/cps-ri/src/main/java/org/onap/cps/spi/repository/YangResourceRepository.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/repository/YangResourceRepository.java
@@ -67,6 +67,17 @@ public interface YangResourceRepository extends JpaRepository<YangResourceEntity
Set<YangResourceModuleReference> findAllModuleReferencesByDataspaceAndAnchor(
@Param("dataspaceName") String dataspaceName, @Param("anchorName") String anchorName);
+ @Query(value = "SELECT DISTINCT yang_resource.*\n"
+ + "FROM dataspace\n"
+ + "JOIN anchor ON anchor.dataspace_id = dataspace.id\n"
+ + "JOIN schema_set ON schema_set.id = anchor.schema_set_id\n"
+ + "JOIN schema_set_yang_resources ON schema_set_yang_resources.schema_set_id = schema_set.id\n"
+ + "JOIN yang_resource ON yang_resource.id = schema_set_yang_resources.yang_resource_id\n"
+ + "WHERE dataspace.name = :dataspaceName "
+ + "AND anchor.name =:anchorName", nativeQuery = true)
+ Set<YangResourceEntity> findAllModuleDefinitionsByDataspaceAndAnchor(
+ @Param("dataspaceName") String dataspaceName, @Param("anchorName") String anchorName);
+
@Query(value = "SELECT DISTINCT\n"
+ "yang_resource.*\n"
+ "FROM\n"
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 c4cfa3d50b..8a43e5125d 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
@@ -26,9 +26,11 @@ import org.onap.cps.spi.entities.YangResourceEntity
import org.onap.cps.spi.exceptions.AlreadyDefinedException
import org.onap.cps.spi.exceptions.DataspaceNotFoundException
import org.onap.cps.spi.exceptions.SchemaSetNotFoundException
+import org.onap.cps.spi.model.ModuleDefinition
import org.onap.cps.spi.model.ModuleReference
import org.onap.cps.spi.repository.AnchorRepository
import org.onap.cps.spi.repository.SchemaSetRepository
+import org.onap.cps.spi.repository.YangResourceRepository
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.test.context.jdbc.Sql
@@ -214,6 +216,14 @@ class CpsModulePersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase
yangResourceRepository.findById(sharedResourceId).isPresent()
}
+ @Sql([CLEAR_DATA, SET_DATA])
+ def 'Retrieving all yang resources module definition for the given dataspace and anchor name.'() {
+ when: 'all yang resources module definitions are retrieved for the given dataspace and anchor name'
+ def result = objectUnderTest.getYangResourceDefinitions('DATASPACE-001', 'ANCHOR3')
+ then: 'the correct module definitions (moduleName, revision and yang resource content) are returned'
+ result.sort() == [new ModuleDefinition('MODULE-NAME-004', 'REVISION-004', 'CONTENT-004')]
+ }
+
def assertSchemaSetPersisted(expectedDataspaceName,
expectedSchemaSetName,
expectedYangResourceName,
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 79d6e03d4a..5e8eb9f6cf 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
@@ -25,6 +25,7 @@ import java.util.Collection;
import java.util.Map;
import org.onap.cps.spi.CascadeDeleteAllowed;
import org.onap.cps.spi.exceptions.DataInUseException;
+import org.onap.cps.spi.model.ModuleDefinition;
import org.onap.cps.spi.model.ModuleReference;
import org.onap.cps.spi.model.SchemaSet;
@@ -94,6 +95,15 @@ public interface CpsModuleService {
Collection<ModuleReference> getYangResourcesModuleReferences(String dataspaceName, String anchorName);
/**
+ * Retrieve module definitions for the given dataspace name and anchor name.
+ *
+ * @param dataspaceName dataspace name
+ * @param anchorName anchor name
+ * @return a collection of module definitions (moduleName, revision, yang resource content)
+ */
+ Collection<ModuleDefinition> getModuleDefinitionsByAnchorName(String dataspaceName, String anchorName);
+
+ /**
* Identify previously unknown Yang Resource module references.
* The system will ignore the namespace of all module references.
*
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 db8a81f276..ff725a617f 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
@@ -31,6 +31,7 @@ import org.onap.cps.spi.CascadeDeleteAllowed;
import org.onap.cps.spi.CpsModulePersistenceService;
import org.onap.cps.spi.exceptions.SchemaSetInUseException;
import org.onap.cps.spi.model.Anchor;
+import org.onap.cps.spi.model.ModuleDefinition;
import org.onap.cps.spi.model.ModuleReference;
import org.onap.cps.spi.model.SchemaSet;
import org.onap.cps.utils.CpsValidator;
@@ -106,6 +107,13 @@ public class CpsModuleServiceImpl implements CpsModuleService {
}
@Override
+ public Collection<ModuleDefinition> getModuleDefinitionsByAnchorName(final String dataspaceName,
+ final String anchorName) {
+ CpsValidator.validateNameCharacters(dataspaceName, anchorName);
+ return cpsModulePersistenceService.getYangResourceDefinitions(dataspaceName, anchorName);
+ }
+
+ @Override
public Collection<ModuleReference> identifyNewModuleReferences(
final Collection<ModuleReference> moduleReferencesToCheck) {
return cpsModulePersistenceService.identifyNewModuleReferences(moduleReferencesToCheck);
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 0e90e84f1e..db2cb60f34 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
@@ -23,6 +23,7 @@ package org.onap.cps.spi;
import java.util.Collection;
import java.util.Map;
+import org.onap.cps.spi.model.ModuleDefinition;
import org.onap.cps.spi.model.ModuleReference;
/**
@@ -89,11 +90,20 @@ public interface CpsModulePersistenceService {
*
* @param dataspaceName dataspace name
* @param anchorName anchor name
- * @return a collection of module names and revisions
+ * @return a collection of module reference (moduleName and revision)
*/
Collection<ModuleReference> getYangResourceModuleReferences(String dataspaceName, String anchorName);
/**
+ * Get YANG resource definitions for the given anchor name and dataspace name.
+ *
+ * @param dataspaceName dataspace name
+ * @param anchorName anchor name
+ * @return a collection of module definitions (moduleName, revision and yang resource content)
+ */
+ Collection<ModuleDefinition> getYangResourceDefinitions(String dataspaceName, String anchorName);
+
+ /**
* Remove unused Yang Resource Modules.
*/
void deleteUnusedYangResourceModules();
diff --git a/cps-service/src/main/java/org/onap/cps/spi/model/ModuleDefinition.java b/cps-service/src/main/java/org/onap/cps/spi/model/ModuleDefinition.java
new file mode 100644
index 0000000000..d7a5b38dcc
--- /dev/null
+++ b/cps-service/src/main/java/org/onap/cps/spi/model/ModuleDefinition.java
@@ -0,0 +1,37 @@
+/*
+ * ============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.spi.model;
+
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class ModuleDefinition extends ModuleReference {
+
+ private static final long serialVersionUID = -6591435720836327732L;
+ private final String content;
+
+ public ModuleDefinition(final String moduleName, final String revision, final String content) {
+ super(moduleName, revision);
+ this.content = content;
+ }
+} \ No newline at end of file
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 95d731478f..429de7d51b 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
@@ -24,7 +24,6 @@ package org.onap.cps.api.impl
import org.onap.cps.TestUtils
import org.onap.cps.api.CpsAdminService
-import org.onap.cps.spi.CascadeDeleteAllowed
import org.onap.cps.spi.CpsModulePersistenceService
import org.onap.cps.spi.exceptions.DataValidationException
import org.onap.cps.spi.exceptions.ModelValidationException
@@ -243,4 +242,11 @@ class CpsModuleServiceImplSpec extends Specification {
then: 'cps module persistence service is called with module references to check'
1 * mockCpsModulePersistenceService.identifyNewModuleReferences(moduleReferencesToCheck);
}
+
+ def 'Getting module definitions.'() {
+ when: 'get module definitions method is called with a valid dataspace and anchor name'
+ objectUnderTest.getModuleDefinitionsByAnchorName('some-dataspace-name', 'some-anchor-name')
+ then: 'CPS module persistence service is invoked the correct number of times'
+ 1 * mockCpsModulePersistenceService.getYangResourceDefinitions('some-dataspace-name', 'some-anchor-name')
+ }
}
diff --git a/cps-service/src/test/groovy/org/onap/cps/utils/JsonObjectMapperSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/utils/JsonObjectMapperSpec.groovy
index acb52413f8..461014418e 100644
--- a/cps-service/src/test/groovy/org/onap/cps/utils/JsonObjectMapperSpec.groovy
+++ b/cps-service/src/test/groovy/org/onap/cps/utils/JsonObjectMapperSpec.groovy
@@ -22,6 +22,7 @@ package org.onap.cps.utils
import com.fasterxml.jackson.databind.ObjectMapper
+import com.fasterxml.jackson.databind.SerializationFeature
import groovy.json.JsonSlurper
import org.onap.cps.TestUtils
import org.onap.cps.spi.exceptions.DataValidationException
@@ -79,10 +80,12 @@ class JsonObjectMapperSpec extends Specification {
def 'Map a unstructured object to json String.'() {
given: 'Unstructured object'
def object = new Object()
+ and: 'disable serialization failure on empty bean'
+ spiedObjectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
when: 'the object is mapped to string'
jsonObjectMapper.asJsonString(object);
- then: 'an exception is thrown'
- thrown(DataValidationException)
+ then: 'no exception is thrown'
+ noExceptionThrown()
}
def 'Map a structurally compatible json String to JsonNode.'() {