REM:
1. 集团一键处置,移除对设备能力信息的判断,默认设备支持处置能力以及处置的IP
This commit is contained in:
HuangXin 2021-10-20 09:17:57 +08:00
parent 5c11f53992
commit f92bc9a097
1 changed files with 85 additions and 79 deletions

View File

@ -163,10 +163,12 @@ public class PengXinAbilityImpl implements DisposeAbility {
try {
log.info("++++Begging PengXin Start Cleanup Task: {}", disposeObject);
if (capType != DisposeCapacityType.BLACKHOOL) {
log.error("----Error PengXin don't support dispose capacity type: {}", capType);
return new MulReturnType<>(ErrorCode.ERR_UNSUPPORT, null);
}
// 集团一键处置线上环境移除对处置能力检测操作
// if (capType != DisposeCapacityType.BLACKHOOL) {
// log.error("----Error PengXin don't support dispose capacity type: {}", capType);
// return new MulReturnType<>(ErrorCode.ERR_UNSUPPORT, null);
// }
// 适配处置时间参数 -1为不限制处置时间
if (duration == null || duration < 0) {
@ -359,54 +361,55 @@ public class PengXinAbilityImpl implements DisposeAbility {
*/
@Override
public void getDisposeDeviceProtectObject() {
// 集团一键处置线上环境移除从设备获取能力信息相关接口调用
if (token == null || token.length() == 0) {
return;
}
// if (token == null || token.length() == 0) {
// return;
// }
try {
String url = urlRootPath + "dispose_device/information/capacity";
ProtocolRespDTO<PengXinDisposeAbilityRsp> rspInfo = restfulInterface.getDeviceDisposeAbility(url, token);
// 判断是否token过期
if (rspInfo != null && reLogin(rspInfo, rspInfo.getMsgContent().getStatus())) {
rspInfo = restfulInterface.getDeviceDisposeAbility(url, token);
}
if (rspInfo != null && rspInfo.getCode() == ErrorCode.ERR_OK.getHttpCode()
&& rspInfo.getMsgContent().getStatus() == ErrorCode.ERR_OK.getCode()) {
rspInfo.getMsgContent().getCapacity().forEach(v -> {
if (v.getObjectType().equals(DisposeObjectType.DOMAIN.getValue())) {
log.error("Unsupported: {}", v.getObjectType());
} else if (v.getObjectType().equals(DisposeObjectType.URL.getValue())) {
log.error("Unsupported: {}", v.getObjectType());
} else {
synchronized (this) {
protectIpV4.clear();
protectIpV6.clear();
if (v.getIpType() == null || v.getIpType().equals(IpAddrType.IPV4_IPV6.getValue())) {
String [] allIpAddr = {null, "0.0.0.0", "0.0.0.0,::"};
if(Arrays.asList(allIpAddr).contains(v.getDisposeIp())) {
protectIpV4.add("");
protectIpV6.add("");
}
} else if (v.getIpType().equals(IpAddrType.IPV4.getValue())) {
protectIpV4.add("");
} else if (v.getIpType().equals(IpAddrType.IPV6.getValue())) {
protectIpV6.add("");
}
}
}
});
}
} catch (Exception ignored) {
}
// try {
// String url = urlRootPath + "dispose_device/information/capacity";
//
// ProtocolRespDTO<PengXinDisposeAbilityRsp> rspInfo = restfulInterface.getDeviceDisposeAbility(url, token);
//
// // 判断是否token过期
// if (rspInfo != null && reLogin(rspInfo, rspInfo.getMsgContent().getStatus())) {
// rspInfo = restfulInterface.getDeviceDisposeAbility(url, token);
// }
//
// if (rspInfo != null && rspInfo.getCode() == ErrorCode.ERR_OK.getHttpCode()
// && rspInfo.getMsgContent().getStatus() == ErrorCode.ERR_OK.getCode()) {
//
// rspInfo.getMsgContent().getCapacity().forEach(v -> {
// if (v.getObjectType().equals(DisposeObjectType.DOMAIN.getValue())) {
// log.error("Unsupported: {}", v.getObjectType());
// } else if (v.getObjectType().equals(DisposeObjectType.URL.getValue())) {
// log.error("Unsupported: {}", v.getObjectType());
// } else {
// synchronized (this) {
//
// protectIpV4.clear();
// protectIpV6.clear();
//
// if (v.getIpType() == null || v.getIpType().equals(IpAddrType.IPV4_IPV6.getValue())) {
// String [] allIpAddr = {null, "0.0.0.0", "0.0.0.0,::"};
//
// if(Arrays.asList(allIpAddr).contains(v.getDisposeIp())) {
// protectIpV4.add("");
// protectIpV6.add("");
// }
// } else if (v.getIpType().equals(IpAddrType.IPV4.getValue())) {
// protectIpV4.add("");
// } else if (v.getIpType().equals(IpAddrType.IPV6.getValue())) {
// protectIpV6.add("");
// }
// }
// }
// });
//
// }
// } catch (Exception ignored) {
// }
}
/**
@ -417,34 +420,36 @@ public class PengXinAbilityImpl implements DisposeAbility {
*/
@Override
public boolean isCarryProtectIp(String ipAddr) {
boolean ret = false;
IPAddress addr = new IPAddressString(ipAddr).getAddress();
synchronized (this) {
if (addr.isIPv4()) {
ret = protectIpV4.stream().anyMatch(v -> Helper.ipInRange(v, ipAddr));
}
if (addr.isIPv6()) {
ret = protectIpV6.stream().anyMatch(v -> Helper.ipInRange(v, ipAddr));
}
}
if (!ret) {
// 更新设备防护IP
getDisposeDeviceProtectObject();
synchronized (this) {
if (addr.isIPv4()) {
ret = protectIpV4.stream().anyMatch(v -> Helper.ipInRange(v, ipAddr));
}
if (addr.isIPv6()) {
ret = protectIpV6.stream().anyMatch(v -> Helper.ipInRange(v, ipAddr));
}
}
}
return ret;
// 集团一键处置线上环境默认支持所有IP地址
return true;
// boolean ret = false;
// IPAddress addr = new IPAddressString(ipAddr).getAddress();
// synchronized (this) {
// if (addr.isIPv4()) {
// ret = protectIpV4.stream().anyMatch(v -> Helper.ipInRange(v, ipAddr));
// }
//
// if (addr.isIPv6()) {
// ret = protectIpV6.stream().anyMatch(v -> Helper.ipInRange(v, ipAddr));
// }
// }
//
// if (!ret) {
// // 更新设备防护IP
// getDisposeDeviceProtectObject();
//
// synchronized (this) {
// if (addr.isIPv4()) {
// ret = protectIpV4.stream().anyMatch(v -> Helper.ipInRange(v, ipAddr));
// }
//
// if (addr.isIPv6()) {
// ret = protectIpV6.stream().anyMatch(v -> Helper.ipInRange(v, ipAddr));
// }
// }
// }
//
// return ret;
}
/**
@ -533,8 +538,9 @@ public class PengXinAbilityImpl implements DisposeAbility {
public void periodTaskRuntime() {
log.debug("++++PengXin Period Task Running");
// 集团一键处置线上环境不再定时获取设备能力信息
// 更新防护对象
getDisposeDeviceProtectObject();
//getDisposeDeviceProtectObject();
// 更新心跳状态
if (timerCnt++ % DisposeConfigValue.HEART_PERIOD_OF_SECOND == 0) {