Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

[#15165] improvement(deps): Update Hadoop to 3.4.3 and move S3 access to AWS SDK v2 (#15166)

geyanggang6ef78e1d5be2
diff --git a/.github/trivy/trivyignore.yaml b/.github/trivy/trivyignore.yaml
index 7e205d1275..c3f5e9a42e 100644
--- a/.github/trivy/trivyignore.yaml
+++ b/.github/trivy/trivyignore.yaml
@@ -24,27 +24,6 @@
# added and points to the issue that tracks it. When an entry expires its finding fails the
# scan again. Renew an entry only after the finding has been re-triaged.
vulnerabilities:
- # authlib
- - id: CVE-2026-114615
- purls:
- - pkg:pypi/[email protected]
- expired_at: 2027-02-07
- statement: "Pre-existing finding, tracked in apache/gravitino#14777."
- - id: CVE-2026-114616
- purls:
- - pkg:pypi/[email protected]
- expired_at: 2027-02-07
- statement: "Pre-existing finding, tracked in apache/gravitino#14777."
- - id: CVE-2026-116672
- purls:
- - pkg:pypi/[email protected]
- expired_at: 2027-02-07
- statement: "Pre-existing finding, tracked in apache/gravitino#14777."
- - id: CVE-2026-96760
- purls:
- - pkg:pypi/[email protected]
- expired_at: 2027-02-07
- statement: "Pre-existing finding, tracked in apache/gravitino#14777."
# com.fasterxml.jackson.core/jackson-core
- id: CVE-2025-52999
purls:
@@ -177,7 +156,7 @@ vulnerabilities:
# com.google.guava/guava
- id: CVE-2026-102554
purls:
- - pkg:maven/com.google.guava/[email protected]
+ - pkg:maven/com.google.guava/[email protected]
- pkg:maven/com.google.guava/[email protected]
- pkg:maven/com.google.guava/[email protected]
- pkg:maven/com.google.guava/[email protected]
@@ -187,30 +166,12 @@ vulnerabilities:
- id: CVE-2021-22569
purls:
- pkg:maven/com.google.protobuf/[email protected]
- - pkg:maven/com.google.protobuf/[email protected]
- expired_at: 2027-02-07
- statement: "Pre-existing finding, tracked in apache/gravitino#14777."
- - id: CVE-2022-3509
- purls:
- - pkg:maven/com.google.protobuf/[email protected]
- expired_at: 2027-02-07
- statement: "Pre-existing finding, tracked in apache/gravitino#14777."
- - id: CVE-2022-3510
- purls:
- - pkg:maven/com.google.protobuf/[email protected]
expired_at: 2027-02-07
statement: "Pre-existing finding, tracked in apache/gravitino#14777."
- id: CVE-2024-7254
purls:
- pkg:maven/com.google.protobuf/[email protected]
- pkg:maven/com.google.protobuf/[email protected]
- - pkg:maven/com.google.protobuf/[email protected]
- expired_at: 2027-02-07
- statement: "Pre-existing finding, tracked in apache/gravitino#14777."
- # com.nimbusds/nimbus-jose-jwt
- - id: CVE-2023-52428
- purls:
- - pkg:maven/com.nimbusds/[email protected]
expired_at: 2027-02-07
statement: "Pre-existing finding, tracked in apache/gravitino#14777."
# com.squareup.okhttp3/okhttp
@@ -219,30 +180,6 @@ vulnerabilities:
- pkg:maven/com.squareup.okhttp3/[email protected]
expired_at: 2027-02-07
statement: "Pre-existing finding, tracked in apache/gravitino#14777."
- # commons-beanutils/commons-beanutils
- - id: CVE-2025-48734
- purls:
- - pkg:maven/commons-beanutils/[email protected]
- expired_at: 2027-02-07
- statement: "Pre-existing finding, tracked in apache/gravitino#14777."
- # commons-io/commons-io
- - id: CVE-2024-47554
- purls:
- - pkg:maven/commons-io/[email protected]
- expired_at: 2027-02-07
- statement: "Pre-existing finding, tracked in apache/gravitino#14777."
- # dnsjava/dnsjava
- - id: CVE-2024-25638
- purls:
- - pkg:maven/dnsjava/[email protected]
- expired_at: 2027-02-07
- statement: "Pre-existing finding, tracked in apache/gravitino#14777."
- # dnspython
- - id: CVE-2026-114605
- purls:
- - pkg:pypi/[email protected]
- expired_at: 2027-02-07
- statement: "Pre-existing finding, tracked in apache/gravitino#14777."
# fsspec
- id: CVE-2026-104851
purls:
@@ -263,17 +200,10 @@ vulnerabilities:
- pkg:maven/io.airlift/[email protected]
expired_at: 2027-02-07
statement: "Pre-existing finding, tracked in apache/gravitino#14777."
- # io.micrometer/micrometer-core
- - id: CVE-2026-40984
- purls:
- - pkg:maven/io.micrometer/[email protected]
- expired_at: 2027-02-07
- statement: "Pre-existing finding, tracked in apache/gravitino#14777."
# io.netty/netty-codec
- id: CVE-2026-42583
purls:
- pkg:maven/io.netty/[email protected]
- - pkg:maven/io.netty/[email protected]
expired_at: 2027-02-07
statement: "Pre-existing finding, tracked in apache/gravitino#14777."
# io.netty/netty-codec, io.netty/netty-codec-compression
@@ -281,7 +211,6 @@ vulnerabilities:
purls:
- pkg:maven/io.netty/[email protected]
- pkg:maven/io.netty/[email protected]
- - pkg:maven/io.netty/[email protected]
expired_at: 2027-02-07
statement: "Pre-existing finding, tracked in apache/gravitino#14777."
# io.netty/netty-codec-dns
@@ -294,33 +223,28 @@ vulnerabilities:
- id: CVE-2026-33870
purls:
- pkg:maven/io.netty/[email protected]
- - pkg:maven/io.netty/[email protected]
expired_at: 2027-02-07
statement: "Pre-existing finding, tracked in apache/gravitino#14777."
- id: CVE-2026-42584
purls:
- pkg:maven/io.netty/[email protected]
- - pkg:maven/io.netty/[email protected]
expired_at: 2027-02-07
statement: "Pre-existing finding, tracked in apache/gravitino#14777."
- id: CVE-2026-55831
purls:
- pkg:maven/io.netty/[email protected]
- - pkg:maven/io.netty/[email protected]
- pkg:maven/io.netty/[email protected]
expired_at: 2027-02-07
statement: "Pre-existing finding, tracked in apache/gravitino#14777."
- id: CVE-2026-55833
purls:
- pkg:maven/io.netty/[email protected]
- - pkg:maven/io.netty/[email protected]
- pkg:maven/io.netty/[email protected]
expired_at: 2027-02-07
statement: "Pre-existing finding, tracked in apache/gravitino#14777."
- id: CVE-2026-56745
purls:
- pkg:maven/io.netty/[email protected]
- - pkg:maven/io.netty/[email protected]
- pkg:maven/io.netty/[email protected]
expired_at: 2027-02-07
statement: "Pre-existing finding, tracked in apache/gravitino#14777."
@@ -328,28 +252,23 @@ vulnerabilities:
- id: CVE-2026-42587
purls:
- pkg:maven/io.netty/[email protected]
- - pkg:maven/io.netty/[email protected]
- pkg:maven/io.netty/[email protected]
- - pkg:maven/io.netty/[email protected]
expired_at: 2027-02-07
statement: "Pre-existing finding, tracked in apache/gravitino#14777."
# io.netty/netty-codec-http2
- id: CVE-2025-55163
purls:
- pkg:maven/io.netty/[email protected]
- - pkg:maven/io.netty/[email protected]
expired_at: 2027-02-07
statement: "Pre-existing finding, tracked in apache/gravitino#14777."
- id: CVE-2026-33871
purls:
- pkg:maven/io.netty/[email protected]
- - pkg:maven/io.netty/[email protected]
expired_at: 2027-02-07
statement: "Pre-existing finding, tracked in apache/gravitino#14777."
- id: CVE-2026-56819
purls:
- pkg:maven/io.netty/[email protected]
- - pkg:maven/io.netty/[email protected]
- pkg:maven/io.netty/[email protected]
expired_at: 2027-02-07
statement: "Pre-existing finding, tracked in apache/gravitino#14777."
@@ -362,28 +281,24 @@ vulnerabilities:
- id: CVE-2026-44249
purls:
- pkg:maven/io.netty/[email protected]
- - pkg:maven/io.netty/[email protected]
- pkg:maven/io.netty/[email protected]
expired_at: 2027-02-07
statement: "Pre-existing finding, tracked in apache/gravitino#14777."
- id: CVE-2026-45416
purls:
- pkg:maven/io.netty/[email protected]
- - pkg:maven/io.netty/[email protected]
- pkg:maven/io.netty/[email protected]
expired_at: 2027-02-07
statement: "Pre-existing finding, tracked in apache/gravitino#14777."
- id: CVE-2026-50010
purls:
- pkg:maven/io.netty/[email protected]
- - pkg:maven/io.netty/[email protected]
- pkg:maven/io.netty/[email protected]
expired_at: 2027-02-07
statement: "Pre-existing finding, tracked in apache/gravitino#14777."
- id: CVE-2026-75595
purls:
- pkg:maven/io.netty/[email protected]
- - pkg:maven/io.netty/[email protected]
- pkg:maven/io.netty/[email protected]
expired_at: 2027-02-07
statement: "Pre-existing finding, tracked in apache/gravitino#14777."
@@ -400,23 +315,6 @@ vulnerabilities:
- pkg:maven/io.netty/[email protected]
expired_at: 2027-02-07
statement: "Pre-existing finding, tracked in apache/gravitino#14777."
- # joserfc
- - id: CVE-2026-119283
- purls:
- - pkg:pypi/[email protected]
- expired_at: 2027-02-07
- statement: "Pre-existing finding, tracked in apache/gravitino#14777."
- # net.minidev/json-smart
- - id: CVE-2021-31684
- purls:
- - pkg:maven/net.minidev/[email protected]
- expired_at: 2027-02-07
- statement: "Pre-existing finding, tracked in apache/gravitino#14777."
- - id: CVE-2023-1370
- purls:
- - pkg:maven/net.minidev/[email protected]
- expired_at: 2027-02-07
- statement: "Pre-existing finding, tracked in apache/gravitino#14777."
# npm/axios
- id: CVE-2026-101898
purls:
@@ -677,23 +575,6 @@ vulnerabilities:
expired_at: 2027-02-07
statement: "Pre-existing finding, tracked in apache/gravitino#14777."
- # org.apache.avro/avro
- - id: CVE-2023-39410
- purls:
- - pkg:maven/org.apache.avro/[email protected]
- expired_at: 2027-02-07
- statement: "Pre-existing finding, tracked in apache/gravitino#14777."
- - id: CVE-2024-47561
- purls:
- - pkg:maven/org.apache.avro/[email protected]
- expired_at: 2027-02-07
- statement: "Pre-existing finding, tracked in apache/gravitino#14777."
- # org.apache.kerby/kerb-server
- - id: CVE-2026-57915
- purls:
- - pkg:maven/org.apache.kerby/[email protected]
- expired_at: 2027-02-07
- statement: "Pre-existing finding, tracked in apache/gravitino#14777."
# org.apache.thrift/libthrift
- id: CVE-2019-0205
purls:
@@ -720,7 +601,7 @@ vulnerabilities:
# org.eclipse.jetty/jetty-http
- id: CVE-2026-2332
purls:
- - pkg:maven/org.eclipse.jetty/[email protected]
+ - pkg:maven/org.eclipse.jetty/[email protected]
- pkg:maven/org.eclipse.jetty/[email protected]
expired_at: 2027-02-07
statement: "Pre-existing finding, tracked in apache/gravitino#14777."
@@ -769,32 +650,9 @@ vulnerabilities:
- pkg:maven/org.lz4/[email protected]
expired_at: 2027-02-07
statement: "Pre-existing finding, tracked in apache/gravitino#14777."
- # org.postgresql/postgresql
- - id: CVE-2026-42198
- purls:
- - pkg:maven/org.postgresql/[email protected]
- expired_at: 2027-02-07
- statement: "Pre-existing finding, tracked in apache/gravitino#14777."
- # org.xerial.snappy/snappy-java
- - id: CVE-2026-108106
- purls:
- - pkg:maven/org.xerial.snappy/[email protected]
- expired_at: 2027-02-07
- statement: "Pre-existing finding, tracked in apache/gravitino#14777."
- - id: CVE-2026-93451
- purls:
- - pkg:maven/org.xerial.snappy/[email protected]
- expired_at: 2027-02-07
- statement: "Pre-existing finding, tracked in apache/gravitino#14777."
# ray
- id: CVE-2026-57516
purls:
- pkg:pypi/[email protected]
expired_at: 2027-02-07
- statement: "Pre-existing finding, tracked in apache/gravitino#14777."
- # software.amazon.ion/ion-java
- - id: CVE-2024-21634
- purls:
- - pkg:maven/software.amazon.ion/[email protected]
- expired_at: 2027-02-07
- statement: "Pre-existing finding, tracked in apache/gravitino#14777."
+ statement: "Pre-existing finding, tracked in apache/gravitino#14777."
\ No newline at end of file
diff --git a/authorizations/authorization-ranger/build.gradle.kts b/authorizations/authorization-ranger/build.gradle.kts
index 7af1df3f3b..36b5ef5275 100644
--- a/authorizations/authorization-ranger/build.gradle.kts
+++ b/authorizations/authorization-ranger/build.gradle.kts
@@ -76,8 +76,8 @@ dependencies {
exclude("javax.servlet")
exclude("javax.ws.rs")
exclude("org.eclipse.jetty")
- // Ranger 2.8 depends on hadoop-client-api/runtime 3.4.x. Keep the Hadoop version shared with
- // the catalogs, which load the authorization libs in the same class loader.
+ // Ranger 2.8 is built on hadoop-client-api/runtime 3.4.2. Use the Hadoop version of the
+ // catalogs, which load the authorization libs in the same class loader.
exclude("org.apache.hadoop")
// Use the versions Gravitino ships with the server, which the isolated class loader shares.
exclude("com.fasterxml.jackson.core")
diff --git a/build.gradle.kts b/build.gradle.kts
index 6100e0813f..485d3ae749 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -45,7 +45,6 @@ import org.w3c.dom.Node
import java.io.IOException
import java.nio.ByteBuffer
import java.util.Locale
-import java.util.Properties
import java.util.zip.ZipFile
import javax.xml.parsers.DocumentBuilderFactory
@@ -312,95 +311,6 @@ class LegalFilesTransformer(
}
}
-/**
- * Removes the Apache Avro copy that hadoop-client-runtime shades under
- * org/apache/hadoop/shaded/org/apache/avro when it is older than 1.11.4.
- *
- * Hadoop 3.3.6 shades Avro 1.7.7, and a dependency constraint cannot replace classes that live inside
- * another jar. Within Hadoop the shaded Avro only backs Avro serialization (SequenceFile, MapReduce job
- * history, `hadoop fs -text`), which Gravitino does not use; the FileSystem, HDFS and Kerberos code
- * paths do not load it. Other jars pass through unchanged. Remove this transform once Hadoop is
- * upgraded to a release that shades Avro 1.11.4 or later (Hadoop 3.4.2+).
- */
-@CacheableTransform
-abstract class StripShadedAvroTransform : TransformAction<TransformParameters.None> {
- companion object {
- val STRIPPED: Attribute<Boolean> =
- Attribute.of("org.apache.gravitino.shaded-avro-stripped", Boolean::class.javaObjectType)
- const val SHADED_AVRO_PREFIX = "org/apache/hadoop/shaded/org/apache/avro/"
- const val AVRO_METADATA_PREFIX = "META-INF/maven/org.apache.avro/"
- const val AVRO_POM_PROPERTIES = "META-INF/maven/org.apache.avro/avro/pom.properties"
- private val MIN_AVRO_VERSION = listOf(1, 11, 4)
-
- /** Returns true if the dotted [version] is lower than 1.11.4. */
- fun isOutdatedAvro(version: String): Boolean {
- val parts = version.split('.', '-').map { it.toIntOrNull() ?: 0 }
- for (i in MIN_AVRO_VERSION.indices) {
- val part = parts.getOrElse(i) { 0 }
- if (part != MIN_AVRO_VERSION[i]) {
- return part < MIN_AVRO_VERSION[i]
- }
- }
- return false
- }
- }
-
- @get:InputArtifact
- @get:PathSensitive(PathSensitivity.NAME_ONLY)
- abstract val inputArtifact: Provider<FileSystemLocation>
-
- override fun transform(outputs: TransformOutputs) {
- val input = inputArtifact.get().asFile
- if (!input.isFile || !input.name.startsWith("hadoop-client-runtime-") || !input.name.endsWith(".jar")) {
- outputs.file(inputArtifact)
- return
- }
-
- val avroVersion = ZipFile(input).use { jar ->
- jar.getEntry(AVRO_POM_PROPERTIES)?.let { entry ->
- Properties().apply { jar.getInputStream(entry).use { load(it) } }.getProperty("version")
- }
- }
- if (avroVersion == null || !isOutdatedAvro(avroVersion)) {
- outputs.file(inputArtifact)
- return
- }
-
- // Keep the original file name so that the distribution layout and license reports do not change.
- val output = outputs.file(input.name)
- var removed = 0
- ZipFile(input).use { jar ->
- ZipOutputStream(output).use { out ->
- jar.entries().asSequence().forEach { source ->
- if (source.name.startsWith(SHADED_AVRO_PREFIX) || source.name.startsWith(AVRO_METADATA_PREFIX)) {
- removed++
- return@forEach
- }
- val entry = ZipEntry(source.name)
- entry.time = source.time
- out.putNextEntry(entry)
- if (!source.isDirectory) {
- jar.getInputStream(source).use { it.copyTo(out) }
- }
- out.closeEntry()
- }
- }
- }
- if (removed == 0) {
- throw GradleException("Expected shaded Avro $avroVersion entries in ${input.name}, found none")
- }
- }
-}
-
-// Projects whose runtime libraries ship hadoop-client-runtime in the distribution.
-val shadedAvroStrippedProjects = setOf(
- ":authorizations:authorization-ranger",
- ":catalogs:catalog-fileset",
- ":catalogs:catalog-lakehouse-iceberg",
- ":iceberg:iceberg-rest-server",
- ":iceberg:iceberg-rest-server-experiment"
-)
-
val snappyJavaVersion: String = libs.versions.snappy.java.get()
val scalaVersion: String = project.properties["scalaVersion"] as? String ?: extra["defaultScalaVersion"].toString()
@@ -719,30 +629,6 @@ subprojects {
// The safe log4j-1.2-api bridge from Log4j 2.x is already included in the log4j bundle.
exclude(group = "log4j", module = "log4j")
}
- // Strip the outdated Avro shaded into hadoop-client-runtime, see StripShadedAvroTransform.
- // The test classpaths use the same jar so that tests run against what the distribution ships.
- if (project.path in shadedAvroStrippedProjects) {
- dependencies {
- attributesSchema {
- attribute(StripShadedAvroTransform.STRIPPED)
- }
- artifactTypes.getByName(ArtifactTypeDefinition.JAR_TYPE) {
- attributes.attribute(StripShadedAvroTransform.STRIPPED, false)
- }
- // The source is not restricted to the "jar" artifact type: with that restriction, artifacts
- // such as hadoop-yarn-server-tests on the test classpaths had no matching variant. The
- // transform passes every artifact other than hadoop-client-runtime through unchanged.
- registerTransform(StripShadedAvroTransform::class) {
- from.attribute(StripShadedAvroTransform.STRIPPED, false)
- to.attribute(StripShadedAvroTransform.STRIPPED, true)
- }
- }
- configurations.matching { it.name == "runtimeClasspath" || it.name == "testRuntimeClasspath" }
- .configureEach {
- attributes.attribute(StripShadedAvroTransform.STRIPPED, true)
- }
- }
-
repositories {
mavenCentral()
mavenLocal()
diff --git a/bundles/aliyun-bundle/build.gradle.kts b/bundles/aliyun-bundle/build.gradle.kts
index 2a4df4042f..b9fb145675 100644
--- a/bundles/aliyun-bundle/build.gradle.kts
+++ b/bundles/aliyun-bundle/build.gradle.kts
@@ -29,6 +29,9 @@ dependencies {
implementation(libs.aliyun.credentials.sdk)
implementation(libs.commons.collections3)
+ // hadoop-aliyun 3.4 uses Commons Collections 4 (getFileStatus and deleteObjects), which
+ // hadoop-client-runtime shades for its own use only.
+ implementation(libs.commons.collections4)
implementation(libs.hadoop3.client.api)
implementation(libs.hadoop3.client.runtime)
implementation(libs.hadoop3.oss)
@@ -36,6 +39,8 @@ dependencies {
// Aliyun oss SDK depends on this package, and JDK >= 9 requires manual add
// https://www.alibabacloud.com/help/en/oss/developer-reference/java-installation?spm=a2c63.p38356.0.i1
implementation(libs.sun.activation)
+ testImplementation(libs.junit.jupiter.api)
+ testRuntimeOnly(libs.junit.jupiter.engine)
}
tasks.withType(ShadowJar::class.java) {
@@ -84,3 +89,10 @@ tasks.jar {
tasks.compileJava {
dependsOn(":catalogs:catalog-fileset:runtimeJars")
}
+
+tasks.test {
+ val bundle = tasks.named<ShadowJar>("shadowJar")
+ dependsOn(bundle)
+ inputs.file(bundle.flatMap { it.archiveFile })
+ doFirst { systemProperty("shadowJarPath", bundle.get().archiveFile.get().asFile.absolutePath) }
+}
diff --git a/bundles/aliyun-bundle/src/test/java/org/apache/gravitino/bundles/TestAliyunBundleConnectorLinkage.java b/bundles/aliyun-bundle/src/test/java/org/apache/gravitino/bundles/TestAliyunBundleConnectorLinkage.java
new file mode 100644
index 0000000000..49e09463ac
--- /dev/null
+++ b/bundles/aliyun-bundle/src/test/java/org/apache/gravitino/bundles/TestAliyunBundleConnectorLinkage.java
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.bundles;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.DataInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Checks that the OSS connector in the Aliyun bundle only links against relocated classes that the
+ * bundle contains. A relocated class can only come from the bundle itself, so a missing one fails
+ * with a {@link NoClassDefFoundError} at runtime, for example when a new Hadoop release starts to
+ * use a library that the bundle does not package.
+ */
+class TestAliyunBundleConnectorLinkage {
+ private static final File BUNDLE = new File(System.getProperty("shadowJarPath"));
+ private static final String CONNECTOR = "org/apache/hadoop/fs/aliyun/";
+ private static final String RELOCATED = "org/apache/gravitino/aliyun/shaded/";
+
+ @Test
+ void testRelocatedReferencesAreBundled() throws IOException {
+ Map<String, Set<String>> missing = new TreeMap<>();
+ try (JarFile jar = new JarFile(BUNDLE)) {
+ Set<String> bundled = new TreeSet<>();
+ jar.stream().map(JarEntry::getName).forEach(bundled::add);
+ for (JarEntry entry : (Iterable<JarEntry>) jar.stream()::iterator) {
+ String name = entry.getName();
+ if (!name.startsWith(CONNECTOR) || !name.endsWith(".class")) {
+ continue;
+ }
+ try (InputStream in = jar.getInputStream(entry)) {
+ for (String reference : referencedClasses(in)) {
+ if (reference.startsWith(RELOCATED) && !bundled.contains(reference + ".class")) {
+ missing.computeIfAbsent(reference, k -> new TreeSet<>()).add(name);
+ }
+ }
+ }
+ }
+ }
+ assertTrue(missing.isEmpty(), "Relocated classes missing from the bundle: " + missing);
+ }
+
+ /** Returns the classes in the constant pool of a class file, as internal names. */
+ private static Set<String> referencedClasses(InputStream classFile) throws IOException {
+ DataInputStream in = new DataInputStream(classFile);
+ in.readInt(); // magic
+ in.readUnsignedShort(); // minor version
+ in.readUnsignedShort(); // major version
+ int count = in.readUnsignedShort();
+ String[] utf8 = new String[count];
+ int[] classNames = new int[count];
+ for (int i = 1; i < count; i++) {
+ int tag = in.readUnsignedByte();
+ switch (tag) {
+ case 1: // Utf8
+ utf8[i] = in.readUTF();
+ break;
+ case 7: // Class
+ classNames[i] = in.readUnsignedShort();
+ break;
+ case 8: // String
+ case 16: // MethodType
+ case 19: // Module
+ case 20: // Package
+ in.readUnsignedShort();
+ break;
+ case 15: // MethodHandle
+ in.readUnsignedByte();
+ in.readUnsignedShort();
+ break;
+ case 3: // Integer
+ case 4: // Float
+ case 9: // Fieldref
+ case 10: // Methodref
+ case 11: // InterfaceMethodref
+ case 12: // NameAndType
+ case 17: // Dynamic
+ case 18: // InvokeDynamic
+ in.readInt();
+ break;
+ case 5: // Long
+ case 6: // Double
+ in.readLong();
+ i++;
+ break;
+ default:
+ throw new IOException("Unknown constant pool tag " + tag);
+ }
+ }
+ Set<String> classes = new TreeSet<>();
+ for (int index : classNames) {
+ if (index != 0) {
+ // Array classes are written as descriptors, for example [Lorg/example/Type;.
+ classes.add(utf8[index].replaceFirst("^\\[+L?", "").replaceFirst(";$", ""));
+ }
+ }
+ return classes;
+ }
+}
diff --git a/bundles/aliyun-bundle/src/test/java/org/apache/gravitino/bundles/TestAliyunBundleShadedLibraries.java b/bundles/aliyun-bundle/src/test/java/org/apache/gravitino/bundles/TestAliyunBundleShadedLibraries.java
new file mode 100644
index 0000000000..6880464fcd
--- /dev/null
+++ b/bundles/aliyun-bundle/src/test/java/org/apache/gravitino/bundles/TestAliyunBundleShadedLibraries.java
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.bundles;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.File;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Checks the libraries that hadoop-client-runtime shades into the aliyun bundle. Hadoop 3.3 shaded
+ * Avro 1.7.7 and protobuf 3.7.1, Hadoop 3.4.3 ships Avro 1.11.4 and protobuf 3.25.
+ */
+class TestAliyunBundleShadedLibraries {
+
+ private static final File BUNDLE = new File(System.getProperty("shadowJarPath"));
+
+ @Test
+ void testAvroIsNotOutdated() throws Exception {
+ for (String version : versionsOf("META-INF/maven/org.apache.avro/avro/pom.properties")) {
+ assertTrue(compare(version, "1.11.4") >= 0, "Outdated Avro " + version);
+ }
+ }
+
+ @Test
+ void testProtobufIsNotOutdated() throws Exception {
+ assertTrue(
+ versionsOf(
+ "META-INF/maven/org.apache.hadoop.thirdparty/hadoop-shaded-protobuf_3_7/pom.properties")
+ .isEmpty(),
+ "hadoop-shaded-protobuf_3_7 is outdated");
+ for (String version :
+ versionsOf("META-INF/maven/com.google.protobuf/protobuf-java/pom.properties")) {
+ assertTrue(compare(version, "3.25.0") >= 0, "Outdated protobuf " + version);
+ }
+ try (JarFile jar = new JarFile(BUNDLE)) {
+ assertFalse(
+ jar.stream()
+ .anyMatch(
+ e -> e.getName().startsWith("org/apache/hadoop/shaded/com/google/protobuf/")),
+ "Protobuf 3.7 is shaded under org/apache/hadoop/shaded");
+ }
+ }
+
+ private static List<String> versionsOf(String propertiesEntry) throws Exception {
+ List<String> versions = new ArrayList<>();
+ try (JarFile jar = new JarFile(BUNDLE)) {
+ for (JarEntry entry : (Iterable<JarEntry>) jar.stream()::iterator) {
+ if (entry.getName().equals(propertiesEntry)) {
+ Properties properties = new Properties();
+ try (InputStream in = jar.getInputStream(entry)) {
+ properties.load(in);
+ }
+ versions.add(properties.getProperty("version"));
+ }
+ }
+ }
+ return versions;
+ }
+
+ private static int compare(String version, String minimum) {
+ String[] left = version.split("[.-]");
+ String[] right = minimum.split("[.-]");
+ for (int i = 0; i < right.length; i++) {
+ int l = i < left.length ? Integer.parseInt(left[i]) : 0;
+ int r = Integer.parseInt(right[i]);
+ if (l != r) {
+ return Integer.compare(l, r);
+ }
+ }
+ return 0;
+ }
+}
diff --git a/bundles/aws-bundle/build.gradle.kts b/bundles/aws-bundle/build.gradle.kts
index 7056bea806..1fd24700cc 100644
--- a/bundles/aws-bundle/build.gradle.kts
+++ b/bundles/aws-bundle/build.gradle.kts
@@ -25,16 +25,40 @@ plugins {
alias(libs.plugins.shadow)
}
+// Keeps the Netty artifacts brought in by the AWS SDK on the single version of the catalog. The BOM
+// sits in a dedicated configuration so that it only applies to this module.
+val nettyBom: Configuration by configurations.creating {
+ isCanBeConsumed = false
+ isCanBeResolved = false
+}
+
+listOf("compileClasspath", "runtimeClasspath", "testCompileClasspath", "testRuntimeClasspath")
+ .forEach { configurations.named(it) { extendsFrom(nettyBom) } }
+
dependencies {
+ nettyBom(platform(libs.netty.bom))
+
implementation(project(":bundles:aws"))
- implementation(libs.hadoop3.aws)
+ implementation(libs.hadoop3.aws) {
+ exclude("software.amazon.awssdk", "bundle")
+ }
+ implementation(libs.bundles.hadoop.aws.sdk)
+ // S3A client-side encryption (CSE-KMS, CSE-CUSTOM). Hadoop 3.3 used the encryption client of the
+ // AWS SDK v1 bundle. Hadoop 3.4 needs the S3 encryption client, which hadoop-aws declares as
+ // provided, and the KMS module, which the single SDK modules above do not include.
+ implementation(libs.aws.kms)
+ implementation(libs.aws.s3.encryption.client)
implementation(libs.aws.iam)
implementation(libs.aws.policy)
implementation(libs.aws.sts)
+ // hadoop-aws 3.4 uses Commons Collections 4 (copyFromLocalFile), which hadoop-client-runtime
+ // shades for its own use only.
+ implementation(libs.commons.collections4)
implementation(libs.hadoop3.client.api)
implementation(libs.hadoop3.client.runtime)
testImplementation(libs.junit.jupiter.api)
+ testImplementation(libs.junit.jupiter.params)
testImplementation(libs.slf4j.api)
testRuntimeOnly(libs.junit.jupiter.engine)
}
@@ -67,6 +91,17 @@ tasks.withType(ShadowJar::class.java) {
relocate("io.netty", "org.apache.gravitino.aws.shaded.io.netty")
relocate("org.apache.commons", "org.apache.gravitino.aws.shaded.org.apache.commons")
relocate("org.apache.http", "org.apache.gravitino.aws.shaded.org.apache.http")
+ // Apache HTTP client 5, brought by the apache5-client module that the AWS SDK v2 service modules
+ // depend on.
+ relocate("org.apache.hc", "org.apache.gravitino.aws.shaded.org.apache.hc")
+ // hadoop-aws links ConfigureShadedAWSSocketFactory against the Apache HTTP client that the
+ // software.amazon.awssdk:bundle shades. The bundle is replaced by the single SDK modules, which use
+ // org.apache.http, so map the shaded name to the same relocated package to keep
+ // fs.s3a.ssl.channel.mode working.
+ relocate(
+ "software.amazon.awssdk.thirdparty.org.apache.http",
+ "org.apache.gravitino.aws.shaded.org.apache.http"
+ )
relocate("org.checkerframework", "org.apache.gravitino.aws.shaded.org.checkerframework")
relocate("org.reactivestreams", "org.apache.gravitino.aws.shaded.org.reactivestreams")
@@ -86,5 +121,6 @@ tasks.test {
val bundle = tasks.named<ShadowJar>("shadowJar")
dependsOn(bundle)
inputs.file(bundle.flatMap { it.archiveFile })
+ systemProperty("nettyVersion", libs.versions.netty.get())
doFirst { systemProperty("shadowJarPath", bundle.get().archiveFile.get().asFile.absolutePath) }
}
diff --git a/bundles/aws-bundle/src/test/java/org/apache/gravitino/bundles/TestAwsBundleConnectorLinkage.java b/bundles/aws-bundle/src/test/java/org/apache/gravitino/bundles/TestAwsBundleConnectorLinkage.java
new file mode 100644
index 0000000000..03f2e66c97
--- /dev/null
+++ b/bundles/aws-bundle/src/test/java/org/apache/gravitino/bundles/TestAwsBundleConnectorLinkage.java
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.bundles;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.DataInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Checks that the S3A connector in the AWS bundle only links against relocated classes that the
+ * bundle contains. A relocated class can only come from the bundle itself, so a missing one fails
+ * with a {@link NoClassDefFoundError} at runtime, for example when a new Hadoop release starts to
+ * use a library that the bundle does not package.
+ */
+class TestAwsBundleConnectorLinkage {
+ private static final File BUNDLE = new File(System.getProperty("shadowJarPath"));
+ private static final String CONNECTOR = "org/apache/hadoop/fs/s3a/";
+ private static final String RELOCATED = "org/apache/gravitino/aws/shaded/";
+
+ /**
+ * Connector classes that may reference relocated classes the bundle does not package, because the
+ * bundle does not support the feature: AWS role policies of S3A delegation tokens (Jackson) and
+ * the marker tool command line (Commons IO).
+ */
+ private static final Set<String> UNSUPPORTED =
+ new HashSet<>(
+ Arrays.asList(CONNECTOR + "auth/RoleModel.class", CONNECTOR + "tools/MarkerTool.class"));
+
+ @Test
+ void testRelocatedReferencesAreBundled() throws IOException {
+ Map<String, Set<String>> missing = new TreeMap<>();
+ try (JarFile jar = new JarFile(BUNDLE)) {
+ Set<String> bundled = new TreeSet<>();
+ jar.stream().map(JarEntry::getName).forEach(bundled::add);
+ for (JarEntry entry : (Iterable<JarEntry>) jar.stream()::iterator) {
+ String name = entry.getName();
+ if (!name.startsWith(CONNECTOR) || !name.endsWith(".class") || UNSUPPORTED.contains(name)) {
+ continue;
+ }
+ try (InputStream in = jar.getInputStream(entry)) {
+ for (String reference : referencedClasses(in)) {
+ if (reference.startsWith(RELOCATED) && !bundled.contains(reference + ".class")) {
+ missing.computeIfAbsent(reference, k -> new TreeSet<>()).add(name);
+ }
+ }
+ }
+ }
+ }
+ assertTrue(missing.isEmpty(), "Relocated classes missing from the bundle: " + missing);
+ }
+
+ /** Returns the classes in the constant pool of a class file, as internal names. */
+ private static Set<String> referencedClasses(InputStream classFile) throws IOException {
+ DataInputStream in = new DataInputStream(classFile);
+ in.readInt(); // magic
+ in.readUnsignedShort(); // minor version
+ in.readUnsignedShort(); // major version
+ int count = in.readUnsignedShort();
+ String[] utf8 = new String[count];
+ int[] classNames = new int[count];
+ for (int i = 1; i < count; i++) {
+ int tag = in.readUnsignedByte();
+ switch (tag) {
+ case 1: // Utf8
+ utf8[i] = in.readUTF();
+ break;
+ case 7: // Class
+ classNames[i] = in.readUnsignedShort();
+ break;
+ case 8: // String
+ case 16: // MethodType
+ case 19: // Module
+ case 20: // Package
+ in.readUnsignedShort();
+ break;
+ case 15: // MethodHandle
+ in.readUnsignedByte();
+ in.readUnsignedShort();
+ break;
+ case 3: // Integer
+ case 4: // Float
+ case 9: // Fieldref
+ case 10: // Methodref
+ case 11: // InterfaceMethodref
+ case 12: // NameAndType
+ case 17: // Dynamic
+ case 18: // InvokeDynamic
+ in.readInt();
+ break;
+ case 5: // Long
+ case 6: // Double
+ in.readLong();
+ i++;
+ break;
+ default:
+ throw new IOException("Unknown constant pool tag " + tag);
+ }
+ }
+ Set<String> classes = new TreeSet<>();
+ for (int index : classNames) {
+ if (index != 0) {
+ // Array classes are written as descriptors, for example [Lorg/example/Type;.
+ classes.add(utf8[index].replaceFirst("^\\[+L?", "").replaceFirst(";$", ""));
+ }
+ }
+ return classes;
+ }
+}
diff --git a/bundles/aws-bundle/src/test/java/org/apache/gravitino/bundles/TestAwsBundleContent.java b/bundles/aws-bundle/src/test/java/org/apache/gravitino/bundles/TestAwsBundleContent.java
new file mode 100644
index 0000000000..cbc95ef059
--- /dev/null
+++ b/bundles/aws-bundle/src/test/java/org/apache/gravitino/bundles/TestAwsBundleContent.java
@@ -0,0 +1,247 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.bundles;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.File;
+import java.io.InputStream;
+import java.lang.reflect.Method;
+import java.net.URI;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Checks the content of the AWS bundle, which is built on hadoop-aws 3.4 and the single modules of
+ * the AWS SDK v2. The bundle must not carry the AWS SDK v1 or the 650 MB AWS SDK v2 bundle, must
+ * keep the Netty copy on the version of the build, and must keep the S3A connector working.
+ */
+class TestAwsBundleContent {
+
+ private static final File BUNDLE = new File(System.getProperty("shadowJarPath"));
+ private static final String NETTY_VERSION = System.getProperty("nettyVersion");
+
+ @Test
+ void testNoAwsSdkV1() throws Exception {
+ try (JarFile jar = new JarFile(BUNDLE)) {
+ assertFalse(
+ jar.stream().anyMatch(entry -> entry.getName().startsWith("com/amazonaws/")),
+ "The AWS SDK v1 must not be bundled");
+ assertFalse(
+ jar.stream()
+ .anyMatch(entry -> entry.getName().startsWith("META-INF/maven/com.amazonaws/")),
+ "The AWS SDK v1 must not be bundled");
+ }
+ }
+
+ @Test
+ void testNoAwsSdkBundleArtifact() throws Exception {
+ try (JarFile jar = new JarFile(BUNDLE)) {
+ assertFalse(
+ jar.stream()
+ .anyMatch(
+ entry ->
+ entry
+ .getName()
+ .equals("META-INF/maven/software.amazon.awssdk/bundle/pom.properties")),
+ "software.amazon.awssdk:bundle must not be bundled");
+ assertFalse(
+ jar.stream()
+ .anyMatch(
+ entry ->
+ entry
+ .getName()
+ .startsWith("software/amazon/awssdk/thirdparty/org/apache/http/")),
+ "The Apache HTTP client shaded by the AWS SDK bundle must not be bundled");
+ }
+ }
+
+ @Test
+ void testApacheHttpClientsAreRelocated() throws Exception {
+ try (JarFile jar = new JarFile(BUNDLE)) {
+ for (String prefix : new String[] {"org/apache/http/", "org/apache/hc/"}) {
+ assertFalse(
+ jar.stream().anyMatch(entry -> entry.getName().startsWith(prefix)),
+ prefix + " must be relocated");
+ String relocated = "org/apache/gravitino/aws/shaded/" + prefix;
+ assertTrue(
+ jar.stream().anyMatch(entry -> entry.getName().startsWith(relocated)),
+ prefix + " must be bundled under " + relocated);
+ }
+ }
+ }
+
+ @Test
+ void testNettyVersion() throws Exception {
+ assertNotNull(NETTY_VERSION, "nettyVersion");
+ List<String> versions = new ArrayList<>();
+ try (JarFile jar = new JarFile(BUNDLE)) {
+ for (JarEntry entry : (Iterable<JarEntry>) jar.stream()::iterator) {
+ if (entry.getName().startsWith("META-INF/maven/io.netty/")
+ && entry.getName().endsWith("/pom.properties")) {
+ Properties properties = new Properties();
+ try (InputStream in = jar.getInputStream(entry)) {
+ properties.load(in);
+ }
+ versions.add(entry.getName() + "=" + properties.getProperty("version"));
+ }
+ }
+ }
+ assertFalse(versions.isEmpty(), "No Netty module found in " + BUNDLE.getName());
+ for (String version : versions) {
+ assertTrue(version.endsWith("=" + NETTY_VERSION), version);
+ }
+ }
+
+ @Test
+ void testShadedSocketFactoryLinks() throws Exception {
+ // hadoop-aws links this class against the Apache HTTP client shaded by the AWS SDK bundle. The
+ // build relocates that package to the Apache HTTP client of the single SDK modules.
+ try (URLClassLoader loader = newLoader()) {
+ Class<?> factory =
+ loader.loadClass("org.apache.hadoop.fs.s3a.impl.ConfigureShadedAWSSocketFactory");
+ Class<?> mode =
+ loader.loadClass(
+ "org.apache.hadoop.security.ssl.DelegatingSSLSocketFactory$SSLChannelMode");
+ Class<?> builderClass =
+ loader.loadClass("software.amazon.awssdk.http.apache.ApacheHttpClient$Builder");
+ Object builder =
+ loader
+ .loadClass("software.amazon.awssdk.http.apache.ApacheHttpClient")
+ .getMethod("builder")
+ .invoke(null);
+ Object instance = factory.getConstructor().newInstance();
+ // Fails with NoClassDefFoundError when the shaded HTTP client cannot be resolved.
+ factory
+ .getMethod("configureSocketFactory", builderClass, mode)
+ .invoke(instance, builder, mode.getField("Default_JSSE").get(null));
+ }
+ }
+
+ @Test
+ void testS3AFileSystemInitializes() throws Exception {
+ try (URLClassLoader loader = newLoader()) {
+ withS3AFileSystem(
+ loader,
+ new String[0][],
+ (fsClass, fs) -> assertEquals("s3a", fsClass.getMethod("getScheme").invoke(fs)));
+ }
+ }
+
+ @ParameterizedTest
+ @ValueSource(booleans = {false, true})
+ void testClientSideEncryptionWithKms(boolean v1Compatibility) throws Exception {
+ // Hadoop 3.3 took the encryption client from the AWS SDK v1 bundle. Hadoop 3.4 needs the S3
+ // encryption client and the KMS module, which hadoop-aws does not bring.
+ String[][] settings = {
+ {"fs.s3a.encryption.algorithm", "CSE-KMS"},
+ {"fs.s3a.encryption.key", "arn:aws:kms:us-east-1:123456789012:key/test-key"},
+ {"fs.s3a.encryption.cse.kms.region", "us-east-1"},
+ {"fs.s3a.encryption.cse.v1.compatibility.enabled", String.valueOf(v1Compatibility)}
+ };
+ try (URLClassLoader loader = newLoader()) {
+ withS3AFileSystem(
+ loader,
+ settings,
+ (fsClass, fs) -> {
+ // The S3 client is created on first use, which builds the KMS keyring and the
+ // encryption client without calling AWS.
+ Object internals = fsClass.getMethod("getS3AInternals").invoke(fs);
+ Object client =
+ loader
+ .loadClass("org.apache.hadoop.fs.s3a.S3AInternals")
+ .getMethod("getAmazonS3Client", String.class)
+ .invoke(internals, "test");
+ assertTrue(
+ loader
+ .loadClass("software.amazon.encryption.s3.S3EncryptionClient")
+ .isInstance(client),
+ "Expected the S3 encryption client, got " + client.getClass().getName());
+ });
+ }
+ }
+
+ private static void withS3AFileSystem(
+ URLClassLoader loader, String[][] extraSettings, FileSystemCheck check) throws Exception {
+ ClassLoader original = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(loader);
+ try {
+ Class<?> confClass = loader.loadClass("org.apache.hadoop.conf.Configuration");
+ Object conf = confClass.getConstructor(boolean.class).newInstance(false);
+ String[][] settings = {
+ {
+ "fs.s3a.aws.credentials.provider", "org.apache.hadoop.fs.s3a.SimpleAWSCredentialsProvider"
+ },
+ {"fs.s3a.access.key", "access-key"},
+ {"fs.s3a.secret.key", "secret-key"},
+ {"fs.s3a.endpoint", "http://127.0.0.1:1"},
+ {"fs.s3a.endpoint.region", "us-east-1"},
+ {"fs.s3a.path.style.access", "true"},
+ {"fs.s3a.connection.ssl.enabled", "false"},
+ {"fs.s3a.bucket.probe", "0"}
+ };
+ Method set = confClass.getMethod("set", String.class, String.class);
+ for (String[] setting : settings) {
+ set.invoke(conf, setting[0], setting[1]);
+ }
+ for (String[] setting : extraSettings) {
+ set.invoke(conf, setting[0], setting[1]);
+ }
+ Class<?> fsClass = loader.loadClass("org.apache.hadoop.fs.s3a.S3AFileSystem");
+ Object fs = fsClass.getConstructor().newInstance();
+ fsClass
+ .getMethod("initialize", URI.class, confClass)
+ .invoke(fs, URI.create("s3a://bucket/"), conf);
+ try {
+ check.accept(fsClass, fs);
+ } finally {
+ fsClass.getMethod("close").invoke(fs);
+ }
+ } finally {
+ Thread.currentThread().setContextClassLoader(original);
+ }
+ }
+
+ /** A check on an initialized S3AFileSystem, loaded by the bundle class loader. */
+ @FunctionalInterface
+ private interface FileSystemCheck {
+ void accept(Class<?> fsClass, Object fs) throws Exception;
+ }
+
+ private static URLClassLoader newLoader() throws Exception {
+ URL[] urls = {
+ BUNDLE.toURI().toURL(),
+ LoggerFactory.class.getProtectionDomain().getCodeSource().getLocation()
+ };
+ // The ordinary test classpath also contains unshaded Hadoop and AWS SDK classes.
+ return new URLClassLoader(urls, ClassLoader.getPlatformClassLoader());
+ }
+}
diff --git a/bundles/aws-bundle/src/test/java/org/apache/gravitino/bundles/TestAwsBundleShadedLibraries.java b/bundles/aws-bundle/src/test/java/org/apache/gravitino/bundles/TestAwsBundleShadedLibraries.java
new file mode 100644
index 0000000000..8c8a42bb7a
--- /dev/null
+++ b/bundles/aws-bundle/src/test/java/org/apache/gravitino/bundles/TestAwsBundleShadedLibraries.java
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.bundles;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.File;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Checks the libraries that hadoop-client-runtime shades into the aws bundle. Hadoop 3.3 shaded
+ * Avro 1.7.7 and protobuf 3.7.1, Hadoop 3.4.3 ships Avro 1.11.4 and protobuf 3.25.
+ */
+class TestAwsBundleShadedLibraries {
+
+ private static final File BUNDLE = new File(System.getProperty("shadowJarPath"));
+
+ @Test
+ void testAvroIsNotOutdated() throws Exception {
+ for (String version : versionsOf("META-INF/maven/org.apache.avro/avro/pom.properties")) {
+ assertTrue(compare(version, "1.11.4") >= 0, "Outdated Avro " + version);
+ }
+ }
+
+ @Test
+ void testProtobufIsNotOutdated() throws Exception {
+ assertTrue(
+ versionsOf(
+ "META-INF/maven/org.apache.hadoop.thirdparty/hadoop-shaded-protobuf_3_7/pom.properties")
+ .isEmpty(),
+ "hadoop-shaded-protobuf_3_7 is outdated");
+ for (String version :
+ versionsOf("META-INF/maven/com.google.protobuf/protobuf-java/pom.properties")) {
+ assertTrue(compare(version, "3.25.0") >= 0, "Outdated protobuf " + version);
+ }
+ try (JarFile jar = new JarFile(BUNDLE)) {
+ assertFalse(
+ jar.stream()
+ .anyMatch(
+ e -> e.getName().startsWith("org/apache/hadoop/shaded/com/google/protobuf/")),
+ "Protobuf 3.7 is shaded under org/apache/hadoop/shaded");
+ }
+ }
+
+ private static List<String> versionsOf(String propertiesEntry) throws Exception {
+ List<String> versions = new ArrayList<>();
+ try (JarFile jar = new JarFile(BUNDLE)) {
+ for (JarEntry entry : (Iterable<JarEntry>) jar.stream()::iterator) {
+ if (entry.getName().equals(propertiesEntry)) {
+ Properties properties = new Properties();
+ try (InputStream in = jar.getInputStream(entry)) {
+ properties.load(in);
+ }
+ versions.add(properties.getProperty("version"));
+ }
+ }
+ }
+ return versions;
+ }
+
+ private static int compare(String version, String minimum) {
+ String[] left = version.split("[.-]");
+ String[] right = minimum.split("[.-]");
+ for (int i = 0; i < right.length; i++) {
+ int l = i < left.length ? Integer.parseInt(left[i]) : 0;
+ int r = Integer.parseInt(right[i]);
+ if (l != r) {
+ return Integer.compare(l, r);
+ }
+ }
+ return 0;
+ }
+}
diff --git a/bundles/aws/build.gradle.kts b/bundles/aws/build.gradle.kts
index 8b9fe82abc..207a51aa6f 100644
--- a/bundles/aws/build.gradle.kts
+++ b/bundles/aws/build.gradle.kts
@@ -42,13 +42,26 @@ dependencies {
compileOnly(libs.aws.iam)
compileOnly(libs.aws.policy)
compileOnly(libs.aws.sts)
- compileOnly(libs.hadoop3.aws)
+ compileOnly(libs.hadoop3.aws) {
+ exclude("software.amazon.awssdk", "bundle")
+ }
compileOnly(libs.hadoop3.client.api)
+ // AWS SDK v1 is only needed to compile S3CredentialsProvider, which serves Hadoop 3.3 and earlier.
+ // The thin bundle does not ship it, the Hadoop runtime provides it.
+ compileOnly(libs.aws.v1.core) {
+ isTransitive = false
+ }
+ testCompileOnly(libs.aws.v1.core) {
+ isTransitive = false
+ }
testImplementation(libs.aws.iam)
testImplementation(libs.aws.policy)
testImplementation(libs.aws.sts)
- testImplementation(libs.hadoop3.aws)
+ testImplementation(libs.hadoop3.aws) {
+ exclude("software.amazon.awssdk", "bundle")
+ }
+ testImplementation(libs.bundles.hadoop.aws.sdk)
testImplementation(libs.hadoop3.client.api)
testImplementation(libs.hadoop3.client.runtime)
testImplementation(libs.junit.jupiter.api)
@@ -59,3 +72,57 @@ dependencies {
tasks.compileJava {
dependsOn(":catalogs:catalog-fileset:runtimeJars")
}
+
+// The thin bundle runs on the Hadoop of its host, which can be 3.3 (AWS SDK v1, for example Spark 3.5)
+// or 3.4 and later (AWS SDK v2). The default test task runs against the Hadoop version of the
+// project. The tasks below run the AWS SDK v1 tests against the oldest supported Hadoop 3.3, once
+// with the AWS SDK v1 only and once with the AWS SDK v2 also on the classpath, as in a Spark 3.5
+// job that uses the Iceberg AWS bundle.
+val hadoop33Version: String = libs.versions.hadoop33.get()
+
+fun hadoop33TestRuntime(withSdkV2: Boolean): Configuration =
+ configurations.testRuntimeClasspath.get().copyRecursive().apply {
+ resolutionStrategy.eachDependency {
+ if (requested.group == "org.apache.hadoop") {
+ useVersion(hadoop33Version)
+ }
+ }
+ if (!withSdkV2) {
+ exclude(group = "software.amazon.awssdk")
+ }
+ }
+
+fun registerHadoop33Test(name: String, withSdkV2: Boolean): TaskProvider<Test> {
+ val runtime = hadoop33TestRuntime(withSdkV2)
+ return tasks.register<Test>(name) {
+ group = "verification"
+ description =
+ "Runs the AWS SDK v1 tests against Hadoop $hadoop33Version" +
+ if (withSdkV2) " with the AWS SDK v2 on the classpath" else ""
+ testClassesDirs = sourceSets.test.get().output.classesDirs
+ classpath = sourceSets.test.get().output + sourceSets.main.get().output + runtime
+ include("**/*V1.class", "**/TestS3CredentialsProviderSelection.class")
+ systemProperty("s3a.expectedSdk", "v1")
+ systemProperty("s3a.sdkV1OnClasspath", "true")
+ systemProperty("s3a.sdkV2OnClasspath", withSdkV2.toString())
+ onlyIf { !project.hasProperty("skipTests") }
+ }
+}
+
+val testHadoop33 = registerHadoop33Test("testHadoop33", withSdkV2 = false)
+val testHadoop33WithSdkV2 = registerHadoop33Test("testHadoop33WithSdkV2", withSdkV2 = true)
+
+tasks.test {
+ // The AWS SDK v1 tests run in the Hadoop 3.3 tasks, the AWS SDK v1 is not on this classpath.
+ exclude("**/*V1.class")
+ val hadoop33 = libs.versions.hadoop3.asProvider().get().startsWith("3.3.")
+ systemProperty("s3a.expectedSdk", if (hadoop33) "v1" else "v2")
+ systemProperty("s3a.sdkV1OnClasspath", hadoop33.toString())
+ systemProperty("s3a.sdkV2OnClasspath", "true")
+ // Run them with `./gradlew test` too, not only with `check`.
+ finalizedBy(testHadoop33, testHadoop33WithSdkV2)
+}
+
+tasks.check {
+ dependsOn(testHadoop33, testHadoop33WithSdkV2)
+}
diff --git a/bundles/aws/src/main/java/org/apache/gravitino/s3/fs/S3CredentialsProvider.java b/bundles/aws/src/main/java/org/apache/gravitino/s3/fs/S3CredentialsProvider.java
index e047c51e70..d3bff60e47 100644
--- a/bundles/aws/src/main/java/org/apache/gravitino/s3/fs/S3CredentialsProvider.java
+++ b/bundles/aws/src/main/java/org/apache/gravitino/s3/fs/S3CredentialsProvider.java
@@ -24,73 +24,50 @@ import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.auth.BasicSessionCredentials;
import java.net.URI;
-import org.apache.gravitino.catalog.hadoop.fs.FileSystemUtils;
-import org.apache.gravitino.catalog.hadoop.fs.GravitinoFileSystemCredentialsProvider;
-import org.apache.gravitino.credential.AwsIrsaCredential;
-import org.apache.gravitino.credential.Credential;
-import org.apache.gravitino.credential.S3SecretKeyCredential;
-import org.apache.gravitino.credential.S3TokenCredential;
+import org.apache.gravitino.s3.fs.S3CredentialsRefresher.S3Credentials;
import org.apache.hadoop.conf.Configuration;
+/**
+ * An AWS SDK v1 credentials provider that vends the S3 credentials of Gravitino. It is used by
+ * Hadoop 3.3 and earlier, whose S3A connector is built on the AWS SDK v1. Hadoop 3.4 and later use
+ * {@link S3CredentialsProviderV2}.
+ */
public class S3CredentialsProvider implements AWSCredentialsProvider {
- private GravitinoFileSystemCredentialsProvider gravitinoFileSystemCredentialsProvider;
- private AWSCredentials basicSessionCredentials;
- private long expirationTime = Long.MAX_VALUE;
- private static final double EXPIRATION_TIME_FACTOR = 0.5D;
+ private final S3CredentialsRefresher refresher;
+ /**
+ * Creates the provider. Hadoop instantiates it by reflection with this signature.
+ *
+ * @param uri The URI of the file system.
+ * @param conf The Hadoop configuration that carries the Gravitino credential provider settings.
+ */
public S3CredentialsProvider(final URI uri, final Configuration conf) {
- this.gravitinoFileSystemCredentialsProvider = FileSystemUtils.getGvfsCredentialProvider(conf);
+ this(conf);
+ }
+
+ /**
+ * Creates the provider. The S3A connector of Hadoop 3.2 and earlier only looks up this signature,
+ * Hadoop 3.3 prefers {@link #S3CredentialsProvider(URI, Configuration)}.
+ *
+ * @param conf The Hadoop configuration that carries the Gravitino credential provider settings.
+ */
+ public S3CredentialsProvider(final Configuration conf) {
+ this.refresher = new S3CredentialsRefresher(conf);
}
@Override
public AWSCredentials getCredentials() {
- // Refresh credentials if they are null or about to expire.
- if (basicSessionCredentials == null || System.currentTimeMillis() >= expirationTime) {
- synchronized (this) {
- refresh();
- }
+ S3Credentials credentials = refresher.getCredentials();
+ if (credentials.sessionToken() == null) {
+ return new BasicAWSCredentials(credentials.accessKeyId(), credentials.secretAccessKey());
}
-
- return basicSessionCredentials;
+ return new BasicSessionCredentials(
+ credentials.accessKeyId(), credentials.secretAccessKey(), credentials.sessionToken());
}
@Override
public void refresh() {
- Credential[] gravitinoCredentials = gravitinoFileSystemCredentialsProvider.getCredentials();
- Credential credential = S3Utils.getSuitableCredential(gravitinoCredentials);
-
- if (credential == null) {
- throw new RuntimeException("No suitable credential for S3 found...");
- }
-
- if (credential instanceof S3SecretKeyCredential) {
- S3SecretKeyCredential s3SecretKeyCredential = (S3SecretKeyCredential) credential;
- basicSessionCredentials =
- new BasicAWSCredentials(
- s3SecretKeyCredential.accessKeyId(), s3SecretKeyCredential.secretAccessKey());
- } else if (credential instanceof S3TokenCredential) {
- S3TokenCredential s3TokenCredential = (S3TokenCredential) credential;
- basicSessionCredentials =
- new BasicSessionCredentials(
- s3TokenCredential.accessKeyId(),
- s3TokenCredential.secretAccessKey(),
- s3TokenCredential.sessionToken());
- } else if (credential instanceof AwsIrsaCredential) {
- AwsIrsaCredential awsIrsaCredential = (AwsIrsaCredential) credential;
- basicSessionCredentials =
- new BasicSessionCredentials(
- awsIrsaCredential.accessKeyId(),
- awsIrsaCredential.secretAccessKey(),
- awsIrsaCredential.sessionToken());
- }
-
- if (credential.expireTimeInMs() > 0) {
- expirationTime =
- System.currentTimeMillis()
- + (long)
- ((credential.expireTimeInMs() - System.currentTimeMillis())
- * EXPIRATION_TIME_FACTOR);
- }
+ refresher.refresh();
}
}
diff --git a/bundles/aws/src/main/java/org/apache/gravitino/s3/fs/S3CredentialsProviderV2.java b/bundles/aws/src/main/java/org/apache/gravitino/s3/fs/S3CredentialsProviderV2.java
new file mode 100644
index 0000000000..826e250e89
--- /dev/null
+++ b/bundles/aws/src/main/java/org/apache/gravitino/s3/fs/S3CredentialsProviderV2.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.s3.fs;
+
+import java.net.URI;
+import org.apache.gravitino.s3.fs.S3CredentialsRefresher.S3Credentials;
+import org.apache.hadoop.conf.Configuration;
+import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
+import software.amazon.awssdk.auth.credentials.AwsCredentials;
+import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
+import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
+
+/**
+ * An AWS SDK v2 credentials provider that vends the S3 credentials of Gravitino. It is used by
+ * Hadoop 3.4 and later, whose S3A connector is built on the AWS SDK v2. Hadoop 3.3 and earlier use
+ * {@link S3CredentialsProvider}.
+ */
+public class S3CredentialsProviderV2 implements AwsCredentialsProvider {
+
+ private final S3CredentialsRefresher refresher;
+
+ /**
+ * Creates the provider. Hadoop instantiates it by reflection with this signature.
+ *
+ * @param uri The URI of the file system.
+ * @param conf The Hadoop configuration that carries the Gravitino credential provider settings.
+ */
+ public S3CredentialsProviderV2(final URI uri, final Configuration conf) {
+ this.refresher = new S3CredentialsRefresher(conf);
+ }
+
+ @Override
+ public AwsCredentials resolveCredentials() {
+ S3Credentials credentials = refresher.getCredentials();
+ if (credentials.sessionToken() == null) {
+ return AwsBasicCredentials.create(credentials.accessKeyId(), credentials.secretAccessKey());
+ }
+ return AwsSessionCredentials.create(
+ credentials.accessKeyId(), credentials.secretAccessKey(), credentials.sessionToken());
+ }
+}
diff --git a/bundles/aws/src/main/java/org/apache/gravitino/s3/fs/S3CredentialsRefresher.java b/bundles/aws/src/main/java/org/apache/gravitino/s3/fs/S3CredentialsRefresher.java
new file mode 100644
index 0000000000..fde2ffaf6e
--- /dev/null
+++ b/bundles/aws/src/main/java/org/apache/gravitino/s3/fs/S3CredentialsRefresher.java
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.s3.fs;
+
+import com.google.common.annotations.VisibleForTesting;
+import javax.annotation.Nullable;
+import org.apache.gravitino.catalog.hadoop.fs.FileSystemUtils;
+import org.apache.gravitino.catalog.hadoop.fs.GravitinoFileSystemCredentialsProvider;
+import org.apache.gravitino.credential.AwsIrsaCredential;
+import org.apache.gravitino.credential.Credential;
+import org.apache.gravitino.credential.S3SecretKeyCredential;
+import org.apache.gravitino.credential.S3TokenCredential;
+import org.apache.hadoop.conf.Configuration;
+
+/**
+ * Fetches S3 credentials from Gravitino and refreshes them before they expire.
+ *
+ * <p>This class does not depend on any AWS SDK class, so that both {@link S3CredentialsProvider}
+ * (AWS SDK v1, used by Hadoop 3.3) and {@link S3CredentialsProviderV2} (AWS SDK v2, used by Hadoop
+ * 3.4 and later) can share it without requiring the other SDK on the classpath.
+ */
+class S3CredentialsRefresher {
+
+ /** The point of the credential lifetime at which the credential is refreshed. */
+ private static final double EXPIRATION_TIME_FACTOR = 0.5D;
+
+ private final GravitinoFileSystemCredentialsProvider gravitinoFileSystemCredentialsProvider;
+ private volatile S3Credentials credentials;
+ private volatile long expirationTime = Long.MAX_VALUE;
+
+ S3CredentialsRefresher(Configuration conf) {
+ this.gravitinoFileSystemCredentialsProvider = FileSystemUtils.getGvfsCredentialProvider(conf);
+ }
+
+ /**
+ * Returns the current credentials, refreshing them if they are missing or about to expire.
+ *
+ * @return the credentials
+ */
+ S3Credentials getCredentials() {
+ if (needsRefresh()) {
+ synchronized (this) {
+ // Another thread may have refreshed the credentials while this one waited for the lock.
+ if (needsRefresh()) {
+ refresh();
+ }
+ }
+ }
+ return credentials;
+ }
+
+ @VisibleForTesting
+ long expirationTime() {
+ return expirationTime;
+ }
+
+ /** Fetches new credentials from Gravitino. */
+ synchronized void refresh() {
+ Credential[] gravitinoCredentials = gravitinoFileSystemCredentialsProvider.getCredentials();
+ Credential credential = S3Utils.getSuitableCredential(gravitinoCredentials);
+ if (credential == null) {
+ throw new RuntimeException("No suitable credential for S3 found...");
+ }
+
+ if (credential instanceof S3SecretKeyCredential) {
+ S3SecretKeyCredential s3SecretKeyCredential = (S3SecretKeyCredential) credential;
+ credentials =
+ new S3Credentials(
+ s3SecretKeyCredential.accessKeyId(), s3SecretKeyCredential.secretAccessKey(), null);
+ } else if (credential instanceof S3TokenCredential) {
+ S3TokenCredential s3TokenCredential = (S3TokenCredential) credential;
+ credentials =
+ new S3Credentials(
+ s3TokenCredential.accessKeyId(),
+ s3TokenCredential.secretAccessKey(),
+ s3TokenCredential.sessionToken());
+ } else if (credential instanceof AwsIrsaCredential) {
+ AwsIrsaCredential awsIrsaCredential = (AwsIrsaCredential) credential;
+ credentials =
+ new S3Credentials(
+ awsIrsaCredential.accessKeyId(),
+ awsIrsaCredential.secretAccessKey(),
+ awsIrsaCredential.sessionToken());
+ }
+
+ if (credential.expireTimeInMs() > 0) {
+ expirationTime =
+ System.currentTimeMillis()
+ + (long)
+ ((credential.expireTimeInMs() - System.currentTimeMillis())
+ * EXPIRATION_TIME_FACTOR);
+ }
+ }
+
+ private boolean needsRefresh() {
+ return credentials == null || System.currentTimeMillis() >= expirationTime;
+ }
+
+ /** Immutable S3 credentials, with a session token for temporary credentials only. */
+ static final class S3Credentials {
+ private final String accessKeyId;
+ private final String secretAccessKey;
+ @Nullable private final String sessionToken;
+
+ S3Credentials(String accessKeyId, String secretAccessKey, @Nullable String sessionToken) {
+ this.accessKeyId = accessKeyId;
+ this.secretAccessKey = secretAccessKey;
+ this.sessionToken = sessionToken;
+ }
+
+ String accessKeyId() {
+ return accessKeyId;
+ }
+
+ String secretAccessKey() {
+ return secretAccessKey;
+ }
+
+ @Nullable
+ String sessionToken() {
+ return sessionToken;
+ }
+ }
+}
diff --git a/bundles/aws/src/main/java/org/apache/gravitino/s3/fs/S3FileSystemProvider.java b/bundles/aws/src/main/java/org/apache/gravitino/s3/fs/S3FileSystemProvider.java
index 07cf221d74..d41f8ce8b2 100644
--- a/bundles/aws/src/main/java/org/apache/gravitino/s3/fs/S3FileSystemProvider.java
+++ b/bundles/aws/src/main/java/org/apache/gravitino/s3/fs/S3FileSystemProvider.java
@@ -21,12 +21,13 @@ package org.apache.gravitino.s3.fs;
import static org.apache.gravitino.catalog.hadoop.fs.Constants.DEFAULT_CONNECTION_TIMEOUT;
import static org.apache.gravitino.catalog.hadoop.fs.Constants.DEFAULT_RETRY_LIMIT;
+import static org.apache.gravitino.catalog.hadoop.fs.Constants.S3_DIRECTORY_MARKER_RETENTION;
+import static org.apache.gravitino.catalog.hadoop.fs.Constants.S3_DIRECTORY_MARKER_RETENTION_DELETE;
import static org.apache.gravitino.catalog.hadoop.fs.Constants.S3_ESTABLISH_TIMEOUT;
import static org.apache.gravitino.catalog.hadoop.fs.Constants.S3_MAX_ERROR_RETRIES;
import static org.apache.gravitino.catalog.hadoop.fs.Constants.S3_RETRY_LIMIT;
import static org.apache.gravitino.catalog.hadoop.fs.Constants.S3_RETRY_THROTTLE_LIMIT;
-import com.amazonaws.auth.AWSCredentialsProvider;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
@@ -66,6 +67,16 @@ public class S3FileSystemProvider implements FileSystemProvider, SupportsCredent
// We can't use Constants.AWS_CREDENTIALS_PROVIDER directly, as in 2.7, this key does not exist.
private static final String S3_CREDENTIAL_KEY = "fs.s3a.aws.credentials.provider";
+ // Class names instead of class literals, so that loading this class does not need the AWS SDK
+ // that is not in use. TestS3CredentialsProviderSelection checks that they match the classes.
+ @VisibleForTesting
+ static final String S3_CREDENTIALS_PROVIDER_V1 =
+ "org.apache.gravitino.s3.fs.S3CredentialsProvider";
+
+ @VisibleForTesting
+ static final String S3_CREDENTIALS_PROVIDER_V2 =
+ "org.apache.gravitino.s3.fs.S3CredentialsProviderV2";
+
private static final String S3_SIMPLE_CREDENTIAL =
"org.apache.hadoop.fs.s3a.SimpleAWSCredentialsProvider";
@@ -94,14 +105,17 @@ public class S3FileSystemProvider implements FileSystemProvider, SupportsCredent
if (credential instanceof S3SecretKeyCredential
|| credential instanceof S3TokenCredential
|| credential instanceof AwsIrsaCredential) {
+ // Hadoop 3.4+ is built on the AWS SDK v2 and Hadoop 3.3 on the AWS SDK v1.
result.put(
- Constants.AWS_CREDENTIALS_PROVIDER, S3CredentialsProvider.class.getCanonicalName());
+ Constants.AWS_CREDENTIALS_PROVIDER,
+ S3Utils.isHadoopAwsSdkV2() ? S3_CREDENTIALS_PROVIDER_V2 : S3_CREDENTIALS_PROVIDER_V1);
}
return result;
}
- private void checkAndSetCredentialProvider(Map<String, String> configs) {
+ @VisibleForTesting
+ void checkAndSetCredentialProvider(Map<String, String> configs) {
String provides = configs.get(S3_CREDENTIAL_KEY);
if (provides == null) {
return;
@@ -114,19 +128,35 @@ public class S3FileSystemProvider implements FileSystemProvider, SupportsCredent
List<String> validProviders = Lists.newArrayList();
for (String provider : providers) {
+ if (S3Utils.isRemappedByHadoop(provider)) {
+ // Hadoop maps this AWS SDK v1 provider name to its AWS SDK v2 counterpart by itself.
+ validProviders.add(provider);
+ continue;
+ }
try {
Class<?> c = Class.forName(provider);
- if (AWSCredentialsProvider.class.isAssignableFrom(c)) {
+ if (S3Utils.isCredentialsProvider(c)) {
validProviders.add(provider);
} else {
LOG.warn(
- "Credential provider {} is not a subclass of AWSCredentialsProvider, skipping",
+ "Credential provider {} is not a credentials provider of the AWS SDK that the S3A "
+ + "connector uses, skipping",
provider);
}
- } catch (Exception e) {
+ } catch (ClassNotFoundException e) {
LOG.warn(
"Credential provider {} not found in the Hadoop runtime, falling back to default",
- provider);
+ provider,
+ e);
+ configs.put(S3_CREDENTIAL_KEY, S3_SIMPLE_CREDENTIAL);
+ return;
+ } catch (Exception | LinkageError e) {
+ // The class exists, but it or a class it depends on cannot be loaded or initialized, for
+ // example because of an incompatible AWS SDK or Hadoop version on the classpath.
+ LOG.warn(
+ "Credential provider {} cannot be loaded in the Hadoop runtime, falling back to default",
+ provider,
+ e);
configs.put(S3_CREDENTIAL_KEY, S3_SIMPLE_CREDENTIAL);
return;
}
@@ -159,7 +189,8 @@ public class S3FileSystemProvider implements FileSystemProvider, SupportsCredent
* @param configs Original configurations
* @return Configurations with additional S3 settings
*/
- private Map<String, String> additionalS3Config(Map<String, String> configs) {
+ @VisibleForTesting
+ Map<String, String> additionalS3Config(Map<String, String> configs) {
Map<String, String> additionalConfigs = Maps.newHashMap(configs);
// Avoid multiple retries to speed up failure in test cases.
@@ -181,6 +212,12 @@ public class S3FileSystemProvider implements FileSystemProvider, SupportsCredent
additionalConfigs.put(S3_RETRY_THROTTLE_LIMIT, DEFAULT_RETRY_LIMIT);
}
+ // Keep deleting the directory markers like Hadoop 3.3 and earlier do, so that the objects
+ // written by Gravitino stay readable by S3A clients that do not understand kept markers.
+ if (!configs.containsKey(S3_DIRECTORY_MARKER_RETENTION)) {
+ additionalConfigs.put(S3_DIRECTORY_MARKER_RETENTION, S3_DIRECTORY_MARKER_RETENTION_DELETE);
+ }
+
// More tuning can be added here.
return ImmutableMap.copyOf(additionalConfigs);
diff --git a/bundles/aws/src/main/java/org/apache/gravitino/s3/fs/S3Utils.java b/bundles/aws/src/main/java/org/apache/gravitino/s3/fs/S3Utils.java
index 0c6244b9d2..e664c897a2 100644
--- a/bundles/aws/src/main/java/org/apache/gravitino/s3/fs/S3Utils.java
+++ b/bundles/aws/src/main/java/org/apache/gravitino/s3/fs/S3Utils.java
@@ -19,13 +19,96 @@
package org.apache.gravitino.s3.fs;
+import com.google.common.collect.ImmutableSet;
+import java.util.Set;
import org.apache.gravitino.credential.AwsIrsaCredential;
import org.apache.gravitino.credential.Credential;
import org.apache.gravitino.credential.S3SecretKeyCredential;
import org.apache.gravitino.credential.S3TokenCredential;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class S3Utils {
+ private static final Logger LOG = LoggerFactory.getLogger(S3Utils.class);
+
+ /**
+ * A class that only exists in Hadoop 3.4 and later, whose S3A connector is built on the AWS SDK
+ * v2. Hadoop 3.3 and earlier are built on the AWS SDK v1.
+ */
+ private static final String HADOOP_AWS_SDK_V2_MARKER_CLASS =
+ "org.apache.hadoop.fs.s3a.adapter.AwsV1BindingSupport";
+
+ private static final String SDK_V1_CREDENTIALS_PROVIDER =
+ "com.amazonaws.auth.AWSCredentialsProvider";
+
+ private static final String SDK_V2_CREDENTIALS_PROVIDER =
+ "software.amazon.awssdk.auth.credentials.AwsCredentialsProvider";
+
+ /**
+ * AWS SDK v1 credentials providers that Hadoop 3.4 and later map to their own providers by name,
+ * so the v1 classes are not needed on the classpath.
+ */
+ private static final Set<String> HADOOP_REMAPPED_SDK_V1_PROVIDERS =
+ ImmutableSet.of(
+ "com.amazonaws.auth.AnonymousAWSCredentials",
+ "com.amazonaws.auth.EC2ContainerCredentialsProviderWrapper",
+ "com.amazonaws.auth.InstanceProfileCredentialsProvider",
+ "com.amazonaws.auth.EnvironmentVariableCredentialsProvider",
+ "com.amazonaws.auth.profile.ProfileCredentialsProvider");
+
+ /**
+ * Check whether the S3A connector of Hadoop on the classpath is built on the AWS SDK v2, that is,
+ * whether it is Hadoop 3.4 or later.
+ *
+ * @return True if the S3A connector uses the AWS SDK v2, false if it uses the AWS SDK v1.
+ */
+ static boolean isHadoopAwsSdkV2() {
+ return loadClass(HADOOP_AWS_SDK_V2_MARKER_CLASS) != null;
+ }
+
+ /**
+ * Check whether the class is a credentials provider that the S3A connector on the classpath can
+ * use. Hadoop 3.4 and later accept AWS SDK v2 providers and, through an adapter, AWS SDK v1
+ * providers. Hadoop 3.3 and earlier only accept AWS SDK v1 providers, even if the AWS SDK v2 is
+ * also on the classpath. The SDK interfaces are resolved by name, because only one of the two
+ * SDKs may be on the classpath.
+ *
+ * @param providerClass The class to check.
+ * @return True if the S3A connector on the classpath can use the class as a credentials provider.
+ */
+ static boolean isCredentialsProvider(Class<?> providerClass) {
+ return isAssignableTo(providerClass, SDK_V1_CREDENTIALS_PROVIDER)
+ || (isHadoopAwsSdkV2() && isAssignableTo(providerClass, SDK_V2_CREDENTIALS_PROVIDER));
+ }
+
+ /**
+ * Check whether the name is an AWS SDK v1 credentials provider that Hadoop 3.4 and later map to
+ * an AWS SDK v2 provider by name, so that the class does not need to exist.
+ *
+ * @param providerName The credentials provider class name.
+ * @return True if the S3A connector remaps the name.
+ */
+ static boolean isRemappedByHadoop(String providerName) {
+ return isHadoopAwsSdkV2() && HADOOP_REMAPPED_SDK_V1_PROVIDERS.contains(providerName);
+ }
+
+ private static boolean isAssignableTo(Class<?> providerClass, String interfaceName) {
+ Class<?> providerInterface = loadClass(interfaceName);
+ return providerInterface != null && providerInterface.isAssignableFrom(providerClass);
+ }
+
+ private static Class<?> loadClass(String className) {
+ try {
+ return Class.forName(className, false, S3Utils.class.getClassLoader());
+ } catch (ClassNotFoundException e) {
+ return null;
+ } catch (LinkageError e) {
+ LOG.warn("Class {} is present but cannot be loaded, treating it as absent", className, e);
+ return null;
+ }
+ }
+
/**
* Get the credential from the credential array. Using dynamic credential first, if not found,
* uses static credential.
diff --git a/bundles/aws/src/test/java/org/apache/gravitino/s3/fs/TestS3CredentialVending.java b/bundles/aws/src/test/java/org/apache/gravitino/s3/fs/TestS3CredentialVendingV1.java
similarity index 80%
rename from bundles/aws/src/test/java/org/apache/gravitino/s3/fs/TestS3CredentialVending.java
rename to bundles/aws/src/test/java/org/apache/gravitino/s3/fs/TestS3CredentialVendingV1.java
index 2d1adab78b..b685c69909 100644
--- a/bundles/aws/src/test/java/org/apache/gravitino/s3/fs/TestS3CredentialVending.java
+++ b/bundles/aws/src/test/java/org/apache/gravitino/s3/fs/TestS3CredentialVendingV1.java
@@ -34,8 +34,8 @@ import org.apache.hadoop.fs.s3a.Constants;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
-/** Tests the complete in-memory credential vending path for S3 credentials. */
-public class TestS3CredentialVending {
+/** Tests the complete in-memory credential vending path for S3 credentials with AWS SDK v1. */
+public class TestS3CredentialVendingV1 {
private static final URI S3_URI = URI.create("s3a://test-bucket/");
private static final long EXPIRATION_TIME = System.currentTimeMillis() + 60_000L;
@@ -77,7 +77,23 @@ public class TestS3CredentialVending {
Assertions.assertEquals("session-token", ((AWSSessionCredentials) actual).getSessionToken());
}
+ @Test
+ void testConfigurationOnlyConstructor() {
+ // The S3A connector of Hadoop 3.2 and earlier only looks up the (Configuration) constructor.
+ S3TokenCredential credential =
+ new S3TokenCredential("access-key", "secret-key", "session-token", EXPIRATION_TIME);
+ AWSCredentials actual = readCredential(credential, false);
+ Assertions.assertTrue(actual instanceof AWSSessionCredentials);
+ Assertions.assertEquals("access-key", actual.getAWSAccessKeyId());
+ Assertions.assertEquals("secret-key", actual.getAWSSecretKey());
+ Assertions.assertEquals("session-token", ((AWSSessionCredentials) actual).getSessionToken());
+ }
+
private AWSCredentials readCredential(Credential credential) {
+ return readCredential(credential, true);
+ }
+
+ private AWSCredentials readCredential(Credential credential, boolean withUri) {
Credential[] credentials = new Credential[] {credential};
String handle = InMemoryFileSystemCredentialsProvider.register(credentials);
try {
@@ -93,7 +109,9 @@ public class TestS3CredentialVending {
S3CredentialsProvider.class.getCanonicalName(),
conf.get(Constants.AWS_CREDENTIALS_PROVIDER));
- return new S3CredentialsProvider(S3_URI, conf).getCredentials();
+ S3CredentialsProvider provider =
+ withUri ? new S3CredentialsProvider(S3_URI, conf) : new S3CredentialsProvider(conf);
+ return provider.getCredentials();
} finally {
InMemoryFileSystemCredentialsProvider.unregister(handle);
}
diff --git a/bundles/aws/src/test/java/org/apache/gravitino/s3/fs/TestS3CredentialVendingV2.java b/bundles/aws/src/test/java/org/apache/gravitino/s3/fs/TestS3CredentialVendingV2.java
new file mode 100644
index 0000000000..e238b80c06
--- /dev/null
+++ b/bundles/aws/src/test/java/org/apache/gravitino/s3/fs/TestS3CredentialVendingV2.java
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.s3.fs;
+
+import java.net.URI;
+import org.apache.gravitino.catalog.hadoop.fs.GravitinoFileSystemCredentialsProvider;
+import org.apache.gravitino.catalog.hadoop.fs.InMemoryFileSystemCredentialsProvider;
+import org.apache.gravitino.credential.AwsIrsaCredential;
+import org.apache.gravitino.credential.Credential;
+import org.apache.gravitino.credential.S3SecretKeyCredential;
+import org.apache.gravitino.credential.S3TokenCredential;
+import org.apache.hadoop.conf.Configuration;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import software.amazon.awssdk.auth.credentials.AwsCredentials;
+import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
+
+/** Tests the complete in-memory credential vending path for S3 credentials with AWS SDK v2. */
+public class TestS3CredentialVendingV2 {
+
+ private static final URI S3_URI = URI.create("s3a://test-bucket/");
+ private static final long EXPIRATION_TIME = System.currentTimeMillis() + 60_000L;
+
+ @Test
+ void testSecretKeyCredential() {
+ S3SecretKeyCredential credential = new S3SecretKeyCredential("access-key", "secret-key");
+ AwsCredentials actual = readCredential(credential);
+
+ Assertions.assertEquals("access-key", actual.accessKeyId());
+ Assertions.assertEquals("secret-key", actual.secretAccessKey());
+ Assertions.assertFalse(actual instanceof AwsSessionCredentials);
+ }
+
+ @Test
+ void testTokenCredential() {
+ S3TokenCredential credential =
+ new S3TokenCredential("access-key", "secret-key", "session-token", EXPIRATION_TIME);
+ AwsCredentials actual = readCredential(credential);
+
+ Assertions.assertTrue(actual instanceof AwsSessionCredentials);
+ Assertions.assertEquals("access-key", actual.accessKeyId());
+ Assertions.assertEquals("secret-key", actual.secretAccessKey());
+ Assertions.assertEquals("session-token", ((AwsSessionCredentials) actual).sessionToken());
+ }
+
+ @Test
+ void testIrsaCredential() {
+ AwsIrsaCredential credential =
+ new AwsIrsaCredential("access-key", "secret-key", "session-token", EXPIRATION_TIME);
+ AwsCredentials actual = readCredential(credential);
+
+ Assertions.assertTrue(actual instanceof AwsSessionCredentials);
+ Assertions.assertEquals("access-key", actual.accessKeyId());
+ Assertions.assertEquals("secret-key", actual.secretAccessKey());
+ Assertions.assertEquals("session-token", ((AwsSessionCredentials) actual).sessionToken());
+ }
+
+ private AwsCredentials readCredential(Credential credential) {
+ Credential[] credentials = new Credential[] {credential};
+ String handle = InMemoryFileSystemCredentialsProvider.register(credentials);
+ try {
+ Configuration conf = new Configuration(false);
+ conf.set(
+ GravitinoFileSystemCredentialsProvider.GVFS_CREDENTIAL_PROVIDER,
+ InMemoryFileSystemCredentialsProvider.class.getCanonicalName());
+ conf.set(InMemoryFileSystemCredentialsProvider.CREDENTIAL_HANDLE, handle);
+ return new S3CredentialsProviderV2(S3_URI, conf).resolveCredentials();
+ } finally {
+ InMemoryFileSystemCredentialsProvider.unregister(handle);
+ }
+ }
+}
diff --git a/bundles/aws/src/test/java/org/apache/gravitino/s3/fs/TestS3CredentialsProviderHadoopBinding.java b/bundles/aws/src/test/java/org/apache/gravitino/s3/fs/TestS3CredentialsProviderHadoopBinding.java
new file mode 100644
index 0000000000..12db2b2b72
--- /dev/null
+++ b/bundles/aws/src/test/java/org/apache/gravitino/s3/fs/TestS3CredentialsProviderHadoopBinding.java
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.s3.fs;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.Map;
+import org.apache.gravitino.catalog.hadoop.fs.GravitinoFileSystemCredentialsProvider;
+import org.apache.gravitino.catalog.hadoop.fs.InMemoryFileSystemCredentialsProvider;
+import org.apache.gravitino.credential.Credential;
+import org.apache.gravitino.credential.S3SecretKeyCredential;
+import org.apache.gravitino.credential.S3TokenCredential;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.s3a.AWSCredentialProviderList;
+import org.apache.hadoop.fs.s3a.auth.CredentialProviderListFactory;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import software.amazon.awssdk.auth.credentials.AwsCredentials;
+import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
+
+/**
+ * Checks that the S3A connector of Hadoop 3.4 creates the provider that {@link
+ * S3FileSystemProvider} vends and reads the Gravitino credentials from it.
+ */
+public class TestS3CredentialsProviderHadoopBinding {
+
+ private static final URI S3_URI = URI.create("s3a://test-bucket/");
+
+ @Test
+ void testSecretKeyCredential() throws IOException {
+ AwsCredentials actual =
+ resolveWithHadoop(new S3SecretKeyCredential("access-key", "secret-key"));
+
+ Assertions.assertEquals("access-key", actual.accessKeyId());
+ Assertions.assertEquals("secret-key", actual.secretAccessKey());
+ Assertions.assertFalse(actual instanceof AwsSessionCredentials);
+ }
+
+ @Test
+ void testTokenCredential() throws IOException {
+ AwsCredentials actual =
+ resolveWithHadoop(
+ new S3TokenCredential(
+ "access-key", "secret-key", "session-token", System.currentTimeMillis() + 60_000L));
+
+ Assertions.assertTrue(actual instanceof AwsSessionCredentials);
+ Assertions.assertEquals("access-key", actual.accessKeyId());
+ Assertions.assertEquals("secret-key", actual.secretAccessKey());
+ Assertions.assertEquals("session-token", ((AwsSessionCredentials) actual).sessionToken());
+ }
+
+ private AwsCredentials resolveWithHadoop(Credential credential) throws IOException {
+ Credential[] credentials = new Credential[] {credential};
+ String handle = InMemoryFileSystemCredentialsProvider.register(credentials);
+ try {
+ Configuration conf = new Configuration(false);
+ Map<String, String> credentialConf =
+ new S3FileSystemProvider().getFileSystemCredentialConf(credentials);
+ credentialConf.forEach(conf::set);
+ conf.set(
+ GravitinoFileSystemCredentialsProvider.GVFS_CREDENTIAL_PROVIDER,
+ InMemoryFileSystemCredentialsProvider.class.getCanonicalName());
+ conf.set(InMemoryFileSystemCredentialsProvider.CREDENTIAL_HANDLE, handle);
+ Assertions.assertEquals(
+ S3CredentialsProviderV2.class.getCanonicalName(),
+ conf.get("fs.s3a.aws.credentials.provider"));
+
+ try (AWSCredentialProviderList providers =
+ CredentialProviderListFactory.createAWSCredentialProviderList(S3_URI, conf)) {
+ return providers.resolveCredentials();
+ }
+ } finally {
+ InMemoryFileSystemCredentialsProvider.unregister(handle);
+ }
+ }
+}
diff --git a/bundles/aws/src/test/java/org/apache/gravitino/s3/fs/TestS3CredentialsProviderSelection.java b/bundles/aws/src/test/java/org/apache/gravitino/s3/fs/TestS3CredentialsProviderSelection.java
new file mode 100644
index 0000000000..645ae411ad
--- /dev/null
+++ b/bundles/aws/src/test/java/org/apache/gravitino/s3/fs/TestS3CredentialsProviderSelection.java
@@ -0,0 +1,202 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.s3.fs;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.gravitino.credential.AwsIrsaCredential;
+import org.apache.gravitino.credential.Credential;
+import org.apache.gravitino.credential.S3SecretKeyCredential;
+import org.apache.gravitino.credential.S3TokenCredential;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests how {@link S3FileSystemProvider} picks and validates the S3A credentials provider. The
+ * expected AWS SDK is passed by the build in the system property {@code s3a.expectedSdk}: "v1" when
+ * the classpath carries Hadoop 3.3, "v2" when it carries Hadoop 3.4 or later.
+ */
+public class TestS3CredentialsProviderSelection {
+
+ private static final String CREDENTIAL_KEY = "fs.s3a.aws.credentials.provider";
+ private static final String SIMPLE = "org.apache.hadoop.fs.s3a.SimpleAWSCredentialsProvider";
+ private static final String ANONYMOUS =
+ "org.apache.hadoop.fs.s3a.AnonymousAWSCredentialsProvider";
+ private static final String V1_ENVIRONMENT =
+ "com.amazonaws.auth.EnvironmentVariableCredentialsProvider";
+ private static final String V2_ENVIRONMENT =
+ "software.amazon.awssdk.auth.credentials.EnvironmentVariableCredentialsProvider";
+
+ private static final String V1_INTERFACE = "com.amazonaws.auth.AWSCredentialsProvider";
+ private static final String V2_INTERFACE =
+ "software.amazon.awssdk.auth.credentials.AwsCredentialsProvider";
+
+ private static final boolean EXPECT_V2 = "v2".equals(System.getProperty("s3a.expectedSdk"));
+
+ private final S3FileSystemProvider provider = new S3FileSystemProvider();
+
+ @Test
+ void testExpectedSdkIsConfigured() {
+ String expected = System.getProperty("s3a.expectedSdk");
+ Assertions.assertTrue("v1".equals(expected) || "v2".equals(expected), "s3a.expectedSdk");
+ }
+
+ @Test
+ void testHadoopSdkDetection() {
+ Assertions.assertEquals(EXPECT_V2, S3Utils.isHadoopAwsSdkV2());
+ }
+
+ @Test
+ void testProviderClassNamesMatchTheClasses() throws ClassNotFoundException {
+ // Only the classes of the SDK in use can be loaded.
+ if (EXPECT_V2) {
+ Assertions.assertEquals(
+ S3CredentialsProviderV2.class.getName(), S3FileSystemProvider.S3_CREDENTIALS_PROVIDER_V2);
+ Assertions.assertTrue(S3Utils.isCredentialsProvider(S3CredentialsProviderV2.class));
+ } else {
+ Assertions.assertEquals(
+ S3CredentialsProvider.class.getName(), S3FileSystemProvider.S3_CREDENTIALS_PROVIDER_V1);
+ Assertions.assertTrue(S3Utils.isCredentialsProvider(S3CredentialsProvider.class));
+ }
+ }
+
+ @Test
+ void testVendedProviderMatchesHadoopSdk() {
+ String expected =
+ EXPECT_V2
+ ? S3FileSystemProvider.S3_CREDENTIALS_PROVIDER_V2
+ : S3FileSystemProvider.S3_CREDENTIALS_PROVIDER_V1;
+ Credential[] secretKey = {new S3SecretKeyCredential("access-key", "secret-key")};
+ Credential[] token = {
+ new S3TokenCredential("access-key", "secret-key", "token", System.currentTimeMillis() + 1000)
+ };
+ Credential[] irsa = {
+ new AwsIrsaCredential("access-key", "secret-key", "token", System.currentTimeMillis() + 1000)
+ };
+
+ for (Credential[] credentials : new Credential[][] {secretKey, token, irsa}) {
+ Assertions.assertEquals(
+ expected, provider.getFileSystemCredentialConf(credentials).get(CREDENTIAL_KEY));
+ }
+ }
+
+ @Test
+ void testNoVendedProviderWithoutS3Credential() {
+ Assertions.assertTrue(provider.getFileSystemCredentialConf(new Credential[0]).isEmpty());
+ }
+
+ @Test
+ void testValidProvidersAreKept() {
+ Assertions.assertEquals(SIMPLE, check(SIMPLE));
+ Assertions.assertEquals(ANONYMOUS, check(ANONYMOUS));
+ Assertions.assertEquals(SIMPLE + "," + ANONYMOUS, check(SIMPLE + ", " + ANONYMOUS));
+ }
+
+ @Test
+ void testAwsSdkV1ProviderNamesAreKept() {
+ // Hadoop 3.4+ maps these names to AWS SDK v2 providers even without the AWS SDK v1, and Hadoop
+ // 3.3 loads them from the AWS SDK v1. They must not be replaced in either case.
+ Assertions.assertEquals(V1_ENVIRONMENT, check(V1_ENVIRONMENT));
+ Assertions.assertEquals(SIMPLE + "," + V1_ENVIRONMENT, check(SIMPLE + "," + V1_ENVIRONMENT));
+ }
+
+ @Test
+ void testAwsSdkV2ProviderName() {
+ // Hadoop 3.3 cannot use AWS SDK v2 providers, even when the AWS SDK v2 is on the classpath.
+ Assertions.assertEquals(EXPECT_V2 ? V2_ENVIRONMENT : SIMPLE, check(V2_ENVIRONMENT));
+ }
+
+ @Test
+ void testVendedProviderOfAnotherSdk() {
+ if (EXPECT_V2) {
+ // Hadoop 3.4+ adapts AWS SDK v1 providers, which needs the AWS SDK v1 on the classpath.
+ Assertions.assertEquals(
+ isPresent(V1_INTERFACE) ? S3FileSystemProvider.S3_CREDENTIALS_PROVIDER_V1 : SIMPLE,
+ check(S3FileSystemProvider.S3_CREDENTIALS_PROVIDER_V1));
+ } else {
+ // Hadoop 3.3 only uses AWS SDK v1 providers.
+ Assertions.assertEquals(SIMPLE, check(S3FileSystemProvider.S3_CREDENTIALS_PROVIDER_V2));
+ }
+ }
+
+ @Test
+ void testExpectedSdkClassesOnClasspath() {
+ // Guards the classpath of each test task, so that the checks above cover what they claim.
+ Assertions.assertEquals(expectedOnClasspath("s3a.sdkV1OnClasspath"), isPresent(V1_INTERFACE));
+ Assertions.assertEquals(expectedOnClasspath("s3a.sdkV2OnClasspath"), isPresent(V2_INTERFACE));
+ }
+
+ private static boolean expectedOnClasspath(String property) {
+ String value = System.getProperty(property);
+ Assertions.assertNotNull(value, property);
+ return Boolean.parseBoolean(value);
+ }
+
+ @Test
+ void testUnknownProviderFallsBackToDefault() {
+ Assertions.assertEquals(SIMPLE, check("com.example.DoesNotExist"));
+ Assertions.assertEquals(SIMPLE, check(SIMPLE + ",com.example.DoesNotExist"));
+ }
+
+ @Test
+ void testProviderThatFailsToInitializeFallsBackToDefault() {
+ // The class exists, but initializing it throws an ExceptionInInitializerError (a LinkageError),
+ // like a provider that depends on an incompatible library.
+ String broken = BrokenProvider.class.getName();
+ Assertions.assertEquals(SIMPLE, check(broken));
+ Assertions.assertEquals(SIMPLE, check(SIMPLE + "," + broken));
+ }
+
+ @Test
+ void testClassThatIsNotAProviderFallsBackToDefault() {
+ Assertions.assertEquals(SIMPLE, check("java.lang.String"));
+ }
+
+ @Test
+ void testMissingKeyIsLeftUntouched() {
+ Map<String, String> configs = new HashMap<>();
+ provider.checkAndSetCredentialProvider(configs);
+ Assertions.assertTrue(configs.isEmpty());
+ }
+
+ private static boolean isPresent(String className) {
+ try {
+ Class.forName(className);
+ return true;
+ } catch (ClassNotFoundException | LinkageError e) {
+ return false;
+ }
+ }
+
+ private String check(String providers) {
+ Map<String, String> configs = new HashMap<>();
+ configs.put(CREDENTIAL_KEY, providers);
+ provider.checkAndSetCredentialProvider(configs);
+ return configs.get(CREDENTIAL_KEY);
+ }
+
+ /** A class whose static initializer always fails. */
+ static class BrokenProvider {
+ static {
+ if (System.nanoTime() != 0) {
+ throw new IllegalStateException("Broken on purpose");
+ }
+ }
+ }
+}
diff --git a/bundles/aws/src/test/java/org/apache/gravitino/s3/fs/TestS3CredentialsRefresher.java b/bundles/aws/src/test/java/org/apache/gravitino/s3/fs/TestS3CredentialsRefresher.java
new file mode 100644
index 0000000000..37306ea156
--- /dev/null
+++ b/bundles/aws/src/test/java/org/apache/gravitino/s3/fs/TestS3CredentialsRefresher.java
@@ -0,0 +1,203 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.s3.fs;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.gravitino.catalog.hadoop.fs.GravitinoFileSystemCredentialsProvider;
+import org.apache.gravitino.credential.Credential;
+import org.apache.gravitino.credential.S3SecretKeyCredential;
+import org.apache.gravitino.credential.S3TokenCredential;
+import org.apache.gravitino.s3.fs.S3CredentialsRefresher.S3Credentials;
+import org.apache.hadoop.conf.Configuration;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/** Tests the refresh and expiration logic shared by the AWS SDK v1 and v2 credential providers. */
+public class TestS3CredentialsRefresher {
+
+ private static final List<Credential> SERVED = new ArrayList<>();
+ private static final AtomicInteger FETCHES = new AtomicInteger();
+ private static volatile long fetchDelayMs;
+
+ @BeforeEach
+ void setUp() {
+ SERVED.clear();
+ FETCHES.set(0);
+ fetchDelayMs = 0;
+ }
+
+ @AfterEach
+ void tearDown() {
+ SERVED.clear();
+ }
+
+ @Test
+ void testCredentialWithoutExpirationIsFetchedOnce() {
+ SERVED.add(new S3SecretKeyCredential("access-key", "secret-key"));
+ S3CredentialsRefresher refresher = newRefresher();
+
+ S3Credentials first = refresher.getCredentials();
+ S3Credentials second = refresher.getCredentials();
+
+ Assertions.assertEquals(1, FETCHES.get());
+ Assertions.assertEquals("access-key", first.accessKeyId());
+ Assertions.assertEquals("secret-key", first.secretAccessKey());
+ Assertions.assertNull(first.sessionToken());
+ Assertions.assertSame(first, second);
+ }
+
+ @Test
+ void testExplicitRefreshFetchesAgain() {
+ SERVED.add(new S3SecretKeyCredential("access-key-1", "secret-key-1"));
+ S3CredentialsRefresher refresher = newRefresher();
+ Assertions.assertEquals("access-key-1", refresher.getCredentials().accessKeyId());
+
+ SERVED.set(0, new S3SecretKeyCredential("access-key-2", "secret-key-2"));
+ refresher.refresh();
+
+ Assertions.assertEquals(2, FETCHES.get());
+ Assertions.assertEquals("access-key-2", refresher.getCredentials().accessKeyId());
+ Assertions.assertEquals(2, FETCHES.get());
+ }
+
+ @Test
+ void testExpiredCredentialIsRefreshed() {
+ SERVED.add(
+ new S3TokenCredential(
+ "access-key-1", "secret-key-1", "token-1", System.currentTimeMillis() - 1000L));
+ S3CredentialsRefresher refresher = newRefresher();
+ Assertions.assertEquals("token-1", refresher.getCredentials().sessionToken());
+ Assertions.assertEquals(1, FETCHES.get());
+
+ SERVED.set(
+ 0,
+ new S3TokenCredential(
+ "access-key-2", "secret-key-2", "token-2", System.currentTimeMillis() + 3_600_000L));
+ S3Credentials refreshed = refresher.getCredentials();
+
+ Assertions.assertEquals(2, FETCHES.get());
+ Assertions.assertEquals("access-key-2", refreshed.accessKeyId());
+ Assertions.assertEquals("token-2", refreshed.sessionToken());
+
+ // The new credential is valid for another hour, so it is served from the cache.
+ Assertions.assertSame(refreshed, refresher.getCredentials());
+ Assertions.assertEquals(2, FETCHES.get());
+ }
+
+ @Test
+ void testRefreshesAtHalfOfTheLifetime() {
+ long lifetimeMs = 100_000L;
+ long before = System.currentTimeMillis();
+ SERVED.add(new S3TokenCredential("access-key", "secret-key", "token", before + lifetimeMs));
+ S3CredentialsRefresher refresher = newRefresher();
+ refresher.getCredentials();
+ long after = System.currentTimeMillis();
+
+ long refreshTime = refresher.expirationTime();
+ Assertions.assertTrue(refreshTime >= before + lifetimeMs / 2 - 1000L);
+ Assertions.assertTrue(refreshTime <= after + lifetimeMs / 2);
+ // Not refreshed yet.
+ refresher.getCredentials();
+ Assertions.assertEquals(1, FETCHES.get());
+ }
+
+ @Test
+ void testConcurrentCallersFetchOnce() throws Exception {
+ SERVED.add(
+ new S3TokenCredential(
+ "access-key", "secret-key", "token", System.currentTimeMillis() + 3_600_000L));
+ // Keep the first fetch running while the other callers wait for the lock.
+ fetchDelayMs = 200;
+ S3CredentialsRefresher refresher = newRefresher();
+ int callers = 8;
+ CountDownLatch start = new CountDownLatch(1);
+ ExecutorService executor = Executors.newFixedThreadPool(callers);
+ try {
+ List<Future<S3Credentials>> results = new ArrayList<>();
+ for (int i = 0; i < callers; i++) {
+ results.add(
+ executor.submit(
+ () -> {
+ start.await();
+ return refresher.getCredentials();
+ }));
+ }
+ start.countDown();
+ for (Future<S3Credentials> result : results) {
+ Assertions.assertEquals("token", result.get(30, TimeUnit.SECONDS).sessionToken());
+ }
+ } finally {
+ executor.shutdownNow();
+ }
+ Assertions.assertEquals(1, FETCHES.get());
+ }
+
+ @Test
+ void testNoSuitableCredential() {
+ S3CredentialsRefresher refresher = newRefresher();
+
+ RuntimeException e = Assertions.assertThrows(RuntimeException.class, refresher::getCredentials);
+ Assertions.assertTrue(e.getMessage().contains("No suitable credential for S3"));
+ }
+
+ private S3CredentialsRefresher newRefresher() {
+ Configuration conf = new Configuration(false);
+ conf.set(
+ GravitinoFileSystemCredentialsProvider.GVFS_CREDENTIAL_PROVIDER,
+ ListCredentialsProvider.class.getName());
+ return new S3CredentialsRefresher(conf);
+ }
+
+ /** Serves the credentials registered in {@link #SERVED} and counts the fetches. */
+ public static class ListCredentialsProvider implements GravitinoFileSystemCredentialsProvider {
+ private Configuration conf;
+
+ @Override
+ public Credential[] getCredentials() {
+ FETCHES.incrementAndGet();
+ if (fetchDelayMs > 0) {
+ try {
+ Thread.sleep(fetchDelayMs);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
+ }
+ return SERVED.toArray(new Credential[0]);
+ }
+
+ @Override
+ public void setConf(Configuration conf) {
+ this.conf = conf;
+ }
+
+ @Override
+ public Configuration getConf() {
+ return conf;
+ }
+ }
+}
diff --git a/bundles/aws/src/test/java/org/apache/gravitino/s3/fs/TestS3FileSystemProviderConfig.java b/bundles/aws/src/test/java/org/apache/gravitino/s3/fs/TestS3FileSystemProviderConfig.java
new file mode 100644
index 0000000000..e596895c8d
--- /dev/null
+++ b/bundles/aws/src/test/java/org/apache/gravitino/s3/fs/TestS3FileSystemProviderConfig.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.s3.fs;
+
+import java.util.Map;
+import org.apache.gravitino.catalog.hadoop.fs.Constants;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+/** Tests the S3A settings that {@link S3FileSystemProvider} adds to the user configuration. */
+public class TestS3FileSystemProviderConfig {
+
+ private final S3FileSystemProvider provider = new S3FileSystemProvider();
+
+ @Test
+ void testDirectoryMarkersAreDeletedByDefault() {
+ Map<String, String> configs = provider.additionalS3Config(Map.of());
+
+ Assertions.assertEquals("delete", configs.get(Constants.S3_DIRECTORY_MARKER_RETENTION));
+ }
+
+ @Test
+ void testUserDirectoryMarkerPolicyIsKept() {
+ Map<String, String> configs =
+ provider.additionalS3Config(Map.of(Constants.S3_DIRECTORY_MARKER_RETENTION, "keep"));
+
+ Assertions.assertEquals("keep", configs.get(Constants.S3_DIRECTORY_MARKER_RETENTION));
+ }
+
+ @Test
+ void testDefaultRetries() {
+ Map<String, String> configs =
+ provider.additionalS3Config(Map.of(Constants.S3_RETRY_LIMIT, "5"));
+
+ Assertions.assertEquals("5", configs.get(Constants.S3_RETRY_LIMIT));
+ Assertions.assertEquals(
+ Constants.DEFAULT_RETRY_LIMIT, configs.get(Constants.S3_MAX_ERROR_RETRIES));
+ Assertions.assertEquals(
+ Constants.DEFAULT_RETRY_LIMIT, configs.get(Constants.S3_RETRY_THROTTLE_LIMIT));
+ Assertions.assertEquals(
+ Constants.DEFAULT_CONNECTION_TIMEOUT, configs.get(Constants.S3_ESTABLISH_TIMEOUT));
+ }
+}
diff --git a/bundles/azure-bundle/build.gradle.kts b/bundles/azure-bundle/build.gradle.kts
index b2574b544b..ce075d11bd 100644
--- a/bundles/azure-bundle/build.gradle.kts
+++ b/bundles/azure-bundle/build.gradle.kts
@@ -33,6 +33,9 @@ dependencies {
implementation(libs.azure.identity)
implementation(libs.azure.storage.file.datalake)
+ // hadoop-azure 3.4 uses Commons IO (workload identity, identity mapping and the blob endpoint
+ // client), which hadoop-client-runtime shades for its own use only.
+ implementation(libs.commons.io)
implementation(libs.hadoop3.abs)
implementation(libs.hadoop3.client.api)
implementation(libs.hadoop3.client.runtime)
diff --git a/bundles/azure-bundle/src/test/java/org/apache/gravitino/bundles/TestAzureBundleConnectorLinkage.java b/bundles/azure-bundle/src/test/java/org/apache/gravitino/bundles/TestAzureBundleConnectorLinkage.java
new file mode 100644
index 0000000000..cbb14839e3
--- /dev/null
+++ b/bundles/azure-bundle/src/test/java/org/apache/gravitino/bundles/TestAzureBundleConnectorLinkage.java
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.bundles;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.DataInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Checks that the ABFS and WASB connectors in the Azure bundle only links against relocated classes
+ * that the bundle contains. A relocated class can only come from the bundle itself, so a missing
+ * one fails with a {@link NoClassDefFoundError} at runtime, for example when a new Hadoop release
+ * starts to use a library that the bundle does not package.
+ */
+class TestAzureBundleConnectorLinkage {
+ private static final File BUNDLE = new File(System.getProperty("shadowJarPath"));
+ private static final String CONNECTOR = "org/apache/hadoop/fs/azure";
+ private static final String RELOCATED = "org/apache/gravitino/azure/shaded/";
+
+ @Test
+ void testRelocatedReferencesAreBundled() throws IOException {
+ Map<String, Set<String>> missing = new TreeMap<>();
+ try (JarFile jar = new JarFile(BUNDLE)) {
+ Set<String> bundled = new TreeSet<>();
+ jar.stream().map(JarEntry::getName).forEach(bundled::add);
+ for (JarEntry entry : (Iterable<JarEntry>) jar.stream()::iterator) {
+ String name = entry.getName();
+ if (!name.startsWith(CONNECTOR) || !name.endsWith(".class")) {
+ continue;
+ }
+ try (InputStream in = jar.getInputStream(entry)) {
+ for (String reference : referencedClasses(in)) {
+ if (reference.startsWith(RELOCATED) && !bundled.contains(reference + ".class")) {
+ missing.computeIfAbsent(reference, k -> new TreeSet<>()).add(name);
+ }
+ }
+ }
+ }
+ }
+ assertTrue(missing.isEmpty(), "Relocated classes missing from the bundle: " + missing);
+ }
+
+ /** Returns the classes in the constant pool of a class file, as internal names. */
+ private static Set<String> referencedClasses(InputStream classFile) throws IOException {
+ DataInputStream in = new DataInputStream(classFile);
+ in.readInt(); // magic
+ in.readUnsignedShort(); // minor version
+ in.readUnsignedShort(); // major version
+ int count = in.readUnsignedShort();
+ String[] utf8 = new String[count];
+ int[] classNames = new int[count];
+ for (int i = 1; i < count; i++) {
+ int tag = in.readUnsignedByte();
+ switch (tag) {
+ case 1: // Utf8
+ utf8[i] = in.readUTF();
+ break;
+ case 7: // Class
+ classNames[i] = in.readUnsignedShort();
+ break;
+ case 8: // String
+ case 16: // MethodType
+ case 19: // Module
+ case 20: // Package
+ in.readUnsignedShort();
+ break;
+ case 15: // MethodHandle
+ in.readUnsignedByte();
+ in.readUnsignedShort();
+ break;
+ case 3: // Integer
+ case 4: // Float
+ case 9: // Fieldref
+ case 10: // Methodref
+ case 11: // InterfaceMethodref
+ case 12: // NameAndType
+ case 17: // Dynamic
+ case 18: // InvokeDynamic
+ in.readInt();
+ break;
+ case 5: // Long
+ case 6: // Double
+ in.readLong();
+ i++;
+ break;
+ default:
+ throw new IOException("Unknown constant pool tag " + tag);
+ }
+ }
+ Set<String> classes = new TreeSet<>();
+ for (int index : classNames) {
+ if (index != 0) {
+ // Array classes are written as descriptors, for example [Lorg/example/Type;.
+ classes.add(utf8[index].replaceFirst("^\\[+L?", "").replaceFirst(";$", ""));
+ }
+ }
+ return classes;
+ }
+}
diff --git a/bundles/azure-bundle/src/test/java/org/apache/gravitino/bundles/TestAzureBundleShadedLibraries.java b/bundles/azure-bundle/src/test/java/org/apache/gravitino/bundles/TestAzureBundleShadedLibraries.java
new file mode 100644
index 0000000000..6bf3863d9e
--- /dev/null
+++ b/bundles/azure-bundle/src/test/java/org/apache/gravitino/bundles/TestAzureBundleShadedLibraries.java
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.bundles;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.File;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Checks the libraries that hadoop-client-runtime shades into the azure bundle. Hadoop 3.3 shaded
+ * Avro 1.7.7 and protobuf 3.7.1, Hadoop 3.4.3 ships Avro 1.11.4 and protobuf 3.25.
+ */
+class TestAzureBundleShadedLibraries {
+
+ private static final File BUNDLE = new File(System.getProperty("shadowJarPath"));
+
+ @Test
+ void testAvroIsNotOutdated() throws Exception {
+ for (String version : versionsOf("META-INF/maven/org.apache.avro/avro/pom.properties")) {
+ assertTrue(compare(version, "1.11.4") >= 0, "Outdated Avro " + version);
+ }
+ }
+
+ @Test
+ void testProtobufIsNotOutdated() throws Exception {
+ assertTrue(
+ versionsOf(
+ "META-INF/maven/org.apache.hadoop.thirdparty/hadoop-shaded-protobuf_3_7/pom.properties")
+ .isEmpty(),
+ "hadoop-shaded-protobuf_3_7 is outdated");
+ for (String version :
+ versionsOf("META-INF/maven/com.google.protobuf/protobuf-java/pom.properties")) {
+ assertTrue(compare(version, "3.25.0") >= 0, "Outdated protobuf " + version);
+ }
+ try (JarFile jar = new JarFile(BUNDLE)) {
+ assertFalse(
+ jar.stream()
+ .anyMatch(
+ e -> e.getName().startsWith("org/apache/hadoop/shaded/com/google/protobuf/")),
+ "Protobuf 3.7 is shaded under org/apache/hadoop/shaded");
+ }
+ }
+
+ private static List<String> versionsOf(String propertiesEntry) throws Exception {
+ List<String> versions = new ArrayList<>();
+ try (JarFile jar = new JarFile(BUNDLE)) {
+ for (JarEntry entry : (Iterable<JarEntry>) jar.stream()::iterator) {
+ if (entry.getName().equals(propertiesEntry)) {
+ Properties properties = new Properties();
+ try (InputStream in = jar.getInputStream(entry)) {
+ properties.load(in);
+ }
+ versions.add(properties.getProperty("version"));
+ }
+ }
+ }
+ return versions;
+ }
+
+ private static int compare(String version, String minimum) {
+ String[] left = version.split("[.-]");
+ String[] right = minimum.split("[.-]");
+ for (int i = 0; i < right.length; i++) {
+ int l = i < left.length ? Integer.parseInt(left[i]) : 0;
+ int r = Integer.parseInt(right[i]);
+ if (l != r) {
+ return Integer.compare(l, r);
+ }
+ }
+ return 0;
+ }
+}
diff --git a/bundles/gcp-bundle/build.gradle.kts b/bundles/gcp-bundle/build.gradle.kts
index cc0f2e1d7a..cee11a0897 100644
--- a/bundles/gcp-bundle/build.gradle.kts
+++ b/bundles/gcp-bundle/build.gradle.kts
@@ -34,6 +34,8 @@ dependencies {
implementation(libs.hadoop3.client.api)
implementation(libs.hadoop3.client.runtime)
implementation(libs.hadoop3.gcs)
+ testImplementation(libs.junit.jupiter.api)
+ testRuntimeOnly(libs.junit.jupiter.engine)
}
tasks.withType(ShadowJar::class.java) {
@@ -83,3 +85,10 @@ tasks.jar {
tasks.compileJava {
dependsOn(":catalogs:catalog-fileset:runtimeJars")
}
+
+tasks.test {
+ val bundle = tasks.named<ShadowJar>("shadowJar")
+ dependsOn(bundle)
+ inputs.file(bundle.flatMap { it.archiveFile })
+ doFirst { systemProperty("shadowJarPath", bundle.get().archiveFile.get().asFile.absolutePath) }
+}
diff --git a/bundles/gcp-bundle/src/test/java/org/apache/gravitino/bundles/TestGcpBundleShadedLibraries.java b/bundles/gcp-bundle/src/test/java/org/apache/gravitino/bundles/TestGcpBundleShadedLibraries.java
new file mode 100644
index 0000000000..1e39b7de62
--- /dev/null
+++ b/bundles/gcp-bundle/src/test/java/org/apache/gravitino/bundles/TestGcpBundleShadedLibraries.java
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.bundles;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.File;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Checks the libraries that hadoop-client-runtime shades into the gcp bundle. Hadoop 3.3 shaded
+ * Avro 1.7.7 and protobuf 3.7.1, Hadoop 3.4.3 ships Avro 1.11.4 and protobuf 3.25.
+ */
+class TestGcpBundleShadedLibraries {
+
+ private static final File BUNDLE = new File(System.getProperty("shadowJarPath"));
+
+ @Test
+ void testAvroIsNotOutdated() throws Exception {
+ for (String version : versionsOf("META-INF/maven/org.apache.avro/avro/pom.properties")) {
+ assertTrue(compare(version, "1.11.4") >= 0, "Outdated Avro " + version);
+ }
+ }
+
+ @Test
+ void testProtobufIsNotOutdated() throws Exception {
+ assertTrue(
+ versionsOf(
+ "META-INF/maven/org.apache.hadoop.thirdparty/hadoop-shaded-protobuf_3_7/pom.properties")
+ .isEmpty(),
+ "hadoop-shaded-protobuf_3_7 is outdated");
+ for (String version :
+ versionsOf("META-INF/maven/com.google.protobuf/protobuf-java/pom.properties")) {
+ assertTrue(compare(version, "3.25.0") >= 0, "Outdated protobuf " + version);
+ }
+ try (JarFile jar = new JarFile(BUNDLE)) {
+ assertFalse(
+ jar.stream()
+ .anyMatch(
+ e -> e.getName().startsWith("org/apache/hadoop/shaded/com/google/protobuf/")),
+ "Protobuf 3.7 is shaded under org/apache/hadoop/shaded");
+ }
+ }
+
+ private static List<String> versionsOf(String propertiesEntry) throws Exception {
+ List<String> versions = new ArrayList<>();
+ try (JarFile jar = new JarFile(BUNDLE)) {
+ for (JarEntry entry : (Iterable<JarEntry>) jar.stream()::iterator) {
+ if (entry.getName().equals(propertiesEntry)) {
+ Properties properties = new Properties();
+ try (InputStream in = jar.getInputStream(entry)) {
+ properties.load(in);
+ }
+ versions.add(properties.getProperty("version"));
+ }
+ }
+ }
+ return versions;
+ }
+
+ private static int compare(String version, String minimum) {
+ String[] left = version.split("[.-]");
+ String[] right = minimum.split("[.-]");
+ for (int i = 0; i < right.length; i++) {
+ int l = i < left.length ? Integer.parseInt(left[i]) : 0;
+ int r = Integer.parseInt(right[i]);
+ if (l != r) {
+ return Integer.compare(l, r);
+ }
+ }
+ return 0;
+ }
+}
diff --git a/bundles/tencent-bundle/build.gradle.kts b/bundles/tencent-bundle/build.gradle.kts
index 209a7200d2..820669b378 100644
--- a/bundles/tencent-bundle/build.gradle.kts
+++ b/bundles/tencent-bundle/build.gradle.kts
@@ -37,6 +37,8 @@ dependencies {
implementation(libs.hadoop3.cos)
implementation(libs.httpclient)
implementation(libs.tencentcloud.sdk.sts)
+ testImplementation(libs.junit.jupiter.api)
+ testRuntimeOnly(libs.junit.jupiter.engine)
}
tasks.withType(ShadowJar::class.java) {
@@ -81,3 +83,10 @@ tasks.jar {
tasks.compileJava {
dependsOn(":catalogs:catalog-fileset:runtimeJars")
}
+
+tasks.test {
+ val bundle = tasks.named<ShadowJar>("shadowJar")
+ dependsOn(bundle)
+ inputs.file(bundle.flatMap { it.archiveFile })
+ doFirst { systemProperty("shadowJarPath", bundle.get().archiveFile.get().asFile.absolutePath) }
+}
diff --git a/bundles/tencent-bundle/src/test/java/org/apache/gravitino/bundles/TestTencentBundleShadedLibraries.java b/bundles/tencent-bundle/src/test/java/org/apache/gravitino/bundles/TestTencentBundleShadedLibraries.java
new file mode 100644
index 0000000000..723feee132
--- /dev/null
+++ b/bundles/tencent-bundle/src/test/java/org/apache/gravitino/bundles/TestTencentBundleShadedLibraries.java
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.bundles;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.File;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Checks the libraries that hadoop-client-runtime shades into the tencent bundle. Hadoop 3.3 shaded
+ * Avro 1.7.7 and protobuf 3.7.1, Hadoop 3.4.3 ships Avro 1.11.4 and protobuf 3.25.
+ */
+class TestTencentBundleShadedLibraries {
+
+ private static final File BUNDLE = new File(System.getProperty("shadowJarPath"));
+
+ @Test
+ void testAvroIsNotOutdated() throws Exception {
+ for (String version : versionsOf("META-INF/maven/org.apache.avro/avro/pom.properties")) {
+ assertTrue(compare(version, "1.11.4") >= 0, "Outdated Avro " + version);
+ }
+ }
+
+ @Test
+ void testProtobufIsNotOutdated() throws Exception {
+ assertTrue(
+ versionsOf(
+ "META-INF/maven/org.apache.hadoop.thirdparty/hadoop-shaded-protobuf_3_7/pom.properties")
+ .isEmpty(),
+ "hadoop-shaded-protobuf_3_7 is outdated");
+ for (String version :
+ versionsOf("META-INF/maven/com.google.protobuf/protobuf-java/pom.properties")) {
+ assertTrue(compare(version, "3.25.0") >= 0, "Outdated protobuf " + version);
+ }
+ try (JarFile jar = new JarFile(BUNDLE)) {
+ assertFalse(
+ jar.stream()
+ .anyMatch(
+ e -> e.getName().startsWith("org/apache/hadoop/shaded/com/google/protobuf/")),
+ "Protobuf 3.7 is shaded under org/apache/hadoop/shaded");
+ }
+ }
+
+ private static List<String> versionsOf(String propertiesEntry) throws Exception {
+ List<String> versions = new ArrayList<>();
+ try (JarFile jar = new JarFile(BUNDLE)) {
+ for (JarEntry entry : (Iterable<JarEntry>) jar.stream()::iterator) {
+ if (entry.getName().equals(propertiesEntry)) {
+ Properties properties = new Properties();
+ try (InputStream in = jar.getInputStream(entry)) {
+ properties.load(in);
+ }
+ versions.add(properties.getProperty("version"));
+ }
+ }
+ }
+ return versions;
+ }
+
+ private static int compare(String version, String minimum) {
+ String[] left = version.split("[.-]");
+ String[] right = minimum.split("[.-]");
+ for (int i = 0; i < right.length; i++) {
+ int l = i < left.length ? Integer.parseInt(left[i]) : 0;
+ int r = Integer.parseInt(right[i]);
+ if (l != r) {
+ return Integer.compare(l, r);
+ }
+ }
+ return 0;
+ }
+}
diff --git a/catalogs/catalog-fileset/build.gradle.kts b/catalogs/catalog-fileset/build.gradle.kts
index d2879efcbb..7f3b2e3b83 100644
--- a/catalogs/catalog-fileset/build.gradle.kts
+++ b/catalogs/catalog-fileset/build.gradle.kts
@@ -145,6 +145,13 @@ tasks.test {
dependsOn(tasks.jar)
}
+ // hadoop-client-api also contains the AuthenticationFilter of hadoop-auth, built against the
+ // shaded servlet API. The MiniDFSCluster runs the unshaded hadoop-common, which needs the class of
+ // hadoop-auth, so put hadoop-auth first instead of relying on the resolution order.
+ val testClasspath = classpath
+ val isHadoopAuth = { file: File -> file.name.startsWith("hadoop-auth-") }
+ classpath = testClasspath.filter(isHadoopAuth) + testClasspath.filter { !isHadoopAuth(it) }
+
// this task depends on :bundles:aws-bundle:jar
dependsOn(":bundles:aws-bundle:jar")
dependsOn(":bundles:aliyun-bundle:jar")
diff --git a/catalogs/catalog-fileset/src/test/java/org/apache/gravitino/catalog/fileset/integration/test/HDFSKerberosIT.java b/catalogs/catalog-fileset/src/test/java/org/apache/gravitino/catalog/fileset/integration/test/HDFSKerberosIT.java
index f4b2ddd3c4..bfb723e90a 100644
--- a/catalogs/catalog-fileset/src/test/java/org/apache/gravitino/catalog/fileset/integration/test/HDFSKerberosIT.java
+++ b/catalogs/catalog-fileset/src/test/java/org/apache/gravitino/catalog/fileset/integration/test/HDFSKerberosIT.java
@@ -23,7 +23,14 @@ import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
+import java.security.AccessController;
import java.security.PrivilegedAction;
+import java.security.PrivilegedExceptionAction;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+import javax.security.auth.Subject;
+import javax.security.auth.kerberos.KerberosTicket;
import org.apache.commons.io.FileUtils;
import org.apache.gravitino.integration.test.container.ContainerSuite;
import org.apache.gravitino.integration.test.container.HiveContainer;
@@ -128,6 +135,78 @@ public class HDFSKerberosIT {
Assertions.assertInstanceOf(AccessControlException.class, e.getCause());
}
+ /**
+ * Logs in from the keytab and logs in again with the Kerberos client of Hadoop 3.4 (Kerby 2.0.3
+ * in hadoop-auth), the way a long-running client renews its ticket. Each relogin must obtain a
+ * new TGT, and the HDFS access must keep working with it.
+ */
+ @Test
+ public void testKerberosHDFSKeytabRelogin() throws Exception {
+ Configuration conf = new Configuration();
+ conf.set("fs.defaultFS", defaultBaseLocation());
+ conf.setBoolean("fs.hdfs.impl.disable.cache", true);
+ conf.set("hadoop.security.authentication", "kerberos");
+ // Hadoop skips a relogin within this period after the last login (60 seconds by default).
+ conf.setInt("hadoop.kerberos.min.seconds.before.relogin", 0);
+ UserGroupInformation.reset();
+ UserGroupInformation.setConfiguration(conf);
+ try {
+ UserGroupInformation ugi =
+ UserGroupInformation.loginUserFromKeytabAndReturnUGI(CLIENT_PRINCIPAL, keytabPath);
+ Assertions.assertTrue(ugi.isFromKeytab());
+ Assertions.assertTrue(ugi.hasKerberosCredentials());
+ Assertions.assertEquals(CLIENT_PRINCIPAL, ugi.getUserName());
+ KerberosTicket initialTgt = getTgt(ugi);
+ assertRootExists(ugi, conf);
+
+ // A forced relogin always logs in again with the keytab.
+ ugi.forceReloginFromKeytab();
+ KerberosTicket forcedTgt = getTgt(ugi);
+ Assertions.assertNotSame(initialTgt, forcedTgt, "forceReloginFromKeytab got no new TGT");
+ assertRootExists(ugi, conf);
+
+ // The conditional relogin only logs in again when the TGT is due for a refresh. Make every
+ // TGT due, so that the renewal path runs.
+ UserGroupInformation.setShouldRenewImmediatelyForTests(true);
+ ugi.checkTGTAndReloginFromKeytab();
+ KerberosTicket renewedTgt = getTgt(ugi);
+ Assertions.assertNotSame(
+ forcedTgt, renewedTgt, "checkTGTAndReloginFromKeytab got no new TGT for a due TGT");
+ assertRootExists(ugi, conf);
+ } finally {
+ UserGroupInformation.setShouldRenewImmediatelyForTests(false);
+ }
+ }
+
+ // UserGroupInformation#getSubject is protected, so read the Subject of the UGI inside doAs.
+ @SuppressWarnings("removal")
+ private static KerberosTicket getTgt(UserGroupInformation ugi) throws Exception {
+ Subject subject =
+ ugi.doAs(
+ (PrivilegedExceptionAction<Subject>)
+ () -> Subject.getSubject(AccessController.getContext()));
+ Set<KerberosTicket> tickets = subject.getPrivateCredentials(KerberosTicket.class);
+ List<KerberosTicket> tgts =
+ tickets.stream()
+ .filter(t -> t.getServer().getName().startsWith("krbtgt/"))
+ .collect(Collectors.toList());
+ Assertions.assertEquals(1, tgts.size(), "Expect exactly one TGT of the client");
+ return tgts.get(0);
+ }
+
+ private static void assertRootExists(UserGroupInformation ugi, Configuration conf)
+ throws Exception {
+ boolean exists =
+ ugi.doAs(
+ (PrivilegedExceptionAction<Boolean>)
+ () -> {
+ try (FileSystem fs = FileSystem.get(conf)) {
+ return fs.exists(new Path("/"));
+ }
+ });
+ Assertions.assertTrue(exists);
+ }
+
private static String defaultBaseLocation() {
return String.format(
"hdfs://%s:%d/user/",
diff --git a/catalogs/catalog-hive/build.gradle.kts b/catalogs/catalog-hive/build.gradle.kts
index 5fa39a7360..42ecd11c74 100644
--- a/catalogs/catalog-hive/build.gradle.kts
+++ b/catalogs/catalog-hive/build.gradle.kts
@@ -94,7 +94,10 @@ dependencies {
testImplementation(libs.bundles.jersey)
testImplementation(libs.bundles.jetty)
testImplementation(libs.bundles.log4j)
- testImplementation(libs.hadoop3.aws)
+ testImplementation(libs.hadoop3.aws) {
+ exclude("software.amazon.awssdk", "bundle")
+ }
+ testImplementation(libs.bundles.hadoop.aws.sdk)
testImplementation(libs.hadoop3.common) {
exclude("*")
}
diff --git a/catalogs/catalog-hive/src/test/java/org/apache/gravitino/catalog/hive/integration/test/CatalogHiveS3IT.java b/catalogs/catalog-hive/src/test/java/org/apache/gravitino/catalog/hive/integration/test/CatalogHiveS3IT.java
index 3192554d6c..414099000e 100644
--- a/catalogs/catalog-hive/src/test/java/org/apache/gravitino/catalog/hive/integration/test/CatalogHiveS3IT.java
+++ b/catalogs/catalog-hive/src/test/java/org/apache/gravitino/catalog/hive/integration/test/CatalogHiveS3IT.java
@@ -39,6 +39,11 @@ import org.testcontainers.containers.Container;
public class CatalogHiveS3IT extends CatalogHive3IT {
private static final Logger LOGGER = LoggerFactory.getLogger(CatalogHiveS3IT.class);
+ // The Hive Metastore in the test image runs an S3A client without directory marker support. It
+ // takes a directory with a marker for an empty one and only deletes the marker when it drops a
+ // table. Hadoop 3.4 keeps the markers by default, so delete them like Hadoop 3.3 does.
+ private static final String DIRECTORY_MARKER_RETENTION = "fs.s3a.directory.marker.retention";
+ private static final String DIRECTORY_MARKER_RETENTION_DELETE = "delete";
private static final String S3_BUCKET_NAME = "my-test-bucket";
private GravitinoLocalStackContainer gravitinoLocalStackContainer;
@@ -140,6 +145,7 @@ public class CatalogHiveS3IT extends CatalogHive3IT {
"fs.s3a.aws.credentials.provider", "org.apache.hadoop.fs.s3a.SimpleAWSCredentialsProvider");
conf.set("fs.s3a.path.style.access", "true");
conf.set("fs.s3a.connection.ssl.enabled", "false");
+ conf.set(DIRECTORY_MARKER_RETENTION, DIRECTORY_MARKER_RETENTION_DELETE);
fileSystem = FileSystem.get(URI.create("s3a://" + S3_BUCKET_NAME), conf);
}
@@ -162,6 +168,7 @@ public class CatalogHiveS3IT extends CatalogHive3IT {
.config("spark.hadoop.fs.s3a.impl", "org.apache.hadoop.fs.s3a.S3AFileSystem")
.config("spark.hadoop.fs.s3a.path.style.access", "true")
.config("spark.hadoop.fs.s3a.connection.ssl.enabled", "false")
+ .config("spark.hadoop." + DIRECTORY_MARKER_RETENTION, DIRECTORY_MARKER_RETENTION_DELETE)
.config(
"spark.hadoop.fs.s3a.aws.credentials.provider",
"org.apache.hadoop.fs.s3a.SimpleAWSCredentialsProvider")
diff --git a/catalogs/catalog-lakehouse-paimon/build.gradle.kts b/catalogs/catalog-lakehouse-paimon/build.gradle.kts
index 8e91b8609f..ecfff1d8a9 100644
--- a/catalogs/catalog-lakehouse-paimon/build.gradle.kts
+++ b/catalogs/catalog-lakehouse-paimon/build.gradle.kts
@@ -125,6 +125,8 @@ dependencies {
exclude("com.github.spotbugs")
exclude("com.sun.jersey")
exclude("com.github.pjfanning", "jersey-json")
+ // hadoop-common 3.4 brings the netty modules, which the catalog does not need.
+ exclude("io.netty")
exclude("javax.servlet")
exclude("org.apache.avro")
exclude("net.java.dev.jets3t")
@@ -134,6 +136,10 @@ dependencies {
exclude("org.eclipse.jetty")
exclude("ch.qos.reload4j")
exclude("org.slf4j", "slf4j-reload4j")
+ // hadoop-common 3.4 declares these, Hadoop 3.3 did not bring them. No Hadoop class that the
+ // catalog uses needs them.
+ exclude("org.bouncycastle", "bcprov-jdk18on")
+ exclude("org.codehaus.jettison", "jettison")
}
implementation(libs.hadoop3.hdfs) {
exclude("*")
@@ -220,7 +226,10 @@ dependencies {
testImplementation(libs.testcontainers.mysql)
// Keep optional Hadoop S3A dependencies available only to tests.
- s3aTestRuntime(libs.hadoop3.aws)
+ s3aTestRuntime(libs.hadoop3.aws) {
+ exclude("software.amazon.awssdk", "bundle")
+ }
+ s3aTestRuntime(libs.bundles.hadoop.aws.sdk)
testRuntimeOnly(libs.junit.jupiter.engine)
// The embedded JDBC credential integration test loads this driver by class name.
testRuntimeOnly(libs.sqlite.jdbc)
@@ -228,34 +237,37 @@ dependencies {
val s3aTestLibDirectory =
"$rootDir/distribution/package-all/catalogs/lakehouse-paimon/libs"
+// hadoop-aws 3.4 is built on the AWS SDK v2, which is made of many jars. Provide all of them
+// except the modules the catalog already ships, in any version, so that no library ends up twice
+// in the directory, and SLF4J, which the server provides.
+val s3aTestJars =
+ provider {
+ fun moduleOf(artifact: ResolvedArtifact) =
+ "${artifact.moduleVersion.id.group}:${artifact.moduleVersion.id.name}"
+ val shipped =
+ configurations.runtimeClasspath.get().resolvedConfiguration.resolvedArtifacts
+ .map(::moduleOf)
+ .toSet()
+ s3aTestRuntime.resolvedConfiguration.resolvedArtifacts
+ .filter { moduleOf(it) != "org.slf4j:slf4j-api" && moduleOf(it) !in shipped }
+ .map { it.file }
+ }
val copyS3ATestDependencies =
tasks.register("copyS3ATestDependencies") {
inputs.files(s3aTestRuntime)
- outputs.files(
- provider {
- s3aTestRuntime.files.filter {
- it.name.startsWith("hadoop-aws-") || it.name.startsWith("aws-java-sdk-bundle-")
- }.map { file("$s3aTestLibDirectory/${it.name}") }
- }
- )
+ outputs.files(provider { s3aTestJars.get().map { file("$s3aTestLibDirectory/${it.name}") } })
// Copy tasks targeting the distribution depend on cleanDistributionPackage. Test setup
// must preserve the existing deployment, so copy the optional jars in a regular task.
doLast {
copy {
- from(s3aTestRuntime) {
- include("hadoop-aws-*.jar", "aws-java-sdk-bundle-*.jar")
- }
+ from(s3aTestJars)
into(s3aTestLibDirectory)
}
}
}
val cleanS3ATestDependencies =
tasks.register<Delete>("cleanS3ATestDependencies") {
- delete(
- fileTree(s3aTestLibDirectory) {
- include("hadoop-aws-*.jar", "aws-java-sdk-bundle-*.jar")
- }
- )
+ delete(provider { s3aTestJars.get().map { file("$s3aTestLibDirectory/${it.name}") } })
}
tasks {
diff --git a/catalogs/hadoop-common/src/main/java/org/apache/gravitino/catalog/hadoop/fs/Constants.java b/catalogs/hadoop-common/src/main/java/org/apache/gravitino/catalog/hadoop/fs/Constants.java
index 76edc5b9cc..95be1d6329 100644
--- a/catalogs/hadoop-common/src/main/java/org/apache/gravitino/catalog/hadoop/fs/Constants.java
+++ b/catalogs/hadoop-common/src/main/java/org/apache/gravitino/catalog/hadoop/fs/Constants.java
@@ -58,6 +58,11 @@ public class Constants {
public static final String S3_RETRY_LIMIT = "fs.s3a.retry.limit";
public static final String S3_RETRY_THROTTLE_LIMIT = "fs.s3a.retry.throttle.limit";
+ // Hadoop 3.4 changed the default from "delete" to "keep". S3A clients of the releases without
+ // marker support (before 2.10.2, 3.1.4, 3.2.2 and 3.3.1) take a directory with a kept marker for
+ // an empty one.
+ public static final String S3_DIRECTORY_MARKER_RETENTION = "fs.s3a.directory.marker.retention";
+ public static final String S3_DIRECTORY_MARKER_RETENTION_DELETE = "delete";
// GCS specific configuration keys
public static final String GCS_GCS_HTTP_CONNECT_TIMEOUT_KEY = "fs.gs.http.connect-timeout";
diff --git a/catalogs/hive-metastore2-libs/build.gradle.kts b/catalogs/hive-metastore2-libs/build.gradle.kts
index 19b19aa851..485d3e9f2b 100644
--- a/catalogs/hive-metastore2-libs/build.gradle.kts
+++ b/catalogs/hive-metastore2-libs/build.gradle.kts
@@ -60,6 +60,10 @@ dependencies {
exclude(group = "net.java.dev.jets3t")
exclude(group = "org.apache.avro")
exclude(group = "org.apache.logging.log4j")
+ // hadoop-common 3.4 declares these, Hadoop 3.3 did not bring them. No Hadoop class on the
+ // metastore client path uses them.
+ exclude(group = "org.bouncycastle", module = "bcprov-jdk18on")
+ exclude(group = "org.codehaus.jettison", module = "jettison")
exclude(group = "org.eclipse.jetty")
exclude(group = "org.eclipse.jetty.aggregate", module = "jetty-all")
exclude(group = "org.eclipse.jetty.orbit", module = "javax.servlet")
@@ -73,7 +77,8 @@ dependencies {
exclude(group = "com.google.code.findbugs")
exclude(group = "com.google.guava")
exclude(group = "com.sun.jersey")
- exclude(group = "io.netty", module = "netty")
+ // hadoop-mapreduce-client-core 3.4 brings netty-all and the netty modules, which are not needed.
+ exclude(group = "io.netty")
exclude(group = "log4j")
exclude(group = "org.apache.avro")
exclude(group = "org.apache.logging.log4j")
diff --git a/catalogs/hive-metastore3-libs/build.gradle.kts b/catalogs/hive-metastore3-libs/build.gradle.kts
index 0727796394..796ace4ca7 100644
--- a/catalogs/hive-metastore3-libs/build.gradle.kts
+++ b/catalogs/hive-metastore3-libs/build.gradle.kts
@@ -65,6 +65,10 @@ dependencies {
exclude(group = "net.java.dev.jets3t")
exclude(group = "org.apache.avro")
exclude(group = "org.apache.logging.log4j")
+ // hadoop-common 3.4 declares these, Hadoop 3.3 did not bring them. No Hadoop class on the
+ // metastore client path uses them.
+ exclude(group = "org.bouncycastle", module = "bcprov-jdk18on")
+ exclude(group = "org.codehaus.jettison", module = "jettison")
exclude(group = "org.eclipse.jetty")
exclude(group = "org.slf4j")
}
diff --git a/clients/filesystem-hadoop3/src/test/java/org/apache/gravitino/filesystem/hadoop/integration/test/GravitinoVirtualFileSystemS3IT.java b/clients/filesystem-hadoop3/src/test/java/org/apache/gravitino/filesystem/hadoop/integration/test/GravitinoVirtualFileSystemS3IT.java
index cdd0d3eb32..a8d6b197f1 100644
--- a/clients/filesystem-hadoop3/src/test/java/org/apache/gravitino/filesystem/hadoop/integration/test/GravitinoVirtualFileSystemS3IT.java
+++ b/clients/filesystem-hadoop3/src/test/java/org/apache/gravitino/filesystem/hadoop/integration/test/GravitinoVirtualFileSystemS3IT.java
@@ -23,22 +23,33 @@ import static org.apache.gravitino.catalog.fileset.FilesetCatalogPropertiesMetad
import com.google.common.collect.Maps;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.util.Collections;
+import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import org.apache.gravitino.Catalog;
+import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.catalog.hadoop.fs.FileSystemUtils;
+import org.apache.gravitino.credential.CredentialConstants;
+import org.apache.gravitino.credential.S3SecretKeyCredential;
+import org.apache.gravitino.file.Fileset;
import org.apache.gravitino.integration.test.container.GravitinoLocalStackContainer;
import org.apache.gravitino.integration.test.util.GravitinoITUtils;
import org.apache.gravitino.s3.fs.S3FileSystemProvider;
import org.apache.gravitino.storage.S3Properties;
import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.FSDataOutputStream;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.Container;
@@ -200,6 +211,90 @@ public class GravitinoVirtualFileSystemS3IT extends GravitinoVirtualFileSystemIT
return String.format("s3a://%s/%s", bucketName, fileset);
}
+ /**
+ * Reads and writes through GVFS with the credentials vended by Gravitino instead of the S3 keys
+ * in the client configuration. The S3A connector of Hadoop 3.4 (AWS SDK v2) gets them from the
+ * AWS SDK v2 credentials provider of Gravitino.
+ */
+ @Test
+ public void testReadWriteWithVendedCredentials() throws IOException {
+ String vendingCatalogName = GravitinoITUtils.genRandomName("catalog_vending");
+ String vendingSchemaName = GravitinoITUtils.genRandomName("schema_vending");
+ String filesetName = GravitinoITUtils.genRandomName("test_fileset_vending");
+
+ Map<String, String> catalogProperties = Maps.newHashMap();
+ catalogProperties.put(FILESYSTEM_PROVIDERS, "s3");
+ catalogProperties.put(
+ CredentialConstants.CREDENTIAL_PROVIDERS,
+ S3SecretKeyCredential.S3_SECRET_KEY_CREDENTIAL_TYPE);
+ catalogProperties.put(S3Properties.GRAVITINO_S3_ACCESS_KEY_ID, accessKey);
+ catalogProperties.put(S3Properties.GRAVITINO_S3_SECRET_ACCESS_KEY, secretKey);
+ catalogProperties.put(S3Properties.GRAVITINO_S3_ENDPOINT, s3Endpoint);
+ Catalog catalog =
+ metalake.createCatalog(
+ vendingCatalogName,
+ Catalog.Type.FILESET,
+ "hadoop",
+ "catalog comment",
+ catalogProperties);
+ catalog.asSchemas().createSchema(vendingSchemaName, "schema comment", catalogProperties);
+ String storageLocation = genStorageLocation(filesetName);
+ NameIdentifier filesetIdent = NameIdentifier.of(vendingSchemaName, filesetName);
+ catalog
+ .asFilesetCatalog()
+ .createFileset(
+ filesetIdent,
+ "fileset comment",
+ Fileset.Type.MANAGED,
+ storageLocation,
+ new HashMap<>());
+
+ // The client carries no S3 key: the keys can only come from the credential vending.
+ Configuration vendingConf = new Configuration();
+ vendingConf.set(
+ "fs.gvfs.impl", "org.apache.gravitino.filesystem.hadoop.GravitinoVirtualFileSystem");
+ vendingConf.set(
+ "fs.AbstractFileSystem.gvfs.impl", "org.apache.gravitino.filesystem.hadoop.Gvfs");
+ vendingConf.set("fs.gvfs.impl.disable.cache", "true");
+ vendingConf.set("fs.gravitino.server.uri", serverUri);
+ vendingConf.set("fs.gravitino.client.metalake", metalakeName);
+ vendingConf.set("fs.gravitino.enableCredentialVending", "true");
+ vendingConf.set(S3Properties.GRAVITINO_S3_ENDPOINT, s3Endpoint);
+
+ Path gvfsPath =
+ new Path(
+ String.format(
+ "gvfs://fileset/%s/%s/%s/vended.txt",
+ vendingCatalogName, vendingSchemaName, filesetName));
+ byte[] content = "vended credentials".getBytes(StandardCharsets.UTF_8);
+ Path realPath = new Path(storageLocation + "/vended.txt");
+ try (FileSystem gvfs = gvfsPath.getFileSystem(vendingConf);
+ FileSystem fs =
+ new Path(storageLocation)
+ .getFileSystem(convertGvfsConfigToRealFileSystemConfig(conf))) {
+ try (FSDataOutputStream out = gvfs.create(gvfsPath)) {
+ out.write(content);
+ }
+ Assertions.assertTrue(gvfs.exists(gvfsPath));
+ Assertions.assertEquals(content.length, gvfs.getFileStatus(gvfsPath).getLen());
+ // The file is in the real bucket.
+ Assertions.assertTrue(fs.exists(realPath));
+
+ byte[] actual = new byte[content.length];
+ try (FSDataInputStream in = gvfs.open(gvfsPath)) {
+ in.readFully(actual);
+ }
+ Assertions.assertArrayEquals(content, actual);
+
+ Assertions.assertTrue(gvfs.delete(gvfsPath, false));
+ Assertions.assertFalse(fs.exists(realPath));
+ }
+
+ catalog.asFilesetCatalog().dropFileset(filesetIdent);
+ catalog.asSchemas().dropSchema(vendingSchemaName, true);
+ metalake.dropCatalog(vendingCatalogName, true);
+ }
+
@Disabled(
"GCS does not support append, java.io.IOException: The append operation is not supported")
public void testAppend() throws IOException {}
diff --git a/dev/release/maven/README.md b/dev/release/maven/README.md
index b97b19d32c..c9501944fd 100644
--- a/dev/release/maven/README.md
+++ b/dev/release/maven/README.md
@@ -53,7 +53,7 @@ inventory. A dependency's POM license declaration may omit embedded third-party
- ANTLR runtime 4.13.2: [BSD-3-Clause LICENSE](https://github.com/antlr/antlr4/blob/4.13.2/LICENSE.txt);
the binary runtime JAR omits this text.
-- Aliyun OSS 3.10.2/3.13.0: the exact Maven Central source JARs contain the same
+- Aliyun OSS 3.10.2/3.13.0/3.13.2: the exact Maven Central source JARs contain the same
BSD-2-Clause header in `com/aliyun/oss/common/utils/IniEditor.java`.
- Google API Client 1.24.1: its exact Maven Central source JAR contains a separate
BSD-3-Clause header in `com/google/api/client/googleapis/auth/oauth2/CloudShellCredential.java`.
diff --git a/dev/release/maven/dependencies.txt b/dev/release/maven/dependencies.txt
index 10c504c5b6..ef37cdda2d 100644
--- a/dev/release/maven/dependencies.txt
+++ b/dev/release/maven/dependencies.txt
@@ -20,6 +20,7 @@
org.antlr:antlr4-runtime:4.13.2=LICENSE.antlr4 | ANTLR4 runtime (BSD-3-Clause)
com.aliyun.oss:aliyun-sdk-oss:3.10.2=LICENSE.aliyun-inieditor | Aliyun OSS (Apache-2.0), including IniEditor (BSD-2-Clause)
com.aliyun.oss:aliyun-sdk-oss:3.13.0=LICENSE.aliyun-inieditor | Aliyun OSS (Apache-2.0), including IniEditor (BSD-2-Clause)
+com.aliyun.oss:aliyun-sdk-oss:3.13.2=LICENSE.aliyun-inieditor | Aliyun OSS (Apache-2.0), including IniEditor (BSD-2-Clause)
com.google.api-client:google-api-client:1.24.1=LICENSE.google-cloudshell | Google API Client (Apache-2.0), including CloudShellCredential (BSD-3-Clause)
com.google.auth:google-auth-library-credentials:1.28.0=LICENSE.google-auth | Google Auth Library (BSD-3-Clause)
com.google.auth:google-auth-library-oauth2-http:1.28.0=LICENSE.google-auth | Google Auth Library (BSD-3-Clause)
diff --git a/docs/fileset-catalog-with-adls.md b/docs/fileset-catalog-with-adls.md
index b54189037d..31e356a0fa 100644
--- a/docs/fileset-catalog-with-adls.md
+++ b/docs/fileset-catalog-with-adls.md
@@ -238,7 +238,7 @@ differs by environment:
| Environment | Jar providing the Azure Data Lake Storage filesystem |
|------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| No Hadoop installed | [`gravitino-azure-bundle`](https://mvnrepository.com/artifact/org.apache.gravitino/gravitino-azure-bundle), a fat jar bundling the Azure Data Lake Storage filesystem implementation and its dependencies |
-| Hadoop already present | `hadoop-azure-${hadoop-version}.jar`, `azure-storage-7.0.1.jar` and `wildfly-openssl-1.0.7.Final.jar`, shipped with Hadoop under `${HADOOP_HOME}/share/hadoop/tools/lib` |
+| Hadoop already present | `hadoop-azure-${hadoop-version}.jar`, `azure-storage-7.0.1.jar` and `wildfly-openssl-${version}.jar`, shipped with Hadoop (see below) |
The artifacts in full:
@@ -250,9 +250,10 @@ The artifacts in full:
`gravitino-azure` functionality. Java and Hadoop-based clients require it to access Gravitino
filesets.
- `hadoop-azure-${hadoop-version}.jar`, `azure-storage-7.0.1.jar` and
- `wildfly-openssl-1.0.7.Final.jar`: the standard Hadoop dependencies for Azure Data Lake Storage
- access, shipped with Hadoop under `${HADOOP_HOME}/share/hadoop/tools/lib`. Supply them yourself
- when running inside an existing Hadoop environment.
+ `wildfly-openssl-${version}.jar`: the standard Hadoop dependencies for Azure Data Lake Storage
+ access. Hadoop 3.3 ships them under `${HADOOP_HOME}/share/hadoop/tools/lib`. Hadoop 3.4.3 ships
+ them under `${HADOOP_HOME}/share/hadoop/common/lib`, which is already on the Hadoop classpath.
+ Supply them yourself when running inside an existing Hadoop environment.
- [`gravitino-azure-${gravitino-version}.jar`](https://mvnrepository.com/artifact/org.apache.gravitino/gravitino-azure):
a "thin" jar carrying only the Azure integration code. It is already contained in both jars above,
so it is not needed as a direct dependency unless you prefer to manage all Hadoop and Azure
@@ -407,7 +408,7 @@ implementations passed with `--jars`. If that happens, add the jars to the Spark
2. Add these jars to the Hadoop classpath:
- `gravitino-filesystem-hadoop3-runtime-${gravitino-version}.jar`, from Maven Central.
- - `hadoop-azure-${hadoop-version}.jar`, `azure-storage-7.0.1.jar` and `wildfly-openssl-1.0.7.Final.jar`, shipped with Hadoop under `${HADOOP_HOME}/share/hadoop/tools/lib`.
+ - `hadoop-azure-${hadoop-version}.jar`, `azure-storage-7.0.1.jar` and `wildfly-openssl-${version}.jar`. Hadoop 3.3 ships them under `${HADOOP_HOME}/share/hadoop/tools/lib`. Hadoop 3.4.3 ships them under `${HADOOP_HOME}/share/hadoop/common/lib`, which is already on the Hadoop classpath.
3. Access the fileset:
diff --git a/docs/fileset-catalog-with-oss.md b/docs/fileset-catalog-with-oss.md
index 633a1f5eb3..86173a44a0 100644
--- a/docs/fileset-catalog-with-oss.md
+++ b/docs/fileset-catalog-with-oss.md
@@ -240,7 +240,7 @@ environment:
| Environment | Jar providing the Alibaba Cloud OSS filesystem |
|------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| No Hadoop installed | [`gravitino-aliyun-bundle`](https://mvnrepository.com/artifact/org.apache.gravitino/gravitino-aliyun-bundle), a fat jar bundling the Alibaba Cloud OSS filesystem implementation and its dependencies |
-| Hadoop already present | `hadoop-aliyun-${hadoop-version}.jar`, `aliyun-sdk-oss-3.13.0.jar` and `jdom2-2.0.6.jar`, shipped with Hadoop under `${HADOOP_HOME}/share/hadoop/tools/lib` |
+| Hadoop already present | `hadoop-aliyun-${hadoop-version}.jar` and the `aliyun-sdk-oss` and `jdom2` jars it depends on (see below) |
The artifacts in full:
@@ -251,10 +251,12 @@ The artifacts in full:
a "fat" jar that bundles the Gravitino virtual filesystem client and already includes the
`gravitino-aliyun` functionality. Java and Hadoop-based clients require it to access Gravitino
filesets.
-- `hadoop-aliyun-${hadoop-version}.jar`, `aliyun-sdk-oss-3.13.0.jar` and `jdom2-2.0.6.jar`: the
- standard Hadoop dependencies for Alibaba Cloud OSS access, shipped with Hadoop under
- `${HADOOP_HOME}/share/hadoop/tools/lib`. Supply them yourself when running inside an existing
- Hadoop environment.
+- `hadoop-aliyun-${hadoop-version}.jar` and the `aliyun-sdk-oss` and `jdom2` jars it depends on:
+ the standard Hadoop dependencies for Alibaba Cloud OSS access. Supply them yourself when running
+ inside an existing Hadoop environment. Hadoop 3.3 ships `hadoop-aliyun`, `aliyun-sdk-oss-3.13.0.jar`
+ and `jdom2-2.0.6.jar` under `${HADOOP_HOME}/share/hadoop/tools/lib`. The Hadoop 3.4.3 binary
+ distribution does not ship them, so download `hadoop-aliyun-3.4.3.jar` and the versions it
+ depends on (`aliyun-sdk-oss-3.13.2.jar` and `jdom2-2.0.6.1.jar`) from Maven Central.
- [`gravitino-aliyun-${gravitino-version}.jar`](https://mvnrepository.com/artifact/org.apache.gravitino/gravitino-aliyun):
a "thin" jar carrying only the Aliyun integration code. It is already contained in both jars
above, so it is not needed as a direct dependency unless you prefer to manage all Hadoop and
@@ -415,7 +417,7 @@ implementations passed with `--jars`. If that happens, add the jars to the Spark
2. Add these jars to the Hadoop classpath:
- `gravitino-filesystem-hadoop3-runtime-${gravitino-version}.jar`, from Maven Central.
- - `hadoop-aliyun-${hadoop-version}.jar`, `aliyun-sdk-oss-3.13.0.jar` and `jdom2-2.0.6.jar`, shipped with Hadoop under `${HADOOP_HOME}/share/hadoop/tools/lib`.
+ - `hadoop-aliyun-${hadoop-version}.jar` and the `aliyun-sdk-oss` and `jdom2` jars it depends on. Hadoop 3.3 ships them under `${HADOOP_HOME}/share/hadoop/tools/lib`. Hadoop 3.4.3 does not ship them, so download `hadoop-aliyun-3.4.3.jar`, `aliyun-sdk-oss-3.13.2.jar` and `jdom2-2.0.6.1.jar` from Maven Central.
3. Access the fileset:
diff --git a/docs/fileset-catalog-with-s3.md b/docs/fileset-catalog-with-s3.md
index 21ef6f6d65..e9a29563b7 100644
--- a/docs/fileset-catalog-with-s3.md
+++ b/docs/fileset-catalog-with-s3.md
@@ -254,7 +254,7 @@ environment:
| Environment | Jar providing the Amazon S3 filesystem |
|------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| No Hadoop installed | [`gravitino-aws-bundle`](https://mvnrepository.com/artifact/org.apache.gravitino/gravitino-aws-bundle), a fat jar bundling the Amazon S3 filesystem implementation and the AWS SDK |
-| Hadoop already present | `hadoop-aws-${hadoop-version}.jar` and `aws-java-sdk-bundle-1.12.262.jar`, shipped with Hadoop under `${HADOOP_HOME}/share/hadoop/tools/lib` |
+| Hadoop already present | `hadoop-aws-${hadoop-version}.jar` and the AWS SDK jar that matches the Hadoop version (see below), taken from your Hadoop installation or Maven Central |
The artifacts in full:
@@ -265,10 +265,17 @@ The artifacts in full:
a "fat" jar that bundles the Gravitino virtual filesystem client and already includes the
`gravitino-aws` functionality. Java and Hadoop-based clients require it to access Gravitino
filesets.
-- `hadoop-aws-${hadoop-version}.jar` and `aws-java-sdk-bundle-1.12.262.jar`: the standard Hadoop
- dependencies for Amazon S3 access, shipped with Hadoop under
- `${HADOOP_HOME}/share/hadoop/tools/lib`. Supply them yourself when running inside an existing
- Hadoop environment.
+- `hadoop-aws-${hadoop-version}.jar` and the AWS SDK jar: the standard Hadoop dependencies for
+ Amazon S3 access. Supply them yourself when running inside an existing Hadoop environment. The
+ `hadoop-aws` jar must have exactly the version of the Hadoop libraries it runs with, otherwise
+ S3A fails with a `NoClassDefFoundError` or `NoSuchMethodError`. The AWS SDK jar depends on the
+ Hadoop version:
+ - Hadoop 3.3 uses the AWS SDK v1 (`aws-java-sdk-bundle-1.12.x.jar`). Both jars are under
+ `${HADOOP_HOME}/share/hadoop/tools/lib`.
+ - Hadoop 3.4 and later use the AWS SDK v2 (`software.amazon.awssdk:bundle`, `bundle-2.x.jar`).
+ In Hadoop 3.4.3, `hadoop-aws` is under `${HADOOP_HOME}/share/hadoop/common/lib` and the SDK
+ jar is not shipped. Download the `bundle` version that your `hadoop-aws` release was built
+ with from Maven Central.
- [`gravitino-aws-${gravitino-version}.jar`](https://mvnrepository.com/artifact/org.apache.gravitino/gravitino-aws):
a "thin" jar carrying only the AWS integration code. It is already contained in both jars above,
so it is not needed as a direct dependency unless you prefer to manage all Hadoop and AWS
@@ -307,6 +314,28 @@ The artifacts in full:
</dependency>
```
+The `gravitino-aws-bundle` jar is built on Hadoop 3.4 and the AWS SDK v2. The thin `gravitino-aws`
+jar and `gravitino-filesystem-hadoop3-runtime` work with both Hadoop 3.3 (AWS SDK v1) and Hadoop 3.4
+and later (AWS SDK v2). Gravitino detects the Hadoop version at runtime and vends the credentials
+with the credentials provider of the matching AWS SDK, so no extra configuration is needed.
+
+S3A client-side encryption (`fs.s3a.encryption.algorithm` set to `CSE-KMS` or `CSE-CUSTOM`) needs
+extra jars with Hadoop 3.4 and later. `gravitino-aws-bundle` already contains them. In an existing
+Hadoop 3.4 environment, add `amazon-s3-encryption-client-java-${version}.jar` (4.0.0 for Hadoop
+3.4.3) and the AWS SDK v2 `kms` jar of the SDK version in use, unless the full
+`software.amazon.awssdk:bundle` jar already provides KMS. Hadoop 3.3 takes the encryption client
+from `aws-java-sdk-bundle` and needs no extra jars. Hadoop 3.4 fails to read objects that were
+written without client-side encryption, or by the AWS SDK v1 `AmazonS3EncryptionClient`, unless
+`fs.s3a.encryption.cse.v1.compatibility.enabled` is `true`. See the
+[Hadoop S3A encryption documentation](https://hadoop.apache.org/docs/r3.4.3/hadoop-aws/tools/hadoop-aws/encryption.html)
+before you enable client-side encryption on an existing fileset.
+
+Hadoop 3.4 changed the default of `fs.s3a.directory.marker.retention` from `delete` to `keep`.
+Gravitino keeps the previous default and sets it to `delete` unless you configure it, so that S3A
+clients of Hadoop releases without directory marker support (before 2.10.2, 3.1.4, 3.2.2 and
+3.3.1) can still read the directories. Set `gravitino.bypass.fs.s3a.directory.marker.retention` to
+`keep` to use the Hadoop 3.4 default.
+
:::note
The thin `gravitino-aws` jar is not needed. Its functionality is already included in both
`gravitino-aws-bundle` and `gravitino-filesystem-hadoop3-runtime`.
@@ -334,7 +363,11 @@ fs.mkdirs(filesetPath);
### Apache Spark
-The example below uses PySpark 3.5.0 in an environment that already has Hadoop 3.3.4.
+The example below uses PySpark 3.5.0, which ships Hadoop 3.3.4 and uses the AWS SDK v1. Spark
+brings its own Hadoop libraries, so the `hadoop-aws` jar must have exactly the Hadoop version of
+your Spark (`hadoop-aws-3.3.4.jar` here). With Hadoop 3.4 and later, such as PySpark 4.0, replace
+the last two jars with the `hadoop-aws-${hadoop-version}.jar` and `bundle-2.x.jar` of the Hadoop
+version of your Spark.
```bash
pip install pyspark==3.5.0
@@ -375,19 +408,10 @@ gvfs_path = "gvfs://fileset/s3_catalog/s3_schema/example_fileset/people"
spark_df.coalesce(1).write.mode("overwrite").option("header", "true").csv(gvfs_path)
```
-If Spark runs without a Hadoop environment, only the jar list changes:
-
-```python
-os.environ["PYSPARK_SUBMIT_ARGS"] = (
- "--jars /path/to/gravitino-aws-bundle-${gravitino-version}.jar,"
- "/path/to/gravitino-filesystem-hadoop3-runtime-${gravitino-version}.jar "
- "--master local[1] pyspark-shell"
-)
-```
-
:::note
-Some Spark versions need a Hadoop environment in the driver and do not pick up filesystem
-implementations passed with `--jars`. If that happens, add the jars to the Spark classpath directly.
+Do not use `gravitino-aws-bundle` with a Spark distribution. The bundle carries Hadoop 3.4.3
+classes, which conflict with the Hadoop libraries of Spark and fail with a `NoSuchMethodError`.
+Use it for applications that run without any Hadoop installation.
:::
### Hadoop fs command
@@ -428,7 +452,7 @@ implementations passed with `--jars`. If that happens, add the jars to the Spark
2. Add these jars to the Hadoop classpath:
- `gravitino-filesystem-hadoop3-runtime-${gravitino-version}.jar`, from Maven Central.
- - `hadoop-aws-${hadoop-version}.jar` and `aws-java-sdk-bundle-1.12.262.jar`, shipped with Hadoop under `${HADOOP_HOME}/share/hadoop/tools/lib`.
+ - `hadoop-aws-${hadoop-version}.jar` and the AWS SDK jar (`aws-java-sdk-bundle-1.12.x.jar` for Hadoop 3.3, `bundle-2.x.jar` for Hadoop 3.4 and later). Hadoop 3.3 ships both under `${HADOOP_HOME}/share/hadoop/tools/lib`. Hadoop 3.4.3 has `hadoop-aws` on its classpath already and does not ship the SDK jar, so download `software.amazon.awssdk:bundle` from Maven Central.
3. Access the fileset:
diff --git a/docs/hive-catalog-with-cloud-storage.md b/docs/hive-catalog-with-cloud-storage.md
index 96b2b3ac3f..b1ac7d58d3 100644
--- a/docs/hive-catalog-with-cloud-storage.md
+++ b/docs/hive-catalog-with-cloud-storage.md
@@ -80,9 +80,11 @@ It's also applicable for Azure Blob Storage(ADLS) and GCS.
After updating the `hive-site.xml`, you need to ensure that the necessary S3-related JARs are included in the Hive classpath. You can do this by executing the following command:
```shell
+# Hadoop 3.3. Hadoop 3.4.3 has hadoop-aws under share/hadoop/common/lib and does not ship the AWS SDK v2
+# bundle jar, download software.amazon.awssdk:bundle from Maven Central instead.
cp ${HADOOP_HOME}/share/hadoop/tools/lib/*aws* ${HIVE_HOME}/lib
-# For Azure Blob Storage(ADLS)
+# For Azure Blob Storage(ADLS). Hadoop 3.4.3 has these jars under share/hadoop/common/lib instead.
cp ${HADOOP_HOME}/share/hadoop/tools/lib/*azure* ${HIVE_HOME}/lib
# For Google Cloud Storage(GCS)
@@ -271,7 +273,7 @@ To access S3-stored tables using Spark, you need to configure the SparkSession a
```
:::note
-Please download [Hadoop AWS jar](https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-aws), [aws java sdk jar](https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-bundle) and place them in the classpath of the Spark. If the JARs are missing, Spark will not be able to access the S3 storage.
+Please download [Hadoop AWS jar](https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-aws), the AWS SDK jar that matches the Hadoop version of the Spark ([aws java sdk v1 jar](https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-bundle) for Hadoop 3.3, [aws java sdk v2 jar](https://mvnrepository.com/artifact/software.amazon.awssdk/bundle) for Hadoop 3.4 and later) and place them in the classpath of the Spark. If the JARs are missing, Spark will not be able to access the S3 storage.
Azure Blob Storage(ADLS) requires the [Hadoop Azure jar](https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-azure), [Azure cloud sdk jar](https://mvnrepository.com/artifact/com.azure/azure-storage-blob) to be placed in the classpath of the Spark.
for Google Cloud Storage(GCS), you need to download the [Hadoop GCS jar](https://github.com/GoogleCloudDataproc/hadoop-connectors/releases) and place it in the classpath of the Spark.
:::
diff --git a/docs/iceberg-rest-engine/spark.md b/docs/iceberg-rest-engine/spark.md
index 08e47a5666..1b0bd037bf 100755
--- a/docs/iceberg-rest-engine/spark.md
+++ b/docs/iceberg-rest-engine/spark.md
@@ -24,7 +24,10 @@ Spark configuration.
- The Gravitino IRC endpoint is accessible from your Spark environment. The default port is `9001`.
- The following JAR files available in your Spark environment:
- `iceberg-spark-runtime-3.5_2.12-1.7.1.jar`
- - `hadoop-aws-3.3.4.jar`
+ - `hadoop-aws-3.3.4.jar` and `aws-java-sdk-bundle-1.12.262.jar`, the S3A connector of the Hadoop
+ 3.3.4 that Spark 3.5.3 ships, which uses the AWS SDK v1. With Spark 4.0 and later, which ship
+ Hadoop 3.4, use the `hadoop-aws` jar of that Hadoop version and the AWS SDK v2 `bundle-2.x.jar`
+ that it requires instead.
- `aws-bundle-2.29.38.jar`
This page uses **Spark 3.5.3** with **Iceberg 1.7.1**. For other versions, ensure compatibility
diff --git a/docs/lakehouse-paimon-catalog.md b/docs/lakehouse-paimon-catalog.md
index 48a2d0b56a..256fe9d463 100644
--- a/docs/lakehouse-paimon-catalog.md
+++ b/docs/lakehouse-paimon-catalog.md
@@ -111,7 +111,9 @@ optional S3A dependencies by default. To enable it, add the following JARs to
- `hadoop-aws-<hadoop-version>.jar`, with the same version as the Hadoop libraries packaged by
Gravitino.
-- The `aws-java-sdk-bundle` version required by that `hadoop-aws` release.
+- The AWS SDK v2 `bundle` jar (`software.amazon.awssdk:bundle`) required by that `hadoop-aws`
+ release, for example `bundle-2.35.4.jar` for `hadoop-aws-3.4.3.jar`. The older AWS SDK v1
+ `aws-java-sdk-bundle` jar is only needed with Hadoop 3.3 and earlier.
The following example configures static credentials and a custom HTTP S3 endpoint:
diff --git a/docs/spark-connector/spark-catalog-hive.md b/docs/spark-connector/spark-catalog-hive.md
index 59d7d0d21a..7fe415ac20 100644
--- a/docs/spark-connector/spark-catalog-hive.md
+++ b/docs/spark-connector/spark-catalog-hive.md
@@ -109,4 +109,4 @@ When using the `spark-sql` shell client, you must explicitly set the `spark.bypa
### S3
-Refer to [Hive catalog with s3](../hive-catalog-with-cloud-storage.md) to set up a Hive catalog with s3 storage. To query the data stored in s3, you need to add s3 secret to the Spark configuration using `spark.sql.catalog.${hive_catalog_name}.fs.s3a.access.key` and `spark.sql.catalog.${hive_catalog_name}.fs.s3a.secret.key`. Additionally, download [hadoop aws jar](https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-aws), [aws java sdk jar](https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-bundle) and place them in the classpath of Spark.
+Refer to [Hive catalog with s3](../hive-catalog-with-cloud-storage.md) to set up a Hive catalog with s3 storage. To query the data stored in s3, you need to add s3 secret to the Spark configuration using `spark.sql.catalog.${hive_catalog_name}.fs.s3a.access.key` and `spark.sql.catalog.${hive_catalog_name}.fs.s3a.secret.key`. Additionally, download [hadoop aws jar](https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-aws), the AWS SDK jar that matches the Hadoop version of Spark ([aws java sdk v1 jar](https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-bundle) for Hadoop 3.3, [aws java sdk v2 jar](https://mvnrepository.com/artifact/software.amazon.awssdk/bundle) for Hadoop 3.4 and later) and place them in the classpath of Spark.
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
index 8310110f46..4b3b515eb0 100644
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@ -19,7 +19,11 @@
[versions]
antlr = "4.13.2"
db-scheduler = "16.12.0"
-awssdk = "2.31.73"
+awssdk = "2.54.17"
+# The S3 encryption client that hadoop-aws 3.4.3 is built with, needed for client-side encryption.
+amazon-s3-encryption-client = "4.0.0"
+# AWS SDK v1 is only needed to compile and test against Hadoop 3.3 (hadoop-aws 3.3.x is built on it).
+awssdk-v1 = "1.12.367"
azure-identity = "1.13.1"
azure-storage-file-datalake = "12.20.0"
reactor-netty-http = "1.2.1"
@@ -52,13 +56,15 @@ airlift-log = "237"
airlift-resolver = "1.6"
hive2 = "2.3.9"
hive3 = "3.1.3"
-hadoop3 = "3.3.6"
+hadoop3 = "3.4.3"
hadoop3-gcs = "1.9.4-hadoop3"
-hadoop3-abs = "3.3.6"
-hadoop3-aliyun = "3.3.6"
+hadoop3-abs = "3.4.3"
+hadoop3-aliyun = "3.4.3"
hadoop-cos = "3.3.0-8.3.23"
-hadoop3-thirdparty = "1.1.1"
-hadoop-minikdc = "3.3.6"
+hadoop3-thirdparty = "1.5.0"
+# Oldest Hadoop line supported by the thin bundles (for example the one shipped with Spark 3.5).
+hadoop33 = "3.3.6"
+hadoop-minikdc = "3.4.3"
re2j = "1.7"
httpclient = "4.4.1"
httpclient5 = "5.4.4"
@@ -194,8 +200,8 @@ datanucleus-jdo = "3.2.0-m3"
hudi = "0.15.0"
google-auth = "1.28.0"
aliyun-credentials = "0.3.12"
-# Match Hadoop 3.3.6. Iceberg 1.11.0 expects OSS.deleteObject(String, String)
-# to return VoidResult. SDK 3.10.2 returns void and fails to link on delete.
+# Iceberg 1.11.0 expects OSS.deleteObject(String, String) to return VoidResult.
+# SDK 3.10.2 returns void and fails to link on delete.
aliyun-sdk-oss = "3.13.0"
tencentcloud-sdk-sts = "3.1.1239"
openlineage = "1.29.0"
@@ -222,6 +228,11 @@ aws-policy = { group = "software.amazon.awssdk", name = "iam-policy-builder", ve
aws-s3 = { group = "software.amazon.awssdk", name = "s3", version.ref = "awssdk" }
aws-sts = { group = "software.amazon.awssdk", name = "sts", version.ref = "awssdk" }
aws-kms = { group = "software.amazon.awssdk", name = "kms", version.ref = "awssdk" }
+aws-s3-transfer-manager = { group = "software.amazon.awssdk", name = "s3-transfer-manager", version.ref = "awssdk" }
+aws-apache-client = { group = "software.amazon.awssdk", name = "apache-client", version.ref = "awssdk" }
+aws-netty-nio-client = { group = "software.amazon.awssdk", name = "netty-nio-client", version.ref = "awssdk" }
+aws-s3-encryption-client = { group = "software.amazon.encryption.s3", name = "amazon-s3-encryption-client-java", version.ref = "amazon-s3-encryption-client" }
+aws-v1-core = { group = "com.amazonaws", name = "aws-java-sdk-core", version.ref = "awssdk-v1" }
azure-identity = { group = "com.azure", name = "azure-identity", version.ref = "azure-identity"}
azure-storage-file-datalake = { group = "com.azure", name = "azure-storage-file-datalake", version.ref = "azure-storage-file-datalake"}
reactor-netty-http = {group = "io.projectreactor.netty", name = "reactor-netty-http", version.ref = "reactor-netty-http"}
@@ -296,7 +307,7 @@ hadoop3-oss = { group = "org.apache.hadoop", name = "hadoop-aliyun", version.ref
hadoop3-cos = { group = "com.qcloud.cos", name = "hadoop-cos", version.ref = "hadoop-cos"}
hadoop3-abs = { group = "org.apache.hadoop", name = "hadoop-azure", version.ref = "hadoop3-abs"}
hadoop3-shaded-guava = { group = "org.apache.hadoop.thirdparty", name = "hadoop-shaded-guava", version.ref = "hadoop3-thirdparty" }
-hadoop3-shaded-protobuf = { group = "org.apache.hadoop.thirdparty", name = "hadoop-shaded-protobuf_3_7", version.ref = "hadoop3-thirdparty" }
+hadoop3-shaded-protobuf = { group = "org.apache.hadoop.thirdparty", name = "hadoop-shaded-protobuf_3_25", version.ref = "hadoop3-thirdparty" }
re2j = { group = "com.google.re2j", name = "re2j", version.ref = "re2j" }
airlift-json = { group = "io.airlift", name = "json", version.ref = "airlift-json"}
airlift-log = { group = "io.airlift", name = "log", version.ref = "airlift-log" }
@@ -444,6 +455,9 @@ jwt = ["jwt-api", "jwt-impl", "jwt-gson"]
metrics = ["metrics-core", "metrics-jersey2", "metrics-jvm", "metrics-jmx", "metrics-servlets"]
prometheus = ["prometheus-servlet", "prometheus-dropwizard", "prometheus-client"]
kerby = ["kerby-core", "kerby-simplekdc"]
+# The AWS SDK v2 modules that hadoop-aws 3.4 needs at runtime. Use them instead of the 650 MB
+# software.amazon.awssdk:bundle that hadoop-aws declares, which must be excluded.
+hadoop-aws-sdk = ["aws-s3", "aws-sts", "aws-s3-transfer-manager", "aws-apache-client", "aws-netty-nio-client"]
[plugins]
spotless = { id = "com.diffplug.spotless", version.ref = "spotless-plugin" }
diff --git a/integration-test-common/build.gradle.kts b/integration-test-common/build.gradle.kts
index b7ca544251..64e38f6bbd 100644
--- a/integration-test-common/build.gradle.kts
+++ b/integration-test-common/build.gradle.kts
@@ -42,7 +42,7 @@ dependencies {
testImplementation(libs.bundles.jwt)
testImplementation(libs.nimbus.jose.jwt)
testImplementation(libs.bundles.log4j)
- testImplementation(libs.commons.cli)
+ testImplementation(libs.commons.cli.new)
testImplementation(libs.commons.lang3)
testImplementation(libs.commons.io)
testImplementation(libs.guava)
diff --git a/spark-connector/v3.5/spark/build.gradle.kts b/spark-connector/v3.5/spark/build.gradle.kts
index 0ba92711a8..47bb405730 100644
--- a/spark-connector/v3.5/spark/build.gradle.kts
+++ b/spark-connector/v3.5/spark/build.gradle.kts
@@ -186,7 +186,10 @@ dependencies {
testImplementation(libs.aws.kms)
testImplementation(libs.aws.s3)
testImplementation(libs.aws.sts)
- testImplementation(libs.hadoop3.aws)
+ testImplementation(libs.hadoop3.aws) {
+ exclude("software.amazon.awssdk", "bundle")
+ }
+ testImplementation(libs.bundles.hadoop.aws.sdk)
// hadoop-aws declares hadoop-client-api as provided; add it explicitly so S3AFileSystem can load
// org.apache.hadoop.fs.impl.prefetch.PrefetchingStatistics (added in 3.3.5) at runtime.
testImplementation(libs.hadoop3.client.api)
diff --git a/spark-connector/v4.0/spark/build.gradle.kts b/spark-connector/v4.0/spark/build.gradle.kts
index 0b80f57171..e64053e2d0 100644
--- a/spark-connector/v4.0/spark/build.gradle.kts
+++ b/spark-connector/v4.0/spark/build.gradle.kts
@@ -210,10 +210,15 @@ dependencies {
testImplementation(libs.aws.kms)
testImplementation(libs.aws.s3)
testImplementation(libs.aws.sts)
- testImplementation(libs.hadoop3.aws)
+ testImplementation(libs.hadoop3.aws) {
+ exclude("software.amazon.awssdk", "bundle")
+ }
+ testImplementation(libs.bundles.hadoop.aws.sdk)
// hadoop-aws declares hadoop-client-api as provided; add it explicitly so S3AFileSystem can load
// org.apache.hadoop.fs.impl.prefetch.PrefetchingStatistics (added in 3.3.5) at runtime.
testImplementation(libs.hadoop3.client.api)
+ // Spark brings an older hadoop-client-runtime; keep it on the same version as hadoop-client-api.
+ testImplementation(libs.hadoop3.client.runtime)
testImplementation(libs.hive2.common) {
exclude("com.sun.jersey")
exclude("org.apache.curator")
diff --git a/spark-connector/v4.1/spark/build.gradle.kts b/spark-connector/v4.1/spark/build.gradle.kts
index 90653f35de..e393a4e6e8 100644
--- a/spark-connector/v4.1/spark/build.gradle.kts
+++ b/spark-connector/v4.1/spark/build.gradle.kts
@@ -210,10 +210,15 @@ dependencies {
testImplementation(libs.aws.kms)
testImplementation(libs.aws.s3)
testImplementation(libs.aws.sts)
- testImplementation(libs.hadoop3.aws)
+ testImplementation(libs.hadoop3.aws) {
+ exclude("software.amazon.awssdk", "bundle")
+ }
+ testImplementation(libs.bundles.hadoop.aws.sdk)
// hadoop-aws declares hadoop-client-api as provided; add it explicitly so S3AFileSystem can load
// org.apache.hadoop.fs.impl.prefetch.PrefetchingStatistics (added in 3.3.5) at runtime.
testImplementation(libs.hadoop3.client.api)
+ // Spark brings an older hadoop-client-runtime; keep it on the same version as hadoop-client-api.
+ testImplementation(libs.hadoop3.client.runtime)
testImplementation(libs.hive2.common) {
exclude("com.sun.jersey")
exclude("org.apache.curator")
diff --git a/trino-connector/integration-test/build.gradle.kts b/trino-connector/integration-test/build.gradle.kts
index 2d3163bca3..8a017df1de 100644
--- a/trino-connector/integration-test/build.gradle.kts
+++ b/trino-connector/integration-test/build.gradle.kts
@@ -46,7 +46,7 @@ dependencies {
testImplementation(libs.bundles.jersey)
testImplementation(libs.bundles.jetty)
testImplementation(libs.bundles.log4j)
- testImplementation(libs.commons.cli)
+ testImplementation(libs.commons.cli.new)
testImplementation(libs.hadoop3.common) {
exclude("*")
}
diff --git a/trino-connector/integration-test/src/test/java/org/apache/gravitino/trino/connector/integration/test/TrinoQueryTestTool.java b/trino-connector/integration-test/src/test/java/org/apache/gravitino/trino/connector/integration/test/TrinoQueryTestTool.java
index 7df1e895b1..c8f64b809d 100644
--- a/trino-connector/integration-test/src/test/java/org/apache/gravitino/trino/connector/integration/test/TrinoQueryTestTool.java
+++ b/trino-connector/integration-test/src/test/java/org/apache/gravitino/trino/connector/integration/test/TrinoQueryTestTool.java
@@ -23,9 +23,9 @@ import java.util.Arrays;
import java.util.concurrent.CountDownLatch;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;
-import org.apache.commons.cli.PosixParser;
import org.apache.gravitino.integration.test.util.ITUtils;
import org.apache.logging.log4j.util.Strings;
@@ -36,62 +36,87 @@ public class TrinoQueryTestTool {
boolean isFailed = false;
try {
options.addOption(
+ null,
"auto",
true,
"Start the test containers and gravitino server automatically, the values are 'all','gravitation','none'."
+ "The default value is 'all'. If the value is 'gravitino', only the gravitino server will be started automatically.");
options.addOption(
- "ignore_failed", false, "Ignore the failed test cases, the default value is 'false'");
+ null,
+ "ignore_failed",
+ false,
+ "Ignore the failed test cases, the default value is 'false'");
options.addOption(
+ null,
"gen_output",
false,
"Generate the output file for the test set, the default value is 'false'");
options.addOption(
+ null,
"test_host",
true,
"Host address for all test services (include gravitino server, trino, hive, postgresql, mysql..., "
+ "if the services are not running on the same host. set the arguments like --gravitino_uri=xxx and --trino_uri=xxx), "
+ "all test services use 127.0.0.1 as default, if --auto is set to 'all', this option is ignored");
options.addOption(
+ null,
"gravitino_uri",
true,
"URL for Gravitino server, if --auto is set to 'all', this option is ignored");
options.addOption(
- "trino_uri", true, "URL for Trino, if --auto is set to 'all', this option is ignored");
+ null,
+ "trino_uri",
+ true,
+ "URL for Trino, if --auto is set to 'all', this option is ignored");
options.addOption(
- "hive_uri", true, "URL for Hive, if --auto is set to 'all', this option is ignored");
+ null,
+ "hive_uri",
+ true,
+ "URL for Hive, if --auto is set to 'all', this option is ignored");
options.addOption(
- "mysql_uri", true, "URL for MySQL, if --auto is set to 'all', this option is ignored");
+ null,
+ "mysql_uri",
+ true,
+ "URL for MySQL, if --auto is set to 'all', this option is ignored");
options.addOption(
- "hdfs_uri", true, "URL for HDFS, if --auto is set to 'all', this option is ignored");
+ null,
+ "hdfs_uri",
+ true,
+ "URL for HDFS, if --auto is set to 'all', this option is ignored");
options.addOption(
+ null,
"postgresql_uri",
true,
"URL for PostgreSQL, if --auto is set to 'all', this option is ignored");
options.addOption(
+ null,
"skip_testsets",
true,
"Comma-separated list of testsets to skip, default is 'glue'. "
+ "Pass an empty string to skip nothing.");
options.addOption(
+ null,
"test_sets_dir",
true,
"Specify the test sets' directory, "
+ "the default value is 'integration-test/src/test/resources/trino-queries'");
- options.addOption("test_set", true, "Specify the test set name to test");
- options.addOption("tester_id", true, "Specify the tester file name prefix to select to test");
- options.addOption("catalog", true, "Specify the catalog name to test");
+ options.addOption(null, "test_set", true, "Specify the test set name to test");
+ options.addOption(
+ null, "tester_id", true, "Specify the tester file name prefix to select to test");
+ options.addOption(null, "catalog", true, "Specify the catalog name to test");
options.addOption(
+ null,
"params",
true,
"Additional parameters that can replace the value of ${key} in the testers contents, "
+ "example: --params=key1,v1;key2,v2");
options.addOption(
+ null,
"trino_worker_num",
true,
"Specify the number of Trino independent worker, the default value is 0."
@@ -99,12 +124,14 @@ public class TrinoQueryTestTool {
+ "otherwise fall back to a single-node setup with combined coordinator-worker roles.");
options.addOption(
+ null,
"trino_version",
true,
"Specify the Trino version to test. If not specified, the version pinned in the test "
+ "docker-compose file is used.");
options.addOption(
+ null,
"trino_connector_dir",
true,
"Specify the Gravitino connector JAR path. "
@@ -113,18 +140,20 @@ public class TrinoQueryTestTool {
+ "file.");
options.addOption(
+ null,
"test_containers",
true,
"Specify the docker compose test containers to start, the default value is 'default'.");
options.addOption(
+ null,
"env_only",
false,
"Start the environment (Gravitino + Trino) and keep it running for manual testing. Press Ctrl+C to shutdown.");
- options.addOption("help", false, "Print this help message");
+ options.addOption(null, "help", false, "Print this help message");
- CommandLineParser parser = new PosixParser();
+ CommandLineParser parser = new DefaultParser();
CommandLine commandLine = parser.parse(options, args);
if (commandLine.hasOption("help")) {