World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#5550] feat(core): add partition pre event to Gravitino event (#5590)
Qiang-Liuc1b988520e9a
diff --git a/core/src/main/java/org/apache/gravitino/listener/PartitionEventDispatcher.java b/core/src/main/java/org/apache/gravitino/listener/PartitionEventDispatcher.javaindex 31e51de8c1..d439b41a5d 100644--- a/core/src/main/java/org/apache/gravitino/listener/PartitionEventDispatcher.java+++ b/core/src/main/java/org/apache/gravitino/listener/PartitionEventDispatcher.java@@ -25,18 +25,24 @@ import org.apache.gravitino.exceptions.NoSuchPartitionException;import org.apache.gravitino.exceptions.PartitionAlreadyExistsException;import org.apache.gravitino.listener.api.event.AddPartitionEvent;import org.apache.gravitino.listener.api.event.AddPartitionFailureEvent;+import org.apache.gravitino.listener.api.event.AddPartitionPreEvent;import org.apache.gravitino.listener.api.event.DropPartitionEvent;import org.apache.gravitino.listener.api.event.DropPartitionFailureEvent;+import org.apache.gravitino.listener.api.event.DropPartitionPreEvent;import org.apache.gravitino.listener.api.event.GetPartitionEvent;import org.apache.gravitino.listener.api.event.GetPartitionFailureEvent;+import org.apache.gravitino.listener.api.event.GetPartitionPreEvent;import org.apache.gravitino.listener.api.event.ListPartitionEvent;import org.apache.gravitino.listener.api.event.ListPartitionFailureEvent;import org.apache.gravitino.listener.api.event.ListPartitionNamesEvent;import org.apache.gravitino.listener.api.event.ListPartitionNamesFailureEvent;+import org.apache.gravitino.listener.api.event.ListPartitionNamesPreEvent;+import org.apache.gravitino.listener.api.event.ListPartitionPreEvent;import org.apache.gravitino.listener.api.event.PartitionExistsEvent;import org.apache.gravitino.listener.api.event.PartitionExistsFailureEvent;import org.apache.gravitino.listener.api.event.PurgePartitionEvent;import org.apache.gravitino.listener.api.event.PurgePartitionFailureEvent;+import org.apache.gravitino.listener.api.event.PurgePartitionPreEvent;import org.apache.gravitino.listener.api.info.partitions.PartitionInfo;import org.apache.gravitino.rel.partitions.Partition;import org.apache.gravitino.utils.PrincipalUtils;@@ -66,6 +72,9 @@ public class PartitionEventDispatcher implements PartitionDispatcher {@Overridepublic Partition addPartition(NameIdentifier ident, Partition partition)throws NoSuchPartitionException, PartitionAlreadyExistsException {+ eventBus.dispatchEvent(+ new AddPartitionPreEvent(+ PrincipalUtils.getCurrentUserName(), ident, PartitionInfo.of(partition)));try {Partition newPartition = dispatcher.addPartition(ident, partition);eventBus.dispatchEvent(@@ -84,6 +93,8 @@ public class PartitionEventDispatcher implements PartitionDispatcher {@Overridepublic Partition getPartition(NameIdentifier ident, String partitionName)throws NoSuchPartitionException {+ eventBus.dispatchEvent(+ new GetPartitionPreEvent(PrincipalUtils.getCurrentUserName(), ident, partitionName));try {Partition partition = dispatcher.getPartition(ident, partitionName);eventBus.dispatchEvent(@@ -100,6 +111,8 @@ public class PartitionEventDispatcher implements PartitionDispatcher {@Overridepublic boolean dropPartition(NameIdentifier ident, String partitionName) {+ eventBus.dispatchEvent(+ new DropPartitionPreEvent(PrincipalUtils.getCurrentUserName(), ident, partitionName));try {boolean isExists = dispatcher.dropPartition(ident, partitionName);eventBus.dispatchEvent(@@ -116,6 +129,7 @@ public class PartitionEventDispatcher implements PartitionDispatcher {@Overridepublic Partition[] listPartitions(NameIdentifier ident) {+ eventBus.dispatchEvent(new ListPartitionPreEvent(PrincipalUtils.getCurrentUserName(), ident));try {Partition[] listPartitions = dispatcher.listPartitions(ident);eventBus.dispatchEvent(new ListPartitionEvent(PrincipalUtils.getCurrentUserName(), ident));@@ -129,6 +143,8 @@ public class PartitionEventDispatcher implements PartitionDispatcher {@Overridepublic String[] listPartitionNames(NameIdentifier ident) {+ eventBus.dispatchEvent(+ new ListPartitionNamesPreEvent(PrincipalUtils.getCurrentUserName(), ident));try {String[] listPartitionNames = dispatcher.listPartitionNames(ident);eventBus.dispatchEvent(@@ -159,6 +175,8 @@ public class PartitionEventDispatcher implements PartitionDispatcher {@Overridepublic boolean purgePartition(NameIdentifier ident, String partitionName) {+ eventBus.dispatchEvent(+ new PurgePartitionPreEvent(PrincipalUtils.getCurrentUserName(), ident, partitionName));try {boolean isExists = dispatcher.purgePartition(ident, partitionName);eventBus.dispatchEvent(diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/AddPartitionPreEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/AddPartitionPreEvent.javanew file mode 100644index 0000000000..cf0c43e8ae--- /dev/null+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/AddPartitionPreEvent.java@@ -0,0 +1,57 @@+/*+ * Licensed to the Apache Software Foundation (ASF) under one+ * or more contributor license agreements. See the NOTICE file+ * distributed with this work for additional information+ * regarding copyright ownership. The ASF licenses this file+ * to you under the Apache License, Version 2.0 (the+ * "License"); you may not use this file except in compliance+ * with the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing,+ * software distributed under the License is distributed on an+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY+ * KIND, either express or implied. See the License for the+ * specific language governing permissions and limitations+ * under the License.+ */+package org.apache.gravitino.listener.api.event;++import org.apache.gravitino.NameIdentifier;+import org.apache.gravitino.annotation.DeveloperApi;+import org.apache.gravitino.listener.api.info.TableInfo;+import org.apache.gravitino.listener.api.info.partitions.PartitionInfo;++/** Represents an event triggered before creating a partition. */+@DeveloperApi+public class AddPartitionPreEvent extends PartitionPreEvent {++ private final PartitionInfo createPartitionRequest;++ public AddPartitionPreEvent(+ String user, NameIdentifier identifier, PartitionInfo createPartitionRequest) {+ super(user, identifier);+ this.createPartitionRequest = createPartitionRequest;+ }++ /**+ * Retrieves the create partition request.+ *+ * @return A {@link TableInfo} instance encapsulating the comprehensive details of create+ * partition request.+ */+ public PartitionInfo createdPartitionRequest() {+ return createPartitionRequest;+ }++ /**+ * Returns the type of operation.+ *+ * @return the operation type.+ */+ @Override+ public OperationType operationType() {+ return OperationType.ADD_PARTITION;+ }+}diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/DropPartitionPreEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/DropPartitionPreEvent.javanew file mode 100644index 0000000000..da677287e4--- /dev/null+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/DropPartitionPreEvent.java@@ -0,0 +1,47 @@+/*+ * 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 before dropping a partition. */+@DeveloperApi+public class DropPartitionPreEvent extends PartitionPreEvent {+ private final String partitionName;++ public DropPartitionPreEvent(String user, NameIdentifier identifier, String partitionName) {+ super(user, identifier);+ this.partitionName = partitionName;+ }++ public String partitionName() {+ return partitionName;+ }++ /**+ * Returns the type of operation.+ *+ * @return the operation type.+ */+ @Override+ public OperationType operationType() {+ return OperationType.DROP_PARTITION;+ }+}diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/GetPartitionPreEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/GetPartitionPreEvent.javanew file mode 100644index 0000000000..f373dfe6ee--- /dev/null+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/GetPartitionPreEvent.java@@ -0,0 +1,48 @@+/*+ * 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 before getting a partition. */+@DeveloperApi+public class GetPartitionPreEvent extends PartitionPreEvent {++ private final String partitionName;++ public GetPartitionPreEvent(String user, NameIdentifier identifier, String partitionName) {+ super(user, identifier);+ this.partitionName = partitionName;+ }++ public String partitionName() {+ return partitionName;+ }++ /**+ * Returns the type of operation.+ *+ * @return the operation type.+ */+ @Override+ public OperationType operationType() {+ return OperationType.LOAD_PARTITION;+ }+}diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/ListPartitionNamesPreEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/ListPartitionNamesPreEvent.javanew file mode 100644index 0000000000..c81db0ca10--- /dev/null+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/ListPartitionNamesPreEvent.java@@ -0,0 +1,41 @@+/*+ * 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 before listing of partition name within a namespace. */+@DeveloperApi+public class ListPartitionNamesPreEvent extends PartitionPreEvent {++ public ListPartitionNamesPreEvent(String user, NameIdentifier identifier) {+ super(user, identifier);+ }++ /**+ * Returns the type of operation.+ *+ * @return the operation type.+ */+ @Override+ public OperationType operationType() {+ return OperationType.LIST_PARTITION_NAMES;+ }+}diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/ListPartitionPreEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/ListPartitionPreEvent.javanew file mode 100644index 0000000000..36b87e628c--- /dev/null+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/ListPartitionPreEvent.java@@ -0,0 +1,40 @@+/*+ * 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 before listing of partition within a namespace. */+@DeveloperApi+public class ListPartitionPreEvent extends PartitionPreEvent {++ public ListPartitionPreEvent(String user, NameIdentifier identifier) {+ super(user, identifier);+ }+ /**+ * Returns the type of operation.+ *+ * @return the operation type.+ */+ @Override+ public OperationType operationType() {+ return OperationType.LIST_PARTITION;+ }+}diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/PartitionPreEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/PartitionPreEvent.javanew file mode 100644index 0000000000..3178530a65--- /dev/null+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/PartitionPreEvent.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.listener.api.event;++import org.apache.gravitino.NameIdentifier;+import org.apache.gravitino.annotation.DeveloperApi;++/** Represents a pre-event for partition operations. */+@DeveloperApi+public abstract class PartitionPreEvent extends PreEvent {++ protected PartitionPreEvent(String user, NameIdentifier identifier) {+ super(user, identifier);+ }+}diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/PurgePartitionPreEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/PurgePartitionPreEvent.javanew file mode 100644index 0000000000..5b9f96fcc4--- /dev/null+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/PurgePartitionPreEvent.java@@ -0,0 +1,47 @@+/*+ * 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 triggered before purging a partition. */+@DeveloperApi+public class PurgePartitionPreEvent extends PartitionPreEvent {++ private final String partitionName;++ public PurgePartitionPreEvent(String user, NameIdentifier identifier, String partitionName) {+ super(user, identifier);+ this.partitionName = partitionName;+ }++ public String partitionName() {+ return partitionName;+ }+ /**+ * Returns the type of operation.+ *+ * @return the operation type.+ */+ @Override+ public OperationType operationType() {+ return OperationType.PURGE_PARTITION;+ }+}diff --git a/core/src/test/java/org/apache/gravitino/listener/api/event/TestPartitionEvent.java b/core/src/test/java/org/apache/gravitino/listener/api/event/TestPartitionEvent.javaindex e8d616365d..6a5b389930 100644--- a/core/src/test/java/org/apache/gravitino/listener/api/event/TestPartitionEvent.java+++ b/core/src/test/java/org/apache/gravitino/listener/api/event/TestPartitionEvent.java@@ -117,6 +117,14 @@ public class TestPartitionEvent {checkPartitionInfo(partitionInfo, partition);Assertions.assertEquals(OperationType.ADD_PARTITION, event.operationType());Assertions.assertEquals(OperationStatus.SUCCESS, event.operationStatus());++ PreEvent preEvent = dummyEventListener.popPreEvent();+ Assertions.assertEquals(identifier, preEvent.identifier());+ Assertions.assertEquals(AddPartitionPreEvent.class, preEvent.getClass());+ partitionInfo = ((AddPartitionPreEvent) preEvent).createdPartitionRequest();+ checkPartitionInfo(partitionInfo, partition);+ Assertions.assertEquals(OperationType.ADD_PARTITION, preEvent.operationType());+ Assertions.assertEquals(OperationStatus.UNPROCESSED, preEvent.operationStatus());}@Test@@ -129,6 +137,12 @@ public class TestPartitionEvent {Assertions.assertEquals(false, ((DropPartitionEvent) event).isExists());Assertions.assertEquals(OperationType.DROP_PARTITION, event.operationType());Assertions.assertEquals(OperationStatus.SUCCESS, event.operationStatus());++ PreEvent preEvent = dummyEventListener.popPreEvent();+ Assertions.assertEquals(identifier, preEvent.identifier());+ Assertions.assertEquals(DropPartitionPreEvent.class, preEvent.getClass());+ Assertions.assertEquals(OperationType.DROP_PARTITION, preEvent.operationType());+ Assertions.assertEquals(OperationStatus.UNPROCESSED, preEvent.operationStatus());}@Test@@ -153,6 +167,12 @@ public class TestPartitionEvent {Assertions.assertEquals(identifier, ((ListPartitionEvent) event).identifier());Assertions.assertEquals(OperationType.LIST_PARTITION, event.operationType());Assertions.assertEquals(OperationStatus.SUCCESS, event.operationStatus());++ PreEvent preEvent = dummyEventListener.popPreEvent();+ Assertions.assertEquals(identifier, preEvent.identifier());+ Assertions.assertEquals(ListPartitionPreEvent.class, preEvent.getClass());+ Assertions.assertEquals(OperationType.LIST_PARTITION, preEvent.operationType());+ Assertions.assertEquals(OperationStatus.UNPROCESSED, preEvent.operationStatus());}@Test@@ -165,6 +185,12 @@ public class TestPartitionEvent {Assertions.assertEquals(identifier, ((ListPartitionNamesEvent) event).identifier());Assertions.assertEquals(OperationType.LIST_PARTITION_NAMES, event.operationType());Assertions.assertEquals(OperationStatus.SUCCESS, event.operationStatus());++ PreEvent preEvent = dummyEventListener.popPreEvent();+ Assertions.assertEquals(identifier, preEvent.identifier());+ Assertions.assertEquals(ListPartitionNamesPreEvent.class, preEvent.getClass());+ Assertions.assertEquals(OperationType.LIST_PARTITION_NAMES, preEvent.operationType());+ Assertions.assertEquals(OperationStatus.UNPROCESSED, preEvent.operationStatus());}@Test@@ -177,6 +203,12 @@ public class TestPartitionEvent {Assertions.assertEquals(identifier, ((PurgePartitionEvent) event).identifier());Assertions.assertEquals(OperationType.PURGE_PARTITION, event.operationType());Assertions.assertEquals(OperationStatus.SUCCESS, event.operationStatus());++ PreEvent preEvent = dummyEventListener.popPreEvent();+ Assertions.assertEquals(identifier, preEvent.identifier());+ Assertions.assertEquals(PurgePartitionPreEvent.class, preEvent.getClass());+ Assertions.assertEquals(OperationType.PURGE_PARTITION, preEvent.operationType());+ Assertions.assertEquals(OperationStatus.UNPROCESSED, preEvent.operationStatus());}@Test@@ -209,6 +241,11 @@ public class TestPartitionEvent {Assertions.assertEquals(identifier, event.identifier());Assertions.assertEquals(OperationType.DROP_PARTITION, event.operationType());Assertions.assertEquals(OperationStatus.FAILURE, event.operationStatus());++ PreEvent preEvent = dummyEventListener.popPreEvent();+ Assertions.assertEquals(identifier, preEvent.identifier());+ Assertions.assertEquals(DropPartitionPreEvent.class, preEvent.getClass());+ Assertions.assertEquals(partition.name(), ((DropPartitionPreEvent) preEvent).partitionName());}@Testdiff --git a/docs/gravitino-server-config.md b/docs/gravitino-server-config.mdindex 9049be5b81..4bbf03d25d 100644--- a/docs/gravitino-server-config.md+++ b/docs/gravitino-server-config.md@@ -136,6 +136,7 @@ Gravitino triggers a pre-event before the operation, a post-event after the comp| Gravitino server schema operation | `CreateSchemaPreEvent`, `AlterSchemaPreEvent`, `DropSchemaPreEvent`, `LoadSchemaPreEvent`, `ListSchemaPreEvent` | 0.8.0-incubating || 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 |#### Event listener plugin