parent
643c03ff7d
commit
4585672a16
|
@ -89,7 +89,7 @@ public class DisposeTaskController {
|
|||
@ApiOperation("启动处置任务")
|
||||
public ProtocolRespDTO taskStart(@RequestBody @Valid ProtocolReqDTO mr,
|
||||
@RequestHeader HttpHeaders headers)
|
||||
throws JsonProcessingException {
|
||||
throws JsonProcessingException {
|
||||
ErrorCode err = mr.verifyRequest(headers);
|
||||
|
||||
if (err != ErrorCode.ERR_OK) {
|
||||
|
@ -102,15 +102,15 @@ public class DisposeTaskController {
|
|||
StartTaskRsp rspInfo = new StartTaskRsp();
|
||||
|
||||
TaskInfoDetail task = TaskInfoDetail.builder()
|
||||
.deviceId(Long.valueOf(reqInfo.getId()))
|
||||
.accountId(userAccountService.getUserByToken(mr.getAuthToken()).getId())
|
||||
.type(reqInfo.getType())
|
||||
.disposeIp(reqInfo.getDisposeIp())
|
||||
.planEndTime(String.valueOf(reqInfo.getDisposeTime() == null ? "" : reqInfo.getDisposeTime()))
|
||||
.flowDirection(reqInfo.getFlowDirection() != null ? reqInfo.getFlowDirection() : FlowDirection.DIRECTION_TWOWAY.getCode())
|
||||
.flowBandWidth(reqInfo.getFlowBandwidth() != null ? reqInfo.getFlowBandwidth() : 1024)
|
||||
.attackType(Helper.attackArrayToString(reqInfo.getAttackType()))
|
||||
.build();
|
||||
.deviceId(Long.valueOf(reqInfo.getId()))
|
||||
.accountId(userAccountService.getUserByToken(mr.getAuthToken()).getId())
|
||||
.type(reqInfo.getType())
|
||||
.disposeIp(reqInfo.getDisposeIp())
|
||||
.planEndTime(String.valueOf(reqInfo.getDisposeTime() == null ? "" : reqInfo.getDisposeTime()))
|
||||
.flowDirection(reqInfo.getFlowDirection() != null ? reqInfo.getFlowDirection() : FlowDirection.DIRECTION_TWOWAY.getCode())
|
||||
.flowBandWidth(reqInfo.getFlowBandwidth() != null ? reqInfo.getFlowBandwidth() : 1024)
|
||||
.attackType(Helper.attackArrayToString(reqInfo.getAttackType()))
|
||||
.build();
|
||||
|
||||
MReturnType<ErrorCode, Long> ret = taskService.createTask(task);
|
||||
|
||||
|
@ -141,7 +141,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) {
|
||||
|
@ -164,7 +164,7 @@ public class DisposeTaskController {
|
|||
rspInfo.getItems().add(taskData);
|
||||
} else {
|
||||
ret.forEach(k -> {
|
||||
if(k.getFirstParam() == ErrorCode.ERR_OK){
|
||||
if (k.getFirstParam() == ErrorCode.ERR_OK) {
|
||||
ErrorCode retError = k.getFirstParam();
|
||||
TaskInfoDetail taskInfo = k.getSecondParam();
|
||||
taskData.setId(String.valueOf(taskInfo.getDeviceId()));
|
||||
|
@ -172,13 +172,13 @@ public class DisposeTaskController {
|
|||
taskData.setType(taskInfo.getType());
|
||||
taskData.setDisposeIp(taskInfo.getDisposeIp());
|
||||
taskData.setLeftTime(Math.abs(Helper.getTimestampDiffNow(taskInfo.getBeginTime())
|
||||
- Helper.getTimestampDiffNow(taskInfo.getPlanEndTime())) / 60);
|
||||
- Helper.getTimestampDiffNow(taskInfo.getPlanEndTime())) / 60);
|
||||
|
||||
taskData.setStatus(retError.getCode());
|
||||
taskData.setMessage(retError.getMsg());
|
||||
|
||||
rspInfo.getItems().add(taskData);
|
||||
}else{
|
||||
} else {
|
||||
log.error("Stop task: taskId:{}, error:{}", v, k.getFirstParam().getMsg());
|
||||
taskData.setStatus(k.getFirstParam().getCode());
|
||||
taskData.setMessage(k.getFirstParam().getMsg());
|
||||
|
@ -203,7 +203,7 @@ public class DisposeTaskController {
|
|||
@ApiOperation("根据处置IP停止处置任务")
|
||||
public ProtocolRespDTO taskStopByIp(@RequestBody ProtocolReqDTO mr,
|
||||
@RequestHeader HttpHeaders headers)
|
||||
throws JsonProcessingException {
|
||||
throws JsonProcessingException {
|
||||
|
||||
ErrorCode err = mr.verifyRequest(headers);
|
||||
|
||||
|
@ -235,13 +235,13 @@ public class DisposeTaskController {
|
|||
taskData.setType(taskInfo.getType());
|
||||
taskData.setDisposeIp(taskInfo.getDisposeIp());
|
||||
taskData.setLeftTime((Math.abs(Helper.getTimestampDiffNow(taskInfo.getBeginTime())
|
||||
- Helper.getTimestampDiffNow(taskInfo.getPlanEndTime()))) / 60);
|
||||
- Helper.getTimestampDiffNow(taskInfo.getPlanEndTime()))) / 60);
|
||||
|
||||
taskData.setStatus(retError.getCode());
|
||||
taskData.setMessage(retError.getMsg());
|
||||
} else {
|
||||
log.error("Stop task: taskId:{}, type:{}, disposeIp:{}, error:{}", v.getId(), v.getType(), v.getDisposeIp(),
|
||||
k.getFirstParam().getMsg());
|
||||
k.getFirstParam().getMsg());
|
||||
taskData.setStatus(k.getFirstParam().getCode());
|
||||
taskData.setMessage(k.getFirstParam().getMsg());
|
||||
}
|
||||
|
@ -267,7 +267,7 @@ public class DisposeTaskController {
|
|||
@ApiOperation("停止处置节点处置任务")
|
||||
public ProtocolRespDTO taskStopAllOfDisposeNode(@RequestBody ProtocolReqDTO mr,
|
||||
@RequestHeader HttpHeaders headers)
|
||||
throws JsonProcessingException {
|
||||
throws JsonProcessingException {
|
||||
ErrorCode err = mr.verifyRequest(headers);
|
||||
|
||||
if (err != ErrorCode.ERR_OK) {
|
||||
|
@ -298,15 +298,15 @@ public class DisposeTaskController {
|
|||
taskData.setType(taskInfo.getType());
|
||||
taskData.setDisposeIp(taskInfo.getDisposeIp());
|
||||
taskData.setLeftTime((Math.abs(Helper.getTimestampDiffNow(taskInfo.getBeginTime())
|
||||
- Helper.getTimestampDiffNow(taskInfo.getPlanEndTime()))) / 60);
|
||||
- Helper.getTimestampDiffNow(taskInfo.getPlanEndTime()))) / 60);
|
||||
|
||||
taskData.setStatus(retError.getCode());
|
||||
taskData.setMessage(retError.getMsg());
|
||||
|
||||
rspInfo.getItems().add(taskData);
|
||||
}else{
|
||||
} else {
|
||||
log.error("Stop task: deviceId:{}, type:{}, error:{}", v.getId(),
|
||||
v.getType(), k.getFirstParam().getMsg());
|
||||
v.getType(), k.getFirstParam().getMsg());
|
||||
TaskInfoData taskData = TaskInfoData.builder().type(v.getType()).build();
|
||||
taskData.setStatus(k.getFirstParam().getCode());
|
||||
taskData.setMessage(k.getFirstParam().getMsg());
|
||||
|
@ -331,7 +331,7 @@ public class DisposeTaskController {
|
|||
@ApiOperation("停止所有处置任务")
|
||||
public ProtocolRespDTO taskStopAll(@RequestBody ProtocolReqDTO mr,
|
||||
@RequestHeader HttpHeaders headers)
|
||||
throws JsonProcessingException {
|
||||
throws JsonProcessingException {
|
||||
|
||||
ErrorCode err = mr.verifyRequest(headers);
|
||||
|
||||
|
@ -353,7 +353,7 @@ public class DisposeTaskController {
|
|||
rspInfo.getItems().add(taskData);
|
||||
} else {
|
||||
ret.forEach(k -> {
|
||||
if(k.getFirstParam() == ErrorCode.ERR_OK){
|
||||
if (k.getFirstParam() == ErrorCode.ERR_OK) {
|
||||
TaskInfoData taskData = TaskInfoData.builder().type(reqInfo.getType()).build();
|
||||
ErrorCode retError = k.getFirstParam();
|
||||
TaskInfoDetail taskInfo = k.getSecondParam();
|
||||
|
@ -362,13 +362,13 @@ public class DisposeTaskController {
|
|||
taskData.setType(taskInfo.getType());
|
||||
taskData.setDisposeIp(taskInfo.getDisposeIp());
|
||||
taskData.setLeftTime((Math.abs(Helper.getTimestampDiffNow(taskInfo.getBeginTime())
|
||||
- Helper.getTimestampDiffNow(taskInfo.getPlanEndTime()))) / 60);
|
||||
- Helper.getTimestampDiffNow(taskInfo.getPlanEndTime()))) / 60);
|
||||
|
||||
taskData.setStatus(retError.getCode());
|
||||
taskData.setMessage(retError.getMsg());
|
||||
|
||||
rspInfo.getItems().add(taskData);
|
||||
}else{
|
||||
} else {
|
||||
log.error("No task to stop: error:{}", k.getFirstParam().getMsg());
|
||||
TaskInfoData taskData = TaskInfoData.builder().type(reqInfo.getType()).build();
|
||||
taskData.setStatus(k.getFirstParam().getCode());
|
||||
|
@ -405,10 +405,10 @@ public class DisposeTaskController {
|
|||
NodeTaskRsp rspInfo = new NodeTaskRsp();
|
||||
|
||||
List<DisposeDevice> valuableData = disposeNodeManager.getAllDisposeDevice()
|
||||
.stream()
|
||||
.filter(v -> reqInfo.getId().length == 0
|
||||
|| Arrays.stream(reqInfo.getId()).anyMatch(s -> s.equals(v.getId().toString())))
|
||||
.collect(Collectors.toList());
|
||||
.stream()
|
||||
.filter(v -> reqInfo.getId().length == 0
|
||||
|| Arrays.stream(reqInfo.getId()).anyMatch(s -> s.equals(v.getId().toString())))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
valuableData.forEach(v -> {
|
||||
NodeTaskData taskData = new NodeTaskData();
|
||||
|
@ -420,14 +420,14 @@ public class DisposeTaskController {
|
|||
if (v.getType().equals(reqInfo.getType()) || reqInfo.getType() == -1) {
|
||||
int diff = Helper.getTimestampDiff(k.getBeginTime(), k.getPlanEndTime());
|
||||
TaskInfoData taskInfoData = TaskInfoData.builder()
|
||||
.taskId(k.getId().toString())
|
||||
.type(k.getType())
|
||||
.startTime(Helper.getTimestampSecond(k.getBeginTime()))
|
||||
.disposeTime(diff)
|
||||
.disposeIp(k.getDisposeIp())
|
||||
.flowAttack(0)
|
||||
.flowClean(0)
|
||||
.build();
|
||||
.taskId(k.getId().toString())
|
||||
.type(k.getType())
|
||||
.startTime(Helper.getTimestampSecond(k.getBeginTime()))
|
||||
.disposeTime(diff)
|
||||
.disposeIp(k.getDisposeIp())
|
||||
.flowAttack(0)
|
||||
.flowClean(0)
|
||||
.build();
|
||||
|
||||
taskData.getTaskArray().add(taskInfoData);
|
||||
bHasData.compareAndSet(false, true);
|
||||
|
@ -447,8 +447,8 @@ public class DisposeTaskController {
|
|||
|
||||
if (reqInfo.getId().length != 0) {
|
||||
List<String> unExists = Arrays.stream(reqInfo.getId())
|
||||
.filter(v -> valuableData.stream().noneMatch(k -> k.getId() == Long.parseLong(v)))
|
||||
.collect(Collectors.toList());
|
||||
.filter(v -> valuableData.stream().noneMatch(k -> k.getId() == Long.parseLong(v)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
unExists.forEach(v -> {
|
||||
log.error("No such task, deviceId:{}", v);
|
||||
|
@ -475,7 +475,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) {
|
||||
|
@ -487,26 +487,26 @@ public class DisposeTaskController {
|
|||
TaskInfoRsp rspInfo = new TaskInfoRsp();
|
||||
|
||||
List<TaskInfoDetail> valuableData = taskService.getAllTask()
|
||||
.stream()
|
||||
.filter(v -> reqInfo.getTaskId().length == 0
|
||||
|| Arrays.stream(reqInfo.getTaskId()).anyMatch(s -> s.equals(v.getId().toString())))
|
||||
.collect(Collectors.toList());
|
||||
.stream()
|
||||
.filter(v -> reqInfo.getTaskId().length == 0
|
||||
|| Arrays.stream(reqInfo.getTaskId()).anyMatch(s -> s.equals(v.getId().toString())))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
valuableData.forEach(v -> {
|
||||
int diff = Helper.getTimestampDiff(v.getBeginTime(), v.getPlanEndTime());
|
||||
|
||||
TaskInfoData taskInfoData = TaskInfoData.builder()
|
||||
.taskId(v.getId().toString())
|
||||
.type(v.getType())
|
||||
.startTime(Helper.getTimestampSecond(v.getBeginTime()))
|
||||
.disposeTime(diff / 60)
|
||||
.disposeIp(v.getDisposeIp())
|
||||
.attackType(Helper.attackStringToArray(v.getAttackType()))
|
||||
.flowDirection(v.getFlowDirection())
|
||||
.flowBandWidth(v.getFlowBandWidth())
|
||||
.flowAttack(0)
|
||||
.flowClean(0)
|
||||
.build();
|
||||
.taskId(v.getId().toString())
|
||||
.type(v.getType())
|
||||
.startTime(Helper.getTimestampSecond(v.getBeginTime()))
|
||||
.disposeTime(diff / 60)
|
||||
.disposeIp(v.getDisposeIp())
|
||||
.attackType(Helper.attackStringToArray(v.getAttackType()))
|
||||
.flowDirection(v.getFlowDirection())
|
||||
.flowBandWidth(v.getFlowBandWidth())
|
||||
.flowAttack(0)
|
||||
.flowClean(0)
|
||||
.build();
|
||||
|
||||
rspInfo.getItems().add(taskInfoData);
|
||||
taskInfoData.setId(v.getDeviceId().toString());
|
||||
|
@ -516,8 +516,8 @@ public class DisposeTaskController {
|
|||
|
||||
if (reqInfo.getTaskId().length != 0) {
|
||||
List<String> unExists = Arrays.stream(reqInfo.getTaskId())
|
||||
.filter(v -> valuableData.stream().noneMatch(k -> k.getId() == Long.parseLong(v)))
|
||||
.collect(Collectors.toList());
|
||||
.filter(v -> valuableData.stream().noneMatch(k -> k.getId() == Long.parseLong(v)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
unExists.forEach(v -> {
|
||||
log.error("No such task, taskId:{}", v);
|
||||
|
|
Loading…
Reference in New Issue