diff options
author | emaclee <lee.anjella.macabuhay@est.tech> | 2023-11-20 09:25:40 +0000 |
---|---|---|
committer | emaclee <lee.anjella.macabuhay@est.tech> | 2023-11-21 16:33:26 +0000 |
commit | 8090317460b8076f128fd8da46873135b007e2fd (patch) | |
tree | 65967aaf3e5f67361f0f58ea9112dc0f2434bf85 /cps-ncmp-service/src/main/java | |
parent | 2240e46412ca11a6deb4b678b52e4e242e298b03 (diff) |
Onboard merge subscriptions model
-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
Diffstat (limited to 'cps-ncmp-service/src/main/java')
-rw-r--r-- | cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/AbstractModelLoader.java | 15 | ||||
-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 |
2 files changed, 32 insertions, 17 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); } - } |