2

我有一份 hadoop 工作,其中包括一些春豆。此外,在 spring 上下文文件中,有一个名为 app.properties 的 PropertyPlaceholderConfigurer。

这个 app.properties 在 jar 文件中,想法是将其从 jar 文件中删除,以便在不重新编译的情况下更改某些属性。

我尝试了该-file选项,该-jarlibs选项但均未奏效。

有任何想法吗?

4

2 回答 2

3

我所做的是:

  • 子类化 PropertyPlaceholderConfigurer
  • 覆盖 loadProperties 方法
  • 如果有自定义 System.getProperty("hdfs_path")

        try {
            Path pt = new Path(hdfsLocationPath);
            FileSystem fs = FileSystem.get(new Configuration());
            BufferedReader br = new BufferedReader(new InputStreamReader(fs.open(pt)));
            props.load(br);
        } catch (Exception e) {
            LOG.error(e);
        }
    

奇迹般有效 ...

于 2012-12-19T21:27:11.990 回答
1

您可以将此属性文件添加到分布式缓存,如下所示:

...
String s3PropertiesFilePath = args[0];
DistributedCache.addCacheFile(new URI(s3PropertiesFilePath), conf);
...

稍后,在 mapper/reducer 的 configure() 中,您可以执行以下操作:

...
Path s3PropertiesFilePath;
Properties prop = new Properties();
@Override
public void configure(JobConf job) {
    s3PropertiesFilePath = DistributedCache.getLocalCacheFiles(job)[0];
    //load the properties file
    prop.load(new FileInputStream(s3PropertiesFilePath.toString()));
...
}

PS:如果您没有在 Amazon EMR 上运行它,那么您可以将此属性文件保存在您的 hdfs 中并提供该路径。

于 2012-12-18T14:50:00.003 回答