From 2b5e8dcfa31df1daa9e387e22498f97eb72bc292 Mon Sep 17 00:00:00 2001 From: lepdou Date: Mon, 29 Aug 2022 19:38:31 +0800 Subject: [PATCH] remove location metadata (#540) --- CHANGELOG.md | 1 + .../cloud/common/metadata/StaticMetadataManager.java | 2 -- .../cloud/common/metadata/StaticMetadataManagerTest.java | 3 --- .../cloud/polaris/loadbalancer/LoadBalancerUtils.java | 9 +++++++++ 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 36015ad94..54e634c85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,4 +23,5 @@ - [Feature: Optimized configuration update](https://github.com/Tencent/spring-cloud-tencent/pull/527) - [Featureļ¼šsupport pushGateway push metrics](https://github.com/Tencent/spring-cloud-tencent/pull/531) - [Feature: remove location metadata](https://github.com/Tencent/spring-cloud-tencent/pull/534) +- [Feature: remove location metadata](https://github.com/Tencent/spring-cloud-tencent/pull/540) - [add feature-env plugin & add spring cloud gateway staining plugin](https://github.com/Tencent/spring-cloud-tencent/pull/532) diff --git a/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/StaticMetadataManager.java b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/StaticMetadataManager.java index 554694fa3..2413e3778 100644 --- a/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/StaticMetadataManager.java +++ b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/StaticMetadataManager.java @@ -214,8 +214,6 @@ public class StaticMetadataManager { mergedMetadataResult.putAll(configMetadata); mergedMetadataResult.putAll(envMetadata); mergedMetadataResult.putAll(customSPIMetadata); - // set location info as metadata - mergedMetadataResult.putAll(getLocationMetadata()); this.mergedStaticMetadata = Collections.unmodifiableMap(mergedMetadataResult); Map mergedTransitiveMetadataResult = new HashMap<>(); diff --git a/spring-cloud-tencent-commons/src/test/java/com/tencent/cloud/common/metadata/StaticMetadataManagerTest.java b/spring-cloud-tencent-commons/src/test/java/com/tencent/cloud/common/metadata/StaticMetadataManagerTest.java index 085b13e21..64aa20bcb 100644 --- a/spring-cloud-tencent-commons/src/test/java/com/tencent/cloud/common/metadata/StaticMetadataManagerTest.java +++ b/spring-cloud-tencent-commons/src/test/java/com/tencent/cloud/common/metadata/StaticMetadataManagerTest.java @@ -128,9 +128,6 @@ public class StaticMetadataManagerTest { Assert.assertEquals("v1", metadata.get("k1")); Assert.assertEquals("v22", metadata.get("k2")); Assert.assertEquals("v33", metadata.get("k3")); - Assert.assertEquals("zone2", metadata.get("zone")); - Assert.assertEquals("region1", metadata.get("region")); - Assert.assertEquals("campus1", metadata.get("campus")); Map transitiveMetadata = metadataManager.getMergedStaticTransitiveMetadata(); Assert.assertEquals(2, transitiveMetadata.size()); diff --git a/spring-cloud-tencent-polaris-loadbalancer/src/main/java/com/tencent/cloud/polaris/loadbalancer/LoadBalancerUtils.java b/spring-cloud-tencent-polaris-loadbalancer/src/main/java/com/tencent/cloud/polaris/loadbalancer/LoadBalancerUtils.java index 997c276f5..14006d47b 100644 --- a/spring-cloud-tencent-polaris-loadbalancer/src/main/java/com/tencent/cloud/polaris/loadbalancer/LoadBalancerUtils.java +++ b/spring-cloud-tencent-polaris-loadbalancer/src/main/java/com/tencent/cloud/polaris/loadbalancer/LoadBalancerUtils.java @@ -24,6 +24,7 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; import com.tencent.cloud.common.metadata.MetadataContext; +import com.tencent.cloud.common.pojo.PolarisServiceInstance; import com.tencent.polaris.api.pojo.DefaultInstance; import com.tencent.polaris.api.pojo.DefaultServiceInstances; import com.tencent.polaris.api.pojo.Instance; @@ -84,6 +85,14 @@ public final class LoadBalancerUtils { instance.setPort(serviceInstance.getPort()); instance.setWeight(DEFAULT_WEIGHT); instance.setMetadata(serviceInstance.getMetadata()); + + if (serviceInstance instanceof PolarisServiceInstance) { + PolarisServiceInstance polarisServiceInstance = (PolarisServiceInstance) serviceInstance; + instance.setRegion(polarisServiceInstance.getPolarisInstance().getRegion()); + instance.setZone(polarisServiceInstance.getPolarisInstance().getZone()); + instance.setCampus(polarisServiceInstance.getPolarisInstance().getCampus()); + } + return instance; } }