diff --git a/config/logback_debug.xml b/config/logback_debug.xml index d5b6e0ca..c1b9aa3b 100644 --- a/config/logback_debug.xml +++ b/config/logback_debug.xml @@ -1,6 +1,7 @@ + diff --git a/src/main/java/com/dispose/common/DDoSAttackType.java b/src/main/java/com/dispose/common/DDoSAttackType.java index 49d66017..ae5572fc 100644 --- a/src/main/java/com/dispose/common/DDoSAttackType.java +++ b/src/main/java/com/dispose/common/DDoSAttackType.java @@ -226,11 +226,11 @@ public enum DDoSAttackType implements BaseEnum { if (type.equals(ALL_ATTACKS)) { continue; } - mask |= type.getValue() << 1; + mask |= (long)1 << type.getValue(); } } else { for (DDoSAttackType type : types) { - mask |= type.getValue() << 1; + mask |= (long)1 << type.getValue(); } } diff --git a/src/main/java/com/dispose/mapper/TaskInfoMapper.java b/src/main/java/com/dispose/mapper/TaskInfoMapper.java new file mode 100644 index 00000000..1303a9c7 --- /dev/null +++ b/src/main/java/com/dispose/mapper/TaskInfoMapper.java @@ -0,0 +1,44 @@ +package com.dispose.mapper; + +import com.dispose.pojo.entity.TaskInfo; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * The interface Task info mapper. + * + * @author + */ +public interface TaskInfoMapper { + /** + * Select all list. + * + * @return the list + */ + List selectAll(); + + /** + * Gets task info by task id. + * + * @param taskId the task id + * @return the task info by task id + */ + List getTaskInfoByTaskId(@Param("taskId") Long taskId); + + /** + * Add new task info list int. + * + * @param taskInfos the task infos + * @return the int + */ + int addNewTaskInfoList(@Param("taskInfos") List taskInfos); + + /** + * Add new task info int. + * + * @param taskInfo the task info + * @return the int + */ + int addNewTaskInfo(@Param("taskInfo") TaskInfo taskInfo); +} diff --git a/src/main/java/com/dispose/pojo/entity/DisposeTask.java b/src/main/java/com/dispose/pojo/entity/DisposeTask.java index 9aa25001..5a1c453f 100644 --- a/src/main/java/com/dispose/pojo/entity/DisposeTask.java +++ b/src/main/java/com/dispose/pojo/entity/DisposeTask.java @@ -16,6 +16,7 @@ import tk.mybatis.mapper.code.Style; import javax.persistence.Id; import javax.persistence.Table; import java.io.Serializable; +import java.util.List; /** * The type Dispose task. @@ -52,9 +53,9 @@ public class DisposeTask implements Serializable { */ private Long accountId; /** - * The Capacity type. + * The Dispose capacity. */ - private DisposeCapacityType capacityType; + private DisposeCapacityType disposeCapacity; /** * The Dispose ip. */ @@ -87,4 +88,9 @@ public class DisposeTask implements Serializable { * The Current status. */ private DisposeTaskStatus currentStatus; + + /** + * The Task info. + */ + private List taskInfo; } diff --git a/src/main/java/com/dispose/pojo/entity/TaskInfo.java b/src/main/java/com/dispose/pojo/entity/TaskInfo.java new file mode 100644 index 00000000..32c30792 --- /dev/null +++ b/src/main/java/com/dispose/pojo/entity/TaskInfo.java @@ -0,0 +1,79 @@ +package com.dispose.pojo.entity; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import tk.mybatis.mapper.annotation.KeySql; +import tk.mybatis.mapper.annotation.NameStyle; +import tk.mybatis.mapper.code.Style; + +import javax.persistence.Id; +import javax.persistence.Table; +import java.io.Serializable; + +/** + * The type Task info. + * + * @author + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder(alphabetic = true) +@Table(name = "task_info") +@NameStyle(Style.normal) +public class TaskInfo implements Serializable { + /** + * The constant serialVersionUID. + */ + private static final long serialVersionUID = 1L; + + /** + * The Id. + */ + @Id + @KeySql(useGeneratedKeys = true) + private Long id; + + /** + * The Task id. + */ + private Long taskId; + /** + * The Device id. + */ + private Long deviceId; + /** + * The Begin time. + */ + private String beginTime; + /** + * The End time. + */ + private String endTime; + /** + * The Task attack type. + */ + private Long taskAttackType; + /** + * The Exec attack type. + */ + private Long execAttackType; + /** + * The Attack type status. + */ + private Long attackTypeStatus; + /** + * The Extern id. + */ + private Long externId; + /** + * The Status. + */ + private Long status; +} diff --git a/src/main/resources/mappers/DisposeCapacity.xml b/src/main/resources/mappers/DisposeCapacity.xml index 7890a81e..d1bf94d7 100644 --- a/src/main/resources/mappers/DisposeCapacity.xml +++ b/src/main/resources/mappers/DisposeCapacity.xml @@ -37,7 +37,7 @@ WHERE dispose_capacity.deviceId = #{deviceId} - SELECT * FROM dispose_capacity WHERE dispose_capacity.deviceId = #{deviceId} diff --git a/src/main/resources/mappers/DisposeTask.xml b/src/main/resources/mappers/DisposeTask.xml index e5848775..ba07e885 100644 --- a/src/main/resources/mappers/DisposeTask.xml +++ b/src/main/resources/mappers/DisposeTask.xml @@ -5,7 +5,7 @@ - + @@ -14,6 +14,17 @@ + + + + + + + + + + + + SELECT * + FROM task_info + + + + INSERT IGNORE INTO task_info(taskId, deviceId, taskAttackType) + VALUES + + (#{task.taskId}, #{task.deviceId}, #{task.taskAttackType}) + + + + + INSERT IGNORE INTO task_info(taskId, deviceId, taskAttackType) + VALUES (#{taskId}, #{deviceId}, #{taskAttackType}) + + + + + \ No newline at end of file diff --git a/src/test/java/com/dispose/test/debug/demo.java b/src/test/java/com/dispose/test/debug/demo.java index d3f6378c..31726fde 100644 --- a/src/test/java/com/dispose/test/debug/demo.java +++ b/src/test/java/com/dispose/test/debug/demo.java @@ -63,6 +63,9 @@ public class demo { // Assert.assertTrue(IPAddrType.ipInRange("", "192.168.0.30")); // } + /** + * Date time debug. + */ @Test public void dateTimeDebug() { Integer v1 = null; @@ -76,6 +79,14 @@ public class demo { log.info("v2: {}", Optional.ofNullable(v2).orElse(0)); } + /** + * Upgrade dispose device properties t. + * + * @param the type parameter + * @param destDev the dest dev + * @param srcDev the src dev + * @return the t + */ private T upgradeDisposeDeviceProperties(T destDev, T srcDev) { Field[] field = srcDev.getClass().getDeclaredFields(); @@ -104,6 +115,11 @@ public class demo { return destDev; } + /** + * Class enum value. + * + * @throws JsonProcessingException the json processing exception + */ @Test public void classEnumValue() throws JsonProcessingException { DisposeDevice dev = DisposeDevice.builder() @@ -132,6 +148,9 @@ public class demo { .writeValueAsString(upgradeDisposeDeviceProperties(dev, dev2))); } + /** + * Privacy helper. + */ @Test public void privacyHelper() { log.info(PrivacyHelper.ipAddressPrivacy("192.168.0.123")); @@ -139,6 +158,9 @@ public class demo { log.info(PrivacyHelper.ipAddressPrivacy("3fde::fde2")); } + /** + * Gets type mask from attack type. + */ @Test public void getTypeMaskFromAttackType() { Long ret = DDoSAttackType.getTypeMaskFromAttackType(new DDoSAttackType[] {DDoSAttackType.ALL_ATTACKS}); diff --git a/src/test/java/com/dispose/test/mapper/DisposeTaskMapperTest.java b/src/test/java/com/dispose/test/mapper/DisposeTaskMapperTest.java index d5059c72..1b6c3ec2 100644 --- a/src/test/java/com/dispose/test/mapper/DisposeTaskMapperTest.java +++ b/src/test/java/com/dispose/test/mapper/DisposeTaskMapperTest.java @@ -2,6 +2,7 @@ package com.dispose.test.mapper; import com.dispose.common.DDoSAttackType; import com.dispose.common.DisposeCapacityType; +import com.dispose.common.DisposeTaskStatus; import com.dispose.common.NetflowDirection; import com.dispose.mapper.DisposeDeviceMapper; import com.dispose.mapper.DisposeTaskMapper; @@ -10,6 +11,7 @@ import com.dispose.pojo.entity.DisposeTask; 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; @@ -20,23 +22,45 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; import java.util.List; +/** + * The type Dispose task mapper test. + * + * @author + */ @RunWith(SpringRunner.class) @SpringBootTest @Slf4j @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class DisposeTaskMapperTest { + /** + * The Dispose task mapper. + */ @Resource private DisposeTaskMapper disposeTaskMapper; + /** + * The User account mapper. + */ @Resource private UserAccountMapper userAccountMapper; + /** + * The Dispose device mapper. + */ @Resource private DisposeDeviceMapper disposeDeviceMapper; + /** + * The Object mapper. + */ @Resource private ObjectMapper objectMapper; + /** + * A 1 add new dispose task. + * + * @throws JsonProcessingException the json processing exception + */ @Test public void a1_addNewDisposeTask() throws JsonProcessingException { Long uId = userAccountMapper.selectAll().get(0).getId(); @@ -44,22 +68,57 @@ public class DisposeTaskMapperTest { DisposeTask task = DisposeTask.builder() .deviceId(dId) .accountId(uId) - .capacityType(DisposeCapacityType.CLEANUP) + .disposeCapacity(DisposeCapacityType.CLEANUP) .disposeIp("192.168.0.1") .planEndTime("30") .flowDirection(NetflowDirection.DIRECTION_BI) - .attackType(DDoSAttackType.getTypeMaskFromAttackType(new DDoSAttackType[] {DDoSAttackType.ALL_ATTACKS})) + .attackType(DDoSAttackType.getTypeMaskFromAttackType(new DDoSAttackType[]{DDoSAttackType.ALL_ATTACKS})) .flowBandWidth(1024) .build(); int ret = disposeTaskMapper.addNewTask(task); - log.info("add ret {}: {}", ret, - objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(task)); + Assert.assertEquals(ret, 1); + + log.debug("add ret {}: {}", ret, objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(task)); List taskList = disposeTaskMapper.selectAll(); - log.info("Database: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(taskList)); + Assert.assertNotNull(taskList); + Assert.assertNotEquals(taskList.size(), 0); + + log.debug("Database: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(taskList)); + } + + /** + * D 1 get task status. + */ + @Test + public void d1_getTaskStatus() { + List taskList = disposeTaskMapper.selectAll(); + + if (taskList != null && taskList.size() > 0) { + taskList.forEach(v -> { + DisposeTaskStatus status = disposeTaskMapper.getTaskStatus(v.getId()); + Assert.assertEquals(v.getCurrentStatus(), status); + }); + } + } + + /** + * C 1 chang task status. + */ + @Test + public void c1_changTaskStatus() { + List taskList = disposeTaskMapper.selectAll(); + + if (taskList != null && taskList.size() > 0) { + taskList.forEach(v -> { + int ret = disposeTaskMapper.changTaskStatus(v.getId(), DisposeTaskStatus.TASK_FINISHED); + DisposeTaskStatus status = disposeTaskMapper.getTaskStatus(v.getId()); + Assert.assertEquals(DisposeTaskStatus.TASK_FINISHED, status); + }); + } } }