REM:
1. 增加判断设备是否支持IP判断
This commit is contained in:
HuangXin 2021-01-27 18:50:46 +08:00
parent 862a352b28
commit 4887952386
1 changed files with 49 additions and 5 deletions

View File

@ -8,10 +8,14 @@ import com.dispose.ability.impl.HuaWeiAbilityImpl;
import com.dispose.ability.impl.PengXinAbilityImpl; import com.dispose.ability.impl.PengXinAbilityImpl;
import com.dispose.ability.impl.VirtualAbilityImpl; import com.dispose.ability.impl.VirtualAbilityImpl;
import com.dispose.common.DisposeCapacityType; import com.dispose.common.DisposeCapacityType;
import com.dispose.common.DisposeConfigValue;
import com.dispose.common.DisposeObjectType;
import com.dispose.common.ErrorCode; import com.dispose.common.ErrorCode;
import com.dispose.common.Helper;
import com.dispose.common.HttpType; import com.dispose.common.HttpType;
import com.dispose.manager.DisposeDeviceManager; import com.dispose.manager.DisposeDeviceManager;
import com.dispose.mapper.ServiceGroupMapper; import com.dispose.mapper.ServiceGroupMapper;
import com.dispose.pojo.entity.DisposeCapacity;
import com.dispose.pojo.entity.DisposeDevice; import com.dispose.pojo.entity.DisposeDevice;
import com.dispose.pojo.po.AbilityInfo; import com.dispose.pojo.po.AbilityInfo;
import com.dispose.service.DisposeAbilityRouterService; import com.dispose.service.DisposeAbilityRouterService;
@ -88,7 +92,7 @@ public class DisposeAbilityRouterServiceImpl implements DisposeAbilityRouterServ
if (dev != null) { if (dev != null) {
return disposeAbilityMap.get(getAbilityDeviceHashKey(dev.getIpAddr(), dev.getIpPort(), return disposeAbilityMap.get(getAbilityDeviceHashKey(dev.getIpAddr(), dev.getIpPort(),
String.valueOf(dev.getDeviceType()))); String.valueOf(dev.getDeviceType())));
} }
return null; return null;
@ -115,7 +119,8 @@ public class DisposeAbilityRouterServiceImpl implements DisposeAbilityRouterServ
DisposeAbility db; DisposeAbility db;
String httpType = dev.getUrlType() == HttpType.HTTP ? "http://" : "https://"; String httpType = dev.getUrlType() == HttpType.HTTP ? "http://" : "https://";
String addr = (dev.getIpPort() == null || dev.getIpPort().length() == 0) ? dev.getIpAddr() : (dev.getIpAddr() + ":" + dev.getIpPort()); String addr = (dev.getIpPort() == null || dev.getIpPort()
.length() == 0) ? dev.getIpAddr() : (dev.getIpAddr() + ":" + dev.getIpPort());
String url = httpType + addr + "/" + dev.getUrlPath(); String url = httpType + addr + "/" + dev.getUrlPath();
switch (dev.getDeviceType()) { switch (dev.getDeviceType()) {
@ -148,7 +153,7 @@ public class DisposeAbilityRouterServiceImpl implements DisposeAbilityRouterServ
db.getDisposeDeviceProtectObject(); db.getDisposeDeviceProtectObject();
String hashKey = getAbilityDeviceHashKey(dev.getIpAddr(), dev.getIpPort(), String hashKey = getAbilityDeviceHashKey(dev.getIpAddr(), dev.getIpPort(),
String.valueOf(dev.getDeviceType())); String.valueOf(dev.getDeviceType()));
// 缓存处置设备到Hash表中 // 缓存处置设备到Hash表中
disposeAbilityMap.put(hashKey, AbilityInfo.builder() disposeAbilityMap.put(hashKey, AbilityInfo.builder()
@ -160,6 +165,38 @@ public class DisposeAbilityRouterServiceImpl implements DisposeAbilityRouterServ
return ErrorCode.ERR_OK; return ErrorCode.ERR_OK;
} }
/**
* Is carry ip boolean.
*
* @param disposeIp the dispose ip
* @param ipSegment the ip segment
* @return the boolean
*/
private boolean isCarryIp(String disposeIp, String ipSegment) {
for (String v : ipSegment.split(DisposeConfigValue.SPLIT_CHAR)) {
if (Helper.ipInRange(v, disposeIp)) {
return true;
}
}
return false;
}
/**
* Is carry dispose object boolean.
*
* @param disposeIp the dispose ip
* @param cfgProtect the cfg protect
* @return the boolean
*/
private boolean isCarryDisposeObject(String disposeIp, List<DisposeCapacity> cfgProtect) {
if (cfgProtect.stream().noneMatch(k -> (k.getObjectType().getValue() & DisposeObjectType.IP.getValue()) != 0)) {
return false;
}
return cfgProtect.stream().anyMatch(k -> isCarryIp(disposeIp, k.getProtectIp()));
}
/** /**
* Verify dispose capacity error code. * Verify dispose capacity error code.
* *
@ -182,6 +219,12 @@ public class DisposeAbilityRouterServiceImpl implements DisposeAbilityRouterServ
return ErrorCode.ERR_NOSUCHTYPE; return ErrorCode.ERR_NOSUCHTYPE;
} }
// if (getAllAbilityDevices().stream()
// .filter(f -> deviceId == -1 || f.getDev().getId().equals(deviceId))
// .noneMatch(f -> isCarryDisposeObject(disposeIp, f.getDev().getDevCapacity()))) {
// return ErrorCode.ERR_NOSUCHDEVICE;
// }
if (getAllAbilityDevices().stream() if (getAllAbilityDevices().stream()
.noneMatch(c -> c.getDb().isCarryProtectIp(disposeIp))) { .noneMatch(c -> c.getDb().isCarryProtectIp(disposeIp))) {
return ErrorCode.ERR_IPNODEVICE; return ErrorCode.ERR_IPNODEVICE;
@ -209,8 +252,9 @@ public class DisposeAbilityRouterServiceImpl implements DisposeAbilityRouterServ
/** /**
* Gets ability device hash key. * Gets ability device hash key.
* *
* @param ipAddr the ip addr * @param ipAddr the ip addr
* @param ipPort the ip port * @param ipPort the ip port
* @param deviceType the device type
* @return the ability device hash key * @return the ability device hash key
*/ */
private String getAbilityDeviceHashKey(String ipAddr, String ipPort, String deviceType) { private String getAbilityDeviceHashKey(String ipAddr, String ipPort, String deviceType) {