OCT
REM: 1. 重命名数据库task_info表为device_task 2. 重构task_info相关Mapper,Manager,Service,xml名称 3. 增加设备任务创建功能 4. 增加部分设备任务启动管理功能
This commit is contained in:
parent
f001a397dd
commit
98729d6735
|
@ -40,6 +40,21 @@ public interface DisposeAbility {
|
|||
@Nullable DDoSAttackType[] attackType,
|
||||
@Nullable Long duration);
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
MulReturnType<ErrorCode, Long> runDispose(String ip, DisposeCapacityType capType,
|
||||
@Nullable NetflowDirection nfDirection,
|
||||
@Nullable DDoSAttackType attackType,
|
||||
@Nullable Long duration);
|
||||
|
||||
/**
|
||||
* Stop dispose mul return type.
|
||||
*
|
||||
|
@ -55,6 +70,22 @@ public interface DisposeAbility {
|
|||
@Nullable DDoSAttackType[] attackType,
|
||||
@Nullable Long taskId);
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
MulReturnType<ErrorCode, Long> stopDispose(String ip, DisposeCapacityType capType,
|
||||
@Nullable NetflowDirection nfDirection,
|
||||
@Nullable DDoSAttackType attackType,
|
||||
@Nullable Long taskId);
|
||||
|
||||
/**
|
||||
* Gets ability device fireware.
|
||||
*
|
||||
|
@ -62,6 +93,13 @@ public interface DisposeAbility {
|
|||
*/
|
||||
MulReturnType<ErrorCode, DeviceFirewareInfo> getAbilityDeviceFireware();
|
||||
|
||||
/**
|
||||
* To device attack type long.
|
||||
*
|
||||
* @param ddosAttackTypeMask the ddos attack type mask
|
||||
* @return the long
|
||||
*/
|
||||
Long toDeviceAttackType(Long ddosAttackTypeMask);
|
||||
|
||||
/**
|
||||
* Gets device link status.
|
||||
|
|
|
@ -10,6 +10,7 @@ import com.dispose.common.NetflowDirection;
|
|||
import com.dispose.pojo.po.MulReturnType;
|
||||
import com.dispose.pojo.vo.DeviceFirewareInfo;
|
||||
import com.dptech.dispose.AbnormalFlowCleaningServicePortType;
|
||||
import com.dptech.dispose.NtcRequestResultInfo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.cxf.endpoint.Client;
|
||||
import org.apache.cxf.frontend.ClientProxy;
|
||||
|
@ -139,6 +140,42 @@ public class DpTechAbilityImpl implements DisposeAbility {
|
|||
return new MulReturnType<>(err, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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,
|
||||
NetflowDirection nfDirection,
|
||||
DDoSAttackType attackType,
|
||||
Long duration) {
|
||||
ErrorCode err = ErrorCode.ERR_OK;
|
||||
|
||||
try {
|
||||
log.info("++++Begging DPTech Start Cleanup Task: {}, {}, {} ", ip, attackType, nfDirection);
|
||||
|
||||
NtcRequestResultInfo ret = cleanTypePort.startAbnormalTaskForUMC(ip, attackType.getValue(),
|
||||
nfDirection.getValue());
|
||||
|
||||
if (ret.getResultRetVal() != 0) {
|
||||
err = ErrorCode.ERR_CALLDEVICE;
|
||||
} else {
|
||||
log.error("----Finish DPTech Start Cleanup Task: {} status {}", ip, err);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
err = ErrorCode.ERR_SYSTEMEXCEPTION;
|
||||
log.error("----Exception Error DPTech Start Cleanup Task: {}", ip);
|
||||
}
|
||||
|
||||
return new MulReturnType<>(err, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop dispose mul return type.
|
||||
*
|
||||
|
@ -193,6 +230,44 @@ public class DpTechAbilityImpl implements DisposeAbility {
|
|||
return new MulReturnType<>(err, 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,
|
||||
NetflowDirection nfDirection,
|
||||
DDoSAttackType attackType,
|
||||
Long taskId) {
|
||||
ErrorCode err = ErrorCode.ERR_OK;
|
||||
|
||||
try {
|
||||
log.info("++++Begging DPTech Stop Cleanup Task: {}, {}, {} ", ip, attackType, nfDirection);
|
||||
|
||||
NtcRequestResultInfo ret = cleanTypePort.stopAbnormalTaskForUMC(ip, attackType.getValue(),
|
||||
nfDirection.getValue());
|
||||
|
||||
if (ret.getResultRetVal() != 0) {
|
||||
err = ErrorCode.ERR_CALLDEVICE;
|
||||
log.error("----Finish DPTech Stop Cleanup Task: {} status {}", ip, err);
|
||||
} else {
|
||||
log.info("----Finish DPTech Stop Cleanup Task: {} status {}", ip, err);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
err = ErrorCode.ERR_SYSTEMEXCEPTION;
|
||||
log.error("----Exception Error DPTech Stop Cleanup Task: {}", ip);
|
||||
}
|
||||
|
||||
return new MulReturnType<>(err, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets device link status.
|
||||
*
|
||||
|
@ -232,4 +307,15 @@ public class DpTechAbilityImpl implements DisposeAbility {
|
|||
.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 DpTechAttackType.formDdosAttackTypeMaks(ddosAttackTypeMask);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,6 +64,27 @@ public class HaoHanAbilityImpl implements DisposeAbility {
|
|||
@Nullable NetflowDirection[] nfDirection,
|
||||
@Nullable DDoSAttackType[] attackType,
|
||||
@Nullable Long duration) {
|
||||
return runDispose(ip, capType,
|
||||
NetflowDirection.DIRECTION_BI,
|
||||
DDoSAttackType.ALL_ATTACKS,
|
||||
duration);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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为不限制处置时间
|
||||
|
@ -103,6 +124,27 @@ public class HaoHanAbilityImpl implements DisposeAbility {
|
|||
@Nullable NetflowDirection[] nfDirection,
|
||||
@Nullable DDoSAttackType[] attackType,
|
||||
@Nullable Long taskId) {
|
||||
return stopDispose(ip, capType,
|
||||
NetflowDirection.DIRECTION_BI,
|
||||
DDoSAttackType.ALL_ATTACKS,
|
||||
taskId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
|
@ -153,4 +195,15 @@ public class HaoHanAbilityImpl implements DisposeAbility {
|
|||
.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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,6 +46,23 @@ public class VirtualAbilityImpl implements DisposeAbility {
|
|||
return new MulReturnType<>(ErrorCode.ERR_OK, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
@ -64,6 +81,23 @@ public class VirtualAbilityImpl implements DisposeAbility {
|
|||
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 ability device fireware.
|
||||
*
|
||||
|
@ -95,4 +129,15 @@ public class VirtualAbilityImpl implements DisposeAbility {
|
|||
public boolean getDeviceLinkStatus() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* To device attack type long.
|
||||
*
|
||||
* @param ddosAttackTypeMask the ddos attack type mask
|
||||
* @return the long
|
||||
*/
|
||||
@Override
|
||||
public Long toDeviceAttackType(Long ddosAttackTypeMask) {
|
||||
return ddosAttackTypeMask;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.dispose.common;
|
|||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -262,6 +263,24 @@ public enum DDoSAttackType implements BaseEnum {
|
|||
return mask;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mask to ddos attack type list.
|
||||
*
|
||||
* @param attackTypeMask the attack type mask
|
||||
* @return the list
|
||||
*/
|
||||
public static List<DDoSAttackType> maskToDdosAttackType(Long attackTypeMask) {
|
||||
List<DDoSAttackType> attackTypes = new ArrayList<>();
|
||||
|
||||
for(DDoSAttackType t : DDoSAttackType.values()) {
|
||||
if((((long)1 << t.getValue()) & attackTypeMask) != 0) {
|
||||
attackTypes.add(t);
|
||||
}
|
||||
}
|
||||
|
||||
return attackTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets value.
|
||||
*
|
||||
|
|
|
@ -27,6 +27,8 @@ public enum DisposeTaskStatus implements BaseEnum {
|
|||
* Task canceled task status.
|
||||
*/
|
||||
TASK_CANCELED(4, "用户中止"),
|
||||
|
||||
TASK_EXPIRED(5, "过期"),
|
||||
;
|
||||
|
||||
/**
|
||||
|
|
|
@ -96,6 +96,19 @@ public enum DpTechAttackType implements BaseEnum {
|
|||
return mask;
|
||||
}
|
||||
|
||||
/**
|
||||
* Form ddos attack type maks long.
|
||||
*
|
||||
* @param ddosAttackMask the ddos attack mask
|
||||
* @return the long
|
||||
*/
|
||||
public static Long formDdosAttackTypeMaks(Long ddosAttackMask) {
|
||||
return getTypeMaskFromAttackType(DDoSAttackType.maskToDdosAttackType(ddosAttackMask)
|
||||
.stream()
|
||||
.flatMap(DpTechAttackType::fromDdosAttackTypeValue)
|
||||
.distinct().toArray(DpTechAttackType[]::new));
|
||||
}
|
||||
|
||||
/**
|
||||
* From ddos attack type value stream.
|
||||
*
|
||||
|
|
|
@ -94,7 +94,6 @@ public enum ErrorCode {
|
|||
* The Err paramexception.
|
||||
*/
|
||||
ERR_PARAMEXCEPTION(21, "参数异常"),
|
||||
|
||||
/**
|
||||
* The Err devicelocked.
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package com.dispose.manager;
|
||||
|
||||
import com.dispose.common.DisposeTaskStatus;
|
||||
import com.dispose.pojo.entity.DeviceTask;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The interface Task info manager.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public interface DeviceTaskManager {
|
||||
/**
|
||||
* Add dispose device task info boolean.
|
||||
*
|
||||
* @param taskId the task id
|
||||
* @param deviceId the device id
|
||||
* @param attackTypeMask the attack type mask
|
||||
* @return the boolean
|
||||
*/
|
||||
boolean addDisposeDeviceTaskInfo(Long taskId, Long deviceId, Long attackTypeMask);
|
||||
|
||||
/**
|
||||
* Gets new dispose device task info.
|
||||
*
|
||||
* @return the new dispose device task info
|
||||
*/
|
||||
List<DeviceTask> getNewDisposeDeviceTaskInfo();
|
||||
|
||||
/**
|
||||
* Change dispose device task info status boolean.
|
||||
*
|
||||
* @param id the id
|
||||
* @param status the status
|
||||
* @return the boolean
|
||||
*/
|
||||
boolean changeDisposeDeviceTaskInfoStatus(Long id, DisposeTaskStatus status);
|
||||
}
|
|
@ -3,8 +3,8 @@ package com.dispose.manager;
|
|||
import com.dispose.common.DisposeCapacityType;
|
||||
import com.dispose.common.DisposeTaskStatus;
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.pojo.entity.DeviceTask;
|
||||
import com.dispose.pojo.entity.DisposeTask;
|
||||
import com.dispose.pojo.entity.TaskInfo;
|
||||
import com.dispose.pojo.po.MulReturnType;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -20,7 +20,7 @@ public interface DisposeTaskManager {
|
|||
*
|
||||
* @return the unfinished task
|
||||
*/
|
||||
List<TaskInfo> getUnfinishedTask();
|
||||
List<DeviceTask> getUnfinishedTask();
|
||||
|
||||
/**
|
||||
* Create new task mul return type.
|
||||
|
@ -37,7 +37,7 @@ public interface DisposeTaskManager {
|
|||
* @param taskInfo the task info
|
||||
* @return the mul return type
|
||||
*/
|
||||
MulReturnType<ErrorCode, Long> addTaskInfo(Long taskId, TaskInfo taskInfo);
|
||||
MulReturnType<ErrorCode, Long> addTaskInfo(Long taskId, DeviceTask taskInfo);
|
||||
|
||||
/**
|
||||
* Sets dispose task status.
|
||||
|
@ -97,12 +97,43 @@ public interface DisposeTaskManager {
|
|||
void setAttackTypeMaskStatus(Long taskId, Long mask);
|
||||
|
||||
/**
|
||||
* Gets task status.
|
||||
* Dispose ip running boolean.
|
||||
*
|
||||
* @param deviceId the device id
|
||||
* @param disposeIp the dispose ip
|
||||
* @param capType the cap type
|
||||
* @return the task status
|
||||
* @return the boolean
|
||||
*/
|
||||
boolean disposeIpRunning(Long deviceId, String disposeIp, DisposeCapacityType capType);
|
||||
|
||||
/**
|
||||
* Gets expired tasks.
|
||||
*
|
||||
* @return the expired tasks
|
||||
*/
|
||||
List<DisposeTask> getExpiredTasks();
|
||||
|
||||
/**
|
||||
* Gets new dispose tasks.
|
||||
*
|
||||
* @return the new dispose tasks
|
||||
*/
|
||||
List<DisposeTask> getNewDisposeTasks();
|
||||
|
||||
/**
|
||||
* Change dispose task status boolean.
|
||||
*
|
||||
* @param taskId the task id
|
||||
* @param status the status
|
||||
* @return the boolean
|
||||
*/
|
||||
boolean changeDisposeTaskStatus(Long taskId, DisposeTaskStatus status);
|
||||
|
||||
/**
|
||||
* Gets dispose task by id.
|
||||
*
|
||||
* @param taskId the task id
|
||||
* @return the dispose task by id
|
||||
*/
|
||||
DisposeTask getDisposeTaskById(Long taskId);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
package com.dispose.manager.impl;
|
||||
|
||||
import com.dispose.common.DisposeTaskStatus;
|
||||
import com.dispose.manager.DeviceTaskManager;
|
||||
import com.dispose.mapper.DeviceTaskMapper;
|
||||
import com.dispose.pojo.entity.DeviceTask;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The type Task info manager.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class DeviceTaskManagerImpl implements DeviceTaskManager {
|
||||
/**
|
||||
* The Task info mapper.
|
||||
*/
|
||||
@Resource
|
||||
private DeviceTaskMapper deviceTaskMapper;
|
||||
|
||||
/**
|
||||
* Add dispose device task info boolean.
|
||||
*
|
||||
* @param taskId the task id
|
||||
* @param deviceId the device id
|
||||
* @param attackTypeMask the attack type mask
|
||||
* @return the boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean addDisposeDeviceTaskInfo(Long taskId, Long deviceId, Long attackTypeMask) {
|
||||
// 如果已经存在相同任务,不再添加重复任务
|
||||
if (deviceTaskMapper.getTaskByDetails(taskId, deviceId, attackTypeMask).size() != 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return deviceTaskMapper.addNewTaskInfo(DeviceTask.builder()
|
||||
.taskId(taskId)
|
||||
.deviceId(deviceId)
|
||||
.taskAttackType(attackTypeMask)
|
||||
.build()) == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets new dispose device task info.
|
||||
*
|
||||
* @return the new dispose device task info
|
||||
*/
|
||||
@Override
|
||||
public List<DeviceTask> getNewDisposeDeviceTaskInfo() {
|
||||
return deviceTaskMapper.getNewTaskInfos();
|
||||
}
|
||||
|
||||
/**
|
||||
* Change dispose device task info status boolean.
|
||||
*
|
||||
* @param id the id
|
||||
* @param status the status
|
||||
* @return the boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean changeDisposeDeviceTaskInfoStatus(Long id, DisposeTaskStatus status) {
|
||||
return deviceTaskMapper.changeTaskStatus(id, status) == 1;
|
||||
}
|
||||
}
|
|
@ -4,11 +4,13 @@ import com.dispose.common.DisposeCapacityType;
|
|||
import com.dispose.common.DisposeTaskStatus;
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.manager.DisposeTaskManager;
|
||||
import com.dispose.mapper.DeviceTaskMapper;
|
||||
import com.dispose.mapper.DisposeTaskMapper;
|
||||
import com.dispose.mapper.TaskInfoMapper;
|
||||
import com.dispose.pojo.entity.DeviceTask;
|
||||
import com.dispose.pojo.entity.DisposeTask;
|
||||
import com.dispose.pojo.entity.TaskInfo;
|
||||
import com.dispose.pojo.po.MulReturnType;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
@ -18,6 +20,8 @@ import java.util.List;
|
|||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class DisposeTaskManagerImpl implements DisposeTaskManager {
|
||||
/**
|
||||
* The Dispose task mapper.
|
||||
|
@ -29,7 +33,7 @@ public class DisposeTaskManagerImpl implements DisposeTaskManager {
|
|||
* The Task info mapper.
|
||||
*/
|
||||
@Resource
|
||||
private TaskInfoMapper taskInfoMapper;
|
||||
private DeviceTaskMapper deviceTaskMapper;
|
||||
|
||||
/**
|
||||
* Create new task mul return type.
|
||||
|
@ -50,7 +54,7 @@ public class DisposeTaskManagerImpl implements DisposeTaskManager {
|
|||
* @return the mul return type
|
||||
*/
|
||||
@Override
|
||||
public MulReturnType<ErrorCode, Long> addTaskInfo(Long taskId, TaskInfo taskInfo) {
|
||||
public MulReturnType<ErrorCode, Long> addTaskInfo(Long taskId, DeviceTask taskInfo) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -60,7 +64,7 @@ public class DisposeTaskManagerImpl implements DisposeTaskManager {
|
|||
* @return the unfinished task
|
||||
*/
|
||||
@Override
|
||||
public List<TaskInfo> getUnfinishedTask() {
|
||||
public List<DeviceTask> getUnfinishedTask() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -152,8 +156,51 @@ public class DisposeTaskManagerImpl implements DisposeTaskManager {
|
|||
*/
|
||||
@Override
|
||||
public boolean disposeIpRunning(Long deviceId, String disposeIp, DisposeCapacityType capType) {
|
||||
List<DisposeTask> taskList = disposeTaskMapper.getRunDisposeTask(deviceId, capType, disposeIp);
|
||||
List<DisposeTask> taskList = disposeTaskMapper.getRunningTask(deviceId, capType, disposeIp);
|
||||
|
||||
return (taskList != null && taskList.size() > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets expired tasks.
|
||||
*
|
||||
* @return the expired tasks
|
||||
*/
|
||||
@Override
|
||||
public List<DisposeTask> getExpiredTasks() {
|
||||
return disposeTaskMapper.getExpiredTasks();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets new dispose tasks.
|
||||
*
|
||||
* @return the new dispose tasks
|
||||
*/
|
||||
@Override
|
||||
public List<DisposeTask> getNewDisposeTasks() {
|
||||
return disposeTaskMapper.getNewTask();
|
||||
}
|
||||
|
||||
/**
|
||||
* Change dispose task status boolean.
|
||||
*
|
||||
* @param taskId the task id
|
||||
* @param status the status
|
||||
* @return the boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean changeDisposeTaskStatus(Long taskId, DisposeTaskStatus status) {
|
||||
return disposeTaskMapper.changTaskStatus(taskId, status) == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets dispose task by id.
|
||||
*
|
||||
* @param taskId the task id
|
||||
* @return the dispose task by id
|
||||
*/
|
||||
@Override
|
||||
public DisposeTask getDisposeTaskById(Long taskId) {
|
||||
return disposeTaskMapper.getDisposeTaskById(taskId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
package com.dispose.mapper;
|
||||
|
||||
import com.dispose.common.DisposeTaskStatus;
|
||||
import com.dispose.pojo.entity.DeviceTask;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The interface Device task mapper.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public interface DeviceTaskMapper {
|
||||
/**
|
||||
* Select all list.
|
||||
*
|
||||
* @return the list
|
||||
*/
|
||||
List<DeviceTask> selectAll();
|
||||
|
||||
/**
|
||||
* Gets task info by task id.
|
||||
*
|
||||
* @param taskId the task id
|
||||
* @return the task info by task id
|
||||
*/
|
||||
List<DeviceTask> getTaskInfoByTaskId(@Param("taskId") Long taskId);
|
||||
|
||||
/**
|
||||
* Add new task info list int.
|
||||
*
|
||||
* @param taskLists the task lists
|
||||
* @return the int
|
||||
*/
|
||||
int addNewTaskInfoList(@Param("taskLists") List<DeviceTask> taskLists);
|
||||
|
||||
/**
|
||||
* Add new task info int.
|
||||
*
|
||||
* @param taskInfo the task info
|
||||
* @return the int
|
||||
*/
|
||||
int addNewTaskInfo(DeviceTask taskInfo);
|
||||
|
||||
/**
|
||||
* Gets new task infos.
|
||||
*
|
||||
* @return the new task infos
|
||||
*/
|
||||
List<DeviceTask> getNewTaskInfos();
|
||||
|
||||
/**
|
||||
* Gets task by details.
|
||||
*
|
||||
* @param taskId the task id
|
||||
* @param deviceId the device id
|
||||
* @param attackType the attack type
|
||||
* @return the task by details
|
||||
*/
|
||||
List<DeviceTask> getTaskByDetails(@Param("taskId") Long taskId,
|
||||
@Param("deviceId") Long deviceId,
|
||||
@Param("attackType") Long attackType);
|
||||
|
||||
/**
|
||||
* Change task status int.
|
||||
*
|
||||
* @param id the id
|
||||
* @param status the status
|
||||
* @return the int
|
||||
*/
|
||||
int changeTaskStatus(@Param("id") Long id,
|
||||
@Param("status") DisposeTaskStatus status);
|
||||
}
|
|
@ -20,6 +20,14 @@ public interface DisposeTaskMapper {
|
|||
*/
|
||||
List<DisposeTask> selectAll();
|
||||
|
||||
/**
|
||||
* Gets dispose task by id.
|
||||
*
|
||||
* @param taskId the task id
|
||||
* @return the dispose task by id
|
||||
*/
|
||||
DisposeTask getDisposeTaskById(@Param("taskId") Long taskId);
|
||||
|
||||
/**
|
||||
* Add new task int.
|
||||
*
|
||||
|
@ -34,7 +42,7 @@ public interface DisposeTaskMapper {
|
|||
* @param taskId the task id
|
||||
* @return the task status
|
||||
*/
|
||||
DisposeTaskStatus getTaskStatus(@Param("id") Long taskId);
|
||||
DisposeTaskStatus getTaskStatus(@Param("taskId") Long taskId);
|
||||
|
||||
/**
|
||||
* Chang task status int.
|
||||
|
@ -47,14 +55,28 @@ public interface DisposeTaskMapper {
|
|||
@Param("status") DisposeTaskStatus status);
|
||||
|
||||
/**
|
||||
* Gets run dispose task.
|
||||
* Gets running task.
|
||||
*
|
||||
* @param deviceId the device id
|
||||
* @param capType the cap type
|
||||
* @param disposeIp the dispose ip
|
||||
* @return the run dispose task
|
||||
* @return the running task
|
||||
*/
|
||||
List<DisposeTask> getRunDisposeTask(@Param("deviceId") Long deviceId,
|
||||
List<DisposeTask> getRunningTask(@Param("deviceId") Long deviceId,
|
||||
@Param("capType") DisposeCapacityType capType,
|
||||
@Param("disposeIp") String disposeIp);
|
||||
|
||||
/**
|
||||
* Gets new task.
|
||||
*
|
||||
* @return the new task
|
||||
*/
|
||||
List<DisposeTask> getNewTask();
|
||||
|
||||
/**
|
||||
* Gets expired tasks.
|
||||
*
|
||||
* @return the expired tasks
|
||||
*/
|
||||
List<DisposeTask> getExpiredTasks();
|
||||
}
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
package com.dispose.mapper;
|
||||
|
||||
import com.dispose.pojo.entity.TaskInfo;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The interface Task info mapper.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public interface TaskInfoMapper {
|
||||
/**
|
||||
* Select all list.
|
||||
*
|
||||
* @return the list
|
||||
*/
|
||||
List<TaskInfo> selectAll();
|
||||
|
||||
/**
|
||||
* Gets task info by task id.
|
||||
*
|
||||
* @param taskId the task id
|
||||
* @return the task info by task id
|
||||
*/
|
||||
List<TaskInfo> getTaskInfoByTaskId(@Param("taskId") Long taskId);
|
||||
|
||||
/**
|
||||
* Add new task info list int.
|
||||
*
|
||||
* @param taskInfos the task infos
|
||||
* @return the int
|
||||
*/
|
||||
int addNewTaskInfoList(@Param("taskInfos") List<TaskInfo> taskInfos);
|
||||
|
||||
/**
|
||||
* Add new task info int.
|
||||
*
|
||||
* @param taskInfo the task info
|
||||
* @return the int
|
||||
*/
|
||||
int addNewTaskInfo(@Param("taskInfo") TaskInfo taskInfo);
|
||||
}
|
|
@ -25,7 +25,7 @@ import java.io.Serializable;
|
|||
@JsonPropertyOrder(alphabetic = true)
|
||||
@Table(name = "task_info")
|
||||
@NameStyle(Style.normal)
|
||||
public class TaskInfo implements Serializable {
|
||||
public class DeviceTask implements Serializable {
|
||||
/**
|
||||
* The constant serialVersionUID.
|
||||
*/
|
|
@ -92,5 +92,5 @@ public class DisposeTask implements Serializable {
|
|||
/**
|
||||
* The Task info.
|
||||
*/
|
||||
private List<TaskInfo> taskInfo;
|
||||
private List<DeviceTask> deviceTask;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
package com.dispose.service;
|
||||
|
||||
/**
|
||||
* The interface Device task manager service.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public interface DeviceTaskManagerService {
|
||||
/**
|
||||
* Device task manager schedule.
|
||||
*/
|
||||
void deviceTaskManagerSchedule();
|
||||
|
||||
/**
|
||||
* Device task runner schedule.
|
||||
*/
|
||||
void deviceTaskRunnerSchedule();
|
||||
}
|
|
@ -21,6 +21,14 @@ public interface DisposeAbilityRouterService {
|
|||
*/
|
||||
AbilityInfo getAbilityDevice(String ipAddr, String ipPort);
|
||||
|
||||
/**
|
||||
* Gets ability device.
|
||||
*
|
||||
* @param id the id
|
||||
* @return the ability device
|
||||
*/
|
||||
AbilityInfo getAbilityDevice(Long id);
|
||||
|
||||
/**
|
||||
* Gets all ability devices.
|
||||
*
|
||||
|
|
|
@ -0,0 +1,147 @@
|
|||
package com.dispose.service.impl;
|
||||
|
||||
import com.dispose.common.DDoSAttackType;
|
||||
import com.dispose.common.DisposeTaskStatus;
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.common.Helper;
|
||||
import com.dispose.common.NetflowDirection;
|
||||
import com.dispose.manager.DeviceTaskManager;
|
||||
import com.dispose.manager.DisposeTaskManager;
|
||||
import com.dispose.pojo.entity.DisposeTask;
|
||||
import com.dispose.pojo.po.AbilityInfo;
|
||||
import com.dispose.pojo.po.MulReturnType;
|
||||
import com.dispose.service.DeviceTaskManagerService;
|
||||
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.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* The type Device task manager service.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
|
||||
/**
|
||||
* The Dispose task manager.
|
||||
*/
|
||||
@Resource
|
||||
private DisposeTaskManager disposeTaskManager;
|
||||
|
||||
/**
|
||||
* The Task info manager.
|
||||
*/
|
||||
@Resource
|
||||
private DeviceTaskManager deviceTaskManager;
|
||||
|
||||
/**
|
||||
* The Dispose ability router service.
|
||||
*/
|
||||
@Resource
|
||||
private DisposeAbilityRouterService disposeAbilityRouterService;
|
||||
|
||||
/**
|
||||
* Device task manager schedule.
|
||||
*/
|
||||
@Override
|
||||
@Async("deviceTaskExecutor")
|
||||
@Scheduled(fixedDelay = 1000)
|
||||
public void deviceTaskManagerSchedule() {
|
||||
// 清理过期任务
|
||||
disposeTaskManager.getExpiredTasks().forEach(v -> {
|
||||
log.info("Task {} {} {} is expired, expect finished at {}",
|
||||
v.getId(), v.getDisposeCapacity(), v.getDisposeIp(), v.getPlanEndTime());
|
||||
// 设置任务状态,过期任务不再为设备创建处置任务
|
||||
disposeTaskManager.changeDisposeTaskStatus(v.getId(), DisposeTaskStatus.TASK_EXPIRED);
|
||||
});
|
||||
|
||||
// 对新建的任务,创建对应处置设备任务信息
|
||||
disposeTaskManager.getNewDisposeTasks().forEach(v -> {
|
||||
// 设置任务状态, 开始创建任务
|
||||
disposeTaskManager.changeDisposeTaskStatus(v.getId(), DisposeTaskStatus.TASK_STARTING);
|
||||
|
||||
// 为当前所有可用处置设备创建对应的处置任务
|
||||
disposeAbilityRouterService.getAllAbilityDevices().stream()
|
||||
// 判断是否是当前设备的处置任务
|
||||
.filter(f -> v.getDeviceId() == -1 || f.getDev().getId().equals(v.getDeviceId()))
|
||||
// 当前设备是否支持该处置能力
|
||||
.filter(c -> c.getDev().getDevCapacity().stream().anyMatch(m -> m.getCapacityType() == v
|
||||
.getDisposeCapacity()))
|
||||
.forEach(d -> {
|
||||
log.info("Add dispose task for device: {}", d.getDev());
|
||||
|
||||
if (!deviceTaskManager.addDisposeDeviceTaskInfo(v.getId(), d.getDev().getId(),
|
||||
d.getDb().toDeviceAttackType(v.getAttackType()))) {
|
||||
log.error("Add task {} to device {} error", v, d);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Device task runner schedule.
|
||||
*/
|
||||
@Override
|
||||
@Async("deviceTaskExecutor")
|
||||
@Scheduled(fixedDelay = 1000)
|
||||
public void deviceTaskRunnerSchedule() {
|
||||
deviceTaskManager.getNewDisposeDeviceTaskInfo()
|
||||
.forEach(v -> {
|
||||
DisposeTask task = disposeTaskManager.getDisposeTaskById(v.getTaskId());
|
||||
assert task != null;
|
||||
log.info("Run task {}", task);
|
||||
|
||||
AbilityInfo ai = disposeAbilityRouterService.getAbilityDevice(task.getDeviceId());
|
||||
|
||||
switch (ai.getDev().getDeviceType()) {
|
||||
case DPTECH_UMC:
|
||||
break;
|
||||
|
||||
case HAOHAN_PLATFORM:
|
||||
deviceTaskManager.changeDisposeDeviceTaskInfoStatus(v.getId(), DisposeTaskStatus.TASK_STARTING);
|
||||
|
||||
MulReturnType<ErrorCode, Long> ret = ai.getDb().runDispose(task.getDisposeIp(),
|
||||
task.getDisposeCapacity(),
|
||||
NetflowDirection.DIRECTION_BI,
|
||||
DDoSAttackType.ALL_ATTACKS,
|
||||
(long)Helper.getTimestampDiffNow(task.getPlanEndTime()));
|
||||
|
||||
deviceTaskManager.changeDisposeDeviceTaskInfoStatus(v.getId(), DisposeTaskStatus.TASK_STARTED);
|
||||
|
||||
if(ret.getFirstParam() != ErrorCode.ERR_OK) {
|
||||
log.error("HAOHAN_PLATFORM setup task error {}: {}", ret.getFirstParam(), v);
|
||||
} else {
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// if (task != null) {
|
||||
//
|
||||
// CompletableFuture.supplyAsync(() ->
|
||||
// disposeAbilityRouterService
|
||||
// .getAbilityDevice(task.getDeviceId())
|
||||
// .getDb()
|
||||
// .runDispose(task.getDisposeIp(),
|
||||
// task.getDisposeCapacity(),
|
||||
// task.getFlowDirection(),
|
||||
// null,
|
||||
// (long)Helper.getTimestampDiffNow(task.getPlanEndTime())))
|
||||
// .whenComplete((k, ex) -> {
|
||||
//
|
||||
// });
|
||||
// }
|
||||
|
||||
});
|
||||
}
|
||||
}
|
|
@ -59,6 +59,26 @@ public class DisposeAbilityRouterServiceImpl implements DisposeAbilityRouterServ
|
|||
return disposeAbilityMap.get(getAbilityDeviceHashKey(ipAddr, ipPort));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets ability device.
|
||||
*
|
||||
* @param id the id
|
||||
* @return the ability device
|
||||
*/
|
||||
@Override
|
||||
public AbilityInfo getAbilityDevice(Long id) {
|
||||
DisposeDevice dev = disposeDeviceManager.getAllNormalDisposeDevices().parallelStream()
|
||||
.filter(v -> v.getId().equals(id))
|
||||
.findAny()
|
||||
.orElse(null);
|
||||
|
||||
if(dev != null) {
|
||||
return disposeAbilityMap.get(getAbilityDeviceHashKey(dev.getIpAddr(), dev.getIpPort()));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all ability devices.
|
||||
*
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.dispose.mapper.DeviceTaskMapper">
|
||||
<resultMap id="task_info" type="com.dispose.pojo.entity.DeviceTask">
|
||||
<id column="id" property="id"/>
|
||||
<result column="taskId" property="taskId"/>
|
||||
<result column="deviceId" property="deviceId"/>
|
||||
<result column="beginTime" property="beginTime"/>
|
||||
<result column="endTime" property="endTime"/>
|
||||
<result column="taskAttackType" property="taskAttackType"/>
|
||||
<result column="execAttackTypeIn" property="execAttackTypeIn"/>
|
||||
<result column="attackTypeStatusIn" property="attackTypeStatusIn"/>
|
||||
<result column="execAttackTypeOut" property="execAttackTypeOut"/>
|
||||
<result column="attackTypeStatusOut" property="attackTypeStatusOut"/>
|
||||
<result column="externId" property="externId"/>
|
||||
<result column="status" property="status"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="selectAll" resultMap="task_info">
|
||||
SELECT *
|
||||
FROM device_task
|
||||
</select>
|
||||
|
||||
<insert id="addNewTaskInfoList" useGeneratedKeys="true" keyProperty="id"
|
||||
parameterType="com.dispose.pojo.entity.DeviceTask">
|
||||
INSERT IGNORE INTO device_task(taskId, deviceId, taskAttackType, status)
|
||||
VALUES
|
||||
<foreach collection="taskLists" item="task" separator=",">
|
||||
(#{task.taskId}, #{task.deviceId}, #{task.taskAttackType},
|
||||
${@com.dispose.common.DisposeTaskStatus@TASK_NEW.getValue()})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<insert id="addNewTaskInfo" useGeneratedKeys="true" keyProperty="id"
|
||||
parameterType="com.dispose.pojo.entity.DeviceTask">
|
||||
INSERT IGNORE INTO device_task(taskId, deviceId, taskAttackType, status)
|
||||
VALUES (#{taskId}, #{deviceId}, #{taskAttackType},
|
||||
${@com.dispose.common.DisposeTaskStatus@TASK_NEW.getValue()})
|
||||
</insert>
|
||||
|
||||
<select id="getTaskInfoByTaskId" resultMap="task_info">
|
||||
SELECT *
|
||||
FROM device_task
|
||||
WHERE taskId = #{taskId, jdbcType=INTEGER}
|
||||
</select>
|
||||
|
||||
<select id="getNewTaskInfos" resultMap="task_info">
|
||||
SELECT *
|
||||
FROM device_task
|
||||
WHERE status = ${@com.dispose.common.DisposeTaskStatus@TASK_NEW.getValue()}
|
||||
</select>
|
||||
|
||||
<select id="getTaskByDetails" resultMap="task_info">
|
||||
SELECT *
|
||||
FROM device_task
|
||||
WHERE status != ${@com.dispose.common.DisposeTaskStatus@TASK_FINISHED.getValue()}
|
||||
AND status != ${@com.dispose.common.DisposeTaskStatus@TASK_CANCELED.getValue()}
|
||||
AND status != ${@com.dispose.common.DisposeTaskStatus@TASK_EXPIRED.getValue()}
|
||||
AND taskId = #{taskId, jdbcType=INTEGER}
|
||||
AND deviceId = #{deviceId, jdbcType=INTEGER}
|
||||
AND taskAttackType = #{attackType, jdbcType=INTEGER}
|
||||
</select>
|
||||
|
||||
<update id="changeTaskStatus">
|
||||
UPDATE device_task
|
||||
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_EXPIRED">
|
||||
, endTime = CURRENT_TIMESTAMP
|
||||
</if>
|
||||
<if test="status == @com.dispose.common.DisposeTaskStatus@TASK_STARTING">
|
||||
, beginTime = CURRENT_TIMESTAMP
|
||||
</if>
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
</mapper>
|
|
@ -29,7 +29,12 @@
|
|||
|
||||
<select id="selectAll" resultMap="dispose_device">
|
||||
SELECT d.*,
|
||||
c.*
|
||||
c.id c_id,
|
||||
c.deviceId deviceId,
|
||||
c.capacityType capacityType,
|
||||
c.objectType objectType,
|
||||
c.ipType ipType,
|
||||
c.protectIp protectIp
|
||||
FROM dispose_device d
|
||||
LEFT JOIN dispose_capacity c ON d.id = c.deviceId
|
||||
</select>
|
||||
|
|
|
@ -14,39 +14,89 @@
|
|||
<result column="attackType" property="attackType"/>
|
||||
<result column="flowBandWidth" property="flowBandWidth"/>
|
||||
<result column="currentStatus" property="currentStatus" javaType="com.dispose.common.DisposeTaskStatus"/>
|
||||
<collection property="taskInfo" ofType="com.dispose.pojo.entity.TaskInfo">
|
||||
<collection property="deviceTask" ofType="com.dispose.pojo.entity.DeviceTask">
|
||||
<id column="t_id" property="id"/>
|
||||
<result column="taskId" property="taskId"/>
|
||||
<result column="t_deviceId" property="deviceId"/>
|
||||
<result column="beginTime" property="beginTime"/>
|
||||
<result column="t_endTime" property="endTime"/>
|
||||
<result column="taskAttackType" property="execAttackType"/>
|
||||
<result column="execAttackType" property="execAttackType"/>
|
||||
<result column="attackTypeStatus" property="attackTypeStatus"/>
|
||||
<result column="taskAttackType" property="taskAttackType"/>
|
||||
<result column="execAttackTypeIn" property="execAttackTypeIn"/>
|
||||
<result column="attackTypeStatusIn" property="attackTypeStatusIn"/>
|
||||
<result column="execAttackTypeOut" property="execAttackTypeOut"/>
|
||||
<result column="attackTypeStatusOut" property="attackTypeStatusOut"/>
|
||||
<result column="externId" property="externId"/>
|
||||
<result column="status" property="status"/>
|
||||
</collection>
|
||||
</resultMap>
|
||||
|
||||
<select id="selectAll" resultMap="dispose_task">
|
||||
SELECT dt.*, ti.*
|
||||
FROM dispose_task dt LEFT JOIN task_info ti on dt.id = ti.taskId
|
||||
SELECT dt.*,
|
||||
ti.id t_id,
|
||||
ti.taskId taskId,
|
||||
ti.deviceId t_deviceId,
|
||||
ti.beginTime beginTime,
|
||||
ti.endTime t_endTime,
|
||||
ti.taskAttackType taskAttackType,
|
||||
ti.execAttackTypeIn execAttackTypeIn,
|
||||
ti.attackTypeStatusIn attackTypeStatusIn,
|
||||
ti.execAttackTypeOut execAttackTypeOut,
|
||||
ti.attackTypeStatusOut attackTypeStatusOut,
|
||||
ti.externId externId,
|
||||
ti.status status
|
||||
FROM dispose_task dt
|
||||
LEFT JOIN device_task ti on dt.id = ti.taskId
|
||||
</select>
|
||||
|
||||
<select id="getRunDisposeTask" resultMap="dispose_task">
|
||||
<select id="getDisposeTaskById" resultMap="dispose_task">
|
||||
SELECT dt.*,
|
||||
ti.id t_id,
|
||||
ti.taskId taskId,
|
||||
ti.deviceId t_deviceId,
|
||||
ti.beginTime beginTime,
|
||||
ti.endTime t_endTime,
|
||||
ti.taskAttackType taskAttackType,
|
||||
ti.execAttackTypeIn execAttackTypeIn,
|
||||
ti.attackTypeStatusIn attackTypeStatusIn,
|
||||
ti.execAttackTypeOut execAttackTypeOut,
|
||||
ti.attackTypeStatusOut attackTypeStatusOut,
|
||||
ti.externId externId,
|
||||
ti.status status
|
||||
FROM dispose_task dt
|
||||
LEFT JOIN device_task ti on dt.id = ti.taskId
|
||||
AND dt.id = #{taskId}
|
||||
</select>
|
||||
|
||||
<select id="getRunningTask" resultMap="dispose_task">
|
||||
SELECT dt.*, ti.*
|
||||
FROM dispose_task dt LEFT JOIN task_info ti on dt.id = ti.taskId
|
||||
FROM dispose_task dt LEFT JOIN device_task ti on dt.id = ti.taskId
|
||||
WHERE
|
||||
dt.disposeCapacity = #{capType, jdbcType=INTEGER} AND
|
||||
dt.disposeIp = #{disposeIp} AND
|
||||
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.planEndTime > CURRENT_TIMESTAMP()
|
||||
<if test="deviceId != -1">
|
||||
AND dt.deviceId = #{deviceId}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="getNewTask" resultType="com.dispose.pojo.entity.DisposeTask">
|
||||
SELECT *
|
||||
FROM dispose_task
|
||||
WHERE currentStatus = ${@com.dispose.common.DisposeTaskStatus@TASK_NEW.getValue()}
|
||||
</select>
|
||||
|
||||
<select id="getExpiredTasks" resultType="com.dispose.pojo.entity.DisposeTask">
|
||||
SELECT *
|
||||
FROM dispose_task
|
||||
WHERE currentStatus != ${@com.dispose.common.DisposeTaskStatus@TASK_FINISHED.getValue()}
|
||||
AND currentStatus != ${@com.dispose.common.DisposeTaskStatus@TASK_CANCELED.getValue()}
|
||||
AND currentStatus != ${@com.dispose.common.DisposeTaskStatus@TASK_EXPIRED.getValue()}
|
||||
AND CURRENT_TIMESTAMP() >= planEndTime
|
||||
</select>
|
||||
|
||||
<insert id="addNewTask" useGeneratedKeys="true" keyProperty="id"
|
||||
parameterType="com.dispose.pojo.entity.DisposeTask">
|
||||
INSERT IGNORE INTO dispose_task(deviceId, accountId, disposeCapacity, disposeIp,
|
||||
|
@ -63,7 +113,8 @@
|
|||
SET
|
||||
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_CANCELED
|
||||
or status == @com.dispose.common.DisposeTaskStatus@TASK_EXPIRED">
|
||||
, endTime = CURRENT_TIMESTAMP
|
||||
</if>
|
||||
WHERE
|
||||
|
@ -73,7 +124,7 @@
|
|||
<select id="getTaskStatus" resultType="com.dispose.common.DisposeTaskStatus">
|
||||
SELECT currentStatus
|
||||
FROM dispose_task
|
||||
WHERE id = #{id, jdbcType=INTEGER}
|
||||
WHERE id = #{taskId, jdbcType=INTEGER}
|
||||
</select>
|
||||
|
||||
</mapper>
|
|
@ -1,45 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.dispose.mapper.TaskInfoMapper">
|
||||
<resultMap id="task_info" type="com.dispose.pojo.entity.TaskInfo">
|
||||
<id column="id" property="id"/>
|
||||
<result column="taskId" property="taskId"/>
|
||||
<result column="deviceId" property="deviceId"/>
|
||||
<result column="beginTime" property="beginTime"/>
|
||||
<result column="endTime" property="endTime"/>
|
||||
<result column="taskAttackType" property="taskAttackType"/>
|
||||
<result column="execAttackTypeIn" property="execAttackTypeIn"/>
|
||||
<result column="attackTypeStatusIn" property="attackTypeStatusIn"/>
|
||||
<result column="execAttackTypeOut" property="execAttackTypeOut"/>
|
||||
<result column="attackTypeStatusOut" property="attackTypeStatusOut"/>
|
||||
<result column="externId" property="externId"/>
|
||||
<result column="status" property="status"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="selectAll" resultMap="task_info">
|
||||
SELECT *
|
||||
FROM task_info
|
||||
</select>
|
||||
|
||||
<insert id="addNewTaskInfoList" useGeneratedKeys="true" keyProperty="id"
|
||||
parameterType="com.dispose.pojo.entity.TaskInfo">
|
||||
INSERT IGNORE INTO task_info(taskId, deviceId, taskAttackType)
|
||||
VALUES
|
||||
<foreach collection="taskInfos" item="task" separator=",">
|
||||
(#{task.taskId}, #{task.deviceId}, #{task.taskAttackType})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<insert id="addNewTaskInfo" useGeneratedKeys="true" keyProperty="id"
|
||||
parameterType="com.dispose.pojo.entity.TaskInfo">
|
||||
INSERT IGNORE INTO task_info(taskId, deviceId, taskAttackType)
|
||||
VALUES (#{taskId}, #{deviceId}, #{taskAttackType})
|
||||
</insert>
|
||||
|
||||
<select id="getTaskInfoByTaskId" resultMap="task_info">
|
||||
SELECT *
|
||||
FROM task_info
|
||||
WHERE taskId = #{taskId, jdbcType=INTEGER}
|
||||
</select>
|
||||
|
||||
</mapper>
|
|
@ -61,23 +61,15 @@ public class DisposeCapacityMapperTest {
|
|||
public void a1_addNewDisposeCapacity() throws JsonProcessingException {
|
||||
List<DisposeCapacity> newCapList = new ArrayList<>();
|
||||
|
||||
Long deviceId = disposeDeviceMapper.selectAll().get(0).getId();
|
||||
|
||||
disposeDeviceMapper.selectAll().forEach(v -> {
|
||||
newCapList.add(DisposeCapacity.builder()
|
||||
.deviceId(deviceId)
|
||||
.deviceId(v.getId())
|
||||
.capacityType(DisposeCapacityType.CLEANUP)
|
||||
.objectType(DisposeObjectType.IP)
|
||||
.ipType(IpAddrType.IPV4_IPV6)
|
||||
.protectIp("")
|
||||
.build());
|
||||
|
||||
newCapList.add(DisposeCapacity.builder()
|
||||
.deviceId(deviceId)
|
||||
.capacityType(DisposeCapacityType.BLOCKING)
|
||||
.objectType(DisposeObjectType.URL)
|
||||
.ipType(IpAddrType.IPV4_IPV6)
|
||||
.protectIp("")
|
||||
.protectIp("0.0.0.0")
|
||||
.build());
|
||||
});
|
||||
|
||||
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(newCapList));
|
||||
|
||||
|
|
|
@ -17,7 +17,9 @@ import org.junit.Test;
|
|||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.MethodSorters;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.annotation.Rollback;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
@ -31,6 +33,8 @@ import java.util.List;
|
|||
@SpringBootTest
|
||||
@Slf4j
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
@Transactional
|
||||
@Rollback
|
||||
public class DisposeTaskMapperTest {
|
||||
/**
|
||||
* The Dispose task mapper.
|
||||
|
@ -107,25 +111,25 @@ public class DisposeTaskMapperTest {
|
|||
|
||||
@Test
|
||||
public void d2_getDisposeTask() throws JsonProcessingException {
|
||||
List<DisposeTask> taskList = disposeTaskMapper.getRunDisposeTask(-1L,
|
||||
List<DisposeTask> taskList = disposeTaskMapper.getRunningTask(-1L,
|
||||
DisposeCapacityType.CLEANUP,
|
||||
"192.168.0.1");
|
||||
|
||||
log.info("Step1: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(taskList));
|
||||
|
||||
taskList = disposeTaskMapper.getRunDisposeTask(570L,
|
||||
taskList = disposeTaskMapper.getRunningTask(570L,
|
||||
DisposeCapacityType.CLEANUP,
|
||||
"192.168.0.1");
|
||||
|
||||
log.info("Step2: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(taskList));
|
||||
|
||||
taskList = disposeTaskMapper.getRunDisposeTask(-1L,
|
||||
taskList = disposeTaskMapper.getRunningTask(-1L,
|
||||
DisposeCapacityType.HIDEPEND,
|
||||
"192.168.0.1");
|
||||
|
||||
log.info("Step3: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(taskList));
|
||||
|
||||
taskList = disposeTaskMapper.getRunDisposeTask(-1L,
|
||||
taskList = disposeTaskMapper.getRunningTask(-1L,
|
||||
DisposeCapacityType.HIDEPEND,
|
||||
"192.168.0.12");
|
||||
|
||||
|
|
Loading…
Reference in New Issue