From 6d5f7cc3a8c30da7c4ca1d7fa31251616b7526a8 Mon Sep 17 00:00:00 2001 From: Albumen Kevin Date: Mon, 28 Nov 2022 15:38:20 +0800 Subject: [PATCH 01/35] Bump version --- .../dubbo-cluster-broadcast-1/pom.xml | 2 +- .../dubbo-cluster-loadbalance-peakewma/pom.xml | 2 +- .../dubbo-cluster-specify-address-dubbo2/pom.xml | 2 +- .../dubbo-cluster-specify-address-dubbo3/pom.xml | 2 +- .../dubbo-configcenter-consul/pom.xml | 2 +- .../dubbo-configcenter-etcd/pom.xml | 4 ++-- dubbo-extensions-dependencies-bom/pom.xml | 2 +- dubbo-filter-extensions/dubbo-filter-seata/pom.xml | 2 +- .../dubbo-metadata-report-consul/pom.xml | 4 ++-- .../dubbo-metadata-report-etcd/pom.xml | 4 ++-- .../dubbo-registry-consul/pom.xml | 2 +- dubbo-registry-extensions/dubbo-registry-dns/pom.xml | 2 +- .../dubbo-registry-etcd3/pom.xml | 4 ++-- .../dubbo-registry-nameservice/pom.xml | 2 +- .../dubbo-registry-redis/pom.xml | 4 ++-- .../dubbo-registry-sofa/pom.xml | 2 +- .../dubbo-remoting-etcd3/pom.xml | 2 +- .../dubbo-remoting-grizzly/pom.xml | 2 +- .../dubbo-remoting-mina/pom.xml | 2 +- dubbo-remoting-extensions/dubbo-remoting-p2p/pom.xml | 2 +- .../dubbo-remoting-quic/pom.xml | 2 +- .../dubbo-remoting-redis/pom.xml | 2 +- dubbo-rpc-extensions/dubbo-rpc-hessian/pom.xml | 4 ++-- dubbo-rpc-extensions/dubbo-rpc-http/pom.xml | 2 +- dubbo-rpc-extensions/dubbo-rpc-memcached/pom.xml | 2 +- dubbo-rpc-extensions/dubbo-rpc-native-thrift/pom.xml | 2 +- dubbo-rpc-extensions/dubbo-rpc-redis/pom.xml | 2 +- dubbo-rpc-extensions/dubbo-rpc-rmi/pom.xml | 2 +- dubbo-rpc-extensions/dubbo-rpc-rocketmq/pom.xml | 2 +- dubbo-rpc-extensions/dubbo-rpc-webservice/pom.xml | 2 +- .../dubbo-serialization-avro/pom.xml | 2 +- .../dubbo-serialization-fastjson/pom.xml | 2 +- .../dubbo-serialization-fst/pom.xml | 2 +- .../dubbo-serialization-gson/pom.xml | 2 +- .../dubbo-serialization-kryo/pom.xml | 2 +- .../dubbo-serialization-msgpack/pom.xml | 2 +- .../dubbo-serialization-native-hession/pom.xml | 2 +- .../dubbo-serialization-protobuf/pom.xml | 2 +- .../dubbo-serialization-protostuff/pom.xml | 2 +- .../dubbo-serialization-test/pom.xml | 12 ++++++------ pom.xml | 2 +- 41 files changed, 52 insertions(+), 52 deletions(-) diff --git a/dubbo-cluster-extensions/dubbo-cluster-broadcast-1/pom.xml b/dubbo-cluster-extensions/dubbo-cluster-broadcast-1/pom.xml index 6b39109ec..03c4a8485 100644 --- a/dubbo-cluster-extensions/dubbo-cluster-broadcast-1/pom.xml +++ b/dubbo-cluster-extensions/dubbo-cluster-broadcast-1/pom.xml @@ -27,7 +27,7 @@ 4.0.0 dubbo-cluster-broadcast-1 - 1.0.1 + 1.0.2-SNAPSHOT jar diff --git a/dubbo-cluster-extensions/dubbo-cluster-loadbalance-peakewma/pom.xml b/dubbo-cluster-extensions/dubbo-cluster-loadbalance-peakewma/pom.xml index 82e85a408..21bf5f16f 100644 --- a/dubbo-cluster-extensions/dubbo-cluster-loadbalance-peakewma/pom.xml +++ b/dubbo-cluster-extensions/dubbo-cluster-loadbalance-peakewma/pom.xml @@ -27,7 +27,7 @@ 4.0.0 dubbo-cluster-loadbalance-peakewma - 1.0.1 + 1.0.2-SNAPSHOT jar diff --git a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/pom.xml b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/pom.xml index e0c3bd58f..c7e566605 100644 --- a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/pom.xml +++ b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/pom.xml @@ -27,7 +27,7 @@ 4.0.0 dubbo-cluster-specify-address-dubbo2 - 1.0.1 + 1.0.2-SNAPSHOT diff --git a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/pom.xml b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/pom.xml index 399a1a963..246bccf51 100644 --- a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/pom.xml +++ b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/pom.xml @@ -27,7 +27,7 @@ 4.0.0 dubbo-cluster-specify-address-dubbo3 - 1.0.1 + 1.0.2-SNAPSHOT diff --git a/dubbo-configcenter-extensions/dubbo-configcenter-consul/pom.xml b/dubbo-configcenter-extensions/dubbo-configcenter-consul/pom.xml index a1db35ff3..8581386c5 100644 --- a/dubbo-configcenter-extensions/dubbo-configcenter-consul/pom.xml +++ b/dubbo-configcenter-extensions/dubbo-configcenter-consul/pom.xml @@ -26,7 +26,7 @@ 4.0.0 dubbo-configcenter-consul - 1.0.1 + 1.0.2-SNAPSHOT diff --git a/dubbo-configcenter-extensions/dubbo-configcenter-etcd/pom.xml b/dubbo-configcenter-extensions/dubbo-configcenter-etcd/pom.xml index 0a70afc43..3078cca42 100644 --- a/dubbo-configcenter-extensions/dubbo-configcenter-etcd/pom.xml +++ b/dubbo-configcenter-extensions/dubbo-configcenter-etcd/pom.xml @@ -28,7 +28,7 @@ 4.0.0 dubbo-configcenter-etcd - 1.0.1 + 1.0.2-SNAPSHOT jar ${project.artifactId} The etcd implementation of the config-center api @@ -57,7 +57,7 @@ org.apache.dubbo.extensions dubbo-remoting-etcd3 - 1.0.1 + 1.0.2-SNAPSHOT diff --git a/dubbo-extensions-dependencies-bom/pom.xml b/dubbo-extensions-dependencies-bom/pom.xml index 10b9c87c0..10dd00472 100644 --- a/dubbo-extensions-dependencies-bom/pom.xml +++ b/dubbo-extensions-dependencies-bom/pom.xml @@ -89,7 +89,7 @@ - 1.0.3 + 1.0.4-SNAPSHOT 3.1.2 5.2.9.RELEASE 2.4.1 diff --git a/dubbo-filter-extensions/dubbo-filter-seata/pom.xml b/dubbo-filter-extensions/dubbo-filter-seata/pom.xml index 8c43b597b..9f9120037 100644 --- a/dubbo-filter-extensions/dubbo-filter-seata/pom.xml +++ b/dubbo-filter-extensions/dubbo-filter-seata/pom.xml @@ -28,7 +28,7 @@ dubbo-filter-seata ${project.artifactId} - 1.0.1 + 1.0.2-SNAPSHOT diff --git a/dubbo-metadata-report-extensions/dubbo-metadata-report-consul/pom.xml b/dubbo-metadata-report-extensions/dubbo-metadata-report-consul/pom.xml index f1a39fe91..d1cb758b5 100644 --- a/dubbo-metadata-report-extensions/dubbo-metadata-report-consul/pom.xml +++ b/dubbo-metadata-report-extensions/dubbo-metadata-report-consul/pom.xml @@ -26,7 +26,7 @@ 4.0.0 - 1.0.1 + 1.0.2-SNAPSHOT dubbo-metadata-report-consul @@ -39,7 +39,7 @@ org.apache.dubbo.extensions dubbo-configcenter-consul - 1.0.1 + 1.0.2-SNAPSHOT com.ecwid.consul diff --git a/dubbo-metadata-report-extensions/dubbo-metadata-report-etcd/pom.xml b/dubbo-metadata-report-extensions/dubbo-metadata-report-etcd/pom.xml index 167bb138a..9a6f2609d 100644 --- a/dubbo-metadata-report-extensions/dubbo-metadata-report-etcd/pom.xml +++ b/dubbo-metadata-report-extensions/dubbo-metadata-report-etcd/pom.xml @@ -27,7 +27,7 @@ 4.0.0 - 1.0.1 + 1.0.2-SNAPSHOT dubbo-metadata-report-etcd @@ -44,7 +44,7 @@ org.apache.dubbo.extensions dubbo-remoting-etcd3 - 1.0.1 + 1.0.2-SNAPSHOT io.etcd diff --git a/dubbo-registry-extensions/dubbo-registry-consul/pom.xml b/dubbo-registry-extensions/dubbo-registry-consul/pom.xml index 7ac2289c9..6d54af330 100644 --- a/dubbo-registry-extensions/dubbo-registry-consul/pom.xml +++ b/dubbo-registry-extensions/dubbo-registry-consul/pom.xml @@ -25,7 +25,7 @@ 4.0.0 - 1.0.1 + 1.0.2-SNAPSHOT dubbo-registry-consul diff --git a/dubbo-registry-extensions/dubbo-registry-dns/pom.xml b/dubbo-registry-extensions/dubbo-registry-dns/pom.xml index 6e07e4858..dbe3942f8 100644 --- a/dubbo-registry-extensions/dubbo-registry-dns/pom.xml +++ b/dubbo-registry-extensions/dubbo-registry-dns/pom.xml @@ -29,7 +29,7 @@ dubbo-registry-dns jar ${project.artifactId} - 1.0.1 + 1.0.2-SNAPSHOT The DNS registry module of Dubbo project diff --git a/dubbo-registry-extensions/dubbo-registry-etcd3/pom.xml b/dubbo-registry-extensions/dubbo-registry-etcd3/pom.xml index 484daffe8..c2de8847c 100644 --- a/dubbo-registry-extensions/dubbo-registry-etcd3/pom.xml +++ b/dubbo-registry-extensions/dubbo-registry-etcd3/pom.xml @@ -25,7 +25,7 @@ 4.0.0 - 1.0.1 + 1.0.2-SNAPSHOT dubbo-registry-etcd3 jar ${project.artifactId} @@ -45,7 +45,7 @@ org.apache.dubbo.extensions dubbo-remoting-etcd3 - 1.0.1 + 1.0.2-SNAPSHOT diff --git a/dubbo-registry-extensions/dubbo-registry-nameservice/pom.xml b/dubbo-registry-extensions/dubbo-registry-nameservice/pom.xml index c8b7fc6ec..deeaa905a 100644 --- a/dubbo-registry-extensions/dubbo-registry-nameservice/pom.xml +++ b/dubbo-registry-extensions/dubbo-registry-nameservice/pom.xml @@ -25,7 +25,7 @@ ${revision} ../pom.xml - 1.0.0 + 1.0.1-SNAPSHOT 4.0.0 dubbo-registry-nameservice dubbo-registry-nameservice diff --git a/dubbo-registry-extensions/dubbo-registry-redis/pom.xml b/dubbo-registry-extensions/dubbo-registry-redis/pom.xml index 807b9af8a..01c091b12 100644 --- a/dubbo-registry-extensions/dubbo-registry-redis/pom.xml +++ b/dubbo-registry-extensions/dubbo-registry-redis/pom.xml @@ -23,7 +23,7 @@ 4.0.0 - 1.0.1 + 1.0.2-SNAPSHOT dubbo-registry-redis jar ${project.artifactId} @@ -40,7 +40,7 @@ org.apache.dubbo.extensions dubbo-remoting-redis - 1.0.1 + 1.0.2-SNAPSHOT redis.clients diff --git a/dubbo-registry-extensions/dubbo-registry-sofa/pom.xml b/dubbo-registry-extensions/dubbo-registry-sofa/pom.xml index cf623ad3c..5d9486b3e 100644 --- a/dubbo-registry-extensions/dubbo-registry-sofa/pom.xml +++ b/dubbo-registry-extensions/dubbo-registry-sofa/pom.xml @@ -24,7 +24,7 @@ 4.0.0 - 1.0.1 + 1.0.2-SNAPSHOT dubbo-registry-sofa ${project.artifactId} The SOFARegistry module of Dubbo project diff --git a/dubbo-remoting-extensions/dubbo-remoting-etcd3/pom.xml b/dubbo-remoting-extensions/dubbo-remoting-etcd3/pom.xml index ab351e8bb..bca7da7b8 100644 --- a/dubbo-remoting-extensions/dubbo-remoting-etcd3/pom.xml +++ b/dubbo-remoting-extensions/dubbo-remoting-etcd3/pom.xml @@ -27,7 +27,7 @@ 4.0.0 - 1.0.1 + 1.0.2-SNAPSHOT dubbo-remoting-etcd3 jar ${project.artifactId} diff --git a/dubbo-remoting-extensions/dubbo-remoting-grizzly/pom.xml b/dubbo-remoting-extensions/dubbo-remoting-grizzly/pom.xml index f528d5430..4d0dc517f 100644 --- a/dubbo-remoting-extensions/dubbo-remoting-grizzly/pom.xml +++ b/dubbo-remoting-extensions/dubbo-remoting-grizzly/pom.xml @@ -23,7 +23,7 @@ 4.0.0 - 1.0.1 + 1.0.2-SNAPSHOT dubbo-remoting-grizzly jar ${project.artifactId} diff --git a/dubbo-remoting-extensions/dubbo-remoting-mina/pom.xml b/dubbo-remoting-extensions/dubbo-remoting-mina/pom.xml index 2195406ba..de20a9421 100644 --- a/dubbo-remoting-extensions/dubbo-remoting-mina/pom.xml +++ b/dubbo-remoting-extensions/dubbo-remoting-mina/pom.xml @@ -23,7 +23,7 @@ 4.0.0 - 1.0.1 + 1.0.2-SNAPSHOT dubbo-remoting-mina jar ${project.artifactId} diff --git a/dubbo-remoting-extensions/dubbo-remoting-p2p/pom.xml b/dubbo-remoting-extensions/dubbo-remoting-p2p/pom.xml index 452abbf0a..8961e35fc 100644 --- a/dubbo-remoting-extensions/dubbo-remoting-p2p/pom.xml +++ b/dubbo-remoting-extensions/dubbo-remoting-p2p/pom.xml @@ -23,7 +23,7 @@ 4.0.0 - 1.0.1 + 1.0.2-SNAPSHOT dubbo-remoting-p2p jar ${project.artifactId} diff --git a/dubbo-remoting-extensions/dubbo-remoting-quic/pom.xml b/dubbo-remoting-extensions/dubbo-remoting-quic/pom.xml index 4c265c63b..627e3d194 100644 --- a/dubbo-remoting-extensions/dubbo-remoting-quic/pom.xml +++ b/dubbo-remoting-extensions/dubbo-remoting-quic/pom.xml @@ -29,7 +29,7 @@ 4.0.0 dubbo-remoting-quic - 1.0.1 + 1.0.2-SNAPSHOT diff --git a/dubbo-remoting-extensions/dubbo-remoting-redis/pom.xml b/dubbo-remoting-extensions/dubbo-remoting-redis/pom.xml index bd8e44c70..f8c982b3b 100644 --- a/dubbo-remoting-extensions/dubbo-remoting-redis/pom.xml +++ b/dubbo-remoting-extensions/dubbo-remoting-redis/pom.xml @@ -23,7 +23,7 @@ 4.0.0 - 1.0.1 + 1.0.2-SNAPSHOT dubbo-remoting-redis jar diff --git a/dubbo-rpc-extensions/dubbo-rpc-hessian/pom.xml b/dubbo-rpc-extensions/dubbo-rpc-hessian/pom.xml index 6e3a3f47d..b37c0d290 100644 --- a/dubbo-rpc-extensions/dubbo-rpc-hessian/pom.xml +++ b/dubbo-rpc-extensions/dubbo-rpc-hessian/pom.xml @@ -24,7 +24,7 @@ 4.0.0 dubbo-rpc-hessian - 1.0.1 + 1.0.2-SNAPSHOT jar ${project.artifactId} @@ -64,7 +64,7 @@ org.apache.dubbo.extensions dubbo-serialization-native-hession - 1.0.1 + 1.0.2-SNAPSHOT org.springframework diff --git a/dubbo-rpc-extensions/dubbo-rpc-http/pom.xml b/dubbo-rpc-extensions/dubbo-rpc-http/pom.xml index 20e439564..2aa4ca317 100644 --- a/dubbo-rpc-extensions/dubbo-rpc-http/pom.xml +++ b/dubbo-rpc-extensions/dubbo-rpc-http/pom.xml @@ -26,7 +26,7 @@ 4.0.0 dubbo-rpc-http - 1.0.1 + 1.0.2-SNAPSHOT The JSON-RPC module of dubbo project diff --git a/dubbo-rpc-extensions/dubbo-rpc-memcached/pom.xml b/dubbo-rpc-extensions/dubbo-rpc-memcached/pom.xml index 1bd0df659..0af66f7dc 100644 --- a/dubbo-rpc-extensions/dubbo-rpc-memcached/pom.xml +++ b/dubbo-rpc-extensions/dubbo-rpc-memcached/pom.xml @@ -24,7 +24,7 @@ 4.0.0 dubbo-rpc-memcached - 1.0.1 + 1.0.2-SNAPSHOT jar ${project.artifactId} The memcached rpc module of dubbo project diff --git a/dubbo-rpc-extensions/dubbo-rpc-native-thrift/pom.xml b/dubbo-rpc-extensions/dubbo-rpc-native-thrift/pom.xml index a34eecb17..42b39f191 100644 --- a/dubbo-rpc-extensions/dubbo-rpc-native-thrift/pom.xml +++ b/dubbo-rpc-extensions/dubbo-rpc-native-thrift/pom.xml @@ -27,7 +27,7 @@ jar ${project.artifactId} The thrift rpc module of dubbo project - 1.0.1 + 1.0.2-SNAPSHOT false diff --git a/dubbo-rpc-extensions/dubbo-rpc-redis/pom.xml b/dubbo-rpc-extensions/dubbo-rpc-redis/pom.xml index 9cf2ad64a..b0bff3714 100644 --- a/dubbo-rpc-extensions/dubbo-rpc-redis/pom.xml +++ b/dubbo-rpc-extensions/dubbo-rpc-redis/pom.xml @@ -24,7 +24,7 @@ 4.0.0 dubbo-rpc-redis - 1.0.1 + 1.0.2-SNAPSHOT jar ${project.artifactId} The redis rpc module of dubbo project diff --git a/dubbo-rpc-extensions/dubbo-rpc-rmi/pom.xml b/dubbo-rpc-extensions/dubbo-rpc-rmi/pom.xml index 5223045d7..c9facd79c 100644 --- a/dubbo-rpc-extensions/dubbo-rpc-rmi/pom.xml +++ b/dubbo-rpc-extensions/dubbo-rpc-rmi/pom.xml @@ -25,7 +25,7 @@ dubbo-rpc-rmi jar - 1.0.1 + 1.0.2-SNAPSHOT The rmi rpc module of dubbo project false diff --git a/dubbo-rpc-extensions/dubbo-rpc-rocketmq/pom.xml b/dubbo-rpc-extensions/dubbo-rpc-rocketmq/pom.xml index 7668ccc80..b84c414f8 100644 --- a/dubbo-rpc-extensions/dubbo-rpc-rocketmq/pom.xml +++ b/dubbo-rpc-extensions/dubbo-rpc-rocketmq/pom.xml @@ -25,7 +25,7 @@ ${revision} ../pom.xml - 1.0.0 + 1.0.1-SNAPSHOT dubbo-rpc-rocketmq dubbo-rpc-rocketmq diff --git a/dubbo-rpc-extensions/dubbo-rpc-webservice/pom.xml b/dubbo-rpc-extensions/dubbo-rpc-webservice/pom.xml index bfb7ad9dc..8539b04a8 100644 --- a/dubbo-rpc-extensions/dubbo-rpc-webservice/pom.xml +++ b/dubbo-rpc-extensions/dubbo-rpc-webservice/pom.xml @@ -26,7 +26,7 @@ dubbo-rpc-webservice jar ${project.artifactId} - 1.0.1 + 1.0.2-SNAPSHOT The webservice rpc module of dubbo project false diff --git a/dubbo-serialization-extensions/dubbo-serialization-avro/pom.xml b/dubbo-serialization-extensions/dubbo-serialization-avro/pom.xml index 60066299c..ac11acbe0 100644 --- a/dubbo-serialization-extensions/dubbo-serialization-avro/pom.xml +++ b/dubbo-serialization-extensions/dubbo-serialization-avro/pom.xml @@ -26,7 +26,7 @@ dubbo-serialization-avro jar ${project.artifactId} - 1.0.1 + 1.0.2-SNAPSHOT The avro serialization module of dubbo project false diff --git a/dubbo-serialization-extensions/dubbo-serialization-fastjson/pom.xml b/dubbo-serialization-extensions/dubbo-serialization-fastjson/pom.xml index 6be286e88..cf2586ac0 100644 --- a/dubbo-serialization-extensions/dubbo-serialization-fastjson/pom.xml +++ b/dubbo-serialization-extensions/dubbo-serialization-fastjson/pom.xml @@ -27,7 +27,7 @@ limitations under the License. dubbo-serialization-fastjson jar ${project.artifactId} - 1.0.1 + 1.0.2-SNAPSHOT The fastjson serialization module of dubbo project false diff --git a/dubbo-serialization-extensions/dubbo-serialization-fst/pom.xml b/dubbo-serialization-extensions/dubbo-serialization-fst/pom.xml index 03ffe78e9..f8a60ac5c 100644 --- a/dubbo-serialization-extensions/dubbo-serialization-fst/pom.xml +++ b/dubbo-serialization-extensions/dubbo-serialization-fst/pom.xml @@ -26,7 +26,7 @@ dubbo-serialization-fst jar ${project.artifactId} - 1.0.1 + 1.0.2-SNAPSHOT The fst serialization module of dubbo project false diff --git a/dubbo-serialization-extensions/dubbo-serialization-gson/pom.xml b/dubbo-serialization-extensions/dubbo-serialization-gson/pom.xml index d2c4f2ab4..fcc82ea8c 100644 --- a/dubbo-serialization-extensions/dubbo-serialization-gson/pom.xml +++ b/dubbo-serialization-extensions/dubbo-serialization-gson/pom.xml @@ -26,7 +26,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more dubbo-serialization-gson jar ${project.artifactId} - 1.0.1 + 1.0.2-SNAPSHOT The GSON serialization implement for dubbo false diff --git a/dubbo-serialization-extensions/dubbo-serialization-kryo/pom.xml b/dubbo-serialization-extensions/dubbo-serialization-kryo/pom.xml index 043b81e06..fb887df92 100644 --- a/dubbo-serialization-extensions/dubbo-serialization-kryo/pom.xml +++ b/dubbo-serialization-extensions/dubbo-serialization-kryo/pom.xml @@ -27,7 +27,7 @@ limitations under the License. dubbo-serialization-kryo jar ${project.artifactId} - 1.0.1 + 1.0.2-SNAPSHOT The kryo serialization module of dubbo project false diff --git a/dubbo-serialization-extensions/dubbo-serialization-msgpack/pom.xml b/dubbo-serialization-extensions/dubbo-serialization-msgpack/pom.xml index 00ae32426..960ba07d0 100644 --- a/dubbo-serialization-extensions/dubbo-serialization-msgpack/pom.xml +++ b/dubbo-serialization-extensions/dubbo-serialization-msgpack/pom.xml @@ -25,7 +25,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more ../pom.xml dubbo-serialization-msgpack - 1.0.1 + 1.0.2-SNAPSHOT jar ${project.artifactId} The Msgpack serialization implement for dubbo diff --git a/dubbo-serialization-extensions/dubbo-serialization-native-hession/pom.xml b/dubbo-serialization-extensions/dubbo-serialization-native-hession/pom.xml index 7efd97587..0a1157e6a 100644 --- a/dubbo-serialization-extensions/dubbo-serialization-native-hession/pom.xml +++ b/dubbo-serialization-extensions/dubbo-serialization-native-hession/pom.xml @@ -25,7 +25,7 @@ limitations under the License. dubbo-serialization-native-hession - 1.0.1 + 1.0.2-SNAPSHOT jar ${project.artifactId} The native-hession serialization module of dubbo project diff --git a/dubbo-serialization-extensions/dubbo-serialization-protobuf/pom.xml b/dubbo-serialization-extensions/dubbo-serialization-protobuf/pom.xml index 5a1f46384..f9a65d481 100644 --- a/dubbo-serialization-extensions/dubbo-serialization-protobuf/pom.xml +++ b/dubbo-serialization-extensions/dubbo-serialization-protobuf/pom.xml @@ -26,7 +26,7 @@ limitations under the License. dubbo-serialization-protobuf jar ${project.artifactId} - 1.0.1 + 1.0.2-SNAPSHOT The protobuf serialization module of dubbo project false diff --git a/dubbo-serialization-extensions/dubbo-serialization-protostuff/pom.xml b/dubbo-serialization-extensions/dubbo-serialization-protostuff/pom.xml index 8d0514cab..4fc39f858 100644 --- a/dubbo-serialization-extensions/dubbo-serialization-protostuff/pom.xml +++ b/dubbo-serialization-extensions/dubbo-serialization-protostuff/pom.xml @@ -28,7 +28,7 @@ limitations under the License. dubbo-serialization-protostuff jar ${project.artifactId} - 1.0.1 + 1.0.2-SNAPSHOT The protostuff serialization module of dubbo project diff --git a/dubbo-serialization-extensions/dubbo-serialization-test/pom.xml b/dubbo-serialization-extensions/dubbo-serialization-test/pom.xml index 80f6f4e81..ebd814006 100644 --- a/dubbo-serialization-extensions/dubbo-serialization-test/pom.xml +++ b/dubbo-serialization-extensions/dubbo-serialization-test/pom.xml @@ -38,7 +38,7 @@ org.apache.dubbo.extensions dubbo-serialization-protostuff - 1.0.1 + 1.0.2-SNAPSHOT gson @@ -48,7 +48,7 @@ org.apache.dubbo.extensions dubbo-serialization-protobuf - 1.0.1 + 1.0.2-SNAPSHOT gson @@ -59,22 +59,22 @@ org.apache.dubbo.extensions dubbo-serialization-kryo - 1.0.1 + 1.0.2-SNAPSHOT org.apache.dubbo.extensions dubbo-serialization-avro - 1.0.1 + 1.0.2-SNAPSHOT org.apache.dubbo.extensions dubbo-serialization-fastjson - 1.0.1 + 1.0.2-SNAPSHOT org.apache.dubbo.extensions dubbo-serialization-fst - 1.0.1 + 1.0.2-SNAPSHOT org.apache.dubbo diff --git a/pom.xml b/pom.xml index d0acf56f3..eb91379fd 100644 --- a/pom.xml +++ b/pom.xml @@ -97,7 +97,7 @@ - 1.0.3 + 1.0.4-SNAPSHOT 5.6.0 3.11.1 From 9312264235fd906d7a5b7a150ae3731b3dcfd82b Mon Sep 17 00:00:00 2001 From: wxbty <38374721+wxbty@users.noreply.github.com> Date: Mon, 5 Dec 2022 11:16:03 +0800 Subject: [PATCH 02/35] [Dubbo-SPECIFY-ADDRESS]support v2 ip spec (#179) --- .../UserSpecifiedAddressRouter.java | 178 +++++++++++++++--- ...mmon.threadpool.manager.ExecutorRepository | 1 + .../UserSpecifiedAddressRouterTest.java | 47 +++-- 3 files changed, 187 insertions(+), 39 deletions(-) create mode 100644 dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/src/main/resources/META-INF/dubbo/org.apache.dubbo.common.threadpool.manager.ExecutorRepository diff --git a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressRouter.java b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressRouter.java index 7c8bd6e61..139ce5c9c 100644 --- a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressRouter.java +++ b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressRouter.java @@ -17,37 +17,61 @@ package org.apache.dubbo.rpc.cluster.specifyaddress; import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.URLBuilder; +import org.apache.dubbo.common.extension.ExtensionLoader; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.threadpool.manager.ExecutorRepository; +import org.apache.dubbo.common.utils.ClassUtils; import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; +import org.apache.dubbo.rpc.Protocol; import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.cluster.router.AbstractRouter; import java.util.Collections; import java.util.HashMap; import java.util.LinkedList; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Iterator; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; -public class UserSpecifiedAddressRouter extends AbstractRouter { +import static org.apache.dubbo.common.constants.CommonConstants.DUBBO; +import static org.apache.dubbo.common.constants.CommonConstants.MONITOR_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; + + +public class UserSpecifiedAddressRouter extends AbstractRouter { private final static Logger logger = LoggerFactory.getLogger(UserSpecifiedAddressRouter.class); // protected for ut purpose protected static int EXPIRE_TIME = 10 * 60 * 1000; - private volatile List> invokers = Collections.emptyList(); - private volatile Map> ip2Invoker; - private volatile Map> address2Invoker; + private volatile List> invokers = Collections.emptyList(); + private volatile Map> ip2Invoker; + private volatile Map> address2Invoker; + private final Protocol protocol; private final Lock cacheLock = new ReentrantLock(); + private final ScheduledExecutorService scheduledExecutorService; + private final AtomicBoolean launchRemovalTask = new AtomicBoolean(false); + + + private final Map> newInvokerCache = new LinkedHashMap<>(16, 0.75f, true); + public UserSpecifiedAddressRouter(URL referenceUrl) { super(referenceUrl); + this.protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension(); + this.scheduledExecutorService = ExtensionLoader.getExtensionLoader(ExecutorRepository.class).getDefaultExtension().nextScheduledExecutor(); } @Override @@ -73,14 +97,14 @@ public List> route(List> invokers, URL url, Invocation // 2. check if set address url if (address.getUrlAddress() != null) { - Invoker invoker = getInvokerByURL(address, invocation); + Invoker invoker = getInvokerByURL(address); result.add((Invoker) invoker); return result; } // 3. check if set ip and port if (StringUtils.isNotEmpty(address.getIp())) { - Invoker invoker = getInvokerByIp(address, invocation); + Invoker invoker = getInvokerByIp(address); result.add((Invoker) invoker); return result; } @@ -88,7 +112,7 @@ public List> route(List> invokers, URL url, Invocation return invokers; } - private Invoker getInvokerByURL(Address address, Invocation invocation) { + private Invoker getInvokerByURL(Address address) { tryLoadSpecifiedMap(); // try to find in directory @@ -112,11 +136,11 @@ private Invoker getInvokerByURL(Address address, Invocation invocation) { } } - // create new one - throw new RpcException("User specified server address not support refer new url in Dubbo 2.x. Please upgrade to Dubbo 3.x and use dubbo-cluster-specify-address-dubbo3."); + URL newUrl = rebuildAddress(address, getUrl()); + return getOrBuildInvokerCache(newUrl); } - public Invoker getInvokerByIp(Address address, Invocation invocation) { + public Invoker getInvokerByIp(Address address) { tryLoadSpecifiedMap(); String ip = address.getIp(); @@ -136,29 +160,31 @@ public Invoker getInvokerByIp(Address address, Invocation invocation) { } if (!address.isNeedToCreate()) { - throwException(invocation, address); + throwException(address); } - throw new RpcException("User specified server address not support refer new url in Dubbo 2.x. Please upgrade to Dubbo 3.x and use dubbo-cluster-specify-address-dubbo3."); + URL newUrl = buildAddress(invokers, address, getUrl()); + return getOrBuildInvokerCache(newUrl); } - private void throwException(Invocation invocation, Address address) { + + private void throwException(Address address) { throw new RpcException("user specified server address : [" + address + "] is not a valid provider for service: [" - + getUrl().getServiceKey() + "]"); + + getUrl().getServiceKey() + "]"); } - private Map> processIp(List> invokerList) { - Map> ip2Invoker = new HashMap<>(); - for (Invoker invoker : invokerList) { + private Map> processIp(List> invokerList) { + Map> ip2Invoker = new HashMap<>(); + for (Invoker invoker : invokerList) { ip2Invoker.put(invoker.getUrl().getHost(), invoker); } return Collections.unmodifiableMap(ip2Invoker); } - private Map> processAddress(List> addresses) { - Map> address2Invoker = new HashMap<>(); - for (Invoker invoker : addresses) { + private Map> processAddress(List> addresses) { + Map> address2Invoker = new HashMap<>(); + for (Invoker invoker : addresses) { address2Invoker.put(invoker.getUrl().getHost() + ":" + invoker.getUrl().getPort(), invoker); } return Collections.unmodifiableMap(address2Invoker); @@ -166,19 +192,19 @@ private Map> processAddress(List> addresses) { // For ut only @Deprecated - protected Map> getIp2Invoker() { + protected Map> getIp2Invoker() { return ip2Invoker; } // For ut only @Deprecated - protected Map> getAddress2Invoker() { + protected Map> getAddress2Invoker() { return address2Invoker; } // For ut only @Deprecated - protected List> getInvokers() { + protected List> getInvokers() { return invokers; } @@ -190,7 +216,7 @@ private void tryLoadSpecifiedMap() { if (ip2Invoker != null) { return; } - List> invokers = this.invokers; + List> invokers = this.invokers; if (CollectionUtils.isEmpty(invokers)) { address2Invoker = Collections.unmodifiableMap(new HashMap<>()); ip2Invoker = Collections.unmodifiableMap(new HashMap<>()); @@ -200,4 +226,108 @@ private void tryLoadSpecifiedMap() { ip2Invoker = processIp(invokers); } } + + + public URL buildAddress(List> invokers, Address address, URL consumerUrl) { + if (!invokers.isEmpty()) { + URL template = invokers.iterator().next().getUrl(); + template = template.setHost(address.getIp()); + if (address.getPort() != 0) { + template = template.setPort(address.getPort()); + } + return template; + } else { + String ip = address.getIp(); + int port = address.getPort(); + if (port == 0) { + port = ExtensionLoader.getExtensionLoader(Protocol.class).getDefaultExtension().getDefaultPort(); + } + return copyConsumerUrl(consumerUrl, ip, port, new HashMap<>()); + } + } + + private URL copyConsumerUrl(URL url, String ip, int port, Map parameters) { + return URLBuilder.from(url) + .setHost(ip) + .setPort(port) + .setProtocol(url.getProtocol() == null ? DUBBO : url.getProtocol()) + .setPath(url.getPath()) + .clearParameters() + .addParameters(parameters) + .removeParameter(MONITOR_KEY) + .build(); + } + + public URL rebuildAddress(Address address, URL consumerUrl) { + URL url = address.getUrlAddress(); + Map parameters = new HashMap<>(url.getParameters()); + parameters.put(VERSION_KEY, consumerUrl.getParameter(VERSION_KEY, "0.0.0")); + parameters.put(GROUP_KEY, consumerUrl.getParameter(GROUP_KEY)); + parameters.putAll(consumerUrl.getParameters()); + return copyConsumerUrl(consumerUrl, url.getHost(), url.getPort(),parameters); + } + + private Invoker getOrBuildInvokerCache(URL url) { + logger.info("Unable to find a proper invoker from directory. Try to create new invoker. New URL: " + url); + + InvokerCache cache; + cacheLock.lock(); + try { + cache = newInvokerCache.get(url); + } finally { + cacheLock.unlock(); + } + if (cache == null) { + Invoker invoker = refer(url); + cacheLock.lock(); + try { + cache = newInvokerCache.get(url); + if (cache == null) { + cache = new InvokerCache<>(invoker); + newInvokerCache.put(url, cache); + if (launchRemovalTask.compareAndSet(false, true)) { + scheduledExecutorService.scheduleAtFixedRate(new RemovalTask(), EXPIRE_TIME / 2, EXPIRE_TIME / 2, TimeUnit.MILLISECONDS); + } + } else { + invoker.destroy(); + } + } finally { + cacheLock.unlock(); + } + } + return cache.getInvoker(); + } + + private Invoker refer(URL url) { + + try { + Class interfaceClass = Class.forName(getUrl().getServiceInterface(), true, ClassUtils.getClassLoader()); + return this.protocol.refer(interfaceClass, url); + } catch (ClassNotFoundException e) { + throw new IllegalStateException(e.getMessage(), e); + } + } + + private class RemovalTask implements Runnable { + @Override + public void run() { + cacheLock.lock(); + try { + if (newInvokerCache.size() > 0) { + Iterator>> iterator = newInvokerCache.entrySet().iterator(); + while (iterator.hasNext()) { + Map.Entry> entry = iterator.next(); + if (System.currentTimeMillis() - entry.getValue().getLastAccess() > EXPIRE_TIME) { + iterator.remove(); + entry.getValue().getInvoker().destroy(); + } else { + break; + } + } + } + } finally { + cacheLock.unlock(); + } + } + } } diff --git a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/src/main/resources/META-INF/dubbo/org.apache.dubbo.common.threadpool.manager.ExecutorRepository b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/src/main/resources/META-INF/dubbo/org.apache.dubbo.common.threadpool.manager.ExecutorRepository new file mode 100644 index 000000000..44199b021 --- /dev/null +++ b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/src/main/resources/META-INF/dubbo/org.apache.dubbo.common.threadpool.manager.ExecutorRepository @@ -0,0 +1 @@ +default=org.apache.dubbo.common.threadpool.manager.DefaultExecutorRepository \ No newline at end of file diff --git a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/src/test/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressRouterTest.java b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/src/test/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressRouterTest.java index 372eb0fb5..34cef9e83 100644 --- a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/src/test/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressRouterTest.java +++ b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/src/test/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressRouterTest.java @@ -37,8 +37,8 @@ public class UserSpecifiedAddressRouterTest { @BeforeEach public void setup() { - consumerUrl = URL.valueOf("127.0.0.2:20880").addParameter("Test", "Value").addParameter("check", "false") - .addParameter("version", "1.0.0").addParameter("group", "Dubbo"); + consumerUrl = URL.valueOf("127.0.0.2:20880").addParameter("Test", "Value").addParameter("check", "false").addParameter("lazy","true") + .addParameter("version", "1.0.0").addParameter("group", "Dubbo").addParameter("interface", DemoService.class.getName()); } @Test @@ -56,7 +56,7 @@ public void testNotify() { // no address Assertions.assertThrows(RpcException.class, () -> - userSpecifiedAddressRouter.route(Collections.emptyList(), consumerUrl, Mockito.mock(Invocation.class))); + userSpecifiedAddressRouter.route(Collections.emptyList(), consumerUrl, Mockito.mock(Invocation.class))); Assertions.assertNotNull(userSpecifiedAddressRouter.getAddress2Invoker()); Assertions.assertNotNull(userSpecifiedAddressRouter.getIp2Invoker()); @@ -72,18 +72,23 @@ public void testGetInvokerByURL() { UserSpecifiedAddressRouter userSpecifiedAddressRouter = new UserSpecifiedAddressRouter(consumerUrl); Assertions.assertEquals(Collections.emptyList(), - userSpecifiedAddressRouter.route(Collections.emptyList(), consumerUrl, Mockito.mock(Invocation.class))); + userSpecifiedAddressRouter.route(Collections.emptyList(), consumerUrl, Mockito.mock(Invocation.class))); - UserSpecifiedAddressUtil.setAddress(new Address(URL.valueOf("127.0.0.1:20880"))); - Assertions.assertThrows(RpcException.class, () -> - userSpecifiedAddressRouter.route(Collections.emptyList(), consumerUrl, Mockito.mock(Invocation.class))); + UserSpecifiedAddressUtil.setAddress(new Address(URL.valueOf("127.0.0.1:20880?lazy=true"))); + List> invokers = userSpecifiedAddressRouter.route(Collections.emptyList(), consumerUrl, Mockito.mock(Invocation.class)); + Assertions.assertEquals(1, invokers.size()); + Assertions.assertEquals("127.0.0.1", invokers.get(0).getUrl().getHost()); + Assertions.assertEquals(20880, invokers.get(0).getUrl().getPort()); + Assertions.assertEquals("Value", invokers.get(0).getUrl().getParameter("Test")); + Assertions.assertEquals(consumerUrl.getParameter("version"), invokers.get(0).getUrl().getParameter("version")); + Assertions.assertEquals(consumerUrl.getParameter("group"), invokers.get(0).getUrl().getParameter("group")); Invoker mockInvoker = Mockito.mock(Invoker.class); Mockito.when(mockInvoker.getUrl()).thenReturn(URL.valueOf("simple://127.0.0.1:20880?Test1=Value")); userSpecifiedAddressRouter.notify(new LinkedList<>(Collections.singletonList(mockInvoker))); UserSpecifiedAddressUtil.setAddress(new Address(URL.valueOf("127.0.0.1:20880"))); - List> invokers = userSpecifiedAddressRouter.route(new LinkedList<>(Collections.singletonList(mockInvoker)), consumerUrl, Mockito.mock(Invocation.class)); + invokers = userSpecifiedAddressRouter.route(new LinkedList<>(Collections.singletonList(mockInvoker)), consumerUrl, Mockito.mock(Invocation.class)); Assertions.assertEquals(1, invokers.size()); Assertions.assertEquals(mockInvoker, invokers.get(0)); @@ -100,8 +105,15 @@ public void testGetInvokerByURL() { Assertions.assertEquals(mockInvoker, invokers.get(0)); UserSpecifiedAddressUtil.setAddress(new Address(URL.valueOf("127.0.0.1:20880?Test1=Value&Test2=Value&Test3=Value"))); - Assertions.assertThrows(RpcException.class, () -> - userSpecifiedAddressRouter.route(Collections.emptyList(), consumerUrl, Mockito.mock(Invocation.class))); + invokers = userSpecifiedAddressRouter.route(Collections.emptyList(), consumerUrl, Mockito.mock(Invocation.class)); + Assertions.assertEquals(1, invokers.size()); + Assertions.assertEquals("127.0.0.1", invokers.get(0).getUrl().getHost()); + Assertions.assertEquals(20880, invokers.get(0).getUrl().getPort()); + Assertions.assertEquals("Value", invokers.get(0).getUrl().getParameter("Test1")); + Assertions.assertEquals("Value", invokers.get(0).getUrl().getParameter("Test2")); + Assertions.assertEquals("Value", invokers.get(0).getUrl().getParameter("Test3")); + Assertions.assertEquals(consumerUrl.getParameter("version"), invokers.get(0).getUrl().getParameter("version")); + Assertions.assertEquals(consumerUrl.getParameter("group"), invokers.get(0).getUrl().getParameter("group")); } @Test @@ -109,7 +121,7 @@ public void testGetInvokerByIp() { UserSpecifiedAddressRouter userSpecifiedAddressRouter = new UserSpecifiedAddressRouter(consumerUrl); Assertions.assertEquals(Collections.emptyList(), - userSpecifiedAddressRouter.route(Collections.emptyList(), consumerUrl, Mockito.mock(Invocation.class))); + userSpecifiedAddressRouter.route(Collections.emptyList(), consumerUrl, Mockito.mock(Invocation.class))); Invoker mockInvoker = Mockito.mock(Invoker.class); Mockito.when(mockInvoker.getUrl()).thenReturn(consumerUrl); @@ -128,14 +140,19 @@ public void testGetInvokerByIp() { UserSpecifiedAddressUtil.setAddress(new Address("127.0.0.2", 20770)); Assertions.assertThrows(RpcException.class, () -> - userSpecifiedAddressRouter.route(new LinkedList<>(Collections.singletonList(mockInvoker)), consumerUrl, Mockito.mock(Invocation.class))); + userSpecifiedAddressRouter.route(new LinkedList<>(Collections.singletonList(mockInvoker)), consumerUrl, Mockito.mock(Invocation.class))); UserSpecifiedAddressUtil.setAddress(new Address("127.0.0.3", 20880)); Assertions.assertThrows(RpcException.class, () -> - userSpecifiedAddressRouter.route(new LinkedList<>(Collections.singletonList(mockInvoker)), consumerUrl, Mockito.mock(Invocation.class))); + userSpecifiedAddressRouter.route(new LinkedList<>(Collections.singletonList(mockInvoker)), consumerUrl, Mockito.mock(Invocation.class))); UserSpecifiedAddressUtil.setAddress(new Address("127.0.0.2", 20770, true)); - Assertions.assertThrows(RpcException.class, () -> - userSpecifiedAddressRouter.route(Collections.emptyList(), consumerUrl, Mockito.mock(Invocation.class))); + invokers = userSpecifiedAddressRouter.route(Collections.emptyList(), consumerUrl, Mockito.mock(Invocation.class)); + Assertions.assertEquals(1, invokers.size()); + Assertions.assertEquals("127.0.0.2", invokers.get(0).getUrl().getHost()); + Assertions.assertEquals(20770, invokers.get(0).getUrl().getPort()); + Assertions.assertEquals("Value", invokers.get(0).getUrl().getParameter("Test")); + Assertions.assertEquals(consumerUrl.getParameter("version"), invokers.get(0).getUrl().getParameter("version")); + Assertions.assertEquals(consumerUrl.getParameter("group"), invokers.get(0).getUrl().getParameter("group")); } } From 12a5931ed2f217e4f63c6ce6c927a519c502aa22 Mon Sep 17 00:00:00 2001 From: andrew shan <45474304+andrewshan@users.noreply.github.com> Date: Tue, 13 Dec 2022 16:44:02 +0800 Subject: [PATCH 03/35] Add polaris extensions support (#184) --- .../dubbo-cluster-polaris-dubbo2/pom.xml | 46 +++ .../rpc/cluster/router/InstanceInvoker.java | 227 +++++++++++++++ .../rpc/cluster/router/PolarisRouter.java | 131 +++++++++ .../cluster/router/PolarisRouterFactory.java | 30 ++ ...org.apache.dubbo.rpc.cluster.RouterFactory | 1 + dubbo-cluster-extensions/pom.xml | 1 + dubbo-extensions-dependencies-bom/pom.xml | 6 + .../dubbo-filter-polaris-dubbo2/pom.xml | 46 +++ .../filter/dubbo2/CircuitBreakerFilter.java | 35 +++ .../dubbo/filter/dubbo2/RateLimitFilter.java | 107 +++++++ .../dubbo/filter/dubbo2/ReportFilter.java | 90 ++++++ .../dubbo/org.apache.dubbo.rpc.Filter | 3 + dubbo-filter-extensions/pom.xml | 1 + .../dubbo-registry-polaris/pom.xml | 48 ++++ .../registry/polaris/PolarisRegistry.java | 264 ++++++++++++++++++ .../polaris/PolarisRegistryFactory.java | 32 +++ .../PolarisRegistryServiceDiscovery.java | 227 +++++++++++++++ .../polaris/PolarisRegistryUtils.java | 51 ++++ .../PolarisServiceDiscoveryFactory.java | 30 ++ .../registry/polaris/task/FetchTask.java | 64 +++++ .../polaris/task/InstancesHandler.java | 28 ++ .../registry/polaris/task/TaskScheduler.java | 73 +++++ .../registry/polaris/task/WatchTask.java | 55 ++++ .../org.apache.dubbo.registry.RegistryFactory | 1 + ...bo.registry.client.ServiceDiscoveryFactory | 1 + .../PolarisRegistryServiceDiscoveryTest.java | 152 ++++++++++ .../registry/polaris/PolarisRegistryTest.java | 133 +++++++++ dubbo-registry-extensions/pom.xml | 3 +- 28 files changed, 1885 insertions(+), 1 deletion(-) create mode 100644 dubbo-cluster-extensions/dubbo-cluster-polaris-dubbo2/pom.xml create mode 100644 dubbo-cluster-extensions/dubbo-cluster-polaris-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/router/InstanceInvoker.java create mode 100644 dubbo-cluster-extensions/dubbo-cluster-polaris-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/router/PolarisRouter.java create mode 100644 dubbo-cluster-extensions/dubbo-cluster-polaris-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/router/PolarisRouterFactory.java create mode 100644 dubbo-cluster-extensions/dubbo-cluster-polaris-dubbo2/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.cluster.RouterFactory create mode 100644 dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/pom.xml create mode 100644 dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/src/main/java/org/apache/dubbo/filter/dubbo2/CircuitBreakerFilter.java create mode 100644 dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/src/main/java/org/apache/dubbo/filter/dubbo2/RateLimitFilter.java create mode 100644 dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/src/main/java/org/apache/dubbo/filter/dubbo2/ReportFilter.java create mode 100644 dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter create mode 100644 dubbo-registry-extensions/dubbo-registry-polaris/pom.xml create mode 100644 dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/PolarisRegistry.java create mode 100644 dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/PolarisRegistryFactory.java create mode 100644 dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/PolarisRegistryServiceDiscovery.java create mode 100644 dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/PolarisRegistryUtils.java create mode 100644 dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/PolarisServiceDiscoveryFactory.java create mode 100644 dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/task/FetchTask.java create mode 100644 dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/task/InstancesHandler.java create mode 100644 dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/task/TaskScheduler.java create mode 100644 dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/task/WatchTask.java create mode 100644 dubbo-registry-extensions/dubbo-registry-polaris/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.RegistryFactory create mode 100644 dubbo-registry-extensions/dubbo-registry-polaris/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.ServiceDiscoveryFactory create mode 100644 dubbo-registry-extensions/dubbo-registry-polaris/src/test/java/org/apache/dubbo/registry/polaris/PolarisRegistryServiceDiscoveryTest.java create mode 100644 dubbo-registry-extensions/dubbo-registry-polaris/src/test/java/org/apache/dubbo/registry/polaris/PolarisRegistryTest.java diff --git a/dubbo-cluster-extensions/dubbo-cluster-polaris-dubbo2/pom.xml b/dubbo-cluster-extensions/dubbo-cluster-polaris-dubbo2/pom.xml new file mode 100644 index 000000000..0b21901c2 --- /dev/null +++ b/dubbo-cluster-extensions/dubbo-cluster-polaris-dubbo2/pom.xml @@ -0,0 +1,46 @@ + + + + + dubbo-cluster-extensions + org.apache.dubbo.extensions + ${revision} + ../pom.xml + + 4.0.0 + + dubbo-cluster-polaris-dubbo2 + dubbo-cluster-polaris-dubbo2 + 1.0.0-SNAPSHOT + Dubbo2 cluster extension for PolarisMesh, support dynamic routing capability. + + + + org.apache.dubbo + dubbo + 2.7.18 + true + + + com.tencent.polaris + polaris-adapter-dubbo + + + diff --git a/dubbo-cluster-extensions/dubbo-cluster-polaris-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/router/InstanceInvoker.java b/dubbo-cluster-extensions/dubbo-cluster-polaris-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/router/InstanceInvoker.java new file mode 100644 index 000000000..90062d157 --- /dev/null +++ b/dubbo-cluster-extensions/dubbo-cluster-polaris-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/router/InstanceInvoker.java @@ -0,0 +1,227 @@ +/* + * 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 org.apache.dubbo.rpc.cluster.router; + +import com.tencent.polaris.api.pojo.CircuitBreakerStatus; +import com.tencent.polaris.api.pojo.DefaultInstance; +import com.tencent.polaris.api.pojo.Instance; +import com.tencent.polaris.api.pojo.StatusDimension; +import com.tencent.polaris.common.registry.Consts; +import com.tencent.polaris.common.registry.ConvertUtils; +import java.util.Collection; +import java.util.Map; +import java.util.Objects; +import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.constants.CommonConstants; +import org.apache.dubbo.common.logger.Logger; +import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.rpc.Invocation; +import org.apache.dubbo.rpc.Invoker; +import org.apache.dubbo.rpc.Result; +import org.apache.dubbo.rpc.RpcException; +import org.apache.dubbo.rpc.cluster.Constants; + +public class InstanceInvoker implements Instance, Invoker { + + private static final Logger LOGGER = LoggerFactory.getLogger(InstanceInvoker.class); + + private final Invoker invoker; + + private final DefaultInstance defaultInstance; + + public InstanceInvoker(Invoker invoker, String namespace) { + this.invoker = invoker; + defaultInstance = new DefaultInstance(); + defaultInstance.setNamespace(namespace); + URL url = invoker.getUrl(); + defaultInstance.setService(url.getServiceInterface()); + defaultInstance.setHost(url.getHost()); + defaultInstance.setPort(url.getPort()); + defaultInstance.setId(url.getParameter(Consts.INSTANCE_KEY_ID)); + defaultInstance.setHealthy(Boolean.parseBoolean(url.getParameter(Consts.INSTANCE_KEY_HEALTHY))); + defaultInstance.setIsolated(Boolean.parseBoolean(url.getParameter(Consts.INSTANCE_KEY_ISOLATED))); + defaultInstance.setVersion(url.getParameter(CommonConstants.VERSION_KEY)); + defaultInstance.setWeight(url.getParameter(Constants.WEIGHT_KEY, 100)); + String circuitBreakerStr = url.getParameter(Consts.INSTANCE_KEY_CIRCUIT_BREAKER); + Map statusDimensionCircuitBreakerStatusMap = ConvertUtils + .stringToCircuitBreakers(circuitBreakerStr); + defaultInstance.getCircuitBreakerStatuses().putAll(statusDimensionCircuitBreakerStatusMap); + defaultInstance.setMetadata(url.getParameters()); + LOGGER.info(String.format("[POLARIS] construct instance from invoker, url %s, instance %s", url, defaultInstance)); + } + + @Override + public Class getInterface() { + return invoker.getInterface(); + } + + @Override + public Result invoke(Invocation invocation) throws RpcException { + return invoker.invoke(invocation); + } + + @Override + public URL getUrl() { + return invoker.getUrl(); + } + + @Override + public boolean isAvailable() { + return invoker.isAvailable(); + } + + @Override + public void destroy() { + invoker.destroy(); + } + + @Override + public String getNamespace() { + return defaultInstance.getNamespace(); + } + + @Override + public String getService() { + return defaultInstance.getService(); + } + + @Override + public String getRevision() { + return defaultInstance.getRevision(); + } + + @Override + public CircuitBreakerStatus getCircuitBreakerStatus() { + return defaultInstance.getCircuitBreakerStatus(); + } + + @Override + public Collection getStatusDimensions() { + return defaultInstance.getStatusDimensions(); + } + + @Override + public CircuitBreakerStatus getCircuitBreakerStatus(StatusDimension statusDimension) { + return defaultInstance.getCircuitBreakerStatus(statusDimension); + } + + @Override + public boolean isHealthy() { + return defaultInstance.isHealthy(); + } + + @Override + public boolean isIsolated() { + return defaultInstance.isIsolated(); + } + + @Override + public String getProtocol() { + return defaultInstance.getProtocol(); + } + + @Override + public String getId() { + return defaultInstance.getId(); + } + + @Override + public String getHost() { + return defaultInstance.getHost(); + } + + @Override + public int getPort() { + return defaultInstance.getPort(); + } + + @Override + public String getVersion() { + return defaultInstance.getVersion(); + } + + @Override + public Map getMetadata() { + return defaultInstance.getMetadata(); + } + + @Override + public boolean isEnableHealthCheck() { + return defaultInstance.isEnableHealthCheck(); + } + + @Override + public String getRegion() { + return defaultInstance.getRegion(); + } + + @Override + public String getZone() { + return defaultInstance.getZone(); + } + + @Override + public String getCampus() { + return defaultInstance.getCampus(); + } + + @Override + public int getPriority() { + return defaultInstance.getPriority(); + } + + @Override + public int getWeight() { + return defaultInstance.getWeight(); + } + + @Override + public String getLogicSet() { + return defaultInstance.getLogicSet(); + } + + @Override + public int compareTo(Instance o) { + return defaultInstance.compareTo(o); + } + + private static final String SEP_CIRCUIT_BREAKER = ","; + + private static final String SEP_CIRCUIT_BREAKER_VALUE = ":"; + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof InstanceInvoker)) { + return false; + } + InstanceInvoker that = (InstanceInvoker) o; + return Objects.equals(defaultInstance, that.defaultInstance); + } + + @Override + public int hashCode() { + return Objects.hash(defaultInstance); + } + + public Invoker getInvoker() { + return invoker; + } +} diff --git a/dubbo-cluster-extensions/dubbo-cluster-polaris-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/router/PolarisRouter.java b/dubbo-cluster-extensions/dubbo-cluster-polaris-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/router/PolarisRouter.java new file mode 100644 index 000000000..88024b914 --- /dev/null +++ b/dubbo-cluster-extensions/dubbo-cluster-polaris-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/router/PolarisRouter.java @@ -0,0 +1,131 @@ +/* + * 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 org.apache.dubbo.rpc.cluster.router; + +import com.tencent.polaris.api.pojo.Instance; +import com.tencent.polaris.api.pojo.RouteArgument; +import com.tencent.polaris.api.pojo.ServiceEventKey.EventType; +import com.tencent.polaris.api.pojo.ServiceRule; +import com.tencent.polaris.api.utils.StringUtils; +import com.tencent.polaris.client.pb.RoutingProto.Routing; +import com.tencent.polaris.common.registry.PolarisOperator; +import com.tencent.polaris.common.registry.PolarisOperators; +import com.tencent.polaris.common.router.ObjectParser; +import com.tencent.polaris.common.router.RuleHandler; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.atomic.AtomicReference; +import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.logger.Logger; +import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.rpc.Invocation; +import org.apache.dubbo.rpc.Invoker; +import org.apache.dubbo.rpc.RpcContext; +import org.apache.dubbo.rpc.RpcException; +import org.apache.dubbo.rpc.cluster.Constants; + +public class PolarisRouter extends AbstractRouter { + + private static final Logger LOGGER = LoggerFactory.getLogger(PolarisRouter.class); + + private final RuleHandler routeRuleHandler; + + private final PolarisOperator polarisOperator; + + private final AtomicReference>> invokersCache = new AtomicReference<>(); + + public PolarisRouter(URL url) { + super(url); + LOGGER.info(String.format("[POLARIS] init service router, url is %s, parameters are %s", url, + url.getParameters())); + this.priority = url.getParameter(Constants.PRIORITY_KEY, 0); + routeRuleHandler = new RuleHandler(); + polarisOperator = PolarisOperators.INSTANCE.getPolarisOperator(url.getHost(), url.getPort()); + } + + @Override + public List> route(List> invokers, URL url, Invocation invocation) throws RpcException { + if (null == invokers || invokers.size() == 0) { + return invokers; + } + if (null == polarisOperator) { + return invokers; + } + List instances = new ArrayList<>(invokers.size()); + Map> instanceInvokerMap = invokersCache.get(); + if (null == instanceInvokerMap) { + instanceInvokerMap = Collections.emptyMap(); + } + for (Invoker invoker : invokers) { + InstanceInvoker instanceInvoker = instanceInvokerMap.get(invoker.getUrl()); + if (null != instanceInvoker) { + instances.add(instanceInvoker); + } else { + instances.add(new InstanceInvoker<>(invoker, polarisOperator.getPolarisConfig().getNamespace())); + } + } + String service = url.getServiceInterface(); + ServiceRule serviceRule = polarisOperator.getServiceRule(service, EventType.ROUTING); + Object ruleObject = serviceRule.getRule(); + Set arguments = new HashSet<>(); + if (null != ruleObject) { + Routing routing = (Routing) ruleObject; + Set routeLabels = routeRuleHandler.getRouteLabels(routing); + for (String routeLabel : routeLabels) { + if (StringUtils.equals(RouteArgument.LABEL_KEY_PATH, routeLabel)) { + arguments.add(RouteArgument.buildPath(invocation.getMethodName())); + } else if (routeLabel.startsWith(RouteArgument.LABEL_KEY_HEADER)) { + String headerName = routeLabel.substring(RouteArgument.LABEL_KEY_HEADER.length()); + String value = RpcContext.getContext().getAttachment(headerName); + if (!StringUtils.isBlank(value)) { + arguments.add(RouteArgument.buildHeader(headerName, value)); + } + } else if (routeLabel.startsWith(RouteArgument.LABEL_KEY_QUERY)) { + String queryName = routeLabel.substring(RouteArgument.LABEL_KEY_QUERY.length()); + if (!StringUtils.isBlank(queryName)) { + Object value = ObjectParser.parseArgumentsByExpression(queryName, invocation.getArguments()); + if (null != value) { + arguments.add(RouteArgument.buildQuery(queryName, String.valueOf(value))); + } + } + } + } + } + LOGGER.debug(String.format("[POLARIS] list service %s, method %s, labels %s, url %s", service, + invocation.getMethodName(), arguments, url)); + List resultInstances = polarisOperator + .route(service, invocation.getMethodName(), arguments, instances); + return (List>) ((List) resultInstances); + } + + public void notify(List> invokers) { + if (null == polarisOperator) { + return; + } + Map> instanceInvokers = new HashMap<>(invokers.size()); + for (Invoker invoker : invokers) { + instanceInvokers.put(invoker.getUrl(), new InstanceInvoker<>(invoker, polarisOperator.getPolarisConfig().getNamespace())); + } + invokersCache.set(instanceInvokers); + } +} diff --git a/dubbo-cluster-extensions/dubbo-cluster-polaris-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/router/PolarisRouterFactory.java b/dubbo-cluster-extensions/dubbo-cluster-polaris-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/router/PolarisRouterFactory.java new file mode 100644 index 000000000..33b56a26d --- /dev/null +++ b/dubbo-cluster-extensions/dubbo-cluster-polaris-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/router/PolarisRouterFactory.java @@ -0,0 +1,30 @@ +/* + * 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 org.apache.dubbo.rpc.cluster.router; + +import org.apache.dubbo.common.URL; +import org.apache.dubbo.rpc.cluster.Router; +import org.apache.dubbo.rpc.cluster.RouterFactory; + +public class PolarisRouterFactory implements RouterFactory { + + @Override + public Router getRouter(URL url) { + return new PolarisRouter(url); + } +} diff --git a/dubbo-cluster-extensions/dubbo-cluster-polaris-dubbo2/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.cluster.RouterFactory b/dubbo-cluster-extensions/dubbo-cluster-polaris-dubbo2/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.cluster.RouterFactory new file mode 100644 index 000000000..35830e7d7 --- /dev/null +++ b/dubbo-cluster-extensions/dubbo-cluster-polaris-dubbo2/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.cluster.RouterFactory @@ -0,0 +1 @@ +polaris_router=org.apache.dubbo.rpc.cluster.router.PolarisRouterFactory \ No newline at end of file diff --git a/dubbo-cluster-extensions/pom.xml b/dubbo-cluster-extensions/pom.xml index c9afcaa47..f3cb4ae1f 100644 --- a/dubbo-cluster-extensions/pom.xml +++ b/dubbo-cluster-extensions/pom.xml @@ -35,6 +35,7 @@ dubbo-cluster-loadbalance-peakewma dubbo-cluster-specify-address-dubbo3 dubbo-cluster-specify-address-dubbo2 + dubbo-cluster-polaris-dubbo2 diff --git a/dubbo-extensions-dependencies-bom/pom.xml b/dubbo-extensions-dependencies-bom/pom.xml index 10dd00472..3475eb7c0 100644 --- a/dubbo-extensions-dependencies-bom/pom.xml +++ b/dubbo-extensions-dependencies-bom/pom.xml @@ -133,6 +133,7 @@ 1.2.11 2.0 3.0.20.Final + 0.1.3 1.2.5 @@ -484,6 +485,11 @@ + + com.tencent.polaris + polaris-adapter-dubbo + ${polaris_adapter_version} + diff --git a/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/pom.xml b/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/pom.xml new file mode 100644 index 000000000..65b677f38 --- /dev/null +++ b/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/pom.xml @@ -0,0 +1,46 @@ + + + + + dubbo-filter-extensions + org.apache.dubbo.extensions + ${revision} + ../pom.xml + + 4.0.0 + + dubbo-filter-polaris-dubbo2 + dubbo-filter-polaris-dubbo2 + 1.0.0-SNAPSHOT + Dubbo2 filter extension for PolarisMesh, support circuitbreaking, ratelimit, metric capabilities. + + + + org.apache.dubbo + dubbo + 2.7.18 + true + + + com.tencent.polaris + polaris-adapter-dubbo + + + diff --git a/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/src/main/java/org/apache/dubbo/filter/dubbo2/CircuitBreakerFilter.java b/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/src/main/java/org/apache/dubbo/filter/dubbo2/CircuitBreakerFilter.java new file mode 100644 index 000000000..80e6188f0 --- /dev/null +++ b/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/src/main/java/org/apache/dubbo/filter/dubbo2/CircuitBreakerFilter.java @@ -0,0 +1,35 @@ +/* + * 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 org.apache.dubbo.filter.dubbo2; + +import org.apache.dubbo.common.constants.CommonConstants; +import org.apache.dubbo.common.extension.Activate; +import org.apache.dubbo.rpc.Filter; +import org.apache.dubbo.rpc.Invocation; +import org.apache.dubbo.rpc.Invoker; +import org.apache.dubbo.rpc.Result; +import org.apache.dubbo.rpc.RpcException; + +@Activate(group = CommonConstants.CONSUMER) +public class CircuitBreakerFilter implements Filter { + + @Override + public Result invoke(Invoker invoker, Invocation invocation) throws RpcException { + return invoker.invoke(invocation); + } +} diff --git a/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/src/main/java/org/apache/dubbo/filter/dubbo2/RateLimitFilter.java b/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/src/main/java/org/apache/dubbo/filter/dubbo2/RateLimitFilter.java new file mode 100644 index 000000000..68411b45c --- /dev/null +++ b/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/src/main/java/org/apache/dubbo/filter/dubbo2/RateLimitFilter.java @@ -0,0 +1,107 @@ +/* + * 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 org.apache.dubbo.filter.dubbo2; + +import com.tencent.polaris.api.pojo.ServiceEventKey.EventType; +import com.tencent.polaris.api.pojo.ServiceRule; +import com.tencent.polaris.api.utils.StringUtils; +import com.tencent.polaris.client.pb.ModelProto.MatchArgument; +import com.tencent.polaris.client.pb.RateLimitProto.RateLimit; +import com.tencent.polaris.common.exception.PolarisBlockException; +import com.tencent.polaris.common.registry.PolarisOperator; +import com.tencent.polaris.common.registry.PolarisOperatorDelegate; +import com.tencent.polaris.common.router.ObjectParser; +import com.tencent.polaris.common.router.RuleHandler; +import com.tencent.polaris.ratelimit.api.rpc.Argument; +import com.tencent.polaris.ratelimit.api.rpc.QuotaResponse; +import com.tencent.polaris.ratelimit.api.rpc.QuotaResultCode; +import java.util.HashSet; +import java.util.Set; +import org.apache.dubbo.common.constants.CommonConstants; +import org.apache.dubbo.common.extension.Activate; +import org.apache.dubbo.common.logger.Logger; +import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.rpc.Filter; +import org.apache.dubbo.rpc.Invocation; +import org.apache.dubbo.rpc.Invoker; +import org.apache.dubbo.rpc.Result; +import org.apache.dubbo.rpc.RpcContext; +import org.apache.dubbo.rpc.RpcException; + +@Activate(group = CommonConstants.PROVIDER) +public class RateLimitFilter extends PolarisOperatorDelegate implements Filter { + + private static final Logger LOGGER = LoggerFactory.getLogger(RateLimitFilter.class); + + private final RuleHandler ruleHandler; + + public RateLimitFilter() { + LOGGER.info("[POLARIS] init polaris ratelimit"); + ruleHandler = new RuleHandler(); + } + + @Override + public Result invoke(Invoker invoker, Invocation invocation) throws RpcException { + String service = invoker.getInterface().getName(); + PolarisOperator polarisOperator = getPolarisOperator(); + if (null == polarisOperator) { + return invoker.invoke(invocation); + } + ServiceRule serviceRule = polarisOperator.getServiceRule(service, EventType.RATE_LIMITING); + Object ruleObject = serviceRule.getRule(); + if (null == ruleObject) { + return invoker.invoke(invocation); + } + RateLimit rateLimit = (RateLimit) ruleObject; + Set ratelimitLabels = ruleHandler.getRatelimitLabels(rateLimit); + String method = invocation.getMethodName(); + Set arguments = new HashSet<>(); + for (MatchArgument matchArgument : ratelimitLabels) { + switch (matchArgument.getType()) { + case HEADER: + String attachmentValue = RpcContext.getContext().getAttachment(matchArgument.getKey()); + if (!StringUtils.isBlank(attachmentValue)) { + arguments.add(Argument.buildHeader(matchArgument.getKey(), attachmentValue)); + } + break; + case QUERY: + Object queryValue = ObjectParser + .parseArgumentsByExpression(matchArgument.getKey(), invocation.getArguments()); + if (null != queryValue) { + arguments.add(Argument + .buildQuery(matchArgument.getKey(), String.valueOf(queryValue))); + } + break; + default: + break; + } + } + QuotaResponse quotaResponse = null; + try { + quotaResponse = polarisOperator.getQuota(service, method, arguments); + } catch (RuntimeException e) { + LOGGER.error("[POLARIS] get quota fail", e); + } + if (null != quotaResponse && quotaResponse.getCode() == QuotaResultCode.QuotaResultLimited) { + // throw block exception when ratelimit occurs + throw new RpcException(RpcException.LIMIT_EXCEEDED_EXCEPTION, new PolarisBlockException( + String.format("url=%s, info=%s", invoker.getUrl(), quotaResponse.getInfo()))); + } + return invoker.invoke(invocation); + } +} diff --git a/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/src/main/java/org/apache/dubbo/filter/dubbo2/ReportFilter.java b/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/src/main/java/org/apache/dubbo/filter/dubbo2/ReportFilter.java new file mode 100644 index 000000000..78a81d746 --- /dev/null +++ b/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/src/main/java/org/apache/dubbo/filter/dubbo2/ReportFilter.java @@ -0,0 +1,90 @@ +/* + * 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 org.apache.dubbo.filter.dubbo2; + + +import com.tencent.polaris.api.pojo.RetStatus; +import com.tencent.polaris.common.registry.PolarisOperator; +import com.tencent.polaris.common.registry.PolarisOperatorDelegate; +import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.constants.CommonConstants; +import org.apache.dubbo.common.extension.Activate; +import org.apache.dubbo.common.logger.Logger; +import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.rpc.Filter; +import org.apache.dubbo.rpc.Invocation; +import org.apache.dubbo.rpc.Invoker; +import org.apache.dubbo.rpc.Result; +import org.apache.dubbo.rpc.RpcException; + +@Activate(group = CommonConstants.CONSUMER) +public class ReportFilter extends PolarisOperatorDelegate implements Filter { + + private static final Logger LOGGER = LoggerFactory.getLogger(ReportFilter.class); + + public ReportFilter() { + LOGGER.info("[POLARIS] init polaris reporter"); + } + + @Override + public Result invoke(Invoker invoker, Invocation invocation) throws RpcException { + long startTimeMilli = System.currentTimeMillis(); + Result result = null; + Throwable exception = null; + RpcException rpcException = null; + try { + result = invoker.invoke(invocation); + } catch (Throwable e) { + exception = e; + } + if (null != result && result.hasException()) { + exception = result.getException(); + } + if (exception instanceof RpcException) { + rpcException = (RpcException) exception; + } + PolarisOperator polarisOperator = getPolarisOperator(); + if (null == polarisOperator) { + return result; + } + RetStatus retStatus = RetStatus.RetSuccess; + int code = 0; + if (null != exception) { + retStatus = RetStatus.RetFail; + if (null != rpcException) { + code = rpcException.getCode(); + if (code == RpcException.LIMIT_EXCEEDED_EXCEPTION) { + // we won't consider limit exception as error + retStatus = RetStatus.RetSuccess; + } + } else { + code = -1; + } + } + URL url = invoker.getUrl(); + long delay = System.currentTimeMillis() - startTimeMilli; + polarisOperator.reportInvokeResult(url.getServiceInterface(), invocation.getMethodName(), url.getHost(), + url.getPort(), delay, retStatus, code); + if (null != rpcException) { + throw rpcException; + } else if (null != exception) { + throw new RpcException(exception); + } + return result; + } +} diff --git a/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter b/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter new file mode 100644 index 000000000..2fb8a58c4 --- /dev/null +++ b/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter @@ -0,0 +1,3 @@ +polaris_report=org.apache.dubbo.filter.dubbo2.ReportFilter +polaris_circuitbreaker=org.apache.dubbo.filter.dubbo2.CircuitBreakerFilter +polaris_ratelimit=org.apache.dubbo.filter.dubbo2.RateLimitFilter \ No newline at end of file diff --git a/dubbo-filter-extensions/pom.xml b/dubbo-filter-extensions/pom.xml index 29ee70528..d52d741fa 100644 --- a/dubbo-filter-extensions/pom.xml +++ b/dubbo-filter-extensions/pom.xml @@ -31,5 +31,6 @@ ${revision} dubbo-filter-seata + dubbo-filter-polaris-dubbo2 diff --git a/dubbo-registry-extensions/dubbo-registry-polaris/pom.xml b/dubbo-registry-extensions/dubbo-registry-polaris/pom.xml new file mode 100644 index 000000000..ab37000fe --- /dev/null +++ b/dubbo-registry-extensions/dubbo-registry-polaris/pom.xml @@ -0,0 +1,48 @@ + + + + dubbo-registry-extensions + org.apache.dubbo.extensions + ${revision} + ../pom.xml + + 4.0.0 + + dubbo-registry-polaris + dubbo-registry-polaris + 1.0.0-SNAPSHOT + Dubbo registry extension for PolarisMesh, support instance register, discover, health-check capabilities. + + + + com.tencent.polaris + polaris-adapter-dubbo + + + org.apache.dubbo + dubbo-registry-api + true + + + org.slf4j + slf4j-api + 1.7.25 + test + + + diff --git a/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/PolarisRegistry.java b/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/PolarisRegistry.java new file mode 100644 index 000000000..31acca2f0 --- /dev/null +++ b/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/PolarisRegistry.java @@ -0,0 +1,264 @@ +/* + * 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 org.apache.dubbo.registry.polaris; + +import com.tencent.polaris.api.listener.ServiceListener; +import com.tencent.polaris.api.pojo.Instance; +import com.tencent.polaris.api.utils.StringUtils; +import com.tencent.polaris.common.registry.Consts; +import com.tencent.polaris.common.registry.ConvertUtils; +import com.tencent.polaris.common.registry.PolarisOperator; +import com.tencent.polaris.common.utils.ExtensionConsts; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicBoolean; +import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.constants.CommonConstants; +import org.apache.dubbo.common.constants.RegistryConstants; +import org.apache.dubbo.common.extension.ExtensionLoader; +import org.apache.dubbo.common.logger.Logger; +import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.ConcurrentHashSet; +import org.apache.dubbo.registry.NotifyListener; +import org.apache.dubbo.registry.polaris.task.FetchTask; +import org.apache.dubbo.registry.polaris.task.InstancesHandler; +import org.apache.dubbo.registry.polaris.task.TaskScheduler; +import org.apache.dubbo.registry.polaris.task.WatchTask; +import org.apache.dubbo.registry.support.FailbackRegistry; +import org.apache.dubbo.rpc.Filter; +import org.apache.dubbo.rpc.cluster.Constants; +import org.apache.dubbo.rpc.cluster.RouterFactory; + +public class PolarisRegistry extends FailbackRegistry { + + private static final Logger LOGGER = LoggerFactory.getLogger(PolarisRegistry.class); + + private static final TaskScheduler taskScheduler = new TaskScheduler(); + + private final Set registeredInstances = new ConcurrentHashSet<>(); + + private final AtomicBoolean destroyed = new AtomicBoolean(false); + + private final Map serviceListeners = new ConcurrentHashMap<>(); + + private final PolarisOperator polarisOperator; + + private final boolean hasCircuitBreaker; + + private final boolean hasRouter; + + public PolarisRegistry(URL url) { + super(url); + polarisOperator = PolarisRegistryUtils.getOrCreatePolarisOperator(url); + ExtensionLoader routerExtensionLoader = ExtensionLoader.getExtensionLoader(RouterFactory.class); + hasRouter = routerExtensionLoader.hasExtension(ExtensionConsts.PLUGIN_ROUTER_NAME); + ExtensionLoader filterExtensionLoader = ExtensionLoader.getExtensionLoader(Filter.class); + hasCircuitBreaker = filterExtensionLoader.hasExtension(ExtensionConsts.PLUGIN_CIRCUITBREAKER_NAME); + } + + private URL buildRouterURL(URL consumerUrl) { + URL routerURL = null; + if (hasRouter) { + URL registryURL = getUrl(); + routerURL = new URL(RegistryConstants.ROUTE_PROTOCOL, registryURL.getHost(), registryURL.getPort()); + routerURL = routerURL.setServiceInterface(CommonConstants.ANY_VALUE); + routerURL = routerURL.addParameter(Constants.ROUTER_KEY, ExtensionConsts.PLUGIN_ROUTER_NAME); + String consumerGroup = consumerUrl.getParameter(CommonConstants.GROUP_KEY); + String consumerVersion = consumerUrl.getParameter(CommonConstants.VERSION_KEY); + String consumerClassifier = consumerUrl.getParameter(CommonConstants.CLASSIFIER_KEY); + if (null != consumerGroup) { + routerURL = routerURL.addParameter(CommonConstants.GROUP_KEY, consumerGroup); + } + if (null != consumerVersion) { + routerURL = routerURL.addParameter(CommonConstants.VERSION_KEY, consumerVersion); + } + if (null != consumerClassifier) { + routerURL = routerURL.addParameter(CommonConstants.CLASSIFIER_KEY, consumerClassifier); + } + } + return routerURL; + } + + @Override + public void doRegister(URL url) { + if (!shouldRegister(url)) { + return; + } + LOGGER.info(String.format("[POLARIS] register service to polaris: %s", url.toString())); + Map metadata = new HashMap<>(url.getParameters()); + metadata.put(CommonConstants.PATH_KEY, url.getPath()); + int port = url.getPort(); + if (port > 0) { + int weight = url.getParameter(Constants.WEIGHT_KEY, Constants.DEFAULT_WEIGHT); + String version = url.getParameter(CommonConstants.VERSION_KEY, ""); + polarisOperator.register(url.getServiceInterface(), url.getHost(), port, url.getProtocol(), version, weight, + metadata); + registeredInstances.add(url); + } else { + LOGGER.warn(String.format("[POLARIS] skip register url %s for zero port value", url)); + } + } + + private boolean shouldRegister(URL url) { + return !StringUtils.equals(url.getProtocol(), CommonConstants.CONSUMER); + } + + @Override + public void doUnregister(URL url) { + if (!shouldRegister(url)) { + return; + } + LOGGER.info(String.format("[POLARIS] unregister service from polaris: %s", url.toString())); + int port = url.getPort(); + if (port > 0) { + polarisOperator.deregister(url.getServiceInterface(), url.getHost(), url.getPort()); + registeredInstances.remove(url); + } + } + + @Override + public void destroy() { + if (destroyed.compareAndSet(false, true)) { + super.destroy(); + Collection urls = Collections.unmodifiableCollection(registeredInstances); + for (URL url : urls) { + doUnregister(url); + } + PolarisRegistryUtils.removePolarisOperator(getUrl()); + polarisOperator.destroy(); + taskScheduler.destroy(); + } + } + + @Override + public void doSubscribe(URL url, NotifyListener listener) { + String service = url.getServiceInterface(); + Instance[] instances = polarisOperator.getAvailableInstances(service, !hasCircuitBreaker); + onInstances(url, listener, instances); + LOGGER.info(String.format("[POLARIS] submit watch task for service %s", service)); + PolarisInstancesHandler polarisInstancesHandler = new PolarisInstancesHandler(url, listener); + FetchTask fetchTask = new FetchTask( + url.getServiceInterface(), polarisInstancesHandler, polarisOperator, !hasCircuitBreaker); + taskScheduler.submitWatchTask(new WatchTask(url.getServiceInterface(), fetchTask, taskScheduler)); + } + + + private void onInstances(URL url, NotifyListener listener, Instance[] instances) { + LOGGER.info(String.format("[POLARIS] update instances count: %d, service: %s", null == instances ? 0 : instances.length, + url.getServiceInterface())); + List urls = new ArrayList<>(); + if (null != instances) { + for (Instance instance : instances) { + urls.add(instanceToURL(instance)); + } + } + URL routerURL = buildRouterURL(url); + if (null != routerURL) { + urls.add(routerURL); + } + PolarisRegistry.this.notify(url, listener, urls); + } + + private static URL instanceToURL(Instance instance) { + Map newMetadata = new HashMap<>(instance.getMetadata()); + boolean hasWeight = false; + if (newMetadata.containsKey(Constants.WEIGHT_KEY)) { + String weightStr = newMetadata.get(Constants.WEIGHT_KEY); + try { + int weightValue = Integer.parseInt(weightStr); + if (weightValue == instance.getWeight()) { + hasWeight = true; + } + } catch (Exception ignored) { + } + } + if (!hasWeight) { + newMetadata.put(Constants.WEIGHT_KEY, Integer.toString(instance.getWeight())); + } + newMetadata.put(Consts.INSTANCE_KEY_ID, instance.getId()); + newMetadata.put(Consts.INSTANCE_KEY_HEALTHY, Boolean.toString(instance.isHealthy())); + newMetadata.put(Consts.INSTANCE_KEY_ISOLATED, Boolean.toString(instance.isIsolated())); + newMetadata.put(Consts.INSTANCE_KEY_CIRCUIT_BREAKER, ConvertUtils.circuitBreakersToString(instance)); + clearEmptyKeys(newMetadata, new String[]{CommonConstants.VERSION_KEY, CommonConstants.GROUP_KEY}); + return new URL(instance.getProtocol(), + instance.getHost(), + instance.getPort(), + newMetadata.get(CommonConstants.PATH_KEY), + newMetadata); + } + + private static void clearEmptyKeys(Map parameters, String[] keys) { + for (String key : keys) { + String value = parameters.get(key); + if (null != value && StringUtils.isBlank(value)) { + parameters.remove(key); + } + } + } + + @Override + public void doUnsubscribe(URL url, NotifyListener listener) { + LOGGER.info(String.format("[polaris] unsubscribe service: %s", url.toString())); + taskScheduler.submitWatchTask(new Runnable() { + @Override + public void run() { + ServiceListener serviceListener = serviceListeners.remove(listener); + if (null != serviceListener) { + polarisOperator.unwatchService(url.getServiceInterface(), serviceListener); + } + } + }); + } + + public PolarisOperator getPolarisOperator() { + return polarisOperator; + } + + @Override + public boolean isAvailable() { + return true; + } + + private class PolarisInstancesHandler implements InstancesHandler { + + private final URL url; + + private final NotifyListener listener; + + public PolarisInstancesHandler(URL url, NotifyListener listener) { + this.url = url; + this.listener = listener; + } + + @Override + public void onInstances(String serviceName, Instance[] instances) { + PolarisRegistry.this.onInstances(url, listener, instances); + } + + @Override + public void onWatchSuccess(String serviceName, ServiceListener serviceListener) { + serviceListeners.put(listener, serviceListener); + } + } +} diff --git a/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/PolarisRegistryFactory.java b/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/PolarisRegistryFactory.java new file mode 100644 index 000000000..18664c5e1 --- /dev/null +++ b/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/PolarisRegistryFactory.java @@ -0,0 +1,32 @@ +/* + * 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 org.apache.dubbo.registry.polaris; + + +import org.apache.dubbo.common.URL; +import org.apache.dubbo.registry.Registry; +import org.apache.dubbo.registry.support.AbstractRegistryFactory; + +public class PolarisRegistryFactory extends AbstractRegistryFactory { + + @Override + protected Registry createRegistry(URL url) { + return new PolarisRegistry(url); + } + +} diff --git a/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/PolarisRegistryServiceDiscovery.java b/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/PolarisRegistryServiceDiscovery.java new file mode 100644 index 000000000..034da732b --- /dev/null +++ b/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/PolarisRegistryServiceDiscovery.java @@ -0,0 +1,227 @@ +/* + * 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 org.apache.dubbo.registry.polaris; + +import com.tencent.polaris.api.listener.ServiceListener; +import com.tencent.polaris.api.pojo.Instance; +import com.tencent.polaris.api.pojo.ServiceInfo; +import com.tencent.polaris.common.registry.Consts; +import com.tencent.polaris.common.registry.ConvertUtils; +import com.tencent.polaris.common.registry.PolarisOperator; +import com.tencent.polaris.common.utils.ExtensionConsts; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.constants.CommonConstants; +import org.apache.dubbo.common.extension.ExtensionLoader; +import org.apache.dubbo.common.logger.Logger; +import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.ConcurrentHashSet; +import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.metadata.MetadataInfo; +import org.apache.dubbo.registry.client.AbstractServiceDiscovery; +import org.apache.dubbo.registry.client.DefaultServiceInstance; +import org.apache.dubbo.registry.client.ServiceInstance; +import org.apache.dubbo.registry.client.event.ServiceInstancesChangedEvent; +import org.apache.dubbo.registry.client.event.listener.ServiceInstancesChangedListener; +import org.apache.dubbo.registry.polaris.task.FetchTask; +import org.apache.dubbo.registry.polaris.task.InstancesHandler; +import org.apache.dubbo.registry.polaris.task.TaskScheduler; +import org.apache.dubbo.registry.polaris.task.WatchTask; +import org.apache.dubbo.rpc.Filter; +import org.apache.dubbo.rpc.cluster.Constants; +import org.apache.dubbo.rpc.model.ApplicationModel; + +public class PolarisRegistryServiceDiscovery extends AbstractServiceDiscovery { + + private static final Logger LOGGER = LoggerFactory.getLogger(PolarisRegistryServiceDiscovery.class); + + private final PolarisOperator polarisOperator; + + private static final TaskScheduler taskScheduler = new TaskScheduler(); + + private final Set registeredInstances = new ConcurrentHashSet<>(); + + private final Map serviceListeners = new ConcurrentHashMap<>(); + + private final boolean hasCircuitBreaker; + + public PolarisRegistryServiceDiscovery(ApplicationModel applicationModel, URL registryURL) { + super(applicationModel, registryURL); + polarisOperator = PolarisRegistryUtils.getOrCreatePolarisOperator(registryURL); + ExtensionLoader filterExtensionLoader = applicationModel.getExtensionDirector() + .getExtensionLoader(Filter.class); + if (null != filterExtensionLoader) { + hasCircuitBreaker = filterExtensionLoader.hasExtension(ExtensionConsts.PLUGIN_CIRCUITBREAKER_NAME); + } else { + hasCircuitBreaker = false; + } + } + + @Override + protected void doRegister(ServiceInstance serviceInstance) throws RuntimeException { + LOGGER.info(String.format( + "[POLARIS] register %s to service %s", serviceInstance.getAddress(), serviceInstance.getServiceName())); + int weight = Constants.DEFAULT_WEIGHT; + String weightValue = serviceInstance.getMetadata(Constants.WEIGHT_KEY); + if (StringUtils.isNotBlank(weightValue)) { + try { + weight = Integer.parseInt(weightValue); + } catch (Exception e) { + LOGGER.warn(String.format("[POLARIS] fail to parse weight value %s", weightValue)); + } + } + String applicationName = serviceInstance.getMetadata(CommonConstants.APPLICATION_KEY); + if (StringUtils.isBlank(applicationName)) { + ApplicationModel applicationModel = serviceInstance.getApplicationModel(); + if (null != applicationModel) { + applicationName = applicationModel.getApplicationName(); + } + serviceInstance.putExtendParam(CommonConstants.APPLICATION_KEY, applicationName); + } + String version = serviceInstance.getMetadata(CommonConstants.VERSION_KEY, ""); + polarisOperator.register(serviceInstance.getServiceName(), serviceInstance.getHost(), serviceInstance.getPort(), + "", version, weight, serviceInstance.getAllParams()); + registeredInstances.add(serviceInstance); + } + + @Override + protected void doUnregister(ServiceInstance serviceInstance) { + LOGGER.info(String.format( + "[POLARIS] unregister %s to service %s", serviceInstance.getAddress(), serviceInstance.getServiceName())); + polarisOperator.deregister(serviceInstance.getServiceName(), serviceInstance.getHost(), serviceInstance.getPort()); + registeredInstances.remove(serviceInstance); + } + + @Override + protected void doDestroy() { + for (ServiceInstance serviceInstance : registeredInstances) { + doUnregister(serviceInstance); + } + PolarisRegistryUtils.removePolarisOperator(getUrl()); + polarisOperator.destroy(); + taskScheduler.destroy(); + } + + @Override + public Set getServices() { + List services = polarisOperator.getServices(); + Set svcNames = new HashSet<>(); + for (ServiceInfo serviceInfo : services) { + svcNames.add(serviceInfo.getService()); + } + return svcNames; + } + + @Override + public List getInstances(String serviceName) throws NullPointerException { + Instance[] availableInstances = polarisOperator.getAvailableInstances(serviceName, !hasCircuitBreaker); + List instances = new ArrayList<>(); + for (Instance availableInstance : availableInstances) { + instances.add(instanceToServiceInstance(availableInstance)); + } + return instances; + } + + @Override + public void addServiceInstancesChangedListener(ServiceInstancesChangedListener listener) + throws NullPointerException, IllegalArgumentException { + PolarisInstancesHandler polarisInstancesHandler = new PolarisInstancesHandler(listener); + for (String serviceName : listener.getServiceNames()) { + LOGGER.info(String.format("[polaris] subscribe service: %s", serviceName)); + FetchTask fetchTask = new FetchTask(serviceName, polarisInstancesHandler, polarisOperator, !hasCircuitBreaker); + taskScheduler.submitWatchTask(new WatchTask(serviceName, fetchTask, taskScheduler)); + } + } + + @Override + public void removeServiceInstancesChangedListener(ServiceInstancesChangedListener listener) { + for (String serviceName : listener.getServiceNames()) { + LOGGER.info(String.format("[polaris] unsubscribe service: %s", serviceName)); + ServiceListener serviceListener = serviceListeners.remove(serviceName); + if (null != serviceListener) { + polarisOperator.unwatchService(serviceName, serviceListener); + } + } + } + + private ServiceInstance instanceToServiceInstance(Instance instance) { + ServiceInstance serviceInstance = new DefaultServiceInstance( + instance.getService(), instance.getHost(), instance.getPort(), applicationModel); + Map newMetadata = new HashMap<>(instance.getMetadata()); + boolean hasWeight = false; + if (newMetadata.containsKey(Constants.WEIGHT_KEY)) { + String weightStr = newMetadata.get(Constants.WEIGHT_KEY); + try { + int weightValue = Integer.parseInt(weightStr); + if (weightValue == instance.getWeight()) { + hasWeight = true; + } + } catch (Exception ignored) { + } + } + if (!hasWeight) { + newMetadata.put(Constants.WEIGHT_KEY, Integer.toString(instance.getWeight())); + } + String applicationName = newMetadata.getOrDefault(CommonConstants.APPLICATION_KEY, "" ); + MetadataInfo.ServiceInfo serviceInfo = new MetadataInfo.ServiceInfo( + instance.getService(), CommonConstants.ANY_VALUE, + instance.getVersion(), + instance.getProtocol(), instance.getPort(), + newMetadata.getOrDefault(CommonConstants.PATH_KEY, ""), newMetadata); + Map serviceInfoMap = new HashMap<>(); + serviceInfoMap.put(instance.getService(), serviceInfo); + MetadataInfo metadataInfo = new MetadataInfo(applicationName, instance.getRevision(), serviceInfoMap); + serviceInstance.setServiceMetadata(metadataInfo); + serviceInstance.getMetadata().putAll(newMetadata); + + serviceInstance.putExtendParamIfAbsent(Consts.INSTANCE_KEY_ID, instance.getId()); + serviceInstance.putExtendParamIfAbsent(Consts.INSTANCE_KEY_HEALTHY, Boolean.toString(instance.isHealthy())); + serviceInstance.putExtendParamIfAbsent(Consts.INSTANCE_KEY_ISOLATED, Boolean.toString(instance.isIsolated())); + serviceInstance.putExtendParamIfAbsent(Consts.INSTANCE_KEY_CIRCUIT_BREAKER, ConvertUtils.circuitBreakersToString(instance)); + return serviceInstance; + } + + private class PolarisInstancesHandler implements InstancesHandler { + + private final ServiceInstancesChangedListener listener; + + public PolarisInstancesHandler(ServiceInstancesChangedListener listener) { + this.listener = listener; + } + + @Override + public void onInstances(String serviceName, Instance[] instances) { + List serviceInstances = new ArrayList<>(); + for (Instance instance : instances) { + serviceInstances.add(instanceToServiceInstance(instance)); + } + listener.onEvent(new ServiceInstancesChangedEvent(serviceName, serviceInstances)); + } + + @Override + public void onWatchSuccess(String serviceName, ServiceListener serviceListener) { + serviceListeners.put(serviceName, serviceListener); + } + } +} diff --git a/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/PolarisRegistryUtils.java b/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/PolarisRegistryUtils.java new file mode 100644 index 000000000..9477e9e63 --- /dev/null +++ b/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/PolarisRegistryUtils.java @@ -0,0 +1,51 @@ +/* + * 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 org.apache.dubbo.registry.polaris; + +import com.tencent.polaris.common.registry.BaseBootConfigHandler; +import com.tencent.polaris.common.registry.PolarisOperator; +import com.tencent.polaris.common.registry.PolarisOperators; +import org.apache.dubbo.common.URL; + +public class PolarisRegistryUtils { + + public static PolarisOperator getOrCreatePolarisOperator(URL registryURL) { + synchronized (PolarisOperators.INSTANCE) { + String host = registryURL.getHost(); + int port = registryURL.getPort(); + PolarisOperator existsOperator = PolarisOperators.INSTANCE.getPolarisOperator(host, port); + if (null != existsOperator) { + return existsOperator; + } else { + PolarisOperator polarisOperator = new PolarisOperator( + host, port, registryURL.getParameters(), new BaseBootConfigHandler()); + PolarisOperators.INSTANCE.addPolarisOperator(polarisOperator); + return polarisOperator; + } + } + } + + public static void removePolarisOperator(URL registryURL) { + synchronized (PolarisOperators.INSTANCE) { + String host = registryURL.getHost(); + int port = registryURL.getPort(); + PolarisOperators.INSTANCE.deletePolarisOperator(host, port); + } + } + +} diff --git a/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/PolarisServiceDiscoveryFactory.java b/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/PolarisServiceDiscoveryFactory.java new file mode 100644 index 000000000..52f9e3af6 --- /dev/null +++ b/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/PolarisServiceDiscoveryFactory.java @@ -0,0 +1,30 @@ +/* + * 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 org.apache.dubbo.registry.polaris; + +import org.apache.dubbo.common.URL; +import org.apache.dubbo.registry.client.AbstractServiceDiscoveryFactory; +import org.apache.dubbo.registry.client.ServiceDiscovery; + +public class PolarisServiceDiscoveryFactory extends AbstractServiceDiscoveryFactory { + + @Override + protected ServiceDiscovery createDiscovery(URL registryURL) { + return new PolarisRegistryServiceDiscovery(applicationModel, registryURL); + } +} diff --git a/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/task/FetchTask.java b/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/task/FetchTask.java new file mode 100644 index 000000000..7a71a09c5 --- /dev/null +++ b/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/task/FetchTask.java @@ -0,0 +1,64 @@ +/* + * 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 org.apache.dubbo.registry.polaris.task; + +import com.tencent.polaris.api.exception.PolarisException; +import com.tencent.polaris.api.pojo.Instance; +import com.tencent.polaris.common.registry.PolarisOperator; +import org.apache.dubbo.common.logger.Logger; +import org.apache.dubbo.common.logger.LoggerFactory; + +public class FetchTask implements Runnable { + + private static final Logger LOGGER = LoggerFactory.getLogger(FetchTask.class); + + private final String service; + + private final InstancesHandler handler; + + private final PolarisOperator polarisOperator; + + private final boolean includeCircuitBreak; + + public FetchTask(String service, InstancesHandler handler, PolarisOperator polarisOperator, boolean includeCircuitBreak) { + this.service = service; + this.handler = handler; + this.polarisOperator = polarisOperator; + this.includeCircuitBreak = includeCircuitBreak; + } + + public PolarisOperator getPolarisOperator() { + return polarisOperator; + } + + public InstancesHandler getHandler() { + return handler; + } + + @Override + public void run() { + Instance[] instances; + try { + instances = polarisOperator.getAvailableInstances(service, includeCircuitBreak); + } catch (PolarisException e) { + LOGGER.error(String.format("[POLARIS] fail to fetch instances for service %s", service), e); + return; + } + handler.onInstances(service, instances); + } +} diff --git a/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/task/InstancesHandler.java b/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/task/InstancesHandler.java new file mode 100644 index 000000000..fc3b71aa9 --- /dev/null +++ b/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/task/InstancesHandler.java @@ -0,0 +1,28 @@ +/* + * 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 org.apache.dubbo.registry.polaris.task; + +import com.tencent.polaris.api.listener.ServiceListener; +import com.tencent.polaris.api.pojo.Instance; + +public interface InstancesHandler { + + void onInstances(String serviceName, Instance[] instances); + + void onWatchSuccess(String serviceName, ServiceListener serviceListener); +} diff --git a/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/task/TaskScheduler.java b/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/task/TaskScheduler.java new file mode 100644 index 000000000..ca9ec6636 --- /dev/null +++ b/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/task/TaskScheduler.java @@ -0,0 +1,73 @@ +/* + * 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 org.apache.dubbo.registry.polaris.task; + +import com.tencent.polaris.client.util.NamedThreadFactory; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.atomic.AtomicBoolean; + +public class TaskScheduler { + + private final ExecutorService fetchExecutor = Executors + .newSingleThreadExecutor(new NamedThreadFactory("agent-fetch")); + + private final ExecutorService watchExecutor = Executors + .newSingleThreadExecutor(new NamedThreadFactory("agent-retry-watch")); + + private final AtomicBoolean executorDestroyed = new AtomicBoolean(false); + + private final Object lock = new Object(); + + public void submitFetchTask(Runnable fetchTask) { + if (executorDestroyed.get()) { + return; + } + synchronized (lock) { + if (executorDestroyed.get()) { + return; + } + fetchExecutor.submit(fetchTask); + } + } + + public void submitWatchTask(Runnable watchTask) { + if (executorDestroyed.get()) { + return; + } + synchronized (lock) { + if (executorDestroyed.get()) { + return; + } + watchExecutor.submit(watchTask); + } + } + + public boolean isDestroyed() { + return executorDestroyed.get(); + } + + public void destroy() { + synchronized (lock) { + if (executorDestroyed.compareAndSet(false, true)) { + fetchExecutor.shutdown(); + watchExecutor.shutdown(); + } + } + } +} diff --git a/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/task/WatchTask.java b/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/task/WatchTask.java new file mode 100644 index 000000000..1774a47c4 --- /dev/null +++ b/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/task/WatchTask.java @@ -0,0 +1,55 @@ +/* + * 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 org.apache.dubbo.registry.polaris.task; + +import com.tencent.polaris.api.listener.ServiceListener; +import com.tencent.polaris.api.pojo.ServiceChangeEvent; + +public class WatchTask implements Runnable { + + private final String service; + + private final FetchTask fetchTask; + + private final ServiceListener serviceListener; + + private final TaskScheduler taskScheduler; + + public WatchTask(String service, FetchTask fetchTask, TaskScheduler taskScheduler) { + this.service = service; + this.fetchTask = fetchTask; + this.serviceListener = new ServiceListener() { + @Override + public void onEvent(ServiceChangeEvent event) { + taskScheduler.submitFetchTask(fetchTask); + } + }; + this.taskScheduler = taskScheduler; + } + + @Override + public void run() { + boolean result = fetchTask.getPolarisOperator().watchService(service, serviceListener); + if (result) { + fetchTask.getHandler().onWatchSuccess(service, serviceListener); + taskScheduler.submitFetchTask(fetchTask); + return; + } + taskScheduler.submitWatchTask(this); + } +} diff --git a/dubbo-registry-extensions/dubbo-registry-polaris/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.RegistryFactory b/dubbo-registry-extensions/dubbo-registry-polaris/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.RegistryFactory new file mode 100644 index 000000000..bccf56ef9 --- /dev/null +++ b/dubbo-registry-extensions/dubbo-registry-polaris/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.RegistryFactory @@ -0,0 +1 @@ +polaris=org.apache.dubbo.registry.polaris.PolarisRegistryFactory \ No newline at end of file diff --git a/dubbo-registry-extensions/dubbo-registry-polaris/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.ServiceDiscoveryFactory b/dubbo-registry-extensions/dubbo-registry-polaris/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.ServiceDiscoveryFactory new file mode 100644 index 000000000..e2e23c949 --- /dev/null +++ b/dubbo-registry-extensions/dubbo-registry-polaris/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.ServiceDiscoveryFactory @@ -0,0 +1 @@ +polaris=org.apache.dubbo.registry.polaris.PolarisServiceDiscoveryFactory \ No newline at end of file diff --git a/dubbo-registry-extensions/dubbo-registry-polaris/src/test/java/org/apache/dubbo/registry/polaris/PolarisRegistryServiceDiscoveryTest.java b/dubbo-registry-extensions/dubbo-registry-polaris/src/test/java/org/apache/dubbo/registry/polaris/PolarisRegistryServiceDiscoveryTest.java new file mode 100644 index 000000000..084370e9f --- /dev/null +++ b/dubbo-registry-extensions/dubbo-registry-polaris/src/test/java/org/apache/dubbo/registry/polaris/PolarisRegistryServiceDiscoveryTest.java @@ -0,0 +1,152 @@ +/* + * 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 org.apache.dubbo.registry.polaris; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.atomic.AtomicBoolean; +import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.utils.NetUtils; +import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.config.ApplicationConfig; +import org.apache.dubbo.registry.NotifyListener; +import org.apache.dubbo.registry.client.DefaultServiceInstance; +import org.apache.dubbo.registry.client.ServiceInstance; +import org.apache.dubbo.registry.client.event.listener.ServiceInstancesChangedListener; +import org.apache.dubbo.rpc.model.ApplicationModel; +import org.apache.dubbo.rpc.model.FrameworkModel; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +public class PolarisRegistryServiceDiscoveryTest { + + private static PolarisRegistryServiceDiscovery polarisRegistryServiceDiscovery; + + private static ApplicationModel applicationModel; + + @BeforeAll + public static void setup() { + Map parameters = new HashMap<>(); + parameters.put("namespace", "dubbo-java-test"); + parameters.put("persist_enable", "false"); + URL url = new URL("polaris", "183.47.111.80", 8091, parameters); + applicationModel = FrameworkModel.defaultModel().newApplication(); + applicationModel.getApplicationConfigManager().setApplication(new ApplicationConfig("Test")); + polarisRegistryServiceDiscovery = new PolarisRegistryServiceDiscovery(applicationModel, url); + } + + @AfterAll + public static void teardown() { + if (null != polarisRegistryServiceDiscovery) { + polarisRegistryServiceDiscovery.doDestroy(); + } + } + + @Test + public void testRegister() { + int count = 10; + String svcName = "polaris-registry-test-service-register"; + String host = NetUtils.getLocalHost(); + List serviceInstances = buildInstanceUrls(svcName, host, 11300, count); + for (ServiceInstance serviceInstance : serviceInstances) { + polarisRegistryServiceDiscovery.doRegister(serviceInstance); + } + try { + Thread.sleep(5000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + try { + List instances = polarisRegistryServiceDiscovery.getInstances(svcName); + Assertions.assertEquals(count, countInstanceByHost(host, instances)); + } finally { + for (ServiceInstance serviceInstance : serviceInstances) { + polarisRegistryServiceDiscovery.doUnregister(serviceInstance); + } + } + } + + private static List buildInstanceUrls(String service, String host, int startPort, int count) { + List serviceUrls = new ArrayList<>(); + for (int i = 0; i < count; i++) { + ServiceInstance serviceInstance = new DefaultServiceInstance(service, host, startPort + i, applicationModel); + serviceUrls.add(serviceInstance); + } + return serviceUrls; + } + + @Test + public void testSubscribe() { + int count = 10; + AtomicBoolean notified = new AtomicBoolean(false); + String svcName = "polaris-registry-test-service-subscribe"; + Set services = new HashSet<>(); + services.add(svcName); + ServiceInstancesChangedListener serviceInstancesChangedListener = new ServiceInstancesChangedListener(services, polarisRegistryServiceDiscovery); + URL consumerUrl = URL.valueOf("consumer://0.0.0.0/" + svcName); + NotifyListener listener = new NotifyListener() { + @Override + public void notify(List urls) { + notified.set(true); + //notifiedCount.set(urls.size()); + } + + public ServiceInstancesChangedListener getServiceListener() { + return serviceInstancesChangedListener; + } + + public URL getConsumerUrl() { + return consumerUrl; + } + }; + String host = NetUtils.getLocalHost(); + serviceInstancesChangedListener.addListenerAndNotify(consumerUrl, listener); + polarisRegistryServiceDiscovery.addServiceInstancesChangedListener(serviceInstancesChangedListener); + List instances = buildInstanceUrls(svcName, host, 11300, count); + for (ServiceInstance instance : instances) { + polarisRegistryServiceDiscovery.doRegister(instance); + } + try { + Thread.sleep(5000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + polarisRegistryServiceDiscovery.removeServiceInstancesChangedListener(serviceInstancesChangedListener); + Assertions.assertTrue(notified.get()); + //Assertions.assertEquals(count, notifiedCount.get()); + for (ServiceInstance serviceInstance : instances) { + polarisRegistryServiceDiscovery.doUnregister(serviceInstance); + } + } + + private static int countInstanceByHost(String host, List instances) { + int count = 0; + for (ServiceInstance instance : instances) { + if (StringUtils.isEquals(host, instance.getHost())) { + count++; + } + } + return count; + } +} diff --git a/dubbo-registry-extensions/dubbo-registry-polaris/src/test/java/org/apache/dubbo/registry/polaris/PolarisRegistryTest.java b/dubbo-registry-extensions/dubbo-registry-polaris/src/test/java/org/apache/dubbo/registry/polaris/PolarisRegistryTest.java new file mode 100644 index 000000000..16c492d7e --- /dev/null +++ b/dubbo-registry-extensions/dubbo-registry-polaris/src/test/java/org/apache/dubbo/registry/polaris/PolarisRegistryTest.java @@ -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 org.apache.dubbo.registry.polaris; + +import com.tencent.polaris.api.pojo.Instance; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; +import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.utils.NetUtils; +import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.registry.NotifyListener; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +public class PolarisRegistryTest { + + private static PolarisRegistry polarisRegistry; + + @BeforeAll + public static void setup() { + Map parameters = new HashMap<>(); + parameters.put("namespace", "dubbo-java-test"); + parameters.put("persist_enable", "false"); + URL url = new URL("polaris", "183.47.111.80", 8091, parameters); + polarisRegistry = new PolarisRegistry(url); + } + + @AfterAll + public static void teardown() { + if (null != polarisRegistry) { + polarisRegistry.destroy(); + } + } + + @Test + public void testSubscribe() { + int count = 10; + AtomicBoolean notified = new AtomicBoolean(false); + String svcName = "polaris-registry-test-service-subscribe"; + URL consumerUrl = URL.valueOf("consumer://0.0.0.0/" + svcName); + NotifyListener listener = new NotifyListener() { + @Override + public void notify(List urls) { + notified.set(true); + } + }; + polarisRegistry.subscribe(consumerUrl, listener); + String host = NetUtils.getLocalHost(); + List serviceUrls = buildInstanceUrls(svcName, host, 11300, count); + try { + for (URL serviceUrl : serviceUrls) { + polarisRegistry.doRegister(serviceUrl); + } + try { + Thread.sleep(5000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + polarisRegistry.unsubscribe(consumerUrl, listener); + Assertions.assertTrue(notified.get()); + } finally { + for (URL serviceUrl : serviceUrls) { + polarisRegistry.doUnregister(serviceUrl); + } + } + } + + @Test + public void testRegister() { + String svcName = "polaris-registry-test-service-register"; + int count = 10; + String host = NetUtils.getLocalHost(); + List serviceUrls = buildInstanceUrls(svcName, host,11300, count); + for (URL serviceUrl : serviceUrls) { + polarisRegistry.doRegister(serviceUrl); + } + try { + Thread.sleep(5000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + try { + Instance[] availableInstances = polarisRegistry.getPolarisOperator().getAvailableInstances(svcName, true); + Assertions.assertEquals(count, countInstanceByHost(host, availableInstances)); + } finally { + for (URL serviceUrl : serviceUrls) { + polarisRegistry.doUnregister(serviceUrl); + } + } + } + + private static List buildInstanceUrls(String service, String host, int startPort, int count) { + List serviceUrls = new ArrayList<>(); + for (int i = 0; i < count; i++) { + URL serviceUrl = URL.valueOf("dubbo://" + host + ":" + + Integer.toString(startPort + i) + "/" + service + "?methods=test1,test2"); + serviceUrls.add(serviceUrl); + } + return serviceUrls; + } + + private static int countInstanceByHost(String host, Instance[] instances) { + int count = 0; + for (Instance instance : instances) { + if (StringUtils.isEquals(host, instance.getHost())) { + count++; + } + } + return count; + } + +} diff --git a/dubbo-registry-extensions/pom.xml b/dubbo-registry-extensions/pom.xml index d870005c4..64eb9c448 100644 --- a/dubbo-registry-extensions/pom.xml +++ b/dubbo-registry-extensions/pom.xml @@ -34,5 +34,6 @@ dubbo-registry-redis dubbo-registry-sofa dubbo-registry-nameservice - + dubbo-registry-polaris + From e98376100e58630ae2f906ce06a5d1f4181fb926 Mon Sep 17 00:00:00 2001 From: wxbty <38374721+wxbty@users.noreply.github.com> Date: Fri, 16 Dec 2022 11:07:13 +0800 Subject: [PATCH 04/35] Bugfix of retries and missing field (#182) Co-authored-by: x-shadow-man <1494445739@qq.com> --- .../pom.xml | 40 +++++++ .../rpc/cluster/specifyaddress/Address.java | 6 + .../UserSpecifiedAddressUtil.java | 0 .../specifyaddress/common}/InvokerCache.java | 9 +- .../pom.xml | 5 + .../AddressSpecifyClusterInterceptor.java} | 37 +++--- .../UserSpecifiedAddressRouter.java | 25 ++-- ...rpc.cluster.interceptor.ClusterInterceptor | 1 + .../specifyaddress/InvokerCacheTest.java | 3 +- .../UserSpecifiedAddressRouterTest.java | 66 ++++++++--- .../pom.xml | 6 + .../rpc/cluster/specifyaddress/Address.java | 111 ------------------ ....java => AddressSpecifyClusterFilter.java} | 31 +++-- ...ultUserSpecifiedServiceAddressBuilder.java | 4 +- .../UserSpecifiedAddressRouter.java | 30 +++-- ...che.dubbo.rpc.cluster.filter.ClusterFilter | 1 + .../specifyaddress/InvokerCacheTest.java | 3 +- .../UserSpecifiedAddressRouterTest.java | 79 ++++++++++--- .../UserSpecifiedAddressUtilTest.java | 2 - dubbo-cluster-extensions/pom.xml | 1 + 20 files changed, 251 insertions(+), 209 deletions(-) create mode 100644 dubbo-cluster-extensions/dubbo-cluster-specify-address-common/pom.xml rename dubbo-cluster-extensions/{dubbo-cluster-specify-address-dubbo2 => dubbo-cluster-specify-address-common}/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/Address.java (95%) rename dubbo-cluster-extensions/{dubbo-cluster-specify-address-dubbo2 => dubbo-cluster-specify-address-common}/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressUtil.java (100%) rename dubbo-cluster-extensions/{dubbo-cluster-specify-address-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress => dubbo-cluster-specify-address-common/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/common}/InvokerCache.java (83%) rename dubbo-cluster-extensions/{dubbo-cluster-specify-address-dubbo3/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressUtil.java => dubbo-cluster-specify-address-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/AddressSpecifyClusterInterceptor.java} (51%) create mode 100644 dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.cluster.interceptor.ClusterInterceptor delete mode 100644 dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/Address.java rename dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/{InvokerCache.java => AddressSpecifyClusterFilter.java} (55%) create mode 100644 dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.cluster.filter.ClusterFilter diff --git a/dubbo-cluster-extensions/dubbo-cluster-specify-address-common/pom.xml b/dubbo-cluster-extensions/dubbo-cluster-specify-address-common/pom.xml new file mode 100644 index 000000000..2720aa63f --- /dev/null +++ b/dubbo-cluster-extensions/dubbo-cluster-specify-address-common/pom.xml @@ -0,0 +1,40 @@ + + + + + dubbo-cluster-extensions + org.apache.dubbo.extensions + ${revision} + ../pom.xml + + 4.0.0 + + dubbo-cluster-specify-address-common + 1.0.2-SNAPSHOT + + + org.apache.dubbo + dubbo-common + provided + + + + + diff --git a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/Address.java b/dubbo-cluster-extensions/dubbo-cluster-specify-address-common/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/Address.java similarity index 95% rename from dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/Address.java rename to dubbo-cluster-extensions/dubbo-cluster-specify-address-common/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/Address.java index b4268bfa3..beff86740 100644 --- a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/Address.java +++ b/dubbo-cluster-extensions/dubbo-cluster-specify-address-common/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/Address.java @@ -22,6 +22,9 @@ import java.util.Objects; public class Address implements Serializable { + + public static final String name = "specifyAddress"; + // ip - priority: 3 private String ip; @@ -38,6 +41,9 @@ public Address(String ip, int port) { this.urlAddress = null; } + /** + * disableRetry default value is true, will disable failover + */ public Address(String ip, int port, boolean needToCreate) { this.ip = ip; this.port = port; diff --git a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressUtil.java b/dubbo-cluster-extensions/dubbo-cluster-specify-address-common/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressUtil.java similarity index 100% rename from dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressUtil.java rename to dubbo-cluster-extensions/dubbo-cluster-specify-address-common/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressUtil.java diff --git a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/InvokerCache.java b/dubbo-cluster-extensions/dubbo-cluster-specify-address-common/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/common/InvokerCache.java similarity index 83% rename from dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/InvokerCache.java rename to dubbo-cluster-extensions/dubbo-cluster-specify-address-common/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/common/InvokerCache.java index 52aff898b..3a1de66ab 100644 --- a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/InvokerCache.java +++ b/dubbo-cluster-extensions/dubbo-cluster-specify-address-common/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/common/InvokerCache.java @@ -14,15 +14,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.rpc.cluster.specifyaddress; +package org.apache.dubbo.rpc.cluster.specifyaddress.common; -import org.apache.dubbo.rpc.Invoker; public class InvokerCache { private long lastAccess = System.currentTimeMillis(); - private final Invoker invoker; + private final T invoker; - public InvokerCache(Invoker invoker) { + public InvokerCache(T invoker) { this.invoker = invoker; } @@ -30,7 +29,7 @@ public long getLastAccess() { return lastAccess; } - public Invoker getInvoker() { + public T getInvoker() { lastAccess = System.currentTimeMillis(); return invoker; } diff --git a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/pom.xml b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/pom.xml index c7e566605..406039527 100644 --- a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/pom.xml +++ b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/pom.xml @@ -36,6 +36,11 @@ 2.7.18 true + + org.apache.dubbo.extensions + dubbo-cluster-specify-address-common + ${project.version} + diff --git a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressUtil.java b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/AddressSpecifyClusterInterceptor.java similarity index 51% rename from dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressUtil.java rename to dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/AddressSpecifyClusterInterceptor.java index 61a6ecb4a..a3da3ba41 100644 --- a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressUtil.java +++ b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/AddressSpecifyClusterInterceptor.java @@ -16,26 +16,29 @@ */ package org.apache.dubbo.rpc.cluster.specifyaddress; -import org.apache.dubbo.common.threadlocal.InternalThreadLocal; +import org.apache.dubbo.common.constants.CommonConstants; +import org.apache.dubbo.common.extension.Activate; +import org.apache.dubbo.rpc.Invocation; +import org.apache.dubbo.rpc.cluster.interceptor.ClusterInterceptor; +import org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker; -public class UserSpecifiedAddressUtil { - private final static InternalThreadLocal
ADDRESS = new InternalThreadLocal<>(); +/** + * The SPECIFY ADDRESS field is handed over to the attachment by the thread + */ +@Activate(group = CommonConstants.CONSUMER) +public class AddressSpecifyClusterInterceptor implements ClusterInterceptor { - /** - * Set specified address to next invoke - * - * @param address specified address - */ - public static void setAddress(Address address) { - ADDRESS.set(address); + @Override + public void before(AbstractClusterInvoker clusterInvoker, Invocation invocation) { + Address current = UserSpecifiedAddressUtil.getAddress(); + if (current != null) { + invocation.put(Address.name, current); + } } - public static Address getAddress() { - try { - return ADDRESS.get(); - } finally { - // work once - ADDRESS.remove(); - } + + @Override + public void after(AbstractClusterInvoker clusterInvoker, Invocation invocation) { + } } diff --git a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressRouter.java b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressRouter.java index 139ce5c9c..84275e654 100644 --- a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressRouter.java +++ b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressRouter.java @@ -30,14 +30,15 @@ import org.apache.dubbo.rpc.Protocol; import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.cluster.router.AbstractRouter; +import org.apache.dubbo.rpc.cluster.specifyaddress.common.InvokerCache; import java.util.Collections; import java.util.HashMap; -import java.util.LinkedList; +import java.util.Iterator; import java.util.LinkedHashMap; +import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.Iterator; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; @@ -45,9 +46,9 @@ import java.util.concurrent.locks.ReentrantLock; import static org.apache.dubbo.common.constants.CommonConstants.DUBBO; +import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; import static org.apache.dubbo.common.constants.CommonConstants.MONITOR_KEY; import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; -import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; public class UserSpecifiedAddressRouter extends AbstractRouter { @@ -66,7 +67,7 @@ public class UserSpecifiedAddressRouter extends AbstractRouter { private final AtomicBoolean launchRemovalTask = new AtomicBoolean(false); - private final Map> newInvokerCache = new LinkedHashMap<>(16, 0.75f, true); + private final Map>> newInvokerCache = new LinkedHashMap<>(16, 0.75f, true); public UserSpecifiedAddressRouter(URL referenceUrl) { super(referenceUrl); @@ -85,14 +86,18 @@ public void notify(List> invokers) { } @Override + @SuppressWarnings("unchecked") public List> route(List> invokers, URL url, Invocation invocation) throws RpcException { - Address address = UserSpecifiedAddressUtil.getAddress(); + + Object addressObj = invocation.get(Address.name); // 1. check if set address in ThreadLocal - if (address == null) { + if (addressObj == null) { return invokers; } + Address address = (Address) addressObj; + List> result = new LinkedList<>(); // 2. check if set address url @@ -259,7 +264,7 @@ private URL copyConsumerUrl(URL url, String ip, int port, Map pa } public URL rebuildAddress(Address address, URL consumerUrl) { - URL url = address.getUrlAddress(); + URL url = (URL) address.getUrlAddress(); Map parameters = new HashMap<>(url.getParameters()); parameters.put(VERSION_KEY, consumerUrl.getParameter(VERSION_KEY, "0.0.0")); parameters.put(GROUP_KEY, consumerUrl.getParameter(GROUP_KEY)); @@ -270,7 +275,7 @@ public URL rebuildAddress(Address address, URL consumerUrl) { private Invoker getOrBuildInvokerCache(URL url) { logger.info("Unable to find a proper invoker from directory. Try to create new invoker. New URL: " + url); - InvokerCache cache; + InvokerCache> cache; cacheLock.lock(); try { cache = newInvokerCache.get(url); @@ -314,9 +319,9 @@ public void run() { cacheLock.lock(); try { if (newInvokerCache.size() > 0) { - Iterator>> iterator = newInvokerCache.entrySet().iterator(); + Iterator>>> iterator = newInvokerCache.entrySet().iterator(); while (iterator.hasNext()) { - Map.Entry> entry = iterator.next(); + Map.Entry>> entry = iterator.next(); if (System.currentTimeMillis() - entry.getValue().getLastAccess() > EXPIRE_TIME) { iterator.remove(); entry.getValue().getInvoker().destroy(); diff --git a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.cluster.interceptor.ClusterInterceptor b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.cluster.interceptor.ClusterInterceptor new file mode 100644 index 000000000..0ae64ac73 --- /dev/null +++ b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.cluster.interceptor.ClusterInterceptor @@ -0,0 +1 @@ +disableRetry=org.apache.dubbo.rpc.cluster.specifyaddress.AddressSpecifyClusterInterceptor \ No newline at end of file diff --git a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/src/test/java/org/apache/dubbo/rpc/cluster/specifyaddress/InvokerCacheTest.java b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/src/test/java/org/apache/dubbo/rpc/cluster/specifyaddress/InvokerCacheTest.java index 47fc38d19..d86ffc4a9 100644 --- a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/src/test/java/org/apache/dubbo/rpc/cluster/specifyaddress/InvokerCacheTest.java +++ b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/src/test/java/org/apache/dubbo/rpc/cluster/specifyaddress/InvokerCacheTest.java @@ -18,6 +18,7 @@ import org.apache.dubbo.rpc.Invoker; +import org.apache.dubbo.rpc.cluster.specifyaddress.common.InvokerCache; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -25,7 +26,7 @@ public class InvokerCacheTest { @Test public void test() throws InterruptedException { - InvokerCache cache = new InvokerCache<>(Mockito.mock(Invoker.class)); + InvokerCache> cache = new InvokerCache<>(Mockito.mock(Invoker.class)); long originTime = cache.getLastAccess(); Thread.sleep(5); cache.getInvoker(); diff --git a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/src/test/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressRouterTest.java b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/src/test/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressRouterTest.java index 34cef9e83..30b6ea6d0 100644 --- a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/src/test/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressRouterTest.java +++ b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/src/test/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressRouterTest.java @@ -20,8 +20,9 @@ import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.RpcException; +import org.apache.dubbo.rpc.RpcInvocation; +import org.apache.dubbo.rpc.cluster.support.FailoverClusterInvoker; import org.apache.dubbo.rpc.model.ApplicationModel; - import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -38,7 +39,7 @@ public class UserSpecifiedAddressRouterTest { @BeforeEach public void setup() { consumerUrl = URL.valueOf("127.0.0.2:20880").addParameter("Test", "Value").addParameter("check", "false").addParameter("lazy","true") - .addParameter("version", "1.0.0").addParameter("group", "Dubbo").addParameter("interface", DemoService.class.getName()); + .addParameter("version", "1.0.0").addParameter("group", "Dubbo").addParameter("interface", DemoService.class.getName()); } @Test @@ -53,10 +54,16 @@ public void testNotify() { Assertions.assertNull(userSpecifiedAddressRouter.getIp2Invoker()); UserSpecifiedAddressUtil.setAddress(new Address("127.0.0.1", 0)); + FailoverClusterInvoker mockInvoker = Mockito.mock(FailoverClusterInvoker.class); + AddressSpecifyClusterInterceptor interceptor = new AddressSpecifyClusterInterceptor(); + + UserSpecifiedAddressUtil.setAddress(new Address("127.0.0.1", 0)); + Invocation invocation = new RpcInvocation(); + interceptor.before(mockInvoker,invocation); // no address Assertions.assertThrows(RpcException.class, () -> - userSpecifiedAddressRouter.route(Collections.emptyList(), consumerUrl, Mockito.mock(Invocation.class))); + userSpecifiedAddressRouter.route(Collections.emptyList(), consumerUrl, invocation)); Assertions.assertNotNull(userSpecifiedAddressRouter.getAddress2Invoker()); Assertions.assertNotNull(userSpecifiedAddressRouter.getIp2Invoker()); @@ -72,10 +79,17 @@ public void testGetInvokerByURL() { UserSpecifiedAddressRouter userSpecifiedAddressRouter = new UserSpecifiedAddressRouter(consumerUrl); Assertions.assertEquals(Collections.emptyList(), - userSpecifiedAddressRouter.route(Collections.emptyList(), consumerUrl, Mockito.mock(Invocation.class))); + userSpecifiedAddressRouter.route(Collections.emptyList(), consumerUrl, Mockito.mock(Invocation.class))); + + FailoverClusterInvoker mockInvoker = Mockito.mock(FailoverClusterInvoker.class); + + AddressSpecifyClusterInterceptor interceptor = new AddressSpecifyClusterInterceptor(); UserSpecifiedAddressUtil.setAddress(new Address(URL.valueOf("127.0.0.1:20880?lazy=true"))); - List> invokers = userSpecifiedAddressRouter.route(Collections.emptyList(), consumerUrl, Mockito.mock(Invocation.class)); + Invocation invocation = new RpcInvocation(); + interceptor.before(mockInvoker,invocation); + + List> invokers = userSpecifiedAddressRouter.route(Collections.emptyList(), consumerUrl, invocation); Assertions.assertEquals(1, invokers.size()); Assertions.assertEquals("127.0.0.1", invokers.get(0).getUrl().getHost()); Assertions.assertEquals(20880, invokers.get(0).getUrl().getPort()); @@ -83,29 +97,36 @@ public void testGetInvokerByURL() { Assertions.assertEquals(consumerUrl.getParameter("version"), invokers.get(0).getUrl().getParameter("version")); Assertions.assertEquals(consumerUrl.getParameter("group"), invokers.get(0).getUrl().getParameter("group")); - Invoker mockInvoker = Mockito.mock(Invoker.class); Mockito.when(mockInvoker.getUrl()).thenReturn(URL.valueOf("simple://127.0.0.1:20880?Test1=Value")); userSpecifiedAddressRouter.notify(new LinkedList<>(Collections.singletonList(mockInvoker))); UserSpecifiedAddressUtil.setAddress(new Address(URL.valueOf("127.0.0.1:20880"))); - invokers = userSpecifiedAddressRouter.route(new LinkedList<>(Collections.singletonList(mockInvoker)), consumerUrl, Mockito.mock(Invocation.class)); + Invocation invocation1 = new RpcInvocation(); + interceptor.before(mockInvoker,invocation1); + invokers = userSpecifiedAddressRouter.route(new LinkedList<>(Collections.singletonList(mockInvoker)), consumerUrl, invocation1); Assertions.assertEquals(1, invokers.size()); Assertions.assertEquals(mockInvoker, invokers.get(0)); userSpecifiedAddressRouter.notify(new LinkedList<>(Collections.singletonList(mockInvoker))); UserSpecifiedAddressUtil.setAddress(new Address(URL.valueOf("127.0.0.1:20880?Test1=Value"))); - invokers = userSpecifiedAddressRouter.route(new LinkedList<>(Collections.singletonList(mockInvoker)), consumerUrl, Mockito.mock(Invocation.class)); + Invocation invocation2 = new RpcInvocation(); + interceptor.before(mockInvoker,invocation2); + invokers = userSpecifiedAddressRouter.route(new LinkedList<>(Collections.singletonList(mockInvoker)), consumerUrl, invocation2); Assertions.assertEquals(1, invokers.size()); Assertions.assertEquals(mockInvoker, invokers.get(0)); userSpecifiedAddressRouter.notify(new LinkedList<>(Collections.singletonList(mockInvoker))); UserSpecifiedAddressUtil.setAddress(new Address(URL.valueOf("simple://127.0.0.1:20880"))); - invokers = userSpecifiedAddressRouter.route(new LinkedList<>(Collections.singletonList(mockInvoker)), consumerUrl, Mockito.mock(Invocation.class)); + Invocation invocation3 = new RpcInvocation(); + interceptor.before(mockInvoker,invocation3); + invokers = userSpecifiedAddressRouter.route(new LinkedList<>(Collections.singletonList(mockInvoker)), consumerUrl, invocation3); Assertions.assertEquals(1, invokers.size()); Assertions.assertEquals(mockInvoker, invokers.get(0)); UserSpecifiedAddressUtil.setAddress(new Address(URL.valueOf("127.0.0.1:20880?Test1=Value&Test2=Value&Test3=Value"))); - invokers = userSpecifiedAddressRouter.route(Collections.emptyList(), consumerUrl, Mockito.mock(Invocation.class)); + Invocation invocation4 = new RpcInvocation(); + interceptor.before(mockInvoker,invocation4); + invokers = userSpecifiedAddressRouter.route(Collections.emptyList(), consumerUrl, invocation4); Assertions.assertEquals(1, invokers.size()); Assertions.assertEquals("127.0.0.1", invokers.get(0).getUrl().getHost()); Assertions.assertEquals(20880, invokers.get(0).getUrl().getPort()); @@ -121,33 +142,44 @@ public void testGetInvokerByIp() { UserSpecifiedAddressRouter userSpecifiedAddressRouter = new UserSpecifiedAddressRouter(consumerUrl); Assertions.assertEquals(Collections.emptyList(), - userSpecifiedAddressRouter.route(Collections.emptyList(), consumerUrl, Mockito.mock(Invocation.class))); + userSpecifiedAddressRouter.route(Collections.emptyList(), consumerUrl, Mockito.mock(Invocation.class))); + AddressSpecifyClusterInterceptor interceptor = new AddressSpecifyClusterInterceptor(); - Invoker mockInvoker = Mockito.mock(Invoker.class); + FailoverClusterInvoker mockInvoker = Mockito.mock(FailoverClusterInvoker.class); Mockito.when(mockInvoker.getUrl()).thenReturn(consumerUrl); userSpecifiedAddressRouter.notify(new LinkedList<>(Collections.singletonList(mockInvoker))); UserSpecifiedAddressUtil.setAddress(new Address("127.0.0.2", 0)); + Invocation invocation = new RpcInvocation(); + interceptor.before(mockInvoker,invocation); List> invokers = userSpecifiedAddressRouter.route(new LinkedList<>(Collections.singletonList(mockInvoker)), consumerUrl, Mockito.mock(Invocation.class)); Assertions.assertEquals(1, invokers.size()); Assertions.assertEquals(mockInvoker, invokers.get(0)); UserSpecifiedAddressUtil.setAddress(new Address("127.0.0.2", 20880)); - invokers = userSpecifiedAddressRouter.route(new LinkedList<>(Collections.singletonList(mockInvoker)), consumerUrl, Mockito.mock(Invocation.class)); + Invocation invocation1 = new RpcInvocation(); + interceptor.before(mockInvoker,invocation1); + invokers = userSpecifiedAddressRouter.route(new LinkedList<>(Collections.singletonList(mockInvoker)), consumerUrl, invocation1); Assertions.assertEquals(1, invokers.size()); Assertions.assertEquals(mockInvoker, invokers.get(0)); UserSpecifiedAddressUtil.setAddress(new Address("127.0.0.2", 20770)); + Invocation invocation2 = new RpcInvocation(); + interceptor.before(mockInvoker,invocation2); Assertions.assertThrows(RpcException.class, () -> - userSpecifiedAddressRouter.route(new LinkedList<>(Collections.singletonList(mockInvoker)), consumerUrl, Mockito.mock(Invocation.class))); + userSpecifiedAddressRouter.route(new LinkedList<>(Collections.singletonList(mockInvoker)), consumerUrl, invocation2)); UserSpecifiedAddressUtil.setAddress(new Address("127.0.0.3", 20880)); + Invocation invocation3 = new RpcInvocation(); + interceptor.before(mockInvoker,invocation3); Assertions.assertThrows(RpcException.class, () -> - userSpecifiedAddressRouter.route(new LinkedList<>(Collections.singletonList(mockInvoker)), consumerUrl, Mockito.mock(Invocation.class))); + userSpecifiedAddressRouter.route(new LinkedList<>(Collections.singletonList(mockInvoker)), consumerUrl, invocation3)); - UserSpecifiedAddressUtil.setAddress(new Address("127.0.0.2", 20770, true)); - invokers = userSpecifiedAddressRouter.route(Collections.emptyList(), consumerUrl, Mockito.mock(Invocation.class)); + UserSpecifiedAddressUtil.setAddress(new Address("127.0.0.2", 20770,true)); + Invocation invocation4 = new RpcInvocation(); + interceptor.before(mockInvoker,invocation4); + invokers = userSpecifiedAddressRouter.route(Collections.emptyList(), consumerUrl, invocation4); Assertions.assertEquals(1, invokers.size()); Assertions.assertEquals("127.0.0.2", invokers.get(0).getUrl().getHost()); Assertions.assertEquals(20770, invokers.get(0).getUrl().getPort()); diff --git a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/pom.xml b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/pom.xml index 246bccf51..72f977c0c 100644 --- a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/pom.xml +++ b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/pom.xml @@ -35,6 +35,12 @@ dubbo true + + + org.apache.dubbo.extensions + dubbo-cluster-specify-address-common + ${project.version} + diff --git a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/Address.java b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/Address.java deleted file mode 100644 index b4268bfa3..000000000 --- a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/Address.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * 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 org.apache.dubbo.rpc.cluster.specifyaddress; - -import org.apache.dubbo.common.URL; - -import java.io.Serializable; -import java.util.Objects; - -public class Address implements Serializable { - // ip - priority: 3 - private String ip; - - // ip+port - priority: 2 - private int port; - - // address - priority: 1 - private URL urlAddress; - private boolean needToCreate = false; - - public Address(String ip, int port) { - this.ip = ip; - this.port = port; - this.urlAddress = null; - } - - public Address(String ip, int port, boolean needToCreate) { - this.ip = ip; - this.port = port; - this.needToCreate = needToCreate; - } - - public Address(URL address) { - this.ip = null; - this.port = 0; - this.urlAddress = address; - } - - public String getIp() { - return ip; - } - - public void setIp(String ip) { - this.ip = ip; - } - - public int getPort() { - return port; - } - - public void setPort(int port) { - this.port = port; - } - - public URL getUrlAddress() { - return urlAddress; - } - - public void setUrlAddress(URL urlAddress) { - this.urlAddress = urlAddress; - } - - public boolean isNeedToCreate() { - return needToCreate; - } - - public void setNeedToCreate(boolean needToCreate) { - this.needToCreate = needToCreate; - } - - @Override - public String toString() { - return "Address{" + - "ip='" + ip + '\'' + - ", port=" + port + - ", address=" + urlAddress + - ", needToCreate=" + needToCreate + - '}'; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - Address address = (Address) o; - return port == address.port && needToCreate == address.needToCreate && Objects.equals(ip, address.ip) && Objects.equals(urlAddress, address.urlAddress); - } - - @Override - public int hashCode() { - return Objects.hash(ip, port, urlAddress, needToCreate); - } -} diff --git a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/InvokerCache.java b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/AddressSpecifyClusterFilter.java similarity index 55% rename from dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/InvokerCache.java rename to dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/AddressSpecifyClusterFilter.java index 52aff898b..b7fa85f8b 100644 --- a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/InvokerCache.java +++ b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/AddressSpecifyClusterFilter.java @@ -16,22 +16,29 @@ */ package org.apache.dubbo.rpc.cluster.specifyaddress; +import org.apache.dubbo.common.extension.Activate; +import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; +import org.apache.dubbo.rpc.Result; +import org.apache.dubbo.rpc.RpcException; +import org.apache.dubbo.rpc.cluster.filter.ClusterFilter; -public class InvokerCache { - private long lastAccess = System.currentTimeMillis(); - private final Invoker invoker; +/** + * The SPECIFY ADDRESS field is handed over to the attachment by the thread + */ +@Activate(group = {"consumer"}) +public class AddressSpecifyClusterFilter implements ClusterFilter { - public InvokerCache(Invoker invoker) { - this.invoker = invoker; - } - public long getLastAccess() { - return lastAccess; - } + @Override + public Result invoke(Invoker invoker, Invocation invocation) throws RpcException { - public Invoker getInvoker() { - lastAccess = System.currentTimeMillis(); - return invoker; + Address current = UserSpecifiedAddressUtil.getAddress(); + if (current != null) { + invocation.put(Address.name, current); + } + return invoker.invoke(invocation); } + + } diff --git a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/DefaultUserSpecifiedServiceAddressBuilder.java b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/DefaultUserSpecifiedServiceAddressBuilder.java index 72743118f..ab2ab3e17 100644 --- a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/DefaultUserSpecifiedServiceAddressBuilder.java +++ b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/DefaultUserSpecifiedServiceAddressBuilder.java @@ -81,7 +81,7 @@ public URL buildAddress(List> invokers, Address address, Invocati } template = new DubboServiceAddressURL( new PathURLAddress(protocol, null, null, consumerUrl.getPath(), ip, port), - URLParam.parse(""), consumerUrl, null); + consumerUrl.getUrlParam(), consumerUrl, null); } return template; @@ -89,7 +89,7 @@ public URL buildAddress(List> invokers, Address address, Invocati @Override public URL rebuildAddress(List> invokers, Address address, Invocation invocation, URL consumerUrl) { - URL url = address.getUrlAddress(); + URL url = (URL) address.getUrlAddress(); Map parameters = new HashMap<>(url.getParameters()); parameters.put(VERSION_KEY, consumerUrl.getVersion()); parameters.put(GROUP_KEY, consumerUrl.getGroup()); diff --git a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressRouter.java b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressRouter.java index a8faeb2b3..00290a482 100644 --- a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressRouter.java +++ b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressRouter.java @@ -30,6 +30,7 @@ import org.apache.dubbo.rpc.cluster.router.RouterSnapshotNode; import org.apache.dubbo.rpc.cluster.router.state.AbstractStateRouter; import org.apache.dubbo.rpc.cluster.router.state.BitList; +import org.apache.dubbo.rpc.cluster.specifyaddress.common.InvokerCache; import java.util.Collections; import java.util.HashMap; @@ -55,7 +56,7 @@ public class UserSpecifiedAddressRouter extends AbstractStateRouter { private volatile Map> address2Invoker; private final Lock cacheLock = new ReentrantLock(); - private final Map> newInvokerCache = new LinkedHashMap<>(16, 0.75f, true); + private final Map>> newInvokerCache = new LinkedHashMap<>(16, 0.75f, true); private final UserSpecifiedServiceAddressBuilder userSpecifiedServiceAddressBuilder; @@ -69,7 +70,7 @@ public UserSpecifiedAddressRouter(URL referenceUrl) { this.scheduledExecutorService = referenceUrl.getScopeModel().getDefaultExtension(ExecutorRepository.class).nextScheduledExecutor(); this.protocol = referenceUrl.getOrDefaultFrameworkModel().getExtensionLoader(Protocol.class).getAdaptiveExtension(); this.userSpecifiedServiceAddressBuilder = referenceUrl.getScopeModel().getExtensionLoader(UserSpecifiedServiceAddressBuilder.class) - .getExtension(referenceUrl.getParameter(USER_SPECIFIED_SERVICE_ADDRESS_BUILDER_KEY, DefaultUserSpecifiedServiceAddressBuilder.NAME)); + .getExtension(referenceUrl.getParameter(USER_SPECIFIED_SERVICE_ADDRESS_BUILDER_KEY, DefaultUserSpecifiedServiceAddressBuilder.NAME)); } @Override @@ -83,19 +84,22 @@ public void notify(BitList> invokers) { } @Override + @SuppressWarnings("unchecked") protected BitList> doRoute(BitList> invokers, URL url, Invocation invocation, boolean needToPrintMessage, Holder> nodeHolder, Holder messageHolder) throws RpcException { - Address address = UserSpecifiedAddressUtil.getAddress(); + Object addressObj = invocation.get(Address.name); // 1. check if set address in ThreadLocal - if (address == null) { + if (addressObj == null) { if (needToPrintMessage) { messageHolder.set("No address specified, continue."); } return continueRoute(invokers, url, invocation, needToPrintMessage, nodeHolder); } + Address address = (Address) addressObj; + BitList> result = new BitList<>(invokers, true); // 2. check if set address url @@ -110,7 +114,7 @@ protected BitList> doRoute(BitList> invokers, URL url, Inv // 3. check if set ip and port if (StringUtils.isNotEmpty(address.getIp())) { - Invoker invoker = getInvokerByIp(address, invocation); + Invoker invoker = getInvokerByIp(address); if (invoker != null) { result.add(invoker); if (needToPrintMessage) { @@ -172,7 +176,7 @@ private Invoker getInvokerByURL(Address address, Invocation invocation) { private Invoker getOrBuildInvokerCache(URL url) { logger.info("Unable to find a proper invoker from directory. Try to create new invoker. New URL: " + url); - InvokerCache cache; + InvokerCache> cache; cacheLock.lock(); try { cache = newInvokerCache.get(url); @@ -200,7 +204,7 @@ private Invoker getOrBuildInvokerCache(URL url) { return cache.getInvoker(); } - public Invoker getInvokerByIp(Address address, Invocation invocation) { + public Invoker getInvokerByIp(Address address) { tryLoadSpecifiedMap(); String ip = address.getIp(); @@ -220,7 +224,7 @@ public Invoker getInvokerByIp(Address address, Invocation invocation) { } if (!address.isNeedToCreate()) { - throwException(invocation, address); + throwException(address); } return null; @@ -234,9 +238,9 @@ private Invoker refer(URL url) { return (Invoker) protocol.refer(getUrl().getServiceModel().getServiceInterfaceClass(), url); } - private void throwException(Invocation invocation, Address address) { + private void throwException(Address address) { throw new RpcException("user specified server address : [" + address + "] is not a valid provider for service: [" - + getUrl().getServiceKey() + "]"); + + getUrl().getServiceKey() + "]"); } private Map> processIp(List> invokerList) { @@ -275,7 +279,7 @@ protected BitList> getInvokers() { // For ut only @Deprecated - protected Map> getNewInvokerCache() { + protected Map>> getNewInvokerCache() { return newInvokerCache; } @@ -311,9 +315,9 @@ public void run() { cacheLock.lock(); try { if (newInvokerCache.size() > 0) { - Iterator>> iterator = newInvokerCache.entrySet().iterator(); + Iterator>>> iterator = newInvokerCache.entrySet().iterator(); while (iterator.hasNext()) { - Map.Entry> entry = iterator.next(); + Map.Entry>> entry = iterator.next(); if (System.currentTimeMillis() - entry.getValue().getLastAccess() > EXPIRE_TIME) { iterator.remove(); entry.getValue().getInvoker().destroy(); diff --git a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.cluster.filter.ClusterFilter b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.cluster.filter.ClusterFilter new file mode 100644 index 000000000..151cb378a --- /dev/null +++ b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.cluster.filter.ClusterFilter @@ -0,0 +1 @@ +disableRetry=org.apache.dubbo.rpc.cluster.specifyaddress.AddressSpecifyClusterFilter \ No newline at end of file diff --git a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/src/test/java/org/apache/dubbo/rpc/cluster/specifyaddress/InvokerCacheTest.java b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/src/test/java/org/apache/dubbo/rpc/cluster/specifyaddress/InvokerCacheTest.java index 47fc38d19..d86ffc4a9 100644 --- a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/src/test/java/org/apache/dubbo/rpc/cluster/specifyaddress/InvokerCacheTest.java +++ b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/src/test/java/org/apache/dubbo/rpc/cluster/specifyaddress/InvokerCacheTest.java @@ -18,6 +18,7 @@ import org.apache.dubbo.rpc.Invoker; +import org.apache.dubbo.rpc.cluster.specifyaddress.common.InvokerCache; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -25,7 +26,7 @@ public class InvokerCacheTest { @Test public void test() throws InterruptedException { - InvokerCache cache = new InvokerCache<>(Mockito.mock(Invoker.class)); + InvokerCache> cache = new InvokerCache<>(Mockito.mock(Invoker.class)); long originTime = cache.getLastAccess(); Thread.sleep(5); cache.getInvoker(); diff --git a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/src/test/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressRouterTest.java b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/src/test/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressRouterTest.java index 4cc09c65c..e25d64ce3 100644 --- a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/src/test/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressRouterTest.java +++ b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/src/test/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressRouterTest.java @@ -20,6 +20,7 @@ import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.RpcException; +import org.apache.dubbo.rpc.RpcInvocation; import org.apache.dubbo.rpc.cluster.router.state.BitList; import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.rpc.model.ServiceModel; @@ -67,11 +68,15 @@ public void testNotify() { Assertions.assertNull(userSpecifiedAddressRouter.getAddress2Invoker()); Assertions.assertNull(userSpecifiedAddressRouter.getIp2Invoker()); + Invocation invocation = new RpcInvocation(); + Invoker mockInvoker = Mockito.mock(Invoker.class); + AddressSpecifyClusterFilter clusterFilter = new AddressSpecifyClusterFilter(); UserSpecifiedAddressUtil.setAddress(new Address("127.0.0.1", 0)); + clusterFilter.invoke(mockInvoker,invocation); // no address Assertions.assertThrows(RpcException.class, () -> - userSpecifiedAddressRouter.doRoute(BitList.emptyList(), consumerUrl, Mockito.mock(Invocation.class), false, null, null)); + userSpecifiedAddressRouter.doRoute(BitList.emptyList(), consumerUrl, invocation, false, null, null)); Assertions.assertNotNull(userSpecifiedAddressRouter.getAddress2Invoker()); Assertions.assertNotNull(userSpecifiedAddressRouter.getIp2Invoker()); @@ -89,8 +94,13 @@ public void testGetInvokerByURL() { Assertions.assertEquals(BitList.emptyList(), userSpecifiedAddressRouter.doRoute(BitList.emptyList(), consumerUrl, Mockito.mock(Invocation.class), false, null, null)); + Invocation invocation = new RpcInvocation(); + Invoker mockInvoker = Mockito.mock(Invoker.class); + AddressSpecifyClusterFilter clusterFilter = new AddressSpecifyClusterFilter(); UserSpecifiedAddressUtil.setAddress(new Address(URL.valueOf("127.0.0.1:20880"))); - BitList> invokers = userSpecifiedAddressRouter.doRoute(BitList.emptyList(), consumerUrl, Mockito.mock(Invocation.class), false, null, null); + clusterFilter.invoke(mockInvoker,invocation); + + BitList> invokers = userSpecifiedAddressRouter.doRoute(BitList.emptyList(), consumerUrl, invocation, false, null, null); Assertions.assertEquals(1, invokers.size()); Assertions.assertEquals("127.0.0.1", invokers.get(0).getUrl().getHost()); Assertions.assertEquals(20880, invokers.get(0).getUrl().getPort()); @@ -98,29 +108,37 @@ public void testGetInvokerByURL() { Assertions.assertEquals(consumerUrl.getVersion(), invokers.get(0).getUrl().getVersion()); Assertions.assertEquals(consumerUrl.getGroup(), invokers.get(0).getUrl().getGroup()); - Invoker mockInvoker = Mockito.mock(Invoker.class); Mockito.when(mockInvoker.getUrl()).thenReturn(URL.valueOf("simple://127.0.0.1:20880?Test1=Value")); userSpecifiedAddressRouter.notify(new BitList<>(Collections.singletonList(mockInvoker))); UserSpecifiedAddressUtil.setAddress(new Address(URL.valueOf("127.0.0.1:20880"))); - invokers = userSpecifiedAddressRouter.doRoute(new BitList<>(Collections.singletonList(mockInvoker)), consumerUrl, Mockito.mock(Invocation.class), false, null, null); + Invocation invocation1 = new RpcInvocation(); + clusterFilter.invoke(mockInvoker,invocation1); + + invokers = userSpecifiedAddressRouter.doRoute(new BitList<>(Collections.singletonList(mockInvoker)), consumerUrl, invocation1, false, null, null); Assertions.assertEquals(1, invokers.size()); Assertions.assertEquals(mockInvoker, invokers.get(0)); userSpecifiedAddressRouter.notify(new BitList<>(Collections.singletonList(mockInvoker))); UserSpecifiedAddressUtil.setAddress(new Address(URL.valueOf("127.0.0.1:20880?Test1=Value"))); - invokers = userSpecifiedAddressRouter.doRoute(new BitList<>(Collections.singletonList(mockInvoker)), consumerUrl, Mockito.mock(Invocation.class), false, null, null); + Invocation invocation2 = new RpcInvocation(); + clusterFilter.invoke(mockInvoker,invocation2); + invokers = userSpecifiedAddressRouter.doRoute(new BitList<>(Collections.singletonList(mockInvoker)), consumerUrl, invocation2, false, null, null); Assertions.assertEquals(1, invokers.size()); Assertions.assertEquals(mockInvoker, invokers.get(0)); userSpecifiedAddressRouter.notify(new BitList<>(Collections.singletonList(mockInvoker))); UserSpecifiedAddressUtil.setAddress(new Address(URL.valueOf("simple://127.0.0.1:20880"))); - invokers = userSpecifiedAddressRouter.doRoute(new BitList<>(Collections.singletonList(mockInvoker)), consumerUrl, Mockito.mock(Invocation.class), false, null, null); + Invocation invocation3 = new RpcInvocation(); + clusterFilter.invoke(mockInvoker,invocation3); + invokers = userSpecifiedAddressRouter.doRoute(new BitList<>(Collections.singletonList(mockInvoker)), consumerUrl, invocation3, false, null, null); Assertions.assertEquals(1, invokers.size()); Assertions.assertEquals(mockInvoker, invokers.get(0)); UserSpecifiedAddressUtil.setAddress(new Address(URL.valueOf("dubbo://127.0.0.1:20880"))); - invokers = userSpecifiedAddressRouter.doRoute(BitList.emptyList(), consumerUrl, Mockito.mock(Invocation.class), false, null, null); + Invocation invocation4 = new RpcInvocation(); + clusterFilter.invoke(mockInvoker,invocation4); + invokers = userSpecifiedAddressRouter.doRoute(BitList.emptyList(), consumerUrl, invocation4, false, null, null); Assertions.assertEquals(1, invokers.size()); Assertions.assertEquals("127.0.0.1", invokers.get(0).getUrl().getHost()); Assertions.assertEquals(20880, invokers.get(0).getUrl().getPort()); @@ -129,7 +147,10 @@ public void testGetInvokerByURL() { Assertions.assertEquals(consumerUrl.getGroup(), invokers.get(0).getUrl().getGroup()); UserSpecifiedAddressUtil.setAddress(new Address(URL.valueOf("127.0.0.1:20770"))); - invokers = userSpecifiedAddressRouter.doRoute(BitList.emptyList(), consumerUrl, Mockito.mock(Invocation.class), false, null, null); + Invocation invocation5 = new RpcInvocation(); + clusterFilter.invoke(mockInvoker,invocation5); + + invokers = userSpecifiedAddressRouter.doRoute(BitList.emptyList(), consumerUrl, invocation5, false, null, null); Assertions.assertEquals(1, invokers.size()); Assertions.assertEquals("127.0.0.1", invokers.get(0).getUrl().getHost()); Assertions.assertEquals(20770, invokers.get(0).getUrl().getPort()); @@ -138,7 +159,9 @@ public void testGetInvokerByURL() { Assertions.assertEquals(consumerUrl.getGroup(), invokers.get(0).getUrl().getGroup()); UserSpecifiedAddressUtil.setAddress(new Address(URL.valueOf("127.0.0.1:20770?Test1=Value1"))); - invokers = userSpecifiedAddressRouter.doRoute(BitList.emptyList(), consumerUrl, Mockito.mock(Invocation.class), false, null, null); + Invocation invocation6 = new RpcInvocation(); + clusterFilter.invoke(mockInvoker,invocation6); + invokers = userSpecifiedAddressRouter.doRoute(BitList.emptyList(), consumerUrl, invocation6, false, null, null); Assertions.assertEquals(1, invokers.size()); Assertions.assertEquals("127.0.0.1", invokers.get(0).getUrl().getHost()); Assertions.assertEquals(20770, invokers.get(0).getUrl().getPort()); @@ -147,7 +170,9 @@ public void testGetInvokerByURL() { Assertions.assertEquals(consumerUrl.getGroup(), invokers.get(0).getUrl().getGroup()); UserSpecifiedAddressUtil.setAddress(new Address(URL.valueOf("127.0.0.2:20770?Test1=Value1"))); - invokers = userSpecifiedAddressRouter.doRoute(BitList.emptyList(), consumerUrl, Mockito.mock(Invocation.class), false, null, null); + Invocation invocation7 = new RpcInvocation(); + clusterFilter.invoke(mockInvoker,invocation7); + invokers = userSpecifiedAddressRouter.doRoute(BitList.emptyList(), consumerUrl, invocation7, false, null, null); Assertions.assertEquals(1, invokers.size()); Assertions.assertEquals("127.0.0.2", invokers.get(0).getUrl().getHost()); Assertions.assertEquals(20770, invokers.get(0).getUrl().getPort()); @@ -156,7 +181,9 @@ public void testGetInvokerByURL() { Assertions.assertEquals(consumerUrl.getGroup(), invokers.get(0).getUrl().getGroup()); UserSpecifiedAddressUtil.setAddress(new Address(URL.valueOf("127.0.0.1:20880?Test1=Value&Test2=Value&Test3=Value"))); - invokers = userSpecifiedAddressRouter.doRoute(BitList.emptyList(), consumerUrl, Mockito.mock(Invocation.class), false, null, null); + Invocation invocation8 = new RpcInvocation(); + clusterFilter.invoke(mockInvoker,invocation8); + invokers = userSpecifiedAddressRouter.doRoute(BitList.emptyList(), consumerUrl, invocation8, false, null, null); Assertions.assertEquals(1, invokers.size()); Assertions.assertEquals("127.0.0.1", invokers.get(0).getUrl().getHost()); Assertions.assertEquals(20880, invokers.get(0).getUrl().getPort()); @@ -175,30 +202,41 @@ public void testGetInvokerByIp() { userSpecifiedAddressRouter.doRoute(BitList.emptyList(), consumerUrl, Mockito.mock(Invocation.class), false, null, null)); Invoker mockInvoker = Mockito.mock(Invoker.class); + AddressSpecifyClusterFilter clusterFilter = new AddressSpecifyClusterFilter(); Mockito.when(mockInvoker.getUrl()).thenReturn(consumerUrl); userSpecifiedAddressRouter.notify(new BitList<>(Collections.singletonList(mockInvoker))); UserSpecifiedAddressUtil.setAddress(new Address("127.0.0.2", 0)); - BitList> invokers = userSpecifiedAddressRouter.doRoute(new BitList<>(Collections.singletonList(mockInvoker)), consumerUrl, Mockito.mock(Invocation.class), false, null, null); + Invocation invocation = new RpcInvocation(); + clusterFilter.invoke(mockInvoker,invocation); + BitList> invokers = userSpecifiedAddressRouter.doRoute(new BitList<>(Collections.singletonList(mockInvoker)), consumerUrl, invocation, false, null, null); Assertions.assertEquals(1, invokers.size()); Assertions.assertEquals(mockInvoker, invokers.get(0)); UserSpecifiedAddressUtil.setAddress(new Address("127.0.0.2", 20880)); - invokers = userSpecifiedAddressRouter.doRoute(new BitList<>(Collections.singletonList(mockInvoker)), consumerUrl, Mockito.mock(Invocation.class), false, null, null); + Invocation invocation1 = new RpcInvocation(); + clusterFilter.invoke(mockInvoker,invocation1); + invokers = userSpecifiedAddressRouter.doRoute(new BitList<>(Collections.singletonList(mockInvoker)), consumerUrl, invocation1, false, null, null); Assertions.assertEquals(1, invokers.size()); Assertions.assertEquals(mockInvoker, invokers.get(0)); UserSpecifiedAddressUtil.setAddress(new Address("127.0.0.2", 20770)); + Invocation invocation2 = new RpcInvocation(); + clusterFilter.invoke(mockInvoker,invocation2); Assertions.assertThrows(RpcException.class, () -> - userSpecifiedAddressRouter.doRoute(new BitList<>(Collections.singletonList(mockInvoker)), consumerUrl, Mockito.mock(Invocation.class), false, null, null)); + userSpecifiedAddressRouter.doRoute(new BitList<>(Collections.singletonList(mockInvoker)), consumerUrl, invocation2, false, null, null)); UserSpecifiedAddressUtil.setAddress(new Address("127.0.0.3", 20880)); + Invocation invocation3 = new RpcInvocation(); + clusterFilter.invoke(mockInvoker,invocation3); Assertions.assertThrows(RpcException.class, () -> - userSpecifiedAddressRouter.doRoute(new BitList<>(Collections.singletonList(mockInvoker)), consumerUrl, Mockito.mock(Invocation.class), false, null, null)); + userSpecifiedAddressRouter.doRoute(new BitList<>(Collections.singletonList(mockInvoker)), consumerUrl, invocation3, false, null, null)); - UserSpecifiedAddressUtil.setAddress(new Address("127.0.0.2", 20770, true)); - invokers = userSpecifiedAddressRouter.doRoute(BitList.emptyList(), consumerUrl, Mockito.mock(Invocation.class), false, null, null); + Invocation invocation4 = new RpcInvocation(); + UserSpecifiedAddressUtil.setAddress(new Address("127.0.0.2", 20770,true)); + clusterFilter.invoke(mockInvoker,invocation4); + invokers = userSpecifiedAddressRouter.doRoute(BitList.emptyList(), consumerUrl, invocation4, false, null, null); Assertions.assertEquals(1, invokers.size()); Assertions.assertEquals("127.0.0.2", invokers.get(0).getUrl().getHost()); Assertions.assertEquals(20770, invokers.get(0).getUrl().getPort()); @@ -208,12 +246,17 @@ public void testGetInvokerByIp() { } @Test + @SuppressWarnings("unchecked") public void testRemovalTask() throws InterruptedException { UserSpecifiedAddressRouter.EXPIRE_TIME = 10; UserSpecifiedAddressRouter userSpecifiedAddressRouter = new UserSpecifiedAddressRouter<>(consumerUrl); UserSpecifiedAddressUtil.setAddress(new Address(URL.valueOf("127.0.0.1:20880"))); - BitList> invokers = userSpecifiedAddressRouter.doRoute(BitList.emptyList(), consumerUrl, Mockito.mock(Invocation.class), false, null, null); + Invocation invocation = new RpcInvocation(); + Invoker mockInvoker = Mockito.mock(Invoker.class); + AddressSpecifyClusterFilter clusterFilter = new AddressSpecifyClusterFilter(); + clusterFilter.invoke(mockInvoker,invocation); + BitList> invokers = userSpecifiedAddressRouter.doRoute(BitList.emptyList(), consumerUrl, invocation, false, null, null); Assertions.assertEquals(1, invokers.size()); Assertions.assertEquals("127.0.0.1", invokers.get(0).getUrl().getHost()); Assertions.assertEquals(20880, invokers.get(0).getUrl().getPort()); diff --git a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/src/test/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressUtilTest.java b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/src/test/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressUtilTest.java index 0dc1c1680..e3048deb1 100644 --- a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/src/test/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressUtilTest.java +++ b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/src/test/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressUtilTest.java @@ -25,9 +25,7 @@ public void test() { Assertions.assertNull(UserSpecifiedAddressUtil.getAddress()); UserSpecifiedAddressUtil.setAddress(new Address("127.0.0.1", 0)); Assertions.assertEquals(new Address("127.0.0.1", 0), UserSpecifiedAddressUtil.getAddress()); - Assertions.assertNull(UserSpecifiedAddressUtil.getAddress()); UserSpecifiedAddressUtil.setAddress(new Address("127.0.0.1", 12345)); Assertions.assertNotEquals(new Address("127.0.0.1", 0), UserSpecifiedAddressUtil.getAddress()); - Assertions.assertNull(UserSpecifiedAddressUtil.getAddress()); } } diff --git a/dubbo-cluster-extensions/pom.xml b/dubbo-cluster-extensions/pom.xml index f3cb4ae1f..994628208 100644 --- a/dubbo-cluster-extensions/pom.xml +++ b/dubbo-cluster-extensions/pom.xml @@ -35,6 +35,7 @@ dubbo-cluster-loadbalance-peakewma dubbo-cluster-specify-address-dubbo3 dubbo-cluster-specify-address-dubbo2 + dubbo-cluster-specify-address-common dubbo-cluster-polaris-dubbo2 From 420d6d6ab17f437b27f2980364e6af48d679dd00 Mon Sep 17 00:00:00 2001 From: andrew shan <45474304+andrewshan@users.noreply.github.com> Date: Fri, 30 Dec 2022 16:08:17 +0800 Subject: [PATCH 05/35] feat: separate the circuitbreaker and ratelimit filters, to make it more decompose to developers (#187) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat:调整filter的引用模式,限流与熔断分开便于用户按需使用 * fix: add license to pom.xml --- .../pom.xml | 30 +++ .../filter/dubbo2/CircuitBreakerFilter.java | 0 .../dubbo/org.apache.dubbo.rpc.Filter | 1 + .../pom.xml | 30 +++ .../dubbo/filter/dubbo2/RateLimitFilter.java | 0 .../dubbo/org.apache.dubbo.rpc.Filter | 1 + .../dubbo-filter-polaris-dubbo2/pom.xml | 5 + .../dubbo/org.apache.dubbo.rpc.Filter | 3 - .../PolarisRegistryServiceDiscovery.java | 227 ------------------ .../PolarisServiceDiscoveryFactory.java | 30 --- .../polaris/filter}/ReportFilter.java | 2 +- ...bo.registry.client.ServiceDiscoveryFactory | 1 - .../internal/org.apache.dubbo.rpc.Filter | 1 + .../PolarisRegistryServiceDiscoveryTest.java | 152 ------------ 14 files changed, 69 insertions(+), 414 deletions(-) create mode 100644 dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-circuitbreaker-dubbo2/pom.xml rename dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/{ => dubbo-filter-polaris-circuitbreaker-dubbo2}/src/main/java/org/apache/dubbo/filter/dubbo2/CircuitBreakerFilter.java (100%) create mode 100644 dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-circuitbreaker-dubbo2/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter create mode 100644 dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-ratelimit-dubbo2/pom.xml rename dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/{ => dubbo-filter-polaris-ratelimit-dubbo2}/src/main/java/org/apache/dubbo/filter/dubbo2/RateLimitFilter.java (100%) create mode 100644 dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-ratelimit-dubbo2/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter delete mode 100644 dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter delete mode 100644 dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/PolarisRegistryServiceDiscovery.java delete mode 100644 dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/PolarisServiceDiscoveryFactory.java rename {dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/src/main/java/org/apache/dubbo/filter/dubbo2 => dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/filter}/ReportFilter.java (98%) delete mode 100644 dubbo-registry-extensions/dubbo-registry-polaris/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.ServiceDiscoveryFactory create mode 100644 dubbo-registry-extensions/dubbo-registry-polaris/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter delete mode 100644 dubbo-registry-extensions/dubbo-registry-polaris/src/test/java/org/apache/dubbo/registry/polaris/PolarisRegistryServiceDiscoveryTest.java diff --git a/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-circuitbreaker-dubbo2/pom.xml b/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-circuitbreaker-dubbo2/pom.xml new file mode 100644 index 000000000..4abcc6dd2 --- /dev/null +++ b/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-circuitbreaker-dubbo2/pom.xml @@ -0,0 +1,30 @@ + + + + + dubbo-filter-polaris-dubbo2 + org.apache.dubbo.extensions + 1.0.0-SNAPSHOT + + 4.0.0 + + dubbo-filter-polaris-circuitbreaker-dubbo2 + + diff --git a/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/src/main/java/org/apache/dubbo/filter/dubbo2/CircuitBreakerFilter.java b/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-circuitbreaker-dubbo2/src/main/java/org/apache/dubbo/filter/dubbo2/CircuitBreakerFilter.java similarity index 100% rename from dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/src/main/java/org/apache/dubbo/filter/dubbo2/CircuitBreakerFilter.java rename to dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-circuitbreaker-dubbo2/src/main/java/org/apache/dubbo/filter/dubbo2/CircuitBreakerFilter.java diff --git a/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-circuitbreaker-dubbo2/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter b/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-circuitbreaker-dubbo2/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter new file mode 100644 index 000000000..6af9e4899 --- /dev/null +++ b/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-circuitbreaker-dubbo2/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter @@ -0,0 +1 @@ +polaris_circuitbreaker=org.apache.dubbo.filter.dubbo2.CircuitBreakerFilter diff --git a/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-ratelimit-dubbo2/pom.xml b/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-ratelimit-dubbo2/pom.xml new file mode 100644 index 000000000..88669ebd4 --- /dev/null +++ b/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-ratelimit-dubbo2/pom.xml @@ -0,0 +1,30 @@ + + + + + dubbo-filter-polaris-dubbo2 + org.apache.dubbo.extensions + 1.0.0-SNAPSHOT + + 4.0.0 + + dubbo-filter-polaris-ratelimit-dubbo2 + + diff --git a/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/src/main/java/org/apache/dubbo/filter/dubbo2/RateLimitFilter.java b/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-ratelimit-dubbo2/src/main/java/org/apache/dubbo/filter/dubbo2/RateLimitFilter.java similarity index 100% rename from dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/src/main/java/org/apache/dubbo/filter/dubbo2/RateLimitFilter.java rename to dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-ratelimit-dubbo2/src/main/java/org/apache/dubbo/filter/dubbo2/RateLimitFilter.java diff --git a/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-ratelimit-dubbo2/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter b/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-ratelimit-dubbo2/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter new file mode 100644 index 000000000..b4ea5c2d0 --- /dev/null +++ b/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-ratelimit-dubbo2/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter @@ -0,0 +1 @@ +polaris_ratelimit=org.apache.dubbo.filter.dubbo2.RateLimitFilter diff --git a/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/pom.xml b/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/pom.xml index 65b677f38..bb845ac9a 100644 --- a/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/pom.xml +++ b/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/pom.xml @@ -27,9 +27,14 @@ 4.0.0 dubbo-filter-polaris-dubbo2 + pom dubbo-filter-polaris-dubbo2 1.0.0-SNAPSHOT Dubbo2 filter extension for PolarisMesh, support circuitbreaking, ratelimit, metric capabilities. + + dubbo-filter-polaris-circuitbreaker-dubbo2 + dubbo-filter-polaris-ratelimit-dubbo2 + diff --git a/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter b/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter deleted file mode 100644 index 2fb8a58c4..000000000 --- a/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter +++ /dev/null @@ -1,3 +0,0 @@ -polaris_report=org.apache.dubbo.filter.dubbo2.ReportFilter -polaris_circuitbreaker=org.apache.dubbo.filter.dubbo2.CircuitBreakerFilter -polaris_ratelimit=org.apache.dubbo.filter.dubbo2.RateLimitFilter \ No newline at end of file diff --git a/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/PolarisRegistryServiceDiscovery.java b/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/PolarisRegistryServiceDiscovery.java deleted file mode 100644 index 034da732b..000000000 --- a/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/PolarisRegistryServiceDiscovery.java +++ /dev/null @@ -1,227 +0,0 @@ -/* - * 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 org.apache.dubbo.registry.polaris; - -import com.tencent.polaris.api.listener.ServiceListener; -import com.tencent.polaris.api.pojo.Instance; -import com.tencent.polaris.api.pojo.ServiceInfo; -import com.tencent.polaris.common.registry.Consts; -import com.tencent.polaris.common.registry.ConvertUtils; -import com.tencent.polaris.common.registry.PolarisOperator; -import com.tencent.polaris.common.utils.ExtensionConsts; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import org.apache.dubbo.common.URL; -import org.apache.dubbo.common.constants.CommonConstants; -import org.apache.dubbo.common.extension.ExtensionLoader; -import org.apache.dubbo.common.logger.Logger; -import org.apache.dubbo.common.logger.LoggerFactory; -import org.apache.dubbo.common.utils.ConcurrentHashSet; -import org.apache.dubbo.common.utils.StringUtils; -import org.apache.dubbo.metadata.MetadataInfo; -import org.apache.dubbo.registry.client.AbstractServiceDiscovery; -import org.apache.dubbo.registry.client.DefaultServiceInstance; -import org.apache.dubbo.registry.client.ServiceInstance; -import org.apache.dubbo.registry.client.event.ServiceInstancesChangedEvent; -import org.apache.dubbo.registry.client.event.listener.ServiceInstancesChangedListener; -import org.apache.dubbo.registry.polaris.task.FetchTask; -import org.apache.dubbo.registry.polaris.task.InstancesHandler; -import org.apache.dubbo.registry.polaris.task.TaskScheduler; -import org.apache.dubbo.registry.polaris.task.WatchTask; -import org.apache.dubbo.rpc.Filter; -import org.apache.dubbo.rpc.cluster.Constants; -import org.apache.dubbo.rpc.model.ApplicationModel; - -public class PolarisRegistryServiceDiscovery extends AbstractServiceDiscovery { - - private static final Logger LOGGER = LoggerFactory.getLogger(PolarisRegistryServiceDiscovery.class); - - private final PolarisOperator polarisOperator; - - private static final TaskScheduler taskScheduler = new TaskScheduler(); - - private final Set registeredInstances = new ConcurrentHashSet<>(); - - private final Map serviceListeners = new ConcurrentHashMap<>(); - - private final boolean hasCircuitBreaker; - - public PolarisRegistryServiceDiscovery(ApplicationModel applicationModel, URL registryURL) { - super(applicationModel, registryURL); - polarisOperator = PolarisRegistryUtils.getOrCreatePolarisOperator(registryURL); - ExtensionLoader filterExtensionLoader = applicationModel.getExtensionDirector() - .getExtensionLoader(Filter.class); - if (null != filterExtensionLoader) { - hasCircuitBreaker = filterExtensionLoader.hasExtension(ExtensionConsts.PLUGIN_CIRCUITBREAKER_NAME); - } else { - hasCircuitBreaker = false; - } - } - - @Override - protected void doRegister(ServiceInstance serviceInstance) throws RuntimeException { - LOGGER.info(String.format( - "[POLARIS] register %s to service %s", serviceInstance.getAddress(), serviceInstance.getServiceName())); - int weight = Constants.DEFAULT_WEIGHT; - String weightValue = serviceInstance.getMetadata(Constants.WEIGHT_KEY); - if (StringUtils.isNotBlank(weightValue)) { - try { - weight = Integer.parseInt(weightValue); - } catch (Exception e) { - LOGGER.warn(String.format("[POLARIS] fail to parse weight value %s", weightValue)); - } - } - String applicationName = serviceInstance.getMetadata(CommonConstants.APPLICATION_KEY); - if (StringUtils.isBlank(applicationName)) { - ApplicationModel applicationModel = serviceInstance.getApplicationModel(); - if (null != applicationModel) { - applicationName = applicationModel.getApplicationName(); - } - serviceInstance.putExtendParam(CommonConstants.APPLICATION_KEY, applicationName); - } - String version = serviceInstance.getMetadata(CommonConstants.VERSION_KEY, ""); - polarisOperator.register(serviceInstance.getServiceName(), serviceInstance.getHost(), serviceInstance.getPort(), - "", version, weight, serviceInstance.getAllParams()); - registeredInstances.add(serviceInstance); - } - - @Override - protected void doUnregister(ServiceInstance serviceInstance) { - LOGGER.info(String.format( - "[POLARIS] unregister %s to service %s", serviceInstance.getAddress(), serviceInstance.getServiceName())); - polarisOperator.deregister(serviceInstance.getServiceName(), serviceInstance.getHost(), serviceInstance.getPort()); - registeredInstances.remove(serviceInstance); - } - - @Override - protected void doDestroy() { - for (ServiceInstance serviceInstance : registeredInstances) { - doUnregister(serviceInstance); - } - PolarisRegistryUtils.removePolarisOperator(getUrl()); - polarisOperator.destroy(); - taskScheduler.destroy(); - } - - @Override - public Set getServices() { - List services = polarisOperator.getServices(); - Set svcNames = new HashSet<>(); - for (ServiceInfo serviceInfo : services) { - svcNames.add(serviceInfo.getService()); - } - return svcNames; - } - - @Override - public List getInstances(String serviceName) throws NullPointerException { - Instance[] availableInstances = polarisOperator.getAvailableInstances(serviceName, !hasCircuitBreaker); - List instances = new ArrayList<>(); - for (Instance availableInstance : availableInstances) { - instances.add(instanceToServiceInstance(availableInstance)); - } - return instances; - } - - @Override - public void addServiceInstancesChangedListener(ServiceInstancesChangedListener listener) - throws NullPointerException, IllegalArgumentException { - PolarisInstancesHandler polarisInstancesHandler = new PolarisInstancesHandler(listener); - for (String serviceName : listener.getServiceNames()) { - LOGGER.info(String.format("[polaris] subscribe service: %s", serviceName)); - FetchTask fetchTask = new FetchTask(serviceName, polarisInstancesHandler, polarisOperator, !hasCircuitBreaker); - taskScheduler.submitWatchTask(new WatchTask(serviceName, fetchTask, taskScheduler)); - } - } - - @Override - public void removeServiceInstancesChangedListener(ServiceInstancesChangedListener listener) { - for (String serviceName : listener.getServiceNames()) { - LOGGER.info(String.format("[polaris] unsubscribe service: %s", serviceName)); - ServiceListener serviceListener = serviceListeners.remove(serviceName); - if (null != serviceListener) { - polarisOperator.unwatchService(serviceName, serviceListener); - } - } - } - - private ServiceInstance instanceToServiceInstance(Instance instance) { - ServiceInstance serviceInstance = new DefaultServiceInstance( - instance.getService(), instance.getHost(), instance.getPort(), applicationModel); - Map newMetadata = new HashMap<>(instance.getMetadata()); - boolean hasWeight = false; - if (newMetadata.containsKey(Constants.WEIGHT_KEY)) { - String weightStr = newMetadata.get(Constants.WEIGHT_KEY); - try { - int weightValue = Integer.parseInt(weightStr); - if (weightValue == instance.getWeight()) { - hasWeight = true; - } - } catch (Exception ignored) { - } - } - if (!hasWeight) { - newMetadata.put(Constants.WEIGHT_KEY, Integer.toString(instance.getWeight())); - } - String applicationName = newMetadata.getOrDefault(CommonConstants.APPLICATION_KEY, "" ); - MetadataInfo.ServiceInfo serviceInfo = new MetadataInfo.ServiceInfo( - instance.getService(), CommonConstants.ANY_VALUE, - instance.getVersion(), - instance.getProtocol(), instance.getPort(), - newMetadata.getOrDefault(CommonConstants.PATH_KEY, ""), newMetadata); - Map serviceInfoMap = new HashMap<>(); - serviceInfoMap.put(instance.getService(), serviceInfo); - MetadataInfo metadataInfo = new MetadataInfo(applicationName, instance.getRevision(), serviceInfoMap); - serviceInstance.setServiceMetadata(metadataInfo); - serviceInstance.getMetadata().putAll(newMetadata); - - serviceInstance.putExtendParamIfAbsent(Consts.INSTANCE_KEY_ID, instance.getId()); - serviceInstance.putExtendParamIfAbsent(Consts.INSTANCE_KEY_HEALTHY, Boolean.toString(instance.isHealthy())); - serviceInstance.putExtendParamIfAbsent(Consts.INSTANCE_KEY_ISOLATED, Boolean.toString(instance.isIsolated())); - serviceInstance.putExtendParamIfAbsent(Consts.INSTANCE_KEY_CIRCUIT_BREAKER, ConvertUtils.circuitBreakersToString(instance)); - return serviceInstance; - } - - private class PolarisInstancesHandler implements InstancesHandler { - - private final ServiceInstancesChangedListener listener; - - public PolarisInstancesHandler(ServiceInstancesChangedListener listener) { - this.listener = listener; - } - - @Override - public void onInstances(String serviceName, Instance[] instances) { - List serviceInstances = new ArrayList<>(); - for (Instance instance : instances) { - serviceInstances.add(instanceToServiceInstance(instance)); - } - listener.onEvent(new ServiceInstancesChangedEvent(serviceName, serviceInstances)); - } - - @Override - public void onWatchSuccess(String serviceName, ServiceListener serviceListener) { - serviceListeners.put(serviceName, serviceListener); - } - } -} diff --git a/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/PolarisServiceDiscoveryFactory.java b/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/PolarisServiceDiscoveryFactory.java deleted file mode 100644 index 52f9e3af6..000000000 --- a/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/PolarisServiceDiscoveryFactory.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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 org.apache.dubbo.registry.polaris; - -import org.apache.dubbo.common.URL; -import org.apache.dubbo.registry.client.AbstractServiceDiscoveryFactory; -import org.apache.dubbo.registry.client.ServiceDiscovery; - -public class PolarisServiceDiscoveryFactory extends AbstractServiceDiscoveryFactory { - - @Override - protected ServiceDiscovery createDiscovery(URL registryURL) { - return new PolarisRegistryServiceDiscovery(applicationModel, registryURL); - } -} diff --git a/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/src/main/java/org/apache/dubbo/filter/dubbo2/ReportFilter.java b/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/filter/ReportFilter.java similarity index 98% rename from dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/src/main/java/org/apache/dubbo/filter/dubbo2/ReportFilter.java rename to dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/filter/ReportFilter.java index 78a81d746..8449db66c 100644 --- a/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/src/main/java/org/apache/dubbo/filter/dubbo2/ReportFilter.java +++ b/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/filter/ReportFilter.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.dubbo.filter.dubbo2; +package org.apache.dubbo.registry.polaris.filter; import com.tencent.polaris.api.pojo.RetStatus; diff --git a/dubbo-registry-extensions/dubbo-registry-polaris/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.ServiceDiscoveryFactory b/dubbo-registry-extensions/dubbo-registry-polaris/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.ServiceDiscoveryFactory deleted file mode 100644 index e2e23c949..000000000 --- a/dubbo-registry-extensions/dubbo-registry-polaris/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.ServiceDiscoveryFactory +++ /dev/null @@ -1 +0,0 @@ -polaris=org.apache.dubbo.registry.polaris.PolarisServiceDiscoveryFactory \ No newline at end of file diff --git a/dubbo-registry-extensions/dubbo-registry-polaris/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter b/dubbo-registry-extensions/dubbo-registry-polaris/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter new file mode 100644 index 000000000..8169e696c --- /dev/null +++ b/dubbo-registry-extensions/dubbo-registry-polaris/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter @@ -0,0 +1 @@ +polaris_report=org.apache.dubbo.registry.polaris.filter.ReportFilter diff --git a/dubbo-registry-extensions/dubbo-registry-polaris/src/test/java/org/apache/dubbo/registry/polaris/PolarisRegistryServiceDiscoveryTest.java b/dubbo-registry-extensions/dubbo-registry-polaris/src/test/java/org/apache/dubbo/registry/polaris/PolarisRegistryServiceDiscoveryTest.java deleted file mode 100644 index 084370e9f..000000000 --- a/dubbo-registry-extensions/dubbo-registry-polaris/src/test/java/org/apache/dubbo/registry/polaris/PolarisRegistryServiceDiscoveryTest.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * 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 org.apache.dubbo.registry.polaris; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.atomic.AtomicBoolean; -import org.apache.dubbo.common.URL; -import org.apache.dubbo.common.utils.NetUtils; -import org.apache.dubbo.common.utils.StringUtils; -import org.apache.dubbo.config.ApplicationConfig; -import org.apache.dubbo.registry.NotifyListener; -import org.apache.dubbo.registry.client.DefaultServiceInstance; -import org.apache.dubbo.registry.client.ServiceInstance; -import org.apache.dubbo.registry.client.event.listener.ServiceInstancesChangedListener; -import org.apache.dubbo.rpc.model.ApplicationModel; -import org.apache.dubbo.rpc.model.FrameworkModel; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - -public class PolarisRegistryServiceDiscoveryTest { - - private static PolarisRegistryServiceDiscovery polarisRegistryServiceDiscovery; - - private static ApplicationModel applicationModel; - - @BeforeAll - public static void setup() { - Map parameters = new HashMap<>(); - parameters.put("namespace", "dubbo-java-test"); - parameters.put("persist_enable", "false"); - URL url = new URL("polaris", "183.47.111.80", 8091, parameters); - applicationModel = FrameworkModel.defaultModel().newApplication(); - applicationModel.getApplicationConfigManager().setApplication(new ApplicationConfig("Test")); - polarisRegistryServiceDiscovery = new PolarisRegistryServiceDiscovery(applicationModel, url); - } - - @AfterAll - public static void teardown() { - if (null != polarisRegistryServiceDiscovery) { - polarisRegistryServiceDiscovery.doDestroy(); - } - } - - @Test - public void testRegister() { - int count = 10; - String svcName = "polaris-registry-test-service-register"; - String host = NetUtils.getLocalHost(); - List serviceInstances = buildInstanceUrls(svcName, host, 11300, count); - for (ServiceInstance serviceInstance : serviceInstances) { - polarisRegistryServiceDiscovery.doRegister(serviceInstance); - } - try { - Thread.sleep(5000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - try { - List instances = polarisRegistryServiceDiscovery.getInstances(svcName); - Assertions.assertEquals(count, countInstanceByHost(host, instances)); - } finally { - for (ServiceInstance serviceInstance : serviceInstances) { - polarisRegistryServiceDiscovery.doUnregister(serviceInstance); - } - } - } - - private static List buildInstanceUrls(String service, String host, int startPort, int count) { - List serviceUrls = new ArrayList<>(); - for (int i = 0; i < count; i++) { - ServiceInstance serviceInstance = new DefaultServiceInstance(service, host, startPort + i, applicationModel); - serviceUrls.add(serviceInstance); - } - return serviceUrls; - } - - @Test - public void testSubscribe() { - int count = 10; - AtomicBoolean notified = new AtomicBoolean(false); - String svcName = "polaris-registry-test-service-subscribe"; - Set services = new HashSet<>(); - services.add(svcName); - ServiceInstancesChangedListener serviceInstancesChangedListener = new ServiceInstancesChangedListener(services, polarisRegistryServiceDiscovery); - URL consumerUrl = URL.valueOf("consumer://0.0.0.0/" + svcName); - NotifyListener listener = new NotifyListener() { - @Override - public void notify(List urls) { - notified.set(true); - //notifiedCount.set(urls.size()); - } - - public ServiceInstancesChangedListener getServiceListener() { - return serviceInstancesChangedListener; - } - - public URL getConsumerUrl() { - return consumerUrl; - } - }; - String host = NetUtils.getLocalHost(); - serviceInstancesChangedListener.addListenerAndNotify(consumerUrl, listener); - polarisRegistryServiceDiscovery.addServiceInstancesChangedListener(serviceInstancesChangedListener); - List instances = buildInstanceUrls(svcName, host, 11300, count); - for (ServiceInstance instance : instances) { - polarisRegistryServiceDiscovery.doRegister(instance); - } - try { - Thread.sleep(5000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - polarisRegistryServiceDiscovery.removeServiceInstancesChangedListener(serviceInstancesChangedListener); - Assertions.assertTrue(notified.get()); - //Assertions.assertEquals(count, notifiedCount.get()); - for (ServiceInstance serviceInstance : instances) { - polarisRegistryServiceDiscovery.doUnregister(serviceInstance); - } - } - - private static int countInstanceByHost(String host, List instances) { - int count = 0; - for (ServiceInstance instance : instances) { - if (StringUtils.isEquals(host, instance.getHost())) { - count++; - } - } - return count; - } -} From b7028f64b147f516b0aa1ecb6d5a910d9982e2e7 Mon Sep 17 00:00:00 2001 From: Albumen Kevin Date: Thu, 5 Jan 2023 10:45:58 +0800 Subject: [PATCH 06/35] Set seata core as optional dependency (#188) --- dubbo-filter-extensions/dubbo-filter-seata/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/dubbo-filter-extensions/dubbo-filter-seata/pom.xml b/dubbo-filter-extensions/dubbo-filter-seata/pom.xml index 9f9120037..71380f19f 100644 --- a/dubbo-filter-extensions/dubbo-filter-seata/pom.xml +++ b/dubbo-filter-extensions/dubbo-filter-seata/pom.xml @@ -34,6 +34,7 @@ io.seata seata-core + true org.apache.dubbo From da2866cbdca17384904a268fef993edb186b23e0 Mon Sep 17 00:00:00 2001 From: CrazyLionLi <31852897+JavaLionLi@users.noreply.github.com> Date: Tue, 10 Jan 2023 17:17:06 +0800 Subject: [PATCH 07/35] optimize: kryo 5.4.0 optimize compatibility with jdk17 (#190) --- dubbo-extensions-dependencies-bom/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dubbo-extensions-dependencies-bom/pom.xml b/dubbo-extensions-dependencies-bom/pom.xml index 3475eb7c0..33af21b76 100644 --- a/dubbo-extensions-dependencies-bom/pom.xml +++ b/dubbo-extensions-dependencies-bom/pom.xml @@ -112,7 +112,7 @@ 1.2.83 2.48-jdk-6 2.8.9 - 5.3.0 + 5.4.0 0.45 0.8.22 1.5.9 From 12502f2a5222d3013c7ba8718fe604a80ab57d03 Mon Sep 17 00:00:00 2001 From: Arnout Engelen Date: Mon, 13 Mar 2023 12:55:37 +0100 Subject: [PATCH 08/35] Explicitly call out hessian-rpc is unstafe by default (#196) --- dubbo-rpc-extensions/dubbo-rpc-hessian/README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 dubbo-rpc-extensions/dubbo-rpc-hessian/README.md diff --git a/dubbo-rpc-extensions/dubbo-rpc-hessian/README.md b/dubbo-rpc-extensions/dubbo-rpc-hessian/README.md new file mode 100644 index 000000000..e1a646543 --- /dev/null +++ b/dubbo-rpc-extensions/dubbo-rpc-hessian/README.md @@ -0,0 +1,14 @@ +# dubbo-rpc-hessian + +## Security + +Warning: by default, anyone who can provide data to the Hessian deserializer +can cause it to run arbitrary code. + +For that reason, if you enable the dubbo-rpc-hessian component, you must make +sure your deployment is only reachable by trusted parties, and/or configure +a serialization whitelist. Unfortunately we don't currently have any +documentation on how to configure a serialization whitelist. + +For more general information on how to deal with deserialization security, +see [this page](https://dubbo.apache.org/en/docs/notices/security/#some-suggestions-to-deal-with-the-security-vulnerability-of-deserialization) From fd0cb02600ceb633644b755a20ee2b4ee445297b Mon Sep 17 00:00:00 2001 From: wxbty <38374721+wxbty@users.noreply.github.com> Date: Thu, 27 Apr 2023 16:09:16 +0800 Subject: [PATCH 09/35] add Gateway mode extension (#205) * add gateway mode * code style * Increase the original parameter type, javaBeanDescriptor passes the actual parameter type * add gateway mod * revert spc * use spi byteAccessor * add licence * add licnece * fix meta-inf * fix bug * fix * fix ver * remove unuse * fix ver * remove unuse * add some opt * add some opt * fix dep * fix licence --------- Co-authored-by: x-shadow-man <1494445739@qq.com> --- .../UserSpecifiedAddressRouter.java | 18 +- .../UserSpecifiedAddressRouter.java | 4 +- dubbo-extensions-dependencies-bom/pom.xml | 2 +- .../dubbo-gateway-common/pom.xml | 29 +++ .../common/OmnipotentCommonConstants.java | 40 +++++ .../dubbo-gateway-consumer/pom.xml | 42 +++++ .../config/InjvmConfigPostProcessor.java | 32 ++++ .../gateway/consumer/filter/OmnSerFilter.java | 166 +++++++++++++++++ ...rg.apache.dubbo.config.ConfigPostProcessor | 1 + .../internal/org.apache.dubbo.rpc.Filter | 1 + .../dubbo-gateway-provider/pom.xml | 50 ++++++ .../provider/ConfigDeployListener.java | 55 ++++++ .../gateway/provider/OmnipotentService.java | 42 +++++ .../gateway/provider/SnfByteAccessor.java | 46 +++++ .../provider/SnfDecodeableRpcInvocation.java | 168 ++++++++++++++++++ .../provider/filter/OmnipotentFilter.java | 91 ++++++++++ ...bo.common.deploy.ApplicationDeployListener | 1 + .../internal/org.apache.dubbo.rpc.Filter | 1 + ...ache.dubbo.rpc.protocol.dubbo.ByteAccessor | 1 + dubbo-gateway-extensions/pom.xml | 37 ++++ dubbo-mock-extensions/README.md | 3 +- dubbo-mock-extensions/README_ch.md | 3 +- pom.xml | 3 +- .../dubbo-serialization-avro-test/pom.xml | 2 +- .../dubbo-serialization-fastjson-test/pom.xml | 2 +- .../dubbo-serialization-fst-test/pom.xml | 2 +- .../dubbo-serialization-gson-test/pom.xml | 2 +- .../dubbo-serialization-kryo-test/pom.xml | 4 +- .../dubbo-serialization-protobuf-test/pom.xml | 2 +- .../pom.xml | 2 +- 30 files changed, 829 insertions(+), 23 deletions(-) create mode 100644 dubbo-gateway-extensions/dubbo-gateway-common/pom.xml create mode 100644 dubbo-gateway-extensions/dubbo-gateway-common/src/main/java/org/apache/dubbo/gateway/common/OmnipotentCommonConstants.java create mode 100644 dubbo-gateway-extensions/dubbo-gateway-consumer/pom.xml create mode 100644 dubbo-gateway-extensions/dubbo-gateway-consumer/src/main/java/org/apache/dubbo/gateway/consumer/config/InjvmConfigPostProcessor.java create mode 100644 dubbo-gateway-extensions/dubbo-gateway-consumer/src/main/java/org/apache/dubbo/gateway/consumer/filter/OmnSerFilter.java create mode 100644 dubbo-gateway-extensions/dubbo-gateway-consumer/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.config.ConfigPostProcessor create mode 100644 dubbo-gateway-extensions/dubbo-gateway-consumer/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter create mode 100644 dubbo-gateway-extensions/dubbo-gateway-provider/pom.xml create mode 100644 dubbo-gateway-extensions/dubbo-gateway-provider/src/main/java/org/apache/dubbo/gateway/provider/ConfigDeployListener.java create mode 100644 dubbo-gateway-extensions/dubbo-gateway-provider/src/main/java/org/apache/dubbo/gateway/provider/OmnipotentService.java create mode 100644 dubbo-gateway-extensions/dubbo-gateway-provider/src/main/java/org/apache/dubbo/gateway/provider/SnfByteAccessor.java create mode 100644 dubbo-gateway-extensions/dubbo-gateway-provider/src/main/java/org/apache/dubbo/gateway/provider/SnfDecodeableRpcInvocation.java create mode 100644 dubbo-gateway-extensions/dubbo-gateway-provider/src/main/java/org/apache/dubbo/gateway/provider/filter/OmnipotentFilter.java create mode 100644 dubbo-gateway-extensions/dubbo-gateway-provider/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.deploy.ApplicationDeployListener create mode 100644 dubbo-gateway-extensions/dubbo-gateway-provider/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter create mode 100644 dubbo-gateway-extensions/dubbo-gateway-provider/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.dubbo.ByteAccessor create mode 100644 dubbo-gateway-extensions/pom.xml diff --git a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressRouter.java b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressRouter.java index 84275e654..3ca0ab1d8 100644 --- a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressRouter.java +++ b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressRouter.java @@ -175,7 +175,7 @@ public Invoker getInvokerByIp(Address address) { private void throwException(Address address) { throw new RpcException("user specified server address : [" + address + "] is not a valid provider for service: [" - + getUrl().getServiceKey() + "]"); + + getUrl().getServiceKey() + "]"); } @@ -253,14 +253,14 @@ public URL buildAddress(List> invokers, Address address, URL cons private URL copyConsumerUrl(URL url, String ip, int port, Map parameters) { return URLBuilder.from(url) - .setHost(ip) - .setPort(port) - .setProtocol(url.getProtocol() == null ? DUBBO : url.getProtocol()) - .setPath(url.getPath()) - .clearParameters() - .addParameters(parameters) - .removeParameter(MONITOR_KEY) - .build(); + .setHost(ip) + .setPort(port) + .setProtocol(url.getProtocol() == null ? DUBBO : url.getProtocol()) + .setPath(url.getPath()) + .clearParameters() + .addParameters(parameters) + .removeParameter(MONITOR_KEY) + .build(); } public URL rebuildAddress(Address address, URL consumerUrl) { diff --git a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressRouter.java b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressRouter.java index 00290a482..5ce7281b1 100644 --- a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressRouter.java +++ b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/UserSpecifiedAddressRouter.java @@ -70,7 +70,7 @@ public UserSpecifiedAddressRouter(URL referenceUrl) { this.scheduledExecutorService = referenceUrl.getScopeModel().getDefaultExtension(ExecutorRepository.class).nextScheduledExecutor(); this.protocol = referenceUrl.getOrDefaultFrameworkModel().getExtensionLoader(Protocol.class).getAdaptiveExtension(); this.userSpecifiedServiceAddressBuilder = referenceUrl.getScopeModel().getExtensionLoader(UserSpecifiedServiceAddressBuilder.class) - .getExtension(referenceUrl.getParameter(USER_SPECIFIED_SERVICE_ADDRESS_BUILDER_KEY, DefaultUserSpecifiedServiceAddressBuilder.NAME)); + .getExtension(referenceUrl.getParameter(USER_SPECIFIED_SERVICE_ADDRESS_BUILDER_KEY, DefaultUserSpecifiedServiceAddressBuilder.NAME)); } @Override @@ -240,7 +240,7 @@ private Invoker refer(URL url) { private void throwException(Address address) { throw new RpcException("user specified server address : [" + address + "] is not a valid provider for service: [" - + getUrl().getServiceKey() + "]"); + + getUrl().getServiceKey() + "]"); } private Map> processIp(List> invokerList) { diff --git a/dubbo-extensions-dependencies-bom/pom.xml b/dubbo-extensions-dependencies-bom/pom.xml index 33af21b76..ad325aa15 100644 --- a/dubbo-extensions-dependencies-bom/pom.xml +++ b/dubbo-extensions-dependencies-bom/pom.xml @@ -89,7 +89,7 @@ - 1.0.4-SNAPSHOT + 1.0.5-SNAPSHOT 3.1.2 5.2.9.RELEASE 2.4.1 diff --git a/dubbo-gateway-extensions/dubbo-gateway-common/pom.xml b/dubbo-gateway-extensions/dubbo-gateway-common/pom.xml new file mode 100644 index 000000000..7c401d8b6 --- /dev/null +++ b/dubbo-gateway-extensions/dubbo-gateway-common/pom.xml @@ -0,0 +1,29 @@ + + + + dubbo-gateway-extensions + org.apache.dubbo.extensions + ${revision} + ../pom.xml + + 4.0.0 + + dubbo-gateway-common + + diff --git a/dubbo-gateway-extensions/dubbo-gateway-common/src/main/java/org/apache/dubbo/gateway/common/OmnipotentCommonConstants.java b/dubbo-gateway-extensions/dubbo-gateway-common/src/main/java/org/apache/dubbo/gateway/common/OmnipotentCommonConstants.java new file mode 100644 index 000000000..314bcf381 --- /dev/null +++ b/dubbo-gateway-extensions/dubbo-gateway-common/src/main/java/org/apache/dubbo/gateway/common/OmnipotentCommonConstants.java @@ -0,0 +1,40 @@ +/* + * 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 org.apache.dubbo.gateway.common; + +public interface OmnipotentCommonConstants { + + //save origin group when service is omn + String ORIGIN_GROUP_KEY = "originGroup"; + + String ORIGIN_GENERIC_PARAMETER_TYPES = "originGenericParameterTypes"; + + String ORIGIN_PARAMETER_TYPES_DESC = "originParameterTypesDesc"; + + String $INVOKE_OMN = "$invokeOmn"; + + String ORIGIN_PATH_KEY = "originPath"; + + String ORIGIN_METHOD_KEY = "originMethod"; + + String ORIGIN_VERSION_KEY = "originVersion"; + + String SPECIFY_ADDRESS = "specifyAddress"; + String GATEWAY_MODE = "gatewayMode"; + +} diff --git a/dubbo-gateway-extensions/dubbo-gateway-consumer/pom.xml b/dubbo-gateway-extensions/dubbo-gateway-consumer/pom.xml new file mode 100644 index 000000000..2d1ead7f7 --- /dev/null +++ b/dubbo-gateway-extensions/dubbo-gateway-consumer/pom.xml @@ -0,0 +1,42 @@ + + + + dubbo-gateway-extensions + org.apache.dubbo.extensions + ${revision} + ../pom.xml + + 4.0.0 + + dubbo-gateway-consumer + + + + org.apache.dubbo + dubbo + provided + + + org.apache.dubbo.extensions + dubbo-gateway-common + ${project.version} + + + + diff --git a/dubbo-gateway-extensions/dubbo-gateway-consumer/src/main/java/org/apache/dubbo/gateway/consumer/config/InjvmConfigPostProcessor.java b/dubbo-gateway-extensions/dubbo-gateway-consumer/src/main/java/org/apache/dubbo/gateway/consumer/config/InjvmConfigPostProcessor.java new file mode 100644 index 000000000..0212bd371 --- /dev/null +++ b/dubbo-gateway-extensions/dubbo-gateway-consumer/src/main/java/org/apache/dubbo/gateway/consumer/config/InjvmConfigPostProcessor.java @@ -0,0 +1,32 @@ +/* + * 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 org.apache.dubbo.gateway.consumer.config; + +import org.apache.dubbo.common.extension.Activate; +import org.apache.dubbo.config.ConfigPostProcessor; +import org.apache.dubbo.config.ReferenceConfig; +import org.apache.dubbo.rpc.Constants; + +@Activate +public class InjvmConfigPostProcessor implements ConfigPostProcessor { + + @Override + public void postProcessReferConfig(ReferenceConfig referenceConfig) { + referenceConfig.setScope(Constants.SCOPE_REMOTE); + } +} diff --git a/dubbo-gateway-extensions/dubbo-gateway-consumer/src/main/java/org/apache/dubbo/gateway/consumer/filter/OmnSerFilter.java b/dubbo-gateway-extensions/dubbo-gateway-consumer/src/main/java/org/apache/dubbo/gateway/consumer/filter/OmnSerFilter.java new file mode 100644 index 000000000..49f3b8f09 --- /dev/null +++ b/dubbo-gateway-extensions/dubbo-gateway-consumer/src/main/java/org/apache/dubbo/gateway/consumer/filter/OmnSerFilter.java @@ -0,0 +1,166 @@ +/* + * 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 org.apache.dubbo.gateway.consumer.filter; + +import org.apache.dubbo.common.beanutil.JavaBeanDescriptor; +import org.apache.dubbo.common.beanutil.JavaBeanSerializeUtil; +import org.apache.dubbo.common.constants.CommonConstants; +import org.apache.dubbo.common.extension.Activate; +import org.apache.dubbo.common.logger.Logger; +import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.ReflectUtils; +import org.apache.dubbo.rpc.Filter; +import org.apache.dubbo.rpc.Invocation; +import org.apache.dubbo.rpc.Invoker; +import org.apache.dubbo.rpc.Result; +import org.apache.dubbo.rpc.RpcContext; +import org.apache.dubbo.rpc.RpcException; +import org.apache.dubbo.rpc.RpcInvocation; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Stream; + +import static org.apache.dubbo.gateway.common.OmnipotentCommonConstants.GATEWAY_MODE; +import static org.apache.dubbo.gateway.common.OmnipotentCommonConstants.ORIGIN_GENERIC_PARAMETER_TYPES; +import static org.apache.dubbo.gateway.common.OmnipotentCommonConstants.ORIGIN_PARAMETER_TYPES_DESC; +import static org.apache.dubbo.gateway.common.OmnipotentCommonConstants.SPECIFY_ADDRESS; + + +@Activate(group = CommonConstants.CONSUMER) +public class OmnSerFilter implements Filter, Filter.Listener { + + private final static Logger logger = LoggerFactory.getLogger(OmnSerFilter.class); + + public static final String name = "specifyAddress"; + + @Override + public Result invoke(Invoker invoker, Invocation invocation) throws RpcException { + + Object address = invocation.get(SPECIFY_ADDRESS); + if (address != null) { + RpcContext.getClientAttachment().setAttachment(GATEWAY_MODE, "omn"); + convertParameterTypeToJavaBeanDescriptor(invocation); + } + return invoker.invoke(invocation); + } + + + @Override + public void onResponse(Result appResponse, Invoker invoker, Invocation inv) { + + Object resData = appResponse.getValue(); + if (resData == null) { + return; + } + + if (ReflectUtils.isPrimitives(resData.getClass())) { + return; + } + generalizeJbdParameter(appResponse.getValue()); + } + + @Override + public void onError(Throwable t, Invoker invoker, Invocation invocation) { + + } + + + @SuppressWarnings({"unchecked", "rawtypes"}) + private void generalizeJbdParameter(Object pojo) { + if (pojo instanceof Collection) { + + Collection collection = (Collection) pojo; + List list = new ArrayList(); + for (Object obj : collection) { + if (obj instanceof JavaBeanDescriptor) { + list.add(JavaBeanSerializeUtil.deserialize((JavaBeanDescriptor) obj)); + } else { + list.add(obj); + } + } + collection.clear(); + collection.addAll(list); + } + + if (pojo instanceof Map) { + + Map map = (Map) pojo; + Map newMap = new HashMap(); + for (Object key : map.keySet()) { + + Object value = map.get(key); + if (key instanceof JavaBeanDescriptor) { + key = JavaBeanSerializeUtil.deserialize((JavaBeanDescriptor) key); + } + if (value instanceof JavaBeanDescriptor) { + value = JavaBeanSerializeUtil.deserialize((JavaBeanDescriptor) value); + } + newMap.put(key, value); + + } + map.clear(); + map.putAll(newMap); + } + + // public field + for (Field field : pojo.getClass().getDeclaredFields()) { + try { + field.setAccessible(true); + Object fieldValue = field.get(pojo); + if (fieldValue instanceof JavaBeanDescriptor) { + field.set(pojo, JavaBeanSerializeUtil.deserialize((JavaBeanDescriptor) fieldValue)); + } + } catch (Exception e) { + throw new RuntimeException(e.getMessage(), e); + } + } + } + + public static void convertParameterTypeToJavaBeanDescriptor(Invocation invocation) { + if (!(invocation instanceof RpcInvocation)) { + logger.warn("Non-RpcInvocation type, gateway mode does not take effect, type:" + invocation.getClass().getName()); + return; + } + Class[] parameterTypes = invocation.getParameterTypes(); + boolean reqFirst = Arrays.stream(parameterTypes).noneMatch(param -> param == JavaBeanDescriptor.class); + if (reqFirst) { + invocation.setObjectAttachment(ORIGIN_GENERIC_PARAMETER_TYPES, getDesc(parameterTypes)); + invocation.setObjectAttachment(ORIGIN_PARAMETER_TYPES_DESC, ((RpcInvocation) invocation).getParameterTypesDesc()); + Arrays.fill(parameterTypes, JavaBeanDescriptor.class); + + Object[] arguments = invocation.getArguments(); + for (int i = 0; i < arguments.length; i++) { + JavaBeanDescriptor jbdArg = JavaBeanSerializeUtil.serialize(arguments[i]); + arguments[i] = jbdArg; + } + + ((RpcInvocation) invocation).setParameterTypesDesc(ReflectUtils.getDesc(parameterTypes)); + ((RpcInvocation) invocation).setCompatibleParamSignatures(Stream.of(parameterTypes).map(Class::getName).toArray(String[]::new)); + } + + } + + private static String[] getDesc(Class[] parameterTypes) { + return Arrays.stream(parameterTypes).map(Class::getName).toArray(String[]::new); + } +} diff --git a/dubbo-gateway-extensions/dubbo-gateway-consumer/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.config.ConfigPostProcessor b/dubbo-gateway-extensions/dubbo-gateway-consumer/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.config.ConfigPostProcessor new file mode 100644 index 000000000..058a13e7f --- /dev/null +++ b/dubbo-gateway-extensions/dubbo-gateway-consumer/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.config.ConfigPostProcessor @@ -0,0 +1 @@ +injvm-initial=org.apache.dubbo.gateway.consumer.config.InjvmConfigPostProcessor diff --git a/dubbo-gateway-extensions/dubbo-gateway-consumer/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter b/dubbo-gateway-extensions/dubbo-gateway-consumer/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter new file mode 100644 index 000000000..319ef6f04 --- /dev/null +++ b/dubbo-gateway-extensions/dubbo-gateway-consumer/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter @@ -0,0 +1 @@ +omnSer=org.apache.dubbo.gateway.consumer.filter.OmnSerFilter diff --git a/dubbo-gateway-extensions/dubbo-gateway-provider/pom.xml b/dubbo-gateway-extensions/dubbo-gateway-provider/pom.xml new file mode 100644 index 000000000..c673308cb --- /dev/null +++ b/dubbo-gateway-extensions/dubbo-gateway-provider/pom.xml @@ -0,0 +1,50 @@ + + + + dubbo-gateway-extensions + org.apache.dubbo.extensions + ${revision} + ../pom.xml + + 4.0.0 + + dubbo-gateway-provider + + + 8 + 8 + + + + + + org.apache.dubbo + dubbo + 3.2.0 + true + + + org.apache.dubbo.extensions + dubbo-gateway-common + ${project.version} + + + + + diff --git a/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/java/org/apache/dubbo/gateway/provider/ConfigDeployListener.java b/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/java/org/apache/dubbo/gateway/provider/ConfigDeployListener.java new file mode 100644 index 000000000..788d8c024 --- /dev/null +++ b/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/java/org/apache/dubbo/gateway/provider/ConfigDeployListener.java @@ -0,0 +1,55 @@ +/* + * 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 org.apache.dubbo.gateway.provider; + +import org.apache.dubbo.common.deploy.ApplicationDeployListener; +import org.apache.dubbo.rpc.model.ApplicationModel; + +import static org.apache.dubbo.common.constants.CommonConstants.BYTE_ACCESSOR_KEY; + +public class ConfigDeployListener implements ApplicationDeployListener { + + @Override + public void onInitialize(ApplicationModel scopeModel) { + System.setProperty(BYTE_ACCESSOR_KEY, "snf"); + } + + @Override + public void onStarting(ApplicationModel scopeModel) { + + } + + @Override + public void onStarted(ApplicationModel scopeModel) { + } + + @Override + public void onStopping(ApplicationModel scopeModel) { + + } + + @Override + public void onStopped(ApplicationModel scopeModel) { + + } + + @Override + public void onFailure(ApplicationModel scopeModel, Throwable cause) { + + } +} diff --git a/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/java/org/apache/dubbo/gateway/provider/OmnipotentService.java b/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/java/org/apache/dubbo/gateway/provider/OmnipotentService.java new file mode 100644 index 000000000..07a8ae3e3 --- /dev/null +++ b/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/java/org/apache/dubbo/gateway/provider/OmnipotentService.java @@ -0,0 +1,42 @@ +/* + * 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 org.apache.dubbo.gateway.provider; + +import org.apache.dubbo.rpc.Invocation; +import org.apache.dubbo.rpc.service.GenericException; +import org.apache.dubbo.rpc.service.GenericService; + +/** + * A more general server-side generalization service than {@link GenericService} + * Any type of interface can be accepted + * + * @since 3.2.0 + */ +public interface OmnipotentService { + + /** + * Generic invocation + * + * @param invocation New construction point invocation, including original service, method and other information + * @return Custom object + * @throws GenericException potential exception thrown from the invocation + */ + Object $invokeOmn(Invocation invocation) throws GenericException; + + +} diff --git a/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/java/org/apache/dubbo/gateway/provider/SnfByteAccessor.java b/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/java/org/apache/dubbo/gateway/provider/SnfByteAccessor.java new file mode 100644 index 000000000..9adf60254 --- /dev/null +++ b/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/java/org/apache/dubbo/gateway/provider/SnfByteAccessor.java @@ -0,0 +1,46 @@ +/* + * 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 org.apache.dubbo.gateway.provider; + +import org.apache.dubbo.remoting.Channel; +import org.apache.dubbo.remoting.exchange.Request; +import org.apache.dubbo.rpc.model.FrameworkModel; +import org.apache.dubbo.rpc.protocol.dubbo.ByteAccessor; +import org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation; + +import java.io.InputStream; + +/** + * Customize byte parsing so that execution can continue when the service does not exist + * + * @since 3.2.0 + */ +public class SnfByteAccessor implements ByteAccessor { + + private final FrameworkModel frameworkModel; + + public SnfByteAccessor(FrameworkModel frameworkModel) { + this.frameworkModel = frameworkModel; + } + + @Override + public DecodeableRpcInvocation getRpcInvocation(Channel channel, Request req, InputStream is, byte proto) { + + return new SnfDecodeableRpcInvocation(frameworkModel, channel, req, is, proto); + } +} diff --git a/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/java/org/apache/dubbo/gateway/provider/SnfDecodeableRpcInvocation.java b/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/java/org/apache/dubbo/gateway/provider/SnfDecodeableRpcInvocation.java new file mode 100644 index 000000000..899939745 --- /dev/null +++ b/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/java/org/apache/dubbo/gateway/provider/SnfDecodeableRpcInvocation.java @@ -0,0 +1,168 @@ +/* + * 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 org.apache.dubbo.gateway.provider; + +import org.apache.dubbo.common.beanutil.JavaBeanDescriptor; +import org.apache.dubbo.common.beanutil.JavaBeanSerializeUtil; +import org.apache.dubbo.common.serialize.Cleanable; +import org.apache.dubbo.common.serialize.ObjectInput; +import org.apache.dubbo.common.utils.CollectionUtils; +import org.apache.dubbo.common.utils.ReflectUtils; +import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.gateway.common.OmnipotentCommonConstants; +import org.apache.dubbo.remoting.Channel; +import org.apache.dubbo.remoting.exchange.Request; +import org.apache.dubbo.remoting.transport.CodecSupport; +import org.apache.dubbo.rpc.Invocation; +import org.apache.dubbo.rpc.model.FrameworkModel; +import org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation; +import org.apache.dubbo.rpc.protocol.dubbo.DubboCodec; +import org.apache.dubbo.rpc.support.RpcUtils; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Map; + +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_VERSION; +import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_VERSION_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.METHOD_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; +import static org.apache.dubbo.gateway.common.OmnipotentCommonConstants.$INVOKE_OMN; +import static org.apache.dubbo.gateway.common.OmnipotentCommonConstants.ORIGIN_GENERIC_PARAMETER_TYPES; +import static org.apache.dubbo.gateway.common.OmnipotentCommonConstants.ORIGIN_GROUP_KEY; +import static org.apache.dubbo.gateway.common.OmnipotentCommonConstants.ORIGIN_PARAMETER_TYPES_DESC; +import static org.apache.dubbo.rpc.Constants.SERIALIZATION_ID_KEY; + +public class SnfDecodeableRpcInvocation extends DecodeableRpcInvocation { + + private static final String DEFAULT_OMNIPOTENT_SERVICE = OmnipotentService.class.getName(); + + + public SnfDecodeableRpcInvocation(FrameworkModel frameworkModel, Channel channel, Request request, InputStream is, byte id) { + super(frameworkModel, channel, request, is, id); + } + + @Override + public Object decode(Channel channel, InputStream input) throws IOException { + ObjectInput in = CodecSupport.getSerialization(serializationType) + .deserialize(channel.getUrl(), input); + this.put(SERIALIZATION_ID_KEY, serializationType); + + String dubboVersion = in.readUTF(); + request.setVersion(dubboVersion); + setAttachment(DUBBO_VERSION_KEY, dubboVersion); + + String path = in.readUTF(); + setAttachment(PATH_KEY, path); + String version = in.readUTF(); + setAttachment(VERSION_KEY, version); + + setMethodName(in.readUTF()); + + String desc = in.readUTF(); + setParameterTypesDesc(desc); + + ClassLoader originClassLoader = Thread.currentThread().getContextClassLoader(); + + try { + Object[] args = DubboCodec.EMPTY_OBJECT_ARRAY; + Class[] pts = DubboCodec.EMPTY_CLASS_ARRAY; + if (desc.length() > 0) { + pts = drawPts(path, version, desc, pts); + if (pts == DubboCodec.EMPTY_CLASS_ARRAY) { + // Service not found ,pts = JavaBeanDescriptor + pts = ReflectUtils.desc2classArray(desc); + } + args = drawArgs(in, pts); + } + setParameterTypes(pts); + setAttachment(ORIGIN_GENERIC_PARAMETER_TYPES, pts); + + Map map = in.readAttachments(); + Class[] retryPts = null; + if (CollectionUtils.isNotEmptyMap(map)) { + if (map.containsKey(ORIGIN_PARAMETER_TYPES_DESC)) { + String originParameterTypesDesc = map.get(ORIGIN_PARAMETER_TYPES_DESC).toString(); + retryPts = drawPts(path, version, originParameterTypesDesc, DubboCodec.EMPTY_CLASS_ARRAY); + boolean snf = (retryPts == DubboCodec.EMPTY_CLASS_ARRAY) && !RpcUtils.isGenericCall(originParameterTypesDesc, getMethodName()) && !RpcUtils.isEcho(originParameterTypesDesc, getMethodName()); + if (snf) { + setAttachment(OmnipotentCommonConstants.ORIGIN_PATH_KEY, getAttachment(PATH_KEY)); + // Replace serviceName in req with omn + setAttachment(PATH_KEY, DEFAULT_OMNIPOTENT_SERVICE); + setAttachment(INTERFACE_KEY, DEFAULT_OMNIPOTENT_SERVICE); + + // version + setAttachment(OmnipotentCommonConstants.ORIGIN_VERSION_KEY, getAttachment(VERSION_KEY)); + setAttachment(VERSION_KEY, DEFAULT_VERSION); + + // method + setAttachment(OmnipotentCommonConstants.ORIGIN_METHOD_KEY, getMethodName()); + setAttachment(METHOD_KEY, $INVOKE_OMN); + setMethodName($INVOKE_OMN); + setParameterTypes(new Class[]{Invocation.class}); + + // Omn needs to use the default path, version and group, + // and the original value starts with origin to save the variable + map.remove(PATH_KEY); + map.remove(VERSION_KEY); + if (map.containsKey(GROUP_KEY)) { + map.put(ORIGIN_GROUP_KEY, map.get(GROUP_KEY)); + map.remove(GROUP_KEY); + } + retryPts = (Class[]) getObjectAttachments().get(ORIGIN_GENERIC_PARAMETER_TYPES); + } + } + + addObjectAttachments(map); + } + + boolean isConvert = false; + for (Class clazz : pts) { + if (clazz == JavaBeanDescriptor.class) { + isConvert = true; + break; + } + } + // isConvert = snf + if (isConvert) { + setParameterTypes(retryPts); + pts = retryPts; + Object[] newArgs = new Object[args.length]; + for (int i = 0; i < args.length; i++) { + if (args[i] instanceof JavaBeanDescriptor) { + newArgs[i] = JavaBeanSerializeUtil.deserialize((JavaBeanDescriptor) args[i]); + } + } + args = newArgs; + } + decodeArgument(channel, pts, args); + } catch (ClassNotFoundException e) { + throw new IOException(StringUtils.toString("Read invocation data failed.", e)); + } finally { + Thread.currentThread().setContextClassLoader(originClassLoader); + if (in instanceof Cleanable) { + ((Cleanable) in).cleanup(); + } + } + return this; + } + +} diff --git a/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/java/org/apache/dubbo/gateway/provider/filter/OmnipotentFilter.java b/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/java/org/apache/dubbo/gateway/provider/filter/OmnipotentFilter.java new file mode 100644 index 000000000..3357a6dd3 --- /dev/null +++ b/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/java/org/apache/dubbo/gateway/provider/filter/OmnipotentFilter.java @@ -0,0 +1,91 @@ +/* + * 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 org.apache.dubbo.gateway.provider.filter; + +import org.apache.dubbo.common.beanutil.JavaBeanAccessor; +import org.apache.dubbo.common.beanutil.JavaBeanDescriptor; +import org.apache.dubbo.common.beanutil.JavaBeanSerializeUtil; +import org.apache.dubbo.common.constants.CommonConstants; +import org.apache.dubbo.common.extension.Activate; +import org.apache.dubbo.gateway.common.OmnipotentCommonConstants; +import org.apache.dubbo.gateway.provider.OmnipotentService; +import org.apache.dubbo.rpc.Filter; +import org.apache.dubbo.rpc.Invocation; +import org.apache.dubbo.rpc.Invoker; +import org.apache.dubbo.rpc.Result; +import org.apache.dubbo.rpc.RpcContext; +import org.apache.dubbo.rpc.RpcException; +import org.apache.dubbo.rpc.RpcInvocation; + +import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; + +/** + * Set the method name, formal parameters, and actual parameters for + * the invokeOmn method of the Omnipotent generalized service + */ +@Activate(group = CommonConstants.PROVIDER, order = -21000) +public class OmnipotentFilter implements Filter { + + @Override + public Result invoke(Invoker invoker, Invocation inv) throws RpcException { + + if (isOmnipotent(invoker.getInterface())) { + setOmnArgs(inv); + inv.getObjectAttachments().remove(OmnipotentCommonConstants.ORIGIN_GENERIC_PARAMETER_TYPES); + RpcContext.getServerAttachment().removeAttachment(OmnipotentCommonConstants.ORIGIN_GENERIC_PARAMETER_TYPES); + } + + return invoker.invoke(inv); + } + + private boolean isOmnipotent(Class interfaceClass) { + return OmnipotentService.class.isAssignableFrom(interfaceClass); + } + + // Restore method information before actual call + private void setOmnArgs(Invocation inv) { + Class[] parameterTypes = (Class[]) inv.getObjectAttachment(OmnipotentCommonConstants.ORIGIN_GENERIC_PARAMETER_TYPES, new Class[]{Invocation.class}); + Object[] arguments = inv.getArguments(); + + Object[] args = new Object[arguments.length]; + for (int i = 0; i < arguments.length; i++) { + // In gateway mode, consumer has used JavaBeanDescriptor as parameter + if (arguments[i] instanceof JavaBeanDescriptor) { + args[i] = arguments[i]; + } else { + args[i] = JavaBeanSerializeUtil.serialize(arguments[i], JavaBeanAccessor.METHOD); + } + } + + RpcInvocation rpcInvocation = new RpcInvocation(inv); + // method + rpcInvocation.setMethodName(inv.getAttachment(OmnipotentCommonConstants.ORIGIN_METHOD_KEY)); + rpcInvocation.setParameterTypes(parameterTypes); + rpcInvocation.setArguments(args); + rpcInvocation.setParameterTypesDesc(inv.getAttachment(OmnipotentCommonConstants.ORIGIN_PARAMETER_TYPES_DESC)); + + // attachment + rpcInvocation.setAttachment(PATH_KEY, inv.getAttachment(OmnipotentCommonConstants.ORIGIN_PATH_KEY)); + rpcInvocation.setAttachment(VERSION_KEY, inv.getAttachment(OmnipotentCommonConstants.ORIGIN_VERSION_KEY)); + rpcInvocation.setAttachment(GROUP_KEY, inv.getAttachment(OmnipotentCommonConstants.ORIGIN_GROUP_KEY)); + ((RpcInvocation) inv).setArguments(new Object[]{rpcInvocation}); + + } + +} diff --git a/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.deploy.ApplicationDeployListener b/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.deploy.ApplicationDeployListener new file mode 100644 index 000000000..04ede7f59 --- /dev/null +++ b/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.deploy.ApplicationDeployListener @@ -0,0 +1 @@ +snfConfig=org.apache.dubbo.gateway.provider.ConfigDeployListener diff --git a/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter b/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter new file mode 100644 index 000000000..9247c64e2 --- /dev/null +++ b/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter @@ -0,0 +1 @@ +omnipotent=org.apache.dubbo.gateway.provider.filter.OmnipotentFilter diff --git a/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.dubbo.ByteAccessor b/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.dubbo.ByteAccessor new file mode 100644 index 000000000..7e33fa6bb --- /dev/null +++ b/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.dubbo.ByteAccessor @@ -0,0 +1 @@ +snf=org.apache.dubbo.gateway.provider.SnfByteAccessor diff --git a/dubbo-gateway-extensions/pom.xml b/dubbo-gateway-extensions/pom.xml new file mode 100644 index 000000000..3a41e5ac6 --- /dev/null +++ b/dubbo-gateway-extensions/pom.xml @@ -0,0 +1,37 @@ + + + + org.apache.dubbo.extensions + extensions-parent + ${revision} + ../pom.xml + + 4.0.0 + + dubbo-gateway-extensions + ${revision} + pom + + + dubbo-gateway-common + dubbo-gateway-provider + dubbo-gateway-consumer + + + diff --git a/dubbo-mock-extensions/README.md b/dubbo-mock-extensions/README.md index 0cb548772..7db308cca 100644 --- a/dubbo-mock-extensions/README.md +++ b/dubbo-mock-extensions/README.md @@ -9,8 +9,9 @@ - Add the dependency. ```xml + - org.apache.dubbo.extensions + org.apache.dubbo.gatewayorg.apache.dubbo.gateway dubbo-mock-admin 3.0.0 diff --git a/dubbo-mock-extensions/README_ch.md b/dubbo-mock-extensions/README_ch.md index e1d2af8b0..7aa6f44b5 100644 --- a/dubbo-mock-extensions/README_ch.md +++ b/dubbo-mock-extensions/README_ch.md @@ -9,8 +9,9 @@ - 引入依赖 ```xml + - org.apache.dubbo.extensions + org.apache.dubbo.gatewayorg.apache.dubbo.gateway dubbo-mock-admin 3.0.0 diff --git a/pom.xml b/pom.xml index eb91379fd..734d33a62 100644 --- a/pom.xml +++ b/pom.xml @@ -94,10 +94,11 @@ dubbo-rpc-extensions dubbo-serialization-extensions dubbo-mock-extensions + dubbo-gateway-extensions - 1.0.4-SNAPSHOT + 1.0.5-SNAPSHOT 5.6.0 3.11.1 diff --git a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-avro-test/pom.xml b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-avro-test/pom.xml index 3962b8827..a22b80f34 100644 --- a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-avro-test/pom.xml +++ b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-avro-test/pom.xml @@ -31,7 +31,7 @@ 3.0.4 4.13.1 4.3.29.RELEASE - 1.0.1-SNAPSHOT + 1.0.2-SNAPSHOT 3.7.0 diff --git a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-fastjson-test/pom.xml b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-fastjson-test/pom.xml index 89d2a7cda..f20a02332 100644 --- a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-fastjson-test/pom.xml +++ b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-fastjson-test/pom.xml @@ -32,7 +32,7 @@ 3.0.4 4.13.1 4.3.29.RELEASE - 1.0.1-SNAPSHOT + 1.0.2-SNAPSHOT 3.7.0 diff --git a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-fst-test/pom.xml b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-fst-test/pom.xml index b63a5853b..89977f146 100644 --- a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-fst-test/pom.xml +++ b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-fst-test/pom.xml @@ -32,7 +32,7 @@ 3.0.4 4.13.1 4.3.29.RELEASE - 1.0.1-SNAPSHOT + 1.0.2-SNAPSHOT 3.7.0 diff --git a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-gson-test/pom.xml b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-gson-test/pom.xml index 3bad54da6..67148472e 100644 --- a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-gson-test/pom.xml +++ b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-gson-test/pom.xml @@ -32,7 +32,7 @@ 3.0.4 4.13.1 4.3.29.RELEASE - 1.0.1-SNAPSHOT + 1.0.2-SNAPSHOT 3.7.0 diff --git a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-kryo-test/pom.xml b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-kryo-test/pom.xml index be0db1ca8..430f1c091 100644 --- a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-kryo-test/pom.xml +++ b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-kryo-test/pom.xml @@ -32,8 +32,8 @@ 3.0.4 4.13.1 4.3.29.RELEASE - 1.0.3-SNAPSHOT - 1.0.1-SNAPSHOT + 1.0.5-SNAPSHOT + 1.0.2-SNAPSHOT 3.7.0 diff --git a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-protobuf-test/pom.xml b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-protobuf-test/pom.xml index d12cc73be..0378770ed 100644 --- a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-protobuf-test/pom.xml +++ b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-protobuf-test/pom.xml @@ -33,7 +33,7 @@ 4.13.1 4.3.29.RELEASE 0.0.2 - 1.0.1-SNAPSHOT + 1.0.2-SNAPSHOT 3.7.0 diff --git a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-protostuff-test/pom.xml b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-protostuff-test/pom.xml index b15af1bc9..cff199ba6 100644 --- a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-protostuff-test/pom.xml +++ b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-protostuff-test/pom.xml @@ -32,7 +32,7 @@ 3.0.4 4.13.1 4.3.29.RELEASE - 1.0.1-SNAPSHOT + 1.0.2-SNAPSHOT 3.7.0 From 446c00f85a23be62d060f247ef4e9f8742660c74 Mon Sep 17 00:00:00 2001 From: Albumen Kevin Date: Thu, 27 Apr 2023 16:09:37 +0800 Subject: [PATCH 10/35] Update ci.yml --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 18d385a24..b9d607d6a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ ubuntu-18.04, windows-2019 ] + os: [ ubuntu-latest, windows-2019 ] jdk: [ 8, 11 ] steps: - uses: actions/checkout@v2 From 607519127a3bc1b7c54883326d48ce02102504a3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 27 Apr 2023 17:23:05 +0800 Subject: [PATCH 11/35] Bump snakeyaml from 1.32 to 2.0 in /test/dubbo-scenario-builder (#208) Bumps [snakeyaml](https://bitbucket.org/snakeyaml/snakeyaml) from 1.32 to 2.0. - [Commits](https://bitbucket.org/snakeyaml/snakeyaml/branches/compare/snakeyaml-2.0..snakeyaml-1.32) --- updated-dependencies: - dependency-name: org.yaml:snakeyaml dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- test/dubbo-scenario-builder/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/dubbo-scenario-builder/pom.xml b/test/dubbo-scenario-builder/pom.xml index ee8fa8b59..b0f981bcb 100644 --- a/test/dubbo-scenario-builder/pom.xml +++ b/test/dubbo-scenario-builder/pom.xml @@ -27,7 +27,7 @@ dubbo-scenario-builder - 1.32 + 2.0 From 4eb1e05c7ad5ab06dc35544b0a1e7aed68867618 Mon Sep 17 00:00:00 2001 From: wxbty <38374721+wxbty@users.noreply.github.com> Date: Fri, 5 May 2023 20:27:43 +0800 Subject: [PATCH 12/35] revert error description (#209) Co-authored-by: x-shadow-man <1494445739@qq.com> --- dubbo-mock-extensions/README.md | 3 +-- dubbo-mock-extensions/README_ch.md | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/dubbo-mock-extensions/README.md b/dubbo-mock-extensions/README.md index 7db308cca..0cb548772 100644 --- a/dubbo-mock-extensions/README.md +++ b/dubbo-mock-extensions/README.md @@ -9,9 +9,8 @@ - Add the dependency. ```xml - - org.apache.dubbo.gatewayorg.apache.dubbo.gateway + org.apache.dubbo.extensions dubbo-mock-admin 3.0.0 diff --git a/dubbo-mock-extensions/README_ch.md b/dubbo-mock-extensions/README_ch.md index 7aa6f44b5..e1d2af8b0 100644 --- a/dubbo-mock-extensions/README_ch.md +++ b/dubbo-mock-extensions/README_ch.md @@ -9,9 +9,8 @@ - 引入依赖 ```xml - - org.apache.dubbo.gatewayorg.apache.dubbo.gateway + org.apache.dubbo.extensions dubbo-mock-admin 3.0.0 From 69d5a6e5d99683443273e6019b228f193c2018c4 Mon Sep 17 00:00:00 2001 From: wxbty <38374721+wxbty@users.noreply.github.com> Date: Mon, 15 May 2023 13:53:29 +0800 Subject: [PATCH 13/35] commment polaris ci because of address can not visist (#210) Co-authored-by: x-shadow-man <1494445739@qq.com> --- .../registry/polaris/PolarisRegistryTest.java | 266 +++++++++--------- 1 file changed, 133 insertions(+), 133 deletions(-) diff --git a/dubbo-registry-extensions/dubbo-registry-polaris/src/test/java/org/apache/dubbo/registry/polaris/PolarisRegistryTest.java b/dubbo-registry-extensions/dubbo-registry-polaris/src/test/java/org/apache/dubbo/registry/polaris/PolarisRegistryTest.java index 16c492d7e..1a959f276 100644 --- a/dubbo-registry-extensions/dubbo-registry-polaris/src/test/java/org/apache/dubbo/registry/polaris/PolarisRegistryTest.java +++ b/dubbo-registry-extensions/dubbo-registry-polaris/src/test/java/org/apache/dubbo/registry/polaris/PolarisRegistryTest.java @@ -1,133 +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 org.apache.dubbo.registry.polaris; - -import com.tencent.polaris.api.pojo.Instance; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; -import org.apache.dubbo.common.URL; -import org.apache.dubbo.common.utils.NetUtils; -import org.apache.dubbo.common.utils.StringUtils; -import org.apache.dubbo.registry.NotifyListener; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - -public class PolarisRegistryTest { - - private static PolarisRegistry polarisRegistry; - - @BeforeAll - public static void setup() { - Map parameters = new HashMap<>(); - parameters.put("namespace", "dubbo-java-test"); - parameters.put("persist_enable", "false"); - URL url = new URL("polaris", "183.47.111.80", 8091, parameters); - polarisRegistry = new PolarisRegistry(url); - } - - @AfterAll - public static void teardown() { - if (null != polarisRegistry) { - polarisRegistry.destroy(); - } - } - - @Test - public void testSubscribe() { - int count = 10; - AtomicBoolean notified = new AtomicBoolean(false); - String svcName = "polaris-registry-test-service-subscribe"; - URL consumerUrl = URL.valueOf("consumer://0.0.0.0/" + svcName); - NotifyListener listener = new NotifyListener() { - @Override - public void notify(List urls) { - notified.set(true); - } - }; - polarisRegistry.subscribe(consumerUrl, listener); - String host = NetUtils.getLocalHost(); - List serviceUrls = buildInstanceUrls(svcName, host, 11300, count); - try { - for (URL serviceUrl : serviceUrls) { - polarisRegistry.doRegister(serviceUrl); - } - try { - Thread.sleep(5000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - polarisRegistry.unsubscribe(consumerUrl, listener); - Assertions.assertTrue(notified.get()); - } finally { - for (URL serviceUrl : serviceUrls) { - polarisRegistry.doUnregister(serviceUrl); - } - } - } - - @Test - public void testRegister() { - String svcName = "polaris-registry-test-service-register"; - int count = 10; - String host = NetUtils.getLocalHost(); - List serviceUrls = buildInstanceUrls(svcName, host,11300, count); - for (URL serviceUrl : serviceUrls) { - polarisRegistry.doRegister(serviceUrl); - } - try { - Thread.sleep(5000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - try { - Instance[] availableInstances = polarisRegistry.getPolarisOperator().getAvailableInstances(svcName, true); - Assertions.assertEquals(count, countInstanceByHost(host, availableInstances)); - } finally { - for (URL serviceUrl : serviceUrls) { - polarisRegistry.doUnregister(serviceUrl); - } - } - } - - private static List buildInstanceUrls(String service, String host, int startPort, int count) { - List serviceUrls = new ArrayList<>(); - for (int i = 0; i < count; i++) { - URL serviceUrl = URL.valueOf("dubbo://" + host + ":" + - Integer.toString(startPort + i) + "/" + service + "?methods=test1,test2"); - serviceUrls.add(serviceUrl); - } - return serviceUrls; - } - - private static int countInstanceByHost(String host, Instance[] instances) { - int count = 0; - for (Instance instance : instances) { - if (StringUtils.isEquals(host, instance.getHost())) { - count++; - } - } - return count; - } - -} +///* +// * 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 org.apache.dubbo.registry.polaris; +// +//import com.tencent.polaris.api.pojo.Instance; +//import java.util.ArrayList; +//import java.util.HashMap; +//import java.util.List; +//import java.util.Map; +//import java.util.concurrent.atomic.AtomicBoolean; +//import java.util.concurrent.atomic.AtomicInteger; +//import org.apache.dubbo.common.URL; +//import org.apache.dubbo.common.utils.NetUtils; +//import org.apache.dubbo.common.utils.StringUtils; +//import org.apache.dubbo.registry.NotifyListener; +//import org.junit.jupiter.api.AfterAll; +//import org.junit.jupiter.api.Assertions; +//import org.junit.jupiter.api.BeforeAll; +//import org.junit.jupiter.api.Test; +// +//public class PolarisRegistryTest { +// +// private static PolarisRegistry polarisRegistry; +// +// @BeforeAll +// public static void setup() { +// Map parameters = new HashMap<>(); +// parameters.put("namespace", "dubbo-java-test"); +// parameters.put("persist_enable", "false"); +// URL url = new URL("polaris", "183.47.111.80", 8091, parameters); +// polarisRegistry = new PolarisRegistry(url); +// } +// +// @AfterAll +// public static void teardown() { +// if (null != polarisRegistry) { +// polarisRegistry.destroy(); +// } +// } +// +// @Test +// public void testSubscribe() { +// int count = 10; +// AtomicBoolean notified = new AtomicBoolean(false); +// String svcName = "polaris-registry-test-service-subscribe"; +// URL consumerUrl = URL.valueOf("consumer://0.0.0.0/" + svcName); +// NotifyListener listener = new NotifyListener() { +// @Override +// public void notify(List urls) { +// notified.set(true); +// } +// }; +// polarisRegistry.subscribe(consumerUrl, listener); +// String host = NetUtils.getLocalHost(); +// List serviceUrls = buildInstanceUrls(svcName, host, 11300, count); +// try { +// for (URL serviceUrl : serviceUrls) { +// polarisRegistry.doRegister(serviceUrl); +// } +// try { +// Thread.sleep(5000); +// } catch (InterruptedException e) { +// e.printStackTrace(); +// } +// polarisRegistry.unsubscribe(consumerUrl, listener); +// Assertions.assertTrue(notified.get()); +// } finally { +// for (URL serviceUrl : serviceUrls) { +// polarisRegistry.doUnregister(serviceUrl); +// } +// } +// } +// +// @Test +// public void testRegister() { +// String svcName = "polaris-registry-test-service-register"; +// int count = 10; +// String host = NetUtils.getLocalHost(); +// List serviceUrls = buildInstanceUrls(svcName, host,11300, count); +// for (URL serviceUrl : serviceUrls) { +// polarisRegistry.doRegister(serviceUrl); +// } +// try { +// Thread.sleep(5000); +// } catch (InterruptedException e) { +// e.printStackTrace(); +// } +// try { +// Instance[] availableInstances = polarisRegistry.getPolarisOperator().getAvailableInstances(svcName, true); +// Assertions.assertEquals(count, countInstanceByHost(host, availableInstances)); +// } finally { +// for (URL serviceUrl : serviceUrls) { +// polarisRegistry.doUnregister(serviceUrl); +// } +// } +// } +// +// private static List buildInstanceUrls(String service, String host, int startPort, int count) { +// List serviceUrls = new ArrayList<>(); +// for (int i = 0; i < count; i++) { +// URL serviceUrl = URL.valueOf("dubbo://" + host + ":" + +// Integer.toString(startPort + i) + "/" + service + "?methods=test1,test2"); +// serviceUrls.add(serviceUrl); +// } +// return serviceUrls; +// } +// +// private static int countInstanceByHost(String host, Instance[] instances) { +// int count = 0; +// for (Instance instance : instances) { +// if (StringUtils.isEquals(host, instance.getHost())) { +// count++; +// } +// } +// return count; +// } +// +//} From 3c49199c484ca1762f04e83a5b78395103a9fd4b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 13 Jul 2023 20:38:11 +0800 Subject: [PATCH 14/35] Bump grpc-protobuf in /dubbo-extensions-dependencies-bom (#214) Bumps [grpc-protobuf](https://github.com/grpc/grpc-java) from 1.31.1 to 1.53.0. - [Release notes](https://github.com/grpc/grpc-java/releases) - [Commits](https://github.com/grpc/grpc-java/compare/v1.31.1...v1.53.0) --- updated-dependencies: - dependency-name: io.grpc:grpc-protobuf dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- dubbo-extensions-dependencies-bom/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dubbo-extensions-dependencies-bom/pom.xml b/dubbo-extensions-dependencies-bom/pom.xml index ad325aa15..9f00167b4 100644 --- a/dubbo-extensions-dependencies-bom/pom.xml +++ b/dubbo-extensions-dependencies-bom/pom.xml @@ -120,7 +120,7 @@ 1.7.25 2.4.4 0.5.7 - 1.31.1 + 1.53.0 0.5.7 4.1.66.Final 2.2.1 From 644960b4c0ff8a4f27555b8ce2b0788120dbd240 Mon Sep 17 00:00:00 2001 From: liaochuntao Date: Thu, 13 Jul 2023 20:38:25 +0800 Subject: [PATCH 15/35] feat:support polaris circuitbreaker ability (#212) * feat:support polaris circuitbreaker ability * feat:support polaris circuitbreaker ability * feat:support polaris circuitbreaker ability * feat:support polaris circuitbreaker ability * feat:support polaris circuitbreaker ability * feat:support polaris circuitbreaker ability --- .../rpc/cluster/router/InstanceInvoker.java | 32 ++-- .../rpc/cluster/router/PolarisRouter.java | 75 ++++----- .../cluster/router/PolarisRouterFactory.java | 4 + dubbo-cluster-extensions/pom.xml | 1 - dubbo-extensions-dependencies-bom/pom.xml | 3 +- .../filter/dubbo2/CallAbortCallback.java | 29 ++++ .../filter/dubbo2/CircuitBreakerFilter.java | 148 +++++++++++++++++- .../filter/dubbo2/RateLimitCallback.java | 29 ++++ .../dubbo/filter/dubbo2/RateLimitFilter.java | 61 +++++--- .../dubbo-registry-dns/pom.xml | 3 - .../registry/polaris/PolarisRegistry.java | 33 ++-- .../polaris/PolarisRegistryUtils.java | 3 +- .../registry/polaris/filter/ReportFilter.java | 92 +++++++---- .../registry/polaris/PolarisRegistryTest.java | 133 ---------------- 14 files changed, 375 insertions(+), 271 deletions(-) create mode 100644 dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-circuitbreaker-dubbo2/src/main/java/org/apache/dubbo/filter/dubbo2/CallAbortCallback.java create mode 100644 dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-ratelimit-dubbo2/src/main/java/org/apache/dubbo/filter/dubbo2/RateLimitCallback.java delete mode 100644 dubbo-registry-extensions/dubbo-registry-polaris/src/test/java/org/apache/dubbo/registry/polaris/PolarisRegistryTest.java diff --git a/dubbo-cluster-extensions/dubbo-cluster-polaris-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/router/InstanceInvoker.java b/dubbo-cluster-extensions/dubbo-cluster-polaris-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/router/InstanceInvoker.java index 90062d157..37b489300 100644 --- a/dubbo-cluster-extensions/dubbo-cluster-polaris-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/router/InstanceInvoker.java +++ b/dubbo-cluster-extensions/dubbo-cluster-polaris-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/router/InstanceInvoker.java @@ -22,20 +22,22 @@ import com.tencent.polaris.api.pojo.Instance; import com.tencent.polaris.api.pojo.StatusDimension; import com.tencent.polaris.common.registry.Consts; -import com.tencent.polaris.common.registry.ConvertUtils; -import java.util.Collection; -import java.util.Map; -import java.util.Objects; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.Result; import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.cluster.Constants; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + public class InstanceInvoker implements Instance, Invoker { private static final Logger LOGGER = LoggerFactory.getLogger(InstanceInvoker.class); @@ -57,14 +59,22 @@ public InstanceInvoker(Invoker invoker, String namespace) { defaultInstance.setIsolated(Boolean.parseBoolean(url.getParameter(Consts.INSTANCE_KEY_ISOLATED))); defaultInstance.setVersion(url.getParameter(CommonConstants.VERSION_KEY)); defaultInstance.setWeight(url.getParameter(Constants.WEIGHT_KEY, 100)); - String circuitBreakerStr = url.getParameter(Consts.INSTANCE_KEY_CIRCUIT_BREAKER); - Map statusDimensionCircuitBreakerStatusMap = ConvertUtils - .stringToCircuitBreakers(circuitBreakerStr); - defaultInstance.getCircuitBreakerStatuses().putAll(statusDimensionCircuitBreakerStatusMap); - defaultInstance.setMetadata(url.getParameters()); + defaultInstance.setMetadata(convertMetadata(url.getParameters())); LOGGER.info(String.format("[POLARIS] construct instance from invoker, url %s, instance %s", url, defaultInstance)); } + private Map convertMetadata(Map parameters) { + Map ret = new HashMap<>(); + parameters.forEach((key, value) -> { + ret.put(key, value); + if (StringUtils.isEquals(key, CommonConstants.REMOTE_APPLICATION_KEY)) { + key = "application"; + ret.put(key, value); + } + }); + return ret; + } + @Override public Class getInterface() { return invoker.getInterface(); @@ -200,10 +210,6 @@ public int compareTo(Instance o) { return defaultInstance.compareTo(o); } - private static final String SEP_CIRCUIT_BREAKER = ","; - - private static final String SEP_CIRCUIT_BREAKER_VALUE = ":"; - @Override public boolean equals(Object o) { if (this == o) { diff --git a/dubbo-cluster-extensions/dubbo-cluster-polaris-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/router/PolarisRouter.java b/dubbo-cluster-extensions/dubbo-cluster-polaris-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/router/PolarisRouter.java index 88024b914..3642c37f0 100644 --- a/dubbo-cluster-extensions/dubbo-cluster-polaris-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/router/PolarisRouter.java +++ b/dubbo-cluster-extensions/dubbo-cluster-polaris-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/router/PolarisRouter.java @@ -22,19 +22,11 @@ import com.tencent.polaris.api.pojo.ServiceEventKey.EventType; import com.tencent.polaris.api.pojo.ServiceRule; import com.tencent.polaris.api.utils.StringUtils; -import com.tencent.polaris.client.pb.RoutingProto.Routing; +import com.tencent.polaris.common.parser.QueryParser; import com.tencent.polaris.common.registry.PolarisOperator; import com.tencent.polaris.common.registry.PolarisOperators; -import com.tencent.polaris.common.router.ObjectParser; import com.tencent.polaris.common.router.RuleHandler; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.atomic.AtomicReference; +import com.tencent.polaris.specification.api.v1.traffic.manage.RoutingProto; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; @@ -44,6 +36,12 @@ import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.cluster.Constants; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Optional; +import java.util.Set; + public class PolarisRouter extends AbstractRouter { private static final Logger LOGGER = LoggerFactory.getLogger(PolarisRouter.class); @@ -52,15 +50,17 @@ public class PolarisRouter extends AbstractRouter { private final PolarisOperator polarisOperator; - private final AtomicReference>> invokersCache = new AtomicReference<>(); + private final QueryParser parser; public PolarisRouter(URL url) { super(url); LOGGER.info(String.format("[POLARIS] init service router, url is %s, parameters are %s", url, - url.getParameters())); + url.getParameters())); + System.setProperty("dubbo.polaris.query_parser", System.getProperty("dubbo.polaris.query_parser", "JsonPath")); this.priority = url.getParameter(Constants.PRIORITY_KEY, 0); - routeRuleHandler = new RuleHandler(); - polarisOperator = PolarisOperators.INSTANCE.getPolarisOperator(url.getHost(), url.getPort()); + this.routeRuleHandler = new RuleHandler(); + this.polarisOperator = PolarisOperators.INSTANCE.getPolarisOperator(url.getHost(), url.getPort()); + this.parser = QueryParser.load(); } @Override @@ -71,25 +71,22 @@ public List> route(List> invokers, URL url, Invocation if (null == polarisOperator) { return invokers; } - List instances = new ArrayList<>(invokers.size()); - Map> instanceInvokerMap = invokersCache.get(); - if (null == instanceInvokerMap) { - instanceInvokerMap = Collections.emptyMap(); - } - for (Invoker invoker : invokers) { - InstanceInvoker instanceInvoker = instanceInvokerMap.get(invoker.getUrl()); - if (null != instanceInvoker) { - instances.add(instanceInvoker); - } else { - instances.add(new InstanceInvoker<>(invoker, polarisOperator.getPolarisConfig().getNamespace())); - } + List instances; + if (invokers.get(0) instanceof Instance) { + instances = (List) ((List) invokers); + } else { + instances = new ArrayList<>(); + for (Invoker invoker : invokers) { + instances.add(new InstanceInvoker<>(invoker, polarisOperator.getPolarisConfig().getNamespace())); + } } + String service = url.getServiceInterface(); ServiceRule serviceRule = polarisOperator.getServiceRule(service, EventType.ROUTING); Object ruleObject = serviceRule.getRule(); Set arguments = new HashSet<>(); if (null != ruleObject) { - Routing routing = (Routing) ruleObject; + RoutingProto.Routing routing = (RoutingProto.Routing) ruleObject; Set routeLabels = routeRuleHandler.getRouteLabels(routing); for (String routeLabel : routeLabels) { if (StringUtils.equals(RouteArgument.LABEL_KEY_PATH, routeLabel)) { @@ -103,29 +100,17 @@ public List> route(List> invokers, URL url, Invocation } else if (routeLabel.startsWith(RouteArgument.LABEL_KEY_QUERY)) { String queryName = routeLabel.substring(RouteArgument.LABEL_KEY_QUERY.length()); if (!StringUtils.isBlank(queryName)) { - Object value = ObjectParser.parseArgumentsByExpression(queryName, invocation.getArguments()); - if (null != value) { - arguments.add(RouteArgument.buildQuery(queryName, String.valueOf(value))); - } + Optional queryValue = parser.parse(queryName, invocation.getArguments()); + queryValue.ifPresent(value -> arguments.add(RouteArgument.buildQuery(queryName, value))); } } } } - LOGGER.debug(String.format("[POLARIS] list service %s, method %s, labels %s, url %s", service, + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(String.format("[POLARIS] list service %s, method %s, labels %s, url %s", service, invocation.getMethodName(), arguments, url)); - List resultInstances = polarisOperator - .route(service, invocation.getMethodName(), arguments, instances); - return (List>) ((List) resultInstances); - } - - public void notify(List> invokers) { - if (null == polarisOperator) { - return; } - Map> instanceInvokers = new HashMap<>(invokers.size()); - for (Invoker invoker : invokers) { - instanceInvokers.put(invoker.getUrl(), new InstanceInvoker<>(invoker, polarisOperator.getPolarisConfig().getNamespace())); - } - invokersCache.set(instanceInvokers); + List resultInstances = polarisOperator.route(service, invocation.getMethodName(), arguments, instances); + return (List>) ((List) resultInstances); } } diff --git a/dubbo-cluster-extensions/dubbo-cluster-polaris-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/router/PolarisRouterFactory.java b/dubbo-cluster-extensions/dubbo-cluster-polaris-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/router/PolarisRouterFactory.java index 33b56a26d..88870ec7f 100644 --- a/dubbo-cluster-extensions/dubbo-cluster-polaris-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/router/PolarisRouterFactory.java +++ b/dubbo-cluster-extensions/dubbo-cluster-polaris-dubbo2/src/main/java/org/apache/dubbo/rpc/cluster/router/PolarisRouterFactory.java @@ -18,9 +18,12 @@ package org.apache.dubbo.rpc.cluster.router; import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.constants.CommonConstants; +import org.apache.dubbo.common.extension.Activate; import org.apache.dubbo.rpc.cluster.Router; import org.apache.dubbo.rpc.cluster.RouterFactory; +@Activate(group = CommonConstants.CONSUMER) public class PolarisRouterFactory implements RouterFactory { @Override @@ -28,3 +31,4 @@ public Router getRouter(URL url) { return new PolarisRouter(url); } } + diff --git a/dubbo-cluster-extensions/pom.xml b/dubbo-cluster-extensions/pom.xml index 994628208..fff3b5fa4 100644 --- a/dubbo-cluster-extensions/pom.xml +++ b/dubbo-cluster-extensions/pom.xml @@ -39,5 +39,4 @@ dubbo-cluster-polaris-dubbo2 - diff --git a/dubbo-extensions-dependencies-bom/pom.xml b/dubbo-extensions-dependencies-bom/pom.xml index 9f00167b4..2e998be0c 100644 --- a/dubbo-extensions-dependencies-bom/pom.xml +++ b/dubbo-extensions-dependencies-bom/pom.xml @@ -133,8 +133,7 @@ 1.2.11 2.0 3.0.20.Final - 0.1.3 - + 0.2.1 1.2.5 diff --git a/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-circuitbreaker-dubbo2/src/main/java/org/apache/dubbo/filter/dubbo2/CallAbortCallback.java b/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-circuitbreaker-dubbo2/src/main/java/org/apache/dubbo/filter/dubbo2/CallAbortCallback.java new file mode 100644 index 000000000..9d3243e4e --- /dev/null +++ b/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-circuitbreaker-dubbo2/src/main/java/org/apache/dubbo/filter/dubbo2/CallAbortCallback.java @@ -0,0 +1,29 @@ +/* + * 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 org.apache.dubbo.filter.dubbo2; + +import com.tencent.polaris.circuitbreak.client.exception.CallAbortedException; +import org.apache.dubbo.rpc.Invocation; +import org.apache.dubbo.rpc.Invoker; +import org.apache.dubbo.rpc.Result; + +public interface CallAbortCallback { + + Result handle(Invoker invoker, Invocation invocation, CallAbortedException ex); + +} diff --git a/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-circuitbreaker-dubbo2/src/main/java/org/apache/dubbo/filter/dubbo2/CircuitBreakerFilter.java b/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-circuitbreaker-dubbo2/src/main/java/org/apache/dubbo/filter/dubbo2/CircuitBreakerFilter.java index 80e6188f0..57a60c019 100644 --- a/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-circuitbreaker-dubbo2/src/main/java/org/apache/dubbo/filter/dubbo2/CircuitBreakerFilter.java +++ b/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-circuitbreaker-dubbo2/src/main/java/org/apache/dubbo/filter/dubbo2/CircuitBreakerFilter.java @@ -17,19 +17,163 @@ package org.apache.dubbo.filter.dubbo2; +import com.tencent.polaris.api.plugin.circuitbreaker.ResourceStat; +import com.tencent.polaris.api.plugin.circuitbreaker.entity.InstanceResource; +import com.tencent.polaris.api.plugin.circuitbreaker.entity.Resource; +import com.tencent.polaris.api.pojo.RetStatus; +import com.tencent.polaris.api.pojo.ServiceKey; +import com.tencent.polaris.api.utils.StringUtils; +import com.tencent.polaris.circuitbreak.api.CircuitBreakAPI; +import com.tencent.polaris.circuitbreak.api.InvokeHandler; +import com.tencent.polaris.circuitbreak.api.pojo.InvokeContext; +import com.tencent.polaris.circuitbreak.api.pojo.ResultToErrorCode; +import com.tencent.polaris.circuitbreak.client.exception.CallAbortedException; +import com.tencent.polaris.common.exception.PolarisBlockException; +import com.tencent.polaris.common.registry.PolarisOperator; +import com.tencent.polaris.common.registry.PolarisOperatorDelegate; +import org.apache.dubbo.common.URL; import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.extension.Activate; +import org.apache.dubbo.common.logger.Logger; +import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.rpc.AsyncRpcResult; import org.apache.dubbo.rpc.Filter; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.Result; import org.apache.dubbo.rpc.RpcException; +import java.util.Objects; +import java.util.ServiceLoader; +import java.util.concurrent.TimeUnit; + @Activate(group = CommonConstants.CONSUMER) -public class CircuitBreakerFilter implements Filter { +public class CircuitBreakerFilter extends PolarisOperatorDelegate implements Filter, ResultToErrorCode { + + private static final Logger LOGGER = LoggerFactory.getLogger(CircuitBreakerFilter.class); + + private final CallAbortCallback callback; + + public CircuitBreakerFilter() { + ServiceLoader loader = ServiceLoader.load(CallAbortCallback.class); + CallAbortCallback instance = loader.iterator().next(); + if (Objects.nonNull(instance)) { + this.callback = instance; + } else { + this.callback = new DefaultCallAbortCallback(); + } + + LOGGER.info("[POLARIS] init polaris circuitbreaker"); + } @Override public Result invoke(Invoker invoker, Invocation invocation) throws RpcException { - return invoker.invoke(invocation); + PolarisOperator polarisOperator = getPolarisOperator(); + if (null == polarisOperator) { + return invoker.invoke(invocation); + } + + CircuitBreakAPI circuitBreakAPI = getPolarisOperator().getCircuitBreakAPI(); + InvokeContext.RequestContext context = new InvokeContext.RequestContext(createCalleeService(invoker), + invocation.getMethodName()); + context.setResultToErrorCode(this); + InvokeHandler handler = circuitBreakAPI.makeInvokeHandler(context); + try { + long startTimeMilli = System.currentTimeMillis(); + InvokeContext.ResponseContext responseContext = new InvokeContext.ResponseContext(); + responseContext.setDurationUnit(TimeUnit.MILLISECONDS); + Result result = null; + RpcException exception = null; + handler.acquirePermission(); + try { + result = invoker.invoke(invocation); + responseContext.setDuration(System.currentTimeMillis() - startTimeMilli); + if (result.hasException()) { + responseContext.setError(result.getException()); + handler.onError(responseContext); + } else { + responseContext.setResult(result); + handler.onSuccess(responseContext); + } + } catch (RpcException e) { + exception = e; + responseContext.setError(e); + responseContext.setDuration(System.currentTimeMillis() - startTimeMilli); + handler.onError(responseContext); + } + ResourceStat resourceStat = createInstanceResourceStat(invoker, invocation, responseContext, + responseContext.getDuration()); + circuitBreakAPI.report(resourceStat); + if (result != null) { + return result; + } + throw exception; + } catch (CallAbortedException abortedException) { + return callback.handle(invoker, invocation, abortedException); + } + } + + private ResourceStat createInstanceResourceStat(Invoker invoker, Invocation invocation, + InvokeContext.ResponseContext context, long delay) { + URL url = invoker.getUrl(); + Throwable exception = context.getError(); + RetStatus retStatus = RetStatus.RetSuccess; + int code = 0; + if (null != exception) { + retStatus = RetStatus.RetFail; + if (exception instanceof RpcException) { + RpcException rpcException = (RpcException) exception; + code = rpcException.getCode(); + if (StringUtils.isNotBlank(rpcException.getMessage()) && rpcException.getMessage() + .contains(PolarisBlockException.PREFIX)) { + // 限流异常不进行熔断 + retStatus = RetStatus.RetFlowControl; + } + if (rpcException.isTimeout()) { + retStatus = RetStatus.RetTimeout; + } + } else { + code = -1; + } + } + + ServiceKey calleeServiceKey = createCalleeService(invoker); + Resource resource = new InstanceResource( + calleeServiceKey, + url.getHost(), + url.getPort(), + new ServiceKey() + ); + return new ResourceStat(resource, code, delay, retStatus); + } + + private ServiceKey createCalleeService(Invoker invoker) { + URL url = invoker.getUrl(); + return new ServiceKey(getPolarisOperator().getPolarisConfig().getNamespace(), url.getServiceInterface()); + } + + @Override + public int onSuccess(Object value) { + return 0; + } + + @Override + public int onError(Throwable throwable) { + int code = 0; + if (throwable instanceof RpcException) { + RpcException rpcException = (RpcException) throwable; + code = rpcException.getCode(); + } else { + code = -1; + } + return code; + } + + private static final class DefaultCallAbortCallback implements CallAbortCallback { + + @Override + public Result handle(Invoker invoker, Invocation invocation, CallAbortedException ex) { + return AsyncRpcResult.newDefaultAsyncResult(ex, invocation); + } } } diff --git a/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-ratelimit-dubbo2/src/main/java/org/apache/dubbo/filter/dubbo2/RateLimitCallback.java b/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-ratelimit-dubbo2/src/main/java/org/apache/dubbo/filter/dubbo2/RateLimitCallback.java new file mode 100644 index 000000000..b8a95261a --- /dev/null +++ b/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-ratelimit-dubbo2/src/main/java/org/apache/dubbo/filter/dubbo2/RateLimitCallback.java @@ -0,0 +1,29 @@ +/* + * 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 org.apache.dubbo.filter.dubbo2; + +import com.tencent.polaris.common.exception.PolarisBlockException; +import org.apache.dubbo.rpc.Invocation; +import org.apache.dubbo.rpc.Invoker; +import org.apache.dubbo.rpc.Result; + +public interface RateLimitCallback { + + Result handle(Invoker invoker, Invocation invocation, PolarisBlockException ex); + +} diff --git a/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-ratelimit-dubbo2/src/main/java/org/apache/dubbo/filter/dubbo2/RateLimitFilter.java b/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-ratelimit-dubbo2/src/main/java/org/apache/dubbo/filter/dubbo2/RateLimitFilter.java index 68411b45c..00af325ba 100644 --- a/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-ratelimit-dubbo2/src/main/java/org/apache/dubbo/filter/dubbo2/RateLimitFilter.java +++ b/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-ratelimit-dubbo2/src/main/java/org/apache/dubbo/filter/dubbo2/RateLimitFilter.java @@ -17,21 +17,19 @@ package org.apache.dubbo.filter.dubbo2; +import com.tencent.polaris.api.exception.PolarisException; import com.tencent.polaris.api.pojo.ServiceEventKey.EventType; import com.tencent.polaris.api.pojo.ServiceRule; import com.tencent.polaris.api.utils.StringUtils; -import com.tencent.polaris.client.pb.ModelProto.MatchArgument; -import com.tencent.polaris.client.pb.RateLimitProto.RateLimit; import com.tencent.polaris.common.exception.PolarisBlockException; +import com.tencent.polaris.common.parser.QueryParser; import com.tencent.polaris.common.registry.PolarisOperator; import com.tencent.polaris.common.registry.PolarisOperatorDelegate; -import com.tencent.polaris.common.router.ObjectParser; import com.tencent.polaris.common.router.RuleHandler; import com.tencent.polaris.ratelimit.api.rpc.Argument; import com.tencent.polaris.ratelimit.api.rpc.QuotaResponse; import com.tencent.polaris.ratelimit.api.rpc.QuotaResultCode; -import java.util.HashSet; -import java.util.Set; +import com.tencent.polaris.specification.api.v1.traffic.manage.RateLimitProto; import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.extension.Activate; import org.apache.dubbo.common.logger.Logger; @@ -43,6 +41,12 @@ import org.apache.dubbo.rpc.RpcContext; import org.apache.dubbo.rpc.RpcException; +import java.util.HashSet; +import java.util.Objects; +import java.util.Optional; +import java.util.ServiceLoader; +import java.util.Set; + @Activate(group = CommonConstants.PROVIDER) public class RateLimitFilter extends PolarisOperatorDelegate implements Filter { @@ -50,9 +54,23 @@ public class RateLimitFilter extends PolarisOperatorDelegate implements Filter { private final RuleHandler ruleHandler; + private final QueryParser parser; + + private final RateLimitCallback callback; + public RateLimitFilter() { LOGGER.info("[POLARIS] init polaris ratelimit"); - ruleHandler = new RuleHandler(); + System.setProperty("dubbo.polaris.query_parser", System.getProperty("dubbo.polaris.query_parser", "JsonPath")); + this.ruleHandler = new RuleHandler(); + this.parser = QueryParser.load(); + + ServiceLoader loader = ServiceLoader.load(RateLimitCallback.class); + RateLimitCallback instance = loader.iterator().next(); + if (Objects.nonNull(instance)) { + this.callback = instance; + } else { + this.callback = new DefaultRateLimitCallback(); + } } @Override @@ -67,11 +85,11 @@ public Result invoke(Invoker invoker, Invocation invocation) throws RpcExcept if (null == ruleObject) { return invoker.invoke(invocation); } - RateLimit rateLimit = (RateLimit) ruleObject; - Set ratelimitLabels = ruleHandler.getRatelimitLabels(rateLimit); + RateLimitProto.RateLimit rateLimit = (RateLimitProto.RateLimit) ruleObject; + Set ratelimitLabels = ruleHandler.getRatelimitLabels(rateLimit); String method = invocation.getMethodName(); Set arguments = new HashSet<>(); - for (MatchArgument matchArgument : ratelimitLabels) { + for (RateLimitProto.MatchArgument matchArgument : ratelimitLabels) { switch (matchArgument.getType()) { case HEADER: String attachmentValue = RpcContext.getContext().getAttachment(matchArgument.getKey()); @@ -80,12 +98,8 @@ public Result invoke(Invoker invoker, Invocation invocation) throws RpcExcept } break; case QUERY: - Object queryValue = ObjectParser - .parseArgumentsByExpression(matchArgument.getKey(), invocation.getArguments()); - if (null != queryValue) { - arguments.add(Argument - .buildQuery(matchArgument.getKey(), String.valueOf(queryValue))); - } + Optional queryValue = parser.parse(matchArgument.getKey(), invocation.getArguments()); + queryValue.ifPresent(value -> arguments.add(Argument.buildQuery(matchArgument.getKey(), value))); break; default: break; @@ -94,14 +108,23 @@ public Result invoke(Invoker invoker, Invocation invocation) throws RpcExcept QuotaResponse quotaResponse = null; try { quotaResponse = polarisOperator.getQuota(service, method, arguments); - } catch (RuntimeException e) { - LOGGER.error("[POLARIS] get quota fail", e); + } catch (PolarisException e) { + LOGGER.error("[POLARIS] get quota fail, {}", e); } if (null != quotaResponse && quotaResponse.getCode() == QuotaResultCode.QuotaResultLimited) { // throw block exception when ratelimit occurs - throw new RpcException(RpcException.LIMIT_EXCEEDED_EXCEPTION, new PolarisBlockException( - String.format("url=%s, info=%s", invoker.getUrl(), quotaResponse.getInfo()))); + return callback.handle(invoker, invocation, new PolarisBlockException( + String.format("url=%s, info=%s", invoker.getUrl(), quotaResponse.getInfo()))); } return invoker.invoke(invocation); } + + private static final class DefaultRateLimitCallback implements RateLimitCallback { + + @Override + public Result handle(Invoker invoker, Invocation invocation, PolarisBlockException ex) { + // throw block exception when ratelimit occurs + throw new RpcException(RpcException.LIMIT_EXCEEDED_EXCEPTION, ex); + } + } } diff --git a/dubbo-registry-extensions/dubbo-registry-dns/pom.xml b/dubbo-registry-extensions/dubbo-registry-dns/pom.xml index dbe3942f8..afa6592eb 100644 --- a/dubbo-registry-extensions/dubbo-registry-dns/pom.xml +++ b/dubbo-registry-extensions/dubbo-registry-dns/pom.xml @@ -38,7 +38,6 @@ dubbo true - io.netty netty-all @@ -47,7 +46,5 @@ com.alibaba fastjson - - diff --git a/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/PolarisRegistry.java b/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/PolarisRegistry.java index 31acca2f0..8b021e9ce 100644 --- a/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/PolarisRegistry.java +++ b/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/PolarisRegistry.java @@ -21,18 +21,8 @@ import com.tencent.polaris.api.pojo.Instance; import com.tencent.polaris.api.utils.StringUtils; import com.tencent.polaris.common.registry.Consts; -import com.tencent.polaris.common.registry.ConvertUtils; import com.tencent.polaris.common.registry.PolarisOperator; import com.tencent.polaris.common.utils.ExtensionConsts; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.atomic.AtomicBoolean; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.constants.RegistryConstants; @@ -50,6 +40,16 @@ import org.apache.dubbo.rpc.cluster.Constants; import org.apache.dubbo.rpc.cluster.RouterFactory; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicBoolean; + public class PolarisRegistry extends FailbackRegistry { private static final Logger LOGGER = LoggerFactory.getLogger(PolarisRegistry.class); @@ -113,7 +113,7 @@ public void doRegister(URL url) { int weight = url.getParameter(Constants.WEIGHT_KEY, Constants.DEFAULT_WEIGHT); String version = url.getParameter(CommonConstants.VERSION_KEY, ""); polarisOperator.register(url.getServiceInterface(), url.getHost(), port, url.getProtocol(), version, weight, - metadata); + metadata); registeredInstances.add(url); } else { LOGGER.warn(String.format("[POLARIS] skip register url %s for zero port value", url)); @@ -166,7 +166,7 @@ public void doSubscribe(URL url, NotifyListener listener) { private void onInstances(URL url, NotifyListener listener, Instance[] instances) { LOGGER.info(String.format("[POLARIS] update instances count: %d, service: %s", null == instances ? 0 : instances.length, - url.getServiceInterface())); + url.getServiceInterface())); List urls = new ArrayList<>(); if (null != instances) { for (Instance instance : instances) { @@ -199,13 +199,12 @@ private static URL instanceToURL(Instance instance) { newMetadata.put(Consts.INSTANCE_KEY_ID, instance.getId()); newMetadata.put(Consts.INSTANCE_KEY_HEALTHY, Boolean.toString(instance.isHealthy())); newMetadata.put(Consts.INSTANCE_KEY_ISOLATED, Boolean.toString(instance.isIsolated())); - newMetadata.put(Consts.INSTANCE_KEY_CIRCUIT_BREAKER, ConvertUtils.circuitBreakersToString(instance)); clearEmptyKeys(newMetadata, new String[]{CommonConstants.VERSION_KEY, CommonConstants.GROUP_KEY}); return new URL(instance.getProtocol(), - instance.getHost(), - instance.getPort(), - newMetadata.get(CommonConstants.PATH_KEY), - newMetadata); + instance.getHost(), + instance.getPort(), + newMetadata.get(CommonConstants.PATH_KEY), + newMetadata); } private static void clearEmptyKeys(Map parameters, String[] keys) { diff --git a/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/PolarisRegistryUtils.java b/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/PolarisRegistryUtils.java index 9477e9e63..3c6198271 100644 --- a/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/PolarisRegistryUtils.java +++ b/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/PolarisRegistryUtils.java @@ -32,8 +32,7 @@ public static PolarisOperator getOrCreatePolarisOperator(URL registryURL) { if (null != existsOperator) { return existsOperator; } else { - PolarisOperator polarisOperator = new PolarisOperator( - host, port, registryURL.getParameters(), new BaseBootConfigHandler()); + PolarisOperator polarisOperator = new PolarisOperator(host, port, registryURL.getParameters(), new BaseBootConfigHandler()); PolarisOperators.INSTANCE.addPolarisOperator(polarisOperator); return polarisOperator; } diff --git a/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/filter/ReportFilter.java b/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/filter/ReportFilter.java index 8449db66c..9e0cb102a 100644 --- a/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/filter/ReportFilter.java +++ b/dubbo-registry-extensions/dubbo-registry-polaris/src/main/java/org/apache/dubbo/registry/polaris/filter/ReportFilter.java @@ -19,6 +19,9 @@ import com.tencent.polaris.api.pojo.RetStatus; +import com.tencent.polaris.api.utils.StringUtils; +import com.tencent.polaris.circuitbreak.client.exception.CallAbortedException; +import com.tencent.polaris.common.exception.PolarisBlockException; import com.tencent.polaris.common.registry.PolarisOperator; import com.tencent.polaris.common.registry.PolarisOperatorDelegate; import org.apache.dubbo.common.URL; @@ -30,10 +33,15 @@ import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.Result; +import org.apache.dubbo.rpc.RpcContext; import org.apache.dubbo.rpc.RpcException; -@Activate(group = CommonConstants.CONSUMER) -public class ReportFilter extends PolarisOperatorDelegate implements Filter { +@Activate(group = CommonConstants.CONSUMER, order = Integer.MIN_VALUE) +public class ReportFilter extends PolarisOperatorDelegate implements Filter, Filter.Listener { + + private static final String LABEL_START_TIME = "reporter_filter_start_time"; + + private static final String LABEL_REMOTE_HOST = "reporter_remote_host_store"; private static final Logger LOGGER = LoggerFactory.getLogger(ReportFilter.class); @@ -43,48 +51,64 @@ public ReportFilter() { @Override public Result invoke(Invoker invoker, Invocation invocation) throws RpcException { - long startTimeMilli = System.currentTimeMillis(); - Result result = null; - Throwable exception = null; - RpcException rpcException = null; - try { - result = invoker.invoke(invocation); - } catch (Throwable e) { - exception = e; - } - if (null != result && result.hasException()) { - exception = result.getException(); - } - if (exception instanceof RpcException) { - rpcException = (RpcException) exception; - } + invocation.put(LABEL_START_TIME, System.currentTimeMillis()); + invocation.put(LABEL_REMOTE_HOST, RpcContext.getContext().getRemoteHost()); + return invoker.invoke(invocation); + } + + @Override + public void onResponse(Result appResponse, Invoker invoker, Invocation invocation) { PolarisOperator polarisOperator = getPolarisOperator(); if (null == polarisOperator) { - return result; + return; } + String callerIp = (String) invocation.get(LABEL_REMOTE_HOST); + Long startTimeMilli = (Long) invocation.get(LABEL_START_TIME); RetStatus retStatus = RetStatus.RetSuccess; int code = 0; - if (null != exception) { + if (appResponse.hasException()) { retStatus = RetStatus.RetFail; - if (null != rpcException) { - code = rpcException.getCode(); - if (code == RpcException.LIMIT_EXCEEDED_EXCEPTION) { - // we won't consider limit exception as error - retStatus = RetStatus.RetSuccess; - } - } else { - code = -1; - } + code = -1; } URL url = invoker.getUrl(); long delay = System.currentTimeMillis() - startTimeMilli; polarisOperator.reportInvokeResult(url.getServiceInterface(), invocation.getMethodName(), url.getHost(), - url.getPort(), delay, retStatus, code); - if (null != rpcException) { - throw rpcException; - } else if (null != exception) { - throw new RpcException(exception); + url.getPort(), callerIp, delay, retStatus, code); + } + + @Override + public void onError(Throwable t, Invoker invoker, Invocation invocation) { + PolarisOperator polarisOperator = getPolarisOperator(); + if (null == polarisOperator) { + return; + } + String callerIp = (String) invocation.get(LABEL_REMOTE_HOST); + Long startTimeMilli = (Long) invocation.get(LABEL_START_TIME); + RetStatus retStatus = RetStatus.RetFail; + int code = -1; + if (t instanceof RpcException) { + RpcException rpcException = (RpcException) t; + code = rpcException.getCode(); + if (isFlowControl(rpcException)) { + retStatus = RetStatus.RetFlowControl; + } + if (rpcException.isTimeout()) { + retStatus = RetStatus.RetTimeout; + } + if (rpcException.getCause() instanceof CallAbortedException) { + retStatus = RetStatus.RetReject; + } } - return result; + URL url = invoker.getUrl(); + long delay = System.currentTimeMillis() - startTimeMilli; + polarisOperator.reportInvokeResult(url.getServiceInterface(), invocation.getMethodName(), url.getHost(), + url.getPort(), callerIp, delay, retStatus, code); + } + + private boolean isFlowControl(RpcException rpcException) { + boolean a = StringUtils.isNotBlank(rpcException.getMessage()) && rpcException.getMessage() + .contains(PolarisBlockException.PREFIX); + boolean b = rpcException.isLimitExceed(); + return a || b; } } diff --git a/dubbo-registry-extensions/dubbo-registry-polaris/src/test/java/org/apache/dubbo/registry/polaris/PolarisRegistryTest.java b/dubbo-registry-extensions/dubbo-registry-polaris/src/test/java/org/apache/dubbo/registry/polaris/PolarisRegistryTest.java deleted file mode 100644 index 1a959f276..000000000 --- a/dubbo-registry-extensions/dubbo-registry-polaris/src/test/java/org/apache/dubbo/registry/polaris/PolarisRegistryTest.java +++ /dev/null @@ -1,133 +0,0 @@ -///* -// * 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 org.apache.dubbo.registry.polaris; -// -//import com.tencent.polaris.api.pojo.Instance; -//import java.util.ArrayList; -//import java.util.HashMap; -//import java.util.List; -//import java.util.Map; -//import java.util.concurrent.atomic.AtomicBoolean; -//import java.util.concurrent.atomic.AtomicInteger; -//import org.apache.dubbo.common.URL; -//import org.apache.dubbo.common.utils.NetUtils; -//import org.apache.dubbo.common.utils.StringUtils; -//import org.apache.dubbo.registry.NotifyListener; -//import org.junit.jupiter.api.AfterAll; -//import org.junit.jupiter.api.Assertions; -//import org.junit.jupiter.api.BeforeAll; -//import org.junit.jupiter.api.Test; -// -//public class PolarisRegistryTest { -// -// private static PolarisRegistry polarisRegistry; -// -// @BeforeAll -// public static void setup() { -// Map parameters = new HashMap<>(); -// parameters.put("namespace", "dubbo-java-test"); -// parameters.put("persist_enable", "false"); -// URL url = new URL("polaris", "183.47.111.80", 8091, parameters); -// polarisRegistry = new PolarisRegistry(url); -// } -// -// @AfterAll -// public static void teardown() { -// if (null != polarisRegistry) { -// polarisRegistry.destroy(); -// } -// } -// -// @Test -// public void testSubscribe() { -// int count = 10; -// AtomicBoolean notified = new AtomicBoolean(false); -// String svcName = "polaris-registry-test-service-subscribe"; -// URL consumerUrl = URL.valueOf("consumer://0.0.0.0/" + svcName); -// NotifyListener listener = new NotifyListener() { -// @Override -// public void notify(List urls) { -// notified.set(true); -// } -// }; -// polarisRegistry.subscribe(consumerUrl, listener); -// String host = NetUtils.getLocalHost(); -// List serviceUrls = buildInstanceUrls(svcName, host, 11300, count); -// try { -// for (URL serviceUrl : serviceUrls) { -// polarisRegistry.doRegister(serviceUrl); -// } -// try { -// Thread.sleep(5000); -// } catch (InterruptedException e) { -// e.printStackTrace(); -// } -// polarisRegistry.unsubscribe(consumerUrl, listener); -// Assertions.assertTrue(notified.get()); -// } finally { -// for (URL serviceUrl : serviceUrls) { -// polarisRegistry.doUnregister(serviceUrl); -// } -// } -// } -// -// @Test -// public void testRegister() { -// String svcName = "polaris-registry-test-service-register"; -// int count = 10; -// String host = NetUtils.getLocalHost(); -// List serviceUrls = buildInstanceUrls(svcName, host,11300, count); -// for (URL serviceUrl : serviceUrls) { -// polarisRegistry.doRegister(serviceUrl); -// } -// try { -// Thread.sleep(5000); -// } catch (InterruptedException e) { -// e.printStackTrace(); -// } -// try { -// Instance[] availableInstances = polarisRegistry.getPolarisOperator().getAvailableInstances(svcName, true); -// Assertions.assertEquals(count, countInstanceByHost(host, availableInstances)); -// } finally { -// for (URL serviceUrl : serviceUrls) { -// polarisRegistry.doUnregister(serviceUrl); -// } -// } -// } -// -// private static List buildInstanceUrls(String service, String host, int startPort, int count) { -// List serviceUrls = new ArrayList<>(); -// for (int i = 0; i < count; i++) { -// URL serviceUrl = URL.valueOf("dubbo://" + host + ":" + -// Integer.toString(startPort + i) + "/" + service + "?methods=test1,test2"); -// serviceUrls.add(serviceUrl); -// } -// return serviceUrls; -// } -// -// private static int countInstanceByHost(String host, Instance[] instances) { -// int count = 0; -// for (Instance instance : instances) { -// if (StringUtils.isEquals(host, instance.getHost())) { -// count++; -// } -// } -// return count; -// } -// -//} From 88d8589ced735d4ff0337f9cae2cfa43f2b9f9cd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 9 Aug 2023 11:32:18 +0800 Subject: [PATCH 16/35] Bump org.springframework:spring-framework-bom (#219) Bumps [org.springframework:spring-framework-bom](https://github.com/spring-projects/spring-framework) from 4.3.29.RELEASE to 4.3.30.RELEASE. - [Release notes](https://github.com/spring-projects/spring-framework/releases) - [Commits](https://github.com/spring-projects/spring-framework/compare/v4.3.29.RELEASE...v4.3.30.RELEASE) --- updated-dependencies: - dependency-name: org.springframework:spring-framework-bom dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .../dubbo-serialization-fst-test/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-fst-test/pom.xml b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-fst-test/pom.xml index 89977f146..77b295770 100644 --- a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-fst-test/pom.xml +++ b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-fst-test/pom.xml @@ -31,7 +31,7 @@ 1.8 3.0.4 4.13.1 - 4.3.29.RELEASE + 4.3.30.RELEASE 1.0.2-SNAPSHOT 3.7.0 From 5c419732a7bae8c29872f4bca38461f33be260d3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 9 Aug 2023 11:32:30 +0800 Subject: [PATCH 17/35] Bump org.springframework:spring-framework-bom (#222) Bumps [org.springframework:spring-framework-bom](https://github.com/spring-projects/spring-framework) from 4.3.29.RELEASE to 4.3.30.RELEASE. - [Release notes](https://github.com/spring-projects/spring-framework/releases) - [Commits](https://github.com/spring-projects/spring-framework/compare/v4.3.29.RELEASE...v4.3.30.RELEASE) --- updated-dependencies: - dependency-name: org.springframework:spring-framework-bom dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .../dubbo-serialization-gson-test/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-gson-test/pom.xml b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-gson-test/pom.xml index 67148472e..069e982fe 100644 --- a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-gson-test/pom.xml +++ b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-gson-test/pom.xml @@ -31,7 +31,7 @@ 1.8 3.0.4 4.13.1 - 4.3.29.RELEASE + 4.3.30.RELEASE 1.0.2-SNAPSHOT 3.7.0 From 8d5d92762d6b8ac3e012590658ad7f7c5645ff4d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 9 Aug 2023 11:32:36 +0800 Subject: [PATCH 18/35] Bump org.springframework:spring-framework-bom (#223) Bumps [org.springframework:spring-framework-bom](https://github.com/spring-projects/spring-framework) from 4.3.29.RELEASE to 4.3.30.RELEASE. - [Release notes](https://github.com/spring-projects/spring-framework/releases) - [Commits](https://github.com/spring-projects/spring-framework/compare/v4.3.29.RELEASE...v4.3.30.RELEASE) --- updated-dependencies: - dependency-name: org.springframework:spring-framework-bom dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .../dubbo-serialization-protobuf-test/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-protobuf-test/pom.xml b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-protobuf-test/pom.xml index 0378770ed..2c14f1fc5 100644 --- a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-protobuf-test/pom.xml +++ b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-protobuf-test/pom.xml @@ -31,7 +31,7 @@ 1.8 3.0.4 4.13.1 - 4.3.29.RELEASE + 4.3.30.RELEASE 0.0.2 1.0.2-SNAPSHOT 3.7.0 From 8a1b2b2cc5ba508fc6cad8b5cb5660a4796d3bb7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 9 Aug 2023 11:32:42 +0800 Subject: [PATCH 19/35] Bump org.springframework:spring-framework-bom (#221) Bumps [org.springframework:spring-framework-bom](https://github.com/spring-projects/spring-framework) from 4.3.29.RELEASE to 4.3.30.RELEASE. - [Release notes](https://github.com/spring-projects/spring-framework/releases) - [Commits](https://github.com/spring-projects/spring-framework/compare/v4.3.29.RELEASE...v4.3.30.RELEASE) --- updated-dependencies: - dependency-name: org.springframework:spring-framework-bom dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .../dubbo-serialization-fastjson-test/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-fastjson-test/pom.xml b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-fastjson-test/pom.xml index f20a02332..f913a9d52 100644 --- a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-fastjson-test/pom.xml +++ b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-fastjson-test/pom.xml @@ -31,7 +31,7 @@ 1.8 3.0.4 4.13.1 - 4.3.29.RELEASE + 4.3.30.RELEASE 1.0.2-SNAPSHOT 3.7.0 From 4397ec1e9713aa970e34fa95d944dbcfcc083ecd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 9 Aug 2023 11:32:49 +0800 Subject: [PATCH 20/35] Bump org.springframework:spring-framework-bom (#220) Bumps [org.springframework:spring-framework-bom](https://github.com/spring-projects/spring-framework) from 4.3.29.RELEASE to 4.3.30.RELEASE. - [Release notes](https://github.com/spring-projects/spring-framework/releases) - [Commits](https://github.com/spring-projects/spring-framework/compare/v4.3.29.RELEASE...v4.3.30.RELEASE) --- updated-dependencies: - dependency-name: org.springframework:spring-framework-bom dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .../dubbo-serialization-kryo-test/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-kryo-test/pom.xml b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-kryo-test/pom.xml index 430f1c091..c9a4ea325 100644 --- a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-kryo-test/pom.xml +++ b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-kryo-test/pom.xml @@ -31,7 +31,7 @@ 1.8 3.0.4 4.13.1 - 4.3.29.RELEASE + 4.3.30.RELEASE 1.0.5-SNAPSHOT 1.0.2-SNAPSHOT 3.7.0 From fb45775847ec777c6c94fbc584661308325c71a8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 9 Aug 2023 11:32:55 +0800 Subject: [PATCH 21/35] Bump org.springframework:spring-framework-bom (#218) Bumps [org.springframework:spring-framework-bom](https://github.com/spring-projects/spring-framework) from 4.3.29.RELEASE to 4.3.30.RELEASE. - [Release notes](https://github.com/spring-projects/spring-framework/releases) - [Commits](https://github.com/spring-projects/spring-framework/compare/v4.3.29.RELEASE...v4.3.30.RELEASE) --- updated-dependencies: - dependency-name: org.springframework:spring-framework-bom dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .../dubbo-serialization-avro-test/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-avro-test/pom.xml b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-avro-test/pom.xml index a22b80f34..7ea494106 100644 --- a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-avro-test/pom.xml +++ b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-avro-test/pom.xml @@ -30,7 +30,7 @@ 1.8 3.0.4 4.13.1 - 4.3.29.RELEASE + 4.3.30.RELEASE 1.0.2-SNAPSHOT 3.7.0 From 5c84c91604c68f2361a9409fc7cc9425760b93a1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 9 Aug 2023 11:33:12 +0800 Subject: [PATCH 22/35] Bump org.springframework:spring-framework-bom (#217) Bumps [org.springframework:spring-framework-bom](https://github.com/spring-projects/spring-framework) from 4.3.29.RELEASE to 4.3.30.RELEASE. - [Release notes](https://github.com/spring-projects/spring-framework/releases) - [Commits](https://github.com/spring-projects/spring-framework/compare/v4.3.29.RELEASE...v4.3.30.RELEASE) --- updated-dependencies: - dependency-name: org.springframework:spring-framework-bom dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .../dubbo-serialization-protostuff-test/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-protostuff-test/pom.xml b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-protostuff-test/pom.xml index cff199ba6..e5fc1351e 100644 --- a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-protostuff-test/pom.xml +++ b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-protostuff-test/pom.xml @@ -31,7 +31,7 @@ 1.8 3.0.4 4.13.1 - 4.3.29.RELEASE + 4.3.30.RELEASE 1.0.2-SNAPSHOT 3.7.0 From abd907b5c63437bb030f947b65e8f9289a510bea Mon Sep 17 00:00:00 2001 From: carlvine500 Date: Thu, 10 Aug 2023 10:59:39 +0800 Subject: [PATCH 23/35] [Cross thread] tag corss thread by annotation (#215) * add dubbo-cross-thread-extensions * add dubbo-cross-thread-extensions * change doc * @DubboCrossThread run with skywalking && ttl * set dubbo-rpc-api optional --------- Co-authored-by: songxiaosheng --- dubbo-cross-thread-extensions/README.md | 141 ++++++++++++++++++ dubbo-cross-thread-extensions/pom.xml | 55 +++++++ .../RunnableOrCallableActivation.java | 71 +++++++++ ...unnableOrCallableConstructInterceptor.java | 41 +++++ .../RunnableOrCallableMethodInterceptor.java | 39 +++++ .../crossthread/toolkit/CallableWrapper.java | 38 +++++ .../crossthread/toolkit/ConsumerWrapper.java | 38 +++++ .../crossthread/toolkit/DubboCrossThread.java | 27 ++++ .../crossthread/toolkit/FunctionWrapper.java | 39 +++++ .../crossthread/toolkit/RunnableWrapper.java | 36 +++++ .../crossthread/DubboCrossThreadTest.java | 82 ++++++++++ dubbo-extensions-dependencies-bom/pom.xml | 11 ++ pom.xml | 1 + 13 files changed, 619 insertions(+) create mode 100644 dubbo-cross-thread-extensions/README.md create mode 100644 dubbo-cross-thread-extensions/pom.xml create mode 100644 dubbo-cross-thread-extensions/src/main/java/org/apache/dubbo/crossthread/interceptor/RunnableOrCallableActivation.java create mode 100644 dubbo-cross-thread-extensions/src/main/java/org/apache/dubbo/crossthread/interceptor/RunnableOrCallableConstructInterceptor.java create mode 100644 dubbo-cross-thread-extensions/src/main/java/org/apache/dubbo/crossthread/interceptor/RunnableOrCallableMethodInterceptor.java create mode 100644 dubbo-cross-thread-extensions/src/main/java/org/apache/dubbo/crossthread/toolkit/CallableWrapper.java create mode 100644 dubbo-cross-thread-extensions/src/main/java/org/apache/dubbo/crossthread/toolkit/ConsumerWrapper.java create mode 100644 dubbo-cross-thread-extensions/src/main/java/org/apache/dubbo/crossthread/toolkit/DubboCrossThread.java create mode 100644 dubbo-cross-thread-extensions/src/main/java/org/apache/dubbo/crossthread/toolkit/FunctionWrapper.java create mode 100644 dubbo-cross-thread-extensions/src/main/java/org/apache/dubbo/crossthread/toolkit/RunnableWrapper.java create mode 100644 dubbo-cross-thread-extensions/src/test/java/org/apache/dubbo/crossthread/DubboCrossThreadTest.java diff --git a/dubbo-cross-thread-extensions/README.md b/dubbo-cross-thread-extensions/README.md new file mode 100644 index 000000000..98ceb2ac2 --- /dev/null +++ b/dubbo-cross-thread-extensions/README.md @@ -0,0 +1,141 @@ +# Dubbo Cross Thread Extensions + +`dubbo-cross-thread-extensions` copy dubbo.tag cross thread lightly . +it can run with skywalking and ttl . + +## Integrate example +### scan annotation by byte-buddy +(you can install with ByteBuddyAgent or use it with `-javaagent=`) +``` + Instrumentation instrumentation = ByteBuddyAgent.install(); + RunnableOrCallableActivation.install(instrumentation); + RpcContext.getClientAttachment().setAttachment(CommonConstants.TAG_KEY, tag); + Callable callable = CallableWrapper.of(new Callable() { + @Override + public String call() throws Exception { + return RpcContext.getClientAttachment().getAttachment(CommonConstants.TAG_KEY); + } + }); + ExecutorService threadPool = Executors.newSingleThreadExecutor(); + Future result = threadPool.submit(callable); +``` +### add annotation @DubboCrossThread + +``` +@DubboCrossThread +public class TargetClass implements Runnable{ + @Override + public void run() { + // ... + } +} +``` +### wrap Callable or Runnable +``` +Callable callable = CallableWrapper.of(new Callable() { + @Override + public String call() throws Exception { + return null; + } +}); +``` +``` +Runnable runnable = RunnableWrapper.of(new Runnable() { + @Override + public void run() { + // ... + } +}); +``` +## Integrate with spring boot + +### add a listener +``` +public class DubboCrossThreadAnnotationListener implements ApplicationListener { + private Logger logger = LoggerFactory.getLogger(DubboCrossThreadAnnotationListener.class); + private Instrumentation instrumentation; + + @Override + public void onApplicationEvent(ApplicationEnvironmentPreparedEvent applicationEnvironmentPreparedEvent) { + RunnableOrCallableActivation.install(this.instrumentation); + logger.info("finished byte buddy installation."); + } + + public DubboCrossThreadAnnotationListener(Instrumentation instrumentation) { + this.instrumentation = instrumentation; + } + + private DubboCrossThreadAnnotationListener() { + + } +} + +``` +### install ByteBuddyAgent +``` +@SpringBootApplication +@ComponentScan(basePackages = "org.apache.your-package") +public class SpringBootDemoApplication { + + public static void main(String[] args) { + SpringApplication application = new SpringApplication(SpringBootDemoApplication.class); + application.addListeners(new DubboCrossThreadAnnotationListener(ByteBuddyAgent.install())); + application.run(args); + } +} +``` + +## run with wkywalking and ttl +jvm arguments: +``` +-javaagent:transmittable-thread-local-2.14.2.jar +-Dskywalking.agent.application_code=tracecallable-ltf1 +-Dskywalking.agent.service_name=test12 +-Dskywalking.collector.backend_service=172.37.66.195:11800 +-javaagent:skywalking-agent.jar +``` +example code: +``` +public class MultiAnnotationWithSwTtl { + private static TransmittableThreadLocal context = new TransmittableThreadLocal<>(); + + public static void main(String[] args) { + Instrumentation instrumentation = ByteBuddyAgent.install(); + RunnableOrCallableActivation.install(instrumentation); + context.set("value-set-in-parent with ttl"); + RunnableWrapper runnable = RunnableWrapper.of(new Runnable() { + @Override + public void run() { + System.out.println("parent thread traceId=" + TraceContext.traceId()); + RpcContext.getClientAttachment().setAttachment("dubbo.tag", "tagValue"); + MyRunnable task = new MyRunnable(); + ExecutorService executorService = Executors.newSingleThreadExecutor(); + executorService.submit(task); + } + }); + runnable.run(); + } + + @TraceCrossThread // copy traceContext (include traceId) + @DubboCrossThread + public static class MyRunnable implements Runnable { + + @Override + public void run() { + System.out.println("dubbo.tag=" + RpcContext.getClientAttachment().getAttachment("dubbo.tag")); + System.out.println("children thread traceId=" + TraceContext.traceId()); + System.out.println("ttl context.get()="+context.get()); + } + + } +} + +``` +output: +``` +parent thread traceId=60cfc24e245d4389b9f40b5b38c33ef6.1.16910355654660001 +dubbo.tag=tagValue +children thread traceId=60cfc24e245d4389b9f40b5b38c33ef6.1.16910355654660001 +ttl context.get()=value-set-in-parent with ttl +``` + diff --git a/dubbo-cross-thread-extensions/pom.xml b/dubbo-cross-thread-extensions/pom.xml new file mode 100644 index 000000000..0d3b659a9 --- /dev/null +++ b/dubbo-cross-thread-extensions/pom.xml @@ -0,0 +1,55 @@ + + + + org.apache.dubbo.extensions + extensions-parent + ${revision} + ../pom.xml + + 4.0.0 + + dubbo-cross-thread-extensions + jar + + + UTF-8 + false + + + + + org.apache.dubbo + dubbo-rpc-api + true + + + org.apache.dubbo + dubbo-common + true + + + net.bytebuddy + byte-buddy + + + net.bytebuddy + byte-buddy-agent + test + + + diff --git a/dubbo-cross-thread-extensions/src/main/java/org/apache/dubbo/crossthread/interceptor/RunnableOrCallableActivation.java b/dubbo-cross-thread-extensions/src/main/java/org/apache/dubbo/crossthread/interceptor/RunnableOrCallableActivation.java new file mode 100644 index 000000000..c1fec872a --- /dev/null +++ b/dubbo-cross-thread-extensions/src/main/java/org/apache/dubbo/crossthread/interceptor/RunnableOrCallableActivation.java @@ -0,0 +1,71 @@ +/* + * 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 org.apache.dubbo.crossthread.interceptor; + +import org.apache.dubbo.crossthread.toolkit.DubboCrossThread; + +import net.bytebuddy.agent.builder.AgentBuilder; +import net.bytebuddy.asm.Advice; +import net.bytebuddy.description.modifier.Visibility; +import net.bytebuddy.description.type.TypeDescription; +import net.bytebuddy.dynamic.DynamicType; +import net.bytebuddy.matcher.ElementMatchers; +import net.bytebuddy.utility.JavaModule; + +import java.lang.instrument.Instrumentation; +import java.security.ProtectionDomain; + +import static net.bytebuddy.matcher.ElementMatchers.isAnnotatedWith; +import static net.bytebuddy.matcher.ElementMatchers.takesArguments; + +public class RunnableOrCallableActivation { + // add '_' before dubboTag to avoid conflict field name + public static final String FIELD_NAME_DUBBO_TAG = "_dubboTag"; + private static final String CALL_METHOD_NAME = "call"; + private static final String RUN_METHOD_NAME = "run"; + private static final String APPLY_METHOD_NAME = "apply"; + private static final String ACCEPT_METHOD_NAME = "accept"; + + public static void install(Instrumentation instrumentation) { + new AgentBuilder.Default() + .with(AgentBuilder.RedefinitionStrategy.RETRANSFORMATION) + .with(AgentBuilder.TypeStrategy.Default.REBASE) + .with(AgentBuilder.RedefinitionStrategy.REDEFINITION) + .type(isAnnotatedWith(DubboCrossThread.class)) + .transform(new AgentBuilder.Transformer() { + @Override + public DynamicType.Builder transform(DynamicType.Builder builder, TypeDescription typeDescription, + ClassLoader classLoader, JavaModule module, + ProtectionDomain protectionDomain) { + return builder + .defineField(FIELD_NAME_DUBBO_TAG, String.class, Visibility.PUBLIC) + .visit(Advice.to(RunnableOrCallableMethodInterceptor.class).on( + ElementMatchers.isMethod().and( + ElementMatchers.named(RUN_METHOD_NAME).and(takesArguments(0)) + .or(ElementMatchers.named(CALL_METHOD_NAME).and(takesArguments(0))) + .or(ElementMatchers.named(APPLY_METHOD_NAME).and(takesArguments(0))) + .or(ElementMatchers.named(ACCEPT_METHOD_NAME).and(takesArguments(0))) + ) + )) + .visit(Advice.to(RunnableOrCallableConstructInterceptor.class).on( + ElementMatchers.isConstructor() + )); + } + }) + .installOn(instrumentation); + } +} diff --git a/dubbo-cross-thread-extensions/src/main/java/org/apache/dubbo/crossthread/interceptor/RunnableOrCallableConstructInterceptor.java b/dubbo-cross-thread-extensions/src/main/java/org/apache/dubbo/crossthread/interceptor/RunnableOrCallableConstructInterceptor.java new file mode 100644 index 000000000..03a8ecf45 --- /dev/null +++ b/dubbo-cross-thread-extensions/src/main/java/org/apache/dubbo/crossthread/interceptor/RunnableOrCallableConstructInterceptor.java @@ -0,0 +1,41 @@ +/* + * 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 org.apache.dubbo.crossthread.interceptor; + +import java.lang.reflect.Field; + +import net.bytebuddy.asm.Advice; + +import org.apache.dubbo.common.constants.CommonConstants; +import org.apache.dubbo.rpc.RpcContext; + +public class RunnableOrCallableConstructInterceptor { + + @Advice.OnMethodEnter + public static void onMethodEnter() { + + } + + @Advice.OnMethodExit + public static void onMethodExit(@Advice.This Object thiz) throws IllegalAccessException, NoSuchFieldException { + Field tag = thiz.getClass().getDeclaredField(RunnableOrCallableActivation.FIELD_NAME_DUBBO_TAG); + // copy tag to RunnableOrCallable's field from RpcContext + String dubboTag = RpcContext.getClientAttachment().getAttachment(CommonConstants.TAG_KEY); + tag.set(thiz, dubboTag); + } + +} diff --git a/dubbo-cross-thread-extensions/src/main/java/org/apache/dubbo/crossthread/interceptor/RunnableOrCallableMethodInterceptor.java b/dubbo-cross-thread-extensions/src/main/java/org/apache/dubbo/crossthread/interceptor/RunnableOrCallableMethodInterceptor.java new file mode 100644 index 000000000..5d4fbf2a2 --- /dev/null +++ b/dubbo-cross-thread-extensions/src/main/java/org/apache/dubbo/crossthread/interceptor/RunnableOrCallableMethodInterceptor.java @@ -0,0 +1,39 @@ +/* + * 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 org.apache.dubbo.crossthread.interceptor; + +import org.apache.dubbo.common.constants.CommonConstants; +import org.apache.dubbo.rpc.RpcContext; + +import net.bytebuddy.asm.Advice; + +public class RunnableOrCallableMethodInterceptor { + + @Advice.OnMethodEnter + public static void onMethodEnter( + @Advice.FieldValue(value = RunnableOrCallableActivation.FIELD_NAME_DUBBO_TAG, readOnly = false) String dubboTag) { + // copy tag to RpcContext from RunnableOrCallable's field value + RpcContext.getClientAttachment().setAttachment(CommonConstants.TAG_KEY, dubboTag); + } + + @Advice.OnMethodExit(onThrowable = Throwable.class) + public static void onMethodExit() { + // clear tag in RpcContext + RpcContext.getClientAttachment().removeAttachment(CommonConstants.TAG_KEY); + } + +} diff --git a/dubbo-cross-thread-extensions/src/main/java/org/apache/dubbo/crossthread/toolkit/CallableWrapper.java b/dubbo-cross-thread-extensions/src/main/java/org/apache/dubbo/crossthread/toolkit/CallableWrapper.java new file mode 100644 index 000000000..7f71fbfda --- /dev/null +++ b/dubbo-cross-thread-extensions/src/main/java/org/apache/dubbo/crossthread/toolkit/CallableWrapper.java @@ -0,0 +1,38 @@ +/* + * 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 org.apache.dubbo.crossthread.toolkit; + +import java.util.concurrent.Callable; + +@DubboCrossThread +public class CallableWrapper implements Callable { + final Callable callable; + + public static CallableWrapper of(Callable r) { + return new CallableWrapper<>(r); + } + + public CallableWrapper(Callable callable) { + this.callable = callable; + } + + @Override + public V call() throws Exception { + return callable.call(); + } +} diff --git a/dubbo-cross-thread-extensions/src/main/java/org/apache/dubbo/crossthread/toolkit/ConsumerWrapper.java b/dubbo-cross-thread-extensions/src/main/java/org/apache/dubbo/crossthread/toolkit/ConsumerWrapper.java new file mode 100644 index 000000000..65c53a490 --- /dev/null +++ b/dubbo-cross-thread-extensions/src/main/java/org/apache/dubbo/crossthread/toolkit/ConsumerWrapper.java @@ -0,0 +1,38 @@ +/* + * 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 org.apache.dubbo.crossthread.toolkit; + +import java.util.function.Consumer; + +@DubboCrossThread +public class ConsumerWrapper implements Consumer { + final Consumer consumer; + + public ConsumerWrapper(Consumer consumer) { + this.consumer = consumer; + } + + public static ConsumerWrapper of(Consumer consumer) { + return new ConsumerWrapper(consumer); + } + + @Override + public void accept(V v) { + this.consumer.accept(v); + } + +} diff --git a/dubbo-cross-thread-extensions/src/main/java/org/apache/dubbo/crossthread/toolkit/DubboCrossThread.java b/dubbo-cross-thread-extensions/src/main/java/org/apache/dubbo/crossthread/toolkit/DubboCrossThread.java new file mode 100644 index 000000000..246fa7c66 --- /dev/null +++ b/dubbo-cross-thread-extensions/src/main/java/org/apache/dubbo/crossthread/toolkit/DubboCrossThread.java @@ -0,0 +1,27 @@ +/* + * 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 org.apache.dubbo.crossthread.toolkit; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +public @interface DubboCrossThread { +} diff --git a/dubbo-cross-thread-extensions/src/main/java/org/apache/dubbo/crossthread/toolkit/FunctionWrapper.java b/dubbo-cross-thread-extensions/src/main/java/org/apache/dubbo/crossthread/toolkit/FunctionWrapper.java new file mode 100644 index 000000000..e053b215f --- /dev/null +++ b/dubbo-cross-thread-extensions/src/main/java/org/apache/dubbo/crossthread/toolkit/FunctionWrapper.java @@ -0,0 +1,39 @@ +/* + * 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 org.apache.dubbo.crossthread.toolkit; + +import java.util.function.Function; + +@DubboCrossThread +public class FunctionWrapper implements Function { + final Function function; + + public FunctionWrapper(Function function) { + this.function = function; + } + + public static FunctionWrapper of(Function function) { + return new FunctionWrapper(function); + } + + @Override + public R apply(T t) { + return this.function.apply(t); + } + +} diff --git a/dubbo-cross-thread-extensions/src/main/java/org/apache/dubbo/crossthread/toolkit/RunnableWrapper.java b/dubbo-cross-thread-extensions/src/main/java/org/apache/dubbo/crossthread/toolkit/RunnableWrapper.java new file mode 100644 index 000000000..da4651952 --- /dev/null +++ b/dubbo-cross-thread-extensions/src/main/java/org/apache/dubbo/crossthread/toolkit/RunnableWrapper.java @@ -0,0 +1,36 @@ +/* + * 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 org.apache.dubbo.crossthread.toolkit; + +@DubboCrossThread +public class RunnableWrapper implements Runnable { + final Runnable runnable; + + public RunnableWrapper(Runnable runnable) { + this.runnable = runnable; + } + + public static RunnableWrapper of(Runnable r) { + return new RunnableWrapper(r); + } + + @Override + public void run() { + this.runnable.run(); + } +} diff --git a/dubbo-cross-thread-extensions/src/test/java/org/apache/dubbo/crossthread/DubboCrossThreadTest.java b/dubbo-cross-thread-extensions/src/test/java/org/apache/dubbo/crossthread/DubboCrossThreadTest.java new file mode 100644 index 000000000..ca430523e --- /dev/null +++ b/dubbo-cross-thread-extensions/src/test/java/org/apache/dubbo/crossthread/DubboCrossThreadTest.java @@ -0,0 +1,82 @@ +/* + * 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 org.apache.dubbo.crossthread; + +import java.lang.instrument.Instrumentation; +import java.util.concurrent.Callable; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +import net.bytebuddy.agent.ByteBuddyAgent; +import org.apache.dubbo.common.constants.CommonConstants; +import org.apache.dubbo.crossthread.interceptor.RunnableOrCallableActivation; +import org.apache.dubbo.rpc.RpcContext; +import org.apache.dubbo.crossthread.toolkit.CallableWrapper; +import org.apache.dubbo.crossthread.toolkit.RunnableWrapper; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class DubboCrossThreadTest { + @Test + public void crossThreadCallableTest() throws ExecutionException, InterruptedException, TimeoutException { + Instrumentation instrumentation = ByteBuddyAgent.install(); + RunnableOrCallableActivation.install(instrumentation); + String tag = "beta"; + RpcContext.getClientAttachment().setAttachment(CommonConstants.TAG_KEY, tag); + Callable callable = CallableWrapper.of(new Callable() { + @Override + public String call() throws Exception { + return RpcContext.getClientAttachment().getAttachment(CommonConstants.TAG_KEY); + } + }); + ExecutorService threadPool = Executors.newSingleThreadExecutor(); + Future submit = threadPool.submit(callable); + assertEquals(tag, submit.get(1, TimeUnit.SECONDS)); + threadPool.shutdown(); + } + + private volatile String tagCrossThread = null; + + @Test + public void crossThreadRunnableTest() throws ExecutionException, InterruptedException { + Instrumentation instrumentation = ByteBuddyAgent.install(); + RunnableOrCallableActivation.install(instrumentation); + String tag = "beta"; + RpcContext.getClientAttachment().setAttachment(CommonConstants.TAG_KEY, tag); + final CountDownLatch latch = new CountDownLatch(1); + Runnable runnable = RunnableWrapper.of(new Runnable() { + @Override + public void run() { + String tag = RpcContext.getClientAttachment().getAttachment(CommonConstants.TAG_KEY); + tagCrossThread = tag; + latch.countDown(); + } + }); + ExecutorService threadPool = Executors.newSingleThreadExecutor(); + threadPool.submit(runnable); + latch.await(1, TimeUnit.SECONDS); + assertEquals(tag, tagCrossThread); + threadPool.shutdown(); + } + +} diff --git a/dubbo-extensions-dependencies-bom/pom.xml b/dubbo-extensions-dependencies-bom/pom.xml index 2e998be0c..257ea87de 100644 --- a/dubbo-extensions-dependencies-bom/pom.xml +++ b/dubbo-extensions-dependencies-bom/pom.xml @@ -135,6 +135,7 @@ 3.0.20.Final 0.2.1 1.2.5 + 1.14.5 @@ -489,6 +490,16 @@ polaris-adapter-dubbo ${polaris_adapter_version} + + net.bytebuddy + byte-buddy + ${byte-buddy.version} + + + net.bytebuddy + byte-buddy-agent + ${byte-buddy.version} + diff --git a/pom.xml b/pom.xml index 734d33a62..7e40544fd 100644 --- a/pom.xml +++ b/pom.xml @@ -95,6 +95,7 @@ dubbo-serialization-extensions dubbo-mock-extensions dubbo-gateway-extensions + dubbo-cross-thread-extensions From a6e6eb1ae338a7e2d5c304bcfc8eb607b1db39fd Mon Sep 17 00:00:00 2001 From: carlvine500 Date: Mon, 14 Aug 2023 18:57:24 +0800 Subject: [PATCH 24/35] [tag subnets] add tag by subnets for near-rpc (#216) * tag subnets * change some protected field to private final;remote unused import * Update pom.xml remove redundant properties. * add dependency junit-jupiter-engine * change description in pom.xml --- dubbo-extensions-dependencies-bom/pom.xml | 12 +++ dubbo-tag-extensions/README.md | 65 ++++++++++++++ dubbo-tag-extensions/README_zh.md | 65 ++++++++++++++ .../dubbo-tag-subnets/pom.xml | 63 ++++++++++++++ .../config/SubnetTagConfigPostProcessor.java | 61 ++++++++++++++ .../dubbo/tag/subnets/utils/SubnetUtil.java | 84 +++++++++++++++++++ ...rg.apache.dubbo.config.ConfigPostProcessor | 1 + .../tag/subnets/utils/SubnetUtilTest.java | 37 ++++++++ .../src/test/resources/log4j.properties | 7 ++ dubbo-tag-extensions/pom.xml | 35 ++++++++ pom.xml | 1 + 11 files changed, 431 insertions(+) create mode 100644 dubbo-tag-extensions/README.md create mode 100644 dubbo-tag-extensions/README_zh.md create mode 100644 dubbo-tag-extensions/dubbo-tag-subnets/pom.xml create mode 100644 dubbo-tag-extensions/dubbo-tag-subnets/src/main/java/org/apache/dubbo/tag/subnets/config/SubnetTagConfigPostProcessor.java create mode 100644 dubbo-tag-extensions/dubbo-tag-subnets/src/main/java/org/apache/dubbo/tag/subnets/utils/SubnetUtil.java create mode 100644 dubbo-tag-extensions/dubbo-tag-subnets/src/main/resources/META-INF/dubbo/org.apache.dubbo.config.ConfigPostProcessor create mode 100644 dubbo-tag-extensions/dubbo-tag-subnets/src/test/java/org/apache/dubbo/tag/subnets/utils/SubnetUtilTest.java create mode 100644 dubbo-tag-extensions/dubbo-tag-subnets/src/test/resources/log4j.properties create mode 100644 dubbo-tag-extensions/pom.xml diff --git a/dubbo-extensions-dependencies-bom/pom.xml b/dubbo-extensions-dependencies-bom/pom.xml index 257ea87de..94c1a5bf1 100644 --- a/dubbo-extensions-dependencies-bom/pom.xml +++ b/dubbo-extensions-dependencies-bom/pom.xml @@ -136,6 +136,8 @@ 0.2.1 1.2.5 1.14.5 + 3.9.0 + 2.0 @@ -500,6 +502,16 @@ byte-buddy-agent ${byte-buddy.version} + + commons-net + commons-net + ${commons_net_version} + + + org.yaml + snakeyaml + ${snakeyaml_version} + diff --git a/dubbo-tag-extensions/README.md b/dubbo-tag-extensions/README.md new file mode 100644 index 000000000..805196069 --- /dev/null +++ b/dubbo-tag-extensions/README.md @@ -0,0 +1,65 @@ +# dubbo tag subnets + +[中文](./README.md) + +dubbo-tag-subnets will generate a tag by subnets, then consumer will prefer rpc provider in the same subnets. + +- example1: there are 3 zone(cn-shanghai-a/cn-shanghai-b/cn-shanghai-c) in aliyun-VPC, service rpc in the same zone +``` +cn|shanghai|a: +- 172.37.66.0/24 #zone=cn-shanghai-a +cn|shanghai|b: +- 172.37.68.0/24 #zone=cn-shanghai-b +cn|shanghai|c: +- 172.37.69.0/24 #zone=cn-shanghai-c +``` +- example2: there is a big zone and there are 3 cells in it , service rpc in the same cell +``` +cn|shanghai|a|cell-1: +- 172.31.35.0/24 #zone=cn-shanghai-a +cn|shanghai|a|cell-2: +- 172.31.36.0/24 #zone=cn-shanghai-a +cn|shanghai|a|cell-3: +- 172.31.37.0/24 #zone=cn-shanghai-a +``` +- example3: there 3 seperate zones(a/b/c) and a common zone(d), consumer prefer rpc in near zones(a/b/c), and then rpc common zone(d). +``` +cn|shanghai|a: +- 172.37.66.0/24 #zone=cn-shanghai-a +cn|hangzhou|b: +- 172.37.67.0/24 #zone=cn-hangzhou-b +cn|shenzhen|c: +- 172.37.68.0/24 #zone=cn-shenzhen-c +"": +- 172.37.69.0/24 #zone=cn-shanghai-d, as common service +``` + +## How to use? + +1. import dependency + +``` + + org.apache.dubbo.extensions + dubbo-tag-subnets + ${dubbo-tag-subnets-version} + + +``` + +2. set tag-subnets in config-center path=/dubbo/config/tag.subnets, zookeeper example: +``` +echo 'cn|cn-northwest|cell-1: +- 172.37.66.0/24 #cn-northwest-1a +cn|cn-north|cell-2: +- 172.37.67.0/24 #cn-northwest-1b +cn|cn-north: +- 192.168.1.0/24 #cn-north-1a +' | tee tag.subnets.yaml +./zkCli.sh create /dubbo/config/tag.subnets "" +./zkCli.sh set /dubbo/config/tag.subnets "$(cat tag.subnets.yaml)" +./zkCli.sh get /dubbo/config/tag.subnets +``` + + +3. start your provider, you will see tag generate by subnets in registry. diff --git a/dubbo-tag-extensions/README_zh.md b/dubbo-tag-extensions/README_zh.md new file mode 100644 index 000000000..e3c31dbd4 --- /dev/null +++ b/dubbo-tag-extensions/README_zh.md @@ -0,0 +1,65 @@ +# dubbo tag subnets + +[中文](./README.md) + +dubbo-tag-subnets 会根据子网生成tag, 然后同子网内的tag相同, 服务调用会优先发生在同子网中. + +- 示例1: 在阿里云VPC, 有三个可用区(cn-shanghai-a/cn-shanghai-b/cn-shanghai-c) , 服务在同一可用区中调用 +``` +cn|shanghai|a: +- 172.37.66.0/24 #zone=cn-shanghai-a +cn|shanghai|b: +- 172.37.68.0/24 #zone=cn-shanghai-b +cn|shanghai|c: +- 172.37.69.0/24 #zone=cn-shanghai-c +``` +- 示例2: 有三个单元在一个大的可用区cn-shanghai-a , 服务在同单元中调用 +``` +cn|shanghai|a|cell-1: +- 172.31.35.0/24 #zone=cn-shanghai-a +cn|shanghai|a|cell-2: +- 172.31.36.0/24 #zone=cn-shanghai-a +cn|shanghai|a|cell-3: +- 172.31.37.0/24 #zone=cn-shanghai-a +``` +- 示例3: 有三个"独立的可用区"(a/b/c) ,有一个"公共的可用区"(d), 服务消费方优先在自己"独立可用区"中调用, 然后调用"公共的可用区". +``` +cn|shanghai|a: +- 172.37.66.0/24 #zone=cn-shanghai-a +cn|hangzhou|b: +- 172.37.67.0/24 #zone=cn-hangzhou-b +cn|shenzhen|c: +- 172.37.68.0/24 #zone=cn-shenzhen-c +"": +- 172.37.69.0/24 #zone=cn-shanghai-d, as common service +``` + +## 如何使用? + +1. 引入依赖 + +``` + + org.apache.dubbo.extensions + dubbo-tag-subnets + ${dubbo-tag-subnets-version} + + +``` + +2. 在配置中心设置 tag-subnets ,路径为/dubbo/config/tag.subnets, zookeeper 配置示例: +``` +echo 'cn|cn-northwest|cell-1: +- 172.37.66.0/24 #cn-northwest-1a +cn|cn-north|cell-2: +- 172.37.67.0/24 #cn-northwest-1b +cn|cn-north: +- 192.168.1.0/24 #cn-north-1a +' | tee tag.subnets.yaml +./zkCli.sh create /dubbo/config/tag.subnets "" +./zkCli.sh set /dubbo/config/tag.subnets "$(cat tag.subnets.yaml)" +./zkCli.sh get /dubbo/config/tag.subnets +``` + + +3. 启动服务提供方, 您将在注册中心看到根据子网生成的服务标签. diff --git a/dubbo-tag-extensions/dubbo-tag-subnets/pom.xml b/dubbo-tag-extensions/dubbo-tag-subnets/pom.xml new file mode 100644 index 000000000..99b6b3146 --- /dev/null +++ b/dubbo-tag-extensions/dubbo-tag-subnets/pom.xml @@ -0,0 +1,63 @@ + + + + dubbo-tag-extensions + org.apache.dubbo.extensions + ${revision} + ../pom.xml + + 4.0.0 + + 1.0.2-SNAPSHOT + dubbo-tag-subnets + ${project.artifactId} + The tag subnets module of dubbo project + + + + org.apache.dubbo + dubbo-registry-api + true + + + org.apache.dubbo + dubbo-common + true + + + org.apache.dubbo + dubbo-config-api + true + + + commons-net + commons-net + + + org.yaml + snakeyaml + + + org.junit.jupiter + junit-jupiter-engine + ${junit_jupiter_version} + test + + + diff --git a/dubbo-tag-extensions/dubbo-tag-subnets/src/main/java/org/apache/dubbo/tag/subnets/config/SubnetTagConfigPostProcessor.java b/dubbo-tag-extensions/dubbo-tag-subnets/src/main/java/org/apache/dubbo/tag/subnets/config/SubnetTagConfigPostProcessor.java new file mode 100644 index 000000000..003b7e6cf --- /dev/null +++ b/dubbo-tag-extensions/dubbo-tag-subnets/src/main/java/org/apache/dubbo/tag/subnets/config/SubnetTagConfigPostProcessor.java @@ -0,0 +1,61 @@ +/* + * 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 org.apache.dubbo.tag.subnets.config; + +import org.apache.dubbo.common.config.ConfigurationUtils; +import org.apache.dubbo.common.extension.Activate; +import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.config.ConfigPostProcessor; +import org.apache.dubbo.config.ServiceConfig; +import org.apache.dubbo.rpc.model.ApplicationModel; +import org.apache.dubbo.rpc.model.ScopeModelAware; +import org.apache.dubbo.tag.subnets.utils.SubnetUtil; + +import static org.apache.dubbo.common.utils.NetUtils.getLocalHost; + + +@Activate +public class SubnetTagConfigPostProcessor implements ConfigPostProcessor, ScopeModelAware { + private ApplicationModel applicationModel; + + @Override + public void setApplicationModel(ApplicationModel applicationModel) { + this.applicationModel = applicationModel; + } + + @Override + public void postProcessServiceConfig(ServiceConfig serviceConfig) { + if (StringUtils.isNotBlank(serviceConfig.getTag())) { + return; + } + if (SubnetUtil.isEmpty()) { + String content = ConfigurationUtils.getCachedDynamicProperty(applicationModel.getDefaultModule(), SubnetUtil.TAG_SUBNETS_KEY, null); + SubnetUtil.init(content); + } + if (SubnetUtil.isEmpty()) { + return; + } + String providerHost = serviceConfig.getProvider().getHost(); + if (StringUtils.isBlank(providerHost)) { + providerHost = getLocalHost(); + } + String tagLevel = SubnetUtil.getTagLevelByHost(providerHost); + serviceConfig.setTag(tagLevel); + } + + +} diff --git a/dubbo-tag-extensions/dubbo-tag-subnets/src/main/java/org/apache/dubbo/tag/subnets/utils/SubnetUtil.java b/dubbo-tag-extensions/dubbo-tag-subnets/src/main/java/org/apache/dubbo/tag/subnets/utils/SubnetUtil.java new file mode 100644 index 000000000..7d74b7949 --- /dev/null +++ b/dubbo-tag-extensions/dubbo-tag-subnets/src/main/java/org/apache/dubbo/tag/subnets/utils/SubnetUtil.java @@ -0,0 +1,84 @@ +/* + * 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 org.apache.dubbo.tag.subnets.utils; + +import org.apache.dubbo.common.utils.StringUtils; + +import org.apache.commons.net.util.SubnetUtils; +import org.yaml.snakeyaml.LoaderOptions; +import org.yaml.snakeyaml.Yaml; +import org.yaml.snakeyaml.constructor.SafeConstructor; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.locks.ReentrantReadWriteLock; + + +public class SubnetUtil { + public static final String TAG_SUBNETS_KEY = "tag.subnets"; + + private static final Map> cellSubnets = new ConcurrentHashMap<>(); + private static final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); + private static final ReentrantReadWriteLock.ReadLock readLock = lock.readLock(); + private static final ReentrantReadWriteLock.WriteLock writeLock = lock.writeLock(); + + public static boolean isEmpty() { + try { + readLock.lock(); + return cellSubnets.isEmpty(); + } finally { + readLock.unlock(); + } + } + + public static void init(String content) { + if (StringUtils.isBlank(content)) { + return; + } + try { + writeLock.lock(); + Yaml yaml = new Yaml(new SafeConstructor(new LoaderOptions())); + cellSubnets.clear(); + Map> tmpPathSubnet = (Map>) yaml.load(content); + for (Map.Entry> entry : tmpPathSubnet.entrySet()) { + String path = entry.getKey(); + List subnetInfos = cellSubnets.computeIfAbsent(path, f -> new ArrayList()); + entry.getValue().forEach(e -> subnetInfos.add(new SubnetUtils(e.trim()).getInfo())); + } + } finally { + writeLock.unlock(); + } + } + + public static String getTagLevelByHost(String host) { + try { + readLock.lock(); + for (Map.Entry> entry : cellSubnets.entrySet()) { + for (SubnetUtils.SubnetInfo subnetInfo : entry.getValue()) { + if (subnetInfo.isInRange(host)) { + return entry.getKey(); + } + } + } + return null; + } finally { + readLock.unlock(); + } + } +} diff --git a/dubbo-tag-extensions/dubbo-tag-subnets/src/main/resources/META-INF/dubbo/org.apache.dubbo.config.ConfigPostProcessor b/dubbo-tag-extensions/dubbo-tag-subnets/src/main/resources/META-INF/dubbo/org.apache.dubbo.config.ConfigPostProcessor new file mode 100644 index 000000000..f37740a4d --- /dev/null +++ b/dubbo-tag-extensions/dubbo-tag-subnets/src/main/resources/META-INF/dubbo/org.apache.dubbo.config.ConfigPostProcessor @@ -0,0 +1 @@ +tag-subnets=org.apache.dubbo.tag.subnets.config.SubnetTagConfigPostProcessor diff --git a/dubbo-tag-extensions/dubbo-tag-subnets/src/test/java/org/apache/dubbo/tag/subnets/utils/SubnetUtilTest.java b/dubbo-tag-extensions/dubbo-tag-subnets/src/test/java/org/apache/dubbo/tag/subnets/utils/SubnetUtilTest.java new file mode 100644 index 000000000..0446d365d --- /dev/null +++ b/dubbo-tag-extensions/dubbo-tag-subnets/src/test/java/org/apache/dubbo/tag/subnets/utils/SubnetUtilTest.java @@ -0,0 +1,37 @@ +/* + * 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 org.apache.dubbo.tag.subnets.utils; + + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class SubnetUtilTest { + @Test + public void testLoadContent() { + String content = "" +// + "cn|cn-northwest|cell-1: \n" + + "- 172.37.66.0/24 #cn-northwest-1a\n" + + "cn|cn-north|cell-2: \n" + + "- 172.37.67.0/24 #cn-northwest-1b\n" + + "\"\": \n" + + "- 172.37.33.0/24 #cn-north-1a\n"; + SubnetUtil.init(content); + Assertions.assertEquals(SubnetUtil.getTagLevelByHost("172.37.66.1"),"cn|cn-northwest|cell-1"); + Assertions.assertEquals(SubnetUtil.getTagLevelByHost("172.37.33.1"),""); + } +} diff --git a/dubbo-tag-extensions/dubbo-tag-subnets/src/test/resources/log4j.properties b/dubbo-tag-extensions/dubbo-tag-subnets/src/test/resources/log4j.properties new file mode 100644 index 000000000..8de4c4fdd --- /dev/null +++ b/dubbo-tag-extensions/dubbo-tag-subnets/src/test/resources/log4j.properties @@ -0,0 +1,7 @@ +###set log levels### +log4j.rootLogger=info, stdout +###output to the console### +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=[%d{dd/MM/yy HH:mm:ss:SSS z}] %t %5p %c{2}: %m%n diff --git a/dubbo-tag-extensions/pom.xml b/dubbo-tag-extensions/pom.xml new file mode 100644 index 000000000..1c62919b3 --- /dev/null +++ b/dubbo-tag-extensions/pom.xml @@ -0,0 +1,35 @@ + + + + + org.apache.dubbo.extensions + extensions-parent + ${revision} + ../pom.xml + + 4.0.0 + ${revision} + pom + dubbo-tag-extensions + + + dubbo-tag-subnets + + diff --git a/pom.xml b/pom.xml index 7e40544fd..78b132351 100644 --- a/pom.xml +++ b/pom.xml @@ -96,6 +96,7 @@ dubbo-mock-extensions dubbo-gateway-extensions dubbo-cross-thread-extensions + dubbo-tag-extensions From d4096a15d0cb41e3eb61c637f64f5c9853204b9d Mon Sep 17 00:00:00 2001 From: songxiaosheng Date: Sun, 1 Oct 2023 10:17:20 +0800 Subject: [PATCH 25/35] :memo: visit code tree to gen doc --- README.md | 76 ++++++++++++++++++- doc-auto-gen/pom.xml | 32 ++++++++ .../java/org/apache/dubbo/doc/DocAutoGen.java | 48 ++++++++++++ .../src/test/java/org/example/AppTest.java | 38 ++++++++++ pom.xml | 1 + 5 files changed, 194 insertions(+), 1 deletion(-) create mode 100644 doc-auto-gen/pom.xml create mode 100644 doc-auto-gen/src/main/java/org/apache/dubbo/doc/DocAutoGen.java create mode 100644 doc-auto-gen/src/test/java/org/example/AppTest.java diff --git a/README.md b/README.md index ef5d07b04..b2e82ce92 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,77 @@ # dubbo-spi-extensions - [![Build Status](https://travis-ci.org/apache/dubbo-spi-extensions.svg?branch=master)](https://travis-ci.org/apache/dubbo-spi-extensions) +[![codecov](https://codecov.io/gh/apache/dubbo-spi-extensions/branch/master/graph/badge.svg)](https://codecov.io/gh/apache/dubbo-spi-extensions) +[![Maven Central](https://img.shields.io/maven-central/v/org.apache.dubbo/dubbo-spi-extensions.svg)](https://search.maven.org/search?q=g:org.apache.dubbo%20AND%20a:dubbo-spi-extensions) +[![GitHub release](https://img.shields.io/github/release/apache/dubbo-spi-extensions.svg)] +- [dubbo-api-docs](dubbo-api-docs) + - [dubbo-api-docs/dubbo-api-docs-annotations](dubbo-api-docs-annotations) + - [dubbo-api-docs/dubbo-api-docs-core](dubbo-api-docs-core) + - [dubbo-api-docs/dubbo-api-docs-examples](dubbo-api-docs-examples) +- [dubbo-cluster-extensions](dubbo-cluster-extensions) + - [dubbo-cluster-extensions/dubbo-cluster-broadcast-1](dubbo-cluster-broadcast-1) + - [dubbo-cluster-extensions/dubbo-cluster-loadbalance-peakewma](dubbo-cluster-loadbalance-peakewma) + - [dubbo-cluster-extensions/dubbo-cluster-polaris-dubbo2](dubbo-cluster-polaris-dubbo2) + - [dubbo-cluster-extensions/dubbo-cluster-specify-address-common](dubbo-cluster-specify-address-common) + - [dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2](dubbo-cluster-specify-address-dubbo2) + - [dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3](dubbo-cluster-specify-address-dubbo3) +- [dubbo-common-extensions](dubbo-common-extensions) +- [dubbo-configcenter-extensions](dubbo-configcenter-extensions) + - [dubbo-configcenter-extensions/dubbo-configcenter-consul](dubbo-configcenter-consul) + - [dubbo-configcenter-extensions/dubbo-configcenter-etcd](dubbo-configcenter-etcd) +- [dubbo-cross-thread-extensions](dubbo-cross-thread-extensions) +- [dubbo-extensions-dependencies-bom](dubbo-extensions-dependencies-bom) +- [dubbo-extensions-distribution](dubbo-extensions-distribution) + - [dubbo-extensions-distribution/dubbo-apache-release](dubbo-apache-release) + - [dubbo-extensions-distribution/dubbo-bom](dubbo-bom) +- [dubbo-filter-extensions](dubbo-filter-extensions) + - [dubbo-filter-extensions/dubbo-filter-polaris-dubbo2](dubbo-filter-polaris-dubbo2) + - [dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-circuitbreaker-dubbo2](dubbo-filter-polaris-circuitbreaker-dubbo2) + - [dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-ratelimit-dubbo2](dubbo-filter-polaris-ratelimit-dubbo2) + - [dubbo-filter-extensions/dubbo-filter-seata](dubbo-filter-seata) +- [dubbo-gateway-extensions](dubbo-gateway-extensions) + - [dubbo-gateway-extensions/dubbo-gateway-common](dubbo-gateway-common) + - [dubbo-gateway-extensions/dubbo-gateway-consumer](dubbo-gateway-consumer) + - [dubbo-gateway-extensions/dubbo-gateway-provider](dubbo-gateway-provider) +- [dubbo-metadata-report-extensions](dubbo-metadata-report-extensions) + - [dubbo-metadata-report-extensions/dubbo-metadata-report-consul](dubbo-metadata-report-consul) + - [dubbo-metadata-report-extensions/dubbo-metadata-report-etcd](dubbo-metadata-report-etcd) +- [dubbo-mock-extensions](dubbo-mock-extensions) + - [dubbo-mock-extensions/dubbo-mock-admin](dubbo-mock-admin) + - [dubbo-mock-extensions/dubbo-mock-api](dubbo-mock-api) +- [dubbo-registry-extensions](dubbo-registry-extensions) + - [dubbo-registry-extensions/dubbo-registry-consul](dubbo-registry-consul) + - [dubbo-registry-extensions/dubbo-registry-dns](dubbo-registry-dns) + - [dubbo-registry-extensions/dubbo-registry-etcd3](dubbo-registry-etcd3) + - [dubbo-registry-extensions/dubbo-registry-nameservice](dubbo-registry-nameservice) + - [dubbo-registry-extensions/dubbo-registry-polaris](dubbo-registry-polaris) + - [dubbo-registry-extensions/dubbo-registry-redis](dubbo-registry-redis) + - [dubbo-registry-extensions/dubbo-registry-sofa](dubbo-registry-sofa) +- [dubbo-remoting-extensions](dubbo-remoting-extensions) + - [dubbo-remoting-extensions/dubbo-remoting-etcd3](dubbo-remoting-etcd3) + - [dubbo-remoting-extensions/dubbo-remoting-grizzly](dubbo-remoting-grizzly) + - [dubbo-remoting-extensions/dubbo-remoting-mina](dubbo-remoting-mina) + - [dubbo-remoting-extensions/dubbo-remoting-p2p](dubbo-remoting-p2p) + - [dubbo-remoting-extensions/dubbo-remoting-quic](dubbo-remoting-quic) + - [dubbo-remoting-extensions/dubbo-remoting-redis](dubbo-remoting-redis) +- [dubbo-rpc-extensions](dubbo-rpc-extensions) + - [dubbo-rpc-extensions/dubbo-rpc-hessian](dubbo-rpc-hessian) + - [dubbo-rpc-extensions/dubbo-rpc-http](dubbo-rpc-http) + - [dubbo-rpc-extensions/dubbo-rpc-memcached](dubbo-rpc-memcached) + - [dubbo-rpc-extensions/dubbo-rpc-native-thrift](dubbo-rpc-native-thrift) + - [dubbo-rpc-extensions/dubbo-rpc-redis](dubbo-rpc-redis) + - [dubbo-rpc-extensions/dubbo-rpc-rmi](dubbo-rpc-rmi) + - [dubbo-rpc-extensions/dubbo-rpc-rocketmq](dubbo-rpc-rocketmq) + - [dubbo-rpc-extensions/dubbo-rpc-webservice](dubbo-rpc-webservice) +- [dubbo-serialization-extensions](dubbo-serialization-extensions) + - [dubbo-serialization-extensions/dubbo-serialization-avro](dubbo-serialization-avro) + - [dubbo-serialization-extensions/dubbo-serialization-fastjson](dubbo-serialization-fastjson) + - [dubbo-serialization-extensions/dubbo-serialization-fst](dubbo-serialization-fst) + - [dubbo-serialization-extensions/dubbo-serialization-gson](dubbo-serialization-gson) + - [dubbo-serialization-extensions/dubbo-serialization-kryo](dubbo-serialization-kryo) + - [dubbo-serialization-extensions/dubbo-serialization-msgpack](dubbo-serialization-msgpack) + - [dubbo-serialization-extensions/dubbo-serialization-native-hession](dubbo-serialization-native-hession) + - [dubbo-serialization-extensions/dubbo-serialization-protobuf](dubbo-serialization-protobuf) + - [dubbo-serialization-extensions/dubbo-serialization-protostuff](dubbo-serialization-protostuff) + - [dubbo-serialization-extensions/dubbo-serialization-test](dubbo-serialization-test) +- [dubbo-tag-extensions](dubbo-tag-extensions) + - [dubbo-tag-extensions/dubbo-tag-subnets](dubbo-tag-subnets) diff --git a/doc-auto-gen/pom.xml b/doc-auto-gen/pom.xml new file mode 100644 index 000000000..e85c1af88 --- /dev/null +++ b/doc-auto-gen/pom.xml @@ -0,0 +1,32 @@ + + 4.0.0 + + org.apache.dubbo.extensions + extensions-parent + ${revision} + ../pom.xml + + + 1.0.1-SNAPSHOT + Dubbo interface documentation, testing tools + + doc-auto-gen + jar + + doc-auto-gen + http://maven.apache.org + + + UTF-8 + + + + + junit + junit + 3.8.1 + test + + + diff --git a/doc-auto-gen/src/main/java/org/apache/dubbo/doc/DocAutoGen.java b/doc-auto-gen/src/main/java/org/apache/dubbo/doc/DocAutoGen.java new file mode 100644 index 000000000..c1c3baf44 --- /dev/null +++ b/doc-auto-gen/src/main/java/org/apache/dubbo/doc/DocAutoGen.java @@ -0,0 +1,48 @@ +package org.apache.dubbo.doc; + +import java.io.*; +import java.util.Arrays; + +public class DocAutoGen { + public static void main(String[] args) throws IOException { + String filePath = System.getProperty("user.dir"); + File file = new File(filePath); + int level = 0; + String parentPath = ""; + System.setOut(new PrintStream(filePath + "/" + "README.md")); + System.out.println("# dubbo-spi-extensions"); + System.out.println("[![Build Status](https://travis-ci.org/apache/dubbo-spi-extensions.svg?branch=master)](https://travis-ci.org/apache/dubbo-spi-extensions)\n" + + "[![codecov](https://codecov.io/gh/apache/dubbo-spi-extensions/branch/master/graph/badge.svg)](https://codecov.io/gh/apache/dubbo-spi-extensions)\n" + + "[![Maven Central](https://img.shields.io/maven-central/v/org.apache.dubbo/dubbo-spi-extensions.svg)](https://search.maven.org/search?q=g:org.apache.dubbo%20AND%20a:dubbo-spi-extensions)\n" + + "[![GitHub release](https://img.shields.io/github/release/apache/dubbo-spi-extensions.svg)]"); + visitFile(file, parentPath, level); + } + + private static void visitFile(File file, String parentPath, int level) { + File[] files = file.listFiles(); + // gen code sort by file name + Arrays.sort(files, (o1, o2) -> { + if (o1.isDirectory() && o2.isFile()) { + return -1; + } + if (o1.isFile() && o2.isDirectory()) { + return 1; + } + return o1.getName().compareTo(o2.getName()); + }); + for (int i = 0; i < files.length; i++) { + File f = files[i]; + String name = f.getName(); + if (name.startsWith("dubbo-")) { + String blank = ""; + for (int j = 0; j < level; j++) { + blank += " "; + } + + String currentPath = level == 0 ? name : parentPath + "/" + name; + System.out.println(blank + "- [" + currentPath + "]" + "(" + name + ")"); + visitFile(f, currentPath, level + 1); + } + } + } +} diff --git a/doc-auto-gen/src/test/java/org/example/AppTest.java b/doc-auto-gen/src/test/java/org/example/AppTest.java new file mode 100644 index 000000000..d5f435df0 --- /dev/null +++ b/doc-auto-gen/src/test/java/org/example/AppTest.java @@ -0,0 +1,38 @@ +package org.example; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +} diff --git a/pom.xml b/pom.xml index 78b132351..d45ce02a1 100644 --- a/pom.xml +++ b/pom.xml @@ -97,6 +97,7 @@ dubbo-gateway-extensions dubbo-cross-thread-extensions dubbo-tag-extensions + doc-auto-gen From d6c143a92299c30efb6291761de18eca6b982849 Mon Sep 17 00:00:00 2001 From: songxiaosheng Date: Sun, 1 Oct 2023 10:18:32 +0800 Subject: [PATCH 26/35] :memo: visit code tree to gen doc --- doc-auto-gen/pom.xml | 16 ++++++++ .../java/org/apache/dubbo/doc/DocAutoGen.java | 16 ++++++++ .../src/test/java/org/example/AppTest.java | 38 ------------------- 3 files changed, 32 insertions(+), 38 deletions(-) delete mode 100644 doc-auto-gen/src/test/java/org/example/AppTest.java diff --git a/doc-auto-gen/pom.xml b/doc-auto-gen/pom.xml index e85c1af88..17ebf6b9e 100644 --- a/doc-auto-gen/pom.xml +++ b/doc-auto-gen/pom.xml @@ -1,3 +1,19 @@ + 4.0.0 diff --git a/doc-auto-gen/src/main/java/org/apache/dubbo/doc/DocAutoGen.java b/doc-auto-gen/src/main/java/org/apache/dubbo/doc/DocAutoGen.java index c1c3baf44..6d16db550 100644 --- a/doc-auto-gen/src/main/java/org/apache/dubbo/doc/DocAutoGen.java +++ b/doc-auto-gen/src/main/java/org/apache/dubbo/doc/DocAutoGen.java @@ -1,3 +1,19 @@ +/* + * 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 org.apache.dubbo.doc; import java.io.*; diff --git a/doc-auto-gen/src/test/java/org/example/AppTest.java b/doc-auto-gen/src/test/java/org/example/AppTest.java deleted file mode 100644 index d5f435df0..000000000 --- a/doc-auto-gen/src/test/java/org/example/AppTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.example; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -/** - * Unit test for simple App. - */ -public class AppTest - extends TestCase -{ - /** - * Create the test case - * - * @param testName name of the test case - */ - public AppTest( String testName ) - { - super( testName ); - } - - /** - * @return the suite of tests being tested - */ - public static Test suite() - { - return new TestSuite( AppTest.class ); - } - - /** - * Rigourous Test :-) - */ - public void testApp() - { - assertTrue( true ); - } -} From f55e2eff97310154e47be26417b2ef6afce244c1 Mon Sep 17 00:00:00 2001 From: songxiaosheng Date: Sun, 1 Oct 2023 10:34:02 +0800 Subject: [PATCH 27/35] :memo: visit code tree to gen doc --- {doc-auto-gen => dobbo-doc-auto-gen}/pom.xml | 2 +- .../src/main/java/org/apache/dubbo/doc/DocAutoGen.java | 0 pom.xml | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename {doc-auto-gen => dobbo-doc-auto-gen}/pom.xml (97%) rename {doc-auto-gen => dobbo-doc-auto-gen}/src/main/java/org/apache/dubbo/doc/DocAutoGen.java (100%) diff --git a/doc-auto-gen/pom.xml b/dobbo-doc-auto-gen/pom.xml similarity index 97% rename from doc-auto-gen/pom.xml rename to dobbo-doc-auto-gen/pom.xml index 17ebf6b9e..f00250d3f 100644 --- a/doc-auto-gen/pom.xml +++ b/dobbo-doc-auto-gen/pom.xml @@ -27,7 +27,7 @@ 1.0.1-SNAPSHOT Dubbo interface documentation, testing tools - doc-auto-gen + dobbo-doc-auto-gen jar doc-auto-gen diff --git a/doc-auto-gen/src/main/java/org/apache/dubbo/doc/DocAutoGen.java b/dobbo-doc-auto-gen/src/main/java/org/apache/dubbo/doc/DocAutoGen.java similarity index 100% rename from doc-auto-gen/src/main/java/org/apache/dubbo/doc/DocAutoGen.java rename to dobbo-doc-auto-gen/src/main/java/org/apache/dubbo/doc/DocAutoGen.java diff --git a/pom.xml b/pom.xml index d45ce02a1..a31ba28c1 100644 --- a/pom.xml +++ b/pom.xml @@ -97,7 +97,7 @@ dubbo-gateway-extensions dubbo-cross-thread-extensions dubbo-tag-extensions - doc-auto-gen + dobbo-doc-auto-gen From 499f6deafa313e48712db772267fc26896d323f0 Mon Sep 17 00:00:00 2001 From: songxiaosheng Date: Sun, 1 Oct 2023 11:10:24 +0800 Subject: [PATCH 28/35] :memo: visit code tree to gen doc --- .../src/main/java/org/apache/dubbo/doc/DocAutoGen.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dobbo-doc-auto-gen/src/main/java/org/apache/dubbo/doc/DocAutoGen.java b/dobbo-doc-auto-gen/src/main/java/org/apache/dubbo/doc/DocAutoGen.java index 6d16db550..2a68cc6f7 100644 --- a/dobbo-doc-auto-gen/src/main/java/org/apache/dubbo/doc/DocAutoGen.java +++ b/dobbo-doc-auto-gen/src/main/java/org/apache/dubbo/doc/DocAutoGen.java @@ -16,7 +16,9 @@ */ package org.apache.dubbo.doc; -import java.io.*; +import java.io.File; +import java.io.IOException; +import java.io.PrintStream; import java.util.Arrays; public class DocAutoGen { From cb5d5677b7f4443e5d53555e71d8516b2fc686a9 Mon Sep 17 00:00:00 2001 From: songxiaosheng Date: Wed, 11 Oct 2023 21:57:25 +0800 Subject: [PATCH 29/35] :memo: visit code tree to gen doc --- README.md | 112 +++++++++--------- .../java/org/apache/dubbo/doc/DocAutoGen.java | 2 +- 2 files changed, 57 insertions(+), 57 deletions(-) diff --git a/README.md b/README.md index b2e82ce92..7da9ec4bb 100644 --- a/README.md +++ b/README.md @@ -4,74 +4,74 @@ [![Maven Central](https://img.shields.io/maven-central/v/org.apache.dubbo/dubbo-spi-extensions.svg)](https://search.maven.org/search?q=g:org.apache.dubbo%20AND%20a:dubbo-spi-extensions) [![GitHub release](https://img.shields.io/github/release/apache/dubbo-spi-extensions.svg)] - [dubbo-api-docs](dubbo-api-docs) - - [dubbo-api-docs/dubbo-api-docs-annotations](dubbo-api-docs-annotations) - - [dubbo-api-docs/dubbo-api-docs-core](dubbo-api-docs-core) - - [dubbo-api-docs/dubbo-api-docs-examples](dubbo-api-docs-examples) + - [dubbo-api-docs-annotations](dubbo-api-docs/dubbo-api-docs-annotations) + - [dubbo-api-docs-core](dubbo-api-docs/dubbo-api-docs-core) + - [dubbo-api-docs-examples](dubbo-api-docs/dubbo-api-docs-examples) - [dubbo-cluster-extensions](dubbo-cluster-extensions) - - [dubbo-cluster-extensions/dubbo-cluster-broadcast-1](dubbo-cluster-broadcast-1) - - [dubbo-cluster-extensions/dubbo-cluster-loadbalance-peakewma](dubbo-cluster-loadbalance-peakewma) - - [dubbo-cluster-extensions/dubbo-cluster-polaris-dubbo2](dubbo-cluster-polaris-dubbo2) - - [dubbo-cluster-extensions/dubbo-cluster-specify-address-common](dubbo-cluster-specify-address-common) - - [dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2](dubbo-cluster-specify-address-dubbo2) - - [dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3](dubbo-cluster-specify-address-dubbo3) + - [dubbo-cluster-broadcast-1](dubbo-cluster-extensions/dubbo-cluster-broadcast-1) + - [dubbo-cluster-loadbalance-peakewma](dubbo-cluster-extensions/dubbo-cluster-loadbalance-peakewma) + - [dubbo-cluster-polaris-dubbo2](dubbo-cluster-extensions/dubbo-cluster-polaris-dubbo2) + - [dubbo-cluster-specify-address-common](dubbo-cluster-extensions/dubbo-cluster-specify-address-common) + - [dubbo-cluster-specify-address-dubbo2](dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2) + - [dubbo-cluster-specify-address-dubbo3](dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3) - [dubbo-common-extensions](dubbo-common-extensions) - [dubbo-configcenter-extensions](dubbo-configcenter-extensions) - - [dubbo-configcenter-extensions/dubbo-configcenter-consul](dubbo-configcenter-consul) - - [dubbo-configcenter-extensions/dubbo-configcenter-etcd](dubbo-configcenter-etcd) + - [dubbo-configcenter-consul](dubbo-configcenter-extensions/dubbo-configcenter-consul) + - [dubbo-configcenter-etcd](dubbo-configcenter-extensions/dubbo-configcenter-etcd) - [dubbo-cross-thread-extensions](dubbo-cross-thread-extensions) - [dubbo-extensions-dependencies-bom](dubbo-extensions-dependencies-bom) - [dubbo-extensions-distribution](dubbo-extensions-distribution) - - [dubbo-extensions-distribution/dubbo-apache-release](dubbo-apache-release) - - [dubbo-extensions-distribution/dubbo-bom](dubbo-bom) + - [dubbo-apache-release](dubbo-extensions-distribution/dubbo-apache-release) + - [dubbo-bom](dubbo-extensions-distribution/dubbo-bom) - [dubbo-filter-extensions](dubbo-filter-extensions) - - [dubbo-filter-extensions/dubbo-filter-polaris-dubbo2](dubbo-filter-polaris-dubbo2) - - [dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-circuitbreaker-dubbo2](dubbo-filter-polaris-circuitbreaker-dubbo2) - - [dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-ratelimit-dubbo2](dubbo-filter-polaris-ratelimit-dubbo2) - - [dubbo-filter-extensions/dubbo-filter-seata](dubbo-filter-seata) + - [dubbo-filter-polaris-dubbo2](dubbo-filter-extensions/dubbo-filter-polaris-dubbo2) + - [dubbo-filter-polaris-circuitbreaker-dubbo2](dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-circuitbreaker-dubbo2) + - [dubbo-filter-polaris-ratelimit-dubbo2](dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-ratelimit-dubbo2) + - [dubbo-filter-seata](dubbo-filter-extensions/dubbo-filter-seata) - [dubbo-gateway-extensions](dubbo-gateway-extensions) - - [dubbo-gateway-extensions/dubbo-gateway-common](dubbo-gateway-common) - - [dubbo-gateway-extensions/dubbo-gateway-consumer](dubbo-gateway-consumer) - - [dubbo-gateway-extensions/dubbo-gateway-provider](dubbo-gateway-provider) + - [dubbo-gateway-common](dubbo-gateway-extensions/dubbo-gateway-common) + - [dubbo-gateway-consumer](dubbo-gateway-extensions/dubbo-gateway-consumer) + - [dubbo-gateway-provider](dubbo-gateway-extensions/dubbo-gateway-provider) - [dubbo-metadata-report-extensions](dubbo-metadata-report-extensions) - - [dubbo-metadata-report-extensions/dubbo-metadata-report-consul](dubbo-metadata-report-consul) - - [dubbo-metadata-report-extensions/dubbo-metadata-report-etcd](dubbo-metadata-report-etcd) + - [dubbo-metadata-report-consul](dubbo-metadata-report-extensions/dubbo-metadata-report-consul) + - [dubbo-metadata-report-etcd](dubbo-metadata-report-extensions/dubbo-metadata-report-etcd) - [dubbo-mock-extensions](dubbo-mock-extensions) - - [dubbo-mock-extensions/dubbo-mock-admin](dubbo-mock-admin) - - [dubbo-mock-extensions/dubbo-mock-api](dubbo-mock-api) + - [dubbo-mock-admin](dubbo-mock-extensions/dubbo-mock-admin) + - [dubbo-mock-api](dubbo-mock-extensions/dubbo-mock-api) - [dubbo-registry-extensions](dubbo-registry-extensions) - - [dubbo-registry-extensions/dubbo-registry-consul](dubbo-registry-consul) - - [dubbo-registry-extensions/dubbo-registry-dns](dubbo-registry-dns) - - [dubbo-registry-extensions/dubbo-registry-etcd3](dubbo-registry-etcd3) - - [dubbo-registry-extensions/dubbo-registry-nameservice](dubbo-registry-nameservice) - - [dubbo-registry-extensions/dubbo-registry-polaris](dubbo-registry-polaris) - - [dubbo-registry-extensions/dubbo-registry-redis](dubbo-registry-redis) - - [dubbo-registry-extensions/dubbo-registry-sofa](dubbo-registry-sofa) + - [dubbo-registry-consul](dubbo-registry-extensions/dubbo-registry-consul) + - [dubbo-registry-dns](dubbo-registry-extensions/dubbo-registry-dns) + - [dubbo-registry-etcd3](dubbo-registry-extensions/dubbo-registry-etcd3) + - [dubbo-registry-nameservice](dubbo-registry-extensions/dubbo-registry-nameservice) + - [dubbo-registry-polaris](dubbo-registry-extensions/dubbo-registry-polaris) + - [dubbo-registry-redis](dubbo-registry-extensions/dubbo-registry-redis) + - [dubbo-registry-sofa](dubbo-registry-extensions/dubbo-registry-sofa) - [dubbo-remoting-extensions](dubbo-remoting-extensions) - - [dubbo-remoting-extensions/dubbo-remoting-etcd3](dubbo-remoting-etcd3) - - [dubbo-remoting-extensions/dubbo-remoting-grizzly](dubbo-remoting-grizzly) - - [dubbo-remoting-extensions/dubbo-remoting-mina](dubbo-remoting-mina) - - [dubbo-remoting-extensions/dubbo-remoting-p2p](dubbo-remoting-p2p) - - [dubbo-remoting-extensions/dubbo-remoting-quic](dubbo-remoting-quic) - - [dubbo-remoting-extensions/dubbo-remoting-redis](dubbo-remoting-redis) + - [dubbo-remoting-etcd3](dubbo-remoting-extensions/dubbo-remoting-etcd3) + - [dubbo-remoting-grizzly](dubbo-remoting-extensions/dubbo-remoting-grizzly) + - [dubbo-remoting-mina](dubbo-remoting-extensions/dubbo-remoting-mina) + - [dubbo-remoting-p2p](dubbo-remoting-extensions/dubbo-remoting-p2p) + - [dubbo-remoting-quic](dubbo-remoting-extensions/dubbo-remoting-quic) + - [dubbo-remoting-redis](dubbo-remoting-extensions/dubbo-remoting-redis) - [dubbo-rpc-extensions](dubbo-rpc-extensions) - - [dubbo-rpc-extensions/dubbo-rpc-hessian](dubbo-rpc-hessian) - - [dubbo-rpc-extensions/dubbo-rpc-http](dubbo-rpc-http) - - [dubbo-rpc-extensions/dubbo-rpc-memcached](dubbo-rpc-memcached) - - [dubbo-rpc-extensions/dubbo-rpc-native-thrift](dubbo-rpc-native-thrift) - - [dubbo-rpc-extensions/dubbo-rpc-redis](dubbo-rpc-redis) - - [dubbo-rpc-extensions/dubbo-rpc-rmi](dubbo-rpc-rmi) - - [dubbo-rpc-extensions/dubbo-rpc-rocketmq](dubbo-rpc-rocketmq) - - [dubbo-rpc-extensions/dubbo-rpc-webservice](dubbo-rpc-webservice) + - [dubbo-rpc-hessian](dubbo-rpc-extensions/dubbo-rpc-hessian) + - [dubbo-rpc-http](dubbo-rpc-extensions/dubbo-rpc-http) + - [dubbo-rpc-memcached](dubbo-rpc-extensions/dubbo-rpc-memcached) + - [dubbo-rpc-native-thrift](dubbo-rpc-extensions/dubbo-rpc-native-thrift) + - [dubbo-rpc-redis](dubbo-rpc-extensions/dubbo-rpc-redis) + - [dubbo-rpc-rmi](dubbo-rpc-extensions/dubbo-rpc-rmi) + - [dubbo-rpc-rocketmq](dubbo-rpc-extensions/dubbo-rpc-rocketmq) + - [dubbo-rpc-webservice](dubbo-rpc-extensions/dubbo-rpc-webservice) - [dubbo-serialization-extensions](dubbo-serialization-extensions) - - [dubbo-serialization-extensions/dubbo-serialization-avro](dubbo-serialization-avro) - - [dubbo-serialization-extensions/dubbo-serialization-fastjson](dubbo-serialization-fastjson) - - [dubbo-serialization-extensions/dubbo-serialization-fst](dubbo-serialization-fst) - - [dubbo-serialization-extensions/dubbo-serialization-gson](dubbo-serialization-gson) - - [dubbo-serialization-extensions/dubbo-serialization-kryo](dubbo-serialization-kryo) - - [dubbo-serialization-extensions/dubbo-serialization-msgpack](dubbo-serialization-msgpack) - - [dubbo-serialization-extensions/dubbo-serialization-native-hession](dubbo-serialization-native-hession) - - [dubbo-serialization-extensions/dubbo-serialization-protobuf](dubbo-serialization-protobuf) - - [dubbo-serialization-extensions/dubbo-serialization-protostuff](dubbo-serialization-protostuff) - - [dubbo-serialization-extensions/dubbo-serialization-test](dubbo-serialization-test) + - [dubbo-serialization-avro](dubbo-serialization-extensions/dubbo-serialization-avro) + - [dubbo-serialization-fastjson](dubbo-serialization-extensions/dubbo-serialization-fastjson) + - [dubbo-serialization-fst](dubbo-serialization-extensions/dubbo-serialization-fst) + - [dubbo-serialization-gson](dubbo-serialization-extensions/dubbo-serialization-gson) + - [dubbo-serialization-kryo](dubbo-serialization-extensions/dubbo-serialization-kryo) + - [dubbo-serialization-msgpack](dubbo-serialization-extensions/dubbo-serialization-msgpack) + - [dubbo-serialization-native-hession](dubbo-serialization-extensions/dubbo-serialization-native-hession) + - [dubbo-serialization-protobuf](dubbo-serialization-extensions/dubbo-serialization-protobuf) + - [dubbo-serialization-protostuff](dubbo-serialization-extensions/dubbo-serialization-protostuff) + - [dubbo-serialization-test](dubbo-serialization-extensions/dubbo-serialization-test) - [dubbo-tag-extensions](dubbo-tag-extensions) - - [dubbo-tag-extensions/dubbo-tag-subnets](dubbo-tag-subnets) + - [dubbo-tag-subnets](dubbo-tag-extensions/dubbo-tag-subnets) diff --git a/dobbo-doc-auto-gen/src/main/java/org/apache/dubbo/doc/DocAutoGen.java b/dobbo-doc-auto-gen/src/main/java/org/apache/dubbo/doc/DocAutoGen.java index 2a68cc6f7..9d4f715dc 100644 --- a/dobbo-doc-auto-gen/src/main/java/org/apache/dubbo/doc/DocAutoGen.java +++ b/dobbo-doc-auto-gen/src/main/java/org/apache/dubbo/doc/DocAutoGen.java @@ -58,7 +58,7 @@ private static void visitFile(File file, String parentPath, int level) { } String currentPath = level == 0 ? name : parentPath + "/" + name; - System.out.println(blank + "- [" + currentPath + "]" + "(" + name + ")"); + System.out.println(blank + "- [" + name + "]" + "(" + currentPath+ ")"); visitFile(f, currentPath, level + 1); } } From b7d4fd4c8be7ae148630bc3eb58c652770a39264 Mon Sep 17 00:00:00 2001 From: Shawn Date: Tue, 17 Oct 2023 17:02:37 +0800 Subject: [PATCH 30/35] [Serialization] add fury serialization framework to dubbo (#226) * add fury serialization framework * add license header * fix readEvent interface * override dubbo version in fury module --------- Co-authored-by: mubai --- dubbo-extensions-dependencies-bom/pom.xml | 6 + .../dubbo-serialization-fury/pom.xml | 56 ++++++++ .../fury/dubbo/BaseFurySerialization.java | 68 ++++++++++ .../fury/dubbo/FuryCheckerListener.java | 92 +++++++++++++ .../dubbo/FuryCompatibleSerialization.java | 62 +++++++++ .../serialize/fury/dubbo/FuryObjectInput.java | 123 ++++++++++++++++++ .../fury/dubbo/FuryObjectOutput.java | 108 +++++++++++++++ .../fury/dubbo/FuryScopeModelInitializer.java | 38 ++++++ .../fury/dubbo/FurySerialization.java | 61 +++++++++ ...pache.dubbo.common.serialize.Serialization | 2 + ...ache.dubbo.rpc.model.ScopeModelInitializer | 2 + .../kryo/optimized/KryoObjectInput2.java | 2 +- .../GenericProtobufJsonObjectInput.java | 2 +- .../support/GenericProtobufObjectInput.java | 2 +- dubbo-serialization-extensions/pom.xml | 1 + 15 files changed, 622 insertions(+), 3 deletions(-) create mode 100644 dubbo-serialization-extensions/dubbo-serialization-fury/pom.xml create mode 100644 dubbo-serialization-extensions/dubbo-serialization-fury/src/main/java/org/apache/dubbo/common/serialize/fury/dubbo/BaseFurySerialization.java create mode 100644 dubbo-serialization-extensions/dubbo-serialization-fury/src/main/java/org/apache/dubbo/common/serialize/fury/dubbo/FuryCheckerListener.java create mode 100644 dubbo-serialization-extensions/dubbo-serialization-fury/src/main/java/org/apache/dubbo/common/serialize/fury/dubbo/FuryCompatibleSerialization.java create mode 100644 dubbo-serialization-extensions/dubbo-serialization-fury/src/main/java/org/apache/dubbo/common/serialize/fury/dubbo/FuryObjectInput.java create mode 100644 dubbo-serialization-extensions/dubbo-serialization-fury/src/main/java/org/apache/dubbo/common/serialize/fury/dubbo/FuryObjectOutput.java create mode 100644 dubbo-serialization-extensions/dubbo-serialization-fury/src/main/java/org/apache/dubbo/common/serialize/fury/dubbo/FuryScopeModelInitializer.java create mode 100644 dubbo-serialization-extensions/dubbo-serialization-fury/src/main/java/org/apache/dubbo/common/serialize/fury/dubbo/FurySerialization.java create mode 100644 dubbo-serialization-extensions/dubbo-serialization-fury/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.serialize.Serialization create mode 100644 dubbo-serialization-extensions/dubbo-serialization-fury/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.model.ScopeModelInitializer diff --git a/dubbo-extensions-dependencies-bom/pom.xml b/dubbo-extensions-dependencies-bom/pom.xml index 94c1a5bf1..7d640d9d7 100644 --- a/dubbo-extensions-dependencies-bom/pom.xml +++ b/dubbo-extensions-dependencies-bom/pom.xml @@ -111,6 +111,7 @@ 1.8.2 1.2.83 2.48-jdk-6 + 0.2.0 2.8.9 5.4.0 0.45 @@ -298,6 +299,11 @@ fst ${fst_version} + + org.furyio + fury-core + ${fury_version} + com.google.code.gson gson diff --git a/dubbo-serialization-extensions/dubbo-serialization-fury/pom.xml b/dubbo-serialization-extensions/dubbo-serialization-fury/pom.xml new file mode 100644 index 000000000..fb7b98d61 --- /dev/null +++ b/dubbo-serialization-extensions/dubbo-serialization-fury/pom.xml @@ -0,0 +1,56 @@ + + + + 4.0.0 + + org.apache.dubbo.extensions + dubbo-serialization-extensions + ${revision} + ../pom.xml + + + dubbo-serialization-fury + + + 17 + 17 + UTF-8 + 3.2.1 + + + + + org.apache.dubbo + dubbo-serialization-api + ${dubbo.version} + true + + + org.apache.dubbo + dubbo + ${dubbo.version} + true + + + org.furyio + fury-core + + + diff --git a/dubbo-serialization-extensions/dubbo-serialization-fury/src/main/java/org/apache/dubbo/common/serialize/fury/dubbo/BaseFurySerialization.java b/dubbo-serialization-extensions/dubbo-serialization-fury/src/main/java/org/apache/dubbo/common/serialize/fury/dubbo/BaseFurySerialization.java new file mode 100644 index 000000000..2b1243a89 --- /dev/null +++ b/dubbo-serialization-extensions/dubbo-serialization-fury/src/main/java/org/apache/dubbo/common/serialize/fury/dubbo/BaseFurySerialization.java @@ -0,0 +1,68 @@ +/* + * 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 org.apache.dubbo.common.serialize.fury.dubbo; + +import io.fury.Fury; +import io.fury.collection.Tuple2; +import io.fury.memory.MemoryBuffer; +import io.fury.util.LoaderBinding; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.Optional; +import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.serialize.ObjectInput; +import org.apache.dubbo.common.serialize.ObjectOutput; +import org.apache.dubbo.common.serialize.Serialization; +import org.apache.dubbo.rpc.model.FrameworkModel; + +/** + * Fury serialization framework integration with dubbo. + * + * @author chaokunyang + */ +public abstract class BaseFurySerialization implements Serialization { + protected abstract Tuple2 getFury(); + + public ObjectOutput serialize(URL url, OutputStream output) throws IOException { + Tuple2 tuple2 = getFury(); + tuple2.f0.setClassLoader(Thread.currentThread().getContextClassLoader()); + Fury fury = tuple2.f0.get(); + FuryCheckerListener checkerListener = getCheckerListener(url); + fury.getClassResolver().setClassChecker(checkerListener.getChecker()); + fury.getClassResolver().setSerializerFactory(checkerListener); + return new FuryObjectOutput(fury, tuple2.f1, output); + } + + public ObjectInput deserialize(URL url, InputStream input) throws IOException { + Tuple2 tuple2 = getFury(); + tuple2.f0.setClassLoader(Thread.currentThread().getContextClassLoader()); + Fury fury = tuple2.f0.get(); + FuryCheckerListener checkerListener = getCheckerListener(url); + fury.getClassResolver().setClassChecker(checkerListener.getChecker()); + return new FuryObjectInput(fury, tuple2.f1, input); + } + + private static FuryCheckerListener getCheckerListener(URL url) { + return Optional.ofNullable(url) + .map(URL::getOrDefaultFrameworkModel) + .orElseGet(FrameworkModel::defaultModel) + .getBeanFactory() + .getBean(FuryCheckerListener.class); + } +} diff --git a/dubbo-serialization-extensions/dubbo-serialization-fury/src/main/java/org/apache/dubbo/common/serialize/fury/dubbo/FuryCheckerListener.java b/dubbo-serialization-extensions/dubbo-serialization-fury/src/main/java/org/apache/dubbo/common/serialize/fury/dubbo/FuryCheckerListener.java new file mode 100644 index 000000000..18100e204 --- /dev/null +++ b/dubbo-serialization-extensions/dubbo-serialization-fury/src/main/java/org/apache/dubbo/common/serialize/fury/dubbo/FuryCheckerListener.java @@ -0,0 +1,92 @@ +/* + * 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 org.apache.dubbo.common.serialize.fury.dubbo; + +import io.fury.Fury; +import io.fury.exception.InsecureException; +import io.fury.resolver.AllowListChecker; +import io.fury.serializer.Serializer; +import io.fury.serializer.SerializerFactory; +import java.io.Serializable; +import java.util.Set; +import org.apache.dubbo.common.utils.AllowClassNotifyListener; +import org.apache.dubbo.common.utils.SerializeCheckStatus; +import org.apache.dubbo.common.utils.SerializeSecurityManager; +import org.apache.dubbo.rpc.model.FrameworkModel; + +@SuppressWarnings("rawtypes") +public class FuryCheckerListener implements AllowClassNotifyListener, SerializerFactory { + private final SerializeSecurityManager securityManager; + private final AllowListChecker checker; + private volatile boolean checkSerializable; + + public FuryCheckerListener(FrameworkModel frameworkModel) { + checker = new AllowListChecker(); + securityManager = + frameworkModel.getBeanFactory().getOrRegisterBean(SerializeSecurityManager.class); + securityManager.registerListener(this); + } + + @Override + public void notifyPrefix(Set allowedList, Set disAllowedList) { + for (String prefix : allowedList) { + checker.allowClass(prefix); + } + for (String prefix : disAllowedList) { + checker.disallowClass(prefix); + } + } + + @Override + public void notifyCheckStatus(SerializeCheckStatus status) { + switch (status) { + case DISABLE: + checker.setCheckLevel(AllowListChecker.CheckLevel.DISABLE); + return; + case WARN: + checker.setCheckLevel(AllowListChecker.CheckLevel.WARN); + return; + case STRICT: + checker.setCheckLevel(AllowListChecker.CheckLevel.STRICT); + return; + default: + throw new UnsupportedOperationException("Unsupported check level " + status); + } + } + + @Override + public void notifyCheckSerializable(boolean checkSerializable) { + this.checkSerializable = checkSerializable; + } + + public AllowListChecker getChecker() { + return checker; + } + + public boolean isCheckSerializable() { + return checkSerializable; + } + + @Override + public Serializer createSerializer(Fury fury, Class cls) { + if (checkSerializable && !Serializable.class.isAssignableFrom(cls)) { + throw new InsecureException(String.format("%s is not Serializable", cls)); + } + return null; + } +} diff --git a/dubbo-serialization-extensions/dubbo-serialization-fury/src/main/java/org/apache/dubbo/common/serialize/fury/dubbo/FuryCompatibleSerialization.java b/dubbo-serialization-extensions/dubbo-serialization-fury/src/main/java/org/apache/dubbo/common/serialize/fury/dubbo/FuryCompatibleSerialization.java new file mode 100644 index 000000000..b853e43dd --- /dev/null +++ b/dubbo-serialization-extensions/dubbo-serialization-fury/src/main/java/org/apache/dubbo/common/serialize/fury/dubbo/FuryCompatibleSerialization.java @@ -0,0 +1,62 @@ +/* + * 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 org.apache.dubbo.common.serialize.fury.dubbo; + +import io.fury.Fury; +import io.fury.collection.Tuple2; +import io.fury.config.CompatibleMode; +import io.fury.memory.MemoryBuffer; +import io.fury.memory.MemoryUtils; +import io.fury.util.LoaderBinding; + +/** + * Fury serialization for dubbo. This integration support type forward/backward compatibility. + * + * @author chaokunyang + */ +public class FuryCompatibleSerialization extends BaseFurySerialization { + public static final byte FURY_SERIALIZATION_ID = 29; + private static final ThreadLocal> furyFactory = + ThreadLocal.withInitial( + () -> { + LoaderBinding binding = + new LoaderBinding( + classLoader -> + Fury.builder() + .withRefTracking(true) + .requireClassRegistration(false) + .withCompatibleMode(CompatibleMode.COMPATIBLE) + .withClassLoader(classLoader) + .build()); + MemoryBuffer buffer = MemoryUtils.buffer(32); + return Tuple2.of(binding, buffer); + }); + + public byte getContentTypeId() { + return FURY_SERIALIZATION_ID; + } + + public String getContentType() { + return "fury/compatible"; + } + + @Override + protected Tuple2 getFury() { + return furyFactory.get(); + } +} diff --git a/dubbo-serialization-extensions/dubbo-serialization-fury/src/main/java/org/apache/dubbo/common/serialize/fury/dubbo/FuryObjectInput.java b/dubbo-serialization-extensions/dubbo-serialization-fury/src/main/java/org/apache/dubbo/common/serialize/fury/dubbo/FuryObjectInput.java new file mode 100644 index 000000000..3f3971eb9 --- /dev/null +++ b/dubbo-serialization-extensions/dubbo-serialization-fury/src/main/java/org/apache/dubbo/common/serialize/fury/dubbo/FuryObjectInput.java @@ -0,0 +1,123 @@ +/* + * 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 org.apache.dubbo.common.serialize.fury.dubbo; + +import io.fury.Fury; +import io.fury.memory.MemoryBuffer; +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.Type; +import org.apache.dubbo.common.serialize.ObjectInput; + +@SuppressWarnings("unchecked") +public class FuryObjectInput implements ObjectInput { + private final Fury fury; + private final MemoryBuffer buffer; + private final InputStream input; + + public FuryObjectInput(Fury fury, MemoryBuffer buffer, InputStream input) { + this.fury = fury; + this.buffer = buffer; + this.input = input; + } + + @Override + public Object readObject() { + return fury.deserializeJavaObjectAndClass(input); + } + + @Override + public T readObject(Class cls) { + return (T) readObject(); + } + + @Override + public T readObject(Class cls, Type type) { + return (T) readObject(); + } + + @Override + public boolean readBool() throws IOException { + readBytes(buffer.getHeapMemory(), 1); + return buffer.getBoolean(0); + } + + @Override + public byte readByte() throws IOException { + readBytes(buffer.getHeapMemory(), 1); + return buffer.get(0); + } + + @Override + public short readShort() throws IOException { + readBytes(buffer.getHeapMemory(), 2); + return buffer.getShort(0); + } + + @Override + public int readInt() throws IOException { + readBytes(buffer.getHeapMemory(), 4); + return buffer.getInt(0); + } + + @Override + public long readLong() throws IOException { + readBytes(buffer.getHeapMemory(), 8); + return buffer.getLong(0); + } + + @Override + public float readFloat() throws IOException { + readBytes(buffer.getHeapMemory(), 4); + return buffer.getFloat(0); + } + + @Override + public double readDouble() throws IOException { + readBytes(buffer.getHeapMemory(), 8); + return buffer.getDouble(0); + } + + @Override + public String readUTF() throws IOException { + int size = readInt(); + buffer.readerIndex(0); + buffer.ensure(size); + readBytes(buffer.getHeapMemory(), size); + if (buffer.readBoolean()) { + return fury.readJavaString(buffer); + } else { + return null; + } + } + + @Override + public byte[] readBytes() throws IOException { + int size = readInt(); + byte[] bytes = new byte[size]; + readBytes(bytes, size); + return bytes; + } + + private void readBytes(byte[] bytes, int size) throws IOException { + int off = 0; + while (off != size) { + off += input.read(bytes, off, size - off); + } + } +} diff --git a/dubbo-serialization-extensions/dubbo-serialization-fury/src/main/java/org/apache/dubbo/common/serialize/fury/dubbo/FuryObjectOutput.java b/dubbo-serialization-extensions/dubbo-serialization-fury/src/main/java/org/apache/dubbo/common/serialize/fury/dubbo/FuryObjectOutput.java new file mode 100644 index 000000000..ac9789936 --- /dev/null +++ b/dubbo-serialization-extensions/dubbo-serialization-fury/src/main/java/org/apache/dubbo/common/serialize/fury/dubbo/FuryObjectOutput.java @@ -0,0 +1,108 @@ +/* + * 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 org.apache.dubbo.common.serialize.fury.dubbo; + +import io.fury.Fury; +import io.fury.memory.MemoryBuffer; +import java.io.IOException; +import java.io.OutputStream; +import org.apache.dubbo.common.serialize.ObjectOutput; + +/** + * Fury implementation for {@link ObjectOutput}. + * + * @author chaokunyang + */ +public class FuryObjectOutput implements ObjectOutput { + private final Fury fury; + private final MemoryBuffer buffer; + private final OutputStream output; + + public FuryObjectOutput(Fury fury, MemoryBuffer buffer, OutputStream output) { + this.fury = fury; + this.buffer = buffer; + this.output = output; + } + + public void writeObject(Object obj) { + fury.serializeJavaObjectAndClass(output, obj); + } + + public void writeBool(boolean v) throws IOException { + buffer.unsafePutBoolean(0, v); + output.write(buffer.getHeapMemory(), 0, 1); + } + + public void writeByte(byte v) throws IOException { + buffer.unsafePut(0, v); + output.write(buffer.getHeapMemory(), 0, 1); + } + + public void writeShort(short v) throws IOException { + buffer.unsafePutShort(0, v); + output.write(buffer.getHeapMemory(), 0, 2); + } + + public void writeInt(int v) throws IOException { + buffer.unsafePutInt(0, v); + output.write(buffer.getHeapMemory(), 0, 4); + } + + public void writeLong(long v) throws IOException { + buffer.unsafePutLong(0, v); + output.write(buffer.getHeapMemory(), 0, 8); + } + + public void writeFloat(float v) throws IOException { + buffer.unsafePutFloat(0, v); + output.write(buffer.getHeapMemory(), 0, 4); + } + + public void writeDouble(double v) throws IOException { + buffer.unsafePutDouble(0, v); + output.write(buffer.getHeapMemory(), 0, 8); + } + + public void writeUTF(String v) throws IOException { + // avoid `writeInt` overwrite sting data. + buffer.writerIndex(4); + if (v != null) { + buffer.writeBoolean(true); + fury.writeJavaString(buffer, v); + } else { + buffer.writeBoolean(false); + } + int size = buffer.writerIndex() - 4; + writeInt(size); + output.write(buffer.getHeapMemory(), 4, size); + } + + public void writeBytes(byte[] v) throws IOException { + writeInt(v.length); + output.write(v); + } + + public void writeBytes(byte[] v, int off, int len) throws IOException { + writeInt(len); + output.write(v, off, len); + } + + public void flushBuffer() throws IOException { + output.flush(); + } +} diff --git a/dubbo-serialization-extensions/dubbo-serialization-fury/src/main/java/org/apache/dubbo/common/serialize/fury/dubbo/FuryScopeModelInitializer.java b/dubbo-serialization-extensions/dubbo-serialization-fury/src/main/java/org/apache/dubbo/common/serialize/fury/dubbo/FuryScopeModelInitializer.java new file mode 100644 index 000000000..5129e1206 --- /dev/null +++ b/dubbo-serialization-extensions/dubbo-serialization-fury/src/main/java/org/apache/dubbo/common/serialize/fury/dubbo/FuryScopeModelInitializer.java @@ -0,0 +1,38 @@ +/* + * 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 org.apache.dubbo.common.serialize.fury.dubbo; + +import org.apache.dubbo.common.beans.factory.ScopeBeanFactory; +import org.apache.dubbo.rpc.model.ApplicationModel; +import org.apache.dubbo.rpc.model.FrameworkModel; +import org.apache.dubbo.rpc.model.ModuleModel; +import org.apache.dubbo.rpc.model.ScopeModelInitializer; + +public class FuryScopeModelInitializer implements ScopeModelInitializer { + @Override + public void initializeFrameworkModel(FrameworkModel frameworkModel) { + ScopeBeanFactory beanFactory = frameworkModel.getBeanFactory(); + beanFactory.registerBean(FuryCheckerListener.class); + } + + @Override + public void initializeApplicationModel(ApplicationModel applicationModel) {} + + @Override + public void initializeModuleModel(ModuleModel moduleModel) {} +} diff --git a/dubbo-serialization-extensions/dubbo-serialization-fury/src/main/java/org/apache/dubbo/common/serialize/fury/dubbo/FurySerialization.java b/dubbo-serialization-extensions/dubbo-serialization-fury/src/main/java/org/apache/dubbo/common/serialize/fury/dubbo/FurySerialization.java new file mode 100644 index 000000000..7c8fc9e01 --- /dev/null +++ b/dubbo-serialization-extensions/dubbo-serialization-fury/src/main/java/org/apache/dubbo/common/serialize/fury/dubbo/FurySerialization.java @@ -0,0 +1,61 @@ +/* + * 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 org.apache.dubbo.common.serialize.fury.dubbo; + +import io.fury.Fury; +import io.fury.collection.Tuple2; +import io.fury.memory.MemoryBuffer; +import io.fury.memory.MemoryUtils; +import io.fury.util.LoaderBinding; + +/** + * Fury serialization for dubbo. This integration doesn't allow type inconsistency between + * serialization and deserialization peer. + * + * @author chaokunyang + */ +public class FurySerialization extends BaseFurySerialization { + public static final byte FURY_SERIALIZATION_ID = 28; + private static final ThreadLocal> furyFactory = + ThreadLocal.withInitial( + () -> { + LoaderBinding binding = + new LoaderBinding( + classLoader -> + Fury.builder() + .withRefTracking(true) + .requireClassRegistration(false) + .withClassLoader(classLoader) + .build()); + MemoryBuffer buffer = MemoryUtils.buffer(32); + return Tuple2.of(binding, buffer); + }); + + public byte getContentTypeId() { + return FURY_SERIALIZATION_ID; + } + + public String getContentType() { + return "fury/consistent"; + } + + @Override + protected Tuple2 getFury() { + return furyFactory.get(); + } +} diff --git a/dubbo-serialization-extensions/dubbo-serialization-fury/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.serialize.Serialization b/dubbo-serialization-extensions/dubbo-serialization-fury/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.serialize.Serialization new file mode 100644 index 000000000..c73b34b88 --- /dev/null +++ b/dubbo-serialization-extensions/dubbo-serialization-fury/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.serialize.Serialization @@ -0,0 +1,2 @@ +fury=org.apache.dubbo.common.serialize.fury.dubbo.FurySerialization +fury-compatible=org.apache.dubbo.common.serialize.fury.dubbo.FuryCompatibleSerialization \ No newline at end of file diff --git a/dubbo-serialization-extensions/dubbo-serialization-fury/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.model.ScopeModelInitializer b/dubbo-serialization-extensions/dubbo-serialization-fury/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.model.ScopeModelInitializer new file mode 100644 index 000000000..3dd365081 --- /dev/null +++ b/dubbo-serialization-extensions/dubbo-serialization-fury/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.model.ScopeModelInitializer @@ -0,0 +1,2 @@ +fury=org.apache.dubbo.common.serialize.fury.dubbo.FuryScopeModelInitializer +fury-compatible=org.apache.dubbo.common.serialize.fury.dubbo.FuryScopeModelInitializer \ No newline at end of file diff --git a/dubbo-serialization-extensions/dubbo-serialization-kryo/src/main/java/org/apache/dubbo/common/serialize/kryo/optimized/KryoObjectInput2.java b/dubbo-serialization-extensions/dubbo-serialization-kryo/src/main/java/org/apache/dubbo/common/serialize/kryo/optimized/KryoObjectInput2.java index 6bc738728..648557a1e 100644 --- a/dubbo-serialization-extensions/dubbo-serialization-kryo/src/main/java/org/apache/dubbo/common/serialize/kryo/optimized/KryoObjectInput2.java +++ b/dubbo-serialization-extensions/dubbo-serialization-kryo/src/main/java/org/apache/dubbo/common/serialize/kryo/optimized/KryoObjectInput2.java @@ -146,7 +146,7 @@ public Throwable readThrowable() throws IOException, ClassNotFoundException { } @Override - public Object readEvent() throws IOException, ClassNotFoundException { + public String readEvent() throws IOException, ClassNotFoundException { try { return kryo.readObjectOrNull(input, String.class); } catch (KryoException e) { diff --git a/dubbo-serialization-extensions/dubbo-serialization-protobuf/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufJsonObjectInput.java b/dubbo-serialization-extensions/dubbo-serialization-protobuf/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufJsonObjectInput.java index 5f5da17e4..d910717a3 100644 --- a/dubbo-serialization-extensions/dubbo-serialization-protobuf/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufJsonObjectInput.java +++ b/dubbo-serialization-extensions/dubbo-serialization-protobuf/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufJsonObjectInput.java @@ -149,7 +149,7 @@ public Map readAttachments() throws IOException, ClassNotFoundEx } @Override - public Object readEvent() throws IOException, ClassNotFoundException { + public String readEvent() throws IOException, ClassNotFoundException { String eventData = readUTF(); if (eventData.equals(MOCK_HEARTBEAT_EVENT)) { eventData = HEARTBEAT_EVENT; diff --git a/dubbo-serialization-extensions/dubbo-serialization-protobuf/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufObjectInput.java b/dubbo-serialization-extensions/dubbo-serialization-protobuf/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufObjectInput.java index e1a851def..a22b5e4d3 100644 --- a/dubbo-serialization-extensions/dubbo-serialization-protobuf/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufObjectInput.java +++ b/dubbo-serialization-extensions/dubbo-serialization-protobuf/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufObjectInput.java @@ -124,7 +124,7 @@ public Throwable readThrowable() throws IOException { } @Override - public Object readEvent() throws IOException { + public String readEvent() throws IOException { String eventData = readUTF(); if (eventData.equals(MOCK_HEARTBEAT_EVENT)) { eventData = HEARTBEAT_EVENT; diff --git a/dubbo-serialization-extensions/pom.xml b/dubbo-serialization-extensions/pom.xml index 2367e62cf..960ecd9b0 100644 --- a/dubbo-serialization-extensions/pom.xml +++ b/dubbo-serialization-extensions/pom.xml @@ -36,6 +36,7 @@ dubbo-serialization-gson dubbo-serialization-fst dubbo-serialization-fastjson + dubbo-serialization-fury dubbo-serialization-avro dubbo-serialization-msgpack dubbo-serialization-native-hession From 180f782d089c112aadb474ac3619c223f660e563 Mon Sep 17 00:00:00 2001 From: aofall <10182210+aofall@users.noreply.github.com> Date: Mon, 6 Nov 2023 16:36:10 +0800 Subject: [PATCH 31/35] feat: Add jackson serialization extension (#231) * feat: Add jackson serialization extension * fix build failed * fix build failed * remove author tag && support jdk8 --- dubbo-extensions-dependencies-bom/pom.xml | 21 ++ .../dubbo-serialization-jackson/pom.xml | 61 ++++++ .../serialize/jackson/JacksonObjectInput.java | 141 ++++++++++++ .../jackson/JacksonObjectOutput.java | 122 +++++++++++ .../jackson/JacksonSerialization.java | 61 ++++++ ...pache.dubbo.common.serialize.Serialization | 1 + .../dubbo-serialization-test/pom.xml | 5 + .../jackson/JacksonObjectInputTest.java | 202 ++++++++++++++++++ .../jackson/JacksonObjectOutputTest.java | 145 +++++++++++++ .../jackson/JacksonSerializationTest.java | 68 ++++++ dubbo-serialization-extensions/pom.xml | 1 + 11 files changed, 828 insertions(+) create mode 100644 dubbo-serialization-extensions/dubbo-serialization-jackson/pom.xml create mode 100644 dubbo-serialization-extensions/dubbo-serialization-jackson/src/main/java/org/apache/dubbo/common/serialize/jackson/JacksonObjectInput.java create mode 100644 dubbo-serialization-extensions/dubbo-serialization-jackson/src/main/java/org/apache/dubbo/common/serialize/jackson/JacksonObjectOutput.java create mode 100644 dubbo-serialization-extensions/dubbo-serialization-jackson/src/main/java/org/apache/dubbo/common/serialize/jackson/JacksonSerialization.java create mode 100644 dubbo-serialization-extensions/dubbo-serialization-jackson/src/main/resources/META-INF/dubbo.internal/org.apache.dubbo.common.serialize.Serialization create mode 100644 dubbo-serialization-extensions/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/jackson/JacksonObjectInputTest.java create mode 100644 dubbo-serialization-extensions/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/jackson/JacksonObjectOutputTest.java create mode 100644 dubbo-serialization-extensions/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/jackson/JacksonSerializationTest.java diff --git a/dubbo-extensions-dependencies-bom/pom.xml b/dubbo-extensions-dependencies-bom/pom.xml index 7d640d9d7..ecca731af 100644 --- a/dubbo-extensions-dependencies-bom/pom.xml +++ b/dubbo-extensions-dependencies-bom/pom.xml @@ -112,6 +112,7 @@ 1.2.83 2.48-jdk-6 0.2.0 + 2.15.3 2.8.9 5.4.0 0.45 @@ -304,6 +305,26 @@ fury-core ${fury_version} + + com.fasterxml.jackson.core + jackson-core + ${jackson_version} + + + com.fasterxml.jackson.core + jackson-annotations + ${jackson_version} + + + com.fasterxml.jackson.core + jackson-databind + ${jackson_version} + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + ${jackson_version} + com.google.code.gson gson diff --git a/dubbo-serialization-extensions/dubbo-serialization-jackson/pom.xml b/dubbo-serialization-extensions/dubbo-serialization-jackson/pom.xml new file mode 100644 index 000000000..fc8695d65 --- /dev/null +++ b/dubbo-serialization-extensions/dubbo-serialization-jackson/pom.xml @@ -0,0 +1,61 @@ + + + 4.0.0 + + org.apache.dubbo.extensions + dubbo-serialization-extensions + ${revision} + ../pom.xml + + + dubbo-serialization-jackson + The jackson serialization module of dubbo project + + + 1.8 + 1.8 + UTF-8 + + + + + org.apache.dubbo + dubbo-serialization-api + true + + + com.fasterxml.jackson.core + jackson-core + + + com.fasterxml.jackson.core + jackson-annotations + + + com.fasterxml.jackson.core + jackson-databind + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + + + + diff --git a/dubbo-serialization-extensions/dubbo-serialization-jackson/src/main/java/org/apache/dubbo/common/serialize/jackson/JacksonObjectInput.java b/dubbo-serialization-extensions/dubbo-serialization-jackson/src/main/java/org/apache/dubbo/common/serialize/jackson/JacksonObjectInput.java new file mode 100644 index 000000000..23118487c --- /dev/null +++ b/dubbo-serialization-extensions/dubbo-serialization-jackson/src/main/java/org/apache/dubbo/common/serialize/jackson/JacksonObjectInput.java @@ -0,0 +1,141 @@ +/* + * 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 org.apache.dubbo.common.serialize.jackson; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import org.apache.dubbo.common.serialize.ObjectInput; + +import java.io.BufferedReader; +import java.io.EOFException; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.lang.reflect.Type; + +/** + * Jackson object input implementation + */ +public class JacksonObjectInput implements ObjectInput { + + private final ObjectMapper MAPPER; + + private final BufferedReader READER; + + public JacksonObjectInput(InputStream inputStream) { + this(new InputStreamReader(inputStream)); + } + + public JacksonObjectInput(Reader reader) { + this.READER = new BufferedReader(reader); + this.MAPPER = new ObjectMapper() + .configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false) + .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) + .setSerializationInclusion(JsonInclude.Include.NON_NULL) + .registerModule(new JavaTimeModule()) + ; + } + + @Override + public Object readObject() throws IOException, ClassNotFoundException { + return read(Object.class); + } + + @Override + public T readObject(Class cls) throws IOException, ClassNotFoundException { + return read(cls); + } + + @Override + public T readObject(Class cls, Type type) throws IOException, ClassNotFoundException { + return read(type); + } + + @Override + public boolean readBool() throws IOException { + return read(boolean.class); + } + + @Override + public byte readByte() throws IOException { + return read(byte.class); + } + + @Override + public short readShort() throws IOException { + return read(short.class); + } + + @Override + public int readInt() throws IOException { + return read(int.class); + } + + @Override + public long readLong() throws IOException { + return read(long.class); + } + + @Override + public float readFloat() throws IOException { + return read(float.class); + } + + @Override + public double readDouble() throws IOException { + return read(double.class); + } + + @Override + public String readUTF() throws IOException { + return read(String.class); + } + + @Override + public byte[] readBytes() throws IOException { + return readLine().getBytes(); + } + + private String readLine() throws IOException { + String line = READER.readLine(); + if (line == null || line.trim().isEmpty()) { + throw new EOFException(); + } + return line; + } + + private T read(Class cls) throws IOException { + String json = readLine(); + return MAPPER.readValue(json, cls); + } + + private T read(Type type) throws IOException { + String json = readLine(); + return MAPPER.readValue(json, new TypeReference() { + @Override + public Type getType() { + return type; + } + }); + } + +} diff --git a/dubbo-serialization-extensions/dubbo-serialization-jackson/src/main/java/org/apache/dubbo/common/serialize/jackson/JacksonObjectOutput.java b/dubbo-serialization-extensions/dubbo-serialization-jackson/src/main/java/org/apache/dubbo/common/serialize/jackson/JacksonObjectOutput.java new file mode 100644 index 000000000..da642e870 --- /dev/null +++ b/dubbo-serialization-extensions/dubbo-serialization-jackson/src/main/java/org/apache/dubbo/common/serialize/jackson/JacksonObjectOutput.java @@ -0,0 +1,122 @@ +/* + * 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 org.apache.dubbo.common.serialize.jackson; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import org.apache.dubbo.common.serialize.ObjectOutput; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.io.Writer; + +/** + * Jackson object output implementation + */ +public class JacksonObjectOutput implements ObjectOutput { + + private final ObjectMapper MAPPER; + + private final PrintWriter WRITER; + + public JacksonObjectOutput(OutputStream outputStream) { + this(new OutputStreamWriter(outputStream)); + } + + public JacksonObjectOutput(Writer writer) { + this.WRITER = new PrintWriter(writer); + this.MAPPER = new ObjectMapper() + .configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false) + .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) + .setSerializationInclusion(JsonInclude.Include.NON_NULL) + .registerModule(new JavaTimeModule()) + ; + } + + @Override + public void writeObject(Object obj) throws IOException { + char[] jsonChars = convertJsonToCharArray(MAPPER.writeValueAsString(obj)); + WRITER.write(jsonChars, 0, jsonChars.length); + WRITER.println(); + WRITER.flush(); + } + + @Override + public void writeBool(boolean v) throws IOException { + writeObject(v); + } + + @Override + public void writeByte(byte v) throws IOException { + writeObject(v); + } + + @Override + public void writeShort(short v) throws IOException { + writeObject(v); + } + + @Override + public void writeInt(int v) throws IOException { + writeObject(v); + } + + @Override + public void writeLong(long v) throws IOException { + writeObject(v); + } + + @Override + public void writeFloat(float v) throws IOException { + writeObject(v); + } + + @Override + public void writeDouble(double v) throws IOException { + writeObject(v); + } + + @Override + public void writeUTF(String v) throws IOException { + writeObject(v); + } + + @Override + public void writeBytes(byte[] v) throws IOException { + WRITER.println(new String(v)); + } + + @Override + public void writeBytes(byte[] v, int off, int len) throws IOException { + WRITER.println(new String(v, off, len)); + } + + @Override + public void flushBuffer() throws IOException { + WRITER.flush(); + } + + private char[] convertJsonToCharArray(String json) { + return json.toCharArray(); + } + +} diff --git a/dubbo-serialization-extensions/dubbo-serialization-jackson/src/main/java/org/apache/dubbo/common/serialize/jackson/JacksonSerialization.java b/dubbo-serialization-extensions/dubbo-serialization-jackson/src/main/java/org/apache/dubbo/common/serialize/jackson/JacksonSerialization.java new file mode 100644 index 000000000..8d6d45515 --- /dev/null +++ b/dubbo-serialization-extensions/dubbo-serialization-jackson/src/main/java/org/apache/dubbo/common/serialize/jackson/JacksonSerialization.java @@ -0,0 +1,61 @@ +/* + * 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 org.apache.dubbo.common.serialize.jackson; + +import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.serialize.ObjectInput; +import org.apache.dubbo.common.serialize.ObjectOutput; +import org.apache.dubbo.common.serialize.Serialization; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +/** + * Jackson serialization implementation + * + *
+ *     e.g. <dubbo:protocol serialization="jackson" />
+ * 
+ */ +public class JacksonSerialization implements Serialization { + + private static final byte JACKSON_SERIALIZATION_ID = 18; + + private static final String JSON_CONTENT_TYPE = "application/json"; + + @Override + public byte getContentTypeId() { + return JACKSON_SERIALIZATION_ID; + } + + @Override + public String getContentType() { + return JSON_CONTENT_TYPE; + } + + @Override + public ObjectOutput serialize(URL url, OutputStream output) throws IOException { + return new JacksonObjectOutput(output); + } + + @Override + public ObjectInput deserialize(URL url, InputStream input) throws IOException { + return new JacksonObjectInput(input); + } + +} diff --git a/dubbo-serialization-extensions/dubbo-serialization-jackson/src/main/resources/META-INF/dubbo.internal/org.apache.dubbo.common.serialize.Serialization b/dubbo-serialization-extensions/dubbo-serialization-jackson/src/main/resources/META-INF/dubbo.internal/org.apache.dubbo.common.serialize.Serialization new file mode 100644 index 000000000..b229ca0a0 --- /dev/null +++ b/dubbo-serialization-extensions/dubbo-serialization-jackson/src/main/resources/META-INF/dubbo.internal/org.apache.dubbo.common.serialize.Serialization @@ -0,0 +1 @@ +jackson=org.apache.dubbo.common.serialize.jackson.JacksonSerialization diff --git a/dubbo-serialization-extensions/dubbo-serialization-test/pom.xml b/dubbo-serialization-extensions/dubbo-serialization-test/pom.xml index ebd814006..1b04a3db2 100644 --- a/dubbo-serialization-extensions/dubbo-serialization-test/pom.xml +++ b/dubbo-serialization-extensions/dubbo-serialization-test/pom.xml @@ -45,6 +45,11 @@ com.google.code.gson 2.8.9
+ + org.apache.dubbo.extensions + dubbo-serialization-jackson + ${revision} + org.apache.dubbo.extensions dubbo-serialization-protobuf diff --git a/dubbo-serialization-extensions/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/jackson/JacksonObjectInputTest.java b/dubbo-serialization-extensions/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/jackson/JacksonObjectInputTest.java new file mode 100644 index 000000000..bb6912dae --- /dev/null +++ b/dubbo-serialization-extensions/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/jackson/JacksonObjectInputTest.java @@ -0,0 +1,202 @@ +/* + * 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 org.apache.dubbo.common.serialize.jackson; + +import org.apache.dubbo.common.serialize.model.Organization; +import org.apache.dubbo.common.serialize.model.Person; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.io.ByteArrayInputStream; +import java.io.EOFException; +import java.io.IOException; +import java.io.StringReader; +import java.lang.reflect.Method; +import java.lang.reflect.Type; +import java.util.List; +import java.util.Map; + +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * {@link JacksonObjectInput} Unit Test + */ +public class JacksonObjectInputTest { + + private JacksonObjectInput jacksonObjectInput; + + @Test + public void testReadBool() throws IOException { + jacksonObjectInput = new JacksonObjectInput(new ByteArrayInputStream("true".getBytes())); + boolean result = jacksonObjectInput.readBool(); + + assertThat(result, is(true)); + + jacksonObjectInput = new JacksonObjectInput(new StringReader("false")); + result = jacksonObjectInput.readBool(); + + assertThat(result, is(false)); + } + + @Test + public void testReadByte() throws IOException { + jacksonObjectInput = new JacksonObjectInput(new ByteArrayInputStream("123".getBytes())); + Byte result = jacksonObjectInput.readByte(); + + assertThat(result, is(Byte.parseByte("123"))); + } + + @Test + public void testReadBytes() throws IOException { + jacksonObjectInput = new JacksonObjectInput(new ByteArrayInputStream("123456".getBytes())); + byte[] result = jacksonObjectInput.readBytes(); + + assertThat(result, is("123456".getBytes())); + } + + @Test + public void testReadShort() throws IOException { + jacksonObjectInput = new JacksonObjectInput(new StringReader("1")); + short result = jacksonObjectInput.readShort(); + + assertThat(result, is((short) 1)); + } + + @Test + public void testReadInt() throws IOException { + jacksonObjectInput = new JacksonObjectInput(new StringReader("1")); + Integer result = jacksonObjectInput.readInt(); + + assertThat(result, is(1)); + } + + @Test + public void testReadDouble() throws IOException { + jacksonObjectInput = new JacksonObjectInput(new StringReader("1.88")); + Double result = jacksonObjectInput.readDouble(); + + assertThat(result, is(1.88d)); + } + + @Test + public void testReadLong() throws IOException { + jacksonObjectInput = new JacksonObjectInput(new StringReader("10")); + Long result = jacksonObjectInput.readLong(); + + assertThat(result, is(10L)); + } + + @Test + public void testReadFloat() throws IOException { + jacksonObjectInput = new JacksonObjectInput(new StringReader("1.66")); + Float result = jacksonObjectInput.readFloat(); + + assertThat(result, is(1.66F)); + } + + @Test + public void testReadUTF() throws IOException { + jacksonObjectInput = new JacksonObjectInput(new StringReader("\"wording\"")); + String result = jacksonObjectInput.readUTF(); + + assertThat(result, is("wording")); + } + + @Test + public void testReadObject() throws IOException, ClassNotFoundException { + jacksonObjectInput = new JacksonObjectInput(new StringReader("{ \"name\":\"John\", \"age\":30 }")); + Person result = jacksonObjectInput.readObject(Person.class); + + assertThat(result, not(nullValue())); + assertThat(result.getName(), is("John")); + assertThat(result.getAge(), is(30)); + } + + @Test + public void testEmptyLine() throws IOException, ClassNotFoundException { + Assertions.assertThrows(EOFException.class, () -> { + jacksonObjectInput = new JacksonObjectInput(new StringReader("")); + + jacksonObjectInput.readObject(); + }); + } + + @Test + public void testEmptySpace() throws IOException, ClassNotFoundException { + Assertions.assertThrows(EOFException.class, () -> { + jacksonObjectInput = new JacksonObjectInput(new StringReader(" ")); + + jacksonObjectInput.readObject(); + }); + } + + @Test + public void testReadObjectWithoutClass() throws IOException, ClassNotFoundException, NoSuchFieldException { + jacksonObjectInput = new JacksonObjectInput(new StringReader("{ \"name\":\"John\", \"age\":30 }")); + + Map map = jacksonObjectInput.readObject(Map.class); + + assertThat(map, not(nullValue())); + assertThat(map.get("name"), is("John")); + assertThat(map.get("age"), is(30)); + } + + + @Test + public void testReadObjectWithTowType() throws Exception { + jacksonObjectInput = new JacksonObjectInput(new StringReader("[{\"name\":\"John\",\"age\":30},{\"name\":\"Born\",\"age\":24}]")); + + Method methodReturnType = getClass().getMethod("towLayer"); + Type type = methodReturnType.getGenericReturnType(); + List o = jacksonObjectInput.readObject(List.class, type); + + assertTrue(o instanceof List); + assertTrue(o.get(0) instanceof Person); + + assertThat(o.size(), is(2)); + assertThat(o.get(1).getName(), is("Born")); + } + + @Test + public void testReadObjectWithThreeType() throws Exception { + jacksonObjectInput = new JacksonObjectInput(new StringReader("{\"data\":[{\"name\":\"John\",\"age\":30},{\"name\":\"Born\",\"age\":24}]}")); + + Method methodReturnType = getClass().getMethod("threeLayer"); + Type type = methodReturnType.getGenericReturnType(); + Organization> o = jacksonObjectInput.readObject(Organization.class, type); + + assertTrue(o instanceof Organization); + assertTrue(o.getData() instanceof List); + assertTrue(o.getData().get(0) instanceof Person); + + assertThat(o.getData().size(), is(2)); + assertThat(o.getData().get(1).getName(), is("Born")); + } + + public List towLayer() { + return null; + } + + public Organization> threeLayer() { + return null; + } + +} diff --git a/dubbo-serialization-extensions/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/jackson/JacksonObjectOutputTest.java b/dubbo-serialization-extensions/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/jackson/JacksonObjectOutputTest.java new file mode 100644 index 000000000..52f5f0148 --- /dev/null +++ b/dubbo-serialization-extensions/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/jackson/JacksonObjectOutputTest.java @@ -0,0 +1,145 @@ +/* + * 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 org.apache.dubbo.common.serialize.jackson; + +import org.apache.dubbo.common.serialize.model.media.Image; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * {@link JacksonObjectOutput} Unit Test + */ +public class JacksonObjectOutputTest { + + private JacksonObjectOutput jacksonObjectOutput; + private JacksonObjectInput jacksonObjectInput; + private ByteArrayOutputStream byteArrayOutputStream; + private ByteArrayInputStream byteArrayInputStream; + + @BeforeEach + public void setUp() throws Exception { + this.byteArrayOutputStream = new ByteArrayOutputStream(); + this.jacksonObjectOutput = new JacksonObjectOutput(byteArrayOutputStream); + } + + @Test + public void testWriteBool() throws IOException { + this.jacksonObjectOutput.writeBool(true); + this.flushToInput(); + + assertThat(jacksonObjectInput.readBool(), is(true)); + } + + @Test + public void testWriteShort() throws IOException { + this.jacksonObjectOutput.writeShort((short) 2); + this.flushToInput(); + + assertThat(jacksonObjectInput.readShort(), is((short) 2)); + } + + @Test + public void testWriteInt() throws IOException { + this.jacksonObjectOutput.writeInt(1); + this.flushToInput(); + + assertThat(jacksonObjectInput.readInt(), is(1)); + } + + @Test + public void testWriteLong() throws IOException { + this.jacksonObjectOutput.writeLong(1000L); + this.flushToInput(); + + assertThat(jacksonObjectInput.readLong(), is(1000L)); + } + + @Test + public void testWriteUTF() throws IOException { + this.jacksonObjectOutput.writeUTF("Pace Hasîtî 和平 Мир"); + this.flushToInput(); + + assertThat(jacksonObjectInput.readUTF(), is("Pace Hasîtî 和平 Мир")); + } + + + @Test + public void testWriteFloat() throws IOException { + this.jacksonObjectOutput.writeFloat(1.88f); + this.flushToInput(); + + assertThat(this.jacksonObjectInput.readFloat(), is(1.88f)); + } + + @Test + public void testWriteDouble() throws IOException { + this.jacksonObjectOutput.writeDouble(1.66d); + this.flushToInput(); + + assertThat(this.jacksonObjectInput.readDouble(), is(1.66d)); + } + + @Test + public void testWriteBytes() throws IOException { + this.jacksonObjectOutput.writeBytes("hello".getBytes()); + this.flushToInput(); + + assertThat(this.jacksonObjectInput.readBytes(), is("hello".getBytes())); + } + + @Test + public void testWriteBytesWithSubLength() throws IOException { + this.jacksonObjectOutput.writeBytes("hello".getBytes(), 2, 2); + this.flushToInput(); + + assertThat(this.jacksonObjectInput.readBytes(), is("ll".getBytes())); + } + + @Test + public void testWriteByte() throws IOException { + this.jacksonObjectOutput.writeByte((byte) 123); + this.flushToInput(); + + assertThat(this.jacksonObjectInput.readByte(), is((byte) 123)); + } + + @Test + public void testWriteObject() throws IOException, ClassNotFoundException { + Image image = new Image("http://dubbo.apache.org/img/dubbo_white.png", "logo", 300, 480, Image.Size.SMALL); + this.jacksonObjectOutput.writeObject(image); + this.flushToInput(); + + Image readObjectForImage = jacksonObjectInput.readObject(Image.class); + assertThat(readObjectForImage, not(nullValue())); + assertThat(readObjectForImage, is(image)); + } + + private void flushToInput() throws IOException { + this.jacksonObjectOutput.flushBuffer(); + this.byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray()); + this.jacksonObjectInput = new JacksonObjectInput(byteArrayInputStream); + } +} diff --git a/dubbo-serialization-extensions/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/jackson/JacksonSerializationTest.java b/dubbo-serialization-extensions/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/jackson/JacksonSerializationTest.java new file mode 100644 index 000000000..4d13d193b --- /dev/null +++ b/dubbo-serialization-extensions/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/jackson/JacksonSerializationTest.java @@ -0,0 +1,68 @@ +/* + * 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 org.apache.dubbo.common.serialize.jackson; + +import org.apache.dubbo.common.serialize.ObjectInput; +import org.apache.dubbo.common.serialize.ObjectOutput; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.mockito.Mockito.mock; + +/** + * {@link JacksonSerialization} Unit Test + */ +public class JacksonSerializationTest { + + private JacksonSerialization jacksonSerialization; + + @BeforeEach + public void setUp() { + this.jacksonSerialization = new JacksonSerialization(); + } + + @Test + public void testContentTypeId() { + MatcherAssert.assertThat(jacksonSerialization.getContentTypeId(), is((byte) 18)); + } + + @Test + public void testContentType() { + MatcherAssert.assertThat(jacksonSerialization.getContentType(), is("application/json")); + } + + @Test + public void testObjectOutput() throws IOException { + ObjectOutput objectOutput = jacksonSerialization.serialize(null, mock(OutputStream.class)); + assertThat(objectOutput, Matchers.instanceOf(JacksonObjectOutput.class)); + } + + @Test + public void testObjectInput() throws IOException { + ObjectInput objectInput = jacksonSerialization.deserialize(null, mock(InputStream.class)); + assertThat(objectInput, Matchers.instanceOf(JacksonObjectInput.class)); + } + +} diff --git a/dubbo-serialization-extensions/pom.xml b/dubbo-serialization-extensions/pom.xml index 960ecd9b0..1173a83e1 100644 --- a/dubbo-serialization-extensions/pom.xml +++ b/dubbo-serialization-extensions/pom.xml @@ -40,6 +40,7 @@ dubbo-serialization-avro dubbo-serialization-msgpack dubbo-serialization-native-hession + dubbo-serialization-jackson dubbo-serialization-test
From 2752e830e55fdf9e9d7aa140e90db05f3e386b9b Mon Sep 17 00:00:00 2001 From: aofall <10182210+aofall@users.noreply.github.com> Date: Tue, 7 Nov 2023 20:04:45 +0800 Subject: [PATCH 32/35] fix: move the recourse file to the corrent path (#233) --- .../internal}/org.apache.dubbo.common.serialize.Serialization | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename dubbo-serialization-extensions/dubbo-serialization-jackson/src/main/resources/META-INF/{dubbo.internal => dubbo/internal}/org.apache.dubbo.common.serialize.Serialization (100%) diff --git a/dubbo-serialization-extensions/dubbo-serialization-jackson/src/main/resources/META-INF/dubbo.internal/org.apache.dubbo.common.serialize.Serialization b/dubbo-serialization-extensions/dubbo-serialization-jackson/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.serialize.Serialization similarity index 100% rename from dubbo-serialization-extensions/dubbo-serialization-jackson/src/main/resources/META-INF/dubbo.internal/org.apache.dubbo.common.serialize.Serialization rename to dubbo-serialization-extensions/dubbo-serialization-jackson/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.serialize.Serialization From 6b534a8588950f680d5e053ac41600662f38d023 Mon Sep 17 00:00:00 2001 From: aofall <10182210+aofall@users.noreply.github.com> Date: Thu, 9 May 2024 20:19:18 +0800 Subject: [PATCH 33/35] update: compatible dubbo 3.0.x (#336) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * upgrade dubbo to the 3.1 latest version in 3.1.0 branch (#293) * upgrade dubbo to the 3.1.x the latest version * fix(#207): Dubbo Redis register support select databases (cherry picked from commit 0f42ecd6b0188282da3366ad4056c8e5e12d9ffe) * Bump version && fix test case failed (#303) * Remove dubbo-gateway-common module because the class ByteAccessor since dubbo 3.2.0, but this branch(3.1.0) based on the dubbo 3.1.x * Bump the extensions version to 3.1.0 && revision the pom.xml * Adjust test ci workspace * add GitHub Actions workflow file * add GitHub Actions workflow file * build: add some ignore file for license check * chore: fix missed or incorrect ASF license * fix multi os prepare test failed * fix test case failed * try to fix conformance test failed * try to fix conformance test failed * fix ci build failed * Cherry-pick bug fix from master into 3.1.0 branch (#334) * [Dubbo-267] Fix protobuf type lose field when deepCopy inJvmInvoker Class. (#268) * fix: dubbo-registry-dns resource leak (#308) * fix: dubbo-registry-dns memory leak && add try catch * revert junit (cherry picked from commit b3033debb4e0277ad865b8b78f54652e24af9100) * fix: redis connection do not close and return to connection pool (#311) (cherry picked from commit cbad15d8767e72c539cae0f3abeb8885338948a6) * fix test lib (#310) * fix test lib * remove useless dependency * remove useless dependency * fix bad test * TimeoutException Increase time * Revert "TimeoutException Increase time" This reverts commit 5e5bb32bc3f26faf2ba318fafc16e9ca96232872. * add MinaClientToServerTest disable (cherry picked from commit f38363fc96817e46af8ea6c3f8ae07701976aedf) * build: add Windows platform unit test for CI && add dependabot config * chore: create etcd for each unit test * chore: already check license by apache skywalking-eyes so skip rat-license check * Revert "chore: already check license by apache skywalking-eyes so skip rat-license check" This reverts commit 98d627b3fe94394712d86ba4aaf13cacf524f50b. * fix: rat-check failed --------- Co-authored-by: MaruHibiki <1807180752@qq.com> Co-authored-by: 王聪洋 <56506697+wcy666103@users.noreply.github.com> * update: compatible dubbo 3.0.x Remove dubbo-registry-dns because ReflectionBasedServiceDiscovery since dubbo 3.1 * ci: adjust build tools use dubbo 3.0 * ci: Upload coverage to Codecov --------- Co-authored-by: MaruHibiki <1807180752@qq.com> Co-authored-by: 王聪洋 <56506697+wcy666103@users.noreply.github.com> --- .codecov.yml | 15 + .github/dependabot.yaml | 15 + .github/workflows/build-and-test-pr.yml | 340 +++++++++++++++++ .../build-and-test-scheduled-3.0.yml | 346 ++++++++++++++++++ .github/workflows/ci.yml | 68 ---- .github/workflows/conformance.yml | 9 +- .github/workflows/release-test.yml | 346 ++++++++++++++++++ .licenserc.yaml | 213 +++++++++++ dobbo-doc-auto-gen/pom.xml | 2 +- .../dubbo-api-docs-annotations/pom.xml | 2 +- dubbo-api-docs/dubbo-api-docs-core/pom.xml | 2 +- .../examples-api/pom.xml | 2 +- .../examples-provider-sca/pom.xml | 4 +- .../examples-provider/pom.xml | 5 +- .../dubbo-api-docs-examples/pom.xml | 2 +- dubbo-api-docs/pom.xml | 90 +---- .../dubbo-cluster-broadcast-1/pom.xml | 2 +- .../pom.xml | 2 +- .../loadbalance/LoadBalanceBaseTest.java | 2 +- .../loadbalance/PeakEwmaLoadBalanceTest.java | 2 +- .../dubbo-cluster-polaris-dubbo2/pom.xml | 2 +- .../pom.xml | 2 +- .../pom.xml | 2 +- .../pom.xml | 2 +- .../dubbo-configcenter-consul/pom.xml | 2 +- .../dubbo-configcenter-etcd/pom.xml | 4 +- .../etcd/EtcdDynamicConfigurationTest.java | 8 +- dubbo-extensions-dependencies-bom/pom.xml | 123 ++++++- .../pom.xml | 2 +- .../pom.xml | 2 +- .../dubbo-filter-polaris-dubbo2/pom.xml | 2 +- .../dubbo-filter-seata/pom.xml | 2 +- .../dubbo-gateway-common/pom.xml | 29 -- .../common/OmnipotentCommonConstants.java | 40 -- .../dubbo-gateway-consumer/pom.xml | 42 --- .../config/InjvmConfigPostProcessor.java | 32 -- .../gateway/consumer/filter/OmnSerFilter.java | 166 --------- ...rg.apache.dubbo.config.ConfigPostProcessor | 1 - .../internal/org.apache.dubbo.rpc.Filter | 1 - .../dubbo-gateway-provider/pom.xml | 50 --- .../provider/ConfigDeployListener.java | 55 --- .../gateway/provider/OmnipotentService.java | 42 --- .../gateway/provider/SnfByteAccessor.java | 46 --- .../provider/SnfDecodeableRpcInvocation.java | 168 --------- .../provider/filter/OmnipotentFilter.java | 91 ----- ...bo.common.deploy.ApplicationDeployListener | 1 - .../internal/org.apache.dubbo.rpc.Filter | 1 - ...ache.dubbo.rpc.protocol.dubbo.ByteAccessor | 1 - dubbo-gateway-extensions/pom.xml | 37 -- .../dubbo-metadata-report-consul/pom.xml | 4 +- .../dubbo-metadata-report-etcd/pom.xml | 4 +- .../dubbo-mock-admin/pom.xml | 4 +- dubbo-mock-extensions/dubbo-mock-api/pom.xml | 2 +- dubbo-mock-extensions/pom.xml | 2 +- .../dubbo-registry-consul/pom.xml | 2 +- .../dubbo-registry-dns/pom.xml | 50 --- .../dubbo/registry/dns/DNSRegistry.java | 58 --- .../registry/dns/DNSRegistryFactory.java | 34 -- .../registry/dns/DNSServiceDiscovery.java | 154 -------- .../dns/DNSServiceDiscoveryFactory.java | 28 -- .../registry/dns/util/DNSClientConst.java | 47 --- .../dubbo/registry/dns/util/DNSResolver.java | 120 ------ .../registry/dns/util/ResolveResult.java | 66 ---- .../org.apache.dubbo.registry.RegistryFactory | 1 - ...che.dubbo.registry.client.ServiceDiscovery | 1 - ...bo.registry.client.ServiceDiscoveryFactory | 1 - .../registry/dns/DNSServiceDiscoveryTest.java | 192 ---------- .../registry/dns/util/DNSResolverTest.java | 30 -- .../src/test/resources/dubbo.properties | 2 - .../dubbo-registry-etcd3/pom.xml | 4 +- .../dubbo-registry-nameservice/pom.xml | 2 +- .../dubbo-registry-polaris/pom.xml | 2 +- .../dubbo-registry-redis/pom.xml | 4 +- .../dubbo-registry-sofa/pom.xml | 2 +- dubbo-registry-extensions/pom.xml | 1 - .../dubbo-remoting-etcd3/pom.xml | 2 +- .../dubbo-remoting-grizzly/pom.xml | 2 +- .../dubbo-remoting-mina/pom.xml | 2 +- .../transport/mina/ClientToServerTest.java | 2 + .../mina/MinaClientToServerTest.java | 2 + .../resources/security/serialize.allowlist | 21 ++ .../dubbo-remoting-p2p/pom.xml | 2 +- .../dubbo-remoting-quic/pom.xml | 2 +- .../dubbo-remoting-redis/pom.xml | 2 +- .../redis/jedis/ClusterRedisClient.java | 10 +- .../remoting/redis/jedis/MonoRedisClient.java | 16 +- .../redis/jedis/SentinelRedisClient.java | 22 +- .../dubbo-rpc-hessian/pom.xml | 4 +- dubbo-rpc-extensions/dubbo-rpc-http/pom.xml | 2 +- .../dubbo-rpc-memcached/pom.xml | 2 +- .../dubbo-rpc-native-thrift/pom.xml | 2 +- dubbo-rpc-extensions/dubbo-rpc-redis/pom.xml | 2 +- dubbo-rpc-extensions/dubbo-rpc-rmi/pom.xml | 2 +- .../dubbo-rpc-rocketmq/pom.xml | 2 +- .../rpc/rocketmq/codec/RocketMQCodec.java | 2 +- .../dubbo-rpc-webservice/pom.xml | 2 +- .../dubbo-serialization-avro/pom.xml | 2 +- .../dubbo-serialization-fastjson/pom.xml | 2 +- .../dubbo-serialization-fst/pom.xml | 2 +- .../dubbo-serialization-fury/pom.xml | 3 - .../fury/dubbo/FuryCheckerListener.java | 52 +-- .../dubbo-serialization-gson/pom.xml | 2 +- .../serialize/gson/GsonJsonObjectOutput.java | 2 +- .../dubbo-serialization-kryo/pom.xml | 2 +- .../dubbo-serialization-msgpack/pom.xml | 2 +- .../pom.xml | 2 +- .../dubbo-serialization-protobuf/pom.xml | 10 +- .../GenericProtobufJsonObjectOutput.java | 11 +- .../support/GenericProtobufObjectOutput.java | 10 +- .../support/ProtobufParamDeepCopyUtil.java | 64 ++++ ...dubbo.rpc.protocol.injvm.ParamDeepCopyUtil | 1 + .../dubbo-serialization-protostuff/pom.xml | 2 +- .../dubbo-serialization-test/pom.xml | 27 +- .../ProtobufParamDeepCopyUtilTest.java | 74 ++++ .../dubbo-tag-subnets/pom.xml | 2 +- pom.xml | 42 ++- test/dubbo-scenario-builder/pom.xml | 5 +- test/dubbo-test-runner/pom.xml | 5 +- test/pom.xml | 21 +- test/scenarios/pom.xml | 9 +- .../dubbo-serialization-avro-test/pom.xml | 9 +- .../dubbo-serialization-fastjson-test/pom.xml | 7 +- .../dubbo-serialization-fst-test/pom.xml | 7 +- .../dubbo-serialization-gson-test/pom.xml | 9 +- .../dubbo-serialization-kryo-test/pom.xml | 10 +- .../dubbo-serialization-protobuf-test/pom.xml | 10 +- .../resources/spring/dubbo-demo-provider.xml | 2 +- .../pom.xml | 7 +- .../dubbo-serialization-testcase/pom.xml | 3 +- .../scenarios-dubbo-serialization/pom.xml | 9 +- 130 files changed, 1803 insertions(+), 1971 deletions(-) create mode 100644 .github/dependabot.yaml create mode 100644 .github/workflows/build-and-test-pr.yml create mode 100644 .github/workflows/build-and-test-scheduled-3.0.yml delete mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/release-test.yml create mode 100644 .licenserc.yaml delete mode 100644 dubbo-gateway-extensions/dubbo-gateway-common/pom.xml delete mode 100644 dubbo-gateway-extensions/dubbo-gateway-common/src/main/java/org/apache/dubbo/gateway/common/OmnipotentCommonConstants.java delete mode 100644 dubbo-gateway-extensions/dubbo-gateway-consumer/pom.xml delete mode 100644 dubbo-gateway-extensions/dubbo-gateway-consumer/src/main/java/org/apache/dubbo/gateway/consumer/config/InjvmConfigPostProcessor.java delete mode 100644 dubbo-gateway-extensions/dubbo-gateway-consumer/src/main/java/org/apache/dubbo/gateway/consumer/filter/OmnSerFilter.java delete mode 100644 dubbo-gateway-extensions/dubbo-gateway-consumer/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.config.ConfigPostProcessor delete mode 100644 dubbo-gateway-extensions/dubbo-gateway-consumer/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter delete mode 100644 dubbo-gateway-extensions/dubbo-gateway-provider/pom.xml delete mode 100644 dubbo-gateway-extensions/dubbo-gateway-provider/src/main/java/org/apache/dubbo/gateway/provider/ConfigDeployListener.java delete mode 100644 dubbo-gateway-extensions/dubbo-gateway-provider/src/main/java/org/apache/dubbo/gateway/provider/OmnipotentService.java delete mode 100644 dubbo-gateway-extensions/dubbo-gateway-provider/src/main/java/org/apache/dubbo/gateway/provider/SnfByteAccessor.java delete mode 100644 dubbo-gateway-extensions/dubbo-gateway-provider/src/main/java/org/apache/dubbo/gateway/provider/SnfDecodeableRpcInvocation.java delete mode 100644 dubbo-gateway-extensions/dubbo-gateway-provider/src/main/java/org/apache/dubbo/gateway/provider/filter/OmnipotentFilter.java delete mode 100644 dubbo-gateway-extensions/dubbo-gateway-provider/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.deploy.ApplicationDeployListener delete mode 100644 dubbo-gateway-extensions/dubbo-gateway-provider/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter delete mode 100644 dubbo-gateway-extensions/dubbo-gateway-provider/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.dubbo.ByteAccessor delete mode 100644 dubbo-gateway-extensions/pom.xml delete mode 100644 dubbo-registry-extensions/dubbo-registry-dns/pom.xml delete mode 100644 dubbo-registry-extensions/dubbo-registry-dns/src/main/java/org/apache/dubbo/registry/dns/DNSRegistry.java delete mode 100644 dubbo-registry-extensions/dubbo-registry-dns/src/main/java/org/apache/dubbo/registry/dns/DNSRegistryFactory.java delete mode 100644 dubbo-registry-extensions/dubbo-registry-dns/src/main/java/org/apache/dubbo/registry/dns/DNSServiceDiscovery.java delete mode 100644 dubbo-registry-extensions/dubbo-registry-dns/src/main/java/org/apache/dubbo/registry/dns/DNSServiceDiscoveryFactory.java delete mode 100644 dubbo-registry-extensions/dubbo-registry-dns/src/main/java/org/apache/dubbo/registry/dns/util/DNSClientConst.java delete mode 100644 dubbo-registry-extensions/dubbo-registry-dns/src/main/java/org/apache/dubbo/registry/dns/util/DNSResolver.java delete mode 100644 dubbo-registry-extensions/dubbo-registry-dns/src/main/java/org/apache/dubbo/registry/dns/util/ResolveResult.java delete mode 100644 dubbo-registry-extensions/dubbo-registry-dns/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.RegistryFactory delete mode 100644 dubbo-registry-extensions/dubbo-registry-dns/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.ServiceDiscovery delete mode 100644 dubbo-registry-extensions/dubbo-registry-dns/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.ServiceDiscoveryFactory delete mode 100644 dubbo-registry-extensions/dubbo-registry-dns/src/test/java/org/apache/dubbo/registry/dns/DNSServiceDiscoveryTest.java delete mode 100644 dubbo-registry-extensions/dubbo-registry-dns/src/test/java/org/apache/dubbo/registry/dns/util/DNSResolverTest.java delete mode 100644 dubbo-registry-extensions/dubbo-registry-dns/src/test/resources/dubbo.properties create mode 100644 dubbo-remoting-extensions/dubbo-remoting-mina/src/test/resources/security/serialize.allowlist create mode 100644 dubbo-serialization-extensions/dubbo-serialization-protobuf/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/ProtobufParamDeepCopyUtil.java create mode 100644 dubbo-serialization-extensions/dubbo-serialization-protobuf/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.injvm.ParamDeepCopyUtil create mode 100644 dubbo-serialization-extensions/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/protobuf/support/ProtobufParamDeepCopyUtilTest.java diff --git a/.codecov.yml b/.codecov.yml index 1acf443bc..8a9fd1bbf 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -1,3 +1,18 @@ +# 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. +# coverage: status: # pull-requests only diff --git a/.github/dependabot.yaml b/.github/dependabot.yaml new file mode 100644 index 000000000..805733a69 --- /dev/null +++ b/.github/dependabot.yaml @@ -0,0 +1,15 @@ +version: 2 +updates: + + - package-ecosystem: "maven" + directory: "/" + open-pull-requests-limit: 20 + # Ignore major version updates + ignore: + - dependency-name: "*" + update-types: ["version-update:semver-major"] + schedule: + interval: "weekly" + day: "monday" + time: "03:00" + timezone: "US/Eastern" diff --git a/.github/workflows/build-and-test-pr.yml b/.github/workflows/build-and-test-pr.yml new file mode 100644 index 000000000..c9a96e594 --- /dev/null +++ b/.github/workflows/build-and-test-pr.yml @@ -0,0 +1,340 @@ +name: Build and Test For PR + +on: [push, pull_request, workflow_dispatch] + +permissions: + contents: read + +env: + FORK_COUNT: 2 + FAIL_FAST: 0 + SHOW_ERROR_DETAIL: 1 + #multi-version size limit + VERSIONS_LIMIT: 4 + JACOCO_ENABLE: true + CANDIDATE_VERSIONS: ' + spring.version:5.3.24; + spring-boot.version:2.7.6; + ' + +jobs: + # Check ASF License + check-license: + name: "Check License" + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Check License + uses: apache/skywalking-eyes@v0.5.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: "Set up JDK 21" + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: 21 + - name: Restore Maven local repository cache + uses: actions/cache@v4 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + - name: Check Dependencies' License + uses: apache/skywalking-eyes/dependency@e1a02359b239bd28de3f6d35fdc870250fa513d5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + config: .licenserc.yaml + mode: check + # Build dubbo-build-tool + build-tools: + name: "Build-tools" + needs: check-license + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ ubuntu-latest, windows-latest ] + fail-fast: false + outputs: + cache-key: ${{ steps.dubbo-build-tools.cache }} + steps: + - name: Support long paths on Windows + if: ${{ startsWith( matrix.os, 'windows') }} + run: git config --system core.longpaths true + - uses: actions/checkout@v4 + name: build tools + with: + repository: 'apache/dubbo' + ref: '3.2' + path: dubbo + - name: "Set up JDK 21" + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: 21 + - uses: actions/cache@v4 + name: "Cache local Maven repository" + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + - name: "Build tools" + run: | + cd ./dubbo + ./mvnw --batch-mode -U -e --no-transfer-progress install -pl dubbo-build-tools -am -DskipTests=true + # Build from source code + build-source: + name: "Build Dubbo-SPI-Extensions" + needs: [check-license, build-tools] + runs-on: ubuntu-latest + # output dubbo-spi-extensions version to others jobs + outputs: + version: ${{ steps.dubbo-spi-extensions-version.outputs.version }} + steps: + - uses: actions/checkout@v4 + with: + path: dubbo-spi-extensions + - uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: 8 + - uses: actions/cache@v4 + name: "Cache local Maven repository" + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}-${{ github.run_id }} + restore-keys: | + ${{ runner.os }}-maven- + ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + - name: "Compile Dubbo-SPI-Extensions (Linux)" + run: | + cd ./dubbo-spi-extensions + ./mvnw --batch-mode --no-snapshot-updates -e --no-transfer-progress --fail-fast -T 2C clean compile -DskipTests=true -DskipIntegrationTests=true -Dcheckstyle.skip=true -Dcheckstyle_unix.skip=true -Drat.skip=true -Dmaven.javadoc.skip=true + - name: "Build Dubbo-SPI-Extensions with Maven" + run: | + cd ./dubbo-spi-extensions + ./mvnw --batch-mode --no-snapshot-updates -e --no-transfer-progress --fail-fast clean source:jar install -Pjacoco,checkstyle -Dmaven.wagon.httpconnectionManager.ttlSeconds=120 -Dmaven.wagon.http.retryHandler.count=5 -Dmaven.test.skip=true -Dmaven.test.skip.exec=true -DembeddedZookeeperPath=${{ github.workspace }}/.tmp/zookeeper + - name: "Pack class result" + run: | + shopt -s globstar + zip ${{ github.workspace }}/class.zip **/target/classes/* -r + - name: "Upload class result" + uses: actions/upload-artifact@v4 + with: + name: "class-file" + path: ${{ github.workspace }}/class.zip + - name: "Pack checkstyle file if failure" + if: failure() + run: zip ${{ github.workspace }}/checkstyle.zip *checkstyle* -r + - name: "Upload checkstyle file if failure" + if: failure() + uses: actions/upload-artifact@v4 + with: + name: "checkstyle-file" + path: ${{ github.workspace }}/checkstyle.zip + - name: "Calculate Dubbo-SPI-Extensions Version" + id: dubbo-spi-extensions-version + run: | + REVISION=`awk '/[^<]+<\/revision>/{gsub(/|<\/revision>/,"",$1);print $1;exit;}' ./dubbo-spi-extensions/pom.xml` + echo "version=$REVISION" >> $GITHUB_OUTPUT + echo "dubbo-spi-extensions version: $REVISION" + # Download dependencies Prepare for unit test + unit-test-prepare: + name: "Preparation for Unit Test On ${{ matrix.os }}" + needs: [check-license] + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ ubuntu-latest, windows-latest ] + fail-fast: false + env: + ZOOKEEPER_VERSION: 3.6.3 + steps: + - uses: actions/cache@v4 + name: "Cache zookeeper binary archive" + id: "cache-zookeeper" + with: + path: ${{ github.workspace }}/.tmp/zookeeper + key: zookeeper-${{ runner.os }}-${{ env.ZOOKEEPER_VERSION }} + restore-keys: | + zookeeper-${{ runner.os }}-${{ env.ZOOKEEPER_VERSION }} + - name: "Set up msys2 if necessary" + if: ${{ startsWith( matrix.os, 'windows') && steps.cache-zookeeper.outputs.cache-hit != 'true' }} + uses: msys2/setup-msys2@v2 + with: + release: false # support cache, see https://github.com/msys2/setup-msys2#context + - name: "Download zookeeper binary archive in Linux OS" + if: ${{ startsWith( matrix.os, 'ubuntu') && steps.cache-zookeeper.outputs.cache-hit != 'true' }} + run: | + mkdir -p ${{ github.workspace }}/.tmp/zookeeper + wget -c https://archive.apache.org/dist/zookeeper/zookeeper-${{ env.ZOOKEEPER_VERSION }}/apache-zookeeper-${{ env.ZOOKEEPER_VERSION }}-bin.tar.gz -O ${{ github.workspace }}/.tmp/zookeeper/apache-zookeeper-bin.tar.gz || + wget -c https://apache.website-solution.net/zookeeper/zookeeper-${{ env.ZOOKEEPER_VERSION }}/apache-zookeeper-${{ env.ZOOKEEPER_VERSION }}-bin.tar.gz -O ${{ github.workspace }}/.tmp/zookeeper/apache-zookeeper-bin.tar.gz || + wget -c http://apache.stu.edu.tw/zookeeper/zookeeper-${{ env.ZOOKEEPER_VERSION }}/apache-zookeeper-${{ env.ZOOKEEPER_VERSION }}-bin.tar.gz -O ${{ github.workspace }}/.tmp/zookeeper/apache-zookeeper-bin.tar.gz || + wget -c http://ftp.jaist.ac.jp/pub/apache/zookeeper/zookeeper-${{ env.ZOOKEEPER_VERSION }}/apache-zookeeper-${{ env.ZOOKEEPER_VERSION }}-bin.tar.gz -O ${{ github.workspace }}/.tmp/zookeeper/apache-zookeeper-bin.tar.gz || + wget -c http://apache.mirror.cdnetworks.com/zookeeper/zookeeper-${{ env.ZOOKEEPER_VERSION }}/apache-zookeeper-${{ env.ZOOKEEPER_VERSION }}-bin.tar.gz -O ${{ github.workspace }}/.tmp/zookeeper/apache-zookeeper-bin.tar.gz || + wget -c http://mirror.apache-kr.org/apache/zookeeper/zookeeper-${{ env.ZOOKEEPER_VERSION }}/apache-zookeeper-${{ env.ZOOKEEPER_VERSION }}-bin.tar.gz -O ${{ github.workspace }}/.tmp/zookeeper/apache-zookeeper-bin.tar.gz + echo "list the downloaded zookeeper binary archive" + ls -al ${{ github.workspace }}/.tmp/zookeeper/apache-zookeeper-bin.tar.gz + - name: "Download zookeeper binary archive in Windows OS" + if: ${{ startsWith( matrix.os, 'windows') && steps.cache-zookeeper.outputs.cache-hit != 'true' }} + shell: msys2 {0} + run: | + mkdir -p ${{ github.workspace }}/.tmp/zookeeper + wget -c https://archive.apache.org/dist/zookeeper/zookeeper-${{ env.ZOOKEEPER_VERSION }}/apache-zookeeper-${{ env.ZOOKEEPER_VERSION }}-bin.tar.gz -O ${{ github.workspace }}/.tmp/zookeeper/apache-zookeeper-bin.tar.gz || + wget -c https://apache.website-solution.net/zookeeper/zookeeper-${{ env.ZOOKEEPER_VERSION }}/apache-zookeeper-${{ env.ZOOKEEPER_VERSION }}-bin.tar.gz -O ${{ github.workspace }}/.tmp/zookeeper/apache-zookeeper-bin.tar.gz || + wget -c http://apache.stu.edu.tw/zookeeper/zookeeper-${{ env.ZOOKEEPER_VERSION }}/apache-zookeeper-${{ env.ZOOKEEPER_VERSION }}-bin.tar.gz -O ${{ github.workspace }}/.tmp/zookeeper/apache-zookeeper-bin.tar.gz || + wget -c http://ftp.jaist.ac.jp/pub/apache/zookeeper/zookeeper-${{ env.ZOOKEEPER_VERSION }}/apache-zookeeper-${{ env.ZOOKEEPER_VERSION }}-bin.tar.gz -O ${{ github.workspace }}/.tmp/zookeeper/apache-zookeeper-bin.tar.gz || + wget -c http://apache.mirror.cdnetworks.com/zookeeper/zookeeper-${{ env.ZOOKEEPER_VERSION }}/apache-zookeeper-${{ env.ZOOKEEPER_VERSION }}-bin.tar.gz -O ${{ github.workspace }}/.tmp/zookeeper/apache-zookeeper-bin.tar.gz || + wget -c http://mirror.apache-kr.org/apache/zookeeper/zookeeper-${{ env.ZOOKEEPER_VERSION }}/apache-zookeeper-${{ env.ZOOKEEPER_VERSION }}-bin.tar.gz -O ${{ github.workspace }}/.tmp/zookeeper/apache-zookeeper-bin.tar.gz + echo "list the downloaded zookeeper binary archive" + ls -al ${{ github.workspace }}/.tmp/zookeeper/apache-zookeeper-bin.tar.gz + - uses: actions/cache@v4 + name: "Cache secret key" + id: "cache-secret-cert" + with: + path: ${{ github.workspace }}/.tmp/rsa + key: secret-rsa-${{ runner.os }}-${{ github.run_id }} + - name: "Create Secret" + run: | + mkdir -p ${{ github.workspace }}/.tmp/rsa + cd ${{ github.workspace }}/.tmp/rsa + openssl genrsa -out rsa_private.pem 1024 + openssl rsa -in rsa_private.pem -pubout -out rsa_public.pem + echo "Current workflow run id: ${{ github.run_id }}" + echo "Start Print Rsa Public Key ---" + cat rsa_public.pem + echo "--- End Print Rsa Public Key" + # Start unit test + unit-test: + needs: [check-license, build-source, unit-test-prepare] + name: "Unit Test ${{ matrix.os }} with JDK ${{ matrix.jdk }}" + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ ubuntu-latest, windows-latest ] + jdk: [ 8, 11 ] + fail-fast: false + env: + DISABLE_FILE_SYSTEM_TEST: true + CURRENT_ROLE: ${{ matrix.case-role }} + DUBBO_DEFAULT_SERIALIZATION: fastjson2 + steps: + - name: Support Windows + if: ${{ startsWith( matrix.os, 'windows') }} + run: | + git config --system core.longpaths true + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: "Set up JDK ${{ matrix.jdk }}" + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: 8 + - uses: actions/cache@v4 + name: "Cache local Maven repository" + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}-${{ github.run_id }} + restore-keys: | + ${{ runner.os }}-maven- + ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + - uses: actions/cache@v4 + name: "Cache zookeeper binary archive" + id: "cache-zookeeper" + with: + path: ${{ github.workspace }}/.tmp/zookeeper + key: zookeeper-${{ runner.os }}-${{ env.ZOOKEEPER_VERSION }} + restore-keys: | + zookeeper-${{ runner.os }}- + - uses: actions/cache@v4 + name: "Cache secret key" + id: "cache-secret-cert" + with: + path: ${{ github.workspace }}/.tmp/rsa + key: secret-rsa-${{ runner.os }}-${{ github.run_id }} + # - name: "Get sonarcloud token" + # if: ${{ github.repository == 'apache/dubbo-spi-extensions' }} + # run: | + # curl "http://dubbo-vm.apache.org:8000/token?workflow_id=${{ github.run_id }}" -o ${{ github.workspace }}/.tmp/encrypted-sonarcloud-token + # openssl rsautl -decrypt -in ${{ github.workspace }}/.tmp/encrypted-sonarcloud-token -out ${{ github.workspace }}/.tmp/decrypted-sonarcloud-token -inkey ${{ github.workspace }}/.tmp/rsa/rsa_private.pem + # - name: "Test with Maven with SonarCloud Scan" + # if: ${{ github.repository == 'apache/dubbo-spi-extensions' }} + # timeout-minutes: 70 + # env: + # # Needed to get some information about the pull request, if any + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # run: | + # source ${{ github.workspace }}/.tmp/decrypted-sonarcloud-token + # ./mvnw --batch-mode --no-snapshot-updates -e --no-transfer-progress --fail-fast clean test verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Pjacoco,jdk15ge-simple,'!jdk15ge',jacoco089 -Dsonar.host.url=https://sonarcloud.io -Dsonar.organization=apache -Dsonar.projectKey=apache_dubbo -DtrimStackTrace=false -Dmaven.wagon.httpconnectionManager.ttlSeconds=120 -Dmaven.wagon.http.retryHandler.count=5 -DskipTests=false -DskipIntegrationTests=false -Dcheckstyle.skip=false -Dcheckstyle_unix.skip=false -Drat.skip=false -Dmaven.javadoc.skip=true -DembeddedZookeeperPath=${{ github.workspace }}/.tmp/zookeeper -Dsonar.coverage.jacoco.xmlReportPaths=dubbo-test/dubbo-dependencies-all/target/site/jacoco-aggregate/jacoco.xml -Dsonar.login=${SONAR_TOKEN} + - name: "Test with Maven without SonarCloud Scan On Linux" + if: ${{ startsWith( matrix.os, 'linux') || startsWith( matrix.os, 'ubuntu') }} + timeout-minutes: 70 + run: | + ./mvnw --batch-mode --no-snapshot-updates -e --no-transfer-progress --fail-fast clean test verify -D"maven.wagon.httpconnectionManager.ttlSeconds=120" -Pjacoco -DtrimStackTrace=false -D"maven.wagon.http.retryHandler.count=5" -DskipTests=false -DskipIntegrationTests=false -D"checkstyle.skip=false" -D"checkstyle_unix.skip=false" -D"rat.skip=false" -D"maven.javadoc.skip=true" -D"embeddedZookeeperPath=${{ github.workspace }}/.tmp/zookeeper" + - name: "Test with Maven without SonarCloud Scan On Windows" + if: ${{ startsWith( matrix.os, 'windows') }} + timeout-minutes: 70 + run: | + ./mvnw --batch-mode --no-snapshot-updates -e --no-transfer-progress --fail-fast clean test verify -D"maven.wagon.httpconnectionManager.ttlSeconds=120" -Pjacoco -DtrimStackTrace=false -D"maven.wagon.http.retryHandler.count=5" -DskipTests=false -DskipIntegrationTests=false -D"checkstyle.skip=false" -D"checkstyle_unix.skip=true" -D"rat.skip=false" -D"maven.javadoc.skip=true" -D"embeddedZookeeperPath=${{ github.workspace }}/.tmp/zookeeper" + - name: "Upload surefire-reports if failure" + if: ${{ failure() }} + uses: actions/upload-artifact@v4 + with: + name: surefire-reports-${{ matrix.os }}-${{ matrix.jdk }} + path: "**/target/surefire-reports/**" + - name: "Upload coverage result" + uses: actions/upload-artifact@v4 + with: + name: coverage-result-${{ matrix.os }}-${{ matrix.jdk }} + path: "**/target/site/**/jacoco.xml" + - name: "Upload coverage to Codecov" + uses: codecov/codecov-action@v4 + +# error-code-inspecting: +# needs: [check-license, build-tools] +# runs-on: ubuntu-latest +# steps: +# - uses: actions/checkout@v4 +# with: +# path: "./dubbo-spi-extensions" +# - uses: actions/checkout@v4 +# with: +# repository: 'apache/dubbo-test-tools' +# ref: main +# path: "./dubbo-test-tools" +# - name: "Set up JDK 21" +# uses: actions/setup-java@v4 +# with: +# distribution: 'zulu' +# java-version: 21 +# - name: Restore Maven local repository cache +# uses: actions/cache@v4 +# with: +# path: ~/.m2/repository +# key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} +# restore-keys: | +# ${{ runner.os }}-maven- +# ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} +# - name: "Compile Dubbo-SPI-Extensions (Linux)" +# run: | +# cd ${{ github.workspace }}/dubbo-spi-extensions +# ./mvnw --batch-mode --no-snapshot-updates -e --no-transfer-progress --fail-fast -T 2C clean install -DskipTests=true -DskipIntegrationTests=true -Dcheckstyle.skip=true -Dcheckstyle_unix.skip=true -Drat.skip=true -Dmaven.javadoc.skip=true +# - name: "Run Error Code Inspecting" +# env: +# DUBBO_ECI_REPORT_AS_ERROR: true +# run: | +# cd ${{ github.workspace }}/dubbo-test-tools/dubbo-error-code-inspector +# ../mvnw --batch-mode --no-snapshot-updates -e --no-transfer-progress --fail-fast -T 2C package exec:java -Ddubbo.eci.report-as-error=${DUBBO_ECI_REPORT_AS_ERROR} -Dmaven.test.skip=true -Dmaven.test.skip.exec=true -Ddubbo.eci.path=${{ github.workspace }}/dubbo-spi-extensions +# - name: "Upload error code inspection result" +# # always() should not be used here, since we don't need to handle the 'canceled' situation. +# if: ${{ success() || failure() }} +# uses: actions/upload-artifact@v4 +# with: +# name: "error-inspection-result" +# path: ${{ github.workspace }}/dubbo-test-tools/dubbo-error-code-inspector/error-inspection-result.txt diff --git a/.github/workflows/build-and-test-scheduled-3.0.yml b/.github/workflows/build-and-test-scheduled-3.0.yml new file mode 100644 index 000000000..1d195b28a --- /dev/null +++ b/.github/workflows/build-and-test-scheduled-3.0.yml @@ -0,0 +1,346 @@ +name: Build and Test Scheduled On 3.0 + +on: + schedule: + - cron: '0 0/6 * * *' + workflow_dispatch: + +permissions: + contents: read + +env: + FORK_COUNT: 2 + FAIL_FAST: 0 + SHOW_ERROR_DETAIL: 1 + #multi-version size limit + VERSIONS_LIMIT: 4 + JACOCO_ENABLE: true + CANDIDATE_VERSIONS: ' + spring.version:5.3.24; + spring-boot.version:2.7.6; + ' + +jobs: + # Check ASF License + check-license: + name: "Check License" + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + ref: '3.0.0' + - name: Check License + uses: apache/skywalking-eyes@v0.5.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: "Set up JDK 21" + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: 21 + - name: Restore Maven local repository cache + uses: actions/cache@v4 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + - name: Check Dependencies' License + uses: apache/skywalking-eyes/dependency@e1a02359b239bd28de3f6d35fdc870250fa513d5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + config: .licenserc.yaml + mode: check + # Build dubbo-build-tool + build-tools: + name: "Build-tools" + needs: check-license + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ ubuntu-latest, windows-latest ] + fail-fast: false + outputs: + cache-key: ${{ steps.dubbo-build-tools.cache }} + steps: + - name: Support long paths on Windows + if: ${{ startsWith( matrix.os, 'windows') }} + run: git config --system core.longpaths true + - uses: actions/checkout@v4 + name: build tools + with: + repository: 'apache/dubbo' + ref: '3.0' + path: dubbo + - name: "Set up JDK 21" + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: 21 + - uses: actions/cache@v4 + name: "Cache local Maven repository" + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + - name: "Build tools" + run: | + cd ./dubbo + ./mvnw --batch-mode -U -e --no-transfer-progress install -pl dubbo-build-tools -am -DskipTests=true + # Build from source code + build-source: + name: "Build Dubbo-SPI-Extensions" + needs: [check-license, build-tools] + runs-on: ubuntu-latest + # output dubbo-spi-extensions version to others jobs + outputs: + version: ${{ steps.dubbo-spi-extensions-version.outputs.version }} + steps: + - uses: actions/checkout@v4 + with: + ref: "3.0.0" + path: dubbo-spi-extensions + - uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: 8 + - uses: actions/cache@v4 + name: "Cache local Maven repository" + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}-${{ github.run_id }} + restore-keys: | + ${{ runner.os }}-maven- + ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + - name: "Compile Dubbo-SPI-Extensions (Linux)" + run: | + cd ./dubbo-spi-extensions + ./mvnw --batch-mode --no-snapshot-updates -e --no-transfer-progress --fail-fast -T 2C clean compile -DskipTests=true -DskipIntegrationTests=true -Dcheckstyle.skip=true -Dcheckstyle_unix.skip=true -Drat.skip=true -Dmaven.javadoc.skip=true + - name: "Build Dubbo-SPI-Extensions with Maven" + run: | + cd ./dubbo-spi-extensions + ./mvnw --batch-mode --no-snapshot-updates -e --no-transfer-progress --fail-fast clean source:jar install -Pjacoco,checkstyle -Dmaven.wagon.httpconnectionManager.ttlSeconds=120 -Dmaven.wagon.http.retryHandler.count=5 -Dmaven.test.skip=true -Dmaven.test.skip.exec=true -DembeddedZookeeperPath=${{ github.workspace }}/.tmp/zookeeper + - name: "Pack class result" + run: | + shopt -s globstar + zip ${{ github.workspace }}/class.zip **/target/classes/* -r + - name: "Upload class result" + uses: actions/upload-artifact@v4 + with: + name: "class-file" + path: ${{ github.workspace }}/class.zip + - name: "Pack checkstyle file if failure" + if: failure() + run: zip ${{ github.workspace }}/checkstyle.zip *checkstyle* -r + - name: "Upload checkstyle file if failure" + if: failure() + uses: actions/upload-artifact@v4 + with: + name: "checkstyle-file" + path: ${{ github.workspace }}/checkstyle.zip + - name: "Calculate Dubbo-SPI-Extensions Version" + id: dubbo-spi-extensions-version + run: | + REVISION=`awk '/[^<]+<\/revision>/{gsub(/|<\/revision>/,"",$1);print $1;exit;}' ./dubbo-spi-extensions/pom.xml` + echo "version=$REVISION" >> $GITHUB_OUTPUT + echo "dubbo-spi-extensions version: $REVISION" + # Download dependencies Prepare for unit test + unit-test-prepare: + name: "Preparation for Unit Test On ${{ matrix.os }}" + needs: [check-license] + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ ubuntu-latest, windows-latest ] + fail-fast: false + env: + ZOOKEEPER_VERSION: 3.6.3 + steps: + - uses: actions/cache@v4 + name: "Cache zookeeper binary archive" + id: "cache-zookeeper" + with: + path: ${{ github.workspace }}/.tmp/zookeeper + key: zookeeper-${{ runner.os }}-${{ env.ZOOKEEPER_VERSION }} + restore-keys: | + zookeeper-${{ runner.os }}-${{ env.ZOOKEEPER_VERSION }} + - name: "Set up msys2 if necessary" + if: ${{ startsWith( matrix.os, 'windows') && steps.cache-zookeeper.outputs.cache-hit != 'true' }} + uses: msys2/setup-msys2@v2 + with: + release: false # support cache, see https://github.com/msys2/setup-msys2#context + - name: "Download zookeeper binary archive in Linux OS" + if: ${{ startsWith( matrix.os, 'ubuntu') && steps.cache-zookeeper.outputs.cache-hit != 'true' }} + run: | + mkdir -p ${{ github.workspace }}/.tmp/zookeeper + wget -c https://archive.apache.org/dist/zookeeper/zookeeper-${{ env.ZOOKEEPER_VERSION }}/apache-zookeeper-${{ env.ZOOKEEPER_VERSION }}-bin.tar.gz -O ${{ github.workspace }}/.tmp/zookeeper/apache-zookeeper-bin.tar.gz || + wget -c https://apache.website-solution.net/zookeeper/zookeeper-${{ env.ZOOKEEPER_VERSION }}/apache-zookeeper-${{ env.ZOOKEEPER_VERSION }}-bin.tar.gz -O ${{ github.workspace }}/.tmp/zookeeper/apache-zookeeper-bin.tar.gz || + wget -c http://apache.stu.edu.tw/zookeeper/zookeeper-${{ env.ZOOKEEPER_VERSION }}/apache-zookeeper-${{ env.ZOOKEEPER_VERSION }}-bin.tar.gz -O ${{ github.workspace }}/.tmp/zookeeper/apache-zookeeper-bin.tar.gz || + wget -c http://ftp.jaist.ac.jp/pub/apache/zookeeper/zookeeper-${{ env.ZOOKEEPER_VERSION }}/apache-zookeeper-${{ env.ZOOKEEPER_VERSION }}-bin.tar.gz -O ${{ github.workspace }}/.tmp/zookeeper/apache-zookeeper-bin.tar.gz || + wget -c http://apache.mirror.cdnetworks.com/zookeeper/zookeeper-${{ env.ZOOKEEPER_VERSION }}/apache-zookeeper-${{ env.ZOOKEEPER_VERSION }}-bin.tar.gz -O ${{ github.workspace }}/.tmp/zookeeper/apache-zookeeper-bin.tar.gz || + wget -c http://mirror.apache-kr.org/apache/zookeeper/zookeeper-${{ env.ZOOKEEPER_VERSION }}/apache-zookeeper-${{ env.ZOOKEEPER_VERSION }}-bin.tar.gz -O ${{ github.workspace }}/.tmp/zookeeper/apache-zookeeper-bin.tar.gz + echo "list the downloaded zookeeper binary archive" + ls -al ${{ github.workspace }}/.tmp/zookeeper/apache-zookeeper-bin.tar.gz + - name: "Download zookeeper binary archive in Windows OS" + if: ${{ startsWith( matrix.os, 'windows') && steps.cache-zookeeper.outputs.cache-hit != 'true' }} + shell: msys2 {0} + run: | + mkdir -p ${{ github.workspace }}/.tmp/zookeeper + wget -c https://archive.apache.org/dist/zookeeper/zookeeper-${{ env.ZOOKEEPER_VERSION }}/apache-zookeeper-${{ env.ZOOKEEPER_VERSION }}-bin.tar.gz -O ${{ github.workspace }}/.tmp/zookeeper/apache-zookeeper-bin.tar.gz || + wget -c https://apache.website-solution.net/zookeeper/zookeeper-${{ env.ZOOKEEPER_VERSION }}/apache-zookeeper-${{ env.ZOOKEEPER_VERSION }}-bin.tar.gz -O ${{ github.workspace }}/.tmp/zookeeper/apache-zookeeper-bin.tar.gz || + wget -c http://apache.stu.edu.tw/zookeeper/zookeeper-${{ env.ZOOKEEPER_VERSION }}/apache-zookeeper-${{ env.ZOOKEEPER_VERSION }}-bin.tar.gz -O ${{ github.workspace }}/.tmp/zookeeper/apache-zookeeper-bin.tar.gz || + wget -c http://ftp.jaist.ac.jp/pub/apache/zookeeper/zookeeper-${{ env.ZOOKEEPER_VERSION }}/apache-zookeeper-${{ env.ZOOKEEPER_VERSION }}-bin.tar.gz -O ${{ github.workspace }}/.tmp/zookeeper/apache-zookeeper-bin.tar.gz || + wget -c http://apache.mirror.cdnetworks.com/zookeeper/zookeeper-${{ env.ZOOKEEPER_VERSION }}/apache-zookeeper-${{ env.ZOOKEEPER_VERSION }}-bin.tar.gz -O ${{ github.workspace }}/.tmp/zookeeper/apache-zookeeper-bin.tar.gz || + wget -c http://mirror.apache-kr.org/apache/zookeeper/zookeeper-${{ env.ZOOKEEPER_VERSION }}/apache-zookeeper-${{ env.ZOOKEEPER_VERSION }}-bin.tar.gz -O ${{ github.workspace }}/.tmp/zookeeper/apache-zookeeper-bin.tar.gz + echo "list the downloaded zookeeper binary archive" + ls -al ${{ github.workspace }}/.tmp/zookeeper/apache-zookeeper-bin.tar.gz + - uses: actions/cache@v4 + name: "Cache secret key" + id: "cache-secret-cert" + with: + path: ${{ github.workspace }}/.tmp/rsa + key: secret-rsa-${{ runner.os }}-${{ github.run_id }} + - name: "Create Secret" + run: | + mkdir -p ${{ github.workspace }}/.tmp/rsa + cd ${{ github.workspace }}/.tmp/rsa + openssl genrsa -out rsa_private.pem 1024 + openssl rsa -in rsa_private.pem -pubout -out rsa_public.pem + echo "Current workflow run id: ${{ github.run_id }}" + echo "Start Print Rsa Public Key ---" + cat rsa_public.pem + echo "--- End Print Rsa Public Key" + # Start unit test + unit-test: + needs: [check-license, build-source, unit-test-prepare] + name: "Unit Test ${{ matrix.os }} with JDK ${{ matrix.jdk }}" + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ ubuntu-latest, windows-latest ] + jdk: [ 8, 11 ] + fail-fast: false + env: + DISABLE_FILE_SYSTEM_TEST: true + CURRENT_ROLE: ${{ matrix.case-role }} + DUBBO_DEFAULT_SERIALIZATION: fastjson2 + steps: + - name: Support Windows + if: ${{ startsWith( matrix.os, 'windows') }} + run: | + git config --system core.longpaths true + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: "Set up JDK ${{ matrix.jdk }}" + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: 8 + - uses: actions/cache@v4 + name: "Cache local Maven repository" + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}-${{ github.run_id }} + restore-keys: | + ${{ runner.os }}-maven- + ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + - uses: actions/cache@v4 + name: "Cache zookeeper binary archive" + id: "cache-zookeeper" + with: + path: ${{ github.workspace }}/.tmp/zookeeper + key: zookeeper-${{ runner.os }}-${{ env.ZOOKEEPER_VERSION }} + restore-keys: | + zookeeper-${{ runner.os }}- + - uses: actions/cache@v4 + name: "Cache secret key" + id: "cache-secret-cert" + with: + path: ${{ github.workspace }}/.tmp/rsa + key: secret-rsa-${{ runner.os }}-${{ github.run_id }} + # - name: "Get sonarcloud token" + # if: ${{ github.repository == 'apache/dubbo-spi-extensions' }} + # run: | + # curl "http://dubbo-vm.apache.org:8000/token?workflow_id=${{ github.run_id }}" -o ${{ github.workspace }}/.tmp/encrypted-sonarcloud-token + # openssl rsautl -decrypt -in ${{ github.workspace }}/.tmp/encrypted-sonarcloud-token -out ${{ github.workspace }}/.tmp/decrypted-sonarcloud-token -inkey ${{ github.workspace }}/.tmp/rsa/rsa_private.pem + # - name: "Test with Maven with SonarCloud Scan" + # if: ${{ github.repository == 'apache/dubbo-spi-extensions' }} + # timeout-minutes: 70 + # env: + # # Needed to get some information about the pull request, if any + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # run: | + # source ${{ github.workspace }}/.tmp/decrypted-sonarcloud-token + # ./mvnw --batch-mode --no-snapshot-updates -e --no-transfer-progress --fail-fast clean test verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Pjacoco,jdk15ge-simple,'!jdk15ge',jacoco089 -Dsonar.host.url=https://sonarcloud.io -Dsonar.organization=apache -Dsonar.projectKey=apache_dubbo -DtrimStackTrace=false -Dmaven.wagon.httpconnectionManager.ttlSeconds=120 -Dmaven.wagon.http.retryHandler.count=5 -DskipTests=false -DskipIntegrationTests=false -Dcheckstyle.skip=false -Dcheckstyle_unix.skip=false -Drat.skip=false -Dmaven.javadoc.skip=true -DembeddedZookeeperPath=${{ github.workspace }}/.tmp/zookeeper -Dsonar.coverage.jacoco.xmlReportPaths=dubbo-test/dubbo-dependencies-all/target/site/jacoco-aggregate/jacoco.xml -Dsonar.login=${SONAR_TOKEN} + - name: "Test with Maven without SonarCloud Scan On Linux" + if: ${{ startsWith( matrix.os, 'linux') || startsWith( matrix.os, 'ubuntu') }} + timeout-minutes: 70 + run: | + ./mvnw --batch-mode --no-snapshot-updates -e --no-transfer-progress --fail-fast clean test verify -D"maven.wagon.httpconnectionManager.ttlSeconds=120" -Pjacoco -DtrimStackTrace=false -D"maven.wagon.http.retryHandler.count=5" -DskipTests=false -DskipIntegrationTests=false -D"checkstyle.skip=false" -D"checkstyle_unix.skip=false" -D"rat.skip=false" -D"maven.javadoc.skip=true" -D"embeddedZookeeperPath=${{ github.workspace }}/.tmp/zookeeper" + - name: "Test with Maven without SonarCloud Scan On Windows" + if: ${{ startsWith( matrix.os, 'windows') }} + timeout-minutes: 70 + run: | + ./mvnw --batch-mode --no-snapshot-updates -e --no-transfer-progress --fail-fast clean test verify -D"maven.wagon.httpconnectionManager.ttlSeconds=120" -Pjacoco -DtrimStackTrace=false -D"maven.wagon.http.retryHandler.count=5" -DskipTests=false -DskipIntegrationTests=false -D"checkstyle.skip=false" -D"checkstyle_unix.skip=true" -D"rat.skip=false" -D"maven.javadoc.skip=true" -D"embeddedZookeeperPath=${{ github.workspace }}/.tmp/zookeeper" + - name: "Upload surefire-reports if failure" + if: ${{ failure() }} + uses: actions/upload-artifact@v4 + with: + name: surefire-reports-${{ matrix.os }}-${{ matrix.jdk }} + path: "**/target/surefire-reports/**" + - name: "Upload coverage result" + uses: actions/upload-artifact@v4 + with: + name: coverage-result-${{ matrix.os }}-${{ matrix.jdk }} + path: "**/target/site/**/jacoco.xml" + - name: "Upload coverage to Codecov" + uses: codecov/codecov-action@v4 + +# error-code-inspecting: +# needs: [check-license, build-tools] +# runs-on: ubuntu-latest +# steps: +# - uses: actions/checkout@v4 +# with: +# path: "./dubbo-spi-extensions" +# - uses: actions/checkout@v4 +# with: +# repository: 'apache/dubbo-test-tools' +# ref: main +# path: "./dubbo-test-tools" +# - name: "Set up JDK 21" +# uses: actions/setup-java@v4 +# with: +# distribution: 'zulu' +# java-version: 21 +# - name: Restore Maven local repository cache +# uses: actions/cache@v4 +# with: +# path: ~/.m2/repository +# key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} +# restore-keys: | +# ${{ runner.os }}-maven- +# ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} +# - name: "Compile Dubbo-SPI-Extensions (Linux)" +# run: | +# cd ${{ github.workspace }}/dubbo-spi-extensions +# ./mvnw --batch-mode --no-snapshot-updates -e --no-transfer-progress --fail-fast -T 2C clean install -DskipTests=true -DskipIntegrationTests=true -Dcheckstyle.skip=true -Dcheckstyle_unix.skip=true -Drat.skip=true -Dmaven.javadoc.skip=true +# - name: "Run Error Code Inspecting" +# env: +# DUBBO_ECI_REPORT_AS_ERROR: true +# run: | +# cd ${{ github.workspace }}/dubbo-test-tools/dubbo-error-code-inspector +# ../mvnw --batch-mode --no-snapshot-updates -e --no-transfer-progress --fail-fast -T 2C package exec:java -Ddubbo.eci.report-as-error=${DUBBO_ECI_REPORT_AS_ERROR} -Dmaven.test.skip=true -Dmaven.test.skip.exec=true -Ddubbo.eci.path=${{ github.workspace }}/dubbo-spi-extensions +# - name: "Upload error code inspection result" +# # always() should not be used here, since we don't need to handle the 'canceled' situation. +# if: ${{ success() || failure() }} +# uses: actions/upload-artifact@v4 +# with: +# name: "error-inspection-result" +# path: ${{ github.workspace }}/dubbo-test-tools/dubbo-error-code-inspector/error-inspection-result.txt diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index b9d607d6a..000000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,68 +0,0 @@ -name: CI - -on: [ push, pull_request ] - -jobs: - build: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [ ubuntu-latest, windows-2019 ] - jdk: [ 8, 11 ] - steps: - - uses: actions/checkout@v2 - with: - path: dubbo-spi-extensions - - uses: actions/checkout@v2 - with: - repository: 'apache/dubbo' - ref: '3.0' - path: dubbo - - name: "Set up JDK ${{ matrix.jdk }}" - uses: actions/setup-java@v1 - with: - java-version: ${{ matrix.jdk }} - - uses: actions/cache@v2 - name: "Cache local Maven repository" - with: - path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven- - - name: "Build tools" - run: | - cd ./dubbo - ./mvnw --batch-mode -U -e --no-transfer-progress install -pl dubbo-build-tools -am -DskipTests=true - - name: "Test with Maven" - timeout-minutes: 40 - if: ${{ startsWith( matrix.os, 'ubuntu') }} - run: | - cd ./dubbo-spi-extensions - ./mvnw --batch-mode -U -e --no-transfer-progress clean test verify -Pjacoco -Dmaven.wagon.httpconnectionManager.ttlSeconds=120 -Dmaven.wagon.http.retryHandler.count=5 -DskipTests=false -DskipIntegrationTests=false -Dcheckstyle.skip=false -Dcheckstyle_unix.skip=false -Drat.skip=false -Dmaven.javadoc.skip=true - - name: "Test with Maven" - timeout-minutes: 50 - if: ${{ startsWith( matrix.os, 'windows') }} - run: | - cd ./dubbo-spi-extensions - ./mvnw --batch-mode -U -e --no-transfer-progress clean test verify -Pjacoco -D"http.keepAlive=false" -D"maven.wagon.http.pool=false" -D"maven.wagon.httpconnectionManager.ttlSeconds=120" -D"maven.wagon.http.retryHandler.count=5" -DskipTests=false -DskipIntegrationTests=true -D"checkstyle.skip=false" -D"checkstyle_unix.skip=true" -D"rat.skip=false" -D"maven.javadoc.skip=true" - - name: "Pack rat file if failure" - if: failure() - run: 7z a ${{ github.workspace }}/rat.zip *rat.txt -r - - name: "Upload rat file if failure" - if: failure() - uses: actions/upload-artifact@v2 - with: - name: "rat-file" - path: ${{ github.workspace }}/rat.zip - - name: "Pack checkstyle file if failure" - if: failure() - run: 7z a ${{ github.workspace }}/checkstyle.zip *checkstyle* -r - - name: "Upload checkstyle file if failure" - if: failure() - uses: actions/upload-artifact@v2 - with: - name: "checkstyle-file" - path: ${{ github.workspace }}/checkstyle.zip - - name: "Upload coverage to Codecov" - uses: codecov/codecov-action@v1 diff --git a/.github/workflows/conformance.yml b/.github/workflows/conformance.yml index dd3700bf1..8fb234608 100644 --- a/.github/workflows/conformance.yml +++ b/.github/workflows/conformance.yml @@ -52,8 +52,8 @@ jobs: ./mvnw --batch-mode -U -e --no-transfer-progress install -am -DskipTests=true - name: "Build Scenarios" run: | - cd ./dubbo-spi-extensions/test/scenarios - ../../mvnw --batch-mode -U -e --no-transfer-progress install -am -DskipTests=true + cd ./dubbo-spi-extensions/test + ../mvnw --batch-mode -U -e --no-transfer-progress install -am -DskipTests=true prepare_test: name: "Prepare Test" @@ -81,7 +81,8 @@ jobs: strategy: fail-fast: false matrix: - java: [ 8,11 ] + # use the unsafe only run on the jdk8 + java: [ 8 ] #testjob id list MUST match 'JOB_COUNT' of 'prepare_test' job_id: [ 1,2,3 ] steps: @@ -122,7 +123,7 @@ jobs: strategy: fail-fast: false matrix: - java: [ 8,11 ] + java: [ 8 ] env: JAVA_VER: ${{matrix.java}} steps: diff --git a/.github/workflows/release-test.yml b/.github/workflows/release-test.yml new file mode 100644 index 000000000..acf7c1aa0 --- /dev/null +++ b/.github/workflows/release-test.yml @@ -0,0 +1,346 @@ +name: Release Test + +on: + push: + branches: + - '**-release' + workflow_dispatch: + +permissions: + contents: read + +env: + FORK_COUNT: 2 + FAIL_FAST: 0 + SHOW_ERROR_DETAIL: 1 + #multi-version size limit + VERSIONS_LIMIT: 4 + JACOCO_ENABLE: true + CANDIDATE_VERSIONS: ' + spring.version:5.3.24; + spring-boot.version:2.7.6; + ' + +jobs: + # Check ASF License + check-license: + name: "Check License" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Check License + uses: apache/skywalking-eyes@v0.5.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: "Set up JDK 21" + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: 21 + - name: Restore Maven local repository cache + uses: actions/cache@v4 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + - name: Check Dependencies' License + uses: apache/skywalking-eyes/dependency@e1a02359b239bd28de3f6d35fdc870250fa513d5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + config: .licenserc.yaml + mode: check + # Build dubbo-build-tool + build-tools: + name: "Build-tools" + needs: check-license + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ ubuntu-latest, windows-latest ] + fail-fast: false + outputs: + cache-key: ${{ steps.dubbo-build-tools.cache }} + steps: + - name: Support long paths on Windows + if: ${{ startsWith( matrix.os, 'windows') }} + run: git config --system core.longpaths true + - uses: actions/checkout@v4 + name: build tools + with: + repository: 'apache/dubbo' + ref: '3.2' + path: dubbo + - name: "Set up JDK 21" + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: 21 + - uses: actions/cache@v4 + name: "Cache local Maven repository" + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + ${{ runner.os }}-maven- + - name: "Build tools" + run: | + cd ./dubbo + ./mvnw --batch-mode -U -e --no-transfer-progress install -pl dubbo-build-tools -am -DskipTests=true + # Build from source code + build-source: + name: "Build Dubbo-SPI-Extensions" + needs: [check-license] + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ ubuntu-latest, windows-latest ] + # output dubbo-spi-extensions version to others jobs + outputs: + version: ${{ steps.dubbo-spi-extensions-version.outputs.version }} + steps: + - uses: actions/checkout@v4 + with: + path: dubbo-spi-extensions + - uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: 8 + - uses: actions/cache@v4 + name: "Cache local Maven repository" + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}-${{ github.run_id }} + restore-keys: | + ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + ${{ runner.os }}-maven- + - name: "Compile Dubbo-SPI-Extensions (Linux)" + run: | + cd ./dubbo-spi-extensions + ./mvnw --batch-mode --no-snapshot-updates -e --no-transfer-progress --fail-fast -T 2C clean compile -DskipTests=true -DskipIntegrationTests=true -Dcheckstyle.skip=true -Dcheckstyle_unix.skip=true -Drat.skip=true -Dmaven.javadoc.skip=true + - name: "Build Dubbo-SPI-Extensions with Maven" + run: | + cd ./dubbo-spi-extensions + ./mvnw --batch-mode --no-snapshot-updates -e --no-transfer-progress --fail-fast clean source:jar install -Pjacoco,checkstyle -Dmaven.wagon.httpconnectionManager.ttlSeconds=120 -Dmaven.wagon.http.retryHandler.count=5 -Dmaven.test.skip=true -Dmaven.test.skip.exec=true -DembeddedZookeeperPath=${{ github.workspace }}/.tmp/zookeeper + - name: "Pack class result" + run: | + shopt -s globstar + zip ${{ github.workspace }}/class.zip **/target/classes/* -r + - name: "Upload class result" + uses: actions/upload-artifact@v4 + with: + name: "class-file" + path: ${{ github.workspace }}/class.zip + - name: "Pack checkstyle file if failure" + if: failure() + run: zip ${{ github.workspace }}/checkstyle.zip *checkstyle* -r + - name: "Upload checkstyle file if failure" + if: failure() + uses: actions/upload-artifact@v4 + with: + name: "checkstyle-file" + path: ${{ github.workspace }}/checkstyle.zip + - name: "Calculate Dubbo-SPI-Extensions Version" + id: dubbo-spi-extensions-version + run: | + REVISION=`awk '/[^<]+<\/revision>/{gsub(/|<\/revision>/,"",$1);print $1;exit;}' ./dubbo-spi-extensions/pom.xml` + echo "version=$REVISION" >> $GITHUB_OUTPUT + echo "dubbo-spi-extensions version: $REVISION" + # Download dependencies Prepare for unit test + unit-test-prepare: + name: "Preparation for Unit Test On ${{ matrix.os }}" + needs: [check-license] + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ ubuntu-latest, windows-latest ] + fail-fast: false + env: + ZOOKEEPER_VERSION: 3.6.3 + steps: + - uses: actions/cache@v4 + name: "Cache zookeeper binary archive" + id: "cache-zookeeper" + with: + path: ${{ github.workspace }}/.tmp/zookeeper + key: zookeeper-${{ runner.os }}-${{ env.ZOOKEEPER_VERSION }} + restore-keys: | + zookeeper-${{ runner.os }}-${{ env.ZOOKEEPER_VERSION }} + - name: "Set up msys2 if necessary" + if: ${{ startsWith( matrix.os, 'windows') && steps.cache-zookeeper.outputs.cache-hit != 'true' }} + uses: msys2/setup-msys2@v2 + with: + release: false # support cache, see https://github.com/msys2/setup-msys2#context + - name: "Download zookeeper binary archive in Linux OS" + if: ${{ startsWith( matrix.os, 'ubuntu') && steps.cache-zookeeper.outputs.cache-hit != 'true' }} + run: | + mkdir -p ${{ github.workspace }}/.tmp/zookeeper + wget -c https://archive.apache.org/dist/zookeeper/zookeeper-${{ env.ZOOKEEPER_VERSION }}/apache-zookeeper-${{ env.ZOOKEEPER_VERSION }}-bin.tar.gz -O ${{ github.workspace }}/.tmp/zookeeper/apache-zookeeper-bin.tar.gz || + wget -c https://apache.website-solution.net/zookeeper/zookeeper-${{ env.ZOOKEEPER_VERSION }}/apache-zookeeper-${{ env.ZOOKEEPER_VERSION }}-bin.tar.gz -O ${{ github.workspace }}/.tmp/zookeeper/apache-zookeeper-bin.tar.gz || + wget -c http://apache.stu.edu.tw/zookeeper/zookeeper-${{ env.ZOOKEEPER_VERSION }}/apache-zookeeper-${{ env.ZOOKEEPER_VERSION }}-bin.tar.gz -O ${{ github.workspace }}/.tmp/zookeeper/apache-zookeeper-bin.tar.gz || + wget -c http://ftp.jaist.ac.jp/pub/apache/zookeeper/zookeeper-${{ env.ZOOKEEPER_VERSION }}/apache-zookeeper-${{ env.ZOOKEEPER_VERSION }}-bin.tar.gz -O ${{ github.workspace }}/.tmp/zookeeper/apache-zookeeper-bin.tar.gz || + wget -c http://apache.mirror.cdnetworks.com/zookeeper/zookeeper-${{ env.ZOOKEEPER_VERSION }}/apache-zookeeper-${{ env.ZOOKEEPER_VERSION }}-bin.tar.gz -O ${{ github.workspace }}/.tmp/zookeeper/apache-zookeeper-bin.tar.gz || + wget -c http://mirror.apache-kr.org/apache/zookeeper/zookeeper-${{ env.ZOOKEEPER_VERSION }}/apache-zookeeper-${{ env.ZOOKEEPER_VERSION }}-bin.tar.gz -O ${{ github.workspace }}/.tmp/zookeeper/apache-zookeeper-bin.tar.gz + echo "list the downloaded zookeeper binary archive" + ls -al ${{ github.workspace }}/.tmp/zookeeper/apache-zookeeper-bin.tar.gz + - name: "Download zookeeper binary archive in Windows OS" + if: ${{ startsWith( matrix.os, 'windows') && steps.cache-zookeeper.outputs.cache-hit != 'true' }} + shell: msys2 {0} + run: | + mkdir -p ${{ github.workspace }}/.tmp/zookeeper + wget -c https://archive.apache.org/dist/zookeeper/zookeeper-${{ env.ZOOKEEPER_VERSION }}/apache-zookeeper-${{ env.ZOOKEEPER_VERSION }}-bin.tar.gz -O ${{ github.workspace }}/.tmp/zookeeper/apache-zookeeper-bin.tar.gz || + wget -c https://apache.website-solution.net/zookeeper/zookeeper-${{ env.ZOOKEEPER_VERSION }}/apache-zookeeper-${{ env.ZOOKEEPER_VERSION }}-bin.tar.gz -O ${{ github.workspace }}/.tmp/zookeeper/apache-zookeeper-bin.tar.gz || + wget -c http://apache.stu.edu.tw/zookeeper/zookeeper-${{ env.ZOOKEEPER_VERSION }}/apache-zookeeper-${{ env.ZOOKEEPER_VERSION }}-bin.tar.gz -O ${{ github.workspace }}/.tmp/zookeeper/apache-zookeeper-bin.tar.gz || + wget -c http://ftp.jaist.ac.jp/pub/apache/zookeeper/zookeeper-${{ env.ZOOKEEPER_VERSION }}/apache-zookeeper-${{ env.ZOOKEEPER_VERSION }}-bin.tar.gz -O ${{ github.workspace }}/.tmp/zookeeper/apache-zookeeper-bin.tar.gz || + wget -c http://apache.mirror.cdnetworks.com/zookeeper/zookeeper-${{ env.ZOOKEEPER_VERSION }}/apache-zookeeper-${{ env.ZOOKEEPER_VERSION }}-bin.tar.gz -O ${{ github.workspace }}/.tmp/zookeeper/apache-zookeeper-bin.tar.gz || + wget -c http://mirror.apache-kr.org/apache/zookeeper/zookeeper-${{ env.ZOOKEEPER_VERSION }}/apache-zookeeper-${{ env.ZOOKEEPER_VERSION }}-bin.tar.gz -O ${{ github.workspace }}/.tmp/zookeeper/apache-zookeeper-bin.tar.gz + echo "list the downloaded zookeeper binary archive" + ls -al ${{ github.workspace }}/.tmp/zookeeper/apache-zookeeper-bin.tar.gz + - uses: actions/cache@v4 + name: "Cache secret key" + id: "cache-secret-cert" + with: + path: ${{ github.workspace }}/.tmp/rsa + key: secret-rsa-${{ runner.os }}-${{ github.run_id }} + - name: "Create Secret" + run: | + mkdir -p ${{ github.workspace }}/.tmp/rsa + cd ${{ github.workspace }}/.tmp/rsa + openssl genrsa -out rsa_private.pem 1024 + openssl rsa -in rsa_private.pem -pubout -out rsa_public.pem + echo "Current workflow run id: ${{ github.run_id }}" + echo "Start Print Rsa Public Key ---" + cat rsa_public.pem + echo "--- End Print Rsa Public Key" + # Start unit test + unit-test: + needs: [check-license, build-source, unit-test-prepare] + name: "Unit Test ${{ matrix.os }} with JDK ${{ matrix.jdk }}" + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ ubuntu-latest, windows-latest ] + jdk: [ 8, 11 ] + fail-fast: false + env: + DISABLE_FILE_SYSTEM_TEST: true + CURRENT_ROLE: ${{ matrix.case-role }} + DUBBO_DEFAULT_SERIALIZATION: fastjson2 + steps: + - name: Support Windows + if: ${{ startsWith( matrix.os, 'windows') }} + run: | + git config --system core.longpaths true + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: "Set up JDK ${{ matrix.jdk }}" + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: 8 + - uses: actions/cache@v4 + name: "Cache local Maven repository" + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}-${{ github.run_id }} + restore-keys: | + ${{ runner.os }}-maven- + ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + - uses: actions/cache@v4 + name: "Cache zookeeper binary archive" + id: "cache-zookeeper" + with: + path: ${{ github.workspace }}/.tmp/zookeeper + key: zookeeper-${{ runner.os }}-${{ env.ZOOKEEPER_VERSION }} + restore-keys: | + zookeeper-${{ runner.os }}- + - name: "Upload surefire-reports if failure" + if: ${{ failure() }} + uses: actions/upload-artifact@v4 + with: + name: surefire-reports-${{ matrix.os }}-${{ matrix.jdk }} + path: "**/target/surefire-reports/**" + - uses: actions/cache@v4 + name: "Cache secret key" + id: "cache-secret-cert" + with: + path: ${{ github.workspace }}/.tmp/rsa + key: secret-rsa-${{ runner.os }}-${{ github.run_id }} + # - name: "Get sonarcloud token" + # if: ${{ github.repository == 'apache/dubbo-spi-extensions' }} + # run: | + # curl "http://dubbo-vm.apache.org:8000/token?workflow_id=${{ github.run_id }}" -o ${{ github.workspace }}/.tmp/encrypted-sonarcloud-token + # openssl rsautl -decrypt -in ${{ github.workspace }}/.tmp/encrypted-sonarcloud-token -out ${{ github.workspace }}/.tmp/decrypted-sonarcloud-token -inkey ${{ github.workspace }}/.tmp/rsa/rsa_private.pem + # - name: "Test with Maven with SonarCloud Scan" + # if: ${{ github.repository == 'apache/dubbo-spi-extensions' }} + # timeout-minutes: 70 + # env: + # # Needed to get some information about the pull request, if any + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # run: | + # source ${{ github.workspace }}/.tmp/decrypted-sonarcloud-token + # ./mvnw --batch-mode --no-snapshot-updates -e --no-transfer-progress --fail-fast clean test verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Pjacoco,jdk15ge-simple,'!jdk15ge',jacoco089 -Dsonar.host.url=https://sonarcloud.io -Dsonar.organization=apache -Dsonar.projectKey=apache_dubbo -DtrimStackTrace=false -Dmaven.wagon.httpconnectionManager.ttlSeconds=120 -Dmaven.wagon.http.retryHandler.count=5 -DskipTests=false -DskipIntegrationTests=false -Dcheckstyle.skip=false -Dcheckstyle_unix.skip=false -Drat.skip=false -Dmaven.javadoc.skip=true -DembeddedZookeeperPath=${{ github.workspace }}/.tmp/zookeeper -Dsonar.coverage.jacoco.xmlReportPaths=dubbo-test/dubbo-dependencies-all/target/site/jacoco-aggregate/jacoco.xml -Dsonar.login=${SONAR_TOKEN} + - name: "Test with Maven without SonarCloud Scan On Linux" + if: ${{ startsWith( matrix.os, 'linux') || startsWith( matrix.os, 'ubuntu') }} + timeout-minutes: 70 + run: | + ./mvnw --batch-mode --no-snapshot-updates -e --no-transfer-progress --fail-fast clean test verify -D"maven.wagon.httpconnectionManager.ttlSeconds=120" -Pjacoco -DtrimStackTrace=false -D"maven.wagon.http.retryHandler.count=5" -DskipTests=false -DskipIntegrationTests=false -D"checkstyle.skip=false" -D"checkstyle_unix.skip=false" -D"rat.skip=false" -D"maven.javadoc.skip=true" -D"embeddedZookeeperPath=${{ github.workspace }}/.tmp/zookeeper" + - name: "Test with Maven without SonarCloud Scan On Windows" + if: ${{ startsWith( matrix.os, 'windows') }} + timeout-minutes: 70 + run: | + ./mvnw --batch-mode --no-snapshot-updates -e --no-transfer-progress --fail-fast clean test verify -D"maven.wagon.httpconnectionManager.ttlSeconds=120" -Pjacoco -DtrimStackTrace=false -D"maven.wagon.http.retryHandler.count=5" -DskipTests=false -DskipIntegrationTests=false -D"checkstyle.skip=false" -D"checkstyle_unix.skip=true" -D"rat.skip=false" -D"maven.javadoc.skip=true" -D"embeddedZookeeperPath=${{ github.workspace }}/.tmp/zookeeper" + - name: "Upload coverage result" + uses: actions/upload-artifact@v4 + with: + name: coverage-result-${{ matrix.os }}-${{ matrix.jdk }} + path: "**/target/site/**/jacoco.xml" + - name: "Upload coverage to Codecov" + uses: codecov/codecov-action@v4 + +# error-code-inspecting: +# needs: [check-license, build-tools] +# runs-on: ubuntu-latest +# steps: +# - uses: actions/checkout@v4 +# with: +# path: "./dubbo-spi-extensions" +# - uses: actions/checkout@v4 +# with: +# repository: 'apache/dubbo-test-tools' +# ref: main +# path: "./dubbo-test-tools" +# - name: "Set up JDK 21" +# uses: actions/setup-java@v4 +# with: +# distribution: 'zulu' +# java-version: 21 +# - name: Restore Maven local repository cache +# uses: actions/cache@v4 +# with: +# path: ~/.m2/repository +# key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} +# restore-keys: | +# ${{ runner.os }}-maven- +# ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} +# - name: "Compile Dubbo-SPI-Extensions (Linux)" +# run: | +# cd ${{ github.workspace }}/dubbo-spi-extensions +# ./mvnw --batch-mode --no-snapshot-updates -e --no-transfer-progress --fail-fast -T 2C clean install -DskipTests=true -DskipIntegrationTests=true -Dcheckstyle.skip=true -Dcheckstyle_unix.skip=true -Drat.skip=true -Dmaven.javadoc.skip=true +# - name: "Run Error Code Inspecting" +# env: +# DUBBO_ECI_REPORT_AS_ERROR: true +# run: | +# cd ${{ github.workspace }}/dubbo-test-tools/dubbo-error-code-inspector +# ../mvnw --batch-mode --no-snapshot-updates -e --no-transfer-progress --fail-fast -T 2C package exec:java -Ddubbo.eci.report-as-error=${DUBBO_ECI_REPORT_AS_ERROR} -Dmaven.test.skip=true -Dmaven.test.skip.exec=true -Ddubbo.eci.path=${{ github.workspace }}/dubbo-spi-extensions +# - name: "Upload error code inspection result" +# # always() should not be used here, since we don't need to handle the 'canceled' situation. +# if: ${{ success() || failure() }} +# uses: actions/upload-artifact@v4 +# with: +# name: "error-inspection-result" +# path: ${{ github.workspace }}/dubbo-test-tools/dubbo-error-code-inspector/error-inspection-result.txt diff --git a/.licenserc.yaml b/.licenserc.yaml new file mode 100644 index 000000000..87bad4957 --- /dev/null +++ b/.licenserc.yaml @@ -0,0 +1,213 @@ +header: + license: + spdx-id: Apache-2.0 + content: | + 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. + + paths-ignore: + - '**/*.versionsBackup' + - '**/.idea/' + - '**/*.iml' + - '**/.settings/*' + - '**/.classpath' + - '**/.project' + - '**/target/**' + - '**/generated/**' + - '**/*.log' + - '**/codestyle/*' + - '**/resources/META-INF/**' + - '**/resources/mockito-extensions/**' + - '**/*.proto' + - '**/*.cache' + - '**/*.txt' + - '**/*.load' + - '**/*.flex' + - '**/*.fc' + - '**/*.javascript' + - '**/*.properties' + - '**/*.sh' + - '**/*.bat' + - '**/*.md' + - '**/*.svg' + - '**/*.png' + - '**/*.json' + - '**/*.conf' + - '**/*.ftl' + - '**/*.tpl' + - '**/*.factories' + - '**/*.handlers' + - '**/*.schemas' + - '**/*.nojekyll' + - '.git/' + - '.github/**' + - '**/.gitignore' + - '**/.helmignore' + - '.repository/' + - 'compiler/**' + - '.gitmodules' + - '.mvn' + - 'mvnw' + - 'mvnw.cmd' + - 'LICENSE' + - 'NOTICE' + - 'CNAME' + - 'Jenkinsfile' + - '**/vendor/**' + - '**/src/test/resources/certs/**' + - '**/src/test/resources/definition/**' + # Generate class + - 'dubbo-rpc-extensions/dubbo-rpc-native-thrift/src/test/java/org/apache/dubbo/rpc/protocol/nativethrift/DemoService.java' + - 'dubbo-rpc-extensions/dubbo-rpc-native-thrift/src/test/java/org/apache/dubbo/rpc/protocol/nativethrift/UserService.java' + # other license + - 'test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-avro-test/src/main/java/org/apache/dubbo/test/serialization/avro/EmbeddedZooKeeper.java' + - 'test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-fastjson-test/src/main/java/org/apache/dubbo/test/serialization/fastjson/EmbeddedZooKeeper.java' + - 'test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-fst-test/src/main/java/org/apache/dubbo/test/serialization/fst/EmbeddedZooKeeper.java' + - 'test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-gson-test/src/main/java/org/apache/dubbo/test/serialization/gson/EmbeddedZooKeeper.java' + - 'test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-kryo-test/src/main/java/org/apache/dubbo/test/serialization/kryo/EmbeddedZooKeeper.java' + - 'test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-protostuff-test/src/main/java/org/apache/dubbo/test/serialization/protostuff/EmbeddedZooKeeper.java' + + comment: on-failure + + license-location-threshold: 130 + +dependency: + files: + - pom.xml + - dubbo-extensions-dependencies-bom/pom.xml + licenses: + - name: com.alibaba.spring:spring-context-support + license: Apache-2.0 + - name: com.fasterxml.jackson.core:jackson-annotations + license: Apache-2.0 + - name: com.fasterxml.jackson.core:jackson-core + license: Apache-2.0 + - name: com.fasterxml.jackson.core:jackson-databind + license: Apache-2.0 + - name: com.fasterxml.jackson.dataformat:jackson-dataformat-yaml + license: Apache-2.0 + - name: com.fasterxml.jackson.datatype:jackson-datatype-jsr310 + license: Apache-2.0 + - name: com.google.code.gson:gson + license: Apache-2.0 + - name: com.google.guava:listenablefuture + license: Apache-2.0 + - name: com.salesforce.servicelibs:grpc-contrib + license: BSD 3-clause + - name: com.squareup.okhttp3:logging-interceptor + license: Apache-2.0 + - name: com.squareup.okhttp3:okhttp + license: Apache-2.0 + - name: com.squareup.okio:okio + license: Apache-2.0 + - name: com.sun.xml.fastinfoset:FastInfoset + license: Apache-2.0 + - name: io.envoyproxy.controlplane:api + license: Apache-2.0 + - name: io.swagger:swagger-annotations + license: Apache-2.0 + - name: io.swagger:swagger-models + license: Apache-2.0 + - name: org.springframework.boot:spring-boot + license: Apache-2.0 + - name: org.springframework.boot:spring-boot-actuator + license: Apache-2.0 + - name: org.springframework.boot:spring-boot-autoconfigure + license: Apache-2.0 + - name: org.springframework.boot:spring-boot-configuration-processor + license: Apache-2.0 + - name: org.springframework.boot:spring-boot-starter + license: Apache-2.0 + - name: org.springframework.boot:spring-boot-starter-actuator + license: Apache-2.0 + - name: org.springframework.boot:spring-boot-starter-logging + license: Apache-2.0 + - name: org.springframework.boot:spring-boot-starter-tomcat + license: Apache-2.0 + - name: org.springframework.boot:spring-boot-starter-web + license: Apache-2.0 + - name: org.slf4j:slf4j-api + license: MIT + - name: org.slf4j:slf4j-log4j12 + license: MIT + - name: org.jboss.resteasy:resteasy-jaxrs + license: Apache-2.0 + - name: org.jboss.resteasy:resteasy-client + license: Apache-2.0 + - name: org.jboss.resteasy:resteasy-netty4 + license: Apache-2.0 + - name: org.jboss.resteasy:resteasy-jdk-http + license: Apache-2.0 + - name: org.jboss.resteasy:resteasy-jackson-provider + license: Apache-2.0 + - name: org.jboss.resteasy:resteasy-jaxb-provider + license: Apache-2.0 + - name: net.jcip:jcip-annotations + license: Apache-2.0 + - name: org.apache.zookeeper:zookeeper + license: Apache-2.0 + - name: org.apache.zookeeper:zookeeper-jute + license: Apache-2.0 + - name: net.bytebuddy:byte-buddy + license: Apache-2.0 + - name: javax.enterprise:cdi-api + license: Apache-2.0 + - name: org.codehaus.plexus:plexus-component-annotations + license: Apache-2.0 + - name: org.slf4j:jcl-over-slf4j + license: Apache-2.0 + - name: org.slf4j:jul-to-slf4j + license: Apache-2.0 + - name: org.codehaus.plexus:plexus-interpolation + license: Apache-2.0 + - name: org.sonatype.plexus:plexus-sec-dispatcher + license: Apache-2.0 + - name: org.sonatype.plexus:plexus-cipher + license: Apache-2.0 + - name: com.google.protobuf:protobuf-java + license: BSD 3-clause + - name: com.google.protobuf:protobuf-java-util + license: BSD 3-clause + # multi license + - name: org.javassist:javassist + license: Apache-2.0 + - name: javax.annotation:javax.annotation-api + license: CDDL-1.0 + - name: com.salesforce.servicelibs:jprotoc + license: CDDL-1.0 + - name: org.checkerframework:checker-compat-qual + license: MIT + - name: ch.qos.logback:logback-classic + license: EPL-1.0 + - name: ch.qos.logback:logback-core + license: EPL-1.0 + - name: javax.servlet:javax.servlet-api + license: CDDL-1.1 + - name: com.sun.activation:javax.activation + license: CDDL-1.1 + - name: javax.activation:activation + license: CDDL-1.1 + - name: jakarta.annotation:jakarta.annotation-api + license: EPL-2.0 + - name: org.glassfish:jakarta.el + license: EPL-2.0 + - name: org.jboss.spec.javax.annotation:jboss-annotations-api_1.2_spec + license: CDDL-1.1 + - name: org.jboss.spec.javax.ws.rs:jboss-jaxrs-api_2.1_spec + license: EPL-2.0 + - name: org.jboss.spec.javax.annotation:jboss-annotations-api_1.3_spec + license: EPL-2.0 + excludes: + - name: javax.xml.bind:jsr173_api diff --git a/dobbo-doc-auto-gen/pom.xml b/dobbo-doc-auto-gen/pom.xml index f00250d3f..1cf5324b4 100644 --- a/dobbo-doc-auto-gen/pom.xml +++ b/dobbo-doc-auto-gen/pom.xml @@ -24,7 +24,7 @@ ../pom.xml - 1.0.1-SNAPSHOT + ${revision} Dubbo interface documentation, testing tools dobbo-doc-auto-gen diff --git a/dubbo-api-docs/dubbo-api-docs-annotations/pom.xml b/dubbo-api-docs/dubbo-api-docs-annotations/pom.xml index 37794b445..7abfe58f4 100644 --- a/dubbo-api-docs/dubbo-api-docs-annotations/pom.xml +++ b/dubbo-api-docs/dubbo-api-docs-annotations/pom.xml @@ -21,7 +21,7 @@ org.apache.dubbo.extensions dubbo-api-docs - 1.0.1-SNAPSHOT + ${revision} ../pom.xml diff --git a/dubbo-api-docs/dubbo-api-docs-core/pom.xml b/dubbo-api-docs/dubbo-api-docs-core/pom.xml index 4d38aecc8..7e08d77c9 100644 --- a/dubbo-api-docs/dubbo-api-docs-core/pom.xml +++ b/dubbo-api-docs/dubbo-api-docs-core/pom.xml @@ -22,7 +22,7 @@ org.apache.dubbo.extensions dubbo-api-docs - 1.0.1-SNAPSHOT + ${revision} ../pom.xml diff --git a/dubbo-api-docs/dubbo-api-docs-examples/examples-api/pom.xml b/dubbo-api-docs/dubbo-api-docs-examples/examples-api/pom.xml index 6dbff83d7..3e70a2a0e 100644 --- a/dubbo-api-docs/dubbo-api-docs-examples/examples-api/pom.xml +++ b/dubbo-api-docs/dubbo-api-docs-examples/examples-api/pom.xml @@ -21,7 +21,7 @@ org.apache.dubbo.extensions.examples.apidocs dubbo-api-docs-examples - 1.0.1-SNAPSHOT + ${revision} ../pom.xml diff --git a/dubbo-api-docs/dubbo-api-docs-examples/examples-provider-sca/pom.xml b/dubbo-api-docs/dubbo-api-docs-examples/examples-provider-sca/pom.xml index bded94ed4..7cf765bf2 100644 --- a/dubbo-api-docs/dubbo-api-docs-examples/examples-provider-sca/pom.xml +++ b/dubbo-api-docs/dubbo-api-docs-examples/examples-provider-sca/pom.xml @@ -21,7 +21,7 @@ org.apache.dubbo.extensions.examples.apidocs dubbo-api-docs-examples - 1.0.1-SNAPSHOT + ${revision} ../pom.xml @@ -39,7 +39,7 @@ org.apache.dubbo.extensions.examples.apidocs examples-api - 1.0.1-SNAPSHOT + ${revision} org.springframework.boot diff --git a/dubbo-api-docs/dubbo-api-docs-examples/examples-provider/pom.xml b/dubbo-api-docs/dubbo-api-docs-examples/examples-provider/pom.xml index d68d91046..19ef4e76f 100644 --- a/dubbo-api-docs/dubbo-api-docs-examples/examples-provider/pom.xml +++ b/dubbo-api-docs/dubbo-api-docs-examples/examples-provider/pom.xml @@ -21,7 +21,7 @@ org.apache.dubbo.extensions.examples.apidocs dubbo-api-docs-examples - 1.0.1-SNAPSHOT + ${revision} ../pom.xml @@ -39,7 +39,7 @@ org.apache.dubbo.extensions.examples.apidocs examples-api - 1.0.1-SNAPSHOT + ${revision} org.springframework.boot @@ -102,7 +102,6 @@ org.apache.dubbo dubbo-monitor-default - ${dubbo.version} diff --git a/dubbo-api-docs/dubbo-api-docs-examples/pom.xml b/dubbo-api-docs/dubbo-api-docs-examples/pom.xml index 9b9e22620..b788ab9af 100644 --- a/dubbo-api-docs/dubbo-api-docs-examples/pom.xml +++ b/dubbo-api-docs/dubbo-api-docs-examples/pom.xml @@ -21,7 +21,7 @@ org.apache.dubbo.extensions dubbo-api-docs - 1.0.1-SNAPSHOT + ${revision} ../pom.xml diff --git a/dubbo-api-docs/pom.xml b/dubbo-api-docs/pom.xml index 12b4594b3..ecea948f0 100644 --- a/dubbo-api-docs/pom.xml +++ b/dubbo-api-docs/pom.xml @@ -25,7 +25,7 @@ dubbo-api-docs - 1.0.1-SNAPSHOT + ${revision} pom ${project.artifactId} @@ -42,8 +42,6 @@ 3.0.0 2.3.4.RELEASE - 2.7.18 - 2.7.8 1.9.4 4.2 3.4.2 @@ -63,92 +61,6 @@ pom import - - org.apache.dubbo - dubbo-parent - ${dubbo.version} - pom - import - - - - - org.apache.dubbo.extensions - dubbo-api-docs-annotations - 1.0.1-SNAPSHOT - - - org.apache.dubbo.extensions - dubbo-api-docs-core - 1.0.1-SNAPSHOT - - - - org.apache.dubbo - dubbo - ${dubbo.version} - - - - org.apache.dubbo - dubbo-registry-nacos - ${dubbo.version} - - - - org.apache.dubbo - dubbo-registry-consul - ${dubbo.version} - - - - org.apache.dubbo - dubbo-registry-default - ${dubbo.version} - - - - org.apache.dubbo - dubbo-registry-etcd3 - ${dubbo.version} - - - - org.apache.dubbo - dubbo-registry-multicast - ${dubbo.version} - - - - org.apache.dubbo - dubbo-registry-multiple - ${dubbo.version} - - - - org.apache.dubbo - dubbo-registry-redis - ${dubbo.version} - - - - org.apache.dubbo - dubbo-registry-sofa - ${dubbo.version} - - - - org.apache.dubbo - dubbo-registry-zookeeper - ${dubbo.version} - - - - org.apache.dubbo - dubbo-spring-boot-starter - ${dubbo.version} - - diff --git a/dubbo-cluster-extensions/dubbo-cluster-broadcast-1/pom.xml b/dubbo-cluster-extensions/dubbo-cluster-broadcast-1/pom.xml index 03c4a8485..16a02288c 100644 --- a/dubbo-cluster-extensions/dubbo-cluster-broadcast-1/pom.xml +++ b/dubbo-cluster-extensions/dubbo-cluster-broadcast-1/pom.xml @@ -27,7 +27,7 @@ 4.0.0 dubbo-cluster-broadcast-1 - 1.0.2-SNAPSHOT + ${revision} jar diff --git a/dubbo-cluster-extensions/dubbo-cluster-loadbalance-peakewma/pom.xml b/dubbo-cluster-extensions/dubbo-cluster-loadbalance-peakewma/pom.xml index 21bf5f16f..ac0b6d589 100644 --- a/dubbo-cluster-extensions/dubbo-cluster-loadbalance-peakewma/pom.xml +++ b/dubbo-cluster-extensions/dubbo-cluster-loadbalance-peakewma/pom.xml @@ -27,7 +27,7 @@ 4.0.0 dubbo-cluster-loadbalance-peakewma - 1.0.2-SNAPSHOT + ${revision} jar diff --git a/dubbo-cluster-extensions/dubbo-cluster-loadbalance-peakewma/src/test/java/org/apache/dubbo/rpc/cluster/loadbalance/LoadBalanceBaseTest.java b/dubbo-cluster-extensions/dubbo-cluster-loadbalance-peakewma/src/test/java/org/apache/dubbo/rpc/cluster/loadbalance/LoadBalanceBaseTest.java index a7fcdac64..bbfea6fef 100644 --- a/dubbo-cluster-extensions/dubbo-cluster-loadbalance-peakewma/src/test/java/org/apache/dubbo/rpc/cluster/loadbalance/LoadBalanceBaseTest.java +++ b/dubbo-cluster-extensions/dubbo-cluster-loadbalance-peakewma/src/test/java/org/apache/dubbo/rpc/cluster/loadbalance/LoadBalanceBaseTest.java @@ -3,7 +3,7 @@ * 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 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 diff --git a/dubbo-cluster-extensions/dubbo-cluster-loadbalance-peakewma/src/test/java/org/apache/dubbo/rpc/cluster/loadbalance/PeakEwmaLoadBalanceTest.java b/dubbo-cluster-extensions/dubbo-cluster-loadbalance-peakewma/src/test/java/org/apache/dubbo/rpc/cluster/loadbalance/PeakEwmaLoadBalanceTest.java index a21bcfeb2..542160c16 100644 --- a/dubbo-cluster-extensions/dubbo-cluster-loadbalance-peakewma/src/test/java/org/apache/dubbo/rpc/cluster/loadbalance/PeakEwmaLoadBalanceTest.java +++ b/dubbo-cluster-extensions/dubbo-cluster-loadbalance-peakewma/src/test/java/org/apache/dubbo/rpc/cluster/loadbalance/PeakEwmaLoadBalanceTest.java @@ -3,7 +3,7 @@ * 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 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 diff --git a/dubbo-cluster-extensions/dubbo-cluster-polaris-dubbo2/pom.xml b/dubbo-cluster-extensions/dubbo-cluster-polaris-dubbo2/pom.xml index 0b21901c2..2fbb26536 100644 --- a/dubbo-cluster-extensions/dubbo-cluster-polaris-dubbo2/pom.xml +++ b/dubbo-cluster-extensions/dubbo-cluster-polaris-dubbo2/pom.xml @@ -28,7 +28,7 @@ dubbo-cluster-polaris-dubbo2 dubbo-cluster-polaris-dubbo2 - 1.0.0-SNAPSHOT + ${revision} Dubbo2 cluster extension for PolarisMesh, support dynamic routing capability. diff --git a/dubbo-cluster-extensions/dubbo-cluster-specify-address-common/pom.xml b/dubbo-cluster-extensions/dubbo-cluster-specify-address-common/pom.xml index 2720aa63f..68a498b01 100644 --- a/dubbo-cluster-extensions/dubbo-cluster-specify-address-common/pom.xml +++ b/dubbo-cluster-extensions/dubbo-cluster-specify-address-common/pom.xml @@ -27,7 +27,7 @@ 4.0.0 dubbo-cluster-specify-address-common - 1.0.2-SNAPSHOT + ${revision} org.apache.dubbo diff --git a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/pom.xml b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/pom.xml index 406039527..dfeb9b6de 100644 --- a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/pom.xml +++ b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo2/pom.xml @@ -27,7 +27,7 @@ 4.0.0 dubbo-cluster-specify-address-dubbo2 - 1.0.2-SNAPSHOT + ${revision} diff --git a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/pom.xml b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/pom.xml index 72f977c0c..ef17d3b0b 100644 --- a/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/pom.xml +++ b/dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/pom.xml @@ -27,7 +27,7 @@ 4.0.0 dubbo-cluster-specify-address-dubbo3 - 1.0.2-SNAPSHOT + ${revision} diff --git a/dubbo-configcenter-extensions/dubbo-configcenter-consul/pom.xml b/dubbo-configcenter-extensions/dubbo-configcenter-consul/pom.xml index 8581386c5..316a1162f 100644 --- a/dubbo-configcenter-extensions/dubbo-configcenter-consul/pom.xml +++ b/dubbo-configcenter-extensions/dubbo-configcenter-consul/pom.xml @@ -26,7 +26,7 @@ 4.0.0 dubbo-configcenter-consul - 1.0.2-SNAPSHOT + ${revision} diff --git a/dubbo-configcenter-extensions/dubbo-configcenter-etcd/pom.xml b/dubbo-configcenter-extensions/dubbo-configcenter-etcd/pom.xml index 3078cca42..05d3098e9 100644 --- a/dubbo-configcenter-extensions/dubbo-configcenter-etcd/pom.xml +++ b/dubbo-configcenter-extensions/dubbo-configcenter-etcd/pom.xml @@ -28,7 +28,7 @@ 4.0.0 dubbo-configcenter-etcd - 1.0.2-SNAPSHOT + ${revision} jar ${project.artifactId} The etcd implementation of the config-center api @@ -57,7 +57,7 @@ org.apache.dubbo.extensions dubbo-remoting-etcd3 - 1.0.2-SNAPSHOT + ${revision} diff --git a/dubbo-configcenter-extensions/dubbo-configcenter-etcd/src/test/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfigurationTest.java b/dubbo-configcenter-extensions/dubbo-configcenter-etcd/src/test/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfigurationTest.java index e6ed4b5bc..60e6889f1 100644 --- a/dubbo-configcenter-extensions/dubbo-configcenter-etcd/src/test/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfigurationTest.java +++ b/dubbo-configcenter-extensions/dubbo-configcenter-etcd/src/test/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfigurationTest.java @@ -26,10 +26,10 @@ import io.etcd.jetcd.Client; import io.etcd.jetcd.launcher.EtcdCluster; import io.etcd.jetcd.launcher.EtcdClusterFactory; -import org.junit.After; import org.junit.Assert; -import org.junit.Before; import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import java.net.URI; import java.util.HashMap; @@ -128,7 +128,7 @@ private void put(String key, String value) { } } - @Before + @BeforeEach public void setUp() { etcdCluster.start(); @@ -146,7 +146,7 @@ public void setUp() { config = new EtcdDynamicConfiguration(url); } - @After + @AfterEach public void tearDown() { etcdCluster.close(); } diff --git a/dubbo-extensions-dependencies-bom/pom.xml b/dubbo-extensions-dependencies-bom/pom.xml index ecca731af..e9a6a1b17 100644 --- a/dubbo-extensions-dependencies-bom/pom.xml +++ b/dubbo-extensions-dependencies-bom/pom.xml @@ -89,13 +89,13 @@ - 1.0.5-SNAPSHOT - 3.1.2 + 3.0.0-SNAPSHOT + 3.0.15 5.2.9.RELEASE 2.4.1 - 5.3.2 + 6.9.2 4.0.51 4.5.13 1.2.0 @@ -108,7 +108,7 @@ 2.2.7 1.2.0 3.1.15 - 1.8.2 + 1.11.3 1.2.83 2.48-jdk-6 0.2.0 @@ -132,14 +132,19 @@ 1.5.2 1.9.12 5.2.0 - 1.2.11 + 1.3.12 2.0 - 3.0.20.Final + 3.15.6.Final + 1.9.13 + 1.6.14 0.2.1 1.2.5 1.14.5 3.9.0 - 2.0 + 2.2 + 3.25.1 + 1.70 + 0.1.35 @@ -158,7 +163,13 @@ pom import - + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + org.apache.dubbo dubbo-core-spi @@ -204,6 +215,14 @@ + + + org.springframework + spring-test + ${spring.version} + test + + com.caucho hessian @@ -514,6 +533,54 @@ + + + org.jboss.resteasy + resteasy-jdk-http + ${resteasy_version} + + + org.jboss.resteasy + resteasy-jackson-provider + ${resteasy_version} + + + org.codehaus.jackson + jackson-core-asl + ${codehaus-jackson_version} + + + org.codehaus.jackson + jackson-mapper-asl + ${codehaus-jackson_version} + + + org.codehaus.jackson + jackson-jaxrs + ${codehaus-jackson_version} + + + org.codehaus.jackson + jackson-xc + ${codehaus-jackson_version} + + + org.jboss.resteasy + resteasy-jaxb-provider + ${resteasy_version} + + + + io.swagger + swagger-annotations + ${swagger_version} + + + io.swagger + swagger-jaxrs + ${swagger_version} + + com.tencent.polaris polaris-adapter-dubbo @@ -539,6 +606,46 @@ snakeyaml ${snakeyaml_version} + + com.google.protobuf + protobuf-java + ${protobuf-java_version} + + + com.google.protobuf + protobuf-java-util + ${protobuf-java_version} + + + org.bouncycastle + bcprov-jdk15on + ${bouncycastle-bcprov_version} + + + org.bouncycastle + bcpkix-jdk15on + ${bouncycastle-bcprov_version} + + + org.bouncycastle + bcprov-ext-jdk15on + ${bouncycastle-bcprov_version} + + + io.envoyproxy.controlplane + api + ${envoy_api_version} + + + org.apache.dubbo.extensions + dubbo-api-docs-annotations + ${revision} + + + org.apache.dubbo.extensions + dubbo-api-docs-core + ${revision} + diff --git a/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-circuitbreaker-dubbo2/pom.xml b/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-circuitbreaker-dubbo2/pom.xml index 4abcc6dd2..7fec6b946 100644 --- a/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-circuitbreaker-dubbo2/pom.xml +++ b/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-circuitbreaker-dubbo2/pom.xml @@ -21,7 +21,7 @@ dubbo-filter-polaris-dubbo2 org.apache.dubbo.extensions - 1.0.0-SNAPSHOT + ${revision} 4.0.0 diff --git a/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-ratelimit-dubbo2/pom.xml b/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-ratelimit-dubbo2/pom.xml index 88669ebd4..68cfee856 100644 --- a/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-ratelimit-dubbo2/pom.xml +++ b/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/dubbo-filter-polaris-ratelimit-dubbo2/pom.xml @@ -21,7 +21,7 @@ dubbo-filter-polaris-dubbo2 org.apache.dubbo.extensions - 1.0.0-SNAPSHOT + ${revision} 4.0.0 diff --git a/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/pom.xml b/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/pom.xml index bb845ac9a..ac5cd08d2 100644 --- a/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/pom.xml +++ b/dubbo-filter-extensions/dubbo-filter-polaris-dubbo2/pom.xml @@ -29,7 +29,7 @@ dubbo-filter-polaris-dubbo2 pom dubbo-filter-polaris-dubbo2 - 1.0.0-SNAPSHOT + ${revision} Dubbo2 filter extension for PolarisMesh, support circuitbreaking, ratelimit, metric capabilities. dubbo-filter-polaris-circuitbreaker-dubbo2 diff --git a/dubbo-filter-extensions/dubbo-filter-seata/pom.xml b/dubbo-filter-extensions/dubbo-filter-seata/pom.xml index 71380f19f..dd7770291 100644 --- a/dubbo-filter-extensions/dubbo-filter-seata/pom.xml +++ b/dubbo-filter-extensions/dubbo-filter-seata/pom.xml @@ -28,7 +28,7 @@ dubbo-filter-seata ${project.artifactId} - 1.0.2-SNAPSHOT + ${revision} diff --git a/dubbo-gateway-extensions/dubbo-gateway-common/pom.xml b/dubbo-gateway-extensions/dubbo-gateway-common/pom.xml deleted file mode 100644 index 7c401d8b6..000000000 --- a/dubbo-gateway-extensions/dubbo-gateway-common/pom.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - dubbo-gateway-extensions - org.apache.dubbo.extensions - ${revision} - ../pom.xml - - 4.0.0 - - dubbo-gateway-common - - diff --git a/dubbo-gateway-extensions/dubbo-gateway-common/src/main/java/org/apache/dubbo/gateway/common/OmnipotentCommonConstants.java b/dubbo-gateway-extensions/dubbo-gateway-common/src/main/java/org/apache/dubbo/gateway/common/OmnipotentCommonConstants.java deleted file mode 100644 index 314bcf381..000000000 --- a/dubbo-gateway-extensions/dubbo-gateway-common/src/main/java/org/apache/dubbo/gateway/common/OmnipotentCommonConstants.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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 org.apache.dubbo.gateway.common; - -public interface OmnipotentCommonConstants { - - //save origin group when service is omn - String ORIGIN_GROUP_KEY = "originGroup"; - - String ORIGIN_GENERIC_PARAMETER_TYPES = "originGenericParameterTypes"; - - String ORIGIN_PARAMETER_TYPES_DESC = "originParameterTypesDesc"; - - String $INVOKE_OMN = "$invokeOmn"; - - String ORIGIN_PATH_KEY = "originPath"; - - String ORIGIN_METHOD_KEY = "originMethod"; - - String ORIGIN_VERSION_KEY = "originVersion"; - - String SPECIFY_ADDRESS = "specifyAddress"; - String GATEWAY_MODE = "gatewayMode"; - -} diff --git a/dubbo-gateway-extensions/dubbo-gateway-consumer/pom.xml b/dubbo-gateway-extensions/dubbo-gateway-consumer/pom.xml deleted file mode 100644 index 2d1ead7f7..000000000 --- a/dubbo-gateway-extensions/dubbo-gateway-consumer/pom.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - dubbo-gateway-extensions - org.apache.dubbo.extensions - ${revision} - ../pom.xml - - 4.0.0 - - dubbo-gateway-consumer - - - - org.apache.dubbo - dubbo - provided - - - org.apache.dubbo.extensions - dubbo-gateway-common - ${project.version} - - - - diff --git a/dubbo-gateway-extensions/dubbo-gateway-consumer/src/main/java/org/apache/dubbo/gateway/consumer/config/InjvmConfigPostProcessor.java b/dubbo-gateway-extensions/dubbo-gateway-consumer/src/main/java/org/apache/dubbo/gateway/consumer/config/InjvmConfigPostProcessor.java deleted file mode 100644 index 0212bd371..000000000 --- a/dubbo-gateway-extensions/dubbo-gateway-consumer/src/main/java/org/apache/dubbo/gateway/consumer/config/InjvmConfigPostProcessor.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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 org.apache.dubbo.gateway.consumer.config; - -import org.apache.dubbo.common.extension.Activate; -import org.apache.dubbo.config.ConfigPostProcessor; -import org.apache.dubbo.config.ReferenceConfig; -import org.apache.dubbo.rpc.Constants; - -@Activate -public class InjvmConfigPostProcessor implements ConfigPostProcessor { - - @Override - public void postProcessReferConfig(ReferenceConfig referenceConfig) { - referenceConfig.setScope(Constants.SCOPE_REMOTE); - } -} diff --git a/dubbo-gateway-extensions/dubbo-gateway-consumer/src/main/java/org/apache/dubbo/gateway/consumer/filter/OmnSerFilter.java b/dubbo-gateway-extensions/dubbo-gateway-consumer/src/main/java/org/apache/dubbo/gateway/consumer/filter/OmnSerFilter.java deleted file mode 100644 index 49f3b8f09..000000000 --- a/dubbo-gateway-extensions/dubbo-gateway-consumer/src/main/java/org/apache/dubbo/gateway/consumer/filter/OmnSerFilter.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * 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 org.apache.dubbo.gateway.consumer.filter; - -import org.apache.dubbo.common.beanutil.JavaBeanDescriptor; -import org.apache.dubbo.common.beanutil.JavaBeanSerializeUtil; -import org.apache.dubbo.common.constants.CommonConstants; -import org.apache.dubbo.common.extension.Activate; -import org.apache.dubbo.common.logger.Logger; -import org.apache.dubbo.common.logger.LoggerFactory; -import org.apache.dubbo.common.utils.ReflectUtils; -import org.apache.dubbo.rpc.Filter; -import org.apache.dubbo.rpc.Invocation; -import org.apache.dubbo.rpc.Invoker; -import org.apache.dubbo.rpc.Result; -import org.apache.dubbo.rpc.RpcContext; -import org.apache.dubbo.rpc.RpcException; -import org.apache.dubbo.rpc.RpcInvocation; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Stream; - -import static org.apache.dubbo.gateway.common.OmnipotentCommonConstants.GATEWAY_MODE; -import static org.apache.dubbo.gateway.common.OmnipotentCommonConstants.ORIGIN_GENERIC_PARAMETER_TYPES; -import static org.apache.dubbo.gateway.common.OmnipotentCommonConstants.ORIGIN_PARAMETER_TYPES_DESC; -import static org.apache.dubbo.gateway.common.OmnipotentCommonConstants.SPECIFY_ADDRESS; - - -@Activate(group = CommonConstants.CONSUMER) -public class OmnSerFilter implements Filter, Filter.Listener { - - private final static Logger logger = LoggerFactory.getLogger(OmnSerFilter.class); - - public static final String name = "specifyAddress"; - - @Override - public Result invoke(Invoker invoker, Invocation invocation) throws RpcException { - - Object address = invocation.get(SPECIFY_ADDRESS); - if (address != null) { - RpcContext.getClientAttachment().setAttachment(GATEWAY_MODE, "omn"); - convertParameterTypeToJavaBeanDescriptor(invocation); - } - return invoker.invoke(invocation); - } - - - @Override - public void onResponse(Result appResponse, Invoker invoker, Invocation inv) { - - Object resData = appResponse.getValue(); - if (resData == null) { - return; - } - - if (ReflectUtils.isPrimitives(resData.getClass())) { - return; - } - generalizeJbdParameter(appResponse.getValue()); - } - - @Override - public void onError(Throwable t, Invoker invoker, Invocation invocation) { - - } - - - @SuppressWarnings({"unchecked", "rawtypes"}) - private void generalizeJbdParameter(Object pojo) { - if (pojo instanceof Collection) { - - Collection collection = (Collection) pojo; - List list = new ArrayList(); - for (Object obj : collection) { - if (obj instanceof JavaBeanDescriptor) { - list.add(JavaBeanSerializeUtil.deserialize((JavaBeanDescriptor) obj)); - } else { - list.add(obj); - } - } - collection.clear(); - collection.addAll(list); - } - - if (pojo instanceof Map) { - - Map map = (Map) pojo; - Map newMap = new HashMap(); - for (Object key : map.keySet()) { - - Object value = map.get(key); - if (key instanceof JavaBeanDescriptor) { - key = JavaBeanSerializeUtil.deserialize((JavaBeanDescriptor) key); - } - if (value instanceof JavaBeanDescriptor) { - value = JavaBeanSerializeUtil.deserialize((JavaBeanDescriptor) value); - } - newMap.put(key, value); - - } - map.clear(); - map.putAll(newMap); - } - - // public field - for (Field field : pojo.getClass().getDeclaredFields()) { - try { - field.setAccessible(true); - Object fieldValue = field.get(pojo); - if (fieldValue instanceof JavaBeanDescriptor) { - field.set(pojo, JavaBeanSerializeUtil.deserialize((JavaBeanDescriptor) fieldValue)); - } - } catch (Exception e) { - throw new RuntimeException(e.getMessage(), e); - } - } - } - - public static void convertParameterTypeToJavaBeanDescriptor(Invocation invocation) { - if (!(invocation instanceof RpcInvocation)) { - logger.warn("Non-RpcInvocation type, gateway mode does not take effect, type:" + invocation.getClass().getName()); - return; - } - Class[] parameterTypes = invocation.getParameterTypes(); - boolean reqFirst = Arrays.stream(parameterTypes).noneMatch(param -> param == JavaBeanDescriptor.class); - if (reqFirst) { - invocation.setObjectAttachment(ORIGIN_GENERIC_PARAMETER_TYPES, getDesc(parameterTypes)); - invocation.setObjectAttachment(ORIGIN_PARAMETER_TYPES_DESC, ((RpcInvocation) invocation).getParameterTypesDesc()); - Arrays.fill(parameterTypes, JavaBeanDescriptor.class); - - Object[] arguments = invocation.getArguments(); - for (int i = 0; i < arguments.length; i++) { - JavaBeanDescriptor jbdArg = JavaBeanSerializeUtil.serialize(arguments[i]); - arguments[i] = jbdArg; - } - - ((RpcInvocation) invocation).setParameterTypesDesc(ReflectUtils.getDesc(parameterTypes)); - ((RpcInvocation) invocation).setCompatibleParamSignatures(Stream.of(parameterTypes).map(Class::getName).toArray(String[]::new)); - } - - } - - private static String[] getDesc(Class[] parameterTypes) { - return Arrays.stream(parameterTypes).map(Class::getName).toArray(String[]::new); - } -} diff --git a/dubbo-gateway-extensions/dubbo-gateway-consumer/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.config.ConfigPostProcessor b/dubbo-gateway-extensions/dubbo-gateway-consumer/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.config.ConfigPostProcessor deleted file mode 100644 index 058a13e7f..000000000 --- a/dubbo-gateway-extensions/dubbo-gateway-consumer/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.config.ConfigPostProcessor +++ /dev/null @@ -1 +0,0 @@ -injvm-initial=org.apache.dubbo.gateway.consumer.config.InjvmConfigPostProcessor diff --git a/dubbo-gateway-extensions/dubbo-gateway-consumer/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter b/dubbo-gateway-extensions/dubbo-gateway-consumer/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter deleted file mode 100644 index 319ef6f04..000000000 --- a/dubbo-gateway-extensions/dubbo-gateway-consumer/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter +++ /dev/null @@ -1 +0,0 @@ -omnSer=org.apache.dubbo.gateway.consumer.filter.OmnSerFilter diff --git a/dubbo-gateway-extensions/dubbo-gateway-provider/pom.xml b/dubbo-gateway-extensions/dubbo-gateway-provider/pom.xml deleted file mode 100644 index c673308cb..000000000 --- a/dubbo-gateway-extensions/dubbo-gateway-provider/pom.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - dubbo-gateway-extensions - org.apache.dubbo.extensions - ${revision} - ../pom.xml - - 4.0.0 - - dubbo-gateway-provider - - - 8 - 8 - - - - - - org.apache.dubbo - dubbo - 3.2.0 - true - - - org.apache.dubbo.extensions - dubbo-gateway-common - ${project.version} - - - - - diff --git a/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/java/org/apache/dubbo/gateway/provider/ConfigDeployListener.java b/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/java/org/apache/dubbo/gateway/provider/ConfigDeployListener.java deleted file mode 100644 index 788d8c024..000000000 --- a/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/java/org/apache/dubbo/gateway/provider/ConfigDeployListener.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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 org.apache.dubbo.gateway.provider; - -import org.apache.dubbo.common.deploy.ApplicationDeployListener; -import org.apache.dubbo.rpc.model.ApplicationModel; - -import static org.apache.dubbo.common.constants.CommonConstants.BYTE_ACCESSOR_KEY; - -public class ConfigDeployListener implements ApplicationDeployListener { - - @Override - public void onInitialize(ApplicationModel scopeModel) { - System.setProperty(BYTE_ACCESSOR_KEY, "snf"); - } - - @Override - public void onStarting(ApplicationModel scopeModel) { - - } - - @Override - public void onStarted(ApplicationModel scopeModel) { - } - - @Override - public void onStopping(ApplicationModel scopeModel) { - - } - - @Override - public void onStopped(ApplicationModel scopeModel) { - - } - - @Override - public void onFailure(ApplicationModel scopeModel, Throwable cause) { - - } -} diff --git a/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/java/org/apache/dubbo/gateway/provider/OmnipotentService.java b/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/java/org/apache/dubbo/gateway/provider/OmnipotentService.java deleted file mode 100644 index 07a8ae3e3..000000000 --- a/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/java/org/apache/dubbo/gateway/provider/OmnipotentService.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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 org.apache.dubbo.gateway.provider; - -import org.apache.dubbo.rpc.Invocation; -import org.apache.dubbo.rpc.service.GenericException; -import org.apache.dubbo.rpc.service.GenericService; - -/** - * A more general server-side generalization service than {@link GenericService} - * Any type of interface can be accepted - * - * @since 3.2.0 - */ -public interface OmnipotentService { - - /** - * Generic invocation - * - * @param invocation New construction point invocation, including original service, method and other information - * @return Custom object - * @throws GenericException potential exception thrown from the invocation - */ - Object $invokeOmn(Invocation invocation) throws GenericException; - - -} diff --git a/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/java/org/apache/dubbo/gateway/provider/SnfByteAccessor.java b/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/java/org/apache/dubbo/gateway/provider/SnfByteAccessor.java deleted file mode 100644 index 9adf60254..000000000 --- a/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/java/org/apache/dubbo/gateway/provider/SnfByteAccessor.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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 org.apache.dubbo.gateway.provider; - -import org.apache.dubbo.remoting.Channel; -import org.apache.dubbo.remoting.exchange.Request; -import org.apache.dubbo.rpc.model.FrameworkModel; -import org.apache.dubbo.rpc.protocol.dubbo.ByteAccessor; -import org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation; - -import java.io.InputStream; - -/** - * Customize byte parsing so that execution can continue when the service does not exist - * - * @since 3.2.0 - */ -public class SnfByteAccessor implements ByteAccessor { - - private final FrameworkModel frameworkModel; - - public SnfByteAccessor(FrameworkModel frameworkModel) { - this.frameworkModel = frameworkModel; - } - - @Override - public DecodeableRpcInvocation getRpcInvocation(Channel channel, Request req, InputStream is, byte proto) { - - return new SnfDecodeableRpcInvocation(frameworkModel, channel, req, is, proto); - } -} diff --git a/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/java/org/apache/dubbo/gateway/provider/SnfDecodeableRpcInvocation.java b/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/java/org/apache/dubbo/gateway/provider/SnfDecodeableRpcInvocation.java deleted file mode 100644 index 899939745..000000000 --- a/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/java/org/apache/dubbo/gateway/provider/SnfDecodeableRpcInvocation.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * 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 org.apache.dubbo.gateway.provider; - -import org.apache.dubbo.common.beanutil.JavaBeanDescriptor; -import org.apache.dubbo.common.beanutil.JavaBeanSerializeUtil; -import org.apache.dubbo.common.serialize.Cleanable; -import org.apache.dubbo.common.serialize.ObjectInput; -import org.apache.dubbo.common.utils.CollectionUtils; -import org.apache.dubbo.common.utils.ReflectUtils; -import org.apache.dubbo.common.utils.StringUtils; -import org.apache.dubbo.gateway.common.OmnipotentCommonConstants; -import org.apache.dubbo.remoting.Channel; -import org.apache.dubbo.remoting.exchange.Request; -import org.apache.dubbo.remoting.transport.CodecSupport; -import org.apache.dubbo.rpc.Invocation; -import org.apache.dubbo.rpc.model.FrameworkModel; -import org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation; -import org.apache.dubbo.rpc.protocol.dubbo.DubboCodec; -import org.apache.dubbo.rpc.support.RpcUtils; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Map; - -import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_VERSION; -import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_VERSION_KEY; -import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; -import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY; -import static org.apache.dubbo.common.constants.CommonConstants.METHOD_KEY; -import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY; -import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; -import static org.apache.dubbo.gateway.common.OmnipotentCommonConstants.$INVOKE_OMN; -import static org.apache.dubbo.gateway.common.OmnipotentCommonConstants.ORIGIN_GENERIC_PARAMETER_TYPES; -import static org.apache.dubbo.gateway.common.OmnipotentCommonConstants.ORIGIN_GROUP_KEY; -import static org.apache.dubbo.gateway.common.OmnipotentCommonConstants.ORIGIN_PARAMETER_TYPES_DESC; -import static org.apache.dubbo.rpc.Constants.SERIALIZATION_ID_KEY; - -public class SnfDecodeableRpcInvocation extends DecodeableRpcInvocation { - - private static final String DEFAULT_OMNIPOTENT_SERVICE = OmnipotentService.class.getName(); - - - public SnfDecodeableRpcInvocation(FrameworkModel frameworkModel, Channel channel, Request request, InputStream is, byte id) { - super(frameworkModel, channel, request, is, id); - } - - @Override - public Object decode(Channel channel, InputStream input) throws IOException { - ObjectInput in = CodecSupport.getSerialization(serializationType) - .deserialize(channel.getUrl(), input); - this.put(SERIALIZATION_ID_KEY, serializationType); - - String dubboVersion = in.readUTF(); - request.setVersion(dubboVersion); - setAttachment(DUBBO_VERSION_KEY, dubboVersion); - - String path = in.readUTF(); - setAttachment(PATH_KEY, path); - String version = in.readUTF(); - setAttachment(VERSION_KEY, version); - - setMethodName(in.readUTF()); - - String desc = in.readUTF(); - setParameterTypesDesc(desc); - - ClassLoader originClassLoader = Thread.currentThread().getContextClassLoader(); - - try { - Object[] args = DubboCodec.EMPTY_OBJECT_ARRAY; - Class[] pts = DubboCodec.EMPTY_CLASS_ARRAY; - if (desc.length() > 0) { - pts = drawPts(path, version, desc, pts); - if (pts == DubboCodec.EMPTY_CLASS_ARRAY) { - // Service not found ,pts = JavaBeanDescriptor - pts = ReflectUtils.desc2classArray(desc); - } - args = drawArgs(in, pts); - } - setParameterTypes(pts); - setAttachment(ORIGIN_GENERIC_PARAMETER_TYPES, pts); - - Map map = in.readAttachments(); - Class[] retryPts = null; - if (CollectionUtils.isNotEmptyMap(map)) { - if (map.containsKey(ORIGIN_PARAMETER_TYPES_DESC)) { - String originParameterTypesDesc = map.get(ORIGIN_PARAMETER_TYPES_DESC).toString(); - retryPts = drawPts(path, version, originParameterTypesDesc, DubboCodec.EMPTY_CLASS_ARRAY); - boolean snf = (retryPts == DubboCodec.EMPTY_CLASS_ARRAY) && !RpcUtils.isGenericCall(originParameterTypesDesc, getMethodName()) && !RpcUtils.isEcho(originParameterTypesDesc, getMethodName()); - if (snf) { - setAttachment(OmnipotentCommonConstants.ORIGIN_PATH_KEY, getAttachment(PATH_KEY)); - // Replace serviceName in req with omn - setAttachment(PATH_KEY, DEFAULT_OMNIPOTENT_SERVICE); - setAttachment(INTERFACE_KEY, DEFAULT_OMNIPOTENT_SERVICE); - - // version - setAttachment(OmnipotentCommonConstants.ORIGIN_VERSION_KEY, getAttachment(VERSION_KEY)); - setAttachment(VERSION_KEY, DEFAULT_VERSION); - - // method - setAttachment(OmnipotentCommonConstants.ORIGIN_METHOD_KEY, getMethodName()); - setAttachment(METHOD_KEY, $INVOKE_OMN); - setMethodName($INVOKE_OMN); - setParameterTypes(new Class[]{Invocation.class}); - - // Omn needs to use the default path, version and group, - // and the original value starts with origin to save the variable - map.remove(PATH_KEY); - map.remove(VERSION_KEY); - if (map.containsKey(GROUP_KEY)) { - map.put(ORIGIN_GROUP_KEY, map.get(GROUP_KEY)); - map.remove(GROUP_KEY); - } - retryPts = (Class[]) getObjectAttachments().get(ORIGIN_GENERIC_PARAMETER_TYPES); - } - } - - addObjectAttachments(map); - } - - boolean isConvert = false; - for (Class clazz : pts) { - if (clazz == JavaBeanDescriptor.class) { - isConvert = true; - break; - } - } - // isConvert = snf - if (isConvert) { - setParameterTypes(retryPts); - pts = retryPts; - Object[] newArgs = new Object[args.length]; - for (int i = 0; i < args.length; i++) { - if (args[i] instanceof JavaBeanDescriptor) { - newArgs[i] = JavaBeanSerializeUtil.deserialize((JavaBeanDescriptor) args[i]); - } - } - args = newArgs; - } - decodeArgument(channel, pts, args); - } catch (ClassNotFoundException e) { - throw new IOException(StringUtils.toString("Read invocation data failed.", e)); - } finally { - Thread.currentThread().setContextClassLoader(originClassLoader); - if (in instanceof Cleanable) { - ((Cleanable) in).cleanup(); - } - } - return this; - } - -} diff --git a/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/java/org/apache/dubbo/gateway/provider/filter/OmnipotentFilter.java b/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/java/org/apache/dubbo/gateway/provider/filter/OmnipotentFilter.java deleted file mode 100644 index 3357a6dd3..000000000 --- a/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/java/org/apache/dubbo/gateway/provider/filter/OmnipotentFilter.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * 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 org.apache.dubbo.gateway.provider.filter; - -import org.apache.dubbo.common.beanutil.JavaBeanAccessor; -import org.apache.dubbo.common.beanutil.JavaBeanDescriptor; -import org.apache.dubbo.common.beanutil.JavaBeanSerializeUtil; -import org.apache.dubbo.common.constants.CommonConstants; -import org.apache.dubbo.common.extension.Activate; -import org.apache.dubbo.gateway.common.OmnipotentCommonConstants; -import org.apache.dubbo.gateway.provider.OmnipotentService; -import org.apache.dubbo.rpc.Filter; -import org.apache.dubbo.rpc.Invocation; -import org.apache.dubbo.rpc.Invoker; -import org.apache.dubbo.rpc.Result; -import org.apache.dubbo.rpc.RpcContext; -import org.apache.dubbo.rpc.RpcException; -import org.apache.dubbo.rpc.RpcInvocation; - -import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; -import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY; -import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; - -/** - * Set the method name, formal parameters, and actual parameters for - * the invokeOmn method of the Omnipotent generalized service - */ -@Activate(group = CommonConstants.PROVIDER, order = -21000) -public class OmnipotentFilter implements Filter { - - @Override - public Result invoke(Invoker invoker, Invocation inv) throws RpcException { - - if (isOmnipotent(invoker.getInterface())) { - setOmnArgs(inv); - inv.getObjectAttachments().remove(OmnipotentCommonConstants.ORIGIN_GENERIC_PARAMETER_TYPES); - RpcContext.getServerAttachment().removeAttachment(OmnipotentCommonConstants.ORIGIN_GENERIC_PARAMETER_TYPES); - } - - return invoker.invoke(inv); - } - - private boolean isOmnipotent(Class interfaceClass) { - return OmnipotentService.class.isAssignableFrom(interfaceClass); - } - - // Restore method information before actual call - private void setOmnArgs(Invocation inv) { - Class[] parameterTypes = (Class[]) inv.getObjectAttachment(OmnipotentCommonConstants.ORIGIN_GENERIC_PARAMETER_TYPES, new Class[]{Invocation.class}); - Object[] arguments = inv.getArguments(); - - Object[] args = new Object[arguments.length]; - for (int i = 0; i < arguments.length; i++) { - // In gateway mode, consumer has used JavaBeanDescriptor as parameter - if (arguments[i] instanceof JavaBeanDescriptor) { - args[i] = arguments[i]; - } else { - args[i] = JavaBeanSerializeUtil.serialize(arguments[i], JavaBeanAccessor.METHOD); - } - } - - RpcInvocation rpcInvocation = new RpcInvocation(inv); - // method - rpcInvocation.setMethodName(inv.getAttachment(OmnipotentCommonConstants.ORIGIN_METHOD_KEY)); - rpcInvocation.setParameterTypes(parameterTypes); - rpcInvocation.setArguments(args); - rpcInvocation.setParameterTypesDesc(inv.getAttachment(OmnipotentCommonConstants.ORIGIN_PARAMETER_TYPES_DESC)); - - // attachment - rpcInvocation.setAttachment(PATH_KEY, inv.getAttachment(OmnipotentCommonConstants.ORIGIN_PATH_KEY)); - rpcInvocation.setAttachment(VERSION_KEY, inv.getAttachment(OmnipotentCommonConstants.ORIGIN_VERSION_KEY)); - rpcInvocation.setAttachment(GROUP_KEY, inv.getAttachment(OmnipotentCommonConstants.ORIGIN_GROUP_KEY)); - ((RpcInvocation) inv).setArguments(new Object[]{rpcInvocation}); - - } - -} diff --git a/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.deploy.ApplicationDeployListener b/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.deploy.ApplicationDeployListener deleted file mode 100644 index 04ede7f59..000000000 --- a/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.deploy.ApplicationDeployListener +++ /dev/null @@ -1 +0,0 @@ -snfConfig=org.apache.dubbo.gateway.provider.ConfigDeployListener diff --git a/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter b/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter deleted file mode 100644 index 9247c64e2..000000000 --- a/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter +++ /dev/null @@ -1 +0,0 @@ -omnipotent=org.apache.dubbo.gateway.provider.filter.OmnipotentFilter diff --git a/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.dubbo.ByteAccessor b/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.dubbo.ByteAccessor deleted file mode 100644 index 7e33fa6bb..000000000 --- a/dubbo-gateway-extensions/dubbo-gateway-provider/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.dubbo.ByteAccessor +++ /dev/null @@ -1 +0,0 @@ -snf=org.apache.dubbo.gateway.provider.SnfByteAccessor diff --git a/dubbo-gateway-extensions/pom.xml b/dubbo-gateway-extensions/pom.xml deleted file mode 100644 index 3a41e5ac6..000000000 --- a/dubbo-gateway-extensions/pom.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - org.apache.dubbo.extensions - extensions-parent - ${revision} - ../pom.xml - - 4.0.0 - - dubbo-gateway-extensions - ${revision} - pom - - - dubbo-gateway-common - dubbo-gateway-provider - dubbo-gateway-consumer - - - diff --git a/dubbo-metadata-report-extensions/dubbo-metadata-report-consul/pom.xml b/dubbo-metadata-report-extensions/dubbo-metadata-report-consul/pom.xml index d1cb758b5..7e58ec279 100644 --- a/dubbo-metadata-report-extensions/dubbo-metadata-report-consul/pom.xml +++ b/dubbo-metadata-report-extensions/dubbo-metadata-report-consul/pom.xml @@ -26,7 +26,7 @@ 4.0.0 - 1.0.2-SNAPSHOT + ${revision} dubbo-metadata-report-consul @@ -39,7 +39,7 @@ org.apache.dubbo.extensions dubbo-configcenter-consul - 1.0.2-SNAPSHOT + ${revision} com.ecwid.consul diff --git a/dubbo-metadata-report-extensions/dubbo-metadata-report-etcd/pom.xml b/dubbo-metadata-report-extensions/dubbo-metadata-report-etcd/pom.xml index 9a6f2609d..dfbdfa61a 100644 --- a/dubbo-metadata-report-extensions/dubbo-metadata-report-etcd/pom.xml +++ b/dubbo-metadata-report-extensions/dubbo-metadata-report-etcd/pom.xml @@ -27,7 +27,7 @@ 4.0.0 - 1.0.2-SNAPSHOT + ${revision} dubbo-metadata-report-etcd @@ -44,7 +44,7 @@ org.apache.dubbo.extensions dubbo-remoting-etcd3 - 1.0.2-SNAPSHOT + ${revision} io.etcd diff --git a/dubbo-mock-extensions/dubbo-mock-admin/pom.xml b/dubbo-mock-extensions/dubbo-mock-admin/pom.xml index ed61404ab..5438ce032 100644 --- a/dubbo-mock-extensions/dubbo-mock-admin/pom.xml +++ b/dubbo-mock-extensions/dubbo-mock-admin/pom.xml @@ -20,7 +20,7 @@ dubbo-mock-extensions org.apache.dubbo.extensions - 3.0.6-SNAPSHOT + ${revision} ../pom.xml 4.0.0 @@ -31,7 +31,7 @@ org.apache.dubbo.extensions dubbo-mock-api - 3.0.6-SNAPSHOT + ${revision} diff --git a/dubbo-mock-extensions/dubbo-mock-api/pom.xml b/dubbo-mock-extensions/dubbo-mock-api/pom.xml index d63e19140..9d6196a12 100644 --- a/dubbo-mock-extensions/dubbo-mock-api/pom.xml +++ b/dubbo-mock-extensions/dubbo-mock-api/pom.xml @@ -20,7 +20,7 @@ dubbo-mock-extensions org.apache.dubbo.extensions - 3.0.6-SNAPSHOT + ${revision} ../pom.xml 4.0.0 diff --git a/dubbo-mock-extensions/pom.xml b/dubbo-mock-extensions/pom.xml index ef926b6ff..17903cf27 100644 --- a/dubbo-mock-extensions/pom.xml +++ b/dubbo-mock-extensions/pom.xml @@ -27,7 +27,7 @@ dubbo-mock-extensions pom - 3.0.6-SNAPSHOT + ${revision} dubbo-mock-api dubbo-mock-admin diff --git a/dubbo-registry-extensions/dubbo-registry-consul/pom.xml b/dubbo-registry-extensions/dubbo-registry-consul/pom.xml index 6d54af330..707f8f902 100644 --- a/dubbo-registry-extensions/dubbo-registry-consul/pom.xml +++ b/dubbo-registry-extensions/dubbo-registry-consul/pom.xml @@ -25,7 +25,7 @@ 4.0.0 - 1.0.2-SNAPSHOT + ${revision} dubbo-registry-consul diff --git a/dubbo-registry-extensions/dubbo-registry-dns/pom.xml b/dubbo-registry-extensions/dubbo-registry-dns/pom.xml deleted file mode 100644 index afa6592eb..000000000 --- a/dubbo-registry-extensions/dubbo-registry-dns/pom.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - - dubbo-registry-extensions - org.apache.dubbo.extensions - ${revision} - ../pom.xml - - 4.0.0 - - dubbo-registry-dns - jar - ${project.artifactId} - 1.0.2-SNAPSHOT - The DNS registry module of Dubbo project - - - - org.apache.dubbo - dubbo - true - - - io.netty - netty-all - - - com.alibaba - fastjson - - - diff --git a/dubbo-registry-extensions/dubbo-registry-dns/src/main/java/org/apache/dubbo/registry/dns/DNSRegistry.java b/dubbo-registry-extensions/dubbo-registry-dns/src/main/java/org/apache/dubbo/registry/dns/DNSRegistry.java deleted file mode 100644 index 79fa0cd88..000000000 --- a/dubbo-registry-extensions/dubbo-registry-dns/src/main/java/org/apache/dubbo/registry/dns/DNSRegistry.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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 org.apache.dubbo.registry.dns; - -import org.apache.dubbo.common.URL; -import org.apache.dubbo.registry.NotifyListener; -import org.apache.dubbo.registry.support.FailbackRegistry; - -/** - * Empty implements for DNS
- * DNS only support `Service Discovery` mode register
- * Used to compat past version like 2.6.x, 2.7.x with interface level register
- * {@link DNSServiceDiscovery} is the real implementation of DNS - */ -public class DNSRegistry extends FailbackRegistry { - public DNSRegistry(URL url) { - super(url); - } - - @Override - public boolean isAvailable() { - return true; - } - - @Override - public void doRegister(URL url) { - - } - - @Override - public void doUnregister(URL url) { - - } - - @Override - public void doSubscribe(URL url, NotifyListener listener) { - - } - - @Override - public void doUnsubscribe(URL url, NotifyListener listener) { - - } -} diff --git a/dubbo-registry-extensions/dubbo-registry-dns/src/main/java/org/apache/dubbo/registry/dns/DNSRegistryFactory.java b/dubbo-registry-extensions/dubbo-registry-dns/src/main/java/org/apache/dubbo/registry/dns/DNSRegistryFactory.java deleted file mode 100644 index 870485e36..000000000 --- a/dubbo-registry-extensions/dubbo-registry-dns/src/main/java/org/apache/dubbo/registry/dns/DNSRegistryFactory.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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 org.apache.dubbo.registry.dns; - -import org.apache.dubbo.common.URL; -import org.apache.dubbo.registry.Registry; -import org.apache.dubbo.registry.support.AbstractRegistryFactory; - -public class DNSRegistryFactory extends AbstractRegistryFactory { - - @Override - protected String createRegistryCacheKey(URL url) { - return url.toFullString(); - } - - @Override - protected Registry createRegistry(URL url) { - return new DNSRegistry(url); - } -} diff --git a/dubbo-registry-extensions/dubbo-registry-dns/src/main/java/org/apache/dubbo/registry/dns/DNSServiceDiscovery.java b/dubbo-registry-extensions/dubbo-registry-dns/src/main/java/org/apache/dubbo/registry/dns/DNSServiceDiscovery.java deleted file mode 100644 index 3c267860a..000000000 --- a/dubbo-registry-extensions/dubbo-registry-dns/src/main/java/org/apache/dubbo/registry/dns/DNSServiceDiscovery.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * 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 org.apache.dubbo.registry.dns; - -import org.apache.dubbo.common.URL; -import org.apache.dubbo.common.logger.Logger; -import org.apache.dubbo.common.logger.LoggerFactory; -import org.apache.dubbo.common.utils.NamedThreadFactory; -import org.apache.dubbo.registry.client.DefaultServiceInstance; -import org.apache.dubbo.registry.client.ReflectionBasedServiceDiscovery; -import org.apache.dubbo.registry.client.ServiceInstance; -import org.apache.dubbo.registry.client.event.listener.ServiceInstancesChangedListener; -import org.apache.dubbo.registry.dns.util.DNSClientConst; -import org.apache.dubbo.registry.dns.util.DNSResolver; -import org.apache.dubbo.registry.dns.util.ResolveResult; -import org.apache.dubbo.rpc.model.ApplicationModel; -import org.apache.dubbo.rpc.model.ScopeModelUtil; - -import java.util.Collections; -import java.util.Comparator; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.TimeUnit; - -public class DNSServiceDiscovery extends ReflectionBasedServiceDiscovery { - private static final Logger logger = LoggerFactory.getLogger(DNSServiceDiscovery.class); - - /** - * DNS properties - */ - - private final String addressPrefix; - private final String addressSuffix; - private final long pollingCycle; - private DNSResolver dnsResolver; - - /** - * Polling task ScheduledFuture, used to stop task when destroy - */ - private final ConcurrentHashMap> pollingExecutorMap = new ConcurrentHashMap<>(); - - /** - * Polling check provider ExecutorService - */ - private final ScheduledExecutorService pollingExecutorService; - - public DNSServiceDiscovery(ApplicationModel applicationModel, URL registryURL) { - super(applicationModel, registryURL); - this.addressPrefix = registryURL.getParameter(DNSClientConst.ADDRESS_PREFIX, ""); - this.addressSuffix = registryURL.getParameter(DNSClientConst.ADDRESS_SUFFIX, ""); - this.pollingCycle = registryURL.getParameter(DNSClientConst.DNS_POLLING_CYCLE, DNSClientConst.DEFAULT_DNS_POLLING_CYCLE); - - String nameserver = registryURL.getHost(); - int port = registryURL.getPort(); - int maxQueriesPerResolve = registryURL.getParameter(DNSClientConst.MAX_QUERIES_PER_RESOLVE, 10); - this.dnsResolver = new DNSResolver(nameserver, port, maxQueriesPerResolve); - - - int scheduledThreadPoolSize = registryURL.getParameter(DNSClientConst.DNS_POLLING_POOL_SIZE_KEY, DNSClientConst.DEFAULT_DNS_POLLING_POOL_SIZE); - - // polling task may take a lot of time, create a new ScheduledThreadPool - pollingExecutorService = Executors.newScheduledThreadPool(scheduledThreadPoolSize, new NamedThreadFactory("Dubbo-DNS-Poll")); - - } - - @Override - public void doDestroy() throws Exception { - super.doDestroy(); - dnsResolver.destroy(); - pollingExecutorMap.forEach((serviceName, scheduledFuture) -> scheduledFuture.cancel(true)); - pollingExecutorMap.clear(); - pollingExecutorService.shutdown(); - } - - @Override - public Set getServices() { - // it is impossible for dns to discover service names - return Collections.singleton("Unsupported Method"); - } - - @Override - public List getInstances(String serviceName) throws NullPointerException { - - String serviceAddress = addressPrefix + serviceName + addressSuffix; - - ResolveResult resolveResult = dnsResolver.resolve(serviceAddress); - - return toServiceInstance(serviceName, resolveResult); - } - - @Override - public void addServiceInstancesChangedListener(ServiceInstancesChangedListener listener) throws NullPointerException, IllegalArgumentException { - listener.getServiceNames().forEach(serviceName -> { - ScheduledFuture scheduledFuture = pollingExecutorService.scheduleAtFixedRate(() -> { - List instances = getInstances(serviceName); - instances.sort(Comparator.comparingInt(ServiceInstance::hashCode)); - notifyListener(serviceName, listener, instances); - }, - pollingCycle, pollingCycle, TimeUnit.MILLISECONDS); - - pollingExecutorMap.put(serviceName, scheduledFuture); - }); - } - - /** - * UT used only - */ - @Deprecated - public void setDnsResolver(DNSResolver dnsResolver) { - this.dnsResolver = dnsResolver; - } - - private List toServiceInstance(String serviceName, ResolveResult resolveResult) { - - int port; - - if (resolveResult.getPort().size() > 0) { - // use first as default - port = resolveResult.getPort().get(0); - } else { - // not support SRV record - port = 20880; - } - - List instanceList = new LinkedList<>(); - - for (String host : resolveResult.getHostnameList()) { - DefaultServiceInstance serviceInstance = new DefaultServiceInstance(serviceName, host, port, ScopeModelUtil.getApplicationModel(getUrl().getScopeModel())); - fillServiceInstance(serviceInstance); - instanceList.add(serviceInstance); - } - - return instanceList; - } -} diff --git a/dubbo-registry-extensions/dubbo-registry-dns/src/main/java/org/apache/dubbo/registry/dns/DNSServiceDiscoveryFactory.java b/dubbo-registry-extensions/dubbo-registry-dns/src/main/java/org/apache/dubbo/registry/dns/DNSServiceDiscoveryFactory.java deleted file mode 100644 index cc4673a3c..000000000 --- a/dubbo-registry-extensions/dubbo-registry-dns/src/main/java/org/apache/dubbo/registry/dns/DNSServiceDiscoveryFactory.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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 org.apache.dubbo.registry.dns; - -import org.apache.dubbo.common.URL; -import org.apache.dubbo.registry.client.AbstractServiceDiscoveryFactory; -import org.apache.dubbo.registry.client.ServiceDiscovery; - -public class DNSServiceDiscoveryFactory extends AbstractServiceDiscoveryFactory { - @Override - protected ServiceDiscovery createDiscovery(URL registryURL) { - return new DNSServiceDiscovery(applicationModel, registryURL); - } -} diff --git a/dubbo-registry-extensions/dubbo-registry-dns/src/main/java/org/apache/dubbo/registry/dns/util/DNSClientConst.java b/dubbo-registry-extensions/dubbo-registry-dns/src/main/java/org/apache/dubbo/registry/dns/util/DNSClientConst.java deleted file mode 100644 index 0fc8ada5f..000000000 --- a/dubbo-registry-extensions/dubbo-registry-dns/src/main/java/org/apache/dubbo/registry/dns/util/DNSClientConst.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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 org.apache.dubbo.registry.dns.util; - -public class DNSClientConst { - - public final static String ADDRESS_PREFIX = "addressPrefix"; - - public final static String ADDRESS_SUFFIX = "addressSuffix"; - - public final static String MAX_QUERIES_PER_RESOLVE = "maxQueriesPerResolve"; - - /** - * To decide the frequency of execute DNS poll (in ms) - */ - public final static String DNS_POLLING_CYCLE = "dnsPollingCycle"; - - /** - * Default value for check frequency: 60000 (ms) - */ - public final static int DEFAULT_DNS_POLLING_CYCLE = 60000; - - /** - * To decide how many threads used to execute DNS poll - */ - public final static String DNS_POLLING_POOL_SIZE_KEY = "dnsPollingPoolSize"; - - /** - * Default value for DNS pool thread: 1 - */ - public final static int DEFAULT_DNS_POLLING_POOL_SIZE = 1; - -} diff --git a/dubbo-registry-extensions/dubbo-registry-dns/src/main/java/org/apache/dubbo/registry/dns/util/DNSResolver.java b/dubbo-registry-extensions/dubbo-registry-dns/src/main/java/org/apache/dubbo/registry/dns/util/DNSResolver.java deleted file mode 100644 index eb520d22b..000000000 --- a/dubbo-registry-extensions/dubbo-registry-dns/src/main/java/org/apache/dubbo/registry/dns/util/DNSResolver.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * 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 org.apache.dubbo.registry.dns.util; - -import org.apache.dubbo.common.logger.Logger; -import org.apache.dubbo.common.logger.LoggerFactory; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.AddressedEnvelope; -import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; -import io.netty.channel.socket.nio.NioDatagramChannel; -import io.netty.handler.codec.dns.DefaultDnsQuestion; -import io.netty.handler.codec.dns.DnsRawRecord; -import io.netty.handler.codec.dns.DnsRecordType; -import io.netty.handler.codec.dns.DnsResponse; -import io.netty.handler.codec.dns.DnsSection; -import io.netty.resolver.ResolvedAddressTypes; -import io.netty.resolver.dns.DnsNameResolver; -import io.netty.resolver.dns.DnsNameResolverBuilder; -import io.netty.util.concurrent.Future; - -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.UnknownHostException; -import java.util.List; -import java.util.stream.Collectors; - -import static io.netty.resolver.dns.DnsServerAddresses.sequential; - -public class DNSResolver { - - private final Logger logger = LoggerFactory.getLogger(getClass()); - - private final DnsNameResolver resolver; - - private static final EventLoopGroup GROUP = new NioEventLoopGroup(1); - - public DNSResolver(String nameserver, int port, int maxQueriesPerResolve) { - this.resolver = newResolver(nameserver, port, maxQueriesPerResolve); - } - - public ResolveResult resolve(String path) { - ResolveResult recordList = new ResolveResult(); - - try { - Future> hostFuture = resolver.resolveAll(path); - Future> srvFuture = - resolver.query(new DefaultDnsQuestion(path, DnsRecordType.SRV)); - - try { - recordList.getHostnameList() - .addAll(hostFuture - .sync().getNow() - .stream() - .map(InetAddress::getHostAddress) - .collect(Collectors.toList())); - - DnsResponse srvResponse = srvFuture.sync().getNow().content(); - for (int i = 0; i < srvResponse.count(DnsSection.ANSWER); i++) { - DnsRawRecord record = srvResponse.recordAt(DnsSection.ANSWER, i); - ByteBuf buf = record.content(); - // Priority - buf.readUnsignedShort(); - // Weight - buf.readUnsignedShort(); - // Port - int port = buf.readUnsignedShort(); - recordList.getPort().add(port); - } - - } catch (InterruptedException e) { - logger.warn("Waiting DNS resolve interrupted. " + e.getLocalizedMessage()); - } - } catch (Throwable t) { - if (t instanceof UnknownHostException) { - if (logger.isInfoEnabled()) { - logger.info(t.getLocalizedMessage()); - } - } else { - logger.error(t.getLocalizedMessage()); - } - } - - - return recordList; - } - - public void destroy() { - resolver.close(); - } - - private static DnsNameResolver newResolver(String nameserver, int port, int maxQueriesPerResolve) { - return new DnsNameResolverBuilder(GROUP.next()) - .channelType(NioDatagramChannel.class) - .maxQueriesPerResolve(maxQueriesPerResolve) - .decodeIdn(true) - .optResourceEnabled(false) - .ndots(1) - .resolvedAddressTypes(ResolvedAddressTypes.IPV4_PREFERRED) - // ignore cache - .ttl(0, 1) - .nameServerProvider((hostname) -> sequential(new InetSocketAddress(nameserver, port)).stream()) - .build(); - } -} diff --git a/dubbo-registry-extensions/dubbo-registry-dns/src/main/java/org/apache/dubbo/registry/dns/util/ResolveResult.java b/dubbo-registry-extensions/dubbo-registry-dns/src/main/java/org/apache/dubbo/registry/dns/util/ResolveResult.java deleted file mode 100644 index ca83e20fb..000000000 --- a/dubbo-registry-extensions/dubbo-registry-dns/src/main/java/org/apache/dubbo/registry/dns/util/ResolveResult.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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 org.apache.dubbo.registry.dns.util; - -import java.util.LinkedList; -import java.util.List; -import java.util.Objects; - -public class ResolveResult { - - private List hostnameList = new LinkedList<>(); - - private List port = new LinkedList<>(); - - public List getHostnameList() { - return hostnameList; - } - - public void setHostnameList(List hostnameList) { - this.hostnameList = hostnameList; - } - - public List getPort() { - return port; - } - - public void setPort(List port) { - this.port = port; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - ResolveResult that = (ResolveResult) o; - return Objects.equals(hostnameList, that.hostnameList) && - Objects.equals(port, that.port); - } - - @Override - public int hashCode() { - return Objects.hash(hostnameList, port); - } - - @Override - public String toString() { - return "ResolveResult{" + - "hostnameList=" + hostnameList + - ", port=" + port + - '}'; - } -} diff --git a/dubbo-registry-extensions/dubbo-registry-dns/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.RegistryFactory b/dubbo-registry-extensions/dubbo-registry-dns/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.RegistryFactory deleted file mode 100644 index 69ca00793..000000000 --- a/dubbo-registry-extensions/dubbo-registry-dns/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.RegistryFactory +++ /dev/null @@ -1 +0,0 @@ -dns=org.apache.dubbo.registry.dns.DNSRegistryFactory \ No newline at end of file diff --git a/dubbo-registry-extensions/dubbo-registry-dns/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.ServiceDiscovery b/dubbo-registry-extensions/dubbo-registry-dns/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.ServiceDiscovery deleted file mode 100644 index 3adb9f4cd..000000000 --- a/dubbo-registry-extensions/dubbo-registry-dns/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.ServiceDiscovery +++ /dev/null @@ -1 +0,0 @@ -dns=org.apache.dubbo.registry.dns.DNSServiceDiscovery \ No newline at end of file diff --git a/dubbo-registry-extensions/dubbo-registry-dns/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.ServiceDiscoveryFactory b/dubbo-registry-extensions/dubbo-registry-dns/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.ServiceDiscoveryFactory deleted file mode 100644 index 900e78c82..000000000 --- a/dubbo-registry-extensions/dubbo-registry-dns/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.ServiceDiscoveryFactory +++ /dev/null @@ -1 +0,0 @@ -dns=org.apache.dubbo.registry.dns.DNSServiceDiscoveryFactory \ No newline at end of file diff --git a/dubbo-registry-extensions/dubbo-registry-dns/src/test/java/org/apache/dubbo/registry/dns/DNSServiceDiscoveryTest.java b/dubbo-registry-extensions/dubbo-registry-dns/src/test/java/org/apache/dubbo/registry/dns/DNSServiceDiscoveryTest.java deleted file mode 100644 index 7b96fbe8e..000000000 --- a/dubbo-registry-extensions/dubbo-registry-dns/src/test/java/org/apache/dubbo/registry/dns/DNSServiceDiscoveryTest.java +++ /dev/null @@ -1,192 +0,0 @@ -/* - * 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 org.apache.dubbo.registry.dns; -// -//import com.alibaba.fastjson.JSONObject; -//import org.apache.dubbo.common.URL; -//import org.apache.dubbo.common.utils.NetUtils; -//import org.apache.dubbo.config.ApplicationConfig; -//import org.apache.dubbo.config.ArgumentConfig; -//import org.apache.dubbo.config.MethodConfig; -//import org.apache.dubbo.config.ProtocolConfig; -//import org.apache.dubbo.config.RegistryConfig; -//import org.apache.dubbo.config.ServiceConfig; -//import org.apache.dubbo.config.bootstrap.DubboBootstrap; -//import org.apache.dubbo.metadata.InstanceMetadataChangedListener; -//import org.apache.dubbo.metadata.MetadataService; -//import org.apache.dubbo.registry.Constants; -//import org.apache.dubbo.registry.client.DefaultServiceInstance; -//import org.apache.dubbo.registry.client.ServiceInstance; -//import org.apache.dubbo.registry.client.event.ServiceInstancesChangedEvent; -//import org.apache.dubbo.registry.client.event.listener.ServiceInstancesChangedListener; -//import org.apache.dubbo.registry.dns.util.DNSClientConst; -//import org.apache.dubbo.registry.dns.util.DNSResolver; -//import org.apache.dubbo.registry.dns.util.ResolveResult; -//import org.apache.dubbo.rpc.model.ApplicationModel; -//import org.apache.dubbo.rpc.model.ScopeModelUtil; -//import org.junit.jupiter.api.AfterEach; -//import org.junit.jupiter.api.BeforeEach; -//import org.junit.jupiter.api.Test; -//import org.mockito.ArgumentCaptor; -//import org.mockito.Mockito; -// -//import java.util.Collections; -//import java.util.HashSet; -//import java.util.List; -//import java.util.Set; -// -//import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_PROTOCOL; -//import static org.apache.dubbo.metadata.MetadataConstants.METADATA_PROXY_TIMEOUT_KEY; -//import static org.junit.jupiter.api.Assertions.assertEquals; -//import static org.junit.jupiter.api.Assertions.assertTrue; -// -//public class DNSServiceDiscoveryTest { -// -// @BeforeEach -// public void setup() { -// DubboBootstrap.reset(); -// ApplicationConfig applicationConfig = new ApplicationConfig("Test"); -// ApplicationModel.defaultModel().getApplicationConfigManager().setApplication(applicationConfig); -// } -// -// @AfterEach -// public void destroy() { -// DubboBootstrap.reset(); -// } -// -// @Test -// public void testProvider() throws Exception { -// ApplicationModel applicationModel = ApplicationModel.defaultModel(); -// applicationModel.getApplicationConfigManager().setApplication(new ApplicationConfig("TestService")); -// URL registryURL = URL.valueOf("dns://"); -// registryURL.setScopeModel(ApplicationModel.defaultModel()); -// DNSServiceDiscovery dnsServiceDiscovery = new DNSServiceDiscovery(applicationModel, registryURL); -// -// assertEquals(registryURL, dnsServiceDiscovery.getUrl()); -// -//// ServiceInstance serviceInstance = new DefaultServiceInstance("TestService", "localhost", 12345, ScopeModelUtil.getApplicationModel(dnsServiceDiscovery.getUrl().getScopeModel())); -//// serviceInstance.getMetadata().put("a", "b"); -// -// dnsServiceDiscovery.register(); -// -// WritableMetadataService metadataService = WritableMetadataService.getDefaultExtension(applicationModel); -// InstanceMetadataChangedListener changeListener = Mockito.mock(InstanceMetadataChangedListener.class); -// -// String metadataString = metadataService -// .getAndListenInstanceMetadata("test", changeListener); -// -// assertEquals(JSONObject.toJSONString(serviceInstance.getMetadata()), metadataString); -// assertEquals(serviceInstance, dnsServiceDiscovery.getLocalInstance()); -// -// dnsServiceDiscovery.unregister(serviceInstance); -// -// Mockito.verify(changeListener, Mockito.times(1)).onEvent(Mockito.any()); -// -// metadataService.getInstanceMetadataChangedListenerMap().clear(); -// metadataService.exportInstanceMetadata(null); -// -// dnsServiceDiscovery.destroy(); -// -// } -// -// @Test -// public void testConsumer() throws Exception { -// ApplicationModel applicationModel = ApplicationModel.defaultModel(); -// applicationModel.getModelEnvironment().getAppExternalConfigMap() -// .put(METADATA_PROXY_TIMEOUT_KEY, String.valueOf(500)); -// URL registryURL = URL.valueOf("dns://") -// .addParameter(DNSClientConst.DNS_POLLING_CYCLE, 100) -// .addParameter(Constants.ECHO_POLLING_CYCLE_KEY, 100); -// registryURL.setScopeModel(ApplicationModel.defaultModel()); -// DNSServiceDiscovery dnsServiceDiscovery = new DNSServiceDiscovery(applicationModel, registryURL); -// -// WritableMetadataService metadataService = WritableMetadataService.getDefaultExtension(applicationModel); -// ServiceInstance serviceInstance = new DefaultServiceInstance("TestService", "localhost", 12345, ScopeModelUtil.getApplicationModel(dnsServiceDiscovery.getUrl().getScopeModel())); -// serviceInstance.getMetadata().put("a", "b"); -// -// dnsServiceDiscovery.register(serviceInstance); -// -// int port = NetUtils.getAvailablePort(); -// applicationModel.getCurrentConfig().setMetadataServicePort(port); -// -// WritableMetadataService spiedMetadataService = Mockito.spy(metadataService); -// -// ServiceConfig serviceConfig = exportMockMetadataService(spiedMetadataService, port); -// -// DNSResolver dnsResolver = Mockito.mock(DNSResolver.class); -// ResolveResult resolveResult = new ResolveResult(); -// resolveResult.getHostnameList().add("127.0.0.1"); -// Mockito.when(dnsResolver.resolve("Test.Service.")).thenReturn(resolveResult); -// dnsServiceDiscovery.setDnsResolver(dnsResolver); -// -// List serviceInstances = dnsServiceDiscovery.getInstances("Test.Service."); -// assertEquals("b", serviceInstances.get(0).getMetadata("a")); -// -// Set serviceNames = new HashSet<>(); -// serviceNames.add("Test.Service."); -// ServiceInstancesChangedListener changedListener = Mockito.spy(new ServiceInstancesChangedListener(serviceNames, null)); -// Mockito.doNothing().when(changedListener).onEvent(Mockito.any()); -// -// serviceInstance.getMetadata().put("a", "c"); -// dnsServiceDiscovery.update(serviceInstance); -// -// serviceInstances = dnsServiceDiscovery.getInstances("Test.Service."); -// assertEquals("c", serviceInstances.get(0).getMetadata("a")); -// -// ArgumentCaptor argument = ArgumentCaptor.forClass(ServiceInstancesChangedEvent.class); -// dnsServiceDiscovery.addServiceInstancesChangedListener(changedListener); -// Thread.sleep(1000); -// Mockito.verify(changedListener, Mockito.timeout(1000)).onEvent(argument.capture()); -// assertEquals("c", argument.getValue().getServiceInstances().get(0).getMetadata("a")); -// -// Mockito.when(dnsResolver.resolve("Test.Service.")).thenReturn(new ResolveResult()); -// -// Thread.sleep(1000); -// assertTrue(dnsServiceDiscovery.getCachedServiceInstances().get("Test.Service.").isEmpty()); -// -// metadataService.exportInstanceMetadata(null); -// metadataService.getInstanceMetadataChangedListenerMap().clear(); -// serviceConfig.unexport(); -// -// dnsServiceDiscovery.destroy(); -// applicationModel.getModelEnvironment().getAppExternalConfigMap() -// .remove(METADATA_PROXY_TIMEOUT_KEY); -// } -// -// private ServiceConfig exportMockMetadataService(MetadataService metadataService, int port) { -// ServiceConfig serviceConfig = new ServiceConfig<>(); -// serviceConfig.setProtocol(new ProtocolConfig(DUBBO_PROTOCOL, port)); -// serviceConfig.setRegistry(new RegistryConfig("239.255.255.255", "multicast")); -// serviceConfig.setInterface(MetadataService.class); -// serviceConfig.setRef(metadataService); -// serviceConfig.setGroup("Test.Service."); -// serviceConfig.setVersion(MetadataService.VERSION); -// MethodConfig methodConfig = new MethodConfig(); -// methodConfig.setName("getAndListenInstanceMetadata"); -// -// ArgumentConfig argumentConfig = new ArgumentConfig(); -// argumentConfig.setIndex(1); -// argumentConfig.setCallback(true); -// -// methodConfig.setArguments(Collections.singletonList(argumentConfig)); -// serviceConfig.setMethods(Collections.singletonList(methodConfig)); -// -// serviceConfig.export(); -// -// return serviceConfig; -// } -//} diff --git a/dubbo-registry-extensions/dubbo-registry-dns/src/test/java/org/apache/dubbo/registry/dns/util/DNSResolverTest.java b/dubbo-registry-extensions/dubbo-registry-dns/src/test/java/org/apache/dubbo/registry/dns/util/DNSResolverTest.java deleted file mode 100644 index 17088ac5f..000000000 --- a/dubbo-registry-extensions/dubbo-registry-dns/src/test/java/org/apache/dubbo/registry/dns/util/DNSResolverTest.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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 org.apache.dubbo.registry.dns.util; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -public class DNSResolverTest { - - @Test - public void testResolve() { - DNSResolver dnsResolver = new DNSResolver("8.8.8.8", 53, 1); - ResolveResult resolve = dnsResolver.resolve("aliyun.com"); - Assertions.assertTrue(resolve.getHostnameList().size() > 0); - } -} diff --git a/dubbo-registry-extensions/dubbo-registry-dns/src/test/resources/dubbo.properties b/dubbo-registry-extensions/dubbo-registry-dns/src/test/resources/dubbo.properties deleted file mode 100644 index 1aade88a5..000000000 --- a/dubbo-registry-extensions/dubbo-registry-dns/src/test/resources/dubbo.properties +++ /dev/null @@ -1,2 +0,0 @@ -dubbo.application.enable-file-cache=false -dubbo.service.shutdown.wait=200 diff --git a/dubbo-registry-extensions/dubbo-registry-etcd3/pom.xml b/dubbo-registry-extensions/dubbo-registry-etcd3/pom.xml index c2de8847c..3e94cf150 100644 --- a/dubbo-registry-extensions/dubbo-registry-etcd3/pom.xml +++ b/dubbo-registry-extensions/dubbo-registry-etcd3/pom.xml @@ -25,7 +25,7 @@ 4.0.0 - 1.0.2-SNAPSHOT + ${revision} dubbo-registry-etcd3 jar ${project.artifactId} @@ -45,7 +45,7 @@ org.apache.dubbo.extensions dubbo-remoting-etcd3 - 1.0.2-SNAPSHOT + ${revision}
diff --git a/dubbo-registry-extensions/dubbo-registry-nameservice/pom.xml b/dubbo-registry-extensions/dubbo-registry-nameservice/pom.xml index deeaa905a..bae0e9801 100644 --- a/dubbo-registry-extensions/dubbo-registry-nameservice/pom.xml +++ b/dubbo-registry-extensions/dubbo-registry-nameservice/pom.xml @@ -25,7 +25,7 @@ ${revision} ../pom.xml - 1.0.1-SNAPSHOT + ${revision} 4.0.0 dubbo-registry-nameservice dubbo-registry-nameservice diff --git a/dubbo-registry-extensions/dubbo-registry-polaris/pom.xml b/dubbo-registry-extensions/dubbo-registry-polaris/pom.xml index ab37000fe..134730ade 100644 --- a/dubbo-registry-extensions/dubbo-registry-polaris/pom.xml +++ b/dubbo-registry-extensions/dubbo-registry-polaris/pom.xml @@ -25,7 +25,7 @@ dubbo-registry-polaris dubbo-registry-polaris - 1.0.0-SNAPSHOT + ${revision} Dubbo registry extension for PolarisMesh, support instance register, discover, health-check capabilities. diff --git a/dubbo-registry-extensions/dubbo-registry-redis/pom.xml b/dubbo-registry-extensions/dubbo-registry-redis/pom.xml index 01c091b12..acf1201a8 100644 --- a/dubbo-registry-extensions/dubbo-registry-redis/pom.xml +++ b/dubbo-registry-extensions/dubbo-registry-redis/pom.xml @@ -23,7 +23,7 @@ 4.0.0 - 1.0.2-SNAPSHOT + ${revision} dubbo-registry-redis jar ${project.artifactId} @@ -40,7 +40,7 @@ org.apache.dubbo.extensions dubbo-remoting-redis - 1.0.2-SNAPSHOT + ${revision} redis.clients diff --git a/dubbo-registry-extensions/dubbo-registry-sofa/pom.xml b/dubbo-registry-extensions/dubbo-registry-sofa/pom.xml index 5d9486b3e..47cd4c99d 100644 --- a/dubbo-registry-extensions/dubbo-registry-sofa/pom.xml +++ b/dubbo-registry-extensions/dubbo-registry-sofa/pom.xml @@ -24,7 +24,7 @@ 4.0.0 - 1.0.2-SNAPSHOT + ${revision} dubbo-registry-sofa ${project.artifactId} The SOFARegistry module of Dubbo project diff --git a/dubbo-registry-extensions/pom.xml b/dubbo-registry-extensions/pom.xml index 64eb9c448..be43b8520 100644 --- a/dubbo-registry-extensions/pom.xml +++ b/dubbo-registry-extensions/pom.xml @@ -28,7 +28,6 @@ ${revision} pom - dubbo-registry-dns dubbo-registry-consul dubbo-registry-etcd3 dubbo-registry-redis diff --git a/dubbo-remoting-extensions/dubbo-remoting-etcd3/pom.xml b/dubbo-remoting-extensions/dubbo-remoting-etcd3/pom.xml index bca7da7b8..9e7f187c7 100644 --- a/dubbo-remoting-extensions/dubbo-remoting-etcd3/pom.xml +++ b/dubbo-remoting-extensions/dubbo-remoting-etcd3/pom.xml @@ -27,7 +27,7 @@ 4.0.0 - 1.0.2-SNAPSHOT + ${revision} dubbo-remoting-etcd3 jar ${project.artifactId} diff --git a/dubbo-remoting-extensions/dubbo-remoting-grizzly/pom.xml b/dubbo-remoting-extensions/dubbo-remoting-grizzly/pom.xml index 4d0dc517f..8ded7761d 100644 --- a/dubbo-remoting-extensions/dubbo-remoting-grizzly/pom.xml +++ b/dubbo-remoting-extensions/dubbo-remoting-grizzly/pom.xml @@ -23,7 +23,7 @@ 4.0.0 - 1.0.2-SNAPSHOT + ${revision} dubbo-remoting-grizzly jar ${project.artifactId} diff --git a/dubbo-remoting-extensions/dubbo-remoting-mina/pom.xml b/dubbo-remoting-extensions/dubbo-remoting-mina/pom.xml index de20a9421..76a5c289e 100644 --- a/dubbo-remoting-extensions/dubbo-remoting-mina/pom.xml +++ b/dubbo-remoting-extensions/dubbo-remoting-mina/pom.xml @@ -23,7 +23,7 @@ 4.0.0 - 1.0.2-SNAPSHOT + ${revision} dubbo-remoting-mina jar ${project.artifactId} diff --git a/dubbo-remoting-extensions/dubbo-remoting-mina/src/test/java/org/apache/remoting/transport/mina/ClientToServerTest.java b/dubbo-remoting-extensions/dubbo-remoting-mina/src/test/java/org/apache/remoting/transport/mina/ClientToServerTest.java index d6fd95768..3c69bbfa9 100644 --- a/dubbo-remoting-extensions/dubbo-remoting-mina/src/test/java/org/apache/remoting/transport/mina/ClientToServerTest.java +++ b/dubbo-remoting-extensions/dubbo-remoting-mina/src/test/java/org/apache/remoting/transport/mina/ClientToServerTest.java @@ -25,6 +25,7 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import java.util.concurrent.CompletableFuture; @@ -32,6 +33,7 @@ /** * ClientToServer */ +@Disabled public abstract class ClientToServerTest { protected static final String LOCALHOST = "127.0.0.1"; diff --git a/dubbo-remoting-extensions/dubbo-remoting-mina/src/test/java/org/apache/remoting/transport/mina/MinaClientToServerTest.java b/dubbo-remoting-extensions/dubbo-remoting-mina/src/test/java/org/apache/remoting/transport/mina/MinaClientToServerTest.java index d1c052556..92a928809 100644 --- a/dubbo-remoting-extensions/dubbo-remoting-mina/src/test/java/org/apache/remoting/transport/mina/MinaClientToServerTest.java +++ b/dubbo-remoting-extensions/dubbo-remoting-mina/src/test/java/org/apache/remoting/transport/mina/MinaClientToServerTest.java @@ -22,10 +22,12 @@ import org.apache.dubbo.remoting.exchange.ExchangeServer; import org.apache.dubbo.remoting.exchange.Exchangers; import org.apache.dubbo.remoting.exchange.support.Replier; +import org.junit.jupiter.api.Disabled; /** * MinaServerClientTest */ +@Disabled public class MinaClientToServerTest extends ClientToServerTest { @Override diff --git a/dubbo-remoting-extensions/dubbo-remoting-mina/src/test/resources/security/serialize.allowlist b/dubbo-remoting-extensions/dubbo-remoting-mina/src/test/resources/security/serialize.allowlist new file mode 100644 index 000000000..cca5734ad --- /dev/null +++ b/dubbo-remoting-extensions/dubbo-remoting-mina/src/test/resources/security/serialize.allowlist @@ -0,0 +1,21 @@ +# +# +# 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. +# +# + +org.apache.remoting.transport.mina.World +org.apache.remoting.transport.mina.Hello diff --git a/dubbo-remoting-extensions/dubbo-remoting-p2p/pom.xml b/dubbo-remoting-extensions/dubbo-remoting-p2p/pom.xml index 8961e35fc..75e82c5ba 100644 --- a/dubbo-remoting-extensions/dubbo-remoting-p2p/pom.xml +++ b/dubbo-remoting-extensions/dubbo-remoting-p2p/pom.xml @@ -23,7 +23,7 @@ 4.0.0 - 1.0.2-SNAPSHOT + ${revision} dubbo-remoting-p2p jar ${project.artifactId} diff --git a/dubbo-remoting-extensions/dubbo-remoting-quic/pom.xml b/dubbo-remoting-extensions/dubbo-remoting-quic/pom.xml index 627e3d194..fc717e004 100644 --- a/dubbo-remoting-extensions/dubbo-remoting-quic/pom.xml +++ b/dubbo-remoting-extensions/dubbo-remoting-quic/pom.xml @@ -29,7 +29,7 @@ 4.0.0 dubbo-remoting-quic - 1.0.2-SNAPSHOT + ${revision} diff --git a/dubbo-remoting-extensions/dubbo-remoting-redis/pom.xml b/dubbo-remoting-extensions/dubbo-remoting-redis/pom.xml index f8c982b3b..26f76bff6 100644 --- a/dubbo-remoting-extensions/dubbo-remoting-redis/pom.xml +++ b/dubbo-remoting-extensions/dubbo-remoting-redis/pom.xml @@ -23,7 +23,7 @@ 4.0.0 - 1.0.2-SNAPSHOT + ${revision} dubbo-remoting-redis jar diff --git a/dubbo-remoting-extensions/dubbo-remoting-redis/src/main/java/org/apache/dubbo/remoting/redis/jedis/ClusterRedisClient.java b/dubbo-remoting-extensions/dubbo-remoting-redis/src/main/java/org/apache/dubbo/remoting/redis/jedis/ClusterRedisClient.java index e0e4c14a1..87c48ee2d 100644 --- a/dubbo-remoting-extensions/dubbo-remoting-redis/src/main/java/org/apache/dubbo/remoting/redis/jedis/ClusterRedisClient.java +++ b/dubbo-remoting-extensions/dubbo-remoting-redis/src/main/java/org/apache/dubbo/remoting/redis/jedis/ClusterRedisClient.java @@ -45,12 +45,15 @@ public class ClusterRedisClient extends AbstractRedisClient implements RedisClie private static final int DEFAULT_MAX_ATTEMPTS = 5; - private JedisCluster jedisCluster; + private final JedisCluster jedisCluster; private Pattern COLON_SPLIT_PATTERN = Pattern.compile("\\s*[:]+\\s*"); public ClusterRedisClient(URL url) { super(url); Set nodes = getNodes(url); + if (url.hasParameter("db.index")) { + logger.warn("Redis Cluster does not support multiple databases, the SELECT command is not allowed. So the setting of db.index will not be effect"); + } jedisCluster = new JedisCluster(nodes, url.getParameter("connection.timeout", DEFAULT_TIMEOUT), url.getParameter("so.timeout", DEFAULT_SO_TIMEOUT), url.getParameter("max.attempts", DEFAULT_MAX_ATTEMPTS), url.getPassword(), getConfig()); @@ -72,7 +75,10 @@ public boolean isConnected() { for (JedisPool jedisPool : poolMap.values()) { Jedis jedis = jedisPool.getResource(); if (jedis.isConnected()) { + jedisPool.returnResource(jedis); return true; + } else { + jedisPool.returnResource(jedis); } } return false; @@ -95,7 +101,7 @@ public Set scan(String pattern) { for (JedisPool jedisPool : nodes.values()) { Jedis jedis = jedisPool.getResource(); result.addAll(scan(jedis, pattern)); - jedis.close(); + jedisPool.returnResource(jedis); } return result; } diff --git a/dubbo-remoting-extensions/dubbo-remoting-redis/src/main/java/org/apache/dubbo/remoting/redis/jedis/MonoRedisClient.java b/dubbo-remoting-extensions/dubbo-remoting-redis/src/main/java/org/apache/dubbo/remoting/redis/jedis/MonoRedisClient.java index 864f18e33..64e4ebb9a 100644 --- a/dubbo-remoting-extensions/dubbo-remoting-redis/src/main/java/org/apache/dubbo/remoting/redis/jedis/MonoRedisClient.java +++ b/dubbo-remoting-extensions/dubbo-remoting-redis/src/main/java/org/apache/dubbo/remoting/redis/jedis/MonoRedisClient.java @@ -35,14 +35,12 @@ public class MonoRedisClient extends AbstractRedisClient implements RedisClient { private static final Logger logger = LoggerFactory.getLogger(MonoRedisClient.class); - private static final String START_CURSOR = "0"; - - private JedisPool jedisPool; + private final JedisPool jedisPool; public MonoRedisClient(URL url) { super(url); jedisPool = new JedisPool(getConfig(), url.getHost(), url.getPort(), - url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT), url.getPassword()); + url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT), url.getPassword(), url.getParameter("db.index", 0)); } @Override @@ -57,7 +55,7 @@ public Long hset(String key, String field, String value) { public Long publish(String channel, String message) { Jedis jedis = jedisPool.getResource(); Long result = jedis.publish(channel, message); - jedis.close(); + jedisPool.returnResource(jedis); return result; } @@ -65,7 +63,7 @@ public Long publish(String channel, String message) { public boolean isConnected() { Jedis jedis = jedisPool.getResource(); boolean connected = jedis.isConnected(); - jedis.close(); + jedisPool.returnResource(jedis); return connected; } @@ -78,7 +76,7 @@ public void destroy() { public Long hdel(String key, String... fields) { Jedis jedis = jedisPool.getResource(); Long result = jedis.hdel(key, fields); - jedis.close(); + jedisPool.returnResource(jedis); return result; } @@ -86,7 +84,7 @@ public Long hdel(String key, String... fields) { public Set scan(String pattern) { Jedis jedis = jedisPool.getResource(); Set result = super.scan(jedis, pattern); - jedis.close(); + jedisPool.returnResource(jedis); return result; } @@ -94,7 +92,7 @@ public Set scan(String pattern) { public Map hgetAll(String key) { Jedis jedis = jedisPool.getResource(); Map result = jedis.hgetAll(key); - jedis.close(); + jedisPool.returnResource(jedis); return result; } diff --git a/dubbo-remoting-extensions/dubbo-remoting-redis/src/main/java/org/apache/dubbo/remoting/redis/jedis/SentinelRedisClient.java b/dubbo-remoting-extensions/dubbo-remoting-redis/src/main/java/org/apache/dubbo/remoting/redis/jedis/SentinelRedisClient.java index 6a10bf987..3fb4afabd 100644 --- a/dubbo-remoting-extensions/dubbo-remoting-redis/src/main/java/org/apache/dubbo/remoting/redis/jedis/SentinelRedisClient.java +++ b/dubbo-remoting-extensions/dubbo-remoting-redis/src/main/java/org/apache/dubbo/remoting/redis/jedis/SentinelRedisClient.java @@ -32,10 +32,13 @@ import java.util.Map; import java.util.Set; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT; +import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; + public class SentinelRedisClient extends AbstractRedisClient implements RedisClient { private static final Logger logger = LoggerFactory.getLogger(SentinelRedisClient.class); - private JedisSentinelPool sentinelPool; + private final JedisSentinelPool sentinelPool; public SentinelRedisClient(URL url) { super(url); @@ -47,14 +50,15 @@ public SentinelRedisClient(URL url) { } Set sentinels = new HashSet<>(Arrays.asList(backupAddresses)); sentinels.add(address); - sentinelPool = new JedisSentinelPool(masterName, sentinels, getConfig(), url.getPassword()); + sentinelPool = new JedisSentinelPool(masterName, sentinels, getConfig(), url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT), url.getPassword(), + url.getParameter("db.index", 0)); } @Override public Long hset(String key, String field, String value) { Jedis jedis = sentinelPool.getResource(); Long result = jedis.hset(key, field, value); - jedis.close(); + sentinelPool.returnResource(jedis); return result; } @@ -62,7 +66,7 @@ public Long hset(String key, String field, String value) { public Long publish(String channel, String message) { Jedis jedis = sentinelPool.getResource(); Long result = jedis.publish(channel, message); - jedis.close(); + sentinelPool.returnResource(jedis); return result; } @@ -70,7 +74,7 @@ public Long publish(String channel, String message) { public boolean isConnected() { Jedis jedis = sentinelPool.getResource(); boolean result = jedis.isConnected(); - jedis.close(); + sentinelPool.returnResource(jedis); return result; } @@ -83,7 +87,7 @@ public void destroy() { public Long hdel(String key, String... fields) { Jedis jedis = sentinelPool.getResource(); Long result = jedis.hdel(key, fields); - jedis.close(); + sentinelPool.returnResource(jedis); return result; } @@ -91,7 +95,7 @@ public Long hdel(String key, String... fields) { public Set scan(String pattern) { Jedis jedis = sentinelPool.getResource(); Set result = scan(jedis, pattern); - jedis.close(); + sentinelPool.returnResource(jedis); return result; } @@ -99,7 +103,7 @@ public Set scan(String pattern) { public Map hgetAll(String key) { Jedis jedis = sentinelPool.getResource(); Map result = jedis.hgetAll(key); - jedis.close(); + sentinelPool.returnResource(jedis); return result; } @@ -107,7 +111,7 @@ public Map hgetAll(String key) { public void psubscribe(JedisPubSub jedisPubSub, String... patterns) { Jedis jedis = sentinelPool.getResource(); jedis.psubscribe(jedisPubSub, patterns); - jedis.close(); + sentinelPool.returnResource(jedis); } @Override diff --git a/dubbo-rpc-extensions/dubbo-rpc-hessian/pom.xml b/dubbo-rpc-extensions/dubbo-rpc-hessian/pom.xml index b37c0d290..5e78ad2c0 100644 --- a/dubbo-rpc-extensions/dubbo-rpc-hessian/pom.xml +++ b/dubbo-rpc-extensions/dubbo-rpc-hessian/pom.xml @@ -24,7 +24,7 @@ 4.0.0 dubbo-rpc-hessian - 1.0.2-SNAPSHOT + ${revision} jar ${project.artifactId} @@ -64,7 +64,7 @@ org.apache.dubbo.extensions dubbo-serialization-native-hession - 1.0.2-SNAPSHOT + ${revision} org.springframework diff --git a/dubbo-rpc-extensions/dubbo-rpc-http/pom.xml b/dubbo-rpc-extensions/dubbo-rpc-http/pom.xml index 2aa4ca317..35a6ef96e 100644 --- a/dubbo-rpc-extensions/dubbo-rpc-http/pom.xml +++ b/dubbo-rpc-extensions/dubbo-rpc-http/pom.xml @@ -26,7 +26,7 @@ 4.0.0 dubbo-rpc-http - 1.0.2-SNAPSHOT + ${revision} The JSON-RPC module of dubbo project diff --git a/dubbo-rpc-extensions/dubbo-rpc-memcached/pom.xml b/dubbo-rpc-extensions/dubbo-rpc-memcached/pom.xml index 0af66f7dc..2369ea9a2 100644 --- a/dubbo-rpc-extensions/dubbo-rpc-memcached/pom.xml +++ b/dubbo-rpc-extensions/dubbo-rpc-memcached/pom.xml @@ -24,7 +24,7 @@ 4.0.0 dubbo-rpc-memcached - 1.0.2-SNAPSHOT + ${revision} jar ${project.artifactId} The memcached rpc module of dubbo project diff --git a/dubbo-rpc-extensions/dubbo-rpc-native-thrift/pom.xml b/dubbo-rpc-extensions/dubbo-rpc-native-thrift/pom.xml index 42b39f191..1f6b0cf3a 100644 --- a/dubbo-rpc-extensions/dubbo-rpc-native-thrift/pom.xml +++ b/dubbo-rpc-extensions/dubbo-rpc-native-thrift/pom.xml @@ -27,7 +27,7 @@ jar ${project.artifactId} The thrift rpc module of dubbo project - 1.0.2-SNAPSHOT + ${revision} false diff --git a/dubbo-rpc-extensions/dubbo-rpc-redis/pom.xml b/dubbo-rpc-extensions/dubbo-rpc-redis/pom.xml index b0bff3714..259a8add9 100644 --- a/dubbo-rpc-extensions/dubbo-rpc-redis/pom.xml +++ b/dubbo-rpc-extensions/dubbo-rpc-redis/pom.xml @@ -24,7 +24,7 @@ 4.0.0 dubbo-rpc-redis - 1.0.2-SNAPSHOT + ${revision} jar ${project.artifactId} The redis rpc module of dubbo project diff --git a/dubbo-rpc-extensions/dubbo-rpc-rmi/pom.xml b/dubbo-rpc-extensions/dubbo-rpc-rmi/pom.xml index c9facd79c..56ba6b4f8 100644 --- a/dubbo-rpc-extensions/dubbo-rpc-rmi/pom.xml +++ b/dubbo-rpc-extensions/dubbo-rpc-rmi/pom.xml @@ -25,7 +25,7 @@ dubbo-rpc-rmi jar - 1.0.2-SNAPSHOT + ${revision} The rmi rpc module of dubbo project false diff --git a/dubbo-rpc-extensions/dubbo-rpc-rocketmq/pom.xml b/dubbo-rpc-extensions/dubbo-rpc-rocketmq/pom.xml index b84c414f8..17115e2ce 100644 --- a/dubbo-rpc-extensions/dubbo-rpc-rocketmq/pom.xml +++ b/dubbo-rpc-extensions/dubbo-rpc-rocketmq/pom.xml @@ -25,7 +25,7 @@ ${revision} ../pom.xml - 1.0.1-SNAPSHOT + ${revision} dubbo-rpc-rocketmq dubbo-rpc-rocketmq diff --git a/dubbo-rpc-extensions/dubbo-rpc-rocketmq/src/main/java/org/apache/dubbo/rpc/rocketmq/codec/RocketMQCodec.java b/dubbo-rpc-extensions/dubbo-rpc-rocketmq/src/main/java/org/apache/dubbo/rpc/rocketmq/codec/RocketMQCodec.java index edfb32dd3..ce7a54c36 100644 --- a/dubbo-rpc-extensions/dubbo-rpc-rocketmq/src/main/java/org/apache/dubbo/rpc/rocketmq/codec/RocketMQCodec.java +++ b/dubbo-rpc-extensions/dubbo-rpc-rocketmq/src/main/java/org/apache/dubbo/rpc/rocketmq/codec/RocketMQCodec.java @@ -95,7 +95,7 @@ protected Object decodeBody(Channel channel, InputStream is, byte[] header) thro data = decodeEventData(channel, in, eventPayload); } } else { - DecodeableRpcResult result = new DecodeableRpcResult(channel, res, is, (Invocation) getRequestData(id), proto); + DecodeableRpcResult result = new DecodeableRpcResult(channel, res, is, (Invocation) getRequestData(channel, res, id), proto); result.decode(); data = result; } diff --git a/dubbo-rpc-extensions/dubbo-rpc-webservice/pom.xml b/dubbo-rpc-extensions/dubbo-rpc-webservice/pom.xml index 8539b04a8..d7b555bdf 100644 --- a/dubbo-rpc-extensions/dubbo-rpc-webservice/pom.xml +++ b/dubbo-rpc-extensions/dubbo-rpc-webservice/pom.xml @@ -26,7 +26,7 @@ dubbo-rpc-webservice jar ${project.artifactId} - 1.0.2-SNAPSHOT + ${revision} The webservice rpc module of dubbo project false diff --git a/dubbo-serialization-extensions/dubbo-serialization-avro/pom.xml b/dubbo-serialization-extensions/dubbo-serialization-avro/pom.xml index ac11acbe0..6e32bbe9c 100644 --- a/dubbo-serialization-extensions/dubbo-serialization-avro/pom.xml +++ b/dubbo-serialization-extensions/dubbo-serialization-avro/pom.xml @@ -26,7 +26,7 @@ dubbo-serialization-avro jar ${project.artifactId} - 1.0.2-SNAPSHOT + ${revision} The avro serialization module of dubbo project false diff --git a/dubbo-serialization-extensions/dubbo-serialization-fastjson/pom.xml b/dubbo-serialization-extensions/dubbo-serialization-fastjson/pom.xml index cf2586ac0..e5915b602 100644 --- a/dubbo-serialization-extensions/dubbo-serialization-fastjson/pom.xml +++ b/dubbo-serialization-extensions/dubbo-serialization-fastjson/pom.xml @@ -27,7 +27,7 @@ limitations under the License. dubbo-serialization-fastjson jar ${project.artifactId} - 1.0.2-SNAPSHOT + ${revision} The fastjson serialization module of dubbo project false diff --git a/dubbo-serialization-extensions/dubbo-serialization-fst/pom.xml b/dubbo-serialization-extensions/dubbo-serialization-fst/pom.xml index f8a60ac5c..cd9ecd392 100644 --- a/dubbo-serialization-extensions/dubbo-serialization-fst/pom.xml +++ b/dubbo-serialization-extensions/dubbo-serialization-fst/pom.xml @@ -26,7 +26,7 @@ dubbo-serialization-fst jar ${project.artifactId} - 1.0.2-SNAPSHOT + ${revision} The fst serialization module of dubbo project false diff --git a/dubbo-serialization-extensions/dubbo-serialization-fury/pom.xml b/dubbo-serialization-extensions/dubbo-serialization-fury/pom.xml index fb7b98d61..cd851ed8d 100644 --- a/dubbo-serialization-extensions/dubbo-serialization-fury/pom.xml +++ b/dubbo-serialization-extensions/dubbo-serialization-fury/pom.xml @@ -32,20 +32,17 @@ limitations under the License. 17 17 UTF-8 - 3.2.1 org.apache.dubbo dubbo-serialization-api - ${dubbo.version} true org.apache.dubbo dubbo - ${dubbo.version} true diff --git a/dubbo-serialization-extensions/dubbo-serialization-fury/src/main/java/org/apache/dubbo/common/serialize/fury/dubbo/FuryCheckerListener.java b/dubbo-serialization-extensions/dubbo-serialization-fury/src/main/java/org/apache/dubbo/common/serialize/fury/dubbo/FuryCheckerListener.java index 18100e204..072851791 100644 --- a/dubbo-serialization-extensions/dubbo-serialization-fury/src/main/java/org/apache/dubbo/common/serialize/fury/dubbo/FuryCheckerListener.java +++ b/dubbo-serialization-extensions/dubbo-serialization-fury/src/main/java/org/apache/dubbo/common/serialize/fury/dubbo/FuryCheckerListener.java @@ -23,65 +23,25 @@ import io.fury.serializer.Serializer; import io.fury.serializer.SerializerFactory; import java.io.Serializable; -import java.util.Set; -import org.apache.dubbo.common.utils.AllowClassNotifyListener; -import org.apache.dubbo.common.utils.SerializeCheckStatus; -import org.apache.dubbo.common.utils.SerializeSecurityManager; import org.apache.dubbo.rpc.model.FrameworkModel; @SuppressWarnings("rawtypes") -public class FuryCheckerListener implements AllowClassNotifyListener, SerializerFactory { - private final SerializeSecurityManager securityManager; +public class FuryCheckerListener implements SerializerFactory { + private final AllowListChecker checker; - private volatile boolean checkSerializable; + private final boolean checkSerializable; public FuryCheckerListener(FrameworkModel frameworkModel) { checker = new AllowListChecker(); - securityManager = - frameworkModel.getBeanFactory().getOrRegisterBean(SerializeSecurityManager.class); - securityManager.registerListener(this); - } - - @Override - public void notifyPrefix(Set allowedList, Set disAllowedList) { - for (String prefix : allowedList) { - checker.allowClass(prefix); - } - for (String prefix : disAllowedList) { - checker.disallowClass(prefix); - } - } - - @Override - public void notifyCheckStatus(SerializeCheckStatus status) { - switch (status) { - case DISABLE: - checker.setCheckLevel(AllowListChecker.CheckLevel.DISABLE); - return; - case WARN: - checker.setCheckLevel(AllowListChecker.CheckLevel.WARN); - return; - case STRICT: - checker.setCheckLevel(AllowListChecker.CheckLevel.STRICT); - return; - default: - throw new UnsupportedOperationException("Unsupported check level " + status); - } - } - - @Override - public void notifyCheckSerializable(boolean checkSerializable) { - this.checkSerializable = checkSerializable; + // serializable check from dubbo 3.1 + checker.setCheckLevel(AllowListChecker.CheckLevel.DISABLE); + checkSerializable = false; } public AllowListChecker getChecker() { return checker; } - public boolean isCheckSerializable() { - return checkSerializable; - } - @Override public Serializer createSerializer(Fury fury, Class cls) { if (checkSerializable && !Serializable.class.isAssignableFrom(cls)) { diff --git a/dubbo-serialization-extensions/dubbo-serialization-gson/pom.xml b/dubbo-serialization-extensions/dubbo-serialization-gson/pom.xml index fcc82ea8c..509942128 100644 --- a/dubbo-serialization-extensions/dubbo-serialization-gson/pom.xml +++ b/dubbo-serialization-extensions/dubbo-serialization-gson/pom.xml @@ -26,7 +26,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more dubbo-serialization-gson jar ${project.artifactId} - 1.0.2-SNAPSHOT + ${revision} The GSON serialization implement for dubbo false diff --git a/dubbo-serialization-extensions/dubbo-serialization-gson/src/main/java/org/apache/dubbo/common/serialize/gson/GsonJsonObjectOutput.java b/dubbo-serialization-extensions/dubbo-serialization-gson/src/main/java/org/apache/dubbo/common/serialize/gson/GsonJsonObjectOutput.java index 763dd13fd..52f51e613 100644 --- a/dubbo-serialization-extensions/dubbo-serialization-gson/src/main/java/org/apache/dubbo/common/serialize/gson/GsonJsonObjectOutput.java +++ b/dubbo-serialization-extensions/dubbo-serialization-gson/src/main/java/org/apache/dubbo/common/serialize/gson/GsonJsonObjectOutput.java @@ -31,7 +31,7 @@ public class GsonJsonObjectOutput implements ObjectOutput { private final PrintWriter writer; - private Gson gson = null; + private Gson gson; public GsonJsonObjectOutput(OutputStream out) { this(new OutputStreamWriter(out)); diff --git a/dubbo-serialization-extensions/dubbo-serialization-kryo/pom.xml b/dubbo-serialization-extensions/dubbo-serialization-kryo/pom.xml index fb887df92..e42df00b2 100644 --- a/dubbo-serialization-extensions/dubbo-serialization-kryo/pom.xml +++ b/dubbo-serialization-extensions/dubbo-serialization-kryo/pom.xml @@ -27,7 +27,7 @@ limitations under the License. dubbo-serialization-kryo jar ${project.artifactId} - 1.0.2-SNAPSHOT + ${revision} The kryo serialization module of dubbo project false diff --git a/dubbo-serialization-extensions/dubbo-serialization-msgpack/pom.xml b/dubbo-serialization-extensions/dubbo-serialization-msgpack/pom.xml index 960ba07d0..74817d0d0 100644 --- a/dubbo-serialization-extensions/dubbo-serialization-msgpack/pom.xml +++ b/dubbo-serialization-extensions/dubbo-serialization-msgpack/pom.xml @@ -25,7 +25,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more ../pom.xml dubbo-serialization-msgpack - 1.0.2-SNAPSHOT + ${revision} jar ${project.artifactId} The Msgpack serialization implement for dubbo diff --git a/dubbo-serialization-extensions/dubbo-serialization-native-hession/pom.xml b/dubbo-serialization-extensions/dubbo-serialization-native-hession/pom.xml index 0a1157e6a..a13e3ed2c 100644 --- a/dubbo-serialization-extensions/dubbo-serialization-native-hession/pom.xml +++ b/dubbo-serialization-extensions/dubbo-serialization-native-hession/pom.xml @@ -25,7 +25,7 @@ limitations under the License. dubbo-serialization-native-hession - 1.0.2-SNAPSHOT + ${revision} jar ${project.artifactId} The native-hession serialization module of dubbo project diff --git a/dubbo-serialization-extensions/dubbo-serialization-protobuf/pom.xml b/dubbo-serialization-extensions/dubbo-serialization-protobuf/pom.xml index f9a65d481..8a4001952 100644 --- a/dubbo-serialization-extensions/dubbo-serialization-protobuf/pom.xml +++ b/dubbo-serialization-extensions/dubbo-serialization-protobuf/pom.xml @@ -26,11 +26,10 @@ limitations under the License. dubbo-serialization-protobuf jar ${project.artifactId} - 1.0.2-SNAPSHOT + ${revision} The protobuf serialization module of dubbo project false - 0.0.1-SNAPSHOT @@ -38,15 +37,18 @@ limitations under the License. dubbo-serialization-api true + + org.apache.dubbo + dubbo + true + com.google.protobuf protobuf-java - 3.16.3 com.google.protobuf protobuf-java-util - 3.11.0 diff --git a/dubbo-serialization-extensions/dubbo-serialization-protobuf/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufJsonObjectOutput.java b/dubbo-serialization-extensions/dubbo-serialization-protobuf/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufJsonObjectOutput.java index 4940e28c1..dea089a6b 100644 --- a/dubbo-serialization-extensions/dubbo-serialization-protobuf/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufJsonObjectOutput.java +++ b/dubbo-serialization-extensions/dubbo-serialization-protobuf/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufJsonObjectOutput.java @@ -27,12 +27,14 @@ import com.google.protobuf.Int32Value; import com.google.protobuf.Int64Value; import com.google.protobuf.StringValue; +import org.apache.dubbo.common.serialize.protobuf.support.wrapper.ThrowablePB; import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.Map; +import java.util.Objects; import static org.apache.dubbo.common.constants.CommonConstants.HEARTBEAT_EVENT; import static org.apache.dubbo.common.constants.CommonConstants.MOCK_HEARTBEAT_EVENT; @@ -108,7 +110,6 @@ public void writeObject(Object obj) throws IOException { if (!ProtobufUtils.isSupported(obj.getClass())) { throw new IllegalArgumentException("This serialization only support google protobuf object, the object class is: " + obj.getClass().getName()); } - writer.write(ProtobufUtils.serializeJson(obj)); writer.println(); writer.flush(); @@ -117,16 +118,18 @@ public void writeObject(Object obj) throws IOException { @Override public void writeThrowable(Object th) throws IOException { if (th instanceof Throwable && !ProtobufUtils.isSupported(th.getClass())) { - th = ProtobufUtils.convertToThrowableProto((Throwable) th); + ThrowablePB.ThrowableProto throwableProto = ProtobufUtils.convertToThrowableProto((Throwable) th); + writer.write(ProtobufUtils.serializeJson(throwableProto)); + } else { + writer.write(ProtobufUtils.serializeJson(th)); } - writer.write(ProtobufUtils.serializeJson(th)); writer.println(); writer.flush(); } @Override public void writeEvent(Object data) throws IOException { - if (data == HEARTBEAT_EVENT) { + if (Objects.equals(data, HEARTBEAT_EVENT)) { data = MOCK_HEARTBEAT_EVENT; } writeUTF((String) data); diff --git a/dubbo-serialization-extensions/dubbo-serialization-protobuf/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufObjectOutput.java b/dubbo-serialization-extensions/dubbo-serialization-protobuf/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufObjectOutput.java index 55bdba9de..b4808c3cf 100644 --- a/dubbo-serialization-extensions/dubbo-serialization-protobuf/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufObjectOutput.java +++ b/dubbo-serialization-extensions/dubbo-serialization-protobuf/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufObjectOutput.java @@ -28,10 +28,12 @@ import org.apache.dubbo.common.serialize.ObjectOutput; import org.apache.dubbo.common.serialize.protobuf.support.wrapper.MapValue; +import org.apache.dubbo.common.serialize.protobuf.support.wrapper.ThrowablePB; import java.io.IOException; import java.io.OutputStream; import java.util.Map; +import java.util.Objects; import static org.apache.dubbo.common.constants.CommonConstants.HEARTBEAT_EVENT; import static org.apache.dubbo.common.constants.CommonConstants.MOCK_HEARTBEAT_EVENT; @@ -120,7 +122,7 @@ public void writeObject(Object obj) throws IOException { @Override public void writeEvent(Object data) throws IOException { - if (data == HEARTBEAT_EVENT) { + if (Objects.equals(data, HEARTBEAT_EVENT)) { data = MOCK_HEARTBEAT_EVENT; } writeUTF((String) data); @@ -129,9 +131,11 @@ public void writeEvent(Object data) throws IOException { @Override public void writeThrowable(Object obj) throws IOException { if (obj instanceof Throwable && !(obj instanceof MessageLite)) { - obj = ProtobufUtils.convertToThrowableProto((Throwable) obj); + ThrowablePB.ThrowableProto throwableProto = ProtobufUtils.convertToThrowableProto((Throwable) obj); + ProtobufUtils.serialize(throwableProto, os); + } else { + ProtobufUtils.serialize(obj, os); } - ProtobufUtils.serialize(obj, os); os.flush(); } diff --git a/dubbo-serialization-extensions/dubbo-serialization-protobuf/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/ProtobufParamDeepCopyUtil.java b/dubbo-serialization-extensions/dubbo-serialization-protobuf/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/ProtobufParamDeepCopyUtil.java new file mode 100644 index 000000000..45af0ca86 --- /dev/null +++ b/dubbo-serialization-extensions/dubbo-serialization-protobuf/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/ProtobufParamDeepCopyUtil.java @@ -0,0 +1,64 @@ +/* + * 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 org.apache.dubbo.common.serialize.protobuf.support; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.logger.Logger; +import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.rpc.protocol.injvm.DefaultParamDeepCopyUtil; +import org.apache.dubbo.rpc.protocol.injvm.ParamDeepCopyUtil; + +public class ProtobufParamDeepCopyUtil implements ParamDeepCopyUtil { + private static final Logger logger = LoggerFactory.getLogger(DefaultParamDeepCopyUtil.class); + + private ParamDeepCopyUtil delegate; + + public ProtobufParamDeepCopyUtil(ParamDeepCopyUtil delegate) { + this.delegate = delegate; + } + + @Override + public T copy(URL url, Object src, Class targetClass) { + boolean isProtobufTypeSupported = ProtobufUtils.isSupported(targetClass); + if(isProtobufTypeSupported){ + try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { + ProtobufUtils.serialize(src, outputStream); + + try (ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray())) { + T deserialize = ProtobufUtils.deserialize(inputStream, targetClass); + return deserialize; + } catch (IOException e) { + logger.error("Error code 4-6. Unable to deep copy parameter to target class.", e); + } + + } catch (Throwable e) { + logger.error("Error code 4-6. Unable to deep copy parameter to target class.", e); + } + + if (src.getClass().equals(targetClass)) { + return (T) src; + } else { + return null; + } + } + return delegate.copy(url, src, targetClass); + } +} diff --git a/dubbo-serialization-extensions/dubbo-serialization-protobuf/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.injvm.ParamDeepCopyUtil b/dubbo-serialization-extensions/dubbo-serialization-protobuf/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.injvm.ParamDeepCopyUtil new file mode 100644 index 000000000..a3cb3e6e2 --- /dev/null +++ b/dubbo-serialization-extensions/dubbo-serialization-protobuf/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.injvm.ParamDeepCopyUtil @@ -0,0 +1 @@ +protobufDeepUtil=org.apache.dubbo.common.serialize.protobuf.support.ProtobufParamDeepCopyUtil diff --git a/dubbo-serialization-extensions/dubbo-serialization-protostuff/pom.xml b/dubbo-serialization-extensions/dubbo-serialization-protostuff/pom.xml index 4fc39f858..550e157aa 100644 --- a/dubbo-serialization-extensions/dubbo-serialization-protostuff/pom.xml +++ b/dubbo-serialization-extensions/dubbo-serialization-protostuff/pom.xml @@ -28,7 +28,7 @@ limitations under the License. dubbo-serialization-protostuff jar ${project.artifactId} - 1.0.2-SNAPSHOT + ${revision} The protostuff serialization module of dubbo project diff --git a/dubbo-serialization-extensions/dubbo-serialization-test/pom.xml b/dubbo-serialization-extensions/dubbo-serialization-test/pom.xml index 1b04a3db2..3bb7ea86b 100644 --- a/dubbo-serialization-extensions/dubbo-serialization-test/pom.xml +++ b/dubbo-serialization-extensions/dubbo-serialization-test/pom.xml @@ -35,25 +35,28 @@ - - org.apache.dubbo.extensions - dubbo-serialization-protostuff - 1.0.2-SNAPSHOT - gson com.google.code.gson 2.8.9 + + org.apache.dubbo.extensions + dubbo-serialization-protostuff + ${revision} + test + org.apache.dubbo.extensions dubbo-serialization-jackson ${revision} + test org.apache.dubbo.extensions dubbo-serialization-protobuf - 1.0.2-SNAPSHOT + ${revision} + test gson @@ -64,22 +67,26 @@ org.apache.dubbo.extensions dubbo-serialization-kryo - 1.0.2-SNAPSHOT + ${revision} + test org.apache.dubbo.extensions dubbo-serialization-avro - 1.0.2-SNAPSHOT + ${revision} + test org.apache.dubbo.extensions dubbo-serialization-fastjson - 1.0.2-SNAPSHOT + ${revision} + test org.apache.dubbo.extensions dubbo-serialization-fst - 1.0.2-SNAPSHOT + ${revision} + test org.apache.dubbo diff --git a/dubbo-serialization-extensions/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/protobuf/support/ProtobufParamDeepCopyUtilTest.java b/dubbo-serialization-extensions/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/protobuf/support/ProtobufParamDeepCopyUtilTest.java new file mode 100644 index 000000000..1c4db2e04 --- /dev/null +++ b/dubbo-serialization-extensions/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/protobuf/support/ProtobufParamDeepCopyUtilTest.java @@ -0,0 +1,74 @@ +/* + * 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 org.apache.dubbo.common.serialize.protobuf.support; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.constants.CommonConstants; +import org.apache.dubbo.common.serialize.protobuf.support.model.GooglePB; +import org.apache.dubbo.rpc.protocol.injvm.DefaultParamDeepCopyUtil; +import org.apache.dubbo.rpc.protocol.injvm.ParamDeepCopyUtil; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import com.google.protobuf.InvalidProtocolBufferException; + +public class ProtobufParamDeepCopyUtilTest { + private ParamDeepCopyUtil paramDeepCopyUtil; + + @BeforeEach + public void setUp() { + URL url = mockURL(); + this.paramDeepCopyUtil = url.getOrDefaultFrameworkModel().getExtensionLoader(ParamDeepCopyUtil.class) + .getExtension(url.getParameter(CommonConstants.INJVM_COPY_UTIL_KEY, DefaultParamDeepCopyUtil.NAME)); + } + + @Test + public void testProtobufDeepCopy() throws InvalidProtocolBufferException { + ProtobufUtils.marshaller(GooglePB.PBRequestType.getDefaultInstance()); + GooglePB.PhoneNumber phoneNumber = GooglePB.PhoneNumber.newBuilder() + .setNumber("134123781291").build(); + List phoneNumberList = new ArrayList<>(); + phoneNumberList.add(phoneNumber); + Map phoneNumberMap = new HashMap<>(); + phoneNumberMap.put("someUser", phoneNumber); + GooglePB.PBRequestType request = GooglePB.PBRequestType.newBuilder() + .setAge(15).setCash(10).setMoney(16.0).setNum(100L) + .addAllPhone(phoneNumberList).putAllDoubleMap(phoneNumberMap).build(); + GooglePB.PBRequestType copyResult = paramDeepCopyUtil.copy(mockURL(), request, GooglePB.PBRequestType.class); + String jsonString = ProtobufUtils.serializeJson(request); + String jsonString2 = ProtobufUtils.serializeJson(copyResult); + assertEquals(jsonString, jsonString2); + assertNotEquals(System.identityHashCode(request), System.identityHashCode(copyResult)); + List copyPhoneList = copyResult.getPhoneList(); + Map copyDoubleMap = copyResult.getDoubleMap(); + assertNotEquals(System.identityHashCode(phoneNumberList.get(0)), System.identityHashCode(copyPhoneList.get(0))); + assertNotEquals(System.identityHashCode(phoneNumberMap.get("someUser")), System.identityHashCode(copyDoubleMap.get("someUser"))); + } + + URL mockURL() { + URL url = new URL("dubbo", "localhost", 20880); + return url; + } +} diff --git a/dubbo-tag-extensions/dubbo-tag-subnets/pom.xml b/dubbo-tag-extensions/dubbo-tag-subnets/pom.xml index 99b6b3146..21fe49628 100644 --- a/dubbo-tag-extensions/dubbo-tag-subnets/pom.xml +++ b/dubbo-tag-extensions/dubbo-tag-subnets/pom.xml @@ -24,7 +24,7 @@ 4.0.0 - 1.0.2-SNAPSHOT + ${revision} dubbo-tag-subnets ${project.artifactId} The tag subnets module of dubbo project diff --git a/pom.xml b/pom.xml index a31ba28c1..0a57e5c94 100644 --- a/pom.xml +++ b/pom.xml @@ -94,23 +94,24 @@ dubbo-rpc-extensions dubbo-serialization-extensions dubbo-mock-extensions - dubbo-gateway-extensions dubbo-cross-thread-extensions dubbo-tag-extensions dobbo-doc-auto-gen - 1.0.5-SNAPSHOT + 3.0.0-SNAPSHOT - 5.6.0 + 5.9.3 + 1.9.3 + 4.2.1 3.11.1 2.2 5.2.4.Final 2.2.4 2.2.7 2.2 - 3.8.0 + 4.11.0 1.8 1.8 @@ -172,6 +173,18 @@ ${junit_jupiter_version} test + + org.junit.platform + junit-platform-commons + ${junit_platform_commons} + test + + + org.junit.jupiter + junit-jupiter-api + ${junit_jupiter_version} + test + org.junit.jupiter junit-jupiter-params @@ -184,12 +197,24 @@ ${hamcrest_version} test + + org.awaitility + awaitility + ${awaitility_version} + test + org.mockito mockito-core ${mockito_version} test + + org.mockito + mockito-inline + ${mockito_version} + test + cglib cglib-nodep @@ -356,11 +381,13 @@ Jenkinsfile **/codestyle/* **/resources/META-INF/** + **/resources/security/** .github/** compiler/** **/generated/** **/mockito-extensions/* + **/junit** @@ -561,9 +588,12 @@ true ${checkstyle.skip} - **/istio/v1/auth/Ca.java, - **/istio/v1/auth/IstioCertificateServiceGrpc.java, + **/istio/v1/auth/**/*, + **/com/google/rpc/*, **/generated/**/*, + **/generated-sources/**/*, + **/grpc/health/**/*, + **/grpc/reflection/**/*, **/target/**/*, diff --git a/test/dubbo-scenario-builder/pom.xml b/test/dubbo-scenario-builder/pom.xml index b0f981bcb..2c1f084e9 100644 --- a/test/dubbo-scenario-builder/pom.xml +++ b/test/dubbo-scenario-builder/pom.xml @@ -18,9 +18,10 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - dubbo-extensions-test org.apache.dubbo.extensions - 1.0.0-SNAPSHOT + dubbo-extensions-test + ${revision} + ../pom.xml 4.0.0 diff --git a/test/dubbo-test-runner/pom.xml b/test/dubbo-test-runner/pom.xml index 2fc320d54..70fd219e3 100644 --- a/test/dubbo-test-runner/pom.xml +++ b/test/dubbo-test-runner/pom.xml @@ -18,9 +18,10 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - dubbo-extensions-test org.apache.dubbo.extensions - 1.0.0-SNAPSHOT + dubbo-extensions-test + ${revision} + ../pom.xml 4.0.0 diff --git a/test/pom.xml b/test/pom.xml index 6f304349b..6ddda8d38 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -19,21 +19,38 @@ 4.0.0 + + org.apache.dubbo.extensions + extensions-parent + ${revision} + ../pom.xml + - org.apache.dubbo.extensions dubbo-extensions-test pom - 1.0.0-SNAPSHOT + ${revision} + dubbo-test-runner dubbo-scenario-builder + scenarios + + + org.apache.dubbo.extensions + dubbo-extensions-dependencies-bom + ${revision} + pom + + + UTF-8 1.8 1.8 + 3.1.11 diff --git a/test/scenarios/pom.xml b/test/scenarios/pom.xml index be93bf85f..e50413dd6 100644 --- a/test/scenarios/pom.xml +++ b/test/scenarios/pom.xml @@ -17,11 +17,16 @@ 4.0.0 + + org.apache.dubbo.extensions + dubbo-extensions-test + ${revision} + ../pom.xml + - org.apache.dubbo.extensions dubbo-scenarios pom - 1.0.0-SNAPSHOT + ${revision} scenarios-dubbo-serialization diff --git a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-avro-test/pom.xml b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-avro-test/pom.xml index 7ea494106..275393903 100644 --- a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-avro-test/pom.xml +++ b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-avro-test/pom.xml @@ -18,9 +18,10 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - scenarios-dubbo-serialization org.apache.dubbo.extensions - 1.0.0-SNAPSHOT + scenarios-dubbo-serialization + ${revision} + ../pom.xml 4.0.0 dubbo-serialization-avro-test @@ -28,10 +29,8 @@ 1.8 1.8 - 3.0.4 4.13.1 4.3.30.RELEASE - 1.0.2-SNAPSHOT 3.7.0 @@ -95,7 +94,7 @@ org.apache.dubbo.extensions dubbo-serialization-avro - ${dubbo.serialization.version} + ${revision} diff --git a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-fastjson-test/pom.xml b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-fastjson-test/pom.xml index f913a9d52..1682346ef 100644 --- a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-fastjson-test/pom.xml +++ b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-fastjson-test/pom.xml @@ -20,7 +20,8 @@ scenarios-dubbo-serialization org.apache.dubbo.extensions - 1.0.0-SNAPSHOT + ${revision} + ../pom.xml 4.0.0 @@ -29,10 +30,8 @@ 1.8 1.8 - 3.0.4 4.13.1 4.3.30.RELEASE - 1.0.2-SNAPSHOT 3.7.0 @@ -96,7 +95,7 @@ org.apache.dubbo.extensions dubbo-serialization-fastjson - ${dubbo.serialization.version} + ${revision} diff --git a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-fst-test/pom.xml b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-fst-test/pom.xml index 77b295770..6c8f8e91c 100644 --- a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-fst-test/pom.xml +++ b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-fst-test/pom.xml @@ -20,7 +20,8 @@ scenarios-dubbo-serialization org.apache.dubbo.extensions - 1.0.0-SNAPSHOT + ${revision} + ../pom.xml 4.0.0 @@ -29,10 +30,8 @@ 1.8 1.8 - 3.0.4 4.13.1 4.3.30.RELEASE - 1.0.2-SNAPSHOT 3.7.0 @@ -96,7 +95,7 @@ org.apache.dubbo.extensions dubbo-serialization-fst - ${dubbo.serialization.version} + ${revision} jackson-core diff --git a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-gson-test/pom.xml b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-gson-test/pom.xml index 069e982fe..953106a67 100644 --- a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-gson-test/pom.xml +++ b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-gson-test/pom.xml @@ -18,9 +18,10 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - scenarios-dubbo-serialization org.apache.dubbo.extensions - 1.0.0-SNAPSHOT + scenarios-dubbo-serialization + ${revision} + ../pom.xml 4.0.0 @@ -29,10 +30,8 @@ 1.8 1.8 - 3.0.4 4.13.1 4.3.30.RELEASE - 1.0.2-SNAPSHOT 3.7.0 @@ -96,7 +95,7 @@ org.apache.dubbo.extensions dubbo-serialization-gson - ${dubbo.serialization.version} + ${revision} diff --git a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-kryo-test/pom.xml b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-kryo-test/pom.xml index c9a4ea325..46bab35d8 100644 --- a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-kryo-test/pom.xml +++ b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-kryo-test/pom.xml @@ -20,7 +20,8 @@ scenarios-dubbo-serialization org.apache.dubbo.extensions - 1.0.0-SNAPSHOT + ${revision} + ../pom.xml 4.0.0 @@ -29,11 +30,8 @@ 1.8 1.8 - 3.0.4 4.13.1 4.3.30.RELEASE - 1.0.5-SNAPSHOT - 1.0.2-SNAPSHOT 3.7.0 @@ -50,7 +48,7 @@ org.apache.dubbo.extensions dubbo-extensions-dependencies-bom - ${dubbo.extensions.version} + ${revision} pom import @@ -105,7 +103,7 @@ org.apache.dubbo.extensions dubbo-serialization-kryo - ${dubbo.serialization.version} + ${revision} diff --git a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-protobuf-test/pom.xml b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-protobuf-test/pom.xml index 2c14f1fc5..73bb1fb4f 100644 --- a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-protobuf-test/pom.xml +++ b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-protobuf-test/pom.xml @@ -20,7 +20,8 @@ scenarios-dubbo-serialization org.apache.dubbo.extensions - 1.0.0-SNAPSHOT + ${revision} + ../pom.xml 4.0.0 @@ -29,11 +30,8 @@ 1.8 1.8 - 3.0.4 4.13.1 4.3.30.RELEASE - 0.0.2 - 1.0.2-SNAPSHOT 3.7.0 @@ -97,7 +95,7 @@ org.apache.dubbo.extensions dubbo-serialization-protobuf - ${dubbo.serialization.version} + ${revision} @@ -171,7 +169,7 @@ dubbo org.apache.dubbo dubbo-compiler - ${dubbo.compiler.version} + ${dubbo.version} org.apache.dubbo.gen.dubbo.Dubbo3Generator diff --git a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-protobuf-test/src/main/resources/spring/dubbo-demo-provider.xml b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-protobuf-test/src/main/resources/spring/dubbo-demo-provider.xml index a0fa283a6..d11b40755 100644 --- a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-protobuf-test/src/main/resources/spring/dubbo-demo-provider.xml +++ b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-protobuf-test/src/main/resources/spring/dubbo-demo-provider.xml @@ -30,6 +30,6 @@ + serialization="protobuf-json"/> diff --git a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-protostuff-test/pom.xml b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-protostuff-test/pom.xml index e5fc1351e..196996630 100644 --- a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-protostuff-test/pom.xml +++ b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-protostuff-test/pom.xml @@ -20,7 +20,8 @@ scenarios-dubbo-serialization org.apache.dubbo.extensions - 1.0.0-SNAPSHOT + ${revision} + ../pom.xml 4.0.0 @@ -29,10 +30,8 @@ 1.8 1.8 - 3.0.4 4.13.1 4.3.30.RELEASE - 1.0.2-SNAPSHOT 3.7.0 @@ -96,7 +95,7 @@ org.apache.dubbo.extensions dubbo-serialization-protostuff - ${dubbo.serialization.version} + ${revision} diff --git a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-testcase/pom.xml b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-testcase/pom.xml index df2ef83a3..0552995f6 100644 --- a/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-testcase/pom.xml +++ b/test/scenarios/scenarios-dubbo-serialization/dubbo-serialization-testcase/pom.xml @@ -20,7 +20,8 @@ scenarios-dubbo-serialization org.apache.dubbo.extensions - 1.0.0-SNAPSHOT + ${revision} + ../pom.xml 4.0.0 diff --git a/test/scenarios/scenarios-dubbo-serialization/pom.xml b/test/scenarios/scenarios-dubbo-serialization/pom.xml index 94273db9d..37ea2afde 100644 --- a/test/scenarios/scenarios-dubbo-serialization/pom.xml +++ b/test/scenarios/scenarios-dubbo-serialization/pom.xml @@ -18,12 +18,16 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - dubbo-scenarios org.apache.dubbo.extensions - 1.0.0-SNAPSHOT + dubbo-scenarios + ${revision} + ../pom.xml + 4.0.0 + scenarios-dubbo-serialization pom + dubbo-serialization-avro-test dubbo-serialization-gson-test @@ -34,7 +38,6 @@ dubbo-serialization-protostuff-test dubbo-serialization-testcase - scenarios-dubbo-serialization 8 From c6dc17d697bb98440d60a82a3dc041a6d686bf16 Mon Sep 17 00:00:00 2001 From: aofall <10182210+aofall@users.noreply.github.com> Date: Tue, 11 Jun 2024 18:51:08 +0800 Subject: [PATCH 34/35] Bump jetcd vertsion from 0.5.7 to 0.7.7 (#398) * update jetcd version * rename the dubbo-registry-etcd extension name from etcd3 to etcd * fix unit test failed * compatible old version * add ASF header --- .../dubbo-configcenter-etcd/pom.xml | 5 ++ .../etcd/EtcdDynamicConfiguration.java | 8 ++- .../etcd/EtcdDynamicConfigurationTest.java | 64 +++++++++++-------- dubbo-extensions-dependencies-bom/pom.xml | 10 ++- .../dubbo-metadata-report-etcd/pom.xml | 5 ++ .../store/etcd/EtcdMetadataReportTest.java | 16 +++-- .../etcd/EtcdCompatibleRegistryFactory.java | 28 ++++++++ .../org.apache.dubbo.registry.RegistryFactory | 3 +- .../dubbo/registry/etcd/EtcdRegistryTest.java | 4 +- .../dubbo-remoting-etcd3/pom.xml | 5 ++ .../dubbo/remoting/etcd/jetcd/LeaseTest.java | 33 +++++++--- 11 files changed, 132 insertions(+), 49 deletions(-) create mode 100644 dubbo-registry-extensions/dubbo-registry-etcd3/src/main/java/org/apache/dubbo/registry/etcd/EtcdCompatibleRegistryFactory.java diff --git a/dubbo-configcenter-extensions/dubbo-configcenter-etcd/pom.xml b/dubbo-configcenter-extensions/dubbo-configcenter-etcd/pom.xml index 05d3098e9..edcef8ebb 100644 --- a/dubbo-configcenter-extensions/dubbo-configcenter-etcd/pom.xml +++ b/dubbo-configcenter-extensions/dubbo-configcenter-etcd/pom.xml @@ -43,6 +43,11 @@ jetcd-launcher test + + io.etcd + jetcd-test + test + org.testcontainers testcontainers diff --git a/dubbo-configcenter-extensions/dubbo-configcenter-etcd/src/main/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfiguration.java b/dubbo-configcenter-extensions/dubbo-configcenter-etcd/src/main/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfiguration.java index 59b384b6c..03beb601b 100644 --- a/dubbo-configcenter-extensions/dubbo-configcenter-etcd/src/main/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfiguration.java +++ b/dubbo-configcenter-extensions/dubbo-configcenter-etcd/src/main/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfiguration.java @@ -22,6 +22,8 @@ import org.apache.dubbo.common.config.configcenter.ConfigChangedEvent; import org.apache.dubbo.common.config.configcenter.ConfigurationListener; import org.apache.dubbo.common.config.configcenter.DynamicConfiguration; +import org.apache.dubbo.common.logger.Logger; +import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.remoting.etcd.StateListener; import org.apache.dubbo.remoting.etcd.jetcd.JEtcdClient; @@ -48,6 +50,8 @@ */ public class EtcdDynamicConfiguration implements DynamicConfiguration { + private static final Logger logger = LoggerFactory.getLogger(EtcdDynamicConfiguration.class); + /** * The final root path would be: /$NAME_SPACE/config */ @@ -71,7 +75,7 @@ public class EtcdDynamicConfiguration implements DynamicConfiguration { try { recover(); } catch (Exception e) { - // ignore + logger.error("add etcd watch failed", e); } } }); @@ -164,7 +168,7 @@ public void onNext(WatchResponse watchResponse) { @Override public void onError(Throwable throwable) { - // ignore + logger.error("etcd watcher get an error", throwable); } @Override diff --git a/dubbo-configcenter-extensions/dubbo-configcenter-etcd/src/test/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfigurationTest.java b/dubbo-configcenter-extensions/dubbo-configcenter-etcd/src/test/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfigurationTest.java index 60e6889f1..fbce0deea 100644 --- a/dubbo-configcenter-extensions/dubbo-configcenter-etcd/src/test/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfigurationTest.java +++ b/dubbo-configcenter-extensions/dubbo-configcenter-etcd/src/test/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfigurationTest.java @@ -17,6 +17,7 @@ package org.apache.dubbo.configcenter.support.etcd; +import io.etcd.jetcd.test.EtcdClusterExtension; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.config.configcenter.ConfigChangedEvent; import org.apache.dubbo.common.config.configcenter.ConfigurationListener; @@ -25,7 +26,8 @@ import io.etcd.jetcd.ByteSequence; import io.etcd.jetcd.Client; import io.etcd.jetcd.launcher.EtcdCluster; -import io.etcd.jetcd.launcher.EtcdClusterFactory; +import org.apache.dubbo.common.logger.Logger; +import org.apache.dubbo.common.logger.LoggerFactory; import org.junit.Assert; import org.junit.Test; import org.junit.jupiter.api.AfterEach; @@ -47,12 +49,45 @@ */ public class EtcdDynamicConfigurationTest { + private static final Logger logger = LoggerFactory.getLogger(EtcdDynamicConfigurationTest.class); + private static EtcdDynamicConfiguration config; - public EtcdCluster etcdCluster = EtcdClusterFactory.buildCluster(getClass().getSimpleName(), 3, false); + public EtcdCluster etcdCluster; private static Client client; + @BeforeEach + public void setUp() { + EtcdClusterExtension clusterExtension = EtcdClusterExtension.builder() + .withClusterName(getClass().getSimpleName()) + .withNodes(3) + .withSsl(false) + .build(); + etcdCluster = clusterExtension.cluster(); + + etcdCluster.start(); + + client = Client.builder().endpoints(etcdCluster.clientEndpoints()).build(); + + List clientEndPoints = etcdCluster.clientEndpoints(); + + String ipAddress = clientEndPoints.get(0).getHost() + ":" + clientEndPoints.get(0).getPort(); + String urlForDubbo = "etcd://" + ipAddress + "/org.apache.dubbo.etcd.testService"; + + // timeout in 15 seconds. + URL url = URL.valueOf(urlForDubbo) + .addParameter(SESSION_TIMEOUT_KEY, 15000); + config = new EtcdDynamicConfiguration(url); + } + + @AfterEach + public void tearDown() { + if (etcdCluster != null) { + etcdCluster.close(); + } + } + @Test public void testGetConfig() { @@ -124,31 +159,8 @@ private void put(String key, String value) { try { client.getKVClient().put(ByteSequence.from(key, UTF_8), ByteSequence.from(value, UTF_8)).get(); } catch (Exception e) { - System.out.println("Error put value to etcd."); + logger.error("Error put value to etcd."); } } - @BeforeEach - public void setUp() { - - etcdCluster.start(); - - client = Client.builder().endpoints(etcdCluster.getClientEndpoints()).build(); - - List clientEndPoints = etcdCluster.getClientEndpoints(); - - String ipAddress = clientEndPoints.get(0).getHost() + ":" + clientEndPoints.get(0).getPort(); - String urlForDubbo = "etcd3://" + ipAddress + "/org.apache.dubbo.etcd.testService"; - - // timeout in 15 seconds. - URL url = URL.valueOf(urlForDubbo) - .addParameter(SESSION_TIMEOUT_KEY, 15000); - config = new EtcdDynamicConfiguration(url); - } - - @AfterEach - public void tearDown() { - etcdCluster.close(); - } - } diff --git a/dubbo-extensions-dependencies-bom/pom.xml b/dubbo-extensions-dependencies-bom/pom.xml index e9a6a1b17..88ddcb436 100644 --- a/dubbo-extensions-dependencies-bom/pom.xml +++ b/dubbo-extensions-dependencies-bom/pom.xml @@ -121,9 +121,8 @@ 1.1.7 1.7.25 2.4.4 - 0.5.7 + 0.7.7 1.53.0 - 0.5.7 4.1.66.Final 2.2.1 1.4.2 @@ -409,6 +408,11 @@ + + io.etcd + jetcd-test + ${jetcd_version} + io.grpc grpc-core @@ -442,7 +446,7 @@ io.etcd jetcd-launcher - ${etcd_launcher_version} + ${jetcd_version} com.github.spotbugs diff --git a/dubbo-metadata-report-extensions/dubbo-metadata-report-etcd/pom.xml b/dubbo-metadata-report-extensions/dubbo-metadata-report-etcd/pom.xml index dfbdfa61a..7a46a3442 100644 --- a/dubbo-metadata-report-extensions/dubbo-metadata-report-etcd/pom.xml +++ b/dubbo-metadata-report-extensions/dubbo-metadata-report-etcd/pom.xml @@ -51,6 +51,11 @@ jetcd-launcher test + + io.etcd + jetcd-test + test + org.testcontainers testcontainers diff --git a/dubbo-metadata-report-extensions/dubbo-metadata-report-etcd/src/test/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReportTest.java b/dubbo-metadata-report-extensions/dubbo-metadata-report-etcd/src/test/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReportTest.java index 119522cf5..a11e26e71 100644 --- a/dubbo-metadata-report-extensions/dubbo-metadata-report-etcd/src/test/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReportTest.java +++ b/dubbo-metadata-report-extensions/dubbo-metadata-report-etcd/src/test/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReportTest.java @@ -17,6 +17,7 @@ package org.apache.dubbo.metadata.store.etcd; +import io.etcd.jetcd.test.EtcdClusterExtension; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.metadata.definition.ServiceDefinitionBuilder; @@ -30,7 +31,6 @@ import io.etcd.jetcd.Client; import io.etcd.jetcd.kv.GetResponse; import io.etcd.jetcd.launcher.EtcdCluster; -import io.etcd.jetcd.launcher.EtcdClusterFactory; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -57,7 +57,7 @@ public class EtcdMetadataReportTest { private static final String TEST_SERVICE = "org.apache.dubbo.metadata.store.etcd.EtcdMetadata4TstService"; - private EtcdCluster etcdCluster = EtcdClusterFactory.buildCluster(getClass().getSimpleName(), 1, false); + private EtcdCluster etcdCluster; private Client etcdClientForTest; private EtcdMetadataReport etcdMetadataReport; private URL registryUrl; @@ -65,9 +65,13 @@ public class EtcdMetadataReportTest { @BeforeEach public void setUp() { + etcdCluster = EtcdClusterExtension.builder().withClusterName(getClass().getSimpleName()) + .withNodes(1) + .withSsl(false) + .build().cluster(); etcdCluster.start(); - etcdClientForTest = Client.builder().endpoints(etcdCluster.getClientEndpoints()).build(); - List clientEndPoints = etcdCluster.getClientEndpoints(); + etcdClientForTest = Client.builder().endpoints(etcdCluster.clientEndpoints()).build(); + List clientEndPoints = etcdCluster.clientEndpoints(); this.registryUrl = URL.valueOf("etcd://" + clientEndPoints.get(0).getHost() + ":" + clientEndPoints.get(0).getPort()); etcdMetadataReportFactory = new EtcdMetadataReportFactory(); this.etcdMetadataReport = (EtcdMetadataReport) etcdMetadataReportFactory.createMetadataReport(registryUrl); @@ -75,7 +79,9 @@ public void setUp() { @AfterEach public void tearDown() throws Exception { - etcdCluster.close(); + if (etcdCluster != null) { + etcdCluster.stop(); + } } @Test diff --git a/dubbo-registry-extensions/dubbo-registry-etcd3/src/main/java/org/apache/dubbo/registry/etcd/EtcdCompatibleRegistryFactory.java b/dubbo-registry-extensions/dubbo-registry-etcd3/src/main/java/org/apache/dubbo/registry/etcd/EtcdCompatibleRegistryFactory.java new file mode 100644 index 000000000..8750a9657 --- /dev/null +++ b/dubbo-registry-extensions/dubbo-registry-etcd3/src/main/java/org/apache/dubbo/registry/etcd/EtcdCompatibleRegistryFactory.java @@ -0,0 +1,28 @@ +/* + * 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 org.apache.dubbo.registry.etcd; + +public class EtcdCompatibleRegistryFactory extends EtcdServiceDiscoveryFactory { + + // The extension name of dubbo-registry-etcd is etcd3 and user should config the URL as 'etcd3://localhost:2379'. + // But the extension name of dubbo-metadata-report-etcd and dubbo-configcenter-etcd are etcd + // and user should config the URL as 'etcd://localhost:2379'. + // To avoid confusion for users when configuring URLs in registry, rename the dubbo-registry-etcd extension name + // from etcd3 to etcd, and use extend class to compatible the old version of dubbo-registry-etcd. + // It can unify the extension name and avoid confusion for users and compatible the old version + +} diff --git a/dubbo-registry-extensions/dubbo-registry-etcd3/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.RegistryFactory b/dubbo-registry-extensions/dubbo-registry-etcd3/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.RegistryFactory index 4a6d09c9f..c5bd906b8 100644 --- a/dubbo-registry-extensions/dubbo-registry-etcd3/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.RegistryFactory +++ b/dubbo-registry-extensions/dubbo-registry-etcd3/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.RegistryFactory @@ -1 +1,2 @@ -etcd3=org.apache.dubbo.registry.etcd.EtcdRegistryFactory \ No newline at end of file +etcd=org.apache.dubbo.registry.etcd.EtcdRegistryFactory +etcd3=org.apache.dubbo.registry.etcd.EtcdCompatibleRegistryFactory diff --git a/dubbo-registry-extensions/dubbo-registry-etcd3/src/test/java/org/apache/dubbo/registry/etcd/EtcdRegistryTest.java b/dubbo-registry-extensions/dubbo-registry-etcd3/src/test/java/org/apache/dubbo/registry/etcd/EtcdRegistryTest.java index 82e32a510..1dd4e9369 100644 --- a/dubbo-registry-extensions/dubbo-registry-etcd3/src/test/java/org/apache/dubbo/registry/etcd/EtcdRegistryTest.java +++ b/dubbo-registry-extensions/dubbo-registry-etcd3/src/test/java/org/apache/dubbo/registry/etcd/EtcdRegistryTest.java @@ -95,9 +95,9 @@ public class EtcdRegistryTest { URL serviceUrl = URL.valueOf("dubbo://" + NetUtils.getLocalHost() + "/" + service + "?methods=test1,test2"); URL serviceUrl2 = URL.valueOf("dubbo://" + NetUtils.getLocalHost() + "/" + service + "?methods=test1,test2,test3"); URL serviceUrl3 = URL.valueOf("dubbo://" + NetUtils.getLocalHost() + "/" + outerService + "?methods=test1,test2"); - URL registryUrl = URL.valueOf("etcd3://127.0.0.1:2379/org.apache.dubbo.registry.RegistryService"); + URL registryUrl = URL.valueOf("etcd://127.0.0.1:2379/org.apache.dubbo.registry.RegistryService"); URL consumerUrl = URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":2018" + "/" + service + "?methods=test1,test2"); - RegistryFactory registryFactory = ExtensionLoader.getExtensionLoader(RegistryFactory.class).getExtension("etcd3", false); + RegistryFactory registryFactory = ExtensionLoader.getExtensionLoader(RegistryFactory.class).getExtension("etcd", false); EtcdRegistry registry; URL subscribe = new URL( ADMIN_PROTOCOL, NetUtils.getLocalHost(), 0, "", diff --git a/dubbo-remoting-extensions/dubbo-remoting-etcd3/pom.xml b/dubbo-remoting-extensions/dubbo-remoting-etcd3/pom.xml index 9e7f187c7..288d86cc7 100644 --- a/dubbo-remoting-extensions/dubbo-remoting-etcd3/pom.xml +++ b/dubbo-remoting-extensions/dubbo-remoting-etcd3/pom.xml @@ -53,6 +53,11 @@ io.etcd jetcd-core + + io.etcd + jetcd-test + test + io.grpc grpc-core diff --git a/dubbo-remoting-extensions/dubbo-remoting-etcd3/src/test/java/org/apache/dubbo/remoting/etcd/jetcd/LeaseTest.java b/dubbo-remoting-extensions/dubbo-remoting-etcd3/src/test/java/org/apache/dubbo/remoting/etcd/jetcd/LeaseTest.java index 618898487..a2feec6ad 100644 --- a/dubbo-remoting-extensions/dubbo-remoting-etcd3/src/test/java/org/apache/dubbo/remoting/etcd/jetcd/LeaseTest.java +++ b/dubbo-remoting-extensions/dubbo-remoting-etcd3/src/test/java/org/apache/dubbo/remoting/etcd/jetcd/LeaseTest.java @@ -39,15 +39,15 @@ import io.etcd.jetcd.KV; import io.etcd.jetcd.Lease; import io.etcd.jetcd.launcher.EtcdCluster; -import io.etcd.jetcd.launcher.EtcdClusterFactory; import io.etcd.jetcd.lease.LeaseKeepAliveResponse; import io.etcd.jetcd.options.PutOption; import io.etcd.jetcd.support.CloseableClient; import io.etcd.jetcd.support.Observers; +import io.etcd.jetcd.test.EtcdClusterExtension; import io.grpc.stub.StreamObserver; -import org.junit.jupiter.api.AfterAll; +import org.apache.dubbo.common.logger.Logger; +import org.apache.dubbo.common.logger.LoggerFactory; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -65,6 +65,8 @@ @Disabled public class LeaseTest { + private static final Logger logger = LoggerFactory.getLogger(LeaseTest.class); + private static EtcdCluster cluster; private KV kvClient; @@ -75,20 +77,31 @@ public class LeaseTest { private static final ByteSequence KEY_2 = ByteSequence.from("foo2", Charsets.UTF_8); private static final ByteSequence VALUE = ByteSequence.from("bar", Charsets.UTF_8); - @BeforeAll - public static void beforeClass() { - cluster = EtcdClusterFactory.buildCluster("etcd-lease", 3, false); + @BeforeEach + public void beforeClass() { + EtcdClusterExtension clusterExtension = EtcdClusterExtension.builder() + .withClusterName("etcd-lease") + .withNodes(3) + .withSsl(false) + .build(); + try { + cluster = clusterExtension.cluster(); + } catch (Exception e) { + logger.error("Init etcd cluster failed"); + } cluster.start(); } - @AfterAll - public static void afterClass() { - cluster.close(); + @AfterEach + public void afterClass() { + if (cluster != null) { + cluster.stop(); + } } @BeforeEach public void setUp() { - client = Client.builder().endpoints(cluster.getClientEndpoints()).build(); + client = Client.builder().endpoints(cluster.clientEndpoints()).build(); kvClient = client.getKVClient(); leaseClient = client.getLeaseClient(); } From 5a7ec170c0c3388a179ea89a7512438fc2b88825 Mon Sep 17 00:00:00 2001 From: songxiaosheng Date: Thu, 13 Jun 2024 18:46:18 +0800 Subject: [PATCH 35/35] :arrow_up: 3.0.0 release --- dubbo-extensions-dependencies-bom/pom.xml | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dubbo-extensions-dependencies-bom/pom.xml b/dubbo-extensions-dependencies-bom/pom.xml index 88ddcb436..714b15566 100644 --- a/dubbo-extensions-dependencies-bom/pom.xml +++ b/dubbo-extensions-dependencies-bom/pom.xml @@ -89,7 +89,7 @@ - 3.0.0-SNAPSHOT + 3.0.0 3.0.15 5.2.9.RELEASE 2.4.1 diff --git a/pom.xml b/pom.xml index 0a57e5c94..4884f8de3 100644 --- a/pom.xml +++ b/pom.xml @@ -100,7 +100,7 @@
- 3.0.0-SNAPSHOT + 3.0.0 5.9.3 1.9.3