Skip to content

Commit f6a47e9

Browse files
committed
feat: refactor HDFS credential management and enhance local testing
- Replaced `hdfsUri` with `hdfsProperties` in S3 JCEKS Extension for more flexible HDFS configurations. - Introduced `hdfsConfiguration` utility method to streamline HDFS property handling. - Added JavaDNS plugin to support stable hostname resolution for local HDFS testing. - Updated TOML configuration and user guide to reflect new HDFS property handling and DataNode customization options.
1 parent d61d646 commit f6a47e9

6 files changed

Lines changed: 40 additions & 5 deletions

File tree

doc/user-guide.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,7 @@ Outputs:
11171117
=== S3 JCEKS Extension
11181118

11191119
The `s3Jceks` extension creates a Hadoop credential provider file in HDFS and stores LocalStack S3 credentials in it.
1120+
It builds its Hadoop client configuration from the active HDFS endpoint properties, including `fs.defaultFS`, `dfs.client.use.datanode.hostname`, `dfs.datanode.hostname`, and any HDFS TLS properties exposed by the test kit.
11201121

11211122
[source,toml]
11221123
----

example/spark/build.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ plugins {
88
id("buildsrc.convention.kotlin-jvm")
99
id("org.openprojectx.spark.platform") version "0.1.41"
1010
id("org.openprojectx.hadoop-native-loader") version "0.1.1"
11+
alias(libs.plugins.javaDns)
1112

1213
}
1314

@@ -112,6 +113,10 @@ tasks.withType<Test>().configureEach {
112113
)
113114
}
114115

116+
javadns {
117+
hosts.put("hdfs", "127.0.0.1")
118+
}
119+
115120
tasks.named<Test>("test") {
116121
useSparkRuntimeClasspath(clouderaSparkRuntimeClasspath, "cloudera")
117122
}

example/spark/src/test/resources/spark-bigdata-test-common.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,8 @@ schemaRegistry = true
1717
localStackS3 = true
1818
fakeGcs = true
1919

20+
[ports]
21+
hdfsDataNode = 9866
22+
2023
[containerLogs]
2124
mode = "FILE"

extensions/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ dependencies {
2424

2525
javadns {
2626
hosts.put("hdfs.test.local", "127.0.0.1")
27+
hosts.put("hdfs", "127.0.0.1")
28+
2729
}

extensions/src/main/kotlin/org/openprojectx/bigdata/test/extensions/hadoop/HadoopCredentialProviders.kt

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,25 @@ object HadoopCredentialProviders {
1616
providerPath: String,
1717
credentials: Map<String, String>,
1818
) {
19-
val conf = Configuration(false)
20-
conf.set("fs.defaultFS", hdfsUri)
19+
createHdfsJceks(
20+
hdfsProperties = mapOf("fs.defaultFS" to hdfsUri),
21+
configDir = configDir,
22+
providerPath = providerPath,
23+
credentials = credentials,
24+
)
25+
}
26+
27+
fun createHdfsJceks(
28+
hdfsProperties: Map<String, String>,
29+
configDir: String,
30+
providerPath: String,
31+
credentials: Map<String, String>,
32+
) {
33+
val conf = hdfsConfiguration(hdfsProperties)
2134
conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, providerPath)
35+
val hdfsUri = requireNotNull(hdfsProperties["fs.defaultFS"]?.takeIf { it.isNotBlank() }) {
36+
"HDFS properties must include non-blank fs.defaultFS"
37+
}
2238
FileSystem.get(URI.create(hdfsUri), conf).use { fs -> fs.mkdirs(Path(configDir)) }
2339

2440
val provider = CredentialProviderFactory.getProviders(conf).single()
@@ -32,8 +48,16 @@ object HadoopCredentialProviders {
3248
}
3349

3450
fun exists(hdfsUri: String, path: String): Boolean {
35-
val conf = Configuration(false)
36-
conf.set("fs.defaultFS", hdfsUri)
51+
val conf = hdfsConfiguration(mapOf("fs.defaultFS" to hdfsUri))
3752
return FileSystem.get(URI.create(hdfsUri), conf).use { fs -> fs.exists(Path(path)) }
3853
}
54+
55+
private fun hdfsConfiguration(properties: Map<String, String>): Configuration =
56+
Configuration(false).apply {
57+
properties.forEach { (key, value) ->
58+
if (value.isNotBlank()) {
59+
set(key, value)
60+
}
61+
}
62+
}
3963
}

extensions/src/main/kotlin/org/openprojectx/bigdata/test/extensions/hadoop/S3JceksExtension.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ data class S3JceksExtension(
2020
val s3 = context.endpoint(BigDataService.LOCALSTACK_S3)
2121
val providerPath = HadoopCredentialProviders.hdfsJceksPath(hdfsDir, fileName)
2222
HadoopCredentialProviders.createHdfsJceks(
23-
hdfsUri = hdfs.property("fs.defaultFS"),
23+
hdfsProperties = hdfs.properties,
2424
configDir = hdfsDir,
2525
providerPath = providerPath,
2626
credentials = mapOf(

0 commit comments

Comments
 (0)