parent
eeab55f940
commit
6cbc49ed48
|
@ -16,7 +16,7 @@ import javax.annotation.Nullable;
|
||||||
public interface DisposeAbility {
|
public interface DisposeAbility {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Init device env error code.
|
* Init device env.
|
||||||
*
|
*
|
||||||
* @param urlPath the url path
|
* @param urlPath the url path
|
||||||
* @param username the username
|
* @param username the username
|
||||||
|
@ -46,11 +46,13 @@ public interface DisposeAbility {
|
||||||
* @param capType the cap type
|
* @param capType the cap type
|
||||||
* @param nfDirection the nf direction
|
* @param nfDirection the nf direction
|
||||||
* @param attackType the attack type
|
* @param attackType the attack type
|
||||||
|
* @param taskId the task id
|
||||||
* @return the mul return type
|
* @return the mul return type
|
||||||
*/
|
*/
|
||||||
MulReturnType<ErrorCode, Long> stopDispose(String ip, DisposeCapacityType capType,
|
MulReturnType<ErrorCode, Long> stopDispose(String ip, DisposeCapacityType capType,
|
||||||
@Nullable NetflowDirection[] nfDirection,
|
@Nullable NetflowDirection[] nfDirection,
|
||||||
@Nullable DDoSAttackType[] attackType);
|
@Nullable DDoSAttackType[] attackType,
|
||||||
|
@Nullable Long taskId);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -45,7 +45,7 @@ public class DpTechAbilityImpl implements DisposeAbility {
|
||||||
private AbnormalFlowCleaningServicePortType cleanTypePort;
|
private AbnormalFlowCleaningServicePortType cleanTypePort;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Init device env error code.
|
* Init device env.
|
||||||
*
|
*
|
||||||
* @param urlPath the url path
|
* @param urlPath the url path
|
||||||
* @param username the username
|
* @param username the username
|
||||||
|
@ -147,12 +147,14 @@ public class DpTechAbilityImpl implements DisposeAbility {
|
||||||
* @param capType the cap type
|
* @param capType the cap type
|
||||||
* @param nfDirection the nf direction
|
* @param nfDirection the nf direction
|
||||||
* @param attackType the attack type
|
* @param attackType the attack type
|
||||||
|
* @param taskId the task id
|
||||||
* @return the mul return type
|
* @return the mul return type
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public MulReturnType<ErrorCode, Long> stopDispose(String ipAddr, DisposeCapacityType capType,
|
public MulReturnType<ErrorCode, Long> stopDispose(String ipAddr, DisposeCapacityType capType,
|
||||||
@Nullable NetflowDirection[] nfDirection,
|
@Nullable NetflowDirection[] nfDirection,
|
||||||
@Nullable DDoSAttackType[] attackType) {
|
@Nullable DDoSAttackType[] attackType,
|
||||||
|
@Nullable Long taskId) {
|
||||||
ErrorCode err = ErrorCode.ERR_OK;
|
ErrorCode err = ErrorCode.ERR_OK;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -192,6 +194,11 @@ public class DpTechAbilityImpl implements DisposeAbility {
|
||||||
return new MulReturnType<>(err, null);
|
return new MulReturnType<>(err, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets device link status.
|
||||||
|
*
|
||||||
|
* @return the device link status
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean getDeviceLinkStatus() {
|
public boolean getDeviceLinkStatus() {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -0,0 +1,133 @@
|
||||||
|
package com.dispose.ability.impl;
|
||||||
|
|
||||||
|
import com.dispose.ability.DisposeAbility;
|
||||||
|
import com.dispose.common.DDoSAttackType;
|
||||||
|
import com.dispose.common.DisposeCapacityType;
|
||||||
|
import com.dispose.common.ErrorCode;
|
||||||
|
import com.dispose.common.NetflowDirection;
|
||||||
|
import com.dispose.pojo.po.MulReturnType;
|
||||||
|
import com.haohan.dispose.common.HaoHanStartCleanResp;
|
||||||
|
import com.haohan.dispose.common.HaoHanStopCleanResp;
|
||||||
|
import com.haohan.dispose.protocol.RestfulInterface;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Hao han ability.
|
||||||
|
*
|
||||||
|
* @author <huangxin@cmhi.chinamoblie.com>
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class HaoHanAbilityImpl implements DisposeAbility {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The constant DISPOSE_PLATFORM_NAME.
|
||||||
|
*/
|
||||||
|
private static final String DISPOSE_PLATFORM_NAME = "HANGYAN_CMCC";
|
||||||
|
/**
|
||||||
|
* The Restful interface.
|
||||||
|
*/
|
||||||
|
private final RestfulInterface restfulInterface = new RestfulInterface();
|
||||||
|
/**
|
||||||
|
* The Url root path.
|
||||||
|
*/
|
||||||
|
private String urlRootPath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init device env.
|
||||||
|
*
|
||||||
|
* @param urlPath the url path
|
||||||
|
* @param username the username
|
||||||
|
* @param password the password
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void initDeviceEnv(String urlPath, String username, String password) {
|
||||||
|
this.urlRootPath = urlPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run dispose mul return type.
|
||||||
|
*
|
||||||
|
* @param ip the ip
|
||||||
|
* @param capType the cap type
|
||||||
|
* @param nfDirection the nf direction
|
||||||
|
* @param attackType the attack type
|
||||||
|
* @param duration the duration
|
||||||
|
* @return the mul return type
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public MulReturnType<ErrorCode, Long> runDispose(String ip, DisposeCapacityType capType,
|
||||||
|
@Nullable NetflowDirection[] nfDirection,
|
||||||
|
@Nullable DDoSAttackType[] attackType,
|
||||||
|
@Nullable Long duration) {
|
||||||
|
log.info("++++Begging Haohan Start Cleanup Task: {}", ip);
|
||||||
|
|
||||||
|
// 适配处置时间参数, -1为不限制处置时间
|
||||||
|
if (duration == null || duration < 0) {
|
||||||
|
duration = -1L;
|
||||||
|
}
|
||||||
|
|
||||||
|
HaoHanStartCleanResp resp = restfulInterface.startClean(this.urlRootPath, ip, duration.intValue(),
|
||||||
|
DISPOSE_PLATFORM_NAME);
|
||||||
|
|
||||||
|
if (resp == null) {
|
||||||
|
log.error("----Error Haohan start clean {} server return error", ip);
|
||||||
|
return new MulReturnType<>(ErrorCode.ERR_HAOHAN_ERROR, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resp.getState() != ErrorCode.ERR_OK.getCode()) {
|
||||||
|
log.error("----Error Haohan start clean {} return error: {}, {}", ip, resp.getState(), resp.getMsg());
|
||||||
|
return new MulReturnType<>(ErrorCode.ERR_HAOHAN_ERROR, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("----Finish Haohan Start Cleanup Task: {}", ip);
|
||||||
|
return new MulReturnType<>(ErrorCode.ERR_OK, (long) resp.getCleanTaskId());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop dispose mul return type.
|
||||||
|
*
|
||||||
|
* @param ip the ip
|
||||||
|
* @param capType the cap type
|
||||||
|
* @param nfDirection the nf direction
|
||||||
|
* @param attackType the attack type
|
||||||
|
* @param taskId the task id
|
||||||
|
* @return the mul return type
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public MulReturnType<ErrorCode, Long> stopDispose(String ip, DisposeCapacityType capType,
|
||||||
|
@Nullable NetflowDirection[] nfDirection,
|
||||||
|
@Nullable DDoSAttackType[] attackType,
|
||||||
|
@Nullable Long taskId) {
|
||||||
|
log.info("++++Begging Haohan Stop Cleanup Task: {}", taskId);
|
||||||
|
|
||||||
|
if (taskId == null) {
|
||||||
|
return new MulReturnType<>(ErrorCode.ERR_PARAMS, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
HaoHanStopCleanResp resp = restfulInterface.stopClean(this.urlRootPath, taskId.intValue(),
|
||||||
|
DISPOSE_PLATFORM_NAME);
|
||||||
|
|
||||||
|
if (resp == null) {
|
||||||
|
log.error("----Error Haohan stop task{} server return error", taskId);
|
||||||
|
return new MulReturnType<>(ErrorCode.ERR_HAOHAN_ERROR, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("----Finish Haohan Stop Cleanup Task: {}", taskId);
|
||||||
|
return new MulReturnType<>(ErrorCode.ERR_OK, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets device link status.
|
||||||
|
*
|
||||||
|
* @return the device link status
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean getDeviceLinkStatus() {
|
||||||
|
// 获取任务信息接口调用成功认为设备心跳正常
|
||||||
|
return (restfulInterface.getCleanTaskStatus(this.urlRootPath, -1) != null);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,75 @@
|
||||||
|
package com.dispose.ability.impl;
|
||||||
|
|
||||||
|
import com.dispose.ability.DisposeAbility;
|
||||||
|
import com.dispose.common.DDoSAttackType;
|
||||||
|
import com.dispose.common.DisposeCapacityType;
|
||||||
|
import com.dispose.common.ErrorCode;
|
||||||
|
import com.dispose.common.NetflowDirection;
|
||||||
|
import com.dispose.pojo.po.MulReturnType;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Virtual ability.
|
||||||
|
*
|
||||||
|
* @author <huangxin@cmhi.chinamoblie.com>
|
||||||
|
*/
|
||||||
|
public class VirtualAbilityImpl implements DisposeAbility {
|
||||||
|
/**
|
||||||
|
* Init device env.
|
||||||
|
*
|
||||||
|
* @param urlPath the url path
|
||||||
|
* @param username the username
|
||||||
|
* @param password the password
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void initDeviceEnv(String urlPath, String username, String password) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run dispose mul return type.
|
||||||
|
*
|
||||||
|
* @param ip the ip
|
||||||
|
* @param capType the cap type
|
||||||
|
* @param nfDirection the nf direction
|
||||||
|
* @param attackType the attack type
|
||||||
|
* @param duration the duration
|
||||||
|
* @return the mul return type
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public MulReturnType<ErrorCode, Long> runDispose(String ip, DisposeCapacityType capType,
|
||||||
|
@Nullable NetflowDirection[] nfDirection,
|
||||||
|
@Nullable DDoSAttackType[] attackType,
|
||||||
|
@Nullable Long duration) {
|
||||||
|
return new MulReturnType<>(ErrorCode.ERR_OK, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop dispose mul return type.
|
||||||
|
*
|
||||||
|
* @param ip the ip
|
||||||
|
* @param capType the cap type
|
||||||
|
* @param nfDirection the nf direction
|
||||||
|
* @param attackType the attack type
|
||||||
|
* @param taskId the task id
|
||||||
|
* @return the mul return type
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public MulReturnType<ErrorCode, Long> stopDispose(String ip, DisposeCapacityType capType,
|
||||||
|
@Nullable NetflowDirection[] nfDirection,
|
||||||
|
@Nullable DDoSAttackType[] attackType,
|
||||||
|
@Nullable Long taskId) {
|
||||||
|
return new MulReturnType<>(ErrorCode.ERR_OK, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets device link status.
|
||||||
|
*
|
||||||
|
* @return the device link status
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean getDeviceLinkStatus() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,5 +17,8 @@ public class DisposeConfigValue {
|
||||||
*/
|
*/
|
||||||
public static volatile long REQUEST_TIMEOUT_MS = 5 * 1000;
|
public static volatile long REQUEST_TIMEOUT_MS = 5 * 1000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The constant USED_PRIVACY_PROTECT.
|
||||||
|
*/
|
||||||
public static volatile boolean USED_PRIVACY_PROTECT = false;
|
public static volatile boolean USED_PRIVACY_PROTECT = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import com.dispose.mapper.DisposeCapacityMapper;
|
||||||
import com.dispose.mapper.DisposeDeviceMapper;
|
import com.dispose.mapper.DisposeDeviceMapper;
|
||||||
import com.dispose.pojo.entity.DisposeDevice;
|
import com.dispose.pojo.entity.DisposeDevice;
|
||||||
import com.dispose.pojo.po.MulReturnType;
|
import com.dispose.pojo.po.MulReturnType;
|
||||||
|
import com.dispose.service.DisposeAbilityRouterService;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
@ -18,7 +19,6 @@ 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.concurrent.ConcurrentHashMap;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type Dispose device manager.
|
* The type Dispose device manager.
|
||||||
|
@ -28,11 +28,6 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||||
@Component
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class DisposeDeviceManagerImpl implements DisposeDeviceManager {
|
public class DisposeDeviceManagerImpl implements DisposeDeviceManager {
|
||||||
|
|
||||||
/**
|
|
||||||
* The Dispose device.
|
|
||||||
*/
|
|
||||||
private final ConcurrentHashMap<String, DisposeDevice> disposeDevice = new ConcurrentHashMap<>();
|
|
||||||
/**
|
/**
|
||||||
* The Dispose capacity mapper.
|
* The Dispose capacity mapper.
|
||||||
*/
|
*/
|
||||||
|
@ -44,6 +39,12 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager {
|
||||||
@Resource
|
@Resource
|
||||||
private DisposeDeviceMapper disposeDeviceMapper;
|
private DisposeDeviceMapper disposeDeviceMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Dispose ability router service.
|
||||||
|
*/
|
||||||
|
@Resource
|
||||||
|
private DisposeAbilityRouterService disposeAbilityRouterService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add dispose device mul return type.
|
* Add dispose device mul return type.
|
||||||
*
|
*
|
||||||
|
@ -71,11 +72,14 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager {
|
||||||
return new MulReturnType<>(ErrorCode.ERR_DATABASE, -1L);
|
return new MulReturnType<>(ErrorCode.ERR_DATABASE, -1L);
|
||||||
} else {
|
} else {
|
||||||
// 添加设备到缓存中,方便调用时查找
|
// 添加设备到缓存中,方便调用时查找
|
||||||
String devKey = dev.getIpAddr() + ":" + dev.getIpPort();
|
ErrorCode err = disposeAbilityRouterService.addDisposeAbilityDevice(dev);
|
||||||
disposeDevice.put(devKey, dev);
|
|
||||||
// 添加设备能力信息
|
// 添加设备能力信息
|
||||||
disposeCapacityMapper.addNewDisposeCapacity(dev.getDevCapacity());
|
if (err == ErrorCode.ERR_OK) {
|
||||||
return new MulReturnType<>(ErrorCode.ERR_OK, dev.getId());
|
disposeCapacityMapper.addNewDisposeCapacity(dev.getDevCapacity());
|
||||||
|
}
|
||||||
|
|
||||||
|
return new MulReturnType<>(err, dev.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,7 +159,7 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager {
|
||||||
disposeCapacityMapper.delDeviceDisposeCapacity(tDev.getId());
|
disposeCapacityMapper.delDeviceDisposeCapacity(tDev.getId());
|
||||||
|
|
||||||
// 新增能力信息完成更新
|
// 新增能力信息完成更新
|
||||||
if(tDev.getDevCapacity().size() != 0){
|
if (tDev.getDevCapacity().size() != 0) {
|
||||||
disposeCapacityMapper.addNewDisposeCapacity(tDev.getDevCapacity());
|
disposeCapacityMapper.addNewDisposeCapacity(tDev.getDevCapacity());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,7 +224,7 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager {
|
||||||
// 获取分页数据
|
// 获取分页数据
|
||||||
List<DisposeDevice> devList = disposeDeviceMapper.selectAll();
|
List<DisposeDevice> devList = disposeDeviceMapper.selectAll();
|
||||||
|
|
||||||
if(devList == null) {
|
if (devList == null) {
|
||||||
devList = new ArrayList<>();
|
devList = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,7 +243,7 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager {
|
||||||
public List<DisposeDevice> getAllDisposeDevices() {
|
public List<DisposeDevice> getAllDisposeDevices() {
|
||||||
List<DisposeDevice> devList = disposeDeviceMapper.selectAll();
|
List<DisposeDevice> devList = disposeDeviceMapper.selectAll();
|
||||||
|
|
||||||
if(devList == null) {
|
if (devList == null) {
|
||||||
devList = new ArrayList<>();
|
devList = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -124,16 +124,4 @@ public class DisposeDevice implements Serializable {
|
||||||
*/
|
*/
|
||||||
@Transient
|
@Transient
|
||||||
private List<DisposeCapacity> devCapacity;
|
private List<DisposeCapacity> devCapacity;
|
||||||
|
|
||||||
/**
|
|
||||||
* The Dev info.
|
|
||||||
*/
|
|
||||||
//@Transient
|
|
||||||
//private DeviceInfo devInfo;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The Link status.
|
|
||||||
*/
|
|
||||||
//@Transient
|
|
||||||
//private Integer linkStatus;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.dispose.pojo.po;
|
||||||
|
|
||||||
|
import com.dispose.ability.DisposeAbility;
|
||||||
|
import com.dispose.pojo.entity.DisposeDevice;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Ability info.
|
||||||
|
*
|
||||||
|
* @author <huangxin@cmhi.chinamoblie.com>
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class AbilityInfo {
|
||||||
|
/**
|
||||||
|
* The Db.
|
||||||
|
*/
|
||||||
|
private DisposeAbility db;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Dev.
|
||||||
|
*/
|
||||||
|
private DisposeDevice dev;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Link status.
|
||||||
|
*/
|
||||||
|
private boolean linkStatus;
|
||||||
|
}
|
|
@ -1,9 +1,38 @@
|
||||||
package com.dispose.service;
|
package com.dispose.service;
|
||||||
|
|
||||||
|
import com.dispose.common.ErrorCode;
|
||||||
|
import com.dispose.pojo.entity.DisposeDevice;
|
||||||
|
import com.dispose.pojo.po.AbilityInfo;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface Dispose ability router service.
|
* The interface Dispose ability router service.
|
||||||
*
|
*
|
||||||
* @author <huangxin@cmhi.chinamoblie.com>
|
* @author <huangxin@cmhi.chinamoblie.com>
|
||||||
*/
|
*/
|
||||||
public interface DisposeAbilityRouterService {
|
public interface DisposeAbilityRouterService {
|
||||||
|
/**
|
||||||
|
* Gets ability device.
|
||||||
|
*
|
||||||
|
* @param ipAddr the ip addr
|
||||||
|
* @param ipPort the ip port
|
||||||
|
* @return the ability device
|
||||||
|
*/
|
||||||
|
AbilityInfo getAbilityDevice(String ipAddr, String ipPort);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets all ability devices.
|
||||||
|
*
|
||||||
|
* @return the all ability devices
|
||||||
|
*/
|
||||||
|
List<AbilityInfo> getAllAbilityDevices();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add dispose ability device error code.
|
||||||
|
*
|
||||||
|
* @param dev the dev
|
||||||
|
* @return the error code
|
||||||
|
*/
|
||||||
|
ErrorCode addDisposeAbilityDevice(DisposeDevice dev);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,15 +2,20 @@ package com.dispose.service.impl;
|
||||||
|
|
||||||
import com.dispose.ability.DisposeAbility;
|
import com.dispose.ability.DisposeAbility;
|
||||||
import com.dispose.ability.impl.DpTechAbilityImpl;
|
import com.dispose.ability.impl.DpTechAbilityImpl;
|
||||||
|
import com.dispose.ability.impl.HaoHanAbilityImpl;
|
||||||
|
import com.dispose.ability.impl.VirtualAbilityImpl;
|
||||||
|
import com.dispose.common.ErrorCode;
|
||||||
import com.dispose.common.HttpType;
|
import com.dispose.common.HttpType;
|
||||||
import com.dispose.manager.DisposeDeviceManager;
|
import com.dispose.manager.DisposeDeviceManager;
|
||||||
import com.dispose.pojo.entity.DisposeDevice;
|
import com.dispose.pojo.entity.DisposeDevice;
|
||||||
|
import com.dispose.pojo.po.AbilityInfo;
|
||||||
import com.dispose.service.DisposeAbilityRouterService;
|
import com.dispose.service.DisposeAbilityRouterService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
@ -25,7 +30,7 @@ public class DisposeAbilityRouterServiceImpl implements DisposeAbilityRouterServ
|
||||||
/**
|
/**
|
||||||
* The Dispose ability map.
|
* The Dispose ability map.
|
||||||
*/
|
*/
|
||||||
private ConcurrentHashMap<String, DisposeAbility> disposeAbilityMap = new ConcurrentHashMap<>();
|
private final ConcurrentHashMap<String, AbilityInfo> disposeAbilityMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Dispose device manager.
|
* The Dispose device manager.
|
||||||
|
@ -37,31 +42,83 @@ public class DisposeAbilityRouterServiceImpl implements DisposeAbilityRouterServ
|
||||||
* Init dispose ability.
|
* Init dispose ability.
|
||||||
*/
|
*/
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void initDisposeAbility() {
|
private void initDisposeAbility() {
|
||||||
List<DisposeDevice> devList = disposeDeviceManager.getAllDisposeDevices();
|
List<DisposeDevice> devList = disposeDeviceManager.getAllDisposeDevices();
|
||||||
|
devList.forEach(this::addDisposeAbilityDevice);
|
||||||
|
}
|
||||||
|
|
||||||
devList.forEach(v -> {
|
/**
|
||||||
DisposeAbility db;
|
* Gets ability device.
|
||||||
|
*
|
||||||
|
* @param ipAddr the ip addr
|
||||||
|
* @param ipPort the ip port
|
||||||
|
* @return the ability device
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public AbilityInfo getAbilityDevice(String ipAddr, String ipPort) {
|
||||||
|
return disposeAbilityMap.get(getAbilityMapKey(ipAddr, ipPort));
|
||||||
|
}
|
||||||
|
|
||||||
String httpType = v.getUrlType() == HttpType.HTTP ? "http://" : "https://";
|
/**
|
||||||
String addr = v.getIpPort() == null || v.getIpPort().length() == 0 ? v.getIpAddr() :
|
* Gets all ability devices.
|
||||||
v.getIpAddr() + ":" + v.getIpPort();
|
*
|
||||||
|
* @return the all ability devices
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<AbilityInfo> getAllAbilityDevices() {
|
||||||
|
return new ArrayList<>(disposeAbilityMap.values());
|
||||||
|
}
|
||||||
|
|
||||||
String url = httpType + addr + "/" + v.getUrlPath();
|
/**
|
||||||
|
* Add dispose ability device error code.
|
||||||
|
*
|
||||||
|
* @param dev the dev
|
||||||
|
* @return the error code
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ErrorCode addDisposeAbilityDevice(DisposeDevice dev) {
|
||||||
|
DisposeAbility db;
|
||||||
|
|
||||||
switch (v.getDeviceType()) {
|
String httpType = dev.getUrlType() == HttpType.HTTP ? "http://" : "https://";
|
||||||
case DPTECH_UMC:
|
String addr = getAbilityMapKey(dev.getIpAddr(), dev.getIpPort());
|
||||||
db = new DpTechAbilityImpl();
|
String url = httpType + addr + "/" + dev.getUrlPath();
|
||||||
db.initDeviceEnv(url, v.getUserName(), v.getPassword());
|
|
||||||
disposeAbilityMap.put(addr, db);
|
switch (dev.getDeviceType()) {
|
||||||
break;
|
case DPTECH_UMC:
|
||||||
case HAOHAN_PLATFORM:
|
db = new DpTechAbilityImpl();
|
||||||
break;
|
break;
|
||||||
case VIRTUAL_DISPOSE:
|
case HAOHAN_PLATFORM:
|
||||||
break;
|
db = new HaoHanAbilityImpl();
|
||||||
default:
|
break;
|
||||||
break;
|
case VIRTUAL_DISPOSE:
|
||||||
}
|
db = new VirtualAbilityImpl();
|
||||||
});
|
break;
|
||||||
|
default:
|
||||||
|
log.error("Unknown dispose device type: {}", dev.getDeviceType());
|
||||||
|
return ErrorCode.ERR_PARAMS;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 初始化设备
|
||||||
|
db.initDeviceEnv(url, dev.getUserName(), dev.getPassword());
|
||||||
|
|
||||||
|
// 缓存处置设备到Hash表中
|
||||||
|
disposeAbilityMap.put(addr, AbilityInfo.builder()
|
||||||
|
.db(db)
|
||||||
|
.dev(dev)
|
||||||
|
.linkStatus(false)
|
||||||
|
.build());
|
||||||
|
|
||||||
|
return ErrorCode.ERR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets ability map key.
|
||||||
|
*
|
||||||
|
* @param ipAddr the ip addr
|
||||||
|
* @param ipPort the ip port
|
||||||
|
* @return the ability map key
|
||||||
|
*/
|
||||||
|
private String getAbilityMapKey(String ipAddr, String ipPort) {
|
||||||
|
return (ipPort == null || ipPort.length() == 0) ? ipAddr : (ipAddr + ":" + ipPort);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
package com.dispose.task;
|
package com.dispose.task;
|
||||||
|
|
||||||
import com.dispose.ability.DisposeAbility;
|
import com.dispose.service.DisposeAbilityRouterService;
|
||||||
import com.dispose.manager.DisposeDeviceManager;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -18,11 +16,11 @@ import javax.annotation.Resource;
|
||||||
@Component
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class DeviceManagerTask {
|
public class DeviceManagerTask {
|
||||||
|
/**
|
||||||
|
* The Dispose ability router service.
|
||||||
|
*/
|
||||||
@Resource
|
@Resource
|
||||||
private DisposeDeviceManager disposeDeviceManager;
|
private DisposeAbilityRouterService disposeAbilityRouterService;
|
||||||
|
|
||||||
@Resource
|
|
||||||
private DisposeAbility disposeAbility;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Thread pool task.
|
* Thread pool task.
|
||||||
|
@ -30,12 +28,10 @@ public class DeviceManagerTask {
|
||||||
@Async("bizExecutor")
|
@Async("bizExecutor")
|
||||||
@Scheduled(cron = "0/5 * * * * ?")
|
@Scheduled(cron = "0/5 * * * * ?")
|
||||||
public void threadPoolTask() {
|
public void threadPoolTask() {
|
||||||
log.info("task run......... {}", disposeAbility.getDeviceLinkStatus());
|
disposeAbilityRouterService.getAllAbilityDevices().forEach(v -> log.info("{}{} get link status {}",
|
||||||
}
|
v.getDev().getIpAddr(),
|
||||||
|
((v.getDev().getIpPort() == null || v.getDev().getIpPort().length() == 0) ?
|
||||||
@PostConstruct
|
"" : ":" + v.getDev().getIpPort()),
|
||||||
public void init() {
|
v.getDb().getDeviceLinkStatus()));
|
||||||
disposeAbility.initDeviceEnv("http://10.88.77.15/UMC/service/AbnormalFlowCleaningService",
|
|
||||||
"admin", "UMCAdministrator");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.haohan.dispose.common;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Hao han get clean task netflow info req.
|
||||||
|
*
|
||||||
|
* @author <huangxin@cmhi.chinamoblie.com>
|
||||||
|
*/
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class HaoHanGetCleanTaskNetflowInfoReq extends HaoHanGetCleanTaskStatusReq {
|
||||||
|
/**
|
||||||
|
* Instantiates a new Hao han get clean task netflow info req.
|
||||||
|
*
|
||||||
|
* @param taskId the task id
|
||||||
|
*/
|
||||||
|
public HaoHanGetCleanTaskNetflowInfoReq(Integer taskId) {
|
||||||
|
this.setCleanTaskId(taskId);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package com.haohan.dispose.common;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Hao han get clean task netflow info resp.
|
||||||
|
*
|
||||||
|
* @author <huangxin@cmhi.chinamoblie.com>
|
||||||
|
*/
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@JsonPropertyOrder({"cleanTaskState", "state", "msg"})
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
|
public class HaoHanGetCleanTaskNetflowInfoResp extends HaoHanGetCleaningNetflowInfoResp {
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.haohan.dispose.common;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Hao han get clean task status req.
|
||||||
|
*
|
||||||
|
* @author <huangxin@cmhi.chinamoblie.com>
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
|
public class HaoHanGetCleanTaskStatusReq {
|
||||||
|
/**
|
||||||
|
* The Clean task state.
|
||||||
|
*/
|
||||||
|
private Integer cleanTaskId;
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package com.haohan.dispose.common;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Hao han get clean task status.
|
||||||
|
*
|
||||||
|
* @author <huangxin@cmhi.chinamoblie.com>
|
||||||
|
*/
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@JsonPropertyOrder({"cleanTaskState", "state", "msg"})
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
|
public class HaoHanGetCleanTaskStatusResp extends HaoHanResp {
|
||||||
|
/**
|
||||||
|
* The Clean task state.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
private Integer cleanTaskState;
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.haohan.dispose.common;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Hao han get cleaning netflow info req.
|
||||||
|
*
|
||||||
|
* @author <huangxin@cmhi.chinamoblie.com>
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class HaoHanGetCleaningNetflowInfoReq {
|
||||||
|
/**
|
||||||
|
* The Order from.
|
||||||
|
*/
|
||||||
|
private String orderFrom;
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
package com.haohan.dispose.common;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Hao han get cleaning netflow info resp.
|
||||||
|
*
|
||||||
|
* @author <huangxin@cmhi.chinamoblie.com>
|
||||||
|
*/
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@JsonPropertyOrder({"cleanTaskState", "state", "msg"})
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
|
public class HaoHanGetCleaningNetflowInfoResp extends HaoHanResp {
|
||||||
|
/**
|
||||||
|
* The Data.
|
||||||
|
*/
|
||||||
|
List<HaoHanNetflowInfo> data;
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
package com.haohan.dispose.common;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Hao han netflow info.
|
||||||
|
*
|
||||||
|
* @author <huangxin@cmhi.chinamoblie.com>
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
|
public class HaoHanNetflowInfo {
|
||||||
|
/**
|
||||||
|
* The Ip.
|
||||||
|
*/
|
||||||
|
private String ip;
|
||||||
|
/**
|
||||||
|
* The In flow.
|
||||||
|
*/
|
||||||
|
private Double inFlow;
|
||||||
|
/**
|
||||||
|
* The In packets.
|
||||||
|
*/
|
||||||
|
private Integer inPackets;
|
||||||
|
/**
|
||||||
|
* The Out flow.
|
||||||
|
*/
|
||||||
|
private Double outFlow;
|
||||||
|
/**
|
||||||
|
* The Out packets.
|
||||||
|
*/
|
||||||
|
private Integer outPackets;
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.haohan.dispose.common;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Hao han resp.
|
||||||
|
*
|
||||||
|
* @author <huangxin@cmhi.chinamoblie.com>
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
|
public class HaoHanResp {
|
||||||
|
/**
|
||||||
|
* The State.
|
||||||
|
*/
|
||||||
|
private Integer state;
|
||||||
|
/**
|
||||||
|
* The Msg.
|
||||||
|
*/
|
||||||
|
private String msg;
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.haohan.dispose.common;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Hao han start clean req.
|
||||||
|
*
|
||||||
|
* @author <huangxin@cmhi.chinamoblie.com>
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
|
public class HaoHanStartCleanReq {
|
||||||
|
/**
|
||||||
|
* The Ip.
|
||||||
|
*/
|
||||||
|
private String ip;
|
||||||
|
/**
|
||||||
|
* The Duration.
|
||||||
|
*/
|
||||||
|
private Integer duration;
|
||||||
|
/**
|
||||||
|
* The Order form.
|
||||||
|
*/
|
||||||
|
private String orderForm;
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.haohan.dispose.common;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Hao han start clean resp.
|
||||||
|
*
|
||||||
|
* @author <huangxin@cmhi.chinamoblie.com>
|
||||||
|
*/
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@JsonPropertyOrder({"cleanTaskId", "state", "msg"})
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
|
public class HaoHanStartCleanResp extends HaoHanResp {
|
||||||
|
/**
|
||||||
|
* The Clean task id.
|
||||||
|
*/
|
||||||
|
private Integer cleanTaskId;
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
package com.haohan.dispose.common;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Hao han stop clean req.
|
||||||
|
*
|
||||||
|
* @author <huangxin@cmhi.chinamoblie.com>
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
|
public class HaoHanStopCleanReq {
|
||||||
|
/**
|
||||||
|
* The Clean task id.
|
||||||
|
*/
|
||||||
|
private Integer cleanTaskId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Order form.
|
||||||
|
*/
|
||||||
|
private String orderForm;
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package com.haohan.dispose.common;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Hao han stop clean resp.
|
||||||
|
*
|
||||||
|
* @author <huangxin@cmhi.chinamoblie.com>
|
||||||
|
*/
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@JsonPropertyOrder({"state", "msg"})
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
|
public class HaoHanStopCleanResp extends HaoHanResp {
|
||||||
|
}
|
|
@ -0,0 +1,145 @@
|
||||||
|
package com.haohan.dispose.protocol;
|
||||||
|
|
||||||
|
import cn.hutool.http.Header;
|
||||||
|
import cn.hutool.http.HttpRequest;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.haohan.dispose.common.HaoHanGetCleanTaskNetflowInfoReq;
|
||||||
|
import com.haohan.dispose.common.HaoHanGetCleanTaskNetflowInfoResp;
|
||||||
|
import com.haohan.dispose.common.HaoHanGetCleanTaskStatusReq;
|
||||||
|
import com.haohan.dispose.common.HaoHanGetCleanTaskStatusResp;
|
||||||
|
import com.haohan.dispose.common.HaoHanGetCleaningNetflowInfoReq;
|
||||||
|
import com.haohan.dispose.common.HaoHanGetCleaningNetflowInfoResp;
|
||||||
|
import com.haohan.dispose.common.HaoHanStartCleanReq;
|
||||||
|
import com.haohan.dispose.common.HaoHanStartCleanResp;
|
||||||
|
import com.haohan.dispose.common.HaoHanStopCleanReq;
|
||||||
|
import com.haohan.dispose.common.HaoHanStopCleanResp;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Restful interface.
|
||||||
|
*
|
||||||
|
* @author <huangxin@cmhi.chinamoblie.com>
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class RestfulInterface {
|
||||||
|
/**
|
||||||
|
* The constant OBJECT_MAPPER.
|
||||||
|
*/
|
||||||
|
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Post json string.
|
||||||
|
*
|
||||||
|
* @param url the url
|
||||||
|
* @param header the header
|
||||||
|
* @param body the body
|
||||||
|
* @return the string
|
||||||
|
*/
|
||||||
|
private static String postJson(String url, Map<String, String> header, String body) {
|
||||||
|
return HttpRequest.post(url).header(Header.CONTENT_TYPE, "application/json").addHeaders(header).body(body)
|
||||||
|
.execute().body();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Protocol run t.
|
||||||
|
*
|
||||||
|
* @param <T> the type parameter
|
||||||
|
* @param <E> the type parameter
|
||||||
|
* @param url the url
|
||||||
|
* @param obj the obj
|
||||||
|
* @param outType the out type
|
||||||
|
* @return the t
|
||||||
|
*/
|
||||||
|
private <T, E> T protocolRun(String url, E obj, Class<T> outType) {
|
||||||
|
try {
|
||||||
|
Map<String, String> httpHeadMap = new HashMap<>(2);
|
||||||
|
httpHeadMap.put(String.valueOf(Header.CONNECTION), "keep-alive");
|
||||||
|
httpHeadMap.put(String.valueOf(Header.ACCEPT), "*/*");
|
||||||
|
|
||||||
|
String svrResp = postJson(url, httpHeadMap, OBJECT_MAPPER.writeValueAsString(obj));
|
||||||
|
|
||||||
|
if (svrResp == null) {
|
||||||
|
log.debug("Server return null: {}", url);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return OBJECT_MAPPER.readValue(svrResp, outType);
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
log.debug("System exception: ", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets clean task status.
|
||||||
|
*
|
||||||
|
* @param baseUrlPath the base url path
|
||||||
|
* @param taskId the task id
|
||||||
|
* @return the clean task status
|
||||||
|
*/
|
||||||
|
public HaoHanGetCleanTaskStatusResp getCleanTaskStatus(String baseUrlPath, Integer taskId) {
|
||||||
|
return protocolRun(baseUrlPath + "/getCleanTaskState",
|
||||||
|
HaoHanGetCleanTaskStatusReq.builder().cleanTaskId(taskId).build(),
|
||||||
|
HaoHanGetCleanTaskStatusResp.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start clean hao han start clean resp.
|
||||||
|
*
|
||||||
|
* @param baseUrlPath the base url path
|
||||||
|
* @param ipAddr the ip addr
|
||||||
|
* @param times the times
|
||||||
|
* @param readme the readme
|
||||||
|
* @return the hao han start clean resp
|
||||||
|
*/
|
||||||
|
public HaoHanStartCleanResp startClean(String baseUrlPath, String ipAddr, int times, String readme) {
|
||||||
|
return protocolRun(baseUrlPath + "/sendTow",
|
||||||
|
new HaoHanStartCleanReq(ipAddr, times, readme),
|
||||||
|
HaoHanStartCleanResp.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop clean hao han stop clean resp.
|
||||||
|
*
|
||||||
|
* @param baseUrlPath the base url path
|
||||||
|
* @param taskId the task id
|
||||||
|
* @param readme the readme
|
||||||
|
* @return the hao han stop clean resp
|
||||||
|
*/
|
||||||
|
public HaoHanStopCleanResp stopClean(String baseUrlPath, Integer taskId, String readme) {
|
||||||
|
return protocolRun(baseUrlPath + "/delTow",
|
||||||
|
new HaoHanStopCleanReq(taskId, readme),
|
||||||
|
HaoHanStopCleanResp.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets cleaning netflow.
|
||||||
|
*
|
||||||
|
* @param baseUrlPath the base url path
|
||||||
|
* @param readme the readme
|
||||||
|
* @return the cleaning netflow
|
||||||
|
*/
|
||||||
|
public HaoHanGetCleaningNetflowInfoResp getCleaningNetflow(String baseUrlPath, String readme) {
|
||||||
|
return protocolRun(baseUrlPath + "/allIpFlow",
|
||||||
|
new HaoHanGetCleaningNetflowInfoReq(readme),
|
||||||
|
HaoHanGetCleaningNetflowInfoResp.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets clean task netflow.
|
||||||
|
*
|
||||||
|
* @param baseUrlPath the base url path
|
||||||
|
* @param taskId the task id
|
||||||
|
* @return the clean task netflow
|
||||||
|
*/
|
||||||
|
public HaoHanGetCleanTaskNetflowInfoResp getCleanTaskNetflow(String baseUrlPath, Integer taskId) {
|
||||||
|
return protocolRun(baseUrlPath + "/cleanTaskFlow",
|
||||||
|
new HaoHanGetCleanTaskNetflowInfoReq(taskId),
|
||||||
|
HaoHanGetCleanTaskNetflowInfoResp.class
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue