parent
4ee61a1a40
commit
ff02e0c793
|
@ -0,0 +1,242 @@
|
||||||
|
package com.dispose.controller;
|
||||||
|
|
||||||
|
import com.dispose.common.ErrorCode;
|
||||||
|
import com.dispose.pojo.dto.ProtocolReqDTO;
|
||||||
|
import com.dispose.pojo.dto.ProtocolRespDTO;
|
||||||
|
import com.dispose.pojo.vo.common.IDArrayReq;
|
||||||
|
import com.dispose.pojo.vo.task.StartTaskReq;
|
||||||
|
import com.dispose.pojo.vo.task.StartTaskRsp;
|
||||||
|
import com.dispose.pojo.vo.task.StopTaskReq;
|
||||||
|
import com.dispose.pojo.vo.task.TaskInfoRsp;
|
||||||
|
import com.dispose.pojo.vo.task.TaskInfoData;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestHeader;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Dispose task controller.
|
||||||
|
*/
|
||||||
|
@Controller
|
||||||
|
@RequestMapping(value = "/task")
|
||||||
|
@Slf4j
|
||||||
|
@Api(value = "抗DDoS处置平台处置任务接口", tags = "抗DDoS处置平台处置任务接口")
|
||||||
|
@Component
|
||||||
|
public class DisposeTaskController {
|
||||||
|
/**
|
||||||
|
* Task start protocol resp dto.
|
||||||
|
*
|
||||||
|
* @param mr the mr
|
||||||
|
* @param headers the headers
|
||||||
|
* @return the protocol resp dto
|
||||||
|
* @throws JsonProcessingException the json processing exception
|
||||||
|
*/
|
||||||
|
@PostMapping("/start")
|
||||||
|
@ResponseBody
|
||||||
|
@ApiOperation("启动处置任务")
|
||||||
|
@Builder
|
||||||
|
public ProtocolRespDTO taskStart(@RequestBody ProtocolReqDTO mr,
|
||||||
|
@RequestHeader HttpHeaders headers)
|
||||||
|
throws JsonProcessingException {
|
||||||
|
ErrorCode err = mr.verifyRequest(headers);
|
||||||
|
|
||||||
|
if (err != ErrorCode.ERR_OK) {
|
||||||
|
return ProtocolRespDTO.result(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
StartTaskReq reqInfo = mr.getRequestObject(StartTaskReq.class);
|
||||||
|
StartTaskRsp rspInfo = new StartTaskRsp();
|
||||||
|
|
||||||
|
rspInfo.setTaskId(String.valueOf(reqInfo.getId()));
|
||||||
|
rspInfo.setStatus(err.getCode());
|
||||||
|
rspInfo.setMessage(err.getMsg());
|
||||||
|
|
||||||
|
return ProtocolRespDTO.result(err, rspInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Task stop protocol resp dto.
|
||||||
|
*
|
||||||
|
* @param mr the mr
|
||||||
|
* @param headers the headers
|
||||||
|
* @return the protocol resp dto
|
||||||
|
* @throws JsonProcessingException the json processing exception
|
||||||
|
*/
|
||||||
|
@PostMapping("/stop")
|
||||||
|
@ResponseBody
|
||||||
|
@ApiOperation("启动处置任务")
|
||||||
|
@Builder
|
||||||
|
public ProtocolRespDTO taskStop(@RequestBody ProtocolReqDTO mr,
|
||||||
|
@RequestHeader HttpHeaders headers)
|
||||||
|
throws JsonProcessingException {
|
||||||
|
ErrorCode err = mr.verifyRequest(headers);
|
||||||
|
|
||||||
|
if (err != ErrorCode.ERR_OK) {
|
||||||
|
return ProtocolRespDTO.result(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class);
|
||||||
|
TaskInfoRsp rspInfo = new TaskInfoRsp();
|
||||||
|
|
||||||
|
if(reqInfo.getTaskId() == null
|
||||||
|
|| reqInfo.getTaskId().length == 0) {
|
||||||
|
return ProtocolRespDTO.result(ErrorCode.ERR_INPUTMISS);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(String v : reqInfo.getTaskId()) {
|
||||||
|
TaskInfoData taskData = TaskInfoData.builder()
|
||||||
|
.taskId(v)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
taskData.setStatus(err.getCode());
|
||||||
|
taskData.setMessage(err.getMsg());
|
||||||
|
|
||||||
|
rspInfo.getResult().add(taskData);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ProtocolRespDTO.result(err, rspInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Task stop by ip protocol resp dto.
|
||||||
|
*
|
||||||
|
* @param mr the mr
|
||||||
|
* @param headers the headers
|
||||||
|
* @return the protocol resp dto
|
||||||
|
* @throws JsonProcessingException the json processing exception
|
||||||
|
*/
|
||||||
|
@PostMapping("/stop_ip")
|
||||||
|
@ResponseBody
|
||||||
|
@ApiOperation("启动处置任务")
|
||||||
|
@Builder
|
||||||
|
public ProtocolRespDTO taskStopByIp(@RequestBody ProtocolReqDTO mr,
|
||||||
|
@RequestHeader HttpHeaders headers)
|
||||||
|
throws JsonProcessingException {
|
||||||
|
ErrorCode err = mr.verifyRequest(headers);
|
||||||
|
|
||||||
|
if (err != ErrorCode.ERR_OK) {
|
||||||
|
return ProtocolRespDTO.result(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
StopTaskReq reqInfo = mr.getRequestObject(StopTaskReq.class);
|
||||||
|
TaskInfoRsp rspInfo = new TaskInfoRsp();
|
||||||
|
|
||||||
|
reqInfo.getItems().forEach(v -> {
|
||||||
|
TaskInfoData taskData = TaskInfoData.builder()
|
||||||
|
.type(v.getType())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
taskData.setId(v.getId());
|
||||||
|
taskData.setStatus(err.getCode());
|
||||||
|
taskData.setMessage(err.getMsg());
|
||||||
|
|
||||||
|
rspInfo.getResult().add(taskData);
|
||||||
|
});
|
||||||
|
|
||||||
|
return ProtocolRespDTO.result(err, rspInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Task stop all of dispose node protocol resp dto.
|
||||||
|
*
|
||||||
|
* @param mr the mr
|
||||||
|
* @param headers the headers
|
||||||
|
* @return the protocol resp dto
|
||||||
|
* @throws JsonProcessingException the json processing exception
|
||||||
|
*/
|
||||||
|
@PostMapping("/stop_node")
|
||||||
|
@ResponseBody
|
||||||
|
@ApiOperation("启动处置任务")
|
||||||
|
@Builder
|
||||||
|
public ProtocolRespDTO taskStopAllOfDisposeNode(@RequestBody ProtocolReqDTO mr,
|
||||||
|
@RequestHeader HttpHeaders headers)
|
||||||
|
throws JsonProcessingException {
|
||||||
|
return taskStopByIp(mr, headers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Task stop all protocol resp dto.
|
||||||
|
*
|
||||||
|
* @param mr the mr
|
||||||
|
* @param headers the headers
|
||||||
|
* @return the protocol resp dto
|
||||||
|
* @throws JsonProcessingException the json processing exception
|
||||||
|
*/
|
||||||
|
@PostMapping("/stop_all")
|
||||||
|
@ResponseBody
|
||||||
|
@ApiOperation("启动处置任务")
|
||||||
|
@Builder
|
||||||
|
public ProtocolRespDTO taskStopAll(@RequestBody ProtocolReqDTO mr,
|
||||||
|
@RequestHeader HttpHeaders headers)
|
||||||
|
throws JsonProcessingException {
|
||||||
|
return taskStopByIp(mr, headers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets node task.
|
||||||
|
*
|
||||||
|
* @param mr the mr
|
||||||
|
* @param headers the headers
|
||||||
|
* @return the node task
|
||||||
|
*/
|
||||||
|
@PostMapping("/get_node")
|
||||||
|
@ResponseBody
|
||||||
|
@ApiOperation("启动处置任务")
|
||||||
|
@Builder
|
||||||
|
public ProtocolRespDTO getNodeTask(@RequestBody ProtocolReqDTO mr,
|
||||||
|
@RequestHeader HttpHeaders headers) throws JsonProcessingException {
|
||||||
|
return getAllTask(mr, headers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets all task.
|
||||||
|
*
|
||||||
|
* @param mr the mr
|
||||||
|
* @param headers the headers
|
||||||
|
* @return the all task
|
||||||
|
* @throws JsonProcessingException the json processing exception
|
||||||
|
*/
|
||||||
|
@PostMapping("/get")
|
||||||
|
@ResponseBody
|
||||||
|
@ApiOperation("启动处置任务")
|
||||||
|
@Builder
|
||||||
|
public ProtocolRespDTO getAllTask(@RequestBody ProtocolReqDTO mr,
|
||||||
|
@RequestHeader HttpHeaders headers)
|
||||||
|
throws JsonProcessingException {
|
||||||
|
ErrorCode err = mr.verifyRequest(headers);
|
||||||
|
|
||||||
|
if (err != ErrorCode.ERR_OK) {
|
||||||
|
return ProtocolRespDTO.result(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class);
|
||||||
|
TaskInfoRsp rspInfo = new TaskInfoRsp();
|
||||||
|
|
||||||
|
if(reqInfo.getTaskId() == null
|
||||||
|
|| reqInfo.getTaskId().length == 0) {
|
||||||
|
return ProtocolRespDTO.result(ErrorCode.ERR_INPUTMISS);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(String v : reqInfo.getTaskId()) {
|
||||||
|
TaskInfoData taskData = TaskInfoData.builder()
|
||||||
|
.taskId(v)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
taskData.setStatus(err.getCode());
|
||||||
|
taskData.setMessage(err.getMsg());
|
||||||
|
|
||||||
|
rspInfo.getResult().add(taskData);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ProtocolRespDTO.result(err, rspInfo);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
package com.dispose.pojo.vo.common;
|
package com.dispose.pojo.vo.common;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
@ -12,6 +13,8 @@ import lombok.NoArgsConstructor;
|
||||||
@Builder
|
@Builder
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
public class IDArrayReq {
|
public class IDArrayReq {
|
||||||
private String[] id;
|
private String[] id;
|
||||||
|
private String[] taskId;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.dispose.pojo.vo.task;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Start task req.
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
|
public class StartTaskReq {
|
||||||
|
private int id;
|
||||||
|
private int type;
|
||||||
|
private String disposeId;
|
||||||
|
private int disposeTime;
|
||||||
|
private Integer flowDirection;
|
||||||
|
private Integer[] attackType;
|
||||||
|
private Integer flowBandWidth;
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package com.dispose.pojo.vo.task;
|
||||||
|
|
||||||
|
import com.dispose.pojo.vo.common.IDReturnStatus;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@JsonPropertyOrder({"id", "taskId", "expireTime", "status", "message"})
|
||||||
|
public class StartTaskRsp extends IDReturnStatus {
|
||||||
|
private String taskId;
|
||||||
|
private int expireTime;
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.dispose.pojo.vo.task;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
|
public class StopTaskData {
|
||||||
|
private String id;
|
||||||
|
private int type;
|
||||||
|
private String disposeIp;
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.dispose.pojo.vo.task;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import java.util.List;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
|
public class StopTaskReq {
|
||||||
|
List<StopTaskData> items;
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
package com.dispose.pojo.vo.task;
|
||||||
|
|
||||||
|
import com.dispose.pojo.vo.common.IDReturnStatus;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@JsonPropertyOrder({"id", "taskId", "type", "disposeIp", "leftTime", "status", "message"})
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
|
public class TaskInfoData extends IDReturnStatus {
|
||||||
|
private String taskId;
|
||||||
|
private Integer type;
|
||||||
|
private String disposeIp;
|
||||||
|
private Integer leftTime;
|
||||||
|
private Integer startTime;
|
||||||
|
private Integer disposeTime;
|
||||||
|
private Integer flowDirection;
|
||||||
|
private Integer[] attackType;
|
||||||
|
private Integer flowBandWidth;
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
package com.dispose.pojo.vo.task;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Task info rsp.
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class TaskInfoRsp {
|
||||||
|
/**
|
||||||
|
* The Result.
|
||||||
|
*/
|
||||||
|
List<TaskInfoData> result;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Task info rsp.
|
||||||
|
*/
|
||||||
|
public TaskInfoRsp() {
|
||||||
|
this.result = new ArrayList<>();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue