|
@@ -1,17 +1,15 @@
|
|
|
package com.mrxu.framework.boot.irule;
|
|
package com.mrxu.framework.boot.irule;
|
|
|
|
|
|
|
|
import com.mrxu.framework.boot.util.SpringApplicationContextUtil;
|
|
import com.mrxu.framework.boot.util.SpringApplicationContextUtil;
|
|
|
|
|
+import com.mrxu.framework.boot.util.SystemInfo;
|
|
|
import com.netflix.loadbalancer.AbstractServerPredicate;
|
|
import com.netflix.loadbalancer.AbstractServerPredicate;
|
|
|
import com.netflix.loadbalancer.IRule;
|
|
import com.netflix.loadbalancer.IRule;
|
|
|
import com.netflix.loadbalancer.PredicateKey;
|
|
import com.netflix.loadbalancer.PredicateKey;
|
|
|
import com.netflix.niws.loadbalancer.DiscoveryEnabledServer;
|
|
import com.netflix.niws.loadbalancer.DiscoveryEnabledServer;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.commons.lang.StringUtils;
|
|
|
|
|
import org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean;
|
|
import org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean;
|
|
|
|
|
|
|
|
-import java.util.Iterator;
|
|
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
-import java.util.Set;
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 功能概要:[服务合法判断逻辑] <br>
|
|
* 功能概要:[服务合法判断逻辑] <br>
|
|
@@ -43,20 +41,16 @@ public class MetadataAwarePredicate extends AbstractServerPredicate {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
DiscoveryEnabledServer server = (DiscoveryEnabledServer) input.getServer();
|
|
DiscoveryEnabledServer server = (DiscoveryEnabledServer) input.getServer();
|
|
|
- Map<String, String> currentMetaDataInfo = eurekaInstanceConfigBean.getMetadataMap();
|
|
|
|
|
- Map<String, String> metadata = server.getInstanceInfo().getMetadata();
|
|
|
|
|
- if(currentMetaDataInfo==null||currentMetaDataInfo.size()<=0||metadata==null||metadata.size()<=0){
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
- Set<Map.Entry<String, String>> curEntries = currentMetaDataInfo.entrySet();
|
|
|
|
|
- Iterator<Map.Entry<String, String>> curit = curEntries.iterator();
|
|
|
|
|
- while(curit.hasNext()){
|
|
|
|
|
- Map.Entry<String, String> entry = curit.next();
|
|
|
|
|
- if("management.port".equalsIgnoreCase(entry.getKey())){
|
|
|
|
|
- continue;
|
|
|
|
|
|
|
+ String isOpenDevStr = eurekaInstanceConfigBean.getEnvironment().getProperty("spring.application.open-dev","false");
|
|
|
|
|
+ if("true".equalsIgnoreCase(isOpenDevStr)){
|
|
|
|
|
+ //本地开启调试模式,转发本机机器码的服务
|
|
|
|
|
+ String localMac = SystemInfo.getLocalMac();
|
|
|
|
|
+ Map<String, String> metadata = server.getInstanceInfo().getMetadata();
|
|
|
|
|
+ if(metadata==null||metadata.size()<=0||!metadata.keySet().contains("mac-addr")){
|
|
|
|
|
+ return false;
|
|
|
}
|
|
}
|
|
|
- String fetchValue = metadata.get(entry.getKey());
|
|
|
|
|
- if(StringUtils.isBlank(fetchValue)||!fetchValue.equals(entry.getValue())){
|
|
|
|
|
|
|
+ String remoteMac = metadata.get("mac-addr");
|
|
|
|
|
+ if(!localMac.equalsIgnoreCase(remoteMac)){
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|