diff --git a/cmd/layotto_multiple_api/helloworld/grpc_api.go b/cmd/layotto_multiple_api/helloworld/grpc_api.go index b58e8987f9..435e79ba34 100644 --- a/cmd/layotto_multiple_api/helloworld/grpc_api.go +++ b/cmd/layotto_multiple_api/helloworld/grpc_api.go @@ -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" @@ -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 diff --git a/components/configstores/registry.go b/components/configstores/registry.go index f6a7b0ea1b..8b91996bf3 100644 --- a/components/configstores/registry.go +++ b/components/configstores/registry.go @@ -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, } } @@ -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) } diff --git a/components/configstores/types.go b/components/configstores/types.go index 7cf680ead9..54786ba1f1 100644 --- a/components/configstores/types.go +++ b/components/configstores/types.go @@ -18,6 +18,7 @@ package configstores // StoreConfig wraps configuration for a store implementation type StoreConfig struct { + Type string `json:"type"` StoreName string `json:"store_name"` Address []string `json:"address"` TimeOut string `json:"timeout"` diff --git a/components/custom/config.go b/components/custom/config.go index a4959b778b..56afd10ee7 100644 --- a/components/custom/config.go +++ b/components/custom/config.go @@ -14,6 +14,7 @@ package custom type Config struct { + Type string `json:"type"` Version string `json:"version"` Metadata map[string]string `json:"metadata"` } diff --git a/components/custom/registry.go b/components/custom/registry.go index a12af8dfa7..659662a235 100644 --- a/components/custom/registry.go +++ b/components/custom/registry.go @@ -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, } } @@ -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) { + 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) diff --git a/components/file/registry.go b/components/file/registry.go index ee986b7c31..c3102a237b 100644 --- a/components/file/registry.go +++ b/components/file/registry.go @@ -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, } } @@ -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) } diff --git a/components/file/types.go b/components/file/types.go index 6c68d7a397..746eb7ebbc 100644 --- a/components/file/types.go +++ b/components/file/types.go @@ -23,6 +23,7 @@ import ( // FileConfig wraps configuration for a file implementation type FileConfig struct { + Type string `json:"type"` Metadata json.RawMessage } diff --git a/components/hello/hello.go b/components/hello/hello.go index a9d244bad3..5f504d5fba 100644 --- a/components/hello/hello.go +++ b/components/hello/hello.go @@ -26,6 +26,7 @@ type HelloService interface { } type HelloConfig struct { + Type string `json:"type"` HelloString string `json:"hello"` } diff --git a/components/hello/registry.go b/components/hello/registry.go index 5aa3dbbaf2..8a0236717c 100644 --- a/components/hello/registry.go +++ b/components/hello/registry.go @@ -24,17 +24,17 @@ import ( type Registry interface { Register(fs ...*HelloFactory) - Create(name string) (HelloService, error) + Create(compType string) (HelloService, error) } type HelloFactory struct { - 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, } } @@ -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) } diff --git a/components/lock/types.go b/components/lock/types.go index ab88927917..ab7d25d27a 100644 --- a/components/lock/types.go +++ b/components/lock/types.go @@ -17,6 +17,7 @@ type Feature string // Lock's metadata type Config struct { + Type string `json:"type"` Metadata map[string]string `json:"metadata"` } diff --git a/components/pkg/info/info.go b/components/pkg/info/info.go index b16280923a..2c88fd6590 100644 --- a/components/pkg/info/info.go +++ b/components/pkg/info/info.go @@ -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) } } diff --git a/components/sequencer/types.go b/components/sequencer/types.go index af5c256fd3..4cc366b1c9 100644 --- a/components/sequencer/types.go +++ b/components/sequencer/types.go @@ -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"` } diff --git a/configs/config_apollo.json b/configs/config_apollo.json index 06d1a31dfe..cc9b358877 100644 --- a/configs/config_apollo.json +++ b/configs/config_apollo.json @@ -29,12 +29,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" ], diff --git a/configs/config_apollo_health.json b/configs/config_apollo_health.json index 2f3ace0548..9570acd529 100644 --- a/configs/config_apollo_health.json +++ b/configs/config_apollo_health.json @@ -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" ], diff --git a/configs/config_bindings.json b/configs/config_bindings.json index 4e069d73f4..2cab9d88ba 100644 --- a/configs/config_bindings.json +++ b/configs/config_bindings.json @@ -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" diff --git a/configs/config_file.json b/configs/config_file.json index f267e5e0e0..a249163fc8 100644 --- a/configs/config_file.json +++ b/configs/config_file.json @@ -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", diff --git a/configs/config_file_qiniu_oss.json b/configs/config_file_qiniu_oss.json index d87a5c7720..b9bf5df66d 100644 --- a/configs/config_file_qiniu_oss.json +++ b/configs/config_file_qiniu_oss.json @@ -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": "", diff --git a/configs/config_file_tencentcloud_oss.json b/configs/config_file_tencentcloud_oss.json index 441d1ab2b4..75bb97de55 100644 --- a/configs/config_file_tencentcloud_oss.json +++ b/configs/config_file_tencentcloud_oss.json @@ -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": "", diff --git a/configs/config_in_memory.json b/configs/config_in_memory.json index 983ff8d6e7..98ddf984ad 100644 --- a/configs/config_in_memory.json +++ b/configs/config_in_memory.json @@ -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", "metadata": {} } } diff --git a/configs/config_integration_redis_etcd.json b/configs/config_integration_redis_etcd.json index 2940dbaf08..ae5d7c73bf 100644 --- a/configs/config_integration_redis_etcd.json +++ b/configs/config_integration_redis_etcd.json @@ -61,19 +61,22 @@ } }, "hellos": { - "helloworld": { + "quick_start_demo": { + "type": "helloworld", "hello": "greeting" } }, "bindings": { - "http": { + "bindings_demo": { + "type": "http", "metadata": { "url": "https://registry.npmmirror.com/layotto/0.0.0" } } }, "config_store": { - "etcd": { + "config_demo": { + "type": "etcd", "address": [ "127.0.0.1:2379" ], @@ -81,7 +84,8 @@ } }, "state": { - "redis": { + "state_demo": { + "type": "redis", "metadata": { "redisHost": "localhost:6380", "redisPassword": "" @@ -89,7 +93,8 @@ } }, "sequencer": { - "etcd": { + "sequencer_demo1": { + "type": "etcd", "metadata": { "endpoints": "localhost:2379", "segmentCacheEnable": "false", @@ -99,7 +104,8 @@ "dialTimeout": "5" } }, - "redis": { + "sequencer_demo2": { + "type": "redis", "metadata": { "redisHost": "127.0.0.1:6380", "redisPassword": "" @@ -107,7 +113,8 @@ } }, "lock": { - "etcd": { + "lock_demo1": { + "type": "etcd", "metadata": { "endpoints": "localhost:2379", "username": "", @@ -116,7 +123,8 @@ "dialTimeout": "5" } }, - "redis": { + "lock_demo2": { + "type": "redis", "metadata": { "redisHost": "localhost:6380", "redisPassword": "" @@ -124,7 +132,8 @@ } }, "pub_subs": { - "redis": { + "pub_subs_demo": { + "type": "redis", "metadata": { "redisHost": "localhost:6380", "redisPassword": "" diff --git a/configs/config_lock_consul.json b/configs/config_lock_consul.json index 4233206f32..673fc04514 100644 --- a/configs/config_lock_consul.json +++ b/configs/config_lock_consul.json @@ -22,12 +22,14 @@ "server_name": "runtime", "grpc_config": { "hellos": { - "helloworld": { + "quick_start_demo": { + "type": "helloworld", "hello": "greeting" } }, "lock": { - "consul": { + "lock_demo": { + "type": "consul", "metadata": { "address": "localhost:8500", "scheme": "http" diff --git a/configs/config_lock_etcd.json b/configs/config_lock_etcd.json index c602e5dc04..acc7b94deb 100644 --- a/configs/config_lock_etcd.json +++ b/configs/config_lock_etcd.json @@ -22,12 +22,14 @@ "server_name": "runtime", "grpc_config": { "hellos": { - "helloworld": { + "quick_start_demo": { + "type": "helloworld", "hello": "greeting" } }, "lock": { - "etcd": { + "lock_demo": { + "type": "etcd", "metadata": { "endpoints": "localhost:2379", "username": "", diff --git a/configs/config_lock_mongo.json b/configs/config_lock_mongo.json index eadf0d992a..9a3a046627 100644 --- a/configs/config_lock_mongo.json +++ b/configs/config_lock_mongo.json @@ -22,12 +22,14 @@ "server_name": "runtime", "grpc_config": { "hellos": { - "helloworld": { + "quick_start_demo": { + "type": "helloworld", "hello": "greeting" } }, "lock": { - "mongo": { + "lock_demo": { + "type": "mongo", "metadata": { "mongoHost": "localhost:27017", "mongoPassword": "", diff --git a/configs/config_lock_redis.json b/configs/config_lock_redis.json index 20e1e6a385..0f6c121f65 100644 --- a/configs/config_lock_redis.json +++ b/configs/config_lock_redis.json @@ -22,12 +22,14 @@ "server_name": "runtime", "grpc_config": { "hellos": { - "helloworld": { + "quick_start_demo": { + "type": "helloworld", "hello": "greeting" } }, "lock": { - "redis": { + "lock_demo": { + "type": "redis", "metadata": { "redisHost": "localhost:6380", "redisPassword": "" diff --git a/configs/config_lock_redis_cluster.json b/configs/config_lock_redis_cluster.json index 99a7c33109..572946d474 100644 --- a/configs/config_lock_redis_cluster.json +++ b/configs/config_lock_redis_cluster.json @@ -22,12 +22,14 @@ "server_name": "runtime", "grpc_config": { "hellos": { - "helloworld": { + "quick_start_demo": { + "type": "helloworld", "hello": "greeting" } }, "lock": { - "redis_cluster": { + "lock_demo": { + "type": "redis_cluster", "metadata": { "concurrency": "0", "redisHosts": "localhost:6381,localhost:6382,localhost:6383,localhost:6384,localhost:6385", diff --git a/configs/config_lock_zookeeper.json b/configs/config_lock_zookeeper.json index 5f77776fbd..ac6cde3482 100644 --- a/configs/config_lock_zookeeper.json +++ b/configs/config_lock_zookeeper.json @@ -22,12 +22,14 @@ "server_name": "runtime", "grpc_config": { "hellos": { - "helloworld": { + "quick_start_demo": { + "type": "helloworld", "hello": "greeting" } }, "lock": { - "zookeeper": { + "lock_demo": { + "type": "zookeeper", "metadata": { "zookeeperHosts": "127.0.0.1", "zookeeperPassword": "", diff --git a/configs/config_redis.json b/configs/config_redis.json index 4ab1a2a701..c4db395101 100644 --- a/configs/config_redis.json +++ b/configs/config_redis.json @@ -22,12 +22,14 @@ "server_name": "runtime", "grpc_config": { "hellos": { - "helloworld": { + "quick_start_demo": { + "type": "helloworld", "hello": "greeting" } }, "state": { - "redis": { + "state_demo": { + "type": "redis", "metadata": { "redisHost": "localhost:6380", "redisPassword": "" @@ -35,7 +37,8 @@ } }, "sequencer": { - "redis": { + "sequencer_demo": { + "type": "redis", "metadata": { "redisHost": "127.0.0.1:6380", "redisPassword": "" @@ -43,7 +46,8 @@ } }, "lock": { - "redis": { + "lock_demo": { + "type": "redis", "metadata": { "redisHost": "localhost:6380", "redisPassword": "" @@ -51,7 +55,8 @@ } }, "pub_subs": { - "redis": { + "pub_subs_demo": { + "type": "redis", "metadata": { "redisHost": "localhost:6380", "redisPassword": "" diff --git a/configs/config_secret_file.json b/configs/config_secret_file.json index bb67cff9c4..b734e26cf6 100644 --- a/configs/config_secret_file.json +++ b/configs/config_secret_file.json @@ -22,17 +22,20 @@ "server_name": "runtime", "grpc_config": { "hellos": { - "helloworld": { + "quick_start_demo": { + "type": "helloworld", "hello": "greeting" } }, "secret_store": { - "local.file": { + "secret_demo": { + "type": "local.file", "metadata": { "secretsFile": "../../configs/secret/config_secret_local_file.json" } }, - "local.env": { + "secret_demo1": { + "type": "local.env", "metadata": { } } @@ -76,3 +79,4 @@ } ] } + diff --git a/configs/config_sequencer_etcd.json b/configs/config_sequencer_etcd.json index 3a18b91536..7ebcaf4dee 100644 --- a/configs/config_sequencer_etcd.json +++ b/configs/config_sequencer_etcd.json @@ -22,12 +22,14 @@ "server_name": "runtime", "grpc_config": { "hellos": { - "helloworld": { + "quick_start_demo": { + "type": "helloworld", "hello": "greeting" } }, "sequencer": { - "etcd": { + "sequencer_demo": { + "type": "etcd", "metadata": { "endpoints": "localhost:2379", "segmentCacheEnable": "false", diff --git a/configs/config_sequencer_mongo.json b/configs/config_sequencer_mongo.json index 9e20e4e1bc..beb5b984b9 100644 --- a/configs/config_sequencer_mongo.json +++ b/configs/config_sequencer_mongo.json @@ -22,12 +22,14 @@ "server_name": "runtime", "grpc_config": { "hellos": { - "helloworld": { + "quick_start_demo": { + "type": "helloworld", "hello": "greeting" } }, "sequencer": { - "mongo": { + "sequencer_demo": { + "type": "mongo", "metadata": { "mongoHost": "localhost:27017", "mongoPassword": "", diff --git a/configs/config_sequencer_redis.json b/configs/config_sequencer_redis.json index 61bd6f9741..332cbd92a6 100644 --- a/configs/config_sequencer_redis.json +++ b/configs/config_sequencer_redis.json @@ -22,12 +22,14 @@ "server_name": "runtime", "grpc_config": { "hellos": { - "helloworld": { + "quick_start_demo": { + "type": "helloworld", "hello": "greeting" } }, "sequencer": { - "redis": { + "sequencer_demo": { + "type": "redis", "metadata": { "redisHost": "127.0.0.1:6379", "redisPassword": "" diff --git a/configs/config_sequencer_zookeeper.json b/configs/config_sequencer_zookeeper.json index 3b63b5fdfe..9018b515ee 100644 --- a/configs/config_sequencer_zookeeper.json +++ b/configs/config_sequencer_zookeeper.json @@ -22,12 +22,14 @@ "server_name": "runtime", "grpc_config": { "hellos": { - "helloworld": { + "quick_start_demo": { + "type": "helloworld", "hello": "greeting" } }, "sequencer": { - "zookeeper": { + "sequencer_demo": { + "type": "zookeeper", "metadata": { "zookeeperHosts": "127.0.0.1", "zookeeperPassword": "", diff --git a/configs/config_state_redis.json b/configs/config_state_redis.json index 71b8f8fc87..f6eace10bb 100644 --- a/configs/config_state_redis.json +++ b/configs/config_state_redis.json @@ -34,12 +34,14 @@ "server_name": "runtime", "grpc_config": { "hellos": { - "helloworld": { + "quick_start_demo": { + "type": "helloworld", "hello": "greeting" } }, "state": { - "redis": { + "state_demo": { + "type": "redis", "metadata": { "redisHost": "localhost:6380", "redisPassword": "" diff --git a/configs/config_trace_skywalking.json b/configs/config_trace_skywalking.json index 458d185f8f..e72c875bed 100644 --- a/configs/config_trace_skywalking.json +++ b/configs/config_trace_skywalking.json @@ -17,12 +17,14 @@ "server_name": "runtime", "grpc_config": { "hellos": { - "helloworld": { + "quick_start_demo": { + "type": "helloworld", "hello": "greeting" } }, "config_store": { - "etcd": { + "config_demo": { + "type": "etcd", "address": [ "127.0.0.1:2379" ], diff --git a/configs/integrate_config.json b/configs/integrate_config.json index 91cdd53512..b0538337b0 100644 --- a/configs/integrate_config.json +++ b/configs/integrate_config.json @@ -17,12 +17,14 @@ "server_name": "runtime", "grpc_config": { "hellos": { - "helloworld": { + "quick_start_demo": { + "type": "helloworld", "hello": "welcome layotto" } }, "state": { - "redis": { + "state_demo": { + "type": "redis", "metadata": { "redisHost": "localhost:6379", "redisPassword": "" @@ -30,7 +32,8 @@ } }, "lock": { - "redis": { + "lock_demo": { + "type": "redis", "metadata": { "redisHost": "localhost:6379", "redisPassword": "" @@ -38,7 +41,8 @@ } }, "sequencer": { - "redis": { + "sequencer_demo": { + "type": "redis", "metadata": { "redisHost": "127.0.0.1:6379", "redisPassword": "" diff --git a/configs/runtime_config.json b/configs/runtime_config.json index ab2b50b79f..c778efe4aa 100644 --- a/configs/runtime_config.json +++ b/configs/runtime_config.json @@ -17,12 +17,14 @@ "server_name": "runtime", "grpc_config": { "hellos": { - "helloworld": { + "quick_start_demo": { + "type": "helloworld", "hello": "greeting" } }, "config_store": { - "etcd": { + "config_demo": { + "type": "etcd", "address": [ "127.0.0.1:2379" ], diff --git a/demo/bindings/main.go b/demo/bindings/main.go index ccdaa1e166..05e667ac2c 100644 --- a/demo/bindings/main.go +++ b/demo/bindings/main.go @@ -19,7 +19,7 @@ func main() { c := runtimev1pb.NewRuntimeClient(conn) metaData := make(map[string]string) metaData["token"] = "123" - req := &runtimev1pb.InvokeBindingRequest{Name: "http", Operation: "get", Metadata: metaData, Data: []byte("auth data")} + req := &runtimev1pb.InvokeBindingRequest{Name: "bindings_demo", Operation: "get", Metadata: metaData, Data: []byte("auth data")} resp, err := c.InvokeBinding(context.Background(), req) if err != nil { fmt.Printf("get file error: %+v", err) diff --git a/demo/faas/code/assemblyscript/assembly/server.ts b/demo/faas/code/assemblyscript/assembly/server.ts index 4fe9f12589..7eabb66e84 100644 --- a/demo/faas/code/assemblyscript/assembly/server.ts +++ b/demo/faas/code/assemblyscript/assembly/server.ts @@ -24,7 +24,7 @@ class ServerHttpContext extends Context { onRequestBody(body_buffer_length: usize, _end_of_stream: bool): FilterDataStatusValues { let name = String.UTF8.decode(get_buffer_bytes(BufferTypeValues.HttpRequestBody, 0, body_buffer_length as u32)); - set_http_response_body(String.UTF8.decode(getState("redis", name))); + set_http_response_body(String.UTF8.decode(getState("state_demo", name))); return FilterDataStatusValues.Continue } } diff --git a/demo/faas/code/golang/server/function.go b/demo/faas/code/golang/server/function.go index 4364778e96..5cbb031fe6 100644 --- a/demo/faas/code/golang/server/function.go +++ b/demo/faas/code/golang/server/function.go @@ -65,7 +65,7 @@ func (ctx *httpHeaders) OnHttpRequestBody(bodySize int, endOfStream bool) types. bookName := string(body) //2. get request state from redis by specific key through ABI - inventories, err := proxywasm.GetState("redis", bookName) + inventories, err := proxywasm.GetState("state_demo", bookName) if err != nil { proxywasm.LogErrorf("GetState failed: %v", err) return types.ActionPause diff --git a/demo/faas/code/golang/server/function_2.wasm b/demo/faas/code/golang/server/function_2.wasm index a735a0d35f..b81560d059 100755 Binary files a/demo/faas/code/golang/server/function_2.wasm and b/demo/faas/code/golang/server/function_2.wasm differ diff --git a/demo/faas/code/rust/server/src/lib.rs b/demo/faas/code/rust/server/src/lib.rs index 3f0de58170..3a131cd917 100644 --- a/demo/faas/code/rust/server/src/lib.rs +++ b/demo/faas/code/rust/server/src/lib.rs @@ -34,7 +34,7 @@ impl HttpContext for ServerHttpContext { None => None, }); match book_name { - Some(book_name) => match get_state("redis", &book_name) { + Some(book_name) => match get_state("state_demo", &book_name) { Ok(response) => { let response = response.unwrap_or(vec![]); set_buffer(BufferType::HttpResponseBody, 0, &response).unwrap(); diff --git a/demo/faas/config.json b/demo/faas/config.json index d48f22f5c9..376538ef31 100644 --- a/demo/faas/config.json +++ b/demo/faas/config.json @@ -26,7 +26,8 @@ } }, "state": { - "redis": { + "state_demo": { + "type": "redis", "metadata": { "redisHost": "localhost:6379", "redisPassword": "" diff --git a/demo/file/client.go b/demo/file/client.go index d34ceacc99..e89de29314 100644 --- a/demo/file/client.go +++ b/demo/file/client.go @@ -18,6 +18,10 @@ import ( "google.golang.org/grpc" ) +const ( + storeName = "file_demo" +) + func TestGet(fileName string) { conn, err := grpc.Dial("127.0.0.1:34904", grpc.WithInsecure()) if err != nil { @@ -26,7 +30,7 @@ func TestGet(fileName string) { } c := runtimev1pb.NewRuntimeClient(conn) - req := &runtimev1pb.GetFileRequest{StoreName: "minioOSS", Name: fileName} + req := &runtimev1pb.GetFileRequest{StoreName: storeName, Name: fileName} cli, err := c.GetFile(context.Background(), req) if err != nil { fmt.Printf("get file error: %+v", err) @@ -53,7 +57,7 @@ func TestPut(fileName string, value string) { meta := make(map[string]string) meta["storageType"] = "Standard" c := runtimev1pb.NewRuntimeClient(conn) - req := &runtimev1pb.PutFileRequest{StoreName: "minioOSS", Name: fileName, Metadata: meta} + req := &runtimev1pb.PutFileRequest{StoreName: storeName, Name: fileName, Metadata: meta} stream, err := c.PutFile(context.TODO()) if err != nil { fmt.Printf("put file failed:%+v", err) @@ -78,7 +82,7 @@ func TestList(bucketName string) { c := runtimev1pb.NewRuntimeClient(conn) marker := "" for { - req := &runtimev1pb.FileRequest{StoreName: "minioOSS", Name: bucketName, Metadata: meta} + req := &runtimev1pb.FileRequest{StoreName: storeName, Name: bucketName, Metadata: meta} listReq := &runtimev1pb.ListFileRequest{Request: req, PageSize: 2, Marker: marker} resp, err := c.ListFile(context.Background(), listReq) if err != nil { @@ -105,7 +109,7 @@ func TestDel(fileName string) { meta := make(map[string]string) meta["storageType"] = "Standard" c := runtimev1pb.NewRuntimeClient(conn) - req := &runtimev1pb.FileRequest{StoreName: "minioOSS", Name: fileName, Metadata: meta} + req := &runtimev1pb.FileRequest{StoreName: storeName, Name: fileName, Metadata: meta} listReq := &runtimev1pb.DelFileRequest{Request: req} _, err = c.DelFile(context.Background(), listReq) if err != nil { @@ -124,7 +128,7 @@ func TestStat(fileName string) { meta := make(map[string]string) meta["storageType"] = "Standard" c := runtimev1pb.NewRuntimeClient(conn) - req := &runtimev1pb.FileRequest{StoreName: "minioOSS", Name: fileName, Metadata: meta} + req := &runtimev1pb.FileRequest{StoreName: storeName, Name: fileName, Metadata: meta} statReq := &runtimev1pb.GetFileMetaRequest{Request: req} data, err := c.GetFileMeta(context.Background(), statReq) //here use grpc error code check file exist or not. diff --git a/demo/file/qiniu/client.go b/demo/file/qiniu/client.go index 8cdf862e92..c9f7867749 100644 --- a/demo/file/qiniu/client.go +++ b/demo/file/qiniu/client.go @@ -31,6 +31,10 @@ import ( "google.golang.org/grpc" ) +const ( + storeName = "file_demo" +) + func TestGet(fileName string) { conn, err := grpc.Dial("127.0.0.1:34904", grpc.WithInsecure()) if err != nil { @@ -39,7 +43,7 @@ func TestGet(fileName string) { } c := runtimev1pb.NewRuntimeClient(conn) - req := &runtimev1pb.GetFileRequest{StoreName: "qiniuOSS", Name: fileName} + req := &runtimev1pb.GetFileRequest{StoreName: storeName, Name: fileName} cli, err := c.GetFile(context.Background(), req) if err != nil { fmt.Printf("get file error: %+v", err) @@ -67,7 +71,7 @@ func TestPut(fileName string, value string) { c := runtimev1pb.NewRuntimeClient(conn) data := []byte(value) meta["filesize"] = strconv.Itoa(len(data)) - req := &runtimev1pb.PutFileRequest{StoreName: "qiniuOSS", Name: fileName, Metadata: meta} + req := &runtimev1pb.PutFileRequest{StoreName: storeName, Name: fileName, Metadata: meta} stream, err := c.PutFile(context.TODO()) if err != nil { fmt.Printf("put file failed:%+v", err) @@ -92,7 +96,7 @@ func TestList(bucketName string) { c := runtimev1pb.NewRuntimeClient(conn) marker := "" for { - req := &runtimev1pb.FileRequest{StoreName: "qiniuOSS", Name: bucketName, Metadata: meta} + req := &runtimev1pb.FileRequest{StoreName: storeName, Name: bucketName, Metadata: meta} listReq := &runtimev1pb.ListFileRequest{Request: req, PageSize: 1, Marker: marker} resp, err := c.ListFile(context.Background(), listReq) if err != nil { @@ -119,7 +123,7 @@ func TestDel(fileName string) { meta := make(map[string]string) meta["storageType"] = "Standard" c := runtimev1pb.NewRuntimeClient(conn) - req := &runtimev1pb.FileRequest{StoreName: "qiniuOSS", Name: fileName, Metadata: meta} + req := &runtimev1pb.FileRequest{StoreName: storeName, Name: fileName, Metadata: meta} listReq := &runtimev1pb.DelFileRequest{Request: req} _, err = c.DelFile(context.Background(), listReq) if err != nil { @@ -138,7 +142,7 @@ func TestStat(fileName string) { meta := make(map[string]string) meta["storageType"] = "Standard" c := runtimev1pb.NewRuntimeClient(conn) - req := &runtimev1pb.FileRequest{StoreName: "qiniuOSS", Name: fileName, Metadata: meta} + req := &runtimev1pb.FileRequest{StoreName: storeName, Name: fileName, Metadata: meta} statReq := &runtimev1pb.GetFileMetaRequest{Request: req} data, err := c.GetFileMeta(context.Background(), statReq) //here use grpc error code check file exist or not. diff --git a/demo/file/stressmem.go b/demo/file/stressmem.go index 269b830d8b..b37e0434f8 100644 --- a/demo/file/stressmem.go +++ b/demo/file/stressmem.go @@ -13,6 +13,10 @@ import ( runtimev1pb "mosn.io/layotto/spec/proto/runtime/v1" ) +const ( + storeName1 = "file_demo" +) + func GetFile(wg *sync.WaitGroup, id int) { defer wg.Done() conn, err := grpc.Dial("127.0.0.1:34904", grpc.WithInsecure()) @@ -21,7 +25,7 @@ func GetFile(wg *sync.WaitGroup, id int) { return } c := runtimev1pb.NewRuntimeClient(conn) - req := &runtimev1pb.GetFileRequest{StoreName: "aliOSS", Name: "fileName"} + req := &runtimev1pb.GetFileRequest{StoreName: storeName1, Name: "fileName"} cli, err := c.GetFile(context.Background(), req) if err != nil { fmt.Printf("get file error: %+v", err) @@ -50,7 +54,7 @@ func PutFile(wg *sync.WaitGroup, id int) { meta := make(map[string]string) meta["storageType"] = "Standard" c := runtimev1pb.NewRuntimeClient(conn) - req := &runtimev1pb.PutFileRequest{StoreName: "aliOSS", Name: "fileName", Metadata: meta} + req := &runtimev1pb.PutFileRequest{StoreName: storeName1, Name: "fileName", Metadata: meta} stream, err := c.PutFile(context.TODO()) if err != nil { fmt.Printf("put file failed:%+v", err) diff --git a/demo/file/tencentcloud/client.go b/demo/file/tencentcloud/client.go index b5f0e7720b..05cd257f55 100644 --- a/demo/file/tencentcloud/client.go +++ b/demo/file/tencentcloud/client.go @@ -30,6 +30,10 @@ import ( "google.golang.org/grpc" ) +const ( + storeName = "file_demo" +) + func TestGet(fileName string) { conn, err := grpc.Dial("127.0.0.1:34904", grpc.WithInsecure()) if err != nil { @@ -38,7 +42,7 @@ func TestGet(fileName string) { } c := runtimev1pb.NewRuntimeClient(conn) - req := &runtimev1pb.GetFileRequest{StoreName: "tencentCloudOSS", Name: fileName} + req := &runtimev1pb.GetFileRequest{StoreName: storeName, Name: fileName} cli, err := c.GetFile(context.Background(), req) if err != nil { fmt.Printf("get file error: %+v", err) @@ -64,7 +68,7 @@ func TestPut(fileName string, value string) { } meta := make(map[string]string) c := runtimev1pb.NewRuntimeClient(conn) - req := &runtimev1pb.PutFileRequest{StoreName: "tencentCloudOSS", Name: fileName, Metadata: meta} + req := &runtimev1pb.PutFileRequest{StoreName: storeName, Name: fileName, Metadata: meta} stream, err := c.PutFile(context.TODO()) if err != nil { fmt.Printf("put file failed:%+v", err) @@ -89,7 +93,7 @@ func TestList(bucketName string) { c := runtimev1pb.NewRuntimeClient(conn) marker := "" for { - req := &runtimev1pb.FileRequest{StoreName: "tencentCloudOSS", Name: bucketName, Metadata: meta} + req := &runtimev1pb.FileRequest{StoreName: storeName, Name: bucketName, Metadata: meta} listReq := &runtimev1pb.ListFileRequest{Request: req, PageSize: 1, Marker: marker} resp, err := c.ListFile(context.Background(), listReq) if err != nil { @@ -116,7 +120,7 @@ func TestDel(fileName string) { meta := make(map[string]string) meta["storageType"] = "Standard" c := runtimev1pb.NewRuntimeClient(conn) - req := &runtimev1pb.FileRequest{StoreName: "tencentCloudOSS", Name: fileName, Metadata: meta} + req := &runtimev1pb.FileRequest{StoreName: storeName, Name: fileName, Metadata: meta} listReq := &runtimev1pb.DelFileRequest{Request: req} _, err = c.DelFile(context.Background(), listReq) if err != nil { @@ -135,7 +139,7 @@ func TestStat(fileName string) { meta := make(map[string]string) meta["storageType"] = "Standard" c := runtimev1pb.NewRuntimeClient(conn) - req := &runtimev1pb.FileRequest{StoreName: "tencentCloudOSS", Name: fileName, Metadata: meta} + req := &runtimev1pb.FileRequest{StoreName: storeName, Name: fileName, Metadata: meta} statReq := &runtimev1pb.GetFileMetaRequest{Request: req} data, err := c.GetFileMeta(context.Background(), statReq) //here use grpc error code check file exist or not. diff --git a/demo/flowcontrol/client.go b/demo/flowcontrol/client.go index cedbe99f97..f4c881c007 100644 --- a/demo/flowcontrol/client.go +++ b/demo/flowcontrol/client.go @@ -36,7 +36,7 @@ func main() { for i := 0; i < 10; i++ { r, err := c.SayHello(context.Background(), &runtimev1pb.SayHelloRequest{ - ServiceName: "helloworld", + ServiceName: "quick_start_demo", }) if err != nil { fmt.Println("get an error: ", err) diff --git a/demo/go.mod b/demo/go.mod index 109a79ee5a..549c6bb140 100644 --- a/demo/go.mod +++ b/demo/go.mod @@ -3,12 +3,12 @@ module mosn.io/layotto/demo go 1.14 require ( - github.com/golang/protobuf v1.5.0 - github.com/google/uuid v1.2.0 + github.com/golang/protobuf v1.5.2 + github.com/google/uuid v1.3.0 github.com/minio/minio-go/v7 v7.0.15 github.com/tetratelabs/proxy-wasm-go-sdk v0.14.1-0.20210922004205-46e3ac3a25fe - google.golang.org/grpc v1.37.0 - google.golang.org/protobuf v1.26.0-rc.1 + google.golang.org/grpc v1.38.0 + google.golang.org/protobuf v1.26.0 mosn.io/layotto/sdk/go-sdk v0.0.0-20211020084508-6f5ee3cfeba0 mosn.io/layotto/spec v0.0.0-20211020084508-6f5ee3cfeba0 ) diff --git a/demo/go.sum b/demo/go.sum index 1bbc5afdef..31f0a75b75 100644 --- a/demo/go.sum +++ b/demo/go.sum @@ -23,8 +23,9 @@ github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:W github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.5.0 h1:LUVKkCeviFUMKqHa4tXIIij/lbhnMbP7Fn5wKdKkRh4= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= @@ -35,8 +36,8 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.2.0 h1:qJYtXnJRWmpe7m/3XlyhrsLrEURqHRM2kxzoxXqyUDs= -github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= +github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/json-iterator/go v1.1.10 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr68= @@ -137,8 +138,9 @@ google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZi google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.37.0 h1:uSZWeQJX5j11bIQ4AJoj+McDBo29cY1MCoC1wO3ts+c= google.golang.org/grpc v1.37.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= +google.golang.org/grpc v1.38.0 h1:/9BgsAsa5nWe26HqOlvlgJnqBuktYOLCgjCPqsa56W0= +google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= @@ -148,8 +150,9 @@ google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2 google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= -google.golang.org/protobuf v1.26.0-rc.1 h1:7QnIQpGRHE5RnLKnESfDoxm2dTapTZua5a0kS0A+VXQ= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/demo/lock/consul/client.go b/demo/lock/consul/client.go index 471ce3344f..5c5e5ed0de 100644 --- a/demo/lock/consul/client.go +++ b/demo/lock/consul/client.go @@ -13,7 +13,7 @@ import ( const ( resourceId = "resource_a" - storeName = "consul" + storeName = "lock_demo" ) func main() { diff --git a/demo/lock/etcd/client.go b/demo/lock/etcd/client.go index 9c9b7c1ab0..5c5e5ed0de 100644 --- a/demo/lock/etcd/client.go +++ b/demo/lock/etcd/client.go @@ -13,7 +13,7 @@ import ( const ( resourceId = "resource_a" - storeName = "etcd" + storeName = "lock_demo" ) func main() { diff --git a/demo/lock/in-memory/client.go b/demo/lock/in-memory/client.go index a7bf70fbd6..a7c05bc645 100644 --- a/demo/lock/in-memory/client.go +++ b/demo/lock/in-memory/client.go @@ -13,7 +13,7 @@ import ( const ( resourceId = "resource_a" - storeName = "in-memory" + storeName = "lock_demo" ) func main() { diff --git a/demo/lock/mongo/client.go b/demo/lock/mongo/client.go index 18fe04849f..e797451c39 100644 --- a/demo/lock/mongo/client.go +++ b/demo/lock/mongo/client.go @@ -13,7 +13,7 @@ import ( const ( resourceId = "resource_a" - storeName = "mongo" + storeName = "lock_demo" ) func main() { diff --git a/demo/lock/redis/client.go b/demo/lock/redis/client.go index 598bf4ad85..5c5e5ed0de 100644 --- a/demo/lock/redis/client.go +++ b/demo/lock/redis/client.go @@ -13,7 +13,7 @@ import ( const ( resourceId = "resource_a" - storeName = "redis" + storeName = "lock_demo" ) func main() { diff --git a/demo/lock/redis/redis_cluster/client_cluster_lock.go b/demo/lock/redis/redis_cluster/client_cluster_lock.go index aab63361d5..64c53b161e 100644 --- a/demo/lock/redis/redis_cluster/client_cluster_lock.go +++ b/demo/lock/redis/redis_cluster/client_cluster_lock.go @@ -13,7 +13,7 @@ import ( const ( resourceId = "resource_a" - storeName = "redis_cluster" + storeName = "lock_demo" ) func main() { diff --git a/demo/lock/zookeeper/client.go b/demo/lock/zookeeper/client.go index 754f53683f..7c38ab9519 100644 --- a/demo/lock/zookeeper/client.go +++ b/demo/lock/zookeeper/client.go @@ -13,7 +13,7 @@ import ( const ( resourceId = "resource_a" - storeName = "zookeeper" + storeName = "zookeeper_demo" ) func main() { diff --git a/demo/pubsub/redis/client/publish_client.go b/demo/pubsub/redis/client/publish_client.go index d1e84b014c..f0760baaa9 100644 --- a/demo/pubsub/redis/client/publish_client.go +++ b/demo/pubsub/redis/client/publish_client.go @@ -38,7 +38,7 @@ func main() { func testPublish(cli client.Client) error { data := []byte("value1") - err := cli.PublishEvent(context.Background(), "redis", topicName, data) + err := cli.PublishEvent(context.Background(), "pub_subs_demo", topicName, data) if err != nil { panic(err) } diff --git a/demo/pubsub/redis/server/subscribe_server.go b/demo/pubsub/redis/server/subscribe_server.go index 36796bca65..38d054891c 100644 --- a/demo/pubsub/redis/server/subscribe_server.go +++ b/demo/pubsub/redis/server/subscribe_server.go @@ -56,7 +56,7 @@ type AppCallbackServerImpl struct { func (a *AppCallbackServerImpl) ListTopicSubscriptions(ctx context.Context, empty *empty.Empty) (*runtimev1pb.ListTopicSubscriptionsResponse, error) { result := &runtimev1pb.ListTopicSubscriptionsResponse{} ts := &runtimev1pb.TopicSubscription{ - PubsubName: "redis", + PubsubName: "pub_subs_demo", Topic: topicName, Metadata: nil, } diff --git a/demo/secret/common/client.go b/demo/secret/common/client.go index 5db14ff5fb..a96832a951 100644 --- a/demo/secret/common/client.go +++ b/demo/secret/common/client.go @@ -6,7 +6,6 @@ import ( "fmt" "mosn.io/layotto/sdk/go-sdk/client" - runtimev1pb "mosn.io/layotto/spec/proto/runtime/v1" ) diff --git a/demo/sequencer/common/client.go b/demo/sequencer/common/client.go index 14c93a2258..1ef3c04c09 100644 --- a/demo/sequencer/common/client.go +++ b/demo/sequencer/common/client.go @@ -1,3 +1,19 @@ +/* + * Copyright 2021 Layotto Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package main import ( @@ -40,8 +56,7 @@ func main() { Metadata: nil, }) if err != nil { - fmt.Print(err) - return + panic(err) } fmt.Printf("Next id:%v \n", id) } diff --git a/docs/en/component_specs/lock/common.md b/docs/en/component_specs/lock/common.md index cb8a3dda53..115971905c 100644 --- a/docs/en/component_specs/lock/common.md +++ b/docs/en/component_specs/lock/common.md @@ -4,7 +4,15 @@ The json configuration file has the following structure: ```json "lock": { - "": { + "": { + "type":"", + "metadata": { + "": "", + "": "" + } + }, + "": { + "type":"", "metadata": { "": "", "": "" @@ -16,7 +24,8 @@ You can configure the key/value configuration items that the component cares abo ```json "lock": { - "redis": { + "lock_demo": { + "type": "redis", "metadata": { "redisHost": "localhost:6380", "redisPassword": "" diff --git a/docs/en/component_specs/pubsub/common.md b/docs/en/component_specs/pubsub/common.md index 31cecd5b07..058e265f61 100644 --- a/docs/en/component_specs/pubsub/common.md +++ b/docs/en/component_specs/pubsub/common.md @@ -4,7 +4,15 @@ The json configuration file has the following structure: ```json "pub_subs": { - "": { + "": { + "type":"", + "metadata": { + "": "", + "": "" + } + }, + "": { + "type":"", "metadata": { "": "", "": "" @@ -16,7 +24,8 @@ You can configure the key/value configuration items that the component cares abo ```json "pub_subs": { - "redis": { + "pubsub_dmoe": { + "type": "redis", "metadata": { "redisHost": "localhost:6380", "redisPassword": "" diff --git a/docs/en/component_specs/secret/common.md b/docs/en/component_specs/secret/common.md index 43081de715..e6c5600232 100644 --- a/docs/en/component_specs/secret/common.md +++ b/docs/en/component_specs/secret/common.md @@ -5,29 +5,40 @@ This component can access secrets from local files, environment variables, k8s, The json configuration file has the following structure: ```json "secret_store": { - "": { - "metadata": { - "": "", - "": "" + "": { + "type":"", + "metadata": { + "": "", + "": "" + } + }, + "": { + "type":"", + "metadata": { + "": "", + "": "" + } } - } } ``` Configuration examples of local file keys, local environment variables, and k8s keys: -``` +```json "secret_store": { - "local.file": { + "secret_demo": { + "type": "local.file", "metadata": { "secretsFile": "../../configs/config_secret_local_file.json" } }, - "local.env": { + "secret_demo1": { + "type": "local.env", "metadata": { } }, - "kubernetes": { + "secret_demo2": { + "type": "kubernetes", "metadata": { } } - } +} ``` \ No newline at end of file diff --git a/docs/en/component_specs/sequencer/common.md b/docs/en/component_specs/sequencer/common.md index c079902508..f899713b4f 100644 --- a/docs/en/component_specs/sequencer/common.md +++ b/docs/en/component_specs/sequencer/common.md @@ -4,7 +4,19 @@ The json configuration file has the following structure: ```json "sequencer": { - "": { + "": { + "type": "Component A Name", + "biggerThan": { + "": "", + "": "" + }, + "metadata": { + "": "", + "": "" + } + }, + "": { + "type": "Component B Name", "biggerThan": { "": "", "": "" @@ -21,7 +33,8 @@ You can configure the key/value configuration items that the component cares abo ```json "sequencer": { - "etcd": { + "sequencer_demo": { + "type": "etcd", "biggerThan": { "key1": 1, "key2": 111 diff --git a/docs/en/component_specs/sequencer/etcd.md b/docs/en/component_specs/sequencer/etcd.md index e2022d90f8..afbbc4811b 100644 --- a/docs/en/component_specs/sequencer/etcd.md +++ b/docs/en/component_specs/sequencer/etcd.md @@ -46,6 +46,6 @@ Execute after the compilation is successful: ````shell cd ${project_path}/demo/sequencer/etcd/ go build -o client - ./client -s "etcd" + ./client -s "sequencer_demo" ```` diff --git a/docs/en/component_specs/state/common.md b/docs/en/component_specs/state/common.md index ac53c52a8a..f880372c34 100644 --- a/docs/en/component_specs/state/common.md +++ b/docs/en/component_specs/state/common.md @@ -4,19 +4,28 @@ The json configuration file has the following structure: ```json "state": { - "": { - "metadata": { - "": "", - "": "" + "": { + "type":"", + "metadata": { + "": "", + "": "" + } + }, + "": { + "type":"", + "metadata": { + "": "", + "": "" + } } - } } ``` You can configure the key/value configuration items that the component cares about in the metadata. For example, [redis component configuration](https://github.com/mosn/layotto/blob/main/configs/config_state_redis.json) is as follows: ```json "state": { - "redis": { + "state_demo": { + "type": "redis", "metadata": { "redisHost": "localhost:6380", "redisPassword": "" diff --git a/docs/en/configuration/overview.md b/docs/en/configuration/overview.md index e655d2882d..a6211878ed 100644 --- a/docs/en/configuration/overview.md +++ b/docs/en/configuration/overview.md @@ -14,7 +14,8 @@ The configuration item in `grpc_config` is Layotto's component configuration, th ```json "grpc_config": { "": { - "": { + "": { + "type": "" "": "", "metadata": { "": "", @@ -23,16 +24,16 @@ The configuration item in `grpc_config` is Layotto's component configuration, th } }, "": { - "": { + "": { + "type": "" "": "", "metadata": { "": "", "": "" } } - } + }, } - ``` As for what to fill in each ``, what is each ``, and which `"": ""` configuration items can be configured with the components, you can refer to [Component specs](en/component_specs/overview) . diff --git a/docs/en/design/configuration/configuration-api-with-apollo.md b/docs/en/design/configuration/configuration-api-with-apollo.md index ca0334c783..9300014a5f 100644 --- a/docs/en/design/configuration/configuration-api-with-apollo.md +++ b/docs/en/design/configuration/configuration-api-with-apollo.md @@ -51,7 +51,8 @@ A: Legacy systems using apollo can't migrate to our sidecar if we design like th ### config.json for sidecar ```json { - "apollo": { + "config_store": { + "type": "apollo", "address": [ "http://106.54.227.205:8080" ], diff --git a/docs/en/start/configuration/start-apollo.md b/docs/en/start/configuration/start-apollo.md index e06574d994..2c99a4cac2 100644 --- a/docs/en/start/configuration/start-apollo.md +++ b/docs/en/start/configuration/start-apollo.md @@ -53,7 +53,7 @@ The client demo calls Layotto to add, delete, modify, and query configuration ``` ```shell - ./client -s "apollo" + ./client -s "config_demo" ``` If the following information is printed, the call is successful: @@ -64,7 +64,7 @@ get configuration after save, &{Key:key1 Content:value1 Group:application Label: get configuration after save, &{Key:haha Content:heihei Group:application Label:prod Tags:map[feature:haha release:1.0.0] Metadata:map[]} delete keys success write start -receive subscribe resp store_name:"apollo" app_id:"apollo" items: tags: > +receive subscribe resp store_name:"config_demo" app_id:"apollo" items: tags: > ``` ### Next step diff --git a/docs/en/start/configuration/start.md b/docs/en/start/configuration/start.md index d40d883458..1b187b7be8 100644 --- a/docs/en/start/configuration/start.md +++ b/docs/en/start/configuration/start.md @@ -47,7 +47,7 @@ Run it: ``` ```shell - ./client -s "etcd" + ./client -s "config_demo" ``` If the following information is printed out, it means the client app has done all the CRUD operations successfully: @@ -58,7 +58,7 @@ get configuration after save, &{Key:key1 Content:value1 Group:application Label: get configuration after save, &{Key:haha Content:heihei Group:application Label:prod Tags:map[feature:haha release:1.0.0] Metadata:map[]} delete keys success write start -receive subscribe resp store_name:"apollo" app_id:"apollo" items: tags: > +receive subscribe resp store_name:"config_demo" app_id:"apollo" items: tags: > ``` ## Next step diff --git a/docs/en/start/secret/start.md b/docs/en/start/secret/start.md index da88d706ef..919c013623 100644 --- a/docs/en/start/secret/start.md +++ b/docs/en/start/secret/start.md @@ -39,7 +39,7 @@ Once finished, the layotto file will be generated in the directory, run it: ``` ```shell - ./client -s "local.file" + ./client -s "secret_demo" ``` If the following information is printed, the demo is successful: diff --git a/docs/en/start/sequencer/start.md b/docs/en/start/sequencer/start.md index 58ca3e6923..63f3508370 100644 --- a/docs/en/start/sequencer/start.md +++ b/docs/en/start/sequencer/start.md @@ -50,7 +50,7 @@ Once finished, the layotto file will be generated in the directory, run it: ```shell cd ${project_path}/demo/sequencer/common/ go build -o client - ./client -s "etcd" + ./client -s "sequencer_demo" ``` If the following information is printed, the demo is successful: diff --git a/docs/en/start/state/start.md b/docs/en/start/state/start.md index c2e0179960..133d8227ce 100644 --- a/docs/en/start/state/start.md +++ b/docs/en/start/state/start.md @@ -68,7 +68,7 @@ The layotto file will be generated in the directory, run it: # change directory to ${your project path}/demo/state/common/ cd ${project_path}/demo/state/common/ go build -o client - ./client -s "redis" + ./client -s "state_demo" ``` If the following information is printed, the demo succeeded: diff --git a/docs/zh/component_specs/custom/common.md b/docs/zh/component_specs/custom/common.md index dfc96bf786..9481eeb498 100644 --- a/docs/zh/component_specs/custom/common.md +++ b/docs/zh/component_specs/custom/common.md @@ -13,14 +13,16 @@ Layotto 中的组件分为两种: ## 配置文件结构 ```json "custom_component": { - "": { + "": { "": { + "type":"", "metadata": { "": "", "": "" } }, "": { + "type":"", "metadata": { "": "", "": "" @@ -33,12 +35,13 @@ Layotto 中的组件分为两种: 您可以在metadata里配置组件关心的key/value配置。 ## 示例 -例如,在`configs/config_in_memory.json` 中,配置了类型是`helloworld` 的 `CustomComponent`,只有一个组件,其组件名是 `in-memory`: +例如,在`configs/config_in_memory.json` 中,配置了 kind 是`helloworld` 的 `CustomComponent`,只有一个组件,其组件名是 `demo`, type 是 `in-memory`: ```json "custom_component": { "helloworld": { - "in-memory": { + "demo": { + "type":"in-memory", "metadata": {} } } diff --git a/docs/zh/component_specs/file/common.md b/docs/zh/component_specs/file/common.md index c8e6f8dda7..a202a0bf30 100644 --- a/docs/zh/component_specs/file/common.md +++ b/docs/zh/component_specs/file/common.md @@ -6,7 +6,8 @@ json配置文件有如下结构: ```json "file": { - "aliOSS": { + "file_demo": { + "type": "aliOSS" "metadata":[ { "endpoint": "endpoint_address", @@ -26,6 +27,7 @@ json配置文件有如下结构: ```golang type FileConfig struct { + Type string Metadata json.RawMessage } @@ -36,7 +38,8 @@ json配置文件有如下结构: ```json "file": { - "localFile": { + "file_demo": { + "type": "localFile", "group":{ "name": "group1" "permisson":"rwx", diff --git a/docs/zh/component_specs/lock/common.md b/docs/zh/component_specs/lock/common.md index adecb61454..cb15d5eece 100644 --- a/docs/zh/component_specs/lock/common.md +++ b/docs/zh/component_specs/lock/common.md @@ -4,7 +4,15 @@ json配置文件有如下结构: ```json "lock": { - "": { + "": { + "type":"", + "metadata": { + "": "", + "": "" + } + }, + "": { + "type":"", "metadata": { "": "", "": "" @@ -17,7 +25,8 @@ json配置文件有如下结构: ```json "lock": { - "redis": { + "lock_demo": { + "type": "redis", "metadata": { "redisHost": "localhost:6380", "redisPassword": "" diff --git a/docs/zh/component_specs/pubsub/common.md b/docs/zh/component_specs/pubsub/common.md index 18f6bee51a..7e8f65ebc5 100644 --- a/docs/zh/component_specs/pubsub/common.md +++ b/docs/zh/component_specs/pubsub/common.md @@ -4,7 +4,15 @@ json配置文件有如下结构: ```json "pub_subs": { - "": { + "": { + "type":"", + "metadata": { + "": "", + "": "" + } + }, + "": { + "type":"", "metadata": { "": "", "": "" @@ -17,7 +25,8 @@ json配置文件有如下结构: ```json "pub_subs": { - "redis": { + "pubsub_dmoe": { + "type": "redis", "metadata": { "redisHost": "localhost:6380", "redisPassword": "" diff --git a/docs/zh/component_specs/secret/common.md b/docs/zh/component_specs/secret/common.md index 66df5d6914..4740f19c8a 100644 --- a/docs/zh/component_specs/secret/common.md +++ b/docs/zh/component_specs/secret/common.md @@ -6,27 +6,38 @@ json配置文件有如下结构: ```json "secret_store": { - "": { - "metadata": { - "": "", - "": "" + "": { + "type":"", + "metadata": { + "": "", + "": "" + } + }, + "": { + "type":"", + "metadata": { + "": "", + "": "" + } } - } } ``` 本地文件秘钥、本地环境变量、k8s秘钥的配置例子: -``` +```json "secret_store": { - "local.file": { + "secret_demo": { + "type": "local.file", "metadata": { "secretsFile": "../../configs/config_secret_local_file.json" } }, - "local.env": { + "secret_demo1": { + "type": "local.env", "metadata": { } }, - "kubernetes": { + "secret_demo2": { + "type": "kubernetes", "metadata": { } } diff --git a/docs/zh/component_specs/sequencer/common.md b/docs/zh/component_specs/sequencer/common.md index 2ac1d5c459..e5308862fa 100644 --- a/docs/zh/component_specs/sequencer/common.md +++ b/docs/zh/component_specs/sequencer/common.md @@ -4,7 +4,19 @@ json配置文件有如下结构: ```json "sequencer": { - "": { + "": { + "type": "Component A Name", + "biggerThan": { + "": "", + "": "" + }, + "metadata": { + "": "", + "": "" + } + }, + "": { + "type": "Component B Name", "biggerThan": { "": "", "": "" @@ -21,7 +33,8 @@ json配置文件有如下结构: ```json "sequencer": { - "etcd": { + "sequencer_demo": { + "type": "etcd", "biggerThan": { "key1": 1, "key2": 111 diff --git a/docs/zh/component_specs/sequencer/etcd.md b/docs/zh/component_specs/sequencer/etcd.md index b4a3a7ae57..9ce8147fac 100644 --- a/docs/zh/component_specs/sequencer/etcd.md +++ b/docs/zh/component_specs/sequencer/etcd.md @@ -47,6 +47,6 @@ go build ````shell cd ${project_path}/demo/sequencer/etcd/ go build -o client - ./client -s "etcd" + ./client -s "sequencer_demo" ```` diff --git a/docs/zh/component_specs/state/common.md b/docs/zh/component_specs/state/common.md index bb307265ba..6da16cc14a 100644 --- a/docs/zh/component_specs/state/common.md +++ b/docs/zh/component_specs/state/common.md @@ -4,12 +4,20 @@ json配置文件有如下结构: ```json "state": { - "": { - "metadata": { - "": "", - "": "" + "": { + "type":"", + "metadata": { + "": "", + "": "" + } + }, + "": { + "type":"", + "metadata": { + "": "", + "": "" + } } - } } ``` @@ -17,7 +25,8 @@ json配置文件有如下结构: ```json "state": { - "redis": { + "state_demo": { + "type": "redis", "metadata": { "redisHost": "localhost:6380", "redisPassword": "" diff --git a/docs/zh/configuration/overview.md b/docs/zh/configuration/overview.md index c340cb5e5a..4549f6a174 100644 --- a/docs/zh/configuration/overview.md +++ b/docs/zh/configuration/overview.md @@ -14,7 +14,8 @@ Layotto 启动时需要读取一个 json 格式的配置文件。示例配置文 ```json "grpc_config": { "": { - "": { + "": { + "type": "" "": "", "metadata": { "": "", @@ -23,16 +24,16 @@ Layotto 启动时需要读取一个 json 格式的配置文件。示例配置文 } }, "": { - "": { + "": { + "type": "" "": "", "metadata": { "": "", "": "" } } - } + }, } - ``` 至于每个API NAME填啥、每个组件名是啥、组件能配哪些Key/Value配置项,您可以查阅[组件配置说明](zh/component_specs/overview) \ No newline at end of file diff --git a/docs/zh/design/actuator/grpc-design-doc.md b/docs/zh/design/actuator/grpc-design-doc.md index c0ed3bd5b2..0071a48987 100644 --- a/docs/zh/design/actuator/grpc-design-doc.md +++ b/docs/zh/design/actuator/grpc-design-doc.md @@ -72,12 +72,14 @@ func MyFunc(_ json.RawMessage) *grpc.Server { "server_name":"runtime", "grpc_config": { "hellos": { - "helloworld": { + "quick_start_demo": { + "type": "helloworld", "hello": "greeting" } }, "config_store": { - "etcd": { + "config_store_demo": { + "type": "etcd", "address": ["127.0.0.1:2379"], "timeout": "10" } diff --git a/docs/zh/design/api_plugin/design.md b/docs/zh/design/api_plugin/design.md index 8539badee3..7f56191253 100644 --- a/docs/zh/design/api_plugin/design.md +++ b/docs/zh/design/api_plugin/design.md @@ -223,36 +223,7 @@ Layotto 中的组件分为两种: 允许您自己扩展自己的组件,比如下面示例中的 `HelloWorld` 组件。 ##### 解释:如何配置自定义组件? -在 json 配置文件中按以下格式配置: -```json - "custom_component": { - "": { - "": { - "metadata": { - "": "", - "": "" - } - }, - "": { - "metadata": { - "": "", - "": "" - } - } - } - }, -``` - -例如,在`configs/config_in_memory.json` 中,配置了类型是`helloworld` 的 `CustomComponent`,只有一个组件,其组件名是 `in-memory`: -```json - "custom_component": { - "helloworld": { - "in-memory": { - "metadata": {} - } - } - }, -``` +详见[自定义组件的配置文档](zh/component_specs/custom/common) ##### 看个例子 看个具体的例子,在[helloworld 示例中](https://github.com/mosn/layotto/blob/main/cmd/layotto_multiple_api/helloworld/grpc_api.go), `*server` 实现了 `Init` @@ -277,7 +248,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 diff --git a/docs/zh/design/configuration/configuration-api-with-apollo.md b/docs/zh/design/configuration/configuration-api-with-apollo.md index ca0334c783..9300014a5f 100644 --- a/docs/zh/design/configuration/configuration-api-with-apollo.md +++ b/docs/zh/design/configuration/configuration-api-with-apollo.md @@ -51,7 +51,8 @@ A: Legacy systems using apollo can't migrate to our sidecar if we design like th ### config.json for sidecar ```json { - "apollo": { + "config_store": { + "type": "apollo", "address": [ "http://106.54.227.205:8080" ], diff --git a/docs/zh/design/file/file-design.md b/docs/zh/design/file/file-design.md index 959e5a5ade..5b3b9c2cc5 100644 --- a/docs/zh/design/file/file-design.md +++ b/docs/zh/design/file/file-design.md @@ -109,7 +109,8 @@ Put接口入参主要有三个,多了一个data字段用来传输文件内容 { "file": { - "aliOSS": { + "file_demo": { + "type": "aliOSS", "metadata":[ { "endpoint": "endpoint_address", diff --git a/docs/zh/start/configuration/start-apollo.md b/docs/zh/start/configuration/start-apollo.md index 4b3a533e11..ff8ea6cb2c 100644 --- a/docs/zh/start/configuration/start-apollo.md +++ b/docs/zh/start/configuration/start-apollo.md @@ -61,7 +61,7 @@ go build -o layotto ``` ```shell - ./client -s "apollo" + ./client -s "config_demo" ``` 打印出如下信息则代表调用成功: @@ -72,7 +72,7 @@ get configuration after save, &{Key:key1 Content:value1 Group:application Label: get configuration after save, &{Key:haha Content:heihei Group:application Label:prod Tags:map[feature:haha release:1.0.0] Metadata:map[]} delete keys success write start -receive subscribe resp store_name:"apollo" app_id:"apollo" items: tags: > +receive subscribe resp store_name:"config_demo" app_id:"apollo" items: tags: > ``` ### 下一步 diff --git a/docs/zh/start/configuration/start.md b/docs/zh/start/configuration/start.md index 56beca28df..847806e1e1 100644 --- a/docs/zh/start/configuration/start.md +++ b/docs/zh/start/configuration/start.md @@ -55,7 +55,7 @@ go build -o layotto ``` ```shell - ./client -s "etcd" + ./client -s "config_demo" ``` 打印出如下信息则代表启动完成: @@ -66,7 +66,7 @@ get configuration after save, &{Key:key1 Content:value1 Group:application Label: get configuration after save, &{Key:haha Content:heihei Group:application Label:prod Tags:map[feature:haha release:1.0.0] Metadata:map[]} delete keys success write start -receive subscribe resp store_name:"apollo" app_id:"apollo" items: tags: > +receive subscribe resp store_name:"config_demo" app_id:"apollo" items: tags: > ``` ## 下一步 diff --git a/docs/zh/start/secret/start.md b/docs/zh/start/secret/start.md index a127c79456..f43e4f9a55 100644 --- a/docs/zh/start/secret/start.md +++ b/docs/zh/start/secret/start.md @@ -35,7 +35,7 @@ go build -o layotto go build -o client ``` ```shell - ./client -s "local.file" + ./client -s "secret_demo" ``` 打印出如下信息则代表调用成功: diff --git a/docs/zh/start/sequencer/start.md b/docs/zh/start/sequencer/start.md index 1fc3aac97d..599db161f2 100644 --- a/docs/zh/start/sequencer/start.md +++ b/docs/zh/start/sequencer/start.md @@ -52,7 +52,7 @@ go build -o layotto ```shell cd ${project_path}/demo/sequencer/common/ go build -o client - ./client -s "etcd" + ./client -s "sequencer_demo" ``` 打印出如下信息则代表调用成功: diff --git a/docs/zh/start/state/start.md b/docs/zh/start/state/start.md index cb8165e9a4..67f125958e 100644 --- a/docs/zh/start/state/start.md +++ b/docs/zh/start/state/start.md @@ -71,7 +71,7 @@ go build -o layotto # change directory to ${your project path}/demo/state/redis/ cd ${project_path}/demo/state/common/ go build -o client - ./client -s "redis" + ./client -s "state_demo" ``` 打印出如下信息则代表调用成功: diff --git a/pkg/runtime/bindings/factory.go b/pkg/runtime/bindings/factory.go index 7c74300d72..ba7f34c3c6 100644 --- a/pkg/runtime/bindings/factory.go +++ b/pkg/runtime/bindings/factory.go @@ -21,25 +21,25 @@ import ( ) type OutputBindingFactory struct { - Name string + CompType string FactoryMethod func() bindings.OutputBinding } -func NewOutputBindingFactory(name string, f func() bindings.OutputBinding) *OutputBindingFactory { +func NewOutputBindingFactory(compType string, f func() bindings.OutputBinding) *OutputBindingFactory { return &OutputBindingFactory{ - Name: name, + CompType: compType, FactoryMethod: f, } } type InputBindingFactory struct { - Name string + CompType string FactoryMethod func() bindings.InputBinding } -func NewInputBindingFactory(name string, f func() bindings.InputBinding) *InputBindingFactory { +func NewInputBindingFactory(compType string, f func() bindings.InputBinding) *InputBindingFactory { return &InputBindingFactory{ - Name: name, + CompType: compType, FactoryMethod: f, } } diff --git a/pkg/runtime/bindings/metadata.go b/pkg/runtime/bindings/metadata.go index 6963183afc..7d1ea0841b 100644 --- a/pkg/runtime/bindings/metadata.go +++ b/pkg/runtime/bindings/metadata.go @@ -17,6 +17,7 @@ package bindings type Metadata struct { + Type string `json:"type"` Version string Metadata map[string]string `json:"metadata"` } diff --git a/pkg/runtime/bindings/registry.go b/pkg/runtime/bindings/registry.go index 478837ae33..0e41647a84 100644 --- a/pkg/runtime/bindings/registry.go +++ b/pkg/runtime/bindings/registry.go @@ -31,8 +31,8 @@ const ( type Registry interface { RegisterOutputBinding(fs ...*OutputBindingFactory) RegisterInputBinding(fs ...*InputBindingFactory) - CreateOutputBinding(name string) (bindings.OutputBinding, error) - CreateInputBinding(name string) (bindings.InputBinding, error) + CreateOutputBinding(compType string) (bindings.OutputBinding, error) + CreateInputBinding(compType string) (bindings.InputBinding, error) } type bindingsRegistry struct { @@ -52,30 +52,30 @@ func NewRegistry(info *info.RuntimeInfo) Registry { func (r *bindingsRegistry) RegisterOutputBinding(fs ...*OutputBindingFactory) { for _, f := range fs { - r.outputBindingStores[f.Name] = f.FactoryMethod - r.info.RegisterComponent(ServiceName, f.Name) + r.outputBindingStores[f.CompType] = f.FactoryMethod + r.info.RegisterComponent(ServiceName, f.CompType) } } func (r *bindingsRegistry) RegisterInputBinding(fs ...*InputBindingFactory) { for _, f := range fs { - r.inputBindingStores[f.Name] = f.FactoryMethod - r.info.RegisterComponent(ServiceName, f.Name) + r.inputBindingStores[f.CompType] = f.FactoryMethod + r.info.RegisterComponent(ServiceName, f.CompType) } } -func (r *bindingsRegistry) CreateOutputBinding(name string) (bindings.OutputBinding, error) { - if f, ok := r.outputBindingStores[name]; ok { - r.info.LoadComponent(ServiceName, name) +func (r *bindingsRegistry) CreateOutputBinding(compType string) (bindings.OutputBinding, error) { + if f, ok := r.outputBindingStores[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) } -func (r *bindingsRegistry) CreateInputBinding(name string) (bindings.InputBinding, error) { - if f, ok := r.inputBindingStores[name]; ok { - r.info.LoadComponent(ServiceName, name) +func (r *bindingsRegistry) CreateInputBinding(compType string) (bindings.InputBinding, error) { + if f, ok := r.inputBindingStores[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) } diff --git a/pkg/runtime/lock/factory.go b/pkg/runtime/lock/factory.go index 17ac251634..7db50702d1 100644 --- a/pkg/runtime/lock/factory.go +++ b/pkg/runtime/lock/factory.go @@ -16,13 +16,13 @@ package lock import "mosn.io/layotto/components/lock" type Factory struct { - Name string + CompType string FactoryMethod func() lock.LockStore } -func NewFactory(name string, f func() lock.LockStore) *Factory { +func NewFactory(compType string, f func() lock.LockStore) *Factory { return &Factory{ - Name: name, + CompType: compType, FactoryMethod: f, } } diff --git a/pkg/runtime/lock/registry.go b/pkg/runtime/lock/registry.go index 8c9a942230..46cbc9c762 100644 --- a/pkg/runtime/lock/registry.go +++ b/pkg/runtime/lock/registry.go @@ -26,7 +26,7 @@ const ( type Registry interface { Register(fs ...*Factory) - Create(name string) (lock.LockStore, error) + Create(compType string) (lock.LockStore, error) } type lockRegistry struct { @@ -44,15 +44,15 @@ func NewRegistry(info *info.RuntimeInfo) Registry { func (r *lockRegistry) Register(fs ...*Factory) { 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 *lockRegistry) Create(name string) (lock.LockStore, error) { - if f, ok := r.stores[name]; ok { - r.info.LoadComponent(ServiceName, name) +func (r *lockRegistry) Create(compType string) (lock.LockStore, 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) } diff --git a/pkg/runtime/options.go b/pkg/runtime/options.go index 13e6b9b148..39d7a44f9b 100644 --- a/pkg/runtime/options.go +++ b/pkg/runtime/options.go @@ -48,7 +48,7 @@ type services struct { inputBinding []*mbindings.InputBindingFactory secretStores []*msecretstores.SecretStoresFactory // Custom components. - // The key is component type + // The key is component kind custom map[string][]*custom.ComponentFactory } @@ -102,12 +102,12 @@ func WithErrInterceptor(i ErrInterceptor) Option { } } -func WithCustomComponentFactory(componentType string, factorys ...*custom.ComponentFactory) Option { +func WithCustomComponentFactory(kind string, factorys ...*custom.ComponentFactory) Option { return func(o *runtimeOptions) { if len(factorys) == 0 { return } - o.services.custom[componentType] = append(o.services.custom[componentType], factorys...) + o.services.custom[kind] = append(o.services.custom[kind], factorys...) } } diff --git a/pkg/runtime/pubsub/config.go b/pkg/runtime/pubsub/config.go index 0cc73104da..8e7d730763 100644 --- a/pkg/runtime/pubsub/config.go +++ b/pkg/runtime/pubsub/config.go @@ -18,5 +18,6 @@ package pubsub // Config wraps configuration for a pubsub implementation type Config struct { + Type string `json:"type"` Metadata map[string]string `json:"metadata"` } diff --git a/pkg/runtime/pubsub/factory.go b/pkg/runtime/pubsub/factory.go index 20f3284d90..f12423f1ee 100644 --- a/pkg/runtime/pubsub/factory.go +++ b/pkg/runtime/pubsub/factory.go @@ -19,13 +19,13 @@ package pubsub import "github.com/dapr/components-contrib/pubsub" type Factory struct { - Name string + CompType string FactoryMethod func() pubsub.PubSub } -func NewFactory(name string, f func() pubsub.PubSub) *Factory { +func NewFactory(compType string, f func() pubsub.PubSub) *Factory { return &Factory{ - Name: name, + CompType: compType, FactoryMethod: f, } } diff --git a/pkg/runtime/pubsub/registry.go b/pkg/runtime/pubsub/registry.go index 8320054104..6db051d6c7 100644 --- a/pkg/runtime/pubsub/registry.go +++ b/pkg/runtime/pubsub/registry.go @@ -29,7 +29,7 @@ const serviceName = "pubsub" // Registry is the pubsub registry with pubsub name as the key type Registry interface { Register(fs ...*Factory) - Create(name string) (dpubsub.PubSub, error) + Create(compType string) (dpubsub.PubSub, error) } type pubsubRegistry struct { @@ -47,15 +47,15 @@ func NewRegistry(info *info.RuntimeInfo) Registry { func (r *pubsubRegistry) Register(fs ...*Factory) { 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 *pubsubRegistry) Create(name string) (dpubsub.PubSub, error) { - if f, ok := r.stores[name]; ok { - r.info.LoadComponent(serviceName, name) +func (r *pubsubRegistry) Create(compType string) (dpubsub.PubSub, 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 registered", name) + return nil, fmt.Errorf("service component %s is not registered", compType) } diff --git a/pkg/runtime/runtime.go b/pkg/runtime/runtime.go index 347bf2e3c2..27d5390198 100644 --- a/pkg/runtime/runtime.go +++ b/pkg/runtime/runtime.go @@ -272,7 +272,7 @@ func (m *MosnRuntime) initHellos(hellos ...*hello.HelloFactory) error { // register all hello services implementation m.helloRegistry.Register(hellos...) for name, config := range m.runtimeConfig.HelloServiceManagement { - h, err := m.helloRegistry.Create(name) + h, err := m.helloRegistry.Create(config.Type) if err != nil { m.errInt(err, "create hello's component %s failed", name) return err @@ -291,7 +291,7 @@ func (m *MosnRuntime) initConfigStores(configStores ...*configstores.StoreFactor // register all config store services implementation m.configStoreRegistry.Register(configStores...) for name, config := range m.runtimeConfig.ConfigStoreManagement { - c, err := m.configStoreRegistry.Create(name) + c, err := m.configStoreRegistry.Create(config.Type) if err != nil { m.errInt(err, "create configstore's component %s failed", name) return err @@ -331,7 +331,7 @@ func (m *MosnRuntime) initPubSubs(factorys ...*runtime_pubsub.Factory) error { m.pubSubRegistry.Register(factorys...) for name, config := range m.runtimeConfig.PubSubManagement { // create component - comp, err := m.pubSubRegistry.Create(name) + comp, err := m.pubSubRegistry.Create(config.Type) if err != nil { m.errInt(err, "create pubsub component %s failed", name) return err @@ -362,7 +362,7 @@ func (m *MosnRuntime) initStates(factorys ...*runtime_state.Factory) error { // 2. loop initializing for name, config := range m.runtimeConfig.StateManagement { // 2.1. create and store the component - comp, err := m.stateRegistry.Create(name) + comp, err := m.stateRegistry.Create(config.Type) if err != nil { m.errInt(err, "create state component %s failed", name) return err @@ -388,7 +388,7 @@ func (m *MosnRuntime) initFiles(files ...*file.FileFactory) error { // register all files store services implementation m.fileRegistry.Register(files...) for name, config := range m.runtimeConfig.Files { - c, err := m.fileRegistry.Create(name) + c, err := m.fileRegistry.Create(config.Type) if err != nil { m.errInt(err, "create files component %s failed", name) return err @@ -409,7 +409,7 @@ func (m *MosnRuntime) initLocks(factorys ...*runtime_lock.Factory) error { // 2. loop initializing for name, config := range m.runtimeConfig.LockManagement { // 2.1. create the component - comp, err := m.lockRegistry.Create(name) + comp, err := m.lockRegistry.Create(config.Type) if err != nil { m.errInt(err, "create lock component %s failed", name) return err @@ -437,7 +437,7 @@ func (m *MosnRuntime) initSequencers(factorys ...*runtime_sequencer.Factory) err // 2. loop initializing for name, config := range m.runtimeConfig.SequencerManagement { // 2.1. create the component - comp, err := m.sequencerRegistry.Create(name) + comp, err := m.sequencerRegistry.Create(config.Type) if err != nil { m.errInt(err, "create sequencer component %s failed", name) return err @@ -489,7 +489,7 @@ func (m *MosnRuntime) initOutputBinding(factorys ...*mbindings.OutputBindingFact // 2. loop initializing for name, config := range m.runtimeConfig.Bindings { // 2.1. create the component - comp, err := m.bindingsRegistry.CreateOutputBinding(name) + comp, err := m.bindingsRegistry.CreateOutputBinding(config.Type) if err != nil { m.errInt(err, "create outbinding component %s failed", name) return err @@ -517,7 +517,7 @@ func (m *MosnRuntime) initSecretStores(factorys ...*msecretstores.SecretStoresFa // 2. loop initializing for name, config := range m.runtimeConfig.SecretStoresManagement { // 2.1. create the component - comp, err := m.secretStoresRegistry.Create(name) + comp, err := m.secretStoresRegistry.Create(config.Type) if err != nil { m.errInt(err, "create secretStore component %s failed", name) return err @@ -560,17 +560,17 @@ func (m *MosnRuntime) initRuntime(r *runtimeOptions) error { return nil } -func (m *MosnRuntime) SetCustomComponent(componentType string, name string, component custom.Component) { - if _, ok := m.customComponent[componentType]; !ok { - m.customComponent[componentType] = make(map[string]custom.Component) +func (m *MosnRuntime) SetCustomComponent(kind string, name string, component custom.Component) { + if _, ok := m.customComponent[kind]; !ok { + m.customComponent[kind] = make(map[string]custom.Component) } - m.customComponent[componentType][name] = component + m.customComponent[kind][name] = component } -func (m *MosnRuntime) initCustomComponents(type2factorys map[string][]*custom.ComponentFactory) error { +func (m *MosnRuntime) initCustomComponents(kind2factorys map[string][]*custom.ComponentFactory) error { log.DefaultLogger.Infof("[runtime] start initializing custom components") // 1. validation - if len(type2factorys) == 0 { + if len(kind2factorys) == 0 { log.DefaultLogger.Infof("[runtime] no custom component factorys compiled") return nil } @@ -579,22 +579,22 @@ func (m *MosnRuntime) initCustomComponents(type2factorys map[string][]*custom.Co return nil } // 2. loop registering all types of components. - for compType, factorys := range type2factorys { + for kind, factorys := range kind2factorys { // 2.0. check empty if len(factorys) == 0 { continue } - name2Config, ok := m.runtimeConfig.CustomComponent[compType] + name2Config, ok := m.runtimeConfig.CustomComponent[kind] if !ok { - log.DefaultLogger.Errorf("[runtime] Your required component type %s is not supported.Please check your configuration", compType) + log.DefaultLogger.Errorf("[runtime] Your required component type %s is not supported.Please check your configuration", kind) continue } // 2.1. register all the factorys - m.customComponentRegistry.Register(compType, factorys...) + m.customComponentRegistry.Register(kind, factorys...) // 2.2. loop initializing component instances for name, config := range name2Config { // create the component - comp, err := m.customComponentRegistry.Create(compType, name) + comp, err := m.customComponentRegistry.Create(kind, config.Type) if err != nil { m.errInt(err, "create custom component %s failed", name) return err @@ -605,7 +605,7 @@ func (m *MosnRuntime) initCustomComponents(type2factorys map[string][]*custom.Co return err } // initialization finish - m.SetCustomComponent(compType, name, comp) + m.SetCustomComponent(kind, name, comp) } } return nil diff --git a/pkg/runtime/runtime_test.go b/pkg/runtime/runtime_test.go index 9fe57ddf4b..a9e5f93de5 100644 --- a/pkg/runtime/runtime_test.go +++ b/pkg/runtime/runtime_test.go @@ -195,7 +195,8 @@ func TestMosnRuntime_Run(t *testing.T) { // 2. construct runtime cfg := &MosnRuntimeConfig{ PubSubManagement: map[string]mpubsub.Config{ - "mock": { + "demo": { + Type: "mock", Metadata: map[string]string{ "target": "layotto", }, @@ -275,7 +276,8 @@ func TestMosnRuntime_initPubSubs(t *testing.T) { cfg := &MosnRuntimeConfig{ PubSubManagement: map[string]mpubsub.Config{ - "mock": { + "demo": { + Type: "mock", Metadata: map[string]string{ "target": "layotto", }, @@ -305,7 +307,12 @@ func TestMosnRuntime_initPubSubsNotExistMetadata(t *testing.T) { cfg := &MosnRuntimeConfig{ PubSubManagement: map[string]mpubsub.Config{ - "mock": {}, + "demo": { + Type: "mock", + Metadata: map[string]string{ + "target": "layotto", + }, + }, }, } // construct MosnRuntime @@ -332,6 +339,7 @@ func TestMosnRuntime_initStates(t *testing.T) { cfg := &MosnRuntimeConfig{ StateManagement: map[string]mstate.Config{ "mock": { + Type: "status", Metadata: map[string]string{ "target": "layotto", }, @@ -344,7 +352,7 @@ func TestMosnRuntime_initStates(t *testing.T) { log.DefaultLogger.Errorf("[runtime] occurs an error: "+err.Error()+", "+format, args...) } // test initStates - err := m.initStates(mstate.NewFactory("mock", f)) + err := m.initStates(mstate.NewFactory("status", f)) // assert result assert.Nil(t, err) }) @@ -361,7 +369,7 @@ func TestMosnRuntime_initRpc(t *testing.T) { cfg := &MosnRuntimeConfig{ RpcManagement: map[string]rpc.RpcConfig{ - "mock": {}, + "rpc": {}, }, } // construct MosnRuntime @@ -370,7 +378,7 @@ func TestMosnRuntime_initRpc(t *testing.T) { log.DefaultLogger.Errorf("[runtime] occurs an error: "+err.Error()+", "+format, args...) } // test initRpcs method - err := m.initRpcs(rpc.NewRpcFactory("mock", f)) + err := m.initRpcs(rpc.NewRpcFactory("rpc", f)) // assert assert.Nil(t, err) }) @@ -386,14 +394,16 @@ func TestMosnRuntime_initConfigStores(t *testing.T) { cfg := &MosnRuntimeConfig{ ConfigStoreManagement: map[string]configstores.StoreConfig{ - "mock": {}, + "mock": { + Type: "store_config", + }, }, } m := NewMosnRuntime(cfg) m.errInt = func(err error, format string, args ...interface{}) { log.DefaultLogger.Errorf("[runtime] occurs an error: "+err.Error()+", "+format, args...) } - err := m.initConfigStores(configstores.NewStoreFactory("mock", f)) + err := m.initConfigStores(configstores.NewStoreFactory("store_config", f)) assert.Nil(t, err) }) } @@ -408,14 +418,16 @@ func TestMosnRuntime_initHellos(t *testing.T) { cfg := &MosnRuntimeConfig{ HelloServiceManagement: map[string]hello.HelloConfig{ - "mock": {}, + "mock": { + Type: "hello", + }, }, } m := NewMosnRuntime(cfg) m.errInt = func(err error, format string, args ...interface{}) { log.DefaultLogger.Errorf("[runtime] occurs an error: "+err.Error()+", "+format, args...) } - err := m.initHellos(hello.NewHelloFactory("mock", f)) + err := m.initHellos(hello.NewHelloFactory("hello", f)) assert.Nil(t, err) }) } @@ -430,14 +442,16 @@ func TestMosnRuntime_initSequencers(t *testing.T) { cfg := &MosnRuntimeConfig{ SequencerManagement: map[string]sequencer.Config{ - "mock": {}, + "mock": { + Type: "sequencers", + }, }, } m := NewMosnRuntime(cfg) m.errInt = func(err error, format string, args ...interface{}) { log.DefaultLogger.Errorf("[runtime] occurs an error: "+err.Error()+", "+format, args...) } - err := m.initSequencers(runtime_sequencer.NewFactory("mock", f)) + err := m.initSequencers(runtime_sequencer.NewFactory("sequencers", f)) assert.Nil(t, err) }) } @@ -452,14 +466,16 @@ func TestMosnRuntime_initLocks(t *testing.T) { cfg := &MosnRuntimeConfig{ LockManagement: map[string]lock.Config{ - "mock": {}, + "mock": { + Type: "lock", + }, }, } m := NewMosnRuntime(cfg) m.errInt = func(err error, format string, args ...interface{}) { log.DefaultLogger.Errorf("[runtime] occurs an error: "+err.Error()+", "+format, args...) } - err := m.initLocks(mlock.NewFactory("mock", f)) + err := m.initLocks(mlock.NewFactory("lock", f)) assert.Nil(t, err) }) } @@ -485,12 +501,13 @@ func TestMosnRuntime_initOutputBinding(t *testing.T) { m := NewMosnRuntime(cfg) assert.Nil(t, m.outputBindings["mockOutbindings"]) - registry := mbindings.NewOutputBindingFactory("mockOutbindings", func() bindings.OutputBinding { + registry := mbindings.NewOutputBindingFactory("mock_outbindings", func() bindings.OutputBinding { return &MockBindings{} }) mdata := make(map[string]string) m.RuntimeConfig().Bindings = make(map[string]mbindings.Metadata) m.runtimeConfig.Bindings["mockOutbindings"] = mbindings.Metadata{ + Type: "mock_outbindings", Metadata: mdata, } err := m.initOutputBinding(registry) @@ -500,13 +517,15 @@ func TestMosnRuntime_initOutputBinding(t *testing.T) { func TestMosnRuntime_runWithCustomComponentAndAPI(t *testing.T) { t.Run("normal", func(t *testing.T) { - compType := "super_pubsub" - compName := "etcd" + kind := "super_pubsub" + compName := "demo" + compType := "etcd" // 1. construct config cfg := &MosnRuntimeConfig{ CustomComponent: map[string]map[string]custom.Config{ - compType: { + kind: { compName: custom.Config{ + Type: compType, Version: "", Metadata: nil, }, @@ -525,14 +544,14 @@ func TestMosnRuntime_runWithCustomComponentAndAPI(t *testing.T) { WithGrpcAPI( default_api.NewGrpcAPI, func(ac *grpc.ApplicationContext) grpc.GrpcAPI { - comp := ac.CustomComponent[compType][compName].(superPubsub) + comp := ac.CustomComponent[kind][compName].(superPubsub) customAPI = &mockGrpcAPI{comp: comp} return customAPI }, ), // Custom components - WithCustomComponentFactory(compType, - custom.NewComponentFactory(compName, newSuperPubsub), + WithCustomComponentFactory(kind, + custom.NewComponentFactory(compType, newSuperPubsub), ), // Hello WithHelloFactory( @@ -540,7 +559,7 @@ func TestMosnRuntime_runWithCustomComponentAndAPI(t *testing.T) { ), // Sequencer WithSequencerFactory( - runtime_sequencer.NewFactory(compName, func() sequencer.Store { + runtime_sequencer.NewFactory(compType, func() sequencer.Store { return sequencer_etcd.NewEtcdSequencer(log.DefaultLogger) }), runtime_sequencer.NewFactory("redis", func() sequencer.Store { @@ -764,12 +783,14 @@ func constructCloudEvent() map[string]interface{} { } func runtimeWithCallbackConnection(t *testing.T) (*MosnRuntime, *mock_appcallback.MockAppCallbackServer) { + compName := "demo" + compType := "mock" // 1. prepare callback // mock callback response subResp := &runtimev1pb.ListTopicSubscriptionsResponse{ Subscriptions: []*runtimev1pb.TopicSubscription{ { - PubsubName: "mock", + PubsubName: compName, Topic: "layotto", Metadata: nil, }, @@ -796,7 +817,8 @@ func runtimeWithCallbackConnection(t *testing.T) (*MosnRuntime, *mock_appcallbac // 3. construct mosn runtime cfg := &MosnRuntimeConfig{ PubSubManagement: map[string]mpubsub.Config{ - "mock": { + compName: { + Type: compType, Metadata: map[string]string{ "target": "layotto", }, diff --git a/pkg/runtime/secretstores/factory.go b/pkg/runtime/secretstores/factory.go index c799652c74..ef96c0afed 100644 --- a/pkg/runtime/secretstores/factory.go +++ b/pkg/runtime/secretstores/factory.go @@ -18,13 +18,13 @@ import ( ) type SecretStoresFactory struct { - Name string + CompType string FactoryMethod func() secretstores.SecretStore } -func NewFactory(name string, f func() secretstores.SecretStore) *SecretStoresFactory { +func NewFactory(compType string, f func() secretstores.SecretStore) *SecretStoresFactory { return &SecretStoresFactory{ - Name: name, + CompType: compType, FactoryMethod: f, } } diff --git a/pkg/runtime/secretstores/factory_test.go b/pkg/runtime/secretstores/factory_test.go new file mode 100644 index 0000000000..4a9743c007 --- /dev/null +++ b/pkg/runtime/secretstores/factory_test.go @@ -0,0 +1,34 @@ +package secretstores + +/* + * Copyright 2021 Layotto Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import ( + "testing" + + "mosn.io/layotto/pkg/mock/components/secret" + + "github.com/dapr/components-contrib/secretstores" + "github.com/stretchr/testify/assert" +) + +func TestNewFactory(t *testing.T) { + factory := NewFactory("test", func() secretstores.SecretStore { + return secret.FakeSecretStore{} + }) + + assert.NotNil(t, factory) +} diff --git a/pkg/runtime/secretstores/metadata.go b/pkg/runtime/secretstores/metadata.go index 03c967cc13..7f4acd728c 100644 --- a/pkg/runtime/secretstores/metadata.go +++ b/pkg/runtime/secretstores/metadata.go @@ -17,6 +17,7 @@ package secretstores type Metadata struct { + Type string `json:"type"` Version string Metadata map[string]string `json:"metadata"` } diff --git a/pkg/runtime/secretstores/registry.go b/pkg/runtime/secretstores/registry.go index bdf34ef56b..4e7e210a4e 100644 --- a/pkg/runtime/secretstores/registry.go +++ b/pkg/runtime/secretstores/registry.go @@ -29,7 +29,7 @@ type ( // Registry is used to get registered secret store implementations. Registry interface { Register(ss ...*SecretStoresFactory) - Create(name string) (secretstores.SecretStore, error) + Create(compType string) (secretstores.SecretStore, error) } secretStoreRegistry struct { @@ -50,17 +50,17 @@ func NewRegistry(info *info.RuntimeInfo) Registry { // Register adds one or many new secret stores to the registry. func (s *secretStoreRegistry) Register(ss ...*SecretStoresFactory) { for _, component := range ss { - s.secretStores[component.Name] = component.FactoryMethod - s.info.RegisterComponent(ServiceName, component.Name) + s.secretStores[component.CompType] = component.FactoryMethod + s.info.RegisterComponent(ServiceName, component.CompType) } } // Create instantiates a secret store based on `name`. -func (s *secretStoreRegistry) Create(name string) (secretstores.SecretStore, error) { - if method, ok := s.secretStores[name]; ok { - s.info.LoadComponent(ServiceName, name) +func (s *secretStoreRegistry) Create(compType string) (secretstores.SecretStore, error) { + if method, ok := s.secretStores[compType]; ok { + s.info.LoadComponent(ServiceName, compType) return method(), nil } - return nil, errors.Errorf("couldn't find secret store %s", name) + return nil, errors.Errorf("couldn't find secret store %s", compType) } diff --git a/pkg/runtime/sequencer/factory.go b/pkg/runtime/sequencer/factory.go index 605bb09406..ac2778b7de 100644 --- a/pkg/runtime/sequencer/factory.go +++ b/pkg/runtime/sequencer/factory.go @@ -18,13 +18,13 @@ import ( ) type Factory struct { - Name string + CompType string FactoryMethod func() sequencer.Store } -func NewFactory(name string, f func() sequencer.Store) *Factory { +func NewFactory(compType string, f func() sequencer.Store) *Factory { return &Factory{ - Name: name, + CompType: compType, FactoryMethod: f, } } diff --git a/pkg/runtime/sequencer/registry.go b/pkg/runtime/sequencer/registry.go index 16c7749213..c54894ad42 100644 --- a/pkg/runtime/sequencer/registry.go +++ b/pkg/runtime/sequencer/registry.go @@ -26,7 +26,7 @@ const ( type Registry interface { Register(fs ...*Factory) - Create(name string) (sequencer.Store, error) + Create(compType string) (sequencer.Store, error) } type sequencerRegistry struct { @@ -44,15 +44,15 @@ func NewRegistry(info *info.RuntimeInfo) Registry { func (r *sequencerRegistry) Register(fs ...*Factory) { 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 *sequencerRegistry) Create(name string) (sequencer.Store, error) { - if f, ok := r.stores[name]; ok { - r.info.LoadComponent(ServiceName, name) +func (r *sequencerRegistry) Create(compType string) (sequencer.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) } diff --git a/pkg/runtime/state/config.go b/pkg/runtime/state/config.go index bed388be13..08e60f851c 100644 --- a/pkg/runtime/state/config.go +++ b/pkg/runtime/state/config.go @@ -18,5 +18,6 @@ package state // Config wraps configuration for a state implementation type Config struct { + Type string `json:"type"` Metadata map[string]string `json:"metadata"` } diff --git a/pkg/runtime/state/factory.go b/pkg/runtime/state/factory.go index 13cabd1144..b38e56cd9f 100644 --- a/pkg/runtime/state/factory.go +++ b/pkg/runtime/state/factory.go @@ -21,14 +21,14 @@ import ( ) type Factory struct { - Name string + CompType string FactoryMethod func() state.Store } // Create a new Factory type variable -func NewFactory(name string, f func() state.Store) *Factory { +func NewFactory(compType string, f func() state.Store) *Factory { return &Factory{ - Name: name, + CompType: compType, FactoryMethod: f, } } diff --git a/pkg/runtime/state/registry.go b/pkg/runtime/state/registry.go index 9cff8415c8..63a2a3a3aa 100644 --- a/pkg/runtime/state/registry.go +++ b/pkg/runtime/state/registry.go @@ -30,7 +30,7 @@ const ( type Registry interface { Register(fs ...*Factory) - Create(name string) (state.Store, error) + Create(compType string) (state.Store, error) } type stateRegistry struct { @@ -50,16 +50,16 @@ func NewRegistry(info *info.RuntimeInfo) Registry { // Registration for multiple Factories func (r *stateRegistry) Register(fs ...*Factory) { 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) } } // Loading components for a registered Factory -func (r *stateRegistry) Create(name string) (state.Store, error) { - if f, ok := r.stores[name]; ok { - r.info.LoadComponent(ServiceName, name) +func (r *stateRegistry) Create(compType string) (state.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) } diff --git a/sdk/go-sdk/client/client_test.go b/sdk/go-sdk/client/client_test.go index 8716228f11..f3c67aca09 100644 --- a/sdk/go-sdk/client/client_test.go +++ b/sdk/go-sdk/client/client_test.go @@ -19,6 +19,7 @@ package client import ( "context" "fmt" + "net" "os" "testing" @@ -81,6 +82,7 @@ func getTestClient(ctx context.Context) (client Client, closer func()) { kv: make(map[string]string), subscribed: make(map[string]bool), state: make(map[string][]byte), + lock: make(map[string]string), }) l := bufconn.Listen(testBufSize) @@ -113,9 +115,10 @@ type testRuntimeServer struct { kv map[string]string subscribed map[string]bool state map[string][]byte + lock map[string]string } -func (s *testRuntimeServer) InvokeService(ctx context.Context, req *runtimev1pb.InvokeServiceRequest) (*runtimev1pb.InvokeResponse, error) { +func (t *testRuntimeServer) InvokeService(ctx context.Context, req *runtimev1pb.InvokeServiceRequest) (*runtimev1pb.InvokeResponse, error) { if req.Message == nil { return &runtimev1pb.InvokeResponse{ ContentType: "text/plain", @@ -130,17 +133,17 @@ func (s *testRuntimeServer) InvokeService(ctx context.Context, req *runtimev1pb. }, nil } -func (s *testRuntimeServer) GetState(ctx context.Context, req *runtimev1pb.GetStateRequest) (*runtimev1pb.GetStateResponse, error) { +func (t *testRuntimeServer) GetState(ctx context.Context, req *runtimev1pb.GetStateRequest) (*runtimev1pb.GetStateResponse, error) { return &pb.GetStateResponse{ - Data: s.state[req.Key], + Data: t.state[req.Key], Etag: "1", }, nil } -func (s *testRuntimeServer) GetBulkState(ctx context.Context, in *runtimev1pb.GetBulkStateRequest) (*runtimev1pb.GetBulkStateResponse, error) { +func (t *testRuntimeServer) GetBulkState(ctx context.Context, in *runtimev1pb.GetBulkStateRequest) (*runtimev1pb.GetBulkStateResponse, error) { items := make([]*runtimev1pb.BulkStateItem, 0) for _, k := range in.GetKeys() { - if v, found := s.state[k]; found { + if v, found := t.state[k]; found { item := &pb.BulkStateItem{ Key: k, Etag: "1", @@ -154,7 +157,7 @@ func (s *testRuntimeServer) GetBulkState(ctx context.Context, in *runtimev1pb.Ge }, nil } -func (s *testRuntimeServer) SaveState(ctx context.Context, req *runtimev1pb.SaveStateRequest) (*empty.Empty, error) { +func (t *testRuntimeServer) SaveState(ctx context.Context, req *runtimev1pb.SaveStateRequest) (*empty.Empty, error) { if req == nil { return &empty.Empty{}, nil } @@ -162,31 +165,31 @@ func (s *testRuntimeServer) SaveState(ctx context.Context, req *runtimev1pb.Save if item == nil { continue } - s.state[item.Key] = item.Value + t.state[item.Key] = item.Value } return &empty.Empty{}, nil } -func (s *testRuntimeServer) DeleteState(ctx context.Context, req *runtimev1pb.DeleteStateRequest) (*empty.Empty, error) { - delete(s.state, req.Key) +func (t *testRuntimeServer) DeleteState(ctx context.Context, req *runtimev1pb.DeleteStateRequest) (*empty.Empty, error) { + delete(t.state, req.Key) return &empty.Empty{}, nil } -func (s *testRuntimeServer) DeleteBulkState(ctx context.Context, req *runtimev1pb.DeleteBulkStateRequest) (*empty.Empty, error) { +func (t *testRuntimeServer) DeleteBulkState(ctx context.Context, req *runtimev1pb.DeleteBulkStateRequest) (*empty.Empty, error) { for _, item := range req.States { - delete(s.state, item.Key) + delete(t.state, item.Key) } return &empty.Empty{}, nil } -func (s *testRuntimeServer) ExecuteStateTransaction(ctx context.Context, in *runtimev1pb.ExecuteStateTransactionRequest) (*empty.Empty, error) { +func (t *testRuntimeServer) ExecuteStateTransaction(ctx context.Context, in *runtimev1pb.ExecuteStateTransactionRequest) (*empty.Empty, error) { for _, op := range in.GetOperations() { item := op.GetRequest() switch opType := op.GetOperationType(); opType { case "upsert": - s.state[item.Key] = item.Value + t.state[item.Key] = item.Value case "delete": - delete(s.state, item.Key) + delete(t.state, item.Key) default: return &empty.Empty{}, fmt.Errorf("invalid operation type: %s", opType) } @@ -194,7 +197,7 @@ func (s *testRuntimeServer) ExecuteStateTransaction(ctx context.Context, in *run return &empty.Empty{}, nil } -func (s *testRuntimeServer) PublishEvent(ctx context.Context, req *runtimev1pb.PublishEventRequest) (*empty.Empty, error) { +func (t *testRuntimeServer) PublishEvent(ctx context.Context, req *runtimev1pb.PublishEventRequest) (*empty.Empty, error) { return &empty.Empty{}, nil } @@ -264,3 +267,42 @@ func (*testRuntimeServer) GetBulkSecret(ctx context.Context, in *runtimev1pb.Get } return resp, nil } + +func (t *testRuntimeServer) TryLock(ctx context.Context, in *runtimev1pb.TryLockRequest) (*runtimev1pb.TryLockResponse, error) { + + if len(t.lock[in.ResourceId]) == 0 { + t.lock[in.ResourceId] = in.LockOwner + resp := &runtimev1pb.TryLockResponse{ + Success: true, + } + return resp, nil + } else { + resp := &runtimev1pb.TryLockResponse{ + Success: false, + } + return resp, nil + } +} + +func (t *testRuntimeServer) Unlock(ctx context.Context, in *runtimev1pb.UnlockRequest) (*runtimev1pb.UnlockResponse, error) { + if len(t.lock[in.ResourceId]) != 0 { + if t.lock[in.ResourceId] == in.LockOwner { + delete(t.lock, in.ResourceId) + resp := &runtimev1pb.UnlockResponse{ + Status: pb.UnlockResponse_SUCCESS, + } + return resp, nil + } else { + resp := &runtimev1pb.UnlockResponse{ + Status: pb.UnlockResponse_LOCK_BELONG_TO_OTHERS, + } + return resp, nil + } + + } else { + resp := &runtimev1pb.UnlockResponse{ + Status: pb.UnlockResponse_LOCK_UNEXIST, + } + return resp, nil + } +} diff --git a/sdk/go-sdk/client/lock_test.go b/sdk/go-sdk/client/lock_test.go new file mode 100644 index 0000000000..2258643ec9 --- /dev/null +++ b/sdk/go-sdk/client/lock_test.go @@ -0,0 +1,86 @@ +package client + +/* + * Copyright 2021 Layotto Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import ( + "testing" + + "context" + + "github.com/stretchr/testify/assert" + + runtimev1pb "mosn.io/layotto/spec/proto/runtime/v1" +) + +func TestTryLock(t *testing.T) { + ctx := context.Background() + t.Run("try lock successfully", func(t *testing.T) { + request := runtimev1pb.TryLockRequest{ + StoreName: "demo", + ResourceId: "lock_test", + LockOwner: "layotto", + } + lock, err := testClient.TryLock(ctx, &request) + assert.Nil(t, err) + assert.True(t, lock.Success) + }) +} + +func TestUnLock(t *testing.T) { + ctx := context.Background() + t.Run("can't unlock with different owner", func(t *testing.T) { + request := runtimev1pb.TryLockRequest{ + StoreName: "demo", + ResourceId: "unlock_test", + LockOwner: "layotto", + } + lock, err := testClient.TryLock(ctx, &request) + assert.Nil(t, err) + assert.True(t, lock.Success) + // 2. unlock with different owner + unlockReq := runtimev1pb.UnlockRequest{ + StoreName: "demo", + ResourceId: "unlock_test", + LockOwner: "layotto1", + } + unlock, err := testClient.Unlock(ctx, &unlockReq) + assert.Nil(t, err) + assert.Equal(t, unlock.Status, runtimev1pb.UnlockResponse_LOCK_BELONG_TO_OTHERS) + }) + + t.Run("unlock successfully", func(t *testing.T) { + request := runtimev1pb.UnlockRequest{ + StoreName: "demo", + ResourceId: "unlock_test", + LockOwner: "layotto", + } + unlock, err := testClient.Unlock(ctx, &request) + assert.Nil(t, err) + assert.Equal(t, unlock.Status, runtimev1pb.UnlockResponse_SUCCESS) + }) + + t.Run("unlock but LOCK_UNEXIST", func(t *testing.T) { + request := runtimev1pb.UnlockRequest{ + StoreName: "demo", + ResourceId: "unlock_test", + LockOwner: "layotto", + } + unlock, err := testClient.Unlock(ctx, &request) + assert.Nil(t, err) + assert.Equal(t, unlock.Status, runtimev1pb.UnlockResponse_LOCK_UNEXIST) + }) +} diff --git a/sdk/go-sdk/test/runtime/redis_integrate_test.go b/sdk/go-sdk/test/runtime/redis_integrate_test.go index cffdf7df17..506e2222c1 100644 --- a/sdk/go-sdk/test/runtime/redis_integrate_test.go +++ b/sdk/go-sdk/test/runtime/redis_integrate_test.go @@ -28,7 +28,7 @@ import ( runtimev1pb "mosn.io/layotto/spec/proto/runtime/v1" ) -var componentName = "redis" +var componentName = "state_demo" func TestHelloApi(t *testing.T) { cli, err := client.NewClientWithAddress("127.0.0.1:11104") @@ -40,7 +40,7 @@ func TestHelloApi(t *testing.T) { ctx := context.Background() helloReq := &client.SayHelloRequest{ - ServiceName: "helloworld", + ServiceName: "quick_start_demo", } helloResp, err := cli.SayHello(ctx, helloReq) assert.Nil(t, err) @@ -61,7 +61,7 @@ func TestStateApi(t *testing.T) { err = cli.SaveState(ctx, componentName, stateKey, stateValue) assert.Nil(t, err) - stateResp, err := cli.GetState(ctx, componentName, stateKey) + stateResp, err := cli.GetState(ctx, "state_demo", stateKey) assert.Nil(t, err) assert.Equal(t, stateValue, stateResp.Value) } @@ -78,10 +78,10 @@ func TestLockApi(t *testing.T) { owner1 := uuid.New().String() owner2 := uuid.New().String() resourceID := "MyLock" - + storeName := "lock_demo" // 1. client1 tryLock resp, err := cli.TryLock(ctx, &runtimev1pb.TryLockRequest{ - StoreName: componentName, + StoreName: storeName, ResourceId: resourceID, LockOwner: owner1, Expire: 100000, @@ -94,7 +94,7 @@ func TestLockApi(t *testing.T) { // 2. client2 tryLock go func() { resp, err := cli.TryLock(ctx, &runtimev1pb.TryLockRequest{ - StoreName: componentName, + StoreName: storeName, ResourceId: resourceID, LockOwner: owner2, Expire: 1000, @@ -106,7 +106,7 @@ func TestLockApi(t *testing.T) { wg.Wait() // 3. client1 unlock unlockResp, err := cli.Unlock(ctx, &runtimev1pb.UnlockRequest{ - StoreName: componentName, + StoreName: storeName, ResourceId: resourceID, LockOwner: owner1, }) @@ -117,7 +117,7 @@ func TestLockApi(t *testing.T) { wg.Add(1) go func() { resp, err := cli.TryLock(ctx, &runtimev1pb.TryLockRequest{ - StoreName: componentName, + StoreName: storeName, ResourceId: resourceID, LockOwner: owner2, Expire: 10, @@ -126,7 +126,7 @@ func TestLockApi(t *testing.T) { assert.True(t, true, resp.Success) // 5. client2 unlock unlockResp, err := cli.Unlock(ctx, &runtimev1pb.UnlockRequest{ - StoreName: componentName, + StoreName: storeName, ResourceId: resourceID, LockOwner: owner2, }) @@ -149,7 +149,7 @@ func TestSequencerApi(t *testing.T) { for i := 1; i < 10; i++ { resp, err := cli.GetNextId(ctx, &runtimev1pb.GetNextIdRequest{ - StoreName: componentName, + StoreName: "sequencer_demo", Key: sequencerKey, }) assert.Nil(t, err)