REM:
1. 增加浩瀚处置设备支持
2. 增加虚拟处置设备支持
This commit is contained in:
HuangXin 2020-08-10 16:49:34 +08:00
parent eeab55f940
commit 6cbc49ed48
24 changed files with 864 additions and 65 deletions

View File

@ -16,7 +16,7 @@ import javax.annotation.Nullable;
public interface DisposeAbility {
/**
* Init device env error code.
* Init device env.
*
* @param urlPath the url path
* @param username the username
@ -46,11 +46,13 @@ public interface DisposeAbility {
* @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
*/
MulReturnType<ErrorCode, Long> stopDispose(String ip, DisposeCapacityType capType,
@Nullable NetflowDirection[] nfDirection,
@Nullable DDoSAttackType[] attackType);
@Nullable DDoSAttackType[] attackType,
@Nullable Long taskId);
/**

View File

@ -45,7 +45,7 @@ public class DpTechAbilityImpl implements DisposeAbility {
private AbnormalFlowCleaningServicePortType cleanTypePort;
/**
* Init device env error code.
* Init device env.
*
* @param urlPath the url path
* @param username the username
@ -147,12 +147,14 @@ public class DpTechAbilityImpl implements DisposeAbility {
* @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 ipAddr, DisposeCapacityType capType,
@Nullable NetflowDirection[] nfDirection,
@Nullable DDoSAttackType[] attackType) {
@Nullable DDoSAttackType[] attackType,
@Nullable Long taskId) {
ErrorCode err = ErrorCode.ERR_OK;
try {
@ -192,6 +194,11 @@ public class DpTechAbilityImpl implements DisposeAbility {
return new MulReturnType<>(err, null);
}
/**
* Gets device link status.
*
* @return the device link status
*/
@Override
public boolean getDeviceLinkStatus() {
try {

View File

@ -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);
}
}

View File

@ -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;
}
}

View File

@ -17,5 +17,8 @@ public class DisposeConfigValue {
*/
public static volatile long REQUEST_TIMEOUT_MS = 5 * 1000;
/**
* The constant USED_PRIVACY_PROTECT.
*/
public static volatile boolean USED_PRIVACY_PROTECT = false;
}

View File

@ -8,6 +8,7 @@ import com.dispose.mapper.DisposeCapacityMapper;
import com.dispose.mapper.DisposeDeviceMapper;
import com.dispose.pojo.entity.DisposeDevice;
import com.dispose.pojo.po.MulReturnType;
import com.dispose.service.DisposeAbilityRouterService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
@ -18,7 +19,6 @@ import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
/**
* The type Dispose device manager.
@ -28,11 +28,6 @@ import java.util.concurrent.ConcurrentHashMap;
@Component
@Slf4j
public class DisposeDeviceManagerImpl implements DisposeDeviceManager {
/**
* The Dispose device.
*/
private final ConcurrentHashMap<String, DisposeDevice> disposeDevice = new ConcurrentHashMap<>();
/**
* The Dispose capacity mapper.
*/
@ -44,6 +39,12 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager {
@Resource
private DisposeDeviceMapper disposeDeviceMapper;
/**
* The Dispose ability router service.
*/
@Resource
private DisposeAbilityRouterService disposeAbilityRouterService;
/**
* Add dispose device mul return type.
*
@ -71,11 +72,14 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager {
return new MulReturnType<>(ErrorCode.ERR_DATABASE, -1L);
} else {
// 添加设备到缓存中方便调用时查找
String devKey = dev.getIpAddr() + ":" + dev.getIpPort();
disposeDevice.put(devKey, dev);
ErrorCode err = disposeAbilityRouterService.addDisposeAbilityDevice(dev);
// 添加设备能力信息
if (err == ErrorCode.ERR_OK) {
disposeCapacityMapper.addNewDisposeCapacity(dev.getDevCapacity());
return new MulReturnType<>(ErrorCode.ERR_OK, dev.getId());
}
return new MulReturnType<>(err, dev.getId());
}
}

View File

@ -124,16 +124,4 @@ public class DisposeDevice implements Serializable {
*/
@Transient
private List<DisposeCapacity> devCapacity;
/**
* The Dev info.
*/
//@Transient
//private DeviceInfo devInfo;
/**
* The Link status.
*/
//@Transient
//private Integer linkStatus;
}

View File

@ -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;
}

View File

@ -1,9 +1,38 @@
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.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
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);
}

View File

@ -2,15 +2,20 @@ package com.dispose.service.impl;
import com.dispose.ability.DisposeAbility;
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.manager.DisposeDeviceManager;
import com.dispose.pojo.entity.DisposeDevice;
import com.dispose.pojo.po.AbilityInfo;
import com.dispose.service.DisposeAbilityRouterService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
@ -25,7 +30,7 @@ public class DisposeAbilityRouterServiceImpl implements DisposeAbilityRouterServ
/**
* The Dispose ability map.
*/
private ConcurrentHashMap<String, DisposeAbility> disposeAbilityMap = new ConcurrentHashMap<>();
private final ConcurrentHashMap<String, AbilityInfo> disposeAbilityMap = new ConcurrentHashMap<>();
/**
* The Dispose device manager.
@ -37,31 +42,83 @@ public class DisposeAbilityRouterServiceImpl implements DisposeAbilityRouterServ
* Init dispose ability.
*/
@PostConstruct
public void initDisposeAbility() {
private void initDisposeAbility() {
List<DisposeDevice> devList = disposeDeviceManager.getAllDisposeDevices();
devList.forEach(this::addDisposeAbilityDevice);
}
devList.forEach(v -> {
/**
* 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));
}
/**
* Gets all ability devices.
*
* @return the all ability devices
*/
@Override
public List<AbilityInfo> getAllAbilityDevices() {
return new ArrayList<>(disposeAbilityMap.values());
}
/**
* Add dispose ability device error code.
*
* @param dev the dev
* @return the error code
*/
@Override
public ErrorCode addDisposeAbilityDevice(DisposeDevice dev) {
DisposeAbility db;
String httpType = v.getUrlType() == HttpType.HTTP ? "http://" : "https://";
String addr = v.getIpPort() == null || v.getIpPort().length() == 0 ? v.getIpAddr() :
v.getIpAddr() + ":" + v.getIpPort();
String httpType = dev.getUrlType() == HttpType.HTTP ? "http://" : "https://";
String addr = getAbilityMapKey(dev.getIpAddr(), dev.getIpPort());
String url = httpType + addr + "/" + dev.getUrlPath();
String url = httpType + addr + "/" + v.getUrlPath();
switch (v.getDeviceType()) {
switch (dev.getDeviceType()) {
case DPTECH_UMC:
db = new DpTechAbilityImpl();
db.initDeviceEnv(url, v.getUserName(), v.getPassword());
disposeAbilityMap.put(addr, db);
break;
case HAOHAN_PLATFORM:
db = new HaoHanAbilityImpl();
break;
case VIRTUAL_DISPOSE:
db = new VirtualAbilityImpl();
break;
default:
break;
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);
}
}

View File

@ -1,13 +1,11 @@
package com.dispose.task;
import com.dispose.ability.DisposeAbility;
import com.dispose.manager.DisposeDeviceManager;
import com.dispose.service.DisposeAbilityRouterService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
/**
@ -18,11 +16,11 @@ import javax.annotation.Resource;
@Component
@Slf4j
public class DeviceManagerTask {
/**
* The Dispose ability router service.
*/
@Resource
private DisposeDeviceManager disposeDeviceManager;
@Resource
private DisposeAbility disposeAbility;
private DisposeAbilityRouterService disposeAbilityRouterService;
/**
* Thread pool task.
@ -30,12 +28,10 @@ public class DeviceManagerTask {
@Async("bizExecutor")
@Scheduled(cron = "0/5 * * * * ?")
public void threadPoolTask() {
log.info("task run......... {}", disposeAbility.getDeviceLinkStatus());
}
@PostConstruct
public void init() {
disposeAbility.initDeviceEnv("http://10.88.77.15/UMC/service/AbnormalFlowCleaningService",
"admin", "UMCAdministrator");
disposeAbilityRouterService.getAllAbilityDevices().forEach(v -> log.info("{}{} get link status {}",
v.getDev().getIpAddr(),
((v.getDev().getIpPort() == null || v.getDev().getIpPort().length() == 0) ?
"" : ":" + v.getDev().getIpPort()),
v.getDb().getDeviceLinkStatus()));
}
}

View File

@ -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);
}
}

View File

@ -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 {
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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 {
}

View File

@ -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
);
}
}