java.net.malformedurexception:无协议:向spark提交作业传递参数时为null

owfi6suc  于 2021-05-27  发布在  Spark
关注(0)|答案(1)|浏览(475)

我有一个小的sparkscala作业,它包含几个参数,即http\u endpoint

import scalaj.http.{Http, HttpOptions}

1 object Main extends App {
2
3   val master = args(0)
4   val http_endpoint = args(1)
5   ...
6   ...
7   
8   def sendRequest = ( text: String ) => {
9      println("#####################: " + http_endpoint)
10     val result = Http(http_endpoint)
11    ...
12    ...
13  }

然后,我把这个作为一个Spark提交工作纱。

spark-submit \
--master yarn \
my-job-example-assembly-1.0.0-SNAPSHOT.jar \
yarn \
"http://my-url-example-12311.us-west-1.elb.amazonaws.com/my/app"

错误:


##################### : null

Caused by: java.net.MalformedURLException: no protocol: null
    at java.net.URL.<init>(URL.java:611)
    at java.net.URL.<init>(URL.java:508)
    at java.net.URL.<init>(URL.java:457)
    at scalaj.http.HttpRequest.exec(Http.scala:343)
    at scalaj.http.HttpRequest.asString(Http.scala:492)

我甚至在我发送的url周围使用了语音引号,但是失败了。当我在第10行的代码中硬编码时,它就工作了。你知道我怎样才能让它在通过arg考试后继续工作吗?

plicqrtu

plicqrtu1#

尝试使用传递参数 --conf spark.driver.args="<args>" 在代码使用中 spark.sparkContext.getConf.get() 为了得到论点。

spark-submit --master yarn --conf spark.driver.args="yarn http://my-url-example-12311.us-west-1.elb.amazonaws.com/my/app" my-job-example-assembly-1.0.0-SNAPSHOT.jar
``` `Example:` ```
spark-shell --conf spark.driver.args="yarn http://my-url-example-12311.us-west-1.elb.amazonaws.com/my/app"

val arg0=spark.sparkContext.getConf.get("spark.driver.args").split("\\s+")(0)
//String = yarn
val arg1=spark.sparkContext.getConf.get("spark.driver.args").split("\\s+")(1)
//String = http://my-url-example-12311.us-west-1.elb.amazonaws.com/my/app

相关问题