Onboard merge subscriptions model 95/136595/9
authoremaclee <lee.anjella.macabuhay@est.tech>
Mon, 20 Nov 2023 09:25:40 +0000 (09:25 +0000)
committeremaclee <lee.anjella.macabuhay@est.tech>
Tue, 21 Nov 2023 16:33:26 +0000 (16:33 +0000)
-Add new model in subscription
-Update unit tests for uploading models using modelLoader
-Modify abstract model loaders to handle more than one
yangResource in creating schema set
-Modifying use of the basic subscription model to the new model
will be on a seperate commit

Issue-ID: CPS-1928
Signed-off-by: emaclee <lee.anjella.macabuhay@est.tech>
Change-Id: I5805ab8c721e8a63726fd210379e815b84b387a3

cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/AbstractModelLoader.java
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/CmDataSubscriptionModelLoader.java [moved from cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/SubscriptionModelLoader.java with 58% similarity]
cps-ncmp-service/src/main/resources/models/cm-data-subscriptions@2023-11-13.yang [new file with mode: 0644]
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/EventPublisherSpec.groovy
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/AbstractModelLoaderSpec.groovy
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/CmDataSubscriptionModelLoaderSpec.groovy [moved from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/SubscriptionModelLoaderSpec.groovy with 84% similarity]
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/InventoryModelLoaderSpec.groovy

index cb2e15a..fd5f2b0 100644 (file)
@@ -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) {
@@ -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 (file)
index 0000000..de675b1
--- /dev/null
@@ -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;
+              }
+
+            }
+          }
+        }
+      }
+    }
+  }
+}
index d0f1afd..0e06383 100644 (file)
@@ -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
index 28eae8d..e5ed21f 100644 (file)
@@ -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()
     }
 
@@ -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.' () {
index 16ab0b8..43e0f69 100644 (file)
@@ -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()
     }