REM:
1. 增加处置能力设备硬件信息获取功能
2. 增加处置能力设备硬件系统启动初始化
This commit is contained in:
HuangXin 2020-08-11 16:23:04 +08:00
parent 8c44bb712c
commit ef6c0c52bf
13 changed files with 227 additions and 26 deletions

View File

@ -5,6 +5,7 @@ import com.dispose.common.DisposeCapacityType;
import com.dispose.common.ErrorCode; import com.dispose.common.ErrorCode;
import com.dispose.common.NetflowDirection; import com.dispose.common.NetflowDirection;
import com.dispose.pojo.po.MulReturnType; import com.dispose.pojo.po.MulReturnType;
import com.dispose.pojo.vo.DeviceFirewareInfo;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -54,6 +55,13 @@ public interface DisposeAbility {
@Nullable DDoSAttackType[] attackType, @Nullable DDoSAttackType[] attackType,
@Nullable Long taskId); @Nullable Long taskId);
/**
* Gets ability device fireware.
*
* @return the ability device fireware
*/
MulReturnType<ErrorCode, DeviceFirewareInfo> getAbilityDeviceFireware();
/** /**
* Gets device link status. * Gets device link status.

View File

@ -8,6 +8,7 @@ import com.dispose.common.DpTechConfigValue;
import com.dispose.common.ErrorCode; import com.dispose.common.ErrorCode;
import com.dispose.common.NetflowDirection; import com.dispose.common.NetflowDirection;
import com.dispose.pojo.po.MulReturnType; import com.dispose.pojo.po.MulReturnType;
import com.dispose.pojo.vo.DeviceFirewareInfo;
import com.dptech.dispose.AbnormalFlowCleaningServicePortType; import com.dptech.dispose.AbnormalFlowCleaningServicePortType;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.cxf.endpoint.Client; import org.apache.cxf.endpoint.Client;
@ -210,4 +211,26 @@ public class DpTechAbilityImpl implements DisposeAbility {
return false; return false;
} }
/**
* Gets ability device fireware.
*
* @return the ability device fireware
*/
@Override
public MulReturnType<ErrorCode, DeviceFirewareInfo> getAbilityDeviceFireware() {
return new MulReturnType<>(ErrorCode.ERR_OK,
DeviceFirewareInfo.builder()
.vendor("DpTech")
.model("UMC")
.firmware("Unknown")
.os("Windows Server")
.kernel("Windows")
.arch("x86_64")
.version("5.7.31")
.memory(-1)
.freeMemory(-1)
.cpuUsed(-1)
.build());
}
} }

View File

@ -6,6 +6,7 @@ import com.dispose.common.DisposeCapacityType;
import com.dispose.common.ErrorCode; import com.dispose.common.ErrorCode;
import com.dispose.common.NetflowDirection; import com.dispose.common.NetflowDirection;
import com.dispose.pojo.po.MulReturnType; import com.dispose.pojo.po.MulReturnType;
import com.dispose.pojo.vo.DeviceFirewareInfo;
import com.haohan.dispose.common.HaoHanStartCleanResp; import com.haohan.dispose.common.HaoHanStartCleanResp;
import com.haohan.dispose.common.HaoHanStopCleanResp; import com.haohan.dispose.common.HaoHanStopCleanResp;
import com.haohan.dispose.protocol.RestfulInterface; import com.haohan.dispose.protocol.RestfulInterface;
@ -130,4 +131,26 @@ public class HaoHanAbilityImpl implements DisposeAbility {
// 获取任务信息接口调用成功认为设备心跳正常 // 获取任务信息接口调用成功认为设备心跳正常
return (restfulInterface.getCleanTaskStatus(this.urlRootPath, -1) != null); return (restfulInterface.getCleanTaskStatus(this.urlRootPath, -1) != null);
} }
/**
* Gets ability device fireware.
*
* @return the ability device fireware
*/
@Override
public MulReturnType<ErrorCode, DeviceFirewareInfo> getAbilityDeviceFireware() {
return new MulReturnType<>(ErrorCode.ERR_OK,
DeviceFirewareInfo.builder()
.vendor("HaoHan")
.model("Unknown")
.firmware("Unknown")
.os("Linux Server")
.kernel("Linux")
.arch("x86_64")
.version("Unknown")
.memory(-1)
.freeMemory(-1)
.cpuUsed(-1)
.build());
}
} }

View File

@ -6,6 +6,7 @@ import com.dispose.common.DisposeCapacityType;
import com.dispose.common.ErrorCode; import com.dispose.common.ErrorCode;
import com.dispose.common.NetflowDirection; import com.dispose.common.NetflowDirection;
import com.dispose.pojo.po.MulReturnType; import com.dispose.pojo.po.MulReturnType;
import com.dispose.pojo.vo.DeviceFirewareInfo;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -63,6 +64,28 @@ public class VirtualAbilityImpl implements DisposeAbility {
return new MulReturnType<>(ErrorCode.ERR_OK, null); return new MulReturnType<>(ErrorCode.ERR_OK, null);
} }
/**
* Gets ability device fireware.
*
* @return the ability device fireware
*/
@Override
public MulReturnType<ErrorCode, DeviceFirewareInfo> getAbilityDeviceFireware() {
return new MulReturnType<>(ErrorCode.ERR_OK,
DeviceFirewareInfo.builder()
.vendor("Virtual")
.model("Dispose_1000")
.firmware("Unknown")
.os("Unknown")
.kernel("Linux")
.arch("x86_64")
.version("Virtual_Device_2.0")
.memory(-1)
.freeMemory(-1)
.cpuUsed(-1)
.build());
}
/** /**
* Gets device link status. * Gets device link status.
* *

View File

@ -143,7 +143,7 @@ public enum DDoSAttackType implements BaseEnum {
*/ */
SENTINEL_AMPLIFICATION ( 33, "SENTINEL_AMPLIFICATION"), SENTINEL_AMPLIFICATION ( 33, "SENTINEL_AMPLIFICATION"),
/** /**
* The Fraggle. * The Fraggle flood.
*/ */
FRAGGLE_FLOOD ( 34, "FRAGGLE_FLOOD"), FRAGGLE_FLOOD ( 34, "FRAGGLE_FLOOD"),
/** /**
@ -177,7 +177,13 @@ public enum DDoSAttackType implements BaseEnum {
/** /**
* The Igmp flood. * The Igmp flood.
*/ */
IGMP_FLOOD ( 42, "IGMP_FLOOD"); IGMP_FLOOD ( 42, "IGMP_FLOOD"),
/**
* All attacks d do s attack type.
*/
ALL_ATTACKS (-1, "ALL_ATTACKS"),
;
/** /**

View File

@ -1,6 +1,7 @@
package com.dispose.common; package com.dispose.common;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -163,8 +164,12 @@ public enum DpTechAttackType implements BaseEnum {
attackList.add(ICMP_FLOOD); attackList.add(ICMP_FLOOD);
break; break;
case ALL_ATTACKS:
attackList.addAll(Arrays.asList(DpTechAttackType.values()));
break;
default: default:
return attackList.stream(); break;
} }
return attackList.stream(); return attackList.stream();

View File

@ -54,5 +54,5 @@ public interface DisposeDeviceManager {
* *
* @return the all dispose devices * @return the all dispose devices
*/ */
List<DisposeDevice> getAllDisposeDevices(); List<DisposeDevice> getAllNormalDisposeDevices();
} }

View File

@ -19,6 +19,7 @@ import java.lang.reflect.Field;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* The type Dispose device manager. * The type Dispose device manager.
@ -240,13 +241,9 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager {
* @return the all dispose devices * @return the all dispose devices
*/ */
@Override @Override
public List<DisposeDevice> getAllDisposeDevices() { public List<DisposeDevice> getAllNormalDisposeDevices() {
List<DisposeDevice> devList = disposeDeviceMapper.selectAll(); return disposeDeviceMapper.selectAll().stream()
.filter(v -> v.getStatus() == ObjectStatus.NORMAL)
if (devList == null) { .collect(Collectors.toList());
devList = new ArrayList<>();
}
return devList;
} }
} }

View File

@ -2,6 +2,7 @@ package com.dispose.pojo.po;
import com.dispose.ability.DisposeAbility; import com.dispose.ability.DisposeAbility;
import com.dispose.pojo.entity.DisposeDevice; import com.dispose.pojo.entity.DisposeDevice;
import com.dispose.pojo.vo.DeviceFirewareInfo;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;
@ -27,6 +28,11 @@ public class AbilityInfo {
*/ */
private DisposeDevice dev; private DisposeDevice dev;
/**
* The Fireware info.
*/
private DeviceFirewareInfo firewareInfo;
/** /**
* The Link status. * The Link status.
*/ */

View File

@ -0,0 +1,58 @@
package com.dispose.pojo.vo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* The type Device fireware info.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class DeviceFirewareInfo {
/**
* The Vendor.
*/
private String vendor;
/**
* The Model.
*/
private String model;
/**
* The Firmware.
*/
private String firmware;
/**
* The Os.
*/
private String os;
/**
* The Kernel.
*/
private String kernel;
/**
* The Arch.
*/
private String arch;
/**
* The Version.
*/
private String version;
/**
* The Memory.
*/
private int memory;
/**
* The Free memory.
*/
private int freeMemory;
/**
* The Cpu used.
*/
private int cpuUsed;
}

View File

@ -43,7 +43,7 @@ public class DisposeAbilityRouterServiceImpl implements DisposeAbilityRouterServ
*/ */
@PostConstruct @PostConstruct
private void initDisposeAbility() { private void initDisposeAbility() {
List<DisposeDevice> devList = disposeDeviceManager.getAllDisposeDevices(); List<DisposeDevice> devList = disposeDeviceManager.getAllNormalDisposeDevices();
devList.forEach(this::addDisposeAbilityDevice); devList.forEach(this::addDisposeAbilityDevice);
} }
@ -56,7 +56,7 @@ public class DisposeAbilityRouterServiceImpl implements DisposeAbilityRouterServ
*/ */
@Override @Override
public AbilityInfo getAbilityDevice(String ipAddr, String ipPort) { public AbilityInfo getAbilityDevice(String ipAddr, String ipPort) {
return disposeAbilityMap.get(getAbilityMapKey(ipAddr, ipPort)); return disposeAbilityMap.get(getAbilityDeviceHashKey(ipAddr, ipPort));
} }
/** /**
@ -80,7 +80,7 @@ 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 = getAbilityMapKey(dev.getIpAddr(), dev.getIpPort()); String addr = getAbilityDeviceHashKey(dev.getIpAddr(), dev.getIpPort());
String url = httpType + addr + "/" + dev.getUrlPath(); String url = httpType + addr + "/" + dev.getUrlPath();
switch (dev.getDeviceType()) { switch (dev.getDeviceType()) {
@ -112,13 +112,13 @@ public class DisposeAbilityRouterServiceImpl implements DisposeAbilityRouterServ
} }
/** /**
* Gets ability map 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
* @return the ability map key * @return the ability device hash key
*/ */
private String getAbilityMapKey(String ipAddr, String ipPort) { private String getAbilityDeviceHashKey(String ipAddr, String ipPort) {
return (ipPort == null || ipPort.length() == 0) ? ipAddr : (ipAddr + ":" + ipPort); return (ipPort == null || ipPort.length() == 0) ? ipAddr : (ipAddr + ":" + ipPort);
} }
} }

View File

@ -3,11 +3,16 @@ package com.dispose.setup;
import com.dispose.common.AuthConfigValue; import com.dispose.common.AuthConfigValue;
import com.dispose.common.DisposeConfigValue; import com.dispose.common.DisposeConfigValue;
import com.dispose.common.DpTechConfigValue; import com.dispose.common.DpTechConfigValue;
import com.dispose.common.ErrorCode;
import com.dispose.config.AuthConfigure; import com.dispose.config.AuthConfigure;
import com.dispose.config.DisposeConfigure; import com.dispose.config.DisposeConfigure;
import com.dispose.config.DpTechConfigure; import com.dispose.config.DpTechConfigure;
import com.dispose.pojo.po.MulReturnType;
import com.dispose.pojo.vo.DeviceFirewareInfo;
import com.dispose.service.DisposeAbilityRouterService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner; import org.springframework.boot.CommandLineRunner;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -38,6 +43,12 @@ public class SystemInitial implements CommandLineRunner {
@Resource @Resource
DpTechConfigure dpTechConfigure; DpTechConfigure dpTechConfigure;
/**
* The Dispose ability router service.
*/
@Resource
private DisposeAbilityRouterService disposeAbilityRouterService;
/** /**
* Load configure. * Load configure.
*/ */
@ -83,6 +94,19 @@ public class SystemInitial implements CommandLineRunner {
} }
} }
@Async("bizExecutor")
public void setupAbilityDevice() {
disposeAbilityRouterService.getAllAbilityDevices().forEach(v -> {
v.setLinkStatus(v.getDb().getDeviceLinkStatus());
MulReturnType<ErrorCode, DeviceFirewareInfo> ret = v.getDb().getAbilityDeviceFireware();
if (ret.getFirstParam() == ErrorCode.ERR_OK) {
v.setFirewareInfo(ret.getSecondParam());
}
});
}
/** /**
* Run. * Run.
* *
@ -92,5 +116,8 @@ public class SystemInitial implements CommandLineRunner {
public void run(String... args) { public void run(String... args) {
// 系统初始化入口 // 系统初始化入口
loadConfigure(); loadConfigure();
// 初始化处置能力设备
setupAbilityDevice();
} }
} }

View File

@ -1,5 +1,8 @@
package com.dispose.task; package com.dispose.task;
import com.dispose.common.ErrorCode;
import com.dispose.pojo.po.MulReturnType;
import com.dispose.pojo.vo.DeviceFirewareInfo;
import com.dispose.service.DisposeAbilityRouterService; import com.dispose.service.DisposeAbilityRouterService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
@ -23,15 +26,37 @@ public class DeviceManagerTask {
private DisposeAbilityRouterService disposeAbilityRouterService; private DisposeAbilityRouterService disposeAbilityRouterService;
/** /**
* Thread pool task. * Update device link status task.
*/ */
@Async("bizExecutor") @Async("bizExecutor")
@Scheduled(cron = "0/5 * * * * ?") @Scheduled(cron = "0/30 * * * * ?")
public void threadPoolTask() { public void updateDeviceLinkStatusTask() {
disposeAbilityRouterService.getAllAbilityDevices().forEach(v -> log.info("{}{} get link status {}", disposeAbilityRouterService.getAllAbilityDevices().forEach(v -> {
v.getDev().getIpAddr(), v.setLinkStatus(v.getDb().getDeviceLinkStatus());
((v.getDev().getIpPort() == null || v.getDev().getIpPort().length() == 0) ? log.debug("{}{} get link status {}", v.getDev().getIpAddr(),
"" : ":" + v.getDev().getIpPort()), ((v.getDev().getIpPort() == null || v.getDev().getIpPort().length() == 0) ? "" :
v.getDb().getDeviceLinkStatus())); ":" + v.getDev().getIpPort()),
v.isLinkStatus());
});
}
/**
* Update device fireware task.
*/
@Async("bizExecutor")
@Scheduled(cron = "0 */1 * * * ?")
public void updateDeviceFirewareTask() {
disposeAbilityRouterService.getAllAbilityDevices().forEach(v -> {
MulReturnType<ErrorCode, DeviceFirewareInfo> ret = v.getDb().getAbilityDeviceFireware();
if (ret.getFirstParam() == ErrorCode.ERR_OK) {
v.setFirewareInfo(ret.getSecondParam());
}
log.debug("{}{} get fireware status {}", v.getDev().getIpAddr(),
((v.getDev().getIpPort() == null || v.getDev().getIpPort().length() == 0) ? "" :
":" + v.getDev().getIpPort()),
ret.getFirstParam());
});
} }
} }