REM:
1. 修改启动处置任务接口,当区域编码下无该设备时返回对应错误信息
This commit is contained in:
chenlinghy 2020-10-30 17:59:57 +08:00
parent c41c2a08ee
commit fa6fd0f2a6
9 changed files with 126 additions and 35 deletions

View File

@ -216,6 +216,10 @@ public enum ErrorCode {
* The Err decrypt aes 256. * The Err decrypt aes 256.
*/ */
ERR_DECRYPT_AES256(111, "AES256解密失败"), ERR_DECRYPT_AES256(111, "AES256解密失败"),
/**
* The Err no device by areaCode.
*/
ERR_NODEVICE_AREACODE(111, "区域无该设备"),
; ;
/** /**

View File

@ -103,9 +103,9 @@ public class DisposeTaskController {
DisposeCapacityType capType = CommonEnumHandler.codeOf(DisposeCapacityType.class, req.getType()); DisposeCapacityType capType = CommonEnumHandler.codeOf(DisposeCapacityType.class, req.getType());
String endTime = String.valueOf(req.getDisposeTime()); String endTime = String.valueOf(req.getDisposeTime());
NetflowDirection netDir = CommonEnumHandler.codeOf(NetflowDirection.class, NetflowDirection netDir = CommonEnumHandler.codeOf(NetflowDirection.class,
Optional.ofNullable(req.getFlowDirection()).orElse(2)); Optional.ofNullable(req.getFlowDirection()).orElse(2));
Long attackType = DDoSAttackType.getTypeMaskFromAttackType(Optional.ofNullable(req.getAttackType()) Long attackType = DDoSAttackType.getTypeMaskFromAttackType(Optional.ofNullable(req.getAttackType())
.orElse(new Integer[]{DDoSAttackType.ALL_ATTACKS.getValue()})); .orElse(new Integer[]{DDoSAttackType.ALL_ATTACKS.getValue()}));
Integer flowBand = Optional.ofNullable(req.getFlowBandwidth()) Integer flowBand = Optional.ofNullable(req.getFlowBandwidth())
.orElse(DisposeConfigValue.DEFAULT_DISPOSE_BANDWIDTH); .orElse(DisposeConfigValue.DEFAULT_DISPOSE_BANDWIDTH);
@ -175,20 +175,20 @@ public class DisposeTaskController {
.deviceId(Long.parseLong(Optional.ofNullable(req.getId()).orElse("-1"))) .deviceId(Long.parseLong(Optional.ofNullable(req.getId()).orElse("-1")))
.areaCode(-1) .areaCode(-1)
.accountId(userAccountService.getUserIdByAuthHead(Objects.requireNonNull(headers.get("Authorization")) .accountId(userAccountService.getUserIdByAuthHead(Objects.requireNonNull(headers.get("Authorization"))
.get(0))) .get(0)))
.disposeCapacity(CommonEnumHandler.codeOf(DisposeCapacityType.class, .disposeCapacity(CommonEnumHandler.codeOf(DisposeCapacityType.class,
req.getType())) req.getType()))
.disposeObject(Helper.ipAddressNormalize(req.getDisposeIp())) .disposeObject(Helper.ipAddressNormalize(req.getDisposeIp()))
.objectType(DisposeObjectType.IP) .objectType(DisposeObjectType.IP)
.planEndTime(String.valueOf(req.getDisposeTime())) .planEndTime(String.valueOf(req.getDisposeTime()))
.flowDirection(CommonEnumHandler.codeOf(NetflowDirection.class, .flowDirection(CommonEnumHandler.codeOf(NetflowDirection.class,
Optional.ofNullable(req.getFlowDirection()) Optional.ofNullable(req.getFlowDirection())
.orElse(2))) .orElse(2)))
.attackType(DDoSAttackType.getTypeMaskFromAttackType( .attackType(DDoSAttackType.getTypeMaskFromAttackType(
Optional.ofNullable(req.getAttackType()) Optional.ofNullable(req.getAttackType())
.orElse(new Integer[]{DDoSAttackType.ALL_ATTACKS.getValue()}))) .orElse(new Integer[]{DDoSAttackType.ALL_ATTACKS.getValue()})))
.flowBandWidth(Optional.ofNullable(req.getFlowBandwidth()) .flowBandWidth(Optional.ofNullable(req.getFlowBandwidth())
.orElse(DisposeConfigValue.DEFAULT_DISPOSE_BANDWIDTH)) .orElse(DisposeConfigValue.DEFAULT_DISPOSE_BANDWIDTH))
.build(); .build();
// 创建处置任务 // 创建处置任务
@ -235,9 +235,9 @@ public class DisposeTaskController {
DisposeCapacityType capType = CommonEnumHandler.codeOf(DisposeCapacityType.class, req.getType()); DisposeCapacityType capType = CommonEnumHandler.codeOf(DisposeCapacityType.class, req.getType());
String endTime = String.valueOf(req.getDisposeTime()); String endTime = String.valueOf(req.getDisposeTime());
NetflowDirection netDir = CommonEnumHandler.codeOf(NetflowDirection.class, NetflowDirection netDir = CommonEnumHandler.codeOf(NetflowDirection.class,
Optional.ofNullable(req.getFlowDirection()).orElse(2)); Optional.ofNullable(req.getFlowDirection()).orElse(2));
Long attackType = DDoSAttackType.getTypeMaskFromAttackType(Optional.ofNullable(req.getAttackType()) Long attackType = DDoSAttackType.getTypeMaskFromAttackType(Optional.ofNullable(req.getAttackType())
.orElse(new Integer[]{DDoSAttackType.ALL_ATTACKS.getValue()})); .orElse(new Integer[]{DDoSAttackType.ALL_ATTACKS.getValue()}));
Integer flowBand = Optional.ofNullable(req.getFlowBandwidth()) Integer flowBand = Optional.ofNullable(req.getFlowBandwidth())
.orElse(DisposeConfigValue.DEFAULT_DISPOSE_BANDWIDTH); .orElse(DisposeConfigValue.DEFAULT_DISPOSE_BANDWIDTH);
@ -311,9 +311,9 @@ public class DisposeTaskController {
// 停止成功 // 停止成功
if (ret.getFirstParam() == ErrorCode.ERR_OK) { if (ret.getFirstParam() == ErrorCode.ERR_OK) {
rspInfo.setDisposeDevice(ret.getSecondParam().getDeviceTask().stream() rspInfo.setDisposeDevice(ret.getSecondParam().getDeviceTask().stream()
.map(DeviceTask::getDeviceId) .map(DeviceTask::getDeviceId)
.map(String::valueOf) .map(String::valueOf)
.toArray(String[]::new)); .toArray(String[]::new));
rspInfo.setType(ret.getSecondParam().getDisposeCapacity().getValue()); rspInfo.setType(ret.getSecondParam().getDisposeCapacity().getValue());
rspInfo.setDisposeIp(ret.getSecondParam().getDisposeObject()); rspInfo.setDisposeIp(ret.getSecondParam().getDisposeObject());
rspInfo.setLeftTime(String.valueOf(Math.abs( rspInfo.setLeftTime(String.valueOf(Math.abs(
@ -350,14 +350,14 @@ public class DisposeTaskController {
//获取TaskId列表 //获取TaskId列表
List<Long> reqTaskIds = Arrays.stream(Optional.ofNullable(mr.getMsgContent().getTaskId()) List<Long> reqTaskIds = Arrays.stream(Optional.ofNullable(mr.getMsgContent().getTaskId())
.orElse(new String[]{})) .orElse(new String[]{}))
.map(Long::parseLong) .map(Long::parseLong)
.collect(Collectors.toList()); .collect(Collectors.toList());
MulReturnType<PageInfo<DisposeTask>, List<DisposeTask>> ret = MulReturnType<PageInfo<DisposeTask>, List<DisposeTask>> ret =
disposeTaskService.getPageDisposeTask(reqTaskIds, disposeTaskService.getPageDisposeTask(reqTaskIds,
mr.getMsgContent().getStartPage(), mr.getMsgContent().getStartPage(),
mr.getMsgContent().getPageSize()); mr.getMsgContent().getPageSize());
// 分页信息 // 分页信息
rspInfo.setCurPageNumber(ret.getFirstParam().getPageNum()); rspInfo.setCurPageNumber(ret.getFirstParam().getPageNum());
@ -407,7 +407,7 @@ public class DisposeTaskController {
} }
rspInfo.getItems().addAll(getTaskDetail.stream().sorted(Comparator.comparingLong((GetTaskDetail v) -> Long.parseLong(v.getTaskId()))) rspInfo.getItems().addAll(getTaskDetail.stream().sorted(Comparator.comparingLong((GetTaskDetail v) -> Long.parseLong(v.getTaskId())))
.collect(Collectors.toList())); .collect(Collectors.toList()));
return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo); return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo);
} }

View File

@ -55,4 +55,12 @@ public interface DisposeDeviceManager {
* @return the all dispose devices * @return the all dispose devices
*/ */
List<DisposeDevice> getAllNormalDisposeDevices(); List<DisposeDevice> getAllNormalDisposeDevices();
/**
* Gets all dispose devices.
*
* @param areaCode the areaCode
* @return the dispose devices
*/
List<DisposeDevice> getDisposeDevices(Integer areaCode);
} }

View File

@ -115,7 +115,7 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager {
fdDest.setAccessible(true); fdDest.setAccessible(true);
if (!obj.equals(fdDest.get(destDev))) { if (!obj.equals(fdDest.get(destDev))) {
log.debug("Upgrade field [{}] value form [{}] to [{}]", fdSrc.getName(), fdDest.get(destDev), log.debug("Upgrade field [{}] value form [{}] to [{}]", fdSrc.getName(), fdDest.get(destDev),
obj); obj);
fdDest.set(destDev, obj); fdDest.set(destDev, obj);
} }
fdDest.setAccessible(false); fdDest.setAccessible(false);
@ -143,11 +143,11 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager {
// HTTP 默认端口 // HTTP 默认端口
if (dev.getUrlType() == HttpType.HTTP) { if (dev.getUrlType() == HttpType.HTTP) {
tDev = disposeDeviceMapper.getDeviceByAddress(dev.getIpAddr(), tDev = disposeDeviceMapper.getDeviceByAddress(dev.getIpAddr(),
HttpType.getDefaultPort(HttpType.HTTP)); HttpType.getDefaultPort(HttpType.HTTP));
} else if (dev.getUrlType() == HttpType.HTTPS) { } else if (dev.getUrlType() == HttpType.HTTPS) {
// HTTPS 默认端口 // HTTPS 默认端口
tDev = disposeDeviceMapper.getDeviceByAddress(dev.getIpAddr(), tDev = disposeDeviceMapper.getDeviceByAddress(dev.getIpAddr(),
HttpType.getDefaultPort(HttpType.HTTPS)); HttpType.getDefaultPort(HttpType.HTTPS));
} }
} }
} }
@ -271,7 +271,19 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager {
@Override @Override
public List<DisposeDevice> getAllNormalDisposeDevices() { public List<DisposeDevice> getAllNormalDisposeDevices() {
return disposeDeviceMapper.selectAll().stream() return disposeDeviceMapper.selectAll().stream()
.filter(v -> v.getStatus() == ObjectStatus.NORMAL) .filter(v -> v.getStatus() == ObjectStatus.NORMAL)
.collect(Collectors.toList()); .collect(Collectors.toList());
}
/**
* Gets dispose devices by areaCode.
*
* @param areaCode the areaCode
* @return the dispose devices by areaCode.
*/
@Override
public List<DisposeDevice> getDisposeDevices(Integer areaCode) {
return disposeDeviceMapper.getDeviceByAreaCode(areaCode);
} }
} }

View File

@ -94,4 +94,13 @@ public interface DisposeDeviceMapper {
*/ */
DisposeDevice getDeviceById(@Param("id") Long id); DisposeDevice getDeviceById(@Param("id") Long id);
/**
* Gets deviceId by areaCode.
*
* @param areaCode the areaCode
* @return the list
*/
List<DisposeDevice> getDeviceByAreaCode(@Param("areaCode") Integer areaCode);
} }

View File

@ -55,4 +55,12 @@ public interface DisposeDeviceManagerService {
* @return the all dispose device * @return the all dispose device
*/ */
List<DisposeDevice> getAllDisposeDevice(); List<DisposeDevice> getAllDisposeDevice();
/**
* Gets dispose device by areaCode.
*
* @param areaCode the areaCode
* @return the all dispose device
*/
List<DisposeDevice> getDisposeDeviceByAreaCode(Integer areaCode);
} }

View File

@ -89,7 +89,7 @@ public class DisposeDeviceManagerServiceImpl implements DisposeDeviceManagerServ
DisposeDevice dev = new DisposeDevice(); DisposeDevice dev = new DisposeDevice();
MulReturnType<ErrorCode, ObjectStatus> ret = disposeDeviceManager.changeDisposeDeviceStatus(v, MulReturnType<ErrorCode, ObjectStatus> ret = disposeDeviceManager.changeDisposeDeviceStatus(v,
ObjectStatus.DELETED); ObjectStatus.DELETED);
dev.setId(v); dev.setId(v);
dev.setStatus(ret.getSecondParam()); dev.setStatus(ret.getSecondParam());
@ -128,4 +128,21 @@ public class DisposeDeviceManagerServiceImpl implements DisposeDeviceManagerServ
return disposeDevices; return disposeDevices;
} }
} }
/**
* Gets dispose device by areaCode.
*
* @param areaCode the areaCode
* @return the all dispose device by areaCode
*/
@Override
public List<DisposeDevice> getDisposeDeviceByAreaCode(Integer areaCode) {
List<DisposeDevice> disposeDevices = disposeDeviceManager.getDisposeDevices(areaCode);
if (disposeDevices == null) {
return new ArrayList<>();
} else {
return disposeDevices;
}
}
} }

View File

@ -3,15 +3,18 @@ package com.dispose.service.impl;
import com.dispose.common.DisposeTaskStatus; import com.dispose.common.DisposeTaskStatus;
import com.dispose.common.ErrorCode; import com.dispose.common.ErrorCode;
import com.dispose.manager.DisposeTaskManager; import com.dispose.manager.DisposeTaskManager;
import com.dispose.pojo.entity.DisposeDevice;
import com.dispose.pojo.entity.DisposeTask; import com.dispose.pojo.entity.DisposeTask;
import com.dispose.pojo.po.MulReturnType; import com.dispose.pojo.po.MulReturnType;
import com.dispose.service.DisposeAbilityRouterService; import com.dispose.service.DisposeAbilityRouterService;
import com.dispose.service.DisposeDeviceManagerService;
import com.dispose.service.DisposeTaskService; import com.dispose.service.DisposeTaskService;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* The type Dispose task service. * The type Dispose task service.
@ -32,6 +35,12 @@ public class DisposeTaskServiceImpl implements DisposeTaskService {
@Resource @Resource
DisposeAbilityRouterService disposeAbilityRouterService; DisposeAbilityRouterService disposeAbilityRouterService;
/**
* The Dispose device manager service.
*/
@Resource
DisposeDeviceManagerService disposeDeviceManagerService;
/** /**
* Create task mul return type. * Create task mul return type.
* *
@ -41,22 +50,32 @@ public class DisposeTaskServiceImpl implements DisposeTaskService {
@Override @Override
public MulReturnType<ErrorCode, DisposeTask> createTask(DisposeTask task) { public MulReturnType<ErrorCode, DisposeTask> createTask(DisposeTask task) {
DisposeTask exitTask = disposeTaskManager.getDisposeTask(task.getDeviceId(), task.getAreaCode(), DisposeTask exitTask = disposeTaskManager.getDisposeTask(task.getDeviceId(), task.getAreaCode(),
task.getDisposeObject(), task.getDisposeCapacity()); task.getDisposeObject(), task.getDisposeCapacity());
if (exitTask != null) { if (exitTask != null) {
return new MulReturnType<>(ErrorCode.ERR_TASKRUNNING, exitTask); return new MulReturnType<>(ErrorCode.ERR_TASKRUNNING, exitTask);
} }
ErrorCode err = disposeAbilityRouterService.verifyDisposeCapacity( ErrorCode err = disposeAbilityRouterService.verifyDisposeCapacity(
task.getDeviceId(), task.getDisposeObject(), task.getDisposeCapacity() task.getDeviceId(), task.getDisposeObject(), task.getDisposeCapacity()
); );
if (err != ErrorCode.ERR_OK) { if (err != ErrorCode.ERR_OK) {
return new MulReturnType<>(err, task); return new MulReturnType<>(err, task);
} }
return new MulReturnType<>(disposeTaskManager.addDisposeTask(task), //areaCode获取对应的deviceId
disposeTaskManager.getDisposeTaskById(task.getId())); List<DisposeDevice> devices = disposeDeviceManagerService.getDisposeDeviceByAreaCode(task.getAreaCode());
// 获取请求id列表
List<Long> deviceIds = devices.stream().map(DisposeDevice::getId).distinct().collect(Collectors.toList());
if (deviceIds.size() == 0 || !deviceIds.contains(task.getDeviceId())) {
return new MulReturnType<>(ErrorCode.ERR_NODEVICE_AREACODE, task);
} else {
return new MulReturnType<>(disposeTaskManager.addDisposeTask(task),
disposeTaskManager.getDisposeTaskById(task.getId()));
}
} }
/** /**

View File

@ -35,15 +35,15 @@
<select id="selectByIdSet" resultMap="dispose_device"> <select id="selectByIdSet" resultMap="dispose_device">
SELECT d.*, SELECT d.*,
c.id c_id, c.id c_id,
c.deviceId deviceId, c.deviceId deviceId,
c.capacityType capacityType, c.capacityType capacityType,
c.objectType objectType, c.objectType objectType,
c.ipType ipType, c.ipType ipType,
c.protectIp protectIp, c.protectIp protectIp,
c.reserveNetflow reserveNetflow c.reserveNetflow reserveNetflow
FROM dispose_device d FROM dispose_device d
LEFT JOIN dispose_capacity c ON d.id = c.deviceId LEFT JOIN dispose_capacity c ON d.id = c.deviceId
WHERE d.id IN WHERE d.id IN
<foreach collection="idList" item="id" index="index" open="(" close=")" separator=","> <foreach collection="idList" item="id" index="index" open="(" close=")" separator=",">
#{id} #{id}
@ -129,4 +129,18 @@
SET status = ${@com.dispose.common.ObjectStatus@NORMAL.getValue()} SET status = ${@com.dispose.common.ObjectStatus@NORMAL.getValue()}
WHERE id = #{id} WHERE id = #{id}
</update> </update>
<select id="getDeviceByAreaCode" resultMap="dispose_device">
SELECT d.*,
c.id c_id,
c.deviceId deviceId,
c.capacityType capacityType,
c.objectType objectType,
c.ipType ipType,
c.protectIp protectIp,
c.reserveNetflow reserveNetflow
FROM dispose_device d
LEFT JOIN dispose_capacity c ON d.id = c.deviceId
WHERE d.areaCode = #{areaCode}
</select>
</mapper> </mapper>