Skip to content

Commit

Permalink
Merge pull request #456 from Yashsharma1911/yash/addIgnorePropertyFor…
Browse files Browse the repository at this point in the history
…Entity

Add status property to meshmodels
  • Loading branch information
Yashsharma1911 authored Feb 19, 2024
2 parents 75d1c5b + 9abf218 commit 3658ddb
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
27 changes: 20 additions & 7 deletions models/meshmodel/core/v1alpha1/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type ModelFilter struct {
// When these are set to true, we also retrieve components/relationships associated with the model.
Components bool
Relationships bool
Status string
}

// Create the filter from map[string]interface{}
Expand All @@ -40,12 +41,15 @@ func (cf *ModelFilter) Create(m map[string]interface{}) {
cf.Name = m["name"].(string)
}

type ModelStatus string

// swagger:response Model
type Model struct {
ID uuid.UUID `json:"id,omitempty" yaml:"-"`
Name string `json:"name"`
Version string `json:"version"`
DisplayName string `json:"displayName" gorm:"modelDisplayName"`
Status ModelStatus `json:"status" gorm:"status"`
HostName string `json:"hostname,omitempty"`
HostID uuid.UUID `json:"hostID,omitempty"`
DisplayHostName string `json:"displayhostname,omitempty"`
Expand All @@ -56,13 +60,14 @@ type Model struct {
}

type ModelDB struct {
ID uuid.UUID `json:"id"`
CategoryID uuid.UUID `json:"-" gorm:"categoryID"`
Name string `json:"modelName" gorm:"modelName"`
Version string `json:"version"`
DisplayName string `json:"modelDisplayName" gorm:"modelDisplayName"`
SubCategory string `json:"subCategory" gorm:"subCategory"`
Metadata []byte `json:"modelMetadata" gorm:"modelMetadata"`
ID uuid.UUID `json:"id"`
CategoryID uuid.UUID `json:"-" gorm:"categoryID"`
Name string `json:"modelName" gorm:"modelName"`
Version string `json:"version"`
DisplayName string `json:"modelDisplayName" gorm:"modelDisplayName"`
SubCategory string `json:"subCategory" gorm:"subCategory"`
Metadata []byte `json:"modelMetadata" gorm:"modelMetadata"`
Status ModelStatus `json:"status" gorm:"status"`
}

func (m Model) Type() types.CapabilityType {
Expand Down Expand Up @@ -96,6 +101,7 @@ func CreateModel(db *database.Handler, cmodel Model) (uuid.UUID, error) {
cmodel.ID = modelID
mdb := cmodel.GetModelDB()
mdb.CategoryID = id
mdb.Status = "registered"
err = db.Create(&mdb).Error
if err != nil {
return uuid.UUID{}, err
Expand All @@ -104,10 +110,16 @@ func CreateModel(db *database.Handler, cmodel Model) (uuid.UUID, error) {
}
return model.ID, nil
}

func UpdateModelsStatus(db *database.Handler, modelID uuid.UUID, status string) error {
return db.Model(&ModelDB{}).Where("id = ?", modelID).Update("status", status).Error
}

func (cmd *ModelDB) GetModel(cat Category) (c Model) {
c.ID = cmd.ID
c.Category = cat
c.DisplayName = cmd.DisplayName
c.Status = cmd.Status
c.Name = cmd.Name
c.Version = cmd.Version
c.Components = make([]ComponentDefinitionDB, 0)
Expand All @@ -118,6 +130,7 @@ func (cmd *ModelDB) GetModel(cat Category) (c Model) {
func (c *Model) GetModelDB() (cmd ModelDB) {
cmd.ID = c.ID
cmd.DisplayName = c.DisplayName
cmd.Status = c.Status
cmd.Name = c.Name
cmd.Version = c.Version
cmd.Metadata, _ = json.Marshal(c.Metadata)
Expand Down
23 changes: 23 additions & 0 deletions models/meshmodel/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,26 @@ func (rm *RegistryManager) RegisterEntity(h Host, en Entity) error {
}
}

// UpdateEntityIgnoreStatus updates the ignore status of an entity based on the provided parameters.
// By default during models generation ignore is set to false
func (rm *RegistryManager) UpdateEntityStatus(ID string, status string, entity string) error {
// Convert string UUID to google UUID
entityID, err := uuid.Parse(ID)
if err != nil {
return err
}
switch entity {
case "models":
err := v1alpha1.UpdateModelsStatus(rm.db, entityID, status)
if err != nil {
return err
}
return nil
default:
return nil
}
}

func (rm *RegistryManager) GetRegistrants(f *v1alpha1.HostFilter) ([]v1alpha1.MeshModelHostsWithEntitySummary, int64, error) {
var result []v1alpha1.MesheryHostSummaryDB
var totalcount int64
Expand Down Expand Up @@ -373,6 +393,9 @@ func (rm *RegistryManager) GetModels(db *database.Handler, f types.Filter) ([]v1
if mf.Offset != 0 {
finder = finder.Offset(mf.Offset)
}
if mf.Status != "" {
finder = finder.Where("model_dbs.status = ?", mf.Status)
}
includeComponents = mf.Components
includeRelationships = mf.Relationships
}
Expand Down

0 comments on commit 3658ddb

Please sign in to comment.