From 6b6a8042581fcd77e8f71f5ce930cbc5a7f2f71d Mon Sep 17 00:00:00 2001 From: HHoflittlefish777 <77738092+HHoflittlefish777@users.noreply.github.com> Date: Wed, 11 Jan 2023 22:33:54 +0800 Subject: [PATCH] update labelRouting to routing (#3077) * update labelRouting to routing --- .../cloud/examples/ConsumerApplication.java | 40 ++++++------- .../event/RoutingDataChangedEvent.java | 8 +-- .../MatchService.java | 10 ++-- .../RoutingRule.java} | 18 +++--- .../UnifiedRoutingDataStructure.java} | 16 +++--- .../rule/HeaderRoutingRule.java} | 10 ++-- .../RouteRule.java => routing/rule/Rule.java} | 4 +- .../rule/UrlRoutingRule.java} | 19 ++++--- .../filter/impl/RoutingXdsResolveFilter.java | 34 +++++------ .../cloud/governance/istio/util/ConvUtil.java | 13 +++-- .../cloud/governance/istio/XdsRulesTests.java | 10 ++-- .../opensergo/OpenSergoTrafficExchanger.java | 4 +- .../OpenSergoTrafficRouterParser.java | 42 +++++++------- .../opensergo/OpenSergoRuleTests.java | 4 +- .../RoutingAutoConfiguration.java} | 24 ++++---- .../RoutingProperties.java} | 6 +- .../RoutingPropertiesAutoConfiguration.java} | 12 ++-- .../feign/RoutingFeignInterceptor.java} | 9 +-- ...ingFeignInterceptorAutoConfiguration.java} | 8 +-- .../listener/RoutingDataListener.java} | 28 +++++---- .../TargetServiceChangedPublisher.java | 2 +- .../repository/FilterService.java | 2 +- .../repository/RoutingDataRepository.java} | 41 ++++++------- .../ribbon/RoutingLoadBalanceRule.java} | 57 ++++++++++--------- ...tingLoadBalanceRuleAutoConfiguration.java} | 8 +-- .../util/ConditionMatchUtil.java | 2 +- .../util/LoadBalanceUtil.java | 2 +- .../util/RequestContext.java | 2 +- .../web/WebMvcAutoConfiguration.java | 2 +- .../{router => routing}/web/WebMvcConfig.java | 2 +- .../web/WebMvcInterceptor.java | 4 +- .../main/resources/META-INF/spring.factories | 10 ++-- 32 files changed, 229 insertions(+), 224 deletions(-) rename spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/{labelrouting => routing}/MatchService.java (88%) rename spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/{labelrouting/LabelRouteRule.java => routing/RoutingRule.java} (78%) rename spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/{labelrouting/UnifiedRouteDataStructure.java => routing/UnifiedRoutingDataStructure.java} (71%) rename spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/{labelrouting/rule/HeaderRule.java => routing/rule/HeaderRoutingRule.java} (85%) rename spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/{labelrouting/rule/RouteRule.java => routing/rule/Rule.java} (90%) rename spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/{labelrouting/rule/UrlRule.java => routing/rule/UrlRoutingRule.java} (85%) rename spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/{router/LabelRoutingAutoConfiguration.java => routing/RoutingAutoConfiguration.java} (62%) rename spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/{router/RouterProperties.java => routing/RoutingProperties.java} (88%) rename spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/{router/RouterPropertiesAutoConfiguration.java => routing/RoutingPropertiesAutoConfiguration.java} (79%) rename spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/{router/feign/FeignInterceptor.java => routing/feign/RoutingFeignInterceptor.java} (83%) rename spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/{router/feign/FeignInterceptorAutoConfiguration.java => routing/feign/RoutingFeignInterceptorAutoConfiguration.java} (82%) rename spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/{router/listener/LabelRouteDataListener.java => routing/listener/RoutingDataListener.java} (64%) rename spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/{router => routing}/publish/TargetServiceChangedPublisher.java (97%) rename spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/{router => routing}/repository/FilterService.java (98%) rename spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/{router/repository/RouteDataRepository.java => routing/repository/RoutingDataRepository.java} (77%) rename spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/{router/ribbon/LabelRouteLBRule.java => routing/ribbon/RoutingLoadBalanceRule.java} (87%) rename spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/{router/ribbon/LabelRouteLBRuleAutoConfiguration.java => routing/ribbon/RoutingLoadBalanceRuleAutoConfiguration.java} (82%) rename spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/{router => routing}/util/ConditionMatchUtil.java (98%) rename spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/{router => routing}/util/LoadBalanceUtil.java (98%) rename spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/{router => routing}/util/RequestContext.java (97%) rename spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/{router => routing}/web/WebMvcAutoConfiguration.java (96%) rename spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/{router => routing}/web/WebMvcConfig.java (96%) rename spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/{router => routing}/web/WebMvcInterceptor.java (93%) diff --git a/spring-cloud-alibaba-examples/governance-example/label-routing-example/consumer-example/src/main/java/com/alibaba/cloud/examples/ConsumerApplication.java b/spring-cloud-alibaba-examples/governance-example/label-routing-example/consumer-example/src/main/java/com/alibaba/cloud/examples/ConsumerApplication.java index ec5f9ec65..3320cb7ca 100644 --- a/spring-cloud-alibaba-examples/governance-example/label-routing-example/consumer-example/src/main/java/com/alibaba/cloud/examples/ConsumerApplication.java +++ b/spring-cloud-alibaba-examples/governance-example/label-routing-example/consumer-example/src/main/java/com/alibaba/cloud/examples/ConsumerApplication.java @@ -20,12 +20,12 @@ import java.util.ArrayList; import java.util.List; import com.alibaba.cloud.commons.governance.event.RoutingDataChangedEvent; -import com.alibaba.cloud.commons.governance.labelrouting.LabelRouteRule; -import com.alibaba.cloud.commons.governance.labelrouting.MatchService; -import com.alibaba.cloud.commons.governance.labelrouting.UnifiedRouteDataStructure; -import com.alibaba.cloud.commons.governance.labelrouting.rule.HeaderRule; -import com.alibaba.cloud.commons.governance.labelrouting.rule.RouteRule; -import com.alibaba.cloud.commons.governance.labelrouting.rule.UrlRule; +import com.alibaba.cloud.commons.governance.routing.MatchService; +import com.alibaba.cloud.commons.governance.routing.RoutingRule; +import com.alibaba.cloud.commons.governance.routing.UnifiedRoutingDataStructure; +import com.alibaba.cloud.commons.governance.routing.rule.HeaderRoutingRule; +import com.alibaba.cloud.commons.governance.routing.rule.Rule; +import com.alibaba.cloud.commons.governance.routing.rule.UrlRoutingRule; import org.springframework.beans.BeansException; import org.springframework.beans.factory.annotation.Autowired; @@ -85,26 +85,26 @@ public class ConsumerApplication { @GetMapping("/add") public void getDataFromControlPlaneTest() { - List routeRules = new ArrayList<>(); + List routeRules = new ArrayList<>(); List matchServices = new ArrayList<>(); - UnifiedRouteDataStructure unifiedRouteDataStructure = new UnifiedRouteDataStructure(); + UnifiedRoutingDataStructure unifiedRouteDataStructure = new UnifiedRoutingDataStructure(); unifiedRouteDataStructure.setTargetService("service-provider"); - LabelRouteRule labelRouteData = new LabelRouteRule(); + RoutingRule labelRouteData = new RoutingRule(); labelRouteData.setDefaultRouteVersion("v1"); - RouteRule routeRule = new HeaderRule(); + Rule routeRule = new HeaderRoutingRule(); routeRule.setType("header"); routeRule.setCondition("="); routeRule.setKey("tag"); routeRule.setValue("gray"); - RouteRule routeRule1 = new UrlRule.Parameter(); + Rule routeRule1 = new UrlRoutingRule.Parameter(); routeRule1.setType("parameter"); routeRule1.setCondition(">"); routeRule1.setKey("id"); routeRule1.setValue("10"); - RouteRule routeRule2 = new UrlRule.Path(); + Rule routeRule2 = new UrlRoutingRule.PathRoutingRule(); routeRule2.setType("path"); routeRule2.setCondition("="); routeRule2.setValue("/router-test"); @@ -122,7 +122,7 @@ public class ConsumerApplication { unifiedRouteDataStructure.setLabelRouteRule(labelRouteData); - List unifiedRouteDataStructureList = new ArrayList<>(); + List unifiedRouteDataStructureList = new ArrayList<>(); unifiedRouteDataStructureList.add(unifiedRouteDataStructure); applicationContext.publishEvent( new RoutingDataChangedEvent(this, unifiedRouteDataStructureList)); @@ -130,26 +130,26 @@ public class ConsumerApplication { @GetMapping("/update") public void updateDataFromControlPlaneTest() { - List routeRules = new ArrayList<>(); + List routeRules = new ArrayList<>(); List matchServices = new ArrayList<>(); - UnifiedRouteDataStructure unifiedRouteDataStructure = new UnifiedRouteDataStructure(); + UnifiedRoutingDataStructure unifiedRouteDataStructure = new UnifiedRoutingDataStructure(); unifiedRouteDataStructure.setTargetService("service-provider"); - LabelRouteRule labelRouteData = new LabelRouteRule(); + RoutingRule labelRouteData = new RoutingRule(); labelRouteData.setDefaultRouteVersion("v1"); - RouteRule routeRule = new HeaderRule(); + Rule routeRule = new HeaderRoutingRule(); routeRule.setType("header"); routeRule.setCondition("="); routeRule.setKey("tag"); routeRule.setValue("gray"); - RouteRule routeRule1 = new UrlRule.Parameter(); + Rule routeRule1 = new UrlRoutingRule.Parameter(); routeRule1.setType("parameter"); routeRule1.setCondition(">"); routeRule1.setKey("id"); routeRule1.setValue("10"); - RouteRule routeRule2 = new UrlRule.Path(); + Rule routeRule2 = new UrlRoutingRule.PathRoutingRule(); routeRule2.setType("path"); routeRule2.setCondition("="); routeRule2.setValue("/router-test"); @@ -167,7 +167,7 @@ public class ConsumerApplication { unifiedRouteDataStructure.setLabelRouteRule(labelRouteData); - List unifiedRouteDataStructureList = new ArrayList<>(); + List unifiedRouteDataStructureList = new ArrayList<>(); unifiedRouteDataStructureList.add(unifiedRouteDataStructure); applicationContext.publishEvent( new RoutingDataChangedEvent(this, unifiedRouteDataStructureList)); diff --git a/spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/event/RoutingDataChangedEvent.java b/spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/event/RoutingDataChangedEvent.java index 53979dfc1..a542dbfab 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/event/RoutingDataChangedEvent.java +++ b/spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/event/RoutingDataChangedEvent.java @@ -18,7 +18,7 @@ package com.alibaba.cloud.commons.governance.event; import java.util.Collection; -import com.alibaba.cloud.commons.governance.labelrouting.UnifiedRouteDataStructure; +import com.alibaba.cloud.commons.governance.routing.UnifiedRoutingDataStructure; /** * @author musi @@ -30,15 +30,15 @@ public class RoutingDataChangedEvent extends GovernanceEvent { /** * Configuration for Label Routing. */ - private final Collection untiedRouterDataStructureList; + private final Collection untiedRouterDataStructureList; public RoutingDataChangedEvent(Object source, - Collection untiedRouterDataStructureList) { + Collection untiedRouterDataStructureList) { super(source); this.untiedRouterDataStructureList = untiedRouterDataStructureList; } - public Collection getUntiedRouterDataStructureList() { + public Collection getUntiedRouterDataStructureList() { return untiedRouterDataStructureList; } diff --git a/spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/labelrouting/MatchService.java b/spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/routing/MatchService.java similarity index 88% rename from spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/labelrouting/MatchService.java rename to spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/routing/MatchService.java index 07991783e..9de50a194 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/labelrouting/MatchService.java +++ b/spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/routing/MatchService.java @@ -14,12 +14,12 @@ * limitations under the License. */ -package com.alibaba.cloud.commons.governance.labelrouting; +package com.alibaba.cloud.commons.governance.routing; import java.util.List; import java.util.Objects; -import com.alibaba.cloud.commons.governance.labelrouting.rule.RouteRule; +import com.alibaba.cloud.commons.governance.routing.rule.Rule; /** * @author HH @@ -27,7 +27,7 @@ import com.alibaba.cloud.commons.governance.labelrouting.rule.RouteRule; */ public class MatchService { - private List ruleList; + private List ruleList; private String version; @@ -43,11 +43,11 @@ public class MatchService { this.fallbackVersion = fallbackVersion; } - public List getRuleList() { + public List getRuleList() { return ruleList; } - public void setRuleList(List ruleList) { + public void setRuleList(List ruleList) { this.ruleList = ruleList; } diff --git a/spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/labelrouting/LabelRouteRule.java b/spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/routing/RoutingRule.java similarity index 78% rename from spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/labelrouting/LabelRouteRule.java rename to spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/routing/RoutingRule.java index 9d829fba3..dceab2cb7 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/labelrouting/LabelRouteRule.java +++ b/spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/routing/RoutingRule.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.alibaba.cloud.commons.governance.labelrouting; +package com.alibaba.cloud.commons.governance.routing; import java.util.List; import java.util.Objects; @@ -23,18 +23,18 @@ import java.util.Objects; * @author HH * @since 2.2.10-RC1 */ -public class LabelRouteRule { +public class RoutingRule { - private String defaultRouteVersion; + private String defaultRoutingVersion; private List matchRouteList; public String getDefaultRouteVersion() { - return defaultRouteVersion; + return defaultRoutingVersion; } public void setDefaultRouteVersion(String defaultRouteVersion) { - this.defaultRouteVersion = defaultRouteVersion; + this.defaultRoutingVersion = defaultRouteVersion; } public List getMatchRouteList() { @@ -53,19 +53,19 @@ public class LabelRouteRule { if (o == null || getClass() != o.getClass()) { return false; } - LabelRouteRule that = (LabelRouteRule) o; - return Objects.equals(defaultRouteVersion, that.defaultRouteVersion) + RoutingRule that = (RoutingRule) o; + return Objects.equals(defaultRoutingVersion, that.defaultRoutingVersion) && Objects.equals(getMatchRouteList(), that.getMatchRouteList()); } @Override public int hashCode() { - return Objects.hash(defaultRouteVersion, getMatchRouteList()); + return Objects.hash(defaultRoutingVersion, getMatchRouteList()); } @Override public String toString() { - return "LabelRouteData{" + "defaultRouteVersion='" + defaultRouteVersion + '\'' + return "LabelRouteData{" + "defaultRouteVersion='" + defaultRoutingVersion + '\'' + ", matchRouteList=" + matchRouteList + '}'; } diff --git a/spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/labelrouting/UnifiedRouteDataStructure.java b/spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/routing/UnifiedRoutingDataStructure.java similarity index 71% rename from spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/labelrouting/UnifiedRouteDataStructure.java rename to spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/routing/UnifiedRoutingDataStructure.java index b25b1ba73..0917f0737 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/labelrouting/UnifiedRouteDataStructure.java +++ b/spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/routing/UnifiedRoutingDataStructure.java @@ -14,24 +14,24 @@ * limitations under the License. */ -package com.alibaba.cloud.commons.governance.labelrouting; +package com.alibaba.cloud.commons.governance.routing; /** * @author HH * @since 2.2.10-RC1 */ -public class UnifiedRouteDataStructure { +public class UnifiedRoutingDataStructure { - private LabelRouteRule labelRouteRule; + private RoutingRule routingRule; private String targetService; - public LabelRouteRule getLabelRouteRule() { - return labelRouteRule; + public RoutingRule getLabelRouteRule() { + return routingRule; } - public void setLabelRouteRule(LabelRouteRule labelRouteRule) { - this.labelRouteRule = labelRouteRule; + public void setLabelRouteRule(RoutingRule labelRouteRule) { + this.routingRule = labelRouteRule; } public String getTargetService() { @@ -44,7 +44,7 @@ public class UnifiedRouteDataStructure { @Override public String toString() { - return "UntiedRouteDataStructure{" + "labelRouteData=" + labelRouteRule + return "UntiedRoutingDataStructure{" + "RoutingData=" + routingRule + ", targetService='" + targetService + '\'' + '}'; } diff --git a/spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/labelrouting/rule/HeaderRule.java b/spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/routing/rule/HeaderRoutingRule.java similarity index 85% rename from spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/labelrouting/rule/HeaderRule.java rename to spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/routing/rule/HeaderRoutingRule.java index b3d8e60f6..cafeb59b9 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/labelrouting/rule/HeaderRule.java +++ b/spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/routing/rule/HeaderRoutingRule.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.alibaba.cloud.commons.governance.labelrouting.rule; +package com.alibaba.cloud.commons.governance.routing.rule; import java.util.Objects; @@ -22,7 +22,7 @@ import java.util.Objects; * @author HH * @since 2.2.10-RC1 */ -public class HeaderRule implements RouteRule { +public class HeaderRoutingRule implements Rule { private String type; @@ -80,7 +80,7 @@ public class HeaderRule implements RouteRule { if (o == null || getClass() != o.getClass()) { return false; } - HeaderRule that = (HeaderRule) o; + HeaderRoutingRule that = (HeaderRoutingRule) o; return Objects.equals(getType(), that.getType()) && Objects.equals(getCondition(), that.getCondition()) && Objects.equals(getKey(), that.getKey()) @@ -94,8 +94,8 @@ public class HeaderRule implements RouteRule { @Override public String toString() { - return "HeaderRule{" + "type='" + type + '\'' + ", condition='" + condition + '\'' - + ", key='" + key + '\'' + ", value='" + value + '\'' + '}'; + return "HeaderRoutingRule{" + "type='" + type + '\'' + ", condition='" + condition + + '\'' + ", key='" + key + '\'' + ", value='" + value + '\'' + '}'; } } diff --git a/spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/labelrouting/rule/RouteRule.java b/spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/routing/rule/Rule.java similarity index 90% rename from spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/labelrouting/rule/RouteRule.java rename to spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/routing/rule/Rule.java index 93186c19e..6c35dc243 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/labelrouting/rule/RouteRule.java +++ b/spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/routing/rule/Rule.java @@ -14,13 +14,13 @@ * limitations under the License. */ -package com.alibaba.cloud.commons.governance.labelrouting.rule; +package com.alibaba.cloud.commons.governance.routing.rule; /** * @author HH * @since 2.2.10-RC1 */ -public interface RouteRule { +public interface Rule { /** * get type of rule. diff --git a/spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/labelrouting/rule/UrlRule.java b/spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/routing/rule/UrlRoutingRule.java similarity index 85% rename from spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/labelrouting/rule/UrlRule.java rename to spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/routing/rule/UrlRoutingRule.java index 7937d9dd9..fc3fb76b0 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/labelrouting/rule/UrlRule.java +++ b/spring-cloud-alibaba-starters/spring-cloud-alibaba-commons/src/main/java/com/alibaba/cloud/commons/governance/routing/rule/UrlRoutingRule.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.alibaba.cloud.commons.governance.labelrouting.rule; +package com.alibaba.cloud.commons.governance.routing.rule; import java.util.Objects; @@ -22,9 +22,9 @@ import java.util.Objects; * @author HH * @since 2.2.10-RC1 */ -public class UrlRule { +public class UrlRoutingRule { - public static class Path implements RouteRule { + public static class PathRoutingRule implements Rule { private String type; @@ -80,7 +80,7 @@ public class UrlRule { if (o == null || getClass() != o.getClass()) { return false; } - Path path = (Path) o; + PathRoutingRule path = (PathRoutingRule) o; return Objects.equals(getType(), path.getType()) && Objects.equals(getCondition(), path.getCondition()) && Objects.equals(getValue(), path.getValue()); @@ -93,13 +93,13 @@ public class UrlRule { @Override public String toString() { - return "Path{" + "type='" + type + '\'' + ", condition='" + condition + '\'' - + ", value='" + value + '\'' + '}'; + return "PathRoutingRule{" + "type='" + type + '\'' + ", condition='" + + condition + '\'' + ", value='" + value + '\'' + '}'; } } - public static class Parameter implements RouteRule { + public static class Parameter implements Rule { private String type; @@ -171,8 +171,9 @@ public class UrlRule { @Override public String toString() { - return "Parameter{" + "type='" + type + '\'' + ", condition='" + condition - + '\'' + ", key='" + key + '\'' + ", value='" + value + '\'' + '}'; + return "ParameterRoutingRule{" + "type='" + type + '\'' + ", condition='" + + condition + '\'' + ", key='" + key + '\'' + ", value='" + value + + '\'' + '}'; } } diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-controlplane-istio/src/main/java/com/alibaba/cloud/governance/istio/filter/impl/RoutingXdsResolveFilter.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-controlplane-istio/src/main/java/com/alibaba/cloud/governance/istio/filter/impl/RoutingXdsResolveFilter.java index c971a37c7..ede0521ef 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-controlplane-istio/src/main/java/com/alibaba/cloud/governance/istio/filter/impl/RoutingXdsResolveFilter.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-controlplane-istio/src/main/java/com/alibaba/cloud/governance/istio/filter/impl/RoutingXdsResolveFilter.java @@ -22,12 +22,12 @@ import java.util.List; import java.util.Map; import com.alibaba.cloud.commons.governance.event.RoutingDataChangedEvent; -import com.alibaba.cloud.commons.governance.labelrouting.LabelRouteRule; -import com.alibaba.cloud.commons.governance.labelrouting.MatchService; -import com.alibaba.cloud.commons.governance.labelrouting.UnifiedRouteDataStructure; -import com.alibaba.cloud.commons.governance.labelrouting.rule.HeaderRule; -import com.alibaba.cloud.commons.governance.labelrouting.rule.RouteRule; -import com.alibaba.cloud.commons.governance.labelrouting.rule.UrlRule; +import com.alibaba.cloud.commons.governance.routing.MatchService; +import com.alibaba.cloud.commons.governance.routing.RoutingRule; +import com.alibaba.cloud.commons.governance.routing.UnifiedRoutingDataStructure; +import com.alibaba.cloud.commons.governance.routing.rule.HeaderRoutingRule; +import com.alibaba.cloud.commons.governance.routing.rule.Rule; +import com.alibaba.cloud.commons.governance.routing.rule.UrlRoutingRule; import com.alibaba.cloud.commons.lang.StringUtils; import com.alibaba.cloud.commons.matcher.StringMatcherType; import com.alibaba.cloud.governance.istio.constant.IstioConstants; @@ -54,11 +54,11 @@ public class RoutingXdsResolveFilter if (routeConfigurations == null) { return false; } - Map untiedRouteDataStructures = new HashMap<>(); + Map untiedRouteDataStructures = new HashMap<>(); for (RouteConfiguration routeConfiguration : routeConfigurations) { List virtualHosts = routeConfiguration.getVirtualHostsList(); for (VirtualHost virtualHost : virtualHosts) { - UnifiedRouteDataStructure unifiedRouteDataStructure = new UnifiedRouteDataStructure(); + UnifiedRoutingDataStructure unifiedRouteDataStructure = new UnifiedRoutingDataStructure(); String targetService = ""; String[] serviceAndPort = virtualHost.getName().split(":"); if (serviceAndPort.length > 0) { @@ -69,7 +69,7 @@ public class RoutingXdsResolveFilter } unifiedRouteDataStructure.setTargetService(targetService); List routes = virtualHost.getRoutesList(); - LabelRouteRule labelRouteRule = getRouteData(routes); + RoutingRule labelRouteRule = getRouteData(routes); unifiedRouteDataStructure.setLabelRouteRule(labelRouteRule); untiedRouteDataStructures.put( unifiedRouteDataStructure.getTargetService(), @@ -81,9 +81,9 @@ public class RoutingXdsResolveFilter return true; } - private LabelRouteRule getRouteData(List routes) { + private RoutingRule getRouteData(List routes) { List matchServices = new ArrayList<>(); - LabelRouteRule labelRouteRule = new LabelRouteRule(); + RoutingRule labelRouteRule = new RoutingRule(); for (Route route : routes) { String cluster = route.getRoute().getCluster(); if (StringUtils.isNotEmpty(cluster)) { @@ -122,10 +122,12 @@ public class RoutingXdsResolveFilter return matchService; } - private List match2RouteRules(RouteMatch routeMatch) { - List routeRules = new ArrayList<>(); + private List match2RouteRules( + RouteMatch routeMatch) { + List routeRules = new ArrayList<>(); for (HeaderMatcher headerMatcher : routeMatch.getHeadersList()) { - HeaderRule headerRule = ConvUtil.headerMatcher2HeaderRule(headerMatcher); + HeaderRoutingRule headerRule = ConvUtil + .headerMatcher2HeaderRule(headerMatcher); if (headerRule != null) { routeRules.add(headerRule); } @@ -133,14 +135,14 @@ public class RoutingXdsResolveFilter for (QueryParameterMatcher parameterMatcher : routeMatch .getQueryParametersList()) { - UrlRule.Parameter parameter = ConvUtil + UrlRoutingRule.Parameter parameter = ConvUtil .parameterMatcher2ParameterRule(parameterMatcher); if (parameter != null) { routeRules.add(parameter); } } - UrlRule.Path path = new UrlRule.Path(); + UrlRoutingRule.PathRoutingRule path = new UrlRoutingRule.PathRoutingRule(); path.setType(PATH); switch (routeMatch.getPathSpecifierCase()) { case PREFIX: diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-controlplane-istio/src/main/java/com/alibaba/cloud/governance/istio/util/ConvUtil.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-controlplane-istio/src/main/java/com/alibaba/cloud/governance/istio/util/ConvUtil.java index 8cf84e995..23147fd27 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-controlplane-istio/src/main/java/com/alibaba/cloud/governance/istio/util/ConvUtil.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-controlplane-istio/src/main/java/com/alibaba/cloud/governance/istio/util/ConvUtil.java @@ -16,8 +16,8 @@ package com.alibaba.cloud.governance.istio.util; -import com.alibaba.cloud.commons.governance.labelrouting.rule.HeaderRule; -import com.alibaba.cloud.commons.governance.labelrouting.rule.UrlRule; +import com.alibaba.cloud.commons.governance.routing.rule.HeaderRoutingRule; +import com.alibaba.cloud.commons.governance.routing.rule.UrlRoutingRule; import com.alibaba.cloud.commons.lang.StringUtils; import com.alibaba.cloud.commons.matcher.IpMatcher; import com.alibaba.cloud.commons.matcher.StringMatcher; @@ -125,9 +125,9 @@ public final class ConvUtil { return headerMatcher.getStringMatch(); } - public static UrlRule.Parameter parameterMatcher2ParameterRule( + public static UrlRoutingRule.Parameter parameterMatcher2ParameterRule( QueryParameterMatcher queryParameterMatcher) { - UrlRule.Parameter parameter = new UrlRule.Parameter(); + UrlRoutingRule.Parameter parameter = new UrlRoutingRule.Parameter(); StringMatcher stringMatcher = ConvUtil .convStringMatcher(queryParameterMatcher.getStringMatch()); if (stringMatcher != null) { @@ -140,11 +140,12 @@ public final class ConvUtil { return null; } - public static HeaderRule headerMatcher2HeaderRule(HeaderMatcher headerMatcher) { + public static HeaderRoutingRule headerMatcher2HeaderRule( + HeaderMatcher headerMatcher) { StringMatcher stringMatcher = ConvUtil .convStringMatcher(ConvUtil.headerMatch2StringMatch(headerMatcher)); if (stringMatcher != null) { - HeaderRule headerRule = new HeaderRule(); + HeaderRoutingRule headerRule = new HeaderRoutingRule(); headerRule.setCondition(stringMatcher.getType().toString()); headerRule.setKey(headerMatcher.getName()); headerRule.setValue(stringMatcher.getMatcher()); diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-controlplane-istio/src/test/java/com/alibaba/cloud/governance/istio/XdsRulesTests.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-controlplane-istio/src/test/java/com/alibaba/cloud/governance/istio/XdsRulesTests.java index ac712088a..9aa4d5c69 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-controlplane-istio/src/test/java/com/alibaba/cloud/governance/istio/XdsRulesTests.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-controlplane-istio/src/test/java/com/alibaba/cloud/governance/istio/XdsRulesTests.java @@ -27,9 +27,9 @@ import com.alibaba.cloud.governance.auth.AuthenticationAutoConfiguration; import com.alibaba.cloud.governance.auth.repository.AuthRepository; import com.alibaba.cloud.governance.istio.protocol.impl.LdsProtocol; import com.alibaba.cloud.governance.istio.protocol.impl.RdsProtocol; -import com.alibaba.cloud.router.LabelRoutingAutoConfiguration; -import com.alibaba.cloud.router.repository.FilterService; -import com.alibaba.cloud.router.repository.RouteDataRepository; +import com.alibaba.cloud.routing.RoutingAutoConfiguration; +import com.alibaba.cloud.routing.repository.FilterService; +import com.alibaba.cloud.routing.repository.RoutingDataRepository; import com.fasterxml.jackson.databind.ObjectMapper; import io.envoyproxy.envoy.config.listener.v3.Listener; import io.envoyproxy.envoy.config.route.v3.RouteConfiguration; @@ -71,7 +71,7 @@ public class XdsRulesTests { private AuthRepository authRepository; @Autowired - private RouteDataRepository routeDataRepository; + private RoutingDataRepository routeDataRepository; @Autowired private LdsProtocol ldsProtocol; @@ -133,7 +133,7 @@ public class XdsRulesTests { @Configuration @EnableAutoConfiguration @ImportAutoConfiguration({ XdsAutoConfiguration.class, - AuthenticationAutoConfiguration.class, LabelRoutingAutoConfiguration.class }) + AuthenticationAutoConfiguration.class, RoutingAutoConfiguration.class }) public static class TestConfig { @Bean(name = TARGET_SERVICE + FilterService.FEIGN_CLIENT_BEAN_SPECIFICATION) diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-controlplane-opensergo/src/main/java/com/alibaba/cloud/governance/opensergo/OpenSergoTrafficExchanger.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-controlplane-opensergo/src/main/java/com/alibaba/cloud/governance/opensergo/OpenSergoTrafficExchanger.java index 8f4089135..106d38ec6 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-controlplane-opensergo/src/main/java/com/alibaba/cloud/governance/opensergo/OpenSergoTrafficExchanger.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-controlplane-opensergo/src/main/java/com/alibaba/cloud/governance/opensergo/OpenSergoTrafficExchanger.java @@ -20,7 +20,7 @@ import java.util.Collection; import java.util.List; import com.alibaba.cloud.commons.governance.event.RoutingDataChangedEvent; -import com.alibaba.cloud.commons.governance.labelrouting.UnifiedRouteDataStructure; +import com.alibaba.cloud.commons.governance.routing.UnifiedRoutingDataStructure; import com.alibaba.cloud.commons.lang.StringUtils; import com.alibaba.cloud.governance.opensergo.util.ConvUtils; import com.google.protobuf.InvalidProtocolBufferException; @@ -92,7 +92,7 @@ public class OpenSergoTrafficExchanger implements ApplicationContextAware { log.debug("OpenSergo client subscribeKey:{} receive message :{}", subscribeKey, dataList); try { - Collection rules = openSergoTrafficRouterParser + Collection rules = openSergoTrafficRouterParser .resolveLabelRouting( (List) dataList); applicationContext.publishEvent( diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-controlplane-opensergo/src/main/java/com/alibaba/cloud/governance/opensergo/OpenSergoTrafficRouterParser.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-controlplane-opensergo/src/main/java/com/alibaba/cloud/governance/opensergo/OpenSergoTrafficRouterParser.java index de457e68a..9cf4d42fa 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-controlplane-opensergo/src/main/java/com/alibaba/cloud/governance/opensergo/OpenSergoTrafficRouterParser.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-controlplane-opensergo/src/main/java/com/alibaba/cloud/governance/opensergo/OpenSergoTrafficRouterParser.java @@ -22,12 +22,12 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import com.alibaba.cloud.commons.governance.labelrouting.LabelRouteRule; -import com.alibaba.cloud.commons.governance.labelrouting.MatchService; -import com.alibaba.cloud.commons.governance.labelrouting.UnifiedRouteDataStructure; -import com.alibaba.cloud.commons.governance.labelrouting.rule.HeaderRule; -import com.alibaba.cloud.commons.governance.labelrouting.rule.RouteRule; -import com.alibaba.cloud.commons.governance.labelrouting.rule.UrlRule; +import com.alibaba.cloud.commons.governance.routing.MatchService; +import com.alibaba.cloud.commons.governance.routing.RoutingRule; +import com.alibaba.cloud.commons.governance.routing.UnifiedRoutingDataStructure; +import com.alibaba.cloud.commons.governance.routing.rule.HeaderRoutingRule; +import com.alibaba.cloud.commons.governance.routing.rule.Rule; +import com.alibaba.cloud.commons.governance.routing.rule.UrlRoutingRule; import com.alibaba.cloud.commons.lang.StringUtils; import com.alibaba.cloud.commons.matcher.StringMatcher; import com.alibaba.cloud.commons.matcher.StringMatcherType; @@ -70,17 +70,17 @@ public class OpenSergoTrafficRouterParser { * @return spring cloud alibaba router rules. * @throws InvalidProtocolBufferException transform exception. */ - public Collection resolveLabelRouting( + public Collection resolveLabelRouting( List routeConfigurations) throws InvalidProtocolBufferException { if (routeConfigurations == null) { return new ArrayList<>(); } - Map unifiedRouteDataStructures = new HashMap<>(); + Map unifiedRouteDataStructures = new HashMap<>(); for (RouteConfiguration routeConfiguration : routeConfigurations) { List virtualHosts = routeConfiguration.getVirtualHostsList(); for (VirtualHost virtualHost : virtualHosts) { - UnifiedRouteDataStructure unifiedRouteDataStructure = new UnifiedRouteDataStructure(); + UnifiedRoutingDataStructure unifiedRouteDataStructure = new UnifiedRoutingDataStructure(); String targetService = ""; String[] serviceAndPort = virtualHost.getName().split(":"); if (serviceAndPort.length > 0) { @@ -88,7 +88,7 @@ public class OpenSergoTrafficRouterParser { } unifiedRouteDataStructure.setTargetService(targetService); List routes = virtualHost.getRoutesList(); - LabelRouteRule labelRouteRule = getLabelRouteData(routes); + RoutingRule labelRouteRule = getLabelRouteData(routes); unifiedRouteDataStructure.setLabelRouteRule(labelRouteRule); unifiedRouteDataStructures.put( unifiedRouteDataStructure.getTargetService(), @@ -98,10 +98,10 @@ public class OpenSergoTrafficRouterParser { return unifiedRouteDataStructures.values(); } - private LabelRouteRule getLabelRouteData(List routes) + private RoutingRule getLabelRouteData(List routes) throws InvalidProtocolBufferException { List matchServices = new ArrayList<>(); - LabelRouteRule labelRouteRule = new LabelRouteRule(); + RoutingRule labelRouteRule = new RoutingRule(); for (Route route : routes) { ClusterSpecifierPlugin clusterSpecifierPlugin = route.getRoute() .getInlineClusterSpecifierPlugin(); @@ -175,10 +175,10 @@ public class OpenSergoTrafficRouterParser { return version; } - private List match2RouteRules(RouteMatch routeMatch) { - List routeRules = new ArrayList<>(); + private List match2RouteRules(RouteMatch routeMatch) { + List routeRules = new ArrayList<>(); for (HeaderMatcher headerMatcher : routeMatch.getHeadersList()) { - HeaderRule headerRule = headerMatcher2HeaderRule(headerMatcher); + HeaderRoutingRule headerRule = headerMatcher2HeaderRule(headerMatcher); if (headerRule != null) { routeRules.add(headerRule); } @@ -186,14 +186,14 @@ public class OpenSergoTrafficRouterParser { for (QueryParameterMatcher parameterMatcher : routeMatch .getQueryParametersList()) { - UrlRule.Parameter parameter = parameterMatcher2ParameterRule( + UrlRoutingRule.Parameter parameter = parameterMatcher2ParameterRule( parameterMatcher); if (parameter != null) { routeRules.add(parameter); } } - UrlRule.Path path = new UrlRule.Path(); + UrlRoutingRule.PathRoutingRule path = new UrlRoutingRule.PathRoutingRule(); path.setType(PATH); switch (routeMatch.getPathSpecifierCase()) { case PREFIX: @@ -222,9 +222,9 @@ public class OpenSergoTrafficRouterParser { return routeRules; } - private UrlRule.Parameter parameterMatcher2ParameterRule( + private UrlRoutingRule.Parameter parameterMatcher2ParameterRule( QueryParameterMatcher queryParameterMatcher) { - UrlRule.Parameter parameter = new UrlRule.Parameter(); + UrlRoutingRule.Parameter parameter = new UrlRoutingRule.Parameter(); StringMatcher stringMatcher = ConvUtils .convStringMatcher(queryParameterMatcher.getStringMatch()); if (stringMatcher != null) { @@ -237,11 +237,11 @@ public class OpenSergoTrafficRouterParser { return null; } - private HeaderRule headerMatcher2HeaderRule(HeaderMatcher headerMatcher) { + private HeaderRoutingRule headerMatcher2HeaderRule(HeaderMatcher headerMatcher) { StringMatcher stringMatcher = ConvUtils .convStringMatcher(ConvUtils.headerMatch2StringMatch(headerMatcher)); if (stringMatcher != null) { - HeaderRule headerRule = new HeaderRule(); + HeaderRoutingRule headerRule = new HeaderRoutingRule(); headerRule.setCondition(stringMatcher.getType().toString()); headerRule.setKey(headerMatcher.getName()); headerRule.setValue(stringMatcher.getMatcher()); diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-controlplane-opensergo/src/test/java/com/alibaba/cloud/governance/opensergo/OpenSergoRuleTests.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-controlplane-opensergo/src/test/java/com/alibaba/cloud/governance/opensergo/OpenSergoRuleTests.java index d53202f89..77fcbcc76 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-controlplane-opensergo/src/test/java/com/alibaba/cloud/governance/opensergo/OpenSergoRuleTests.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-controlplane-opensergo/src/test/java/com/alibaba/cloud/governance/opensergo/OpenSergoRuleTests.java @@ -20,7 +20,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; -import com.alibaba.cloud.commons.governance.labelrouting.UnifiedRouteDataStructure; +import com.alibaba.cloud.commons.governance.routing.UnifiedRoutingDataStructure; import io.envoyproxy.envoy.config.route.v3.HeaderMatcher; import io.envoyproxy.envoy.config.route.v3.Route; import io.envoyproxy.envoy.config.route.v3.RouteAction; @@ -62,7 +62,7 @@ public class OpenSergoRuleTests { .setName("service-provider").addVirtualHosts(virtualHost).build(); List routeConfigurations = new ArrayList<>(); routeConfigurations.add(routeConfiguration); - Collection rules = openSergoTrafficRouterParser + Collection rules = openSergoTrafficRouterParser .resolveLabelRouting(routeConfigurations); Assert.assertEquals(rules.size(), 1); } diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/LabelRoutingAutoConfiguration.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/RoutingAutoConfiguration.java similarity index 62% rename from spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/LabelRoutingAutoConfiguration.java rename to spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/RoutingAutoConfiguration.java index 4c4d4e359..979d857fa 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/LabelRoutingAutoConfiguration.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/RoutingAutoConfiguration.java @@ -14,11 +14,11 @@ * limitations under the License. */ -package com.alibaba.cloud.router; +package com.alibaba.cloud.routing; -import com.alibaba.cloud.router.listener.LabelRouteDataListener; -import com.alibaba.cloud.router.repository.FilterService; -import com.alibaba.cloud.router.repository.RouteDataRepository; +import com.alibaba.cloud.routing.listener.RoutingDataListener; +import com.alibaba.cloud.routing.repository.FilterService; +import com.alibaba.cloud.routing.repository.RoutingDataRepository; import org.springframework.boot.autoconfigure.AutoConfigureOrder; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -30,18 +30,18 @@ import org.springframework.context.annotation.Configuration; * @since 2.2.10-RC1 */ @Configuration(proxyBeanMethods = false) -@AutoConfigureOrder(LabelRoutingAutoConfiguration.LABEL_ROUTING_AUTO_CONFIG_ORDER) -public class LabelRoutingAutoConfiguration { +@AutoConfigureOrder(RoutingAutoConfiguration.ROUTING_AUTO_CONFIG_ORDER) +public class RoutingAutoConfiguration { /** * Order of label routing auto config. */ - public static final int LABEL_ROUTING_AUTO_CONFIG_ORDER = 10; + public static final int ROUTING_AUTO_CONFIG_ORDER = 10; @Bean @ConditionalOnMissingBean - public RouteDataRepository routeDataRepository() { - return new RouteDataRepository(); + public RoutingDataRepository routingDataRepository() { + return new RoutingDataRepository(); } @Bean @@ -51,9 +51,9 @@ public class LabelRoutingAutoConfiguration { } @Bean - public LabelRouteDataListener labelRouteDataListener( - RouteDataRepository routeDataRepository, FilterService filterService) { - return new LabelRouteDataListener(routeDataRepository, filterService); + public RoutingDataListener routingDataListener( + RoutingDataRepository routingDataRepository, FilterService filterService) { + return new RoutingDataListener(routingDataRepository, filterService); } } diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/RouterProperties.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/RoutingProperties.java similarity index 88% rename from spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/RouterProperties.java rename to spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/RoutingProperties.java index 8b05d296b..a953d133c 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/RouterProperties.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/RoutingProperties.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.alibaba.cloud.router; +package com.alibaba.cloud.routing; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -22,8 +22,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; * @author HH * @since 2.2.10-RC1 */ -@ConfigurationProperties(prefix = RouterProperties.PROPERTY_PREFIX) -public class RouterProperties { +@ConfigurationProperties(prefix = RoutingProperties.PROPERTY_PREFIX) +public class RoutingProperties { /** * Properties prefix. diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/RouterPropertiesAutoConfiguration.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/RoutingPropertiesAutoConfiguration.java similarity index 79% rename from spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/RouterPropertiesAutoConfiguration.java rename to spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/RoutingPropertiesAutoConfiguration.java index a4f935474..93bb98b3f 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/RouterPropertiesAutoConfiguration.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/RoutingPropertiesAutoConfiguration.java @@ -14,9 +14,9 @@ * limitations under the License. */ -package com.alibaba.cloud.router; +package com.alibaba.cloud.routing; -import com.alibaba.cloud.router.publish.TargetServiceChangedPublisher; +import com.alibaba.cloud.routing.publish.TargetServiceChangedPublisher; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.properties.EnableConfigurationProperties; @@ -28,13 +28,13 @@ import org.springframework.context.annotation.Configuration; * @since 2.2.10-RC1 */ @Configuration(proxyBeanMethods = false) -@EnableConfigurationProperties({ RouterProperties.class }) -public class RouterPropertiesAutoConfiguration { +@EnableConfigurationProperties({ RoutingProperties.class }) +public class RoutingPropertiesAutoConfiguration { @Bean @ConditionalOnMissingBean - public RouterProperties routerProperties() { - return new RouterProperties(); + public RoutingProperties routingProperties() { + return new RoutingProperties(); } @Bean diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/feign/FeignInterceptor.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/feign/RoutingFeignInterceptor.java similarity index 83% rename from spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/feign/FeignInterceptor.java rename to spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/feign/RoutingFeignInterceptor.java index abb5cad8b..ccd888919 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/feign/FeignInterceptor.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/feign/RoutingFeignInterceptor.java @@ -14,13 +14,13 @@ * limitations under the License. */ -package com.alibaba.cloud.router.feign; +package com.alibaba.cloud.routing.feign; import java.util.Enumeration; import javax.servlet.http.HttpServletRequest; -import com.alibaba.cloud.router.util.RequestContext; +import com.alibaba.cloud.routing.util.RequestContext; import feign.RequestInterceptor; import feign.RequestTemplate; import org.slf4j.Logger; @@ -30,9 +30,10 @@ import org.slf4j.LoggerFactory; * @author HH * @since 2.2.10-RC1 */ -public class FeignInterceptor implements RequestInterceptor { +public class RoutingFeignInterceptor implements RequestInterceptor { - private static final Logger LOG = LoggerFactory.getLogger(FeignInterceptor.class); + private static final Logger LOG = LoggerFactory + .getLogger(RoutingFeignInterceptor.class); @Override public void apply(RequestTemplate requestTemplate) { diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/feign/FeignInterceptorAutoConfiguration.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/feign/RoutingFeignInterceptorAutoConfiguration.java similarity index 82% rename from spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/feign/FeignInterceptorAutoConfiguration.java rename to spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/feign/RoutingFeignInterceptorAutoConfiguration.java index f04efc8f0..b06edee58 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/feign/FeignInterceptorAutoConfiguration.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/feign/RoutingFeignInterceptorAutoConfiguration.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.alibaba.cloud.router.feign; +package com.alibaba.cloud.routing.feign; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Bean; @@ -25,12 +25,12 @@ import org.springframework.context.annotation.Configuration; * @since 2.2.10-RC1 */ @Configuration(proxyBeanMethods = false) -public class FeignInterceptorAutoConfiguration { +public class RoutingFeignInterceptorAutoConfiguration { @Bean @ConditionalOnMissingBean - public FeignInterceptor feignInterceptor() { - return new FeignInterceptor(); + public RoutingFeignInterceptor routingFeignInterceptor() { + return new RoutingFeignInterceptor(); } } diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/listener/LabelRouteDataListener.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/listener/RoutingDataListener.java similarity index 64% rename from spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/listener/LabelRouteDataListener.java rename to spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/listener/RoutingDataListener.java index 7ef45fe1b..2216a65f2 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/listener/LabelRouteDataListener.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/listener/RoutingDataListener.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.alibaba.cloud.router.listener; +package com.alibaba.cloud.routing.listener; import java.util.Collection; import java.util.HashSet; @@ -22,9 +22,9 @@ import java.util.List; import java.util.stream.Collectors; import com.alibaba.cloud.commons.governance.event.RoutingDataChangedEvent; -import com.alibaba.cloud.commons.governance.labelrouting.UnifiedRouteDataStructure; -import com.alibaba.cloud.router.repository.FilterService; -import com.alibaba.cloud.router.repository.RouteDataRepository; +import com.alibaba.cloud.commons.governance.routing.UnifiedRoutingDataStructure; +import com.alibaba.cloud.routing.repository.FilterService; +import com.alibaba.cloud.routing.repository.RoutingDataRepository; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,39 +35,37 @@ import org.springframework.context.ApplicationListener; * @author * @since 2.2.10-RC1 */ -public class LabelRouteDataListener - implements ApplicationListener { +public class RoutingDataListener implements ApplicationListener { - private static final Logger log = LoggerFactory - .getLogger(LabelRouteDataListener.class); + private static final Logger log = LoggerFactory.getLogger(RoutingDataListener.class); - private RouteDataRepository routeDataRepository; + private RoutingDataRepository routingDataRepository; private FilterService filterService; - public LabelRouteDataListener(RouteDataRepository routeDataRepository, + public RoutingDataListener(RoutingDataRepository routeDataRepository, FilterService filterService) { - this.routeDataRepository = routeDataRepository; + this.routingDataRepository = routeDataRepository; this.filterService = filterService; } @Override public void onApplicationEvent(RoutingDataChangedEvent event) { try { - Collection untiedRouterDataStructureList = event + Collection unifiedRoutingDataStructureList = event .getUntiedRouterDataStructureList(); // Filter service. // todo can cache the result HashSet definitionFeignService = filterService - .getDefinitionFeignService(untiedRouterDataStructureList.size()); - List routeDatalist = untiedRouterDataStructureList + .getDefinitionFeignService(unifiedRoutingDataStructureList.size()); + List routeDatalist = unifiedRoutingDataStructureList .stream() .filter(unifiedRouteDataStructure -> definitionFeignService .contains(unifiedRouteDataStructure.getTargetService())) .collect(Collectors.toList()); - routeDataRepository.updateRouteData(routeDatalist); + routingDataRepository.updateRouteData(routeDatalist); } catch (Exception e) { log.error("Failed to update route data", e); diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/publish/TargetServiceChangedPublisher.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/publish/TargetServiceChangedPublisher.java similarity index 97% rename from spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/publish/TargetServiceChangedPublisher.java rename to spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/publish/TargetServiceChangedPublisher.java index 806aa022e..f74d7af40 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/publish/TargetServiceChangedPublisher.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/publish/TargetServiceChangedPublisher.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.alibaba.cloud.router.publish; +package com.alibaba.cloud.routing.publish; import java.util.concurrent.ConcurrentHashMap; diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/repository/FilterService.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/repository/FilterService.java similarity index 98% rename from spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/repository/FilterService.java rename to spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/repository/FilterService.java index 51b3b36cb..39f7fb1b0 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/repository/FilterService.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/repository/FilterService.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.alibaba.cloud.router.repository; +package com.alibaba.cloud.routing.repository; import java.util.HashSet; diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/repository/RouteDataRepository.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/repository/RoutingDataRepository.java similarity index 77% rename from spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/repository/RouteDataRepository.java rename to spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/repository/RoutingDataRepository.java index 0c210e73e..bc4537078 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/repository/RouteDataRepository.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/repository/RoutingDataRepository.java @@ -14,17 +14,17 @@ * limitations under the License. */ -package com.alibaba.cloud.router.repository; +package com.alibaba.cloud.routing.repository; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.concurrent.ConcurrentHashMap; -import com.alibaba.cloud.commons.governance.labelrouting.LabelRouteRule; -import com.alibaba.cloud.commons.governance.labelrouting.MatchService; -import com.alibaba.cloud.commons.governance.labelrouting.UnifiedRouteDataStructure; -import com.alibaba.cloud.commons.governance.labelrouting.rule.RouteRule; +import com.alibaba.cloud.commons.governance.routing.MatchService; +import com.alibaba.cloud.commons.governance.routing.RoutingRule; +import com.alibaba.cloud.commons.governance.routing.UnifiedRoutingDataStructure; +import com.alibaba.cloud.commons.governance.routing.rule.Rule; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,12 +34,13 @@ import org.springframework.util.CollectionUtils; * @author HH * @since 2.2.10-RC1 */ -public class RouteDataRepository { +public class RoutingDataRepository { - private static final Logger LOG = LoggerFactory.getLogger(RouteDataRepository.class); + private static final Logger LOG = LoggerFactory + .getLogger(RoutingDataRepository.class); /** - * Key is service name,value is hashmap,which key is single RouteRule key,value is + * Key is service name,value is hashmap,which key is single RoutingRule key,value is * match service. Use double hash index to parse route rule. */ private ConcurrentHashMap>> routeCache = new ConcurrentHashMap<>(); @@ -47,7 +48,7 @@ public class RouteDataRepository { /** * The default version of each service. */ - private ConcurrentHashMap defaultRouteVersion = new ConcurrentHashMap<>(); + private ConcurrentHashMap defaultRoutingVersion = new ConcurrentHashMap<>(); /** * Sign of path. @@ -74,13 +75,13 @@ public class RouteDataRepository { */ public static final int MIN_WEIGHT = 0; - public void updateRouteData(final List routeDataList) { + public void updateRouteData(final List routeDataList) { ConcurrentHashMap>> newRouteCache = new ConcurrentHashMap<>(); ConcurrentHashMap> newPathRuleMap = new ConcurrentHashMap<>(); - for (UnifiedRouteDataStructure routeData : routeDataList) { + for (UnifiedRoutingDataStructure routeData : routeDataList) { nonNullCheck(routeData); buildHashIndex(routeData, newRouteCache, newPathRuleMap); - defaultRouteVersion.put(routeData.getTargetService(), + defaultRoutingVersion.put(routeData.getTargetService(), routeData.getLabelRouteRule().getDefaultRouteVersion()); } // Replace it atomically @@ -88,16 +89,16 @@ public class RouteDataRepository { this.pathRuleMap = newPathRuleMap; } - private void nonNullCheck(UnifiedRouteDataStructure unifiedRouteDataStructure) { - String targetService = unifiedRouteDataStructure.getTargetService(); + private void nonNullCheck(UnifiedRoutingDataStructure unifiedRoutingDataStructure) { + String targetService = unifiedRoutingDataStructure.getTargetService(); if (targetService == null) { LOG.error("Lose target Service name."); } - final LabelRouteRule labelRouteData = unifiedRouteDataStructure + final RoutingRule labelRouteData = unifiedRoutingDataStructure .getLabelRouteRule(); final List matchServiceList = labelRouteData.getMatchRouteList(); for (MatchService matchService : matchServiceList) { - final List ruleList = matchService.getRuleList(); + final List ruleList = matchService.getRuleList(); String version = matchService.getVersion(); Integer weight = matchService.getWeight(); if (CollectionUtils.isEmpty(ruleList)) { @@ -118,7 +119,7 @@ public class RouteDataRepository { } } - private void buildHashIndex(final UnifiedRouteDataStructure routerData, + private void buildHashIndex(final UnifiedRoutingDataStructure routerData, ConcurrentHashMap>> newRouteCache, ConcurrentHashMap> newPathRuleMap) { final List matchRouteList = routerData.getLabelRouteRule() @@ -126,7 +127,7 @@ public class RouteDataRepository { HashMap> singleRuleMap = new HashMap<>(); for (MatchService matchService : matchRouteList) { - List ruleList = matchService.getRuleList(); + List ruleList = matchService.getRuleList(); // Take out the path label separately, because there is no key for hash index. if (ruleList.size() == 1 @@ -140,7 +141,7 @@ public class RouteDataRepository { newPathRuleMap.put(routerData.getTargetService(), matchServiceList); continue; } - for (RouteRule routeRule : ruleList) { + for (Rule routeRule : ruleList) { List matchServiceList = singleRuleMap .get(routeRule.getKey()); if (matchServiceList == null) { @@ -160,7 +161,7 @@ public class RouteDataRepository { } public String getDefaultRouteVersion(String targetService) { - return defaultRouteVersion.get(targetService); + return defaultRoutingVersion.get(targetService); } public List getPathRules(String targetService) { diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/ribbon/LabelRouteLBRule.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/ribbon/RoutingLoadBalanceRule.java similarity index 87% rename from spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/ribbon/LabelRouteLBRule.java rename to spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/ribbon/RoutingLoadBalanceRule.java index 5bdd2596b..0e8205681 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/ribbon/LabelRouteLBRule.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/ribbon/RoutingLoadBalanceRule.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.alibaba.cloud.router.ribbon; +package com.alibaba.cloud.routing.ribbon; import java.util.ArrayList; import java.util.Arrays; @@ -27,17 +27,17 @@ import java.util.concurrent.ThreadLocalRandom; import javax.servlet.http.HttpServletRequest; -import com.alibaba.cloud.commons.governance.labelrouting.MatchService; -import com.alibaba.cloud.commons.governance.labelrouting.rule.RouteRule; +import com.alibaba.cloud.commons.governance.routing.MatchService; +import com.alibaba.cloud.commons.governance.routing.rule.Rule; import com.alibaba.cloud.nacos.NacosDiscoveryProperties; import com.alibaba.cloud.nacos.NacosServiceManager; import com.alibaba.cloud.nacos.ribbon.NacosServer; -import com.alibaba.cloud.router.RouterProperties; -import com.alibaba.cloud.router.publish.TargetServiceChangedPublisher; -import com.alibaba.cloud.router.repository.RouteDataRepository; -import com.alibaba.cloud.router.util.ConditionMatchUtil; -import com.alibaba.cloud.router.util.LoadBalanceUtil; -import com.alibaba.cloud.router.util.RequestContext; +import com.alibaba.cloud.routing.RoutingProperties; +import com.alibaba.cloud.routing.publish.TargetServiceChangedPublisher; +import com.alibaba.cloud.routing.repository.RoutingDataRepository; +import com.alibaba.cloud.routing.util.ConditionMatchUtil; +import com.alibaba.cloud.routing.util.LoadBalanceUtil; +import com.alibaba.cloud.routing.util.RequestContext; import com.alibaba.nacos.api.naming.NamingService; import com.alibaba.nacos.api.naming.pojo.Instance; import com.netflix.loadbalancer.AbstractServerPredicate; @@ -54,9 +54,10 @@ import org.springframework.util.CollectionUtils; * @author HH * @since 2.2.10-RC1 */ -public class LabelRouteLBRule extends PredicateBasedRule { +public class RoutingLoadBalanceRule extends PredicateBasedRule { - private static final Logger LOG = LoggerFactory.getLogger(LabelRouteLBRule.class); + private static final Logger LOG = LoggerFactory + .getLogger(RoutingLoadBalanceRule.class); /** * Support Parsing Rules from path,only URI at present. @@ -110,10 +111,10 @@ public class LabelRouteLBRule extends PredicateBasedRule { private NacosServiceManager nacosServiceManager; @Autowired - private RouteDataRepository routeDataRepository; + private RoutingDataRepository routingDataRepository; @Autowired - private RouterProperties routerProperties; + private RoutingProperties routingProperties; @Autowired private TargetServiceChangedPublisher targetServiceChangedPublisher; @@ -126,11 +127,11 @@ public class LabelRouteLBRule extends PredicateBasedRule { targetServiceChangedPublisher.addTargetService(targetServiceName); // If routeData isn't present, use normal load balance rule. - final HashMap> routeData = routeDataRepository + final HashMap> routeData = routingDataRepository .getRouteRule(targetServiceName); if (routeData == null) { return loadBalanceUtil.loadBalanceByOrdinaryRule(loadBalancer, key, - routerProperties.getRule()); + routingProperties.getRule()); } // Get instances from register-center. @@ -214,7 +215,7 @@ public class LabelRouteLBRule extends PredicateBasedRule { } } final Map parameterMap = request.getParameterMap(); - int defaultVersionWeight = RouteDataRepository.SUM_WEIGHT; + int defaultVersionWeight = RoutingDataRepository.SUM_WEIGHT; boolean isMatch = false; // Parse rule. @@ -244,7 +245,7 @@ public class LabelRouteLBRule extends PredicateBasedRule { } } - final List pathRules = routeDataRepository + final List pathRules = routingDataRepository .getPathRules(targetServiceName); if (!isMatch && pathRules != null) { for (MatchService matchService : pathRules) { @@ -260,8 +261,8 @@ public class LabelRouteLBRule extends PredicateBasedRule { } // Add default route - if (defaultVersionWeight > RouteDataRepository.MIN_WEIGHT) { - String defaultRouteVersion = routeDataRepository + if (defaultVersionWeight > RoutingDataRepository.MIN_WEIGHT) { + String defaultRouteVersion = routingDataRepository .getDefaultRouteVersion(targetServiceName); versionSet.add(defaultRouteVersion); weightMap.put(defaultRouteVersion, defaultVersionWeight); @@ -275,18 +276,18 @@ public class LabelRouteLBRule extends PredicateBasedRule { HashSet versionSet, HashMap weightMap, HashSet fallbackVersionSet, HashMap fallbackWeightMap) { - final List matchServiceList = routeDataRepository + final List matchServiceList = routingDataRepository .getRouteRule(targetServiceName).get(keyName); if (matchServiceList == null) { return NO_MATCH; } for (MatchService matchService : matchServiceList) { - final List ruleList = matchService.getRuleList(); + final List ruleList = matchService.getRuleList(); String version = matchService.getVersion(); Integer weight = matchService.getWeight(); String fallback = matchService.getFallback(); boolean isMatchRule = true; - for (RouteRule routeRule : ruleList) { + for (Rule routeRule : ruleList) { String type = routeRule.getType(); switch (type) { case PATH: @@ -318,7 +319,7 @@ public class LabelRouteLBRule extends PredicateBasedRule { return NO_MATCH; } - private boolean parseRequestPath(final RouteRule routeRule, + private boolean parseRequestPath(final Rule routeRule, final HttpServletRequest request) { String condition = routeRule.getCondition(); String value = routeRule.getValue(); @@ -326,7 +327,7 @@ public class LabelRouteLBRule extends PredicateBasedRule { return conditionMatch(condition, value, uri); } - private boolean parseRequestHeader(final RouteRule routeRule, + private boolean parseRequestHeader(final Rule routeRule, final HashMap requestHeaders) { if (requestHeaders.size() == 0) { return false; @@ -337,7 +338,7 @@ public class LabelRouteLBRule extends PredicateBasedRule { return conditionMatch(condition, value, headerValue); } - private boolean parseRequestParameter(final RouteRule routeRule, + private boolean parseRequestParameter(final Rule routeRule, final Map parameterMap) { if (parameterMap == null || parameterMap.size() == 0) { return false; @@ -389,12 +390,12 @@ public class LabelRouteLBRule extends PredicateBasedRule { } } - if (sum > RouteDataRepository.SUM_WEIGHT) { - LOG.error("Sum of weight has over {} ", RouteDataRepository.SUM_WEIGHT); + if (sum > RoutingDataRepository.SUM_WEIGHT) { + LOG.error("Sum of weight has over {} ", RoutingDataRepository.SUM_WEIGHT); } double random = ThreadLocalRandom.current().nextDouble( - RouteDataRepository.MIN_WEIGHT, RouteDataRepository.SUM_WEIGHT); + RoutingDataRepository.MIN_WEIGHT, RoutingDataRepository.SUM_WEIGHT); int chooseServiceIndex = Arrays.binarySearch(weightArray, random); if (chooseServiceIndex < 0) { chooseServiceIndex = -chooseServiceIndex - 1; diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/ribbon/LabelRouteLBRuleAutoConfiguration.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/ribbon/RoutingLoadBalanceRuleAutoConfiguration.java similarity index 82% rename from spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/ribbon/LabelRouteLBRuleAutoConfiguration.java rename to spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/ribbon/RoutingLoadBalanceRuleAutoConfiguration.java index 85f8c6e44..f9c453d65 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/ribbon/LabelRouteLBRuleAutoConfiguration.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/ribbon/RoutingLoadBalanceRuleAutoConfiguration.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.alibaba.cloud.router.ribbon; +package com.alibaba.cloud.routing.ribbon; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Bean; @@ -25,12 +25,12 @@ import org.springframework.context.annotation.Configuration; * @since 2.2.10-RC1 */ @Configuration(proxyBeanMethods = false) -public class LabelRouteLBRuleAutoConfiguration { +public class RoutingLoadBalanceRuleAutoConfiguration { @Bean @ConditionalOnMissingBean - public LabelRouteLBRule labelRouteRule() { - return new LabelRouteLBRule(); + public RoutingLoadBalanceRule routingLoadBalanceRule() { + return new RoutingLoadBalanceRule(); } } diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/util/ConditionMatchUtil.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/util/ConditionMatchUtil.java similarity index 98% rename from spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/util/ConditionMatchUtil.java rename to spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/util/ConditionMatchUtil.java index c972865ed..918461f57 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/util/ConditionMatchUtil.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/util/ConditionMatchUtil.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.alibaba.cloud.router.util; +package com.alibaba.cloud.routing.util; import java.util.regex.Pattern; diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/util/LoadBalanceUtil.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/util/LoadBalanceUtil.java similarity index 98% rename from spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/util/LoadBalanceUtil.java rename to spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/util/LoadBalanceUtil.java index e759f760c..5f89c0495 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/util/LoadBalanceUtil.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/util/LoadBalanceUtil.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.alibaba.cloud.router.util; +package com.alibaba.cloud.routing.util; import com.netflix.loadbalancer.AvailabilityFilteringRule; import com.netflix.loadbalancer.BestAvailableRule; diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/util/RequestContext.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/util/RequestContext.java similarity index 97% rename from spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/util/RequestContext.java rename to spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/util/RequestContext.java index e4839d227..7bdcbc720 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/util/RequestContext.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/util/RequestContext.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.alibaba.cloud.router.util; +package com.alibaba.cloud.routing.util; import javax.servlet.http.HttpServletRequest; diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/web/WebMvcAutoConfiguration.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/web/WebMvcAutoConfiguration.java similarity index 96% rename from spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/web/WebMvcAutoConfiguration.java rename to spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/web/WebMvcAutoConfiguration.java index ef3c1cd05..a89590f72 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/web/WebMvcAutoConfiguration.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/web/WebMvcAutoConfiguration.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.alibaba.cloud.router.web; +package com.alibaba.cloud.routing.web; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Bean; diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/web/WebMvcConfig.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/web/WebMvcConfig.java similarity index 96% rename from spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/web/WebMvcConfig.java rename to spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/web/WebMvcConfig.java index 93c0a1a38..a2ddf867a 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/web/WebMvcConfig.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/web/WebMvcConfig.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.alibaba.cloud.router.web; +package com.alibaba.cloud.routing.web; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/web/WebMvcInterceptor.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/web/WebMvcInterceptor.java similarity index 93% rename from spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/web/WebMvcInterceptor.java rename to spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/web/WebMvcInterceptor.java index 0d90e56b0..e501bb3f9 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/router/web/WebMvcInterceptor.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/java/com/alibaba/cloud/routing/web/WebMvcInterceptor.java @@ -14,12 +14,12 @@ * limitations under the License. */ -package com.alibaba.cloud.router.web; +package com.alibaba.cloud.routing.web; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import com.alibaba.cloud.router.util.RequestContext; +import com.alibaba.cloud.routing.util.RequestContext; import org.springframework.lang.Nullable; import org.springframework.web.servlet.HandlerInterceptor; diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/resources/META-INF/spring.factories b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/resources/META-INF/spring.factories index 8c8247703..42bcdb73a 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/resources/META-INF/spring.factories +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-governance-routing/src/main/resources/META-INF/spring.factories @@ -1,6 +1,6 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ - com.alibaba.cloud.router.LabelRoutingAutoConfiguration,\ - com.alibaba.cloud.router.feign.FeignInterceptorAutoConfiguration,\ - com.alibaba.cloud.router.ribbon.LabelRouteLBRuleAutoConfiguration,\ - com.alibaba.cloud.router.web.WebMvcAutoConfiguration,\ - com.alibaba.cloud.router.RouterPropertiesAutoConfiguration \ No newline at end of file + com.alibaba.cloud.routing.RoutingAutoConfiguration,\ + com.alibaba.cloud.routing.feign.RoutingFeignInterceptorAutoConfiguration,\ + com.alibaba.cloud.routing.ribbon.RoutingLoadBalanceRuleAutoConfiguration,\ + com.alibaba.cloud.routing.web.WebMvcAutoConfiguration,\ + com.alibaba.cloud.routing.RoutingPropertiesAutoConfiguration