Hadoop实践(三)---Hadoop API 之 ToolRunner

29 篇文章 6 订阅
23 篇文章 0 订阅
本文介绍了如何在Hadoop实践中使用ToolRunner和GenericOptionsParser来运行实现了Tool接口的类,并解析通用的Hadoop命令行参数。ToolRunner能够与GenericOptionsParser配合,处理配置的修改,同时确保应用程序特定的选项直接传递。
摘要由CSDN通过智能技术生成

ToolRunner

ToolRunner可用于运行实现Tool接口的类。 它与GenericOptionsParser(通用选项解析器)一起工作以解析通用hadoop命令行参数并修改Tool的配置。 应用程序特定的选项将会不经修改就传递。

包含的方法

类型方法描述
static booleanconfirmPrompt(String prompt)向用户打印提示,如果用户使用“y”或“yes”响应,则返回true
static voidprintGenericCommandUsage(PrintStream out)打印通用命令行参数和使用信息
static intrun(Configuration conf, Tool tool, String[] args)在使用给定的泛型参数解析之后,通过Tool.run(String [])运行给定的工具
static intrun(Tool tool, String[] args)运行工具及其配置

从类java.lang.Object继承的方法:

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait、

例子:

public static boolean confirmPrompt(String prompt) throws IOException

向用户打印提示,如果用户使用“y”或“yes”响应,则返回true。 (不区分大小写)

Throws:IOException
public static void printGenericCommandUsage(PrintStream out)

打印通用命令行参数和使用信息

Parameters:
out - stream to write usage information to.
public static int run(Configuration conf,Tool tool,String[] args)throws Exception

在使用给定的泛型参数解析之后,通过Tool.run(String [])运行给定的工具。使用给定的配置,或如果为null则构建一个。使用可能修改的conf版本设置工具的配置。

Parameters:
conf - Configuration for the Tool.
tool - Tool to run.
args - command-line arguments to the tool.

Returns:
exit code of the Tool.run(String[]) method.

Throws:Exception
public static int run(Tool tool,String[] args)throws Exception

运行工具及其配置。相当于run(tool.getConf(),tool,args)

Parameters:
tool - Tool to run.
args - command-line arguments to the tool.

Returns:
exit code of the Tool.run(String[]) method.(Tool.run方法的退出代码)

Throws:
Exception
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值