REM:
1. 增加获取能力节点处置中任务接口和服务
2. 增加获取能力节点所有处置任务接口和服务
3. 修改部分对象数据类型为包装类型,支持默认Mapper接口
4. 执行重新格式化代码
5. 执行清理代码操作
6. 执行JavaDoc更新操作
This commit is contained in:
huangxin 2020-04-27 14:00:01 +08:00
parent 3e5f642c3b
commit f5bd8cd02c
23 changed files with 502 additions and 53 deletions

View File

@ -286,11 +286,72 @@
}
```
## 获取能力节点处置中任务
+ 请求命令
字段|内容
----|----
Request URI|dispose/information/run_task
Content type|application/json;charset=UTF-8
Authorization|"Bearer b8f01b8303cd9fcb7d3c9ed1b1c54d4a6e04bac3a66ab7df6ba81f690882ca2e"
Body|{"ver":2,"cryptoType":0,"timeStamp":1587604330447,"msgContent":"{\"id\":[\"242\",\"123\"]}"}
```json
{
"ver": 2,
"cryptoType": 0,
"timeStamp": 1587604330447,
"msgContent": "{\"id\":[\"242\",\"123\"]}"
}
```
+ 响应消息
字段|内容
----|----
Content type|application/json;charset=UTF-8
Body|{"ver":2,"cryptoType":0,"timeStamp":1587959081368,"code":200,"msgContent":"{\"items\":[{\"id\":\"242\",\"taskArray\":[{\"taskId\":\"180\",\"type\":0,\"disposeIp\":\"192.168.0.1\",\"startTime\":1587890555,\"disposeTime\":3596,\"flowAttack\":0,\"flowClean\":0}],\"status\":0,\"message\":\"成功\"},{\"id\":\"123\",\"taskArray\":[],\"status\":19,\"message\":\"没有这个设备\"}]}"}
```json
{
"ver": 2,
"cryptoType": 0,
"timeStamp": 1587959081368,
"code": 200,
"msgContent": "{\"items\":[{\"id\":\"242\",\"taskArray\":[{\"taskId\":\"180\",\"type\":0,\"disposeIp\":\"192.168.0.1\",\"startTime\":1587890555,\"disposeTime\":3596,\"flowAttack\":0,\"flowClean\":0}],\"status\":0,\"message\":\"成功\"},{\"id\":\"123\",\"taskArray\":[],\"status\":19,\"message\":\"没有这个设备\"}]}"
}
```
## 获取能力节点所有处置任务
+ 请求命令
字段|内容
----|----
Request URI|dispose/information/all_task
Content type|application/json;charset=UTF-8
Authorization|"Bearer b8f01b8303cd9fcb7d3c9ed1b1c54d4a6e04bac3a66ab7df6ba81f690882ca2e"
Body|{"ver":2,"cryptoType":0,"timeStamp":1587604330447,"msgContent":"{\"id\":[\"242\",\"123\"]}"}
```json
{
"ver": 2,
"cryptoType": 0,
"timeStamp": 1587604330447,
"msgContent": "{\"id\":[\"242\",\"123\"]}"
}
```
+ 响应消息
字段|内容
----|----
Content type|application/json;charset=UTF-8
Body|{"ver":2,"cryptoType":0,"timeStamp":1587959355300,"code":200,"msgContent":"{\"items\":[{\"id\":\"242\",\"taskArray\":[{\"taskId\":\"180\",\"type\":0,\"disposeIp\":\"192.168.0.1\",\"startTime\":1587890555,\"disposeTime\":3596,\"flowAttack\":0,\"flowClean\":0}],\"status\":0,\"message\":\"成功\"},{\"id\":\"123\",\"taskArray\":[],\"status\":19,\"message\":\"没有这个设备\"}]}"}
```json
{
"ver": 2,
"cryptoType": 0,
"timeStamp": 1587959355300,
"code": 200,
"msgContent": "{\"items\":[{\"id\":\"242\",\"taskArray\":[{\"taskId\":\"180\",\"type\":0,\"disposeIp\":\"192.168.0.1\",\"startTime\":1587890555,\"disposeTime\":3596,\"flowAttack\":0,\"flowClean\":0}],\"status\":0,\"message\":\"成功\"},{\"id\":\"123\",\"taskArray\":[],\"status\":19,\"message\":\"没有这个设备\"}]}"
}
```
## 获取能力节点列表
+ 请求命令
字段|内容
----|----
Request URI|dispose/information/node_list
----|----
Request URI|dispose/information/node_list
Content type|application/json;charset=UTF-8
Authorization|"Bearer b8f01b8303cd9fcb7d3c9ed1b1c54d4a6e04bac3a66ab7df6ba81f690882ca2e"

View File

@ -1,10 +1,8 @@
package com.dispose.Interceptor;
import com.dispose.common.ConstValue;
import java.io.IOException;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.UnsupportedCallbackException;
import org.apache.wss4j.common.ext.WSPasswordCallback;
/**
@ -15,11 +13,9 @@ public class SoapPasswordCallbackHandler implements CallbackHandler {
* Handle.
*
* @param callbacks the callbacks
* @throws IOException the io exception
* @throws UnsupportedCallbackException the unsupported callback exception
*/
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
public void handle(Callback[] callbacks) {
WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
pc.setPassword(ConstValue.SOAPWrapperConst.PASSWORD);
}

View File

@ -5,23 +5,23 @@ package com.dispose.common;
*/
public enum DisposeTaskStatus {
/**
* Task new dispose task status.
* The Task new.
*/
TASK_NEW(0, "新建"),
/**
* Task running dispose task status.
* The Task running.
*/
TASK_RUNNING(1, "运行中"),
/**
* Task stop dispose task status.
* The Task stop.
*/
TASK_STOP(2, "停止"),
/**
* Task finish dispose task status.
* The Task finish.
*/
TASK_FINISH(3, "结束"),
/**
* Task delete dispose task status.
* The Task delete.
*/
TASK_DELETE(4, "删除");

View File

@ -111,12 +111,18 @@ public enum ErrorCode {
ERR_TASKRUNNING(26, "同类任务正在运行"),
/**
* Err nosupport error code.
* The Err unsupport.
*/
ERR_UNSUPPORT(27, "不支持的操作"),
/**
* Err interrupt error code.
*/
ERR_INTERRUPT(28, "操作中断"),
/**
* Err calldevice error code.
*/
ERR_CALLDEVICE(29, "调用设备失败"),
;

View File

@ -5,15 +5,15 @@ package com.dispose.common;
*/
public enum FlowDirection {
/**
* Direction input flow direction.
* The Direction input.
*/
DIRECTION_INPUT(0, "流入"),
/**
* Direction output flow direction.
* The Direction output.
*/
DIRECTION_OUTPUT(1, "流出"),
/**
* Direction twoway flow direction.
* The Direction twoway.
*/
DIRECTION_TWOWAY(2, "双向");

View File

@ -7,6 +7,7 @@ import com.dispose.pojo.dto.ProtocolRespDTO;
import com.dispose.pojo.entity.DisposeDevice;
import com.dispose.pojo.vo.common.DisposeCapacity;
import com.dispose.pojo.vo.common.IDArrayReq;
import com.dispose.pojo.vo.common.TaskInfoData;
import com.dispose.pojo.vo.information.DeviceCapacityData;
import com.dispose.pojo.vo.information.DeviceCapacityRsp;
import com.dispose.pojo.vo.information.DeviceInfoData;
@ -14,14 +15,20 @@ import com.dispose.pojo.vo.information.DeviceInfoRsp;
import com.dispose.pojo.vo.information.DisposeNodeData;
import com.dispose.pojo.vo.information.DisposeNodeListRsp;
import com.dispose.pojo.vo.information.LinkStatusRsp;
import com.dispose.pojo.vo.information.NodeTaskData;
import com.dispose.pojo.vo.information.NodeTaskRsp;
import com.dispose.pojo.vo.information.VersionRsp;
import com.dispose.service.DisposeNodeManager;
import com.dispose.service.TaskService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders;
@ -42,6 +49,12 @@ import org.springframework.web.bind.annotation.ResponseBody;
@Api(value = "抗DDoS处置平台能力节点信息接口", tags = "抗DDoS处置平台能力节点信息接口")
@Component
public class DisposeNodeInfoController {
/**
* The Task service.
*/
@Resource
private TaskService taskService;
/**
* The Object mapper.
*/
@ -468,7 +481,6 @@ public class DisposeNodeInfoController {
@PostMapping("/node_details")
@ResponseBody
@ApiOperation("处置节点详细信息")
//@JsonView(DisposeCapacity.CapacityView.class)
public ProtocolRespDTO getDisposeNodeDetails(@RequestBody ProtocolReqDTO mr,
@RequestHeader HttpHeaders headers)
throws JsonProcessingException {
@ -535,4 +547,148 @@ public class DisposeNodeInfoController {
}
return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo);
}
/**
* Gets running dispose task list.
*
* @param mr the mr
* @param headers the headers
* @return the running dispose task list
* @throws JsonProcessingException the json processing exception
*/
@PostMapping("/run_task")
@ResponseBody
@ApiOperation("获取正在进行的处置任务")
public ProtocolRespDTO getRunningDisposeTaskList(@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);
NodeTaskRsp rspInfo = new NodeTaskRsp();
List<DisposeDevice> valuableData = disposeNodeManager.getAllDisposeDevice()
.parallelStream()
.filter(v -> reqInfo.getId().length == 0
|| Arrays.stream(reqInfo.getId()).anyMatch(s -> s.equals(v.getId().toString())))
.collect(Collectors.toList());
valuableData.parallelStream().forEach(v -> {
NodeTaskData taskData = new NodeTaskData();
rspInfo.getItems().add(taskData);
taskData.setId(v.getId().toString());
taskData.setStatus(ErrorCode.ERR_OK.getCode());
taskData.setMessage(ErrorCode.ERR_OK.getMsg());
taskService.getNodeAllRunningTask(v.getId()).parallelStream().forEach(k -> {
Long tmLong = Timestamp.valueOf(k.getBeginTime()).toInstant().toEpochMilli() / 1000;
Long endTm = Timestamp.valueOf(k.getPlanEndTime()).toInstant().toEpochMilli() / 1000;
Long diff = endTm - tmLong;
TaskInfoData taskInfoData = TaskInfoData.builder()
.taskId(k.getId().toString())
.type(k.getType())
.startTime(tmLong.intValue())
.disposeTime(diff.intValue())
.disposeIp(k.getDisposeIp())
.flowAttack(0)
.flowClean(0)
.build();
taskData.getTaskArray().add(taskInfoData);
});
});
if (reqInfo.getId().length != 0) {
List<String> unExists = Arrays.stream(reqInfo.getId())
.filter(v -> valuableData.parallelStream().noneMatch(k -> k.getId() == Long.parseLong(v)))
.collect(Collectors.toList());
unExists.parallelStream().forEach(v -> {
NodeTaskData taskData = new NodeTaskData();
rspInfo.getItems().add(taskData);
taskData.setId(v);
taskData.setStatus(ErrorCode.ERR_NOSUCHDEVICE.getCode());
taskData.setMessage(ErrorCode.ERR_NOSUCHDEVICE.getMsg());
});
}
return ProtocolRespDTO.result(err, rspInfo);
}
/**
* Gets all dispose task list.
*
* @param mr the mr
* @param headers the headers
* @return the all dispose task list
* @throws JsonProcessingException the json processing exception
*/
@PostMapping("/all_task")
@ResponseBody
@ApiOperation("获取所有处置任务")
public ProtocolRespDTO getAllDisposeTaskList(@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);
NodeTaskRsp rspInfo = new NodeTaskRsp();
List<DisposeDevice> valuableData = disposeNodeManager.getAllDisposeDevice()
.parallelStream()
.filter(v -> reqInfo.getId().length == 0
|| Arrays.stream(reqInfo.getId()).anyMatch(s -> s.equals(v.getId().toString())))
.collect(Collectors.toList());
valuableData.parallelStream().forEach(v -> {
NodeTaskData taskData = new NodeTaskData();
rspInfo.getItems().add(taskData);
taskData.setId(v.getId().toString());
taskData.setStatus(ErrorCode.ERR_OK.getCode());
taskData.setMessage(ErrorCode.ERR_OK.getMsg());
taskService.getNodeAllTask(v.getId()).parallelStream().forEach(k -> {
Long tmLong = Timestamp.valueOf(k.getBeginTime()).toInstant().toEpochMilli() / 1000;
Long endTm = Timestamp.valueOf(k.getPlanEndTime()).toInstant().toEpochMilli() / 1000;
Long diff = endTm - tmLong;
TaskInfoData taskInfoData = TaskInfoData.builder()
.taskId(k.getId().toString())
.type(k.getType())
.startTime(tmLong.intValue())
.disposeTime(diff.intValue())
.disposeIp(k.getDisposeIp())
.flowAttack(0)
.flowClean(0)
.build();
taskData.getTaskArray().add(taskInfoData);
});
});
if (reqInfo.getId().length != 0) {
List<String> unExists = Arrays.stream(reqInfo.getId())
.filter(v -> valuableData.parallelStream().noneMatch(k -> k.getId() == Long.parseLong(v)))
.collect(Collectors.toList());
unExists.parallelStream().forEach(v -> {
NodeTaskData taskData = new NodeTaskData();
rspInfo.getItems().add(taskData);
taskData.setId(v);
taskData.setStatus(ErrorCode.ERR_NOSUCHDEVICE.getCode());
taskData.setMessage(ErrorCode.ERR_NOSUCHDEVICE.getMsg());
});
}
return ProtocolRespDTO.result(err, rspInfo);
}
}

View File

@ -71,7 +71,7 @@ public class DisposeTaskController {
*/
@PostMapping("/stop")
@ResponseBody
@ApiOperation("启动处置任务")
@ApiOperation("停止处置任务")
public ProtocolRespDTO taskStop(@RequestBody ProtocolReqDTO mr,
@RequestHeader HttpHeaders headers)
throws JsonProcessingException {
@ -97,7 +97,7 @@ public class DisposeTaskController {
taskData.setStatus(err.getCode());
taskData.setMessage(err.getMsg());
rspInfo.getResult().add(taskData);
rspInfo.getItems().add(taskData);
}
return ProtocolRespDTO.result(err, rspInfo);
@ -113,7 +113,7 @@ public class DisposeTaskController {
*/
@PostMapping("/stop_ip")
@ResponseBody
@ApiOperation("启动处置任务")
@ApiOperation("根据处置IP停止处置任务")
public ProtocolRespDTO taskStopByIp(@RequestBody ProtocolReqDTO mr,
@RequestHeader HttpHeaders headers)
throws JsonProcessingException {
@ -135,7 +135,7 @@ public class DisposeTaskController {
taskData.setStatus(err.getCode());
taskData.setMessage(err.getMsg());
rspInfo.getResult().add(taskData);
rspInfo.getItems().add(taskData);
});
return ProtocolRespDTO.result(err, rspInfo);
@ -151,7 +151,7 @@ public class DisposeTaskController {
*/
@PostMapping("/stop_node")
@ResponseBody
@ApiOperation("启动处置任务")
@ApiOperation("停止处置节点处置任务")
public ProtocolRespDTO taskStopAllOfDisposeNode(@RequestBody ProtocolReqDTO mr,
@RequestHeader HttpHeaders headers)
throws JsonProcessingException {
@ -185,7 +185,7 @@ public class DisposeTaskController {
*/
@PostMapping("/get_node")
@ResponseBody
@ApiOperation("启动处置任务")
@ApiOperation("获取节点处置任务")
public ProtocolRespDTO getNodeTask(@RequestBody ProtocolReqDTO mr,
@RequestHeader HttpHeaders headers) throws JsonProcessingException {
return getAllTask(mr, headers);
@ -201,7 +201,7 @@ public class DisposeTaskController {
*/
@PostMapping("/get")
@ResponseBody
@ApiOperation("启动处置任务")
@ApiOperation("获取全部处置任务")
public ProtocolRespDTO getAllTask(@RequestBody ProtocolReqDTO mr,
@RequestHeader HttpHeaders headers)
throws JsonProcessingException {
@ -227,7 +227,7 @@ public class DisposeTaskController {
taskData.setStatus(err.getCode());
taskData.setMessage(err.getMsg());
rspInfo.getResult().add(taskData);
rspInfo.getItems().add(taskData);
}
return ProtocolRespDTO.result(err, rspInfo);

View File

@ -188,11 +188,11 @@ public class DPTechImpl implements DisposeEntryManager {
}
/**
* Run dispose boolean.
* Run dispose error code.
*
* @param ip the ip
* @param type the type
* @return the boolean
* @return the error code
*/
@Override
public ErrorCode runDispose(String ip, DeviceCapacity type) {
@ -225,11 +225,11 @@ public class DPTechImpl implements DisposeEntryManager {
}
/**
* Stop dispose boolean.
* Stop dispose error code.
*
* @param ipAddr the ip addr
* @param type the type
* @return the boolean
* @return the error code
*/
@Override
public ErrorCode stopDispose(String ipAddr, DeviceCapacity type) {

View File

@ -33,11 +33,11 @@ public class VirtualDeviceImpl implements DisposeEntryManager {
}
/**
* Run dispose boolean.
* Run dispose error code.
*
* @param ip the ip
* @param type the type
* @return the boolean
* @return the error code
*/
@Override
public ErrorCode runDispose(String ip, DeviceCapacity type) {
@ -45,11 +45,11 @@ public class VirtualDeviceImpl implements DisposeEntryManager {
}
/**
* Stop dispose boolean.
* Stop dispose error code.
*
* @param ipAddr the ip addr
* @param type the type
* @return the boolean
* @return the error code
*/
@Override
public ErrorCode stopDispose(String ipAddr, DeviceCapacity type) {

View File

@ -1,5 +1,6 @@
package com.dispose.dispose.po;
import java.io.Serializable;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@ -10,7 +11,13 @@ import lombok.NoArgsConstructor;
@Data
@Builder
@NoArgsConstructor
public class DeviceInfo {
public class DeviceInfo implements Serializable {
/**
* The constant serialVersionUID.
*/
private static final long serialVersionUID = 1L;
/**
* The Vendor.
*/

View File

@ -1,5 +1,6 @@
package com.dispose.pojo.po;
import java.io.Serializable;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
@ -16,7 +17,12 @@ import lombok.ToString;
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class DisposeDeviceCapacity {
public class DisposeDeviceCapacity implements Serializable {
/**
* The constant serialVersionUID.
*/
private static final long serialVersionUID = 1L;
/**
* The Capacity.

View File

@ -14,7 +14,7 @@ public class ReturnStatus {
/**
* The Status.
*/
private int status;
private Integer status;
/**
* The Message.
*/

View File

@ -22,7 +22,7 @@ public class DisposeCapacity {
* The Type.
*/
@JsonView(BaseView.class)
private int type;
private Integer type;
/**
* The Dispose ip.
*/
@ -32,12 +32,12 @@ public class DisposeCapacity {
* The Tol capacity.
*/
@JsonView(CapacityView.class)
private int tolCapacity;
private Integer tolCapacity;
/**
* The Used capacity.
*/
@JsonView(CapacityView.class)
private int usedCapacity;
private Integer usedCapacity;
/**
* The interface Base view.

View File

@ -55,4 +55,14 @@ public class TaskInfoData extends IDReturnStatus {
* The Flow band width.
*/
private Integer flowBandWidth;
/**
* The Flow attack.
*/
private Integer flowAttack;
/**
* The Flow clean.
*/
private Integer flowClean;
}

View File

@ -41,7 +41,7 @@ public class TaskInfoDetail implements Serializable {
/**
* The Type.
*/
private int type;
private Integer type;
/**
* The Dispose ip.
*/
@ -61,7 +61,7 @@ public class TaskInfoDetail implements Serializable {
/**
* The Flow direction.
*/
private int flowDirection;
private Integer flowDirection;
/**
* The Attack type.
*/
@ -69,9 +69,9 @@ public class TaskInfoDetail implements Serializable {
/**
* The Flow band width.
*/
private int flowBandWidth;
private Integer flowBandWidth;
/**
* The Current status.
*/
private int currentStatus;
private Integer currentStatus;
}

View File

@ -0,0 +1,35 @@
package com.dispose.pojo.vo.information;
import com.dispose.pojo.vo.common.IDReturnStatus;
import com.dispose.pojo.vo.common.TaskInfoData;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import java.util.ArrayList;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* The type Node task data.
*/
@EqualsAndHashCode(callSuper = true)
@Data
@Builder
@AllArgsConstructor
@JsonPropertyOrder({"id", "taskArray", "status", "message"})
@JsonInclude(JsonInclude.Include.NON_NULL)
public class NodeTaskData extends IDReturnStatus {
/**
* The Task array.
*/
private List<TaskInfoData> taskArray;
/**
* Instantiates a new Node task data.
*/
public NodeTaskData() {
this.taskArray = new ArrayList<>();
}
}

View File

@ -0,0 +1,27 @@
package com.dispose.pojo.vo.information;
import java.util.ArrayList;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
/**
* The type Node task rsp.
*/
@Data
@Builder
@AllArgsConstructor
public class NodeTaskRsp {
/**
* The Items.
*/
private List<NodeTaskData> items;
/**
* Instantiates a new Node task rsp.
*/
public NodeTaskRsp() {
this.items = new ArrayList<>();
}
}

View File

@ -15,14 +15,14 @@ import lombok.Data;
@AllArgsConstructor
public class TaskInfoRsp {
/**
* The Result.
* The Items.
*/
List<TaskInfoData> result;
List<TaskInfoData> items;
/**
* Instantiates a new Task info rsp.
*/
public TaskInfoRsp() {
this.result = new ArrayList<>();
this.items = new ArrayList<>();
}
}

View File

@ -2,6 +2,7 @@ package com.dispose.service;
import com.dispose.common.ErrorCode;
import com.dispose.pojo.vo.common.TaskInfoDetail;
import java.util.List;
/**
* The interface Task service.
@ -59,4 +60,20 @@ public interface TaskService {
* @return the boolean
*/
boolean taskIsExpired(TaskInfoDetail task);
/**
* Gets node all running task.
*
* @param devId the dev id
* @return the node all running task
*/
List<TaskInfoDetail> getNodeAllRunningTask(Long devId);
/**
* Gets node all task.
*
* @param devId the dev id
* @return the node all task
*/
List<TaskInfoDetail> getNodeAllTask(Long devId);
}

View File

@ -11,6 +11,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@ -170,4 +171,37 @@ public class TaskServiceImpl implements TaskService {
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
.isBefore(LocalDateTime.now());
}
/**
* Gets node all running task.
*
* @param devId the dev id
* @return the node all running task
*/
@Override
public List<TaskInfoDetail> getNodeAllRunningTask(Long devId) {
List<TaskInfoDetail> taskList = taskCacheManager
.getAllTask()
.stream()
.filter(v -> v.getCurrentStatus() == DisposeTaskStatus.TASK_RUNNING.getCode()
&& v.getDeviceId().equals(devId))
.collect(Collectors.toList());
if(taskList.size() > 0) {
return taskList;
}
return null;
}
/**
* Gets node all task.
*
* @param devId the dev id
* @return the node all task
*/
@Override
public List<TaskInfoDetail> getNodeAllTask(Long devId) {
return taskCacheManager.getAllTask();
}
}

View File

@ -8,7 +8,7 @@
currentStatus)
VALUES
(#{deviceId}, #{accountId}, #{type}, #{disposeIp},
#{planEndTime}, #{flowDirection}, #{attackType},
date_add(now(), interval #{planEndTime} MINUTE), #{flowDirection}, #{attackType},
#{flowBandWidth}, #{currentStatus}
)
</insert>

View File

@ -478,4 +478,101 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
.getResponse()
.getContentAsString();
}
@Test
public void t8_getNodeAllRunTask() throws Exception {
IDArrayReq reqData = IDArrayReq.builder()
.id(new String[]{String.valueOf(getExistsDeviceId()), "123"})
.build();
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
reqInfo.setVer(ConstValue.Protocol.VERSION);
reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
reqInfo.setTimeStamp(System.currentTimeMillis());
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData));
mockMvc.perform(MockMvcRequestBuilders
.post("/information/run_task")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken())
.content(objectMapper.writeValueAsString(reqInfo)))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(200))
.andReturn()
.getResponse()
.getContentAsString();
}
@Test
public void t8_getNodeAllRunTaskAll() throws Exception {
IDArrayReq reqData = IDArrayReq.builder()
.id(new String[]{})
.build();
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
reqInfo.setVer(ConstValue.Protocol.VERSION);
reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
reqInfo.setTimeStamp(System.currentTimeMillis());
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData));
mockMvc.perform(MockMvcRequestBuilders
.post("/information/run_task")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken())
.content(objectMapper.writeValueAsString(reqInfo)))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(200))
.andReturn()
.getResponse()
.getContentAsString();
}
@Test
public void t9_getNodeAllTask() throws Exception {
IDArrayReq reqData = IDArrayReq.builder()
.id(new String[]{String.valueOf(getExistsDeviceId()), "123"})
.build();
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
reqInfo.setVer(ConstValue.Protocol.VERSION);
reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
reqInfo.setTimeStamp(System.currentTimeMillis());
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData));
mockMvc.perform(MockMvcRequestBuilders
.post("/information/all_task")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken())
.content(objectMapper.writeValueAsString(reqInfo)))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(200))
.andReturn()
.getResponse()
.getContentAsString();
}
@Test
public void t9_getNodeAllTaskAll() throws Exception {
IDArrayReq reqData = IDArrayReq.builder()
.id(new String[]{})
.build();
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
reqInfo.setVer(ConstValue.Protocol.VERSION);
reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
reqInfo.setTimeStamp(System.currentTimeMillis());
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData));
mockMvc.perform(MockMvcRequestBuilders
.post("/information/all_task")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken())
.content(objectMapper.writeValueAsString(reqInfo)))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(200))
.andReturn()
.getResponse()
.getContentAsString();
}
}

View File

@ -7,8 +7,6 @@ import com.dispose.common.FlowDirection;
import com.dispose.pojo.vo.common.TaskInfoDetail;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
@ -79,7 +77,7 @@ public class DisposeTaskMapperTest extends InitTestEnvironment {
* Add new task test.
*/
@Test
public void addNewTaskTest() {
public void t1_addNewTaskTest() {
TaskInfoDetail taskData = TaskInfoDetail.builder()
.id(-1L)
.deviceId(deviceId)
@ -89,8 +87,7 @@ public class DisposeTaskMapperTest extends InitTestEnvironment {
.attackType("0")
.flowDirection(FlowDirection.DIRECTION_TWOWAY.getCode())
.currentStatus(DisposeTaskStatus.TASK_NEW.getCode())
.planEndTime(LocalDateTime.now().plusMinutes(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd " +
"HH:mm:ss")))
.planEndTime("60")
.build();
disposeTaskMapper.addNewTask(taskData);
@ -103,7 +100,7 @@ public class DisposeTaskMapperTest extends InitTestEnvironment {
* Remove task test.
*/
@Test
public void removeTaskTest() {
public void t99_removeTaskTest() {
disposeTaskMapper.selectAll().forEach(v -> {
disposeTaskMapper.removeTaskById(v.getId());
Assert.assertNull(disposeTaskMapper.getTaskInfoById(v.getId()));