FrameworkUploader implements Runnable { @VisibleForTesting boolean parseArguments(String[] args) throws IOException { Options opts = new Options(); opts.addOption(OptionBuilder.create("h")); opts.addOption(OptionBuilder.create("help")); opts.addOption(OptionBuilder .withDescription("Input class path. Defaults to the default classpath.") .hasArg().create("input")); opts.addOption(OptionBuilder .withDescription( "Regex specifying the full path of jars to include in the" + " framework tarball. Default is a hardcoded set of jars" + " considered necessary to include") .hasArg().create("whitelist")); opts.addOption(OptionBuilder .withDescription( "Regex specifying the full path of jars to exclude in the" + " framework tarball. Default is a hardcoded set of jars" + " considered unnecessary to include") .hasArg().create("blacklist")); opts.addOption(OptionBuilder .withDescription( "Target file system to upload to." + " Example: hdfs: .hasArg().create("fs")); opts.addOption(OptionBuilder .withDescription( "Target file to upload to with a reference name." + " Example: /usr/mr-framework.tar.gz#mr-framework") .hasArg().create("target")); opts.addOption(OptionBuilder .withDescription( "Desired initial replication count. Default 3.") .hasArg().create("initialReplication")); opts.addOption(OptionBuilder .withDescription( "Desired final replication count. Default 10.") .hasArg().create("finalReplication")); opts.addOption(OptionBuilder .withDescription( "Desired acceptable replication count. Default 9.") .hasArg().create("acceptableReplication")); opts.addOption(OptionBuilder .withDescription( "Desired timeout for the acceptable" + " replication in seconds. Default 10") .hasArg().create("timeout")); opts.addOption(OptionBuilder .withDescription("Ignore symlinks into the same directory") .create("nosymlink")); GenericOptionsParser parser = new GenericOptionsParser(opts, args); if (parser.getCommandLine().hasOption("help") || parser.getCommandLine().hasOption("h")) { printHelp(opts); return false; } input = parser.getCommandLine().getOptionValue( "input", System.getProperty("java.class.path")); whitelist = parser.getCommandLine().getOptionValue( "whitelist", DefaultJars.DEFAULT_MR_JARS); blacklist = parser.getCommandLine().getOptionValue( "blacklist", DefaultJars.DEFAULT_EXCLUDED_MR_JARS); initialReplication = Short.parseShort(parser.getCommandLine().getOptionValue( "initialReplication", "3")); finalReplication = Short.parseShort(parser.getCommandLine().getOptionValue( "finalReplication", "10")); acceptableReplication = Short.parseShort( parser.getCommandLine().getOptionValue( "acceptableReplication", "9")); timeout = Integer.parseInt( parser.getCommandLine().getOptionValue("timeout", "10")); if (parser.getCommandLine().hasOption("nosymlink")) { ignoreSymlink = true; } String fs = parser.getCommandLine() .getOptionValue("fs", null); String path = parser.getCommandLine().getOptionValue("target", "/usr/lib/mr-framework.tar.gz#mr-framework"); boolean isFullPath = path.startsWith("hdfs: path.startsWith("file: if (fs == null) { fs = conf.get(FS_DEFAULT_NAME_KEY); if (fs == null && !isFullPath) { LOG.error("No filesystem specified in either fs or target."); printHelp(opts); return false; } else { LOG.info(String.format( "Target file system not specified. Using default %s", fs)); } } if (path.isEmpty()) { LOG.error("Target directory not specified"); printHelp(opts); return false; } StringBuilder absolutePath = new StringBuilder(); if (!isFullPath) { absolutePath.append(fs); absolutePath.append(path.startsWith("/") ? "" : "/"); } absolutePath.append(path); target = absolutePath.toString(); if (parser.getRemainingArgs().length > 0) { LOG.warn("Unexpected parameters"); printHelp(opts); return false; } return true; }  void run(); static void main(String[] args);  }
@Test public void testHelp() throws IOException { String[] args = new String[]{"-help"}; FrameworkUploader uploader = new FrameworkUploader(); boolean success = uploader.parseArguments(args); Assert.assertFalse("Expected to print help", success); Assert.assertEquals("Expected ignore run", null, uploader.input); Assert.assertEquals("Expected ignore run", null, uploader.whitelist); Assert.assertEquals("Expected ignore run", null, uploader.target); }
@Test public void testWrongArgument() throws IOException { String[] args = new String[]{"-unexpected"}; FrameworkUploader uploader = new FrameworkUploader(); boolean success = uploader.parseArguments(args); Assert.assertFalse("Expected to print help", success); }
@Test public void testArguments() throws IOException { String[] args = new String[]{ "-input", "A", "-whitelist", "B", "-blacklist", "C", "-fs", "hdfs: "-target", "D", "-initialReplication", "100", "-acceptableReplication", "120", "-finalReplication", "140", "-timeout", "10"}; FrameworkUploader uploader = new FrameworkUploader(); boolean success = uploader.parseArguments(args); Assert.assertTrue("Expected to print help", success); Assert.assertEquals("Input mismatch", "A", uploader.input); Assert.assertEquals("Whitelist mismatch", "B", uploader.whitelist); Assert.assertEquals("Blacklist mismatch", "C", uploader.blacklist); Assert.assertEquals("Target mismatch", "hdfs: uploader.target); Assert.assertEquals("Initial replication mismatch", 100, uploader.initialReplication); Assert.assertEquals("Acceptable replication mismatch", 120, uploader.acceptableReplication); Assert.assertEquals("Final replication mismatch", 140, uploader.finalReplication); Assert.assertEquals("Timeout mismatch", 10, uploader.timeout); }
@Test public void testNoFilesystem() throws IOException { FrameworkUploader uploader = new FrameworkUploader(); boolean success = uploader.parseArguments(new String[]{}); Assert.assertTrue("Expected to parse arguments", success); Assert.assertEquals( "Expected", "file: }