diff options
| author | shizhendong <[email protected]> | 2024-01-17 15:36:12 +0800 |
|---|---|---|
| committer | shizhendong <[email protected]> | 2024-01-17 15:36:12 +0800 |
| commit | 5134f0d574e1c321c00c320c137ae0eff62ad77e (patch) | |
| tree | 71180e6043f28537dc2a823fcd15f1a604c26c48 | |
| parent | 0d8e5fabce7e79d49a3a3efb7695646f9e62ecf8 (diff) | |
feat: NEZ-3380 setup 接口取消 redis 配置rel-24.01.01
1. setup 接口取消 redis 配置
2. 取消 redis 相关 configuration
3. 删除 redis jar包依赖
4. setUp db.url 支持多个连接,默认取第一个
45 files changed, 384 insertions, 896 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5a4d16d1..45eb54cb 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -10,8 +10,6 @@ variables: MYSQL_DATABASE: "test" # mariadb 密码配置(必须),注意变量名是 MYSQL_ROOT_PASSWORD MYSQL_ROOT_PASSWORD: '111111' - # redis 端口定义 (必须) - REDIS_PORT: 6379 # sys_i18n 数据源信息 NZ_DB_HOST: "192.168.44.23" NZ_DB_USER: "nezha" @@ -20,7 +18,6 @@ variables: # 定义全局依赖的docker服务,即 这条流水线 pipeline 中的任务都用这里的服务 services: - mariadb:10.2.14 - - redis:6.2.5 # 开始执行脚本前所需执行脚本 before_script: - echo "begin ci" diff --git a/nz-admin/pom.xml b/nz-admin/pom.xml index 9029a8ea..883cb2ac 100644 --- a/nz-admin/pom.xml +++ b/nz-admin/pom.xml @@ -34,15 +34,6 @@ <artifactId>nz-common</artifactId> <version>2.0</version> </dependency> - <!-- 集群环境,需要打开注释 --> - <!--<dependency> --> - <!--<groupId>org.springframework.session</groupId> --> - <!--<artifactId>spring-session-data-redis</artifactId> --> - <!--</dependency> --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-data-redis</artifactId> - </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-freemarker</artifactId> @@ -101,13 +92,6 @@ </exclusion> </exclusions> </dependency> - <!--shiro-redis --> - <!-- https://mvnrepository.com/artifact/org.crazycake/shiro-redis --> - <dependency> - <groupId>org.crazycake</groupId> - <artifactId>shiro-redis</artifactId> - <version>3.3.1</version> - </dependency> <dependency> <groupId>com.github.axet</groupId> <artifactId>kaptcha</artifactId> diff --git a/nz-admin/src/main/java/com/nis/common/config/DataSourceConfig.java b/nz-admin/src/main/java/com/nis/common/config/DataSourceConfig.java index 1f0ee02c..51230264 100644 --- a/nz-admin/src/main/java/com/nis/common/config/DataSourceConfig.java +++ b/nz-admin/src/main/java/com/nis/common/config/DataSourceConfig.java @@ -4,6 +4,8 @@ import cn.hutool.db.Db; import cn.hutool.db.ds.simple.SimpleDataSource; import cn.hutool.log.Log; import com.alibaba.druid.pool.DruidDataSource; +import com.alibaba.druid.pool.ha.HighAvailableDataSource; +import com.alibaba.druid.pool.ha.selector.DataSourceSelector; import com.nis.common.utils.Constant; import com.nis.common.utils.Tool; import lombok.Data; @@ -21,19 +23,25 @@ import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.support.DefaultTransactionDefinition; import javax.sql.DataSource; +import java.sql.Connection; import java.sql.SQLException; import java.util.List; +import java.util.Map; import java.util.Properties; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.concurrent.TimeUnit; @Configuration public class DataSourceConfig { private static final Log log = Log.get(); - - @Value("${database.host}") - private String databaseHost; - @Value("${database.port:3306}") - private int databasePort; + + /** + * 格式: IP:port, 例:192.168.44.36:3306,192.168.44.36:3307 + */ + @Value("${database.url}") + private String databaseUrl; @Value("${database.name}") private String databaseName; @Value("${database.user}") @@ -52,7 +60,22 @@ public class DataSourceConfig { private String urlPattern; @Value("${spring.datasource.druid.driver-class-name:com.mysql.cj.jdbc.Driver}") private String driver; - + /** + * 默认10s检查一次 + */ + @Value("${ha.checkingIntervalSeconds:10}") + private int haCheckingIntervalSeconds; + /** + * 默认超过3次失败,放入黑名单 + */ + @Value("${ha.blacklistThreshold:3}") + private int haBlacklistThreshold; + /** + * 默认延迟5分钟启动检查 + */ + @Value("${ha.checkingDelaySeconds:300}") + private int haCheckingDelaySeconds; + @Data @Component @ConfigurationProperties("spring.datasource") @@ -82,22 +105,50 @@ public class DataSourceConfig { */ @Bean public DataSource dataSource() throws SQLException { - if(!Tool.StrUtil.isAllNotBlank(this.databaseHost,this.databaseUser,this.databaseName)) { + if(!Tool.StrUtil.isAllNotBlank(this.databaseUrl,this.databaseUser,this.databaseName)) { return null; } /* 数据库密码解密 */ databasePin = Tool.AesUtil.decrypt(this.databasePin, Constant.AES_SECRET_KEY); - //初始化时创建 数据库 - this.createDatabase(); - log.info("datasource config,user:{}, url: {}",this.databaseUser,this.getDbUrl()); - DruidDataSource dataSource = new DruidDataSource(); - //设置 druid config - dataSource.setConnectProperties(druidConfig.getDruid()); - dataSource.setUrl(this.getDbUrl()); - dataSource.setUsername(this.databaseUser); - dataSource.setPassword(this.databasePin); - dataSource.init(); - return dataSource; + // 默认获取第一个 url 做为数据源 + List<String> urlList = Tool.ListUtil.list(false, this.databaseUrl.split(",")); + // TODO 暂时不需要排序,目前强制使用第一个作为数据源 + // urlList.sort(Comparator.naturalOrder()); + + Map<String, DataSource> dataSourceMap = Tool.MapUtil.newHashMap(); + String[] urlArr = urlList.get(0).split(":"); + // 自动创建数据库 + this.createDatabase(urlArr[0], Tool.NumberUtil.parseInt(urlArr[1]), this.databaseUser, this.databasePin); + // 创建 master datasource + DruidDataSource dataSource = new DruidDataSource(); + // 设置 druid config + dataSource.setConnectProperties(druidConfig.getDruid()); + dataSource.setUrl(this.getDbUrl(urlArr[0], Tool.NumberUtil.parseInt(urlArr[1]))); + dataSource.setUsername(this.databaseUser); + dataSource.setPassword(this.databasePin); + dataSource.init(); + dataSourceMap.put(MasterFirstDataSourceSelector.MASTER_KEY, dataSource); + log.info("master datasource init, url: {}", dataSource.getUrl()); + // TODO 解开以下代码以满足多数据源 + /*if (urlList.size() > 1) { + urlArr = urlList.get(1).split(":"); + DruidDataSource slaveDataSource = new DruidDataSource(); + // 设置 druid config + slaveDataSource.setConnectProperties(druidConfig.getDruid()); + slaveDataSource.setUrl(this.getDbUrl(urlArr[0], Tool.NumberUtil.parseInt(urlArr[1]))); + slaveDataSource.setUsername(this.databaseUser); + slaveDataSource.setPassword(this.databasePin); + slaveDataSource.init(); + log.info("slave datasource init, url: {}", slaveDataSource.getUrl()); + dataSourceMap.put(MasterFirstDataSourceSelector.SLAVE_KEY, slaveDataSource); + }*/ + // 创建高可用 DataSource + HighAvailableDataSource haDS = new HighAvailableDataSource(); + DataSourceSelector selector = new MasterFirstDataSourceSelector(haDS); + haDS.setDataSourceSelector(selector); + haDS.setDataSourceMap(dataSourceMap); + haDS.init(); + return haDS; } /** 返回data数据库的事务 @@ -139,22 +190,21 @@ public class DataSourceConfig { * 获取数据库连接url * @return */ - private String getDbUrl() { - return this.urlPattern.replace("{{host}}", this.databaseHost) - .replace("{{port}}", String.valueOf(this.databasePort)) - .replace("{{dbName}}", this.databaseName); + private String getDbUrl(String host, int port) { + return this.urlPattern.replace("{{host}}", host).replace("{{port}}", String.valueOf(port)).replace("{{dbName}}", + this.databaseName); } /** * 没有数据库时自动创建 */ @SuppressWarnings("all") - private void createDatabase() { + private void createDatabase(String host, int port, String username, String pin) { SimpleDataSource dataSource = null; try { - String url = this.urlPattern.replace("{{host}}", this.databaseHost) - .replace("{{port}}", String.valueOf(this.databasePort)).replace("/{{dbName}}", ""); - dataSource = new SimpleDataSource(url, this.databaseUser, this.databasePin, this.driver); + String url = this.urlPattern.replace("{{host}}", host) + .replace("{{port}}", String.valueOf(port)).replace("/{{dbName}}", ""); + dataSource = new SimpleDataSource(url, username, pin, this.driver); Db db = Tool.DbUtil.use(dataSource); List<String> dbNames = db.query("show databases;", String.class); if(dbNames != null) { @@ -170,4 +220,105 @@ public class DataSourceConfig { Tool.DbUtil.close(dataSource); } } + + class MasterFirstDataSourceSelector implements DataSourceSelector { + public static final String MASTER_KEY = "master"; + public static final String SLAVE_KEY = "slave"; + private HighAvailableDataSource highAvailableDataSource; + private volatile boolean inited = false; + private volatile Map<String, Long> lastSuccessTimes = new ConcurrentHashMap<String, Long>(); + + public MasterFirstDataSourceSelector(HighAvailableDataSource highAvailableDataSource) { + this.highAvailableDataSource = highAvailableDataSource; + } + + @Override + public DataSource get() { + init(); + Map<String, DataSource> dataSourceMap = highAvailableDataSource.getAvailableDataSourceMap(); + if (dataSourceMap == null || dataSourceMap.isEmpty()) { + return null; + } + if (dataSourceMap.size() == 1) { + for (DataSource v : dataSourceMap.values()) { + return v; + } + } + return dataSourceMap.get(MASTER_KEY); + } + + @Override + public void setTarget(String name) { + } + + @Override + public void init() { + if (inited) { + return; + } + // 设置初始值 + highAvailableDataSource.getDataSourceMap().forEach((key, v) -> { + lastSuccessTimes.put(key, Tool.DateUtil.current()); + }); + ScheduledThreadPoolExecutor executor = Tool.ThreadUtil.createScheduledExecutor(1); + executor.scheduleWithFixedDelay(new Runnable() { + @SuppressWarnings("static-access") + @Override + public void run() { + Thread.currentThread().setName("HA datasource check"); + try { + // 1、获取所有datasource + Map<String, DataSource> dataSourceMap = highAvailableDataSource.getDataSourceMap(); + if (Tool.MapUtil.isEmpty(dataSourceMap)) { + log.warn("no one datasource"); + } + // 2、遍历datasource检查是否可用 + dataSourceMap.forEach((key, ds) -> { + if (!(ds instanceof DruidDataSource)) { + return; + } + DruidDataSource dds = (DruidDataSource) ds; + Connection conn = null; + try { + conn = dds.getConnection(1000); + dds.validateConnection(conn); + lastSuccessTimes.put(key, Tool.DateUtil.current()); + } catch (Exception e) { + log.warn("datasource error, key: {}, url: {}", key, dds.getUrl()); + } finally { + Tool.DbUtil.close(conn); + } + }); + // 3、将不可用datasource 放入黑名单 + lastSuccessTimes.forEach((key, t) -> { + if ((Tool.DateUtil.current() - t) / haCheckingIntervalSeconds + / 1000 > haBlacklistThreshold) { + // 超过阈值 放入黑名单 + highAvailableDataSource.addBlackList(key); + log.info("{} datasource last success time {},add to blacklist", key, t); + } else { + // 未超过阈值,从黑名单取出 + highAvailableDataSource.removeBlackList(key); + log.info("{} datasource last success time {}", key, t); + } + }); + } catch (Exception e) { + log.warn(e); + } + } + }, haCheckingDelaySeconds, haCheckingIntervalSeconds, TimeUnit.SECONDS); // 延迟5分钟启动 + inited = true; + } + + @Override + public String getName() { + return "master-first"; + } + + @Override + public void destroy() { + } + + } + }
\ No newline at end of file diff --git a/nz-admin/src/main/java/com/nis/common/config/FlywayConfig.java b/nz-admin/src/main/java/com/nis/common/config/FlywayConfig.java index bd1abad9..35e5ea05 100644 --- a/nz-admin/src/main/java/com/nis/common/config/FlywayConfig.java +++ b/nz-admin/src/main/java/com/nis/common/config/FlywayConfig.java @@ -31,7 +31,7 @@ import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @Configuration -@DependsOn(value = {"dataSourceConfig", "redisConfig"}) +@DependsOn(value = {"dataSourceConfig"}) public class FlywayConfig implements ApplicationContextAware { private static final Log log = Log.get(); diff --git a/nz-admin/src/main/java/com/nis/common/config/RedisConfig.java b/nz-admin/src/main/java/com/nis/common/config/RedisConfig.java deleted file mode 100644 index ea78bfe5..00000000 --- a/nz-admin/src/main/java/com/nis/common/config/RedisConfig.java +++ /dev/null @@ -1,163 +0,0 @@ -package com.nis.common.config; - -import cn.hutool.log.Log; -import com.nis.common.utils.Tool; -import lombok.Data; -import org.apache.commons.pool2.impl.GenericObjectPoolConfig; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.dao.DataAccessException; -import org.springframework.data.redis.connection.*; -import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; -import org.springframework.data.redis.connection.lettuce.LettucePoolingClientConfiguration; -import org.springframework.data.redis.core.RedisCallback; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.data.redis.core.StringRedisTemplate; -import org.springframework.data.redis.serializer.StringRedisSerializer; - -import java.net.UnknownHostException; -import java.time.Duration; -import java.util.List; - -/** - * redis 初始化配置 - * - * @author fang - * - */ -@Configuration -@Data -public class RedisConfig { - - private static final Log log = Log.get(); - - @Value("${redis.mode:standalone}") - private String redisMode; - - @Value("${redis.host}") - private String redisHost; - @Value("${redis.port:6379}") - private int redisPort; - @Value("${redis.database:0}") - private int redisDatabase; - @Value("${redis.pin}") - private String redisPin; - @Value("${nezha.inited:0}") - private int inited; - // redis sentinel配置项 - @Value("${redis.sentinel.master:}") - private String sentinelMaster; - @Value("${redis.sentinel.nodes:}") - private String sentinelNodes; - /** - * redis配置项 - */ - @Value("${spring.redis.jedis.pool.max-idle:10}") - private int maxIdle; - @Value("${spring.redis.jedis.pool.min-idle:3}") - private int minIdle; - @Value("${spring.redis.jedis.pool.max-wait:100000}") - private int maxWait; - @Value("${spring.redis.jedis.pool.max-active:100}") - private int maxActive; - @Value("${spring.redis.timeout:100000}") - private long redisTimeout; - - @Bean(name = "redisConnectionFactory") - public RedisConnectionFactory redisConnectionFactory() { - - GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig(); - poolConfig.setMinIdle(this.getMinIdle()); - poolConfig.setMaxIdle(this.getMaxIdle()); - poolConfig.setMaxTotal(this.getMaxActive()); - poolConfig.setMaxWaitMillis(this.getMaxWait()); - - LettucePoolingClientConfiguration lettucePoolingClientConfiguration = LettucePoolingClientConfiguration - .builder().commandTimeout(Duration.ofMillis(this.getRedisTimeout())).shutdownTimeout(Duration.ZERO) - .poolConfig(poolConfig).build(); - - RedisStandaloneConfiguration redisStandaloneConfiguration = null; - RedisSentinelConfiguration redisSentinelConfiguration = null; - RedisConnectionFactory factory; - - if (Tool.StrUtil.equalsIgnoreCase(redisMode, "standalone")) { - log.info("standalone redis config: {}:{}/{}", this.getRedisHost(), this.getRedisPort(),this.getRedisDatabase()); - if (!Tool.ObjectUtil.isAllNotEmpty(this.getRedisHost(), this.getRedisPort(), this.getRedisDatabase())) { - log.error("redis config error"); - return null; - } - redisStandaloneConfiguration = new RedisStandaloneConfiguration(); - redisStandaloneConfiguration.setDatabase(this.getRedisDatabase()); - redisStandaloneConfiguration.setHostName(this.getRedisHost()); - redisStandaloneConfiguration.setPort(this.getRedisPort()); - if (Tool.StrUtil.isNotBlank(this.getRedisPin())){ - redisStandaloneConfiguration.setPassword(this.getRedisPin()); - } - factory = new LettuceConnectionFactory(redisStandaloneConfiguration, lettucePoolingClientConfiguration); - } else if (Tool.StrUtil.equalsIgnoreCase(redisMode, "sentinel")) { - log.info("sentinel redis config: {}, {}, {}", sentinelMaster, sentinelNodes, this.getRedisDatabase()); - if (!Tool.ObjectUtil.isAllNotEmpty(this.getSentinelMaster(), this.getSentinelNodes(),this.getRedisDatabase())) { - log.error("redis config error"); - return null; - } - redisSentinelConfiguration = new RedisSentinelConfiguration(); - redisSentinelConfiguration.master(sentinelMaster); - List<RedisNode> nodeList = Tool.ListUtil.list(false); - String[] nodeArr = sentinelNodes.split(","); - for (String node : nodeArr) { - nodeList.add(new RedisNode(node.split(":")[0], Tool.NumberUtil.parseInt(node.split(":")[1]))); - } - redisSentinelConfiguration.setSentinels(nodeList); - redisSentinelConfiguration.setDatabase(redisDatabase); - if (Tool.StrUtil.isNotBlank(redisPin)) { - redisSentinelConfiguration.setPassword(redisPin); - } - factory = new LettuceConnectionFactory(redisSentinelConfiguration, lettucePoolingClientConfiguration); - } else { - log.error("redis config error, unknow redis mode: {}", redisMode); - return null; - } - - return factory; - } - - @Bean(name = "redisTemplate") - public RedisTemplate<?, ?> redisTemplate(RedisConnectionFactory redisConnectionFactory) - throws UnknownHostException { - RedisTemplate<?, ?> template = new RedisTemplate<>(); - - template.setKeySerializer(new StringRedisSerializer()); - template.setHashKeySerializer(new StringRedisSerializer()); - template.setHashValueSerializer(new StringRedisSerializer()); - template.setValueSerializer(new StringRedisSerializer()); - template.setConnectionFactory(redisConnectionFactory); - template.afterPropertiesSet(); - template.execute(new RedisCallback<Object>() { - - @Override - public Object doInRedis(RedisConnection connection) throws DataAccessException { - String ping = connection.ping(); - if (Tool.StrUtil.isBlank(ping)) { - log.error("redis connetion error"); - } - return null; - } - }); - return template; - } - - @Bean(name = "stringRedisTemplate") - public StringRedisTemplate stringRedisTemplate(RedisConnectionFactory redisConnectionFactory) - throws UnknownHostException { - StringRedisTemplate template = new StringRedisTemplate(); - template.setKeySerializer(new StringRedisSerializer()); - template.setHashKeySerializer(new StringRedisSerializer()); - template.setHashValueSerializer(new StringRedisSerializer()); - template.setValueSerializer(new StringRedisSerializer()); - template.setConnectionFactory(redisConnectionFactory); - template.afterPropertiesSet(); - return template; - } - -} diff --git a/nz-admin/src/main/java/com/nis/common/config/SetupRunner.java b/nz-admin/src/main/java/com/nis/common/config/SetupRunner.java index 5ca75c2f..d3441356 100644 --- a/nz-admin/src/main/java/com/nis/common/config/SetupRunner.java +++ b/nz-admin/src/main/java/com/nis/common/config/SetupRunner.java @@ -22,6 +22,7 @@ import com.nis.modules.sys.service.SysUserService; import com.nis.modules.sys.shiro.ShiroUtils; import com.nis.modules.vsys.backend.VsysTaskConfigThread; import com.nis.setup.entity.SetupEntity; +import com.nis.setup.entity.SystemEntity; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.CommandLineRunner; @@ -145,17 +146,30 @@ public class SetupRunner implements CommandLineRunner{ if(file.exists()) { log.info("start inited setup"); String jsonStr = Tool.FileUtil.readUtf8String(file); - SetupEntity setupEntity = Tool.JSONUtil.toBean(jsonStr, SetupEntity.class); - sysConfService.updateValueByKey("alert_api",setupEntity.getSystem().getAlertPath()==null ? "":setupEntity.getSystem().getAlertPath()); - sysConfService.updateValueByKey("prometheus_federation_enabled",setupEntity.getSystem().getFederationEnabled()); - log.info("update db config"); - SysUserEntity sysUser = sysUserService.getById(adminId); - sysUser.setId(Long.parseLong(adminId)); - sysUser.setUsername(setupEntity.getSystem().getUsername()); - sysUser.setPin(ShiroUtils.sha256(setupEntity.getSystem().getPin(), sysUser.getSalt())); - log.info("update admin user"); - sysUserService.updateById(sysUser); - Tool.FileUtil.del(file);//删除临时配置文件 + SetupEntity setupEntity = Tool.JSONUtil.toBean(jsonStr, SetupEntity.class); + // adminUser + SysUserEntity adminUser = setupEntity.getAdminUser(); + SysUserEntity sysUser = sysUserService.getById(adminId); + sysUser.setId(Long.parseLong(adminId)); + sysUser.setUsername(adminUser.getUsername()); + sysUser.setPin(ShiroUtils.sha256(adminUser.getPin(), sysUser.getSalt())); + sysUserService.updateById(sysUser); + log.info("update admin user"); + + // system + SystemEntity system = setupEntity.getSystem(); + Map<String, String> updateSysConfMap = Tool.MapUtil.newHashMap(); + updateSysConfMap.put("timezone", system.getTimezone()); + updateSysConfMap.put("language", system.getLanguage()); + updateSysConfMap.put("prometheus_federation_enabled", system.getFederationEnabled()); + updateSysConfMap.put("asset_ping_from", system.getAsset_ping_from()); + updateSysConfMap.put("asset_ping_interval", system.getAsset_ping_interval()); + updateSysConfMap.put("default_scrape_interval", system.getDefault_scrape_interval()); + updateSysConfMap.put("default_scrape_timeout", system.getDefault_scrape_timeout()); + updateSysConfMap.put("snmp_trap_listen_port", system.getSnmp_trap_listen_port()); + sysConfService.saveOrUpdateConfsBatch(updateSysConfMap); + log.info("update db config"); + Tool.FileUtil.del(file);//删除临时配置文件 } //配置文件 boolean absolutePath = Tool.FileUtil.isAbsolutePath(nezhaConfigPath); diff --git a/nz-admin/src/main/java/com/nis/common/config/ShiroConfig.java b/nz-admin/src/main/java/com/nis/common/config/ShiroConfig.java index 9ee00994..e93720a7 100644 --- a/nz-admin/src/main/java/com/nis/common/config/ShiroConfig.java +++ b/nz-admin/src/main/java/com/nis/common/config/ShiroConfig.java @@ -47,7 +47,7 @@ import java.util.Map; * */ @Configuration -@DependsOn(value = { "mybatisPlusConfig", "redisConfig" }) +@DependsOn(value = {"mybatisPlusConfig"}) public class ShiroConfig { @Autowired diff --git a/nz-admin/src/main/java/com/nis/common/interceptor/TokenCheckFilter.java b/nz-admin/src/main/java/com/nis/common/interceptor/TokenCheckFilter.java index 9b1596c9..64feebe7 100644 --- a/nz-admin/src/main/java/com/nis/common/interceptor/TokenCheckFilter.java +++ b/nz-admin/src/main/java/com/nis/common/interceptor/TokenCheckFilter.java @@ -74,7 +74,7 @@ public class TokenCheckFilter extends AccessControlFilter { // 查询sys_api_key是否有该token记录 SysApiKey apiKey = sysApiKeyDao.selectOne(new QueryWrapper<SysApiKey>().lambda().eq(SysApiKey::getToken, token).and( wrapper -> wrapper.ge(SysApiKey::getExpireAt, time).or().isNull(SysApiKey::getExpireAt))); - // 如果有的话则认证通过 同时将该值存放到redis里 + // 如果有的话则认证通过 同时将该值存放到session里 if (ToolUtil.isEmpty(apiKey)) { // 如果没有则 返回响应值 return false; diff --git a/nz-admin/src/main/java/com/nis/common/job/HaJob.java b/nz-admin/src/main/java/com/nis/common/job/HaJob.java deleted file mode 100644 index 67ea22ff..00000000 --- a/nz-admin/src/main/java/com/nis/common/job/HaJob.java +++ /dev/null @@ -1,43 +0,0 @@ -/* -package com.nis.common.job; - -import cn.hutool.core.util.StrUtil; -import cn.hutool.log.Log; -import com.nis.common.utils.Constant; -import org.quartz.DisallowConcurrentExecution; -import org.quartz.JobExecutionContext; -import org.quartz.JobExecutionException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.scheduling.quartz.QuartzJobBean; - -import java.util.concurrent.TimeUnit; - -@DisallowConcurrentExecution -public class HaJob extends QuartzJobBean { - - private Log log = Log.get(); - - @Autowired - private RedisTemplate redisTemplate; - - @SuppressWarnings("unchecked") - @Override - protected void executeInternal(JobExecutionContext arg0) throws JobExecutionException { - Thread.currentThread().setName("HaJob"); - String serverId = (String) redisTemplate.opsForValue().get(Constant.SYS_HA_LOCK); - if(StrUtil.isBlank(serverId)) { - Boolean lock = redisTemplate.opsForValue().setIfAbsent(Constant.SYS_HA_LOCK, Constant.SERVER_ID,10, TimeUnit.SECONDS); - if(lock) { - log.debug("HA job set lock"); - } - }else if(StrUtil.equals(serverId, Constant.SERVER_ID)){ - redisTemplate.expire(Constant.SYS_HA_LOCK, 10, TimeUnit.SECONDS); - log.debug("HA job get lock , Timeout update"); - }else { - log.debug("HA job can not get lock , job in another program"); - } - } - -} -*/ diff --git a/nz-admin/src/main/java/com/nis/common/utils/Constant.java b/nz-admin/src/main/java/com/nis/common/utils/Constant.java index bc2e5db8..df30ce2b 100644 --- a/nz-admin/src/main/java/com/nis/common/utils/Constant.java +++ b/nz-admin/src/main/java/com/nis/common/utils/Constant.java @@ -97,10 +97,10 @@ public class Constant { public static final List<Integer> ALERTMESSAGE_STATE; /** - * agent 配置下发 cortex/loke redis 下发标识 + * agent 配置下发中 cortex/loke 组件更新标识 */ - public static final String REDIS_KEY_CORTEX_UPDATE = "cortex_update"; - public static final String REDIS_KEY_LOKI_UPDATE = "loki_update"; + public static final String CACHE_KEY_CORTEX_UPDATE = "cortex_update"; + public static final String CACHE_KEY_LOKI_UPDATE = "loki_update"; /** * prometheus query range 代理接口 限制查询最大条数 @@ -1144,10 +1144,13 @@ public class Constant { public static final String ENDPOINT_LOGS_STATE_CACHE_KEY = "endpoint_logs_state"; - public static final String ASSET_TALON_STATUS_CACHE_KEY = "asset_talon_status"; + public static final String ASSET_TALON_STATE_CACHE_KEY = "asset_talon_state"; public static final String AGENT_STATE_CACHE_KEY = "agent_state"; + // cortex_update & loki_update + public static final String AGENT_COMPONENT_UPDATE_STATE_CACHE_KEY = "agent_component_update_state"; + public static final String SYSCONFIG_KEY_IPAMSUBNET_IMPORT_HEADER="ipam_subnet_import_header"; public static final String SYSCONFIG_KEY_IPAMIP_IMPORT_HEADER="ipam_ip_import_header"; diff --git a/nz-admin/src/main/java/com/nis/common/utils/RedisLock.java b/nz-admin/src/main/java/com/nis/common/utils/RedisLock.java deleted file mode 100644 index 814abb04..00000000 --- a/nz-admin/src/main/java/com/nis/common/utils/RedisLock.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.nis.common.utils; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.data.redis.core.StringRedisTemplate; -import org.springframework.data.redis.core.script.DefaultRedisScript; -import org.springframework.stereotype.Component; - -import java.util.Arrays; -import java.util.concurrent.TimeUnit; - -/** - * redis 分布式锁 - */ -@Component -public class RedisLock { - - @Autowired - private StringRedisTemplate stringRedisTemplate; - - @Autowired - private DefaultRedisScript<Long> redisScript; - - private final Long RELEASE_SUCCESS = 1L; - - - /** - * 加锁 - * - * @param key - * @return - */ - public boolean lock(String key, String value, Long timeout) { - // 加锁并设置过期时间 - return stringRedisTemplate.opsForValue().setIfAbsent(key, value, timeout, TimeUnit.SECONDS); - } - - /** - * 释放锁 - * - * @param key - * @return - */ - public boolean unlock(String key, String value) { - // 使用 lua 脚本:先判断是否是自己设置的锁,再执行删除 - Long result = (Long) stringRedisTemplate.execute(redisScript, Arrays.asList(key, value)); - return RELEASE_SUCCESS.equals(result); - } - - - /** - * 注入redis script 在上面释放锁的时候使用 - * - * @return - */ - @Bean - public DefaultRedisScript<Long> defaultRedisScript() { - DefaultRedisScript<Long> defaultRedisScript = new DefaultRedisScript<>(); - defaultRedisScript.setResultType(Long.class); - // 使用脚本的方式执行 两步合成一步 保证了操作原子性 - defaultRedisScript.setScriptText("if redis.call('get', KEYS[1]) == KEYS[2] then return redis.call('del', KEYS[1]) else return 0 end"); - return defaultRedisScript; - } - - -} diff --git a/nz-admin/src/main/java/com/nis/common/utils/RedisUtils.java b/nz-admin/src/main/java/com/nis/common/utils/RedisUtils.java deleted file mode 100644 index 406f424d..00000000 --- a/nz-admin/src/main/java/com/nis/common/utils/RedisUtils.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.nis.common.utils; - -import com.alibaba.fastjson.JSON; -import jakarta.annotation.Resource; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.data.redis.core.ValueOperations; -import org.springframework.stereotype.Component; - -import java.util.concurrent.TimeUnit; - -@Component -public class RedisUtils { - @Autowired - private RedisTemplate redisTemplate; - @Resource(name="redisTemplate") - private ValueOperations<String, String> valueOperations; - /** 默认过期时长,单位:秒 */ - public final static long DEFAULT_EXPIRE = 60 * 60 * 24; - /** 不设置过期时长 */ - public final static long NOT_EXPIRE = -1; - - public void set(String key, Object value, long expire){ - valueOperations.set(key, toJson(value)); - if(expire != NOT_EXPIRE){ - redisTemplate.expire(key, expire, TimeUnit.SECONDS); - } - } - - public void set(String key, Object value){ - set(key, value, DEFAULT_EXPIRE); - } - - public <T> T get(String key, Class<T> clazz, long expire) { - String value = valueOperations.get(key); - if(expire != NOT_EXPIRE){ - redisTemplate.expire(key, expire, TimeUnit.SECONDS); - } - return value == null ? null : fromJson(value, clazz); - } - - public <T> T get(String key, Class<T> clazz) { - return get(key, clazz, NOT_EXPIRE); - } - - public String get(String key, long expire) { - String value = valueOperations.get(key); - if(expire != NOT_EXPIRE){ - redisTemplate.expire(key, expire, TimeUnit.SECONDS); - } - return value; - } - - public String get(String key) { - return get(key, NOT_EXPIRE); - } - - public void delete(String key) { - redisTemplate.delete(key); - } - - /** - * Object转成JSON数据 - */ - private String toJson(Object object){ - if(object instanceof Integer || object instanceof Long || object instanceof Float || - object instanceof Double || object instanceof Boolean || object instanceof String){ - return String.valueOf(object); - } - return JSON.toJSONString(object); - } - - /** - * JSON数据,转成Object - */ - private <T> T fromJson(String json, Class<T> clazz){ - return JSON.parseObject(json, clazz); - } -} diff --git a/nz-admin/src/main/java/com/nis/modules/agent/job/AgentConfigUtil.java b/nz-admin/src/main/java/com/nis/modules/agent/job/AgentConfigUtil.java index 3563dd0b..2772cb9f 100644 --- a/nz-admin/src/main/java/com/nis/modules/agent/job/AgentConfigUtil.java +++ b/nz-admin/src/main/java/com/nis/modules/agent/job/AgentConfigUtil.java @@ -121,66 +121,6 @@ public class AgentConfigUtil { } /** - * 生成 rule.yml - * - * @return - */ -// public Map generateRuleYml() { -// log.debug("rule.yml 开始生成"); -// // sys_config 配置表信息 -// List<SysConfigEntity> configEntityList = sysConfService.list(); -// Map<String, String> configMap = configEntityList.stream() -// .collect(Collectors.toMap(SysConfigEntity::getParamKey, SysConfigEntity::getParamValue)); -// -// List<AlertRuleEntity> alertRuleEntities = ruleService.list(new LambdaQueryWrapper<AlertRuleEntity>() -// .ne(AlertRuleEntity::getBuildIn, 1).eq(AlertRuleEntity::getState, 1)); -// List<AlertSeverityConf> severityConfs = alertSeverityService.list(); -// Map<Integer, String> alertSeverityIdAndNameMap = severityConfs.stream() -// .collect(Collectors.toMap(AlertSeverityConf::getId, AlertSeverityConf::getName)); -// -// List<Map> ruleList = new ArrayList<>(); -// for (AlertRuleEntity entity : alertRuleEntities) { -// Map map = new LinkedHashMap(16); -// map.put("id", entity.getId()); -// map.put("expr", ToolUtil.string2Json(entity.getExpr())); -// map.put("operator", entity.getOperator()); -// // 以字符串方式替换 double 类型,保证不丢失精度 -// map.put("threshold", entity.getThreshold() + ""); -// map.put("last", entity.getLast()); -// -// String severityName = alertSeverityIdAndNameMap.get(entity.getSeverityId()); -// map.put("severity_name", ToolUtil.string2Json(severityName)); -// map.put("severity_id", entity.getSeverityId()); -// map.put("summary", ToolUtil.string2Json(entity.getSummary())); -// map.put("description", ToolUtil.string2Json(entity.getDescription())); -// ruleList.add(map); -// } -// -// Map params = new LinkedHashMap(4); -// // alert 方式实现 endpoint state -- 该方案不再使用,兼容未删除 -// String endpointAlertPush = configMap.get(Constant.ENDPOINT_ALERT_PUSH); -// if (StrUtil.equals(endpointAlertPush, "1")) { -// params.put("endpointAlert", true); -// } else { -// params.put("endpointAlert", false); -// } -// params.put("ruleList", ruleList); -// -// Map map = new HashMap(); -// String content = ""; -// try { -// Template template = TemplateUtil.stringToTemplate(configMap.get(Constant.SYSCONFIG_KEY_PROM_RULE_TMPL), -// Constant.SYSCONFIG_KEY_PROM_RULE_TMPL); -// content = FreeMarkerTemplateUtils.processTemplateIntoString(template, params); -// map = JSONObject.parseObject(content, LinkedHashMap.class, Feature.OrderedField); -// } catch (IOException | TemplateException | RuntimeException e) { -// log.error("rule 模板生成失败,模板内容:" + JSONObject.toJSONString(content), e); -// } -// log.debug("rule.yml 生成结束"); -// return map; -// } - - /** * 生成 cortex.yml * * @param agent @@ -289,36 +229,6 @@ public class AgentConfigUtil { } /** - * 获取当前支持 alert 的 agent id , 如果获取失败 则获取 global 第一个 agent - * - * @param healthyAgents - * @return - */ - /*public Integer getSupportAlertPromId(List<Agent> healthyAgents) { - Object supportAlertPromId = redisTemplate.opsForValue().get(Constant.REDIS_KEY_SUPPORT_ALERT_AGENT_ID); - supportAlertPromId = ToolUtil.isEmpty(supportAlertPromId) ? "" : supportAlertPromId; - - // 当前支持 alert 的 agent , 判断是否存在,不存在则重新 找一个 agent 下发配置 - if (StrUtil.isNotEmpty(supportAlertPromId.toString())) { - Agent agentById = agentService.getById(supportAlertPromId.toString()); - if (agentById == null || agentById.getStatus() != 1) { - supportAlertPromId = ""; - } - } - - // 第一个 健康的 gloabl cortex 支持 alert - if (StrUtil.isEmpty(supportAlertPromId.toString())) { - Agent supportAlertAgent = healthyAgents.stream() - .filter(agent -> Constant.AgentType.GLOBAL.getValue().equals(agent.getType())) - .sorted(Comparator.comparing(Agent::getId)).findFirst().orElse(null); - supportAlertPromId = supportAlertAgent.getId(); - redisTemplate.opsForValue().set(Constant.REDIS_KEY_SUPPORT_ALERT_AGENT_ID, - supportAlertPromId.toString()); - } - return Integer.valueOf(supportAlertPromId.toString()); - }*/ - - /** * 组装 snmp.yml * * @return diff --git a/nz-admin/src/main/java/com/nis/modules/agent/job/AgentHealthCheckJob.java b/nz-admin/src/main/java/com/nis/modules/agent/job/AgentHealthCheckJob.java index 29986224..12d2a0ca 100644 --- a/nz-admin/src/main/java/com/nis/modules/agent/job/AgentHealthCheckJob.java +++ b/nz-admin/src/main/java/com/nis/modules/agent/job/AgentHealthCheckJob.java @@ -18,7 +18,6 @@ import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.data.redis.core.RedisTemplate; import org.springframework.scheduling.quartz.QuartzJobBean; import java.util.*; @@ -33,8 +32,6 @@ public class AgentHealthCheckJob extends QuartzJobBean { private AgentService agentService; @Autowired private SysConfService sysConfService; - @Autowired - private RedisTemplate redisTemplate; private static ExecutorService exec = Executors.newCachedThreadPool(); // 计数器,每 forceSync 个周期 执行一次强制执行 @@ -120,17 +117,16 @@ public class AgentHealthCheckJob extends QuartzJobBean { // 认证失败 agent.setStatus(-1); } else { + TimedCache<String, Object> cache = LocalCacheManager.getTimedCache(Constant.SYS_STATE_CACHE_PREFIX, Constant.AGENT_COMPONENT_UPDATE_STATE_CACHE_KEY); // 状态不为 down ,继续判断 可用状态 if (unavailable.equals(cortexState)) { - Boolean cortexUpdateExist = redisTemplate - .hasKey(Constant.REDIS_KEY_CORTEX_UPDATE); + Boolean cortexUpdateExist = cache.containsKey(Constant.CACHE_KEY_CORTEX_UPDATE); // 返回为 UNAVAILABLE 但不存在更新标识,认为其不可用 if (!cortexUpdateExist) agent.setStatus(0); } if (unavailable.equals(lokiState)) { - Boolean lokiUpdateExist = redisTemplate - .hasKey(Constant.REDIS_KEY_LOKI_UPDATE); + Boolean lokiUpdateExist = cache.containsKey(Constant.CACHE_KEY_LOKI_UPDATE); // 返回为 UNAVAILABLE 但不存在更新标识,认为其不可用 if (!lokiUpdateExist) agent.setStatus(0); diff --git a/nz-admin/src/main/java/com/nis/modules/agent/job/AutoConfigAgentJob.java b/nz-admin/src/main/java/com/nis/modules/agent/job/AutoConfigAgentJob.java index c1845d88..d3e501d2 100644 --- a/nz-admin/src/main/java/com/nis/modules/agent/job/AutoConfigAgentJob.java +++ b/nz-admin/src/main/java/com/nis/modules/agent/job/AutoConfigAgentJob.java @@ -26,7 +26,6 @@ import org.quartz.DisallowConcurrentExecution; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.core.RedisTemplate; import org.springframework.http.HttpMethod; import org.springframework.scheduling.quartz.QuartzJobBean; @@ -48,9 +47,6 @@ public class AutoConfigAgentJob extends QuartzJobBean { private static final Log log = Log.get(); @Autowired - private RedisTemplate redisTemplate; - - @Autowired private AgentConfigUtil configUtil; @Autowired @@ -92,7 +88,7 @@ public class AutoConfigAgentJob extends QuartzJobBean { healthyAgents.add(agentInCache); } } - log.info("[AutoConfigAgentJob] [Get healthy agent list from redis] [size: {}]", healthyAgents.size()); + log.info("[AutoConfigAgentJob] [Get healthy agent list from cache] [size: {}]", healthyAgents.size()); } else { healthyAgents = agentService.list(new LambdaQueryWrapper<Agent>().eq(Agent::getStatus, 1)); log.info("[AutoConfigAgentJob] [Get healthy agent list from db] [size: {}]", healthyAgents.size()); @@ -210,20 +206,6 @@ public class AutoConfigAgentJob extends QuartzJobBean { ThreadUtil.execAsync(() -> { boolean cortexChangeFlag = configUtil.compareDataChanges("cortex"); log.info("[setUpAgentConfig] [conf_event cortex state] [change: {}]", cortexChangeFlag); - -// boolean ruleChangeFlag = configUtil.compareDataChanges("rule"); -// log.info("[setUpAgentConfig] [conf_event rule state] [change: {}]", ruleChangeFlag); - - // 是否更新 rule.yml 配置 -// String alertConfUpdate = sysConfService.getValue("nz_alert_rule_eval_enable"); -// Map alertYmlMap = configUtil.generateRuleYml(); -// if (ruleChangeFlag && StrUtil.equals("0", StrUtil.emptyToDefault(alertConfUpdate, "1"))) { -// // 生成 alert.yml -// // 如果 cortex 没有变更 就只更新 rule -// if (!cortexChangeFlag) { -// this.justUpdateRuleConf(alertYmlMap, healthyPromServers); -// } -// } if (cortexChangeFlag) { this.updateCortexConf(healthyPromServers); } @@ -655,9 +637,11 @@ public class AutoConfigAgentJob extends QuartzJobBean { } } - // 配置下发后向 redis 记录配置更新 默认五分钟 单位 s - String cortexUpdateTimeout = Tool.ObjectUtil.defaultIfNull(sysConfService.getValue(Constant.SYSCONFIG_KEY_LOKI_UPDATE_TIMEOUT), "300"); - redisTemplate.opsForValue().set(Constant.REDIS_KEY_LOKI_UPDATE, "1", Integer.valueOf(cortexUpdateTimeout), TimeUnit.SECONDS); + // 配置下发后向 local cahce 记录配置更新 默认五分钟 单位 s + String lokiUpdateTimeout = Tool.ObjectUtil.defaultIfNull(sysConfService.getValue(Constant.SYSCONFIG_KEY_LOKI_UPDATE_TIMEOUT), "300"); + + TimedCache<String, Object> cache = LocalCacheManager.getTimedCache(Constant.SYS_STATE_CACHE_PREFIX, Constant.AGENT_COMPONENT_UPDATE_STATE_CACHE_KEY); + cache.put(Constant.CACHE_KEY_LOKI_UPDATE, "1", TimeUnit.SECONDS.toMillis(Integer.valueOf(lokiUpdateTimeout))); }); } @@ -688,45 +672,6 @@ public class AutoConfigAgentJob extends QuartzJobBean { } /** - * prometheus cortex 都没有变更 , 只更新 rule.yml - * - * @param alertYmlMap - * @param healthyPromServers - */ - /*private void justUpdateRuleConf(Map alertYmlMap, List<Agent> healthyPromServers) { - // 先判断 redis 中是否存在 alert 告警标识 - Boolean aBoolean = redisTemplate.hasKey(Constant.REDIS_KEY_SUPPORT_ALERT_AGENT_ID); - Integer supportAlertPromId = configUtil.getSupportAlertPromId(healthyPromServers); - Agent agent = agentService.getById(supportAlertPromId); - - - // 无论对象存储与否 全部由于 cortex 支持 rule - Map<String, Object> updateRuleConfigBody = new HashMap<>(2); - updateRuleConfigBody.put("rule", alertYmlMap); - // 告警标识不存在 则需要同时下发 cortex 配置 - if (!aBoolean) { - List<Agent> globalPromServerList = healthyPromServers.stream().filter(agentEntity -> Constant.AgentType.GLOBAL.getValue().equals(agentEntity.getType())).collect(Collectors.toList()); - Map cortexYml = configUtil.generateCortexYml(agent, globalPromServerList, true); - updateRuleConfigBody.put("config", cortexYml); - } - - String result = null; - String path = "/cortex/config"; - try { - result = AgentUtil.request(agent, HttpMethod.POST,path, null, updateRuleConfigBody, String.class); - } catch (RuntimeException e) { - log.error(e,"request error,path:{},agent:{}",path,Tool.JSONUtil.toJsonStr(agent)); - } - - log.debug("rule 更新请求返回结果 {}", result); - if (result == null) { - configUtil.updateAgentStatus(agent, 0); - } else { - configUtil.afterRequestApi(path, result, agent); - } - }*/ - - /** * cortex 配置下发 * * @param healthyAgents @@ -773,9 +718,11 @@ public class AutoConfigAgentJob extends QuartzJobBean { } } - // 配置下发后向 redis 记录配置更新 默认五分钟 单位 s + // 配置下发后向 local cahce 记录配置更新 默认五分钟 单位 s String cortexUpdateTimeout = Tool.ObjectUtil.defaultIfNull(sysConfService.getValue(Constant.SYSCONFIG_KEY_CORTEX_UPDATE_TIMEOUT), "300"); - redisTemplate.opsForValue().set(Constant.REDIS_KEY_CORTEX_UPDATE, "1", Integer.valueOf(cortexUpdateTimeout), TimeUnit.SECONDS); + + TimedCache<String, Object> cache = LocalCacheManager.getTimedCache(Constant.SYS_STATE_CACHE_PREFIX, Constant.AGENT_COMPONENT_UPDATE_STATE_CACHE_KEY); + cache.put(Constant.CACHE_KEY_CORTEX_UPDATE, "1", TimeUnit.SECONDS.toMillis(Integer.valueOf(cortexUpdateTimeout))); }); } diff --git a/nz-admin/src/main/java/com/nis/modules/alert/service/impl/AlertHandlerServiceImpl.java b/nz-admin/src/main/java/com/nis/modules/alert/service/impl/AlertHandlerServiceImpl.java index 1acd134a..261fcf07 100644 --- a/nz-admin/src/main/java/com/nis/modules/alert/service/impl/AlertHandlerServiceImpl.java +++ b/nz-admin/src/main/java/com/nis/modules/alert/service/impl/AlertHandlerServiceImpl.java @@ -82,7 +82,7 @@ public class AlertHandlerServiceImpl implements AlertHandlerService { @Autowired private FullTextSearchService fullTextSearchService; - @Value("${redis.maxQueueLength:100}") + @Value("${cache.maxQueueLength:100}") private Long maxQueueLength;// cache 队列长度 /** * alert message 超时时间 diff --git a/nz-admin/src/main/java/com/nis/modules/alert/service/impl/AlertMessageServiceImpl.java b/nz-admin/src/main/java/com/nis/modules/alert/service/impl/AlertMessageServiceImpl.java index a20d9b5c..0611f9a2 100644 --- a/nz-admin/src/main/java/com/nis/modules/alert/service/impl/AlertMessageServiceImpl.java +++ b/nz-admin/src/main/java/com/nis/modules/alert/service/impl/AlertMessageServiceImpl.java @@ -28,8 +28,8 @@ public class AlertMessageServiceImpl extends ServiceImpl<AlertMessageDao, AlertM private AlertMessageDao alertMessageDao; @Autowired private AlertHandlerDao msgHandlerDao; - @Value("${redis.maxAlertMessageSize:10000}") - private Integer maxQueueLength;//redis队列长度 + @Value("${cache.maxAlertMessageSize:10000}") + private Integer maxQueueLength;// 队列长度 @Override @Transactional(rollbackFor = Exception.class) diff --git a/nz-admin/src/main/java/com/nis/modules/alert/service/impl/RecordRuleServiceImpl.java b/nz-admin/src/main/java/com/nis/modules/alert/service/impl/RecordRuleServiceImpl.java index 63249b9a..9d3bd5e3 100644 --- a/nz-admin/src/main/java/com/nis/modules/alert/service/impl/RecordRuleServiceImpl.java +++ b/nz-admin/src/main/java/com/nis/modules/alert/service/impl/RecordRuleServiceImpl.java @@ -64,7 +64,7 @@ public class RecordRuleServiceImpl extends ServiceImpl<RecordRuleDao, RecordRule /** * record list max size */ - @Value("${redis.maxRecordDataSize:100000}") + @Value("${cache.maxRecordDataSize:100000}") private Long maxRecordSize; @Override diff --git a/nz-admin/src/main/java/com/nis/modules/asset/job/AssetTalonStatusJob.java b/nz-admin/src/main/java/com/nis/modules/asset/job/AssetTalonStatusJob.java index a368e0ff..7e86f59f 100644 --- a/nz-admin/src/main/java/com/nis/modules/asset/job/AssetTalonStatusJob.java +++ b/nz-admin/src/main/java/com/nis/modules/asset/job/AssetTalonStatusJob.java @@ -195,7 +195,7 @@ public class AssetTalonStatusJob extends QuartzJobBean { Map<Integer, AssetTalonStatus> map = talonUpdateStatusList.stream().collect(Collectors.toMap(AssetTalonStatus::getAssetId, Function.identity())); //判断查询数据与缓存中变化的信息 - TimedCache<String, Object> assetTalonStatusCache = LocalCacheManager.getTimedCache(Constant.SYS_STATE_CACHE_PREFIX, Constant.ASSET_TALON_STATUS_CACHE_KEY); + TimedCache<String, Object> assetTalonStatusCache = LocalCacheManager.getTimedCache(Constant.SYS_STATE_CACHE_PREFIX, Constant.ASSET_TALON_STATE_CACHE_KEY); if (BooleanUtil.negate(assetTalonStatusCache.isEmpty()) && counter % forceSync != 0) { for (int i = talonUpdateStatusList.size() - 1; i >= 0; i--) { AssetTalonStatus assetTalonStatus = talonUpdateStatusList.get(i); diff --git a/nz-admin/src/main/java/com/nis/modules/asset/service/impl/AssetAssetServiceImpl.java b/nz-admin/src/main/java/com/nis/modules/asset/service/impl/AssetAssetServiceImpl.java index 12cf5623..121f16ca 100644 --- a/nz-admin/src/main/java/com/nis/modules/asset/service/impl/AssetAssetServiceImpl.java +++ b/nz-admin/src/main/java/com/nis/modules/asset/service/impl/AssetAssetServiceImpl.java @@ -1029,7 +1029,7 @@ public class AssetAssetServiceImpl extends ServiceImpl<AssetAssetDao, AssetAsset LocalCacheManager.getTimedCache(Constant.SYS_STATE_CACHE_PREFIX, Constant.SYSCONFIG_KEY_ASSET_PING).remove(assetId.toString()); assetTalonStatusService.removeById(assetId); - LocalCacheManager.getTimedCache(Constant.SYS_STATE_CACHE_PREFIX, Constant.ASSET_TALON_STATUS_CACHE_KEY).remove(assetId.toString()); + LocalCacheManager.getTimedCache(Constant.SYS_STATE_CACHE_PREFIX, Constant.ASSET_TALON_STATE_CACHE_KEY).remove(assetId.toString()); } private void saveAssetRelData(AssetAsset asset) { @@ -1136,7 +1136,7 @@ public class AssetAssetServiceImpl extends ServiceImpl<AssetAssetDao, AssetAsset // asset Talon assetTalonStatusService.removeByIds(removeAssetIdList); - TimedCache<String, Object> assetTalonCache = LocalCacheManager.getTimedCache(Constant.SYS_STATE_CACHE_PREFIX, Constant.ASSET_TALON_STATUS_CACHE_KEY); + TimedCache<String, Object> assetTalonCache = LocalCacheManager.getTimedCache(Constant.SYS_STATE_CACHE_PREFIX, Constant.ASSET_TALON_STATE_CACHE_KEY); tempIdListForRemoveCache.parallelStream().forEach(key -> assetTalonCache.remove(key)); // field diff --git a/nz-admin/src/main/java/com/nis/modules/dashboard/controller/VisualController.java b/nz-admin/src/main/java/com/nis/modules/dashboard/controller/VisualController.java index b0708bf2..ff4afe04 100644 --- a/nz-admin/src/main/java/com/nis/modules/dashboard/controller/VisualController.java +++ b/nz-admin/src/main/java/com/nis/modules/dashboard/controller/VisualController.java @@ -10,6 +10,7 @@ import com.nis.common.smartvalidate.ValidateUtils; import com.nis.common.utils.*; import com.nis.modules.dashboard.service.VisualService; import com.nis.modules.dashboard.utils.DashboardConstant; +import com.nis.modules.election.dao.LeaderElectionDao; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; @@ -17,6 +18,7 @@ import org.springframework.web.bind.annotation.*; import java.io.IOException; import java.util.Map; +import java.util.concurrent.TimeUnit; @RestController @RequestMapping("/visual") @@ -27,9 +29,6 @@ public class VisualController { @Autowired private VisualService visualService; - @Autowired - private RedisLock redisLock; - /** * explore 快照 */ @@ -136,9 +135,12 @@ public class VisualController { return R.error(RCode.DASHBOARD_TEMPLATE_SYNC_PARAM_ISNULL); // get lock + LeaderElectionDao dao = LeaderElectionDao.getInstance(); + String uuid = Tool.StrUtil.uuid(); + dao.attemptLeadership(DashboardConstant.TEMPLATE_SYNC_LOCK_KEY, uuid, TimeUnit.SECONDS.toMillis(300)); try { - if (redisLock.lock(DashboardConstant.TEMPLATE_SYNC_LOCK_KEY, uuid, 300L)) { + if (dao.isLeader(DashboardConstant.TEMPLATE_SYNC_LOCK_KEY, uuid)) { log.info("[syncTemplateDashboard] [Get lock and start synchronization template]"); // sync Template On dashboard @@ -148,8 +150,11 @@ public class VisualController { log.warn("[syncTemplateDashboard] [Failed to get lock and do not perform template synchronization]"); return R.error(RCode.DASHBOARD_TEMPLATE_SYNC_FAILED_GET_LOCK); } + } catch (Exception e) { + log.error(e, "[syncTemplateDashboard] [error]"); + throw new NZException(RCode.ERROR); } finally { - redisLock.unlock(DashboardConstant.TEMPLATE_SYNC_LOCK_KEY, uuid); + dao.forceReElection(DashboardConstant.TEMPLATE_SYNC_LOCK_KEY, uuid); } } diff --git a/nz-admin/src/main/java/com/nis/modules/dashboard/service/VisualDashboardService.java b/nz-admin/src/main/java/com/nis/modules/dashboard/service/VisualDashboardService.java index 9cc379a3..845a1ff6 100644 --- a/nz-admin/src/main/java/com/nis/modules/dashboard/service/VisualDashboardService.java +++ b/nz-admin/src/main/java/com/nis/modules/dashboard/service/VisualDashboardService.java @@ -45,9 +45,9 @@ public interface VisualDashboardService extends IService<VisualDashboard> { VisualDashboard queryDashboardIncludeChartInfo(Integer dashboardId); - void addReportConfigInRedis(VisualDashboard dashboard); + void addReportConfigInCache(VisualDashboard dashboard); - void updateReportConfigInRedis(VisualDashboard oldDashboard, VisualDashboard newDashboard); + void updateReportConfigInCache(VisualDashboard oldDashboard, VisualDashboard newDashboard); // template dashboard , add assetInfo or endpointInfo chart void addLinkObjectInfoChart(VisualDashboard dashboard); diff --git a/nz-admin/src/main/java/com/nis/modules/dashboard/service/impl/VisualDashboardServiceImpl.java b/nz-admin/src/main/java/com/nis/modules/dashboard/service/impl/VisualDashboardServiceImpl.java index 35ceacdf..053d5f58 100644 --- a/nz-admin/src/main/java/com/nis/modules/dashboard/service/impl/VisualDashboardServiceImpl.java +++ b/nz-admin/src/main/java/com/nis/modules/dashboard/service/impl/VisualDashboardServiceImpl.java @@ -544,8 +544,8 @@ public class VisualDashboardServiceImpl extends ServiceImpl<VisualDashboardDao, // add assetInfo or endpointInfo chart this.addLinkObjectInfoChart(dashboard); - // add Report Config In Redis - this.addReportConfigInRedis(dashboard); + // add Report Config In Cache + this.addReportConfigInCache(dashboard); } /** @@ -583,15 +583,15 @@ public class VisualDashboardServiceImpl extends ServiceImpl<VisualDashboardDao, } /** - * add Report Config In Redis + * add Report Config In Cache * * @param dashboard */ @Override - public void addReportConfigInRedis(VisualDashboard dashboard) { + public void addReportConfigInCache(VisualDashboard dashboard) { String type = dashboard.getType(); if (StrUtil.equals(DashboardConstant.Type.TEMPLATE.getValue(), type)) { - log.warn("[addReportConfigInRedis] [template dashboard does not support report config] [dashboardId: {}] [type: {}]", dashboard.getId(), type); + log.warn("[addReportConfigInCache] [template dashboard does not support report config] [dashboardId: {}] [type: {}]", dashboard.getId(), type); return; } @@ -600,7 +600,7 @@ public class VisualDashboardServiceImpl extends ServiceImpl<VisualDashboardDao, reportEnable = JSONPath.read(dashboard.getParam().toString(), "report.enable").toString(); } - log.info("[addReportConfigInRedis] [publish config to redis] [enable: {}]", reportEnable); + log.info("[addReportConfigInCache] [publish config to nz-web component] [enable: {}]", reportEnable); // publish report config when reportEnable is true if (Tool.StrUtil.equalsIgnoreCase("true", StrUtil.nullToDefault(reportEnable, "false"))) { Map publishMap = new HashMap(4); @@ -643,21 +643,21 @@ public class VisualDashboardServiceImpl extends ServiceImpl<VisualDashboardDao, // 修改 this.updateById(dashboard); - // update Report Config In Redis - this.updateReportConfigInRedis(oldDashboard, dashboard); + // update Report Config In Cache + this.updateReportConfigInCache(oldDashboard, dashboard); } /** - * update Report Config In Redis + * update Report Config In Cache * * @param oldDashboard * @param newDashboard */ @Override - public void updateReportConfigInRedis(VisualDashboard oldDashboard, VisualDashboard newDashboard) { + public void updateReportConfigInCache(VisualDashboard oldDashboard, VisualDashboard newDashboard) { String type = newDashboard.getType(); if (StrUtil.equals(DashboardConstant.Type.TEMPLATE.getValue(), type)) { - log.warn("[updateReportConfigInRedis] [template dashboard does not support report config] [DashboardId: {}] [type: {}]", newDashboard.getId(), type); + log.warn("[updateReportConfigInCache] [template dashboard does not support report config] [DashboardId: {}] [type: {}]", newDashboard.getId(), type); return; } @@ -671,7 +671,7 @@ public class VisualDashboardServiceImpl extends ServiceImpl<VisualDashboardDao, boolean isUpdate = !oldParamMap.equals(newParamMap); - log.info("[updateReportConfigInRedis] [publish config to redis] [isUpdate: {}]", isUpdate); + log.info("[updateReportConfigInCache] [publish config to nz-web component] [isUpdate: {}]", isUpdate); if (isUpdate) { Map publishMap = new HashMap(4); publishMap.put("dashboardId", newDashboard.getId()); @@ -1564,15 +1564,15 @@ public class VisualDashboardServiceImpl extends ServiceImpl<VisualDashboardDao, dashboard.setWeight(oldDashboard.getWeight()); this.updateById(dashboard); - // update Report Config In Redis - this.updateReportConfigInRedis(oldDashboard, dashboard); + // update Report Config In Cache + this.updateReportConfigInCache(oldDashboard, dashboard); } else { params.put("save", true); // insert this.save(dashboard); - // add Report Config In Redis - this.addReportConfigInRedis(dashboard); + // add Report Config In Cache + this.addReportConfigInCache(dashboard); // add assetInfo or endpointInfo chart this.addLinkObjectInfoChart(dashboard); diff --git a/nz-admin/src/main/java/com/nis/modules/dashboard/service/impl/VisualServiceImpl.java b/nz-admin/src/main/java/com/nis/modules/dashboard/service/impl/VisualServiceImpl.java index c425d2d5..fb711188 100644 --- a/nz-admin/src/main/java/com/nis/modules/dashboard/service/impl/VisualServiceImpl.java +++ b/nz-admin/src/main/java/com/nis/modules/dashboard/service/impl/VisualServiceImpl.java @@ -1006,8 +1006,8 @@ public class VisualServiceImpl implements VisualService { updateDashboardObject.setUts(System.currentTimeMillis()); dashboardService.updateById(updateDashboardObject); - // update Report Config In Redis - dashboardService.updateReportConfigInRedis(syncDashboard, updateDashboardObject); + // update Report Config In Cache + dashboardService.updateReportConfigInCache(syncDashboard, updateDashboardObject); // insert chart Map<Integer, Integer> groupIdMapping = new HashMap<>(); diff --git a/nz-admin/src/main/java/com/nis/modules/dashboard/utils/DashboardConstant.java b/nz-admin/src/main/java/com/nis/modules/dashboard/utils/DashboardConstant.java index d93f5b49..9cb72d48 100644 --- a/nz-admin/src/main/java/com/nis/modules/dashboard/utils/DashboardConstant.java +++ b/nz-admin/src/main/java/com/nis/modules/dashboard/utils/DashboardConstant.java @@ -10,7 +10,7 @@ public class DashboardConstant { /** * dashboard 模板同步锁 key */ - public static final String TEMPLATE_SYNC_LOCK_KEY = "dashboardTemplateSynchronizationLock"; + public static final String TEMPLATE_SYNC_LOCK_KEY = "dashboard_template_sync_lock"; /** diff --git a/nz-admin/src/main/java/com/nis/modules/sys/job/SessionTimeOutJob.java b/nz-admin/src/main/java/com/nis/modules/sys/job/SessionTimeOutJob.java index 41a0db0e..60796c2d 100644 --- a/nz-admin/src/main/java/com/nis/modules/sys/job/SessionTimeOutJob.java +++ b/nz-admin/src/main/java/com/nis/modules/sys/job/SessionTimeOutJob.java @@ -44,7 +44,8 @@ public class SessionTimeOutJob extends QuartzJobBean { if (BooleanUtil.negate(isLeader)) return; Thread.currentThread().setName("SessionTimeOutJob"); - // 获取redis中所有的token信息 + + // active sessions Map<String, SysUserEntity> shiroSessionInfoMap = ShiroUtils.getShiroSessionInfoMap(); // 获取所有登录用户的信息 diff --git a/nz-admin/src/main/java/com/nis/modules/sys/job/SysComponentJob.java b/nz-admin/src/main/java/com/nis/modules/sys/job/SysComponentJob.java index a48fea13..326cd15e 100644 --- a/nz-admin/src/main/java/com/nis/modules/sys/job/SysComponentJob.java +++ b/nz-admin/src/main/java/com/nis/modules/sys/job/SysComponentJob.java @@ -20,6 +20,7 @@ import org.springframework.scheduling.quartz.QuartzJobBean; import java.net.InetAddress; import java.net.UnknownHostException; +import java.util.List; /** * 系统组件 状态检查线程 1、更新当前组件的状态 a、当设置了host时,直接使用 host b、没有设置host时,通过socket 连接 数据库 @@ -41,10 +42,8 @@ public class SysComponentJob extends QuartzJobBean { private String host; @Value("${server.port}") private Integer port; - @Value("${database.host}") - private String dbHost; - @Value("${database.port:3306}") - private Integer dbPort; + @Value("${database.url}") + private String databaseUrl; @Value("${server.ssl.enabled:false}") private boolean sslEnabled; @@ -53,7 +52,9 @@ public class SysComponentJob extends QuartzJobBean { protected void executeInternal(JobExecutionContext context) throws JobExecutionException { Thread.currentThread().setName("SysComponentJob"); // 获取本机ip - String localHost = Tool.StrUtil.isNotBlank(host) ? host : Tool.NetUtil.getLocalIPBySocket(dbHost, dbPort); + List<String> urlList = Tool.ListUtil.list(false, this.databaseUrl.split(",")); + String[] urlArr = urlList.get(0).split(":"); + String localHost = Tool.StrUtil.isNotBlank(host) ? host : Tool.NetUtil.getLocalIPBySocket(urlArr[0], Integer.valueOf(urlArr[1])); String protocol = sslEnabled ? "https" : "http"; // 正确得到本机ip,更新 sys_component 表 if (Tool.StrUtil.isNotBlank(localHost)) { diff --git a/nz-admin/src/main/java/com/nis/modules/sys/service/impl/SysApiKeyServiceImpl.java b/nz-admin/src/main/java/com/nis/modules/sys/service/impl/SysApiKeyServiceImpl.java index 4ed2d6c2..5ca8336a 100644 --- a/nz-admin/src/main/java/com/nis/modules/sys/service/impl/SysApiKeyServiceImpl.java +++ b/nz-admin/src/main/java/com/nis/modules/sys/service/impl/SysApiKeyServiceImpl.java @@ -121,7 +121,7 @@ public class SysApiKeyServiceImpl extends ServiceImpl<SysApiKeyDao,SysApiKey> im new LambdaQueryWrapper<SysApiKey>().in(SysApiKey::getId, Arrays.asList(ids.split(","))) .eq(SysApiKey::getCreateBy, ShiroUtils.getUserId().intValue()) ); - // 删除 redis 中 api key + // 删除 api key 对应的 shiro session List<String> tokens = sysApiKeys.stream().map(k -> k.getToken()).collect(Collectors.toList()); ShiroUtils.deleteSession(tokens); diff --git a/nz-admin/src/main/java/com/nis/modules/sys/service/impl/SysConfServiceImpl.java b/nz-admin/src/main/java/com/nis/modules/sys/service/impl/SysConfServiceImpl.java index 6370d7bb..f3690ce9 100644 --- a/nz-admin/src/main/java/com/nis/modules/sys/service/impl/SysConfServiceImpl.java +++ b/nz-admin/src/main/java/com/nis/modules/sys/service/impl/SysConfServiceImpl.java @@ -343,9 +343,9 @@ public class SysConfServiceImpl extends ServiceImpl<SysConfDao, SysConfigEntity> /*@Transactional(rollbackFor = Exception.class) public void resetEnterData() { try { - // redis写入当前用户id + // cache 写入当前用户id Long userId = ShiroUtils.getUserId(); - redisTemplate.opsForValue().set("reset",String.valueOf(userId),expire, TimeUnit.SECONDS); + cache.set("reset",String.valueOf(userId),expire, TimeUnit.SECONDS); // 删除用户输入的数据 String jsonTables = this.getValue(Constant.RESET_TABLE_INFOS); if(StringUtils.isNotEmpty(jsonTables)) { @@ -354,8 +354,8 @@ public class SysConfServiceImpl extends ServiceImpl<SysConfDao, SysConfigEntity> this.baseMapper.clearData((String)table); }); } - // 删除redis中key=reset的数据 - redisTemplate.delete("reset"); + // 删除cache中key=reset的数据 + cache.delete("reset"); logger.info("nezha reset success"); } catch (RuntimeException e) { logger.error("nezha reset fail",e); diff --git a/nz-admin/src/main/java/com/nis/modules/sys/service/impl/SysInfoServiceImpl.java b/nz-admin/src/main/java/com/nis/modules/sys/service/impl/SysInfoServiceImpl.java index 794bdd3f..c55f18ad 100644 --- a/nz-admin/src/main/java/com/nis/modules/sys/service/impl/SysInfoServiceImpl.java +++ b/nz-admin/src/main/java/com/nis/modules/sys/service/impl/SysInfoServiceImpl.java @@ -42,7 +42,7 @@ public class SysInfoServiceImpl implements SysInfoService { resultMap.put("nezha", sysVersionMap); - // 2. 组件版本信息 mariaDB redis prometheus + // 2. 组件版本信息 mariaDB prometheus List<Map> componentVersionInfoList = new ArrayList<>(); // ① mariaDB version @@ -52,27 +52,13 @@ public class SysInfoServiceImpl implements SysInfoService { componentVersion.put("version", dataBasesVersion); componentVersionInfoList.add(componentVersion); - // ② redis version - // Object redisVersion = redisTemplate.execute(new RedisCallback<String>() { - // @Override - // public String doInRedis(RedisConnection connection) throws DataAccessException { - // RedisServerCommands redisServerCommands = connection.serverCommands(); - // Properties info = redisServerCommands.info(); - // return info.get("redis_version").toString(); - // } - // }); - // componentVersion = new HashMap(4); - // componentVersion.put("name", "Redis"); - // componentVersion.put("version", redisVersion.toString()); - // componentVersionInfoList.add(componentVersion); - - // ③ prometheus version 随机获取可用 agent + // ② prometheus version 随机获取可用 agent List<Agent> healthyAgentList = agentDao.selectList(new QueryWrapper<Agent>().lambda().eq(true, Agent::getStatus, 1)); if (CollectionUtils.isNotEmpty(healthyAgentList)) { Agent server = healthyAgentList.get(RandomUtils.nextInt(0, healthyAgentList.size())); String path = "/prometheus/proxy/api/v1/status/buildinfo"; try { - String result = AgentUtil.requestGet(server,path, null, String.class); + String result = AgentUtil.requestGet(server, path, null, String.class); R resultObj = JSONObject.parseObject(result, R.class); if (RCode.SUCCESS.getCode().equals((Integer) resultObj.get("code"))) { Object data = resultObj.get("data"); diff --git a/nz-admin/src/main/java/com/nis/modules/sys/service/impl/SysUserServiceImpl.java b/nz-admin/src/main/java/com/nis/modules/sys/service/impl/SysUserServiceImpl.java index 272b8732..bf0bd55c 100644 --- a/nz-admin/src/main/java/com/nis/modules/sys/service/impl/SysUserServiceImpl.java +++ b/nz-admin/src/main/java/com/nis/modules/sys/service/impl/SysUserServiceImpl.java @@ -224,11 +224,11 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserDao, SysUserEntity> i if (StringUtils.isBlank(user.getPin())) { user.setPin(null); } else { - // 如果不是本人更改 自己密码的话,删除 redis 中用户session + // 如果不是本人更改 自己密码的话,删除用户 session Long loginUserId = ShiroUtils.getUserId(); if (!loginUserId.equals(user.getId())) { - // 通过 userId 删除 redis 中记录的 登录信息 - this.removeUserInfoInRedis(user.getId()); + // remove user session + this.removeUserSession(user.getId()); } SysUserEntity userEntity = this.getById(user.getId()); user.setPin(ShiroUtils.sha256(user.getPin(), userEntity.getSalt())); @@ -263,8 +263,8 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserDao, SysUserEntity> i // 角色变更 sysUserRoleService.saveOrUpdate(userId, roleIds); - // 通过 userId 删除 redis 中记录的 登录信息 - this.removeUserInfoInRedis(userId); + // remove user session + this.removeUserSession(userId); // 变更 sys_api_key role_id 注:当前 用户只能关联一个角色 String updateRoleId = Arrays.asList(roleIds.split(",")).get(0); @@ -272,12 +272,11 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserDao, SysUserEntity> i } /** - * 通过 userId 删除 redis 中记录的 登录信息 + * remove user session * * @param userId */ - private void removeUserInfoInRedis(Long userId) { - // 删除 redis 中的 token + private void removeUserSession(Long userId) { List<String> removeKeys = new ArrayList<>(); try { Map<String, SysUserEntity> shiroSessionInfoMap = ShiroUtils.getShiroSessionInfoMap(); @@ -288,7 +287,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserDao, SysUserEntity> i } } } catch (Exception e) { - log.error(e, "[removeUserInfoInRedis] [error] [userId: {}]", userId); + log.error(e, "[removeUserSession] [error] [userId: {}]", userId); } finally { // 删除 关联key if (CollectionUtils.isNotEmpty(removeKeys)) { @@ -366,7 +365,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserDao, SysUserEntity> i } if(Tool.CollUtil.isNotEmpty(visualDashboardList)) dashboardService.updateBatchById(visualDashboardList); - // 先查询,redis 中的 api key 同样需要删除 + // 用户创建的 api key List<SysApiKey> apiKeyList = sysApiKeyService.list(new LambdaUpdateWrapper<SysApiKey>().in(SysApiKey::getCreateBy, idList)); // 删除相关 sys_api_key sysApiKeyService.remove(new LambdaUpdateWrapper<SysApiKey>().in(SysApiKey::getCreateBy, idList)); @@ -377,7 +376,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserDao, SysUserEntity> i // sys user preference sysUserPrefService.remove(new LambdaQueryWrapper<SysUserPreference>().in(SysUserPreference::getUid, idList)); - // 删除 redis 中 用户token 信息 + // session token list List<String> removeKeys = new ArrayList<>(); List<Long> userIdList = new ArrayList<>(split.length); for (int i = 0; i < split.length; i++) { diff --git a/nz-admin/src/main/java/com/nis/modules/sys/shiro/ShiroUtils.java b/nz-admin/src/main/java/com/nis/modules/sys/shiro/ShiroUtils.java index f5f8eeb4..6f24d295 100644 --- a/nz-admin/src/main/java/com/nis/modules/sys/shiro/ShiroUtils.java +++ b/nz-admin/src/main/java/com/nis/modules/sys/shiro/ShiroUtils.java @@ -110,9 +110,10 @@ public class ShiroUtils { } return userList; } - + + /** - * 从 redis 中获取 token 和 用户信息 + * getActiveSessions * * @return */ diff --git a/nz-admin/src/main/java/com/nis/modules/tool/service/impl/FullTextSearchServiceImpl.java b/nz-admin/src/main/java/com/nis/modules/tool/service/impl/FullTextSearchServiceImpl.java index e21344d1..01ef4db6 100644 --- a/nz-admin/src/main/java/com/nis/modules/tool/service/impl/FullTextSearchServiceImpl.java +++ b/nz-admin/src/main/java/com/nis/modules/tool/service/impl/FullTextSearchServiceImpl.java @@ -100,7 +100,7 @@ public class FullTextSearchServiceImpl implements FullTextSearchService { return new PageUtils(page); } else { - // TODO REDIS + // TODO CACHE return new PageUtils(null); } } diff --git a/nz-admin/src/main/java/com/nis/setup/controller/SetupController.java b/nz-admin/src/main/java/com/nis/setup/controller/SetupController.java index 7eaa6c05..ca4318a5 100644 --- a/nz-admin/src/main/java/com/nis/setup/controller/SetupController.java +++ b/nz-admin/src/main/java/com/nis/setup/controller/SetupController.java @@ -2,28 +2,32 @@ package com.nis.setup.controller; import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.IORuntimeException; -import cn.hutool.core.io.IoUtil; import cn.hutool.core.util.RuntimeUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.db.Db; import cn.hutool.db.DbUtil; import cn.hutool.db.ds.simple.SimpleDataSource; import cn.hutool.log.Log; -import cn.hutool.setting.dialect.Props; +import com.nis.common.exception.NZException; import com.nis.common.smartvalidate.ValidateUtils; import com.nis.common.utils.Constant; import com.nis.common.utils.R; import com.nis.common.utils.RCode; import com.nis.common.utils.Tool; +import com.nis.modules.sys.entity.SysUserEntity; +import com.nis.setup.entity.DatabaseEntity; import com.nis.setup.entity.SetupEntity; +import com.nis.setup.entity.SystemEntity; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.*; -import redis.clients.jedis.Jedis; import java.io.File; import java.io.IOException; import java.sql.SQLException; +import java.util.Arrays; +import java.util.LinkedHashMap; import java.util.List; +import java.util.stream.Collectors; @RestController @RequestMapping("/setup") @@ -42,8 +46,6 @@ public class SetupController { private String restartCommand; @Value("${database.loginTimeout:10}") private Integer dbLoginTimeouot;//数据库登录超时时间 - @Value("${redis.loginTimeout:10}") - private Integer redisLoginTimeouot;//redis登录超时时间 /** * 获取 nezha inited 状态 * @return @@ -60,10 +62,6 @@ public class SetupController { */ @PostMapping("/config") public R setup(@RequestBody SetupEntity setup){ - ValidateUtils.is(setup.getDatabase().getHost()).notNull(RCode.SYS_CONFIG_DB_URL_ISNULL) - .and(setup.getDatabase().getUsername()).notNull(RCode.SYS_CONFIG_DB_USERNAME_ISNULL) - .and(setup.getDatabase().getPin()).notNull(RCode.SYS_CONFIG_DB_PASSWORD_ISNULL) - .and(setup.getRedis().getHost()).notNull(RCode.SYS_CONFIG_REDIS_HOST_ISNULL); R r = doCheckCode(setup.getCode()); if(r.get("code") != RCode.SUCCESS.getCode()){ return R.error(RCode.SYS_CONFIG_CODE_INVALID); @@ -71,6 +69,27 @@ public class SetupController { if(inited == 2) {//已经配置过,不需要再配置 return R.error(RCode.SYS_CONFIG_HAD_CONFIG); } + // db + DatabaseEntity database = setup.getDatabase(); + ValidateUtils.is(database.getUrl()).notNull(RCode.SYS_CONFIG_DB_URL_ISNULL) + .and(database.getUsername()).notNull(RCode.SYS_CONFIG_DB_USERNAME_ISNULL) + .and(database.getPin()).notNull(RCode.SYS_CONFIG_DB_PASSWORD_ISNULL); + List<String> dbUrlList = Arrays.asList(database.getUrl()); + if (dbUrlList.size() > 2) { + throw new NZException(RCode.SYS_CONFIG_DB_URL_EXCEEDED_LIMIT); + } + + // adminUser + SysUserEntity adminUser = setup.getAdminUser(); + ValidateUtils.is(adminUser.getUsername()).notNull(RCode.SYS_USER_NAME_ISNULL) + .and(adminUser.getPin()).notNull(RCode.SYS_USER_PASSWORD_ISNULL); + + // system + SystemEntity system = setup.getSystem(); + ValidateUtils.is(system.getTimezone()).notNull(RCode.SYS_CONFIG_TIMEZONE_ISNULL); + if (StrUtil.equals("0", system.getFederationEnabled())) { + system.setAsset_ping_from("1"); + } try{ //配置文件 boolean absolutePath = Tool.FileUtil.isAbsolutePath(nezhaConfigPath); @@ -78,7 +97,6 @@ public class SetupController { log.info("nezhaConfigPath:{}",configFile.getAbsolutePath()); //更改 nezha.inited 为 2,下次启动时不再执行 //nezha.properties 配置文件路径:./config/nezha.properties - Props prop = null; if(!configFile.exists()) { //创建父目录&配置文件 Tool.FileUtil.mkParentDirs(configFile.getAbsolutePath()); @@ -92,21 +110,18 @@ public class SetupController { // String dbPinHex = aes.encryptHex(setup.getDatabase().getPin()); String dbPinHex = Tool.AesUtil.encrypt(setup.getDatabase().getPin(), Constant.AES_SECRET_KEY); - prop = new Props(configFile, Constant.DEFAULT_CHARTSET_NAME); - prop.put("nezha.inited", "1"); - prop.put("database.host",setup.getDatabase().getHost()); - prop.put("database.port",Tool.StrUtil.utf8Str(setup.getDatabase().getPort())); - prop.put("database.name",setup.getDatabase().getName()); - prop.put("database.user",setup.getDatabase().getUsername()); - prop.put("database.pin",dbPinHex); - prop.put("redis.host",setup.getRedis().getHost()); - prop.put("redis.port",Tool.StrUtil.utf8Str(setup.getRedis().getPort())); - prop.put("redis.pin",setup.getRedis().getPin()); - if(Tool.StrUtil.isBlank(prop.getStr("server.port"))) { - prop.put("server.port","80"); - } - //保存配置文件 - prop.store(configFile.getAbsolutePath()); + LinkedHashMap<String, String> propsMap = new LinkedHashMap<>(); + propsMap.put("nezha.inited", "1"); + if (Tool.StrUtil.isBlank(propsMap.get("server.port"))) { + propsMap.put("server.port","80"); + } + propsMap.put("database.url", dbUrlList.stream().collect(Collectors.joining(","))); + propsMap.put("database.name", setup.getDatabase().getName()); + propsMap.put("database.user", setup.getDatabase().getUsername()); + propsMap.put("database.pin", dbPinHex); + + // 保存配置文件 + FileUtil.writeUtf8Map(propsMap, configFile, "=", false); //其它配置保存到临时文件 File tmpConfigFile = Tool.FileUtil.file(tmpDir, Constant.SETUP_FILE_NAME); @@ -135,75 +150,48 @@ public class SetupController { } @PostMapping("/checkDb") - public R checkDBConnection(@RequestBody SetupEntity setup){ + public R checkDBConnection(@RequestBody SetupEntity setup) { R r = doCheckCode(setup.getCode()); - if(r.get("code") != RCode.SUCCESS.getCode()){ + if (r.get("code") != RCode.SUCCESS.getCode()) { return R.error(RCode.SYS_CONFIG_CODE_INVALID); } - ValidateUtils.is(setup.getDatabase().getHost()).notNull(RCode.SYS_CONFIG_DB_PARAM_INVALID) + ValidateUtils.is(setup.getDatabase().getUrl()).notNull(RCode.SYS_CONFIG_DB_URL_ISNULL) .and(setup.getDatabase().getUsername()).notNull(RCode.SYS_CONFIG_DB_USERNAME_ISNULL) .and(setup.getDatabase().getPin()).notNull(RCode.SYS_CONFIG_DB_PASSWORD_ISNULL) .and(setup.getDatabase().getName()).notNull(RCode.SYS_CONFIG_DB_NAME_ISNULL); String dbName = setup.getDatabase().getName(); - SimpleDataSource dataSource = null; - try{ - dataSource = new SimpleDataSource(setup.getDatabase().getUrl(), setup.getDatabase().getUsername(), setup.getDatabase().getPin(), driver); - dataSource.setLoginTimeout(dbLoginTimeouot); - Db db = DbUtil.use(dataSource); - //没有自动创建 数据库 - List<String> dbNames = db.query("show databases;", String.class); - if(dbNames != null) { - boolean match = dbNames.stream().anyMatch(dbName::equalsIgnoreCase); - if(!match) { - int execute = db.execute("create database if not exists `" + dbName + "` default character set utf8mb4 COLLATE utf8mb4_general_ci"); - log.info("database {} not exists,auto create database,result:{}",dbName,execute); - } - } - - String result = db.queryString("select 1"); - if(Tool.StrUtil.isNotBlank(result)) { - return R.ok(); - } - return R.error(RCode.SYS_CONFIG_DB_PARAM_INVALID); - }catch (SQLException | RuntimeException e){ - log.error(e); - return R.error(RCode.SYS_CONFIG_DB_PARAM_INVALID); - } finally { - Tool.IoUtil.close(dataSource); - } - } - @PostMapping("/checkRedis") - public R checkRedisConnection(@RequestBody SetupEntity setup){ - R r = doCheckCode(setup.getCode()); - if(r.get("code") != RCode.SUCCESS.getCode()){ - return R.error(RCode.SYS_CONFIG_CODE_INVALID); - } - ValidateUtils.is(setup.getRedis().getHost()).notNull(RCode.SYS_CONFIG_REDIS_HOST_ISNULL); - Jedis jedis = null; - try{ - jedis = new Jedis(setup.getRedis().getHost(),setup.getRedis().getPort(),redisLoginTimeouot); - if(!StrUtil.isEmpty(setup.getRedis().getPin())){ - jedis.auth(setup.getRedis().getPin()); - } + log.info("[checkDBConnection] [begin] [checkUrl: {}] [username: {}]", setup.getDatabase().getUrl(), setup.getDatabase().getUsername()); - if("pong".equalsIgnoreCase(jedis.ping())){ - return R.ok(); - } - return R.error(RCode.SYS_CONFIG_REDIS_PARAM_INVALID); - }catch (RuntimeException e){ - log.error(e); - if(e.getMessage().indexOf("NOAUTH") != -1){ - return R.error(RCode.SYS_CONFIG_REDIS_PASSWORD_REQUIRED); - }else if(e.getMessage().indexOf("invalid password") != -1){ - return R.error(RCode.SYS_CONFIG_REDIS_PASSWORD_INVALID); - }else{ - return R.error(RCode.SYS_CONFIG_REDIS_PARAM_INVALID); + List<String> dbUrlList = Arrays.asList(setup.getDatabase().getUrl()); + for (String url : dbUrlList) { + try (SimpleDataSource dataSource = new SimpleDataSource(setup.getDatabase().getConnectionUrl(url), setup.getDatabase().getUsername(), setup.getDatabase().getPin(), driver);) { + dataSource.setLoginTimeout(dbLoginTimeouot); + Db db = DbUtil.use(dataSource); + // 没有自动创建 数据库 + List<String> dbNames = db.query("show databases;", String.class); + if (dbNames != null) { + boolean match = dbNames.stream().anyMatch(dbName::equalsIgnoreCase); + if (!match) { + int execute = db.execute("create database if not exists `" + dbName + "` default character set utf8mb4 COLLATE utf8mb4_general_ci"); + log.info("database {} not exists,auto create database,result:{}", dbName, execute); + } + } + String result = db.queryString("select 1"); + log.info("[checkDBConnection] [url: {}] [result: {}]", url, result); + + if (Tool.StrUtil.isEmpty(result)) { + return R.error(RCode.SYS_CONFIG_DB_CONNECTION_FAILED.setParam(url)); + } + } catch (SQLException | RuntimeException e) { + log.error(e, "[checkDBConnection] [error] [db: {}]", url); + return R.error(RCode.SYS_CONFIG_DB_CONNECTION_FAILED.setParam(url)); } - }finally { - IoUtil.close(jedis); } + log.info("[checkDBConnection] [finshed]"); + return R.ok(); } + private R doCheckCode(String code){ File codeFile = FileUtil.file(this.tmpDir,"nezha.auth"); log.info("nezha.auth path: {} ",codeFile.getAbsolutePath()); diff --git a/nz-admin/src/main/java/com/nis/setup/entity/DatabaseEntity.java b/nz-admin/src/main/java/com/nis/setup/entity/DatabaseEntity.java index 84d3669c..ca5aca5f 100644 --- a/nz-admin/src/main/java/com/nis/setup/entity/DatabaseEntity.java +++ b/nz-admin/src/main/java/com/nis/setup/entity/DatabaseEntity.java @@ -6,14 +6,13 @@ import java.io.Serializable; @Data public class DatabaseEntity implements Serializable { - private String host; - private Integer port = 3306; + private String[] url; private String name = "nz"; private String username; private String pin; - public String getUrl(){ - return "jdbc:mysql://"+this.getHost()+":"+this.getPort()+"/"+"?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false"; + public String getConnectionUrl(String hostAndPort) { + return "jdbc:mysql://" + hostAndPort + "/" + "?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false"; } } diff --git a/nz-admin/src/main/java/com/nis/setup/entity/RedisEntity.java b/nz-admin/src/main/java/com/nis/setup/entity/RedisEntity.java deleted file mode 100644 index fdd54196..00000000 --- a/nz-admin/src/main/java/com/nis/setup/entity/RedisEntity.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.nis.setup.entity; - -import lombok.Data; - -import java.io.Serializable; - -@Data -public class RedisEntity implements Serializable { - private String host; - private Integer port = 6379; - private String pin ; -} diff --git a/nz-admin/src/main/java/com/nis/setup/entity/SetupEntity.java b/nz-admin/src/main/java/com/nis/setup/entity/SetupEntity.java index 8f371003..a1cb0d90 100644 --- a/nz-admin/src/main/java/com/nis/setup/entity/SetupEntity.java +++ b/nz-admin/src/main/java/com/nis/setup/entity/SetupEntity.java @@ -1,12 +1,13 @@ package com.nis.setup.entity; -import lombok.Data; - import java.io.Serializable; + +import com.nis.modules.sys.entity.SysUserEntity; +import lombok.Data; @Data public class SetupEntity implements Serializable { - private RedisEntity redis; private DatabaseEntity database; private SystemEntity system; + private SysUserEntity adminUser; private String code; } diff --git a/nz-admin/src/main/java/com/nis/setup/entity/SystemEntity.java b/nz-admin/src/main/java/com/nis/setup/entity/SystemEntity.java index ec2ce486..03c3ff5d 100644 --- a/nz-admin/src/main/java/com/nis/setup/entity/SystemEntity.java +++ b/nz-admin/src/main/java/com/nis/setup/entity/SystemEntity.java @@ -6,10 +6,15 @@ import java.io.Serializable; @Data public class SystemEntity implements Serializable { - private String alertPath; - private String alertPrefix; + private String timezone; + private String language = "en"; + // prometheus_federation_enabled private String federationEnabled = "1"; - private String username; - private String pin; + private String asset_ping_from = "1"; + private String asset_ping_interval = "300"; + private String default_scrape_interval = "30"; + private String default_scrape_timeout = "30"; + private String snmp_trap_listen_port = "162"; + } diff --git a/nz-admin/src/main/resources/application.yml b/nz-admin/src/main/resources/application.yml index 29a17368..e9729c4c 100644 --- a/nz-admin/src/main/resources/application.yml +++ b/nz-admin/src/main/resources/application.yml @@ -77,7 +77,7 @@ nezha: endpointStateTime: 90000 #endpoint state超时周期时间 毫秒 userId: expire: 300 - cluster: false #集群配置 true集群环境 false单机环境,还需打开pom.xml里的spring-session-data-redis注释 + cluster: false #集群配置 true集群环境 false单机环境 globalSessionTimeout: 3600 #单机环境,session过期时间为60分钟 promtoolPath: ./promtool uploadTempPath: /upload/temp diff --git a/nz-admin/src/main/resources/config/nezha.properties b/nz-admin/src/main/resources/config/nezha.properties index f9acf304..fb923901 100644 --- a/nz-admin/src/main/resources/config/nezha.properties +++ b/nz-admin/src/main/resources/config/nezha.properties @@ -3,17 +3,6 @@ server.port=80 nezha.inited=0 database.name=nz -database.host=192.168.40.42 -database.port=3306 +database.url=192.168.40.42:3306 database.user=root database.pin=111111 -# 可选值:standalone,sentinel,默认:standalone -redis.mode=standalone -redis.host=192.168.40.41 -redis.port=6379 -redis.pin= -# sentinel 模式配置项 -redis.sentinel.master=master -# 格式: 192.168.1.1:6379,192.168.1.2:6379 -redis.sentinel.nodes= - diff --git a/nz-admin/src/test/resources/application-test.properties b/nz-admin/src/test/resources/application-test.properties index 1065e244..6696b05e 100644 --- a/nz-admin/src/test/resources/application-test.properties +++ b/nz-admin/src/test/resources/application-test.properties @@ -5,17 +5,10 @@ nezha.inited=2 # gitlab-ci db name database.name=test # gitlab-ci db host ; mysql �� host Ϊ mysql -database.host=mariadb -database.port=3306 +database.url=mariadb:3306 database.user=root # AES ���� 111111 database.pin=69a494821500d42563e1b61cbd117fea -#redis.host=127.0.0.1 -# gitlab-ci redis host -redis.host=redis -redis.port=6379 -redis.pin= -redis.database=6 nezha.generate.api.name=Network Zodiac API logging.config=src/test/resources/logback-spring.xml quartz.enabled=false diff --git a/nz-common/src/main/java/com/nis/common/aspect/RedisAspect.java b/nz-common/src/main/java/com/nis/common/aspect/RedisAspect.java deleted file mode 100644 index e6914222..00000000 --- a/nz-common/src/main/java/com/nis/common/aspect/RedisAspect.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - - * - - * - * - */ - -package com.nis.common.aspect; - -import cn.hutool.log.Log; -import com.nis.common.exception.NZException; -import org.aspectj.lang.ProceedingJoinPoint; -import org.aspectj.lang.annotation.Around; -import org.aspectj.lang.annotation.Aspect; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; - -/** - * Redis切面处理类 - * - * @author Mark [email protected] - */ -@Aspect -@Component -public class RedisAspect { - private Log logger = Log.get(); - /** - * 是否开启redis缓存 true开启 false关闭 - */ - @Value("${nezha.redis.open: false}") - private boolean open; - - @Around("execution(* com.nis.common.utils.RedisUtils.*(..))") - public Object around(ProceedingJoinPoint point) throws Throwable { - Object result = null; - if(open){ - try{ - result = point.proceed(); - }catch (Exception e){ - logger.error("redis error",e); - throw new NZException("Redis服务异常"); - } - } - return result; - } -} diff --git a/nz-common/src/main/java/com/nis/common/config/RedisConfig.java b/nz-common/src/main/java/com/nis/common/config/RedisConfig.java deleted file mode 100644 index 7a7ffc12..00000000 --- a/nz-common/src/main/java/com/nis/common/config/RedisConfig.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - - * - - * - * - */ - -package com.nis.common.config; - -import org.springframework.context.annotation.Configuration; - -/** - * Redis配置 - * - * @author Mark [email protected] - */ -@Configuration -public class RedisConfig { -// @Autowired -// private RedisConnectionFactory factory; -// -// @Bean -// public RedisTemplate<String, Object> redisTemplate() { -// RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>(); -// redisTemplate.setKeySerializer(new StringRedisSerializer()); -// redisTemplate.setHashKeySerializer(new StringRedisSerializer()); -// redisTemplate.setHashValueSerializer(new StringRedisSerializer()); -// redisTemplate.setValueSerializer(new StringRedisSerializer()); -// redisTemplate.setConnectionFactory(factory); -// return redisTemplate; -// } -// -// @Bean -// public HashOperations<String, String, Object> hashOperations(RedisTemplate<String, Object> redisTemplate) { -// return redisTemplate.opsForHash(); -// } -// -// @Bean -// public ValueOperations<String, String> valueOperations(RedisTemplate<String, String> redisTemplate) { -// return redisTemplate.opsForValue(); -// } -// -// @Bean -// public ListOperations<String, Object> listOperations(RedisTemplate<String, Object> redisTemplate) { -// return redisTemplate.opsForList(); -// } -// -// @Bean -// public SetOperations<String, Object> setOperations(RedisTemplate<String, Object> redisTemplate) { -// return redisTemplate.opsForSet(); -// } -// -// @Bean -// public ZSetOperations<String, Object> zSetOperations(RedisTemplate<String, Object> redisTemplate) { -// return redisTemplate.opsForZSet(); -// } -} diff --git a/nz-common/src/main/java/com/nis/common/utils/RCode.java b/nz-common/src/main/java/com/nis/common/utils/RCode.java index c5f33c0f..03af998c 100644 --- a/nz-common/src/main/java/com/nis/common/utils/RCode.java +++ b/nz-common/src/main/java/com/nis/common/utils/RCode.java @@ -797,15 +797,10 @@ public enum RCode { SYS_CONFIG_UNSAVEDCHANGE_ISNULL(571065, "System config unsaved change can not be empty"), SYS_CONFIG_CODE_FILE_ISNULL(574066,"The validate file is not exist"), //不存在校验使用的文件 SYS_CONFIG_CODE_INVALID(574067,"The code is invalid"),//校验文件中的code与传递的值不符 - SYS_CONFIG_DB_PARAM_INVALID(574068,"The DB connect params is invalid"),//校验文件中的code与传递的值不符 - SYS_CONFIG_REDIS_PASSWORD_INVALID(574069,"The redis password is invalid"), - SYS_CONFIG_REDIS_PASSWORD_REQUIRED(574070,"The redis password is required"), - SYS_CONFIG_REDIS_PARAM_INVALID(574071,"The redis params is invalid"), + SYS_CONFIG_DB_CONNECTION_FAILED(570068, "{0} Connection failed"), SYS_CONFIG_DB_URL_ISNULL(574072,"The DB host is null"), SYS_CONFIG_DB_USERNAME_ISNULL(574073,"The DB username is null"), SYS_CONFIG_DB_PASSWORD_ISNULL(574074,"The DB password is null"), - SYS_CONFIG_REDIS_HOST_ISNULL(574075,"The redis host is null"), - SYS_CONFIG_REDIS_PORT_ISNULL(574076,"The redis host is null"), SYS_CONFIG_HAD_CONFIG(574077,"Someone has started to configure the system"), SYS_CONFIG_SESSION_TIMEOUT_INVALID(573078,"Session timeout is not less than 15"), SYS_CONFIGI_PROMEFEDEENABLED_NCORRECT(574079, "Prometheus federation enabled must be 0 or 1"), @@ -813,6 +808,7 @@ public enum RCode { SYS_CONFIGI_METRICSSTORAGETYPE_NCORRECT(574081, "Metrics storage type must be 1 or 2"), SYS_CONFIGI_LOGSSTORAGETYPE_NCORRECT(574082, "Logs storage type must be 1 or 2"), SYS_CONFIG_DB_NAME_ISNULL(574083,"The DB name is null"), + SYS_CONFIG_DB_URL_EXCEEDED_LIMIT(573084, "Please limit the number of DB URL configuration items"), /** @@ -25,7 +25,6 @@ <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>21</java.version> <junit.version>4.12</junit.version> - <jedis.version>2.9.0</jedis.version> <druid.version>1.2.8</druid.version> <mybatisplus.version>3.5.3.2</mybatisplus.version> <mysql.version>8.0.27</mysql.version> @@ -69,20 +68,11 @@ <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> </dependency> -<!-- <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-data-redis</artifactId> - </dependency> --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> <optional>true</optional> </dependency> - <dependency> - <groupId>redis.clients</groupId> - <artifactId>jedis</artifactId> - <version>${jedis.version}</version> - </dependency> <!-- mysql驱动 --> <dependency> <groupId>mysql</groupId> |
