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

feature: Decoupled type #549

Merged
merged 75 commits into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from 74 commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
5485ede
decouple Name and Type
akkw May 8, 2022
7531b39
decouple Name and Type
akkw May 8, 2022
5bcf169
Merge branch 'main' into decoupled_type
akkw May 8, 2022
f9e525b
decouple Name and Type
akkw May 8, 2022
7e4a4e4
decouple Name and Type
akkw May 8, 2022
1480708
Merge branch 'main' of github.com:mosn/layotto into decoupled_type
akkw May 11, 2022
aefe748
decouple Name and Type
akkw May 11, 2022
740fa08
Merge branch 'main' into decoupled_type
zhenjunMa May 12, 2022
7f6b720
Merge branch 'main' into decoupled_type
seeflood May 12, 2022
aa23245
Merge branch 'main' into decoupled_type
seeflood May 13, 2022
2b02e13
decouple Name and Type
akkw May 14, 2022
3ccfc2f
decouple Name and Type
akkw May 14, 2022
c2e2d35
decouple Name and Type
akkw May 14, 2022
aa6835e
decouple Name and Type
akkw May 14, 2022
cbecd72
decouple Name and Type
akkw May 14, 2022
625615a
decouple Name and Type
akkw May 14, 2022
47ae961
decouple Name and Type
akkw May 14, 2022
1bc3ec8
decouple Name and Type
akkw May 14, 2022
928a504
decouple Name and Type
akkw May 14, 2022
98def9e
decouple Name and Type
akkw May 14, 2022
36213b2
decouple Name and Type
akkw May 14, 2022
bde6ef3
decouple Name and Type
akkw May 14, 2022
18c3006
decouple Name and Type
akkw May 15, 2022
045a09b
decouple Name and Type
akkw May 15, 2022
ffdb3b4
Merge branch 'main' into decoupled_type
Xunzhuo May 15, 2022
cebed22
decouple Name and Type
akkw May 15, 2022
a349906
decouple Name and Type
akkw May 15, 2022
7483638
decouple Name and Type
akkw May 15, 2022
a7eb031
decouple Name and Type
akkw May 15, 2022
1891524
decouple Name and Type
akkw May 15, 2022
210ea47
decouple Name and Type
akkw May 15, 2022
7fe5458
decouple Name and Type
akkw May 15, 2022
2378a09
decouple Name and Type
akkw May 15, 2022
ccdbef6
decouple Name and Type
akkw May 15, 2022
208e89f
decouple Name and Type
akkw May 15, 2022
a6889fd
decouple Name and Type
akkw May 15, 2022
7872978
decouple Name and Type
akkw May 15, 2022
a78492f
decouple Name and Type
akkw May 15, 2022
5230f1a
Merge branch 'main' into decoupled_type
seeflood May 16, 2022
671ab35
decouple Name and Type
akkw May 16, 2022
eca8ecc
decouple Name and Type
akkw May 16, 2022
3fabb6e
decouple Name and Type
akkw May 16, 2022
cc16133
decouple Name and Type
akkw May 16, 2022
4ff1c6b
decouple Name and Type
akkw May 16, 2022
12d1f58
decouple Name and Type
akkw May 17, 2022
a073161
decouple Name and Type
akkw May 17, 2022
5c073e9
decouple Name and Type
akkw May 17, 2022
26ab6e1
decouple Name and Type
akkw May 17, 2022
0584b18
Merge branch 'main' into decoupled_type
akkw May 18, 2022
2b6fba7
update wasm demo
zhenjunMa May 18, 2022
fe5a2f8
Merge branch 'main' into decoupled_type
seeflood May 19, 2022
ae5d00a
add type field
seeflood May 19, 2022
cc55fb3
modify custom component
seeflood May 19, 2022
d940cf9
fix typo
seeflood May 19, 2022
17a8c10
demo -> mosn
seeflood May 19, 2022
b54b43d
fix typo
seeflood May 19, 2022
86253bf
decouple Name and Type
akkw May 19, 2022
45ce426
decouple Name and Type
akkw May 19, 2022
7137fde
decouple Name and Type
akkw May 19, 2022
8392e11
decouple Name and Type
akkw May 21, 2022
505339c
Merge branch 'main' of github.com:mosn/layotto into decoupled_type
akkw May 21, 2022
8452cc9
decouple Name and Type
akkw May 21, 2022
800af6d
improve runtime_test.go
seeflood May 23, 2022
8a0eda9
fix ut
seeflood May 23, 2022
1f16729
decouple Name and Type
akkw May 24, 2022
8666733
Merge branch 'decoupled_type' of github.com:akkw/layotto into decoupl…
akkw May 24, 2022
f95470f
Merge branch 'main' of github.com:mosn/layotto into decoupled_type
akkw May 24, 2022
aabed76
Merge branch 'main' of github.com:mosn/layotto into decoupled_type
akkw May 24, 2022
201c561
decouple Name and Type
akkw May 24, 2022
760fc30
decouple Name and Type
akkw May 24, 2022
b1263b5
decouple Name and Type
akkw May 24, 2022
0c9c2cf
decouple Name and Type
akkw May 24, 2022
d996572
decouple Name and Type
akkw May 24, 2022
eeab6f0
decouple Name and Type
akkw May 24, 2022
405a271
fix ut
seeflood May 25, 2022
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
4 changes: 2 additions & 2 deletions cmd/layotto_multiple_api/helloworld/grpc_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
grpc_api "mosn.io/layotto/pkg/grpc"
)

const componentType = "helloworld"
const kind = "helloworld"

// This demo will always use this component name.
const componentName = "in-memory"
Expand All @@ -40,7 +40,7 @@ func NewHelloWorldAPI(ac *grpc_api.ApplicationContext) grpc.GrpcAPI {
name2component := make(map[string]component.HelloWorld)
if len(ac.CustomComponent) != 0 {
// we only care about those components of type "helloworld"
name2comp, ok := ac.CustomComponent[componentType]
name2comp, ok := ac.CustomComponent[kind]
if ok && len(name2comp) > 0 {
for name, v := range name2comp {
// convert them using type assertion
Expand Down
20 changes: 10 additions & 10 deletions components/configstores/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ import (

type Registry interface {
Register(fs ...*StoreFactory)
Create(name string) (Store, error)
Create(compType string) (Store, error)
}

type StoreFactory struct {
Name string
CompType string
FactoryMethod func() Store
}

func NewStoreFactory(name string, f func() Store) *StoreFactory {
func NewStoreFactory(compType string, f func() Store) *StoreFactory {
return &StoreFactory{
Name: name,
CompType: compType,
FactoryMethod: f,
}
}
Expand All @@ -54,15 +54,15 @@ func NewRegistry(info *info.RuntimeInfo) Registry {

func (r *StoreRegistry) Register(fs ...*StoreFactory) {
for _, f := range fs {
r.stores[f.Name] = f.FactoryMethod
r.info.RegisterComponent(ServiceName, f.Name)
r.stores[f.CompType] = f.FactoryMethod
r.info.RegisterComponent(ServiceName, f.CompType)
}
}

func (r *StoreRegistry) Create(name string) (Store, error) {
if f, ok := r.stores[name]; ok {
r.info.LoadComponent(ServiceName, name)
func (r *StoreRegistry) Create(compType string) (Store, error) {
if f, ok := r.stores[compType]; ok {
r.info.LoadComponent(ServiceName, compType)
return f(), nil
}
return nil, fmt.Errorf("service component %s is not regsitered", name)
return nil, fmt.Errorf("service component %s is not regsitered", compType)
}
1 change: 1 addition & 0 deletions components/configstores/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package configstores

// StoreConfig wraps configuration for a store implementation
type StoreConfig struct {
Type string `json:"type"`
akkw marked this conversation as resolved.
Show resolved Hide resolved
StoreName string `json:"store_name"`
Address []string `json:"address"`
TimeOut string `json:"timeout"`
Expand Down
1 change: 1 addition & 0 deletions components/custom/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package custom

type Config struct {
Type string `json:"type"`
Version string `json:"version"`
Metadata map[string]string `json:"metadata"`
}
30 changes: 15 additions & 15 deletions components/custom/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ import (
)

type Registry interface {
Register(componentType string, factorys ...*ComponentFactory)
Create(componentType, name string) (Component, error)
Register(kind string, factorys ...*ComponentFactory)
Create(kind, compType string) (Component, error)
}

type ComponentFactory struct {
Name string
Type string
FactoryMethod func() Component
}

func NewComponentFactory(name string, f func() Component) *ComponentFactory {
func NewComponentFactory(compType string, f func() Component) *ComponentFactory {
return &ComponentFactory{
Name: name,
Type: compType,
FactoryMethod: f,
}
}
Expand All @@ -48,29 +48,29 @@ func NewRegistry(info *info.RuntimeInfo) Registry {
}
}

func (r *componentRegistry) Register(componentType string, fs ...*ComponentFactory) {
func (r *componentRegistry) Register(kind string, fs ...*ComponentFactory) {
if len(fs) == 0 {
return
}
r.info.AddService(componentType)
r.info.AddService(kind)
// lazy init
if _, ok := r.stores[componentType]; !ok {
r.stores[componentType] = make(map[string]func() Component)
if _, ok := r.stores[kind]; !ok {
r.stores[kind] = make(map[string]func() Component)
}
// register FactoryMethod
for _, f := range fs {
r.stores[componentType][f.Name] = f.FactoryMethod
r.info.RegisterComponent(componentType, f.Name)
r.stores[kind][f.Type] = f.FactoryMethod
r.info.RegisterComponent(kind, f.Type)
}
}

func (r *componentRegistry) Create(componentType, name string) (Component, error) {
store, ok := r.stores[componentType]
func (r *componentRegistry) Create(compType, name string) (Component, error) {
seeflood marked this conversation as resolved.
Show resolved Hide resolved
store, ok := r.stores[compType]
if !ok {
return nil, fmt.Errorf("custom component type %s is not regsitered", componentType)
return nil, fmt.Errorf("custom component type %s is not regsitered", compType)
}
if f, ok := store[name]; ok {
r.info.LoadComponent(componentType, name)
r.info.LoadComponent(compType, name)
return f(), nil
}
return nil, fmt.Errorf("custom component %s is not regsitered", name)
Expand Down
20 changes: 10 additions & 10 deletions components/file/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ import (

type Registry interface {
Register(fs ...*FileFactory)
Create(name string) (File, error)
Create(compType string) (File, error)
}

type FileFactory struct {
Name string
CompType string
FactoryMethod func() File
}

func NewFileFactory(name string, f func() File) *FileFactory {
func NewFileFactory(CompType string, f func() File) *FileFactory {
return &FileFactory{
Name: name,
CompType: CompType,
FactoryMethod: f,
}
}
Expand All @@ -54,15 +54,15 @@ func NewRegistry(info *info.RuntimeInfo) Registry {

func (r *FileStoreRegistry) Register(fs ...*FileFactory) {
for _, f := range fs {
r.files[f.Name] = f.FactoryMethod
r.info.RegisterComponent(ServiceName, f.Name)
r.files[f.CompType] = f.FactoryMethod
r.info.RegisterComponent(ServiceName, f.CompType)
}
}

func (r *FileStoreRegistry) Create(name string) (File, error) {
if f, ok := r.files[name]; ok {
r.info.LoadComponent(ServiceName, name)
func (r *FileStoreRegistry) Create(compType string) (File, error) {
if f, ok := r.files[compType]; ok {
r.info.LoadComponent(ServiceName, compType)
return f(), nil
}
return nil, fmt.Errorf("service component %s is not regsitered", name)
return nil, fmt.Errorf("service component %s is not regsitered", compType)
}
1 change: 1 addition & 0 deletions components/file/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

// FileConfig wraps configuration for a file implementation
type FileConfig struct {
Type string `json:"type"`
Metadata json.RawMessage
}

Expand Down
1 change: 1 addition & 0 deletions components/hello/hello.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type HelloService interface {
}

type HelloConfig struct {
Type string `json:"type"`
HelloString string `json:"hello"`
}

Expand Down
20 changes: 10 additions & 10 deletions components/hello/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ import (

type Registry interface {
Register(fs ...*HelloFactory)
Create(name string) (HelloService, error)
Create(compType string) (HelloService, error)
}

type HelloFactory struct {
akkw marked this conversation as resolved.
Show resolved Hide resolved
Name string
CompType string
FatcoryMethod func() HelloService
}

func NewHelloFactory(name string, f func() HelloService) *HelloFactory {
func NewHelloFactory(compType string, f func() HelloService) *HelloFactory {
return &HelloFactory{
Name: name,
CompType: compType,
FatcoryMethod: f,
}
}
Expand All @@ -54,15 +54,15 @@ func NewRegistry(info *info.RuntimeInfo) Registry {

func (r *helloRegistry) Register(fs ...*HelloFactory) {
for _, f := range fs {
r.stores[f.Name] = f.FatcoryMethod
r.info.RegisterComponent(ServiceName, f.Name) // 注册组件信息
r.stores[f.CompType] = f.FatcoryMethod
r.info.RegisterComponent(ServiceName, f.CompType) // 注册组件信息
}
}

func (r *helloRegistry) Create(name string) (HelloService, error) {
if f, ok := r.stores[name]; ok {
r.info.LoadComponent(ServiceName, name) // 加载组件信息
func (r *helloRegistry) Create(compType string) (HelloService, error) {
if f, ok := r.stores[compType]; ok {
r.info.LoadComponent(ServiceName, compType) // 加载组件信息
return f(), nil
}
return nil, fmt.Errorf("service component %s is not regsitered", name)
return nil, fmt.Errorf("service component %s is not regsitered", compType)
}
1 change: 1 addition & 0 deletions components/lock/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Feature string

// Lock's metadata
type Config struct {
Type string `json:"type"`
Metadata map[string]string `json:"metadata"`
}

Expand Down
8 changes: 4 additions & 4 deletions components/pkg/info/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ func (info *RuntimeInfo) AddService(service string) {
info.Services[service] = &ComponentInfo{}
}

func (info *RuntimeInfo) RegisterComponent(service string, name string) {
func (info *RuntimeInfo) RegisterComponent(service string, compType string) {
if c, ok := info.Services[service]; ok {
c.Registered = append(c.Registered, name)
c.Registered = append(c.Registered, compType)
}
}

func (info *RuntimeInfo) LoadComponent(service string, name string) {
func (info *RuntimeInfo) LoadComponent(service string, compType string) {
if c, ok := info.Services[service]; ok {
c.Loaded = append(c.Loaded, name)
c.Loaded = append(c.Loaded, compType)
akkw marked this conversation as resolved.
Show resolved Hide resolved
}
}
1 change: 1 addition & 0 deletions components/sequencer/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package sequencer

type Config struct {
Type string `json:"type"`
BiggerThan map[string]int64 `json:"biggerThan"`
Metadata map[string]string `json:"metadata"`
}
6 changes: 4 additions & 2 deletions configs/config_apollo.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@
"server_name": "runtime",
"grpc_config": {
"hellos": {
"helloworld": {
"quick_start_demo": {
"type": "helloworld",
"hello": "greeting"
}
},
"config_store": {
akkw marked this conversation as resolved.
Show resolved Hide resolved
"apollo": {
"config_demo": {
"type": "apollo",
"address": [
"http://106.54.227.205:8080"
],
Expand Down
6 changes: 4 additions & 2 deletions configs/config_apollo_health.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@
"server_name": "runtime",
"grpc_config": {
"hellos": {
"helloworld": {
"quick_start_demo": {
"type": "helloworld",
"hello": "greeting"
}
},
"config_store": {
"apollo": {
"config_demo": {
"type": "apollo",
"address": [
"http://106.54.227.205:8080"
],
Expand Down
6 changes: 4 additions & 2 deletions configs/config_bindings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
"server_name": "runtime",
"grpc_config": {
"hellos": {
"helloworld": {
"quick_start_demo": {
"type": "helloworld",
"hello": "greeting"
}
},
"bindings": {
"http": {
"bindings_demo": {
"type": "http",
"metadata":
{
"url": "https://github.com/mosn/layotto"
Expand Down
6 changes: 4 additions & 2 deletions configs/config_file.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
"server_name": "runtime",
"grpc_config": {
"hellos": {
"helloworld": {
"quick_start_demo": {
"type": "helloworld",
"hello": "greeting"
}
},
"file": {
"minioOSS": {
"file_demo": {
"type": "minioOSS",
"metadata": [
{
"endpoint": "127.0.0.1:9000",
Expand Down
6 changes: 4 additions & 2 deletions configs/config_file_qiniu_oss.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
"server_name": "runtime",
"grpc_config": {
"hellos": {
"helloworld": {
"quick_start_demo": {
"type": "helloworld",
"hello": "greeting"
}
},
"file": {
"qiniuOSS": {
"file_demo": {
"type": "qiniuOSS",
"metadata": [
{
"endpoint": "<require>",
Expand Down
6 changes: 4 additions & 2 deletions configs/config_file_tencentcloud_oss.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
"server_name": "runtime",
"grpc_config": {
"hellos": {
"helloworld": {
"quick_start_demo": {
"type": "helloworld",
"hello": "greeting"
}
},
"files": {
"tencentCloudOSS": {
"file_demo": {
"type": "tencentCloudOSS",
"metadata": [
{
"endpoint": "<get endpoint from https://console.cloud.tencent.com/cos/bucket configuration management>",
Expand Down
Loading