接上文
about云源码分析之hadoop2.x(2.7.1为例)二次开发基础:命令行添加
我们有了基础,那么只需要找到hadoop源码是如何添加、定义命令行即可。
同样我们找到宝
- package org.apache.hadoop.util中GenericOptionsParser
-
- private static Options buildGeneralOptions(Options opts) {
- Option fs = OptionBuilder.withArgName("local|namenode:port")
- .hasArg()
- .withDescription("specify a namenode")
- .create("fs");
- Option jt = OptionBuilder.withArgName("local|resourcemanager:port")
- .hasArg()
- .withDescription("specify a ResourceManager")
- .create("jt");
- Option oconf = OptionBuilder.withArgName("configuration file")
- .hasArg()
- .withDescription("specify an application configuration file")
- .create("conf");
- Option property = OptionBuilder.withArgName("property=value")
- .hasArg()
- .withDescription("use value for given property")
- .create('D');
- Option libjars = OptionBuilder.withArgName("paths")
- .hasArg()
- .withDescription("comma separated jar files to include in the classpath.")
- .create("libjars");
- Option files = OptionBuilder.withArgName("paths")
- .hasArg()
- .withDescription("comma separated files to be copied to the " +
- "map reduce cluster")
- .create("files");
- Option archives = OptionBuilder.withArgName("paths")
- .hasArg()
- .withDescription("comma separated archives to be unarchived" +
- " on the compute machines.")
- .create("archives");
-
- // file with security tokens
- Option tokensFile = OptionBuilder.withArgName("tokensFile")
- .hasArg()
- .withDescription("name of the file with the tokens")
- .create("tokenCacheFile");
-
- opts.addOption(fs);
- opts.addOption(jt);
- opts.addOption(oconf);
- opts.addOption(property);
- opts.addOption(libjars);
- opts.addOption(files);
- opts.addOption(archives);
- opts.addOption(tokensFile);
-
- return opts;
- }
复制代码
通过利用这个Options,你可以使用addOption()方法定义你的应用程序可接受的命令行参数,每次都为一个option调用一次这个方法
更多源码见附件:
GenericOptionsParser.zip
(5.19 KB, 下载次数: 13)
|