Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update fields to retrieve HostID and name #332

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions models/meshmodel/core/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const (
ComponentDefinition CapabilityType = "component"
PolicyDefinition CapabilityType = "policy"
RelationshipDefinition CapabilityType = "relationship"
Model CapabilityType = "model"
)

// Each entity will have it's own Filter implementation via which it exposes the nobs and dials to fetch entities
Expand Down
17 changes: 10 additions & 7 deletions models/meshmodel/core/v1alpha1/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ const (
type ComponentDefinition struct {
ID uuid.UUID `json:"-"`
TypeMeta
DisplayName string `json:"displayName" gorm:"displayName"`
Format ComponentFormat `json:"format" yaml:"format"`
Metadata map[string]interface{} `json:"metadata" yaml:"metadata"`
Model Model `json:"model"`
Schema string `json:"schema,omitempty" yaml:"schema"`
CreatedAt time.Time `json:"-"`
UpdatedAt time.Time `json:"-"`
DisplayName string `json:"displayName" gorm:"displayName"`
Format ComponentFormat `json:"format" yaml:"format"`
HostName string `json:"hostname"`
HostID uuid.UUID `json:"hostID"`
DisplayHostName string `json:"displayhostname"`
Metadata map[string]interface{} `json:"metadata" yaml:"metadata"`
Model Model `json:"model"`
Schema string `json:"schema,omitempty" yaml:"schema"`
CreatedAt time.Time `json:"-"`
UpdatedAt time.Time `json:"-"`
}
type ComponentDefinitionDB struct {
ID uuid.UUID `json:"-"`
Expand Down
42 changes: 29 additions & 13 deletions models/meshmodel/core/v1alpha1/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/google/uuid"
"github.com/layer5io/meshkit/database"
"github.com/layer5io/meshkit/models/meshmodel/core/types"
"gorm.io/gorm"
)

Expand All @@ -33,21 +34,27 @@ func (cf *ModelFilter) Create(m map[string]interface{}) {

// swagger:response Model
type Model struct {
ID uuid.UUID `json:"-" yaml:"-"`
Name string `json:"name"`
Version string `json:"version"`
DisplayName string `json:"displayName" gorm:"modelDisplayName"`
Category Category `json:"category"`
Metadata map[string]interface{} `json:"metadata" yaml:"modelMetadata"`
ID uuid.UUID `json:"-" yaml:"-"`
Name string `json:"name"`
Version string `json:"version"`
DisplayName string `json:"displayName" gorm:"modelDisplayName"`
HostName string `json:"hostname"`
HostID uuid.UUID `json:"hostID"`
DisplayHostName string `json:"displayhostname"`
Category Category `json:"category"`
Metadata map[string]interface{} `json:"metadata" yaml:"modelMetadata"`
}
type ModelDB struct {
ID uuid.UUID `json:"-"`
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:"-"`
CategoryID uuid.UUID `json:"-" gorm:"categoryID"`
HostName string `json:"hostname"`
HostID uuid.UUID `json:"hostID"`
DisplayHostName string `json:"displayhostname"`
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"`
}

func CreateModel(db *database.Handler, cmodel Model) (uuid.UUID, error) {
Expand Down Expand Up @@ -85,6 +92,8 @@ func CreateModel(db *database.Handler, cmodel Model) (uuid.UUID, error) {
func (cmd *ModelDB) GetModel(cat Category) (c Model) {
c.ID = cmd.ID
c.Category = cat
c.HostName = cmd.HostName
c.HostID = cmd.HostID
c.DisplayName = cmd.DisplayName
c.Name = cmd.Name
c.Version = cmd.Version
Expand All @@ -99,3 +108,10 @@ func (c *Model) GetModelDB() (cmd ModelDB) {
cmd.Metadata, _ = json.Marshal(c.Metadata)
return
}

func (r Model) Type() types.CapabilityType {
return types.Model
}
func (r Model) GetID() uuid.UUID {
return r.ID
}
15 changes: 9 additions & 6 deletions models/meshmodel/core/v1alpha1/relationship.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ import (
type RelationshipDefinition struct {
ID uuid.UUID `json:"-"`
TypeMeta
Model Model `json:"model"`
Metadata map[string]interface{} `json:"metadata" yaml:"metadata"`
SubType string `json:"subType" yaml:"subType" gorm:"subType"`
Selectors map[string]interface{} `json:"selectors" yaml:"selectors"`
CreatedAt time.Time `json:"-"`
UpdatedAt time.Time `json:"-"`
Model Model `json:"model"`
HostName string `json:"hostname"`
HostID uuid.UUID `json:"hostID"`
DisplayHostName string `json:"displayhostname"`
Metadata map[string]interface{} `json:"metadata" yaml:"metadata"`
SubType string `json:"subType" yaml:"subType" gorm:"subType"`
Selectors map[string]interface{} `json:"selectors" yaml:"selectors"`
CreatedAt time.Time `json:"-"`
UpdatedAt time.Time `json:"-"`
}

type RelationshipDefinitionDB struct {
Expand Down
12 changes: 12 additions & 0 deletions models/meshmodel/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,13 @@ func (rm *RegistryManager) GetEntities(f types.Filter) ([]Entity, *int64, *int)
en = append(en, pol)
}
return en, nil, nil
case *v1alpha1.ModelFilter:
en := make([]Entity, 0)
models, count, _ := rm.GetModels(rm.db, filter)
for _, model := range models {
en = append(en, model)
}
return en, &count, nil
default:
return nil, nil, nil
}
Expand Down Expand Up @@ -243,6 +250,11 @@ func (rm *RegistryManager) GetModels(db *database.Handler, f types.Filter) ([]v1
fmt.Println(err.Error()) //for debugging
}
for _, modelDB := range modelWithCategoriess {
filter := &v1alpha1.ComponentFilter{}
entities, _, _ := rm.GetEntities(filter)
host := rm.GetRegistrant(entities[0])
modelDB.HostID = host.ID
modelDB.HostName = host.Hostname
m = append(m, modelDB.ModelDB.GetModel(modelDB.GetCategory(db)))
}
return m, count, countUniqueModels(modelWithCategoriess)
Expand Down
3 changes: 2 additions & 1 deletion schemas/configuration.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package schemas

import "embed"

//go:embed configuration
var Schemas embed.FS
var Schemas embed.FS