Commit de17df63 by Nepxion

重构类结构

parent c45e7f5b
...@@ -51,21 +51,31 @@ public class DiscoveryControlStrategy { ...@@ -51,21 +51,31 @@ public class DiscoveryControlStrategy {
} }
private void applyIpAddressFilter(String providerServiceId, List<ServiceInstance> instances) { private void applyIpAddressFilter(String providerServiceId, List<ServiceInstance> instances) {
String ipAddress = pluginCache.get(providerServiceId); String filterIpAddress = pluginCache.get(providerServiceId);
if (StringUtils.isNotEmpty(ipAddress)) { if (StringUtils.isNotEmpty(filterIpAddress)) {
String[] filterArray = StringUtils.split(ipAddress, PluginConstant.SEPARATE);
List<String> filterList = Arrays.asList(filterArray);
Iterator<ServiceInstance> iterator = instances.iterator(); Iterator<ServiceInstance> iterator = instances.iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
ServiceInstance serviceInstance = iterator.next(); ServiceInstance serviceInstance = iterator.next();
String host = serviceInstance.getHost(); String host = serviceInstance.getHost();
if (filterList.contains(host)) { boolean valid = validateBlacklist(filterIpAddress, host);
if (valid) {
iterator.remove(); iterator.remove();
} }
} }
} }
} }
private boolean validateBlacklist(String filterIpAddress, String ipAddress) {
String[] filterArray = StringUtils.split(ipAddress, PluginConstant.SEPARATE);
for (String filter : filterArray) {
if (ipAddress.startsWith(filter)) {
return true;
}
}
return false;
}
private void applyVersionFilter(String consumerServiceId, String consumerServiceVersion, String providerServiceId, List<ServiceInstance> instances) { private void applyVersionFilter(String consumerServiceId, String consumerServiceVersion, String providerServiceId, List<ServiceInstance> instances) {
// 如果消费端未配置版本号,那么它可以调用提供端所有服务,需要符合规范,极力避免该情况发生 // 如果消费端未配置版本号,那么它可以调用提供端所有服务,需要符合规范,极力避免该情况发生
if (StringUtils.isEmpty(consumerServiceVersion)) { if (StringUtils.isEmpty(consumerServiceVersion)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment