Merge remote-tracking branch 'origin/v2.0.2_dev' into v2.0.2_dev

This commit is contained in:
HuangXin 2020-11-02 17:10:16 +08:00
commit c68a20d106
10 changed files with 128 additions and 37 deletions

View File

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

View File

@ -55,4 +55,12 @@ public interface DisposeDeviceManager {
* @return the all dispose devices
*/
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);
if (!obj.equals(fdDest.get(destDev))) {
log.debug("Upgrade field [{}] value form [{}] to [{}]", fdSrc.getName(), fdDest.get(destDev),
obj);
obj);
fdDest.set(destDev, obj);
}
fdDest.setAccessible(false);
@ -143,11 +143,11 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager {
// HTTP 默认端口
if (dev.getUrlType() == HttpType.HTTP) {
tDev = disposeDeviceMapper.getDeviceByAddress(dev.getIpAddr(),
HttpType.getDefaultPort(HttpType.HTTP));
HttpType.getDefaultPort(HttpType.HTTP));
} else if (dev.getUrlType() == HttpType.HTTPS) {
// HTTPS 默认端口
tDev = disposeDeviceMapper.getDeviceByAddress(dev.getIpAddr(),
HttpType.getDefaultPort(HttpType.HTTPS));
HttpType.getDefaultPort(HttpType.HTTPS));
}
}
}
@ -271,7 +271,19 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager {
@Override
public List<DisposeDevice> getAllNormalDisposeDevices() {
return disposeDeviceMapper.selectAll().stream()
.filter(v -> v.getStatus() == ObjectStatus.NORMAL)
.collect(Collectors.toList());
.filter(v -> v.getStatus() == ObjectStatus.NORMAL)
.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);
/**
* 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
*/
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();
MulReturnType<ErrorCode, ObjectStatus> ret = disposeDeviceManager.changeDisposeDeviceStatus(v,
ObjectStatus.DELETED);
ObjectStatus.DELETED);
dev.setId(v);
dev.setStatus(ret.getSecondParam());
@ -128,4 +128,21 @@ public class DisposeDeviceManagerServiceImpl implements DisposeDeviceManagerServ
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.ErrorCode;
import com.dispose.manager.DisposeTaskManager;
import com.dispose.pojo.entity.DisposeDevice;
import com.dispose.pojo.entity.DisposeTask;
import com.dispose.pojo.po.MulReturnType;
import com.dispose.service.DisposeAbilityRouterService;
import com.dispose.service.DisposeDeviceManagerService;
import com.dispose.service.DisposeTaskService;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
/**
* The type Dispose task service.
@ -32,6 +35,12 @@ public class DisposeTaskServiceImpl implements DisposeTaskService {
@Resource
DisposeAbilityRouterService disposeAbilityRouterService;
/**
* The Dispose device manager service.
*/
@Resource
DisposeDeviceManagerService disposeDeviceManagerService;
/**
* Create task mul return type.
*
@ -41,22 +50,32 @@ public class DisposeTaskServiceImpl implements DisposeTaskService {
@Override
public MulReturnType<ErrorCode, DisposeTask> createTask(DisposeTask task) {
DisposeTask exitTask = disposeTaskManager.getDisposeTask(task.getDeviceId(), task.getAreaCode(),
task.getDisposeObject(), task.getDisposeCapacity());
task.getDisposeObject(), task.getDisposeCapacity());
if (exitTask != null) {
return new MulReturnType<>(ErrorCode.ERR_TASKRUNNING, exitTask);
}
ErrorCode err = disposeAbilityRouterService.verifyDisposeCapacity(
task.getDeviceId(), task.getDisposeObject(), task.getDisposeCapacity()
task.getDeviceId(), task.getDisposeObject(), task.getDisposeCapacity()
);
if (err != ErrorCode.ERR_OK) {
return new MulReturnType<>(err, task);
}
return new MulReturnType<>(disposeTaskManager.addDisposeTask(task),
disposeTaskManager.getDisposeTaskById(task.getId()));
//areaCode获取对应的deviceId
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 d.*,
c.id c_id,
c.deviceId deviceId,
c.capacityType capacityType,
c.objectType objectType,
c.ipType ipType,
c.protectIp protectIp,
c.reserveNetflow reserveNetflow
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
LEFT JOIN dispose_capacity c ON d.id = c.deviceId
WHERE d.id IN
<foreach collection="idList" item="id" index="index" open="(" close=")" separator=",">
#{id}
@ -129,4 +129,18 @@
SET status = ${@com.dispose.common.ObjectStatus@NORMAL.getValue()}
WHERE id = #{id}
</update>
</mapper>
<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>

View File

@ -144,10 +144,10 @@
<insert id="addNewTask" useGeneratedKeys="true" keyProperty="id"
parameterType="com.dispose.pojo.entity.DisposeTask">
INSERT IGNORE INTO dispose_task(deviceId, accountId, disposeCapacity, disposeObject, objectType,
INSERT IGNORE INTO dispose_task(deviceId, accountId, areaCode, disposeCapacity, disposeObject, objectType,
planEndTime, flowDirection, attackType, flowBandWidth,
currentStatus)
VALUES (#{deviceId}, #{accountId}, #{disposeCapacity}, #{disposeObject}, #{objectType},
VALUES (#{deviceId}, #{accountId}, #{areaCode}, #{disposeCapacity}, #{disposeObject}, #{objectType},
date_add(now(), interval #{planEndTime} MINUTE), #{flowDirection}, #{attackType},
#{flowBandWidth}, ${@com.dispose.common.DisposeTaskStatus@TASK_NEW.getValue()})
</insert>