Do not use RpcService in TPCE networkmodel module
[transportpce.git] / lighty / src / main / java / io / lighty / controllers / tpce / Main.java
index b979e08477de27bcd9b9171215b74d531d88caa5..f7521205a17ed8320d52c1c19574060079c7222b 100644 (file)
@@ -20,13 +20,13 @@ import io.lighty.core.controller.impl.config.ControllerConfiguration;
 import io.lighty.core.controller.impl.util.ControllerConfigUtils;
 import io.lighty.modules.northbound.restconf.community.impl.CommunityRestConf;
 import io.lighty.modules.northbound.restconf.community.impl.CommunityRestConfBuilder;
-import io.lighty.modules.northbound.restconf.community.impl.config.JsonRestConfServiceType;
 import io.lighty.modules.northbound.restconf.community.impl.config.RestConfConfiguration;
 import io.lighty.modules.northbound.restconf.community.impl.util.RestConfConfigUtils;
 import io.lighty.modules.southbound.netconf.impl.NetconfSBPlugin;
 import io.lighty.modules.southbound.netconf.impl.NetconfTopologyPluginBuilder;
 import io.lighty.modules.southbound.netconf.impl.config.NetconfConfiguration;
 import io.lighty.modules.southbound.netconf.impl.util.NetconfConfigUtils;
+import io.lighty.openapi.OpenApiLighty;
 import io.lighty.server.LightyServerBuilder;
 import java.io.IOException;
 import java.net.InetSocketAddress;
@@ -34,7 +34,6 @@ 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;
@@ -47,19 +46,22 @@ 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 String TAPI_OPTION_NAME = "tapi";
+    private static final String OLMTIMER1_OPTION_NAME = "olmtimer1";
+    private static final String OLMTIMER2_OPTION_NAME = "olmtimer2";
 
     private static final Logger LOG = LoggerFactory.getLogger(Main.class);
 
     private ShutdownHook shutdownHook;
 
     public void start() {
-        start(null, false, false);
+        start(null, false, false, null, null, false);
     }
 
     @SuppressWarnings("checkstyle:Illegalcatch")
-    public void start(String restConfConfigurationFile, boolean activateNbiNotification, boolean registerShutdownHook) {
+    public void start(String restConfConfigurationFile, boolean activateNbiNotification, boolean activateTapi,
+                      String olmtimer1, String olmtimer2, boolean registerShutdownHook) {
         long startTime = System.nanoTime();
         TpceBanner.print();
         RestConfConfiguration restConfConfig = null;
@@ -80,10 +82,10 @@ public class Main {
                 restConfConfig.setHttpPort(8181);
 
             }
-            restConfConfig.setJsonRestconfServiceType(JsonRestConfServiceType.DRAFT_02);
             // 3. NETCONF SBP configuration
             NetconfConfiguration netconfSBPConfig = NetconfConfigUtils.createDefaultNetconfConfiguration();
-            startLighty(singleNodeConfiguration, restConfConfig, netconfSBPConfig, registerShutdownHook, activateNbiNotification);
+            startLighty(singleNodeConfiguration, restConfConfig, netconfSBPConfig, registerShutdownHook,
+                    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) {
@@ -102,9 +104,8 @@ public class Main {
         }
     }
 
-    /**
-     * Build options for command line arguments
-     * @return
+    /*
+     * Build options for command line arguments.
      */
     private static Options buildOptions() {
         Option restconfFileOption = Option.builder(RESTCONF_OPTION_NAME)
@@ -114,21 +115,42 @@ public class Main {
                 .required(false)
                 .build();
         Option useNbiNotificationsOption = Option.builder(NBINOTIFICATION_OPTION_NAME)
-                .desc("Activate NBI notifications feature")
-                .argName(NBINOTIFICATION_OPTION_NAME)
-                .hasArg(false)
+            .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)
+                .hasArg(true)
+                .required(false)
+                .build();
+        Option olmTimer2Option = Option.builder(OLMTIMER2_OPTION_NAME)
+                .desc("OLM timer 2 value")
+                .argName(OLMTIMER1_OPTION_NAME)
+                .hasArg(true)
                 .required(false)
                 .build();
         Options options = new Options();
         options.addOption(restconfFileOption);
         options.addOption(useNbiNotificationsOption);
+        options.addOption(useTapiOption);
+        options.addOption(olmTimer1Option);
+        options.addOption(olmTimer2Option);
         return options;
     }
 
     private void startLighty(ControllerConfiguration controllerConfiguration,
             RestConfConfiguration restConfConfiguration, NetconfConfiguration netconfSBPConfiguration,
-            boolean registerShutdownHook, boolean activateNbiNotification)
-                    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)
@@ -136,16 +158,21 @@ public class Main {
         LightyController lightyController = lightyControllerBuilder.from(controllerConfiguration).build();
         lightyController.start().get();
 
-        // 2. start RestConf server
+        // 2. Start swagger server
         LightyServerBuilder jettyServerBuilder = new LightyServerBuilder(
                 new InetSocketAddress(restConfConfiguration.getInetAddress(), restConfConfiguration.getHttpPort()));
         CommunityRestConfBuilder communityRestConfBuilder = CommunityRestConfBuilder.from(
                 RestConfConfigUtils.getRestConfConfiguration(restConfConfiguration, lightyController.getServices()));
+        OpenApiLighty swagger = new OpenApiLighty(restConfConfiguration, jettyServerBuilder,
+                lightyController.getServices());
+        swagger.start().get();
+
+        // 3. start RestConf server
         CommunityRestConf communityRestConf = communityRestConfBuilder.withLightyServer(jettyServerBuilder).build();
         communityRestConf.start().get();
         communityRestConf.startServer();
 
-        // 3. start NetConf SBP
+        // 4. start NetConf SBP
         NetconfSBPlugin netconfSouthboundPlugin;
         netconfSBPConfiguration = NetconfConfigUtils.injectServicesToTopologyConfig(netconfSBPConfiguration,
                 lightyController.getServices());
@@ -155,11 +182,12 @@ public class Main {
                 .build();
         netconfSouthboundPlugin.start().get();
 
-        // 4. start TransportPCE beans
-        TransportPCE transportPCE = new TransportPCEImpl(lightyController.getServices(), activateNbiNotification);
+        // 5. start TransportPCE beans
+        TransportPCE transportPCE = new TransportPCEImpl(lightyController.getServices(), activateNbiNotification,
+            activateTapi, olmtimer1, olmtimer2);
         transportPCE.start().get();
 
-        // 5. Register shutdown hook for graceful shutdown.
+        // 6. Register shutdown hook for graceful shutdown.
         shutdownHook = new ShutdownHook(lightyController, communityRestConf, netconfSouthboundPlugin, transportPCE);
         if (registerShutdownHook) {
             Runtime.getRuntime().addShutdownHook(shutdownHook);
@@ -176,15 +204,19 @@ 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, true);
+            app.start(restConfConfigurationFile, useNbiNotifications, useTapi, olmtimer1, olmtimer2, true);
         } catch (ParseException e) {
             HelpFormatter formatter = new HelpFormatter();
             formatter.printHelp(
                     "java -ms<size> -mx<size> -XX:MaxMetaspaceSize=<size> -jar tpce.jar "
                     + "[-restconf <restconfConfigurationFile>] [-nbinotification]"
-                    +" e.g. java -ms128m -mx512m -XX:MaxMetaspaceSize=128m -jar tpce.jar"
-                    + "-restconf ../src/test/resources/config.json -nbinotification",
+                    + " e.g. java -ms128m -mx512m -XX:MaxMetaspaceSize=128m -jar tpce.jar"
+                    + "-restconf ../src/test/resources/config.json -nbinotification"
+                    + "-olmtimer1 120000 -olmtimer2 20000",
                     options);
             System.exit(1);
         }