World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#5552] feat(core): add metalake pre event to Gravitino event (#5583)
Qiang-Liu1a08d54df906
diff --git a/core/src/main/java/org/apache/gravitino/listener/MetalakeEventDispatcher.java b/core/src/main/java/org/apache/gravitino/listener/MetalakeEventDispatcher.javaindex 535d337b30..0ff109a483 100644--- a/core/src/main/java/org/apache/gravitino/listener/MetalakeEventDispatcher.java+++ b/core/src/main/java/org/apache/gravitino/listener/MetalakeEventDispatcher.java@@ -29,14 +29,19 @@ import org.apache.gravitino.exceptions.NoSuchMetalakeException;import org.apache.gravitino.exceptions.NonEmptyEntityException;import org.apache.gravitino.listener.api.event.AlterMetalakeEvent;import org.apache.gravitino.listener.api.event.AlterMetalakeFailureEvent;+import org.apache.gravitino.listener.api.event.AlterMetalakePreEvent;import org.apache.gravitino.listener.api.event.CreateMetalakeEvent;import org.apache.gravitino.listener.api.event.CreateMetalakeFailureEvent;+import org.apache.gravitino.listener.api.event.CreateMetalakePreEvent;import org.apache.gravitino.listener.api.event.DropMetalakeEvent;import org.apache.gravitino.listener.api.event.DropMetalakeFailureEvent;+import org.apache.gravitino.listener.api.event.DropMetalakePreEvent;import org.apache.gravitino.listener.api.event.ListMetalakeEvent;import org.apache.gravitino.listener.api.event.ListMetalakeFailureEvent;+import org.apache.gravitino.listener.api.event.ListMetalakePreEvent;import org.apache.gravitino.listener.api.event.LoadMetalakeEvent;import org.apache.gravitino.listener.api.event.LoadMetalakeFailureEvent;+import org.apache.gravitino.listener.api.event.LoadMetalakePreEvent;import org.apache.gravitino.listener.api.info.MetalakeInfo;import org.apache.gravitino.metalake.MetalakeDispatcher;import org.apache.gravitino.utils.PrincipalUtils;@@ -65,6 +70,7 @@ public class MetalakeEventDispatcher implements MetalakeDispatcher {@Overridepublic Metalake[] listMetalakes() {+ eventBus.dispatchEvent(new ListMetalakePreEvent(PrincipalUtils.getCurrentUserName()));try {Metalake[] metalakes = dispatcher.listMetalakes();eventBus.dispatchEvent(new ListMetalakeEvent(PrincipalUtils.getCurrentUserName()));@@ -77,6 +83,7 @@ public class MetalakeEventDispatcher implements MetalakeDispatcher {@Overridepublic Metalake loadMetalake(NameIdentifier ident) throws NoSuchMetalakeException {+ eventBus.dispatchEvent(new LoadMetalakePreEvent(PrincipalUtils.getCurrentUserName(), ident));try {Metalake metalake = dispatcher.loadMetalake(ident);eventBus.dispatchEvent(@@ -99,6 +106,10 @@ public class MetalakeEventDispatcher implements MetalakeDispatcher {public Metalake createMetalake(NameIdentifier ident, String comment, Map<String, String> properties)throws MetalakeAlreadyExistsException {+ MetalakeInfo createMetalakeRequest = new MetalakeInfo(ident.name(), comment, properties, null);+ eventBus.dispatchEvent(+ new CreateMetalakePreEvent(+ PrincipalUtils.getCurrentUserName(), ident, createMetalakeRequest));try {Metalake metalake = dispatcher.createMetalake(ident, comment, properties);eventBus.dispatchEvent(@@ -117,6 +128,8 @@ public class MetalakeEventDispatcher implements MetalakeDispatcher {@Overridepublic Metalake alterMetalake(NameIdentifier ident, MetalakeChange... changes)throws NoSuchMetalakeException, IllegalArgumentException {+ eventBus.dispatchEvent(+ new AlterMetalakePreEvent(PrincipalUtils.getCurrentUserName(), ident, changes));try {Metalake metalake = dispatcher.alterMetalake(ident, changes);eventBus.dispatchEvent(@@ -133,6 +146,7 @@ public class MetalakeEventDispatcher implements MetalakeDispatcher {@Overridepublic boolean dropMetalake(NameIdentifier ident, boolean force)throws NonEmptyEntityException, MetalakeInUseException {+ eventBus.dispatchEvent(new DropMetalakePreEvent(PrincipalUtils.getCurrentUserName(), ident));try {boolean isExists = dispatcher.dropMetalake(ident, force);eventBus.dispatchEvent(diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/AlterMetalakePreEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/AlterMetalakePreEvent.javanew file mode 100644index 0000000000..68fede7bae--- /dev/null+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/AlterMetalakePreEvent.java@@ -0,0 +1,46 @@+/*+ * 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.MetalakeChange;+import org.apache.gravitino.NameIdentifier;+import org.apache.gravitino.annotation.DeveloperApi;++/** Represents an event triggered before altering a metalake. */+@DeveloperApi+public class AlterMetalakePreEvent extends PreEvent {+ private final MetalakeChange[] metalakeChanges;++ public AlterMetalakePreEvent(+ String user, NameIdentifier identifier, MetalakeChange[] metalakeChanges) {+ super(user, identifier);+ this.metalakeChanges = metalakeChanges;+ }++ /**+ * Retrieves the specific changes that were made to the metalake during the alteration process.+ *+ * @return An array of {@link MetalakeChange} objects detailing each modification applied to the+ * metalake.+ */+ public MetalakeChange[] metalakeChanges() {+ return metalakeChanges;+ }+}diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/CreateMetalakePreEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/CreateMetalakePreEvent.javanew file mode 100644index 0000000000..951c03670f--- /dev/null+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/CreateMetalakePreEvent.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.listener.api.event;++import org.apache.gravitino.NameIdentifier;+import org.apache.gravitino.annotation.DeveloperApi;+import org.apache.gravitino.listener.api.info.MetalakeInfo;++/** Represents an event triggered before creating a metalake. */+@DeveloperApi+public class CreateMetalakePreEvent extends MetalakePreEvent {++ private final MetalakeInfo createMetalakeRequest;++ public CreateMetalakePreEvent(+ String user, NameIdentifier identifier, MetalakeInfo createMetalakeRequest) {+ super(user, identifier);+ this.createMetalakeRequest = createMetalakeRequest;+ }++ /**+ * @return A {@link MetalakeInfo} instance encapsulating the comprehensive details of create+ * metalake+ */+ public MetalakeInfo createMetalakeRequest() {+ return createMetalakeRequest;+ }+}diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/DropMetalakePreEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/DropMetalakePreEvent.javanew file mode 100644index 0000000000..91ee886ff3--- /dev/null+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/DropMetalakePreEvent.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 an event triggered before dropping a metalake. */+@DeveloperApi+public class DropMetalakePreEvent extends MetalakePreEvent {++ public DropMetalakePreEvent(String user, NameIdentifier identifier) {+ super(user, identifier);+ }+}diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/ListMetalakePreEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/ListMetalakePreEvent.javanew file mode 100644index 0000000000..f97198e349--- /dev/null+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/ListMetalakePreEvent.java@@ -0,0 +1,30 @@+/*+ * 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.annotation.DeveloperApi;++/** Represents an event triggered before listing a metalake. */+@DeveloperApi+public class ListMetalakePreEvent extends MetalakePreEvent {++ public ListMetalakePreEvent(String user) {+ super(user, null);+ }+}diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/LoadMetalakePreEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/LoadMetalakePreEvent.javanew file mode 100644index 0000000000..58a805e938--- /dev/null+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/LoadMetalakePreEvent.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 an event triggered before loading a metalake. */+@DeveloperApi+public class LoadMetalakePreEvent extends MetalakePreEvent {+ public LoadMetalakePreEvent(String user, NameIdentifier identifier) {+ super(user, identifier);+ }+}diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/MetalakePreEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/MetalakePreEvent.javanew file mode 100644index 0000000000..a44ad80630--- /dev/null+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/MetalakePreEvent.java@@ -0,0 +1,32 @@+/*+ * 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 metalake operations. */+@DeveloperApi+public abstract class MetalakePreEvent extends PreEvent {++ protected MetalakePreEvent(String user, NameIdentifier identifier) {+ super(user, identifier);+ }+}diff --git a/core/src/test/java/org/apache/gravitino/listener/api/event/TestMetalakeEvent.java b/core/src/test/java/org/apache/gravitino/listener/api/event/TestMetalakeEvent.javaindex 2b5377f759..39f727dc59 100644--- a/core/src/test/java/org/apache/gravitino/listener/api/event/TestMetalakeEvent.java+++ b/core/src/test/java/org/apache/gravitino/listener/api/event/TestMetalakeEvent.java@@ -69,6 +69,12 @@ public class TestMetalakeEvent {Assertions.assertEquals(CreateMetalakeEvent.class, event.getClass());MetalakeInfo metalakeInfo = ((CreateMetalakeEvent) event).createdMetalakeInfo();checkMetalakeInfo(metalakeInfo, metalake);++ PreEvent preEvent = dummyEventListener.popPreEvent();+ Assertions.assertEquals(identifier, preEvent.identifier());+ Assertions.assertEquals(CreateMetalakePreEvent.class, preEvent.getClass());+ metalakeInfo = ((CreateMetalakePreEvent) preEvent).createMetalakeRequest();+ checkMetalakeInfo(metalakeInfo, metalake);}@Test@@ -80,6 +86,10 @@ public class TestMetalakeEvent {Assertions.assertEquals(LoadMetalakeEvent.class, event.getClass());MetalakeInfo metalakeInfo = ((LoadMetalakeEvent) event).loadedMetalakeInfo();checkMetalakeInfo(metalakeInfo, metalake);++ PreEvent preEvent = dummyEventListener.popPreEvent();+ Assertions.assertEquals(identifier, preEvent.identifier());+ Assertions.assertEquals(LoadMetalakePreEvent.class, preEvent.getClass());}@Test@@ -95,6 +105,13 @@ public class TestMetalakeEvent {MetalakeChange[] metalakeChanges = ((AlterMetalakeEvent) event).metalakeChanges();Assertions.assertTrue(metalakeChanges.length == 1);Assertions.assertEquals(metalakeChange, metalakeChanges[0]);++ PreEvent preEvent = dummyEventListener.popPreEvent();+ Assertions.assertEquals(identifier, preEvent.identifier());+ Assertions.assertEquals(AlterMetalakePreEvent.class, preEvent.getClass());+ Assertions.assertEquals(1, ((AlterMetalakePreEvent) preEvent).metalakeChanges().length);+ Assertions.assertEquals(+ metalakeChange, ((AlterMetalakePreEvent) preEvent).metalakeChanges()[0]);}@Test@@ -105,6 +122,10 @@ public class TestMetalakeEvent {Assertions.assertEquals(identifier, event.identifier());Assertions.assertEquals(DropMetalakeEvent.class, event.getClass());Assertions.assertTrue(((DropMetalakeEvent) event).isExists());++ PreEvent preEvent = dummyEventListener.popPreEvent();+ Assertions.assertEquals(identifier, preEvent.identifier());+ Assertions.assertEquals(DropMetalakePreEvent.class, preEvent.getClass());}@Testdiff --git a/docs/gravitino-server-config.md b/docs/gravitino-server-config.mdindex 35838393ae..9049be5b81 100644--- a/docs/gravitino-server-config.md+++ b/docs/gravitino-server-config.md@@ -135,6 +135,7 @@ Gravitino triggers a pre-event before the operation, a post-event after the comp| Gravitino server table operation | `CreateTablePreEvent`, `AlterTablePreEvent`, `DropTablePreEvent`, `PurgeTablePreEvent`, `LoadTablePreEvent`, `ListTablePreEvent` | 0.8.0-incubating || 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 |#### Event listener plugin