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.used-privacy-protect=false
# 集团一键处置设备状态轮询时间
dispose.cmhi-device-query-period=3
dispose.call-error-retry-times=3
# 分页配置项
@ -52,4 +54,5 @@ trust.auth-hosts=127.0.0.12,::1
#需要调试的设备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 volatile int CMHI_DEVICE_QUERY_PERIOD = 1;
/**
* The constant LOG_HOSTS.
*/
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.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import javax.annotation.PostConstruct;
import java.util.Arrays;
import java.util.Locale;
import java.util.Optional;
@ -25,18 +27,24 @@ import java.util.Optional;
@ConfigurationProperties(prefix = "device")
@Configuration
@Slf4j
public class DeviceLogConfigure {
public class DeviceLogConfigure implements WebMvcConfigurer {
/**
* The Log hosts.
*/
private String[] logHosts;
/**
* The Log paths.
*/
private String[] logPaths;
/**
* Init global value.
*/
@PostConstruct
private void initGlobalValue() {
DisposeConfigValue.LOG_HOSTS.clear();
DisposeConfigValue.LOG_PATHS.clear();
for (String s : Optional.ofNullable(logHosts).orElse(new String[]{""})) {
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 path: {}", DisposeConfigValue.LOG_PATHS);
}
/**
* Refresh config value.
*/
public void refreshConfigValue() {
initGlobalValue();
}
}

View File

@ -56,11 +56,17 @@ public class DisposeConfigure {
*/
private Integer minSplitPageSize;
/**
* The Cmhi device query period.
*/
private Integer cmhiDeviceQueryPeriod;
/**
* Init global value.
*/
@PostConstruct
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.CHECK_PROTO_REQUEST_TIMEOUT = Optional.ofNullable(checkProtocolTimeout).orElse(true);
DisposeConfigValue.USED_PRIVACY_PROTECT = Optional.ofNullable(usedPrivacyProtect).orElse(true);

View File

@ -225,7 +225,8 @@ public class RestfulInterface {
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) {
log.debug("Restful response: {} {}, {}: \n+++{}\n---{}", reqType.name(), url, token, reqJson, svrResp);
} else {

View File

@ -60,6 +60,11 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
@Resource
private DisposeAbilityRouterService disposeAbilityRouterService;
/**
* The Timer cnt.
*/
private long timerCnt = 0;
/**
* Is carry ip boolean.
@ -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,
DeviceTask deviceTask,
DisposeTask disposeTask, NetflowDirection netflowDirection) {
@ -751,6 +764,8 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
deviceTaskStopSchedule();
// 定时刷新设备任务状态
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();
}
}