This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
The following commit(s) were added to refs/heads/master by this push:
new 09feec0 [SCB-2361] Support AZ information and IP grouping strategy
(#2747)
09feec0 is described below
commit 09feec0f964367364a855e795be07377046563f4
Author: zyl <[email protected]>
AuthorDate: Thu Mar 24 19:53:38 2022 +0800
[SCB-2361] Support AZ information and IP grouping strategy (#2747)
---
.../servicecomb/serviceregistry/api/Const.java | 4 ++++
.../refresh/ClassificationAddress.java | 21 ++++++++++++---------
.../serviceregistry/client/TestIpPortManager.java | 11 +++++++----
3 files changed, 23 insertions(+), 13 deletions(-)
diff --git
a/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/api/Const.java
b/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/api/Const.java
index 125d77a..15558d1 100644
---
a/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/api/Const.java
+++
b/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/api/Const.java
@@ -198,4 +198,8 @@ public final class Const {
public static final String SERVICECENTER_FRAMEWORK_VERSION = "1.0.0";
public static final String SERVICE_CENTER_ENABLED =
"servicecomb.service.registry.enabled";
+
+ public static final String SAME_ZONE = "sameZone";
+
+ public static final String SAME_REGION = "sameRegion";
}
diff --git
a/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/refresh/ClassificationAddress.java
b/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/refresh/ClassificationAddress.java
index 1b7666f..86d33ca 100644
---
a/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/refresh/ClassificationAddress.java
+++
b/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/refresh/ClassificationAddress.java
@@ -22,6 +22,8 @@ import static
org.apache.servicecomb.serviceregistry.api.Const.CSE_MONITORING_NA
import static org.apache.servicecomb.serviceregistry.api.Const.KIE_NAME;
import static org.apache.servicecomb.serviceregistry.api.Const.REGISTRY_APP_ID;
import static
org.apache.servicecomb.serviceregistry.api.Const.REGISTRY_SERVICE_NAME;
+import static org.apache.servicecomb.serviceregistry.api.Const.SAME_REGION;
+import static org.apache.servicecomb.serviceregistry.api.Const.SAME_ZONE;
import java.util.ArrayList;
import java.util.HashMap;
@@ -134,8 +136,8 @@ public class ClassificationAddress {
sameRegion.add(endPoint);
}
});
- zoneAndRegion.put("sameZone", new ArrayList<>(sameZone));
- zoneAndRegion.put("sameRegion", new ArrayList<>(sameRegion));
+ zoneAndRegion.put(SAME_ZONE, new ArrayList<>(sameZone));
+ zoneAndRegion.put(SAME_REGION, new ArrayList<>(sameRegion));
return zoneAndRegion;
}
@@ -164,23 +166,24 @@ public class ClassificationAddress {
sameRegion.add(cacheEndpoint.getEndpoint());
}
}
- zoneAndRegion.put("sameZone", new ArrayList<>(sameZone));
- zoneAndRegion.put("sameRegion", new ArrayList<>(sameRegion));
+ zoneAndRegion.put(SAME_ZONE, new ArrayList<>(sameZone));
+ zoneAndRegion.put(SAME_REGION, new ArrayList<>(sameRegion));
return zoneAndRegion;
}
private DataCenterInfo findRegion(List<CacheEndpoint> CacheEndpoints) {
- MicroserviceInstance myself =
RegistrationManager.INSTANCE.getMicroserviceInstance();
- if (myself.getDataCenterInfo() == null) {
- return null;
- }
for (CacheEndpoint cacheEndpoint : CacheEndpoints) {
boolean isMatch =
cacheEndpoint.getEndpoint().contains(this.defaultIpPort.get(0).getHostOrIp());
if (isMatch && cacheEndpoint.getInstance().getDataCenterInfo() != null) {
return cacheEndpoint.getInstance().getDataCenterInfo();
}
}
- return null;
+
+ MicroserviceInstance myself =
RegistrationManager.INSTANCE.getMicroserviceInstance();
+ if (myself.getDataCenterInfo() == null) {
+ return null;
+ }
+ return myself.getDataCenterInfo();
}
private boolean regionAndAZMatch(DataCenterInfo myself, MicroserviceInstance
target) {
diff --git
a/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/client/TestIpPortManager.java
b/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/client/TestIpPortManager.java
index 68ca58f..5c12cde 100644
---
a/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/client/TestIpPortManager.java
+++
b/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/client/TestIpPortManager.java
@@ -25,6 +25,7 @@ import java.util.Map;
import org.apache.servicecomb.config.ConfigUtil;
import org.apache.servicecomb.foundation.common.net.IpPort;
import org.apache.servicecomb.registry.RegistrationManager;
+import org.apache.servicecomb.registry.api.registry.DataCenterInfo;
import org.apache.servicecomb.serviceregistry.RegistryUtils;
import org.apache.servicecomb.registry.api.registry.MicroserviceInstance;
import org.apache.servicecomb.registry.cache.CacheEndpoint;
@@ -102,11 +103,13 @@ public class TestIpPortManager {
// mock endpoint list
Map<String, List<CacheEndpoint>> addresses = new HashMap<>();
- List<CacheEndpoint> instances = new ArrayList<>();
- instances.add(new CacheEndpoint("http://127.0.0.1:9982", null));
- addresses.put("rest", instances);
+ List<CacheEndpoint> cacheEndpoints = new ArrayList<>();
+ MicroserviceInstance Instance = new MicroserviceInstance();
+ Instance.setDataCenterInfo(null);
+ cacheEndpoints.add(new CacheEndpoint("http://127.0.0.1:9982", Instance));
+ addresses.put("rest", cacheEndpoints);
ClassificationAddress classificationAddres = new
ClassificationAddress(config, cacheManager);
- manager.classificationAddress =classificationAddres;
+ manager.classificationAddress = classificationAddres;
new Expectations() {
{
cacheManager.getOrCreate("default", "SERVICECENTER", "latest");