X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=lighty%2Fsrc%2Fmain%2Fjava%2Fio%2Flighty%2Fcontrollers%2Ftpce%2FMain.java;h=0d84d5e99b38af82d45d6339b57a6d0d85f3ef9f;hb=7d4f682d48155fdc6c3b4ad1b1c05e58919f2655;hp=7ad45575fb4e009a093299ea3f46dfb81b6e064a;hpb=bfea62e2a8396424a527f0cad1521b8c16a13c90;p=transportpce.git 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 7ad45575f..0d84d5e99 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,33 @@ 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 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(new String[] {}, false); + start(null, false, null, null, false); } @SuppressWarnings("checkstyle:Illegalcatch") - public void start(String[] args, boolean registerShutdownHook) { + public void start(String restConfConfigurationFile, boolean activateNbiNotification, + String olmtimer1, String olmtimer2, boolean registerShutdownHook) { long startTime = System.nanoTime(); TpceBanner.print(); RestConfConfiguration restConfConfig = null; @@ -57,8 +69,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 +84,8 @@ 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, 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) { @@ -91,9 +104,47 @@ public class Main { } } + /** + * Build options for command line arguments. + * @return + */ + private static Options buildOptions() { + Option restconfFileOption = 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(); + 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(olmTimer1Option); + options.addOption(olmTimer2Option); + return options; + } + private void startLighty(ControllerConfiguration controllerConfiguration, RestConfConfiguration restConfConfiguration, NetconfConfiguration netconfSBPConfiguration, - boolean registerShutdownHook) throws ConfigurationException, ExecutionException, InterruptedException { + boolean registerShutdownHook, boolean activateNbiNotification, String olmtimer1, String olmtimer2) + throws ConfigurationException, ExecutionException, InterruptedException { // 1. initialize and start Lighty controller (MD-SAL, Controller, YangTools, // Akka) @@ -102,12 +153,11 @@ public class Main { lightyController.start().get(); // 2. start RestConf server - CommunityRestConfBuilder communityRestConfBuilder = new CommunityRestConfBuilder(); LightyServerBuilder jettyServerBuilder = new LightyServerBuilder( new InetSocketAddress(restConfConfiguration.getInetAddress(), restConfConfiguration.getHttpPort())); - CommunityRestConf communityRestConf = communityRestConfBuilder.from( - RestConfConfigUtils.getRestConfConfiguration(restConfConfiguration, lightyController.getServices())) - .withLightyServer(jettyServerBuilder).build(); + CommunityRestConfBuilder communityRestConfBuilder = CommunityRestConfBuilder.from( + RestConfConfigUtils.getRestConfConfiguration(restConfConfiguration, lightyController.getServices())); + CommunityRestConf communityRestConf = communityRestConfBuilder.withLightyServer(jettyServerBuilder).build(); communityRestConf.start().get(); communityRestConf.startServer(); @@ -115,13 +165,15 @@ public class Main { NetconfSBPlugin netconfSouthboundPlugin; netconfSBPConfiguration = NetconfConfigUtils.injectServicesToTopologyConfig(netconfSBPConfiguration, lightyController.getServices()); - NetconfTopologyPluginBuilder netconfSBPBuilder = new NetconfTopologyPluginBuilder(); + NetconfTopologyPluginBuilder netconfSBPBuilder = new NetconfTopologyPluginBuilder( + lightyController.getServices(), netconfSBPConfiguration); netconfSouthboundPlugin = netconfSBPBuilder.from(netconfSBPConfiguration, lightyController.getServices()) .build(); netconfSouthboundPlugin.start().get(); // 4. start TransportPCE beans - TransportPCE transportPCE = new TransportPCEImpl(lightyController.getServices()); + TransportPCE transportPCE = new TransportPCEImpl(lightyController.getServices(), activateNbiNotification, + olmtimer1, olmtimer2); transportPCE.start().get(); // 5. Register shutdown hook for graceful shutdown. @@ -136,8 +188,26 @@ public class Main { } public static void main(String[] args) { - Main app = new Main(); - app.start(args, true); + Options options = buildOptions(); + try { + CommandLine commandLine = new DefaultParser().parse(options, args); + String restConfConfigurationFile = commandLine.getOptionValue(RESTCONF_OPTION_NAME, null); + boolean useNbiNotifications = commandLine.hasOption(NBINOTIFICATION_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); + } catch (ParseException e) { + HelpFormatter formatter = new HelpFormatter(); + formatter.printHelp( + "java -ms -mx -XX:MaxMetaspaceSize= -jar tpce.jar " + + "[-restconf ] [-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); + } } private static class ShutdownHook extends Thread {