使用ToolRunner和GenericOptionParser在Hadoop上使用Yaml而不是xml配置文件

时间:2015-01-26 10:11:30

标签: hadoop yaml config

我正在开发一个MapReduce(hadoop2.6)应用程序,我想使用yaml格式而不是xml配置格式

例如

configuration:
  hello: "world"

而不是

<?xml version="1.0"?>
<configuration>
    <property>
        <name>hello</name>
        <value>world</value>
    </property>
</configuration>

有没有办法告诉ToolRunner,解析器,或者我提供Yaml文件的人?或此功能不存在,但< / em>的)


以下是该应用程序的框架:

public class MyDriver extends Configured implements Tool {

    private static final Logger log = LoggerFactory.getLogger(FractalDriver.class);

    static {
        Configuration.addDefaultResource("fractals-default.yml"); 
    }

    @Override
    public int run(String[] strings) throws Exception {
        System.out.println("Waiting for that day, I say hello to you {}!",
                           getConf().get("hello", "les gens"));

        return 0;
    }


    public static void main(String[] args) throws Exception {
        int exitCode = ToolRunner.run(new FractalDriver(), args);
        System.exit(exitCode);
    }
}

当然,如果我尝试这个,我会得到一个例外:

[Fatal Error] my-default.yml:1:1: Content is not allowed in prolog.
Exception in thread "main" java.lang.RuntimeException: org.xml.sax.SAXParseException; systemId: file:/SOMEPATH/target/classes/my-default.yml; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
    at org.apache.hadoop.conf.Configuration.loadResource(Configuration.java:2517)
    at org.apache.hadoop.conf.Configuration.loadResources(Configuration.java:2364)
    at ...

0 个答案:

没有答案