This is an automated email from the ASF dual-hosted git repository.
zhaoqingran pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hertzbeat.git
The following commit(s) were added to refs/heads/master by this push:
new c30295cf9 [improve] Increase the priority of configuration
initialization (#2709)
c30295cf9 is described below
commit c30295cf9cbf0b9fabc7c12844d9aa633de0e199
Author: liutianyou <[email protected]>
AuthorDate: Fri Sep 13 08:10:46 2024 +0800
[improve] Increase the priority of configuration initialization (#2709)
---
...mmandLineRunner.java => ConfigInitializer.java} | 52 ++++++++++++++++------
1 file changed, 38 insertions(+), 14 deletions(-)
diff --git
a/manager/src/main/java/org/apache/hertzbeat/manager/config/CommonCommandLineRunner.java
b/manager/src/main/java/org/apache/hertzbeat/manager/config/ConfigInitializer.java
similarity index 89%
rename from
manager/src/main/java/org/apache/hertzbeat/manager/config/CommonCommandLineRunner.java
rename to
manager/src/main/java/org/apache/hertzbeat/manager/config/ConfigInitializer.java
index f1cac1a2b..a571e6bff 100644
---
a/manager/src/main/java/org/apache/hertzbeat/manager/config/CommonCommandLineRunner.java
+++
b/manager/src/main/java/org/apache/hertzbeat/manager/config/ConfigInitializer.java
@@ -24,6 +24,7 @@ import java.text.SimpleDateFormat;
import java.util.Locale;
import java.util.Random;
import java.util.TimeZone;
+import lombok.SneakyThrows;
import org.apache.commons.lang3.StringUtils;
import org.apache.hertzbeat.common.constants.CommonConstants;
import org.apache.hertzbeat.common.entity.manager.GeneralConfig;
@@ -37,46 +38,48 @@ import
org.apache.hertzbeat.manager.service.impl.SystemGeneralConfigServiceImpl;
import org.apache.hertzbeat.manager.service.impl.SystemSecretServiceImpl;
import org.apache.hertzbeat.manager.service.impl.TemplateConfigServiceImpl;
import org.springframework.beans.factory.annotation.Value;
-import org.springframework.boot.CommandLineRunner;
+import org.springframework.context.SmartLifecycle;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
/**
- * Common CommandLineRunner class
+ * Config Initializer
*/
@Component
@Order(value = Ordered.HIGHEST_PRECEDENCE + 2)
-public class CommonCommandLineRunner implements CommandLineRunner {
+public class ConfigInitializer implements SmartLifecycle {
- private static final String DEFAULT_JWT_SECRET =
"CyaFv0bwq2Eik0jdrKUtsA6bx3sDJeFV643R "
+ private boolean running = false;
+
+ private static final String DEFAULT_JWT_SECRET =
"CyaFv0bwq2Eik0jdrKUtsA6bx3sDJeFV643R "
+ "LnfKefTjsIfJLBa2YkhEqEGtcHDTNe4CU6+9 "
+ "8tVt4bisXQ13rbN0oxhUZR73M6EByXIO+SV5 "
+ "dKhaX0csgOCTlCxq20yhmUea6H6JIpSE2Rwp";
-
+
@Value("${sureness.jwt.secret:" + DEFAULT_JWT_SECRET + "}")
private String currentJwtSecret;
-
+
@Resource
private SystemGeneralConfigServiceImpl systemGeneralConfigService;
-
+
@Resource
private SystemSecretServiceImpl systemSecretService;
-
+
@Resource
private TemplateConfigServiceImpl templateConfigService;
-
+
@Resource
private AppService appService;
-
+
@Resource
protected GeneralConfigDao generalConfigDao;
-
+
@Resource
protected ObjectMapper objectMapper;
- @Override
- public void run(String... args) throws Exception {
+ @SneakyThrows
+ public void initConfig() {
// for system config
SystemConfig systemConfig = systemGeneralConfigService.getConfig();
if (systemConfig != null) {
@@ -89,7 +92,7 @@ public class CommonCommandLineRunner implements
CommandLineRunner {
} else {
// init system config data
systemConfig =
SystemConfig.builder().timeZoneId(TimeZone.getDefault().getID())
- .locale(Locale.getDefault().getLanguage() +
CommonConstants.LOCALE_SEPARATOR
+ .locale(Locale.getDefault().getLanguage() +
CommonConstants.LOCALE_SEPARATOR
+
Locale.getDefault().getCountry())
.build();
String contentJson = objectMapper.writeValueAsString(systemConfig);
@@ -126,4 +129,25 @@ public class CommonCommandLineRunner implements
CommandLineRunner {
// set the jwt secret token in util
JsonWebTokenUtil.setDefaultSecretKey(currentJwtSecret);
}
+
+ @Override
+ public void start() {
+ initConfig();
+ running = true;
+ }
+
+ @Override
+ public void stop() {
+ running = false;
+ }
+
+ @Override
+ public boolean isRunning() {
+ return running;
+ }
+
+ @Override
+ public int getPhase() {
+ return Ordered.HIGHEST_PRECEDENCE;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]