From faac56d306a9f33297b5d9a85cdcac33a3d384ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=80=85=E5=BC=88?= Date: Mon, 7 Jan 2019 11:54:28 +0800 Subject: [PATCH 01/39] doc: add blog with Sentinel in action (#392) --- doc/awesome-sentinel.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/doc/awesome-sentinel.md b/doc/awesome-sentinel.md index d871eb2d43..c7112f21e0 100644 --- a/doc/awesome-sentinel.md +++ b/doc/awesome-sentinel.md @@ -33,4 +33,10 @@ You can also add to [sentinel-group/sentinel-awesome](https://github.com/sentine - [Guideline: 从 Hystrix 迁移到 Sentinel](https://github.com/alibaba/Sentinel/wiki/Guideline:-%E4%BB%8E-Hystrix-%E8%BF%81%E7%A7%BB%E5%88%B0-Sentinel) by [Eric Zhao](https://github.com/sczyh30) - [Sentinel 控制台监控数据持久化【MySQL】(Spring Data JPA)](https://www.cnblogs.com/cdfive2018/p/9838577.html) by [cdfive](https://github.com/cdfive) - [Sentinel 控制台监控数据持久化【InfluxDB】](https://www.cnblogs.com/cdfive2018/p/9914838.html) by [cdfive](https://github.com/cdfive) -- [Sentinel一体化监控解决方案 CrateDB+Grafana](https://blog.csdn.net/huyong1990/article/details/82392386) by [Young Hu](https://github.com/YoungHu) \ No newline at end of file +- [Sentinel一体化监控解决方案 CrateDB+Grafana](https://blog.csdn.net/huyong1990/article/details/82392386) by [Young Hu](https://github.com/YoungHu) +- [Sentinel 原理-全解析](https://mp.weixin.qq.com/s/7_pCkamNv0269e5l9_Wz7w) by [houyi](https://github.com/all4you) +- [Sentinel 原理-调用链](https://mp.weixin.qq.com/s/UEzwD22YC6jpp02foNSXnw) by [houyi](https://github.com/all4you) +- [Sentinel 原理-滑动窗口](https://mp.weixin.qq.com/s/B1_7Kb_CxeKEAv43kdCWOA) by [houyi](https://github.com/all4you) +- [Sentinel 实战-限流](https://mp.weixin.qq.com/s/rjyU37Dm-sxNln7GUD8tOw) by [houyi](https://github.com/all4you) +- [Sentinel 实战-控制台](https://mp.weixin.qq.com/s/23EDFHMXLwsDqw-4O5dR5A) by [houyi](https://github.com/all4you) +- [Sentinel 实战-规则持久化](https://mp.weixin.qq.com/s/twMFiBfRawKLR-1-N-f1yw) by [houyi](https://github.com/all4you) \ No newline at end of file From 4c4cb348668d21e3e34b9c55bb78429046a9faf3 Mon Sep 17 00:00:00 2001 From: cdfive <31885791+cdfive@users.noreply.github.com> Date: Mon, 7 Jan 2019 16:17:19 +0800 Subject: [PATCH 02/39] dashboard: make fallbackToLocalWhenFail be configurable in dashboard and fix edit rule issue when cancel (#370) - Make fallbackToLocalWhenFail of cluster rules configurable in dashboard - Fix edit rule when hit cancel button (object share problem solved by deep copy) - Add metric table td header's title for friendly prompt info --- .../resources/app/scripts/controllers/authority.js | 2 +- .../resources/app/scripts/controllers/degrade.js | 2 +- .../resources/app/scripts/controllers/flow_v1.js | 2 +- .../resources/app/scripts/controllers/flow_v2.js | 5 +++-- .../app/scripts/controllers/param_flow.js | 2 +- .../resources/app/scripts/controllers/system.js | 2 +- .../app/views/dialog/flow-rule-dialog.html | 14 +++++++++++++- .../main/webapp/resources/app/views/metric.html | 6 +++--- 8 files changed, 24 insertions(+), 11 deletions(-) diff --git a/sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/authority.js b/sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/authority.js index 96ef1239d2..fb7b789daf 100644 --- a/sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/authority.js +++ b/sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/authority.js @@ -55,7 +55,7 @@ angular.module('sentinelDashboardApp').controller('AuthorityRuleController', ['$ var authorityRuleDialog; $scope.editRule = function (rule) { - $scope.currentRule = rule; + $scope.currentRule = angular.copy(rule); $scope.authorityRuleDialog = { title: '编辑授权规则', type: 'edit', diff --git a/sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/degrade.js b/sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/degrade.js index 14423f6510..45773c66a0 100755 --- a/sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/degrade.js +++ b/sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/degrade.js @@ -45,7 +45,7 @@ app.controller('DegradeCtl', ['$scope', '$stateParams', 'DegradeService', 'ngDia var degradeRuleDialog; $scope.editRule = function (rule) { - $scope.currentRule = rule; + $scope.currentRule = angular.copy(rule); $scope.degradeRuleDialog = { title: '编辑降级规则', type: 'edit', diff --git a/sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/flow_v1.js b/sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/flow_v1.js index d587a13d88..643ff12d92 100755 --- a/sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/flow_v1.js +++ b/sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/flow_v1.js @@ -61,7 +61,7 @@ app.controller('FlowControllerV1', ['$scope', '$stateParams', 'FlowServiceV1', ' var flowRuleDialog; $scope.editRule = function (rule) { - $scope.currentRule = rule; + $scope.currentRule = angular.copy(rule); $scope.flowRuleDialog = { title: '编辑流控规则', type: 'edit', diff --git a/sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/flow_v2.js b/sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/flow_v2.js index 4e11c2440b..8a98c8d507 100755 --- a/sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/flow_v2.js +++ b/sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/flow_v2.js @@ -61,7 +61,7 @@ app.controller('FlowControllerV2', ['$scope', '$stateParams', 'FlowServiceV2', ' var flowRuleDialog; $scope.editRule = function (rule) { - $scope.currentRule = rule; + $scope.currentRule = angular.copy(rule); $scope.flowRuleDialog = { title: '编辑流控规则', type: 'edit', @@ -88,7 +88,8 @@ app.controller('FlowControllerV2', ['$scope', '$stateParams', 'FlowServiceV2', ' limitApp: 'default', clusterMode: false, clusterConfig: { - thresholdType: 0 + thresholdType: 0, + fallbackToLocalWhenFail: true } }; $scope.flowRuleDialog = { diff --git a/sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/param_flow.js b/sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/param_flow.js index 4b6f799e8f..65cf157edd 100644 --- a/sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/param_flow.js +++ b/sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/param_flow.js @@ -129,7 +129,7 @@ angular.module('sentinelDashboardApp').controller('ParamFlowController', ['$scop var paramFlowRuleDialog; $scope.editRule = function (rule) { - $scope.currentRule = rule; + $scope.currentRule = angular.copy(rule); $scope.paramFlowRuleDialog = { title: '编辑热点规则', type: 'edit', diff --git a/sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/system.js b/sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/system.js index c08d418f78..8e7ed65556 100755 --- a/sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/system.js +++ b/sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/system.js @@ -58,7 +58,7 @@ app.controller('SystemCtl', ['$scope', '$stateParams', 'SystemService', 'ngDialo $scope.getMachineRules = getMachineRules; var systemRuleDialog; $scope.editRule = function (rule) { - $scope.currentRule = rule; + $scope.currentRule = angular.copy(rule); $scope.systemRuleDialog = { title: '编辑系统保护规则', type: 'edit', diff --git a/sentinel-dashboard/src/main/webapp/resources/app/views/dialog/flow-rule-dialog.html b/sentinel-dashboard/src/main/webapp/resources/app/views/dialog/flow-rule-dialog.html index bd07ac3611..b7dd29c502 100755 --- a/sentinel-dashboard/src/main/webapp/resources/app/views/dialog/flow-rule-dialog.html +++ b/sentinel-dashboard/src/main/webapp/resources/app/views/dialog/flow-rule-dialog.html @@ -53,7 +53,9 @@
+
@@ -66,6 +68,16 @@
+
+ +
+ +
+
+
@@ -133,4 +145,4 @@
- + \ No newline at end of file diff --git a/sentinel-dashboard/src/main/webapp/resources/app/views/metric.html b/sentinel-dashboard/src/main/webapp/resources/app/views/metric.html index ed08eb7459..a77b895f0a 100755 --- a/sentinel-dashboard/src/main/webapp/resources/app/views/metric.html +++ b/sentinel-dashboard/src/main/webapp/resources/app/views/metric.html @@ -51,9 +51,9 @@ 时间 - p_qps - b_qps - rt(ms) + p_qps + b_qps + rt(ms) From d3b3d6572fc8b45ef97827e609169e24a497b858 Mon Sep 17 00:00:00 2001 From: Zhe Jiang Date: Mon, 7 Jan 2019 16:40:35 +0800 Subject: [PATCH 03/39] dashboard: add healthCount/total information in sidebar of Sentinel dashboard (#376) --- .../app/scripts/directives/sidebar/sidebar.html | 1 + .../app/scripts/directives/sidebar/sidebar.js | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/sentinel-dashboard/src/main/webapp/resources/app/scripts/directives/sidebar/sidebar.html b/sentinel-dashboard/src/main/webapp/resources/app/scripts/directives/sidebar/sidebar.html index 6a030b3729..dbabfff672 100755 --- a/sentinel-dashboard/src/main/webapp/resources/app/scripts/directives/sidebar/sidebar.html +++ b/sentinel-dashboard/src/main/webapp/resources/app/scripts/directives/sidebar/sidebar.html @@ -19,6 +19,7 @@  {{entry.app}} + ({{entry.heathCount}}/{{entry.machines.length}}) diff --git a/sentinel-dashboard/src/main/webapp/resources/app/scripts/directives/sidebar/sidebar.js b/sentinel-dashboard/src/main/webapp/resources/app/scripts/directives/sidebar/sidebar.js index ce1a903003..55f63548f9 100755 --- a/sentinel-dashboard/src/main/webapp/resources/app/scripts/directives/sidebar/sidebar.js +++ b/sentinel-dashboard/src/main/webapp/resources/app/scripts/directives/sidebar/sidebar.js @@ -21,11 +21,22 @@ angular.module('sentinelDashboardApp') function (data) { if (data.code === 0) { let initHashApp = $location.path().split('/')[3]; + let currTime = moment(new Date()).utc().add(-1000*60*5).format('YYYY-MM-DDTHH:mm:ss') $scope.apps = data.data; - $scope.apps.forEach(function (item) { + $scope.apps = $scope.apps.map(function (item) { if (item.app === initHashApp) { item.active = true; } + var heathCount = 0; + for (var i in item.machines) { + if (item.machines[i].timestamp>currTime) { + heathCount++; + } + } + item.heathCount = heathCount; + if (heathCount>0) { + return item; + } }); } } From 471bdf7599f3e611623a7d3fe29d8a2500f7bf88 Mon Sep 17 00:00:00 2001 From: Eric Zhao Date: Tue, 8 Jan 2019 09:45:16 +0800 Subject: [PATCH 04/39] dashboard: structure rearrangement and polish related code Signed-off-by: Eric Zhao --- .../{view => controller}/AppController.java | 5 +-- .../AuthorityRuleController.java | 3 +- .../DegradeController.java | 3 +- .../{view => controller}/DemoController.java | 2 +- .../FlowControllerV1.java | 7 ++-- .../MachineRegistryController.java | 3 +- .../MetricController.java | 5 +-- .../ParamFlowRuleController.java | 4 ++- .../ResourceController.java | 5 +-- .../SystemController.java | 3 +- .../cluster/ClusterAssignController.java | 4 +-- .../cluster/ClusterConfigController.java | 4 +-- .../v2}/FlowControllerV2.java | 3 +- .../dashboard/{view => domain}/Result.java | 2 +- .../{view => domain}/vo/MachineInfoVo.java | 2 +- .../{view => domain}/vo/MetricVo.java | 2 +- .../{view => domain}/vo/ResourceVo.java | 2 +- .../sentinel/dashboard/view/HealthCheck.java | 33 ------------------- 18 files changed, 35 insertions(+), 57 deletions(-) rename sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/{view => controller}/AppController.java (94%) rename sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/{view => controller}/AuthorityRuleController.java (98%) rename sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/{view => controller}/DegradeController.java (98%) rename sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/{view => controller}/DemoController.java (98%) rename sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/{view => controller}/FlowControllerV1.java (97%) rename sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/{view => controller}/MachineRegistryController.java (96%) rename sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/{view => controller}/MetricController.java (97%) rename sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/{view => controller}/ParamFlowRuleController.java (98%) rename sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/{view => controller}/ResourceController.java (95%) rename sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/{view => controller}/SystemController.java (98%) rename sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/{view => controller}/cluster/ClusterAssignController.java (97%) rename sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/{view => controller}/cluster/ClusterConfigController.java (98%) rename sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/{view => controller/v2}/FlowControllerV2.java (98%) rename sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/{view => domain}/Result.java (98%) rename sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/{view => domain}/vo/MachineInfoVo.java (98%) rename sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/{view => domain}/vo/MetricVo.java (99%) rename sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/{view => domain}/vo/ResourceVo.java (99%) delete mode 100755 sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/HealthCheck.java diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/AppController.java b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/AppController.java similarity index 94% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/AppController.java rename to sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/AppController.java index 024a094e76..25e453732c 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/AppController.java +++ b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/AppController.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.view; +package com.taobao.csp.sentinel.dashboard.controller; import java.util.ArrayList; import java.util.Collections; @@ -25,7 +25,8 @@ import com.taobao.csp.sentinel.dashboard.discovery.AppInfo; import com.taobao.csp.sentinel.dashboard.discovery.AppManagement; import com.taobao.csp.sentinel.dashboard.discovery.MachineInfo; -import com.taobao.csp.sentinel.dashboard.view.vo.MachineInfoVo; +import com.taobao.csp.sentinel.dashboard.domain.Result; +import com.taobao.csp.sentinel.dashboard.domain.vo.MachineInfoVo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/AuthorityRuleController.java b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/AuthorityRuleController.java similarity index 98% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/AuthorityRuleController.java rename to sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/AuthorityRuleController.java index 367067b98f..1f28e9ba47 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/AuthorityRuleController.java +++ b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/AuthorityRuleController.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.view; +package com.taobao.csp.sentinel.dashboard.controller; import java.util.Date; import java.util.List; @@ -24,6 +24,7 @@ import com.taobao.csp.sentinel.dashboard.client.SentinelApiClient; import com.taobao.csp.sentinel.dashboard.datasource.entity.rule.AuthorityRuleEntity; import com.taobao.csp.sentinel.dashboard.discovery.MachineInfo; +import com.taobao.csp.sentinel.dashboard.domain.Result; import com.taobao.csp.sentinel.dashboard.repository.rule.RuleRepository; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/DegradeController.java b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/DegradeController.java similarity index 98% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/DegradeController.java rename to sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/DegradeController.java index 78d3ffc145..ef50d2b4f1 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/DegradeController.java +++ b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/DegradeController.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.view; +package com.taobao.csp.sentinel.dashboard.controller; import java.util.Date; import java.util.List; @@ -24,6 +24,7 @@ import com.taobao.csp.sentinel.dashboard.datasource.entity.rule.DegradeRuleEntity; import com.taobao.csp.sentinel.dashboard.discovery.MachineInfo; import com.taobao.csp.sentinel.dashboard.client.SentinelApiClient; +import com.taobao.csp.sentinel.dashboard.domain.Result; import com.taobao.csp.sentinel.dashboard.repository.rule.InMemDegradeRuleStore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/DemoController.java b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/DemoController.java similarity index 98% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/DemoController.java rename to sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/DemoController.java index 8b7ab528f2..a30ea440ed 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/DemoController.java +++ b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/DemoController.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.view; +package com.taobao.csp.sentinel.dashboard.controller; import java.util.Random; import java.util.concurrent.TimeUnit; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/FlowControllerV1.java b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/FlowControllerV1.java similarity index 97% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/FlowControllerV1.java rename to sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/FlowControllerV1.java index dd435fe15b..94ac3e5589 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/FlowControllerV1.java +++ b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/FlowControllerV1.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.view; +package com.taobao.csp.sentinel.dashboard.controller; import java.util.Date; import java.util.List; @@ -23,6 +23,7 @@ import com.taobao.csp.sentinel.dashboard.client.SentinelApiClient; import com.taobao.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity; import com.taobao.csp.sentinel.dashboard.discovery.MachineInfo; +import com.taobao.csp.sentinel.dashboard.domain.Result; import com.taobao.csp.sentinel.dashboard.repository.rule.InMemoryRuleRepositoryAdapter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -56,8 +57,8 @@ public class FlowControllerV1 { @GetMapping("/rules") public Result> apiQueryMachineRules(@RequestParam String app, - @RequestParam String ip, - @RequestParam Integer port) { + @RequestParam String ip, + @RequestParam Integer port) { if (StringUtil.isEmpty(app)) { return Result.ofFail(-1, "app can't be null or empty"); } diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/MachineRegistryController.java b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/MachineRegistryController.java similarity index 96% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/MachineRegistryController.java rename to sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/MachineRegistryController.java index 5a73f5ecfd..e55f111f94 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/MachineRegistryController.java +++ b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/MachineRegistryController.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.view; +package com.taobao.csp.sentinel.dashboard.controller; import java.util.Date; @@ -22,6 +22,7 @@ import com.taobao.csp.sentinel.dashboard.discovery.AppManagement; import com.taobao.csp.sentinel.dashboard.discovery.MachineDiscovery; import com.taobao.csp.sentinel.dashboard.discovery.MachineInfo; +import com.taobao.csp.sentinel.dashboard.domain.Result; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/MetricController.java b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/MetricController.java similarity index 97% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/MetricController.java rename to sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/MetricController.java index ee336664e4..9de266800b 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/MetricController.java +++ b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/MetricController.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.view; +package com.taobao.csp.sentinel.dashboard.controller; import java.util.ArrayList; import java.util.Collections; @@ -24,6 +24,7 @@ import java.util.TreeMap; import java.util.concurrent.ConcurrentHashMap; +import com.taobao.csp.sentinel.dashboard.domain.Result; import com.taobao.csp.sentinel.dashboard.repository.metric.MetricsRepository; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -36,7 +37,7 @@ import com.alibaba.csp.sentinel.util.StringUtil; import com.taobao.csp.sentinel.dashboard.datasource.entity.MetricEntity; -import com.taobao.csp.sentinel.dashboard.view.vo.MetricVo; +import com.taobao.csp.sentinel.dashboard.domain.vo.MetricVo; /** * @author leyou diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/ParamFlowRuleController.java b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/ParamFlowRuleController.java similarity index 98% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/ParamFlowRuleController.java rename to sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/ParamFlowRuleController.java index c24b605d85..dfe2cfba45 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/ParamFlowRuleController.java +++ b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/ParamFlowRuleController.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.view; +package com.taobao.csp.sentinel.dashboard.controller; import java.util.Date; import java.util.List; @@ -30,6 +30,7 @@ import com.taobao.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity; import com.taobao.csp.sentinel.dashboard.discovery.AppManagement; import com.taobao.csp.sentinel.dashboard.discovery.MachineInfo; +import com.taobao.csp.sentinel.dashboard.domain.Result; import com.taobao.csp.sentinel.dashboard.repository.rule.RuleRepository; import com.taobao.csp.sentinel.dashboard.util.VersionUtils; import org.slf4j.Logger; @@ -123,6 +124,7 @@ public Result apiAddParamFlowRule(@RequestBody ParamFlowRul return unsupportedVersion(); } entity.setId(null); + entity.getRule().setResource(entity.getResource().trim()); Date date = new Date(); entity.setGmtCreate(date); entity.setGmtModified(date); diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/ResourceController.java b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/ResourceController.java similarity index 95% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/ResourceController.java rename to sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/ResourceController.java index a6e16cae6c..3189923f98 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/ResourceController.java +++ b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/ResourceController.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.view; +package com.taobao.csp.sentinel.dashboard.controller; import java.util.List; import java.util.stream.Collectors; @@ -23,7 +23,8 @@ import com.taobao.csp.sentinel.dashboard.domain.ResourceTreeNode; import com.taobao.csp.sentinel.dashboard.client.SentinelApiClient; -import com.taobao.csp.sentinel.dashboard.view.vo.ResourceVo; +import com.taobao.csp.sentinel.dashboard.domain.Result; +import com.taobao.csp.sentinel.dashboard.domain.vo.ResourceVo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/SystemController.java b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/SystemController.java similarity index 98% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/SystemController.java rename to sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/SystemController.java index 17dfe83352..437b2e4e5c 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/SystemController.java +++ b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/SystemController.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.view; +package com.taobao.csp.sentinel.dashboard.controller; import java.util.Date; import java.util.List; @@ -23,6 +23,7 @@ import com.taobao.csp.sentinel.dashboard.datasource.entity.rule.SystemRuleEntity; import com.taobao.csp.sentinel.dashboard.discovery.MachineInfo; import com.taobao.csp.sentinel.dashboard.client.SentinelApiClient; +import com.taobao.csp.sentinel.dashboard.domain.Result; import com.taobao.csp.sentinel.dashboard.repository.rule.InMemSystemRuleStore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/cluster/ClusterAssignController.java b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/cluster/ClusterAssignController.java similarity index 97% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/cluster/ClusterAssignController.java rename to sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/cluster/ClusterAssignController.java index 0a91e56b4d..491386cef0 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/cluster/ClusterAssignController.java +++ b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/cluster/ClusterAssignController.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.view.cluster; +package com.taobao.csp.sentinel.dashboard.controller.cluster; import java.util.Collections; import java.util.Set; @@ -24,7 +24,7 @@ import com.taobao.csp.sentinel.dashboard.domain.cluster.ClusterAppAssignResultVO; import com.taobao.csp.sentinel.dashboard.domain.cluster.ClusterAppSingleServerAssignRequest; import com.taobao.csp.sentinel.dashboard.service.ClusterAssignService; -import com.taobao.csp.sentinel.dashboard.view.Result; +import com.taobao.csp.sentinel.dashboard.domain.Result; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/cluster/ClusterConfigController.java b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/cluster/ClusterConfigController.java similarity index 98% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/cluster/ClusterConfigController.java rename to sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/cluster/ClusterConfigController.java index ee234e699e..bcbb3b6506 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/cluster/ClusterConfigController.java +++ b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/cluster/ClusterConfigController.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.view.cluster; +package com.taobao.csp.sentinel.dashboard.controller.cluster; import java.util.List; import java.util.Optional; @@ -37,7 +37,7 @@ import com.taobao.csp.sentinel.dashboard.service.ClusterConfigService; import com.taobao.csp.sentinel.dashboard.util.ClusterEntityUtils; import com.taobao.csp.sentinel.dashboard.util.VersionUtils; -import com.taobao.csp.sentinel.dashboard.view.Result; +import com.taobao.csp.sentinel.dashboard.domain.Result; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/FlowControllerV2.java b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/v2/FlowControllerV2.java similarity index 98% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/FlowControllerV2.java rename to sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/v2/FlowControllerV2.java index c3bf5bf96d..fb9ecb49c8 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/FlowControllerV2.java +++ b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/v2/FlowControllerV2.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.view; +package com.taobao.csp.sentinel.dashboard.controller.v2; import java.util.Date; import java.util.List; @@ -24,6 +24,7 @@ import com.taobao.csp.sentinel.dashboard.repository.rule.InMemoryRuleRepositoryAdapter; import com.taobao.csp.sentinel.dashboard.rule.DynamicRuleProvider; import com.taobao.csp.sentinel.dashboard.rule.DynamicRulePublisher; +import com.taobao.csp.sentinel.dashboard.domain.Result; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/Result.java b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/Result.java similarity index 98% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/Result.java rename to sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/Result.java index 5f8ee7467b..23d8d84dda 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/Result.java +++ b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/Result.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.view; +package com.taobao.csp.sentinel.dashboard.domain; /** * @author leyou diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/vo/MachineInfoVo.java b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/vo/MachineInfoVo.java similarity index 98% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/vo/MachineInfoVo.java rename to sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/vo/MachineInfoVo.java index 4e9af36785..835237e101 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/vo/MachineInfoVo.java +++ b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/vo/MachineInfoVo.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.view.vo; +package com.taobao.csp.sentinel.dashboard.domain.vo; import java.util.ArrayList; import java.util.Date; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/vo/MetricVo.java b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/vo/MetricVo.java similarity index 99% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/vo/MetricVo.java rename to sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/vo/MetricVo.java index c2e73713b3..460580c660 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/vo/MetricVo.java +++ b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/vo/MetricVo.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.view.vo; +package com.taobao.csp.sentinel.dashboard.domain.vo; import java.util.ArrayList; import java.util.Collection; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/vo/ResourceVo.java b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/vo/ResourceVo.java similarity index 99% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/vo/ResourceVo.java rename to sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/vo/ResourceVo.java index 1870e6aaad..a5fb302eca 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/vo/ResourceVo.java +++ b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/vo/ResourceVo.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.view.vo; +package com.taobao.csp.sentinel.dashboard.domain.vo; import java.util.ArrayList; import java.util.List; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/HealthCheck.java b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/HealthCheck.java deleted file mode 100755 index 2afb48c7e4..0000000000 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/HealthCheck.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 1999-2018 Alibaba Group Holding Ltd. - * - * 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.taobao.csp.sentinel.dashboard.view; - -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.ResponseBody; - -@Controller -public class HealthCheck { - /** - * 健康检查 - */ - @GetMapping("/health") - public - @ResponseBody - String checkPreload() { - return "success"; - } -} From 883565a5f662ccf1e85dfbfadf7ad8b434cc93d6 Mon Sep 17 00:00:00 2001 From: Arlmls <23259825+Arlmls@users.noreply.github.com> Date: Wed, 9 Jan 2019 17:16:32 +0800 Subject: [PATCH 05/39] dashboard: change text of p_qps and b_qps to be more intuitive in monitoring page (#398) --- .../main/webapp/resources/app/scripts/controllers/metric.js | 4 ++-- .../src/main/webapp/resources/app/views/metric.html | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/metric.js b/sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/metric.js index 7986d2f6ff..2fa4b92fb1 100755 --- a/sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/metric.js +++ b/sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/metric.js @@ -131,10 +131,10 @@ app.controller('MetricCtl', ['$scope', '$stateParams', 'MetricService', '$interv allowAllCanceled: true, itemFormatter: function (val) { if ('passQps' === val) { - return 'p_qps'; + return 'p_qps(通过 QPS)'; } if ('blockQps' === val) { - return 'b_qps'; + return 'b_qps(拒绝 QPS)'; } return val; }, diff --git a/sentinel-dashboard/src/main/webapp/resources/app/views/metric.html b/sentinel-dashboard/src/main/webapp/resources/app/views/metric.html index a77b895f0a..d248bebf5f 100755 --- a/sentinel-dashboard/src/main/webapp/resources/app/views/metric.html +++ b/sentinel-dashboard/src/main/webapp/resources/app/views/metric.html @@ -51,9 +51,9 @@ 时间 - p_qps - b_qps - rt(ms) + 通过QPS + 拒绝QPS + 响应时间(ms) From 4118cae63b865dc252a741be809ff212e199bfee Mon Sep 17 00:00:00 2001 From: Eric Zhao Date: Thu, 10 Jan 2019 10:34:14 +0800 Subject: [PATCH 06/39] dashboard: frontend refinement of monitoring page and flow rule dialog description Signed-off-by: Eric Zhao --- .../webapp/resources/app/scripts/controllers/metric.js | 10 +++++----- .../resources/app/views/dialog/flow-rule-dialog.html | 2 +- .../src/main/webapp/resources/app/views/metric.html | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/metric.js b/sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/metric.js index 2fa4b92fb1..b7e2539de0 100755 --- a/sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/metric.js +++ b/sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/metric.js @@ -89,14 +89,14 @@ app.controller('MetricCtl', ['$scope', '$stateParams', 'MetricService', '$interv min: 0, max: maxQps, fine: true, - alias: 'p_qps' + alias: '通过 QPS' // max: 10 }); chart.scale('blockQps', { min: 0, max: maxQps, fine: true, - alias: 'b_qps', + alias: '拒绝 QPS', }); chart.scale('rt', { min: 0, @@ -131,10 +131,10 @@ app.controller('MetricCtl', ['$scope', '$stateParams', 'MetricService', '$interv allowAllCanceled: true, itemFormatter: function (val) { if ('passQps' === val) { - return 'p_qps(通过 QPS)'; + return '通过 QPS'; } if ('blockQps' === val) { - return 'b_qps(拒绝 QPS)'; + return '拒绝 QPS'; } return val; }, @@ -181,7 +181,7 @@ app.controller('MetricCtl', ['$scope', '$stateParams', 'MetricService', '$interv MetricService.queryAppSortedIdentities(params).success(function (data) { $scope.metrics = []; $scope.emptyObjs = []; - if (data.code == 0 && data.data) { + if (data.code === 0 && data.data) { var metricsObj = data.data.metric; var identityNames = Object.keys(metricsObj); if (identityNames.length < 1) { diff --git a/sentinel-dashboard/src/main/webapp/resources/app/views/dialog/flow-rule-dialog.html b/sentinel-dashboard/src/main/webapp/resources/app/views/dialog/flow-rule-dialog.html index b7dd29c502..a010a25198 100755 --- a/sentinel-dashboard/src/main/webapp/resources/app/views/dialog/flow-rule-dialog.html +++ b/sentinel-dashboard/src/main/webapp/resources/app/views/dialog/flow-rule-dialog.html @@ -73,8 +73,8 @@
+  如果 Token Server 不可用是否退化到单机限流
diff --git a/sentinel-dashboard/src/main/webapp/resources/app/views/metric.html b/sentinel-dashboard/src/main/webapp/resources/app/views/metric.html index d248bebf5f..4f0fc7f588 100755 --- a/sentinel-dashboard/src/main/webapp/resources/app/views/metric.html +++ b/sentinel-dashboard/src/main/webapp/resources/app/views/metric.html @@ -51,9 +51,9 @@ 时间 - 通过QPS - 拒绝QPS - 响应时间(ms) + 通过 QPS + 拒绝QPS + 响应时间(ms) From 219877d80432341a170a5c05131221d76c5af982 Mon Sep 17 00:00:00 2001 From: moon tiger Date: Sat, 12 Jan 2019 10:16:12 +0800 Subject: [PATCH 07/39] Add adapter support for Zuul 1.x (#188) - implement `SentinelPreFilter`, `SentinelPostFilter` and `SentinelErrorFilter` - support fallback --- sentinel-adapter/pom.xml | 7 +- .../sentinel-zuul-adapter/README.md | 148 +++++++++++++++++ .../sentinel-zuul-adapter/pom.xml | 48 ++++++ .../adapter/zuul/constants/ZuulConstant.java | 62 +++++++ .../adapter/zuul/fallback/BlockResponse.java | 67 ++++++++ .../DefaultBlockFallbackProvider.java | 43 +++++ .../fallback/DefaultRequestOriginParser.java | 13 ++ .../zuul/fallback/DefaultUrlCleaner.java | 27 +++ .../zuul/fallback/RequestOriginParser.java | 34 ++++ .../adapter/zuul/fallback/UrlCleaner.java | 31 ++++ .../fallback/ZuulBlockFallbackManager.java | 57 +++++++ .../fallback/ZuulBlockFallbackProvider.java | 40 +++++ .../zuul/filters/AbstractSentinelFilter.java | 46 +++++ .../zuul/filters/SentinelErrorFilter.java | 81 +++++++++ .../zuul/filters/SentinelPostFilter.java | 60 +++++++ .../zuul/filters/SentinelPreFilter.java | 112 +++++++++++++ .../properties/SentinelZuulProperties.java | 80 +++++++++ .../adapter/zuul/util/FilterUtil.java | 157 ++++++++++++++++++ .../ZuulBlockFallbackManagerTest.java | 62 +++++++ .../ZuulBlockFallbackProviderTest.java | 61 +++++++ .../zuul/filters/SentinelErrorFilterTest.java | 56 +++++++ .../zuul/filters/SentinelPostFilterTest.java | 45 +++++ .../zuul/filters/SentinelPreFilterTest.java | 106 ++++++++++++ 23 files changed, 1442 insertions(+), 1 deletion(-) create mode 100755 sentinel-adapter/sentinel-zuul-adapter/README.md create mode 100755 sentinel-adapter/sentinel-zuul-adapter/pom.xml create mode 100644 sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/constants/ZuulConstant.java create mode 100644 sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/fallback/BlockResponse.java create mode 100644 sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/fallback/DefaultBlockFallbackProvider.java create mode 100644 sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/fallback/DefaultRequestOriginParser.java create mode 100755 sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/fallback/DefaultUrlCleaner.java create mode 100644 sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/fallback/RequestOriginParser.java create mode 100755 sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/fallback/UrlCleaner.java create mode 100644 sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/fallback/ZuulBlockFallbackManager.java create mode 100644 sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/fallback/ZuulBlockFallbackProvider.java create mode 100644 sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/filters/AbstractSentinelFilter.java create mode 100644 sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/filters/SentinelErrorFilter.java create mode 100644 sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/filters/SentinelPostFilter.java create mode 100644 sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/filters/SentinelPreFilter.java create mode 100644 sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/properties/SentinelZuulProperties.java create mode 100755 sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/util/FilterUtil.java create mode 100644 sentinel-adapter/sentinel-zuul-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/zuul/fallback/ZuulBlockFallbackManagerTest.java create mode 100644 sentinel-adapter/sentinel-zuul-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/zuul/fallback/ZuulBlockFallbackProviderTest.java create mode 100644 sentinel-adapter/sentinel-zuul-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/zuul/filters/SentinelErrorFilterTest.java create mode 100644 sentinel-adapter/sentinel-zuul-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/zuul/filters/SentinelPostFilterTest.java create mode 100644 sentinel-adapter/sentinel-zuul-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/zuul/filters/SentinelPreFilterTest.java diff --git a/sentinel-adapter/pom.xml b/sentinel-adapter/pom.xml index cfb8d5779d..04a8a4ea18 100755 --- a/sentinel-adapter/pom.xml +++ b/sentinel-adapter/pom.xml @@ -18,6 +18,7 @@ sentinel-web-servlet sentinel-dubbo-adapter sentinel-grpc-adapter + sentinel-zuul-adapter @@ -32,7 +33,11 @@ sentinel-extension ${project.version} - + + com.alibaba.csp + sentinel-web-servlet + ${project.version} + junit junit diff --git a/sentinel-adapter/sentinel-zuul-adapter/README.md b/sentinel-adapter/sentinel-zuul-adapter/README.md new file mode 100755 index 0000000000..dde1c4ebcb --- /dev/null +++ b/sentinel-adapter/sentinel-zuul-adapter/README.md @@ -0,0 +1,148 @@ +# Sentinel Zuul Adapter + +Zuul does not provide rateLimit function, If use default `SentinelRibbonFilter` route filter. it wrapped by Hystrix Command. so only provide Service level +circuit protect. + +Sentinel can provide `ServiceId` level and `API Path` level flow control for zuul gateway service. + +*Note*: this project is for zuul 1. + +## How to use + +1. Add maven dependency + +```xml + + com.alibaba.csp + sentinel-zuul-adapter + x.y.z + + +``` + +2. Register filters + +```java +// get registry +final FilterRegistry r = FilterRegistry.instance(); +// this is property config. set filter ennable +SentinelZuulProperties properties = new SentinelZuulProperties(); +properties.setEnabled(true); +// set url cleaner, here use default +DefaultUrlCleaner defaultUrlCleaner = new DefaultUrlCleaner(); +// set origin parser. here use default +DefaultRequestOriginParser defaultRequestOriginParser = new DefaultRequestOriginParser(); + +// register filters. you must register all three filters. +SentinelPreFilter sentinelPreFilter = new SentinelPreFilter(properties, defaultUrlCleaner, defaultRequestOriginParser); +r.put("sentinelPreFilter", sentinelPreFilter); +SentinelPostFilter postFilter = new SentinelPostFilter(properties); +r.put("sentinelPostFilter", postFilter); +SentinelErrorFilter errorFilter = new SentinelErrorFilter(properties); +r.put("sentinelErrorFilter", errorFilter); +``` + +## How it works + +As Zuul run as per thread per connection block model, we add filters around `route Filter` to trace sentinel statistics. + +- `SentinelPreFilter`: Get an entry of resource,the first order is **ServiceId**(the key in RequestContext is `serviceId`, this can set in own custom filter), then **API Path**. +- `SentinelPostFilter`: When success response,exit entry. +- `SentinelPreFilter`: When get an `Exception`, trace the exception and exit context. + + +the order of Filter can be changed in property: + + + +Filters create structure like: + + +```bash + +EntranceNode: machine-root(t:3 pq:0 bq:0 tq:0 rt:0 prq:0 1mp:0 1mb:0 1mt:0) +-EntranceNode: coke(t:2 pq:0 bq:0 tq:0 rt:0 prq:0 1mp:0 1mb:0 1mt:0) +--coke(t:2 pq:0 bq:0 tq:0 rt:0 prq:0 1mp:0 1mb:0 1mt:0) +---/coke/coke(t:0 pq:0 bq:0 tq:0 rt:0 prq:0 1mp:0 1mb:0 1mt:0) +-EntranceNode: sentinel_default_context(t:0 pq:0 bq:0 tq:0 rt:0 prq:0 1mp:0 1mb:0 1mt:0) +-EntranceNode: book(t:1 pq:0 bq:0 tq:0 rt:0 prq:0 1mp:0 1mb:0 1mt:0) +--book(t:1 pq:0 bq:0 tq:0 rt:0 prq:0 1mp:0 1mb:0 1mt:0) +---/book/coke(t:0 pq:0 bq:0 tq:0 rt:0 prq:0 1mp:0 1mb:0 1mt:0) + +``` + +`book` and `coke` are serviceId. + +`---/book/coke` is api path, the real uri is `/coke`. + + +## Integration with Sentinel DashBord + +1. Start [Sentinel DashBord](https://github.com/alibaba/Sentinel/wiki/%E6%8E%A7%E5%88%B6%E5%8F%B0). + +2. Sentinel has full rule config features. see [Dynamic-Rule-Configuration](https://github.com/alibaba/Sentinel/wiki/Dynamic-Rule-Configuration) + +## Fallbacks + +Implements `SentinelFallbackProvider` to define your own Fallback Provider when Sentinel Block Exception throwing. the default +Fallback Provider is `DefaultBlockFallbackProvider`. + +By default Fallback route is `ServiveId + URI PATH`, example `/book/coke`, first `book` is serviceId, `/coke` is URI PATH. so that both +can be needed. + +Here is an example: + +```java + +// custom provider +public class MyBlockFallbackProvider implements ZuulBlockFallbackProvider { + + private Logger logger = LoggerFactory.getLogger(DefaultBlockFallbackProvider.class); + + // you can define root as service level + @Override + public String getRoute() { + return "/coke/coke"; + } + + @Override + public BlockResponse fallbackResponse(String route, Throwable cause) { + RecordLog.info(String.format("[Sentinel DefaultBlockFallbackProvider] Run fallback route: %s", route)); + if (cause instanceof BlockException) { + return new BlockResponse(429, "Sentinel block exception", route); + } else { + return new BlockResponse(500, "System Error", route); + } + } + } + + // register fallback + ZuulBlockFallbackManager.registerProvider(new MyBlockFallbackProvider()); + +``` + +Default block response + +```json + +{ + "code":429, + "message":"Sentinel block exception", + "route":"/" +} +``` + +## Origin parser + +自定义解析URL + +```java + +public class DefaultRequestOriginParser implements RequestOriginParser { + @Override + public String parseOrigin(HttpServletRequest request) { + return ""; + } +} + +``` diff --git a/sentinel-adapter/sentinel-zuul-adapter/pom.xml b/sentinel-adapter/sentinel-zuul-adapter/pom.xml new file mode 100755 index 0000000000..bf2c237368 --- /dev/null +++ b/sentinel-adapter/sentinel-zuul-adapter/pom.xml @@ -0,0 +1,48 @@ + + + + sentinel-adapter + com.alibaba.csp + 1.4.2-SNAPSHOT + + 4.0.0 + sentinel-zuul-adapter + jar + + + 1.3.1 + 3.1.0 + + + + + com.alibaba.csp + sentinel-core + + + com.netflix.zuul + zuul-core + ${zuul.version} + provided + + + junit + junit + test + + + org.mockito + mockito-core + test + + + javax.servlet + javax.servlet-api + ${servlet.api.version} + provided + + + + \ No newline at end of file diff --git a/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/constants/ZuulConstant.java b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/constants/ZuulConstant.java new file mode 100644 index 0000000000..244fbf4ae8 --- /dev/null +++ b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/constants/ZuulConstant.java @@ -0,0 +1,62 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * 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.alibaba.csp.sentinel.adapter.zuul.constants; + +import com.netflix.zuul.ZuulFilter; + +/** + * @author tiger + */ +public class ZuulConstant { + + /** + * Zuul {@link com.netflix.zuul.context.RequestContext} key for use in load balancer. + */ + public static final String SERVICE_ID_KEY = "serviceId"; + + /** + * {@link ZuulFilter#filterType()} error type. + */ + public static final String ERROR_TYPE = "error"; + + /** + * {@link ZuulFilter#filterType()} post type. + */ + public static final String POST_TYPE = "post"; + + /** + * {@link ZuulFilter#filterType()} pre type. + */ + public static final String PRE_TYPE = "pre"; + + /** + * {@link ZuulFilter#filterType()} route type. + */ + public static final String ROUTE_TYPE = "route"; + + /** + * Filter Order for SEND_RESPONSE_FILTER_ORDER + */ + public static final int SEND_RESPONSE_FILTER_ORDER = 1000; + + /** + * Zuul use Sentinel as default context when serviceId is empty. + */ + public static final String ZUUL_DEFAULT_CONTEXT = "zuul_default_context"; + + private ZuulConstant(){} +} diff --git a/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/fallback/BlockResponse.java b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/fallback/BlockResponse.java new file mode 100644 index 0000000000..6fd617fd10 --- /dev/null +++ b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/fallback/BlockResponse.java @@ -0,0 +1,67 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * 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.alibaba.csp.sentinel.adapter.zuul.fallback; + +/** + * Fall back response for {@link com.alibaba.csp.sentinel.slots.block.BlockException} + * + * @author tiger + */ +public class BlockResponse { + private int code; + private String message; + private String route; + + public BlockResponse(int code, String message, String route) { + this.code = code; + this.message = message; + this.route = route; + } + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getRoute() { + return route; + } + + public void setRoute(String route) { + this.route = route; + } + + @Override + public String toString() { + return "{" + + "\"code\":" + code + + ", \"message\":" + "\"" + message + "\"" + + ", \"route\":" + "\"" + route + "\"" + + '}'; + } +} diff --git a/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/fallback/DefaultBlockFallbackProvider.java b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/fallback/DefaultBlockFallbackProvider.java new file mode 100644 index 0000000000..432db872b1 --- /dev/null +++ b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/fallback/DefaultBlockFallbackProvider.java @@ -0,0 +1,43 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * 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.alibaba.csp.sentinel.adapter.zuul.fallback; + +import com.alibaba.csp.sentinel.log.RecordLog; +import com.alibaba.csp.sentinel.slots.block.BlockException; + +/** + * Default Fallback provider for sentinel {@link BlockException}, {@literal *} meant for all routes. + * + * @author tiger + */ +public class DefaultBlockFallbackProvider implements ZuulBlockFallbackProvider { + + @Override + public String getRoute() { + return "*"; + } + + @Override + public BlockResponse fallbackResponse(String route, Throwable cause) { + RecordLog.info(String.format("[Sentinel DefaultBlockFallbackProvider] Run fallback route: %s", route)); + if (cause instanceof BlockException) { + return new BlockResponse(429, "Sentinel block exception", route); + } else { + return new BlockResponse(500, "System Error", route); + } + } +} diff --git a/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/fallback/DefaultRequestOriginParser.java b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/fallback/DefaultRequestOriginParser.java new file mode 100644 index 0000000000..45dba4d705 --- /dev/null +++ b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/fallback/DefaultRequestOriginParser.java @@ -0,0 +1,13 @@ +package com.alibaba.csp.sentinel.adapter.zuul.fallback; + +import javax.servlet.http.HttpServletRequest; + +/** + * @author tiger + */ +public class DefaultRequestOriginParser implements RequestOriginParser { + @Override + public String parseOrigin(HttpServletRequest request) { + return ""; + } +} diff --git a/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/fallback/DefaultUrlCleaner.java b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/fallback/DefaultUrlCleaner.java new file mode 100755 index 0000000000..097808204e --- /dev/null +++ b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/fallback/DefaultUrlCleaner.java @@ -0,0 +1,27 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * 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.alibaba.csp.sentinel.adapter.zuul.fallback; + +/*** + * @author tiger + */ +public class DefaultUrlCleaner implements UrlCleaner { + + @Override + public String clean(String originUrl) { + return originUrl; + } +} diff --git a/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/fallback/RequestOriginParser.java b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/fallback/RequestOriginParser.java new file mode 100644 index 0000000000..20f6d744a2 --- /dev/null +++ b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/fallback/RequestOriginParser.java @@ -0,0 +1,34 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * 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.alibaba.csp.sentinel.adapter.zuul.fallback; + +import javax.servlet.http.HttpServletRequest; + +/** + * The origin parser parses request origin (e.g. IP, user, appName) from HTTP request. + * + * @author tiger + */ +public interface RequestOriginParser { + + /** + * Parse the origin from given HTTP request. + * + * @param request HTTP request + * @return parsed origin + */ + String parseOrigin(HttpServletRequest request); +} diff --git a/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/fallback/UrlCleaner.java b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/fallback/UrlCleaner.java new file mode 100755 index 0000000000..d6b9a33b46 --- /dev/null +++ b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/fallback/UrlCleaner.java @@ -0,0 +1,31 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * 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.alibaba.csp.sentinel.adapter.zuul.fallback; + +/*** + * @author tiger + */ +public interface UrlCleaner { + + /*** + *

Process the url. Some path variables should be handled and unified.

+ *

e.g. collect_item_relation--10200012121-.html will be converted to collect_item_relation.html

+ * + * @param originUrl original url + * @return processed url + */ + String clean(String originUrl); +} diff --git a/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/fallback/ZuulBlockFallbackManager.java b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/fallback/ZuulBlockFallbackManager.java new file mode 100644 index 0000000000..2760acff6b --- /dev/null +++ b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/fallback/ZuulBlockFallbackManager.java @@ -0,0 +1,57 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * 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.alibaba.csp.sentinel.adapter.zuul.fallback; + +import java.util.HashMap; +import java.util.Map; + +/** + * This provide fall back class manager. + * + * @author tiger + */ +public class ZuulBlockFallbackManager { + + private static Map fallbackProviderCache = new HashMap(); + + private static ZuulBlockFallbackProvider defaultFallbackProvider = new DefaultBlockFallbackProvider(); + + /** + * Register special provider for different route. + */ + public static synchronized void registerProvider(ZuulBlockFallbackProvider provider) { + String route = provider.getRoute(); + if ("*".equals(route) || route == null) { + defaultFallbackProvider = provider; + } else { + fallbackProviderCache.put(route, provider); + } + } + + public static ZuulBlockFallbackProvider getFallbackProvider(String route) { + ZuulBlockFallbackProvider provider = fallbackProviderCache.get(route); + if (provider == null) { + provider = defaultFallbackProvider; + } + return provider; + } + + public synchronized static void clear(){ + fallbackProviderCache.clear(); + } + +} diff --git a/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/fallback/ZuulBlockFallbackProvider.java b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/fallback/ZuulBlockFallbackProvider.java new file mode 100644 index 0000000000..e6b3acb0c8 --- /dev/null +++ b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/fallback/ZuulBlockFallbackProvider.java @@ -0,0 +1,40 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * 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.alibaba.csp.sentinel.adapter.zuul.fallback; + +/** + * This interface is compatible for different spring cloud version. + * + * @author tiger + */ +public interface ZuulBlockFallbackProvider { + + /** + * The route this fallback will be used for. + * @return The route the fallback will be used for. + */ + String getRoute(); + + /** + * Provides a fallback response based on the cause of the failed execution. + * + * @param route The route the fallback is for + * @param cause cause of the main method failure, may be null + * @return the fallback response + */ + BlockResponse fallbackResponse(String route, Throwable cause); +} diff --git a/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/filters/AbstractSentinelFilter.java b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/filters/AbstractSentinelFilter.java new file mode 100644 index 0000000000..0becdf53d3 --- /dev/null +++ b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/filters/AbstractSentinelFilter.java @@ -0,0 +1,46 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * 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.alibaba.csp.sentinel.adapter.zuul.filters; + +import com.alibaba.csp.sentinel.adapter.zuul.properties.SentinelZuulProperties; +import com.alibaba.csp.sentinel.util.AssertUtil; +import com.netflix.zuul.ZuulFilter; + +/** + * Abstract class for sentinel filters. + * + * @author tiger + */ +public abstract class AbstractSentinelFilter extends ZuulFilter { + + private final SentinelZuulProperties sentinelZuulProperties; + + public SentinelZuulProperties getSentinelZuulProperties() { + return sentinelZuulProperties; + } + + public AbstractSentinelFilter(SentinelZuulProperties sentinelZuulProperties) { + AssertUtil.notNull(sentinelZuulProperties,"SentinelZuulProperties can not be null"); + this.sentinelZuulProperties = sentinelZuulProperties; + } + + @Override + public boolean shouldFilter() { + return sentinelZuulProperties.isEnabled(); + } + +} diff --git a/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/filters/SentinelErrorFilter.java b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/filters/SentinelErrorFilter.java new file mode 100644 index 0000000000..dc192dba5a --- /dev/null +++ b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/filters/SentinelErrorFilter.java @@ -0,0 +1,81 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * 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.alibaba.csp.sentinel.adapter.zuul.filters; + +import com.alibaba.csp.sentinel.Tracer; +import com.alibaba.csp.sentinel.adapter.zuul.properties.SentinelZuulProperties; +import com.alibaba.csp.sentinel.context.ContextUtil; +import com.alibaba.csp.sentinel.log.RecordLog; +import com.alibaba.csp.sentinel.slots.block.BlockException; +import com.netflix.zuul.context.RequestContext; +import com.netflix.zuul.exception.ZuulException; + +import static com.alibaba.csp.sentinel.adapter.zuul.constants.ZuulConstant.ERROR_TYPE; + +/** + * This filter track routing exception and exit entry; + * + * @author tiger + */ +public class SentinelErrorFilter extends AbstractSentinelFilter { + + public SentinelErrorFilter(SentinelZuulProperties sentinelZuulProperties) { + super(sentinelZuulProperties); + } + + @Override + public String filterType() { + return ERROR_TYPE; + } + + @Override + public boolean shouldFilter() { + RequestContext ctx = RequestContext.getCurrentContext(); + return getSentinelZuulProperties().isEnabled() && ctx.getThrowable() != null; + } + + @Override + public int filterOrder() { + return getSentinelZuulProperties().getOrder().getError(); + } + + /** + * Trace not {@link BlockException} ex. + * While loop will exit all entries, + * Case serviceId and URL entry twice in {@link SentinelPreFilter}. + * The ContextUtil.getContext().getCurEntry() will exit from inner to outer. + */ + @Override + public Object run() throws ZuulException { + try { + RequestContext ctx = RequestContext.getCurrentContext(); + Throwable throwable = ctx.getThrowable(); + if (throwable != null) { + if (!BlockException.isBlockException(throwable)) { + Tracer.trace(throwable.getCause()); + RecordLog.info("[Sentinel Error Filter] Trace cause", throwable.getCause()); + } + } + } finally { + while (ContextUtil.getContext() != null && ContextUtil.getContext().getCurEntry() != null) { + ContextUtil.getContext().getCurEntry().exit(); + } + ContextUtil.exit(); + } + return null; + } +} diff --git a/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/filters/SentinelPostFilter.java b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/filters/SentinelPostFilter.java new file mode 100644 index 0000000000..9159489c1c --- /dev/null +++ b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/filters/SentinelPostFilter.java @@ -0,0 +1,60 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * 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.alibaba.csp.sentinel.adapter.zuul.filters; + +import com.alibaba.csp.sentinel.adapter.zuul.properties.SentinelZuulProperties; +import com.alibaba.csp.sentinel.context.ContextUtil; +import com.alibaba.csp.sentinel.log.RecordLog; +import com.netflix.zuul.exception.ZuulException; + +import static com.alibaba.csp.sentinel.adapter.zuul.constants.ZuulConstant.POST_TYPE; + +/** + * This filter do success routing RT statistic and exit {@link com.alibaba.csp.sentinel.Entry} + * + * @author tiger + */ +public class SentinelPostFilter extends AbstractSentinelFilter { + + public SentinelPostFilter(SentinelZuulProperties sentinelZuulProperties) { + super(sentinelZuulProperties); + } + + @Override + public String filterType() { + return POST_TYPE; + } + + @Override + public int filterOrder() { + return getSentinelZuulProperties().getOrder().getPost(); + } + + /** + * While loop will exit all entries, + * Case serviceId and URL entry twice in {@link SentinelPreFilter}. + * The ContextUtil.getContext().getCurEntry() will exit from inner to outer. + */ + @Override + public Object run() throws ZuulException { + while (ContextUtil.getContext() != null && ContextUtil.getContext().getCurEntry() != null) { + ContextUtil.getContext().getCurEntry().exit(); + } + ContextUtil.exit(); + return null; + } +} diff --git a/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/filters/SentinelPreFilter.java b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/filters/SentinelPreFilter.java new file mode 100644 index 0000000000..7ef2c787a2 --- /dev/null +++ b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/filters/SentinelPreFilter.java @@ -0,0 +1,112 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * 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.alibaba.csp.sentinel.adapter.zuul.filters; + +import com.alibaba.csp.sentinel.EntryType; +import com.alibaba.csp.sentinel.SphU; +import com.alibaba.csp.sentinel.adapter.zuul.fallback.*; +import com.alibaba.csp.sentinel.adapter.zuul.properties.SentinelZuulProperties; +import com.alibaba.csp.sentinel.adapter.zuul.util.FilterUtil; +import com.alibaba.csp.sentinel.context.ContextUtil; +import com.alibaba.csp.sentinel.log.RecordLog; +import com.alibaba.csp.sentinel.slots.block.BlockException; +import com.alibaba.csp.sentinel.util.AssertUtil; +import com.alibaba.csp.sentinel.util.StringUtil; +import com.netflix.zuul.context.RequestContext; +import com.netflix.zuul.exception.ZuulException; + +import javax.servlet.http.HttpServletRequest; + +import static com.alibaba.csp.sentinel.adapter.zuul.constants.ZuulConstant.PRE_TYPE; +import static com.alibaba.csp.sentinel.adapter.zuul.constants.ZuulConstant.SERVICE_ID_KEY; +import static com.alibaba.csp.sentinel.adapter.zuul.constants.ZuulConstant.ZUUL_DEFAULT_CONTEXT; + +/** + * This pre filter get an entry of resource,the first order is ServiceId, then API Path. + * When get a BlockException run fallback logic. + * + * @author tiger + */ +public class SentinelPreFilter extends AbstractSentinelFilter { + + private final UrlCleaner urlCleaner; + + private final RequestOriginParser requestOriginParser; + + public SentinelPreFilter(SentinelZuulProperties sentinelZuulProperties, + UrlCleaner urlCleaner, + RequestOriginParser requestOriginParser) { + super(sentinelZuulProperties); + AssertUtil.notNull(urlCleaner, "UrlCleaner can not be null"); + AssertUtil.notNull(requestOriginParser, "RequestOriginParser can not be null"); + this.urlCleaner = urlCleaner; + this.requestOriginParser = requestOriginParser; + } + + @Override + public String filterType() { + return PRE_TYPE; + } + + /** + * This run before route filter so we can get more accurate RT time. + */ + @Override + public int filterOrder() { + return getSentinelZuulProperties().getOrder().getPre(); + } + + @Override + public Object run() throws ZuulException { + RequestContext ctx = RequestContext.getCurrentContext(); + String origin = parseOrigin(ctx.getRequest()); + String serviceTarget = (String) ctx.get(SERVICE_ID_KEY); + // When serviceId blocked first get the service level fallback provider. + String fallBackRoute = serviceTarget; + try { + if (StringUtil.isNotEmpty(serviceTarget)) { + RecordLog.info(String.format("[Sentinel Pre Filter] Origin: %s enter ServiceId: %s", origin, serviceTarget)); + ContextUtil.enter(serviceTarget, origin); + SphU.entry(serviceTarget, EntryType.IN); + } else { + RecordLog.info("[Sentinel Pre Filter] ServiceId is empty"); + ContextUtil.enter(ZUUL_DEFAULT_CONTEXT, origin); + } + String uriTarget = FilterUtil.filterTarget(ctx.getRequest()); + // Clean and unify the URL. + // For REST APIs, you have to clean the URL (e.g. `/foo/1` and `/foo/2` -> `/foo/:id`), or + // the amount of context and resources will exceed the threshold. + uriTarget = urlCleaner.clean(uriTarget); + fallBackRoute = uriTarget; + RecordLog.info(String.format("[Sentinel Pre Filter] Origin: %s enter Uri Path: %s", origin, uriTarget)); + SphU.entry(uriTarget, EntryType.IN); + } catch (BlockException ex) { + RecordLog.warn(String.format("[Sentinel Pre Filter] Block Exception when Origin: %s enter fall back route: %s", origin, fallBackRoute), ex); + ZuulBlockFallbackProvider zuulBlockFallbackProvider = ZuulBlockFallbackManager.getFallbackProvider(fallBackRoute); + BlockResponse blockResponse = zuulBlockFallbackProvider.fallbackResponse(fallBackRoute, ex); + // prevent routing from running + ctx.setRouteHost(null); + ctx.set(SERVICE_ID_KEY, null); + ctx.setResponseBody(blockResponse.toString()); + } + return null; + } + + private String parseOrigin(HttpServletRequest request) { + return requestOriginParser.parseOrigin(request); + } +} diff --git a/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/properties/SentinelZuulProperties.java b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/properties/SentinelZuulProperties.java new file mode 100644 index 0000000000..8e7681ed14 --- /dev/null +++ b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/properties/SentinelZuulProperties.java @@ -0,0 +1,80 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * 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.alibaba.csp.sentinel.adapter.zuul.properties; + +import static com.alibaba.csp.sentinel.adapter.zuul.constants.ZuulConstant.SEND_RESPONSE_FILTER_ORDER; + +/** + * Sentinel Spring Cloud Zuul AutoConfiguration property. + * + * @author tiger + */ +public class SentinelZuulProperties { + + private boolean enabled = false; + + private Order order = new Order(); + + public static class Order { + + private int post = SEND_RESPONSE_FILTER_ORDER - 10; + + private int pre = 10000; + + private int error = -1; + + public int getPost() { + return post; + } + + public void setPost(int post) { + this.post = post; + } + + public int getPre() { + return pre; + } + + public void setPre(int pre) { + this.pre = pre; + } + + public int getError() { + return error; + } + + public void setError(int error) { + this.error = error; + } + } + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + public Order getOrder() { + return order; + } + + public void setOrder(Order order) { + this.order = order; + } +} diff --git a/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/util/FilterUtil.java b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/util/FilterUtil.java new file mode 100755 index 0000000000..cc00cceea8 --- /dev/null +++ b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/zuul/util/FilterUtil.java @@ -0,0 +1,157 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * 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.alibaba.csp.sentinel.adapter.zuul.util; + +import com.alibaba.csp.sentinel.util.StringUtil; + +import javax.servlet.http.HttpServletRequest; + +/** + * Util class for web servlet filter. + * This is same as servlet adapter util class + * + * @author tiger + */ +public final class FilterUtil { + + public static String filterTarget(HttpServletRequest request) { + String pathInfo = getResourcePath(request); + if (!pathInfo.startsWith("/")) { + pathInfo = "/" + pathInfo; + } + + if ("/".equals(pathInfo)) { + return pathInfo; + } + + // Note: pathInfo should be converted to camelCase style. + int lastSlashIndex = pathInfo.lastIndexOf("/"); + + if (lastSlashIndex >= 0) { + pathInfo = pathInfo.substring(0, lastSlashIndex) + "/" + + StringUtil.trim(pathInfo.substring(lastSlashIndex + 1)); + } else { + pathInfo = "/" + StringUtil.trim(pathInfo); + } + + return pathInfo; + } + + private static String getResourcePath(HttpServletRequest request) { + String pathInfo = normalizeAbsolutePath(request.getPathInfo(), false); + String servletPath = normalizeAbsolutePath(request.getServletPath(), pathInfo.length() != 0); + + return servletPath + pathInfo; + } + + private static String normalizeAbsolutePath(String path, boolean removeTrailingSlash) throws IllegalStateException { + return normalizePath(path, true, false, removeTrailingSlash); + } + + private static String normalizePath(String path, boolean forceAbsolute, boolean forceRelative, + boolean removeTrailingSlash) throws IllegalStateException { + char[] pathChars = StringUtil.trimToEmpty(path).toCharArray(); + int length = pathChars.length; + + // Check path and slash. + boolean startsWithSlash = false; + boolean endsWithSlash = false; + + if (length > 0) { + char firstChar = pathChars[0]; + char lastChar = pathChars[length - 1]; + + startsWithSlash = firstChar == '/' || firstChar == '\\'; + endsWithSlash = lastChar == '/' || lastChar == '\\'; + } + + StringBuilder buf = new StringBuilder(length); + boolean isAbsolutePath = forceAbsolute || !forceRelative && startsWithSlash; + int index = startsWithSlash ? 0 : -1; + int level = 0; + + if (isAbsolutePath) { + buf.append("/"); + } + + while (index < length) { + index = indexOfSlash(pathChars, index + 1, false); + + if (index == length) { + break; + } + + int nextSlashIndex = indexOfSlash(pathChars, index, true); + + String element = new String(pathChars, index, nextSlashIndex - index); + index = nextSlashIndex; + + // Ignore "." + if (".".equals(element)) { + continue; + } + + // Backtrack ".." + if ("..".equals(element)) { + if (level == 0) { + if (isAbsolutePath) { + throw new IllegalStateException(path); + } else { + buf.append("../"); + } + } else { + buf.setLength(pathChars[--level]); + } + + continue; + } + + pathChars[level++] = (char)buf.length(); + buf.append(element).append('/'); + } + + // remove the last "/" + if (buf.length() > 0) { + if (!endsWithSlash || removeTrailingSlash) { + buf.setLength(buf.length() - 1); + } + } + + return buf.toString(); + } + + private static int indexOfSlash(char[] chars, int beginIndex, boolean slash) { + int i = beginIndex; + + for (; i < chars.length; i++) { + char ch = chars[i]; + + if (slash) { + if (ch == '/' || ch == '\\') { + break; // if a slash + } + } else { + if (ch != '/' && ch != '\\') { + break; // if not a slash + } + } + } + + return i; + } + + private FilterUtil() {} +} diff --git a/sentinel-adapter/sentinel-zuul-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/zuul/fallback/ZuulBlockFallbackManagerTest.java b/sentinel-adapter/sentinel-zuul-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/zuul/fallback/ZuulBlockFallbackManagerTest.java new file mode 100644 index 0000000000..81425be222 --- /dev/null +++ b/sentinel-adapter/sentinel-zuul-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/zuul/fallback/ZuulBlockFallbackManagerTest.java @@ -0,0 +1,62 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * 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.alibaba.csp.sentinel.adapter.zuul.fallback; + +import com.alibaba.csp.sentinel.slots.block.flow.FlowException; +import org.junit.Assert; +import org.junit.Test; + + +/** + * @author tiger + */ +public class ZuulBlockFallbackManagerTest { + + private String ROUTE = "/test"; + + private String DEFAULT_ROUTE = "*"; + + class MyNullResponseFallBackProvider implements ZuulBlockFallbackProvider { + @Override + public String getRoute() { + return ROUTE; + } + + @Override + public BlockResponse fallbackResponse(String route, Throwable cause) { + return null; + } + } + + @Test + public void testRegisterProvider() throws Exception { + MyNullResponseFallBackProvider myNullResponseFallBackProvider = new MyNullResponseFallBackProvider(); + ZuulBlockFallbackManager.registerProvider(myNullResponseFallBackProvider); + Assert.assertEquals(myNullResponseFallBackProvider.getRoute(), ROUTE); + Assert.assertNull(myNullResponseFallBackProvider.fallbackResponse(ROUTE, new FlowException("flow ex"))); + } + + @Test + public void clear() { + MyNullResponseFallBackProvider myNullResponseFallBackProvider = new MyNullResponseFallBackProvider(); + ZuulBlockFallbackManager.registerProvider(myNullResponseFallBackProvider); + Assert.assertEquals(myNullResponseFallBackProvider.getRoute(), ROUTE); + ZuulBlockFallbackManager.clear(); + Assert.assertEquals(ZuulBlockFallbackManager.getFallbackProvider(ROUTE).getRoute(),DEFAULT_ROUTE); + } + +} \ No newline at end of file diff --git a/sentinel-adapter/sentinel-zuul-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/zuul/fallback/ZuulBlockFallbackProviderTest.java b/sentinel-adapter/sentinel-zuul-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/zuul/fallback/ZuulBlockFallbackProviderTest.java new file mode 100644 index 0000000000..f701d4a9da --- /dev/null +++ b/sentinel-adapter/sentinel-zuul-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/zuul/fallback/ZuulBlockFallbackProviderTest.java @@ -0,0 +1,61 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * 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.alibaba.csp.sentinel.adapter.zuul.fallback; + +import com.alibaba.csp.sentinel.slots.block.flow.FlowException; +import org.junit.Assert; +import org.junit.Test; + +/** + * @author tiger + */ +public class ZuulBlockFallbackProviderTest { + + private String ALL_ROUTE = "*"; + + @Test + public void testGetNullRoute() throws Exception { + ZuulBlockFallbackProvider fallbackProvider = ZuulBlockFallbackManager.getFallbackProvider(null); + Assert.assertEquals(fallbackProvider.getRoute(), ALL_ROUTE); + } + + @Test + public void testGetDefaultRoute() throws Exception { + ZuulBlockFallbackProvider fallbackProvider = ZuulBlockFallbackManager.getFallbackProvider(ALL_ROUTE); + Assert.assertEquals(fallbackProvider.getRoute(), ALL_ROUTE); + } + + @Test + public void testGetNotInCacheRoute() throws Exception { + ZuulBlockFallbackProvider fallbackProvider = ZuulBlockFallbackManager.getFallbackProvider("/not/in"); + Assert.assertEquals(fallbackProvider.getRoute(), ALL_ROUTE); + } + + @Test + public void testFlowControlFallbackResponse() throws Exception { + ZuulBlockFallbackProvider fallbackProvider = ZuulBlockFallbackManager.getFallbackProvider(ALL_ROUTE); + BlockResponse clientHttpResponse = fallbackProvider.fallbackResponse(ALL_ROUTE, new FlowException("flow exception")); + Assert.assertEquals(clientHttpResponse.getCode(), 429); + } + + @Test + public void testRuntimeExceptionFallbackResponse() throws Exception { + ZuulBlockFallbackProvider fallbackProvider = ZuulBlockFallbackManager.getFallbackProvider(ALL_ROUTE); + BlockResponse clientHttpResponse = fallbackProvider.fallbackResponse(ALL_ROUTE, new RuntimeException()); + Assert.assertEquals(clientHttpResponse.getCode(), 500); + } +} \ No newline at end of file diff --git a/sentinel-adapter/sentinel-zuul-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/zuul/filters/SentinelErrorFilterTest.java b/sentinel-adapter/sentinel-zuul-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/zuul/filters/SentinelErrorFilterTest.java new file mode 100644 index 0000000000..8f2bca89e7 --- /dev/null +++ b/sentinel-adapter/sentinel-zuul-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/zuul/filters/SentinelErrorFilterTest.java @@ -0,0 +1,56 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * 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.alibaba.csp.sentinel.adapter.zuul.filters; + +import com.alibaba.csp.sentinel.adapter.zuul.properties.SentinelZuulProperties; +import com.netflix.zuul.context.RequestContext; +import org.junit.Assert; +import org.junit.Test; + +import static com.alibaba.csp.sentinel.adapter.zuul.constants.ZuulConstant.ERROR_TYPE; + +/** + * @author tiger + */ +public class SentinelErrorFilterTest { + @Test + public void testFilterType() throws Exception { + SentinelZuulProperties properties = new SentinelZuulProperties(); + SentinelErrorFilter sentinelErrorFilter = new SentinelErrorFilter(properties); + Assert.assertEquals(sentinelErrorFilter.filterType(), ERROR_TYPE); + } + + @Test + public void testShouldFilter() { + SentinelZuulProperties properties = new SentinelZuulProperties(); + Assert.assertFalse(properties.isEnabled()); + properties.setEnabled(true); + SentinelErrorFilter sentinelErrorFilter = new SentinelErrorFilter(properties); + RequestContext ctx = RequestContext.getCurrentContext(); + ctx.setThrowable(new RuntimeException()); + Assert.assertTrue(sentinelErrorFilter.shouldFilter()); + } + + @Test + public void testRun() throws Exception { + SentinelZuulProperties properties = new SentinelZuulProperties(); + SentinelErrorFilter sentinelErrorFilter = new SentinelErrorFilter(properties); + Object result = sentinelErrorFilter.run(); + Assert.assertNull(result); + } + +} \ No newline at end of file diff --git a/sentinel-adapter/sentinel-zuul-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/zuul/filters/SentinelPostFilterTest.java b/sentinel-adapter/sentinel-zuul-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/zuul/filters/SentinelPostFilterTest.java new file mode 100644 index 0000000000..6ccd6cae20 --- /dev/null +++ b/sentinel-adapter/sentinel-zuul-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/zuul/filters/SentinelPostFilterTest.java @@ -0,0 +1,45 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * 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.alibaba.csp.sentinel.adapter.zuul.filters; + +import com.alibaba.csp.sentinel.adapter.zuul.properties.SentinelZuulProperties; +import org.junit.Assert; +import org.junit.Test; + +import static com.alibaba.csp.sentinel.adapter.zuul.constants.ZuulConstant.POST_TYPE; + +/** + * @author tiger + */ +public class SentinelPostFilterTest { + + @Test + public void testFilterType() throws Exception { + SentinelZuulProperties properties = new SentinelZuulProperties(); + SentinelPostFilter sentinelPostFilter = new SentinelPostFilter(properties); + Assert.assertEquals(sentinelPostFilter.filterType(), POST_TYPE); + } + + @Test + public void testRun() throws Exception { + SentinelZuulProperties properties = new SentinelZuulProperties(); + SentinelPostFilter sentinelPostFilter = new SentinelPostFilter(properties); + Object result = sentinelPostFilter.run(); + Assert.assertNull(result); + } + +} \ No newline at end of file diff --git a/sentinel-adapter/sentinel-zuul-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/zuul/filters/SentinelPreFilterTest.java b/sentinel-adapter/sentinel-zuul-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/zuul/filters/SentinelPreFilterTest.java new file mode 100644 index 0000000000..ab71e5cfd7 --- /dev/null +++ b/sentinel-adapter/sentinel-zuul-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/zuul/filters/SentinelPreFilterTest.java @@ -0,0 +1,106 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * 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.alibaba.csp.sentinel.adapter.zuul.filters; + +import com.alibaba.csp.sentinel.adapter.zuul.fallback.DefaultRequestOriginParser; +import com.alibaba.csp.sentinel.adapter.zuul.fallback.RequestOriginParser; +import com.alibaba.csp.sentinel.adapter.zuul.fallback.UrlCleaner; +import com.alibaba.csp.sentinel.adapter.zuul.properties.SentinelZuulProperties; +import com.alibaba.csp.sentinel.slots.block.flow.FlowException; +import com.netflix.zuul.context.RequestContext; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; + +import javax.servlet.http.HttpServletRequest; + +import static com.alibaba.csp.sentinel.adapter.zuul.constants.ZuulConstant.PRE_TYPE; +import static com.alibaba.csp.sentinel.adapter.zuul.constants.ZuulConstant.SERVICE_ID_KEY; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.when; + +/** + * @author tiger + */ +public class SentinelPreFilterTest { + + private String SERVICE_ID = "servicea"; + + private String URI = "/servicea/test"; + + @Mock + private HttpServletRequest httpServletRequest; + + @Mock + private UrlCleaner urlCleaner; + + private final RequestOriginParser requestOriginParser = new DefaultRequestOriginParser(); + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + when(httpServletRequest.getContextPath()).thenReturn(""); + when(httpServletRequest.getPathInfo()).thenReturn(URI); + RequestContext requestContext = new RequestContext(); + requestContext.set(SERVICE_ID_KEY, SERVICE_ID); + requestContext.setRequest(httpServletRequest); + RequestContext.testSetCurrentContext(requestContext); + } + + @Test + public void testFilterType() throws Exception { + SentinelZuulProperties properties = new SentinelZuulProperties(); + SentinelPreFilter sentinelPreFilter = new SentinelPreFilter(properties, urlCleaner, requestOriginParser); + Assert.assertEquals(sentinelPreFilter.filterType(), PRE_TYPE); + } + + @Test + public void testRun() throws Exception { + RequestContext ctx = RequestContext.getCurrentContext(); + SentinelZuulProperties properties = new SentinelZuulProperties(); + SentinelPreFilter sentinelPreFilter = new SentinelPreFilter(properties, urlCleaner, requestOriginParser); + given(urlCleaner.clean(URI)).willReturn(URI); + sentinelPreFilter.run(); + Assert.assertNull(ctx.getRouteHost()); + Assert.assertEquals(ctx.get(SERVICE_ID_KEY), SERVICE_ID); + } + + @Test + public void testServiceFallBackRun() throws Exception { + RequestContext ctx = RequestContext.getCurrentContext(); + SentinelZuulProperties properties = new SentinelZuulProperties(); + properties.setEnabled(true); + SentinelPreFilter sentinelPreFilter = new SentinelPreFilter(properties, urlCleaner, requestOriginParser); + + given(urlCleaner.clean(URI)).willAnswer( + new Answer() { + @Override + public Object answer(InvocationOnMock invocation) throws Throwable { + throw new FlowException("flow ex"); + } + } + ); + sentinelPreFilter.run(); + Assert.assertNull(ctx.getRouteHost()); + Assert.assertNull(ctx.get(SERVICE_ID_KEY)); + } + +} \ No newline at end of file From 95ca72cbf556316c84e067e5e59abae140f34e96 Mon Sep 17 00:00:00 2001 From: Eric Zhao Date: Mon, 14 Jan 2019 14:08:42 +0800 Subject: [PATCH 08/39] Update document and pom for sentinel-zuul-adapter Signed-off-by: Eric Zhao --- .../sentinel-zuul-adapter/README.md | 88 ++++++++----------- .../sentinel-zuul-adapter/pom.xml | 13 +-- 2 files changed, 43 insertions(+), 58 deletions(-) diff --git a/sentinel-adapter/sentinel-zuul-adapter/README.md b/sentinel-adapter/sentinel-zuul-adapter/README.md index dde1c4ebcb..f86b440674 100755 --- a/sentinel-adapter/sentinel-zuul-adapter/README.md +++ b/sentinel-adapter/sentinel-zuul-adapter/README.md @@ -1,23 +1,19 @@ # Sentinel Zuul Adapter -Zuul does not provide rateLimit function, If use default `SentinelRibbonFilter` route filter. it wrapped by Hystrix Command. so only provide Service level -circuit protect. +Sentinel Zuul Adapter provides **ServiceId level** and **API Path level** flow control for Zuul gateway service. -Sentinel can provide `ServiceId` level and `API Path` level flow control for zuul gateway service. - -*Note*: this project is for zuul 1. +> *Note*: this adapter only support Zuul 1.x. ## How to use -1. Add maven dependency +1. Add Maven dependency to your `pom.xml`: ```xml - - com.alibaba.csp - sentinel-zuul-adapter - x.y.z - - + + com.alibaba.csp + sentinel-zuul-adapter + x.y.z + ``` 2. Register filters @@ -25,12 +21,12 @@ Sentinel can provide `ServiceId` level and `API Path` level flow control for zuu ```java // get registry final FilterRegistry r = FilterRegistry.instance(); -// this is property config. set filter ennable +// this is property config. set filter enable SentinelZuulProperties properties = new SentinelZuulProperties(); properties.setEnabled(true); -// set url cleaner, here use default +// set url cleaner, here use default DefaultUrlCleaner defaultUrlCleaner = new DefaultUrlCleaner(); -// set origin parser. here use default +// set origin parser. here use default DefaultRequestOriginParser defaultRequestOriginParser = new DefaultRequestOriginParser(); // register filters. you must register all three filters. @@ -44,22 +40,19 @@ r.put("sentinelErrorFilter", errorFilter); ## How it works -As Zuul run as per thread per connection block model, we add filters around `route Filter` to trace sentinel statistics. - -- `SentinelPreFilter`: Get an entry of resource,the first order is **ServiceId**(the key in RequestContext is `serviceId`, this can set in own custom filter), then **API Path**. -- `SentinelPostFilter`: When success response,exit entry. -- `SentinelPreFilter`: When get an `Exception`, trace the exception and exit context. - - -the order of Filter can be changed in property: +As Zuul run as per thread per connection block model, we add filters around `route Filter` to trace sentinel statistics. +- `SentinelPreFilter`: Get an entry of resource, the first order is **ServiceId** (the key in RequestContext is `serviceId`, this can set in own custom filter), then **API Path**. +- `SentinelPostFilter`: When success response, exit entry. +- `SentinelPreFilter`: When an `Exception` caught, trace the exception and exit context. + -Filters create structure like: +The order of filters can be changed in property. +The invocation chain resembles this: ```bash - EntranceNode: machine-root(t:3 pq:0 bq:0 tq:0 rt:0 prq:0 1mp:0 1mb:0 1mt:0) -EntranceNode: coke(t:2 pq:0 bq:0 tq:0 rt:0 prq:0 1mp:0 1mb:0 1mt:0) --coke(t:2 pq:0 bq:0 tq:0 rt:0 prq:0 1mp:0 1mb:0 1mt:0) @@ -68,38 +61,33 @@ EntranceNode: machine-root(t:3 pq:0 bq:0 tq:0 rt:0 prq:0 1mp:0 1mb:0 1mt:0) -EntranceNode: book(t:1 pq:0 bq:0 tq:0 rt:0 prq:0 1mp:0 1mb:0 1mt:0) --book(t:1 pq:0 bq:0 tq:0 rt:0 prq:0 1mp:0 1mb:0 1mt:0) ---/book/coke(t:0 pq:0 bq:0 tq:0 rt:0 prq:0 1mp:0 1mb:0 1mt:0) - ``` -`book` and `coke` are serviceId. - -`---/book/coke` is api path, the real uri is `/coke`. - +- `book` and `coke` are serviceId. +- `/book/coke` is api path, the real API path is `/coke`. -## Integration with Sentinel DashBord +## Integration with Sentinel Dashboard -1. Start [Sentinel DashBord](https://github.com/alibaba/Sentinel/wiki/%E6%8E%A7%E5%88%B6%E5%8F%B0). - -2. Sentinel has full rule config features. see [Dynamic-Rule-Configuration](https://github.com/alibaba/Sentinel/wiki/Dynamic-Rule-Configuration) +1. Start [Sentinel Dashboard](https://github.com/alibaba/Sentinel/wiki/Dashboard). +2. You can configure the rules in Sentinel dashboard or via dynamic rule configuration. ## Fallbacks -Implements `SentinelFallbackProvider` to define your own Fallback Provider when Sentinel Block Exception throwing. the default -Fallback Provider is `DefaultBlockFallbackProvider`. +You can implement `SentinelFallbackProvider` to define your own fallback provider when Sentinel `BlockException` is thrown. +The default fallback provider is `DefaultBlockFallbackProvider`. -By default Fallback route is `ServiveId + URI PATH`, example `/book/coke`, first `book` is serviceId, `/coke` is URI PATH. so that both -can be needed. +By default fallback route is `ServiveId + URI PATH`, example `/book/coke`, first `book` is serviceId, `/coke` is URI PATH, so that both can be needed. Here is an example: ```java -// custom provider +// custom provider public class MyBlockFallbackProvider implements ZuulBlockFallbackProvider { private Logger logger = LoggerFactory.getLogger(DefaultBlockFallbackProvider.class); - - // you can define root as service level + + // you can define root as service level @Override public String getRoute() { return "/coke/coke"; @@ -115,16 +103,14 @@ public class MyBlockFallbackProvider implements ZuulBlockFallbackProvider { } } } - + // register fallback ZuulBlockFallbackManager.registerProvider(new MyBlockFallbackProvider()); - ``` -Default block response +Default block response: ```json - { "code":429, "message":"Sentinel block exception", @@ -132,17 +118,15 @@ Default block response } ``` -## Origin parser +## Request origin parser -自定义解析URL +You can register customized request origin parser like this: ```java - -public class DefaultRequestOriginParser implements RequestOriginParser { +public class MyRequestOriginParser implements RequestOriginParser { @Override public String parseOrigin(HttpServletRequest request) { - return ""; + return request.getRemoteAddr(); } } - -``` +``` \ No newline at end of file diff --git a/sentinel-adapter/sentinel-zuul-adapter/pom.xml b/sentinel-adapter/sentinel-zuul-adapter/pom.xml index bf2c237368..3894bbae88 100755 --- a/sentinel-adapter/sentinel-zuul-adapter/pom.xml +++ b/sentinel-adapter/sentinel-zuul-adapter/pom.xml @@ -21,12 +21,19 @@ com.alibaba.csp sentinel-core + + javax.servlet + javax.servlet-api + ${servlet.api.version} + provided + com.netflix.zuul zuul-core ${zuul.version} provided + junit junit @@ -37,12 +44,6 @@ mockito-core test - - javax.servlet - javax.servlet-api - ${servlet.api.version} - provided - \ No newline at end of file From cca58497c44c822d7ebc014e1535aee47ec43a32 Mon Sep 17 00:00:00 2001 From: Eric Zhao Date: Mon, 14 Jan 2019 14:16:58 +0800 Subject: [PATCH 09/39] Update cluster demo README and remove unused demo Signed-off-by: Eric Zhao --- .../sentinel-demo-cluster-embedded/README.md | 6 ++ .../demo/cluster/ClusterClientDemo.java | 62 ------------------- 2 files changed, 6 insertions(+), 62 deletions(-) create mode 100644 sentinel-demo/sentinel-demo-cluster/sentinel-demo-cluster-embedded/README.md delete mode 100644 sentinel-demo/sentinel-demo-cluster/sentinel-demo-cluster-embedded/src/main/java/com/alibaba/csp/sentinel/demo/cluster/ClusterClientDemo.java diff --git a/sentinel-demo/sentinel-demo-cluster/sentinel-demo-cluster-embedded/README.md b/sentinel-demo/sentinel-demo-cluster/sentinel-demo-cluster-embedded/README.md new file mode 100644 index 0000000000..95d93c0773 --- /dev/null +++ b/sentinel-demo/sentinel-demo-cluster/sentinel-demo-cluster-embedded/README.md @@ -0,0 +1,6 @@ +# Sentinel Cluster Embedded Mode Demo + +This demo demonstrates how to configure data source for cluster rules and configuration +in **embedded mode**. You can start multiple `ClusterDemoApplication` instances and do cluster assignment in Sentinel dashboard or via dynamic data source. + +See [DemoClusterInitFunc](https://github.com/alibaba/Sentinel/blob/master/sentinel-demo/sentinel-demo-cluster/sentinel-demo-cluster-embedded/src/main/java/com/alibaba/csp/sentinel/demo/cluster/init/DemoClusterInitFunc.java) for a sample of dynamic configuration. \ No newline at end of file diff --git a/sentinel-demo/sentinel-demo-cluster/sentinel-demo-cluster-embedded/src/main/java/com/alibaba/csp/sentinel/demo/cluster/ClusterClientDemo.java b/sentinel-demo/sentinel-demo-cluster/sentinel-demo-cluster-embedded/src/main/java/com/alibaba/csp/sentinel/demo/cluster/ClusterClientDemo.java deleted file mode 100644 index cf0af2e9d2..0000000000 --- a/sentinel-demo/sentinel-demo-cluster/sentinel-demo-cluster-embedded/src/main/java/com/alibaba/csp/sentinel/demo/cluster/ClusterClientDemo.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 1999-2018 Alibaba Group Holding Ltd. - * - * 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.alibaba.csp.sentinel.demo.cluster; - -import com.alibaba.csp.sentinel.Entry; -import com.alibaba.csp.sentinel.EntryType; -import com.alibaba.csp.sentinel.SphU; -import com.alibaba.csp.sentinel.cluster.ClusterStateManager; -import com.alibaba.csp.sentinel.init.InitExecutor; -import com.alibaba.csp.sentinel.slots.block.BlockException; - -/** - *

Run this demo with the following args: -Dproject.name=appA

- *

You need a token server running already.

- * - * @author Eric Zhao - */ -public class ClusterClientDemo { - - public static void main(String[] args) { - InitExecutor.doInit(); - - // Manually schedule the cluster mode to client. - // In common, we need a scheduling system to modify the cluster mode automatically. - // Command HTTP API: http://:/setClusterMode?mode= - ClusterStateManager.setToClient(); - - String resourceName = "cluster-demo-entry"; - - // Assume we have a cluster flow rule for `demo-resource`: QPS = 5 in AVG_LOCAL mode. - for (int i = 0; i < 10; i++) { - tryEntry(resourceName); - } - } - - private static void tryEntry(String res) { - Entry entry = null; - try { - entry = SphU.entry(res, EntryType.IN, 1, "abc", "def"); - System.out.println("Passed"); - } catch (BlockException ex) { - ex.printStackTrace(); - } finally { - if (entry != null) { - entry.exit(); - } - } - } -} From 57593975f8d61e9e747b69eeebfdcbdcd1de283e Mon Sep 17 00:00:00 2001 From: kangyl <460720197@qq.com> Date: Mon, 14 Jan 2019 17:54:31 +0800 Subject: [PATCH 10/39] Remove redundant semicolon in MetricWriter (#412) --- .../java/com/alibaba/csp/sentinel/node/metric/MetricWriter.java | 1 - 1 file changed, 1 deletion(-) diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/metric/MetricWriter.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/metric/MetricWriter.java index a1ca49ff15..30fd14ee02 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/metric/MetricWriter.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/metric/MetricWriter.java @@ -346,7 +346,6 @@ private void closeAndNewFile(String fileName) throws Exception { outMetricBuf = new BufferedOutputStream(outMetric); curMetricFile = new File(fileName); String idxFile = formIndexFileName(fileName); - ; curMetricIndexFile = new File(idxFile); outIndex = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(idxFile, append))); RecordLog.info("[MetricWriter] New metric file created: " + fileName); From f089afd8d94713821ecd208efb2fac555b40a708 Mon Sep 17 00:00:00 2001 From: kexianjun Date: Tue, 15 Jan 2019 17:18:07 +0800 Subject: [PATCH 11/39] Fix incorrect comment in NodeSelectorSlot javadoc (#419) --- .../csp/sentinel/slots/nodeselector/NodeSelectorSlot.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/nodeselector/NodeSelectorSlot.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/nodeselector/NodeSelectorSlot.java index 7b475b89f6..aad95c8a74 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/nodeselector/NodeSelectorSlot.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/nodeselector/NodeSelectorSlot.java @@ -33,7 +33,7 @@ *
    *
  1. adding a new {@link DefaultNode} if needed as the last child in the context. * The context's last node is the current node or the parent node of the context.
  2. - *
  3. setting itself to the the context current node.
  4. + *
  5. setting itself to the context current node.
  6. *
*

* From d352f41f7827744b26b2d29519c93c92efaa195e Mon Sep 17 00:00:00 2001 From: cdfive <31885791+cdfive@users.noreply.github.com> Date: Tue, 15 Jan 2019 22:52:41 +0800 Subject: [PATCH 12/39] dashboard: when click the first-level menu of sidebar, don't jump to the home page (#422) --- .../resources/app/scripts/directives/sidebar/sidebar.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentinel-dashboard/src/main/webapp/resources/app/scripts/directives/sidebar/sidebar.html b/sentinel-dashboard/src/main/webapp/resources/app/scripts/directives/sidebar/sidebar.html index dbabfff672..f6889213e1 100755 --- a/sentinel-dashboard/src/main/webapp/resources/app/scripts/directives/sidebar/sidebar.html +++ b/sentinel-dashboard/src/main/webapp/resources/app/scripts/directives/sidebar/sidebar.html @@ -16,7 +16,7 @@
  • {{dropDown}} - +  {{entry.app}} ({{entry.heathCount}}/{{entry.machines.length}}) From aacb4d6de1db98537da53b4a2ce0218d10b5424a Mon Sep 17 00:00:00 2001 From: Carpenter Lee Date: Wed, 16 Jan 2019 15:21:16 +0800 Subject: [PATCH 13/39] Bug fix: fix 420, fix negative waitTime in RateLimiterController and WarmUpRateLimiterController Signed-off-by: Carpenter Lee --- .../block/flow/controller/RateLimiterController.java | 9 ++++++--- .../flow/controller/WarmUpRateLimiterController.java | 8 +++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/controller/RateLimiterController.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/controller/RateLimiterController.java index e17e53cf89..ab08619fad 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/controller/RateLimiterController.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/controller/RateLimiterController.java @@ -58,17 +58,20 @@ public boolean canPass(Node node, int acquireCount, boolean prioritized) { } else { // Calculate the time to wait. long waitTime = costTime + latestPassedTime.get() - TimeUtil.currentTimeMillis(); - if (waitTime >= maxQueueingTimeMs) { + if (waitTime > maxQueueingTimeMs) { return false; } else { long oldTime = latestPassedTime.addAndGet(costTime); try { waitTime = oldTime - TimeUtil.currentTimeMillis(); - if (waitTime >= maxQueueingTimeMs) { + if (waitTime > maxQueueingTimeMs) { latestPassedTime.addAndGet(-costTime); return false; } - Thread.sleep(waitTime); + // in race condition waitTime may <= 0 + if (waitTime > 0) { + Thread.sleep(waitTime); + } return true; } catch (InterruptedException e) { } diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/controller/WarmUpRateLimiterController.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/controller/WarmUpRateLimiterController.java index 7080f4c478..ca8d953b2a 100644 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/controller/WarmUpRateLimiterController.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/controller/WarmUpRateLimiterController.java @@ -68,17 +68,19 @@ public boolean canPass(Node node, int acquireCount, boolean prioritized) { return true; } else { long waitTime = costTime + latestPassedTime.get() - currentTime; - if (waitTime >= timeOutInMs) { + if (waitTime > timeOutInMs) { return false; } else { long oldTime = latestPassedTime.addAndGet(costTime); try { waitTime = oldTime - TimeUtil.currentTimeMillis(); - if (waitTime >= timeOutInMs) { + if (waitTime > timeOutInMs) { latestPassedTime.addAndGet(-costTime); return false; } - Thread.sleep(waitTime); + if (waitTime > 0) { + Thread.sleep(waitTime); + } return true; } catch (InterruptedException e) { } From dd11dc3abc34cad3a566dd2f1fe9abaa21e4a7bf Mon Sep 17 00:00:00 2001 From: Eric Zhao Date: Wed, 16 Jan 2019 16:24:01 +0800 Subject: [PATCH 14/39] Improve cluster embedded demo Signed-off-by: Eric Zhao --- .../cluster/init/DemoClusterInitFunc.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/sentinel-demo/sentinel-demo-cluster/sentinel-demo-cluster-embedded/src/main/java/com/alibaba/csp/sentinel/demo/cluster/init/DemoClusterInitFunc.java b/sentinel-demo/sentinel-demo-cluster/sentinel-demo-cluster-embedded/src/main/java/com/alibaba/csp/sentinel/demo/cluster/init/DemoClusterInitFunc.java index 59ef0cda3a..d11992909e 100644 --- a/sentinel-demo/sentinel-demo-cluster/sentinel-demo-cluster-embedded/src/main/java/com/alibaba/csp/sentinel/demo/cluster/init/DemoClusterInitFunc.java +++ b/sentinel-demo/sentinel-demo-cluster/sentinel-demo-cluster-embedded/src/main/java/com/alibaba/csp/sentinel/demo/cluster/init/DemoClusterInitFunc.java @@ -58,14 +58,19 @@ public class DemoClusterInitFunc implements InitFunc { @Override public void init() throws Exception { - // Init token client related data source. + // Register client dynamic rule data source. initDynamicRuleProperty(); + // Register token client related data source. + // Token client common config: initClientConfigProperty(); + // Token client assign config (e.g. target token server) retrieved from assign map: initClientServerAssignProperty(); - // Init token server related data source. + // Register token server related data source. + // Register dynamic rule data source supplier for token server: registerClusterRuleSupplier(); + // Token server transport config extracted from assign map: initServerTransportConfigProperty(); // Init cluster state property for extracting mode from cluster map data source. @@ -101,15 +106,16 @@ private void initServerTransportConfigProperty() { private void registerClusterRuleSupplier() { // Register cluster flow rule property supplier which creates data source by namespace. + // Flow rule dataId format: ${namespace}-flow-rules ClusterFlowRuleManager.setPropertySupplier(namespace -> { ReadableDataSource> ds = new NacosDataSource<>(remoteAddress, groupId, - flowDataId, source -> JSON.parseObject(source, new TypeReference>() {})); + namespace + DemoConstants.FLOW_POSTFIX, source -> JSON.parseObject(source, new TypeReference>() {})); return ds.getProperty(); }); // Register cluster parameter flow rule property supplier which creates data source by namespace. ClusterParamFlowRuleManager.setPropertySupplier(namespace -> { ReadableDataSource> ds = new NacosDataSource<>(remoteAddress, groupId, - paramDataId, source -> JSON.parseObject(source, new TypeReference>() {})); + namespace + DemoConstants.PARAM_FLOW_POSTFIX, source -> JSON.parseObject(source, new TypeReference>() {})); return ds.getProperty(); }); } @@ -147,6 +153,8 @@ private int extractMode(List groupList) { if (groupList.stream().anyMatch(this::machineEqual)) { return ClusterStateManager.CLUSTER_SERVER; } + // If current machine belongs to any of the token server group, then it's token client. + // Otherwise it's unassigned, should be set to NOT_STARTED. boolean canBeClient = groupList.stream() .flatMap(e -> e.getClientSet().stream()) .anyMatch(e -> e.equals(getCurrentMachineId())); @@ -180,8 +188,9 @@ private boolean machineEqual(/*@Valid*/ ClusterGroupEntity group) { } private String getCurrentMachineId() { + // Note: this may not work well for container-based env. return HostNameUtil.getIp() + SEPARATOR + TransportConfig.getRuntimePort(); } private static final String SEPARATOR = "@"; -} +} \ No newline at end of file From 9465fee68d9eb436c2904b23491d200d82cb984f Mon Sep 17 00:00:00 2001 From: wangjunwei87 <1625837+wangjunwei87@users.noreply.github.com> Date: Wed, 16 Jan 2019 18:39:52 +0800 Subject: [PATCH 15/39] doc: fix typo in README of Sentinel Dubbo Demo (#425) --- sentinel-demo/sentinel-demo-dubbo/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sentinel-demo/sentinel-demo-dubbo/README.md b/sentinel-demo/sentinel-demo-dubbo/README.md index 2a9fc3ea3d..84b3414f9c 100644 --- a/sentinel-demo/sentinel-demo-dubbo/README.md +++ b/sentinel-demo/sentinel-demo-dubbo/README.md @@ -58,11 +58,11 @@ Demo 1 演示了此限流场景,我们看一下这种模式的限流产生的 ## Service Consumer -> 对服务提供方的流量控制可分为**控制并发线程数**和**服务降级**两个维度。 +> 对服务消费方的流量控制可分为**控制并发线程数**和**服务降级**两个维度。 ### 并发线程数限流 -Service Consumer 作为客户端去调用远程服务。每一个服务都可能会依赖几个下游服务,若某个服务 A 依赖的下游服务 B 出现了不稳定的情况,服务 A 请求 服务 B 的响应时间变长,从而服务 A 调用服务 B 的线程就会产生堆积,最终可能耗尽服务 A 的线程数。我们通过用并发线程数来控制对下游服务 B 的访问,来保证下游服务不可靠的时候,不会拖垮服务自身。基于这种场景,推荐给 Consumer 配置**线程数模式**的限流,来保证自身不被不稳定服务所影响。限流粒度同样可以是服务接口和服务方法两种粒度。 +Service Consumer 作为客户端去调用远程服务。每一个服务都可能会依赖几个下游服务,若某个服务 A 依赖的下游服务 B 出现了不稳定的情况,服务 A 请求服务 B 的响应时间变长,从而服务 A 调用服务 B 的线程就会产生堆积,最终可能耗尽服务 A 的线程数。我们通过用并发线程数来控制对下游服务 B 的访问,来保证下游服务不可靠的时候,不会拖垮服务自身。基于这种场景,推荐给 Consumer 配置**线程数模式**的限流,来保证自身不被不稳定服务所影响。限流粒度同样可以是服务接口和服务方法两种粒度。 采用基于线程数的限流模式后,我们不需要再显式地去进行线程池隔离,Sentinel 会控制资源的线程数,超出的请求直接拒绝,直到堆积的线程处理完成。 From 636ba05148d6ce6813c58239a76c2edd9e5bc774 Mon Sep 17 00:00:00 2001 From: huaifeng Date: Mon, 21 Jan 2019 12:45:49 +0800 Subject: [PATCH 16/39] Upgrade Dubbo version in sentinel-demo-dubbo (#436) --- sentinel-demo/sentinel-demo-dubbo/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentinel-demo/sentinel-demo-dubbo/pom.xml b/sentinel-demo/sentinel-demo-dubbo/pom.xml index 09c1357562..d7c64c9562 100644 --- a/sentinel-demo/sentinel-demo-dubbo/pom.xml +++ b/sentinel-demo/sentinel-demo-dubbo/pom.xml @@ -20,7 +20,7 @@ com.alibaba dubbo - 2.6.2 + 2.6.5 com.alibaba.csp From 829fde2ea64fe98e455441075d6c987f55a7a894 Mon Sep 17 00:00:00 2001 From: Carpenter Lee Date: Mon, 21 Jan 2019 13:02:52 +0800 Subject: [PATCH 17/39] Rename dashboard package name from com.taobao to com.alibaba (#435) Signed-off-by: Carpenter Lee --- sentinel-dashboard/pom.xml | 2 +- .../dashboard/DashboardApplication.java | 2 +- .../client/CommandFailedException.java | 2 +- .../client/CommandNotFoundException.java | 2 +- .../dashboard/client/SentinelApiClient.java | 79 +++++++++---------- .../sentinel/dashboard/config/WebConfig.java | 2 +- .../dashboard/controller/AppController.java | 12 +-- .../controller/AuthorityRuleController.java | 12 +-- .../controller/DegradeController.java | 12 +-- .../dashboard/controller/DemoController.java | 2 +- .../controller/FlowControllerV1.java | 12 +-- .../controller/MachineRegistryController.java | 10 +-- .../controller/MetricController.java | 10 +-- .../controller/ParamFlowRuleController.java | 20 ++--- .../controller/ResourceController.java | 10 +-- .../controller/SystemController.java | 12 +-- .../cluster/ClusterAssignController.java | 12 +-- .../cluster/ClusterConfigController.java | 30 +++---- .../controller/v2/FlowControllerV2.java | 12 +-- .../datasource/entity/ApplicationEntity.java | 4 +- .../datasource/entity/MachineEntity.java | 4 +- .../datasource/entity/MetricEntity.java | 2 +- .../entity/MetricPositionEntity.java | 2 +- .../datasource/entity/SentinelVersion.java | 2 +- .../entity/rule/AbstractRuleEntity.java | 2 +- .../entity/rule/AuthorityRuleEntity.java | 2 +- .../entity/rule/DegradeRuleEntity.java | 2 +- .../entity/rule/FlowRuleEntity.java | 2 +- .../entity/rule/ParamFlowRuleEntity.java | 2 +- .../datasource/entity/rule/RuleEntity.java | 2 +- .../entity/rule/SystemRuleEntity.java | 2 +- .../sentinel/dashboard/discovery/AppInfo.java | 2 +- .../dashboard/discovery/AppManagement.java | 2 +- .../dashboard/discovery/MachineDiscovery.java | 2 +- .../dashboard/discovery/MachineInfo.java | 2 +- .../discovery/SimpleMachineDiscovery.java | 2 +- .../dashboard/domain/ResourceTreeNode.java | 2 +- .../csp/sentinel/dashboard/domain/Result.java | 2 +- .../cluster/ClusterAppAssignResultVO.java | 2 +- .../cluster/ClusterAppFullAssignRequest.java | 4 +- .../ClusterAppSingleServerAssignRequest.java | 4 +- .../domain/cluster/ClusterClientInfoVO.java | 2 +- .../domain/cluster/ClusterGroupEntity.java | 2 +- .../domain/cluster/ClusterStateSingleVO.java | 2 +- .../cluster/ConnectionDescriptorVO.java | 2 +- .../domain/cluster/ConnectionGroupVO.java | 2 +- .../cluster/config/ClusterClientConfig.java | 2 +- .../cluster/config/ServerFlowConfig.java | 2 +- .../cluster/config/ServerTransportConfig.java | 2 +- .../cluster/request/ClusterAppAssignMap.java | 2 +- .../request/ClusterClientModifyRequest.java | 4 +- .../cluster/request/ClusterModifyRequest.java | 2 +- .../request/ClusterServerModifyRequest.java | 6 +- .../state/AppClusterClientStateWrapVO.java | 2 +- .../state/AppClusterServerStateWrapVO.java | 2 +- .../cluster/state/ClusterClientStateVO.java | 4 +- .../cluster/state/ClusterRequestLimitVO.java | 2 +- .../cluster/state/ClusterServerStateVO.java | 8 +- .../state/ClusterStateSimpleEntity.java | 2 +- .../state/ClusterUniversalStatePairVO.java | 2 +- .../state/ClusterUniversalStateVO.java | 2 +- .../dashboard/domain/vo/MachineInfoVo.java | 6 +- .../dashboard/domain/vo/MetricVo.java | 4 +- .../dashboard/domain/vo/ResourceVo.java | 4 +- .../dashboard/metric/MetricFetcher.java | 12 +-- .../metric/InMemoryMetricsRepository.java | 4 +- .../repository/metric/MetricsRepository.java | 2 +- .../rule/InMemAuthorityRuleStore.java | 5 +- .../rule/InMemDegradeRuleStore.java | 5 +- .../repository/rule/InMemFlowRuleStore.java | 4 +- .../rule/InMemParamFlowRuleStore.java | 4 +- .../repository/rule/InMemSystemRuleStore.java | 5 +- .../rule/InMemoryRuleRepositoryAdapter.java | 7 +- .../repository/rule/RuleRepository.java | 4 +- .../dashboard/rule/DynamicRuleProvider.java | 2 +- .../dashboard/rule/DynamicRulePublisher.java | 2 +- .../dashboard/rule/FlowRuleApiProvider.java | 13 +-- .../dashboard/rule/FlowRuleApiPublisher.java | 12 +-- .../service/ClusterAssignService.java | 6 +- .../service/ClusterAssignServiceImpl.java | 19 +++-- .../service/ClusterConfigService.java | 32 ++++---- .../sentinel/dashboard/util/AsyncUtils.java | 2 +- .../dashboard/util/ClusterEntityUtils.java | 16 ++-- .../sentinel/dashboard/util/MachineUtils.java | 5 +- .../sentinel/dashboard/util/RuleUtils.java | 2 +- .../sentinel/dashboard/util/VersionUtils.java | 4 +- .../dashboard/discovery/AppInfoTest.java | 2 +- .../rule/nacos/FlowRuleNacosProvider.java | 6 +- .../rule/nacos/FlowRuleNacosPublisher.java | 6 +- .../dashboard/rule/nacos/NacosConfig.java | 4 +- .../dashboard/rule/nacos/NacosConfigUtil.java | 2 +- 91 files changed, 281 insertions(+), 281 deletions(-) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/DashboardApplication.java (96%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/client/CommandFailedException.java (94%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/client/CommandNotFoundException.java (94%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/client/SentinelApiClient.java (89%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/config/WebConfig.java (97%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/controller/AppController.java (87%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/controller/AuthorityRuleController.java (94%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/controller/DegradeController.java (94%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/controller/DemoController.java (98%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/controller/FlowControllerV1.java (96%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/controller/MachineRegistryController.java (89%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/controller/MetricController.java (95%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/controller/ParamFlowRuleController.java (93%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/controller/ResourceController.java (91%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/controller/SystemController.java (94%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/controller/cluster/ClusterAssignController.java (90%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/controller/cluster/ClusterConfigController.java (89%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/controller/v2/FlowControllerV2.java (95%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/datasource/entity/ApplicationEntity.java (94%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/datasource/entity/MachineEntity.java (95%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/datasource/entity/MetricEntity.java (98%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/datasource/entity/MetricPositionEntity.java (97%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/datasource/entity/SentinelVersion.java (98%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/datasource/entity/rule/AbstractRuleEntity.java (97%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/datasource/entity/rule/AuthorityRuleEntity.java (96%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/datasource/entity/rule/DegradeRuleEntity.java (98%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/datasource/entity/rule/FlowRuleEntity.java (98%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/datasource/entity/rule/ParamFlowRuleEntity.java (97%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/datasource/entity/rule/RuleEntity.java (92%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/datasource/entity/rule/SystemRuleEntity.java (97%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/discovery/AppInfo.java (97%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/discovery/AppManagement.java (97%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/discovery/MachineDiscovery.java (94%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/discovery/MachineInfo.java (98%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/discovery/SimpleMachineDiscovery.java (96%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/domain/ResourceTreeNode.java (99%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/domain/Result.java (97%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/domain/cluster/ClusterAppAssignResultVO.java (96%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/domain/cluster/ClusterAppFullAssignRequest.java (91%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/domain/cluster/ClusterAppSingleServerAssignRequest.java (91%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/domain/cluster/ClusterClientInfoVO.java (97%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/domain/cluster/ClusterGroupEntity.java (97%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/domain/cluster/ClusterStateSingleVO.java (96%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/domain/cluster/ConnectionDescriptorVO.java (95%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/domain/cluster/ConnectionGroupVO.java (96%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/domain/cluster/config/ClusterClientConfig.java (96%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/domain/cluster/config/ServerFlowConfig.java (97%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/domain/cluster/config/ServerTransportConfig.java (96%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/domain/cluster/request/ClusterAppAssignMap.java (97%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/domain/cluster/request/ClusterClientModifyRequest.java (92%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/domain/cluster/request/ClusterModifyRequest.java (92%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/domain/cluster/request/ClusterServerModifyRequest.java (92%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/domain/cluster/state/AppClusterClientStateWrapVO.java (96%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/domain/cluster/state/AppClusterServerStateWrapVO.java (97%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/domain/cluster/state/ClusterClientStateVO.java (89%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/domain/cluster/state/ClusterRequestLimitVO.java (96%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/domain/cluster/state/ClusterServerStateVO.java (90%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/domain/cluster/state/ClusterStateSimpleEntity.java (96%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/domain/cluster/state/ClusterUniversalStatePairVO.java (96%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/domain/cluster/state/ClusterUniversalStateVO.java (96%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/domain/vo/MachineInfoVo.java (93%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/domain/vo/MetricVo.java (97%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/domain/vo/ResourceVo.java (98%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/metric/MetricFetcher.java (97%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/repository/metric/InMemoryMetricsRepository.java (97%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/repository/metric/MetricsRepository.java (96%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/repository/rule/InMemAuthorityRuleStore.java (87%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/repository/rule/InMemDegradeRuleStore.java (87%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/repository/rule/InMemFlowRuleStore.java (91%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/repository/rule/InMemParamFlowRuleStore.java (91%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/repository/rule/InMemSystemRuleStore.java (87%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/repository/rule/InMemoryRuleRepositoryAdapter.java (94%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/repository/rule/RuleRepository.java (93%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/rule/DynamicRuleProvider.java (93%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/rule/DynamicRulePublisher.java (95%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/rule/FlowRuleApiProvider.java (84%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/rule/FlowRuleApiPublisher.java (81%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/service/ClusterAssignService.java (88%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/service/ClusterAssignServiceImpl.java (93%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/service/ClusterConfigService.java (86%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/util/AsyncUtils.java (97%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/util/ClusterEntityUtils.java (89%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/util/MachineUtils.java (95%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/util/RuleUtils.java (98%) rename sentinel-dashboard/src/main/java/com/{taobao => alibaba}/csp/sentinel/dashboard/util/VersionUtils.java (94%) rename sentinel-dashboard/src/test/java/com/{taobao => alibaba}/csp/sentinel/dashboard/discovery/AppInfoTest.java (96%) rename sentinel-dashboard/src/test/java/com/{taobao => alibaba}/csp/sentinel/dashboard/rule/nacos/FlowRuleNacosProvider.java (88%) rename sentinel-dashboard/src/test/java/com/{taobao => alibaba}/csp/sentinel/dashboard/rule/nacos/FlowRuleNacosPublisher.java (88%) rename sentinel-dashboard/src/test/java/com/{taobao => alibaba}/csp/sentinel/dashboard/rule/nacos/NacosConfig.java (91%) rename sentinel-dashboard/src/test/java/com/{taobao => alibaba}/csp/sentinel/dashboard/rule/nacos/NacosConfigUtil.java (96%) diff --git a/sentinel-dashboard/pom.xml b/sentinel-dashboard/pom.xml index 7d8bcdaa69..7e68b52076 100755 --- a/sentinel-dashboard/pom.xml +++ b/sentinel-dashboard/pom.xml @@ -120,7 +120,7 @@ spring-boot-maven-plugin true - com.taobao.csp.sentinel.dashboard.DashboardApplication + com.alibaba.csp.sentinel.dashboard.DashboardApplication diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/DashboardApplication.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/DashboardApplication.java similarity index 96% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/DashboardApplication.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/DashboardApplication.java index a56c0ac088..f748646262 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/DashboardApplication.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/DashboardApplication.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard; +package com.alibaba.csp.sentinel.dashboard; import com.alibaba.csp.sentinel.init.InitExecutor; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/client/CommandFailedException.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/client/CommandFailedException.java similarity index 94% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/client/CommandFailedException.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/client/CommandFailedException.java index 337c0c956a..76b6aeb104 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/client/CommandFailedException.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/client/CommandFailedException.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.client; +package com.alibaba.csp.sentinel.dashboard.client; /** * @author Eric Zhao diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/client/CommandNotFoundException.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/client/CommandNotFoundException.java similarity index 94% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/client/CommandNotFoundException.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/client/CommandNotFoundException.java index 3914a9e163..0db956807d 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/client/CommandNotFoundException.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/client/CommandNotFoundException.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.client; +package com.alibaba.csp.sentinel.dashboard.client; /** * @author Eric Zhao diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/client/SentinelApiClient.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/client/SentinelApiClient.java similarity index 89% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/client/SentinelApiClient.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/client/SentinelApiClient.java index 6a512099d4..4d5ccdab2f 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/client/SentinelApiClient.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/client/SentinelApiClient.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.client; +package com.alibaba.csp.sentinel.dashboard.client; import java.io.UnsupportedEncodingException; import java.net.URI; @@ -32,6 +32,7 @@ import com.alibaba.csp.sentinel.command.CommandConstants; import com.alibaba.csp.sentinel.config.SentinelConfig; import com.alibaba.csp.sentinel.command.vo.NodeVo; +import com.alibaba.csp.sentinel.dashboard.util.AsyncUtils; import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule; import com.alibaba.csp.sentinel.slots.block.flow.FlowRule; import com.alibaba.csp.sentinel.slots.system.SystemRule; @@ -39,18 +40,18 @@ import com.alibaba.csp.sentinel.util.StringUtil; import com.alibaba.fastjson.JSON; -import com.taobao.csp.sentinel.dashboard.datasource.entity.rule.AuthorityRuleEntity; -import com.taobao.csp.sentinel.dashboard.datasource.entity.rule.DegradeRuleEntity; -import com.taobao.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity; -import com.taobao.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity; -import com.taobao.csp.sentinel.dashboard.datasource.entity.rule.SystemRuleEntity; -import com.taobao.csp.sentinel.dashboard.domain.cluster.ClusterClientInfoVO; -import com.taobao.csp.sentinel.dashboard.domain.cluster.state.ClusterServerStateVO; -import com.taobao.csp.sentinel.dashboard.domain.cluster.state.ClusterStateSimpleEntity; -import com.taobao.csp.sentinel.dashboard.domain.cluster.config.ClusterClientConfig; -import com.taobao.csp.sentinel.dashboard.domain.cluster.config.ServerFlowConfig; -import com.taobao.csp.sentinel.dashboard.domain.cluster.config.ServerTransportConfig; -import com.taobao.csp.sentinel.dashboard.util.RuleUtils; +import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.AuthorityRuleEntity; +import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.DegradeRuleEntity; +import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity; +import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity; +import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.SystemRuleEntity; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterClientInfoVO; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterServerStateVO; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterStateSimpleEntity; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ClusterClientConfig; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerFlowConfig; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerTransportConfig; +import com.alibaba.csp.sentinel.dashboard.util.RuleUtils; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.utils.URIBuilder; @@ -65,8 +66,6 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; -import static com.taobao.csp.sentinel.dashboard.util.AsyncUtils.*; - /** * Communicate with Sentinel client. * @@ -327,7 +326,7 @@ public CompletableFuture> fetchParamFlowRulesOfMachine ); } catch (Exception e) { logger.error("Error when fetching parameter flow rules", e); - return newFailedFuture(e); + return AsyncUtils.newFailedFuture(e); } } @@ -482,7 +481,7 @@ public CompletableFuture setParamFlowRuleOfMachine(String app, String ip, return CompletableFuture.completedFuture(null); } if (StringUtil.isBlank(ip) || port <= 0) { - return newFailedFuture(new IllegalArgumentException("Invalid parameter")); + return AsyncUtils.newFailedFuture(new IllegalArgumentException("Invalid parameter")); } try { String data = JSON.toJSONString( @@ -499,12 +498,12 @@ public CompletableFuture setParamFlowRuleOfMachine(String app, String ip, return CompletableFuture.completedFuture(null); } else { logger.warn("Push parameter flow rules to client failed: " + e); - return newFailedFuture(new RuntimeException(e)); + return AsyncUtils.newFailedFuture(new RuntimeException(e)); } }); } catch (Exception ex) { logger.warn("Error when setting parameter flow rule", ex); - return newFailedFuture(ex); + return AsyncUtils.newFailedFuture(ex); } } @@ -512,7 +511,7 @@ public CompletableFuture setParamFlowRuleOfMachine(String app, String ip, public CompletableFuture fetchClusterMode(String app, String ip, int port) { if (StringUtil.isBlank(ip) || port <= 0) { - return newFailedFuture(new IllegalArgumentException("Invalid parameter")); + return AsyncUtils.newFailedFuture(new IllegalArgumentException("Invalid parameter")); } try { URIBuilder uriBuilder = new URIBuilder(); @@ -522,13 +521,13 @@ public CompletableFuture fetchClusterMode(String app, .thenApply(r -> JSON.parseObject(r, ClusterStateSimpleEntity.class)); } catch (Exception ex) { logger.warn("Error when fetching cluster mode", ex); - return newFailedFuture(ex); + return AsyncUtils.newFailedFuture(ex); } } public CompletableFuture modifyClusterMode(String app, String ip, int port, int mode) { if (StringUtil.isBlank(ip) || port <= 0) { - return newFailedFuture(new IllegalArgumentException("Invalid parameter")); + return AsyncUtils.newFailedFuture(new IllegalArgumentException("Invalid parameter")); } try { URIBuilder uriBuilder = new URIBuilder(); @@ -541,18 +540,18 @@ public CompletableFuture modifyClusterMode(String app, String ip, int port return CompletableFuture.completedFuture(null); } else { logger.warn("Error when modifying cluster mode: " + e); - return newFailedFuture(new RuntimeException(e)); + return AsyncUtils.newFailedFuture(new RuntimeException(e)); } }); } catch (Exception ex) { logger.warn("Error when modifying cluster mode", ex); - return newFailedFuture(ex); + return AsyncUtils.newFailedFuture(ex); } } public CompletableFuture fetchClusterClientInfoAndConfig(String app, String ip, int port) { if (StringUtil.isBlank(ip) || port <= 0) { - return newFailedFuture(new IllegalArgumentException("Invalid parameter")); + return AsyncUtils.newFailedFuture(new IllegalArgumentException("Invalid parameter")); } try { URIBuilder uriBuilder = new URIBuilder(); @@ -562,13 +561,13 @@ public CompletableFuture fetchClusterClientInfoAndConfig(St .thenApply(r -> JSON.parseObject(r, ClusterClientInfoVO.class)); } catch (Exception ex) { logger.warn("Error when fetching cluster client config", ex); - return newFailedFuture(ex); + return AsyncUtils.newFailedFuture(ex); } } public CompletableFuture modifyClusterClientConfig(String app, String ip, int port, ClusterClientConfig config) { if (StringUtil.isBlank(ip) || port <= 0) { - return newFailedFuture(new IllegalArgumentException("Invalid parameter")); + return AsyncUtils.newFailedFuture(new IllegalArgumentException("Invalid parameter")); } try { URIBuilder uriBuilder = new URIBuilder(); @@ -581,18 +580,18 @@ public CompletableFuture modifyClusterClientConfig(String app, String ip, return CompletableFuture.completedFuture(null); } else { logger.warn("Error when modifying cluster client config: " + e); - return newFailedFuture(new RuntimeException(e)); + return AsyncUtils.newFailedFuture(new RuntimeException(e)); } }); } catch (Exception ex) { logger.warn("Error when modifying cluster client config", ex); - return newFailedFuture(ex); + return AsyncUtils.newFailedFuture(ex); } } public CompletableFuture modifyClusterServerFlowConfig(String app, String ip, int port, ServerFlowConfig config) { if (StringUtil.isBlank(ip) || port <= 0) { - return newFailedFuture(new IllegalArgumentException("Invalid parameter")); + return AsyncUtils.newFailedFuture(new IllegalArgumentException("Invalid parameter")); } try { URIBuilder uriBuilder = new URIBuilder(); @@ -605,18 +604,18 @@ public CompletableFuture modifyClusterServerFlowConfig(String app, String return CompletableFuture.completedFuture(null); } else { logger.warn("Error when modifying cluster server flow config: " + e); - return newFailedFuture(new RuntimeException(e)); + return AsyncUtils.newFailedFuture(new RuntimeException(e)); } }); } catch (Exception ex) { logger.warn("Error when modifying cluster server flow config", ex); - return newFailedFuture(ex); + return AsyncUtils.newFailedFuture(ex); } } public CompletableFuture modifyClusterServerTransportConfig(String app, String ip, int port, ServerTransportConfig config) { if (StringUtil.isBlank(ip) || port <= 0) { - return newFailedFuture(new IllegalArgumentException("Invalid parameter")); + return AsyncUtils.newFailedFuture(new IllegalArgumentException("Invalid parameter")); } try { URIBuilder uriBuilder = new URIBuilder(); @@ -630,18 +629,18 @@ public CompletableFuture modifyClusterServerTransportConfig(String app, St return CompletableFuture.completedFuture(null); } else { logger.warn("Error when modifying cluster server transport config: " + e); - return newFailedFuture(new RuntimeException(e)); + return AsyncUtils.newFailedFuture(new RuntimeException(e)); } }); } catch (Exception ex) { logger.warn("Error when modifying cluster server transport config", ex); - return newFailedFuture(ex); + return AsyncUtils.newFailedFuture(ex); } } public CompletableFuture modifyClusterServerNamespaceSet(String app, String ip, int port, Set set) { if (StringUtil.isBlank(ip) || port <= 0) { - return newFailedFuture(new IllegalArgumentException("Invalid parameter")); + return AsyncUtils.newFailedFuture(new IllegalArgumentException("Invalid parameter")); } try { URIBuilder uriBuilder = new URIBuilder(); @@ -654,18 +653,18 @@ public CompletableFuture modifyClusterServerNamespaceSet(String app, Strin return CompletableFuture.completedFuture(null); } else { logger.warn("Error when modifying cluster server NamespaceSet: " + e); - return newFailedFuture(new RuntimeException(e)); + return AsyncUtils.newFailedFuture(new RuntimeException(e)); } }); } catch (Exception ex) { logger.warn("Error when modifying cluster server NamespaceSet", ex); - return newFailedFuture(ex); + return AsyncUtils.newFailedFuture(ex); } } public CompletableFuture fetchClusterServerBasicInfo(String app, String ip, int port) { if (StringUtil.isBlank(ip) || port <= 0) { - return newFailedFuture(new IllegalArgumentException("Invalid parameter")); + return AsyncUtils.newFailedFuture(new IllegalArgumentException("Invalid parameter")); } try { URIBuilder uriBuilder = new URIBuilder(); @@ -675,7 +674,7 @@ public CompletableFuture fetchClusterServerBasicInfo(Strin .thenApply(r -> JSON.parseObject(r, ClusterServerStateVO.class)); } catch (Exception ex) { logger.warn("Error when fetching cluster sever all config and basic info", ex); - return newFailedFuture(ex); + return AsyncUtils.newFailedFuture(ex); } } } diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/config/WebConfig.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/config/WebConfig.java similarity index 97% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/config/WebConfig.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/config/WebConfig.java index 6fa051f0a7..d507d584da 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/config/WebConfig.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/config/WebConfig.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.config; +package com.alibaba.csp.sentinel.dashboard.config; import javax.servlet.Filter; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/AppController.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/AppController.java similarity index 87% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/AppController.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/AppController.java index 25e453732c..03f6d5dd61 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/AppController.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/AppController.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.controller; +package com.alibaba.csp.sentinel.dashboard.controller; import java.util.ArrayList; import java.util.Collections; @@ -22,11 +22,11 @@ import javax.servlet.http.HttpServletRequest; -import com.taobao.csp.sentinel.dashboard.discovery.AppInfo; -import com.taobao.csp.sentinel.dashboard.discovery.AppManagement; -import com.taobao.csp.sentinel.dashboard.discovery.MachineInfo; -import com.taobao.csp.sentinel.dashboard.domain.Result; -import com.taobao.csp.sentinel.dashboard.domain.vo.MachineInfoVo; +import com.alibaba.csp.sentinel.dashboard.discovery.AppInfo; +import com.alibaba.csp.sentinel.dashboard.discovery.AppManagement; +import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo; +import com.alibaba.csp.sentinel.dashboard.domain.Result; +import com.alibaba.csp.sentinel.dashboard.domain.vo.MachineInfoVo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/AuthorityRuleController.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/AuthorityRuleController.java similarity index 94% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/AuthorityRuleController.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/AuthorityRuleController.java index 1f28e9ba47..f76ec34bcf 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/AuthorityRuleController.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/AuthorityRuleController.java @@ -13,19 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.controller; +package com.alibaba.csp.sentinel.dashboard.controller; import java.util.Date; import java.util.List; +import com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient; +import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo; import com.alibaba.csp.sentinel.slots.block.RuleConstant; import com.alibaba.csp.sentinel.util.StringUtil; -import com.taobao.csp.sentinel.dashboard.client.SentinelApiClient; -import com.taobao.csp.sentinel.dashboard.datasource.entity.rule.AuthorityRuleEntity; -import com.taobao.csp.sentinel.dashboard.discovery.MachineInfo; -import com.taobao.csp.sentinel.dashboard.domain.Result; -import com.taobao.csp.sentinel.dashboard.repository.rule.RuleRepository; +import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.AuthorityRuleEntity; +import com.alibaba.csp.sentinel.dashboard.domain.Result; +import com.alibaba.csp.sentinel.dashboard.repository.rule.RuleRepository; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/DegradeController.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/DegradeController.java similarity index 94% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/DegradeController.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/DegradeController.java index ef50d2b4f1..79818e7788 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/DegradeController.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/DegradeController.java @@ -13,19 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.controller; +package com.alibaba.csp.sentinel.dashboard.controller; import java.util.Date; import java.util.List; +import com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient; +import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo; import com.alibaba.csp.sentinel.slots.block.RuleConstant; import com.alibaba.csp.sentinel.util.StringUtil; -import com.taobao.csp.sentinel.dashboard.datasource.entity.rule.DegradeRuleEntity; -import com.taobao.csp.sentinel.dashboard.discovery.MachineInfo; -import com.taobao.csp.sentinel.dashboard.client.SentinelApiClient; -import com.taobao.csp.sentinel.dashboard.domain.Result; -import com.taobao.csp.sentinel.dashboard.repository.rule.InMemDegradeRuleStore; +import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.DegradeRuleEntity; +import com.alibaba.csp.sentinel.dashboard.domain.Result; +import com.alibaba.csp.sentinel.dashboard.repository.rule.InMemDegradeRuleStore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/DemoController.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/DemoController.java similarity index 98% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/DemoController.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/DemoController.java index a30ea440ed..91ae671225 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/DemoController.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/DemoController.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.controller; +package com.alibaba.csp.sentinel.dashboard.controller; import java.util.Random; import java.util.concurrent.TimeUnit; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/FlowControllerV1.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/FlowControllerV1.java similarity index 96% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/FlowControllerV1.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/FlowControllerV1.java index 94ac3e5589..23bdfee7c7 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/FlowControllerV1.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/FlowControllerV1.java @@ -13,18 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.controller; +package com.alibaba.csp.sentinel.dashboard.controller; import java.util.Date; import java.util.List; import com.alibaba.csp.sentinel.util.StringUtil; -import com.taobao.csp.sentinel.dashboard.client.SentinelApiClient; -import com.taobao.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity; -import com.taobao.csp.sentinel.dashboard.discovery.MachineInfo; -import com.taobao.csp.sentinel.dashboard.domain.Result; -import com.taobao.csp.sentinel.dashboard.repository.rule.InMemoryRuleRepositoryAdapter; +import com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient; +import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity; +import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo; +import com.alibaba.csp.sentinel.dashboard.domain.Result; +import com.alibaba.csp.sentinel.dashboard.repository.rule.InMemoryRuleRepositoryAdapter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/MachineRegistryController.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/MachineRegistryController.java similarity index 89% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/MachineRegistryController.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/MachineRegistryController.java index e55f111f94..fc84e7338d 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/MachineRegistryController.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/MachineRegistryController.java @@ -13,16 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.controller; +package com.alibaba.csp.sentinel.dashboard.controller; import java.util.Date; +import com.alibaba.csp.sentinel.dashboard.discovery.AppManagement; import com.alibaba.csp.sentinel.util.StringUtil; -import com.taobao.csp.sentinel.dashboard.discovery.AppManagement; -import com.taobao.csp.sentinel.dashboard.discovery.MachineDiscovery; -import com.taobao.csp.sentinel.dashboard.discovery.MachineInfo; -import com.taobao.csp.sentinel.dashboard.domain.Result; +import com.alibaba.csp.sentinel.dashboard.discovery.MachineDiscovery; +import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo; +import com.alibaba.csp.sentinel.dashboard.domain.Result; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/MetricController.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/MetricController.java similarity index 95% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/MetricController.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/MetricController.java index 9de266800b..ab90c0fc53 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/MetricController.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/MetricController.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.controller; +package com.alibaba.csp.sentinel.dashboard.controller; import java.util.ArrayList; import java.util.Collections; @@ -24,8 +24,8 @@ import java.util.TreeMap; import java.util.concurrent.ConcurrentHashMap; -import com.taobao.csp.sentinel.dashboard.domain.Result; -import com.taobao.csp.sentinel.dashboard.repository.metric.MetricsRepository; +import com.alibaba.csp.sentinel.dashboard.domain.Result; +import com.alibaba.csp.sentinel.dashboard.repository.metric.MetricsRepository; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -36,8 +36,8 @@ import com.alibaba.csp.sentinel.util.StringUtil; -import com.taobao.csp.sentinel.dashboard.datasource.entity.MetricEntity; -import com.taobao.csp.sentinel.dashboard.domain.vo.MetricVo; +import com.alibaba.csp.sentinel.dashboard.datasource.entity.MetricEntity; +import com.alibaba.csp.sentinel.dashboard.domain.vo.MetricVo; /** * @author leyou diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/ParamFlowRuleController.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/ParamFlowRuleController.java similarity index 93% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/ParamFlowRuleController.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/ParamFlowRuleController.java index dfe2cfba45..9d962eae98 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/ParamFlowRuleController.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/ParamFlowRuleController.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.controller; +package com.alibaba.csp.sentinel.dashboard.controller; import java.util.Date; import java.util.List; @@ -21,18 +21,18 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; +import com.alibaba.csp.sentinel.dashboard.client.CommandNotFoundException; +import com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient; +import com.alibaba.csp.sentinel.dashboard.discovery.AppManagement; +import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo; import com.alibaba.csp.sentinel.slots.block.RuleConstant; import com.alibaba.csp.sentinel.util.StringUtil; -import com.taobao.csp.sentinel.dashboard.client.CommandNotFoundException; -import com.taobao.csp.sentinel.dashboard.client.SentinelApiClient; -import com.taobao.csp.sentinel.dashboard.datasource.entity.SentinelVersion; -import com.taobao.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity; -import com.taobao.csp.sentinel.dashboard.discovery.AppManagement; -import com.taobao.csp.sentinel.dashboard.discovery.MachineInfo; -import com.taobao.csp.sentinel.dashboard.domain.Result; -import com.taobao.csp.sentinel.dashboard.repository.rule.RuleRepository; -import com.taobao.csp.sentinel.dashboard.util.VersionUtils; +import com.alibaba.csp.sentinel.dashboard.datasource.entity.SentinelVersion; +import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity; +import com.alibaba.csp.sentinel.dashboard.domain.Result; +import com.alibaba.csp.sentinel.dashboard.repository.rule.RuleRepository; +import com.alibaba.csp.sentinel.dashboard.util.VersionUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/ResourceController.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/ResourceController.java similarity index 91% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/ResourceController.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/ResourceController.java index 3189923f98..f1a9a9df4a 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/ResourceController.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/ResourceController.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.controller; +package com.alibaba.csp.sentinel.dashboard.controller; import java.util.List; import java.util.stream.Collectors; @@ -21,10 +21,10 @@ import com.alibaba.csp.sentinel.util.StringUtil; import com.alibaba.csp.sentinel.command.vo.NodeVo; -import com.taobao.csp.sentinel.dashboard.domain.ResourceTreeNode; -import com.taobao.csp.sentinel.dashboard.client.SentinelApiClient; -import com.taobao.csp.sentinel.dashboard.domain.Result; -import com.taobao.csp.sentinel.dashboard.domain.vo.ResourceVo; +import com.alibaba.csp.sentinel.dashboard.domain.ResourceTreeNode; +import com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient; +import com.alibaba.csp.sentinel.dashboard.domain.Result; +import com.alibaba.csp.sentinel.dashboard.domain.vo.ResourceVo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/SystemController.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/SystemController.java similarity index 94% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/SystemController.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/SystemController.java index 437b2e4e5c..f496a74baf 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/SystemController.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/SystemController.java @@ -13,18 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.controller; +package com.alibaba.csp.sentinel.dashboard.controller; import java.util.Date; import java.util.List; import com.alibaba.csp.sentinel.util.StringUtil; -import com.taobao.csp.sentinel.dashboard.datasource.entity.rule.SystemRuleEntity; -import com.taobao.csp.sentinel.dashboard.discovery.MachineInfo; -import com.taobao.csp.sentinel.dashboard.client.SentinelApiClient; -import com.taobao.csp.sentinel.dashboard.domain.Result; -import com.taobao.csp.sentinel.dashboard.repository.rule.InMemSystemRuleStore; +import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.SystemRuleEntity; +import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo; +import com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient; +import com.alibaba.csp.sentinel.dashboard.domain.Result; +import com.alibaba.csp.sentinel.dashboard.repository.rule.InMemSystemRuleStore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/cluster/ClusterAssignController.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/cluster/ClusterAssignController.java similarity index 90% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/cluster/ClusterAssignController.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/cluster/ClusterAssignController.java index 491386cef0..dc2e14f5b3 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/cluster/ClusterAssignController.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/cluster/ClusterAssignController.java @@ -13,18 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.controller.cluster; +package com.alibaba.csp.sentinel.dashboard.controller.cluster; import java.util.Collections; import java.util.Set; import com.alibaba.csp.sentinel.util.StringUtil; -import com.taobao.csp.sentinel.dashboard.domain.cluster.ClusterAppFullAssignRequest; -import com.taobao.csp.sentinel.dashboard.domain.cluster.ClusterAppAssignResultVO; -import com.taobao.csp.sentinel.dashboard.domain.cluster.ClusterAppSingleServerAssignRequest; -import com.taobao.csp.sentinel.dashboard.service.ClusterAssignService; -import com.taobao.csp.sentinel.dashboard.domain.Result; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterAppFullAssignRequest; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterAppAssignResultVO; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterAppSingleServerAssignRequest; +import com.alibaba.csp.sentinel.dashboard.service.ClusterAssignService; +import com.alibaba.csp.sentinel.dashboard.domain.Result; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/cluster/ClusterConfigController.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/cluster/ClusterConfigController.java similarity index 89% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/cluster/ClusterConfigController.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/cluster/ClusterConfigController.java index bcbb3b6506..e9b9aed0e4 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/cluster/ClusterConfigController.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/cluster/ClusterConfigController.java @@ -13,31 +13,31 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.controller.cluster; +package com.alibaba.csp.sentinel.dashboard.controller.cluster; import java.util.List; import java.util.Optional; import java.util.concurrent.ExecutionException; import com.alibaba.csp.sentinel.cluster.ClusterStateManager; +import com.alibaba.csp.sentinel.dashboard.client.CommandNotFoundException; +import com.alibaba.csp.sentinel.dashboard.discovery.AppManagement; import com.alibaba.csp.sentinel.util.StringUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; -import com.taobao.csp.sentinel.dashboard.client.CommandNotFoundException; -import com.taobao.csp.sentinel.dashboard.datasource.entity.SentinelVersion; -import com.taobao.csp.sentinel.dashboard.discovery.AppManagement; -import com.taobao.csp.sentinel.dashboard.domain.cluster.request.ClusterClientModifyRequest; -import com.taobao.csp.sentinel.dashboard.domain.cluster.request.ClusterModifyRequest; -import com.taobao.csp.sentinel.dashboard.domain.cluster.request.ClusterServerModifyRequest; -import com.taobao.csp.sentinel.dashboard.domain.cluster.state.AppClusterClientStateWrapVO; -import com.taobao.csp.sentinel.dashboard.domain.cluster.state.AppClusterServerStateWrapVO; -import com.taobao.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStatePairVO; -import com.taobao.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStateVO; -import com.taobao.csp.sentinel.dashboard.service.ClusterConfigService; -import com.taobao.csp.sentinel.dashboard.util.ClusterEntityUtils; -import com.taobao.csp.sentinel.dashboard.util.VersionUtils; -import com.taobao.csp.sentinel.dashboard.domain.Result; +import com.alibaba.csp.sentinel.dashboard.datasource.entity.SentinelVersion; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterClientModifyRequest; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterModifyRequest; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterServerModifyRequest; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.state.AppClusterClientStateWrapVO; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.state.AppClusterServerStateWrapVO; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStatePairVO; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStateVO; +import com.alibaba.csp.sentinel.dashboard.service.ClusterConfigService; +import com.alibaba.csp.sentinel.dashboard.util.ClusterEntityUtils; +import com.alibaba.csp.sentinel.dashboard.util.VersionUtils; +import com.alibaba.csp.sentinel.dashboard.domain.Result; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/v2/FlowControllerV2.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/v2/FlowControllerV2.java similarity index 95% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/v2/FlowControllerV2.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/v2/FlowControllerV2.java index fb9ecb49c8..30ae0ba9dc 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/controller/v2/FlowControllerV2.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/v2/FlowControllerV2.java @@ -13,18 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.controller.v2; +package com.alibaba.csp.sentinel.dashboard.controller.v2; import java.util.Date; import java.util.List; import com.alibaba.csp.sentinel.util.StringUtil; -import com.taobao.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity; -import com.taobao.csp.sentinel.dashboard.repository.rule.InMemoryRuleRepositoryAdapter; -import com.taobao.csp.sentinel.dashboard.rule.DynamicRuleProvider; -import com.taobao.csp.sentinel.dashboard.rule.DynamicRulePublisher; -import com.taobao.csp.sentinel.dashboard.domain.Result; +import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity; +import com.alibaba.csp.sentinel.dashboard.repository.rule.InMemoryRuleRepositoryAdapter; +import com.alibaba.csp.sentinel.dashboard.rule.DynamicRuleProvider; +import com.alibaba.csp.sentinel.dashboard.rule.DynamicRulePublisher; +import com.alibaba.csp.sentinel.dashboard.domain.Result; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/datasource/entity/ApplicationEntity.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/ApplicationEntity.java similarity index 94% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/datasource/entity/ApplicationEntity.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/ApplicationEntity.java index 19dc4a3ffe..edaee180ac 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/datasource/entity/ApplicationEntity.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/ApplicationEntity.java @@ -13,11 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.datasource.entity; +package com.alibaba.csp.sentinel.dashboard.datasource.entity; import java.util.Date; -import com.taobao.csp.sentinel.dashboard.discovery.AppInfo; +import com.alibaba.csp.sentinel.dashboard.discovery.AppInfo; /** * @author leyou diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/datasource/entity/MachineEntity.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/MachineEntity.java similarity index 95% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/datasource/entity/MachineEntity.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/MachineEntity.java index 682e4c78b6..677e549bb7 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/datasource/entity/MachineEntity.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/MachineEntity.java @@ -13,11 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.datasource.entity; +package com.alibaba.csp.sentinel.dashboard.datasource.entity; import java.util.Date; -import com.taobao.csp.sentinel.dashboard.discovery.MachineInfo; +import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo; /** * @author leyou diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/datasource/entity/MetricEntity.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/MetricEntity.java similarity index 98% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/datasource/entity/MetricEntity.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/MetricEntity.java index fd3314f6a2..f08a41a693 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/datasource/entity/MetricEntity.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/MetricEntity.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.datasource.entity; +package com.alibaba.csp.sentinel.dashboard.datasource.entity; import java.util.Date; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/datasource/entity/MetricPositionEntity.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/MetricPositionEntity.java similarity index 97% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/datasource/entity/MetricPositionEntity.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/MetricPositionEntity.java index 47fd7d33da..2be29eb839 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/datasource/entity/MetricPositionEntity.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/MetricPositionEntity.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.datasource.entity; +package com.alibaba.csp.sentinel.dashboard.datasource.entity; import java.util.Date; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/datasource/entity/SentinelVersion.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/SentinelVersion.java similarity index 98% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/datasource/entity/SentinelVersion.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/SentinelVersion.java index f1ebfe04e5..7fc105ee79 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/datasource/entity/SentinelVersion.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/SentinelVersion.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.datasource.entity; +package com.alibaba.csp.sentinel.dashboard.datasource.entity; /** * @author Eric Zhao diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/datasource/entity/rule/AbstractRuleEntity.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/AbstractRuleEntity.java similarity index 97% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/datasource/entity/rule/AbstractRuleEntity.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/AbstractRuleEntity.java index 7d84eaf742..1f5eaa23dd 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/datasource/entity/rule/AbstractRuleEntity.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/AbstractRuleEntity.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.datasource.entity.rule; +package com.alibaba.csp.sentinel.dashboard.datasource.entity.rule; import java.util.Date; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/datasource/entity/rule/AuthorityRuleEntity.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/AuthorityRuleEntity.java similarity index 96% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/datasource/entity/rule/AuthorityRuleEntity.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/AuthorityRuleEntity.java index 6c98d8c1c6..9249620101 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/datasource/entity/rule/AuthorityRuleEntity.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/AuthorityRuleEntity.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.datasource.entity.rule; +package com.alibaba.csp.sentinel.dashboard.datasource.entity.rule; import com.alibaba.csp.sentinel.slots.block.authority.AuthorityRule; import com.alibaba.csp.sentinel.util.AssertUtil; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/datasource/entity/rule/DegradeRuleEntity.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/DegradeRuleEntity.java similarity index 98% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/datasource/entity/rule/DegradeRuleEntity.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/DegradeRuleEntity.java index 07898526a0..f77d608032 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/datasource/entity/rule/DegradeRuleEntity.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/DegradeRuleEntity.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.datasource.entity.rule; +package com.alibaba.csp.sentinel.dashboard.datasource.entity.rule; import java.util.Date; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/datasource/entity/rule/FlowRuleEntity.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/FlowRuleEntity.java similarity index 98% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/datasource/entity/rule/FlowRuleEntity.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/FlowRuleEntity.java index eb2eced92d..65e9acc1ee 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/datasource/entity/rule/FlowRuleEntity.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/FlowRuleEntity.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.datasource.entity.rule; +package com.alibaba.csp.sentinel.dashboard.datasource.entity.rule; import java.util.Date; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/datasource/entity/rule/ParamFlowRuleEntity.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/ParamFlowRuleEntity.java similarity index 97% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/datasource/entity/rule/ParamFlowRuleEntity.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/ParamFlowRuleEntity.java index 3924f1fdab..5cb845ba04 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/datasource/entity/rule/ParamFlowRuleEntity.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/ParamFlowRuleEntity.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.datasource.entity.rule; +package com.alibaba.csp.sentinel.dashboard.datasource.entity.rule; import java.util.List; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/datasource/entity/rule/RuleEntity.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/RuleEntity.java similarity index 92% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/datasource/entity/rule/RuleEntity.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/RuleEntity.java index eeeb5728a3..0f22ec5347 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/datasource/entity/rule/RuleEntity.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/RuleEntity.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.datasource.entity.rule; +package com.alibaba.csp.sentinel.dashboard.datasource.entity.rule; import java.util.Date; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/datasource/entity/rule/SystemRuleEntity.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/SystemRuleEntity.java similarity index 97% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/datasource/entity/rule/SystemRuleEntity.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/SystemRuleEntity.java index 6199803858..1c6e3bfda4 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/datasource/entity/rule/SystemRuleEntity.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/SystemRuleEntity.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.datasource.entity.rule; +package com.alibaba.csp.sentinel.dashboard.datasource.entity.rule; import java.util.Date; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/discovery/AppInfo.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/discovery/AppInfo.java similarity index 97% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/discovery/AppInfo.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/discovery/AppInfo.java index ff9a5262e5..b5290306a5 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/discovery/AppInfo.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/discovery/AppInfo.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.discovery; +package com.alibaba.csp.sentinel.dashboard.discovery; import java.util.HashSet; import java.util.Optional; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/discovery/AppManagement.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/discovery/AppManagement.java similarity index 97% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/discovery/AppManagement.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/discovery/AppManagement.java index 8002c659ba..89b7481ca1 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/discovery/AppManagement.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/discovery/AppManagement.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.discovery; +package com.alibaba.csp.sentinel.dashboard.discovery; import java.util.List; import java.util.Set; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/discovery/MachineDiscovery.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/discovery/MachineDiscovery.java similarity index 94% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/discovery/MachineDiscovery.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/discovery/MachineDiscovery.java index 792bf451e3..88cdbd5e84 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/discovery/MachineDiscovery.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/discovery/MachineDiscovery.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.discovery; +package com.alibaba.csp.sentinel.dashboard.discovery; import java.util.List; import java.util.Set; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/discovery/MachineInfo.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/discovery/MachineInfo.java similarity index 98% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/discovery/MachineInfo.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/discovery/MachineInfo.java index 51d2ef95dc..c4ba88c3cd 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/discovery/MachineInfo.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/discovery/MachineInfo.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.discovery; +package com.alibaba.csp.sentinel.dashboard.discovery; import java.util.Date; import java.util.Objects; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/discovery/SimpleMachineDiscovery.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/discovery/SimpleMachineDiscovery.java similarity index 96% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/discovery/SimpleMachineDiscovery.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/discovery/SimpleMachineDiscovery.java index 1148664fff..b0f1f63be8 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/discovery/SimpleMachineDiscovery.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/discovery/SimpleMachineDiscovery.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.discovery; +package com.alibaba.csp.sentinel.dashboard.discovery; import java.util.ArrayList; import java.util.HashSet; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/ResourceTreeNode.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/ResourceTreeNode.java similarity index 99% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/ResourceTreeNode.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/ResourceTreeNode.java index 8011ff8b9d..fa2e7ca9b1 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/ResourceTreeNode.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/ResourceTreeNode.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.domain; +package com.alibaba.csp.sentinel.dashboard.domain; import java.util.ArrayList; import java.util.HashMap; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/Result.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/Result.java similarity index 97% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/Result.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/Result.java index 23d8d84dda..2dbf476f0c 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/Result.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/Result.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.domain; +package com.alibaba.csp.sentinel.dashboard.domain; /** * @author leyou diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/ClusterAppAssignResultVO.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/ClusterAppAssignResultVO.java similarity index 96% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/ClusterAppAssignResultVO.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/ClusterAppAssignResultVO.java index 4d6846280b..b7b48ccf04 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/ClusterAppAssignResultVO.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/ClusterAppAssignResultVO.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.domain.cluster; +package com.alibaba.csp.sentinel.dashboard.domain.cluster; import java.util.Set; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/ClusterAppFullAssignRequest.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/ClusterAppFullAssignRequest.java similarity index 91% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/ClusterAppFullAssignRequest.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/ClusterAppFullAssignRequest.java index d4590ff57e..96a3dc9332 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/ClusterAppFullAssignRequest.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/ClusterAppFullAssignRequest.java @@ -13,12 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.domain.cluster; +package com.alibaba.csp.sentinel.dashboard.domain.cluster; import java.util.List; import java.util.Set; -import com.taobao.csp.sentinel.dashboard.domain.cluster.request.ClusterAppAssignMap; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterAppAssignMap; /** * @author Eric Zhao diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/ClusterAppSingleServerAssignRequest.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/ClusterAppSingleServerAssignRequest.java similarity index 91% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/ClusterAppSingleServerAssignRequest.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/ClusterAppSingleServerAssignRequest.java index db93503297..f9d9bbc0e9 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/ClusterAppSingleServerAssignRequest.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/ClusterAppSingleServerAssignRequest.java @@ -13,11 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.domain.cluster; +package com.alibaba.csp.sentinel.dashboard.domain.cluster; import java.util.Set; -import com.taobao.csp.sentinel.dashboard.domain.cluster.request.ClusterAppAssignMap; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterAppAssignMap; /** * @author Eric Zhao diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/ClusterClientInfoVO.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/ClusterClientInfoVO.java similarity index 97% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/ClusterClientInfoVO.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/ClusterClientInfoVO.java index 1bff214c9e..a9437e76f0 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/ClusterClientInfoVO.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/ClusterClientInfoVO.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.domain.cluster; +package com.alibaba.csp.sentinel.dashboard.domain.cluster; /** * @author Eric Zhao diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/ClusterGroupEntity.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/ClusterGroupEntity.java similarity index 97% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/ClusterGroupEntity.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/ClusterGroupEntity.java index dcbf46f4b5..eef2552154 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/ClusterGroupEntity.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/ClusterGroupEntity.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.domain.cluster; +package com.alibaba.csp.sentinel.dashboard.domain.cluster; import java.util.HashSet; import java.util.Set; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/ClusterStateSingleVO.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/ClusterStateSingleVO.java similarity index 96% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/ClusterStateSingleVO.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/ClusterStateSingleVO.java index 0013fa569e..7678c5195f 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/ClusterStateSingleVO.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/ClusterStateSingleVO.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.domain.cluster; +package com.alibaba.csp.sentinel.dashboard.domain.cluster; /** * @author Eric Zhao diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/ConnectionDescriptorVO.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/ConnectionDescriptorVO.java similarity index 95% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/ConnectionDescriptorVO.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/ConnectionDescriptorVO.java index 415aaf6fd3..71d9e74d83 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/ConnectionDescriptorVO.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/ConnectionDescriptorVO.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.domain.cluster; +package com.alibaba.csp.sentinel.dashboard.domain.cluster; /** diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/ConnectionGroupVO.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/ConnectionGroupVO.java similarity index 96% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/ConnectionGroupVO.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/ConnectionGroupVO.java index 5618c88376..af3aa90670 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/ConnectionGroupVO.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/ConnectionGroupVO.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.domain.cluster; +package com.alibaba.csp.sentinel.dashboard.domain.cluster; import java.util.List; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/config/ClusterClientConfig.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/config/ClusterClientConfig.java similarity index 96% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/config/ClusterClientConfig.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/config/ClusterClientConfig.java index 6130479850..2cd6bb3bd1 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/config/ClusterClientConfig.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/config/ClusterClientConfig.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.domain.cluster.config; +package com.alibaba.csp.sentinel.dashboard.domain.cluster.config; /** * @author Eric Zhao diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/config/ServerFlowConfig.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/config/ServerFlowConfig.java similarity index 97% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/config/ServerFlowConfig.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/config/ServerFlowConfig.java index cc62c5c29f..3390ea14f0 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/config/ServerFlowConfig.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/config/ServerFlowConfig.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.domain.cluster.config; +package com.alibaba.csp.sentinel.dashboard.domain.cluster.config; /** * @author Eric Zhao diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/config/ServerTransportConfig.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/config/ServerTransportConfig.java similarity index 96% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/config/ServerTransportConfig.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/config/ServerTransportConfig.java index 698da2e67d..58fe12a7dc 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/config/ServerTransportConfig.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/config/ServerTransportConfig.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.domain.cluster.config; +package com.alibaba.csp.sentinel.dashboard.domain.cluster.config; /** * @author Eric Zhao diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/request/ClusterAppAssignMap.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/request/ClusterAppAssignMap.java similarity index 97% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/request/ClusterAppAssignMap.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/request/ClusterAppAssignMap.java index 047ef38302..3dbf96b1d3 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/request/ClusterAppAssignMap.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/request/ClusterAppAssignMap.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.domain.cluster.request; +package com.alibaba.csp.sentinel.dashboard.domain.cluster.request; import java.util.Set; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/request/ClusterClientModifyRequest.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/request/ClusterClientModifyRequest.java similarity index 92% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/request/ClusterClientModifyRequest.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/request/ClusterClientModifyRequest.java index 9c7a28b6a4..e6ff5610d5 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/request/ClusterClientModifyRequest.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/request/ClusterClientModifyRequest.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.domain.cluster.request; +package com.alibaba.csp.sentinel.dashboard.domain.cluster.request; -import com.taobao.csp.sentinel.dashboard.domain.cluster.config.ClusterClientConfig; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ClusterClientConfig; /** * @author Eric Zhao diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/request/ClusterModifyRequest.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/request/ClusterModifyRequest.java similarity index 92% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/request/ClusterModifyRequest.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/request/ClusterModifyRequest.java index 5922074986..9f855ef7c2 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/request/ClusterModifyRequest.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/request/ClusterModifyRequest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.domain.cluster.request; +package com.alibaba.csp.sentinel.dashboard.domain.cluster.request; /** * @author Eric Zhao diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/request/ClusterServerModifyRequest.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/request/ClusterServerModifyRequest.java similarity index 92% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/request/ClusterServerModifyRequest.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/request/ClusterServerModifyRequest.java index 0d647940cc..9389f693fa 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/request/ClusterServerModifyRequest.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/request/ClusterServerModifyRequest.java @@ -13,12 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.domain.cluster.request; +package com.alibaba.csp.sentinel.dashboard.domain.cluster.request; import java.util.Set; -import com.taobao.csp.sentinel.dashboard.domain.cluster.config.ServerFlowConfig; -import com.taobao.csp.sentinel.dashboard.domain.cluster.config.ServerTransportConfig; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerFlowConfig; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerTransportConfig; /** * @author Eric Zhao diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/state/AppClusterClientStateWrapVO.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/state/AppClusterClientStateWrapVO.java similarity index 96% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/state/AppClusterClientStateWrapVO.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/state/AppClusterClientStateWrapVO.java index ba642c2cdd..4076d23b29 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/state/AppClusterClientStateWrapVO.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/state/AppClusterClientStateWrapVO.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.domain.cluster.state; +package com.alibaba.csp.sentinel.dashboard.domain.cluster.state; /** * @author Eric Zhao diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/state/AppClusterServerStateWrapVO.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/state/AppClusterServerStateWrapVO.java similarity index 97% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/state/AppClusterServerStateWrapVO.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/state/AppClusterServerStateWrapVO.java index 1d7b06c8b6..ed39e7bcee 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/state/AppClusterServerStateWrapVO.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/state/AppClusterServerStateWrapVO.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.domain.cluster.state; +package com.alibaba.csp.sentinel.dashboard.domain.cluster.state; /** * @author Eric Zhao diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/state/ClusterClientStateVO.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/state/ClusterClientStateVO.java similarity index 89% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/state/ClusterClientStateVO.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/state/ClusterClientStateVO.java index f0ca39b4cb..ac61b0b971 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/state/ClusterClientStateVO.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/state/ClusterClientStateVO.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.domain.cluster.state; +package com.alibaba.csp.sentinel.dashboard.domain.cluster.state; -import com.taobao.csp.sentinel.dashboard.domain.cluster.ClusterClientInfoVO; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterClientInfoVO; /** * @author Eric Zhao diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/state/ClusterRequestLimitVO.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/state/ClusterRequestLimitVO.java similarity index 96% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/state/ClusterRequestLimitVO.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/state/ClusterRequestLimitVO.java index ba0d09959b..6c5da420ed 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/state/ClusterRequestLimitVO.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/state/ClusterRequestLimitVO.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.domain.cluster.state; +package com.alibaba.csp.sentinel.dashboard.domain.cluster.state; /** * @author Eric Zhao diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/state/ClusterServerStateVO.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/state/ClusterServerStateVO.java similarity index 90% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/state/ClusterServerStateVO.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/state/ClusterServerStateVO.java index e751696b30..bb4166de0d 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/state/ClusterServerStateVO.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/state/ClusterServerStateVO.java @@ -13,14 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.domain.cluster.state; +package com.alibaba.csp.sentinel.dashboard.domain.cluster.state; import java.util.List; import java.util.Set; -import com.taobao.csp.sentinel.dashboard.domain.cluster.ConnectionGroupVO; -import com.taobao.csp.sentinel.dashboard.domain.cluster.config.ServerFlowConfig; -import com.taobao.csp.sentinel.dashboard.domain.cluster.config.ServerTransportConfig; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.ConnectionGroupVO; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerFlowConfig; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerTransportConfig; /** * @author Eric Zhao diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/state/ClusterStateSimpleEntity.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/state/ClusterStateSimpleEntity.java similarity index 96% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/state/ClusterStateSimpleEntity.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/state/ClusterStateSimpleEntity.java index 0ccf5e6361..c5537aab0b 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/state/ClusterStateSimpleEntity.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/state/ClusterStateSimpleEntity.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.domain.cluster.state; +package com.alibaba.csp.sentinel.dashboard.domain.cluster.state; /** * @author Eric Zhao diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/state/ClusterUniversalStatePairVO.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/state/ClusterUniversalStatePairVO.java similarity index 96% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/state/ClusterUniversalStatePairVO.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/state/ClusterUniversalStatePairVO.java index 428915caa3..112765602b 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/state/ClusterUniversalStatePairVO.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/state/ClusterUniversalStatePairVO.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.domain.cluster.state; +package com.alibaba.csp.sentinel.dashboard.domain.cluster.state; /** * @author Eric Zhao diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/state/ClusterUniversalStateVO.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/state/ClusterUniversalStateVO.java similarity index 96% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/state/ClusterUniversalStateVO.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/state/ClusterUniversalStateVO.java index 78fa7ba373..3e9a787db4 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/cluster/state/ClusterUniversalStateVO.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/state/ClusterUniversalStateVO.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.domain.cluster.state; +package com.alibaba.csp.sentinel.dashboard.domain.cluster.state; /** * @author Eric Zhao diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/vo/MachineInfoVo.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/vo/MachineInfoVo.java similarity index 93% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/vo/MachineInfoVo.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/vo/MachineInfoVo.java index 835237e101..1c7ef85421 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/vo/MachineInfoVo.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/vo/MachineInfoVo.java @@ -13,14 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.domain.vo; +package com.alibaba.csp.sentinel.dashboard.domain.vo; import java.util.ArrayList; import java.util.Date; import java.util.List; -import com.taobao.csp.sentinel.dashboard.discovery.MachineDiscovery; -import com.taobao.csp.sentinel.dashboard.discovery.MachineInfo; +import com.alibaba.csp.sentinel.dashboard.discovery.MachineDiscovery; +import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo; /** * @author leyou diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/vo/MetricVo.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/vo/MetricVo.java similarity index 97% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/vo/MetricVo.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/vo/MetricVo.java index 460580c660..af64941ee0 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/vo/MetricVo.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/vo/MetricVo.java @@ -13,13 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.domain.vo; +package com.alibaba.csp.sentinel.dashboard.domain.vo; import java.util.ArrayList; import java.util.Collection; import java.util.List; -import com.taobao.csp.sentinel.dashboard.datasource.entity.MetricEntity; +import com.alibaba.csp.sentinel.dashboard.datasource.entity.MetricEntity; /** * @author leyou diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/vo/ResourceVo.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/vo/ResourceVo.java similarity index 98% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/vo/ResourceVo.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/vo/ResourceVo.java index a5fb302eca..a8ffe24e97 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/domain/vo/ResourceVo.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/vo/ResourceVo.java @@ -13,14 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.domain.vo; +package com.alibaba.csp.sentinel.dashboard.domain.vo; import java.util.ArrayList; import java.util.List; import com.alibaba.csp.sentinel.command.vo.NodeVo; -import com.taobao.csp.sentinel.dashboard.domain.ResourceTreeNode; +import com.alibaba.csp.sentinel.dashboard.domain.ResourceTreeNode; /** * @author leyou diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/metric/MetricFetcher.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/metric/MetricFetcher.java similarity index 97% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/metric/MetricFetcher.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/metric/MetricFetcher.java index 369d035373..0941e549f6 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/metric/MetricFetcher.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/metric/MetricFetcher.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.metric; +package com.alibaba.csp.sentinel.dashboard.metric; import java.net.ConnectException; import java.net.SocketTimeoutException; @@ -36,14 +36,14 @@ import com.alibaba.csp.sentinel.concurrent.NamedThreadFactory; import com.alibaba.csp.sentinel.config.SentinelConfig; +import com.alibaba.csp.sentinel.dashboard.datasource.entity.MetricEntity; +import com.alibaba.csp.sentinel.dashboard.discovery.AppManagement; +import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo; import com.alibaba.csp.sentinel.node.metric.MetricNode; import com.alibaba.csp.sentinel.util.StringUtil; -import com.taobao.csp.sentinel.dashboard.datasource.entity.MetricEntity; -import com.taobao.csp.sentinel.dashboard.discovery.AppManagement; -import com.taobao.csp.sentinel.dashboard.discovery.MachineInfo; -import com.taobao.csp.sentinel.dashboard.repository.metric.MetricsRepository; -import com.taobao.csp.sentinel.dashboard.util.MachineUtils; +import com.alibaba.csp.sentinel.dashboard.repository.metric.MetricsRepository; +import com.alibaba.csp.sentinel.dashboard.util.MachineUtils; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.concurrent.FutureCallback; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/repository/metric/InMemoryMetricsRepository.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/metric/InMemoryMetricsRepository.java similarity index 97% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/repository/metric/InMemoryMetricsRepository.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/metric/InMemoryMetricsRepository.java index c52403b49a..d10ecf2c3a 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/repository/metric/InMemoryMetricsRepository.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/metric/InMemoryMetricsRepository.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.repository.metric; +package com.alibaba.csp.sentinel.dashboard.repository.metric; import java.util.ArrayList; import java.util.HashMap; @@ -24,9 +24,9 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; +import com.alibaba.csp.sentinel.dashboard.datasource.entity.MetricEntity; import com.alibaba.csp.sentinel.util.StringUtil; -import com.taobao.csp.sentinel.dashboard.datasource.entity.MetricEntity; import org.springframework.stereotype.Component; /** diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/repository/metric/MetricsRepository.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/metric/MetricsRepository.java similarity index 96% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/repository/metric/MetricsRepository.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/metric/MetricsRepository.java index 5840dd3f64..f54cc2090f 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/repository/metric/MetricsRepository.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/metric/MetricsRepository.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.repository.metric; +package com.alibaba.csp.sentinel.dashboard.repository.metric; import java.util.List; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/repository/rule/InMemAuthorityRuleStore.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/rule/InMemAuthorityRuleStore.java similarity index 87% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/repository/rule/InMemAuthorityRuleStore.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/rule/InMemAuthorityRuleStore.java index e04f0b86b2..bbeb88891a 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/repository/rule/InMemAuthorityRuleStore.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/rule/InMemAuthorityRuleStore.java @@ -13,11 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.repository.rule; +package com.alibaba.csp.sentinel.dashboard.repository.rule; import java.util.concurrent.atomic.AtomicLong; -import com.taobao.csp.sentinel.dashboard.datasource.entity.rule.AuthorityRuleEntity; +import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.AuthorityRuleEntity; + import org.springframework.stereotype.Component; /** diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/repository/rule/InMemDegradeRuleStore.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/rule/InMemDegradeRuleStore.java similarity index 87% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/repository/rule/InMemDegradeRuleStore.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/rule/InMemDegradeRuleStore.java index 13bb02b773..0b9bf7e1a5 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/repository/rule/InMemDegradeRuleStore.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/rule/InMemDegradeRuleStore.java @@ -13,11 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.repository.rule; +package com.alibaba.csp.sentinel.dashboard.repository.rule; import java.util.concurrent.atomic.AtomicLong; -import com.taobao.csp.sentinel.dashboard.datasource.entity.rule.DegradeRuleEntity; +import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.DegradeRuleEntity; + import org.springframework.stereotype.Component; /** diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/repository/rule/InMemFlowRuleStore.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/rule/InMemFlowRuleStore.java similarity index 91% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/repository/rule/InMemFlowRuleStore.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/rule/InMemFlowRuleStore.java index 8474211151..c5a2a347d7 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/repository/rule/InMemFlowRuleStore.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/rule/InMemFlowRuleStore.java @@ -13,13 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.repository.rule; +package com.alibaba.csp.sentinel.dashboard.repository.rule; import java.util.concurrent.atomic.AtomicLong; +import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity; import com.alibaba.csp.sentinel.slots.block.flow.ClusterFlowConfig; -import com.taobao.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity; import org.springframework.stereotype.Component; /** diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/repository/rule/InMemParamFlowRuleStore.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/rule/InMemParamFlowRuleStore.java similarity index 91% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/repository/rule/InMemParamFlowRuleStore.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/rule/InMemParamFlowRuleStore.java index cf848e5e16..5a82f13874 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/repository/rule/InMemParamFlowRuleStore.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/rule/InMemParamFlowRuleStore.java @@ -13,13 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.repository.rule; +package com.alibaba.csp.sentinel.dashboard.repository.rule; import java.util.concurrent.atomic.AtomicLong; +import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity; import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowClusterConfig; -import com.taobao.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity; import org.springframework.stereotype.Component; /** diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/repository/rule/InMemSystemRuleStore.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/rule/InMemSystemRuleStore.java similarity index 87% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/repository/rule/InMemSystemRuleStore.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/rule/InMemSystemRuleStore.java index f1cb7f4b9a..8d3949b419 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/repository/rule/InMemSystemRuleStore.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/rule/InMemSystemRuleStore.java @@ -13,11 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.repository.rule; +package com.alibaba.csp.sentinel.dashboard.repository.rule; import java.util.concurrent.atomic.AtomicLong; -import com.taobao.csp.sentinel.dashboard.datasource.entity.rule.SystemRuleEntity; +import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.SystemRuleEntity; + import org.springframework.stereotype.Component; /** diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/repository/rule/InMemoryRuleRepositoryAdapter.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/rule/InMemoryRuleRepositoryAdapter.java similarity index 94% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/repository/rule/InMemoryRuleRepositoryAdapter.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/rule/InMemoryRuleRepositoryAdapter.java index 0901426aab..c6fdeed3a1 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/repository/rule/InMemoryRuleRepositoryAdapter.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/rule/InMemoryRuleRepositoryAdapter.java @@ -13,18 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.repository.rule; +package com.alibaba.csp.sentinel.dashboard.repository.rule; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.RuleEntity; +import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo; import com.alibaba.csp.sentinel.util.AssertUtil; -import com.taobao.csp.sentinel.dashboard.datasource.entity.rule.RuleEntity; -import com.taobao.csp.sentinel.dashboard.discovery.MachineInfo; - /** * @author leyou */ diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/repository/rule/RuleRepository.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/rule/RuleRepository.java similarity index 93% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/repository/rule/RuleRepository.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/rule/RuleRepository.java index 6cd3f7927f..266c2fab68 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/repository/rule/RuleRepository.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/rule/RuleRepository.java @@ -13,11 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.repository.rule; +package com.alibaba.csp.sentinel.dashboard.repository.rule; import java.util.List; -import com.taobao.csp.sentinel.dashboard.discovery.MachineInfo; +import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo; /** * Interface to store and find rules. diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/rule/DynamicRuleProvider.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/rule/DynamicRuleProvider.java similarity index 93% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/rule/DynamicRuleProvider.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/rule/DynamicRuleProvider.java index 20a1e937fd..7ee38ad16a 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/rule/DynamicRuleProvider.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/rule/DynamicRuleProvider.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.rule; +package com.alibaba.csp.sentinel.dashboard.rule; /** * @author Eric Zhao diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/rule/DynamicRulePublisher.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/rule/DynamicRulePublisher.java similarity index 95% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/rule/DynamicRulePublisher.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/rule/DynamicRulePublisher.java index 007bb8635c..940d76af81 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/rule/DynamicRulePublisher.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/rule/DynamicRulePublisher.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.rule; +package com.alibaba.csp.sentinel.dashboard.rule; /** * @author Eric Zhao diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/rule/FlowRuleApiProvider.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/rule/FlowRuleApiProvider.java similarity index 84% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/rule/FlowRuleApiProvider.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/rule/FlowRuleApiProvider.java index 57c2dc0410..cf5d9b2a6c 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/rule/FlowRuleApiProvider.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/rule/FlowRuleApiProvider.java @@ -13,19 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.rule; +package com.alibaba.csp.sentinel.dashboard.rule; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; +import com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient; +import com.alibaba.csp.sentinel.dashboard.discovery.AppManagement; +import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo; +import com.alibaba.csp.sentinel.dashboard.util.MachineUtils; import com.alibaba.csp.sentinel.util.StringUtil; -import com.taobao.csp.sentinel.dashboard.client.SentinelApiClient; -import com.taobao.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity; -import com.taobao.csp.sentinel.dashboard.discovery.AppManagement; -import com.taobao.csp.sentinel.dashboard.discovery.MachineInfo; -import com.taobao.csp.sentinel.dashboard.util.MachineUtils; +import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/rule/FlowRuleApiPublisher.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/rule/FlowRuleApiPublisher.java similarity index 81% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/rule/FlowRuleApiPublisher.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/rule/FlowRuleApiPublisher.java index e8656c886f..2f65379840 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/rule/FlowRuleApiPublisher.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/rule/FlowRuleApiPublisher.java @@ -13,18 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.rule; +package com.alibaba.csp.sentinel.dashboard.rule; import java.util.List; import java.util.Set; +import com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient; +import com.alibaba.csp.sentinel.dashboard.discovery.AppManagement; +import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo; import com.alibaba.csp.sentinel.util.StringUtil; -import com.taobao.csp.sentinel.dashboard.client.SentinelApiClient; -import com.taobao.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity; -import com.taobao.csp.sentinel.dashboard.discovery.AppManagement; -import com.taobao.csp.sentinel.dashboard.discovery.MachineInfo; -import com.taobao.csp.sentinel.dashboard.util.MachineUtils; +import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity; +import com.alibaba.csp.sentinel.dashboard.util.MachineUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/service/ClusterAssignService.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/service/ClusterAssignService.java similarity index 88% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/service/ClusterAssignService.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/service/ClusterAssignService.java index 3b2a1edfd6..79a796ed56 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/service/ClusterAssignService.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/service/ClusterAssignService.java @@ -13,13 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.service; +package com.alibaba.csp.sentinel.dashboard.service; import java.util.List; import java.util.Set; -import com.taobao.csp.sentinel.dashboard.domain.cluster.ClusterAppAssignResultVO; -import com.taobao.csp.sentinel.dashboard.domain.cluster.request.ClusterAppAssignMap; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterAppAssignResultVO; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterAppAssignMap; /** * @author Eric Zhao diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/service/ClusterAssignServiceImpl.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/service/ClusterAssignServiceImpl.java similarity index 93% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/service/ClusterAssignServiceImpl.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/service/ClusterAssignServiceImpl.java index c7ebda8237..5ed1af12a8 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/service/ClusterAssignServiceImpl.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/service/ClusterAssignServiceImpl.java @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.service; +package com.alibaba.csp.sentinel.dashboard.service; -import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Objects; @@ -29,14 +28,14 @@ import com.alibaba.csp.sentinel.util.AssertUtil; import com.alibaba.csp.sentinel.util.function.Tuple2; -import com.taobao.csp.sentinel.dashboard.client.SentinelApiClient; -import com.taobao.csp.sentinel.dashboard.domain.cluster.ClusterAppAssignResultVO; -import com.taobao.csp.sentinel.dashboard.domain.cluster.ClusterGroupEntity; -import com.taobao.csp.sentinel.dashboard.domain.cluster.config.ClusterClientConfig; -import com.taobao.csp.sentinel.dashboard.domain.cluster.config.ServerFlowConfig; -import com.taobao.csp.sentinel.dashboard.domain.cluster.config.ServerTransportConfig; -import com.taobao.csp.sentinel.dashboard.domain.cluster.request.ClusterAppAssignMap; -import com.taobao.csp.sentinel.dashboard.util.MachineUtils; +import com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterAppAssignResultVO; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterGroupEntity; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ClusterClientConfig; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerFlowConfig; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerTransportConfig; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterAppAssignMap; +import com.alibaba.csp.sentinel.dashboard.util.MachineUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/service/ClusterConfigService.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/service/ClusterConfigService.java similarity index 86% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/service/ClusterConfigService.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/service/ClusterConfigService.java index 0e91c617ea..fe52ee9c47 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/service/ClusterConfigService.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/service/ClusterConfigService.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.service; +package com.alibaba.csp.sentinel.dashboard.service; import java.util.ArrayList; import java.util.List; @@ -22,23 +22,23 @@ import java.util.stream.Collectors; import com.alibaba.csp.sentinel.cluster.ClusterStateManager; +import com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient; +import com.alibaba.csp.sentinel.dashboard.discovery.AppInfo; +import com.alibaba.csp.sentinel.dashboard.discovery.AppManagement; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterServerModifyRequest; +import com.alibaba.csp.sentinel.dashboard.util.AsyncUtils; +import com.alibaba.csp.sentinel.dashboard.util.ClusterEntityUtils; import com.alibaba.csp.sentinel.util.StringUtil; -import com.taobao.csp.sentinel.dashboard.client.SentinelApiClient; -import com.taobao.csp.sentinel.dashboard.discovery.AppInfo; -import com.taobao.csp.sentinel.dashboard.discovery.AppManagement; -import com.taobao.csp.sentinel.dashboard.domain.cluster.ClusterGroupEntity; -import com.taobao.csp.sentinel.dashboard.domain.cluster.request.ClusterClientModifyRequest; -import com.taobao.csp.sentinel.dashboard.domain.cluster.state.ClusterClientStateVO; -import com.taobao.csp.sentinel.dashboard.domain.cluster.request.ClusterServerModifyRequest; -import com.taobao.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStatePairVO; -import com.taobao.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStateVO; -import com.taobao.csp.sentinel.dashboard.domain.cluster.config.ClusterClientConfig; -import com.taobao.csp.sentinel.dashboard.domain.cluster.config.ServerFlowConfig; -import com.taobao.csp.sentinel.dashboard.domain.cluster.config.ServerTransportConfig; -import com.taobao.csp.sentinel.dashboard.util.AsyncUtils; -import com.taobao.csp.sentinel.dashboard.util.ClusterEntityUtils; -import com.taobao.csp.sentinel.dashboard.util.MachineUtils; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterGroupEntity; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterClientModifyRequest; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterClientStateVO; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStatePairVO; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStateVO; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ClusterClientConfig; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerFlowConfig; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerTransportConfig; +import com.alibaba.csp.sentinel.dashboard.util.MachineUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/util/AsyncUtils.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/util/AsyncUtils.java similarity index 97% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/util/AsyncUtils.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/util/AsyncUtils.java index 20563b6189..9881cdaced 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/util/AsyncUtils.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/util/AsyncUtils.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.util; +package com.alibaba.csp.sentinel.dashboard.util; import java.util.List; import java.util.Objects; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/util/ClusterEntityUtils.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/util/ClusterEntityUtils.java similarity index 89% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/util/ClusterEntityUtils.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/util/ClusterEntityUtils.java index 06f291ba8a..f36bf2965f 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/util/ClusterEntityUtils.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/util/ClusterEntityUtils.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.util; +package com.alibaba.csp.sentinel.dashboard.util; import java.util.ArrayList; import java.util.HashMap; @@ -23,13 +23,13 @@ import com.alibaba.csp.sentinel.cluster.ClusterStateManager; import com.alibaba.csp.sentinel.util.StringUtil; -import com.taobao.csp.sentinel.dashboard.domain.cluster.ClusterGroupEntity; -import com.taobao.csp.sentinel.dashboard.domain.cluster.ConnectionGroupVO; -import com.taobao.csp.sentinel.dashboard.domain.cluster.state.AppClusterClientStateWrapVO; -import com.taobao.csp.sentinel.dashboard.domain.cluster.state.AppClusterServerStateWrapVO; -import com.taobao.csp.sentinel.dashboard.domain.cluster.state.ClusterClientStateVO; -import com.taobao.csp.sentinel.dashboard.domain.cluster.state.ClusterServerStateVO; -import com.taobao.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStatePairVO; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterGroupEntity; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.ConnectionGroupVO; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.state.AppClusterClientStateWrapVO; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.state.AppClusterServerStateWrapVO; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterClientStateVO; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterServerStateVO; +import com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStatePairVO; /** * @author Eric Zhao diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/util/MachineUtils.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/util/MachineUtils.java similarity index 95% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/util/MachineUtils.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/util/MachineUtils.java index b7836287c9..1bfbe91d72 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/util/MachineUtils.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/util/MachineUtils.java @@ -13,15 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.util; +package com.alibaba.csp.sentinel.dashboard.util; import java.util.Optional; +import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo; import com.alibaba.csp.sentinel.util.StringUtil; import com.alibaba.csp.sentinel.util.function.Tuple2; -import com.taobao.csp.sentinel.dashboard.discovery.MachineInfo; - /** * @author Eric Zhao */ diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/util/RuleUtils.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/util/RuleUtils.java similarity index 98% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/util/RuleUtils.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/util/RuleUtils.java index e38586c54e..8761c048aa 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/util/RuleUtils.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/util/RuleUtils.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.util; +package com.alibaba.csp.sentinel.dashboard.util; import java.util.List; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/util/VersionUtils.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/util/VersionUtils.java similarity index 94% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/util/VersionUtils.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/util/VersionUtils.java index 3316c32813..ad7b626541 100644 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/util/VersionUtils.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/util/VersionUtils.java @@ -13,13 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.util; +package com.alibaba.csp.sentinel.dashboard.util; import java.util.Optional; import com.alibaba.csp.sentinel.util.StringUtil; -import com.taobao.csp.sentinel.dashboard.datasource.entity.SentinelVersion; +import com.alibaba.csp.sentinel.dashboard.datasource.entity.SentinelVersion; /** * Util class for parsing version. diff --git a/sentinel-dashboard/src/test/java/com/taobao/csp/sentinel/dashboard/discovery/AppInfoTest.java b/sentinel-dashboard/src/test/java/com/alibaba/csp/sentinel/dashboard/discovery/AppInfoTest.java similarity index 96% rename from sentinel-dashboard/src/test/java/com/taobao/csp/sentinel/dashboard/discovery/AppInfoTest.java rename to sentinel-dashboard/src/test/java/com/alibaba/csp/sentinel/dashboard/discovery/AppInfoTest.java index a92c8053a2..34539f265f 100644 --- a/sentinel-dashboard/src/test/java/com/taobao/csp/sentinel/dashboard/discovery/AppInfoTest.java +++ b/sentinel-dashboard/src/test/java/com/alibaba/csp/sentinel/dashboard/discovery/AppInfoTest.java @@ -1,4 +1,4 @@ -package com.taobao.csp.sentinel.dashboard.discovery; +package com.alibaba.csp.sentinel.dashboard.discovery; import java.util.ConcurrentModificationException; import java.util.Set; diff --git a/sentinel-dashboard/src/test/java/com/taobao/csp/sentinel/dashboard/rule/nacos/FlowRuleNacosProvider.java b/sentinel-dashboard/src/test/java/com/alibaba/csp/sentinel/dashboard/rule/nacos/FlowRuleNacosProvider.java similarity index 88% rename from sentinel-dashboard/src/test/java/com/taobao/csp/sentinel/dashboard/rule/nacos/FlowRuleNacosProvider.java rename to sentinel-dashboard/src/test/java/com/alibaba/csp/sentinel/dashboard/rule/nacos/FlowRuleNacosProvider.java index 0c5fe27ecb..3f9a3fd39f 100644 --- a/sentinel-dashboard/src/test/java/com/taobao/csp/sentinel/dashboard/rule/nacos/FlowRuleNacosProvider.java +++ b/sentinel-dashboard/src/test/java/com/alibaba/csp/sentinel/dashboard/rule/nacos/FlowRuleNacosProvider.java @@ -13,17 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.rule.nacos; +package com.alibaba.csp.sentinel.dashboard.rule.nacos; import java.util.ArrayList; import java.util.List; +import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity; +import com.alibaba.csp.sentinel.dashboard.rule.DynamicRuleProvider; import com.alibaba.csp.sentinel.datasource.Converter; import com.alibaba.csp.sentinel.util.StringUtil; import com.alibaba.nacos.api.config.ConfigService; -import com.taobao.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity; -import com.taobao.csp.sentinel.dashboard.rule.DynamicRuleProvider; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; diff --git a/sentinel-dashboard/src/test/java/com/taobao/csp/sentinel/dashboard/rule/nacos/FlowRuleNacosPublisher.java b/sentinel-dashboard/src/test/java/com/alibaba/csp/sentinel/dashboard/rule/nacos/FlowRuleNacosPublisher.java similarity index 88% rename from sentinel-dashboard/src/test/java/com/taobao/csp/sentinel/dashboard/rule/nacos/FlowRuleNacosPublisher.java rename to sentinel-dashboard/src/test/java/com/alibaba/csp/sentinel/dashboard/rule/nacos/FlowRuleNacosPublisher.java index 4b3bf84079..8297dec299 100644 --- a/sentinel-dashboard/src/test/java/com/taobao/csp/sentinel/dashboard/rule/nacos/FlowRuleNacosPublisher.java +++ b/sentinel-dashboard/src/test/java/com/alibaba/csp/sentinel/dashboard/rule/nacos/FlowRuleNacosPublisher.java @@ -13,16 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.rule.nacos; +package com.alibaba.csp.sentinel.dashboard.rule.nacos; import java.util.List; +import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity; +import com.alibaba.csp.sentinel.dashboard.rule.DynamicRulePublisher; import com.alibaba.csp.sentinel.datasource.Converter; import com.alibaba.csp.sentinel.util.AssertUtil; import com.alibaba.nacos.api.config.ConfigService; -import com.taobao.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity; -import com.taobao.csp.sentinel.dashboard.rule.DynamicRulePublisher; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; diff --git a/sentinel-dashboard/src/test/java/com/taobao/csp/sentinel/dashboard/rule/nacos/NacosConfig.java b/sentinel-dashboard/src/test/java/com/alibaba/csp/sentinel/dashboard/rule/nacos/NacosConfig.java similarity index 91% rename from sentinel-dashboard/src/test/java/com/taobao/csp/sentinel/dashboard/rule/nacos/NacosConfig.java rename to sentinel-dashboard/src/test/java/com/alibaba/csp/sentinel/dashboard/rule/nacos/NacosConfig.java index 146b869742..7cdc980dd0 100644 --- a/sentinel-dashboard/src/test/java/com/taobao/csp/sentinel/dashboard/rule/nacos/NacosConfig.java +++ b/sentinel-dashboard/src/test/java/com/alibaba/csp/sentinel/dashboard/rule/nacos/NacosConfig.java @@ -13,16 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.rule.nacos; +package com.alibaba.csp.sentinel.dashboard.rule.nacos; import java.util.List; +import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity; import com.alibaba.csp.sentinel.datasource.Converter; import com.alibaba.fastjson.JSON; import com.alibaba.nacos.api.config.ConfigFactory; import com.alibaba.nacos.api.config.ConfigService; -import com.taobao.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/sentinel-dashboard/src/test/java/com/taobao/csp/sentinel/dashboard/rule/nacos/NacosConfigUtil.java b/sentinel-dashboard/src/test/java/com/alibaba/csp/sentinel/dashboard/rule/nacos/NacosConfigUtil.java similarity index 96% rename from sentinel-dashboard/src/test/java/com/taobao/csp/sentinel/dashboard/rule/nacos/NacosConfigUtil.java rename to sentinel-dashboard/src/test/java/com/alibaba/csp/sentinel/dashboard/rule/nacos/NacosConfigUtil.java index 312d63fdb0..0c666313a1 100644 --- a/sentinel-dashboard/src/test/java/com/taobao/csp/sentinel/dashboard/rule/nacos/NacosConfigUtil.java +++ b/sentinel-dashboard/src/test/java/com/alibaba/csp/sentinel/dashboard/rule/nacos/NacosConfigUtil.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.rule.nacos; +package com.alibaba.csp.sentinel.dashboard.rule.nacos; /** * @author Eric Zhao From b760ad96156cb097ae6e7f15f6ec4bdd206f2d46 Mon Sep 17 00:00:00 2001 From: giegie Date: Mon, 21 Jan 2019 16:22:17 +0800 Subject: [PATCH 18/39] Add logback dependency in sentinel-demo-nacos-datasource to avoid log ClassNotFoundException thrown by Nacos client (#438) --- sentinel-demo/sentinel-demo-nacos-datasource/pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sentinel-demo/sentinel-demo-nacos-datasource/pom.xml b/sentinel-demo/sentinel-demo-nacos-datasource/pom.xml index 6478cc54d0..66f22d4f15 100644 --- a/sentinel-demo/sentinel-demo-nacos-datasource/pom.xml +++ b/sentinel-demo/sentinel-demo-nacos-datasource/pom.xml @@ -29,6 +29,12 @@ com.alibaba fastjson + + + ch.qos.logback + logback-classic + 1.2.3 + From 1f8236a9e86dc35330dc015962cbba55db34c5f4 Mon Sep 17 00:00:00 2001 From: Eric Zhao Date: Mon, 21 Jan 2019 19:18:20 +0800 Subject: [PATCH 19/39] dashboard: update WebConfig and improve token server list page Signed-off-by: Eric Zhao --- .../com/alibaba/csp/sentinel/dashboard/config/WebConfig.java | 5 ++--- .../webapp/resources/app/views/cluster_app_server_list.html | 5 +++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/config/WebConfig.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/config/WebConfig.java index d507d584da..d0e2965917 100755 --- a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/config/WebConfig.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/config/WebConfig.java @@ -26,13 +26,13 @@ import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; /** * @author leyou */ @Configuration -public class WebConfig extends WebMvcConfigurerAdapter { +public class WebConfig implements WebMvcConfigurer { private final Logger logger = LoggerFactory.getLogger(WebConfig.class); @@ -62,5 +62,4 @@ public FilterRegistrationBean sentinelFilterRegistration() { return registration; } - } diff --git a/sentinel-dashboard/src/main/webapp/resources/app/views/cluster_app_server_list.html b/sentinel-dashboard/src/main/webapp/resources/app/views/cluster_app_server_list.html index e69153b74a..53e4e38874 100644 --- a/sentinel-dashboard/src/main/webapp/resources/app/views/cluster_app_server_list.html +++ b/sentinel-dashboard/src/main/webapp/resources/app/views/cluster_app_server_list.html @@ -43,6 +43,7 @@ Server ID Port 命名空间集合 + 运行模式 总连接数 QPS 总览 操作 @@ -55,6 +56,10 @@ {{serverVO.state.namespaceSetStr}} + + 嵌入模式 + 独立模式 + {{serverVO.connectedCount}} From 9e62b688fd78eb42666c951d9addbd8bc6a7c619 Mon Sep 17 00:00:00 2001 From: Eric Zhao Date: Fri, 25 Jan 2019 13:48:31 +0800 Subject: [PATCH 20/39] Add catch throwable logic in ClusterStateManager to detect fatal error when loading SPI Signed-off-by: Eric Zhao --- .../sentinel/cluster/ClusterStateManager.java | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/cluster/ClusterStateManager.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/cluster/ClusterStateManager.java index 3c15f87df4..068bb88d6b 100644 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/cluster/ClusterStateManager.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/cluster/ClusterStateManager.java @@ -224,17 +224,22 @@ private static boolean applyStateInternal(Integer state) { if (state == mode) { return true; } - switch (state) { - case CLUSTER_CLIENT: - return setToClient(); - case CLUSTER_SERVER: - return setToServer(); - case CLUSTER_NOT_STARTED: - setStop(); - return true; - default: - RecordLog.warn("[ClusterStateManager] Ignoring unknown cluster state: " + state); - return false; + try { + switch (state) { + case CLUSTER_CLIENT: + return setToClient(); + case CLUSTER_SERVER: + return setToServer(); + case CLUSTER_NOT_STARTED: + setStop(); + return true; + default: + RecordLog.warn("[ClusterStateManager] Ignoring unknown cluster state: " + state); + return false; + } + } catch (Throwable t) { + RecordLog.warn("[ClusterStateManager] Fatal error when applying state: " + state, t); + return false; } } From b1238f87b276ca8ca161e49105017b7006660ffc Mon Sep 17 00:00:00 2001 From: Eric Zhao Date: Fri, 25 Jan 2019 16:34:17 +0800 Subject: [PATCH 21/39] Fixes #453: Support tracing exception count for specific entry or context in Tracer Signed-off-by: Eric Zhao --- .../java/com/alibaba/csp/sentinel/Tracer.java | 71 ++++++++++++++++++- 1 file changed, 68 insertions(+), 3 deletions(-) diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/Tracer.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/Tracer.java index 3971ee10cb..8a5cdea7eb 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/Tracer.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/Tracer.java @@ -22,18 +22,30 @@ import com.alibaba.csp.sentinel.slots.block.BlockException; /** - * This class is used to record other exception except block exception. + * This class is used to record other exceptions except block exception. * * @author jialiang.linjl + * @author Eric Zhao */ public final class Tracer { + /** + * Trace provided {@link Throwable} and increment exception count to entry in current context. + * + * @param e exception to record + */ public static void trace(Throwable e) { trace(e, 1); } + /** + * Trace provided {@link Throwable} and add exception count to entry in current context. + * + * @param e exception to record + * @param count exception count to add + */ public static void trace(Throwable e, int count) { - if (e instanceof BlockException) { + if (e == null || e instanceof BlockException) { return; } @@ -43,6 +55,58 @@ public static void trace(Throwable e, int count) { } DefaultNode curNode = (DefaultNode)context.getCurNode(); + traceExceptionToNode(e, count, curNode); + } + + /** + * Trace provided {@link Throwable} and add exception count to current entry in provided context. + * + * @param e exception to record + * @param count exception count to add + * @since 1.4.2 + */ + public static void traceContext(Throwable e, int count, Context context) { + if (e == null || e instanceof BlockException) { + return; + } + if (context == null) { + return; + } + + DefaultNode curNode = (DefaultNode)context.getCurNode(); + traceExceptionToNode(e, count, curNode); + } + + /** + * Trace provided {@link Throwable} and increment exception count to provided entry. + * + * @param e exception to record + * @since 1.4.2 + */ + public static void traceEntry(Throwable e, Entry entry) { + traceEntry(e, 1, entry); + } + + /** + * Trace provided {@link Throwable} and add exception count to provided entry. + * + * @param e exception to record + * @param count exception count to add + * @since 1.4.2 + */ + public static void traceEntry(Throwable e, int count, Entry entry) { + if (e == null || e instanceof BlockException) { + return; + } + if (entry == null || entry.getCurNode() == null) { + return; + } + + DefaultNode curNode = (DefaultNode)entry.getCurNode(); + traceExceptionToNode(e, count, curNode); + } + + private static void traceExceptionToNode(Throwable t, int count, DefaultNode curNode) { if (curNode == null) { return; } @@ -52,7 +116,8 @@ public static void trace(Throwable e, int count) { if (clusterNode == null) { return; } - clusterNode.trace(e, count); + clusterNode.trace(t, count); } + private Tracer() {} } From c1c93674194826698fb836a22c24a7cf90d29a1f Mon Sep 17 00:00:00 2001 From: Eric Zhao Date: Fri, 25 Jan 2019 16:59:54 +0800 Subject: [PATCH 22/39] Remove slf4j dependency in sentinel-annotation-aspectj Signed-off-by: Eric Zhao --- .../sentinel-annotation-aspectj/pom.xml | 6 ------ .../aspectj/AbstractSentinelAspectSupport.java | 11 +++++------ 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/sentinel-extension/sentinel-annotation-aspectj/pom.xml b/sentinel-extension/sentinel-annotation-aspectj/pom.xml index e43d641355..1de4c6008c 100644 --- a/sentinel-extension/sentinel-annotation-aspectj/pom.xml +++ b/sentinel-extension/sentinel-annotation-aspectj/pom.xml @@ -32,12 +32,6 @@ aspectjweaver ${aspectj.version} - - - org.slf4j - slf4j-api - 1.7.25 - \ No newline at end of file diff --git a/sentinel-extension/sentinel-annotation-aspectj/src/main/java/com/alibaba/csp/sentinel/annotation/aspectj/AbstractSentinelAspectSupport.java b/sentinel-extension/sentinel-annotation-aspectj/src/main/java/com/alibaba/csp/sentinel/annotation/aspectj/AbstractSentinelAspectSupport.java index 5aacf89e69..fe72e4f74a 100644 --- a/sentinel-extension/sentinel-annotation-aspectj/src/main/java/com/alibaba/csp/sentinel/annotation/aspectj/AbstractSentinelAspectSupport.java +++ b/sentinel-extension/sentinel-annotation-aspectj/src/main/java/com/alibaba/csp/sentinel/annotation/aspectj/AbstractSentinelAspectSupport.java @@ -16,6 +16,7 @@ package com.alibaba.csp.sentinel.annotation.aspectj; import com.alibaba.csp.sentinel.annotation.SentinelResource; +import com.alibaba.csp.sentinel.log.RecordLog; import com.alibaba.csp.sentinel.slots.block.BlockException; import com.alibaba.csp.sentinel.slots.block.degrade.DegradeException; import com.alibaba.csp.sentinel.util.MethodUtil; @@ -23,8 +24,6 @@ import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.reflect.MethodSignature; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.lang.reflect.Method; import java.lang.reflect.Modifier; @@ -32,11 +31,11 @@ /** * Some common functions for Sentinel annotation aspect. + * + * @author Eric Zhao */ public abstract class AbstractSentinelAspectSupport { - private final Logger logger = LoggerFactory.getLogger(this.getClass()); - protected String getResourceName(String resourceName, Method method) { // If resource name is present in annotation, use this value. if (StringUtil.isNotBlank(resourceName)) { @@ -154,7 +153,7 @@ private Method findMethod(boolean mustStatic, Class clazz, String name, Class && returnType.isAssignableFrom(method.getReturnType()) && Arrays.equals(parameterTypes, method.getParameterTypes())) { - logger.info("Resolved method [{}] in class [{}]", name, clazz.getCanonicalName()); + RecordLog.info("Resolved method [{0}] in class [{1}]", name, clazz.getCanonicalName()); return method; } } @@ -164,7 +163,7 @@ private Method findMethod(boolean mustStatic, Class clazz, String name, Class return findMethod(mustStatic, superClass, name, returnType, parameterTypes); } else { String methodType = mustStatic ? " static" : ""; - logger.error("Cannot find{} method [{}] in class [{}] with parameters {}", + RecordLog.warn("Cannot find{0} method [{1}] in class [{2}] with parameters {3}", methodType, name, clazz.getCanonicalName(), Arrays.toString(parameterTypes)); return null; } From 9e257f1f93e4e014bbdfa51b60115c836601ea81 Mon Sep 17 00:00:00 2001 From: mjaow Date: Sat, 26 Jan 2019 10:44:10 +0800 Subject: [PATCH 23/39] Fix error value type and rename variable in EntranceNode class (#457) --- .../alibaba/csp/sentinel/node/EntranceNode.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/EntranceNode.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/EntranceNode.java index e379daf424..518e448241 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/EntranceNode.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/EntranceNode.java @@ -44,18 +44,18 @@ public EntranceNode(ResourceWrapper id, ClusterNode clusterNode) { @Override public long avgRt() { - long rt = 0; + long total = 0; long totalQps = 0; for (Node node : getChildList()) { - rt += node.avgRt() * node.passQps(); + total += node.avgRt() * node.passQps(); totalQps += node.passQps(); } - return rt / (totalQps == 0 ? 1 : totalQps); + return total / (totalQps == 0 ? 1 : totalQps); } @Override public long blockQps() { - int blockQps = 0; + long blockQps = 0; for (Node node : getChildList()) { blockQps += node.blockQps(); } @@ -82,7 +82,7 @@ public int curThreadNum() { @Override public long totalQps() { - int r = 0; + long r = 0; for (Node node : getChildList()) { r += node.totalQps(); } @@ -91,7 +91,7 @@ public long totalQps() { @Override public long successQps() { - int r = 0; + long r = 0; for (Node node : getChildList()) { r += node.successQps(); } @@ -100,7 +100,7 @@ public long successQps() { @Override public long passQps() { - int r = 0; + long r = 0; for (Node node : getChildList()) { r += node.passQps(); } From 75eb58da6ab27dd00dc651003a9aa363a00769b0 Mon Sep 17 00:00:00 2001 From: mjaow Date: Mon, 28 Jan 2019 11:44:31 +0800 Subject: [PATCH 24/39] Remove duplicate comment in WarmUpController (#464) --- .../slots/block/flow/controller/WarmUpController.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/controller/WarmUpController.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/controller/WarmUpController.java index 2cc99a1536..9e4097f972 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/controller/WarmUpController.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/controller/WarmUpController.java @@ -34,11 +34,6 @@ * * That’s why we need “warm up”. * - * Sentinel’s “warm up” implementation is based on Guava's algorithm. However, - * unlike Guava's scenario, which is a “leaky bucket”, and is mainly used to - * adjust the request interval, Sentinel is more focus on controlling the count - * of incoming requests per second without calculating its interval. - * * Sentinel's "warm-up" implementation is based on the guava-based algorithm. * However, Guava’s implementation focus on adjusting the request interval, in * other words, a Leaky bucket. Sentinel pays more attention to controlling the From 80594086cef21f99fed5a2d4b397405c7aed331f Mon Sep 17 00:00:00 2001 From: mjaow Date: Mon, 28 Jan 2019 14:23:41 +0800 Subject: [PATCH 25/39] Fix zero-count divide overflow bug in RateLimiterController (#461) --- .../flow/controller/RateLimiterController.java | 15 +++++++++++++++ .../controller/RateLimiterControllerTest.java | 12 +++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/controller/RateLimiterController.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/controller/RateLimiterController.java index ab08619fad..099ff1af73 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/controller/RateLimiterController.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/controller/RateLimiterController.java @@ -44,6 +44,21 @@ public boolean canPass(Node node, int acquireCount) { @Override public boolean canPass(Node node, int acquireCount, boolean prioritized) { + /* + 1. Pass when acquire count is less or equal than 0 + 2. Reject when count is less or equal than 0. + Otherwise,the costTime will be max of long and waitTime will overflow in some cases. + This will lead to pass of following request.It's dangerous!!! + */ + + if (acquireCount <= 0) { + return true; + } + + if (count <= 0) { + return false; + } + long currentTime = TimeUtil.currentTimeMillis(); // Calculate the interval between every two requests. long costTime = Math.round(1.0 * (acquireCount) / count * 1000); diff --git a/sentinel-core/src/test/java/com/alibaba/csp/sentinel/slots/block/flow/controller/RateLimiterControllerTest.java b/sentinel-core/src/test/java/com/alibaba/csp/sentinel/slots/block/flow/controller/RateLimiterControllerTest.java index 282c5bf29d..adec543bbd 100755 --- a/sentinel-core/src/test/java/com/alibaba/csp/sentinel/slots/block/flow/controller/RateLimiterControllerTest.java +++ b/sentinel-core/src/test/java/com/alibaba/csp/sentinel/slots/block/flow/controller/RateLimiterControllerTest.java @@ -15,6 +15,7 @@ */ package com.alibaba.csp.sentinel.slots.block.flow.controller; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; @@ -25,7 +26,6 @@ import com.alibaba.csp.sentinel.util.TimeUtil; import com.alibaba.csp.sentinel.node.Node; -import com.alibaba.csp.sentinel.slots.block.flow.controller.RateLimiterController; /** * @author jialiang.linjl @@ -85,4 +85,14 @@ public void run() { } + @Test + public void testPaceController_zeroattack() throws InterruptedException { + RateLimiterController paceController = new RateLimiterController(500, 0d); + Node node = mock(Node.class); + + for (int i = 0; i < 2; i++) { + assertFalse(paceController.canPass(node, 1)); + assertTrue(paceController.canPass(node, 0)); + } + } } From 43643397dd755a30235cd13ddd04d262706f6be2 Mon Sep 17 00:00:00 2001 From: luoxiangnan Date: Mon, 28 Jan 2019 15:47:39 +0800 Subject: [PATCH 26/39] HashMap init optimize when adding new ClusterNode to cluster node map (#465) - reuse old map size to avoid rearrange and rehash the map --- .../csp/sentinel/slots/clusterbuilder/ClusterBuilderSlot.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/clusterbuilder/ClusterBuilderSlot.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/clusterbuilder/ClusterBuilderSlot.java index f6faea0fc1..31ef6b65f0 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/clusterbuilder/ClusterBuilderSlot.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/clusterbuilder/ClusterBuilderSlot.java @@ -81,7 +81,7 @@ public void entry(Context context, ResourceWrapper resourceWrapper, DefaultNode if (clusterNode == null) { // Create the cluster node. clusterNode = Env.nodeBuilder.buildClusterNode(); - HashMap newMap = new HashMap(16); + HashMap newMap = new HashMap(Math.max(clusterNodeMap.size(), 16)); newMap.putAll(clusterNodeMap); newMap.put(node.getId(), clusterNode); From 146dee96ef3f61abb25d2030482fcbe5229ef3ef Mon Sep 17 00:00:00 2001 From: Eric Zhao Date: Mon, 28 Jan 2019 16:22:34 +0800 Subject: [PATCH 27/39] Code and javadoc refinement Signed-off-by: Eric Zhao --- .../cluster/ClusterErrorMessages.java | 2 +- .../flow/rule/ClusterFlowRuleManager.java | 1 + .../controller/RateLimiterController.java | 11 +++----- .../flow/controller/WarmUpController.java | 25 +++++++++++-------- .../csp/sentinel/slots/logger/LogSlot.java | 4 +-- .../alibaba/csp/sentinel/util/PidUtil.java | 6 +++++ 6 files changed, 28 insertions(+), 21 deletions(-) diff --git a/sentinel-cluster/sentinel-cluster-common-default/src/main/java/com/alibaba/csp/sentinel/cluster/ClusterErrorMessages.java b/sentinel-cluster/sentinel-cluster-common-default/src/main/java/com/alibaba/csp/sentinel/cluster/ClusterErrorMessages.java index 3e6ad41690..6b4020a1e4 100644 --- a/sentinel-cluster/sentinel-cluster-common-default/src/main/java/com/alibaba/csp/sentinel/cluster/ClusterErrorMessages.java +++ b/sentinel-cluster/sentinel-cluster-common-default/src/main/java/com/alibaba/csp/sentinel/cluster/ClusterErrorMessages.java @@ -25,7 +25,7 @@ public final class ClusterErrorMessages { public static final String UNEXPECTED_STATUS = "unexpected status"; public static final String TOO_MANY_REQUESTS = "too many requests (client side)"; public static final String REQUEST_TIME_OUT = "request time out"; - public static final String CLIENT_NOT_READY = "client not ready (not running or initializing)"; + public static final String CLIENT_NOT_READY = "client not ready"; public static final String NO_RULES_IN_SERVER = "no rules in token server"; private ClusterErrorMessages() {} diff --git a/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/flow/rule/ClusterFlowRuleManager.java b/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/flow/rule/ClusterFlowRuleManager.java index 13bee56ae2..85464bb48a 100644 --- a/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/flow/rule/ClusterFlowRuleManager.java +++ b/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/flow/rule/ClusterFlowRuleManager.java @@ -104,6 +104,7 @@ private static void initDefaultProperty() { } public static void setPropertySupplier(Function>> propertySupplier) { + AssertUtil.notNull(propertySupplier, "flow rule property supplier cannot be null"); ClusterFlowRuleManager.propertySupplier = propertySupplier; } diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/controller/RateLimiterController.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/controller/RateLimiterController.java index 099ff1af73..ca07b028cf 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/controller/RateLimiterController.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/controller/RateLimiterController.java @@ -44,17 +44,12 @@ public boolean canPass(Node node, int acquireCount) { @Override public boolean canPass(Node node, int acquireCount, boolean prioritized) { - /* - 1. Pass when acquire count is less or equal than 0 - 2. Reject when count is less or equal than 0. - Otherwise,the costTime will be max of long and waitTime will overflow in some cases. - This will lead to pass of following request.It's dangerous!!! - */ - + // Pass when acquire count is less or equal than 0. if (acquireCount <= 0) { return true; } - + // Reject when count is less or equal than 0. + // Otherwise,the costTime will be max of long and waitTime will overflow in some cases. if (count <= 0) { return false; } diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/controller/WarmUpController.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/controller/WarmUpController.java index 9e4097f972..a4f69318bc 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/controller/WarmUpController.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/controller/WarmUpController.java @@ -27,32 +27,37 @@ * rate-based, which means that we need to translate rate to QPS. *

    * + *

    * Requests arriving at the pulse may drag down long idle systems even though it * has a much larger handling capability in stable period. It usually happens in - * scenarios that require extra time for initialization, e.g. DB - * establishes a connection; connects to a remote service, and so on. - * - * That’s why we need “warm up”. - * - * Sentinel's "warm-up" implementation is based on the guava-based algorithm. - * However, Guava’s implementation focus on adjusting the request interval, in - * other words, a Leaky bucket. Sentinel pays more attention to controlling the - * count of incoming requests per second without calculating its interval, it is - * more like a “Token bucket.” + * scenarios that require extra time for initialization, e.g. DB establishes a connection, + * connects to a remote service, and so on. That’s why we need “warm up”. + *

    * + *

    + * Sentinel's "warm-up" implementation is based on the Guava's algorithm. + * However, Guava’s implementation focuses on adjusting the request interval, + * which is similar to leaky bucket. Sentinel pays more attention to + * controlling the count of incoming requests per second without calculating its interval, + * which resembles token bucket algorithm. + *

    * + *

    * The remaining tokens in the bucket is used to measure the system utility. * Suppose a system can handle b requests per second. Every second b tokens will * be added into the bucket until the bucket is full. And when system processes * a request, it takes a token from the bucket. The more tokens left in the * bucket, the lower the utilization of the system; when the token in the token * bucket is above a certain threshold, we call it in a "saturation" state. + *

    * + *

    * Base on Guava’s theory, there is a linear equation we can write this in the * form y = m * x + b where y (a.k.a y(x)), or qps(q)), is our expected QPS * given a saturated period (e.g. 3 minutes in), m is the rate of change from * our cold (minimum) rate to our stable (maximum) rate, x (or q) is the * occupied token. + *

    * * @author jialiang.linjl */ diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/logger/LogSlot.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/logger/LogSlot.java index b43cd32c64..802690a9ab 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/logger/LogSlot.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/logger/LogSlot.java @@ -38,7 +38,7 @@ public void entry(Context context, ResourceWrapper resourceWrapper, DefaultNode context.getOrigin(), count); throw e; } catch (Throwable e) { - RecordLog.info("Entry exception", e); + RecordLog.warn("Unexpected entry exception", e); } } @@ -48,7 +48,7 @@ public void exit(Context context, ResourceWrapper resourceWrapper, int count, Ob try { fireExit(context, resourceWrapper, count, args); } catch (Throwable e) { - RecordLog.info("Entry exit exception", e); + RecordLog.warn("Unexpected entry exit exception", e); } } } diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/util/PidUtil.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/util/PidUtil.java index 31efefb7e1..720aa2859a 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/util/PidUtil.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/util/PidUtil.java @@ -22,7 +22,13 @@ */ public final class PidUtil { + /** + * Resolve and get current process ID. + * + * @return current process ID + */ public static int getPid() { + // Note: this will trigger local host resolve, which might be slow. String name = ManagementFactory.getRuntimeMXBean().getName(); return Integer.parseInt(name.split("@")[0]); } From abad82aa01cd2ce3ecc631774c76ca310a673015 Mon Sep 17 00:00:00 2001 From: Eric Zhao Date: Mon, 28 Jan 2019 17:23:33 +0800 Subject: [PATCH 28/39] Update dependency version of fastjson and jacoco-maven-plugin Signed-off-by: Eric Zhao --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 0ab0869f45..e607a910b1 100755 --- a/pom.xml +++ b/pom.xml @@ -41,7 +41,7 @@ - 1.2.54 + 1.2.55 4.12 @@ -58,7 +58,7 @@ 3.0.1 2.8.2 1.6 - 0.8.2 + 0.8.3 3.1.0 From 45b4f97ba73a625f65ec4431eed59beb95f5bcfc Mon Sep 17 00:00:00 2001 From: Andres Almiray Date: Tue, 29 Jan 2019 02:57:38 +0100 Subject: [PATCH 29/39] Make build faster by reducing fixed waiting time in tests (#449) - Apply awaitility to core tests - Cache maven local repo in Travis --- .travis.yml | 6 +- pom.xml | 13 ++++ sentinel-core/pom.xml | 20 +++++- .../sentinel/AsyncEntryIntegrationTest.java | 68 +++++++++++++------ .../base/metric/MetricsLeapArrayTest.java | 2 +- .../flow/FlowPartialIntegrationTest.java | 50 +++++--------- .../flow/controller/WarmUpControllerTest.java | 3 +- .../slots/logger/EagleEyeLogUtilTest.java | 30 ++++++-- .../sentinel-datasource-redis/pom.xml | 5 +- .../SentinelModeRedisDataSourceTest.java | 21 ++++-- .../redis/StandaloneRedisDataSourceTest.java | 19 ++++-- .../sentinel-datasource-zookeeper/pom.xml | 5 +- .../zookeeper/ZookeeperDataSourceTest.java | 13 +++- 13 files changed, 171 insertions(+), 84 deletions(-) diff --git a/.travis.yml b/.travis.yml index 59e27d024c..5c3f897009 100755 --- a/.travis.yml +++ b/.travis.yml @@ -13,4 +13,8 @@ matrix: - env: BUILD_JDK=ORACLE_JDK_11 after_success: - - bash <(curl -s https://codecov.io/bash) \ No newline at end of file + - bash <(curl -s https://codecov.io/bash) + +cache: + directories: + - $HOME/.m2/ diff --git a/pom.xml b/pom.xml index e607a910b1..6fcba990af 100755 --- a/pom.xml +++ b/pom.xml @@ -46,6 +46,7 @@ 4.12 2.21.0 + 3.1.5 UTF-8 @@ -155,6 +156,18 @@ ${mockito.version} test + + org.awaitility + awaitility + ${awaitility.version} + test + + + org.hamcrest + java-hamcrest + 2.0.0.0 + test + diff --git a/sentinel-core/pom.xml b/sentinel-core/pom.xml index b544fa65bc..1d674c5d41 100755 --- a/sentinel-core/pom.xml +++ b/sentinel-core/pom.xml @@ -16,12 +16,28 @@ junit junit - test + + + org.hamcrest + hamcrest-core + + + org.hamcrest + hamcrest-libray + + org.mockito mockito-core - test + + + org.awaitility + awaitility + + + org.hamcrest + java-hamcrest diff --git a/sentinel-core/src/test/java/com/alibaba/csp/sentinel/AsyncEntryIntegrationTest.java b/sentinel-core/src/test/java/com/alibaba/csp/sentinel/AsyncEntryIntegrationTest.java index 3b984421bd..7da7b39f35 100644 --- a/sentinel-core/src/test/java/com/alibaba/csp/sentinel/AsyncEntryIntegrationTest.java +++ b/sentinel-core/src/test/java/com/alibaba/csp/sentinel/AsyncEntryIntegrationTest.java @@ -15,22 +15,24 @@ */ package com.alibaba.csp.sentinel; -import java.util.Set; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; - import com.alibaba.csp.sentinel.context.ContextTestUtil; import com.alibaba.csp.sentinel.context.ContextUtil; import com.alibaba.csp.sentinel.node.DefaultNode; import com.alibaba.csp.sentinel.node.Node; import com.alibaba.csp.sentinel.slots.block.BlockException; - +import org.hamcrest.CoreMatchers; import org.junit.After; import org.junit.Before; import org.junit.Test; -import static org.junit.Assert.*; +import java.util.Set; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; + +import static org.awaitility.Awaitility.await; +import static org.junit.Assert.fail; /** * Integration test for asynchronous entry, including common scenarios. @@ -175,37 +177,59 @@ public void testAsyncEntryUnderSyncEntry() throws Exception { ContextUtil.exit(); } - TimeUnit.SECONDS.sleep(15); + // we keep the original timeout of 15 seconds although the test should + // complete in less than 6 seconds + await().timeout(15, TimeUnit.SECONDS) + .until(new Callable() { + @Override + public DefaultNode call() throws Exception { + return queryInvocationTree(false); + } + }, CoreMatchers.notNullValue()); - testInvocationTreeCorrect(); + queryInvocationTree(true); } - private void testInvocationTreeCorrect() { + private DefaultNode queryInvocationTree(boolean check) { DefaultNode root = Constants.ROOT; - DefaultNode entranceNode = shouldHasChildFor(root, contextName); - DefaultNode testTopNode = shouldHasChildFor(entranceNode, "test-top"); - DefaultNode testAsyncNode = shouldHasChildFor(testTopNode, "test-async"); - shouldHasChildFor(testTopNode, "test-sync"); - shouldHasChildFor(testAsyncNode, "test-sync-in-async"); - DefaultNode anotherAsyncInAsyncNode = shouldHasChildFor(testAsyncNode, "test-another-async"); - shouldHasChildFor(anotherAsyncInAsyncNode, "test-another-in-async"); + DefaultNode entranceNode = shouldHasChildFor(root, contextName, check); + DefaultNode testTopNode = shouldHasChildFor(entranceNode, "test-top", check); + DefaultNode testAsyncNode = shouldHasChildFor(testTopNode, "test-async", check); + shouldHasChildFor(testTopNode, "test-sync", check); + shouldHasChildFor(testAsyncNode, "test-sync-in-async", check); + DefaultNode anotherAsyncInAsyncNode = shouldHasChildFor(testAsyncNode, "test-another-async", check); + return shouldHasChildFor(anotherAsyncInAsyncNode, "test-another-in-async", check); } - private DefaultNode shouldHasChildFor(DefaultNode root, String resourceName) { + private DefaultNode shouldHasChildFor(DefaultNode root, String resourceName, boolean check) { + if (root == null) { + if (check) { + fail("Root node should not be empty"); + } else { + return null; + } + } Set nodeSet = root.getChildList(); if (nodeSet == null || nodeSet.isEmpty()) { - fail("Child nodes should not be empty: " + root.getId().getName()); + if (check) { + fail("Child nodes should not be empty: " + root.getId().getName()); + } else { + return null; + } } for (Node node : nodeSet) { if (node instanceof DefaultNode) { - DefaultNode dn = (DefaultNode)node; + DefaultNode dn = (DefaultNode) node; if (dn.getId().getName().equals(resourceName)) { return dn; } } } - fail(String.format("The given node <%s> does not have child for resource <%s>", - root.getId().getName(), resourceName)); + + if (check) { + fail(String.format("The given node <%s> does not have child for resource <%s>", + root.getId().getName(), resourceName)); + } return null; } diff --git a/sentinel-core/src/test/java/com/alibaba/csp/sentinel/base/metric/MetricsLeapArrayTest.java b/sentinel-core/src/test/java/com/alibaba/csp/sentinel/base/metric/MetricsLeapArrayTest.java index 99e7e263a9..f6f2b29a2b 100755 --- a/sentinel-core/src/test/java/com/alibaba/csp/sentinel/base/metric/MetricsLeapArrayTest.java +++ b/sentinel-core/src/test/java/com/alibaba/csp/sentinel/base/metric/MetricsLeapArrayTest.java @@ -203,7 +203,7 @@ public void testListWindowsNewBucket() throws Exception { windowWraps.add(leapArray.currentWindow(time)); windowWraps.add(leapArray.currentWindow(time + windowLengthInMs)); - Thread.sleep(intervalInSec * 1000 + windowLengthInMs * 3); + Thread.sleep(intervalInMs + windowLengthInMs * 3); List> list = leapArray.list(); for (WindowWrap wrap : list) { diff --git a/sentinel-core/src/test/java/com/alibaba/csp/sentinel/slots/block/flow/FlowPartialIntegrationTest.java b/sentinel-core/src/test/java/com/alibaba/csp/sentinel/slots/block/flow/FlowPartialIntegrationTest.java index 5da8f30b52..a507b5aff6 100755 --- a/sentinel-core/src/test/java/com/alibaba/csp/sentinel/slots/block/flow/FlowPartialIntegrationTest.java +++ b/sentinel-core/src/test/java/com/alibaba/csp/sentinel/slots/block/flow/FlowPartialIntegrationTest.java @@ -16,6 +16,7 @@ package com.alibaba.csp.sentinel.slots.block.flow; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.util.Arrays; import java.util.Collections; @@ -57,8 +58,8 @@ public void testQPSGrade() { } } - @Test - public void testThreadGrade() throws InterruptedException { + @Test(expected = BlockException.class) + public void testThreadGrade() throws InterruptedException, BlockException { FlowRule flowRule = new FlowRule(); flowRule.setResource("testThreadGrade"); flowRule.setGrade(RuleConstant.FLOW_GRADE_THREAD); @@ -73,17 +74,15 @@ public void run() { Entry e = null; try { e = SphU.entry("testThreadGrade"); - assertTrue(true); synchronized (sequence) { System.out.println("notify up"); sequence.notify(); } - Thread.sleep(1000); + Thread.sleep(100); } catch (BlockException e1) { - assertTrue(false); + fail("Should had failed"); } catch (InterruptedException e1) { - assertTrue(false); - e1.printStackTrace(); + fail("Should had failed"); } e.exit(); } @@ -92,20 +91,14 @@ public void run() { Thread thread = new Thread(runnable); thread.start(); - Entry e = null; synchronized (sequence) { System.out.println("sleep"); sequence.wait(); System.out.println("wake up"); } - try { - e = SphU.entry("testThreadGrade"); - assertTrue(false); - } catch (BlockException e1) { - assertTrue(true); - } - System.out.println("done"); + SphU.entry("testThreadGrade"); + System.out.println("done"); } @Test @@ -129,10 +122,9 @@ public void testOriginFlowRule() { Entry e = null; try { e = SphU.entry("testOriginFlowRule"); - assertTrue(false); + fail("Should had failed"); } catch (BlockException e1) { e1.printStackTrace(); - assertTrue(true); } assertTrue(e == null); @@ -142,10 +134,8 @@ public void testOriginFlowRule() { e = null; try { e = SphU.entry("testOriginFlowRule"); - assertTrue(true); } catch (BlockException e1) { - e1.printStackTrace(); - assertTrue(false); + fail("Should had failed"); } e.exit(); @@ -165,17 +155,14 @@ public void testFlowRule_other() { Entry e = null; try { e = SphU.entry("testOther"); - assertTrue(true); } catch (BlockException e1) { - e1.printStackTrace(); - assertTrue(false); + e1.printStackTrace();fail("Should had failed"); } if (e != null) { - assertTrue(true); e.exit(); } else { - assertTrue(false); + fail("Should had failed"); } } @@ -194,10 +181,9 @@ public void testStrategy() { Entry e = null; try { e = SphU.entry("testStrategy"); - assertTrue(false); + fail("Should had failed"); } catch (BlockException e1) { e1.printStackTrace(); - assertTrue(true); } ContextUtil.exit(); @@ -215,10 +201,9 @@ public void testStrategy() { ContextUtil.enter("entry1"); try { e = SphU.entry("testStrategy"); - assertTrue(true); } catch (BlockException e1) { e1.printStackTrace(); - assertTrue(false); + fail("Should had failed"); } e.exit(); ContextUtil.exit(); @@ -238,10 +223,9 @@ public void testStrategy_chain() { ContextUtil.enter("entry1"); try { e = SphU.entry("entry2"); - assertTrue(false); + fail("Should had failed"); } catch (BlockException e1) { e1.printStackTrace(); - assertTrue(true); } ContextUtil.exit(); @@ -250,13 +234,11 @@ public void testStrategy_chain() { ContextUtil.enter("entry3"); try { e = SphU.entry("entry2"); - assertTrue(true); } catch (BlockException e1) { - assertTrue(false); + fail("Should had failed"); } e.exit(); ContextUtil.exit(); - } } diff --git a/sentinel-core/src/test/java/com/alibaba/csp/sentinel/slots/block/flow/controller/WarmUpControllerTest.java b/sentinel-core/src/test/java/com/alibaba/csp/sentinel/slots/block/flow/controller/WarmUpControllerTest.java index 7482f489b8..6e9f7d0854 100755 --- a/sentinel-core/src/test/java/com/alibaba/csp/sentinel/slots/block/flow/controller/WarmUpControllerTest.java +++ b/sentinel-core/src/test/java/com/alibaba/csp/sentinel/slots/block/flow/controller/WarmUpControllerTest.java @@ -23,7 +23,6 @@ import org.junit.Test; import com.alibaba.csp.sentinel.node.Node; -import com.alibaba.csp.sentinel.slots.block.flow.controller.WarmUpController; /** * @author jialiang.linjl @@ -49,7 +48,7 @@ public void testWarmUp() throws InterruptedException { when(node.previousPassQps()).thenReturn(10L); for (int i = 0; i < 100; i++) { - Thread.sleep(1000); + Thread.sleep(100); warmupController.canPass(node, 1); } when(node.passQps()).thenReturn(8L); diff --git a/sentinel-core/src/test/java/com/alibaba/csp/sentinel/slots/logger/EagleEyeLogUtilTest.java b/sentinel-core/src/test/java/com/alibaba/csp/sentinel/slots/logger/EagleEyeLogUtilTest.java index b2b769d0bf..fd9e9f4318 100644 --- a/sentinel-core/src/test/java/com/alibaba/csp/sentinel/slots/logger/EagleEyeLogUtilTest.java +++ b/sentinel-core/src/test/java/com/alibaba/csp/sentinel/slots/logger/EagleEyeLogUtilTest.java @@ -1,12 +1,18 @@ package com.alibaba.csp.sentinel.slots.logger; import java.io.File; +import java.util.concurrent.Callable; +import java.util.concurrent.TimeUnit; import com.alibaba.csp.sentinel.log.LogBase; import com.alibaba.csp.sentinel.log.RecordLog; +import org.hamcrest.CoreMatchers; +import org.hamcrest.Matchers; +import org.hamcrest.io.FileMatchers; import org.junit.Test; +import static org.awaitility.Awaitility.await; import static org.junit.Assert.*; /** @@ -17,9 +23,15 @@ public class EagleEyeLogUtilTest { @Test public void testWriteLog() throws Exception { EagleEyeLogUtil.log("resourceName", "BlockException", "app1", "origin", 1); - Thread.sleep(1100); - String file = RecordLog.getLogBaseDir() + EagleEyeLogUtil.FILE_NAME; - assertTrue(new File(file).exists()); + + final File file = new File(RecordLog.getLogBaseDir() + EagleEyeLogUtil.FILE_NAME); + await().timeout(2, TimeUnit.SECONDS) + .until(new Callable() { + @Override + public File call() throws Exception { + return file; + } + }, FileMatchers.anExistingFile()); } @Test @@ -29,8 +41,14 @@ public void testChangeLogBase() throws Exception { System.setProperty(LogBase.LOG_DIR, newLogBase); EagleEyeLogUtil.log("resourceName", "BlockException", "app1", "origin", 1); - Thread.sleep(1100); - String file = RecordLog.getLogBaseDir() + EagleEyeLogUtil.FILE_NAME; - assertTrue(new File(file).exists()); + + final File file = new File(RecordLog.getLogBaseDir() + EagleEyeLogUtil.FILE_NAME); + await().timeout(2, TimeUnit.SECONDS) + .until(new Callable() { + @Override + public File call() throws Exception { + return file; + } + }, FileMatchers.anExistingFile()); } } \ No newline at end of file diff --git a/sentinel-extension/sentinel-datasource-redis/pom.xml b/sentinel-extension/sentinel-datasource-redis/pom.xml index 34b720f76f..3fbd5d5648 100644 --- a/sentinel-extension/sentinel-datasource-redis/pom.xml +++ b/sentinel-extension/sentinel-datasource-redis/pom.xml @@ -34,7 +34,10 @@ junit junit - test + + + org.awaitility + awaitility com.alibaba diff --git a/sentinel-extension/sentinel-datasource-redis/src/test/java/com/alibaba/csp/sentinel/datasource/redis/SentinelModeRedisDataSourceTest.java b/sentinel-extension/sentinel-datasource-redis/src/test/java/com/alibaba/csp/sentinel/datasource/redis/SentinelModeRedisDataSourceTest.java index 054e7dc3fb..ee43287ad9 100644 --- a/sentinel-extension/sentinel-datasource-redis/src/test/java/com/alibaba/csp/sentinel/datasource/redis/SentinelModeRedisDataSourceTest.java +++ b/sentinel-extension/sentinel-datasource-redis/src/test/java/com/alibaba/csp/sentinel/datasource/redis/SentinelModeRedisDataSourceTest.java @@ -27,10 +27,15 @@ import io.lettuce.core.RedisClient; import io.lettuce.core.RedisURI; import io.lettuce.core.api.sync.RedisCommands; +import org.hamcrest.Matchers; import org.junit.*; import java.util.List; import java.util.Random; +import java.util.concurrent.Callable; +import java.util.concurrent.TimeUnit; + +import static org.awaitility.Awaitility.await; /** * Redis redisSentinel mode test cases for {@link RedisDataSource}. @@ -79,14 +84,16 @@ public void testConnectToSentinelAndPubMsgSuccess() { subCommands.set(ruleKey, flowRulesJson); subCommands.publish(channel, flowRulesJson); subCommands.exec(); - try { - Thread.sleep(2000); - } catch (InterruptedException e) { - e.printStackTrace(); - } + + await().timeout(2, TimeUnit.SECONDS) + .until(new Callable>() { + @Override + public List call() throws Exception { + return FlowRuleManager.getRules(); + } + }, Matchers.hasSize(1)); + List rules = FlowRuleManager.getRules(); - Assert.assertEquals(1, rules.size()); - rules = FlowRuleManager.getRules(); Assert.assertEquals(rules.get(0).getMaxQueueingTimeMs(), maxQueueingTimeMs); String value = subCommands.get(ruleKey); List flowRulesValuesInRedis = buildFlowConfigParser().convert(value); diff --git a/sentinel-extension/sentinel-datasource-redis/src/test/java/com/alibaba/csp/sentinel/datasource/redis/StandaloneRedisDataSourceTest.java b/sentinel-extension/sentinel-datasource-redis/src/test/java/com/alibaba/csp/sentinel/datasource/redis/StandaloneRedisDataSourceTest.java index 408d0bc443..9a9ba63d27 100644 --- a/sentinel-extension/sentinel-datasource-redis/src/test/java/com/alibaba/csp/sentinel/datasource/redis/StandaloneRedisDataSourceTest.java +++ b/sentinel-extension/sentinel-datasource-redis/src/test/java/com/alibaba/csp/sentinel/datasource/redis/StandaloneRedisDataSourceTest.java @@ -31,6 +31,7 @@ import io.lettuce.core.api.sync.RedisCommands; import io.lettuce.core.pubsub.StatefulRedisPubSubConnection; import io.lettuce.core.pubsub.api.sync.RedisPubSubCommands; +import org.hamcrest.Matchers; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -39,6 +40,10 @@ import java.io.IOException; import java.util.List; import java.util.Random; +import java.util.concurrent.Callable; +import java.util.concurrent.TimeUnit; + +import static org.awaitility.Awaitility.await; /** * Redis stand-alone mode test cases for {@link RedisDataSource}. @@ -92,11 +97,15 @@ public void testPubMsgAndReceiveSuccess() { subCommands.set(ruleKey, flowRules); subCommands.publish(channel, flowRules); subCommands.exec(); - try { - Thread.sleep(2000); - } catch (InterruptedException e) { - e.printStackTrace(); - } + + await().timeout(2, TimeUnit.SECONDS) + .until(new Callable>() { + @Override + public List call() throws Exception { + return FlowRuleManager.getRules(); + } + }, Matchers.hasSize(1)); + rules = FlowRuleManager.getRules(); Assert.assertEquals(rules.get(0).getMaxQueueingTimeMs(), maxQueueingTimeMs); String value = subCommands.get(ruleKey); diff --git a/sentinel-extension/sentinel-datasource-zookeeper/pom.xml b/sentinel-extension/sentinel-datasource-zookeeper/pom.xml index e4a247271f..343d97568e 100644 --- a/sentinel-extension/sentinel-datasource-zookeeper/pom.xml +++ b/sentinel-extension/sentinel-datasource-zookeeper/pom.xml @@ -46,7 +46,10 @@ junit junit - test + + + org.awaitility + awaitility org.apache.curator diff --git a/sentinel-extension/sentinel-datasource-zookeeper/src/test/java/com/alibaba/csp/sentinel/datasource/zookeeper/ZookeeperDataSourceTest.java b/sentinel-extension/sentinel-datasource-zookeeper/src/test/java/com/alibaba/csp/sentinel/datasource/zookeeper/ZookeeperDataSourceTest.java index 2425b7c275..14a8d767dd 100644 --- a/sentinel-extension/sentinel-datasource-zookeeper/src/test/java/com/alibaba/csp/sentinel/datasource/zookeeper/ZookeeperDataSourceTest.java +++ b/sentinel-extension/sentinel-datasource-zookeeper/src/test/java/com/alibaba/csp/sentinel/datasource/zookeeper/ZookeeperDataSourceTest.java @@ -2,6 +2,8 @@ import java.util.Collections; import java.util.List; +import java.util.concurrent.Callable; +import java.util.concurrent.TimeUnit; import com.alibaba.csp.sentinel.datasource.Converter; import com.alibaba.csp.sentinel.datasource.ReadableDataSource; @@ -19,6 +21,7 @@ import org.apache.zookeeper.data.Stat; import org.junit.Test; +import static org.awaitility.Awaitility.await; import static org.junit.Assert.*; /** @@ -68,10 +71,16 @@ private void publishThenTestFor(CuratorFramework zkClient, String path, String r String ruleString = JSON.toJSONString(Collections.singletonList(rule)); zkClient.setData().forPath(path, ruleString.getBytes()); - Thread.sleep(5000); + await().timeout(5, TimeUnit.SECONDS) + .until(new Callable() { + @Override + public Boolean call() throws Exception { + List rules = FlowRuleManager.getRules(); + return rules != null && !rules.isEmpty(); + } + }); List rules = FlowRuleManager.getRules(); - assertTrue(rules != null && !rules.isEmpty()); boolean exists = false; for (FlowRule r : rules) { if (resourceName.equals(r.getResource())) { From da5e1cd4d08c9d067d983d0beb0b07ca3aef11b1 Mon Sep 17 00:00:00 2001 From: cdfive <31885791+cdfive@users.noreply.github.com> Date: Tue, 29 Jan 2019 10:07:17 +0800 Subject: [PATCH 30/39] Add some unit test for StatisticNode, ClusterNode and DefaultNodeBuilder class (#423) --- .../csp/sentinel/node/ClusterNodeTest.java | 149 +++++++++++++ .../sentinel/node/DefaultNodeBuilderTest.java | 85 ++++++++ .../csp/sentinel/node/StatisticNodeTest.java | 202 ++++++++++++++++++ 3 files changed, 436 insertions(+) create mode 100644 sentinel-core/src/test/java/com/alibaba/csp/sentinel/node/ClusterNodeTest.java create mode 100644 sentinel-core/src/test/java/com/alibaba/csp/sentinel/node/DefaultNodeBuilderTest.java create mode 100644 sentinel-core/src/test/java/com/alibaba/csp/sentinel/node/StatisticNodeTest.java diff --git a/sentinel-core/src/test/java/com/alibaba/csp/sentinel/node/ClusterNodeTest.java b/sentinel-core/src/test/java/com/alibaba/csp/sentinel/node/ClusterNodeTest.java new file mode 100644 index 0000000000..e762a09f27 --- /dev/null +++ b/sentinel-core/src/test/java/com/alibaba/csp/sentinel/node/ClusterNodeTest.java @@ -0,0 +1,149 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * 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.alibaba.csp.sentinel.node; + +import com.alibaba.csp.sentinel.slots.block.flow.FlowException; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Random; +import java.util.Set; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +import static org.junit.Assert.*; + +/** + * Test cases for {@link ClusterNode}. + * + * @author cdfive + * @date 2019-01-11 + */ +public class ClusterNodeTest { + + @Test + public void testGetOrCreateOriginNodeSingleThread() { + ClusterNode clusterNode = new ClusterNode(); + + String origin1 = "origin1"; + Node originNode1 = clusterNode.getOrCreateOriginNode(origin1); + assertNotNull(originNode1); + assertEquals(1, clusterNode.getOriginCountMap().size()); + + String origin2 = "origin2"; + Node originNode2 = clusterNode.getOrCreateOriginNode(origin2); + assertNotNull(originNode2); + assertEquals(2, clusterNode.getOriginCountMap().size()); + assertNotSame(originNode1, originNode2); + + // test same origin, no StatisticNode added into the originCountMap + Node tmpOriginNode = clusterNode.getOrCreateOriginNode(origin1); + assertEquals(2, clusterNode.getOriginCountMap().size()); + assertSame(tmpOriginNode, originNode1); + + assertTrue(clusterNode.getOriginCountMap().containsKey(origin1)); + assertTrue(clusterNode.getOriginCountMap().containsKey(origin2)); + } + + @Test + public void testGetOrCreateOriginNodeMultiThread() { + // note: in junit4, repeat execute a test method is not very convenient + // for simple, here use a loop instead + // https://stackoverflow.com/questions/1492856/easy-way-of-running-the-same-junit-test-over-and-over + // in junit5, use @RepeatedTest(10) + int testTimes = 10;// execute 10 times, test will have chance to failed, if remove the lock in ClusterNode + for (int times = 0; times < testTimes; times++) { + final ClusterNode clusterNode = new ClusterNode(); + + // store all distinct nodes by calling ClusterNode#getOrCreateOriginNode + final Set createdNodes = new HashSet(); + + final Random random = new Random(); + + // 10 threads, 3 origins, 20 tasks(in total, calling 20 times of ClusterNode#getOrCreateOriginNode concurrently) + final ExecutorService es = Executors.newFixedThreadPool(10); + final List origins = Arrays.asList("origin1", "origin2", "origin3"); + int taskCount = 20; + + List> tasks = new ArrayList>(taskCount); + for (int i = 0; i < taskCount; i++) { + tasks.add(new Callable() { + @Override + public Object call() throws Exception { + // one task call one times of ClusterNode#getOrCreateOriginNode + Node node = clusterNode.getOrCreateOriginNode(origins.get(random.nextInt(origins.size()))); + // add the result node to the createdNodes set + // node: since HashSet is non-threadsafe, synchronized the ClusterNodeTest.class + synchronized (ClusterNodeTest.class) { + createdNodes.add(node); + } + return null; + } + }); + } + + try { + es.invokeAll(tasks); + } catch (InterruptedException e) { + e.printStackTrace(); + } + es.shutdown(); + + // origins.size() origins, the same count as the originCountMap + assertEquals(origins.size(), clusterNode.getOriginCountMap().size()); + + // not use `assertEquals(origins.size(), createdNodes.size());`, but a compare judgement for debug + if (origins.size() != createdNodes.size()) { + // for debug, we can add a breakpoint here to see the detail info of createdNodes, if remove the lock in ClusterNode + fail("originCountMap's size should " + origins.size() + ", but actual " + createdNodes.size()); + } + + // verify originCountMap's key + for (String origin : origins) { + assertTrue(clusterNode.getOriginCountMap().containsKey(origin)); + } + } + } + + + @Test + public void testTrace() { + ClusterNode clusterNode = new ClusterNode(); + + Exception exception = new RuntimeException("test"); + + // test count<=0, no exceptionQps added + clusterNode.trace(exception, 0); + clusterNode.trace(exception, -1); + assertEquals(0, clusterNode.exceptionQps()); + assertEquals(0, clusterNode.totalException()); + + // test count=1, not BlockException, 1 exceptionQps added + clusterNode.trace(exception, 1); + assertEquals(1, clusterNode.exceptionQps()); + assertEquals(1, clusterNode.totalException()); + + // test count=1, BlockException, no exceptionQps added + FlowException flowException = new FlowException("flow"); + clusterNode.trace(flowException, 1); + assertEquals(1, clusterNode.exceptionQps()); + assertEquals(1, clusterNode.totalException()); + } +} diff --git a/sentinel-core/src/test/java/com/alibaba/csp/sentinel/node/DefaultNodeBuilderTest.java b/sentinel-core/src/test/java/com/alibaba/csp/sentinel/node/DefaultNodeBuilderTest.java new file mode 100644 index 0000000000..19eb927bdb --- /dev/null +++ b/sentinel-core/src/test/java/com/alibaba/csp/sentinel/node/DefaultNodeBuilderTest.java @@ -0,0 +1,85 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * 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.alibaba.csp.sentinel.node; + +import com.alibaba.csp.sentinel.EntryType; +import com.alibaba.csp.sentinel.slotchain.ResourceWrapper; +import com.alibaba.csp.sentinel.slotchain.StringResourceWrapper; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Test cases for {@link DefaultNodeBuilder}. + * + * @author cdfive + * @date 2019-01-15 + */ +public class DefaultNodeBuilderTest { + + @Test + public void testBuildTreeNode() { + DefaultNodeBuilder builder = new DefaultNodeBuilder(); + + ResourceWrapper id = new StringResourceWrapper("resA", EntryType.IN); + ClusterNode clusterNode = new ClusterNode(); + DefaultNode defaultNode = builder.buildTreeNode(id, clusterNode); + + assertNotNull(defaultNode); + assertEquals(id, defaultNode.getId()); + assertEquals(clusterNode, defaultNode.getClusterNode()); + + // verify each call returns a different instance + DefaultNode defaultNode2 = builder.buildTreeNode(id, clusterNode); + assertNotNull(defaultNode2); + assertNotSame(defaultNode, defaultNode2); + // now DefaultNode#equals(Object) is not implemented, they are not equal + assertNotEquals(defaultNode, defaultNode2); + } + + @Test + public void testBuildTreeNode_NullClusterNode() { + DefaultNodeBuilder builder = new DefaultNodeBuilder(); + + ResourceWrapper id = new StringResourceWrapper("resA", EntryType.IN); + DefaultNode defaultNode = builder.buildTreeNode(id, null); + + assertNotNull(defaultNode); + assertEquals(id, defaultNode.getId()); + assertEquals(null, defaultNode.getClusterNode()); + + // verify each call returns a different instance + DefaultNode defaultNode2 = builder.buildTreeNode(id, null); + assertNotNull(defaultNode2); + assertNotSame(defaultNode, defaultNode2); + // now DefaultNode#equals(Object) is not implemented, they are not equal + assertNotEquals(defaultNode, defaultNode2); + } + + @Test + public void testBuildClusterNode() { + DefaultNodeBuilder builder = new DefaultNodeBuilder(); + ClusterNode clusterNode = builder.buildClusterNode(); + assertNotNull(clusterNode); + + // verify each call returns a different instance + ClusterNode clusterNode2 = builder.buildClusterNode(); + assertNotNull(clusterNode2); + assertNotSame(clusterNode, clusterNode2); + // as new a ClusterNode instance in DefaultNodeBuilder#buildClusterNode(), they are not equal + assertNotEquals(clusterNode, clusterNode2); + } +} diff --git a/sentinel-core/src/test/java/com/alibaba/csp/sentinel/node/StatisticNodeTest.java b/sentinel-core/src/test/java/com/alibaba/csp/sentinel/node/StatisticNodeTest.java new file mode 100644 index 0000000000..674985f893 --- /dev/null +++ b/sentinel-core/src/test/java/com/alibaba/csp/sentinel/node/StatisticNodeTest.java @@ -0,0 +1,202 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * 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.alibaba.csp.sentinel.node; + +import com.alibaba.csp.sentinel.Constants; +import com.alibaba.csp.sentinel.util.TimeUtil; +import org.junit.Test; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Random; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * Test cases for {@link StatisticNode}. + * + * @author cdfive + * @date 2019-01-08 + */ +public class StatisticNodeTest { + + private static final String LOG_PREFIX = "[StatisticNodeTest]"; + + private static final SimpleDateFormat SDF = new SimpleDateFormat("yyyy-HH-dd HH:mm:ss"); + + private static final Random RANDOM = new Random(); + + private static final int THREAD_COUNT = 20; + + /** + * A simple test for statistic threadNum and qps by using StatisticNode + * + *

    + * 20 threads, 30 tasks, every task execute 10 times of bizMethod + * one bizMthod execute within 1 second, and within 0.5 second interval to exceute next bizMthod + * so that the total time cost will be within 1 minute + *

    + * + *

    + * Print the statistic info of StatisticNode and verify some results + *

    + */ + @Test + public void testStatisticThreadNumAndQps() { + long testStartTime = TimeUtil.currentTimeMillis(); + + int taskCount = 30; + int taskBizExecuteCount = 10; + + StatisticNode node = new StatisticNode(); + + ExecutorService bizEs = Executors.newFixedThreadPool(THREAD_COUNT); + ExecutorService tickEs = Executors.newSingleThreadExecutor(); + + tickEs.submit(new TickTask(node)); + + List bizTasks = new ArrayList(taskBizExecuteCount); + for (int i = 0; i < taskCount; i++) { + bizTasks.add(new BizTask(node, taskBizExecuteCount)); + } + try { + bizEs.invokeAll(bizTasks); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + log("===================================================="); + log("all biz task done, waiting 3 second to exit"); + sleep(3000); + + bizEs.shutdown(); + tickEs.shutdown(); + + // now no biz method execute, so there is no curThreadNum,passQps,successQps + assertEquals(0, node.curThreadNum()); + assertEquals(0, node.passQps()); + assertEquals(0, node.successQps()); + + // note: total time cost should be controlled within 1 minute, + // as the node.totalRequest() holding statistics of recent 60 seconds + int totalRequest = taskCount * taskBizExecuteCount; + // verify totalRequest + assertEquals(totalRequest, node.totalRequest()); + // as all execute success, totalRequest should equal to totalSuccess + assertEquals(totalRequest, node.totalSuccess()); + + // now there are no data in time span, so the minRT should be equals to TIME_DROP_VALVE + assertEquals(node.minRt(), Constants.TIME_DROP_VALVE); + + log("===================================================="); + log("testStatisticThreadNumAndQps done, cost " + (TimeUtil.currentTimeMillis() - testStartTime) + "ms"); + } + + private static class BizTask implements Callable { + + private StatisticNode node; + + private Integer bizExecuteCount; + + public BizTask(StatisticNode node, Integer bizExecuteCount) { + this.node = node; + this.bizExecuteCount = bizExecuteCount; + } + + @Override + public Object call() throws Exception { + while (true) { + node.increaseThreadNum(); + node.addPassRequest(1); + + long startTime = TimeUtil.currentTimeMillis(); + bizMethod(); + + node.decreaseThreadNum(); + + // decrease one ThreadNum, so curThreadNum should less than THREAD_COUNT + assertTrue(node.curThreadNum() < THREAD_COUNT); + + long rt = TimeUtil.currentTimeMillis() - startTime; + node.addRtAndSuccess(rt, 1); + + // wait random 0.5 second for simulate method call interval, + // otherwise the curThreadNum will always be THREAD_COUNT at the beginning + sleep(RANDOM.nextInt(500)); + + bizExecuteCount--; + if (bizExecuteCount <= 0) { + break; + } + } + + return null; + } + } + + private static void bizMethod() { + // simulate biz method call in random 1 second + sleep(RANDOM.nextInt(1000)); + } + + private static class TickTask implements Runnable { + + private StatisticNode node; + + public TickTask(StatisticNode node) { + this.node = node; + } + + @Override + public void run() { + while (true) { + // print statistic info every 1 second + sleep(1000); + + // the curThreadNum should not greater than THREAD_COUNT + assertTrue(node.curThreadNum() <= THREAD_COUNT); + + logNode(node); + } + } + } + + private static void sleep(long ms) { + try { + TimeUnit.MILLISECONDS.sleep(ms); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + private static void logNode(StatisticNode node) { + log(SDF.format(new Date()) + " curThreadNum=" + node.curThreadNum() + ",passQps=" + node.passQps() + + ",successQps=" + node.successQps() + ",maxSuccessQps=" + node.maxSuccessQps() + + ",totalRequest=" + node.totalRequest() + ",totalSuccess=" + node.totalSuccess() + + ",avgRt=" + node.avgRt() + ",minRt=" + node.minRt()); + } + + private static void log(Object obj) { + System.out.println(LOG_PREFIX + obj); + } +} From 71556341238a67cabf7733757602eb3fd0933811 Mon Sep 17 00:00:00 2001 From: Eric Zhao Date: Tue, 29 Jan 2019 10:28:07 +0800 Subject: [PATCH 31/39] Refinement for test cases Signed-off-by: Eric Zhao --- .../csp/sentinel/node/ClusterNodeTest.java | 37 +++++++++++-------- .../sentinel/node/DefaultNodeBuilderTest.java | 5 +-- .../csp/sentinel/node/StatisticNodeTest.java | 3 +- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/sentinel-core/src/test/java/com/alibaba/csp/sentinel/node/ClusterNodeTest.java b/sentinel-core/src/test/java/com/alibaba/csp/sentinel/node/ClusterNodeTest.java index e762a09f27..258ac76df6 100644 --- a/sentinel-core/src/test/java/com/alibaba/csp/sentinel/node/ClusterNodeTest.java +++ b/sentinel-core/src/test/java/com/alibaba/csp/sentinel/node/ClusterNodeTest.java @@ -16,15 +16,18 @@ package com.alibaba.csp.sentinel.node; import com.alibaba.csp.sentinel.slots.block.flow.FlowException; + import org.junit.Test; import java.util.ArrayList; import java.util.Arrays; -import java.util.HashSet; +import java.util.Collections; import java.util.List; import java.util.Random; import java.util.Set; import java.util.concurrent.Callable; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -34,7 +37,6 @@ * Test cases for {@link ClusterNode}. * * @author cdfive - * @date 2019-01-11 */ public class ClusterNodeTest { @@ -64,23 +66,28 @@ public void testGetOrCreateOriginNodeSingleThread() { @Test public void testGetOrCreateOriginNodeMultiThread() { - // note: in junit4, repeat execute a test method is not very convenient + // Note: in JUnit 4, repeat execute a test method is not very convenient // for simple, here use a loop instead // https://stackoverflow.com/questions/1492856/easy-way-of-running-the-same-junit-test-over-and-over - // in junit5, use @RepeatedTest(10) - int testTimes = 10;// execute 10 times, test will have chance to failed, if remove the lock in ClusterNode + // in JUnit 5, use @RepeatedTest(10) + + // execute 10 times, test will have chance to failed, if remove the lock in ClusterNode + final int testTimes = 10; + for (int times = 0; times < testTimes; times++) { final ClusterNode clusterNode = new ClusterNode(); - // store all distinct nodes by calling ClusterNode#getOrCreateOriginNode - final Set createdNodes = new HashSet(); + // Store all distinct nodes by calling ClusterNode#getOrCreateOriginNode. + // Here we need a thread-safe concurrent set (created from ConcurrentHashMap). + final Set createdNodes = Collections.newSetFromMap(new ConcurrentHashMap()); final Random random = new Random(); - // 10 threads, 3 origins, 20 tasks(in total, calling 20 times of ClusterNode#getOrCreateOriginNode concurrently) + // 10 threads, 3 origins, 20 tasks (calling 20 times of ClusterNode#getOrCreateOriginNode concurrently) final ExecutorService es = Executors.newFixedThreadPool(10); final List origins = Arrays.asList("origin1", "origin2", "origin3"); int taskCount = 20; + final CountDownLatch latch = new CountDownLatch(taskCount); List> tasks = new ArrayList>(taskCount); for (int i = 0; i < taskCount; i++) { @@ -90,10 +97,9 @@ public Object call() throws Exception { // one task call one times of ClusterNode#getOrCreateOriginNode Node node = clusterNode.getOrCreateOriginNode(origins.get(random.nextInt(origins.size()))); // add the result node to the createdNodes set - // node: since HashSet is non-threadsafe, synchronized the ClusterNodeTest.class - synchronized (ClusterNodeTest.class) { - createdNodes.add(node); - } + createdNodes.add(node); + latch.countDown(); + return null; } }); @@ -101,6 +107,7 @@ public Object call() throws Exception { try { es.invokeAll(tasks); + latch.await(); } catch (InterruptedException e) { e.printStackTrace(); } @@ -111,7 +118,8 @@ public Object call() throws Exception { // not use `assertEquals(origins.size(), createdNodes.size());`, but a compare judgement for debug if (origins.size() != createdNodes.size()) { - // for debug, we can add a breakpoint here to see the detail info of createdNodes, if remove the lock in ClusterNode + // for debug, we can add a breakpoint here to see the detail info of createdNodes, + // if we removed the lock in ClusterNode fail("originCountMap's size should " + origins.size() + ", but actual " + createdNodes.size()); } @@ -122,9 +130,8 @@ public Object call() throws Exception { } } - @Test - public void testTrace() { + public void testTraceException() { ClusterNode clusterNode = new ClusterNode(); Exception exception = new RuntimeException("test"); diff --git a/sentinel-core/src/test/java/com/alibaba/csp/sentinel/node/DefaultNodeBuilderTest.java b/sentinel-core/src/test/java/com/alibaba/csp/sentinel/node/DefaultNodeBuilderTest.java index 19eb927bdb..56872fa305 100644 --- a/sentinel-core/src/test/java/com/alibaba/csp/sentinel/node/DefaultNodeBuilderTest.java +++ b/sentinel-core/src/test/java/com/alibaba/csp/sentinel/node/DefaultNodeBuilderTest.java @@ -26,7 +26,6 @@ * Test cases for {@link DefaultNodeBuilder}. * * @author cdfive - * @date 2019-01-15 */ public class DefaultNodeBuilderTest { @@ -51,7 +50,7 @@ public void testBuildTreeNode() { } @Test - public void testBuildTreeNode_NullClusterNode() { + public void testBuildTreeNodeNullClusterNode() { DefaultNodeBuilder builder = new DefaultNodeBuilder(); ResourceWrapper id = new StringResourceWrapper("resA", EntryType.IN); @@ -59,7 +58,7 @@ public void testBuildTreeNode_NullClusterNode() { assertNotNull(defaultNode); assertEquals(id, defaultNode.getId()); - assertEquals(null, defaultNode.getClusterNode()); + assertNull(defaultNode.getClusterNode()); // verify each call returns a different instance DefaultNode defaultNode2 = builder.buildTreeNode(id, null); diff --git a/sentinel-core/src/test/java/com/alibaba/csp/sentinel/node/StatisticNodeTest.java b/sentinel-core/src/test/java/com/alibaba/csp/sentinel/node/StatisticNodeTest.java index 674985f893..4520b5bc4e 100644 --- a/sentinel-core/src/test/java/com/alibaba/csp/sentinel/node/StatisticNodeTest.java +++ b/sentinel-core/src/test/java/com/alibaba/csp/sentinel/node/StatisticNodeTest.java @@ -36,7 +36,6 @@ * Test cases for {@link StatisticNode}. * * @author cdfive - * @date 2019-01-08 */ public class StatisticNodeTest { @@ -53,7 +52,7 @@ public class StatisticNodeTest { * *

    * 20 threads, 30 tasks, every task execute 10 times of bizMethod - * one bizMthod execute within 1 second, and within 0.5 second interval to exceute next bizMthod + * one bizMethod execute within 1 second, and within 0.5 second interval to exceute next bizMthod * so that the total time cost will be within 1 minute *

    * From cb2cb2f2fe40d575752b1e35168fc1aabf3ae4ca Mon Sep 17 00:00:00 2001 From: Eric Zhao Date: Wed, 30 Jan 2019 09:37:13 +0800 Subject: [PATCH 32/39] Add back thread count metric type support for parameter flow control Signed-off-by: Eric Zhao --- .../sentinel-parameter-flow-control/README.md | 2 +- .../ParamFlowStatisticSlotCallbackInit.java | 3 + .../block/flow/param/ParamFlowChecker.java | 10 +- .../slots/block/flow/param/ParamFlowRule.java | 2 +- .../block/flow/param/ParamFlowRuleUtil.java | 2 +- .../block/flow/param/ParameterMetric.java | 143 ++++++++++++++++++ .../ParamFlowStatisticEntryCallback.java | 1 + .../ParamFlowStatisticExitCallback.java | 40 +++++ .../flow/param/ParamFlowCheckerTest.java | 52 +++++++ .../flow/param/ParamFlowRuleManagerTest.java | 2 +- .../block/flow/param/ParamFlowSlotTest.java | 1 + .../block/flow/param/ParameterMetricTest.java | 109 +++++++++++++ 12 files changed, 362 insertions(+), 5 deletions(-) create mode 100644 sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/statistic/ParamFlowStatisticExitCallback.java diff --git a/sentinel-extension/sentinel-parameter-flow-control/README.md b/sentinel-extension/sentinel-parameter-flow-control/README.md index bf698a42b6..9098968986 100644 --- a/sentinel-extension/sentinel-parameter-flow-control/README.md +++ b/sentinel-extension/sentinel-parameter-flow-control/README.md @@ -52,7 +52,7 @@ The description for fields of `ParamFlowRule`: | :----: | :----| :----| | resource| resource name (**required**) || | count | flow control threshold (**required**) || -| grade | flow control mode (only QPS mode is supported) | QPS mode | +| grade | metric type (QPS or thread count) | QPS mode | | paramIdx | the index of provided parameter in `SphU.entry(xxx, args)` (**required**) || | paramFlowItemList | the exception items of parameter; you can set threshold to a specific parameter value || diff --git a/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/init/ParamFlowStatisticSlotCallbackInit.java b/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/init/ParamFlowStatisticSlotCallbackInit.java index 56d6bd2868..f380ce6066 100644 --- a/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/init/ParamFlowStatisticSlotCallbackInit.java +++ b/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/init/ParamFlowStatisticSlotCallbackInit.java @@ -16,6 +16,7 @@ package com.alibaba.csp.sentinel.init; import com.alibaba.csp.sentinel.slots.statistic.ParamFlowStatisticEntryCallback; +import com.alibaba.csp.sentinel.slots.statistic.ParamFlowStatisticExitCallback; import com.alibaba.csp.sentinel.slots.statistic.StatisticSlotCallbackRegistry; /** @@ -31,5 +32,7 @@ public class ParamFlowStatisticSlotCallbackInit implements InitFunc { public void init() { StatisticSlotCallbackRegistry.addEntryCallback(ParamFlowStatisticEntryCallback.class.getName(), new ParamFlowStatisticEntryCallback()); + StatisticSlotCallbackRegistry.addExitCallback(ParamFlowStatisticExitCallback.class.getName(), + new ParamFlowStatisticExitCallback()); } } diff --git a/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowChecker.java b/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowChecker.java index 27df8ccba5..5ea64dcee7 100644 --- a/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowChecker.java +++ b/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowChecker.java @@ -57,7 +57,7 @@ static boolean passCheck(ResourceWrapper resourceWrapper, /*@Valid*/ ParamFlowRu return true; } - if (rule.isClusterMode()) { + if (rule.isClusterMode() && rule.getGrade() == RuleConstant.FLOW_GRADE_QPS) { return passClusterCheck(resourceWrapper, rule, count, value); } @@ -106,6 +106,14 @@ static boolean passSingleValueCheck(ResourceWrapper resourceWrapper, ParamFlowRu } return false; } + } else if (rule.getGrade() == RuleConstant.FLOW_GRADE_THREAD) { + long threadCount = getHotParameters(resourceWrapper).getThreadCount(rule.getParamIdx(), value); + if (exclusionItems.contains(value)) { + int itemThreshold = rule.getParsedHotItems().get(value); + return ++threadCount <= itemThreshold; + } + long threshold = (long) rule.getCount(); + return ++threadCount <= threshold; } return true; diff --git a/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowRule.java b/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowRule.java index a986aeb66d..5b2747fc38 100644 --- a/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowRule.java +++ b/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowRule.java @@ -41,7 +41,7 @@ public ParamFlowRule(String resourceName) { } /** - * The threshold type of flow control (1: QPS). + * The threshold type of flow control (0: thread count, 1: QPS). */ private int grade = RuleConstant.FLOW_GRADE_QPS; diff --git a/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowRuleUtil.java b/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowRuleUtil.java index f58a837b08..48e4a2c1f1 100644 --- a/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowRuleUtil.java +++ b/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowRuleUtil.java @@ -31,7 +31,7 @@ public final class ParamFlowRuleUtil { public static boolean isValidRule(ParamFlowRule rule) { return rule != null && !StringUtil.isBlank(rule.getResource()) && rule.getCount() >= 0 - && rule.getParamIdx() != null && rule.getParamIdx() >= 0 && checkCluster(rule); + && rule.getGrade() >= 0 && rule.getParamIdx() != null && rule.getParamIdx() >= 0 && checkCluster(rule); } private static boolean checkCluster(/*@PreChecked*/ ParamFlowRule rule) { diff --git a/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParameterMetric.java b/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParameterMetric.java index 028185f765..0f2a800336 100644 --- a/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParameterMetric.java +++ b/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParameterMetric.java @@ -20,10 +20,13 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicInteger; import com.alibaba.csp.sentinel.log.RecordLog; import com.alibaba.csp.sentinel.node.IntervalProperty; import com.alibaba.csp.sentinel.node.SampleCountProperty; +import com.alibaba.csp.sentinel.slots.statistic.cache.CacheMap; +import com.alibaba.csp.sentinel.slots.statistic.cache.ConcurrentLinkedHashMapWrapper; import com.alibaba.csp.sentinel.slots.statistic.metric.HotParameterLeapArray; import com.alibaba.csp.sentinel.util.AssertUtil; @@ -52,13 +55,20 @@ public ParameterMetric(int sampleCount, int intervalInMs) { private Map rollingParameters = new ConcurrentHashMap(); + private Map> threadCountMap = + new ConcurrentHashMap>(); public Map getRollingParameters() { return rollingParameters; } + public Map> getThreadCountMap() { + return threadCountMap; + } + public synchronized void clear() { rollingParameters.clear(); + threadCountMap.clear(); } public void initializeForIndex(int index) { @@ -68,7 +78,129 @@ public void initializeForIndex(int index) { if (rollingParameters.get(index) == null) { rollingParameters.put(index, new HotParameterLeapArray(sampleCount, intervalMs)); } + + if (threadCountMap.get(index) == null) { + threadCountMap.put(index, + new ConcurrentLinkedHashMapWrapper(THREAD_COUNT_MAX_CAPACITY)); + } + } + } + } + + @SuppressWarnings("rawtypes") + public void decreaseThreadCount(Object... args) { + if (args == null) { + return; + } + + try { + for (int index = 0; index < args.length; index++) { + CacheMap threadCount = threadCountMap.get(index); + if (threadCount == null) { + continue; + } + + Object arg = args[index]; + if (arg == null) { + continue; + } + if (Collection.class.isAssignableFrom(arg.getClass())) { + + for (Object value : ((Collection)arg)) { + AtomicInteger oldValue = threadCount.putIfAbsent(value, new AtomicInteger()); + if (oldValue != null) { + int currentValue = oldValue.decrementAndGet(); + if (currentValue <= 0) { + threadCount.remove(value); + } + } + + } + } else if (arg.getClass().isArray()) { + int length = Array.getLength(arg); + for (int i = 0; i < length; i++) { + Object value = Array.get(arg, i); + AtomicInteger oldValue = threadCount.putIfAbsent(value, new AtomicInteger()); + if (oldValue != null) { + int currentValue = oldValue.decrementAndGet(); + if (currentValue <= 0) { + threadCount.remove(value); + } + } + + } + } else { + AtomicInteger oldValue = threadCount.putIfAbsent(arg, new AtomicInteger()); + if (oldValue != null) { + int currentValue = oldValue.decrementAndGet(); + if (currentValue <= 0) { + threadCount.remove(arg); + } + } + + } + } + } catch (Throwable e) { + RecordLog.warn("[ParameterMetric] Param exception", e); + } + } + + @SuppressWarnings("rawtypes") + public void addThreadCount(Object... args) { + if (args == null) { + return; + } + + try { + for (int index = 0; index < args.length; index++) { + CacheMap threadCount = threadCountMap.get(index); + if (threadCount == null) { + continue; + } + + Object arg = args[index]; + + if (arg == null) { + continue; + } + + if (Collection.class.isAssignableFrom(arg.getClass())) { + for (Object value : ((Collection)arg)) { + AtomicInteger oldValue = threadCount.putIfAbsent(value, new AtomicInteger()); + if (oldValue != null) { + oldValue.incrementAndGet(); + } else { + threadCount.put(value, new AtomicInteger(1)); + } + + } + } else if (arg.getClass().isArray()) { + int length = Array.getLength(arg); + for (int i = 0; i < length; i++) { + Object value = Array.get(arg, i); + AtomicInteger oldValue = threadCount.putIfAbsent(value, new AtomicInteger()); + if (oldValue != null) { + oldValue.incrementAndGet(); + } else { + threadCount.put(value, new AtomicInteger(1)); + } + + } + } else { + AtomicInteger oldValue = threadCount.putIfAbsent(arg, new AtomicInteger()); + if (oldValue != null) { + oldValue.incrementAndGet(); + } else { + threadCount.put(arg, new AtomicInteger(1)); + } + + } + + } + + } catch (Throwable e) { + RecordLog.warn("[ParameterMetric] Param exception", e); } } @@ -159,4 +291,15 @@ public Map getTopPassParamCount(int index, int number) { return new HashMap(); } + + public long getThreadCount(int index, Object value) { + if (threadCountMap.get(index) == null) { + return 0; + } + + AtomicInteger count = threadCountMap.get(index).get(value); + return count == null ? 0L : count.get(); + } + + private static final long THREAD_COUNT_MAX_CAPACITY = 4000; } diff --git a/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/statistic/ParamFlowStatisticEntryCallback.java b/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/statistic/ParamFlowStatisticEntryCallback.java index df99cfcf6f..0aee21554b 100644 --- a/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/statistic/ParamFlowStatisticEntryCallback.java +++ b/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/statistic/ParamFlowStatisticEntryCallback.java @@ -37,6 +37,7 @@ public void onPass(Context context, ResourceWrapper resourceWrapper, DefaultNode if (parameterMetric != null) { parameterMetric.addPass(count, args); + parameterMetric.addThreadCount(args); } } diff --git a/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/statistic/ParamFlowStatisticExitCallback.java b/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/statistic/ParamFlowStatisticExitCallback.java new file mode 100644 index 0000000000..1cb63917a6 --- /dev/null +++ b/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/statistic/ParamFlowStatisticExitCallback.java @@ -0,0 +1,40 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * 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.alibaba.csp.sentinel.slots.statistic; + +import com.alibaba.csp.sentinel.context.Context; +import com.alibaba.csp.sentinel.slotchain.ProcessorSlotExitCallback; +import com.alibaba.csp.sentinel.slotchain.ResourceWrapper; +import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowSlot; +import com.alibaba.csp.sentinel.slots.block.flow.param.ParameterMetric; + +/** + * @author Eric Zhao + * @since 0.2.0 + */ +public class ParamFlowStatisticExitCallback implements ProcessorSlotExitCallback { + + @Override + public void onExit(Context context, ResourceWrapper resourceWrapper, int count, Object... args) { + if (context.getCurEntry().getError() == null) { + ParameterMetric parameterMetric = ParamFlowSlot.getParamMetric(resourceWrapper); + + if (parameterMetric != null) { + parameterMetric.decreaseThreadCount(args); + } + } + } +} \ No newline at end of file diff --git a/sentinel-extension/sentinel-parameter-flow-control/src/test/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowCheckerTest.java b/sentinel-extension/sentinel-parameter-flow-control/src/test/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowCheckerTest.java index 0b9e481ef9..b22bd77c9e 100644 --- a/sentinel-extension/sentinel-parameter-flow-control/src/test/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowCheckerTest.java +++ b/sentinel-extension/sentinel-parameter-flow-control/src/test/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowCheckerTest.java @@ -23,6 +23,7 @@ import com.alibaba.csp.sentinel.EntryType; import com.alibaba.csp.sentinel.slotchain.ResourceWrapper; import com.alibaba.csp.sentinel.slotchain.StringResourceWrapper; +import com.alibaba.csp.sentinel.slots.block.RuleConstant; import org.junit.After; import org.junit.Before; @@ -129,6 +130,57 @@ public void testSingleValueCheckQpsWithExceptionItems() { assertFalse(ParamFlowChecker.passSingleValueCheck(resourceWrapper, rule, 1, valueD)); } + @Test + public void testSingleValueCheckThreadCountWithExceptionItems() { + final String resourceName = "testSingleValueCheckThreadCountWithExceptionItems"; + final ResourceWrapper resourceWrapper = new StringResourceWrapper(resourceName, EntryType.IN); + int paramIdx = 0; + + long globalThreshold = 5L; + int thresholdB = 3; + int thresholdD = 7; + + ParamFlowRule rule = new ParamFlowRule(resourceName) + .setCount(globalThreshold) + .setParamIdx(paramIdx) + .setGrade(RuleConstant.FLOW_GRADE_THREAD); + + String valueA = "valueA"; + String valueB = "valueB"; + String valueC = "valueC"; + String valueD = "valueD"; + + // Directly set parsed map for test. + Map map = new HashMap(); + map.put(valueB, thresholdB); + map.put(valueD, thresholdD); + rule.setParsedHotItems(map); + + ParameterMetric metric = mock(ParameterMetric.class); + when(metric.getThreadCount(paramIdx, valueA)).thenReturn(globalThreshold - 1); + when(metric.getThreadCount(paramIdx, valueB)).thenReturn(globalThreshold - 1); + when(metric.getThreadCount(paramIdx, valueC)).thenReturn(globalThreshold - 1); + when(metric.getThreadCount(paramIdx, valueD)).thenReturn(globalThreshold + 1); + ParamFlowSlot.getMetricsMap().put(resourceWrapper, metric); + + assertTrue(ParamFlowChecker.passSingleValueCheck(resourceWrapper, rule, 1, valueA)); + assertFalse(ParamFlowChecker.passSingleValueCheck(resourceWrapper, rule, 1, valueB)); + assertTrue(ParamFlowChecker.passSingleValueCheck(resourceWrapper, rule, 1, valueC)); + assertTrue(ParamFlowChecker.passSingleValueCheck(resourceWrapper, rule, 1, valueD)); + + when(metric.getThreadCount(paramIdx, valueA)).thenReturn(globalThreshold); + when(metric.getThreadCount(paramIdx, valueB)).thenReturn(thresholdB - 1L); + when(metric.getThreadCount(paramIdx, valueC)).thenReturn(globalThreshold + 1); + when(metric.getThreadCount(paramIdx, valueD)).thenReturn(globalThreshold - 1) + .thenReturn((long)thresholdD); + + assertFalse(ParamFlowChecker.passSingleValueCheck(resourceWrapper, rule, 1, valueA)); + assertTrue(ParamFlowChecker.passSingleValueCheck(resourceWrapper, rule, 1, valueB)); + assertFalse(ParamFlowChecker.passSingleValueCheck(resourceWrapper, rule, 1, valueC)); + assertTrue(ParamFlowChecker.passSingleValueCheck(resourceWrapper, rule, 1, valueD)); + assertFalse(ParamFlowChecker.passSingleValueCheck(resourceWrapper, rule, 1, valueD)); + } + @Test public void testPassLocalCheckForCollection() { final String resourceName = "testPassLocalCheckForCollection"; diff --git a/sentinel-extension/sentinel-parameter-flow-control/src/test/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowRuleManagerTest.java b/sentinel-extension/sentinel-parameter-flow-control/src/test/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowRuleManagerTest.java index a6ae69c0c5..58af635873 100644 --- a/sentinel-extension/sentinel-parameter-flow-control/src/test/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowRuleManagerTest.java +++ b/sentinel-extension/sentinel-parameter-flow-control/src/test/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowRuleManagerTest.java @@ -79,7 +79,7 @@ public void testLoadHotParamRulesAndGet() { ParamFlowRule ruleC = new ParamFlowRule(resA) .setCount(8) .setParamIdx(1) - .setGrade(RuleConstant.FLOW_GRADE_QPS); + .setGrade(RuleConstant.FLOW_GRADE_THREAD); // Rule D is for resource B. ParamFlowRule ruleD = new ParamFlowRule(resB) .setCount(9) diff --git a/sentinel-extension/sentinel-parameter-flow-control/src/test/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowSlotTest.java b/sentinel-extension/sentinel-parameter-flow-control/src/test/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowSlotTest.java index 32d6dc6fe5..70043fe028 100644 --- a/sentinel-extension/sentinel-parameter-flow-control/src/test/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowSlotTest.java +++ b/sentinel-extension/sentinel-parameter-flow-control/src/test/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowSlotTest.java @@ -97,6 +97,7 @@ public void testInitParamMetrics() { ParameterMetric metric = ParamFlowSlot.getParamMetric(resourceWrapper); assertNotNull(metric); assertNotNull(metric.getRollingParameters().get(index)); + assertNotNull(metric.getThreadCountMap().get(index)); // Duplicate init. paramFlowSlot.initHotParamMetricsFor(resourceWrapper, index); diff --git a/sentinel-extension/sentinel-parameter-flow-control/src/test/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParameterMetricTest.java b/sentinel-extension/sentinel-parameter-flow-control/src/test/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParameterMetricTest.java index e7789e841f..0450574b5e 100644 --- a/sentinel-extension/sentinel-parameter-flow-control/src/test/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParameterMetricTest.java +++ b/sentinel-extension/sentinel-parameter-flow-control/src/test/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParameterMetricTest.java @@ -15,9 +15,12 @@ */ package com.alibaba.csp.sentinel.slots.block.flow.param; +import java.util.Arrays; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; +import com.alibaba.csp.sentinel.slots.statistic.cache.CacheMap; import com.alibaba.csp.sentinel.slots.statistic.metric.HotParameterLeapArray; import org.junit.Test; @@ -60,13 +63,119 @@ public void testInitAndClearHotParameterMetric() { int index = 1; metric.initializeForIndex(index); HotParameterLeapArray leapArray = metric.getRollingParameters().get(index); + CacheMap cacheMap = metric.getThreadCountMap().get(index); assertNotNull(leapArray); + assertNotNull(cacheMap); metric.initializeForIndex(index); assertSame(leapArray, metric.getRollingParameters().get(index)); + assertSame(cacheMap, metric.getThreadCountMap().get(index)); metric.clear(); assertEquals(0, metric.getRollingParameters().size()); + assertEquals(0, metric.getThreadCountMap().size()); + } + + @Test + public void testAddAndDecreaseThreadCountCommon() { + testAddAndDecreaseThreadCount(PARAM_TYPE_NORMAL); + testAddAndDecreaseThreadCount(PARAM_TYPE_ARRAY); + testAddAndDecreaseThreadCount(PARAM_TYPE_COLLECTION); + } + + private void testAddAndDecreaseThreadCount(int paramType) { + int paramIdx = 0; + int n = 3; + long[] v = new long[] {19L, 3L, 8L}; + ParameterMetric metric = new ParameterMetric(); + metric.initializeForIndex(paramIdx); + assertTrue(metric.getThreadCountMap().containsKey(paramIdx)); + + switch (paramType) { + case PARAM_TYPE_ARRAY: + metric.addThreadCount((Object)v); + break; + case PARAM_TYPE_COLLECTION: + metric.addThreadCount(Arrays.asList(v[0], v[1], v[2])); + break; + case PARAM_TYPE_NORMAL: + default: + metric.addThreadCount(v[0]); + metric.addThreadCount(v[1]); + metric.addThreadCount(v[2]); + break; + } + + assertEquals(1, metric.getThreadCountMap().size()); + CacheMap threadCountMap = metric.getThreadCountMap().get(paramIdx); + assertEquals(v.length, threadCountMap.size()); + for (long vs : v) { + assertEquals(1, threadCountMap.get(vs).get()); + } + + for (int i = 1 ; i < n; i++) { + switch (paramType) { + case PARAM_TYPE_ARRAY: + metric.addThreadCount((Object)v); + break; + case PARAM_TYPE_COLLECTION: + metric.addThreadCount(Arrays.asList(v[0], v[1], v[2])); + break; + case PARAM_TYPE_NORMAL: + default: + metric.addThreadCount(v[0]); + metric.addThreadCount(v[1]); + metric.addThreadCount(v[2]); + break; + } + } + assertEquals(1, metric.getThreadCountMap().size()); + threadCountMap = metric.getThreadCountMap().get(paramIdx); + assertEquals(v.length, threadCountMap.size()); + for (long vs : v) { + assertEquals(n, threadCountMap.get(vs).get()); + } + + for (int i = 1 ; i < n; i++) { + switch (paramType) { + case PARAM_TYPE_ARRAY: + metric.decreaseThreadCount((Object)v); + break; + case PARAM_TYPE_COLLECTION: + metric.decreaseThreadCount(Arrays.asList(v[0], v[1], v[2])); + break; + case PARAM_TYPE_NORMAL: + default: + metric.decreaseThreadCount(v[0]); + metric.decreaseThreadCount(v[1]); + metric.decreaseThreadCount(v[2]); + break; + } + } + assertEquals(1, metric.getThreadCountMap().size()); + threadCountMap = metric.getThreadCountMap().get(paramIdx); + assertEquals(v.length, threadCountMap.size()); + for (long vs : v) { + assertEquals(1, threadCountMap.get(vs).get()); + } + + switch (paramType) { + case PARAM_TYPE_ARRAY: + metric.decreaseThreadCount((Object)v); + break; + case PARAM_TYPE_COLLECTION: + metric.decreaseThreadCount(Arrays.asList(v[0], v[1], v[2])); + break; + case PARAM_TYPE_NORMAL: + default: + metric.decreaseThreadCount(v[0]); + metric.decreaseThreadCount(v[1]); + metric.decreaseThreadCount(v[2]); + break; + } + assertEquals(1, metric.getThreadCountMap().size()); + threadCountMap = metric.getThreadCountMap().get(paramIdx); + assertEquals(0, threadCountMap.size()); } private static final int PARAM_TYPE_NORMAL = 0; From c0d93181e8a66f79b87300bab40d4ca7a15134e8 Mon Sep 17 00:00:00 2001 From: mjaow Date: Wed, 30 Jan 2019 10:25:16 +0800 Subject: [PATCH 33/39] Add volatile in double-checked locking field in ClusterBuilderSlot (#466) --- .../csp/sentinel/slots/clusterbuilder/ClusterBuilderSlot.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/clusterbuilder/ClusterBuilderSlot.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/clusterbuilder/ClusterBuilderSlot.java index 31ef6b65f0..acbc3895b4 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/clusterbuilder/ClusterBuilderSlot.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/clusterbuilder/ClusterBuilderSlot.java @@ -70,7 +70,7 @@ public class ClusterBuilderSlot extends AbstractLinkedProcessorSlot private static final Object lock = new Object(); - private ClusterNode clusterNode = null; + private volatile ClusterNode clusterNode = null; @Override public void entry(Context context, ResourceWrapper resourceWrapper, DefaultNode node, int count, From 5f98bf03c033c2fed3018c9346ef8dbc9101e1f3 Mon Sep 17 00:00:00 2001 From: Eric Zhao Date: Wed, 30 Jan 2019 16:41:39 +0800 Subject: [PATCH 34/39] Improve ClusterServerConfigManager in sentinel-cluster-server-default and add basic test cases Signed-off-by: Eric Zhao --- .../config/ClusterServerConfigManager.java | 71 ++++++++++++++++++- .../ClusterServerConfigManagerTest.java | 31 ++++++++ 2 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 sentinel-cluster/sentinel-cluster-server-default/src/test/java/com/alibaba/csp/sentinel/cluster/server/config/ClusterServerConfigManagerTest.java diff --git a/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/config/ClusterServerConfigManager.java b/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/config/ClusterServerConfigManager.java index 8b15875511..b3d3fcd651 100644 --- a/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/config/ClusterServerConfigManager.java +++ b/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/config/ClusterServerConfigManager.java @@ -35,6 +35,7 @@ import com.alibaba.csp.sentinel.property.DynamicSentinelProperty; import com.alibaba.csp.sentinel.property.PropertyListener; import com.alibaba.csp.sentinel.property.SentinelProperty; +import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleUtil; import com.alibaba.csp.sentinel.util.AssertUtil; /** @@ -95,7 +96,13 @@ public final class ClusterServerConfigManager { namespaceSetProperty.addListener(NAMESPACE_SET_PROPERTY_LISTENER); } + /** + * Register cluster server namespace set dynamic property. + * + * @param property server namespace set dynamic property + */ public static void registerNamespaceSetProperty(SentinelProperty> property) { + AssertUtil.notNull(property, "namespace set dynamic property cannot be null"); synchronized (NAMESPACE_SET_PROPERTY_LISTENER) { RecordLog.info( "[ClusterServerConfigManager] Registering new namespace set dynamic property to Sentinel server " @@ -106,7 +113,13 @@ public static void registerNamespaceSetProperty(SentinelProperty> pr } } + /** + * Register cluster server transport configuration dynamic property. + * + * @param property server transport configuration dynamic property + */ public static void registerServerTransportProperty(SentinelProperty property) { + AssertUtil.notNull(property, "cluster server transport config dynamic property cannot be null"); synchronized (TRANSPORT_PROPERTY_LISTENER) { RecordLog.info( "[ClusterServerConfigManager] Registering new server transport dynamic property to Sentinel server " @@ -117,14 +130,46 @@ public static void registerServerTransportProperty(SentinelProperty property) { + AssertUtil.notNull(property, "cluster server flow config dynamic property cannot be null"); + synchronized (GLOBAL_FLOW_PROPERTY_LISTENER) { + RecordLog.info( + "[ClusterServerConfigManager] Registering new server global flow dynamic property " + + "to Sentinel server config manager"); + globalFlowProperty.removeListener(GLOBAL_FLOW_PROPERTY_LISTENER); + property.addListener(GLOBAL_FLOW_PROPERTY_LISTENER); + globalFlowProperty = property; + } + } + + /** + * Load provided server namespace set to property in memory. + * + * @param namespaceSet valid namespace set + */ public static void loadServerNamespaceSet(Set namespaceSet) { namespaceSetProperty.updateValue(namespaceSet); } + /** + * Load provided server transport configuration to property in memory. + * + * @param config valid cluster server transport configuration + */ public static void loadGlobalTransportConfig(ServerTransportConfig config) { transportConfigProperty.updateValue(config); } + /** + * Load provided server global statistic (flow) configuration to property in memory. + * + * @param config valid cluster server flow configuration for global + */ public static void loadGlobalFlowConfig(ServerFlowConfig config) { globalFlowProperty.updateValue(config); } @@ -133,7 +178,7 @@ public static void loadGlobalFlowConfig(ServerFlowConfig config) { * Load server flow config for a specific namespace. * * @param namespace a valid namespace - * @param config valid flow config for the namespace + * @param config valid flow config for the namespace */ public static void loadFlowConfig(String namespace, ServerFlowConfig config) { AssertUtil.notEmpty(namespace, "namespace cannot be empty"); @@ -141,6 +186,12 @@ public static void loadFlowConfig(String namespace, ServerFlowConfig config) { globalFlowProperty.updateValue(config); } + /** + * Add a transport config observer. The observers will be called as soon as + * there are some changes in transport config (e.g. token server port). + * + * @param observer a valid transport config observer + */ public static void addTransportConfigChangeObserver(ServerTransportConfigObserver observer) { AssertUtil.notNull(observer, "observer cannot be null"); TRANSPORT_CONFIG_OBSERVERS.add(observer); @@ -175,16 +226,20 @@ private static void applyNamespaceSetChange(Set newSet) { } newSet = new HashSet<>(newSet); + // Always add the `default` namespace to the namespace set. newSet.add(ServerConstants.DEFAULT_NAMESPACE); + if (embedded) { // In embedded server mode, the server itself is also a part of service, // so it should be added to namespace set. + // By default, the added namespace is the appName. newSet.add(ConfigSupplierRegistry.getNamespaceSupplier().get()); } Set oldSet = ClusterServerConfigManager.namespaceSet; if (oldSet != null && !oldSet.isEmpty()) { for (String ns : oldSet) { + // Remove the cluster rule property for deprecated namespace set. if (!newSet.contains(ns)) { ClusterFlowRuleManager.removeProperty(ns); ClusterParamFlowRuleManager.removeProperty(ns); @@ -194,8 +249,10 @@ private static void applyNamespaceSetChange(Set newSet) { ClusterServerConfigManager.namespaceSet = newSet; for (String ns : newSet) { + // Register the rule property if needed. ClusterFlowRuleManager.registerPropertyIfAbsent(ns); ClusterParamFlowRuleManager.registerPropertyIfAbsent(ns); + // Initialize the global QPS limiter for the namespace. GlobalRequestLimiter.initIfAbsent(ns); } } @@ -294,7 +351,8 @@ public static boolean isValidTransportConfig(ServerTransportConfig config) { public static boolean isValidFlowConfig(ServerFlowConfig config) { return config != null && config.getMaxOccupyRatio() >= 0 && config.getExceedCount() >= 0 - && config.getMaxAllowedQps() >= 0; + && config.getMaxAllowedQps() >= 0 + && FlowRuleUtil.isWindowConfigValid(config.getSampleCount(), config.getIntervalMs()); } public static double getExceedCount(String namespace) { @@ -388,6 +446,15 @@ public static boolean isEmbedded() { return embedded; } + /** + *

    Set the embedded mode flag for the token server.

    + *

    + * NOTE: developers SHOULD NOT manually invoke this method. + * The embedded flag should be initialized by Sentinel when starting token server. + *

    + * + * @param embedded whether the token server is currently running in embedded mode + */ public static void setEmbedded(boolean embedded) { ClusterServerConfigManager.embedded = embedded; } diff --git a/sentinel-cluster/sentinel-cluster-server-default/src/test/java/com/alibaba/csp/sentinel/cluster/server/config/ClusterServerConfigManagerTest.java b/sentinel-cluster/sentinel-cluster-server-default/src/test/java/com/alibaba/csp/sentinel/cluster/server/config/ClusterServerConfigManagerTest.java new file mode 100644 index 0000000000..c088f9bdca --- /dev/null +++ b/sentinel-cluster/sentinel-cluster-server-default/src/test/java/com/alibaba/csp/sentinel/cluster/server/config/ClusterServerConfigManagerTest.java @@ -0,0 +1,31 @@ +package com.alibaba.csp.sentinel.cluster.server.config; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * @author Eric Zhao + */ +public class ClusterServerConfigManagerTest { + + @Test + public void testIsValidTransportConfig() { + ServerTransportConfig badConfig1 = new ServerTransportConfig().setPort(-1); + ServerTransportConfig badConfig2 = new ServerTransportConfig().setPort(886622); + ServerTransportConfig goodConfig1 = new ServerTransportConfig().setPort(23456); + assertFalse(ClusterServerConfigManager.isValidTransportConfig(badConfig1)); + assertFalse(ClusterServerConfigManager.isValidTransportConfig(badConfig2)); + assertTrue(ClusterServerConfigManager.isValidTransportConfig(goodConfig1)); + } + + @Test + public void testIsValidFlowConfig() { + ServerFlowConfig badConfig1 = new ServerFlowConfig().setMaxAllowedQps(-2); + ServerFlowConfig badConfig2 = new ServerFlowConfig().setIntervalMs(1000).setSampleCount(3); + ServerFlowConfig badConfig3 = new ServerFlowConfig().setIntervalMs(1000).setSampleCount(0); + assertFalse(ClusterServerConfigManager.isValidFlowConfig(badConfig1)); + assertFalse(ClusterServerConfigManager.isValidFlowConfig(badConfig2)); + assertFalse(ClusterServerConfigManager.isValidFlowConfig(badConfig3)); + } +} \ No newline at end of file From 9ea2d7cba5c960857ca1fcc9ebf2a10a836b3be8 Mon Sep 17 00:00:00 2001 From: yanlinly Date: Thu, 31 Jan 2019 09:21:39 +0800 Subject: [PATCH 35/39] Update Nacos SDK version to 0.8 and update Nacos namespace demo (#474) --- .../datasource/nacos/NacosDataSourceDemo.java | 39 +++++++++++++++---- .../sentinel-datasource-nacos/pom.xml | 2 +- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/sentinel-demo/sentinel-demo-nacos-datasource/src/main/java/com/alibaba/csp/sentinel/demo/datasource/nacos/NacosDataSourceDemo.java b/sentinel-demo/sentinel-demo-nacos-datasource/src/main/java/com/alibaba/csp/sentinel/demo/datasource/nacos/NacosDataSourceDemo.java index 51856354d1..00116cde37 100644 --- a/sentinel-demo/sentinel-demo-nacos-datasource/src/main/java/com/alibaba/csp/sentinel/demo/datasource/nacos/NacosDataSourceDemo.java +++ b/sentinel-demo/sentinel-demo-nacos-datasource/src/main/java/com/alibaba/csp/sentinel/demo/datasource/nacos/NacosDataSourceDemo.java @@ -16,6 +16,7 @@ package com.alibaba.csp.sentinel.demo.datasource.nacos; import java.util.List; +import java.util.Properties; import com.alibaba.csp.sentinel.datasource.ReadableDataSource; import com.alibaba.csp.sentinel.datasource.nacos.NacosDataSource; @@ -23,10 +24,10 @@ import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.TypeReference; +import com.alibaba.nacos.api.PropertyKeyConst; /** * This demo demonstrates how to use Nacos as the data source of Sentinel rules. - * * Before you start, you need to start a Nacos server in local first, and then * use {@link NacosConfigSender} to publish initial rule configuration to Nacos. * @@ -35,9 +36,24 @@ public class NacosDataSourceDemo { private static final String KEY = "TestResource"; + // nacos server ip + private static final String remoteAddress = "localhost"; + // nacos group + private static final String groupId = "Sentinel:Demo"; + // nacos dataId + private static final String dataId = "com.alibaba.csp.sentinel.demo.flow.rule"; + // if change to true, should be config NACOS_NAMESPACE_ID + private static boolean isDemoNamespace = false; + // fill your namespace id,if you want to use namespace. for example: 0f5c7314-4983-4022-ad5a-347de1d1057d,you can get it on nacos's console + private static final String NACOS_NAMESPACE_ID = "${namespace}"; public static void main(String[] args) { - loadRules(); + if (isDemoNamespace) { + loadMyNamespaceRules(); + } else { + loadRules(); + } + // Assume we config: resource is `TestResource`, initial QPS threshold is 5. FlowQpsRunner runner = new FlowQpsRunner(KEY, 1, 100); runner.simulateTraffic(); @@ -45,12 +61,21 @@ public static void main(String[] args) { } private static void loadRules() { - final String remoteAddress = "localhost"; - final String groupId = "Sentinel:Demo"; - final String dataId = "com.alibaba.csp.sentinel.demo.flow.rule"; - ReadableDataSource> flowRuleDataSource = new NacosDataSource<>(remoteAddress, groupId, dataId, - source -> JSON.parseObject(source, new TypeReference>() {})); + source -> JSON.parseObject(source, new TypeReference>() { + })); + FlowRuleManager.register2Property(flowRuleDataSource.getProperty()); + } + + private static void loadMyNamespaceRules() { + Properties properties = new Properties(); + properties.put(PropertyKeyConst.SERVER_ADDR, remoteAddress); + properties.put(PropertyKeyConst.NAMESPACE, NACOS_NAMESPACE_ID); + + ReadableDataSource> flowRuleDataSource = new NacosDataSource<>(properties, groupId, dataId, + source -> JSON.parseObject(source, new TypeReference>() { + })); FlowRuleManager.register2Property(flowRuleDataSource.getProperty()); } + } diff --git a/sentinel-extension/sentinel-datasource-nacos/pom.xml b/sentinel-extension/sentinel-datasource-nacos/pom.xml index 7e41b2a3e1..9fa6e49818 100644 --- a/sentinel-extension/sentinel-datasource-nacos/pom.xml +++ b/sentinel-extension/sentinel-datasource-nacos/pom.xml @@ -13,7 +13,7 @@ jar - 0.6.2 + 0.8.0 From 00957626667ffa94efa5cbdcec96f74e8248aa88 Mon Sep 17 00:00:00 2001 From: Eric Zhao Date: Thu, 31 Jan 2019 14:24:05 +0800 Subject: [PATCH 36/39] Carry the triggered rule in subclasses of BlockException (#469) * Extract getRule in BlockException and refine override methods in subclasses Signed-off-by: Eric Zhao --- .../sentinel/slots/block/BlockException.java | 22 +++++++++++-- .../block/authority/AuthorityException.java | 19 ++++++++++- .../slots/block/authority/AuthoritySlot.java | 2 +- .../slots/block/degrade/DegradeException.java | 16 ++++++++++ .../block/degrade/DegradeRuleManager.java | 2 +- .../slots/block/flow/FlowException.java | 16 +++++++++- .../sentinel/slots/block/flow/FlowSlot.java | 2 +- .../slots/system/SystemBlockException.java | 23 +++++++++---- .../block/flow/param/ParamFlowException.java | 32 +++++++++++++++++-- .../slots/block/flow/param/ParamFlowSlot.java | 6 ++-- 10 files changed, 121 insertions(+), 19 deletions(-) diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/BlockException.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/BlockException.java index 605b7b7cd5..ada98383f2 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/BlockException.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/BlockException.java @@ -15,8 +15,9 @@ */ package com.alibaba.csp.sentinel.slots.block; -/*** - * Abstract exception indicating blocked by Sentinel due to flow control, degraded or system guard. +/** + * Abstract exception indicating blocked by Sentinel due to flow control, + * circuit breaking or system protection triggered. * * @author youji.zj */ @@ -42,6 +43,7 @@ public abstract class BlockException extends Exception { THROW_OUT_EXCEPTION.setStackTrace(sentinelStackTrace); } + protected AbstractRule rule; private String ruleLimitApp; public BlockException(String ruleLimitApp) { @@ -49,6 +51,12 @@ public BlockException(String ruleLimitApp) { this.ruleLimitApp = ruleLimitApp; } + public BlockException(String ruleLimitApp, AbstractRule rule) { + super(); + this.ruleLimitApp = ruleLimitApp; + this.rule = rule; + } + public BlockException(String message, Throwable cause) { super(message, cause); } @@ -58,6 +66,12 @@ public BlockException(String ruleLimitApp, String message) { this.ruleLimitApp = ruleLimitApp; } + public BlockException(String ruleLimitApp, String message, AbstractRule rule) { + super(message); + this.ruleLimitApp = ruleLimitApp; + this.rule = rule; + } + @Override public Throwable fillInStackTrace() { return this; @@ -98,4 +112,8 @@ public static boolean isBlockException(Throwable t) { return false; } + + public AbstractRule getRule() { + return rule; + } } diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/authority/AuthorityException.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/authority/AuthorityException.java index e007ec658c..b3d0854bfd 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/authority/AuthorityException.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/authority/AuthorityException.java @@ -17,9 +17,11 @@ import com.alibaba.csp.sentinel.slots.block.BlockException; -/*** +/** + * Block exception for request origin access (authority) control. * * @author youji.zj + * @author Eric Zhao */ public class AuthorityException extends BlockException { @@ -27,6 +29,10 @@ public AuthorityException(String ruleLimitApp) { super(ruleLimitApp); } + public AuthorityException(String ruleLimitApp, AuthorityRule rule) { + super(ruleLimitApp, rule); + } + public AuthorityException(String message, Throwable cause) { super(message, cause); } @@ -40,4 +46,15 @@ public Throwable fillInStackTrace() { return this; } + /** + * Get triggered rule. + * Note: the rule result is a reference to rule map and SHOULD NOT be modified. + * + * @return triggered rule + * @since 1.4.2 + */ + @Override + public AuthorityRule getRule() { + return rule.as(AuthorityRule.class); + } } diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/authority/AuthoritySlot.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/authority/AuthoritySlot.java index e9786c1a82..369699c9a0 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/authority/AuthoritySlot.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/authority/AuthoritySlot.java @@ -58,7 +58,7 @@ void checkBlackWhiteAuthority(ResourceWrapper resource, Context context) throws for (AuthorityRule rule : rules) { if (!AuthorityRuleChecker.passCheck(rule, context)) { - throw new AuthorityException(context.getOrigin()); + throw new AuthorityException(context.getOrigin(), rule); } } } diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/degrade/DegradeException.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/degrade/DegradeException.java index 1538373d71..718d68f705 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/degrade/DegradeException.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/degrade/DegradeException.java @@ -26,6 +26,10 @@ public DegradeException(String ruleLimitApp) { super(ruleLimitApp); } + public DegradeException(String ruleLimitApp, DegradeRule rule) { + super(ruleLimitApp, rule); + } + public DegradeException(String message, Throwable cause) { super(message, cause); } @@ -38,4 +42,16 @@ public DegradeException(String ruleLimitApp, String message) { public Throwable fillInStackTrace() { return this; } + + /** + * Get triggered rule. + * Note: the rule result is a reference to rule map and SHOULD NOT be modified. + * + * @return triggered rule + * @since 1.4.2 + */ + @Override + public DegradeRule getRule() { + return rule.as(DegradeRule.class); + } } diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/degrade/DegradeRuleManager.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/degrade/DegradeRuleManager.java index 6e3bd7fc31..5da818fac7 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/degrade/DegradeRuleManager.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/degrade/DegradeRuleManager.java @@ -76,7 +76,7 @@ public static void checkDegrade(ResourceWrapper resource, Context context, Defau for (DegradeRule rule : rules) { if (!rule.passCheck(context, node, count)) { - throw new DegradeException(rule.getLimitApp()); + throw new DegradeException(rule.getLimitApp(), rule); } } } diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowException.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowException.java index 81c2a0e37e..01e8a3e586 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowException.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowException.java @@ -23,10 +23,13 @@ public class FlowException extends BlockException { public FlowException(String ruleLimitApp) { - super(ruleLimitApp); } + public FlowException(String ruleLimitApp, FlowRule rule) { + super(ruleLimitApp, rule); + } + public FlowException(String message, Throwable cause) { super(message, cause); } @@ -40,4 +43,15 @@ public Throwable fillInStackTrace() { return this; } + /** + * Get triggered rule. + * Note: the rule result is a reference to rule map and SHOULD NOT be modified. + * + * @return triggered rule + * @since 1.4.2 + */ + @Override + public FlowRule getRule() { + return rule.as(FlowRule.class); + } } diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowSlot.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowSlot.java index 3f392db1e7..9aa900ecd3 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowSlot.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowSlot.java @@ -151,7 +151,7 @@ void checkFlow(ResourceWrapper resource, Context context, DefaultNode node, int if (rules != null) { for (FlowRule rule : rules) { if (!canPassCheck(rule, context, node, count, prioritized)) { - throw new FlowException(rule.getLimitApp()); + throw new FlowException(rule.getLimitApp(), rule); } } } diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/system/SystemBlockException.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/system/SystemBlockException.java index a6d6a8357e..24504e17d4 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/system/SystemBlockException.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/system/SystemBlockException.java @@ -22,25 +22,34 @@ */ public class SystemBlockException extends BlockException { - String resourceName; - - public String getResourceName() { - return resourceName; - } + private final String resourceName; public SystemBlockException(String resourceName, String message, Throwable cause) { super(message, cause); this.resourceName = resourceName; } - public SystemBlockException(String resourceName, String ruleLimitApp) { - super(ruleLimitApp); + public SystemBlockException(String resourceName, String limitType) { + super(limitType); this.resourceName = resourceName; } + public String getResourceName() { + return resourceName; + } + @Override public Throwable fillInStackTrace() { return this; } + /** + * Return the limit type of system rule. + * + * @return the limit type + * @since 1.4.2 + */ + public String getLimitType() { + return getRuleLimitApp(); + } } diff --git a/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowException.java b/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowException.java index a4a659c0a2..1c47bc5342 100644 --- a/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowException.java +++ b/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowException.java @@ -32,11 +32,17 @@ public ParamFlowException(String resourceName, String message, Throwable cause) this.resourceName = resourceName; } - public ParamFlowException(String resourceName, String message) { - super(message, message); + public ParamFlowException(String resourceName, String param) { + super(param, param); this.resourceName = resourceName; } + public ParamFlowException(String resourceName, String param, ParamFlowRule rule) { + super(param, param); + this.resourceName = resourceName; + this.rule = rule; + } + public String getResourceName() { return resourceName; } @@ -45,4 +51,26 @@ public String getResourceName() { public Throwable fillInStackTrace() { return this; } + + /** + * Get the parameter value that triggered the parameter flow control. + * + * @return the parameter value + * @since 1.4.2 + */ + public String getLimitParam() { + return getMessage(); + } + + /** + * Get triggered rule. + * Note: the rule result is a reference to rule map and SHOULD NOT be modified. + * + * @return triggered rule + * @since 1.4.2 + */ + @Override + public ParamFlowRule getRule() { + return rule.as(ParamFlowRule.class); + } } diff --git a/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowSlot.java b/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowSlot.java index b3f7bec9f0..48d34f8fda 100644 --- a/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowSlot.java +++ b/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowSlot.java @@ -81,12 +81,12 @@ void checkFlow(ResourceWrapper resourceWrapper, int count, Object... args) // Here we add the block count. addBlockCount(resourceWrapper, count, args); - String message = ""; + String triggeredParam = ""; if (args.length > rule.getParamIdx()) { Object value = args[rule.getParamIdx()]; - message = String.valueOf(value); + triggeredParam = String.valueOf(value); } - throw new ParamFlowException(resourceWrapper.getName(), message); + throw new ParamFlowException(resourceWrapper.getName(), triggeredParam, rule); } } } From 7fb4ebf2824fc7511847ad09eaf057facd32cf2f Mon Sep 17 00:00:00 2001 From: Eric Zhao Date: Mon, 28 Jan 2019 09:49:25 +0800 Subject: [PATCH 37/39] Fix NPE bug when creating connection group in ConnectionManager - The NPE will occur when multiple threads are trying to create the connection group for the same namespace Signed-off-by: Eric Zhao --- .../sentinel/cluster/server/connection/ConnectionManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/connection/ConnectionManager.java b/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/connection/ConnectionManager.java index 5bbbaeaa37..6b6be604a7 100644 --- a/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/connection/ConnectionManager.java +++ b/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/connection/ConnectionManager.java @@ -55,7 +55,7 @@ public static ConnectionGroup getOrCreateGroup(String namespace) { ConnectionGroup group = CONN_MAP.get(namespace); if (group == null) { synchronized (CREATE_LOCK) { - if (CONN_MAP.get(namespace) == null) { + if ((group = CONN_MAP.get(namespace)) == null) { group = new ConnectionGroup(namespace); CONN_MAP.put(namespace, group); } From 9b9c5022c7f3070101b84c66a8cf0eb9cce16f41 Mon Sep 17 00:00:00 2001 From: Eric Zhao Date: Mon, 28 Jan 2019 10:32:28 +0800 Subject: [PATCH 38/39] Improve and fix bugs for ConnectionManager and add test cases Signed-off-by: Eric Zhao --- .../FetchClusterServerInfoCommandHandler.java | 2 +- .../server/connection/ConnectionGroup.java | 6 +- .../server/connection/ConnectionManager.java | 13 ++- .../connection/ConnectionGroupTest.java | 34 ++++++ .../connection/ConnectionManagerTest.java | 102 ++++++++++++++++++ 5 files changed, 153 insertions(+), 4 deletions(-) create mode 100644 sentinel-cluster/sentinel-cluster-server-default/src/test/java/com/alibaba/csp/sentinel/cluster/server/connection/ConnectionGroupTest.java create mode 100644 sentinel-cluster/sentinel-cluster-server-default/src/test/java/com/alibaba/csp/sentinel/cluster/server/connection/ConnectionManagerTest.java diff --git a/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/command/handler/FetchClusterServerInfoCommandHandler.java b/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/command/handler/FetchClusterServerInfoCommandHandler.java index c5510c9422..d5ae01b96d 100644 --- a/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/command/handler/FetchClusterServerInfoCommandHandler.java +++ b/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/command/handler/FetchClusterServerInfoCommandHandler.java @@ -43,7 +43,7 @@ public CommandResponse handle(CommandRequest request) { JSONArray connectionGroups = new JSONArray(); Set namespaceSet = ClusterServerConfigManager.getNamespaceSet(); for (String namespace : namespaceSet) { - ConnectionGroup group = ConnectionManager.getConnectionGroup(namespace); + ConnectionGroup group = ConnectionManager.getOrCreateConnectionGroup(namespace); if (group != null) { connectionGroups.add(group); } diff --git a/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/connection/ConnectionGroup.java b/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/connection/ConnectionGroup.java index c4f8471948..9a3d53cd28 100644 --- a/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/connection/ConnectionGroup.java +++ b/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/connection/ConnectionGroup.java @@ -56,8 +56,10 @@ public ConnectionGroup addConnection(String address) { } else { host = address; } - connectionSet.add(new ConnectionDescriptor().setAddress(address).setHost(host)); - connectedCount.incrementAndGet(); + boolean newAdded = connectionSet.add(new ConnectionDescriptor().setAddress(address).setHost(host)); + if (newAdded) { + connectedCount.incrementAndGet(); + } return this; } diff --git a/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/connection/ConnectionManager.java b/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/connection/ConnectionManager.java index 6b6be604a7..37f88cedd7 100644 --- a/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/connection/ConnectionManager.java +++ b/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/connection/ConnectionManager.java @@ -100,12 +100,23 @@ public static ConnectionGroup addConnection(String namespace, String address) { return group; } - public static ConnectionGroup getConnectionGroup(String namespace) { + public static ConnectionGroup getOrCreateConnectionGroup(String namespace) { AssertUtil.assertNotBlank(namespace, "namespace should not be empty"); ConnectionGroup group = getOrCreateGroup(namespace); return group; } + public static ConnectionGroup getConnectionGroup(String namespace) { + AssertUtil.assertNotBlank(namespace, "namespace should not be empty"); + ConnectionGroup group = CONN_MAP.get(namespace); + return group; + } + + static void clear() { + CONN_MAP.clear(); + NAMESPACE_MAP.clear(); + } + private static final Object CREATE_LOCK = new Object(); private ConnectionManager() {} diff --git a/sentinel-cluster/sentinel-cluster-server-default/src/test/java/com/alibaba/csp/sentinel/cluster/server/connection/ConnectionGroupTest.java b/sentinel-cluster/sentinel-cluster-server-default/src/test/java/com/alibaba/csp/sentinel/cluster/server/connection/ConnectionGroupTest.java new file mode 100644 index 0000000000..b87ae34665 --- /dev/null +++ b/sentinel-cluster/sentinel-cluster-server-default/src/test/java/com/alibaba/csp/sentinel/cluster/server/connection/ConnectionGroupTest.java @@ -0,0 +1,34 @@ +package com.alibaba.csp.sentinel.cluster.server.connection; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * @author Eric Zhao + */ +public class ConnectionGroupTest { + + @Test + public void testAddAndRemoveConnection() { + String namespace = "test-conn-group"; + ConnectionGroup group = new ConnectionGroup(namespace); + assertEquals(0, group.getConnectedCount()); + + String address1 = "12.23.34.45:5566"; + String address2 = "192.168.0.22:32123"; + String address3 = "12.23.34.45:5566"; + group.addConnection(address1); + assertEquals(1, group.getConnectedCount()); + group.addConnection(address2); + assertEquals(2, group.getConnectedCount()); + group.addConnection(address3); + assertEquals(2, group.getConnectedCount()); + + group.removeConnection(address1); + assertEquals(1, group.getConnectedCount()); + + group.removeConnection(address3); + assertEquals(1, group.getConnectedCount()); + } +} \ No newline at end of file diff --git a/sentinel-cluster/sentinel-cluster-server-default/src/test/java/com/alibaba/csp/sentinel/cluster/server/connection/ConnectionManagerTest.java b/sentinel-cluster/sentinel-cluster-server-default/src/test/java/com/alibaba/csp/sentinel/cluster/server/connection/ConnectionManagerTest.java new file mode 100644 index 0000000000..03eac0b076 --- /dev/null +++ b/sentinel-cluster/sentinel-cluster-server-default/src/test/java/com/alibaba/csp/sentinel/cluster/server/connection/ConnectionManagerTest.java @@ -0,0 +1,102 @@ +package com.alibaba.csp.sentinel.cluster.server.connection; + +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.CountDownLatch; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * @author Eric Zhao + */ +public class ConnectionManagerTest { + + @Before + public void setUp() { + ConnectionManager.clear(); + } + + @After + public void cleanUp() { + ConnectionManager.clear(); + } + + @Test + public void testAndConnectionAndGetConnectedCount() { + String namespace = "test-namespace"; + assertEquals(0, ConnectionManager.getConnectedCount(namespace)); + + // Put one connection. + ConnectionManager.addConnection(namespace, "12.23.34.45:1997"); + assertEquals(1, ConnectionManager.getConnectedCount(namespace)); + // Put duplicate connection. + ConnectionManager.addConnection(namespace, "12.23.34.45:1997"); + assertEquals(1, ConnectionManager.getConnectedCount(namespace)); + + // Put another connection. + ConnectionManager.addConnection(namespace, "12.23.34.49:22123"); + assertEquals(2, ConnectionManager.getConnectedCount(namespace)); + } + + @Test(expected = IllegalArgumentException.class) + public void testGetOrCreateGroupBadNamespace() { + ConnectionManager.getOrCreateGroup(""); + } + + @Test + public void testGetOrCreateGroupMultipleThread() throws Exception { + final String namespace = "test-namespace"; + int threadCount = 32; + final List groups = new CopyOnWriteArrayList<>(); + final CountDownLatch latch = new CountDownLatch(threadCount); + for (int i = 0; i < threadCount; i++) { + new Thread(new Runnable() { + @Override + public void run() { + groups.add(ConnectionManager.getOrCreateGroup(namespace)); + latch.countDown(); + } + }).start(); + } + latch.await(); + for (int i = 1; i < groups.size(); i++) { + assertSame(groups.get(i - 1).getNamespace(), groups.get(i).getNamespace()); + } + } + + @Test + public void testRemoveConnection() { + String namespace = "test-namespace-remove"; + String address1 = "12.23.34.45:1997"; + String address2 = "12.23.34.46:1998"; + String address3 = "12.23.34.47:1999"; + ConnectionManager.addConnection(namespace, address1); + ConnectionManager.addConnection(namespace, address2); + ConnectionManager.addConnection(namespace, address3); + + assertEquals(3, ConnectionManager.getConnectedCount(namespace)); + ConnectionManager.removeConnection(namespace, address3); + assertEquals(2, ConnectionManager.getConnectedCount(namespace)); + assertFalse(ConnectionManager.getOrCreateConnectionGroup(namespace).getConnectionSet().contains( + new ConnectionDescriptor().setAddress(address3) + )); + } + + @Test + public void testGetOrCreateConnectionGroup() { + String namespace = "test-namespace"; + assertNull(ConnectionManager.getConnectionGroup(namespace)); + ConnectionGroup group1 = ConnectionManager.getOrCreateConnectionGroup(namespace); + assertNotNull(group1); + + // Put one connection. + ConnectionManager.addConnection(namespace, "12.23.34.45:1997"); + ConnectionGroup group2 = ConnectionManager.getOrCreateConnectionGroup(namespace); + + assertSame(group1, group2); + } +} \ No newline at end of file From 2109367f163602ffeda054c1b631a7ec6928afe9 Mon Sep 17 00:00:00 2001 From: "Nick.Tan" Date: Sun, 17 Feb 2019 22:38:50 +0800 Subject: [PATCH 39/39] fix dashboard listResourcesOfApp concurrent error fix ConcurrentModificationException of listResourcesOfApp method --- .../metric/InMemoryMetricsRepository.java | 29 ++-- .../metric/InMemoryMetricsRepositoryTest.java | 142 ++++++++++++++++++ 2 files changed, 158 insertions(+), 13 deletions(-) create mode 100644 sentinel-dashboard/src/test/java/com/alibaba/csp/sentinel/dashboard/repository/metric/InMemoryMetricsRepositoryTest.java diff --git a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/metric/InMemoryMetricsRepository.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/metric/InMemoryMetricsRepository.java index d10ecf2c3a..bed4ea1c73 100644 --- a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/metric/InMemoryMetricsRepository.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/metric/InMemoryMetricsRepository.java @@ -27,6 +27,7 @@ import com.alibaba.csp.sentinel.dashboard.datasource.entity.MetricEntity; import com.alibaba.csp.sentinel.util.StringUtil; +import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap; import org.springframework.stereotype.Component; /** @@ -43,21 +44,23 @@ public class InMemoryMetricsRepository implements MetricsRepository resource -> timestamp -> metric} */ - private Map>> allMetrics = new ConcurrentHashMap<>(); + private Map>> allMetrics = new ConcurrentHashMap<>(); + + @Override public synchronized void save(MetricEntity entity) { if (entity == null || StringUtil.isBlank(entity.getApp())) { return; } - allMetrics.computeIfAbsent(entity.getApp(), e -> new HashMap<>(16)) - .computeIfAbsent(entity.getResource(), e -> new LinkedHashMap() { - @Override - protected boolean removeEldestEntry(Entry eldest) { + allMetrics.computeIfAbsent(entity.getApp(), e -> new ConcurrentHashMap<>(16)) + .computeIfAbsent(entity.getResource(), e -> new ConcurrentLinkedHashMap.Builder() + .maximumWeightedCapacity(MAX_METRIC_LIVE_TIME_MS).weigher((key, value) -> { // Metric older than {@link #MAX_METRIC_LIVE_TIME_MS} will be removed. - return eldest.getKey() < System.currentTimeMillis() - MAX_METRIC_LIVE_TIME_MS; - } - }).put(entity.getTimestamp().getTime(), entity); + int weight = (int)(System.currentTimeMillis() - key); + // weight must be a number greater than or equal to one + return Math.max(weight, 1); + }).build()).put(entity.getTimestamp().getTime(), entity); } @Override @@ -75,11 +78,11 @@ public synchronized List queryByAppAndResourceBetween(String app, if (StringUtil.isBlank(app)) { return results; } - Map> resourceMap = allMetrics.get(app); + Map> resourceMap = allMetrics.get(app); if (resourceMap == null) { return results; } - LinkedHashMap metricsMap = resourceMap.get(resource); + ConcurrentLinkedHashMap metricsMap = resourceMap.get(resource); if (metricsMap == null) { return results; } @@ -98,14 +101,14 @@ public List listResourcesOfApp(String app) { return results; } // resource -> timestamp -> metric - Map> resourceMap = allMetrics.get(app); + Map> resourceMap = allMetrics.get(app); if (resourceMap == null) { return results; } final long minTimeMs = System.currentTimeMillis() - 1000 * 60; - Map resourceCount = new HashMap<>(32); + Map resourceCount = new ConcurrentHashMap<>(32); - for (Entry> resourceMetrics : resourceMap.entrySet()) { + for (Entry> resourceMetrics : resourceMap.entrySet()) { for (Entry metrics : resourceMetrics.getValue().entrySet()) { if (metrics.getKey() < minTimeMs) { continue; diff --git a/sentinel-dashboard/src/test/java/com/alibaba/csp/sentinel/dashboard/repository/metric/InMemoryMetricsRepositoryTest.java b/sentinel-dashboard/src/test/java/com/alibaba/csp/sentinel/dashboard/repository/metric/InMemoryMetricsRepositoryTest.java new file mode 100644 index 0000000000..62040671da --- /dev/null +++ b/sentinel-dashboard/src/test/java/com/alibaba/csp/sentinel/dashboard/repository/metric/InMemoryMetricsRepositoryTest.java @@ -0,0 +1,142 @@ +package com.alibaba.csp.sentinel.dashboard.repository.metric; + +import com.alibaba.csp.sentinel.dashboard.datasource.entity.MetricEntity; +import org.assertj.core.util.Lists; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.springframework.util.CollectionUtils; + +import java.util.ConcurrentModificationException; +import java.util.Date; +import java.util.List; +import java.util.concurrent.*; + +import static org.junit.Assert.*; + +/** + * InMemoryMetricsRepository Test + * + * @author Nick Tan + */ +public class InMemoryMetricsRepositoryTest { + + private static final String DEFAULT_APP = "default"; + private static final String DEFAULT_EXPIRE_APP = "default_expire_app"; + private static final String DEFAULT_RESOURCE = "test"; + private static final long EXPIRE_TIME = 1000 * 60 * 5L; + private InMemoryMetricsRepository inMemoryMetricsRepository; + + private static final int AVAILABLE_CPU_PROCESSORS = Runtime.getRuntime().availableProcessors(); + + private ExecutorService executorService = Executors.newFixedThreadPool(AVAILABLE_CPU_PROCESSORS); + + @Before + public void setUp() throws Exception { + + inMemoryMetricsRepository = new InMemoryMetricsRepository(); + } + + @Test + public void save() throws InterruptedException { + + for (int i = 0; i < 1000000; i++) { + + MetricEntity entry = new MetricEntity(); + entry.setApp(DEFAULT_APP); + entry.setResource(DEFAULT_RESOURCE); + entry.setTimestamp(new Date(System.currentTimeMillis())); + entry.setPassQps(1L); + entry.setExceptionQps(1L); + entry.setBlockQps(0L); + entry.setSuccessQps(1L); + inMemoryMetricsRepository.save(entry); + + } + + } + + @Test + public void testExpireMetric() throws InterruptedException { + + long now = System.currentTimeMillis(); + MetricEntity expireEntry = new MetricEntity(); + expireEntry.setApp(DEFAULT_EXPIRE_APP); + expireEntry.setResource(DEFAULT_RESOURCE); + expireEntry.setTimestamp(new Date(now - EXPIRE_TIME - 10L)); + expireEntry.setPassQps(1L); + expireEntry.setExceptionQps(1L); + expireEntry.setBlockQps(0L); + expireEntry.setSuccessQps(1L); + inMemoryMetricsRepository.save(expireEntry); + + MetricEntity entry = new MetricEntity(); + entry.setApp(DEFAULT_EXPIRE_APP); + entry.setResource(DEFAULT_RESOURCE); + entry.setTimestamp(new Date(now)); + entry.setPassQps(1L); + entry.setExceptionQps(1L); + entry.setBlockQps(0L); + entry.setSuccessQps(1L); + inMemoryMetricsRepository.save(entry); + + List list = inMemoryMetricsRepository.queryByAppAndResourceBetween( + DEFAULT_EXPIRE_APP, DEFAULT_RESOURCE, now - 2 * EXPIRE_TIME, now + EXPIRE_TIME); + + Assert.assertEquals(false, CollectionUtils.isEmpty(list)); + + assertTrue(list.size() == 1); + + } + + @Test + public void listResourcesOfApp() throws InterruptedException { + // prepare basic test data + save(); + System.out.println(System.currentTimeMillis() + "[basic test data ready]"); + + List futures = Lists.newArrayList(); + + // concurrent query resources of app + final CyclicBarrier cyclicBarrier = new CyclicBarrier(AVAILABLE_CPU_PROCESSORS); + for (int j = 0; j < 10000; j++) { + + futures.add( + CompletableFuture.runAsync(() -> { + try { + cyclicBarrier.await(); + inMemoryMetricsRepository.listResourcesOfApp(DEFAULT_APP); + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (BrokenBarrierException e) { + e.printStackTrace(); + } + }, executorService + )); + } + + // batch add metric entity + for (int i = 0; i < 10000; i++) { + + MetricEntity entry = new MetricEntity(); + entry.setApp(DEFAULT_APP); + entry.setResource(DEFAULT_RESOURCE); + entry.setTimestamp(new Date(System.currentTimeMillis() - EXPIRE_TIME - 1000L)); + entry.setPassQps(1L); + entry.setExceptionQps(1L); + entry.setBlockQps(0L); + entry.setSuccessQps(1L); + inMemoryMetricsRepository.save(entry); + + } + + CompletableFuture all = CompletableFuture.allOf(futures.toArray((new CompletableFuture[futures.size()]))); + try { + all.join(); + } catch (ConcurrentModificationException e) { + e.printStackTrace(); + assertFalse("concurrent error", e instanceof ConcurrentModificationException); + } + } + +} \ No newline at end of file