REM:
1.增加错误码
2.修改鹏信设备执行任务失败错误码
3.修改鹏信设备启动、停止处置任务
4.修改定时更新设备处置状态
This commit is contained in:
chenlinghy 2020-11-25 17:28:54 +08:00
parent 1d157e2d54
commit 37bd4aacb6
7 changed files with 26 additions and 51 deletions

View File

@ -179,18 +179,18 @@ public class PengXinAbilityImpl implements DisposeAbility {
if (rspInfo == null || rspInfo.getCode() != ErrorCode.ERR_OK.getHttpCode()) {
log.error("----Error PengXin start clean {} server return error", disposeObject);
return new MulReturnType<>(ErrorCode.ERR_HAOHAN_ERROR, null);
return new MulReturnType<>(ErrorCode.ERR_PENGXIN_ERROR, null);
}
if (rspInfo.getMsgContent().getItems().size() == 0) {
log.error("----Error PengXin start clean {} server return nothing", disposeObject);
return new MulReturnType<>(ErrorCode.ERR_HAOHAN_ERROR, null);
return new MulReturnType<>(ErrorCode.ERR_PENGXIN_ERROR, null);
} else {
int errCode = rspInfo.getMsgContent().getItems().get(0).getStatus();
if (errCode != ErrorCode.ERR_OK.getCode()) {
log.error("----Error PengXin start clean {} server return error: {}", disposeObject, errCode);
return new MulReturnType<>(ErrorCode.ERR_HAOHAN_ERROR, null);
return new MulReturnType<>(ErrorCode.ERR_PENGXIN_ERROR, null);
}
log.debug("----Finish PengXin Start Cleanup Task: {}", disposeObject);
@ -252,13 +252,13 @@ public class PengXinAbilityImpl implements DisposeAbility {
if (rspInfo.getMsgContent().getItems().size() == 0) {
log.error("----Error PengXin stop clean {} server return nothing", disposeObject);
return new MulReturnType<>(ErrorCode.ERR_HAOHAN_ERROR, null);
return new MulReturnType<>(ErrorCode.ERR_PENGXIN_ERROR, null);
} else {
int errCode = rspInfo.getMsgContent().getItems().get(0).getStatus();
if (errCode != ErrorCode.ERR_OK.getCode()) {
log.error("----Error PengXin stop clean {} server return error: {}", disposeObject, errCode);
return new MulReturnType<>(ErrorCode.ERR_HAOHAN_ERROR, null);
return new MulReturnType<>(ErrorCode.ERR_PENGXIN_ERROR, null);
}
log.debug("----Finish PengXin Stop Cleanup Task: {}", taskId);

View File

@ -235,7 +235,11 @@ public enum ErrorCode {
/**
* The Err huawei error.
*/
ERR_HUAWEI_ERROR(34, "华为设备返回错误"),
ERR_HUAWEI_ERROR(116, "华为设备返回错误"),
/**
* The Err pengxin error.
*/
ERR_PENGXIN_ERROR(117, "鹏信设备返回错误"),
;
/**

View File

@ -137,10 +137,9 @@ public interface DeviceTaskManager {
DeviceTask getTaskById(Long id);
/**
* Gets peng xin task by id.
* Gets peng xin task.
*
* @param startId the start id
* @return the peng xin task by id
* @return the peng xin task
*/
List<DeviceTask> getPengXinTaskById(Long startId);
List<DeviceTask> getPengXinTask();
}

View File

@ -297,12 +297,12 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
}
/**
* Gets PengXin device task info by startId.
* Gets PengXin device task info.
*
* @return the minId task info.
*/
@Override
public List<DeviceTask> getPengXinTaskById(Long startId){
return deviceTaskMapper.getPengXinTask(startId);
public List<DeviceTask> getPengXinTask(){
return deviceTaskMapper.getPengXinTask();
}
}

View File

@ -158,8 +158,7 @@ public interface DeviceTaskMapper {
/**
* Gets PengXin device task info.
*
* @param startId the start id
* @return PengXin device task info
*/
List<DeviceTask> getPengXinTask(Long startId);
List<DeviceTask> getPengXinTask();
}

View File

@ -14,15 +14,12 @@ import com.dispose.pojo.po.AbilityInfo;
import com.dispose.pojo.po.MulReturnType;
import com.dispose.service.DeviceTaskManagerService;
import com.dispose.service.DisposeAbilityRouterService;
import com.pengxin.dispose.common.PengXinTaskStatus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
/**
@ -443,8 +440,6 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
// 设置任务状态为启动中
deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(), DisposeTaskStatus.TASK_STARTING);
// 设置设备任务状态为启动中
deviceTaskManager.changeDisposeDeviceTaskInfoDevStatus(deviceTask.getId(), (long) PengXinTaskStatus.TASK_STARTING.getValue());
// 设置启动任务攻击类型状态
deviceTaskManager.setExecAttackType(deviceTask.getId(), NetflowDirection.DIRECTION_BI,
deviceTask.getTaskAttackType());
@ -471,9 +466,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
} else if (deviceTask.getErrRetry() < DisposeConfigValue.CALL_ERROR_RETRY_TIMES) {
// 设置该任务为新任务待下次重试启动
deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(), DisposeTaskStatus.TASK_NEW);
// 设置设备任务状态为启动处置任务失败
deviceTaskManager.changeDisposeDeviceTaskInfoDevStatus(deviceTask.getId(),
(long) PengXinTaskStatus.TASK_STARTED_FAILED.getValue());
// 记录任务出错重试次数
deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), deviceTask.getErrRetry() + 1);
log.error("PENGXIN_PLATFORM setup task times {} error {}: {}", deviceTask.getErrRetry(),
@ -482,9 +475,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
// 任务出错不在重试当做失败任务处理
deviceTaskManager.setAttackTypeStatus(deviceTask.getId(),
disposeTask.getFlowDirection(), 0L);
// 设置设备任务状态为启动处置任务失败
deviceTaskManager.changeDisposeDeviceTaskInfoDevStatus(deviceTask.getId(),
(long) PengXinTaskStatus.TASK_STARTED_FAILED.getValue());
log.error("PENGXIN_PLATFORM setup task error {}: {}", ret.getFirstParam(), deviceTask);
}
}
@ -499,10 +490,6 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
private void pengXinDeviceTaskStop(AbilityInfo ai, DeviceTask deviceTask, DisposeTask disposeTask) {
MulReturnType<ErrorCode, Long> ret;
// 设置设备任务状态为解封中
deviceTaskManager.changeDisposeDeviceTaskInfoDevStatus(deviceTask.getId(),
(long) PengXinTaskStatus.TASK_UNBLOCKING.getValue());
// 停止处置任务
ret = ai.getDb().stopDispose(disposeTask.getDisposeObject(), disposeTask.getDisposeCapacity(), null, null,
deviceTask.getExternId());
@ -514,17 +501,11 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), 0);
deviceTaskManager.setAttackTypeStatus(deviceTask.getId(), disposeTask.getFlowDirection(), 0L);
} else if (deviceTask.getErrRetry() < DisposeConfigValue.CALL_ERROR_RETRY_TIMES) {
// 设置设备任务状态为解封失败
deviceTaskManager.changeDisposeDeviceTaskInfoDevStatus(deviceTask.getId(),
(long) PengXinTaskStatus.TASK_UNBLOCKED_FAILED.getValue());
// 记录任务出错重试次数
deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), deviceTask.getErrRetry() + 1);
log.error("PENGXIN_PLATFORM stop task times {} error {}: {}", deviceTask.getErrRetry(),
ret.getSecondParam(), deviceTask);
} else {
// 设置设备任务状态为解封失败
deviceTaskManager.changeDisposeDeviceTaskInfoDevStatus(deviceTask.getId(),
(long) PengXinTaskStatus.TASK_UNBLOCKED_FAILED.getValue());
log.error("PENGXIN_PLATFORM stop task error {}: {}", ret.getFirstParam(), deviceTask);
}
}
@ -796,15 +777,8 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
* Device task status schedule.
*/
public void deviceTaskStatusSchedule() {
List<DeviceTask> taskList = new ArrayList<>();
//处置任务设备类型为鹏信设备任务状态不再变更
for (Long i = 1L; deviceTaskManager.getPengXinTaskById(i).size() != 0; i = taskList.get(taskList.size() - 1).getId() + 1) {
log.debug("startId:{}", i);
taskList.addAll(deviceTaskManager.getPengXinTaskById(i));
}
for (DeviceTask v : taskList) {
for (DeviceTask v : deviceTaskManager.getPengXinTask()) {
// 获取设备
AbilityInfo ai = disposeAbilityRouterService.getAbilityDevice(v.getDeviceId());
@ -827,6 +801,8 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
MulReturnType<ErrorCode, Long> ret = ai.getDb().taskStatus(v.getExternId());
if (ret.getFirstParam() == ErrorCode.ERR_OK) {
log.debug("id:{}, before devStatus:{}, after devStatus:{}", v.getId(),
v.getDevStatus(), ret.getSecondParam());
deviceTaskManager.changeDisposeDeviceTaskInfoDevStatus(v.getId(),
ret.getSecondParam());
}

View File

@ -29,15 +29,15 @@
VALUES
<foreach collection="taskLists" item="task" separator=",">
(#{task.taskId}, #{task.deviceId}, #{task.taskAttackType},
${@com.dispose.common.DisposeTaskStatus@TASK_NEW.getValue()}, 0)
${@com.dispose.common.DisposeTaskStatus@TASK_NEW.getValue()}, -1)
</foreach>
</insert>
<insert id="addNewTaskInfo" useGeneratedKeys="true" keyProperty="id"
parameterType="com.dispose.pojo.entity.DeviceTask">
INSERT IGNORE INTO device_task(taskId, deviceId, taskAttackType, status)
INSERT IGNORE INTO device_task(taskId, deviceId, taskAttackType, status, devStatus)
VALUES (#{taskId}, #{deviceId}, #{taskAttackType},
${@com.dispose.common.DisposeTaskStatus@TASK_NEW.getValue()})
${@com.dispose.common.DisposeTaskStatus@TASK_NEW.getValue()}, -1)
</insert>
<select id="getTaskInfoById" resultMap="device_task">
@ -136,9 +136,6 @@
WHERE
dd.deviceType = 2
AND
dt.devStatus != 8 AND dt.devStatus != 7
AND
dt.id >= #{startId}
LIMIT 100
dt.devStatus != 8 AND dt.devStatus != 7 AND dt.devStatus != -1
</select>
</mapper>