diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/DropModelEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/DropModelEvent.java new file mode 100644 index 00000000000..5a063ea0ee6 --- /dev/null +++ b/core/src/main/java/org/apache/gravitino/listener/api/event/DropModelEvent.java @@ -0,0 +1,75 @@ +/* + * 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.listener.api.info.ModelInfo; + +/** Event representing the successful drop of a model. */ +public class DropModelEvent extends ModelEvent { + private final ModelInfo dropModelInfo; + private final boolean isExists; + + /** + * Constructs an instance of {@code DropModelEvent}, capturing essential details about the + * successful drop of a model. + * + * @param user The username of the individual who initiated the model drop operation. + * @param identifier The unique identifier of the model that was dropped. + * @param dropModelInfo The state of the model post-drop operation. + * @param isExists A boolean flag indicating whether the model existed at the time of the drop + * operation. + */ + public DropModelEvent( + String user, NameIdentifier identifier, ModelInfo dropModelInfo, boolean isExists) { + super(user, identifier); + this.dropModelInfo = dropModelInfo; + this.isExists = isExists; + } + + /** + * Retrieves the state of the model post-drop operation. + * + * @return The state of the model post-drop operation. + */ + public ModelInfo DropModelInfo() { + return dropModelInfo; + } + + /** + * Retrieves the existence status of the model at the time of the drop operation. + * + * @return A boolean value indicating whether the model existed. {@code true} if the model + * existed, otherwise {@code false}. + */ + public boolean isExists() { + return isExists; + } + + /** + * Returns the type of operation. + * + * @return the operation type. + */ + @Override + public OperationType operationType() { + return OperationType.DROP_MODEL; + } +} diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/DropModelVersionEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/DropModelVersionEvent.java new file mode 100644 index 00000000000..d329a2ef676 --- /dev/null +++ b/core/src/main/java/org/apache/gravitino/listener/api/event/DropModelVersionEvent.java @@ -0,0 +1,78 @@ +/* + * 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.listener.api.info.ModelInfo; + +/** + * Represents an event that is generated after a model version is successfully dropped from the + * model. + */ +public class DropModelVersionEvent extends ModelEvent { + + private final ModelInfo dropModelVersionInfo; + private final boolean isExists; + + /** + * Constructs a new {@code DropModelVersionEvent} instance, encapsulating information about the + * outcome of a model version drop operation. + * + * @param user The user who initiated the drop model version operation. + * @param identifier The identifier of the model that was attempted to be dropped a version. + * @param isExists A boolean flag indicating whether the model version existed at the time of the + * drop operation. + */ + public DropModelVersionEvent( + String user, NameIdentifier identifier, ModelInfo dropModelVersionInfo, boolean isExists) { + super(user, identifier); + this.dropModelVersionInfo = dropModelVersionInfo; + this.isExists = isExists; + } + + /** + * Retrieves the state of the model after the drop version operation. + * + * @return The state of the model after the drop version operation. + */ + public ModelInfo DropModelVersionInfo() { + return dropModelVersionInfo; + } + + /** + * Retrieves the existence status of the model version at the time of the drop operation. + * + * @return A boolean value indicating whether the model version existed. {@code true} if the table + * existed, otherwise {@code false}. + */ + public boolean isExists() { + return isExists; + } + + /** + * Returns the type of operation. + * + * @return the operation type. + */ + @Override + public OperationType operationType() { + return OperationType.DROP_MODEL_VERSION; + } +} diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/GetModelEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/GetModelEvent.java new file mode 100644 index 00000000000..fd10fc5afad --- /dev/null +++ b/core/src/main/java/org/apache/gravitino/listener/api/event/GetModelEvent.java @@ -0,0 +1,60 @@ +/* + * 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.listener.api.info.ModelInfo; + +/** Represents an event triggered upon the successful getting of a model. */ +public class GetModelEvent extends ModelEvent { + private final ModelInfo modelInfo; + + /** + * Constructs an instance of {@code GetModelEvent}, capturing essential details about the + * successful getting of a model. + * + * @param user The username of the individual who initiated the model get. + * @param identifier The unique identifier of the model that was get. + * @param modelInfo The state of the model post-get. + */ + public GetModelEvent(String user, NameIdentifier identifier, ModelInfo modelInfo) { + super(user, identifier); + this.modelInfo = modelInfo; + } + + /** + * Retrieves the state of the model as it was made available to the user after successful getting. + * + * @return A {@link ModelInfo} instance encapsulating the details of the model as get. + */ + public ModelInfo getModelInfo() { + return modelInfo; + } + + /** + * Returns the type of operation. + * + * @return the operation type. + */ + @Override + public OperationType operationType() { + return OperationType.GET_MODEL; + } +} diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/GetModelVersionEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/GetModelVersionEvent.java new file mode 100644 index 00000000000..b8519c38edf --- /dev/null +++ b/core/src/main/java/org/apache/gravitino/listener/api/event/GetModelVersionEvent.java @@ -0,0 +1,61 @@ +/* + * 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.listener.api.info.ModelInfo; + +/** Represents an event triggered upon the successful getting the version of a model. */ +public class GetModelVersionEvent extends ModelEvent { + public final ModelInfo GetModelVersionInfo; + + /** + * Constructs an instance of {@code GetModelVersionEvent}. + * + * @param user The username of the individual who initiated the get model version event. + * @param identifier The unique identifier of the model that was getting the version. + * @param getModelVersionInfo The state of the model after the version was loaded. + */ + public GetModelVersionEvent( + String user, NameIdentifier identifier, ModelInfo getModelVersionInfo) { + super(user, identifier); + GetModelVersionInfo = getModelVersionInfo; + } + + /** + * Retrieves the state of the model as it was made available to the user after successful getting + * the version. + * + * @return A {@link ModelInfo} instance encapsulating the details of the model version. + */ + public ModelInfo getModelVersionInfo() { + return GetModelVersionInfo; + } + + /** + * Returns the type of operation. + * + * @return the operation type. + */ + @Override + public OperationType operationType() { + return OperationType.GET_MODEL_VERSION; + } +} diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/LinkModelVersionEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/LinkModelVersionEvent.java new file mode 100644 index 00000000000..17eae5d5de0 --- /dev/null +++ b/core/src/main/java/org/apache/gravitino/listener/api/event/LinkModelVersionEvent.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.listener.api.event; + +import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.listener.api.info.ModelInfo; + +/** Represents an event triggered upon the successful linking of a model version. */ +public class LinkModelVersionEvent extends ModelEvent { + private ModelInfo linkModelVersionInfo; + + /** + * Constructs an instance of {@code LinkModelVersionEvent}, capturing essential details about the + * successful linking of a model version. + * + * @param user The username of the individual who initiated the model version linking. + * @param identifier The unique identifier of the model that was linked. + * @param linkModelVersionInfo The final state of the model after linking. + */ + public LinkModelVersionEvent( + String user, NameIdentifier identifier, ModelInfo linkModelVersionInfo) { + super(user, identifier); + this.linkModelVersionInfo = linkModelVersionInfo; + } + + /** + * Retrieves the final state of the model, as it was returned to the user after successful link a + * model version. + * + * @return A {@link ModelInfo} instance encapsulating the comprehensive details of the newly model + * version. + */ + public ModelInfo linkModelVersionInfo() { + return linkModelVersionInfo; + } + + /** + * Returns the type of operation. + * + * @return the operation type. + */ + @Override + public OperationType operationType() { + return OperationType.LINK_MODEL_VERSION; + } +} diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/ListModelEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/ListModelEvent.java new file mode 100644 index 00000000000..cf430e9c6e0 --- /dev/null +++ b/core/src/main/java/org/apache/gravitino/listener/api/event/ListModelEvent.java @@ -0,0 +1,65 @@ +/* + * 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.Namespace; + +/** + * Represents an event that is triggered upon the successful list of models within a namespace. + * + *
To optimize memory usage and avoid the potential overhead associated with storing a large + * number of tables directly within the ListTableEvent, the actual tables listed are not maintained + * in this event. This design decision helps in managing resource efficiency, especially in + * environments with extensive table listings. + */ +public class ListModelEvent extends ModelEvent { + private final Namespace namespace; + + /** + * Constructs an instance of {@code ListTableEvent}. + * + * @param user The username of the individual who initiated the model listing. + * @param namespace The namespace from which models were listed. + */ + public ListModelEvent(String user, Namespace namespace) { + super(user, NameIdentifier.of(namespace.levels())); + this.namespace = namespace; + } + + /** + * Provides the namespace associated with this event. + * + * @return A {@link Namespace} instance from which models were listed. + */ + public Namespace namespace() { + return namespace; + } + + /** + * Returns the type of operation. + * + * @return the operation type. + */ + @Override + public OperationType operationType() { + return OperationType.LIST_MODEL; + } +} diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/ListModelVersionsEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/ListModelVersionsEvent.java new file mode 100644 index 00000000000..5892b2d73ea --- /dev/null +++ b/core/src/main/java/org/apache/gravitino/listener/api/event/ListModelVersionsEvent.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.listener.api.event; + +import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.listener.api.info.ModelInfo; + +/** + * Represents an event that is triggered upon the successful list of model versions within a model. + */ +public class ListModelVersionsEvent extends ModelEvent { + + private final ModelInfo listModelVersionInfo; + + /** + * Constructs an instance of {@code ListModelVersionsEvent}. + * + * @param user The username of the individual who initiated the model version listing. + * @param identifier The unique identifier of the model that it's version was listed. + * @param listModelVersionInfo The model information containing the list of model versions. + */ + public ListModelVersionsEvent( + String user, NameIdentifier identifier, ModelInfo listModelVersionInfo) { + super(user, identifier); + this.listModelVersionInfo = listModelVersionInfo; + } + + /** + * Retrieves the model information containing the list of model versions. + * + * @return A {@link ModelInfo} instance containing the list of model versions. + */ + public ModelInfo listModelVersionInfo() { + return listModelVersionInfo; + } + + /** + * Returns the type of operation. + * + * @return the operation type. + */ + @Override + public OperationType operationType() { + return OperationType.LIST_MODEL_VERSIONS; + } +} diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/ModelEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/ModelEvent.java new file mode 100644 index 00000000000..fff03355c76 --- /dev/null +++ b/core/src/main/java/org/apache/gravitino/listener/api/event/ModelEvent.java @@ -0,0 +1,50 @@ +/* + * 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; + +/** + * Represents an abstract base class for events related to Model operations. This class extends + * {@link Event} to provide a more specific context involving operations on Models, such as link, + * register, or modification. It captures essential information including the user performing the + * operation and the identifier of the model being operated on. + * + *
Concrete implementations of this class should provide additional details pertinent to the
+ * specific type of model operation being represented.
+ */
+public abstract class ModelEvent extends Event {
+
+ /**
+ * Constructs a new ModelEvent with the specified user and model identifier.
+ *
+ * @param user The user responsible for triggering the model operation.
+ * @param identifier The identifier of the Model involved in the operation. This encapsulates
+ * details such as the metalake, catalog, schema, and Model name.
+ */
+ protected ModelEvent(String user, NameIdentifier identifier) {
+ super(user, identifier);
+ }
+
+ @Override
+ public OperationStatus operationStatus() {
+ return OperationStatus.SUCCESS;
+ }
+}
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.java
index 00cbf1e1a4e..f9e5c9265c5 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
@@ -86,5 +86,17 @@ public enum OperationType {
RENAME_VIEW,
LIST_VIEW,
+ // Model event
+ REGISTER_MODEL,
+ DROP_MODEL,
+ GET_MODEL,
+ LIST_MODEL,
+
+ // Model Version
+ LINK_MODEL_VERSION,
+ DROP_MODEL_VERSION,
+ GET_MODEL_VERSION,
+ LIST_MODEL_VERSIONS,
+
UNKNOWN,
}
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/RegisterModelEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/RegisterModelEvent.java
new file mode 100644
index 00000000000..feeb1a1dfdf
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/RegisterModelEvent.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.listener.api.event;
+
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.listener.api.info.ModelInfo;
+
+/** Represents an event triggered upon the successful registration of a model. */
+public class RegisterModelEvent extends ModelEvent {
+ private final ModelInfo registeredTopicInfo;
+
+ /**
+ * Constructs an instance of RegisterModelEvent, capturing essential details about the successful
+ * registration of a model.
+ *
+ * @param user The user responsible for triggering the model operation.
+ * @param identifier The identifier of the Model involved in the operation. This encapsulates
+ * details such as the metalake, catalog, schema, and Model name.
+ * @param registeredTopicInfo The final state of the model post-creation.
+ */
+ protected RegisterModelEvent(
+ String user, NameIdentifier identifier, ModelInfo registeredTopicInfo) {
+ super(user, identifier);
+ this.registeredTopicInfo = registeredTopicInfo;
+ }
+
+ /**
+ * Retrieves the final state of the model as it was returned to the user after successful
+ * registration.
+ *
+ * @return the model information.
+ */
+ public ModelInfo registeredModelInfo() {
+ return registeredTopicInfo;
+ }
+
+ /**
+ * Returns the type of operation.
+ *
+ * @return the operation type.
+ */
+ @Override
+ public OperationType operationType() {
+ return OperationType.REGISTER_MODEL;
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/info/ModelInfo.java b/core/src/main/java/org/apache/gravitino/listener/api/info/ModelInfo.java
new file mode 100644
index 00000000000..5d271c2347e
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/listener/api/info/ModelInfo.java
@@ -0,0 +1,96 @@
+/*
+ * 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.info;
+
+import java.util.Map;
+import javax.annotation.Nullable;
+import lombok.Getter;
+import org.apache.gravitino.Audit;
+import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.model.Model;
+import org.apache.gravitino.model.ModelVersion;
+
+/**
+ * ModelInfo exposes model information for event listener, it's supposed to be read only. Most of
+ * the fields are shallow copied internally not deep copies for performance.
+ */
+@DeveloperApi
+public class ModelInfo {
+ @Getter private final String name;
+ @Nullable private final String comment;
+ @Getter private final Map