错误yarn.ApplicationMaster:用户类引发异常:java.lang.NoClassDefFoundError:scala / Function0 $ class

时间:2019-06-13 11:39:51

标签: java scala apache-spark hadoop

我正在尝试通过Apache Livy向Hadoop纱簇提交Spark作业。使用指定的here步骤设置集群。

Java代码正在Windows本地计算机上通过IntelliJ运行。 spark和hadoop群集位于linux服务器上。其他应用程序(不带Livy)可以通过hdfs上的操作和Spark计算完美运行。

我正在尝试运行在群集的应用程序的stderr中看到的错误日志:

INFO yarn.ApplicationMaster: Waiting for spark context initialization...
INFO driver.RSCDriver: Connecting to: master:10000
INFO driver.RSCDriver: Starting RPC server...
INFO rpc.RpcServer: Connected to the port 10001
WARN rsc.RSCConf: Your hostname, master, resolves to a loopback address, but we couldn't find any external IP address!
WARN rsc.RSCConf: Set livy.rsc.rpc.server.address if you need to bind to another address.
INFO driver.RSCDriver: Received job request 37e4684d-9de2-4a4b-9506-0b10a3e78a51
INFO driver.RSCDriver: SparkContext not yet up, queueing job request.
ERROR yarn.ApplicationMaster: User class threw exception: java.lang.NoClassDefFoundError: scala/Function0$class
java.lang.NoClassDefFoundError: scala/Function0$class
    at org.apache.livy.shaded.json4s.ThreadLocal.<init>(Formats.scala:311)
    at org.apache.livy.shaded.json4s.DefaultFormats$class.$init$(Formats.scala:318)
    at org.apache.livy.shaded.json4s.DefaultFormats$.<init>(Formats.scala:296)
    at org.apache.livy.shaded.json4s.DefaultFormats$.<clinit>(Formats.scala)
    at org.apache.livy.repl.Session.<init>(Session.scala:66)
    at org.apache.livy.repl.ReplDriver.initializeSparkEntries(ReplDriver.scala:41)
    at org.apache.livy.rsc.driver.RSCDriver.run(RSCDriver.java:333)
    at org.apache.livy.rsc.driver.RSCDriverBootstrapper.main(RSCDriverBootstrapper.java:93)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.spark.deploy.yarn.ApplicationMaster$$anon$2.run(ApplicationMaster.scala:684)
Caused by: java.lang.ClassNotFoundException: scala.Function0$class
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 13 more
INFO yarn.ApplicationMaster: Final app status: FAILED, exitCode: 13, (reason: User class threw exception: java.lang.NoClassDefFoundError: scala/Function0$class
    at org.apache.livy.shaded.json4s.ThreadLocal.<init>(Formats.scala:311)
    at org.apache.livy.shaded.json4s.DefaultFormats$class.$init$(Formats.scala:318)
    at org.apache.livy.shaded.json4s.DefaultFormats$.<init>(Formats.scala:296)
    at org.apache.livy.shaded.json4s.DefaultFormats$.<clinit>(Formats.scala)
    at org.apache.livy.repl.Session.<init>(Session.scala:66)
    at org.apache.livy.repl.ReplDriver.initializeSparkEntries(ReplDriver.scala:41)
    at org.apache.livy.rsc.driver.RSCDriver.run(RSCDriver.java:333)
    at org.apache.livy.rsc.driver.RSCDriverBootstrapper.main(RSCDriverBootstrapper.java:93)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.spark.deploy.yarn.ApplicationMaster$$anon$2.run(ApplicationMaster.scala:684)
Caused by: java.lang.ClassNotFoundException: scala.Function0$class
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 13 more
)

用于提交Spark作业的java代码:

URI uri = new URI("http", "username:password" , "host" , 8998, "", null, null);

Map<String,String> config = new HashMap<>();
config.put("spark.app.name","livy-poc");
config.put("livy.client.http.connection.timeout", "180s");
config.put("spark.driver.memory", "1g");

LivyClient client = new LivyClientBuilder(true).setURI(uri).setAll(config).build();

try {
    client.addJar(new URI("/path_to_jars/spark-core_2.12-2.4.2.jar")).get();
    client.addJar(new URI("/path_to_jars/scala-library-2.12.8.jar")).get();
    client.addJar(new URI("/path_to_jars/ThisJavaCode.jar")).get();

    System.out.printf("Running PiJob with %d samples...\n", 2);
    double pi = client.submit(new PiJob(2)).get();
    System.out.println("Pi is roughly: " + pi);
} catch (InterruptedException | ExecutionException e) {
    e.printStackTrace();
} finally {
    client.stop(true);
}
}

livy.conf文件具有:

# What spark master Livy sessions should use.
livy.spark.master = yarn
# What spark deploy mode Livy sessions should use.
livy.spark.deployMode = cluster

如果我错过了任何东西,可以说几点吗?

1 个答案:

答案 0 :(得分:1)

Livy似乎仅支持针对Scala 2.11.x构建的Spark版本。参见https://issues.apache.org/jira/browse/LIVY-423

更改client.addJar(...行,以包含Scala 2.11版本和针对2.11构建的Spark发行版。