dongjoon-hyun commented on a change in pull request #27367: [SPARK-30638][CORE]
Add resources allocated to PluginContext
URL: https://github.com/apache/spark/pull/27367#discussion_r373313652
##########
File path:
core/src/test/scala/org/apache/spark/internal/plugin/PluginContainerSuite.scala
##########
@@ -140,34 +147,124 @@ class PluginContainerSuite extends SparkFunSuite with
BeforeAndAfterEach with Lo
assert(children.length >= 3)
}
}
+
+ test("plugin initialization in non-local mode with resources") {
+ withTempDir { dir =>
+ val scriptPath = createTempScriptWithExpectedOutput(dir,
"gpuDiscoveryScript",
+ """{"name": "gpu","addresses":["5", "6"]}""")
+
+ val workerScript = createTempScriptWithExpectedOutput(dir,
"resourceDiscoveryScript",
+ """{"name": "gpu","addresses":["3", "4"]}""")
+
+ val conf = new SparkConf()
+ .setAppName(getClass().getName())
+ .set(SparkLauncher.SPARK_MASTER, "local-cluster[1,1,1024]")
+ .set(PLUGINS, Seq(classOf[NonLocalModeSparkPlugin].getName()))
+ .set(NonLocalModeSparkPlugin.TEST_PATH_CONF, dir.getAbsolutePath())
+ .set(DRIVER_GPU_ID.amountConf, "2")
+ .set(DRIVER_GPU_ID.discoveryScriptConf, scriptPath)
+ .set(WORKER_GPU_ID.amountConf, "2")
+ .set(WORKER_GPU_ID.discoveryScriptConf, workerScript)
+ .set(EXECUTOR_GPU_ID.amountConf, "2")
+ sc = new SparkContext(conf)
+
+ // Ensure all executors has started
+ TestUtils.waitUntilExecutorsUp(sc, 1, 10000)
+
+ var children = Array.empty[File]
+ eventually(timeout(10.seconds), interval(100.millis)) {
+ children = dir.listFiles()
+ assert(children != null)
+ // we have 2 discovery scripts and then expect 1 driver and 1 executor
file
+ assert(children.length >= 4)
+ }
+ val execFiles =
+
children.filter(_.getName.startsWith(NonLocalModeSparkPlugin.executorFileStr))
+ assert(execFiles.size === 1)
+ val allLines = Files.readLines(execFiles(0), StandardCharsets.US_ASCII)
+ assert(allLines.size === 1)
+ val addrs = NonLocalModeSparkPlugin.extractGpuAddrs(allLines.get(0))
+ assert(addrs.size === 2)
+ assert(addrs.sorted === Array("3", "4"))
+
+ assert(NonLocalModeSparkPlugin.driverContext != null)
+ val driverResources = NonLocalModeSparkPlugin.driverContext.resources()
+ assert(driverResources.size === 1)
+ assert(driverResources.get(GPU).addresses === Array("5", "6"))
+ assert(driverResources.get(GPU).name === GPU)
+ }
+ }
}
class NonLocalModeSparkPlugin extends SparkPlugin {
override def driverPlugin(): DriverPlugin = {
new DriverPlugin() {
override def init(sc: SparkContext, ctx: PluginContext): JMap[String,
String] = {
- NonLocalModeSparkPlugin.writeFile(ctx.conf(), ctx.executorID())
- Map.empty.asJava
+
NonLocalModeSparkPlugin.writeDriverFile(NonLocalModeSparkPlugin.driverFileStr,
ctx.conf(),
+ ctx.executorID())
+ NonLocalModeSparkPlugin.driverContext = ctx
+ Map.empty[String, String].asJava
}
}
}
override def executorPlugin(): ExecutorPlugin = {
new ExecutorPlugin() {
override def init(ctx: PluginContext, extraConf: JMap[String, String]):
Unit = {
- NonLocalModeSparkPlugin.writeFile(ctx.conf(), ctx.executorID())
+
NonLocalModeSparkPlugin.writeFile(NonLocalModeSparkPlugin.executorFileStr,
ctx.conf(),
+ ctx.executorID(), ctx.resources().asScala.toMap)
Review comment:
indentation?
----------------------------------------------------------------
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]