Skip to content

Commit

Permalink
[apache#6078] feat(core): Support model event to Gravitino server
Browse files Browse the repository at this point in the history
Fix some error and add ModelEventDispatcher to Gravitino server.
  • Loading branch information
Abyss-lord committed Jan 14, 2025
1 parent cfcdb83 commit b0c8321
Show file tree
Hide file tree
Showing 10 changed files with 874 additions and 54 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@
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;

/**
Expand All @@ -33,26 +31,14 @@ public class DropModelEvent extends ModelEvent {
*
* @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) {
public DropModelEvent(String user, NameIdentifier identifier, 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.
*
Expand All @@ -72,4 +58,14 @@ public boolean isExists() {
public OperationType operationType() {
return OperationType.DROP_MODEL;
}

/**
* The status of the operation.
*
* @return The operation status.
*/
@Override
public OperationStatus operationStatus() {
return isExists() ? OperationStatus.SUCCESS : OperationStatus.UNPROCESSED;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@
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;

/**
Expand All @@ -40,22 +38,11 @@ public class DropModelVersionEvent extends ModelEvent {
* @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) {
public DropModelVersionEvent(String user, NameIdentifier identifier, 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.
*
Expand All @@ -75,4 +62,9 @@ public boolean isExists() {
public OperationType operationType() {
return OperationType.DROP_MODEL_VERSION;
}

@Override
public OperationStatus operationStatus() {
return isExists() ? OperationStatus.SUCCESS : OperationStatus.UNPROCESSED;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,18 @@

/** Represents an event triggered upon the successful getting the version of a model. */
public class GetModelVersionEvent extends ModelEvent {
public final ModelInfo getModelVersionInfo;
public final ModelInfo modelInfo;

/**
* 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.
* @param modelInfo The state of the model after the version was loaded.
*/
public GetModelVersionEvent(
String user, NameIdentifier identifier, ModelInfo getModelVersionInfo) {
public GetModelVersionEvent(String user, NameIdentifier identifier, ModelInfo modelInfo) {
super(user, identifier);
this.getModelVersionInfo = getModelVersionInfo;
this.modelInfo = modelInfo;
}

/**
Expand All @@ -46,7 +45,7 @@ public GetModelVersionEvent(
* @return A {@link ModelInfo} instance encapsulating the details of the model version.
*/
public ModelInfo getModelVersionInfo() {
return getModelVersionInfo;
return modelInfo;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,19 @@

/** Represents an event triggered upon the successful linking of a model version. */
public class LinkModelVersionEvent extends ModelEvent {
private ModelInfo linkModelVersionInfo;
private ModelInfo modelInfo;

/**
* 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.
* @param modelInfo The final state of the model after linking.
*/
public LinkModelVersionEvent(
String user, NameIdentifier identifier, ModelInfo linkModelVersionInfo) {
public LinkModelVersionEvent(String user, NameIdentifier identifier, ModelInfo modelInfo) {
super(user, identifier);
this.linkModelVersionInfo = linkModelVersionInfo;
this.modelInfo = modelInfo;
}

/**
Expand All @@ -48,7 +47,7 @@ public LinkModelVersionEvent(
* version.
*/
public ModelInfo linkModelVersionInfo() {
return linkModelVersionInfo;
return modelInfo;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,18 @@
*/
public class ListModelVersionsEvent extends ModelEvent {

private final ModelInfo listModelVersionInfo;
private final ModelInfo modelInfo;

/**
* 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.
* @param modelInfo The model information containing the list of model versions.
*/
public ListModelVersionsEvent(
String user, NameIdentifier identifier, ModelInfo listModelVersionInfo) {
public ListModelVersionsEvent(String user, NameIdentifier identifier, ModelInfo modelInfo) {
super(user, identifier);
this.listModelVersionInfo = listModelVersionInfo;
this.modelInfo = modelInfo;
}

/**
Expand All @@ -48,7 +47,7 @@ public ListModelVersionsEvent(
* @return A {@link ModelInfo} instance containing the list of model versions.
*/
public ModelInfo listModelVersionInfo() {
return listModelVersionInfo;
return modelInfo;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ public class RegisterModelEvent extends ModelEvent {
* 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) {
public RegisterModelEvent(String user, NameIdentifier identifier, ModelInfo registeredTopicInfo) {
super(user, identifier);
this.registeredTopicInfo = registeredTopicInfo;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
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
Expand All @@ -38,7 +37,7 @@ public class ModelInfo {
@Getter private final Map<String, String> properties;
@Nullable private final Audit audit;
@Getter private final int lastVersion;
private final ModelVersion[] versions;
private final ModelVersionInfo[] versions;

/**
* Constructs model information based on a given model.
Expand All @@ -55,7 +54,7 @@ public ModelInfo(Model model) {
* @param model the model to expose information for.
* @param modelVersions the versions of the model.
*/
public ModelInfo(Model model, ModelVersion[] modelVersions) {
public ModelInfo(Model model, ModelVersionInfo[] modelVersions) {
this.name = model.name();
this.properties = model.properties();
this.comment = model.comment();
Expand Down Expand Up @@ -90,7 +89,7 @@ public Audit getAudit() {
* @return the versions of the model or null if not set.
*/
@Nullable
public ModelVersion[] getModelVersion() {
public ModelVersionInfo[] modelVersions() {
return versions;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* 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.model.ModelVersion;

/**
* {@link ModelVersionInfo} exposes model version information for event listener, it's supposed to
* be read only. Most of the fields are shallow copied internally not deep copies for performance.
*/
public class ModelVersionInfo {
@Getter private final String uri;
@Getter @Nullable private final String[] aliases;
@Nullable private final String comment;
@Getter private final Map<String, String> properties;
@Nullable private final Audit auditInfo;

/**
* Constructs model version information based on a given {@link ModelVersion}.
*
* @param modelVersion the model version to expose information for.
*/
public ModelVersionInfo(ModelVersion modelVersion) {
this.uri = modelVersion.uri();
this.aliases = modelVersion.aliases();
this.comment = modelVersion.comment();
this.properties = modelVersion.properties();
this.auditInfo = modelVersion.auditInfo();
}

/**
* Constructs model version information based on a given arguments.
*
* @param uri
* @param aliases
* @param comment
* @param properties
*/
public ModelVersionInfo(
String uri, String[] aliases, String comment, Map<String, String> properties) {
this.uri = uri;
this.aliases = aliases;
this.comment = comment;
this.properties = properties;
this.auditInfo = null;
}

/**
* Returns the comment of the model version.
*
* @return the comment of the model version or null if not set.
*/
@Nullable
public String getComment() {
return comment;
}

/**
* Returns the audit information of the model version.
*
* @return the audit information of the model version or null if not set.
*/
@Nullable
public Audit getAudit() {
return auditInfo;
}
}
Loading

0 comments on commit b0c8321

Please sign in to comment.