World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#4277] feat(client/server): Add the `getFileLocation` interface code skeleton (#4281)
xloyaecddeed8bf58
diff --git a/LICENSE b/LICENSEindex a2d4737924..33eaa2bb89 100644--- a/LICENSE+++ b/LICENSE@@ -266,6 +266,7 @@./dev/docker/hive/hadoop-env.sh./dev/docker/kerberos-hive/hadoop-env.sh./dev/docker/kerberos-hive/yarn-env.sh+ ./common/src/main/java/org/apache/gravitino/audit/CallerContext.java./common/src/main/java/org/apache/gravitino/auth/KerberosUtils.java./server-common/src/main/java/org/apache/gravitino/server/authentication/KerberosAuthenticator.java./server-common/src/test/java/org/apache/gravitino/server/authentication/KerberosTestUtils.javadiff --git a/api/src/main/java/org/apache/gravitino/file/FilesetCatalog.java b/api/src/main/java/org/apache/gravitino/file/FilesetCatalog.javaindex bdd4d02ff2..a4ba788eef 100644--- a/api/src/main/java/org/apache/gravitino/file/FilesetCatalog.java+++ b/api/src/main/java/org/apache/gravitino/file/FilesetCatalog.java@@ -120,4 +120,15 @@ public interface FilesetCatalog {* @return true If the fileset is dropped, false the fileset did not exist.*/boolean dropFileset(NameIdentifier ident);++ /**+ * Get the actual location of a file or directory based on the storage location of Fileset and the+ * sub path.+ *+ * @param ident A fileset identifier.+ * @param subPath The sub path to the file or directory.+ * @return The actual location of the file or directory.+ * @throws NoSuchFilesetException If the fileset does not exist.+ */+ String getFileLocation(NameIdentifier ident, String subPath) throws NoSuchFilesetException;}diff --git a/catalogs/catalog-hadoop/src/main/java/org/apache/gravitino/catalog/hadoop/HadoopCatalogOperations.java b/catalogs/catalog-hadoop/src/main/java/org/apache/gravitino/catalog/hadoop/HadoopCatalogOperations.javaindex eed8da9a14..0de7b27e15 100644--- a/catalogs/catalog-hadoop/src/main/java/org/apache/gravitino/catalog/hadoop/HadoopCatalogOperations.java+++ b/catalogs/catalog-hadoop/src/main/java/org/apache/gravitino/catalog/hadoop/HadoopCatalogOperations.java@@ -354,6 +354,12 @@ public class HadoopCatalogOperations implements CatalogOperations, SupportsSchem}}+ @Override+ public String getFileLocation(NameIdentifier ident, String subPath)+ throws NoSuchFilesetException {+ throw new UnsupportedOperationException("Not implemented");+ }+@Overridepublic NameIdentifier[] listSchemas(Namespace namespace) throws NoSuchCatalogException {try {diff --git a/catalogs/catalog-hadoop/src/main/java/org/apache/gravitino/catalog/hadoop/SecureHadoopCatalogOperations.java b/catalogs/catalog-hadoop/src/main/java/org/apache/gravitino/catalog/hadoop/SecureHadoopCatalogOperations.javaindex 1952cbd252..284fd491d0 100644--- a/catalogs/catalog-hadoop/src/main/java/org/apache/gravitino/catalog/hadoop/SecureHadoopCatalogOperations.java+++ b/catalogs/catalog-hadoop/src/main/java/org/apache/gravitino/catalog/hadoop/SecureHadoopCatalogOperations.java@@ -218,6 +218,12 @@ public class SecureHadoopCatalogOperationsreturn hadoopCatalogOperations.loadFileset(ident);}+ @Override+ public String getFileLocation(NameIdentifier ident, String subPath)+ throws NoSuchFilesetException {+ throw new UnsupportedOperationException("Not implemented");+ }+@Overridepublic void close() throws IOException {hadoopCatalogOperations.close();diff --git a/clients/client-java/src/main/java/org/apache/gravitino/client/FilesetCatalog.java b/clients/client-java/src/main/java/org/apache/gravitino/client/FilesetCatalog.javaindex 3f0d49530e..f568370b13 100644--- a/clients/client-java/src/main/java/org/apache/gravitino/client/FilesetCatalog.java+++ b/clients/client-java/src/main/java/org/apache/gravitino/client/FilesetCatalog.java@@ -226,6 +226,21 @@ class FilesetCatalog extends BaseSchemaCatalog implements org.apache.gravitino.freturn resp.dropped();}+ /**+ * Get the actual path of a file or directory based on the storage location of Fileset and the sub+ * path.+ *+ * @param ident A fileset identifier.+ * @param subPath The sub path to the file or directory.+ * @return The actual location of the file or directory.+ * @throws NoSuchFilesetException If the fileset does not exist.+ */+ @Override+ public String getFileLocation(NameIdentifier ident, String subPath)+ throws NoSuchFilesetException {+ throw new UnsupportedOperationException("Not implemented");+ }+@VisibleForTestingstatic String formatFilesetRequestPath(Namespace ns) {Namespace schemaNs = Namespace.of(ns.level(0), ns.level(1));diff --git a/common/src/main/java/org/apache/gravitino/audit/CallerContext.java b/common/src/main/java/org/apache/gravitino/audit/CallerContext.javanew file mode 100644index 0000000000..e0289779f6--- /dev/null+++ b/common/src/main/java/org/apache/gravitino/audit/CallerContext.java@@ -0,0 +1,132 @@+/*+ * 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.audit;++import com.google.common.base.Objects;+import com.google.common.base.Preconditions;+import java.util.Map;++/**+ * A class defining the caller context for auditing coarse granularity operations.+ *+ * <p>Reference:+ *+ * <p>hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/CallerContext.java+ */+public class CallerContext {+ private Map<String, String> context;++ private CallerContext() {}++ /**+ * Returns the context map in the caller context.+ *+ * @return the context map+ */+ public Map<String, String> context() {+ return context;+ }++ @Override+ public boolean equals(Object o) {+ if (this == o) return true;+ if (!(o instanceof CallerContext)) return false;+ CallerContext context1 = (CallerContext) o;+ return Objects.equal(context, context1.context);+ }++ @Override+ public int hashCode() {+ return Objects.hashCode(context);+ }++ /** Builder to create a caller context. */+ public static class Builder {+ private final CallerContext callerContext;++ private Builder() {+ callerContext = new CallerContext();+ }++ /**+ * Sets the context for CallerContext+ *+ * @param context The context to set.+ * @return This Builder instance for method chaining.+ */+ public CallerContext.Builder withContext(Map<String, String> context) {+ callerContext.context = context;+ return this;+ }++ /** Validate the variables in the CallerContext. */+ private void validate() {+ Preconditions.checkArgument(callerContext.context != null, "context cannot be null");+ }++ /**+ * Build the CallerContext.+ *+ * @return The CallerContext.+ */+ public CallerContext build() {+ validate();+ return callerContext;+ }+ }++ /**+ * Create a new builder for the CallerContext.+ *+ * @return A new builder for the CallerContext.+ */+ public static CallerContext.Builder builder() {+ return new CallerContext.Builder();+ }++ /** A thread local holder for the CallerContext. */+ public static class CallerContextHolder {++ private static final ThreadLocal<CallerContext> CALLER_CONTEXT = new ThreadLocal<>();++ /**+ * Get the CallerContext from the thread local.+ *+ * @return The CallerContext.+ */+ public static CallerContext get() {+ return CALLER_CONTEXT.get();+ }++ /**+ * Set the CallerContext in the thread local.+ *+ * @param context The CallerContext to set.+ */+ public static void set(CallerContext context) {+ CALLER_CONTEXT.set(context);+ }++ /** Remove the CallerContext from the thread local. */+ public static void remove() {+ CALLER_CONTEXT.remove();+ }+ }+}diff --git a/common/src/main/java/org/apache/gravitino/audit/FilesetAuditConstants.java b/common/src/main/java/org/apache/gravitino/audit/FilesetAuditConstants.javanew file mode 100644index 0000000000..188f750946--- /dev/null+++ b/common/src/main/java/org/apache/gravitino/audit/FilesetAuditConstants.java@@ -0,0 +1,31 @@+/*+ * 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.audit;++/** Constants used for fileset data operation audits. */+public class FilesetAuditConstants {+ private FilesetAuditConstants() {}++ /** The HTTP header used to pass the internal client type. */+ public static final String HTTP_HEADER_INTERNAL_CLIENT_TYPE = "InternalClientType";++ /** The HTTP header used to pass the fileset data operation. */+ public static final String HTTP_HEADER_FILESET_DATA_OPERATION = "FilesetDataOperation";+}diff --git a/common/src/main/java/org/apache/gravitino/audit/FilesetDataOperation.java b/common/src/main/java/org/apache/gravitino/audit/FilesetDataOperation.javanew file mode 100644index 0000000000..0324d4594e--- /dev/null+++ b/common/src/main/java/org/apache/gravitino/audit/FilesetDataOperation.java@@ -0,0 +1,63 @@+/*+ * 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.audit;++/** An enum class containing fileset data operations that supported. */+public enum FilesetDataOperation {+ /** This data operation means that create a new file. */+ CREATE,+ /** This data operation means that open a file. */+ OPEN,+ /** This data operation means that append some content into a file. */+ APPEND,+ /** This data operation means that rename a file or a directory. */+ RENAME,+ /** This data operation means that delete a file or a directory. */+ DELETE,+ /** This data operation means that get a file status from a file or a directory. */+ GET_FILE_STATUS,+ /** This data operation means that list file statuses under a directory. */+ LIST_STATUS,+ /** This data operation means that create a directory. */+ MKDIRS,+ /** This data operation means that get the default replication of a file system. */+ GET_DEFAULT_REPLICATION,+ /** This data operation means that get the default block size of a file system. */+ GET_DEFAULT_BLOCK_SIZE,+ /** This data operation means that set current working directory. */+ SET_WORKING_DIR,+ /** This data operation means that it is an unknown data operation. */+ UNKNOWN;++ /**+ * Check if the operation is valid.+ *+ * @param operation the operation to check+ * @return true if the operation is valid, false otherwise+ */+ public static boolean checkValid(String operation) {+ try {+ FilesetDataOperation.valueOf(operation);+ return true;+ } catch (IllegalArgumentException e) {+ throw new IllegalArgumentException("Unknown fileset data operation: " + operation, e);+ }+ }+}diff --git a/common/src/main/java/org/apache/gravitino/audit/InternalClientType.java b/common/src/main/java/org/apache/gravitino/audit/InternalClientType.javanew file mode 100644index 0000000000..8c273f1d71--- /dev/null+++ b/common/src/main/java/org/apache/gravitino/audit/InternalClientType.java@@ -0,0 +1,51 @@+/*+ * 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.audit;++/** An enum class containing internal client type that supported. */+public enum InternalClientType {+ /**+ * The client type is `org.apache.gravitino.filesystem.hadoop.GravitinoVirtualFileSystem` which in+ * the filesystem-hadoop3 module.+ */+ HADOOP_GVFS,+ /**+ * The client type is `gravitino.filesystem.gvfs.GravitinoVirtualFileSystem` which in the+ * client-python module.+ */+ PYTHON_GVFS,+ /** The client type is unknown. */+ UNKNOWN;++ /**+ * Check if the client type is valid.+ *+ * @param clientType the client type+ * @return true if the client type is valid, false otherwise+ */+ public static boolean checkValid(String clientType) {+ try {+ InternalClientType.valueOf(clientType);+ return true;+ } catch (IllegalArgumentException e) {+ throw new IllegalArgumentException("Unknown internal client type: " + clientType, e);+ }+ }+}diff --git a/common/src/main/java/org/apache/gravitino/dto/responses/FileLocationResponse.java b/common/src/main/java/org/apache/gravitino/dto/responses/FileLocationResponse.javanew file mode 100644index 0000000000..42da22ab5b--- /dev/null+++ b/common/src/main/java/org/apache/gravitino/dto/responses/FileLocationResponse.java@@ -0,0 +1,64 @@+/*+ * 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.dto.responses;++import com.fasterxml.jackson.annotation.JsonProperty;+import com.google.common.base.Preconditions;+import lombok.EqualsAndHashCode;+import lombok.Getter;+import lombok.ToString;+import org.apache.commons.lang3.StringUtils;++/** Response for the actual file location. */+@Getter+@ToString+@EqualsAndHashCode(callSuper = true)+public class FileLocationResponse extends BaseResponse {+ @JsonProperty("fileLocation")+ private final String fileLocation;++ /** Constructor for FileLocationResponse. */+ public FileLocationResponse() {+ super(0);+ this.fileLocation = null;+ }++ /**+ * Constructor for FileLocationResponse.+ *+ * @param fileLocation the actual file location.+ */+ public FileLocationResponse(String fileLocation) {+ super(0);+ this.fileLocation = fileLocation;+ }++ /**+ * Validates the response.+ *+ * @throws IllegalArgumentException if the response is invalid.+ */+ @Override+ public void validate() throws IllegalArgumentException {+ super.validate();+ Preconditions.checkArgument(+ StringUtils.isNotBlank(fileLocation), "fileLocation must not be null");+ }+}diff --git a/common/src/test/java/org/apache/gravitino/audit/TestCallerContext.java b/common/src/test/java/org/apache/gravitino/audit/TestCallerContext.javanew file mode 100644index 0000000000..e0f3d4d56c--- /dev/null+++ b/common/src/test/java/org/apache/gravitino/audit/TestCallerContext.java@@ -0,0 +1,45 @@+/*+ * 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.audit;++import java.util.HashMap;+import java.util.Map;+import org.junit.jupiter.api.Assertions;+import org.junit.jupiter.api.Test;++public class TestCallerContext {+ @Test+ public void testCallerContext() {+ try {+ Map<String, String> contextMap = new HashMap<>();+ contextMap.put("test", "test");+ contextMap.put("test2", "test2");+ CallerContext callerContext = CallerContext.builder().withContext(contextMap).build();+ CallerContext.CallerContextHolder.set(callerContext);++ CallerContext actualCallerContext = CallerContext.CallerContextHolder.get();++ Assertions.assertEquals(callerContext, actualCallerContext);+ Assertions.assertEquals(callerContext.context(), actualCallerContext.context());+ } finally {+ CallerContext.CallerContextHolder.remove();+ }+ }+}diff --git a/common/src/test/java/org/apache/gravitino/dto/responses/TestResponses.java b/common/src/test/java/org/apache/gravitino/dto/responses/TestResponses.javaindex 242c0f9535..5f94782022 100644--- a/common/src/test/java/org/apache/gravitino/dto/responses/TestResponses.java+++ b/common/src/test/java/org/apache/gravitino/dto/responses/TestResponses.java@@ -377,4 +377,17 @@ public class TestResponses {Exception e = assertThrows(IllegalArgumentException.class, response1::validate);assertEquals("\"tag\" must not be null", e.getMessage());}++ @Test+ void testFileLocationResponse() {+ String actualFileLocation = "file:/test/1";+ FileLocationResponse response = new FileLocationResponse(actualFileLocation);+ response.validate(); // No exception thrown+ }++ @Test+ void testFileLocationResponseException() {+ FileLocationResponse response = new FileLocationResponse();+ assertThrows(IllegalArgumentException.class, () -> response.validate());+ }}diff --git a/core/src/main/java/org/apache/gravitino/catalog/FilesetNormalizeDispatcher.java b/core/src/main/java/org/apache/gravitino/catalog/FilesetNormalizeDispatcher.javaindex d79630392a..4c87efcee5 100644--- a/core/src/main/java/org/apache/gravitino/catalog/FilesetNormalizeDispatcher.java+++ b/core/src/main/java/org/apache/gravitino/catalog/FilesetNormalizeDispatcher.java@@ -94,6 +94,11 @@ public class FilesetNormalizeDispatcher implements FilesetDispatcher {return dispatcher.dropFileset(normalizeCaseSensitive(ident));}+ @Override+ public String getFileLocation(NameIdentifier ident, String subPath) {+ throw new UnsupportedOperationException("Not implemented");+ }+private NameIdentifier normalizeNameIdentifier(NameIdentifier ident) {Capability capabilities = getCapability(ident, catalogManager);return applyCapabilities(ident, Capability.Scope.FILESET, capabilities);diff --git a/core/src/main/java/org/apache/gravitino/catalog/FilesetOperationDispatcher.java b/core/src/main/java/org/apache/gravitino/catalog/FilesetOperationDispatcher.javaindex e28369f96b..73339bb898 100644--- a/core/src/main/java/org/apache/gravitino/catalog/FilesetOperationDispatcher.java+++ b/core/src/main/java/org/apache/gravitino/catalog/FilesetOperationDispatcher.java@@ -195,4 +195,19 @@ public class FilesetOperationDispatcher extends OperationDispatcher implements Fc -> c.doWithFilesetOps(f -> f.dropFileset(ident)),NonEmptyEntityException.class);}++ /**+ * Get the actual location of a file or directory based on the storage location of Fileset and the+ * sub path.+ *+ * @param ident A fileset identifier.+ * @param subPath The sub path to the file or directory.+ * @return The actual location of the file or directory.+ * @throws NoSuchFilesetException If the fileset does not exist.+ */+ @Override+ public String getFileLocation(NameIdentifier ident, String subPath)+ throws NoSuchFilesetException {+ throw new UnsupportedOperationException("Not implemented");+ }}diff --git a/core/src/main/java/org/apache/gravitino/hook/FilesetHookDispatcher.java b/core/src/main/java/org/apache/gravitino/hook/FilesetHookDispatcher.javaindex 6e5a82eb26..9557ecb725 100644--- a/core/src/main/java/org/apache/gravitino/hook/FilesetHookDispatcher.java+++ b/core/src/main/java/org/apache/gravitino/hook/FilesetHookDispatcher.java@@ -93,4 +93,10 @@ public class FilesetHookDispatcher implements FilesetDispatcher {public boolean filesetExists(NameIdentifier ident) {return dispatcher.filesetExists(ident);}++ @Override+ public String getFileLocation(NameIdentifier ident, String subPath)+ throws NoSuchFilesetException {+ throw new UnsupportedOperationException("Not implemented");+ }}diff --git a/core/src/main/java/org/apache/gravitino/listener/FilesetEventDispatcher.java b/core/src/main/java/org/apache/gravitino/listener/FilesetEventDispatcher.javaindex 4daac06bab..108220dfc9 100644--- a/core/src/main/java/org/apache/gravitino/listener/FilesetEventDispatcher.java+++ b/core/src/main/java/org/apache/gravitino/listener/FilesetEventDispatcher.java@@ -138,4 +138,10 @@ public class FilesetEventDispatcher implements FilesetDispatcher {throw e;}}++ @Override+ public String getFileLocation(NameIdentifier ident, String subPath)+ throws NoSuchFilesetException {+ throw new UnsupportedOperationException("Not implemented");+ }}diff --git a/core/src/test/java/org/apache/gravitino/connector/TestCatalogOperations.java b/core/src/test/java/org/apache/gravitino/connector/TestCatalogOperations.javaindex 7588af17c5..0b73bf4b2d 100644--- a/core/src/test/java/org/apache/gravitino/connector/TestCatalogOperations.java+++ b/core/src/test/java/org/apache/gravitino/connector/TestCatalogOperations.java@@ -430,6 +430,11 @@ public class TestCatalogOperations}}+ @Override+ public String getFileLocation(NameIdentifier ident, String subPath) {+ throw new UnsupportedOperationException("Not implemented");+ }+@Overridepublic NameIdentifier[] listTopics(Namespace namespace) throws NoSuchSchemaException {return topics.keySet().stream()