Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#6079] fix(core): Support model failure event to Gravitino server #6670

Merged
merged 2 commits into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,23 @@
import org.apache.gravitino.exceptions.NoSuchModelException;
import org.apache.gravitino.exceptions.NoSuchModelVersionException;
import org.apache.gravitino.exceptions.NoSuchSchemaException;
import org.apache.gravitino.listener.api.event.DeleteModelFailureEvent;
import org.apache.gravitino.listener.api.event.DeleteModelPreEvent;
import org.apache.gravitino.listener.api.event.DeleteModelVersionFailureEvent;
import org.apache.gravitino.listener.api.event.DeleteModelVersionPreEvent;
import org.apache.gravitino.listener.api.event.GetModelFailureEvent;
import org.apache.gravitino.listener.api.event.GetModelPreEvent;
import org.apache.gravitino.listener.api.event.GetModelVersionFailureEvent;
import org.apache.gravitino.listener.api.event.GetModelVersionPreEvent;
import org.apache.gravitino.listener.api.event.LinkModelVersionFailureEvent;
import org.apache.gravitino.listener.api.event.LinkModelVersionPreEvent;
import org.apache.gravitino.listener.api.event.ListModelFailureEvent;
import org.apache.gravitino.listener.api.event.ListModelPreEvent;
import org.apache.gravitino.listener.api.event.ListModelVersionFailureEvent;
import org.apache.gravitino.listener.api.event.ListModelVersionPreEvent;
import org.apache.gravitino.listener.api.event.RegisterAndLinkModelFailureEvent;
import org.apache.gravitino.listener.api.event.RegisterAndLinkModelPreEvent;
import org.apache.gravitino.listener.api.event.RegisterModelFailureEvent;
import org.apache.gravitino.listener.api.event.RegisterModelPreEvent;
import org.apache.gravitino.listener.api.info.ModelInfo;
import org.apache.gravitino.listener.api.info.ModelVersionInfo;
Expand Down Expand Up @@ -70,15 +79,15 @@ public ModelEventDispatcher(EventBus eventBus, ModelDispatcher dispatcher) {
@Override
public Model registerModel(NameIdentifier ident, String comment, Map<String, String> properties)
throws NoSuchSchemaException, ModelAlreadyExistsException {
String user = PrincipalUtils.getCurrentUserName();
ModelInfo registerRequest = new ModelInfo(ident.name(), properties, comment);
eventBus.dispatchEvent(
new RegisterModelPreEvent(PrincipalUtils.getCurrentUserName(), ident, registerRequest));
eventBus.dispatchEvent(new RegisterModelPreEvent(user, ident, registerRequest));
try {
Model model = dispatcher.registerModel(ident, comment, properties);
// TODO: ModelEvent
return model;
} catch (Exception e) {
// TODO: failureEvent
eventBus.dispatchEvent(new RegisterModelFailureEvent(user, ident, e, registerRequest));
throw e;
}
}
Expand All @@ -96,59 +105,63 @@ public Model registerModel(
ModelInfo registerModelRequest = new ModelInfo(ident.name(), properties, comment);
ModelVersionInfo linkModelVersionRequest =
new ModelVersionInfo(uri, comment, properties, aliases);
String user = PrincipalUtils.getCurrentUserName();

RegisterAndLinkModelPreEvent registerAndLinkModelPreEvent =
new RegisterAndLinkModelPreEvent(
PrincipalUtils.getCurrentUserName(),
ident,
registerModelRequest,
linkModelVersionRequest);
user, ident, registerModelRequest, linkModelVersionRequest);
eventBus.dispatchEvent(registerAndLinkModelPreEvent);
try {
// TODO: ModelEvent
return dispatcher.registerModel(ident, uri, aliases, comment, properties);
} catch (Exception e) {
eventBus.dispatchEvent(
new RegisterAndLinkModelFailureEvent(
user, ident, e, registerModelRequest, linkModelVersionRequest));
throw e;
}
}

/** {@inheritDoc} */
@Override
public Model getModel(NameIdentifier ident) throws NoSuchModelException {
eventBus.dispatchEvent(new GetModelPreEvent(PrincipalUtils.getCurrentUserName(), ident));
String user = PrincipalUtils.getCurrentUserName();
eventBus.dispatchEvent(new GetModelPreEvent(user, ident));
try {
Model model = dispatcher.getModel(ident);
// TODO: ModelEvent
return model;
} catch (Exception e) {
// TODO: failureEvent
eventBus.dispatchEvent(new GetModelFailureEvent(user, ident, e));
throw e;
}
}

/** {@inheritDoc} */
@Override
public boolean deleteModel(NameIdentifier ident) {
eventBus.dispatchEvent(new DeleteModelPreEvent(PrincipalUtils.getCurrentUserName(), ident));
String user = PrincipalUtils.getCurrentUserName();
eventBus.dispatchEvent(new DeleteModelPreEvent(user, ident));
try {
// TODO: ModelEvent
return dispatcher.deleteModel(ident);
} catch (Exception e) {
// TODO: failureEvent
eventBus.dispatchEvent(new DeleteModelFailureEvent(user, ident, e));
throw e;
}
}

/** {@inheritDoc} */
@Override
public NameIdentifier[] listModels(Namespace namespace) throws NoSuchSchemaException {
eventBus.dispatchEvent(new ListModelPreEvent(PrincipalUtils.getCurrentUserName(), namespace));
String user = PrincipalUtils.getCurrentUserName();
eventBus.dispatchEvent(new ListModelPreEvent(user, namespace));
try {
NameIdentifier[] models = dispatcher.listModels(namespace);
// TODO: ModelEvent
return models;
} catch (Exception e) {
// TODO: failureEvent
eventBus.dispatchEvent(new ListModelFailureEvent(user, namespace, e));
throw e;
}
}
Expand All @@ -163,13 +176,14 @@ public void linkModelVersion(
Map<String, String> properties)
throws NoSuchModelException, ModelVersionAliasesAlreadyExistException {
ModelVersionInfo linkModelRequest = new ModelVersionInfo(uri, comment, properties, aliases);
eventBus.dispatchEvent(
new LinkModelVersionPreEvent(PrincipalUtils.getCurrentUserName(), ident, linkModelRequest));
String user = PrincipalUtils.getCurrentUserName();

eventBus.dispatchEvent(new LinkModelVersionPreEvent(user, ident, linkModelRequest));
try {
dispatcher.linkModelVersion(ident, uri, aliases, comment, properties);
// TODO: ModelEvent
} catch (Exception e) {
// TODO: failureEvent
eventBus.dispatchEvent(new LinkModelVersionFailureEvent(user, ident, e, linkModelRequest));
throw e;
}
}
Expand All @@ -178,13 +192,14 @@ public void linkModelVersion(
@Override
public ModelVersion getModelVersion(NameIdentifier ident, int version)
throws NoSuchModelVersionException {
eventBus.dispatchEvent(
new GetModelVersionPreEvent(PrincipalUtils.getCurrentUserName(), ident, null, version));
String user = PrincipalUtils.getCurrentUserName();

eventBus.dispatchEvent(new GetModelVersionPreEvent(user, ident, null, version));
try {
// TODO: ModelEvent
return dispatcher.getModelVersion(ident, version);
} catch (Exception e) {
// TODO: failureEvent
eventBus.dispatchEvent(new GetModelVersionFailureEvent(user, ident, e, null, version));
throw e;
}
}
Expand All @@ -193,59 +208,63 @@ public ModelVersion getModelVersion(NameIdentifier ident, int version)
@Override
public ModelVersion getModelVersion(NameIdentifier ident, String alias)
throws NoSuchModelVersionException {
eventBus.dispatchEvent(
new GetModelVersionPreEvent(PrincipalUtils.getCurrentUserName(), ident, alias, null));
String user = PrincipalUtils.getCurrentUserName();

eventBus.dispatchEvent(new GetModelVersionPreEvent(user, ident, alias, null));
try {
ModelVersion modelVersion = dispatcher.getModelVersion(ident, alias);
// TODO: ModelEvent
return modelVersion;
} catch (Exception e) {
// TODO: failureEvent
eventBus.dispatchEvent(new GetModelVersionFailureEvent(user, ident, e, alias, null));
throw e;
}
}

/** {@inheritDoc} */
@Override
public boolean deleteModelVersion(NameIdentifier ident, int version) {
eventBus.dispatchEvent(
new DeleteModelVersionPreEvent(PrincipalUtils.getCurrentUserName(), ident, null, version));
String user = PrincipalUtils.getCurrentUserName();

eventBus.dispatchEvent(new DeleteModelVersionPreEvent(user, ident, null, version));
try {
boolean isExists = dispatcher.deleteModelVersion(ident, version);
// TODO: ModelEvent
return isExists;
} catch (Exception e) {
// TODO: failureEvent
eventBus.dispatchEvent(new DeleteModelVersionFailureEvent(user, ident, e, null, version));
throw e;
}
}

/** {@inheritDoc} */
@Override
public boolean deleteModelVersion(NameIdentifier ident, String alias) {
eventBus.dispatchEvent(
new DeleteModelVersionPreEvent(PrincipalUtils.getCurrentUserName(), ident, alias, null));
String user = PrincipalUtils.getCurrentUserName();

eventBus.dispatchEvent(new DeleteModelVersionPreEvent(user, ident, alias, null));
try {
boolean isExists = dispatcher.deleteModelVersion(ident, alias);
// TODO: ModelEvent
return isExists;
} catch (Exception e) {
// TODO: failureEvent
eventBus.dispatchEvent(new DeleteModelVersionFailureEvent(user, ident, e, alias, null));
throw e;
}
}

/** {@inheritDoc} */
@Override
public int[] listModelVersions(NameIdentifier ident) throws NoSuchModelException {
eventBus.dispatchEvent(
new ListModelVersionPreEvent(PrincipalUtils.getCurrentUserName(), ident));
String user = PrincipalUtils.getCurrentUserName();

eventBus.dispatchEvent(new ListModelVersionPreEvent(user, ident));
try {
int[] versions = dispatcher.listModelVersions(ident);
// TODO: ModelEvent
return versions;
} catch (Exception e) {
// TODO: failureEvent
eventBus.dispatchEvent(new ListModelVersionFailureEvent(user, ident, e));
throw e;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

/**
* Represents an event that is generated when an attempt to drop a model from the schema fails due
* to an exception.
*/
@DeveloperApi
public class DeleteModelFailureEvent extends ModelFailureEvent {
/**
* Construct a new {@link DeleteModelFailureEvent} instance, capturing detailed information about
* the failed attempt to drop a model.
*
* @param user The user who initiated the drop model operation.
* @param identifier The identifier of the model that the operation attempted to drop.
* @param exception The exception that was thrown during the drop model operation, offering
* insights into what went wrong and why the operation failed.
*/
public DeleteModelFailureEvent(String user, NameIdentifier identifier, Exception exception) {
super(user, identifier, exception);
}

/**
* Returns the type of operation.
*
* @return the operation type.
*/
@Override
public OperationType operationType() {
return OperationType.DELETE_MODEL;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* 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 java.util.Optional;
import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.annotation.DeveloperApi;

/**
* Represents an event that is generated when an attempt to delete a model version from a model
* fails due to an exception.
*/
@DeveloperApi
public class DeleteModelVersionFailureEvent extends ModelFailureEvent {
private final Optional<String> alias;
private final Optional<Integer> version;

/**
* Constructs a new instance of {@link DeleteModelVersionFailureEvent} instance, capturing
* detailed information about the failed attempt to delete a model version. only one of alias or
* version are valid.
*
* @param user The user who initiated the delete model version operation.
* @param identifier The identifier of the model that the operation attempted to delete a version
* from.
* @param exception The exception that was thrown during the delete model version operation,
* offering insights into what went wrong and why the operation failed.
* @param alias The alias of the model version to be deleted.
* @param version The version of the model version to be deleted.
*/
public DeleteModelVersionFailureEvent(
String user, NameIdentifier identifier, Exception exception, String alias, Integer version) {
super(user, identifier, exception);

this.alias = Optional.ofNullable(alias);
this.version = Optional.ofNullable(version);
}

/**
* Returns the alias of the model version to be deleted.
*
* @return A {@link Optional} instance containing the alias if it was provided, or an empty {@link
* Optional} otherwise.
*/
public Optional<String> alias() {
return alias;
}

/**
* Returns the version of the model version to be deleted.
*
* @return A {@link Optional} instance containing the version if it was provided, or an empty
* {@link Optional} otherwise.
*/
public Optional<Integer> version() {
return version;
}

/**
* Returns the type of operation.
*
* @return the operation type.
*/
@Override
public OperationType operationType() {
return OperationType.DELETE_MODEL_VERSION;
}
}
Loading