From 38d1af69ad7b63381ef3177e1aaab8f2a8729dbe Mon Sep 17 00:00:00 2001 From: QIANGLU <598505651@qq.com> Date: Tue, 2 Jun 2020 18:34:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8A=A8=E6=80=81=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../agent/core/conf/CubicConfInitalizer.java | 25 +++++++++++++++++++ .../src/main/resources/application.yml | 5 ++++ 2 files changed, 30 insertions(+) diff --git a/cubic-core/src/main/java/com/matrix/cubic/agent/core/conf/CubicConfInitalizer.java b/cubic-core/src/main/java/com/matrix/cubic/agent/core/conf/CubicConfInitalizer.java index b2ff52c..68a8bfd 100644 --- a/cubic-core/src/main/java/com/matrix/cubic/agent/core/conf/CubicConfInitalizer.java +++ b/cubic-core/src/main/java/com/matrix/cubic/agent/core/conf/CubicConfInitalizer.java @@ -11,6 +11,7 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; +import java.util.Map; import java.util.Properties; import java.util.UUID; @@ -28,6 +29,8 @@ public class CubicConfInitalizer { private final static String SYSTEM_CONFIG_PATH = "cubic_config"; private final static String DEFAULT_CONFIG_FILE_NAME = "/config/agent.config"; + private static final String ENV_KEY_PREFIX = "cubic."; + private static boolean IS_INIT_COMPLETED = false; public static void initConfig() { @@ -39,6 +42,12 @@ public class CubicConfInitalizer { logger.error("Failed to read the config file, agent will is going to run in default config.", e); } + try { + overrideConfigBySystemProp(); + } catch (Exception e) { + logger.error( "Failed to read the system properties.",e); + } + IS_INIT_COMPLETED = true; if(StringUtils.isEmpty(AgentConfig.Agent.INSTANCE_UUID)){ @@ -66,4 +75,20 @@ public class CubicConfInitalizer { throw new CubicConfigNotFoundException("Failed to load agent.config"); } + + private static void overrideConfigBySystemProp() throws IllegalAccessException { + Properties properties = new Properties(); + Properties systemProperties = System.getProperties(); + for (final Map.Entry prop : systemProperties.entrySet()) { + String key = prop.getKey().toString(); + if (key.startsWith(ENV_KEY_PREFIX)) { + String realKey = key.substring(ENV_KEY_PREFIX.length()); + properties.put(realKey, prop.getValue()); + } + } + + if (!properties.isEmpty()) { + CubicConfigConvert.initialize(properties, AgentConfig.class); + } + } } diff --git a/cubic-proxy/src/main/resources/application.yml b/cubic-proxy/src/main/resources/application.yml index 3997247..844e9fd 100644 --- a/cubic-proxy/src/main/resources/application.yml +++ b/cubic-proxy/src/main/resources/application.yml @@ -7,6 +7,10 @@ spring: password: admin profiles: active: dev + redis: + lettuce: + pool: + max-active: server: port: 6081 tomcat: @@ -23,6 +27,7 @@ management: web: base-path: / + log: level: info path: /tmp/logs