Merge branch 'v2.0.3_dev' into 'master'

V2.0.3 dev

See merge request 
This commit is contained in:
黄昕 2020-12-09 09:16:35 +08:00
commit 548914f306
35 changed files with 1853 additions and 55 deletions

View File

@ -56,6 +56,14 @@ public interface DisposeAbility {
@Nullable Integer attackType,
@Nullable String taskId);
/**
* Task status mul return type.
*
* @param taskId the task id
* @return the mul return type
*/
MulReturnType<ErrorCode, Long> taskStatus(String taskId);
/**
* Gets ability device fireware.
*

View File

@ -316,4 +316,15 @@ public class DpTechAbilityImpl implements DisposeAbility {
return ret;
}
/**
* Task status mul return type.
*
* @param taskId the task id
* @return the mul return type
*/
@Override
public MulReturnType<ErrorCode, Long> taskStatus(String taskId) {
return new MulReturnType<>(ErrorCode.ERR_UNSUPPORT, -1L);
}
}

View File

@ -214,4 +214,15 @@ public class HaoHanAbilityImpl implements DisposeAbility {
IPAddress addr = new IPAddressString(ipAddr).getAddress();
return addr.isIPv4();
}
/**
* Task status mul return type.
*
* @param taskId the task id
* @return the mul return type
*/
@Override
public MulReturnType<ErrorCode, Long> taskStatus(String taskId) {
return new MulReturnType<>(ErrorCode.ERR_UNSUPPORT, -1L);
}
}

View File

@ -0,0 +1,330 @@
package com.dispose.ability.impl;
import com.dispose.ability.DisposeAbility;
import cn.hutool.http.HttpResponse;
import com.dispose.common.DisposeCapacityType;
import com.dispose.common.DisposeObjectType;
import com.dispose.common.ErrorCode;
import com.dispose.common.NetflowDirection;
import com.dispose.pojo.po.MulReturnType;
import com.dispose.pojo.vo.DeviceFirewareInfo;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.huawei.dispose.common.HuaWeiLoginResp;
import com.huawei.dispose.protocol.HuaWeiInterface;
import inet.ipaddr.IPAddress;
import inet.ipaddr.IPAddressString;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.annotation.Nullable;
import javax.servlet.http.HttpServletResponse;
@Component
@Slf4j
public class HuaWeiAbilityImpl implements DisposeAbility {
/**
* The Restful interface.
*/
private final HuaWeiInterface restfulInterface = new HuaWeiInterface();
/**
* The constant OBJECT_MAPPER.
*/
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
/**
* The Url root path.
*/
@Getter
@Setter
private String urlRootPath;
/**
* The Username.
*/
@Getter
@Setter
private String username;
/**
* The Password.
*/
@Getter
@Setter
private String password;
/**
* The Token.
*/
private String token;
/**
* 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;
this.username = username;
this.password = password;
upgradeToken();
}
/**
* Run dispose mul return type.
*
* @param disposeObject the dispose object
* @param objectType the object type
* @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, String> runDispose(String disposeObject, DisposeObjectType objectType,
DisposeCapacityType capType,
@Nullable NetflowDirection nfDirection,
@Nullable Integer attackType,
@Nullable Long duration) {
String url = urlRootPath + "/divert";
String disposeObj = null;
IPAddress addr = new IPAddressString(disposeObject).getAddress();
if (addr.isIPv4()) {
disposeObj = disposeObject + "/32";
}else if(addr.isIPv6()) {
disposeObj = disposeObject + "/128";
}
if (token == null || token.length() == 0) {
return new MulReturnType<>(ErrorCode.ERR_LOGOUT, "");
}
try {
log.info("++++Begging HuaWei Start Cleanup Task: {}", disposeObject);
if (capType != DisposeCapacityType.CLEANUP) {
log.error("----Error HuaWei don't support dispose capacity type: {}", capType);
return new MulReturnType<>(ErrorCode.ERR_UNSUPPORT, null);
}
ErrorCode resp = restfulInterface.createDivert(url, token, new String[]{disposeObj});
// 判断是否token过期
if (resp == ErrorCode.ERR_TOKENNOTFOUND) {
// 重新登录获取 token
upgradeToken();
resp = restfulInterface.createDivert(url, token, new String[]{disposeObject});
}
if (resp == null) {
log.error("----Error HuaWei start clean {} server return error", disposeObject);
return new MulReturnType<>(ErrorCode.ERR_HUAWEI_ERROR, null);
}
if (resp != ErrorCode.ERR_OK) {
log.error("----Error HuaWei start clean {} return error: {}, {}", disposeObject, resp.getCode(), resp.getMsg());
return new MulReturnType<>(ErrorCode.ERR_HUAWEI_ERROR, null);
}
log.debug("----Finish HuaWei Start Cleanup Task: {}", disposeObject);
return new MulReturnType<>(ErrorCode.ERR_OK, null);
} catch (Exception ex) {
log.error("----Exception HuaWei Start Cleanup Task: {}, {}, {}", disposeObject, nfDirection, duration);
return new MulReturnType<>(ErrorCode.ERR_SYSTEMEXCEPTION, null);
}
}
/**
* Stop dispose mul return type.
*
* @param disposeObject the dispose object
* @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 disposeObject, DisposeCapacityType capType,
@Nullable NetflowDirection nfDirection,
@Nullable Integer attackType,
@Nullable String taskId) {
IPAddress addr = new IPAddressString(disposeObject).getAddress();
String disposeObj = null;
if (addr.isIPv4()) {
disposeObj = disposeObject + "-32";
}else if(addr.isIPv6()) {
disposeObj = disposeObject + "-128";
}
String url = urlRootPath + "/divert/" + disposeObj;
if (token == null || token.length() == 0) {
return new MulReturnType<>(ErrorCode.ERR_LOGOUT, null);
}
try {
log.debug("++++Begging HuaWei Stop Cleanup Task: {}", taskId);
if (capType != DisposeCapacityType.CLEANUP) {
log.error("----Error HuaWei don't support dispose capacity type: {}", capType);
return new MulReturnType<>(ErrorCode.ERR_UNSUPPORT, null);
}
if (taskId == null) {
return new MulReturnType<>(ErrorCode.ERR_PARAMS, null);
}
ErrorCode rspInfo = restfulInterface.deleteZones(url, token);
// 判断是否token过期
if (rspInfo == ErrorCode.ERR_TOKENNOTFOUND) {
// 重新登录获取 token
upgradeToken();
rspInfo = restfulInterface.deleteZones(url, token);
}
if (rspInfo == null) {
log.error("----Error HuaWei stop task{} server return error", taskId);
return new MulReturnType<>(ErrorCode.ERR_HUAWEI_ERROR, null);
}
if (rspInfo != ErrorCode.ERR_OK) {
log.error("----Error HuaWei stop task{} server return error", taskId);
return new MulReturnType<>(ErrorCode.ERR_CALLDEVICE, null);
}
log.debug("----Finish HuaWei Stop Cleanup Task: {}", taskId);
return new MulReturnType<>(ErrorCode.ERR_OK, null);
} catch (Exception ex) {
log.error("----Exception HuaWei Stop Cleanup Task: {}, {}, {}", disposeObject, nfDirection, taskId);
return new MulReturnType<>(ErrorCode.ERR_SYSTEMEXCEPTION, null);
}
}
/**
* Task status mul return type.
*
* @param taskId the task id
* @return the mul return type
*/
@Override
public MulReturnType<ErrorCode, Long> taskStatus(String taskId) {
return 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("HuaWei")
.model("Unknown")
.firmware("Unknown")
.os("Linux Server")
.kernel("Linux")
.arch("x86_64")
.version("Unknown")
.memory(-1)
.freeMemory(-1)
.cpuUsed(-1)
.build());
}
/**
* To device attack type long.
*
* @param ddosAttackTypeMask the ddos attack type mask
* @return the long
*/
@Override
public Long toDeviceAttackType(Long ddosAttackTypeMask) {
return ddosAttackTypeMask;
}
/**
* Gets device link status.
*
* @return the device link status
*/
@Override
public boolean getDeviceLinkStatus() {
try {
//查询所有的zone接口调用成功认为设备心跳正常
String url = urlRootPath + "/allzone";
if (token == null || token.length() == 0) {
return false;
}
HttpResponse response = restfulInterface.queryAllZones(url, token);
if (response.getStatus() == HttpServletResponse.SC_PRECONDITION_FAILED) {
// 重新登录获取 token
upgradeToken();
response = restfulInterface.queryAllZones(url, token);
}
return response.getStatus() == HttpServletResponse.SC_OK;
} catch (
Exception ex) {
log.error(ex.getMessage());
}
return false;
}
/**
* Gets dispose device protect object.
*/
@Override
public void getDisposeDeviceProtectObject() {
}
/**
* Is carry protect ip boolean.
*
* @param ipAddr the ip addr
* @return the boolean
*/
@Override
public boolean isCarryProtectIp(String ipAddr) {
return true;
}
/**
* Upgrade token.
*/
private void upgradeToken() {
try {
HttpResponse resp = restfulInterface.auth(this.urlRootPath, username, password);
if (resp != null) {
if (resp.getStatus() == HttpServletResponse.SC_OK && resp.body() != null) {
HuaWeiLoginResp logInfo = OBJECT_MAPPER.readValue(resp.body(), HuaWeiLoginResp.class);
this.token = logInfo.getToken();
}
}
} catch (Exception ignored) {
}
}
}

View File

@ -15,6 +15,7 @@ import com.pengxin.dispose.common.PengXinLoginRsp;
import com.pengxin.dispose.common.PengXinStartTaskItem;
import com.pengxin.dispose.common.PengXinStartTaskRsp;
import com.pengxin.dispose.common.PengXinStopTaskRsp;
import com.pengxin.dispose.common.PengXinTaskStatusRsp;
import com.pengxin.dispose.protocol.PengXinInterface;
import inet.ipaddr.IPAddress;
import inet.ipaddr.IPAddressString;
@ -34,7 +35,6 @@ import java.util.List;
*/
@Slf4j
public class PengXinAbilityImpl implements DisposeAbility {
/**
* The Protect ip v 4.
*/
@ -43,48 +43,41 @@ public class PengXinAbilityImpl implements DisposeAbility {
* The Protect ip v 6.
*/
private final List<String> protectIpV6 = new ArrayList<>();
/**
* The Restful interface.
*/
private final PengXinInterface restfulInterface = new PengXinInterface();
/**
* The Peng xin dispose type.
*/
private final Integer[] pengXinDisposeType = new Integer[]{0, 4, 1, 3};
/**
* The Task req id.
*/
private Long taskReqId = System.currentTimeMillis();
/**
* The Url root path.
*/
@Getter
@Setter
private String urlRootPath;
/**
* The Username.
*/
@Getter
@Setter
private String username;
/**
* The Password.
*/
@Getter
@Setter
private String password;
/**
* The Token.
*/
private String token;
/**
* The Peng xin dispose type.
*/
private final Integer[] pengXinDisposeType = new Integer[] {0, 4, 1, 3};
/**
* Gets peng xin task type.
*
@ -141,7 +134,8 @@ public class PengXinAbilityImpl implements DisposeAbility {
* @return the mul return type
*/
@Override
public MulReturnType<ErrorCode, String> runDispose(String disposeObject, DisposeObjectType objectType, DisposeCapacityType capType,
public MulReturnType<ErrorCode, String> runDispose(String disposeObject, DisposeObjectType objectType,
DisposeCapacityType capType,
@Nullable NetflowDirection nfDirection,
@Nullable Integer attackType,
@Nullable Long duration) {
@ -185,11 +179,23 @@ public class PengXinAbilityImpl implements DisposeAbility {
if (rspInfo == null || rspInfo.getCode() != ErrorCode.ERR_OK.getHttpCode()) {
log.error("----Error PengXin start clean {} server return error", disposeObject);
return new MulReturnType<>(ErrorCode.ERR_HAOHAN_ERROR, null);
return new MulReturnType<>(ErrorCode.ERR_PENGXIN_ERROR, null);
}
log.debug("----Finish PengXin Start Cleanup Task: {}", disposeObject);
return new MulReturnType<>(ErrorCode.ERR_OK, rspInfo.getMsgContent().getItems().get(0).getTaskId());
if (rspInfo.getMsgContent().getItems().size() == 0) {
log.error("----Error PengXin start clean {} server return nothing", disposeObject);
return new MulReturnType<>(ErrorCode.ERR_PENGXIN_ERROR, null);
} else {
int errCode = rspInfo.getMsgContent().getItems().get(0).getStatus();
if (errCode != ErrorCode.ERR_OK.getCode()) {
log.error("----Error PengXin start clean {} server return error: {}", disposeObject, errCode);
return new MulReturnType<>(ErrorCode.ERR_PENGXIN_ERROR, null);
}
log.debug("----Finish PengXin Start Cleanup Task: {}", disposeObject);
return new MulReturnType<>(ErrorCode.ERR_OK, rspInfo.getMsgContent().getItems().get(0).getTaskId());
}
} catch (Exception ex) {
log.error("----Exception PengXin Start Cleanup Task: {}, {}, {}", disposeObject, nfDirection, duration);
return new MulReturnType<>(ErrorCode.ERR_SYSTEMEXCEPTION, null);
@ -218,7 +224,7 @@ public class PengXinAbilityImpl implements DisposeAbility {
}
try {
log.debug("++++Begging PengXin Stop Cleanup Task: {}", taskId);
log.info("++++Begging PengXin Stop Cleanup Task: {}", taskId);
if (capType != DisposeCapacityType.BLACKHOOL) {
log.error("----Error PengXin don't support dispose capacity type: {}", capType);
@ -244,8 +250,20 @@ public class PengXinAbilityImpl implements DisposeAbility {
return new MulReturnType<>(ErrorCode.ERR_CALLDEVICE, null);
}
log.debug("----Finish PengXin Stop Cleanup Task: {}", taskId);
return new MulReturnType<>(ErrorCode.ERR_OK, null);
if (rspInfo.getMsgContent().getItems().size() == 0) {
log.error("----Error PengXin stop clean {} server return nothing", disposeObject);
return new MulReturnType<>(ErrorCode.ERR_PENGXIN_ERROR, null);
} else {
int errCode = rspInfo.getMsgContent().getItems().get(0).getStatus();
if (errCode != ErrorCode.ERR_OK.getCode()) {
log.error("----Error PengXin stop clean {} server return error: {}", disposeObject, errCode);
return new MulReturnType<>(ErrorCode.ERR_PENGXIN_ERROR, null);
}
log.debug("----Finish PengXin Stop Cleanup Task: {}", taskId);
return new MulReturnType<>(ErrorCode.ERR_OK, null);
}
} catch (Exception ex) {
log.error("----Exception PengXin Stop Cleanup Task: {}, {}, {}", disposeObject, nfDirection, taskId);
return new MulReturnType<>(ErrorCode.ERR_SYSTEMEXCEPTION, null);
@ -407,6 +425,47 @@ public class PengXinAbilityImpl implements DisposeAbility {
return ret;
}
/**
* Task status mul return type.
*
* @param taskId the task id
* @return the mul return type
*/
@Override
public MulReturnType<ErrorCode, Long> taskStatus(String taskId) {
if (token == null || token.length() == 0) {
return new MulReturnType<>(ErrorCode.ERR_LOGOUT, -1L);
}
try {
String url = urlRootPath + "dispose_device/task/get";
ProtocolRespDTO<PengXinTaskStatusRsp> rspInfo = restfulInterface.getDeviceTaskStatus(url, token,
new String[]{taskId});
// 判断是否token过期
if (rspInfo != null && rspInfo.getCode() == HttpServletResponse.SC_UNAUTHORIZED) {
// 重新登录获取 token
upgradeToken();
rspInfo = restfulInterface.getDeviceTaskStatus(url, token, new String[]{taskId});
}
if (rspInfo != null && rspInfo.getCode() == ErrorCode.ERR_OK.getHttpCode()) {
if (rspInfo.getMsgContent().getItems().size() == 0) {
return new MulReturnType<>(ErrorCode.ERR_NOSUCHTASK, -1L);
}
return new MulReturnType<>(ErrorCode.ERR_OK,
rspInfo.getMsgContent().getItems().get(0).getTaskStatus());
} else {
return new MulReturnType<>(ErrorCode.ERR_CALLDEVICE, -1L);
}
} catch (Exception ignored) {
return new MulReturnType<>(ErrorCode.ERR_SYSTEMEXCEPTION, -1L);
}
}
/**
* Upgrade token.
*/

View File

@ -132,4 +132,15 @@ public class VirtualAbilityImpl implements DisposeAbility {
public boolean isCarryProtectIp(String ipAddr) {
return true;
}
/**
* Task status mul return type.
*
* @param taskId the task id
* @return the mul return type
*/
@Override
public MulReturnType<ErrorCode, Long> taskStatus(String taskId) {
return new MulReturnType<>(ErrorCode.ERR_UNSUPPORT, -1L);
}
}

View File

@ -14,12 +14,14 @@ public enum DisposeDeviceType implements BaseEnum {
* The Haohan platform.
*/
HAOHAN_PLATFORM(1, "浩瀚处置设备"),
/**
* The Pengxin platform.
*/
PENGXIN_PLATFORM(2, "鹏信处置设备"),
/**
* The HuaWei platform.
*/
HUAWEI_PLATFORM(3, "华为处置设备"),
/**
* The Virtual dispose.
*/

View File

@ -30,6 +30,16 @@ public enum DisposeTaskStatus implements BaseEnum {
* The Task expired.
*/
TASK_EXPIRED(5, "过期"),
/**
* Task start failed dispose task status.
*/
TASK_START_FAILED(6, "启动失败"),
/**
* Task stop failed dispose task status.
*/
TASK_STOP_FAILED(7, "停止失败"),
;
/**

View File

@ -219,7 +219,27 @@ public enum ErrorCode {
/**
* The Err no device by areaCode.
*/
ERR_NODEVICE_AREACODE(111, "区域无该设备"),
ERR_NODEVICE_AREACODE(112, "区域无该设备"),
/**
* The Err specified IP already exists.
*/
ERR_SPECIFIEDIP_EXISTS(113, "指定的IP已经存在"),
/**
* The Err specified IP does not exists.
*/
ERR_SPECIFIEDIP_NOTEXISTS(114, "指定的IP地址不存在"),
/**
* The Err server processing request.
*/
ERR_SERVER_PROCESSREQ(115, "服务器处理请求错误"),
/**
* The Err huawei error.
*/
ERR_HUAWEI_ERROR(116, "华为设备返回错误"),
/**
* The Err pengxin error.
*/
ERR_PENGXIN_ERROR(117, "鹏信设备返回错误"),
;
/**

View File

@ -101,7 +101,7 @@ public class DisposeTaskController {
Long devId = Long.parseLong(Optional.ofNullable(req.getDeviceId()).orElse("-1"));
Long aId = userAccountService.getUserIdByAuthHead(Objects.requireNonNull(headers.get("Authorization")).get(0));
DisposeCapacityType capType = CommonEnumHandler.codeOf(DisposeCapacityType.class, req.getType());
String endTime = String.valueOf(req.getDisposeTime());
String endTime = String.valueOf(req.getDisposeTime() == -1 ? 5256000: req.getDisposeTime());
NetflowDirection netDir = CommonEnumHandler.codeOf(NetflowDirection.class,
Optional.ofNullable(req.getFlowDirection()).orElse(2));
Long attackType = DDoSAttackType.getTypeMaskFromAttackType(Optional.ofNullable(req.getAttackType())
@ -399,6 +399,7 @@ public class DisposeTaskController {
.devId(String.valueOf(k.getDeviceId()))
.externId(String.valueOf(k.getExternId()))
.status(k.getStatus())
.devStatus(k.getDevStatus())
.build();
taskDetail.getDeviceTask().add(deviceTaskDetail);
});

View File

@ -45,6 +45,15 @@ public interface DeviceTaskManager {
*/
boolean changeDisposeDeviceTaskInfoStatus(Long id, DisposeTaskStatus status);
/**
* Change dispose device task info dev status int.
*
* @param id the id
* @param devStatus the dev status
* @return the int
*/
int changeDisposeDeviceTaskInfoDevStatus(Long id, Long devStatus);
/**
* Sets exec attack type.
*
@ -126,4 +135,11 @@ public interface DeviceTaskManager {
* @return the task by id
*/
DeviceTask getTaskById(Long id);
/**
* Gets peng xin task.
*
* @return the peng xin task
*/
List<DeviceTask> getPengXinTask();
}

View File

@ -79,6 +79,18 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
return deviceTaskMapper.changeTaskStatus(id, status) == 1;
}
/**
* Change dispose device task info dev status long.
*
* @param id the id
* @param devStatus the dev status
* @return the long
*/
@Override
public int changeDisposeDeviceTaskInfoDevStatus(Long id, Long devStatus) {
return deviceTaskMapper.changeTaskDevStatus(id, devStatus);
}
/**
* Sets exec attack type.
*
@ -283,4 +295,14 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
public DeviceTask getTaskById(Long id) {
return deviceTaskMapper.getTaskInfoById(id);
}
/**
* Gets PengXin device task info.
*
* @return the minId task info.
*/
@Override
public List<DeviceTask> getPengXinTask(){
return deviceTaskMapper.getPengXinTask();
}
}

View File

@ -3,10 +3,12 @@ package com.dispose.manager.impl;
import com.dispose.common.DisposeCapacityType;
import com.dispose.common.DisposeTaskStatus;
import com.dispose.common.ErrorCode;
import com.dispose.manager.DeviceTaskManager;
import com.dispose.manager.DisposeTaskManager;
import com.dispose.mapper.DisposeTaskMapper;
import com.dispose.pojo.entity.DisposeTask;
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;
@ -24,12 +26,29 @@ import java.util.List;
@Component
@Slf4j
public class DisposeTaskManagerImpl implements DisposeTaskManager {
/**
* The Device task manager.
*/
@Resource
private DeviceTaskManager deviceTaskManager;
/**
* The Dispose ability router service.
*/
@Resource
private DisposeAbilityRouterService disposeAbilityRouterService;
/**
* The Dispose task mapper.
*/
@Resource
private DisposeTaskMapper disposeTaskMapper;
/**
* The Dispose task manager.
*/
@Resource
private DisposeTaskManager disposeTaskManager;
/**
* Gets dispose task.
*

View File

@ -85,6 +85,16 @@ public interface DeviceTaskMapper {
int changeTaskStatus(@Param("id") Long id,
@Param("status") DisposeTaskStatus status);
/**
* Change task dev status int.
*
* @param id the id
* @param devStatus the dev status
* @return the int
*/
int changeTaskDevStatus(@Param("id") Long id,
@Param("devStatus") Long devStatus);
/**
* Change exec attack type in value int.
*
@ -144,4 +154,11 @@ public interface DeviceTaskMapper {
*/
int changeExternId(@Param("id") Long id,
@Param("externId") String externId);
/**
* Gets PengXin device task info.
*
* @return PengXin device task info
*/
List<DeviceTask> getPengXinTask();
}

View File

@ -31,6 +31,10 @@ public class GetDeviceTaskDetail {
* The Extern id.
*/
private String externId;
/**
* The Dev status.
*/
private Long devStatus;
/**
* The Status.
*/

View File

@ -87,4 +87,8 @@ public class DeviceTask implements Serializable {
* The Status.
*/
private Long status;
/**
* The Dev status.
*/
private Long devStatus;
}

View File

@ -2,6 +2,7 @@ package com.dispose.restful;
import cn.hutool.http.Header;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.dispose.common.ConstValue;
import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO;
import com.fasterxml.jackson.core.JsonProcessingException;
@ -53,12 +54,12 @@ public class RestfulInterface {
* @param url the url
* @param header the header
* @param body the body
* @return the string
* @return the http response
*/
private static String postJson(String url, Map<String, String> header, String body) {
private static HttpResponse postJson(String url, Map<String, String> header, String body) {
HttpRequest.setGlobalTimeout(timeOutValue);
return HttpRequest.post(url).header(Header.CONTENT_TYPE, "application/json").addHeaders(header).body(body)
.execute().body();
.execute();
}
/**
@ -66,12 +67,39 @@ public class RestfulInterface {
*
* @param url the url
* @param header the header
* @return the json
* @return the http response
*/
private static String getJson(String url, Map<String, String> header) {
private static HttpResponse getJson(String url, Map<String, String> header) {
HttpRequest.setGlobalTimeout(timeOutValue);
return HttpRequest.get(url).header(Header.CONTENT_TYPE, "application/json").addHeaders(header)
.execute().body();
.execute();
}
/**
* Put json.
*
* @param url the url
* @param header the header
* @param body the body
* @return the http response
*/
private static HttpResponse putJson(String url, Map<String, String> header, String body) {
HttpRequest.setGlobalTimeout(timeOutValue);
return HttpRequest.put(url).header(Header.CONTENT_TYPE, "application/json").addHeaders(header).body(body)
.execute();
}
/**
* Deletes http response.
*
* @param url the url
* @param header the header
* @return the http response
*/
private static HttpResponse deleteJson(String url, Map<String, String> header, String body) {
HttpRequest.setGlobalTimeout(timeOutValue);
return HttpRequest.delete(url).header(Header.CONTENT_TYPE, "application/json").addHeaders(header).body(body)
.execute();
}
/**
@ -94,7 +122,7 @@ public class RestfulInterface {
log.debug("Restful request: {}: {}", url, reqJson);
String svrResp = postJson(url, httpHeadMap, reqJson);
String svrResp = postJson(url, httpHeadMap, reqJson).body();
if (svrResp == null) {
log.debug("Server return null: {}", url);
@ -141,10 +169,10 @@ public class RestfulInterface {
switch (reqType) {
case GET:
svrResp = getJson(url, httpHeadMap);
svrResp = getJson(url, httpHeadMap).body();
break;
case POST:
svrResp = postJson(url, httpHeadMap, reqJson);
svrResp = postJson(url, httpHeadMap, reqJson).body();
break;
default:
log.error("Unknown method: {}", reqType);
@ -171,6 +199,65 @@ public class RestfulInterface {
}
}
/**
* huawei pro run protocol resp dto.
*
* @param <E> the type parameter
* @param url the url
* @param token the token
* @param obj the obj
* @param reqType the req type
* @return the t
*/
public static <E> HttpResponse huaWeiProRun(String url, String token, E obj, RequestMethod reqType) {
try {
HttpResponse svrResp = null;
Map<String, String> httpHeadMap = new HashMap<>(2);
httpHeadMap.put(String.valueOf(Header.CONNECTION), "keep-alive");
httpHeadMap.put(String.valueOf(Header.ACCEPT), "*/*");
if (token != null && token.length() > 0) {
httpHeadMap.put("X-Auth-Token", token);
}
String reqJson = OBJECT_MAPPER.writeValueAsString(obj);
log.debug("Restful request: {}, {}: {}", url, token, reqJson);
switch (reqType) {
case GET:
svrResp = getJson(url, httpHeadMap);
break;
case POST:
svrResp = postJson(url, httpHeadMap, reqJson);
break;
case PUT:
svrResp = putJson(url, httpHeadMap, reqJson);
break;
case DELETE:
svrResp = deleteJson(url, httpHeadMap, reqJson);
break;
default:
log.error("Unknown method: {}", reqType);
break;
}
if (svrResp == null) {
log.debug("Server return null: {}", url);
return null;
}
log.debug("Restful response: {}, {}: {}", url, token, svrResp.body());
return svrResp;
} catch (JsonProcessingException e) {
log.info("System exception: ", e);
return null;
}
}
/**
* Create resp type type.
*

View File

@ -1,6 +1,7 @@
package com.dispose.service.impl;
import com.dispose.common.DisposeConfigValue;
import com.dispose.common.DisposeDeviceType;
import com.dispose.common.DisposeTaskStatus;
import com.dispose.common.DpTechAttackType;
import com.dispose.common.ErrorCode;
@ -14,6 +15,7 @@ import com.dispose.pojo.po.AbilityInfo;
import com.dispose.pojo.po.MulReturnType;
import com.dispose.service.DeviceTaskManagerService;
import com.dispose.service.DisposeAbilityRouterService;
import com.pengxin.dispose.common.PengXinTaskStatus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
@ -117,7 +119,6 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(), DisposeTaskStatus.TASK_FINISHED);
}
/**
* Hao han device task run.
*
@ -434,7 +435,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
MulReturnType<ErrorCode, String> ret;
// 重试错误次数过多
if (deviceTask.getErrRetry() >= DisposeConfigValue.CALL_ERROR_RETRY_TIMES) {
if (deviceTask.getErrRetry() > DisposeConfigValue.CALL_ERROR_RETRY_TIMES) {
return;
}
@ -466,14 +467,26 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
} else if (deviceTask.getErrRetry() < DisposeConfigValue.CALL_ERROR_RETRY_TIMES) {
// 设置该任务为新任务待下次重试启动
deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(), DisposeTaskStatus.TASK_NEW);
// 记录任务出错重试次数
deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), deviceTask.getErrRetry() + 1);
log.error("PENGXIN_PLATFORM setup task times {} error {}: {}", deviceTask.getErrRetry(),
ret.getSecondParam(), deviceTask);
} else {
// 任务出错不在重试当做失败任务处理
deviceTaskManager.setAttackTypeStatus(deviceTask.getId(),
disposeTask.getFlowDirection(), 0L);
deviceTaskManager.setAttackTypeStatus(deviceTask.getId(), disposeTask.getFlowDirection(), 0L);
// 设置该任务为启动失败
deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(),
DisposeTaskStatus.TASK_START_FAILED);
//任务出错设备任务状态为启动处置任务失败
deviceTaskManager.changeDisposeDeviceTaskInfoDevStatus(deviceTask.getId(),
(long) PengXinTaskStatus.TASK_STARTED_FAILED.getValue());
// 记录任务出错重试次数
deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), 0);
log.error("PENGXIN_PLATFORM setup task error {}: {}", ret.getFirstParam(), deviceTask);
}
}
@ -488,6 +501,11 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
private void pengXinDeviceTaskStop(AbilityInfo ai, DeviceTask deviceTask, DisposeTask disposeTask) {
MulReturnType<ErrorCode, Long> ret;
// 重试错误次数过多
if (deviceTask.getErrRetry() > DisposeConfigValue.CALL_ERROR_RETRY_TIMES) {
return;
}
// 停止处置任务
ret = ai.getDb().stopDispose(disposeTask.getDisposeObject(), disposeTask.getDisposeCapacity(), null, null,
deviceTask.getExternId());
@ -504,16 +522,216 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
log.error("PENGXIN_PLATFORM stop task times {} error {}: {}", deviceTask.getErrRetry(),
ret.getSecondParam(), deviceTask);
} else {
// 记录任务出错重试次数
deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), 0);
// 设置该任务为停止失败
deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(), DisposeTaskStatus.TASK_STOP_FAILED);
log.error("PENGXIN_PLATFORM stop task error {}: {}", ret.getFirstParam(), deviceTask);
}
}
/**
* Hua wei device task run.
*
* @param ai the ai
* @param deviceTask the device task
* @param disposeTask the dispose task
*/
private void huaWeiDeviceTaskRun(AbilityInfo ai, DeviceTask deviceTask, DisposeTask disposeTask) {
MulReturnType<ErrorCode, String> ret;
// 重试错误次数过多
if (deviceTask.getErrRetry() >= DisposeConfigValue.CALL_ERROR_RETRY_TIMES) {
return;
}
// 设置任务状态为启动中
deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(), DisposeTaskStatus.TASK_STARTING);
// 设置启动任务攻击类型状态
deviceTaskManager.setExecAttackType(deviceTask.getId(), NetflowDirection.DIRECTION_BI,
deviceTask.getTaskAttackType());
ret = ai.getDb()
.runDispose(disposeTask.getDisposeObject(), disposeTask.getObjectType(),
disposeTask.getDisposeCapacity(), null,
null, (long) -(Helper.getTimestampDiffNow(disposeTask.getPlanEndTime()) / 60));
if (ret.getFirstParam() == ErrorCode.ERR_OK) {
// 设置攻击类型任务启动结果
deviceTaskManager.setAttackTypeStatus(deviceTask.getId(),
disposeTask.getFlowDirection(), deviceTask.getTaskAttackType());
// 更改处置任务状态为处置中
deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(), DisposeTaskStatus.TASK_STARTED);
log.info("HUAWEI_PLATFORM setup task succeed: {}, device taskId {}", deviceTask, ret.getSecondParam());
// 重置错误尝试次数
deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), 0);
} else if (deviceTask.getErrRetry() < DisposeConfigValue.CALL_ERROR_RETRY_TIMES) {
// 设置该任务为新任务待下次重试启动
deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(), DisposeTaskStatus.TASK_NEW);
// 记录任务出错重试次数
deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), deviceTask.getErrRetry() + 1);
log.error("HUAWEI_PLATFORM setup task times {} error {}: {}", deviceTask.getErrRetry(),
ret.getSecondParam(), deviceTask);
} else {
// 任务出错不在重试当做失败任务处理
deviceTaskManager.setAttackTypeStatus(deviceTask.getId(),
disposeTask.getFlowDirection(), 0L);
log.error("HUAWEI_PLATFORM setup task error {}: {}", ret.getFirstParam(), deviceTask);
}
}
/**
* Hua wei device task stop.
*
* @param ai the ai
* @param deviceTask the device task
* @param disposeTask the dispose task
*/
private void huaWeiDeviceTaskStop(AbilityInfo ai, DeviceTask deviceTask, DisposeTask disposeTask) {
MulReturnType<ErrorCode, Long> ret;
// 停止处置任务
ret = ai.getDb().stopDispose(disposeTask.getDisposeObject(), disposeTask.getDisposeCapacity(), null, null,
deviceTask.getExternId());
if (ret.getFirstParam() == ErrorCode.ERR_OK) {
log.info("HUAWEI_PLATFORM stop task succeed: {}, device taskId {}", deviceTask, ret.getSecondParam());
// 设置任务状态为结束
deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(), DisposeTaskStatus.TASK_FINISHED);
deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), 0);
deviceTaskManager.setAttackTypeStatus(deviceTask.getId(), disposeTask.getFlowDirection(), 0L);
} else if (deviceTask.getErrRetry() < DisposeConfigValue.CALL_ERROR_RETRY_TIMES) {
// 记录任务出错重试次数
deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), deviceTask.getErrRetry() + 1);
log.error("HUAWEI_PLATFORM stop task times {} error {}: {}", deviceTask.getErrRetry(),
ret.getSecondParam(), deviceTask);
} else {
log.error("HUAWEI_PLATFORM stop task error {}: {}", ret.getFirstParam(), deviceTask);
}
}
/**
* Restful device task run.
*
* @param ai the ai
* @param deviceTask the device task
* @param disposeTask the dispose task
* @param deviceType the device type
*/
private void restfulDeviceTaskRun(AbilityInfo ai, DeviceTask deviceTask, DisposeTask disposeTask,
DisposeDeviceType deviceType) {
MulReturnType<ErrorCode, String> ret;
// 重试错误次数过多
if (deviceTask.getErrRetry() > DisposeConfigValue.CALL_ERROR_RETRY_TIMES) {
return;
}
// 设置任务状态为启动中
deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(), DisposeTaskStatus.TASK_STARTING);
// 设置启动任务攻击类型状态
deviceTaskManager.setExecAttackType(deviceTask.getId(), NetflowDirection.DIRECTION_BI,
deviceTask.getTaskAttackType());
ret = ai.getDb()
.runDispose(disposeTask.getDisposeObject(), disposeTask.getObjectType(),
disposeTask.getDisposeCapacity(), null,
null, (long) -(Helper.getTimestampDiffNow(disposeTask.getPlanEndTime()) / 60));
if (ret.getFirstParam() == ErrorCode.ERR_OK) {
// 设置攻击类型任务启动结果
deviceTaskManager.setAttackTypeStatus(deviceTask.getId(),
disposeTask.getFlowDirection(), deviceTask.getTaskAttackType());
// 更改处置任务状态为处置中
deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(), DisposeTaskStatus.TASK_STARTED);
// 记录设备返回的任务ID
if (ret.getSecondParam() != null && ret.getSecondParam().length() > 0) {
deviceTaskManager.setTaskExternId(deviceTask.getId(), ret.getSecondParam());
log.info("{} setup task succeed: {}, device taskId {}", deviceType, deviceTask, ret.getSecondParam());
} else {
log.info("{} setup task succeed: {}, unnecessary device taskId", deviceType, deviceTask);
}
// 重置错误尝试次数
deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), 0);
} else if (deviceTask.getErrRetry() < DisposeConfigValue.CALL_ERROR_RETRY_TIMES) {
// 设置该任务为新任务待下次重试启动
deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(), DisposeTaskStatus.TASK_NEW);
// 记录任务出错重试次数
deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), deviceTask.getErrRetry() + 1);
log.error("{} setup task times {} error {}: {}", deviceType, deviceTask.getErrRetry(),
ret.getSecondParam(), deviceTask);
} else {
// 任务出错不在重试当做失败任务处理
deviceTaskManager.setAttackTypeStatus(deviceTask.getId(), disposeTask.getFlowDirection(), 0L);
// 设置该任务为启动失败
deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(),
DisposeTaskStatus.TASK_START_FAILED);
//任务出错设备任务状态为启动处置任务失败
deviceTaskManager.changeDisposeDeviceTaskInfoDevStatus(deviceTask.getId(),
(long) PengXinTaskStatus.TASK_STARTED_FAILED.getValue());
// 记录任务出错重试次数
deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), 0);
log.error("{} setup task error {}: {}", deviceType, ret.getFirstParam(), deviceTask);
}
}
/**
* Restful device task stop.
*
* @param ai the ai
* @param deviceTask the device task
* @param disposeTask the dispose task
* @param deviceType the device type
*/
private void restfulDeviceTaskStop(AbilityInfo ai, DeviceTask deviceTask, DisposeTask disposeTask,
DisposeDeviceType deviceType) {
MulReturnType<ErrorCode, Long> ret;
// 重试错误次数过多
if (deviceTask.getErrRetry() > DisposeConfigValue.CALL_ERROR_RETRY_TIMES) {
return;
}
// 停止处置任务
ret = ai.getDb().stopDispose(disposeTask.getDisposeObject(), disposeTask.getDisposeCapacity(), null, null,
deviceTask.getExternId());
if (ret.getFirstParam() == ErrorCode.ERR_OK) {
log.info("{} stop task succeed: {}, device taskId {}", deviceType, deviceTask, ret.getSecondParam());
// 设置任务状态为结束
deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(), DisposeTaskStatus.TASK_FINISHED);
deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), 0);
deviceTaskManager.setAttackTypeStatus(deviceTask.getId(), disposeTask.getFlowDirection(), 0L);
} else if (deviceTask.getErrRetry() < DisposeConfigValue.CALL_ERROR_RETRY_TIMES) {
// 记录任务出错重试次数
deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), deviceTask.getErrRetry() + 1);
log.error("{} stop task times {} error {}: {}", deviceType, deviceTask.getErrRetry(),
ret.getSecondParam(), deviceTask);
} else {
// 记录任务出错重试次数
deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), 0);
// 设置该任务为停止失败
deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(), DisposeTaskStatus.TASK_STOP_FAILED);
log.error("{} stop task error {}: {}", deviceType, ret.getFirstParam(), deviceTask);
}
}
/**
* Dispose task manager schedule.
*/
@Override
public void disposeTaskManagerSchedule() {
// 清理过期任务
for (DisposeTask v : disposeTaskManager.getExpiredTasks()) {
log.info("Task {} {} {} is expired, expect finished at {}",
@ -590,7 +808,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
break;
case HAOHAN_PLATFORM:
haoHanDeviceTaskRun(ai, v, task);
restfulDeviceTaskRun(ai, v, task, DisposeDeviceType.HAOHAN_PLATFORM);
break;
case VIRTUAL_DISPOSE:
@ -598,7 +816,11 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
break;
case PENGXIN_PLATFORM:
pengXinDeviceTaskRun(ai, v, task);
restfulDeviceTaskRun(ai, v, task, DisposeDeviceType.PENGXIN_PLATFORM);
break;
case HUAWEI_PLATFORM:
restfulDeviceTaskRun(ai, v, task, DisposeDeviceType.HUAWEI_PLATFORM);
break;
default:
@ -653,15 +875,13 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
// 设置标志避免对同一个IP重复调用停止处置命令
taskCache.put(taskStopKey, true);
deviceTaskManager.changeDisposeDeviceTaskInfoStatus(v.getId(), DisposeTaskStatus.TASK_EXPIRED);
switch (ai.getDev().getDeviceType()) {
case DPTECH_UMC:
dpTechDeviceTaskStop(ai, v, task);
break;
case HAOHAN_PLATFORM:
haoHanDeviceTaskStop(ai, v, task);
restfulDeviceTaskStop(ai, v, task, DisposeDeviceType.HAOHAN_PLATFORM);
break;
case VIRTUAL_DISPOSE:
@ -669,7 +889,11 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
break;
case PENGXIN_PLATFORM:
pengXinDeviceTaskStop(ai, v, task);
restfulDeviceTaskStop(ai, v, task, DisposeDeviceType.PENGXIN_PLATFORM);
break;
case HUAWEI_PLATFORM:
restfulDeviceTaskStop(ai, v, task, DisposeDeviceType.HUAWEI_PLATFORM);
break;
default:
@ -682,6 +906,46 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
}
}
/**
* Device task status schedule.
*/
public void deviceTaskStatusSchedule() {
//处置任务设备类型为鹏信设备任务状态不再变更
for (DeviceTask v : deviceTaskManager.getPengXinTask()) {
// 获取设备
AbilityInfo ai = disposeAbilityRouterService.getAbilityDevice(v.getDeviceId());
// 如果设备已经删除或者禁用跳过处理
if (ai == null) {
continue;
}
// 对处置IP生成一个唯一的操作标识符
String taskStatusKey = v.getId() + "Status" + ai.getDev().getDeviceType().getDescription();
if (taskCache.containsKey(taskStatusKey)) {
continue;
}
// 设置标志避免对同一个IP重复调用停止处置命令
taskCache.put(taskStatusKey, true);
if (v.getExternId() != null && v.getExternId().length() > 0) {
MulReturnType<ErrorCode, Long> ret = ai.getDb().taskStatus(v.getExternId());
if (ret.getFirstParam() == ErrorCode.ERR_OK) {
log.debug("id:{}, before devStatus:{}, after devStatus:{}", v.getId(),
v.getDevStatus(), ret.getSecondParam());
deviceTaskManager.changeDisposeDeviceTaskInfoDevStatus(v.getId(),
ret.getSecondParam());
}
}
// 处置命令调用结束允许下一次停止命令调用
taskCache.remove(taskStatusKey);
}
}
/**
* Schedule runner thread.
*/
@ -697,5 +961,8 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
// 处置设备停止任务
deviceTaskStopSchedule();
// 定时刷新设备任务状态
deviceTaskStatusSchedule();
}
}

View File

@ -5,6 +5,7 @@ import com.dispose.ability.impl.DpTechAbilityImpl;
import com.dispose.ability.impl.HaoHanAbilityImpl;
import com.dispose.ability.impl.PengXinAbilityImpl;
import com.dispose.ability.impl.VirtualAbilityImpl;
import com.dispose.ability.impl.HuaWeiAbilityImpl;
import com.dispose.common.DisposeCapacityType;
import com.dispose.common.ErrorCode;
import com.dispose.common.HttpType;
@ -115,6 +116,9 @@ public class DisposeAbilityRouterServiceImpl implements DisposeAbilityRouterServ
case PENGXIN_PLATFORM:
db = new PengXinAbilityImpl();
break;
case HUAWEI_PLATFORM:
db = new HuaWeiAbilityImpl();
break;
case VIRTUAL_DISPOSE:
db = new VirtualAbilityImpl();
break;

View File

@ -83,7 +83,7 @@ public class HaoHanInterface {
// 自动停止多余的旧任务
ids.forEach(v -> {
log.debug("HAOHAN_PLATFORM automatic stop more task: {}", v);
stopClean(baseUrlPath, Integer.parseInt(maxId), readme);
stopClean(baseUrlPath, Integer.parseInt(v), readme);
});
// 更改返回值

View File

@ -0,0 +1,28 @@
package com.huawei.dispose.common;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* The type Hua wei login req.
*
* @author <chenlinghy@cmhi.chinamoblie.com>
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonPropertyOrder({"zone_ip"})
@JsonInclude(JsonInclude.Include.NON_NULL)
public class HuaWeiCreatDivertReq {
/**
* The array zone ip.
*/
@JsonProperty("zone_ip")
private String[] zoneIp;
}

View File

@ -0,0 +1,30 @@
package com.huawei.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.NoArgsConstructor;
/**
* The type Hua wei login req.
*
* @author <chenlinghy@cmhi.chinamoblie.com>
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonPropertyOrder({"username", "password"})
@JsonInclude(JsonInclude.Include.NON_NULL)
public class HuaWeiLoginReq {
/**
* The User name.
*/
private String username;
/**
* The Password.
*/
private String password;
}

View File

@ -0,0 +1,26 @@
package com.huawei.dispose.common;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
/**
* The type Hua wei login rsp.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
@EqualsAndHashCode()
@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonPropertyOrder({"token"})
@JsonInclude(JsonInclude.Include.NON_NULL)
public class HuaWeiLoginResp {
/**
* The Token.
*/
private String token;
}

View File

@ -0,0 +1,111 @@
package com.huawei.dispose.protocol;
import cn.hutool.http.HttpResponse;
import com.dispose.common.ErrorCode;
import com.dispose.restful.RestfulInterface;
import com.huawei.dispose.common.HuaWeiCreatDivertReq;
import com.huawei.dispose.common.HuaWeiLoginReq;
import org.springframework.web.bind.annotation.RequestMethod;
import javax.servlet.http.HttpServletResponse;
/**
* The type Hua Wei interface.
*
* @author <chenlinghy@cmhi.chinamoblie.com>
*/
public class HuaWeiInterface {
/**
* Login protocol resp dto.
*
* @param baseUrlPath the base url path
* @param username the username
* @param password the password
* @return the http resp
*/
public HttpResponse auth(String baseUrlPath, String username, String password) {
return RestfulInterface.huaWeiProRun(baseUrlPath + "/auth",
null,
new HuaWeiLoginReq(username, password),
RequestMethod.POST);
}
/**
* create divert protocol resp dto.
*
* @param baseUrlPath the base url path
* @param token the token
* @param zone_ip zone ip
* @return the delete zone status
*/
public ErrorCode createDivert(String baseUrlPath, String token, String[] zone_ip) {
//获取HTTP部分
HttpResponse response = RestfulInterface.huaWeiProRun(baseUrlPath,
token,
new HuaWeiCreatDivertReq(zone_ip),
RequestMethod.POST);
if (response != null) {
if (response.getStatus() == HttpServletResponse.SC_CREATED) {
return ErrorCode.ERR_OK;
} else if (response.getStatus() == HttpServletResponse.SC_BAD_REQUEST) {
return ErrorCode.ERR_PARAMS;
} else if (response.getStatus() == HttpServletResponse.SC_CONFLICT) {
return ErrorCode.ERR_SPECIFIEDIP_EXISTS;
} else if (response.getStatus() == HttpServletResponse.SC_PRECONDITION_FAILED) {
return ErrorCode.ERR_TOKENNOTFOUND;
} else if (response.getStatus() == HttpServletResponse.SC_INTERNAL_SERVER_ERROR) {
return ErrorCode.ERR_SERVER_PROCESSREQ;
}
}
return ErrorCode.ERR_UNKNOWNCMD;
}
/**
* delete divert protocol resp dto.
*
* @param baseUrlPath the base url path
* @param token the token
* @return the delete zone status
*/
public ErrorCode deleteZones(String baseUrlPath, String token) {
//获取HTTP部分
HttpResponse response = RestfulInterface.huaWeiProRun(baseUrlPath,
token,
null,
RequestMethod.DELETE);
if (response != null) {
if (response.getStatus() == HttpServletResponse.SC_OK) {
return ErrorCode.ERR_OK;
} else if (response.getStatus() == HttpServletResponse.SC_BAD_REQUEST) {
return ErrorCode.ERR_PARAMS;
} else if (response.getStatus() == HttpServletResponse.SC_NOT_FOUND) {
return ErrorCode.ERR_SPECIFIEDIP_NOTEXISTS;
} else if (response.getStatus() == HttpServletResponse.SC_PRECONDITION_FAILED) {
return ErrorCode.ERR_TOKENNOTFOUND;
} else if (response.getStatus() == HttpServletResponse.SC_INTERNAL_SERVER_ERROR) {
return ErrorCode.ERR_SERVER_PROCESSREQ;
}
}
return ErrorCode.ERR_UNKNOWNCMD;
}
/**
* query all zones protocol resp dto.
*
* @param baseUrlPath the base url path
* @param token the token
* @return the http resp
*/
public HttpResponse queryAllZones(String baseUrlPath, String token) {
return RestfulInterface.huaWeiProRun(baseUrlPath,
token,
null,
RequestMethod.GET);
}
}

View File

@ -0,0 +1,96 @@
package com.pengxin.dispose.common;
import com.dispose.common.BaseEnum;
/**
* The enum Dispose task status.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
public enum PengXinTaskStatus implements BaseEnum {
/**
* The Task starting.
*/
TASK_STARTING(0, "启动中"),
/**
* The Task started.
*/
TASK_STARTED(1, "封堵中"),
/**
* The user aborted Task finished .
*/
TASK_FINISHED_USER(2, "用户中止"),
/**
* The Task finished automatically when the scheduled time is reached.
*/
TASK_FINISHED_TIME(3, "已结束"),
/**
* The Task started failed.
*/
TASK_STARTED_FAILED(4, "设备启动处置任务失败"),
/**
* The Task reviewing.
*/
TASK_REVIEWING(5, "待审核"),
/**
* The Task reviewed failed.
*/
TASK_REVIEWED_FAILED(6, "审核失败"),
/**
* The Task unblocked failed.
*/
TASK_UNBLOCKED_FAILED(7, "解封失败"),
/**
* The Task unblocked.
*/
TASK_UNBLOCKED(8, "解封成功"),
/**
* The Task unblocking.
*/
TASK_UNBLOCKING(9, "解封中"),
/**
* The Task unknown.
*/
TASK_UNKNOWN(-1, "未知状态"),
;
/**
* The Code.
*/
private final Integer code;
/**
* The Readme.
*/
private final String readme;
/**
* Instantiates a new Dispose task status.
*
* @param code the code
* @param readme the readme
*/
PengXinTaskStatus(int code, String readme) {
this.code = code;
this.readme = readme;
}
/**
* Gets value.
*
* @return the value
*/
@Override
public Integer getValue() {
return this.code;
}
/**
* Gets description.
*
* @return the description
*/
@Override
public String getDescription() {
return this.readme;
}
}

View File

@ -0,0 +1,48 @@
package com.pengxin.dispose.common;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
/**
* The type Peng xin task status item.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class PengXinTaskStatusItem extends PengXinBaseResp {
/**
* The Task id.
*/
private String taskId;
/**
* The Type.
*/
private Integer type;
/**
* The Object type.
*/
private Integer objectType;
/**
* The Dispose object.
*/
private String disposeObject;
/**
* The Start time.
*/
private Long startTime;
/**
* The Dispose time.
*/
private Long disposeTime;
/**
* The Task status.
*/
private Long taskStatus;
}

View File

@ -0,0 +1,30 @@
package com.pengxin.dispose.common;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* The type Peng xin task status rsp.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class PengXinTaskStatusRsp {
/**
* The Device name.
*/
private String deviceName;
/**
* The Items.
*/
private List<PengXinTaskStatusItem> items;
}

View File

@ -13,6 +13,7 @@ import com.pengxin.dispose.common.PengXinStartTaskReq;
import com.pengxin.dispose.common.PengXinStartTaskRsp;
import com.pengxin.dispose.common.PengXinStopTaskReq;
import com.pengxin.dispose.common.PengXinStopTaskRsp;
import com.pengxin.dispose.common.PengXinTaskStatusRsp;
import org.springframework.web.bind.annotation.RequestMethod;
import javax.servlet.http.HttpServletResponse;
@ -160,4 +161,29 @@ public class PengXinInterface {
PengXinDisposeAbilityRsp.class,
RequestMethod.GET);
}
/**
* Gets device task status.
*
* @param baseUrlPath the base url path
* @param token the token
* @param taskId the task id
* @return the device task status
*/
public ProtocolRespDTO<PengXinTaskStatusRsp> getDeviceTaskStatus(String baseUrlPath, String token, String[] taskId) {
BaseProtocolDTO<PengXinStopTaskReq> reqInfo = new BaseProtocolDTO<>();
reqInfo.setMsgContent(new PengXinStopTaskReq());
reqInfo.getMsgContent().setTaskId(taskId);
reqInfo.setCryptoType(this.cryptoType);
reqInfo.setVer(this.ver);
reqInfo.setTimeStamp(System.currentTimeMillis());
return RestfulInterface.baseProRun(baseUrlPath,
token,
reqInfo,
PengXinTaskStatusRsp.class,
RequestMethod.POST);
}
}

View File

@ -36,6 +36,7 @@ CREATE TABLE `device_task`
`externId` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '扩展任务ID',
`errRetry` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '调用失败重试次数',
`status` int(10) NOT NULL DEFAULT 0 COMMENT '任务状态',
`devStatus` int(10) NOT NULL DEFAULT 0 COMMENT '设备任务状态',
PRIMARY KEY (`id`) USING BTREE,
INDEX `task_info_ibfk_1` (`taskId`) USING BTREE,
INDEX `task_info_ibfk_2` (`deviceId`) USING BTREE,

View File

@ -14,6 +14,7 @@
<result column="attackTypeStatusOut" property="attackTypeStatusOut"/>
<result column="externId" property="externId"/>
<result column="errRetry" property="errRetry"/>
<result column="devStatus" property="devStatus"/>
<result column="status" property="status"/>
</resultMap>
@ -24,19 +25,19 @@
<insert id="addNewTaskInfoList" useGeneratedKeys="true" keyProperty="id"
parameterType="com.dispose.pojo.entity.DeviceTask">
INSERT IGNORE INTO device_task(taskId, deviceId, taskAttackType, status)
INSERT IGNORE INTO device_task(taskId, deviceId, taskAttackType, status, devStatus)
VALUES
<foreach collection="taskLists" item="task" separator=",">
(#{task.taskId}, #{task.deviceId}, #{task.taskAttackType},
${@com.dispose.common.DisposeTaskStatus@TASK_NEW.getValue()})
${@com.dispose.common.DisposeTaskStatus@TASK_NEW.getValue()}, -1)
</foreach>
</insert>
<insert id="addNewTaskInfo" useGeneratedKeys="true" keyProperty="id"
parameterType="com.dispose.pojo.entity.DeviceTask">
INSERT IGNORE INTO device_task(taskId, deviceId, taskAttackType, status)
INSERT IGNORE INTO device_task(taskId, deviceId, taskAttackType, status, devStatus)
VALUES (#{taskId}, #{deviceId}, #{taskAttackType},
${@com.dispose.common.DisposeTaskStatus@TASK_NEW.getValue()})
${@com.dispose.common.DisposeTaskStatus@TASK_NEW.getValue()}, -1)
</insert>
<select id="getTaskInfoById" resultMap="device_task">
@ -54,16 +55,29 @@
<select id="getNewTaskInfos" resultMap="device_task">
SELECT *
FROM device_task
WHERE status = ${@com.dispose.common.DisposeTaskStatus@TASK_NEW.getValue()}
OR status = ${@com.dispose.common.DisposeTaskStatus@TASK_STARTING.getValue()}
<choose>
<when test="status == @com.dispose.common.DisposeTaskStatus@TASK_START_FAILED">
WHERE CURRENT_TIMESTAMP - endTime > 300
</when>
<otherwise>
WHERE status = ${@com.dispose.common.DisposeTaskStatus@TASK_NEW.getValue()}
</otherwise>
</choose>
</select>
<select id="getRunningTaskInfos" resultMap="device_task">
SELECT *
FROM device_task
WHERE status = ${@com.dispose.common.DisposeTaskStatus@TASK_NEW.getValue()}
OR status = ${@com.dispose.common.DisposeTaskStatus@TASK_STARTING.getValue()}
OR status = ${@com.dispose.common.DisposeTaskStatus@TASK_STARTED.getValue()}
<choose>
<when test="status == @com.dispose.common.DisposeTaskStatus@TASK_STOP_FAILED">
WHERE CURRENT_TIMESTAMP - endTime > 300
</when>
<otherwise>
WHERE status = ${@com.dispose.common.DisposeTaskStatus@TASK_NEW.getValue()}
OR status = ${@com.dispose.common.DisposeTaskStatus@TASK_STARTING.getValue()}
OR status = ${@com.dispose.common.DisposeTaskStatus@TASK_STARTED.getValue()}
</otherwise>
</choose>
</select>
<select id="getTaskByDetails" resultMap="device_task">
@ -78,6 +92,8 @@
SET status = #{status}
<if test="status == @com.dispose.common.DisposeTaskStatus@TASK_FINISHED
or status == @com.dispose.common.DisposeTaskStatus@TASK_CANCELED
or status == @com.dispose.common.DisposeTaskStatus@TASK_START_FAILED
or status == @com.dispose.common.DisposeTaskStatus@TASK_STOP_FAILED
or status == @com.dispose.common.DisposeTaskStatus@TASK_EXPIRED">
, endTime = CURRENT_TIMESTAMP
</if>
@ -87,6 +103,13 @@
WHERE id = #{id}
</update>
<update id="changeTaskDevStatus">
UPDATE device_task
SET devStatus = #{devStatus}
WHERE id = #{id}
AND devStatus != #{devStatus}
</update>
<update id="changeExecAttackTypeInValue">
UPDATE device_task
SET execAttackTypeIn = #{attackTypeValue}
@ -123,4 +146,13 @@
WHERE id = #{id}
</update>
<select id="getPengXinTask" resultType="com.dispose.pojo.entity.DeviceTask">
SELECT dt.*, dd.*
FROM device_task dt
LEFT JOIN dispose_device dd ON dt.deviceId = dd.id
WHERE dd.deviceType = ${@com.dispose.common.DisposeDeviceType@PENGXIN_PLATFORM.getValue()}
AND dt.devStatus != ${@com.pengxin.dispose.common.PengXinTaskStatus@TASK_FINISHED_USER.getValue()}
AND dt.devStatus != ${@com.pengxin.dispose.common.PengXinTaskStatus@TASK_FINISHED_TIME.getValue()}
AND dt.devStatus != ${@com.pengxin.dispose.common.PengXinTaskStatus@TASK_REVIEWED_FAILED.getValue()}
</select>
</mapper>

View File

@ -30,6 +30,7 @@
<result column="externId" property="externId"/>
<result column="errRetry" property="errRetry"/>
<result column="status" property="status"/>
<result column="devStatus" property="devStatus"/>
</collection>
</resultMap>
@ -61,6 +62,7 @@
ti.attackTypeStatusOut attackTypeStatusOut,
ti.externId externId,
ti.errRetry errRetry,
ti.devStatus devStatus,
ti.status status
FROM dispose_task dt
LEFT JOIN device_task ti on dt.id = ti.taskId
@ -84,6 +86,7 @@
ti.attackTypeStatusOut attackTypeStatusOut,
ti.externId externId,
ti.errRetry errRetry,
ti.devStatus devStatus,
ti.status status
FROM dispose_task dt
LEFT JOIN device_task ti on dt.id = ti.taskId
@ -103,6 +106,7 @@
ti.attackTypeStatusOut attackTypeStatusOut,
ti.externId externId,
ti.errRetry errRetry,
ti.devStatus devStatus,
ti.status status
FROM dispose_task dt
LEFT JOIN device_task ti on dt.id = ti.taskId
@ -118,6 +122,8 @@
dt.currentStatus != ${@com.dispose.common.DisposeTaskStatus@TASK_FINISHED.getValue()} AND
dt.currentStatus != ${@com.dispose.common.DisposeTaskStatus@TASK_CANCELED.getValue()} AND
dt.currentStatus != ${@com.dispose.common.DisposeTaskStatus@TASK_EXPIRED.getValue()} AND
dt.currentStatus != ${@com.dispose.common.DisposeTaskStatus@TASK_START_FAILED.getValue()} AND
dt.currentStatus != ${@com.dispose.common.DisposeTaskStatus@TASK_STOP_FAILED.getValue()} AND
dt.planEndTime > CURRENT_TIMESTAMP()
<if test="deviceId != -1">
AND dt.deviceId = #{deviceId}
@ -159,6 +165,8 @@
currentStatus = #{status}
<if test="status == @com.dispose.common.DisposeTaskStatus@TASK_FINISHED
or status == @com.dispose.common.DisposeTaskStatus@TASK_CANCELED
or status == @com.dispose.common.DisposeTaskStatus@TASK_START_FAILED
or status == @com.dispose.common.DisposeTaskStatus@TASK_STOP_FAILED
or status == @com.dispose.common.DisposeTaskStatus@TASK_EXPIRED">
, endTime = CURRENT_TIMESTAMP
</if>

View File

@ -36,6 +36,7 @@ CREATE TABLE `device_task`
`externId` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '扩展任务ID',
`errRetry` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '调用失败重试次数',
`status` int(10) NOT NULL DEFAULT 0 COMMENT '任务状态',
`devStatus` int(10) NOT NULL DEFAULT 0 COMMENT '设备任务状态',
PRIMARY KEY (`id`) USING BTREE,
INDEX `task_info_ibfk_1` (`taskId`) USING BTREE,
INDEX `task_info_ibfk_2` (`deviceId`) USING BTREE,
@ -174,7 +175,8 @@ VALUES (1, -1, 1, -1, 0, '192.168.10.1', 1, CURRENT_TIMESTAMP, date_add(now(), i
8796093022207,
1024, 0);
INSERT INTO `dispose_task`
VALUES (2, -1, 1, -1, 0, '192.168.10.2', 1, CURRENT_TIMESTAMP, date_add(now(), interval 60 MINUTE), null, 2, 8796093022207,
VALUES (2, -1, 1, -1, 0, '192.168.10.2', 1, CURRENT_TIMESTAMP, date_add(now(), interval 60 MINUTE), null, 2,
8796093022207,
1024, 0);
-- ----------------------------

View File

@ -17,6 +17,7 @@ import com.dispose.test.testcase.qa.v200.P2Logout;
import com.dispose.test.testcase.qa.v200.P2TaskList;
import com.dispose.test.testcase.qa.v200.P2TaskStart;
import com.dispose.test.testcase.qa.v200.P2TaskStartMulIp;
import com.dispose.test.testcase.qa.v200.P2TaskStartDispose;
import com.dispose.test.testcase.qa.v200.P2TaskStop;
import com.dispose.test.testcase.qa.v200.P3All;
@ -73,6 +74,7 @@ public interface TestCaseRun {
Collections.addAll(tolTestCase, P2TaskStart.getTestCase());
Collections.addAll(tolTestCase, P2TaskStartMulIp.getTestCase());
Collections.addAll(tolTestCase, P2TaskStartDispose.getTestCase());
Collections.addAll(tolTestCase, P2TaskStop.getTestCase());
Collections.addAll(tolTestCase, P2TaskList.getTestCase());

View File

@ -107,7 +107,7 @@ public class JsonTestCaseRun extends CommonRestfulJson implements TestCaseRun {
.filter(k -> k.getCaseJsonValue() != null && k.getCaseJsonValue().length() > 0)
.filter(k -> usedId.size() == 0 || usedId.stream().anyMatch(v -> Objects.equals(v, k.getId())))
.filter(k -> Arrays.stream(CommonEnvironment.commonPriorityFilter).anyMatch(v -> k.getPriority() == v))
//.filter(k -> k.getId() >= 20000)
//.filter(k -> k.getId() >= 1300)
.collect(Collectors.toList());
}

View File

@ -0,0 +1,455 @@
package com.dispose.test.testcase.qa.v200;
import com.dispose.common.ErrorCode;
import com.dispose.pojo.dto.protocol.base.BaseRespStatus;
import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO;
import com.dispose.pojo.dto.protocol.task.DisposeTaskStartRsp;
import com.dispose.pojo.dto.protocol.task.TaskStartMulRsp;
import com.dispose.test.common.QATestItem;
import com.dispose.test.common.TestPriority;
import com.dispose.test.common.VerifyProtoRespCallback;
import com.dispose.test.qa.TestCaseRun;
import org.junit.Assert;
import org.springframework.web.bind.annotation.RequestMethod;
/**
* The type P 2 task start dispose ip.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
public class P2TaskStartDispose {
/**
* The constant BASE_P2_TASK_START_MUL_ID.
*/
public static final int BASE_P2_TASK_START_MUL_ID = 1300;
/**
* The constant testItemArray.
*/
private static final QATestItem[] testItemArray = new QATestItem[]{
QATestItem.builder()
.id(BASE_P2_TASK_START_MUL_ID)
.name("对多个IP指定攻击类型进行清洗")
.priority(TestPriority.P2_PRIORITY)
.urlPath("/task/startDispose")
.method(RequestMethod.POST)
.caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":0," +
"\"disposeObjects\":[{\"disposeObject\":\"192.168.50.4\", \"objectType\": 1, \"areaCode\": 0}," +
"{\"disposeObject\":\"192.168.50.3\", \"objectType\": 1, \"areaCode\": 0}],\"disposeTime\":10," +
"\"flowDirection\":2,\"attackType\":[1,2,3,4,5]}}")
.rspClass(DisposeTaskStartRsp.class)
.rspCode(ErrorCode.ERR_OK)
.autoLogin(true)
.verifyCallback((VerifyProtoRespCallback<DisposeTaskStartRsp>) (v, e, c) -> {
Assert.assertNotNull(v);
Assert.assertNotNull(v.getMsgContent());
Assert.assertEquals((long) v.getCode(), e.getHttpCode());
Assert.assertNotNull(v.getMsgContent().getItems());
v.getMsgContent().getItems().forEach(k -> {
Assert.assertNotNull(k.getDisposeObject());
Assert.assertEquals((long) k.getStatus(), e.getCode());
Assert.assertNotNull(k.getTaskId());
Assert.assertNotNull(k.getExpireTime());
});
}).build(),
QATestItem.builder()
.id(BASE_P2_TASK_START_MUL_ID + 1)
.name("对多个IP全部攻击类型进行清洗")
.priority(TestPriority.P2_PRIORITY)
.urlPath("/task/startDispose")
.method(RequestMethod.POST)
.caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":0," +
"\"disposeObjects\":[{\"disposeObject\":\"192.168.50.4\", \"objectType\": 1, \"areaCode\": 0}," +
"{\"disposeObject\":\"192.168.50.3\", \"objectType\": 1, \"areaCode\": 0}],\"disposeTime\":10," +
"\"flowDirection\":2,\"attackType\":[-1]}}")
.rspClass(DisposeTaskStartRsp.class)
.rspCode(ErrorCode.ERR_OK)
.autoLogin(true)
.verifyCallback((VerifyProtoRespCallback<DisposeTaskStartRsp>) (v, e, c) -> {
Assert.assertNotNull(v);
Assert.assertNotNull(v.getMsgContent());
Assert.assertEquals((long) v.getCode(), e.getHttpCode());
Assert.assertNotNull(v.getMsgContent().getItems());
v.getMsgContent().getItems().forEach(k -> {
Assert.assertNotNull(k.getDisposeObject());
Assert.assertEquals((long) k.getStatus(), e.getCode());
Assert.assertNotNull(k.getTaskId());
Assert.assertNotNull(k.getExpireTime());
});
})
.build(),
QATestItem.builder()
.id(BASE_P2_TASK_START_MUL_ID + 2)
.name("对多个IP全部攻击类型进行清洗")
.priority(TestPriority.P2_PRIORITY)
.urlPath("/task/startDispose")
.method(RequestMethod.POST)
.caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":0," +
"\"disposeObjects\":[{\"disposeObject\":\"192.168.50.4\", \"objectType\": 1, \"areaCode\": 0}," +
"{\"disposeObject\":\"192.168.50.3\", \"objectType\": 1, \"areaCode\": 0}],\"disposeTime\":10," +
"\"flowDirection\":2}}")
.rspClass(DisposeTaskStartRsp.class)
.rspCode(ErrorCode.ERR_OK)
.autoLogin(true)
.verifyCallback((VerifyProtoRespCallback<DisposeTaskStartRsp>) (v, e, c) -> {
Assert.assertNotNull(v);
Assert.assertNotNull(v.getMsgContent());
Assert.assertEquals((long) v.getCode(), e.getHttpCode());
Assert.assertNotNull(v.getMsgContent().getItems());
v.getMsgContent().getItems().forEach(k -> {
Assert.assertNotNull(k.getDisposeObject());
Assert.assertEquals((long) k.getStatus(), e.getCode());
Assert.assertNotNull(k.getTaskId());
Assert.assertNotNull(k.getExpireTime());
});
})
.build(),
QATestItem.builder()
.id(BASE_P2_TASK_START_MUL_ID + 3)
.name("对多个IPV6指定攻击类型进行清洗")
.priority(TestPriority.P2_PRIORITY)
.urlPath("/task/startDispose")
.method(RequestMethod.POST)
.caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":0," +
"\"disposeObjects\":[{\"disposeObject\":\"ABCD:EF01:2345:6789:ABCD:EF01:2345:6789\", \"objectType\": 1, \"areaCode\": 0}," +
"{\"disposeObject\":\"ABCD:EF01:2345:6789:ABCD:EF01:2345:1234\", \"objectType\": 1, \"areaCode\": 0}]," +
"\"disposeTime\":10,\"flowDirection\":2, \"attackType\":[1,2,3,4,5]}}")
.rspClass(DisposeTaskStartRsp.class)
.rspCode(ErrorCode.ERR_OK)
.autoLogin(true)
.verifyCallback((VerifyProtoRespCallback<DisposeTaskStartRsp>) (v, e, c) -> {
Assert.assertNotNull(v);
Assert.assertNotNull(v.getMsgContent());
Assert.assertEquals((long) v.getCode(), e.getHttpCode());
Assert.assertNotNull(v.getMsgContent().getItems());
v.getMsgContent().getItems().forEach(k -> {
Assert.assertNotNull(k.getDisposeObject());
Assert.assertEquals((long) k.getStatus(), e.getCode());
Assert.assertNotNull(k.getTaskId());
Assert.assertNotNull(k.getExpireTime());
});
})
.build(),
QATestItem.builder()
.id(BASE_P2_TASK_START_MUL_ID + 4)
.name("对多个IPV6全部攻击类型进行清洗")
.priority(TestPriority.P2_PRIORITY)
.urlPath("/task/startDispose")
.method(RequestMethod.POST)
.caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":0," +
"\"disposeObjects\":[{\"disposeObject\":\"ABCD:EF01:2345:6789:ABCD:EF01:2345:6789\", \"objectType\": 1, \"areaCode\": 0}," +
"{\"disposeObject\":\"ABCD:EF01:2345:6789:ABCD:EF01:2345:1234\", \"objectType\": 1, \"areaCode\": 0}]," +
"\"disposeTime\":10,\"flowDirection\":2, \"attackType\":[-1]}}")
.rspClass(DisposeTaskStartRsp.class)
.rspCode(ErrorCode.ERR_OK)
.autoLogin(true)
.verifyCallback((VerifyProtoRespCallback<DisposeTaskStartRsp>) (v, e, c) -> {
Assert.assertNotNull(v);
Assert.assertNotNull(v.getMsgContent());
Assert.assertEquals((long) v.getCode(), e.getHttpCode());
Assert.assertNotNull(v.getMsgContent().getItems());
v.getMsgContent().getItems().forEach(k -> {
Assert.assertNotNull(k.getDisposeObject());
Assert.assertEquals((long) k.getStatus(), e.getCode());
Assert.assertNotNull(k.getTaskId());
Assert.assertNotNull(k.getExpireTime());
});
})
.build(),
QATestItem.builder()
.id(BASE_P2_TASK_START_MUL_ID + 5)
.name("对IPV4和IPV6进行清洗")
.priority(TestPriority.P2_PRIORITY)
.urlPath("/task/startDispose")
.method(RequestMethod.POST)
.caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":0," +
"\"disposeObjects\":[{\"disposeObject\":\"192.168.50.4\", \"objectType\": 1, \"areaCode\": 0}," +
"{\"disposeObject\":\"ABCD:EF01:2345:6789:ABCD:EF01:2345:1234\", \"objectType\": 1, \"areaCode\": 0}]," +
"\"disposeTime\":10,\"flowDirection\":2, \"attackType\":[-1]}}")
.rspClass(DisposeTaskStartRsp.class)
.rspCode(ErrorCode.ERR_OK)
.autoLogin(true)
.verifyCallback((VerifyProtoRespCallback<DisposeTaskStartRsp>) (v, e, c) -> {
Assert.assertNotNull(v);
Assert.assertNotNull(v.getMsgContent());
Assert.assertEquals((long) v.getCode(), e.getHttpCode());
Assert.assertNotNull(v.getMsgContent().getItems());
v.getMsgContent().getItems().forEach(k -> {
Assert.assertNotNull(k.getDisposeObject());
Assert.assertEquals((long) k.getStatus(), e.getCode());
Assert.assertNotNull(k.getTaskId());
Assert.assertNotNull(k.getExpireTime());
});
})
.build(),
QATestItem.builder()
.id(BASE_P2_TASK_START_MUL_ID + 6)
.name("对多个IP入向进行清洗")
.priority(TestPriority.P2_PRIORITY)
.urlPath("/task/startDispose")
.method(RequestMethod.POST)
.caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":0," +
"\"disposeObjects\":[{\"disposeObject\":\"192.168.50.4\", \"objectType\": 1, \"areaCode\": 0}," +
"{\"disposeObject\":\"192.168.50.3\", \"objectType\": 1, \"areaCode\": 0}],\"disposeTime\":10," +
"\"flowDirection\":0,\"attackType\":[-1]}}")
.rspClass(DisposeTaskStartRsp.class)
.rspCode(ErrorCode.ERR_OK)
.autoLogin(true)
.verifyCallback((VerifyProtoRespCallback<DisposeTaskStartRsp>) (v, e, c) -> {
Assert.assertNotNull(v);
Assert.assertNotNull(v.getMsgContent());
Assert.assertEquals((long) v.getCode(), e.getHttpCode());
Assert.assertNotNull(v.getMsgContent().getItems());
v.getMsgContent().getItems().forEach(k -> {
Assert.assertNotNull(k.getDisposeObject());
Assert.assertEquals((long) k.getStatus(), e.getCode());
Assert.assertNotNull(k.getTaskId());
Assert.assertNotNull(k.getExpireTime());
});
})
.build(),
QATestItem.builder()
.id(BASE_P2_TASK_START_MUL_ID + 7)
.name("对多个IP出向进行清洗")
.priority(TestPriority.P2_PRIORITY)
.urlPath("/task/startDispose")
.method(RequestMethod.POST)
.caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":0," +
"\"disposeObjects\":[{\"disposeObject\":\"192.168.50.4\", \"objectType\": 1, \"areaCode\": 0}," +
"{\"disposeObject\":\"192.168.50.3\", \"objectType\": 1, \"areaCode\": 0}],\"disposeTime\":10," +
"\"flowDirection\":1,\"attackType\":[-1]}}")
.rspClass(DisposeTaskStartRsp.class)
.rspCode(ErrorCode.ERR_OK)
.autoLogin(true)
.verifyCallback((VerifyProtoRespCallback<DisposeTaskStartRsp>) (v, e, c) -> {
Assert.assertNotNull(v);
Assert.assertNotNull(v.getMsgContent());
Assert.assertEquals((long) v.getCode(), e.getHttpCode());
Assert.assertNotNull(v.getMsgContent().getItems());
v.getMsgContent().getItems().forEach(k -> {
Assert.assertNotNull(k.getDisposeObject());
Assert.assertEquals((long) k.getStatus(), e.getCode());
Assert.assertNotNull(k.getTaskId());
Assert.assertNotNull(k.getExpireTime());
});
})
.build(),
QATestItem.builder()
.id(BASE_P2_TASK_START_MUL_ID + 8)
.name("对多个IP进行高防处置")
.priority(TestPriority.P2_PRIORITY)
.urlPath("/task/startDispose")
.method(RequestMethod.POST)
.caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":2," +
"\"disposeObjects\":[{\"disposeObject\":\"192.168.50.4\", \"objectType\": 1, \"areaCode\": 0}," +
"{\"disposeObject\":\"192.168.50.3\", \"objectType\": 1, \"areaCode\": 0}],\"disposeTime\":10," +
"\"flowDirection\":2,\"attackType\":[-1]}}")
.rspClass(DisposeTaskStartRsp.class)
.rspCode(ErrorCode.ERR_OK)
.autoLogin(true)
.verifyCallback((VerifyProtoRespCallback<DisposeTaskStartRsp>) (v, e, c) -> {
Assert.assertNotNull(v);
Assert.assertNotNull(v.getMsgContent());
Assert.assertEquals((long) v.getCode(), e.getHttpCode());
Assert.assertNotNull(v.getMsgContent().getItems());
v.getMsgContent().getItems().forEach(k -> {
Assert.assertNotNull(k.getDisposeObject());
Assert.assertEquals((long) k.getStatus(), e.getCode());
Assert.assertNotNull(k.getTaskId());
Assert.assertNotNull(k.getExpireTime());
});
})
.build(),
QATestItem.builder()
.id(BASE_P2_TASK_START_MUL_ID + 9)
.name("对多个IP进行压制处置")
.priority(TestPriority.P2_PRIORITY)
.urlPath("/task/startDispose")
.method(RequestMethod.POST)
.caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":1," +
"\"disposeObjects\":[{\"disposeObject\":\"192.168.50.4\", \"objectType\": 1, \"areaCode\": 0}," +
"{\"disposeObject\":\"192.168.50.3\", \"objectType\": 1, \"areaCode\": 0}],\"disposeTime\":10," +
"\"flowDirection\":2,\"attackType\":[1,2,3,4,5]}}")
.rspClass(DisposeTaskStartRsp.class)
.rspCode(ErrorCode.ERR_OK)
.autoLogin(true)
.verifyCallback((VerifyProtoRespCallback<DisposeTaskStartRsp>) (v, e, c) -> {
Assert.assertNotNull(v);
Assert.assertNotNull(v.getMsgContent());
Assert.assertEquals((long) v.getCode(), e.getHttpCode());
Assert.assertNotNull(v.getMsgContent().getItems());
v.getMsgContent().getItems().forEach(k -> {
Assert.assertNotNull(k.getDisposeObject());
Assert.assertEquals((long) k.getStatus(), e.getCode());
Assert.assertNotNull(k.getTaskId());
Assert.assertNotNull(k.getExpireTime());
});
})
.build(),
QATestItem.builder()
.id(BASE_P2_TASK_START_MUL_ID + 10)
.name("对多个IP进行检测处置")
.priority(TestPriority.P2_PRIORITY)
.urlPath("/task/startDispose")
.method(RequestMethod.POST)
.caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":3," +
"\"disposeObjects\":[{\"disposeObject\":\"192.168.50.4\", \"objectType\": 1, \"areaCode\": 0}," +
"{\"disposeObject\":\"192.168.50.3\", \"objectType\": 1, \"areaCode\": 0}],\"disposeTime\":10," +
"\"flowDirection\":2,\"attackType\":[1,2,3,4,5]}}")
.rspClass(DisposeTaskStartRsp.class)
.rspCode(ErrorCode.ERR_OK)
.autoLogin(true)
.verifyCallback((VerifyProtoRespCallback<DisposeTaskStartRsp>) (v, e, c) -> {
Assert.assertNotNull(v);
Assert.assertNotNull(v.getMsgContent());
Assert.assertEquals((long) v.getCode(), e.getHttpCode());
Assert.assertNotNull(v.getMsgContent().getItems());
v.getMsgContent().getItems().forEach(k -> {
Assert.assertNotNull(k.getDisposeObject());
Assert.assertEquals((long) k.getStatus(), e.getCode());
Assert.assertNotNull(k.getTaskId());
Assert.assertNotNull(k.getExpireTime());
});
})
.build(),
QATestItem.builder()
.id(BASE_P2_TASK_START_MUL_ID + 11)
.name("msgContent为空")
.priority(TestPriority.P2_PRIORITY)
.urlPath("/task/startDispose")
.method(RequestMethod.POST)
.caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":}")
.rspClass(TaskStartMulRsp.class)
.rspCode(ErrorCode.ERR_PARAMEXCEPTION)
.autoLogin(true)
.verifyCallback(P2TaskStartDispose::verifyJsonExceptionResp)
.build(),
QATestItem.builder()
.id(BASE_P2_TASK_START_MUL_ID + 12)
.name("type为null")
.priority(TestPriority.P2_PRIORITY)
.urlPath("/task/startDispose")
.method(RequestMethod.POST)
.caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":null," +
"\"disposeObjects\":[{\"disposeObject\":\"192.168.50.4\", \"objectType\": 1, \"areaCode\": 0}," +
"{\"disposeObject\":\"192.168.50.3\", \"objectType\": 1, \"areaCode\": 0}],\"disposeTime\":10," +
"\"flowDirection\":2,\"attackType\":[-1]}}")
.rspClass(TaskStartMulRsp.class)
.rspCode(ErrorCode.ERR_PARAMEXCEPTION)
.autoLogin(true)
.verifyCallback(P2TaskStartDispose::verifyJsonExceptionResp)
.build(),
QATestItem.builder()
.id(BASE_P2_TASK_START_MUL_ID + 13)
.name("type为字符串")
.priority(TestPriority.P2_PRIORITY)
.urlPath("/task/startDispose")
.method(RequestMethod.POST)
.caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":\"0\"," +
"\"disposeObjects\":[{\"disposeObject\":\"192.168.50.4\", \"objectType\": 1, \"areaCode\": 0}," +
"{\"disposeObject\":\"192.168.50.3\", \"objectType\": 1, \"areaCode\": 0}],\"disposeTime\":10," +
"\"flowDirection\":2,\"attackType\":[-1]}}")
.rspClass(TaskStartMulRsp.class)
.rspCode(ErrorCode.ERR_PARAMEXCEPTION)
.autoLogin(true)
.verifyCallback(P2TaskStartDispose::verifyJsonExceptionResp)
.build(),
QATestItem.builder()
.id(BASE_P2_TASK_START_MUL_ID + 14)
.name("disposeObjects为null")
.priority(TestPriority.P2_PRIORITY)
.urlPath("/task/startDispose")
.method(RequestMethod.POST)
.caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":0," +
"\"disposeObjects\":null,\"disposeTime\":10," +
"\"flowDirection\":2,\"attackType\":[-1]}}")
.rspClass(TaskStartMulRsp.class)
.rspCode(ErrorCode.ERR_PARAMEXCEPTION)
.autoLogin(true)
.verifyCallback(P2TaskStartDispose::verifyJsonExceptionResp)
.build(),
QATestItem.builder()
.id(BASE_P2_TASK_START_MUL_ID + 15)
.name("disposeTime为null")
.priority(TestPriority.P2_PRIORITY)
.urlPath("/task/startDispose")
.method(RequestMethod.POST)
.caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":0," +
"\"disposeObjects\":[{\"disposeObject\":\"192.168.50.4\", \"objectType\": 1, \"areaCode\": 0}," +
"{\"disposeObject\":\"192.168.50.3\", \"objectType\": 1, \"areaCode\": 0}],\"disposeTime\":null," +
"\"flowDirection\":2,\"attackType\":[-1]}}")
.rspClass(TaskStartMulRsp.class)
.rspCode(ErrorCode.ERR_PARAMEXCEPTION)
.autoLogin(true)
.verifyCallback(P2TaskStartDispose::verifyJsonExceptionResp)
.build(),
QATestItem.builder()
.id(BASE_P2_TASK_START_MUL_ID + 16)
.name("disposeTime为字符串")
.priority(TestPriority.P2_PRIORITY)
.urlPath("/task/startDispose")
.method(RequestMethod.POST)
.caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":0," +
"\"disposeObjects\":[{\"disposeObject\":\"192.168.50.4\", \"objectType\": 1, \"areaCode\": 0}," +
"{\"disposeObject\":\"192.168.50.3\", \"objectType\": 1, \"areaCode\": 0}],\"disposeTime\":\"10\"," +
"\"flowDirection\":2,\"attackType\":[-1]}}")
.rspClass(TaskStartMulRsp.class)
.rspCode(ErrorCode.ERR_PARAMEXCEPTION)
.autoLogin(true)
.verifyCallback(P2TaskStartDispose::verifyJsonExceptionResp)
.build(),
};
/**
* Get test case qa test item [ ].
*
* @return the qa test item [ ]
*/
public static QATestItem[] getTestCase() {
return testItemArray;
}
/**
* Verify json exception resp.
*
* @param v the v
* @param e the e
* @param c the c
*/
private static void verifyJsonExceptionResp(ProtocolRespDTO<? extends BaseRespStatus> v, ErrorCode e,
TestCaseRun c) {
Assert.assertNotNull(v);
Assert.assertNotNull(v.getMsgContent());
Assert.assertEquals((long) v.getCode(), e.getHttpCode());
Assert.assertEquals((long) v.getMsgContent().getStatus(), e.getCode());
}
}