adapt polaris-java 1.10.1 version (#746)

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

@ -16,3 +16,4 @@
- [Fix:fix javadoc.](https://github.com/Tencent/spring-cloud-tencent/pull/721) - [Fix:fix javadoc.](https://github.com/Tencent/spring-cloud-tencent/pull/721)
- [Code optimization & correct comment](https://github.com/Tencent/spring-cloud-tencent/pull/722) - [Code optimization & correct comment](https://github.com/Tencent/spring-cloud-tencent/pull/722)
- [fix:fix discovery junit.](https://github.com/Tencent/spring-cloud-tencent/pull/730) - [fix:fix discovery junit.](https://github.com/Tencent/spring-cloud-tencent/pull/730)
- [adapt polaris-java 1.10.1 version](https://github.com/Tencent/spring-cloud-tencent/pull/746)

@ -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, Hoatian Zhang * @author lepdou, Hoatian Zhang
@ -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, Hoatian Zhang * @author lepdou, Hoatian Zhang
@ -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);
}
} }

@ -24,6 +24,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.tencent.cloud.common.constant.RouterConstant; import com.tencent.cloud.common.constant.RouterConstant;
@ -42,6 +43,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;
@ -124,13 +126,16 @@ public class PolarisRouterServiceInstanceListSupplierTest {
ProcessRoutersRequest request = polarisSupplier.buildProcessRoutersRequest(serviceInstances, routerContext); ProcessRoutersRequest request = polarisSupplier.buildProcessRoutersRequest(serviceInstances, routerContext);
polarisSupplier.processRouterRequestInterceptors(request, routerContext); polarisSupplier.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());
}
} }
} }
@ -153,14 +158,22 @@ public class PolarisRouterServiceInstanceListSupplierTest {
ProcessRoutersRequest request = polarisSupplier.buildProcessRoutersRequest(serviceInstances, routerContext); ProcessRoutersRequest request = polarisSupplier.buildProcessRoutersRequest(serviceInstances, routerContext);
polarisSupplier.processRouterRequestInterceptors(request, routerContext); polarisSupplier.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());
}
} }
} }
@ -183,14 +196,11 @@ public class PolarisRouterServiceInstanceListSupplierTest {
ProcessRoutersRequest request = polarisSupplier.buildProcessRoutersRequest(serviceInstances, routerContext); ProcessRoutersRequest request = polarisSupplier.buildProcessRoutersRequest(serviceInstances, routerContext);
polarisSupplier.processRouterRequestInterceptors(request, routerContext); polarisSupplier.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));
} }
} }

@ -73,7 +73,7 @@
<revision>1.9.0-2021.0.3-SNAPSHOT</revision> <revision>1.9.0-2021.0.3-SNAPSHOT</revision>
<!-- Dependencies --> <!-- Dependencies -->
<polaris.version>1.10.0-SNAPSHOT</polaris.version> <polaris.version>1.10.1-SNAPSHOT</polaris.version>
<guava.version>31.0.1-jre</guava.version> <guava.version>31.0.1-jre</guava.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>

@ -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