From 5ab0ddea646d73be2e43a926a783e9a0f0b41101 Mon Sep 17 00:00:00 2001 From: liaochuntao Date: Tue, 16 Jan 2024 23:45:10 +0800 Subject: [PATCH] feat:support dubbo3.2.x (#37) --- .../pom.xml | 8 +- .../dubbo/example/api/GreetingService.java} | 48 +-- .../dubbo-circuitbreak-consumer/pom.xml | 100 ----- .../circuitbreak/consumer/Application.java | 68 ---- .../src/main/resources/log4j.properties | 7 - .../dubbo-circuitbreak-provider/pom.xml | 94 ----- .../circuitbreak/provider/Application.java | 57 --- .../provider/DemoServiceImpl.java | 50 --- .../src/main/resources/log4j.properties | 7 - .../dubbo-circuitbreak-example/pom.xml | 19 - .../dubbo-discovery-consumer/pom.xml | 94 ----- .../dubbo/discovery/consumer/Application.java | 59 --- .../src/main/resources/log4j.properties | 7 - .../dubbo-discovery-provider/pom.xml | 94 ----- .../dubbo/discovery/provider/Application.java | 46 --- .../discovery/provider/DemoServiceImpl.java | 41 -- .../src/main/resources/log4j.properties | 7 - .../dubbo-quick-consumer/pom.xml | 140 +++++++ .../consumer/GreetingServiceConsumer.java | 81 ++-- .../discovery/example/consumer/Main.java | 107 +++++ .../src/main/resources/log4j2.xml | 12 + .../spring/dubbo-consumer.properties | 6 + .../dubbo-quick-provider/pom.xml | 150 +++++++ .../provider/AnnotatedGreetingService.java} | 69 ++-- .../discovery/example/provider/Main.java | 43 ++ .../src/main/resources/log4j2.xml | 12 + .../spring/dubbo-provider.properties | 19 + .../dubbo-discovery-example/pom.xml | 11 +- .../dubbo/demo/CircuitbreakDemoService.java | 22 -- .../org/apache/dubbo/demo/DemoService.java | 29 -- .../apache/dubbo/demo/GreetingService.java | 24 -- .../org/apache/dubbo/demo/NextService.java | 22 -- .../dubbo-ratelimit-consumer/pom.xml | 94 ----- .../dubbo/ratelimit/consumer/Application.java | 99 ----- .../src/main/resources/log4j.properties | 7 - .../dubbo-ratelimit-provider/pom.xml | 100 ----- .../dubbo/ratelimit/provider/Application.java | 55 --- .../provider/RatelimitDemoServiceImpl.java | 41 -- .../src/main/resources/log4j.properties | 7 - .../dubbo-ratelimit-example/pom.xml | 20 - .../dubbo-router-back/pom.xml | 94 ----- .../dubbo/router/back/Application.java | 64 --- .../dubbo-router-front/pom.xml | 100 ----- .../dubbo/router/front/Application.java | 59 --- .../src/main/resources/log4j.xml | 28 -- .../dubbo-router-middle/pom.xml | 100 ----- .../dubbo/router/middle/Application.java | 59 --- .../router/middle/MiddleDemoServiceImpl.java | 65 --- .../dubbo-router-example/pom.xml | 21 - dubbo/dubbo-examples/pom.xml | 49 ++- .../dubbo-circuitbreaker-polaris/pom.xml | 10 - .../circuitbreaker/CircuitBreakerFilter.java | 217 +++++----- .../dubbo-configcenter-polaris/pom.xml | 23 ++ .../PolarisDynamicConfiguration.java | 139 +++++++ .../PolarisDynamicConfigurationFactory.java | 63 ++- ...g.configcenter.DynamicConfigurationFactory | 1 + .../dubbo-metadatareport-polaris/pom.xml | 22 ++ .../report/PolarisMetadataReport.java | 369 ++++++++++++++++++ .../report/PolarisMetadataReportFactory.java | 60 +-- ...ubbo.metadata.report.MetadataReportFactory | 1 + .../dubbo-ratelimit-polaris/pom.xml | 10 - .../dubbo/ratelimit/RateLimitFilter.java | 65 ++- .../org.apache.dubbo.rpc.Filter | 0 .../dubbo-registry-polaris/pom.xml | 7 +- .../dubbo/registry/PolarisRegistry.java | 17 +- .../registry/PolarisRegistryFactory.java | 12 + .../registry/PolarisServiceDiscovery.java | 212 ++++++++++ .../PolarisServiceDiscoveryFactory.java | 41 ++ .../polaris/dubbo/report/ReportFilter.java | 51 ++- .../org.apache.dubbo.registry.RegistryFactory | 0 ...bo.registry.client.ServiceDiscoveryFactory | 1 + .../org.apache.dubbo.rpc.Filter | 0 .../dubbo-router-polaris/pom.xml | 10 - .../polaris/dubbo/router/InstanceInvoker.java | 5 +- .../polaris/dubbo/router/PolarisRouter.java | 114 +++--- dubbo/dubbo-plugins/pom.xml | 2 + dubbo/pom.xml | 33 -- .../dubbox-discovery-consumer/pom.xml | 59 --- .../dubbox/discovery/consumer/DemoAction.java | 81 ---- .../discovery/consumer/DemoConsumer.java | 26 -- .../META-INF/spring/discovery-demo-action.xml | 11 - .../spring/discovery-demo-consumer.xml | 22 -- .../src/main/resources/log4j.xml | 28 -- .../dubbox-discovery-example-api/pom.xml | 16 - .../discovery/example/api/BidRequest.java | 53 --- .../discovery/example/api/BidResponse.java | 42 -- .../discovery/example/api/BidService.java | 25 -- .../dubbox/discovery/example/api/Device.java | 77 ---- .../dubbox/discovery/example/api/Geo.java | 59 --- .../discovery/example/api/Impression.java | 41 -- .../dubbox/discovery/example/api/SeatBid.java | 42 -- .../dubbox-discovery-provider/pom.xml | 66 ---- .../discovery/provider/Application.java | 26 -- .../discovery/provider/BidServiceImpl.java | 48 --- .../spring/dubbox-discovery-provider.xml | 20 - .../src/main/resources/log4j.xml | 28 -- .../src/main/webapp/WEB-INF/web.xml | 30 -- .../dubbox-discovery-example/pom.xml | 294 -------------- .../dubbox-ratelimit-consumer/pom.xml | 59 --- .../ratelimit/consumer/Application.java | 25 -- .../ratelimit/consumer/RatelimitAction.java | 81 ---- .../spring/ratelimit-demo-consumer.xml | 23 -- .../src/main/resources/log4j.xml | 51 --- .../dubbox-ratelimit-example-api/pom.xml | 15 - .../dubbox/ratelimit/example/api/User.java | 41 -- .../ratelimit/example/api/UserService.java | 23 -- .../dubbox-ratelimit-provider/pom.xml | 61 --- .../ratelimit/provider/Application.java | 26 -- .../ratelimit/provider/UserServiceImpl.java | 32 -- .../spring/dubbox-ratelimit-provider.xml | 20 - .../src/main/resources/log4j.xml | 28 -- .../src/main/webapp/WEB-INF/web.xml | 30 -- .../dubbox-ratelimit-example/pom.xml | 300 -------------- .../dubbox-router-back/pom.xml | 60 --- .../dubbox/router/back/Application.java | 26 -- .../dubbox/router/back/BackServiceImpl.java | 40 -- .../META-INF/spring/dubbox-router-back.xml | 21 - .../src/main/resources/log4j.xml | 28 -- .../src/main/webapp/WEB-INF/web.xml | 30 -- .../dubbox-router-example-api/pom.xml | 16 - .../router/example/api/BackService.java | 23 -- .../router/example/api/FooResponse.java | 33 -- .../router/example/api/MiddleService.java | 23 -- .../dubbox-router-front/pom.xml | 59 --- .../dubbox/router/front/FrontAction.java | 25 -- .../dubbox/router/front/FrontService.java | 50 --- .../META-INF/spring/dubbox-router-front.xml | 20 - .../dubbox-router-middle/pom.xml | 60 --- .../dubbox/router/middle/Application.java | 26 -- .../router/middle/MiddleServiceImpl.java | 47 --- .../META-INF/spring/dubbox-router-middle.xml | 26 -- .../src/main/resources/log4j.xml | 28 -- .../src/main/webapp/WEB-INF/web.xml | 30 -- .../dubbox-router-example/pom.xml | 300 -------------- dubbox/dubbox-examples/pom.xml | 367 ----------------- .../dubbox-circuitbreaker-polaris/pom.xml | 32 -- .../circuitbreaker/CircuitBreakerFilter.java | 155 -------- .../dubbo/com.alibaba.dubbo.rpc.Filter | 1 - .../dubbox-ratelimit-polaris/pom.xml | 32 -- .../dubbox/ratelimit/RateLimitFilter.java | 107 ----- .../dubbo/com.alibaba.dubbo.rpc.Filter | 1 - .../dubbox-registry-polaris/pom.xml | 32 -- .../dubbox/registry/PolarisRegistry.java | 205 ---------- .../polaris/dubbox/report/ReportFilter.java | 100 ----- ...com.alibaba.dubbo.registry.RegistryFactory | 1 - .../dubbo/com.alibaba.dubbo.rpc.Filter | 1 - .../dubbox-router-polaris/pom.xml | 32 -- .../dubbox/router/InstanceInvoker.java | 218 ----------- .../polaris/dubbox/router/PolarisRouter.java | 141 ------- ...om.alibaba.dubbo.rpc.cluster.RouterFactory | 1 - dubbox/dubbox-plugins/pom.xml | 23 -- dubbox/pom.xml | 35 -- polaris-adapter-dubbo/pom.xml | 49 ++- .../polaris/common/parser/QueryParser.java | 14 +- .../registry/BaseBootConfigHandler.java | 1 + .../common/registry/DubboServiceInfo.java | 109 ++++++ .../common/registry/PolarisConfig.java | 47 ++- .../common/registry/PolarisOperator.java | 58 ++- .../registry/PolarisOperatorDelegate.java | 20 +- .../common/registry/PolarisOperators.java | 39 +- .../common/{registry => utils}/Consts.java | 14 +- .../{registry => utils}/ConvertUtils.java | 2 +- .../polaris/common/utils/DubboUtils.java | 79 ++++ .../polaris/common/utils/ExampleConsts.java | 29 -- .../polaris/common/utils/ExtensionConsts.java | 29 -- pom.xml | 6 +- 166 files changed, 2139 insertions(+), 6821 deletions(-) rename dubbo/dubbo-examples/{dubbo-example-interface => dubbo-api-example}/pom.xml (60%) rename dubbo/dubbo-examples/{dubbo-example-interface/src/main/java/org/apache/dubbo/demo/RatelimitDemoService.java => dubbo-api-example/src/main/java/com/tencent/polaris/dubbo/example/api/GreetingService.java} (83%) delete mode 100644 dubbo/dubbo-examples/dubbo-circuitbreak-example/dubbo-circuitbreak-consumer/pom.xml delete mode 100644 dubbo/dubbo-examples/dubbo-circuitbreak-example/dubbo-circuitbreak-consumer/src/main/java/com/tencent/polaris/dubbo/circuitbreak/consumer/Application.java delete mode 100644 dubbo/dubbo-examples/dubbo-circuitbreak-example/dubbo-circuitbreak-consumer/src/main/resources/log4j.properties delete mode 100644 dubbo/dubbo-examples/dubbo-circuitbreak-example/dubbo-circuitbreak-provider/pom.xml delete mode 100644 dubbo/dubbo-examples/dubbo-circuitbreak-example/dubbo-circuitbreak-provider/src/main/java/com/tencent/polaris/dubbo/circuitbreak/provider/Application.java delete mode 100644 dubbo/dubbo-examples/dubbo-circuitbreak-example/dubbo-circuitbreak-provider/src/main/java/com/tencent/polaris/dubbo/circuitbreak/provider/DemoServiceImpl.java delete mode 100644 dubbo/dubbo-examples/dubbo-circuitbreak-example/dubbo-circuitbreak-provider/src/main/resources/log4j.properties delete mode 100644 dubbo/dubbo-examples/dubbo-circuitbreak-example/pom.xml delete mode 100644 dubbo/dubbo-examples/dubbo-discovery-example/dubbo-discovery-consumer/pom.xml delete mode 100644 dubbo/dubbo-examples/dubbo-discovery-example/dubbo-discovery-consumer/src/main/java/com/tencent/polaris/dubbo/discovery/consumer/Application.java delete mode 100644 dubbo/dubbo-examples/dubbo-discovery-example/dubbo-discovery-consumer/src/main/resources/log4j.properties delete mode 100644 dubbo/dubbo-examples/dubbo-discovery-example/dubbo-discovery-provider/pom.xml delete mode 100644 dubbo/dubbo-examples/dubbo-discovery-example/dubbo-discovery-provider/src/main/java/com/tencent/polaris/dubbo/discovery/provider/Application.java delete mode 100644 dubbo/dubbo-examples/dubbo-discovery-example/dubbo-discovery-provider/src/main/java/com/tencent/polaris/dubbo/discovery/provider/DemoServiceImpl.java delete mode 100644 dubbo/dubbo-examples/dubbo-discovery-example/dubbo-discovery-provider/src/main/resources/log4j.properties create mode 100644 dubbo/dubbo-examples/dubbo-discovery-example/dubbo-quick-consumer/pom.xml rename dubbox/dubbox-examples/dubbox-router-example/dubbox-router-example-api/src/main/java/com/tencent/polaris/dubbox/router/example/api/FooRequest.java => dubbo/dubbo-examples/dubbo-discovery-example/dubbo-quick-consumer/src/main/java/com/tencent/polaris/dubbo/discovery/example/consumer/GreetingServiceConsumer.java (56%) create mode 100644 dubbo/dubbo-examples/dubbo-discovery-example/dubbo-quick-consumer/src/main/java/com/tencent/polaris/dubbo/discovery/example/consumer/Main.java create mode 100644 dubbo/dubbo-examples/dubbo-discovery-example/dubbo-quick-consumer/src/main/resources/log4j2.xml create mode 100644 dubbo/dubbo-examples/dubbo-discovery-example/dubbo-quick-consumer/src/main/resources/spring/dubbo-consumer.properties create mode 100644 dubbo/dubbo-examples/dubbo-discovery-example/dubbo-quick-provider/pom.xml rename dubbo/dubbo-examples/{dubbo-router-example/dubbo-router-back/src/main/java/com/tencent/polaris/dubbo/router/back/BackDemoServiceImpl.java => dubbo-discovery-example/dubbo-quick-provider/src/main/java/com/tencent/polaris/dubbo/discovery/example/provider/AnnotatedGreetingService.java} (66%) create mode 100644 dubbo/dubbo-examples/dubbo-discovery-example/dubbo-quick-provider/src/main/java/com/tencent/polaris/dubbo/discovery/example/provider/Main.java create mode 100644 dubbo/dubbo-examples/dubbo-discovery-example/dubbo-quick-provider/src/main/resources/log4j2.xml create mode 100644 dubbo/dubbo-examples/dubbo-discovery-example/dubbo-quick-provider/src/main/resources/spring/dubbo-provider.properties delete mode 100644 dubbo/dubbo-examples/dubbo-example-interface/src/main/java/org/apache/dubbo/demo/CircuitbreakDemoService.java delete mode 100644 dubbo/dubbo-examples/dubbo-example-interface/src/main/java/org/apache/dubbo/demo/DemoService.java delete mode 100644 dubbo/dubbo-examples/dubbo-example-interface/src/main/java/org/apache/dubbo/demo/GreetingService.java delete mode 100644 dubbo/dubbo-examples/dubbo-example-interface/src/main/java/org/apache/dubbo/demo/NextService.java delete mode 100644 dubbo/dubbo-examples/dubbo-ratelimit-example/dubbo-ratelimit-consumer/pom.xml delete mode 100644 dubbo/dubbo-examples/dubbo-ratelimit-example/dubbo-ratelimit-consumer/src/main/java/com/tencent/polaris/dubbo/ratelimit/consumer/Application.java delete mode 100644 dubbo/dubbo-examples/dubbo-ratelimit-example/dubbo-ratelimit-consumer/src/main/resources/log4j.properties delete mode 100644 dubbo/dubbo-examples/dubbo-ratelimit-example/dubbo-ratelimit-provider/pom.xml delete mode 100644 dubbo/dubbo-examples/dubbo-ratelimit-example/dubbo-ratelimit-provider/src/main/java/com/tencent/polaris/dubbo/ratelimit/provider/Application.java delete mode 100644 dubbo/dubbo-examples/dubbo-ratelimit-example/dubbo-ratelimit-provider/src/main/java/com/tencent/polaris/dubbo/ratelimit/provider/RatelimitDemoServiceImpl.java delete mode 100644 dubbo/dubbo-examples/dubbo-ratelimit-example/dubbo-ratelimit-provider/src/main/resources/log4j.properties delete mode 100644 dubbo/dubbo-examples/dubbo-ratelimit-example/pom.xml delete mode 100644 dubbo/dubbo-examples/dubbo-router-example/dubbo-router-back/pom.xml delete mode 100644 dubbo/dubbo-examples/dubbo-router-example/dubbo-router-back/src/main/java/com/tencent/polaris/dubbo/router/back/Application.java delete mode 100644 dubbo/dubbo-examples/dubbo-router-example/dubbo-router-front/pom.xml delete mode 100644 dubbo/dubbo-examples/dubbo-router-example/dubbo-router-front/src/main/java/com/tencent/polaris/dubbo/router/front/Application.java delete mode 100644 dubbo/dubbo-examples/dubbo-router-example/dubbo-router-front/src/main/resources/log4j.xml delete mode 100644 dubbo/dubbo-examples/dubbo-router-example/dubbo-router-middle/pom.xml delete mode 100644 dubbo/dubbo-examples/dubbo-router-example/dubbo-router-middle/src/main/java/com/tencent/polaris/dubbo/router/middle/Application.java delete mode 100644 dubbo/dubbo-examples/dubbo-router-example/dubbo-router-middle/src/main/java/com/tencent/polaris/dubbo/router/middle/MiddleDemoServiceImpl.java delete mode 100644 dubbo/dubbo-examples/dubbo-router-example/pom.xml create mode 100644 dubbo/dubbo-plugins/dubbo-configcenter-polaris/pom.xml create mode 100644 dubbo/dubbo-plugins/dubbo-configcenter-polaris/src/main/java/com/tencent/polaris/dubbo/configuration/PolarisDynamicConfiguration.java rename dubbox/dubbox-plugins/dubbox-router-polaris/src/main/java/com/tencent/polaris/dubbox/router/PolarisRouterFactory.java => dubbo/dubbo-plugins/dubbo-configcenter-polaris/src/main/java/com/tencent/polaris/dubbo/configuration/PolarisDynamicConfigurationFactory.java (61%) create mode 100644 dubbo/dubbo-plugins/dubbo-configcenter-polaris/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.config.configcenter.DynamicConfigurationFactory create mode 100644 dubbo/dubbo-plugins/dubbo-metadatareport-polaris/pom.xml create mode 100644 dubbo/dubbo-plugins/dubbo-metadatareport-polaris/src/main/java/com/tencent/polaris/dubbo/metadata/report/PolarisMetadataReport.java rename dubbox/dubbox-plugins/dubbox-registry-polaris/src/main/java/com/tencent/polaris/dubbox/registry/PolarisRegistryFactory.java => dubbo/dubbo-plugins/dubbo-metadatareport-polaris/src/main/java/com/tencent/polaris/dubbo/metadata/report/PolarisMetadataReportFactory.java (61%) create mode 100644 dubbo/dubbo-plugins/dubbo-metadatareport-polaris/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.report.MetadataReportFactory rename dubbo/dubbo-plugins/dubbo-ratelimit-polaris/src/main/resources/META-INF/dubbo/{ => internal}/org.apache.dubbo.rpc.Filter (100%) create mode 100644 dubbo/dubbo-plugins/dubbo-registry-polaris/src/main/java/com/tencent/polaris/dubbo/registry/PolarisServiceDiscovery.java create mode 100644 dubbo/dubbo-plugins/dubbo-registry-polaris/src/main/java/com/tencent/polaris/dubbo/registry/PolarisServiceDiscoveryFactory.java rename dubbo/dubbo-plugins/dubbo-registry-polaris/src/main/resources/META-INF/dubbo/{ => internal}/org.apache.dubbo.registry.RegistryFactory (100%) create mode 100644 dubbo/dubbo-plugins/dubbo-registry-polaris/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.ServiceDiscoveryFactory rename dubbo/dubbo-plugins/dubbo-registry-polaris/src/main/resources/META-INF/dubbo/{ => internal}/org.apache.dubbo.rpc.Filter (100%) delete mode 100644 dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-consumer/pom.xml delete mode 100644 dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-consumer/src/main/java/com/tencent/polaris/dubbox/discovery/consumer/DemoAction.java delete mode 100644 dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-consumer/src/main/java/com/tencent/polaris/dubbox/discovery/consumer/DemoConsumer.java delete mode 100644 dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-consumer/src/main/resources/META-INF/spring/discovery-demo-action.xml delete mode 100644 dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-consumer/src/main/resources/META-INF/spring/discovery-demo-consumer.xml delete mode 100644 dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-consumer/src/main/resources/log4j.xml delete mode 100644 dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-example-api/pom.xml delete mode 100644 dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-example-api/src/main/java/com/tencent/polaris/dubbox/discovery/example/api/BidRequest.java delete mode 100644 dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-example-api/src/main/java/com/tencent/polaris/dubbox/discovery/example/api/BidResponse.java delete mode 100644 dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-example-api/src/main/java/com/tencent/polaris/dubbox/discovery/example/api/BidService.java delete mode 100644 dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-example-api/src/main/java/com/tencent/polaris/dubbox/discovery/example/api/Device.java delete mode 100644 dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-example-api/src/main/java/com/tencent/polaris/dubbox/discovery/example/api/Geo.java delete mode 100644 dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-example-api/src/main/java/com/tencent/polaris/dubbox/discovery/example/api/Impression.java delete mode 100644 dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-example-api/src/main/java/com/tencent/polaris/dubbox/discovery/example/api/SeatBid.java delete mode 100644 dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-provider/pom.xml delete mode 100644 dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-provider/src/main/java/com/tencent/polaris/dubbox/discovery/provider/Application.java delete mode 100644 dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-provider/src/main/java/com/tencent/polaris/dubbox/discovery/provider/BidServiceImpl.java delete mode 100644 dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-provider/src/main/resources/META-INF/spring/dubbox-discovery-provider.xml delete mode 100644 dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-provider/src/main/resources/log4j.xml delete mode 100644 dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-provider/src/main/webapp/WEB-INF/web.xml delete mode 100644 dubbox/dubbox-examples/dubbox-discovery-example/pom.xml delete mode 100644 dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-consumer/pom.xml delete mode 100644 dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-consumer/src/main/java/com/tencent/polaris/dubbox/ratelimit/consumer/Application.java delete mode 100644 dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-consumer/src/main/java/com/tencent/polaris/dubbox/ratelimit/consumer/RatelimitAction.java delete mode 100644 dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-consumer/src/main/resources/META-INF/spring/ratelimit-demo-consumer.xml delete mode 100644 dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-consumer/src/main/resources/log4j.xml delete mode 100644 dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-example-api/pom.xml delete mode 100644 dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-example-api/src/main/java/com/tencent/polaris/dubbox/ratelimit/example/api/User.java delete mode 100644 dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-example-api/src/main/java/com/tencent/polaris/dubbox/ratelimit/example/api/UserService.java delete mode 100644 dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-provider/pom.xml delete mode 100644 dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-provider/src/main/java/com/tencent/polaris/dubbox/ratelimit/provider/Application.java delete mode 100644 dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-provider/src/main/java/com/tencent/polaris/dubbox/ratelimit/provider/UserServiceImpl.java delete mode 100644 dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-provider/src/main/resources/META-INF/spring/dubbox-ratelimit-provider.xml delete mode 100644 dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-provider/src/main/resources/log4j.xml delete mode 100644 dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-provider/src/main/webapp/WEB-INF/web.xml delete mode 100644 dubbox/dubbox-examples/dubbox-ratelimit-example/pom.xml delete mode 100644 dubbox/dubbox-examples/dubbox-router-example/dubbox-router-back/pom.xml delete mode 100644 dubbox/dubbox-examples/dubbox-router-example/dubbox-router-back/src/main/java/com/tencent/polaris/dubbox/router/back/Application.java delete mode 100644 dubbox/dubbox-examples/dubbox-router-example/dubbox-router-back/src/main/java/com/tencent/polaris/dubbox/router/back/BackServiceImpl.java delete mode 100644 dubbox/dubbox-examples/dubbox-router-example/dubbox-router-back/src/main/resources/META-INF/spring/dubbox-router-back.xml delete mode 100644 dubbox/dubbox-examples/dubbox-router-example/dubbox-router-back/src/main/resources/log4j.xml delete mode 100644 dubbox/dubbox-examples/dubbox-router-example/dubbox-router-back/src/main/webapp/WEB-INF/web.xml delete mode 100644 dubbox/dubbox-examples/dubbox-router-example/dubbox-router-example-api/pom.xml delete mode 100644 dubbox/dubbox-examples/dubbox-router-example/dubbox-router-example-api/src/main/java/com/tencent/polaris/dubbox/router/example/api/BackService.java delete mode 100644 dubbox/dubbox-examples/dubbox-router-example/dubbox-router-example-api/src/main/java/com/tencent/polaris/dubbox/router/example/api/FooResponse.java delete mode 100644 dubbox/dubbox-examples/dubbox-router-example/dubbox-router-example-api/src/main/java/com/tencent/polaris/dubbox/router/example/api/MiddleService.java delete mode 100644 dubbox/dubbox-examples/dubbox-router-example/dubbox-router-front/pom.xml delete mode 100644 dubbox/dubbox-examples/dubbox-router-example/dubbox-router-front/src/main/java/com/tencent/polaris/dubbox/router/front/FrontAction.java delete mode 100644 dubbox/dubbox-examples/dubbox-router-example/dubbox-router-front/src/main/java/com/tencent/polaris/dubbox/router/front/FrontService.java delete mode 100644 dubbox/dubbox-examples/dubbox-router-example/dubbox-router-front/src/main/resources/META-INF/spring/dubbox-router-front.xml delete mode 100644 dubbox/dubbox-examples/dubbox-router-example/dubbox-router-middle/pom.xml delete mode 100644 dubbox/dubbox-examples/dubbox-router-example/dubbox-router-middle/src/main/java/com/tencent/polaris/dubbox/router/middle/Application.java delete mode 100644 dubbox/dubbox-examples/dubbox-router-example/dubbox-router-middle/src/main/java/com/tencent/polaris/dubbox/router/middle/MiddleServiceImpl.java delete mode 100644 dubbox/dubbox-examples/dubbox-router-example/dubbox-router-middle/src/main/resources/META-INF/spring/dubbox-router-middle.xml delete mode 100644 dubbox/dubbox-examples/dubbox-router-example/dubbox-router-middle/src/main/resources/log4j.xml delete mode 100644 dubbox/dubbox-examples/dubbox-router-example/dubbox-router-middle/src/main/webapp/WEB-INF/web.xml delete mode 100644 dubbox/dubbox-examples/dubbox-router-example/pom.xml delete mode 100644 dubbox/dubbox-examples/pom.xml delete mode 100644 dubbox/dubbox-plugins/dubbox-circuitbreaker-polaris/pom.xml delete mode 100644 dubbox/dubbox-plugins/dubbox-circuitbreaker-polaris/src/main/java/com/tencent/polaris/dubbox/circuitbreaker/CircuitBreakerFilter.java delete mode 100644 dubbox/dubbox-plugins/dubbox-circuitbreaker-polaris/src/main/resources/META-INF/dubbo/com.alibaba.dubbo.rpc.Filter delete mode 100644 dubbox/dubbox-plugins/dubbox-ratelimit-polaris/pom.xml delete mode 100644 dubbox/dubbox-plugins/dubbox-ratelimit-polaris/src/main/java/com/tencent/polaris/dubbox/ratelimit/RateLimitFilter.java delete mode 100644 dubbox/dubbox-plugins/dubbox-ratelimit-polaris/src/main/resources/META-INF/dubbo/com.alibaba.dubbo.rpc.Filter delete mode 100644 dubbox/dubbox-plugins/dubbox-registry-polaris/pom.xml delete mode 100644 dubbox/dubbox-plugins/dubbox-registry-polaris/src/main/java/com/tencent/polaris/dubbox/registry/PolarisRegistry.java delete mode 100644 dubbox/dubbox-plugins/dubbox-registry-polaris/src/main/java/com/tencent/polaris/dubbox/report/ReportFilter.java delete mode 100644 dubbox/dubbox-plugins/dubbox-registry-polaris/src/main/resources/META-INF/dubbo/com.alibaba.dubbo.registry.RegistryFactory delete mode 100644 dubbox/dubbox-plugins/dubbox-registry-polaris/src/main/resources/META-INF/dubbo/com.alibaba.dubbo.rpc.Filter delete mode 100644 dubbox/dubbox-plugins/dubbox-router-polaris/pom.xml delete mode 100644 dubbox/dubbox-plugins/dubbox-router-polaris/src/main/java/com/tencent/polaris/dubbox/router/InstanceInvoker.java delete mode 100644 dubbox/dubbox-plugins/dubbox-router-polaris/src/main/java/com/tencent/polaris/dubbox/router/PolarisRouter.java delete mode 100644 dubbox/dubbox-plugins/dubbox-router-polaris/src/main/resources/META-INF/dubbo/com.alibaba.dubbo.rpc.cluster.RouterFactory delete mode 100644 dubbox/dubbox-plugins/pom.xml delete mode 100644 dubbox/pom.xml create mode 100644 polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/registry/DubboServiceInfo.java rename polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/{registry => utils}/Consts.java (78%) rename polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/{registry => utils}/ConvertUtils.java (95%) create mode 100644 polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/utils/DubboUtils.java delete mode 100644 polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/utils/ExampleConsts.java delete mode 100644 polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/utils/ExtensionConsts.java diff --git a/dubbo/dubbo-examples/dubbo-example-interface/pom.xml b/dubbo/dubbo-examples/dubbo-api-example/pom.xml similarity index 60% rename from dubbo/dubbo-examples/dubbo-example-interface/pom.xml rename to dubbo/dubbo-examples/dubbo-api-example/pom.xml index 9d6268a..19c0d18 100644 --- a/dubbo/dubbo-examples/dubbo-example-interface/pom.xml +++ b/dubbo/dubbo-examples/dubbo-api-example/pom.xml @@ -1,7 +1,7 @@ + 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-examples com.tencent.polaris @@ -9,8 +9,6 @@ ../pom.xml 4.0.0 - - dubbo-example-interface - + dubbo-api-example \ No newline at end of file diff --git a/dubbo/dubbo-examples/dubbo-example-interface/src/main/java/org/apache/dubbo/demo/RatelimitDemoService.java b/dubbo/dubbo-examples/dubbo-api-example/src/main/java/com/tencent/polaris/dubbo/example/api/GreetingService.java similarity index 83% rename from dubbo/dubbo-examples/dubbo-example-interface/src/main/java/org/apache/dubbo/demo/RatelimitDemoService.java rename to dubbo/dubbo-examples/dubbo-api-example/src/main/java/com/tencent/polaris/dubbo/example/api/GreetingService.java index 26029f9..779c7c6 100644 --- a/dubbo/dubbo-examples/dubbo-example-interface/src/main/java/org/apache/dubbo/demo/RatelimitDemoService.java +++ b/dubbo/dubbo-examples/dubbo-api-example/src/main/java/com/tencent/polaris/dubbo/example/api/GreetingService.java @@ -1,22 +1,26 @@ -/* - * Tencent is pleased to support the open source community by making Polaris available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * 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.demo; - -public interface RatelimitDemoService extends DemoService { - -} +/* + * Tencent is pleased to support the open source community by making Polaris available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * 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 com.tencent.polaris.dubbo.example.api; + +public interface GreetingService { + + String sayHello(String name); + + String sayHi(String name); + +} diff --git a/dubbo/dubbo-examples/dubbo-circuitbreak-example/dubbo-circuitbreak-consumer/pom.xml b/dubbo/dubbo-examples/dubbo-circuitbreak-example/dubbo-circuitbreak-consumer/pom.xml deleted file mode 100644 index 2ca72c6..0000000 --- a/dubbo/dubbo-examples/dubbo-circuitbreak-example/dubbo-circuitbreak-consumer/pom.xml +++ /dev/null @@ -1,100 +0,0 @@ - - - - dubbo-circuitbreak-example - com.tencent.polaris - ${revision} - ../pom.xml - - 4.0.0 - - dubbo-circuitbreak-consumer - - - - com.tencent.polaris - dubbo-example-interface - ${project.version} - - - org.apache.dubbo - dubbo-config-api - - - org.apache.dubbo - dubbo-rpc-dubbo - - - org.apache.dubbo - dubbo-remoting-netty4 - - - org.apache.dubbo - dubbo-serialization-hessian2 - - - - org.slf4j - slf4j-api - - - org.slf4j - slf4j-log4j12 - - - log4j - log4j - - - - com.tencent.polaris - dubbo-registry-polaris - ${project.version} - - - - com.tencent.polaris - dubbo-circuitbreaker-polaris - ${project.version} - - - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.0.0 - - - package - - shade - - - - - *:* - - META-INF/*.SF - META-INF/*.DSA - META-INF/*.RSA - - - - - - com.tencent.polaris.dubbo.circuitbreak.consumer.Application - - - - - - - - - - \ No newline at end of file diff --git a/dubbo/dubbo-examples/dubbo-circuitbreak-example/dubbo-circuitbreak-consumer/src/main/java/com/tencent/polaris/dubbo/circuitbreak/consumer/Application.java b/dubbo/dubbo-examples/dubbo-circuitbreak-example/dubbo-circuitbreak-consumer/src/main/java/com/tencent/polaris/dubbo/circuitbreak/consumer/Application.java deleted file mode 100644 index 65c4745..0000000 --- a/dubbo/dubbo-examples/dubbo-circuitbreak-example/dubbo-circuitbreak-consumer/src/main/java/com/tencent/polaris/dubbo/circuitbreak/consumer/Application.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Polaris available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * 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 com.tencent.polaris.dubbo.circuitbreak.consumer; - -import com.tencent.polaris.common.utils.ExampleConsts; -import org.apache.dubbo.common.constants.CommonConstants; -import org.apache.dubbo.config.ApplicationConfig; -import org.apache.dubbo.config.ConsumerConfig; -import org.apache.dubbo.config.ReferenceConfig; -import org.apache.dubbo.config.RegistryConfig; -import org.apache.dubbo.config.bootstrap.DubboBootstrap; -import org.apache.dubbo.config.utils.ReferenceConfigCache; -import org.apache.dubbo.demo.CircuitbreakDemoService; -import org.apache.dubbo.demo.DemoService; -import org.apache.dubbo.rpc.RpcContext; - -public class Application { - - public static void main(String[] args) { - ReferenceConfig reference = new ReferenceConfig<>(); - reference.setRegistry(new RegistryConfig(ExampleConsts.POLARIS_ADDRESS)); - reference.setInterface(CircuitbreakDemoService.class); - reference.setVersion(CommonConstants.ANY_VALUE); - reference.setRetries(0); - DubboBootstrap bootstrap = DubboBootstrap.getInstance() - .application(new ApplicationConfig("dubbo-circuitbreak-consumer-service")) - .registry(new RegistryConfig(ExampleConsts.POLARIS_ADDRESS)); - - bootstrap.consumer(builder -> { - builder.filter("polaris_report,polaris_circuitbreaker"); - }); - bootstrap.reference(reference).start(); - DemoService service = ReferenceConfigCache.getCache().get(reference); - - int i = 0; - for (;;) { - i ++; - long startTimeMilli = System.currentTimeMillis(); - sayHello(service); - long endTimeMilli = System.currentTimeMillis(); - System.out.printf("invoke %d, time consume %d%n", i, endTimeMilli - startTimeMilli); - } - } - - private static void sayHello(DemoService service) { - try { - String message = service.sayHello("hello"); - System.out.printf("message is %s%n", message); - } catch (Throwable e) { - System.out.printf("exception caught: %s%n", e.getMessage()); - } - } -} diff --git a/dubbo/dubbo-examples/dubbo-circuitbreak-example/dubbo-circuitbreak-consumer/src/main/resources/log4j.properties b/dubbo/dubbo-examples/dubbo-circuitbreak-example/dubbo-circuitbreak-consumer/src/main/resources/log4j.properties deleted file mode 100644 index 15a0900..0000000 --- a/dubbo/dubbo-examples/dubbo-circuitbreak-example/dubbo-circuitbreak-consumer/src/main/resources/log4j.properties +++ /dev/null @@ -1,7 +0,0 @@ -###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 \ No newline at end of file diff --git a/dubbo/dubbo-examples/dubbo-circuitbreak-example/dubbo-circuitbreak-provider/pom.xml b/dubbo/dubbo-examples/dubbo-circuitbreak-example/dubbo-circuitbreak-provider/pom.xml deleted file mode 100644 index f2bdc0e..0000000 --- a/dubbo/dubbo-examples/dubbo-circuitbreak-example/dubbo-circuitbreak-provider/pom.xml +++ /dev/null @@ -1,94 +0,0 @@ - - - - dubbo-circuitbreak-example - com.tencent.polaris - ${revision} - ../pom.xml - - 4.0.0 - - dubbo-circuitbreak-provider - - - - com.tencent.polaris - dubbo-example-interface - ${project.version} - - - org.apache.dubbo - dubbo-config-api - - - org.apache.dubbo - dubbo-rpc-dubbo - - - org.apache.dubbo - dubbo-remoting-netty4 - - - org.apache.dubbo - dubbo-serialization-hessian2 - - - - org.slf4j - slf4j-api - - - org.slf4j - slf4j-log4j12 - - - log4j - log4j - - - - com.tencent.polaris - dubbo-registry-polaris - ${project.version} - - - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.0.0 - - - package - - shade - - - - - *:* - - META-INF/*.SF - META-INF/*.DSA - META-INF/*.RSA - - - - - - com.tencent.polaris.dubbo.circuitbreak.provider.Application - - - - - - - - - - \ No newline at end of file diff --git a/dubbo/dubbo-examples/dubbo-circuitbreak-example/dubbo-circuitbreak-provider/src/main/java/com/tencent/polaris/dubbo/circuitbreak/provider/Application.java b/dubbo/dubbo-examples/dubbo-circuitbreak-example/dubbo-circuitbreak-provider/src/main/java/com/tencent/polaris/dubbo/circuitbreak/provider/Application.java deleted file mode 100644 index 86d1d49..0000000 --- a/dubbo/dubbo-examples/dubbo-circuitbreak-example/dubbo-circuitbreak-provider/src/main/java/com/tencent/polaris/dubbo/circuitbreak/provider/Application.java +++ /dev/null @@ -1,57 +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 com.tencent.polaris.dubbo.circuitbreak.provider; - -import com.tencent.polaris.common.utils.ExampleConsts; -import org.apache.dubbo.common.utils.StringUtils; -import org.apache.dubbo.config.ApplicationConfig; -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.demo.CircuitbreakDemoService; - -public class Application { - - public static void main(String[] args) { - startWithBootstrap(); - } - - private static void startWithBootstrap() { - ServiceConfig service = new ServiceConfig<>(); - service.setInterface(CircuitbreakDemoService.class); - service.setRef(new DemoServiceImpl()); - String portStr = System.getenv(ExampleConsts.ENV_KEY_PORT); - int port; - if (StringUtils.isBlank(portStr)) { - port = 10070; - } else { - port = Integer.parseInt(portStr); - } - ProtocolConfig protocolConfig = new ProtocolConfig(); - protocolConfig.setPort(port); - DubboBootstrap bootstrap = DubboBootstrap.getInstance(); - bootstrap.application(new ApplicationConfig("dubbo-circuitbreak-provider-service")) - .registry(new RegistryConfig(ExampleConsts.POLARIS_ADDRESS)) - .service(service) - .protocol(protocolConfig) - .start() - .await(); - } - -} diff --git a/dubbo/dubbo-examples/dubbo-circuitbreak-example/dubbo-circuitbreak-provider/src/main/java/com/tencent/polaris/dubbo/circuitbreak/provider/DemoServiceImpl.java b/dubbo/dubbo-examples/dubbo-circuitbreak-example/dubbo-circuitbreak-provider/src/main/java/com/tencent/polaris/dubbo/circuitbreak/provider/DemoServiceImpl.java deleted file mode 100644 index e781737..0000000 --- a/dubbo/dubbo-examples/dubbo-circuitbreak-example/dubbo-circuitbreak-provider/src/main/java/com/tencent/polaris/dubbo/circuitbreak/provider/DemoServiceImpl.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Polaris available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * 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 com.tencent.polaris.dubbo.circuitbreak.provider; - -import com.tencent.polaris.api.utils.StringUtils; -import com.tencent.polaris.common.utils.ExampleConsts; -import java.util.concurrent.atomic.AtomicInteger; -import org.apache.dubbo.demo.CircuitbreakDemoService; -import org.apache.dubbo.rpc.RpcContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class DemoServiceImpl implements CircuitbreakDemoService { - - private static final Logger logger = LoggerFactory.getLogger(DemoServiceImpl.class); - - private final boolean hasException; - - private final AtomicInteger count = new AtomicInteger(0); - - public DemoServiceImpl() { - String exception = System.getenv(ExampleConsts.ENV_KEY_EXCEPTION); - hasException = StringUtils.isNotBlank(exception); - } - - @Override - public String sayHello(String name) { - System.out.printf("invoke count %d, hasException %s%n", count.incrementAndGet(), hasException); - if (hasException) { - throw new RuntimeException("exception caught by testing"); - } - logger.info("[CB] Hello " + name + ", request from consumer: " + RpcContext.getContext().getRemoteAddress()); - return "[CB] Hello " + name + ", response from provider: " + RpcContext.getContext().getLocalAddress(); - } -} diff --git a/dubbo/dubbo-examples/dubbo-circuitbreak-example/dubbo-circuitbreak-provider/src/main/resources/log4j.properties b/dubbo/dubbo-examples/dubbo-circuitbreak-example/dubbo-circuitbreak-provider/src/main/resources/log4j.properties deleted file mode 100644 index 15a0900..0000000 --- a/dubbo/dubbo-examples/dubbo-circuitbreak-example/dubbo-circuitbreak-provider/src/main/resources/log4j.properties +++ /dev/null @@ -1,7 +0,0 @@ -###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 \ No newline at end of file diff --git a/dubbo/dubbo-examples/dubbo-circuitbreak-example/pom.xml b/dubbo/dubbo-examples/dubbo-circuitbreak-example/pom.xml deleted file mode 100644 index 9984460..0000000 --- a/dubbo/dubbo-examples/dubbo-circuitbreak-example/pom.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - dubbo-examples - com.tencent.polaris - ${revision} - ../pom.xml - - 4.0.0 - pom - dubbo-circuitbreak-example - - - dubbo-circuitbreak-provider - dubbo-circuitbreak-consumer - - \ No newline at end of file diff --git a/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-discovery-consumer/pom.xml b/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-discovery-consumer/pom.xml deleted file mode 100644 index 340c159..0000000 --- a/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-discovery-consumer/pom.xml +++ /dev/null @@ -1,94 +0,0 @@ - - - - dubbo-discovery-example - com.tencent.polaris - ${revision} - ../pom.xml - - 4.0.0 - - dubbo-discovery-consumer - - - - com.tencent.polaris - dubbo-example-interface - ${project.version} - - - org.apache.dubbo - dubbo-config-api - - - org.apache.dubbo - dubbo-rpc-dubbo - - - org.apache.dubbo - dubbo-remoting-netty4 - - - org.apache.dubbo - dubbo-serialization-hessian2 - - - - org.slf4j - slf4j-api - - - org.slf4j - slf4j-log4j12 - - - log4j - log4j - - - - com.tencent.polaris - dubbo-registry-polaris - ${project.version} - - - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.0.0 - - - package - - shade - - - - - *:* - - META-INF/*.SF - META-INF/*.DSA - META-INF/*.RSA - - - - - - com.tencent.polaris.dubbo.discovery.consumer.Application - - - - - - - - - - \ No newline at end of file diff --git a/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-discovery-consumer/src/main/java/com/tencent/polaris/dubbo/discovery/consumer/Application.java b/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-discovery-consumer/src/main/java/com/tencent/polaris/dubbo/discovery/consumer/Application.java deleted file mode 100644 index c3ee33f..0000000 --- a/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-discovery-consumer/src/main/java/com/tencent/polaris/dubbo/discovery/consumer/Application.java +++ /dev/null @@ -1,59 +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 com.tencent.polaris.dubbo.discovery.consumer; - -import com.tencent.polaris.common.utils.ExampleConsts; -import org.apache.dubbo.config.ApplicationConfig; -import org.apache.dubbo.config.ProtocolConfig; -import org.apache.dubbo.config.ReferenceConfig; -import org.apache.dubbo.config.RegistryConfig; -import org.apache.dubbo.config.bootstrap.DubboBootstrap; -import org.apache.dubbo.config.utils.ReferenceConfigCache; -import org.apache.dubbo.demo.DemoService; -import org.apache.dubbo.rpc.service.GenericService; - -public class Application { - - public static void main(String[] args) { - runWithBootstrap(); - } - - private static void runWithBootstrap() { - ReferenceConfig reference = new ReferenceConfig<>(); - reference.setInterface(DemoService.class); - reference.setGeneric("true"); - reference.setTimeout(10000); - - DubboBootstrap bootstrap = DubboBootstrap.getInstance(); - bootstrap.application(new ApplicationConfig("dubbo-demo-api-consumer")) - .registry(new RegistryConfig(ExampleConsts.POLARIS_ADDRESS)) - .reference(reference) - .start(); - - DemoService demoService = ReferenceConfigCache.getCache().get(reference); - String message = demoService.sayHello("dubbo"); - System.out.println(message); - - // generic invoke - GenericService genericService = (GenericService) demoService; - Object genericInvokeResult = genericService.$invoke("sayHello", new String[]{String.class.getName()}, - new Object[]{"dubbo generic invoke"}); - System.out.println(genericInvokeResult); - } - -} diff --git a/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-discovery-consumer/src/main/resources/log4j.properties b/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-discovery-consumer/src/main/resources/log4j.properties deleted file mode 100644 index 15a0900..0000000 --- a/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-discovery-consumer/src/main/resources/log4j.properties +++ /dev/null @@ -1,7 +0,0 @@ -###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 \ No newline at end of file diff --git a/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-discovery-provider/pom.xml b/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-discovery-provider/pom.xml deleted file mode 100644 index 28278d9..0000000 --- a/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-discovery-provider/pom.xml +++ /dev/null @@ -1,94 +0,0 @@ - - - - dubbo-discovery-example - com.tencent.polaris - ${revision} - ../pom.xml - - 4.0.0 - - dubbo-discovery-provider - - - - com.tencent.polaris - dubbo-example-interface - ${project.version} - - - org.apache.dubbo - dubbo-config-api - - - org.apache.dubbo - dubbo-rpc-dubbo - - - org.apache.dubbo - dubbo-remoting-netty4 - - - org.apache.dubbo - dubbo-serialization-hessian2 - - - - org.slf4j - slf4j-api - - - org.slf4j - slf4j-log4j12 - - - log4j - log4j - - - - com.tencent.polaris - dubbo-registry-polaris - ${project.version} - - - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.0.0 - - - package - - shade - - - - - *:* - - META-INF/*.SF - META-INF/*.DSA - META-INF/*.RSA - - - - - - com.tencent.polaris.dubbo.discovery.provider.Application - - - - - - - - - - \ No newline at end of file diff --git a/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-discovery-provider/src/main/java/com/tencent/polaris/dubbo/discovery/provider/Application.java b/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-discovery-provider/src/main/java/com/tencent/polaris/dubbo/discovery/provider/Application.java deleted file mode 100644 index 9786474..0000000 --- a/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-discovery-provider/src/main/java/com/tencent/polaris/dubbo/discovery/provider/Application.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 com.tencent.polaris.dubbo.discovery.provider; - -import com.tencent.polaris.common.utils.ExampleConsts; -import org.apache.dubbo.config.ApplicationConfig; -import org.apache.dubbo.config.RegistryConfig; -import org.apache.dubbo.config.ServiceConfig; -import org.apache.dubbo.config.bootstrap.DubboBootstrap; -import org.apache.dubbo.demo.DemoService; - -public class Application { - - public static void main(String[] args) throws Exception { - startWithBootstrap(); - } - - private static void startWithBootstrap() { - ServiceConfig service = new ServiceConfig<>(); - service.setInterface(DemoService.class); - service.setRef(new DemoServiceImpl()); - - DubboBootstrap bootstrap = DubboBootstrap.getInstance(); - bootstrap.application(new ApplicationConfig("dubbo-demo-api-provider")) - .registry(new RegistryConfig(ExampleConsts.POLARIS_ADDRESS)) - .service(service) - .start() - .await(); - } - -} diff --git a/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-discovery-provider/src/main/java/com/tencent/polaris/dubbo/discovery/provider/DemoServiceImpl.java b/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-discovery-provider/src/main/java/com/tencent/polaris/dubbo/discovery/provider/DemoServiceImpl.java deleted file mode 100644 index d1e9c2d..0000000 --- a/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-discovery-provider/src/main/java/com/tencent/polaris/dubbo/discovery/provider/DemoServiceImpl.java +++ /dev/null @@ -1,41 +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 com.tencent.polaris.dubbo.discovery.provider; - -import java.util.concurrent.CompletableFuture; -import org.apache.dubbo.demo.DemoService; -import org.apache.dubbo.rpc.RpcContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class DemoServiceImpl implements DemoService { - - private static final Logger logger = LoggerFactory.getLogger(DemoServiceImpl.class); - - @Override - public String sayHello(String name) { - logger.info("Hello " + name + ", request from consumer: " + RpcContext.getContext().getRemoteAddress()); - return "Hello " + name + ", response from provider: " + RpcContext.getContext().getLocalAddress(); - } - - @Override - public CompletableFuture sayHelloAsync(String name) { - return null; - } - -} diff --git a/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-discovery-provider/src/main/resources/log4j.properties b/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-discovery-provider/src/main/resources/log4j.properties deleted file mode 100644 index 15a0900..0000000 --- a/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-discovery-provider/src/main/resources/log4j.properties +++ /dev/null @@ -1,7 +0,0 @@ -###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 \ No newline at end of file diff --git a/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-quick-consumer/pom.xml b/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-quick-consumer/pom.xml new file mode 100644 index 0000000..fa9d2b0 --- /dev/null +++ b/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-quick-consumer/pom.xml @@ -0,0 +1,140 @@ + + + + dubbo-discovery-example + com.tencent.polaris + ${revision} + ../pom.xml + + 4.0.0 + + dubbo-quick-consumer + + + 1.8 + 1.8 + UTF-8 + + 3.2.6 + 4.3.30.RELEASE + 2.20.0 + 4.13.1 + 3.7.0 + + + + + + org.springframework + spring-framework-bom + ${spring.version} + pom + import + + + + org.apache.dubbo + dubbo-bom + ${dubbo.version} + pom + import + + + + junit + junit + ${junit.version} + + + + + + + org.apache.dubbo + dubbo + ${dubbo.version} + + + + com.tencent.polaris + dubbo-api-example + ${revision} + + + + com.tencent.polaris + dubbo-registry-polaris + ${revision} + + + + com.tencent.polaris + dubbo-metadatareport-polaris + ${revision} + + + + com.tencent.polaris + dubbo-configcenter-polaris + ${revision} + + + + org.apache.logging.log4j + log4j-slf4j-impl + ${log4j2.version} + + + + junit + junit + test + + + + org.springframework + spring-test + test + + + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.0.0 + + + package + + shade + + + + + *:* + + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + + + + + + com.tencent.polaris.dubbo.discovery.example.consumer.Main + + + + + + + + + + + \ No newline at end of file diff --git a/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-example-api/src/main/java/com/tencent/polaris/dubbox/router/example/api/FooRequest.java b/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-quick-consumer/src/main/java/com/tencent/polaris/dubbo/discovery/example/consumer/GreetingServiceConsumer.java similarity index 56% rename from dubbox/dubbox-examples/dubbox-router-example/dubbox-router-example-api/src/main/java/com/tencent/polaris/dubbox/router/example/api/FooRequest.java rename to dubbo/dubbo-examples/dubbo-discovery-example/dubbo-quick-consumer/src/main/java/com/tencent/polaris/dubbo/discovery/example/consumer/GreetingServiceConsumer.java index 9a53d5b..8525a46 100644 --- a/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-example-api/src/main/java/com/tencent/polaris/dubbox/router/example/api/FooRequest.java +++ b/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-quick-consumer/src/main/java/com/tencent/polaris/dubbo/discovery/example/consumer/GreetingServiceConsumer.java @@ -1,43 +1,38 @@ -/* - * Tencent is pleased to support the open source community by making Polaris available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * 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 com.tencent.polaris.dubbox.router.example.api; - -import java.io.Serializable; - -public class FooRequest implements Serializable { - - private String user; - - private String pwd; - - public String getUser() { - return user; - } - - public void setUser(String user) { - this.user = user; - } - - public String getPwd() { - return pwd; - } - - public void setPwd(String pwd) { - this.pwd = pwd; - } -} +/* + * Tencent is pleased to support the open source community by making Polaris available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * 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 com.tencent.polaris.dubbo.discovery.example.consumer; + +import com.tencent.polaris.dubbo.example.api.GreetingService; +import org.apache.dubbo.config.annotation.DubboReference; +import org.springframework.stereotype.Component; + +@Component("annotatedConsumer") +public class GreetingServiceConsumer { + + @DubboReference(version = "1.0.0") + private GreetingService greetingService; + + public String doSayHello(String name) { + return greetingService.sayHello(name); + } + + public String doSayHi(String name) { + return greetingService.sayHi(name); + } + +} \ No newline at end of file diff --git a/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-quick-consumer/src/main/java/com/tencent/polaris/dubbo/discovery/example/consumer/Main.java b/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-quick-consumer/src/main/java/com/tencent/polaris/dubbo/discovery/example/consumer/Main.java new file mode 100644 index 0000000..2bd536e --- /dev/null +++ b/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-quick-consumer/src/main/java/com/tencent/polaris/dubbo/discovery/example/consumer/Main.java @@ -0,0 +1,107 @@ +/* + * Tencent is pleased to support the open source community by making Polaris available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * 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 com.tencent.polaris.dubbo.discovery.example.consumer; + +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpHandler; +import com.sun.net.httpserver.HttpServer; +import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.UnsupportedEncodingException; +import java.net.InetSocketAddress; +import java.net.URI; +import java.net.URLDecoder; +import java.util.LinkedHashMap; +import java.util.Map; + +public class Main { + + private static final int LISTEN_PORT = 15700; + + private static final String PATH = "/echo"; + public static void main(String[] args) throws Exception { + AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class); + context.start(); + GreetingServiceConsumer greetingServiceConsumer = context.getBean(GreetingServiceConsumer.class); + System.out.println("please input name"); + + HttpServer server = HttpServer.create(new InetSocketAddress(LISTEN_PORT), 0); + server.createContext(PATH, new EchoClientHandler(greetingServiceConsumer)); + Runtime.getRuntime().addShutdownHook(new Thread(() -> { + server.stop(1); + })); + server.start(); + } + + private static class EchoClientHandler implements HttpHandler { + + private final GreetingServiceConsumer consumer; + + public EchoClientHandler(GreetingServiceConsumer consumer) { + this.consumer = consumer; + } + + @Override + public void handle(HttpExchange exchange) throws IOException { + Map parameters = splitQuery(exchange.getRequestURI()); + String echoValue = parameters.get("value"); + String method = parameters.get("method"); + String response = ""; + switch (method) { + case "sayHello": + response = consumer.doSayHello(echoValue); + break; + case "sayHi": + response = consumer.doSayHi(echoValue); + break; + } + exchange.sendResponseHeaders(200, 0); + OutputStream os = exchange.getResponseBody(); + os.write(response.getBytes()); + os.close(); + } + + private static Map splitQuery(URI uri) throws UnsupportedEncodingException { + Map query_pairs = new LinkedHashMap<>(); + String query = uri.getQuery(); + String[] pairs = query.split("&"); + for (String pair : pairs) { + int idx = pair.indexOf("="); + query_pairs.put(URLDecoder.decode(pair.substring(0, idx), "UTF-8"), + URLDecoder.decode(pair.substring(idx + 1), "UTF-8")); + } + return query_pairs; + } + + } + + + @Configuration + @EnableDubbo(scanBasePackages = "com.tencent.polaris.dubbo.discovery.example.consumer") + @PropertySource("classpath:/spring/dubbo-consumer.properties") + @ComponentScan(value = {"com.tencent.polaris.dubbo.discovery.example.consumer"}) + static class ConsumerConfiguration { + + } +} \ No newline at end of file diff --git a/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-quick-consumer/src/main/resources/log4j2.xml b/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-quick-consumer/src/main/resources/log4j2.xml new file mode 100644 index 0000000..226bc62 --- /dev/null +++ b/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-quick-consumer/src/main/resources/log4j2.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-quick-consumer/src/main/resources/spring/dubbo-consumer.properties b/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-quick-consumer/src/main/resources/spring/dubbo-consumer.properties new file mode 100644 index 0000000..38dcb62 --- /dev/null +++ b/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-quick-consumer/src/main/resources/spring/dubbo-consumer.properties @@ -0,0 +1,6 @@ +dubbo.application.name=polaris-discovery-demo-consumer +dubbo.application.register-mode=instance +dubbo.registry.address=polaris://127.0.0.1:8091?namespace=dubbo&token= +dubbo.consumer.timeout=3000 +dubbo.config-center.address=polaris://127.0.0.1:8093 +dubbo.metadata-report.address=polaris://127.0.0.1:8091?namespace=dubbo&token= \ No newline at end of file diff --git a/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-quick-provider/pom.xml b/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-quick-provider/pom.xml new file mode 100644 index 0000000..8ad3238 --- /dev/null +++ b/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-quick-provider/pom.xml @@ -0,0 +1,150 @@ + + + + dubbo-discovery-example + com.tencent.polaris + ${revision} + ../pom.xml + + 4.0.0 + + dubbo-quick-provider + + + 1.8 + 1.8 + UTF-8 + + 3.2.6 + 4.3.30.RELEASE + 2.20.0 + 4.13.1 + 3.7.0 + + + + + + org.springframework + spring-framework-bom + ${spring.version} + pom + import + + + + org.apache.dubbo + dubbo-bom + ${dubbo.version} + pom + import + + + + junit + junit + ${junit.version} + + + + + + + org.apache.dubbo + dubbo + ${dubbo.version} + + + + com.tencent.polaris + dubbo-api-example + ${revision} + + + + + com.tencent.polaris + dubbo-registry-polaris + ${revision} + + + + + com.tencent.polaris + dubbo-metadatareport-polaris + ${revision} + + + + + com.tencent.polaris + dubbo-configcenter-polaris + ${revision} + + + + + com.tencent.polaris + dubbo-ratelimit-polaris + ${revision} + + + + org.apache.logging.log4j + log4j-slf4j-impl + ${log4j2.version} + + + + junit + junit + test + + + + org.springframework + spring-test + test + + + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.0.0 + + + package + + shade + + + + + *:* + + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + + + + + + com.tencent.polaris.dubbo.discovery.example.provider.Main + + + + + + + + + + + \ No newline at end of file diff --git a/dubbo/dubbo-examples/dubbo-router-example/dubbo-router-back/src/main/java/com/tencent/polaris/dubbo/router/back/BackDemoServiceImpl.java b/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-quick-provider/src/main/java/com/tencent/polaris/dubbo/discovery/example/provider/AnnotatedGreetingService.java similarity index 66% rename from dubbo/dubbo-examples/dubbo-router-example/dubbo-router-back/src/main/java/com/tencent/polaris/dubbo/router/back/BackDemoServiceImpl.java rename to dubbo/dubbo-examples/dubbo-discovery-example/dubbo-quick-provider/src/main/java/com/tencent/polaris/dubbo/discovery/example/provider/AnnotatedGreetingService.java index a1f4714..dcfa2f8 100644 --- a/dubbo/dubbo-examples/dubbo-router-example/dubbo-router-back/src/main/java/com/tencent/polaris/dubbo/router/back/BackDemoServiceImpl.java +++ b/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-quick-provider/src/main/java/com/tencent/polaris/dubbo/discovery/example/provider/AnnotatedGreetingService.java @@ -1,34 +1,35 @@ -/* - * Tencent is pleased to support the open source community by making Polaris available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * 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 com.tencent.polaris.dubbo.router.back; - -import org.apache.dubbo.demo.NextService; - -public class BackDemoServiceImpl implements NextService { - - private final String version; - - public BackDemoServiceImpl(String version) { - this.version = version; - } - - @Override - public String sayHello(String name) { - return String.format("back.%s[%s]", name, version); - } -} +/* + * Tencent is pleased to support the open source community by making Polaris available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * 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 com.tencent.polaris.dubbo.discovery.example.provider; + +import com.tencent.polaris.dubbo.example.api.GreetingService; +import org.apache.dubbo.config.annotation.DubboService; + +@DubboService(version = "1.0.0") +public class AnnotatedGreetingService implements GreetingService { + + public String sayHello(String name) { + return "hello, " + name; + } + + @Override + public String sayHi(String name) { + return "[provider by polaris] hi, " + name; + } + +} \ No newline at end of file diff --git a/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-quick-provider/src/main/java/com/tencent/polaris/dubbo/discovery/example/provider/Main.java b/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-quick-provider/src/main/java/com/tencent/polaris/dubbo/discovery/example/provider/Main.java new file mode 100644 index 0000000..fedabac --- /dev/null +++ b/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-quick-provider/src/main/java/com/tencent/polaris/dubbo/discovery/example/provider/Main.java @@ -0,0 +1,43 @@ +/* + * Tencent is pleased to support the open source community by making Polaris available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * 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 com.tencent.polaris.dubbo.discovery.example.provider; + +import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; + +import java.util.concurrent.CountDownLatch; + +public class Main { + public static void main(String[] args) throws Exception { + AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class); + context.start(); + System.out.println("dubbo service started"); + new CountDownLatch(1).await(); + } + + @Configuration + @EnableDubbo(scanBasePackages = "com.tencent.polaris.dubbo.discovery.example.provider") + @PropertySource("classpath:/spring/dubbo-provider.properties") + @ComponentScan(value = {"com.tencent.polaris.dubbo.discovery.example.provider"}) + static class ConsumerConfiguration { + + } +} \ No newline at end of file diff --git a/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-quick-provider/src/main/resources/log4j2.xml b/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-quick-provider/src/main/resources/log4j2.xml new file mode 100644 index 0000000..226bc62 --- /dev/null +++ b/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-quick-provider/src/main/resources/log4j2.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-quick-provider/src/main/resources/spring/dubbo-provider.properties b/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-quick-provider/src/main/resources/spring/dubbo-provider.properties new file mode 100644 index 0000000..6c8eaf2 --- /dev/null +++ b/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-quick-provider/src/main/resources/spring/dubbo-provider.properties @@ -0,0 +1,19 @@ +# ???? +dubbo.application.name=polaris-discovery-demo-provider +# dubbo ??????????????? +# dubbo intstance +# dubbo interface +# dubbo all?instance + interface? +dubbo.application.register-mode=instance +# ?????? +dubbo.registry.address=polaris://127.0.0.1:8091?namespace=dubbo&token=${??/????token} +dubbo.protocol.name=dubbo +dubbo.protocol.port=20880 +dubbo.provider.token=true +# dubbo ???? +dubbo.config-center.address=polaris://127.0.0.1:8093 +# dubbo ????? +dubbo.metadata-report.address=polaris://127.0.0.1:8091?namespace=dubbo&token= + +# +dubbo.provider.filter=polaris_ratelimit diff --git a/dubbo/dubbo-examples/dubbo-discovery-example/pom.xml b/dubbo/dubbo-examples/dubbo-discovery-example/pom.xml index 920fc86..4b7de40 100644 --- a/dubbo/dubbo-examples/dubbo-discovery-example/pom.xml +++ b/dubbo/dubbo-examples/dubbo-discovery-example/pom.xml @@ -1,7 +1,7 @@ + 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-examples com.tencent.polaris @@ -9,12 +9,13 @@ ../pom.xml 4.0.0 - dubbo-discovery-example pom + - dubbo-discovery-provider - dubbo-discovery-consumer + dubbo-quick-provider + dubbo-quick-consumer + \ No newline at end of file diff --git a/dubbo/dubbo-examples/dubbo-example-interface/src/main/java/org/apache/dubbo/demo/CircuitbreakDemoService.java b/dubbo/dubbo-examples/dubbo-example-interface/src/main/java/org/apache/dubbo/demo/CircuitbreakDemoService.java deleted file mode 100644 index fbb3211..0000000 --- a/dubbo/dubbo-examples/dubbo-example-interface/src/main/java/org/apache/dubbo/demo/CircuitbreakDemoService.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Polaris available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * 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.demo; - -public interface CircuitbreakDemoService extends DemoService { - -} diff --git a/dubbo/dubbo-examples/dubbo-example-interface/src/main/java/org/apache/dubbo/demo/DemoService.java b/dubbo/dubbo-examples/dubbo-example-interface/src/main/java/org/apache/dubbo/demo/DemoService.java deleted file mode 100644 index 32337ac..0000000 --- a/dubbo/dubbo-examples/dubbo-example-interface/src/main/java/org/apache/dubbo/demo/DemoService.java +++ /dev/null @@ -1,29 +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.demo; - -import java.util.concurrent.CompletableFuture; - -public interface DemoService { - - String sayHello(String name); - - default CompletableFuture sayHelloAsync(String name) { - return CompletableFuture.completedFuture(sayHello(name)); - } - -} \ No newline at end of file diff --git a/dubbo/dubbo-examples/dubbo-example-interface/src/main/java/org/apache/dubbo/demo/GreetingService.java b/dubbo/dubbo-examples/dubbo-example-interface/src/main/java/org/apache/dubbo/demo/GreetingService.java deleted file mode 100644 index 38c7a60..0000000 --- a/dubbo/dubbo-examples/dubbo-example-interface/src/main/java/org/apache/dubbo/demo/GreetingService.java +++ /dev/null @@ -1,24 +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.demo; - -/** - * - */ -public interface GreetingService { - String hello(); -} diff --git a/dubbo/dubbo-examples/dubbo-example-interface/src/main/java/org/apache/dubbo/demo/NextService.java b/dubbo/dubbo-examples/dubbo-example-interface/src/main/java/org/apache/dubbo/demo/NextService.java deleted file mode 100644 index cc5e120..0000000 --- a/dubbo/dubbo-examples/dubbo-example-interface/src/main/java/org/apache/dubbo/demo/NextService.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Polaris available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * 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.demo; - -public interface NextService extends DemoService { - -} diff --git a/dubbo/dubbo-examples/dubbo-ratelimit-example/dubbo-ratelimit-consumer/pom.xml b/dubbo/dubbo-examples/dubbo-ratelimit-example/dubbo-ratelimit-consumer/pom.xml deleted file mode 100644 index a4eb79b..0000000 --- a/dubbo/dubbo-examples/dubbo-ratelimit-example/dubbo-ratelimit-consumer/pom.xml +++ /dev/null @@ -1,94 +0,0 @@ - - - - dubbo-ratelimit-example - com.tencent.polaris - ${revision} - ../pom.xml - - 4.0.0 - - dubbo-ratelimit-consumer - - - - com.tencent.polaris - dubbo-example-interface - ${project.version} - - - org.apache.dubbo - dubbo-config-api - - - org.apache.dubbo - dubbo-rpc-dubbo - - - org.apache.dubbo - dubbo-remoting-netty4 - - - org.apache.dubbo - dubbo-serialization-hessian2 - - - - org.slf4j - slf4j-api - - - org.slf4j - slf4j-log4j12 - - - log4j - log4j - - - - com.tencent.polaris - dubbo-registry-polaris - ${project.version} - - - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.0.0 - - - package - - shade - - - - - *:* - - META-INF/*.SF - META-INF/*.DSA - META-INF/*.RSA - - - - - - com.tencent.polaris.dubbo.ratelimit.consumer.Application - - - - - - - - - - \ No newline at end of file diff --git a/dubbo/dubbo-examples/dubbo-ratelimit-example/dubbo-ratelimit-consumer/src/main/java/com/tencent/polaris/dubbo/ratelimit/consumer/Application.java b/dubbo/dubbo-examples/dubbo-ratelimit-example/dubbo-ratelimit-consumer/src/main/java/com/tencent/polaris/dubbo/ratelimit/consumer/Application.java deleted file mode 100644 index 5f6b643..0000000 --- a/dubbo/dubbo-examples/dubbo-ratelimit-example/dubbo-ratelimit-consumer/src/main/java/com/tencent/polaris/dubbo/ratelimit/consumer/Application.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Polaris available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * 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 com.tencent.polaris.dubbo.ratelimit.consumer; - -import com.tencent.polaris.common.utils.ExampleConsts; -import org.apache.dubbo.common.constants.CommonConstants; -import org.apache.dubbo.config.ApplicationConfig; -import org.apache.dubbo.config.ReferenceConfig; -import org.apache.dubbo.config.RegistryConfig; -import org.apache.dubbo.config.bootstrap.DubboBootstrap; -import org.apache.dubbo.config.utils.ReferenceConfigCache; -import org.apache.dubbo.demo.RatelimitDemoService; -import org.apache.dubbo.rpc.RpcContext; -import org.apache.dubbo.rpc.RpcException; - -public class Application { - - public static void main(String[] args) { - ReferenceConfig reference = new ReferenceConfig<>(); - reference.setRegistry(new RegistryConfig(ExampleConsts.POLARIS_ADDRESS)); - reference.setInterface(RatelimitDemoService.class); - reference.setVersion(CommonConstants.ANY_VALUE); - reference.setRetries(0); - DubboBootstrap bootstrap = DubboBootstrap.getInstance() - .application(new ApplicationConfig("dubbo-ratelimit-service")) - .registry(new RegistryConfig(ExampleConsts.POLARIS_ADDRESS)); - bootstrap.reference(reference).start(); - RatelimitDemoService service = ReferenceConfigCache.getCache().get(reference); - - System.out.println("start to invoke archer"); - int pass = 0; - int block = 0; - for (int i = 0; i < 600; i++) { - if (sayHello(service, "archer")) { - if (block > 0) { - System.out.printf("archer blocked %d%n", block); - block = 0; - } - pass++; - } else { - if (pass > 0) { - System.out.printf("archer passed %d%n", pass); - pass = 0; - } - block++; - } - try { - Thread.sleep(1); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - try { - Thread.sleep(2000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - System.out.println("start to invoke tommy"); - pass = 0; - block = 0; - for (int i = 0; i < 600; i++) { - if (sayHello(service, "tommy")) { - pass++; - } else { - block++; - } - } - System.out.printf("tommy passed %d, blocked %d%n", pass, block); - } - - private static boolean sayHello(RatelimitDemoService service, String userName) { - RpcContext.getContext().setAttachment("user", userName); - try { - service.sayHello("hello"); - } catch (Exception e) { - if (e instanceof RpcException) { - System.out.println("block exception " + e.getMessage()); - return false; - } - throw e; - } - return true; - } -} diff --git a/dubbo/dubbo-examples/dubbo-ratelimit-example/dubbo-ratelimit-consumer/src/main/resources/log4j.properties b/dubbo/dubbo-examples/dubbo-ratelimit-example/dubbo-ratelimit-consumer/src/main/resources/log4j.properties deleted file mode 100644 index 15a0900..0000000 --- a/dubbo/dubbo-examples/dubbo-ratelimit-example/dubbo-ratelimit-consumer/src/main/resources/log4j.properties +++ /dev/null @@ -1,7 +0,0 @@ -###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 \ No newline at end of file diff --git a/dubbo/dubbo-examples/dubbo-ratelimit-example/dubbo-ratelimit-provider/pom.xml b/dubbo/dubbo-examples/dubbo-ratelimit-example/dubbo-ratelimit-provider/pom.xml deleted file mode 100644 index 85b1eb5..0000000 --- a/dubbo/dubbo-examples/dubbo-ratelimit-example/dubbo-ratelimit-provider/pom.xml +++ /dev/null @@ -1,100 +0,0 @@ - - - - dubbo-ratelimit-example - com.tencent.polaris - ${revision} - ../pom.xml - - 4.0.0 - - dubbo-ratelimit-provider - - - - com.tencent.polaris - dubbo-example-interface - ${project.version} - - - org.apache.dubbo - dubbo-config-api - - - org.apache.dubbo - dubbo-rpc-dubbo - - - org.apache.dubbo - dubbo-remoting-netty4 - - - org.apache.dubbo - dubbo-serialization-hessian2 - - - - org.slf4j - slf4j-api - - - org.slf4j - slf4j-log4j12 - - - log4j - log4j - - - - com.tencent.polaris - dubbo-registry-polaris - ${project.version} - - - - com.tencent.polaris - dubbo-ratelimit-polaris - ${project.version} - - - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.0.0 - - - package - - shade - - - - - *:* - - META-INF/*.SF - META-INF/*.DSA - META-INF/*.RSA - - - - - - com.tencent.polaris.dubbo.ratelimit.provider.Application - - - - - - - - - - \ No newline at end of file diff --git a/dubbo/dubbo-examples/dubbo-ratelimit-example/dubbo-ratelimit-provider/src/main/java/com/tencent/polaris/dubbo/ratelimit/provider/Application.java b/dubbo/dubbo-examples/dubbo-ratelimit-example/dubbo-ratelimit-provider/src/main/java/com/tencent/polaris/dubbo/ratelimit/provider/Application.java deleted file mode 100644 index 801afc3..0000000 --- a/dubbo/dubbo-examples/dubbo-ratelimit-example/dubbo-ratelimit-provider/src/main/java/com/tencent/polaris/dubbo/ratelimit/provider/Application.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Polaris available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * 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 com.tencent.polaris.dubbo.ratelimit.provider; - -import com.tencent.polaris.common.utils.ExampleConsts; -import org.apache.dubbo.common.utils.StringUtils; -import org.apache.dubbo.config.ApplicationConfig; -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.demo.RatelimitDemoService; - -public class Application { - - public static void main(String[] args) { - startWithExport(); - } - - private static void startWithExport() { - DubboBootstrap bootstrap = DubboBootstrap.getInstance() - .application(new ApplicationConfig("dubbo-ratelimit-provider")) - .registry(new RegistryConfig(ExampleConsts.POLARIS_ADDRESS)); - - ServiceConfig service = new ServiceConfig<>(); - service.setInterface(RatelimitDemoService.class); - service.setRef(new RatelimitDemoServiceImpl()); - ProtocolConfig protocolConfig = new ProtocolConfig(); - String portStr = System.getenv(ExampleConsts.ENV_KEY_PORT); - int port; - if (StringUtils.isBlank(portStr)) { - port = 10070; - } else { - port = Integer.parseInt(portStr); - } - protocolConfig.setPort(port); - System.out.println("dubbo ratelimit service started"); - bootstrap.service(service).protocol(protocolConfig).start().await(); - } -} diff --git a/dubbo/dubbo-examples/dubbo-ratelimit-example/dubbo-ratelimit-provider/src/main/java/com/tencent/polaris/dubbo/ratelimit/provider/RatelimitDemoServiceImpl.java b/dubbo/dubbo-examples/dubbo-ratelimit-example/dubbo-ratelimit-provider/src/main/java/com/tencent/polaris/dubbo/ratelimit/provider/RatelimitDemoServiceImpl.java deleted file mode 100644 index 9e38d91..0000000 --- a/dubbo/dubbo-examples/dubbo-ratelimit-example/dubbo-ratelimit-provider/src/main/java/com/tencent/polaris/dubbo/ratelimit/provider/RatelimitDemoServiceImpl.java +++ /dev/null @@ -1,41 +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 com.tencent.polaris.dubbo.ratelimit.provider; - -import java.util.concurrent.CompletableFuture; -import org.apache.dubbo.demo.RatelimitDemoService; -import org.apache.dubbo.rpc.RpcContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class RatelimitDemoServiceImpl implements RatelimitDemoService { - - private static final Logger logger = LoggerFactory.getLogger(RatelimitDemoServiceImpl.class); - - @Override - public String sayHello(String name) { - logger.info("Hello " + name + ", request from consumer: " + RpcContext.getContext().getRemoteAddress()); - return "Hello " + name + ", response from provider: " + RpcContext.getContext().getLocalAddress(); - } - - @Override - public CompletableFuture sayHelloAsync(String name) { - return null; - } - -} diff --git a/dubbo/dubbo-examples/dubbo-ratelimit-example/dubbo-ratelimit-provider/src/main/resources/log4j.properties b/dubbo/dubbo-examples/dubbo-ratelimit-example/dubbo-ratelimit-provider/src/main/resources/log4j.properties deleted file mode 100644 index 15a0900..0000000 --- a/dubbo/dubbo-examples/dubbo-ratelimit-example/dubbo-ratelimit-provider/src/main/resources/log4j.properties +++ /dev/null @@ -1,7 +0,0 @@ -###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 \ No newline at end of file diff --git a/dubbo/dubbo-examples/dubbo-ratelimit-example/pom.xml b/dubbo/dubbo-examples/dubbo-ratelimit-example/pom.xml deleted file mode 100644 index e37801e..0000000 --- a/dubbo/dubbo-examples/dubbo-ratelimit-example/pom.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - dubbo-examples - com.tencent.polaris - ${revision} - ../pom.xml - - 4.0.0 - - dubbo-ratelimit-example - pom - - dubbo-ratelimit-provider - dubbo-ratelimit-consumer - - - \ No newline at end of file diff --git a/dubbo/dubbo-examples/dubbo-router-example/dubbo-router-back/pom.xml b/dubbo/dubbo-examples/dubbo-router-example/dubbo-router-back/pom.xml deleted file mode 100644 index 5937c87..0000000 --- a/dubbo/dubbo-examples/dubbo-router-example/dubbo-router-back/pom.xml +++ /dev/null @@ -1,94 +0,0 @@ - - - - dubbo-router-example - com.tencent.polaris - ${revision} - ../pom.xml - - 4.0.0 - - dubbo-router-back - - - - com.tencent.polaris - dubbo-example-interface - ${project.version} - - - org.apache.dubbo - dubbo-config-api - - - org.apache.dubbo - dubbo-rpc-dubbo - - - org.apache.dubbo - dubbo-remoting-netty4 - - - org.apache.dubbo - dubbo-serialization-hessian2 - - - - org.slf4j - slf4j-api - - - org.slf4j - slf4j-log4j12 - - - log4j - log4j - - - - com.tencent.polaris - dubbo-registry-polaris - ${project.version} - - - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.0.0 - - - package - - shade - - - - - *:* - - META-INF/*.SF - META-INF/*.DSA - META-INF/*.RSA - - - - - - com.tencent.polaris.dubbo.router.back.Application - - - - - - - - - - \ No newline at end of file diff --git a/dubbo/dubbo-examples/dubbo-router-example/dubbo-router-back/src/main/java/com/tencent/polaris/dubbo/router/back/Application.java b/dubbo/dubbo-examples/dubbo-router-example/dubbo-router-back/src/main/java/com/tencent/polaris/dubbo/router/back/Application.java deleted file mode 100644 index 4b5747c..0000000 --- a/dubbo/dubbo-examples/dubbo-router-example/dubbo-router-back/src/main/java/com/tencent/polaris/dubbo/router/back/Application.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Polaris available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * 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 com.tencent.polaris.dubbo.router.back; - -import com.tencent.polaris.common.utils.ExampleConsts; -import org.apache.dubbo.common.constants.CommonConstants; -import org.apache.dubbo.common.utils.CollectionUtils; -import org.apache.dubbo.common.utils.StringUtils; -import org.apache.dubbo.config.ApplicationConfig; -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.demo.NextService; - -public class Application { - - public static void main(String[] args) { - startWithExport(); - } - - private static void startWithExport() { - String version = System.getenv(ExampleConsts.ENV_KEY_VERSION); - ServiceConfig service = new ServiceConfig<>(); - service.setInterface(NextService.class); - service.setRef(new BackDemoServiceImpl(version)); - service.setParameters(CollectionUtils.toStringMap(CommonConstants.VERSION_KEY, version)); - - System.out.println("dubbo back service started"); - RegistryConfig registryConfig = new RegistryConfig(ExampleConsts.POLARIS_ADDRESS); - ProtocolConfig protocolConfig = new ProtocolConfig(); - String portStr = System.getenv(ExampleConsts.ENV_KEY_PORT); - int port; - if (StringUtils.isBlank(portStr)) { - port = 10060; - } else { - port = Integer.parseInt(portStr); - } - protocolConfig.setPort(port); - DubboBootstrap bootstrap = DubboBootstrap.getInstance(); - bootstrap.application(new ApplicationConfig("dubbo-router-back-service")) - .registry(registryConfig) - .service(service) - .protocol(protocolConfig) - .start() - .await(); - - } -} diff --git a/dubbo/dubbo-examples/dubbo-router-example/dubbo-router-front/pom.xml b/dubbo/dubbo-examples/dubbo-router-example/dubbo-router-front/pom.xml deleted file mode 100644 index ee897ec..0000000 --- a/dubbo/dubbo-examples/dubbo-router-example/dubbo-router-front/pom.xml +++ /dev/null @@ -1,100 +0,0 @@ - - - - dubbo-router-example - com.tencent.polaris - ${revision} - ../pom.xml - - 4.0.0 - - dubbo-router-front - - - - com.tencent.polaris - dubbo-example-interface - ${project.version} - - - org.apache.dubbo - dubbo-config-api - - - org.apache.dubbo - dubbo-rpc-dubbo - - - org.apache.dubbo - dubbo-remoting-netty4 - - - org.apache.dubbo - dubbo-serialization-hessian2 - - - - org.slf4j - slf4j-api - - - org.slf4j - slf4j-log4j12 - - - log4j - log4j - - - - com.tencent.polaris - dubbo-registry-polaris - ${project.version} - - - - com.tencent.polaris - dubbo-router-polaris - ${project.version} - - - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.0.0 - - - package - - shade - - - - - *:* - - META-INF/*.SF - META-INF/*.DSA - META-INF/*.RSA - - - - - - com.tencent.polaris.dubbo.router.front.Application - - - - - - - - - - \ No newline at end of file diff --git a/dubbo/dubbo-examples/dubbo-router-example/dubbo-router-front/src/main/java/com/tencent/polaris/dubbo/router/front/Application.java b/dubbo/dubbo-examples/dubbo-router-example/dubbo-router-front/src/main/java/com/tencent/polaris/dubbo/router/front/Application.java deleted file mode 100644 index f4094b3..0000000 --- a/dubbo/dubbo-examples/dubbo-router-example/dubbo-router-front/src/main/java/com/tencent/polaris/dubbo/router/front/Application.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Polaris available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * 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 com.tencent.polaris.dubbo.router.front; - -import com.tencent.polaris.common.utils.ExampleConsts; -import org.apache.dubbo.common.constants.CommonConstants; -import org.apache.dubbo.config.ApplicationConfig; -import org.apache.dubbo.config.ReferenceConfig; -import org.apache.dubbo.config.RegistryConfig; -import org.apache.dubbo.config.bootstrap.DubboBootstrap; -import org.apache.dubbo.config.utils.ReferenceConfigCache; -import org.apache.dubbo.demo.DemoService; -import org.apache.dubbo.rpc.RpcContext; - -public class Application { - - public static void main(String[] args) { - ReferenceConfig reference = new ReferenceConfig<>(); - reference.setRegistry(new RegistryConfig(ExampleConsts.POLARIS_ADDRESS)); - reference.setInterface(DemoService.class); - reference.setVersion(CommonConstants.ANY_VALUE); - reference.setRouter("polaris_router"); - DubboBootstrap bootstrap = DubboBootstrap.getInstance() - .application(new ApplicationConfig("dubbo-router-front-service")) - .registry(new RegistryConfig(ExampleConsts.POLARIS_ADDRESS)); - bootstrap.consumer(consumerBuilder -> { - }); - bootstrap.reference(reference).start(); - DemoService service = ReferenceConfigCache.getCache().get(reference); - - for (int i = 0; i < 10; i++) { - sayHello(service, "archer"); - } - for (int i = 0; i < 10; i++) { - sayHello(service, "tommy"); - } - } - - private static void sayHello(DemoService service, String userName) { - RpcContext.getContext().setAttachment("user", userName); - String message = service.sayHello("hello"); - System.out.printf("message from %s is %s%n", userName, message); - } -} diff --git a/dubbo/dubbo-examples/dubbo-router-example/dubbo-router-front/src/main/resources/log4j.xml b/dubbo/dubbo-examples/dubbo-router-example/dubbo-router-front/src/main/resources/log4j.xml deleted file mode 100644 index 24e120f..0000000 --- a/dubbo/dubbo-examples/dubbo-router-example/dubbo-router-front/src/main/resources/log4j.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/dubbo/dubbo-examples/dubbo-router-example/dubbo-router-middle/pom.xml b/dubbo/dubbo-examples/dubbo-router-example/dubbo-router-middle/pom.xml deleted file mode 100644 index 8c6cc85..0000000 --- a/dubbo/dubbo-examples/dubbo-router-example/dubbo-router-middle/pom.xml +++ /dev/null @@ -1,100 +0,0 @@ - - - - dubbo-router-example - com.tencent.polaris - ${revision} - ../pom.xml - - 4.0.0 - - dubbo-router-middle - - - - com.tencent.polaris - dubbo-example-interface - ${project.version} - - - org.apache.dubbo - dubbo-config-api - - - org.apache.dubbo - dubbo-rpc-dubbo - - - org.apache.dubbo - dubbo-remoting-netty4 - - - org.apache.dubbo - dubbo-serialization-hessian2 - - - - org.slf4j - slf4j-api - - - org.slf4j - slf4j-log4j12 - - - log4j - log4j - - - - com.tencent.polaris - dubbo-registry-polaris - ${project.version} - - - - com.tencent.polaris - dubbo-router-polaris - ${project.version} - - - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.0.0 - - - package - - shade - - - - - *:* - - META-INF/*.SF - META-INF/*.DSA - META-INF/*.RSA - - - - - - com.tencent.polaris.dubbo.router.middle.Application - - - - - - - - - - \ No newline at end of file diff --git a/dubbo/dubbo-examples/dubbo-router-example/dubbo-router-middle/src/main/java/com/tencent/polaris/dubbo/router/middle/Application.java b/dubbo/dubbo-examples/dubbo-router-example/dubbo-router-middle/src/main/java/com/tencent/polaris/dubbo/router/middle/Application.java deleted file mode 100644 index c2cc335..0000000 --- a/dubbo/dubbo-examples/dubbo-router-example/dubbo-router-middle/src/main/java/com/tencent/polaris/dubbo/router/middle/Application.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Polaris available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * 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 com.tencent.polaris.dubbo.router.middle; - -import com.tencent.polaris.common.utils.ExampleConsts; -import org.apache.dubbo.common.constants.CommonConstants; -import org.apache.dubbo.common.utils.CollectionUtils; -import org.apache.dubbo.common.utils.StringUtils; -import org.apache.dubbo.config.ApplicationConfig; -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.demo.DemoService; - -public class Application { - - public static void main(String[] args) { - startWithExport(); - } - - private static void startWithExport() { - String version = System.getenv(ExampleConsts.ENV_KEY_VERSION); - DubboBootstrap bootstrap = DubboBootstrap.getInstance() - .application(new ApplicationConfig("dubbo-router-middle-service")) - .registry(new RegistryConfig(ExampleConsts.POLARIS_ADDRESS)); - - ServiceConfig service = new ServiceConfig<>(); - service.setInterface(DemoService.class); - service.setRef(new MiddleDemoServiceImpl(version, bootstrap)); - service.setParameters(CollectionUtils.toStringMap(CommonConstants.VERSION_KEY, version)); - ProtocolConfig protocolConfig = new ProtocolConfig(); - String portStr = System.getenv(ExampleConsts.ENV_KEY_PORT); - int port; - if (StringUtils.isBlank(portStr)) { - port = 10050; - } else { - port = Integer.parseInt(portStr); - } - protocolConfig.setPort(port); - System.out.println("dubbo middle service started"); - bootstrap.service(service).protocol(protocolConfig).start().await(); - } -} diff --git a/dubbo/dubbo-examples/dubbo-router-example/dubbo-router-middle/src/main/java/com/tencent/polaris/dubbo/router/middle/MiddleDemoServiceImpl.java b/dubbo/dubbo-examples/dubbo-router-example/dubbo-router-middle/src/main/java/com/tencent/polaris/dubbo/router/middle/MiddleDemoServiceImpl.java deleted file mode 100644 index 66fb6c7..0000000 --- a/dubbo/dubbo-examples/dubbo-router-example/dubbo-router-middle/src/main/java/com/tencent/polaris/dubbo/router/middle/MiddleDemoServiceImpl.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Polaris available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * 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 com.tencent.polaris.dubbo.router.middle; - -import com.tencent.polaris.common.utils.ExampleConsts; -import org.apache.dubbo.common.constants.CommonConstants; -import org.apache.dubbo.config.ReferenceConfig; -import org.apache.dubbo.config.RegistryConfig; -import org.apache.dubbo.config.bootstrap.DubboBootstrap; -import org.apache.dubbo.config.utils.ReferenceConfigCache; -import org.apache.dubbo.demo.DemoService; -import org.apache.dubbo.demo.NextService; - -public class MiddleDemoServiceImpl implements DemoService { - - private final String version; - - private NextService nextService; - - private final DubboBootstrap bootstrap; - - public MiddleDemoServiceImpl(String version, DubboBootstrap bootstrap) { - this.version = version; - this.bootstrap = bootstrap; - } - - private NextService getNextService() { - if (null != nextService) { - return nextService; - } - synchronized (this) { - if (null != nextService) { - return nextService; - } - ReferenceConfig reference = new ReferenceConfig<>(); - reference.setRegistry(new RegistryConfig(ExampleConsts.POLARIS_ADDRESS)); - reference.setInterface(NextService.class); - reference.setVersion(CommonConstants.ANY_VALUE); - bootstrap.reference(reference).start(); - nextService = ReferenceConfigCache.getCache().get(reference); - return nextService; - } - } - - @Override - public String sayHello(String name) { - String responseText = getNextService().sayHello(name); - return String.format("middle.%s[%s]->%s", name, version, responseText); - } -} diff --git a/dubbo/dubbo-examples/dubbo-router-example/pom.xml b/dubbo/dubbo-examples/dubbo-router-example/pom.xml deleted file mode 100644 index 40d5c44..0000000 --- a/dubbo/dubbo-examples/dubbo-router-example/pom.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - dubbo-examples - com.tencent.polaris - ${revision} - ../pom.xml - - 4.0.0 - - dubbo-router-example - - pom - - dubbo-router-middle - dubbo-router-front - dubbo-router-back - - \ No newline at end of file diff --git a/dubbo/dubbo-examples/pom.xml b/dubbo/dubbo-examples/pom.xml index fa895ed..928f1f1 100644 --- a/dubbo/dubbo-examples/pom.xml +++ b/dubbo/dubbo-examples/pom.xml @@ -1,7 +1,7 @@ + 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 com.tencent.polaris @@ -10,34 +10,33 @@ 4.0.0 - dubbo-examples + + true + + dubbo-examples pom + + dubbo-api-example dubbo-discovery-example - dubbo-example-interface - dubbo-router-example - dubbo-ratelimit-example - dubbo-circuitbreak-example - - 1.7.25 - true - + + + + javax.annotation + + [1.11,) + + + + javax.annotation + javax.annotation-api + 1.3.2 + + + + - - - - org.slf4j - slf4j-log4j12 - ${slf4j-log4j12.version} - - - log4j - log4j - 1.2.17 - - - \ No newline at end of file diff --git a/dubbo/dubbo-plugins/dubbo-circuitbreaker-polaris/pom.xml b/dubbo/dubbo-plugins/dubbo-circuitbreaker-polaris/pom.xml index 2c529ec..38c6e8f 100644 --- a/dubbo/dubbo-plugins/dubbo-circuitbreaker-polaris/pom.xml +++ b/dubbo/dubbo-plugins/dubbo-circuitbreaker-polaris/pom.xml @@ -18,15 +18,5 @@ dubbo-registry-polaris ${project.version} - - org.apache.dubbo - dubbo - provided - - - org.slf4j - slf4j-api - provided - \ No newline at end of file diff --git a/dubbo/dubbo-plugins/dubbo-circuitbreaker-polaris/src/main/java/com/tencent/polaris/dubbo/circuitbreaker/CircuitBreakerFilter.java b/dubbo/dubbo-plugins/dubbo-circuitbreaker-polaris/src/main/java/com/tencent/polaris/dubbo/circuitbreaker/CircuitBreakerFilter.java index 1116a00..40ed349 100644 --- a/dubbo/dubbo-plugins/dubbo-circuitbreaker-polaris/src/main/java/com/tencent/polaris/dubbo/circuitbreaker/CircuitBreakerFilter.java +++ b/dubbo/dubbo-plugins/dubbo-circuitbreaker-polaris/src/main/java/com/tencent/polaris/dubbo/circuitbreaker/CircuitBreakerFilter.java @@ -17,8 +17,6 @@ package com.tencent.polaris.dubbo.circuitbreaker; -import java.util.concurrent.TimeUnit; - 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; @@ -31,132 +29,137 @@ 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.DubboServiceInfo; import com.tencent.polaris.common.registry.PolarisOperator; import com.tencent.polaris.common.registry.PolarisOperatorDelegate; +import com.tencent.polaris.common.utils.DubboUtils; 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.ErrorTypeAwareLogger; +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; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import java.util.List; +import java.util.Objects; +import java.util.concurrent.TimeUnit; @Activate(group = CommonConstants.CONSUMER) public class CircuitBreakerFilter extends PolarisOperatorDelegate implements Filter, ResultToErrorCode { - private static final Logger LOGGER = LoggerFactory.getLogger(CircuitBreakerFilter.class); + protected final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(getClass()); + + private final PolarisOperator operator; - public CircuitBreakerFilter() { - LOGGER.info("[POLARIS] init polaris circuitbreaker"); - } + private final CircuitBreakAPI circuitBreakAPI; - @Override - public Result invoke(Invoker invoker, Invocation invocation) throws RpcException { - PolarisOperator polarisOperator = getPolarisOperator(); - if (null == polarisOperator) { - return invoker.invoke(invocation); - } + public CircuitBreakerFilter() { + logger.info("[POLARIS] init polaris circuitbreaker"); + this.operator = getGovernancePolarisOperator(); + this.circuitBreakAPI = operator.getCircuitBreakAPI(); + } - 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) { - throw new RpcException(abortedException); - } - } + @Override + public Result invoke(Invoker invoker, Invocation invocation) throws RpcException { + List serviceInfos = DubboUtils.analyzeDubboServiceInfo(applicationModel, invoker, invocation); + if (serviceInfos.isEmpty() || Objects.isNull(operator)) { + return invoker.invoke(invocation); + } + DubboServiceInfo firstService = serviceInfos.get(0); - 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; - } - } + InvokeContext.RequestContext context = new InvokeContext.RequestContext(createCalleeService(firstService), firstService.getInterfaceName()); + 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, firstService, responseContext, responseContext.getDuration()); + circuitBreakAPI.report(resourceStat); + if (result != null) { + return result; + } + throw exception; + } catch (CallAbortedException abortedException) { + throw new RpcException(abortedException); + } + } - else { - code = -1; - } - } + private ResourceStat createInstanceResourceStat(Invoker invoker, Invocation invocation, DubboServiceInfo serviceInfo, + 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); - } + ServiceKey calleeServiceKey = createCalleeService(serviceInfo); + 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()); - } + private ServiceKey createCalleeService(DubboServiceInfo serviceInfo) { + return new ServiceKey(operator.getPolarisConfig().getNamespace(), serviceInfo.getService()); + } - @Override - public int onSuccess(Object value) { - return 0; - } + @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; - } + @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; + } } diff --git a/dubbo/dubbo-plugins/dubbo-configcenter-polaris/pom.xml b/dubbo/dubbo-plugins/dubbo-configcenter-polaris/pom.xml new file mode 100644 index 0000000..fdd87e8 --- /dev/null +++ b/dubbo/dubbo-plugins/dubbo-configcenter-polaris/pom.xml @@ -0,0 +1,23 @@ + + + + dubbo-plugins + com.tencent.polaris + ${revision} + ../pom.xml + + 4.0.0 + + dubbo-configcenter-polaris + + + + com.tencent.polaris + polaris-adapter-dubbo + ${project.version} + + + + \ No newline at end of file diff --git a/dubbo/dubbo-plugins/dubbo-configcenter-polaris/src/main/java/com/tencent/polaris/dubbo/configuration/PolarisDynamicConfiguration.java b/dubbo/dubbo-plugins/dubbo-configcenter-polaris/src/main/java/com/tencent/polaris/dubbo/configuration/PolarisDynamicConfiguration.java new file mode 100644 index 0000000..82466f8 --- /dev/null +++ b/dubbo/dubbo-plugins/dubbo-configcenter-polaris/src/main/java/com/tencent/polaris/dubbo/configuration/PolarisDynamicConfiguration.java @@ -0,0 +1,139 @@ +/* + * Tencent is pleased to support the open source community by making Polaris available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * 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 com.tencent.polaris.dubbo.configuration; + +import com.tencent.polaris.api.exception.PolarisException; +import com.tencent.polaris.api.exception.ServerCodes; +import com.tencent.polaris.api.plugin.configuration.ConfigFileResponse; +import com.tencent.polaris.common.registry.PolarisConfig; +import com.tencent.polaris.common.registry.PolarisOperator; +import com.tencent.polaris.common.registry.PolarisOperators; +import com.tencent.polaris.configuration.api.core.ConfigFile; +import com.tencent.polaris.configuration.api.core.ConfigFilePublishService; +import com.tencent.polaris.configuration.api.core.ConfigFileService; +import org.apache.dubbo.common.URL; +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.ErrorTypeAwareLogger; +import org.apache.dubbo.common.logger.LoggerFactory; + +import java.util.Collections; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CopyOnWriteArraySet; + +public class PolarisDynamicConfiguration implements DynamicConfiguration { + + private final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(getClass()); + + private final PolarisOperator operator; + + private final PolarisConfig polarisConfig; + + private final ConfigFileService fileQuerier; + + private final ConfigFilePublishService filePublisher; + + private Map> listeners = new ConcurrentHashMap<>(); + + PolarisDynamicConfiguration(URL url) { + this.operator = PolarisOperators.INSTANCE.loadOrStoreForConfig(url.getHost(), url.getPort(), url.getParameters()); + this.polarisConfig = operator.getPolarisConfig(); + this.fileQuerier = operator.getConfigFileAPI(); + this.filePublisher = operator.getConfigFilePublishAPI(); + } + + @Override + public void addListener(String key, String group, ConfigurationListener listener) { + String fileKey = group + "@@" + key; + listeners.computeIfAbsent(fileKey, s -> { + ConfigFile configFile = fileQuerier.getConfigFile(polarisConfig.getNamespace(), group, key); + configFile.addChangeListener(event -> { + Set watchers = listeners.getOrDefault(fileKey, Collections.emptySet()); + watchers.forEach(configurationListener -> { + ConfigChangedEvent dubboEvent = new ConfigChangedEvent(key, group, event.getNewValue()); + configurationListener.process(dubboEvent); + }); + }); + return new CopyOnWriteArraySet<>(); + }); + + listeners.get(fileKey).add(listener); + } + + @Override + public void removeListener(String key, String group, ConfigurationListener listener) { + String fileKey = group + "@@" + key; + listeners.getOrDefault(fileKey, Collections.emptySet()).remove(listener); + } + + @Override + public String getConfig(String key, String group, long timeout) throws IllegalStateException { + ConfigFile configFile = fileQuerier.getConfigFile(polarisConfig.getNamespace(), group, key); + return configFile.getContent(); + } + + @Override + public Object getInternalProperty(String key) { + ConfigFile configFile = fileQuerier.getConfigFile(polarisConfig.getNamespace(), DEFAULT_GROUP, key); + return configFile.getContent(); + } + + @Override + public boolean publishConfig(String key, String group, String content) throws UnsupportedOperationException { + try { + ConfigFileResponse response = filePublisher.createConfigFile(polarisConfig.getNamespace(), group, key, content); + if (response.getCode() == ServerCodes.EXISTED_RESOURCE) { + response = filePublisher.updateConfigFile(polarisConfig.getNamespace(), group, key, content); + } + if (response.getCode() != ServerCodes.EXECUTE_SUCCESS) { + logger.error( + formatCode(response.getCode()), + response.getMessage(), + String.format("key(%s) group(%s)", key, group), + "upsert config fail" + ); + return false; + } + response = filePublisher.releaseConfigFile(polarisConfig.getNamespace(), group, key); + if (response.getCode() != ServerCodes.EXECUTE_SUCCESS) { + logger.error( + formatCode(response.getCode()), + response.getMessage(), + String.format("key(%s) group(%s)", key, group), + "release config fail" + ); + return false; + } + return true; + } catch (PolarisException e) { + logger.error( + formatCode(e.getCode()), + e.getMessage(), + String.format("key(%s) group(%s)", key, group), + "publish config fail"); + return false; + } + } + + private String formatCode(Object val) { + return "POLARIS:" + val; + } +} diff --git a/dubbox/dubbox-plugins/dubbox-router-polaris/src/main/java/com/tencent/polaris/dubbox/router/PolarisRouterFactory.java b/dubbo/dubbo-plugins/dubbo-configcenter-polaris/src/main/java/com/tencent/polaris/dubbo/configuration/PolarisDynamicConfigurationFactory.java similarity index 61% rename from dubbox/dubbox-plugins/dubbox-router-polaris/src/main/java/com/tencent/polaris/dubbox/router/PolarisRouterFactory.java rename to dubbo/dubbo-plugins/dubbo-configcenter-polaris/src/main/java/com/tencent/polaris/dubbo/configuration/PolarisDynamicConfigurationFactory.java index 5a1240b..2d8db3d 100644 --- a/dubbox/dubbox-plugins/dubbox-router-polaris/src/main/java/com/tencent/polaris/dubbox/router/PolarisRouterFactory.java +++ b/dubbo/dubbo-plugins/dubbo-configcenter-polaris/src/main/java/com/tencent/polaris/dubbo/configuration/PolarisDynamicConfigurationFactory.java @@ -1,33 +1,30 @@ -/* - * Tencent is pleased to support the open source community by making Polaris available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * 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 com.tencent.polaris.dubbox.router; - -import com.alibaba.dubbo.common.URL; -import com.alibaba.dubbo.common.extension.Activate; -import com.alibaba.dubbo.rpc.cluster.Router; -import com.alibaba.dubbo.rpc.cluster.RouterFactory; - -@Activate -public class PolarisRouterFactory implements RouterFactory { - - @Override - public Router getRouter(URL url) { - return new PolarisRouter(url); - } -} +/* + * Tencent is pleased to support the open source community by making Polaris available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * 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 com.tencent.polaris.dubbo.configuration; + +import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.config.configcenter.AbstractDynamicConfigurationFactory; +import org.apache.dubbo.common.config.configcenter.DynamicConfiguration; + +public class PolarisDynamicConfigurationFactory extends AbstractDynamicConfigurationFactory { + + @Override + protected DynamicConfiguration createDynamicConfiguration(URL url) { + return new PolarisDynamicConfiguration(url); + } +} diff --git a/dubbo/dubbo-plugins/dubbo-configcenter-polaris/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.config.configcenter.DynamicConfigurationFactory b/dubbo/dubbo-plugins/dubbo-configcenter-polaris/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.config.configcenter.DynamicConfigurationFactory new file mode 100644 index 0000000..3ffcc57 --- /dev/null +++ b/dubbo/dubbo-plugins/dubbo-configcenter-polaris/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.config.configcenter.DynamicConfigurationFactory @@ -0,0 +1 @@ +polaris=com.tencent.polaris.dubbo.configuration.PolarisDynamicConfigurationFactory \ No newline at end of file diff --git a/dubbo/dubbo-plugins/dubbo-metadatareport-polaris/pom.xml b/dubbo/dubbo-plugins/dubbo-metadatareport-polaris/pom.xml new file mode 100644 index 0000000..4f44bcf --- /dev/null +++ b/dubbo/dubbo-plugins/dubbo-metadatareport-polaris/pom.xml @@ -0,0 +1,22 @@ + + + + dubbo-plugins + com.tencent.polaris + ${revision} + ../pom.xml + + 4.0.0 + + dubbo-metadatareport-polaris + + + + com.tencent.polaris + polaris-adapter-dubbo + ${project.version} + + + \ No newline at end of file diff --git a/dubbo/dubbo-plugins/dubbo-metadatareport-polaris/src/main/java/com/tencent/polaris/dubbo/metadata/report/PolarisMetadataReport.java b/dubbo/dubbo-plugins/dubbo-metadatareport-polaris/src/main/java/com/tencent/polaris/dubbo/metadata/report/PolarisMetadataReport.java new file mode 100644 index 0000000..56a0ffa --- /dev/null +++ b/dubbo/dubbo-plugins/dubbo-metadatareport-polaris/src/main/java/com/tencent/polaris/dubbo/metadata/report/PolarisMetadataReport.java @@ -0,0 +1,369 @@ +/* + * Copyright 2019 NAVER Corp. + * + * Licensed 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 com.tencent.polaris.dubbo.metadata.report; + +import com.tencent.polaris.api.core.ConsumerAPI; +import com.tencent.polaris.api.core.ProviderAPI; +import com.tencent.polaris.api.exception.PolarisException; +import com.tencent.polaris.api.exception.ServerCodes; +import com.tencent.polaris.api.plugin.configuration.ConfigFileResponse; +import com.tencent.polaris.api.plugin.server.InterfaceDescriptor; +import com.tencent.polaris.api.plugin.server.ReportServiceContractRequest; +import com.tencent.polaris.api.pojo.ServiceRule; +import com.tencent.polaris.api.rpc.GetServiceContractRequest; +import com.tencent.polaris.api.rpc.ServiceRuleResponse; +import com.tencent.polaris.common.registry.PolarisConfig; +import com.tencent.polaris.common.registry.PolarisOperator; +import com.tencent.polaris.common.registry.PolarisOperators; +import com.tencent.polaris.common.utils.Consts; +import com.tencent.polaris.configuration.api.core.ConfigFile; +import com.tencent.polaris.configuration.api.core.ConfigFileChangeEvent; +import com.tencent.polaris.configuration.api.core.ConfigFileChangeListener; +import com.tencent.polaris.configuration.api.core.ConfigFilePublishService; +import com.tencent.polaris.configuration.api.core.ConfigFileService; +import com.tencent.polaris.configuration.api.rpc.ConfigPublishRequest; +import com.tencent.polaris.specification.api.v1.service.manage.ServiceContractProto; +import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.config.configcenter.ConfigItem; +import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; +import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.ConcurrentHashSet; +import org.apache.dubbo.metadata.MappingChangedEvent; +import org.apache.dubbo.metadata.MappingListener; +import org.apache.dubbo.metadata.MetadataInfo; +import org.apache.dubbo.metadata.ServiceNameMapping; +import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier; +import org.apache.dubbo.metadata.report.identifier.ServiceMetadataIdentifier; +import org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier; +import org.apache.dubbo.metadata.report.support.AbstractMetadataReport; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + +import static org.apache.dubbo.metadata.MetadataConstants.REPORT_CONSUMER_URL_KEY; +import static org.apache.dubbo.metadata.ServiceNameMapping.DEFAULT_MAPPING_GROUP; + +public class PolarisMetadataReport extends AbstractMetadataReport { + + protected final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(getClass()); + + private final PolarisOperator operator; + + private final PolarisConfig config; + + private final ProviderAPI providerAPI; + + private final ConsumerAPI consumerAPI; + + private final ConfigFileService fileQuerier; + + private final ConfigFilePublishService filePubilsher; + + private final Map> mappingListeners = new ConcurrentHashMap<>(); + + private final Map sourceMappingListeners = new ConcurrentHashMap<>(); + + PolarisMetadataReport(URL url) { + super(url); + this.operator = PolarisOperators.INSTANCE.loadOrStoreForGovernance(url.getHost(), url.getPort(), url.getParameters()); + this.config = operator.getPolarisConfig(); + this.providerAPI = operator.getProviderAPI(); + this.consumerAPI = operator.getConsumerAPI(); + this.fileQuerier = operator.getConfigFileAPI(); + this.filePubilsher = operator.getConfigFilePublishAPI(); + } + + @Override + protected void doStoreProviderMetadata(MetadataIdentifier providerMetadataIdentifier, String serviceDefinitions) { + reportServiceContract(toDescriptor(providerMetadataIdentifier, serviceDefinitions)); + } + + @Override + protected void doStoreConsumerMetadata(MetadataIdentifier consumerMetadataIdentifier, String serviceParameterString) { + if (getUrl().getParameter(REPORT_CONSUMER_URL_KEY, false)) { + reportServiceContract(toDescriptor(consumerMetadataIdentifier, serviceParameterString)); + } + } + + @Override + protected void doSaveMetadata(ServiceMetadataIdentifier metadataIdentifier, URL url) { + reportServiceContract(toDescriptor(metadataIdentifier, url)); + } + + @Override + protected void doRemoveMetadata(ServiceMetadataIdentifier metadataIdentifier) { + // + } + + @Override + protected List doGetExportedURLs(ServiceMetadataIdentifier metadataIdentifier) { + GetServiceContractRequest request = new GetServiceContractRequest(); + ServiceRuleResponse response = consumerAPI.getServiceContract(request); + ServiceRule rule = response.getServiceRule(); + if (Objects.isNull(rule)) { + return Collections.emptyList(); + } + ServiceContractProto.ServiceContract contract = (ServiceContractProto.ServiceContract) rule.getRule(); + List descriptors = contract.getInterfacesList(); + for (ServiceContractProto.InterfaceDescriptor descriptor : descriptors) { + if (!Objects.equals(descriptor.getId(), metadataIdentifier.getIdentifierKey())) { + continue; + } + String content = descriptor.getContent(); + return new ArrayList<>(Collections.singletonList(URL.decode(content))); + } + return Collections.emptyList(); + } + + @Override + protected void doSaveSubscriberData(SubscriberMetadataIdentifier identifier, String urlListStr) { + } + + @Override + protected String doGetSubscribedURLs(SubscriberMetadataIdentifier subscriberMetadataIdentifier) { + return null; + } + + + @Override + public String getServiceDefinition(MetadataIdentifier metadataIdentifier) { + GetServiceContractRequest request = new GetServiceContractRequest(); + request.setName(metadataIdentifier.getApplication()); + request.setService(metadataIdentifier.getApplication()); + request.setVersion(metadataIdentifier.getVersion()); + Optional result = getServiceContract(request); + if (!result.isPresent()) { + return null; + } + + List descriptors = result.get().getInterfacesList(); + for (ServiceContractProto.InterfaceDescriptor descriptor : descriptors) { + if (!Objects.equals(descriptor.getId(), metadataIdentifier.getIdentifierKey())) { + continue; + } + return descriptor.getContent(); + } + return null; + } + + @Override + public void publishAppMetadata(SubscriberMetadataIdentifier identifier, MetadataInfo metadataInfo) { + ReportServiceContractRequest request = new ReportServiceContractRequest(); + request.setName(identifier.getApplication()); + request.setService(identifier.getApplication()); + request.setVersion(identifier.getRevision()); + request.setContent(metadataInfo.getContent()); + + reportServiceContract(request); + } + + @Override + public void unPublishAppMetadata(SubscriberMetadataIdentifier identifier, MetadataInfo metadataInfo) { + } + + @Override + public MetadataInfo getAppMetadata(SubscriberMetadataIdentifier identifier, Map instanceMetadata) { + return null; + } + + private ReportServiceContractRequest toDescriptor(ServiceMetadataIdentifier identifier, URL url) { + ReportServiceContractRequest request = new ReportServiceContractRequest(); + request.setName(url.getApplication()); + request.setService(url.getApplication()); + request.setVersion(url.getVersion()); + + InterfaceDescriptor descriptor = new InterfaceDescriptor(); + descriptor.setId(identifier.getIdentifierKey()); + descriptor.setName(String.format("%s_%s", url.getSide(), url.getGroup())); + descriptor.setPath(url.getServiceInterface()); + descriptor.setMethod(""); + descriptor.setContent(URL.encode(url.toFullString())); + + List descriptors = new ArrayList<>(1); + descriptors.add(descriptor); + request.setInterfaceDescriptors(descriptors); + + return request; + } + + private ReportServiceContractRequest toDescriptor(MetadataIdentifier identifier, String serviceDefinitions) { + ReportServiceContractRequest request = new ReportServiceContractRequest(); + request.setName(identifier.getApplication()); + request.setService(identifier.getApplication()); + request.setVersion(identifier.getVersion()); + + InterfaceDescriptor descriptor = new InterfaceDescriptor(); + descriptor.setId(identifier.getIdentifierKey()); + descriptor.setName(String.format("%s_%s", identifier.getSide(), identifier.getGroup())); + descriptor.setPath(identifier.getServiceInterface()); + descriptor.setMethod(""); + descriptor.setContent(serviceDefinitions); + + List descriptors = new ArrayList<>(1); + descriptors.add(descriptor); + request.setInterfaceDescriptors(descriptors); + + return request; + } + + private Optional getServiceContract(GetServiceContractRequest req) { + req.setNamespace(config.getNamespace()); + req.setProtocol(Consts.DUBBO_PROTOCOL); + try { + ServiceRuleResponse response = consumerAPI.getServiceContract(req); + ServiceRule rule = response.getServiceRule(); + if (Objects.isNull(rule)) { + return Optional.empty(); + } + ServiceContractProto.ServiceContract contract = (ServiceContractProto.ServiceContract) rule.getRule(); + return Optional.ofNullable(contract); + } catch (PolarisException e) { + logger.error( + formatCode(e.getCode()), + e.getMessage(), + "", + "report service_contract fail" + ); + } + return Optional.empty(); + } + + + private void reportServiceContract(ReportServiceContractRequest req) { + req.setNamespace(config.getNamespace()); + req.setProtocol(Consts.DUBBO_PROTOCOL); + try { + providerAPI.reportServiceContract(req); + } catch (PolarisException e) { + logger.error( + formatCode(e.getCode()), + e.getMessage(), + "", + "report service_contract fail" + ); + } + } + + // ------- 和 Dubbo3 应用级注册发现有关的操作 -------- + // ------- 这里必须实现,否则就需要用户指定 providerBy ------ + + @Override + public ConfigItem getConfigItem(String key, String group) { + ConfigFile file = fileQuerier.getConfigFile(config.getNamespace(), group, key); + String content = file.getContent(); + return new ConfigItem(content, file.getMd5()); + } + + @Override + public boolean registerServiceAppMapping(String serviceInterface, String defaultMappingGroup, String newConfigContent, Object ticket) { + ConfigPublishRequest request = new ConfigPublishRequest(); + request.setNamespace(config.getNamespace()); + request.setGroup(defaultMappingGroup); + request.setFilename(serviceInterface); + request.setContent(newConfigContent); + request.setCasMd5((String) ticket); + ConfigFileResponse response = filePubilsher.upsertAndPublish(request); + if (response.getCode() == ServerCodes.EXECUTE_SUCCESS) { + return true; + } + logger.error( + formatCode(response.getCode()), + response.getMessage(), + String.format("key(%s) group(%s) md5(%s)", serviceInterface, defaultMappingGroup, ticket), + "registerServiceAppMapping fail" + ); + return false; + } + + @Override + public void removeServiceAppMappingListener(String serviceKey, MappingListener listener) { + Set listeners = mappingListeners.getOrDefault(serviceKey, Collections.emptySet()); + listeners.remove(listener); + } + + /** + * dubbo 根据 serviceKey(接口名称)查找提供该接口的 application 到底有哪些 + * + * @param serviceKey dubbo 的 interface name + * @param listener {@link MappingListener} + * @param url {@link URL} + * @return {@link Set} 提供此接口的所用应用列表名称 + */ + @Override + public Set getServiceAppMapping(String serviceKey, MappingListener listener, URL url) { + String group = DEFAULT_MAPPING_GROUP; + ConfigFile file = fileQuerier.getConfigFile(config.getNamespace(), group, serviceKey); + + mappingListeners.compute(serviceKey, (s, mappingListeners) -> { + sourceMappingListeners.compute(serviceKey, (s1, configFileChangeListener) -> { + ConfigFileChangeListener changeListener = new MappingConfigFileChangeListener(serviceKey, this); + file.addChangeListener(changeListener); + return changeListener; + }); + return new ConcurrentHashSet<>(); + }); + + mappingListeners.get(serviceKey).add(listener); + + return ServiceNameMapping.getAppNames(file.getContent()); + } + + /** + * dubbo 根据 serviceKey(接口名称)查找提供该接口的 application 到底有哪些 + * + * @param serviceKey dubbo 的 interface name + * @param url {@link URL} + * @return {@link Set} 提供此接口的所用应用列表名称 + */ + @Override + public Set getServiceAppMapping(String serviceKey, URL url) { + String group = DEFAULT_MAPPING_GROUP; + ConfigFile file = fileQuerier.getConfigFile(config.getNamespace(), group, serviceKey); + return ServiceNameMapping.getAppNames(file.getContent()); + } + + private String formatCode(Object val) { + return "POLARIS:" + val; + } + + private static class MappingConfigFileChangeListener implements ConfigFileChangeListener { + + private final String serviceKey; + + private final PolarisMetadataReport report; + + public MappingConfigFileChangeListener(String serviceKey, PolarisMetadataReport report) { + this.serviceKey = serviceKey; + this.report = report; + } + + @Override + public void onChange(ConfigFileChangeEvent event) { + MappingChangedEvent mappingChangedEvent = new MappingChangedEvent(serviceKey, ServiceNameMapping.getAppNames(event.getNewValue())); + + Set mappingListeners = report.mappingListeners.getOrDefault(serviceKey, Collections.emptySet()); + mappingListeners.forEach(mappingListener -> mappingListener.onEvent(mappingChangedEvent)); + } + } + +} diff --git a/dubbox/dubbox-plugins/dubbox-registry-polaris/src/main/java/com/tencent/polaris/dubbox/registry/PolarisRegistryFactory.java b/dubbo/dubbo-plugins/dubbo-metadatareport-polaris/src/main/java/com/tencent/polaris/dubbo/metadata/report/PolarisMetadataReportFactory.java similarity index 61% rename from dubbox/dubbox-plugins/dubbox-registry-polaris/src/main/java/com/tencent/polaris/dubbox/registry/PolarisRegistryFactory.java rename to dubbo/dubbo-plugins/dubbo-metadatareport-polaris/src/main/java/com/tencent/polaris/dubbo/metadata/report/PolarisMetadataReportFactory.java index bae0557..111b5c1 100644 --- a/dubbox/dubbox-plugins/dubbox-registry-polaris/src/main/java/com/tencent/polaris/dubbox/registry/PolarisRegistryFactory.java +++ b/dubbo/dubbo-plugins/dubbo-metadatareport-polaris/src/main/java/com/tencent/polaris/dubbo/metadata/report/PolarisMetadataReportFactory.java @@ -1,30 +1,30 @@ -/* - * Copyright 2019 NAVER Corp. - * - * Licensed 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 com.tencent.polaris.dubbox.registry; - -import com.alibaba.dubbo.common.URL; -import com.alibaba.dubbo.registry.Registry; -import com.alibaba.dubbo.registry.support.AbstractRegistryFactory; - -public class PolarisRegistryFactory extends AbstractRegistryFactory { - - @Override - protected Registry createRegistry(URL url) { - return new PolarisRegistry(url); - } - -} +/* + * Copyright 2019 NAVER Corp. + * + * Licensed 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 com.tencent.polaris.dubbo.metadata.report; + +import org.apache.dubbo.common.URL; +import org.apache.dubbo.metadata.report.MetadataReport; +import org.apache.dubbo.metadata.report.MetadataReportFactory; + +public class PolarisMetadataReportFactory implements MetadataReportFactory { + + @Override + public MetadataReport getMetadataReport(URL url) { + return new PolarisMetadataReport(url); + } + +} diff --git a/dubbo/dubbo-plugins/dubbo-metadatareport-polaris/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.report.MetadataReportFactory b/dubbo/dubbo-plugins/dubbo-metadatareport-polaris/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.report.MetadataReportFactory new file mode 100644 index 0000000..299e575 --- /dev/null +++ b/dubbo/dubbo-plugins/dubbo-metadatareport-polaris/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.report.MetadataReportFactory @@ -0,0 +1 @@ +polaris=com.tencent.polaris.dubbo.metadata.report.PolarisMetadataReportFactory \ No newline at end of file diff --git a/dubbo/dubbo-plugins/dubbo-ratelimit-polaris/pom.xml b/dubbo/dubbo-plugins/dubbo-ratelimit-polaris/pom.xml index 455fb27..1c42b0a 100644 --- a/dubbo/dubbo-plugins/dubbo-ratelimit-polaris/pom.xml +++ b/dubbo/dubbo-plugins/dubbo-ratelimit-polaris/pom.xml @@ -18,15 +18,5 @@ dubbo-registry-polaris ${project.version} - - org.apache.dubbo - dubbo - provided - - - org.slf4j - slf4j-api - provided - \ No newline at end of file diff --git a/dubbo/dubbo-plugins/dubbo-ratelimit-polaris/src/main/java/com/tencent/polaris/dubbo/ratelimit/RateLimitFilter.java b/dubbo/dubbo-plugins/dubbo-ratelimit-polaris/src/main/java/com/tencent/polaris/dubbo/ratelimit/RateLimitFilter.java index ae79392..d3261a8 100644 --- a/dubbo/dubbo-plugins/dubbo-ratelimit-polaris/src/main/java/com/tencent/polaris/dubbo/ratelimit/RateLimitFilter.java +++ b/dubbo/dubbo-plugins/dubbo-ratelimit-polaris/src/main/java/com/tencent/polaris/dubbo/ratelimit/RateLimitFilter.java @@ -17,18 +17,26 @@ package com.tencent.polaris.dubbo.ratelimit; +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.common.exception.PolarisBlockException; import com.tencent.polaris.common.parser.QueryParser; +import com.tencent.polaris.common.registry.DubboServiceInfo; import com.tencent.polaris.common.registry.PolarisOperator; import com.tencent.polaris.common.registry.PolarisOperatorDelegate; import com.tencent.polaris.common.router.RuleHandler; +import com.tencent.polaris.common.utils.DubboUtils; 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.HashMap; import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.function.Consumer; @@ -36,47 +44,59 @@ 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.ErrorTypeAwareLogger; +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; +import org.apache.dubbo.rpc.model.ApplicationModel; +import org.apache.dubbo.rpc.model.ScopeModelAware; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; @Activate(group = CommonConstants.PROVIDER) -public class RateLimitFilter extends PolarisOperatorDelegate implements Filter { +public class RateLimitFilter extends PolarisOperatorDelegate implements Filter, ScopeModelAware { - private static final Logger LOGGER = LoggerFactory.getLogger(RateLimitFilter.class); + protected final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(getClass()); private final RuleHandler ruleHandler; private final QueryParser parser; + private final PolarisOperator operator; + public RateLimitFilter() { - LOGGER.info("[POLARIS] init polaris ratelimit"); - ruleHandler = new RuleHandler(); - parser = QueryParser.load(); + logger.info("[POLARIS] init polaris ratelimit"); + this.ruleHandler = new RuleHandler(); + this.parser = QueryParser.load(); + this.operator = getGovernancePolarisOperator(); } @Override public Result invoke(Invoker invoker, Invocation invocation) throws RpcException { - String service = invoker.getInterface().getName(); - PolarisOperator polarisOperator = getPolarisOperator(); + PolarisOperator polarisOperator = getGovernancePolarisOperator(); if (null == polarisOperator) { return invoker.invoke(invocation); } - ServiceRule serviceRule = polarisOperator.getServiceRule(service, EventType.RATE_LIMITING); + List serviceInfos = DubboUtils.analyzeDubboServiceInfo(applicationModel, invoker, invocation); + for (DubboServiceInfo serviceInfo : serviceInfos) { + checkRateLimit(invoker, invocation, serviceInfo); + } + return invoker.invoke(invocation); + } + + private void checkRateLimit(Invoker invoker, Invocation invocation, DubboServiceInfo serviceInfo) { + ServiceRule serviceRule = operator.getServiceRule(serviceInfo.getService(), EventType.RATE_LIMITING); Object ruleObject = serviceRule.getRule(); - if (null == ruleObject) { - return invoker.invoke(invocation); + if (Objects.isNull(ruleObject)) { + return; } RateLimitProto.RateLimit rateLimit = (RateLimitProto.RateLimit) ruleObject; - Set ratelimitLabels = ruleHandler.getRatelimitLabels(rateLimit); - String method = invocation.getMethodName(); + Set trafficLabels = ruleHandler.getRatelimitLabels(rateLimit); Set arguments = new HashSet<>(); - for (RateLimitProto.MatchArgument matchArgument : ratelimitLabels) { + for (RateLimitProto.MatchArgument matchArgument : trafficLabels) { switch (matchArgument.getType()) { case HEADER: String attachmentValue = RpcContext.getContext().getAttachment(matchArgument.getKey()); @@ -92,17 +112,26 @@ public Result invoke(Invoker invoker, Invocation invocation) throws RpcExcept break; } } + if (StringUtils.isNotEmpty(serviceInfo.getMethodName())) { + arguments.add(Argument.buildMethod(serviceInfo.getMethodName())); + } QuotaResponse quotaResponse = null; try { - quotaResponse = polarisOperator.getQuota(service, method, arguments); - } catch (RuntimeException e) { - LOGGER.error("[POLARIS] get quota fail, {}", e.getMessage()); + quotaResponse = operator.getQuota(serviceInfo.getService(), serviceInfo.getReportMethodName(), arguments); + } catch (PolarisException e) { + Map externalParam = new HashMap<>(); + externalParam.put("serviceInfo", serviceInfo); + externalParam.put("arguments", arguments); + logger.error(formatCode(e.getCode()), + e.getMessage(), + externalParam.toString(), + "check rate_limit by polaris fail"); } if (null != quotaResponse && quotaResponse.getCode() == QuotaResultCode.QuotaResultLimited) { // 请求被限流,则抛出异常 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/dubbo-plugins/dubbo-ratelimit-polaris/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter b/dubbo/dubbo-plugins/dubbo-ratelimit-polaris/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter similarity index 100% rename from dubbo/dubbo-plugins/dubbo-ratelimit-polaris/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter rename to dubbo/dubbo-plugins/dubbo-ratelimit-polaris/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter diff --git a/dubbo/dubbo-plugins/dubbo-registry-polaris/pom.xml b/dubbo/dubbo-plugins/dubbo-registry-polaris/pom.xml index 41c0a3e..574425e 100644 --- a/dubbo/dubbo-plugins/dubbo-registry-polaris/pom.xml +++ b/dubbo/dubbo-plugins/dubbo-registry-polaris/pom.xml @@ -18,15 +18,10 @@ polaris-adapter-dubbo ${project.version} - - org.apache.dubbo - dubbo - provided - org.slf4j slf4j-api - provided + ${slf4j.version} \ No newline at end of file diff --git a/dubbo/dubbo-plugins/dubbo-registry-polaris/src/main/java/com/tencent/polaris/dubbo/registry/PolarisRegistry.java b/dubbo/dubbo-plugins/dubbo-registry-polaris/src/main/java/com/tencent/polaris/dubbo/registry/PolarisRegistry.java index 1a9d8cd..0140f5c 100644 --- a/dubbo/dubbo-plugins/dubbo-registry-polaris/src/main/java/com/tencent/polaris/dubbo/registry/PolarisRegistry.java +++ b/dubbo/dubbo-plugins/dubbo-registry-polaris/src/main/java/com/tencent/polaris/dubbo/registry/PolarisRegistry.java @@ -20,10 +20,8 @@ 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.BaseBootConfigHandler; -import com.tencent.polaris.common.registry.BootConfigHandler; -import com.tencent.polaris.common.registry.Consts; -import com.tencent.polaris.common.registry.ConvertUtils; +import com.tencent.polaris.common.utils.Consts; +import com.tencent.polaris.common.utils.ConvertUtils; import com.tencent.polaris.common.registry.PolarisOperator; import com.tencent.polaris.common.registry.PolarisOperators; import org.apache.dubbo.common.URL; @@ -64,13 +62,8 @@ public class PolarisRegistry extends FailbackRegistry { private final PolarisOperator polarisOperator; public PolarisRegistry(URL url) { - this(url, new BaseBootConfigHandler()); - } - - // for test - public PolarisRegistry(URL url, BootConfigHandler... handlers) { super(url); - polarisOperator = PolarisOperators.INSTANCE.loadOrStore(url.getHost(), url.getPort(), url.getParameters(), handlers); + polarisOperator = PolarisOperators.INSTANCE.loadOrStoreForGovernance(url.getHost(), url.getPort(), url.getParameters()); } @Override @@ -84,7 +77,7 @@ public void doRegister(URL url) { int port = url.getPort(); if (port > 0) { int weight = url.getParameter(Constants.WEIGHT_KEY, Constants.DEFAULT_WEIGHT); - String version = url.getParameter(CommonConstants.VERSION_KEY, ""); + String version = url.getParameter(CommonConstants.VERSION_KEY, "1.0.0"); polarisOperator.register(url.getServiceInterface(), url.getHost(), port, url.getProtocol(), version, weight, metadata); registeredInstances.add(url); @@ -94,7 +87,7 @@ public void doRegister(URL url) { } private boolean shouldRegister(URL url) { - return !StringUtils.equals(url.getProtocol(), CommonConstants.CONSUMER); + return StringUtils.equals(url.getProtocol(), CommonConstants.PROVIDER); } @Override diff --git a/dubbo/dubbo-plugins/dubbo-registry-polaris/src/main/java/com/tencent/polaris/dubbo/registry/PolarisRegistryFactory.java b/dubbo/dubbo-plugins/dubbo-registry-polaris/src/main/java/com/tencent/polaris/dubbo/registry/PolarisRegistryFactory.java index 4c6466a..60f0ea5 100644 --- a/dubbo/dubbo-plugins/dubbo-registry-polaris/src/main/java/com/tencent/polaris/dubbo/registry/PolarisRegistryFactory.java +++ b/dubbo/dubbo-plugins/dubbo-registry-polaris/src/main/java/com/tencent/polaris/dubbo/registry/PolarisRegistryFactory.java @@ -17,12 +17,24 @@ package com.tencent.polaris.dubbo.registry; +import com.tencent.polaris.api.utils.StringUtils; +import com.tencent.polaris.common.utils.Consts; 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 String createRegistryCacheKey(URL url) { + String namespace = url.getParameter(Consts.KEY_NAMESPACE); + url = URL.valueOf(url.toServiceStringWithoutResolving()); + if (StringUtils.isNotEmpty(namespace)) { + url = url.addParameter(Consts.KEY_NAMESPACE, namespace); + } + return url.toFullString(); + } + @Override protected Registry createRegistry(URL url) { PolarisRegistry polarisRegistry = new PolarisRegistry(url); diff --git a/dubbo/dubbo-plugins/dubbo-registry-polaris/src/main/java/com/tencent/polaris/dubbo/registry/PolarisServiceDiscovery.java b/dubbo/dubbo-plugins/dubbo-registry-polaris/src/main/java/com/tencent/polaris/dubbo/registry/PolarisServiceDiscovery.java new file mode 100644 index 0000000..0d62bc9 --- /dev/null +++ b/dubbo/dubbo-plugins/dubbo-registry-polaris/src/main/java/com/tencent/polaris/dubbo/registry/PolarisServiceDiscovery.java @@ -0,0 +1,212 @@ +/* + * Copyright 2019 NAVER Corp. + * + * Licensed 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 com.tencent.polaris.dubbo.registry; + +import com.tencent.polaris.api.core.ConsumerAPI; +import com.tencent.polaris.api.listener.ServiceListener; +import com.tencent.polaris.api.pojo.Instance; +import com.tencent.polaris.api.pojo.ServiceChangeEvent; +import com.tencent.polaris.api.pojo.ServiceInfo; +import com.tencent.polaris.api.rpc.UnWatchServiceRequest; +import com.tencent.polaris.api.rpc.WatchServiceRequest; +import com.tencent.polaris.api.utils.StringUtils; +import com.tencent.polaris.common.registry.PolarisOperator; +import com.tencent.polaris.common.registry.PolarisOperators; +import com.tencent.polaris.common.utils.Consts; +import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.utils.CollectionUtils; +import org.apache.dubbo.common.utils.ConcurrentHashSet; +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.rpc.model.ApplicationModel; +import org.apache.dubbo.rpc.model.ScopeModelUtil; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Function; +import java.util.stream.Collectors; + +public class PolarisServiceDiscovery extends AbstractServiceDiscovery { + + private final PolarisOperator operator; + + private final ConsumerAPI consumerAPI; + + private final Map listenerMap = new ConcurrentHashMap<>(); + + private Map> serviceListeners = new ConcurrentHashMap<>(); + + public PolarisServiceDiscovery(ApplicationModel applicationModel, URL url) { + super(applicationModel, url); + this.operator = PolarisOperators.INSTANCE.loadOrStoreForGovernance(url.getHost(), url.getPort(), url.getParameters()); + this.consumerAPI = operator.getConsumerAPI(); + } + + @Override + protected void doRegister(ServiceInstance instance) throws RuntimeException { + Map metadata = new HashMap<>(instance.getMetadata()); + metadata.remove(Consts.INSTANCE_WEIGHT); + metadata.remove(Consts.INSTANCE_VERSION); + if (CollectionUtils.isEmptyMap(metadata)) { + metadata = new HashMap<>(); + } + metadata.replaceAll((s, s2) -> StringUtils.defaultString(s2)); + operator.register( + serviceName, + instance.getHost(), + instance.getPort(), + "dubbo", + instance.getMetadata(Consts.INSTANCE_VERSION, "1.0.0"), + Integer.parseInt(instance.getMetadata(Consts.INSTANCE_WEIGHT, "100")), + metadata + ); + } + + @Override + protected void doUnregister(ServiceInstance instance) { + operator.deregister( + serviceName, + instance.getHost(), + instance.getPort() + ); + } + + @Override + protected void doDestroy() throws Exception { + operator.destroy(); + } + + @Override + public Set getServices() { + return operator.getServices().stream().map(ServiceInfo::getService).collect(Collectors.toSet()); + } + + @Override + public List getInstances(String serviceName) throws NullPointerException { + Instance[] instances = operator.getAvailableInstances(serviceName, true); + if (Objects.isNull(instances) || instances.length == 0) { + return Collections.emptyList(); + } + List ret = new ArrayList<>(instances.length); + for (Instance instance : instances) { + DefaultServiceInstance serviceInstance = + new DefaultServiceInstance( + instance.getService(), + instance.getHost(), instance.getPort(), + ScopeModelUtil.getApplicationModel(registryURL.getScopeModel())); + serviceInstance.setMetadata(instance.getMetadata()); + serviceInstance.setEnabled(!instance.isIsolated()); + serviceInstance.setHealthy(instance.isHealthy()); + ret.add(serviceInstance); + } + return ret; + } + + @Override + public void addServiceInstancesChangedListener(ServiceInstancesChangedListener + listener) throws NullPointerException, IllegalArgumentException { + if (!instanceListeners.add(listener)) { + return; + } + Set services = listener.getServiceNames(); + for (String service : services) { + serviceListeners.computeIfAbsent(service, name -> { + ServiceListener serviceListener = new InnerServiceListener(service); + listenerMap.put(service, serviceListener); + + WatchServiceRequest request = new WatchServiceRequest(); + request.setNamespace(operator.getPolarisConfig().getNamespace()); + request.setService(service); + request.setListeners(Collections.singletonList(serviceListener)); + consumerAPI.watchService(request); + return new ConcurrentHashSet<>(); + }); + + serviceListeners.get(service).add(listener); + } + } + + @Override + public void removeServiceInstancesChangedListener(ServiceInstancesChangedListener + listener) throws IllegalArgumentException { + if (!instanceListeners.remove(listener)) { + return; + } + Set services = listener.getServiceNames(); + for (String service : services) { + Set listeners = serviceListeners.get(service); + if (CollectionUtils.isEmpty(listeners)) { + serviceListeners.remove(service); + + ServiceListener serviceListener = listenerMap.remove(service); + if (Objects.nonNull(serviceListener)) { + UnWatchServiceRequest request = UnWatchServiceRequest.UnWatchServiceRequestBuilder + .anUnWatchServiceRequest() + .namespace(operator.getPolarisConfig().getNamespace()) + .service(service) + .listeners(Collections.singletonList(serviceListener)) + .build(); + consumerAPI.unWatchService(request); + } + continue; + } + listeners.remove(listener); + } + } + + private class InnerServiceListener implements ServiceListener{ + + private final String service; + + private InnerServiceListener(String service) { + this.service = service; + } + + @Override + public void onEvent(ServiceChangeEvent event) { + String serviceName = event.getServiceKey().getService(); + List serviceInstances = event.getAllInstances() + .stream() + .map((Function) instance -> { + DefaultServiceInstance serviceInstance = + new DefaultServiceInstance( + instance.getService(), + instance.getHost(), instance.getPort(), + ScopeModelUtil.getApplicationModel(registryURL.getScopeModel())); + serviceInstance.setMetadata(instance.getMetadata()); + serviceInstance.setEnabled(!instance.isIsolated()); + serviceInstance.setHealthy(instance.isHealthy()); + return serviceInstance; + }) + .collect(Collectors.toList()); + + Set listeners = serviceListeners.getOrDefault(service, Collections.emptySet()); + + ServiceInstancesChangedEvent changedEvent = new ServiceInstancesChangedEvent(serviceName, serviceInstances); + listeners.forEach(listener -> listener.onEvent(changedEvent)); + } + } +} diff --git a/dubbo/dubbo-plugins/dubbo-registry-polaris/src/main/java/com/tencent/polaris/dubbo/registry/PolarisServiceDiscoveryFactory.java b/dubbo/dubbo-plugins/dubbo-registry-polaris/src/main/java/com/tencent/polaris/dubbo/registry/PolarisServiceDiscoveryFactory.java new file mode 100644 index 0000000..17cedde --- /dev/null +++ b/dubbo/dubbo-plugins/dubbo-registry-polaris/src/main/java/com/tencent/polaris/dubbo/registry/PolarisServiceDiscoveryFactory.java @@ -0,0 +1,41 @@ +/* + * Copyright 2019 NAVER Corp. + * + * Licensed 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 com.tencent.polaris.dubbo.registry; + +import com.tencent.polaris.api.utils.StringUtils; +import com.tencent.polaris.common.utils.Consts; +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 String createRegistryCacheKey(URL url) { + String namespace = url.getParameter(Consts.KEY_NAMESPACE); + url = URL.valueOf(url.toServiceStringWithoutResolving()); + if (StringUtils.isNotEmpty(namespace)) { + url = url.addParameter(Consts.KEY_NAMESPACE, namespace); + } + return url.toFullString(); + } + + @Override + protected ServiceDiscovery createDiscovery(URL registryURL) { + return new PolarisServiceDiscovery(applicationModel, registryURL); + } +} diff --git a/dubbo/dubbo-plugins/dubbo-registry-polaris/src/main/java/com/tencent/polaris/dubbo/report/ReportFilter.java b/dubbo/dubbo-plugins/dubbo-registry-polaris/src/main/java/com/tencent/polaris/dubbo/report/ReportFilter.java index 2a1b1cd..e3cb130 100644 --- a/dubbo/dubbo-plugins/dubbo-registry-polaris/src/main/java/com/tencent/polaris/dubbo/report/ReportFilter.java +++ b/dubbo/dubbo-plugins/dubbo-registry-polaris/src/main/java/com/tencent/polaris/dubbo/report/ReportFilter.java @@ -22,8 +22,10 @@ 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.DubboServiceInfo; import com.tencent.polaris.common.registry.PolarisOperator; import com.tencent.polaris.common.registry.PolarisOperatorDelegate; +import com.tencent.polaris.common.utils.DubboUtils; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.extension.Activate; @@ -33,9 +35,13 @@ import org.apache.dubbo.rpc.Result; import org.apache.dubbo.rpc.RpcContext; import org.apache.dubbo.rpc.RpcException; +import org.apache.dubbo.rpc.model.ApplicationModel; +import org.apache.dubbo.rpc.model.ScopeModelAware; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.List; + @Activate(group = CommonConstants.CONSUMER, order = Integer.MIN_VALUE) public class ReportFilter extends PolarisOperatorDelegate implements Filter, Filter.Listener { @@ -43,6 +49,8 @@ public class ReportFilter extends PolarisOperatorDelegate implements Filter, Fil private static final Logger LOGGER = LoggerFactory.getLogger(ReportFilter.class); + private ApplicationModel applicationModel; + public ReportFilter() { LOGGER.info("[POLARIS] init polaris reporter"); } @@ -55,26 +63,29 @@ public Result invoke(Invoker invoker, Invocation invocation) throws RpcExcept @Override public void onResponse(Result appResponse, Invoker invoker, Invocation invocation) { - PolarisOperator polarisOperator = getPolarisOperator(); - if (null == polarisOperator) { - return; - } - Long startTimeMilli = (Long) invocation.get(LABEL_START_TIME); - RetStatus retStatus = RetStatus.RetSuccess; - int code = 0; - if (appResponse.hasException()) { - retStatus = RetStatus.RetFail; - code = -1; - } - URL url = invoker.getUrl(); - long delay = System.currentTimeMillis() - startTimeMilli; - polarisOperator.reportInvokeResult(url.getServiceInterface(), invocation.getMethodName(), url.getHost(), - url.getPort(), RpcContext.getContext().getLocalHost(), delay, retStatus, code); + PolarisOperator polarisOperator = getGovernancePolarisOperator(); + if (null == polarisOperator) { + return; + } + Long startTimeMilli = (Long) invocation.get(LABEL_START_TIME); + RetStatus retStatus = RetStatus.RetSuccess; + int code = 0; + if (appResponse.hasException()) { + retStatus = RetStatus.RetFail; + code = -1; + } + URL url = invoker.getUrl(); + long delay = System.currentTimeMillis() - startTimeMilli; + List serviceInfos = DubboUtils.analyzeDubboServiceInfo(applicationModel, invoker, invocation); + for (DubboServiceInfo serviceInfo : serviceInfos) { + polarisOperator.reportInvokeResult(serviceInfo.getService(), serviceInfo.getReportMethodName(), url.getHost(), + url.getPort(), RpcContext.getServiceContext().getLocalHost(), delay, retStatus, code); + } } @Override public void onError(Throwable t, Invoker invoker, Invocation invocation) { - PolarisOperator polarisOperator = getPolarisOperator(); + PolarisOperator polarisOperator = getGovernancePolarisOperator(); if (null == polarisOperator) { return; } @@ -96,8 +107,11 @@ public void onError(Throwable t, Invoker invoker, Invocation invocation) { } URL url = invoker.getUrl(); long delay = System.currentTimeMillis() - startTimeMilli; - polarisOperator.reportInvokeResult(url.getServiceInterface(), invocation.getMethodName(), url.getHost(), - url.getPort(), RpcContext.getContext().getLocalHost(), delay, retStatus, code); + List serviceInfos = DubboUtils.analyzeDubboServiceInfo(applicationModel, invoker, invocation); + for (DubboServiceInfo serviceInfo : serviceInfos) { + polarisOperator.reportInvokeResult(serviceInfo.getService(), serviceInfo.getReportMethodName(), url.getHost(), + url.getPort(), RpcContext.getServiceContext().getLocalHost(), delay, retStatus, code); + } } private boolean isFlowControl(RpcException rpcException) { @@ -106,4 +120,5 @@ private boolean isFlowControl(RpcException rpcException) { boolean b = rpcException.isLimitExceed(); return a || b; } + } diff --git a/dubbo/dubbo-plugins/dubbo-registry-polaris/src/main/resources/META-INF/dubbo/org.apache.dubbo.registry.RegistryFactory b/dubbo/dubbo-plugins/dubbo-registry-polaris/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.RegistryFactory similarity index 100% rename from dubbo/dubbo-plugins/dubbo-registry-polaris/src/main/resources/META-INF/dubbo/org.apache.dubbo.registry.RegistryFactory rename to dubbo/dubbo-plugins/dubbo-registry-polaris/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.RegistryFactory diff --git a/dubbo/dubbo-plugins/dubbo-registry-polaris/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.ServiceDiscoveryFactory b/dubbo/dubbo-plugins/dubbo-registry-polaris/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.ServiceDiscoveryFactory new file mode 100644 index 0000000..dec6ab1 --- /dev/null +++ b/dubbo/dubbo-plugins/dubbo-registry-polaris/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.ServiceDiscoveryFactory @@ -0,0 +1 @@ +polaris=com.tencent.polaris.dubbo.registry.PolarisServiceDiscoveryFactory \ No newline at end of file diff --git a/dubbo/dubbo-plugins/dubbo-registry-polaris/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter b/dubbo/dubbo-plugins/dubbo-registry-polaris/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter similarity index 100% rename from dubbo/dubbo-plugins/dubbo-registry-polaris/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter rename to dubbo/dubbo-plugins/dubbo-registry-polaris/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter diff --git a/dubbo/dubbo-plugins/dubbo-router-polaris/pom.xml b/dubbo/dubbo-plugins/dubbo-router-polaris/pom.xml index 8948d1d..ce31d5f 100644 --- a/dubbo/dubbo-plugins/dubbo-router-polaris/pom.xml +++ b/dubbo/dubbo-plugins/dubbo-router-polaris/pom.xml @@ -18,15 +18,5 @@ dubbo-registry-polaris ${project.version} - - org.apache.dubbo - dubbo - provided - - - org.slf4j - slf4j-api - provided - \ No newline at end of file diff --git a/dubbo/dubbo-plugins/dubbo-router-polaris/src/main/java/com/tencent/polaris/dubbo/router/InstanceInvoker.java b/dubbo/dubbo-plugins/dubbo-router-polaris/src/main/java/com/tencent/polaris/dubbo/router/InstanceInvoker.java index b8d960f..a2ed49d 100644 --- a/dubbo/dubbo-plugins/dubbo-router-polaris/src/main/java/com/tencent/polaris/dubbo/router/InstanceInvoker.java +++ b/dubbo/dubbo-plugins/dubbo-router-polaris/src/main/java/com/tencent/polaris/dubbo/router/InstanceInvoker.java @@ -25,7 +25,8 @@ import java.util.Map; import java.util.Objects; -import com.tencent.polaris.common.registry.Consts; +import com.tencent.polaris.common.registry.DubboServiceInfo; +import com.tencent.polaris.common.utils.Consts; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.rpc.Invocation; @@ -44,7 +45,7 @@ public class InstanceInvoker implements Instance, Invoker { private final DefaultInstance defaultInstance; - public InstanceInvoker(Invoker invoker, String namespace) { + public InstanceInvoker(Invoker invoker, DubboServiceInfo serviceInfo, String namespace) { this.invoker = invoker; defaultInstance = new DefaultInstance(); defaultInstance.setNamespace(namespace); diff --git a/dubbo/dubbo-plugins/dubbo-router-polaris/src/main/java/com/tencent/polaris/dubbo/router/PolarisRouter.java b/dubbo/dubbo-plugins/dubbo-router-polaris/src/main/java/com/tencent/polaris/dubbo/router/PolarisRouter.java index 882eddd..934288f 100644 --- a/dubbo/dubbo-plugins/dubbo-router-polaris/src/main/java/com/tencent/polaris/dubbo/router/PolarisRouter.java +++ b/dubbo/dubbo-plugins/dubbo-router-polaris/src/main/java/com/tencent/polaris/dubbo/router/PolarisRouter.java @@ -23,92 +23,108 @@ import com.tencent.polaris.api.pojo.ServiceRule; import com.tencent.polaris.api.utils.StringUtils; import com.tencent.polaris.common.parser.QueryParser; +import com.tencent.polaris.common.registry.DubboServiceInfo; import com.tencent.polaris.common.registry.PolarisOperator; import com.tencent.polaris.common.registry.PolarisOperators; import com.tencent.polaris.common.router.RuleHandler; +import com.tencent.polaris.common.utils.DubboUtils; import com.tencent.polaris.specification.api.v1.traffic.manage.RoutingProto; import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; +import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.CollectionUtils; 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; import org.apache.dubbo.rpc.cluster.router.AbstractRouter; +import org.apache.dubbo.rpc.cluster.router.RouterResult; +import org.apache.dubbo.rpc.model.ApplicationModel; +import org.apache.dubbo.rpc.model.ScopeModelAware; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.HashSet; import java.util.List; +import java.util.Objects; import java.util.Optional; import java.util.Set; -public class PolarisRouter extends AbstractRouter { +public class PolarisRouter extends AbstractRouter implements ScopeModelAware { - private static final Logger LOGGER = LoggerFactory.getLogger(PolarisRouter.class); + protected final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(getClass()); private final RuleHandler routeRuleHandler; - private final PolarisOperator polarisOperator; + private final PolarisOperator operator; private final QueryParser parser; + private ApplicationModel applicationModel; + public PolarisRouter(URL url) { super(url); - LOGGER.info("[POLARIS] init service router, url is {}, parameters are {}", url, - url.getParameters()); - this.priority = url.getParameter(Constants.PRIORITY_KEY, 0); - routeRuleHandler = new RuleHandler(); - polarisOperator = PolarisOperators.INSTANCE.getPolarisOperator(url.getHost(), url.getPort()); - parser = QueryParser.load(); + logger.info(String.format("[POLARIS] init service router, url is %s, parameters are %s", url, + url.getParameters())); + this.routeRuleHandler = new RuleHandler(); + this.operator = PolarisOperators.INSTANCE.getGovernancePolarisOperator(); + this.parser = QueryParser.load(); } @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; + public RouterResult> route(List> invokers, URL url, Invocation invocation, boolean needToPrintMessage) throws RpcException { + if (CollectionUtils.isEmpty(invokers) || Objects.isNull(operator)) { + return new RouterResult<>(invokers); } - 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())); - } + List serviceInfos = DubboUtils.analyzeDubboServiceInfo(applicationModel, url, invocation); + for (DubboServiceInfo serviceInfo : serviceInfos) { + RouterResult> result = realRoute(invokers, url, invocation, serviceInfo); + if (!result.getResult().isEmpty()) { + return result; + } } + return new RouterResult<>(invokers); + } - String service = url.getServiceInterface(); - ServiceRule serviceRule = polarisOperator.getServiceRule(service, EventType.ROUTING); + @SuppressWarnings("unchecked") + public RouterResult> realRoute(List> invokers, URL url, Invocation invocation, DubboServiceInfo serviceInfo) { + List instances = new ArrayList<>(invokers.size()); + for (Invoker invoker : invokers) { + instances.add(new InstanceInvoker<>(invoker, null, operator.getPolarisConfig().getNamespace())); + } + ServiceRule serviceRule = operator.getServiceRule(serviceInfo.getService(), EventType.ROUTING); Object ruleObject = serviceRule.getRule(); + if (Objects.isNull(ruleObject)) { + return new RouterResult<>(invokers); + } Set arguments = new HashSet<>(); - if (null != ruleObject) { - RoutingProto.Routing routing = (RoutingProto.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)) { - Optional value = parser.parse(queryName, invocation.getArguments()); - value.ifPresent(s -> arguments.add(RouteArgument.buildQuery(queryName, s))); - } + RoutingProto.Routing routing = (RoutingProto.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.getClientAttachment().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)) { + Optional value = parser.parse(queryName, invocation.getArguments()); + value.ifPresent(s -> arguments.add(RouteArgument.buildQuery(queryName, s))); } } } - LOGGER.debug("[POLARIS] list service {}, method {}, labels {}, url {}", service, - invocation.getMethodName(), arguments, url); - List resultInstances = polarisOperator.route(service, invocation.getMethodName(), arguments, instances); - return (List>) ((List) resultInstances); + logger.debug(String.format("[POLARIS] list service(%s), method(%s), labels(%s), url(%s)", serviceInfo.getService(), + invocation.getMethodName(), arguments, url)); + List resultInstances = operator.route(serviceInfo.getService(), invocation.getMethodName(), arguments, instances); + return new RouterResult<>((List>) ((List) resultInstances)); + } + + @Override + public void setApplicationModel(ApplicationModel applicationModel) { + this.applicationModel = applicationModel; } } diff --git a/dubbo/dubbo-plugins/pom.xml b/dubbo/dubbo-plugins/pom.xml index f38ac80..5f56dfa 100644 --- a/dubbo/dubbo-plugins/pom.xml +++ b/dubbo/dubbo-plugins/pom.xml @@ -18,6 +18,8 @@ dubbo-router-polaris dubbo-ratelimit-polaris dubbo-circuitbreaker-polaris + dubbo-configcenter-polaris + dubbo-metadatareport-polaris \ No newline at end of file diff --git a/dubbo/pom.xml b/dubbo/pom.xml index 6d04263..d3c34bf 100644 --- a/dubbo/pom.xml +++ b/dubbo/pom.xml @@ -13,42 +13,9 @@ dubbo pom - - 2.7.18 - - dubbo-plugins dubbo-examples - - - - org.apache.dubbo - dubbo - ${apache.dubbo.version} - - - org.apache.dubbo - dubbo-config-api - ${apache.dubbo.version} - - - org.apache.dubbo - dubbo-rpc-dubbo - ${apache.dubbo.version} - - - org.apache.dubbo - dubbo-remoting-netty4 - ${apache.dubbo.version} - - - org.apache.dubbo - dubbo-serialization-hessian2 - ${apache.dubbo.version} - - - \ No newline at end of file diff --git a/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-consumer/pom.xml b/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-consumer/pom.xml deleted file mode 100644 index 1ea0bc1..0000000 --- a/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-consumer/pom.xml +++ /dev/null @@ -1,59 +0,0 @@ - - - - dubbox-discovery-example - com.tencent.polaris - ${revision} - ../pom.xml - - 4.0.0 - - dubbox-discovery-consumer - - - - com.tencent.polaris - dubbox-discovery-example-api - ${project.version} - - - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.0.0 - - - package - - shade - - - - - *:* - - META-INF/*.SF - META-INF/*.DSA - META-INF/*.RSA - - - - - - com.tencent.polaris.dubbox.discovery.consumer.DemoConsumer - - - - - - - - - - \ No newline at end of file diff --git a/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-consumer/src/main/java/com/tencent/polaris/dubbox/discovery/consumer/DemoAction.java b/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-consumer/src/main/java/com/tencent/polaris/dubbox/discovery/consumer/DemoAction.java deleted file mode 100644 index 5bf73d5..0000000 --- a/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-consumer/src/main/java/com/tencent/polaris/dubbox/discovery/consumer/DemoAction.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Polaris available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * 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 com.tencent.polaris.dubbox.discovery.consumer; - -import com.alibaba.dubbo.config.ReferenceConfig; -import com.tencent.polaris.dubbox.discovery.example.api.BidRequest; -import com.tencent.polaris.dubbox.discovery.example.api.BidService; -import com.tencent.polaris.dubbox.discovery.example.api.Device; -import com.tencent.polaris.dubbox.discovery.example.api.Geo; -import com.tencent.polaris.dubbox.discovery.example.api.Impression; -import java.util.ArrayList; -import java.util.List; - -public class DemoAction { - - private BidService bidService; - - public BidService getBidService() { - return bidService; - } - - public void setBidService(BidService bidService) { - this.bidService = bidService; - } - - public void start() { - BidRequest request = new BidRequest(); - - Impression imp = new Impression(); - imp.setBidFloor(1.1); - imp.setId("abc"); - List imps = new ArrayList(1); - imps.add(imp); - request.setImpressions(imps); - - Geo geo = new Geo(); - geo.setCity("beijing"); - geo.setCountry("china"); - geo.setLat(100.1f); - geo.setLon(100.1f); - - Device device = new Device(); - device.setMake("apple"); - device.setOs("ios"); - device.setVersion("7.0"); - device.setLang("zh_CN"); - device.setModel("iphone"); - device.setGeo(geo); - request.setDevice(device); - - for (int i = 0; i < 10; i++) { - try { - System.out.println(bidService.bid(request).getId()); - System.out.println("SUCESS: got bid response id: " + bidService.bid(request).getId()); - } catch (Throwable e) { - System.out.printf("exception caugh %s%n", e.getMessage()); - try { - Thread.sleep(1000); - } catch (InterruptedException interruptedException) { - interruptedException.printStackTrace(); - } - } - } - } - -} diff --git a/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-consumer/src/main/java/com/tencent/polaris/dubbox/discovery/consumer/DemoConsumer.java b/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-consumer/src/main/java/com/tencent/polaris/dubbox/discovery/consumer/DemoConsumer.java deleted file mode 100644 index b2d2f2c..0000000 --- a/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-consumer/src/main/java/com/tencent/polaris/dubbox/discovery/consumer/DemoConsumer.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Polaris available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * 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 com.tencent.polaris.dubbox.discovery.consumer; - -public class DemoConsumer { - - public static void main(String[] args) { - com.alibaba.dubbo.container.Main.main(args); - } - -} \ No newline at end of file diff --git a/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-consumer/src/main/resources/META-INF/spring/discovery-demo-action.xml b/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-consumer/src/main/resources/META-INF/spring/discovery-demo-action.xml deleted file mode 100644 index 91f51a3..0000000 --- a/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-consumer/src/main/resources/META-INF/spring/discovery-demo-action.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-consumer/src/main/resources/META-INF/spring/discovery-demo-consumer.xml b/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-consumer/src/main/resources/META-INF/spring/discovery-demo-consumer.xml deleted file mode 100644 index d86b1ed..0000000 --- a/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-consumer/src/main/resources/META-INF/spring/discovery-demo-consumer.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-consumer/src/main/resources/log4j.xml b/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-consumer/src/main/resources/log4j.xml deleted file mode 100644 index 1c80705..0000000 --- a/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-consumer/src/main/resources/log4j.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-example-api/pom.xml b/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-example-api/pom.xml deleted file mode 100644 index 13f0d7f..0000000 --- a/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-example-api/pom.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - dubbox-discovery-example - com.tencent.polaris - ${revision} - ../pom.xml - - 4.0.0 - - dubbox-discovery-example-api - - - \ No newline at end of file diff --git a/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-example-api/src/main/java/com/tencent/polaris/dubbox/discovery/example/api/BidRequest.java b/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-example-api/src/main/java/com/tencent/polaris/dubbox/discovery/example/api/BidRequest.java deleted file mode 100644 index ea3ef65..0000000 --- a/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-example-api/src/main/java/com/tencent/polaris/dubbox/discovery/example/api/BidRequest.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Copyright 1999-2014 dangdang.com. - * - * Licensed 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 com.tencent.polaris.dubbox.discovery.example.api; - -import java.io.Serializable; -import java.util.List; - -public class BidRequest implements Serializable { - - private String id; - - private Device device; - - private List impressions; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public Device getDevice() { - return device; - } - - public void setDevice(Device device) { - this.device = device; - } - - public List getImpressions() { - return impressions; - } - - public void setImpressions(List impressions) { - this.impressions = impressions; - } -} diff --git a/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-example-api/src/main/java/com/tencent/polaris/dubbox/discovery/example/api/BidResponse.java b/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-example-api/src/main/java/com/tencent/polaris/dubbox/discovery/example/api/BidResponse.java deleted file mode 100644 index b4a02fa..0000000 --- a/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-example-api/src/main/java/com/tencent/polaris/dubbox/discovery/example/api/BidResponse.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright 1999-2014 dangdang.com. - * - * Licensed 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 com.tencent.polaris.dubbox.discovery.example.api; - -import java.io.Serializable; -import java.util.List; - -public class BidResponse implements Serializable { - - private String id; - private List seatBids; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public List getSeatBids() { - return seatBids; - } - - public void setSeatBids(List seatBids) { - this.seatBids = seatBids; - } -} diff --git a/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-example-api/src/main/java/com/tencent/polaris/dubbox/discovery/example/api/BidService.java b/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-example-api/src/main/java/com/tencent/polaris/dubbox/discovery/example/api/BidService.java deleted file mode 100644 index 1548be2..0000000 --- a/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-example-api/src/main/java/com/tencent/polaris/dubbox/discovery/example/api/BidService.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Polaris available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * 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 com.tencent.polaris.dubbox.discovery.example.api; - -public interface BidService { - - BidResponse bid(BidRequest request); - - void throwNPE() throws NullPointerException; -} diff --git a/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-example-api/src/main/java/com/tencent/polaris/dubbox/discovery/example/api/Device.java b/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-example-api/src/main/java/com/tencent/polaris/dubbox/discovery/example/api/Device.java deleted file mode 100644 index d75dddc..0000000 --- a/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-example-api/src/main/java/com/tencent/polaris/dubbox/discovery/example/api/Device.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * Copyright 1999-2014 dangdang.com. - * - * Licensed 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 com.tencent.polaris.dubbox.discovery.example.api; - -import java.io.Serializable; - -public class Device implements Serializable { - - private String os; - private String make; - private String version; - private String model; - private String lang; - private Geo geo; - - public String getOs() { - return os; - } - - public void setOs(String os) { - this.os = os; - } - - public String getMake() { - return make; - } - - public void setMake(String make) { - this.make = make; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - public String getModel() { - return model; - } - - public void setModel(String model) { - this.model = model; - } - - public String getLang() { - return lang; - } - - public void setLang(String lang) { - this.lang = lang; - } - - public Geo getGeo() { - return geo; - } - - public void setGeo(Geo geo) { - this.geo = geo; - } -} diff --git a/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-example-api/src/main/java/com/tencent/polaris/dubbox/discovery/example/api/Geo.java b/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-example-api/src/main/java/com/tencent/polaris/dubbox/discovery/example/api/Geo.java deleted file mode 100644 index 40b645e..0000000 --- a/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-example-api/src/main/java/com/tencent/polaris/dubbox/discovery/example/api/Geo.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Copyright 1999-2014 dangdang.com. - * - * Licensed 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 com.tencent.polaris.dubbox.discovery.example.api; - -import java.io.Serializable; - -public class Geo implements Serializable { - - private float lon; - private float lat; - private String country; - private String city; - - public float getLon() { - return lon; - } - - public void setLon(float lon) { - this.lon = lon; - } - - public float getLat() { - return lat; - } - - public void setLat(float lat) { - this.lat = lat; - } - - public String getCountry() { - return country; - } - - public void setCountry(String country) { - this.country = country; - } - - public String getCity() { - return city; - } - - public void setCity(String city) { - this.city = city; - } -} diff --git a/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-example-api/src/main/java/com/tencent/polaris/dubbox/discovery/example/api/Impression.java b/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-example-api/src/main/java/com/tencent/polaris/dubbox/discovery/example/api/Impression.java deleted file mode 100644 index 3603352..0000000 --- a/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-example-api/src/main/java/com/tencent/polaris/dubbox/discovery/example/api/Impression.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright 1999-2014 dangdang.com. - * - * Licensed 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 com.tencent.polaris.dubbox.discovery.example.api; - -import java.io.Serializable; - -public class Impression implements Serializable { - - private String id; - private double bidFloor; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public double getBidFloor() { - return bidFloor; - } - - public void setBidFloor(double bidFloor) { - this.bidFloor = bidFloor; - } -} diff --git a/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-example-api/src/main/java/com/tencent/polaris/dubbox/discovery/example/api/SeatBid.java b/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-example-api/src/main/java/com/tencent/polaris/dubbox/discovery/example/api/SeatBid.java deleted file mode 100644 index 7c797a8..0000000 --- a/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-example-api/src/main/java/com/tencent/polaris/dubbox/discovery/example/api/SeatBid.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright 1999-2014 dangdang.com. - * - * Licensed 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 com.tencent.polaris.dubbox.discovery.example.api; - -import java.io.Serializable; - -public class SeatBid implements Serializable { - - private String seat; - - private String group; - - public String getSeat() { - return seat; - } - - public void setSeat(String seat) { - this.seat = seat; - } - - public String getGroup() { - return group; - } - - public void setGroup(String group) { - this.group = group; - } -} diff --git a/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-provider/pom.xml b/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-provider/pom.xml deleted file mode 100644 index 041c013..0000000 --- a/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-provider/pom.xml +++ /dev/null @@ -1,66 +0,0 @@ - - - - dubbox-discovery-example - com.tencent.polaris - ${revision} - ../pom.xml - - 4.0.0 - - dubbox-discovery-provider - war - - - - com.tencent.polaris - dubbox-discovery-example-api - ${project.version} - - - - com.alibaba - dubbo-remoting-netty - ${alibaba.dubbo.version} - - - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.0.0 - - - package - - shade - - - - - *:* - - META-INF/*.SF - META-INF/*.DSA - META-INF/*.RSA - - - - - - com.tencent.polaris.dubbox.discovery.provider.Application - - - - - - - - - - \ No newline at end of file diff --git a/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-provider/src/main/java/com/tencent/polaris/dubbox/discovery/provider/Application.java b/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-provider/src/main/java/com/tencent/polaris/dubbox/discovery/provider/Application.java deleted file mode 100644 index 3c75f96..0000000 --- a/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-provider/src/main/java/com/tencent/polaris/dubbox/discovery/provider/Application.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Polaris available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * 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 com.tencent.polaris.dubbox.discovery.provider; - -public class Application { - - public static void main(String[] args) { - com.alibaba.dubbo.container.Main.main(args); - } - -} diff --git a/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-provider/src/main/java/com/tencent/polaris/dubbox/discovery/provider/BidServiceImpl.java b/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-provider/src/main/java/com/tencent/polaris/dubbox/discovery/provider/BidServiceImpl.java deleted file mode 100644 index 6016e38..0000000 --- a/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-provider/src/main/java/com/tencent/polaris/dubbox/discovery/provider/BidServiceImpl.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Polaris available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * 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 com.tencent.polaris.dubbox.discovery.provider; - -import com.tencent.polaris.dubbox.discovery.example.api.BidRequest; -import com.tencent.polaris.dubbox.discovery.example.api.BidResponse; -import com.tencent.polaris.dubbox.discovery.example.api.BidService; -import com.tencent.polaris.dubbox.discovery.example.api.SeatBid; -import java.util.ArrayList; -import java.util.List; - -public class BidServiceImpl implements BidService { - - public BidResponse bid(BidRequest request) { - BidResponse response = new BidResponse(); - - response.setId("abc"); - - SeatBid seatBid = new SeatBid(); - seatBid.setGroup("group"); - seatBid.setSeat("seat"); - List seatBids = new ArrayList(1); - seatBids.add(seatBid); - - response.setSeatBids(seatBids); - - return response; - } - - public void throwNPE() throws NullPointerException { - throw new NullPointerException(); - } -} diff --git a/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-provider/src/main/resources/META-INF/spring/dubbox-discovery-provider.xml b/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-provider/src/main/resources/META-INF/spring/dubbox-discovery-provider.xml deleted file mode 100644 index 6812873..0000000 --- a/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-provider/src/main/resources/META-INF/spring/dubbox-discovery-provider.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-provider/src/main/resources/log4j.xml b/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-provider/src/main/resources/log4j.xml deleted file mode 100644 index ae988c3..0000000 --- a/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-provider/src/main/resources/log4j.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-provider/src/main/webapp/WEB-INF/web.xml b/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-provider/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index 21d048b..0000000 --- a/dubbox/dubbox-examples/dubbox-discovery-example/dubbox-discovery-provider/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - contextConfigLocation - /WEB-INF/classes/META-INF/spring/dubbox-discovery-provider.xml - - - - - com.alibaba.dubbo.remoting.http.servlet.BootstrapListener - - - - org.springframework.web.context.ContextLoaderListener - - - - dispatcher - com.alibaba.dubbo.remoting.http.servlet.DispatcherServlet - 1 - - - - dispatcher - /services/* - - \ No newline at end of file diff --git a/dubbox/dubbox-examples/dubbox-discovery-example/pom.xml b/dubbox/dubbox-examples/dubbox-discovery-example/pom.xml deleted file mode 100644 index 21cdc0b..0000000 --- a/dubbox/dubbox-examples/dubbox-discovery-example/pom.xml +++ /dev/null @@ -1,294 +0,0 @@ - - - - dubbox-examples - com.tencent.polaris - ${revision} - ../pom.xml - - 4.0.0 - - dubbox-discovery-example - pom - - dubbox-discovery-example-api - dubbox-discovery-provider - dubbox-discovery-consumer - - - - - com.tencent.polaris - dubbox-registry-polaris - ${project.version} - - - com.alibaba - dubbo - - - org.javassist - javassist - - - io.netty - netty-all - ${netty_version} - - - org.apache.mina - mina-core - - - org.glassfish.grizzly - grizzly-core - - - org.apache.httpcomponents - httpclient - - - com.alibaba - fastjson - - - com.thoughtworks.xstream - xstream - - - org.apache.bsf - bsf-api - - - org.apache.zookeeper - zookeeper - - - com.github.sgroschupf - zkclient - - - org.apache.curator - curator-framework - - - com.googlecode.xmemcached - xmemcached - - - org.apache.cxf - cxf-rt-frontend-simple - - - org.apache.cxf - cxf-rt-transports-http - - - org.apache.thrift - libthrift - - - com.caucho - hessian - - - javax.servlet - javax.servlet-api - - - org.mortbay.jetty - jetty - - - org.mortbay.jetty - servlet-api - - - - - log4j - log4j - - - org.slf4j - slf4j-api - - - redis.clients - jedis - - - javax.validation - validation-api - - - org.hibernate - hibernate-validator - - - javax.cache - cache-api - - - - org.jboss.resteasy - resteasy-jaxrs - - - - org.jboss.resteasy - resteasy-client - - - - org.jboss.resteasy - resteasy-netty - - - - org.jboss.resteasy - resteasy-jdk-http - - - - org.jboss.resteasy - resteasy-jackson-provider - - - - org.jboss.resteasy - resteasy-jaxb-provider - - - - org.apache.tomcat.embed - tomcat-embed-core - - - org.apache.tomcat.embed - tomcat-embed-logging-juli - - - - com.esotericsoftware.kryo - kryo - - - de.javakaffee - kryo-serializers - - - de.ruedigermoeller - fst - - - org.springframework - spring-web - - - - - - - org.apache.maven.plugins - maven-jar-plugin - - - true - true - - true - true - - - - - - maven-source-plugin - - - attach-sources - package - - jar-no-fork - - - - - - org.apache.maven.plugins - maven-surefire-plugin - ${maven-surefire-plugin_version} - - - - - - - org.apache.maven.plugins - maven-jar-plugin - ${maven_jar_plugin_version} - - - org.apache.maven.plugins - maven-war-plugin - ${maven_war_plugin_version} - - - org.apache.maven.plugins - maven-install-plugin - ${maven_install_plugin_version} - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven_compiler_plugin_version} - - true - ${java_source_version} - ${java_target_version} - ${file_encoding} - - - - - - - - org.eclipse.m2e - lifecycle-mapping - 1.0.0 - - - - - - - org.apache.maven.plugins - - - maven-dependency-plugin - - - [2.1,) - - - unpack - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-consumer/pom.xml b/dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-consumer/pom.xml deleted file mode 100644 index 9943d2b..0000000 --- a/dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-consumer/pom.xml +++ /dev/null @@ -1,59 +0,0 @@ - - - - dubbox-ratelimit-example - com.tencent.polaris - ${revision} - ../pom.xml - - 4.0.0 - - dubbox-ratelimit-consumer - - - - com.tencent.polaris - dubbox-ratelimit-example-api - ${project.version} - - - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.0.0 - - - package - - shade - - - - - *:* - - META-INF/*.SF - META-INF/*.DSA - META-INF/*.RSA - - - - - - com.tencent.polaris.dubbox.ratelimit.consumer.Application - - - - - - - - - - \ No newline at end of file diff --git a/dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-consumer/src/main/java/com/tencent/polaris/dubbox/ratelimit/consumer/Application.java b/dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-consumer/src/main/java/com/tencent/polaris/dubbox/ratelimit/consumer/Application.java deleted file mode 100644 index 44cd7a3..0000000 --- a/dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-consumer/src/main/java/com/tencent/polaris/dubbox/ratelimit/consumer/Application.java +++ /dev/null @@ -1,25 +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 com.tencent.polaris.dubbox.ratelimit.consumer; -public class Application { - - public static void main(String[] args) { - com.alibaba.dubbo.container.Main.main(args); - } - -} diff --git a/dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-consumer/src/main/java/com/tencent/polaris/dubbox/ratelimit/consumer/RatelimitAction.java b/dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-consumer/src/main/java/com/tencent/polaris/dubbox/ratelimit/consumer/RatelimitAction.java deleted file mode 100644 index 773ad4a..0000000 --- a/dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-consumer/src/main/java/com/tencent/polaris/dubbox/ratelimit/consumer/RatelimitAction.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Polaris available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * 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 com.tencent.polaris.dubbox.ratelimit.consumer; - -import com.alibaba.dubbo.rpc.RpcContext; -import com.alibaba.dubbo.rpc.RpcException; -import com.tencent.polaris.dubbox.ratelimit.example.api.User; -import com.tencent.polaris.dubbox.ratelimit.example.api.UserService; - -public class RatelimitAction { - - private UserService userService; - - public UserService getUserService() { - return userService; - } - - public void setUserService(UserService userService) { - this.userService = userService; - } - - public void start() { - System.out.println("start to invoke archer"); - int pass = 0; - int block = 0; - for (int i = 0; i < 1000; i++) { - if (register("jason")) { - pass++; - } else { - block++; - } - } - System.out.printf("register archer passed %d, blocked %d%n", pass, block); - try { - Thread.sleep(2000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - System.out.println("start to invoke tommy"); - pass = 0; - block = 0; - for (int i = 0; i < 1000; i++) { - if (register("tommy")) { - pass++; - } else { - block++; - } - } - System.out.printf("register tommy passed %d, blocked %d%n", pass, block); - } - - private boolean register(String name) { - User user = new User(); - user.setName(name); - RpcContext.getContext().setAttachment("user", name); - try { - userService.registerUser(user); - } catch (Exception e) { - if (e instanceof RpcException) { - return false; - } - throw new RuntimeException(e); - } - return true; - } -} diff --git a/dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-consumer/src/main/resources/META-INF/spring/ratelimit-demo-consumer.xml b/dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-consumer/src/main/resources/META-INF/spring/ratelimit-demo-consumer.xml deleted file mode 100644 index 805c026..0000000 --- a/dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-consumer/src/main/resources/META-INF/spring/ratelimit-demo-consumer.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-consumer/src/main/resources/log4j.xml b/dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-consumer/src/main/resources/log4j.xml deleted file mode 100644 index fb82d11..0000000 --- a/dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-consumer/src/main/resources/log4j.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - ` - - - - - - - - - - - - - - \ No newline at end of file diff --git a/dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-example-api/pom.xml b/dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-example-api/pom.xml deleted file mode 100644 index b6908e2..0000000 --- a/dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-example-api/pom.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - dubbox-ratelimit-example - com.tencent.polaris - ${revision} - ../pom.xml - - 4.0.0 - - dubbox-ratelimit-example-api - - \ No newline at end of file diff --git a/dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-example-api/src/main/java/com/tencent/polaris/dubbox/ratelimit/example/api/User.java b/dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-example-api/src/main/java/com/tencent/polaris/dubbox/ratelimit/example/api/User.java deleted file mode 100644 index 73c8ebe..0000000 --- a/dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-example-api/src/main/java/com/tencent/polaris/dubbox/ratelimit/example/api/User.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Polaris available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * 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 com.tencent.polaris.dubbox.ratelimit.example.api; - -public class User { - - private Long id; - - private String name; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } -} diff --git a/dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-example-api/src/main/java/com/tencent/polaris/dubbox/ratelimit/example/api/UserService.java b/dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-example-api/src/main/java/com/tencent/polaris/dubbox/ratelimit/example/api/UserService.java deleted file mode 100644 index f2fa49d..0000000 --- a/dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-example-api/src/main/java/com/tencent/polaris/dubbox/ratelimit/example/api/UserService.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Polaris available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * 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 com.tencent.polaris.dubbox.ratelimit.example.api; - -public interface UserService { - - Long registerUser(User user); -} diff --git a/dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-provider/pom.xml b/dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-provider/pom.xml deleted file mode 100644 index f0d0a6b..0000000 --- a/dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-provider/pom.xml +++ /dev/null @@ -1,61 +0,0 @@ - - - - dubbox-ratelimit-example - com.tencent.polaris - ${revision} - ../pom.xml - - 4.0.0 - - dubbox-ratelimit-provider - - war - - - - com.tencent.polaris - dubbox-ratelimit-example-api - ${project.version} - - - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.0.0 - - - package - - shade - - - - - *:* - - META-INF/*.SF - META-INF/*.DSA - META-INF/*.RSA - - - - - - com.tencent.polaris.dubbox.ratelimit.provider.Application - - - - - - - - - - \ No newline at end of file diff --git a/dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-provider/src/main/java/com/tencent/polaris/dubbox/ratelimit/provider/Application.java b/dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-provider/src/main/java/com/tencent/polaris/dubbox/ratelimit/provider/Application.java deleted file mode 100644 index 5b8c8bf..0000000 --- a/dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-provider/src/main/java/com/tencent/polaris/dubbox/ratelimit/provider/Application.java +++ /dev/null @@ -1,26 +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 com.tencent.polaris.dubbox.ratelimit.provider; - -public class Application { - - public static void main(String[] args) { - com.alibaba.dubbo.container.Main.main(args); - } - -} diff --git a/dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-provider/src/main/java/com/tencent/polaris/dubbox/ratelimit/provider/UserServiceImpl.java b/dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-provider/src/main/java/com/tencent/polaris/dubbox/ratelimit/provider/UserServiceImpl.java deleted file mode 100644 index 4a6e8b9..0000000 --- a/dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-provider/src/main/java/com/tencent/polaris/dubbox/ratelimit/provider/UserServiceImpl.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Polaris available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * 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 com.tencent.polaris.dubbox.ratelimit.provider; - -import com.tencent.polaris.dubbox.ratelimit.example.api.User; -import com.tencent.polaris.dubbox.ratelimit.example.api.UserService; -import java.util.concurrent.atomic.AtomicLong; - -public class UserServiceImpl implements UserService { - - private final AtomicLong index = new AtomicLong(0); - - @Override - public Long registerUser(User user) { - return index.incrementAndGet(); - } -} diff --git a/dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-provider/src/main/resources/META-INF/spring/dubbox-ratelimit-provider.xml b/dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-provider/src/main/resources/META-INF/spring/dubbox-ratelimit-provider.xml deleted file mode 100644 index b7bb287..0000000 --- a/dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-provider/src/main/resources/META-INF/spring/dubbox-ratelimit-provider.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-provider/src/main/resources/log4j.xml b/dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-provider/src/main/resources/log4j.xml deleted file mode 100644 index ae988c3..0000000 --- a/dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-provider/src/main/resources/log4j.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-provider/src/main/webapp/WEB-INF/web.xml b/dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-provider/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index e08b3d3..0000000 --- a/dubbox/dubbox-examples/dubbox-ratelimit-example/dubbox-ratelimit-provider/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - contextConfigLocation - /WEB-INF/classes/META-INF/spring/dubbox-ratelimit-provider.xml - - - - - com.alibaba.dubbo.remoting.http.servlet.BootstrapListener - - - - org.springframework.web.context.ContextLoaderListener - - - - dispatcher - com.alibaba.dubbo.remoting.http.servlet.DispatcherServlet - 1 - - - - dispatcher - /services/* - - \ No newline at end of file diff --git a/dubbox/dubbox-examples/dubbox-ratelimit-example/pom.xml b/dubbox/dubbox-examples/dubbox-ratelimit-example/pom.xml deleted file mode 100644 index fd6a95e..0000000 --- a/dubbox/dubbox-examples/dubbox-ratelimit-example/pom.xml +++ /dev/null @@ -1,300 +0,0 @@ - - - - dubbox-examples - com.tencent.polaris - ${revision} - ../pom.xml - - 4.0.0 - - dubbox-ratelimit-example - - pom - - dubbox-ratelimit-provider - dubbox-ratelimit-consumer - dubbox-ratelimit-example-api - - - - - com.tencent.polaris - dubbox-registry-polaris - ${project.version} - - - com.tencent.polaris - dubbox-ratelimit-polaris - ${project.version} - - - com.alibaba - dubbo - - - org.javassist - javassist - - - io.netty - netty-all - ${netty_version} - - - org.apache.mina - mina-core - - - org.glassfish.grizzly - grizzly-core - - - org.apache.httpcomponents - httpclient - - - com.alibaba - fastjson - - - com.thoughtworks.xstream - xstream - - - org.apache.bsf - bsf-api - - - org.apache.zookeeper - zookeeper - - - com.github.sgroschupf - zkclient - - - org.apache.curator - curator-framework - - - com.googlecode.xmemcached - xmemcached - - - org.apache.cxf - cxf-rt-frontend-simple - - - org.apache.cxf - cxf-rt-transports-http - - - org.apache.thrift - libthrift - - - com.caucho - hessian - - - javax.servlet - javax.servlet-api - - - org.mortbay.jetty - jetty - - - org.mortbay.jetty - servlet-api - - - - - log4j - log4j - - - org.slf4j - slf4j-api - - - redis.clients - jedis - - - javax.validation - validation-api - - - org.hibernate - hibernate-validator - - - javax.cache - cache-api - - - - org.jboss.resteasy - resteasy-jaxrs - - - - org.jboss.resteasy - resteasy-client - - - - org.jboss.resteasy - resteasy-netty - - - - org.jboss.resteasy - resteasy-jdk-http - - - - org.jboss.resteasy - resteasy-jackson-provider - - - - org.jboss.resteasy - resteasy-jaxb-provider - - - - org.apache.tomcat.embed - tomcat-embed-core - - - org.apache.tomcat.embed - tomcat-embed-logging-juli - - - - com.esotericsoftware.kryo - kryo - - - de.javakaffee - kryo-serializers - - - de.ruedigermoeller - fst - - - org.springframework - spring-web - - - - - - - org.apache.maven.plugins - maven-jar-plugin - - - true - true - - true - true - - - - - - maven-source-plugin - - - attach-sources - package - - jar-no-fork - - - - - - org.apache.maven.plugins - maven-surefire-plugin - ${maven-surefire-plugin_version} - - - - - - - org.apache.maven.plugins - maven-jar-plugin - ${maven_jar_plugin_version} - - - org.apache.maven.plugins - maven-war-plugin - ${maven_war_plugin_version} - - - org.apache.maven.plugins - maven-install-plugin - ${maven_install_plugin_version} - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven_compiler_plugin_version} - - true - ${java_source_version} - ${java_target_version} - ${file_encoding} - - - - - - - - org.eclipse.m2e - lifecycle-mapping - 1.0.0 - - - - - - - org.apache.maven.plugins - - - maven-dependency-plugin - - - [2.1,) - - - unpack - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-back/pom.xml b/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-back/pom.xml deleted file mode 100644 index cf1cf07..0000000 --- a/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-back/pom.xml +++ /dev/null @@ -1,60 +0,0 @@ - - - - dubbox-router-example - com.tencent.polaris - ${revision} - ../pom.xml - - 4.0.0 - - dubbox-router-back - war - - - - com.tencent.polaris - dubbox-router-example-api - ${project.version} - - - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.0.0 - - - package - - shade - - - - - *:* - - META-INF/*.SF - META-INF/*.DSA - META-INF/*.RSA - - - - - - com.tencent.polaris.dubbox.router.back.Application - - - - - - - - - - \ No newline at end of file diff --git a/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-back/src/main/java/com/tencent/polaris/dubbox/router/back/Application.java b/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-back/src/main/java/com/tencent/polaris/dubbox/router/back/Application.java deleted file mode 100644 index 3cf1159..0000000 --- a/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-back/src/main/java/com/tencent/polaris/dubbox/router/back/Application.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Polaris available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * 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 com.tencent.polaris.dubbox.router.back; - -public class Application { - - public static void main(String[] args) { - com.alibaba.dubbo.container.Main.main(args); - } - -} diff --git a/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-back/src/main/java/com/tencent/polaris/dubbox/router/back/BackServiceImpl.java b/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-back/src/main/java/com/tencent/polaris/dubbox/router/back/BackServiceImpl.java deleted file mode 100644 index 52f21f5..0000000 --- a/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-back/src/main/java/com/tencent/polaris/dubbox/router/back/BackServiceImpl.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Polaris available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * 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 com.tencent.polaris.dubbox.router.back; - -import com.tencent.polaris.common.utils.ExampleConsts; -import com.tencent.polaris.dubbox.router.example.api.BackService; -import com.tencent.polaris.dubbox.router.example.api.FooRequest; -import com.tencent.polaris.dubbox.router.example.api.FooResponse; - -public class BackServiceImpl implements BackService { - - private final String version; - - public BackServiceImpl() { - version = System.getenv(ExampleConsts.ENV_KEY_VERSION); - } - - @Override - public FooResponse foo(FooRequest request) { - String message = String.format("user %s login with pwd %s", request.getUser(), request.getPwd()); - FooResponse fooResponse = new FooResponse(); - fooResponse.setMessage(message); - return fooResponse; - } -} diff --git a/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-back/src/main/resources/META-INF/spring/dubbox-router-back.xml b/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-back/src/main/resources/META-INF/spring/dubbox-router-back.xml deleted file mode 100644 index 3cf0afd..0000000 --- a/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-back/src/main/resources/META-INF/spring/dubbox-router-back.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-back/src/main/resources/log4j.xml b/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-back/src/main/resources/log4j.xml deleted file mode 100644 index ae988c3..0000000 --- a/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-back/src/main/resources/log4j.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-back/src/main/webapp/WEB-INF/web.xml b/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-back/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index fe1a0a7..0000000 --- a/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-back/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - contextConfigLocation - /WEB-INF/classes/META-INF/spring/dubbox-router-back.xml - - - - - com.alibaba.dubbo.remoting.http.servlet.BootstrapListener - - - - org.springframework.web.context.ContextLoaderListener - - - - dispatcher - com.alibaba.dubbo.remoting.http.servlet.DispatcherServlet - 1 - - - - dispatcher - /services/* - - \ No newline at end of file diff --git a/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-example-api/pom.xml b/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-example-api/pom.xml deleted file mode 100644 index f5a488a..0000000 --- a/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-example-api/pom.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - dubbox-router-example - com.tencent.polaris - ${revision} - ../pom.xml - - 4.0.0 - - dubbox-router-example-api - - - \ No newline at end of file diff --git a/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-example-api/src/main/java/com/tencent/polaris/dubbox/router/example/api/BackService.java b/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-example-api/src/main/java/com/tencent/polaris/dubbox/router/example/api/BackService.java deleted file mode 100644 index dc9470c..0000000 --- a/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-example-api/src/main/java/com/tencent/polaris/dubbox/router/example/api/BackService.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Polaris available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * 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 com.tencent.polaris.dubbox.router.example.api; - -public interface BackService { - - FooResponse foo(FooRequest request); -} diff --git a/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-example-api/src/main/java/com/tencent/polaris/dubbox/router/example/api/FooResponse.java b/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-example-api/src/main/java/com/tencent/polaris/dubbox/router/example/api/FooResponse.java deleted file mode 100644 index fda7a75..0000000 --- a/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-example-api/src/main/java/com/tencent/polaris/dubbox/router/example/api/FooResponse.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Polaris available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * 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 com.tencent.polaris.dubbox.router.example.api; - -import java.io.Serializable; - -public class FooResponse implements Serializable { - - private String message; - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } -} diff --git a/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-example-api/src/main/java/com/tencent/polaris/dubbox/router/example/api/MiddleService.java b/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-example-api/src/main/java/com/tencent/polaris/dubbox/router/example/api/MiddleService.java deleted file mode 100644 index fa7560b..0000000 --- a/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-example-api/src/main/java/com/tencent/polaris/dubbox/router/example/api/MiddleService.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Polaris available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * 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 com.tencent.polaris.dubbox.router.example.api; - -public interface MiddleService { - - FooResponse foo(FooRequest request); -} diff --git a/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-front/pom.xml b/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-front/pom.xml deleted file mode 100644 index 0d2ff6b..0000000 --- a/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-front/pom.xml +++ /dev/null @@ -1,59 +0,0 @@ - - - - dubbox-router-example - com.tencent.polaris - ${revision} - ../pom.xml - - 4.0.0 - - dubbox-router-front - - - - com.tencent.polaris - dubbox-router-example-api - ${project.version} - - - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.0.0 - - - package - - shade - - - - - *:* - - META-INF/*.SF - META-INF/*.DSA - META-INF/*.RSA - - - - - - com.tencent.polaris.dubbox.router.front.FrontAction - - - - - - - - - - \ No newline at end of file diff --git a/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-front/src/main/java/com/tencent/polaris/dubbox/router/front/FrontAction.java b/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-front/src/main/java/com/tencent/polaris/dubbox/router/front/FrontAction.java deleted file mode 100644 index 5e1ae51..0000000 --- a/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-front/src/main/java/com/tencent/polaris/dubbox/router/front/FrontAction.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Polaris available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * 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 com.tencent.polaris.dubbox.router.front; - -public class FrontAction { - - public static void main(String[] args) { - com.alibaba.dubbo.container.Main.main(args); - } -} diff --git a/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-front/src/main/java/com/tencent/polaris/dubbox/router/front/FrontService.java b/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-front/src/main/java/com/tencent/polaris/dubbox/router/front/FrontService.java deleted file mode 100644 index 66469cf..0000000 --- a/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-front/src/main/java/com/tencent/polaris/dubbox/router/front/FrontService.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Polaris available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * 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 com.tencent.polaris.dubbox.router.front; - -import com.alibaba.dubbo.rpc.RpcContext; -import com.tencent.polaris.dubbox.router.example.api.FooRequest; -import com.tencent.polaris.dubbox.router.example.api.FooResponse; -import com.tencent.polaris.dubbox.router.example.api.MiddleService; - -public class FrontService { - - private MiddleService middleService; - - public void setMiddleService(MiddleService middleService) { - this.middleService = middleService; - } - - public void start() { - for (int i = 0; i < 10; i++) { - foo("archer"); - } - for (int i = 0; i < 10; i++) { - foo("tommy"); - } - } - - private void foo(String userName) { - RpcContext.getContext().setAttachment("user", userName); - FooRequest fooRequest = new FooRequest(); - fooRequest.setUser(userName); - fooRequest.setPwd("123"); - FooResponse message = middleService.foo(fooRequest); - System.out.printf("frontService->%s%n", message.getMessage()); - } -} diff --git a/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-front/src/main/resources/META-INF/spring/dubbox-router-front.xml b/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-front/src/main/resources/META-INF/spring/dubbox-router-front.xml deleted file mode 100644 index c7f5ae7..0000000 --- a/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-front/src/main/resources/META-INF/spring/dubbox-router-front.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-middle/pom.xml b/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-middle/pom.xml deleted file mode 100644 index 407b741..0000000 --- a/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-middle/pom.xml +++ /dev/null @@ -1,60 +0,0 @@ - - - - dubbox-router-example - com.tencent.polaris - ${revision} - ../pom.xml - - 4.0.0 - - dubbox-router-middle - war - - - - com.tencent.polaris - dubbox-router-example-api - ${project.version} - - - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.0.0 - - - package - - shade - - - - - *:* - - META-INF/*.SF - META-INF/*.DSA - META-INF/*.RSA - - - - - - com.tencent.polaris.dubbox.router.middle.Application - - - - - - - - - - \ No newline at end of file diff --git a/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-middle/src/main/java/com/tencent/polaris/dubbox/router/middle/Application.java b/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-middle/src/main/java/com/tencent/polaris/dubbox/router/middle/Application.java deleted file mode 100644 index 8438f9d..0000000 --- a/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-middle/src/main/java/com/tencent/polaris/dubbox/router/middle/Application.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Polaris available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * 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 com.tencent.polaris.dubbox.router.middle; - -public class Application { - - public static void main(String[] args) { - com.alibaba.dubbo.container.Main.main(args); - } - -} diff --git a/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-middle/src/main/java/com/tencent/polaris/dubbox/router/middle/MiddleServiceImpl.java b/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-middle/src/main/java/com/tencent/polaris/dubbox/router/middle/MiddleServiceImpl.java deleted file mode 100644 index 08afdcf..0000000 --- a/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-middle/src/main/java/com/tencent/polaris/dubbox/router/middle/MiddleServiceImpl.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Polaris available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * 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 com.tencent.polaris.dubbox.router.middle; - -import com.tencent.polaris.common.utils.ExampleConsts; -import com.tencent.polaris.dubbox.router.example.api.BackService; -import com.tencent.polaris.dubbox.router.example.api.FooRequest; -import com.tencent.polaris.dubbox.router.example.api.FooResponse; -import com.tencent.polaris.dubbox.router.example.api.MiddleService; - -public class MiddleServiceImpl implements MiddleService { - - private BackService backService; - - private final String version; - - public MiddleServiceImpl() { - version = System.getenv(ExampleConsts.ENV_KEY_VERSION); - } - - public void setBackService(BackService backService) { - this.backService = backService; - } - - @Override - public FooResponse foo(FooRequest request) { - FooResponse response = backService.foo(request); - FooResponse finalResponse = new FooResponse(); - finalResponse.setMessage(String.format("middle.%s->%s", version, response.getMessage())); - return finalResponse; - } -} diff --git a/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-middle/src/main/resources/META-INF/spring/dubbox-router-middle.xml b/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-middle/src/main/resources/META-INF/spring/dubbox-router-middle.xml deleted file mode 100644 index f5bc68e..0000000 --- a/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-middle/src/main/resources/META-INF/spring/dubbox-router-middle.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-middle/src/main/resources/log4j.xml b/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-middle/src/main/resources/log4j.xml deleted file mode 100644 index ae988c3..0000000 --- a/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-middle/src/main/resources/log4j.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-middle/src/main/webapp/WEB-INF/web.xml b/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-middle/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index 04d702a..0000000 --- a/dubbox/dubbox-examples/dubbox-router-example/dubbox-router-middle/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - contextConfigLocation - /WEB-INF/classes/META-INF/spring/dubbox-router-middle.xml - - - - - com.alibaba.dubbo.remoting.http.servlet.BootstrapListener - - - - org.springframework.web.context.ContextLoaderListener - - - - dispatcher - com.alibaba.dubbo.remoting.http.servlet.DispatcherServlet - 1 - - - - dispatcher - /services/* - - \ No newline at end of file diff --git a/dubbox/dubbox-examples/dubbox-router-example/pom.xml b/dubbox/dubbox-examples/dubbox-router-example/pom.xml deleted file mode 100644 index db8405f..0000000 --- a/dubbox/dubbox-examples/dubbox-router-example/pom.xml +++ /dev/null @@ -1,300 +0,0 @@ - - - - dubbox-examples - com.tencent.polaris - ${revision} - ../pom.xml - - 4.0.0 - - dubbox-router-example - pom - - dubbox-router-front - dubbox-router-middle - dubbox-router-back - dubbox-router-example-api - - - - - com.tencent.polaris - dubbox-registry-polaris - ${project.version} - - - com.tencent.polaris - dubbox-router-polaris - ${project.version} - - - com.alibaba - dubbo - - - org.javassist - javassist - - - io.netty - netty-all - ${netty_version} - - - org.apache.mina - mina-core - - - org.glassfish.grizzly - grizzly-core - - - org.apache.httpcomponents - httpclient - - - com.alibaba - fastjson - - - com.thoughtworks.xstream - xstream - - - org.apache.bsf - bsf-api - - - org.apache.zookeeper - zookeeper - - - com.github.sgroschupf - zkclient - - - org.apache.curator - curator-framework - - - com.googlecode.xmemcached - xmemcached - - - org.apache.cxf - cxf-rt-frontend-simple - - - org.apache.cxf - cxf-rt-transports-http - - - org.apache.thrift - libthrift - - - com.caucho - hessian - - - javax.servlet - javax.servlet-api - - - org.mortbay.jetty - jetty - - - org.mortbay.jetty - servlet-api - - - - - log4j - log4j - - - org.slf4j - slf4j-api - - - redis.clients - jedis - - - javax.validation - validation-api - - - org.hibernate - hibernate-validator - - - javax.cache - cache-api - - - - org.jboss.resteasy - resteasy-jaxrs - - - - org.jboss.resteasy - resteasy-client - - - - org.jboss.resteasy - resteasy-netty - - - - org.jboss.resteasy - resteasy-jdk-http - - - - org.jboss.resteasy - resteasy-jackson-provider - - - - org.jboss.resteasy - resteasy-jaxb-provider - - - - org.apache.tomcat.embed - tomcat-embed-core - - - org.apache.tomcat.embed - tomcat-embed-logging-juli - - - - com.esotericsoftware.kryo - kryo - - - de.javakaffee - kryo-serializers - - - de.ruedigermoeller - fst - - - org.springframework - spring-web - - - - - - - org.apache.maven.plugins - maven-jar-plugin - - - true - true - - true - true - - - - - - maven-source-plugin - - - attach-sources - package - - jar-no-fork - - - - - - org.apache.maven.plugins - maven-surefire-plugin - ${maven-surefire-plugin_version} - - - - - - - org.apache.maven.plugins - maven-jar-plugin - ${maven_jar_plugin_version} - - - org.apache.maven.plugins - maven-war-plugin - ${maven_war_plugin_version} - - - org.apache.maven.plugins - maven-install-plugin - ${maven_install_plugin_version} - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven_compiler_plugin_version} - - true - ${java_source_version} - ${java_target_version} - ${file_encoding} - - - - - - - - org.eclipse.m2e - lifecycle-mapping - 1.0.0 - - - - - - - org.apache.maven.plugins - - - maven-dependency-plugin - - - [2.1,) - - - unpack - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/dubbox/dubbox-examples/pom.xml b/dubbox/dubbox-examples/pom.xml deleted file mode 100644 index 1a19e82..0000000 --- a/dubbox/dubbox-examples/pom.xml +++ /dev/null @@ -1,367 +0,0 @@ - - - - dubbox - com.tencent.polaris - ${revision} - ../pom.xml - - 4.0.0 - - dubbox-examples - - pom - - dubbox-discovery-example - dubbox-router-example - dubbox-ratelimit-example - - - - - 3.2.9.RELEASE - 3.15.0-GA - 4.1.66.Final - 1.1.7 - 2.1.4 - 4.2.1 - 3.2.13 - 1.4.1 - 1.1.39 - 3.1 - 0.8 - 3.4.6 - 0.1 - 2.5.0 - 2.1.0 - 1.3.6 - 2.6.1 - 0.8.0 - 1.0.13 - 4.0.7 - 3.1.0 - 6.1.26 - 1.0.0.GA - 4.2.0.Final - 0.4 - 2.0-M5.1 - 3.0 - 2.2 - 3.0.8 - 2.3.3 - 1.6 - 8.0.11 - - 1.6.2 - 1.1 - 1.2.16 - 1.0.6 - - 4.10 - 3.0 - 0.999.8 - - true - - 2.3.2 - 1.6 - 1.6 - UTF-8 - - 2.1.1 - 2.3.2 - 2.1.1 - 2.3.1 - 2.7 - - 2.17 - - - - - - - org.springframework - spring-framework-bom - ${spring.bom.version} - pom - import - - - org.javassist - javassist - ${javassist_version} - - - io.netty - netty-all - ${netty_version} - - - org.apache.mina - mina-core - ${mina_version} - - - org.glassfish.grizzly - grizzly-core - ${grizzly_version} - - - org.apache.httpcomponents - httpclient - ${httpclient_version} - - - com.alibaba - hessian-lite - ${hessian_lite_version} - - - com.alibaba - fastjson - ${fastjson_version} - - - com.thoughtworks.xstream - xstream - ${xstream_version} - - - org.apache.bsf - bsf-api - ${bsf_version} - - - org.jvnet.sorcerer - sorcerer-javac - ${sorcerer_version} - - - org.apache.zookeeper - zookeeper - ${zookeeper_version} - - - com.github.sgroschupf - zkclient - ${zkclient_version} - - - org.apache.curator - curator-framework - ${curator_version} - - - redis.clients - jedis - ${jedis_version} - - - com.googlecode.xmemcached - xmemcached - ${xmemcached_version} - - - org.apache.cxf - cxf-rt-frontend-simple - ${cxf_version} - - - org.apache.cxf - cxf-rt-transports-http - ${cxf_version} - - - org.apache.thrift - libthrift - ${thrift_version} - - - jfree - jfreechart - ${jfreechart_version} - - - com.caucho - hessian - ${hessian_version} - - - javax.servlet - javax.servlet-api - ${servlet_version} - - - org.mortbay.jetty - jetty - ${jetty_version} - - - javax.validation - validation-api - ${validation_version} - - - org.hibernate - hibernate-validator - ${hibernate_validator_version} - - - javax.cache - cache-api - ${jcache_version} - - - org.apache.tuscany.sca - tuscany-sca-api - ${sca_version} - - - com.google.inject - guice - ${guice_version} - - - com.alibaba.citrus - citrus-webx-all - ${webx_version} - - - com.fasterxml.jackson.core - jackson-core - ${jackson_version} - - - com.fasterxml.jackson.core - jackson-databind - ${jackson_version} - - - - org.slf4j - slf4j-api - ${slf4j_version} - - - org.slf4j - slf4j-log4j12 - ${slf4j_version} - - - commons-logging - commons-logging-api - ${jcl_version} - - - log4j - log4j - ${log4j_version} - - - ch.qos.logback - logback-classic - ${logback_version} - - - - junit - junit - ${junit_version} - test - - - org.easymock - easymock - ${easymock_version} - test - - - com.googlecode.jmockit - jmockit - ${jmockit_version} - test - - - org.easymock - easymockclassextension - ${easymock_version} - test - - - cglib - cglib-nodep - ${cglib_version} - - - commons-pool - commons-pool - ${commons_pool_version} - - - org.apache.tomcat.embed - tomcat-embed-core - ${tomcat_embed_version} - - - org.apache.tomcat.embed - tomcat-embed-logging-juli - ${tomcat_embed_version} - - - - - javax.ws.rs - javax.ws.rs-api - 2.0 - - - org.jboss.resteasy - resteasy-jaxrs - 3.0.7.Final - - - org.jboss.resteasy - resteasy-client - 3.0.7.Final - - - org.jboss.resteasy - resteasy-netty - 3.0.7.Final - - - org.jboss.resteasy - resteasy-jdk-http - 3.0.7.Final - - - org.jboss.resteasy - resteasy-jackson-provider - 3.0.7.Final - - - org.jboss.resteasy - resteasy-jaxb-provider - 3.0.7.Final - - - com.esotericsoftware.kryo - kryo - 2.24.0 - - - de.javakaffee - kryo-serializers - 0.26 - - - de.ruedigermoeller - fst - 1.55 - - - - \ No newline at end of file diff --git a/dubbox/dubbox-plugins/dubbox-circuitbreaker-polaris/pom.xml b/dubbox/dubbox-plugins/dubbox-circuitbreaker-polaris/pom.xml deleted file mode 100644 index 5996daf..0000000 --- a/dubbox/dubbox-plugins/dubbox-circuitbreaker-polaris/pom.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - dubbox-plugins - com.tencent.polaris - ${revision} - ../pom.xml - - 4.0.0 - - dubbox-circuitbreaker-polaris - - - - com.tencent.polaris - dubbox-registry-polaris - ${project.version} - - - com.alibaba - dubbo - provided - - - org.slf4j - slf4j-api - provided - - - \ No newline at end of file diff --git a/dubbox/dubbox-plugins/dubbox-circuitbreaker-polaris/src/main/java/com/tencent/polaris/dubbox/circuitbreaker/CircuitBreakerFilter.java b/dubbox/dubbox-plugins/dubbox-circuitbreaker-polaris/src/main/java/com/tencent/polaris/dubbox/circuitbreaker/CircuitBreakerFilter.java deleted file mode 100644 index 4d4b8d5..0000000 --- a/dubbox/dubbox-plugins/dubbox-circuitbreaker-polaris/src/main/java/com/tencent/polaris/dubbox/circuitbreaker/CircuitBreakerFilter.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Polaris available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * 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 com.tencent.polaris.dubbox.circuitbreaker; - - -import java.util.concurrent.TimeUnit; - -import com.alibaba.dubbo.common.Constants; -import com.alibaba.dubbo.common.URL; -import com.alibaba.dubbo.common.extension.Activate; -import com.alibaba.dubbo.rpc.Filter; -import com.alibaba.dubbo.rpc.Invocation; -import com.alibaba.dubbo.rpc.Invoker; -import com.alibaba.dubbo.rpc.Result; -import com.alibaba.dubbo.rpc.RpcException; -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; - -@Activate(group = Constants.CONSUMER) -public class CircuitBreakerFilter extends PolarisOperatorDelegate implements Filter, ResultToErrorCode { - - @Override - public Result invoke(Invoker invoker, Invocation invocation) throws RpcException { - 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) { - throw new RpcException(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; - } -} diff --git a/dubbox/dubbox-plugins/dubbox-circuitbreaker-polaris/src/main/resources/META-INF/dubbo/com.alibaba.dubbo.rpc.Filter b/dubbox/dubbox-plugins/dubbox-circuitbreaker-polaris/src/main/resources/META-INF/dubbo/com.alibaba.dubbo.rpc.Filter deleted file mode 100644 index 10c0e80..0000000 --- a/dubbox/dubbox-plugins/dubbox-circuitbreaker-polaris/src/main/resources/META-INF/dubbo/com.alibaba.dubbo.rpc.Filter +++ /dev/null @@ -1 +0,0 @@ -polaris_circuitbreaker=com.tencent.polaris.dubbox.circuitbreaker.CircuitBreakerFilter \ No newline at end of file diff --git a/dubbox/dubbox-plugins/dubbox-ratelimit-polaris/pom.xml b/dubbox/dubbox-plugins/dubbox-ratelimit-polaris/pom.xml deleted file mode 100644 index 62c80e3..0000000 --- a/dubbox/dubbox-plugins/dubbox-ratelimit-polaris/pom.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - dubbox-plugins - com.tencent.polaris - ${revision} - ../pom.xml - - 4.0.0 - - dubbox-ratelimit-polaris - - - - com.tencent.polaris - dubbox-registry-polaris - ${project.version} - - - com.alibaba - dubbo - provided - - - org.slf4j - slf4j-api - provided - - - \ No newline at end of file diff --git a/dubbox/dubbox-plugins/dubbox-ratelimit-polaris/src/main/java/com/tencent/polaris/dubbox/ratelimit/RateLimitFilter.java b/dubbox/dubbox-plugins/dubbox-ratelimit-polaris/src/main/java/com/tencent/polaris/dubbox/ratelimit/RateLimitFilter.java deleted file mode 100644 index 973a135..0000000 --- a/dubbox/dubbox-plugins/dubbox-ratelimit-polaris/src/main/java/com/tencent/polaris/dubbox/ratelimit/RateLimitFilter.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Polaris available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * 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 com.tencent.polaris.dubbox.ratelimit; - -import com.alibaba.dubbo.common.Constants; -import com.alibaba.dubbo.common.extension.Activate; -import com.alibaba.dubbo.rpc.Filter; -import com.alibaba.dubbo.rpc.Invocation; -import com.alibaba.dubbo.rpc.Invoker; -import com.alibaba.dubbo.rpc.Result; -import com.alibaba.dubbo.rpc.RpcContext; -import com.alibaba.dubbo.rpc.RpcException; -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.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.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 com.tencent.polaris.specification.api.v1.traffic.manage.RateLimitProto; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.HashSet; -import java.util.Optional; -import java.util.Set; - -@Activate(group = Constants.PROVIDER) -public class RateLimitFilter extends PolarisOperatorDelegate implements Filter { - - private static final Logger LOGGER = LoggerFactory.getLogger(RateLimitFilter.class); - - private final RuleHandler ruleHandler; - - private final QueryParser parser; - - public RateLimitFilter() { - LOGGER.info("[POLARIS] init polaris ratelimit"); - ruleHandler = new RuleHandler(); - parser = QueryParser.load(); - } - - @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); - } - RateLimitProto.RateLimit rateLimit = (RateLimitProto.RateLimit) ruleObject; - Set ratelimitLabels = ruleHandler.getRatelimitLabels(rateLimit); - String method = invocation.getMethodName(); - Set arguments = new HashSet<>(); - for (RateLimitProto.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: - Optional queryValue = parser.parse(matchArgument.getKey(), invocation.getArguments()); - queryValue.ifPresent(value -> arguments.add(Argument.buildQuery(matchArgument.getKey(), value))); - break; - default: - break; - } - } - QuotaResponse quotaResponse = null; - try { - quotaResponse = polarisOperator.getQuota(service, method, arguments); - } catch (RuntimeException e) { - LOGGER.error("[POLARIS] get quota fail, {}", e.getMessage()); - } - if (null != quotaResponse && quotaResponse.getCode() == QuotaResultCode.QuotaResultLimited) { - // 请求被限流,则抛出异常 - throw new RpcException(new PolarisBlockException( - String.format("url=%s, info=%s", invoker.getUrl(), quotaResponse.getInfo()))); - } - return invoker.invoke(invocation); - } -} diff --git a/dubbox/dubbox-plugins/dubbox-ratelimit-polaris/src/main/resources/META-INF/dubbo/com.alibaba.dubbo.rpc.Filter b/dubbox/dubbox-plugins/dubbox-ratelimit-polaris/src/main/resources/META-INF/dubbo/com.alibaba.dubbo.rpc.Filter deleted file mode 100644 index 058f077..0000000 --- a/dubbox/dubbox-plugins/dubbox-ratelimit-polaris/src/main/resources/META-INF/dubbo/com.alibaba.dubbo.rpc.Filter +++ /dev/null @@ -1 +0,0 @@ -polaris_ratelimit=com.tencent.polaris.dubbox.ratelimit.RateLimitFilter \ No newline at end of file diff --git a/dubbox/dubbox-plugins/dubbox-registry-polaris/pom.xml b/dubbox/dubbox-plugins/dubbox-registry-polaris/pom.xml deleted file mode 100644 index 10b5b6f..0000000 --- a/dubbox/dubbox-plugins/dubbox-registry-polaris/pom.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - dubbox-plugins - com.tencent.polaris - ${revision} - ../pom.xml - - 4.0.0 - - dubbox-registry-polaris - - - - com.tencent.polaris - polaris-adapter-dubbo - ${project.version} - - - com.alibaba - dubbo - provided - - - org.slf4j - slf4j-api - provided - - - \ No newline at end of file diff --git a/dubbox/dubbox-plugins/dubbox-registry-polaris/src/main/java/com/tencent/polaris/dubbox/registry/PolarisRegistry.java b/dubbox/dubbox-plugins/dubbox-registry-polaris/src/main/java/com/tencent/polaris/dubbox/registry/PolarisRegistry.java deleted file mode 100644 index 963b959..0000000 --- a/dubbox/dubbox-plugins/dubbox-registry-polaris/src/main/java/com/tencent/polaris/dubbox/registry/PolarisRegistry.java +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright 2019 NAVER Corp. - * - * Licensed 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 com.tencent.polaris.dubbox.registry; - -import com.alibaba.dubbo.common.Constants; -import com.alibaba.dubbo.common.URL; -import com.alibaba.dubbo.common.extension.ExtensionLoader; -import com.alibaba.dubbo.common.utils.CollectionUtils; -import com.alibaba.dubbo.common.utils.ConcurrentHashSet; -import com.alibaba.dubbo.registry.NotifyListener; -import com.alibaba.dubbo.registry.support.FailbackRegistry; -import com.alibaba.dubbo.rpc.Filter; -import com.alibaba.dubbo.rpc.cluster.RouterFactory; -import com.tencent.polaris.api.exception.PolarisException; -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.registry.PolarisOperators; -import com.tencent.polaris.common.utils.ExtensionConsts; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -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 static com.alibaba.dubbo.common.Constants.CATEGORY_KEY; -import static com.alibaba.dubbo.common.Constants.DEFAULT_CATEGORY; -import static com.alibaba.dubbo.common.Constants.EMPTY_PROTOCOL; -import static com.alibaba.dubbo.common.Constants.PATH_KEY; - -public class PolarisRegistry extends FailbackRegistry { - - private static final Logger LOGGER = LoggerFactory.getLogger(PolarisRegistry.class); - - private final Set registeredInstances = new ConcurrentHashSet<>(); - - private final AtomicBoolean destroyed = new AtomicBoolean(false); - - private final Map serviceListeners = new ConcurrentHashMap<>(); - - private final PolarisOperator polarisOperator; - - public PolarisRegistry(URL url) { - super(url); - polarisOperator = PolarisOperators.INSTANCE.loadOrStore(url.getHost(), url.getPort(), url.getParameters()); - } - - @Override - public void doRegister(URL url) { - if (!shouldRegister(url)) { - return; - } - LOGGER.info("[POLARIS] register service to polaris: {}", url.toString()); - Map metadata = new HashMap<>(url.getParameters()); - metadata.put(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(Constants.VERSION_KEY, ""); - polarisOperator.register(url.getServiceInterface(), url.getHost(), port, url.getProtocol(), version, weight, - metadata); - registeredInstances.add(url); - } else { - LOGGER.warn("[POLARIS] skip register url {} for zero port value", url); - } - } - - private boolean shouldRegister(URL url) { - return !StringUtils.equals(url.getProtocol(), Constants.CONSUMER); - } - - @Override - public void doUnregister(URL url) { - if (!shouldRegister(url)) { - return; - } - LOGGER.info("[POLARIS] unregister service from polaris: {}", 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); - } - polarisOperator.destroy(); - } - } - - @Override - public void doSubscribe(URL url, NotifyListener listener) { - String service = url.getServiceInterface(); - Instance[] instances = polarisOperator.getAvailableInstances(service, true); - onInstances(url, listener, instances); - LOGGER.info("[POLARIS] submit watch task for service {}", service); - - serviceListeners.computeIfAbsent(listener, notifyListener -> { - ServiceListener serviceListener = event -> { - try { - Instance[] curInstances = polarisOperator.getAvailableInstances(service, true); - onInstances(url, listener, curInstances); - } catch (PolarisException e) { - LOGGER.error("[POLARIS] fail to fetch instances for service {}: {}", service, e.toString()); - } - }; - polarisOperator.watchService(service, serviceListener); - return serviceListener; - }); - } - - private void onInstances(URL url, NotifyListener listener, Instance[] instances) { - LOGGER.info("[POLARIS] update instances count: {}, service: {}", null == instances ? 0 : instances.length, - url.getServiceInterface()); - List urls = new ArrayList<>(); - if (null != instances) { - for (Instance instance : instances) { - urls.add(instanceToURL(instance)); - } - } - notify(url, listener, toUrlWithEmpty(url, 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)); - return new URL(instance.getProtocol(), - instance.getHost(), - instance.getPort(), - newMetadata.get(PATH_KEY), - newMetadata); - } - - private List toUrlWithEmpty(URL providerUrl, List urls) { - if (CollectionUtils.isEmpty(urls)) { - LOGGER.warn("[POLARIS] received empty url address list, will clear current available addresses"); - URL empty = providerUrl - .setProtocol(EMPTY_PROTOCOL) - .addParameter(CATEGORY_KEY, DEFAULT_CATEGORY); - urls.add(empty); - } - return urls; - } - - @Override - public void doUnsubscribe(URL url, NotifyListener listener) { - LOGGER.info("[polaris] unsubscribe service: {}", url.toString()); - ServiceListener serviceListener = serviceListeners.get(listener); - if (serviceListener != null) { - polarisOperator.unwatchService(url.getServiceInterface(), serviceListener); - } - } - - @Override - public boolean isAvailable() { - return true; - } -} diff --git a/dubbox/dubbox-plugins/dubbox-registry-polaris/src/main/java/com/tencent/polaris/dubbox/report/ReportFilter.java b/dubbox/dubbox-plugins/dubbox-registry-polaris/src/main/java/com/tencent/polaris/dubbox/report/ReportFilter.java deleted file mode 100644 index 5f1a47b..0000000 --- a/dubbox/dubbox-plugins/dubbox-registry-polaris/src/main/java/com/tencent/polaris/dubbox/report/ReportFilter.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright 2019 NAVER Corp. - * - * Licensed 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 com.tencent.polaris.dubbox.report; - -import com.alibaba.dubbo.common.Constants; -import com.alibaba.dubbo.common.URL; -import com.alibaba.dubbo.common.extension.Activate; -import com.alibaba.dubbo.rpc.Filter; -import com.alibaba.dubbo.rpc.Invocation; -import com.alibaba.dubbo.rpc.Invoker; -import com.alibaba.dubbo.rpc.Result; -import com.alibaba.dubbo.rpc.RpcContext; -import com.alibaba.dubbo.rpc.RpcException; -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.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@Activate(group = Constants.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(); - try { - Result result = invoker.invoke(invocation); - long delay = System.currentTimeMillis() - startTimeMilli; - if (result.hasException()) { - onError(invoker, invocation, result.getException(), delay); - } else { - onSuccess(invoker, invocation, result, delay); - } - return result; - } - catch (RpcException e) { - long delay = System.currentTimeMillis() - startTimeMilli; - onError(invoker, invocation, e, delay); - throw e; - } - } - - private void onSuccess(Invoker invoker, Invocation invocation, Result result, long costMill) { - PolarisOperator polarisOperator = getPolarisOperator(); - if (null == polarisOperator) { - return; - } - RetStatus retStatus = RetStatus.RetSuccess; - URL url = invoker.getUrl(); - polarisOperator.reportInvokeResult(url.getServiceInterface(), invocation.getMethodName(), url.getHost(), - url.getPort(), RpcContext.getContext().getLocalHost(), costMill, retStatus, 0); - } - - private void onError(Invoker invoker, Invocation invocation, Throwable exception, long costMill) { - PolarisOperator polarisOperator = getPolarisOperator(); - if (null == polarisOperator) { - return; - } - RetStatus retStatus = RetStatus.RetFail; - URL url = invoker.getUrl(); - int code = -1; - if (exception instanceof RpcException) { - RpcException rpcException = (RpcException) exception; - code = rpcException.getCode(); - if (StringUtils.isNotBlank(exception.getMessage()) && exception.getMessage() - .contains(PolarisBlockException.PREFIX)) { - // 限流异常不进行熔断 - retStatus = RetStatus.RetFlowControl; - } - if (rpcException.getCause() instanceof CallAbortedException) { - retStatus = RetStatus.RetReject; - } - } - polarisOperator.reportInvokeResult(url.getServiceInterface(), invocation.getMethodName(), url.getHost(), - url.getPort(), RpcContext.getContext().getLocalHost(), costMill, retStatus, code); - } -} diff --git a/dubbox/dubbox-plugins/dubbox-registry-polaris/src/main/resources/META-INF/dubbo/com.alibaba.dubbo.registry.RegistryFactory b/dubbox/dubbox-plugins/dubbox-registry-polaris/src/main/resources/META-INF/dubbo/com.alibaba.dubbo.registry.RegistryFactory deleted file mode 100644 index 81e84bf..0000000 --- a/dubbox/dubbox-plugins/dubbox-registry-polaris/src/main/resources/META-INF/dubbo/com.alibaba.dubbo.registry.RegistryFactory +++ /dev/null @@ -1 +0,0 @@ -polaris=com.tencent.polaris.dubbox.registry.PolarisRegistryFactory \ No newline at end of file diff --git a/dubbox/dubbox-plugins/dubbox-registry-polaris/src/main/resources/META-INF/dubbo/com.alibaba.dubbo.rpc.Filter b/dubbox/dubbox-plugins/dubbox-registry-polaris/src/main/resources/META-INF/dubbo/com.alibaba.dubbo.rpc.Filter deleted file mode 100644 index 931ea6d..0000000 --- a/dubbox/dubbox-plugins/dubbox-registry-polaris/src/main/resources/META-INF/dubbo/com.alibaba.dubbo.rpc.Filter +++ /dev/null @@ -1 +0,0 @@ -polaris_report=com.tencent.polaris.dubbox.report.ReportFilter \ No newline at end of file diff --git a/dubbox/dubbox-plugins/dubbox-router-polaris/pom.xml b/dubbox/dubbox-plugins/dubbox-router-polaris/pom.xml deleted file mode 100644 index 8e4e3b5..0000000 --- a/dubbox/dubbox-plugins/dubbox-router-polaris/pom.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - dubbox-plugins - com.tencent.polaris - ${revision} - ../pom.xml - - 4.0.0 - - dubbox-router-polaris - - - - com.tencent.polaris - dubbox-registry-polaris - ${project.version} - - - com.alibaba - dubbo - provided - - - org.slf4j - slf4j-api - provided - - - \ No newline at end of file diff --git a/dubbox/dubbox-plugins/dubbox-router-polaris/src/main/java/com/tencent/polaris/dubbox/router/InstanceInvoker.java b/dubbox/dubbox-plugins/dubbox-router-polaris/src/main/java/com/tencent/polaris/dubbox/router/InstanceInvoker.java deleted file mode 100644 index 4970638..0000000 --- a/dubbox/dubbox-plugins/dubbox-router-polaris/src/main/java/com/tencent/polaris/dubbox/router/InstanceInvoker.java +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Polaris available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * 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 com.tencent.polaris.dubbox.router; - -import com.alibaba.dubbo.common.Constants; -import com.alibaba.dubbo.common.URL; -import com.alibaba.dubbo.rpc.Invocation; -import com.alibaba.dubbo.rpc.Invoker; -import com.alibaba.dubbo.rpc.Result; -import com.alibaba.dubbo.rpc.RpcException; -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.slf4j.Logger; -import org.slf4j.LoggerFactory; - -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(Constants.VERSION_KEY)); - defaultInstance.setWeight(url.getParameter(Constants.WEIGHT_KEY, 100)); - defaultInstance.setMetadata(url.getParameters()); - LOGGER.info("[POLARIS] construct instance from invoker, url {}, instance {}", 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); - } -} diff --git a/dubbox/dubbox-plugins/dubbox-router-polaris/src/main/java/com/tencent/polaris/dubbox/router/PolarisRouter.java b/dubbox/dubbox-plugins/dubbox-router-polaris/src/main/java/com/tencent/polaris/dubbox/router/PolarisRouter.java deleted file mode 100644 index b939308..0000000 --- a/dubbox/dubbox-plugins/dubbox-router-polaris/src/main/java/com/tencent/polaris/dubbox/router/PolarisRouter.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Polaris available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * 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 com.tencent.polaris.dubbox.router; - -import com.alibaba.dubbo.common.Constants; -import com.alibaba.dubbo.common.URL; -import com.alibaba.dubbo.rpc.Invocation; -import com.alibaba.dubbo.rpc.Invoker; -import com.alibaba.dubbo.rpc.RpcContext; -import com.alibaba.dubbo.rpc.RpcException; -import com.alibaba.dubbo.rpc.cluster.Router; -import com.alibaba.dubbo.rpc.cluster.router.script.ScriptRouter; -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.common.parser.QueryParser; -import com.tencent.polaris.common.registry.PolarisOperator; -import com.tencent.polaris.common.registry.PolarisOperators; -import com.tencent.polaris.common.router.RuleHandler; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Optional; -import java.util.Set; - -import com.tencent.polaris.specification.api.v1.traffic.manage.RoutingProto; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class PolarisRouter implements Router { - - private static final Logger LOGGER = LoggerFactory.getLogger(PolarisRouter.class); - - private final RuleHandler routeRuleHandler; - - private final PolarisOperator polarisOperator; - - private final URL url; - - private final int priority; - - private final QueryParser parser; - - public PolarisRouter(URL url) { - super(); - LOGGER.info("[POLARIS] init service router, url is {}, parameters are {}", url, - url.getParameters()); - this.url = url; - this.priority = url.getParameter(Constants.PRIORITY_KEY, 0); - routeRuleHandler = new RuleHandler(); - polarisOperator = PolarisOperators.INSTANCE.getPolarisOperator(url.getHost(), url.getPort()); - parser = QueryParser.load(); - } - - @Override - public URL getUrl() { - return url; - } - - @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; - 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) { - RoutingProto.Routing routing = (RoutingProto.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)) { - Optional value = parser.parse(queryName, invocation.getArguments()); - value.ifPresent(v -> arguments.add(RouteArgument.buildQuery(queryName, v))); - } - } - } - } - LOGGER.debug("[POLARIS] list service {}, method {}, labels {}, url {}", service, - invocation.getMethodName(), arguments, url); - List resultInstances = polarisOperator - .route(service, invocation.getMethodName(), arguments, instances); - return (List>) ((List) resultInstances); - } - - @Override - public int getPriority() { - return priority; - } - - @Override - public int compareTo(Router o) { - if (o == null || o.getClass() != ScriptRouter.class) { - return 1; - } - PolarisRouter c = (PolarisRouter) o; - return this.priority > c.priority ? 1 : -1; - } -} diff --git a/dubbox/dubbox-plugins/dubbox-router-polaris/src/main/resources/META-INF/dubbo/com.alibaba.dubbo.rpc.cluster.RouterFactory b/dubbox/dubbox-plugins/dubbox-router-polaris/src/main/resources/META-INF/dubbo/com.alibaba.dubbo.rpc.cluster.RouterFactory deleted file mode 100644 index 160aa8b..0000000 --- a/dubbox/dubbox-plugins/dubbox-router-polaris/src/main/resources/META-INF/dubbo/com.alibaba.dubbo.rpc.cluster.RouterFactory +++ /dev/null @@ -1 +0,0 @@ -polaris_router=com.tencent.polaris.dubbox.router.PolarisRouterFactory \ No newline at end of file diff --git a/dubbox/dubbox-plugins/pom.xml b/dubbox/dubbox-plugins/pom.xml deleted file mode 100644 index a23b0bb..0000000 --- a/dubbox/dubbox-plugins/pom.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - dubbox - com.tencent.polaris - ${revision} - ../pom.xml - - 4.0.0 - - dubbox-plugins - pom - - - dubbox-registry-polaris - dubbox-router-polaris - dubbox-ratelimit-polaris - dubbox-circuitbreaker-polaris - - - \ No newline at end of file diff --git a/dubbox/pom.xml b/dubbox/pom.xml deleted file mode 100644 index e40b80b..0000000 --- a/dubbox/pom.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - dubbo-java-polaris - com.tencent.polaris - ${revision} - ../pom.xml - - 4.0.0 - - dubbox - - pom - - - 2.6.9 - - - - dubbox-plugins - dubbox-examples - - - - - - com.alibaba - dubbo - ${alibaba.dubbo.version} - - - - \ No newline at end of file diff --git a/polaris-adapter-dubbo/pom.xml b/polaris-adapter-dubbo/pom.xml index 7a0f9c9..e31ea6c 100644 --- a/polaris-adapter-dubbo/pom.xml +++ b/polaris-adapter-dubbo/pom.xml @@ -12,7 +12,53 @@ polaris-adapter-dubbo + + + + org.apache.dubbo + dubbo + ${apache.dubbo.version} + true + + + org.apache.dubbo + dubbo-config-api + ${apache.dubbo.version} + true + + + org.apache.dubbo + dubbo-metadata-api + ${apache.dubbo.version} + true + + + org.apache.dubbo + dubbo-rpc-api + ${apache.dubbo.version} + true + + + org.apache.dubbo + dubbo-registry-api + ${apache.dubbo.version} + true + + + org.apache.dubbo + dubbo-common + ${apache.dubbo.version} + true + + + + + + org.apache.dubbo + dubbo + ${apache.dubbo.version} + com.tencent.polaris polaris-all @@ -20,11 +66,12 @@ org.slf4j slf4j-api - true + ${slf4j.version} com.jayway.jsonpath json-path + ${json_path_version} junit diff --git a/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/parser/QueryParser.java b/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/parser/QueryParser.java index f272101..5d3a002 100644 --- a/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/parser/QueryParser.java +++ b/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/parser/QueryParser.java @@ -29,15 +29,13 @@ public interface QueryParser { static QueryParser load() { ServiceLoader loader = ServiceLoader.load(QueryParser.class); - QueryParser instance = loader.iterator().next(); - if (Objects.nonNull(instance)) { - return instance; + if (loader.iterator().hasNext()) { + QueryParser instance = loader.iterator().next(); + if (Objects.nonNull(instance)) { + return instance; + } } - String parser = System.getProperty("dubbo.polaris.query_parser"); - if (parser.equals("JsonPath")) { - return new JsonPathQueryParser(); - } - return new JavaObjectQueryParser(); + return new JsonPathQueryParser(); } } diff --git a/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/registry/BaseBootConfigHandler.java b/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/registry/BaseBootConfigHandler.java index 8d750af..55eacce 100644 --- a/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/registry/BaseBootConfigHandler.java +++ b/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/registry/BaseBootConfigHandler.java @@ -17,6 +17,7 @@ package com.tencent.polaris.common.registry; +import com.tencent.polaris.common.utils.Consts; import com.tencent.polaris.factory.config.ConfigurationImpl; import java.util.Map; import org.slf4j.Logger; diff --git a/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/registry/DubboServiceInfo.java b/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/registry/DubboServiceInfo.java new file mode 100644 index 0000000..a2d968d --- /dev/null +++ b/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/registry/DubboServiceInfo.java @@ -0,0 +1,109 @@ +/* + * Tencent is pleased to support the open source community by making Polaris available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * 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 com.tencent.polaris.common.registry; + +import org.apache.dubbo.common.utils.StringUtils; + +public class DubboServiceInfo { + + private String service; + + private String interfaceName; + + private String methodName; + + public String getService() { + return service; + } + + public void setService(String service) { + this.service = service; + } + + public String getInterfaceName() { + return interfaceName; + } + + public void setInterfaceName(String interfaceName) { + this.interfaceName = interfaceName; + } + + public String getMethodName() { + return methodName; + } + + public void setMethodName(String methodName) { + this.methodName = methodName; + } + + public String getRateLimitInterface() { + if (StringUtils.isEmpty(interfaceName)) { + return interfaceName; + } + return methodName; + } + + public String getReportMethodName() { + return this.interfaceName + "#" + this.methodName; + } + + public static Builder builder() { + return new Builder(); + } + + public static final class Builder { + private String service; + private String interfaceName; + private String methodName; + + private Builder() { + } + + public Builder service(String service) { + this.service = service; + return this; + } + + public Builder interfaceName(String interfaceName) { + this.interfaceName = interfaceName; + return this; + } + + public Builder methodName(String methodName) { + this.methodName = methodName; + return this; + } + + public DubboServiceInfo build() { + DubboServiceInfo dubboServiceInfo = new DubboServiceInfo(); + dubboServiceInfo.setService(service); + dubboServiceInfo.setInterfaceName(interfaceName); + dubboServiceInfo.setMethodName(methodName); + return dubboServiceInfo; + } + } + + @Override + public String toString() { + return "DubboServiceInfo{" + + "service='" + service + '\'' + + ", interfaceName='" + interfaceName + '\'' + + ", methodName='" + methodName + '\'' + + '}'; + } +} diff --git a/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/registry/PolarisConfig.java b/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/registry/PolarisConfig.java index ebc1847..c8ae554 100644 --- a/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/registry/PolarisConfig.java +++ b/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/registry/PolarisConfig.java @@ -18,6 +18,8 @@ package com.tencent.polaris.common.registry; import java.util.Map; + +import com.tencent.polaris.common.utils.Consts; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -27,18 +29,19 @@ public class PolarisConfig { private final String namespace; - private final String registryAddress; + private String discoverAddress; - private final String configAddress; + private String configAddress; private final String token; private final int ttl; - public PolarisConfig(String host, int port, Map parameters) { - registryAddress = String.format("%s:%d", host, port); - configAddress = String.format("%s:%d", host, Consts.CONFIG_PORT); + private final PolarisOperators.OperatorType operatorType; + public PolarisConfig(PolarisOperators.OperatorType operatorType, String host, int port, Map parameters) { + this.operatorType = operatorType; + initAddress(host, port, parameters); String namespaceStr = parameters.get(Consts.KEY_NAMESPACE); if (null == namespaceStr || namespaceStr.length() == 0) { namespaceStr = Consts.DEFAULT_NAMESPACE; @@ -58,22 +61,41 @@ public PolarisConfig(String host, int port, Map parameters) { LOG.info("[Common] construct polarisConfig {}", this); } - public String getNamespace() { - return namespace; + private void initAddress(String host, int port, Map parameters) { + int discoverPort = 8091; + int configPort = 8093; + switch (operatorType) { + case CONFIG: + configPort = port; + String discoverPortStr = parameters.getOrDefault(Consts.DISCOVER_PORT, discoverPort + ""); + discoverPort = Integer.parseInt(discoverPortStr); + break; + case GOVERNANCE: + discoverPort = port; + String configPortStr = parameters.getOrDefault(Consts.CONFIG_PORT, configPort + ""); + configPort = Integer.parseInt(configPortStr); + break; + } + discoverAddress = String.format("%s:%d", host, discoverPort); + configAddress = String.format("%s:%d", host, configPort); } - public String getRegistryAddress() { - return registryAddress; + public String getNamespace() { + return namespace; } - public String getToken() { - return token; + public String getDiscoverAddress() { + return discoverAddress; } public String getConfigAddress() { return configAddress; } + public String getToken() { + return token; + } + public int getTtl() { return ttl; } @@ -82,10 +104,11 @@ public int getTtl() { public String toString() { return "PolarisConfig{" + "namespace='" + namespace + '\'' + - ", registryAddress='" + registryAddress + '\'' + + ", discoverAddress='" + discoverAddress + '\'' + ", configAddress='" + configAddress + '\'' + ", token='" + token + '\'' + ", ttl=" + ttl + + ", operatorType=" + operatorType + '}'; } } diff --git a/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/registry/PolarisOperator.java b/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/registry/PolarisOperator.java index 18394b7..74af333 100644 --- a/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/registry/PolarisOperator.java +++ b/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/registry/PolarisOperator.java @@ -19,7 +19,6 @@ import com.tencent.polaris.api.core.ConsumerAPI; import com.tencent.polaris.api.core.ProviderAPI; import com.tencent.polaris.api.listener.ServiceListener; -import com.tencent.polaris.api.plugin.circuitbreaker.ResourceStat; import com.tencent.polaris.api.pojo.DefaultServiceInstances; import com.tencent.polaris.api.pojo.Instance; import com.tencent.polaris.api.pojo.RetStatus; @@ -45,8 +44,10 @@ import com.tencent.polaris.circuitbreak.api.CircuitBreakAPI; import com.tencent.polaris.circuitbreak.factory.CircuitBreakAPIFactory; import com.tencent.polaris.client.api.SDKContext; +import com.tencent.polaris.configuration.api.core.ConfigFilePublishService; import com.tencent.polaris.configuration.api.core.ConfigFileService; import com.tencent.polaris.configuration.factory.ConfigFileServiceFactory; +import com.tencent.polaris.configuration.factory.ConfigFileServicePublishFactory; import com.tencent.polaris.factory.ConfigAPIFactory; import com.tencent.polaris.factory.api.DiscoveryAPIFactory; import com.tencent.polaris.factory.api.RouterAPIFactory; @@ -61,14 +62,13 @@ import com.tencent.polaris.router.api.rpc.ProcessLoadBalanceResponse; import com.tencent.polaris.router.api.rpc.ProcessRoutersRequest; import com.tencent.polaris.router.api.rpc.ProcessRoutersResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import shade.polaris.com.google.protobuf.Message; public class PolarisOperator { @@ -88,29 +88,39 @@ public class PolarisOperator { private CircuitBreakAPI circuitBreakAPI; - public PolarisOperator(String host, int port, Map parameters, BootConfigHandler... handlers) { - polarisConfig = new PolarisConfig(host, port, parameters); - init(parameters, handlers); + private ConfigFileService configFileAPI; + + private ConfigFilePublishService configFilePublishAPI; + + PolarisOperator(PolarisOperators.OperatorType operatorType, String host, int port, Map parameters, BootConfigHandler... handlers) { + polarisConfig = new PolarisConfig(operatorType, host, port, parameters); + init(operatorType, parameters, handlers); } - private void init(Map parameters, BootConfigHandler... handlers) { + private void init(PolarisOperators.OperatorType operatorType, Map parameters, BootConfigHandler... handlers) { ConfigurationImpl configuration = (ConfigurationImpl) ConfigAPIFactory.defaultConfig(); configuration.setDefault(); - configuration.getGlobal().getServerConnector() - .setAddresses(Collections.singletonList(polarisConfig.getRegistryAddress())); - configuration.getConfigFile().getServerConnector() - .setAddresses(Collections.singletonList(polarisConfig.getConfigAddress())); if (null != handlers && handlers.length > 0) { for (BootConfigHandler bootConfigHandler : handlers) { bootConfigHandler.handle(parameters, configuration); } } + + // 设置服务治理连接地址 + configuration.getGlobal().getServerConnector() + .setAddresses(Collections.singletonList(polarisConfig.getDiscoverAddress())); + // 设置配置中心连接地址 + configuration.getConfigFile().getServerConnector() + .setAddresses(Collections.singletonList(polarisConfig.getConfigAddress())); sdkContext = SDKContext.initContextByConfig(configuration); consumerAPI = DiscoveryAPIFactory.createConsumerAPIByContext(sdkContext); providerAPI = DiscoveryAPIFactory.createProviderAPIByContext(sdkContext); limitAPI = LimitAPIFactory.createLimitAPIByContext(sdkContext); routerAPI = RouterAPIFactory.createRouterAPIByContext(sdkContext); circuitBreakAPI = CircuitBreakAPIFactory.createCircuitBreakAPIByContext(sdkContext); + // + configFileAPI = ConfigFileServiceFactory.createConfigFileService(sdkContext); + configFilePublishAPI = ConfigFileServicePublishFactory.createConfigFilePublishService(sdkContext); } public void destroy() { @@ -121,7 +131,7 @@ public void destroy() { * 服务注册 */ public void register(String service, String host, int port, String protocol, String version, int weight, - Map metadata) { + Map metadata) { LOGGER.info( "[POLARIS] start to register: service {}, host {}, port {}, protocol {}, version {}, weight {}, metadata {}", service, host, port, protocol, version, weight, metadata); @@ -194,7 +204,7 @@ public Instance[] getAvailableInstances(String service, boolean includeCircuitBr * @param delay 本次服务调用延迟,单位ms */ public void reportInvokeResult(String service, String method, String host, int port, String callerIp, long delay, RetStatus retStatus, - int code) { + int code) { ServiceCallResult serviceCallResult = new ServiceCallResult(); serviceCallResult.setNamespace(polarisConfig.getNamespace()); serviceCallResult.setService(service); @@ -268,23 +278,31 @@ public PolarisConfig getPolarisConfig() { return polarisConfig; } - public ConsumerAPI getConsumerAPI() { + public ConsumerAPI getConsumerAPI() { return consumerAPI; } - public ProviderAPI getProviderAPI() { + public ProviderAPI getProviderAPI() { return providerAPI; } - public LimitAPI getLimitAPI() { + public LimitAPI getLimitAPI() { return limitAPI; } - public RouterAPI getRouterAPI() { + public RouterAPI getRouterAPI() { return routerAPI; } - public CircuitBreakAPI getCircuitBreakAPI() { + public ConfigFileService getConfigFileAPI() { + return configFileAPI; + } + + public ConfigFilePublishService getConfigFilePublishAPI() { + return configFilePublishAPI; + } + + public CircuitBreakAPI getCircuitBreakAPI() { return circuitBreakAPI; } } diff --git a/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/registry/PolarisOperatorDelegate.java b/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/registry/PolarisOperatorDelegate.java index 23f5eb0..20ab9ed 100644 --- a/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/registry/PolarisOperatorDelegate.java +++ b/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/registry/PolarisOperatorDelegate.java @@ -17,13 +17,23 @@ package com.tencent.polaris.common.registry; -public class PolarisOperatorDelegate { +import org.apache.dubbo.rpc.model.ApplicationModel; +import org.apache.dubbo.rpc.model.ScopeModelAware; + +public class PolarisOperatorDelegate implements ScopeModelAware { private PolarisOperator polarisOperator; private final Object lock = new Object(); - public PolarisOperator getPolarisOperator() { + protected ApplicationModel applicationModel; + + @Override + public void setApplicationModel(ApplicationModel applicationModel) { + this.applicationModel = applicationModel; + } + + public PolarisOperator getGovernancePolarisOperator() { if (null != polarisOperator) { return polarisOperator; } @@ -31,8 +41,12 @@ public PolarisOperator getPolarisOperator() { if (null != polarisOperator) { return polarisOperator; } - polarisOperator = PolarisOperators.INSTANCE.getFirstPolarisOperator(); + polarisOperator = PolarisOperators.INSTANCE.getGovernancePolarisOperator(); return polarisOperator; } } + + protected String formatCode(Object val) { + return "POLARIS:" + val; + } } diff --git a/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/registry/PolarisOperators.java b/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/registry/PolarisOperators.java index 91e3047..0ff2076 100644 --- a/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/registry/PolarisOperators.java +++ b/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/registry/PolarisOperators.java @@ -28,35 +28,42 @@ public class PolarisOperators { - private final Map polarisOperatorMap = new ConcurrentHashMap<>(); + enum OperatorType { + GOVERNANCE, + CONFIG, + } + + private final Map> polarisOperatorMap; private PolarisOperators() { + polarisOperatorMap = new ConcurrentHashMap<>(); + polarisOperatorMap.put(OperatorType.GOVERNANCE, new ConcurrentHashMap<>()); + polarisOperatorMap.put(OperatorType.CONFIG, new ConcurrentHashMap<>()); } public static final PolarisOperators INSTANCE = new PolarisOperators(); - public PolarisOperator loadOrStore(String host, int port, Map parameters, BootConfigHandler... handlers) { - Map params = Optional.ofNullable(parameters).orElse(Collections.EMPTY_MAP); + public PolarisOperator loadOrStoreForGovernance(String host, int port, Map parameters) { + Map operatorMap = polarisOperatorMap.get(OperatorType.GOVERNANCE); + Map params = Optional.ofNullable(parameters).orElse(Collections.emptyMap()); String key = host + ":" + port + "|hash_code:" + params.hashCode(); - PolarisOperator saveVal = polarisOperatorMap.computeIfAbsent(key, s -> new PolarisOperator(host, port, parameters, handlers)); - return saveVal; + return operatorMap.computeIfAbsent(key, s -> new PolarisOperator(OperatorType.GOVERNANCE, host, port, parameters, new BaseBootConfigHandler())); } - public PolarisOperator getPolarisOperator(String host, int port) { - String address = String.format("%s:%d", host, port); - return polarisOperatorMap.get(address); + public PolarisOperator loadOrStoreForConfig(String host, int port, Map parameters) { + Map operatorMap = polarisOperatorMap.get(OperatorType.CONFIG); + Map params = Optional.ofNullable(parameters).orElse(Collections.emptyMap()); + String key = host + ":" + port + "|hash_code:" + params.hashCode(); + return operatorMap.computeIfAbsent(key, s -> new PolarisOperator(OperatorType.CONFIG, host, port, parameters, new BaseBootConfigHandler())); } - public PolarisOperator getFirstPolarisOperator() { - if (polarisOperatorMap.isEmpty()) { + + public PolarisOperator getGovernancePolarisOperator() { + Map operatorMap = polarisOperatorMap.get(OperatorType.GOVERNANCE); + if (operatorMap.isEmpty()) { return null; } - return polarisOperatorMap.values().iterator().next(); - } - - public void deletePolarisOperator(String host, int port) { - String address = String.format("%s:%d", host, port); - polarisOperatorMap.remove(address); + return operatorMap.values().iterator().next(); } } diff --git a/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/registry/Consts.java b/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/utils/Consts.java similarity index 78% rename from polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/registry/Consts.java rename to polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/utils/Consts.java index 3b5e378..0f80213 100644 --- a/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/registry/Consts.java +++ b/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/utils/Consts.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.tencent.polaris.common.registry; +package com.tencent.polaris.common.utils; public interface Consts { @@ -22,8 +22,6 @@ public interface Consts { int DEFAULT_TTL = 5; - int CONFIG_PORT = 8093; - String KEY_NAMESPACE = "namespace"; String KEY_TIMEOUT = "timeout"; @@ -41,4 +39,14 @@ public interface Consts { String INSTANCE_KEY_CIRCUIT_BREAKER = "_internal_circuit_breaker"; String INSTANCE_KEY_ID = "_internal_id"; + + String INSTANCE_VERSION = "version"; + + String INSTANCE_WEIGHT = "weight"; + + String DUBBO_PROTOCOL = "dubbo"; + + String CONFIG_PORT = "config_port"; + + String DISCOVER_PORT = "discover_port"; } diff --git a/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/registry/ConvertUtils.java b/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/utils/ConvertUtils.java similarity index 95% rename from polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/registry/ConvertUtils.java rename to polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/utils/ConvertUtils.java index ce08460..9cb7541 100644 --- a/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/registry/ConvertUtils.java +++ b/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/utils/ConvertUtils.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.tencent.polaris.common.registry; +package com.tencent.polaris.common.utils; import com.tencent.polaris.api.pojo.CircuitBreakerStatus; import com.tencent.polaris.api.pojo.CircuitBreakerStatus.Status; diff --git a/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/utils/DubboUtils.java b/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/utils/DubboUtils.java new file mode 100644 index 0000000..e5ffc6f --- /dev/null +++ b/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/utils/DubboUtils.java @@ -0,0 +1,79 @@ +/* + * Copyright 2019 NAVER Corp. + * + * Licensed 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 com.tencent.polaris.common.utils; + +import com.tencent.polaris.common.registry.DubboServiceInfo; +import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.config.ConfigurationUtils; +import org.apache.dubbo.common.constants.RegistryConstants; +import org.apache.dubbo.rpc.Invocation; +import org.apache.dubbo.rpc.Invoker; +import org.apache.dubbo.rpc.model.ScopeModel; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class DubboUtils { + + // 这里需要获取注册粒度 + + public static String getRegisterMode(ScopeModel model) { + return ConfigurationUtils.getCachedDynamicProperty(model, + RegistryConstants.DUBBO_REGISTER_MODE_DEFAULT_KEY, + RegistryConstants.DEFAULT_REGISTER_MODE_INSTANCE); + } + + public static List analyzeDubboServiceInfo(ScopeModel model, URL url, Invocation invocation) { + String registerMode = getRegisterMode(model); + + switch (registerMode) { + case RegistryConstants.DEFAULT_REGISTER_MODE_INSTANCE: + return Collections.singletonList(DubboServiceInfo.builder() + .service(url.getApplication()) + .interfaceName(invocation.getServiceName()) + .methodName(invocation.getMethodName()) + .build()); + case RegistryConstants.DEFAULT_REGISTER_MODE_ALL: + DubboServiceInfo instanceInfo = new DubboServiceInfo(); + instanceInfo.setService(url.getApplication()); + instanceInfo.setInterfaceName(invocation.getServiceName()); + instanceInfo.setMethodName(invocation.getMethodName()); + + DubboServiceInfo interfaceInfo = new DubboServiceInfo(); + instanceInfo.setService(invocation.getServiceName()); + instanceInfo.setMethodName(invocation.getMethodName()); + + List serviceInfos = new ArrayList<>(2); + serviceInfos.add(instanceInfo); + serviceInfos.add(interfaceInfo); + return serviceInfos; + case RegistryConstants.DEFAULT_REGISTER_MODE_INTERFACE: + return Collections.singletonList(DubboServiceInfo.builder() + .service(invocation.getServiceName()) + .methodName(invocation.getMethodName()) + .build()); + default: + throw new IllegalStateException("invalid dubbo register mode: " + registerMode); + } + } + + public static List analyzeDubboServiceInfo(ScopeModel model, Invoker invoker, Invocation invocation) { + return analyzeDubboServiceInfo(model, invoker.getUrl(), invocation); + } + +} diff --git a/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/utils/ExampleConsts.java b/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/utils/ExampleConsts.java deleted file mode 100644 index 14ae8cf..0000000 --- a/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/utils/ExampleConsts.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Polaris available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * 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 com.tencent.polaris.common.utils; - -public interface ExampleConsts { - - String ENV_KEY_VERSION = "VERSION"; - - String ENV_KEY_PORT = "DUBBO_PORT_TO_BIND"; - - String ENV_KEY_EXCEPTION = "EXCEPTION"; - - String POLARIS_ADDRESS = "polaris://127.0.0.1:8091"; -} diff --git a/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/utils/ExtensionConsts.java b/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/utils/ExtensionConsts.java deleted file mode 100644 index be42461..0000000 --- a/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/utils/ExtensionConsts.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Polaris available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * 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 com.tencent.polaris.common.utils; - -public interface ExtensionConsts { - - String PLUGIN_REGISTRY_NAME = "polaris"; - - String PLUGIN_ROUTER_NAME = "polaris_router"; - - String PLUGIN_CIRCUITBREAKER_NAME = "polaris_circuitbreaker"; - - -} diff --git a/pom.xml b/pom.xml index 71f5f63..4731020 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,6 @@ polaris-adapter-dubbo dubbo - dubbox Polaris Parent Dubbox Java Polaris POM @@ -38,7 +37,7 @@ - 0.2.3-SNAPSHOT + 0.1.0-3.2.7-SNAPSHOT ${maven.build.timestamp} yyyy-MM-dd HH:mm UTF-8 @@ -52,7 +51,8 @@ 3.0.1 3.0.0-M1 1.2.5 - 1.12.10 + 1.15.0-SNAPSHOT + 3.2.7 1.7.25 2.8.0