From a94746db74a9d1d3deca2cf12085e3fb19bf4e72 Mon Sep 17 00:00:00 2001 From: "vito.he" Date: Thu, 4 Jul 2019 10:33:52 +0800 Subject: [PATCH 01/34] Add: define configurator --- cluster/configuration.go | 8 ++ cluster/configurator/override.go | 102 ++++++++++++++++++ cluster/configurator/override_test.go | 55 ++++++++++ common/constant/default.go | 14 ++- common/constant/key.go | 25 +++-- common/extension/configurator.go | 39 +++++++ common/url.go | 18 +++- common/url_test.go | 10 ++ examples/jsonrpc/go-client/app/client.go | 2 +- .../dubbo.client.properties | 15 +++ .../dubbo.properties | 15 +++ registry/directory/directory.go | 10 ++ registry/zookeeper/registry.go | 2 +- remoting/listener.go | 2 +- remoting/zookeeper/listener.go | 2 +- 15 files changed, 302 insertions(+), 17 deletions(-) create mode 100644 cluster/configuration.go create mode 100644 cluster/configurator/override.go create mode 100644 cluster/configurator/override_test.go create mode 100644 common/extension/configurator.go create mode 100644 examples/jsonrpc/with-configcenter-go-client/dubbo.client.properties create mode 100644 examples/jsonrpc/with-configcenter-go-server/dubbo.properties diff --git a/cluster/configuration.go b/cluster/configuration.go new file mode 100644 index 0000000000..ebe29a145d --- /dev/null +++ b/cluster/configuration.go @@ -0,0 +1,8 @@ +package cluster + +import "github.com/apache/dubbo-go/common" + +type Configurator interface { + GetUrl() *common.URL + Configure(url *common.URL) +} diff --git a/cluster/configurator/override.go b/cluster/configurator/override.go new file mode 100644 index 0000000000..7328cf7831 --- /dev/null +++ b/cluster/configurator/override.go @@ -0,0 +1,102 @@ +package configurator + +import ( + "github.com/apache/dubbo-go/cluster" + "github.com/apache/dubbo-go/common" + "github.com/apache/dubbo-go/common/constant" + "github.com/apache/dubbo-go/common/extension" + "github.com/apache/dubbo-go/common/utils" + "github.com/dubbogo/gost/container" + "strings" +) + +func init() { + extension.SetConfigurator("override", newConfigurator) +} +func newConfigurator(url *common.URL) cluster.Configurator { + return &overrideConfigurator{configuratorUrl: url} +} + +type overrideConfigurator struct { + configuratorUrl *common.URL +} + +func (c *overrideConfigurator) GetUrl() *common.URL { + return c.configuratorUrl +} + +func (c *overrideConfigurator) Configure(url *common.URL) { + //remove configuratorUrl some param that can not be configured + if c.configuratorUrl.GetParam(constant.ENABLED_KEY, "true") == "false" || len(c.configuratorUrl.Location) == 0 { + return + } + + //branch for version 2.7.x + apiVersion := c.configuratorUrl.GetParam(constant.CONFIG_VERSION_KEY, "") + if len(apiVersion) != 0 { + currentSide := url.GetParam(constant.SIDE_KEY, "") + configuratorSide := c.configuratorUrl.GetParam(constant.SIDE_KEY, "") + if currentSide == configuratorSide && common.DubboRole[common.CONSUMER] == currentSide && c.configuratorUrl.Port == "0" { + localIP, _ := utils.GetLocalIP() + c.configureIfMatch(localIP, url) + } else if currentSide == configuratorSide && common.DubboRole[common.PROVIDER] == currentSide && c.configuratorUrl.Port == url.Port { + c.configureIfMatch(url.Ip, url) + } + } else { + //branch for version 2.6.x and less + c.configureDeprecated(url) + } +} + +//translate from java, compatible rules in java +func (c *overrideConfigurator) configureIfMatch(host string, url *common.URL) { + if constant.ANYHOST_VALUE == c.configuratorUrl.Ip || host == c.configuratorUrl.Ip { + providers := c.configuratorUrl.GetParam(constant.OVERRIDE_PROVIDERS_KEY, "") + if len(providers) == 0 || strings.Index(providers, url.Location) >= 0 || strings.Index(providers, constant.ANYHOST_VALUE) >= 0 { + configApp := c.configuratorUrl.GetParam(constant.APPLICATION_KEY, c.configuratorUrl.Username) + currentApp := url.GetParam(constant.APPLICATION_KEY, url.Username) + if len(configApp) == 0 || constant.ANY_VALUE == configApp || configApp == currentApp { + conditionKeys := container.NewSet() + conditionKeys.Add(constant.CATEGORY_KEY) + conditionKeys.Add(constant.CHECK_KEY) + conditionKeys.Add(constant.ENABLED_KEY) + conditionKeys.Add(constant.GROUP_KEY) + conditionKeys.Add(constant.VERSION_KEY) + conditionKeys.Add(constant.APPLICATION_KEY) + conditionKeys.Add(constant.SIDE_KEY) + conditionKeys.Add(constant.CONFIG_VERSION_KEY) + conditionKeys.Add(constant.COMPATIBLE_CONFIG_KEY) + for k, _ := range c.configuratorUrl.Params { + value := c.configuratorUrl.Params.Get(k) + if strings.HasPrefix(k, "~") || k == constant.APPLICATION_KEY || k == constant.SIDE_KEY { + conditionKeys.Add(k) + if len(value) != 0 && value != constant.ANY_VALUE && value != c.configuratorUrl.Params.Get(strings.TrimPrefix(k, "~")) { + return + } + } + } + c.configuratorUrl.RemoveParams(conditionKeys) + url.SetParams(c.configuratorUrl.Params) + } + } + } +} + +func (c *overrideConfigurator) configureDeprecated(url *common.URL) { + // If override url has port, means it is a provider address. We want to control a specific provider with this override url, it may take effect on the specific provider instance or on consumers holding this provider instance. + if c.configuratorUrl.Port != "0" { + if url.Port == c.configuratorUrl.Port { + c.configureIfMatch(url.Ip, url) + } + } else { + // override url don't have a port, means the ip override url specify is a consumer address or 0.0.0.0 + // 1.If it is a consumer ip address, the intention is to control a specific consumer instance, it must takes effect at the consumer side, any provider received this override url should ignore; + // 2.If the ip is 0.0.0.0, this override url can be used on consumer, and also can be used on provider + if url.GetParam(constant.SIDE_KEY, "") == common.DubboRole[common.CONSUMER] { + localIP, _ := utils.GetLocalIP() + c.configureIfMatch(localIP, url) + } else { + c.configureIfMatch(constant.ANYHOST_VALUE, url) + } + } +} diff --git a/cluster/configurator/override_test.go b/cluster/configurator/override_test.go new file mode 100644 index 0000000000..0e763469c8 --- /dev/null +++ b/cluster/configurator/override_test.go @@ -0,0 +1,55 @@ +package configurator + +import ( + "context" + "github.com/apache/dubbo-go/common" + "github.com/apache/dubbo-go/common/constant" + "github.com/apache/dubbo-go/common/extension" + "github.com/stretchr/testify/assert" + "testing" +) + +func Test_configureVerison2p6(t *testing.T) { + url, err := common.NewURL(context.Background(), "override://0.0.0.0:0/com.xxx.mock.userProvider?group=1&version=1&cluster=failfast&application=BDTService") + assert.NoError(t, err) + configurator := extension.GetConfigurator("override", &url) + assert.Equal(t, "override", configurator.GetUrl().Protocol) + + providerUrl, err := common.NewURL(context.Background(), "jsonrpc://127.0.0.1:20001/com.ikurento.user.UserProvider?anyhost=true&app.version=0.0.1&application=BDTService&category=providers&cluster=failover&dubbo=dubbo-provider-golang-2.6.0&environment=dev&group=&interface=com.ikurento.user.UserProvider&ip=10.32.20.124&loadbalance=random&methods.GetUser.loadbalance=random&methods.GetUser.retries=1&methods.GetUser.weight=0&module=dubbogo+user-info+server&name=BDTService&organization=ikurento.com&owner=ZX&pid=64225&retries=0&service.filter=echo&side=provider×tamp=1562076628&version=&warmup=100") + configurator.Configure(&providerUrl) + assert.Equal(t, "failfast", providerUrl.Params.Get(constant.CLUSTER_KEY)) + +} +func Test_configureVerisonOverrideAddr(t *testing.T) { + url, err := common.NewURL(context.Background(), "override://0.0.0.0:0/com.xxx.mock.userProvider?group=1&version=1&cluster=failfast&application=BDTService&providerAddresses=127.0.0.2:20001|127.0.0.3:20001") + assert.NoError(t, err) + configurator := extension.GetConfigurator("override", &url) + assert.Equal(t, "override", configurator.GetUrl().Protocol) + + providerUrl, err := common.NewURL(context.Background(), "jsonrpc://127.0.0.1:20001/com.ikurento.user.UserProvider?anyhost=true&app.version=0.0.1&application=BDTService&category=providers&cluster=failover&dubbo=dubbo-provider-golang-2.6.0&environment=dev&group=&interface=com.ikurento.user.UserProvider&ip=10.32.20.124&loadbalance=random&methods.GetUser.loadbalance=random&methods.GetUser.retries=1&methods.GetUser.weight=0&module=dubbogo+user-info+server&name=BDTService&organization=ikurento.com&owner=ZX&pid=64225&retries=0&service.filter=echo&side=provider×tamp=1562076628&version=&warmup=100") + configurator.Configure(&providerUrl) + assert.Equal(t, "failover", providerUrl.Params.Get(constant.CLUSTER_KEY)) + +} +func Test_configureVerison2p6WithIp(t *testing.T) { + url, err := common.NewURL(context.Background(), "override://127.0.0.1:20001/com.xxx.mock.userProvider?group=1&version=1&cluster=failfast&application=BDTService") + assert.NoError(t, err) + configurator := extension.GetConfigurator("override", &url) + assert.Equal(t, "override", configurator.GetUrl().Protocol) + + providerUrl, err := common.NewURL(context.Background(), "jsonrpc://127.0.0.1:20001/com.ikurento.user.UserProvider?anyhost=true&app.version=0.0.1&application=BDTService&category=providers&cluster=failover&dubbo=dubbo-provider-golang-2.6.0&environment=dev&group=&interface=com.ikurento.user.UserProvider&ip=10.32.20.124&loadbalance=random&methods.GetUser.loadbalance=random&methods.GetUser.retries=1&methods.GetUser.weight=0&module=dubbogo+user-info+server&name=BDTService&organization=ikurento.com&owner=ZX&pid=64225&retries=0&service.filter=echo&side=provider×tamp=1562076628&version=&warmup=100") + configurator.Configure(&providerUrl) + assert.Equal(t, "failfast", providerUrl.Params.Get(constant.CLUSTER_KEY)) + +} + +func Test_configureVerison2p7(t *testing.T) { + url, err := common.NewURL(context.Background(), "jsonrpc://0.0.0.0:20001/com.xxx.mock.userProvider?group=1&version=1&cluster=failfast&application=BDTService&configVersion=1.0&side=provider") + assert.NoError(t, err) + configurator := extension.GetConfigurator("override", &url) + + providerUrl, err := common.NewURL(context.Background(), "jsonrpc://127.0.0.1:20001/com.ikurento.user.UserProvider?anyhost=true&app.version=0.0.1&application=BDTService&category=providers&cluster=failover&dubbo=dubbo-provider-golang-2.6.0&environment=dev&group=&interface=com.ikurento.user.UserProvider&ip=10.32.20.124&loadbalance=random&methods.GetUser.loadbalance=random&methods.GetUser.retries=1&methods.GetUser.weight=0&module=dubbogo+user-info+server&name=BDTService&organization=ikurento.com&owner=ZX&pid=64225&retries=0&service.filter=echo&side=provider×tamp=1562076628&version=&warmup=100") + configurator.Configure(&providerUrl) + assert.Equal(t, "failfast", providerUrl.Params.Get(constant.CLUSTER_KEY)) + +} diff --git a/common/constant/default.go b/common/constant/default.go index 05461ca6e7..503ccb23b3 100644 --- a/common/constant/default.go +++ b/common/constant/default.go @@ -18,8 +18,12 @@ package constant const ( - DUBBO = "dubbo" + DUBBO = "dubbo" + PROVIDER_PROTOCOL = "provider" + //compatible with 2.6.x + OVERRIDE_PROTOCOL = "override" ) + const ( DEFAULT_WEIGHT = 100 // DEFAULT_WARMUP = 10 * 60 // in java here is 10*60*1000 because of System.currentTimeMillis() is measured in milliseconds & in go time.Unix() is second @@ -42,5 +46,11 @@ const ( ) const ( - ANY_VALUE = "*" + ANY_VALUE = "*" + ANYHOST_VALUE = "0.0.0.0" +) + +const ( + CONFIGURATORS_CATEGORY = "configurators" + DEFAULT_CATEGORY = "providers" ) diff --git a/common/constant/key.go b/common/constant/key.go index 82df44c3e1..f045bc8e95 100644 --- a/common/constant/key.go +++ b/common/constant/key.go @@ -22,13 +22,18 @@ const ( ) const ( - GROUP_KEY = "group" - VERSION_KEY = "version" - INTERFACE_KEY = "interface" - PATH_KEY = "path" - SERVICE_KEY = "service" - METHODS_KEY = "methods" - TIMEOUT_KEY = "timeout" + GROUP_KEY = "group" + VERSION_KEY = "version" + INTERFACE_KEY = "interface" + PATH_KEY = "path" + SERVICE_KEY = "service" + METHODS_KEY = "methods" + TIMEOUT_KEY = "timeout" + CATEGORY_KEY = "category" + CHECK_KEY = "check" + ENABLED_KEY = "enabled" + SIDE_KEY = "side" + OVERRIDE_PROVIDERS_KEY = "providerAddresses" ) const ( @@ -73,8 +78,10 @@ const ( ) const ( - CONFIG_NAMESPACE_KEY = "config.namespace" - CONFIG_TIMEOUT_KET = "config.timeout" + CONFIG_NAMESPACE_KEY = "config.namespace" + CONFIG_TIMEOUT_KET = "config.timeout" + CONFIG_VERSION_KEY = "configVersion" + COMPATIBLE_CONFIG_KEY = "compatible_config" ) const ( RegistryConfigPrefix = "dubbo.registries." diff --git a/common/extension/configurator.go b/common/extension/configurator.go new file mode 100644 index 0000000000..4a2b4f8ae8 --- /dev/null +++ b/common/extension/configurator.go @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 extension + +import ( + "github.com/apache/dubbo-go/cluster" + "github.com/apache/dubbo-go/common" +) + +var ( + configurator = make(map[string]func(url *common.URL) cluster.Configurator) +) + +func SetConfigurator(name string, v func(url *common.URL) cluster.Configurator) { + configurator[name] = v +} + +func GetConfigurator(name string, url *common.URL) cluster.Configurator { + if configurator[name] == nil { + panic("config center for " + name + " is not existing, make sure you have import the package.") + } + return configurator[name](url) + +} diff --git a/common/url.go b/common/url.go index 47b44cf57f..f40feda3ee 100644 --- a/common/url.go +++ b/common/url.go @@ -22,6 +22,7 @@ import ( "context" "encoding/base64" "fmt" + "math" "net" "net/url" @@ -30,6 +31,7 @@ import ( ) import ( + "github.com/dubbogo/gost/container" perrors "github.com/pkg/errors" ) @@ -231,8 +233,8 @@ func (c URL) String() string { func (c URL) Key() string { buildString := fmt.Sprintf( - "%s://%s:%s@%s:%s/?interface=%s&group=%s&version=%s", - c.Protocol, c.Username, c.Password, c.Ip, c.Port, c.Service(), c.GetParam(constant.GROUP_KEY, ""), c.GetParam(constant.VERSION_KEY, "")) + "%s://%s:%s@%s:%s/?interface=%s&group=%s&version=%s&category_key=%s", + c.Protocol, c.Username, c.Password, c.Ip, c.Port, c.Service(), c.GetParam(constant.GROUP_KEY, ""), c.GetParam(constant.VERSION_KEY, ""), c.GetParam(constant.CATEGORY_KEY, "")) return buildString //return c.ServiceKey() } @@ -358,6 +360,18 @@ func (c URL) GetMethodParam(method string, key string, d string) string { } return r } +func (c *URL) RemoveParams(set *container.HashSet) { + for k, _ := range set.Items { + s := k.(string) + delete(c.Params, s) + } +} +func (c *URL) SetParams(m url.Values) { + + for k, _ := range m { + c.Params.Set(k, m.Get(k)) + } +} // ToMap transfer URL to Map func (c URL) ToMap() map[string]string { diff --git a/common/url_test.go b/common/url_test.go index 143e31cb34..68ed5b488c 100644 --- a/common/url_test.go +++ b/common/url_test.go @@ -232,3 +232,13 @@ func TestMergeUrl(t *testing.T) { assert.Equal(t, "1", mergedUrl.GetParam("test2", "")) assert.Equal(t, "1", mergedUrl.GetParam("test3", "")) } + +func TestURL_SetParams(t *testing.T) { + u1, err := NewURL(context.TODO(), "dubbo://:@127.0.0.1:20000/com.ikurento.user.UserProvider?interface=com.ikurento.user.UserProvider&group=&version=2.6.0&configVersion=1.0") + assert.NoError(t, err) + params := url.Values{} + params.Set("key", "3") + u1.SetParams(params) + assert.Equal(t, "3", u1.Params.Get("key")) + assert.Equal(t, "2.6.0", u1.Params.Get("version")) +} diff --git a/examples/jsonrpc/go-client/app/client.go b/examples/jsonrpc/go-client/app/client.go index 478a88d194..7a47e14bda 100644 --- a/examples/jsonrpc/go-client/app/client.go +++ b/examples/jsonrpc/go-client/app/client.go @@ -59,7 +59,7 @@ func main() { println("res: %v", res) } - time.Sleep(3e9) + time.Sleep(10e9) println("\n\n\nstart to test jsonrpc") user := &JsonRPCUser{} diff --git a/examples/jsonrpc/with-configcenter-go-client/dubbo.client.properties b/examples/jsonrpc/with-configcenter-go-client/dubbo.client.properties new file mode 100644 index 0000000000..c7e6e0e3dd --- /dev/null +++ b/examples/jsonrpc/with-configcenter-go-client/dubbo.client.properties @@ -0,0 +1,15 @@ +dubbo.consumer.check=true +dubbo.consumer.request_timeout=5s +dubbo.consumer.connect_timeout=5s +dubbo.application.organization=ikurento.com +dubbo.application.name=BDTService +dubbo.application.module=dubbogo user-info client +dubbo.application.version=0.0.1 +dubbo.application.owner=ZX1 +dubbo.application.environment=dev +dubbo.registries.hangzhouzk.protocol=zookeeper +dubbo.registries.hangzhouzk.timeout=3s +dubbo.registries.hangzhouzk.address=127.0.0.1:2181 +dubbo.registries.shanghaizk.protocol=zookeeper +dubbo.registries.shanghaizk.timeout=3s +dubbo.registries.shanghaizk.address=127.0.0.1:2182 diff --git a/examples/jsonrpc/with-configcenter-go-server/dubbo.properties b/examples/jsonrpc/with-configcenter-go-server/dubbo.properties new file mode 100644 index 0000000000..7477c41eb5 --- /dev/null +++ b/examples/jsonrpc/with-configcenter-go-server/dubbo.properties @@ -0,0 +1,15 @@ +dubbo.application.organization=ikurento.com +dubbo.application.name=BDTService +dubbo.application.module=dubbogo user-info server +dubbo.application.version=0.0.1 +dubbo.application.owner=ZX1 +dubbo.application.environment=dev +dubbo.registries.hangzhouzk.protocol=zookeeper +dubbo.registries.hangzhouzk.timeout=3s +dubbo.registries.hangzhouzk.address=127.0.0.1:2181 +dubbo.registries.shanghaizk.protocol=zookeeper +dubbo.registries.shanghaizk.timeout=3s +dubbo.registries.shanghaizk.address=127.0.0.1:2182 +dubbo.protocols.dubbo1.name=dubbo +dubbo.protocols.dubbo1.ip=127.0.0.1 +dubbo.protocols.dubbo1.port=20001 \ No newline at end of file diff --git a/registry/directory/directory.go b/registry/directory/directory.go index 11687f82ee..d9bc7921b8 100644 --- a/registry/directory/directory.go +++ b/registry/directory/directory.go @@ -85,6 +85,7 @@ func (dir *registryDirectory) Subscribe(url common.URL) { for { if !dir.registry.IsAvailable() { logger.Warnf("event listener game over.") + time.Sleep(time.Duration(RegistryConnDelay) * time.Second) return } @@ -234,3 +235,12 @@ func (dir *registryDirectory) Destroy() { dir.cacheInvokers = []protocol.Invoker{} }) } + +type referenceConfigurationListener struct { + directory *registryDirectory + url *common.URL +} + +func (l *referenceConfigurationListener) Process(event *remoting.ConfigChangeEvent) { + //l.directory.refreshInvokers(event) +} diff --git a/registry/zookeeper/registry.go b/registry/zookeeper/registry.go index 6b15133319..67a8b3b67f 100644 --- a/registry/zookeeper/registry.go +++ b/registry/zookeeper/registry.go @@ -421,7 +421,7 @@ func (r *zkRegistry) getListener(conf common.URL) (*RegistryConfigurationListene //注册到dataconfig的interested r.dataListener.AddInterestedURL(&conf) - go r.listener.ListenServiceEvent(fmt.Sprintf("/dubbo/%s/providers", conf.Service()), r.dataListener) + go r.listener.ListenServiceEvent(fmt.Sprintf("/dubbo/%s/"+conf.GetParam(constant.CATEGORY_KEY, constant.DEFAULT_CATEGORY), conf.Service()), r.dataListener) return zkListener, nil } diff --git a/remoting/listener.go b/remoting/listener.go index da30f6989d..866c8503bb 100644 --- a/remoting/listener.go +++ b/remoting/listener.go @@ -46,7 +46,7 @@ type EventType int const ( EventTypeAdd = iota EventTypeDel - EvnetTypeUpdate + EventTypeUpdate ) var serviceEventTypeStrings = [...]string{ diff --git a/remoting/zookeeper/listener.go b/remoting/zookeeper/listener.go index 5b9e0a8f82..78c83ba3b2 100644 --- a/remoting/zookeeper/listener.go +++ b/remoting/zookeeper/listener.go @@ -69,7 +69,7 @@ func (l *ZkEventListener) ListenServiceNodeEvent(zkPath string, listener ...remo logger.Warnf("zk.ExistW(key{%s}) = event{EventNodeDataChanged}", zkPath) if len(listener) > 0 { content, _, _ := l.client.Conn.Get(zkEvent.Path) - listener[0].DataChange(remoting.Event{Path: zkEvent.Path, Action: remoting.EvnetTypeUpdate, Content: string(content)}) + listener[0].DataChange(remoting.Event{Path: zkEvent.Path, Action: remoting.EventTypeUpdate, Content: string(content)}) } case zk.EventNodeCreated: From cf43b7527e10fed03656daf354e72fd7c0ce9b45 Mon Sep 17 00:00:00 2001 From: "vito.he" Date: Sun, 1 Sep 2019 00:21:53 +0800 Subject: [PATCH 02/34] Add: protocol config center commit --- common/config/environment.go | 16 +- common/constant/default.go | 7 +- common/constant/key.go | 8 +- common/extension/configurator.go | 18 +- common/url.go | 5 + config/base_config.go | 1 + config_center/configuration_listener.go | 22 ++ config_center/configuration_parser.go | 24 -- .../configurator.go | 6 +- config_center/configurator/mock.go | 22 ++ .../configurator/override.go | 12 +- .../configurator/override_test.go | 0 config_center/dynamic_configuration.go | 10 +- config_center/mock_dynamic_config.go | 14 +- config_center/parser/configuration_parser.go | 231 ++++++++++++++++++ .../{ => parser}/configuration_parser_test.go | 2 +- config_center/zookeeper/factory.go | 3 +- config_center/zookeeper/impl.go | 12 +- config_center/zookeeper/impl_test.go | 3 +- config_center/zookeeper/listener.go | 15 +- registry/base_configuration_listener.go | 76 ++++++ registry/directory/directory.go | 3 +- registry/directory/directory_test.go | 4 +- registry/mock_registry.go | 38 ++- registry/protocol/protocol.go | 82 ++++++- registry/protocol/protocol_test.go | 13 + registry/zookeeper/listener.go | 13 +- remoting/etcdv3/listener.go | 2 +- remoting/listener.go | 18 +- 29 files changed, 576 insertions(+), 104 deletions(-) create mode 100644 config_center/configuration_listener.go delete mode 100644 config_center/configuration_parser.go rename cluster/configuration.go => config_center/configurator.go (54%) create mode 100644 config_center/configurator/mock.go rename {cluster => config_center}/configurator/override.go (96%) rename {cluster => config_center}/configurator/override_test.go (100%) create mode 100644 config_center/parser/configuration_parser.go rename config_center/{ => parser}/configuration_parser_test.go (94%) create mode 100644 registry/base_configuration_listener.go diff --git a/common/config/environment.go b/common/config/environment.go index 8709d69a78..77a962a511 100644 --- a/common/config/environment.go +++ b/common/config/environment.go @@ -19,6 +19,7 @@ package config import ( "container/list" + "github.com/apache/dubbo-go/config_center" "strings" "sync" ) @@ -29,9 +30,10 @@ import ( // We just have config center configuration which can override configuration in consumer.yaml & provider.yaml. // But for add these features in future ,I finish the environment struct following Environment class in java. type Environment struct { - configCenterFirst bool - externalConfigs sync.Map - externalConfigMap sync.Map + configCenterFirst bool + externalConfigs sync.Map + externalConfigMap sync.Map + dynamicConfiguration config_center.DynamicConfiguration } var ( @@ -68,6 +70,14 @@ func (env *Environment) Configuration() *list.List { return list } +func (env *Environment) SetDynamicConfiguration(dc config_center.DynamicConfiguration) { + env.dynamicConfiguration = dc +} + +func (env *Environment) GetDynamicConfiguration() config_center.DynamicConfiguration { + return env.dynamicConfiguration +} + type InmemoryConfiguration struct { store *sync.Map } diff --git a/common/constant/default.go b/common/constant/default.go index e5c92fad4d..b7b8bb0237 100644 --- a/common/constant/default.go +++ b/common/constant/default.go @@ -22,6 +22,7 @@ const ( PROVIDER_PROTOCOL = "provider" //compatible with 2.6.x OVERRIDE_PROTOCOL = "override" + EMPTY_PROTOCOL = "empty" ) const ( @@ -56,6 +57,8 @@ const ( ) const ( - CONFIGURATORS_CATEGORY = "configurators" - DEFAULT_CATEGORY = "providers" + CONFIGURATORS_CATEGORY = "configurators" + DEFAULT_CATEGORY = "providers" + DYNAMIC_CONFIGURATORS_CATEGORY = "dynamicconfigurators" + APP_DYNAMIC_CONFIGURATORS_CATEGORY = "appdynamicconfigurators" ) diff --git a/common/constant/key.go b/common/constant/key.go index 13d65eb6f8..e8db5713e3 100644 --- a/common/constant/key.go +++ b/common/constant/key.go @@ -34,8 +34,8 @@ const ( ENABLED_KEY = "enabled" SIDE_KEY = "side" OVERRIDE_PROVIDERS_KEY = "providerAddresses" - BEAN_NAME_KEY = "bean.name" - GENERIC_KEY = "generic" + BEAN_NAME_KEY = "bean.name" + GENERIC_KEY = "generic" ) const ( @@ -98,6 +98,10 @@ const ( ConsumerConfigPrefix = "dubbo.consumer." ) +const ( + CONFIGURATORS_SUFFIX = ".configurators" +) + const ( NACOS_KEY = "nacos" NACOS_DEFAULT_ROLETYPE = 3 diff --git a/common/extension/configurator.go b/common/extension/configurator.go index 99cc8bdb98..f7e1a263cd 100644 --- a/common/extension/configurator.go +++ b/common/extension/configurator.go @@ -18,33 +18,39 @@ package extension import ( - "github.com/apache/dubbo-go/cluster" "github.com/apache/dubbo-go/common" + "github.com/apache/dubbo-go/config_center" ) var ( - configurator = make(map[string]func(url *common.URL) cluster.Configurator) + configurator = make(map[string]func(url *common.URL) config_center.Configurator) ) -func SetConfigurator(name string, v func(url *common.URL) cluster.Configurator) { +func SetConfigurator(name string, v func(url *common.URL) config_center.Configurator) { configurator[name] = v } -func GetConfigurator(name string, url *common.URL) cluster.Configurator { +func GetConfigurator(name string, url *common.URL) config_center.Configurator { if configurator[name] == nil { panic("config center for " + name + " is not existing, make sure you have import the package.") } return configurator[name](url) } -func SetDefaultConfigurator(v func(url *common.URL) cluster.Configurator) { +func SetDefaultConfigurator(v func(url *common.URL) config_center.Configurator) { configurator["default"] = v } -func GetDefaultConfigurator(url *common.URL) cluster.Configurator { +func GetDefaultConfigurator(url *common.URL) config_center.Configurator { if configurator["default"] == nil { panic("config center for default is not existing, make sure you have import the package.") } return configurator["default"](url) } +func GetDefaultConfiguratorFunc() func(url *common.URL) config_center.Configurator { + if configurator["default"] == nil { + panic("config center for default is not existing, make sure you have import the package.") + } + return configurator["default"] +} diff --git a/common/url.go b/common/url.go index 52472d463a..4d9f6d1208 100644 --- a/common/url.go +++ b/common/url.go @@ -288,6 +288,11 @@ func (c URL) ServiceKey() string { return buf.String() } +func (c *URL) EncodedServiceKey() string { + serviceKey := c.ServiceKey() + return strings.Replace(serviceKey, "/", "*", 1) +} + func (c URL) Context() context.Context { return c.ctx } diff --git a/config/base_config.go b/config/base_config.go index 54ad8aba36..65cc0fe3f9 100644 --- a/config/base_config.go +++ b/config/base_config.go @@ -60,6 +60,7 @@ func (c *BaseConfig) prepareEnvironment() error { factory := extension.GetConfigCenterFactory(c.ConfigCenterConfig.Protocol) dynamicConfig, err := factory.GetDynamicConfiguration(c.configCenterUrl) + config.GetEnvInstance().SetDynamicConfiguration(dynamicConfig) if err != nil { logger.Errorf("Get dynamic configuration error , error message is %v", err) return perrors.WithStack(err) diff --git a/config_center/configuration_listener.go b/config_center/configuration_listener.go new file mode 100644 index 0000000000..5367ee72df --- /dev/null +++ b/config_center/configuration_listener.go @@ -0,0 +1,22 @@ +package config_center + +import ( + "fmt" +) +import ( + "github.com/apache/dubbo-go/remoting" +) + +type ConfigurationListener interface { + Process(*ConfigChangeEvent) +} + +type ConfigChangeEvent struct { + Key string + Value interface{} + ConfigType remoting.EventType +} + +func (c ConfigChangeEvent) String() string { + return fmt.Sprintf("ConfigChangeEvent{key = %v , value = %v , changeType = %v}", c.Key, c.Value, c.ConfigType) +} diff --git a/config_center/configuration_parser.go b/config_center/configuration_parser.go deleted file mode 100644 index ab02789c92..0000000000 --- a/config_center/configuration_parser.go +++ /dev/null @@ -1,24 +0,0 @@ -package config_center - -import ( - "github.com/magiconair/properties" -) -import ( - "github.com/apache/dubbo-go/common/logger" -) - -type ConfigurationParser interface { - Parse(string) (map[string]string, error) -} - -//for support properties file in config center -type DefaultConfigurationParser struct{} - -func (parser *DefaultConfigurationParser) Parse(content string) (map[string]string, error) { - properties, err := properties.LoadString(content) - if err != nil { - logger.Errorf("Parse the content {%v} in DefaultConfigurationParser error ,error message is {%v}", content, err) - return nil, err - } - return properties.Map(), nil -} diff --git a/cluster/configuration.go b/config_center/configurator.go similarity index 54% rename from cluster/configuration.go rename to config_center/configurator.go index ebe29a145d..0b0b1ddee8 100644 --- a/cluster/configuration.go +++ b/config_center/configurator.go @@ -1,6 +1,8 @@ -package cluster +package config_center -import "github.com/apache/dubbo-go/common" +import ( + "github.com/apache/dubbo-go/common" +) type Configurator interface { GetUrl() *common.URL diff --git a/config_center/configurator/mock.go b/config_center/configurator/mock.go new file mode 100644 index 0000000000..8547d562e1 --- /dev/null +++ b/config_center/configurator/mock.go @@ -0,0 +1,22 @@ +package configurator + +import ( + "github.com/apache/dubbo-go/common" + "github.com/apache/dubbo-go/config_center" +) + +func NewMockConfigurator(url *common.URL) config_center.Configurator { + return &mockConfigurator{configuratorUrl: url} +} + +type mockConfigurator struct { + configuratorUrl *common.URL +} + +func (c *mockConfigurator) GetUrl() *common.URL { + return c.configuratorUrl +} + +func (c *mockConfigurator) Configure(url *common.URL) { + +} diff --git a/cluster/configurator/override.go b/config_center/configurator/override.go similarity index 96% rename from cluster/configurator/override.go rename to config_center/configurator/override.go index 797665e513..78ab3d8533 100644 --- a/cluster/configurator/override.go +++ b/config_center/configurator/override.go @@ -1,19 +1,23 @@ package configurator import ( - "github.com/apache/dubbo-go/cluster" + "strings" +) +import ( + "github.com/dubbogo/gost/container" +) +import ( "github.com/apache/dubbo-go/common" "github.com/apache/dubbo-go/common/constant" "github.com/apache/dubbo-go/common/extension" "github.com/apache/dubbo-go/common/utils" - "github.com/dubbogo/gost/container" - "strings" + "github.com/apache/dubbo-go/config_center" ) func init() { extension.SetDefaultConfigurator(newConfigurator) } -func newConfigurator(url *common.URL) cluster.Configurator { +func newConfigurator(url *common.URL) config_center.Configurator { return &overrideConfigurator{configuratorUrl: url} } diff --git a/cluster/configurator/override_test.go b/config_center/configurator/override_test.go similarity index 100% rename from cluster/configurator/override_test.go rename to config_center/configurator/override_test.go diff --git a/config_center/dynamic_configuration.go b/config_center/dynamic_configuration.go index 3b829507b1..c3718ee4c9 100644 --- a/config_center/dynamic_configuration.go +++ b/config_center/dynamic_configuration.go @@ -21,7 +21,7 @@ import ( "time" ) import ( - "github.com/apache/dubbo-go/remoting" + "github.com/apache/dubbo-go/config_center/parser" ) ////////////////////////////////////////// @@ -31,10 +31,10 @@ const DEFAULT_GROUP = "dubbo" const DEFAULT_CONFIG_TIMEOUT = "10s" type DynamicConfiguration interface { - Parser() ConfigurationParser - SetParser(ConfigurationParser) - AddListener(string, remoting.ConfigurationListener, ...Option) - RemoveListener(string, remoting.ConfigurationListener, ...Option) + Parser() parser.ConfigurationParser + SetParser(parser.ConfigurationParser) + AddListener(string, ConfigurationListener, ...Option) + RemoveListener(string, ConfigurationListener, ...Option) GetConfig(string, ...Option) (string, error) GetConfigs(string, ...Option) (string, error) } diff --git a/config_center/mock_dynamic_config.go b/config_center/mock_dynamic_config.go index a6c7267a4f..7ecffca160 100644 --- a/config_center/mock_dynamic_config.go +++ b/config_center/mock_dynamic_config.go @@ -18,11 +18,11 @@ package config_center import ( + "github.com/apache/dubbo-go/config_center/parser" "sync" ) import ( "github.com/apache/dubbo-go/common" - "github.com/apache/dubbo-go/remoting" ) type MockDynamicConfigurationFactory struct{} @@ -36,7 +36,7 @@ func (f *MockDynamicConfigurationFactory) GetDynamicConfiguration(url *common.UR var err error once.Do(func() { dynamicConfiguration = &mockDynamicConfiguration{} - dynamicConfiguration.SetParser(&DefaultConfigurationParser{}) + dynamicConfiguration.SetParser(&parser.DefaultConfigurationParser{}) dynamicConfiguration.content = ` dubbo.consumer.request_timeout=5s dubbo.consumer.connect_timeout=5s @@ -67,14 +67,14 @@ func (f *MockDynamicConfigurationFactory) GetDynamicConfiguration(url *common.UR } type mockDynamicConfiguration struct { - parser ConfigurationParser + parser parser.ConfigurationParser content string } -func (c *mockDynamicConfiguration) AddListener(key string, listener remoting.ConfigurationListener, opions ...Option) { +func (c *mockDynamicConfiguration) AddListener(key string, listener ConfigurationListener, opions ...Option) { } -func (c *mockDynamicConfiguration) RemoveListener(key string, listener remoting.ConfigurationListener, opions ...Option) { +func (c *mockDynamicConfiguration) RemoveListener(key string, listener ConfigurationListener, opions ...Option) { } func (c *mockDynamicConfiguration) GetConfig(key string, opts ...Option) (string, error) { @@ -87,9 +87,9 @@ func (c *mockDynamicConfiguration) GetConfigs(key string, opts ...Option) (strin return c.GetConfig(key, opts...) } -func (c *mockDynamicConfiguration) Parser() ConfigurationParser { +func (c *mockDynamicConfiguration) Parser() parser.ConfigurationParser { return c.parser } -func (c *mockDynamicConfiguration) SetParser(p ConfigurationParser) { +func (c *mockDynamicConfiguration) SetParser(p parser.ConfigurationParser) { c.parser = p } diff --git a/config_center/parser/configuration_parser.go b/config_center/parser/configuration_parser.go new file mode 100644 index 0000000000..34d5f26763 --- /dev/null +++ b/config_center/parser/configuration_parser.go @@ -0,0 +1,231 @@ +package parser + +import ( + "context" + "strconv" + "strings" +) +import ( + "github.com/magiconair/properties" + perrors "github.com/pkg/errors" + "gopkg.in/yaml.v2" +) +import ( + "github.com/apache/dubbo-go/common" + "github.com/apache/dubbo-go/common/constant" + "github.com/apache/dubbo-go/common/logger" +) + +type ConfigurationParser interface { + Parse(string) (map[string]string, error) + ParseToUrls(content string) ([]*common.URL, error) +} + +//for support properties file in config center +type DefaultConfigurationParser struct{} + +func (parser *DefaultConfigurationParser) Parse(content string) (map[string]string, error) { + properties, err := properties.LoadString(content) + if err != nil { + logger.Errorf("Parse the content {%v} in DefaultConfigurationParser error ,error message is {%v}", content, err) + return nil, err + } + return properties.Map(), nil +} + +func (parser *DefaultConfigurationParser) ParseToUrls(content string) ([]*common.URL, error) { + config := ConfiguratorConfig{} + if err := yaml.Unmarshal([]byte(content), &config); err != nil { + return nil, err + } + scope := config.Scope + items := config.Configs + var allUrls []*common.URL + if scope == ScopeApplication { + for _, v := range items { + urls, err := appItemToUrls(v, config) + if err != nil { + return nil, err + } + allUrls = append(allUrls, urls...) + } + } else { + for _, v := range items { + urls, err := serviceItemToUrls(v, config) + if err != nil { + return nil, err + } + allUrls = append(allUrls, urls...) + } + } + return allUrls, nil +} +func serviceItemToUrls(item ConfigItem, config ConfiguratorConfig) ([]*common.URL, error) { + var addresses = item.Addresses + if len(addresses) == 0 { + addresses = append(addresses, constant.ANYHOST_VALUE) + } + var urls []*common.URL + for _, v := range addresses { + urlStr := constant.OVERRIDE_PROTOCOL + "://" + v + "/" + serviceStr, err := getServiceString(config.Key) + if err != nil { + return nil, perrors.WithStack(err) + } + urlStr = urlStr + serviceStr + paramStr, err := getParamString(item) + if err != nil { + return nil, perrors.WithStack(err) + } + urlStr = urlStr + paramStr + urlStr = urlStr + getEnabledString(item, config) + urlStr = urlStr + "&category=" + urlStr = urlStr + constant.DYNAMIC_CONFIGURATORS_CATEGORY + urlStr = urlStr + "&configVersion=" + urlStr = urlStr + config.ConfigVersion + apps := item.Applications + if len(apps) > 0 { + for _, v := range apps { + newUrlStr := urlStr + newUrlStr = newUrlStr + "&application" + newUrlStr = newUrlStr + v + url, err := common.NewURL(context.Background(), newUrlStr) + if err != nil { + perrors.WithStack(err) + } + urls = append(urls, &url) + } + } else { + url, err := common.NewURL(context.Background(), urlStr) + if err != nil { + perrors.WithStack(err) + } + urls = append(urls, &url) + } + } + return urls, nil +} +func appItemToUrls(item ConfigItem, config ConfiguratorConfig) ([]*common.URL, error) { + var addresses = item.Addresses + if len(addresses) == 0 { + addresses = append(addresses, constant.ANYHOST_VALUE) + } + var urls []*common.URL + for _, v := range addresses { + urlStr := constant.OVERRIDE_PROTOCOL + "://" + v + "/" + services := item.Services + if len(services) == 0 { + services = append(services, constant.ANY_VALUE) + } + for _, vs := range services { + serviceStr, err := getServiceString(vs) + if err != nil { + return nil, perrors.WithStack(err) + } + urlStr = urlStr + serviceStr + paramStr, err := getParamString(item) + if err != nil { + return nil, perrors.WithStack(err) + } + urlStr = urlStr + paramStr + urlStr = urlStr + "&application=" + urlStr = urlStr + config.Key + urlStr = urlStr + getEnabledString(item, config) + urlStr = urlStr + "&category=" + urlStr = urlStr + constant.APP_DYNAMIC_CONFIGURATORS_CATEGORY + urlStr = urlStr + "&configVersion=" + urlStr = urlStr + config.ConfigVersion + url, err := common.NewURL(context.Background(), urlStr) + if err != nil { + perrors.WithStack(err) + } + urls = append(urls, &url) + } + } + return urls, nil +} + +func getServiceString(service string) (string, error) { + if len(service) == 0 { + return "", perrors.New("service field in configuration is null.") + } + var serviceStr string + i := strings.Index(service, "/") + if i > 0 { + serviceStr = serviceStr + "group=" + serviceStr = serviceStr + service[0:i] + serviceStr = serviceStr + "&" + service = service[i+1:] + } + j := strings.Index(service, ":") + if j > 0 { + serviceStr = serviceStr + "version=" + serviceStr = serviceStr + service[j+1:] + serviceStr = serviceStr + "&" + service = service[0:j] + } + serviceStr = service + "?" + serviceStr + return serviceStr, nil +} + +func getParamString(item ConfigItem) (string, error) { + var retStr string + retStr = retStr + "category=" + retStr = retStr + constant.DYNAMIC_CONFIGURATORS_CATEGORY + if len(item.Side) > 0 { + retStr = retStr + "&side=" + retStr = retStr + item.Side + } + params := item.Parameters + if len(params) <= 0 { + return "", perrors.New("Invalid configurator rule, please specify at least one parameter " + + "you want to change in the rule.") + } + for k, v := range params { + retStr = retStr + "&" + retStr = retStr + k + retStr = retStr + "=" + retStr = retStr + v + } + + if len(item.ProviderAddresses) >= 0 { + retStr = retStr + "&" + retStr = retStr + constant.OVERRIDE_PROVIDERS_KEY + retStr = retStr + "=" + retStr = retStr + strings.Join(item.ProviderAddresses, ",") + } + + return retStr, nil +} +func getEnabledString(item ConfigItem, config ConfiguratorConfig) string { + retStr := "&enabled=" + if len(item.Type) == 0 || item.Type == GeneralType { + retStr = retStr + strconv.FormatBool(config.Enabled) + } else { + retStr = retStr + strconv.FormatBool(item.Enabled) + } + return retStr +} + +const ( + ScopeApplication = "application" + GeneralType = "general" +) + +type ConfiguratorConfig struct { + ConfigVersion string + Scope string + Key string + Enabled bool + Configs []ConfigItem +} +type ConfigItem struct { + Type string + Enabled bool + Addresses []string + ProviderAddresses []string + Services []string + Applications []string + Parameters map[string]string + Side string +} diff --git a/config_center/configuration_parser_test.go b/config_center/parser/configuration_parser_test.go similarity index 94% rename from config_center/configuration_parser_test.go rename to config_center/parser/configuration_parser_test.go index 3c84fd70b0..08490e8581 100644 --- a/config_center/configuration_parser_test.go +++ b/config_center/parser/configuration_parser_test.go @@ -1,4 +1,4 @@ -package config_center +package parser import ( "testing" diff --git a/config_center/zookeeper/factory.go b/config_center/zookeeper/factory.go index c1c7e27b14..ac10d2a76f 100644 --- a/config_center/zookeeper/factory.go +++ b/config_center/zookeeper/factory.go @@ -18,6 +18,7 @@ package zookeeper import ( + "github.com/apache/dubbo-go/config_center/parser" "sync" ) import ( @@ -44,7 +45,7 @@ func (f *zookeeperDynamicConfigurationFactory) GetDynamicConfiguration(url *comm if err != nil { return nil, err } - dynamicConfiguration.SetParser(&config_center.DefaultConfigurationParser{}) + dynamicConfiguration.SetParser(&parser.DefaultConfigurationParser{}) return dynamicConfiguration, err } diff --git a/config_center/zookeeper/impl.go b/config_center/zookeeper/impl.go index f2827b2bb6..1858a5a83d 100644 --- a/config_center/zookeeper/impl.go +++ b/config_center/zookeeper/impl.go @@ -18,6 +18,7 @@ package zookeeper import ( + "github.com/apache/dubbo-go/config_center/parser" "strings" "sync" "time" @@ -31,7 +32,6 @@ import ( "github.com/apache/dubbo-go/common/constant" "github.com/apache/dubbo-go/common/logger" "github.com/apache/dubbo-go/config_center" - "github.com/apache/dubbo-go/remoting" "github.com/apache/dubbo-go/remoting/zookeeper" ) @@ -48,7 +48,7 @@ type zookeeperDynamicConfiguration struct { listenerLock sync.Mutex listener *zookeeper.ZkEventListener cacheListener *CacheListener - parser config_center.ConfigurationParser + parser parser.ConfigurationParser } func newZookeeperDynamicConfiguration(url *common.URL) (*zookeeperDynamicConfiguration, error) { @@ -99,11 +99,11 @@ func newMockZookeeperDynamicConfiguration(url *common.URL, opts ...zookeeper.Opt } -func (c *zookeeperDynamicConfiguration) AddListener(key string, listener remoting.ConfigurationListener, opions ...config_center.Option) { +func (c *zookeeperDynamicConfiguration) AddListener(key string, listener config_center.ConfigurationListener, opions ...config_center.Option) { c.cacheListener.AddListener(key, listener) } -func (c *zookeeperDynamicConfiguration) RemoveListener(key string, listener remoting.ConfigurationListener, opions ...config_center.Option) { +func (c *zookeeperDynamicConfiguration) RemoveListener(key string, listener config_center.ConfigurationListener, opions ...config_center.Option) { c.cacheListener.RemoveListener(key, listener) } @@ -143,10 +143,10 @@ func (c *zookeeperDynamicConfiguration) GetConfigs(key string, opts ...config_ce return c.GetConfig(key, opts...) } -func (c *zookeeperDynamicConfiguration) Parser() config_center.ConfigurationParser { +func (c *zookeeperDynamicConfiguration) Parser() parser.ConfigurationParser { return c.parser } -func (c *zookeeperDynamicConfiguration) SetParser(p config_center.ConfigurationParser) { +func (c *zookeeperDynamicConfiguration) SetParser(p parser.ConfigurationParser) { c.parser = p } diff --git a/config_center/zookeeper/impl_test.go b/config_center/zookeeper/impl_test.go index 26b899e82d..b200b9cdbf 100644 --- a/config_center/zookeeper/impl_test.go +++ b/config_center/zookeeper/impl_test.go @@ -19,6 +19,7 @@ package zookeeper import ( "context" "fmt" + "github.com/apache/dubbo-go/config_center/parser" "sync" "testing" ) @@ -37,7 +38,7 @@ import ( func initZkData(group string, t *testing.T) (*zk.TestCluster, *zookeeperDynamicConfiguration) { regurl, _ := common.NewURL(context.TODO(), "registry://127.0.0.1:1111") ts, reg, err := newMockZookeeperDynamicConfiguration(®url) - reg.SetParser(&config_center.DefaultConfigurationParser{}) + reg.SetParser(&parser.DefaultConfigurationParser{}) assert.NoError(t, err) diff --git a/config_center/zookeeper/listener.go b/config_center/zookeeper/listener.go index c79c05c9bc..0874f0c2f7 100644 --- a/config_center/zookeeper/listener.go +++ b/config_center/zookeeper/listener.go @@ -22,6 +22,7 @@ import ( "sync" ) import ( + "github.com/apache/dubbo-go/config_center" "github.com/apache/dubbo-go/remoting" ) @@ -33,21 +34,21 @@ type CacheListener struct { func NewCacheListener(rootPath string) *CacheListener { return &CacheListener{rootPath: rootPath} } -func (l *CacheListener) AddListener(key string, listener remoting.ConfigurationListener) { +func (l *CacheListener) AddListener(key string, listener config_center.ConfigurationListener) { // reference from https://stackoverflow.com/questions/34018908/golang-why-dont-we-have-a-set-datastructure // make a map[your type]struct{} like set in java - listeners, loaded := l.keyListeners.LoadOrStore(key, map[remoting.ConfigurationListener]struct{}{listener: struct{}{}}) + listeners, loaded := l.keyListeners.LoadOrStore(key, map[config_center.ConfigurationListener]struct{}{listener: struct{}{}}) if loaded { - listeners.(map[remoting.ConfigurationListener]struct{})[listener] = struct{}{} + listeners.(map[config_center.ConfigurationListener]struct{})[listener] = struct{}{} l.keyListeners.Store(key, listeners) } } -func (l *CacheListener) RemoveListener(key string, listener remoting.ConfigurationListener) { +func (l *CacheListener) RemoveListener(key string, listener config_center.ConfigurationListener) { listeners, loaded := l.keyListeners.Load(key) if loaded { - delete(listeners.(map[remoting.ConfigurationListener]struct{}), listener) + delete(listeners.(map[config_center.ConfigurationListener]struct{}), listener) } } @@ -59,8 +60,8 @@ func (l *CacheListener) DataChange(event remoting.Event) bool { key := l.pathToKey(event.Path) if key != "" { if listeners, ok := l.keyListeners.Load(key); ok { - for listener := range listeners.(map[remoting.ConfigurationListener]struct{}) { - listener.Process(&remoting.ConfigChangeEvent{Key: key, Value: event.Content, ConfigType: event.Action}) + for listener := range listeners.(map[config_center.ConfigurationListener]struct{}) { + listener.Process(&config_center.ConfigChangeEvent{Key: key, Value: event.Content, ConfigType: event.Action}) } return true } diff --git a/registry/base_configuration_listener.go b/registry/base_configuration_listener.go new file mode 100644 index 0000000000..f209049877 --- /dev/null +++ b/registry/base_configuration_listener.go @@ -0,0 +1,76 @@ +package registry + +import ( + perrors "github.com/pkg/errors" +) +import ( + "github.com/apache/dubbo-go/common" + "github.com/apache/dubbo-go/common/config" + "github.com/apache/dubbo-go/common/constant" + "github.com/apache/dubbo-go/common/logger" + "github.com/apache/dubbo-go/config_center" + "github.com/apache/dubbo-go/remoting" +) + +type BaseConfigurationListener struct { + configurators []config_center.Configurator + dynamicConfiguration config_center.DynamicConfiguration + defaultConfiguratorFunc func(url *common.URL) config_center.Configurator +} + +func (bcl *BaseConfigurationListener) Configurators() []config_center.Configurator { + return bcl.configurators +} +func (bcl *BaseConfigurationListener) InitWith(key string, listener config_center.ConfigurationListener, f func(url *common.URL) config_center.Configurator) error { + bcl.dynamicConfiguration = config.GetEnvInstance().GetDynamicConfiguration() + bcl.defaultConfiguratorFunc = f + bcl.dynamicConfiguration.AddListener(key, listener) + if rawConfig, err := bcl.dynamicConfiguration.GetConfig(key, config_center.WithGroup(constant.DUBBO)); err != nil { + return err + } else if len(rawConfig) > 0 { + bcl.genConfiguratorFromRawRule(rawConfig) + } + return nil +} + +func (bcl *BaseConfigurationListener) Process(event *config_center.ConfigChangeEvent) { + logger.Infof("Notification of overriding rule, change type is: %v , raw config content is:%v", event.ConfigType, event.Value) + if event.ConfigType == remoting.EventTypeDel { + bcl.configurators = nil + } else { + if err := bcl.genConfiguratorFromRawRule(event.Value.(string)); err != nil { + logger.Error(perrors.WithStack(err)) + } + } +} + +func (bcl *BaseConfigurationListener) genConfiguratorFromRawRule(rawConfig string) error { + urls, err := bcl.dynamicConfiguration.Parser().ParseToUrls(rawConfig) + if err != nil { + return perrors.WithMessage(err, "Failed to parse raw dynamic config and it will not take effect, the raw config is: "+ + rawConfig) + } + bcl.configurators = ToConfigurators(urls, bcl.defaultConfiguratorFunc) + return nil +} +func (bcl *BaseConfigurationListener) OverrideUrl(url *common.URL) { + for _, v := range bcl.configurators { + v.Configure(url) + } +} + +func ToConfigurators(urls []*common.URL, f func(url *common.URL) config_center.Configurator) []config_center.Configurator { + if len(urls) == 0 { + return nil + } + var configurators []config_center.Configurator + for _, url := range urls { + if url.Protocol == constant.EMPTY_PROTOCOL { + configurators = []config_center.Configurator{} + break + } + //TODO:anyhost_key judage + configurators = append(configurators, f(url)) + } + return configurators +} diff --git a/registry/directory/directory.go b/registry/directory/directory.go index cd479ed7d6..43bc65742b 100644 --- a/registry/directory/directory.go +++ b/registry/directory/directory.go @@ -32,6 +32,7 @@ import ( "github.com/apache/dubbo-go/common/constant" "github.com/apache/dubbo-go/common/extension" "github.com/apache/dubbo-go/common/logger" + "github.com/apache/dubbo-go/config_center" "github.com/apache/dubbo-go/protocol" "github.com/apache/dubbo-go/protocol/protocolwrapper" "github.com/apache/dubbo-go/registry" @@ -219,6 +220,6 @@ type referenceConfigurationListener struct { url *common.URL } -func (l *referenceConfigurationListener) Process(event *remoting.ConfigChangeEvent) { +func (l *referenceConfigurationListener) Process(event *config_center.ConfigChangeEvent) { //l.directory.refreshInvokers(event) } diff --git a/registry/directory/directory_test.go b/registry/directory/directory_test.go index f31165d0a2..5c2113de04 100644 --- a/registry/directory/directory_test.go +++ b/registry/directory/directory_test.go @@ -74,7 +74,7 @@ func TestSubscribe_Group(t *testing.T) { mockRegistry, _ := registry.NewMockRegistry(&common.URL{}) registryDirectory, _ := NewRegistryDirectory(®url, mockRegistry) - go registryDirectory.Subscribe(*common.NewURLWithOptions(common.WithPath("testservice"))) + go registryDirectory.Subscribe(common.NewURLWithOptions(common.WithPath("testservice"))) //for group1 urlmap := url.Values{} @@ -127,7 +127,7 @@ func normalRegistryDir() (*registryDirectory, *registry.MockRegistry) { mockRegistry, _ := registry.NewMockRegistry(&common.URL{}) registryDirectory, _ := NewRegistryDirectory(&url, mockRegistry) - go registryDirectory.Subscribe(*common.NewURLWithOptions(common.WithPath("testservice"))) + go registryDirectory.Subscribe(common.NewURLWithOptions(common.WithPath("testservice"))) for i := 0; i < 3; i++ { mockRegistry.(*registry.MockRegistry).MockEvent(®istry.ServiceEvent{Action: remoting.EventTypeAdd, Service: *common.NewURLWithOptions(common.WithPath("TEST"+strconv.FormatInt(int64(i), 10)), common.WithProtocol("dubbo"))}) } diff --git a/registry/mock_registry.go b/registry/mock_registry.go index 1fc700edb7..29922ef5bb 100644 --- a/registry/mock_registry.go +++ b/registry/mock_registry.go @@ -18,7 +18,9 @@ package registry import ( + "github.com/apache/dubbo-go/common/logger" "go.uber.org/atomic" + "time" ) import ( @@ -53,9 +55,43 @@ func (r *MockRegistry) GetUrl() common.URL { return common.URL{} } -func (r *MockRegistry) Subscribe(common.URL) (Listener, error) { +func (r *MockRegistry) subscribe(*common.URL) (Listener, error) { return r.listener, nil } +func (r *MockRegistry) Subscribe(url *common.URL, notifyListener NotifyListener) { + go func() { + for { + if !r.IsAvailable() { + logger.Warnf("event listener game over.") + time.Sleep(time.Duration(3) * time.Second) + return + } + + listener, err := r.subscribe(url) + if err != nil { + if !r.IsAvailable() { + logger.Warnf("event listener game over.") + return + } + time.Sleep(time.Duration(3) * time.Second) + continue + } + + for { + if serviceEvent, err := listener.Next(); err != nil { + listener.Close() + time.Sleep(time.Duration(3) * time.Second) + return + } else { + logger.Infof("update begin, service event: %v", serviceEvent.String()) + notifyListener.Notify(serviceEvent) + } + + } + + } + }() +} type listener struct { count int64 diff --git a/registry/protocol/protocol.go b/registry/protocol/protocol.go index 58d17940ae..51d4d26a66 100644 --- a/registry/protocol/protocol.go +++ b/registry/protocol/protocol.go @@ -18,7 +18,8 @@ package protocol import ( - "github.com/apache/dubbo-go/cluster" + "github.com/apache/dubbo-go/config" + "github.com/apache/dubbo-go/config_center" "sync" ) @@ -43,7 +44,10 @@ type registryProtocol struct { registries sync.Map //To solve the problem of RMI repeated exposure port conflicts, the services that have been exposed are no longer exposed. //providerurl <--> exporter - bounds sync.Map + bounds sync.Map + overrideListeners sync.Map + serviceConfigurationListeners sync.Map + providerConfigurationListener *providerConfigurationListener } func init() { @@ -51,9 +55,13 @@ func init() { } func newRegistryProtocol() *registryProtocol { + overrideListeners := sync.Map{} return ®istryProtocol{ - registries: sync.Map{}, - bounds: sync.Map{}, + overrideListeners: overrideListeners, + registries: sync.Map{}, + bounds: sync.Map{}, + serviceConfigurationListeners: sync.Map{}, + providerConfigurationListener: newProviderConfigurationListener(&overrideListeners), } } func getRegistry(regUrl *common.URL) registry.Registry { @@ -107,6 +115,14 @@ func (proto *registryProtocol) Export(invoker protocol.Invoker) protocol.Exporte providerUrl := getProviderUrl(invoker) overriderUrl := getSubscribedOverrideUrl(&providerUrl) + // Deprecated! subscribe to override rules in 2.6.x or before. + overrideSubscribeListener := newOverrideSubscribeListener(overriderUrl, invoker, proto) + proto.overrideListeners.Store(overriderUrl, overrideSubscribeListener) + proto.providerConfigurationListener.OverrideUrl(&providerUrl) + serviceConfigurationListener := newServiceConfigurationListener(overrideSubscribeListener, &providerUrl) + proto.serviceConfigurationListeners.Store(providerUrl.ServiceKey(), serviceConfigurationListener) + serviceConfigurationListener.OverrideUrl(&providerUrl) + var reg registry.Registry if regI, loaded := proto.registries.Load(registryUrl.Key()); !loaded { @@ -134,8 +150,6 @@ func (proto *registryProtocol) Export(invoker protocol.Invoker) protocol.Exporte logger.Infof("The exporter has not been cached, and will return a new exporter!") } - // Deprecated! subscribe to override rules in 2.6.x or before. - overrideSubscribeListener := &overrideSubscribeListener{url: overriderUrl, originInvoker: invoker, protocol: proto} reg.Subscribe(overriderUrl, overrideSubscribeListener) return cachedExporter.(protocol.Exporter) @@ -161,9 +175,12 @@ type overrideSubscribeListener struct { url *common.URL originInvoker protocol.Invoker protocol *registryProtocol - configurator cluster.Configurator + configurator config_center.Configurator } +func newOverrideSubscribeListener(overriderUrl *common.URL, invoker protocol.Invoker, proto *registryProtocol) *overrideSubscribeListener { + return &overrideSubscribeListener{url: overriderUrl, originInvoker: invoker, protocol: proto} +} func (nl *overrideSubscribeListener) Notify(event *registry.ServiceEvent) { if isMatched(&(event.Service), nl.url) { nl.configurator = extension.GetDefaultConfigurator(&(event.Service)) @@ -175,7 +192,19 @@ func (nl *overrideSubscribeListener) doOverrideIfNecessary() { key := providerUrl.Key() if exporter, ok := nl.protocol.bounds.Load(key); ok { currentUrl := exporter.(protocol.Exporter).GetInvoker().GetUrl() + // Compatible with the 2.6.x nl.configurator.Configure(&providerUrl) + // provider application level management in 2.7.x + for _, v := range nl.protocol.providerConfigurationListener.Configurators() { + v.Configure(&providerUrl) + } + // provider service level management in 2.7.x + if serviceListener, ok := nl.protocol.serviceConfigurationListeners.Load(providerUrl.ServiceKey()); ok { + for _, v := range serviceListener.(*serviceConfigurationListener).Configurators() { + v.Configure(&providerUrl) + } + } + if currentUrl.String() == providerUrl.String() { newRegUrl := nl.originInvoker.GetUrl() setProviderUrl(&newRegUrl, &providerUrl) @@ -271,3 +300,42 @@ func (ivk *wrappedInvoker) GetUrl() common.URL { func (ivk *wrappedInvoker) getInvoker() protocol.Invoker { return ivk.invoker } + +type providerConfigurationListener struct { + registry.BaseConfigurationListener + overrideListeners *sync.Map +} + +func newProviderConfigurationListener(overrideListeners *sync.Map) *providerConfigurationListener { + listener := &providerConfigurationListener{} + listener.overrideListeners = overrideListeners + //TODO:error handler + _ = listener.BaseConfigurationListener.InitWith(config.GetProviderConfig().ApplicationConfig.Name+constant.CONFIGURATORS_SUFFIX, listener, extension.GetDefaultConfiguratorFunc()) + return listener +} + +func (listener *providerConfigurationListener) Process(event *config_center.ConfigChangeEvent) { + listener.BaseConfigurationListener.Process(event) + listener.overrideListeners.Range(func(key, value interface{}) bool { + value.(*overrideSubscribeListener).doOverrideIfNecessary() + return true + }) +} + +type serviceConfigurationListener struct { + registry.BaseConfigurationListener + overrideListener *overrideSubscribeListener + providerUrl *common.URL +} + +func newServiceConfigurationListener(overrideListener *overrideSubscribeListener, providerUrl *common.URL) *serviceConfigurationListener { + listener := &serviceConfigurationListener{overrideListener: overrideListener, providerUrl: providerUrl} + //TODO:error handler + _ = listener.BaseConfigurationListener.InitWith(providerUrl.EncodedServiceKey()+constant.CONFIGURATORS_SUFFIX, listener, extension.GetDefaultConfiguratorFunc()) + return &serviceConfigurationListener{overrideListener: overrideListener, providerUrl: providerUrl} +} + +func (listener *serviceConfigurationListener) Process(event *config_center.ConfigChangeEvent) { + listener.BaseConfigurationListener.Process(event) + listener.overrideListener.doOverrideIfNecessary() +} diff --git a/registry/protocol/protocol_test.go b/registry/protocol/protocol_test.go index 418f1f6779..72c0300dfc 100644 --- a/registry/protocol/protocol_test.go +++ b/registry/protocol/protocol_test.go @@ -19,6 +19,8 @@ package protocol import ( "context" + "github.com/apache/dubbo-go/config_center" + "testing" ) @@ -29,13 +31,23 @@ import ( import ( cluster "github.com/apache/dubbo-go/cluster/cluster_impl" "github.com/apache/dubbo-go/common" + commonConfig "github.com/apache/dubbo-go/common/config" "github.com/apache/dubbo-go/common/constant" "github.com/apache/dubbo-go/common/extension" + "github.com/apache/dubbo-go/config" + "github.com/apache/dubbo-go/config_center/configurator" "github.com/apache/dubbo-go/protocol" "github.com/apache/dubbo-go/protocol/protocolwrapper" "github.com/apache/dubbo-go/registry" ) +func init() { + extension.SetDefaultConfigurator(configurator.NewMockConfigurator) + config.SetProviderConfig(config.ProviderConfig{ApplicationConfig: &config.ApplicationConfig{Name: "mock"}}) + factory := &config_center.MockDynamicConfigurationFactory{} + dc, _ := factory.GetDynamicConfiguration(&common.URL{}) + commonConfig.GetEnvInstance().SetDynamicConfiguration(dc) +} func referNormal(t *testing.T, regProtocol *registryProtocol) { extension.SetProtocol("registry", GetProtocol) extension.SetRegistry("mock", registry.NewMockRegistry) @@ -108,6 +120,7 @@ func exporterNormal(t *testing.T, regProtocol *registryProtocol) { } func TestExporter(t *testing.T) { + regProtocol := newRegistryProtocol() exporterNormal(t, regProtocol) } diff --git a/registry/zookeeper/listener.go b/registry/zookeeper/listener.go index 7d58cee122..688ede8b65 100644 --- a/registry/zookeeper/listener.go +++ b/registry/zookeeper/listener.go @@ -19,6 +19,7 @@ package zookeeper import ( "context" + "github.com/apache/dubbo-go/config_center" "strings" ) import ( @@ -34,10 +35,10 @@ import ( type RegistryDataListener struct { interestedURL []*common.URL - listener remoting.ConfigurationListener + listener config_center.ConfigurationListener } -func NewRegistryDataListener(listener remoting.ConfigurationListener) *RegistryDataListener { +func NewRegistryDataListener(listener config_center.ConfigurationListener) *RegistryDataListener { return &RegistryDataListener{listener: listener, interestedURL: []*common.URL{}} } func (l *RegistryDataListener) AddInterestedURL(url *common.URL) { @@ -59,7 +60,7 @@ func (l *RegistryDataListener) DataChange(eventType remoting.Event) bool { } for _, v := range l.interestedURL { if serviceURL.URLEqual(*v) { - l.listener.Process(&remoting.ConfigChangeEvent{Value: serviceURL, ConfigType: eventType.Action}) + l.listener.Process(&config_center.ConfigChangeEvent{Value: serviceURL, ConfigType: eventType.Action}) return true } } @@ -70,14 +71,14 @@ func (l *RegistryDataListener) DataChange(eventType remoting.Event) bool { type RegistryConfigurationListener struct { client *zk.ZookeeperClient registry *zkRegistry - events chan *remoting.ConfigChangeEvent + events chan *config_center.ConfigChangeEvent } func NewRegistryConfigurationListener(client *zk.ZookeeperClient, reg *zkRegistry) *RegistryConfigurationListener { reg.wg.Add(1) - return &RegistryConfigurationListener{client: client, registry: reg, events: make(chan *remoting.ConfigChangeEvent, 32)} + return &RegistryConfigurationListener{client: client, registry: reg, events: make(chan *config_center.ConfigChangeEvent, 32)} } -func (l *RegistryConfigurationListener) Process(configType *remoting.ConfigChangeEvent) { +func (l *RegistryConfigurationListener) Process(configType *config_center.ConfigChangeEvent) { l.events <- configType } diff --git a/remoting/etcdv3/listener.go b/remoting/etcdv3/listener.go index 59273af554..f5401917e2 100644 --- a/remoting/etcdv3/listener.go +++ b/remoting/etcdv3/listener.go @@ -100,7 +100,7 @@ func (l *EventListener) handleEvents(event *clientv3.Event, listeners ...remotin logger.Infof("etcd get event (key{%s}) = event{EventNodeDataChanged}", event.Kv.Key) listener.DataChange(remoting.Event{ Path: string(event.Kv.Key), - Action: remoting.EvnetTypeUpdate, + Action: remoting.EventTypeUpdate, Content: string(event.Kv.Value), }) } diff --git a/remoting/listener.go b/remoting/listener.go index b94ba26980..8d1e357d37 100644 --- a/remoting/listener.go +++ b/remoting/listener.go @@ -17,26 +17,14 @@ package remoting -import "fmt" - -type ConfigurationListener interface { - Process(*ConfigChangeEvent) -} +import ( + "fmt" +) type DataListener interface { DataChange(eventType Event) bool //bool is return for interface implement is interesting } -type ConfigChangeEvent struct { - Key string - Value interface{} - ConfigType EventType -} - -func (c ConfigChangeEvent) String() string { - return fmt.Sprintf("ConfigChangeEvent{key = %v , value = %v , changeType = %v}", c.Key, c.Value, c.ConfigType) -} - ////////////////////////////////////////// // event type ////////////////////////////////////////// From 13f9eedd1a7dd928ecf67ccb1d339fb401af8490 Mon Sep 17 00:00:00 2001 From: "vito.he" Date: Mon, 2 Sep 2019 16:10:37 +0800 Subject: [PATCH 03/34] Add:before ci shell --- .gitignore | 5 +++++ before_ci.sh | 4 ++++ 2 files changed, 9 insertions(+) create mode 100644 before_ci.sh diff --git a/.gitignore b/.gitignore index 1e651f122b..e917b9dfe0 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,8 @@ coverage.txt logs/ .vscode/ coverage.txt + +# unit test +remoting/zookeeper/zookeeper-4unittest/ +config_center/zookeeper/zookeeper-4unittest/ +registry/zookeeper/zookeeper-4unittest/ diff --git a/before_ci.sh b/before_ci.sh new file mode 100644 index 0000000000..7acee76ce5 --- /dev/null +++ b/before_ci.sh @@ -0,0 +1,4 @@ +mkdir -p remoting/zookeeper/zookeeper-4unittest/contrib/fatjar config_center/zookeeper/zookeeper-4unittest/contrib/fatjar registry/zookeeper/zookeeper-4unittest/contrib/fatjar +wget -P "remoting/zookeeper/zookeeper-4unittest/contrib/fatjar" https://github.com/dubbogo/resources/raw/master/zookeeper-4unitest/contrib/fatjar/zookeeper-3.4.9-fatjar.jar +cp remoting/zookeeper/zookeeper-4unittest/contrib/fatjar/zookeeper-3.4.9-fatjar.jar config_center/zookeeper/zookeeper-4unittest/contrib/fatjar/ +cp remoting/zookeeper/zookeeper-4unittest/contrib/fatjar/zookeeper-3.4.9-fatjar.jar registry/zookeeper/zookeeper-4unittest/contrib/fatjar/ \ No newline at end of file From 52bb0e17e48b8335a8813d927505749284a7d08e Mon Sep 17 00:00:00 2001 From: "vito.he" Date: Fri, 6 Sep 2019 18:16:17 +0800 Subject: [PATCH 04/34] Add:can run successful --- cluster/directory/base_directory.go | 3 + common/constant/default.go | 5 +- common/url.go | 4 +- common/url_test.go | 2 +- config/reference_config.go | 4 +- config/service_config.go | 1 - config_center/mock_dynamic_config.go | 71 ++++++++-- config_center/parser/configuration_parser.go | 28 ++-- registry/directory/directory.go | 141 ++++++++++++++----- registry/directory/directory_test.go | 67 +++++++-- registry/etcdv3/registry.go | 4 +- registry/protocol/protocol.go | 53 ++++--- registry/protocol/protocol_test.go | 52 +++++-- registry/zookeeper/registry.go | 6 +- 14 files changed, 324 insertions(+), 117 deletions(-) diff --git a/cluster/directory/base_directory.go b/cluster/directory/base_directory.go index b201197714..1d59b51cc3 100644 --- a/cluster/directory/base_directory.go +++ b/cluster/directory/base_directory.go @@ -42,6 +42,9 @@ func NewBaseDirectory(url *common.URL) BaseDirectory { func (dir *BaseDirectory) GetUrl() common.URL { return *dir.url } +func (dir *BaseDirectory) GetDirectoryUrl() *common.URL { + return dir.url +} func (dir *BaseDirectory) Destroy(doDestroy func()) { if dir.destroyed.CAS(false, true) { diff --git a/common/constant/default.go b/common/constant/default.go index b7b8bb0237..9144249ef6 100644 --- a/common/constant/default.go +++ b/common/constant/default.go @@ -23,6 +23,7 @@ const ( //compatible with 2.6.x OVERRIDE_PROTOCOL = "override" EMPTY_PROTOCOL = "empty" + ROUTER_PROTOCOL = "router" ) const ( @@ -58,7 +59,9 @@ const ( const ( CONFIGURATORS_CATEGORY = "configurators" - DEFAULT_CATEGORY = "providers" + ROUTER_CATEGORY = "category" + DEFAULT_CATEGORY = PROVIDER_CATEGORY DYNAMIC_CONFIGURATORS_CATEGORY = "dynamicconfigurators" APP_DYNAMIC_CONFIGURATORS_CATEGORY = "appdynamicconfigurators" + PROVIDER_CATEGORY = "providers" ) diff --git a/common/url.go b/common/url.go index aeae47b840..43c6431c4b 100644 --- a/common/url.go +++ b/common/url.go @@ -454,8 +454,8 @@ func (c URL) ToMap() map[string]string { // configuration > reference config >service config // in this function we should merge the reference local url config into the service url from registry. //TODO configuration merge, in the future , the configuration center's config should merge too. -func MergeUrl(serviceUrl URL, referenceUrl *URL) URL { - mergedUrl := serviceUrl +func MergeUrl(serviceUrl *URL, referenceUrl *URL) *URL { + mergedUrl := serviceUrl.Clone() var methodConfigMergeFcn = []func(method string){} //iterator the referenceUrl if serviceUrl not have the key ,merge in diff --git a/common/url_test.go b/common/url_test.go index 0f23c5a1d0..2f03f1080c 100644 --- a/common/url_test.go +++ b/common/url_test.go @@ -227,7 +227,7 @@ func TestMergeUrl(t *testing.T) { referenceUrl, _ := NewURL(context.TODO(), "mock1://127.0.0.1:1111", WithParams(referenceUrlParams)) serviceUrl, _ := NewURL(context.TODO(), "mock2://127.0.0.1:20000", WithParams(serviceUrlParams)) - mergedUrl := MergeUrl(serviceUrl, &referenceUrl) + mergedUrl := MergeUrl(&serviceUrl, &referenceUrl) assert.Equal(t, "random", mergedUrl.GetParam(constant.CLUSTER_KEY, "")) assert.Equal(t, "1", mergedUrl.GetParam("test2", "")) assert.Equal(t, "1", mergedUrl.GetParam("test3", "")) diff --git a/config/reference_config.go b/config/reference_config.go index f90e3aabd3..b3a3bae447 100644 --- a/config/reference_config.go +++ b/config/reference_config.go @@ -97,8 +97,8 @@ func (refconfig *ReferenceConfig) Refer() { serviceUrl.Path = "/" + refconfig.id } // merge url need to do - newUrl := common.MergeUrl(serviceUrl, url) - refconfig.urls = append(refconfig.urls, &newUrl) + newUrl := common.MergeUrl(&serviceUrl, url) + refconfig.urls = append(refconfig.urls, newUrl) } } diff --git a/config/service_config.go b/config/service_config.go index 5430f8a7c3..05cdc84f5b 100644 --- a/config/service_config.go +++ b/config/service_config.go @@ -111,7 +111,6 @@ func (srvconfig *ServiceConfig) Export() error { common.WithParams(urlMap), common.WithParamsValue(constant.BEAN_NAME_KEY, srvconfig.id), common.WithMethods(strings.Split(methods, ","))) - if len(regUrls) > 0 { for _, regUrl := range regUrls { regUrl.SubURL = url diff --git a/config_center/mock_dynamic_config.go b/config_center/mock_dynamic_config.go index 7ecffca160..7045c48ec9 100644 --- a/config_center/mock_dynamic_config.go +++ b/config_center/mock_dynamic_config.go @@ -18,24 +18,27 @@ package config_center import ( - "github.com/apache/dubbo-go/config_center/parser" + "github.com/apache/dubbo-go/common/constant" + "github.com/apache/dubbo-go/remoting" + "gopkg.in/yaml.v2" "sync" ) import ( "github.com/apache/dubbo-go/common" + "github.com/apache/dubbo-go/config_center/parser" ) type MockDynamicConfigurationFactory struct{} var ( once sync.Once - dynamicConfiguration *mockDynamicConfiguration + dynamicConfiguration *MockDynamicConfiguration ) func (f *MockDynamicConfigurationFactory) GetDynamicConfiguration(url *common.URL) (DynamicConfiguration, error) { var err error once.Do(func() { - dynamicConfiguration = &mockDynamicConfiguration{} + dynamicConfiguration = &MockDynamicConfiguration{listener: map[string]ConfigurationListener{}} dynamicConfiguration.SetParser(&parser.DefaultConfigurationParser{}) dynamicConfiguration.content = ` dubbo.consumer.request_timeout=5s @@ -66,30 +69,74 @@ func (f *MockDynamicConfigurationFactory) GetDynamicConfiguration(url *common.UR } -type mockDynamicConfiguration struct { - parser parser.ConfigurationParser - content string +type MockDynamicConfiguration struct { + parser parser.ConfigurationParser + content string + listener map[string]ConfigurationListener } -func (c *mockDynamicConfiguration) AddListener(key string, listener ConfigurationListener, opions ...Option) { +func (c *MockDynamicConfiguration) AddListener(key string, listener ConfigurationListener, opions ...Option) { + c.listener[key] = listener } -func (c *mockDynamicConfiguration) RemoveListener(key string, listener ConfigurationListener, opions ...Option) { +func (c *MockDynamicConfiguration) RemoveListener(key string, listener ConfigurationListener, opions ...Option) { } -func (c *mockDynamicConfiguration) GetConfig(key string, opts ...Option) (string, error) { +func (c *MockDynamicConfiguration) GetConfig(key string, opts ...Option) (string, error) { return c.content, nil } //For zookeeper, getConfig and getConfigs have the same meaning. -func (c *mockDynamicConfiguration) GetConfigs(key string, opts ...Option) (string, error) { +func (c *MockDynamicConfiguration) GetConfigs(key string, opts ...Option) (string, error) { return c.GetConfig(key, opts...) } -func (c *mockDynamicConfiguration) Parser() parser.ConfigurationParser { +func (c *MockDynamicConfiguration) Parser() parser.ConfigurationParser { return c.parser } -func (c *mockDynamicConfiguration) SetParser(p parser.ConfigurationParser) { +func (c *MockDynamicConfiguration) SetParser(p parser.ConfigurationParser) { c.parser = p } + +func (c *MockDynamicConfiguration) MockServiceConfigEvent() { + config := &parser.ConfiguratorConfig{ + ConfigVersion: "2.7.1", + Scope: parser.GeneralType, + Key: "org.apache.dubbo-go.mockService", + Enabled: true, + Configs: []parser.ConfigItem{ + {Type: parser.GeneralType, + Enabled: true, + Addresses: []string{"0.0.0.0"}, + Services: []string{"org.apache.dubbo-go.mockService"}, + Side: "provider", + Parameters: map[string]string{"cluster": "mock1"}, + }, + }, + } + value, _ := yaml.Marshal(config) + key := "group*org.apache.dubbo-go.mockService:1.0.0" + constant.CONFIGURATORS_SUFFIX + c.listener[key].Process(&ConfigChangeEvent{Key: key, Value: string(value), ConfigType: remoting.EventTypeAdd}) +} + +func (c *MockDynamicConfiguration) MockApplicationConfigEvent() { + config := &parser.ConfiguratorConfig{ + ConfigVersion: "2.7.1", + Scope: parser.ScopeApplication, + Key: "org.apache.dubbo-go.mockService", + Enabled: true, + Configs: []parser.ConfigItem{ + {Type: parser.ScopeApplication, + Enabled: true, + Addresses: []string{"0.0.0.0"}, + Services: []string{"org.apache.dubbo-go.mockService"}, + Side: "provider", + Parameters: map[string]string{"cluster": "mock1"}, + }, + }, + } + value, _ := yaml.Marshal(config) + key := "test-application" + constant.CONFIGURATORS_SUFFIX + c.listener[key].Process(&ConfigChangeEvent{Key: key, Value: string(value), ConfigType: remoting.EventTypeAdd}) +} diff --git a/config_center/parser/configuration_parser.go b/config_center/parser/configuration_parser.go index 34d5f26763..bc0eb1182d 100644 --- a/config_center/parser/configuration_parser.go +++ b/config_center/parser/configuration_parser.go @@ -137,7 +137,7 @@ func appItemToUrls(item ConfigItem, config ConfiguratorConfig) ([]*common.URL, e urlStr = urlStr + config.ConfigVersion url, err := common.NewURL(context.Background(), urlStr) if err != nil { - perrors.WithStack(err) + return nil, perrors.WithStack(err) } urls = append(urls, &url) } @@ -213,19 +213,19 @@ const ( ) type ConfiguratorConfig struct { - ConfigVersion string - Scope string - Key string - Enabled bool - Configs []ConfigItem + ConfigVersion string `yaml:"configVersion"` + Scope string `yaml:"scope"` + Key string `yaml:"key"` + Enabled bool `yaml:"enabled"` + Configs []ConfigItem `yaml:"configs"` } type ConfigItem struct { - Type string - Enabled bool - Addresses []string - ProviderAddresses []string - Services []string - Applications []string - Parameters map[string]string - Side string + Type string `yaml:"type"` + Enabled bool `yaml:"enabled"` + Addresses []string `yaml:"addresses"` + ProviderAddresses []string `yaml:"providerAddresses"` + Services []string `yaml:"services"` + Applications []string `yaml:"applications"` + Parameters map[string]string `yaml:"parameters"` + Side string `yaml:"side"` } diff --git a/registry/directory/directory.go b/registry/directory/directory.go index 3ea5b36fcd..407890678b 100644 --- a/registry/directory/directory.go +++ b/registry/directory/directory.go @@ -32,11 +32,12 @@ import ( "github.com/apache/dubbo-go/common/constant" "github.com/apache/dubbo-go/common/extension" "github.com/apache/dubbo-go/common/logger" + "github.com/apache/dubbo-go/config" "github.com/apache/dubbo-go/config_center" + _ "github.com/apache/dubbo-go/config_center/configurator" "github.com/apache/dubbo-go/protocol" "github.com/apache/dubbo-go/protocol/protocolwrapper" "github.com/apache/dubbo-go/registry" - "github.com/apache/dubbo-go/remoting" ) const ( @@ -51,11 +52,15 @@ type Option func(*Options) type registryDirectory struct { directory.BaseDirectory - cacheInvokers []protocol.Invoker - listenerLock sync.Mutex - serviceType string - registry registry.Registry - cacheInvokersMap *sync.Map //use sync.map + cacheInvokers []protocol.Invoker + listenerLock sync.Mutex + serviceType string + registry registry.Registry + cacheInvokersMap *sync.Map //use sync.map + cacheOriginUrl *common.URL + configurators []config_center.Configurator + consumerConfigurationListener *consumerConfigurationListener + referenceConfigurationListener *referenceConfigurationListener Options } @@ -70,28 +75,27 @@ func NewRegistryDirectory(url *common.URL, registry registry.Registry, opts ...O if url.SubURL == nil { return nil, perrors.Errorf("url is invalid, suburl can not be nil") } - return ®istryDirectory{ + dir := ®istryDirectory{ BaseDirectory: directory.NewBaseDirectory(url), cacheInvokers: []protocol.Invoker{}, cacheInvokersMap: &sync.Map{}, serviceType: url.SubURL.Service(), registry: registry, Options: options, - }, nil + } + dir.consumerConfigurationListener = newConsumerConfigurationListener(dir) + return dir, nil } //subscibe from registry func (dir *registryDirectory) Subscribe(url *common.URL) { - notifyListener := ¬ifyListener{dir} - dir.registry.Subscribe(url, notifyListener) -} - -type notifyListener struct { - dir *registryDirectory + dir.consumerConfigurationListener.addNotifyListener(dir) + dir.referenceConfigurationListener = newReferenceConfigurationListener(dir, url) + dir.registry.Subscribe(url, dir) } -func (nl *notifyListener) Notify(event *registry.ServiceEvent) { - go nl.dir.update(event) +func (dir *registryDirectory) Notify(event *registry.ServiceEvent) { + go dir.update(event) } //subscribe service from registry, and update the cacheServices @@ -105,21 +109,33 @@ func (dir *registryDirectory) update(res *registry.ServiceEvent) { } func (dir *registryDirectory) refreshInvokers(res *registry.ServiceEvent) { - - switch res.Action { - case remoting.EventTypeAdd: - //dir.cacheService.EventTypeAdd(res.Path, dir.serviceTTL) - dir.cacheInvoker(res.Service) - case remoting.EventTypeDel: - //dir.cacheService.EventTypeDel(res.Path, dir.serviceTTL) - dir.uncacheInvoker(res.Service) - logger.Infof("selector delete service url{%s}", res.Service) - default: - return + var url *common.URL + //judge is override or others + if res != nil { + url = &res.Service + //1.for override url in 2.6.x + if url.Protocol == constant.OVERRIDE_PROTOCOL || + url.GetParam(constant.CATEGORY_KEY, constant.DEFAULT_CATEGORY) == constant.CONFIGURATORS_CATEGORY { + dir.configurators = append(dir.configurators, extension.GetDefaultConfigurator(url)) + } else if url.Protocol == constant.ROUTER_PROTOCOL || //2.for router + url.GetParam(constant.CATEGORY_KEY, constant.DEFAULT_CATEGORY) == constant.ROUTER_CATEGORY { + //TODO: router + } } - + // + //switch res.Action { + //case remoting.EventTypeAdd: + // //dir.cacheService.EventTypeAdd(res.Path, dir.serviceTTL) + // dir.cacheInvoker(&res.Service) + //case remoting.EventTypeDel: + // //dir.cacheService.EventTypeDel(res.Path, dir.serviceTTL) + // dir.uncacheInvoker(&res.Service) + // logger.Infof("selector delete service url{%s}", res.Service) + //default: + // return + //} + dir.cacheInvoker(url) newInvokers := dir.toGroupInvokers() - dir.listenerLock.Lock() defer dir.listenerLock.Unlock() dir.cacheInvokers = newInvokers @@ -160,22 +176,33 @@ func (dir *registryDirectory) toGroupInvokers() []protocol.Invoker { return groupInvokersList } -func (dir *registryDirectory) uncacheInvoker(url common.URL) { +func (dir *registryDirectory) uncacheInvoker(url *common.URL) { logger.Debugf("service will be deleted in cache invokers: invokers key is %s!", url.Key()) dir.cacheInvokersMap.Delete(url.Key()) } -func (dir *registryDirectory) cacheInvoker(url common.URL) { - referenceUrl := dir.GetUrl().SubURL +func (dir *registryDirectory) cacheInvoker(url *common.URL) { + dir.overrideUrl(dir.GetDirectoryUrl()) + referenceUrl := dir.GetDirectoryUrl().SubURL + + if url == nil && dir.cacheOriginUrl != nil { + url = dir.cacheOriginUrl + } else { + dir.cacheOriginUrl = url + } + if url == nil { + logger.Error("URL is nil ,pls check if service url is subscribe successfully!") + return + } //check the url's protocol is equal to the protocol which is configured in reference config or referenceUrl is not care about protocol if url.Protocol == referenceUrl.Protocol || referenceUrl.Protocol == "" { - url = common.MergeUrl(url, referenceUrl) - - if _, ok := dir.cacheInvokersMap.Load(url.Key()); !ok { + newUrl := common.MergeUrl(url, referenceUrl) + dir.overrideUrl(newUrl) + if _, ok := dir.cacheInvokersMap.Load(newUrl.Key()); !ok { logger.Debugf("service will be added in cache invokers: invokers key is %s!", url.Key()) - newInvoker := extension.GetProtocol(protocolwrapper.FILTER).Refer(url) + newInvoker := extension.GetProtocol(protocolwrapper.FILTER).Refer(*newUrl) if newInvoker != nil { - dir.cacheInvokersMap.Store(url.Key(), newInvoker) + dir.cacheInvokersMap.Store(newUrl.Key(), newInvoker) } } } @@ -209,12 +236,50 @@ func (dir *registryDirectory) Destroy() { dir.cacheInvokers = []protocol.Invoker{} }) } +func (dir *registryDirectory) overrideUrl(targetUrl *common.URL) { + doOverrideUrl(dir.configurators, targetUrl) + doOverrideUrl(dir.consumerConfigurationListener.Configurators(), targetUrl) + doOverrideUrl(dir.referenceConfigurationListener.Configurators(), targetUrl) +} + +func doOverrideUrl(configurators []config_center.Configurator, targetUrl *common.URL) { + for _, v := range configurators { + v.Configure(targetUrl) + } +} type referenceConfigurationListener struct { + registry.BaseConfigurationListener directory *registryDirectory url *common.URL } +func newReferenceConfigurationListener(dir *registryDirectory, url *common.URL) *referenceConfigurationListener { + listener := &referenceConfigurationListener{directory: dir, url: url} + listener.InitWith(url.EncodedServiceKey()+constant.CONFIGURATORS_SUFFIX, listener, extension.GetDefaultConfiguratorFunc()) + return listener +} + func (l *referenceConfigurationListener) Process(event *config_center.ConfigChangeEvent) { - //l.directory.refreshInvokers(event) + l.BaseConfigurationListener.Process(event) + l.directory.refreshInvokers(nil) +} + +type consumerConfigurationListener struct { + registry.BaseConfigurationListener + listeners []registry.NotifyListener + directory *registryDirectory +} + +func newConsumerConfigurationListener(dir *registryDirectory) *consumerConfigurationListener { + listener := &consumerConfigurationListener{directory: dir} + listener.InitWith(config.GetConsumerConfig().ApplicationConfig.Name+constant.CONFIGURATORS_SUFFIX, listener, extension.GetDefaultConfiguratorFunc()) + return listener +} +func (l *consumerConfigurationListener) addNotifyListener(listener registry.NotifyListener) { + l.listeners = append(l.listeners, listener) +} +func (l *consumerConfigurationListener) Process(event *config_center.ConfigChangeEvent) { + l.BaseConfigurationListener.Process(event) + l.directory.refreshInvokers(nil) } diff --git a/registry/directory/directory_test.go b/registry/directory/directory_test.go index 5c2113de04..e606720554 100644 --- a/registry/directory/directory_test.go +++ b/registry/directory/directory_test.go @@ -34,12 +34,16 @@ import ( "github.com/apache/dubbo-go/common" "github.com/apache/dubbo-go/common/constant" "github.com/apache/dubbo-go/common/extension" + "github.com/apache/dubbo-go/config" "github.com/apache/dubbo-go/protocol/invocation" "github.com/apache/dubbo-go/protocol/protocolwrapper" "github.com/apache/dubbo-go/registry" "github.com/apache/dubbo-go/remoting" ) +func init() { + config.SetConsumerConfig(config.ConsumerConfig{ApplicationConfig: &config.ApplicationConfig{Name: "test-application"}}) +} func TestSubscribe(t *testing.T) { registryDirectory, _ := normalRegistryDir() @@ -47,14 +51,15 @@ func TestSubscribe(t *testing.T) { assert.Len(t, registryDirectory.cacheInvokers, 3) } -func TestSubscribe_Delete(t *testing.T) { - registryDirectory, mockRegistry := normalRegistryDir() - time.Sleep(1e9) - assert.Len(t, registryDirectory.cacheInvokers, 3) - mockRegistry.MockEvent(®istry.ServiceEvent{Action: remoting.EventTypeDel, Service: *common.NewURLWithOptions(common.WithPath("TEST0"), common.WithProtocol("dubbo"))}) - time.Sleep(1e9) - assert.Len(t, registryDirectory.cacheInvokers, 2) -} +////Deprecated! not support delete +//func TestSubscribe_Delete(t *testing.T) { +// registryDirectory, mockRegistry := normalRegistryDir() +// time.Sleep(1e9) +// assert.Len(t, registryDirectory.cacheInvokers, 3) +// mockRegistry.MockEvent(®istry.ServiceEvent{Action: remoting.EventTypeDel, Service: *common.NewURLWithOptions(common.WithPath("TEST0"), common.WithProtocol("dubbo"))}) +// time.Sleep(1e9) +// assert.Len(t, registryDirectory.cacheInvokers, 2) +//} func TestSubscribe_InvalidUrl(t *testing.T) { url, _ := common.NewURL(context.TODO(), "mock://127.0.0.1:1111") @@ -116,20 +121,56 @@ func Test_List(t *testing.T) { assert.Len(t, registryDirectory.List(&invocation.RPCInvocation{}), 3) assert.Equal(t, true, registryDirectory.IsAvailable()) +} +func Test_MergeProviderUrl(t *testing.T) { + registryDirectory, mockRegistry := normalRegistryDir(true) + providerUrl, _ := common.NewURL(context.TODO(), "dubbo://0.0.0.0:20000/org.apache.dubbo-go.mockService", + common.WithParamsValue(constant.CLUSTER_KEY, "mock1"), + common.WithParamsValue(constant.GROUP_KEY, "group"), + common.WithParamsValue(constant.VERSION_KEY, "1.0.0")) + mockRegistry.MockEvent(®istry.ServiceEvent{Action: remoting.EventTypeAdd, Service: providerUrl}) + time.Sleep(1e9) + assert.Len(t, registryDirectory.cacheInvokers, 1) + if len(registryDirectory.cacheInvokers) > 0 { + assert.Equal(t, "mock", registryDirectory.cacheInvokers[0].GetUrl().GetParam(constant.CLUSTER_KEY, "")) + } + } -func normalRegistryDir() (*registryDirectory, *registry.MockRegistry) { +func Test_MergeOverrideUrl(t *testing.T) { + registryDirectory, mockRegistry := normalRegistryDir(true) + providerUrl, _ := common.NewURL(context.TODO(), "dubbo://0.0.0.0:20000/org.apache.dubbo-go.mockService", + common.WithParamsValue(constant.CLUSTER_KEY, "mock"), + common.WithParamsValue(constant.GROUP_KEY, "group"), + common.WithParamsValue(constant.VERSION_KEY, "1.0.0")) + mockRegistry.MockEvent(®istry.ServiceEvent{Action: remoting.EventTypeAdd, Service: providerUrl}) + overrideUrl, _ := common.NewURL(context.TODO(), "override://0.0.0.0:20000/org.apache.dubbo-go.mockService", + common.WithParamsValue(constant.CLUSTER_KEY, "mock1"), + common.WithParamsValue(constant.GROUP_KEY, "group"), + common.WithParamsValue(constant.VERSION_KEY, "1.0.0")) + mockRegistry.MockEvent(®istry.ServiceEvent{Action: remoting.EventTypeAdd, Service: overrideUrl}) + time.Sleep(1e9) + assert.Len(t, registryDirectory.cacheInvokers, 1) + if len(registryDirectory.cacheInvokers) > 0 { + assert.Equal(t, "mock1", registryDirectory.cacheInvokers[0].GetUrl().GetParam(constant.CLUSTER_KEY, "")) + } + +} + +func normalRegistryDir(noMockEvent ...bool) (*registryDirectory, *registry.MockRegistry) { extension.SetProtocol(protocolwrapper.FILTER, protocolwrapper.NewMockProtocolFilter) url, _ := common.NewURL(context.TODO(), "mock://127.0.0.1:1111") - suburl, _ := common.NewURL(context.TODO(), "dubbo://127.0.0.1:20000") + suburl, _ := common.NewURL(context.TODO(), "dubbo://127.0.0.1:20000/org.apache.dubbo-go.mockService", common.WithParamsValue(constant.CLUSTER_KEY, "mock"), common.WithParamsValue(constant.GROUP_KEY, "group"), common.WithParamsValue(constant.VERSION_KEY, "1.0.0")) url.SubURL = &suburl mockRegistry, _ := registry.NewMockRegistry(&common.URL{}) registryDirectory, _ := NewRegistryDirectory(&url, mockRegistry) - go registryDirectory.Subscribe(common.NewURLWithOptions(common.WithPath("testservice"))) - for i := 0; i < 3; i++ { - mockRegistry.(*registry.MockRegistry).MockEvent(®istry.ServiceEvent{Action: remoting.EventTypeAdd, Service: *common.NewURLWithOptions(common.WithPath("TEST"+strconv.FormatInt(int64(i), 10)), common.WithProtocol("dubbo"))}) + go registryDirectory.Subscribe(&suburl) + if len(noMockEvent) == 0 { + for i := 0; i < 3; i++ { + mockRegistry.(*registry.MockRegistry).MockEvent(®istry.ServiceEvent{Action: remoting.EventTypeAdd, Service: *common.NewURLWithOptions(common.WithPath("TEST"+strconv.FormatInt(int64(i), 10)), common.WithProtocol("dubbo"))}) + } } return registryDirectory, mockRegistry.(*registry.MockRegistry) } diff --git a/registry/etcdv3/registry.go b/registry/etcdv3/registry.go index 4b140f893f..845be96fe8 100644 --- a/registry/etcdv3/registry.go +++ b/registry/etcdv3/registry.go @@ -322,7 +322,9 @@ func (r *etcdV3Registry) subscribe(svc *common.URL) (registry.Listener, error) { //register the svc to dataListener r.dataListener.AddInterestedURL(svc) - go r.listener.ListenServiceEvent(fmt.Sprintf("/dubbo/%s/providers", svc.Service()), r.dataListener) + for _, v := range strings.Split(svc.GetParam(constant.CATEGORY_KEY, constant.DEFAULT_CATEGORY), ",") { + go r.listener.ListenServiceEvent(fmt.Sprintf("/dubbo/%s/"+v, svc.Service()), r.dataListener) + } return configListener, nil } diff --git a/registry/protocol/protocol.go b/registry/protocol/protocol.go index 0289ddac56..75563bc2f7 100644 --- a/registry/protocol/protocol.go +++ b/registry/protocol/protocol.go @@ -18,9 +18,6 @@ package protocol import ( - "github.com/apache/dubbo-go/config" - "github.com/apache/dubbo-go/config_center" - "github.com/apache/dubbo-go/remoting" "strings" "sync" ) @@ -30,10 +27,14 @@ import ( "github.com/apache/dubbo-go/common/constant" "github.com/apache/dubbo-go/common/extension" "github.com/apache/dubbo-go/common/logger" + "github.com/apache/dubbo-go/config" + "github.com/apache/dubbo-go/config_center" + _ "github.com/apache/dubbo-go/config_center/configurator" "github.com/apache/dubbo-go/protocol" "github.com/apache/dubbo-go/protocol/protocolwrapper" "github.com/apache/dubbo-go/registry" directory2 "github.com/apache/dubbo-go/registry/directory" + "github.com/apache/dubbo-go/remoting" ) var ( @@ -43,13 +44,14 @@ var ( type registryProtocol struct { invokers []protocol.Invoker // Registry Map - registries sync.Map + registries *sync.Map //To solve the problem of RMI repeated exposure port conflicts, the services that have been exposed are no longer exposed. //providerurl <--> exporter - bounds sync.Map - overrideListeners sync.Map - serviceConfigurationListeners sync.Map + bounds *sync.Map + overrideListeners *sync.Map + serviceConfigurationListeners *sync.Map providerConfigurationListener *providerConfigurationListener + once sync.Once } func init() { @@ -63,13 +65,9 @@ func getCacheKey(url *common.URL) string { return newUrl.String() } func newRegistryProtocol() *registryProtocol { - overrideListeners := sync.Map{} return ®istryProtocol{ - overrideListeners: overrideListeners, - registries: sync.Map{}, - bounds: sync.Map{}, - serviceConfigurationListeners: sync.Map{}, - providerConfigurationListener: newProviderConfigurationListener(&overrideListeners), + registries: &sync.Map{}, + bounds: &sync.Map{}, } } func getRegistry(regUrl *common.URL) registry.Registry { @@ -80,6 +78,11 @@ func getRegistry(regUrl *common.URL) registry.Registry { } return reg } +func (proto *registryProtocol) initConfigurationListeners() { + proto.overrideListeners = &sync.Map{} + proto.serviceConfigurationListeners = &sync.Map{} + proto.providerConfigurationListener = newProviderConfigurationListener(proto.overrideListeners) +} func (proto *registryProtocol) Refer(url common.URL) protocol.Invoker { var registryUrl = url @@ -119,6 +122,10 @@ func (proto *registryProtocol) Refer(url common.URL) protocol.Invoker { } func (proto *registryProtocol) Export(invoker protocol.Invoker) protocol.Exporter { + + proto.once.Do(func() { + proto.initConfigurationListeners() + }) registryUrl := getRegistryUrl(invoker) providerUrl := getProviderUrl(invoker) @@ -197,14 +204,17 @@ func (nl *overrideSubscribeListener) doOverrideIfNecessary() { if exporter, ok := nl.protocol.bounds.Load(key); ok { currentUrl := exporter.(protocol.Exporter).GetInvoker().GetUrl() // Compatible with the 2.6.x - nl.configurator.Configure(providerUrl) + if nl.configurator != nil { + nl.configurator.Configure(providerUrl) + } // provider application level management in 2.7.x for _, v := range nl.protocol.providerConfigurationListener.Configurators() { v.Configure(providerUrl) } // provider service level management in 2.7.x if serviceListener, ok := nl.protocol.serviceConfigurationListeners.Load(providerUrl.ServiceKey()); ok { - for _, v := range serviceListener.(*serviceConfigurationListener).Configurators() { + listener := serviceListener.(*serviceConfigurationListener) + for _, v := range listener.Configurators() { v.Configure(providerUrl) } } @@ -247,7 +257,10 @@ func isMatched(providerUrl *common.URL, consumerUrl *common.URL) bool { //todo: public static boolean isContains(String values, String value) { // return isNotEmpty(values) && isContains(COMMA_SPLIT_PATTERN.split(values), value); // } - return (consumerGroup == constant.ANY_VALUE || consumerGroup == providerGroup || strings.Contains(consumerGroup, providerGroup)) && (consumerVersion == constant.ANY_VALUE || consumerVersion == providerVersion) && (consumerClassifier == "" || consumerClassifier == constant.ANY_VALUE || consumerClassifier == providerClassifier) + return (consumerGroup == constant.ANY_VALUE || consumerGroup == providerGroup || + strings.Contains(consumerGroup, providerGroup)) && (consumerVersion == constant.ANY_VALUE || + consumerVersion == providerVersion) && (len(consumerClassifier) == 0 || consumerClassifier == constant.ANY_VALUE || + consumerClassifier == providerClassifier) } func isMatchCategory(category string, categories string) bool { if categories == "" { @@ -346,8 +359,7 @@ type providerConfigurationListener struct { func newProviderConfigurationListener(overrideListeners *sync.Map) *providerConfigurationListener { listener := &providerConfigurationListener{} listener.overrideListeners = overrideListeners - //TODO:error handler - listener.BaseConfigurationListener.InitWith(config.GetProviderConfig().ApplicationConfig.Name+constant.CONFIGURATORS_SUFFIX, listener, extension.GetDefaultConfiguratorFunc()) + listener.InitWith(config.GetProviderConfig().ApplicationConfig.Name+constant.CONFIGURATORS_SUFFIX, listener, extension.GetDefaultConfiguratorFunc()) return listener } @@ -367,9 +379,8 @@ type serviceConfigurationListener struct { func newServiceConfigurationListener(overrideListener *overrideSubscribeListener, providerUrl *common.URL) *serviceConfigurationListener { listener := &serviceConfigurationListener{overrideListener: overrideListener, providerUrl: providerUrl} - //TODO:error handler - listener.BaseConfigurationListener.InitWith(providerUrl.EncodedServiceKey()+constant.CONFIGURATORS_SUFFIX, listener, extension.GetDefaultConfiguratorFunc()) - return &serviceConfigurationListener{overrideListener: overrideListener, providerUrl: providerUrl} + listener.InitWith(providerUrl.EncodedServiceKey()+constant.CONFIGURATORS_SUFFIX, listener, extension.GetDefaultConfiguratorFunc()) + return listener } func (listener *serviceConfigurationListener) Process(event *config_center.ConfigChangeEvent) { diff --git a/registry/protocol/protocol_test.go b/registry/protocol/protocol_test.go index 55b031bfdb..45f9069a73 100644 --- a/registry/protocol/protocol_test.go +++ b/registry/protocol/protocol_test.go @@ -43,8 +43,7 @@ import ( ) func init() { - extension.SetDefaultConfigurator(configurator.NewMockConfigurator) - config.SetProviderConfig(config.ProviderConfig{ApplicationConfig: &config.ApplicationConfig{Name: "mock"}}) + config.SetProviderConfig(config.ProviderConfig{ApplicationConfig: &config.ApplicationConfig{Name: "test-application"}}) } func referNormal(t *testing.T, regProtocol *registryProtocol) { extension.SetProtocol("registry", GetProtocol) @@ -63,6 +62,7 @@ func referNormal(t *testing.T, regProtocol *registryProtocol) { } func TestRefer(t *testing.T) { + config.SetConsumerConfig(config.ConsumerConfig{ApplicationConfig: &config.ApplicationConfig{Name: "test-application"}}) regProtocol := newRegistryProtocol() referNormal(t, regProtocol) } @@ -107,7 +107,7 @@ func exporterNormal(t *testing.T, regProtocol *registryProtocol) *common.URL { extension.SetRegistry("mock", registry.NewMockRegistry) extension.SetProtocol(protocolwrapper.FILTER, protocolwrapper.NewMockProtocolFilter) url, _ := common.NewURL(context.TODO(), "mock://127.0.0.1:1111") - suburl, _ := common.NewURL(context.TODO(), "dubbo://127.0.0.1:20000/org.apache.dubbo-go.mockService", common.WithParamsValue(constant.CLUSTER_KEY, "mock")) + suburl, _ := common.NewURL(context.TODO(), "dubbo://127.0.0.1:20000/org.apache.dubbo-go.mockService", common.WithParamsValue(constant.CLUSTER_KEY, "mock"), common.WithParamsValue(constant.GROUP_KEY, "group"), common.WithParamsValue(constant.VERSION_KEY, "1.0.0")) url.SubURL = &suburl invoker := protocol.NewBaseInvoker(url) @@ -155,7 +155,7 @@ func TestOneRegAndProtoExporter(t *testing.T) { exporterNormal(t, regProtocol) url2, _ := common.NewURL(context.TODO(), "mock://127.0.0.1:1111") - suburl2, _ := common.NewURL(context.TODO(), "dubbo://127.0.0.1:20000//", common.WithParamsValue(constant.CLUSTER_KEY, "mock")) + suburl2, _ := common.NewURL(context.TODO(), "dubbo://127.0.0.1:20000/org.apache.dubbo-go.mockService", common.WithParamsValue(constant.CLUSTER_KEY, "mock"), common.WithParamsValue(constant.GROUP_KEY, "group"), common.WithParamsValue(constant.VERSION_KEY, "1.0.0")) url2.SubURL = &suburl2 invoker2 := protocol.NewBaseInvoker(url2) @@ -201,9 +201,7 @@ func TestDestry(t *testing.T) { func TestExportWithOverrideListener(t *testing.T) { extension.SetDefaultConfigurator(configurator.NewMockConfigurator) - ccUrl, _ := common.NewURL(context.TODO(), "mock://127.0.0.1:1111") - dc, _ := (&config_center.MockDynamicConfigurationFactory{}).GetDynamicConfiguration(&ccUrl) - common_cfg.GetEnvInstance().SetDynamicConfiguration(dc) + regProtocol := newRegistryProtocol() url := exporterNormal(t, regProtocol) var reg *registry.MockRegistry @@ -213,7 +211,7 @@ func TestExportWithOverrideListener(t *testing.T) { assert.Fail(t, "regProtocol.registries.Load can not be loaded") return } - overrideUrl, _ := common.NewURL(context.Background(), "override://0:0:0:0/org.apache.dubbo-go.mockService?cluster=mock1") + overrideUrl, _ := common.NewURL(context.Background(), "override://0:0:0:0/org.apache.dubbo-go.mockService?cluster=mock1&&group=group&&version=1.0.0") event := ®istry.ServiceEvent{Action: remoting.EventTypeAdd, Service: overrideUrl} reg.MockEvent(event) time.Sleep(1e9) @@ -222,3 +220,41 @@ func TestExportWithOverrideListener(t *testing.T) { v2, _ := regProtocol.bounds.Load(getCacheKey(newUrl)) assert.NotNil(t, v2) } + +func TestExportWithServiceConfig(t *testing.T) { + extension.SetDefaultConfigurator(configurator.NewMockConfigurator) + ccUrl, _ := common.NewURL(context.TODO(), "mock://127.0.0.1:1111") + dc, _ := (&config_center.MockDynamicConfigurationFactory{}).GetDynamicConfiguration(&ccUrl) + common_cfg.GetEnvInstance().SetDynamicConfiguration(dc) + regProtocol := newRegistryProtocol() + url := exporterNormal(t, regProtocol) + if _, loaded := regProtocol.registries.Load(url.Key()); !loaded { + assert.Fail(t, "regProtocol.registries.Load can not be loaded") + return + } + dc.(*config_center.MockDynamicConfiguration).MockServiceConfigEvent() + + newUrl := url.SubURL.Clone() + newUrl.Params.Set(constant.CLUSTER_KEY, "mock1") + v2, _ := regProtocol.bounds.Load(getCacheKey(newUrl)) + assert.NotNil(t, v2) +} + +func TestExportWithApplicationConfig(t *testing.T) { + extension.SetDefaultConfigurator(configurator.NewMockConfigurator) + ccUrl, _ := common.NewURL(context.TODO(), "mock://127.0.0.1:1111") + dc, _ := (&config_center.MockDynamicConfigurationFactory{}).GetDynamicConfiguration(&ccUrl) + common_cfg.GetEnvInstance().SetDynamicConfiguration(dc) + regProtocol := newRegistryProtocol() + url := exporterNormal(t, regProtocol) + if _, loaded := regProtocol.registries.Load(url.Key()); !loaded { + assert.Fail(t, "regProtocol.registries.Load can not be loaded") + return + } + dc.(*config_center.MockDynamicConfiguration).MockApplicationConfigEvent() + + newUrl := url.SubURL.Clone() + newUrl.Params.Set(constant.CLUSTER_KEY, "mock1") + v2, _ := regProtocol.bounds.Load(getCacheKey(newUrl)) + assert.NotNil(t, v2) +} diff --git a/registry/zookeeper/registry.go b/registry/zookeeper/registry.go index e86b7cfcca..e066729d6a 100644 --- a/registry/zookeeper/registry.go +++ b/registry/zookeeper/registry.go @@ -81,7 +81,6 @@ type zkRegistry struct { configListener *RegistryConfigurationListener //for provider zkPath map[string]int // key = protocol://ip:port/interface - } func newZkRegistry(url *common.URL) (registry.Registry, error) { @@ -459,8 +458,9 @@ func (r *zkRegistry) getListener(conf *common.URL) (*RegistryConfigurationListen //Interested register to dataconfig. r.dataListener.AddInterestedURL(conf) - - go r.listener.ListenServiceEvent(fmt.Sprintf("/dubbo/%s/"+conf.GetParam(constant.CATEGORY_KEY, constant.DEFAULT_CATEGORY), conf.Service()), r.dataListener) + for _, v := range strings.Split(conf.GetParam(constant.CATEGORY_KEY, constant.DEFAULT_CATEGORY), ",") { + go r.listener.ListenServiceEvent(fmt.Sprintf("/dubbo/%s/"+v, conf.Service()), r.dataListener) + } return zkListener, nil } From 4c1886fcd7a120f190f82b65149449fe01580a03 Mon Sep 17 00:00:00 2001 From: "vito.he" Date: Fri, 6 Sep 2019 18:32:31 +0800 Subject: [PATCH 05/34] Add:add license header & format code --- common/config/environment.go | 5 ++++- common/config/environment_test.go | 1 + config/base_config.go | 2 ++ config/config_utils.go | 1 + config/consumer_config.go | 2 ++ config/protocol_config.go | 1 + config/registry_config_test.go | 6 +++++- config_center/configuration_listener.go | 18 ++++++++++++++++++ config_center/configurator.go | 17 +++++++++++++++++ config_center/configurator/override.go | 2 ++ config_center/configurator/override_test.go | 2 ++ config_center/dynamic_configuration.go | 1 + config_center/mock_dynamic_config.go | 10 +++++++--- config_center/parser/configuration_parser.go | 19 +++++++++++++++++++ .../parser/configuration_parser_test.go | 18 ++++++++++++++++++ config_center/zookeeper/factory.go | 3 ++- config_center/zookeeper/impl.go | 4 +++- config_center/zookeeper/listener.go | 1 + registry/base_configuration_listener.go | 17 +++++++++++++++++ registry/mock_registry.go | 7 +++++-- registry/protocol/protocol_test.go | 2 +- registry/zookeeper/listener.go | 4 +++- registry/zookeeper/listener_test.go | 17 +++++++++++++++++ 23 files changed, 149 insertions(+), 11 deletions(-) diff --git a/common/config/environment.go b/common/config/environment.go index 77a962a511..a9447aa120 100644 --- a/common/config/environment.go +++ b/common/config/environment.go @@ -19,11 +19,14 @@ package config import ( "container/list" - "github.com/apache/dubbo-go/config_center" "strings" "sync" ) +import ( + "github.com/apache/dubbo-go/config_center" +) + // There is dubbo.properties file and application level config center configuration which higner than normal config center in java. So in java the // configuration sequence will be config center > application level config center > dubbo.properties > spring bean configuration. // But in go, neither the dubbo.properties file or application level config center configuration will not support for the time being. diff --git a/common/config/environment_test.go b/common/config/environment_test.go index ab7cafae89..0e1d679bc4 100644 --- a/common/config/environment_test.go +++ b/common/config/environment_test.go @@ -19,6 +19,7 @@ package config import ( "testing" ) + import ( "github.com/stretchr/testify/assert" ) diff --git a/config/base_config.go b/config/base_config.go index 65cc0fe3f9..6c85b5e46a 100644 --- a/config/base_config.go +++ b/config/base_config.go @@ -21,9 +21,11 @@ import ( "reflect" "strconv" ) + import ( perrors "github.com/pkg/errors" ) + import ( "github.com/apache/dubbo-go/common" "github.com/apache/dubbo-go/common/config" diff --git a/config/config_utils.go b/config/config_utils.go index 90837344ca..6bc574a546 100644 --- a/config/config_utils.go +++ b/config/config_utils.go @@ -21,6 +21,7 @@ import ( "regexp" "strings" ) + import ( "github.com/apache/dubbo-go/common/constant" ) diff --git a/config/consumer_config.go b/config/consumer_config.go index 55082ffe41..ebeb7fe75d 100644 --- a/config/consumer_config.go +++ b/config/consumer_config.go @@ -22,10 +22,12 @@ import ( "path" "time" ) + import ( perrors "github.com/pkg/errors" "gopkg.in/yaml.v2" ) + import ( "github.com/apache/dubbo-go/common/constant" "github.com/apache/dubbo-go/common/logger" diff --git a/config/protocol_config.go b/config/protocol_config.go index 6440f3090d..b71423670c 100644 --- a/config/protocol_config.go +++ b/config/protocol_config.go @@ -19,6 +19,7 @@ package config import ( "strings" ) + import ( "github.com/apache/dubbo-go/common/constant" ) diff --git a/config/registry_config_test.go b/config/registry_config_test.go index f600a21a01..45d38b29cc 100644 --- a/config/registry_config_test.go +++ b/config/registry_config_test.go @@ -20,11 +20,15 @@ import ( "fmt" "testing" ) + import ( - "github.com/apache/dubbo-go/common" "github.com/stretchr/testify/assert" ) +import ( + "github.com/apache/dubbo-go/common" +) + func Test_loadRegistries(t *testing.T) { target := "shanghai1" regs := map[string]*RegistryConfig{ diff --git a/config_center/configuration_listener.go b/config_center/configuration_listener.go index 5367ee72df..1419bcdd0c 100644 --- a/config_center/configuration_listener.go +++ b/config_center/configuration_listener.go @@ -1,8 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 config_center import ( "fmt" ) + import ( "github.com/apache/dubbo-go/remoting" ) diff --git a/config_center/configurator.go b/config_center/configurator.go index 0b0b1ddee8..3ba293ec60 100644 --- a/config_center/configurator.go +++ b/config_center/configurator.go @@ -1,3 +1,20 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 config_center import ( diff --git a/config_center/configurator/override.go b/config_center/configurator/override.go index a4a97294d2..458e2f44e9 100644 --- a/config_center/configurator/override.go +++ b/config_center/configurator/override.go @@ -19,9 +19,11 @@ package configurator import ( "strings" ) + import ( "github.com/dubbogo/gost/container" ) + import ( "github.com/apache/dubbo-go/common" "github.com/apache/dubbo-go/common/constant" diff --git a/config_center/configurator/override_test.go b/config_center/configurator/override_test.go index e03056ded5..2790488f27 100644 --- a/config_center/configurator/override_test.go +++ b/config_center/configurator/override_test.go @@ -20,9 +20,11 @@ import ( "context" "testing" ) + import ( "github.com/stretchr/testify/assert" ) + import ( "github.com/apache/dubbo-go/common" "github.com/apache/dubbo-go/common/constant" diff --git a/config_center/dynamic_configuration.go b/config_center/dynamic_configuration.go index c3718ee4c9..1028b26d96 100644 --- a/config_center/dynamic_configuration.go +++ b/config_center/dynamic_configuration.go @@ -20,6 +20,7 @@ package config_center import ( "time" ) + import ( "github.com/apache/dubbo-go/config_center/parser" ) diff --git a/config_center/mock_dynamic_config.go b/config_center/mock_dynamic_config.go index 7045c48ec9..e8f10d45ff 100644 --- a/config_center/mock_dynamic_config.go +++ b/config_center/mock_dynamic_config.go @@ -18,14 +18,18 @@ package config_center import ( - "github.com/apache/dubbo-go/common/constant" - "github.com/apache/dubbo-go/remoting" - "gopkg.in/yaml.v2" "sync" ) + +import ( + "gopkg.in/yaml.v2" +) + import ( "github.com/apache/dubbo-go/common" + "github.com/apache/dubbo-go/common/constant" "github.com/apache/dubbo-go/config_center/parser" + "github.com/apache/dubbo-go/remoting" ) type MockDynamicConfigurationFactory struct{} diff --git a/config_center/parser/configuration_parser.go b/config_center/parser/configuration_parser.go index bc0eb1182d..da140da3ef 100644 --- a/config_center/parser/configuration_parser.go +++ b/config_center/parser/configuration_parser.go @@ -1,3 +1,20 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 parser import ( @@ -5,11 +22,13 @@ import ( "strconv" "strings" ) + import ( "github.com/magiconair/properties" perrors "github.com/pkg/errors" "gopkg.in/yaml.v2" ) + import ( "github.com/apache/dubbo-go/common" "github.com/apache/dubbo-go/common/constant" diff --git a/config_center/parser/configuration_parser_test.go b/config_center/parser/configuration_parser_test.go index 08490e8581..7a59ea9b48 100644 --- a/config_center/parser/configuration_parser_test.go +++ b/config_center/parser/configuration_parser_test.go @@ -1,8 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 parser import ( "testing" ) + import ( "github.com/stretchr/testify/assert" ) diff --git a/config_center/zookeeper/factory.go b/config_center/zookeeper/factory.go index ac10d2a76f..611f4b9785 100644 --- a/config_center/zookeeper/factory.go +++ b/config_center/zookeeper/factory.go @@ -18,13 +18,14 @@ package zookeeper import ( - "github.com/apache/dubbo-go/config_center/parser" "sync" ) + import ( "github.com/apache/dubbo-go/common" "github.com/apache/dubbo-go/common/extension" "github.com/apache/dubbo-go/config_center" + "github.com/apache/dubbo-go/config_center/parser" ) func init() { diff --git a/config_center/zookeeper/impl.go b/config_center/zookeeper/impl.go index 1858a5a83d..84e4b54e23 100644 --- a/config_center/zookeeper/impl.go +++ b/config_center/zookeeper/impl.go @@ -18,20 +18,22 @@ package zookeeper import ( - "github.com/apache/dubbo-go/config_center/parser" "strings" "sync" "time" ) + import ( perrors "github.com/pkg/errors" "github.com/samuel/go-zookeeper/zk" ) + import ( "github.com/apache/dubbo-go/common" "github.com/apache/dubbo-go/common/constant" "github.com/apache/dubbo-go/common/logger" "github.com/apache/dubbo-go/config_center" + "github.com/apache/dubbo-go/config_center/parser" "github.com/apache/dubbo-go/remoting/zookeeper" ) diff --git a/config_center/zookeeper/listener.go b/config_center/zookeeper/listener.go index 0874f0c2f7..7128b6f5a3 100644 --- a/config_center/zookeeper/listener.go +++ b/config_center/zookeeper/listener.go @@ -21,6 +21,7 @@ import ( "strings" "sync" ) + import ( "github.com/apache/dubbo-go/config_center" "github.com/apache/dubbo-go/remoting" diff --git a/registry/base_configuration_listener.go b/registry/base_configuration_listener.go index 791996340d..925baa2198 100644 --- a/registry/base_configuration_listener.go +++ b/registry/base_configuration_listener.go @@ -1,3 +1,20 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 registry import ( diff --git a/registry/mock_registry.go b/registry/mock_registry.go index 29922ef5bb..512c452e39 100644 --- a/registry/mock_registry.go +++ b/registry/mock_registry.go @@ -18,13 +18,16 @@ package registry import ( - "github.com/apache/dubbo-go/common/logger" - "go.uber.org/atomic" "time" ) +import ( + "go.uber.org/atomic" +) + import ( "github.com/apache/dubbo-go/common" + "github.com/apache/dubbo-go/common/logger" ) type MockRegistry struct { diff --git a/registry/protocol/protocol_test.go b/registry/protocol/protocol_test.go index 45f9069a73..56d9fe7d1a 100644 --- a/registry/protocol/protocol_test.go +++ b/registry/protocol/protocol_test.go @@ -19,7 +19,6 @@ package protocol import ( "context" - "github.com/apache/dubbo-go/remoting" "testing" "time" ) @@ -40,6 +39,7 @@ import ( "github.com/apache/dubbo-go/protocol" "github.com/apache/dubbo-go/protocol/protocolwrapper" "github.com/apache/dubbo-go/registry" + "github.com/apache/dubbo-go/remoting" ) func init() { diff --git a/registry/zookeeper/listener.go b/registry/zookeeper/listener.go index 688ede8b65..857421f077 100644 --- a/registry/zookeeper/listener.go +++ b/registry/zookeeper/listener.go @@ -19,15 +19,17 @@ package zookeeper import ( "context" - "github.com/apache/dubbo-go/config_center" "strings" ) + import ( perrors "github.com/pkg/errors" ) + import ( "github.com/apache/dubbo-go/common" "github.com/apache/dubbo-go/common/logger" + "github.com/apache/dubbo-go/config_center" "github.com/apache/dubbo-go/registry" "github.com/apache/dubbo-go/remoting" zk "github.com/apache/dubbo-go/remoting/zookeeper" diff --git a/registry/zookeeper/listener_test.go b/registry/zookeeper/listener_test.go index c30e5d47d2..ca8e442684 100644 --- a/registry/zookeeper/listener_test.go +++ b/registry/zookeeper/listener_test.go @@ -1,3 +1,20 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 zookeeper import ( From 49dc253b008cdc8c4f3619bc44de281691a5dfe8 Mon Sep 17 00:00:00 2001 From: "vito.he" Date: Fri, 6 Sep 2019 19:11:26 +0800 Subject: [PATCH 06/34] Mod:dependency modify --- go.mod | 2 -- go.sum | 2 -- 2 files changed, 4 deletions(-) diff --git a/go.mod b/go.mod index f88e82a6d2..37781aee51 100644 --- a/go.mod +++ b/go.mod @@ -30,8 +30,6 @@ require ( github.com/lestrrat/go-file-rotatelogs v0.0.0-20180223000712-d3151e2a480f // indirect github.com/lestrrat/go-strftime v0.0.0-20180220042222-ba3bf9c1d042 // indirect github.com/magiconair/properties v1.8.1 - github.com/mitchellh/copystructure v1.0.0 - github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 github.com/nacos-group/nacos-sdk-go v0.0.0-20190723125407-0242d42e3dbb github.com/pkg/errors v0.8.1 github.com/prometheus/client_golang v1.1.0 // indirect diff --git a/go.sum b/go.sum index 0ac707c33b..3758060eef 100644 --- a/go.sum +++ b/go.sum @@ -354,8 +354,6 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw= -github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/nacos-group/nacos-sdk-go v0.0.0-20190723125407-0242d42e3dbb h1:lbmvw8r9W55w+aQgWn35W1nuleRIECMoqUrmwAOAvoI= github.com/nacos-group/nacos-sdk-go v0.0.0-20190723125407-0242d42e3dbb/go.mod h1:CEkSvEpoveoYjA81m4HNeYQ0sge0LFGKSEqO3JKHllo= From cb646cdf73a8f1aa4164520da1c15557085dc698 Mon Sep 17 00:00:00 2001 From: "vito.he" Date: Fri, 6 Sep 2019 19:20:53 +0800 Subject: [PATCH 07/34] Mod:dependency modify --- go.sum | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/go.sum b/go.sum index 3758060eef..cde014464a 100644 --- a/go.sum +++ b/go.sum @@ -39,7 +39,6 @@ github.com/apache/dubbo-go-hessian2 v1.2.5-0.20190731020727-1697039810c8 h1:7zJl github.com/apache/dubbo-go-hessian2 v1.2.5-0.20190731020727-1697039810c8/go.mod h1:LWnndnrFXZmJLAzoyNAPNHSIJ1KOHVkTSsHgC3YYWlo= github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e h1:QEF07wC0T1rKkctt1RINW/+RMTVmiwxETico2l3gxJA= github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= -github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da h1:8GUt8eRujhVEGZFFEjBj46YV4rDjvGrNxb0KMWYkL2I= github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= github.com/armon/go-metrics v0.0.0-20190430140413-ec5e00d3c878 h1:EFSB7Zo9Eg91v7MJPVsifUysc/wPdN+NOnVe6bWbdBM= github.com/armon/go-metrics v0.0.0-20190430140413-ec5e00d3c878/go.mod h1:3AMJUQhVx52RsWOnlkpikZr01T/yAVN2gn0861vByNg= @@ -217,7 +216,6 @@ github.com/hashicorp/go-immutable-radix v1.0.0 h1:AKDB1HM5PWEA7i4nhcpwOrO2byshxB github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= github.com/hashicorp/go-memdb v0.0.0-20180223233045-1289e7fffe71 h1:yxxFgVz31vFoKKTtRUNbXLNe4GFnbLKqg+0N7yG42L8= github.com/hashicorp/go-memdb v0.0.0-20180223233045-1289e7fffe71/go.mod h1:kbfItVoBJwCfKXDXN4YoAXjxcFVZ7MRrJzyTX6H4giE= -github.com/hashicorp/go-msgpack v0.5.3 h1:zKjpN5BK/P5lMYrLmBHdBULWbJ0XpYR+7NGzqkZzoD4= github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= github.com/hashicorp/go-msgpack v0.5.5 h1:i9R9JSrqIz0QVLz3sz+i3YJdT7TTSLcfLLzJi9aZTuI= github.com/hashicorp/go-msgpack v0.5.5/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= @@ -229,7 +227,7 @@ github.com/hashicorp/go-raftchunking v0.6.1 h1:moEnaG3gcwsWNyIBJoD5PCByE+Ewkqxh6 github.com/hashicorp/go-raftchunking v0.6.1/go.mod h1:cGlg3JtDy7qy6c/3Bu660Mic1JF+7lWqIwCFSb08fX0= github.com/hashicorp/go-retryablehttp v0.5.3 h1:QlWt0KvWT0lq8MFppF9tsJGF+ynG7ztc2KIPhzRGk7s= github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs= -github.com/hashicorp/go-rootcerts v1.0.0 h1:ueI78wUjYExhCvMLow4icJnayNNFRgy0d9EGs/a1T44= +github.com/hashicorp/go-rootcerts v1.0.0 h1:Rqb66Oo1X/eSV1x66xbDccZjhJigjg0+e82kpwzSwCI= github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU= github.com/hashicorp/go-sockaddr v1.0.0 h1:GeH6tui99pF4NJgfnhp+L6+FfobzVW3Ah46sLo0ICXs= github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU= @@ -252,7 +250,6 @@ github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= github.com/hashicorp/mdns v1.0.1 h1:XFSOubp8KWB+Jd2PDyaX5xUd5bhSP/+pTDZVDMzZJM8= github.com/hashicorp/mdns v1.0.1/go.mod h1:4gW7WsVCke5TE7EPeYliwHlRUyBtfCwuFwuMg2DmyNY= -github.com/hashicorp/memberlist v0.1.3 h1:EmmoJme1matNzb+hMpDuR/0sbJSUisxyqBGG676r31M= github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= github.com/hashicorp/memberlist v0.1.4 h1:gkyML/r71w3FL8gUi74Vk76avkj/9lYAY9lvg0OcoGs= github.com/hashicorp/memberlist v0.1.4/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= @@ -296,8 +293,6 @@ github.com/json-iterator/go v1.1.7 h1:KfgG9LzI+pYjr4xvmz/5H4FXjokeP+rlHLhv3iH62F github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= -github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= -github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/keybase/go-crypto v0.0.0-20180614160407-5114a9a81e1b h1:VE6r2OwP5gj+Z9aCkSKl3MlmnZbfMAjhvR5T7abKHEo= @@ -374,7 +369,6 @@ github.com/ory/dockertest v3.3.4+incompatible h1:VrpM6Gqg7CrPm3bL4Wm1skO+zFWLbh7 github.com/ory/dockertest v3.3.4+incompatible/go.mod h1:1vX4m9wsvi00u5bseYwXaSnhNrne+V0E6LAcBILJdPs= github.com/packethost/packngo v0.1.1-0.20180711074735-b9cb5096f54c h1:vwpFWvAO8DeIZfFeqASzZfsxuWPno9ncAebBEP0N3uE= github.com/packethost/packngo v0.1.1-0.20180711074735-b9cb5096f54c/go.mod h1:otzZQXgoO96RTzDB/Hycg0qZcXZsWJGJRSXbmEIJ+4M= -github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c h1:Lgl0gzECD8GnQ5QCWA8o6BtfL6mDH5rQgM4/fX3avOs= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY= github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= @@ -427,11 +421,8 @@ github.com/sirupsen/logrus v1.2.0 h1:juTguoYk5qI21pwyTXY3B3Y5cOTH3ZUyZCg1v/mihuo github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/smartystreets/assertions v0.0.0-20180820201707-7c9eb446e3cf/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= -github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= -github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/goconvey v0.0.0-20180222194500-ef6db91d284a/go.mod h1:XDJAKZRPZ1CvBcN2aX5YOUTYGHki24fSF0Iv48Ibg0s= -github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a h1:pa8hGb/2YqsZKovtsgrwcDH1RZhVbTKCjLp47XpqCDs= github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/smartystreets/goconvey v0.0.0-20190710185942-9d28bd7c0945 h1:N8Bg45zpk/UcpNGnfJt2y/3lRWASHNTUET8owPYCgYI= github.com/smartystreets/goconvey v0.0.0-20190710185942-9d28bd7c0945/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= @@ -473,7 +464,6 @@ go.uber.org/zap v1.10.0 h1:ORx85nbTijNz8ljznvCMR1ZBIPKFn3jQrag10X2AsuM= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c h1:Vj5n4GlwjmQteupaxJ9+0FNOmBrHfq7vN4btdGoDZgI= golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= @@ -510,7 +500,6 @@ golang.org/x/sys v0.0.0-20190508220229-2d0786266e9c/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190523142557-0e01d883c5c5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3 h1:4y9KwBHBgBNwDbtu44R5o1fdOCQUEXhbk/P4A9WmJq0= golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= From 2b5ee466e960c86347e305ffef51920308deb5c1 Mon Sep 17 00:00:00 2001 From: "vito.he" Date: Fri, 6 Sep 2019 19:29:21 +0800 Subject: [PATCH 08/34] Mod:dependency modify --- go.sum | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/go.sum b/go.sum index cde014464a..24b4a7afb0 100644 --- a/go.sum +++ b/go.sum @@ -186,7 +186,7 @@ github.com/gotestyourself/gotestyourself v2.2.0+incompatible h1:1yOKgt0XYKUg1HOK github.com/gotestyourself/gotestyourself v2.2.0+incompatible/go.mod h1:zZKM6oeNM8k+FRljX1mnzVYeS8wiGgQyvST1/GafPbY= github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 h1:pdN6V1QBWetyv/0+wjACpqVH+eVULgEjkurDLq3goeM= github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= -github.com/grpc-ecosystem/go-grpc-middleware v1.0.0 h1:BWIsLfhgKhV5g/oF34aRjniBHLTZe5DNekSjbAjIS6c= +github.com/grpc-ecosystem/go-grpc-middleware v1.0.0 h1:Iju5GlWwrvL6UBg4zJJt3btmonfrMlCDdsejg4CZE7c= github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= @@ -423,6 +423,7 @@ github.com/smartystreets/assertions v0.0.0-20180820201707-7c9eb446e3cf/go.mod h1 github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/goconvey v0.0.0-20180222194500-ef6db91d284a/go.mod h1:XDJAKZRPZ1CvBcN2aX5YOUTYGHki24fSF0Iv48Ibg0s= +github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a h1:pa8hGb/2YqsZKovtsgrwcDH1RZhVbTKCjLp47XpqCDs= github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/smartystreets/goconvey v0.0.0-20190710185942-9d28bd7c0945 h1:N8Bg45zpk/UcpNGnfJt2y/3lRWASHNTUET8owPYCgYI= github.com/smartystreets/goconvey v0.0.0-20190710185942-9d28bd7c0945/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= @@ -464,6 +465,7 @@ go.uber.org/zap v1.10.0 h1:ORx85nbTijNz8ljznvCMR1ZBIPKFn3jQrag10X2AsuM= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c h1:Vj5n4GlwjmQteupaxJ9+0FNOmBrHfq7vN4btdGoDZgI= golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= @@ -500,6 +502,7 @@ golang.org/x/sys v0.0.0-20190508220229-2d0786266e9c/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190523142557-0e01d883c5c5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3 h1:4y9KwBHBgBNwDbtu44R5o1fdOCQUEXhbk/P4A9WmJq0= golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= From 08b86ada50981009d89e513ab0605dca27fabfc3 Mon Sep 17 00:00:00 2001 From: "vito.he" Date: Mon, 9 Sep 2019 13:32:19 +0800 Subject: [PATCH 09/34] Mod:bug in directory cache invoker --- registry/directory/directory.go | 13 ++++++++++-- registry/directory/directory_test.go | 31 ++++++++++++++++++++-------- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/registry/directory/directory.go b/registry/directory/directory.go index 86bb74f76e..54f0acd843 100644 --- a/registry/directory/directory.go +++ b/registry/directory/directory.go @@ -117,8 +117,10 @@ func (dir *registryDirectory) refreshInvokers(res *registry.ServiceEvent) { if url.Protocol == constant.OVERRIDE_PROTOCOL || url.GetParam(constant.CATEGORY_KEY, constant.DEFAULT_CATEGORY) == constant.CONFIGURATORS_CATEGORY { dir.configurators = append(dir.configurators, extension.GetDefaultConfigurator(url)) + url = nil } else if url.Protocol == constant.ROUTER_PROTOCOL || //2.for router url.GetParam(constant.CATEGORY_KEY, constant.DEFAULT_CATEGORY) == constant.ROUTER_CATEGORY { + url = nil //TODO: router } } @@ -198,12 +200,19 @@ func (dir *registryDirectory) cacheInvoker(url *common.URL) { if url.Protocol == referenceUrl.Protocol || referenceUrl.Protocol == "" { newUrl := common.MergeUrl(url, referenceUrl) dir.overrideUrl(newUrl) - if _, ok := dir.cacheInvokersMap.Load(newUrl.Key()); !ok { - logger.Debugf("service will be added in cache invokers: invokers key is %s!", url.Key()) + if cacheInvoker, ok := dir.cacheInvokersMap.Load(newUrl.Key()); !ok { + logger.Infof("service will be added in cache invokers: invokers url is %s!", newUrl) newInvoker := extension.GetProtocol(protocolwrapper.FILTER).Refer(*newUrl) if newInvoker != nil { dir.cacheInvokersMap.Store(newUrl.Key(), newInvoker) } + } else { + logger.Infof("service will be updated in cache invokers: new invoker url is %s, old invoker url is %s", newUrl, cacheInvoker.(protocol.Invoker).GetUrl()) + newInvoker := extension.GetProtocol(protocolwrapper.FILTER).Refer(*newUrl) + if newInvoker != nil { + dir.cacheInvokersMap.Store(newUrl.Key(), newInvoker) + cacheInvoker.(protocol.Invoker).Destroy() + } } } } diff --git a/registry/directory/directory_test.go b/registry/directory/directory_test.go index d36257888e..e2e18020e2 100644 --- a/registry/directory/directory_test.go +++ b/registry/directory/directory_test.go @@ -144,15 +144,28 @@ func Test_MergeOverrideUrl(t *testing.T) { common.WithParamsValue(constant.GROUP_KEY, "group"), common.WithParamsValue(constant.VERSION_KEY, "1.0.0")) mockRegistry.MockEvent(®istry.ServiceEvent{Action: remoting.EventTypeAdd, Service: providerUrl}) - overrideUrl, _ := common.NewURL(context.TODO(), "override://0.0.0.0:20000/org.apache.dubbo-go.mockService", - common.WithParamsValue(constant.CLUSTER_KEY, "mock1"), - common.WithParamsValue(constant.GROUP_KEY, "group"), - common.WithParamsValue(constant.VERSION_KEY, "1.0.0")) - mockRegistry.MockEvent(®istry.ServiceEvent{Action: remoting.EventTypeAdd, Service: overrideUrl}) - time.Sleep(1e9) - assert.Len(t, registryDirectory.cacheInvokers, 1) - if len(registryDirectory.cacheInvokers) > 0 { - assert.Equal(t, "mock1", registryDirectory.cacheInvokers[0].GetUrl().GetParam(constant.CLUSTER_KEY, "")) +Loop1: + for { + if len(registryDirectory.cacheInvokers) > 0 { + overrideUrl, _ := common.NewURL(context.TODO(), "override://0.0.0.0:20000/org.apache.dubbo-go.mockService", + common.WithParamsValue(constant.CLUSTER_KEY, "mock1"), + common.WithParamsValue(constant.GROUP_KEY, "group"), + common.WithParamsValue(constant.VERSION_KEY, "1.0.0")) + mockRegistry.MockEvent(®istry.ServiceEvent{Action: remoting.EventTypeAdd, Service: overrideUrl}) + Loop2: + for { + if len(registryDirectory.cacheInvokers) > 0 { + if "mock1" == registryDirectory.cacheInvokers[0].GetUrl().GetParam(constant.CLUSTER_KEY, "") { + assert.Len(t, registryDirectory.cacheInvokers, 1) + assert.True(t, true) + break Loop2 + } else { + time.Sleep(500 * time.Millisecond) + } + } + } + break Loop1 + } } } From bf4271b7e1093d6ab49a136c8c8bdc81a64f129e Mon Sep 17 00:00:00 2001 From: "vito.he" Date: Mon, 9 Sep 2019 14:14:18 +0800 Subject: [PATCH 10/34] Mod:remove registry subscribe listen.next sleep error --- registry/consul/registry.go | 1 - registry/etcdv3/registry.go | 1 - registry/nacos/registry.go | 1 - registry/zookeeper/registry.go | 1 - 4 files changed, 4 deletions(-) diff --git a/registry/consul/registry.go b/registry/consul/registry.go index 0fd555429f..1fd3e54e96 100644 --- a/registry/consul/registry.go +++ b/registry/consul/registry.go @@ -150,7 +150,6 @@ func (r *consulRegistry) Subscribe(url *common.URL, notifyListener registry.Noti if serviceEvent, err := listener.Next(); err != nil { logger.Warnf("Selector.watch() = error{%v}", perrors.WithStack(err)) listener.Close() - time.Sleep(time.Duration(RegistryConnDelay) * time.Second) return } else { logger.Infof("update begin, service event: %v", serviceEvent.String()) diff --git a/registry/etcdv3/registry.go b/registry/etcdv3/registry.go index 00231ad800..ca02d1f2ef 100644 --- a/registry/etcdv3/registry.go +++ b/registry/etcdv3/registry.go @@ -352,7 +352,6 @@ func (r *etcdV3Registry) Subscribe(url *common.URL, notifyListener registry.Noti if serviceEvent, err := listener.Next(); err != nil { logger.Warnf("Selector.watch() = error{%v}", perrors.WithStack(err)) listener.Close() - time.Sleep(time.Duration(RegistryConnDelay) * time.Second) return } else { logger.Infof("update begin, service event: %v", serviceEvent.String()) diff --git a/registry/nacos/registry.go b/registry/nacos/registry.go index 52980006e1..3699fab3c5 100644 --- a/registry/nacos/registry.go +++ b/registry/nacos/registry.go @@ -192,7 +192,6 @@ func (r *nacosRegistry) Subscribe(url *common.URL, notifyListener registry.Notif if serviceEvent, err := listener.Next(); err != nil { logger.Warnf("Selector.watch() = error{%v}", perrors.WithStack(err)) listener.Close() - time.Sleep(time.Duration(RegistryConnDelay) * time.Second) return } else { logger.Infof("update begin, service event: %v", serviceEvent.String()) diff --git a/registry/zookeeper/registry.go b/registry/zookeeper/registry.go index ba58848829..6f892b8f4b 100644 --- a/registry/zookeeper/registry.go +++ b/registry/zookeeper/registry.go @@ -420,7 +420,6 @@ func (r *zkRegistry) Subscribe(url *common.URL, notifyListener registry.NotifyLi if serviceEvent, err := listener.Next(); err != nil { logger.Warnf("Selector.watch() = error{%v}", perrors.WithStack(err)) listener.Close() - time.Sleep(time.Duration(RegistryConnDelay) * time.Second) return } else { logger.Infof("update begin, service event: %v", serviceEvent.String()) From 23f5b402a10d8f11b73dd3d9676b088cb7977f35 Mon Sep 17 00:00:00 2001 From: "vito.he" Date: Tue, 10 Sep 2019 18:42:31 +0800 Subject: [PATCH 11/34] Add:support single registry config in config center --- common/config/environment.go | 23 ++-- common/config/environment_test.go | 2 +- common/constant/key.go | 13 ++- config/base_config.go | 106 ++++++++++++++---- config/base_config_test.go | 158 ++++++++++++++++++++++++++- config/config_center_config.go | 21 ++-- config/config_loader.go | 7 ++ config/config_loader_test.go | 93 +++++++++++++++- config/consumer_config.go | 1 + config/provider_config.go | 1 + config/reference_config_test.go | 61 +++++++++-- config/registry_config.go | 49 +++++---- config/service_config_test.go | 54 ++++++++- config_center/mock_dynamic_config.go | 8 +- 14 files changed, 515 insertions(+), 82 deletions(-) diff --git a/common/config/environment.go b/common/config/environment.go index a9447aa120..931f046091 100644 --- a/common/config/environment.go +++ b/common/config/environment.go @@ -36,6 +36,7 @@ type Environment struct { configCenterFirst bool externalConfigs sync.Map externalConfigMap sync.Map + appExternalConfigMap sync.Map dynamicConfiguration config_center.DynamicConfiguration } @@ -50,6 +51,9 @@ func GetEnvInstance() *Environment { }) return instance } +func NewEnvInstance() { + instance = &Environment{configCenterFirst: true} +} //func (env *Environment) SetConfigCenterFirst() { // env.configCenterFirst = true @@ -65,11 +69,17 @@ func (env *Environment) UpdateExternalConfigMap(externalMap map[string]string) { } } +func (env *Environment) UpdateAppExternalConfigMap(externalMap map[string]string) { + for k, v := range externalMap { + env.appExternalConfigMap.Store(k, v) + } +} + func (env *Environment) Configuration() *list.List { list := list.New() - memConf := newInmemoryConfiguration() - memConf.setProperties(&(env.externalConfigMap)) - list.PushBack(memConf) + // The sequence would be: SystemConfiguration -> ExternalConfiguration -> AppExternalConfiguration -> AbstractConfig -> PropertiesConfiguration + list.PushFront(newInmemoryConfiguration(&(env.externalConfigMap))) + list.PushFront(newInmemoryConfiguration(&(env.appExternalConfigMap))) return list } @@ -85,11 +95,8 @@ type InmemoryConfiguration struct { store *sync.Map } -func newInmemoryConfiguration() *InmemoryConfiguration { - return &InmemoryConfiguration{} -} -func (conf *InmemoryConfiguration) setProperties(p *sync.Map) { - conf.store = p +func newInmemoryConfiguration(p *sync.Map) *InmemoryConfiguration { + return &InmemoryConfiguration{store: p} } func (conf *InmemoryConfiguration) GetProperty(key string) (bool, string) { diff --git a/common/config/environment_test.go b/common/config/environment_test.go index 0e1d679bc4..2d84dc4ae3 100644 --- a/common/config/environment_test.go +++ b/common/config/environment_test.go @@ -39,7 +39,7 @@ func TestEnvironment_UpdateExternalConfigMap(t *testing.T) { func TestEnvironment_ConfigurationAndGetProperty(t *testing.T) { GetEnvInstance().UpdateExternalConfigMap(map[string]string{"1": "2"}) list := GetEnvInstance().Configuration() - ok, v := list.Front().Value.(*InmemoryConfiguration).GetProperty("1") + ok, v := list.Back().Value.(*InmemoryConfiguration).GetProperty("1") assert.True(t, ok) assert.Equal(t, "2", v) } diff --git a/common/constant/key.go b/common/constant/key.go index feb6fc9aaa..1b25d11edc 100644 --- a/common/constant/key.go +++ b/common/constant/key.go @@ -91,12 +91,13 @@ const ( COMPATIBLE_CONFIG_KEY = "compatible_config" ) const ( - RegistryConfigPrefix = "dubbo.registries." - ReferenceConfigPrefix = "dubbo.reference." - ServiceConfigPrefix = "dubbo.service." - ProtocolConfigPrefix = "dubbo.protocols." - ProviderConfigPrefix = "dubbo.provider." - ConsumerConfigPrefix = "dubbo.consumer." + RegistryConfigPrefix = "dubbo.registries." + SingleRegistryConfigPrefix = "dubbo.registry." + ReferenceConfigPrefix = "dubbo.reference." + ServiceConfigPrefix = "dubbo.service." + ProtocolConfigPrefix = "dubbo.protocols." + ProviderConfigPrefix = "dubbo.provider." + ConsumerConfigPrefix = "dubbo.consumer." ) const ( diff --git a/config/base_config.go b/config/base_config.go index 6c85b5e46a..e51d8b9550 100644 --- a/config/base_config.go +++ b/config/base_config.go @@ -20,6 +20,7 @@ import ( "context" "reflect" "strconv" + "strings" ) import ( @@ -72,15 +73,43 @@ func (c *BaseConfig) prepareEnvironment() error { logger.Errorf("Get config content in dynamic configuration error , error message is %v", err) return perrors.WithStack(err) } + var appGroup string + var appContent string + if providerConfig != nil && providerConfig.ApplicationConfig != nil && + reflect.ValueOf(c.fatherConfig).Elem().Type().Name() == "ProviderConfig" { + appGroup = providerConfig.ApplicationConfig.Name + } else if consumerConfig != nil && consumerConfig.ApplicationConfig != nil && + reflect.ValueOf(c.fatherConfig).Elem().Type().Name() == "ConsumerConfig" { + appGroup = consumerConfig.ApplicationConfig.Name + } + + if len(appGroup) != 0 { + configFile := c.ConfigCenterConfig.AppConfigFile + if len(configFile) == 0 { + configFile = c.ConfigCenterConfig.ConfigFile + } + appContent, err = dynamicConfig.GetConfig(configFile, config_center.WithGroup(appGroup)) + } + //global config file mapContent, err := dynamicConfig.Parser().Parse(content) if err != nil { return perrors.WithStack(err) } config.GetEnvInstance().UpdateExternalConfigMap(mapContent) + + //appGroup config file + if len(appContent) != 0 { + appMapConent, err := dynamicConfig.Parser().Parse(appContent) + if err != nil { + return perrors.WithStack(err) + } + config.GetEnvInstance().UpdateAppExternalConfigMap(appMapConent) + } + return nil } -func getKeyPrefix(val reflect.Value, id reflect.Value) string { +func getKeyPrefix(val reflect.Value, id reflect.Value) []string { var ( prefix string idStr string @@ -94,21 +123,42 @@ func getKeyPrefix(val reflect.Value, id reflect.Value) string { } else { prefix = val.MethodByName("Prefix").Call(nil)[0].String() } + var retPrefixs []string - if idStr != "" { - return prefix + idStr + "." - } else { - return prefix + for _, pfx := range strings.Split(prefix, "|") { + if idStr != "" { + retPrefixs = append(retPrefixs, pfx+idStr+".") + } else { + retPrefixs = append(retPrefixs, pfx) + } } -} + return retPrefixs +} +func getPtrElement(v reflect.Value) reflect.Value { + if v.Kind() == reflect.Ptr { + v = v.Elem() + if v.Kind() == reflect.Ptr { + return getPtrElement(v) + } + } + return v +} func setFieldValue(val reflect.Value, id reflect.Value, config *config.InmemoryConfiguration) { for i := 0; i < val.NumField(); i++ { if key := val.Type().Field(i).Tag.Get("property"); key != "-" && key != "" { f := val.Field(i) if f.IsValid() { setBaseValue := func(f reflect.Value) { - ok, value := config.GetProperty(getKeyPrefix(val, id) + key) + var ok bool + var value string + prefixs := getKeyPrefix(val, id) + for _, pfx := range prefixs { + ok, value = config.GetProperty(pfx + key) + if ok { + break + } + } if ok { switch f.Kind() { case reflect.Int64: @@ -154,12 +204,12 @@ func setFieldValue(val reflect.Value, id reflect.Value, config *config.InmemoryC } - setBaseValue(f) if f.Kind() == reflect.Ptr { - if f.Elem().Kind() == reflect.Struct { - setFieldValue(f.Elem(), reflect.Value{}, config) + f = getPtrElement(f) + if f.Kind() == reflect.Struct { + setFieldValue(f, reflect.Value{}, config) } else { - setBaseValue(f.Elem()) + setBaseValue(f) } } @@ -170,10 +220,11 @@ func setFieldValue(val reflect.Value, id reflect.Value, config *config.InmemoryC for i := 0; i < f.Len(); i++ { e := f.Index(i) if e.Kind() == reflect.Ptr { - if e.Elem().Kind() == reflect.Struct { - setFieldValue(e.Elem(), reflect.Value{}, config) + e = getPtrElement(e) + if e.Kind() == reflect.Struct { + setFieldValue(e, reflect.Value{}, config) } else { - setBaseValue(e.Elem()) + setBaseValue(e) } } @@ -186,10 +237,16 @@ func setFieldValue(val reflect.Value, id reflect.Value, config *config.InmemoryC //initiate config s := reflect.New(f.Type().Elem().Elem()) prefix := s.MethodByName("Prefix").Call(nil)[0].String() - m := config.GetSubProperty(prefix) - for k := range m { - f.SetMapIndex(reflect.ValueOf(k), reflect.New(f.Type().Elem().Elem())) + for _, pfx := range strings.Split(prefix, "|") { + m := config.GetSubProperty(pfx) + if m != nil { + for k := range m { + f.SetMapIndex(reflect.ValueOf(k), reflect.New(f.Type().Elem().Elem())) + } + } + } + } //iter := f.MapRange() @@ -198,10 +255,11 @@ func setFieldValue(val reflect.Value, id reflect.Value, config *config.InmemoryC v := f.MapIndex(k) switch v.Kind() { case reflect.Ptr: - if v.Elem().Kind() == reflect.Struct { - setFieldValue(v.Elem(), k, config) + v = getPtrElement(v) + if v.Kind() == reflect.Struct { + setFieldValue(v, k, config) } else { - setBaseValue(v.Elem()) + setBaseValue(v) } case reflect.Int64, reflect.String, reflect.Bool, reflect.Float64: setBaseValue(v) @@ -210,6 +268,7 @@ func setFieldValue(val reflect.Value, id reflect.Value, config *config.InmemoryC } } } + setBaseValue(f) } } @@ -217,8 +276,13 @@ func setFieldValue(val reflect.Value, id reflect.Value, config *config.InmemoryC } func (c *BaseConfig) fresh() { configList := config.GetEnvInstance().Configuration() - config := configList.Front().Value.(*config.InmemoryConfiguration) + for element := configList.Front(); element != nil; element = element.Next() { + config := element.Value.(*config.InmemoryConfiguration) + c.freshInternalConfig(config) + } +} +func (c *BaseConfig) freshInternalConfig(config *config.InmemoryConfiguration) { //reflect to init struct tp := reflect.ValueOf(c.fatherConfig).Elem().Type() initializeStruct(tp, reflect.ValueOf(c.fatherConfig).Elem()) diff --git a/config/base_config_test.go b/config/base_config_test.go index d07d983f64..239bece475 100644 --- a/config/base_config_test.go +++ b/config/base_config_test.go @@ -125,6 +125,162 @@ func Test_refresh(t *testing.T) { assert.Equal(t, "dubbo", father.ApplicationConfig.Name) } +func Test_appExternal_refresh(t *testing.T) { + c := &BaseConfig{} + mockMap := map[string]string{} + mockMap["dubbo.registries.shanghai_reg1.protocol"] = "mock100" + mockMap["dubbo.reference.com.MockService.MockService.retries"] = "10" + mockMap["dubbo.com.MockService.MockService.GetUser.retries"] = "10" + mockMap["dubbo.consumer.check"] = "false" + mockMap["dubbo.application.name"] = "dubbo" + + config.GetEnvInstance().UpdateAppExternalConfigMap(mockMap) + mockMap["dubbo.consumer.check"] = "true" + config.GetEnvInstance().UpdateExternalConfigMap(mockMap) + father := &ConsumerConfig{ + Check: &[]bool{true}[0], + ApplicationConfig: &ApplicationConfig{ + Organization: "dubbo_org", + Name: "dubbo", + Module: "module", + Version: "2.6.0", + Owner: "dubbo", + Environment: "test"}, + Registries: map[string]*RegistryConfig{ + //"shanghai_reg1": { + // id: "shanghai_reg1", + // Protocol: "mock", + // TimeoutStr: "2s", + // Group: "shanghai_idc", + // Address: "127.0.0.1:2181", + // Username: "user1", + // Password: "pwd1", + //}, + "shanghai_reg2": { + Protocol: "mock", + TimeoutStr: "2s", + Group: "shanghai_idc", + Address: "127.0.0.2:2181", + Username: "user1", + Password: "pwd1", + }, + "hangzhou_reg1": { + Protocol: "mock", + TimeoutStr: "2s", + Group: "hangzhou_idc", + Address: "127.0.0.3:2181", + Username: "user1", + Password: "pwd1", + }, + "hangzhou_reg2": { + Protocol: "mock", + TimeoutStr: "2s", + Group: "hangzhou_idc", + Address: "127.0.0.4:2181", + Username: "user1", + Password: "pwd1", + }, + }, + References: map[string]*ReferenceConfig{ + "MockService": { + InterfaceName: "com.MockService", + Protocol: "mock", + Cluster: "failover", + Loadbalance: "random", + Retries: 3, + Group: "huadong_idc", + Version: "1.0.0", + Methods: []*MethodConfig{ + { + InterfaceId: "MockService", + InterfaceName: "com.MockService", + Name: "GetUser", + Retries: 2, + Loadbalance: "random", + }, + { + InterfaceId: "MockService", + InterfaceName: "com.MockService", + Name: "GetUser1", + Retries: 2, + Loadbalance: "random", + }, + }, + }, + }, + } + + c.SetFatherConfig(father) + c.fresh() + assert.Equal(t, "mock100", father.Registries["shanghai_reg1"].Protocol) + assert.Equal(t, int64(10), father.References["MockService"].Retries) + + assert.Equal(t, int64(10), father.References["MockService"].Methods[0].Retries) + assert.Equal(t, &[]bool{true}[0], father.Check) + assert.Equal(t, "dubbo", father.ApplicationConfig.Name) +} + +func Test_refresh_singleRegistry(t *testing.T) { + c := &BaseConfig{} + mockMap := map[string]string{} + mockMap["dubbo.registry.address"] = "mock100://127.0.0.1:2181" + mockMap["dubbo.reference.com.MockService.MockService.retries"] = "10" + mockMap["dubbo.com.MockService.MockService.GetUser.retries"] = "10" + mockMap["dubbo.consumer.check"] = "false" + mockMap["dubbo.application.name"] = "dubbo" + + config.GetEnvInstance().UpdateExternalConfigMap(mockMap) + + father := &ConsumerConfig{ + Check: &[]bool{true}[0], + ApplicationConfig: &ApplicationConfig{ + Organization: "dubbo_org", + Name: "dubbo", + Module: "module", + Version: "2.6.0", + Owner: "dubbo", + Environment: "test"}, + Registries: map[string]*RegistryConfig{}, + Registry: &RegistryConfig{}, + References: map[string]*ReferenceConfig{ + "MockService": { + InterfaceName: "com.MockService", + Protocol: "mock", + Cluster: "failover", + Loadbalance: "random", + Retries: 3, + Group: "huadong_idc", + Version: "1.0.0", + Methods: []*MethodConfig{ + { + InterfaceId: "MockService", + InterfaceName: "com.MockService", + Name: "GetUser", + Retries: 2, + Loadbalance: "random", + }, + { + InterfaceId: "MockService", + InterfaceName: "com.MockService", + Name: "GetUser1", + Retries: 2, + Loadbalance: "random", + }, + }, + }, + }, + } + + c.SetFatherConfig(father) + c.fresh() + assert.Equal(t, "mock100://127.0.0.1:2181", father.Registry.Address) + assert.Equal(t, int64(10), father.References["MockService"].Retries) + + assert.Equal(t, int64(10), father.References["MockService"].Methods[0].Retries) + assert.Equal(t, &[]bool{false}[0], father.Check) + assert.Equal(t, "dubbo", father.ApplicationConfig.Name) +} + func Test_refreshProvider(t *testing.T) { c := &BaseConfig{} mockMap := map[string]string{} @@ -233,7 +389,7 @@ func Test_startConfigCenter(t *testing.T) { }} err := c.startConfigCenter(context.Background()) assert.NoError(t, err) - b, v := config.GetEnvInstance().Configuration().Front().Value.(*config.InmemoryConfiguration).GetProperty("dubbo.application.organization") + b, v := config.GetEnvInstance().Configuration().Back().Value.(*config.InmemoryConfiguration).GetProperty("dubbo.application.organization") assert.True(t, b) assert.Equal(t, "ikurento.com", v) } diff --git a/config/config_center_config.go b/config/config_center_config.go index 47efce1265..e7bbd8e24f 100644 --- a/config/config_center_config.go +++ b/config/config_center_config.go @@ -23,14 +23,15 @@ import ( ) type ConfigCenterConfig struct { - context context.Context - Protocol string `required:"true" yaml:"protocol" json:"protocol,omitempty"` - Address string `yaml:"address" json:"address,omitempty"` - Cluster string `yaml:"cluster" json:"cluster,omitempty"` - Group string `default:"dubbo" yaml:"group" json:"group,omitempty"` - Username string `yaml:"username" json:"username,omitempty"` - Password string `yaml:"password" json:"password,omitempty"` - ConfigFile string `default:"dubbo.properties" yaml:"config_file" json:"config_file,omitempty"` - TimeoutStr string `yaml:"timeout" json:"timeout,omitempty"` - timeout time.Duration + context context.Context + Protocol string `required:"true" yaml:"protocol" json:"protocol,omitempty"` + Address string `yaml:"address" json:"address,omitempty"` + Cluster string `yaml:"cluster" json:"cluster,omitempty"` + Group string `default:"dubbo" yaml:"group" json:"group,omitempty"` + Username string `yaml:"username" json:"username,omitempty"` + Password string `yaml:"password" json:"password,omitempty"` + ConfigFile string `default:"dubbo.properties" yaml:"config_file" json:"config_file,omitempty"` + AppConfigFile string `yaml:"app_config_file" json:"app_config_file,omitempty"` + TimeoutStr string `yaml:"timeout" json:"timeout,omitempty"` + timeout time.Duration } diff --git a/config/config_loader.go b/config/config_loader.go index c5127c8c43..8561828ae0 100644 --- a/config/config_loader.go +++ b/config/config_loader.go @@ -54,6 +54,11 @@ func init() { providerConfig = nil } } +func checkRegistries(registries map[string]*RegistryConfig, singleRegistry *RegistryConfig) { + if len(registries) == 0 && singleRegistry != nil { + registries[constant.DEFAULT_KEY] = singleRegistry + } +} // Dubbo Init func Load() { @@ -64,6 +69,7 @@ func Load() { if err := configCenterRefreshConsumer(); err != nil { logger.Errorf("[consumer config center refresh] %#v", err) } + checkRegistries(consumerConfig.Registries, consumerConfig.Registry) for key, ref := range consumerConfig.References { if ref.Generic { genericService := NewGenericService(key) @@ -116,6 +122,7 @@ func Load() { if err := configCenterRefreshProvider(); err != nil { logger.Errorf("[provider config center refresh] %#v", err) } + checkRegistries(providerConfig.Registries, providerConfig.Registry) for key, svs := range providerConfig.Services { rpcService := GetProviderService(key) if rpcService == nil { diff --git a/config/config_loader_test.go b/config/config_loader_test.go index 107fea0b1d..3562bf5a18 100644 --- a/config/config_loader_test.go +++ b/config/config_loader_test.go @@ -29,6 +29,8 @@ import ( import ( "github.com/apache/dubbo-go/cluster/cluster_impl" "github.com/apache/dubbo-go/common" + "github.com/apache/dubbo-go/common/config" + "github.com/apache/dubbo-go/common/constant" "github.com/apache/dubbo-go/common/extension" "github.com/apache/dubbo-go/common/proxy/proxy_factory" "github.com/apache/dubbo-go/config_center" @@ -58,8 +60,36 @@ func TestConfigLoader(t *testing.T) { } func TestLoad(t *testing.T) { - doInit() - doinit() + doInitConsumer() + doInitProvider() + + ms := &MockService{} + SetConsumerService(ms) + SetProviderService(ms) + + extension.SetProtocol("registry", GetProtocol) + extension.SetCluster("registryAware", cluster_impl.NewRegistryAwareCluster) + extension.SetProxyFactory("default", proxy_factory.NewDefaultProxyFactory) + + Load() + + assert.Equal(t, ms, GetRPCService(ms.Reference())) + ms2 := &struct { + MockService + }{} + RPCService(ms2) + assert.NotEqual(t, ms2, GetRPCService(ms2.Reference())) + + conServices = map[string]common.RPCService{} + proServices = map[string]common.RPCService{} + common.ServiceMap.UnRegister("mock", "MockService") + consumerConfig = nil + providerConfig = nil +} + +func TestLoadWithSingleReg(t *testing.T) { + doInitConsumerWithSingleRegistry() + doInitProviderWithSingleRegistry() ms := &MockService{} SetConsumerService(ms) @@ -86,8 +116,8 @@ func TestLoad(t *testing.T) { } func TestWithNoRegLoad(t *testing.T) { - doInit() - doinit() + doInitConsumer() + doInitProvider() providerConfig.Services["MockService"].Registry = "" consumerConfig.References["MockService"].Registry = "" ms := &MockService{} @@ -145,3 +175,58 @@ func TestConfigLoaderWithConfigCenter(t *testing.T) { assert.Equal(t, "127.0.0.1:2181", consumerConfig.Registries["hangzhouzk"].Address) } + +func TestConfigLoaderWithConfigCenterSingleRegistry(t *testing.T) { + consumerConfig = nil + providerConfig = nil + config.NewEnvInstance() + extension.SetConfigCenterFactory("mock", func() config_center.DynamicConfigurationFactory { + return &config_center.MockDynamicConfigurationFactory{Content: ` + dubbo.consumer.request_timeout=5s + dubbo.consumer.connect_timeout=5s + dubbo.application.organization=ikurento.com + dubbo.application.name=BDTService + dubbo.application.module=dubbogo user-info server + dubbo.application.version=0.0.1 + dubbo.application.owner=ZX + dubbo.application.environment=dev + dubbo.registry.address=mock://127.0.0.1:2182 + dubbo.service.com.ikurento.user.UserProvider.protocol=dubbo + dubbo.service.com.ikurento.user.UserProvider.interface=com.ikurento.user.UserProvider + dubbo.service.com.ikurento.user.UserProvider.loadbalance=random + dubbo.service.com.ikurento.user.UserProvider.warmup=100 + dubbo.service.com.ikurento.user.UserProvider.cluster=failover + dubbo.protocols.jsonrpc1.name=jsonrpc + dubbo.protocols.jsonrpc1.ip=127.0.0.1 + dubbo.protocols.jsonrpc1.port=20001 +`} + }) + + conPath, err := filepath.Abs("./testdata/consumer_config_with_configcenter.yml") + assert.NoError(t, err) + proPath, err := filepath.Abs("./testdata/provider_config.yml") + assert.NoError(t, err) + + assert.Nil(t, consumerConfig) + assert.Equal(t, ConsumerConfig{}, GetConsumerConfig()) + assert.Nil(t, providerConfig) + assert.Equal(t, ProviderConfig{}, GetProviderConfig()) + + err = ConsumerInit(conPath) + configCenterRefreshConsumer() + checkRegistries(consumerConfig.Registries, consumerConfig.Registry) + assert.NoError(t, err) + err = ProviderInit(proPath) + configCenterRefreshProvider() + checkRegistries(providerConfig.Registries, providerConfig.Registry) + assert.NoError(t, err) + + assert.NotNil(t, consumerConfig) + assert.NotEqual(t, ConsumerConfig{}, GetConsumerConfig()) + assert.NotNil(t, providerConfig) + assert.NotEqual(t, ProviderConfig{}, GetProviderConfig()) + + assert.Equal(t, "BDTService", consumerConfig.ApplicationConfig.Name) + assert.Equal(t, "mock://127.0.0.1:2182", consumerConfig.Registries[constant.DEFAULT_KEY].Address) + +} diff --git a/config/consumer_config.go b/config/consumer_config.go index ebeb7fe75d..48d1a27609 100644 --- a/config/consumer_config.go +++ b/config/consumer_config.go @@ -51,6 +51,7 @@ type ConsumerConfig struct { ProxyFactory string `yaml:"proxy_factory" default:"default" json:"proxy_factory,omitempty" property:"proxy_factory"` Check *bool `yaml:"check" json:"check,omitempty" property:"check"` + Registry *RegistryConfig `yaml:"registry" json:"registry,omitempty" property:"registry"` Registries map[string]*RegistryConfig `yaml:"registries" json:"registries,omitempty" property:"registries"` References map[string]*ReferenceConfig `yaml:"references" json:"references,omitempty" property:"references"` ProtocolConf interface{} `yaml:"protocol_conf" json:"protocol_conf,omitempty" property:"protocol_conf"` diff --git a/config/provider_config.go b/config/provider_config.go index db8abaf73e..726d05ae6e 100644 --- a/config/provider_config.go +++ b/config/provider_config.go @@ -42,6 +42,7 @@ type ProviderConfig struct { ProxyFactory string `yaml:"proxy_factory" default:"default" json:"proxy_factory,omitempty" property:"proxy_factory"` ApplicationConfig *ApplicationConfig `yaml:"application_config" json:"application_config,omitempty" property:"application_config"` + Registry *RegistryConfig `yaml:"registry" json:"registry,omitempty" property:"registry"` Registries map[string]*RegistryConfig `yaml:"registries" json:"registries,omitempty" property:"registries"` Services map[string]*ServiceConfig `yaml:"services" json:"services,omitempty" property:"services"` Protocols map[string]*ProtocolConfig `yaml:"protocols" json:"protocols,omitempty" property:"protocols"` diff --git a/config/reference_config_test.go b/config/reference_config_test.go index d36fa04d74..4dbdd31d8f 100644 --- a/config/reference_config_test.go +++ b/config/reference_config_test.go @@ -36,7 +36,7 @@ import ( var regProtocol protocol.Protocol -func doInit() { +func doInitConsumer() { consumerConfig = &ConsumerConfig{ ApplicationConfig: &ApplicationConfig{ Organization: "dubbo_org", @@ -110,8 +110,53 @@ func doInit() { } } +func doInitConsumerWithSingleRegistry() { + consumerConfig = &ConsumerConfig{ + ApplicationConfig: &ApplicationConfig{ + Organization: "dubbo_org", + Name: "dubbo", + Module: "module", + Version: "2.6.0", + Owner: "dubbo", + Environment: "test"}, + Registry: &RegistryConfig{ + Address: "mock://27.0.0.1:2181", + Username: "user1", + Password: "pwd1", + }, + Registries: map[string]*RegistryConfig{}, + References: map[string]*ReferenceConfig{ + "MockService": { + Params: map[string]string{ + "serviceid": "soa.mock", + "forks": "5", + }, + InterfaceName: "com.MockService", + Protocol: "mock", + Cluster: "failover", + Loadbalance: "random", + Retries: 3, + Group: "huadong_idc", + Version: "1.0.0", + Methods: []*MethodConfig{ + { + Name: "GetUser", + Retries: 2, + Loadbalance: "random", + }, + { + Name: "GetUser1", + Retries: 2, + Loadbalance: "random", + }, + }, + }, + }, + } +} + func Test_ReferMultireg(t *testing.T) { - doInit() + doInitConsumer() extension.SetProtocol("registry", GetProtocol) extension.SetCluster("registryAware", cluster_impl.NewRegistryAwareCluster) @@ -124,7 +169,7 @@ func Test_ReferMultireg(t *testing.T) { } func Test_Refer(t *testing.T) { - doInit() + doInitConsumer() extension.SetProtocol("registry", GetProtocol) extension.SetCluster("registryAware", cluster_impl.NewRegistryAwareCluster) @@ -137,7 +182,7 @@ func Test_Refer(t *testing.T) { consumerConfig = nil } func Test_ReferP2P(t *testing.T) { - doInit() + doInitConsumer() extension.SetProtocol("dubbo", GetProtocol) m := consumerConfig.References["MockService"] m.Url = "dubbo://127.0.0.1:20000" @@ -151,7 +196,7 @@ func Test_ReferP2P(t *testing.T) { } func Test_ReferMultiP2P(t *testing.T) { - doInit() + doInitConsumer() extension.SetProtocol("dubbo", GetProtocol) m := consumerConfig.References["MockService"] m.Url = "dubbo://127.0.0.1:20000;dubbo://127.0.0.2:20000" @@ -165,7 +210,7 @@ func Test_ReferMultiP2P(t *testing.T) { } func Test_ReferMultiP2PWithReg(t *testing.T) { - doInit() + doInitConsumer() extension.SetProtocol("dubbo", GetProtocol) extension.SetProtocol("registry", GetProtocol) m := consumerConfig.References["MockService"] @@ -180,7 +225,7 @@ func Test_ReferMultiP2PWithReg(t *testing.T) { } func Test_Implement(t *testing.T) { - doInit() + doInitConsumer() extension.SetProtocol("registry", GetProtocol) extension.SetCluster("registryAware", cluster_impl.NewRegistryAwareCluster) for _, reference := range consumerConfig.References { @@ -193,7 +238,7 @@ func Test_Implement(t *testing.T) { } func Test_Forking(t *testing.T) { - doInit() + doInitConsumer() extension.SetProtocol("dubbo", GetProtocol) extension.SetProtocol("registry", GetProtocol) m := consumerConfig.References["MockService"] diff --git a/config/registry_config.go b/config/registry_config.go index 0abdab810f..480377754a 100644 --- a/config/registry_config.go +++ b/config/registry_config.go @@ -43,7 +43,7 @@ type RegistryConfig struct { } func (*RegistryConfig) Prefix() string { - return constant.RegistryConfigPrefix + return constant.RegistryConfigPrefix + "|" + constant.SingleRegistryConfigPrefix } func loadRegistries(targetRegistries string, registries map[string]*RegistryConfig, roleType common.RoleType) []*common.URL { @@ -73,27 +73,22 @@ func loadRegistries(targetRegistries string, registries map[string]*RegistryConf url common.URL err error ) - if addresses := strings.Split(registryConf.Address, ","); len(addresses) > 1 { - url, err = common.NewURL( - context.Background(), - constant.REGISTRY_PROTOCOL+"://"+addresses[0], - common.WithParams(registryConf.getUrlMap(roleType)), - common.WithUsername(registryConf.Username), - common.WithPassword(registryConf.Password), - common.WithLocation(registryConf.Address), - ) - } else { - url, err = common.NewURL( - context.Background(), - constant.REGISTRY_PROTOCOL+"://"+registryConf.Address, - common.WithParams(registryConf.getUrlMap(roleType)), - common.WithUsername(registryConf.Username), - common.WithPassword(registryConf.Password), - ) - } + + addresses := strings.Split(registryConf.Address, ",") + address := addresses[0] + address = traslateRegistryConf(address, registryConf) + url, err = common.NewURL( + context.Background(), + constant.REGISTRY_PROTOCOL+"://"+address, + common.WithParams(registryConf.getUrlMap(roleType)), + common.WithUsername(registryConf.Username), + common.WithPassword(registryConf.Password), + common.WithLocation(registryConf.Address), + ) if err != nil { - logger.Errorf("The registry id:%s url is invalid ,and will skip the registry, error: %#v", k, err) + logger.Errorf("The registry id:%s url is invalid , error: %#v", k, err) + panic(err) } else { urls = append(urls, &url) } @@ -115,3 +110,17 @@ func (regconfig *RegistryConfig) getUrlMap(roleType common.RoleType) url.Values } return urlMap } + +func traslateRegistryConf(address string, registryConf *RegistryConfig) string { + if strings.Contains(address, "://") { + translatedUrl, err := url.Parse(address) + if err != nil { + logger.Errorf("The registry url is invalid , error: %#v", err) + panic(err) + } + address = translatedUrl.Host + registryConf.Protocol = translatedUrl.Scheme + registryConf.Address = strings.Replace(registryConf.Address, translatedUrl.Scheme+"://", "", -1) + } + return address +} diff --git a/config/service_config_test.go b/config/service_config_test.go index f1de3ac08a..d229ce4d2f 100644 --- a/config/service_config_test.go +++ b/config/service_config_test.go @@ -25,7 +25,7 @@ import ( "github.com/apache/dubbo-go/common/extension" ) -func doinit() { +func doInitProvider() { providerConfig = &ProviderConfig{ ApplicationConfig: &ApplicationConfig{ Organization: "dubbo_org", @@ -104,8 +104,58 @@ func doinit() { } } +func doInitProviderWithSingleRegistry() { + providerConfig = &ProviderConfig{ + ApplicationConfig: &ApplicationConfig{ + Organization: "dubbo_org", + Name: "dubbo", + Module: "module", + Version: "2.6.0", + Owner: "dubbo", + Environment: "test"}, + Registry: &RegistryConfig{ + Address: "mock://127.0.0.1:2181", + Username: "user1", + Password: "pwd1", + }, + Registries: map[string]*RegistryConfig{}, + Services: map[string]*ServiceConfig{ + "MockService": { + InterfaceName: "com.MockService", + Protocol: "mock", + Cluster: "failover", + Loadbalance: "random", + Retries: 3, + Group: "huadong_idc", + Version: "1.0.0", + Methods: []*MethodConfig{ + { + Name: "GetUser", + Retries: 2, + Loadbalance: "random", + Weight: 200, + }, + { + Name: "GetUser1", + Retries: 2, + Loadbalance: "random", + Weight: 200, + }, + }, + }, + }, + Protocols: map[string]*ProtocolConfig{ + "mock": { + Name: "mock", + Ip: "127.0.0.1", + Port: "20000", + }, + }, + } +} + func Test_Export(t *testing.T) { - doinit() + doInitProvider() extension.SetProtocol("registry", GetProtocol) for i := range providerConfig.Services { diff --git a/config_center/mock_dynamic_config.go b/config_center/mock_dynamic_config.go index e8f10d45ff..47b509231d 100644 --- a/config_center/mock_dynamic_config.go +++ b/config_center/mock_dynamic_config.go @@ -32,7 +32,9 @@ import ( "github.com/apache/dubbo-go/remoting" ) -type MockDynamicConfigurationFactory struct{} +type MockDynamicConfigurationFactory struct { + Content string +} var ( once sync.Once @@ -44,6 +46,7 @@ func (f *MockDynamicConfigurationFactory) GetDynamicConfiguration(url *common.UR once.Do(func() { dynamicConfiguration = &MockDynamicConfiguration{listener: map[string]ConfigurationListener{}} dynamicConfiguration.SetParser(&parser.DefaultConfigurationParser{}) + dynamicConfiguration.content = ` dubbo.consumer.request_timeout=5s dubbo.consumer.connect_timeout=5s @@ -69,6 +72,9 @@ func (f *MockDynamicConfigurationFactory) GetDynamicConfiguration(url *common.UR dubbo.protocols.jsonrpc1.port=20001 ` }) + if len(f.Content) != 0 { + dynamicConfiguration.content = f.Content + } return dynamicConfiguration, err } From 895e7c369dae9d31fa0e31416cf810c77a300ad4 Mon Sep 17 00:00:00 2001 From: "vito.he" Date: Wed, 11 Sep 2019 14:16:49 +0800 Subject: [PATCH 12/34] Add:add support yaml default tag --- config/application_config.go | 18 +++++++++++++++++- config/config_center_config.go | 15 +++++++++++++++ config/consumer_config.go | 12 ++++++++++++ config/method_config.go | 15 +++++++++++++++ config/provider_config.go | 12 ++++++++++++ config/provider_config_test.go | 19 +++++++++++++++++++ config/reference_config.go | 9 +++++++++ config/registry_config.go | 15 +++++++++++++++ config/service_config.go | 12 ++++++++++++ go.mod | 1 + go.sum | 2 ++ 11 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 config/provider_config_test.go diff --git a/config/application_config.go b/config/application_config.go index af4ffd6acf..fcd4d38c9b 100644 --- a/config/application_config.go +++ b/config/application_config.go @@ -17,7 +17,13 @@ package config -import "github.com/apache/dubbo-go/common/constant" +import ( + "github.com/creasty/defaults" +) + +import ( + "github.com/apache/dubbo-go/common/constant" +) type ApplicationConfig struct { Organization string `yaml:"organization" json:"organization,omitempty" property:"organization"` @@ -37,3 +43,13 @@ func (c *ApplicationConfig) Id() string { func (c *ApplicationConfig) SetId(id string) { } +func (c *ApplicationConfig) UnmarshalYAML(unmarshal func(interface{}) error) error { + if err := defaults.Set(c); err != nil { + return err + } + type plain ApplicationConfig + if err := unmarshal((*plain)(c)); err != nil { + return err + } + return nil +} diff --git a/config/config_center_config.go b/config/config_center_config.go index e7bbd8e24f..9a0bd1ee1d 100644 --- a/config/config_center_config.go +++ b/config/config_center_config.go @@ -22,6 +22,10 @@ import ( "time" ) +import ( + "github.com/creasty/defaults" +) + type ConfigCenterConfig struct { context context.Context Protocol string `required:"true" yaml:"protocol" json:"protocol,omitempty"` @@ -35,3 +39,14 @@ type ConfigCenterConfig struct { TimeoutStr string `yaml:"timeout" json:"timeout,omitempty"` timeout time.Duration } + +func (c *ConfigCenterConfig) UnmarshalYAML(unmarshal func(interface{}) error) error { + if err := defaults.Set(c); err != nil { + return err + } + type plain ConfigCenterConfig + if err := unmarshal((*plain)(c)); err != nil { + return err + } + return nil +} diff --git a/config/consumer_config.go b/config/consumer_config.go index 48d1a27609..9a9f734c4e 100644 --- a/config/consumer_config.go +++ b/config/consumer_config.go @@ -24,6 +24,7 @@ import ( ) import ( + "github.com/creasty/defaults" perrors "github.com/pkg/errors" "gopkg.in/yaml.v2" ) @@ -58,6 +59,17 @@ type ConsumerConfig struct { FilterConf interface{} `yaml:"filter_conf" json:"filter_conf,omitempty" property:"filter_conf" ` } +func (c *ConsumerConfig) UnmarshalYAML(unmarshal func(interface{}) error) error { + if err := defaults.Set(c); err != nil { + return err + } + type plain ConsumerConfig + if err := unmarshal((*plain)(c)); err != nil { + return err + } + return nil +} + func (*ConsumerConfig) Prefix() string { return constant.ConsumerConfigPrefix } diff --git a/config/method_config.go b/config/method_config.go index 95479d1b65..aff322535a 100644 --- a/config/method_config.go +++ b/config/method_config.go @@ -16,6 +16,10 @@ */ package config +import ( + "github.com/creasty/defaults" +) + import ( "github.com/apache/dubbo-go/common/constant" ) @@ -36,3 +40,14 @@ func (c *MethodConfig) Prefix() string { return constant.DUBBO + "." + c.InterfaceName + "." + c.Name + "." } } + +func (c *MethodConfig) UnmarshalYAML(unmarshal func(interface{}) error) error { + if err := defaults.Set(c); err != nil { + return err + } + type plain MethodConfig + if err := unmarshal((*plain)(c)); err != nil { + return err + } + return nil +} diff --git a/config/provider_config.go b/config/provider_config.go index 726d05ae6e..2302cdf0b2 100644 --- a/config/provider_config.go +++ b/config/provider_config.go @@ -23,6 +23,7 @@ import ( ) import ( + "github.com/creasty/defaults" perrors "github.com/pkg/errors" "gopkg.in/yaml.v2" ) @@ -50,6 +51,17 @@ type ProviderConfig struct { FilterConf interface{} `yaml:"filter_conf" json:"filter_conf,omitempty" property:"filter_conf" ` } +func (c *ProviderConfig) UnmarshalYAML(unmarshal func(interface{}) error) error { + if err := defaults.Set(c); err != nil { + return err + } + type plain ProviderConfig + if err := unmarshal((*plain)(c)); err != nil { + return err + } + return nil +} + func (*ProviderConfig) Prefix() string { return constant.ProviderConfigPrefix } diff --git a/config/provider_config_test.go b/config/provider_config_test.go new file mode 100644 index 0000000000..e3db222175 --- /dev/null +++ b/config/provider_config_test.go @@ -0,0 +1,19 @@ +package config + +import ( + "path/filepath" + "testing" +) + +import ( + "github.com/stretchr/testify/assert" +) + +func TestProviderInit(t *testing.T) { + conPath, err := filepath.Abs("./testdata/consumer_config_with_configcenter.yml") + assert.NoError(t, err) + assert.NoError(t, ConsumerInit(conPath)) + assert.Equal(t, "default", consumerConfig.ProxyFactory) + assert.Equal(t, "dubbo.properties", consumerConfig.ConfigCenterConfig.ConfigFile) + assert.Equal(t, "100ms", consumerConfig.Connect_Timeout) +} diff --git a/config/reference_config.go b/config/reference_config.go index b3a3bae447..4b063bc60b 100644 --- a/config/reference_config.go +++ b/config/reference_config.go @@ -25,6 +25,10 @@ import ( "time" ) +import ( + "github.com/creasty/defaults" +) + import ( "github.com/apache/dubbo-go/cluster/directory" "github.com/apache/dubbo-go/common" @@ -68,6 +72,7 @@ func NewReferenceConfig(id string, ctx context.Context) *ReferenceConfig { } func (refconfig *ReferenceConfig) UnmarshalYAML(unmarshal func(interface{}) error) error { + type rf ReferenceConfig raw := rf{} // Put your defaults here if err := unmarshal(&raw); err != nil { @@ -75,6 +80,10 @@ func (refconfig *ReferenceConfig) UnmarshalYAML(unmarshal func(interface{}) erro } *refconfig = ReferenceConfig(raw) + if err := defaults.Set(refconfig); err != nil { + return err + } + return nil } diff --git a/config/registry_config.go b/config/registry_config.go index 480377754a..9ffa41eb5b 100644 --- a/config/registry_config.go +++ b/config/registry_config.go @@ -24,6 +24,10 @@ import ( "strings" ) +import ( + "github.com/creasty/defaults" +) + import ( "github.com/apache/dubbo-go/common" "github.com/apache/dubbo-go/common/constant" @@ -42,6 +46,17 @@ type RegistryConfig struct { Params map[string]string `yaml:"params" json:"params,omitempty" property:"params"` } +func (c *RegistryConfig) UnmarshalYAML(unmarshal func(interface{}) error) error { + if err := defaults.Set(c); err != nil { + return err + } + type plain RegistryConfig + if err := unmarshal((*plain)(c)); err != nil { + return err + } + return nil +} + func (*RegistryConfig) Prefix() string { return constant.RegistryConfigPrefix + "|" + constant.SingleRegistryConfigPrefix } diff --git a/config/service_config.go b/config/service_config.go index 05cdc84f5b..85af4d048e 100644 --- a/config/service_config.go +++ b/config/service_config.go @@ -28,6 +28,7 @@ import ( ) import ( + "github.com/creasty/defaults" perrors "github.com/pkg/errors" "go.uber.org/atomic" ) @@ -67,6 +68,17 @@ func (c *ServiceConfig) Prefix() string { return constant.ServiceConfigPrefix + c.InterfaceName + "." } +func (c *ServiceConfig) UnmarshalYAML(unmarshal func(interface{}) error) error { + if err := defaults.Set(c); err != nil { + return err + } + type plain ServiceConfig + if err := unmarshal((*plain)(c)); err != nil { + return err + } + return nil +} + // The only way to get a new ServiceConfig func NewServiceConfig(id string, context context.Context) *ServiceConfig { diff --git a/go.mod b/go.mod index 37781aee51..fa66c6a647 100644 --- a/go.mod +++ b/go.mod @@ -11,6 +11,7 @@ require ( github.com/coreos/go-semver v0.3.0 // indirect github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f // indirect github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect + github.com/creasty/defaults v1.3.0 github.com/dubbogo/getty v1.2.2 github.com/dubbogo/gost v1.1.1 github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect diff --git a/go.sum b/go.sum index 24b4a7afb0..4add9fcf79 100644 --- a/go.sum +++ b/go.sum @@ -84,6 +84,8 @@ github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f h1:JOrtw2xFKzlg+ github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f h1:lBNOc5arjvs8E5mO2tbpBpLoyyu8B6e44T7hJy6potg= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= +github.com/creasty/defaults v1.3.0 h1:uG+RAxYbJgOPCOdKEcec9ZJXeva7Y6mj/8egdzwmLtw= +github.com/creasty/defaults v1.3.0/go.mod h1:CIEEvs7oIVZm30R8VxtFJs+4k201gReYyuYHJxZc68I= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= From 414b7ae47bc445879bd91a1409e8ea6c00cdfd0b Mon Sep 17 00:00:00 2001 From: "vito.he" Date: Thu, 12 Sep 2019 14:47:12 +0800 Subject: [PATCH 13/34] Add:reference & service protocol default --- config/provider_config_test.go | 16 +++- config/reference_config.go | 2 +- config/service_config.go | 2 +- .../consumer_config_withoutProtocol.yml | 77 +++++++++++++++++++ .../provider_config_withoutProtocol.yml | 76 ++++++++++++++++++ 5 files changed, 170 insertions(+), 3 deletions(-) create mode 100644 config/testdata/consumer_config_withoutProtocol.yml create mode 100644 config/testdata/provider_config_withoutProtocol.yml diff --git a/config/provider_config_test.go b/config/provider_config_test.go index e3db222175..db4b5f9906 100644 --- a/config/provider_config_test.go +++ b/config/provider_config_test.go @@ -9,7 +9,7 @@ import ( "github.com/stretchr/testify/assert" ) -func TestProviderInit(t *testing.T) { +func TestConsumerInit(t *testing.T) { conPath, err := filepath.Abs("./testdata/consumer_config_with_configcenter.yml") assert.NoError(t, err) assert.NoError(t, ConsumerInit(conPath)) @@ -17,3 +17,17 @@ func TestProviderInit(t *testing.T) { assert.Equal(t, "dubbo.properties", consumerConfig.ConfigCenterConfig.ConfigFile) assert.Equal(t, "100ms", consumerConfig.Connect_Timeout) } + +func TestConsumerInitWithDefaultProtocol(t *testing.T) { + conPath, err := filepath.Abs("./testdata/consumer_config_withoutProtocol.yml") + assert.NoError(t, err) + assert.NoError(t, ConsumerInit(conPath)) + assert.Equal(t, "dubbo", consumerConfig.References["UserProvider"].Protocol) +} + +func TestProviderInitWithDefaultProtocol(t *testing.T) { + conPath, err := filepath.Abs("./testdata/provider_config_withoutProtocol.yml") + assert.NoError(t, err) + assert.NoError(t, ProviderInit(conPath)) + assert.Equal(t, "dubbo", providerConfig.Services["UserProvider"].Protocol) +} diff --git a/config/reference_config.go b/config/reference_config.go index 4b063bc60b..fb854a14d5 100644 --- a/config/reference_config.go +++ b/config/reference_config.go @@ -47,7 +47,7 @@ type ReferenceConfig struct { Check *bool `yaml:"check" json:"check,omitempty" property:"check"` Url string `yaml:"url" json:"url,omitempty" property:"url"` Filter string `yaml:"filter" json:"filter,omitempty" property:"filter"` - Protocol string `yaml:"protocol" json:"protocol,omitempty" property:"protocol"` + Protocol string `default:"dubbo" yaml:"protocol" json:"protocol,omitempty" property:"protocol"` Registry string `yaml:"registry" json:"registry,omitempty" property:"registry"` Cluster string `yaml:"cluster" json:"cluster,omitempty" property:"cluster"` Loadbalance string `yaml:"loadbalance" json:"loadbalance,omitempty" property:"loadbalance"` diff --git a/config/service_config.go b/config/service_config.go index 85af4d048e..c41509917d 100644 --- a/config/service_config.go +++ b/config/service_config.go @@ -46,7 +46,7 @@ type ServiceConfig struct { context context.Context id string Filter string `yaml:"filter" json:"filter,omitempty" property:"filter"` - Protocol string `required:"true" yaml:"protocol" json:"protocol,omitempty" property:"protocol"` //multi protocol support, split by ',' + Protocol string `default:"dubbo" required:"true" yaml:"protocol" json:"protocol,omitempty" property:"protocol"` //multi protocol support, split by ',' InterfaceName string `required:"true" yaml:"interface" json:"interface,omitempty" property:"interface"` Registry string `yaml:"registry" json:"registry,omitempty" property:"registry"` Cluster string `default:"failover" yaml:"cluster" json:"cluster,omitempty" property:"cluster"` diff --git a/config/testdata/consumer_config_withoutProtocol.yml b/config/testdata/consumer_config_withoutProtocol.yml new file mode 100644 index 0000000000..a051afbf13 --- /dev/null +++ b/config/testdata/consumer_config_withoutProtocol.yml @@ -0,0 +1,77 @@ +# dubbo client yaml configure file + +filter: "" + +# client +request_timeout : "100ms" +# connect timeout +connect_timeout : "100ms" +check: true +# application config +application_config: + organization : "ikurento.com" + name : "BDTService" + module : "dubbogo user-info client" + version : "0.0.1" + owner : "ZX" + environment : "dev" + +registries : + + "hangzhouzk": + protocol: "zookeeper" + timeout : "3s" + address: "127.0.0.1:2181" + username: "" + password: "" + "shanghaizk": + protocol: "zookeeper" + timeout : "3s" + address: "127.0.0.1:2182" + username: "" + password: "" + +references: + "UserProvider": + registry: "hangzhouzk,shanghaizk" + filter: "" + version: "1.0" + group: "as" + interface : "com.ikurento.user.UserProvider" + url: "dubbo://127.0.0.1:20000/UserProvider" + cluster: "failover" + methods : + - name: "GetUser" + retries: 3 + params: + "serviceid": + "soa.com.ikurento.user.UserProvider" + "forks": 5 + +protocol_conf: + dubbo: + reconnect_interval: 0 + connection_number: 2 + heartbeat_period: "5s" + session_timeout: "20s" + pool_size: 64 + pool_ttl: 600 + # gr_pool_size is recommended to be set to [cpu core number] * 100 + gr_pool_size: 1200 + # queue_len is recommended to be set to 64 or 128 + queue_len: 64 + # queue_number is recommended to be set to gr_pool_size / 20 + queue_number: 60 + getty_session_param: + compress_encoding: false + tcp_no_delay: true + tcp_keep_alive: true + keep_alive_period: "120s" + tcp_r_buf_size: 262144 + tcp_w_buf_size: 65536 + pkg_wq_size: 512 + tcp_read_timeout: "1s" + tcp_write_timeout: "5s" + wait_timeout: "1s" + max_msg_len: 1024 + session_name: "client" diff --git a/config/testdata/provider_config_withoutProtocol.yml b/config/testdata/provider_config_withoutProtocol.yml new file mode 100644 index 0000000000..07349f8269 --- /dev/null +++ b/config/testdata/provider_config_withoutProtocol.yml @@ -0,0 +1,76 @@ +# dubbo server yaml configure file + +filter: "" +# application config +application_config: + organization : "ikurento.com" + name : "BDTService" + module : "dubbogo user-info server" + version : "0.0.1" + owner : "ZX" + environment : "dev" + +registries : + "hangzhouzk": + protocol: "zookeeper" + timeout : "3s" + address: "127.0.0.1:2181" + username: "" + password: "" + "shanghaizk": + protocol: "zookeeper" + timeout : "3s" + address: "127.0.0.1:2182" + username: "" + password: "" + + +services: + "UserProvider": + registry: "hangzhouzk,shanghaizk" + filter: "" + # equivalent to interface of dubbo.xml + interface : "com.ikurento.user.UserProvider" + loadbalance: "random" + version: "1.0" + group: "as" + warmup: "100" + cluster: "failover" + methods: + - name: "GetUser" + retries: 1 + loadbalance: "random" + +protocols: + "dubbo": + name: "dubbo" + # while using dubbo protocol, ip cannot is 127.0.0.1, because client of java-dubbo will get 'connection refuse' + ip : "127.0.0.1" + port : 20000 + #- name: "jsonrpc" + # ip: "127.0.0.1" + # port: 20001 + +protocol_conf: + dubbo: + session_number: 700 + session_timeout: "20s" + # gr_pool_size is recommended to be set to [cpu core number] * 10 + gr_pool_size: 120 + # queue_len is recommended to be set to 64 or 128 + queue_len: 64 + # queue_number is recommended to be set to gr_pool_size / 20 + queue_number: 6 + getty_session_param: + compress_encoding: false + tcp_no_delay: true + tcp_keep_alive: true + keep_alive_period: "120s" + tcp_r_buf_size: 262144 + tcp_w_buf_size: 65536 + pkg_wq_size: 512 + tcp_read_timeout: "1s" + tcp_write_timeout: "5s" + wait_timeout: "1s" + max_msg_len: 1024 + session_name: "server" From 1ee6882cec3f31771749076c5e8da70f524c1c5a Mon Sep 17 00:00:00 2001 From: "vito.he" Date: Thu, 12 Sep 2019 15:31:11 +0800 Subject: [PATCH 14/34] Mod:change application_config to application --- config/consumer_config.go | 2 +- config/provider_config.go | 2 +- config/testdata/consumer_config.yml | 2 +- .../consumer_config_withoutProtocol.yml | 2 +- config/testdata/provider_config.yml | 2 +- .../provider_config_withoutProtocol.yml | 2 +- .../with-configcenter-go-client/app/client.go | 152 ------------- .../with-configcenter-go-client/app/user.go | 113 ---------- .../app/version.go | 22 -- .../assembly/bin/load.sh | 203 ------------------ .../assembly/common/app.properties | 23 -- .../assembly/common/build.sh | 83 ------- .../assembly/linux/dev.sh | 36 ---- .../assembly/linux/release.sh | 35 --- .../assembly/linux/test.sh | 35 --- .../assembly/mac/dev.sh | 36 ---- .../assembly/mac/release.sh | 34 --- .../assembly/mac/test.sh | 34 --- .../assembly/windows/dev.sh | 34 --- .../assembly/windows/release.sh | 34 --- .../assembly/windows/test.sh | 34 --- .../profiles/dev/client.yml | 38 ---- .../profiles/dev/log.yml | 28 --- .../profiles/release/client.yml | 38 ---- .../profiles/release/log.yml | 28 --- .../profiles/test/client.yml | 38 ---- .../profiles/test/log.yml | 28 --- .../with-configcenter-go-server/app/server.go | 86 -------- .../with-configcenter-go-server/app/user.go | 192 ----------------- .../app/version.go | 22 -- .../assembly/bin/load.sh | 151 ------------- .../assembly/common/app.properties | 23 -- .../assembly/common/build.sh | 80 ------- .../assembly/linux/dev.sh | 36 ---- .../assembly/linux/release.sh | 36 ---- .../assembly/linux/test.sh | 36 ---- .../assembly/mac/dev.sh | 36 ---- .../assembly/mac/release.sh | 36 ---- .../assembly/mac/test.sh | 36 ---- .../assembly/windows/dev.sh | 36 ---- .../assembly/windows/release.sh | 36 ---- .../assembly/windows/test.sh | 36 ---- .../profiles/dev/log.yml | 28 --- .../profiles/dev/server.yml | 39 ---- .../profiles/release/log.yml | 28 --- .../profiles/release/server.yml | 39 ---- .../profiles/test/log.yml | 28 --- .../profiles/test/server.yml | 39 ---- .../with-configcenter-go-client/app/client.go | 137 ------------ .../with-configcenter-go-client/app/user.go | 63 ------ .../app/version.go | 22 -- .../assembly/bin/load.sh | 203 ------------------ .../assembly/common/app.properties | 23 -- .../assembly/common/build.sh | 83 ------- .../assembly/linux/dev.sh | 36 ---- .../assembly/linux/release.sh | 35 --- .../assembly/linux/test.sh | 35 --- .../assembly/mac/dev.sh | 36 ---- .../assembly/mac/release.sh | 34 --- .../assembly/mac/test.sh | 34 --- .../assembly/windows/dev.sh | 34 --- .../assembly/windows/release.sh | 34 --- .../assembly/windows/test.sh | 34 --- .../profiles/dev/client.yml | 16 -- .../profiles/dev/log.yml | 28 --- .../profiles/release/client.yml | 16 -- .../profiles/release/log.yml | 28 --- .../profiles/test/client.yml | 16 -- .../profiles/test/log.yml | 28 --- .../with-configcenter-go-server/app/server.go | 75 ------- .../with-configcenter-go-server/app/user.go | 155 ------------- .../app/version.go | 22 -- .../assembly/bin/load.sh | 151 ------------- .../assembly/common/app.properties | 23 -- .../assembly/common/build.sh | 80 ------- .../assembly/linux/dev.sh | 36 ---- .../assembly/linux/release.sh | 36 ---- .../assembly/linux/test.sh | 36 ---- .../assembly/mac/dev.sh | 36 ---- .../assembly/mac/release.sh | 36 ---- .../assembly/mac/test.sh | 36 ---- .../assembly/windows/dev.sh | 36 ---- .../assembly/windows/release.sh | 36 ---- .../assembly/windows/test.sh | 36 ---- .../profiles/dev/log.yml | 28 --- .../profiles/dev/server.yml | 22 -- .../profiles/release/log.yml | 28 --- .../profiles/release/server.yml | 25 --- .../profiles/test/log.yml | 28 --- .../profiles/test/server.yml | 25 --- examples/consul/go-client/config/client.yml | 2 +- examples/consul/go-server/config/server.yml | 2 +- .../dubbo/go-client/profiles/dev/client.yml | 2 +- .../go-client/profiles/release/client.yml | 83 ------- .../dubbo/go-client/profiles/release/log.yml | 28 --- .../dubbo/go-client/profiles/test/client.yml | 83 ------- .../dubbo/go-client/profiles/test/log.yml | 28 --- .../dubbo/go-server/profiles/dev/server.yml | 2 +- .../dubbo/go-server/profiles/release/log.yml | 28 --- .../go-server/profiles/release/server.yml | 91 -------- .../dubbo/go-server/profiles/test/log.yml | 28 --- .../dubbo/go-server/profiles/test/server.yml | 91 -------- .../jsonrpc/go-client/profiles/dev/client.yml | 2 +- .../go-client/profiles/release/client.yml | 60 ------ .../go-client/profiles/release/log.yml | 28 --- .../go-client/profiles/test/client.yml | 60 ------ .../jsonrpc/go-client/profiles/test/log.yml | 28 --- .../jsonrpc/go-server/profiles/dev/server.yml | 2 +- .../go-server/profiles/release/log.yml | 28 --- .../go-server/profiles/release/server.yml | 75 ------- .../jsonrpc/go-server/profiles/test/log.yml | 28 --- .../go-server/profiles/test/server.yml | 75 ------- .../generic/go-client/profiles/dev/client.yml | 2 +- .../go-client/profiles/release/client.yml | 55 ----- .../go-client/profiles/release/log.yml | 28 --- .../go-client/profiles/test/client.yml | 55 ----- .../generic/go-client/profiles/test/log.yml | 28 --- .../dubbo/go-client/profiles/dev/client.yml | 2 +- .../go-client/profiles/release/client.yml | 60 ------ .../dubbo/go-client/profiles/release/log.yml | 28 --- .../dubbo/go-client/profiles/test/client.yml | 59 ----- .../dubbo/go-client/profiles/test/log.yml | 28 --- .../dubbo/go-server/profiles/dev/server.yml | 2 +- .../dubbo/go-server/profiles/release/log.yml | 28 --- .../go-server/profiles/release/server.yml | 62 ------ .../dubbo/go-server/profiles/test/log.yml | 28 --- .../dubbo/go-server/profiles/test/server.yml | 62 ------ .../profiles/dev/client.yml | 2 +- .../profiles/release/client.yml | 98 --------- .../profiles/release/log.yml | 28 --- .../profiles/test/client.yml | 99 --------- .../profiles/test/log.yml | 28 --- .../dubbo.client.properties | 15 -- .../dubbo.properties | 15 -- 134 files changed, 16 insertions(+), 5808 deletions(-) delete mode 100644 examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/app/client.go delete mode 100644 examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/app/user.go delete mode 100644 examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/app/version.go delete mode 100644 examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/bin/load.sh delete mode 100644 examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/common/app.properties delete mode 100644 examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/common/build.sh delete mode 100644 examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/linux/dev.sh delete mode 100644 examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/linux/release.sh delete mode 100644 examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/linux/test.sh delete mode 100644 examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/mac/dev.sh delete mode 100644 examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/mac/release.sh delete mode 100644 examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/mac/test.sh delete mode 100644 examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/windows/dev.sh delete mode 100644 examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/windows/release.sh delete mode 100644 examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/windows/test.sh delete mode 100644 examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/profiles/dev/client.yml delete mode 100644 examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/profiles/dev/log.yml delete mode 100644 examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/profiles/release/client.yml delete mode 100644 examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/profiles/release/log.yml delete mode 100644 examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/profiles/test/client.yml delete mode 100644 examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/profiles/test/log.yml delete mode 100644 examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/app/server.go delete mode 100644 examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/app/user.go delete mode 100644 examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/app/version.go delete mode 100644 examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/bin/load.sh delete mode 100644 examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/common/app.properties delete mode 100644 examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/common/build.sh delete mode 100644 examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/linux/dev.sh delete mode 100644 examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/linux/release.sh delete mode 100644 examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/linux/test.sh delete mode 100644 examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/mac/dev.sh delete mode 100644 examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/mac/release.sh delete mode 100644 examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/mac/test.sh delete mode 100644 examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/windows/dev.sh delete mode 100644 examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/windows/release.sh delete mode 100644 examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/windows/test.sh delete mode 100644 examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/profiles/dev/log.yml delete mode 100644 examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/profiles/dev/server.yml delete mode 100644 examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/profiles/release/log.yml delete mode 100644 examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/profiles/release/server.yml delete mode 100644 examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/profiles/test/log.yml delete mode 100644 examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/profiles/test/server.yml delete mode 100644 examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/app/client.go delete mode 100644 examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/app/user.go delete mode 100644 examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/app/version.go delete mode 100644 examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/bin/load.sh delete mode 100644 examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/common/app.properties delete mode 100644 examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/common/build.sh delete mode 100644 examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/linux/dev.sh delete mode 100644 examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/linux/release.sh delete mode 100644 examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/linux/test.sh delete mode 100644 examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/mac/dev.sh delete mode 100644 examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/mac/release.sh delete mode 100644 examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/mac/test.sh delete mode 100644 examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/windows/dev.sh delete mode 100644 examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/windows/release.sh delete mode 100644 examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/windows/test.sh delete mode 100644 examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/profiles/dev/client.yml delete mode 100644 examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/profiles/dev/log.yml delete mode 100644 examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/profiles/release/client.yml delete mode 100644 examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/profiles/release/log.yml delete mode 100644 examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/profiles/test/client.yml delete mode 100644 examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/profiles/test/log.yml delete mode 100644 examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/app/server.go delete mode 100644 examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/app/user.go delete mode 100644 examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/app/version.go delete mode 100644 examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/bin/load.sh delete mode 100644 examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/common/app.properties delete mode 100644 examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/common/build.sh delete mode 100644 examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/linux/dev.sh delete mode 100644 examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/linux/release.sh delete mode 100644 examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/linux/test.sh delete mode 100644 examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/mac/dev.sh delete mode 100644 examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/mac/release.sh delete mode 100644 examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/mac/test.sh delete mode 100644 examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/windows/dev.sh delete mode 100644 examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/windows/release.sh delete mode 100644 examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/windows/test.sh delete mode 100644 examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/profiles/dev/log.yml delete mode 100644 examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/profiles/dev/server.yml delete mode 100644 examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/profiles/release/log.yml delete mode 100644 examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/profiles/release/server.yml delete mode 100644 examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/profiles/test/log.yml delete mode 100644 examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/profiles/test/server.yml delete mode 100644 examples/general/dubbo/go-client/profiles/release/client.yml delete mode 100644 examples/general/dubbo/go-client/profiles/release/log.yml delete mode 100644 examples/general/dubbo/go-client/profiles/test/client.yml delete mode 100644 examples/general/dubbo/go-client/profiles/test/log.yml delete mode 100644 examples/general/dubbo/go-server/profiles/release/log.yml delete mode 100644 examples/general/dubbo/go-server/profiles/release/server.yml delete mode 100644 examples/general/dubbo/go-server/profiles/test/log.yml delete mode 100644 examples/general/dubbo/go-server/profiles/test/server.yml delete mode 100644 examples/general/jsonrpc/go-client/profiles/release/client.yml delete mode 100644 examples/general/jsonrpc/go-client/profiles/release/log.yml delete mode 100644 examples/general/jsonrpc/go-client/profiles/test/client.yml delete mode 100644 examples/general/jsonrpc/go-client/profiles/test/log.yml delete mode 100644 examples/general/jsonrpc/go-server/profiles/release/log.yml delete mode 100644 examples/general/jsonrpc/go-server/profiles/release/server.yml delete mode 100644 examples/general/jsonrpc/go-server/profiles/test/log.yml delete mode 100644 examples/general/jsonrpc/go-server/profiles/test/server.yml delete mode 100644 examples/generic/go-client/profiles/release/client.yml delete mode 100644 examples/generic/go-client/profiles/release/log.yml delete mode 100644 examples/generic/go-client/profiles/test/client.yml delete mode 100644 examples/generic/go-client/profiles/test/log.yml delete mode 100644 examples/helloworld/dubbo/go-client/profiles/release/client.yml delete mode 100644 examples/helloworld/dubbo/go-client/profiles/release/log.yml delete mode 100644 examples/helloworld/dubbo/go-client/profiles/test/client.yml delete mode 100644 examples/helloworld/dubbo/go-client/profiles/test/log.yml delete mode 100644 examples/helloworld/dubbo/go-server/profiles/release/log.yml delete mode 100644 examples/helloworld/dubbo/go-server/profiles/release/server.yml delete mode 100644 examples/helloworld/dubbo/go-server/profiles/test/log.yml delete mode 100644 examples/helloworld/dubbo/go-server/profiles/test/server.yml delete mode 100644 examples/hystrixfilter/dubbo/with-hystrix-go-client/profiles/release/client.yml delete mode 100644 examples/hystrixfilter/dubbo/with-hystrix-go-client/profiles/release/log.yml delete mode 100644 examples/hystrixfilter/dubbo/with-hystrix-go-client/profiles/test/client.yml delete mode 100644 examples/hystrixfilter/dubbo/with-hystrix-go-client/profiles/test/log.yml delete mode 100644 examples/jsonrpc/with-configcenter-go-client/dubbo.client.properties delete mode 100644 examples/jsonrpc/with-configcenter-go-server/dubbo.properties diff --git a/config/consumer_config.go b/config/consumer_config.go index 9a9f734c4e..b1ebdd5d8e 100644 --- a/config/consumer_config.go +++ b/config/consumer_config.go @@ -42,7 +42,7 @@ type ConsumerConfig struct { BaseConfig `yaml:",inline"` Filter string `yaml:"filter" json:"filter,omitempty" property:"filter"` // application - ApplicationConfig *ApplicationConfig `yaml:"application_config" json:"application_config,omitempty" property:"application_config"` + ApplicationConfig *ApplicationConfig `yaml:"application" json:"application,omitempty" property:"application"` // client Connect_Timeout string `default:"100ms" yaml:"connect_timeout" json:"connect_timeout,omitempty" property:"connect_timeout"` ConnectTimeout time.Duration diff --git a/config/provider_config.go b/config/provider_config.go index 2302cdf0b2..00faa1d0ab 100644 --- a/config/provider_config.go +++ b/config/provider_config.go @@ -42,7 +42,7 @@ type ProviderConfig struct { Filter string `yaml:"filter" json:"filter,omitempty" property:"filter"` ProxyFactory string `yaml:"proxy_factory" default:"default" json:"proxy_factory,omitempty" property:"proxy_factory"` - ApplicationConfig *ApplicationConfig `yaml:"application_config" json:"application_config,omitempty" property:"application_config"` + ApplicationConfig *ApplicationConfig `yaml:"application" json:"application,omitempty" property:"application"` Registry *RegistryConfig `yaml:"registry" json:"registry,omitempty" property:"registry"` Registries map[string]*RegistryConfig `yaml:"registries" json:"registries,omitempty" property:"registries"` Services map[string]*ServiceConfig `yaml:"services" json:"services,omitempty" property:"services"` diff --git a/config/testdata/consumer_config.yml b/config/testdata/consumer_config.yml index 372873abbb..a13ad86faa 100644 --- a/config/testdata/consumer_config.yml +++ b/config/testdata/consumer_config.yml @@ -8,7 +8,7 @@ request_timeout : "100ms" connect_timeout : "100ms" check: true # application config -application_config: +application: organization : "ikurento.com" name : "BDTService" module : "dubbogo user-info client" diff --git a/config/testdata/consumer_config_withoutProtocol.yml b/config/testdata/consumer_config_withoutProtocol.yml index a051afbf13..e4393063ea 100644 --- a/config/testdata/consumer_config_withoutProtocol.yml +++ b/config/testdata/consumer_config_withoutProtocol.yml @@ -8,7 +8,7 @@ request_timeout : "100ms" connect_timeout : "100ms" check: true # application config -application_config: +application: organization : "ikurento.com" name : "BDTService" module : "dubbogo user-info client" diff --git a/config/testdata/provider_config.yml b/config/testdata/provider_config.yml index e135860c20..5cbefe0811 100644 --- a/config/testdata/provider_config.yml +++ b/config/testdata/provider_config.yml @@ -2,7 +2,7 @@ filter: "" # application config -application_config: +application: organization : "ikurento.com" name : "BDTService" module : "dubbogo user-info server" diff --git a/config/testdata/provider_config_withoutProtocol.yml b/config/testdata/provider_config_withoutProtocol.yml index 07349f8269..9aa36d4677 100644 --- a/config/testdata/provider_config_withoutProtocol.yml +++ b/config/testdata/provider_config_withoutProtocol.yml @@ -2,7 +2,7 @@ filter: "" # application config -application_config: +application: organization : "ikurento.com" name : "BDTService" module : "dubbogo user-info server" diff --git a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/app/client.go b/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/app/client.go deleted file mode 100644 index 44ffbd98f6..0000000000 --- a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/app/client.go +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 ( - "context" - "fmt" - "os" - "os/signal" - "syscall" - "time" -) - -import ( - hessian "github.com/apache/dubbo-go-hessian2" -) - -import ( - "github.com/apache/dubbo-go/common/logger" - _ "github.com/apache/dubbo-go/common/proxy/proxy_factory" - "github.com/apache/dubbo-go/config" - _ "github.com/apache/dubbo-go/protocol/dubbo" - _ "github.com/apache/dubbo-go/registry/protocol" - - _ "github.com/apache/dubbo-go/filter/impl" - - _ "github.com/apache/dubbo-go/cluster/cluster_impl" - _ "github.com/apache/dubbo-go/cluster/loadbalance" - _ "github.com/apache/dubbo-go/config_center/zookeeper" - _ "github.com/apache/dubbo-go/registry/zookeeper" -) - -var ( - survivalTimeout int = 10e9 -) - -// they are necessary: -// export CONF_CONSUMER_FILE_PATH="xxx" -// export APP_LOG_CONF_FILE="xxx" -func main() { - - hessian.RegisterJavaEnum(Gender(MAN)) - hessian.RegisterJavaEnum(Gender(WOMAN)) - hessian.RegisterPOJO(&User{}) - - config.Load() - - println("\n\n\necho") - res, err := userProvider.Echo(context.TODO(), "OK") - if err != nil { - panic(err) - } - println("res: %v\n", res) - - time.Sleep(3e9) - - println("\n\n\nstart to test dubbo") - user := &User{} - err = userProvider.GetUser(context.TODO(), []interface{}{"A003"}, user) - if err != nil { - panic(err) - } - println("response result: %v", user) - - println("\n\n\nstart to test dubbo - GetUser0") - ret, err := userProvider.GetUser0("A003", "Moorse") - if err != nil { - panic(err) - } - println("response result: %v", ret) - - println("\n\n\nstart to test dubbo - GetUsers") - ret1, err := userProvider.GetUsers([]interface{}{[]interface{}{"A002", "A003"}}) - if err != nil { - panic(err) - } - println("response result: %v", ret1) - - println("\n\n\nstart to test dubbo - getUser") - user = &User{} - var i int32 = 1 - err = userProvider.GetUser2(context.TODO(), []interface{}{i}, user) - if err != nil { - panic(err) - } - println("response result: %v", user) - - println("\n\n\nstart to test dubbo - GetUser3") - err = userProvider.GetUser3() - if err != nil { - panic(err) - } - println("succ!") - - println("\n\n\nstart to test dubbo - getErr") - user = &User{} - err = userProvider.GetErr(context.TODO(), []interface{}{"A003"}, user) - if err != nil { - println("getErr - error: %v", err) - } - - println("\n\n\nstart to test dubbo illegal method") - err = userProvider.GetUser1(context.TODO(), []interface{}{"A003"}, user) - if err != nil { - panic(err) - } - - initSignal() -} - -func initSignal() { - signals := make(chan os.Signal, 1) - // It is not possible to block SIGKILL or syscall.SIGSTOP - signal.Notify(signals, os.Interrupt, os.Kill, syscall.SIGHUP, - syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT) - for { - sig := <-signals - logger.Infof("get signal %s", sig.String()) - switch sig { - case syscall.SIGHUP: - // reload() - default: - time.AfterFunc(time.Duration(survivalTimeout)*time.Second, func() { - logger.Warnf("app exit now by force...") - os.Exit(1) - }) - - // The program exits normally or timeout forcibly exits. - fmt.Println("app exit now...") - return - } - } -} - -func println(format string, args ...interface{}) { - fmt.Printf("\033[32;40m"+format+"\033[0m\n", args...) -} diff --git a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/app/user.go b/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/app/user.go deleted file mode 100644 index 5bddf1e19f..0000000000 --- a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/app/user.go +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 ( - "context" - "fmt" - "strconv" - "time" -) - -import ( - hessian "github.com/apache/dubbo-go-hessian2" -) - -import ( - "github.com/apache/dubbo-go/config" -) - -type Gender hessian.JavaEnum - -var userProvider = new(UserProvider) - -func init() { - config.SetConsumerService(userProvider) -} - -const ( - MAN hessian.JavaEnum = iota - WOMAN -) - -var genderName = map[hessian.JavaEnum]string{ - MAN: "MAN", - WOMAN: "WOMAN", -} - -var genderValue = map[string]hessian.JavaEnum{ - "MAN": MAN, - "WOMAN": WOMAN, -} - -func (g Gender) JavaClassName() string { - return "com.ikurento.user.Gender" -} - -func (g Gender) String() string { - s, ok := genderName[hessian.JavaEnum(g)] - if ok { - return s - } - - return strconv.Itoa(int(g)) -} - -func (g Gender) EnumValue(s string) hessian.JavaEnum { - v, ok := genderValue[s] - if ok { - return v - } - - return hessian.InvalidJavaEnum -} - -type User struct { - // !!! Cannot define lowercase names of variable - Id string - Name string - Age int32 - Time time.Time - Sex Gender // notice: java enum Object <--> go string -} - -func (u User) String() string { - return fmt.Sprintf( - "User{Id:%s, Name:%s, Age:%d, Time:%s, Sex:%s}", - u.Id, u.Name, u.Age, u.Time, u.Sex, - ) -} - -func (User) JavaClassName() string { - return "com.ikurento.user.User" -} - -type UserProvider struct { - GetUsers func(req []interface{}) ([]interface{}, error) - GetErr func(ctx context.Context, req []interface{}, rsp *User) error - GetUser func(ctx context.Context, req []interface{}, rsp *User) error - GetUser0 func(id string, name string) (User, error) - GetUser1 func(ctx context.Context, req []interface{}, rsp *User) error - GetUser2 func(ctx context.Context, req []interface{}, rsp *User) error `dubbo:"getUser"` - GetUser3 func() error - Echo func(ctx context.Context, req interface{}) (interface{}, error) // Echo represent EchoFilter will be used -} - -func (u *UserProvider) Reference() string { - return "UserProvider" -} diff --git a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/app/version.go b/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/app/version.go deleted file mode 100644 index c6138584f1..0000000000 --- a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/app/version.go +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 - -var ( - Version = "2.6.0" -) diff --git a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/bin/load.sh b/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/bin/load.sh deleted file mode 100644 index ffa240b29d..0000000000 --- a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/bin/load.sh +++ /dev/null @@ -1,203 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - -APP_NAME="APPLICATION_NAME" -APP_ARGS="" -SLEEP_INTERVAL=5 -MAX_LIFETIME=4000 - -PROJECT_HOME="" -OS_NAME=`uname` -if [[ ${OS_NAME} != "Windows" ]]; then - PROJECT_HOME=`pwd` - PROJECT_HOME=${PROJECT_HOME}"/" -else - APP_NAME="APPLICATION_NAME.exe" -fi - -export CONF_CONSUMER_FILE_PATH=${PROJECT_HOME}"TARGET_CONF_FILE" -export APP_LOG_CONF_FILE=${PROJECT_HOME}"TARGET_LOG_CONF_FILE" -# export GOTRACEBACK=system -# export GODEBUG=gctrace=1 - -usage() { - echo "Usage: $0 start [conf suffix]" - echo " $0 stop" - echo " $0 term" - echo " $0 restart" - echo " $0 list" - echo " $0 monitor" - echo " $0 crontab" - exit -} - -start() { - arg=$1 - if [ "$arg" = "" ];then - echo "No registry type! Default client.yml!" - else - export CONF_CONSUMER_FILE_PATH=${CONF_CONSUMER_FILE_PATH//\.yml/\_$arg\.yml} - fi - if [ ! -f "${CONF_CONSUMER_FILE_PATH}" ];then - echo $CONF_CONSUMER_FILE_PATH" is not existing!" - return - fi - APP_LOG_PATH=${PROJECT_HOME}"logs/" - mkdir -p ${APP_LOG_PATH} - APP_BIN=${PROJECT_HOME}sbin/${APP_NAME} - chmod u+x ${APP_BIN} - # CMD="nohup ${APP_BIN} ${APP_ARGS} >>${APP_NAME}.nohup.out 2>&1 &" - CMD="${APP_BIN}" - eval ${CMD} - PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $2}'` - if [[ ${OS_NAME} != "Linux" && ${OS_NAME} != "Darwin" ]]; then - PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $1}'` - fi - CUR=`date +%FT%T` - if [ "${PID}" != "" ]; then - for p in ${PID} - do - echo "start ${APP_NAME} ( pid =" ${p} ") at " ${CUR} - done - fi -} - -stop() { - PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $2}'` - if [[ ${OS_NAME} != "Linux" && ${OS_NAME} != "Darwin" ]]; then - PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $1}'` - fi - if [ "${PID}" != "" ]; - then - for ps in ${PID} - do - echo "kill -SIGINT ${APP_NAME} ( pid =" ${ps} ")" - kill -2 ${ps} - done - fi -} - - -term() { - PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $2}'` - if [[ ${OS_NAME} != "Linux" && ${OS_NAME} != "Darwin" ]]; then - PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $1}'` - fi - if [ "${PID}" != "" ]; - then - for ps in ${PID} - do - echo "kill -9 ${APP_NAME} ( pid =" ${ps} ")" - kill -9 ${ps} - done - fi -} - -list() { - PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{printf("%s,%s,%s,%s\n", $1, $2, $9, $10)}'` - if [[ ${OS_NAME} != "Linux" && ${OS_NAME} != "Darwin" ]]; then - PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{printf("%s,%s,%s,%s,%s\n", $1, $4, $6, $7, $8)}'` - fi - - if [ "${PID}" != "" ]; then - echo "list ${APP_NAME}" - - if [[ ${OS_NAME} == "Linux" || ${OS_NAME} == "Darwin" ]]; then - echo "index: user, pid, start, duration" - else - echo "index: PID, WINPID, UID, STIME, COMMAND" - fi - idx=0 - for ps in ${PID} - do - echo "${idx}: ${ps}" - ((idx ++)) - done - fi -} - -monitor() { - idx=0 - while true; do - PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $2}'` - if [[ ${OS_NAME} != "Linux" && ${OS_NAME} != "Darwin" ]]; then - PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $1}'` - fi - if [[ "${PID}" == "" ]]; then - start - idx=0 - fi - - ((LIFE=idx*${SLEEP_INTERVAL})) - echo "${APP_NAME} ( pid = " ${PID} ") has been working in normal state for " $LIFE " seconds." - ((idx ++)) - sleep ${SLEEP_INTERVAL} - done -} - -crontab() { - idx=0 - while true; do - PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $2}'` - if [[ ${OS_NAME} != "Linux" && ${OS_NAME} != "Darwin" ]]; then - PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $1}'` - fi - if [[ "${PID}" == "" ]]; then - start - idx=0 - fi - - ((LIFE=idx*${SLEEP_INTERVAL})) - echo "${APP_NAME} ( pid = " ${PID} ") has been working in normal state for " $LIFE " seconds." - ((idx ++)) - sleep ${SLEEP_INTERVAL} - if [[ ${LIFE} -gt ${MAX_LIFETIME} ]]; then - kill -9 ${PID} - fi - done -} - -opt=$1 -case C"$opt" in - Cstart) - start $2 - ;; - Cstop) - stop - ;; - Cterm) - term - ;; - Crestart) - term - start $2 - ;; - Clist) - list - ;; - Cmonitor) - monitor - ;; - Ccrontab) - crontab - ;; - C*) - usage - ;; -esac - diff --git a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/common/app.properties b/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/common/app.properties deleted file mode 100644 index e10868f4d2..0000000000 --- a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/common/app.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - -export TARGET_EXEC_NAME="user_info_client" -# BUILD_PACKAGE="dubbogo-examples/user-info/client/app" -export BUILD_PACKAGE="app" - -export TARGET_CONF_FILE="conf/client.yml" -export TARGET_LOG_CONF_FILE="conf/log.yml" diff --git a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/common/build.sh b/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/common/build.sh deleted file mode 100644 index c9a9e87c73..0000000000 --- a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/common/build.sh +++ /dev/null @@ -1,83 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - -rm -rf target/ - -PROJECT_HOME=`pwd` -TARGET_FOLDER=${PROJECT_HOME}/target/${GOOS} - -TARGET_SBIN_NAME=${TARGET_EXEC_NAME} -version=`cat app/version.go | grep Version | grep -v "Apache" | awk -F '=' '{print $2}' | awk -F '"' '{print $2}'` -if [[ ${GOOS} == "windows" ]]; then - TARGET_SBIN_NAME=${TARGET_SBIN_NAME}.exe -fi -TARGET_NAME=${TARGET_FOLDER}/${TARGET_SBIN_NAME} -if [[ $PROFILE == "dev" || $PROFILE == "test" ]]; then - # GFLAGS=-gcflags "-N -l" -race -x -v # -x会把go build的详细过程输出 - # GFLAGS=-gcflags "-N -l" -race -v - # GFLAGS="-gcflags \"-N -l\" -v" - cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -i -o ${TARGET_NAME} && cd - -else - # -s去掉符号表(然后panic时候的stack trace就没有任何文件名/行号信息了,这个等价于普通C/C++程序被strip的效果), - # -w去掉DWARF调试信息,得到的程序就不能用gdb调试了。-s和-w也可以分开使用,一般来说如果不打算用gdb调试, - # -w基本没啥损失。-s的损失就有点大了。 - cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -i -o ${TARGET_NAME} && cd - -fi - -TAR_NAME=${TARGET_EXEC_NAME}-${version}-`date "+%Y%m%d-%H%M"`-${PROFILE} - -mkdir -p ${TARGET_FOLDER}/${TAR_NAME} - -SBIN_DIR=${TARGET_FOLDER}/${TAR_NAME}/sbin -BIN_DIR=${TARGET_FOLDER}/${TAR_NAME} -CONF_DIR=${TARGET_FOLDER}/${TAR_NAME}/conf - -mkdir -p ${SBIN_DIR} -mkdir -p ${CONF_DIR} - -mv ${TARGET_NAME} ${SBIN_DIR} -cp -r assembly/bin ${BIN_DIR} -cd ${BIN_DIR}/bin/ && mv load.sh load_${TARGET_EXEC_NAME}.sh && cd - - -platform=$(uname) -# modify APPLICATION_NAME -if [ ${platform} == "Darwin" ]; then - sed -i "" "s~APPLICATION_NAME~${TARGET_EXEC_NAME}~g" ${BIN_DIR}/bin/* -else - sed -i "s~APPLICATION_NAME~${TARGET_EXEC_NAME}~g" ${BIN_DIR}/bin/* -fi - -# modify TARGET_CONF_FILE -if [ ${platform} == "Darwin" ]; then - sed -i "" "s~TARGET_CONF_FILE~${TARGET_CONF_FILE}~g" ${BIN_DIR}/bin/* -else - sed -i "s~TARGET_CONF_FILE~${TARGET_CONF_FILE}~g" ${BIN_DIR}/bin/* -fi - -# modify TARGET_LOG_CONF_FILE -if [ ${platform} == "Darwin" ]; then - sed -i "" "s~TARGET_LOG_CONF_FILE~${TARGET_LOG_CONF_FILE}~g" ${BIN_DIR}/bin/* -else - sed -i "s~TARGET_LOG_CONF_FILE~${TARGET_LOG_CONF_FILE}~g" ${BIN_DIR}/bin/* -fi - -cp -r profiles/${PROFILE}/* ${CONF_DIR} - -cd ${TARGET_FOLDER} - -tar czf ${TAR_NAME}.tar.gz ${TAR_NAME}/* - diff --git a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/linux/dev.sh b/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/linux/dev.sh deleted file mode 100644 index eada737c8d..0000000000 --- a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/linux/dev.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - - -set -e - -export GOOS=linux -export GOARCH=amd64 - -export PROFILE="dev" - -PROJECT_HOME=`pwd` - -if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then - . ${PROJECT_HOME}/assembly/common/app.properties -fi - - -if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then - sh ${PROJECT_HOME}/assembly/common/build.sh -fi diff --git a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/linux/release.sh b/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/linux/release.sh deleted file mode 100644 index 10eb3d73f8..0000000000 --- a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/linux/release.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - - -set -e - -export GOOS=linux -export GOARCH=amd64 - -export PROFILE="release" -export PROJECT_HOME=`pwd` - -if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then - . ${PROJECT_HOME}/assembly/common/app.properties -fi - - -if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then - sh ${PROJECT_HOME}/assembly/common/build.sh -fi diff --git a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/linux/test.sh b/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/linux/test.sh deleted file mode 100644 index 78b650c0d4..0000000000 --- a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/linux/test.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - - -set -e - -export GOOS=linux -export GOARCH=amd64 - -export PROFILE="test" -export PROJECT_HOME=`pwd` - -if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then - . ${PROJECT_HOME}/assembly/common/app.properties -fi - - -if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then - sh ${PROJECT_HOME}/assembly/common/build.sh -fi diff --git a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/mac/dev.sh b/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/mac/dev.sh deleted file mode 100644 index c828476990..0000000000 --- a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/mac/dev.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - - -set -e - -export GOOS=darwin -export GOARCH=amd64 - -export PROFILE="dev" - -export PROJECT_HOME=`pwd` - -if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then - . ${PROJECT_HOME}/assembly/common/app.properties -fi - - -if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then - sh ${PROJECT_HOME}/assembly/common/build.sh -fi diff --git a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/mac/release.sh b/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/mac/release.sh deleted file mode 100644 index 91c2dfee79..0000000000 --- a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/mac/release.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - - -set -e - -export GOOS=darwin -export GOARCH=amd64 - -export PROFILE="release" -export PROJECT_HOME=`pwd` - -if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then - . ${PROJECT_HOME}/assembly/common/app.properties -fi - -if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then - sh ${PROJECT_HOME}/assembly/common/build.sh -fi diff --git a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/mac/test.sh b/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/mac/test.sh deleted file mode 100644 index a7853f5e2d..0000000000 --- a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/mac/test.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - -set -e - -export GOOS=darwin -export GOARCH=amd64 - -export PROFILE="test" -export PROJECT_HOME=`pwd` - -if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then - . ${PROJECT_HOME}/assembly/common/app.properties -fi - - -if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then - sh ${PROJECT_HOME}/assembly/common/build.sh -fi diff --git a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/windows/dev.sh b/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/windows/dev.sh deleted file mode 100644 index 10a3866c0f..0000000000 --- a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/windows/dev.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - - -set -e - -export GOOS=linux -export GOARCH=amd64 - -export PROFILE="dev" -PROJECT_HOME=`pwd` - -if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then - . ${PROJECT_HOME}/assembly/common/app.properties -fi - -if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then - sh ${PROJECT_HOME}/assembly/common/build.sh -fi diff --git a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/windows/release.sh b/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/windows/release.sh deleted file mode 100644 index 21af573fa3..0000000000 --- a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/windows/release.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - - -set -e - -export GOOS=windows -export GOARCH=amd64 - -export PROFILE="release" -export PROJECT_HOME=`pwd` - -if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then - . ${PROJECT_HOME}/assembly/common/app.properties -fi - -if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then - sh ${PROJECT_HOME}/assembly/common/build.sh -fi diff --git a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/windows/test.sh b/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/windows/test.sh deleted file mode 100644 index 2104da8b59..0000000000 --- a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/assembly/windows/test.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - - -set -e - -export GOOS=windows -export GOARCH=amd64 - -export PROFILE="test" -export PROJECT_HOME=`pwd` - -if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then - . ${PROJECT_HOME}/assembly/common/app.properties -fi - -if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then - sh ${PROJECT_HOME}/assembly/common/build.sh -fi diff --git a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/profiles/dev/client.yml b/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/profiles/dev/client.yml deleted file mode 100644 index c8e7bd0b05..0000000000 --- a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/profiles/dev/client.yml +++ /dev/null @@ -1,38 +0,0 @@ -# dubbo client yaml configure file - -config_center: - protocol: "zookeeper" - address: "127.0.0.1:2181" - group: "dubbo" - config_file: "dubbo.client.properties" - -references: - "UserProvider": - protocol : "dubbo" - interface : "com.ikurento.user.UserProvider" - cluster: "failover" - methods : - - name: "GetUser" - retries: 3 - -protocol_conf: - dubbo: - reconnect_interval: 0 - connection_number: 2 - heartbeat_period: "5s" - session_timeout: "20s" - pool_size: 64 - pool_ttl: 600 - getty_session_param: - compress_encoding: false - tcp_no_delay: true - tcp_keep_alive: true - keep_alive_period: "120s" - tcp_r_buf_size: 262144 - tcp_w_buf_size: 65536 - pkg_wq_size: 512 - tcp_read_timeout: "1s" - tcp_write_timeout: "5s" - wait_timeout: "1s" - max_msg_len: 10240 - session_name: "client" diff --git a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/profiles/dev/log.yml b/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/profiles/dev/log.yml deleted file mode 100644 index 59fa4279ad..0000000000 --- a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/profiles/dev/log.yml +++ /dev/null @@ -1,28 +0,0 @@ - -level: "debug" -development: true -disableCaller: false -disableStacktrace: false -sampling: -encoding: "console" - -# encoder -encoderConfig: - messageKey: "message" - levelKey: "level" - timeKey: "time" - nameKey: "logger" - callerKey: "caller" - stacktraceKey: "stacktrace" - lineEnding: "" - levelEncoder: "capitalColor" - timeEncoder: "iso8601" - durationEncoder: "seconds" - callerEncoder: "short" - nameEncoder: "" - -outputPaths: - - "stderr" -errorOutputPaths: - - "stderr" -initialFields: diff --git a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/profiles/release/client.yml b/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/profiles/release/client.yml deleted file mode 100644 index c8e7bd0b05..0000000000 --- a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/profiles/release/client.yml +++ /dev/null @@ -1,38 +0,0 @@ -# dubbo client yaml configure file - -config_center: - protocol: "zookeeper" - address: "127.0.0.1:2181" - group: "dubbo" - config_file: "dubbo.client.properties" - -references: - "UserProvider": - protocol : "dubbo" - interface : "com.ikurento.user.UserProvider" - cluster: "failover" - methods : - - name: "GetUser" - retries: 3 - -protocol_conf: - dubbo: - reconnect_interval: 0 - connection_number: 2 - heartbeat_period: "5s" - session_timeout: "20s" - pool_size: 64 - pool_ttl: 600 - getty_session_param: - compress_encoding: false - tcp_no_delay: true - tcp_keep_alive: true - keep_alive_period: "120s" - tcp_r_buf_size: 262144 - tcp_w_buf_size: 65536 - pkg_wq_size: 512 - tcp_read_timeout: "1s" - tcp_write_timeout: "5s" - wait_timeout: "1s" - max_msg_len: 10240 - session_name: "client" diff --git a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/profiles/release/log.yml b/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/profiles/release/log.yml deleted file mode 100644 index e0514be020..0000000000 --- a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/profiles/release/log.yml +++ /dev/null @@ -1,28 +0,0 @@ - -level: "warn" -development: true -disableCaller: true -disableStacktrace: true -sampling: -encoding: "console" - -# encoder -encoderConfig: - messageKey: "message" - levelKey: "level" - timeKey: "time" - nameKey: "logger" - callerKey: "caller" - stacktraceKey: "stacktrace" - lineEnding: "" - levelEncoder: "capitalColor" - timeEncoder: "iso8601" - durationEncoder: "seconds" - callerEncoder: "short" - nameEncoder: "" - -outputPaths: - - "stderr" -errorOutputPaths: - - "stderr" -initialFields: diff --git a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/profiles/test/client.yml b/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/profiles/test/client.yml deleted file mode 100644 index c8e7bd0b05..0000000000 --- a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/profiles/test/client.yml +++ /dev/null @@ -1,38 +0,0 @@ -# dubbo client yaml configure file - -config_center: - protocol: "zookeeper" - address: "127.0.0.1:2181" - group: "dubbo" - config_file: "dubbo.client.properties" - -references: - "UserProvider": - protocol : "dubbo" - interface : "com.ikurento.user.UserProvider" - cluster: "failover" - methods : - - name: "GetUser" - retries: 3 - -protocol_conf: - dubbo: - reconnect_interval: 0 - connection_number: 2 - heartbeat_period: "5s" - session_timeout: "20s" - pool_size: 64 - pool_ttl: 600 - getty_session_param: - compress_encoding: false - tcp_no_delay: true - tcp_keep_alive: true - keep_alive_period: "120s" - tcp_r_buf_size: 262144 - tcp_w_buf_size: 65536 - pkg_wq_size: 512 - tcp_read_timeout: "1s" - tcp_write_timeout: "5s" - wait_timeout: "1s" - max_msg_len: 10240 - session_name: "client" diff --git a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/profiles/test/log.yml b/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/profiles/test/log.yml deleted file mode 100644 index baee0b7248..0000000000 --- a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/profiles/test/log.yml +++ /dev/null @@ -1,28 +0,0 @@ - -level: "info" -development: false -disableCaller: false -disableStacktrace: true -sampling: -encoding: "console" - -# encoder -encoderConfig: - messageKey: "message" - levelKey: "level" - timeKey: "time" - nameKey: "logger" - callerKey: "caller" - stacktraceKey: "stacktrace" - lineEnding: "" - levelEncoder: "capitalColor" - timeEncoder: "iso8601" - durationEncoder: "seconds" - callerEncoder: "short" - nameEncoder: "" - -outputPaths: - - "stderr" -errorOutputPaths: - - "stderr" -initialFields: diff --git a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/app/server.go b/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/app/server.go deleted file mode 100644 index 04c614d732..0000000000 --- a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/app/server.go +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 ( - "fmt" - "os" - "os/signal" - "syscall" - "time" -) - -import ( - hessian "github.com/apache/dubbo-go-hessian2" -) - -import ( - _ "github.com/apache/dubbo-go/cluster/cluster_impl" - _ "github.com/apache/dubbo-go/cluster/loadbalance" - "github.com/apache/dubbo-go/common/logger" - _ "github.com/apache/dubbo-go/common/proxy/proxy_factory" - "github.com/apache/dubbo-go/config" - _ "github.com/apache/dubbo-go/config_center/zookeeper" - _ "github.com/apache/dubbo-go/filter/impl" - _ "github.com/apache/dubbo-go/protocol/dubbo" - _ "github.com/apache/dubbo-go/registry/protocol" - _ "github.com/apache/dubbo-go/registry/zookeeper" -) - -var ( - survivalTimeout = int(3e9) -) - -// they are necessary: -// export CONF_PROVIDER_FILE_PATH="xxx" -// export APP_LOG_CONF_FILE="xxx" -func main() { - - // ------for hessian2------ - hessian.RegisterJavaEnum(Gender(MAN)) - hessian.RegisterJavaEnum(Gender(WOMAN)) - hessian.RegisterPOJO(&User{}) - // ------------ - - config.Load() - - initSignal() -} - -func initSignal() { - signals := make(chan os.Signal, 1) - // It is not possible to block SIGKILL or syscall.SIGSTOP - signal.Notify(signals, os.Interrupt, os.Kill, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT) - for { - sig := <-signals - logger.Infof("get signal %s", sig.String()) - switch sig { - case syscall.SIGHUP: - // reload() - default: - time.AfterFunc(time.Duration(float64(survivalTimeout)*float64(time.Second)), func() { - logger.Warnf("app exit now by force...") - os.Exit(1) - }) - - // The program exits normally or timeout forcibly exits. - fmt.Println("provider app exit now...") - return - } - } -} diff --git a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/app/user.go b/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/app/user.go deleted file mode 100644 index 0e4d057668..0000000000 --- a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/app/user.go +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 ( - "context" - "fmt" - "strconv" - "time" -) - -import ( - hessian "github.com/apache/dubbo-go-hessian2" - "github.com/apache/dubbo-go-hessian2/java_exception" - perrors "github.com/pkg/errors" -) - -import ( - "github.com/apache/dubbo-go/config" -) - -type Gender hessian.JavaEnum - -func init() { - config.SetProviderService(new(UserProvider)) -} - -const ( - MAN hessian.JavaEnum = iota - WOMAN -) - -var genderName = map[hessian.JavaEnum]string{ - MAN: "MAN", - WOMAN: "WOMAN", -} - -var genderValue = map[string]hessian.JavaEnum{ - "MAN": MAN, - "WOMAN": WOMAN, -} - -func (g Gender) JavaClassName() string { - return "com.ikurento.user.Gender" -} - -func (g Gender) String() string { - s, ok := genderName[hessian.JavaEnum(g)] - if ok { - return s - } - - return strconv.Itoa(int(g)) -} - -func (g Gender) EnumValue(s string) hessian.JavaEnum { - v, ok := genderValue[s] - if ok { - return v - } - - return hessian.InvalidJavaEnum -} - -type ( - User struct { - // !!! Cannot define lowercase names of variable - Id string - Name string - Age int32 - Time time.Time - Sex Gender // notice: java enum Object <--> go string - } - - UserProvider struct { - user map[string]User - } -) - -var ( - DefaultUser = User{ - Id: "0", Name: "Alex Stocks", Age: 31, - Sex: Gender(MAN), - } - - userMap = UserProvider{user: make(map[string]User)} -) - -func init() { - userMap.user["A000"] = DefaultUser - userMap.user["A001"] = User{Id: "001", Name: "ZhangSheng", Age: 18, Sex: Gender(MAN)} - userMap.user["A002"] = User{Id: "002", Name: "Lily", Age: 20, Sex: Gender(WOMAN)} - userMap.user["A003"] = User{Id: "113", Name: "Moorse", Age: 30, Sex: Gender(WOMAN)} - for k, v := range userMap.user { - v.Time = time.Now() - userMap.user[k] = v - } -} - -func (u User) String() string { - return fmt.Sprintf( - "User{Id:%s, Name:%s, Age:%d, Time:%s, Sex:%s}", - u.Id, u.Name, u.Age, u.Time, u.Sex, - ) -} - -func (u User) JavaClassName() string { - return "com.ikurento.user.User" -} - -func (u *UserProvider) getUser(userId string) (*User, error) { - if user, ok := userMap.user[userId]; ok { - return &user, nil - } - - return nil, fmt.Errorf("invalid user id:%s", userId) -} - -func (u *UserProvider) GetUser(ctx context.Context, req []interface{}, rsp *User) error { - var ( - err error - user *User - ) - - println("req:%#v", req) - user, err = u.getUser(req[0].(string)) - if err == nil { - *rsp = *user - println("rsp:%#v", rsp) - } - return err -} - -func (u *UserProvider) GetErr(ctx context.Context, req []interface{}, rsp *User) error { - return java_exception.NewThrowable("exception") -} - -func (u *UserProvider) GetUser0(id string, name string) (User, error) { - var err error - - println("id:%s, name:%s", id, name) - user, err := u.getUser(id) - if err != nil { - return User{}, err - } - if user.Name != name { - return User{}, perrors.New("name is not " + user.Name) - } - return *user, err -} - -func (u *UserProvider) GetUsers(req []interface{}) ([]interface{}, error) { - var err error - - println("req:%s", req) - t := req[0].([]interface{}) - user, err := u.getUser(t[0].(string)) - if err != nil { - return nil, err - } - println("user:%v", user) - user1, err := u.getUser(t[1].(string)) - if err != nil { - return nil, err - } - println("user1:%v", user1) - - return []interface{}{user, user1}, err -} - -func (u *UserProvider) Reference() string { - return "UserProvider" -} - -func println(format string, args ...interface{}) { - fmt.Printf("\033[32;40m"+format+"\033[0m\n", args...) -} diff --git a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/app/version.go b/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/app/version.go deleted file mode 100644 index c6138584f1..0000000000 --- a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/app/version.go +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 - -var ( - Version = "2.6.0" -) diff --git a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/bin/load.sh b/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/bin/load.sh deleted file mode 100644 index 90077c2471..0000000000 --- a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/bin/load.sh +++ /dev/null @@ -1,151 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - -APP_NAME="APPLICATION_NAME" -APP_ARGS="" - - -PROJECT_HOME="" -OS_NAME=`uname` -if [[ ${OS_NAME} != "Windows" ]]; then - PROJECT_HOME=`pwd` - PROJECT_HOME=${PROJECT_HOME}"/" -fi - -export CONF_PROVIDER_FILE_PATH=${PROJECT_HOME}"TARGET_CONF_FILE" -export APP_LOG_CONF_FILE=${PROJECT_HOME}"TARGET_LOG_CONF_FILE" - -usage() { - echo "Usage: $0 start [conf suffix]" - echo " $0 stop" - echo " $0 term" - echo " $0 restart" - echo " $0 list" - echo " $0 monitor" - echo " $0 crontab" - exit -} - -start() { - arg=$1 - if [ "$arg" = "" ];then - echo "No registry type! Default server.yml!" - else - export CONF_PROVIDER_FILE_PATH=${CONF_PROVIDER_FILE_PATH//\.yml/\_$arg\.yml} - fi - if [ ! -f "${CONF_PROVIDER_FILE_PATH}" ];then - echo $CONF_PROVIDER_FILE_PATH" is not existing!" - return - fi - APP_LOG_PATH="${PROJECT_HOME}logs/" - mkdir -p ${APP_LOG_PATH} - APP_BIN=${PROJECT_HOME}sbin/${APP_NAME} - chmod u+x ${APP_BIN} - # CMD="nohup ${APP_BIN} ${APP_ARGS} >>${APP_NAME}.nohup.out 2>&1 &" - CMD="${APP_BIN}" - eval ${CMD} - PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $2}'` - if [[ ${OS_NAME} != "Linux" && ${OS_NAME} != "Darwin" ]]; then - PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $1}'` - fi - CUR=`date +%FT%T` - if [ "${PID}" != "" ]; then - for p in ${PID} - do - echo "start ${APP_NAME} ( pid =" ${p} ") at " ${CUR} - done - fi -} - -stop() { - PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $2}'` - if [[ ${OS_NAME} != "Linux" && ${OS_NAME} != "Darwin" ]]; then - PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $1}'` - fi - if [ "${PID}" != "" ]; - then - for ps in ${PID} - do - echo "kill -SIGINT ${APP_NAME} ( pid =" ${ps} ")" - kill -2 ${ps} - done - fi -} - - -term() { - PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $2}'` - if [[ ${OS_NAME} != "Linux" && ${OS_NAME} != "Darwin" ]]; then - PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $1}'` - fi - if [ "${PID}" != "" ]; - then - for ps in ${PID} - do - echo "kill -9 ${APP_NAME} ( pid =" ${ps} ")" - kill -9 ${ps} - done - fi -} - -list() { - PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{printf("%s,%s,%s,%s\n", $1, $2, $9, $10)}'` - if [[ ${OS_NAME} != "Linux" && ${OS_NAME} != "Darwin" ]]; then - PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{printf("%s,%s,%s,%s,%s\n", $1, $4, $6, $7, $8)}'` - fi - - if [ "${PID}" != "" ]; then - echo "list ${APP_NAME}" - - if [[ ${OS_NAME} == "Linux" || ${OS_NAME} == "Darwin" ]]; then - echo "index: user, pid, start, duration" - else - echo "index: PID, WINPID, UID, STIME, COMMAND" - fi - idx=0 - for ps in ${PID} - do - echo "${idx}: ${ps}" - ((idx ++)) - done - fi -} - -opt=$1 -case C"$opt" in - Cstart) - start $2 - ;; - Cstop) - stop - ;; - Cterm) - term - ;; - Crestart) - term - start $2 - ;; - Clist) - list - ;; - C*) - usage - ;; -esac - diff --git a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/common/app.properties b/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/common/app.properties deleted file mode 100644 index 1f0827eb51..0000000000 --- a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/common/app.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - -TARGET_EXEC_NAME="user_info_server" -# BUILD_PACKAGE="dubbogo-examples/user-info/server/app" -BUILD_PACKAGE="app" - -TARGET_CONF_FILE="conf/server.yml" -TARGET_LOG_CONF_FILE="conf/log.yml" diff --git a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/common/build.sh b/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/common/build.sh deleted file mode 100644 index 89a95ce679..0000000000 --- a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/common/build.sh +++ /dev/null @@ -1,80 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - -rm -rf target/ - -PROJECT_HOME=`pwd` -TARGET_FOLDER=${PROJECT_HOME}/target/${GOOS} - -TARGET_SBIN_NAME=${TARGET_EXEC_NAME} -version=`cat app/version.go | grep Version | grep -v "Apache" | awk -F '=' '{print $2}' | awk -F '"' '{print $2}'` -if [[ ${GOOS} == "windows" ]]; then - TARGET_SBIN_NAME=${TARGET_SBIN_NAME}.exe -fi -TARGET_NAME=${TARGET_FOLDER}/${TARGET_SBIN_NAME} -if [[ $PROFILE = "test" ]]; then - # GFLAGS=-gcflags "-N -l" -race -x -v # -x会把go build的详细过程输出 - # GFLAGS=-gcflags "-N -l" -race -v - # GFLAGS="-gcflags \"-N -l\" -v" - cd ${BUILD_PACKAGE} && go build -gcflags "-N -l" -x -v -i -o ${TARGET_NAME} && cd - -else - # -s去掉符号表(然后panic时候的stack trace就没有任何文件名/行号信息了,这个等价于普通C/C++程序被strip的效果), - # -w去掉DWARF调试信息,得到的程序就不能用gdb调试了。-s和-w也可以分开使用,一般来说如果不打算用gdb调试, - # -w基本没啥损失。-s的损失就有点大了。 - cd ${BUILD_PACKAGE} && go build -ldflags "-w" -x -v -i -o ${TARGET_NAME} && cd - -fi - -TAR_NAME=${TARGET_EXEC_NAME}-${version}-`date "+%Y%m%d-%H%M"`-${PROFILE} - -mkdir -p ${TARGET_FOLDER}/${TAR_NAME} - -SBIN_DIR=${TARGET_FOLDER}/${TAR_NAME}/sbin -BIN_DIR=${TARGET_FOLDER}/${TAR_NAME} -CONF_DIR=${TARGET_FOLDER}/${TAR_NAME}/conf - -mkdir -p ${SBIN_DIR} -mkdir -p ${CONF_DIR} - -mv ${TARGET_NAME} ${SBIN_DIR} -cp -r assembly/bin ${BIN_DIR} -# modify APPLICATION_NAME -# OS=`uname` -# if [[ $OS=="Darwin" ]]; then -if [ "$(uname)" == "Darwin" ]; then - sed -i "" "s~APPLICATION_NAME~${TARGET_EXEC_NAME}~g" ${BIN_DIR}/bin/* -else - sed -i "s~APPLICATION_NAME~${TARGET_EXEC_NAME}~g" ${BIN_DIR}/bin/* -fi -# modify TARGET_CONF_FILE -if [ "$(uname)" == "Darwin" ]; then - sed -i "" "s~TARGET_CONF_FILE~${TARGET_CONF_FILE}~g" ${BIN_DIR}/bin/* -else - sed -i "s~TARGET_CONF_FILE~${TARGET_CONF_FILE}~g" ${BIN_DIR}/bin/* -fi -# modify TARGET_LOG_CONF_FILE -if [ "$(uname)" == "Darwin" ]; then - sed -i "" "s~TARGET_LOG_CONF_FILE~${TARGET_LOG_CONF_FILE}~g" ${BIN_DIR}/bin/* -else - sed -i "s~TARGET_LOG_CONF_FILE~${TARGET_LOG_CONF_FILE}~g" ${BIN_DIR}/bin/* -fi - -cp -r profiles/${PROFILE}/* ${CONF_DIR} - -cd ${TARGET_FOLDER} - -tar czf ${TAR_NAME}.tar.gz ${TAR_NAME}/* - diff --git a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/linux/dev.sh b/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/linux/dev.sh deleted file mode 100644 index d830ac98c2..0000000000 --- a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/linux/dev.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - - -set -e - -export GOOS=linux -export GOARCH=amd64 - -PROFILE=dev - -PROJECT_HOME=`pwd` - -if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then -. ${PROJECT_HOME}/assembly/common/app.properties -fi - - -if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then -. ${PROJECT_HOME}/assembly/common/build.sh -fi diff --git a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/linux/release.sh b/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/linux/release.sh deleted file mode 100644 index 99303800b0..0000000000 --- a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/linux/release.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - - -set -e - -export GOOS=linux -export GOARCH=amd64 - -PROFILE=release - -PROJECT_HOME=`pwd` - -if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then -. ${PROJECT_HOME}/assembly/common/app.properties -fi - - -if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then -. ${PROJECT_HOME}/assembly/common/build.sh -fi diff --git a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/linux/test.sh b/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/linux/test.sh deleted file mode 100644 index 87144bb973..0000000000 --- a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/linux/test.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - - -set -e - -export GOOS=linux -export GOARCH=amd64 - -PROFILE=test - -PROJECT_HOME=`pwd` - -if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then -. ${PROJECT_HOME}/assembly/common/app.properties -fi - - -if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then -. ${PROJECT_HOME}/assembly/common/build.sh -fi diff --git a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/mac/dev.sh b/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/mac/dev.sh deleted file mode 100644 index 3a7659b2d5..0000000000 --- a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/mac/dev.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - - -set -e - -export GOOS=darwin -export GOARCH=amd64 - -PROFILE=dev - -PROJECT_HOME=`pwd` - -if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then -. ${PROJECT_HOME}/assembly/common/app.properties -fi - - -if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then -. ${PROJECT_HOME}/assembly/common/build.sh -fi diff --git a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/mac/release.sh b/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/mac/release.sh deleted file mode 100644 index 1c4bce4bf8..0000000000 --- a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/mac/release.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - - -set -e - -export GOOS=darwin -export GOARCH=amd64 - -PROFILE=release - -PROJECT_HOME=`pwd` - -if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then -. ${PROJECT_HOME}/assembly/common/app.properties -fi - - -if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then -. ${PROJECT_HOME}/assembly/common/build.sh -fi diff --git a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/mac/test.sh b/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/mac/test.sh deleted file mode 100644 index 69206e32fe..0000000000 --- a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/mac/test.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - -set -e - -export GOOS=darwin -export GOARCH=amd64 - -PROFILE=test - -PROJECT_HOME=`pwd` - -if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then -. ${PROJECT_HOME}/assembly/common/app.properties -fi - - -if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then -. ${PROJECT_HOME}/assembly/common/build.sh -fi - diff --git a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/windows/dev.sh b/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/windows/dev.sh deleted file mode 100644 index 011fb41148..0000000000 --- a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/windows/dev.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - - -set -e - -export GOOS=windows -export GOARCH=amd64 - -PROFILE=dev - -PROJECT_HOME=`pwd` - -if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then -. ${PROJECT_HOME}/assembly/common/app.properties -fi - - -if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then -. ${PROJECT_HOME}/assembly/common/build.sh -fi diff --git a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/windows/release.sh b/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/windows/release.sh deleted file mode 100644 index 679a26a7dc..0000000000 --- a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/windows/release.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - - -set -e - -export GOOS=windows -export GOARCH=amd64 - -PROFILE=release - -PROJECT_HOME=`pwd` - -if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then -. ${PROJECT_HOME}/assembly/common/app.properties -fi - - -if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then -. ${PROJECT_HOME}/assembly/common/build.sh -fi diff --git a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/windows/test.sh b/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/windows/test.sh deleted file mode 100644 index 4a36de0f3a..0000000000 --- a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/assembly/windows/test.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - - -set -e - -export GOOS=windows -export GOARCH=amd64 - -PROFILE=test - -PROJECT_HOME=`pwd` - -if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then -. ${PROJECT_HOME}/assembly/common/app.properties -fi - - -if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then -. ${PROJECT_HOME}/assembly/common/build.sh -fi diff --git a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/profiles/dev/log.yml b/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/profiles/dev/log.yml deleted file mode 100644 index 59fa4279ad..0000000000 --- a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/profiles/dev/log.yml +++ /dev/null @@ -1,28 +0,0 @@ - -level: "debug" -development: true -disableCaller: false -disableStacktrace: false -sampling: -encoding: "console" - -# encoder -encoderConfig: - messageKey: "message" - levelKey: "level" - timeKey: "time" - nameKey: "logger" - callerKey: "caller" - stacktraceKey: "stacktrace" - lineEnding: "" - levelEncoder: "capitalColor" - timeEncoder: "iso8601" - durationEncoder: "seconds" - callerEncoder: "short" - nameEncoder: "" - -outputPaths: - - "stderr" -errorOutputPaths: - - "stderr" -initialFields: diff --git a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/profiles/dev/server.yml b/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/profiles/dev/server.yml deleted file mode 100644 index cdaaca4c38..0000000000 --- a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/profiles/dev/server.yml +++ /dev/null @@ -1,39 +0,0 @@ -# dubbo server yaml configure file - - -config_center: - protocol: "zookeeper" - address: "127.0.0.1:2181" - group: "dubbo" - config_file: "dubbo.properties" - -services: - "UserProvider": - protocol : "dubbo" - # 相当于dubbo.xml中的interface - interface : "com.ikurento.user.UserProvider" - loadbalance: "random" - warmup: "100" - cluster: "failover" - methods: - - name: "GetUser" - retries: 1 - loadbalance: "random" - -protocol_conf: - dubbo: - session_number: 700 - session_timeout: "20s" - getty_session_param: - compress_encoding: false - tcp_no_delay: true - tcp_keep_alive: true - keep_alive_period: "120s" - tcp_r_buf_size: 262144 - tcp_w_buf_size: 65536 - pkg_wq_size: 512 - tcp_read_timeout: "1s" - tcp_write_timeout: "5s" - wait_timeout: "1s" - max_msg_len: 1024 - session_name: "server" diff --git a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/profiles/release/log.yml b/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/profiles/release/log.yml deleted file mode 100644 index e0514be020..0000000000 --- a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/profiles/release/log.yml +++ /dev/null @@ -1,28 +0,0 @@ - -level: "warn" -development: true -disableCaller: true -disableStacktrace: true -sampling: -encoding: "console" - -# encoder -encoderConfig: - messageKey: "message" - levelKey: "level" - timeKey: "time" - nameKey: "logger" - callerKey: "caller" - stacktraceKey: "stacktrace" - lineEnding: "" - levelEncoder: "capitalColor" - timeEncoder: "iso8601" - durationEncoder: "seconds" - callerEncoder: "short" - nameEncoder: "" - -outputPaths: - - "stderr" -errorOutputPaths: - - "stderr" -initialFields: diff --git a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/profiles/release/server.yml b/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/profiles/release/server.yml deleted file mode 100644 index cdaaca4c38..0000000000 --- a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/profiles/release/server.yml +++ /dev/null @@ -1,39 +0,0 @@ -# dubbo server yaml configure file - - -config_center: - protocol: "zookeeper" - address: "127.0.0.1:2181" - group: "dubbo" - config_file: "dubbo.properties" - -services: - "UserProvider": - protocol : "dubbo" - # 相当于dubbo.xml中的interface - interface : "com.ikurento.user.UserProvider" - loadbalance: "random" - warmup: "100" - cluster: "failover" - methods: - - name: "GetUser" - retries: 1 - loadbalance: "random" - -protocol_conf: - dubbo: - session_number: 700 - session_timeout: "20s" - getty_session_param: - compress_encoding: false - tcp_no_delay: true - tcp_keep_alive: true - keep_alive_period: "120s" - tcp_r_buf_size: 262144 - tcp_w_buf_size: 65536 - pkg_wq_size: 512 - tcp_read_timeout: "1s" - tcp_write_timeout: "5s" - wait_timeout: "1s" - max_msg_len: 1024 - session_name: "server" diff --git a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/profiles/test/log.yml b/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/profiles/test/log.yml deleted file mode 100644 index baee0b7248..0000000000 --- a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/profiles/test/log.yml +++ /dev/null @@ -1,28 +0,0 @@ - -level: "info" -development: false -disableCaller: false -disableStacktrace: true -sampling: -encoding: "console" - -# encoder -encoderConfig: - messageKey: "message" - levelKey: "level" - timeKey: "time" - nameKey: "logger" - callerKey: "caller" - stacktraceKey: "stacktrace" - lineEnding: "" - levelEncoder: "capitalColor" - timeEncoder: "iso8601" - durationEncoder: "seconds" - callerEncoder: "short" - nameEncoder: "" - -outputPaths: - - "stderr" -errorOutputPaths: - - "stderr" -initialFields: diff --git a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/profiles/test/server.yml b/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/profiles/test/server.yml deleted file mode 100644 index cdaaca4c38..0000000000 --- a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-server/profiles/test/server.yml +++ /dev/null @@ -1,39 +0,0 @@ -# dubbo server yaml configure file - - -config_center: - protocol: "zookeeper" - address: "127.0.0.1:2181" - group: "dubbo" - config_file: "dubbo.properties" - -services: - "UserProvider": - protocol : "dubbo" - # 相当于dubbo.xml中的interface - interface : "com.ikurento.user.UserProvider" - loadbalance: "random" - warmup: "100" - cluster: "failover" - methods: - - name: "GetUser" - retries: 1 - loadbalance: "random" - -protocol_conf: - dubbo: - session_number: 700 - session_timeout: "20s" - getty_session_param: - compress_encoding: false - tcp_no_delay: true - tcp_keep_alive: true - keep_alive_period: "120s" - tcp_r_buf_size: 262144 - tcp_w_buf_size: 65536 - pkg_wq_size: 512 - tcp_read_timeout: "1s" - tcp_write_timeout: "5s" - wait_timeout: "1s" - max_msg_len: 1024 - session_name: "server" diff --git a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/app/client.go b/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/app/client.go deleted file mode 100644 index db76d939a1..0000000000 --- a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/app/client.go +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 ( - "context" - "fmt" - "os" - "os/signal" - "syscall" - "time" -) - -import ( - "github.com/apache/dubbo-go/common/logger" - _ "github.com/apache/dubbo-go/common/proxy/proxy_factory" - "github.com/apache/dubbo-go/config" - _ "github.com/apache/dubbo-go/protocol/jsonrpc" - _ "github.com/apache/dubbo-go/registry/protocol" - - _ "github.com/apache/dubbo-go/filter/impl" - - _ "github.com/apache/dubbo-go/cluster/cluster_impl" - _ "github.com/apache/dubbo-go/cluster/loadbalance" - _ "github.com/apache/dubbo-go/config_center/zookeeper" - _ "github.com/apache/dubbo-go/registry/zookeeper" -) - -var ( - survivalTimeout int = 10e9 -) - -// they are necessary: -// export CONF_CONSUMER_FILE_PATH="xxx" -// export APP_LOG_CONF_FILE="xxx" -func main() { - - config.Load() - - println("\n\n\necho") - res, err := userProvider.Echo(context.TODO(), "OK") - if err != nil { - println("echo - error: %v", err) - } else { - println("res: %v", res) - } - - time.Sleep(3e9) - - println("\n\n\nstart to test jsonrpc") - user := &JsonRPCUser{} - err = userProvider.GetUser(context.TODO(), []interface{}{"A003"}, user) - if err != nil { - panic(err) - } - println("response result: %v", user) - - println("\n\n\nstart to test jsonrpc - GetUser0") - ret, err := userProvider.GetUser0("A003", "Moorse") - if err != nil { - panic(err) - } - println("response result: %v", ret) - - println("\n\n\nstart to test jsonrpc - GetUsers") - ret1, err := userProvider.GetUsers([]interface{}{[]interface{}{"A002", "A003"}}) - if err != nil { - panic(err) - } - println("response result: %v", ret1) - - println("\n\n\nstart to test jsonrpc - getUser") - user = &JsonRPCUser{} - err = userProvider.GetUser2(context.TODO(), []interface{}{1}, user) - if err != nil { - panic(err) - } - println("response result: %v", user) - - println("\n\n\nstart to test jsonrpc - GetUser3") - err = userProvider.GetUser3() - if err != nil { - panic(err) - } - println("succ!") - - println("\n\n\nstart to test jsonrpc illegal method") - err = userProvider.GetUser1(context.TODO(), []interface{}{"A003"}, user) - if err != nil { - panic(err) - } - - initSignal() -} - -func initSignal() { - signals := make(chan os.Signal, 1) - // It is not possible to block SIGKILL or syscall.SIGSTOP - signal.Notify(signals, os.Interrupt, os.Kill, syscall.SIGHUP, - syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT) - for { - sig := <-signals - logger.Infof("get signal %s", sig.String()) - switch sig { - case syscall.SIGHUP: - // reload() - default: - time.AfterFunc(time.Duration(survivalTimeout)*time.Second, func() { - logger.Warnf("app exit now by force...") - os.Exit(1) - }) - - // The program exits normally or timeout forcibly exits. - fmt.Println("app exit now...") - return - } - } -} - -func println(format string, args ...interface{}) { - fmt.Printf("\033[32;40m"+format+"\033[0m\n", args...) -} diff --git a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/app/user.go b/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/app/user.go deleted file mode 100644 index fef665bb3d..0000000000 --- a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/app/user.go +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 ( - "context" - "fmt" - "time" -) - -import ( - "github.com/apache/dubbo-go/config" -) - -var userProvider = new(UserProvider) - -func init() { - config.SetConsumerService(userProvider) -} - -type JsonRPCUser struct { - ID string `json:"id"` - Name string `json:"name"` - Age int64 `json:"age"` - Time int64 `json:"time"` - Sex string `json:"sex"` -} - -func (u JsonRPCUser) String() string { - return fmt.Sprintf( - "User{ID:%s, Name:%s, Age:%d, Time:%s, Sex:%s}", - u.ID, u.Name, u.Age, time.Unix(u.Time, 0).Format("2006-01-02 15:04:05.99999"), u.Sex, - ) -} - -type UserProvider struct { - GetUsers func(req []interface{}) ([]JsonRPCUser, error) - GetUser func(ctx context.Context, req []interface{}, rsp *JsonRPCUser) error - GetUser0 func(id string, name string) (JsonRPCUser, error) - GetUser1 func(ctx context.Context, req []interface{}, rsp *JsonRPCUser) error - GetUser2 func(ctx context.Context, req []interface{}, rsp *JsonRPCUser) error `dubbo:"getUser"` - GetUser3 func() error - Echo func(ctx context.Context, req interface{}) (interface{}, error) // Echo represent EchoFilter will be used -} - -func (u *UserProvider) Reference() string { - return "UserProvider" -} diff --git a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/app/version.go b/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/app/version.go deleted file mode 100644 index c6138584f1..0000000000 --- a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/app/version.go +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 - -var ( - Version = "2.6.0" -) diff --git a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/bin/load.sh b/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/bin/load.sh deleted file mode 100644 index ffa240b29d..0000000000 --- a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/bin/load.sh +++ /dev/null @@ -1,203 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - -APP_NAME="APPLICATION_NAME" -APP_ARGS="" -SLEEP_INTERVAL=5 -MAX_LIFETIME=4000 - -PROJECT_HOME="" -OS_NAME=`uname` -if [[ ${OS_NAME} != "Windows" ]]; then - PROJECT_HOME=`pwd` - PROJECT_HOME=${PROJECT_HOME}"/" -else - APP_NAME="APPLICATION_NAME.exe" -fi - -export CONF_CONSUMER_FILE_PATH=${PROJECT_HOME}"TARGET_CONF_FILE" -export APP_LOG_CONF_FILE=${PROJECT_HOME}"TARGET_LOG_CONF_FILE" -# export GOTRACEBACK=system -# export GODEBUG=gctrace=1 - -usage() { - echo "Usage: $0 start [conf suffix]" - echo " $0 stop" - echo " $0 term" - echo " $0 restart" - echo " $0 list" - echo " $0 monitor" - echo " $0 crontab" - exit -} - -start() { - arg=$1 - if [ "$arg" = "" ];then - echo "No registry type! Default client.yml!" - else - export CONF_CONSUMER_FILE_PATH=${CONF_CONSUMER_FILE_PATH//\.yml/\_$arg\.yml} - fi - if [ ! -f "${CONF_CONSUMER_FILE_PATH}" ];then - echo $CONF_CONSUMER_FILE_PATH" is not existing!" - return - fi - APP_LOG_PATH=${PROJECT_HOME}"logs/" - mkdir -p ${APP_LOG_PATH} - APP_BIN=${PROJECT_HOME}sbin/${APP_NAME} - chmod u+x ${APP_BIN} - # CMD="nohup ${APP_BIN} ${APP_ARGS} >>${APP_NAME}.nohup.out 2>&1 &" - CMD="${APP_BIN}" - eval ${CMD} - PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $2}'` - if [[ ${OS_NAME} != "Linux" && ${OS_NAME} != "Darwin" ]]; then - PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $1}'` - fi - CUR=`date +%FT%T` - if [ "${PID}" != "" ]; then - for p in ${PID} - do - echo "start ${APP_NAME} ( pid =" ${p} ") at " ${CUR} - done - fi -} - -stop() { - PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $2}'` - if [[ ${OS_NAME} != "Linux" && ${OS_NAME} != "Darwin" ]]; then - PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $1}'` - fi - if [ "${PID}" != "" ]; - then - for ps in ${PID} - do - echo "kill -SIGINT ${APP_NAME} ( pid =" ${ps} ")" - kill -2 ${ps} - done - fi -} - - -term() { - PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $2}'` - if [[ ${OS_NAME} != "Linux" && ${OS_NAME} != "Darwin" ]]; then - PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $1}'` - fi - if [ "${PID}" != "" ]; - then - for ps in ${PID} - do - echo "kill -9 ${APP_NAME} ( pid =" ${ps} ")" - kill -9 ${ps} - done - fi -} - -list() { - PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{printf("%s,%s,%s,%s\n", $1, $2, $9, $10)}'` - if [[ ${OS_NAME} != "Linux" && ${OS_NAME} != "Darwin" ]]; then - PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{printf("%s,%s,%s,%s,%s\n", $1, $4, $6, $7, $8)}'` - fi - - if [ "${PID}" != "" ]; then - echo "list ${APP_NAME}" - - if [[ ${OS_NAME} == "Linux" || ${OS_NAME} == "Darwin" ]]; then - echo "index: user, pid, start, duration" - else - echo "index: PID, WINPID, UID, STIME, COMMAND" - fi - idx=0 - for ps in ${PID} - do - echo "${idx}: ${ps}" - ((idx ++)) - done - fi -} - -monitor() { - idx=0 - while true; do - PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $2}'` - if [[ ${OS_NAME} != "Linux" && ${OS_NAME} != "Darwin" ]]; then - PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $1}'` - fi - if [[ "${PID}" == "" ]]; then - start - idx=0 - fi - - ((LIFE=idx*${SLEEP_INTERVAL})) - echo "${APP_NAME} ( pid = " ${PID} ") has been working in normal state for " $LIFE " seconds." - ((idx ++)) - sleep ${SLEEP_INTERVAL} - done -} - -crontab() { - idx=0 - while true; do - PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $2}'` - if [[ ${OS_NAME} != "Linux" && ${OS_NAME} != "Darwin" ]]; then - PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $1}'` - fi - if [[ "${PID}" == "" ]]; then - start - idx=0 - fi - - ((LIFE=idx*${SLEEP_INTERVAL})) - echo "${APP_NAME} ( pid = " ${PID} ") has been working in normal state for " $LIFE " seconds." - ((idx ++)) - sleep ${SLEEP_INTERVAL} - if [[ ${LIFE} -gt ${MAX_LIFETIME} ]]; then - kill -9 ${PID} - fi - done -} - -opt=$1 -case C"$opt" in - Cstart) - start $2 - ;; - Cstop) - stop - ;; - Cterm) - term - ;; - Crestart) - term - start $2 - ;; - Clist) - list - ;; - Cmonitor) - monitor - ;; - Ccrontab) - crontab - ;; - C*) - usage - ;; -esac - diff --git a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/common/app.properties b/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/common/app.properties deleted file mode 100644 index e10868f4d2..0000000000 --- a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/common/app.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - -export TARGET_EXEC_NAME="user_info_client" -# BUILD_PACKAGE="dubbogo-examples/user-info/client/app" -export BUILD_PACKAGE="app" - -export TARGET_CONF_FILE="conf/client.yml" -export TARGET_LOG_CONF_FILE="conf/log.yml" diff --git a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/common/build.sh b/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/common/build.sh deleted file mode 100644 index c9a9e87c73..0000000000 --- a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/common/build.sh +++ /dev/null @@ -1,83 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - -rm -rf target/ - -PROJECT_HOME=`pwd` -TARGET_FOLDER=${PROJECT_HOME}/target/${GOOS} - -TARGET_SBIN_NAME=${TARGET_EXEC_NAME} -version=`cat app/version.go | grep Version | grep -v "Apache" | awk -F '=' '{print $2}' | awk -F '"' '{print $2}'` -if [[ ${GOOS} == "windows" ]]; then - TARGET_SBIN_NAME=${TARGET_SBIN_NAME}.exe -fi -TARGET_NAME=${TARGET_FOLDER}/${TARGET_SBIN_NAME} -if [[ $PROFILE == "dev" || $PROFILE == "test" ]]; then - # GFLAGS=-gcflags "-N -l" -race -x -v # -x会把go build的详细过程输出 - # GFLAGS=-gcflags "-N -l" -race -v - # GFLAGS="-gcflags \"-N -l\" -v" - cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -i -o ${TARGET_NAME} && cd - -else - # -s去掉符号表(然后panic时候的stack trace就没有任何文件名/行号信息了,这个等价于普通C/C++程序被strip的效果), - # -w去掉DWARF调试信息,得到的程序就不能用gdb调试了。-s和-w也可以分开使用,一般来说如果不打算用gdb调试, - # -w基本没啥损失。-s的损失就有点大了。 - cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -i -o ${TARGET_NAME} && cd - -fi - -TAR_NAME=${TARGET_EXEC_NAME}-${version}-`date "+%Y%m%d-%H%M"`-${PROFILE} - -mkdir -p ${TARGET_FOLDER}/${TAR_NAME} - -SBIN_DIR=${TARGET_FOLDER}/${TAR_NAME}/sbin -BIN_DIR=${TARGET_FOLDER}/${TAR_NAME} -CONF_DIR=${TARGET_FOLDER}/${TAR_NAME}/conf - -mkdir -p ${SBIN_DIR} -mkdir -p ${CONF_DIR} - -mv ${TARGET_NAME} ${SBIN_DIR} -cp -r assembly/bin ${BIN_DIR} -cd ${BIN_DIR}/bin/ && mv load.sh load_${TARGET_EXEC_NAME}.sh && cd - - -platform=$(uname) -# modify APPLICATION_NAME -if [ ${platform} == "Darwin" ]; then - sed -i "" "s~APPLICATION_NAME~${TARGET_EXEC_NAME}~g" ${BIN_DIR}/bin/* -else - sed -i "s~APPLICATION_NAME~${TARGET_EXEC_NAME}~g" ${BIN_DIR}/bin/* -fi - -# modify TARGET_CONF_FILE -if [ ${platform} == "Darwin" ]; then - sed -i "" "s~TARGET_CONF_FILE~${TARGET_CONF_FILE}~g" ${BIN_DIR}/bin/* -else - sed -i "s~TARGET_CONF_FILE~${TARGET_CONF_FILE}~g" ${BIN_DIR}/bin/* -fi - -# modify TARGET_LOG_CONF_FILE -if [ ${platform} == "Darwin" ]; then - sed -i "" "s~TARGET_LOG_CONF_FILE~${TARGET_LOG_CONF_FILE}~g" ${BIN_DIR}/bin/* -else - sed -i "s~TARGET_LOG_CONF_FILE~${TARGET_LOG_CONF_FILE}~g" ${BIN_DIR}/bin/* -fi - -cp -r profiles/${PROFILE}/* ${CONF_DIR} - -cd ${TARGET_FOLDER} - -tar czf ${TAR_NAME}.tar.gz ${TAR_NAME}/* - diff --git a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/linux/dev.sh b/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/linux/dev.sh deleted file mode 100644 index eada737c8d..0000000000 --- a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/linux/dev.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - - -set -e - -export GOOS=linux -export GOARCH=amd64 - -export PROFILE="dev" - -PROJECT_HOME=`pwd` - -if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then - . ${PROJECT_HOME}/assembly/common/app.properties -fi - - -if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then - sh ${PROJECT_HOME}/assembly/common/build.sh -fi diff --git a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/linux/release.sh b/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/linux/release.sh deleted file mode 100644 index 10eb3d73f8..0000000000 --- a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/linux/release.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - - -set -e - -export GOOS=linux -export GOARCH=amd64 - -export PROFILE="release" -export PROJECT_HOME=`pwd` - -if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then - . ${PROJECT_HOME}/assembly/common/app.properties -fi - - -if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then - sh ${PROJECT_HOME}/assembly/common/build.sh -fi diff --git a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/linux/test.sh b/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/linux/test.sh deleted file mode 100644 index 78b650c0d4..0000000000 --- a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/linux/test.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - - -set -e - -export GOOS=linux -export GOARCH=amd64 - -export PROFILE="test" -export PROJECT_HOME=`pwd` - -if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then - . ${PROJECT_HOME}/assembly/common/app.properties -fi - - -if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then - sh ${PROJECT_HOME}/assembly/common/build.sh -fi diff --git a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/mac/dev.sh b/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/mac/dev.sh deleted file mode 100644 index c828476990..0000000000 --- a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/mac/dev.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - - -set -e - -export GOOS=darwin -export GOARCH=amd64 - -export PROFILE="dev" - -export PROJECT_HOME=`pwd` - -if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then - . ${PROJECT_HOME}/assembly/common/app.properties -fi - - -if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then - sh ${PROJECT_HOME}/assembly/common/build.sh -fi diff --git a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/mac/release.sh b/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/mac/release.sh deleted file mode 100644 index 91c2dfee79..0000000000 --- a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/mac/release.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - - -set -e - -export GOOS=darwin -export GOARCH=amd64 - -export PROFILE="release" -export PROJECT_HOME=`pwd` - -if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then - . ${PROJECT_HOME}/assembly/common/app.properties -fi - -if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then - sh ${PROJECT_HOME}/assembly/common/build.sh -fi diff --git a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/mac/test.sh b/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/mac/test.sh deleted file mode 100644 index a7853f5e2d..0000000000 --- a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/mac/test.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - -set -e - -export GOOS=darwin -export GOARCH=amd64 - -export PROFILE="test" -export PROJECT_HOME=`pwd` - -if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then - . ${PROJECT_HOME}/assembly/common/app.properties -fi - - -if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then - sh ${PROJECT_HOME}/assembly/common/build.sh -fi diff --git a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/windows/dev.sh b/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/windows/dev.sh deleted file mode 100644 index 10a3866c0f..0000000000 --- a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/windows/dev.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - - -set -e - -export GOOS=linux -export GOARCH=amd64 - -export PROFILE="dev" -PROJECT_HOME=`pwd` - -if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then - . ${PROJECT_HOME}/assembly/common/app.properties -fi - -if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then - sh ${PROJECT_HOME}/assembly/common/build.sh -fi diff --git a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/windows/release.sh b/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/windows/release.sh deleted file mode 100644 index 21af573fa3..0000000000 --- a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/windows/release.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - - -set -e - -export GOOS=windows -export GOARCH=amd64 - -export PROFILE="release" -export PROJECT_HOME=`pwd` - -if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then - . ${PROJECT_HOME}/assembly/common/app.properties -fi - -if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then - sh ${PROJECT_HOME}/assembly/common/build.sh -fi diff --git a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/windows/test.sh b/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/windows/test.sh deleted file mode 100644 index 2104da8b59..0000000000 --- a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/assembly/windows/test.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - - -set -e - -export GOOS=windows -export GOARCH=amd64 - -export PROFILE="test" -export PROJECT_HOME=`pwd` - -if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then - . ${PROJECT_HOME}/assembly/common/app.properties -fi - -if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then - sh ${PROJECT_HOME}/assembly/common/build.sh -fi diff --git a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/profiles/dev/client.yml b/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/profiles/dev/client.yml deleted file mode 100644 index 3770f52b83..0000000000 --- a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/profiles/dev/client.yml +++ /dev/null @@ -1,16 +0,0 @@ -# dubbo client yaml configure file - -config_center: - protocol: "zookeeper" - address: "127.0.0.1:2181" - group: "dubbo" - config_file: "dubbo.client.properties" - -references: - "UserProvider": - protocol : "jsonrpc" - interface : "com.ikurento.user.UserProvider" - cluster: "failover" - methods : - - name: "GetUser" - retries: 3 diff --git a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/profiles/dev/log.yml b/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/profiles/dev/log.yml deleted file mode 100644 index 59fa4279ad..0000000000 --- a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/profiles/dev/log.yml +++ /dev/null @@ -1,28 +0,0 @@ - -level: "debug" -development: true -disableCaller: false -disableStacktrace: false -sampling: -encoding: "console" - -# encoder -encoderConfig: - messageKey: "message" - levelKey: "level" - timeKey: "time" - nameKey: "logger" - callerKey: "caller" - stacktraceKey: "stacktrace" - lineEnding: "" - levelEncoder: "capitalColor" - timeEncoder: "iso8601" - durationEncoder: "seconds" - callerEncoder: "short" - nameEncoder: "" - -outputPaths: - - "stderr" -errorOutputPaths: - - "stderr" -initialFields: diff --git a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/profiles/release/client.yml b/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/profiles/release/client.yml deleted file mode 100644 index 3770f52b83..0000000000 --- a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/profiles/release/client.yml +++ /dev/null @@ -1,16 +0,0 @@ -# dubbo client yaml configure file - -config_center: - protocol: "zookeeper" - address: "127.0.0.1:2181" - group: "dubbo" - config_file: "dubbo.client.properties" - -references: - "UserProvider": - protocol : "jsonrpc" - interface : "com.ikurento.user.UserProvider" - cluster: "failover" - methods : - - name: "GetUser" - retries: 3 diff --git a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/profiles/release/log.yml b/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/profiles/release/log.yml deleted file mode 100644 index e0514be020..0000000000 --- a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/profiles/release/log.yml +++ /dev/null @@ -1,28 +0,0 @@ - -level: "warn" -development: true -disableCaller: true -disableStacktrace: true -sampling: -encoding: "console" - -# encoder -encoderConfig: - messageKey: "message" - levelKey: "level" - timeKey: "time" - nameKey: "logger" - callerKey: "caller" - stacktraceKey: "stacktrace" - lineEnding: "" - levelEncoder: "capitalColor" - timeEncoder: "iso8601" - durationEncoder: "seconds" - callerEncoder: "short" - nameEncoder: "" - -outputPaths: - - "stderr" -errorOutputPaths: - - "stderr" -initialFields: diff --git a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/profiles/test/client.yml b/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/profiles/test/client.yml deleted file mode 100644 index 3770f52b83..0000000000 --- a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/profiles/test/client.yml +++ /dev/null @@ -1,16 +0,0 @@ -# dubbo client yaml configure file - -config_center: - protocol: "zookeeper" - address: "127.0.0.1:2181" - group: "dubbo" - config_file: "dubbo.client.properties" - -references: - "UserProvider": - protocol : "jsonrpc" - interface : "com.ikurento.user.UserProvider" - cluster: "failover" - methods : - - name: "GetUser" - retries: 3 diff --git a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/profiles/test/log.yml b/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/profiles/test/log.yml deleted file mode 100644 index baee0b7248..0000000000 --- a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-client/profiles/test/log.yml +++ /dev/null @@ -1,28 +0,0 @@ - -level: "info" -development: false -disableCaller: false -disableStacktrace: true -sampling: -encoding: "console" - -# encoder -encoderConfig: - messageKey: "message" - levelKey: "level" - timeKey: "time" - nameKey: "logger" - callerKey: "caller" - stacktraceKey: "stacktrace" - lineEnding: "" - levelEncoder: "capitalColor" - timeEncoder: "iso8601" - durationEncoder: "seconds" - callerEncoder: "short" - nameEncoder: "" - -outputPaths: - - "stderr" -errorOutputPaths: - - "stderr" -initialFields: diff --git a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/app/server.go b/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/app/server.go deleted file mode 100644 index 23cfd41553..0000000000 --- a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/app/server.go +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 ( - "fmt" - "os" - "os/signal" - "syscall" - "time" -) - -import ( - _ "github.com/apache/dubbo-go/cluster/cluster_impl" - _ "github.com/apache/dubbo-go/cluster/loadbalance" - "github.com/apache/dubbo-go/common/logger" - _ "github.com/apache/dubbo-go/common/proxy/proxy_factory" - "github.com/apache/dubbo-go/config" - _ "github.com/apache/dubbo-go/config_center/zookeeper" - _ "github.com/apache/dubbo-go/filter/impl" - _ "github.com/apache/dubbo-go/protocol/jsonrpc" - _ "github.com/apache/dubbo-go/registry/protocol" - _ "github.com/apache/dubbo-go/registry/zookeeper" -) - -var ( - survivalTimeout = int(3e9) -) - -// they are necessary: -// export CONF_PROVIDER_FILE_PATH="xxx" -// export APP_LOG_CONF_FILE="xxx" -func main() { - config.Load() - - initSignal() -} - -func initSignal() { - signals := make(chan os.Signal, 1) - // It is not possible to block SIGKILL or syscall.SIGSTOP - signal.Notify(signals, os.Interrupt, os.Kill, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT) - for { - sig := <-signals - logger.Infof("get signal %s", sig.String()) - switch sig { - case syscall.SIGHUP: - // reload() - default: - time.AfterFunc(time.Duration(float64(survivalTimeout)*float64(time.Second)), func() { - logger.Warnf("app exit now by force...") - os.Exit(1) - }) - - // The program exits normally or timeout forcibly exits. - fmt.Println("provider app exit now...") - return - } - } -} diff --git a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/app/user.go b/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/app/user.go deleted file mode 100644 index 9ab9e58cb4..0000000000 --- a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/app/user.go +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 ( - "context" - "fmt" - "time" -) - -import ( - perrors "github.com/pkg/errors" -) - -import ( - "github.com/apache/dubbo-go/config" -) - -type Gender int - -func init() { - config.SetProviderService(new(UserProvider)) -} - -const ( - MAN = iota - WOMAN -) - -var genderStrings = [...]string{ - "MAN", - "WOMAN", -} - -func (g Gender) String() string { - return genderStrings[g] -} - -type ( - User struct { - Id string `json:"id"` - Name string `json:"name"` - Age int `json:"age"` - sex Gender - Birth int `json:"time"` - Sex string `json:"sex"` - } - - UserProvider struct { - user map[string]User - } -) - -var ( - DefaultUser = User{ - Id: "0", Name: "Alex Stocks", Age: 31, - // Birth: int(time.Date(1985, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()), - Birth: int(time.Date(1985, 11, 24, 15, 15, 0, 0, time.Local).Unix()), - sex: Gender(MAN), - } - - userMap = UserProvider{user: make(map[string]User)} -) - -func init() { - DefaultUser.Sex = DefaultUser.sex.String() - userMap.user["A000"] = DefaultUser - userMap.user["A001"] = User{Id: "001", Name: "ZhangSheng", Age: 18, sex: MAN} - userMap.user["A002"] = User{Id: "002", Name: "Lily", Age: 20, sex: WOMAN} - userMap.user["A003"] = User{Id: "113", Name: "Moorse", Age: 30, sex: MAN} - for k, v := range userMap.user { - v.Birth = int(time.Now().AddDate(-1*v.Age, 0, 0).Unix()) - v.Sex = userMap.user[k].sex.String() - userMap.user[k] = v - } -} - -func (u *UserProvider) getUser(userId string) (*User, error) { - if user, ok := userMap.user[userId]; ok { - return &user, nil - } - - return nil, fmt.Errorf("invalid user id:%s", userId) -} - -func (u *UserProvider) GetUser(ctx context.Context, req []interface{}, rsp *User) error { - var ( - err error - user *User - ) - - println("req:%#v", req) - user, err = u.getUser(req[0].(string)) - if err == nil { - *rsp = *user - println("rsp:%#v", rsp) - } - return err -} - -func (u *UserProvider) GetUser0(id string, name string) (User, error) { - var err error - - println("id:%s, name:%s", id, name) - user, err := u.getUser(id) - if err != nil { - return User{}, err - } - if user.Name != name { - return User{}, perrors.New("name is not " + user.Name) - } - return *user, err -} - -func (u *UserProvider) GetUsers(req []interface{}) ([]User, error) { - var err error - - println("req:%s", req) - t := req[0].([]interface{}) - user, err := u.getUser(t[0].(string)) - if err != nil { - return nil, err - } - println("user:%v", user) - user1, err := u.getUser(t[1].(string)) - if err != nil { - return nil, err - } - println("user1:%v", user1) - - return []User{*user, *user1}, err -} - -func (u *UserProvider) Reference() string { - return "UserProvider" -} - -func println(format string, args ...interface{}) { - fmt.Printf("\033[32;40m"+format+"\033[0m\n", args...) -} diff --git a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/app/version.go b/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/app/version.go deleted file mode 100644 index c6138584f1..0000000000 --- a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/app/version.go +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 - -var ( - Version = "2.6.0" -) diff --git a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/bin/load.sh b/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/bin/load.sh deleted file mode 100644 index 90077c2471..0000000000 --- a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/bin/load.sh +++ /dev/null @@ -1,151 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - -APP_NAME="APPLICATION_NAME" -APP_ARGS="" - - -PROJECT_HOME="" -OS_NAME=`uname` -if [[ ${OS_NAME} != "Windows" ]]; then - PROJECT_HOME=`pwd` - PROJECT_HOME=${PROJECT_HOME}"/" -fi - -export CONF_PROVIDER_FILE_PATH=${PROJECT_HOME}"TARGET_CONF_FILE" -export APP_LOG_CONF_FILE=${PROJECT_HOME}"TARGET_LOG_CONF_FILE" - -usage() { - echo "Usage: $0 start [conf suffix]" - echo " $0 stop" - echo " $0 term" - echo " $0 restart" - echo " $0 list" - echo " $0 monitor" - echo " $0 crontab" - exit -} - -start() { - arg=$1 - if [ "$arg" = "" ];then - echo "No registry type! Default server.yml!" - else - export CONF_PROVIDER_FILE_PATH=${CONF_PROVIDER_FILE_PATH//\.yml/\_$arg\.yml} - fi - if [ ! -f "${CONF_PROVIDER_FILE_PATH}" ];then - echo $CONF_PROVIDER_FILE_PATH" is not existing!" - return - fi - APP_LOG_PATH="${PROJECT_HOME}logs/" - mkdir -p ${APP_LOG_PATH} - APP_BIN=${PROJECT_HOME}sbin/${APP_NAME} - chmod u+x ${APP_BIN} - # CMD="nohup ${APP_BIN} ${APP_ARGS} >>${APP_NAME}.nohup.out 2>&1 &" - CMD="${APP_BIN}" - eval ${CMD} - PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $2}'` - if [[ ${OS_NAME} != "Linux" && ${OS_NAME} != "Darwin" ]]; then - PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $1}'` - fi - CUR=`date +%FT%T` - if [ "${PID}" != "" ]; then - for p in ${PID} - do - echo "start ${APP_NAME} ( pid =" ${p} ") at " ${CUR} - done - fi -} - -stop() { - PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $2}'` - if [[ ${OS_NAME} != "Linux" && ${OS_NAME} != "Darwin" ]]; then - PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $1}'` - fi - if [ "${PID}" != "" ]; - then - for ps in ${PID} - do - echo "kill -SIGINT ${APP_NAME} ( pid =" ${ps} ")" - kill -2 ${ps} - done - fi -} - - -term() { - PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $2}'` - if [[ ${OS_NAME} != "Linux" && ${OS_NAME} != "Darwin" ]]; then - PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $1}'` - fi - if [ "${PID}" != "" ]; - then - for ps in ${PID} - do - echo "kill -9 ${APP_NAME} ( pid =" ${ps} ")" - kill -9 ${ps} - done - fi -} - -list() { - PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{printf("%s,%s,%s,%s\n", $1, $2, $9, $10)}'` - if [[ ${OS_NAME} != "Linux" && ${OS_NAME} != "Darwin" ]]; then - PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{printf("%s,%s,%s,%s,%s\n", $1, $4, $6, $7, $8)}'` - fi - - if [ "${PID}" != "" ]; then - echo "list ${APP_NAME}" - - if [[ ${OS_NAME} == "Linux" || ${OS_NAME} == "Darwin" ]]; then - echo "index: user, pid, start, duration" - else - echo "index: PID, WINPID, UID, STIME, COMMAND" - fi - idx=0 - for ps in ${PID} - do - echo "${idx}: ${ps}" - ((idx ++)) - done - fi -} - -opt=$1 -case C"$opt" in - Cstart) - start $2 - ;; - Cstop) - stop - ;; - Cterm) - term - ;; - Crestart) - term - start $2 - ;; - Clist) - list - ;; - C*) - usage - ;; -esac - diff --git a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/common/app.properties b/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/common/app.properties deleted file mode 100644 index 1f0827eb51..0000000000 --- a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/common/app.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - -TARGET_EXEC_NAME="user_info_server" -# BUILD_PACKAGE="dubbogo-examples/user-info/server/app" -BUILD_PACKAGE="app" - -TARGET_CONF_FILE="conf/server.yml" -TARGET_LOG_CONF_FILE="conf/log.yml" diff --git a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/common/build.sh b/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/common/build.sh deleted file mode 100644 index 89a95ce679..0000000000 --- a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/common/build.sh +++ /dev/null @@ -1,80 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - -rm -rf target/ - -PROJECT_HOME=`pwd` -TARGET_FOLDER=${PROJECT_HOME}/target/${GOOS} - -TARGET_SBIN_NAME=${TARGET_EXEC_NAME} -version=`cat app/version.go | grep Version | grep -v "Apache" | awk -F '=' '{print $2}' | awk -F '"' '{print $2}'` -if [[ ${GOOS} == "windows" ]]; then - TARGET_SBIN_NAME=${TARGET_SBIN_NAME}.exe -fi -TARGET_NAME=${TARGET_FOLDER}/${TARGET_SBIN_NAME} -if [[ $PROFILE = "test" ]]; then - # GFLAGS=-gcflags "-N -l" -race -x -v # -x会把go build的详细过程输出 - # GFLAGS=-gcflags "-N -l" -race -v - # GFLAGS="-gcflags \"-N -l\" -v" - cd ${BUILD_PACKAGE} && go build -gcflags "-N -l" -x -v -i -o ${TARGET_NAME} && cd - -else - # -s去掉符号表(然后panic时候的stack trace就没有任何文件名/行号信息了,这个等价于普通C/C++程序被strip的效果), - # -w去掉DWARF调试信息,得到的程序就不能用gdb调试了。-s和-w也可以分开使用,一般来说如果不打算用gdb调试, - # -w基本没啥损失。-s的损失就有点大了。 - cd ${BUILD_PACKAGE} && go build -ldflags "-w" -x -v -i -o ${TARGET_NAME} && cd - -fi - -TAR_NAME=${TARGET_EXEC_NAME}-${version}-`date "+%Y%m%d-%H%M"`-${PROFILE} - -mkdir -p ${TARGET_FOLDER}/${TAR_NAME} - -SBIN_DIR=${TARGET_FOLDER}/${TAR_NAME}/sbin -BIN_DIR=${TARGET_FOLDER}/${TAR_NAME} -CONF_DIR=${TARGET_FOLDER}/${TAR_NAME}/conf - -mkdir -p ${SBIN_DIR} -mkdir -p ${CONF_DIR} - -mv ${TARGET_NAME} ${SBIN_DIR} -cp -r assembly/bin ${BIN_DIR} -# modify APPLICATION_NAME -# OS=`uname` -# if [[ $OS=="Darwin" ]]; then -if [ "$(uname)" == "Darwin" ]; then - sed -i "" "s~APPLICATION_NAME~${TARGET_EXEC_NAME}~g" ${BIN_DIR}/bin/* -else - sed -i "s~APPLICATION_NAME~${TARGET_EXEC_NAME}~g" ${BIN_DIR}/bin/* -fi -# modify TARGET_CONF_FILE -if [ "$(uname)" == "Darwin" ]; then - sed -i "" "s~TARGET_CONF_FILE~${TARGET_CONF_FILE}~g" ${BIN_DIR}/bin/* -else - sed -i "s~TARGET_CONF_FILE~${TARGET_CONF_FILE}~g" ${BIN_DIR}/bin/* -fi -# modify TARGET_LOG_CONF_FILE -if [ "$(uname)" == "Darwin" ]; then - sed -i "" "s~TARGET_LOG_CONF_FILE~${TARGET_LOG_CONF_FILE}~g" ${BIN_DIR}/bin/* -else - sed -i "s~TARGET_LOG_CONF_FILE~${TARGET_LOG_CONF_FILE}~g" ${BIN_DIR}/bin/* -fi - -cp -r profiles/${PROFILE}/* ${CONF_DIR} - -cd ${TARGET_FOLDER} - -tar czf ${TAR_NAME}.tar.gz ${TAR_NAME}/* - diff --git a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/linux/dev.sh b/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/linux/dev.sh deleted file mode 100644 index d830ac98c2..0000000000 --- a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/linux/dev.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - - -set -e - -export GOOS=linux -export GOARCH=amd64 - -PROFILE=dev - -PROJECT_HOME=`pwd` - -if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then -. ${PROJECT_HOME}/assembly/common/app.properties -fi - - -if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then -. ${PROJECT_HOME}/assembly/common/build.sh -fi diff --git a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/linux/release.sh b/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/linux/release.sh deleted file mode 100644 index 99303800b0..0000000000 --- a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/linux/release.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - - -set -e - -export GOOS=linux -export GOARCH=amd64 - -PROFILE=release - -PROJECT_HOME=`pwd` - -if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then -. ${PROJECT_HOME}/assembly/common/app.properties -fi - - -if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then -. ${PROJECT_HOME}/assembly/common/build.sh -fi diff --git a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/linux/test.sh b/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/linux/test.sh deleted file mode 100644 index 87144bb973..0000000000 --- a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/linux/test.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - - -set -e - -export GOOS=linux -export GOARCH=amd64 - -PROFILE=test - -PROJECT_HOME=`pwd` - -if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then -. ${PROJECT_HOME}/assembly/common/app.properties -fi - - -if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then -. ${PROJECT_HOME}/assembly/common/build.sh -fi diff --git a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/mac/dev.sh b/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/mac/dev.sh deleted file mode 100644 index 3a7659b2d5..0000000000 --- a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/mac/dev.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - - -set -e - -export GOOS=darwin -export GOARCH=amd64 - -PROFILE=dev - -PROJECT_HOME=`pwd` - -if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then -. ${PROJECT_HOME}/assembly/common/app.properties -fi - - -if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then -. ${PROJECT_HOME}/assembly/common/build.sh -fi diff --git a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/mac/release.sh b/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/mac/release.sh deleted file mode 100644 index 1c4bce4bf8..0000000000 --- a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/mac/release.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - - -set -e - -export GOOS=darwin -export GOARCH=amd64 - -PROFILE=release - -PROJECT_HOME=`pwd` - -if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then -. ${PROJECT_HOME}/assembly/common/app.properties -fi - - -if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then -. ${PROJECT_HOME}/assembly/common/build.sh -fi diff --git a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/mac/test.sh b/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/mac/test.sh deleted file mode 100644 index 69206e32fe..0000000000 --- a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/mac/test.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - -set -e - -export GOOS=darwin -export GOARCH=amd64 - -PROFILE=test - -PROJECT_HOME=`pwd` - -if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then -. ${PROJECT_HOME}/assembly/common/app.properties -fi - - -if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then -. ${PROJECT_HOME}/assembly/common/build.sh -fi - diff --git a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/windows/dev.sh b/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/windows/dev.sh deleted file mode 100644 index 011fb41148..0000000000 --- a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/windows/dev.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - - -set -e - -export GOOS=windows -export GOARCH=amd64 - -PROFILE=dev - -PROJECT_HOME=`pwd` - -if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then -. ${PROJECT_HOME}/assembly/common/app.properties -fi - - -if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then -. ${PROJECT_HOME}/assembly/common/build.sh -fi diff --git a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/windows/release.sh b/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/windows/release.sh deleted file mode 100644 index 679a26a7dc..0000000000 --- a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/windows/release.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - - -set -e - -export GOOS=windows -export GOARCH=amd64 - -PROFILE=release - -PROJECT_HOME=`pwd` - -if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then -. ${PROJECT_HOME}/assembly/common/app.properties -fi - - -if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then -. ${PROJECT_HOME}/assembly/common/build.sh -fi diff --git a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/windows/test.sh b/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/windows/test.sh deleted file mode 100644 index 4a36de0f3a..0000000000 --- a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/assembly/windows/test.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - - -set -e - -export GOOS=windows -export GOARCH=amd64 - -PROFILE=test - -PROJECT_HOME=`pwd` - -if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then -. ${PROJECT_HOME}/assembly/common/app.properties -fi - - -if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then -. ${PROJECT_HOME}/assembly/common/build.sh -fi diff --git a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/profiles/dev/log.yml b/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/profiles/dev/log.yml deleted file mode 100644 index 59fa4279ad..0000000000 --- a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/profiles/dev/log.yml +++ /dev/null @@ -1,28 +0,0 @@ - -level: "debug" -development: true -disableCaller: false -disableStacktrace: false -sampling: -encoding: "console" - -# encoder -encoderConfig: - messageKey: "message" - levelKey: "level" - timeKey: "time" - nameKey: "logger" - callerKey: "caller" - stacktraceKey: "stacktrace" - lineEnding: "" - levelEncoder: "capitalColor" - timeEncoder: "iso8601" - durationEncoder: "seconds" - callerEncoder: "short" - nameEncoder: "" - -outputPaths: - - "stderr" -errorOutputPaths: - - "stderr" -initialFields: diff --git a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/profiles/dev/server.yml b/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/profiles/dev/server.yml deleted file mode 100644 index 5c2a2fe2cb..0000000000 --- a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/profiles/dev/server.yml +++ /dev/null @@ -1,22 +0,0 @@ -# dubbo server yaml configure file - -# application config - -services: - "UserProvider": - protocol : "jsonrpc" - # 相当于dubbo.xml中的interface - interface : "com.ikurento.user.UserProvider" - loadbalance: "random" - warmup: "100" - cluster: "failover" - methods: - - name: "GetUser" - retries: 1 - loadbalance: "random" - -config_center: - protocol: "zookeeper" - address: "127.0.0.1:2181" - group: "dubbo" - config_file: "dubbo.properties" diff --git a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/profiles/release/log.yml b/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/profiles/release/log.yml deleted file mode 100644 index e0514be020..0000000000 --- a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/profiles/release/log.yml +++ /dev/null @@ -1,28 +0,0 @@ - -level: "warn" -development: true -disableCaller: true -disableStacktrace: true -sampling: -encoding: "console" - -# encoder -encoderConfig: - messageKey: "message" - levelKey: "level" - timeKey: "time" - nameKey: "logger" - callerKey: "caller" - stacktraceKey: "stacktrace" - lineEnding: "" - levelEncoder: "capitalColor" - timeEncoder: "iso8601" - durationEncoder: "seconds" - callerEncoder: "short" - nameEncoder: "" - -outputPaths: - - "stderr" -errorOutputPaths: - - "stderr" -initialFields: diff --git a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/profiles/release/server.yml b/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/profiles/release/server.yml deleted file mode 100644 index 82c9fa66ad..0000000000 --- a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/profiles/release/server.yml +++ /dev/null @@ -1,25 +0,0 @@ -# dubbo server yaml configure file - -# application config - -services: - "UserProvider": - protocol : "jsonrpc" - # 相当于dubbo.xml中的interface - interface : "com.ikurento.user.UserProvider" - loadbalance: "random" - warmup: "100" - cluster: "failover" - methods: - - name: "GetUser" - retries: 1 - loadbalance: "random" - -config_center: - protocol: "zookeeper" - address: "127.0.0.1:2181" - group: "dubbo" - config_file: "dubbo.properties" - - - diff --git a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/profiles/test/log.yml b/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/profiles/test/log.yml deleted file mode 100644 index baee0b7248..0000000000 --- a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/profiles/test/log.yml +++ /dev/null @@ -1,28 +0,0 @@ - -level: "info" -development: false -disableCaller: false -disableStacktrace: true -sampling: -encoding: "console" - -# encoder -encoderConfig: - messageKey: "message" - levelKey: "level" - timeKey: "time" - nameKey: "logger" - callerKey: "caller" - stacktraceKey: "stacktrace" - lineEnding: "" - levelEncoder: "capitalColor" - timeEncoder: "iso8601" - durationEncoder: "seconds" - callerEncoder: "short" - nameEncoder: "" - -outputPaths: - - "stderr" -errorOutputPaths: - - "stderr" -initialFields: diff --git a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/profiles/test/server.yml b/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/profiles/test/server.yml deleted file mode 100644 index 82c9fa66ad..0000000000 --- a/examples/configcenter/zookeeper/jsonrpc/with-configcenter-go-server/profiles/test/server.yml +++ /dev/null @@ -1,25 +0,0 @@ -# dubbo server yaml configure file - -# application config - -services: - "UserProvider": - protocol : "jsonrpc" - # 相当于dubbo.xml中的interface - interface : "com.ikurento.user.UserProvider" - loadbalance: "random" - warmup: "100" - cluster: "failover" - methods: - - name: "GetUser" - retries: 1 - loadbalance: "random" - -config_center: - protocol: "zookeeper" - address: "127.0.0.1:2181" - group: "dubbo" - config_file: "dubbo.properties" - - - diff --git a/examples/consul/go-client/config/client.yml b/examples/consul/go-client/config/client.yml index 8a7458c384..8a4c088bd6 100644 --- a/examples/consul/go-client/config/client.yml +++ b/examples/consul/go-client/config/client.yml @@ -1,4 +1,4 @@ -application_config: +application: organization : "ikurento.com" name : "BDTService" module : "dubbogo user-info client" diff --git a/examples/consul/go-server/config/server.yml b/examples/consul/go-server/config/server.yml index c12800e68d..b251860d7a 100644 --- a/examples/consul/go-server/config/server.yml +++ b/examples/consul/go-server/config/server.yml @@ -1,4 +1,4 @@ -application_config: +application: organization : "ikurento.com" name : "BDTService" module : "dubbogo user-info server" diff --git a/examples/general/dubbo/go-client/profiles/dev/client.yml b/examples/general/dubbo/go-client/profiles/dev/client.yml index ff69668841..3e22e97c0a 100644 --- a/examples/general/dubbo/go-client/profiles/dev/client.yml +++ b/examples/general/dubbo/go-client/profiles/dev/client.yml @@ -8,7 +8,7 @@ request_timeout : "3s" connect_timeout : "3s" # application config -application_config: +application: organization : "ikurento.com" name : "BDTService" module : "dubbogo user-info client" diff --git a/examples/general/dubbo/go-client/profiles/release/client.yml b/examples/general/dubbo/go-client/profiles/release/client.yml deleted file mode 100644 index b4d897fda2..0000000000 --- a/examples/general/dubbo/go-client/profiles/release/client.yml +++ /dev/null @@ -1,83 +0,0 @@ -# dubbo client yaml configure file - - -check: true -# client -request_timeout : "3s" -# connect timeout -connect_timeout : "3s" - -# application config -application_config: - organization : "ikurento.com" - name : "BDTService" - module : "dubbogo user-info client" - version : "0.0.1" - owner : "ZX" - environment : "release" - -registries : - "hangzhouzk": - protocol: "zookeeper" - timeout : "3s" - address: "127.0.0.1:2181" - username: "" - password: "" - "shanghaizk": - protocol: "zookeeper" - timeout : "3s" - address: "127.0.0.1:2182" - username: "" - password: "" - -references: - "UserProvider": - # 可以指定多个registry,使用逗号隔开;不指定默认向所有注册中心注册 - registry: "hangzhouzk" - protocol : "dubbo" - interface : "com.ikurento.user.UserProvider" - cluster: "failover" - methods : - - name: "GetUser" - retries: 3 - "UserProvider1": - registry: "hangzhouzk" - protocol: "dubbo" - version: "2.0" - interface: "com.ikurento.user.UserProvider" - cluster: "failover" - methods: - - name: "GetUser" - retries: 3 - "UserProvider2": - registry: "hangzhouzk" - protocol: "dubbo" - version: "2.0" - group: "as" - interface: "com.ikurento.user.UserProvider" - cluster: "failover" - methods: - - name: "GetUser" - retries: 3 - -protocol_conf: - dubbo: - reconnect_interval: 0 - connection_number: 2 - heartbeat_period: "5s" - session_timeout: "20s" - pool_size: 64 - pool_ttl: 600 - getty_session_param: - compress_encoding: false - tcp_no_delay: true - tcp_keep_alive: true - keep_alive_period: "120s" - tcp_r_buf_size: 262144 - tcp_w_buf_size: 65536 - pkg_wq_size: 512 - tcp_read_timeout: "1s" - tcp_write_timeout: "5s" - wait_timeout: "1s" - max_msg_len: 10240 - session_name: "client" diff --git a/examples/general/dubbo/go-client/profiles/release/log.yml b/examples/general/dubbo/go-client/profiles/release/log.yml deleted file mode 100644 index e0514be020..0000000000 --- a/examples/general/dubbo/go-client/profiles/release/log.yml +++ /dev/null @@ -1,28 +0,0 @@ - -level: "warn" -development: true -disableCaller: true -disableStacktrace: true -sampling: -encoding: "console" - -# encoder -encoderConfig: - messageKey: "message" - levelKey: "level" - timeKey: "time" - nameKey: "logger" - callerKey: "caller" - stacktraceKey: "stacktrace" - lineEnding: "" - levelEncoder: "capitalColor" - timeEncoder: "iso8601" - durationEncoder: "seconds" - callerEncoder: "short" - nameEncoder: "" - -outputPaths: - - "stderr" -errorOutputPaths: - - "stderr" -initialFields: diff --git a/examples/general/dubbo/go-client/profiles/test/client.yml b/examples/general/dubbo/go-client/profiles/test/client.yml deleted file mode 100644 index c8b5c58691..0000000000 --- a/examples/general/dubbo/go-client/profiles/test/client.yml +++ /dev/null @@ -1,83 +0,0 @@ -# dubbo client yaml configure file - - -check: true -# client -request_timeout : "3s" -# connect timeout -connect_timeout : "3s" - -# application config -application_config: - organization : "ikurento.com" - name : "BDTService" - module : "dubbogo user-info client" - version : "0.0.1" - owner : "ZX" - environment : "test" - -registries : - "hangzhouzk": - protocol: "zookeeper" - timeout : "3s" - address: "127.0.0.1:2181" - username: "" - password: "" - "shanghaizk": - protocol: "zookeeper" - timeout : "3s" - address: "127.0.0.1:2182" - username: "" - password: "" - -references: - "UserProvider": - # 可以指定多个registry,使用逗号隔开;不指定默认向所有注册中心注册 - registry: "hangzhouzk" - protocol : "dubbo" - interface : "com.ikurento.user.UserProvider" - cluster: "failover" - methods : - - name: "GetUser" - retries: 3 - "UserProvider1": - registry: "hangzhouzk" - protocol: "dubbo" - version: "2.0" - interface: "com.ikurento.user.UserProvider" - cluster: "failover" - methods: - - name: "GetUser" - retries: 3 - "UserProvider2": - registry: "hangzhouzk" - protocol: "dubbo" - version: "2.0" - group: "as" - interface: "com.ikurento.user.UserProvider" - cluster: "failover" - methods: - - name: "GetUser" - retries: 3 - -protocol_conf: - dubbo: - reconnect_interval: 0 - connection_number: 2 - heartbeat_period: "5s" - session_timeout: "20s" - pool_size: 64 - pool_ttl: 600 - getty_session_param: - compress_encoding: false - tcp_no_delay: true - tcp_keep_alive: true - keep_alive_period: "120s" - tcp_r_buf_size: 262144 - tcp_w_buf_size: 65536 - pkg_wq_size: 512 - tcp_read_timeout: "1s" - tcp_write_timeout: "5s" - wait_timeout: "1s" - max_msg_len: 10240 - session_name: "client" diff --git a/examples/general/dubbo/go-client/profiles/test/log.yml b/examples/general/dubbo/go-client/profiles/test/log.yml deleted file mode 100644 index baee0b7248..0000000000 --- a/examples/general/dubbo/go-client/profiles/test/log.yml +++ /dev/null @@ -1,28 +0,0 @@ - -level: "info" -development: false -disableCaller: false -disableStacktrace: true -sampling: -encoding: "console" - -# encoder -encoderConfig: - messageKey: "message" - levelKey: "level" - timeKey: "time" - nameKey: "logger" - callerKey: "caller" - stacktraceKey: "stacktrace" - lineEnding: "" - levelEncoder: "capitalColor" - timeEncoder: "iso8601" - durationEncoder: "seconds" - callerEncoder: "short" - nameEncoder: "" - -outputPaths: - - "stderr" -errorOutputPaths: - - "stderr" -initialFields: diff --git a/examples/general/dubbo/go-server/profiles/dev/server.yml b/examples/general/dubbo/go-server/profiles/dev/server.yml index 79c2cb2cc2..c4aeedf8eb 100644 --- a/examples/general/dubbo/go-server/profiles/dev/server.yml +++ b/examples/general/dubbo/go-server/profiles/dev/server.yml @@ -2,7 +2,7 @@ # application config -application_config: +application: organization : "ikurento.com" name : "BDTService" module : "dubbogo user-info server" diff --git a/examples/general/dubbo/go-server/profiles/release/log.yml b/examples/general/dubbo/go-server/profiles/release/log.yml deleted file mode 100644 index e0514be020..0000000000 --- a/examples/general/dubbo/go-server/profiles/release/log.yml +++ /dev/null @@ -1,28 +0,0 @@ - -level: "warn" -development: true -disableCaller: true -disableStacktrace: true -sampling: -encoding: "console" - -# encoder -encoderConfig: - messageKey: "message" - levelKey: "level" - timeKey: "time" - nameKey: "logger" - callerKey: "caller" - stacktraceKey: "stacktrace" - lineEnding: "" - levelEncoder: "capitalColor" - timeEncoder: "iso8601" - durationEncoder: "seconds" - callerEncoder: "short" - nameEncoder: "" - -outputPaths: - - "stderr" -errorOutputPaths: - - "stderr" -initialFields: diff --git a/examples/general/dubbo/go-server/profiles/release/server.yml b/examples/general/dubbo/go-server/profiles/release/server.yml deleted file mode 100644 index 6890ed3bdb..0000000000 --- a/examples/general/dubbo/go-server/profiles/release/server.yml +++ /dev/null @@ -1,91 +0,0 @@ -# dubbo server yaml configure file - - -# application config -application_config: - organization : "ikurento.com" - name : "BDTService" - module : "dubbogo user-info server" - version : "0.0.1" - owner : "ZX" - environment : "release" - -registries : - "hangzhouzk": - protocol: "zookeeper" - timeout : "3s" - address: "127.0.0.1:2181" - username: "" - password: "" - "shanghaizk": - protocol: "zookeeper" - timeout : "3s" - address: "127.0.0.1:2182" - username: "" - password: "" - - -services: - "UserProvider": - # 可以指定多个registry,使用逗号隔开;不指定默认向所有注册中心注册 - registry: "hangzhouzk" - protocol : "dubbo" - # 相当于dubbo.xml中的interface - interface : "com.ikurento.user.UserProvider" - loadbalance: "random" - warmup: "100" - cluster: "failover" - methods: - - name: "GetUser" - retries: 1 - loadbalance: "random" - "UserProvider1": - registry: "hangzhouzk" - protocol: "dubbo" - version: "2.0" - interface: "com.ikurento.user.UserProvider" - loadbalance: "random" - warmup: "100" - cluster: "failover" - methods: - - name: "GetUser" - retries: 1 - loadbalance: "random" - "UserProvider2": - registry: "hangzhouzk" - protocol: "dubbo" - version: "2.0" - group: "as" - interface: "com.ikurento.user.UserProvider" - loadbalance: "random" - warmup: "100" - cluster: "failover" - methods: - - name: "GetUser" - retries: 1 - loadbalance: "random" - -protocols: - "dubbo1": - name: "dubbo" - # ip : "127.0.0.1" - port: 20000 - - -protocol_conf: - dubbo: - session_number: 700 - session_timeout: "20s" - getty_session_param: - compress_encoding: false - tcp_no_delay: true - tcp_keep_alive: true - keep_alive_period: "120s" - tcp_r_buf_size: 262144 - tcp_w_buf_size: 65536 - pkg_wq_size: 512 - tcp_read_timeout: "1s" - tcp_write_timeout: "5s" - wait_timeout: "1s" - max_msg_len: 1024 - session_name: "server" diff --git a/examples/general/dubbo/go-server/profiles/test/log.yml b/examples/general/dubbo/go-server/profiles/test/log.yml deleted file mode 100644 index baee0b7248..0000000000 --- a/examples/general/dubbo/go-server/profiles/test/log.yml +++ /dev/null @@ -1,28 +0,0 @@ - -level: "info" -development: false -disableCaller: false -disableStacktrace: true -sampling: -encoding: "console" - -# encoder -encoderConfig: - messageKey: "message" - levelKey: "level" - timeKey: "time" - nameKey: "logger" - callerKey: "caller" - stacktraceKey: "stacktrace" - lineEnding: "" - levelEncoder: "capitalColor" - timeEncoder: "iso8601" - durationEncoder: "seconds" - callerEncoder: "short" - nameEncoder: "" - -outputPaths: - - "stderr" -errorOutputPaths: - - "stderr" -initialFields: diff --git a/examples/general/dubbo/go-server/profiles/test/server.yml b/examples/general/dubbo/go-server/profiles/test/server.yml deleted file mode 100644 index b6dd41da44..0000000000 --- a/examples/general/dubbo/go-server/profiles/test/server.yml +++ /dev/null @@ -1,91 +0,0 @@ -# dubbo server yaml configure file - - -# application config -application_config: - organization : "ikurento.com" - name : "BDTService" - module : "dubbogo user-info server" - version : "0.0.1" - owner : "ZX" - environment : "test" - -registries : - "hangzhouzk": - protocol: "zookeeper" - timeout : "3s" - address: "127.0.0.1:2181" - username: "" - password: "" - "shanghaizk": - protocol: "zookeeper" - timeout : "3s" - address: "127.0.0.1:2182" - username: "" - password: "" - - -services: - "UserProvider": - # 可以指定多个registry,使用逗号隔开;不指定默认向所有注册中心注册 - registry: "hangzhouzk" - protocol : "dubbo" - # 相当于dubbo.xml中的interface - interface : "com.ikurento.user.UserProvider" - loadbalance: "random" - warmup: "100" - cluster: "failover" - methods: - - name: "GetUser" - retries: 1 - loadbalance: "random" - "UserProvider1": - registry: "hangzhouzk" - protocol: "dubbo" - version: "2.0" - interface: "com.ikurento.user.UserProvider" - loadbalance: "random" - warmup: "100" - cluster: "failover" - methods: - - name: "GetUser" - retries: 1 - loadbalance: "random" - "UserProvider2": - registry: "hangzhouzk" - protocol: "dubbo" - version: "2.0" - group: "as" - interface: "com.ikurento.user.UserProvider" - loadbalance: "random" - warmup: "100" - cluster: "failover" - methods: - - name: "GetUser" - retries: 1 - loadbalance: "random" - -protocols: - "dubbo1": - name: "dubbo" - # ip : "127.0.0.1" - port: 20000 - - -protocol_conf: - dubbo: - session_number: 700 - session_timeout: "20s" - getty_session_param: - compress_encoding: false - tcp_no_delay: true - tcp_keep_alive: true - keep_alive_period: "120s" - tcp_r_buf_size: 262144 - tcp_w_buf_size: 65536 - pkg_wq_size: 512 - tcp_read_timeout: "1s" - tcp_write_timeout: "5s" - wait_timeout: "1s" - max_msg_len: 1024 - session_name: "server" diff --git a/examples/general/jsonrpc/go-client/profiles/dev/client.yml b/examples/general/jsonrpc/go-client/profiles/dev/client.yml index 788e06eecd..ed757d7eca 100644 --- a/examples/general/jsonrpc/go-client/profiles/dev/client.yml +++ b/examples/general/jsonrpc/go-client/profiles/dev/client.yml @@ -7,7 +7,7 @@ request_timeout : "3s" connect_timeout : "3s" # application config -application_config: +application: organization : "ikurento.com" name : "BDTService" module : "dubbogo user-info client" diff --git a/examples/general/jsonrpc/go-client/profiles/release/client.yml b/examples/general/jsonrpc/go-client/profiles/release/client.yml deleted file mode 100644 index 0084e5b04d..0000000000 --- a/examples/general/jsonrpc/go-client/profiles/release/client.yml +++ /dev/null @@ -1,60 +0,0 @@ -# dubbo client yaml configure file - -check: true -# client -request_timeout : "3s" -# connect timeout -connect_timeout : "3s" - -# application config -application_config: - organization : "ikurento.com" - name : "BDTService" - module : "dubbogo user-info client" - version : "0.0.1" - owner : "ZX" - environment : "release" - -registries : - "hangzhouzk": - protocol: "zookeeper" - timeout : "3s" - address: "127.0.0.1:2181" - username: "" - password: "" - "shanghaizk": - protocol: "zookeeper" - timeout : "3s" - address: "127.0.0.1:2182" - username: "" - password: "" - -references: - "UserProvider": - # 可以指定多个registry,使用逗号隔开;不指定默认向所有注册中心注册 - registry: "hangzhouzk" - protocol : "jsonrpc" - interface : "com.ikurento.user.UserProvider" - cluster: "failover" - methods : - - name: "GetUser" - retries: 3 - "UserProvider1": - registry: "hangzhouzk" - protocol: "jsonrpc" - version : "2.0" - interface: "com.ikurento.user.UserProvider" - cluster: "failover" - methods: - - name: "GetUser" - retries: 3 - "UserProvider2": - registry: "hangzhouzk" - protocol: "jsonrpc" - version : "2.0" - group: "as" - interface: "com.ikurento.user.UserProvider" - cluster: "failover" - methods: - - name: "GetUser" - retries: 3 diff --git a/examples/general/jsonrpc/go-client/profiles/release/log.yml b/examples/general/jsonrpc/go-client/profiles/release/log.yml deleted file mode 100644 index e0514be020..0000000000 --- a/examples/general/jsonrpc/go-client/profiles/release/log.yml +++ /dev/null @@ -1,28 +0,0 @@ - -level: "warn" -development: true -disableCaller: true -disableStacktrace: true -sampling: -encoding: "console" - -# encoder -encoderConfig: - messageKey: "message" - levelKey: "level" - timeKey: "time" - nameKey: "logger" - callerKey: "caller" - stacktraceKey: "stacktrace" - lineEnding: "" - levelEncoder: "capitalColor" - timeEncoder: "iso8601" - durationEncoder: "seconds" - callerEncoder: "short" - nameEncoder: "" - -outputPaths: - - "stderr" -errorOutputPaths: - - "stderr" -initialFields: diff --git a/examples/general/jsonrpc/go-client/profiles/test/client.yml b/examples/general/jsonrpc/go-client/profiles/test/client.yml deleted file mode 100644 index 3efdedad4a..0000000000 --- a/examples/general/jsonrpc/go-client/profiles/test/client.yml +++ /dev/null @@ -1,60 +0,0 @@ -# dubbo client yaml configure file - -check: true -# client -request_timeout : "3s" -# connect timeout -connect_timeout : "3s" - -# application config -application_config: - organization : "ikurento.com" - name : "BDTService" - module : "dubbogo user-info client" - version : "0.0.1" - owner : "ZX" - environment : "test" - -registries : - "hangzhouzk": - protocol: "zookeeper" - timeout : "3s" - address: "127.0.0.1:2181" - username: "" - password: "" - "shanghaizk": - protocol: "zookeeper" - timeout : "3s" - address: "127.0.0.1:2182" - username: "" - password: "" - -references: - "UserProvider": - # 可以指定多个registry,使用逗号隔开;不指定默认向所有注册中心注册 - registry: "hangzhouzk" - protocol : "jsonrpc" - interface : "com.ikurento.user.UserProvider" - cluster: "failover" - methods : - - name: "GetUser" - retries: 3 - "UserProvider1": - registry: "hangzhouzk" - protocol: "jsonrpc" - version : "2.0" - interface: "com.ikurento.user.UserProvider" - cluster: "failover" - methods: - - name: "GetUser" - retries: 3 - "UserProvider2": - registry: "hangzhouzk" - protocol: "jsonrpc" - version : "2.0" - group: "as" - interface: "com.ikurento.user.UserProvider" - cluster: "failover" - methods: - - name: "GetUser" - retries: 3 diff --git a/examples/general/jsonrpc/go-client/profiles/test/log.yml b/examples/general/jsonrpc/go-client/profiles/test/log.yml deleted file mode 100644 index baee0b7248..0000000000 --- a/examples/general/jsonrpc/go-client/profiles/test/log.yml +++ /dev/null @@ -1,28 +0,0 @@ - -level: "info" -development: false -disableCaller: false -disableStacktrace: true -sampling: -encoding: "console" - -# encoder -encoderConfig: - messageKey: "message" - levelKey: "level" - timeKey: "time" - nameKey: "logger" - callerKey: "caller" - stacktraceKey: "stacktrace" - lineEnding: "" - levelEncoder: "capitalColor" - timeEncoder: "iso8601" - durationEncoder: "seconds" - callerEncoder: "short" - nameEncoder: "" - -outputPaths: - - "stderr" -errorOutputPaths: - - "stderr" -initialFields: diff --git a/examples/general/jsonrpc/go-server/profiles/dev/server.yml b/examples/general/jsonrpc/go-server/profiles/dev/server.yml index 4d74d2ef6f..e5983dcfc2 100644 --- a/examples/general/jsonrpc/go-server/profiles/dev/server.yml +++ b/examples/general/jsonrpc/go-server/profiles/dev/server.yml @@ -1,7 +1,7 @@ # dubbo server yaml configure file # application config -application_config: +application: organization : "ikurento.com" name : "BDTService" module : "dubbogo user-info server" diff --git a/examples/general/jsonrpc/go-server/profiles/release/log.yml b/examples/general/jsonrpc/go-server/profiles/release/log.yml deleted file mode 100644 index e0514be020..0000000000 --- a/examples/general/jsonrpc/go-server/profiles/release/log.yml +++ /dev/null @@ -1,28 +0,0 @@ - -level: "warn" -development: true -disableCaller: true -disableStacktrace: true -sampling: -encoding: "console" - -# encoder -encoderConfig: - messageKey: "message" - levelKey: "level" - timeKey: "time" - nameKey: "logger" - callerKey: "caller" - stacktraceKey: "stacktrace" - lineEnding: "" - levelEncoder: "capitalColor" - timeEncoder: "iso8601" - durationEncoder: "seconds" - callerEncoder: "short" - nameEncoder: "" - -outputPaths: - - "stderr" -errorOutputPaths: - - "stderr" -initialFields: diff --git a/examples/general/jsonrpc/go-server/profiles/release/server.yml b/examples/general/jsonrpc/go-server/profiles/release/server.yml deleted file mode 100644 index 3f7d2fdfff..0000000000 --- a/examples/general/jsonrpc/go-server/profiles/release/server.yml +++ /dev/null @@ -1,75 +0,0 @@ -# dubbo server yaml configure file - -# application config -application_config: - organization : "ikurento.com" - name : "BDTService" - module : "dubbogo user-info server" - version : "0.0.1" - owner : "ZX" - environment : "release" - -registries : - "hangzhouzk": - protocol: "zookeeper" - timeout : "3s" - address: "127.0.0.1:2181" - username: "" - password: "" - "shanghaizk": - protocol: "zookeeper" - timeout : "3s" - address: "127.0.0.1:2182" - username: "" - password: "" - - -services: - "UserProvider": - # 可以指定多个registry,使用逗号隔开;不指定默认向所有注册中心注册 - registry: "hangzhouzk" - protocol : "jsonrpc" - # 相当于dubbo.xml中的interface - interface : "com.ikurento.user.UserProvider" - loadbalance: "random" - warmup: "100" - cluster: "failover" - methods: - - name: "GetUser" - retries: 1 - loadbalance: "random" - "UserProvider1": - registry: "hangzhouzk" - protocol: "jsonrpc" - interface: "com.ikurento.user.UserProvider" - loadbalance: "random" - version: "2.0" - warmup: "100" - cluster: "failover" - methods: - - name: "GetUser" - retries: 1 - loadbalance: "random" - "UserProvider2": - registry: "hangzhouzk" - protocol: "jsonrpc" - interface: "com.ikurento.user.UserProvider" - loadbalance: "random" - version: "2.0" - group: "as" - warmup: "100" - cluster: "failover" - methods: - - name: "GetUser" - retries: 1 - loadbalance: "random" - -protocols: - #- name: "dubbo" - # ip : "127.0.0.1" - # port : 20000 - "jsonrpc1": - name: "jsonrpc" - ip: "127.0.0.1" - port: 20001 - diff --git a/examples/general/jsonrpc/go-server/profiles/test/log.yml b/examples/general/jsonrpc/go-server/profiles/test/log.yml deleted file mode 100644 index baee0b7248..0000000000 --- a/examples/general/jsonrpc/go-server/profiles/test/log.yml +++ /dev/null @@ -1,28 +0,0 @@ - -level: "info" -development: false -disableCaller: false -disableStacktrace: true -sampling: -encoding: "console" - -# encoder -encoderConfig: - messageKey: "message" - levelKey: "level" - timeKey: "time" - nameKey: "logger" - callerKey: "caller" - stacktraceKey: "stacktrace" - lineEnding: "" - levelEncoder: "capitalColor" - timeEncoder: "iso8601" - durationEncoder: "seconds" - callerEncoder: "short" - nameEncoder: "" - -outputPaths: - - "stderr" -errorOutputPaths: - - "stderr" -initialFields: diff --git a/examples/general/jsonrpc/go-server/profiles/test/server.yml b/examples/general/jsonrpc/go-server/profiles/test/server.yml deleted file mode 100644 index dd0637e797..0000000000 --- a/examples/general/jsonrpc/go-server/profiles/test/server.yml +++ /dev/null @@ -1,75 +0,0 @@ -# dubbo server yaml configure file - -# application config -application_config: - organization : "ikurento.com" - name : "BDTService" - module : "dubbogo user-info server" - version : "0.0.1" - owner : "ZX" - environment : "test" - -registries : - "hangzhouzk": - protocol: "zookeeper" - timeout : "3s" - address: "127.0.0.1:2181" - username: "" - password: "" - "shanghaizk": - protocol: "zookeeper" - timeout : "3s" - address: "127.0.0.1:2182" - username: "" - password: "" - - -services: - "UserProvider": - # 可以指定多个registry,使用逗号隔开;不指定默认向所有注册中心注册 - registry: "hangzhouzk" - protocol : "jsonrpc" - # 相当于dubbo.xml中的interface - interface : "com.ikurento.user.UserProvider" - loadbalance: "random" - warmup: "100" - cluster: "failover" - methods: - - name: "GetUser" - retries: 1 - loadbalance: "random" - "UserProvider1": - registry: "hangzhouzk" - protocol: "jsonrpc" - interface: "com.ikurento.user.UserProvider" - loadbalance: "random" - version: "2.0" - warmup: "100" - cluster: "failover" - methods: - - name: "GetUser" - retries: 1 - loadbalance: "random" - "UserProvider2": - registry: "hangzhouzk" - protocol: "jsonrpc" - interface: "com.ikurento.user.UserProvider" - loadbalance: "random" - version: "2.0" - group: "as" - warmup: "100" - cluster: "failover" - methods: - - name: "GetUser" - retries: 1 - loadbalance: "random" - -protocols: - #- name: "dubbo" - # ip : "127.0.0.1" - # port : 20000 - "jsonrpc1": - name: "jsonrpc" - ip: "127.0.0.1" - port: 20001 - diff --git a/examples/generic/go-client/profiles/dev/client.yml b/examples/generic/go-client/profiles/dev/client.yml index f4e3180aa8..26752fb256 100644 --- a/examples/generic/go-client/profiles/dev/client.yml +++ b/examples/generic/go-client/profiles/dev/client.yml @@ -8,7 +8,7 @@ request_timeout : "3s" connect_timeout : "3s" # application config -application_config: +application: organization : "ikurento.com" name : "BDTService" module : "dubbogo genric client" diff --git a/examples/generic/go-client/profiles/release/client.yml b/examples/generic/go-client/profiles/release/client.yml deleted file mode 100644 index 5a21bca6c9..0000000000 --- a/examples/generic/go-client/profiles/release/client.yml +++ /dev/null @@ -1,55 +0,0 @@ -# dubbo client yaml configure file - - -check: true -# client -request_timeout : "3s" -# connect timeout -connect_timeout : "3s" - -# application config -application_config: - organization : "ikurento.com" - name : "BDTService" - module : "dubbogo generic client" - version : "0.0.1" - owner : "ZX" - environment : "release" - -registries : - "hangzhouzk": - protocol: "zookeeper" - timeout : "3s" - address: "127.0.0.1:2181" - username: "" - password: "" - "shanghaizk": - protocol: "zookeeper" - timeout : "3s" - address: "127.0.0.1:2182" - username: "" - password: "" - -references: - -protocol_conf: - dubbo: - reconnect_interval: 0 - connection_number: 2 - heartbeat_period: "5s" - session_timeout: "20s" - pool_size: 64 - pool_ttl: 600 - getty_session_param: - compress_encoding: false - tcp_no_delay: true - tcp_keep_alive: true - keep_alive_period: "120s" - tcp_r_buf_size: 262144 - tcp_w_buf_size: 65536 - pkg_wq_size: 512 - tcp_read_timeout: "1s" - tcp_write_timeout: "5s" - wait_timeout: "1s" - max_msg_len: 10240 - session_name: "client" diff --git a/examples/generic/go-client/profiles/release/log.yml b/examples/generic/go-client/profiles/release/log.yml deleted file mode 100644 index e0514be020..0000000000 --- a/examples/generic/go-client/profiles/release/log.yml +++ /dev/null @@ -1,28 +0,0 @@ - -level: "warn" -development: true -disableCaller: true -disableStacktrace: true -sampling: -encoding: "console" - -# encoder -encoderConfig: - messageKey: "message" - levelKey: "level" - timeKey: "time" - nameKey: "logger" - callerKey: "caller" - stacktraceKey: "stacktrace" - lineEnding: "" - levelEncoder: "capitalColor" - timeEncoder: "iso8601" - durationEncoder: "seconds" - callerEncoder: "short" - nameEncoder: "" - -outputPaths: - - "stderr" -errorOutputPaths: - - "stderr" -initialFields: diff --git a/examples/generic/go-client/profiles/test/client.yml b/examples/generic/go-client/profiles/test/client.yml deleted file mode 100644 index 7442c64c71..0000000000 --- a/examples/generic/go-client/profiles/test/client.yml +++ /dev/null @@ -1,55 +0,0 @@ -# dubbo client yaml configure file - - -check: true -# client -request_timeout : "3s" -# connect timeout -connect_timeout : "3s" - -# application config -application_config: - organization : "ikurento.com" - name : "BDTService" - module : "dubbogo user-info client" - version : "0.0.1" - owner : "ZX" - environment : "test" - -registries : - "hangzhouzk": - protocol: "zookeeper" - timeout : "3s" - address: "127.0.0.1:2181" - username: "" - password: "" - "shanghaizk": - protocol: "zookeeper" - timeout : "3s" - address: "127.0.0.1:2182" - username: "" - password: "" - -references: - -protocol_conf: - dubbo: - reconnect_interval: 0 - connection_number: 2 - heartbeat_period: "5s" - session_timeout: "20s" - pool_size: 64 - pool_ttl: 600 - getty_session_param: - compress_encoding: false - tcp_no_delay: true - tcp_keep_alive: true - keep_alive_period: "120s" - tcp_r_buf_size: 262144 - tcp_w_buf_size: 65536 - pkg_wq_size: 512 - tcp_read_timeout: "1s" - tcp_write_timeout: "5s" - wait_timeout: "1s" - max_msg_len: 10240 - session_name: "client" diff --git a/examples/generic/go-client/profiles/test/log.yml b/examples/generic/go-client/profiles/test/log.yml deleted file mode 100644 index baee0b7248..0000000000 --- a/examples/generic/go-client/profiles/test/log.yml +++ /dev/null @@ -1,28 +0,0 @@ - -level: "info" -development: false -disableCaller: false -disableStacktrace: true -sampling: -encoding: "console" - -# encoder -encoderConfig: - messageKey: "message" - levelKey: "level" - timeKey: "time" - nameKey: "logger" - callerKey: "caller" - stacktraceKey: "stacktrace" - lineEnding: "" - levelEncoder: "capitalColor" - timeEncoder: "iso8601" - durationEncoder: "seconds" - callerEncoder: "short" - nameEncoder: "" - -outputPaths: - - "stderr" -errorOutputPaths: - - "stderr" -initialFields: diff --git a/examples/helloworld/dubbo/go-client/profiles/dev/client.yml b/examples/helloworld/dubbo/go-client/profiles/dev/client.yml index fed05b0973..8a318fd040 100644 --- a/examples/helloworld/dubbo/go-client/profiles/dev/client.yml +++ b/examples/helloworld/dubbo/go-client/profiles/dev/client.yml @@ -8,7 +8,7 @@ request_timeout : "3s" connect_timeout : "3s" # application config -application_config: +application: organization : "ikurento.com" name : "BDTService" module : "dubbogo user-info client" diff --git a/examples/helloworld/dubbo/go-client/profiles/release/client.yml b/examples/helloworld/dubbo/go-client/profiles/release/client.yml deleted file mode 100644 index 02bf722754..0000000000 --- a/examples/helloworld/dubbo/go-client/profiles/release/client.yml +++ /dev/null @@ -1,60 +0,0 @@ -# dubbo client yaml configure file - - -check: true -# client -request_timeout : "3s" -# connect timeout -connect_timeout : "3s" - -# application config -application_config: - organization : "ikurento.com" - name : "BDTService" - module : "dubbogo user-info client" - version : "0.0.1" - owner : "ZX" - environment : "release" - -registries : - "hangzhouzk": - protocol: "zookeeper" - timeout : "3s" - address: "127.0.0.1:2181" - username: "" - password: "" - - -references: - "UserProvider": - # 可以指定多个registry,使用逗号隔开;不指定默认向所有注册中心注册 - registry: "hangzhouzk" - protocol : "dubbo" - interface : "com.ikurento.user.UserProvider" - cluster: "failover" - methods : - - name: "GetUser" - retries: 3 - -protocol_conf: - dubbo: - reconnect_interval: 0 - connection_number: 2 - heartbeat_period: "5s" - session_timeout: "20s" - pool_size: 64 - pool_ttl: 600 - getty_session_param: - compress_encoding: false - tcp_no_delay: true - tcp_keep_alive: true - keep_alive_period: "120s" - tcp_r_buf_size: 262144 - tcp_w_buf_size: 65536 - pkg_rq_size: 1024 - pkg_wq_size: 512 - tcp_read_timeout: "1s" - tcp_write_timeout: "5s" - wait_timeout: "1s" - max_msg_len: 10240 - session_name: "client" diff --git a/examples/helloworld/dubbo/go-client/profiles/release/log.yml b/examples/helloworld/dubbo/go-client/profiles/release/log.yml deleted file mode 100644 index e0514be020..0000000000 --- a/examples/helloworld/dubbo/go-client/profiles/release/log.yml +++ /dev/null @@ -1,28 +0,0 @@ - -level: "warn" -development: true -disableCaller: true -disableStacktrace: true -sampling: -encoding: "console" - -# encoder -encoderConfig: - messageKey: "message" - levelKey: "level" - timeKey: "time" - nameKey: "logger" - callerKey: "caller" - stacktraceKey: "stacktrace" - lineEnding: "" - levelEncoder: "capitalColor" - timeEncoder: "iso8601" - durationEncoder: "seconds" - callerEncoder: "short" - nameEncoder: "" - -outputPaths: - - "stderr" -errorOutputPaths: - - "stderr" -initialFields: diff --git a/examples/helloworld/dubbo/go-client/profiles/test/client.yml b/examples/helloworld/dubbo/go-client/profiles/test/client.yml deleted file mode 100644 index 417a388c6c..0000000000 --- a/examples/helloworld/dubbo/go-client/profiles/test/client.yml +++ /dev/null @@ -1,59 +0,0 @@ -# dubbo client yaml configure file - - -check: true -# client -request_timeout : "3s" -# connect timeout -connect_timeout : "3s" - -# application config -application_config: - organization : "ikurento.com" - name : "BDTService" - module : "dubbogo user-info client" - version : "0.0.1" - owner : "ZX" - environment : "test" - -registries : - "hangzhouzk": - protocol: "zookeeper" - timeout : "3s" - address: "127.0.0.1:2181" - username: "" - password: "" - -references: - "UserProvider": - # 可以指定多个registry,使用逗号隔开;不指定默认向所有注册中心注册 - registry: "hangzhouzk" - protocol : "dubbo" - interface : "com.ikurento.user.UserProvider" - cluster: "failover" - methods : - - name: "GetUser" - retries: 3 - -protocol_conf: - dubbo: - reconnect_interval: 0 - connection_number: 2 - heartbeat_period: "5s" - session_timeout: "20s" - pool_size: 64 - pool_ttl: 600 - getty_session_param: - compress_encoding: false - tcp_no_delay: true - tcp_keep_alive: true - keep_alive_period: "120s" - tcp_r_buf_size: 262144 - tcp_w_buf_size: 65536 - pkg_rq_size: 1024 - pkg_wq_size: 512 - tcp_read_timeout: "1s" - tcp_write_timeout: "5s" - wait_timeout: "1s" - max_msg_len: 10240 - session_name: "client" diff --git a/examples/helloworld/dubbo/go-client/profiles/test/log.yml b/examples/helloworld/dubbo/go-client/profiles/test/log.yml deleted file mode 100644 index baee0b7248..0000000000 --- a/examples/helloworld/dubbo/go-client/profiles/test/log.yml +++ /dev/null @@ -1,28 +0,0 @@ - -level: "info" -development: false -disableCaller: false -disableStacktrace: true -sampling: -encoding: "console" - -# encoder -encoderConfig: - messageKey: "message" - levelKey: "level" - timeKey: "time" - nameKey: "logger" - callerKey: "caller" - stacktraceKey: "stacktrace" - lineEnding: "" - levelEncoder: "capitalColor" - timeEncoder: "iso8601" - durationEncoder: "seconds" - callerEncoder: "short" - nameEncoder: "" - -outputPaths: - - "stderr" -errorOutputPaths: - - "stderr" -initialFields: diff --git a/examples/helloworld/dubbo/go-server/profiles/dev/server.yml b/examples/helloworld/dubbo/go-server/profiles/dev/server.yml index be7eedeaa3..ab7f63d7e4 100644 --- a/examples/helloworld/dubbo/go-server/profiles/dev/server.yml +++ b/examples/helloworld/dubbo/go-server/profiles/dev/server.yml @@ -2,7 +2,7 @@ # application config -application_config: +application: organization : "ikurento.com" name : "BDTService" module : "dubbogo user-info server" diff --git a/examples/helloworld/dubbo/go-server/profiles/release/log.yml b/examples/helloworld/dubbo/go-server/profiles/release/log.yml deleted file mode 100644 index e0514be020..0000000000 --- a/examples/helloworld/dubbo/go-server/profiles/release/log.yml +++ /dev/null @@ -1,28 +0,0 @@ - -level: "warn" -development: true -disableCaller: true -disableStacktrace: true -sampling: -encoding: "console" - -# encoder -encoderConfig: - messageKey: "message" - levelKey: "level" - timeKey: "time" - nameKey: "logger" - callerKey: "caller" - stacktraceKey: "stacktrace" - lineEnding: "" - levelEncoder: "capitalColor" - timeEncoder: "iso8601" - durationEncoder: "seconds" - callerEncoder: "short" - nameEncoder: "" - -outputPaths: - - "stderr" -errorOutputPaths: - - "stderr" -initialFields: diff --git a/examples/helloworld/dubbo/go-server/profiles/release/server.yml b/examples/helloworld/dubbo/go-server/profiles/release/server.yml deleted file mode 100644 index 4786e83669..0000000000 --- a/examples/helloworld/dubbo/go-server/profiles/release/server.yml +++ /dev/null @@ -1,62 +0,0 @@ -# dubbo server yaml configure file - - -# application config -application_config: - organization : "ikurento.com" - name : "BDTService" - module : "dubbogo user-info server" - version : "0.0.1" - owner : "ZX" - environment : "release" - -registries : - "hangzhouzk": - protocol: "zookeeper" - timeout : "3s" - address: "127.0.0.1:2181" - username: "" - password: "" - - -services: - "UserProvider": - # 可以指定多个registry,使用逗号隔开;不指定默认向所有注册中心注册 - registry: "hangzhouzk" - protocol : "dubbo" - # 相当于dubbo.xml中的interface - interface : "com.ikurento.user.UserProvider" - loadbalance: "random" - warmup: "100" - cluster: "failover" - methods: - - name: "GetUser" - retries: 1 - loadbalance: "random" - - -protocols: - "dubbo1": - name: "dubbo" - # ip : "127.0.0.1" - port: 20000 - - -protocol_conf: - dubbo: - session_number: 700 - session_timeout: "20s" - getty_session_param: - compress_encoding: false - tcp_no_delay: true - tcp_keep_alive: true - keep_alive_period: "120s" - tcp_r_buf_size: 262144 - tcp_w_buf_size: 65536 - pkg_rq_size: 1024 - pkg_wq_size: 512 - tcp_read_timeout: "1s" - tcp_write_timeout: "5s" - wait_timeout: "1s" - max_msg_len: 1024 - session_name: "server" diff --git a/examples/helloworld/dubbo/go-server/profiles/test/log.yml b/examples/helloworld/dubbo/go-server/profiles/test/log.yml deleted file mode 100644 index baee0b7248..0000000000 --- a/examples/helloworld/dubbo/go-server/profiles/test/log.yml +++ /dev/null @@ -1,28 +0,0 @@ - -level: "info" -development: false -disableCaller: false -disableStacktrace: true -sampling: -encoding: "console" - -# encoder -encoderConfig: - messageKey: "message" - levelKey: "level" - timeKey: "time" - nameKey: "logger" - callerKey: "caller" - stacktraceKey: "stacktrace" - lineEnding: "" - levelEncoder: "capitalColor" - timeEncoder: "iso8601" - durationEncoder: "seconds" - callerEncoder: "short" - nameEncoder: "" - -outputPaths: - - "stderr" -errorOutputPaths: - - "stderr" -initialFields: diff --git a/examples/helloworld/dubbo/go-server/profiles/test/server.yml b/examples/helloworld/dubbo/go-server/profiles/test/server.yml deleted file mode 100644 index ba6eb2b800..0000000000 --- a/examples/helloworld/dubbo/go-server/profiles/test/server.yml +++ /dev/null @@ -1,62 +0,0 @@ -# dubbo server yaml configure file - - -# application config -application_config: - organization : "ikurento.com" - name : "BDTService" - module : "dubbogo user-info server" - version : "0.0.1" - owner : "ZX" - environment : "test" - -registries : - "hangzhouzk": - protocol: "zookeeper" - timeout : "3s" - address: "127.0.0.1:2181" - username: "" - password: "" - - - -services: - "UserProvider": - # 可以指定多个registry,使用逗号隔开;不指定默认向所有注册中心注册 - registry: "hangzhouzk" - protocol : "dubbo" - # 相当于dubbo.xml中的interface - interface : "com.ikurento.user.UserProvider" - loadbalance: "random" - warmup: "100" - cluster: "failover" - methods: - - name: "GetUser" - retries: 1 - loadbalance: "random" - -protocols: - "dubbo1": - name: "dubbo" - # ip : "127.0.0.1" - port: 20000 - - -protocol_conf: - dubbo: - session_number: 700 - session_timeout: "20s" - getty_session_param: - compress_encoding: false - tcp_no_delay: true - tcp_keep_alive: true - keep_alive_period: "120s" - tcp_r_buf_size: 262144 - tcp_w_buf_size: 65536 - pkg_rq_size: 1024 - pkg_wq_size: 512 - tcp_read_timeout: "1s" - tcp_write_timeout: "5s" - wait_timeout: "1s" - max_msg_len: 1024 - session_name: "server" diff --git a/examples/hystrixfilter/dubbo/with-hystrix-go-client/profiles/dev/client.yml b/examples/hystrixfilter/dubbo/with-hystrix-go-client/profiles/dev/client.yml index 5b5003fb2c..71b0c2bf1c 100644 --- a/examples/hystrixfilter/dubbo/with-hystrix-go-client/profiles/dev/client.yml +++ b/examples/hystrixfilter/dubbo/with-hystrix-go-client/profiles/dev/client.yml @@ -8,7 +8,7 @@ request_timeout : "3s" connect_timeout : "3s" # application config -application_config: +application: organization : "ikurento.com" name : "BDTService" module : "dubbogo user-info client" diff --git a/examples/hystrixfilter/dubbo/with-hystrix-go-client/profiles/release/client.yml b/examples/hystrixfilter/dubbo/with-hystrix-go-client/profiles/release/client.yml deleted file mode 100644 index 9263f2d01f..0000000000 --- a/examples/hystrixfilter/dubbo/with-hystrix-go-client/profiles/release/client.yml +++ /dev/null @@ -1,98 +0,0 @@ -# dubbo client yaml configure file - - -check: true -# client -request_timeout : "3s" -# connect timeout -connect_timeout : "3s" - -# application config -application_config: - organization : "ikurento.com" - name : "BDTService" - module : "dubbogo user-info client" - version : "0.0.1" - owner : "ZX" - environment : "release" - -registries : - "hangzhouzk": - protocol: "zookeeper" - timeout : "3s" - address: "127.0.0.1:2181" - username: "" - password: "" - "shanghaizk": - protocol: "zookeeper" - timeout : "3s" - address: "127.0.0.1:2182" - username: "" - password: "" - -references: - "UserProvider": - # 可以指定多个registry,使用逗号隔开;不指定默认向所有注册中心注册 - registry: "hangzhouzk" - filter: "example_fallback,hystrix_consumer" - protocol : "dubbo" -# version: "2.0" -# group: "as" - interface : "com.ikurento.user.UserProvider" - cluster: "failover" - methods : - - name: "GetUser" - retries: 3 - -protocol_conf: - dubbo: - reconnect_interval: 0 - connection_number: 2 - heartbeat_period: "5s" - session_timeout: "20s" - fail_fast_timeout: "5s" - pool_size: 64 - pool_ttl: 600 - getty_session_param: - compress_encoding: false - tcp_no_delay: true - tcp_keep_alive: true - keep_alive_period: "120s" - tcp_r_buf_size: 262144 - tcp_w_buf_size: 65536 - pkg_rq_size: 1024 - pkg_wq_size: 512 - tcp_read_timeout: "1s" - tcp_write_timeout: "5s" - wait_timeout: "1s" - max_msg_len: 10240 - session_name: "client" - -filter_conf: - hystrix: - configs: - "Default": - timeout : 1000 - max_concurrent_requests : 10 - sleep_window : 5000 - error_percent_threshold : 50 - request_volume_threshold: 20 - "userp": - timeout: 1200 - max_concurrent_requests: 8 - sleep_window: 4000 - error_percent_threshold: 45 - request_volume_threshold: 15 - "userp_m": - timeout : 1200 - max_concurrent_requests : 12 - sleep_window : 6000 - error_percent_threshold : 60 - request_volume_threshold: 30 - fallback: "exampleFallback" - default: "Default" - services: - "com.ikurento.user.UserProvider": - service_config: "userp" - methods: - "GetUser": "userp_m" diff --git a/examples/hystrixfilter/dubbo/with-hystrix-go-client/profiles/release/log.yml b/examples/hystrixfilter/dubbo/with-hystrix-go-client/profiles/release/log.yml deleted file mode 100644 index d8606247b8..0000000000 --- a/examples/hystrixfilter/dubbo/with-hystrix-go-client/profiles/release/log.yml +++ /dev/null @@ -1,28 +0,0 @@ - -level: "warn" -development: true -disableCaller: true -disableStacktrace: true -sampling: -encoding: "console" - -# encoder -encoderConfig: - messageKey: "message" - levelKey: "level" - timeKey: "time" - nameKey: "logger" - callerKey: "caller" - stacktraceKey: "stacktrace" - lineEnding: "" - levelEncoder: "capitalColor" - timeEncoder: "iso8601" - durationEncoder: "seconds" - callerEncoder: "short" - nameEncoder: "" - -outputPaths: - - "stderr" -errorOutputPaths: - - "stderr" -initialFields: diff --git a/examples/hystrixfilter/dubbo/with-hystrix-go-client/profiles/test/client.yml b/examples/hystrixfilter/dubbo/with-hystrix-go-client/profiles/test/client.yml deleted file mode 100644 index 048703b6bb..0000000000 --- a/examples/hystrixfilter/dubbo/with-hystrix-go-client/profiles/test/client.yml +++ /dev/null @@ -1,99 +0,0 @@ -# dubbo client yaml configure file - - -check: true -# client -request_timeout : "3s" -# connect timeout -connect_timeout : "3s" - -# application config -application_config: - organization : "ikurento.com" - name : "BDTService" - module : "dubbogo user-info client" - version : "0.0.1" - owner : "ZX" - environment : "test" - -registries : - "hangzhouzk": - protocol: "zookeeper" - timeout : "3s" - address: "127.0.0.1:2181" - username: "" - password: "" - "shanghaizk": - protocol: "zookeeper" - timeout : "3s" - address: "127.0.0.1:2182" - username: "" - password: "" - -references: - "UserProvider": - # 可以指定多个registry,使用逗号隔开;不指定默认向所有注册中心注册 - registry: "hangzhouzk" - filter: "example_fallback,hystrix_consumer" - protocol : "dubbo" -# version: "2.0" -# group: "as" - interface : "com.ikurento.user.UserProvider" - cluster: "failover" - methods : - - name: "GetUser" - retries: 3 - -protocol_conf: - dubbo: - reconnect_interval: 0 - connection_number: 2 - heartbeat_period: "5s" - session_timeout: "20s" - fail_fast_timeout: "5s" - pool_size: 64 - pool_ttl: 600 - getty_session_param: - compress_encoding: false - tcp_no_delay: true - tcp_keep_alive: true - keep_alive_period: "120s" - tcp_r_buf_size: 262144 - tcp_w_buf_size: 65536 - pkg_rq_size: 1024 - pkg_wq_size: 512 - tcp_read_timeout: "1s" - tcp_write_timeout: "5s" - wait_timeout: "1s" - max_msg_len: 10240 - session_name: "client" - -filter_conf: - hystrix: - configs: - "Default": - timeout : 1000 - max_concurrent_requests : 25 - sleep_window : 5000 - error_percent_threshold : 50 - request_volume_threshold: 20 - "userp": - timeout: 2000 - max_concurrent_requests: 512 - sleep_window: 4000 - error_percent_threshold: 35 - request_volume_threshold: 6 - "userp_m": - timeout : 1200 - max_concurrent_requests : 512 - sleep_window : 6000 - error_percent_threshold : 60 - request_volume_threshold: 16 - error_whitelist: [".*exception.*"] - default: "Default" - services: - "com.ikurento.user.UserProvider": - service_config: "userp" - methods: - "GetUser": "userp_m" - "GetUser1": "userp_m" \ No newline at end of file diff --git a/examples/hystrixfilter/dubbo/with-hystrix-go-client/profiles/test/log.yml b/examples/hystrixfilter/dubbo/with-hystrix-go-client/profiles/test/log.yml deleted file mode 100644 index f93d3c7fcc..0000000000 --- a/examples/hystrixfilter/dubbo/with-hystrix-go-client/profiles/test/log.yml +++ /dev/null @@ -1,28 +0,0 @@ - -level: "info" -development: false -disableCaller: false -disableStacktrace: true -sampling: -encoding: "console" - -# encoder -encoderConfig: - messageKey: "message" - levelKey: "level" - timeKey: "time" - nameKey: "logger" - callerKey: "caller" - stacktraceKey: "stacktrace" - lineEnding: "" - levelEncoder: "capitalColor" - timeEncoder: "iso8601" - durationEncoder: "seconds" - callerEncoder: "short" - nameEncoder: "" - -outputPaths: - - "stderr" -errorOutputPaths: - - "stderr" -initialFields: diff --git a/examples/jsonrpc/with-configcenter-go-client/dubbo.client.properties b/examples/jsonrpc/with-configcenter-go-client/dubbo.client.properties deleted file mode 100644 index c7e6e0e3dd..0000000000 --- a/examples/jsonrpc/with-configcenter-go-client/dubbo.client.properties +++ /dev/null @@ -1,15 +0,0 @@ -dubbo.consumer.check=true -dubbo.consumer.request_timeout=5s -dubbo.consumer.connect_timeout=5s -dubbo.application.organization=ikurento.com -dubbo.application.name=BDTService -dubbo.application.module=dubbogo user-info client -dubbo.application.version=0.0.1 -dubbo.application.owner=ZX1 -dubbo.application.environment=dev -dubbo.registries.hangzhouzk.protocol=zookeeper -dubbo.registries.hangzhouzk.timeout=3s -dubbo.registries.hangzhouzk.address=127.0.0.1:2181 -dubbo.registries.shanghaizk.protocol=zookeeper -dubbo.registries.shanghaizk.timeout=3s -dubbo.registries.shanghaizk.address=127.0.0.1:2182 diff --git a/examples/jsonrpc/with-configcenter-go-server/dubbo.properties b/examples/jsonrpc/with-configcenter-go-server/dubbo.properties deleted file mode 100644 index 7477c41eb5..0000000000 --- a/examples/jsonrpc/with-configcenter-go-server/dubbo.properties +++ /dev/null @@ -1,15 +0,0 @@ -dubbo.application.organization=ikurento.com -dubbo.application.name=BDTService -dubbo.application.module=dubbogo user-info server -dubbo.application.version=0.0.1 -dubbo.application.owner=ZX1 -dubbo.application.environment=dev -dubbo.registries.hangzhouzk.protocol=zookeeper -dubbo.registries.hangzhouzk.timeout=3s -dubbo.registries.hangzhouzk.address=127.0.0.1:2181 -dubbo.registries.shanghaizk.protocol=zookeeper -dubbo.registries.shanghaizk.timeout=3s -dubbo.registries.shanghaizk.address=127.0.0.1:2182 -dubbo.protocols.dubbo1.name=dubbo -dubbo.protocols.dubbo1.ip=127.0.0.1 -dubbo.protocols.dubbo1.port=20001 \ No newline at end of file From 72067dcd41c17d036eeb0febe0fa785472318b29 Mon Sep 17 00:00:00 2001 From: "vito.he" Date: Thu, 12 Sep 2019 16:01:42 +0800 Subject: [PATCH 15/34] Mod:add application name check --- config/config_center_config.go | 2 +- config/config_loader.go | 14 +++++++++++++- config/config_loader_test.go | 2 ++ .../testdata/consumer_config_with_configcenter.yml | 2 ++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/config/config_center_config.go b/config/config_center_config.go index 9a0bd1ee1d..ed43558956 100644 --- a/config/config_center_config.go +++ b/config/config_center_config.go @@ -35,7 +35,7 @@ type ConfigCenterConfig struct { Username string `yaml:"username" json:"username,omitempty"` Password string `yaml:"password" json:"password,omitempty"` ConfigFile string `default:"dubbo.properties" yaml:"config_file" json:"config_file,omitempty"` - AppConfigFile string `yaml:"app_config_file" json:"app_config_file,omitempty"` + AppConfigFile string `default:"dubbo.properties" yaml:"app_config_file" json:"app_config_file,omitempty"` TimeoutStr string `yaml:"timeout" json:"timeout,omitempty"` timeout time.Duration } diff --git a/config/config_loader.go b/config/config_loader.go index 8561828ae0..716e3d089b 100644 --- a/config/config_loader.go +++ b/config/config_loader.go @@ -60,12 +60,21 @@ func checkRegistries(registries map[string]*RegistryConfig, singleRegistry *Regi } } +func checkApplicationName(config *ApplicationConfig) { + if len(config.Name) == 0 { + errMsg := "application config must not be nil, pls check your configuration" + logger.Errorf(errMsg) + panic(errMsg) + } +} + // Dubbo Init func Load() { // reference config if consumerConfig == nil { logger.Warnf("consumerConfig is nil!") } else { + checkApplicationName(consumerConfig.ApplicationConfig) if err := configCenterRefreshConsumer(); err != nil { logger.Errorf("[consumer config center refresh] %#v", err) } @@ -98,7 +107,9 @@ func Load() { checkok = false count++ if count > maxWait { - panic(fmt.Sprintf("Failed to check the status of the service %v . No provider available for the service to the consumer use dubbo version %v", refconfig.InterfaceName, constant.Version)) + errMsg := fmt.Sprintf("Failed to check the status of the service %v . No provider available for the service to the consumer use dubbo version %v", refconfig.InterfaceName, constant.Version) + logger.Error(errMsg) + panic(errMsg) } time.Sleep(time.Second * 1) break @@ -119,6 +130,7 @@ func Load() { if providerConfig == nil { logger.Warnf("providerConfig is nil!") } else { + checkApplicationName(providerConfig.ApplicationConfig) if err := configCenterRefreshProvider(); err != nil { logger.Errorf("[provider config center refresh] %#v", err) } diff --git a/config/config_loader_test.go b/config/config_loader_test.go index 3562bf5a18..498f826780 100644 --- a/config/config_loader_test.go +++ b/config/config_loader_test.go @@ -213,10 +213,12 @@ func TestConfigLoaderWithConfigCenterSingleRegistry(t *testing.T) { assert.Equal(t, ProviderConfig{}, GetProviderConfig()) err = ConsumerInit(conPath) + checkApplicationName(consumerConfig.ApplicationConfig) configCenterRefreshConsumer() checkRegistries(consumerConfig.Registries, consumerConfig.Registry) assert.NoError(t, err) err = ProviderInit(proPath) + checkApplicationName(providerConfig.ApplicationConfig) configCenterRefreshProvider() checkRegistries(providerConfig.Registries, providerConfig.Registry) assert.NoError(t, err) diff --git a/config/testdata/consumer_config_with_configcenter.yml b/config/testdata/consumer_config_with_configcenter.yml index c6505e4492..7ee4ce7029 100644 --- a/config/testdata/consumer_config_with_configcenter.yml +++ b/config/testdata/consumer_config_with_configcenter.yml @@ -1,5 +1,7 @@ # dubbo client yaml configure file +application: + name: "BDTService" config_center: protocol: "mock" address: "127.0.0.1" From 8bfd6b1573ef5b9ca0d0342b54829ca0d6b9a78e Mon Sep 17 00:00:00 2001 From: "vito.he" Date: Thu, 12 Sep 2019 16:05:32 +0800 Subject: [PATCH 16/34] Mod:add application name check --- config/config_loader.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/config_loader.go b/config/config_loader.go index 716e3d089b..0b48761fd6 100644 --- a/config/config_loader.go +++ b/config/config_loader.go @@ -61,7 +61,7 @@ func checkRegistries(registries map[string]*RegistryConfig, singleRegistry *Regi } func checkApplicationName(config *ApplicationConfig) { - if len(config.Name) == 0 { + if config == nil || len(config.Name) == 0 { errMsg := "application config must not be nil, pls check your configuration" logger.Errorf(errMsg) panic(errMsg) From 8a72be85e4c55ac5b1ff99fc4f1d1f14b8c8ae78 Mon Sep 17 00:00:00 2001 From: "vito.he" Date: Thu, 12 Sep 2019 17:59:59 +0800 Subject: [PATCH 17/34] Add:config center service_config & reference_config id --- config/base_config.go | 45 +++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/config/base_config.go b/config/base_config.go index e51d8b9550..264eeda3cc 100644 --- a/config/base_config.go +++ b/config/base_config.go @@ -109,14 +109,10 @@ func (c *BaseConfig) prepareEnvironment() error { return nil } -func getKeyPrefix(val reflect.Value, id reflect.Value) []string { +func getKeyPrefix(val reflect.Value) []string { var ( prefix string - idStr string ) - if id.Kind() == reflect.String { - idStr = id.Interface().(string) - } if val.CanAddr() { prefix = val.Addr().MethodByName("Prefix").Call(nil)[0].String() @@ -126,11 +122,9 @@ func getKeyPrefix(val reflect.Value, id reflect.Value) []string { var retPrefixs []string for _, pfx := range strings.Split(prefix, "|") { - if idStr != "" { - retPrefixs = append(retPrefixs, pfx+idStr+".") - } else { - retPrefixs = append(retPrefixs, pfx) - } + + retPrefixs = append(retPrefixs, pfx) + } return retPrefixs @@ -150,14 +144,37 @@ func setFieldValue(val reflect.Value, id reflect.Value, config *config.InmemoryC f := val.Field(i) if f.IsValid() { setBaseValue := func(f reflect.Value) { - var ok bool - var value string - prefixs := getKeyPrefix(val, id) + + var ( + ok bool + value string + idStr string + ) + + prefixs := getKeyPrefix(val) + + if id.Kind() == reflect.String { + idStr = id.Interface().(string) + } + for _, pfx := range prefixs { - ok, value = config.GetProperty(pfx + key) + + if len(pfx) > 0 { + if len(idStr) > 0 { + ok, value = config.GetProperty(pfx + idStr + "." + key) + } + if len(value) == 0 || !ok { + ok, value = config.GetProperty(pfx + key) + } + + } else { + ok, value = config.GetProperty(key) + } + if ok { break } + } if ok { switch f.Kind() { From ddf2e270055d4234eb27099a3aaf12e0981770de Mon Sep 17 00:00:00 2001 From: "vito.he" Date: Thu, 12 Sep 2019 18:03:50 +0800 Subject: [PATCH 18/34] Add:config center service_config & reference_config id ut --- config/base_config_test.go | 96 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/config/base_config_test.go b/config/base_config_test.go index 239bece475..4180247637 100644 --- a/config/base_config_test.go +++ b/config/base_config_test.go @@ -130,6 +130,102 @@ func Test_appExternal_refresh(t *testing.T) { mockMap := map[string]string{} mockMap["dubbo.registries.shanghai_reg1.protocol"] = "mock100" mockMap["dubbo.reference.com.MockService.MockService.retries"] = "10" + mockMap["dubbo.reference.com.MockService.retries"] = "5" + mockMap["dubbo.com.MockService.MockService.GetUser.retries"] = "10" + mockMap["dubbo.consumer.check"] = "false" + mockMap["dubbo.application.name"] = "dubbo" + + config.GetEnvInstance().UpdateAppExternalConfigMap(mockMap) + mockMap["dubbo.consumer.check"] = "true" + config.GetEnvInstance().UpdateExternalConfigMap(mockMap) + father := &ConsumerConfig{ + Check: &[]bool{true}[0], + ApplicationConfig: &ApplicationConfig{ + Organization: "dubbo_org", + Name: "dubbo", + Module: "module", + Version: "2.6.0", + Owner: "dubbo", + Environment: "test"}, + Registries: map[string]*RegistryConfig{ + //"shanghai_reg1": { + // id: "shanghai_reg1", + // Protocol: "mock", + // TimeoutStr: "2s", + // Group: "shanghai_idc", + // Address: "127.0.0.1:2181", + // Username: "user1", + // Password: "pwd1", + //}, + "shanghai_reg2": { + Protocol: "mock", + TimeoutStr: "2s", + Group: "shanghai_idc", + Address: "127.0.0.2:2181", + Username: "user1", + Password: "pwd1", + }, + "hangzhou_reg1": { + Protocol: "mock", + TimeoutStr: "2s", + Group: "hangzhou_idc", + Address: "127.0.0.3:2181", + Username: "user1", + Password: "pwd1", + }, + "hangzhou_reg2": { + Protocol: "mock", + TimeoutStr: "2s", + Group: "hangzhou_idc", + Address: "127.0.0.4:2181", + Username: "user1", + Password: "pwd1", + }, + }, + References: map[string]*ReferenceConfig{ + "MockService": { + InterfaceName: "com.MockService", + Protocol: "mock", + Cluster: "failover", + Loadbalance: "random", + Retries: 3, + Group: "huadong_idc", + Version: "1.0.0", + Methods: []*MethodConfig{ + { + InterfaceId: "MockService", + InterfaceName: "com.MockService", + Name: "GetUser", + Retries: 2, + Loadbalance: "random", + }, + { + InterfaceId: "MockService", + InterfaceName: "com.MockService", + Name: "GetUser1", + Retries: 2, + Loadbalance: "random", + }, + }, + }, + }, + } + + c.SetFatherConfig(father) + c.fresh() + assert.Equal(t, "mock100", father.Registries["shanghai_reg1"].Protocol) + assert.Equal(t, int64(10), father.References["MockService"].Retries) + + assert.Equal(t, int64(10), father.References["MockService"].Methods[0].Retries) + assert.Equal(t, &[]bool{true}[0], father.Check) + assert.Equal(t, "dubbo", father.ApplicationConfig.Name) +} + +func Test_appExternalWithoutId_refresh(t *testing.T) { + c := &BaseConfig{} + mockMap := map[string]string{} + mockMap["dubbo.registries.shanghai_reg1.protocol"] = "mock100" + mockMap["dubbo.reference.com.MockService.retries"] = "10" mockMap["dubbo.com.MockService.MockService.GetUser.retries"] = "10" mockMap["dubbo.consumer.check"] = "false" mockMap["dubbo.application.name"] = "dubbo" From 53bce2d6b8678251efb85abf6164163575d85ad7 Mon Sep 17 00:00:00 2001 From: justimkiss Date: Tue, 17 Sep 2019 13:47:08 +0800 Subject: [PATCH 19/34] fix issue:204 --- protocol/dubbo/client.go | 2 +- protocol/dubbo/server.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/protocol/dubbo/client.go b/protocol/dubbo/client.go index 2cec5aa8fa..4927f51cf7 100644 --- a/protocol/dubbo/client.go +++ b/protocol/dubbo/client.go @@ -59,7 +59,7 @@ func init() { return } dubboConf := protocolConf.(map[interface{}]interface{})[DUBBO] - if protocolConf == nil { + if dubboConf == nil { logger.Warnf("dubboConf is nil") return } diff --git a/protocol/dubbo/server.go b/protocol/dubbo/server.go index 8daeee05e2..5f93a794d2 100644 --- a/protocol/dubbo/server.go +++ b/protocol/dubbo/server.go @@ -48,7 +48,7 @@ func init() { return } dubboConf := protocolConf.(map[interface{}]interface{})[DUBBO] - if protocolConf == nil { + if dubboConf == nil { logger.Warnf("dubboConf is nil") return } From 1d8580676dc26edba47b86c1f7507fa352de8e1e Mon Sep 17 00:00:00 2001 From: xujianhai666 Date: Thu, 12 Sep 2019 06:51:38 +0800 Subject: [PATCH 20/34] add token support --- common/constant/default.go | 2 +- common/constant/key.go | 1 + common/url.go | 13 +++ config/service_config.go | 6 +- .../dubbo/go-server/profiles/dev/server.yml | 1 + filter/impl/token_filter.go | 68 +++++++++++++++ filter/impl/token_filter_test.go | 85 +++++++++++++++++++ go.mod | 1 + protocol/dubbo/dubbo_invoker.go | 18 ++++ 9 files changed, 193 insertions(+), 2 deletions(-) create mode 100644 filter/impl/token_filter.go create mode 100644 filter/impl/token_filter_test.go diff --git a/common/constant/default.go b/common/constant/default.go index d937fcb3ed..405920e20f 100644 --- a/common/constant/default.go +++ b/common/constant/default.go @@ -46,7 +46,7 @@ const ( const ( DEFAULT_KEY = "default" PREFIX_DEFAULT_KEY = "default." - DEFAULT_SERVICE_FILTERS = "echo" + DEFAULT_SERVICE_FILTERS = "echo,token" DEFAULT_REFERENCE_FILTERS = "" GENERIC_REFERENCE_FILTERS = "generic" GENERIC = "$invoke" diff --git a/common/constant/key.go b/common/constant/key.go index 1b25d11edc..abb78c987b 100644 --- a/common/constant/key.go +++ b/common/constant/key.go @@ -37,6 +37,7 @@ const ( BEAN_NAME_KEY = "bean.name" GENERIC_KEY = "generic" CLASSIFIER_KEY = "classifier" + TOKEN_KEY = "token" ) const ( diff --git a/common/url.go b/common/url.go index 9f5b50264a..bf58ca188c 100644 --- a/common/url.go +++ b/common/url.go @@ -34,6 +34,7 @@ import ( "github.com/dubbogo/gost/container" "github.com/jinzhu/copier" perrors "github.com/pkg/errors" + "github.com/satori/go.uuid" ) import ( @@ -150,6 +151,18 @@ func WithLocation(location string) option { } } +func WithToken(token string) option { + return func(url *URL) { + if len(token) > 0 { + value := token + if strings.ToLower(token) == "true" || strings.ToLower(token) == "default" { + value = uuid.NewV4().String() + } + url.SetParam(constant.TOKEN_KEY, value) + } + } +} + func NewURLWithOptions(opts ...option) *URL { url := &URL{} for _, opt := range opts { diff --git a/config/service_config.go b/config/service_config.go index df6b8d1839..ce15c61eb3 100644 --- a/config/service_config.go +++ b/config/service_config.go @@ -57,6 +57,7 @@ type ServiceConfig struct { Warmup string `yaml:"warmup" json:"warmup,omitempty" property:"warmup"` Retries string `yaml:"retries" json:"retries,omitempty" property:"retries"` Params map[string]string `yaml:"params" json:"params,omitempty" property:"params"` + Token string `yaml:"token" json:"token,omitempty" property:"token"` unexported *atomic.Bool exported *atomic.Bool rpcService common.RPCService @@ -122,7 +123,10 @@ func (srvconfig *ServiceConfig) Export() error { common.WithPort(proto.Port), common.WithParams(urlMap), common.WithParamsValue(constant.BEAN_NAME_KEY, srvconfig.id), - common.WithMethods(strings.Split(methods, ","))) + common.WithMethods(strings.Split(methods, ",")), + common.WithToken(srvconfig.Token), + ) + if len(regUrls) > 0 { for _, regUrl := range regUrls { regUrl.SubURL = url diff --git a/examples/helloworld/dubbo/go-server/profiles/dev/server.yml b/examples/helloworld/dubbo/go-server/profiles/dev/server.yml index 27e9d55c8d..8e8594a1ce 100644 --- a/examples/helloworld/dubbo/go-server/profiles/dev/server.yml +++ b/examples/helloworld/dubbo/go-server/profiles/dev/server.yml @@ -30,6 +30,7 @@ services: - name: "GetUser" retries: "1" loadbalance: "random" + token: "true" protocols: "dubbo": diff --git a/filter/impl/token_filter.go b/filter/impl/token_filter.go new file mode 100644 index 0000000000..6b658bed7c --- /dev/null +++ b/filter/impl/token_filter.go @@ -0,0 +1,68 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You 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 impl + +import ( + "strings" +) + +import ( + perrors "github.com/pkg/errors" +) + +import ( + "github.com/apache/dubbo-go/common/constant" + "github.com/apache/dubbo-go/coconfig/service_config.gommon/extension" + "github.com/apache/dubbo-go/filter" + "github.com/apache/dubbo-go/protocol" +) + +const ( + token = "token" +) + +func init() { + extension.SetFilter(token, GetTokenFilter) +} + +type TokenFilter struct{} + +func (tf *TokenFilter) Invoke(invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result { + invokerTkn := invoker.GetUrl().GetParam(constant.TOKEN_KEY, "") + if len(invokerTkn) > 0 { + attachs := invocation.Attachments() + if len(attachs) > 0 { + remoteTkn, exist := attachs[constant.TOKEN_KEY] + if exist && strings.EqualFold(invokerTkn, remoteTkn) { + return invoker.Invoke(invocation) + } + } + return &protocol.RPCResult{Err: perrors.Errorf("Invalid token! Forbid invoke remote service %s method %s ", + invoker, invocation.MethodName())} + } + + return invoker.Invoke(invocation) +} + +func (tf *TokenFilter) OnResponse(result protocol.Result, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result { + return result +} + +func GetTokenFilter() filter.Filter { + return &TokenFilter{} +} diff --git a/filter/impl/token_filter_test.go b/filter/impl/token_filter_test.go new file mode 100644 index 0000000000..1473f27403 --- /dev/null +++ b/filter/impl/token_filter_test.go @@ -0,0 +1,85 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You 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 impl + +import ( + "net/url" + "testing" +) + +import ( + "github.com/stretchr/testify/assert" +) + +import ( + "github.com/apache/dubbo-go/common" + "github.com/apache/dubbo-go/common/constant" + "github.com/apache/dubbo-go/protocol" + "github.com/apache/dubbo-go/protocol/invocation" +) + +func TestTokenFilter_Invoke(t *testing.T) { + filter := GetTokenFilter() + + url := common.NewURLWithOptions( + common.WithParams(url.Values{}), + common.WithParamsValue(constant.TOKEN_KEY, "ori_key")) + attch := make(map[string]string, 0) + attch[constant.TOKEN_KEY] = "ori_key" + result := filter.Invoke(protocol.NewBaseInvoker(*url), + invocation.NewRPCInvocation("MethodName", []interface{}{"OK"}, attch)) + assert.Nil(t, result.Error()) + assert.Nil(t, result.Result()) +} + +func TestTokenFilter_InvokeEmptyToken(t *testing.T) { + filter := GetTokenFilter() + + url := common.URL{} + attch := make(map[string]string, 0) + attch[constant.TOKEN_KEY] = "ori_key" + result := filter.Invoke(protocol.NewBaseInvoker(url), + invocation.NewRPCInvocation("MethodName", []interface{}{"OK"}, attch)) + assert.Nil(t, result.Error()) + assert.Nil(t, result.Result()) +} + +func TestTokenFilter_InvokeEmptyAttach(t *testing.T) { + filter := GetTokenFilter() + + url := common.NewURLWithOptions( + common.WithParams(url.Values{}), + common.WithParamsValue(constant.TOKEN_KEY, "ori_key")) + attch := make(map[string]string, 0) + result := filter.Invoke(protocol.NewBaseInvoker(*url), + invocation.NewRPCInvocation("MethodName", []interface{}{"OK"}, attch)) + assert.NotNil(t, result.Error()) +} + +func TestTokenFilter_InvokeNotEqual(t *testing.T) { + filter := GetTokenFilter() + + url := common.NewURLWithOptions( + common.WithParams(url.Values{}), + common.WithParamsValue(constant.TOKEN_KEY, "ori_key")) + attch := make(map[string]string, 0) + attch[constant.TOKEN_KEY] = "err_key" + result := filter.Invoke(protocol.NewBaseInvoker(*url), + invocation.NewRPCInvocation("MethodName", []interface{}{"OK"}, attch)) + assert.NotNil(t, result.Error()) +} diff --git a/go.mod b/go.mod index ec3c24c278..09948c93c5 100644 --- a/go.mod +++ b/go.mod @@ -35,6 +35,7 @@ require ( github.com/pkg/errors v0.8.1 github.com/prometheus/client_golang v1.1.0 // indirect github.com/samuel/go-zookeeper v0.0.0-20180130194729-c4fab1ac1bec + github.com/satori/go.uuid v1.2.0 github.com/smartystreets/goconvey v0.0.0-20190710185942-9d28bd7c0945 // indirect github.com/soheilhy/cmux v0.1.4 // indirect github.com/stretchr/testify v1.3.0 diff --git a/protocol/dubbo/dubbo_invoker.go b/protocol/dubbo/dubbo_invoker.go index 4bfc1324cf..1b736b1289 100644 --- a/protocol/dubbo/dubbo_invoker.go +++ b/protocol/dubbo/dubbo_invoker.go @@ -36,16 +36,29 @@ import ( var Err_No_Reply = perrors.New("request need @response") +var ( + attachmentKey = []string{constant.INTERFACE_KEY, constant.GROUP_KEY, constant.TOKEN_KEY, constant.TIMEOUT_KEY} +) + type DubboInvoker struct { protocol.BaseInvoker client *Client + attachment map[string]string destroyLock sync.Mutex } func NewDubboInvoker(url common.URL, client *Client) *DubboInvoker { + attachment := make(map[string]string, 0) + for _, k := range attachmentKey { + if v := url.GetParam(k, ""); len(v) > 0 { + attachment[k] = v + } + } + return &DubboInvoker{ BaseInvoker: *protocol.NewBaseInvoker(url), client: client, + attachment: attachment, } } @@ -57,6 +70,11 @@ func (di *DubboInvoker) Invoke(invocation protocol.Invocation) protocol.Result { ) inv := invocation.(*invocation_impl.RPCInvocation) + if len(di.attachment) > 0 { + for k, v := range di.attachment { + inv.SetAttachments(k, v) + } + } url := di.GetUrl() // async async, err := strconv.ParseBool(inv.AttachmentsByKey(constant.ASYNC_KEY, "false")) From bb37d14e7fc8a818c4dcb38fa8a8c28866850f61 Mon Sep 17 00:00:00 2001 From: xujianhai666 Date: Tue, 17 Sep 2019 10:21:30 +0800 Subject: [PATCH 21/34] fix according review --- filter/impl/token_filter.go | 14 ++++++-------- protocol/dubbo/dubbo_invoker.go | 13 ++----------- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/filter/impl/token_filter.go b/filter/impl/token_filter.go index 6b658bed7c..8c42851c34 100644 --- a/filter/impl/token_filter.go +++ b/filter/impl/token_filter.go @@ -33,11 +33,11 @@ import ( ) const ( - token = "token" + TOKEN = "token" ) func init() { - extension.SetFilter(token, GetTokenFilter) + extension.SetFilter(TOKEN, GetTokenFilter) } type TokenFilter struct{} @@ -46,13 +46,11 @@ func (tf *TokenFilter) Invoke(invoker protocol.Invoker, invocation protocol.Invo invokerTkn := invoker.GetUrl().GetParam(constant.TOKEN_KEY, "") if len(invokerTkn) > 0 { attachs := invocation.Attachments() - if len(attachs) > 0 { - remoteTkn, exist := attachs[constant.TOKEN_KEY] - if exist && strings.EqualFold(invokerTkn, remoteTkn) { - return invoker.Invoke(invocation) - } + remoteTkn, exist := attachs[constant.TOKEN_KEY] + if exist && strings.EqualFold(invokerTkn, remoteTkn) { + return invoker.Invoke(invocation) } - return &protocol.RPCResult{Err: perrors.Errorf("Invalid token! Forbid invoke remote service %s method %s ", + return &protocol.RPCResult{Err: perrors.Errorf("Invalid token! Forbid invoke remote service %v method %s ", invoker, invocation.MethodName())} } diff --git a/protocol/dubbo/dubbo_invoker.go b/protocol/dubbo/dubbo_invoker.go index 1b736b1289..bc321a97a4 100644 --- a/protocol/dubbo/dubbo_invoker.go +++ b/protocol/dubbo/dubbo_invoker.go @@ -43,22 +43,13 @@ var ( type DubboInvoker struct { protocol.BaseInvoker client *Client - attachment map[string]string destroyLock sync.Mutex } func NewDubboInvoker(url common.URL, client *Client) *DubboInvoker { - attachment := make(map[string]string, 0) - for _, k := range attachmentKey { - if v := url.GetParam(k, ""); len(v) > 0 { - attachment[k] = v - } - } - return &DubboInvoker{ BaseInvoker: *protocol.NewBaseInvoker(url), client: client, - attachment: attachment, } } @@ -70,8 +61,8 @@ func (di *DubboInvoker) Invoke(invocation protocol.Invocation) protocol.Result { ) inv := invocation.(*invocation_impl.RPCInvocation) - if len(di.attachment) > 0 { - for k, v := range di.attachment { + for _, k := range attachmentKey { + if v := di.GetUrl().GetParam(k, ""); len(v) > 0 { inv.SetAttachments(k, v) } } From c88b789caa76086b5a206f619154f07df2fd792f Mon Sep 17 00:00:00 2001 From: xujianhai666 Date: Wed, 18 Sep 2019 10:51:43 +0800 Subject: [PATCH 22/34] fix extension --- filter/impl/token_filter.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/filter/impl/token_filter.go b/filter/impl/token_filter.go index 8c42851c34..d10dff5b76 100644 --- a/filter/impl/token_filter.go +++ b/filter/impl/token_filter.go @@ -27,7 +27,7 @@ import ( import ( "github.com/apache/dubbo-go/common/constant" - "github.com/apache/dubbo-go/coconfig/service_config.gommon/extension" + "github.com/apache/dubbo-go/common/extension" "github.com/apache/dubbo-go/filter" "github.com/apache/dubbo-go/protocol" ) From 07ef06451c374dfd1e193a568e7918abcbc327d4 Mon Sep 17 00:00:00 2001 From: xujianhai666 Date: Wed, 18 Sep 2019 11:10:12 +0800 Subject: [PATCH 23/34] add feature list --- CHANGE.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGE.md b/CHANGE.md index cdfca4fb6d..3029186468 100644 --- a/CHANGE.md +++ b/CHANGE.md @@ -10,6 +10,7 @@ - Allow user set custom params for registry; - Support zookeeper config center; - Failsafe/Failback Cluster Strategy; +- Support TokenFilter; ### Enhancement From 08883269b74f832f44d1bc4826d3321a6bf5d308 Mon Sep 17 00:00:00 2001 From: xujianhai666 Date: Wed, 18 Sep 2019 11:23:57 +0800 Subject: [PATCH 24/34] move feature list to readme --- CHANGE.md | 1 - README.md | 4 ++-- README_CN.md | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/CHANGE.md b/CHANGE.md index 3029186468..cdfca4fb6d 100644 --- a/CHANGE.md +++ b/CHANGE.md @@ -10,7 +10,6 @@ - Allow user set custom params for registry; - Support zookeeper config center; - Failsafe/Failback Cluster Strategy; -- Support TokenFilter; ### Enhancement diff --git a/README.md b/README.md index 36e0ad78c3..c5ad2f3a56 100644 --- a/README.md +++ b/README.md @@ -34,13 +34,13 @@ Finished List: - Configure Center: Zookeeper - Cluster Strategy: Failover/[Failfast](https://github.com/apache/dubbo-go/pull/140)/[Failsafe/Failback](https://github.com/apache/dubbo-go/pull/136)/[Available](https://github.com/apache/dubbo-go/pull/155)/[Broadcast](https://github.com/apache/dubbo-go/pull/158)/[Forking](https://github.com/apache/dubbo-go/pull/161) - Load Balance: Random/[RoundRobin](https://github.com/apache/dubbo-go/pull/66)/[LeastActive](https://github.com/apache/dubbo-go/pull/65) -- Filter: Echo Health Check/[Circuit break and service downgrade](https://github.com/apache/dubbo-go/pull/133) +- Filter: Echo Health Check/[Circuit break and service downgrade](https://github.com/apache/dubbo-go/pull/133)/[TokenFilter](https://github.com/apache/dubbo-go/pull/202) - Other feature: [generic invoke](https://github.com/apache/dubbo-go/pull/122)/start check/connecting certain provider/multi-protocols/multi-registries/multi-versions/service group Working List: - Load Balance: ConsistentHash -- Filter: TokenFilter/AccessLogFilter/CountFilter/ExecuteLimitFilter/TpsLimitFilter +- Filter: AccessLogFilter/CountFilter/ExecuteLimitFilter/TpsLimitFilter - Registry: k8s - Configure Center: apollo - Dynamic Configuration Center & Metadata Center (dubbo v2.7.x) diff --git a/README_CN.md b/README_CN.md index 387070d267..266d1d0e92 100644 --- a/README_CN.md +++ b/README_CN.md @@ -33,14 +33,14 @@ Apache License, Version 2.0 - 配置中心: Zookeeper - 集群策略: Failover/[Failfast](https://github.com/apache/dubbo-go/pull/140)/[Failsafe/Failback](https://github.com/apache/dubbo-go/pull/136)/[Available](https://github.com/apache/dubbo-go/pull/155)/[Broadcast](https://github.com/apache/dubbo-go/pull/158)/[Forking](https://github.com/apache/dubbo-go/pull/161) - 负载均衡策略: Random/[RoundRobin](https://github.com/apache/dubbo-go/pull/66)/[LeastActive](https://github.com/apache/dubbo-go/pull/65) -- 过滤器: Echo Health Check/[服务熔断&降级](https://github.com/apache/dubbo-go/pull/133) +- 过滤器: Echo Health Check/[服务熔断&降级](https://github.com/apache/dubbo-go/pull/133)/[TokenFilter](https://github.com/apache/dubbo-go/pull/202) - 其他功能支持: [泛化调用](https://github.com/apache/dubbo-go/pull/122)/启动时检查/服务直连/多服务协议/多注册中心/多服务版本/服务分组 开发中列表: - 集群策略: Forking - 负载均衡策略: ConsistentHash -- 过滤器: TokenFilter/AccessLogFilter/CountFilter/ExecuteLimitFilter/TpsLimitFilter +- 过滤器: AccessLogFilter/CountFilter/ExecuteLimitFilter/TpsLimitFilter - 注册中心: k8s - 配置中心: apollo - 动态配置中心 & 元数据中心 (dubbo v2.7.x) From 26b50d9272c98667f7ee8dfa3c9dbe313338386b Mon Sep 17 00:00:00 2001 From: Ian Luo Date: Wed, 18 Sep 2019 20:34:01 +0800 Subject: [PATCH 25/34] fix issue #207: common/utils/net_test.go:25 cannot pass --- common/utils/net.go | 72 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 55 insertions(+), 17 deletions(-) diff --git a/common/utils/net.go b/common/utils/net.go index 41d7b9e2e5..4629d522a2 100644 --- a/common/utils/net.go +++ b/common/utils/net.go @@ -19,6 +19,7 @@ package utils import ( "net" + "strings" ) import ( @@ -39,38 +40,49 @@ func init() { // ref: https://stackoverflow.com/questions/23558425/how-do-i-get-the-local-ip-address-in-go func GetLocalIP() (string, error) { - ifs, err := net.Interfaces() + faces, err := net.Interfaces() if err != nil { return "", perrors.WithStack(err) } - var ipAddr []byte - for _, i := range ifs { - addrs, err := i.Addrs() + var privateIpv4Addr, ipv4Addr net.IP + for _, face := range faces { + if face.Flags&net.FlagUp == 0 { + // interface down + continue + } + + if face.Flags&net.FlagLoopback != 0 { + // loopback interface + continue + } + + if strings.Contains(strings.ToLower(face.Name), "docker") { + continue + } + + addrs, err := face.Addrs() if err != nil { return "", perrors.WithStack(err) } - var ip net.IP - for _, addr := range addrs { - switch v := addr.(type) { - case *net.IPNet: - ip = v.IP - case *net.IPAddr: - ip = v.IP - } - if !ip.IsLoopback() && ip.To4() != nil && isPrivateIP(ip.String()) { - ipAddr = ip - break + if ipv4, ok := getValidIPv4(addrs); ok { + ipv4Addr = ipv4 + if isPrivateIP(ipv4.String()) { + privateIpv4Addr = ipv4 } } } - if ipAddr == nil { + if ipv4Addr == nil { return "", perrors.Errorf("can not get local IP") } - return net.IP(ipAddr).String(), nil + if privateIpv4Addr == nil { + return ipv4Addr.String(), nil + } + + return privateIpv4Addr.String(), nil } func isPrivateIP(ipAddr string) bool { @@ -82,3 +94,29 @@ func isPrivateIP(ipAddr string) bool { } return false } + +func getValidIPv4(addrs []net.Addr) (net.IP, bool) { + for _, addr := range addrs { + var ip net.IP + + switch v := addr.(type) { + case *net.IPNet: + ip = v.IP + case *net.IPAddr: + ip = v.IP + } + + if ip == nil || ip.IsLoopback() { + continue + } + + ip = ip.To4() + if ip == nil { + // not an valid ipv4 address + continue + } + + return ip, true + } + return nil, false +} From bf4734a102710f84e034a5299ddd1345e15e0ab2 Mon Sep 17 00:00:00 2001 From: Ian Luo Date: Wed, 18 Sep 2019 20:54:21 +0800 Subject: [PATCH 26/34] enhance isPrivateIP --- common/utils/net.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/common/utils/net.go b/common/utils/net.go index 4629d522a2..29dfd9df21 100644 --- a/common/utils/net.go +++ b/common/utils/net.go @@ -68,7 +68,7 @@ func GetLocalIP() (string, error) { if ipv4, ok := getValidIPv4(addrs); ok { ipv4Addr = ipv4 - if isPrivateIP(ipv4.String()) { + if isPrivateIP(ipv4) { privateIpv4Addr = ipv4 } } @@ -85,8 +85,7 @@ func GetLocalIP() (string, error) { return privateIpv4Addr.String(), nil } -func isPrivateIP(ipAddr string) bool { - ip := net.ParseIP(ipAddr) +func isPrivateIP(ip net.IP) bool { for _, priv := range privateBlocks { if priv.Contains(ip) { return true From 92c804836d9be5a53bfc0433bdb34897fabdb010 Mon Sep 17 00:00:00 2001 From: Ian Luo Date: Wed, 18 Sep 2019 20:56:56 +0800 Subject: [PATCH 27/34] direct return once private ip is detected --- common/utils/net.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/common/utils/net.go b/common/utils/net.go index 29dfd9df21..9dda7fad21 100644 --- a/common/utils/net.go +++ b/common/utils/net.go @@ -45,7 +45,7 @@ func GetLocalIP() (string, error) { return "", perrors.WithStack(err) } - var privateIpv4Addr, ipv4Addr net.IP + var addr net.IP for _, face := range faces { if face.Flags&net.FlagUp == 0 { // interface down @@ -67,22 +67,18 @@ func GetLocalIP() (string, error) { } if ipv4, ok := getValidIPv4(addrs); ok { - ipv4Addr = ipv4 + addr = ipv4 if isPrivateIP(ipv4) { - privateIpv4Addr = ipv4 + return ipv4.String(), nil } } } - if ipv4Addr == nil { + if addr == nil { return "", perrors.Errorf("can not get local IP") } - if privateIpv4Addr == nil { - return ipv4Addr.String(), nil - } - - return privateIpv4Addr.String(), nil + return addr.String(), nil } func isPrivateIP(ip net.IP) bool { From 7d2753b822c215d97e1ac7f3563022ad12d2d5d0 Mon Sep 17 00:00:00 2001 From: Ian Luo Date: Wed, 18 Sep 2019 21:04:21 +0800 Subject: [PATCH 28/34] introduce isValidNetworkInterface --- common/utils/net.go | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/common/utils/net.go b/common/utils/net.go index 9dda7fad21..1e74685f76 100644 --- a/common/utils/net.go +++ b/common/utils/net.go @@ -47,17 +47,7 @@ func GetLocalIP() (string, error) { var addr net.IP for _, face := range faces { - if face.Flags&net.FlagUp == 0 { - // interface down - continue - } - - if face.Flags&net.FlagLoopback != 0 { - // loopback interface - continue - } - - if strings.Contains(strings.ToLower(face.Name), "docker") { + if !isValidNetworkInterface(face) { continue } @@ -115,3 +105,21 @@ func getValidIPv4(addrs []net.Addr) (net.IP, bool) { } return nil, false } + +func isValidNetworkInterface(face net.Interface) bool { + if face.Flags&net.FlagUp == 0 { + // interface down + return false + } + + if face.Flags&net.FlagLoopback != 0 { + // loopback interface + return false + } + + if strings.Contains(strings.ToLower(face.Name), "docker") { + return false + } + + return true +} \ No newline at end of file From 61a064103629a2ce40dad75c41deaaf9be99cf27 Mon Sep 17 00:00:00 2001 From: Ian Luo Date: Thu, 19 Sep 2019 01:15:16 +0800 Subject: [PATCH 29/34] go fmt --- common/utils/net.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/utils/net.go b/common/utils/net.go index 1e74685f76..31b032e79d 100644 --- a/common/utils/net.go +++ b/common/utils/net.go @@ -122,4 +122,4 @@ func isValidNetworkInterface(face net.Interface) bool { } return true -} \ No newline at end of file +} From 42715c69b768c53651dd30ba93b3535126e2790d Mon Sep 17 00:00:00 2001 From: Ian Luo Date: Thu, 19 Sep 2019 01:16:45 +0800 Subject: [PATCH 30/34] remove useless comment --- common/utils/net.go | 1 - 1 file changed, 1 deletion(-) diff --git a/common/utils/net.go b/common/utils/net.go index 31b032e79d..47a2502317 100644 --- a/common/utils/net.go +++ b/common/utils/net.go @@ -38,7 +38,6 @@ func init() { } } -// ref: https://stackoverflow.com/questions/23558425/how-do-i-get-the-local-ip-address-in-go func GetLocalIP() (string, error) { faces, err := net.Interfaces() if err != nil { From 91a881d84ad6880c5f7a2ed0967821d3ab3eb9e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E8=BE=9B=E6=A0=BC?= Date: Thu, 19 Sep 2019 09:47:14 +0800 Subject: [PATCH 31/34] fix: skip subscribe in provider situation --- registry/consul/registry.go | 20 ++++---------------- registry/consul/registry_test.go | 2 +- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/registry/consul/registry.go b/registry/consul/registry.go index 1fd3e54e96..73bf3975bc 100644 --- a/registry/consul/registry.go +++ b/registry/consul/registry.go @@ -111,31 +111,21 @@ func (r *consulRegistry) unregister(url common.URL) error { return r.client.Agent().ServiceDeregister(buildId(url)) } -func (r *consulRegistry) subscribe(url *common.URL) (registry.Listener, error) { - var ( - listener registry.Listener - err error - ) - +func (r *consulRegistry) Subscribe(url *common.URL, notifyListener registry.NotifyListener) { role, _ := strconv.Atoi(r.URL.GetParam(constant.ROLE_KEY, "")) if role == common.CONSUMER { - listener, err = r.getListener(*url) - if err != nil { - return nil, err - } + r.subscribe(url, notifyListener) } - return listener, nil } -//subscibe from registry -func (r *consulRegistry) Subscribe(url *common.URL, notifyListener registry.NotifyListener) { +func (r *consulRegistry) subscribe(url *common.URL, notifyListener registry.NotifyListener) { for { if !r.IsAvailable() { logger.Warnf("event listener game over.") return } - listener, err := r.subscribe(url) + listener, err := r.getListener(*url) if err != nil { if !r.IsAvailable() { logger.Warnf("event listener game over.") @@ -155,9 +145,7 @@ func (r *consulRegistry) Subscribe(url *common.URL, notifyListener registry.Noti logger.Infof("update begin, service event: %v", serviceEvent.String()) notifyListener.Notify(serviceEvent) } - } - } } diff --git a/registry/consul/registry_test.go b/registry/consul/registry_test.go index ff8c2e2316..bb6842cd8f 100644 --- a/registry/consul/registry_test.go +++ b/registry/consul/registry_test.go @@ -51,7 +51,7 @@ func (suite *consulRegistryTestSuite) testUnregister() { func (suite *consulRegistryTestSuite) testSubscribe() { consumerUrl := newConsumerUrl(consumerHost, consumerPort, service, protocol) suite.consumerUrl = consumerUrl - listener, err := suite.consumerRegistry.subscribe(&consumerUrl) + listener, err := suite.consumerRegistry.getListener(consumerUrl) assert.NoError(suite.t, err) suite.listener = listener } From e11330e7c629471d85ee40e810fecb2d0fd73385 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E8=BE=9B=E6=A0=BC?= Date: Thu, 19 Sep 2019 09:54:58 +0800 Subject: [PATCH 32/34] fix typo --- registry/directory/directory.go | 9 ++++----- registry/etcdv3/registry.go | 2 +- registry/nacos/registry.go | 9 +++++---- registry/zookeeper/registry.go | 4 +++- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/registry/directory/directory.go b/registry/directory/directory.go index 54f0acd843..b6794e2ebf 100644 --- a/registry/directory/directory.go +++ b/registry/directory/directory.go @@ -40,10 +40,6 @@ import ( "github.com/apache/dubbo-go/registry" ) -const ( - RegistryConnDelay = 3 -) - type Options struct { serviceTTL time.Duration } @@ -87,7 +83,7 @@ func NewRegistryDirectory(url *common.URL, registry registry.Registry, opts ...O return dir, nil } -//subscibe from registry +//subscribe from registry func (dir *registryDirectory) Subscribe(url *common.URL) { dir.consumerConfigurationListener.addNotifyListener(dir) dir.referenceConfigurationListener = newReferenceConfigurationListener(dir, url) @@ -245,6 +241,7 @@ func (dir *registryDirectory) Destroy() { dir.cacheInvokers = []protocol.Invoker{} }) } + func (dir *registryDirectory) overrideUrl(targetUrl *common.URL) { doOverrideUrl(dir.configurators, targetUrl) doOverrideUrl(dir.consumerConfigurationListener.Configurators(), targetUrl) @@ -293,9 +290,11 @@ func newConsumerConfigurationListener(dir *registryDirectory) *consumerConfigura ) return listener } + func (l *consumerConfigurationListener) addNotifyListener(listener registry.NotifyListener) { l.listeners = append(l.listeners, listener) } + func (l *consumerConfigurationListener) Process(event *config_center.ConfigChangeEvent) { l.BaseConfigurationListener.Process(event) l.directory.refreshInvokers(nil) diff --git a/registry/etcdv3/registry.go b/registry/etcdv3/registry.go index 8bb1ff430e..bf097f0b59 100644 --- a/registry/etcdv3/registry.go +++ b/registry/etcdv3/registry.go @@ -330,7 +330,7 @@ func (r *etcdV3Registry) subscribe(svc *common.URL) (registry.Listener, error) { return configListener, nil } -//subscibe from registry +//subscribe from registry func (r *etcdV3Registry) Subscribe(url *common.URL, notifyListener registry.NotifyListener) { for { if !r.IsAvailable() { diff --git a/registry/nacos/registry.go b/registry/nacos/registry.go index f1a78264ce..7025b3e5d4 100644 --- a/registry/nacos/registry.go +++ b/registry/nacos/registry.go @@ -172,15 +172,15 @@ func (nr *nacosRegistry) subscribe(conf *common.URL) (registry.Listener, error) return NewNacosListener(*conf, nr.namingClient) } -//subscibe from registry -func (r *nacosRegistry) Subscribe(url *common.URL, notifyListener registry.NotifyListener) { +//subscribe from registry +func (nr *nacosRegistry) Subscribe(url *common.URL, notifyListener registry.NotifyListener) { for { - if !r.IsAvailable() { + if !nr.IsAvailable() { logger.Warnf("event listener game over.") return } - listener, err := r.subscribe(url) + listener, err := nr.subscribe(url) if err != nil { if !r.IsAvailable() { logger.Warnf("event listener game over.") @@ -205,6 +205,7 @@ func (r *nacosRegistry) Subscribe(url *common.URL, notifyListener registry.Notif } } + func (nr *nacosRegistry) GetUrl() common.URL { return *nr.URL } diff --git a/registry/zookeeper/registry.go b/registry/zookeeper/registry.go index e14541dd04..972a4b6c5e 100644 --- a/registry/zookeeper/registry.go +++ b/registry/zookeeper/registry.go @@ -147,6 +147,7 @@ func newMockZkRegistry(url *common.URL, opts ...zookeeper.Option) (*zk.TestClust return c, r, nil } + func (r *zkRegistry) ZkClient() *zookeeper.ZookeeperClient { return r.client } @@ -399,7 +400,7 @@ func (r *zkRegistry) subscribe(conf *common.URL) (registry.Listener, error) { return r.getListener(conf) } -//subscibe from registry +//subscribe from registry func (r *zkRegistry) Subscribe(url *common.URL, notifyListener registry.NotifyListener) { for { if !r.IsAvailable() { @@ -432,6 +433,7 @@ func (r *zkRegistry) Subscribe(url *common.URL, notifyListener registry.NotifyLi } } + func (r *zkRegistry) getListener(conf *common.URL) (*RegistryConfigurationListener, error) { var ( zkListener *RegistryConfigurationListener From dd30685cf3b921723e260e50a0a4df9638ae09ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E8=BE=9B=E6=A0=BC?= Date: Thu, 19 Sep 2019 10:19:50 +0800 Subject: [PATCH 33/34] fix bug --- common/constant/env.go | 2 +- config/config_loader.go | 1 + registry/nacos/registry.go | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/common/constant/env.go b/common/constant/env.go index f0e4fabe02..c2bc3c4bc3 100644 --- a/common/constant/env.go +++ b/common/constant/env.go @@ -20,5 +20,5 @@ package constant const ( CONF_CONSUMER_FILE_PATH = "CONF_CONSUMER_FILE_PATH" CONF_PROVIDER_FILE_PATH = "CONF_PROVIDER_FILE_PATH" - APP_LOG_CONF_FILE string = "APP_LOG_CONF_FILE" + APP_LOG_CONF_FILE = "APP_LOG_CONF_FILE" ) diff --git a/config/config_loader.go b/config/config_loader.go index 0b48761fd6..b737d3f233 100644 --- a/config/config_loader.go +++ b/config/config_loader.go @@ -54,6 +54,7 @@ func init() { providerConfig = nil } } + func checkRegistries(registries map[string]*RegistryConfig, singleRegistry *RegistryConfig) { if len(registries) == 0 && singleRegistry != nil { registries[constant.DEFAULT_KEY] = singleRegistry diff --git a/registry/nacos/registry.go b/registry/nacos/registry.go index 7025b3e5d4..229c6f8f0c 100644 --- a/registry/nacos/registry.go +++ b/registry/nacos/registry.go @@ -182,7 +182,7 @@ func (nr *nacosRegistry) Subscribe(url *common.URL, notifyListener registry.Noti listener, err := nr.subscribe(url) if err != nil { - if !r.IsAvailable() { + if !nr.IsAvailable() { logger.Warnf("event listener game over.") return } From 71d53f12f17f7860b9e5b80e1a5527a7e512c481 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E8=BE=9B=E6=A0=BC?= Date: Thu, 19 Sep 2019 10:30:50 +0800 Subject: [PATCH 34/34] go fmt --- common/constant/env.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/common/constant/env.go b/common/constant/env.go index c2bc3c4bc3..759cb0be0a 100644 --- a/common/constant/env.go +++ b/common/constant/env.go @@ -18,7 +18,7 @@ package constant const ( - CONF_CONSUMER_FILE_PATH = "CONF_CONSUMER_FILE_PATH" - CONF_PROVIDER_FILE_PATH = "CONF_PROVIDER_FILE_PATH" - APP_LOG_CONF_FILE = "APP_LOG_CONF_FILE" + CONF_CONSUMER_FILE_PATH = "CONF_CONSUMER_FILE_PATH" + CONF_PROVIDER_FILE_PATH = "CONF_PROVIDER_FILE_PATH" + APP_LOG_CONF_FILE = "APP_LOG_CONF_FILE" )