diff --git a/models/meshmodel/core/v1alpha1/component.go b/models/meshmodel/core/v1alpha1/component.go index d5403135..8daeb923 100644 --- a/models/meshmodel/core/v1alpha1/component.go +++ b/models/meshmodel/core/v1alpha1/component.go @@ -108,7 +108,6 @@ func GetMeshModelComponents(db *database.Handler, f ComponentFilter) (c []Compon Joins("JOIN model_dbs ON component_definition_dbs.model_id = model_dbs.id"). Joins("JOIN category_dbs ON model_dbs.category_id = category_dbs.id") // - if f.Greedy { if f.Name != "" && f.DisplayName != "" { finder = finder.Where("component_definition_dbs.kind LIKE ? OR display_name LIKE ?", "%"+f.Name+"%", f.DisplayName+"%") @@ -128,7 +127,7 @@ func GetMeshModelComponents(db *database.Handler, f ComponentFilter) (c []Compon if f.ModelName != "" && f.ModelName != "all" { finder = finder.Where("model_dbs.name = ?", f.ModelName) } - + if f.Annotations == "true" { finder = finder.Where("component_definition_dbs.metadata->>'isAnnotation' = true") } else if f.Annotations == "false" { @@ -188,7 +187,7 @@ type ComponentFilter struct { OrderOn string Limit int //If 0 or unspecified then all records are returned and limit is not used Offset int - Annotations string + Annotations string //When this query parameter is "true", only components with the "isAnnotation" property set to true are returned. When this query parameter is "false", all components except those considered to be annotation components are returned. Any other value of the query parameter results in both annotations as well as non-annotation models being returned. } // Create the filter from map[string]interface{} diff --git a/models/meshmodel/core/v1alpha1/models.go b/models/meshmodel/core/v1alpha1/models.go index a8d53afc..b9c92455 100644 --- a/models/meshmodel/core/v1alpha1/models.go +++ b/models/meshmodel/core/v1alpha1/models.go @@ -14,15 +14,16 @@ import ( var modelCreationLock sync.Mutex //Each component/relationship will perform a check and if the model already doesn't exist, it will create a model. This lock will make sure that there are no race conditions. type ModelFilter struct { Name string - Registrant string //name of the registrant for a given model + Registrant string //name of the registrant for a given model DisplayName string //If Name is already passed, avoid passing Display name unless greedy=true, else the filter will translate to an AND returning only the models where name and display name match exactly. Ignore, if this behavior is expected. Greedy bool //when set to true - instead of an exact match, name will be prefix matched. Also an OR will be performed of name and display_name Version string Category string OrderOn string Sort string //asc or desc. Default behavior is asc - Limit int //If 0 or unspecified then all records are returned and limit is not used + Limit int //If 0 or unspecified then all records are returned and limit is not used Offset int + Annotations string //When this query parameter is "true", only models with the "isAnnotation" property set to true are returned. When this query parameter is "false", all models except those considered to be annotation models are returned. Any other value of the query parameter results in both annoations as well as non-annotation models being returned. } // Create the filter from map[string]interface{} diff --git a/models/meshmodel/registry/registry.go b/models/meshmodel/registry/registry.go index cbad3ca8..9be106d5 100644 --- a/models/meshmodel/registry/registry.go +++ b/models/meshmodel/registry/registry.go @@ -334,6 +334,11 @@ func (rm *RegistryManager) GetModels(db *database.Handler, f types.Filter) ([]v1 finder = finder.Where("model_dbs.display_name = ?", mf.DisplayName) } } + if mf.Annotations == "true" { + finder = finder.Where("model_dbs.metadata->>'isAnnotation' = true") + } else if mf.Annotations == "false" { + finder = finder.Where("model_dbs.metadata->>'isAnnotation' = false") + } if mf.Version != "" { finder = finder.Where("model_dbs.version = ?", mf.Version) } @@ -343,6 +348,11 @@ func (rm *RegistryManager) GetModels(db *database.Handler, f types.Filter) ([]v1 if mf.Registrant != "" { finder = finder.Where("hosts.hostname = ?", mf.Registrant) } + if mf.Annotations == "true" { + finder = finder.Where("model_dbs.metadata->>'isAnnotation' = true") + } else if mf.Annotations == "false" { + finder = finder.Where("model_dbs.metadata->>'isAnnotation' = false") + } if mf.OrderOn != "" { if mf.Sort == "desc" { finder = finder.Order(clause.OrderByColumn{Column: clause.Column{Name: mf.OrderOn}, Desc: true}) diff --git a/utils/manifests/getComponents.go b/utils/manifests/getComponents.go index b9fb1bdf..9ae8e479 100644 --- a/utils/manifests/getComponents.go +++ b/utils/manifests/getComponents.go @@ -12,7 +12,6 @@ import ( k8s "github.com/layer5io/meshkit/utils/kubernetes" ) - func GetFromManifest(ctx context.Context, url string, resource int, cfg Config) (*Component, error) { manifest, err := utils.ReadFileSource(url) if err != nil { diff --git a/utils/utils.go b/utils/utils.go index d8aa3599..0ae44d41 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -247,7 +247,6 @@ func Contains[G []K, K comparable](slice G, ele K) bool { return false } - func Cast[K any](val interface{}) (K, error) { assertedValue, ok := val.(K) if !ok { @@ -256,7 +255,7 @@ func Cast[K any](val interface{}) (K, error) { return assertedValue, nil } -func MarshalAndUnmarshal[fromType any, toType any](val fromType) (unmarshalledvalue toType, err error){ +func MarshalAndUnmarshal[fromType any, toType any](val fromType) (unmarshalledvalue toType, err error) { data, err := Marshal(val) if err != nil { return