aboutsummaryrefslogtreecommitdiffstats
path: root/cps-service
diff options
context:
space:
mode:
Diffstat (limited to 'cps-service')
-rw-r--r--cps-service/pom.xml2
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java27
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java16
-rwxr-xr-xcps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java17
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy32
5 files changed, 62 insertions, 32 deletions
diff --git a/cps-service/pom.xml b/cps-service/pom.xml
index bfc3931bc8..9c7031e2f8 100644
--- a/cps-service/pom.xml
+++ b/cps-service/pom.xml
@@ -28,7 +28,7 @@
<parent>
<groupId>org.onap.cps</groupId>
<artifactId>cps-parent</artifactId>
- <version>2.1.0-SNAPSHOT</version>
+ <version>3.0.0-SNAPSHOT</version>
<relativePath>../cps-parent/pom.xml</relativePath>
</parent>
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 1dccf49c9b..6ae28fe9c3 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
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2020 Nordix Foundation
+ * Copyright (C) 2020-2022 Nordix Foundation
* Modifications Copyright (C) 2020-2021 Pantheon.tech
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,7 +22,6 @@
package org.onap.cps.api;
import java.util.Collection;
-import java.util.List;
import java.util.Map;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.onap.cps.spi.CascadeDeleteAllowed;
@@ -48,16 +47,14 @@ public interface CpsModuleService {
/**
* Create a schema set from new modules and existing modules.
- *
- * @param dataspaceName Dataspace name
- * @param schemaSetName schema set name
- * @param newYangResourcesModuleNameToContentMap YANG resources map where key is a module name and value is content
- * @param moduleReferences List of YANG resources module references of the modules
- * needed for this handle that are already in CPS
+ * @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 moduleReferences List of YANG resources module references of the modules
*/
void createSchemaSetFromModules(@NonNull String dataspaceName, @NonNull String schemaSetName,
- @NonNull Map<String, String> newYangResourcesModuleNameToContentMap,
- @NonNull List<ModuleReference> moduleReferences);
+ @NonNull Map<String, String> newModuleNameToContentMap,
+ Collection<ModuleReference> moduleReferences);
/**
* Read schema set in the given dataspace.
@@ -96,4 +93,14 @@ public interface CpsModuleService {
* @return a list of ModuleReference objects
*/
Collection<ModuleReference> getYangResourcesModuleReferences(String dataspaceName, String anchorName);
+
+ /**
+ * Identify previously unknown Yang Resource module references.
+ *
+ * @param moduleReferencesToCheck the moduleReferencesToCheck
+ * @returns collection of module references
+ */
+ Collection<ModuleReference> identifyNewModuleReferences(
+ Collection<ModuleReference> moduleReferencesToCheck);
+
}
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 ffcc5a22f6..7267f22b55 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
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2020-2021 Nordix Foundation
+ * Copyright (C) 2020-2022 Nordix Foundation
* Modifications Copyright (C) 2020-2021 Pantheon.tech
* Modifications Copyright (C) 2022 Bell Canada
* ================================================================================
@@ -23,7 +23,6 @@
package org.onap.cps.api.impl;
import java.util.Collection;
-import java.util.List;
import java.util.Map;
import lombok.AllArgsConstructor;
import org.onap.cps.api.CpsAdminService;
@@ -57,10 +56,10 @@ public class CpsModuleServiceImpl implements CpsModuleService {
@Override
public void createSchemaSetFromModules(final String dataspaceName, final String schemaSetName,
- final Map<String, String> newYangResourcesModuleNameToContentMap,
- final List<ModuleReference> moduleReferences) {
+ final Map<String, String> newModuleNameToContentMap,
+ final Collection<ModuleReference> moduleReferences) {
cpsModulePersistenceService.storeSchemaSetFromModules(dataspaceName, schemaSetName,
- newYangResourcesModuleNameToContentMap, moduleReferences);
+ newModuleNameToContentMap, moduleReferences);
}
@@ -102,4 +101,11 @@ public class CpsModuleServiceImpl implements CpsModuleService {
private boolean isCascadeDeleteProhibited(final CascadeDeleteAllowed cascadeDeleteAllowed) {
return CascadeDeleteAllowed.CASCADE_DELETE_PROHIBITED == cascadeDeleteAllowed;
}
+
+ @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 e082734417..4306df78da 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
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2020 Nordix Foundation
+ * Copyright (C) 2020-2022 Nordix Foundation
* Modifications Copyright (C) 2020-2022 Bell Canada.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,7 +22,6 @@
package org.onap.cps.spi;
import java.util.Collection;
-import java.util.List;
import java.util.Map;
import org.onap.cps.spi.model.ModuleReference;
@@ -45,11 +44,11 @@ public interface CpsModulePersistenceService {
*
* @param dataspaceName Dataspace name
* @param schemaSetName Schema set name
- * @param newYangResourcesModuleNameToContentMap YANG resources map where key is a module name and value is content
+ * @param newModuleNameToContentMap YANG resources map where key is a module name and value is content
* @param moduleReferences List of YANG resources module references
*/
void storeSchemaSetFromModules(String dataspaceName, String schemaSetName,
- Map<String, String> newYangResourcesModuleNameToContentMap, List<ModuleReference> moduleReferences);
+ Map<String, String> newModuleNameToContentMap, Collection<ModuleReference> moduleReferences);
/**
* Deletes Schema Set.
@@ -98,4 +97,14 @@ public interface CpsModulePersistenceService {
* Remove unused Yang Resource Modules.
*/
void deleteUnusedYangResourceModules();
+
+ /**
+ * Identify new module references from those returned by a node compared to what is in CPS already.
+ *
+ * @param moduleReferencesToCheck the module references ot check
+ * @returns Collection of {@link ModuleReference} of previously unknown module references
+ */
+ Collection<ModuleReference> identifyNewModuleReferences(
+ Collection<ModuleReference> moduleReferencesToCheck);
+
}
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 67dce1daf6..afd8e8666f 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
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2020-2021 Nordix Foundation
+ * Copyright (C) 2020-2022 Nordix Foundation
* Modifications Copyright (C) 2020-2021 Pantheon.tech
* Modifications Copyright (C) 2020-2022 Bell Canada.
* ================================================================================
@@ -37,11 +37,11 @@ import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_PROHIBITED
class CpsModuleServiceImplSpec extends Specification {
- def mockModuleStoreService = Mock(CpsModulePersistenceService)
+ def mockCpsModulePersistenceService = Mock(CpsModulePersistenceService)
def mockCpsAdminService = Mock(CpsAdminService)
def mockYangTextSchemaSourceSetCache = Mock(YangTextSchemaSourceSetCache)
- def objectUnderTest = new CpsModuleServiceImpl(mockModuleStoreService, mockYangTextSchemaSourceSetCache, mockCpsAdminService)
+ def objectUnderTest = new CpsModuleServiceImpl(mockCpsModulePersistenceService, mockYangTextSchemaSourceSetCache, mockCpsAdminService)
def 'Create schema set.'() {
given: 'Valid yang resource as name-to-content map'
@@ -49,7 +49,7 @@ class CpsModuleServiceImplSpec extends Specification {
when: 'Create schema set method is invoked'
objectUnderTest.createSchemaSet('someDataspace', 'someSchemaSet', yangResourcesNameToContentMap)
then: 'Parameters are validated and processing is delegated to persistence service'
- 1 * mockModuleStoreService.storeSchemaSet('someDataspace', 'someSchemaSet', yangResourcesNameToContentMap)
+ 1 * mockCpsModulePersistenceService.storeSchemaSet('someDataspace', 'someSchemaSet', yangResourcesNameToContentMap)
}
def 'Create schema set from new modules and existing modules.'() {
@@ -59,8 +59,7 @@ class CpsModuleServiceImplSpec extends Specification {
when: 'create schema set from modules method is invoked'
objectUnderTest.createSchemaSetFromModules("someDataspaceName", "someSchemaSetName", [newModule: "newContent"], listOfExistingModulesModuleReference)
then: 'processing is delegated to persistence service'
- 1 * mockModuleStoreService.storeSchemaSetFromModules("someDataspaceName", "someSchemaSetName", [newModule: "newContent"], listOfExistingModulesModuleReference)
-
+ 1 * mockCpsModulePersistenceService.storeSchemaSetFromModules("someDataspaceName", "someSchemaSetName", [newModule: "newContent"], listOfExistingModulesModuleReference)
}
def 'Create schema set from invalid resources'() {
@@ -94,11 +93,11 @@ class CpsModuleServiceImplSpec extends Specification {
then: 'anchor deletion is called #numberOfAnchors times'
numberOfAnchors * mockCpsAdminService.deleteAnchor('my-dataspace', _)
and: 'persistence service method is invoked with same parameters'
- 1 * mockModuleStoreService.deleteSchemaSet('my-dataspace', 'my-schemaset')
+ 1 * mockCpsModulePersistenceService.deleteSchemaSet('my-dataspace', 'my-schemaset')
and: 'schema set will be removed from the cache'
1 * mockYangTextSchemaSourceSetCache.removeFromCache('my-dataspace', 'my-schemaset')
and: 'orphan yang resources are deleted'
- 1 * mockModuleStoreService.deleteUnusedYangResourceModules()
+ 1 * mockCpsModulePersistenceService.deleteUnusedYangResourceModules()
where: 'following parameters are used'
numberOfAnchors << [0, 3]
}
@@ -111,11 +110,11 @@ class CpsModuleServiceImplSpec extends Specification {
then: 'no anchors are deleted'
0 * mockCpsAdminService.deleteAnchor(_, _)
and: 'persistence service method is invoked with same parameters'
- 1 * mockModuleStoreService.deleteSchemaSet('my-dataspace', 'my-schemaset')
+ 1 * mockCpsModulePersistenceService.deleteSchemaSet('my-dataspace', 'my-schemaset')
and: 'schema set will be removed from the cache'
1 * mockYangTextSchemaSourceSetCache.removeFromCache('my-dataspace', 'my-schemaset')
and: 'orphan yang resources are deleted'
- 1 * mockModuleStoreService.deleteUnusedYangResourceModules()
+ 1 * mockCpsModulePersistenceService.deleteUnusedYangResourceModules()
}
def 'Delete schema-set when cascade is prohibited and schema-set has anchors.'() {
@@ -136,7 +135,7 @@ class CpsModuleServiceImplSpec extends Specification {
def 'Get all yang resources module references.'() {
given: 'an already present module reference'
def moduleReferences = [new ExtendedModuleReference()]
- mockModuleStoreService.getYangResourceModuleReferences('someDataspaceName') >> moduleReferences
+ mockCpsModulePersistenceService.getYangResourceModuleReferences('someDataspaceName') >> moduleReferences
expect: 'the list provided by persistence service is returned as result'
objectUnderTest.getYangResourceModuleReferences('someDataspaceName') == moduleReferences
}
@@ -145,8 +144,17 @@ class CpsModuleServiceImplSpec extends Specification {
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
+ mockCpsModulePersistenceService.getYangResourceModuleReferences('someDataspaceName', 'someAnchorName') >> moduleReferences
expect: 'the list provided by persistence service is returned as result'
objectUnderTest.getYangResourcesModuleReferences('someDataspaceName', 'someAnchorName') == moduleReferences
}
+
+ def 'Identifying new module references'(){
+ given: 'module references from cm handle'
+ def moduleReferencesToCheck = [new ModuleReference('some-module', 'some-revision')]
+ when: 'identifyNewModuleReferences is called'
+ objectUnderTest.identifyNewModuleReferences(moduleReferencesToCheck)
+ then: 'cps module persistence service is called with module references to check'
+ 1 * mockCpsModulePersistenceService.identifyNewModuleReferences(moduleReferencesToCheck);
+ }
}