Skip to content

Commit

Permalink
Move DELETE /mlflow/registered-models/delete endpoint. (#89)
Browse files Browse the repository at this point in the history
Signed-off-by: Software Developer <7852635+dsuhinin@users.noreply.github.com>
  • Loading branch information
dsuhinin authored Nov 20, 2024
1 parent 7af6166 commit 0cf60de
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 1 deletion.
2 changes: 1 addition & 1 deletion magefiles/generate/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var ServiceInfoMap = map[string]ServiceGenerationInfo{
// "createRegisteredModel",
"renameRegisteredModel",
"updateRegisteredModel",
// "deleteRegisteredModel",
"deleteRegisteredModel",
// "getRegisteredModel",
// "searchRegisteredModels",
"getLatestVersions",
Expand Down
5 changes: 5 additions & 0 deletions mlflow_go/store/model_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from mlflow.entities.model_registry import ModelVersion, RegisteredModel
from mlflow.protos.model_registry_pb2 import (
DeleteRegisteredModel,
GetLatestVersions,
RenameRegisteredModel,
UpdateRegisteredModel,
Expand Down Expand Up @@ -55,6 +56,10 @@ def rename_registered_model(self, name, new_name):
)
return RegisteredModel.from_proto(response.registered_model)

def delete_registered_model(self, name):
request = DeleteRegisteredModel(name=name)
self.service.call_endpoint(get_lib().ModelRegistryServiceDeleteRegisteredModel, request)


def ModelRegistryStore(cls):
return type(cls.__name__, (_ModelRegistryStore, cls), {})
Expand Down
1 change: 1 addition & 0 deletions pkg/contract/service/model_registry.g.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions pkg/lib/model_registry.g.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions pkg/model_registry/service/model_versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,13 @@ func (m *ModelRegistryService) RenameRegisteredModel(
RegisteredModel: registeredModel.ToProto(),
}, nil
}

func (m *ModelRegistryService) DeleteRegisteredModel(
ctx context.Context, input *protos.DeleteRegisteredModel,
) (*protos.DeleteRegisteredModel_Response, *contract.Error) {
if err := m.store.DeleteRegisteredModel(ctx, input.GetName()); err != nil {
return nil, err
}

return &protos.DeleteRegisteredModel_Response{}, nil
}
57 changes: 57 additions & 0 deletions pkg/model_registry/store/sql/model_versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,60 @@ func (m *ModelRegistrySQLStore) RenameRegisteredModel(

return registeredModel, nil
}

func (m *ModelRegistrySQLStore) DeleteRegisteredModel(ctx context.Context, name string) *contract.Error {
registeredModel, err := m.GetRegisteredModelByName(ctx, name)
if err != nil {
return err
}

if err := m.db.WithContext(ctx).Transaction(func(transaction *gorm.DB) error {
if err := transaction.Where(
"name = ?", registeredModel.Name,
).Delete(
models.ModelVersionTag{},
).Error; err != nil {
return err
}

if err := transaction.Where(
"name = ?", registeredModel.Name,
).Delete(
models.ModelVersion{},
).Error; err != nil {
return err
}

if err := transaction.Where(
"name = ?", registeredModel.Name,
).Delete(
models.RegisteredModelTag{},
).Error; err != nil {
return err
}

if err := transaction.Where(
"name = ?", registeredModel.Name,
).Delete(
models.RegisteredModelAlias{},
).Error; err != nil {
return err
}

if err := transaction.Where(
"name = ?", registeredModel.Name,
).Delete(
models.RegisteredModel{},
).Error; err != nil {
return err
}

return nil
}); err != nil {
return contract.NewError(
protos.ErrorCode_INTERNAL_ERROR, fmt.Sprintf("error deleting registered model: %v", err),
)
}

return nil
}
1 change: 1 addition & 0 deletions pkg/model_registry/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ type ModelRegistryStore interface {
GetLatestVersions(ctx context.Context, name string, stages []string) ([]*protos.ModelVersion, *contract.Error)
UpdateRegisteredModel(ctx context.Context, name, description string) (*entities.RegisteredModel, *contract.Error)
RenameRegisteredModel(ctx context.Context, name, newName string) (*entities.RegisteredModel, *contract.Error)
DeleteRegisteredModel(ctx context.Context, name string) *contract.Error
}
11 changes: 11 additions & 0 deletions pkg/server/routes/model_registry.g.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0cf60de

Please sign in to comment.