OCT
REM: 1. 增加task_info数据库 2. 增加数据库Mapper 3. 支持广播处置任务到所有设备
This commit is contained in:
parent
59f5552c4d
commit
70da55edff
|
@ -64,7 +64,8 @@ public enum IPAddrType {
|
|||
public static boolean ipInRange(String rangeIp, String ipAddr) throws AddressStringException {
|
||||
final int numIp = 2;
|
||||
|
||||
if (rangeIp.equals(ipAddr)) {
|
||||
// 范围为空字符串或者与IP相同时,返回真
|
||||
if (rangeIp.length() == 0 || rangeIp.equals(ipAddr)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,6 @@ import javax.annotation.Resource;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
@ -583,12 +582,12 @@ public class DisposeNodeInfoController {
|
|||
taskData.setMessage(ErrorCode.ERR_NOSUCHTASK.getMsg());
|
||||
} else {
|
||||
runTasks.forEach(k -> {
|
||||
int diff = Helper.getTimestampDiff(k.getBeginTime(), k.getPlanEndTime());
|
||||
int diff = Helper.getTimestampDiff(k.getCreateTime(), k.getPlanEndTime());
|
||||
|
||||
TaskInfoData taskInfoData = TaskInfoData.builder()
|
||||
.taskId(k.getId().toString())
|
||||
.type(k.getType())
|
||||
.startTime(Helper.getTimestampSecond(k.getBeginTime()))
|
||||
.startTime(Helper.getTimestampSecond(k.getCreateTime()))
|
||||
.disposeTime(diff)
|
||||
.disposeIp(k.getDisposeIp())
|
||||
.flowAttack(0)
|
||||
|
@ -672,12 +671,12 @@ public class DisposeNodeInfoController {
|
|||
taskData.setMessage(ErrorCode.ERR_NOSUCHTASK.getMsg());
|
||||
} else {
|
||||
runTasks.forEach(k -> {
|
||||
int diff = Helper.getTimestampDiff(k.getBeginTime(), k.getPlanEndTime());
|
||||
int diff = Helper.getTimestampDiff(k.getCreateTime(), k.getPlanEndTime());
|
||||
|
||||
TaskInfoData taskInfoData = TaskInfoData.builder()
|
||||
.taskId(k.getId().toString())
|
||||
.type(k.getType())
|
||||
.startTime(Helper.getTimestampSecond(k.getBeginTime()))
|
||||
.startTime(Helper.getTimestampSecond(k.getCreateTime()))
|
||||
.disposeTime(diff)
|
||||
.disposeIp(k.getDisposeIp())
|
||||
.currentStatus(taskService.taskIsRunning(k) ? 0 : 1)
|
||||
|
|
|
@ -44,7 +44,6 @@ import java.time.ZoneId;
|
|||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -515,11 +514,11 @@ public class DisposeTaskController {
|
|||
taskService.getNodeAllRunningTask(v.getId()).forEach(k -> {
|
||||
if (v.getType().equals(reqInfo.getType())
|
||||
|| reqInfo.getType() == DeviceCapacity.ALLCAPACITY.getCode()) {
|
||||
int diff = Helper.getTimestampDiff(k.getBeginTime(), k.getPlanEndTime());
|
||||
int diff = Helper.getTimestampDiff(k.getCreateTime(), k.getPlanEndTime());
|
||||
TaskInfoData taskInfoData = TaskInfoData.builder()
|
||||
.taskId(k.getId().toString())
|
||||
.type(k.getType())
|
||||
.startTime(Helper.getTimestampSecond(k.getBeginTime()))
|
||||
.startTime(Helper.getTimestampSecond(k.getCreateTime()))
|
||||
.disposeTime(diff)
|
||||
.disposeIp(k.getDisposeIp())
|
||||
.flowAttack(0)
|
||||
|
@ -599,12 +598,12 @@ public class DisposeTaskController {
|
|||
.collect(Collectors.toList());
|
||||
|
||||
valuableData.forEach(v -> {
|
||||
int diff = Helper.getTimestampDiff(v.getBeginTime(), v.getPlanEndTime());
|
||||
int diff = Helper.getTimestampDiff(v.getCreateTime(), v.getPlanEndTime());
|
||||
|
||||
TaskInfoData taskInfoData = TaskInfoData.builder()
|
||||
.taskId(v.getId().toString())
|
||||
.type(v.getType())
|
||||
.startTime(Helper.getTimestampSecond(v.getBeginTime()))
|
||||
.startTime(Helper.getTimestampSecond(v.getCreateTime()))
|
||||
.disposeTime(diff / 60)
|
||||
.disposeIp(v.getDisposeIp())
|
||||
.attackType(Helper.attackStringToArray(v.getAttackType()))
|
||||
|
|
|
@ -20,13 +20,15 @@ import java.util.List;
|
|||
@Slf4j
|
||||
public class HaoHanImpl implements DisposeEntryManager {
|
||||
|
||||
private String deviceAddress;
|
||||
|
||||
/**
|
||||
* Instantiates a new Hao han.
|
||||
*
|
||||
* @param ipAddr the ip addr
|
||||
*/
|
||||
public HaoHanImpl(String ipAddr) {
|
||||
|
||||
this(ipAddr, IPAddrType.IPV4_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -36,7 +38,8 @@ public class HaoHanImpl implements DisposeEntryManager {
|
|||
* @param type the type
|
||||
*/
|
||||
public HaoHanImpl(String ipAddr, IPAddrType type) {
|
||||
|
||||
//http://10.88.77.88:18080/DDoSClean/clean/cleanTaskFlow
|
||||
deviceAddress = "http://" + ipAddr + "/DDoSClean/clean";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -109,7 +112,7 @@ public class HaoHanImpl implements DisposeEntryManager {
|
|||
.capacity(DeviceCapacity.CLEANUP.getCode())
|
||||
.tolFlowCapacity(0)
|
||||
// IPv4范围
|
||||
.protectIpV4(new String[] {"0.0.0.0-255.255.255.255"})
|
||||
.protectIpV4(new String[] {""})
|
||||
// IPv6范围
|
||||
.protectIpV6(new String[] {""})
|
||||
.build());
|
||||
|
@ -126,7 +129,8 @@ public class HaoHanImpl implements DisposeEntryManager {
|
|||
public boolean getDeviceLinkStatus() {
|
||||
try {
|
||||
String jsonRequest = "{\"cleanTaskId\":\"-1\"}";
|
||||
Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/cleanTaskFlow",
|
||||
//"http://10.88.77.88:18080/DDoSClean/clean/cleanTaskFlow"
|
||||
Http.postJson(deviceAddress + "cleanTaskFlow",
|
||||
null,
|
||||
jsonRequest);
|
||||
return true;
|
||||
|
|
|
@ -53,7 +53,7 @@ public interface DisposeTaskMapper extends Mapper<TaskInfoDetail>,
|
|||
* @param id the id
|
||||
* @return the task info by id
|
||||
*/
|
||||
TaskInfoDetail getTaskInfoById(Long id);
|
||||
TaskInfoDetail getTaskById(Long id);
|
||||
|
||||
/**
|
||||
* Gets all task by dispose ip.
|
||||
|
@ -108,7 +108,7 @@ public interface DisposeTaskMapper extends Mapper<TaskInfoDetail>,
|
|||
* @param type the type
|
||||
* @return the task by task info
|
||||
*/
|
||||
List<TaskInfoDetail> getTaskByTaskInfo(
|
||||
List<TaskInfoDetail> getTaskByTaskDetail(
|
||||
@Param("devId") Long devId,
|
||||
@Param("userId") Long userId,
|
||||
@Param("ipAddr") String ipAddr,
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
package com.dispose.mapper;
|
||||
|
||||
|
||||
import com.dispose.pojo.vo.common.TaskInfo;
|
||||
|
||||
/**
|
||||
* The interface Task info mapper.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public interface TaskInfoMapper {
|
||||
/**
|
||||
* Add new task info.
|
||||
*
|
||||
* @param taskInfo the task info
|
||||
*/
|
||||
void addNewTaskInfo(TaskInfo taskInfo);
|
||||
|
||||
/**
|
||||
* Gets task info.
|
||||
*
|
||||
* @param taskId the task id
|
||||
* @param deviceId the device id
|
||||
* @return the task info
|
||||
*/
|
||||
TaskInfo getTaskInfo(Long taskId, Long deviceId);
|
||||
|
||||
/**
|
||||
* Gets task info by task id.
|
||||
*
|
||||
* @param taskId the task id
|
||||
* @return the task info by task id
|
||||
*/
|
||||
TaskInfo getTaskInfoByTaskId(Long taskId);
|
||||
|
||||
/**
|
||||
* Change task info status.
|
||||
*
|
||||
* @param id the id
|
||||
* @param status the status
|
||||
*/
|
||||
void changeTaskInfoStatus(Long id, Long status);
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.dispose.pojo.vo.common;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import tk.mybatis.mapper.annotation.NameStyle;
|
||||
import tk.mybatis.mapper.code.Style;
|
||||
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
* The type Task info.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table(name = "task_info")
|
||||
@NameStyle(Style.normal)
|
||||
public class TaskInfo {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
private Long id;
|
||||
private Long taskId;
|
||||
private Long deviceId;
|
||||
private String beginTime;
|
||||
private String endTime;
|
||||
private Long externId;
|
||||
private Long status;
|
||||
}
|
|
@ -31,7 +31,7 @@ public class TaskInfoDetail implements Serializable {
|
|||
private Long accountId;
|
||||
private Integer type;
|
||||
private String disposeIp;
|
||||
private String beginTime;
|
||||
private String createTime;
|
||||
private String planEndTime;
|
||||
private String endTime;
|
||||
private Integer flowDirection;
|
||||
|
|
|
@ -77,5 +77,5 @@ public interface DisposeNodeManager {
|
|||
* @param capacity the capacity
|
||||
* @return the dispose device
|
||||
*/
|
||||
DisposeDevice getDisposeDevice(String ipAddr, DeviceCapacity capacity);
|
||||
List<DisposeDevice> getDisposeDevice(String ipAddr, DeviceCapacity capacity);
|
||||
}
|
||||
|
|
|
@ -256,8 +256,15 @@ public class DisposeNodeManagerImpl implements DisposeNodeManager {
|
|||
* @return the dispose device
|
||||
*/
|
||||
@Override
|
||||
public DisposeDevice getDisposeDevice(String ipAddr, DeviceCapacity capacity) {
|
||||
public List<DisposeDevice> getDisposeDevice(String ipAddr, DeviceCapacity capacity) {
|
||||
List<DisposeDevice> devList = new ArrayList<>();
|
||||
|
||||
for (DisposeDevice dev : disposeDevMap.values()) {
|
||||
// 判断设备是否在线
|
||||
if (dev.getLinkStatus() != 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 判断当前设备是否支持处置能力
|
||||
List<DisposeDeviceCapacity> capList = dev.getDevCaps()
|
||||
.stream()
|
||||
|
@ -267,11 +274,14 @@ public class DisposeNodeManagerImpl implements DisposeNodeManager {
|
|||
// 设备是否支持处置该IP的
|
||||
if (capList.stream().anyMatch(k -> isIpInRange(k, ipAddr))) {
|
||||
log.info("{} with {} used device {}:{}", ipAddr, capacity.getReadme(), dev.getId(), dev.getIpAddr());
|
||||
return dev;
|
||||
devList.add(dev);
|
||||
}
|
||||
}
|
||||
|
||||
log.error("No such device to process {} of {}", ipAddr, capacity.getReadme());
|
||||
return null;
|
||||
if (devList.size() == 0) {
|
||||
log.error("No such device to process {} of {}", ipAddr, capacity.getReadme());
|
||||
}
|
||||
|
||||
return devList;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,19 +47,23 @@ public class TaskServiceImpl implements TaskService {
|
|||
@Resource
|
||||
private DisposeNodeManager disposeNodeManager;
|
||||
|
||||
private DisposeEntryManager getDisposeDeviceHandle(String disposeIp, int devCapType) {
|
||||
private List<DisposeEntryManager> getDisposeDeviceHandle(String disposeIp, int devCapType) {
|
||||
List<DisposeEntryManager> devEntry = new ArrayList<>();
|
||||
|
||||
DisposeDevice dev = getDisposeNode(disposeIp, devCapType);
|
||||
List<DisposeDevice> dev = getDisposeNode(disposeIp, devCapType);
|
||||
|
||||
// 判断是否有支持处置该IP的能力
|
||||
if (dev == null) {
|
||||
log.info("No dispose device handle: disposeIp:{}, devCapType:{}", disposeIp, devCapType);
|
||||
return null;
|
||||
return devEntry;
|
||||
}
|
||||
|
||||
return DeviceRouter.deviceRouterFactory(dev.getType(), dev.getIpAddr());
|
||||
dev.forEach(v -> devEntry.add(DeviceRouter.deviceRouterFactory(v.getType(), v.getIpAddr())));
|
||||
|
||||
return devEntry;
|
||||
}
|
||||
|
||||
private DisposeDevice getDisposeNode(String disposeIp, int devCapType) {
|
||||
private List<DisposeDevice> getDisposeNode(String disposeIp, int devCapType) {
|
||||
DeviceCapacity cap;
|
||||
|
||||
try {
|
||||
|
@ -105,34 +109,29 @@ public class TaskServiceImpl implements TaskService {
|
|||
*/
|
||||
@Override
|
||||
public MulReturnType<ErrorCode, Long> createTask(TaskInfoDetail task) {
|
||||
DisposeDevice disposeDevice;
|
||||
List<DisposeDevice> disposeDevice = new ArrayList<>();
|
||||
Long taskId = task.getDeviceId();
|
||||
|
||||
// 首先查找有没有能处置这个ip的能力节点
|
||||
// 没有指定处置能力节点的情况
|
||||
if (taskId == null || taskId < 0) {
|
||||
disposeDevice = getDisposeNode(task.getDisposeIp(), task.getType());
|
||||
|
||||
//处置IP不在范围内
|
||||
if(disposeDevice == null){
|
||||
return MulReturnType.<ErrorCode, Long>builder()
|
||||
.firstParam(ErrorCode.ERR_UNABLEDISPOSEIP)
|
||||
.secondParam(-1L)
|
||||
.build();
|
||||
}
|
||||
task.setDeviceId(-1L);
|
||||
} else { // 指定了处置能力节点的情况
|
||||
disposeDevice = disposeNodeManager.getDisposeDeviceById(taskId);
|
||||
DisposeDevice dev = disposeNodeManager.getDisposeDeviceById(taskId);
|
||||
if (dev != null) {
|
||||
disposeDevice.add(dev);
|
||||
task.setDeviceId(dev.getId());
|
||||
}
|
||||
}
|
||||
|
||||
if (disposeDevice == null) {
|
||||
if (disposeDevice.size() == 0) {
|
||||
log.error("No such device to dispose this task: devId:{}, disposeIp:{}, type:{}",
|
||||
task.getDeviceId(), task.getDisposeIp(), task.getType());
|
||||
return MulReturnType.<ErrorCode, Long>builder()
|
||||
.firstParam(ErrorCode.ERR_NOSUCHDEVICE)
|
||||
.secondParam(-1L)
|
||||
.build();
|
||||
} else {
|
||||
task.setDeviceId(disposeDevice.getId());
|
||||
}
|
||||
|
||||
// 查询当前是否有相同能力节点,相同用户,相同处置IP的且正在执行的处置任务,如果存在则忽略该次任务(依照产品需求)
|
||||
|
@ -157,9 +156,9 @@ public class TaskServiceImpl implements TaskService {
|
|||
// 将该任务写入数据库和缓存,等到定时任务真正启动该任务
|
||||
disposeTaskMapper.addNewTask(task);
|
||||
|
||||
task.setBeginTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
task.setCreateTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
|
||||
TaskInfoDetail cacheTask = disposeTaskMapper.getTaskInfoById(task.getId());
|
||||
TaskInfoDetail cacheTask = disposeTaskMapper.getTaskById(task.getId());
|
||||
|
||||
ErrorCode err = taskCacheManager.addTask(cacheTask);
|
||||
|
||||
|
@ -188,9 +187,9 @@ public class TaskServiceImpl implements TaskService {
|
|||
}
|
||||
|
||||
// 再次检查是否有处置设备能够处置该任务
|
||||
DisposeEntryManager dp = getDisposeDeviceHandle(task.getDisposeIp(), task.getType());
|
||||
List<DisposeEntryManager> dp = getDisposeDeviceHandle(task.getDisposeIp(), task.getType());
|
||||
|
||||
if (dp == null) {
|
||||
if (dp.size() == 0) {
|
||||
log.error("No such device to dispose this task: disposeId:{}, type:{}", task.getDisposeIp(), task.getType());
|
||||
return ErrorCode.ERR_NOSUCHDEVICE;
|
||||
}
|
||||
|
@ -200,25 +199,27 @@ public class TaskServiceImpl implements TaskService {
|
|||
|
||||
taskCacheManager.upgradeTaskStatus(taskId, DisposeTaskStatus.TASK_RUNNING.getCode());
|
||||
|
||||
// 异步启动处置任务
|
||||
CompletableFuture.supplyAsync(() -> dp.runDispose(task.getDisposeIp(), DeviceCapacity.values()[task.getType()]))
|
||||
.whenComplete((v, ex) -> {
|
||||
if (ex != null) {
|
||||
log.error("Start task: taskId:{}, error:{}", taskId, ex.getMessage());
|
||||
// 执行任务失败恢复缓存中的任务状态
|
||||
taskCacheManager.upgradeTaskStatus(taskId, DisposeTaskStatus.TASK_NEW.getCode());
|
||||
} else {
|
||||
if (v != ErrorCode.ERR_OK) {
|
||||
dp.forEach(k -> {
|
||||
// 异步启动处置任务
|
||||
CompletableFuture.supplyAsync(() -> k.runDispose(task.getDisposeIp(), DeviceCapacity.values()[task.getType()]))
|
||||
.whenComplete((v, ex) -> {
|
||||
if (ex != null) {
|
||||
log.error("Start task: taskId:{}, error:{}", taskId, ex.getMessage());
|
||||
// 执行任务失败恢复缓存中的任务状态
|
||||
taskCacheManager.upgradeTaskStatus(taskId, DisposeTaskStatus.TASK_NEW.getCode());
|
||||
log.error("Start task: taskId:{}, disposeIp:{}, error:{}", taskId, task.getDisposeIp(), v.getMsg());
|
||||
//taskCacheManager.upgradeTaskStatus(taskId, DisposeTaskStatus.TASK_NEW.getCode());
|
||||
} else {
|
||||
// 任务执行完成后更新数据库处置任务状态
|
||||
disposeTaskMapper.changeTaskCurrentStatus(taskId, DisposeTaskStatus.TASK_RUNNING.getCode());
|
||||
log.info("Start task finished: taskId:{}, disposeId:{}, type:{}", taskId, task.getDisposeIp(), task.getType());
|
||||
if (v != ErrorCode.ERR_OK) {
|
||||
// 执行任务失败恢复缓存中的任务状态
|
||||
//taskCacheManager.upgradeTaskStatus(taskId, DisposeTaskStatus.TASK_NEW.getCode());
|
||||
log.error("Start task: taskId:{}, disposeIp:{}, error:{}", taskId, task.getDisposeIp(), v.getMsg());
|
||||
} else {
|
||||
// 任务执行完成后更新数据库处置任务状态
|
||||
//disposeTaskMapper.changeTaskCurrentStatus(taskId, DisposeTaskStatus.TASK_RUNNING.getCode());
|
||||
log.info("Start task finished: taskId:{}, disposeId:{}, type:{}", taskId, task.getDisposeIp(), task.getType());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return err;
|
||||
|
@ -236,9 +237,9 @@ public class TaskServiceImpl implements TaskService {
|
|||
TaskInfoDetail task = taskCacheManager.getTaskById(taskId);
|
||||
|
||||
if (task != null) {
|
||||
DisposeEntryManager dp = getDisposeDeviceHandle(task.getDisposeIp(), task.getType());
|
||||
List<DisposeEntryManager> dp = getDisposeDeviceHandle(task.getDisposeIp(), task.getType());
|
||||
|
||||
if (dp == null) {
|
||||
if (dp.size() == 0) {
|
||||
log.error("No such device to dispose this task: disposeId:{}, type:{}", task.getDisposeIp(), task.getType());
|
||||
return ErrorCode.ERR_NOSUCHDEVICE;
|
||||
}
|
||||
|
@ -252,25 +253,27 @@ public class TaskServiceImpl implements TaskService {
|
|||
return err;
|
||||
}
|
||||
|
||||
// 异步启动处置任务
|
||||
CompletableFuture.supplyAsync(() -> dp.stopDispose(task.getDisposeIp(), DeviceCapacity.values()[task.getType()]))
|
||||
.whenComplete((v, ex) -> {
|
||||
if (ex != null) {
|
||||
// 恢复缓存中任务状态到先前状态
|
||||
taskCacheManager.upgradeTaskStatus(taskId, prdStatus);
|
||||
log.error("Stop task: taskId:{}, error:{}", taskId, ex.getMessage());
|
||||
} else {
|
||||
if (v != ErrorCode.ERR_OK) {
|
||||
dp.forEach(k -> {
|
||||
// 异步启动处置任务
|
||||
CompletableFuture.supplyAsync(() -> k.stopDispose(task.getDisposeIp(), DeviceCapacity.values()[task.getType()]))
|
||||
.whenComplete((v, ex) -> {
|
||||
if (ex != null) {
|
||||
// 恢复缓存中任务状态到先前状态
|
||||
taskCacheManager.upgradeTaskStatus(taskId, prdStatus);
|
||||
log.error("Stop task: taskId:{}, error:{}", taskId, v.getMsg());
|
||||
log.error("Stop task: taskId:{}, error:{}", taskId, ex.getMessage());
|
||||
} else {
|
||||
// 任务执行完成后更新数据库处置任务状态
|
||||
finishTask(taskId);
|
||||
log.info("Stop task finished: taskId:{}, disposeId:{}, type:{}", taskId, task.getDisposeIp(), task.getType());
|
||||
if (v != ErrorCode.ERR_OK) {
|
||||
// 恢复缓存中任务状态到先前状态
|
||||
taskCacheManager.upgradeTaskStatus(taskId, prdStatus);
|
||||
log.error("Stop task: taskId:{}, error:{}", taskId, v.getMsg());
|
||||
} else {
|
||||
// 任务执行完成后更新数据库处置任务状态
|
||||
finishTask(taskId);
|
||||
log.info("Stop task finished: taskId:{}, disposeId:{}, type:{}", taskId, task.getDisposeIp(), task.getType());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
log.error("No such task: taskId:{}", taskId);
|
||||
return ErrorCode.ERR_NOSUCHTASK;
|
||||
|
@ -293,7 +296,7 @@ public class TaskServiceImpl implements TaskService {
|
|||
if (err == ErrorCode.ERR_OK) {
|
||||
// 设置数据库任务状态为完成状态
|
||||
disposeTaskMapper.changeTaskCurrentStatus(taskId, DisposeTaskStatus.TASK_FINISH.getCode());
|
||||
Integer currentStatus = disposeTaskMapper.getTaskInfoById(taskId).getCurrentStatus();
|
||||
Integer currentStatus = disposeTaskMapper.getTaskById(taskId).getCurrentStatus();
|
||||
log.info("taskId:{}, currentStatus:{}", taskId, currentStatus);
|
||||
// 移除缓存中的任务信息
|
||||
taskCacheManager.removeTask(taskId);
|
||||
|
|
|
@ -39,7 +39,7 @@ public class TaskManagerTask {
|
|||
// 判断是否存在正在运行的过期的任务,如果存在则结束该任务
|
||||
if(taskService.taskIsExpired(taskData) && taskService.taskIsRunning(taskData)) {
|
||||
log.info("Finish expired task {}:{} begin at {}",
|
||||
taskData.getId(), taskData.getDisposeIp(), taskData.getBeginTime());
|
||||
taskData.getId(), taskData.getDisposeIp(), taskData.getCreateTime());
|
||||
taskService.stopTask(taskData.getId());
|
||||
it.remove();
|
||||
continue;
|
||||
|
@ -53,7 +53,7 @@ public class TaskManagerTask {
|
|||
// 判断是否有新建任务,如果有的话启动新建的处置任务
|
||||
if (taskData.getCurrentStatus() == DisposeTaskStatus.TASK_NEW.getCode()) {
|
||||
log.info("Start task {}:{} of {}",
|
||||
taskData.getId(), taskData.getDisposeIp(), taskData.getBeginTime());
|
||||
taskData.getId(), taskData.getDisposeIp(), taskData.getCreateTime());
|
||||
if (taskService.startTask(taskData.getId()) != ErrorCode.ERR_OK) {
|
||||
taskData.setRetryTimes(taskData.getRetryTimes() + 1);
|
||||
log.error("startTask Task {}:{} error\n", taskData.getId(), taskData.getDisposeIp());
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
WHERE id = #{id, jdbcType=INTEGER}
|
||||
</select>
|
||||
|
||||
<select id="getTaskInfoById" resultType="com.dispose.pojo.vo.common.TaskInfoDetail">
|
||||
<select id="getTaskById" resultType="com.dispose.pojo.vo.common.TaskInfoDetail">
|
||||
SELECT *
|
||||
FROM dispose_task
|
||||
WHERE id = #{id, jdbcType=INTEGER}
|
||||
|
@ -78,7 +78,7 @@
|
|||
WHERE currentStatus = #{status, jdbcType=INTEGER}
|
||||
</select>
|
||||
|
||||
<select id="getTaskByTaskInfo" resultType="com.dispose.pojo.vo.common.TaskInfoDetail">
|
||||
<select id="getTaskByTaskDetail" resultType="com.dispose.pojo.vo.common.TaskInfoDetail">
|
||||
SELECT *
|
||||
FROM dispose_task
|
||||
WHERE deviceId = #{devId, jdbcType=INTEGER}
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
<?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">
|
||||
<insert id="addNewTaskInfo" useGeneratedKeys="true" keyProperty="id"
|
||||
parameterType="com.dispose.pojo.vo.common.TaskInfo">
|
||||
INSERT IGNORE INTO task_info(taskId, deviceId, externId)
|
||||
VALUES (#{taskId}, #{deviceId}, #{externId})
|
||||
</insert>
|
||||
|
||||
<select id="getTaskInfo" resultType="com.dispose.pojo.vo.common.TaskInfo">
|
||||
SELECT *
|
||||
FROM task_info
|
||||
WHERE taskId = #{taskId, jdbcType=INTEGER}
|
||||
AND deviceId = #{deviceId, jdbcType=INTEGER}
|
||||
</select>
|
||||
|
||||
<select id="getTaskInfoByTaskId" resultType="com.dispose.pojo.vo.common.TaskInfo">
|
||||
SELECT *
|
||||
FROM task_info
|
||||
WHERE taskId = #{taskId, jdbcType=INTEGER}
|
||||
</select>
|
||||
|
||||
<update id="changeTaskInfoStatus">
|
||||
UPDATE
|
||||
task_info
|
||||
SET
|
||||
status = #{status, jdbcType=INTEGER}
|
||||
WHERE
|
||||
id = #{id, jdbcType=INTEGER}
|
||||
</update>
|
||||
|
||||
</mapper>
|
|
@ -52,5 +52,6 @@ public class demo {
|
|||
Assert.assertTrue(IPAddrType.ipInRange("192.168.0.30", "192.168.0.30"));
|
||||
Assert.assertTrue(IPAddrType.ipInRange("192.168.0.40-192.168.0.40", "192.168.0.40"));
|
||||
Assert.assertTrue(IPAddrType.ipInRange("0.0.0.0-255.255.255.255", "192.168.0.30"));
|
||||
Assert.assertTrue(IPAddrType.ipInRange("", "192.168.0.30"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -97,7 +97,7 @@ public class DisposeTaskMapperTest extends InitTestEnvironment {
|
|||
disposeTaskMapper.addNewTask(taskData);
|
||||
|
||||
Assert.assertNotEquals(java.util.Optional.ofNullable(taskData.getId()), -1L);
|
||||
Assert.assertNotNull(disposeTaskMapper.getTaskInfoById(taskData.getId()));
|
||||
Assert.assertNotNull(disposeTaskMapper.getTaskById(taskData.getId()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -107,7 +107,7 @@ public class DisposeTaskMapperTest extends InitTestEnvironment {
|
|||
public void t99_removeTaskTest() {
|
||||
disposeTaskMapper.selectAll().forEach(v -> {
|
||||
disposeTaskMapper.removeTaskById(v.getId());
|
||||
Assert.assertNull(disposeTaskMapper.getTaskInfoById(v.getId()));
|
||||
Assert.assertNull(disposeTaskMapper.getTaskById(v.getId()));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -135,7 +135,7 @@ public class DisposeTaskMapperTest extends InitTestEnvironment {
|
|||
@Test
|
||||
public void t3_getTaskInfoByIdTest() {
|
||||
disposeTaskMapper.selectAll().forEach(v -> {
|
||||
TaskInfoDetail taskInfo = disposeTaskMapper.getTaskInfoById(v.getId());
|
||||
TaskInfoDetail taskInfo = disposeTaskMapper.getTaskById(v.getId());
|
||||
Assert.assertNotNull(taskInfo);
|
||||
Assert.assertEquals(taskInfo.getId(), v.getId());
|
||||
try {
|
||||
|
@ -246,7 +246,7 @@ public class DisposeTaskMapperTest extends InitTestEnvironment {
|
|||
@Test
|
||||
public void t9_getTaskByTaskInfoTest() {
|
||||
disposeTaskMapper.selectAll().forEach(v -> disposeTaskMapper
|
||||
.getTaskByTaskInfo(v.getDeviceId(),v.getAccountId(),v.getDisposeIp(),v.getType())
|
||||
.getTaskByTaskDetail(v.getDeviceId(),v.getAccountId(),v.getDisposeIp(),v.getType())
|
||||
.forEach(k -> {
|
||||
Assert.assertEquals(k.getDeviceId(), v.getDeviceId());
|
||||
Assert.assertEquals(k.getAccountId(), v.getAccountId());
|
||||
|
|
Loading…
Reference in New Issue