Skip to content

Commit e032a62

Browse files
yanghuayaooqinn
authored andcommitted
[KYUUBI #1757] Extract workingDir from engine specific process builde…
…r into ProcBuilder <!-- Thanks for sending a pull request! Here are some tips for you: 1. If this is your first time, please read our contributor guidelines: https://kyuubi.readthedocs.io/en/latest/community/contributions.html 2. If the PR is related to an issue in https://github.com/apache/incubator-kyuubi/issues, add '[KYUUBI #XXXX]' in your PR title, e.g., '[KYUUBI #XXXX] Your PR title ...'. 3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][KYUUBI #XXXX] Your PR title ...'. --> ### _Why are the changes needed?_ <!-- Please clarify why the changes are needed. For instance, 1. If you add a feature, you can talk about the use case of it. 2. If you fix a bug, you can clarify why it is a bug. --> ### _How was this patch tested?_ - [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible - [ ] Add screenshots for manual tests if appropriate - [ ] [Run test](https://kyuubi.readthedocs.io/en/latest/develop_tools/testing.html#running-tests) locally before make a pull request Closes #1758 from yanghua/KYUUBI-1757. Closes #1757 14d3673 [yanghua] Fix CI issue d669691 [yanghua] [KYUUBI #1757] Extract workingDir from engine specific process builder into ProcBuilder Authored-by: yanghua <yanghua1127@gmail.com> Signed-off-by: Kent Yao <yao@apache.org>
1 parent 1155603 commit e032a62

File tree

3 files changed

+29
-57
lines changed

3 files changed

+29
-57
lines changed

kyuubi-server/src/main/scala/org/apache/kyuubi/engine/ProcBuilder.scala

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ package org.apache.kyuubi.engine
2020
import java.io.{File, IOException}
2121
import java.lang.ProcessBuilder.Redirect
2222
import java.nio.charset.StandardCharsets
23-
import java.nio.file.{Files, Path}
23+
import java.nio.file.{Files, Path, Paths}
2424

2525
import scala.collection.JavaConverters._
2626
import scala.util.matching.Regex
2727

2828
import com.google.common.collect.EvictingQueue
2929
import org.apache.commons.lang3.StringUtils.containsIgnoreCase
3030

31-
import org.apache.kyuubi.{KyuubiSQLException, Logging}
31+
import org.apache.kyuubi.{KyuubiSQLException, Logging, Utils}
3232
import org.apache.kyuubi.config.KyuubiConf
3333
import org.apache.kyuubi.operation.log.OperationLog
3434
import org.apache.kyuubi.util.NamedThreadFactory
@@ -57,7 +57,31 @@ trait ProcBuilder {
5757

5858
protected val extraEngineLog: Option[OperationLog]
5959

60-
protected val workingDir: Path
60+
protected val workingDir: Path = {
61+
env.get("KYUUBI_WORK_DIR_ROOT").map { root =>
62+
val workingRoot = Paths.get(root).toAbsolutePath
63+
if (!Files.exists(workingRoot)) {
64+
debug(s"Creating KYUUBI_WORK_DIR_ROOT at $workingRoot")
65+
Files.createDirectories(workingRoot)
66+
}
67+
if (Files.isDirectory(workingRoot)) {
68+
workingRoot.toString
69+
} else null
70+
}.map { rootAbs =>
71+
val working = Paths.get(rootAbs, proxyUser)
72+
if (!Files.exists(working)) {
73+
debug(s"Creating $proxyUser's working directory at $working")
74+
Files.createDirectories(working)
75+
}
76+
if (Files.isDirectory(working)) {
77+
working
78+
} else {
79+
Utils.createTempDir(rootAbs, proxyUser)
80+
}
81+
}.getOrElse {
82+
Utils.createTempDir(namePrefix = proxyUser)
83+
}
84+
}
6185

6286
final lazy val processBuilder: ProcessBuilder = {
6387
val pb = new ProcessBuilder(commands: _*)

kyuubi-server/src/main/scala/org/apache/kyuubi/engine/flink/FlinkProcessBuilder.scala

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package org.apache.kyuubi.engine.flink
1919

2020
import java.io.{File, FilenameFilter}
2121
import java.net.URI
22-
import java.nio.file.{Files, Path, Paths}
22+
import java.nio.file.{Files, Paths}
2323

2424
import com.google.common.annotations.VisibleForTesting
2525

@@ -99,32 +99,6 @@ class FlinkProcessBuilder(
9999

100100
override protected def commands: Array[String] = Array(executable)
101101

102-
override protected val workingDir: Path = {
103-
env.get("KYUUBI_WORK_DIR_ROOT").map { root =>
104-
val workingRoot = Paths.get(root).toAbsolutePath
105-
if (!Files.exists(workingRoot)) {
106-
debug(s"Creating KYUUBI_WORK_DIR_ROOT at $workingRoot")
107-
Files.createDirectories(workingRoot)
108-
}
109-
if (Files.isDirectory(workingRoot)) {
110-
workingRoot.toString
111-
} else null
112-
}.map { rootAbs =>
113-
val working = Paths.get(rootAbs, proxyUser)
114-
if (!Files.exists(working)) {
115-
debug(s"Creating $proxyUser's working directory at $working")
116-
Files.createDirectories(working)
117-
}
118-
if (Files.isDirectory(working)) {
119-
working
120-
} else {
121-
Utils.createTempDir(rootAbs, proxyUser)
122-
}
123-
}.getOrElse {
124-
Utils.createTempDir(namePrefix = proxyUser)
125-
}
126-
}
127-
128102
override def toString: String = commands.map {
129103
case arg if arg.startsWith("--") => s"\\\n\t$arg"
130104
case arg => arg

kyuubi-server/src/main/scala/org/apache/kyuubi/engine/spark/SparkProcessBuilder.scala

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package org.apache.kyuubi.engine.spark
1919

2020
import java.io.{File, FilenameFilter, IOException}
2121
import java.net.URI
22-
import java.nio.file.{Files, Path, Paths}
22+
import java.nio.file.{Files, Paths}
2323

2424
import scala.collection.mutable.ArrayBuffer
2525

@@ -98,32 +98,6 @@ class SparkProcessBuilder(
9898
}
9999
}
100100

101-
override protected val workingDir: Path = {
102-
env.get("KYUUBI_WORK_DIR_ROOT").map { root =>
103-
val workingRoot = Paths.get(root).toAbsolutePath
104-
if (!Files.exists(workingRoot)) {
105-
debug(s"Creating KYUUBI_WORK_DIR_ROOT at $workingRoot")
106-
Files.createDirectories(workingRoot)
107-
}
108-
if (Files.isDirectory(workingRoot)) {
109-
workingRoot.toString
110-
} else null
111-
}.map { rootAbs =>
112-
val working = Paths.get(rootAbs, proxyUser)
113-
if (!Files.exists(working)) {
114-
debug(s"Creating $proxyUser's working directory at $working")
115-
Files.createDirectories(working)
116-
}
117-
if (Files.isDirectory(working)) {
118-
working
119-
} else {
120-
Utils.createTempDir(rootAbs, proxyUser)
121-
}
122-
}.getOrElse {
123-
Utils.createTempDir(namePrefix = proxyUser)
124-
}
125-
}
126-
127101
override protected def commands: Array[String] = {
128102
val buffer = new ArrayBuffer[String]()
129103
buffer += executable

0 commit comments

Comments
 (0)