[monitor] 监控类型名称i18n国际化支持
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package com.usthe.manager.controller;
|
||||
|
||||
import com.usthe.common.entity.dto.Message;
|
||||
import com.usthe.manager.pojo.entity.ParamDefine;
|
||||
import com.usthe.manager.service.AppService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
|
||||
|
||||
/**
|
||||
* 国际化I18N
|
||||
* @author tom
|
||||
* @date 2021/12/4 21:40
|
||||
*/
|
||||
@Api(tags = "I18N国际化资源API")
|
||||
@RestController
|
||||
@RequestMapping(path = "/i18n", produces = {APPLICATION_JSON_VALUE})
|
||||
public class I18nController {
|
||||
|
||||
@Autowired
|
||||
private AppService appService;
|
||||
|
||||
@GetMapping("/{lang}")
|
||||
@ApiOperation(value = "查询总的i18n资源", notes = "查询总的i18n国际化文本资源")
|
||||
public ResponseEntity<Message<Map<String, String>>> queryI18n(
|
||||
@ApiParam(value = "语言类型", example = "zh-CN", defaultValue = "zh-CN")
|
||||
@PathVariable(name = "lang", required = false) String lang) {
|
||||
if (lang == null || "".equals(lang)) {
|
||||
lang = "zh-CN";
|
||||
}
|
||||
lang = lang.equalsIgnoreCase("zh-cn")? "zh-CN" : lang;
|
||||
lang = lang.equalsIgnoreCase("en-us")? "en-US" : lang;
|
||||
Map<String, String> i18nResource = appService.getI18nResources(lang);
|
||||
return ResponseEntity.ok(new Message<>(i18nResource));
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import com.usthe.common.entity.job.Job;
|
||||
import com.usthe.manager.pojo.entity.ParamDefine;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 监控类型管理接口
|
||||
@@ -26,4 +27,11 @@ public interface AppService {
|
||||
* @throws IllegalArgumentException 当不存在即不支持对应名称的监控类型时抛出
|
||||
*/
|
||||
Job getAppDefine(String app) throws IllegalArgumentException;
|
||||
|
||||
/**
|
||||
* 获取定义的监控I18N资源
|
||||
* @param lang 语言类型
|
||||
* @return I18N资源
|
||||
*/
|
||||
Map<String, String> getI18nResources(String lang);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.usthe.manager.pojo.dto.ParamDefineDto;
|
||||
import com.usthe.manager.pojo.entity.ParamDefine;
|
||||
import com.usthe.manager.service.AppService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.kafka.common.protocol.types.Field;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -17,6 +18,7 @@ import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@@ -57,6 +59,23 @@ public class AppServiceImpl implements AppService, CommandLineRunner {
|
||||
return appDefine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getI18nResources(String lang) {
|
||||
Map<String, String> i18nMap = new HashMap<>(32);
|
||||
for (Job job : appDefines.values()) {
|
||||
// todo 暂时只国际化监控类型名称 后面需要支持指标名称
|
||||
Map<String, String> name = job.getName();
|
||||
if (name != null && !name.isEmpty()) {
|
||||
String i18nName = name.get(lang);
|
||||
if (i18nName == null) {
|
||||
i18nName = name.values().stream().findFirst().get();
|
||||
}
|
||||
i18nMap.put("monitor.app." + job.getApp(), i18nName);
|
||||
}
|
||||
}
|
||||
return i18nMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(String... args) throws Exception {
|
||||
// 读取app定义配置加载到内存中 define/app/*.yml
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
# 监控应用类型名称(与文件名保持一致) eg: linux windows tomcat mysql aws...
|
||||
# 监控应用类型(与文件名保持一致) eg: linux windows tomcat mysql aws...
|
||||
app: exapmle
|
||||
name:
|
||||
zh-CN: 模拟应用类型
|
||||
en-US: EXAMPLE APP
|
||||
# 参数映射map. type是参数类型: 0-number数字, 1-string明文字符串, 2-secret加密字符串
|
||||
# 强制固定必须参数 - host
|
||||
configmap:
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
# 监控应用类型名称(与文件名保持一致) eg: linux windows tomcat mysql aws...
|
||||
app: api
|
||||
name:
|
||||
zh-CN: HTTP API
|
||||
en-US: HTTP API
|
||||
# 参数映射map. type是参数类型: 0-number数字, 1-string明文字符串, 2-secret加密字符串
|
||||
# 强制固定必须参数 - host
|
||||
configmap:
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
# 监控应用类型名称(与文件名保持一致) eg: linux windows tomcat mysql aws...
|
||||
app: ping
|
||||
name:
|
||||
zh-CN: PING连通性
|
||||
en-US: PING CONNECT
|
||||
# 参数映射map. type是参数类型: 0-number数字, 1-string明文字符串, 2-secret加密字符串
|
||||
# 强制固定必须参数 - host
|
||||
configmap:
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
app: telnet
|
||||
name:
|
||||
zh-CN: TELNET端口可用性
|
||||
en-US: PORT TELNET
|
||||
configmap:
|
||||
- key: host
|
||||
type: 1
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# 监控应用类型名称(与文件名保持一致) eg: linux windows tomcat mysql aws...
|
||||
app: website
|
||||
# 参数映射map. type是参数类型: 0-number数字, 1-string明文字符串, 2-secret加密字符串
|
||||
# 强制固定必须参数 - host
|
||||
name:
|
||||
zh-CN: 网站监测
|
||||
en-US: WEBSITE MONITOR
|
||||
configmap:
|
||||
- key: host
|
||||
type: 1
|
||||
|
||||
Reference in New Issue
Block a user