REM:
1. 增加浩瀚设备处置接口实现
2. 增加浩瀚设备处置设备实现
This commit is contained in:
HuangXin 2020-06-22 15:17:16 +08:00
parent 51f7b0324a
commit 3231008163
5 changed files with 219 additions and 10 deletions

View File

@ -63,6 +63,11 @@ public enum IPAddrType {
*/ */
public static boolean ipInRange(String rangeIp, String ipAddr) throws AddressStringException { public static boolean ipInRange(String rangeIp, String ipAddr) throws AddressStringException {
final int numIp = 2; final int numIp = 2;
if (rangeIp.equals(ipAddr)) {
return true;
}
String[] ipList = rangeIp.split("-"); String[] ipList = rangeIp.split("-");
if (ipList.length != numIp) { if (ipList.length != numIp) {

View File

@ -4,6 +4,7 @@ import com.dispose.common.DisposeDeviceType;
import com.dispose.common.GlobalVar; import com.dispose.common.GlobalVar;
import com.dispose.common.IPAddrType; import com.dispose.common.IPAddrType;
import com.dispose.dispose.impl.DpTechImpl; import com.dispose.dispose.impl.DpTechImpl;
import com.dispose.dispose.impl.HaoHanImpl;
import com.dispose.dispose.impl.VirtualDeviceImpl; import com.dispose.dispose.impl.VirtualDeviceImpl;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -36,15 +37,20 @@ public class DeviceRouter {
if (DEVICE_CACHE_MAP.containsKey(mapKey)) { if (DEVICE_CACHE_MAP.containsKey(mapKey)) {
return DEVICE_CACHE_MAP.get(mapKey); return DEVICE_CACHE_MAP.get(mapKey);
} else { } else {
DisposeEntryManager dev = null;
// 第一次访问创建新对象并缓存 // 第一次访问创建新对象并缓存
if (GlobalVar.USED_VIRTUAL_DISPOSE_MODE) { if (GlobalVar.USED_VIRTUAL_DISPOSE_MODE) {
// 虚拟设备供调试业务使用 // 虚拟设备供调试业务使用
DisposeEntryManager dev = new VirtualDeviceImpl(ipAddr); dev = new VirtualDeviceImpl(ipAddr);
DEVICE_CACHE_MAP.put(mapKey, dev);
return dev;
} else if (devType == DisposeDeviceType.DPTECH_UMC.getCode()) { } else if (devType == DisposeDeviceType.DPTECH_UMC.getCode()) {
// 迪普设备 // 迪普设备
DisposeEntryManager dev = new DpTechImpl(ipAddr); dev = new DpTechImpl(ipAddr);
} else if (devType == DisposeDeviceType.HAOHAN_PLATFORM.getCode()) {
// 浩瀚设备
dev = new HaoHanImpl(ipAddr);
}
if (dev != null) {
DEVICE_CACHE_MAP.put(mapKey, dev); DEVICE_CACHE_MAP.put(mapKey, dev);
return dev; return dev;
} }

View File

@ -90,9 +90,4 @@ public interface DisposeEntryManager {
* @return the device info * @return the device info
*/ */
DeviceInfo getDeviceInfo(); DeviceInfo getDeviceInfo();
//public NtcRequestResultInfo stopAbnormalTask(String abnormalIp, int attackType, int direction);
//public NtcRequestResultInfo startAbnormalTask(String abnormalIp, int attackType, int direction);
} }

View File

@ -0,0 +1,178 @@
package com.dispose.dispose.impl;
import com.dispose.common.DeviceCapacity;
import com.dispose.common.ErrorCode;
import com.dispose.common.IPAddrType;
import com.dispose.dispose.DisposeEntryManager;
import com.dispose.dispose.po.DeviceInfo;
import com.dispose.pojo.po.DisposeDeviceCapacity;
import lombok.extern.slf4j.Slf4j;
import java.util.ArrayList;
import java.util.List;
/**
* The type Hao han.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
@Slf4j
public class HaoHanImpl implements DisposeEntryManager {
/**
* Instantiates a new Hao han.
*
* @param ipAddr the ip addr
*/
public HaoHanImpl(String ipAddr) {
}
/**
* Instantiates a new Hao han.
*
* @param ipAddr the ip addr
* @param type the type
*/
public HaoHanImpl(String ipAddr, IPAddrType type) {
}
/**
* Run dispose error code.
*
* @param ip the ip
* @param type the type
* @return the error code
*/
@Override
public ErrorCode runDispose(String ip, DeviceCapacity type) {
return ErrorCode.ERR_OK;
}
/**
* Stop dispose error code.
*
* @param ipAddr the ip addr
* @param type the type
* @return the error code
*/
@Override
public ErrorCode stopDispose(String ipAddr, DeviceCapacity type) {
return ErrorCode.ERR_OK;
}
/**
* Gets version.
*
* @return the version
*/
@Override
public String getVersion() {
return "Not Support";
}
/**
* Gets device info.
*
* @return the device info
*/
@Override
public DeviceInfo getDeviceInfo() {
// 当前设备接口不支持返回模拟数据
return DeviceInfo.builder()
.vendor("HaoHan")
.model("Unknown")
.firmware("Unknown")
.os("Linux Server")
.kernel("Linux")
.arch("x86_64")
.memory(-1)
.freeMemory(-1)
.cpuUsed(-1)
.build();
}
/**
* Gets device capacity.
*
* @return the device capacity
*/
@Override
public List<DisposeDeviceCapacity> getDeviceCapacity() {
List<DisposeDeviceCapacity> capList = new ArrayList<>();
// 保存清洗能力信息
capList.add(DisposeDeviceCapacity.builder()
// 清洗能力
.capacity(DeviceCapacity.CLEANUP.getCode())
.tolFlowCapacity(0)
// IPv4范围
.protectIpV4(new String[] {"0.0.0.0-255.255.255.255"})
// IPv6范围
.protectIpV6(new String[] {""})
.build());
return capList;
}
/**
* Gets device link status.
*
* @return the device link status
*/
@Override
public boolean getDeviceLinkStatus() {
try {
// 获取防护对象接口调用成功认为设备心跳正常
getAllProtectionObject();
return true;
} catch (Exception ex) {
log.error(ex.getMessage());
}
return false;
}
/**
* Gets all detection object.
*
* @param <T> the type parameter
* @return the all detection object
*/
@Override
public <T> T getAllDetectionObject() {
return null;
}
/**
* Gets all protection object.
*
* @param <T> the type parameter
* @return the all protection object
*/
@Override
public <T> T getAllProtectionObject() {
return null;
}
/**
* Gets protect devices.
*
* @return the protect devices
*/
@Override
public String getProtectDevices() {
return null;
}
/**
* Gets detection devices.
*
* @return the detection devices
*/
@Override
public String getDetectionDevices() {
return null;
}
}

View File

@ -1,16 +1,28 @@
package com.dispose.test.debug; package com.dispose.test.debug;
import com.dispose.common.IPAddrType;
import com.dispose.pojo.vo.common.IDArrayReq; import com.dispose.pojo.vo.common.IDArrayReq;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import inet.ipaddr.AddressStringException;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
/**
* The type Demo.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
@Slf4j @Slf4j
public class demo { public class demo {
/**
* A 1 idid array req test.
*
* @throws JsonProcessingException the json processing exception
*/
@Test @Test
public void a1_IDIDArrayReqTest() throws JsonProcessingException { public void a1_IDIDArrayReqTest() throws JsonProcessingException {
String json = "{\"id\":[\"1\", \"123\", \"1234\", \"1234\"]}"; String json = "{\"id\":[\"1\", \"123\", \"1234\", \"1234\"]}";
@ -28,6 +40,19 @@ public class demo {
id = new ObjectMapper().readValue(json, IDArrayReq.class); id = new ObjectMapper().readValue(json, IDArrayReq.class);
Assert.assertEquals(id.getId().length, 3); Assert.assertEquals(id.getId().length, 3);
id = new ObjectMapper().readValue(json4, IDArrayReq.class); //id = new ObjectMapper().readValue(json4, IDArrayReq.class);
}
/**
* A 2 ip range test.
*
* @throws AddressStringException the address string exception
*/
@Test
public void a2_ipRangeTest() throws AddressStringException {
Assert.assertTrue(IPAddrType.ipInRange("192.168.0.1-192.168.0.100", "192.168.0.30"));
Assert.assertTrue(IPAddrType.ipInRange("192.168.0.30", "192.168.0.30"));
Assert.assertTrue(IPAddrType.ipInRange("192.168.0.40-192.168.0.40", "192.168.0.40"));
Assert.assertTrue(IPAddrType.ipInRange("0.0.0.0-255.255.255.255", "192.168.0.30"));
} }
} }