diff options
author | lukegleeson <luke.gleeson@est.tech> | 2023-03-13 15:00:19 +0000 |
---|---|---|
committer | lukegleeson <luke.gleeson@est.tech> | 2023-03-14 12:05:23 +0000 |
commit | 6f93cead4a2adc13bad1ca1f2c3dcd81420477f0 (patch) | |
tree | 9eb707556231415ba3e99f7a328a624cbdf2fdfd /cps-ncmp-service/src/main/java | |
parent | 692f1ceff7934bb60ee9604d70b249c174081a4a (diff) |
subscription-registry node in subscription loader
Adding top node subscription-registry for the adding of subscriptions
Issue-ID: CPS-1548
Signed-off-by: lukegleeson <luke.gleeson@est.tech>
Change-Id: I4107293ce023e4c53dbb8b5d3feb0922cc3d4817
Diffstat (limited to 'cps-ncmp-service/src/main/java')
-rw-r--r-- | cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/SubscriptionModelLoader.java | 20 |
1 files changed, 20 insertions, 0 deletions
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/SubscriptionModelLoader.java index 0d82bb5c1c..705c9d2664 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/SubscriptionModelLoader.java @@ -22,11 +22,13 @@ package org.onap.cps.ncmp.init; import java.io.InputStream; import java.nio.charset.StandardCharsets; +import java.time.OffsetDateTime; import java.util.Map; import lombok.NonNull; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.onap.cps.api.CpsAdminService; +import org.onap.cps.api.CpsDataService; import org.onap.cps.api.CpsModuleService; import org.onap.cps.ncmp.api.impl.exception.NcmpStartUpException; import org.onap.cps.spi.exceptions.AlreadyDefinedException; @@ -42,9 +44,11 @@ public class SubscriptionModelLoader implements ModelLoader { private final CpsAdminService cpsAdminService; private final CpsModuleService cpsModuleService; + private final CpsDataService cpsDataService; private static final String SUBSCRIPTION_DATASPACE_NAME = "NCMP-Admin"; private static final String SUBSCRIPTION_ANCHOR_NAME = "AVC-Subscriptions"; private static final String SUBSCRIPTION_SCHEMASET_NAME = "subscriptions"; + private static final String SUBSCRIPTION_REGISTRY_DATANODE_NAME = "subscription-registry"; @Value("${ncmp.model-loader.subscription:false}") private boolean subscriptionModelLoaderEnabled; @@ -76,6 +80,8 @@ public class SubscriptionModelLoader implements ModelLoader { if (!yangResourceContentMap.get("subscription.yang").isEmpty()) { createSchemaSet(SUBSCRIPTION_DATASPACE_NAME, SUBSCRIPTION_SCHEMASET_NAME, yangResourceContentMap); createAnchor(SUBSCRIPTION_DATASPACE_NAME, SUBSCRIPTION_SCHEMASET_NAME, SUBSCRIPTION_ANCHOR_NAME); + createTopLevelDataNode(SUBSCRIPTION_DATASPACE_NAME, SUBSCRIPTION_ANCHOR_NAME, + SUBSCRIPTION_REGISTRY_DATANODE_NAME); } } @@ -116,6 +122,20 @@ public class SubscriptionModelLoader implements ModelLoader { return true; } + private void createTopLevelDataNode(final String dataspaceName, + final String anchorName, + final String dataNodeName) { + final String nodeData = "{\"" + dataNodeName + "\":{}}"; + try { + cpsDataService.saveData(dataspaceName, anchorName, nodeData, OffsetDateTime.now()); + } catch (final AlreadyDefinedException exception) { + log.info("Creating new data node {} failed as data node already exists", dataNodeName); + } catch (final Exception exception) { + log.debug("Creating data node for subscription model failed: {}", exception.getMessage()); + throw new NcmpStartUpException("Creating data node failed", exception.getMessage()); + } + } + private String getFileContentAsString() { try (InputStream inputStream = getClass().getClassLoader() .getResourceAsStream("model/subscription.yang")) { |