Skip to content

Commit

Permalink
Merge pull request #2 from apache/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
joeyzhouy authored Sep 23, 2019
2 parents e35d29c + dcbd967 commit 0163daf
Show file tree
Hide file tree
Showing 199 changed files with 2,871 additions and 5,955 deletions.
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: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
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
23 changes: 20 additions & 3 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 All @@ -40,13 +46,24 @@ 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"
ECHO = "$echo"
)

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"
)
6 changes: 3 additions & 3 deletions common/constant/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 string = "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"
)
48 changes: 31 additions & 17 deletions common/constant/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,22 @@ 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"
TOKEN_KEY = "token"
)

const (
Expand Down Expand Up @@ -79,16 +86,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

0 comments on commit 0163daf

Please sign in to comment.