parent
c41c2a08ee
commit
fa6fd0f2a6
|
@ -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, "区域无该设备"),
|
||||
;
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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>
|
||||
|
||||
<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>
|
Loading…
Reference in New Issue