Skip to content

Commit 628719f

Browse files
xifengyaooqinn
authored andcommitted
[KYUUBI #1477] Use KyuubiHadoopUtils.newHadoopConf instead of new Con…
…figuration() <!-- 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?_ - [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 - EventLoggingServiceSuite ![image](https://user-images.githubusercontent.com/12961802/147745991-fcb14907-4d3a-4bce-a492-1b111b6e1614.png) - HadoopFsDelegationTokenProviderSuite ![image](https://user-images.githubusercontent.com/12961802/147746114-2d2037d7-fe72-4e85-8db5-7b3244136c5b.png) - KyuubiHadoopUtilsSuite ![image](https://user-images.githubusercontent.com/12961802/147746199-40e0ca91-9f48-4395-941b-a08affb6fbd9.png) - [x] [Run test](https://kyuubi.readthedocs.io/en/latest/develop_tools/testing.html#running-tests) locally before make a pull request Closes #1661 from xifeng/kyuubi-1477. Closes #1477 ad068c6 [xifeng yang] [KYUUBI #1477] Use KyuubiHadoopUtils.newHadoopConf instead of new Configuration() Authored-by: xifeng yang <xifeng.yang@hotmail.com> Signed-off-by: Kent Yao <yao@apache.org>
1 parent 2f1f258 commit 628719f

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

kyuubi-common/src/main/scala/org/apache/kyuubi/util/KyuubiHadoopUtils.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,12 @@ object KyuubiHadoopUtils {
4141
classOf[Credentials].getDeclaredField("tokenMap")
4242
tokenMapField.setAccessible(true)
4343

44-
def newHadoopConf(conf: KyuubiConf): Configuration = {
45-
val hadoopConf = new Configuration()
46-
conf.getAll.foreach { case (k, v) => hadoopConf.set(k, v) }
44+
def newHadoopConf(
45+
conf: KyuubiConf,
46+
loadDefaults: Boolean = true): Configuration = {
47+
val hadoopConf = new Configuration(loadDefaults)
48+
conf.getAll
49+
.foreach { case (k, v) => hadoopConf.set(k, v) }
4750
hadoopConf
4851
}
4952

kyuubi-common/src/test/scala/org/apache/kyuubi/util/KyuubiHadoopUtilsSuite.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
package org.apache.kyuubi.util
1919

20+
import java.util.stream.StreamSupport
21+
2022
import scala.util.Random
2123

2224
import org.apache.hadoop.io.Text
@@ -59,4 +61,18 @@ class KyuubiHadoopUtilsSuite extends KyuubiFunSuite {
5961
KyuubiHadoopUtils.encodeCredentials(credentials))
6062
assert(decoded.getToken(token.getKind) == credentials.getToken(token.getKind))
6163
}
64+
65+
test("new hadoop conf with kyuubi conf with loadDefaults") {
66+
val abc = "kyuubi.abc"
67+
val kyuubiConf = new KyuubiConf()
68+
.set(abc, "xyz")
69+
70+
var hadoopConf = KyuubiHadoopUtils.newHadoopConf(kyuubiConf)
71+
assert(StreamSupport.stream(hadoopConf.spliterator(), false)
72+
.anyMatch(entry => entry.getKey.startsWith("hadoop") || entry.getKey.startsWith("fs")))
73+
74+
hadoopConf = KyuubiHadoopUtils.newHadoopConf(kyuubiConf, loadDefaults = false)
75+
assert(StreamSupport.stream(hadoopConf.spliterator(), false)
76+
.noneMatch(entry => entry.getKey.startsWith("hadoop") || entry.getKey.startsWith("fs")))
77+
}
6278
}

kyuubi-server/src/main/scala/org/apache/kyuubi/credentials/HadoopFsDelegationTokenProvider.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import org.apache.hadoop.security.UserGroupInformation.AuthenticationMethod
3131
import org.apache.kyuubi.Logging
3232
import org.apache.kyuubi.config.KyuubiConf
3333
import org.apache.kyuubi.credentials.HadoopFsDelegationTokenProvider.{disableFsCache, doAsProxyUser}
34+
import org.apache.kyuubi.util.KyuubiHadoopUtils
3435

3536
class HadoopFsDelegationTokenProvider extends HadoopDelegationTokenProvider with Logging {
3637

@@ -80,7 +81,10 @@ object HadoopFsDelegationTokenProvider {
8081

8182
def disableFsCache(kyuubiConf: KyuubiConf, hadoopConf: Configuration): Configuration = {
8283
// Avoid unnecessary disk io by not loading default resources
83-
val newConf = new Configuration(false)
84+
val newConf = KyuubiHadoopUtils.newHadoopConf(
85+
kyuubiConf,
86+
loadDefaults = false)
87+
8488
hadoopConf.iterator().asScala.foreach(e => newConf.set(e.getKey, e.getValue))
8589

8690
hadoopFSsToAccess(kyuubiConf, hadoopConf)

kyuubi-server/src/main/scala/org/apache/kyuubi/server/EventLoggingService.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ package org.apache.kyuubi.server
1919

2020
import java.net.InetAddress
2121

22-
import org.apache.hadoop.conf.Configuration
23-
2422
import org.apache.kyuubi.config.KyuubiConf
2523
import org.apache.kyuubi.config.KyuubiConf.SERVER_EVENT_JSON_LOG_PATH
2624
import org.apache.kyuubi.config.KyuubiConf.SERVER_EVENT_LOGGERS
@@ -33,6 +31,7 @@ import org.apache.kyuubi.util.KyuubiHadoopUtils
3331
class EventLoggingService extends AbstractEventLoggingService[KyuubiServerEvent] {
3432

3533
override def initialize(conf: KyuubiConf): Unit = {
34+
val hadoopConf = KyuubiHadoopUtils.newHadoopConf(conf)
3635
conf.get(SERVER_EVENT_LOGGERS)
3736
.map(EventLoggerType.withName)
3837
.foreach {
@@ -41,9 +40,9 @@ class EventLoggingService extends AbstractEventLoggingService[KyuubiServerEvent]
4140
val jsonEventLogger = new JsonEventLogger[KyuubiServerEvent](
4241
s"server-$hostName",
4342
SERVER_EVENT_JSON_LOG_PATH,
44-
new Configuration())
43+
hadoopConf)
4544
// TODO: #1180 kyuubiServerEvent need create logRoot automatically
46-
jsonEventLogger.createEventLogRootDir(conf, KyuubiHadoopUtils.newHadoopConf(conf))
45+
jsonEventLogger.createEventLogRootDir(conf, hadoopConf)
4746
addService(jsonEventLogger)
4847
addEventLogger(jsonEventLogger)
4948
case logger =>

0 commit comments

Comments
 (0)