Skip to content

Commit

Permalink
[ISSUE #1601] polarismesh registry center (#1620)
Browse files Browse the repository at this point in the history
* feat: try to support dubbo

* Merge 3.0 to master (#1606)

* build(deps): bump github.com/hashicorp/vault/sdk from 0.2.1 to 0.3.0 (#1552)

Bumps [github.com/hashicorp/vault/sdk](https://github.com/hashicorp/vault) from 0.2.1 to 0.3.0.
- [Release notes](https://github.com/hashicorp/vault/releases)
- [Changelog](https://github.com/hashicorp/vault/blob/main/CHANGELOG.md)
- [Commits](hashicorp/vault@sdk/v0.2.1...v0.3.0)

---
updated-dependencies:
- dependency-name: github.com/hashicorp/vault/sdk
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* delete useless codes (#1551)

* Update CHANGELOG.md

* [#1559]: adjust the startup process of the configuration center (#1560)

* [#1559]:
1. fix the startup process of the configuration center(remove error log)
2. refactor zk registry listener

* delete redundant dynamic configuration center cache

Co-authored-by: dongjianhui03 <dongjianhui03@meituan.com>

* [#1276]modify the name of the receiver to a single character (#1561)

Co-authored-by: dongjianhui03 <dongjianhui03@meituan.com>

* style(common): rename constants in camel-case style (#1563)

* style(common): rename constants in camel-case style

* style(common): rename Ttl to TTL

* fix: #1558: Set root config to global ptr in Init() function. (#1564)

* fix: #1558

* fix: change the api to start the app by config-api

* fix: in the Consumer service, the Reference config property ‘check’ use the Consumer config when omitted

* Triple upgrade to grpc (#1566)

* fix: init triple grpc

* fix: delete replace

* Fix: upgrade triple grpc

* Fix: remove unused file

* Fix decrease grpc go version to 1.14

* Fix: add server side serialization

* register not use metadata configuration.

* build(deps): bump github.com/go-resty/resty/v2 from 2.3.0 to 2.7.0 (#1579)

Bumps [github.com/go-resty/resty/v2](https://github.com/go-resty/resty) from 2.3.0 to 2.7.0.
- [Release notes](https://github.com/go-resty/resty/releases)
- [Commits](go-resty/resty@v2.3.0...v2.7.0)

---
updated-dependencies:
- dependency-name: github.com/go-resty/resty/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* build(deps): bump google.golang.org/grpc from 1.41.0 to 1.42.0 (#1578)

Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.41.0 to 1.42.0.
- [Release notes](https://github.com/grpc/grpc-go/releases)
- [Commits](grpc/grpc-go@v1.41.0...v1.42.0)

---
updated-dependencies:
- dependency-name: google.golang.org/grpc
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* build(deps): bump github.com/knadh/koanf from 1.3.0 to 1.3.2 (#1577)

Bumps [github.com/knadh/koanf](https://github.com/knadh/koanf) from 1.3.0 to 1.3.2.
- [Release notes](https://github.com/knadh/koanf/releases)
- [Commits](knadh/koanf@v1.3.0...v1.3.2)

---
updated-dependencies:
- dependency-name: github.com/knadh/koanf
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* fix: registry param

* fix: fix ns and group

* fix: integrate test

* Fix: integrate test

* fix: url fmt

* fix: nacos servicediscovery group

* Fix: enhance zk

* start application (#1571)

Co-authored-by: wangxiaowei14227 <wangxiaowei14227@autohome.com.cn>
Co-authored-by: lizhixin.lzx <lizhixin.lzx@alibaba-inc.com>
Co-authored-by: LaurenceLiZhixin <382673304@qq.com>

* graceful shutdwon filter (#1585)

Co-authored-by: wangxiaowei14227 <wangxiaowei14227@autohome.com.cn>

* Fix: some bugs and features for 3.0 (#1586)

* fix: some bugs

* Fix: remove file\k8s registry, k8s remote

* refactor listenDirEvent
1. remove CLEAR label;
2. remove register/unregister logic for watch children;
3. reorder the zk dynamic configuration code
4. adapt the gost

* hessian encode attachments return error (#1588)

* upgrade gost dependency version

* upgrade hessian to v1.9.5 (#1595)

* build(deps): bump k8s.io/apimachinery from 0.16.9 to 0.22.4 (#1600)

Bumps [k8s.io/apimachinery](https://github.com/kubernetes/apimachinery) from 0.16.9 to 0.22.4.
- [Release notes](https://github.com/kubernetes/apimachinery/releases)
- [Commits](kubernetes/apimachinery@v0.16.9...v0.22.4)

---
updated-dependencies:
- dependency-name: k8s.io/apimachinery
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* ftr: triple tracing (#1596)

* ftr: triple tracing

* fix: if-else to switch

* [fix #1590] filter single instance (#1591)

* filter single instance

* filter single instance

Co-authored-by: wangxiaowei14227 <wangxiaowei14227@autohome.com.cn>

* Ftr/triple reflect support (#1603)

* ftr: triple-reflection

* fix: comment and var name

* Fix: comment typo

* Fix: official website

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Xin.Zh <dragoncharlie@foxmail.com>
Co-authored-by: Mulavar <978007503@qq.com>
Co-authored-by: dongjianhui03 <dongjianhui03@meituan.com>
Co-authored-by: Xuewei Niu <a@nxw.name>
Co-authored-by: PhilYue <phil.yue@foxmail.com>
Co-authored-by: lizhixin.lzx <lizhixin.lzx@alibaba-inc.com>
Co-authored-by: sanxun0325 <bbz17640380550@163.com>
Co-authored-by: Xuewei Niu <justxuewei@apache.org>
Co-authored-by: zhaoyunxing <zhaoyunxing@apache.org>
Co-authored-by: wangxw <2484713618@qq.com>
Co-authored-by: wangxiaowei14227 <wangxiaowei14227@autohome.com.cn>
Co-authored-by: 望哥 <gelnyang@163.com>

* feat: support polaris

* feat: support polarismesh registry

* fix: fix cr issue

* chore: run go mod tidy to fix ci-error

* refactor: change polaris::ConsumerAPI.GetInstances => GetAllInstances

* fix github action scan error

* fix: fix go fmt error

* fix: import formatter

* fix: fix cr issue

* fix: fix code-style check error

* fix: fix cr issue

* fix: fix maybe nil error

* fix: fix lose event bug

* style: fix code style

Co-authored-by: springliao <springliao@tencent.com>
Co-authored-by: Laurence <45508533+LaurenceLiZhixin@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Xin.Zh <dragoncharlie@foxmail.com>
Co-authored-by: Mulavar <978007503@qq.com>
Co-authored-by: dongjianhui03 <dongjianhui03@meituan.com>
Co-authored-by: Xuewei Niu <a@nxw.name>
Co-authored-by: PhilYue <phil.yue@foxmail.com>
Co-authored-by: lizhixin.lzx <lizhixin.lzx@alibaba-inc.com>
Co-authored-by: sanxun0325 <bbz17640380550@163.com>
Co-authored-by: Xuewei Niu <justxuewei@apache.org>
Co-authored-by: zhaoyunxing <zhaoyunxing@apache.org>
Co-authored-by: wangxw <2484713618@qq.com>
Co-authored-by: wangxiaowei14227 <wangxiaowei14227@autohome.com.cn>
Co-authored-by: 望哥 <gelnyang@163.com>
Co-authored-by: LaurenceLiZhixin <382673304@qq.com>
  • Loading branch information
17 people authored Dec 1, 2021
1 parent 1bd06c1 commit a8fba70
Show file tree
Hide file tree
Showing 12 changed files with 1,355 additions and 1 deletion.
14 changes: 14 additions & 0 deletions common/constant/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,20 @@ const (
NacosPassword = "nacos.password"
)

const (
PolarisKey = "polaris"
PolarisDefaultRoleType = 3
PolarisConfigFilePath = "configPath"
PolarisNamespace = "namespace"
PolarisServiceToken = "token"
PolarisServiceNameSeparator = ":"
PolarisDubboPath = "DUBBOPATH"
PolarisInstanceID = "polaris.instanceID"
PolarisDefaultNamespace = "default"
PolarisDubboGroup = "dubbo.group"
PolarisClientName = "polaris-client"
)

const (
FileKey = "file"
)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ require (
github.com/natefinch/lumberjack v2.0.0+incompatible
github.com/opentracing/opentracing-go v1.2.0
github.com/pkg/errors v0.9.1
github.com/polarismesh/polaris-go v1.0.0
github.com/prometheus/client_golang v1.11.0
github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b
github.com/stretchr/testify v1.7.0
Expand All @@ -45,7 +46,6 @@ require (
go.uber.org/zap v1.19.1
google.golang.org/grpc v1.42.0
google.golang.org/protobuf v1.27.1
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/yaml.v2 v2.4.0
k8s.io/apimachinery v0.22.4
k8s.io/client-go v0.16.9
Expand Down
18 changes: 18 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ github.com/Workiva/go-datastructures v1.0.52 h1:PLSK6pwn8mYdaoaCZEMsXBpBotr4HHn9
github.com/Workiva/go-datastructures v1.0.52/go.mod h1:Z+F2Rca0qCsVYDS8z7bAGm8f3UkzuWYS/oBZz5a7VVA=
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5 h1:rFw4nCn9iMW+Vajsk51NtYIcwSTkXr+JGrMd36kTDJw=
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c=
github.com/agiledragon/gomonkey v0.0.0-20190517145658-8fa491f7b918 h1:a88Ln+jbIokfi6xoKtq10dbgp4VMg1CmHF1J42p8EyE=
github.com/agiledragon/gomonkey v0.0.0-20190517145658-8fa491f7b918/go.mod h1:2NGfXu1a80LLr2cmWXGBDaHEjb1idR6+FVlX5T3D9hw=
github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
Expand Down Expand Up @@ -339,6 +341,13 @@ github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8l
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/gonum/blas v0.0.0-20181208220705-f22b278b28ac/go.mod h1:P32wAyui1PQ58Oce/KYkOqQv8cVw1zAapXOl+dRFGbc=
github.com/gonum/floats v0.0.0-20181209220543-c233463c7e82/go.mod h1:PxC8OnwL11+aosOB5+iEPoV3picfs8tUpkVd0pDo+Kg=
github.com/gonum/integrate v0.0.0-20181209220457-a422b5c0fdf2/go.mod h1:pDgmNM6seYpwvPos3q+zxlXMsbve6mOIPucUnUOrI7Y=
github.com/gonum/internal v0.0.0-20181124074243-f884aa714029/go.mod h1:Pu4dmpkhSyOzRwuXkOgAvijx4o+4YMUJJo9OvPYMkks=
github.com/gonum/lapack v0.0.0-20181123203213-e4cdc5a0bff9/go.mod h1:XA3DeT6rxh2EAE789SSiSJNqxPaC0aE9J8NTOI0Jo/A=
github.com/gonum/matrix v0.0.0-20181209220409-c518dec07be9/go.mod h1:0EXg4mc1CNP0HCqCz+K4ts155PXIlUywf0wqN+GfPZw=
github.com/gonum/stat v0.0.0-20181125101827-41a0da705a5b/go.mod h1:Z4GIJBJO3Wa4gD4vbwQxXXZ+WHmW6E9ixmNrwvs0iZs=
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/btree v1.0.0 h1:0udJVsspx3VBr5FwtLhQQtuAsVc79tTq0ocGIPAU6qo=
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
Expand Down Expand Up @@ -420,6 +429,7 @@ github.com/hashicorp/go-immutable-radix v1.3.1/go.mod h1:0y9vanUI8NX6FsYoO3zeMjh
github.com/hashicorp/go-kms-wrapping/entropy v0.1.0/go.mod h1:d1g9WGtAunDNpek8jUIEJnBlbgKS1N2Q61QkHiZyR1g=
github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/hashicorp/go-plugin v1.0.1/go.mod h1:++UyYGoz3o5w9ZzAdZxtQKrWWP+iqPBn3cQptSMzBuY=
github.com/hashicorp/go-plugin v1.4.3/go.mod h1:5fGEH17QVwTTcR0zV7yhDPLLmFX9YSZ38b18Udy6vYQ=
Expand Down Expand Up @@ -555,6 +565,7 @@ github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFW
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s=
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/go-testing-interface v0.0.0-20171004221916-a61a99592b77/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI=
github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI=
Expand Down Expand Up @@ -648,6 +659,8 @@ github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6J
github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/polarismesh/polaris-go v1.0.0 h1:JIBANM5nfhu5knbg269kldQ58bSSV7a6AzTQk1OZwt8=
github.com/polarismesh/polaris-go v1.0.0/go.mod h1:uzNFDShCN+UhBncwwNqNVhPpI1ZXYwPlb9N/aE+/vE0=
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs=
Expand Down Expand Up @@ -720,13 +733,16 @@ github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic
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-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
github.com/soheilhy/cmux v0.1.5-0.20210205191134-5ec6847320e5 h1:GJTW+uNMIV1RKwox+T4aN0/sQlYRg78uHZf2H0aBcDw=
github.com/soheilhy/cmux v0.1.5-0.20210205191134-5ec6847320e5/go.mod h1:T7TcVDs9LWfQgPlPsdngu6I6QIoyIFZDDC6sNE1GqG0=
github.com/sony/gobreaker v0.4.1/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJOjmxWY=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
github.com/spf13/afero v1.2.2 h1:5jhuqJyZCZf2JRofRvN/nIFgIWNzPa3/Vz8mYylgbWc=
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
Expand Down Expand Up @@ -836,6 +852,7 @@ go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/goleak v1.1.11-0.20210813005559-691160354723 h1:sHOAIxRGBp443oHZIPB+HsUGaksVCXVQENPxwTfQdH4=
go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/multierr v1.2.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU=
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
Expand Down Expand Up @@ -932,6 +949,7 @@ golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200320220750-118fecf932d8/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20200421231249-e086a090c8fd/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
Expand Down
1 change: 1 addition & 0 deletions imports/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import (
_ "dubbo.apache.org/dubbo-go/v3/protocol/rest"
_ "dubbo.apache.org/dubbo-go/v3/registry/etcdv3"
_ "dubbo.apache.org/dubbo-go/v3/registry/nacos"
_ "dubbo.apache.org/dubbo-go/v3/registry/polaris"
_ "dubbo.apache.org/dubbo-go/v3/registry/protocol"
_ "dubbo.apache.org/dubbo-go/v3/registry/servicediscovery"
_ "dubbo.apache.org/dubbo-go/v3/registry/zookeeper"
Expand Down
133 changes: 133 additions & 0 deletions registry/polaris/core.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*
* 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 polaris

import (
"sync"
"time"
)

import (
"github.com/polarismesh/polaris-go/api"
"github.com/polarismesh/polaris-go/pkg/model"
)

import (
"dubbo.apache.org/dubbo-go/v3/config_center"
"dubbo.apache.org/dubbo-go/v3/remoting"
)

type subscriber func(remoting.EventType, []model.Instance)

// PolarisServiceWatcher
type PolarisServiceWatcher struct {
consumer api.ConsumerAPI
subscribeParam *api.WatchServiceRequest
lock *sync.RWMutex
subscribers []subscriber
execOnce *sync.Once
}

// newPolarisWatcher create PolarisServiceWatcher to do watch service action
func newPolarisWatcher(param *api.WatchServiceRequest, consumer api.ConsumerAPI) (*PolarisServiceWatcher, error) {
watcher := &PolarisServiceWatcher{
subscribeParam: param,
consumer: consumer,
lock: &sync.RWMutex{},
subscribers: make([]subscriber, 0),
execOnce: &sync.Once{},
}
return watcher, nil
}

// AddSubscriber add subscriber into watcher's subscribers
func (watcher *PolarisServiceWatcher) AddSubscriber(subscriber func(remoting.EventType, []model.Instance)) {

watcher.lazyRun()

watcher.lock.Lock()
defer watcher.lock.Unlock()

watcher.subscribers = append(watcher.subscribers, subscriber)
}

// lazyRun Delayed execution, only triggered when AddSubscriber is called, and will only be executed once
func (watcher *PolarisServiceWatcher) lazyRun() {
watcher.execOnce.Do(func() {
go watcher.startWatch()
})
}

// startWatch start run work to watch target service by polaris
func (watcher *PolarisServiceWatcher) startWatch() {

for {
resp, err := watcher.consumer.WatchService(watcher.subscribeParam)
if err != nil {
time.Sleep(time.Duration(500 * time.Millisecond))
continue
}

watcher.notifyAllSubscriber(&config_center.ConfigChangeEvent{
Value: resp.GetAllInstancesResp.Instances,
ConfigType: remoting.EventTypeAdd,
})

select {
case event := <-resp.EventChannel:
eType := event.GetSubScribeEventType()
if eType == api.EventInstance {
insEvent := event.(*model.InstanceEvent)
if insEvent.AddEvent != nil {
watcher.notifyAllSubscriber(&config_center.ConfigChangeEvent{
Value: insEvent.AddEvent.Instances,
ConfigType: remoting.EventTypeAdd,
})
}
if insEvent.UpdateEvent != nil {
instances := make([]model.Instance, len(insEvent.UpdateEvent.UpdateList))
for i := range insEvent.UpdateEvent.UpdateList {
instances[i] = insEvent.UpdateEvent.UpdateList[i].After
}
watcher.notifyAllSubscriber(&config_center.ConfigChangeEvent{
Value: instances,
ConfigType: remoting.EventTypeUpdate,
})
}
if insEvent.DeleteEvent != nil {
watcher.notifyAllSubscriber(&config_center.ConfigChangeEvent{
Value: insEvent.DeleteEvent.Instances,
ConfigType: remoting.EventTypeDel,
})
}
}
}
}
}

// notifyAllSubscriber notify config_center.ConfigChangeEvent to all subscriber
func (watcher *PolarisServiceWatcher) notifyAllSubscriber(event *config_center.ConfigChangeEvent) {
watcher.lock.RLock()
defer watcher.lock.RUnlock()

for i := 0; i < len(watcher.subscribers); i++ {
subscriber := watcher.subscribers[i]
subscriber(event.ConfigType, event.Value.([]model.Instance))
}

}
118 changes: 118 additions & 0 deletions registry/polaris/listener.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* 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 polaris

import (
"bytes"
"net/url"
"strconv"
)

import (
gxchan "github.com/dubbogo/gost/container/chan"

perrors "github.com/pkg/errors"

"github.com/polarismesh/polaris-go/pkg/model"
)

import (
"dubbo.apache.org/dubbo-go/v3/common"
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/common/logger"
"dubbo.apache.org/dubbo-go/v3/config_center"
"dubbo.apache.org/dubbo-go/v3/registry"
)

type polarisListener struct {
watcher *PolarisServiceWatcher
listenUrl *common.URL
events *gxchan.UnboundedChan
closeCh chan struct{}
}

// NewPolarisListener new polaris listener
func NewPolarisListener(url *common.URL) (*polarisListener, error) {
listener := &polarisListener{
listenUrl: url,
events: gxchan.NewUnboundedChan(32),
closeCh: make(chan struct{}),
}
return listener, nil
}

// Next returns next service event once received
func (pl *polarisListener) Next() (*registry.ServiceEvent, error) {
for {
select {
case <-pl.closeCh:
logger.Warnf("polaris listener is close!listenUrl:%+v", pl.listenUrl)
return nil, perrors.New("listener stopped")
case val := <-pl.events.Out():
e, _ := val.(*config_center.ConfigChangeEvent)
logger.Debugf("got polaris event %s", e)
instance := e.Value.(model.Instance)
return &registry.ServiceEvent{Action: e.ConfigType, Service: generateUrl(instance)}, nil
}
}
}

// Close closes this listener
func (pl *polarisListener) Close() {
// TODO need to add UnWatch in polaris
close(pl.closeCh)
}

func getSubscribeName(url *common.URL) string {
var buffer bytes.Buffer
buffer.Write([]byte(common.DubboNodes[common.PROVIDER]))
appendParam(&buffer, url, constant.InterfaceKey)
return buffer.String()
}

func generateUrl(instance model.Instance) *common.URL {
if instance.GetMetadata() == nil {
logger.Errorf("polaris instance metadata is empty,instance:%+v", instance)
return nil
}
path := instance.GetMetadata()["path"]
myInterface := instance.GetMetadata()["interface"]
if len(path) == 0 && len(myInterface) == 0 {
logger.Errorf("polaris instance metadata does not have both path key and interface key,instance:%+v", instance)
return nil
}
if len(path) == 0 && len(myInterface) != 0 {
path = "/" + myInterface
}
protocol := instance.GetProtocol()
if len(protocol) == 0 {
logger.Errorf("polaris instance metadata does not have protocol key,instance:%+v", instance)
return nil
}
urlMap := url.Values{}
for k, v := range instance.GetMetadata() {
urlMap.Set(k, v)
}
return common.NewURLWithOptions(
common.WithIp(instance.GetHost()),
common.WithPort(strconv.Itoa(int(instance.GetPort()))),
common.WithProtocol(protocol),
common.WithParams(urlMap),
common.WithPath(path),
)
}
Loading

0 comments on commit a8fba70

Please sign in to comment.