From d055446f98f7d36531e464daf6b92aaa696c70aa Mon Sep 17 00:00:00 2001 From: tomsun28 Date: Sun, 30 Jan 2022 13:00:12 +0800 Subject: [PATCH] =?UTF-8?q?[collector,manager]=E7=9B=91=E6=8E=A7=E5=AF=86?= =?UTF-8?q?=E9=92=A5=E5=8A=A0=E5=AF=86=E4=BC=A0=E8=BE=93=EF=BC=8Cradio?= =?UTF-8?q?=E5=85=A5=E5=8F=82=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dispatch/timer/WheelTimerTask.java | 17 +++++++++++++- .../service/impl/MonitorServiceImpl.java | 22 ++++++++++++++++--- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/collector/src/main/java/com/usthe/collector/dispatch/timer/WheelTimerTask.java b/collector/src/main/java/com/usthe/collector/dispatch/timer/WheelTimerTask.java index 6998ffe..fb50aed 100644 --- a/collector/src/main/java/com/usthe/collector/dispatch/timer/WheelTimerTask.java +++ b/collector/src/main/java/com/usthe/collector/dispatch/timer/WheelTimerTask.java @@ -10,6 +10,9 @@ import com.usthe.collector.util.SpringContextHolder; import com.usthe.common.entity.job.Configmap; import com.usthe.common.entity.job.Job; import com.usthe.common.entity.job.Metrics; +import com.usthe.common.util.AesUtil; +import com.usthe.common.util.CommonConstants; +import lombok.extern.slf4j.Slf4j; import java.util.ArrayList; import java.util.Iterator; @@ -22,6 +25,7 @@ import java.util.stream.Collectors; * @author tomsun28 * @date 2021/11/1 17:18 */ +@Slf4j public class WheelTimerTask implements TimerTask { private final Job job; @@ -42,7 +46,18 @@ public class WheelTimerTask implements TimerTask { private void initJobMetrics(Job job) { // 将监控实际参数值对采集字段进行替换 List config = job.getConfigmap(); - Map configmap = config.stream().collect(Collectors.toMap(Configmap::getKey, item -> item)); + Map configmap = config.stream() + .peek(item -> { + // 对加密串进行解密 + if (item.getType() == CommonConstants.PARAM_TYPE_PASSWORD && item.getValue() != null) { + String decodeValue = AesUtil.aesDecode(String.valueOf(item.getValue())); + if (decodeValue == null) { + log.error("Aes Decode value {} error.", item.getValue()); + } + item.setValue(decodeValue); + } + }) + .collect(Collectors.toMap(Configmap::getKey, item -> item)); List metrics = job.getMetrics(); List metricsTmp = new ArrayList<>(metrics.size()); for (Metrics metric : metrics) { diff --git a/manager/src/main/java/com/usthe/manager/service/impl/MonitorServiceImpl.java b/manager/src/main/java/com/usthe/manager/service/impl/MonitorServiceImpl.java index 458961d..7944ef4 100644 --- a/manager/src/main/java/com/usthe/manager/service/impl/MonitorServiceImpl.java +++ b/manager/src/main/java/com/usthe/manager/service/impl/MonitorServiceImpl.java @@ -131,10 +131,10 @@ public class MonitorServiceImpl implements MonitorService { for (ParamDefine paramDefine : paramDefines) { String field = paramDefine.getField(); Param param = paramMap.get(field); - if (paramDefine.isRequired() && param == null) { + if (paramDefine.isRequired() && (param == null || param.getValue() == null)) { throw new IllegalArgumentException("Params field " + field + " is required."); } - if (param != null) { + if (param != null && param.getValue() != null && !"".equals(param.getValue())) { switch (paramDefine.getType()) { case "number": double doubleValue; @@ -151,6 +151,7 @@ public class MonitorServiceImpl implements MonitorService { + paramDefine.getType() + " over range " + paramDefine.getRange()); } } + param.setType(CommonConstants.PARAM_TYPE_NUMBER); break; case "text": Short limit = paramDefine.getLimit(); @@ -175,6 +176,7 @@ public class MonitorServiceImpl implements MonitorService { passwordValue = AesUtil.aesEncode(passwordValue); param.setValue(passwordValue); } + param.setType(CommonConstants.PARAM_TYPE_PASSWORD); break; case "boolean": // boolean校验 @@ -187,7 +189,21 @@ public class MonitorServiceImpl implements MonitorService { } break; case "radio": - // todo radio校验 + // radio单选值校验 + List options = paramDefine.getOptions(); + boolean invalid = true; + if (options != null) { + for (ParamDefine.Option option : options) { + if (param.getValue().equalsIgnoreCase(option.getValue())) { + invalid = false; + break; + } + } + } + if (invalid) { + throw new IllegalArgumentException("Params field " + field + " value " + + param.getValue() + " is invalid option value"); + } break; case "checkbox": // todo checkbox校验