Skip to content

Commit 2013946

Browse files
authored
fix: stop using dest-svc-metadata to match instance metadata. (#655)
1 parent 81e48f8 commit 2013946

File tree

5 files changed

+361
-263
lines changed

5 files changed

+361
-263
lines changed

polaris-discovery/polaris-discovery-factory/src/test/java/com/tencent/polaris/discovery/test/core/MetadataRouterTest.java

Lines changed: 0 additions & 254 deletions
This file was deleted.

polaris-discovery/polaris-discovery-factory/src/test/java/com/tencent/polaris/discovery/test/suite/DiscoveryAPITestingSuite.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package com.tencent.polaris.discovery.test.suite;
1919

2020
import com.tencent.polaris.discovery.test.core.ConsumerTest;
21-
import com.tencent.polaris.discovery.test.core.MetadataRouterTest;
2221
import com.tencent.polaris.discovery.test.core.ProviderTest;
2322
import org.junit.runner.RunWith;
2423
import org.junit.runners.Suite;
@@ -27,7 +26,6 @@
2726
@Suite.SuiteClasses({
2827
ConsumerTest.class,
2928
ProviderTest.class,
30-
MetadataRouterTest.class,
3129
})
3230
public class DiscoveryAPITestingSuite {
3331

polaris-plugins/polaris-plugins-router/router-metadata/src/main/java/com/tencent/polaris/plugins/router/metadata/MetadataRouter.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public RouteResult router(RouteInfo routeInfo, ServiceInstances instances) throw
119119
case others:
120120
return new RouteResult(addNotContainKeyIns(instances, reqMetadata), RouteResult.State.Next);
121121
default:
122-
// 默认不降级
122+
// none或其他情况不降级
123123
throw new PolarisException(ErrorCode.METADATA_MISMATCH,
124124
String.format("can not find any instance by service %s", routeInfo.getDestService()));
125125
}
@@ -183,12 +183,8 @@ public boolean enable(RouteInfo routeInfo, ServiceMetadata dstSvcInfo) {
183183
}
184184

185185
private Map<String, String> getRouterMetadata(RouteInfo routeInfo) {
186-
//兼容从 destService 获取元数据
187-
Map<String, String> metadata = routeInfo.getDestService().getMetadata();
188-
if (MapUtils.isNotEmpty(metadata)) {
189-
return metadata;
190-
}
191-
metadata = new HashMap<>(routeInfo.getRouterMetadata(ROUTER_TYPE_METADATA));
186+
Map<String, String> metadata = new HashMap<>(routeInfo.getRouterMetadata(ROUTER_TYPE_METADATA));
187+
192188
if (routeInfo.getMetadataContainerGroup() != null && routeInfo.getMetadataContainerGroup().getCustomMetadataContainer() != null) {
193189
String metadataRouteKeys = routeInfo.getMetadataContainerGroup().getCustomMetadataContainer().getRawMetadataMapValue(ROUTER_TYPE_METADATA, KEY_METADATA_KEYS);
194190
if (StringUtils.isNotBlank(metadataRouteKeys)) {

polaris-router/polaris-router-factory/pom.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,29 @@
2626
<artifactId>router-mirroring</artifactId>
2727
<version>${project.version}</version>
2828
</dependency>
29+
<dependency>
30+
<groupId>com.tencent.polaris</groupId>
31+
<artifactId>polaris-test-mock-discovery</artifactId>
32+
<version>${project.version}</version>
33+
<scope>test</scope>
34+
</dependency>
35+
<dependency>
36+
<groupId>com.tencent.polaris</groupId>
37+
<artifactId>polaris-test-common</artifactId>
38+
<version>${project.version}</version>
39+
<scope>test</scope>
40+
</dependency>
41+
<dependency>
42+
<groupId>com.tencent.polaris</groupId>
43+
<artifactId>router-metadata</artifactId>
44+
<version>${project.version}</version>
45+
<scope>test</scope>
46+
</dependency>
47+
<dependency>
48+
<groupId>com.tencent.polaris</groupId>
49+
<artifactId>polaris-discovery-factory</artifactId>
50+
<version>${project.version}</version>
51+
<scope>test</scope>
52+
</dependency>
2953
</dependencies>
3054
</project>

0 commit comments

Comments
 (0)