Skip to content

Commit

Permalink
Merge pull request #131 from gr455/meshmodel-components
Browse files Browse the repository at this point in the history
Add meshmodel component support
  • Loading branch information
Revolyssup authored Jan 2, 2023
2 parents 8b3a4c7 + 6506ed6 commit 93ece74
Show file tree
Hide file tree
Showing 115 changed files with 13,095 additions and 15 deletions.
63 changes: 60 additions & 3 deletions appmesh/oam/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,59 @@ import (
"fmt"
"os"
"path/filepath"
"strconv"
"strings"
"sync"

"github.com/layer5io/meshery-adapter-library/adapter"
"github.com/layer5io/meshery-app-mesh/internal/config"
"github.com/layer5io/meshkit/models/meshmodel/core/types"
)

var (
basePath, _ = os.Getwd()
// WorkloadPath contains the path to the workload schemas and definitions directory
WorkloadPath = filepath.Join(basePath, "templates", "oam", "workloads")
basePath, _ = os.Getwd()
WorkloadPath = filepath.Join(basePath, "templates", "oam", "workloads")
MeshmodelComponents = filepath.Join(basePath, "templates", "meshmodel", "components")
traitPath = filepath.Join(basePath, "templates", "oam", "traits")
// traitPath = filepath.Join(basePath, "templates", "oam", "traits")
pathSets = []schemaDefinitionPathSet{}
)

// AvailableVersions denote the component versions available statically
var AvailableVersions = map[string]bool{}
var availableVersionGlobalMutex sync.Mutex

type schemaDefinitionPathSet struct {
oamDefinitionPath string
jsonSchemaPath string
name string
}

type meshmodelDefinitionPathSet struct {
meshmodelDefinitionPath string
}

func RegisterMeshModelComponents(uuid, runtime, host, port string) error {
meshmodelRDP := []adapter.MeshModelRegistrantDefinitionPath{}
pathSets, err := loadMeshmodelComponents(MeshmodelComponents)
if err != nil {
return err
}
portint, _ := strconv.Atoi(port)
for _, pathSet := range pathSets {
meshmodelRDP = append(meshmodelRDP, adapter.MeshModelRegistrantDefinitionPath{
EntityDefintionPath: pathSet.meshmodelDefinitionPath,
Host: host,
Port: portint,
Type: types.ComponentDefinition,
})
}

return adapter.
NewMeshModelRegistrant(meshmodelRDP, fmt.Sprintf("%s/api/meshmodel/components/register", runtime)).
Register(uuid)
}

// RegisterWorkloads will register all of the workload definitions
// present in the path oam/workloads
//
Expand Down Expand Up @@ -56,6 +86,31 @@ func RegisterWorkloads(runtime, host string) error {
Register()
}

func loadMeshmodelComponents(basepath string) ([]meshmodelDefinitionPathSet, error) {
res := []meshmodelDefinitionPathSet{}
if err := filepath.Walk(basepath, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}

if info.IsDir() {
return nil
}

res = append(res, meshmodelDefinitionPathSet{
meshmodelDefinitionPath: path,
})
availableVersionGlobalMutex.Lock()
AvailableVersions[filepath.Base(filepath.Dir(path))] = true // Getting available versions already existing on file system
availableVersionGlobalMutex.Unlock()
return nil
}); err != nil {
return nil, err
}

return res, nil
}

// RegisterTraits will register all of the trait definitions
// present in the path oam/traits
//
Expand Down Expand Up @@ -107,7 +162,9 @@ func load(basePath string) ([]schemaDefinitionPathSet, error) {
jsonSchemaPath: fmt.Sprintf("%s.meshery.layer5io.schema.json", nameWithPath),
name: filepath.Base(nameWithPath),
})
availableVersionGlobalMutex.Lock()
AvailableVersions[filepath.Base(filepath.Dir(path))] = true
availableVersionGlobalMutex.Unlock()
}

return nil
Expand Down
17 changes: 17 additions & 0 deletions build/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,26 @@ var DefaultGenerationMethod string
var DefaultGenerationURL string
var LatestVersion string
var WorkloadPath string
var MeshModelPath string
var AllVersions []string

const Component = "APP_MESH"

var meshmodelmetadata = map[string]interface{}{
"Primary Color": "#F49322",
"Secondary Color": "#F4BC79",
"Shape": "circle",
"Logo URL": "",
"SVG_Color": "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE svg><svg width=\"32\" height=\"32\" viewBox=\"0 0 122 122\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\"><path fill-rule=\"evenodd\" clip-rule=\"evenodd\" d=\"M34.667 116.007C4.287 101.462-8.551 65.04 5.992 34.657A60.98 60.98 0 0 1 87.333 5.98c30.38 14.544 43.218 50.966 28.675 81.35-14.544 30.383-50.962 43.222-81.341 28.677Z\" fill=\"#F49322\"/><path d=\"m29.488 41.005-1.92-3.24 11.328-5.76 1.92 3.24-11.328 5.76Zm18.048-9.18-1.92-3.24 10.176-5.22 1.92 3.24-10.176 5.22Zm10.368 26.1-10.176-5.04 1.728-3.24 10.176 5.04-1.728 3.24Zm-17.088-8.46-10.176-5.04 1.728-3.24 10.176 5.04-1.728 3.24Zm24.576 8.1-1.728-3.24 10.368-4.68 1.728 3.24-10.368 4.68Zm17.28-7.92-1.728-3.24 10.368-4.68 1.728 3.24-10.368 4.68Zm-25.92 50.58-11.52-5.76 1.728-3.24 11.52 5.76-1.728 3.24Zm-17.28-8.28-10.176-5.04 1.728-3.24 10.176 5.04-1.728 3.24Zm-10.368-46.26h-3.84v13.86h3.84v-13.86Zm33.792 35.82h-3.84v14.22h3.84v-14.22Z\" fill=\"#fff\"/><path d=\"M27.184 47.125a5.425 5.425 0 0 1-3.648-1.44c-.96-.9-1.536-2.16-1.536-3.42 0-1.26.576-2.52 1.536-3.42 1.92-1.8 5.376-1.8 7.296 0 .96.9 1.536 2.16 1.536 3.42 0 1.26-.576 2.52-1.536 3.42-.96.9-2.304 1.44-3.648 1.44Zm0-6.12c-.384 0-.768.18-.96.36-.192.18-.384.54-.384.9s.192.72.384.9c.576.54 1.344.54 1.92 0 .192-.18.384-.54.384-.9s-.192-.72-.384-.9a1.52 1.52 0 0 0-.96-.36Zm0 46.44a5.425 5.425 0 0 1-3.648-1.44c-.96-.9-1.536-2.16-1.536-3.42 0-1.26.576-2.52 1.536-3.42 1.92-1.8 5.376-1.8 7.296 0 .96.9 1.536 2.16 1.536 3.42 0 1.26-.576 2.52-1.536 3.42-.96.9-2.304 1.44-3.648 1.44Zm0-6.12c-.384 0-.768.18-.96.36-.192.18-.384.54-.384.9s.192.72.384.9c.576.54 1.344.54 1.92 0 .192-.18.384-.54.384-.9s-.192-.72-.384-.9a1.52 1.52 0 0 0-.96-.36Zm33.792 22.32a5.425 5.425 0 0 1-3.648-1.44c-.96-.9-1.536-2.16-1.536-3.42 0-1.26.576-2.52 1.536-3.42 2.112-1.98 5.376-1.98 7.296 0 2.112 1.98 2.112 5.04 0 6.84-1.152.9-2.304 1.44-3.648 1.44Zm0-6.3c-.384 0-.768.18-.96.36-.576.54-.576 1.26 0 1.8s1.344.54 1.92 0c.576-.54.576-1.26 0-1.8-.384-.18-.768-.36-.96-.36Zm0-34.2a5.425 5.425 0 0 1-3.648-1.44c-.96-.9-1.536-2.16-1.536-3.42 0-1.26.576-2.52 1.536-3.42 2.112-1.98 5.376-1.98 7.296 0 2.112 1.98 2.112 5.04 0 6.84-1.152 1.08-2.304 1.44-3.648 1.44Zm0-6.12c-.384 0-.768.18-.96.36-.576.54-.576 1.26 0 1.8s1.344.54 1.92 0c.576-.54.576-1.26 0-1.8-.384-.18-.768-.36-.96-.36Zm33.216 30.42a5.425 5.425 0 0 1-3.648-1.44c-2.112-1.98-2.112-5.04 0-6.84 1.92-1.8 5.376-1.8 7.296 0 .96.9 1.536 2.16 1.536 3.42 0 1.26-.576 2.52-1.536 3.42-.96.9-2.304 1.44-3.648 1.44Zm0-6.12c-.384 0-.768.18-.96.36-.576.54-.576 1.26 0 1.8s1.344.54 1.92 0c.576-.54.576-1.26 0-1.8a1.52 1.52 0 0 0-.96-.36Zm0-34.2a5.425 5.425 0 0 1-3.648-1.44c-2.112-1.98-2.112-5.04 0-6.84 1.92-1.8 5.376-1.8 7.296 0 2.112 1.98 2.112 5.04 0 6.84-.96.9-2.304 1.44-3.648 1.44Zm0-6.12c-.384 0-.768.18-.96.36-.576.54-.576 1.26 0 1.8s1.344.54 1.92 0c.576-.54.576-1.26 0-1.8a1.52 1.52 0 0 0-.96-.36Zm-33.216-12.24a5.425 5.425 0 0 1-3.648-1.44c-.96-.9-1.536-2.16-1.536-3.42 0-1.26.576-2.52 1.536-3.42 2.112-1.98 5.376-1.98 7.296 0 2.112 1.98 2.112 5.04 0 6.84-1.152.9-2.304 1.44-3.648 1.44Zm0-6.12c-.384 0-.768.18-.96.36-.576.54-.576 1.26 0 1.8s1.344.54 1.92 0c.576-.54.576-1.26 0-1.8-.384-.36-.768-.36-.96-.36Z\" fill=\"#fff\"/><path d=\"M29.104 63.145h-3.84v15.48h3.84v-15.48Zm66.816-17.46h-3.84v13.86h3.84v-13.86Zm0 17.46h-3.84v15.48h3.84v-15.48Zm-14.784-28.08 1.92-3.24L94 37.405l-1.92 3.24-10.944-5.58Zm-18.432-9.36 1.92-3.24 11.712 5.94-1.92 3.24-11.712-5.94Zm.192 36h-3.84v14.22h3.84v-14.22Zm.576 35.46 11.136-5.4 1.728 3.24-11.136 5.4-1.728-3.24Zm16.704-8.1 10.944-5.4 1.728 3.24-10.944 5.4-1.728-3.24Z\" fill=\"#fff\"/></svg>",
"SVG_White": "<svg width=\"32\" height=\"32\" viewBox=\"0 0 32 32\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\"><g clip-path=\"url(#a)\" fill=\"#fff\"><path d=\"M3.095 8.319 2.3 7.094l4.682-2.178.794 1.225L3.095 8.32Zm7.46-3.47L9.76 3.622l4.205-1.973.794 1.225-4.206 1.973Zm4.285 9.866-4.207-1.905.715-1.225 4.206 1.906-.715 1.224Zm-7.063-3.198L3.57 9.612l.714-1.225 4.206 1.905-.714 1.225Zm10.157 3.063-.714-1.225 4.285-1.77.714 1.225-4.285 1.77Zm7.142-2.995-.714-1.225 4.285-1.769.714 1.225-4.285 1.77ZM14.363 30.707l-4.761-2.178.714-1.224 4.761 2.177-.714 1.225Zm-7.142-3.13-4.206-1.905.715-1.226 4.205 1.906-.714 1.225ZM2.936 10.088H1.35v5.24h1.587v-5.24ZM16.903 23.63h-1.587v5.376h1.587V23.63Z\"/><path d=\"M2.143 10.633a2.36 2.36 0 0 1-1.508-.545C.238 9.748 0 9.272 0 8.795c0-.476.238-.952.635-1.293.793-.68 2.222-.68 3.015 0 .397.34.635.817.635 1.293 0 .477-.238.953-.635 1.293a2.36 2.36 0 0 1-1.507.545Zm0-2.314a.662.662 0 0 0-.397.136.484.484 0 0 0-.159.34c0 .136.08.273.159.34a.59.59 0 0 0 .793 0 .484.484 0 0 0 .16-.34.484.484 0 0 0-.16-.34.662.662 0 0 0-.396-.136Zm0 17.556a2.36 2.36 0 0 1-1.508-.544C.238 24.991 0 24.515 0 24.038c0-.476.238-.953.635-1.293.793-.68 2.222-.68 3.015 0 .397.34.635.817.635 1.293 0 .477-.238.953-.635 1.293a2.36 2.36 0 0 1-1.507.544Zm0-2.313a.662.662 0 0 0-.397.136.484.484 0 0 0-.159.34c0 .136.08.272.159.34a.59.59 0 0 0 .793 0 .484.484 0 0 0 .16-.34.484.484 0 0 0-.16-.34.663.663 0 0 0-.396-.136ZM16.11 32a2.36 2.36 0 0 1-1.509-.544c-.396-.34-.635-.817-.635-1.293 0-.477.239-.953.635-1.293.873-.749 2.222-.749 3.016 0 .873.748.873 1.905 0 2.586-.476.34-.952.544-1.508.544Zm0-2.382a.662.662 0 0 0-.398.137c-.238.204-.238.476 0 .68a.59.59 0 0 0 .794 0c.238-.204.238-.476 0-.68-.159-.069-.317-.137-.397-.137Zm0-12.929a2.36 2.36 0 0 1-1.509-.544c-.396-.34-.635-.817-.635-1.293 0-.477.239-.953.635-1.293.873-.749 2.222-.749 3.016 0 .873.748.873 1.905 0 2.586-.476.408-.952.544-1.508.544Zm0-2.314a.662.662 0 0 0-.398.136c-.238.205-.238.477 0 .681a.59.59 0 0 0 .794 0c.238-.204.238-.476 0-.68-.159-.069-.317-.137-.397-.137Zm13.728 11.5a2.36 2.36 0 0 1-1.508-.544c-.873-.748-.873-1.905 0-2.586.793-.68 2.222-.68 3.015 0 .397.34.635.817.635 1.293 0 .477-.238.953-.635 1.293a2.36 2.36 0 0 1-1.507.544Zm0-2.313a.662.662 0 0 0-.397.136c-.238.204-.238.476 0 .68a.59.59 0 0 0 .793 0c.238-.204.238-.476 0-.68a.663.663 0 0 0-.396-.136Zm0-12.929a2.36 2.36 0 0 1-1.508-.545c-.873-.748-.873-1.905 0-2.586.793-.68 2.222-.68 3.015 0 .873.749.873 1.906 0 2.586a2.36 2.36 0 0 1-1.507.545Zm0-2.314a.663.663 0 0 0-.397.136c-.238.204-.238.476 0 .68a.59.59 0 0 0 .793 0c.238-.204.238-.476 0-.68a.662.662 0 0 0-.396-.136ZM16.11 3.692a2.36 2.36 0 0 1-1.509-.545c-.396-.34-.635-.816-.635-1.293 0-.476.239-.952.635-1.293.873-.748 2.222-.748 3.016 0 .873.749.873 1.906 0 2.586-.476.34-.952.545-1.508.545Zm0-2.314a.662.662 0 0 0-.398.136c-.238.204-.238.476 0 .68a.59.59 0 0 0 .794 0c.238-.204.238-.476 0-.68-.159-.136-.317-.136-.397-.136Z\"/><path d=\"M2.936 16.689H1.35v5.852h1.587V16.69Zm27.616-6.601h-1.587v5.24h1.587v-5.24Zm0 6.601h-1.587v5.852h1.587V16.69Zm-6.11-10.616.793-1.225 4.523 2.11-.793 1.225-4.523-2.11Zm-7.619-3.538.794-1.225 4.84 2.245-.793 1.225-4.84-2.245Zm.08 13.61h-1.587v5.376h1.587v-5.376Zm.237 13.405 4.603-2.041.715 1.225-4.603 2.041-.714-1.225Zm6.905-3.062 4.523-2.041.714 1.225-4.523 2.04-.714-1.224Z\"/></g><defs><clipPath id=\"a\"><path fill=\"#fff\" d=\"M0 0h32v32H0z\"/></clipPath></defs></svg>",
}

var MeshModelConfig = adapter.MeshModelConfig{ //Move to build/config.go
Category: "Orchestration & Management",
SubCategory: "Service Mesh",
Metadata: meshmodelmetadata,
}

// NewConfig creates the configuration for creating components
func NewConfig(version string) manifests.Config {
return manifests.Config{
Expand All @@ -41,6 +57,7 @@ func NewConfig(version string) manifests.Config {
func init() {
wd, _ := os.Getwd()
WorkloadPath = filepath.Join(wd, "templates", "oam", "workloads")
MeshModelPath = filepath.Join(wd, "templates", "meshmodel", "components")
AllVersions, _ = utils.GetLatestReleaseTagsSorted("aws", "aws-app-mesh-controller-for-k8s")
if len(AllVersions) == 0 {
return
Expand Down
14 changes: 12 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ replace (

require (
github.com/google/uuid v1.3.0
github.com/layer5io/meshery-adapter-library v0.6.0
github.com/layer5io/meshery-adapter-library v0.6.3
github.com/layer5io/meshkit v0.6.11
github.com/layer5io/service-mesh-performance v0.3.4
gopkg.in/yaml.v2 v2.4.0
Expand Down Expand Up @@ -73,6 +73,15 @@ require (
github.com/huandu/xstrings v1.3.2 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgconn v1.13.0 // indirect
github.com/jackc/pgio v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgproto3/v2 v2.3.1 // indirect
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
github.com/jackc/pgtype v1.12.0 // indirect
github.com/jackc/pgx/v4 v4.17.2 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/jmoiron/sqlx v1.3.5 // indirect
github.com/josharian/intern v1.0.0 // indirect
Expand Down Expand Up @@ -125,7 +134,6 @@ require (
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.11.0 // indirect
github.com/stretchr/objx v0.4.0 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
Expand All @@ -152,6 +160,8 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.66.4 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/driver/postgres v1.3.10 // indirect
gorm.io/driver/sqlite v1.3.1 // indirect
gorm.io/gorm v1.23.7 // indirect
helm.sh/helm/v3 v3.9.4 // indirect
k8s.io/api v0.25.1 // indirect
Expand Down
Loading

0 comments on commit 93ece74

Please sign in to comment.