我有我的yarn
cluster
模式运行的火花工作。我需要通过我的应用程序特定的Java属性文件。我这样做的java FileInputStream
。
但我现在面临的FileNotFoundException异常/home/aiman/config/my-file.properties
我的Java属性文件是:/home/aiman/config/my-file.properties
mongo_server=my.mongo.server
mongo_port=1530
mongo_user=mongoadmin
mongo_password=readONLYpass
mongo_db=testdb
我spark-submit
的样子:
spark-submit --master yarn --deploy-mode cluster --class mongo.MongoRead --jars /home/aiman/ojdbc-7.jar /home/aiman/app/jars/MongoRead-0.1-jar-with-dependencies.jar /home/aiman/config/my-file.properties
代码片段:
public static void main(final String[] args) throws Exception
{
if(args.length<1){
System.out.println("Please provide properties file path");
System.exit(1);
}
System.out.println("Mongo Import Begins...");
Properties prop = new Properties();
InputStream in = null;
try{
in = new FileInputStream(args[0]);
prop.load(in);
}
catch(Exception e){
e.printStackTrace();
System.exit(1);
}
/*Reading the properties*/
String mongoServer = prop.getProperty("mongo_server");
String mongoPort = prop.getProperty("mongo_port");
String mongoUser = prop.getProperty("mongo_user");
....
...
String mongoAddress = "mongodb://"+mongoUser+":"+mongoPassword+"@"+mongoServer+":"+mongoPort+"/"+mongoDb+"."+tableNm;
SparkSession spark = SparkSession.builder()
.appName("MongoSparkRecordReader")
.config("spark.mongodb.input.uri", mongoAddress)
.config("spark.mongodb.output.uri", mongoAddress)
.getOrCreate();
JavaSparkContext jsc = new JavaSparkContext(spark.sparkContext());
...
..
}
请建议什么错误。我在读的属性在一个错误的方式文件,它没有找到想要的文件?
你应该通过“--file /home/aiman/config/my-file.properties”火花提交的说法,这将文件分发到由纱会发现“我的文件推出了集装箱通过本地文件。在他们的JVM的类路径中属性”。然后,您应该能够阅读它作为一个JVM的本地资源。
在--deploy-mode client
运行这样可以解决问题。司机是越来越推出,其中属性文件存在。因此,文件越来越阅读并没有得到任何的异常。