2

I am trying to run Spark on Yarn.

I was running Spark 1.6.0 which was okay with Yarn (hadoop 2.7.1). Then, i upgraded to Spark 2.2.1 with the same Yarn i used and my applications are all failed because of this error:

Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/spark/network/util/ByteUnit : Unsupported major.minor version 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:803)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:442)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:64)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:354)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:348)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:347)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at org.apache.spark.internal.config.package$.<init>(package.scala:41)
    at org.apache.spark.internal.config.package$.<clinit>(package.scala)
    at org.apache.spark.deploy.yarn.ApplicationMaster.<init>(ApplicationMaster.scala:73)
    at org.apache.spark.deploy.yarn.ApplicationMaster$$anonfun$main$1.apply$mcV$sp(ApplicationMaster.scala:763)
    at org.apache.spark.deploy.SparkHadoopUtil$$anon$2.run(SparkHadoopUtil.scala:67)
    at org.apache.spark.deploy.SparkHadoopUtil$$anon$2.run(SparkHadoopUtil.scala:66)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:415)
    at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1698)
    at org.apache.spark.deploy.SparkHadoopUtil.runAsSparkUser(SparkHadoopUtil.scala:66)
    at org.apache.spark.deploy.yarn.ApplicationMaster$.main(ApplicationMaster.scala:762)
    at org.apache.spark.deploy.yarn.ExecutorLauncher$.main(ApplicationMaster.scala:785)
    at org.apache.spark.deploy.yarn.ExecutorLauncher.main(ApplicationMaster.scala)

After some research, i figured out it was due to a build that was done with an older JDK version than the one used for running. I was running Java 7, and now I installed Java 8 and java -version shows (in both master and workers) :

java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)

and javac -version :

javac 1.8.0_161

I expected the error to stop when upgraded but it didn't.

Does this error has something to do with any conf file of HADOOP_CONF_DIR? Or maybe i did something wrong when upgrading java (any environment variable or stuff like that)

Any help would be appreciated, thanks

MehdiOua
  • 169
  • 2
  • 7

3 Answers3

4

UnsupportedClassVersionError is thrown when your JDK version is lower than the .class files in your Java application.

The issue is because of Java version mismatch. If you look at the Wikipedia Java Class Reference you can see that the new version of your application requires Java 8:

  • J2SE 17 = 61
  • J2SE 16 = 60
  • J2SE 15 = 59
  • J2SE 14 = 58
  • J2SE 13 = 57
  • J2SE 12 = 56
  • J2SE 11 = 55
  • J2SE 10 = 54
  • J2SE 9 = 53
  • J2SE 8 = 52
  • J2SE 7 = 51
  • J2SE 6.0 = 50
  • J2SE 5.0 = 49
  • JDK 1.4 = 48
  • JDK 1.3 = 47
  • JDK 1.2 = 46
  • JDK 1.1 = 45

If you have Java 8 and you are still getting this error, you should change the content of your JAVA_HOME environment variable.

If you still get this error, you should take a look at this Stackoverflow question (or you could always remove all old versions of Java from your system...).

Apparently you have to add spark.executorEnv.JAVA_HOME=/usr/java/ in spark-defaults.conf. Note that you can provide it in command line with --conf.

See http://spark.apache.org/docs/latest/configuration.html#runtime-environment

Calabacin
  • 725
  • 2
  • 8
  • 19
  • I have this in my ~/.bashrc export JAVA_HOME=/usr/lib/jvm/java-8-oracle export PATH=$JAVA_HOME/bin:$PATH – MehdiOua Feb 07 '18 at 12:25
  • Updated my answer to add spark specific information. – Calabacin Feb 07 '18 at 14:29
  • bin/spark-submit --master yarn --deploy-mode cluster --conf spark.executorEnv.JAVA_HOME="/usr/lib/jvm/java-8-oracle" --py-files /home/hadoop/opentsdb_pandas-master/opentsdb_pandas.py /home/hadoop/opentsdb_pandas-master/first.py tried this one and still nothing, i'm desperate. any help ? @Calabacin – MehdiOua Feb 07 '18 at 14:34
  • At this point I would remove all other Java versions and if it still happens I would either find that java version inside Spark folder structure or I would grep all config files in Spark to find any use of a different version. – Calabacin Feb 07 '18 at 14:43
0

Most probably, you have a startup file (start.bat, start.sh, that sort of thing) that has the path to the Java installation coded into it. It could also be in a configuration file. What happens if you uninstall Java 7? If you get an error that the Java executable is not found, then there's your answer.

SeverityOne
  • 2,476
  • 12
  • 25
  • 1
    When i try to run Spark standalone it works, but when it comes to yarn it throws that error. Would it be the start-yarn.sh which uses yarn-env.sh then? – MehdiOua Feb 07 '18 at 12:27
  • Well, I don't have the startup scripts before me, but the JVM used by your server doesn't support Java 8. Startup scripts usually don't rely on the user's path, and therefore code the path to Java in either the startup file or some configuration file. I would start looking there, like in a `bin` directory. – SeverityOne Feb 07 '18 at 13:04
0

Set JAVA_HOME to the JDK1.8 path (for example /usr/java/jdk1.8.0_151) in /etc/hadoop/conf/hadoop-env.sh, restart resource manager and node manager services, then submit the spark job.

Paul Roub
  • 36,322
  • 27
  • 84
  • 93
abasar
  • 1,659
  • 1
  • 12
  • 7