Web ログを分析するための MapReduce ジョブを作成しています。私のコードは、IP アドレスを地理的位置にマップすることを目的としており、そのために Maxmind Geo API ( https://github.com/maxmind/geoip-api-java ) を使用しています。私のコードには、IP と場所の一致を含むデータベース ファイルを必要とする LookupService メソッドがあります。分散キャッシュを使用してこのデータベース ファイルを渡そうとしています。私は2つの異なる方法でこれをやってみました
ケース1:
HDFS からファイルを渡すジョブを実行しますが、常に「ファイルが見つかりません」というエラーがスローされます。
sudo -u hdfs hadoop jar \
WebLogProcessing-0.0.1-SNAPSHOT-jar-with-dependencies.jar \
GeoLocationDatasetDriver /user/hdfs/input /user/hdfs/out_put \
/user/hdfs/GeoLiteCity.dat
また
sudo -u hdfs hadoop jar \
WebLogProcessing-0.0.1-SNAPSHOT-jar-with-dependencies.jar \
GeoLocationDatasetDriver /user/hdfs/input /user/hdfs/out_put \
hdfs://sandbox.hortonworks.com:8020/user/hdfs/GeoLiteCity.dat
ドライバー クラス コード:
Configuration conf = getConf();
Job job = Job.getInstance(conf);
job.addCacheFile(new Path(args[2]).toUri());
マッパー クラス コード:
public void setup(Context context) throws IOException
{
URI[] uriList = context.getCacheFiles();
Path database_path = new Path(uriList[0].toString());
LookupService cl = new LookupService(database_path.toString(),
LookupService.GEOIP_MEMORY_CACHE | LookupService.GEOIP_CHECK_CACHE);
}
ケース 2: -files オプションを介してローカル ファイル システムからファイルを渡すことにより、コードを実行します。エラー:行 LookupService cl = new LookupService(database_path) で Null ポインタ例外が発生しました
sudo -u hdfs hadoop jar \
WebLogProcessing-0.0.1-SNAPSHOT-jar-with-dependencies.jar \
com.prithvi.mapreduce.logprocessing.ipgeo.GeoLocationDatasetDriver \
-files /tmp/jobs/GeoLiteCity.dat /user/hdfs/input /user/hdfs/out_put \
GeoLiteCity.dat
ドライバーコード:
Configuration conf = getConf();
Job job = Job.getInstance(conf);
String dbfile = args[2];
conf.set("maxmind.geo.database.file", dbfile);
マッパー コード:
public void setup(Context context) throws IOException
{
Configuration conf = context.getConfiguration();
String database_path = conf.get("maxmind.geo.database.file");
LookupService cl = new LookupService(database_path,
LookupService.GEOIP_MEMORY_CACHE | LookupService.GEOIP_CHECK_CACHE);
}
仕事を遂行するには、すべてのタスク トラッカーでこのデータベース ファイルが必要です。誰でも正しい方法を教えてもらえますか?