Commit e962149a by Nepxion

修改测试用例

parent 4a09d1a8
......@@ -41,7 +41,10 @@ public class MyDiscoveryEnabledAdapter implements DiscoveryEnabledAdapter {
LOG.info("Gateway端负载均衡用户定制触发:serviceId={}, host={}, metadata={}, context={}", serviceId, server.toString(), metadata, context);
if (StringUtils.equals(token, "abc")) {
String filterToken = "abc";
if (StringUtils.isNotEmpty(token) && token.contains(filterToken)) {
LOG.info("过滤条件:当Token含有'{}'的时候,不能被Ribbon负载均衡到", filterToken);
return false;
}
......
......@@ -17,6 +17,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import com.nepxion.discovery.plugin.framework.adapter.PluginAdapter;
import com.nepxion.discovery.plugin.framework.constant.PluginConstant;
import com.nepxion.discovery.plugin.strategy.discovery.DiscoveryEnabledAdapter;
import com.nepxion.discovery.plugin.strategy.extension.service.constant.ServiceStrategyConstant;
import com.nepxion.discovery.plugin.strategy.extension.service.context.ServiceStrategyContext;
......@@ -33,29 +34,28 @@ public class MyDiscoveryEnabledAdapter implements DiscoveryEnabledAdapter {
public boolean apply(Server server) {
ServiceStrategyContext context = ServiceStrategyContext.getCurrentContext();
Map<String, Object> attributes = context.getAttributes();
String serviceId = server.getMetaInfo().getAppName().toLowerCase();
Map<String, String> metadata = pluginAdapter.getServerMetadata(server);
String version = metadata.get(PluginConstant.VERSION);
LOG.info("Serivice端负载均衡用户定制触发:serviceId={}, host={}, metadata={}, context={}", serviceId, server.toString(), metadata, context);
if (attributes.containsKey(ServiceStrategyConstant.PARAMETER_MAP)) {
Map<String, Object> parameterMap = (Map<String, Object>) attributes.get(ServiceStrategyConstant.PARAMETER_MAP);
String value = parameterMap.get("value").toString();
if (StringUtils.isNotEmpty(value) && value.contains("abc")) {
LOG.info("过滤条件:当前端输入值包含'abc'的时候,不能被Ribbon负载均衡到");
return false;
String filterServiceId = "discovery-springcloud-example-c";
String filterVersion = "1.0";
String filterBusinessValue = "abc";
if (StringUtils.equals(serviceId, filterServiceId) && StringUtils.equals(version, filterVersion)) {
if (attributes.containsKey(ServiceStrategyConstant.PARAMETER_MAP)) {
Map<String, Object> parameterMap = (Map<String, Object>) attributes.get(ServiceStrategyConstant.PARAMETER_MAP);
String value = parameterMap.get("value").toString();
if (StringUtils.isNotEmpty(value) && value.contains(filterBusinessValue)) {
LOG.info("过滤条件:当serviceId={} && version={} && 业务参数含有'{}'的时候,不能被Ribbon负载均衡到", filterServiceId, filterVersion, filterBusinessValue);
return false;
}
}
}
/*String version = metadata.get(PluginConstant.VERSION);
if (StringUtils.equals(serviceId, "discovery-springcloud-example-c") && StringUtils.equals(version, "1.0")) {
LOG.info("过滤条件:当serviceId={},version={}的时候,不能被Ribbon负载均衡到", serviceId, version);
return false;
}*/
return true;
}
}
\ No newline at end of file
......@@ -38,8 +38,9 @@ public class MyDiscoveryEnabledAdapter implements DiscoveryEnabledAdapter {
LOG.info("Zuul端负载均衡用户定制触发:serviceId={}, host={}, metadata={}, context={}", serviceId, server.toString(), metadata, context);
if (StringUtils.isNotEmpty(token) && token.contains("abc")) {
LOG.info("过滤条件:当前端输入值包含'abc'的时候,不能被Ribbon负载均衡到");
String filterToken = "abc";
if (StringUtils.isNotEmpty(token) && token.contains(filterToken)) {
LOG.info("过滤条件:当Token含有'{}'的时候,不能被Ribbon负载均衡到", filterToken);
return false;
}
......
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