From 2cc579273e29458d974d9e31355332ef2fa13bf5 Mon Sep 17 00:00:00 2001 From: Gilles Thouenon Date: Sun, 8 May 2022 18:45:28 +0200 Subject: [PATCH] Adapt lighty to run with optional karaf features - put tapi as an optional feature to install in lighty, as it is the case with karaf - add use of two new environment variables (INSTALL_NBINOTIFICATIONS and INSTALL_TAPI) to start lighty with nbinotifications and tapi features - adapt lighty launcher shell script to take into acount these environment variables, as well as the OLM_TIMER ones - adapt tox consequently JIRA: TRNSPRTPCE-663 Signed-off-by: Gilles Thouenon Change-Id: I85c9a27f38de01343e4f13ce548440a9171502b1 --- .../resources/clean-start-controller.sh | 18 ++++- .../java/io/lighty/controllers/tpce/Main.java | 33 +++++---- .../tpce/module/TransportPCEImpl.java | 71 ++++++++++--------- .../io/lighty/controllers/tpce/MaintTest.java | 4 +- tox.ini | 3 + 5 files changed, 82 insertions(+), 47 deletions(-) diff --git a/lighty/src/main/assembly/resources/clean-start-controller.sh b/lighty/src/main/assembly/resources/clean-start-controller.sh index ad4926ddc..89907be25 100755 --- a/lighty/src/main/assembly/resources/clean-start-controller.sh +++ b/lighty/src/main/assembly/resources/clean-start-controller.sh @@ -27,10 +27,26 @@ if [ -z "$USE_ODL_ALT_AKKA_MGT_PORT" ]; then else AKKA_MGT_PORT=$USE_ODL_ALT_AKKA_MGT_PORT fi +if [ -z "$OLM_TIMER1" ]; then + olmtimer1=3000 +else + olmtimer1=$OLM_TIMER1 +fi +if [ -z "$OLM_TIMER2" ]; then + olmtimer2=2000 +else + olmtimer2=$OLM_TIMER2 +fi +if [ -n "$INSTALL_NBINOTIFICATIONS" ] && [ "$INSTALL_NBINOTIFICATIONS" = "True" ]; then + install_nbinotifications="-nbinotification" +fi +if [ -n "$INSTALL_TAPI" ]; then + install_tapi="-tapi" +fi # generate appropriate configuration files cat config_template.json | sed -e "s/ODL_RESTCONF_PORT/$RESTCONF_PORT/" -e "s/ODL_WEBSOCKET_PORT/$WEBSOCKET_PORT/" >config.json cat akka-default_template.conf | sed -e "s/ODL_AKKA_PORT/$AKKA_PORT/" -e "s/ODL_AKKA_MGT_PORT/$AKKA_MGT_PORT/" >singlenode/akka-default.conf #start controller -java -ms128m -mx512m -XX:MaxMetaspaceSize=128m -jar tpce.jar -restconf config.json -olmtimer1 3000 -olmtimer2 2000 +java -ms128m -mx512m -XX:MaxMetaspaceSize=128m -jar tpce.jar -restconf config.json $install_nbinotifications $install_tapi -olmtimer1 $olmtimer1 -olmtimer2 $olmtimer2 \ No newline at end of file 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 9215bc29f..043f37f96 100644 --- a/lighty/src/main/java/io/lighty/controllers/tpce/Main.java +++ b/lighty/src/main/java/io/lighty/controllers/tpce/Main.java @@ -47,6 +47,7 @@ public class Main { private static final String RESTCONF_OPTION_NAME = "restconf"; private static final String NBINOTIFICATION_OPTION_NAME = "nbinotification"; + private static final String TAPI_OPTION_NAME = "tapi"; private static final String OLMTIMER1_OPTION_NAME = "olmtimer1"; private static final String OLMTIMER2_OPTION_NAME = "olmtimer2"; @@ -55,11 +56,11 @@ public class Main { private ShutdownHook shutdownHook; public void start() { - start(null, false, null, null, false); + start(null, false, false, null, null, false); } @SuppressWarnings("checkstyle:Illegalcatch") - public void start(String restConfConfigurationFile, boolean activateNbiNotification, + public void start(String restConfConfigurationFile, boolean activateNbiNotification, boolean activateTapi, String olmtimer1, String olmtimer2, boolean registerShutdownHook) { long startTime = System.nanoTime(); TpceBanner.print(); @@ -85,7 +86,7 @@ public class Main { // 3. NETCONF SBP configuration NetconfConfiguration netconfSBPConfig = NetconfConfigUtils.createDefaultNetconfConfiguration(); startLighty(singleNodeConfiguration, restConfConfig, netconfSBPConfig, registerShutdownHook, - activateNbiNotification, olmtimer1, olmtimer2); + activateNbiNotification, activateTapi, olmtimer1, olmtimer2); float duration = (System.nanoTime() - startTime) / 1_000_000f; LOG.info("lighty.io and RESTCONF-NETCONF started in {}ms", duration); } catch (ConfigurationException | ExecutionException | IOException e) { @@ -115,11 +116,17 @@ public class Main { .required(false) .build(); Option useNbiNotificationsOption = Option.builder(NBINOTIFICATION_OPTION_NAME) - .desc("Activate NBI notifications feature") - .argName(NBINOTIFICATION_OPTION_NAME) - .hasArg(false) - .required(false) - .build(); + .desc("Activate NBI notifications feature") + .argName(NBINOTIFICATION_OPTION_NAME) + .hasArg(false) + .required(false) + .build(); + Option useTapiOption = Option.builder(TAPI_OPTION_NAME) + .desc("Activate TAPI feature") + .argName(TAPI_OPTION_NAME) + .hasArg(false) + .required(false) + .build(); Option olmTimer1Option = Option.builder(OLMTIMER1_OPTION_NAME) .desc("OLM timer 1 value") .argName(OLMTIMER1_OPTION_NAME) @@ -135,6 +142,7 @@ public class Main { Options options = new Options(); options.addOption(restconfFileOption); options.addOption(useNbiNotificationsOption); + options.addOption(useTapiOption); options.addOption(olmTimer1Option); options.addOption(olmTimer2Option); return options; @@ -142,8 +150,8 @@ public class Main { private void startLighty(ControllerConfiguration controllerConfiguration, RestConfConfiguration restConfConfiguration, NetconfConfiguration netconfSBPConfiguration, - boolean registerShutdownHook, boolean activateNbiNotification, String olmtimer1, String olmtimer2) - throws ConfigurationException, ExecutionException, InterruptedException { + boolean registerShutdownHook, boolean activateNbiNotification, boolean activateTapi, String olmtimer1, + String olmtimer2) throws ConfigurationException, ExecutionException, InterruptedException { // 1. initialize and start Lighty controller (MD-SAL, Controller, YangTools, // Akka) @@ -172,7 +180,7 @@ public class Main { // 4. start TransportPCE beans TransportPCE transportPCE = new TransportPCEImpl(lightyController.getServices(), activateNbiNotification, - olmtimer1, olmtimer2); + activateTapi, olmtimer1, olmtimer2); transportPCE.start().get(); // 5. Register shutdown hook for graceful shutdown. @@ -192,10 +200,11 @@ public class Main { CommandLine commandLine = new DefaultParser().parse(options, args); String restConfConfigurationFile = commandLine.getOptionValue(RESTCONF_OPTION_NAME, null); boolean useNbiNotifications = commandLine.hasOption(NBINOTIFICATION_OPTION_NAME); + boolean useTapi = commandLine.hasOption(TAPI_OPTION_NAME); String olmtimer1 = commandLine.getOptionValue(OLMTIMER1_OPTION_NAME, null); String olmtimer2 = commandLine.getOptionValue(OLMTIMER2_OPTION_NAME, null); Main app = new Main(); - app.start(restConfConfigurationFile, useNbiNotifications, olmtimer1, olmtimer2, true); + app.start(restConfConfigurationFile, useNbiNotifications, useTapi, olmtimer1, olmtimer2, true); } catch (ParseException e) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp( 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 276940850..ef88bf77e 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 @@ -115,10 +115,10 @@ public class TransportPCEImpl extends AbstractLightyModule implements TransportP private final OlmProvider olmProvider; // renderer beans private final RendererProvider rendererProvider; - // T-api - private final TapiProvider tapiProvider; // service-handler beans private final ServicehandlerProvider servicehandlerProvider; + // T-api + private TapiProvider tapiProvider; // nbi-notifications beans private NbiNotificationsProvider nbiNotificationsProvider; /** @@ -128,7 +128,7 @@ public class TransportPCEImpl extends AbstractLightyModule implements TransportP "ServiceHandler", "RendererListener"); private final List publisherAlarmList = Arrays.asList("ServiceListener"); - public TransportPCEImpl(LightyServices lightyServices, boolean activateNbiNotification, + public TransportPCEImpl(LightyServices lightyServices, boolean activateNbiNotification, boolean activateTapi, String olmtimer1, String olmtimer2) { LOG.info("Initializing transaction providers ..."); deviceTransactionManager = new DeviceTransactionManagerImpl(lightyServices.getBindingMountPointService(), @@ -208,30 +208,31 @@ public class TransportPCEImpl extends AbstractLightyModule implements TransportP lightyServices.getRpcProviderService(), lightyServices.getNotificationService(), serviceDataStoreOperations, pceListenerImpl, serviceListener, rendererListenerImpl, networkModelListenerImpl, servicehandler); + if (activateTapi) { + LOG.info("Creating tapi beans ..."); + TapiLink tapiLink = new TapiLink(networkTransaction); + R2RTapiLinkDiscovery tapilinkDiscoveryImpl = new R2RTapiLinkDiscovery(networkTransaction, + deviceTransactionManager, tapiLink); + TapiRendererListenerImpl tapiRendererListenerImpl = new TapiRendererListenerImpl(lightyServices + .getBindingDataBroker()); + TapiPceListenerImpl tapiPceListenerImpl = new TapiPceListenerImpl(lightyServices.getBindingDataBroker()); + TapiServiceHandlerListenerImpl tapiServiceHandlerListener = new TapiServiceHandlerListenerImpl(lightyServices + .getBindingDataBroker()); + TransportpceTapinetworkutilsService tapiNetworkutilsServiceImpl = new TapiNetworkUtilsImpl( + networkTransaction, tapiLink); + TapiNetworkModelService tapiNetworkModelService = new TapiNetworkModelServiceImpl( + tapilinkDiscoveryImpl, networkTransaction, tapiLink); + TapiNetconfTopologyListener tapiNetConfTopologyListener = + new TapiNetconfTopologyListener(tapiNetworkModelService); + TapiOrLinkListener orLinkListener = new TapiOrLinkListener(tapiLink, networkTransaction); + TapiPortMappingListener tapiPortMappingListener = + new TapiPortMappingListener(tapiNetworkModelService); - LOG.info("Creating tapi beans ..."); - TapiLink tapiLink = new TapiLink(networkTransaction); - R2RTapiLinkDiscovery tapilinkDiscoveryImpl = new R2RTapiLinkDiscovery(networkTransaction, - deviceTransactionManager, tapiLink); - TapiRendererListenerImpl tapiRendererListenerImpl = new TapiRendererListenerImpl(lightyServices - .getBindingDataBroker()); - TapiPceListenerImpl tapiPceListenerImpl = new TapiPceListenerImpl(lightyServices.getBindingDataBroker()); - TapiServiceHandlerListenerImpl tapiServiceHandlerListener = new TapiServiceHandlerListenerImpl(lightyServices - .getBindingDataBroker()); - TransportpceTapinetworkutilsService tapiNetworkutilsServiceImpl = new TapiNetworkUtilsImpl( - networkTransaction, tapiLink); - TapiNetworkModelService tapiNetworkModelService = new TapiNetworkModelServiceImpl( - tapilinkDiscoveryImpl, networkTransaction, tapiLink); - TapiNetconfTopologyListener tapiNetConfTopologyListener = - new TapiNetconfTopologyListener(tapiNetworkModelService); - TapiOrLinkListener orLinkListener = new TapiOrLinkListener(tapiLink, networkTransaction); - TapiPortMappingListener tapiPortMappingListener = - new TapiPortMappingListener(tapiNetworkModelService); - - tapiProvider = initTapi(lightyServices, servicehandler, networkTransaction, serviceDataStoreOperations, - tapiNetConfTopologyListener, tapiPortMappingListener, tapiNetworkutilsServiceImpl, tapiPceListenerImpl, - tapiRendererListenerImpl, tapiServiceHandlerListener, lightyServices.getNotificationService(), - orLinkListener); + tapiProvider = initTapi(lightyServices, servicehandler, networkTransaction, serviceDataStoreOperations, + tapiNetConfTopologyListener, tapiPortMappingListener, tapiNetworkutilsServiceImpl, tapiPceListenerImpl, + tapiRendererListenerImpl, tapiServiceHandlerListener, lightyServices.getNotificationService(), + orLinkListener); + } if (activateNbiNotification) { LOG.info("Creating nbi-notifications beans ..."); nbiNotificationsProvider = new NbiNotificationsProvider( @@ -252,8 +253,10 @@ public class TransportPCEImpl extends AbstractLightyModule implements TransportP rendererProvider.init(); LOG.info("Initializing service-handler provider ..."); servicehandlerProvider.init(); - LOG.info("Initializing tapi provider ..."); - tapiProvider.init(); + if (tapiProvider != null) { + LOG.info("Initializing tapi provider ..."); + tapiProvider.init(); + } if (nbiNotificationsProvider != null) { LOG.info("Initializing nbi-notifications provider ..."); nbiNotificationsProvider.init(); @@ -264,10 +267,14 @@ public class TransportPCEImpl extends AbstractLightyModule implements TransportP @Override protected boolean stopProcedure() { - nbiNotificationsProvider.close(); - LOG.info("Shutting down nbi-notifications provider ..."); - tapiProvider.close(); - LOG.info("Shutting down service-handler provider ..."); + if (nbiNotificationsProvider != null) { + nbiNotificationsProvider.close(); + LOG.info("Shutting down nbi-notifications provider ..."); + } + if (tapiProvider != null) { + tapiProvider.close(); + LOG.info("Shutting down service-handler provider ..."); + } servicehandlerProvider.close(); LOG.info("Shutting down renderer provider ..."); rendererProvider.close(); 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 872cb5205..98abb12db 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(null, false, "3000", "2000", true); + main.start(null, false, false, "3000", "2000", 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,7 +56,7 @@ public class MaintTest { @Test public void startConfigFileTest() throws Exception { File configFile = new File("src/test/resources/config.json"); - main.start(configFile.getAbsolutePath(), false, "3000", "2000", true); + main.start(configFile.getAbsolutePath(), false, false, "3000", "2000", 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()); } diff --git a/tox.ini b/tox.ini index 3491f79c7..d2936ac2b 100644 --- a/tox.ini +++ b/tox.ini @@ -190,6 +190,8 @@ setenv = USE_ODL_ALT_KARAF_ENV=./karaf221.env USE_ODL_ALT_KARAF_INSTALL_DIR=karaf221 INSTALL_TAPI=True + OLM_TIMER1=3000 + OLM_TIMER2=2000 commands = ./launch_tests.sh tapi {posargs:} @@ -202,6 +204,7 @@ passenv = LAUNCHER USE_LIGHTY USE_ODL_RESTCONF_VERSION OLM_TIMER1 OLM_TIMER2 setenv = OLM_TIMER1=3000 OLM_TIMER2=2000 + INSTALL_NBINOTIFICATIONS=True commands = ./dockercmd.sh run -d -p 2181:2181 -p 9092:9092 --env ADVERTISED_LISTENERS=PLAINTEXT://localhost:9092 --name tpce_kafka1 teivah/kafka:2.0.0 -- 2.36.6