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

Add methods for lifecycle management of database instance #226

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
Prev Previous commit
Next Next commit
Add Database compliant Meshmodel structs
Signed-off-by: revolyssup <[email protected]>
Revolyssup committed Oct 28, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit b217bf4fb0e273958d0bbdc8a74140507b43d608
23 changes: 17 additions & 6 deletions models/meshmodel/core/v1alpha1/component.go
Original file line number Diff line number Diff line change
@@ -3,26 +3,37 @@ package v1alpha1
const ComponentDefinitionKindKey = "ComponentDefinition"

type TypeMeta struct {
Kind string `json:"kind,omitempty"`
APIVersion string `json:"apiVersion,omitempty"`
Kind string `json:"kind,omitempty" gorm:"kind"`
APIVersion string `json:"apiVersion,omitempty" gorm:"apiVersion"`
}

// use NewComponent function for instantiating
type Component struct {
TypeMeta
ComponentSpec
Metadata map[string]interface{} `json:"metadata,omitempty"`
TypeMeta `gorm:"embedded"`
ComponentSpec `gorm:"embedded"`
Metadata map[string]interface{} `json:"metadata,omitempty" gorm:"type:JSONB"`
// for backward compatibility
Spec string `json:"spec,omitempty"`
}

type ComponentSpec struct {
Schematic map[string]interface{} `json:"schematic,omitempty"`
Schematic map[string]interface{} `json:"schematic,omitempty" gorm:"type:JSONB"`
}

type ComponentCapability struct {
Component
capability
}
type capability struct {
ID string `json:"id,omitempty"`
// Host is the address of the service registering the capability
Host string `json:"host,omitempty"`
}

func NewComponent() Component {
comp := Component{}
comp.APIVersion = "core.meshery.io/v1alpha1"
comp.Kind = ComponentDefinitionKindKey
comp.Metadata = make(map[string]interface{}, 1)
return comp
}
51 changes: 51 additions & 0 deletions models/meshmodel/core/v1alpha1/component_capabilities_db.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package v1alpha1

import (
"encoding/json"

"github.com/google/uuid"
)

// This file consists of methods and structs that database(gorm) will use to interact with meshmodel components
type ComponentDB struct {
TypeMeta
ComponentSpecDB
Metadata []byte `json:"metadata"`
// for backward compatibility
Spec string `json:"spec,omitempty"`
}

type ComponentSpecDB struct {
Schematic []byte `json:"schematic,omitempty"`
}

type ComponentCapabilityDB struct {
ID uuid.UUID `json:"id,omitempty"`
ComponentDB
capability
}
type capabilityDB struct {
// Host is the address of the service registering the capability
Host string `json:"host,omitempty"`
}

func ComponentCapabilityFromCCDB(cdb ComponentCapabilityDB) (c ComponentCapability) {
c.capability = cdb.capability
c.TypeMeta = cdb.TypeMeta
c.Spec = cdb.Spec
m := make(map[string]interface{})
json.Unmarshal(cdb.Metadata, &m)
c.Metadata = m
schematic := make(map[string]interface{})
json.Unmarshal(cdb.Schematic, &schematic)
c.Schematic = schematic
return
}
func ComponentCapabilityDBFromCC(c ComponentCapability) (cdb ComponentCapabilityDB) {
cdb.capability = c.capability
cdb.TypeMeta = c.TypeMeta
cdb.Spec = c.Spec
cdb.Metadata, _ = json.Marshal(c.Metadata)
cdb.Schematic, _ = json.Marshal(c.Schematic)
return
}
1 change: 1 addition & 0 deletions utils/component/generator_test.go
Original file line number Diff line number Diff line change
@@ -130,6 +130,7 @@ func getNewComponent(spec string, name string) v1alpha1.Component {
meta := map[string]interface{}{
ComponentMetaNameKey: name,
}

comp.Metadata = meta
return comp
}