Merge remote-tracking branch 'origin/v2.0.0_dev' into v2.0.0_dev
This commit is contained in:
commit
5af7cca3fd
|
@ -201,7 +201,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
|
|||
|
||||
// 遍历设备攻击类型
|
||||
for (DpTechAttackType t : DpTechAttackType.maskToDdosAttackType(deviceTask.getTaskAttackType())) {
|
||||
// 入方向
|
||||
// 出方向
|
||||
if (disposeTask.getFlowDirection() != NetflowDirection.DIRECTION_IN) {
|
||||
// 已经启动过的任务不再重复启动
|
||||
if ((deviceTask.getExecAttackTypeOut() & t.getAttackTypeMask()) != 0) {
|
||||
|
@ -239,7 +239,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
|
|||
}
|
||||
}
|
||||
|
||||
// 出方向
|
||||
// 入方向
|
||||
if (disposeTask.getFlowDirection() != NetflowDirection.DIRECTION_OUT) {
|
||||
// 已经启动过的任务不再重复启动
|
||||
if ((deviceTask.getExecAttackTypeIn() & t.getAttackTypeMask()) != 0) {
|
||||
|
@ -284,7 +284,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
|
|||
// 获取处置任务当前在设备上的执行状态
|
||||
DeviceTask devTask = deviceTaskManager.getTaskById(deviceTask.getId());
|
||||
|
||||
// 入方向
|
||||
// 出方向
|
||||
if (disposeTask.getFlowDirection() != NetflowDirection.DIRECTION_IN) {
|
||||
if (!devTask.getExecAttackTypeOut().equals(devTask.getTaskAttackType())
|
||||
|| !devTask.getExecAttackTypeOut().equals(devTask.getAttackTypeStatusOut())) {
|
||||
|
@ -292,7 +292,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
|
|||
}
|
||||
}
|
||||
|
||||
// 出方向
|
||||
// 入方向
|
||||
if (disposeTask.getFlowDirection() != NetflowDirection.DIRECTION_OUT) {
|
||||
if (!devTask.getExecAttackTypeIn().equals(devTask.getTaskAttackType())
|
||||
|| !devTask.getExecAttackTypeIn().equals(devTask.getAttackTypeStatusIn())) {
|
||||
|
@ -322,7 +322,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
|
|||
|
||||
// 遍历处置设备执行成功的攻击类型
|
||||
for (DpTechAttackType t : DpTechAttackType.maskToDdosAttackType(deviceTask.getAttackTypeStatusIn())) {
|
||||
// 入方向
|
||||
// 出方向
|
||||
if (disposeTask.getFlowDirection() != NetflowDirection.DIRECTION_IN) {
|
||||
// 调用迪普设备停止处置任务
|
||||
ret = ai.getDb().stopDispose(disposeTask.getDisposeIp(), disposeTask.getDisposeCapacity(),
|
||||
|
@ -348,7 +348,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
|
|||
}
|
||||
}
|
||||
|
||||
// 出方向
|
||||
// 入方向
|
||||
if (disposeTask.getFlowDirection() != NetflowDirection.DIRECTION_OUT) {
|
||||
// 调用迪普设备启动处置任务
|
||||
ret = ai.getDb().stopDispose(disposeTask.getDisposeIp(), disposeTask.getDisposeCapacity(),
|
||||
|
@ -382,14 +382,14 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
|
|||
// 获取处置任务当前在设备上的执行状态
|
||||
DeviceTask devTask = deviceTaskManager.getTaskById(deviceTask.getId());
|
||||
|
||||
// 入方向
|
||||
// 出方向
|
||||
if (disposeTask.getFlowDirection() != NetflowDirection.DIRECTION_IN) {
|
||||
if (devTask.getAttackTypeStatusOut() != 0) {
|
||||
taskStopSucceed = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 出方向
|
||||
// 入方向
|
||||
if (disposeTask.getFlowDirection() != NetflowDirection.DIRECTION_OUT) {
|
||||
if (devTask.getAttackTypeStatusIn() != 0) {
|
||||
taskStopSucceed = false;
|
||||
|
|
|
@ -54,10 +54,6 @@
|
|||
user_account
|
||||
SET lastAccess = CURRENT_TIMESTAMP
|
||||
WHERE username = #{username, jdbcType=VARCHAR};
|
||||
|
||||
SELECT lastAccess
|
||||
FROM user_account
|
||||
WHERE username = #{username, jdbcType=VARCHAR}
|
||||
</select>
|
||||
|
||||
<update id="upgradeLoginTime">
|
||||
|
|
|
@ -0,0 +1,262 @@
|
|||
package com.dispose.test.manager;
|
||||
|
||||
import com.dispose.common.DisposeTaskStatus;
|
||||
import com.dispose.common.NetflowDirection;
|
||||
import com.dispose.manager.DeviceTaskManager;
|
||||
import com.dispose.mapper.DeviceTaskMapper;
|
||||
import com.dispose.mapper.DisposeTaskMapper;
|
||||
import com.dispose.pojo.entity.DeviceTask;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Assert;
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.MethodSorters;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.annotation.Rollback;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The type Dispose device manager test.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@Slf4j
|
||||
@SpringBootTest
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
@Transactional
|
||||
@Rollback
|
||||
public class DeviceTaskManagerTest {
|
||||
/**
|
||||
* The Object mapper.
|
||||
*/
|
||||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
/**
|
||||
* The device task mapper.
|
||||
*/
|
||||
@Resource
|
||||
private DeviceTaskMapper deviceTaskMapper;
|
||||
/**
|
||||
* The device task manager.
|
||||
*/
|
||||
@Resource
|
||||
private DeviceTaskManager deviceTaskManager;
|
||||
/**
|
||||
* The Dispose task mapper.
|
||||
*/
|
||||
@Resource
|
||||
private DisposeTaskMapper disposeTaskMapper;
|
||||
|
||||
/**
|
||||
* A 1 add dispose device task info boolean.
|
||||
*/
|
||||
@Test
|
||||
public void a1_addDisposeDeviceTaskInfo() {
|
||||
Long deviceId = disposeTaskMapper.selectAll().get(0).getDeviceId();
|
||||
Long taskId = disposeTaskMapper.selectAll().get(0).getId();
|
||||
|
||||
// 如果已经存在相同任务,不再添加重复任务
|
||||
deviceTaskMapper.selectAll().forEach(v -> {
|
||||
boolean result = deviceTaskManager.addDisposeDeviceTaskInfo(v.getTaskId(), v.getDeviceId(), v.getTaskAttackType());
|
||||
log.info("result-->{}", result);
|
||||
Assert.assertTrue(result);
|
||||
});
|
||||
|
||||
|
||||
DeviceTask deviceTask = DeviceTask.builder()
|
||||
.taskId(taskId)
|
||||
.deviceId(deviceId)
|
||||
.taskAttackType(10737508815L)
|
||||
.build();
|
||||
|
||||
boolean addResult = deviceTaskManager.addDisposeDeviceTaskInfo(deviceTask.getTaskId(), deviceTask.getDeviceId(),
|
||||
deviceTask.getTaskAttackType());
|
||||
log.info("addResult-->{}", addResult);
|
||||
Assert.assertTrue(addResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* A 2 gets new dispose device task info.
|
||||
*/
|
||||
@Test
|
||||
public void a2_getNewDisposeDeviceTaskInfo() throws JsonProcessingException {
|
||||
List<DeviceTask> deviceTaskList = deviceTaskMapper.selectAll();
|
||||
|
||||
long newNumber = deviceTaskList.stream().filter(v -> (v.getStatus() == (long) DisposeTaskStatus.TASK_NEW.getValue())
|
||||
|| (v.getStatus() == (long) DisposeTaskStatus.TASK_STARTING.getValue())).count();
|
||||
log.info("newNumber-->{}", newNumber);
|
||||
|
||||
if (newNumber > 0) {
|
||||
List<DeviceTask> newTask = deviceTaskManager.getNewDisposeDeviceTaskInfo();
|
||||
log.info("newTask: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(newTask));
|
||||
|
||||
Assert.assertNotNull(newTask);
|
||||
Assert.assertNotEquals(newTask.size(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A 3 gets started dispose device task info.
|
||||
*/
|
||||
@Test
|
||||
public void a3_getStartedDisposeDeviceTaskInfo() throws JsonProcessingException {
|
||||
List<DeviceTask> deviceTaskList = deviceTaskMapper.selectAll();
|
||||
|
||||
long startedNumber = deviceTaskList.stream().filter(v -> (v.getStatus() == (long) DisposeTaskStatus.TASK_NEW.getValue())
|
||||
|| (v.getStatus() == (long) DisposeTaskStatus.TASK_STARTING.getValue()
|
||||
|| (v.getStatus() == (long) DisposeTaskStatus.TASK_STARTED.getValue()))).count();
|
||||
log.info("startedNumber-->{}", startedNumber);
|
||||
|
||||
if (startedNumber > 0) {
|
||||
List<DeviceTask> startedTask = deviceTaskManager.getStartedDisposeDeviceTaskInfo();
|
||||
log.info("startedTask: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(startedTask));
|
||||
|
||||
Assert.assertNotNull(startedTask);
|
||||
Assert.assertNotEquals(startedTask.size(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A 4 change dispose device task info status.
|
||||
*/
|
||||
@Test
|
||||
public void a4_changeDisposeDeviceTaskInfoStatus() {
|
||||
DeviceTask deviceTask = deviceTaskMapper.selectAll().get(0);
|
||||
|
||||
for (DisposeTaskStatus status : DisposeTaskStatus.values()
|
||||
) {
|
||||
boolean result = deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(), status);
|
||||
Assert.assertTrue(result);
|
||||
Assert.assertEquals(Long.valueOf(status.getValue()), deviceTaskMapper.getTaskInfoById(deviceTask.getId()).getStatus());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A 5 exec attack type.
|
||||
*/
|
||||
@Test
|
||||
public void a5_execAttackType() {
|
||||
DeviceTask deviceTask = deviceTaskMapper.selectAll().get(0);
|
||||
|
||||
//sets exec attack type
|
||||
for (NetflowDirection nf : NetflowDirection.values()
|
||||
) {
|
||||
for (long i = 10737508814L; i <= 10737508824L; i++) {
|
||||
boolean result = deviceTaskManager.setExecAttackType(deviceTask.getId(), nf, i);
|
||||
Assert.assertTrue(result);
|
||||
|
||||
if (nf == NetflowDirection.DIRECTION_IN) {
|
||||
Assert.assertEquals(String.valueOf(i), String.valueOf(deviceTaskMapper.getTaskInfoById(deviceTask.getId()).getExecAttackTypeIn()));
|
||||
} else {
|
||||
Assert.assertEquals(String.valueOf(i), String.valueOf(deviceTaskMapper.getTaskInfoById(deviceTask.getId()).getExecAttackTypeOut()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//exec attack type clean bits
|
||||
for (NetflowDirection nf : NetflowDirection.values()
|
||||
) {
|
||||
deviceTaskManager.execAttackTypeCleanBit(deviceTask.getId(), nf, 2);
|
||||
deviceTaskManager.execAttackTypeCleanBit(deviceTask.getId(), nf, 4);
|
||||
}
|
||||
|
||||
//exec attack type set bits
|
||||
for (NetflowDirection nf : NetflowDirection.values()
|
||||
) {
|
||||
deviceTaskManager.execAttackTypeSetBit(deviceTask.getId(), nf, 2);
|
||||
deviceTaskManager.execAttackTypeSetBit(deviceTask.getId(), nf, 4);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A 6 exec attack type status.
|
||||
*/
|
||||
@Test
|
||||
public void a6_attackTypeStatus() {
|
||||
DeviceTask deviceTask = deviceTaskMapper.selectAll().get(0);
|
||||
|
||||
//sets exec attack type
|
||||
for (NetflowDirection nf : NetflowDirection.values()
|
||||
) {
|
||||
for (long i = 10737508814L; i <= 10737508824L; i++) {
|
||||
boolean result = deviceTaskManager.setAttackTypeStatus(deviceTask.getId(), nf, i);
|
||||
Assert.assertTrue(result);
|
||||
|
||||
if (nf == NetflowDirection.DIRECTION_IN) {
|
||||
Assert.assertEquals(String.valueOf(i), String.valueOf(deviceTaskMapper.getTaskInfoById(deviceTask.getId()).getAttackTypeStatusIn()));
|
||||
} else {
|
||||
Assert.assertEquals(String.valueOf(i), String.valueOf(deviceTaskMapper.getTaskInfoById(deviceTask.getId()).getAttackTypeStatusOut()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//attack type status clean bits
|
||||
for (NetflowDirection nf : NetflowDirection.values()
|
||||
) {
|
||||
deviceTaskManager.attackTypeStatusCleanBit(deviceTask.getId(), nf, 2);
|
||||
deviceTaskManager.attackTypeStatusCleanBit(deviceTask.getId(), nf, 4);
|
||||
}
|
||||
|
||||
//attack type status set bits
|
||||
for (NetflowDirection nf : NetflowDirection.values()
|
||||
) {
|
||||
deviceTaskManager.attackTypeStatusSetBit(deviceTask.getId(), nf, 2);
|
||||
deviceTaskManager.attackTypeStatusSetBit(deviceTask.getId(), nf, 4);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A 7 sets task error retry times.
|
||||
*/
|
||||
@Test
|
||||
public void a7_setTaskErrRetryTimes() {
|
||||
DeviceTask deviceTask = deviceTaskMapper.selectAll().get(0);
|
||||
|
||||
for (int i = 0; i <= 5; i++) {
|
||||
boolean result = deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), i);
|
||||
Assert.assertTrue(result);
|
||||
Assert.assertEquals(String.valueOf(i), String.valueOf(deviceTaskMapper.getTaskInfoById(deviceTask.getId()).getErrRetry()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A 8 sets task extern id.
|
||||
*/
|
||||
@Test
|
||||
public void a8_setTaskExternId() {
|
||||
DeviceTask deviceTask = deviceTaskMapper.selectAll().get(0);
|
||||
|
||||
for (long i = 223L; i <= 230L; i++) {
|
||||
boolean result = deviceTaskManager.setTaskExternId(deviceTask.getId(), i);
|
||||
Assert.assertTrue(result);
|
||||
Assert.assertEquals(String.valueOf(i), String.valueOf(deviceTaskMapper.getTaskInfoById(deviceTask.getId()).getExternId()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A 9 gets task by id.
|
||||
*/
|
||||
@Test
|
||||
public void a9_getTaskById() {
|
||||
deviceTaskMapper.selectAll().forEach(v -> {
|
||||
DeviceTask deviceTask = deviceTaskManager.getTaskById(v.getId());
|
||||
|
||||
try {
|
||||
log.info("deviceTask: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(deviceTask));
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Assert.assertNotNull(deviceTask);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,11 +1,9 @@
|
|||
package com.dispose.test.manager;
|
||||
|
||||
import com.dispose.common.DisposeDeviceType;
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.common.HttpType;
|
||||
import com.dispose.common.ObjectStatus;
|
||||
import com.dispose.common.*;
|
||||
import com.dispose.manager.DisposeDeviceManager;
|
||||
import com.dispose.mapper.DisposeDeviceMapper;
|
||||
import com.dispose.pojo.entity.DisposeCapacity;
|
||||
import com.dispose.pojo.entity.DisposeDevice;
|
||||
import com.dispose.pojo.po.MulReturnType;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
|
@ -62,6 +60,16 @@ public class DisposeDeviceManagerTest {
|
|||
*/
|
||||
@Test
|
||||
public void a1_addDisposeDevice() {
|
||||
Long deviceId = disposeDeviceMapper.selectAll().get(0).getId();
|
||||
List<DisposeCapacity> devCap = new ArrayList<>();
|
||||
|
||||
devCap.add(DisposeCapacity.builder()
|
||||
.deviceId(deviceId)
|
||||
.ipType(IpAddrType.IPV4_IPV6)
|
||||
.capacityType(DisposeCapacityType.CLEANUP)
|
||||
.objectType(DisposeObjectType.IP)
|
||||
.protectIp("")
|
||||
.build());
|
||||
|
||||
for (int i = 1; i < 3; i++) {
|
||||
String ipAddr = "192.168.0." + i;
|
||||
|
@ -81,6 +89,7 @@ public class DisposeDeviceManagerTest {
|
|||
.urlType(HttpType.HTTP)
|
||||
.readme("实验室测试设备")
|
||||
.status(ObjectStatus.NORMAL)
|
||||
.devCapacity(devCap)
|
||||
.build();
|
||||
|
||||
MulReturnType<ErrorCode, Long> ret = disposeDeviceManager.addDisposeDevice(dev);
|
||||
|
@ -122,6 +131,16 @@ public class DisposeDeviceManagerTest {
|
|||
*/
|
||||
@Test
|
||||
public void a2_upgradeDisposeDevice() throws JsonProcessingException {
|
||||
Long deviceId = disposeDeviceMapper.selectAll().get(0).getId();
|
||||
List<DisposeCapacity> devCap = new ArrayList<>();
|
||||
|
||||
devCap.add(DisposeCapacity.builder()
|
||||
.deviceId(deviceId)
|
||||
.ipType(IpAddrType.IPV4_IPV6)
|
||||
.capacityType(DisposeCapacityType.CLEANUP)
|
||||
.objectType(DisposeObjectType.IP)
|
||||
.protectIp("")
|
||||
.build());
|
||||
|
||||
for (int i = 1; i < 3; i++) {
|
||||
String ipAddr = "192.168.0." + i;
|
||||
|
@ -141,6 +160,7 @@ public class DisposeDeviceManagerTest {
|
|||
.urlType(HttpType.HTTP)
|
||||
.readme("实验室测试设备")
|
||||
.status(ObjectStatus.NORMAL)
|
||||
.devCapacity(devCap)
|
||||
.build();
|
||||
|
||||
disposeDeviceManager.addDisposeDevice(dev);
|
||||
|
|
|
@ -0,0 +1,114 @@
|
|||
package com.dispose.test.service;
|
||||
|
||||
import com.dispose.common.*;
|
||||
import com.dispose.mapper.DisposeDeviceMapper;
|
||||
import com.dispose.mapper.DisposeTaskMapper;
|
||||
import com.dispose.mapper.UserAccountMapper;
|
||||
import com.dispose.pojo.entity.DisposeTask;
|
||||
import com.dispose.pojo.po.MulReturnType;
|
||||
import com.dispose.service.DeviceTaskManagerService;
|
||||
import com.dispose.service.UserAccountService;
|
||||
import com.dispose.test.Global.InitTestEnvironment;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Before;
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.MethodSorters;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.annotation.Rollback;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
/**
|
||||
* The type User account service test.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@Slf4j
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
@Transactional
|
||||
@Rollback
|
||||
public class DeviceTaskManagerServiceTest extends InitTestEnvironment {
|
||||
/**
|
||||
* The constant token.
|
||||
*/
|
||||
private static String token = "";
|
||||
/**
|
||||
* The User account service.
|
||||
*/
|
||||
@Resource
|
||||
private UserAccountService userAccountService;
|
||||
/**
|
||||
* The device task manager service.
|
||||
*/
|
||||
@Resource
|
||||
private DeviceTaskManagerService deviceTaskManagerService;
|
||||
/**
|
||||
* The Object mapper.
|
||||
*/
|
||||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
/**
|
||||
* The user account mapper.
|
||||
*/
|
||||
@Resource
|
||||
private UserAccountMapper userAccountMapper;
|
||||
/**
|
||||
* The Dispose device mapper.
|
||||
*/
|
||||
@Resource
|
||||
private DisposeDeviceMapper disposeDeviceMapper;
|
||||
/**
|
||||
* The Dispose task mapper.
|
||||
*/
|
||||
@Resource
|
||||
private DisposeTaskMapper disposeTaskMapper;
|
||||
|
||||
/**
|
||||
* User login test.
|
||||
*
|
||||
* @throws NoSuchAlgorithmException the no such algorithm exception
|
||||
*/
|
||||
@Before
|
||||
public void userLoginTest() throws NoSuchAlgorithmException {
|
||||
MulReturnType<ErrorCode, String> ret = userAccountService.loginService(getUSER_NAME(),
|
||||
getPASSWORD());
|
||||
|
||||
if (ret.getFirstParam() == ErrorCode.ERR_OK) {
|
||||
DeviceTaskManagerServiceTest.token = ret.getSecondParam();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule runner thread.
|
||||
*/
|
||||
@Test
|
||||
public void a1_scheduleRunnerThread() throws JsonProcessingException {
|
||||
Long uId = userAccountMapper.selectAll().get(0).getId();
|
||||
Long dId = disposeDeviceMapper.selectAll().get(0).getId();
|
||||
|
||||
DisposeTask task = DisposeTask.builder()
|
||||
.deviceId(dId)
|
||||
.accountId(uId)
|
||||
.disposeCapacity(DisposeCapacityType.CLEANUP)
|
||||
.disposeIp("192.168.0.1")
|
||||
.planEndTime("30")
|
||||
.flowDirection(NetflowDirection.DIRECTION_BI)
|
||||
.attackType(DDoSAttackType.getTypeMaskFromAttackType(new DDoSAttackType[]{DDoSAttackType.ALL_ATTACKS}))
|
||||
.flowBandWidth(1024)
|
||||
.build();
|
||||
|
||||
disposeTaskMapper.addNewTask(task);
|
||||
log.info("DisposeTask: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(task));
|
||||
|
||||
deviceTaskManagerService.scheduleRunnerThread();
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@ import com.dispose.common.DisposeDeviceType;
|
|||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.common.HttpType;
|
||||
import com.dispose.common.ObjectStatus;
|
||||
import com.dispose.mapper.DisposeDeviceMapper;
|
||||
import com.dispose.pojo.entity.DisposeDevice;
|
||||
import com.dispose.pojo.po.AbilityInfo;
|
||||
import com.dispose.pojo.po.MulReturnType;
|
||||
|
@ -54,6 +55,11 @@ public class DisposeAbilityRouterServiceTest extends InitTestEnvironment {
|
|||
*/
|
||||
@Resource
|
||||
private DisposeAbilityRouterService disposeAbilityRouterService;
|
||||
/**
|
||||
* The dispose device mapper.
|
||||
*/
|
||||
@Resource
|
||||
private DisposeDeviceMapper disposeDeviceMapper;
|
||||
/**
|
||||
* The Object mapper.
|
||||
*/
|
||||
|
@ -117,10 +123,69 @@ public class DisposeAbilityRouterServiceTest extends InitTestEnvironment {
|
|||
List<AbilityInfo> abilityInfoList = disposeAbilityRouterService.getAllAbilityDevices();
|
||||
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(abilityInfoList));
|
||||
|
||||
abilityInfoList.forEach(v->{
|
||||
abilityInfoList.forEach(v -> {
|
||||
Assert.assertNotNull(v.getDb());
|
||||
Assert.assertNotNull(v.getDev());
|
||||
Assert.assertFalse(v.isLinkStatus());
|
||||
|
||||
if(v.getDev().getDeviceType() == DisposeDeviceType.VIRTUAL_DISPOSE){
|
||||
Assert.assertNull(v.getFirewareInfo());
|
||||
Assert.assertFalse(v.isLinkStatus());
|
||||
}else{
|
||||
Assert.assertNotNull(v.getFirewareInfo());
|
||||
Assert.assertTrue(v.isLinkStatus());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* A 3 Gets ability device by ipAddr and ipPort.
|
||||
*/
|
||||
@Test
|
||||
public void a3_getAbilityDeviceTest() throws JsonProcessingException {
|
||||
List<DisposeDevice> deviceList = disposeDeviceMapper.selectAll();
|
||||
|
||||
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(deviceList));
|
||||
|
||||
deviceList.forEach(v -> {
|
||||
AbilityInfo abilityInfo = disposeAbilityRouterService.getAbilityDevice(v.getIpAddr(), v.getIpPort());
|
||||
|
||||
Assert.assertNotNull(abilityInfo);
|
||||
Assert.assertNotNull(abilityInfo.getDb());
|
||||
Assert.assertNotNull(abilityInfo.getDev());
|
||||
|
||||
if(abilityInfo.getDev().getDeviceType() == DisposeDeviceType.VIRTUAL_DISPOSE){
|
||||
Assert.assertNull(abilityInfo.getFirewareInfo());
|
||||
Assert.assertFalse(abilityInfo.isLinkStatus());
|
||||
}else{
|
||||
Assert.assertNotNull(abilityInfo.getFirewareInfo());
|
||||
Assert.assertTrue(abilityInfo.isLinkStatus());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* A 4 Gets ability device by id.
|
||||
*/
|
||||
@Test
|
||||
public void a4_getAbilityDevice() throws JsonProcessingException {
|
||||
List<DisposeDevice> deviceList = disposeDeviceMapper.selectAll();
|
||||
|
||||
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(deviceList));
|
||||
|
||||
deviceList.forEach(v -> {
|
||||
AbilityInfo abilityInfo = disposeAbilityRouterService.getAbilityDevice(v.getId());
|
||||
|
||||
Assert.assertNotNull(abilityInfo);
|
||||
Assert.assertNotNull(abilityInfo.getDb());
|
||||
Assert.assertNotNull(abilityInfo.getDev());
|
||||
|
||||
if(abilityInfo.getDev().getDeviceType() == DisposeDeviceType.VIRTUAL_DISPOSE){
|
||||
Assert.assertNull(abilityInfo.getFirewareInfo());
|
||||
Assert.assertFalse(abilityInfo.isLinkStatus());
|
||||
}else{
|
||||
Assert.assertNotNull(abilityInfo.getFirewareInfo());
|
||||
Assert.assertTrue(abilityInfo.isLinkStatus());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue