Updated Branches:
  refs/heads/master fc26e5b83 -> 8d528af82

Spark shell exits if it cannot create SparkContext

Mainly, this occurs if you provide a messed up MASTER url (one that doesn't 
match one
of our regexes). Previously, we would default to Mesos, fail, and then start 
the shell
anyway, except that any Spark command would fail.


Project: http://git-wip-us.apache.org/repos/asf/incubator-spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-spark/commit/74737264
Tree: http://git-wip-us.apache.org/repos/asf/incubator-spark/tree/74737264
Diff: http://git-wip-us.apache.org/repos/asf/incubator-spark/diff/74737264

Branch: refs/heads/master
Commit: 74737264c4a9b2a9a99bf3aa77928f6960bad78c
Parents: fc26e5b
Author: Aaron Davidson <aa...@databricks.com>
Authored: Thu Oct 17 18:51:19 2013 -0700
Committer: Aaron Davidson <aa...@databricks.com>
Committed: Thu Oct 17 18:51:19 2013 -0700

----------------------------------------------------------------------
 .../src/main/scala/org/apache/spark/SparkContext.scala | 13 ++++++-------
 .../main/scala/org/apache/spark/repl/SparkILoop.scala  |  9 ++++++++-
 2 files changed, 14 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-spark/blob/74737264/core/src/main/scala/org/apache/spark/SparkContext.scala
----------------------------------------------------------------------
diff --git a/core/src/main/scala/org/apache/spark/SparkContext.scala 
b/core/src/main/scala/org/apache/spark/SparkContext.scala
index 0aafc0a..3ed9caa 100644
--- a/core/src/main/scala/org/apache/spark/SparkContext.scala
+++ b/core/src/main/scala/org/apache/spark/SparkContext.scala
@@ -217,21 +217,20 @@ class SparkContext(
         scheduler.initialize(backend)
         scheduler
 
-      case _ =>
-        if (MESOS_REGEX.findFirstIn(master).isEmpty) {
-          logWarning("Master %s does not match expected format, parsing as 
Mesos URL".format(master))
-        }
+      case MESOS_REGEX(mesosUrl) =>
         MesosNativeLibrary.load()
         val scheduler = new ClusterScheduler(this)
         val coarseGrained = System.getProperty("spark.mesos.coarse", 
"false").toBoolean
-        val masterWithoutProtocol = master.replaceFirst("^mesos://", "")  // 
Strip initial mesos://
         val backend = if (coarseGrained) {
-          new CoarseMesosSchedulerBackend(scheduler, this, 
masterWithoutProtocol, appName)
+          new CoarseMesosSchedulerBackend(scheduler, this, mesosUrl, appName)
         } else {
-          new MesosSchedulerBackend(scheduler, this, masterWithoutProtocol, 
appName)
+          new MesosSchedulerBackend(scheduler, this, mesosUrl, appName)
         }
         scheduler.initialize(backend)
         scheduler
+
+      case _ =>
+        throw new SparkException("Could not parse Master URL: '" + master + 
"'")
     }
   }
   taskScheduler.start()

http://git-wip-us.apache.org/repos/asf/incubator-spark/blob/74737264/repl/src/main/scala/org/apache/spark/repl/SparkILoop.scala
----------------------------------------------------------------------
diff --git a/repl/src/main/scala/org/apache/spark/repl/SparkILoop.scala 
b/repl/src/main/scala/org/apache/spark/repl/SparkILoop.scala
index 36f54a2..48a8fa9 100644
--- a/repl/src/main/scala/org/apache/spark/repl/SparkILoop.scala
+++ b/repl/src/main/scala/org/apache/spark/repl/SparkILoop.scala
@@ -845,7 +845,14 @@ class SparkILoop(in0: Option[BufferedReader], val out: 
PrintWriter, val master:
     val jars = Option(System.getenv("ADD_JARS")).map(_.split(','))
                                                 .getOrElse(new 
Array[String](0))
                                                 .map(new 
java.io.File(_).getAbsolutePath)
-    sparkContext = new SparkContext(master, "Spark shell", 
System.getenv("SPARK_HOME"), jars)
+    try {
+      sparkContext = new SparkContext(master, "Spark shell", 
System.getenv("SPARK_HOME"), jars)
+    } catch {
+      case e: Exception =>
+        e.printStackTrace()
+        echo("Failed to create SparkContext, exiting...")
+        sys.exit(1)
+    }
     sparkContext
   }
 

Reply via email to