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 64 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
10 changes: 5 additions & 5 deletions components/configstores/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

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

type StoreFactory struct {
Expand Down Expand Up @@ -59,10 +59,10 @@ func (r *StoreRegistry) Register(fs ...*StoreFactory) {
}
}

func (r *StoreRegistry) Create(name string) (Store, error) {
if f, ok := r.stores[name]; ok {
r.info.LoadComponent(ServiceName, name)
func (r *StoreRegistry) Create(componentType string) (Store, error) {
if f, ok := r.stores[componentType]; ok {
r.info.LoadComponent(ServiceName, componentType)
return f(), nil
}
return nil, fmt.Errorf("service component %s is not regsitered", name)
return nil, fmt.Errorf("service component %s is not regsitered", componentType)
}
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"`
}
12 changes: 6 additions & 6 deletions components/custom/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ import (

type Registry interface {
Register(componentType string, factorys ...*ComponentFactory)
Create(componentType, name string) (Component, error)
Create(kind, componentType 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 Down Expand Up @@ -59,8 +59,8 @@ func (r *componentRegistry) Register(componentType string, fs ...*ComponentFacto
}
// register FactoryMethod
for _, f := range fs {
r.stores[componentType][f.Name] = f.FactoryMethod
r.info.RegisterComponent(componentType, f.Name)
r.stores[componentType][f.Type] = f.FactoryMethod
r.info.RegisterComponent(componentType, f.Type)
}
}

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

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

type FileFactory struct {
Expand Down Expand Up @@ -59,10 +59,10 @@ func (r *FileStoreRegistry) Register(fs ...*FileFactory) {
}
}

func (r *FileStoreRegistry) Create(name string) (File, error) {
if f, ok := r.files[name]; ok {
r.info.LoadComponent(ServiceName, name)
func (r *FileStoreRegistry) Create(componentType string) (File, error) {
if f, ok := r.files[componentType]; ok {
r.info.LoadComponent(ServiceName, componentType)
return f(), nil
}
return nil, fmt.Errorf("service component %s is not regsitered", name)
return nil, fmt.Errorf("service component %s is not regsitered", componentType)
}
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
10 changes: 5 additions & 5 deletions components/hello/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

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

type HelloFactory struct {
akkw marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -59,10 +59,10 @@ func (r *helloRegistry) Register(fs ...*HelloFactory) {
}
}

func (r *helloRegistry) Create(name string) (HelloService, error) {
if f, ok := r.stores[name]; ok {
r.info.LoadComponent(ServiceName, name) // 加载组件信息
func (r *helloRegistry) Create(componentType string) (HelloService, error) {
if f, ok := r.stores[componentType]; ok {
r.info.LoadComponent(ServiceName, componentType) // 加载组件信息
return f(), nil
}
return nil, fmt.Errorf("service component %s is not regsitered", name)
return nil, fmt.Errorf("service component %s is not regsitered", componentType)
}
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
4 changes: 2 additions & 2 deletions components/pkg/info/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func (info *RuntimeInfo) RegisterComponent(service string, name string) {
}
}

func (info *RuntimeInfo) LoadComponent(service string, name string) {
func (info *RuntimeInfo) LoadComponent(service string, componentType string) {
if c, ok := info.Services[service]; ok {
c.Loaded = append(c.Loaded, name)
c.Loaded = append(c.Loaded, componentType)
}
}
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
18 changes: 12 additions & 6 deletions configs/config_in_memory.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,43 @@
"server_name": "runtime",
"grpc_config": {
"hellos": {
"helloworld": {
"quick_start_demo": {
"type": "helloworld",
"hello": "greeting"
}
},
"state": {
"in-memory": {
"state_demo": {
"type": "in-memory",
"metadata": {
}
}
},
"lock": {
"in-memory": {
"lock_demo": {
"type": "in-memory",
"metadata": {
}
}
},
"pub_subs": {
"in-memory": {
"pub_subs_demo": {
"type": "in-memory",
"metadata": {
"consumerID": "1"
}
}
},
"sequencer": {
"in-memory": {
"sequencer_demo": {
"type": "in-memory",
"metadata": {}
}
},
"custom_component": {
"helloworld": {
"in-memory": {
"demo": {
"type": "in-memory",
seeflood marked this conversation as resolved.
Show resolved Hide resolved
"metadata": {}
}
}
Expand Down
Loading