From c0fd1e023368a059dc204370f1a5b108914ae500 Mon Sep 17 00:00:00 2001 From: manuedelf Date: Tue, 12 Jan 2021 23:11:47 +0100 Subject: [PATCH] NBI Notifications as karaf feature - 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 Change-Id: Ic28aef2705b5cd79277b56467727dedfe9b7b843 --- .../odl-transportpce-nbinotifications/pom.xml | 68 +++++++++++++++++++ .../src/main/feature/feature.xml | 12 ++++ ...daylight.transportpce.nbinotifications.cfg | 2 + features/pom.xml | 1 + karaf/pom.xml | 9 ++- lighty/pom.xml | 11 +++ .../java/io/lighty/controllers/tpce/Main.java | 66 +++++++++++++++--- .../tpce/module/TransportPCEImpl.java | 24 ++++++- .../controllers/tpce/utils/TPCEUtils.java | 2 + .../io/lighty/controllers/tpce/MaintTest.java | 5 +- 10 files changed, 186 insertions(+), 14 deletions(-) create mode 100644 features/odl-transportpce-nbinotifications/pom.xml create mode 100644 features/odl-transportpce-nbinotifications/src/main/feature/feature.xml create mode 100644 features/odl-transportpce-nbinotifications/src/main/resources/org.opendaylight.transportpce.nbinotifications.cfg diff --git a/features/odl-transportpce-nbinotifications/pom.xml b/features/odl-transportpce-nbinotifications/pom.xml new file mode 100644 index 000000000..29469b1ad --- /dev/null +++ b/features/odl-transportpce-nbinotifications/pom.xml @@ -0,0 +1,68 @@ + + + + 4.0.0 + + + org.opendaylight.odlparent + single-feature-parent + 8.1.0 + + + + org.opendaylight.transportpce + odl-transportpce-nbinotifications + 3.0.0-SNAPSHOT + feature + + OpenDaylight :: transportpce :: nbinotifications + + + true + + + + org.opendaylight.transportpce + odl-transportpce + ${project.version} + features + xml + + + ${project.groupId} + transportpce-nbinotifications + ${project.version} + + + + + + org.codehaus.mojo + build-helper-maven-plugin + + + attach-dmaap-artifact + package + + attach-artifact + + + + + ${basedir}/src/main/resources/org.opendaylight.transportpce.nbinotifications.cfg + cfg + config + + + + + + + + + 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 index 000000000..5e99a5241 --- /dev/null +++ b/features/odl-transportpce-nbinotifications/src/main/feature/feature.xml @@ -0,0 +1,12 @@ + + + + + + mvn:${project.groupId}/${project.artifactId}/${project.version}/cfg/config + + + \ 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 index 000000000..ea5c7c069 --- /dev/null +++ b/features/odl-transportpce-nbinotifications/src/main/resources/org.opendaylight.transportpce.nbinotifications.cfg @@ -0,0 +1,2 @@ +suscriber.server=${env:KAFKA_SERVER:-localhost:9092} +publisher.server=${env:KAFKA_SERVER:-localhost:9092} diff --git a/features/pom.xml b/features/pom.xml index 95532599f..55992861d 100644 --- a/features/pom.xml +++ b/features/pom.xml @@ -26,5 +26,6 @@ and is available at http://www.eclipse.org/legal/epl-v10.html INTERNAL odl-transportpce odl-transportpce-tapi odl-transportpce-inventory + odl-transportpce-nbinotifications diff --git a/karaf/pom.xml b/karaf/pom.xml index f71a9d80b..fe569f852 100644 --- a/karaf/pom.xml +++ b/karaf/pom.xml @@ -66,7 +66,14 @@ and is available at http://www.eclipse.org/legal/epl-v10.html INTERNAL xml runtime - + + ${project.groupId} + odl-transportpce-nbinotifications + ${project.version} + features + xml + runtime + diff --git a/lighty/pom.xml b/lighty/pom.xml index 8ee8a1275..891b72caf 100644 --- a/lighty/pom.xml +++ b/lighty/pom.xml @@ -32,6 +32,12 @@ + + + commons-cli + commons-cli + 1.4 + @@ -67,6 +73,11 @@ transportpce-tapi ${transportpce.version} + + org.opendaylight.transportpce + transportpce-nbinotifications + ${transportpce.version} + diff --git a/lighty/src/main/java/io/lighty/controllers/tpce/Main.java b/lighty/src/main/java/io/lighty/controllers/tpce/Main.java index 9cba68c00..c548a79b5 100644 --- a/lighty/src/main/java/io/lighty/controllers/tpce/Main.java +++ b/lighty/src/main/java/io/lighty/controllers/tpce/Main.java @@ -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 { diff --git a/lighty/src/main/java/io/lighty/controllers/tpce/module/TransportPCEImpl.java b/lighty/src/main/java/io/lighty/controllers/tpce/module/TransportPCEImpl.java index fe1c59fa6..f2542536c 100644 --- a/lighty/src/main/java/io/lighty/controllers/tpce/module/TransportPCEImpl.java +++ b/lighty/src/main/java/io/lighty/controllers/tpce/module/TransportPCEImpl.java @@ -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 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(); diff --git a/lighty/src/main/java/io/lighty/controllers/tpce/utils/TPCEUtils.java b/lighty/src/main/java/io/lighty/controllers/tpce/utils/TPCEUtils.java index d97f525cf..9c2cfc1a6 100644 --- a/lighty/src/main/java/io/lighty/controllers/tpce/utils/TPCEUtils.java +++ b/lighty/src/main/java/io/lighty/controllers/tpce/utils/TPCEUtils.java @@ -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 TPCE_YANG_MODEL = Stream.concat( diff --git a/lighty/src/test/java/io/lighty/controllers/tpce/MaintTest.java b/lighty/src/test/java/io/lighty/controllers/tpce/MaintTest.java index 096c25d34..de130a4db 100644 --- a/lighty/src/test/java/io/lighty/controllers/tpce/MaintTest.java +++ b/lighty/src/test/java/io/lighty/controllers/tpce/MaintTest.java @@ -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()); } -- 2.36.6