Skip to content

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

[#9568] feat (fileset): Add support for multiple locations across different clusters in fileset (#9569)

Yuhuidaf5f26f66e3
diff --git a/catalogs/catalog-common/src/main/java/org/apache/gravitino/utils/FilesetUtil.java b/catalogs/catalog-common/src/main/java/org/apache/gravitino/utils/FilesetUtil.java
new file mode 100644
index 0000000000..3338342e85
--- /dev/null
+++ b/catalogs/catalog-common/src/main/java/org/apache/gravitino/utils/FilesetUtil.java
@@ -0,0 +1,138 @@
+/*
+ * 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.utils;
+
+import com.google.common.base.Preconditions;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.commons.lang3.StringUtils;
+
+/** Utility class for fileset-related operations. */
+public class FilesetUtil {
+
+ private FilesetUtil() {}
+
+ /**
+ * Get user-defined configurations for a given path based on the path's base location
+ * (scheme://authority).
+ *
+ * <p>The logic:
+ *
+ * <ol>
+ * <li>Extract baseLocation (scheme://authority) from the given path
+ * <li>Find config entries like "fs.path.config.&lt;name&gt; = &lt;base_location&gt;" where the
+ * base_location matches the extracted baseLocation
+ * <li>Extract the name from the matching entry
+ * <li>Then find all config entries with prefix "fs.path.config.&lt;name&gt;." and extract
+ * properties
+ * </ol>
+ *
+ * <p>Example:
+ *
+ * <pre>
+ * fs.path.config.cluster1 = s3://bucket1
+ * fs.path.config.cluster1.aws-access-key = XXX1
+ * fs.path.config.cluster1.aws-secret-key = XXX2
+ * If path is "s3://bucket1/path/fileset1", then baseLocation is "s3://bucket1",
+ * cluster1 matches and we extract:
+ * - aws-access-key = XXX1
+ * - aws-secret-key = XXX2
+ * </pre>
+ *
+ * @param path the path to extract configurations for
+ * @param conf the configuration map containing path-based configurations
+ * @param configPrefix the prefix for path-based configurations (e.g., "fs.path.config.")
+ * @return a map of user-defined configurations for the given path
+ */
+ public static Map<String, String> getUserDefinedFileSystemConfigs(
+ URI path, Map<String, String> conf, String configPrefix) {
+ Preconditions.checkArgument(path != null, "Path should not be null");
+ Preconditions.checkArgument(conf != null, "Configuration map should not be null");
+ Preconditions.checkArgument(
+ StringUtils.isNotBlank(configPrefix), "Config prefix should not be blank");
+
+ Map<String, String> properties = new HashMap<>();
+ String baseLocation = getBaseLocation(path);
+ String locationName = null;
+
+ // First pass: find the location name by matching baseLocation
+ // Look for entries like "fs.path.config.<name> = <base_location>"
+ // The key format should be exactly "fs.path.config.<name>" (no dot after name)
+ for (Map.Entry<String, String> entry : conf.entrySet()) {
+ String key = entry.getKey();
+ String value = entry.getValue();
+
+ // Check if this is a location definition: "fs.path.config.<name> = <base_location>"
+ // The key format should be exactly "fs.path.config.<name>" (no dot after name)
+ if (key.startsWith(configPrefix)) {
+ String suffix = key.substring(configPrefix.length());
+ // Check if this is a location definition (no dot after the name)
+ // Format: "fs.path.config.<name>" (not "fs.path.config.<name>.<property>")
+ if (!suffix.contains(".")
+ && StringUtils.isNotBlank(suffix)
+ && StringUtils.isNotBlank(value)) {
+ // This is a location definition: "fs.path.config.<name>"
+ // Extract baseLocation from the value and compare with the path's baseLocation
+ try {
+ URI valueUri = new URI(value);
+ String valueBaseLocation = getBaseLocation(valueUri);
+ if (baseLocation.equals(valueBaseLocation)) {
+ locationName = suffix;
+ break;
+ }
+ } catch (Exception e) {
+ throw new IllegalArgumentException(
+ String.format("Invalid URI in configuration of key %s: %s", key, value), e);
+ }
+ }
+ }
+ }
+
+ // Second pass: extract all properties for the matched location name
+ if (locationName != null) {
+ String propertyPrefix = configPrefix + locationName + ".";
+ for (Map.Entry<String, String> entry : conf.entrySet()) {
+ String key = entry.getKey();
+ // Check if this key is a property for the matched location
+ // e.g., "fs.path.config.cluster1.aws-ak" matches prefix "fs.path.config.cluster1."
+ if (key.startsWith(propertyPrefix)) {
+ // Extract the property name after the location prefix
+ // e.g., "fs.path.config.cluster1.aws-ak" -> "aws-ak"
+ String propertyName = key.substring(propertyPrefix.length());
+ if (!propertyName.isEmpty()) {
+ properties.put(propertyName, entry.getValue());
+ }
+ }
+ }
+ }
+
+ return properties;
+ }
+
+ /**
+ * Extract base location (scheme://authority) from a URI.
+ *
+ * @param uri the URI to extract base location from
+ * @return the base location in format "scheme://authority"
+ */
+ private static String getBaseLocation(URI uri) {
+ return uri.getScheme() + "://" + (uri.getAuthority() == null ? "" : uri.getAuthority());
+ }
+}
diff --git a/catalogs/catalog-fileset/build.gradle.kts b/catalogs/catalog-fileset/build.gradle.kts
index 99060517a9..979bed1cf6 100644
--- a/catalogs/catalog-fileset/build.gradle.kts
+++ b/catalogs/catalog-fileset/build.gradle.kts
@@ -42,6 +42,7 @@ dependencies {
}
implementation(libs.awaitility)
implementation(libs.caffeine)
+ implementation(libs.cglib)
implementation(libs.commons.lang3)
implementation(libs.commons.io)
implementation(libs.hadoop3.client.api)
diff --git a/catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/FilesetCatalogImpl.java b/catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/FilesetCatalogImpl.java
index c403edf904..76984f92ca 100644
--- a/catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/FilesetCatalogImpl.java
+++ b/catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/FilesetCatalogImpl.java
@@ -46,7 +46,7 @@ public class FilesetCatalogImpl extends BaseCatalog<FilesetCatalogImpl> {
@Override
protected CatalogOperations newOps(Map<String, String> config) {
- return new SecureFilesetCatalogOperations();
+ return new FilesetCatalogOperations();
}
@Override
diff --git a/catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/FilesetCatalogOperations.java b/catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/FilesetCatalogOperations.java
index a6a6d78a64..ed660b850f 100644
--- a/catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/FilesetCatalogOperations.java
+++ b/catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/FilesetCatalogOperations.java
@@ -18,6 +18,7 @@
*/
package org.apache.gravitino.catalog.fileset;
+import static org.apache.gravitino.catalog.hadoop.fs.HDFSFileSystemProvider.SCHEME_HDFS;
import static org.apache.gravitino.file.Fileset.LOCATION_NAME_UNKNOWN;
import static org.apache.gravitino.file.Fileset.PROPERTY_CATALOG_PLACEHOLDER;
import static org.apache.gravitino.file.Fileset.PROPERTY_DEFAULT_LOCATION_NAME;
@@ -44,6 +45,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ArrayBlockingQueue;
@@ -56,6 +58,7 @@ import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import java.util.stream.Collectors;
import javax.annotation.Nullable;
import org.apache.commons.lang3.StringUtils;
import org.apache.gravitino.Catalog;
@@ -77,6 +80,10 @@ import org.apache.gravitino.catalog.hadoop.fs.FileSystemUtils;
import org.apache.gravitino.connector.CatalogInfo;
import org.apache.gravitino.connector.CatalogOperations;
import org.apache.gravitino.connector.HasPropertyMetadata;
+import org.apache.gravitino.connector.credential.PathContext;
+import org.apache.gravitino.connector.credential.SupportsPathBasedCredentials;
+import org.apache.gravitino.credential.CredentialConstants;
+import org.apache.gravitino.credential.CredentialUtils;
import org.apache.gravitino.dto.file.FileInfoDTO;
import org.apache.gravitino.exceptions.AlreadyExistsException;
import org.apache.gravitino.exceptions.FilesetAlreadyExistsException;
@@ -97,18 +104,19 @@ import org.apache.gravitino.meta.FilesetEntity;
import org.apache.gravitino.meta.SchemaEntity;
import org.apache.gravitino.metrics.MetricsSystem;
import org.apache.gravitino.metrics.source.FilesetCatalogMetricsSource;
+import org.apache.gravitino.utils.FilesetUtil;
+import org.apache.gravitino.utils.NameIdentifierUtil;
import org.apache.gravitino.utils.NamespaceUtil;
import org.apache.gravitino.utils.PrincipalUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
-import org.apache.hadoop.security.UserGroupInformation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class FilesetCatalogOperations extends ManagedSchemaOperations
- implements CatalogOperations, FilesetCatalog, FilesetFileOps {
+ implements CatalogOperations, FilesetCatalog, FilesetFileOps, SupportsPathBasedCredentials {
private static final String SCHEMA_DOES_NOT_EXIST_MSG = "Schema %s does not exist";
private static final String FILESET_DOES_NOT_EXIST_MSG = "Fileset %s does not exist";
private static final String SLASH = "/";
@@ -138,6 +146,9 @@ public class FilesetCatalogOperations extends ManagedSchemaOperations
private FilesetCatalogMetricsSource catalogMetricsSource;
@VisibleForTesting ScheduledThreadPoolExecutor scheduler;
+
+ // TODO: Move the file system cache to the module of hadoop-common and reuse it in the
+ // BaseGVFSOperations
@VisibleForTesting Cache<FileSystemCacheKey, FileSystem> fileSystemCache;
private final ThreadPoolExecutor fileSystemExecutor =
@@ -162,23 +173,22 @@ public class FilesetCatalogOperations extends ManagedSchemaOperations
}
static class FileSystemCacheKey {
- // When the path is a path without scheme such as 'file','hdfs', etc., then the scheme and
- // authority are both null
+ /**
+ * When the path is a path without scheme such as 'file','hdfs', etc., then the scheme and
+ * authority are both null
+ *
+ * <p>NOTE: The filesystem cache key includes the schema, authority, and current user. Changes
+ * to the configuration of the fileset will not affect the cached filesystem.
+ */
@Nullable private final String scheme;
+
@Nullable private final String authority;
- private final Map<String, String> conf;
private final String currentUser;
- FileSystemCacheKey(String scheme, String authority, Map<String, String> conf) {
+ FileSystemCacheKey(String scheme, String authority) {
this.scheme = scheme;
this.authority = authority;
- this.conf = conf;
-
- try {
- this.currentUser = UserGroupInformation.getCurrentUser().getShortUserName();
- } catch (IOException e) {
- throw new RuntimeException("Failed to get current user", e);
- }
+ this.currentUser = PrincipalUtils.getCurrentUserName();
}
@Override
@@ -190,16 +200,14 @@ public class FilesetCatalogOperations extends ManagedSchemaOperations
return false;
}
FileSystemCacheKey that = (FileSystemCacheKey) o;
- return conf.equals(that.conf)
- && (scheme == null ? that.scheme == null : scheme.equals(that.scheme))
- && (authority == null ? that.authority == null : authority.equals(that.authority))
- && currentUser.equals(that.currentUser);
+ return Objects.equals(scheme, that.scheme)
+ && Objects.equals(authority, that.authority)
+ && Objects.equals(currentUser, that.currentUser);
}
@Override
public int hashCode() {
- int result = conf.hashCode();
- result = 31 * result + (scheme == null ? 0 : scheme.hashCode());
+ int result = 31 * (scheme == null ? 0 : scheme.hashCode());
result = 31 * result + (authority == null ? 0 : authority.hashCode());
result = 31 * result + currentUser.hashCode();
return result;
@@ -245,14 +253,9 @@ public class FilesetCatalogOperations extends ManagedSchemaOperations
}
if (!disableFSOps) {
- String fileSystemProviders =
- (String)
- propertiesMetadata
- .catalogPropertiesMetadata()
- .getOrDefault(config, FilesetCatalogPropertiesMetadata.FILESYSTEM_PROVIDERS);
this.fileSystemProvidersMap =
ImmutableMap.<String, FileSystemProvider>builder()
- .putAll(FileSystemUtils.getFileSystemProviders(fileSystemProviders))
+ .putAll(FileSystemUtils.getFileSystemProviders())
.build();
String defaultFileSystemProviderName =
@@ -351,13 +354,17 @@ public class FilesetCatalogOperations extends ManagedSchemaOperations
throw new UnsupportedOperationException("Filesystem operations are disabled on this server");
}
- String actualPath = getFileLocation(filesetIdent, subPath, locationName);
+ Fileset fileset = loadFileset(filesetIdent);
+ String actualPath = getFileLocation(fileset, subPath, locationName);
- FileSystem fileSystem = getFileSystemWithCache(new Path(actualPath), conf);
+ Path actualPathObj = new Path(actualPath);
+ Map<String, String> fsConf =
+ mergeUpLevelConfigurations(filesetIdent, fileset.properties(), actualPathObj);
+ FileSystem fileSystem = getFileSystemWithCache(actualPathObj, fsConf);
Path formalizedPath =
new Path(actualPath).makeQualified(fileSystem.getUri(), fileSystem.getWorkingDirectory());
- FileSystem fs = getFileSystemWithCache(formalizedPath, conf);
+ FileSystem fs = getFileSystemWithCache(formalizedPath, fsConf);
if (!fs.exists(formalizedPath)) {
throw new IllegalArgumentException(
String.format(
@@ -480,12 +487,8 @@ public class FilesetCatalogOperations extends ManagedSchemaOperations
try {
// formalize the path to avoid path without scheme, uri, authority, etc.
for (Map.Entry<String, Path> entry : filesetPaths.entrySet()) {
- // merge the properties from catalog, schema and fileset to get the final configuration
- // for fileset.
- // the priority is: fileset properties > schema properties > catalog properties
- Map<String, String> fsConf = new HashMap<>(conf);
- fsConf.putAll(schemaEntity.properties());
- fsConf.putAll(properties);
+ Map<String, String> fsConf =
+ mergeUpLevelConfigurations(ident, properties, entry.getValue());
FileSystem tmpFs = getFileSystemWithCache(entry.getValue(), fsConf);
Path formalizePath =
entry.getValue().makeQualified(tmpFs.getUri(), tmpFs.getWorkingDirectory());
@@ -668,7 +671,9 @@ public class FilesetCatalogOperations extends ManagedSchemaOperations
storageLocations.forEach(
(locationName, location) -> {
try {
- FileSystem fs = getFileSystemWithCache(location, conf);
+ Map<String, String> fsConf =
+ mergeUpLevelConfigurations(ident, filesetEntity.properties(), location);
+ FileSystem fs = getFileSystemWithCache(location, fsConf);
if (fs.exists(location)) {
if (!fs.delete(location, true)) {
LOG.warn(
@@ -711,72 +716,9 @@ public class FilesetCatalogOperations extends ManagedSchemaOperations
@Override
public String getFileLocation(NameIdentifier ident, String subPath, String locationName)
throws NoSuchFilesetException, NoSuchLocationNameException {
- Preconditions.checkArgument(subPath != null, "subPath must not be null");
- String processedSubPath;
- if (!subPath.trim().isEmpty() && !subPath.trim().startsWith(SLASH)) {
- processedSubPath = SLASH + subPath.trim();
- } else {
- processedSubPath = subPath.trim();
- }
Fileset fileset = loadFileset(ident);
- String targetLocationName;
- if (locationName == null) {
- targetLocationName =
- fileset.storageLocations().size() == 1
- // to be compatible with the old version, the fileset in old version only has one
- // location and does not have the default-location-name property
- ? fileset.storageLocations().keySet().iterator().next()
- : fileset.properties().get(PROPERTY_DEFAULT_LOCATION_NAME);
- } else {
- targetLocationName = locationName;
- }
- if (!fileset.storageLocations().containsKey(targetLocationName)) {
- throw new NoSuchLocationNameException(
- "Location name %s does not exist in fileset %s", targetLocationName, ident);
- }
-
- // do checks for some data operations.
- if (hasCallerContext()) {
- Map<String, String> contextMap = CallerContext.CallerContextHolder.get().context();
- String operation =
- contextMap.getOrDefault(
- FilesetAuditConstants.HTTP_HEADER_FILESET_DATA_OPERATION,
- FilesetDataOperation.UNKNOWN.name());
- if (!FilesetDataOperation.checkValid(operation)) {
- LOG.warn(
- "The data operation: {} is not valid, we cannot do some checks for this operation.",
- operation);
- } else {
- FilesetDataOperation dataOperation = FilesetDataOperation.valueOf(operation);
- switch (dataOperation) {
- case RENAME:
- // if the sub path is blank, it cannot be renamed otherwise the metadata in the
- // Gravitino server may be inconsistent.
- if (StringUtils.isBlank(processedSubPath)
- || (processedSubPath.startsWith(SLASH) && processedSubPath.length() == 1)) {
- throw new GravitinoRuntimeException(
- "subPath cannot be blank when need to rename a file or a directory.");
- }
- break;
- default:
- break;
- }
- }
- }
-
- String fileLocation;
- // If the processed sub path is blank, we pass the storage location directly
- if (StringUtils.isBlank(processedSubPath)) {
- fileLocation = fileset.storageLocations().get(targetLocationName);
- } else {
- // the processed sub path always starts with "/" if it is not blank,
- // so we can safely remove the tailing slash if the storage location ends with "/".
- String storageLocation =
- removeTrailingSlash(fileset.storageLocations().get(targetLocationName));
- fileLocation = String.format("%s%s", storageLocation, processedSubPath);
- }
- return fileLocation;
+ return getFileLocation(fileset, subPath, locationName);
}
@Override
@@ -799,7 +741,9 @@ public class FilesetCatalogOperations extends ManagedSchemaOperations
(locationName, schemaPath) -> {
if (schemaPath != null && !containsPlaceholder(schemaPath.toString())) {
try {
- FileSystem fs = getFileSystemWithCache(schemaPath, conf);
+ Map<String, String> fsConf =
+ mergeUpLevelConfigurations(ident, properties, schemaPath);
+ FileSystem fs = getFileSystemWithCache(schemaPath, fsConf);
if (fs.exists(schemaPath) && fs.getFileStatus(schemaPath).isFile()) {
throw new IllegalArgumentException(
"Fileset schema location cannot be a file: "
@@ -911,7 +855,9 @@ public class FilesetCatalogOperations extends ManagedSchemaOperations
(locationName, location) -> {
try {
Path filesetPath = new Path(location);
- FileSystem fs = getFileSystemWithCache(filesetPath, conf);
+ Map<String, String> fsConf =
+ mergeUpLevelConfigurations(ident, f.properties(), filesetPath);
+ FileSystem fs = getFileSystemWithCache(filesetPath, fsConf);
if (fs.exists(filesetPath)) {
if (!fs.delete(filesetPath, true)) {
LOG.warn(
@@ -941,7 +887,9 @@ public class FilesetCatalogOperations extends ManagedSchemaOperations
schemaPaths.forEach(
(locationName, schemaPath) -> {
try {
- FileSystem fs = getFileSystemWithCache(schemaPath, conf);
+ Map<String, String> fsConf =
+ mergeUpLevelConfigurations(ident, schemaEntity.properties(), schemaPath);
+ FileSystem fs = getFileSystemWithCache(schemaPath, fsConf);
if (fs.exists(schemaPath)) {
FileStatus[] statuses = fs.listStatus(schemaPath);
if (statuses.length == 0) {
@@ -1108,7 +1056,15 @@ public class FilesetCatalogOperations extends ManagedSchemaOperations
if (!disableFSOps && !containsPlaceholder(v)) {
Path path = new Path(v);
- FileSystem fs = getFileSystemWithCache(path, conf);
+ // At catalog initialization, only merge catalog config and user-defined location
+ // configs
+ Map<String, String> fsConf = new HashMap<>(conf);
+ fsConf.putAll(
+ FilesetUtil.getUserDefinedFileSystemConfigs(
+ path.toUri(),
+ conf,
+ FilesetCatalogPropertiesMetadata.FS_GRAVITINO_PATH_CONFIG_PREFIX));
+ FileSystem fs = getFileSystemWithCache(path, fsConf);
try {
if (fs.exists(path) && fs.getFileStatus(path).isFile()) {
throw new IllegalArgumentException(
@@ -1374,9 +1330,11 @@ public class FilesetCatalogOperations extends ManagedSchemaOperations
@VisibleForTesting
FileSystem getFileSystemWithCache(Path path, Map<String, String> conf) {
String scheme = path.toUri().getScheme();
- String authority = path.toUri().getAuthority();
+ FileSystemProvider provider = fileSystemProvidersMap.get(scheme);
+ String authority =
+ provider != null ? provider.getFullAuthority(path, conf) : path.toUri().getAuthority();
return fileSystemCache.get(
- new FileSystemCacheKey(scheme, authority, conf),
+ new FileSystemCacheKey(scheme, authority),
cacheKey -> {
try {
return getFileSystem(path, conf);
@@ -1421,7 +1379,16 @@ public class FilesetCatalogOperations extends ManagedSchemaOperations
config, FilesetCatalogPropertiesMetadata.FILESYSTEM_CONNECTION_TIMEOUT_SECONDS);
Future<FileSystem> fileSystemFuture =
- fileSystemExecutor.submit(() -> provider.getFileSystem(path, config));
+ fileSystemExecutor.submit(
+ () -> {
+ if (scheme.equals(SCHEME_HDFS)) {
+ return new ImpersonationHDFSFileSystemProxy(
+ path, config, PrincipalUtils::getCurrentUserName)
+ .getProxy();
+ } else {
+ return provider.getFileSystem(path, config);
+ }
+ });
try {
return fileSystemFuture.get(timeoutSeconds, TimeUnit.SECONDS);
@@ -1462,4 +1429,173 @@ public class FilesetCatalogOperations extends ManagedSchemaOperations
throw new IOException("Failed to create FileSystem", cause);
}
}
+
+ private String getFileLocation(Fileset fileset, String subPath, String locationName) {
+ Preconditions.checkArgument(subPath != null, "subPath must not be null");
+ String processedSubPath;
+ if (!subPath.trim().isEmpty() && !subPath.trim().startsWith(SLASH)) {
+ processedSubPath = SLASH + subPath.trim();
+ } else {
+ processedSubPath = subPath.trim();
+ }
+
+ String targetLocationName;
+ if (locationName == null) {
+ targetLocationName =
+ fileset.storageLocations().size() == 1
+ // to be compatible with the old version, the fileset in old version only has one
+ // location and does not have the default-location-name property
+ ? fileset.storageLocations().keySet().iterator().next()
+ : fileset.properties().get(PROPERTY_DEFAULT_LOCATION_NAME);
+ } else {
+ targetLocationName = locationName;
+ }
+ if (!fileset.storageLocations().containsKey(targetLocationName)) {
+ throw new NoSuchLocationNameException(
+ "Location name %s does not exist in fileset %s", targetLocationName, fileset.name());
+ }
+
+ // do checks for some data operations.
+ if (hasCallerContext()) {
+ Map<String, String> contextMap = CallerContext.CallerContextHolder.get().context();
+ String operation =
+ contextMap.getOrDefault(
+ FilesetAuditConstants.HTTP_HEADER_FILESET_DATA_OPERATION,
+ FilesetDataOperation.UNKNOWN.name());
+ if (!FilesetDataOperation.checkValid(operation)) {
+ LOG.warn(
+ "The data operation: {} is not valid, we cannot do some checks for this operation.",
+ operation);
+ } else {
+ FilesetDataOperation dataOperation = FilesetDataOperation.valueOf(operation);
+ switch (dataOperation) {
+ case RENAME:
+ // if the sub path is blank, it cannot be renamed otherwise the metadata in the
+ // Gravitino server may be inconsistent.
+ if (StringUtils.isBlank(processedSubPath)
+ || (processedSubPath.startsWith(SLASH) && processedSubPath.length() == 1)) {
+ throw new GravitinoRuntimeException(
+ "subPath cannot be blank when need to rename a file or a directory.");
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ String fileLocation;
+ // If the processed sub path is blank, we pass the storage location directly
+ if (StringUtils.isBlank(processedSubPath)) {
+ fileLocation = fileset.storageLocations().get(targetLocationName);
+ } else {
+ // the processed sub path always starts with "/" if it is not blank,
+ // so we can safely remove the tailing slash if the storage location ends with "/".
+ String storageLocation =
+ removeTrailingSlash(fileset.storageLocations().get(targetLocationName));
+ fileLocation = String.format("%s%s", storageLocation, processedSubPath);
+ }
+ return fileLocation;
+ }
+
+ @VisibleForTesting
+ Map<String, String> mergeUpLevelConfigurations(
+ NameIdentifier ident, Map<String, String> entityProperties, Path path) {
+ // Merge configurations from catalog, schema, and entity (fileset) levels, and also include
+ // user-defined configurations for the specified location.
+ Map<String, String> mergedProperties = new HashMap<>(conf);
+ if (ident.namespace().levels().length == 2) {
+ // schema level
+ mergedProperties.putAll(entityProperties);
+ // Add user-defined configs for location if provided
+ mergedProperties.putAll(
+ FilesetUtil.getUserDefinedFileSystemConfigs(
+ path.toUri(),
+ mergedProperties,
+ FilesetCatalogPropertiesMetadata.FS_GRAVITINO_PATH_CONFIG_PREFIX));
+ return mergedProperties;
+ }
+
+ // fileset level
+ NameIdentifierUtil.checkFileset(ident);
+ NameIdentifier schemaIdent = NameIdentifierUtil.getSchemaIdentifier(ident);
+ Schema schema = loadSchema(schemaIdent);
+ mergedProperties.putAll(schema.properties());
+ mergedProperties.putAll(entityProperties);
+ // Add user-defined configs for location if provided
+ mergedProperties.putAll(
+ FilesetUtil.getUserDefinedFileSystemConfigs(
+ path.toUri(),
+ mergedProperties,
+ FilesetCatalogPropertiesMetadata.FS_GRAVITINO_PATH_CONFIG_PREFIX));
+ return mergedProperties;
+ }
+
+ @Override
+ public List<PathContext> getPathContext(NameIdentifier filesetIdentifier) {
+ Fileset fileset = loadFileset(filesetIdentifier);
+ String path = getTargetLocation(fileset);
+
+ Set<String> providers =
+ CredentialUtils.getCredentialProvidersByOrder(
+ fileset::properties,
+ () -> {
+ Namespace namespace = filesetIdentifier.namespace();
+ NameIdentifier schemaIdentifier =
+ NameIdentifierUtil.ofSchema(
+ namespace.level(0), namespace.level(1), namespace.level(2));
+ return loadSchema(schemaIdentifier).properties();
+ },
+ () -> conf);
+ return providers.stream()
+ .map(provider -> new PathContext(path, provider))
+ .collect(Collectors.toList());
+ }
+
+ @VisibleForTesting
+ protected String getTargetLocation(Fileset fileset) {
+ CallerContext callerContext = CallerContext.CallerContextHolder.get();
+ String targetLocationName;
+ String targetLocation;
+ if (callerContext != null
+ && callerContext
+ .context()
+ .containsKey(CredentialConstants.HTTP_HEADER_CURRENT_LOCATION_NAME)) {
+ // case 1: target location name is passed in the header
+ targetLocationName =
+ callerContext.context().get(CredentialConstants.HTTP_HEADER_CURRENT_LOCATION_NAME);
+ Preconditions.checkArgument(
+ fileset.storageLocations().containsKey(targetLocationName),
+ "The location name %s is not in the fileset %s, expected location names are %s",
+ targetLocationName,
+ fileset.name(),
+ fileset.storageLocations().keySet());
+ targetLocation = fileset.storageLocations().get(targetLocationName);
+
+ } else if (fileset.storageLocations().size() == 1) {
+ // case 2: target location name is not passed in the header, but there is only one location.
+ // note: mainly used for backward compatibility since the old code does not pass the header
+ // and only supports one location
+ targetLocation = fileset.storageLocations().values().iterator().next();
+ targetLocationName = fileset.storageLocations().keySet().iterator().next();
+
+ } else {
+ // case 3: target location name is not passed in the header, and there are multiple locations.
+ // use the default location name
+ targetLocationName = fileset.properties().get(PROPERTY_DEFAULT_LOCATION_NAME);
+ // this should never happen, but just in case
+ Preconditions.checkArgument(
+ StringUtils.isNotBlank(targetLocationName),
+ "The default location name of the fileset %s should not be empty.",
+ fileset.name());
+ targetLocation = fileset.storageLocations().get(targetLocationName);
+ }
+
+ Preconditions.checkArgument(
+ StringUtils.isNotBlank(targetLocation),
+ "The location with the location name %s of the fileset %s should not be empty.",
+ targetLocationName,
+ fileset.name());
+ return targetLocation;
+ }
}
diff --git a/catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/FilesetCatalogPropertiesMetadata.java b/catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/FilesetCatalogPropertiesMetadata.java
index e4dc00b0ce..57c5a79842 100644
--- a/catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/FilesetCatalogPropertiesMetadata.java
+++ b/catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/FilesetCatalogPropertiesMetadata.java
@@ -18,14 +18,19 @@
*/
package org.apache.gravitino.catalog.fileset;
-import static org.apache.gravitino.catalog.fileset.authentication.kerberos.KerberosConfig.KERBEROS_PROPERTY_ENTRIES;
import static org.apache.gravitino.catalog.hadoop.fs.Constants.BUILTIN_LOCAL_FS_PROVIDER;
+import static org.apache.gravitino.catalog.hadoop.fs.kerberos.AuthenticationConfig.AUTH_TYPE_KEY;
+import static org.apache.gravitino.catalog.hadoop.fs.kerberos.AuthenticationConfig.IMPERSONATION_ENABLE_KEY;
+import static org.apache.gravitino.catalog.hadoop.fs.kerberos.AuthenticationConfig.KERBEROS_DEFAULT_IMPERSONATION_ENABLE;
+import static org.apache.gravitino.catalog.hadoop.fs.kerberos.KerberosConfig.CHECK_INTERVAL_SEC_KEY;
+import static org.apache.gravitino.catalog.hadoop.fs.kerberos.KerberosConfig.FETCH_TIMEOUT_SEC_KEY;
+import static org.apache.gravitino.catalog.hadoop.fs.kerberos.KerberosConfig.KEY_TAB_URI_KEY;
+import static org.apache.gravitino.catalog.hadoop.fs.kerberos.KerberosConfig.PRINCIPAL_KEY;
import static org.apache.gravitino.file.Fileset.LOCATION_NAME_UNKNOWN;
import static org.apache.gravitino.file.Fileset.PROPERTY_MULTIPLE_LOCATIONS_PREFIX;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
-import org.apache.gravitino.catalog.fileset.authentication.AuthenticationConfig;
import org.apache.gravitino.catalog.hadoop.fs.FileSystemProvider;
import org.apache.gravitino.catalog.hadoop.fs.LocalFileSystemProvider;
import org.apache.gravitino.connector.BaseCatalogPropertiesMetadata;
@@ -66,9 +71,12 @@ public class FilesetCatalogPropertiesMetadata extends BaseCatalogPropertiesMetad
/** The value to indicate the cache value is not set. */
public static final long CACHE_VALUE_NOT_SET = -1;
- static final String FILESYSTEM_CONNECTION_TIMEOUT_SECONDS = "filesystem-conn-timeout-secs";
+ public static final String FILESYSTEM_CONNECTION_TIMEOUT_SECONDS = "filesystem-conn-timeout-secs";
static final int DEFAULT_GET_FILESYSTEM_TIMEOUT_SECONDS = 6;
+ /** The prefix for user-defined location configs: {@code fs.path.config.<name>=<path>}. */
+ public static final String FS_GRAVITINO_PATH_CONFIG_PREFIX = "fs.path.config.";
+
/**
* The property to disable file system operations like list, exists, mkdir operations in the
* server side, so that the server side catalog can be used as a metadata only catalog, no need to
@@ -78,6 +86,65 @@ public class FilesetCatalogPropertiesMetadata extends BaseCatalogPropertiesMetad
static final boolean DEFAULT_DISABLE_FILESYSTEM_OPS = false;
+ public static final Map<String, PropertyEntry<?>> KERBEROS_PROPERTY_ENTRIES =
+ new ImmutableMap.Builder<String, PropertyEntry<?>>()
+ .put(
+ KEY_TAB_URI_KEY,
+ PropertyEntry.stringOptionalPropertyEntry(
+ KEY_TAB_URI_KEY,
+ "The uri of key tab for the catalog",
+ false /* immutable */,
+ null /* default value */,
+ false /* hidden */))
+ .put(
+ PRINCIPAL_KEY,
+ PropertyEntry.stringOptionalPropertyEntry(
+ PRINCIPAL_KEY,
+ "The principal for the catalog",
+ false /* immutable */,
+ null /* defaultValue */,
+ false /* hidden */))
+ .put(
+ CHECK_INTERVAL_SEC_KEY,
+ PropertyEntry.integerOptionalPropertyEntry(
+ CHECK_INTERVAL_SEC_KEY,
+ "The interval to check validness of the principal",
+ true /* immutable */,
+ 60 /* defaultValue */,
+ false /* hidden */))
+ .put(
+ FETCH_TIMEOUT_SEC_KEY,
+ PropertyEntry.integerOptionalPropertyEntry(
+ FETCH_TIMEOUT_SEC_KEY,
+ "The timeout to fetch key tab",
+ false /* immutable */,
+ 60 /* defaultValue */,
+ false /* hidden */))
+ .build();
+
+ public static final Map<String, PropertyEntry<?>> AUTHENTICATION_PROPERTY_ENTRIES =
+ new ImmutableMap.Builder<String, PropertyEntry<?>>()
+ .put(
+ IMPERSONATION_ENABLE_KEY,
+ PropertyEntry.booleanPropertyEntry(
+ IMPERSONATION_ENABLE_KEY,
+ "Whether to enable impersonation for the Fileset catalog",
+ false /* required */,
+ true /* immutable */,
+ KERBEROS_DEFAULT_IMPERSONATION_ENABLE /* default value */,
+ false /* hidden */,
+ false /* reserved */))
+ .put(
+ AUTH_TYPE_KEY,
+ PropertyEntry.stringOptionalPropertyEntry(
+ AUTH_TYPE_KEY,
+ "The type of authentication for Fileset catalog, currently we only "
+ + "support simple and Kerberos",
+ false /* immutable */,
+ null /* default value */,
+ false /* hidden */))
+ .build();
+
private static final Map<String, PropertyEntry<?>> FILESET_CATALOG_PROPERTY_ENTRIES =
ImmutableMap.<String, PropertyEntry<?>>builder()
.put(
@@ -155,7 +222,7 @@ public class FilesetCatalogPropertiesMetadata extends BaseCatalogPropertiesMetad
false /* reserved */))
// The following two are about authentication.
.putAll(KERBEROS_PROPERTY_ENTRIES)
- .putAll(AuthenticationConfig.AUTHENTICATION_PROPERTY_ENTRIES)
+ .putAll(AUTHENTICATION_PROPERTY_ENTRIES)
.putAll(CredentialConfig.CREDENTIAL_PROPERTY_ENTRIES)
.build();
diff --git a/catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/FilesetPropertiesMetadata.java b/catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/FilesetPropertiesMetadata.java
index c52f922f35..e5a20d266c 100644
--- a/catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/FilesetPropertiesMetadata.java
+++ b/catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/FilesetPropertiesMetadata.java
@@ -18,6 +18,8 @@
*/
package org.apache.gravitino.catalog.fileset;
+import static org.apache.gravitino.catalog.fileset.FilesetCatalogPropertiesMetadata.AUTHENTICATION_PROPERTY_ENTRIES;
+import static org.apache.gravitino.catalog.fileset.FilesetCatalogPropertiesMetadata.KERBEROS_PROPERTY_ENTRIES;
import static org.apache.gravitino.file.Fileset.PROPERTY_CATALOG_PLACEHOLDER;
import static org.apache.gravitino.file.Fileset.PROPERTY_DEFAULT_LOCATION_NAME;
import static org.apache.gravitino.file.Fileset.PROPERTY_FILESET_PLACEHOLDER;
@@ -26,8 +28,6 @@ import static org.apache.gravitino.file.Fileset.PROPERTY_SCHEMA_PLACEHOLDER;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
-import org.apache.gravitino.catalog.fileset.authentication.AuthenticationConfig;
-import org.apache.gravitino.catalog.fileset.authentication.kerberos.KerberosConfig;
import org.apache.gravitino.connector.BasePropertiesMetadata;
import org.apache.gravitino.connector.PropertyEntry;
import org.apache.gravitino.credential.config.CredentialConfig;
@@ -73,8 +73,8 @@ public class FilesetPropertiesMetadata extends BasePropertiesMetadata {
true /* immutable */,
null,
false /* hidden */))
- .putAll(KerberosConfig.KERBEROS_PROPERTY_ENTRIES)
- .putAll(AuthenticationConfig.AUTHENTICATION_PROPERTY_ENTRIES)
+ .putAll(KERBEROS_PROPERTY_ENTRIES)
+ .putAll(AUTHENTICATION_PROPERTY_ENTRIES)
.putAll(CredentialConfig.CREDENTIAL_PROPERTY_ENTRIES);
return builder.build();
}
diff --git a/catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/FilesetSchemaPropertiesMetadata.java b/catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/FilesetSchemaPropertiesMetadata.java
index 35d0c34bba..266c9f977a 100644
--- a/catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/FilesetSchemaPropertiesMetadata.java
+++ b/catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/FilesetSchemaPropertiesMetadata.java
@@ -18,13 +18,13 @@
*/
package org.apache.gravitino.catalog.fileset;
+import static org.apache.gravitino.catalog.fileset.FilesetCatalogPropertiesMetadata.AUTHENTICATION_PROPERTY_ENTRIES;
+import static org.apache.gravitino.catalog.fileset.FilesetCatalogPropertiesMetadata.KERBEROS_PROPERTY_ENTRIES;
import static org.apache.gravitino.file.Fileset.LOCATION_NAME_UNKNOWN;
import static org.apache.gravitino.file.Fileset.PROPERTY_MULTIPLE_LOCATIONS_PREFIX;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
-import org.apache.gravitino.catalog.fileset.authentication.AuthenticationConfig;
-import org.apache.gravitino.catalog.fileset.authentication.kerberos.KerberosConfig;
import org.apache.gravitino.connector.BasePropertiesMetadata;
import org.apache.gravitino.connector.PropertyEntry;
import org.apache.gravitino.credential.config.CredentialConfig;
@@ -66,8 +66,8 @@ public class FilesetSchemaPropertiesMetadata extends BasePropertiesMetadata {
null /* default value */,
false /* hidden */,
false /* reserved */))
- .putAll(KerberosConfig.KERBEROS_PROPERTY_ENTRIES)
- .putAll(AuthenticationConfig.AUTHENTICATION_PROPERTY_ENTRIES)
+ .putAll(KERBEROS_PROPERTY_ENTRIES)
+ .putAll(AUTHENTICATION_PROPERTY_ENTRIES)
.putAll(CredentialConfig.CREDENTIAL_PROPERTY_ENTRIES)
.build();
diff --git a/catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/ImpersonationHDFSFileSystemProxy.java b/catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/ImpersonationHDFSFileSystemProxy.java
new file mode 100644
index 0000000000..6a1612a3b8
--- /dev/null
+++ b/catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/ImpersonationHDFSFileSystemProxy.java
@@ -0,0 +1,71 @@
+/*
+ * 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.catalog.fileset;
+
+import com.google.common.base.Preconditions;
+import java.util.Map;
+import org.apache.gravitino.catalog.hadoop.fs.HDFSFileSystemProxy;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** A FileSystem proxy that supports user impersonation for HDFS FileSystem */
+public class ImpersonationHDFSFileSystemProxy extends HDFSFileSystemProxy {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ImpersonationHDFSFileSystemProxy.class);
+
+ private final ProxyUserHandler proxyUserHandler;
+
+ /**
+ * Create a HDFSAuthenticationFileSystem with the given path and configuration. Supports both
+ * simple and Kerberos authentication and has user impersonation capability.
+ *
+ * @param path the HDFS path
+ * @param config the configuration map of Gravitino
+ * @param handler the handle of retrieving proxy user
+ */
+ public ImpersonationHDFSFileSystemProxy(
+ Path path, Map<String, String> config, ProxyUserHandler handler) {
+ super();
+
+ Preconditions.checkArgument(handler != null, "ProxyUserHandler cannot be null");
+ this.proxyUserHandler = handler;
+ initFileSystem(path, config);
+ }
+
+ protected UserGroupInformation getRequestUser() {
+ if (!impersonationEnabled) {
+ return super.getRequestUser();
+ }
+
+ UserGroupInformation requestUgi;
+ String proxyUserName = proxyUserHandler.getProxyUser();
+ if (!proxyUserName.contains("@")) {
+ proxyUserName = String.format("%s@%s", proxyUserName, kerberosRealm);
+ }
+ requestUgi = UserGroupInformation.createProxyUser(proxyUserName, initUgi);
+ LOG.debug("Using login user with impersonation: {}", initUgi.getUserName());
+ return requestUgi;
+ }
+
+ interface ProxyUserHandler {
+ String getProxyUser();
+ }
+}
diff --git a/catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/SecureFilesetCatalogOperations.java b/catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/SecureFilesetCatalogOperations.java
deleted file mode 100644
index b6d5e9cf0c..0000000000
--- a/catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/SecureFilesetCatalogOperations.java
+++ /dev/null
@@ -1,398 +0,0 @@
-/*
- * 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.catalog.fileset;
-
-import static org.apache.gravitino.file.Fileset.PROPERTY_DEFAULT_LOCATION_NAME;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Preconditions;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.stream.Collectors;
-import javax.security.auth.Subject;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.gravitino.Catalog;
-import org.apache.gravitino.Entity;
-import org.apache.gravitino.EntityStore;
-import org.apache.gravitino.NameIdentifier;
-import org.apache.gravitino.Namespace;
-import org.apache.gravitino.Schema;
-import org.apache.gravitino.SchemaChange;
-import org.apache.gravitino.UserPrincipal;
-import org.apache.gravitino.audit.CallerContext;
-import org.apache.gravitino.catalog.FilesetFileOps;
-import org.apache.gravitino.catalog.fileset.authentication.UserContext;
-import org.apache.gravitino.connector.CatalogInfo;
-import org.apache.gravitino.connector.CatalogOperations;
-import org.apache.gravitino.connector.HasPropertyMetadata;
-import org.apache.gravitino.connector.SupportsSchemas;
-import org.apache.gravitino.connector.credential.PathContext;
-import org.apache.gravitino.connector.credential.SupportsPathBasedCredentials;
-import org.apache.gravitino.credential.CredentialConstants;
-import org.apache.gravitino.credential.CredentialUtils;
-import org.apache.gravitino.exceptions.FilesetAlreadyExistsException;
-import org.apache.gravitino.exceptions.NoSuchCatalogException;
-import org.apache.gravitino.exceptions.NoSuchEntityException;
-import org.apache.gravitino.exceptions.NoSuchFilesetException;
-import org.apache.gravitino.exceptions.NoSuchLocationNameException;
-import org.apache.gravitino.exceptions.NoSuchSchemaException;
-import org.apache.gravitino.exceptions.NonEmptySchemaException;
-import org.apache.gravitino.exceptions.SchemaAlreadyExistsException;
-import org.apache.gravitino.file.FileInfo;
-import org.apache.gravitino.file.Fileset;
-import org.apache.gravitino.file.FilesetCatalog;
-import org.apache.gravitino.file.FilesetChange;
-import org.apache.gravitino.meta.FilesetEntity;
-import org.apache.gravitino.meta.SchemaEntity;
-import org.apache.gravitino.utils.ClassLoaderResourceCleanerUtils;
-import org.apache.gravitino.utils.NameIdentifierUtil;
-import org.apache.gravitino.utils.PrincipalUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-@SuppressWarnings("removal")
-public class SecureFilesetCatalogOperations
- implements CatalogOperations,
- SupportsSchemas,
- FilesetCatalog,
- FilesetFileOps,
- SupportsPathBasedCredentials {
-
- public static final Logger LOG = LoggerFactory.getLogger(SecureFilesetCatalogOperations.class);
-
- private final FilesetCatalogOperations filesetCatalogOperations;
-
- public static final String GRAVITINO_KEYTAB_FORMAT = "keytabs/gravitino-%s";
-
- private UserContext catalogUserContext;
-
- private Map<String, String> catalogProperties;
-
- public SecureFilesetCatalogOperations() {
- this.filesetCatalogOperations = new FilesetCatalogOperations();
- }
-
- public SecureFilesetCatalogOperations(EntityStore store) {
- this.filesetCatalogOperations = new FilesetCatalogOperations(store);
- }
-
- @Override
- public void initialize(
- Map<String, String> config, CatalogInfo info, HasPropertyMetadata propertiesMetadata)
- throws RuntimeException {
- filesetCatalogOperations.initialize(config, info, propertiesMetadata);
- this.catalogUserContext =
- UserContext.getUserContext(NameIdentifier.of(info.namespace(), info.name()), config, info);
- this.catalogProperties = info.properties();
- }
-
- @VisibleForTesting
- public FilesetCatalogOperations getBaseFilesetCatalogOperations() {
- return filesetCatalogOperations;
- }
-
- @Override
- public Fileset createMultipleLocationFileset(
- NameIdentifier ident,
- String comment,
- Fileset.Type type,
- Map<String, String> storageLocations,
- Map<String, String> properties)
- throws NoSuchSchemaException, FilesetAlreadyExistsException {
- String apiUser = PrincipalUtils.getCurrentUserName();
-
- Map<String, String> filesetProperties = mergeUpLevelConfigurations(ident, properties);
- UserContext userContext =
- UserContext.getUserContext(
- ident, filesetProperties, filesetCatalogOperations.getCatalogInfo());
- return userContext.doAs(
- () -> {
- try {
- setUser(apiUser);
- return filesetCatalogOperations.createMultipleLocationFileset(
- ident, comment, type, storageLocations, properties);
- } finally {
- unsetUser(apiUser);
- }
- },
- ident);
- }
-
- @Override
- public boolean dropFileset(NameIdentifier ident) {
- FilesetEntity filesetEntity;
- try {
- filesetEntity =
- filesetCatalogOperations
- .store()
- .get(ident, Entity.EntityType.FILESET, FilesetEntity.class);
- } catch (NoSuchEntityException e) {
- LOG.warn("Fileset {} does not exist", ident);
- return false;
- } catch (IOException ioe) {
- throw new RuntimeException("Failed to delete fileset " + ident, ioe);
- }
-
- Map<String, String> filesetProperties =
- mergeUpLevelConfigurations(ident, filesetEntity.properties());
- UserContext userContext =
- UserContext.getUserContext(
- ident, filesetProperties, filesetCatalogOperations.getCatalogInfo());
- boolean r = userContext.doAs(() -> filesetCatalogOperations.dropFileset(ident), ident);
- UserContext.clearUserContext(ident);
- return r;
- }
-
- public Map<String, String> mergeUpLevelConfigurations(
- NameIdentifier ident, Map<String, String> entityProperties) {
- Map<String, String> mergedProperties = new HashMap<>(filesetCatalogOperations.getConf());
- if (ident.namespace().levels().length == 2) {
- // schema level
- mergedProperties.putAll(entityProperties);
- return mergedProperties;
- }
-
- // fileset level
- NameIdentifierUtil.checkFileset(ident);
- NameIdentifier schemaIdent = NameIdentifierUtil.getSchemaIdentifier(ident);
- Schema schema = filesetCatalogOperations.loadSchema(schemaIdent);
- mergedProperties.putAll(schema.properties());
- mergedProperties.putAll(entityProperties);
- return mergedProperties;
- }
-
- @Override
- public Schema createSchema(NameIdentifier ident, String comment, Map<String, String> properties)
- throws NoSuchCatalogException, SchemaAlreadyExistsException {
- Map<String, String> schemaProperties = mergeUpLevelConfigurations(ident, properties);
- String apiUser = PrincipalUtils.getCurrentUserName();
- UserContext userContext =
- UserContext.getUserContext(
- ident, schemaProperties, filesetCatalogOperations.getCatalogInfo());
- return userContext.doAs(
- () -> {
- try {
- setUser(apiUser);
- return filesetCatalogOperations.createSchema(ident, comment, properties);
- } finally {
- unsetUser(apiUser);
- }
- },
- ident);
- }
-
- @Override
- public boolean dropSchema(NameIdentifier ident, boolean cascade) throws NonEmptySchemaException {
- try {
- SchemaEntity schemaEntity =
- filesetCatalogOperations.store().get(ident, Entity.EntityType.SCHEMA, SchemaEntity.class);
-
- Map<String, String> schemaProperties =
- mergeUpLevelConfigurations(ident, schemaEntity.properties());
- UserContext userContext =
- UserContext.getUserContext(
- ident, schemaProperties, filesetCatalogOperations.getCatalogInfo());
- boolean r =
- userContext.doAs(() -> filesetCatalogOperations.dropSchema(ident, cascade), ident);
- UserContext.clearUserContext(ident);
-
- return r;
- } catch (NoSuchEntityException e) {
- LOG.warn("Schema {} does not exist", ident);
- return false;
-
- } catch (IOException ioe) {
- throw new RuntimeException("Failed to delete schema " + ident, ioe);
- }
- }
-
- @Override
- public Fileset alterFileset(NameIdentifier ident, FilesetChange... changes)
- throws NoSuchFilesetException, IllegalArgumentException {
- Fileset fileset = filesetCatalogOperations.alterFileset(ident, changes);
-
- String finalName = ident.name();
- for (FilesetChange change : changes) {
- if (change instanceof FilesetChange.RenameFileset) {
- finalName = ((FilesetChange.RenameFileset) change).getNewName();
- }
- }
- if (!ident.name().equals(finalName)) {
- UserContext.clearUserContext(NameIdentifier.of(ident.namespace(), finalName));
- }
-
- return fileset;
- }
-
- @Override
- public NameIdentifier[] listSchemas(Namespace namespace) throws NoSuchCatalogException {
- return filesetCatalogOperations.listSchemas(namespace);
- }
-
- @Override
- public Schema loadSchema(NameIdentifier ident) throws NoSuchSchemaException {
- return filesetCatalogOperations.loadSchema(ident);
- }
-
- @Override
- public Schema alterSchema(NameIdentifier ident, SchemaChange... changes)
- throws NoSuchSchemaException {
- return filesetCatalogOperations.alterSchema(ident, changes);
- }
-
- @Override
- public NameIdentifier[] listFilesets(Namespace namespace) throws NoSuchSchemaException {
- return filesetCatalogOperations.listFilesets(namespace);
- }
-
- @Override
- public FileInfo[] listFiles(NameIdentifier ident, String locationName, String subPath)
- throws NoSuchFilesetException, IOException {
- return filesetCatalogOperations.listFiles(ident, locationName, subPath);
- }
-
- @Override
- public Fileset loadFileset(NameIdentifier ident) throws NoSuchFilesetException {
- return filesetCatalogOperations.loadFileset(ident);
- }
-
- @Override
- public String getFileLocation(NameIdentifier ident, String subPath, String locationName)
- throws NoSuchFilesetException, NoSuchLocationNameException {
- return filesetCatalogOperations.getFileLocation(ident, subPath, locationName);
- }
-
- @Override
- public void close() throws IOException {
- filesetCatalogOperations.close();
-
- catalogUserContext.close();
-
- UserContext.cleanAllUserContext();
-
- ClassLoaderResourceCleanerUtils.closeClassLoaderResource(this.getClass().getClassLoader());
- }
-
- @Override
- public void testConnection(
- NameIdentifier catalogIdent,
- Catalog.Type type,
- String provider,
- String comment,
- Map<String, String> properties) {
- filesetCatalogOperations.testConnection(catalogIdent, type, provider, comment, properties);
- }
-
- @Override
- public List<PathContext> getPathContext(NameIdentifier filesetIdentifier) {
- Fileset fileset = loadFileset(filesetIdentifier);
- String path = getTargetLocation(fileset);
-
- Set<String> providers =
- CredentialUtils.getCredentialProvidersByOrder(
- fileset::properties,
- () -> {
- Namespace namespace = filesetIdentifier.namespace();
- NameIdentifier schemaIdentifier =
- NameIdentifierUtil.ofSchema(
- namespace.level(0), namespace.level(1), namespace.level(2));
- return loadSchema(schemaIdentifier).properties();
- },
- () -> catalogProperties);
- return providers.stream()
- .map(provider -> new PathContext(path, provider))
- .collect(Collectors.toList());
- }
-
- @VisibleForTesting
- protected String getTargetLocation(Fileset fileset) {
- CallerContext callerContext = CallerContext.CallerContextHolder.get();
- String targetLocationName;
- String targetLocation;
- if (callerContext != null
- && callerContext
- .context()
- .containsKey(CredentialConstants.HTTP_HEADER_CURRENT_LOCATION_NAME)) {
- // case 1: target location name is passed in the header
- targetLocationName =
- callerContext.context().get(CredentialConstants.HTTP_HEADER_CURRENT_LOCATION_NAME);
- Preconditions.checkArgument(
- fileset.storageLocations().containsKey(targetLocationName),
- "The location name %s is not in the fileset %s, expected location names are %s",
- targetLocationName,
- fileset.name(),
- fileset.storageLocations().keySet());
- targetLocation = fileset.storageLocations().get(targetLocationName);
-
- } else if (fileset.storageLocations().size() == 1) {
- // case 2: target location name is not passed in the header, but there is only one location.
- // note: mainly used for backward compatibility since the old code does not pass the header
- // and only supports one location
- targetLocation = fileset.storageLocations().values().iterator().next();
- targetLocationName = fileset.storageLocations().keySet().iterator().next();
-
- } else {
- // case 3: target location name is not passed in the header, and there are multiple locations.
- // use the default location name
- targetLocationName = fileset.properties().get(PROPERTY_DEFAULT_LOCATION_NAME);
- // this should never happen, but just in case
- Preconditions.checkArgument(
- StringUtils.isNotBlank(targetLocationName),
- "The default location name of the fileset %s should not be empty.",
- fileset.name());
- targetLocation = fileset.storageLocations().get(targetLocationName);
- }
-
- Preconditions.checkArgument(
- StringUtils.isNotBlank(targetLocation),
- "The location with the location name %s of the fileset %s should not be empty.",
- targetLocationName,
- fileset.name());
- return targetLocation;
- }
-
- /**
- * Add the user to the subject so that we can get the last user in the subject. Fileset catalog
- * uses this method to pass api user from the client side, so that we can get the user in the
- * subject. Please do not mix it with UserGroupInformation.getCurrentUser().
- *
- * @param apiUser the username to set.
- */
- private void setUser(String apiUser) {
- java.security.AccessControlContext context = java.security.AccessController.getContext();
- Subject subject = Subject.getSubject(context);
- subject.getPrincipals().add(new UserPrincipal(apiUser));
- }
-
- /**
- * Unset the user from the subject. This is used to remove the api user from the subject after the
- * operation is done.
- *
- * @param apiUser the username to unset.
- */
- private void unsetUser(String apiUser) {
- java.security.AccessControlContext context = java.security.AccessController.getContext();
- Subject subject = Subject.getSubject(context);
- subject.getPrincipals().removeIf(principal -> principal.getName().equals(apiUser));
- }
-}
diff --git a/catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/authentication/KerberosUserContext.java b/catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/authentication/KerberosUserContext.java
deleted file mode 100644
index 2d04defa85..0000000000
--- a/catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/authentication/KerberosUserContext.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * 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.catalog.fileset.authentication;
-
-import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Locale;
-import java.util.Map;
-import org.apache.gravitino.catalog.fileset.authentication.kerberos.KerberosClient;
-import org.apache.gravitino.utils.PrincipalUtils;
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.security.UserGroupInformation;
-import org.apache.hadoop.security.UserGroupInformation.AuthenticationMethod;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class KerberosUserContext extends UserContext {
- public static final Logger LOGGER = LoggerFactory.getLogger(KerberosUserContext.class);
-
- private UserGroupInformation userGroupInformation;
- private boolean enableUserImpersonation;
- private String kerberosRealm;
- private final String keytab;
-
- private KerberosClient kerberosClient;
-
- KerberosUserContext(boolean enableUserImpersonation, String keytabPath) {
- this.enableUserImpersonation = enableUserImpersonation;
- this.keytab = keytabPath;
- }
-
- public void setEnableUserImpersonation(boolean enableUserImpersonation) {
- this.enableUserImpersonation = enableUserImpersonation;
- }
-
- public synchronized void initKerberos(
- Map<String, String> properties, Configuration configuration, boolean refreshCredentials) {
- configuration.set(
- HADOOP_SECURITY_AUTHENTICATION,
- AuthenticationMethod.KERBEROS.name().toLowerCase(Locale.ROOT));
- try {
- KerberosClient client = new KerberosClient(properties, configuration, refreshCredentials);
- // Add the kerberos client to the closable to close resources.
- this.kerberosClient = client;
- File keytabFile = client.saveKeyTabFileFromUri(keytab);
- this.kerberosRealm = client.login(keytabFile.getAbsolutePath());
- this.userGroupInformation = UserGroupInformation.getLoginUser();
- } catch (IOException e) {
- throw new RuntimeException("Failed to login with Kerberos", e);
- }
- }
-
- @Override
- UserGroupInformation createProxyUser() {
- String proxyKerberosPrincipalName = PrincipalUtils.getCurrentUserName();
- if (!proxyKerberosPrincipalName.contains("@")) {
- proxyKerberosPrincipalName =
- String.format("%s@%s", proxyKerberosPrincipalName, kerberosRealm);
- }
-
- return UserGroupInformation.createProxyUser(proxyKerberosPrincipalName, getUser());
- }
-
- @Override
- UserGroupInformation getUser() {
- return userGroupInformation;
- }
-
- @Override
- boolean enableUserImpersonation() {
- return enableUserImpersonation;
- }
-
- @Override
- public void close() throws IOException {
- if (kerberosClient != null) {
- kerberosClient.close();
- }
-
- if (keytab == null) {
- return;
- }
-
- File file = new File(keytab);
- if (file.exists()) {
- boolean isDeleted = file.delete();
- if (!isDeleted) {
- LOGGER.error("Failed to delete file: {}", keytab);
- }
- }
- }
-
- public KerberosUserContext deepCopy() {
- KerberosUserContext copy = new KerberosUserContext(enableUserImpersonation, keytab);
- copy.userGroupInformation = userGroupInformation;
- copy.kerberosRealm = kerberosRealm;
- return copy;
- }
-}
diff --git a/catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/authentication/SimpleUserContext.java b/catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/authentication/SimpleUserContext.java
deleted file mode 100644
index 3ffa58fdb5..0000000000
--- a/catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/authentication/SimpleUserContext.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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.catalog.fileset.authentication;
-
-import java.io.IOException;
-import org.apache.gravitino.utils.PrincipalUtils;
-import org.apache.hadoop.security.UserGroupInformation;
-
-public class SimpleUserContext extends UserContext {
- private final UserGroupInformation userGroupInformation;
- private final boolean enableUserImpersonation;
-
- SimpleUserContext(UserGroupInformation userGroupInformation, boolean enableUserImpersonation) {
- this.userGroupInformation = userGroupInformation;
- this.enableUserImpersonation = enableUserImpersonation;
- }
-
- @Override
- UserGroupInformation getUser() {
- return userGroupInformation;
- }
-
- @Override
- boolean enableUserImpersonation() {
- return enableUserImpersonation;
- }
-
- @Override
- public void close() throws IOException {}
-
- @Override
- UserGroupInformation createProxyUser() {
- return UserGroupInformation.createProxyUser(PrincipalUtils.getCurrentUserName(), getUser());
- }
-}
diff --git a/catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/authentication/UserContext.java b/catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/authentication/UserContext.java
deleted file mode 100644
index 5837b2823c..0000000000
--- a/catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/authentication/UserContext.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * 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.catalog.fileset.authentication;
-
-import static org.apache.gravitino.catalog.fileset.SecureFilesetCatalogOperations.GRAVITINO_KEYTAB_FORMAT;
-import static org.apache.gravitino.catalog.fileset.authentication.AuthenticationConfig.ENABLE_IMPERSONATION_ENTRY;
-import static org.apache.gravitino.catalog.fileset.authentication.AuthenticationConfig.IMPERSONATION_ENABLE_KEY;
-import static org.apache.gravitino.catalog.hadoop.fs.FileSystemProvider.GRAVITINO_BYPASS;
-
-import com.google.common.collect.Maps;
-import java.io.Closeable;
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.UndeclaredThrowableException;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
-import java.util.Map;
-import org.apache.gravitino.NameIdentifier;
-import org.apache.gravitino.catalog.fileset.authentication.AuthenticationConfig.AuthenticationType;
-import org.apache.gravitino.catalog.hadoop.fs.FileSystemUtils;
-import org.apache.gravitino.connector.CatalogInfo;
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.security.UserGroupInformation;
-
-public abstract class UserContext implements Closeable {
-
- private static final Map<NameIdentifier, UserContext> userContextMap = Maps.newConcurrentMap();
-
- private static void addUserContext(NameIdentifier nameIdentifier, UserContext userContext) {
- userContextMap.put(nameIdentifier, userContext);
- }
-
- public static void clearUserContext(NameIdentifier nameIdentifier) {
- UserContext userContext = userContextMap.remove(nameIdentifier);
- if (userContext != null) {
- try {
- userContext.close();
- } catch (IOException e) {
- throw new RuntimeException("Failed to close user context", e);
- }
- }
- }
-
- public static void cleanAllUserContext() {
- userContextMap.keySet().forEach(UserContext::clearUserContext);
- userContextMap.clear();
- }
-
- public static UserContext getUserContext(
- NameIdentifier nameIdentifier, Map<String, String> properties, CatalogInfo catalogInfo) {
- Configuration configuration = FileSystemUtils.createConfiguration(GRAVITINO_BYPASS, properties);
- AuthenticationConfig authenticationConfig = new AuthenticationConfig(properties, configuration);
-
- // If we do not set the impersonation, we will use the parent context;
- boolean enableUserImpersonation = ENABLE_IMPERSONATION_ENTRY.getDefaultValue();
- if (properties.containsKey(IMPERSONATION_ENABLE_KEY)) {
- enableUserImpersonation = authenticationConfig.isImpersonationEnabled();
- }
-
- AuthenticationType authenticationType =
- authenticationConfig.isSimpleAuth()
- ? AuthenticationType.SIMPLE
- : AuthenticationType.KERBEROS;
-
- UserGroupInformation currentUser;
- try {
- currentUser = UserGroupInformation.getCurrentUser();
- } catch (IOException ioException) {
- throw new RuntimeException("Failed to get current user", ioException);
- }
-
- if (authenticationType == AuthenticationType.SIMPLE) {
- SimpleUserContext simpleUserContext =
- new SimpleUserContext(currentUser, enableUserImpersonation);
- addUserContext(nameIdentifier, simpleUserContext);
- return simpleUserContext;
- } else if (authenticationType == AuthenticationType.KERBEROS) {
- String keytabPath =
- String.format(
- GRAVITINO_KEYTAB_FORMAT,
- catalogInfo.id() + "-" + nameIdentifier.toString().replace(".", "-"));
- KerberosUserContext kerberosUserContext =
- new KerberosUserContext(enableUserImpersonation, keytabPath);
- kerberosUserContext.initKerberos(properties, configuration, true);
- addUserContext(nameIdentifier, kerberosUserContext);
- return kerberosUserContext;
- } else {
- throw new RuntimeException("Unsupported authentication type: " + authenticationType);
- }
- }
-
- abstract UserGroupInformation getUser();
-
- abstract boolean enableUserImpersonation();
-
- abstract UserGroupInformation createProxyUser();
-
- public <T> T doAs(PrivilegedExceptionAction<T> action, NameIdentifier ident) {
- UserGroupInformation u = getUser();
- if (enableUserImpersonation()) {
- u = createProxyUser();
- }
-
- try {
- return u.doAs(action);
- } catch (IOException | InterruptedException ioe) {
- throw new RuntimeException("Failed to operation on entity:" + ident, ioe);
- } catch (UndeclaredThrowableException e) {
- Throwable innerException = e.getCause();
- if (innerException instanceof PrivilegedActionException) {
- throw new RuntimeException(innerException.getCause());
- } else if (innerException instanceof InvocationTargetException) {
- throw new RuntimeException(innerException.getCause());
- } else {
- throw new RuntimeException(innerException);
- }
- }
- }
-}
diff --git a/catalogs/catalog-fileset/src/test/java/org/apache/gravitino/catalog/fileset/TestFilesetCatalogOperations.java b/catalogs/catalog-fileset/src/test/java/org/apache/gravitino/catalog/fileset/TestFilesetCatalogOperations.java
index d73e3d54dd..6d59d261a9 100644
--- a/catalogs/catalog-fileset/src/test/java/org/apache/gravitino/catalog/fileset/TestFilesetCatalogOperations.java
+++ b/catalogs/catalog-fileset/src/test/java/org/apache/gravitino/catalog/fileset/TestFilesetCatalogOperations.java
@@ -354,9 +354,7 @@ public class TestFilesetCatalogOperations {
@Test
public void testFilesetCatalogConfiguration() {
Map<String, String> emptyProps = Maps.newHashMap();
- SecureFilesetCatalogOperations secOps = new SecureFilesetCatalogOperations(store);
-
- FilesetCatalogOperations ops = secOps.getBaseFilesetCatalogOperations();
+ FilesetCatalogOperations ops = new FilesetCatalogOperations(store);
CatalogInfo catalogInfo = randomCatalogInfo();
ops.initialize(emptyProps, catalogInfo, FILESET_PROPERTIES_METADATA);
@@ -561,7 +559,7 @@ public class TestFilesetCatalogOperations {
Assertions.assertEquals(name, schema.name());
- try (SecureFilesetCatalogOperations ops = new SecureFilesetCatalogOperations(store)) {
+ try (FilesetCatalogOperations ops = new FilesetCatalogOperations(store)) {
ops.initialize(Maps.newHashMap(), randomCatalogInfo(), FILESET_PROPERTIES_METADATA);
Schema schema1 = ops.loadSchema(NameIdentifierUtil.ofSchema("m1", "c1", name));
Assertions.assertEquals(name, schema1.name());
@@ -587,7 +585,7 @@ public class TestFilesetCatalogOperations {
createSchema(testId1, name1, comment1, null, null);
createSchema(testId2, name2, comment2, null, null);
- try (SecureFilesetCatalogOperations ops = new SecureFilesetCatalogOperations(store)) {
+ try (FilesetCatalogOperations ops = new FilesetCatalogOperations(store)) {
ops.initialize(Maps.newHashMap(), randomCatalogInfo(), FILESET_PROPERTIES_METADATA);
Set<NameIdentifier> idents =
Arrays.stream(ops.listSchemas(Namespace.of("m1", "c1"))).collect(Collectors.toSet());
@@ -606,7 +604,7 @@ public class TestFilesetCatalogOperations {
Schema schema = createSchema(testId, name, comment, catalogPath, null);
Assertions.assertEquals(name, schema.name());
- try (SecureFilesetCatalogOperations ops = new SecureFilesetCatalogOperations(store)) {
+ try (FilesetCatalogOperations ops = new FilesetCatalogOperations(store)) {
ops.initialize(Maps.newHashMap(), randomCatalogInfo(), FILESET_PROPERTIES_METADATA);
Schema schema1 = ops.loadSchema(NameIdentifierUtil.ofSchema("m1", "c1", name));
Assertions.assertEquals(name, schema1.name());
@@ -655,7 +653,7 @@ public class TestFilesetCatalogOperations {
Assertions.assertEquals(schemaName, schema.name());
NameIdentifier id = NameIdentifierUtil.ofSchema("m1", "c1", schemaName);
- try (SecureFilesetCatalogOperations ops = new SecureFilesetCatalogOperations(store)) {
+ try (FilesetCatalogOperations ops = new FilesetCatalogOperations(store)) {
ops.initialize(
ImmutableMap.of(LOCATION, catalogPath),
randomCatalogInfo("m1", "c1"),
@@ -727,7 +725,7 @@ public class TestFilesetCatalogOperations {
Assertions.assertEquals(schemaName, schema.name());
NameIdentifier id = NameIdentifierUtil.ofSchema("m1", "c1", schemaName);
- try (SecureFilesetCatalogOperations ops = new SecureFilesetCatalogOperations(store)) {
+ try (FilesetCatalogOperations ops = new FilesetCatalogOperations(store)) {
ops.initialize(
ImmutableMap.of(LOCATION, catalogPath, DISABLE_FILESYSTEM_OPS, "true"),
randomCatalogInfo("m1", "c1"),
@@ -769,7 +767,7 @@ public class TestFilesetCatalogOperations {
}
NameIdentifier schemaIdent = NameIdentifierUtil.ofSchema("m1", "c1", schemaName);
- try (SecureFilesetCatalogOperations ops = new SecureFilesetCatalogOperations(store)) {
+ try (FilesetCatalogOperations ops = new FilesetCatalogOperations(store)) {
ops.initialize(catalogProps, randomCatalogInfo("m1", "c1"), FILESET_PROPERTIES_METADATA);
if (!ops.schemaExists(schemaIdent)) {
createSchema(generateTestId(), schemaName, comment, catalogPath, schemaPath);
@@ -826,7 +824,7 @@ public class TestFilesetCatalogOperations {
}
NameIdentifier schemaIdent = NameIdentifierUtil.ofSchema("m1", "c1", schemaName);
- try (SecureFilesetCatalogOperations ops = new SecureFilesetCatalogOperations(store)) {
+ try (FilesetCatalogOperations ops = new FilesetCatalogOperations(store)) {
ops.initialize(catalogProps, randomCatalogInfo("m1", "c1"), FILESET_PROPERTIES_METADATA);
if (!ops.schemaExists(schemaIdent)) {
createSchema(generateTestId(), schemaName, comment, catalogPath, schemaPath, true);
@@ -902,7 +900,7 @@ public class TestFilesetCatalogOperations {
+ " when it's catalog and schema "
+ "location are not set",
exception.getMessage());
- try (SecureFilesetCatalogOperations ops = new SecureFilesetCatalogOperations(store)) {
+ try (FilesetCatalogOperations ops = new FilesetCatalogOperations(store)) {
ops.initialize(Maps.newHashMap(), randomCatalogInfo(), FILESET_PROPERTIES_METADATA);
Throwable e =
Assertions.assertThrows(
@@ -921,7 +919,7 @@ public class TestFilesetCatalogOperations {
Assertions.assertEquals(
"Storage location must be set for external fileset " + filesetIdent,
exception1.getMessage());
- try (SecureFilesetCatalogOperations ops = new SecureFilesetCatalogOperations(store)) {
+ try (FilesetCatalogOperations ops = new FilesetCatalogOperations(store)) {
ops.initialize(Maps.newHashMap(), randomCatalogInfo(), FILESET_PROPERTIES_METADATA);
Throwable e =
Assertions.assertThrows(
@@ -946,7 +944,7 @@ public class TestFilesetCatalogOperations {
createFileset(fileset, schemaName, comment, Fileset.Type.MANAGED, null, null);
}
- try (SecureFilesetCatalogOperations ops = new SecureFilesetCatalogOperations(store)) {
+ try (FilesetCatalogOperations ops = new FilesetCatalogOperations(store)) {
ops.initialize(Maps.newHashMap(), randomCatalogInfo(), FILESET_PROPERTIES_METADATA);
Set<NameIdentifier> idents =
Arrays.stream(ops.listFilesets(Namespace.of("m1", "c1", schemaName)))
@@ -970,7 +968,7 @@ public class TestFilesetCatalogOperations {
createSchema(testId, schemaName, comment, null, schemaPath);
createFileset(filesetName, schemaName, comment, Fileset.Type.MANAGED, null, null);
- try (SecureFilesetCatalogOperations ops = new SecureFilesetCatalogOperations(store)) {
+ try (FilesetCatalogOperations ops = new FilesetCatalogOperations(store)) {
ops.initialize(Maps.newHashMap(), randomCatalogInfo(), FILESET_PROPERTIES_METADATA);
Path testDir = new Path(schemaPath + "/" + filesetName);
@@ -1022,7 +1020,7 @@ public class TestFilesetCatalogOperations {
Map<String, String> catalogProps = Collections.singletonMap(DISABLE_FILESYSTEM_OPS, "true");
- try (SecureFilesetCatalogOperations ops = new SecureFilesetCatalogOperations(store)) {
+ try (FilesetCatalogOperations ops = new FilesetCatalogOperations(store)) {
ops.initialize(catalogProps, randomCatalogInfo(), FILESET_PROPERTIES_METADATA);
UnsupportedOperationException ex =
Assertions.assertThrows(
@@ -1050,7 +1048,7 @@ public class TestFilesetCatalogOperations {
final NameIdentifier filesetIdent =
NameIdentifier.of("m1", "c1", schema.name(), fileset.name());
- try (SecureFilesetCatalogOperations ops = new SecureFilesetCatalogOperations(store)) {
+ try (FilesetCatalogOperations ops = new FilesetCatalogOperations(store)) {
ops.initialize(Maps.newHashMap(), randomCatalogInfo(), FILESET_PROPERTIES_METADATA);
IllegalArgumentException ex =
Assertions.assertThrows(
@@ -1083,7 +1081,7 @@ public class TestFilesetCatalogOperations {
}
NameIdentifier schemaIdent = NameIdentifierUtil.ofSchema("m1", "c1", schemaName);
- try (SecureFilesetCatalogOperations ops = new SecureFilesetCatalogOperations(store)) {
+ try (FilesetCatalogOperations ops = new FilesetCatalogOperations(store)) {
ops.initialize(catalogProps, randomCatalogInfo("m1", "c1"), FILESET_PROPERTIES_METADATA);
if (!ops.schemaExists(schemaIdent)) {
createSchema(generateTestId(), schemaName, comment, catalogPath, schemaPath);
@@ -1131,7 +1129,7 @@ public class TestFilesetCatalogOperations {
FilesetChange change1 = FilesetChange.setProperty("k1", "v1");
FilesetChange change2 = FilesetChange.removeProperty("k1");
- try (SecureFilesetCatalogOperations ops = new SecureFilesetCatalogOperations(store)) {
+ try (FilesetCatalogOperations ops = new FilesetCatalogOperations(store)) {
ops.initialize(Maps.newHashMap(), randomCatalogInfo(), FILESET_PROPERTIES_METADATA);
NameIdentifier filesetIdent = NameIdentifier.of("m1", "c1", schemaName, filesetName);
@@ -1243,7 +1241,7 @@ public class TestFilesetCatalogOperations {
Fileset fileset = createFileset(name, schemaName, comment, Fileset.Type.MANAGED, null, null);
FilesetChange change1 = FilesetChange.updateComment(comment + "_new");
- try (SecureFilesetCatalogOperations ops = new SecureFilesetCatalogOperations(store)) {
+ try (FilesetCatalogOperations ops = new FilesetCatalogOperations(store)) {
ops.initialize(Maps.newHashMap(), randomCatalogInfo(), FILESET_PROPERTIES_METADATA);
NameIdentifier filesetIdent = NameIdentifier.of("m1", "c1", schemaName, name);
@@ -1268,7 +1266,7 @@ public class TestFilesetCatalogOperations {
createFileset(filesetName, schemaName, comment, Fileset.Type.MANAGED, null, null);
FilesetChange change1 = FilesetChange.updateComment(null);
- try (SecureFilesetCatalogOperations ops = new SecureFilesetCatalogOperations(store)) {
+ try (FilesetCatalogOperations ops = new FilesetCatalogOperations(store)) {
ops.initialize(Maps.newHashMap(), randomCatalogInfo(), FILESET_PROPERTIES_METADATA);
NameIdentifier filesetIdent = NameIdentifier.of("m1", "c1", schemaName, filesetName);
@@ -1282,7 +1280,7 @@ public class TestFilesetCatalogOperations {
@Test
public void testTestConnection() {
- SecureFilesetCatalogOperations catalogOperations = new SecureFilesetCatalogOperations(store);
+ FilesetCatalogOperations catalogOperations = new FilesetCatalogOperations(store);
Assertions.assertDoesNotThrow(
() ->
catalogOperations.testConnection(
@@ -1295,7 +1293,7 @@ public class TestFilesetCatalogOperations {
@Test
void testTrailSlash() throws IOException {
- try (SecureFilesetCatalogOperations ops = new SecureFilesetCatalogOperations(store)) {
+ try (FilesetCatalogOperations ops = new FilesetCatalogOperations(store)) {
String location = "hdfs://localhost:9000";
Map<String, String> catalogProperties = Maps.newHashMap();
@@ -1342,7 +1340,7 @@ public class TestFilesetCatalogOperations {
createFileset(
filesetName, schemaName, comment, Fileset.Type.MANAGED, null, storageLocation);
- try (SecureFilesetCatalogOperations ops = new SecureFilesetCatalogOperations(store)) {
+ try (FilesetCatalogOperations ops = new FilesetCatalogOperations(store)) {
ops.initialize(Maps.newHashMap(), randomCatalogInfo(), FILESET_PROPERTIES_METADATA);
NameIdentifier filesetIdent = NameIdentifier.of("m1", "c1", schemaName, filesetName);
// test sub path starts with "/"
@@ -1458,6 +1456,13 @@ public class TestFilesetCatalogOperations {
})
.scheduler(Scheduler.forScheduledExecutorService(mockOps.scheduler))
.build();
+ FieldUtils.writeField(
+ mockOps,
+ "fileSystemProvidersMap",
+ ImmutableMap.<String, FileSystemProvider>builder()
+ .putAll(FileSystemUtils.getFileSystemProviders())
+ .build(),
+ true);
when(mockOps.loadFileset(filesetIdent)).thenReturn(mockFileset);
when(mockOps.getConf()).thenReturn(Maps.newHashMap());
String subPath = "/test/test.parquet";
@@ -1477,6 +1482,8 @@ public class TestFilesetCatalogOperations {
mockOps.getFileSystemWithCache(new Path("file:///dir1/subdir/file2"), mockOps.getConf());
Assertions.assertSame(fs1, fs2);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
}
}
@@ -1591,7 +1598,7 @@ public class TestFilesetCatalogOperations {
}
NameIdentifier schemaIdent = NameIdentifierUtil.ofSchema("m1", "c1", schemaName);
- try (SecureFilesetCatalogOperations ops = new SecureFilesetCatalogOperations(store)) {
+ try (FilesetCatalogOperations ops = new FilesetCatalogOperations(store)) {
ops.initialize(catalogProps, randomCatalogInfo("m1", "c1"), FILESET_PROPERTIES_METADATA);
if (!ops.schemaExists(schemaIdent)) {
createSchema(generateTestId(), schemaName, comment, catalogPath, schemaPath);
@@ -1646,7 +1653,7 @@ public class TestFilesetCatalogOperations {
String comment = "comment_s1";
NameIdentifier schemaIdent = NameIdentifierUtil.ofSchema("m1", "c1", schemaName);
- try (SecureFilesetCatalogOperations ops = new SecureFilesetCatalogOperations(store)) {
+ try (FilesetCatalogOperations ops = new FilesetCatalogOperations(store)) {
ops.initialize(catalogPaths, randomCatalogInfo("m1", "c1"), FILESET_PROPERTIES_METADATA);
if (!ops.schemaExists(schemaIdent)) {
createMultiLocationSchema(schemaName, comment, catalogPaths, schemaPaths);
@@ -1714,7 +1721,7 @@ public class TestFilesetCatalogOperations {
// empty location name in catalog location
Map<String, String> illegalLocations =
ImmutableMap.of(PROPERTY_MULTIPLE_LOCATIONS_PREFIX + "", TEST_ROOT_PATH + "/catalog31_1");
- try (SecureFilesetCatalogOperations ops = new SecureFilesetCatalogOperations(store)) {
+ try (FilesetCatalogOperations ops = new FilesetCatalogOperations(store)) {
Exception exception =
Assertions.assertThrows(
IllegalArgumentException.class,
@@ -1825,7 +1832,7 @@ public class TestFilesetCatalogOperations {
@Test
public void testGetTargetLocation() throws IOException {
- try (SecureFilesetCatalogOperations ops = new SecureFilesetCatalogOperations(store)) {
+ try (FilesetCatalogOperations ops = new FilesetCatalogOperations(store)) {
ops.initialize(
Collections.emptyMap(), randomCatalogInfo("m1", "c1"), FILESET_PROPERTIES_METADATA);
@@ -1906,9 +1913,14 @@ public class TestFilesetCatalogOperations {
Exception e =
Assertions.assertThrows(
IOException.class,
- () ->
+ () -> {
+ try {
filesetCatalogOperations.getFileSystem(
- new Path("file:///tmp"), ImmutableMap.of()));
+ new Path("file:///tmp"), ImmutableMap.of());
+ } catch (Exception xe) {
+ throw xe;
+ }
+ });
Assertions.assertTrue(e.getMessage().contains("Failed to get FileSystem for path"));
}
@@ -2930,7 +2942,7 @@ public class TestFilesetCatalogOperations {
props.put(LOCATION, catalogPath);
}
- try (SecureFilesetCatalogOperations ops = new SecureFilesetCatalogOperations(store)) {
+ try (FilesetCatalogOperations ops = new FilesetCatalogOperations(store)) {
ops.initialize(props, randomCatalogInfo("m1", "c1"), FILESET_PROPERTIES_METADATA);
NameIdentifier schemaIdent = NameIdentifierUtil.ofSchema("m1", "c1", name);
@@ -2952,7 +2964,7 @@ public class TestFilesetCatalogOperations {
Map<String, String> catalogPaths,
Map<String, String> schemaPaths)
throws IOException {
- try (SecureFilesetCatalogOperations ops = new SecureFilesetCatalogOperations(store)) {
+ try (FilesetCatalogOperations ops = new FilesetCatalogOperations(store)) {
ops.initialize(catalogPaths, randomCatalogInfo("m1", "c1"), FILESET_PROPERTIES_METADATA);
NameIdentifier schemaIdent = NameIdentifierUtil.ofSchema("m1", "c1", name);
@@ -2974,7 +2986,7 @@ public class TestFilesetCatalogOperations {
Map<String, String> storageLocations,
Map<String, String> filesetProps)
throws IOException {
- try (SecureFilesetCatalogOperations ops = new SecureFilesetCatalogOperations(store)) {
+ try (FilesetCatalogOperations ops = new FilesetCatalogOperations(store)) {
ops.initialize(catalogPaths, randomCatalogInfo("m1", "c1"), FILESET_PROPERTIES_METADATA);
NameIdentifier filesetIdent = NameIdentifier.of("m1", "c1", schemaName, name);
@@ -3013,7 +3025,7 @@ public class TestFilesetCatalogOperations {
props.put(LOCATION, catalogPath);
}
- try (SecureFilesetCatalogOperations ops = new SecureFilesetCatalogOperations(store)) {
+ try (FilesetCatalogOperations ops = new FilesetCatalogOperations(store)) {
ops.initialize(props, randomCatalogInfo("m1", "c1"), FILESET_PROPERTIES_METADATA);
NameIdentifier filesetIdent = NameIdentifier.of("m1", "c1", schemaName, name);
@@ -3039,7 +3051,7 @@ public class TestFilesetCatalogOperations {
props.put(LOCATION, catalogPath);
}
- try (SecureFilesetCatalogOperations ops = new SecureFilesetCatalogOperations(store)) {
+ try (FilesetCatalogOperations ops = new FilesetCatalogOperations(store)) {
ops.initialize(props, randomCatalogInfo("m1", "c1"), FILESET_PROPERTIES_METADATA);
NameIdentifier filesetIdent = NameIdentifier.of("m1", "c1", schemaName, name);
@@ -3054,4 +3066,152 @@ public class TestFilesetCatalogOperations {
private long generateTestId() {
return idGenerator.nextId();
}
+
+ @Test
+ public void testMergeUpLevelConfigurations() throws Exception {
+ final long testId = generateTestId();
+ final String schemaName = "schema" + testId;
+ final String schemaPath = TEST_ROOT_PATH + "/" + schemaName;
+ final String filesetName = "fileset" + testId;
+
+ Map<String, String> catalogProps = Maps.newHashMap();
+ catalogProps.put(LOCATION, TEST_ROOT_PATH);
+ catalogProps.put("catalog-prop", "catalog-value");
+ catalogProps.put("common-prop", "catalog-common-value");
+
+ try (FilesetCatalogOperations ops = new FilesetCatalogOperations(store)) {
+ ops.initialize(catalogProps, randomCatalogInfo("m1", "c1"), FILESET_PROPERTIES_METADATA);
+
+ // Create schema
+ NameIdentifier schemaIdent = NameIdentifierUtil.ofSchema("m1", "c1", schemaName);
+ Map<String, String> schemaProps = Maps.newHashMap();
+ schemaProps.put(LOCATION, schemaPath);
+ schemaProps.put("schema-prop", "schema-value");
+ schemaProps.put("common-prop", "schema-common-value"); // Override catalog common-prop
+ StringIdentifier stringId = StringIdentifier.fromId(idGenerator.nextId());
+ schemaProps = Maps.newHashMap(StringIdentifier.newPropertiesWithId(stringId, schemaProps));
+ Schema schema = ops.createSchema(schemaIdent, "comment", schemaProps);
+
+ Path schemaTestPath = new Path(schemaPath);
+ Map<String, String> schemaResult =
+ ops.mergeUpLevelConfigurations(schemaIdent, schema.properties(), schemaTestPath);
+
+ // Verify schema props override catalog configs (schema location overrides catalog location)
+ Assertions.assertEquals(schemaPath, schemaResult.get(LOCATION));
+ Assertions.assertEquals("catalog-value", schemaResult.get("catalog-prop"));
+ // Verify schema props are included
+ Assertions.assertEquals("schema-value", schemaResult.get("schema-prop"));
+ // Verify property override: schema props override catalog props
+ Assertions.assertEquals("schema-common-value", schemaResult.get("common-prop"));
+
+ // Create fileset
+ NameIdentifier filesetIdent =
+ NameIdentifierUtil.ofFileset("m1", "c1", schemaName, filesetName);
+ Map<String, String> filesetProps = Maps.newHashMap();
+ filesetProps.put("fileset-prop", "fileset-value");
+ filesetProps.put("common-prop", "fileset-common-value"); // Override schema common-prop
+ StringIdentifier filesetStringId = StringIdentifier.fromId(idGenerator.nextId());
+ filesetProps =
+ Maps.newHashMap(StringIdentifier.newPropertiesWithId(filesetStringId, filesetProps));
+ Fileset fileset =
+ ops.createFileset(
+ filesetIdent,
+ "comment",
+ Fileset.Type.MANAGED,
+ schemaPath + "/" + filesetName,
+ filesetProps);
+
+ // Test fileset level configuration merging
+ Path filesetPath = new Path(schemaPath + "/" + filesetName);
+ Map<String, String> filesetResult =
+ ops.mergeUpLevelConfigurations(filesetIdent, fileset.properties(), filesetPath);
+
+ // Verify schema props are included (schema location overrides catalog location)
+ Assertions.assertEquals(schemaPath, filesetResult.get(LOCATION));
+ Assertions.assertEquals("catalog-value", filesetResult.get("catalog-prop"));
+ // Verify schema props are included
+ Assertions.assertEquals("schema-value", filesetResult.get("schema-prop"));
+ // Verify fileset props are included
+ Assertions.assertEquals("fileset-value", filesetResult.get("fileset-prop"));
+ // Verify property override: fileset props override schema props, which override catalog props
+ // Order: catalog -> schema.properties() -> fileset props
+ Assertions.assertEquals("fileset-common-value", filesetResult.get("common-prop"));
+ }
+ }
+
+ @Test
+ public void testMergeUpLevelConfigurationsWithMultipleLocationConfigs() throws Exception {
+ final long testId = generateTestId();
+ final String schemaName = "schema" + testId;
+ final String schemaPath = TEST_ROOT_PATH + "/" + schemaName;
+
+ // Define two different location base paths (scheme://authority)
+ // Use different authorities to distinguish them
+ final String location1BasePath = "s3://bucket1";
+ final String location2BasePath = "s3://bucket2";
+
+ Map<String, String> catalogProps = Maps.newHashMap();
+ catalogProps.put(LOCATION, TEST_ROOT_PATH);
+ // Define location1: fs.path.config.cluster1 = <base_location> (scheme://authority)
+ catalogProps.put(
+ FilesetCatalogPropertiesMetadata.FS_GRAVITINO_PATH_CONFIG_PREFIX + "cluster1",
+ location1BasePath);
+ // Add user-defined configs for location1
+ catalogProps.put(
+ FilesetCatalogPropertiesMetadata.FS_GRAVITINO_PATH_CONFIG_PREFIX + "cluster1.aws-ak",
+ "AK1");
+ catalogProps.put(
+ FilesetCatalogPropertiesMetadata.FS_GRAVITINO_PATH_CONFIG_PREFIX + "cluster1.aws-sk",
+ "SK1");
+ // Define location2: fs.path.config.cluster2 = <base_location> (scheme://authority)
+ catalogProps.put(
+ FilesetCatalogPropertiesMetadata.FS_GRAVITINO_PATH_CONFIG_PREFIX + "cluster2",
+ location2BasePath);
+ // Add user-defined configs for location2
+ catalogProps.put(
+ FilesetCatalogPropertiesMetadata.FS_GRAVITINO_PATH_CONFIG_PREFIX + "cluster2.aws-ak",
+ "AK2");
+ catalogProps.put(
+ FilesetCatalogPropertiesMetadata.FS_GRAVITINO_PATH_CONFIG_PREFIX + "cluster2.endpoint",
+ "s3://endpoint2");
+
+ try (FilesetCatalogOperations ops = new FilesetCatalogOperations(store)) {
+ ops.initialize(catalogProps, randomCatalogInfo("m1", "c1"), FILESET_PROPERTIES_METADATA);
+
+ // Create schema
+ NameIdentifier schemaIdent = NameIdentifierUtil.ofSchema("m1", "c1", schemaName);
+ Map<String, String> schemaProps = Maps.newHashMap();
+ schemaProps.put(LOCATION, schemaPath);
+ StringIdentifier stringId = StringIdentifier.fromId(idGenerator.nextId());
+ schemaProps = Maps.newHashMap(StringIdentifier.newPropertiesWithId(stringId, schemaProps));
+ Schema schema = ops.createSchema(schemaIdent, "comment", schemaProps);
+
+ // Test with path that matches location1 (same scheme://authority)
+ Path testPath1 = new Path(location1BasePath + "/fileset1");
+ Map<String, String> result1 =
+ ops.mergeUpLevelConfigurations(schemaIdent, schema.properties(), testPath1);
+ // Verify location1's configs are extracted from FS_GRAVITINO_PATH_CONFIG_PREFIX
+ Assertions.assertEquals("AK1", result1.get("aws-ak"));
+ Assertions.assertEquals("SK1", result1.get("aws-sk"));
+ Assertions.assertNull(result1.get("endpoint")); // Should not have location2's config
+
+ // Test with path that matches location2 (same scheme://authority)
+ Path testPath2 = new Path(location2BasePath + "/fileset2");
+ Map<String, String> result2 =
+ ops.mergeUpLevelConfigurations(schemaIdent, schema.properties(), testPath2);
+ // Verify location2's configs are extracted from FS_GRAVITINO_PATH_CONFIG_PREFIX
+ Assertions.assertEquals("AK2", result2.get("aws-ak"));
+ Assertions.assertEquals("s3://endpoint2", result2.get("endpoint"));
+ Assertions.assertNull(result2.get("aws-sk")); // Should not have location1's config
+
+ // Test with path that doesn't match any location (different scheme://authority)
+ Path testPath3 = new Path("s3://bucket3/fileset3");
+ Map<String, String> result3 =
+ ops.mergeUpLevelConfigurations(schemaIdent, schema.properties(), testPath3);
+ // Verify no location-specific configs are extracted from FS_GRAVITINO_PATH_CONFIG_PREFIX
+ Assertions.assertNull(result3.get("aws-ak"));
+ Assertions.assertNull(result3.get("aws-sk"));
+ Assertions.assertNull(result3.get("endpoint"));
+ }
+ }
}
diff --git a/catalogs/catalog-fileset/src/test/java/org/apache/gravitino/catalog/fileset/integration/test/HadoopUserAuthenticationIT.java b/catalogs/catalog-fileset/src/test/java/org/apache/gravitino/catalog/fileset/integration/test/HadoopUserAuthenticationIT.java
index 629c772248..5566c889f1 100644
--- a/catalogs/catalog-fileset/src/test/java/org/apache/gravitino/catalog/fileset/integration/test/HadoopUserAuthenticationIT.java
+++ b/catalogs/catalog-fileset/src/test/java/org/apache/gravitino/catalog/fileset/integration/test/HadoopUserAuthenticationIT.java
@@ -19,10 +19,11 @@
package org.apache.gravitino.catalog.fileset.integration.test;
-import static org.apache.gravitino.catalog.fileset.authentication.AuthenticationConfig.AUTH_TYPE_KEY;
-import static org.apache.gravitino.catalog.fileset.authentication.kerberos.KerberosConfig.IMPERSONATION_ENABLE_KEY;
-import static org.apache.gravitino.catalog.fileset.authentication.kerberos.KerberosConfig.KEY_TAB_URI_KEY;
-import static org.apache.gravitino.catalog.fileset.authentication.kerberos.KerberosConfig.PRINCIPAL_KEY;
+import static org.apache.gravitino.catalog.fileset.FilesetCatalogPropertiesMetadata.FILESYSTEM_CONNECTION_TIMEOUT_SECONDS;
+import static org.apache.gravitino.catalog.hadoop.fs.kerberos.AuthenticationConfig.AUTH_TYPE_KEY;
+import static org.apache.gravitino.catalog.hadoop.fs.kerberos.KerberosConfig.IMPERSONATION_ENABLE_KEY;
+import static org.apache.gravitino.catalog.hadoop.fs.kerberos.KerberosConfig.KEY_TAB_URI_KEY;
+import static org.apache.gravitino.catalog.hadoop.fs.kerberos.KerberosConfig.PRINCIPAL_KEY;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableMap;
@@ -312,7 +313,17 @@ public class HadoopUserAuthenticationIT extends BaseIT {
.withClientPrincipal(GRAVITINO_CLIENT_PRINCIPAL)
.withKeyTabFile(new File(TMP_DIR + GRAVITINO_CLIENT_KEYTAB))
.build();
- adminClient = GravitinoAdminClient.builder(serverUri).withKerberosAuth(provider).build();
+ Map<String, String> clientProperties =
+ ImmutableMap.of(
+ "gravitino.client.connectionTimeoutMs",
+ "600000",
+ "gravitino.client.socketTimeoutMs",
+ "600000");
+ adminClient =
+ GravitinoAdminClient.builder(serverUri)
+ .withKerberosAuth(provider)
+ .withClientConfig(clientProperties)
+ .build();
String metalakeName = GravitinoITUtils.genRandomName("metalake");
String catalogName = GravitinoITUtils.genRandomName("catalog");
@@ -327,6 +338,7 @@ public class HadoopUserAuthenticationIT extends BaseIT {
properties.put(IMPERSONATION_ENABLE_KEY, "true");
properties.put(KEY_TAB_URI_KEY, TMP_DIR + HADOOP_CLIENT_KEYTAB);
properties.put(PRINCIPAL_KEY, HADOOP_CLIENT_PRINCIPAL);
+ properties.put(FILESYSTEM_CONNECTION_TIMEOUT_SECONDS, "600");
properties.put("location", location);
properties.put("gravitino.bypass.dfs.namenode.kerberos.principal.pattern", "*");
@@ -552,7 +564,8 @@ public class HadoopUserAuthenticationIT extends BaseIT {
Assertions.assertDoesNotThrow(
() -> catalog.asFilesetCatalog().dropFileset(NameIdentifier.of(SCHEMA_NAME, fileset2)));
- Assertions.assertDoesNotThrow(() -> catalog.asSchemas().dropSchema(SCHEMA_NAME, true));
+ Assertions.assertThrows(
+ Exception.class, () -> catalog.asSchemas().dropSchema(SCHEMA_NAME, true));
kerberosHiveContainer.executeInContainer(
"hadoop", "fs", "-chown", "-R", "cli_schema", "/user/hadoop/" + catalogName);
Assertions.assertDoesNotThrow(() -> catalog.asSchemas().dropSchema(SCHEMA_NAME, true));
diff --git a/catalogs/catalog-fileset/src/test/java/org/apache/gravitino/catalog/fileset/integration/test/HadoopUserImpersonationIT.java b/catalogs/catalog-fileset/src/test/java/org/apache/gravitino/catalog/fileset/integration/test/HadoopUserImpersonationIT.java
index 6a9b493d12..c40f22a57a 100644
--- a/catalogs/catalog-fileset/src/test/java/org/apache/gravitino/catalog/fileset/integration/test/HadoopUserImpersonationIT.java
+++ b/catalogs/catalog-fileset/src/test/java/org/apache/gravitino/catalog/fileset/integration/test/HadoopUserImpersonationIT.java
@@ -19,10 +19,10 @@
package org.apache.gravitino.catalog.fileset.integration.test;
-import static org.apache.gravitino.catalog.fileset.authentication.AuthenticationConfig.AUTH_TYPE_KEY;
-import static org.apache.gravitino.catalog.fileset.authentication.kerberos.KerberosConfig.IMPERSONATION_ENABLE_KEY;
-import static org.apache.gravitino.catalog.fileset.authentication.kerberos.KerberosConfig.KEY_TAB_URI_KEY;
-import static org.apache.gravitino.catalog.fileset.authentication.kerberos.KerberosConfig.PRINCIPAL_KEY;
+import static org.apache.gravitino.catalog.hadoop.fs.kerberos.AuthenticationConfig.AUTH_TYPE_KEY;
+import static org.apache.gravitino.catalog.hadoop.fs.kerberos.KerberosConfig.IMPERSONATION_ENABLE_KEY;
+import static org.apache.gravitino.catalog.hadoop.fs.kerberos.KerberosConfig.KEY_TAB_URI_KEY;
+import static org.apache.gravitino.catalog.hadoop.fs.kerberos.KerberosConfig.PRINCIPAL_KEY;
import static org.apache.hadoop.hdfs.client.HdfsClientConfigKeys.DFS_DATA_TRANSFER_PROTECTION_KEY;
import com.google.common.collect.ImmutableMap;
diff --git a/catalogs/hadoop-common/build.gradle.kts b/catalogs/hadoop-common/build.gradle.kts
index 3bbec78987..47dab24c75 100644
--- a/catalogs/hadoop-common/build.gradle.kts
+++ b/catalogs/hadoop-common/build.gradle.kts
@@ -24,10 +24,15 @@ plugins {
// try to avoid adding extra dependencies because it is used by catalogs and connectors.
dependencies {
implementation(project(":api"))
+ implementation(project(":common"))
+
+ implementation(libs.cglib)
implementation(libs.commons.lang3)
+ implementation(libs.commons.io)
implementation(libs.hadoop3.client.api)
implementation(libs.hadoop3.client.runtime)
implementation(libs.guava)
+ implementation(libs.slf4j.api)
testImplementation(libs.junit.jupiter.api)
testImplementation(libs.junit.jupiter.params)
diff --git a/catalogs/hadoop-common/src/main/java/org/apache/gravitino/catalog/hadoop/fs/FileSystemProvider.java b/catalogs/hadoop-common/src/main/java/org/apache/gravitino/catalog/hadoop/fs/FileSystemProvider.java
index 9c1979345d..b5738383bb 100644
--- a/catalogs/hadoop-common/src/main/java/org/apache/gravitino/catalog/hadoop/fs/FileSystemProvider.java
+++ b/catalogs/hadoop-common/src/main/java/org/apache/gravitino/catalog/hadoop/fs/FileSystemProvider.java
@@ -80,4 +80,15 @@ public interface FileSystemProvider {
* @return The name of this FileSystem provider.
*/
String name();
+
+ /**
+ * Get full authority (user:pw@host:port?xxx=1) from the given path and configuration.
+ *
+ * @param path The path to get the authority from.
+ * @param conf The configuration map.
+ * @return The full authority string.
+ */
+ default String getFullAuthority(Path path, Map<String, String> conf) {
+ return path.toUri().getAuthority();
+ }
}
diff --git a/catalogs/hadoop-common/src/main/java/org/apache/gravitino/catalog/hadoop/fs/FileSystemUtils.java b/catalogs/hadoop-common/src/main/java/org/apache/gravitino/catalog/hadoop/fs/FileSystemUtils.java
index fac32500ce..c2a789ea74 100644
--- a/catalogs/hadoop-common/src/main/java/org/apache/gravitino/catalog/hadoop/fs/FileSystemUtils.java
+++ b/catalogs/hadoop-common/src/main/java/org/apache/gravitino/catalog/hadoop/fs/FileSystemUtils.java
@@ -18,24 +18,17 @@
*/
package org.apache.gravitino.catalog.hadoop.fs;
-import static org.apache.gravitino.catalog.hadoop.fs.Constants.BUILTIN_HDFS_FS_PROVIDER;
-import static org.apache.gravitino.catalog.hadoop.fs.Constants.BUILTIN_LOCAL_FS_PROVIDER;
import static org.apache.gravitino.catalog.hadoop.fs.Constants.CONFIG_RESOURCES;
import static org.apache.gravitino.catalog.hadoop.fs.Constants.FS_DISABLE_CACHE;
import static org.apache.gravitino.catalog.hadoop.fs.FileSystemProvider.GRAVITINO_BYPASS;
import static org.apache.gravitino.catalog.hadoop.fs.HDFSFileSystemProvider.IPC_FALLBACK_TO_SIMPLE_AUTH_ALLOWED;
import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
import com.google.common.collect.Streams;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.util.Arrays;
-import java.util.Locale;
import java.util.Map;
import java.util.ServiceLoader;
-import java.util.Set;
-import java.util.stream.Collectors;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamWriter;
import org.apache.commons.lang3.StringUtils;
@@ -51,28 +44,14 @@ public class FileSystemUtils {
private FileSystemUtils() {}
- public static Map<String, FileSystemProvider> getFileSystemProviders(String fileSystemProviders) {
+ public static Map<String, FileSystemProvider> getFileSystemProviders() {
Map<String, FileSystemProvider> resultMap = Maps.newHashMap();
ServiceLoader<FileSystemProvider> allFileSystemProviders =
ServiceLoader.load(FileSystemProvider.class);
- Set<String> providersInUses =
- fileSystemProviders != null
- ? Arrays.stream(fileSystemProviders.split(","))
- .map(f -> f.trim().toLowerCase(Locale.ROOT))
- .collect(Collectors.toSet())
- : Sets.newHashSet();
-
- // Add built-in file system providers to the use list automatically.
- providersInUses.add(BUILTIN_LOCAL_FS_PROVIDER.toLowerCase(Locale.ROOT));
- providersInUses.add(BUILTIN_HDFS_FS_PROVIDER.toLowerCase(Locale.ROOT));
-
// Only get the file system providers that are in the user list and check if the scheme is
// unique.
Streams.stream(allFileSystemProviders.iterator())
- .filter(
- fileSystemProvider ->
- providersInUses.contains(fileSystemProvider.name().toLowerCase(Locale.ROOT)))
.forEach(
fileSystemProvider -> {
if (resultMap.containsKey(fileSystemProvider.scheme())) {
@@ -84,23 +63,6 @@ public class FileSystemUtils {
}
resultMap.put(fileSystemProvider.scheme(), fileSystemProvider);
});
-
- // If not all file system providers in providersInUses was found, throw an exception.
- Set<String> notFoundProviders =
- Sets.difference(
- providersInUses,
- resultMap.values().stream()
- .map(p -> p.name().toLowerCase(Locale.ROOT))
- .collect(Collectors.toSet()))
- .immutableCopy();
- if (!notFoundProviders.isEmpty()) {
- throw new UnsupportedOperationException(
- String.format(
- "File system providers %s not found in the classpath. Please make sure the file system "
- + "provider is in the classpath.",
- notFoundProviders));
- }
-
return resultMap;
}
diff --git a/catalogs/hadoop-common/src/main/java/org/apache/gravitino/catalog/hadoop/fs/HDFSFileSystemProvider.java b/catalogs/hadoop-common/src/main/java/org/apache/gravitino/catalog/hadoop/fs/HDFSFileSystemProvider.java
index 27fc90d80a..e9a087558d 100644
--- a/catalogs/hadoop-common/src/main/java/org/apache/gravitino/catalog/hadoop/fs/HDFSFileSystemProvider.java
+++ b/catalogs/hadoop-common/src/main/java/org/apache/gravitino/catalog/hadoop/fs/HDFSFileSystemProvider.java
@@ -23,12 +23,15 @@ import static org.apache.gravitino.catalog.hadoop.fs.Constants.DEFAULT_CONNECTIO
import static org.apache.gravitino.catalog.hadoop.fs.Constants.DEFAULT_HDFS_IPC_PING;
import static org.apache.gravitino.catalog.hadoop.fs.Constants.HDFS_IPC_CLIENT_CONNECT_TIMEOUT_KEY;
import static org.apache.gravitino.catalog.hadoop.fs.Constants.HDFS_IPC_PING_KEY;
+import static org.apache.gravitino.catalog.hadoop.fs.kerberos.AuthenticationConfig.IMPERSONATION_ENABLE_KEY;
+import static org.apache.gravitino.catalog.hadoop.fs.kerberos.KerberosConfig.PRINCIPAL_KEY;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import java.io.IOException;
import java.util.Map;
import javax.annotation.Nonnull;
+import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
@@ -57,13 +60,28 @@ public class HDFSFileSystemProvider implements FileSystemProvider {
return BUILTIN_HDFS_FS_PROVIDER;
}
+ @Override
+ public String getFullAuthority(Path path, Map<String, String> conf) {
+ String authority = path.toUri().getAuthority();
+ String principal = conf.get(PRINCIPAL_KEY);
+ if (StringUtils.isNotBlank(principal)) {
+ principal = principal.replaceAll("@.*$", ""); // Remove realm if exists
+ authority = String.format("%s@%s", principal, authority);
+ }
+ String impersonationEnabled = conf.get(IMPERSONATION_ENABLE_KEY);
+ if (conf.containsKey(IMPERSONATION_ENABLE_KEY)) {
+ authority = String.format("%s?impersonation_enabled=%s", authority, impersonationEnabled);
+ }
+ return authority;
+ }
+
/**
* Add additional HDFS specific configurations.
*
* @param configs Original configurations.
* @return Configurations with additional HDFS specific configurations.
*/
- private Map<String, String> additionalHDFSConfig(Map<String, String> configs) {
+ public static Map<String, String> additionalHDFSConfig(Map<String, String> configs) {
Map<String, String> additionalConfigs = Maps.newHashMap(configs);
// Avoid multiple retries to speed up failure in test cases.
diff --git a/clients/filesystem-hadoop3/src/main/java/org/apache/gravitino/filesystem/hadoop/HDFSFileSystemProxy.java b/catalogs/hadoop-common/src/main/java/org/apache/gravitino/catalog/hadoop/fs/HDFSFileSystemProxy.java
similarity index 50%
rename from clients/filesystem-hadoop3/src/main/java/org/apache/gravitino/filesystem/hadoop/HDFSFileSystemProxy.java
rename to catalogs/hadoop-common/src/main/java/org/apache/gravitino/catalog/hadoop/fs/HDFSFileSystemProxy.java
index 776b844859..902e5f3f49 100644
--- a/clients/filesystem-hadoop3/src/main/java/org/apache/gravitino/filesystem/hadoop/HDFSFileSystemProxy.java
+++ b/catalogs/hadoop-common/src/main/java/org/apache/gravitino/catalog/hadoop/fs/HDFSFileSystemProxy.java
@@ -16,97 +16,86 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.gravitino.filesystem.hadoop;
+package org.apache.gravitino.catalog.hadoop.fs;
import static org.apache.gravitino.catalog.hadoop.fs.Constants.AUTH_KERBEROS;
-import static org.apache.gravitino.catalog.hadoop.fs.Constants.AUTH_SIMPLE;
import static org.apache.gravitino.catalog.hadoop.fs.Constants.FS_DISABLE_CACHE;
-import static org.apache.gravitino.catalog.hadoop.fs.Constants.HADOOP_KRB5_CONF;
-import static org.apache.gravitino.catalog.hadoop.fs.Constants.HADOOP_SECURITY_KEYTAB;
-import static org.apache.gravitino.catalog.hadoop.fs.Constants.HADOOP_SECURITY_PRINCIPAL;
-import static org.apache.gravitino.catalog.hadoop.fs.Constants.SECURITY_KRB5_ENV;
+import static org.apache.gravitino.catalog.hadoop.fs.FileSystemProvider.GRAVITINO_BYPASS;
import static org.apache.gravitino.catalog.hadoop.fs.HDFSFileSystemProvider.IPC_FALLBACK_TO_SIMPLE_AUTH_ALLOWED;
+import static org.apache.gravitino.catalog.hadoop.fs.HDFSFileSystemProvider.additionalHDFSConfig;
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION;
+import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.security.PrivilegedExceptionAction;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
+import java.util.Locale;
+import java.util.Map;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
-import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.catalog.hadoop.fs.kerberos.AuthenticationConfig;
+import org.apache.gravitino.catalog.hadoop.fs.kerberos.KerberosClient;
import org.apache.gravitino.exceptions.GravitinoRuntimeException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.security.UserGroupInformation;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-/**
- * A FileSystem wrapper that runs all operations under a specific UGI (UserGroupInformation).
- * Supports both simple and Kerberos authentication, with automatic ticket renewal.
- */
+/** A FileSystem wrapper that runs all operations under a specific UGI (UserGroupInformation). */
public class HDFSFileSystemProxy implements MethodInterceptor {
- private static final Logger LOG = LoggerFactory.getLogger(HDFSFileSystemProxy.class);
+ public static final String GRAVITINO_KEYTAB_FORMAT = "keytabs/gravitino-%s";
+ private static final String GRAVITINO_ID_KEY = "gravitino.identifier";
- private static final long DEFAULT_RENEW_INTERVAL_MS = 10 * 60 * 1000L;
- private static final String SYSTEM_USER_NAME = System.getProperty("user.name");
- private static final String SYSTEM_ENV_HADOOP_USER_NAME = "HADOOP_USER_NAME";
+ protected UserGroupInformation initUgi;
+ private FileSystem fs;
+ private Configuration configuration;
+ protected boolean impersonationEnabled;
+ protected String kerberosRealm;
- private final UserGroupInformation ugi;
- private final FileSystem fs;
- private final Configuration configuration;
- private ScheduledExecutorService kerberosRenewExecutor;
+ protected HDFSFileSystemProxy() {}
/**
* Create a HDFSAuthenticationFileSystem with the given path and configuration. Supports both
- * simple and Kerberos authentication, with automatic ticket renewal for Kerberos.
+ * simple and Kerberos authentication.
*
* @param path the HDFS path
- * @param conf the Hadoop configuration
+ * @param config the configuration map of Gravitino
*/
- public HDFSFileSystemProxy(Path path, Configuration conf) {
+ public HDFSFileSystemProxy(Path path, Map<String, String> config) {
+ initFileSystem(path, config);
+ }
+
+ protected void initFileSystem(Path path, Map<String, String> config) {
try {
+ Map<String, String> hadoopConfMap = additionalHDFSConfig(config);
+ Configuration conf = FileSystemUtils.createConfiguration(GRAVITINO_BYPASS, hadoopConfMap);
+
conf.setBoolean(FS_DISABLE_CACHE, true);
conf.setBoolean(IPC_FALLBACK_TO_SIMPLE_AUTH_ALLOWED, true);
this.configuration = conf;
- String authType = conf.get(HADOOP_SECURITY_AUTHENTICATION, AUTH_SIMPLE);
+ AuthenticationConfig authenticationConfig = new AuthenticationConfig(config, configuration);
+ this.impersonationEnabled = authenticationConfig.isImpersonationEnabled();
+ String authType = authenticationConfig.getAuthType();
if (AUTH_KERBEROS.equalsIgnoreCase(authType)) {
- String krb5Config = conf.get(HADOOP_KRB5_CONF);
-
- if (krb5Config != null) {
- System.setProperty(SECURITY_KRB5_ENV, krb5Config);
- }
- UserGroupInformation.setConfiguration(conf);
- String principal = conf.get(HADOOP_SECURITY_PRINCIPAL, null);
- String keytab = conf.get(HADOOP_SECURITY_KEYTAB, null);
-
- if (principal == null || keytab == null) {
- throw new GravitinoRuntimeException(
- "Kerberos principal and keytab must be provided for kerberos authentication");
- }
-
- this.ugi = UserGroupInformation.loginUserFromKeytabAndReturnUGI(principal, keytab);
- startKerberosRenewalTask(principal);
+ this.configuration.set(
+ HADOOP_SECURITY_AUTHENTICATION,
+ UserGroupInformation.AuthenticationMethod.KERBEROS.name().toLowerCase(Locale.ROOT));
+ this.initUgi = initKerberosUgi(config, configuration);
} else {
- String userName = System.getenv(SYSTEM_ENV_HADOOP_USER_NAME);
- if (StringUtils.isEmpty(userName)) {
- userName = SYSTEM_USER_NAME;
- }
- this.ugi = UserGroupInformation.createRemoteUser(userName);
+ this.initUgi = UserGroupInformation.getCurrentUser();
}
+ UserGroupInformation requestUgi = getRequestUser();
this.fs =
- ugi.doAs(
+ requestUgi.doAs(
(PrivilegedExceptionAction<FileSystem>)
() -> FileSystem.newInstance(path.toUri(), conf));
+ } catch (GravitinoRuntimeException e) {
+ throw e;
} catch (Exception e) {
throw new GravitinoRuntimeException(e, "Failed to create HDFS FileSystem with UGI: %s", path);
}
@@ -120,7 +109,8 @@ public class HDFSFileSystemProxy implements MethodInterceptor {
*/
public FileSystem getProxy() throws IOException {
Enhancer e = new Enhancer();
- e.setClassLoader(fs.getClass().getClassLoader());
+ ClassLoader enhancerClassLoader = Enhancer.class.getClassLoader();
+ e.setClassLoader(enhancerClassLoader);
e.setSuperclass(fs.getClass());
e.setCallback(this);
FileSystem proxyFs = (FileSystem) e.create();
@@ -148,46 +138,14 @@ public class HDFSFileSystemProxy implements MethodInterceptor {
}
}
- /** Schedule periodic Kerberos re-login to refresh TGT before expiry. */
- private void startKerberosRenewalTask(String principal) {
- kerberosRenewExecutor =
- Executors.newSingleThreadScheduledExecutor(
- r -> {
- Thread t = new Thread(r, "HDFSFileSystemProxy Kerberos-Renewal-Thread");
- t.setDaemon(true);
- return t;
- });
-
- kerberosRenewExecutor.scheduleAtFixedRate(
- () -> {
- try {
- if (ugi.hasKerberosCredentials()) {
- ugi.checkTGTAndReloginFromKeytab();
- }
- } catch (Exception e) {
- LOG.error(
- "[Kerberos] Failed to renew TGT for principal {}: {}",
- principal,
- e.getMessage(),
- e);
- }
- },
- DEFAULT_RENEW_INTERVAL_MS,
- DEFAULT_RENEW_INTERVAL_MS,
- TimeUnit.MILLISECONDS);
- }
-
- /** Close the Kerberos renewal executor service to prevent resource leaks. */
- private void close() {
- if (kerberosRenewExecutor != null) {
- kerberosRenewExecutor.shutdownNow();
- kerberosRenewExecutor = null;
- }
+ protected UserGroupInformation getRequestUser() {
+ return initUgi;
}
/** Invoke the method on the underlying FileSystem using ugi.doAs. */
- private Object invokeWithUgi(MethodProxy methodProxy, Object[] objects) throws Throwable {
- return ugi.doAs(
+ protected Object invokeWithUgi(MethodProxy methodProxy, Object[] objects) throws Throwable {
+ UserGroupInformation currentUgi = getRequestUser();
+ return currentUgi.doAs(
(PrivilegedExceptionAction<Object>)
() -> {
try {
@@ -202,4 +160,21 @@ public class HDFSFileSystemProxy implements MethodInterceptor {
}
});
}
+
+ private void close() {}
+
+ private UserGroupInformation initKerberosUgi(
+ Map<String, String> properties, Configuration configuration) {
+ try {
+ KerberosClient client = new KerberosClient(properties, configuration, true);
+ String keytabPath =
+ String.format(GRAVITINO_KEYTAB_FORMAT, properties.getOrDefault(GRAVITINO_ID_KEY, ""));
+ File keytabFile = client.saveKeyTabFileFromUri(keytabPath);
+ UserGroupInformation ugi = client.login(keytabFile.getAbsolutePath());
+ this.kerberosRealm = client.getKerberosRealm();
+ return ugi;
+ } catch (IOException e) {
+ throw new RuntimeException("Failed to login with Kerberos", e);
+ }
+ }
}
diff --git a/catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/authentication/AuthenticationConfig.java b/catalogs/hadoop-common/src/main/java/org/apache/gravitino/catalog/hadoop/fs/kerberos/AuthenticationConfig.java
similarity index 73%
rename from catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/authentication/AuthenticationConfig.java
rename to catalogs/hadoop-common/src/main/java/org/apache/gravitino/catalog/hadoop/fs/kerberos/AuthenticationConfig.java
index d70e1bae2f..daef5ee736 100644
--- a/catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/authentication/AuthenticationConfig.java
+++ b/catalogs/hadoop-common/src/main/java/org/apache/gravitino/catalog/hadoop/fs/kerberos/AuthenticationConfig.java
@@ -17,17 +17,15 @@
* under the License.
*/
-package org.apache.gravitino.catalog.fileset.authentication;
+package org.apache.gravitino.catalog.hadoop.fs.kerberos;
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION;
-import com.google.common.collect.ImmutableMap;
import java.util.Map;
import org.apache.gravitino.Config;
import org.apache.gravitino.config.ConfigBuilder;
import org.apache.gravitino.config.ConfigConstants;
import org.apache.gravitino.config.ConfigEntry;
-import org.apache.gravitino.connector.PropertyEntry;
import org.apache.hadoop.conf.Configuration;
public class AuthenticationConfig extends Config {
@@ -90,27 +88,4 @@ public class AuthenticationConfig extends Config {
public boolean isKerberosAuth() {
return AuthenticationType.KERBEROS.name().equalsIgnoreCase(getAuthType());
}
-
- public static final Map<String, PropertyEntry<?>> AUTHENTICATION_PROPERTY_ENTRIES =
- new ImmutableMap.Builder<String, PropertyEntry<?>>()
- .put(
- IMPERSONATION_ENABLE_KEY,
- PropertyEntry.booleanPropertyEntry(
- IMPERSONATION_ENABLE_KEY,
- "Whether to enable impersonation for the Fileset catalog",
- false /* required */,
- true /* immutable */,
- KERBEROS_DEFAULT_IMPERSONATION_ENABLE /* default value */,
- false /* hidden */,
- false /* reserved */))
- .put(
- AUTH_TYPE_KEY,
- PropertyEntry.stringOptionalPropertyEntry(
- AUTH_TYPE_KEY,
- "The type of authentication for Fileset catalog, currently we only "
- + "support simple and Kerberos",
- false /* immutable */,
- null /* default value */,
- false /* hidden */))
- .build();
}
diff --git a/catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/authentication/kerberos/FetchFileUtils.java b/catalogs/hadoop-common/src/main/java/org/apache/gravitino/catalog/hadoop/fs/kerberos/FetchFileUtils.java
similarity index 96%
rename from catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/authentication/kerberos/FetchFileUtils.java
rename to catalogs/hadoop-common/src/main/java/org/apache/gravitino/catalog/hadoop/fs/kerberos/FetchFileUtils.java
index dbd66cfa10..d014345c54 100644
--- a/catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/authentication/kerberos/FetchFileUtils.java
+++ b/catalogs/hadoop-common/src/main/java/org/apache/gravitino/catalog/hadoop/fs/kerberos/FetchFileUtils.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.gravitino.catalog.fileset.authentication.kerberos;
+package org.apache.gravitino.catalog.hadoop.fs.kerberos;
import java.io.File;
import java.io.IOException;
diff --git a/catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/authentication/kerberos/KerberosClient.java b/catalogs/hadoop-common/src/main/java/org/apache/gravitino/catalog/hadoop/fs/kerberos/KerberosClient.java
similarity index 91%
rename from catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/authentication/kerberos/KerberosClient.java
rename to catalogs/hadoop-common/src/main/java/org/apache/gravitino/catalog/hadoop/fs/kerberos/KerberosClient.java
index 09e6405177..eb93f2ab72 100644
--- a/catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/authentication/kerberos/KerberosClient.java
+++ b/catalogs/hadoop-common/src/main/java/org/apache/gravitino/catalog/hadoop/fs/kerberos/KerberosClient.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.gravitino.catalog.fileset.authentication.kerberos;
+package org.apache.gravitino.catalog.hadoop.fs.kerberos;
import static org.apache.gravitino.catalog.hadoop.fs.Constants.HADOOP_KRB5_CONF;
import static org.apache.gravitino.catalog.hadoop.fs.Constants.SECURITY_KRB5_ENV;
@@ -46,6 +46,7 @@ public class KerberosClient implements Closeable {
private final Map<String, String> conf;
private final Configuration hadoopConf;
private final boolean refreshCredentials;
+ private String kerberosRealm;
public KerberosClient(
Map<String, String> conf, Configuration hadoopConf, boolean refreshCredentials) {
@@ -54,7 +55,7 @@ public class KerberosClient implements Closeable {
this.refreshCredentials = refreshCredentials;
}
- public String login(String keytabFilePath) throws IOException {
+ public UserGroupInformation login(String keytabFilePath) throws IOException {
KerberosConfig kerberosConfig = new KerberosConfig(conf, hadoopConf);
// Check the principal and keytab file
@@ -65,6 +66,7 @@ public class KerberosClient implements Closeable {
List<String> principalComponents = Splitter.on('@').splitToList(catalogPrincipal);
Preconditions.checkArgument(
principalComponents.size() == 2, "The principal has the wrong format");
+ kerberosRealm = principalComponents.get(1);
String krb5Config = hadoopConf.get(HADOOP_KRB5_CONF);
if (krb5Config != null) {
@@ -73,8 +75,8 @@ public class KerberosClient implements Closeable {
// Login
UserGroupInformation.setConfiguration(hadoopConf);
- UserGroupInformation.loginUserFromKeytab(catalogPrincipal, keytabFilePath);
- UserGroupInformation kerberosLoginUgi = UserGroupInformation.getLoginUser();
+ UserGroupInformation kerberosLoginUgi =
+ UserGroupInformation.loginUserFromKeytabAndReturnUGI(catalogPrincipal, keytabFilePath);
// Refresh the cache if it's out of date.
if (refreshCredentials) {
@@ -93,7 +95,7 @@ public class KerberosClient implements Closeable {
TimeUnit.SECONDS);
}
- return principalComponents.get(1);
+ return kerberosLoginUgi;
}
public File saveKeyTabFileFromUri(String keytabPath) throws IOException {
@@ -135,4 +137,8 @@ public class KerberosClient implements Closeable {
checkTgtExecutor.shutdown();
}
}
+
+ public String getKerberosRealm() {
+ return kerberosRealm;
+ }
}
diff --git a/catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/authentication/kerberos/KerberosConfig.java b/catalogs/hadoop-common/src/main/java/org/apache/gravitino/catalog/hadoop/fs/kerberos/KerberosConfig.java
similarity index 69%
rename from catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/authentication/kerberos/KerberosConfig.java
rename to catalogs/hadoop-common/src/main/java/org/apache/gravitino/catalog/hadoop/fs/kerberos/KerberosConfig.java
index d9e7fe1d05..146fcf6324 100644
--- a/catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/authentication/kerberos/KerberosConfig.java
+++ b/catalogs/hadoop-common/src/main/java/org/apache/gravitino/catalog/hadoop/fs/kerberos/KerberosConfig.java
@@ -17,19 +17,16 @@
* under the License.
*/
-package org.apache.gravitino.catalog.fileset.authentication.kerberos;
+package org.apache.gravitino.catalog.hadoop.fs.kerberos;
import static org.apache.gravitino.catalog.hadoop.fs.Constants.HADOOP_SECURITY_KEYTAB;
import static org.apache.gravitino.catalog.hadoop.fs.Constants.HADOOP_SECURITY_PRINCIPAL;
-import com.google.common.collect.ImmutableMap;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
-import org.apache.gravitino.catalog.fileset.authentication.AuthenticationConfig;
import org.apache.gravitino.config.ConfigBuilder;
import org.apache.gravitino.config.ConfigConstants;
import org.apache.gravitino.config.ConfigEntry;
-import org.apache.gravitino.connector.PropertyEntry;
import org.apache.hadoop.conf.Configuration;
public class KerberosConfig extends AuthenticationConfig {
@@ -102,40 +99,4 @@ public class KerberosConfig extends AuthenticationConfig {
public int getFetchTimeoutSec() {
return get(FETCH_TIMEOUT_SEC_ENTRY);
}
-
- public static final Map<String, PropertyEntry<?>> KERBEROS_PROPERTY_ENTRIES =
- new ImmutableMap.Builder<String, PropertyEntry<?>>()
- .put(
- KEY_TAB_URI_KEY,
- PropertyEntry.stringOptionalPropertyEntry(
- KEY_TAB_URI_KEY,
- "The uri of key tab for the catalog",
- false /* immutable */,
- null /* default value */,
- false /* hidden */))
- .put(
- PRINCIPAL_KEY,
- PropertyEntry.stringOptionalPropertyEntry(
- PRINCIPAL_KEY,
- "The principal for the catalog",
- false /* immutable */,
- null /* defaultValue */,
- false /* hidden */))
- .put(
- CHECK_INTERVAL_SEC_KEY,
- PropertyEntry.integerOptionalPropertyEntry(
- CHECK_INTERVAL_SEC_KEY,
- "The interval to check validness of the principal",
- true /* immutable */,
- 60 /* defaultValue */,
- false /* hidden */))
- .put(
- FETCH_TIMEOUT_SEC_KEY,
- PropertyEntry.integerOptionalPropertyEntry(
- FETCH_TIMEOUT_SEC_KEY,
- "The timeout to fetch key tab",
- false /* immutable */,
- 60 /* defaultValue */,
- false /* hidden */))
- .build();
}
diff --git a/clients/filesystem-hadoop3/src/main/java/org/apache/gravitino/filesystem/hadoop/BaseGVFSOperations.java b/clients/filesystem-hadoop3/src/main/java/org/apache/gravitino/filesystem/hadoop/BaseGVFSOperations.java
index 95ac0201a6..ccfb8e29fa 100644
--- a/clients/filesystem-hadoop3/src/main/java/org/apache/gravitino/filesystem/hadoop/BaseGVFSOperations.java
+++ b/clients/filesystem-hadoop3/src/main/java/org/apache/gravitino/filesystem/hadoop/BaseGVFSOperations.java
@@ -18,12 +18,12 @@
*/
package org.apache.gravitino.filesystem.hadoop;
-import static org.apache.gravitino.catalog.hadoop.fs.FileSystemProvider.GRAVITINO_BYPASS;
import static org.apache.gravitino.catalog.hadoop.fs.HDFSFileSystemProvider.SCHEME_HDFS;
import static org.apache.gravitino.file.Fileset.PROPERTY_DEFAULT_LOCATION_NAME;
import static org.apache.gravitino.filesystem.hadoop.GravitinoVirtualFileSystemConfiguration.FS_GRAVITINO_CURRENT_LOCATION_NAME;
import static org.apache.gravitino.filesystem.hadoop.GravitinoVirtualFileSystemConfiguration.FS_GRAVITINO_FILESET_METADATA_CACHE_ENABLE;
import static org.apache.gravitino.filesystem.hadoop.GravitinoVirtualFileSystemConfiguration.FS_GRAVITINO_FILESET_METADATA_CACHE_ENABLE_DEFAULT;
+import static org.apache.gravitino.filesystem.hadoop.GravitinoVirtualFileSystemConfiguration.FS_GRAVITINO_PATH_CONFIG_PREFIX;
import static org.apache.gravitino.filesystem.hadoop.GravitinoVirtualFileSystemUtils.extractIdentifier;
import static org.apache.gravitino.filesystem.hadoop.GravitinoVirtualFileSystemUtils.extractNonDefaultConfig;
import static org.apache.gravitino.filesystem.hadoop.GravitinoVirtualFileSystemUtils.getSubPathFromGvfsPath;
@@ -66,8 +66,8 @@ import org.apache.gravitino.audit.FilesetAuditConstants;
import org.apache.gravitino.audit.FilesetDataOperation;
import org.apache.gravitino.audit.InternalClientType;
import org.apache.gravitino.catalog.hadoop.fs.FileSystemProvider;
-import org.apache.gravitino.catalog.hadoop.fs.FileSystemUtils;
import org.apache.gravitino.catalog.hadoop.fs.GravitinoFileSystemCredentialsProvider;
+import org.apache.gravitino.catalog.hadoop.fs.HDFSFileSystemProxy;
import org.apache.gravitino.catalog.hadoop.fs.SupportsCredentialVending;
import org.apache.gravitino.client.GravitinoClient;
import org.apache.gravitino.credential.Credential;
@@ -81,6 +81,7 @@ import org.apache.gravitino.file.FilesetCatalog;
import org.apache.gravitino.storage.AzureProperties;
import org.apache.gravitino.storage.OSSProperties;
import org.apache.gravitino.storage.S3Properties;
+import org.apache.gravitino.utils.FilesetUtil;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FSDataOutputStream;
@@ -712,7 +713,9 @@ public abstract class BaseGVFSOperations implements Closeable {
Path targetLocation = new Path(fileset.storageLocations().get(targetLocationName));
Map<String, String> allProperties = getAllProperties(filesetIdent, fileset.properties());
- allProperties.putAll(getUserDefinedConfigs(getBaseLocation(targetLocation)));
+ allProperties.putAll(
+ FilesetUtil.getUserDefinedFileSystemConfigs(
+ targetLocation.toUri(), allProperties, FS_GRAVITINO_PATH_CONFIG_PREFIX));
if (enableCredentialVending()) {
allProperties.putAll(
@@ -787,52 +790,6 @@ public abstract class BaseGVFSOperations implements Closeable {
CallerContext.CallerContextHolder.set(callerContext);
}
- /**
- * Get user defined configurations for a specific location. Configuration format:
- *
- * @param baseLocation the base location of fileset
- * @return a map of configuration properties for the specified location
- */
- private Map<String, String> getUserDefinedConfigs(String baseLocation) {
- // Prepare a map to hold the properties for the specified location
- // fs.path.config.<location_name> = location
- // fs.path.config.<location_name>.<property_name> = <property_value>
- // eg:
- // fs.path.config.cluster1 = s3://bucket/path/
- // fs.path.config.cluster1.aws-access-key = XXX
- // fs.path.config.cluster1.aws-secret-key = XXX
- Map<String, String> properties = new HashMap<>();
- if (StringUtils.isBlank(baseLocation)) {
- return properties;
- }
- String locationPrefix =
- GravitinoVirtualFileSystemConfiguration.FS_GRAVITINO_PATH_CONFIG_PREFIX
- + baseLocation
- + ".";
-
- // Iterate through all configuration entries
- for (Map.Entry<String, String> entry : conf) {
- String key = entry.getKey();
-
- // Check if this key is a property for the specified location
- // e.g., "fs.path.config.cluster1.aws-ak" matches prefix "fs.path.config.cluster1."
- if (key.startsWith(locationPrefix)) {
- // Extract the property name after the location prefix
- // e.g., "fs.path.config.cluster1.aws-ak" -> "aws-ak"
- String propertyName = key.substring(locationPrefix.length());
- if (!propertyName.isEmpty()) {
- properties.put(propertyName, entry.getValue());
- }
- }
- }
-
- return properties;
- }
-
- private String getBaseLocation(Path targetLocation) {
- return targetLocation.toUri().getScheme() + "://" + targetLocation.toUri().getAuthority();
- }
-
/**
* Get the actual file system by the given actual file path and properties.
*
@@ -847,33 +804,31 @@ public abstract class BaseGVFSOperations implements Closeable {
Preconditions.checkArgument(
StringUtils.isNotBlank(scheme), "Scheme of the actual file location cannot be null.");
+ FileSystemProvider provider = getFileSystemProviderByScheme(scheme);
+ String authority = provider.getFullAuthority(actualFilePath, allProperties);
UserGroupInformation ugi;
try {
+
ugi = UserGroupInformation.getCurrentUser();
} catch (IOException e) {
throw new GravitinoRuntimeException(
e, "Cannot get current user for path: %s", actualFilePath);
}
return fileSystemCache.get(
- new FileSystemCacheKey(scheme, uri.getAuthority(), ugi),
+ new FileSystemCacheKey(scheme, authority, ugi),
cacheKey -> {
- FileSystemProvider provider = getFileSystemProviderByScheme(scheme);
-
- // Reset the FileSystem service loader to make sure the FileSystem will reload the
- // service file systems, this is a temporary solution to fix the issue
- // https://github.com/apache/gravitino/issues/5609
- resetFileSystemServiceLoader(scheme);
try {
- FileSystem fs;
+
+ // Reset the FileSystem service loader to make sure the FileSystem will reload the
+ // service file systems, this is a temporary solution to fix the issue
+ // https://github.com/apache/gravitino/issues/5609
+ resetFileSystemServiceLoader(scheme);
+
if (scheme.equals(SCHEME_HDFS)) {
- Configuration fsConfig =
- FileSystemUtils.createConfiguration(GRAVITINO_BYPASS, allProperties);
- HDFSFileSystemProxy proxy = new HDFSFileSystemProxy(actualFilePath, fsConfig);
- fs = proxy.getProxy();
+ return new HDFSFileSystemProxy(actualFilePath, allProperties).getProxy();
} else {
- fs = provider.getFileSystem(actualFilePath, allProperties);
+ return provider.getFileSystem(actualFilePath, allProperties);
}
- return fs;
} catch (IOException e) {
throw new GravitinoRuntimeException(
e, "Cannot get FileSystem for path: %s", actualFilePath);
diff --git a/clients/filesystem-hadoop3/src/test/java/org/apache/gravitino/filesystem/hadoop/TestBaseGVFSOperationsUserConfigs.java b/clients/filesystem-hadoop3/src/test/java/org/apache/gravitino/filesystem/hadoop/TestBaseGVFSOperationsUserConfigs.java
index 5d552b1991..00b46286d3 100644
--- a/clients/filesystem-hadoop3/src/test/java/org/apache/gravitino/filesystem/hadoop/TestBaseGVFSOperationsUserConfigs.java
+++ b/clients/filesystem-hadoop3/src/test/java/org/apache/gravitino/filesystem/hadoop/TestBaseGVFSOperationsUserConfigs.java
@@ -19,14 +19,13 @@
package org.apache.gravitino.filesystem.hadoop;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.withSettings;
-import java.lang.reflect.Method;
+import java.net.URI;
+import java.util.HashMap;
import java.util.Map;
+import org.apache.gravitino.utils.FilesetUtil;
import org.apache.hadoop.conf.Configuration;
import org.junit.jupiter.api.Test;
-import org.mockito.Mockito;
/** Unit test covering the user-defined configuration extraction logic in BaseGVFSOperations. */
public class TestBaseGVFSOperationsUserConfigs {
@@ -41,25 +40,13 @@ public class TestBaseGVFSOperationsUserConfigs {
return conf;
}
- @SuppressWarnings("unchecked")
- private Map<String, String> invokeGetUserDefinedConfigs(
- BaseGVFSOperations operations, String locationName) {
- try {
- Method method =
- BaseGVFSOperations.class.getDeclaredMethod("getUserDefinedConfigs", String.class);
- method.setAccessible(true);
- return (Map<String, String>) method.invoke(operations, locationName);
- } catch (ReflectiveOperationException e) {
- throw new RuntimeException("Unable to invoke getUserDefinedConfigs", e);
- }
- }
-
@Test
public void testGetUserDefinedConfigsReturnsExpectedEntries() throws Exception {
Configuration conf = createBaseConfiguration();
+ // Define location1 with base location hdfs://cluster1
conf.set(
GravitinoVirtualFileSystemConfiguration.FS_GRAVITINO_PATH_CONFIG_PREFIX + "cluster1",
- "hdfs://cluster1/");
+ "hdfs://cluster1");
conf.set(
GravitinoVirtualFileSystemConfiguration.FS_GRAVITINO_PATH_CONFIG_PREFIX + "cluster1.aws-ak",
"AK1");
@@ -71,16 +58,26 @@ public class TestBaseGVFSOperationsUserConfigs {
+ "cluster1.config.resource",
"/etc/core-site.xml,hdfs-site.xml");
// Another location's property which should be ignored
+ conf.set(
+ GravitinoVirtualFileSystemConfiguration.FS_GRAVITINO_PATH_CONFIG_PREFIX + "cluster2",
+ "hdfs://cluster2");
conf.set(
GravitinoVirtualFileSystemConfiguration.FS_GRAVITINO_PATH_CONFIG_PREFIX + "cluster2.aws-ak",
"AK2");
- BaseGVFSOperations operations =
- mock(
- BaseGVFSOperations.class,
- withSettings().useConstructor(conf).defaultAnswer(Mockito.CALLS_REAL_METHODS));
+ // Convert Configuration to Map for FilesetUtil
+ Map<String, String> confMap = new HashMap<>();
+ for (Map.Entry<String, String> entry : conf) {
+ confMap.put(entry.getKey(), entry.getValue());
+ }
- Map<String, String> properties = invokeGetUserDefinedConfigs(operations, "cluster1");
+ // Test with path that matches cluster1 (same baseLocation: hdfs://cluster1)
+ URI testPath = new URI("hdfs://cluster1/path/to/file");
+ Map<String, String> properties =
+ FilesetUtil.getUserDefinedFileSystemConfigs(
+ testPath,
+ confMap,
+ GravitinoVirtualFileSystemConfiguration.FS_GRAVITINO_PATH_CONFIG_PREFIX);
assertEquals(3, properties.size(), "Only cluster1 scoped properties should be returned");
assertEquals("AK1", properties.get("aws-ak"));
diff --git a/core/src/main/java/org/apache/gravitino/UserPrincipal.java b/core/src/main/java/org/apache/gravitino/UserPrincipal.java
index 5f8b347742..a1d00f7ccc 100644
--- a/core/src/main/java/org/apache/gravitino/UserPrincipal.java
+++ b/core/src/main/java/org/apache/gravitino/UserPrincipal.java
@@ -22,15 +22,26 @@ package org.apache.gravitino;
import com.google.common.base.Preconditions;
import java.security.Principal;
+/** A simple implementation of Principal that holds a username. */
public class UserPrincipal implements Principal {
private final String username;
+ /**
+ * Constructs a UserPrincipal with the given username.
+ *
+ * @param username the username of the principal
+ */
public UserPrincipal(final String username) {
Preconditions.checkArgument(username != null, "UserPrincipal must have the username");
this.username = username;
}
+ /**
+ * Returns the username of this principal.
+ *
+ * @return the username
+ */
@Override
public String getName() {
return username;
diff --git a/core/src/main/java/org/apache/gravitino/utils/IsolatedClassLoader.java b/core/src/main/java/org/apache/gravitino/utils/IsolatedClassLoader.java
index f9974ab490..a7006aca57 100644
--- a/core/src/main/java/org/apache/gravitino/utils/IsolatedClassLoader.java
+++ b/core/src/main/java/org/apache/gravitino/utils/IsolatedClassLoader.java
@@ -247,7 +247,6 @@ public class IsolatedClassLoader implements Closeable {
|| name.startsWith("org.apache.gravitino.catalog.mysql.")
|| name.startsWith("org.apache.gravitino.catalog.postgresql.")
|| name.startsWith("org.apache.gravitino.catalog.doris.")
- || name.startsWith("org.apache.gravitino.catalog.hadoop.")
|| name.startsWith("org.apache.gravitino.catalog.fileset.")
|| name.startsWith("org.apache.gravitino.catalog.model.")
|| name.startsWith("org.apache.gravitino.catalog.kafka."));
diff --git a/docs/fileset-catalog-with-adls.md b/docs/fileset-catalog-with-adls.md
index 31021ad631..fd1b007ab9 100644
--- a/docs/fileset-catalog-with-adls.md
+++ b/docs/fileset-catalog-with-adls.md
@@ -30,12 +30,15 @@ Apart from configurations mentioned in [fileset-catalog-catalog-configuration](.
| Configuration item | Description | Default value | Required | Since version |
|-------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------|----------|------------------|
-| `filesystem-providers` | The file system providers to add. Set it to `abs` if it's a Azure Blob Storage fileset, or a comma separated string that contains `abs` like `oss,abs,s3` to support multiple kinds of fileset including `abs`. | (none) | Yes | 0.8.0-incubating |
-| `default-filesystem-provider` | The name default filesystem providers of this Fileset catalog if users do not specify the scheme in the URI. Default value is `builtin-local`, for Azure Blob Storage, if we set this value, we can omit the prefix 'abfss://' in the location. | `builtin-local` | No | 0.8.0-incubating |
+| `filesystem-providers` | (deprecated) The file system providers to add. Set it to `abs` if it's a Azure Blob Storage fileset, or a comma separated string that contains `abs` like `oss,abs,s3` to support multiple kinds of fileset including `abs`. | (none) | Yes | 0.8.0-incubating |
+| `default-filesystem-provider` | (deprecated) The name default filesystem providers of this Fileset catalog if users do not specify the scheme in the URI. Default value is `builtin-local`, for Azure Blob Storage, if we set this value, we can omit the prefix 'abfss://' in the location. | `builtin-local` | No | 0.8.0-incubating |
| `azure-storage-account-name ` | The account name of Azure Blob Storage. | (none) | Yes | 0.8.0-incubating |
| `azure-storage-account-key` | The account key of Azure Blob Storage. | (none) | Yes | 0.8.0-incubating |
| `credential-providers` | The credential provider types, separated by comma, possible value can be `adls-token`, `azure-account-key`. As the default authentication type is using account name and account key as the above, this configuration can enable credential vending provided by Gravitino server and client will no longer need to provide authentication information like account_name/account_key to access ADLS by GVFS. Once it's set, more configuration items are needed to make it works, please see [adls-credential-vending](security/credential-vending.md#adls-credentials) | (none) | No | 0.8.0-incubating |
+:::note
+`default-filesystem-provider` and `filesystem-providers` are deprecated since 1.2.0. The fileset catalog automatically loads filesystem providers on the classpath, including buildin filesystem provider and cloud providers when the corresponding bundle jar is present (for example, `gravitino-azure-bundle`).
+:::
### Configurations for a schema
@@ -65,8 +68,7 @@ curl -X POST -H "Accept: application/vnd.gravitino.v1+json" \
"properties": {
"location": "abfss://[email protected]/path",
"azure-storage-account-name": "The account name of the Azure Blob Storage",
- "azure-storage-account-key": "The account key of the Azure Blob Storage",
- "filesystem-providers": "abs"
+ "azure-storage-account-key": "The account key of the Azure Blob Storage"
}
}' http://localhost:8090/api/metalakes/metalake/catalogs
```
@@ -84,7 +86,6 @@ Map<String, String> adlsProperties = ImmutableMap.<String, String>builder()
.put("location", "abfss://[email protected]/path")
.put("azure-storage-account-name", "azure storage account name")
.put("azure-storage-account-key", "azure storage account key")
- .put("filesystem-providers", "abs")
.build();
Catalog adlsCatalog = gravitinoClient.createCatalog("example_catalog",
@@ -103,8 +104,7 @@ gravitino_client: GravitinoClient = GravitinoClient(uri="http://localhost:8090",
adls_properties = {
"location": "abfss://[email protected]/path",
"azure-storage-account-name": "azure storage account name",
- "azure-storage-account-key": "azure storage account key",
- "filesystem-providers": "abs"
+ "azure-storage-account-key": "azure storage account key"
}
adls_properties = gravitino_client.create_catalog(name="example_catalog",
@@ -506,7 +506,6 @@ curl -X POST -H "Accept: application/vnd.gravitino.v1+json" \
"location": "abfss://[email protected]/path",
"azure-storage-account-name": "The account name of the Azure Blob Storage",
"azure-storage-account-key": "The account key of the Azure Blob Storage",
- "filesystem-providers": "abs",
"credential-providers": "adls-token",
"azure-tenant-id":"The Azure tenant id",
"azure-client-id":"The Azure client id",
diff --git a/docs/fileset-catalog-with-gcs.md b/docs/fileset-catalog-with-gcs.md
index 3379dac852..404921e3ac 100644
--- a/docs/fileset-catalog-with-gcs.md
+++ b/docs/fileset-catalog-with-gcs.md
@@ -29,11 +29,14 @@ Apart from configurations mentioned in [Fileset-catalog-catalog-configuration](.
| Configuration item | Description | Default value | Required | Since version |
|-------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------|----------|------------------|
-| `filesystem-providers` | The file system providers to add. Set it to `gcs` if it's a GCS fileset, a comma separated string that contains `gcs` like `gcs,s3` to support multiple kinds of fileset including `gcs`. | (none) | Yes | 0.7.0-incubating |
-| `default-filesystem-provider` | The name default filesystem providers of this Fileset catalog if users do not specify the scheme in the URI. Default value is `builtin-local`, for GCS, if we set this value, we can omit the prefix 'gs://' in the location. | `builtin-local` | No | 0.7.0-incubating |
+| `filesystem-providers` | (deprecated) The file system providers to add. Set it to `gcs` if it's a GCS fileset, a comma separated string that contains `gcs` like `gcs,s3` to support multiple kinds of fileset including `gcs`. | (none) | Yes | 0.7.0-incubating |
+| `default-filesystem-provider` | (deprecated) The name default filesystem providers of this Fileset catalog if users do not specify the scheme in the URI. Default value is `builtin-local`, for GCS, if we set this value, we can omit the prefix 'gs://' in the location. | `builtin-local` | No | 0.7.0-incubating |
| `gcs-service-account-file` | The path of GCS service account JSON file. | (none) | Yes | 0.7.0-incubating |
| `credential-providers` | The credential provider types, separated by comma, possible value can be `gcs-token`. As the default authentication type is using service account as the above, this configuration can enable credential vending provided by Gravitino server and client will no longer need to provide authentication information like service account to access GCS by GVFS. Once it's set, more configuration items are needed to make it works, please see [gcs-credential-vending](security/credential-vending.md#gcs-credentials) | (none) | No | 0.8.0-incubating |
+:::note
+`default-filesystem-provider` and `filesystem-providers` are deprecated since 1.2.0. The fileset catalog automatically loads filesystem providers on the classpath, including buildin filesystem provider and cloud providers when the corresponding bundle jar is present (for example, `gravitino-gcp-bundle`).
+:::
### Configurations for a schema
@@ -62,8 +65,7 @@ curl -X POST -H "Accept: application/vnd.gravitino.v1+json" \
"comment": "This is a GCS fileset catalog",
"properties": {
"location": "gs://bucket/root",
- "gcs-service-account-file": "path_of_gcs_service_account_file",
- "filesystem-providers": "gcs"
+ "gcs-service-account-file": "path_of_gcs_service_account_file"
}
}' http://localhost:8090/api/metalakes/metalake/catalogs
```
@@ -80,7 +82,6 @@ GravitinoClient gravitinoClient = GravitinoClient
Map<String, String> gcsProperties = ImmutableMap.<String, String>builder()
.put("location", "gs://bucket/root")
.put("gcs-service-account-file", "path_of_gcs_service_account_file")
- .put("filesystem-providers", "gcs")
.build();
Catalog gcsCatalog = gravitinoClient.createCatalog("test_catalog",
@@ -98,8 +99,7 @@ Catalog gcsCatalog = gravitinoClient.createCatalog("test_catalog",
gravitino_client: GravitinoClient = GravitinoClient(uri="http://localhost:8090", metalake_name="metalake")
gcs_properties = {
"location": "gs://bucket/root",
- "gcs-service-account-file": "path_of_gcs_service_account_file",
- "filesystem-providers": "gcs"
+ "gcs-service-account-file": "path_of_gcs_service_account_file"
}
gcs_properties = gravitino_client.create_catalog(name="test_catalog",
@@ -488,7 +488,6 @@ curl -X POST -H "Accept: application/vnd.gravitino.v1+json" \
"properties": {
"location": "gs://bucket/root",
"gcs-service-account-file": "path_of_gcs_service_account_file",
- "filesystem-providers": "gcs",
"credential-providers": "gcs-token"
}
}' http://localhost:8090/api/metalakes/metalake/catalogs
diff --git a/docs/fileset-catalog-with-oss.md b/docs/fileset-catalog-with-oss.md
index 5bc1ce34ad..cf9b446364 100644
--- a/docs/fileset-catalog-with-oss.md
+++ b/docs/fileset-catalog-with-oss.md
@@ -28,15 +28,18 @@ Once the server is up and running, you can proceed to configure the Fileset cata
In addition to the basic configurations mentioned in [Fileset-catalog-catalog-configuration](./fileset-catalog.md#catalog-properties), the following properties are required to configure a Fileset catalog with OSS:
-| Configuration item | Description | Default value | Required | Since version |
-|--------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------|----------|------------------|
-| `filesystem-providers` | The file system providers to add. Set it to `oss` if it's a OSS fileset, or a comma separated string that contains `oss` like `oss,gs,s3` to support multiple kinds of fileset including `oss`. | (none) | Yes | 0.7.0-incubating |
-| `default-filesystem-provider` | The name default filesystem providers of this Fileset catalog if users do not specify the scheme in the URI. Default value is `builtin-local`, for OSS, if we set this value, we can omit the prefix 'oss://' in the location. | `builtin-local` | No | 0.7.0-incubating |
-| `oss-endpoint` | The endpoint of the Aliyun OSS. | (none) | Yes | 0.7.0-incubating |
-| `oss-access-key-id` | The access key of the Aliyun OSS. | (none) | Yes | 0.7.0-incubating |
-| `oss-secret-access-key` | The secret key of the Aliyun OSS. | (none) | Yes | 0.7.0-incubating |
-| `credential-providers` | The credential provider types, separated by comma, possible value can be `oss-token`, `oss-secret-key`. As the default authentication type is using AKSK as the above, this configuration can enable credential vending provided by Gravitino server and client will no longer need to provide authentication information like AKSK to access OSS by GVFS. Once it's set, more configuration items are needed to make it works, please see [oss-credential-vending](security/credential-vending.md#oss-credentials) | (none) | No | 0.8.0-incubating |
+| Configuration item | Description | Default value | Required | Since version |
+|-------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------|----------|------------------|
+| `filesystem-providers` | (deprecated) The file system providers to add. Set it to `oss` if it's a OSS fileset, or a comma separated string that contains `oss` like `oss,gs,s3` to support multiple kinds of fileset including `oss`. | (none) | Yes | 0.7.0-incubating |
+| `default-filesystem-provider` | (deprecated) The name default filesystem providers of this Fileset catalog if users do not specify the scheme in the URI. Default value is `builtin-local`, for OSS, if we set this value, we can omit the prefix 'oss://' in the location. | `builtin-local` | No | 0.7.0-incubating |
+| `oss-endpoint` | The endpoint of the Aliyun OSS. | (none) | Yes | 0.7.0-incubating |
+| `oss-access-key-id` | The access key of the Aliyun OSS. | (none) | Yes | 0.7.0-incubating |
+| `oss-secret-access-key` | The secret key of the Aliyun OSS. | (none) | Yes | 0.7.0-incubating |
+| `credential-providers` | The credential provider types, separated by comma, possible value can be `oss-token`, `oss-secret-key`. As the default authentication type is using AKSK as the above, this configuration can enable credential vending provided by Gravitino server and client will no longer need to provide authentication information like AKSK to access OSS by GVFS. Once it's set, more configuration items are needed to make it works, please see [oss-credential-vending](security/credential-vending.md#oss-credentials) | (none) | No | 0.8.0-incubating |
+:::note
+`default-filesystem-provider` and `filesystem-providers` are deprecated since 1.2.0. The fileset catalog automatically loads filesystem providers on the classpath, including buildin filesystem provider and cloud providers when the corresponding bundle jar is present (for example, `gravitino-aliyun-bundle`).
+:::
### Configurations for a schema
@@ -67,8 +70,7 @@ curl -X POST -H "Accept: application/vnd.gravitino.v1+json" \
"location": "oss://bucket/root",
"oss-access-key-id": "access_key",
"oss-secret-access-key": "secret_key",
- "oss-endpoint": "http://oss-cn-hangzhou.aliyuncs.com",
- "filesystem-providers": "oss"
+ "oss-endpoint": "http://oss-cn-hangzhou.aliyuncs.com"
}
}' http://localhost:8090/api/metalakes/metalake/catalogs
```
@@ -87,7 +89,6 @@ Map<String, String> ossProperties = ImmutableMap.<String, String>builder()
.put("oss-access-key-id", "access_key")
.put("oss-secret-access-key", "secret_key")
.put("oss-endpoint", "http://oss-cn-hangzhou.aliyuncs.com")
- .put("filesystem-providers", "oss")
.build();
Catalog ossCatalog = gravitinoClient.createCatalog("test_catalog",
@@ -107,8 +108,7 @@ oss_properties = {
"location": "oss://bucket/root",
"oss-access-key-id": "access_key"
"oss-secret-access-key": "secret_key",
- "oss-endpoint": "ossProperties",
- "filesystem-providers": "oss"
+ "oss-endpoint": "ossProperties"
}
oss_catalog = gravitino_client.create_catalog(name="test_catalog",
@@ -516,7 +516,6 @@ curl -X POST -H "Accept: application/vnd.gravitino.v1+json" \
"oss-access-key-id": "access_key",
"oss-secret-access-key": "secret_key",
"oss-endpoint": "http://oss-cn-hangzhou.aliyuncs.com",
- "filesystem-providers": "oss",
"credential-providers": "oss-token",
"oss-region":"oss-cn-hangzhou",
"oss-role-arn":"The ARN of the role to access the OSS data"
@@ -563,4 +562,3 @@ spark = SparkSession.builder
Python client and Hadoop command are similar to the above examples.
-
diff --git a/docs/fileset-catalog-with-s3.md b/docs/fileset-catalog-with-s3.md
index 078af4189c..167a2bfb5e 100644
--- a/docs/fileset-catalog-with-s3.md
+++ b/docs/fileset-catalog-with-s3.md
@@ -28,14 +28,18 @@ Once the server is up and running, you can proceed to configure the Fileset cata
In addition to the basic configurations mentioned in [Fileset-catalog-catalog-configuration](./fileset-catalog.md#catalog-properties), the following properties are necessary to configure a Fileset catalog with S3:
-| Configuration item | Description | Default value | Required | Since version |
-|--------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------|----------|------------------|
-| `filesystem-providers` | The file system providers to add. Set it to `s3` if it's a S3 fileset, or a comma separated string that contains `s3` like `gs,s3` to support multiple kinds of fileset including `s3`. | (none) | Yes | 0.7.0-incubating |
-| `default-filesystem-provider` | The name default filesystem providers of this Fileset catalog if users do not specify the scheme in the URI. Default value is `builtin-local`, for S3, if we set this value, we can omit the prefix 's3a://' in the location. | `builtin-local` | No | 0.7.0-incubating |
-| `s3-endpoint` | The endpoint of the AWS S3. | (none) | Yes | 0.7.0-incubating |
-| `s3-access-key-id` | The access key of the AWS S3. | (none) | Yes | 0.7.0-incubating |
-| `s3-secret-access-key` | The secret key of the AWS S3. | (none) | Yes | 0.7.0-incubating |
-| `credential-providers` | The credential provider types, separated by comma, possible value can be `s3-token`, `s3-secret-key`. As the default authentication type is using AKSK as the above, this configuration can enable credential vending provided by Gravitino server and client will no longer need to provide authentication information like AKSK to access S3 by GVFS. Once it's set, more configuration items are needed to make it works, please see [s3-credential-vending](security/credential-vending.md#s3-credentials) | (none) | No | 0.8.0-incubating |
+| Configuration item | Description | Default value | Required | Since version |
+|-------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------|----------|------------------|
+| `filesystem-providers` | (deprecated) The file system providers to add. Set it to `s3` if it's a S3 fileset, or a comma separated string that contains `s3` like `gs,s3` to support multiple kinds of fileset including `s3`. | (none) | Yes | 0.7.0-incubating |
+| `default-filesystem-provider` | (deprecated) The name default filesystem providers of this Fileset catalog if users do not specify the scheme in the URI. Default value is `builtin-local`, for S3, if we set this value, we can omit the prefix 's3a://' in the location. | `builtin-local` | No | 0.7.0-incubating |
+| `s3-endpoint` | The endpoint of the AWS S3. | (none) | Yes | 0.7.0-incubating |
+| `s3-access-key-id` | The access key of the AWS S3. | (none) | Yes | 0.7.0-incubating |
+| `s3-secret-access-key` | The secret key of the AWS S3. | (none) | Yes | 0.7.0-incubating |
+| `credential-providers` | The credential provider types, separated by comma, possible value can be `s3-token`, `s3-secret-key`. As the default authentication type is using AKSK as the above, this configuration can enable credential vending provided by Gravitino server and client will no longer need to provide authentication information like AKSK to access S3 by GVFS. Once it's set, more configuration items are needed to make it works, please see [s3-credential-vending](security/credential-vending.md#s3-credentials) | (none) | No | 0.8.0-incubating |
+
+:::note
+`default-filesystem-provider` and `filesystem-providers` are deprecated since 1.2.0. The fileset catalog automatically loads filesystem providers on the classpath, including buildin filesystem provider and cloud providers when the corresponding bundle jar is present (for example, `gravitino-aws-bundle`).
+:::
### Configurations for a schema
@@ -66,8 +70,7 @@ curl -X POST -H "Accept: application/vnd.gravitino.v1+json" \
"location": "s3a://bucket/root",
"s3-access-key-id": "access_key",
"s3-secret-access-key": "secret_key",
- "s3-endpoint": "http://s3.ap-northeast-1.amazonaws.com",
- "filesystem-providers": "s3"
+ "s3-endpoint": "http://s3.ap-northeast-1.amazonaws.com"
}
}' http://localhost:8090/api/metalakes/metalake/catalogs
```
@@ -86,7 +89,6 @@ Map<String, String> s3Properties = ImmutableMap.<String, String>builder()
.put("s3-access-key-id", "access_key")
.put("s3-secret-access-key", "secret_key")
.put("s3-endpoint", "http://s3.ap-northeast-1.amazonaws.com")
- .put("filesystem-providers", "s3")
.build();
Catalog s3Catalog = gravitinoClient.createCatalog("test_catalog",
@@ -106,8 +108,7 @@ s3_properties = {
"location": "s3a://bucket/root",
"s3-access-key-id": "access_key"
"s3-secret-access-key": "secret_key",
- "s3-endpoint": "http://s3.ap-northeast-1.amazonaws.com",
- "filesystem-providers": "s3"
+ "s3-endpoint": "http://s3.ap-northeast-1.amazonaws.com"
}
s3_catalog = gravitino_client.create_catalog(name="test_catalog",
@@ -517,7 +518,6 @@ curl -X POST -H "Accept: application/vnd.gravitino.v1+json" \
"s3-access-key-id": "access_key",
"s3-secret-access-key": "secret_key",
"s3-endpoint": "http://s3.ap-northeast-1.amazonaws.com",
- "filesystem-providers": "s3",
"credential-providers": "s3-token",
"s3-region":"ap-northeast-1",
"s3-role-arn":"The ARN of the role to access the S3 data"
@@ -564,4 +564,3 @@ spark = SparkSession.builder
Python client and Hadoop command are similar to the above examples.
-
diff --git a/docs/fileset-catalog.md b/docs/fileset-catalog.md
index f1b9407ef6..fbc5113239 100644
--- a/docs/fileset-catalog.md
+++ b/docs/fileset-catalog.md
@@ -28,18 +28,23 @@ Hadoop 3. If there's any compatibility issue, please create an [issue](https://g
Besides the [common catalog properties](./gravitino-server-config.md#apache-gravitino-catalog-properties-configuration),
the Fileset catalog has the following properties:
-| Property Name | Description | Default Value | Required | Since Version |
-|--------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------|----------|------------------|
-| `location` | The storage location managed by Fileset catalog. Its location name is `unknown`. The value should always a directory(HDFS) or path prefix(cloud storage like S3, GCS.) and does not support a single file. | (none) | No | 0.5.0 |
-| `location-` | The property prefix. User can use `location-{name}={path}` to set multiple locations with different names for the catalog. | (none) | No | 0.9.0-incubating |
-| `default-filesystem-provider` | The default filesystem provider of this Fileset catalog if users do not specify the scheme in the URI. Candidate values are 'builtin-local', 'builtin-hdfs', 's3', 'gcs', 'abs' and 'oss'. Default value is `builtin-local`. For S3, if we set this value to 's3', we can omit the prefix 's3a://' in the location. | `builtin-local` | No | 0.7.0-incubating |
-| `filesystem-providers` | The file system providers to add. Users need to set this configuration to support cloud storage or custom HCFS. For instance, set it to `s3` or a comma separated string that contains `s3` like `gs,s3` to support multiple kinds of fileset including `s3`. | (none) | Yes | 0.7.0-incubating |
-| `credential-providers` | The credential provider types, separated by comma. | (none) | No | 0.8.0-incubating |
-| `filesystem-conn-timeout-secs` | The timeout of getting the file system using Hadoop FileSystem client instance. Time unit: seconds. | 6 | No | 0.8.0-incubating |
-| `disable-filesystem-ops` | The configuration to disable file system operations in the server side. If set to true, the Fileset catalog in the server side will not create, drop files or folder when the schema, fileset is created, dropped. | false | No | 0.9.0-incubating |
-| `fileset-cache-eviction-interval-ms` | The interval in milliseconds to evict the fileset cache, -1 means never evict. | 3600000 | No | 0.9.0-incubating |
-| `fileset-cache-max-size` | The maximum number of the filesets the cache may contain, -1 means no limit. | 200000 | No | 0.9.0-incubating |
-| `config.resources` | The configuration resources, separated by comma. For example, `hdfs-site.xml,core-site.xml`. | (none) | No | 1.1.0 |
+| Property Name | Description | Default Value | Required | Since Version |
+|--------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------|----------|------------------|
+| `location` | The storage location managed by Fileset catalog. Its location name is `unknown`. The value should always a directory(HDFS) or path prefix(cloud storage like S3, GCS.) and does not support a single file. | (none) | No | 0.5.0 |
+| `location-` | The property prefix. User can use `location-{name}={path}` to set multiple locations with different names for the catalog. | (none) | No | 0.9.0-incubating |
+| `default-filesystem-provider` | (deprecated) The default filesystem provider of this Fileset catalog if users do not specify the scheme in the URI. Candidate values are 'builtin-local', 'builtin-hdfs', 's3', 'gcs', 'abs' and 'oss'. Default value is `builtin-local`. For S3, if we set this value to 's3', we can omit the prefix 's3a://' in the location. | `builtin-local` | No | 0.7.0-incubating |
+| `filesystem-providers` | (deprecated) The file system providers to add. Users need to set this configuration to support cloud storage or custom HCFS. For instance, set it to `s3` or a comma separated string that contains `s3` like `gs,s3` to support multiple kinds of fileset including `s3`. | (none) | NO | 0.7.0-incubating |
+| `credential-providers` | The credential provider types, separated by comma. | (none) | No | 0.8.0-incubating |
+| `filesystem-conn-timeout-secs` | The timeout of getting the file system using Hadoop FileSystem client instance. Time unit: seconds. | 6 | No | 0.8.0-incubating |
+| `disable-filesystem-ops` | The configuration to disable file system operations in the server side. If set to true, the Fileset catalog in the server side will not create, drop files or folder when the schema, fileset is created, dropped. | false | No | 0.9.0-incubating |
+| `fileset-cache-eviction-interval-ms` | The interval in milliseconds to evict the fileset cache, -1 means never evict. | 3600000 | No | 0.9.0-incubating |
+| `fileset-cache-max-size` | The maximum number of the filesets the cache may contain, -1 means no limit. | 200000 | No | 0.9.0-incubating |
+| `config.resources` | The configuration resources, separated by comma. For example, `hdfs-site.xml,core-site.xml`. | (none) | No | 1.1.0 |
+| `fs.path.config.<name>` | Defines a logical location entry. Set `fs.path.config.<name>` to the real base URI (for example, `hdfs://cluster1/`). Any key that starts with the same prefix (such as `fs.path.config.<name>.config.resource`) is treated as a location-scoped property and will be forwarded to the underlying filesystem client. | (none) | No | 1.2.0 |
+
+:::note
+`default-filesystem-provider` and `filesystem-providers` are deprecated since 1.2.0. The fileset catalog automatically loads filesystem providers on the classpath, including buildin filesystem provider and cloud providers when the corresponding bundle jar is present (for example, `gravitino-aws-bundle`, `gravitino-azure-bundle`, `gravitino-aliyun-bundle`, or `gravitino-gcp-bundle`).
+:::
Please refer to [Credential vending](./security/credential-vending.md) for more details about credential vending.
@@ -96,7 +101,6 @@ the jar [gravitino-hadoop-common](https://repo1.maven.org/maven2/org/apache/grav
// Name of the file system provider. 'builtin-local' for Local file system, 'builtin-hdfs' for HDFS,
// 's3' for AWS S3, 'gcs' for GCS, 'oss' for Aliyun OSS.
- // You need to set catalog properties `filesystem-providers` to support this file system.
String name();
```
@@ -107,8 +111,7 @@ the custom file system provider. For example, the content of `S3FileSystemProvid
![img.png](assets/fileset/custom-filesystem-provider.png)
After implementing the `FileSystemProvider` interface, you need to put the jar file into the
-`$GRAVITINO_HOME/catalogs/fileset/libs` directory. Then you can set the `filesystem-providers`
-property to use your custom file system provider.
+`$GRAVITINO_HOME/catalogs/fileset/libs` directory. Then you can use your custom file system provider.
### Authentication for fileset catalog
diff --git a/docs/manage-fileset-metadata-using-gravitino.md b/docs/manage-fileset-metadata-using-gravitino.md
index cb86df26dc..b3ab389b17 100644
--- a/docs/manage-fileset-metadata-using-gravitino.md
+++ b/docs/manage-fileset-metadata-using-gravitino.md
@@ -473,7 +473,6 @@ curl -X POST -H "Accept: application/vnd.gravitino.v1+json" \
"type": "FILESET",
"comment": "comment",
"properties": {
- "filesystem-providers": "builtin-local,builtin-hdfs,s3,gcs",
"location-l1": "file:///{{catalog}}/{{schema}}/workspace_{{project}}/{{user}}",
"location-l2": "hdfs:///{{catalog}}/{{schema}}/workspace_{{project}}/{{user}}"
}
@@ -539,7 +538,6 @@ Catalog catalog = gravitinoClient.createCatalog(
Type.FILESET,
"comment",
ImmutableMap.of(
- "filesystem-providers", "builtin-local,builtin-hdfs,s3,gcs",
"location-l1", "file:///{{catalog}}/{{schema}}/workspace_{{project}}/{{user}}",
"location-l2", "hdfs:///{{catalog}}/{{schema}}/workspace_{{project}}/{{user}}"));
FilesetCatalog filesetCatalog = catalog.asFilesetCatalog();
@@ -595,7 +593,6 @@ catalog: Catalog = gravitino_client.create_catalog(
provider=None,
comment="comment",
properties={
- "filesystem-providers": "builtin-local,builtin-hdfs,s3,gcs",
"location-l1": "file:///{{catalog}}/{{schema}}/workspace_{{project}}/{{user}}",
"location-l2": "hdfs:///{{catalog}}/{{schema}}/workspace_{{project}}/{{user}}",
}
@@ -921,3 +918,45 @@ curl -X POST -H "Accept: application/vnd.gravitino.v1+json" \
}' http://localhost:8090/api/metalakes/test/catalogs/fileset_catalog/schemas/test_schema/filesets
```
+Alternatively, you can pass configurations for multiple clusters using the `fs.path.config.{cluster_name}.*` format when creating the fileset catalog.
+All schemas and filesets under the catalog can inherit configuration based on the cluster name,
+and the configuration can be overridden at the schema or fileset level if needed.
+The system can automatically retrieve the appropriate configuration from `fs.path.config` configuration based on the fileset’s storage location
+and override the corresponding fileset properties by key.
+
+```text
+# create fileset catalog with multiple cluster configurations, and specify HDFS and S3 clusters configurations by logical names
+curl -X POST -H "Accept: application/vnd.gravitino.v1+json" \
+-H "Content-Type: application/json" -d '{
+ "name": "fileset_catalog",
+ "type": "FILESET",
+ "comment": "This is a fileset catalog",
+ "provider": "fileset",
+ "properties": {
+ "location": "hdfs://172.17.0.2:9000/fileset_catalog",
+ "fs.path.config.hadoop1"="hdfs://172.17.0.2:9000",
+ "fs.path.config.hadoop1.config.resources"="/etc/conf/cluster1/core-site.xml,/etc/conf/cluster1/hdfs-site.xml",
+ "fs.path.config.aws1"="s3://mybuctket",
+ "fs.path.config.aws1.access.key"="your_access_key",
+ "fs.path.config.aws1.secret.key"="your_secret_key"
+ }
+}' http://localhost:8090/api/metalakes/test/catalogs
+
+# create fileset fs1 in the default HDFS cluster, it will inherit the hadoop1 cluster configuration from the catalog
+curl -X POST -H "Accept: application/vnd.gravitino.v1+json"
+-H "Content-Type: application/json" -d '{
+ "name": "fs1",
+ "comment": "This is an example fileset",
+ "type": "MANAGED",
+ "storageLocation": "hdfs://172.17.0.2:9000/datawarehouse/fs1"
+}' http://localhost:8090/api/metalakes/test/catalogs/fileset_catalog/schemas/test_schema/filesets
+
+# create fileset fs2 in another s3 cluster, it will inherit the aws1 cluster configuration from the catalog
+curl -X POST -H "Accept: application/vnd.gravitino.v1+json" \
+-H "Content-Type: application/json" -d '{
+ "name": "fs2",
+ "comment": "This is an example fileset",
+ "type": "MANAGED",
+ "storageLocation": "s3://mybuctket/datawarehouse/fs2"
+}' http://localhost:8090/api/metalakes/test/catalogs/fileset_catalog/schemas/test_schema/filesets
+```