diff --git a/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java b/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java index b15ca83a..07d06bc6 100644 --- a/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java +++ b/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java @@ -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; diff --git a/src/test/java/com/dispose/test/service/DeviceTaskManagerServiceTest.java b/src/test/java/com/dispose/test/service/DeviceTaskManagerServiceTest.java new file mode 100644 index 00000000..466daea3 --- /dev/null +++ b/src/test/java/com/dispose/test/service/DeviceTaskManagerServiceTest.java @@ -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 + */ +@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 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(); + } +} \ No newline at end of file