Prechádzať zdrojové kódy

增加配置项分组文件与访问接口

luoshi 2 rokov pred
rodič
commit
c68bf40248

+ 10 - 4
src/main/java/com/qmth/ops/api/controller/admin/ConfigController.java

@@ -2,12 +2,10 @@ package com.qmth.ops.api.controller.admin;
 
 import com.qmth.ops.api.binder.FileFormatBinder;
 import com.qmth.ops.api.constants.OpsApiConstants;
+import com.qmth.ops.biz.domain.ConfigGroup;
 import com.qmth.ops.biz.domain.ConfigItem;
 import com.qmth.ops.biz.domain.FileFormat;
-import com.qmth.ops.biz.service.AppService;
-import com.qmth.ops.biz.service.ConfigService;
-import com.qmth.ops.biz.service.ModuleService;
-import com.qmth.ops.biz.service.VersionService;
+import com.qmth.ops.biz.service.*;
 import org.springframework.web.bind.WebDataBinder;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
@@ -20,6 +18,9 @@ import java.util.List;
 @RequestMapping(OpsApiConstants.ADMIN_URI_PREFIX + "/config")
 public class ConfigController {
 
+    @Resource
+    private ConfigGroupService configGroupService;
+
     @Resource
     private ConfigService configService;
 
@@ -37,6 +38,11 @@ public class ConfigController {
         dataBinder.addCustomFormatter(new FileFormatBinder());
     }
 
+    @PostMapping("/groups")
+    public List<ConfigGroup> listGroups() {
+        return configGroupService.getConfigGroupList();
+    }
+
     @PostMapping("/baseline")
     public List<ConfigItem> listBaseline(@RequestParam Long appId, @RequestParam Long versionId,
             @RequestParam Long moduleId) {

+ 36 - 0
src/main/java/com/qmth/ops/biz/domain/ConfigGroup.java

@@ -0,0 +1,36 @@
+package com.qmth.ops.biz.domain;
+
+import java.util.List;
+
+public class ConfigGroup {
+
+    private String name;
+
+    private String prefix;
+
+    private List<ConfigGroupItem> available;
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getPrefix() {
+        return prefix;
+    }
+
+    public void setPrefix(String prefix) {
+        this.prefix = prefix;
+    }
+
+    public List<ConfigGroupItem> getAvailable() {
+        return available;
+    }
+
+    public void setAvailable(List<ConfigGroupItem> available) {
+        this.available = available;
+    }
+}

+ 54 - 0
src/main/java/com/qmth/ops/biz/domain/ConfigGroupItem.java

@@ -0,0 +1,54 @@
+package com.qmth.ops.biz.domain;
+
+public class ConfigGroupItem {
+
+    private String key;
+
+    private String description;
+
+    private String type;
+
+    private Object defaultValue;
+
+    private Object[] options;
+
+    public String getKey() {
+        return key;
+    }
+
+    public void setKey(String key) {
+        this.key = key;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public Object getDefaultValue() {
+        return defaultValue;
+    }
+
+    public void setDefaultValue(Object defaultValue) {
+        this.defaultValue = defaultValue;
+    }
+
+    public Object[] getOptions() {
+        return options;
+    }
+
+    public void setOptions(Object[] options) {
+        this.options = options;
+    }
+}

+ 42 - 0
src/main/java/com/qmth/ops/biz/service/ConfigGroupService.java

@@ -0,0 +1,42 @@
+package com.qmth.ops.biz.service;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.type.CollectionType;
+import com.qmth.ops.biz.domain.ConfigGroup;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+@Service
+public class ConfigGroupService {
+
+    private static final Logger log = LoggerFactory.getLogger(ConfigGroupService.class);
+
+    private static String[] FILE_PATH = { "config/qmth-boot.json", "config/spring.json" };
+
+    private List<ConfigGroup> configGroupList = new ArrayList<>();
+
+    public ConfigGroupService() throws IOException {
+        loadGroupFile(configGroupList, FILE_PATH);
+    }
+
+    private void loadGroupFile(List<ConfigGroup> configGroupList, String... path) throws IOException {
+        ObjectMapper mapper = new ObjectMapper();
+        CollectionType collectionType = mapper.getTypeFactory()
+                .constructCollectionType(ArrayList.class, ConfigGroup.class);
+        for (String filePath : path) {
+            List<ConfigGroup> list = mapper
+                    .readValue(this.getClass().getClassLoader().getResourceAsStream(filePath), collectionType);
+            log.info(filePath + " size=" + list.size());
+            configGroupList.addAll(list);
+        }
+    }
+
+    public List<ConfigGroup> getConfigGroupList() {
+        return configGroupList;
+    }
+}

+ 454 - 0
src/main/resources/config/qmth-boot.json

@@ -0,0 +1,454 @@
+[
+  {
+    "name": "qmth-boot:starter-api",
+    "prefix": "com.qmth.api",
+    "available": [
+      {
+        "key": "com.qmth.api.uri-prefix",
+        "description": "API统一使用的uri前缀",
+        "type": "string",
+        "defaultValue": "/api",
+        "options": []
+      },
+      {
+        "key": "com.qmth.api.error-mapping",
+        "description": "是否启用/error映射处理",
+        "type": "boolean",
+        "defaultValue": true,
+        "options": []
+      },
+      {
+        "key": "com.qmth.api.global-strict",
+        "description": "是否全局默认严格模式",
+        "type": "boolean",
+        "defaultValue": false,
+        "options": []
+      },
+      {
+        "key": "com.qmth.api.global-auth",
+        "description": "全局默认鉴权",
+        "type": "boolean",
+        "defaultValue": false,
+        "options": []
+      },
+      {
+        "key": "com.qmth.api.global-rate-limit",
+        "description": "全局默认限流规则",
+        "type": "string",
+        "defaultValue": null,
+        "options": []
+      },
+      {
+        "key": "com.qmth.api.metrics-endpoint",
+        "description": "统计查询接口",
+        "type": "string",
+        "defaultValue": null,
+        "options": []
+      }
+    ]
+  },
+  {
+    "name": "qmth-boot:data-mybatis-plus@datasource",
+    "prefix": "com.qmth.datasource",
+    "available": [
+      {
+        "key": "com.qmth.datasource.driver-class-name",
+        "description": "MySQL不用额外填写",
+        "type": "string",
+        "defaultValue": "com.mysql.cj.jdbc.Driver",
+        "options": []
+      },
+      {
+        "key": "com.qmth.datasource.url",
+        "description": "数据库连接地址",
+        "type": "string",
+        "defaultValue": null,
+        "options": []
+      },
+      {
+        "key": "com.qmth.datasource.username",
+        "description": "数据库连接账号",
+        "type": "string",
+        "defaultValue": null,
+        "options": []
+      },
+      {
+        "key": "com.qmth.datasource.password",
+        "description": "数据库连接密码",
+        "type": "string",
+        "defaultValue": null,
+        "options": []
+      },
+      {
+        "key": "com.qmth.datasource.min-idle",
+        "description": "数据库连接池最小闲置",
+        "type": "number",
+        "defaultValue": 5,
+        "options": []
+      },
+      {
+        "key": "com.qmth.datasource.max-pool-size",
+        "description": "数据库连接池最大数量",
+        "type": "number",
+        "defaultValue": 10,
+        "options": []
+      },
+      {
+        "key": "com.qmth.datasource.idle-timeout",
+        "description": "数据库连接闲置超时时间",
+        "type": "duration",
+        "defaultValue": "10m",
+        "options": []
+      },
+      {
+        "key": "com.qmth.datasource.connection-timeout",
+        "description": "数据库连接超时时间",
+        "type": "duration",
+        "defaultValue": "30s",
+        "options": []
+      },
+      {
+        "key": "com.qmth.datasource.max-lifetime",
+        "description": "数据库连接超时时间",
+        "type": "duration",
+        "defaultValue": "7h",
+        "options": []
+      }
+    ]
+  },
+  {
+    "name": "qmth-boot:data-mybatis-plus@mybatis",
+    "prefix": "com.qmth.mybatis",
+    "available": [
+      {
+        "key": "com.qmth.mybatis.log-level",
+        "description": "mybatis日志级别",
+        "type": "string",
+        "defaultValue": "info",
+        "options": [
+          "trace",
+          "debug",
+          "info",
+          "warn",
+          "error",
+          "off"
+        ]
+      }
+    ]
+  },
+  {
+    "name": "qmth-boot:data-redis",
+    "prefix": "com.qmth.redis",
+    "available": [
+      {
+        "key": "com.qmth.redis.host",
+        "description": "redis主机",
+        "type": "string",
+        "defaultValue": null,
+        "options": []
+      },
+      {
+        "key": "com.qmth.redis.port",
+        "description": "redis端口",
+        "type": "number",
+        "defaultValue": 6379,
+        "options": []
+      },
+      {
+        "key": "com.qmth.redis.db",
+        "description": "redis库编号",
+        "type": "number",
+        "defaultValue": 0,
+        "options": []
+      },
+      {
+        "key": "com.qmth.redis.password",
+        "description": "redis连接密码",
+        "type": "string",
+        "defaultValue": null,
+        "options": []
+      },
+      {
+        "key": "com.qmth.redis.use-ssl",
+        "description": "是否使用SSL连接",
+        "type": "boolean",
+        "defaultValue": false,
+        "options": []
+      },
+      {
+        "key": "com.qmth.redis.timeout",
+        "description": "redis命令超时时间",
+        "type": "duration",
+        "defaultValue": "3s",
+        "options": []
+      }
+    ]
+  },
+  {
+    "name": "qmth-boot:core-security",
+    "prefix": "com.qmth.auth",
+    "available": [
+      {
+        "key": "com.qmth.auth.time-max-delay",
+        "description": "服务器时间晚于鉴权时间戳最大时长",
+        "type": "duration",
+        "defaultValue": "15s",
+        "options": []
+      },
+      {
+        "key": "com.qmth.auth.time-max-ahead",
+        "description": "服务器时间早于鉴权时间戳最大时长",
+        "type": "duration",
+        "defaultValue": "5s",
+        "options": []
+      }
+    ]
+  },
+  {
+    "name": "qmth-boot:core-uid",
+    "prefix": "com.qmth.uid",
+    "available": [
+      {
+        "key": "com.qmth.uid.datacenter-id",
+        "description": "数据中心编号,需要在0~7之间",
+        "type": "number",
+        "defaultValue": "0",
+        "options": [
+          0,
+          1,
+          2,
+          3,
+          4,
+          5,
+          6,
+          7
+        ]
+      }
+    ]
+  },
+  {
+    "name": "qmth-boot:core-cache",
+    "prefix": "com.qmth.cache",
+    "available": [
+      {
+        "key": "com.qmth.cache.allow-null-value",
+        "description": "是否允许空值缓存",
+        "type": "boolean",
+        "defaultValue": true,
+        "options": []
+      },
+      {
+        "key": "com.qmth.cache.expire-after-write",
+        "description": "缓存写入后的强制失效时长,大于0时才生效",
+        "type": "duration",
+        "defaultValue": "0s",
+        "options": []
+      }
+    ]
+  },
+  {
+    "name": "qmth-boot:core-fss",
+    "prefix": "com.qmth.fss",
+    "available": [
+      {
+        "key": "com.qmth.fss.*.config",
+        "description": "多存储模式bucket设置",
+        "type": "string",
+        "defaultValue": null,
+        "options": []
+      },
+      {
+        "key": "com.qmth.fss.*.server",
+        "description": "多存储模式bucket访问前缀",
+        "type": "string",
+        "defaultValue": null,
+        "options": []
+      },
+      {
+        "key": "com.qmth.fss.config",
+        "description": "单存储模式设置",
+        "type": "string",
+        "defaultValue": null,
+        "options": []
+      },
+      {
+        "key": "com.qmth.fss.server",
+        "description": "单存储模式访问前缀",
+        "type": "string",
+        "defaultValue": null,
+        "options": []
+      }
+    ]
+  },
+  {
+    "name": "qmth-boot:core-logging",
+    "prefix": "com.qmth.logging",
+    "available": [
+      {
+        "key": "com.qmth.logging.pattern",
+        "description": "日志格式,不建议修改",
+        "type": "string",
+        "defaultValue": "%d{yyyy-MM-dd HH:mm:ss.SSS} | %-5level | %X{TRACE_ID} | %X{CALLER} | %logger{39}:%L | %msg%n",
+        "options": []
+      },
+      {
+        "key": "com.qmth.logging.root-level",
+        "description": "root日志级别",
+        "type": "string",
+        "defaultValue": "info",
+        "options": [
+          "trace",
+          "debug",
+          "info",
+          "warn",
+          "error",
+          "off"
+        ]
+      },
+      {
+        "key": "com.qmth.logging.file-path",
+        "description": "基本日志文件全路径,不设置表示不启用日志文件",
+        "type": "string",
+        "defaultValue": null,
+        "options": []
+      },
+      {
+        "key": "com.qmth.logging.file-max-history",
+        "description": "日志文件最多保留天数",
+        "type": "number",
+        "defaultValue": 7,
+        "options": []
+      },
+      {
+        "key": "com.qmth.logging.file-max-size",
+        "description": "拆分单个日志文件最大容量",
+        "type": "datasize",
+        "defaultValue": "100MB",
+        "options": []
+      },
+      {
+        "key": "com.qmth.logging.file-total-size",
+        "description": "所有日志文件容量上限",
+        "type": "datasize",
+        "defaultValue": "20GB",
+        "options": []
+      }
+    ]
+  },
+  {
+    "name": "qmth-boot:core-retrofit",
+    "prefix": "com.qmth.retrofit",
+    "available": [
+      {
+        "key": "com.qmth.retrofit.connect-timeout",
+        "description": "连接超时",
+        "type": "duration",
+        "defaultValue": "10s",
+        "options": []
+      },
+      {
+        "key": "com.qmth.retrofit.read-timeout",
+        "description": "读取超时",
+        "type": "duration",
+        "defaultValue": "10s",
+        "options": []
+      },
+      {
+        "key": "com.qmth.retrofit.write-timeout",
+        "description": "写入超时",
+        "type": "duration",
+        "defaultValue": "10s",
+        "options": []
+      },
+      {
+        "key": "com.qmth.retrofit.pool.max-idle",
+        "description": "连接池最大空闲",
+        "type": "number",
+        "defaultValue": 1,
+        "options": []
+      },
+      {
+        "key": "com.qmth.retrofit.pool.keep-alive",
+        "description": "连接池空闲时间",
+        "type": "duration",
+        "defaultValue": "10m",
+        "options": []
+      },
+      {
+        "key": "com.qmth.retrofit.retry.count",
+        "description": "最多重试次数",
+        "type": "number",
+        "defaultValue": 3,
+        "options": []
+      },
+      {
+        "key": "com.qmth.retrofit.retry.interval",
+        "description": "重试间隔时间",
+        "type": "duration",
+        "defaultValue": "300ms",
+        "options": []
+      },
+      {
+        "key": "com.qmth.retrofit.log-level",
+        "description": "日志级别",
+        "type": "string",
+        "defaultValue": "off",
+        "options": [
+          "trace",
+          "debug",
+          "info",
+          "warn",
+          "error",
+          "off"
+        ]
+      }
+    ]
+  },
+  {
+    "name": "qmth-boot:core-solar",
+    "prefix": "com.qmth.solar",
+    "available": [
+      {
+        "key": "com.qmth.solar.server",
+        "description": "solar服务地址",
+        "type": "string",
+        "defaultValue": "https://solar.qmth.com.cn",
+        "options": []
+      },
+      {
+        "key": "com.qmth.solar.access-key",
+        "description": "在线模式访问key",
+        "type": "string",
+        "defaultValue": null,
+        "options": []
+      },
+      {
+        "key": "com.qmth.solar.access-secret",
+        "description": "在线模式访问secret",
+        "type": "string",
+        "defaultValue": null,
+        "options": []
+      },
+      {
+        "key": "com.qmth.solar.license",
+        "description": "离线模式授权文件路径",
+        "type": "string",
+        "defaultValue": null,
+        "options": []
+      }
+    ]
+  },
+  {
+    "name": "qmth-boot:core-sms",
+    "prefix": "com.qmth.sms",
+    "available": [
+      {
+        "key": "com.qmth.sms.server",
+        "description": "短信服务地址,云端模式不用修改",
+        "type": "string",
+        "defaultValue": "https://solar.qmth.com.cn",
+        "options": []
+      }
+    ]
+  }
+]

+ 27 - 0
src/main/resources/config/spring.json

@@ -0,0 +1,27 @@
+[
+  {
+    "name": "server配置",
+    "prefix": "server",
+    "available": []
+  },
+  {
+    "name": "spring配置",
+    "prefix": "spring",
+    "available": []
+  },
+  {
+    "name": "rocketmq配置",
+    "prefix": "rocketmq",
+    "available": []
+  },
+  {
+    "name": "mybatis-plus配置",
+    "prefix": "mybatis-plus",
+    "available": []
+  },
+  {
+    "name": "logging配置",
+    "prefix": "logging",
+    "available": []
+  }
+]