@Test() @Category(UnitTest.class) public void testRunEmpty() throws Exception { int ret = mrgeo.run(new String[]{}); Assert.assertEquals("Unexpected return value", -1, ret); }
@Override public int run(String[] args) throws IOException { if (commands == null) { loadCommands(); } Options options = createOptions(); if (args.length == 0) { general_usage(options); return -1; } String cmdStr = args[0]; if (cmdStr.equals("-h") || cmdStr.equals("--help")) { general_usage(options); return 0; } CommandSpi spi = commands.get(cmdStr); Command cmd; if (spi == null) { System.out.println("Command not found: " + cmdStr); System.out.println(); general_usage(options); return -1; } else { try { cmd = spi.getCommandClass().newInstance(); } catch (InstantiationException | IllegalAccessException e) { log.error("Exception thrown", e); return -1; } cmd.addOptions(options); } CommandLine line; try { CommandLineParser parser = new ExtendedGnuParser(true); line = parser.parse(options, Arrays.copyOfRange(args, 1, args.length)); } catch (ParseException e) { if (args.length > 1) { for (String help: args) { if (help.equals("-h") || help.equals("--help")) { specific_usage(cmd, options); return 0; } } } System.out.println(e.getMessage()); specific_usage(cmd, options); return -1; } long start = System.currentTimeMillis(); try { if (line.hasOption("h")) { specific_usage(cmd, options); return 0; } else { if (line.hasOption("np")) { MrGeoProperties.getInstance().setProperty(MrGeoConstants.MRGEO_AUTOPERSISTANCE, "false"); } if (line.hasOption("d")) { LoggingUtils.setDefaultLogLevel(LoggingUtils.DEBUG); } else if (line.hasOption("v")) { LoggingUtils.setDefaultLogLevel(LoggingUtils.INFO); } else { LoggingUtils.setDefaultLogLevel(LoggingUtils.ERROR); HadoopUtils.adjustLogging(); } if (line.hasOption("exec")) { MrGeoProperties.getInstance().setProperty(MrGeoConstants.MRGEO_MAXEXECUTORS, line.getOptionValue("exec")); } if (line.hasOption("cores")) { MrGeoProperties.getInstance().setProperty(MrGeoConstants.MRGEO_MAXCORES, line.getOptionValue("cores")); } if (line.hasOption("mem")) { MrGeoProperties.getInstance().setProperty(MrGeoConstants.MRGEO_MAXMEMORY, line.getOptionValue("mem")); } } if (line.hasOption("l")) { System.out.println("Using local runner"); HadoopUtils.setupLocalRunner(getConf()); } if (!commands.containsKey(cmdStr)) { int ret = 0; if (!line.hasOption("h")) { System.out.println("Command not found: " + cmdStr); System.out.println(); ret = -1; } general_usage(options); return ret; } ProviderProperties providerProperties = new ProviderProperties(); try { return cmd.run(line, getConf(), providerProperties); } catch (ParseException e) { System.out.println(e.getMessage()); new HelpFormatter().printHelp(cmd.getUsage(), options); return -1; } } finally { long end = System.currentTimeMillis(); long duration = end - start; PeriodFormatter formatter = new PeriodFormatterBuilder() .appendHours() .appendSuffix("h:") .appendMinutes() .appendSuffix("m:") .appendSeconds() .appendSuffix("s") .toFormatter(); String formatted = formatter.print(new Period(duration)); log.info(cmdStr + " completed in " + formatted); System.out.println(cmdStr + " completed in " + formatted); } }
MrGeo extends Configured implements Tool { @Override public int run(String[] args) throws IOException { if (commands == null) { loadCommands(); } Options options = createOptions(); if (args.length == 0) { general_usage(options); return -1; } String cmdStr = args[0]; if (cmdStr.equals("-h") || cmdStr.equals("--help")) { general_usage(options); return 0; } CommandSpi spi = commands.get(cmdStr); Command cmd; if (spi == null) { System.out.println("Command not found: " + cmdStr); System.out.println(); general_usage(options); return -1; } else { try { cmd = spi.getCommandClass().newInstance(); } catch (InstantiationException | IllegalAccessException e) { log.error("Exception thrown", e); return -1; } cmd.addOptions(options); } CommandLine line; try { CommandLineParser parser = new ExtendedGnuParser(true); line = parser.parse(options, Arrays.copyOfRange(args, 1, args.length)); } catch (ParseException e) { if (args.length > 1) { for (String help: args) { if (help.equals("-h") || help.equals("--help")) { specific_usage(cmd, options); return 0; } } } System.out.println(e.getMessage()); specific_usage(cmd, options); return -1; } long start = System.currentTimeMillis(); try { if (line.hasOption("h")) { specific_usage(cmd, options); return 0; } else { if (line.hasOption("np")) { MrGeoProperties.getInstance().setProperty(MrGeoConstants.MRGEO_AUTOPERSISTANCE, "false"); } if (line.hasOption("d")) { LoggingUtils.setDefaultLogLevel(LoggingUtils.DEBUG); } else if (line.hasOption("v")) { LoggingUtils.setDefaultLogLevel(LoggingUtils.INFO); } else { LoggingUtils.setDefaultLogLevel(LoggingUtils.ERROR); HadoopUtils.adjustLogging(); } if (line.hasOption("exec")) { MrGeoProperties.getInstance().setProperty(MrGeoConstants.MRGEO_MAXEXECUTORS, line.getOptionValue("exec")); } if (line.hasOption("cores")) { MrGeoProperties.getInstance().setProperty(MrGeoConstants.MRGEO_MAXCORES, line.getOptionValue("cores")); } if (line.hasOption("mem")) { MrGeoProperties.getInstance().setProperty(MrGeoConstants.MRGEO_MAXMEMORY, line.getOptionValue("mem")); } } if (line.hasOption("l")) { System.out.println("Using local runner"); HadoopUtils.setupLocalRunner(getConf()); } if (!commands.containsKey(cmdStr)) { int ret = 0; if (!line.hasOption("h")) { System.out.println("Command not found: " + cmdStr); System.out.println(); ret = -1; } general_usage(options); return ret; } ProviderProperties providerProperties = new ProviderProperties(); try { return cmd.run(line, getConf(), providerProperties); } catch (ParseException e) { System.out.println(e.getMessage()); new HelpFormatter().printHelp(cmd.getUsage(), options); return -1; } } finally { long end = System.currentTimeMillis(); long duration = end - start; PeriodFormatter formatter = new PeriodFormatterBuilder() .appendHours() .appendSuffix("h:") .appendMinutes() .appendSuffix("m:") .appendSeconds() .appendSuffix("s") .toFormatter(); String formatted = formatter.print(new Period(duration)); log.info(cmdStr + " completed in " + formatted); System.out.println(cmdStr + " completed in " + formatted); } } }
MrGeo extends Configured implements Tool { @Override public int run(String[] args) throws IOException { if (commands == null) { loadCommands(); } Options options = createOptions(); if (args.length == 0) { general_usage(options); return -1; } String cmdStr = args[0]; if (cmdStr.equals("-h") || cmdStr.equals("--help")) { general_usage(options); return 0; } CommandSpi spi = commands.get(cmdStr); Command cmd; if (spi == null) { System.out.println("Command not found: " + cmdStr); System.out.println(); general_usage(options); return -1; } else { try { cmd = spi.getCommandClass().newInstance(); } catch (InstantiationException | IllegalAccessException e) { log.error("Exception thrown", e); return -1; } cmd.addOptions(options); } CommandLine line; try { CommandLineParser parser = new ExtendedGnuParser(true); line = parser.parse(options, Arrays.copyOfRange(args, 1, args.length)); } catch (ParseException e) { if (args.length > 1) { for (String help: args) { if (help.equals("-h") || help.equals("--help")) { specific_usage(cmd, options); return 0; } } } System.out.println(e.getMessage()); specific_usage(cmd, options); return -1; } long start = System.currentTimeMillis(); try { if (line.hasOption("h")) { specific_usage(cmd, options); return 0; } else { if (line.hasOption("np")) { MrGeoProperties.getInstance().setProperty(MrGeoConstants.MRGEO_AUTOPERSISTANCE, "false"); } if (line.hasOption("d")) { LoggingUtils.setDefaultLogLevel(LoggingUtils.DEBUG); } else if (line.hasOption("v")) { LoggingUtils.setDefaultLogLevel(LoggingUtils.INFO); } else { LoggingUtils.setDefaultLogLevel(LoggingUtils.ERROR); HadoopUtils.adjustLogging(); } if (line.hasOption("exec")) { MrGeoProperties.getInstance().setProperty(MrGeoConstants.MRGEO_MAXEXECUTORS, line.getOptionValue("exec")); } if (line.hasOption("cores")) { MrGeoProperties.getInstance().setProperty(MrGeoConstants.MRGEO_MAXCORES, line.getOptionValue("cores")); } if (line.hasOption("mem")) { MrGeoProperties.getInstance().setProperty(MrGeoConstants.MRGEO_MAXMEMORY, line.getOptionValue("mem")); } } if (line.hasOption("l")) { System.out.println("Using local runner"); HadoopUtils.setupLocalRunner(getConf()); } if (!commands.containsKey(cmdStr)) { int ret = 0; if (!line.hasOption("h")) { System.out.println("Command not found: " + cmdStr); System.out.println(); ret = -1; } general_usage(options); return ret; } ProviderProperties providerProperties = new ProviderProperties(); try { return cmd.run(line, getConf(), providerProperties); } catch (ParseException e) { System.out.println(e.getMessage()); new HelpFormatter().printHelp(cmd.getUsage(), options); return -1; } } finally { long end = System.currentTimeMillis(); long duration = end - start; PeriodFormatter formatter = new PeriodFormatterBuilder() .appendHours() .appendSuffix("h:") .appendMinutes() .appendSuffix("m:") .appendSeconds() .appendSuffix("s") .toFormatter(); String formatted = formatter.print(new Period(duration)); log.info(cmdStr + " completed in " + formatted); System.out.println(cmdStr + " completed in " + formatted); } }  }
MrGeo extends Configured implements Tool { @Override public int run(String[] args) throws IOException { if (commands == null) { loadCommands(); } Options options = createOptions(); if (args.length == 0) { general_usage(options); return -1; } String cmdStr = args[0]; if (cmdStr.equals("-h") || cmdStr.equals("--help")) { general_usage(options); return 0; } CommandSpi spi = commands.get(cmdStr); Command cmd; if (spi == null) { System.out.println("Command not found: " + cmdStr); System.out.println(); general_usage(options); return -1; } else { try { cmd = spi.getCommandClass().newInstance(); } catch (InstantiationException | IllegalAccessException e) { log.error("Exception thrown", e); return -1; } cmd.addOptions(options); } CommandLine line; try { CommandLineParser parser = new ExtendedGnuParser(true); line = parser.parse(options, Arrays.copyOfRange(args, 1, args.length)); } catch (ParseException e) { if (args.length > 1) { for (String help: args) { if (help.equals("-h") || help.equals("--help")) { specific_usage(cmd, options); return 0; } } } System.out.println(e.getMessage()); specific_usage(cmd, options); return -1; } long start = System.currentTimeMillis(); try { if (line.hasOption("h")) { specific_usage(cmd, options); return 0; } else { if (line.hasOption("np")) { MrGeoProperties.getInstance().setProperty(MrGeoConstants.MRGEO_AUTOPERSISTANCE, "false"); } if (line.hasOption("d")) { LoggingUtils.setDefaultLogLevel(LoggingUtils.DEBUG); } else if (line.hasOption("v")) { LoggingUtils.setDefaultLogLevel(LoggingUtils.INFO); } else { LoggingUtils.setDefaultLogLevel(LoggingUtils.ERROR); HadoopUtils.adjustLogging(); } if (line.hasOption("exec")) { MrGeoProperties.getInstance().setProperty(MrGeoConstants.MRGEO_MAXEXECUTORS, line.getOptionValue("exec")); } if (line.hasOption("cores")) { MrGeoProperties.getInstance().setProperty(MrGeoConstants.MRGEO_MAXCORES, line.getOptionValue("cores")); } if (line.hasOption("mem")) { MrGeoProperties.getInstance().setProperty(MrGeoConstants.MRGEO_MAXMEMORY, line.getOptionValue("mem")); } } if (line.hasOption("l")) { System.out.println("Using local runner"); HadoopUtils.setupLocalRunner(getConf()); } if (!commands.containsKey(cmdStr)) { int ret = 0; if (!line.hasOption("h")) { System.out.println("Command not found: " + cmdStr); System.out.println(); ret = -1; } general_usage(options); return ret; } ProviderProperties providerProperties = new ProviderProperties(); try { return cmd.run(line, getConf(), providerProperties); } catch (ParseException e) { System.out.println(e.getMessage()); new HelpFormatter().printHelp(cmd.getUsage(), options); return -1; } } finally { long end = System.currentTimeMillis(); long duration = end - start; PeriodFormatter formatter = new PeriodFormatterBuilder() .appendHours() .appendSuffix("h:") .appendMinutes() .appendSuffix("m:") .appendSeconds() .appendSuffix("s") .toFormatter(); String formatted = formatter.print(new Period(duration)); log.info(cmdStr + " completed in " + formatted); System.out.println(cmdStr + " completed in " + formatted); } }  static void main(String[] args); @Override int run(String[] args); }
MrGeo extends Configured implements Tool { @Override public int run(String[] args) throws IOException { if (commands == null) { loadCommands(); } Options options = createOptions(); if (args.length == 0) { general_usage(options); return -1; } String cmdStr = args[0]; if (cmdStr.equals("-h") || cmdStr.equals("--help")) { general_usage(options); return 0; } CommandSpi spi = commands.get(cmdStr); Command cmd; if (spi == null) { System.out.println("Command not found: " + cmdStr); System.out.println(); general_usage(options); return -1; } else { try { cmd = spi.getCommandClass().newInstance(); } catch (InstantiationException | IllegalAccessException e) { log.error("Exception thrown", e); return -1; } cmd.addOptions(options); } CommandLine line; try { CommandLineParser parser = new ExtendedGnuParser(true); line = parser.parse(options, Arrays.copyOfRange(args, 1, args.length)); } catch (ParseException e) { if (args.length > 1) { for (String help: args) { if (help.equals("-h") || help.equals("--help")) { specific_usage(cmd, options); return 0; } } } System.out.println(e.getMessage()); specific_usage(cmd, options); return -1; } long start = System.currentTimeMillis(); try { if (line.hasOption("h")) { specific_usage(cmd, options); return 0; } else { if (line.hasOption("np")) { MrGeoProperties.getInstance().setProperty(MrGeoConstants.MRGEO_AUTOPERSISTANCE, "false"); } if (line.hasOption("d")) { LoggingUtils.setDefaultLogLevel(LoggingUtils.DEBUG); } else if (line.hasOption("v")) { LoggingUtils.setDefaultLogLevel(LoggingUtils.INFO); } else { LoggingUtils.setDefaultLogLevel(LoggingUtils.ERROR); HadoopUtils.adjustLogging(); } if (line.hasOption("exec")) { MrGeoProperties.getInstance().setProperty(MrGeoConstants.MRGEO_MAXEXECUTORS, line.getOptionValue("exec")); } if (line.hasOption("cores")) { MrGeoProperties.getInstance().setProperty(MrGeoConstants.MRGEO_MAXCORES, line.getOptionValue("cores")); } if (line.hasOption("mem")) { MrGeoProperties.getInstance().setProperty(MrGeoConstants.MRGEO_MAXMEMORY, line.getOptionValue("mem")); } } if (line.hasOption("l")) { System.out.println("Using local runner"); HadoopUtils.setupLocalRunner(getConf()); } if (!commands.containsKey(cmdStr)) { int ret = 0; if (!line.hasOption("h")) { System.out.println("Command not found: " + cmdStr); System.out.println(); ret = -1; } general_usage(options); return ret; } ProviderProperties providerProperties = new ProviderProperties(); try { return cmd.run(line, getConf(), providerProperties); } catch (ParseException e) { System.out.println(e.getMessage()); new HelpFormatter().printHelp(cmd.getUsage(), options); return -1; } } finally { long end = System.currentTimeMillis(); long duration = end - start; PeriodFormatter formatter = new PeriodFormatterBuilder() .appendHours() .appendSuffix("h:") .appendMinutes() .appendSuffix("m:") .appendSeconds() .appendSuffix("s") .toFormatter(); String formatted = formatter.print(new Period(duration)); log.info(cmdStr + " completed in " + formatted); System.out.println(cmdStr + " completed in " + formatted); } }  static void main(String[] args); @Override int run(String[] args);  }