NBI Notifications as karaf feature 23/94623/26
authormanuedelf <emmanuelle.delfour@orange.com>
Tue, 12 Jan 2021 22:11:47 +0000 (23:11 +0100)
committerguillaume.lambert <guillaume.lambert@orange.com>
Thu, 11 Mar 2021 15:47:41 +0000 (16:47 +0100)
- add a new maven module in features maven project
- update lighty with NBI notification:
  - NBI notifications is optional and could be activated through command
    line option -nbinotification
  - restconf file configuration is now passed with -restconf command
    line option
  - add apache common-cli to ease the parsing of command line options

JIRA: TRNSPRTPCE-343
Signed-off-by: manuedelf <emmanuelle.delfour@orange.com>
Change-Id: Ic28aef2705b5cd79277b56467727dedfe9b7b843

features/odl-transportpce-nbinotifications/pom.xml [new file with mode: 0644]
features/odl-transportpce-nbinotifications/src/main/feature/feature.xml [new file with mode: 0644]
features/odl-transportpce-nbinotifications/src/main/resources/org.opendaylight.transportpce.nbinotifications.cfg [new file with mode: 0644]
features/pom.xml
karaf/pom.xml
lighty/pom.xml
lighty/src/main/java/io/lighty/controllers/tpce/Main.java
lighty/src/main/java/io/lighty/controllers/tpce/module/TransportPCEImpl.java
lighty/src/main/java/io/lighty/controllers/tpce/utils/TPCEUtils.java
lighty/src/test/java/io/lighty/controllers/tpce/MaintTest.java

diff --git a/features/odl-transportpce-nbinotifications/pom.xml b/features/odl-transportpce-nbinotifications/pom.xml
new file mode 100644 (file)
index 0000000..29469b1
--- /dev/null
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Copyright © 2021 Orange and others. All rights reserved. This program
+    and the accompanying materials are made available under the terms of the
+    Eclipse Public License v1.0 which accompanies this distribution, and is available
+    at http://www.eclipse.org/legal/epl-v10.html INTERNAL -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.opendaylight.odlparent</groupId>
+        <artifactId>single-feature-parent</artifactId>
+        <version>8.1.0</version>
+        <relativePath />
+    </parent>
+
+    <groupId>org.opendaylight.transportpce</groupId>
+    <artifactId>odl-transportpce-nbinotifications</artifactId>
+    <version>3.0.0-SNAPSHOT</version>
+    <packaging>feature</packaging>
+
+    <name>OpenDaylight :: transportpce :: nbinotifications</name>
+    <properties>
+    <!-- skipped because we are using config file as artifact and it is not installed before running test -->
+        <skip.karaf.featureTest>true</skip.karaf.featureTest>
+    </properties>
+    <dependencies>
+        <dependency>
+            <groupId>org.opendaylight.transportpce</groupId>
+            <artifactId>odl-transportpce</artifactId>
+            <version>${project.version}</version>
+            <classifier>features</classifier>
+            <type>xml</type>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>transportpce-nbinotifications</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+    </dependencies>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>build-helper-maven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>attach-dmaap-artifact</id>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>attach-artifact</goal>
+                        </goals>
+                        <configuration>
+                            <artifacts>
+                                <artifact>
+                                    <file>${basedir}/src/main/resources/org.opendaylight.transportpce.nbinotifications.cfg</file>
+                                    <type>cfg</type>
+                                    <classifier>config</classifier>
+                                </artifact>
+                            </artifacts>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+</project>
diff --git a/features/odl-transportpce-nbinotifications/src/main/feature/feature.xml b/features/odl-transportpce-nbinotifications/src/main/feature/feature.xml
new file mode 100644 (file)
index 0000000..5e99a52
--- /dev/null
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!-- Copyright © 2021 Orange and others. All rights reserved. This program
+    and the accompanying materials are made available under the terms of the
+    Eclipse Public License v1.0 which accompanies this distribution, and is available
+    at http://www.eclipse.org/legal/epl-v10.html INTERNAL -->
+<features xmlns="http://karaf.apache.org/xmlns/features/v1.4.0" name="odl-transportpce-nbinotifications">
+    <feature name="odl-transportpce-nbinotifications">
+        <configfile finalname="etc/org.opendaylight.transportpce.nbinotififications.cfg" override="false">
+            mvn:${project.groupId}/${project.artifactId}/${project.version}/cfg/config
+        </configfile>
+    </feature>
+</features>
\ No newline at end of file
diff --git a/features/odl-transportpce-nbinotifications/src/main/resources/org.opendaylight.transportpce.nbinotifications.cfg b/features/odl-transportpce-nbinotifications/src/main/resources/org.opendaylight.transportpce.nbinotifications.cfg
new file mode 100644 (file)
index 0000000..ea5c7c0
--- /dev/null
@@ -0,0 +1,2 @@
+suscriber.server=${env:KAFKA_SERVER:-localhost:9092}
+publisher.server=${env:KAFKA_SERVER:-localhost:9092}
index 95532599fb9766e0aa6a1858f6b1ee20defdf109..55992861db6132d790923969b1362212fe68e23b 100644 (file)
@@ -26,5 +26,6 @@ and is available at http://www.eclipse.org/legal/epl-v10.html INTERNAL
     <module>odl-transportpce</module>
     <module>odl-transportpce-tapi</module>
     <module>odl-transportpce-inventory</module>
+    <module>odl-transportpce-nbinotifications</module>
   </modules>
 </project>
index f71a9d80b0da30cf16cb030d6756a12820f26348..fe569f85254b0f302785a3fe9767aaf9e5fb7714 100644 (file)
@@ -66,7 +66,14 @@ and is available at http://www.eclipse.org/legal/epl-v10.html INTERNAL
       <type>xml</type>
       <scope>runtime</scope>
     </dependency>
-
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>odl-transportpce-nbinotifications</artifactId>
+      <version>${project.version}</version>
+      <classifier>features</classifier>
+      <type>xml</type>
+      <scope>runtime</scope>
+    </dependency>
   </dependencies>
 
   <build>
index 8ee8a1275341ed380a2efdae2f9186ac5779192c..891b72caf049dcbb0e4195bd60f2f4c4f9a2f43a 100644 (file)
     </properties>
 
     <dependencies>
+        <!-- for parsing command line arguments -->
+        <dependency>
+            <groupId>commons-cli</groupId>
+            <artifactId>commons-cli</artifactId>
+            <version>1.4</version>
+        </dependency>
 
         <!-- TPCE Models - BEGIN -->
         <dependency>
             <artifactId>transportpce-tapi</artifactId>
             <version>${transportpce.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.opendaylight.transportpce</groupId>
+            <artifactId>transportpce-nbinotifications</artifactId>
+            <version>${transportpce.version}</version>
+        </dependency>
         <!-- TPCE bundles - END -->
 
         <dependency>
index 9cba68c009e353678721847f44d3f422c18f1df0..c548a79b5924ced10c18ef2f8d11b407423a65a3 100644 (file)
@@ -34,21 +34,32 @@ import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.concurrent.ExecutionException;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.DefaultParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class Main {
 
+    private static final String RESTCONF_OPTION_NAME = "restconf";
+
+    private static final String NBINOTIFICATION_OPTION_NAME = "nbinotification";
+
     private static final Logger LOG = LoggerFactory.getLogger(Main.class);
 
     private ShutdownHook shutdownHook;
 
     public void start() {
-        start(new String[] {}, false);
+        start(null, false, false);
     }
 
     @SuppressWarnings("checkstyle:Illegalcatch")
-    public void start(String[] args, boolean registerShutdownHook) {
+    public void start(String restConfConfigurationFile, boolean activateNbiNotification, boolean registerShutdownHook) {
         long startTime = System.nanoTime();
         TpceBanner.print();
         RestConfConfiguration restConfConfig = null;
@@ -57,8 +68,8 @@ public class Main {
             ControllerConfiguration singleNodeConfiguration = ControllerConfigUtils
                     .getDefaultSingleNodeConfiguration(TPCEUtils.getYangModels());
             // 2. get RESTCONF NBP configuration
-            if (args.length == 1) {
-                Path configPath = Paths.get(args[0]);
+            if (restConfConfigurationFile != null) {
+                Path configPath = Paths.get(restConfConfigurationFile);
                 LOG.info("Using restconf configuration from file {} ...", configPath);
                 restConfConfig = RestConfConfigUtils.getRestConfConfiguration(Files.newInputStream(configPath));
 
@@ -72,7 +83,7 @@ public class Main {
             restConfConfig.setJsonRestconfServiceType(JsonRestConfServiceType.DRAFT_02);
             // 3. NETCONF SBP configuration
             NetconfConfiguration netconfSBPConfig = NetconfConfigUtils.createDefaultNetconfConfiguration();
-            startLighty(singleNodeConfiguration, restConfConfig, netconfSBPConfig, registerShutdownHook);
+            startLighty(singleNodeConfiguration, restConfConfig, netconfSBPConfig, registerShutdownHook, activateNbiNotification);
             float duration = (System.nanoTime() - startTime) / 1_000_000f;
             LOG.info("lighty.io and RESTCONF-NETCONF started in {}ms", duration);
         } catch (ConfigurationException | ExecutionException | IOException e) {
@@ -91,9 +102,33 @@ public class Main {
         }
     }
 
+    /**
+     * Build options for command line arguments
+     * @return
+     */
+    private static Options builOptions() {
+        Option rescontFileOption = Option.builder(RESTCONF_OPTION_NAME)
+                .desc("Restconf configuration file")
+                .argName(RESTCONF_OPTION_NAME)
+                .hasArg(true)
+                .required(false)
+                .build();
+        Option useNbiNotificationsOption = Option.builder(NBINOTIFICATION_OPTION_NAME)
+                .desc("Activate NBI notifications feature")
+                .argName(NBINOTIFICATION_OPTION_NAME)
+                .hasArg(false)
+                .required(false)
+                .build();
+        Options options = new Options();
+        options.addOption(rescontFileOption);
+        options.addOption(useNbiNotificationsOption);
+        return options;
+    }
+
     private void startLighty(ControllerConfiguration controllerConfiguration,
             RestConfConfiguration restConfConfiguration, NetconfConfiguration netconfSBPConfiguration,
-            boolean registerShutdownHook) throws ConfigurationException, ExecutionException, InterruptedException {
+            boolean registerShutdownHook, boolean activateNbiNotification)
+                    throws ConfigurationException, ExecutionException, InterruptedException {
 
         // 1. initialize and start Lighty controller (MD-SAL, Controller, YangTools,
         // Akka)
@@ -121,7 +156,7 @@ public class Main {
         netconfSouthboundPlugin.start().get();
 
         // 4. start TransportPCE beans
-        TransportPCE transportPCE = new TransportPCEImpl(lightyController.getServices());
+        TransportPCE transportPCE = new TransportPCEImpl(lightyController.getServices(), activateNbiNotification);
         transportPCE.start().get();
 
         // 5. Register shutdown hook for graceful shutdown.
@@ -136,8 +171,21 @@ public class Main {
     }
 
     public static void main(String[] args) {
-        Main app = new Main();
-        app.start(args, true);
+        Options options = builOptions();
+        try {
+            CommandLine commandLine = new DefaultParser().parse(options, args);
+            String restConfConfigurationFile = commandLine.getOptionValue(RESTCONF_OPTION_NAME, null);
+            boolean useNbiNotifications = commandLine.hasOption(NBINOTIFICATION_OPTION_NAME);
+            Main app = new Main();
+            app.start(restConfConfigurationFile, useNbiNotifications, true);
+        } catch (ParseException e) {
+            HelpFormatter formatter = new HelpFormatter();
+            formatter.printHelp(
+                    "java -ms128m -mx512m -XX:MaxMetaspaceSize=128m -jar tpce.jar "
+                    + "[-restconf rescontConfigurationFile] [-nbinotification]",
+                    options);
+            System.exit(1);
+        }
     }
 
     private static class ShutdownHook extends Thread {
index fe1c59fa6c152f9bc100c09f1a632bedb9881c49..f2542536c1d8fe5bb0b624d683357dba30e9ae54 100644 (file)
@@ -9,6 +9,10 @@ package io.lighty.controllers.tpce.module;
 
 import io.lighty.core.controller.api.AbstractLightyModule;
 import io.lighty.core.controller.api.LightyServices;
+
+import java.util.Arrays;
+import java.util.List;
+
 import org.opendaylight.transportpce.common.crossconnect.CrossConnect;
 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl;
 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl121;
@@ -29,6 +33,7 @@ import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfa
 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl121;
 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl221;
 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl710;
+import org.opendaylight.transportpce.nbinotifications.impl.NbiNotificationsProvider;
 import org.opendaylight.transportpce.networkmodel.NetConfTopologyListener;
 import org.opendaylight.transportpce.networkmodel.NetworkModelProvider;
 import org.opendaylight.transportpce.networkmodel.NetworkUtilsImpl;
@@ -98,8 +103,15 @@ public class TransportPCEImpl extends AbstractLightyModule implements TransportP
     private final TapiProvider tapiProvider;
     // service-handler beans
     private final ServicehandlerProvider servicehandlerProvider;
+    // nbi-notifications beans
+    private NbiNotificationsProvider nbiNotificationsProvider;
+    /**
+     * List of publisher topics.
+     */
+    private final List<String> publisherTopicList =
+            Arrays.asList("PceListener", "ServiceHandlerOperations", "ServiceHandler", "RendererListener");
 
-    public TransportPCEImpl(LightyServices lightyServices) {
+    public TransportPCEImpl(LightyServices lightyServices, boolean activateNbiNotification) {
         LOG.info("Initializing transaction providers ...");
         deviceTransactionManager = new DeviceTransactionManagerImpl(lightyServices.getBindingMountPointService(),
                 MAX_DURATION_TO_SUBMIT_TRANSACTION);
@@ -175,6 +187,12 @@ public class TransportPCEImpl extends AbstractLightyModule implements TransportP
                 serviceDataStoreOperations, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
                 servicehandler);
         tapiProvider = initTapi(lightyServices, servicehandler);
+        if(activateNbiNotification) {
+            LOG.info("Creating nbi-notifications beans ...");
+            nbiNotificationsProvider = new NbiNotificationsProvider(
+                    publisherTopicList, null, null, lightyServices.getRpcProviderService(),
+                    lightyServices.getNotificationService(), lightyServices.getAdapterContext().currentSerializer());
+        }
     }
 
     @Override
@@ -191,12 +209,16 @@ public class TransportPCEImpl extends AbstractLightyModule implements TransportP
         servicehandlerProvider.init();
         LOG.info("Initializing tapi provider ...");
         tapiProvider.init();
+        LOG.info("Initializing nbi-notifications provider ...");
+        nbiNotificationsProvider.init();
         LOG.info("Init done.");
         return true;
     }
 
     @Override
     protected boolean stopProcedure() {
+        nbiNotificationsProvider.close();
+        LOG.info("Shutting down nbi-notifications provider ...");
         tapiProvider.close();
         LOG.info("Shutting down service-handler provider ...");
         servicehandlerProvider.close();
index d97f525cf35bdfe16f848563883443ae5e238d43..9c2cfc1a615d69aba53f593fefeb9de2d62817aa 100644 (file)
@@ -255,6 +255,8 @@ public final class TPCEUtils {
             org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.rev131019.$YangModuleInfoImpl
                     .getInstance(),
             org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.tapi.rev180928.$YangModuleInfoImpl
+                    .getInstance(),
+            org.opendaylight.yang.gen.v1.nbi.notifications.rev201130.$YangModuleInfoImpl
                     .getInstance());
 
     private static final Set<YangModuleInfo> TPCE_YANG_MODEL = Stream.concat(
index 096c25d34a1bfad0b1dbc4800e7361f5d582b5eb..de130a4db56548b2e51af3d34c31aa2051ea95b0 100644 (file)
@@ -48,7 +48,7 @@ public class MaintTest {
 
     @Test
     public void startNoConfigFileTest() throws Exception {
-        main.start(new String[0], true);
+        main.start(null, false, true);
         ContentResponse response = client.GET("http://localhost:8181/restconf/config/ietf-network:networks/network/openroadm-topology");
         assertEquals("Response code should be 200", 200, response.getStatus());
     }
@@ -56,8 +56,7 @@ public class MaintTest {
     @Test
     public void startConfigFileTest() throws Exception {
         File configFile = new File("src/test/resources/config.json");
-        String[] args = {configFile.getAbsolutePath()};
-        main.start(args, true);
+        main.start(configFile.getAbsolutePath(), false, true);
         ContentResponse response = client.GET("http://localhost:8888/restconfCustom/config/ietf-network:networks/network/openroadm-topology");
         assertEquals("Response code should be 200", 200, response.getStatus());
     }