From 1532120603119d8c1ffb5660c0edff18f92acdf5 Mon Sep 17 00:00:00 2001 From: Ashish Tiwari Date: Sun, 18 Dec 2022 15:02:08 +0530 Subject: [PATCH 1/2] Add functionality to get registrant in MeshModel Signed-off-by: Ashish Tiwari --- models/meshmodel/core/v1alpha1/component.go | 3 +++ models/meshmodel/registry.go | 10 ++++++++++ models/oam/core/v1alpha1/application_component.go | 2 ++ 3 files changed, 15 insertions(+) diff --git a/models/meshmodel/core/v1alpha1/component.go b/models/meshmodel/core/v1alpha1/component.go index 2a2f2493..38122deb 100644 --- a/models/meshmodel/core/v1alpha1/component.go +++ b/models/meshmodel/core/v1alpha1/component.go @@ -58,6 +58,9 @@ type Models struct { func (c ComponentDefinition) Type() types.CapabilityType { return types.ComponentDefinition } +func (c ComponentDefinition) GetID() uuid.UUID { + return c.ID +} var componentCreationLock sync.Mutex diff --git a/models/meshmodel/registry.go b/models/meshmodel/registry.go index 4109e4d0..8eef7ea8 100644 --- a/models/meshmodel/registry.go +++ b/models/meshmodel/registry.go @@ -49,6 +49,7 @@ func createHost(db *database.Handler, h Host) (uuid.UUID, error) { // ComponentDefinitions and PolicyDefinitions are examples of entities type Entity interface { Type() types.CapabilityType + GetID() uuid.UUID } // RegistryManager instance will expose methods for registry operations & sits between the database level operations and user facing API handlers. @@ -123,3 +124,12 @@ func (rm *RegistryManager) GetEntities(f types.Filter) []Entity { return nil } } + +func (rm *RegistryManager) GetRegistrant(e Entity) Host { + eID := e.GetID() + var reg Registry + _ = rm.db.Where("entity = ?", eID).Find(®).Error + var h Host + _ = rm.db.Where("id = ?", reg.RegistrantID).Find(&h).Error + return h +} diff --git a/models/oam/core/v1alpha1/application_component.go b/models/oam/core/v1alpha1/application_component.go index ccd8afc1..d9493744 100644 --- a/models/oam/core/v1alpha1/application_component.go +++ b/models/oam/core/v1alpha1/application_component.go @@ -16,6 +16,8 @@ type Component struct { type ComponentSpec struct { Type string `json:"type"` Version string `json:"version"` + APIVersion string `json:"apiVersion"` + Model string `json:"model"` Settings map[string]interface{} `json:"settings"` Parameters []ComponentParameter `json:"parameters"` } From 070f5cec46594fa89158384dec73ee819850102a Mon Sep 17 00:00:00 2001 From: Ashish Tiwari Date: Sun, 18 Dec 2022 15:29:46 +0530 Subject: [PATCH 2/2] Add GetID to RelationshipDefinition Signed-off-by: Ashish Tiwari --- models/meshmodel/core/v1alpha1/relationship.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/models/meshmodel/core/v1alpha1/relationship.go b/models/meshmodel/core/v1alpha1/relationship.go index cd41c89d..726e8823 100644 --- a/models/meshmodel/core/v1alpha1/relationship.go +++ b/models/meshmodel/core/v1alpha1/relationship.go @@ -78,6 +78,9 @@ func (rdb *RelationshipDefinitionDB) GetRelationshipDefinition() (r Relationship func (r RelationshipDefinition) Type() types.CapabilityType { return types.RelationshipDefinition } +func (r RelationshipDefinition) GetID() uuid.UUID { + return r.ID +} func CreateRelationship(db *database.Handler, r RelationshipDefinition) (uuid.UUID, error) { r.ID = uuid.New()