parent
09adf46ef3
commit
034881e4de
|
@ -120,6 +120,7 @@ public class DisposeTaskController {
|
|||
DisposeTask task = DisposeTask.builder()
|
||||
.deviceId(devId)
|
||||
.accountId(aId)
|
||||
.areaCode(v.getAreaCode() == null ? -1 : v.getAreaCode())
|
||||
.disposeCapacity(capType)
|
||||
.disposeObject(Helper.ipAddressNormalize(v.getDisposeObject()))
|
||||
.objectType(t)
|
||||
|
@ -172,6 +173,7 @@ public class DisposeTaskController {
|
|||
// 构造处置任务参数
|
||||
DisposeTask task = DisposeTask.builder()
|
||||
.deviceId(Long.parseLong(Optional.ofNullable(req.getId()).orElse("-1")))
|
||||
.areaCode(-1)
|
||||
.accountId(userAccountService.getUserIdByAuthHead(Objects.requireNonNull(headers.get("Authorization"))
|
||||
.get(0)))
|
||||
.disposeCapacity(CommonEnumHandler.codeOf(DisposeCapacityType.class,
|
||||
|
@ -248,6 +250,7 @@ public class DisposeTaskController {
|
|||
DisposeTask task = DisposeTask.builder()
|
||||
.deviceId(devId)
|
||||
.accountId(aId)
|
||||
.areaCode(-1)
|
||||
.disposeCapacity(capType)
|
||||
.disposeObject(Helper.ipAddressNormalize(ip))
|
||||
.objectType(DisposeObjectType.IP)
|
||||
|
|
|
@ -19,11 +19,12 @@ public interface DisposeTaskManager {
|
|||
* Gets dispose task.
|
||||
*
|
||||
* @param deviceId the device id
|
||||
* @param areaCode the area code
|
||||
* @param disposeIp the dispose ip
|
||||
* @param capType the cap type
|
||||
* @return the dispose task
|
||||
*/
|
||||
DisposeTask getDisposeTask(Long deviceId, String disposeIp, DisposeCapacityType capType);
|
||||
DisposeTask getDisposeTask(Long deviceId, Integer areaCode, String disposeIp, DisposeCapacityType capType);
|
||||
|
||||
/**
|
||||
* Add dispose task error code.
|
||||
|
@ -65,16 +66,16 @@ public interface DisposeTaskManager {
|
|||
DisposeTask getDisposeTaskById(Long taskId);
|
||||
|
||||
/**
|
||||
* Gets dispose task by id.
|
||||
* Gets dispose tasks.
|
||||
*
|
||||
* @return the dispose task list
|
||||
* @return the dispose tasks
|
||||
*/
|
||||
List<DisposeTask> getDisposeTasks();
|
||||
|
||||
/**
|
||||
* Gets pages of task.
|
||||
*
|
||||
* @param taskId the task id
|
||||
* @param taskId the task id
|
||||
* @param startPage the start page
|
||||
* @param pageSize the page size
|
||||
* @return the pages of task
|
||||
|
|
|
@ -34,13 +34,14 @@ public class DisposeTaskManagerImpl implements DisposeTaskManager {
|
|||
* Gets dispose task.
|
||||
*
|
||||
* @param deviceId the device id
|
||||
* @param areaCode the area code
|
||||
* @param disposeIp the dispose ip
|
||||
* @param capType the cap type
|
||||
* @return the dispose task
|
||||
*/
|
||||
@Override
|
||||
public DisposeTask getDisposeTask(Long deviceId, String disposeIp, DisposeCapacityType capType) {
|
||||
return disposeTaskMapper.getRunningTask(deviceId, capType, disposeIp);
|
||||
public DisposeTask getDisposeTask(Long deviceId, Integer areaCode, String disposeIp, DisposeCapacityType capType) {
|
||||
return disposeTaskMapper.getRunningTask(deviceId, areaCode, capType, disposeIp);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -102,9 +103,9 @@ public class DisposeTaskManagerImpl implements DisposeTaskManager {
|
|||
}
|
||||
|
||||
/**
|
||||
* Gets dispose task by id.
|
||||
* Gets dispose tasks.
|
||||
*
|
||||
* @return the dispose task list
|
||||
* @return the dispose tasks
|
||||
*/
|
||||
@Override
|
||||
public List<DisposeTask> getDisposeTasks() {
|
||||
|
@ -114,7 +115,7 @@ public class DisposeTaskManagerImpl implements DisposeTaskManager {
|
|||
/**
|
||||
* Gets pages of task.
|
||||
*
|
||||
* @param taskId the task id
|
||||
* @param taskId the task id
|
||||
* @param startPage the start page
|
||||
* @param pageSize the page size
|
||||
* @return the pages of task
|
||||
|
@ -129,7 +130,7 @@ public class DisposeTaskManagerImpl implements DisposeTaskManager {
|
|||
// 设置分页信息
|
||||
PageHelper.startPage(startPage, pageSize);
|
||||
|
||||
if(taskId.size() > 0) {
|
||||
if (taskId.size() > 0) {
|
||||
preList = disposeTaskMapper.selectPageById(taskId);
|
||||
} else {
|
||||
preList = disposeTaskMapper.selectPageAll();
|
||||
|
@ -138,8 +139,8 @@ public class DisposeTaskManagerImpl implements DisposeTaskManager {
|
|||
|
||||
pageInfo = new PageInfo<>(preList);
|
||||
|
||||
if(taskId.size() == 0){
|
||||
return new MulReturnType<>(pageInfo, new ArrayList<>());
|
||||
if (taskId.size() == 0) {
|
||||
return new MulReturnType<>(pageInfo, new ArrayList<>());
|
||||
}
|
||||
|
||||
List<DisposeTask> taskList = new ArrayList<>(disposeTaskMapper.selectByIdSet(taskId));
|
||||
|
|
|
@ -86,6 +86,7 @@ public interface DisposeTaskMapper {
|
|||
* @return the running task
|
||||
*/
|
||||
DisposeTask getRunningTask(@Param("deviceId") Long deviceId,
|
||||
@Param("areaCode") Integer areaCode,
|
||||
@Param("capType") DisposeCapacityType capType,
|
||||
@Param("disposeObject") String disposeObject);
|
||||
|
||||
|
|
|
@ -38,4 +38,9 @@ public class DisposeObject {
|
|||
@NotNull(message = "objectType 处置类型不能为空", groups = ValidGroups.TaskStartReqValid.class)
|
||||
@ValidBaseEnum(enumClass = DisposeObjectType.class, groups = ValidGroups.TaskStartReqValid.class)
|
||||
private Integer objectType;
|
||||
|
||||
/**
|
||||
* The Area code.
|
||||
*/
|
||||
private Integer areaCode;
|
||||
}
|
||||
|
|
|
@ -52,6 +52,10 @@ public class DisposeTask implements Serializable {
|
|||
* The Account id.
|
||||
*/
|
||||
private Long accountId;
|
||||
/**
|
||||
* The Area code.
|
||||
*/
|
||||
private Integer areaCode;
|
||||
/**
|
||||
* The Dispose capacity.
|
||||
*/
|
||||
|
|
|
@ -531,9 +531,12 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
|
|||
disposeAbilityRouterService.getAllAbilityDevices().stream()
|
||||
// 判断是否是当前设备的处置任务
|
||||
.filter(f -> v.getDeviceId() == -1 || f.getDev().getId().equals(v.getDeviceId()))
|
||||
// 判断是否是当前区域处置
|
||||
.filter(f -> v.getAreaCode() == -1 || f.getDev().getAreaCode().equals(v.getAreaCode()))
|
||||
// 当前设备是否支持该处置能力
|
||||
.filter(c -> c.getDev().getDevCapacity().stream().anyMatch(m -> m.getCapacityType() == v
|
||||
.getDisposeCapacity()))
|
||||
// 当前设备是否支持处置该IP
|
||||
.filter(c -> c.getDb().isCarryProtectIp(v.getDisposeObject()))
|
||||
.forEach(d -> {
|
||||
log.info("Add dispose task for device: {}", d.getDev());
|
||||
|
|
|
@ -40,7 +40,7 @@ public class DisposeTaskServiceImpl implements DisposeTaskService {
|
|||
*/
|
||||
@Override
|
||||
public MulReturnType<ErrorCode, DisposeTask> createTask(DisposeTask task) {
|
||||
DisposeTask exitTask = disposeTaskManager.getDisposeTask(task.getDeviceId(),
|
||||
DisposeTask exitTask = disposeTaskManager.getDisposeTask(task.getDeviceId(), task.getAreaCode(),
|
||||
task.getDisposeObject(), task.getDisposeCapacity());
|
||||
|
||||
if (exitTask != null) {
|
||||
|
|
|
@ -107,6 +107,7 @@ CREATE TABLE `dispose_task`
|
|||
`id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '处置任务唯一标识符',
|
||||
`deviceId` int(10) NOT NULL COMMENT '处置设备唯一标识符',
|
||||
`accountId` int(10) UNSIGNED NOT NULL COMMENT '用户唯一标识符',
|
||||
`areaCode` int(11) NOT NULL DEFAULT -1 COMMENT '设备物理位置区域码',
|
||||
`disposeCapacity` int(11) NOT NULL COMMENT '处置能力类型:0:清洗 1:高防 2:黑洞 3:检测',
|
||||
`disposeObject` varchar(4096) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '处置对象',
|
||||
`objectType` int(8) NOT NULL COMMENT '处置对象类型:\r\n0:IP\r\n1:域名 \r\n2:URL',
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
<id column="id" property="id"/>
|
||||
<id column="deviceId" property="deviceId"/>
|
||||
<id column="accountId" property="accountId"/>
|
||||
<result column="areaCode" property="areaCode"/>
|
||||
<result column="disposeCapacity" property="disposeCapacity" javaType="com.dispose.common.DisposeCapacityType"/>
|
||||
<result column="disposeObject" property="disposeObject"/>
|
||||
<result column="objectType" property="objectType" javaType="com.dispose.common.DisposeObjectType"/>
|
||||
|
@ -121,6 +122,9 @@
|
|||
<if test="deviceId != -1">
|
||||
AND dt.deviceId = #{deviceId}
|
||||
</if>
|
||||
<if test="areaCode != -1">
|
||||
AND dt.areaCode = #{areaCode}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="getNewTask" resultType="com.dispose.pojo.entity.DisposeTask">
|
||||
|
|
|
@ -76,8 +76,8 @@ public class DisposeTaskManagerTest extends InitTestEnvironment {
|
|||
@Test
|
||||
public void a1_disposeIpRunning() {
|
||||
disposeTaskMapper.selectAll().forEach(v -> {
|
||||
DisposeTask runningResult = disposeTaskManager.getDisposeTask(v.getDeviceId(), v.getDisposeObject(),
|
||||
v.getDisposeCapacity());
|
||||
DisposeTask runningResult = disposeTaskManager.getDisposeTask(v.getDeviceId(), v.getAreaCode(),
|
||||
v.getDisposeObject(), v.getDisposeCapacity());
|
||||
|
||||
log.info("runningResult-->{}", runningResult);
|
||||
|
||||
|
|
|
@ -125,25 +125,25 @@ public class DisposeTaskMapperTest extends InitTestEnvironment {
|
|||
*/
|
||||
@Test
|
||||
public void a3_getRunningTask() throws JsonProcessingException {
|
||||
DisposeTask taskList = disposeTaskMapper.getRunningTask(-1L,
|
||||
DisposeTask taskList = disposeTaskMapper.getRunningTask(-1L, -1,
|
||||
DisposeCapacityType.CLEANUP,
|
||||
"192.168.0.1");
|
||||
|
||||
log.info("Step1: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(taskList));
|
||||
|
||||
taskList = disposeTaskMapper.getRunningTask(570L,
|
||||
taskList = disposeTaskMapper.getRunningTask(570L, -1,
|
||||
DisposeCapacityType.CLEANUP,
|
||||
"192.168.0.1");
|
||||
|
||||
log.info("Step2: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(taskList));
|
||||
|
||||
taskList = disposeTaskMapper.getRunningTask(-1L,
|
||||
taskList = disposeTaskMapper.getRunningTask(-1L, -1,
|
||||
DisposeCapacityType.HIDEPEND,
|
||||
"192.168.0.1");
|
||||
|
||||
log.info("Step3: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(taskList));
|
||||
|
||||
taskList = disposeTaskMapper.getRunningTask(-1L,
|
||||
taskList = disposeTaskMapper.getRunningTask(-1L, -1,
|
||||
DisposeCapacityType.HIDEPEND,
|
||||
"192.168.0.12");
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ public class DisposeTaskServiceTest extends InitTestEnvironment {
|
|||
@Before
|
||||
public void userLoginTest() throws NoSuchAlgorithmException {
|
||||
MulReturnType<ErrorCode, String> ret = userAccountService.loginService(getUSER_NAME(),
|
||||
getPASSWORD());
|
||||
getPASSWORD());
|
||||
|
||||
if (ret.getFirstParam() == ErrorCode.ERR_OK) {
|
||||
DisposeTaskServiceTest.token = ret.getSecondParam();
|
||||
|
@ -114,19 +114,24 @@ public class DisposeTaskServiceTest extends InitTestEnvironment {
|
|||
|
||||
if (ret.getFirstParam() == ErrorCode.ERR_OK) {
|
||||
Assert.assertNotNull(ret.getSecondParam());
|
||||
Assert.assertEquals(String.valueOf(ret.getSecondParam().getDisposeCapacity()), String.valueOf(DisposeCapacityType.CLEANUP));
|
||||
Assert.assertEquals(String.valueOf(ret.getSecondParam()
|
||||
.getDisposeCapacity()),
|
||||
String.valueOf(DisposeCapacityType.CLEANUP));
|
||||
} else {
|
||||
Assert.assertNotEquals(ret.getFirstParam().getCode(), ErrorCode.ERR_OK.getCode());
|
||||
}
|
||||
|
||||
disposeTaskManager.getExpiredTasks().forEach(v->{
|
||||
disposeTaskManager.getExpiredTasks().forEach(v -> {
|
||||
disposeTaskManager.changeDisposeTaskStatus(v.getId(), DisposeTaskStatus.TASK_NEW);
|
||||
|
||||
MulReturnType<ErrorCode, DisposeTask> result = disposeTaskService.createTask(v);
|
||||
|
||||
Assert.assertEquals(result.getFirstParam().getCode(), ErrorCode.ERR_TASKRUNNING.getCode());
|
||||
Assert.assertEquals(result.getSecondParam().getId(), disposeTaskManager.getDisposeTask(newTask.getDeviceId(),
|
||||
newTask.getDisposeObject(), newTask.getDisposeCapacity()).getId());
|
||||
Assert.assertEquals(result.getSecondParam().getId(),
|
||||
disposeTaskManager.getDisposeTask(newTask.getDeviceId(), v.getAreaCode(),
|
||||
newTask.getDisposeObject(),
|
||||
newTask.getDisposeCapacity())
|
||||
.getId());
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -134,7 +139,7 @@ public class DisposeTaskServiceTest extends InitTestEnvironment {
|
|||
* creat task mul return type.
|
||||
*/
|
||||
@Test
|
||||
public void a2_stopTask(){
|
||||
public void a2_stopTask() {
|
||||
DisposeTask newTask = DisposeTask.builder()
|
||||
.deviceId(disposeDeviceManager.getAllNormalDisposeDevices().get(0).getId())
|
||||
.accountId(1L)
|
||||
|
@ -149,7 +154,7 @@ public class DisposeTaskServiceTest extends InitTestEnvironment {
|
|||
|
||||
disposeTaskService.createTask(newTask);
|
||||
|
||||
disposeTaskManager.getExpiredTasks().forEach(v->{
|
||||
disposeTaskManager.getExpiredTasks().forEach(v -> {
|
||||
MulReturnType<ErrorCode, DisposeTask> ret = disposeTaskService.stopTask(v.getId());
|
||||
|
||||
Assert.assertEquals(ret.getFirstParam(), ErrorCode.ERR_TASKNOTRUNNING);
|
||||
|
@ -157,23 +162,24 @@ public class DisposeTaskServiceTest extends InitTestEnvironment {
|
|||
});
|
||||
|
||||
|
||||
disposeTaskManager.getNewDisposeTasks().forEach(k->{
|
||||
MulReturnType<ErrorCode, DisposeTask> ret = disposeTaskService.stopTask(k.getId());
|
||||
disposeTaskManager.getNewDisposeTasks().forEach(k -> {
|
||||
MulReturnType<ErrorCode, DisposeTask> ret = disposeTaskService.stopTask(k.getId());
|
||||
|
||||
if(ret.getFirstParam() == ErrorCode.ERR_OK){
|
||||
Assert.assertNotNull(ret.getSecondParam());
|
||||
Assert.assertEquals(disposeTaskManager.getDisposeTaskById(k.getId()).getCurrentStatus(), DisposeTaskStatus.TASK_CANCELED);
|
||||
}else{
|
||||
Assert.assertNull(ret.getSecondParam());
|
||||
}
|
||||
});
|
||||
if (ret.getFirstParam() == ErrorCode.ERR_OK) {
|
||||
Assert.assertNotNull(ret.getSecondParam());
|
||||
Assert.assertEquals(disposeTaskManager.getDisposeTaskById(k.getId())
|
||||
.getCurrentStatus(), DisposeTaskStatus.TASK_CANCELED);
|
||||
} else {
|
||||
Assert.assertNull(ret.getSecondParam());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* get dispose task.
|
||||
*/
|
||||
@Test
|
||||
public void a3_getDisposeTask(){
|
||||
public void a3_getDisposeTask() {
|
||||
DisposeTask newTask = DisposeTask.builder()
|
||||
.deviceId(disposeDeviceManager.getAllNormalDisposeDevices().get(0).getId())
|
||||
.accountId(1L)
|
||||
|
@ -188,7 +194,7 @@ public class DisposeTaskServiceTest extends InitTestEnvironment {
|
|||
|
||||
disposeTaskService.createTask(newTask);
|
||||
|
||||
disposeTaskManager.getNewDisposeTasks().forEach(v->{
|
||||
disposeTaskManager.getNewDisposeTasks().forEach(v -> {
|
||||
DisposeTask task = disposeTaskService.getDisposeTask(v.getId());
|
||||
Assert.assertNotNull(task);
|
||||
Assert.assertEquals(task.getCurrentStatus(), DisposeTaskStatus.TASK_NEW);
|
||||
|
@ -201,15 +207,15 @@ public class DisposeTaskServiceTest extends InitTestEnvironment {
|
|||
*/
|
||||
@Test
|
||||
public void a4_stopTaskTest() {
|
||||
if(disposeTaskManager.getNewDisposeTasks().size() == 0){
|
||||
if (disposeTaskManager.getNewDisposeTasks().size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
Long taskId = disposeTaskManager.getNewDisposeTasks().get(0).getId();
|
||||
|
||||
MulReturnType<ErrorCode, DisposeTask> ret = disposeTaskService.stopTask(taskId-1);
|
||||
MulReturnType<ErrorCode, DisposeTask> ret = disposeTaskService.stopTask(taskId - 1);
|
||||
if (ret.getFirstParam() == ErrorCode.ERR_NOSUCHTASK) {
|
||||
Assert.assertNull(disposeTaskManager.getDisposeTaskById(taskId-1));
|
||||
Assert.assertNull(disposeTaskManager.getDisposeTaskById(taskId - 1));
|
||||
}
|
||||
|
||||
ret = disposeTaskService.stopTask(taskId);
|
||||
|
@ -219,14 +225,12 @@ public class DisposeTaskServiceTest extends InitTestEnvironment {
|
|||
if (ret.getFirstParam() == ErrorCode.ERR_TASKNOTRUNNING) {
|
||||
Assert.assertNotNull(task);
|
||||
Assert.assertFalse(task.getCurrentStatus().taskIsRunning());
|
||||
}
|
||||
else if(ret.getFirstParam() == ErrorCode.ERR_DATABASE){
|
||||
} else if (ret.getFirstParam() == ErrorCode.ERR_DATABASE) {
|
||||
Assert.assertNull(task);
|
||||
Assert.assertFalse(disposeTaskManager.changeDisposeTaskStatus(taskId, DisposeTaskStatus.TASK_CANCELED));
|
||||
}
|
||||
else if(ret.getFirstParam() == ErrorCode.ERR_OK){
|
||||
} else if (ret.getFirstParam() == ErrorCode.ERR_OK) {
|
||||
Assert.assertNotNull(task);
|
||||
Assert.assertEquals(task.getCurrentStatus(),DisposeTaskStatus.TASK_CANCELED);
|
||||
Assert.assertEquals(task.getCurrentStatus(), DisposeTaskStatus.TASK_CANCELED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue