Skip to content

Commit

Permalink
[KYUUBI #1509] Make KYUUBI_WORK_DIR_ROOT as the default root path.
Browse files Browse the repository at this point in the history
<!--
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.
-->

Make KYUUBI_WORK_DIR_ROOT as the default root path. For details: #1509.

### _How was this patch tested?_
- [X] Add some test cases that check the changes thoroughly including negative and positive cases if possible

- [X] Add screenshots for manual tests if appropriate

- [X] [Run test](https://kyuubi.readthedocs.io/en/latest/develop_tools/testing.html#running-tests) locally before make a pull request

Closes #1519 from wForget/KYUUBI-1509.

Closes #1509

ff078e5 [Wang Zhen] [KYUUBI-1509] Make KYUUBI_WORK_DIR_ROOT as the default root path.

Authored-by: Wang Zhen <[email protected]>
Signed-off-by: Kent Yao <[email protected]>
  • Loading branch information
wForget authored and yaooqinn committed Dec 7, 2021
1 parent 6ea83e0 commit 986d983
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package org.apache.kyuubi.engine.spark.session
import org.apache.hive.service.rpc.thrift.TProtocolVersion
import org.apache.spark.sql.SparkSession

import org.apache.kyuubi.KyuubiSQLException
import org.apache.kyuubi.{KyuubiSQLException, Utils}
import org.apache.kyuubi.config.KyuubiConf
import org.apache.kyuubi.config.KyuubiConf._
import org.apache.kyuubi.engine.ShareLevel
Expand All @@ -42,7 +42,8 @@ class SparkSQLSessionManager private (name: String, spark: SparkSession)
def this(spark: SparkSession) = this(classOf[SparkSQLSessionManager].getSimpleName, spark)

override def initialize(conf: KyuubiConf): Unit = {
_operationLogRoot = Some(conf.get(ENGINE_OPERATION_LOG_DIR_ROOT))
val absPath = Utils.getAbsolutePathFromWork(conf.get(ENGINE_OPERATION_LOG_DIR_ROOT))
_operationLogRoot = Some(absPath.toAbsolutePath.toString)
super.initialize(conf)
}

Expand Down
13 changes: 13 additions & 0 deletions kyuubi-common/src/main/scala/org/apache/kyuubi/Utils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,19 @@ object Utils extends Logging {
error)
}

def getAbsolutePathFromWork(pathStr: String, env: Map[String, String] = sys.env): Path = {
val path = Paths.get(pathStr)
if (path.isAbsolute) {
path
} else {
val workDir = env.get("KYUUBI_WORK_DIR_ROOT") match {
case Some(dir) => dir
case _ => System.getProperty("user.dir")
}
Paths.get(workDir, pathStr)
}
}

/**
* Delete a directory recursively.
*/
Expand Down
12 changes: 11 additions & 1 deletion kyuubi-common/src/test/scala/org/apache/kyuubi/UtilsSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package org.apache.kyuubi

import java.io.{File, IOException}
import java.net.InetAddress
import java.nio.file.Files
import java.nio.file.{Files, Paths}
import java.security.PrivilegedExceptionAction
import java.util.Properties

Expand Down Expand Up @@ -130,4 +130,14 @@ class UtilsSuite extends KyuubiFunSuite {
assert(Utils.findLocalInetAddress !== InetAddress.getLocalHost)
}
}

test("getAbsolutePathFromWork") {
val workDir = System.getenv("KYUUBI_WORK_DIR_ROOT")
val path1 = "path1"
assert(Utils.getAbsolutePathFromWork(path1).toAbsolutePath.toString ===
Paths.get(workDir, path1).toAbsolutePath.toString)

val path2 = "/tmp/path2"
assert(Utils.getAbsolutePathFromWork(path2).toString === path2)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import com.codahale.metrics.MetricRegistry
import com.codahale.metrics.json.MetricsModule
import com.fasterxml.jackson.databind.ObjectMapper

import org.apache.kyuubi.Utils
import org.apache.kyuubi.config.KyuubiConf
import org.apache.kyuubi.metrics.MetricsConf._
import org.apache.kyuubi.service.AbstractService
Expand All @@ -43,7 +44,7 @@ class JsonReporterService(registry: MetricRegistry)
private var reportPath: Path = _

override def initialize(conf: KyuubiConf): Unit = synchronized {
reportDir = Paths.get(conf.get(METRICS_JSON_LOCATION)).toAbsolutePath
reportDir = Utils.getAbsolutePathFromWork(conf.get(METRICS_JSON_LOCATION))
Files.createDirectories(reportDir)
reportPath = Paths.get(reportDir.toString, "report.json").toAbsolutePath
super.initialize(conf)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package org.apache.kyuubi.session
import com.codahale.metrics.MetricRegistry
import org.apache.hive.service.rpc.thrift.TProtocolVersion

import org.apache.kyuubi.KyuubiSQLException
import org.apache.kyuubi.{KyuubiSQLException, Utils}
import org.apache.kyuubi.config.KyuubiConf
import org.apache.kyuubi.config.KyuubiConf._
import org.apache.kyuubi.credentials.HadoopCredentialsManager
Expand All @@ -37,7 +37,8 @@ class KyuubiSessionManager private (name: String) extends SessionManager(name) {

override def initialize(conf: KyuubiConf): Unit = {
addService(credentialsManager)
_operationLogRoot = Some(conf.get(SERVER_OPERATION_LOG_DIR_ROOT))
val absPath = Utils.getAbsolutePathFromWork(conf.get(SERVER_OPERATION_LOG_DIR_ROOT))
_operationLogRoot = Some(absPath.toAbsolutePath.toString)
super.initialize(conf)
}

Expand Down

0 comments on commit 986d983

Please sign in to comment.