Repository: spark
Updated Branches:
  refs/heads/master 607f50341 -> e4d439c83


[SPARK-14729][SCHEDULER] Refactored YARN scheduler creation code to use newly 
added ExternalClusterManager

## What changes were proposed in this pull request?
With the addition of ExternalClusterManager(ECM) interface in PR #11723, any 
cluster manager can now be integrated with Spark. It was suggested in  
ExternalClusterManager PR that one of the existing cluster managers should 
start using the new interface to ensure that the API is correct. Ideally, all 
the existing cluster managers should eventually use the ECM interface but as a 
first step yarn will now use the ECM interface. This PR refactors YARN code 
from SparkContext.createTaskScheduler function  into YarnClusterManager that 
implements ECM interface.

## How was this patch tested?
Since this is refactoring, no new tests has been added. Existing tests have 
been run. Basic manual testing with YARN was done too.

Author: Hemant Bhanawat <[email protected]>

Closes #12641 from hbhanawat/yarnClusterMgr.


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

Branch: refs/heads/master
Commit: e4d439c831a7fe3dbfeff6ce029c3ce1f9420ab8
Parents: 607f503
Author: Hemant Bhanawat <[email protected]>
Authored: Wed Apr 27 10:59:23 2016 -0700
Committer: Marcelo Vanzin <[email protected]>
Committed: Wed Apr 27 10:59:23 2016 -0700

----------------------------------------------------------------------
 .../scala/org/apache/spark/SparkContext.scala   | 48 +----------------
 .../SparkContextSchedulerCreationSuite.scala    | 20 -------
 ...pache.spark.scheduler.ExternalClusterManager |  1 +
 .../scheduler/cluster/YarnClusterManager.scala  | 56 ++++++++++++++++++++
 4 files changed, 58 insertions(+), 67 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/e4d439c8/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 e7eabd2..f322a77 100644
--- a/core/src/main/scala/org/apache/spark/SparkContext.scala
+++ b/core/src/main/scala/org/apache/spark/SparkContext.scala
@@ -2389,53 +2389,6 @@ object SparkContext extends Logging {
         }
         (backend, scheduler)
 
-      case "yarn" if deployMode == "cluster" =>
-        val scheduler = try {
-          val clazz = 
Utils.classForName("org.apache.spark.scheduler.cluster.YarnClusterScheduler")
-          val cons = clazz.getConstructor(classOf[SparkContext])
-          cons.newInstance(sc).asInstanceOf[TaskSchedulerImpl]
-        } catch {
-          // TODO: Enumerate the exact reasons why it can fail
-          // But irrespective of it, it means we cannot proceed !
-          case e: Exception =>
-            throw new SparkException("YARN mode not available ?", e)
-        }
-        val backend = try {
-          val clazz =
-            
Utils.classForName("org.apache.spark.scheduler.cluster.YarnClusterSchedulerBackend")
-          val cons = clazz.getConstructor(classOf[TaskSchedulerImpl], 
classOf[SparkContext])
-          cons.newInstance(scheduler, 
sc).asInstanceOf[CoarseGrainedSchedulerBackend]
-        } catch {
-          case e: Exception =>
-            throw new SparkException("YARN mode not available ?", e)
-        }
-        scheduler.initialize(backend)
-        (backend, scheduler)
-
-      case "yarn" if deployMode == "client" =>
-        val scheduler = try {
-          val clazz = 
Utils.classForName("org.apache.spark.scheduler.cluster.YarnScheduler")
-          val cons = clazz.getConstructor(classOf[SparkContext])
-          cons.newInstance(sc).asInstanceOf[TaskSchedulerImpl]
-
-        } catch {
-          case e: Exception =>
-            throw new SparkException("YARN mode not available ?", e)
-        }
-
-        val backend = try {
-          val clazz =
-            
Utils.classForName("org.apache.spark.scheduler.cluster.YarnClientSchedulerBackend")
-          val cons = clazz.getConstructor(classOf[TaskSchedulerImpl], 
classOf[SparkContext])
-          cons.newInstance(scheduler, 
sc).asInstanceOf[CoarseGrainedSchedulerBackend]
-        } catch {
-          case e: Exception =>
-            throw new SparkException("YARN mode not available ?", e)
-        }
-
-        scheduler.initialize(backend)
-        (backend, scheduler)
-
       case MESOS_REGEX(mesosUrl) =>
         MesosNativeLibrary.load()
         val scheduler = new TaskSchedulerImpl(sc)
@@ -2464,6 +2417,7 @@ object SparkContext extends Logging {
           cm.initialize(scheduler, backend)
           (backend, scheduler)
         } catch {
+          case se: SparkException => throw se
           case NonFatal(e) =>
             throw new SparkException("External scheduler cannot be 
instantiated", e)
         }

http://git-wip-us.apache.org/repos/asf/spark/blob/e4d439c8/core/src/test/scala/org/apache/spark/SparkContextSchedulerCreationSuite.scala
----------------------------------------------------------------------
diff --git 
a/core/src/test/scala/org/apache/spark/SparkContextSchedulerCreationSuite.scala 
b/core/src/test/scala/org/apache/spark/SparkContextSchedulerCreationSuite.scala
index 49c2bf6..213d70f 100644
--- 
a/core/src/test/scala/org/apache/spark/SparkContextSchedulerCreationSuite.scala
+++ 
b/core/src/test/scala/org/apache/spark/SparkContextSchedulerCreationSuite.scala
@@ -129,26 +129,6 @@ class SparkContextSchedulerCreationSuite
     }
   }
 
-  def testYarn(master: String, deployMode: String, expectedClassName: String) {
-    try {
-      val sched = createTaskScheduler(master, deployMode)
-      assert(sched.getClass === Utils.classForName(expectedClassName))
-    } catch {
-      case e: SparkException =>
-        assert(e.getMessage.contains("YARN mode not available"))
-        logWarning("YARN not available, could not test actual YARN scheduler 
creation")
-      case e: Throwable => fail(e)
-    }
-  }
-
-  test("yarn-cluster") {
-    testYarn("yarn", "cluster", 
"org.apache.spark.scheduler.cluster.YarnClusterScheduler")
-  }
-
-  test("yarn-client") {
-    testYarn("yarn", "client", 
"org.apache.spark.scheduler.cluster.YarnScheduler")
-  }
-
   def testMesos(master: String, expectedClass: Class[_], coarse: Boolean) {
     val conf = new SparkConf().set("spark.mesos.coarse", coarse.toString)
     try {

http://git-wip-us.apache.org/repos/asf/spark/blob/e4d439c8/yarn/src/main/resources/META-INF/services/org.apache.spark.scheduler.ExternalClusterManager
----------------------------------------------------------------------
diff --git 
a/yarn/src/main/resources/META-INF/services/org.apache.spark.scheduler.ExternalClusterManager
 
b/yarn/src/main/resources/META-INF/services/org.apache.spark.scheduler.ExternalClusterManager
new file mode 100644
index 0000000..6e8a1eb
--- /dev/null
+++ 
b/yarn/src/main/resources/META-INF/services/org.apache.spark.scheduler.ExternalClusterManager
@@ -0,0 +1 @@
+org.apache.spark.scheduler.cluster.YarnClusterManager

http://git-wip-us.apache.org/repos/asf/spark/blob/e4d439c8/yarn/src/main/scala/org/apache/spark/scheduler/cluster/YarnClusterManager.scala
----------------------------------------------------------------------
diff --git 
a/yarn/src/main/scala/org/apache/spark/scheduler/cluster/YarnClusterManager.scala
 
b/yarn/src/main/scala/org/apache/spark/scheduler/cluster/YarnClusterManager.scala
new file mode 100644
index 0000000..64cd1bd
--- /dev/null
+++ 
b/yarn/src/main/scala/org/apache/spark/scheduler/cluster/YarnClusterManager.scala
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.scheduler.cluster
+
+import org.apache.spark.{SparkContext, SparkException}
+import org.apache.spark.scheduler.{ExternalClusterManager, SchedulerBackend, 
TaskScheduler, TaskSchedulerImpl}
+
+/**
+ * Cluster Manager for creation of Yarn scheduler and backend
+ */
+private[spark] class YarnClusterManager extends ExternalClusterManager {
+
+  override def canCreate(masterURL: String): Boolean = {
+    masterURL == "yarn"
+  }
+
+  override def createTaskScheduler(sc: SparkContext, masterURL: String): 
TaskScheduler = {
+    sc.deployMode match {
+      case "cluster" => new YarnClusterScheduler(sc)
+      case "client" => new YarnScheduler(sc)
+      case _ => throw new SparkException(s"Unknown deploy mode 
'${sc.deployMode}' for Yarn")
+    }
+  }
+
+  override def createSchedulerBackend(sc: SparkContext,
+      masterURL: String,
+      scheduler: TaskScheduler): SchedulerBackend = {
+    sc.deployMode match {
+      case "cluster" =>
+        new 
YarnClusterSchedulerBackend(scheduler.asInstanceOf[TaskSchedulerImpl], sc)
+      case "client" =>
+        new 
YarnClientSchedulerBackend(scheduler.asInstanceOf[TaskSchedulerImpl], sc)
+      case  _ =>
+        throw new SparkException(s"Unknown deploy mode '${sc.deployMode}' for 
Yarn")
+    }
+  }
+
+  override def initialize(scheduler: TaskScheduler, backend: 
SchedulerBackend): Unit = {
+    scheduler.asInstanceOf[TaskSchedulerImpl].initialize(backend)
+  }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to