diff options
Diffstat (limited to 'cps-ncmp-service/src/main/java/org')
2 files changed, 31 insertions, 3 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/notifications/avc/AvcEventConsumer.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/notifications/avc/AvcEventConsumer.java index 79a36bf506..58290a7e9d 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/notifications/avc/AvcEventConsumer.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/notifications/avc/AvcEventConsumer.java @@ -44,7 +44,7 @@ public class AvcEventConsumer { * @param avcEvent the event to be consumed and produced. */ @KafkaListener( - topics = "dmi-cm-events", + topics = "${app.dmi.cm-events.topic}", properties = {"spring.json.value.default.type=org.onap.cps.ncmp.event.model.AvcEvent"}) public void consumeAndForward(final AvcEvent avcEvent) { log.debug("Consuming AVC event {} ...", avcEvent); 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 6713491e6e..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,14 +22,17 @@ 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; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.stereotype.Component; @@ -41,9 +44,14 @@ 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; /** * Method calls boarding subscription model when Application is ready. @@ -53,7 +61,11 @@ public class SubscriptionModelLoader implements ModelLoader { @Override public void onApplicationEvent(@NonNull final ApplicationReadyEvent applicationReadyEvent) { try { - onboardSubscriptionModel(); + if (subscriptionModelLoaderEnabled) { + onboardSubscriptionModel(); + } else { + log.info("Subscription Model Loader is disabled"); + } } catch (final NcmpStartUpException ncmpStartUpException) { log.debug("Onboarding model for NCMP failed: {} ", ncmpStartUpException.getMessage()); SpringApplication.exit(applicationReadyEvent.getApplicationContext(), () -> 1); @@ -68,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); } } @@ -108,8 +122,22 @@ 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 = ClassLoader.getSystemClassLoader() + try (InputStream inputStream = getClass().getClassLoader() .getResourceAsStream("model/subscription.yang")) { return new String(inputStream.readAllBytes(), StandardCharsets.UTF_8); } catch (final Exception exception) { |