REM:
1.  监视设备配置项支持自动更新
2.  增加集团一键处置设备设备状态更新周期配置项
This commit is contained in:
HuangXin 2021-10-29 08:17:19 +08:00
parent ac7ec41aa5
commit fca424a84e
7 changed files with 129 additions and 42 deletions

View File

@ -6,6 +6,8 @@ dispose.split_char=,
dispose.request-timeout-second=5 dispose.request-timeout-second=5
# 是否开启隐私保护 # 是否开启隐私保护
dispose.used-privacy-protect=false dispose.used-privacy-protect=false
# 集团一键处置设备状态轮询时间
dispose.cmhi-device-query-period=3
dispose.call-error-retry-times=3 dispose.call-error-retry-times=3
# 分页配置项 # 分页配置项
@ -52,4 +54,5 @@ trust.auth-hosts=127.0.0.12,::1
#需要调试的设备IP/IP+端口 #需要调试的设备IP/IP+端口
# 主机,多个主机逗号(,)分割 # 主机,多个主机逗号(,)分割
device.log-hosts=https://111.28.2.17:443,http://172.21.44.239 device.log-hosts=https://111.28.2.17:443,http://172.21.44.239,https://183.230.71.73:8888/
device.log-paths=login,logout,capacity,start,stop,get,linkstatus

View File

@ -67,8 +67,18 @@ public class DisposeConfigValue {
*/ */
public static final long HEART_PERIOD_OF_SECOND = 30; public static final long HEART_PERIOD_OF_SECOND = 30;
/**
* 集团一键处置设备状态查询周期
*/
public static volatile int CMHI_DEVICE_QUERY_PERIOD = 1;
/** /**
* The constant LOG_HOSTS. * The constant LOG_HOSTS.
*/ */
public static final List<String> LOG_HOSTS = new ArrayList<>(); public static final List<String> LOG_HOSTS = new ArrayList<>();
/**
* The constant LOG_PATHS.
*/
public static final List<String> LOG_PATHS = new ArrayList<>();
} }

View File

@ -8,8 +8,10 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import java.util.Arrays;
import java.util.Locale; import java.util.Locale;
import java.util.Optional; import java.util.Optional;
@ -25,18 +27,24 @@ import java.util.Optional;
@ConfigurationProperties(prefix = "device") @ConfigurationProperties(prefix = "device")
@Configuration @Configuration
@Slf4j @Slf4j
public class DeviceLogConfigure { public class DeviceLogConfigure implements WebMvcConfigurer {
/** /**
* The Log hosts. * The Log hosts.
*/ */
private String[] logHosts; private String[] logHosts;
/**
* The Log paths.
*/
private String[] logPaths;
/** /**
* Init global value. * Init global value.
*/ */
@PostConstruct @PostConstruct
private void initGlobalValue() { private void initGlobalValue() {
DisposeConfigValue.LOG_HOSTS.clear(); DisposeConfigValue.LOG_HOSTS.clear();
DisposeConfigValue.LOG_PATHS.clear();
for (String s : Optional.ofNullable(logHosts).orElse(new String[]{""})) { for (String s : Optional.ofNullable(logHosts).orElse(new String[]{""})) {
if (s.toLowerCase(Locale.ROOT).startsWith("http")) { if (s.toLowerCase(Locale.ROOT).startsWith("http")) {
@ -44,6 +52,15 @@ public class DeviceLogConfigure {
} }
} }
DisposeConfigValue.LOG_PATHS.addAll(Arrays.asList(Optional.ofNullable(logPaths).orElse(new String[]{""})));
log.debug("Log device: {}", DisposeConfigValue.LOG_HOSTS); log.debug("Log device: {}", DisposeConfigValue.LOG_HOSTS);
log.debug("Log path: {}", DisposeConfigValue.LOG_PATHS);
}
/**
* Refresh config value.
*/
public void refreshConfigValue() {
initGlobalValue();
} }
} }

View File

@ -56,11 +56,17 @@ public class DisposeConfigure {
*/ */
private Integer minSplitPageSize; private Integer minSplitPageSize;
/**
* The Cmhi device query period.
*/
private Integer cmhiDeviceQueryPeriod;
/** /**
* Init global value. * Init global value.
*/ */
@PostConstruct @PostConstruct
private void initGlobalValue() { private void initGlobalValue() {
DisposeConfigValue.CMHI_DEVICE_QUERY_PERIOD = Optional.ofNullable(cmhiDeviceQueryPeriod).orElse(1);
DisposeConfigValue.REQUEST_TIMEOUT_MS = Optional.ofNullable(requestTimeoutSecond).orElse((long) 5) * 1000; DisposeConfigValue.REQUEST_TIMEOUT_MS = Optional.ofNullable(requestTimeoutSecond).orElse((long) 5) * 1000;
DisposeConfigValue.CHECK_PROTO_REQUEST_TIMEOUT = Optional.ofNullable(checkProtocolTimeout).orElse(true); DisposeConfigValue.CHECK_PROTO_REQUEST_TIMEOUT = Optional.ofNullable(checkProtocolTimeout).orElse(true);
DisposeConfigValue.USED_PRIVACY_PROTECT = Optional.ofNullable(usedPrivacyProtect).orElse(true); DisposeConfigValue.USED_PRIVACY_PROTECT = Optional.ofNullable(usedPrivacyProtect).orElse(true);

View File

@ -225,7 +225,8 @@ public class RestfulInterface {
return null; return null;
} }
if (DisposeConfigValue.LOG_HOSTS.stream().anyMatch(url::startsWith)) { if (DisposeConfigValue.LOG_HOSTS.stream().anyMatch(url::startsWith)
&& DisposeConfigValue.LOG_PATHS.stream().anyMatch(url::endsWith)) {
if(reqJson.length() > 0) { if(reqJson.length() > 0) {
log.debug("Restful response: {} {}, {}: \n+++{}\n---{}", reqType.name(), url, token, reqJson, svrResp); log.debug("Restful response: {} {}, {}: \n+++{}\n---{}", reqType.name(), url, token, reqJson, svrResp);
} else { } else {

View File

@ -60,6 +60,11 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
@Resource @Resource
private DisposeAbilityRouterService disposeAbilityRouterService; private DisposeAbilityRouterService disposeAbilityRouterService;
/**
* The Timer cnt.
*/
private long timerCnt = 0;
/** /**
* Is carry ip boolean. * Is carry ip boolean.
@ -107,26 +112,26 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(), DisposeTaskStatus.TASK_STARTING); deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(), DisposeTaskStatus.TASK_STARTING);
// 设置启动任务攻击类型状态 // 设置启动任务攻击类型状态
deviceTaskManager.setExecAttackType(deviceTask.getId(), NetflowDirection.DIRECTION_BI, deviceTaskManager.setExecAttackType(deviceTask.getId(), NetflowDirection.DIRECTION_BI,
deviceTask.getTaskAttackType()); deviceTask.getTaskAttackType());
// 调用设备执行处置任务 // 调用设备执行处置任务
ret = ai.getDb() ret = ai.getDb()
.runDispose(disposeTask.getDisposeObject(), disposeTask.getObjectType(), .runDispose(disposeTask.getDisposeObject(), disposeTask.getObjectType(),
disposeTask.getDisposeCapacity(), disposeTask.getDisposeCapacity(),
null, null, null); null, null, null);
if (ret.getFirstParam() == ErrorCode.ERR_OK) { if (ret.getFirstParam() == ErrorCode.ERR_OK) {
// 设置攻击类型任务启动结果 // 设置攻击类型任务启动结果
deviceTaskManager.setAttackTypeStatus(deviceTask.getId(), deviceTaskManager.setAttackTypeStatus(deviceTask.getId(),
disposeTask.getFlowDirection(), deviceTask.getTaskAttackType()); disposeTask.getFlowDirection(), deviceTask.getTaskAttackType());
// 更改处置任务状态为处置中 // 更改处置任务状态为处置中
deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(), deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(),
DisposeTaskStatus.TASK_STARTED); DisposeTaskStatus.TASK_STARTED);
log.info("VIRTUAL_DISPOSE setup task succeed: {}", deviceTask); log.info("VIRTUAL_DISPOSE setup task succeed: {}", deviceTask);
} else { } else {
// 任务出错不在重试当做失败任务处理 // 任务出错不在重试当做失败任务处理
deviceTaskManager.setAttackTypeStatus(deviceTask.getId(), deviceTaskManager.setAttackTypeStatus(deviceTask.getId(),
disposeTask.getFlowDirection(), 0L); disposeTask.getFlowDirection(), 0L);
log.error("VIRTUAL_DISPOSE setup task error {}: {}", ret.getFirstParam(), deviceTask); log.error("VIRTUAL_DISPOSE setup task error {}: {}", ret.getFirstParam(), deviceTask);
} }
} }
@ -157,6 +162,14 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
} }
/**
* Dp tech device exe.
*
* @param ai the ai
* @param deviceTask the device task
* @param disposeTask the dispose task
* @param netflowDirection the netflow direction
*/
private void dpTechDeviceExe(AbilityInfo ai, private void dpTechDeviceExe(AbilityInfo ai,
DeviceTask deviceTask, DeviceTask deviceTask,
DisposeTask disposeTask, NetflowDirection netflowDirection) { DisposeTask disposeTask, NetflowDirection netflowDirection) {
@ -169,19 +182,19 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
// 设置启动任务攻击类型状态 // 设置启动任务攻击类型状态
deviceTaskManager.execAttackTypeSetBit(deviceTask.getId(), netflowDirection, deviceTaskManager.execAttackTypeSetBit(deviceTask.getId(), netflowDirection,
attackType.getValue()); attackType.getValue());
// 调用迪普设备启动处置任务 // 调用迪普设备启动处置任务
ret = ai.getDb().runDispose(disposeTask.getDisposeObject(), disposeTask.getObjectType(), ret = ai.getDb().runDispose(disposeTask.getDisposeObject(), disposeTask.getObjectType(),
disposeTask.getDisposeCapacity(), netflowDirection, disposeTask.getDisposeCapacity(), netflowDirection,
attackType.getValue(), null); attackType.getValue(), null);
if (ret.getFirstParam() == ErrorCode.ERR_OK) { if (ret.getFirstParam() == ErrorCode.ERR_OK) {
// 标志启动成功 // 标志启动成功
deviceTaskManager.attackTypeStatusSetBit(deviceTask.getId(), netflowDirection, deviceTaskManager.attackTypeStatusSetBit(deviceTask.getId(), netflowDirection,
attackType.getValue()); attackType.getValue());
log.info("DPTECH_UMC setup task {}, {} succeed: {}", attackType, netflowDirection, log.info("DPTECH_UMC setup task {}, {} succeed: {}", attackType, netflowDirection,
deviceTask); deviceTask);
deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), 0); deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), 0);
} else if (deviceTask.getErrRetry() < DisposeConfigValue.CALL_ERROR_RETRY_TIMES * nTime) { } else if (deviceTask.getErrRetry() < DisposeConfigValue.CALL_ERROR_RETRY_TIMES * nTime) {
@ -191,12 +204,12 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), deviceTask.getErrRetry()); deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), deviceTask.getErrRetry());
//清除任务攻击类型启动标志 //清除任务攻击类型启动标志
deviceTaskManager.execAttackTypeCleanBit(deviceTask.getId(), netflowDirection, deviceTaskManager.execAttackTypeCleanBit(deviceTask.getId(), netflowDirection,
attackType.getValue()); attackType.getValue());
log.error("DPTECH_UMC setup task {}, {} times {} error: {}", attackType, log.error("DPTECH_UMC setup task {}, {} times {} error: {}", attackType,
netflowDirection, deviceTask.getErrRetry(), deviceTask); netflowDirection, deviceTask.getErrRetry(), deviceTask);
} else { } else {
log.error("DPTECH_UMC setup task {}, {} error {}: {}", attackType, log.error("DPTECH_UMC setup task {}, {} error {}: {}", attackType,
netflowDirection, ret.getFirstParam(), deviceTask); netflowDirection, ret.getFirstParam(), deviceTask);
} }
} }
@ -273,12 +286,12 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
if (disposeTask.getFlowDirection() != NetflowDirection.DIRECTION_IN) { if (disposeTask.getFlowDirection() != NetflowDirection.DIRECTION_IN) {
// 调用迪普设备停止处置任务 // 调用迪普设备停止处置任务
ret = ai.getDb().stopDispose(disposeTask.getDisposeObject(), disposeTask.getDisposeCapacity(), ret = ai.getDb().stopDispose(disposeTask.getDisposeObject(), disposeTask.getDisposeCapacity(),
NetflowDirection.DIRECTION_OUT, t.getValue(), null); NetflowDirection.DIRECTION_OUT, t.getValue(), null);
if (ret.getFirstParam() == ErrorCode.ERR_OK) { if (ret.getFirstParam() == ErrorCode.ERR_OK) {
// 标志停止成功 // 标志停止成功
deviceTaskManager.attackTypeStatusCleanBit(deviceTask.getId(), NetflowDirection.DIRECTION_OUT, deviceTaskManager.attackTypeStatusCleanBit(deviceTask.getId(), NetflowDirection.DIRECTION_OUT,
t.getValue()); t.getValue());
log.info("DPTECH_UMC stop task {}, {} succeed: {}", t, NetflowDirection.DIRECTION_OUT, deviceTask); log.info("DPTECH_UMC stop task {}, {} succeed: {}", t, NetflowDirection.DIRECTION_OUT, deviceTask);
@ -288,10 +301,10 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
deviceTask.setErrRetry(deviceTask.getErrRetry() + 1); deviceTask.setErrRetry(deviceTask.getErrRetry() + 1);
deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), deviceTask.getErrRetry()); deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), deviceTask.getErrRetry());
log.error("DPTECH_UMC stop task {}, {} times {} error: {}", t, log.error("DPTECH_UMC stop task {}, {} times {} error: {}", t,
NetflowDirection.DIRECTION_OUT, deviceTask.getErrRetry(), deviceTask); NetflowDirection.DIRECTION_OUT, deviceTask.getErrRetry(), deviceTask);
} else { } else {
log.info("DPTECH_UMC stop task {}, {} error {}: {}", t, log.info("DPTECH_UMC stop task {}, {} error {}: {}", t,
NetflowDirection.DIRECTION_OUT, ret.getFirstParam(), deviceTask); NetflowDirection.DIRECTION_OUT, ret.getFirstParam(), deviceTask);
} }
} }
@ -299,15 +312,15 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
if (disposeTask.getFlowDirection() != NetflowDirection.DIRECTION_OUT) { if (disposeTask.getFlowDirection() != NetflowDirection.DIRECTION_OUT) {
// 调用迪普设备启动处置任务 // 调用迪普设备启动处置任务
ret = ai.getDb().stopDispose(disposeTask.getDisposeObject(), disposeTask.getDisposeCapacity(), ret = ai.getDb().stopDispose(disposeTask.getDisposeObject(), disposeTask.getDisposeCapacity(),
NetflowDirection.DIRECTION_IN, t.getValue(), null); NetflowDirection.DIRECTION_IN, t.getValue(), null);
if (ret.getFirstParam() == ErrorCode.ERR_OK) { if (ret.getFirstParam() == ErrorCode.ERR_OK) {
// 标志启动成功 // 标志启动成功
deviceTaskManager.attackTypeStatusCleanBit(deviceTask.getId(), NetflowDirection.DIRECTION_IN, deviceTaskManager.attackTypeStatusCleanBit(deviceTask.getId(), NetflowDirection.DIRECTION_IN,
t.getValue()); t.getValue());
log.info("DPTECH_UMC setup task {}, {} succeed: {}", t, log.info("DPTECH_UMC setup task {}, {} succeed: {}", t,
NetflowDirection.DIRECTION_IN, deviceTask); NetflowDirection.DIRECTION_IN, deviceTask);
deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), 0); deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), 0);
} else if (deviceTask.getErrRetry() < DisposeConfigValue.CALL_ERROR_RETRY_TIMES * 10) { } else if (deviceTask.getErrRetry() < DisposeConfigValue.CALL_ERROR_RETRY_TIMES * 10) {
@ -315,10 +328,10 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
deviceTask.setErrRetry(deviceTask.getErrRetry() + 1); deviceTask.setErrRetry(deviceTask.getErrRetry() + 1);
deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), deviceTask.getErrRetry()); deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), deviceTask.getErrRetry());
log.error("DPTECH_UMC stop task {}, {} times {} error: {}", t, log.error("DPTECH_UMC stop task {}, {} times {} error: {}", t,
NetflowDirection.DIRECTION_IN, deviceTask.getErrRetry(), deviceTask); NetflowDirection.DIRECTION_IN, deviceTask.getErrRetry(), deviceTask);
} else { } else {
log.info("DPTECH_UMC stop task {}, {} error {}: {}", t, log.info("DPTECH_UMC stop task {}, {} error {}: {}", t,
NetflowDirection.DIRECTION_IN, ret.getFirstParam(), deviceTask); NetflowDirection.DIRECTION_IN, ret.getFirstParam(), deviceTask);
} }
} }
} }
@ -374,17 +387,17 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(), DisposeTaskStatus.TASK_STARTING); deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(), DisposeTaskStatus.TASK_STARTING);
// 设置启动任务攻击类型状态 // 设置启动任务攻击类型状态
deviceTaskManager.setExecAttackType(deviceTask.getId(), NetflowDirection.DIRECTION_BI, deviceTaskManager.setExecAttackType(deviceTask.getId(), NetflowDirection.DIRECTION_BI,
deviceTask.getTaskAttackType()); deviceTask.getTaskAttackType());
ret = ai.getDb() ret = ai.getDb()
.runDispose(disposeTask.getDisposeObject(), disposeTask.getObjectType(), .runDispose(disposeTask.getDisposeObject(), disposeTask.getObjectType(),
disposeTask.getDisposeCapacity(), null, disposeTask.getDisposeCapacity(), null,
null, (long) -(Helper.getTimestampDiffNow(disposeTask.getPlanEndTime()) / 60)); null, (long) -(Helper.getTimestampDiffNow(disposeTask.getPlanEndTime()) / 60));
if (ret.getFirstParam() == ErrorCode.ERR_OK) { if (ret.getFirstParam() == ErrorCode.ERR_OK) {
// 设置攻击类型任务启动结果 // 设置攻击类型任务启动结果
deviceTaskManager.setAttackTypeStatus(deviceTask.getId(), deviceTaskManager.setAttackTypeStatus(deviceTask.getId(),
disposeTask.getFlowDirection(), deviceTask.getTaskAttackType()); disposeTask.getFlowDirection(), deviceTask.getTaskAttackType());
// 更改处置任务状态为处置中 // 更改处置任务状态为处置中
deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(), DisposeTaskStatus.TASK_STARTED); deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(), DisposeTaskStatus.TASK_STARTED);
@ -405,18 +418,18 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
// 记录任务出错重试次数 // 记录任务出错重试次数
deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), deviceTask.getErrRetry() + 1); deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), deviceTask.getErrRetry() + 1);
log.error("{} setup task times {} error {}: {}", deviceType, deviceTask.getErrRetry(), log.error("{} setup task times {} error {}: {}", deviceType, deviceTask.getErrRetry(),
ret.getSecondParam(), deviceTask); ret.getSecondParam(), deviceTask);
} else { } else {
// 任务出错不在重试当做失败任务处理 // 任务出错不在重试当做失败任务处理
deviceTaskManager.setAttackTypeStatus(deviceTask.getId(), disposeTask.getFlowDirection(), 0L); deviceTaskManager.setAttackTypeStatus(deviceTask.getId(), disposeTask.getFlowDirection(), 0L);
// 设置该任务为启动失败 // 设置该任务为启动失败
deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(), deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(),
DisposeTaskStatus.TASK_START_FAILED); DisposeTaskStatus.TASK_START_FAILED);
//任务出错设备任务状态为启动处置任务失败 //任务出错设备任务状态为启动处置任务失败
deviceTaskManager.changeDisposeDeviceTaskInfoDevStatus(deviceTask.getId(), deviceTaskManager.changeDisposeDeviceTaskInfoDevStatus(deviceTask.getId(),
(long) PengXinTaskStatus.TASK_STARTED_FAILED.getValue()); (long) PengXinTaskStatus.TASK_STARTED_FAILED.getValue());
// 记录任务出错重试次数 // 记录任务出错重试次数
deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), 0); deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), 0);
@ -444,7 +457,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
// 停止处置任务 // 停止处置任务
ret = ai.getDb().stopDispose(disposeTask.getDisposeObject(), disposeTask.getDisposeCapacity(), null, null, ret = ai.getDb().stopDispose(disposeTask.getDisposeObject(), disposeTask.getDisposeCapacity(), null, null,
deviceTask.getExternId()); deviceTask.getExternId());
if (ret.getFirstParam() == ErrorCode.ERR_OK) { if (ret.getFirstParam() == ErrorCode.ERR_OK) {
log.info("{} stop task succeed: {}, device taskId {}", deviceType, deviceTask, ret.getSecondParam()); log.info("{} stop task succeed: {}, device taskId {}", deviceType, deviceTask, ret.getSecondParam());
@ -456,7 +469,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
// 记录任务出错重试次数 // 记录任务出错重试次数
deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), deviceTask.getErrRetry() + 1); deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), deviceTask.getErrRetry() + 1);
log.error("{} stop task times {} error {}: {}", deviceType, deviceTask.getErrRetry(), log.error("{} stop task times {} error {}: {}", deviceType, deviceTask.getErrRetry(),
ret.getSecondParam(), deviceTask); ret.getSecondParam(), deviceTask);
} else { } else {
// 记录任务出错重试次数 // 记录任务出错重试次数
deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), 0); deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), 0);
@ -475,7 +488,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
// 清理过期任务 // 清理过期任务
for (DisposeTask v : disposeTaskManager.getExpiredTasks()) { for (DisposeTask v : disposeTaskManager.getExpiredTasks()) {
log.info("Task {} {} {} is expired, expect finished at {}", log.info("Task {} {} {} is expired, expect finished at {}",
v.getId(), v.getDisposeCapacity(), v.getDisposeObject(), v.getPlanEndTime()); v.getId(), v.getDisposeCapacity(), v.getDisposeObject(), v.getPlanEndTime());
// 设置任务状态过期任务不再为设备创建处置任务 // 设置任务状态过期任务不再为设备创建处置任务
disposeTaskManager.changeDisposeTaskStatus(v.getId(), DisposeTaskStatus.TASK_EXPIRED); disposeTaskManager.changeDisposeTaskStatus(v.getId(), DisposeTaskStatus.TASK_EXPIRED);
} }
@ -517,15 +530,15 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
// 检查当前设备是否已经创建了该任务 // 检查当前设备是否已经创建了该任务
if (deviceTaskManager.deviceTaskCreated(v.getId(), if (deviceTaskManager.deviceTaskCreated(v.getId(),
d.getDev().getId())) { d.getDev().getId())) {
return; return;
} }
log.info("Add dispose task for device: {}", d.getDev()); log.info("Add dispose task for device: {}", d.getDev());
if (!deviceTaskManager if (!deviceTaskManager
.addDisposeDeviceTaskInfo(v.getId(), .addDisposeDeviceTaskInfo(v.getId(),
d.getDev().getId(), d.getDev().getId(),
d.getDb().toDeviceAttackType(v.getAttackType()))) { d.getDb().toDeviceAttackType(v.getAttackType()))) {
log.error("Add task {} to device {} error", v, d); log.error("Add task {} to device {} error", v, d);
} }
}); });
@ -723,9 +736,9 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
if (ret.getFirstParam() == ErrorCode.ERR_OK) { if (ret.getFirstParam() == ErrorCode.ERR_OK) {
log.debug("id:{}, before devStatus:{}, after devStatus:{}", v.getId(), log.debug("id:{}, before devStatus:{}, after devStatus:{}", v.getId(),
v.getDevStatus(), ret.getSecondParam()); v.getDevStatus(), ret.getSecondParam());
deviceTaskManager.changeDisposeDeviceTaskInfoDevStatus(v.getId(), deviceTaskManager.changeDisposeDeviceTaskInfoDevStatus(v.getId(),
ret.getSecondParam()); ret.getSecondParam());
} }
} }
@ -751,6 +764,8 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
deviceTaskStopSchedule(); deviceTaskStopSchedule();
// 定时刷新设备任务状态 // 定时刷新设备任务状态
deviceTaskStatusSchedule(); if (timerCnt++ % DisposeConfigValue.CMHI_DEVICE_QUERY_PERIOD == 0) {
deviceTaskStatusSchedule();
}
} }
} }

View File

@ -0,0 +1,35 @@
package com.dispose.task;
import com.dispose.common.DisposeConfigValue;
import com.dispose.config.DeviceLogConfigure;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
/**
* The type Refresh config.
* @author xajhu
*/
@Component
@Slf4j
public class RefreshConfigTask {
/**
* The Device log configure.
*/
@Resource
private DeviceLogConfigure deviceLogConfigure;
/**
* Refresh config file task.
*/
@Async("bizExecutor")
@Scheduled(cron = "0/1 * * * * ?")
public void refreshConfigFileTask() {
deviceLogConfigure.refreshConfigValue();
}
}