From f6b1d6afc57700b59c2ced2ae3b7c06827163fb3 Mon Sep 17 00:00:00 2001 From: "vito.he" <hxmhlt@163.com> Date: Mon, 29 Apr 2019 21:43:25 +0800 Subject: [PATCH] Add:2.6.0 application config mod --- common/constant/key.go | 8 +++++++- config/registry_url.go | 13 ++++--------- config/support/config_loader.go | 11 +++++------ config/support/reference_config.go | 13 +++++++++++-- config/support/service_config.go | 9 +++++++++ registry/zookeeper/registry.go | 30 ++++++++++++++++-------------- 6 files changed, 52 insertions(+), 32 deletions(-) diff --git a/common/constant/key.go b/common/constant/key.go index 33dfeba3f..b5b9315c6 100644 --- a/common/constant/key.go +++ b/common/constant/key.go @@ -38,5 +38,11 @@ const ( ) const ( -//EXPORT_KEY = "export" + APPLICATION_KEY = "application" + ORGANIZATION_KEY = "organization" + NAME_KEY = "name" + MODULE_KEY = "module" + APP_VERSION_KEY = "version" + OWNER_KEY = "owner" + ENVIRONMENT_KEY = "environment" ) diff --git a/config/registry_url.go b/config/registry_url.go index c464f0b6e..a07c1dc96 100644 --- a/config/registry_url.go +++ b/config/registry_url.go @@ -47,15 +47,10 @@ type RegistryURL struct { Version string `yaml:"version" json:"version,omitempty"` Group string `yaml:"group" json:"group,omitempty"` //for registry - Username string `yaml:"username" json:"username,omitempty"` - Password string `yaml:"password" json:"password,omitempty"` - DubboType DubboType `yaml:"-"` - Organization string `yaml:"organization" json:"organization,omitempty"` - Name string `yaml:"name" json:"name,omitempty"` - Module string `yaml:"module" json:"module,omitempty"` - Owner string `yaml:"owner" json:"owner,omitempty"` - Environment string `yaml:"environment" json:"environment,omitempty"` - Address string `yaml:"address" json:"address,omitempty"` + Username string `yaml:"username" json:"username,omitempty"` + Password string `yaml:"password" json:"password,omitempty"` + DubboType DubboType `yaml:"-"` + Address string `yaml:"address" json:"address,omitempty"` } func NewRegistryURL(context context.Context, urlString string) (*RegistryURL, error) { diff --git a/config/support/config_loader.go b/config/support/config_loader.go index 726217d51..03c89d589 100644 --- a/config/support/config_loader.go +++ b/config/support/config_loader.go @@ -142,8 +142,6 @@ type ConsumerConfig struct { // codec & selector & transport & registry Selector string `default:"cache" yaml:"selector" json:"selector,omitempty"` Selector_TTL string `default:"10m" yaml:"selector_ttl" json:"selector_ttl,omitempty"` - //client load balance algorithm - ClientLoadBalance string `default:"round_robin" yaml:"client_load_balance" json:"client_load_balance,omitempty"` // application ApplicationConfig ApplicationConfig `yaml:"application_config" json:"application_config,omitempty"` Registries []RegistryConfig `yaml:"registries" json:"registries,omitempty"` @@ -168,10 +166,11 @@ func GetConsumerConfig() ConsumerConfig { ///////////////////////// type ProviderConfig struct { - Path string `yaml:"path" json:"path,omitempty"` - Registries []RegistryConfig `yaml:"registries" json:"registries,omitempty"` - Services []ServiceConfig `yaml:"services" json:"services,omitempty"` - Protocols []ProtocolConfig `yaml:"protocols" json:"protocols,omitempty"` + ApplicationConfig ApplicationConfig `yaml:"application_config" json:"application_config,omitempty"` + Path string `yaml:"path" json:"path,omitempty"` + Registries []RegistryConfig `yaml:"registries" json:"registries,omitempty"` + Services []ServiceConfig `yaml:"services" json:"services,omitempty"` + Protocols []ProtocolConfig `yaml:"protocols" json:"protocols,omitempty"` } func SetProviderConfig(p ProviderConfig) { diff --git a/config/support/reference_config.go b/config/support/reference_config.go index 88d934a43..4097afbaf 100644 --- a/config/support/reference_config.go +++ b/config/support/reference_config.go @@ -2,16 +2,16 @@ package support import ( "context" - "github.com/dubbo/dubbo-go/common/constant" - "github.com/dubbo/dubbo-go/config" "net/url" "strconv" "time" ) import ( + "github.com/dubbo/dubbo-go/common/constant" "github.com/dubbo/dubbo-go/common/extension" "github.com/dubbo/dubbo-go/common/proxy" + "github.com/dubbo/dubbo-go/config" "github.com/dubbo/dubbo-go/protocol" ) @@ -77,6 +77,15 @@ func (refconfig *ReferenceConfig) getUrlMap() url.Values { //getty invoke async or sync urlMap.Set(constant.ASYNC_KEY, strconv.FormatBool(refconfig.Async)) + //application info + urlMap.Set(constant.APPLICATION_KEY, consumerConfig.ApplicationConfig.Name) + urlMap.Set(constant.ORGANIZATION_KEY, consumerConfig.ApplicationConfig.Organization) + urlMap.Set(constant.NAME_KEY, consumerConfig.ApplicationConfig.Name) + urlMap.Set(constant.MODULE_KEY, consumerConfig.ApplicationConfig.Module) + urlMap.Set(constant.APP_VERSION_KEY, consumerConfig.ApplicationConfig.Version) + urlMap.Set(constant.OWNER_KEY, consumerConfig.ApplicationConfig.Owner) + urlMap.Set(constant.ENVIRONMENT_KEY, consumerConfig.ApplicationConfig.Environment) + for _, v := range refconfig.Methods { urlMap.Set("methods."+v.name+"."+constant.LOADBALANCE_KEY, v.loadbalance) urlMap.Set("methods."+v.name+"."+constant.RETRIES_KEY, strconv.FormatInt(v.retries, 10)) diff --git a/config/support/service_config.go b/config/support/service_config.go index f7762ca0e..6aa937a28 100644 --- a/config/support/service_config.go +++ b/config/support/service_config.go @@ -107,6 +107,15 @@ func (srvconfig *ServiceConfig) getUrlMap() url.Values { urlMap.Set(constant.WARMUP_KEY, srvconfig.warmup) urlMap.Set(constant.RETRIES_KEY, strconv.FormatInt(srvconfig.retries, 10)) + //application info + urlMap.Set(constant.APPLICATION_KEY, providerConfig.ApplicationConfig.Name) + urlMap.Set(constant.ORGANIZATION_KEY, providerConfig.ApplicationConfig.Organization) + urlMap.Set(constant.NAME_KEY, providerConfig.ApplicationConfig.Name) + urlMap.Set(constant.MODULE_KEY, providerConfig.ApplicationConfig.Module) + urlMap.Set(constant.APP_VERSION_KEY, providerConfig.ApplicationConfig.Version) + urlMap.Set(constant.OWNER_KEY, providerConfig.ApplicationConfig.Owner) + urlMap.Set(constant.ENVIRONMENT_KEY, providerConfig.ApplicationConfig.Environment) + for _, v := range srvconfig.Methods { urlMap.Set("methods."+v.name+"."+constant.LOADBALANCE_KEY, v.loadbalance) urlMap.Set("methods."+v.name+"."+constant.RETRIES_KEY, strconv.FormatInt(v.retries, 10)) diff --git a/registry/zookeeper/registry.go b/registry/zookeeper/registry.go index 48fe411e5..585c67476 100644 --- a/registry/zookeeper/registry.go +++ b/registry/zookeeper/registry.go @@ -6,6 +6,7 @@ import ( "net/url" "os" "strconv" + "strings" "sync" "time" ) @@ -18,6 +19,7 @@ import ( ) import ( + "github.com/dubbo/dubbo-go/common/constant" "github.com/dubbo/dubbo-go/common/extension" "github.com/dubbo/dubbo-go/config" "github.com/dubbo/dubbo-go/registry" @@ -78,12 +80,12 @@ func NewZkRegistry(url *config.RegistryURL) (registry.Registry, error) { zkPath: make(map[string]int), } - if r.Name == "" { - r.Name = RegistryZkClient - } - if r.Version == "" { - r.Version = version.Version - } + //if r.URL.Name == "" { + // r.URL.Name = RegistryZkClient + //} + //if r.Version == "" { + // r.Version = version.Version + //} if r.Timeout == 0 { r.Timeout = 1e9 @@ -283,12 +285,12 @@ func (r *ZkRegistry) register(c config.URL) error { } params = url.Values{} - params.Add("application", r.Name) + params.Add("application", c.GetParam(constant.APPLICATION_KEY, "")) params.Add("default.timeout", fmt.Sprintf("%d", defaultTimeout/1e6)) - params.Add("environment", r.Environment) - params.Add("org", r.Organization) - params.Add("module", r.Module) - params.Add("owner", r.Owner) + params.Add("environment", c.GetParam(constant.ENVIRONMENT_KEY, "")) + params.Add("org", c.GetParam(constant.ORGANIZATION_KEY, "")) + params.Add("module", c.GetParam(constant.MODULE_KEY, "")) + params.Add("owner", c.GetParam(constant.OWNER_KEY, "")) params.Add("pid", processID) params.Add("ip", localIP) params.Add("timeout", fmt.Sprintf("%d", int64(r.Timeout)/1e6)) @@ -309,7 +311,7 @@ func (r *ZkRegistry) register(c config.URL) error { case config.PROVIDER: - if conf.Service == "" || conf.Methods == "" { + if conf.Service == "" || len(conf.Methods) == 0 { return jerrors.Errorf("conf{Service:%s, Methods:%s}", conf.Service, conf.Methods) } // 鍏堝垱寤烘湇鍔′笅闈㈢殑provider node @@ -338,8 +340,8 @@ func (r *ZkRegistry) register(c config.URL) error { if conf.Version != "" { params.Add("version", conf.Version) } - if conf.Methods != "" { - params.Add("methods", conf.Methods) + if len(conf.Methods) == 0 { + params.Add("methods", strings.Join(conf.Methods, ",")) } log.Debug("provider zk url params:%#v", params) var path = conf.Path -- GitLab