World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#7314] Implement ListFilesEvent in FilesetEventDispatcher (#7377)
Yunchi Pang224b075b1c40
diff --git a/core/src/main/java/org/apache/gravitino/listener/FilesetEventDispatcher.java b/core/src/main/java/org/apache/gravitino/listener/FilesetEventDispatcher.javaindex f332f84c10..77bbe390ae 100644--- a/core/src/main/java/org/apache/gravitino/listener/FilesetEventDispatcher.java+++ b/core/src/main/java/org/apache/gravitino/listener/FilesetEventDispatcher.java@@ -45,6 +45,9 @@ import org.apache.gravitino.listener.api.event.DropFilesetPreEvent;import org.apache.gravitino.listener.api.event.GetFileLocationEvent;import org.apache.gravitino.listener.api.event.GetFileLocationFailureEvent;import org.apache.gravitino.listener.api.event.GetFileLocationPreEvent;+import org.apache.gravitino.listener.api.event.ListFilesEvent;+import org.apache.gravitino.listener.api.event.ListFilesFailureEvent;+import org.apache.gravitino.listener.api.event.ListFilesPreEvent;import org.apache.gravitino.listener.api.event.ListFilesetEvent;import org.apache.gravitino.listener.api.event.ListFilesetFailureEvent;import org.apache.gravitino.listener.api.event.ListFilesetPreEvent;@@ -86,8 +89,19 @@ public class FilesetEventDispatcher implements FilesetDispatcher {@Overridepublic FileInfo[] listFiles(NameIdentifier ident, String locationName, String subPath)throws NoSuchFilesetException, IOException {- // TODO: implement the ListFilesEvent- return dispatcher.listFiles(ident, locationName, subPath);+ eventBus.dispatchEvent(+ new ListFilesPreEvent(PrincipalUtils.getCurrentUserName(), ident, locationName, subPath));+ try {+ FileInfo[] fileInfos = dispatcher.listFiles(ident, locationName, subPath);+ eventBus.dispatchEvent(+ new ListFilesEvent(PrincipalUtils.getCurrentUserName(), ident, locationName, subPath));+ return fileInfos;+ } catch (Exception e) {+ eventBus.dispatchEvent(+ new ListFilesFailureEvent(+ PrincipalUtils.getCurrentUserName(), ident, locationName, subPath, e));+ throw e;+ }}@Overridediff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/ListFilesEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/ListFilesEvent.javanew file mode 100644index 0000000000..6ec8712a7a--- /dev/null+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/ListFilesEvent.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.listener.api.event;++import org.apache.gravitino.NameIdentifier;+import org.apache.gravitino.annotation.DeveloperApi;++/**+ * Represents an event that is triggered upon the successful listing of files and directories under+ * a filesets within a system.+ */+@DeveloperApi+public final class ListFilesEvent extends FilesetEvent {+ private final String subPath;+ private final String locationName;++ /**+ * Constructs a new {@code ListFilesEvent}.+ *+ * @param user The user who initiated the listing of files/directories under the fileset.+ * @param ident The identifier of the fileset.+ * @param locationName The name of the location.+ * @param subPath The subPath of the fileset+ */+ public ListFilesEvent(String user, NameIdentifier ident, String locationName, String subPath) {+ super(user, ident);+ this.locationName = locationName;+ this.subPath = subPath;+ }++ public String locationName() {+ return locationName;+ }++ public String subPath() {+ return subPath;+ }++ /**+ * Returns the type of operation.+ *+ * @return the operation type.+ */+ @Override+ public OperationType operationType() {+ return OperationType.LIST_FILESET_FILES;+ }+}diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/ListFilesFailureEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/ListFilesFailureEvent.javanew file mode 100644index 0000000000..46b5ebfd8d--- /dev/null+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/ListFilesFailureEvent.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.listener.api.event;++import org.apache.gravitino.NameIdentifier;+import org.apache.gravitino.annotation.DeveloperApi;++@DeveloperApi+public class ListFilesFailureEvent extends FilesetFailureEvent {+ private final String locationName;+ private final String subPath;++ /**+ * Constructs a new {@code ListFilesFailureEvent}.+ *+ * @param user The user who initiated the listing of files/directories under the fileset.+ * @param ident The identifier of the fileset.+ * @param locationName The name of the location.+ * @param subPath The subPath of the fileset.+ * @param exception The exception encountered during the files listing attempt, which serves as an+ * indicator of the issues that caused the failure.+ */+ public ListFilesFailureEvent(+ String user, NameIdentifier ident, String locationName, String subPath, Exception exception) {+ super(user, ident, exception);+ this.locationName = locationName;+ this.subPath = subPath;+ }++ public String locationName() {+ return locationName;+ }++ public String subPath() {+ return subPath;+ }++ /**+ * Returns the type of operation.+ *+ * @return the operation type.+ */+ @Override+ public OperationType operationType() {+ return OperationType.LIST_FILESET_FILES;+ }+}diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/ListFilesPreEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/ListFilesPreEvent.javanew file mode 100644index 0000000000..8a454fd9ca--- /dev/null+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/ListFilesPreEvent.java@@ -0,0 +1,53 @@+/*+ * 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.listener.api.event;++import org.apache.gravitino.NameIdentifier;+import org.apache.gravitino.annotation.DeveloperApi;++@DeveloperApi+public class ListFilesPreEvent extends FilesetPreEvent {+ private final String locationName;+ private final String subPath;++ public ListFilesPreEvent(String user, NameIdentifier ident, String locationName, String subPath) {+ super(user, ident);+ this.locationName = locationName;+ this.subPath = subPath;+ }++ public String locationName() {+ return locationName;+ }++ public String subPath() {+ return subPath;+ }++ /**+ * Returns the type of operation.+ *+ * @return the operation type.+ */+ @Override+ public OperationType operationType() {+ return OperationType.LIST_FILESET_FILES;+ }+}diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/OperationType.java b/core/src/main/java/org/apache/gravitino/listener/api/event/OperationType.javaindex cd1ed914a1..f6162c77ef 100644--- a/core/src/main/java/org/apache/gravitino/listener/api/event/OperationType.java+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/OperationType.java@@ -57,6 +57,7 @@ public enum OperationType {ALTER_FILESET,CREATE_FILESET,LIST_FILESET,+ LIST_FILESET_FILES,LOAD_FILESET,GET_FILESET_LOCATION,diff --git a/core/src/test/java/org/apache/gravitino/listener/api/event/TestFilesetEvent.java b/core/src/test/java/org/apache/gravitino/listener/api/event/TestFilesetEvent.javaindex 1f0795652b..967758e99b 100644--- a/core/src/test/java/org/apache/gravitino/listener/api/event/TestFilesetEvent.java+++ b/core/src/test/java/org/apache/gravitino/listener/api/event/TestFilesetEvent.java@@ -27,6 +27,7 @@ import static org.mockito.Mockito.when;import com.google.common.collect.ImmutableMap;import com.google.common.collect.Maps;+import java.io.IOException;import java.util.Arrays;import java.util.Map;import org.apache.gravitino.NameIdentifier;@@ -173,6 +174,29 @@ public class TestFilesetEvent {Assertions.assertEquals(OperationStatus.UNPROCESSED, preEvent.operationStatus());}+ @Test+ void testListFilesetFilesEvent() throws IOException {+ NameIdentifier identifier = NameIdentifier.of("metalake", "catalog", fileset.name());+ String locationName = "default";+ String subPath = "/";+ dispatcher.listFiles(identifier, locationName, subPath);+ Event event = dummyEventListener.popPostEvent();+ Assertions.assertEquals(identifier, event.identifier());+ Assertions.assertEquals(ListFilesEvent.class, event.getClass());+ Assertions.assertEquals(locationName, ((ListFilesEvent) event).locationName());+ Assertions.assertEquals(subPath, ((ListFilesEvent) event).subPath());+ Assertions.assertEquals(OperationType.LIST_FILESET_FILES, event.operationType());+ Assertions.assertEquals(OperationStatus.SUCCESS, event.operationStatus());++ PreEvent preEvent = dummyEventListener.popPreEvent();+ Assertions.assertEquals(ListFilesPreEvent.class, preEvent.getClass());+ Assertions.assertEquals(identifier, preEvent.identifier());+ Assertions.assertEquals(locationName, ((ListFilesPreEvent) preEvent).locationName());+ Assertions.assertEquals(subPath, ((ListFilesPreEvent) preEvent).subPath());+ Assertions.assertEquals(OperationType.LIST_FILESET_FILES, preEvent.operationType());+ Assertions.assertEquals(OperationStatus.UNPROCESSED, preEvent.operationStatus());+ }+@Testvoid testGetFileLocationEvent() {NameIdentifier identifier = NameIdentifier.of("metalake", "catalog", fileset.name());@@ -305,6 +329,25 @@ public class TestFilesetEvent {Assertions.assertEquals(OperationStatus.FAILURE, event.operationStatus());}+ @Test+ void testListFilesetFilesFailureEvent() {+ NameIdentifier identifier = NameIdentifier.of("metalake", "catalog", "fileset");+ String locationName = "default";+ String subPath = "/";+ Assertions.assertThrowsExactly(+ GravitinoRuntimeException.class,+ () -> failureDispatcher.listFiles(identifier, locationName, subPath));+ Event event = dummyEventListener.popPostEvent();+ Assertions.assertEquals(identifier, event.identifier());+ Assertions.assertEquals(ListFilesFailureEvent.class, event.getClass());+ Assertions.assertEquals(+ GravitinoRuntimeException.class, ((ListFilesFailureEvent) event).exception().getClass());+ Assertions.assertEquals(locationName, ((ListFilesFailureEvent) event).locationName());+ Assertions.assertEquals(subPath, ((ListFilesFailureEvent) event).subPath());+ Assertions.assertEquals(OperationType.LIST_FILESET_FILES, event.operationType());+ Assertions.assertEquals(OperationStatus.FAILURE, event.operationStatus());+ }+@Testvoid testGetFileLocationFailureEvent() {NameIdentifier identifier = NameIdentifier.of("metalake", "catalog", "fileset");diff --git a/docs/gravitino-server-config.md b/docs/gravitino-server-config.mdindex 20fc313d47..3ba749bc1e 100644--- a/docs/gravitino-server-config.md+++ b/docs/gravitino-server-config.md@@ -121,7 +121,7 @@ Gravitino triggers a pre-event before the operation, a post-event after the comp| Operation type | Post-event | Since Version ||-------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------|| table operation | `CreateTableEvent`, `AlterTableEvent`, `DropTableEvent`, `LoadTableEvent`, `ListTableEvent`, `PurgeTableFailureEvent`, `CreateTableFailureEvent`, `AlterTableFailureEvent`, `DropTableFailureEvent`, `LoadTableFailureEvent`, `ListTableFailureEvent`, `PurgeTableFailureEvent` | 0.5.0 |-| fileset operation | `CreateFileSetEvent`, `AlterFileSetEvent`, `DropFileSetEvent`, `LoadFileSetEvent`, `ListFileSetEvent`, `CreateFileSetFailureEvent`, `AlterFileSetFailureEvent`, `DropFileSetFailureEvent`, `LoadFileSetFailureEvent`, `ListFileSetFailureEvent` | 0.5.0 |+| fileset operation | `CreateFileSetEvent`, `AlterFileSetEvent`, `DropFileSetEvent`, `LoadFileSetEvent`, `ListFileSetEvent`, `CreateFileSetFailureEvent`, `AlterFileSetFailureEvent`, `DropFileSetFailureEvent`, `LoadFileSetFailureEvent`, `ListFileSetFailureEvent`, `ListFilesFailureEvent` | 0.5.0 || topic operation | `CreateTopicEvent`, `AlterTopicEvent`, `DropTopicEvent`, `LoadTopicEvent`, `ListTopicEvent`, `CreateTopicFailureEvent`, `AlterTopicFailureEvent`, `DropTopicFailureEvent`, `LoadTopicFailureEvent`, `ListTopicFailureEvent` | 0.5.0 || schema operation | `CreateSchemaEvent`, `AlterSchemaEvent`, `DropSchemaEvent`, `LoadSchemaEvent`, `ListSchemaEvent`, `CreateSchemaFailureEvent`, `AlterSchemaFailureEvent`, `DropSchemaFailureEvent`, `LoadSchemaFailureEvent`, `ListSchemaFailureEvent` | 0.5.0 || catalog operation | `CreateCatalogEvent`, `AlterCatalogEvent`, `DropCatalogEvent`, `LoadCatalogEvent`, `ListCatalogEvent`, `CreateCatalogFailureEvent`, `AlterCatalogFailureEvent`, `DropCatalogFailureEvent`, `LoadCatalogFailureEvent`, `ListCatalogFailureEvent` | 0.5.0 |@@ -145,7 +145,7 @@ Gravitino triggers a pre-event before the operation, a post-event after the comp| Gravitino server catalog operation | `CreateCatalogPreEvent`, `AlterCatalogPreEvent`, `DropCatalogPreEvent`, `LoadCatalogPreEvent`, `ListCatalogPreEvent` | 0.8.0-incubating || Gravitino server metalake operation | `CreateMetalakePreEvent`, `AlterMetalakePreEvent`,`DropMetalakePreEvent`,`LoadMetalakePreEvent`,`ListMetalakePreEvent` | 0.8.0-incubating || Gravitino server partition operation | `AddPartitionPreEvent`, `DropPartitionPreEvent`, `GetPartitionPreEvent`, `PurgePartitionPreEvent`,`ListPartitionPreEvent`,`ListPartitionNamesPreEvent` | 0.8.0-incubating |-| Gravitino server fileset operation | `CreateFilesetPreEvent`, `AlterFilesetPreEvent`, `DropFilesetPreEvent`, `LoadFilesetPreEvent`,`ListFilesetPreEvent`,`GetFileLocationPreEvent` | 0.8.0-incubating |+| Gravitino server fileset operation | `CreateFilesetPreEvent`, `AlterFilesetPreEvent`, `DropFilesetPreEvent`, `LoadFilesetPreEvent`,`ListFilesetPreEvent`,`GetFileLocationPreEvent`, `ListFilesPreEvent` | 0.8.0-incubating || Gravitino server model operation | `DeleteModelPreEvent`, `DeleteModelVersionPreEvent`, `RegisterAndLinkModelPreEvent`,`GetModelPreEvent`, `GetModelVersionPreEvent`,`LinkModelVersionPreEvent`,`ListModelPreEvent`,`RegisterModelPreEvent`, `AlterModelPreEvent`, `AlterModelVersionPreEvent`, `AlterModelVersionPreEvent` | 0.9.0-incubating || Gravitino server tag operation | `ListTagsPreEvent`, `ListTagsInfoPreEvent`, `CreateTagPreEvent`, `GetTagPreEvent`, `AlterTagPreEvent`, `DeleteTagPreEvent`, `ListMetadataObjectsForTagPreEvent`, `ListTagsForMetadataObjectPreEvent`, `ListTagsInfoForMetadataObjectPreEvent`, `AssociateTagsForMetadataObjectPreEvent`, `GetTagForMetadataObjectPreEvent` | 0.9.0-incubating || Gravitino server user operation | `AddUserPreEvent`, `GetUserPreEvent`, `ListUserNamesPreEvent`, `ListUsersPreEvent`, `RemoveUserPreEvent`, `GrantUserRolesPreEvent`, `RevokeUserRolesPreEvent` | 0.9.0-incubating |