Commit 4bf2cd9e by Nepxion

元数据增加服务名

parent 5012a387
...@@ -36,6 +36,7 @@ public class ConsulApplicationContextInitializer extends PluginApplicationContex ...@@ -36,6 +36,7 @@ public class ConsulApplicationContextInitializer extends PluginApplicationContex
consulDiscoveryProperties.setPreferIpAddress(true); consulDiscoveryProperties.setPreferIpAddress(true);
List<String> tags = consulDiscoveryProperties.getTags(); List<String> tags = consulDiscoveryProperties.getTags();
tags.add(DiscoveryConstant.SPRING_APPLICATION_NAME + "=" + PluginContextAware.getApplicationName(environment));
tags.add(DiscoveryConstant.SPRING_APPLICATION_DISCOVERY_PLUGIN + "=" + ConsulConstant.DISCOVERY_PLUGIN); tags.add(DiscoveryConstant.SPRING_APPLICATION_DISCOVERY_PLUGIN + "=" + ConsulConstant.DISCOVERY_PLUGIN);
tags.add(DiscoveryConstant.SPRING_APPLICATION_DISCOVERY_VERSION + "=" + DiscoveryConstant.DISCOVERY_VERSION); tags.add(DiscoveryConstant.SPRING_APPLICATION_DISCOVERY_VERSION + "=" + DiscoveryConstant.DISCOVERY_VERSION);
tags.add(DiscoveryConstant.SPRING_APPLICATION_REGISTER_CONTROL_ENABLED + "=" + PluginContextAware.isRegisterControlEnabled(environment)); tags.add(DiscoveryConstant.SPRING_APPLICATION_REGISTER_CONTROL_ENABLED + "=" + PluginContextAware.isRegisterControlEnabled(environment));
......
...@@ -36,6 +36,7 @@ public class EurekaApplicationContextInitializer extends PluginApplicationContex ...@@ -36,6 +36,7 @@ public class EurekaApplicationContextInitializer extends PluginApplicationContex
eurekaInstanceConfig.setPreferIpAddress(true); eurekaInstanceConfig.setPreferIpAddress(true);
Map<String, String> metadataMap = eurekaInstanceConfig.getMetadataMap(); Map<String, String> metadataMap = eurekaInstanceConfig.getMetadataMap();
metadataMap.put(DiscoveryConstant.SPRING_APPLICATION_NAME, PluginContextAware.getApplicationName(environment));
metadataMap.put(DiscoveryConstant.SPRING_APPLICATION_DISCOVERY_PLUGIN, EurekaConstant.DISCOVERY_PLUGIN); metadataMap.put(DiscoveryConstant.SPRING_APPLICATION_DISCOVERY_PLUGIN, EurekaConstant.DISCOVERY_PLUGIN);
metadataMap.put(DiscoveryConstant.SPRING_APPLICATION_DISCOVERY_VERSION, DiscoveryConstant.DISCOVERY_VERSION); metadataMap.put(DiscoveryConstant.SPRING_APPLICATION_DISCOVERY_VERSION, DiscoveryConstant.DISCOVERY_VERSION);
metadataMap.put(DiscoveryConstant.SPRING_APPLICATION_REGISTER_CONTROL_ENABLED, PluginContextAware.isRegisterControlEnabled(environment).toString()); metadataMap.put(DiscoveryConstant.SPRING_APPLICATION_REGISTER_CONTROL_ENABLED, PluginContextAware.isRegisterControlEnabled(environment).toString());
......
...@@ -35,6 +35,7 @@ public class NacosApplicationContextInitializer extends PluginApplicationContext ...@@ -35,6 +35,7 @@ public class NacosApplicationContextInitializer extends PluginApplicationContext
NacosDiscoveryProperties nacosDiscoveryProperties = (NacosDiscoveryProperties) bean; NacosDiscoveryProperties nacosDiscoveryProperties = (NacosDiscoveryProperties) bean;
Map<String, String> metadata = nacosDiscoveryProperties.getMetadata(); Map<String, String> metadata = nacosDiscoveryProperties.getMetadata();
metadata.put(DiscoveryConstant.SPRING_APPLICATION_NAME, PluginContextAware.getApplicationName(environment));
metadata.put(DiscoveryConstant.SPRING_APPLICATION_DISCOVERY_PLUGIN, NacosConstant.DISCOVERY_PLUGIN); metadata.put(DiscoveryConstant.SPRING_APPLICATION_DISCOVERY_PLUGIN, NacosConstant.DISCOVERY_PLUGIN);
metadata.put(DiscoveryConstant.SPRING_APPLICATION_DISCOVERY_VERSION, DiscoveryConstant.DISCOVERY_VERSION); metadata.put(DiscoveryConstant.SPRING_APPLICATION_DISCOVERY_VERSION, DiscoveryConstant.DISCOVERY_VERSION);
metadata.put(DiscoveryConstant.SPRING_APPLICATION_REGISTER_CONTROL_ENABLED, PluginContextAware.isRegisterControlEnabled(environment).toString()); metadata.put(DiscoveryConstant.SPRING_APPLICATION_REGISTER_CONTROL_ENABLED, PluginContextAware.isRegisterControlEnabled(environment).toString());
......
...@@ -36,6 +36,7 @@ public class ZookeeperApplicationContextInitializer extends PluginApplicationCon ...@@ -36,6 +36,7 @@ public class ZookeeperApplicationContextInitializer extends PluginApplicationCon
zookeeperDiscoveryProperties.setPreferIpAddress(true); zookeeperDiscoveryProperties.setPreferIpAddress(true);
Map<String, String> metadata = zookeeperDiscoveryProperties.getMetadata(); Map<String, String> metadata = zookeeperDiscoveryProperties.getMetadata();
metadata.put(DiscoveryConstant.SPRING_APPLICATION_NAME, PluginContextAware.getApplicationName(environment));
metadata.put(DiscoveryConstant.SPRING_APPLICATION_DISCOVERY_PLUGIN, ZookeeperConstant.DISCOVERY_PLUGIN); metadata.put(DiscoveryConstant.SPRING_APPLICATION_DISCOVERY_PLUGIN, ZookeeperConstant.DISCOVERY_PLUGIN);
metadata.put(DiscoveryConstant.SPRING_APPLICATION_DISCOVERY_VERSION, DiscoveryConstant.DISCOVERY_VERSION); metadata.put(DiscoveryConstant.SPRING_APPLICATION_DISCOVERY_VERSION, DiscoveryConstant.DISCOVERY_VERSION);
metadata.put(DiscoveryConstant.SPRING_APPLICATION_REGISTER_CONTROL_ENABLED, PluginContextAware.isRegisterControlEnabled(environment).toString()); metadata.put(DiscoveryConstant.SPRING_APPLICATION_REGISTER_CONTROL_ENABLED, PluginContextAware.isRegisterControlEnabled(environment).toString());
......
...@@ -148,6 +148,11 @@ public abstract class AbstractPluginAdapter implements PluginAdapter { ...@@ -148,6 +148,11 @@ public abstract class AbstractPluginAdapter implements PluginAdapter {
} }
@Override @Override
public String getServerServiceId(Server server) {
return getServerMetadata(server).get(DiscoveryConstant.SPRING_APPLICATION_NAME).toLowerCase();
}
@Override
public String getServerVersion(Server server) { public String getServerVersion(Server server) {
return getServerMetadata(server).get(DiscoveryConstant.VERSION); return getServerMetadata(server).get(DiscoveryConstant.VERSION);
} }
......
...@@ -53,6 +53,8 @@ public interface PluginAdapter { ...@@ -53,6 +53,8 @@ public interface PluginAdapter {
Map<String, String> getServerMetadata(Server server); Map<String, String> getServerMetadata(Server server);
String getServerServiceId(Server server);
String getServerVersion(Server server); String getServerVersion(Server server);
String getServerRegion(Server server); String getServerRegion(Server server);
......
...@@ -133,6 +133,10 @@ public class PluginContextAware implements ApplicationContextAware { ...@@ -133,6 +133,10 @@ public class PluginContextAware implements ApplicationContextAware {
return environment.getProperty(DiscoveryConstant.SPRING_APPLICATION_CONFIG_PATH, String.class, StringUtils.equals(getConfigFormat(environment), DiscoveryConstant.XML_FORMAT) ? DiscoveryConstant.PREFIX_CLASSPATH + DiscoveryConstant.RULE + "." + DiscoveryConstant.XML_FORMAT : DiscoveryConstant.PREFIX_CLASSPATH + DiscoveryConstant.RULE + "." + DiscoveryConstant.JSON_FORMAT); return environment.getProperty(DiscoveryConstant.SPRING_APPLICATION_CONFIG_PATH, String.class, StringUtils.equals(getConfigFormat(environment), DiscoveryConstant.XML_FORMAT) ? DiscoveryConstant.PREFIX_CLASSPATH + DiscoveryConstant.RULE + "." + DiscoveryConstant.XML_FORMAT : DiscoveryConstant.PREFIX_CLASSPATH + DiscoveryConstant.RULE + "." + DiscoveryConstant.JSON_FORMAT);
} }
public static String getApplicationName(Environment environment) {
return environment.getProperty(DiscoveryConstant.SPRING_APPLICATION_NAME);
}
public static String getGroupKey(Environment environment) { public static String getGroupKey(Environment environment) {
return environment.getProperty(DiscoveryConstant.SPRING_APPLICATION_GROUP_KEY, String.class, DiscoveryConstant.GROUP); return environment.getProperty(DiscoveryConstant.SPRING_APPLICATION_GROUP_KEY, String.class, DiscoveryConstant.GROUP);
} }
......
...@@ -96,7 +96,7 @@ public class WeightRandomLoadBalance { ...@@ -96,7 +96,7 @@ public class WeightRandomLoadBalance {
Map<String, List<WeightEntity>> weightEntityMap = weightFilterEntity.getWeightEntityMap(); Map<String, List<WeightEntity>> weightEntityMap = weightFilterEntity.getWeightEntityMap();
RegionWeightEntity regionWeightEntity = weightFilterEntity.getRegionWeightEntity(); RegionWeightEntity regionWeightEntity = weightFilterEntity.getRegionWeightEntity();
String providerServiceId = server.getMetaInfo().getAppName(); String providerServiceId = pluginAdapter.getServerServiceId(server);
String providerVersion = pluginAdapter.getServerVersion(server); String providerVersion = pluginAdapter.getServerVersion(server);
String providerRegion = pluginAdapter.getServerRegion(server); String providerRegion = pluginAdapter.getServerRegion(server);
......
...@@ -29,7 +29,7 @@ public class DefaultDiscoveryEnabledAdapter extends AbstractDiscoveryEnabledAdap ...@@ -29,7 +29,7 @@ public class DefaultDiscoveryEnabledAdapter extends AbstractDiscoveryEnabledAdap
protected String getVersionValue(Server server) { protected String getVersionValue(Server server) {
ServerWebExchange exchange = gatewayStrategyContextHolder.getExchange(); ServerWebExchange exchange = gatewayStrategyContextHolder.getExchange();
if (exchange == null) { if (exchange == null) {
String serviceId = server.getMetaInfo().getAppName().toLowerCase(); String serviceId = pluginAdapter.getServerServiceId(server);
LOG.warn("The ServerWebExchange object is null, ignore to do version filter for service={}...", serviceId); LOG.warn("The ServerWebExchange object is null, ignore to do version filter for service={}...", serviceId);
...@@ -43,7 +43,7 @@ public class DefaultDiscoveryEnabledAdapter extends AbstractDiscoveryEnabledAdap ...@@ -43,7 +43,7 @@ public class DefaultDiscoveryEnabledAdapter extends AbstractDiscoveryEnabledAdap
protected String getRegionValue(Server server) { protected String getRegionValue(Server server) {
ServerWebExchange exchange = gatewayStrategyContextHolder.getExchange(); ServerWebExchange exchange = gatewayStrategyContextHolder.getExchange();
if (exchange == null) { if (exchange == null) {
String serviceId = server.getMetaInfo().getAppName().toLowerCase(); String serviceId = pluginAdapter.getServerServiceId(server);
LOG.warn("The ServerWebExchange object is null, ignore to do region filter for service={}...", serviceId); LOG.warn("The ServerWebExchange object is null, ignore to do region filter for service={}...", serviceId);
...@@ -57,7 +57,7 @@ public class DefaultDiscoveryEnabledAdapter extends AbstractDiscoveryEnabledAdap ...@@ -57,7 +57,7 @@ public class DefaultDiscoveryEnabledAdapter extends AbstractDiscoveryEnabledAdap
protected String getAddressValue(Server server) { protected String getAddressValue(Server server) {
ServerWebExchange exchange = gatewayStrategyContextHolder.getExchange(); ServerWebExchange exchange = gatewayStrategyContextHolder.getExchange();
if (exchange == null) { if (exchange == null) {
String serviceId = server.getMetaInfo().getAppName().toLowerCase(); String serviceId = pluginAdapter.getServerServiceId(server);
LOG.warn("The ServerWebExchange object is null, ignore to do region filter for service={}...", serviceId); LOG.warn("The ServerWebExchange object is null, ignore to do region filter for service={}...", serviceId);
......
...@@ -29,7 +29,7 @@ public class DefaultDiscoveryEnabledAdapter extends AbstractDiscoveryEnabledAdap ...@@ -29,7 +29,7 @@ public class DefaultDiscoveryEnabledAdapter extends AbstractDiscoveryEnabledAdap
protected String getVersionValue(Server server) { protected String getVersionValue(Server server) {
ServletRequestAttributes attributes = serviceStrategyContextHolder.getRestAttributes(); ServletRequestAttributes attributes = serviceStrategyContextHolder.getRestAttributes();
if (attributes == null) { if (attributes == null) {
String serviceId = server.getMetaInfo().getAppName().toLowerCase(); String serviceId = pluginAdapter.getServerServiceId(server);
LOG.warn("The ServletRequestAttributes object is null, ignore to do version filter for service={}...", serviceId); LOG.warn("The ServletRequestAttributes object is null, ignore to do version filter for service={}...", serviceId);
...@@ -43,7 +43,7 @@ public class DefaultDiscoveryEnabledAdapter extends AbstractDiscoveryEnabledAdap ...@@ -43,7 +43,7 @@ public class DefaultDiscoveryEnabledAdapter extends AbstractDiscoveryEnabledAdap
protected String getRegionValue(Server server) { protected String getRegionValue(Server server) {
ServletRequestAttributes attributes = serviceStrategyContextHolder.getRestAttributes(); ServletRequestAttributes attributes = serviceStrategyContextHolder.getRestAttributes();
if (attributes == null) { if (attributes == null) {
String serviceId = server.getMetaInfo().getAppName().toLowerCase(); String serviceId = pluginAdapter.getServerServiceId(server);
LOG.warn("The ServletRequestAttributes object is null, ignore to do region filter for service={}...", serviceId); LOG.warn("The ServletRequestAttributes object is null, ignore to do region filter for service={}...", serviceId);
...@@ -57,7 +57,7 @@ public class DefaultDiscoveryEnabledAdapter extends AbstractDiscoveryEnabledAdap ...@@ -57,7 +57,7 @@ public class DefaultDiscoveryEnabledAdapter extends AbstractDiscoveryEnabledAdap
protected String getAddressValue(Server server) { protected String getAddressValue(Server server) {
ServletRequestAttributes attributes = serviceStrategyContextHolder.getRestAttributes(); ServletRequestAttributes attributes = serviceStrategyContextHolder.getRestAttributes();
if (attributes == null) { if (attributes == null) {
String serviceId = server.getMetaInfo().getAppName().toLowerCase(); String serviceId = pluginAdapter.getServerServiceId(server);
LOG.warn("The ServletRequestAttributes object is null, ignore to do region filter for service={}...", serviceId); LOG.warn("The ServletRequestAttributes object is null, ignore to do region filter for service={}...", serviceId);
......
...@@ -30,7 +30,7 @@ public class DefaultDiscoveryEnabledAdapter extends AbstractDiscoveryEnabledAdap ...@@ -30,7 +30,7 @@ public class DefaultDiscoveryEnabledAdapter extends AbstractDiscoveryEnabledAdap
protected String getVersionValue(Server server) { protected String getVersionValue(Server server) {
HttpServletRequest request = zuulStrategyContextHolder.getRequest(); HttpServletRequest request = zuulStrategyContextHolder.getRequest();
if (request == null) { if (request == null) {
String serviceId = server.getMetaInfo().getAppName().toLowerCase(); String serviceId = pluginAdapter.getServerServiceId(server);
LOG.warn("The HttpServletRequest object is null, ignore to do version filter for service={}...", serviceId); LOG.warn("The HttpServletRequest object is null, ignore to do version filter for service={}...", serviceId);
...@@ -44,7 +44,7 @@ public class DefaultDiscoveryEnabledAdapter extends AbstractDiscoveryEnabledAdap ...@@ -44,7 +44,7 @@ public class DefaultDiscoveryEnabledAdapter extends AbstractDiscoveryEnabledAdap
protected String getRegionValue(Server server) { protected String getRegionValue(Server server) {
HttpServletRequest request = zuulStrategyContextHolder.getRequest(); HttpServletRequest request = zuulStrategyContextHolder.getRequest();
if (request == null) { if (request == null) {
String serviceId = server.getMetaInfo().getAppName().toLowerCase(); String serviceId = pluginAdapter.getServerServiceId(server);
LOG.warn("The HttpServletRequest object is null, ignore to do region filter for service={}...", serviceId); LOG.warn("The HttpServletRequest object is null, ignore to do region filter for service={}...", serviceId);
...@@ -58,7 +58,7 @@ public class DefaultDiscoveryEnabledAdapter extends AbstractDiscoveryEnabledAdap ...@@ -58,7 +58,7 @@ public class DefaultDiscoveryEnabledAdapter extends AbstractDiscoveryEnabledAdap
protected String getAddressValue(Server server) { protected String getAddressValue(Server server) {
HttpServletRequest request = zuulStrategyContextHolder.getRequest(); HttpServletRequest request = zuulStrategyContextHolder.getRequest();
if (request == null) { if (request == null) {
String serviceId = server.getMetaInfo().getAppName().toLowerCase(); String serviceId = pluginAdapter.getServerServiceId(server);
LOG.warn("The HttpServletRequest object is null, ignore to do region filter for service={}...", serviceId); LOG.warn("The HttpServletRequest object is null, ignore to do region filter for service={}...", serviceId);
......
...@@ -28,7 +28,7 @@ public abstract class AbstractDiscoveryEnabledAdapter implements DiscoveryEnable ...@@ -28,7 +28,7 @@ public abstract class AbstractDiscoveryEnabledAdapter implements DiscoveryEnable
private DiscoveryEnabledStrategy discoveryEnabledStrategy; private DiscoveryEnabledStrategy discoveryEnabledStrategy;
@Autowired @Autowired
private PluginAdapter pluginAdapter; protected PluginAdapter pluginAdapter;
@Override @Override
public boolean apply(Server server, Map<String, String> metadata) { public boolean apply(Server server, Map<String, String> metadata) {
...@@ -75,7 +75,7 @@ public abstract class AbstractDiscoveryEnabledAdapter implements DiscoveryEnable ...@@ -75,7 +75,7 @@ public abstract class AbstractDiscoveryEnabledAdapter implements DiscoveryEnable
String versions = null; String versions = null;
try { try {
Map<String, String> versionMap = JsonUtil.fromJson(versionValue, Map.class); Map<String, String> versionMap = JsonUtil.fromJson(versionValue, Map.class);
String serviceId = server.getMetaInfo().getAppName().toLowerCase(); String serviceId = pluginAdapter.getServerServiceId(server);
versions = versionMap.get(serviceId); versions = versionMap.get(serviceId);
} catch (Exception e) { } catch (Exception e) {
versions = versionValue; versions = versionValue;
...@@ -118,7 +118,7 @@ public abstract class AbstractDiscoveryEnabledAdapter implements DiscoveryEnable ...@@ -118,7 +118,7 @@ public abstract class AbstractDiscoveryEnabledAdapter implements DiscoveryEnable
String regions = null; String regions = null;
try { try {
Map<String, String> regionMap = JsonUtil.fromJson(regionValue, Map.class); Map<String, String> regionMap = JsonUtil.fromJson(regionValue, Map.class);
String serviceId = server.getMetaInfo().getAppName().toLowerCase(); String serviceId = pluginAdapter.getServerServiceId(server);
regions = regionMap.get(serviceId); regions = regionMap.get(serviceId);
} catch (Exception e) { } catch (Exception e) {
regions = regionValue; regions = regionValue;
...@@ -154,7 +154,7 @@ public abstract class AbstractDiscoveryEnabledAdapter implements DiscoveryEnable ...@@ -154,7 +154,7 @@ public abstract class AbstractDiscoveryEnabledAdapter implements DiscoveryEnable
} }
Map<String, String> addressMap = JsonUtil.fromJson(addressValue, Map.class); Map<String, String> addressMap = JsonUtil.fromJson(addressValue, Map.class);
String serviceId = server.getMetaInfo().getAppName().toLowerCase(); String serviceId = pluginAdapter.getServerServiceId(server);
String addresses = addressMap.get(serviceId); String addresses = addressMap.get(serviceId);
if (StringUtils.isEmpty(addresses)) { if (StringUtils.isEmpty(addresses)) {
return true; return true;
......
...@@ -17,6 +17,7 @@ import org.slf4j.LoggerFactory; ...@@ -17,6 +17,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.ServerWebExchange;
import com.nepxion.discovery.plugin.framework.adapter.PluginAdapter;
import com.nepxion.discovery.plugin.strategy.adapter.DiscoveryEnabledStrategy; import com.nepxion.discovery.plugin.strategy.adapter.DiscoveryEnabledStrategy;
import com.nepxion.discovery.plugin.strategy.gateway.context.GatewayStrategyContextHolder; import com.nepxion.discovery.plugin.strategy.gateway.context.GatewayStrategyContextHolder;
import com.netflix.loadbalancer.Server; import com.netflix.loadbalancer.Server;
...@@ -28,6 +29,9 @@ public class MyDiscoveryEnabledStrategy implements DiscoveryEnabledStrategy { ...@@ -28,6 +29,9 @@ public class MyDiscoveryEnabledStrategy implements DiscoveryEnabledStrategy {
@Autowired @Autowired
private GatewayStrategyContextHolder gatewayStrategyContextHolder; private GatewayStrategyContextHolder gatewayStrategyContextHolder;
@Autowired
private PluginAdapter pluginAdapter;
@Override @Override
public boolean apply(Server server, Map<String, String> metadata) { public boolean apply(Server server, Map<String, String> metadata) {
// 对Rest调用传来的Header参数(例如Token)做策略 // 对Rest调用传来的Header参数(例如Token)做策略
...@@ -44,7 +48,7 @@ public class MyDiscoveryEnabledStrategy implements DiscoveryEnabledStrategy { ...@@ -44,7 +48,7 @@ public class MyDiscoveryEnabledStrategy implements DiscoveryEnabledStrategy {
String token = exchange.getRequest().getHeaders().getFirst("token"); String token = exchange.getRequest().getHeaders().getFirst("token");
// String value = exchange.getRequest().getQueryParams().getFirst("value"); // String value = exchange.getRequest().getQueryParams().getFirst("value");
String serviceId = server.getMetaInfo().getAppName().toLowerCase(); String serviceId = pluginAdapter.getServerServiceId(server);
LOG.info("Gateway端负载均衡用户定制触发:serviceId={}, host={}, metadata={}", serviceId, server.toString(), metadata); LOG.info("Gateway端负载均衡用户定制触发:serviceId={}, host={}, metadata={}", serviceId, server.toString(), metadata);
......
...@@ -18,6 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -18,6 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.request.ServletRequestAttributes; import org.springframework.web.context.request.ServletRequestAttributes;
import com.nepxion.discovery.common.constant.DiscoveryConstant; import com.nepxion.discovery.common.constant.DiscoveryConstant;
import com.nepxion.discovery.plugin.framework.adapter.PluginAdapter;
import com.nepxion.discovery.plugin.strategy.adapter.DiscoveryEnabledStrategy; import com.nepxion.discovery.plugin.strategy.adapter.DiscoveryEnabledStrategy;
import com.nepxion.discovery.plugin.strategy.service.constant.ServiceStrategyConstant; import com.nepxion.discovery.plugin.strategy.service.constant.ServiceStrategyConstant;
import com.nepxion.discovery.plugin.strategy.service.context.ServiceStrategyContextHolder; import com.nepxion.discovery.plugin.strategy.service.context.ServiceStrategyContextHolder;
...@@ -30,6 +31,9 @@ public class MyDiscoveryEnabledStrategy implements DiscoveryEnabledStrategy { ...@@ -30,6 +31,9 @@ public class MyDiscoveryEnabledStrategy implements DiscoveryEnabledStrategy {
@Autowired @Autowired
private ServiceStrategyContextHolder serviceStrategyContextHolder; private ServiceStrategyContextHolder serviceStrategyContextHolder;
@Autowired
private PluginAdapter pluginAdapter;
@Override @Override
public boolean apply(Server server, Map<String, String> metadata) { public boolean apply(Server server, Map<String, String> metadata) {
// 对Rest调用传来的Header参数(例如Token)做策略 // 对Rest调用传来的Header参数(例如Token)做策略
...@@ -52,7 +56,7 @@ public class MyDiscoveryEnabledStrategy implements DiscoveryEnabledStrategy { ...@@ -52,7 +56,7 @@ public class MyDiscoveryEnabledStrategy implements DiscoveryEnabledStrategy {
String token = attributes.getRequest().getHeader("token"); String token = attributes.getRequest().getHeader("token");
// String value = attributes.getRequest().getParameter("value"); // String value = attributes.getRequest().getParameter("value");
String serviceId = server.getMetaInfo().getAppName().toLowerCase(); String serviceId = pluginAdapter.getServerServiceId(server);
LOG.info("Serivice端负载均衡用户定制触发:serviceId={}, host={}, metadata={}, attributes={}", serviceId, server.toString(), metadata, attributes); LOG.info("Serivice端负载均衡用户定制触发:serviceId={}, host={}, metadata={}, attributes={}", serviceId, server.toString(), metadata, attributes);
...@@ -72,7 +76,7 @@ public class MyDiscoveryEnabledStrategy implements DiscoveryEnabledStrategy { ...@@ -72,7 +76,7 @@ public class MyDiscoveryEnabledStrategy implements DiscoveryEnabledStrategy {
private boolean applyFromMethod(Server server, Map<String, String> metadata) { private boolean applyFromMethod(Server server, Map<String, String> metadata) {
Map<String, Object> attributes = serviceStrategyContextHolder.getRpcAttributes(); Map<String, Object> attributes = serviceStrategyContextHolder.getRpcAttributes();
String serviceId = server.getMetaInfo().getAppName().toLowerCase(); String serviceId = pluginAdapter.getServerServiceId(server);
String version = metadata.get(DiscoveryConstant.VERSION); String version = metadata.get(DiscoveryConstant.VERSION);
LOG.info("Serivice端负载均衡用户定制触发:serviceId={}, host={}, metadata={}, attributes={}", serviceId, server.toString(), metadata, attributes); LOG.info("Serivice端负载均衡用户定制触发:serviceId={}, host={}, metadata={}, attributes={}", serviceId, server.toString(), metadata, attributes);
......
...@@ -18,6 +18,7 @@ import org.slf4j.Logger; ...@@ -18,6 +18,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import com.nepxion.discovery.plugin.framework.adapter.PluginAdapter;
import com.nepxion.discovery.plugin.strategy.adapter.DiscoveryEnabledStrategy; import com.nepxion.discovery.plugin.strategy.adapter.DiscoveryEnabledStrategy;
import com.nepxion.discovery.plugin.strategy.zuul.context.ZuulStrategyContextHolder; import com.nepxion.discovery.plugin.strategy.zuul.context.ZuulStrategyContextHolder;
import com.netflix.loadbalancer.Server; import com.netflix.loadbalancer.Server;
...@@ -29,6 +30,9 @@ public class MyDiscoveryEnabledStrategy implements DiscoveryEnabledStrategy { ...@@ -29,6 +30,9 @@ public class MyDiscoveryEnabledStrategy implements DiscoveryEnabledStrategy {
@Autowired @Autowired
private ZuulStrategyContextHolder zuulStrategyContextHolder; private ZuulStrategyContextHolder zuulStrategyContextHolder;
@Autowired
private PluginAdapter pluginAdapter;
@Override @Override
public boolean apply(Server server, Map<String, String> metadata) { public boolean apply(Server server, Map<String, String> metadata) {
// 对Rest调用传来的Header参数(例如Token)做策略 // 对Rest调用传来的Header参数(例如Token)做策略
...@@ -45,7 +49,7 @@ public class MyDiscoveryEnabledStrategy implements DiscoveryEnabledStrategy { ...@@ -45,7 +49,7 @@ public class MyDiscoveryEnabledStrategy implements DiscoveryEnabledStrategy {
String token = request.getHeader("token"); String token = request.getHeader("token");
// String value = request.getParameter("value"); // String value = request.getParameter("value");
String serviceId = server.getMetaInfo().getAppName().toLowerCase(); String serviceId = pluginAdapter.getServerServiceId(server);
LOG.info("Zuul端负载均衡用户定制触发:serviceId={}, host={}, metadata={}", serviceId, server.toString(), metadata); LOG.info("Zuul端负载均衡用户定制触发:serviceId={}, host={}, metadata={}", serviceId, server.toString(), metadata);
......
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