parent
4f16bc1dcc
commit
adccc0f09c
|
@ -3,6 +3,7 @@ package com.dispose.manager.impl;
|
|||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.manager.TaskCacheManager;
|
||||
import com.dispose.pojo.vo.common.TaskInfoDetail;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -13,6 +14,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||
* The type Task cache manager.
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class TaskCacheManagerImpl implements TaskCacheManager {
|
||||
/**
|
||||
* The Task cache map.
|
||||
|
@ -91,6 +93,7 @@ public class TaskCacheManagerImpl implements TaskCacheManager {
|
|||
@Override
|
||||
public ErrorCode upgradeTaskStatus(Long id, int status) {
|
||||
if (!taskCacheMap.containsKey(id)) {
|
||||
log.error("No such task to update the taskStatus: taskId:{}", id);
|
||||
return ErrorCode.ERR_NOSUCHDEVICE;
|
||||
}
|
||||
|
||||
|
|
|
@ -60,6 +60,7 @@ public class DisposeNodeManagerImpl implements DisposeNodeManager {
|
|||
List<DisposeDevice> devList = disposeDeviceMapper.selectAll();
|
||||
|
||||
if (devList == null) {
|
||||
log.error("No device in database");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -92,6 +93,7 @@ public class DisposeNodeManagerImpl implements DisposeNodeManager {
|
|||
DisposeDevice dev = disposeDeviceMapper.getDeviceById(id);
|
||||
|
||||
if (dev == null) {
|
||||
log.error("No such device: deviceId:{}", id);
|
||||
return ErrorCode.ERR_NOSUCHDEVICE;
|
||||
}
|
||||
|
||||
|
@ -109,6 +111,7 @@ public class DisposeNodeManagerImpl implements DisposeNodeManager {
|
|||
// 判断该IP是否存在
|
||||
if (disposeDeviceMapper.isDeviceExistsByIp(ipAddr) == 0
|
||||
|| !disposeDevMap.containsKey(ipAddr)) {
|
||||
log.error("No such dispose device: ipAddr:{}", ipAddr);
|
||||
return ErrorCode.ERR_NOSUCHDEVICE;
|
||||
}
|
||||
|
||||
|
@ -116,6 +119,7 @@ public class DisposeNodeManagerImpl implements DisposeNodeManager {
|
|||
DisposeDevice dev = disposeDevMap.get(ipAddr);
|
||||
|
||||
if (dev == null) {
|
||||
log.error("No such dispose device in cache: ipAddr:{}", ipAddr);
|
||||
return ErrorCode.ERR_NOSUCHDEVICE;
|
||||
}
|
||||
|
||||
|
@ -136,7 +140,7 @@ public class DisposeNodeManagerImpl implements DisposeNodeManager {
|
|||
public MReturnType<ErrorCode, String> addNewDisposeDevice(DisposeDevice dev) {
|
||||
DisposeEntryManager dp;
|
||||
|
||||
if(dev.getType() == null || dev.getIpAddr() == null || !IPAddrType.isIpAddress(dev.getIpAddr())) {
|
||||
if (dev.getType() == null || dev.getIpAddr() == null || !IPAddrType.isIpAddress(dev.getIpAddr())) {
|
||||
log.error("Add device error: type {}, ip {}", dev.getType(), dev.getIpAddr());
|
||||
return new MReturnType<>(ErrorCode.ERR_PARAMEXCEPTION, String.valueOf(-1));
|
||||
}
|
||||
|
@ -148,9 +152,12 @@ public class DisposeNodeManagerImpl implements DisposeNodeManager {
|
|||
|
||||
// 判断设备是否在线
|
||||
if (!dp.getDeviceLinkStatus()) {
|
||||
log.error("The device heartbeat is abnormal and offline: deviceId:{}, type:{}, ip:{}",
|
||||
dev.getId(), dev.getType(), dev.getIpAddr());
|
||||
return new MReturnType<>(ErrorCode.ERR_NOSUCHDEVICE, String.valueOf(-1));
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
log.error("No such dispose device: deviceId:{}, type:{}, ip:{}", dev.getId(), dev.getType(), dev.getIpAddr());
|
||||
return new MReturnType<>(ErrorCode.ERR_NOSUCHDEVICE, String.valueOf(-1));
|
||||
}
|
||||
|
||||
|
@ -159,6 +166,7 @@ public class DisposeNodeManagerImpl implements DisposeNodeManager {
|
|||
|
||||
// 设备已经存在
|
||||
if (dbDev != null) {
|
||||
log.error("The dispose device already exists: deviceId:{}, type:{}, ip:{}", dev.getId(), dev.getType(), dev.getIpAddr());
|
||||
return new MReturnType<>(ErrorCode.ERR_DEVICEEXISTS, String.valueOf(dbDev.getId()));
|
||||
}
|
||||
|
||||
|
@ -226,23 +234,26 @@ public class DisposeNodeManagerImpl implements DisposeNodeManager {
|
|||
*/
|
||||
private boolean isIpInRange(DisposeDeviceCapacity cap, String ipAddr) {
|
||||
try {
|
||||
if(IPAddrType.getIpAddrType(ipAddr) == IPAddrType.IPV4_TYPE) {
|
||||
for(String s : cap.getProtectIpV4()) {
|
||||
if(IPAddrType.ipInRange(s, ipAddr)) {
|
||||
if (IPAddrType.getIpAddrType(ipAddr) == IPAddrType.IPV4_TYPE) {
|
||||
for (String s : cap.getProtectIpV4()) {
|
||||
if (IPAddrType.ipInRange(s, ipAddr)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else if(IPAddrType.getIpAddrType(ipAddr) == IPAddrType.IPV6_TYPE) {
|
||||
for(String s : cap.getProtectIpV6()) {
|
||||
if(IPAddrType.ipInRange(s, ipAddr)) {
|
||||
} else if (IPAddrType.getIpAddrType(ipAddr) == IPAddrType.IPV6_TYPE) {
|
||||
for (String s : cap.getProtectIpV6()) {
|
||||
if (IPAddrType.ipInRange(s, ipAddr)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (AddressStringException e) {
|
||||
log.error(e.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
log.error("The IP address is not within device capacity: ipAddr:{}, capIpv4:{}, capIpv6:{}",
|
||||
ipAddr, cap.getProtectIpV4(), cap.getProtectIpV6());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -263,7 +274,7 @@ public class DisposeNodeManagerImpl implements DisposeNodeManager {
|
|||
.collect(Collectors.toList());
|
||||
|
||||
// 设备是否支持处置该IP的
|
||||
if(capList.stream().anyMatch(k -> isIpInRange(k, ipAddr))) {
|
||||
if (capList.stream().anyMatch(k -> isIpInRange(k, ipAddr))) {
|
||||
log.info("{} with {} used device {}:{}", ipAddr, capacity.getReadme(), dev.getId(), dev.getIpAddr());
|
||||
return dev;
|
||||
}
|
||||
|
|
|
@ -70,6 +70,7 @@ public class TaskServiceImpl implements TaskService {
|
|||
DisposeDevice dev = getDisposeNode(disposeIp, devCapType);
|
||||
|
||||
if (dev == null) {
|
||||
log.info("No dispose device handle: disposeIp:{}, devCapType:{}", disposeIp, devCapType);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -130,11 +131,11 @@ public class TaskServiceImpl implements TaskService {
|
|||
*/
|
||||
@Override
|
||||
public MReturnType<ErrorCode, Long> createTask(TaskInfoDetail task) {
|
||||
if(task.getDisposeIp() == null || task.getDisposeIp().length() == 0
|
||||
if (task.getDisposeIp() == null || task.getDisposeIp().length() == 0
|
||||
|| task.getPlanEndTime() == null || task.getPlanEndTime().length() == 0
|
||||
|| task.getType() == null || !IPAddrType.isIpAddress(task.getDisposeIp())) {
|
||||
log.error("Input params error: devId:{}, disposeIp:{}, type:{}",
|
||||
task.getDeviceId(), task.getDisposeIp(), task.getType());
|
||||
log.error("Input params error: devId:{}, disposeIp:{}, type:{}, planEndTime:{}",
|
||||
task.getDeviceId(), task.getDisposeIp(), task.getType(), task.getPlanEndTime());
|
||||
return MReturnType.<ErrorCode, Long>builder()
|
||||
.firstParam(ErrorCode.ERR_PARAMEXCEPTION)
|
||||
.secondParam(-1L)
|
||||
|
@ -152,7 +153,8 @@ public class TaskServiceImpl implements TaskService {
|
|||
}
|
||||
|
||||
if (disposeDevice == null) {
|
||||
log.error("No such device to dispose this task: devId:{}, disposeIp:{}, type:{}", task.getDeviceId(), task.getDisposeIp(), task.getType());
|
||||
log.error("No such device to dispose this task: devId:{}, disposeIp:{}, type:{}",
|
||||
task.getDeviceId(), task.getDisposeIp(), task.getType());
|
||||
return MReturnType.<ErrorCode, Long>builder()
|
||||
.firstParam(ErrorCode.ERR_NOSUCHDEVICE)
|
||||
.secondParam(-1L)
|
||||
|
@ -172,7 +174,8 @@ public class TaskServiceImpl implements TaskService {
|
|||
.collect(Collectors.toList());
|
||||
|
||||
if (taskList.size() > 0) {
|
||||
log.error("Same dispose task is running: devId:{}, disposeIp:{}, type:{}", task.getDeviceId(), task.getDisposeIp(), task.getType());
|
||||
log.error("Same dispose task is running: devId:{}, disposeIp:{}, type:{}",
|
||||
task.getDeviceId(), task.getDisposeIp(), task.getType());
|
||||
return MReturnType.<ErrorCode, Long>builder()
|
||||
.firstParam(ErrorCode.ERR_TASKRUNNING)
|
||||
.secondParam(taskList.get(0).getId())
|
||||
|
@ -188,7 +191,7 @@ public class TaskServiceImpl implements TaskService {
|
|||
|
||||
ErrorCode err = taskCacheManager.addTask(cacheTask);
|
||||
|
||||
log.info("Create new dispose task is running: devId:{}, disposeIp:{}, type:{} result {}",
|
||||
log.info("Create new dispose task is running: devId:{}, disposeIp:{}, type:{}, result:{}",
|
||||
task.getDeviceId(), task.getDisposeIp(), task.getType(), err.getMsg());
|
||||
|
||||
return MReturnType.<ErrorCode, Long>builder().firstParam(err).secondParam(task.getId()).build();
|
||||
|
@ -236,7 +239,7 @@ public class TaskServiceImpl implements TaskService {
|
|||
if (v != ErrorCode.ERR_OK) {
|
||||
// 执行任务失败恢复缓存中的任务状态
|
||||
taskCacheManager.upgradeTaskStatus(taskId, DisposeTaskStatus.TASK_NEW.getCode());
|
||||
log.error("Start task {}:{} error {}", task.getId(), task.getDisposeIp(), err.getMsg());
|
||||
log.error("Start task: taskId:{}, disposeIp:{}, error:{}", taskId, task.getDisposeIp(), v.getMsg());
|
||||
} else {
|
||||
// 任务执行完成后更新数据库处置任务状态
|
||||
disposeTaskMapper.changeTaskCurrentStatus(taskId, DisposeTaskStatus.TASK_RUNNING.getCode());
|
||||
|
@ -273,6 +276,7 @@ public class TaskServiceImpl implements TaskService {
|
|||
ErrorCode err = taskCacheManager.upgradeTaskStatus(taskId, DisposeTaskStatus.TASK_STOP.getCode());
|
||||
|
||||
if (err != ErrorCode.ERR_OK) {
|
||||
log.error("Failed to update task status, currentStatus:{}", task.getCurrentStatus());
|
||||
return err;
|
||||
}
|
||||
|
||||
|
@ -287,7 +291,7 @@ public class TaskServiceImpl implements TaskService {
|
|||
if (v != ErrorCode.ERR_OK) {
|
||||
// 恢复缓存中任务状态到先前状态
|
||||
taskCacheManager.upgradeTaskStatus(taskId, prdStatus);
|
||||
log.error("Start task {}:{} error {}", task.getId(), task.getDisposeIp(), err.getMsg());
|
||||
log.error("Stop task: taskId:{}, error:{}", taskId, v.getMsg());
|
||||
} else {
|
||||
// 任务执行完成后更新数据库处置任务状态
|
||||
finishTask(taskId);
|
||||
|
@ -317,6 +321,8 @@ public class TaskServiceImpl implements TaskService {
|
|||
if (err == ErrorCode.ERR_OK) {
|
||||
// 设置数据库任务状态为完成状态
|
||||
disposeTaskMapper.changeTaskCurrentStatus(taskId, DisposeTaskStatus.TASK_FINISH.getCode());
|
||||
Integer currentStatus = disposeTaskMapper.getTaskInfoById(taskId).getCurrentStatus();
|
||||
log.info("taskId:{}, currentStatus:{}", taskId, currentStatus);
|
||||
// 移除缓存中的任务信息
|
||||
taskCacheManager.removeTask(taskId);
|
||||
}
|
||||
|
@ -368,6 +374,7 @@ public class TaskServiceImpl implements TaskService {
|
|||
.collect(Collectors.toList());
|
||||
|
||||
if (taskList.size() > 0) {
|
||||
log.info("The device has tasks running: devId:{}, tasksRunningNumber:{}", devId, taskList.size());
|
||||
return taskList;
|
||||
}
|
||||
|
||||
|
@ -389,6 +396,7 @@ public class TaskServiceImpl implements TaskService {
|
|||
.collect(Collectors.toList());
|
||||
|
||||
if (taskList.size() > 0) {
|
||||
log.info("The device has tasks: devId:{}, tasksNumber:{}", devId, taskList.size());
|
||||
return taskList;
|
||||
}
|
||||
|
||||
|
@ -446,9 +454,9 @@ public class TaskServiceImpl implements TaskService {
|
|||
public List<MReturnType<ErrorCode, TaskInfoDetail>> stopTaskByDisposeIp(Long devId, int type, String ipAddr) {
|
||||
List<MReturnType<ErrorCode, TaskInfoDetail>> retList = new ArrayList<>();
|
||||
|
||||
if(devId == null || devId == -1L || ipAddr == null || ipAddr.length() == 0 || !IPAddrType.isIpAddress(ipAddr)) {
|
||||
if (devId == null || devId == -1L || ipAddr == null || ipAddr.length() == 0 || !IPAddrType.isIpAddress(ipAddr)) {
|
||||
retList.add(new MReturnType<>(ErrorCode.ERR_PARAMEXCEPTION, null));
|
||||
log.error("Input params error: devId:{}, disposeIp:{}, type:{}", devId, ipAddr, type);
|
||||
log.error("Input params error: devId:{}, disposeIp:{}, type:{}", devId, ipAddr, type);
|
||||
return retList;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue