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.
add catalog pkg to load catalog sources and a simple yaml catalog imp…
…lementation scaffold Signed-off-by: Dhiraj Bokde <[email protected]>
- Loading branch information
Showing
4 changed files
with
151 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package catalog | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/kubeflow/model-registry/pkg/openapi" | ||
yaml3 "gopkg.in/yaml.v3" | ||
"log" | ||
"os" | ||
) | ||
|
||
// ModelCatalogApi is implemented by catalog types, e.g. YamlCatalog | ||
type ModelCatalogApi interface { | ||
GetCatalogModel(ctx context.Context, modelId string) (openapi.CatalogModel, error) | ||
GetCatalogModelVersion(ctx context.Context, modelId string, versionId string) (openapi.CatalogModelVersion, error) | ||
GetCatalogModelVersions(ctx context.Context, modelId string, nameParam string, externalIdParam string, pageSizeParam string, orderByParam openapi.OrderByField, sortOrderParam openapi.SortOrder, offsetParam string) (openapi.CatalogModelVersionList, error) | ||
GetCatalogModels(ctx context.Context, nameParam string, externalIdParam string, pageSizeParam string, orderByParam openapi.OrderByField, sortOrderParam openapi.SortOrder, offsetParam string) (openapi.CatalogModelList, error) | ||
GetCatalogSource() (openapi.CatalogSource, error) | ||
} | ||
|
||
type CatalogSource struct { | ||
openapi.CatalogSource | ||
|
||
// Catalog type to use, must match one of the registered types | ||
Type string `json:"type"` | ||
|
||
// private properties used for configuring the catalog connection based on catalog implementation | ||
PrivateProperties *map[string]openapi.MetadataValue `json:"privateProperties,omitempty"` | ||
} | ||
|
||
type CatalogsConfig struct { | ||
Catalogs []CatalogSource `json:"catalogs"` | ||
} | ||
|
||
type CatalogTypeRegisterFunc func (source *CatalogSource) ModelCatalogApi | ||
|
||
var catalogTypes = make(map[string]CatalogTypeRegisterFunc, 0) | ||
|
||
func RegisterCatalogType(catalogType string, callback CatalogTypeRegisterFunc) { | ||
catalogTypes[catalogType] = callback | ||
} | ||
|
||
func LoadCatalogSources(catalogsPath string) (map[string]ModelCatalogApi, error) { | ||
config := CatalogsConfig{} | ||
f, err := os.Open(catalogsPath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer f.Close() | ||
|
||
decoder := yaml3.NewDecoder(f) | ||
if err := decoder.Decode(&config); err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
catalogs := make(map[string]ModelCatalogApi) | ||
for _, catalog := range config.Catalogs { | ||
catalogType := catalog.Type | ||
registerFunc, ok := catalogTypes[catalogType] | ||
if !ok { | ||
return nil, fmt.Errorf("catalog type %s not registered", catalogType) | ||
} | ||
id := catalog.GetId() | ||
catalogs[id] = registerFunc(&catalog) | ||
} | ||
return catalogs, nil | ||
} |
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,71 @@ | ||
package catalog | ||
|
||
import ( | ||
"context" | ||
"github.com/kubeflow/model-registry/pkg/openapi" | ||
) | ||
|
||
type YamlCatalog struct { | ||
Models []struct { | ||
Name string `yaml:"name"` | ||
Provider string `yaml:"provider"` | ||
Description string `yaml:"description"` | ||
ReadmeLink string `yaml:"readmeLink"` | ||
Language []string `yaml:"language"` | ||
License string `yaml:"license"` | ||
LicenseLink string `yaml:"licenseLink"` | ||
LibraryName string `yaml:"libraryName"` | ||
Tags []string `yaml:"tags"` | ||
Tasks []string `yaml:"tasks"` | ||
CreateTimeSinceEpoch int64 `yaml:"createTimeSinceEpoch"` | ||
LastUpdateTimeSinceEpoch int64 `yaml:"lastUpdateTimeSinceEpoch"` | ||
BaseModel []struct { | ||
Catalog string `yaml:"catalog"` | ||
Repository string `yaml:"repository"` | ||
Model string `yaml:"model"` | ||
} `yaml:"baseModel,omitempty"` | ||
} `yaml:"models"` | ||
} | ||
|
||
type yamlCatalogImpl struct { | ||
contents *YamlCatalog | ||
source *CatalogSource | ||
} | ||
|
||
func (y yamlCatalogImpl) GetCatalogModel(ctx context.Context, modelId string) (openapi.CatalogModel, error) { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (y yamlCatalogImpl) GetCatalogModelVersion(ctx context.Context, modelId string, versionId string) (openapi.CatalogModelVersion, error) { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (y yamlCatalogImpl) GetCatalogModelVersions(ctx context.Context, modelId string, nameParam string, externalIdParam string, pageSizeParam string, orderByParam openapi.OrderByField, sortOrderParam openapi.SortOrder, offsetParam string) (openapi.CatalogModelVersionList, error) { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (y yamlCatalogImpl) GetCatalogModels(ctx context.Context, nameParam string, externalIdParam string, pageSizeParam string, orderByParam openapi.OrderByField, sortOrderParam openapi.SortOrder, offsetParam string) (openapi.CatalogModelList, error) { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (y yamlCatalogImpl) GetCatalogSource() (openapi.CatalogSource, error) { | ||
return y.source.CatalogSource, nil | ||
} | ||
|
||
// TODO start background thread to watch file | ||
|
||
var _ ModelCatalogApi = &yamlCatalogImpl{} | ||
|
||
func NewYamlCatalog(source *CatalogSource) ModelCatalogApi { | ||
// TODO read file contents from config | ||
var contents YamlCatalog | ||
return &yamlCatalogImpl{source: source, contents: &contents} | ||
} | ||
|
||
func init() { | ||
RegisterCatalogType("yaml", NewYamlCatalog) | ||
} |
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