Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: new feature to support dynamic config center which compatible with dubbo 2.6.x & 2.7.x #194

Merged
merged 29 commits into from
Sep 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
90b03bb
Merge branch 'master' into config_center
hxmhlt Jul 1, 2019
e9c351a
Merge branch 'master' into config_center
hxmhlt Jul 1, 2019
189adec
Merge branch 'master' into config_center
hxmhlt Jul 2, 2019
4653db0
Merge branch 'config_params' into config_center
hxmhlt Jul 2, 2019
34145b4
Merge branch 'config_params' into config_center
hxmhlt Jul 2, 2019
a94746d
Add: define configurator
hxmhlt Jul 4, 2019
5924ce4
Add:dynamic config in registry protocol export
hxmhlt Jul 13, 2019
d9703b9
Merge dev
hxmhlt Aug 27, 2019
cf43b75
Add: protocol config center commit
hxmhlt Aug 31, 2019
13f9eed
Add:before ci shell
hxmhlt Sep 2, 2019
f361297
Add:unit test for dynamic cc 2.6
hxmhlt Sep 5, 2019
52bb0e1
Add:can run successful
hxmhlt Sep 6, 2019
4e2382b
Merge remote-tracking branch 'apache/develop' into config_center
hxmhlt Sep 6, 2019
4c1886f
Add:add license header & format code
hxmhlt Sep 6, 2019
49dc253
Mod:dependency modify
hxmhlt Sep 6, 2019
cb646cd
Mod:dependency modify
hxmhlt Sep 6, 2019
2b5ee46
Mod:dependency modify
hxmhlt Sep 6, 2019
db6a465
Mod:resolve pr review & merge develop
hxmhlt Sep 9, 2019
08b86ad
Mod:bug in directory cache invoker
hxmhlt Sep 9, 2019
bf4271b
Mod:remove registry subscribe listen.next sleep error
hxmhlt Sep 9, 2019
23f5b40
Add:support single registry config in config center
hxmhlt Sep 10, 2019
895e7c3
Add:add support yaml default tag
hxmhlt Sep 11, 2019
414b7ae
Add:reference & service protocol default
hxmhlt Sep 12, 2019
1ee6882
Mod:change application_config to application
hxmhlt Sep 12, 2019
72067dc
Mod:add application name check
hxmhlt Sep 12, 2019
8bfd6b1
Mod:add application name check
hxmhlt Sep 12, 2019
8a72be8
Add:config center service_config & reference_config id
hxmhlt Sep 12, 2019
ddf2e27
Add:config center service_config & reference_config id ut
hxmhlt Sep 12, 2019
ccefec7
Mod:merge develop
hxmhlt Sep 17, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ coverage.txt
# unit test
remoting/zookeeper/zookeeper-4unittest/
config_center/zookeeper/zookeeper-4unittest/
registry/zookeeper/zookeeper-4unittest/
registry/zookeeper/zookeeper-4unittest/
4 changes: 4 additions & 0 deletions before_ut.sh
Original file line number Diff line number Diff line change
@@ -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/
3 changes: 3 additions & 0 deletions cluster/directory/base_directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
42 changes: 31 additions & 11 deletions common/config/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,21 @@ import (
"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.
// 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
appExternalConfigMap sync.Map
dynamicConfiguration config_center.DynamicConfiguration
}

var (
Expand All @@ -45,6 +51,9 @@ func GetEnvInstance() *Environment {
})
return instance
}
func NewEnvInstance() {
instance = &Environment{configCenterFirst: true}
}

//func (env *Environment) SetConfigCenterFirst() {
// env.configCenterFirst = true
Expand All @@ -60,23 +69,34 @@ 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
}

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
}

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) {
Expand Down
3 changes: 2 additions & 1 deletion common/config/environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package config
import (
"testing"
)

import (
"github.com/stretchr/testify/assert"
)
Expand All @@ -38,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)
}
Expand Down
21 changes: 19 additions & 2 deletions common/constant/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@
package constant

const (
DUBBO = "dubbo"
DUBBO = "dubbo"
PROVIDER_PROTOCOL = "provider"
//compatible with 2.6.x
OVERRIDE_PROTOCOL = "override"
EMPTY_PROTOCOL = "empty"
ROUTER_PROTOCOL = "router"
)

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
Expand Down Expand Up @@ -48,5 +54,16 @@ const (
)

const (
ANY_VALUE = "*"
ANY_VALUE = "*"
ANYHOST_VALUE = "0.0.0.0"
REMOVE_VALUE_PREFIX = "-"
)

const (
CONFIGURATORS_CATEGORY = "configurators"
ROUTER_CATEGORY = "category"
DEFAULT_CATEGORY = PROVIDER_CATEGORY
DYNAMIC_CONFIGURATORS_CATEGORY = "dynamicconfigurators"
APP_DYNAMIC_CONFIGURATORS_CATEGORY = "appdynamicconfigurators"
PROVIDER_CATEGORY = "providers"
)
47 changes: 30 additions & 17 deletions common/constant/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,21 @@ const (
)

const (
GROUP_KEY = "group"
VERSION_KEY = "version"
INTERFACE_KEY = "interface"
PATH_KEY = "path"
SERVICE_KEY = "service"
METHODS_KEY = "methods"
TIMEOUT_KEY = "timeout"
BEAN_NAME_KEY = "bean.name"
GENERIC_KEY = "generic"
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"
BEAN_NAME_KEY = "bean.name"
GENERIC_KEY = "generic"
CLASSIFIER_KEY = "classifier"
)

const (
Expand Down Expand Up @@ -79,16 +85,23 @@ 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."
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 (
CONFIGURATORS_SUFFIX = ".configurators"
)

const (
Expand Down
60 changes: 60 additions & 0 deletions common/extension/configurator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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/common"
"github.com/apache/dubbo-go/config_center"
)

const DefaultKey = "default"

type getConfiguratorFunc func(url *common.URL) config_center.Configurator

var (
configurator = make(map[string]getConfiguratorFunc)
)

func SetConfigurator(name string, v getConfiguratorFunc) {
configurator[name] = v
}

func GetConfigurator(name string, url *common.URL) config_center.Configurator {
if configurator[name] == nil {
panic("configurator for " + name + " is not existing, make sure you have import the package.")
}
return configurator[name](url)

}
func SetDefaultConfigurator(v getConfiguratorFunc) {
configurator[DefaultKey] = v
}

func GetDefaultConfigurator(url *common.URL) config_center.Configurator {
if configurator[DefaultKey] == nil {
panic("configurator for default is not existing, make sure you have import the package.")
}
return configurator[DefaultKey](url)

}
func GetDefaultConfiguratorFunc() getConfiguratorFunc {
if configurator[DefaultKey] == nil {
panic("configurator for default is not existing, make sure you have import the package.")
}
return configurator[DefaultKey]
}
Loading