REM:
1. 修正迪普防护对象获取缓存功能
This commit is contained in:
HuangXin 2021-01-14 10:18:44 +08:00
parent 7bc5f2ef1a
commit 1f1abbfe4b
1 changed files with 43 additions and 15 deletions

View File

@ -1,5 +1,6 @@
package com.dispose.ability.impl;
import com.dispose.common.ConstValue;
import com.dispose.common.DisposeConfigValue;
import com.dispose.common.DpTechConfigValue;
import com.dispose.common.IpAddrType;
@ -13,6 +14,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.regex.Pattern;
/**
* The type Dp tech bypass ability.
@ -79,7 +81,7 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl {
@Override
public void getDisposeDeviceProtectObject() {
try {
log.info("++++Begging DPTech Get All Protection Objects");
log.debug("++++Begging DPTech Get All Protection Objects");
ArrayOfProtectionObjectDataForService ret = getCleanTypePort().getAllProtectionObjectFromUMC();
if (ret == null) {
@ -103,32 +105,58 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl {
log.error("!!!!Remove Protection Object {} Error: {}", objName, rsp.getResultInfo().getValue());
}
} else {
// 缓存所有防护对象
DpProtectObject obj = DpProtectObject.builder()
DpProtectObject obj;
if (!umcObject.contains(objName)) {
// 获取防护对象
obj = umcObject.get(objName);
} else {
obj = DpProtectObject.builder()
.cleanupDevices(k.getCleaningDevices().getValue())
.protectName(objName)
.detectionDevices(k.getDetectionDevices().getValue())
.ipType(k.getIpType() == 0 ? IpAddrType.IPV4 : IpAddrType.IPV6)
.ipSegment(new Hashtable<>())
.build();
// 添加到缓存
umcObject.put(objName, obj);
}
String ipSeg = k.getIpSegment().getValue();
log.debug("DpTech response type: {}, value: {}", k.getIpType(), ipSeg);
Hashtable<String, String> tmpTable = new Hashtable<>();
// 分割IP段
Arrays.stream(StringUtils.deleteWhitespace(ipSeg).split(",")).forEach(v -> {
String ipValue = v.replaceAll("\\d+_", "");
String key = v.replace(ipValue, "").replace("_", "");
if (Pattern.matches(ConstValue.ipAddrSegmentReg(), ipValue)) {
// 添加到缓存
obj.getIpSegment().put(key, ipValue);
tmpTable.put(key, ipValue);
} else {
// 删除异常段
NtcRequestResultInfo rsp = getCleanTypePort().deleteProtectionObjectIPRangeForUMC(objName
, key);
if (rsp.getResultRetVal() == 0) {
log.warn("!!!!Remove Exception Protection IpSegment {}, {} Succeed", objName, v);
} else {
log.warn("!!!!Remove Exception Protection IpSegment {}, {} Error: {}", objName, v,
rsp.getResultInfo().getValue());
}
}
});
// 添加到缓存
umcObject.put(objName, obj);
// 判断是否需要更新IP段信息
if(!obj.getIpSegment().equals(tmpTable)) {
obj.setIpSegment(tmpTable);
}
}
});
log.info("----Finish DPTech Get All Protection Objects: {}", ret.getProtectionObjectDataForService()
.size());
log.debug("----Finish DPTech Get All Protection Objects Succeed");
} catch (Exception ex) {
log.error("----Exception DPTech Get All Protection Objects: {}", ex.getMessage());
}