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 zk register code #355

Merged
merged 1 commit into from
Feb 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
63 changes: 33 additions & 30 deletions config_center/zookeeper/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
)

import (
"github.com/dubbogo/go-zookeeper/zk"
perrors "github.com/pkg/errors"
"github.com/samuel/go-zookeeper/zk"
)

import (
Expand All @@ -37,7 +37,11 @@ import (
"github.com/apache/dubbo-go/remoting/zookeeper"
)

const ZkClient = "zk config_center"
const (
// ZkClient
//zookeeper client name
ZkClient = "zk config_center"
)

type zookeeperDynamicConfiguration struct {
url *common.URL
Expand Down Expand Up @@ -134,10 +138,9 @@ func (c *zookeeperDynamicConfiguration) GetProperties(key string, opts ...config
content, _, err := c.client.GetContent(c.rootPath + "/" + key)
if err != nil {
return "", perrors.WithStack(err)
} else {
return string(content), nil
}

return string(content), nil
}

//For zookeeper, getConfig and getConfigs have the same meaning.
Expand All @@ -156,57 +159,57 @@ func (c *zookeeperDynamicConfiguration) SetParser(p parser.ConfigurationParser)
c.parser = p
}

func (r *zookeeperDynamicConfiguration) ZkClient() *zookeeper.ZookeeperClient {
return r.client
func (c *zookeeperDynamicConfiguration) ZkClient() *zookeeper.ZookeeperClient {
return c.client
}

func (r *zookeeperDynamicConfiguration) SetZkClient(client *zookeeper.ZookeeperClient) {
r.client = client
func (c *zookeeperDynamicConfiguration) SetZkClient(client *zookeeper.ZookeeperClient) {
c.client = client
}

func (r *zookeeperDynamicConfiguration) ZkClientLock() *sync.Mutex {
return &r.cltLock
func (c *zookeeperDynamicConfiguration) ZkClientLock() *sync.Mutex {
return &c.cltLock
}

func (r *zookeeperDynamicConfiguration) WaitGroup() *sync.WaitGroup {
return &r.wg
func (c *zookeeperDynamicConfiguration) WaitGroup() *sync.WaitGroup {
return &c.wg
}

func (r *zookeeperDynamicConfiguration) GetDone() chan struct{} {
return r.done
func (c *zookeeperDynamicConfiguration) Done() chan struct{} {
return c.done
}

func (r *zookeeperDynamicConfiguration) GetUrl() common.URL {
return *r.url
func (c *zookeeperDynamicConfiguration) GetUrl() common.URL {
return *c.url
}

func (r *zookeeperDynamicConfiguration) Destroy() {
if r.listener != nil {
r.listener.Close()
func (c *zookeeperDynamicConfiguration) Destroy() {
if c.listener != nil {
c.listener.Close()
}
close(r.done)
r.wg.Wait()
r.closeConfigs()
close(c.done)
c.wg.Wait()
c.closeConfigs()
}

func (r *zookeeperDynamicConfiguration) IsAvailable() bool {
func (c *zookeeperDynamicConfiguration) IsAvailable() bool {
select {
case <-r.done:
case <-c.done:
return false
default:
return true
}
}

func (r *zookeeperDynamicConfiguration) closeConfigs() {
r.cltLock.Lock()
defer r.cltLock.Unlock()
func (c *zookeeperDynamicConfiguration) closeConfigs() {
c.cltLock.Lock()
defer c.cltLock.Unlock()
logger.Infof("begin to close provider zk client")
// Close the old client first to close the tmp node
r.client.Close()
r.client = nil
c.client.Close()
c.client = nil
}

func (r *zookeeperDynamicConfiguration) RestartCallBack() bool {
func (c *zookeeperDynamicConfiguration) RestartCallBack() bool {
return true
}
2 changes: 1 addition & 1 deletion config_center/zookeeper/impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
)

import (
"github.com/samuel/go-zookeeper/zk"
"github.com/dubbogo/go-zookeeper/zk"
"github.com/stretchr/testify/assert"
)

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect
github.com/creasty/defaults v1.3.0
github.com/dubbogo/getty v1.3.2
github.com/dubbogo/go-zookeeper v1.0.0
github.com/dubbogo/gost v1.5.2
github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect
github.com/go-errors/errors v1.0.1 // indirect
Expand All @@ -37,7 +38,6 @@ require (
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
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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ github.com/docker/go-units v0.3.3 h1:Xk8S3Xj5sLGlG5g67hJmYMmUgXv5N4PhkjJHHqrwnTk
github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/dubbogo/getty v1.3.2 h1:l1KVSs/1CtTKbIPTrkTtBT6S9ddvmswDGoAnnl2CDpM=
github.com/dubbogo/getty v1.3.2/go.mod h1:ANbVQ9tbpZ2b0xdR8nRrgS/oXIsZAeRxzvPSOn/7mbk=
github.com/dubbogo/go-zookeeper v1.0.0 h1:RsYdlGwhDW+iKXM3eIIcvt34P2swLdmQfuIJxsHlGoM=
github.com/dubbogo/go-zookeeper v1.0.0/go.mod h1:fn6n2CAEer3novYgk9ULLwAjuV8/g4DdC2ENwRb6E+c=
github.com/dubbogo/gost v1.5.1 h1:oG5dzaWf1KYynBaBoUIOkgT+YD0niHV6xxI0Odq7hDg=
github.com/dubbogo/gost v1.5.1/go.mod h1:pPTjVyoJan3aPxBPNUX0ADkXjPibLo+/Ib0/fADXSG8=
github.com/dubbogo/gost v1.5.2 h1:ri/03971hdpnn3QeCU+4UZgnRNGDXLDGDucR/iozZm8=
Expand Down Expand Up @@ -410,8 +412,6 @@ github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6So
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/ryanuber/go-glob v0.0.0-20170128012129-256dc444b735 h1:7YvPJVmEeFHR1Tj9sZEYsmarJEQfMVYpd/Vyy/A8dqE=
github.com/ryanuber/go-glob v0.0.0-20170128012129-256dc444b735/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc=
github.com/samuel/go-zookeeper v0.0.0-20180130194729-c4fab1ac1bec h1:6ncX5ko6B9LntYM0YBRXkiSaZMmLYeZ/NWcmeB43mMY=
github.com/samuel/go-zookeeper v0.0.0-20180130194729-c4fab1ac1bec/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E=
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 h1:nn5Wsu0esKSJiIVhscUtVbo7ada43DJhG55ua/hjS5I=
Expand Down
Loading