Commit 0cacd820 by Nepxion

修复缺省未配置的Bug

parent cb986c12
......@@ -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");
}
RegisterEntity registerEntity = new RegisterEntity();
DiscoveryEntity discoveryEntity = new DiscoveryEntity();
RegisterEntity registerEntity = null;
DiscoveryEntity discoveryEntity = null;
for (Iterator elementIterator = element.elementIterator(); elementIterator.hasNext();) {
Object childElementObject = elementIterator.next();
if (childElementObject instanceof Element) {
Element childElement = (Element) childElementObject;
if (StringUtils.equals(childElement.getName(), ConfigurationConstant.REGISTER_ELEMENT_NAME)) {
registerEntity = new RegisterEntity();
parseRegister(childElement, registerEntity);
} else if (StringUtils.equals(childElement.getName(), ConfigurationConstant.DISCOVERY_ELEMENT_NAME)) {
discoveryEntity = new DiscoveryEntity();
parseDiscovery(childElement, discoveryEntity);
}
}
......
......@@ -42,21 +42,42 @@ public class DiscoveryStrategy {
try {
reentrantReadWriteLock.readLock().lock();
applyIpAddressFilter(providerServiceId, instances);
applyVersionFilter(consumerServiceId, consumerServiceVersion, providerServiceId, instances);
} finally {
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) {
DiscoveryEntity discoveryEntity = pluginEntity.getDiscoveryEntity();
if (discoveryEntity == null) {
return;
}
Map<String, List<DiscoveryServiceEntity>> serviceEntityMap = discoveryEntity.getServiceEntityMap();
// 未找到相应的版本定义或者未定义
if (MapUtils.isEmpty(serviceEntityMap)) {
return;
}
List<DiscoveryServiceEntity> serviceEntityList = serviceEntityMap.get(consumerServiceId);
// 未找到相应的版本定义或者未定义
if (CollectionUtils.isEmpty(serviceEntityList)) {
return;
}
......
......@@ -18,9 +18,9 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
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.RegisterEntity;
import com.nepxion.discovery.plugin.core.entity.RegisterFilterType;
import com.nepxion.discovery.plugin.core.exception.PluginException;
public class RegisterStrategy {
......@@ -44,6 +44,10 @@ public class RegisterStrategy {
private void applyIpAddressFilter(String serviceId, String ipAddress) {
RegisterEntity registerEntity = pluginEntity.getRegisterEntity();
if (registerEntity == null) {
return;
}
RegisterFilterType filterType = registerEntity.getFilterType();
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