Commit 0cacd820 by Nepxion

修复缺省未配置的Bug

parent cb986c12
...@@ -55,16 +55,18 @@ public class ConfigurationParser extends Dom4JParser { ...@@ -55,16 +55,18 @@ public class ConfigurationParser extends Dom4JParser {
throw new PluginException("The count of element[" + ConfigurationConstant.DISCOVERY_ELEMENT_NAME + "] can't be more than 1"); throw new PluginException("The count of element[" + ConfigurationConstant.DISCOVERY_ELEMENT_NAME + "] can't be more than 1");
} }
RegisterEntity registerEntity = new RegisterEntity(); RegisterEntity registerEntity = null;
DiscoveryEntity discoveryEntity = new DiscoveryEntity(); DiscoveryEntity discoveryEntity = null;
for (Iterator elementIterator = element.elementIterator(); elementIterator.hasNext();) { for (Iterator elementIterator = element.elementIterator(); elementIterator.hasNext();) {
Object childElementObject = elementIterator.next(); Object childElementObject = elementIterator.next();
if (childElementObject instanceof Element) { if (childElementObject instanceof Element) {
Element childElement = (Element) childElementObject; Element childElement = (Element) childElementObject;
if (StringUtils.equals(childElement.getName(), ConfigurationConstant.REGISTER_ELEMENT_NAME)) { if (StringUtils.equals(childElement.getName(), ConfigurationConstant.REGISTER_ELEMENT_NAME)) {
registerEntity = new RegisterEntity();
parseRegister(childElement, registerEntity); parseRegister(childElement, registerEntity);
} else if (StringUtils.equals(childElement.getName(), ConfigurationConstant.DISCOVERY_ELEMENT_NAME)) { } else if (StringUtils.equals(childElement.getName(), ConfigurationConstant.DISCOVERY_ELEMENT_NAME)) {
discoveryEntity = new DiscoveryEntity();
parseDiscovery(childElement, discoveryEntity); parseDiscovery(childElement, discoveryEntity);
} }
} }
......
...@@ -42,21 +42,42 @@ public class DiscoveryStrategy { ...@@ -42,21 +42,42 @@ public class DiscoveryStrategy {
try { try {
reentrantReadWriteLock.readLock().lock(); reentrantReadWriteLock.readLock().lock();
applyIpAddressFilter(providerServiceId, instances);
applyVersionFilter(consumerServiceId, consumerServiceVersion, providerServiceId, instances); applyVersionFilter(consumerServiceId, consumerServiceVersion, providerServiceId, instances);
} finally { } finally {
reentrantReadWriteLock.readLock().unlock(); reentrantReadWriteLock.readLock().unlock();
} }
} }
private void applyIpAddressFilter(String providerServiceId, List<ServiceInstance> instances) {
String ipAddress = pluginCache.get(providerServiceId);
if (StringUtils.isNotEmpty(ipAddress)) {
String[] filterArray = StringUtils.split(ipAddress, PluginConstant.SEPARATE);
List<String> filterList = Arrays.asList(filterArray);
Iterator<ServiceInstance> iterator = instances.iterator();
while (iterator.hasNext()) {
ServiceInstance serviceInstance = iterator.next();
String host = serviceInstance.getHost();
if (filterList.contains(host)) {
iterator.remove();
}
}
}
}
private void applyVersionFilter(String consumerServiceId, String consumerServiceVersion, String providerServiceId, List<ServiceInstance> instances) { private void applyVersionFilter(String consumerServiceId, String consumerServiceVersion, String providerServiceId, List<ServiceInstance> instances) {
DiscoveryEntity discoveryEntity = pluginEntity.getDiscoveryEntity(); DiscoveryEntity discoveryEntity = pluginEntity.getDiscoveryEntity();
if (discoveryEntity == null) {
return;
}
Map<String, List<DiscoveryServiceEntity>> serviceEntityMap = discoveryEntity.getServiceEntityMap(); Map<String, List<DiscoveryServiceEntity>> serviceEntityMap = discoveryEntity.getServiceEntityMap();
// 未找到相应的版本定义或者未定义
if (MapUtils.isEmpty(serviceEntityMap)) { if (MapUtils.isEmpty(serviceEntityMap)) {
return; return;
} }
List<DiscoveryServiceEntity> serviceEntityList = serviceEntityMap.get(consumerServiceId); List<DiscoveryServiceEntity> serviceEntityList = serviceEntityMap.get(consumerServiceId);
// 未找到相应的版本定义或者未定义
if (CollectionUtils.isEmpty(serviceEntityList)) { if (CollectionUtils.isEmpty(serviceEntityList)) {
return; return;
} }
......
...@@ -18,9 +18,9 @@ import org.slf4j.LoggerFactory; ...@@ -18,9 +18,9 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import com.nepxion.discovery.plugin.core.constant.PluginConstant; import com.nepxion.discovery.plugin.core.constant.PluginConstant;
import com.nepxion.discovery.plugin.core.entity.RegisterFilterType;
import com.nepxion.discovery.plugin.core.entity.PluginEntity; import com.nepxion.discovery.plugin.core.entity.PluginEntity;
import com.nepxion.discovery.plugin.core.entity.RegisterEntity; import com.nepxion.discovery.plugin.core.entity.RegisterEntity;
import com.nepxion.discovery.plugin.core.entity.RegisterFilterType;
import com.nepxion.discovery.plugin.core.exception.PluginException; import com.nepxion.discovery.plugin.core.exception.PluginException;
public class RegisterStrategy { public class RegisterStrategy {
...@@ -44,6 +44,10 @@ public class RegisterStrategy { ...@@ -44,6 +44,10 @@ public class RegisterStrategy {
private void applyIpAddressFilter(String serviceId, String ipAddress) { private void applyIpAddressFilter(String serviceId, String ipAddress) {
RegisterEntity registerEntity = pluginEntity.getRegisterEntity(); RegisterEntity registerEntity = pluginEntity.getRegisterEntity();
if (registerEntity == null) {
return;
}
RegisterFilterType filterType = registerEntity.getFilterType(); RegisterFilterType filterType = registerEntity.getFilterType();
String globalFilterValue = registerEntity.getFilterValue(); String globalFilterValue = registerEntity.getFilterValue();
......
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