summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ncmp-service')
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/AbstractModelLoader.java15
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/CmDataSubscriptionModelLoader.java (renamed from cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/SubscriptionModelLoader.java)34
-rw-r--r--cps-ncmp-service/src/main/resources/models/cm-data-subscriptions@2023-11-13.yang49
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/EventPublisherSpec.groovy4
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/AbstractModelLoaderSpec.groovy4
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/CmDataSubscriptionModelLoaderSpec.groovy (renamed from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/SubscriptionModelLoaderSpec.groovy)16
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/InventoryModelLoaderSpec.groovy4
7 files changed, 95 insertions, 31 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/AbstractModelLoader.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/AbstractModelLoader.java
index cb2e15a3ce..fd5f2b0ed6 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/AbstractModelLoader.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/AbstractModelLoader.java
@@ -24,6 +24,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.time.OffsetDateTime;
+import java.util.HashMap;
import java.util.Map;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
@@ -85,10 +86,10 @@ abstract class AbstractModelLoader implements ModelLoader {
}
}
- void createSchemaSet(final String dataspaceName, final String schemaSetName, final String resourceName) {
+ void createSchemaSet(final String dataspaceName, final String schemaSetName, final String... resourceNames) {
try {
- final Map<String, String> yangResourceContentMap = createYangResourceToContentMap(resourceName);
- cpsModuleService.createSchemaSet(dataspaceName, schemaSetName, yangResourceContentMap);
+ final Map<String, String> yangResourcesContentMap = createYangResourcesToContentMap(resourceNames);
+ cpsModuleService.createSchemaSet(dataspaceName, schemaSetName, yangResourcesContentMap);
} catch (final AlreadyDefinedException alreadyDefinedException) {
log.warn("Creating new schema set failed as schema set already exists");
} catch (final Exception exception) {
@@ -140,8 +141,12 @@ abstract class AbstractModelLoader implements ModelLoader {
}
}
- Map<String, String> createYangResourceToContentMap(final String resourceName) {
- return Map.of(resourceName, getFileContentAsString("models/" + resourceName));
+ Map<String, String> createYangResourcesToContentMap(final String... resourceNames) {
+ final Map<String, String> yangResourcesToContentMap = new HashMap<>();
+ for (final String resourceName: resourceNames) {
+ yangResourcesToContentMap.put(resourceName, getFileContentAsString("models/" + resourceName));
+ }
+ return yangResourcesToContentMap;
}
private String getFileContentAsString(final String fileName) {
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/SubscriptionModelLoader.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/CmDataSubscriptionModelLoader.java
index 4d1a91ca99..ade31e9ce6 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/SubscriptionModelLoader.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/CmDataSubscriptionModelLoader.java
@@ -31,16 +31,23 @@ import org.springframework.stereotype.Service;
@Slf4j
@Service
-public class SubscriptionModelLoader extends AbstractModelLoader {
+public class CmDataSubscriptionModelLoader extends AbstractModelLoader {
- private static final String MODEL_FILENAME = "subscription.yang";
- private static final String ANCHOR_NAME = "AVC-Subscriptions";
- private static final String SCHEMASET_NAME = "subscriptions";
- private static final String REGISTRY_DATANODE_NAME = "subscription-registry";
+ private static final String MODEL_FILENAME = "cm-data-subscriptions@2023-11-13.yang";
+ private static final String SCHEMASET_NAME = "cm-data-subscriptions";
+ private static final String ANCHOR_NAME = "cm-data-subscriptions";
+ private static final String REGISTRY_DATANODE_NAME = "datastores";
- public SubscriptionModelLoader(final CpsAdminService cpsAdminService,
- final CpsModuleService cpsModuleService,
- final CpsDataService cpsDataService) {
+ private static final String DEPRECATED_MODEL_FILENAME = "subscription.yang";
+ private static final String DEPRECATED_ANCHOR_NAME = "AVC-Subscriptions";
+ private static final String DEPRECATED_SCHEMASET_NAME = "subscriptions";
+ private static final String DEPRECATED_REGISTRY_DATANODE_NAME = "subscription-registry";
+
+
+
+ public CmDataSubscriptionModelLoader(final CpsAdminService cpsAdminService,
+ final CpsModuleService cpsModuleService,
+ final CpsDataService cpsDataService) {
super(cpsAdminService, cpsModuleService, cpsDataService);
}
@@ -51,17 +58,20 @@ public class SubscriptionModelLoader extends AbstractModelLoader {
public void onboardOrUpgradeModel() {
if (subscriptionModelLoaderEnabled) {
waitUntilDataspaceIsAvailable(NCMP_DATASPACE_NAME);
- onboardSubscriptionModel();
- log.info("Subscription Model onboarded successfully");
+ onboardSubscriptionModels();
+ log.info("Subscription Models onboarded successfully");
} else {
log.info("Subscription Model Loader is disabled");
}
}
- private void onboardSubscriptionModel() {
+ private void onboardSubscriptionModels() {
+ createSchemaSet(NCMP_DATASPACE_NAME, DEPRECATED_SCHEMASET_NAME, DEPRECATED_MODEL_FILENAME);
+ createAnchor(NCMP_DATASPACE_NAME, DEPRECATED_SCHEMASET_NAME, DEPRECATED_ANCHOR_NAME);
+ createTopLevelDataNode(NCMP_DATASPACE_NAME, DEPRECATED_ANCHOR_NAME, DEPRECATED_REGISTRY_DATANODE_NAME);
+
createSchemaSet(NCMP_DATASPACE_NAME, SCHEMASET_NAME, MODEL_FILENAME);
createAnchor(NCMP_DATASPACE_NAME, SCHEMASET_NAME, ANCHOR_NAME);
createTopLevelDataNode(NCMP_DATASPACE_NAME, ANCHOR_NAME, REGISTRY_DATANODE_NAME);
}
-
}
diff --git a/cps-ncmp-service/src/main/resources/models/cm-data-subscriptions@2023-11-13.yang b/cps-ncmp-service/src/main/resources/models/cm-data-subscriptions@2023-11-13.yang
new file mode 100644
index 0000000000..de675b117c
--- /dev/null
+++ b/cps-ncmp-service/src/main/resources/models/cm-data-subscriptions@2023-11-13.yang
@@ -0,0 +1,49 @@
+module cm-data-subscriptions {
+ yang-version 1.1;
+ namespace "org:onap:cps:ncmp";
+
+ prefix cmds;
+
+ revision "2023-11-13" {
+ description
+ "First release of cm data (notification) subscriptions model";
+ }
+
+ container datastores {
+
+ list datastore {
+ key "name";
+
+ leaf name {
+ type string;
+ }
+
+ container cm-handles {
+
+ list cm-handle {
+ key "id";
+
+ leaf id {
+ type string;
+ }
+
+ container filters {
+
+ list filter {
+ key "xpath";
+
+ leaf xpath {
+ type string;
+ }
+
+ leaf-list subscribers {
+ type string;
+ }
+
+ }
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/EventPublisherSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/EventPublisherSpec.groovy
index d0f1afd5d5..0e063834e4 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/EventPublisherSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/EventPublisherSpec.groovy
@@ -26,7 +26,7 @@ import ch.qos.logback.core.read.ListAppender
import org.apache.kafka.clients.producer.ProducerRecord
import org.apache.kafka.clients.producer.RecordMetadata
import org.apache.kafka.common.TopicPartition
-import org.onap.cps.ncmp.init.SubscriptionModelLoader
+import org.onap.cps.ncmp.init.CmDataSubscriptionModelLoader
import org.slf4j.LoggerFactory
import org.springframework.kafka.support.SendResult
import spock.lang.Ignore
@@ -46,7 +46,7 @@ class EventPublisherSpec extends Specification {
}
void cleanup() {
- ((Logger) LoggerFactory.getLogger(SubscriptionModelLoader.class)).detachAndStopAllAppenders()
+ ((Logger) LoggerFactory.getLogger(CmDataSubscriptionModelLoader.class)).detachAndStopAllAppenders()
}
@Ignore
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/AbstractModelLoaderSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/AbstractModelLoaderSpec.groovy
index 28eae8df14..e5ed21f1c4 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/AbstractModelLoaderSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/AbstractModelLoaderSpec.groovy
@@ -49,7 +49,7 @@ class AbstractModelLoaderSpec extends Specification {
def loggingListAppender
void setup() {
- yangResourceToContentMap = objectUnderTest.createYangResourceToContentMap('subscription.yang')
+ yangResourceToContentMap = objectUnderTest.createYangResourcesToContentMap('subscription.yang')
logger.setLevel(Level.DEBUG)
loggingListAppender = new ListAppender()
logger.addAppender(loggingListAppender)
@@ -58,7 +58,7 @@ class AbstractModelLoaderSpec extends Specification {
}
void cleanup() {
- ((Logger) LoggerFactory.getLogger(SubscriptionModelLoader.class)).detachAndStopAllAppenders()
+ ((Logger) LoggerFactory.getLogger(CmDataSubscriptionModelLoader.class)).detachAndStopAllAppenders()
applicationContext.close()
}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/SubscriptionModelLoaderSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/CmDataSubscriptionModelLoaderSpec.groovy
index 3486316a0a..06627129a9 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/SubscriptionModelLoaderSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/CmDataSubscriptionModelLoaderSpec.groovy
@@ -34,21 +34,21 @@ import org.springframework.boot.context.event.ApplicationReadyEvent
import org.springframework.context.annotation.AnnotationConfigApplicationContext
import spock.lang.Specification
-class SubscriptionModelLoaderSpec extends Specification {
+class CmDataSubscriptionModelLoaderSpec extends Specification {
def mockCpsAdminService = Mock(CpsAdminService)
def mockCpsModuleService = Mock(CpsModuleService)
def mockCpsDataService = Mock(CpsDataService)
- def objectUnderTest = new SubscriptionModelLoader(mockCpsAdminService, mockCpsModuleService, mockCpsDataService)
+ def objectUnderTest = new CmDataSubscriptionModelLoader(mockCpsAdminService, mockCpsModuleService, mockCpsDataService)
def applicationContext = new AnnotationConfigApplicationContext()
- def expectedYangResourceToContentMap
+ def expectedYangResourcesToContentMap
def logger = (Logger) LoggerFactory.getLogger(objectUnderTest.class)
def loggingListAppender
void setup() {
- expectedYangResourceToContentMap = objectUnderTest.createYangResourceToContentMap('subscription.yang')
+ expectedYangResourcesToContentMap = objectUnderTest.createYangResourcesToContentMap('cm-data-subscriptions@2023-11-13.yang')
logger.setLevel(Level.DEBUG)
loggingListAppender = new ListAppender()
logger.addAppender(loggingListAppender)
@@ -57,7 +57,7 @@ class SubscriptionModelLoaderSpec extends Specification {
}
void cleanup() {
- ((Logger) LoggerFactory.getLogger(SubscriptionModelLoader.class)).detachAndStopAllAppenders()
+ ((Logger) LoggerFactory.getLogger(CmDataSubscriptionModelLoader.class)).detachAndStopAllAppenders()
applicationContext.close()
}
@@ -69,11 +69,11 @@ class SubscriptionModelLoaderSpec extends Specification {
when: 'the application is ready'
objectUnderTest.onApplicationEvent(Mock(ApplicationReadyEvent))
then: 'the module service to create schema set is called once'
- 1 * mockCpsModuleService.createSchemaSet(NCMP_DATASPACE_NAME, 'subscriptions', expectedYangResourceToContentMap)
+ 1 * mockCpsModuleService.createSchemaSet(NCMP_DATASPACE_NAME, 'cm-data-subscriptions', expectedYangResourcesToContentMap)
and: 'the admin service to create an anchor set is called once'
- 1 * mockCpsAdminService.createAnchor(NCMP_DATASPACE_NAME, 'subscriptions', 'AVC-Subscriptions')
+ 1 * mockCpsAdminService.createAnchor(NCMP_DATASPACE_NAME, 'cm-data-subscriptions', 'cm-data-subscriptions')
and: 'the data service to create a top level datanode is called once'
- 1 * mockCpsDataService.saveData(NCMP_DATASPACE_NAME, 'AVC-Subscriptions', '{"subscription-registry":{}}', _)
+ 1 * mockCpsDataService.saveData(NCMP_DATASPACE_NAME, 'cm-data-subscriptions', '{"datastores":{}}', _)
}
def 'Subscription model loader disabled.' () {
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/InventoryModelLoaderSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/InventoryModelLoaderSpec.groovy
index 16ab0b8846..43e0f69b3f 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/InventoryModelLoaderSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/InventoryModelLoaderSpec.groovy
@@ -49,7 +49,7 @@ class InventoryModelLoaderSpec extends Specification {
def loggingListAppender
void setup() {
- expectedYangResourceToContentMap = objectUnderTest.createYangResourceToContentMap('dmi-registry@2023-08-23.yang')
+ expectedYangResourceToContentMap = objectUnderTest.createYangResourcesToContentMap('dmi-registry@2023-08-23.yang')
logger.setLevel(Level.DEBUG)
loggingListAppender = new ListAppender()
logger.addAppender(loggingListAppender)
@@ -58,7 +58,7 @@ class InventoryModelLoaderSpec extends Specification {
}
void cleanup() {
- ((Logger) LoggerFactory.getLogger(SubscriptionModelLoader.class)).detachAndStopAllAppenders()
+ ((Logger) LoggerFactory.getLogger(CmDataSubscriptionModelLoader.class)).detachAndStopAllAppenders()
applicationContext.close()
}