Skip to content

Commit d2a40ad

Browse files
committed
SPARK-1652: Spark submit should fail gracefully if YARN support not enabled
1 parent 71f4d26 commit d2a40ad

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

core/src/main/scala/org/apache/spark/deploy/SparkSubmit.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import java.net.{URI, URL}
2323
import scala.collection.mutable.{ArrayBuffer, HashMap, Map}
2424

2525
import org.apache.spark.executor.ExecutorURLClassLoader
26+
import org.apache.spark.util.Utils
2627

2728
/**
2829
* Scala code behind the spark-submit script. The script handles setting up the classpath with
@@ -128,6 +129,15 @@ object SparkSubmit {
128129
childArgs += ("--class", appArgs.mainClass)
129130
}
130131

132+
if (clusterManager == YARN) {
133+
// The choice of class is arbitrary, could use any spark-yarn class
134+
if (!Utils.classIsLoadable("org.apache.spark.deploy.yarn.Client") || !Utils.isTesting) {
135+
val msg = "Could not load YARN classes. This copy of Spark may not have been compiled " +
136+
"with YARN support."
137+
throw new Exception(msg)
138+
}
139+
}
140+
131141
val options = List[OptionAssigner](
132142
new OptionAssigner(appArgs.master, ALL_CLUSTER_MGRS, false, sysProp = "spark.master"),
133143
new OptionAssigner(appArgs.driverExtraClassPath, STANDALONE | YARN, true,

core/src/main/scala/org/apache/spark/util/Utils.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import scala.collection.Map
2828
import scala.collection.mutable.ArrayBuffer
2929
import scala.io.Source
3030
import scala.reflect.ClassTag
31+
import scala.util.Try
3132

3233
import com.google.common.io.Files
3334
import org.apache.commons.lang.SystemUtils
@@ -137,6 +138,11 @@ private[spark] object Utils extends Logging {
137138
def getContextOrSparkClassLoader =
138139
Option(Thread.currentThread().getContextClassLoader).getOrElse(getSparkClassLoader)
139140

141+
/** Determines whether the provided class is loadable in the current thread. */
142+
def classIsLoadable(clazz: String): Boolean = {
143+
Try { Class.forName(clazz, false, getContextOrSparkClassLoader) }.isSuccess
144+
}
145+
140146
/**
141147
* Primitive often used when writing {@link java.nio.ByteBuffer} to {@link java.io.DataOutput}.
142148
*/

0 commit comments

Comments
 (0)