Adapt lighty to run with optional karaf features 79/100979/2
authorGilles Thouenon <gilles.thouenon@orange.com>
Sun, 8 May 2022 16:45:28 +0000 (18:45 +0200)
committerGuillaume Lambert <guillaume.lambert@orange.com>
Tue, 10 May 2022 12:50:54 +0000 (12:50 +0000)
- 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 <gilles.thouenon@orange.com>
Change-Id: I85c9a27f38de01343e4f13ce548440a9171502b1

lighty/src/main/assembly/resources/clean-start-controller.sh
lighty/src/main/java/io/lighty/controllers/tpce/Main.java
lighty/src/main/java/io/lighty/controllers/tpce/module/TransportPCEImpl.java
lighty/src/test/java/io/lighty/controllers/tpce/MaintTest.java
tox.ini

index ad4926ddc42df34c97dfae4afc89f5c037ac02a8..89907be25460efee9a10184ae8a99751983ab803 100755 (executable)
@@ -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
index 9215bc29fee36c0dfe42d5cd2e8a72db76763f7d..043f37f9657f7cfbc738100e8b24d3ce6ed91a6f 100644 (file)
@@ -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(
index 276940850bddb42f12e478f5083ff4c8755df50d..ef88bf77e81598a2dc3f74de3f7af0bf7b45c118 100644 (file)
@@ -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<String> 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();
index 872cb52050706e17fc6381076409d6f0b677350b..98abb12dba47b8404d92cd21e9e210b5fbb57593 100644 (file)
@@ -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 3491f79c754f1c555c2a8c937975e55212c66a88..d2936ac2b4d4324119a67dfc9a6748b815633468 100644 (file)
--- 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