Skip to content

Commit

Permalink
Merge branch '1.4' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
wenxuwan committed Nov 14, 2020
2 parents 36f92db + e80c2e4 commit 7232064
Show file tree
Hide file tree
Showing 25 changed files with 812 additions and 419 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Apache License, Version 2.0

## Release note ##

[v1.4.0-rc1 - Mar 17, 2020](https://github.com/apache/dubbo-go/releases/tag/v1.4.0-rc1)
[v1.4.0 - Mar 17, 2020](https://github.com/apache/dubbo-go/releases/tag/v1.4.0)

[v1.3.0 - Mar 1, 2020](https://github.com/apache/dubbo-go/releases/tag/v1.3.0)

Expand Down
2 changes: 2 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Apache License, Version 2.0

## 发布日志 ##

[v1.4.0 - 2020年3月17日](https://github.com/apache/dubbo-go/releases/tag/v1.4.0)

[v1.3.0 - 2020年3月1日](https://github.com/apache/dubbo-go/releases/tag/v1.3.0)

[v1.2.0 - 2019年11月15日](https://github.com/apache/dubbo-go/releases/tag/v1.2.0)
Expand Down
3 changes: 3 additions & 0 deletions common/constant/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ const (
NACOS_CATEGORY_KEY = "category"
NACOS_PROTOCOL_KEY = "protocol"
NACOS_PATH_KEY = "path"
NACOS_PASSWORD = "password"
NACOS_USERNAME = "username"
NACOS_NAMESPACEID = "namespaceId"
)

const (
Expand Down
5 changes: 4 additions & 1 deletion common/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@ func WithToken(token string) option {
if len(token) > 0 {
value := token
if strings.ToLower(token) == "true" || strings.ToLower(token) == "default" {
value = uuid.NewV4().String()
UUID, err := uuid.NewV4()
if err == nil {
value = UUID.String()
}
}
url.SetParam(constant.TOKEN_KEY, value)
}
Expand Down
9 changes: 6 additions & 3 deletions config/consumer_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (

import (
"github.com/creasty/defaults"
"github.com/dubbogo/getty"
perrors "github.com/pkg/errors"
)

Expand All @@ -34,6 +33,10 @@ import (
"github.com/apache/dubbo-go/common/yaml"
)

const (
MaxWheelTimeSpan = 900e9 // 900s, 15 minute
)

/////////////////////////
// consumerConfig
/////////////////////////
Expand Down Expand Up @@ -107,9 +110,9 @@ func ConsumerInit(confConFile string) error {
if consumerConfig.RequestTimeout, err = time.ParseDuration(consumerConfig.Request_Timeout); err != nil {
return perrors.WithMessagef(err, "time.ParseDuration(Request_Timeout{%#v})", consumerConfig.Request_Timeout)
}
if consumerConfig.RequestTimeout >= time.Duration(getty.MaxWheelTimeSpan) {
if consumerConfig.RequestTimeout >= time.Duration(MaxWheelTimeSpan) {
return perrors.WithMessagef(err, "request_timeout %s should be less than %s",
consumerConfig.Request_Timeout, time.Duration(getty.MaxWheelTimeSpan))
consumerConfig.Request_Timeout, time.Duration(MaxWheelTimeSpan))
}
}
if consumerConfig.Connect_Timeout != "" {
Expand Down
2 changes: 1 addition & 1 deletion config/graceful_shutdown_signal_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var (
// ShutdownSignals ...
ShutdownSignals = []os.Signal{os.Interrupt, os.Kill, syscall.SIGKILL, syscall.SIGSTOP,
syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGILL, syscall.SIGTRAP,
syscall.SIGABRT, syscall.SIGSYS}
syscall.SIGABRT, syscall.SIGSYS, syscall.SIGTERM}

// DumpHeapShutdownSignals ...
DumpHeapShutdownSignals = []os.Signal{syscall.SIGQUIT, syscall.SIGILL,
Expand Down
2 changes: 1 addition & 1 deletion config/graceful_shutdown_signal_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var (
// ShutdownSignals ...
ShutdownSignals = []os.Signal{os.Interrupt, os.Kill, syscall.SIGKILL, syscall.SIGSTOP,
syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGILL, syscall.SIGTRAP,
syscall.SIGABRT, syscall.SIGSYS}
syscall.SIGABRT, syscall.SIGSYS, syscall.SIGTERM}

// DumpHeapShutdownSignals ...
DumpHeapShutdownSignals = []os.Signal{syscall.SIGQUIT, syscall.SIGILL,
Expand Down
2 changes: 1 addition & 1 deletion config/graceful_shutdown_signal_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var (
// ShutdownSignals ...
ShutdownSignals = []os.Signal{os.Interrupt, os.Kill, syscall.SIGKILL,
syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGILL, syscall.SIGTRAP,
syscall.SIGABRT}
syscall.SIGABRT, syscall.SIGTERM}

// DumpHeapShutdownSignals ...
DumpHeapShutdownSignals = []os.Signal{syscall.SIGQUIT, syscall.SIGILL, syscall.SIGTRAP, syscall.SIGABRT}
Expand Down
36 changes: 13 additions & 23 deletions config_center/apollo/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,28 @@ import (

import (
"github.com/pkg/errors"
"github.com/zouyx/agollo"
"github.com/zouyx/agollo/v3"
agolloConstant "github.com/zouyx/agollo/v3/constant"
"github.com/zouyx/agollo/v3/env/config"
)

import (
"github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/common/constant"
cc "github.com/apache/dubbo-go/config_center"
"github.com/apache/dubbo-go/config_center/parser"
"github.com/apache/dubbo-go/remoting"
)

const (
apolloProtocolPrefix = "http://"
apolloConfigFormat = "%s.%s"
apolloConfigFormat = "%s%s"
)

type apolloConfiguration struct {
url *common.URL

listeners sync.Map
appConf *agollo.AppConfig
appConf *config.AppConfig
parser parser.ConfigurationParser
}

Expand All @@ -59,39 +60,28 @@ func newApolloConfiguration(url *common.URL) (*apolloConfiguration, error) {

appId := url.GetParam(constant.CONFIG_APP_ID_KEY, "")
namespaces := getProperties(url.GetParam(constant.CONFIG_NAMESPACE_KEY, cc.DEFAULT_GROUP))
c.appConf = &agollo.AppConfig{
AppId: appId,
c.appConf = &config.AppConfig{
AppID: appId,
Cluster: configCluster,
NamespaceName: namespaces,
Ip: configAddr,
IP: configAddr,
}

agollo.InitCustomConfig(func() (*agollo.AppConfig, error) {
agollo.InitCustomConfig(func() (*config.AppConfig, error) {
return c.appConf, nil
})

return c, agollo.Start()
}

func getChangeType(change agollo.ConfigChangeType) remoting.EventType {
switch change {
case agollo.ADDED:
return remoting.EventTypeAdd
case agollo.DELETED:
return remoting.EventTypeDel
default:
return remoting.EventTypeUpdate
}
}

func (c *apolloConfiguration) AddListener(key string, listener cc.ConfigurationListener, opts ...cc.Option) {
k := &cc.Options{}
for _, opt := range opts {
opt(k)
}

key = k.Group + key
l, _ := c.listeners.LoadOrStore(key, NewApolloListener())
l, _ := c.listeners.LoadOrStore(key, newApolloListener())
l.(*apolloListener).AddListener(listener)
}

Expand All @@ -109,10 +99,10 @@ func (c *apolloConfiguration) RemoveListener(key string, listener cc.Configurati
}

func getProperties(namespace string) string {
return getNamespaceName(namespace, agollo.Properties)
return getNamespaceName(namespace, agolloConstant.Properties)
}

func getNamespaceName(namespace string, configFileFormat agollo.ConfigFileFormat) string {
func getNamespaceName(namespace string, configFileFormat agolloConstant.ConfigFileFormat) string {
return fmt.Sprintf(apolloConfigFormat, namespace, configFileFormat)
}

Expand All @@ -137,7 +127,7 @@ func (c *apolloConfiguration) GetProperties(key string, opts ...cc.Option) (stri
if config == nil {
return "", errors.New(fmt.Sprintf("nothing in namespace:%s ", key))
}
return config.GetContent(agollo.Properties), nil
return config.GetContent(), nil
}

func (c *apolloConfiguration) getAddressWithProtocolPrefix(url *common.URL) string {
Expand Down
25 changes: 5 additions & 20 deletions config_center/apollo/impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ func initMockApollo(t *testing.T) *apolloConfiguration {
return configuration
}

func TestAddListener(t *testing.T) {
func TestListener(t *testing.T) {
listener := &apolloDataListener{}
listener.wg.Add(1)
listener.wg.Add(2)
apollo := initMockApollo(t)
mockConfigRes = `{
"appId": "testApplication_yang",
Expand All @@ -215,28 +215,14 @@ func TestAddListener(t *testing.T) {
},
"releaseKey": "20191104105242-0f13805d89f834a4"
}`
//test add
apollo.AddListener(mockNamespace, listener)
listener.wg.Wait()
assert.Equal(t, "registries.hangzhouzk.username", listener.event)
assert.Equal(t, "mockDubbog.properties", listener.event)
assert.Greater(t, listener.count, 0)
deleteMockJson(t)
}

func TestRemoveListener(t *testing.T) {
listener := &apolloDataListener{}
apollo := initMockApollo(t)
mockConfigRes = `{
"appId": "testApplication_yang",
"cluster": "default",
"namespaceName": "mockDubbog.properties",
"configurations": {
"registries.hangzhouzk.username": "11111"
},
"releaseKey": "20191104105242-0f13805d89f834a4"
}`
apollo.AddListener(mockNamespace, listener)
//test remove
apollo.RemoveListener(mockNamespace, listener)
assert.Equal(t, "", listener.event)
listenerCount := 0
apollo.listeners.Range(func(key, value interface{}) bool {
apolloListener := value.(*apolloListener)
Expand All @@ -247,7 +233,6 @@ func TestRemoveListener(t *testing.T) {
return true
})
assert.Equal(t, listenerCount, 0)
assert.Equal(t, listener.count, 0)
deleteMockJson(t)
}

Expand Down
38 changes: 26 additions & 12 deletions config_center/apollo/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,48 @@
package apollo

import (
"github.com/zouyx/agollo"
"github.com/zouyx/agollo/v3"
"github.com/zouyx/agollo/v3/storage"
"gopkg.in/yaml.v2"
)

import (
"github.com/apache/dubbo-go/common/logger"
"github.com/apache/dubbo-go/config_center"
"github.com/apache/dubbo-go/remoting"
)

type apolloListener struct {
listeners map[config_center.ConfigurationListener]struct{}
}

// NewApolloListener ...
func NewApolloListener() *apolloListener {
// nolint
func newApolloListener() *apolloListener {
return &apolloListener{
listeners: make(map[config_center.ConfigurationListener]struct{}, 0),
}
}

// OnChange ...
func (a *apolloListener) OnChange(changeEvent *agollo.ChangeEvent) {
for key, change := range changeEvent.Changes {
for listener := range a.listeners {
listener.Process(&config_center.ConfigChangeEvent{
ConfigType: getChangeType(change.ChangeType),
Key: key,
Value: change.NewValue,
})
}
func (a *apolloListener) OnChange(changeEvent *storage.ChangeEvent) {

}

// OnNewestChange process each listener by all changes
func (a *apolloListener) OnNewestChange(changeEvent *storage.FullChangeEvent) {
b, err := yaml.Marshal(changeEvent.Changes)
if err != nil {
logger.Errorf("apollo onNewestChange err %+v",
err)
return
}
content := string(b)
for listener := range a.listeners {
listener.Process(&config_center.ConfigChangeEvent{
ConfigType: remoting.EventTypeUpdate,
Key: changeEvent.Namespace,
Value: content,
})
}
}

Expand Down
Loading

0 comments on commit 7232064

Please sign in to comment.