Adapt polaris-java 1.10.1 version (#747)

pull/751/head
lepdou 2 years ago committed by GitHub
parent fb3c2c439f
commit e4a288b056
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -12,3 +12,4 @@
- [Code optimization & correct comment](https://github.com/Tencent/spring-cloud-tencent/pull/724) - [Code optimization & correct comment](https://github.com/Tencent/spring-cloud-tencent/pull/724)
- [fix:fix javadoc.](https://github.com/Tencent/spring-cloud-tencent/pull/727) - [fix:fix javadoc.](https://github.com/Tencent/spring-cloud-tencent/pull/727)
- [fix:fix discovery junit.](https://github.com/Tencent/spring-cloud-tencent/pull/729) - [fix:fix discovery junit.](https://github.com/Tencent/spring-cloud-tencent/pull/729)
- [adapt polaris-java 1.10.1 version](https://github.com/Tencent/spring-cloud-tencent/pull/747)

@ -61,6 +61,7 @@ public class PolarisDiscoveryHandler {
GetHealthyInstancesRequest getHealthyInstancesRequest = new GetHealthyInstancesRequest(); GetHealthyInstancesRequest getHealthyInstancesRequest = new GetHealthyInstancesRequest();
getHealthyInstancesRequest.setNamespace(namespace); getHealthyInstancesRequest.setNamespace(namespace);
getHealthyInstancesRequest.setService(service); getHealthyInstancesRequest.setService(service);
getHealthyInstancesRequest.setIncludeCircuitBreakInstances(false);
return polarisConsumer.getHealthyInstances(getHealthyInstancesRequest); return polarisConsumer.getHealthyInstances(getHealthyInstancesRequest);
} }

@ -18,6 +18,7 @@
package com.tencent.cloud.polaris.router.interceptor; package com.tencent.cloud.polaris.router.interceptor;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -25,9 +26,12 @@ import com.tencent.cloud.common.constant.RouterConstant;
import com.tencent.cloud.polaris.router.PolarisRouterContext; import com.tencent.cloud.polaris.router.PolarisRouterContext;
import com.tencent.cloud.polaris.router.config.properties.PolarisMetadataRouterProperties; import com.tencent.cloud.polaris.router.config.properties.PolarisMetadataRouterProperties;
import com.tencent.cloud.polaris.router.spi.RouterRequestInterceptor; import com.tencent.cloud.polaris.router.spi.RouterRequestInterceptor;
import com.tencent.polaris.api.pojo.RouteArgument;
import com.tencent.polaris.plugins.router.metadata.MetadataRouter; import com.tencent.polaris.plugins.router.metadata.MetadataRouter;
import com.tencent.polaris.router.api.rpc.ProcessRoutersRequest; import com.tencent.polaris.router.api.rpc.ProcessRoutersRequest;
import org.springframework.util.CollectionUtils;
/** /**
* Router request interceptor for metadata router. * Router request interceptor for metadata router.
* @author lepdou 2022-07-06 * @author lepdou 2022-07-06
@ -53,6 +57,12 @@ public class MetadataRouterRequestInterceptor implements RouterRequestIntercepto
Map<String, String> metadataRouterLabels = routerContext.getLabels(RouterConstant.ROUTER_LABELS, Map<String, String> metadataRouterLabels = routerContext.getLabels(RouterConstant.ROUTER_LABELS,
metadataRouterKeys); metadataRouterKeys);
// 3. set metadata router labels to request // 3. set metadata router labels to request
request.addRouterMetadata(MetadataRouter.ROUTER_TYPE_METADATA, metadataRouterLabels); Set<RouteArgument> routeArguments = new HashSet<>();
if (!CollectionUtils.isEmpty(metadataRouterKeys)) {
for (Map.Entry<String, String> entry : metadataRouterLabels.entrySet()) {
routeArguments.add(RouteArgument.buildCustom(entry.getKey(), entry.getValue()));
}
}
request.putRouterArgument(MetadataRouter.ROUTER_TYPE_METADATA, routeArguments);
} }
} }

@ -18,12 +18,13 @@
package com.tencent.cloud.polaris.router.interceptor; package com.tencent.cloud.polaris.router.interceptor;
import java.util.HashMap; import java.util.HashSet;
import java.util.Map; import java.util.Set;
import com.tencent.cloud.polaris.router.PolarisRouterContext; import com.tencent.cloud.polaris.router.PolarisRouterContext;
import com.tencent.cloud.polaris.router.config.properties.PolarisNearByRouterProperties; import com.tencent.cloud.polaris.router.config.properties.PolarisNearByRouterProperties;
import com.tencent.cloud.polaris.router.spi.RouterRequestInterceptor; import com.tencent.cloud.polaris.router.spi.RouterRequestInterceptor;
import com.tencent.polaris.api.pojo.RouteArgument;
import com.tencent.polaris.plugins.router.nearby.NearbyRouter; import com.tencent.polaris.plugins.router.nearby.NearbyRouter;
import com.tencent.polaris.router.api.rpc.ProcessRoutersRequest; import com.tencent.polaris.router.api.rpc.ProcessRoutersRequest;
@ -45,9 +46,9 @@ public class NearbyRouterRequestInterceptor implements RouterRequestInterceptor
return; return;
} }
Map<String, String> nearbyRouterMetadata = new HashMap<>(); Set<RouteArgument> routeArguments = new HashSet<>(1);
nearbyRouterMetadata.put(NearbyRouter.ROUTER_ENABLED, "true"); routeArguments.add(RouteArgument.buildCustom(NearbyRouter.ROUTER_ENABLED, "true"));
request.addRouterMetadata(NearbyRouter.ROUTER_TYPE_NEAR_BY, nearbyRouterMetadata); request.putRouterArgument(NearbyRouter.ROUTER_TYPE_NEAR_BY, routeArguments);
} }
} }

@ -18,16 +18,20 @@
package com.tencent.cloud.polaris.router.interceptor; package com.tencent.cloud.polaris.router.interceptor;
import java.util.HashMap; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set;
import com.tencent.cloud.common.constant.RouterConstant; import com.tencent.cloud.common.constant.RouterConstant;
import com.tencent.cloud.polaris.router.PolarisRouterContext; import com.tencent.cloud.polaris.router.PolarisRouterContext;
import com.tencent.cloud.polaris.router.config.properties.PolarisRuleBasedRouterProperties; import com.tencent.cloud.polaris.router.config.properties.PolarisRuleBasedRouterProperties;
import com.tencent.cloud.polaris.router.spi.RouterRequestInterceptor; import com.tencent.cloud.polaris.router.spi.RouterRequestInterceptor;
import com.tencent.polaris.api.pojo.RouteArgument;
import com.tencent.polaris.plugins.router.rule.RuleBasedRouter; import com.tencent.polaris.plugins.router.rule.RuleBasedRouter;
import com.tencent.polaris.router.api.rpc.ProcessRoutersRequest; import com.tencent.polaris.router.api.rpc.ProcessRoutersRequest;
import org.springframework.util.CollectionUtils;
/** /**
* Router request interceptor for rule based router. * Router request interceptor for rule based router.
* @author lepdou 2022-07-06 * @author lepdou 2022-07-06
@ -45,16 +49,21 @@ public class RuleBasedRouterRequestInterceptor implements RouterRequestIntercept
boolean ruleBasedRouterEnabled = polarisRuleBasedRouterProperties.isEnabled(); boolean ruleBasedRouterEnabled = polarisRuleBasedRouterProperties.isEnabled();
// set dynamic switch for rule based router // set dynamic switch for rule based router
Map<String, String> metadata = new HashMap<>(); Set<RouteArgument> routeArguments = new HashSet<>();
metadata.put(RuleBasedRouter.ROUTER_ENABLED, String.valueOf(ruleBasedRouterEnabled)); routeArguments.add(RouteArgument.buildCustom(RuleBasedRouter.ROUTER_ENABLED, String.valueOf(ruleBasedRouterEnabled)));
request.addRouterMetadata(RuleBasedRouter.ROUTER_TYPE_RULE_BASED, metadata);
// The label information that the rule based routing depends on // The label information that the rule based routing depends on
// is placed in the metadata of the source service for transmission. // is placed in the metadata of the source service for transmission.
// Later, can consider putting it in routerMetadata like other routers. // Later, can consider putting it in routerMetadata like other routers.
if (ruleBasedRouterEnabled) { if (ruleBasedRouterEnabled) {
Map<String, String> ruleRouterLabels = routerContext.getLabels(RouterConstant.ROUTER_LABELS); Map<String, String> ruleRouterLabels = routerContext.getLabels(RouterConstant.ROUTER_LABELS);
request.getSourceService().setMetadata(ruleRouterLabels); if (!CollectionUtils.isEmpty(ruleRouterLabels)) {
for (Map.Entry<String, String> label : ruleRouterLabels.entrySet()) {
routeArguments.add(RouteArgument.buildCustom(label.getKey(), label.getValue()));
}
}
} }
request.putRouterArgument(RuleBasedRouter.ROUTER_TYPE_RULE_BASED, routeArguments);
} }
} }

@ -23,6 +23,7 @@ import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import com.netflix.client.config.DefaultClientConfigImpl; import com.netflix.client.config.DefaultClientConfigImpl;
@ -52,6 +53,7 @@ import com.tencent.cloud.polaris.router.spi.RouterRequestInterceptor;
import com.tencent.polaris.api.pojo.DefaultInstance; import com.tencent.polaris.api.pojo.DefaultInstance;
import com.tencent.polaris.api.pojo.DefaultServiceInstances; import com.tencent.polaris.api.pojo.DefaultServiceInstances;
import com.tencent.polaris.api.pojo.Instance; import com.tencent.polaris.api.pojo.Instance;
import com.tencent.polaris.api.pojo.RouteArgument;
import com.tencent.polaris.api.pojo.ServiceInstances; import com.tencent.polaris.api.pojo.ServiceInstances;
import com.tencent.polaris.api.pojo.ServiceKey; import com.tencent.polaris.api.pojo.ServiceKey;
import com.tencent.polaris.plugins.router.metadata.MetadataRouter; import com.tencent.polaris.plugins.router.metadata.MetadataRouter;
@ -220,13 +222,16 @@ public class PolarisLoadBalancerCompositeRuleTest {
ProcessRoutersRequest request = compositeRule.buildProcessRoutersBaseRequest(serviceInstances); ProcessRoutersRequest request = compositeRule.buildProcessRoutersBaseRequest(serviceInstances);
compositeRule.processRouterRequestInterceptors(request, routerContext); compositeRule.processRouterRequestInterceptors(request, routerContext);
Map<String, String> routerMetadata = request.getRouterMetadata(MetadataRouter.ROUTER_TYPE_METADATA); Set<RouteArgument> routerMetadata = request.getRouterArguments(MetadataRouter.ROUTER_TYPE_METADATA);
Assert.assertEquals(1, routerMetadata.size()); Assert.assertEquals(1, routerMetadata.size());
Assert.assertEquals(0, request.getRouterMetadata(NearbyRouter.ROUTER_TYPE_NEAR_BY).size()); Assert.assertEquals(0, request.getRouterArguments(NearbyRouter.ROUTER_TYPE_NEAR_BY).size());
Assert.assertEquals(1, request.getRouterMetadata(RuleBasedRouter.ROUTER_TYPE_RULE_BASED).size()); Assert.assertEquals(1, request.getRouterArguments(RuleBasedRouter.ROUTER_TYPE_RULE_BASED).size());
Assert.assertEquals("false", request.getRouterMetadata(RuleBasedRouter.ROUTER_TYPE_RULE_BASED)
.get(RuleBasedRouter.ROUTER_ENABLED)); for (RouteArgument routeArgument : request.getRouterArguments(RuleBasedRouter.ROUTER_TYPE_RULE_BASED)) {
Assert.assertEquals(RuleBasedRouter.ROUTER_ENABLED, routeArgument.getKey());
Assert.assertEquals("false", routeArgument.getValue());
}
} }
} }
@ -250,14 +255,22 @@ public class PolarisLoadBalancerCompositeRuleTest {
ProcessRoutersRequest request = compositeRule.buildProcessRoutersBaseRequest(serviceInstances); ProcessRoutersRequest request = compositeRule.buildProcessRoutersBaseRequest(serviceInstances);
compositeRule.processRouterRequestInterceptors(request, routerContext); compositeRule.processRouterRequestInterceptors(request, routerContext);
Map<String, String> routerMetadata = request.getRouterMetadata(NearbyRouter.ROUTER_TYPE_NEAR_BY); Set<RouteArgument> routerMetadata = request.getRouterArguments(NearbyRouter.ROUTER_TYPE_NEAR_BY);
Assert.assertEquals(0, request.getRouterMetadata(MetadataRouter.ROUTER_TYPE_METADATA).size()); Assert.assertEquals(0, request.getRouterArguments(MetadataRouter.ROUTER_TYPE_METADATA).size());
Assert.assertEquals(1, routerMetadata.size()); Assert.assertEquals(1, routerMetadata.size());
Assert.assertEquals("true", routerMetadata.get(NearbyRouter.ROUTER_ENABLED));
Assert.assertEquals(1, request.getRouterMetadata(RuleBasedRouter.ROUTER_TYPE_RULE_BASED).size()); for (RouteArgument routeArgument : routerMetadata) {
Assert.assertEquals("false", request.getRouterMetadata(RuleBasedRouter.ROUTER_TYPE_RULE_BASED) Assert.assertEquals(NearbyRouter.ROUTER_ENABLED, routeArgument.getKey());
.get(RuleBasedRouter.ROUTER_ENABLED)); Assert.assertEquals("true", routeArgument.getValue());
}
Assert.assertEquals(1, request.getRouterArguments(RuleBasedRouter.ROUTER_TYPE_RULE_BASED).size());
for (RouteArgument routeArgument : request.getRouterArguments(RuleBasedRouter.ROUTER_TYPE_RULE_BASED)) {
Assert.assertEquals(RuleBasedRouter.ROUTER_ENABLED, routeArgument.getKey());
Assert.assertEquals("false", routeArgument.getValue());
}
} }
} }
@ -281,14 +294,11 @@ public class PolarisLoadBalancerCompositeRuleTest {
ProcessRoutersRequest request = compositeRule.buildProcessRoutersBaseRequest(serviceInstances); ProcessRoutersRequest request = compositeRule.buildProcessRoutersBaseRequest(serviceInstances);
compositeRule.processRouterRequestInterceptors(request, routerContext); compositeRule.processRouterRequestInterceptors(request, routerContext);
Map<String, String> routerMetadata = request.getRouterMetadata(RuleBasedRouter.ROUTER_TYPE_RULE_BASED); Set<RouteArgument> routerMetadata = request.getRouterArguments(RuleBasedRouter.ROUTER_TYPE_RULE_BASED);
Assert.assertEquals(1, routerMetadata.size()); Assert.assertEquals(3, routerMetadata.size());
Assert.assertEquals(0, request.getRouterMetadata(MetadataRouter.ROUTER_TYPE_METADATA).size()); Assert.assertEquals(0, request.getRouterArguments(MetadataRouter.ROUTER_TYPE_METADATA).size());
Assert.assertEquals(0, request.getRouterMetadata(NearbyRouter.ROUTER_TYPE_NEAR_BY).size()); Assert.assertEquals(0, request.getRouterArguments(NearbyRouter.ROUTER_TYPE_NEAR_BY).size());
Assert.assertEquals(1, request.getRouterMetadata(RuleBasedRouter.ROUTER_TYPE_RULE_BASED).size());
Assert.assertEquals("true", request.getRouterMetadata(RuleBasedRouter.ROUTER_TYPE_RULE_BASED)
.get(RuleBasedRouter.ROUTER_ENABLED));
} }
} }

@ -71,7 +71,7 @@
<properties> <properties>
<revision>1.9.0-Hoxton.SR12-SNAPSHOT</revision> <revision>1.9.0-Hoxton.SR12-SNAPSHOT</revision>
<polaris.version>1.10.0-SNAPSHOT</polaris.version> <polaris.version>1.10.1-SNAPSHOT</polaris.version>
<logback.version>1.2.11</logback.version> <logback.version>1.2.11</logback.version>
<mocktio.version>4.5.1</mocktio.version> <mocktio.version>4.5.1</mocktio.version>
<byte-buddy.version>1.12.10</byte-buddy.version> <byte-buddy.version>1.12.10</byte-buddy.version>

@ -18,11 +18,12 @@
package com.tencent.cloud.plugin.featureenv; package com.tencent.cloud.plugin.featureenv;
import java.util.HashMap; import java.util.HashSet;
import java.util.Map; import java.util.Set;
import com.tencent.cloud.polaris.router.PolarisRouterContext; import com.tencent.cloud.polaris.router.PolarisRouterContext;
import com.tencent.cloud.polaris.router.spi.RouterRequestInterceptor; import com.tencent.cloud.polaris.router.spi.RouterRequestInterceptor;
import com.tencent.polaris.api.pojo.RouteArgument;
import com.tencent.polaris.api.rpc.MetadataFailoverType; import com.tencent.polaris.api.rpc.MetadataFailoverType;
import com.tencent.polaris.plugins.router.metadata.MetadataRouter; import com.tencent.polaris.plugins.router.metadata.MetadataRouter;
import com.tencent.polaris.router.api.rpc.ProcessRoutersRequest; import com.tencent.polaris.router.api.rpc.ProcessRoutersRequest;
@ -54,10 +55,11 @@ public class FeatureEnvRouterRequestInterceptor implements RouterRequestIntercep
} }
//3. set env metadata to router request //3. set env metadata to router request
Map<String, String> envMetadata = new HashMap<>(); Set<RouteArgument> routeArguments = new HashSet<>(1);
envMetadata.put(envLabelKey, envLabelValue); routeArguments.add(RouteArgument.buildCustom(envLabelKey, envLabelValue));
request.putRouterArgument(MetadataRouter.ROUTER_TYPE_METADATA, routeArguments);
request.addRouterMetadata(MetadataRouter.ROUTER_TYPE_METADATA, envMetadata);
//4. set failover type to others //4. set failover type to others
request.setMetadataFailoverType(MetadataFailoverType.METADATAFAILOVERNOTKEY); request.setMetadataFailoverType(MetadataFailoverType.METADATAFAILOVERNOTKEY);

Loading…
Cancel
Save