aboutsummaryrefslogtreecommitdiffstats
path: root/cps-service
diff options
context:
space:
mode:
Diffstat (limited to 'cps-service')
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java15
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java17
-rwxr-xr-xcps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java15
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy34
4 files changed, 65 insertions, 16 deletions
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 e8c3e7775c..2928464461 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
@@ -53,7 +53,7 @@ public interface CpsModuleService {
* @param newModuleNameToContentMap YANG resources map where key is a module name and value is content
* @param allModuleReferences All YANG resource module references
*/
- void createOrUpgradeSchemaSetFromModules(String dataspaceName, String schemaSetName,
+ void createSchemaSetFromModules(String dataspaceName, String schemaSetName,
Map<String, String> newModuleNameToContentMap,
Collection<ModuleReference> allModuleReferences);
@@ -94,6 +94,19 @@ public interface CpsModuleService {
*/
void deleteSchemaSetsWithCascade(String dataspaceName, Collection<String> schemaSetNames);
+
+ /**
+ * upgrade schema sets with existing or new modules.
+ *
+ * @param dataspaceName dataspace name
+ * @param schemaSetName schema set name
+ * @param newModuleNameToContentMap YANG resources map where key is a module name and value is content
+ * @param allModuleReferences All YANG resource module references
+ */
+ void upgradeSchemaSetFromModules(final String dataspaceName, final String schemaSetName,
+ final Map<String, String> newModuleNameToContentMap,
+ final Collection<ModuleReference> allModuleReferences);
+
/**
* Retrieve module references for the given dataspace name.
*
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 d274b51bf6..5337237846 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
@@ -66,9 +66,9 @@ public class CpsModuleServiceImpl implements CpsModuleService {
}
@Override
- public void createOrUpgradeSchemaSetFromModules(final String dataspaceName, final String schemaSetName,
- final Map<String, String> newModuleNameToContentMap,
- final Collection<ModuleReference> allModuleReferences) {
+ public void createSchemaSetFromModules(final String dataspaceName, final String schemaSetName,
+ final Map<String, String> newModuleNameToContentMap,
+ final Collection<ModuleReference> allModuleReferences) {
cpsValidator.validateNameCharacters(dataspaceName, schemaSetName);
cpsModulePersistenceService.storeSchemaSetFromModules(dataspaceName, schemaSetName,
newModuleNameToContentMap, allModuleReferences);
@@ -125,6 +125,17 @@ public class CpsModuleServiceImpl implements CpsModuleService {
}
@Override
+ public void upgradeSchemaSetFromModules(final String dataspaceName, final String schemaSetName,
+ final Map<String, String> newModuleNameToContentMap,
+ final Collection<ModuleReference> allModuleReferences) {
+ cpsValidator.validateNameCharacters(dataspaceName, schemaSetName);
+ cpsModulePersistenceService.updateSchemaSetFromModules(dataspaceName, schemaSetName,
+ newModuleNameToContentMap, allModuleReferences);
+ yangTextSchemaSourceSetCache.removeFromCache(dataspaceName, schemaSetName);
+ }
+
+
+ @Override
public Collection<ModuleReference> getYangResourceModuleReferences(final String dataspaceName) {
cpsValidator.validateNameCharacters(dataspaceName);
return cpsModulePersistenceService.getYangResourceModuleReferences(dataspaceName);
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 beb3d4fa8c..aaca2ee5b5 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
@@ -43,7 +43,7 @@ public interface CpsModulePersistenceService {
void storeSchemaSet(String dataspaceName, String schemaSetName, Map<String, String> yangResourcesNameToContentMap);
/**
- * Stores a schema set from new modules and existing modules.
+ * Stores a new schema set from new modules and existing modules.
*
* @param dataspaceName Dataspace name
* @param schemaSetName Schema set name
@@ -54,6 +54,19 @@ public interface CpsModulePersistenceService {
Map<String, String> newModuleNameToContentMap, Collection<ModuleReference> allModuleReferences);
/**
+ * Update an existing schema set from new modules and existing modules.
+ *
+ * @param dataspaceName Dataspace name
+ * @param schemaSetName Schema set name
+ * @param newModuleNameToContentMap YANG resources map where key is a module name and value is content
+ * @param allModuleReferences All YANG resources module references
+ */
+ void updateSchemaSetFromModules(final String dataspaceName, final String schemaSetName,
+ final Map<String, String> newModuleNameToContentMap,
+ final Collection<ModuleReference> allModuleReferences);
+
+
+ /**
* Get all schema sets for a given dataspace.
*
* @param dataspaceName dataspace name.
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 61f67416d2..d8edb02abd 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
@@ -23,6 +23,9 @@
package org.onap.cps.api.impl
+import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_ALLOWED
+import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_PROHIBITED
+
import org.onap.cps.TestUtils
import org.onap.cps.api.CpsAdminService
import org.onap.cps.spi.CpsModulePersistenceService
@@ -38,8 +41,6 @@ import org.onap.cps.yang.TimedYangTextSchemaSourceSetBuilder
import org.onap.cps.yang.YangTextSchemaSourceSet
import org.onap.cps.yang.YangTextSchemaSourceSetBuilder
import spock.lang.Specification
-import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_ALLOWED
-import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_PROHIBITED
class CpsModuleServiceImplSpec extends Specification {
@@ -65,7 +66,7 @@ class CpsModuleServiceImplSpec extends Specification {
def moduleReferenceForExistingModule = new ModuleReference('test', '2021-10-12','test.org')
def listOfExistingModulesModuleReference = [moduleReferenceForExistingModule]
when: 'create schema set from modules method is invoked'
- objectUnderTest.createOrUpgradeSchemaSetFromModules('someDataspaceName', 'someSchemaSetName', [newModule: 'newContent'], listOfExistingModulesModuleReference)
+ objectUnderTest.createSchemaSetFromModules('someDataspaceName', 'someSchemaSetName', [newModule: 'newContent'], listOfExistingModulesModuleReference)
then: 'processing is delegated to persistence service'
1 * mockCpsModulePersistenceService.storeSchemaSetFromModules('someDataspaceName', 'someSchemaSetName', [newModule: 'newContent'], listOfExistingModulesModuleReference)
and: 'the CpsValidator is called on the dataspaceName and schemaSetName'
@@ -175,12 +176,6 @@ class CpsModuleServiceImplSpec extends Specification {
thrown(SchemaSetInUseException)
}
- def createAnchors(int anchorCount) {
- def anchors = []
- (0..<anchorCount).each { anchors.add(new Anchor("my-anchor-$it", 'my-dataspace', 'my-schemaset')) }
- return anchors
- }
-
def 'Delete multiple schema-sets when cascade is allowed.'() {
given: '#numberOfAnchors anchors are associated with each schemaset'
mockCpsAdminService.getAnchors('my-dataspace', ['my-schemaset1', 'my-schemaset2']) >> createAnchors(numberOfAnchors * 2)
@@ -202,9 +197,16 @@ class CpsModuleServiceImplSpec extends Specification {
numberOfAnchors << [0, 3]
}
+ def 'Upgrade existing schema set'() {
+ when: 'schema set update is requested'
+ objectUnderTest.upgradeSchemaSetFromModules('my-dataspace', 'my-schemaset', [:], moduleReferences)
+ then: 'no exception is thrown '
+ noExceptionThrown()
+ }
+
def 'Get all yang resources module references.'() {
given: 'an already present module reference'
- def moduleReferences = [new ModuleReference('some module name','some revision name')]
+ def moduleReferences = getModuleReferences()
mockCpsModulePersistenceService.getYangResourceModuleReferences('someDataspaceName') >> moduleReferences
when: 'get yang resource module references is called'
def result = objectUnderTest.getYangResourceModuleReferences('someDataspaceName')
@@ -228,7 +230,7 @@ class CpsModuleServiceImplSpec extends Specification {
def 'Identifying new module references.'(){
given: 'module references from cm handle'
- def moduleReferencesToCheck = [new ModuleReference('some-module', 'some-revision')]
+ def moduleReferencesToCheck = getModuleReferences()
when: 'identifyNewModuleReferences is called'
objectUnderTest.identifyNewModuleReferences(moduleReferencesToCheck)
then: 'cps module persistence service is called with module references to check'
@@ -246,4 +248,14 @@ class CpsModuleServiceImplSpec extends Specification {
and: 'the CpsValidator is called on the dataspaceName and schemaSetName'
1 * mockCpsValidator.validateNameCharacters('some-dataspace-name', 'some-anchor-name')
}
+
+ def getModuleReferences() {
+ return [new ModuleReference('some module name','some revision name')]
+ }
+
+ def createAnchors(int anchorCount) {
+ def anchors = []
+ (0..<anchorCount).each { anchors.add(new Anchor("my-anchor-$it", 'my-dataspace', 'my-schemaset')) }
+ return anchors
+ }
}