parent
456a4e8fbb
commit
dbe7feb01c
|
@ -115,3 +115,4 @@ buildNumber.properties
|
|||
!/src/main/resources/git.properties
|
||||
basedir/
|
||||
/.idea/
|
||||
/phoenix_ddos_handle.iml
|
||||
|
|
|
@ -12,8 +12,6 @@ import com.dispose.service.UserAccountService;
|
|||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import javax.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
@ -24,6 +22,9 @@ import org.springframework.web.bind.annotation.RequestHeader;
|
|||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
/**
|
||||
* The type Auth controller.
|
||||
*/
|
||||
|
@ -51,7 +52,7 @@ public class AuthController {
|
|||
@ResponseBody
|
||||
@ApiOperation("登录")
|
||||
public ProtocolRespDTO userLogin(@RequestBody ProtocolReqDTO mr)
|
||||
throws JsonProcessingException, NoSuchAlgorithmException {
|
||||
throws JsonProcessingException, NoSuchAlgorithmException {
|
||||
ErrorCode err = mr.verifyRequest();
|
||||
|
||||
if (err != ErrorCode.ERR_OK) {
|
||||
|
@ -62,18 +63,18 @@ public class AuthController {
|
|||
|
||||
|
||||
MReturnType<ErrorCode, String> ret = userAccountService.loginService(reqInfo.getUserName(),
|
||||
reqInfo.getPassword());
|
||||
reqInfo.getPassword());
|
||||
|
||||
if (ret.getFirstParam() != ErrorCode.ERR_OK) {
|
||||
return ProtocolRespDTO.result(ret.getFirstParam());
|
||||
}
|
||||
|
||||
LoginRsp rspInfo = LoginRsp.builder()
|
||||
.userName(reqInfo.getUserName())
|
||||
.token(ret.getSecondParam())
|
||||
.logTime(System.currentTimeMillis())
|
||||
.expireTime(System.currentTimeMillis() + ConstValue.GlobalConfigure.TOKEN_EXPIRED_TIME_MS)
|
||||
.build();
|
||||
.userName(reqInfo.getUserName())
|
||||
.token(ret.getSecondParam())
|
||||
.logTime(System.currentTimeMillis())
|
||||
.expireTime(System.currentTimeMillis() + ConstValue.GlobalConfigure.TOKEN_EXPIRED_TIME_MS)
|
||||
.build();
|
||||
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo);
|
||||
}
|
||||
|
@ -91,7 +92,7 @@ public class AuthController {
|
|||
@ApiOperation("注销")
|
||||
public ProtocolRespDTO userLogout(@RequestBody ProtocolReqDTO mr,
|
||||
@RequestHeader HttpHeaders headers)
|
||||
throws JsonProcessingException {
|
||||
throws JsonProcessingException {
|
||||
|
||||
ErrorCode err = mr.verifyRequest(headers);
|
||||
|
||||
|
@ -108,8 +109,8 @@ public class AuthController {
|
|||
}
|
||||
|
||||
LogoutRsp rspInfo = LogoutRsp.builder()
|
||||
.userName(reqInfo.getUserName())
|
||||
.build();
|
||||
.userName(reqInfo.getUserName())
|
||||
.build();
|
||||
|
||||
rspInfo.setStatus(ErrorCode.ERR_OK.getCode());
|
||||
rspInfo.setMessage(ErrorCode.ERR_OK.getMsg());
|
||||
|
|
|
@ -24,12 +24,6 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
|||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
@ -40,6 +34,13 @@ import org.springframework.web.bind.annotation.RequestHeader;
|
|||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* The type Dispose node info controller.
|
||||
*/
|
||||
|
|
|
@ -15,9 +15,6 @@ import com.dispose.service.DisposeNodeManager;
|
|||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
@ -29,6 +26,10 @@ import org.springframework.web.bind.annotation.RequestHeader;
|
|||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The type Dispose node manager controller.
|
||||
*/
|
||||
|
@ -63,7 +64,7 @@ public class DisposeNodeManagerController {
|
|||
@ApiOperation("添加处置能力节点")
|
||||
public ProtocolRespDTO addDisposeNode(@RequestBody ProtocolReqDTO mr,
|
||||
@RequestHeader HttpHeaders headers)
|
||||
throws JsonProcessingException {
|
||||
throws JsonProcessingException {
|
||||
|
||||
ErrorCode err = mr.verifyRequest(headers);
|
||||
|
||||
|
@ -83,14 +84,14 @@ public class DisposeNodeManagerController {
|
|||
|
||||
reqInfo.getItems().forEach(v -> {
|
||||
DisposeDevice dev = DisposeDevice.builder()
|
||||
.type(v.getType())
|
||||
.name(v.getName())
|
||||
.ipAddr(v.getIpAddr())
|
||||
.areaCode(v.getAreaCode())
|
||||
.manufacturer(v.getManufacturer())
|
||||
.model(v.getModel())
|
||||
.version(v.getVersion())
|
||||
.build();
|
||||
.type(v.getType())
|
||||
.name(v.getName())
|
||||
.ipAddr(v.getIpAddr())
|
||||
.areaCode(v.getAreaCode())
|
||||
.manufacturer(v.getManufacturer())
|
||||
.model(v.getModel())
|
||||
.version(v.getVersion())
|
||||
.build();
|
||||
MReturnType<ErrorCode, String> ret;
|
||||
try {
|
||||
ret = disposeNodeManager.addNewDisposeDevice(dev);
|
||||
|
@ -122,7 +123,7 @@ public class DisposeNodeManagerController {
|
|||
@ApiOperation("删除处置能力节点")
|
||||
public ProtocolRespDTO removeDisposeNode(@RequestBody ProtocolReqDTO mr,
|
||||
@RequestHeader HttpHeaders headers)
|
||||
throws JsonProcessingException {
|
||||
throws JsonProcessingException {
|
||||
ErrorCode err = mr.verifyRequest(headers);
|
||||
|
||||
if (err != ErrorCode.ERR_OK) {
|
||||
|
|
|
@ -19,13 +19,6 @@ import com.dispose.service.TaskService;
|
|||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
@ -36,6 +29,14 @@ import org.springframework.web.bind.annotation.RequestHeader;
|
|||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* The type Dispose task controller.
|
||||
*/
|
||||
|
@ -64,7 +65,7 @@ public class DisposeTaskController {
|
|||
@ApiOperation("启动处置任务")
|
||||
public ProtocolRespDTO taskStart(@RequestBody ProtocolReqDTO mr,
|
||||
@RequestHeader HttpHeaders headers)
|
||||
throws JsonProcessingException {
|
||||
throws JsonProcessingException {
|
||||
ErrorCode err = mr.verifyRequest(headers);
|
||||
|
||||
if (err != ErrorCode.ERR_OK) {
|
||||
|
@ -74,6 +75,8 @@ public class DisposeTaskController {
|
|||
StartTaskReq reqInfo = mr.getRequestObject(StartTaskReq.class);
|
||||
StartTaskRsp rspInfo = new StartTaskRsp();
|
||||
|
||||
//taskService.createTask()
|
||||
|
||||
rspInfo.setTaskId(String.valueOf(reqInfo.getId()));
|
||||
rspInfo.setStatus(err.getCode());
|
||||
rspInfo.setMessage(err.getMsg());
|
||||
|
@ -94,7 +97,7 @@ public class DisposeTaskController {
|
|||
@ApiOperation("停止处置任务")
|
||||
public ProtocolRespDTO taskStop(@RequestBody ProtocolReqDTO mr,
|
||||
@RequestHeader HttpHeaders headers)
|
||||
throws JsonProcessingException {
|
||||
throws JsonProcessingException {
|
||||
ErrorCode err = mr.verifyRequest(headers);
|
||||
|
||||
if (err != ErrorCode.ERR_OK) {
|
||||
|
@ -105,14 +108,14 @@ public class DisposeTaskController {
|
|||
TaskInfoRsp rspInfo = new TaskInfoRsp();
|
||||
|
||||
if (reqInfo.getTaskId() == null
|
||||
|| reqInfo.getTaskId().length == 0) {
|
||||
|| reqInfo.getTaskId().length == 0) {
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_INPUTMISS);
|
||||
}
|
||||
|
||||
for (String v : reqInfo.getTaskId()) {
|
||||
TaskInfoData taskData = TaskInfoData.builder()
|
||||
.taskId(v)
|
||||
.build();
|
||||
.taskId(v)
|
||||
.build();
|
||||
|
||||
taskData.setStatus(err.getCode());
|
||||
taskData.setMessage(err.getMsg());
|
||||
|
@ -136,7 +139,7 @@ public class DisposeTaskController {
|
|||
@ApiOperation("根据处置IP停止处置任务")
|
||||
public ProtocolRespDTO taskStopByIp(@RequestBody ProtocolReqDTO mr,
|
||||
@RequestHeader HttpHeaders headers)
|
||||
throws JsonProcessingException {
|
||||
throws JsonProcessingException {
|
||||
ErrorCode err = mr.verifyRequest(headers);
|
||||
|
||||
if (err != ErrorCode.ERR_OK) {
|
||||
|
@ -148,8 +151,8 @@ public class DisposeTaskController {
|
|||
|
||||
reqInfo.getItems().forEach(v -> {
|
||||
TaskInfoData taskData = TaskInfoData.builder()
|
||||
.type(v.getType())
|
||||
.build();
|
||||
.type(v.getType())
|
||||
.build();
|
||||
|
||||
taskData.setId(v.getId());
|
||||
taskData.setStatus(err.getCode());
|
||||
|
@ -174,7 +177,7 @@ public class DisposeTaskController {
|
|||
@ApiOperation("停止处置节点处置任务")
|
||||
public ProtocolRespDTO taskStopAllOfDisposeNode(@RequestBody ProtocolReqDTO mr,
|
||||
@RequestHeader HttpHeaders headers)
|
||||
throws JsonProcessingException {
|
||||
throws JsonProcessingException {
|
||||
return taskStopByIp(mr, headers);
|
||||
}
|
||||
|
||||
|
@ -191,7 +194,7 @@ public class DisposeTaskController {
|
|||
@ApiOperation("启动处置任务")
|
||||
public ProtocolRespDTO taskStopAll(@RequestBody ProtocolReqDTO mr,
|
||||
@RequestHeader HttpHeaders headers)
|
||||
throws JsonProcessingException {
|
||||
throws JsonProcessingException {
|
||||
return taskStopByIp(mr, headers);
|
||||
}
|
||||
|
||||
|
@ -218,10 +221,10 @@ public class DisposeTaskController {
|
|||
NodeTaskRsp rspInfo = new NodeTaskRsp();
|
||||
|
||||
List<DisposeDevice> valuableData = disposeNodeManager.getAllDisposeDevice()
|
||||
.parallelStream()
|
||||
.filter(v -> reqInfo.getId().length == 0
|
||||
|| Arrays.stream(reqInfo.getId()).anyMatch(s -> s.equals(v.getId().toString())))
|
||||
.collect(Collectors.toList());
|
||||
.parallelStream()
|
||||
.filter(v -> reqInfo.getId().length == 0
|
||||
|| Arrays.stream(reqInfo.getId()).anyMatch(s -> s.equals(v.getId().toString())))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
valuableData.parallelStream().forEach(v -> {
|
||||
NodeTaskData taskData = new NodeTaskData();
|
||||
|
@ -235,14 +238,14 @@ public class DisposeTaskController {
|
|||
Long endTm = Timestamp.valueOf(k.getPlanEndTime()).toInstant().toEpochMilli() / 1000;
|
||||
Long diff = endTm - tmLong;
|
||||
TaskInfoData taskInfoData = TaskInfoData.builder()
|
||||
.taskId(k.getId().toString())
|
||||
.type(k.getType())
|
||||
.startTime(tmLong.intValue())
|
||||
.disposeTime(diff.intValue())
|
||||
.disposeIp(k.getDisposeIp())
|
||||
.flowAttack(0)
|
||||
.flowClean(0)
|
||||
.build();
|
||||
.taskId(k.getId().toString())
|
||||
.type(k.getType())
|
||||
.startTime(tmLong.intValue())
|
||||
.disposeTime(diff.intValue())
|
||||
.disposeIp(k.getDisposeIp())
|
||||
.flowAttack(0)
|
||||
.flowClean(0)
|
||||
.build();
|
||||
|
||||
taskData.getTaskArray().add(taskInfoData);
|
||||
bHasData.compareAndSet(false, true);
|
||||
|
@ -261,8 +264,8 @@ public class DisposeTaskController {
|
|||
|
||||
if (reqInfo.getId().length != 0) {
|
||||
List<String> unExists = Arrays.stream(reqInfo.getId())
|
||||
.filter(v -> valuableData.parallelStream().noneMatch(k -> k.getId() == Long.parseLong(v)))
|
||||
.collect(Collectors.toList());
|
||||
.filter(v -> valuableData.parallelStream().noneMatch(k -> k.getId() == Long.parseLong(v)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
unExists.parallelStream().forEach(v -> {
|
||||
NodeTaskData taskData = new NodeTaskData();
|
||||
|
@ -302,7 +305,7 @@ public class DisposeTaskController {
|
|||
@ApiOperation("获取全部处置任务")
|
||||
public ProtocolRespDTO getAllTask(@RequestBody ProtocolReqDTO mr,
|
||||
@RequestHeader HttpHeaders headers)
|
||||
throws JsonProcessingException {
|
||||
throws JsonProcessingException {
|
||||
ErrorCode err = mr.verifyRequest(headers);
|
||||
|
||||
if (err != ErrorCode.ERR_OK) {
|
||||
|
@ -313,10 +316,10 @@ public class DisposeTaskController {
|
|||
TaskInfoRsp rspInfo = new TaskInfoRsp();
|
||||
|
||||
List<TaskInfoDetail> valuableData = taskService.getAllTask()
|
||||
.parallelStream()
|
||||
.filter(v -> reqInfo.getTaskId().length == 0
|
||||
|| Arrays.stream(reqInfo.getTaskId()).anyMatch(s -> s.equals(v.getId().toString())))
|
||||
.collect(Collectors.toList());
|
||||
.parallelStream()
|
||||
.filter(v -> reqInfo.getTaskId().length == 0
|
||||
|| Arrays.stream(reqInfo.getTaskId()).anyMatch(s -> s.equals(v.getId().toString())))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
valuableData.parallelStream().forEach(v -> {
|
||||
Long tmLong = Timestamp.valueOf(v.getBeginTime()).toInstant().toEpochMilli() / 1000;
|
||||
|
@ -324,17 +327,17 @@ public class DisposeTaskController {
|
|||
Long diff = endTm - tmLong;
|
||||
|
||||
TaskInfoData taskInfoData = TaskInfoData.builder()
|
||||
.taskId(v.getId().toString())
|
||||
.type(v.getType())
|
||||
.startTime(tmLong.intValue())
|
||||
.disposeTime(diff.intValue())
|
||||
.disposeIp(v.getDisposeIp())
|
||||
.attackType(getIntArrayByString(v.getAttackType()))
|
||||
.flowDirection(v.getFlowDirection())
|
||||
.flowBandWidth(v.getFlowBandWidth())
|
||||
.flowAttack(0)
|
||||
.flowClean(0)
|
||||
.build();
|
||||
.taskId(v.getId().toString())
|
||||
.type(v.getType())
|
||||
.startTime(tmLong.intValue())
|
||||
.disposeTime(diff.intValue())
|
||||
.disposeIp(v.getDisposeIp())
|
||||
.attackType(getIntArrayByString(v.getAttackType()))
|
||||
.flowDirection(v.getFlowDirection())
|
||||
.flowBandWidth(v.getFlowBandWidth())
|
||||
.flowAttack(0)
|
||||
.flowClean(0)
|
||||
.build();
|
||||
|
||||
rspInfo.getItems().add(taskInfoData);
|
||||
taskInfoData.setId(v.getId().toString());
|
||||
|
@ -344,8 +347,8 @@ public class DisposeTaskController {
|
|||
|
||||
if (reqInfo.getTaskId().length != 0) {
|
||||
List<String> unExists = Arrays.stream(reqInfo.getTaskId())
|
||||
.filter(v -> valuableData.parallelStream().noneMatch(k -> k.getId() == Long.parseLong(v)))
|
||||
.collect(Collectors.toList());
|
||||
.filter(v -> valuableData.parallelStream().noneMatch(k -> k.getId() == Long.parseLong(v)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
unExists.parallelStream().forEach(v -> {
|
||||
TaskInfoData taskData = new TaskInfoData();
|
||||
|
|
|
@ -4,42 +4,46 @@ import com.dispose.pojo.entity.DisposeDevice;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author phoenix
|
||||
* @date 2020年4月27日
|
||||
* The interface Dispose device manager.
|
||||
*/
|
||||
public interface DisposeDeviceManager {
|
||||
|
||||
/**
|
||||
* @param dd
|
||||
* @return
|
||||
* @Description: TODO(这里用一句话描述这个方法的作用)
|
||||
* Save dispose device int.
|
||||
*
|
||||
* @param dd the dd
|
||||
* @return the int
|
||||
*/
|
||||
int saveDisposeDevice(DisposeDevice dd);
|
||||
|
||||
/**
|
||||
* @param ip
|
||||
* @return
|
||||
* @Description: TODO(这里用一句话描述这个方法的作用)
|
||||
* Find dispose device by ip dispose device.
|
||||
*
|
||||
* @param ip the ip
|
||||
* @return the dispose device
|
||||
*/
|
||||
DisposeDevice findDisposeDeviceByIp(String ip);
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* @return
|
||||
* @Description: TODO(这里用一句话描述这个方法的作用)
|
||||
* Find dispose device by id dispose device.
|
||||
*
|
||||
* @param id the id
|
||||
* @return the dispose device
|
||||
*/
|
||||
DisposeDevice findDisposeDeviceById(Long id);
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @Description: TODO(这里用一句话描述这个方法的作用)
|
||||
* Find all dispose device list.
|
||||
*
|
||||
* @return the list
|
||||
*/
|
||||
List<DisposeDevice> findAllDisposeDevice();
|
||||
|
||||
/**
|
||||
* @param ip
|
||||
* @return
|
||||
* @Description: TODO(这里用一句话描述这个方法的作用)
|
||||
* Del dispose device by ip int.
|
||||
*
|
||||
* @param ip the ip
|
||||
* @return the int
|
||||
*/
|
||||
int delDisposeDeviceByIp(String ip);
|
||||
|
||||
|
|
|
@ -8,5 +8,49 @@ import tk.mybatis.mapper.common.MySqlMapper;
|
|||
* The interface Dispose device mapper.
|
||||
*/
|
||||
public interface DisposeDeviceMapper extends Mapper<DisposeDevice>, MySqlMapper<DisposeDevice> {
|
||||
/**
|
||||
* Add new dispose device.
|
||||
*
|
||||
* @param dev the dev
|
||||
*/
|
||||
void addNewDisposeDevice(DisposeDevice dev);
|
||||
|
||||
/**
|
||||
* Is device exists by ip int.
|
||||
*
|
||||
* @param ipAddr the ip addr
|
||||
* @return the int
|
||||
*/
|
||||
int isDeviceExistsByIp(String ipAddr);
|
||||
|
||||
/**
|
||||
* Is device exists by id int.
|
||||
*
|
||||
* @param id the id
|
||||
* @return the int
|
||||
*/
|
||||
int isDeviceExistsById(Long id);
|
||||
|
||||
/**
|
||||
* Gets device by ip.
|
||||
*
|
||||
* @param ipAddr the ip addr
|
||||
* @return the device by ip
|
||||
*/
|
||||
DisposeDevice getDeviceByIp(String ipAddr);
|
||||
|
||||
/**
|
||||
* Gets device by id.
|
||||
*
|
||||
* @param id the id
|
||||
* @return the device by id
|
||||
*/
|
||||
DisposeDevice getDeviceById(Long id);
|
||||
|
||||
/**
|
||||
* Del dispose device by ip.
|
||||
*
|
||||
* @param ipAddr the ip addr
|
||||
*/
|
||||
void delDisposeDeviceByIp(String ipAddr);
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ public class StartTaskReq {
|
|||
/**
|
||||
* The Id.
|
||||
*/
|
||||
private int id;
|
||||
private Integer id;
|
||||
/**
|
||||
* The Type.
|
||||
*/
|
||||
|
|
|
@ -70,12 +70,4 @@ public interface DisposeNodeManager {
|
|||
* @return the dispose device
|
||||
*/
|
||||
DisposeDevice getDisposeDevice(String ipAddr, DeviceCapacity capacity);
|
||||
|
||||
/**
|
||||
* 判断设备是否存在
|
||||
*
|
||||
* @param ip
|
||||
* @return
|
||||
*/
|
||||
boolean isExistsDisposeDeviceByIp(String ip);
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import com.dispose.common.ErrorCode;
|
|||
import com.dispose.common.IPAddrType;
|
||||
import com.dispose.dispose.DeviceRouter;
|
||||
import com.dispose.dispose.DisposeEntryManager;
|
||||
import com.dispose.manager.DisposeDeviceManager;
|
||||
import com.dispose.mapper.DisposeDeviceMapper;
|
||||
import com.dispose.pojo.entity.DisposeDevice;
|
||||
import com.dispose.pojo.po.DisposeDeviceCapacity;
|
||||
import com.dispose.pojo.po.MReturnType;
|
||||
|
@ -18,41 +18,34 @@ import java.util.Optional;
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* The type Dispose node manager.
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class DisposeNodeManagerImpl implements DisposeNodeManager {
|
||||
|
||||
/**
|
||||
* The Dispose dev map.
|
||||
*/
|
||||
private final ConcurrentHashMap<String, DisposeDevice> disposeDevMap = new ConcurrentHashMap<>();
|
||||
/**
|
||||
* The Dispose device mapper.
|
||||
*/
|
||||
@Resource
|
||||
private DisposeDeviceManager disposeDeviceManager;
|
||||
private DisposeDeviceMapper disposeDeviceMapper;
|
||||
/**
|
||||
* The User account service.
|
||||
*/
|
||||
@Resource
|
||||
private UserAccountService userAccountService;
|
||||
|
||||
@Override
|
||||
public boolean isExistsDisposeDeviceByIp(String ip) {
|
||||
// TODO Auto-generated method stub
|
||||
log.info("查询该处置设备是否存在 {}", ip);
|
||||
return disposeDeviceManager.findDisposeDeviceByIp(ip) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load dispose node from db.
|
||||
*/
|
||||
@Override
|
||||
public void loadDisposeNodeFromDB() {
|
||||
List<DisposeDevice> devList = disposeDeviceManager.findAllDisposeDevice();
|
||||
List<DisposeDevice> devList = disposeDeviceMapper.selectAll();
|
||||
|
||||
if (devList == null) {
|
||||
return;
|
||||
|
@ -60,8 +53,8 @@ public class DisposeNodeManagerImpl implements DisposeNodeManager {
|
|||
|
||||
devList.forEach(v -> {
|
||||
DisposeEntryManager dp = DeviceRouter.deviceRouterFactory(v.getType(),
|
||||
v.getIpAddr(),
|
||||
IPAddrType.getIpAddrType(v.getIpAddr()));
|
||||
v.getIpAddr(),
|
||||
IPAddrType.getIpAddrType(v.getIpAddr()));
|
||||
|
||||
v.setLinkStatus(dp.getDeviceLinkStatus() ? 1 : 0);
|
||||
v.setVersion(dp.getVersion());
|
||||
|
@ -80,7 +73,8 @@ public class DisposeNodeManagerImpl implements DisposeNodeManager {
|
|||
*/
|
||||
@Override
|
||||
public ErrorCode delDisposeDeviceById(Long id) {
|
||||
DisposeDevice dev = disposeDeviceManager.findDisposeDeviceById(id);
|
||||
DisposeEntryManager dp;
|
||||
DisposeDevice dev = disposeDeviceMapper.getDeviceById(id);
|
||||
|
||||
if (dev == null) {
|
||||
return ErrorCode.ERR_NOSUCHDEVICE;
|
||||
|
@ -97,8 +91,10 @@ public class DisposeNodeManagerImpl implements DisposeNodeManager {
|
|||
*/
|
||||
@Override
|
||||
public ErrorCode delDisposeDeviceByIp(String ipAddr) {
|
||||
if (!isExistsDisposeDeviceByIp(ipAddr)
|
||||
|| !disposeDevMap.containsKey(ipAddr)) {
|
||||
DisposeEntryManager dp;
|
||||
|
||||
if (disposeDeviceMapper.isDeviceExistsByIp(ipAddr) == 0
|
||||
|| !disposeDevMap.containsKey(ipAddr)) {
|
||||
return ErrorCode.ERR_NOSUCHDEVICE;
|
||||
}
|
||||
|
||||
|
@ -108,7 +104,7 @@ public class DisposeNodeManagerImpl implements DisposeNodeManager {
|
|||
return ErrorCode.ERR_NOSUCHDEVICE;
|
||||
}
|
||||
|
||||
disposeDeviceManager.delDisposeDeviceByIp(ipAddr);
|
||||
disposeDeviceMapper.delDisposeDeviceByIp(ipAddr);
|
||||
disposeDevMap.remove(ipAddr);
|
||||
|
||||
return ErrorCode.ERR_OK;
|
||||
|
@ -126,12 +122,12 @@ public class DisposeNodeManagerImpl implements DisposeNodeManager {
|
|||
|
||||
try {
|
||||
dp = DeviceRouter.deviceRouterFactory(dev.getType(),
|
||||
dev.getIpAddr(), IPAddrType.getIpAddrType(dev.getIpAddr()));
|
||||
dev.getIpAddr(), IPAddrType.getIpAddrType(dev.getIpAddr()));
|
||||
} catch (Exception ex) {
|
||||
return new MReturnType<>(ErrorCode.ERR_NOSUCHDEVICE, String.valueOf(-1));
|
||||
}
|
||||
|
||||
DisposeDevice dbDev = disposeDeviceManager.findDisposeDeviceByIp(dev.getIpAddr());
|
||||
DisposeDevice dbDev = disposeDeviceMapper.getDeviceByIp(dev.getIpAddr());
|
||||
|
||||
if (dbDev != null) {
|
||||
return new MReturnType<>(ErrorCode.ERR_DEVICEEXISTS, String.valueOf(dbDev.getId()));
|
||||
|
@ -149,7 +145,7 @@ public class DisposeNodeManagerImpl implements DisposeNodeManager {
|
|||
|
||||
dev.setDevInfo(dp.getDeviceInfo());
|
||||
|
||||
disposeDeviceManager.saveDisposeDevice(dev);
|
||||
disposeDeviceMapper.addNewDisposeDevice(dev);
|
||||
|
||||
disposeDevMap.put(dev.getIpAddr(), dev);
|
||||
return new MReturnType<>(ErrorCode.ERR_OK, dev.getId().toString());
|
||||
|
@ -185,8 +181,8 @@ public class DisposeNodeManagerImpl implements DisposeNodeManager {
|
|||
@Override
|
||||
public DisposeDevice getDisposeDeviceById(Long id) {
|
||||
Optional<DisposeDevice> findRet = disposeDevMap.values().stream()
|
||||
.filter(disposeDevMap -> id.equals(disposeDevMap.getId()))
|
||||
.findFirst();
|
||||
.filter(disposeDevMap -> id.equals(disposeDevMap.getId()))
|
||||
.findFirst();
|
||||
|
||||
return findRet.orElse(null);
|
||||
}
|
||||
|
@ -228,15 +224,15 @@ 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;
|
||||
}
|
||||
}
|
||||
|
@ -259,11 +255,11 @@ public class DisposeNodeManagerImpl implements DisposeNodeManager {
|
|||
public DisposeDevice getDisposeDevice(String ipAddr, DeviceCapacity capacity) {
|
||||
for (DisposeDevice dev : disposeDevMap.values()) {
|
||||
List<DisposeDeviceCapacity> capList = dev.getDevCaps()
|
||||
.stream()
|
||||
.filter(f -> f.getCapacity() == capacity.getCode())
|
||||
.collect(Collectors.toList());
|
||||
.stream()
|
||||
.filter(f -> f.getCapacity() == capacity.getCode())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (capList.stream().anyMatch(k -> isIpInRange(k, ipAddr))) {
|
||||
if(capList.stream().anyMatch(k -> isIpInRange(k, ipAddr))) {
|
||||
return dev;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,13 +14,14 @@ import com.dispose.service.DisposeNodeManager;
|
|||
import com.dispose.service.TaskService;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* The type Task service.
|
||||
|
@ -82,7 +83,7 @@ public class TaskServiceImpl implements TaskService {
|
|||
|
||||
if (err == ErrorCode.ERR_OK) {
|
||||
List<TaskInfoDetail> taskList = disposeTaskMapper.getTaskByTaskInfo(task.getId(), task.getAccountId(),
|
||||
task.getDisposeIp(), task.getType());
|
||||
task.getDisposeIp(), task.getType());
|
||||
|
||||
for (TaskInfoDetail v : taskList) {
|
||||
if (!taskIsExpired(v) && taskIsRunning(v)) {
|
||||
|
@ -99,7 +100,7 @@ public class TaskServiceImpl implements TaskService {
|
|||
private DisposeEntryManager getDisposeDeviceHandle(TaskInfoDetail task) {
|
||||
if (task != null) {
|
||||
DisposeDevice dev = disposeNodeManager.getDisposeDevice(task.getDisposeIp(),
|
||||
DeviceCapacity.values()[task.getType()]);
|
||||
DeviceCapacity.values()[task.getType()]);
|
||||
|
||||
if (dev == null) {
|
||||
return null;
|
||||
|
@ -119,6 +120,7 @@ public class TaskServiceImpl implements TaskService {
|
|||
*/
|
||||
@Override
|
||||
public ErrorCode startTask(Long taskId) {
|
||||
ErrorCode err = ErrorCode.ERR_OK;
|
||||
TaskInfoDetail task = taskCacheManager.getTaskById(taskId);
|
||||
|
||||
if (task == null) {
|
||||
|
@ -127,23 +129,27 @@ public class TaskServiceImpl implements TaskService {
|
|||
|
||||
DisposeEntryManager dp = getDisposeDeviceHandle(task);
|
||||
|
||||
if (dp == null) {
|
||||
return ErrorCode.ERR_NOSUCHDEVICE;
|
||||
}
|
||||
|
||||
if (taskIsExpired(task)) {
|
||||
taskCacheManager.upgradeTaskStatus(taskId, DisposeTaskStatus.TASK_FINISH.getCode());
|
||||
disposeTaskMapper.changeTaskCurrentStatus(taskId, DisposeTaskStatus.TASK_FINISH.getCode());
|
||||
if (dp != null) {
|
||||
asyncService.asyncStopDisposeDeviceTask(dp, task.getDisposeIp(),
|
||||
DeviceCapacity.values()[task.getType()]);
|
||||
err = dp.stopDispose(task.getDisposeIp(), DeviceCapacity.values()[task.getType()]);
|
||||
|
||||
if (err == ErrorCode.ERR_OK) {
|
||||
taskCacheManager.upgradeTaskStatus(taskId, DisposeTaskStatus.TASK_FINISH.getCode());
|
||||
disposeTaskMapper.changeTaskCurrentStatus(taskId, DisposeTaskStatus.TASK_FINISH.getCode());
|
||||
}
|
||||
} else if (!taskIsRunning(task)) {
|
||||
taskCacheManager.upgradeTaskStatus(taskId, DisposeTaskStatus.TASK_RUNNING.getCode());
|
||||
disposeTaskMapper.changeTaskCurrentStatus(taskId, DisposeTaskStatus.TASK_RUNNING.getCode());
|
||||
if (dp != null) {
|
||||
asyncService.asyncStartDisposeDeviceTask(dp, task.getDisposeIp(),
|
||||
DeviceCapacity.values()[task.getType()]);
|
||||
err = dp.runDispose(task.getDisposeIp(), DeviceCapacity.values()[task.getType()]);
|
||||
|
||||
if (err == ErrorCode.ERR_OK) {
|
||||
taskCacheManager.upgradeTaskStatus(taskId, DisposeTaskStatus.TASK_RUNNING.getCode());
|
||||
disposeTaskMapper.changeTaskCurrentStatus(taskId, DisposeTaskStatus.TASK_RUNNING.getCode());
|
||||
}
|
||||
}
|
||||
|
||||
return ErrorCode.ERR_OK;
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -168,7 +174,7 @@ public class TaskServiceImpl implements TaskService {
|
|||
|
||||
if (dp != null) {
|
||||
asyncService.asyncStopDisposeDeviceTask(dp, task.getDisposeIp(),
|
||||
DeviceCapacity.values()[task.getType()]);
|
||||
DeviceCapacity.values()[task.getType()]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -200,7 +206,7 @@ public class TaskServiceImpl implements TaskService {
|
|||
@Override
|
||||
public boolean taskIsRunning(TaskInfoDetail task) {
|
||||
return task.getCurrentStatus() == DisposeTaskStatus.TASK_RUNNING.getCode()
|
||||
|| task.getCurrentStatus() == DisposeTaskStatus.TASK_NEW.getCode();
|
||||
|| task.getCurrentStatus() == DisposeTaskStatus.TASK_NEW.getCode();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -212,13 +218,13 @@ public class TaskServiceImpl implements TaskService {
|
|||
@Override
|
||||
public boolean taskIsExpired(TaskInfoDetail task) {
|
||||
LocalDateTime lt = LocalDateTime.parse(task.getPlanEndTime(),
|
||||
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
|
||||
log.info(lt.toString());
|
||||
|
||||
return LocalDateTime.parse(task.getPlanEndTime(),
|
||||
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
|
||||
.isBefore(LocalDateTime.now());
|
||||
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
|
||||
.isBefore(LocalDateTime.now());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -230,11 +236,11 @@ public class TaskServiceImpl implements TaskService {
|
|||
@Override
|
||||
public List<TaskInfoDetail> getNodeAllRunningTask(Long devId) {
|
||||
List<TaskInfoDetail> taskList = taskCacheManager
|
||||
.getAllTask()
|
||||
.stream()
|
||||
.filter(v -> v.getCurrentStatus() == DisposeTaskStatus.TASK_RUNNING.getCode()
|
||||
&& v.getDeviceId().equals(devId))
|
||||
.collect(Collectors.toList());
|
||||
.getAllTask()
|
||||
.stream()
|
||||
.filter(v -> v.getCurrentStatus() == DisposeTaskStatus.TASK_RUNNING.getCode()
|
||||
&& v.getDeviceId().equals(devId))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (taskList.size() > 0) {
|
||||
return taskList;
|
||||
|
@ -252,10 +258,10 @@ public class TaskServiceImpl implements TaskService {
|
|||
@Override
|
||||
public List<TaskInfoDetail> getNodeAllTask(Long devId) {
|
||||
List<TaskInfoDetail> taskList = taskCacheManager
|
||||
.getAllTask()
|
||||
.stream()
|
||||
.filter(v -> v.getDeviceId().equals(devId))
|
||||
.collect(Collectors.toList());
|
||||
.getAllTask()
|
||||
.stream()
|
||||
.filter(v -> v.getDeviceId().equals(devId))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (taskList.size() > 0) {
|
||||
return taskList;
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
<?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.DisposeDeviceMapper">
|
||||
<insert id="addNewDisposeDevice" useGeneratedKeys="true" keyProperty="id" parameterType="com.dispose.pojo.entity.DisposeDevice">
|
||||
INSERT IGNORE INTO
|
||||
dispose_device(ipAddr, type,
|
||||
areaCode, name, manufacturer,
|
||||
model, version, readme, status)
|
||||
VALUES
|
||||
(#{ipAddr}, #{type},
|
||||
#{areaCode}, #{name}, #{manufacturer},
|
||||
#{model}, #{version}, #{readme}, 0)
|
||||
</insert>
|
||||
|
||||
<select id="getDeviceByIp" resultType="com.dispose.pojo.entity.DisposeDevice" parameterType="java.lang.String">
|
||||
SELECT * FROM dispose_device
|
||||
WHERE
|
||||
ipAddr = #{ipAddr}
|
||||
</select>
|
||||
|
||||
<select id="getDeviceById" resultType="com.dispose.pojo.entity.DisposeDevice" parameterType="java.lang.Long">
|
||||
SELECT * FROM dispose_device
|
||||
WHERE
|
||||
id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="isDeviceExistsByIp" resultType="java.lang.Integer">
|
||||
SELECT COUNT(*) FROM dispose_device
|
||||
WHERE
|
||||
ipAddr = #{ipAddr}
|
||||
</select>
|
||||
<select id="isDeviceExistsById" resultType="java.lang.Integer">
|
||||
SELECT COUNT(*) FROM dispose_device
|
||||
WHERE
|
||||
id = #{id}
|
||||
</select>
|
||||
<delete id="delDisposeDeviceByIp" parameterType="java.lang.String">
|
||||
DELETE
|
||||
dispose_device
|
||||
FROM
|
||||
dispose_device
|
||||
WHERE
|
||||
dispose_device.ipAddr = #{ipAddr}
|
||||
</delete>
|
||||
<delete id="delDisposeDeviceById" parameterType="java.lang.Long">
|
||||
DELETE
|
||||
dispose_device
|
||||
FROM
|
||||
dispose_device
|
||||
WHERE
|
||||
dispose_device.id = #{id}
|
||||
</delete>
|
||||
</mapper>
|
Loading…
Reference in New Issue