(没有活动的SparkContext。)将Job提交给本地Spark master时出错

时间:2017-03-22 11:54:51

标签: java apache-spark

我在本地计算机上启动并运行了Spark Master和Spark Slave。我想通过这样的命令行配置将我的代码提交给我运行的Spark Master,就像文档中所描述的那样https://spark.apache.org/docs/latest/configuration.html#dynamically-loading-spark-properties

JavaSparkContext sc = new JavaSparkContext(new SparkConf());
JavaStreamingContext jssc = new JavaStreamingContext(sc, BATCH_SIZE);
...

在构建我的.jar之后,我通过

提交
bin/spark-submit --class logAnalysis.myApp --name "myApp" --master "spark://some.server:7077" /jars/myApp-0.3.jar

编辑:我之前尝试过没有引号的主人。

在此之后,我得到以下错误:

17/03/22 12:23:02 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
17/03/22 12:23:04 ERROR StandaloneSchedulerBackend: Application has been killed. Reason: Master removed our application: FAILED
17/03/22 12:23:04 ERROR SparkContext: Error initializing SparkContext.
java.lang.IllegalStateException: Cannot call methods on a stopped SparkContext.
This stopped SparkContext was created at:

org.apache.spark.api.java.JavaSparkContext.<init>(JavaSparkContext.scala:58)
logAnalysis.myApp.main(myApp.java:48)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:606)
org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:736)
org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:185)
org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:210)
org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:124)
org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)

The currently active SparkContext was created at:

(No active SparkContext.)

        at org.apache.spark.SparkContext.assertNotStopped(SparkContext.scala:101)
        at org.apache.spark.SparkContext.getSchedulingMode(SparkContext.scala:1658)
        at org.apache.spark.SparkContext.postEnvironmentUpdate(SparkContext.scala:2162)
        at org.apache.spark.SparkContext.<init>(SparkContext.scala:542)
        at org.apache.spark.api.java.JavaSparkContext.<init>(JavaSparkContext.scala:58)
        at logAnalysis.myApp.main(myApp.java:48)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:736)
        at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:185)
        at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:210)
        at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:124)
        at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
Exception in thread "main" java.lang.IllegalStateException: Cannot call methods on a stopped SparkContext.

My Spark Master在作业列表中显示作业失败,因此我成功连接到我的主人。

当我通过

提交工作时
bin/spark-submit --class logAnalysis.myApp--name "myApp" --master local[8] /jars/myApp-0.3.jar

它运作得很好。

使用spark 2.0.2,我的scala版本不是问题所在,如本主题所述:Why is "Cannot call methods on a stopped SparkContext" thrown when connecting to Spark Standalone from Java application?

一切都有点默认设置。一些建议为什么会发生这种情况?

1 个答案:

答案 0 :(得分:0)

我现在已经在我的群集中添加了另一个节点。它已成功运行1x Master - 2x Worker Setup。

除了将ElasticSearch-HadoopConnector添加到配置之外,没有更改代码中的任何内容:

JavaSparkContext sc = new JavaSparkContext(new SparkConf().set("es.nodes", "node1").set("es.port", "9200"));

我不知道问题是什么,也许是由Config引起的。但如前所述,当将Master设置为local [*]时,作业成功运行。