Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion models/meshmodel/core/v1alpha1/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ func CreateComponent(db *database.Handler, c ComponentDefinition) (uuid.UUID, er
if model.ID == tempModelID || err == gorm.ErrRecordNotFound { //The model is already not present and needs to be inserted
model = c.Model
model.ID = modelID
err = db.Create(&model).Error
mdb := model.GetModelDB()
err = db.Create(&mdb).Error
if err != nil {
modelCreationLock.Unlock()
return uuid.UUID{}, err
Expand Down
35 changes: 35 additions & 0 deletions models/meshmodel/core/v1alpha1/models.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v1alpha1

import (
"encoding/json"
"sync"

"github.com/google/uuid"
Expand All @@ -21,12 +22,22 @@ type ModelFilter struct {

// swagger:response Model
type Model struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Revolyssup, educate me: what's the difference between Model and ModelDB?

ID uuid.UUID `json:"-"`
Name string `json:"name"`
Version string `json:"version"`
DisplayName string `json:"modelDisplayName" gorm:"modelDisplayName"`
Category string `json:"category"`
SubCategory string `json:"subCategory" gorm:"subCategory"`
Metadata map[string]interface{} `json:"modelMetadata" yaml:"modelMetadata"`
}
type ModelDB struct {
ID uuid.UUID `json:"-"`
Name string `json:"name"`
Version string `json:"version"`
DisplayName string `json:"modelDisplayName" gorm:"modelDisplayName"`
Category string `json:"category"`
SubCategory string `json:"subCategory" gorm:"subCategory"`
Metadata []byte `json:"modelMetadata" gorm:"modelMetadata"`
}

// Create the filter from map[string]interface{}
Expand All @@ -36,3 +47,27 @@ func (cf *ModelFilter) Create(m map[string]interface{}) {
}
cf.Name = m["name"].(string)
}
func (cmd *ModelDB) GetModel() (c Model) {
cmd.ID = c.ID
cmd.Category = c.Category
cmd.DisplayName = c.DisplayName
cmd.Name = c.Name
cmd.SubCategory = c.SubCategory
cmd.Version = c.Version
cmd.Metadata, _ = json.Marshal(c.Metadata)
if c.Metadata == nil {
c.Metadata = make(map[string]interface{})
}
_ = json.Unmarshal(cmd.Metadata, &c.Metadata)
return
}
func (c *Model) GetModelDB() (cmd ModelDB) {
cmd.ID = c.ID
cmd.Category = c.Category
cmd.DisplayName = c.DisplayName
cmd.Name = c.Name
cmd.SubCategory = c.SubCategory
cmd.Version = c.Version
cmd.Metadata, _ = json.Marshal(c.Metadata)
return
}
3 changes: 2 additions & 1 deletion models/meshmodel/core/v1alpha1/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ func CreatePolicy(db *database.Handler, p PolicyDefinition) (uuid.UUID, error) {
if model.ID == tempModelID || err == gorm.ErrRecordNotFound {
model = p.Model
model.ID = modelID
err = db.Create(&model).Error
mdb := model.GetModelDB()
err = db.Create(&mdb).Error
if err != nil {
modelCreationLock.Unlock()
return uuid.UUID{}, err
Expand Down
3 changes: 2 additions & 1 deletion models/meshmodel/core/v1alpha1/relationship.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ func CreateRelationship(db *database.Handler, r RelationshipDefinition) (uuid.UU
if model.ID == tempModelID || err == gorm.ErrRecordNotFound { //The model is already not present and needs to be inserted
model = r.Model
model.ID = modelID
err = db.Create(&model).Error
mdb := model.GetModelDB()
err = db.Create(&mdb).Error
if err != nil {
modelCreationLock.Unlock()
return uuid.UUID{}, err
Expand Down
8 changes: 6 additions & 2 deletions models/meshmodel/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ func (rm *RegistryManager) GetEntities(f types.Filter) []Entity {
}
}
func (rm *RegistryManager) GetModels(f types.Filter) []v1alpha1.Model {
var mod []v1alpha1.Model
var mod []v1alpha1.ModelDB
var m []v1alpha1.Model
finder := rm.db.Model(&mod)
if mf, ok := f.(*v1alpha1.ModelFilter); ok {
if mf.Greedy {
Expand Down Expand Up @@ -223,7 +224,10 @@ func (rm *RegistryManager) GetModels(f types.Filter) []v1alpha1.Model {
}
}
_ = finder.Find(&mod).Error
return mod
for _, modelDB := range mod {
m = append(m, modelDB.GetModel())
}
return m
}
func (rm *RegistryManager) GetRegistrant(e Entity) Host {
eID := e.GetID()
Expand Down