tgravescs commented on a change in pull request #24406: [SPARK-27024] Executor 
interface for cluster managers to support GPU and other resources
URL: https://github.com/apache/spark/pull/24406#discussion_r280846743
 
 

 ##########
 File path: 
core/src/main/scala/org/apache/spark/executor/CoarseGrainedExecutorBackend.scala
 ##########
 @@ -71,6 +82,46 @@ private[spark] class CoarseGrainedExecutorBackend(
     }(ThreadUtils.sameThread)
   }
 
+  // visible for testing
+  def parseResources(resourcesFile: Option[String]): Map[String, 
ResourceInformation] = {
+    // only parse the resources if a task requires them
+    val taskConfPrefix = SPARK_TASK_RESOURCE_PREFIX
+    val resourceInfo = if (env.conf.getAllWithPrefix(taskConfPrefix).nonEmpty) 
{
+      val resources = resourcesFile.map { resourceFileStr => {
+        val source = new BufferedInputStream(new 
FileInputStream(resourceFileStr))
+        val resourceMap = try {
+          val parsedJson = parse(source).asInstanceOf[JArray].arr
+          parsedJson.map(_.extract[ResourceInformation]).map(x => (x.name -> 
x)).toMap
+        } catch {
+          case e @ (_: MappingException | _: MismatchedInputException | _: 
ClassCastException) =>
+            throw new SparkException(
+              s"Exception parsing the resources passed in: $resourcesFile", e)
+        } finally {
+          source.close()
+        }
+        resourceMap
+      }}.getOrElse(ResourceDiscoverer.findResources(env.conf, false))
+
+      if (resources.isEmpty) {
+        throw new SparkException(s"User specified resources per task via: 
$taskConfPrefix," +
+          s" but can't find any resources available on the executor.")
+      }
 
 Review comment:
   Yeah, I guess we could add a check here, I left it off thinking eventually 
we want to allow this and figured the scheduler would check but for now it 
probably makes sense to fail early here, I'll add checks to make sure resources 
there and they are large enough

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

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

Reply via email to