forked from kubeflow/model-registry
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement MR service layer (kubeflow#68)
* Add service layer Co-authored-by: Matteo Mortari <[email protected]> * Refactor service layer api Co-authored-by: Matteo Mortari <[email protected]> * Adapt to refactored openapi models Co-authored-by: Matteo Mortari <[email protected]> * Add ModelVersion API core impl and test update * Refactor core layer testing * Improve core testing * Cleanup comments * check put parent context error * cleanup readme * Correct terminology in tests * Using more explicit test-nocache on Makefile * Refactor core layer to make use of *List from openapi Co-authored-by: Andrea Lamparelli <[email protected]> --------- Co-authored-by: Matteo Mortari <[email protected]>
- Loading branch information
Showing
12 changed files
with
1,445 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package core | ||
|
||
import "github.com/opendatahub-io/model-registry/internal/model/openapi" | ||
|
||
// Note: for convention, here we are keeping here adherence to the mlmd side | ||
type BaseResourceId int64 | ||
|
||
type ListOptions struct { | ||
PageSize *int32 | ||
OrderBy *string | ||
SortOrder *string | ||
NextPageToken *string | ||
} | ||
|
||
type ModelRegistryApi interface { | ||
// REGISTERED MODEL | ||
|
||
// UpsertRegisteredModel create or update a registered model, the behavior follows the same | ||
// approach used by MLMD gRPC api. If Id is provided update the entity otherwise create a new one. | ||
UpsertRegisteredModel(registeredModel *openapi.RegisteredModel) (*openapi.RegisteredModel, error) | ||
|
||
GetRegisteredModelById(id *BaseResourceId) (*openapi.RegisteredModel, error) | ||
GetRegisteredModelByParams(name *string, externalId *string) (*openapi.RegisteredModel, error) | ||
GetRegisteredModels(listOptions ListOptions) (*openapi.RegisteredModelList, error) | ||
|
||
// MODEL VERSION | ||
|
||
// Create a new Model Version | ||
// or update a Model Version associated to a specific RegisteredModel identified by registeredModelId parameter | ||
UpsertModelVersion(modelVersion *openapi.ModelVersion, registeredModelId *BaseResourceId) (*openapi.ModelVersion, error) | ||
|
||
GetModelVersionById(id *BaseResourceId) (*openapi.ModelVersion, error) | ||
GetModelVersionByParams(name *string, externalId *string) (*openapi.ModelVersion, error) | ||
GetModelVersions(listOptions ListOptions, registeredModelId *BaseResourceId) (*openapi.ModelVersionList, error) | ||
|
||
// MODEL ARTIFACT | ||
|
||
// Create or update a Model Artifact associated to a specific ModelVersion | ||
// identified by ModelArtifact.ModelVersionId | ||
UpsertModelArtifact(modelArtifact *openapi.ModelArtifact, modelVersionId *BaseResourceId) (*openapi.ModelArtifact, error) | ||
|
||
GetModelArtifactById(id *BaseResourceId) (*openapi.ModelArtifact, error) | ||
GetModelArtifactByParams(name *string, externalId *string) (*openapi.ModelArtifact, error) | ||
GetModelArtifacts(listOptions ListOptions, modelVersionId *BaseResourceId) (*openapi.ModelArtifactList, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package core | ||
|
||
import ( | ||
"github.com/opendatahub-io/model-registry/internal/ml_metadata/proto" | ||
) | ||
|
||
func zeroIfNil[T any](input *T) T { | ||
if input != nil { | ||
return *input | ||
} | ||
return *new(T) | ||
} | ||
|
||
func BuildListOperationOptions(listOptions ListOptions) (*proto.ListOperationOptions, error) { | ||
|
||
result := proto.ListOperationOptions{} | ||
if listOptions.PageSize != nil { | ||
result.MaxResultSize = listOptions.PageSize | ||
} | ||
if listOptions.NextPageToken != nil { | ||
result.NextPageToken = listOptions.NextPageToken | ||
} | ||
if listOptions.OrderBy != nil { | ||
so := listOptions.SortOrder | ||
|
||
// default is DESC | ||
isAsc := false | ||
if so != nil && *so == "ASC" { | ||
isAsc = true | ||
} | ||
|
||
var orderByField proto.ListOperationOptions_OrderByField_Field | ||
if val, ok := proto.ListOperationOptions_OrderByField_Field_value[*listOptions.OrderBy]; ok { | ||
orderByField = proto.ListOperationOptions_OrderByField_Field(val) | ||
} | ||
|
||
result.OrderByField = &proto.ListOperationOptions_OrderByField{ | ||
Field: &orderByField, | ||
IsAsc: &isAsc, | ||
} | ||
} | ||
return &result, nil | ||
} |
Oops, something went wrong.