From 2f9e781a7c3e22bf25df83dcc3ff44b885a80957 Mon Sep 17 00:00:00 2001 From: Ravi Pendurty Date: Wed, 3 Feb 2021 14:09:25 +0100 Subject: Adapt SDNR northbound to Aluminium Adapt SDNR northbound to Aluminium Issue-ID: CCSDK-3128 Signed-off-by: Ravi Pendurty Change-Id: Id2dc38d4f2573d5c6aeedfb42349433f22aa86f5 Signed-off-by: Ravi Pendurty --- sdnr/northbound/CMNotify/feature/pom.xml | 2 +- sdnr/northbound/CMNotify/installer/pom.xml | 2 +- sdnr/northbound/CMNotify/model/pom.xml | 2 +- sdnr/northbound/CMNotify/pom.xml | 2 +- sdnr/northbound/CMNotify/provider/pom.xml | 83 +------ .../sdnr/northbound/cmnotify/CMNotifyProvider.java | 271 +++++++++++---------- .../OSGI-INF/blueprint/impl-blueprint.xml | 50 ---- .../org/opendaylight/blueprint/impl-blueprint.xml | 29 +-- .../sdnr/northbound/cmnotify/TestCMNotify.java | 25 +- 9 files changed, 179 insertions(+), 287 deletions(-) delete mode 100644 sdnr/northbound/CMNotify/provider/src/main/resources/OSGI-INF/blueprint/impl-blueprint.xml (limited to 'sdnr/northbound/CMNotify') diff --git a/sdnr/northbound/CMNotify/feature/pom.xml b/sdnr/northbound/CMNotify/feature/pom.xml index 3c7cb7218..90fe74663 100644 --- a/sdnr/northbound/CMNotify/feature/pom.xml +++ b/sdnr/northbound/CMNotify/feature/pom.xml @@ -26,7 +26,7 @@ org.onap.ccsdk.parent single-feature-parent - 2.1.0 + 2.1.1-SNAPSHOT diff --git a/sdnr/northbound/CMNotify/installer/pom.xml b/sdnr/northbound/CMNotify/installer/pom.xml index 20e551faf..b540ea737 100644 --- a/sdnr/northbound/CMNotify/installer/pom.xml +++ b/sdnr/northbound/CMNotify/installer/pom.xml @@ -26,7 +26,7 @@ org.onap.ccsdk.parent odlparent-lite - 2.1.0 + 2.1.1-SNAPSHOT diff --git a/sdnr/northbound/CMNotify/model/pom.xml b/sdnr/northbound/CMNotify/model/pom.xml index 43dcecf1e..3af4c6602 100644 --- a/sdnr/northbound/CMNotify/model/pom.xml +++ b/sdnr/northbound/CMNotify/model/pom.xml @@ -26,7 +26,7 @@ org.onap.ccsdk.parent binding-parent - 2.1.0 + 2.1.1-SNAPSHOT diff --git a/sdnr/northbound/CMNotify/pom.xml b/sdnr/northbound/CMNotify/pom.xml index a930edba4..54db602f3 100644 --- a/sdnr/northbound/CMNotify/pom.xml +++ b/sdnr/northbound/CMNotify/pom.xml @@ -26,7 +26,7 @@ org.onap.ccsdk.parent odlparent-lite - 2.1.0 + 2.1.1-SNAPSHOT diff --git a/sdnr/northbound/CMNotify/provider/pom.xml b/sdnr/northbound/CMNotify/provider/pom.xml index c434790f7..f964d63e1 100644 --- a/sdnr/northbound/CMNotify/provider/pom.xml +++ b/sdnr/northbound/CMNotify/provider/pom.xml @@ -26,7 +26,7 @@ org.onap.ccsdk.parent binding-parent - 2.1.0 + 2.1.1-SNAPSHOT @@ -39,16 +39,6 @@ - - org.onap.ccsdk.sli.core sli-core-artifacts @@ -64,36 +54,13 @@ CMNotify-model ${project.version} - - - org.opendaylight.controller - sal-binding-api - - - org.onap.ccsdk.sli.core - sli-common - provided - - - org.onap.ccsdk.sli.core - sli-provider - provided - - - org.opendaylight.controller - sal-test-model - test - - - org.opendaylight.controller - sal-binding-broker-impl - test - - - org.opendaylight.controller - sal-binding-broker-impl - test-jar - tests + org.opendaylight.mdsal + mdsal-binding-test-model test @@ -161,10 +96,6 @@ org.opendaylight.controller sal-common-util - - org.opendaylight.controller - sal-core-api - org.opendaylight.yangtools yang-data-impl diff --git a/sdnr/northbound/CMNotify/provider/src/main/java/org/onap/ccsdk/features/sdnr/northbound/cmnotify/CMNotifyProvider.java b/sdnr/northbound/CMNotify/provider/src/main/java/org/onap/ccsdk/features/sdnr/northbound/cmnotify/CMNotifyProvider.java index 7317ac4b8..452741b3f 100644 --- a/sdnr/northbound/CMNotify/provider/src/main/java/org/onap/ccsdk/features/sdnr/northbound/cmnotify/CMNotifyProvider.java +++ b/sdnr/northbound/CMNotify/provider/src/main/java/org/onap/ccsdk/features/sdnr/northbound/cmnotify/CMNotifyProvider.java @@ -28,149 +28,162 @@ import java.util.Properties; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import org.onap.ccsdk.sli.core.sli.provider.MdsalHelper; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; -import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; +import org.opendaylight.mdsal.binding.api.DataBroker; +import org.opendaylight.mdsal.binding.api.NotificationPublishService; +import org.opendaylight.mdsal.binding.api.RpcProviderService; import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev200224.CMNOTIFYAPIService; import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev200224.NbrlistChangeNotificationInput; import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev200224.NbrlistChangeNotificationInputBuilder; import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev200224.NbrlistChangeNotificationOutput; import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev200224.NbrlistChangeNotificationOutputBuilder; - import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.concepts.ObjectRegistration; import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.common.RpcResultBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Defines a base implementation for your provider. This class extends from a helper class which - * provides storage for the most commonly used components of the MD-SAL. Additionally the base class - * provides some basic logging and initialization / clean up methods. + * Defines a base implementation for your provider. This class extends from a + * helper class which provides storage for the most commonly used components of + * the MD-SAL. Additionally the base class provides some basic logging and + * initialization / clean up methods. * */ public class CMNotifyProvider implements AutoCloseable, CMNOTIFYAPIService { - private static final Logger LOG = LoggerFactory.getLogger(CMNotifyProvider.class); - - private static final String APPLICATION_NAME = "CMNotify-api"; - private static final String NBRLIST_CHANGE_NOTIFICATION = "nbrlist-change-notification"; - - - private final ExecutorService executor; - protected DataBroker dataBroker; - protected NotificationPublishService notificationService; - protected RpcProviderRegistry rpcRegistry; - protected BindingAwareBroker.RpcRegistration rpcRegistration; - private final CMNotifyClient CMNotifyClient; - - public CMNotifyProvider(final DataBroker dataBroker, final NotificationPublishService notificationPublishService, - final RpcProviderRegistry rpcProviderRegistry, final CMNotifyClient CMNotifyClient) { - - LOG.info("Creating provider for {}", APPLICATION_NAME); - executor = Executors.newFixedThreadPool(1); - this.dataBroker = dataBroker; - this.notificationService = notificationPublishService; - this.rpcRegistry = rpcProviderRegistry; - this.CMNotifyClient = CMNotifyClient; - initialize(); - } - - public void initialize() { - LOG.info("Initializing provider for {}", APPLICATION_NAME); - rpcRegistration = rpcRegistry.addRpcImplementation(CMNOTIFYAPIService.class, this); - LOG.info("Initialization complete for {}", APPLICATION_NAME); - } - - protected void initializeChild() { - // Override if you have custom initialization intelligence - } - - @Override - public void close() throws Exception { - LOG.info("Closing provider for {}", APPLICATION_NAME); - executor.shutdown(); - rpcRegistration.close(); - LOG.info("Successfully closed provider for {}", APPLICATION_NAME); - } - - // RPC nbrlist-change-notification - - @Override - public ListenableFuture> nbrlistChangeNotification(NbrlistChangeNotificationInput input) { - final String svcOperation = "nbrlist-change-notification"; - - Properties parms = new Properties(); - NbrlistChangeNotificationOutputBuilder serviceDataBuilder = (NbrlistChangeNotificationOutputBuilder) getServiceData(NBRLIST_CHANGE_NOTIFICATION); - - LOG.info("Reached RPC nbrlist-change-notification"); - - LOG.info(svcOperation + " called."); - - if (input == null) { - LOG.debug("exiting " + svcOperation + " because of invalid input"); - serviceDataBuilder.setResponseCode("Input is null"); - RpcResult rpcResult = - RpcResultBuilder.status(true).withResult(serviceDataBuilder.build()).build(); - return Futures.immediateFuture(rpcResult); - } - - // add input to parms - LOG.info("Adding INPUT data for " + svcOperation + " input: " + input); - NbrlistChangeNotificationInputBuilder inputBuilder = new NbrlistChangeNotificationInputBuilder(input); - MdsalHelper.toProperties(parms, inputBuilder.build()); - - LOG.info("Printing SLI parameters to be passed"); - - // iterate properties file to get key-value pairs - for (String key : parms.stringPropertyNames()) { - String value = parms.getProperty(key); - LOG.info("The SLI parameter in " + key + " is: " + value); - } - - // Call SLI sync method - try { - if (CMNotifyClient.hasGraph("CM-NOTIFY-API", svcOperation, null, "sync")) { - LOG.info("CMNotifyClient has a Directed Graph for '" + svcOperation + "'"); - try { - CMNotifyClient.execute("CM-NOTIFY-API", svcOperation, null, "sync", serviceDataBuilder, parms); - } catch (Exception e) { - LOG.error("Caught exception executing service logic for " + svcOperation, e); - serviceDataBuilder.setResponseCode("500"); - } - } else { - LOG.error("No service logic active for CMNotify: '" + svcOperation + "'"); - serviceDataBuilder.setResponseCode("503"); - } - } catch (Exception e) { - LOG.error("Caught exception looking for service logic", e); - serviceDataBuilder.setResponseCode("500"); - } - - String errorCode = serviceDataBuilder.getResponseCode(); - - if (!("0".equals(errorCode) || "200".equals(errorCode))) { - LOG.error("Returned FAILED for " + svcOperation + " error code: '" + errorCode + "'"); - } else { - LOG.info("Returned SUCCESS for " + svcOperation + " "); - serviceDataBuilder.setResponseMessage("CM Notification Executed and RuntimeDB Updated. "); - } - - RpcResult rpcResult = - RpcResultBuilder.status(true).withResult(serviceDataBuilder.build()).build(); - - LOG.info("Successful exit from nbrlist-change-notification "); - - return Futures.immediateFuture(rpcResult); - } - - - protected Builder getServiceData(String svcOperation) { - switch (svcOperation) { - case NBRLIST_CHANGE_NOTIFICATION: - return new NbrlistChangeNotificationOutputBuilder(); - } - return null; - } + private static final Logger LOG = LoggerFactory.getLogger(CMNotifyProvider.class); + + private static final String APPLICATION_NAME = "CMNotify-api"; + private static final String NBRLIST_CHANGE_NOTIFICATION = "nbrlist-change-notification"; + + private final ExecutorService executor; + protected DataBroker dataBroker; + protected RpcProviderService rpcProviderRegistry; + protected NotificationPublishService notificationService; + private ObjectRegistration rpcReg; + private CMNotifyClient CMNotifyClient; + + public CMNotifyProvider() { + + LOG.info("Creating provider for {}", APPLICATION_NAME); + executor = Executors.newFixedThreadPool(1); + + this.dataBroker = null; + this.notificationService = null; + this.rpcProviderRegistry = null; + this.CMNotifyClient = null; + + } + + public void setDataBroker(DataBroker dataBroker) { + this.dataBroker = dataBroker; + } + + public void setRpcProviderRegistry(RpcProviderService rpcProviderRegistry) { + this.rpcProviderRegistry = rpcProviderRegistry; + } + + public void setNotificationPublishService(NotificationPublishService notificationPublishService) { + this.notificationService = notificationPublishService; + } + + public void setClient(CMNotifyClient client) { + this.CMNotifyClient = client; + } + + public void init() { + LOG.info("Initializing provider for {}", APPLICATION_NAME); + rpcReg = rpcProviderRegistry.registerRpcImplementation(CMNOTIFYAPIService.class, this); + LOG.info("Initialization complete for {}", APPLICATION_NAME); + } + + @Override + public void close() throws Exception { + LOG.info("Closing provider for {}", APPLICATION_NAME); + executor.shutdown(); + if (rpcReg != null) + rpcReg.close(); + LOG.info("Successfully closed provider for {}", APPLICATION_NAME); + } + + // RPC nbrlist-change-notification + + @Override + public ListenableFuture> nbrlistChangeNotification( + NbrlistChangeNotificationInput input) { + final String svcOperation = "nbrlist-change-notification"; + + Properties parms = new Properties(); + NbrlistChangeNotificationOutputBuilder serviceDataBuilder = (NbrlistChangeNotificationOutputBuilder) getServiceData( + NBRLIST_CHANGE_NOTIFICATION); + + LOG.info("Reached RPC nbrlist-change-notification"); + + LOG.info(svcOperation + " called."); + + if (input == null) { + LOG.debug("exiting " + svcOperation + " because of invalid input"); + serviceDataBuilder.setResponseCode("Input is null"); + RpcResult rpcResult = RpcResultBuilder + .status(true).withResult(serviceDataBuilder.build()).build(); + return Futures.immediateFuture(rpcResult); + } + + // add input to parms + LOG.info("Adding INPUT data for " + svcOperation + " input: " + input); + NbrlistChangeNotificationInputBuilder inputBuilder = new NbrlistChangeNotificationInputBuilder(input); + MdsalHelper.toProperties(parms, inputBuilder.build()); + + LOG.info("Printing SLI parameters to be passed"); + + // iterate properties file to get key-value pairs + for (String key : parms.stringPropertyNames()) { + String value = parms.getProperty(key); + LOG.info("The SLI parameter in " + key + " is: " + value); + } + + // Call SLI sync method + try { + if (CMNotifyClient.hasGraph("CM-NOTIFY-API", svcOperation, null, "sync")) { + LOG.info("CMNotifyClient has a Directed Graph for '" + svcOperation + "'"); + try { + CMNotifyClient.execute("CM-NOTIFY-API", svcOperation, null, "sync", serviceDataBuilder, parms); + } catch (Exception e) { + LOG.error("Caught exception executing service logic for " + svcOperation, e); + serviceDataBuilder.setResponseCode("500"); + } + } else { + LOG.error("No service logic active for CMNotify: '" + svcOperation + "'"); + serviceDataBuilder.setResponseCode("503"); + } + } catch (Exception e) { + LOG.error("Caught exception looking for service logic", e); + serviceDataBuilder.setResponseCode("500"); + } + + String errorCode = serviceDataBuilder.getResponseCode(); + + if (!("0".equals(errorCode) || "200".equals(errorCode))) { + LOG.error("Returned FAILED for " + svcOperation + " error code: '" + errorCode + "'"); + } else { + LOG.info("Returned SUCCESS for " + svcOperation + " "); + serviceDataBuilder.setResponseMessage("CM Notification Executed and RuntimeDB Updated. "); + } + + RpcResult rpcResult = RpcResultBuilder + .status(true).withResult(serviceDataBuilder.build()).build(); + + LOG.info("Successful exit from nbrlist-change-notification "); + + return Futures.immediateFuture(rpcResult); + } + + protected Builder getServiceData(String svcOperation) { + switch (svcOperation) { + case NBRLIST_CHANGE_NOTIFICATION: + return new NbrlistChangeNotificationOutputBuilder(); + } + return null; + } } diff --git a/sdnr/northbound/CMNotify/provider/src/main/resources/OSGI-INF/blueprint/impl-blueprint.xml b/sdnr/northbound/CMNotify/provider/src/main/resources/OSGI-INF/blueprint/impl-blueprint.xml deleted file mode 100644 index fd036bbd0..000000000 --- a/sdnr/northbound/CMNotify/provider/src/main/resources/OSGI-INF/blueprint/impl-blueprint.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/sdnr/northbound/CMNotify/provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml b/sdnr/northbound/CMNotify/provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml index fd036bbd0..3eb531291 100644 --- a/sdnr/northbound/CMNotify/provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml +++ b/sdnr/northbound/CMNotify/provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml @@ -30,21 +30,22 @@ - - - - - - - - - - - + + + + + + + + + + diff --git a/sdnr/northbound/CMNotify/provider/src/test/java/org/onap/ccsdk/features/sdnr/northbound/cmnotify/TestCMNotify.java b/sdnr/northbound/CMNotify/provider/src/test/java/org/onap/ccsdk/features/sdnr/northbound/cmnotify/TestCMNotify.java index 36218eb99..f062e51b6 100644 --- a/sdnr/northbound/CMNotify/provider/src/test/java/org/onap/ccsdk/features/sdnr/northbound/cmnotify/TestCMNotify.java +++ b/sdnr/northbound/CMNotify/provider/src/test/java/org/onap/ccsdk/features/sdnr/northbound/cmnotify/TestCMNotify.java @@ -24,14 +24,9 @@ package org.onap.ccsdk.features.sdnr.northbound.cmnotify; import org.junit.Before; import org.junit.Test; -import org.onap.ccsdk.features.sdnr.northbound.cmnotify.CMNotifyClient; -import org.onap.ccsdk.features.sdnr.northbound.cmnotify.CMNotifyProvider; - -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; -import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest; -import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; - +import org.opendaylight.mdsal.binding.api.DataBroker; +import org.opendaylight.mdsal.binding.api.NotificationPublishService; +import org.opendaylight.mdsal.binding.api.RpcProviderService; import org.opendaylight.yangtools.yang.common.RpcResult; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -41,16 +36,14 @@ import static org.mockito.Mockito.mock; import java.math.*; -import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev200224.NbrlistChangeNotificationInput; import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev200224.NbrlistChangeNotificationInputBuilder; import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev200224.NbrlistChangeNotificationOutput; -import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev200224.NbrlistChangeNotificationOutputBuilder; import com.google.common.util.concurrent.ListenableFuture; -public class TestCMNotify extends AbstractConcurrentDataBrokerTest { +public class TestCMNotify { private CMNotifyProvider cMNotifyProvider; private static final Logger LOG = LoggerFactory.getLogger(CMNotifyProvider.class); @@ -58,11 +51,15 @@ public class TestCMNotify extends AbstractConcurrentDataBrokerTest { @Before public void setUp() throws Exception { if (null == cMNotifyProvider) { - DataBroker dataBroker = getDataBroker(); + DataBroker dataBroker = mock(DataBroker.class); NotificationPublishService mockNotification = mock(NotificationPublishService.class); - RpcProviderRegistry mockRpcRegistry = mock(RpcProviderRegistry.class); + RpcProviderService mockRpcRegistry = mock(RpcProviderService.class); CMNotifyClient mockSliClient = mock(CMNotifyClient.class); - cMNotifyProvider = new CMNotifyProvider(dataBroker, mockNotification, mockRpcRegistry, mockSliClient); + cMNotifyProvider = new CMNotifyProvider(); + cMNotifyProvider.setDataBroker(dataBroker); + cMNotifyProvider.setNotificationPublishService(mockNotification); + cMNotifyProvider.setRpcProviderRegistry(mockRpcRegistry); + cMNotifyProvider.setClient(mockSliClient); } } -- cgit 1.2.3-korg