javax.xml.bind
diff --git a/hippo4j-server/src/main/java/cn/hippo4j/server/config/DataBaseConfiguration.java b/hippo4j-server/src/main/java/cn/hippo4j/server/config/DataBaseConfiguration.java
new file mode 100644
index 00000000..607d4370
--- /dev/null
+++ b/hippo4j-server/src/main/java/cn/hippo4j/server/config/DataBaseConfiguration.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package cn.hippo4j.server.config;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * Database configuration.
+ *
+ * Quoted from org.apache.shenyu.admin.config.DataBaseConfiguration
+ */
+@Configuration
+public class DataBaseConfiguration {
+
+ @Bean
+ @ConditionalOnMissingBean(value = DataBaseProperties.class)
+ public DataBaseProperties dataBaseProperties(@Value("${hippo4j.database.dialect:h2}") String dialect,
+ @Value("${hippo4j.database.init_script:sql-script/h2/schema.sql}") String initScript,
+ @Value("${hippo4j.database.init_enable:false}") Boolean initEnable) {
+ DataBaseProperties dataSourceProperties = new DataBaseProperties();
+ dataSourceProperties.setDialect(dialect);
+ dataSourceProperties.setInitScript(initScript);
+ dataSourceProperties.setInitEnable(initEnable);
+ return dataSourceProperties;
+ }
+}
diff --git a/hippo4j-server/src/main/java/cn/hippo4j/server/config/DataBaseProperties.java b/hippo4j-server/src/main/java/cn/hippo4j/server/config/DataBaseProperties.java
new file mode 100644
index 00000000..15565724
--- /dev/null
+++ b/hippo4j-server/src/main/java/cn/hippo4j/server/config/DataBaseProperties.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package cn.hippo4j.server.config;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+/**
+ * Database properties.
+ *
+ *
Quoted from org.apache.shenyu.admin.config.properties.DataBaseProperties
+ */
+@Data
+@ConfigurationProperties(prefix = "hippo4j.database")
+public class DataBaseProperties {
+
+ /**
+ * Dialect
+ */
+ private String dialect;
+
+ /**
+ * Init script
+ */
+ private String initScript;
+
+ /**
+ * Init enable
+ */
+ private Boolean initEnable;
+}
diff --git a/hippo4j-server/src/main/java/cn/hippo4j/server/init/LocalDataSourceLoader.java b/hippo4j-server/src/main/java/cn/hippo4j/server/init/LocalDataSourceLoader.java
new file mode 100644
index 00000000..fc3283c4
--- /dev/null
+++ b/hippo4j-server/src/main/java/cn/hippo4j/server/init/LocalDataSourceLoader.java
@@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package cn.hippo4j.server.init;
+
+import cn.hippo4j.server.config.DataBaseProperties;
+import com.google.common.base.Splitter;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.ibatis.io.Resources;
+import org.apache.ibatis.jdbc.ScriptRunner;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
+import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
+import org.springframework.lang.NonNull;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.nio.charset.StandardCharsets;
+import java.sql.*;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Local datasource loader.
+ *
+ *
Quoted from org.apache.shenyu.admin.spring.LocalDataSourceLoader
+ */
+@Slf4j
+@Component
+@ConditionalOnExpression("'${hippo4j.database.dialect}' == 'mysql' or '${hippo4j.database.dialect}' == 'h2'")
+public class LocalDataSourceLoader implements InstantiationAwareBeanPostProcessor {
+
+ private static final String PRE_FIX = "file:";
+
+ @Resource
+ private DataBaseProperties dataBaseProperties;
+
+ @Override
+ public Object postProcessAfterInitialization(@NonNull final Object bean, final String beanName) throws BeansException {
+ if ((bean instanceof DataSourceProperties) && dataBaseProperties.getInitEnable()) {
+ this.init((DataSourceProperties) bean);
+ }
+ return bean;
+ }
+
+ private void init(final DataSourceProperties properties) {
+ try {
+ String jdbcUrl = properties.getUrl();
+ // If jdbcUrl in the configuration file specifies the hippo4j database, it is removed,
+ // because the hippo4j database does not need to be specified when executing the SQL file,
+ // otherwise the hippo4j database will be disconnected when the hippo4j database does not exist
+ if (Objects.equals(dataBaseProperties.getDialect(), "mysql")) {
+ jdbcUrl = StringUtils.replace(properties.getUrl(), "/hippo4j_manager?", "?");
+ }
+ Connection connection = DriverManager.getConnection(jdbcUrl, properties.getUsername(), properties.getPassword());
+ // TODO Compatible with h2 to execute `INSERT IGNORE INTO` statement error
+ if (Objects.equals(dataBaseProperties.getDialect(), "h2") && ifNonExecute(connection)) {
+ return;
+ }
+ execute(connection, dataBaseProperties.getInitScript());
+ } catch (Exception ex) {
+ log.error("Datasource init error.", ex);
+ throw new RuntimeException(ex.getMessage());
+ }
+ }
+
+ private boolean ifNonExecute(final Connection conn) throws SQLException {
+ try (
+ Statement statement = conn.createStatement();
+ ResultSet resultSet = statement.executeQuery("SELECT COUNT(*) FROM `user`")) {
+ if (resultSet.next()) {
+ int countUser = resultSet.getInt(1);
+ return countUser > 0 ? true : false;
+ }
+ } catch (Exception ignored) {
+ log.error("Query data for errors.", ignored);
+ }
+ return false;
+ }
+
+ private void execute(final Connection conn, final String script) throws Exception {
+ ScriptRunner runner = new ScriptRunner(conn);
+ try {
+ // Doesn't print logger
+ runner.setLogWriter(null);
+ runner.setAutoCommit(true);
+ Resources.setCharset(StandardCharsets.UTF_8);
+ List initScripts = Splitter.on(";").splitToList(script);
+ for (String sqlScript : initScripts) {
+ if (sqlScript.startsWith(PRE_FIX)) {
+ String sqlFile = sqlScript.substring(PRE_FIX.length());
+ try (Reader fileReader = getResourceAsReader(sqlFile)) {
+ log.info("Execute hippo4j schema sql: {}", sqlFile);
+ runner.runScript(fileReader);
+ }
+ } else {
+ try (Reader fileReader = Resources.getResourceAsReader(sqlScript)) {
+ log.info("Execute hippo4j schema sql: {}", sqlScript);
+ runner.runScript(fileReader);
+ }
+ }
+ }
+ } finally {
+ conn.close();
+ }
+ }
+
+ private static Reader getResourceAsReader(final String resource) throws IOException {
+ return new InputStreamReader(new FileInputStream(resource), StandardCharsets.UTF_8);
+ }
+}
diff --git a/hippo4j-server/src/main/resources/application-h2.properties b/hippo4j-server/src/main/resources/application-h2.properties
index 5859aa19..b4bdea1c 100644
--- a/hippo4j-server/src/main/resources/application-h2.properties
+++ b/hippo4j-server/src/main/resources/application-h2.properties
@@ -1,6 +1,9 @@
-### Default database
+### Data source customization section
+hippo4j.database.dialect=h2
+hippo4j.database.init_enable=true
+hippo4j.database.init_script=sql-script/h2/hippo4j_manager.sql
+
spring.datasource.driver-class-name=org.h2.Driver
-spring.datasource.url=jdbc:h2:mem:hippo4j_manager;DB_CLOSE_DELAY=-1;MODE=MySQL;
+spring.datasource.url=jdbc:h2:file:{your storage address}/h2_hippo4j_test_file;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL;
spring.datasource.username=sa
spring.datasource.password=sa
-spring.datasource.schema=classpath:sql-script/h2/hippo4j_manager.sql
diff --git a/hippo4j-server/src/main/resources/application-mysql.properties b/hippo4j-server/src/main/resources/application-mysql.properties
deleted file mode 100644
index 2940c413..00000000
--- a/hippo4j-server/src/main/resources/application-mysql.properties
+++ /dev/null
@@ -1,5 +0,0 @@
-### Data source customization section
-spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
-spring.datasource.url=jdbc:mysql://localhost:3306/hippo4j_manager?characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8
-spring.datasource.username=root
-spring.datasource.password=root
diff --git a/hippo4j-server/src/main/resources/application.properties b/hippo4j-server/src/main/resources/application.properties
index 69a499af..b14c92fd 100644
--- a/hippo4j-server/src/main/resources/application.properties
+++ b/hippo4j-server/src/main/resources/application.properties
@@ -21,10 +21,21 @@ tenant=hippo4j
hippo4j.core.clean-history-data-period=30
hippo4j.core.clean-history-data-enable=true
+### Initialize the database dialect class.
+hippo4j.database.dialect=mysql
+hippo4j.database.init_enable=true
+hippo4j.database.init_script=sql-script/mysql/hippo4j_manager.sql
+
### Use netty to report thread pool monitoring data. The default is http.
# hippo4j.core.monitor.report-type=netty
#*************** Config Module Related Configurations ***************#
+### Default database
+spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
+spring.datasource.url=jdbc:mysql://localhost:3306/hippo4j_manager?characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8
+spring.datasource.username=root
+spring.datasource.password=root
+
### Hikari Datasource
spring.datasource.hikari.pool-name=Hikari
spring.datasource.hikari.connectionTimeout=30000
diff --git a/hippo4j-server/src/main/resources/banner.txt b/hippo4j-server/src/main/resources/banner.txt
index f075fe2c..3da2014a 100644
--- a/hippo4j-server/src/main/resources/banner.txt
+++ b/hippo4j-server/src/main/resources/banner.txt
@@ -1,15 +1,7 @@
- ,--, ,--, ,---._
- ,--.'| ,--.'| .-- -.' \ Hippo4J ${application.version}
- ,--, | : ,--, ,-.----. ,-.----. ,--, | : | | : Port: ${server.port}
-,---.'| : ',--.'| \ / \ \ / \ ,---. ,---.'| : ' : ; | PID: ${pid}
-| | : _' || |, | : || : | ' ,'\ ; : | | ; : | Console: http://127.0.0.1:${server.port}/index.html
-: : |.' |`--'_ | | .\ :| | .\ : / / || | : _' | | : :
-| ' ' ; :,' ,'| . : |: |. : |: |. ; ,. :: : |.' | : https://hippo4j.cn
-' | .'. |' | | | | \ :| | \ :' | |: :| ' ' ; : | ; |
-| | : | '| | : | : . || : . |' | .; :\ \ .'. | ___ l
-' : | : ;' : |__ : |`-': |`-'| : | `---`: | ' / /\ J :
-| | ' ,/ | | '.'|: : : : : : \ \ / ' ; |/ ../ `..- ,
-; : ;--' ; : ;| | : | | : `----' | : ;\ \ ;
-| ,/ | , / `---'.| `---'.| ' ,/ \ \ ,'
-'---' ---`-' `---` `---` '--' "---....--'
+ __ __ ___ ___ __
+ | |--.|__|.-----..-----..-----.| | | |__| Hippo4J ${application.version}
+ | || || _ || _ || _ || | | | | Port: ${server.port} PID: ${pid}
+ |__|__||__|| __|| __||_____||____ | | |
+ |__| |__| |: ||___| Site: https://hippo4j.cn
+ `---'
diff --git a/hippo4j-server/src/main/resources/sql-script/h2/hippo4j_manager.sql b/hippo4j-server/src/main/resources/sql-script/h2/hippo4j_manager.sql
index 2768fe2b..6db62ec4 100755
--- a/hippo4j-server/src/main/resources/sql-script/h2/hippo4j_manager.sql
+++ b/hippo4j-server/src/main/resources/sql-script/h2/hippo4j_manager.sql
@@ -1,235 +1,155 @@
-/******************************************/
-/* 数据库全名 = hippo4j_manager */
-/* 表名称 = tenant */
-/******************************************/
-DROP TABLE IF EXISTS `tenant`, `tenant_info`;
-CREATE TABLE `tenant` (
- `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
- `tenant_id` varchar(128) DEFAULT NULL COMMENT '租户ID',
- `tenant_name` varchar(128) DEFAULT NULL COMMENT '租户名称',
- `tenant_desc` varchar(256) DEFAULT NULL COMMENT '租户介绍',
- `owner` varchar(32) DEFAULT '-' COMMENT '负责人',
- `gmt_create` datetime DEFAULT NULL COMMENT '创建时间',
- `gmt_modified` datetime DEFAULT NULL COMMENT '修改时间',
- `del_flag` tinyint(1) DEFAULT NULL COMMENT '是否删除',
- PRIMARY KEY (`id`),
- UNIQUE KEY `tenant_id` (`id`),
- KEY `uk_tenantinfo_tenantid` (`tenant_id`,`del_flag`) USING BTREE
-) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='租户表';
+CREATE TABLE IF NOT EXISTS `tenant` (
+ `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
+ `tenant_id` varchar(128) DEFAULT NULL COMMENT '租户ID',
+ `tenant_name` varchar(128) DEFAULT NULL COMMENT '租户名称',
+ `tenant_desc` varchar(256) DEFAULT NULL COMMENT '租户介绍',
+ `owner` varchar(32) DEFAULT '-' COMMENT '负责人',
+ `gmt_create` datetime DEFAULT NULL COMMENT '创建时间',
+ `gmt_modified` datetime DEFAULT NULL COMMENT '修改时间',
+ `del_flag` tinyint(1) DEFAULT NULL COMMENT '是否删除',
+ PRIMARY KEY (`id`)
+);
+
+CREATE TABLE IF NOT EXISTS `item` (
+ `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
+ `tenant_id` varchar(128) DEFAULT NULL COMMENT '租户ID',
+ `item_id` varchar(128) DEFAULT NULL COMMENT '项目ID',
+ `item_name` varchar(128) DEFAULT NULL COMMENT '项目名称',
+ `item_desc` varchar(256) DEFAULT NULL COMMENT '项目介绍',
+ `owner` varchar(32) DEFAULT NULL COMMENT '负责人',
+ `gmt_create` datetime DEFAULT NULL COMMENT '创建时间',
+ `gmt_modified` datetime DEFAULT NULL COMMENT '修改时间',
+ `del_flag` tinyint(1) DEFAULT NULL COMMENT '是否删除',
+ PRIMARY KEY (`id`)
+);
+
+CREATE TABLE IF NOT EXISTS `config` (
+ `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
+ `tenant_id` varchar(128) DEFAULT NULL COMMENT '租户ID',
+ `item_id` varchar(256) DEFAULT NULL COMMENT '项目ID',
+ `tp_id` varchar(56) DEFAULT NULL COMMENT '线程池ID',
+ `tp_name` varchar(56) DEFAULT NULL COMMENT '线程池名称',
+ `core_size` int(11) DEFAULT NULL COMMENT '核心线程数',
+ `max_size` int(11) DEFAULT NULL COMMENT '最大线程数',
+ `queue_type` int(11) DEFAULT NULL COMMENT '队列类型...',
+ `capacity` int(11) DEFAULT NULL COMMENT '队列大小',
+ `rejected_type` int(11) DEFAULT NULL COMMENT '拒绝策略',
+ `keep_alive_time` int(11) DEFAULT NULL COMMENT '线程存活时间(秒)',
+ `execute_time_out` int(11) DEFAULT NULL COMMENT '执行超时时间(毫秒)',
+ `allow_core_thread_time_out` tinyint(1) DEFAULT NULL COMMENT '允许核心线程超时',
+ `content` longtext COMMENT '线程池内容',
+ `md5` varchar(32) NOT NULL COMMENT 'MD5',
+ `is_alarm` tinyint(1) DEFAULT NULL COMMENT '是否报警',
+ `capacity_alarm` int(11) DEFAULT NULL COMMENT '容量报警',
+ `liveness_alarm` int(11) DEFAULT NULL COMMENT '活跃度报警',
+ `gmt_create` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+ `gmt_modified` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
+ `del_flag` tinyint(1) DEFAULT NULL COMMENT '是否删除',
+ PRIMARY KEY (`id`)
+);
+
+CREATE TABLE IF NOT EXISTS `inst_config` (
+ `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
+ `tenant_id` varchar(128) DEFAULT NULL COMMENT '租户ID',
+ `item_id` varchar(256) DEFAULT NULL COMMENT '项目ID',
+ `tp_id` varchar(56) DEFAULT NULL COMMENT '线程池ID',
+ `instance_id` varchar(256) DEFAULT NULL COMMENT '实例ID',
+ `content` longtext COMMENT '线程池内容',
+ `md5` varchar(32) NOT NULL COMMENT 'MD5',
+ `gmt_create` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+ `gmt_modified` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
+ PRIMARY KEY (`id`)
+);
+
+CREATE TABLE IF NOT EXISTS `his_run_data` (
+ `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
+ `tenant_id` varchar(128) DEFAULT NULL COMMENT '租户ID',
+ `item_id` varchar(256) DEFAULT NULL COMMENT '项目ID',
+ `tp_id` varchar(56) DEFAULT NULL COMMENT '线程池ID',
+ `instance_id` varchar(256) DEFAULT NULL COMMENT '实例ID',
+ `current_load` bigint(20) DEFAULT NULL COMMENT '当前负载',
+ `peak_load` bigint(20) DEFAULT NULL COMMENT '峰值负载',
+ `pool_size` bigint(20) DEFAULT NULL COMMENT '线程数',
+ `active_size` bigint(20) DEFAULT NULL COMMENT '活跃线程数',
+ `queue_capacity` bigint(20) DEFAULT NULL COMMENT '队列容量',
+ `queue_size` bigint(20) DEFAULT NULL COMMENT '队列元素',
+ `queue_remaining_capacity` bigint(20) DEFAULT NULL COMMENT '队列剩余容量',
+ `completed_task_count` bigint(20) DEFAULT NULL COMMENT '已完成任务计数',
+ `reject_count` bigint(20) DEFAULT NULL COMMENT '拒绝次数',
+ `timestamp` bigint(20) DEFAULT NULL COMMENT '时间戳',
+ `gmt_create` datetime DEFAULT NULL COMMENT '创建时间',
+ `gmt_modified` datetime DEFAULT NULL COMMENT '修改时间',
+ PRIMARY KEY (`id`)
+);
+
+CREATE TABLE IF NOT EXISTS `log_record_info` (
+ `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
+ `tenant` varchar(128) NOT NULL DEFAULT '' COMMENT '租户标识',
+ `biz_key` varchar(128) NOT NULL DEFAULT '' COMMENT '日志业务标识',
+ `biz_no` varchar(128) NOT NULL DEFAULT '' COMMENT '业务码标识',
+ `operator` varchar(64) NOT NULL DEFAULT '' COMMENT '操作人',
+ `action` varchar(128) NOT NULL DEFAULT '' COMMENT '动作',
+ `category` varchar(128) NOT NULL DEFAULT '' COMMENT '种类',
+ `detail` varchar(2048) NOT NULL DEFAULT '' COMMENT '修改的详细信息,可以为json',
+ `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+ PRIMARY KEY (`id`)
+);
+
+CREATE TABLE IF NOT EXISTS `user` (
+ `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
+ `user_name` varchar(64) NOT NULL COMMENT '用户名',
+ `password` varchar(512) NOT NULL COMMENT '用户密码',
+ `role` varchar(50) NOT NULL COMMENT '角色',
+ `gmt_create` datetime NOT NULL COMMENT '创建时间',
+ `gmt_modified` datetime NOT NULL COMMENT '修改时间',
+ `del_flag` tinyint(1) NOT NULL COMMENT '是否删除',
+ PRIMARY KEY (`id`)
+);
+
+CREATE TABLE IF NOT EXISTS `role` (
+ `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
+ `role` varchar(64) NOT NULL COMMENT '角色',
+ `user_name` varchar(64) NOT NULL COMMENT '用户名',
+ `gmt_create` datetime NOT NULL COMMENT '创建时间',
+ `gmt_modified` datetime NOT NULL COMMENT '修改时间',
+ `del_flag` tinyint(1) NOT NULL COMMENT '是否删除',
+ PRIMARY KEY (`id`)
+);
+
+CREATE TABLE IF NOT EXISTS `permission` (
+ `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
+ `role` varchar(512) NOT NULL COMMENT '角色',
+ `resource` varchar(512) NOT NULL COMMENT '资源',
+ `action` varchar(8) NOT NULL COMMENT '读写权限',
+ `gmt_create` datetime NOT NULL COMMENT '创建时间',
+ `gmt_modified` datetime NOT NULL COMMENT '修改时间',
+ `del_flag` tinyint(1) NOT NULL COMMENT '是否删除',
+ PRIMARY KEY (`id`)
+);
+
+CREATE TABLE IF NOT EXISTS `notify` (
+ `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
+ `tenant_id` varchar(128) NOT NULL DEFAULT '' COMMENT '租户ID',
+ `item_id` varchar(128) NOT NULL COMMENT '项目ID',
+ `tp_id` varchar(128) NOT NULL COMMENT '线程池ID',
+ `platform` varchar(32) NOT NULL COMMENT '通知平台',
+ `type` varchar(32) NOT NULL COMMENT '通知类型',
+ `secret_key` varchar(256) NOT NULL COMMENT '密钥',
+ `interval` int(11) DEFAULT NULL COMMENT '报警间隔',
+ `receives` varchar(512) NOT NULL COMMENT '接收者',
+ `enable` tinyint(1) DEFAULT NULL COMMENT '是否启用',
+ `gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+ `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
+ `del_flag` tinyint(1) NOT NULL COMMENT '是否删除',
+ PRIMARY KEY (`id`)
+);
-/******************************************/
-/* 数据库全名 = hippo4j_manager */
-/* 表名称 = item */
-/******************************************/
-DROP TABLE IF EXISTS `item`, `item_info`;
-CREATE TABLE `item` (
- `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
- `tenant_id` varchar(128) DEFAULT NULL COMMENT '租户ID',
- `item_id` varchar(128) DEFAULT NULL COMMENT '项目ID',
- `item_name` varchar(128) DEFAULT NULL COMMENT '项目名称',
- `item_desc` varchar(256) DEFAULT NULL COMMENT '项目介绍',
- `owner` varchar(32) DEFAULT NULL COMMENT '负责人',
- `gmt_create` datetime DEFAULT NULL COMMENT '创建时间',
- `gmt_modified` datetime DEFAULT NULL COMMENT '修改时间',
- `del_flag` tinyint(1) DEFAULT NULL COMMENT '是否删除',
- PRIMARY KEY (`id`),
- UNIQUE KEY `item_id` (`id`),
- UNIQUE KEY `item_uk_iteminfo_tenantitem` (`tenant_id`,`item_id`,`del_flag`) USING BTREE
-) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='项目表';
-
-/******************************************/
-/* 数据库全名 = hippo4j_manager */
-/* 表名称 = config */
-/******************************************/
-DROP TABLE IF EXISTS `config`, `config_info`;
-CREATE TABLE `config` (
- `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
- `tenant_id` varchar(128) DEFAULT NULL COMMENT '租户ID',
- `item_id` varchar(256) DEFAULT NULL COMMENT '项目ID',
- `tp_id` varchar(56) DEFAULT NULL COMMENT '线程池ID',
- `tp_name` varchar(56) DEFAULT NULL COMMENT '线程池名称',
- `core_size` int(11) DEFAULT NULL COMMENT '核心线程数',
- `max_size` int(11) DEFAULT NULL COMMENT '最大线程数',
- `queue_type` int(11) DEFAULT NULL COMMENT '队列类型...',
- `capacity` int(11) DEFAULT NULL COMMENT '队列大小',
- `rejected_type` int(11) DEFAULT NULL COMMENT '拒绝策略',
- `keep_alive_time` int(11) DEFAULT NULL COMMENT '线程存活时间',
- `allow_core_thread_time_out` tinyint(1) DEFAULT NULL COMMENT '允许核心线程超时',
- `content` longtext COMMENT '线程池内容',
- `md5` varchar(32) NOT NULL COMMENT 'MD5',
- `is_alarm` tinyint(1) DEFAULT NULL COMMENT '是否报警',
- `capacity_alarm` int(11) DEFAULT NULL COMMENT '容量报警',
- `liveness_alarm` int(11) DEFAULT NULL COMMENT '活跃度报警',
- `gmt_create` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
- `gmt_modified` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
- `del_flag` tinyint(1) DEFAULT NULL COMMENT '是否删除',
- PRIMARY KEY (`id`),
- UNIQUE KEY `config_id` (`id`),
- UNIQUE KEY `config_uk_configinfo_datagrouptenant` (`tenant_id`,`item_id`,`tp_id`,`del_flag`) USING BTREE
-) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='线程池配置表';
-
-/******************************************/
-/* 数据库全名 = hippo4j_manager */
-/* 表名称 = inst_config */
-/******************************************/
-DROP TABLE IF EXISTS `inst_config`;
-CREATE TABLE `inst_config` (
- `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
- `tenant_id` varchar(128) DEFAULT NULL COMMENT '租户ID',
- `item_id` varchar(256) DEFAULT NULL COMMENT '项目ID',
- `tp_id` varchar(56) DEFAULT NULL COMMENT '线程池ID',
- `instance_id` varchar(256) DEFAULT NULL COMMENT '实例ID',
- `content` longtext COMMENT '线程池内容',
- `md5` varchar(32) NOT NULL COMMENT 'MD5',
- `gmt_create` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
- `gmt_modified` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
- PRIMARY KEY (`id`),
- UNIQUE KEY `inst_config_id` (`id`),
- KEY `idx_config_instance` (`tenant_id`,`item_id`,`tp_id`,`instance_id`) USING BTREE,
- KEY `idx_instance` (`instance_id`) USING BTREE
-) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='线程池配置实例表';
-
-/******************************************/
-/* 数据库全名 = hippo4j_manager */
-/* 表名称 = his_run_data */
-/******************************************/
-DROP TABLE IF EXISTS `his_run_data`;
-CREATE TABLE `his_run_data` (
- `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
- `tenant_id` varchar(128) DEFAULT NULL COMMENT '租户ID',
- `item_id` varchar(256) DEFAULT NULL COMMENT '项目ID',
- `tp_id` varchar(56) DEFAULT NULL COMMENT '线程池ID',
- `instance_id` varchar(256) DEFAULT NULL COMMENT '实例ID',
- `current_load` bigint(20) DEFAULT NULL COMMENT '当前负载',
- `peak_load` bigint(20) DEFAULT NULL COMMENT '峰值负载',
- `pool_size` bigint(20) DEFAULT NULL COMMENT '线程数',
- `active_size` bigint(20) DEFAULT NULL COMMENT '活跃线程数',
- `queue_capacity` bigint(20) DEFAULT NULL COMMENT '队列容量',
- `queue_size` bigint(20) DEFAULT NULL COMMENT '队列元素',
- `queue_remaining_capacity` bigint(20) DEFAULT NULL COMMENT '队列剩余容量',
- `completed_task_count` bigint(20) DEFAULT NULL COMMENT '已完成任务计数',
- `reject_count` bigint(20) DEFAULT NULL COMMENT '拒绝次数',
- `timestamp` bigint(20) DEFAULT NULL COMMENT '时间戳',
- `gmt_create` datetime DEFAULT NULL COMMENT '创建时间',
- `gmt_modified` datetime DEFAULT NULL COMMENT '修改时间',
- PRIMARY KEY (`id`),
- KEY `idx_group_key` (`tenant_id`,`item_id`,`tp_id`,`instance_id`) USING BTREE,
- KEY `idx_timestamp` (`timestamp`) USING BTREE
-) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='历史运行数据表';
-
-/******************************************/
-/* 数据库全名 = hippo4j_manager */
-/* 表名称 = log_record_info */
-/******************************************/
-DROP TABLE IF EXISTS `log_record_info`;
-CREATE TABLE `log_record_info` (
- `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
- `tenant` varchar(128) NOT NULL DEFAULT '' COMMENT '租户标识',
- `biz_key` varchar(128) NOT NULL DEFAULT '' COMMENT '日志业务标识',
- `biz_no` varchar(128) NOT NULL DEFAULT '' COMMENT '业务码标识',
- `operator` varchar(64) NOT NULL DEFAULT '' COMMENT '操作人',
- `action` varchar(128) NOT NULL DEFAULT '' COMMENT '动作',
- `category` varchar(128) NOT NULL DEFAULT '' COMMENT '种类',
- `detail` varchar(2048) NOT NULL DEFAULT '' COMMENT '修改的详细信息,可以为json',
- `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
- PRIMARY KEY (`id`),
- KEY `idx_biz_key` (`biz_key`)
-) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='操作日志表';
-
-/******************************************/
-/* 数据库全名 = hippo4j_manager */
-/* 表名称 = user */
-/******************************************/
-DROP TABLE IF EXISTS `user`;
-CREATE TABLE `user` (
- `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
- `user_name` varchar(64) NOT NULL COMMENT '用户名',
- `password` varchar(512) NOT NULL COMMENT '用户密码',
- `role` varchar(50) NOT NULL COMMENT '角色',
- `gmt_create` datetime NOT NULL COMMENT '创建时间',
- `gmt_modified` datetime NOT NULL COMMENT '修改时间',
- `del_flag` tinyint(1) NOT NULL COMMENT '是否删除',
- PRIMARY KEY (`id`)
-) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='用户表';
-
-/******************************************/
-/* 数据库全名 = hippo4j_manager */
-/* 表名称 = role */
-/******************************************/
-DROP TABLE IF EXISTS `role`;
-CREATE TABLE `role` (
- `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
- `role` varchar(64) NOT NULL COMMENT '角色',
- `user_name` varchar(64) NOT NULL COMMENT '用户名',
- `gmt_create` datetime NOT NULL COMMENT '创建时间',
- `gmt_modified` datetime NOT NULL COMMENT '修改时间',
- `del_flag` tinyint(1) NOT NULL COMMENT '是否删除',
- PRIMARY KEY (`id`)
-) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='角色表';
-
-/******************************************/
-/* 数据库全名 = hippo4j_manager */
-/* 表名称 = permission */
-/******************************************/
-DROP TABLE IF EXISTS `permission`;
-CREATE TABLE `permission` (
- `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
- `role` varchar(512) NOT NULL COMMENT '角色',
- `resource` varchar(512) NOT NULL COMMENT '资源',
- `action` varchar(8) NOT NULL COMMENT '读写权限',
- `gmt_create` datetime NOT NULL COMMENT '创建时间',
- `gmt_modified` datetime NOT NULL COMMENT '修改时间',
- `del_flag` tinyint(1) NOT NULL COMMENT '是否删除',
- PRIMARY KEY (`id`)
-) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='权限表';
-
-/******************************************/
-/* 数据库全名 = hippo4j_manager */
-/* 表名称 = notify */
-/******************************************/
-DROP TABLE IF EXISTS `alarm`, `notify`;
-CREATE TABLE `notify` (
- `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
- `tenant_id` varchar(128) NOT NULL DEFAULT '' COMMENT '租户ID',
- `item_id` varchar(128) NOT NULL COMMENT '项目ID',
- `tp_id` varchar(128) NOT NULL COMMENT '线程池ID',
- `platform` varchar(32) NOT NULL COMMENT '通知平台',
- `type` varchar(32) NOT NULL COMMENT '通知类型',
- `secret_key` varchar(256) NOT NULL COMMENT '密钥',
- `interval` int(11) DEFAULT NULL COMMENT '报警间隔',
- `receives` varchar(512) NOT NULL COMMENT '接收者',
- `enable` tinyint(1) DEFAULT NULL COMMENT '是否启用',
- `gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
- `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
- `del_flag` tinyint(1) NOT NULL COMMENT '是否删除',
- PRIMARY KEY (`id`),
- UNIQUE KEY `notify_uk_notify_biz_key` (`tenant_id`,`item_id`,`tp_id`,`platform`,`type`,`del_flag`) USING BTREE
-) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='通知表';
-
-/* 租户 */
INSERT INTO `tenant` (`id`, `tenant_id`, `tenant_name`, `tenant_desc`, `owner`, `gmt_create`, `gmt_modified`, `del_flag`) VALUES ('1', 'prescription', '处方组', '负责维护处方服务, 包括不限于电子处方等业务', '谢良辰', '2021-10-24 13:42:11', '2021-10-24 13:42:11', '0');
-/* 项目 */
INSERT INTO `item` (`id`, `tenant_id`, `item_id`, `item_name`, `item_desc`, `owner`, `gmt_create`, `gmt_modified`, `del_flag`) VALUES ('1', 'prescription', 'dynamic-threadpool-example', '动态线程池示例项目', '动态线程池示例项目,对应 Hippo 项目的 example 模块', '马称', '2021-10-24 16:11:00', '2021-10-24 16:11:00', '0');
-/* 线程池 */
-INSERT INTO `config` (`id`, `tenant_id`, `item_id`, `tp_id`, `tp_name`, `core_size`, `max_size`, `queue_type`, `capacity`, `rejected_type`, `keep_alive_time`, `allow_core_thread_time_out`, `content`, `md5`, `is_alarm`, `capacity_alarm`, `liveness_alarm`, `gmt_create`, `gmt_modified`, `del_flag`) VALUES ('1', 'prescription', 'dynamic-threadpool-example', 'message-consume', '示例消费者线程池', '5', '10', '9', '1024', '2', '9999', '0', '{\"tenantId\":\"prescription\",\"itemId\":\"dynamic-threadpool-example\",\"tpId\":\"message-consume\",\"coreSize\":5,\"maxSize\":10,\"queueType\":9,\"capacity\":1024,\"keepAliveTime\":9999,\"rejectedType\":2,\"isAlarm\":0,\"capacityAlarm\":80,\"livenessAlarm\":80,\"allowCoreThreadTimeOut\":0}', 'f80ea89044889fb6cec20e1a517f2ec3', '0', '80', '80', '2021-10-24 10:24:00', '2021-12-22 08:58:55', '0'),
- ('2', 'prescription', 'dynamic-threadpool-example', 'message-produce', '示例生产者线程池', '5', '15', '9', '1024', '1', '9999', '0', '{\"tenantId\":\"prescription\",\"itemId\":\"dynamic-threadpool-example\",\"tpId\":\"message-produce\",\"coreSize\":5,\"maxSize\":15,\"queueType\":9,\"capacity\":1024,\"keepAliveTime\":9999,\"rejectedType\":1,\"isAlarm\":0,\"capacityAlarm\":30,\"livenessAlarm\":30,\"allowCoreThreadTimeOut\":0}', '525e1429468bcfe98df7e70a75710051', '0', '30', '30', '2021-10-24 10:24:00', '2021-12-22 08:59:02', '0');
+INSERT INTO `config` (`id`, `tenant_id`, `item_id`, `tp_id`, `tp_name`, `core_size`, `max_size`, `queue_type`, `capacity`, `rejected_type`, `keep_alive_time`, `allow_core_thread_time_out`, `content`, `md5`, `is_alarm`, `capacity_alarm`, `liveness_alarm`, `gmt_create`, `gmt_modified`, `del_flag`) VALUES ('1', 'prescription', 'dynamic-threadpool-example', 'message-consume', '示例消费者线程池', '5', '10', '9', '1024', '2', '9999', '0', '{\"tenantId\":\"prescription\",\"itemId\":\"dynamic-threadpool-example\",\"tpId\":\"message-consume\",\"coreSize\":5,\"maxSize\":10,\"queueType\":9,\"capacity\":1024,\"keepAliveTime\":9999,\"rejectedType\":2,\"isAlarm\":0,\"capacityAlarm\":80,\"livenessAlarm\":80,\"allowCoreThreadTimeOut\":0}', 'f80ea89044889fb6cec20e1a517f2ec3', '0', '80', '80', '2021-10-24 10:24:00', '2021-12-22 08:58:55', '0'), ('2', 'prescription', 'dynamic-threadpool-example', 'message-produce', '示例生产者线程池', '5', '15', '9', '1024', '1', '9999', '0', '{\"tenantId\":\"prescription\",\"itemId\":\"dynamic-threadpool-example\",\"tpId\":\"message-produce\",\"coreSize\":5,\"maxSize\":15,\"queueType\":9,\"capacity\":1024,\"keepAliveTime\":9999,\"rejectedType\":1,\"isAlarm\":0,\"capacityAlarm\":30,\"livenessAlarm\":30,\"allowCoreThreadTimeOut\":0}', '525e1429468bcfe98df7e70a75710051', '0', '30', '30', '2021-10-24 10:24:00', '2021-12-22 08:59:02', '0');
-/* 用户 */
INSERT INTO `user` (`id`, `user_name`, `password`, `role`, `gmt_create`, `gmt_modified`, `del_flag`) VALUES ('1', 'admin', '$2a$10$2KCqRbra0Yn2TwvkZxtfLuWuUP5KyCWsljO/ci5pLD27pqR3TV1vy', 'ROLE_ADMIN', '2021-11-04 21:35:17', '2021-11-15 23:04:59', '0');
-/* 通知表 */
-INSERT INTO `notify` (`id`, `tenant_id`, `item_id`, `tp_id`, `platform`, `type`, `secret_key`, `interval`, `receives`, `enable`, `gmt_create`, `gmt_modified`, `del_flag`) VALUES ('1', 'prescription', 'dynamic-threadpool-example', 'message-produce', 'DING', 'CONFIG', '4a582a588a161d6e3a1bd1de7eea9ee9f562cdfcbe56b6e72029e7fd512b2eae', NULL, '15601166691', '0', '2021-11-18 22:49:50', '2021-11-18 22:49:50', '0'),
- ('2', 'prescription', 'dynamic-threadpool-example', 'message-produce', 'DING', 'ALARM', '4a582a588a161d6e3a1bd1de7eea9ee9f562cdfcbe56b6e72029e7fd512b2eae', '30', '15601166691', '0', '2021-11-18 22:50:06', '2021-11-18 22:50:06', '0');
-
-/* 1.1.0 Upgrade Start */
-ALTER TABLE `config` DROP INDEX `config_uk_configinfo_datagrouptenant`;
-ALTER TABLE `item` DROP INDEX `item_uk_iteminfo_tenantitem`;
-ALTER TABLE `tenant` DROP INDEX `uk_tenantinfo_tenantid`;
-/* 1.1.0 Upgrade End */
-
-/* 1.4.0 Upgrade Start */
-ALTER TABLE config Modify COLUMN keep_alive_time int(11) COMMENT '线程存活时间(秒)';
-ALTER TABLE config Add execute_time_out int(11) COMMENT '执行超时时间(毫秒)' AFTER keep_alive_time;
-/* 1.4.0 Upgrade Start */
+INSERT INTO `notify` (`id`, `tenant_id`, `item_id`, `tp_id`, `platform`, `type`, `secret_key`, `interval`, `receives`, `enable`, `gmt_create`, `gmt_modified`, `del_flag`) VALUES ('1', 'prescription', 'dynamic-threadpool-example', 'message-produce', 'DING', 'CONFIG', '4a582a588a161d6e3a1bd1de7eea9ee9f562cdfcbe56b6e72029e7fd512b2eae', NULL, '15601166691', '0', '2021-11-18 22:49:50', '2021-11-18 22:49:50', '0'), ('2', 'prescription', 'dynamic-threadpool-example', 'message-produce', 'DING', 'ALARM', '4a582a588a161d6e3a1bd1de7eea9ee9f562cdfcbe56b6e72029e7fd512b2eae', '30', '15601166691', '0', '2021-11-18 22:50:06', '2021-11-18 22:50:06', '0');
diff --git a/hippo4j-server/src/main/resources/sql-script/mysql/hippo4j_manager.sql b/hippo4j-server/src/main/resources/sql-script/mysql/hippo4j_manager.sql
new file mode 100644
index 00000000..348dc009
--- /dev/null
+++ b/hippo4j-server/src/main/resources/sql-script/mysql/hippo4j_manager.sql
@@ -0,0 +1,214 @@
+CREATE DATABASE /*!32312 IF NOT EXISTS*/ `hippo4j_manager` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_bin */;
+
+USE `hippo4j_manager`;
+
+/******************************************/
+/* 数据库全名 = hippo4j_manager */
+/* 表名称 = tenant */
+/******************************************/
+CREATE TABLE IF NOT EXISTS `tenant` (
+ `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
+ `tenant_id` varchar(128) DEFAULT NULL COMMENT '租户ID',
+ `tenant_name` varchar(128) DEFAULT NULL COMMENT '租户名称',
+ `tenant_desc` varchar(256) DEFAULT NULL COMMENT '租户介绍',
+ `owner` varchar(32) DEFAULT '-' COMMENT '负责人',
+ `gmt_create` datetime DEFAULT NULL COMMENT '创建时间',
+ `gmt_modified` datetime DEFAULT NULL COMMENT '修改时间',
+ `del_flag` tinyint(1) DEFAULT NULL COMMENT '是否删除',
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `id` (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='租户表';
+
+/******************************************/
+/* 数据库全名 = hippo4j_manager */
+/* 表名称 = item */
+/******************************************/
+CREATE TABLE IF NOT EXISTS `item` (
+ `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
+ `tenant_id` varchar(128) DEFAULT NULL COMMENT '租户ID',
+ `item_id` varchar(128) DEFAULT NULL COMMENT '项目ID',
+ `item_name` varchar(128) DEFAULT NULL COMMENT '项目名称',
+ `item_desc` varchar(256) DEFAULT NULL COMMENT '项目介绍',
+ `owner` varchar(32) DEFAULT NULL COMMENT '负责人',
+ `gmt_create` datetime DEFAULT NULL COMMENT '创建时间',
+ `gmt_modified` datetime DEFAULT NULL COMMENT '修改时间',
+ `del_flag` tinyint(1) DEFAULT NULL COMMENT '是否删除',
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `id` (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='项目表';
+
+/******************************************/
+/* 数据库全名 = hippo4j_manager */
+/* 表名称 = config */
+/******************************************/
+CREATE TABLE IF NOT EXISTS `config` (
+ `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
+ `tenant_id` varchar(128) DEFAULT NULL COMMENT '租户ID',
+ `item_id` varchar(256) DEFAULT NULL COMMENT '项目ID',
+ `tp_id` varchar(56) DEFAULT NULL COMMENT '线程池ID',
+ `tp_name` varchar(56) DEFAULT NULL COMMENT '线程池名称',
+ `core_size` int(11) DEFAULT NULL COMMENT '核心线程数',
+ `max_size` int(11) DEFAULT NULL COMMENT '最大线程数',
+ `queue_type` int(11) DEFAULT NULL COMMENT '队列类型...',
+ `capacity` int(11) DEFAULT NULL COMMENT '队列大小',
+ `rejected_type` int(11) DEFAULT NULL COMMENT '拒绝策略',
+ `keep_alive_time` int(11) DEFAULT NULL COMMENT '线程存活时间(秒)',
+ `execute_time_out` int(11) DEFAULT NULL COMMENT '执行超时时间(毫秒)',
+ `allow_core_thread_time_out` tinyint(1) DEFAULT NULL COMMENT '允许核心线程超时',
+ `content` longtext COMMENT '线程池内容',
+ `md5` varchar(32) NOT NULL COMMENT 'MD5',
+ `is_alarm` tinyint(1) DEFAULT NULL COMMENT '是否报警',
+ `capacity_alarm` int(11) DEFAULT NULL COMMENT '容量报警',
+ `liveness_alarm` int(11) DEFAULT NULL COMMENT '活跃度报警',
+ `gmt_create` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+ `gmt_modified` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
+ `del_flag` tinyint(1) DEFAULT NULL COMMENT '是否删除',
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `id` (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='线程池配置表';
+
+/******************************************/
+/* 数据库全名 = hippo4j_manager */
+/* 表名称 = inst_config */
+/******************************************/
+CREATE TABLE IF NOT EXISTS `inst_config` (
+ `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
+ `tenant_id` varchar(128) DEFAULT NULL COMMENT '租户ID',
+ `item_id` varchar(256) DEFAULT NULL COMMENT '项目ID',
+ `tp_id` varchar(56) DEFAULT NULL COMMENT '线程池ID',
+ `instance_id` varchar(256) DEFAULT NULL COMMENT '实例ID',
+ `content` longtext COMMENT '线程池内容',
+ `md5` varchar(32) NOT NULL COMMENT 'MD5',
+ `gmt_create` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+ `gmt_modified` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `id` (`id`),
+ KEY `idx_config_instance` (`tenant_id`,`item_id`,`tp_id`,`instance_id`) USING BTREE,
+ KEY `idx_instance` (`instance_id`) USING BTREE
+) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='线程池配置实例表';
+
+/******************************************/
+/* 数据库全名 = hippo4j_manager */
+/* 表名称 = his_run_data */
+/******************************************/
+CREATE TABLE IF NOT EXISTS `his_run_data` (
+ `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
+ `tenant_id` varchar(128) DEFAULT NULL COMMENT '租户ID',
+ `item_id` varchar(256) DEFAULT NULL COMMENT '项目ID',
+ `tp_id` varchar(56) DEFAULT NULL COMMENT '线程池ID',
+ `instance_id` varchar(256) DEFAULT NULL COMMENT '实例ID',
+ `current_load` bigint(20) DEFAULT NULL COMMENT '当前负载',
+ `peak_load` bigint(20) DEFAULT NULL COMMENT '峰值负载',
+ `pool_size` bigint(20) DEFAULT NULL COMMENT '线程数',
+ `active_size` bigint(20) DEFAULT NULL COMMENT '活跃线程数',
+ `queue_capacity` bigint(20) DEFAULT NULL COMMENT '队列容量',
+ `queue_size` bigint(20) DEFAULT NULL COMMENT '队列元素',
+ `queue_remaining_capacity` bigint(20) DEFAULT NULL COMMENT '队列剩余容量',
+ `completed_task_count` bigint(20) DEFAULT NULL COMMENT '已完成任务计数',
+ `reject_count` bigint(20) DEFAULT NULL COMMENT '拒绝次数',
+ `timestamp` bigint(20) DEFAULT NULL COMMENT '时间戳',
+ `gmt_create` datetime DEFAULT NULL COMMENT '创建时间',
+ `gmt_modified` datetime DEFAULT NULL COMMENT '修改时间',
+ PRIMARY KEY (`id`),
+ KEY `idx_group_key` (`tenant_id`,`item_id`,`tp_id`,`instance_id`) USING BTREE,
+ KEY `idx_timestamp` (`timestamp`) USING BTREE
+) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='历史运行数据表';
+
+/******************************************/
+/* 数据库全名 = hippo4j_manager */
+/* 表名称 = log_record_info */
+/******************************************/
+CREATE TABLE IF NOT EXISTS `log_record_info` (
+ `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
+ `tenant` varchar(128) NOT NULL DEFAULT '' COMMENT '租户标识',
+ `biz_key` varchar(128) NOT NULL DEFAULT '' COMMENT '日志业务标识',
+ `biz_no` varchar(128) NOT NULL DEFAULT '' COMMENT '业务码标识',
+ `operator` varchar(64) NOT NULL DEFAULT '' COMMENT '操作人',
+ `action` varchar(128) NOT NULL DEFAULT '' COMMENT '动作',
+ `category` varchar(128) NOT NULL DEFAULT '' COMMENT '种类',
+ `detail` varchar(2048) NOT NULL DEFAULT '' COMMENT '修改的详细信息,可以为json',
+ `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+ PRIMARY KEY (`id`),
+ KEY `idx_biz_key` (`biz_key`)
+) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='操作日志表';
+
+/******************************************/
+/* 数据库全名 = hippo4j_manager */
+/* 表名称 = user */
+/******************************************/
+CREATE TABLE IF NOT EXISTS `user` (
+ `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
+ `user_name` varchar(64) NOT NULL COMMENT '用户名',
+ `password` varchar(512) NOT NULL COMMENT '用户密码',
+ `role` varchar(50) NOT NULL COMMENT '角色',
+ `gmt_create` datetime NOT NULL COMMENT '创建时间',
+ `gmt_modified` datetime NOT NULL COMMENT '修改时间',
+ `del_flag` tinyint(1) NOT NULL COMMENT '是否删除',
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='用户表';
+
+/******************************************/
+/* 数据库全名 = hippo4j_manager */
+/* 表名称 = role */
+/******************************************/
+CREATE TABLE IF NOT EXISTS `role` (
+ `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
+ `role` varchar(64) NOT NULL COMMENT '角色',
+ `user_name` varchar(64) NOT NULL COMMENT '用户名',
+ `gmt_create` datetime NOT NULL COMMENT '创建时间',
+ `gmt_modified` datetime NOT NULL COMMENT '修改时间',
+ `del_flag` tinyint(1) NOT NULL COMMENT '是否删除',
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='角色表';
+
+/******************************************/
+/* 数据库全名 = hippo4j_manager */
+/* 表名称 = permission */
+/******************************************/
+CREATE TABLE IF NOT EXISTS `permission` (
+ `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
+ `role` varchar(512) NOT NULL COMMENT '角色',
+ `resource` varchar(512) NOT NULL COMMENT '资源',
+ `action` varchar(8) NOT NULL COMMENT '读写权限',
+ `gmt_create` datetime NOT NULL COMMENT '创建时间',
+ `gmt_modified` datetime NOT NULL COMMENT '修改时间',
+ `del_flag` tinyint(1) NOT NULL COMMENT '是否删除',
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='权限表';
+
+/******************************************/
+/* 数据库全名 = hippo4j_manager */
+/* 表名称 = notify */
+/******************************************/
+CREATE TABLE IF NOT EXISTS `notify` (
+ `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
+ `tenant_id` varchar(128) NOT NULL DEFAULT '' COMMENT '租户ID',
+ `item_id` varchar(128) NOT NULL COMMENT '项目ID',
+ `tp_id` varchar(128) NOT NULL COMMENT '线程池ID',
+ `platform` varchar(32) NOT NULL COMMENT '通知平台',
+ `type` varchar(32) NOT NULL COMMENT '通知类型',
+ `secret_key` varchar(256) NOT NULL COMMENT '密钥',
+ `interval` int(11) DEFAULT NULL COMMENT '报警间隔',
+ `receives` varchar(512) NOT NULL COMMENT '接收者',
+ `enable` tinyint(1) DEFAULT NULL COMMENT '是否启用',
+ `gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+ `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
+ `del_flag` tinyint(1) NOT NULL COMMENT '是否删除',
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `uk_notify_biz_key` (`tenant_id`,`item_id`,`tp_id`,`platform`,`type`,`del_flag`) USING BTREE
+) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='通知表';
+
+/* 租户 */
+INSERT IGNORE INTO `tenant` (`id`, `tenant_id`, `tenant_name`, `tenant_desc`, `owner`, `gmt_create`, `gmt_modified`, `del_flag`) VALUES ('1', 'prescription', '处方组', '负责维护处方服务, 包括不限于电子处方等业务', '谢良辰', '2021-10-24 13:42:11', '2021-10-24 13:42:11', '0');
+
+/* 项目 */
+INSERT IGNORE INTO `item` (`id`, `tenant_id`, `item_id`, `item_name`, `item_desc`, `owner`, `gmt_create`, `gmt_modified`, `del_flag`) VALUES ('1', 'prescription', 'dynamic-threadpool-example', '动态线程池示例项目', '动态线程池示例项目,对应 Hippo 项目的 example 模块', '马称', '2021-10-24 16:11:00', '2021-10-24 16:11:00', '0');
+
+/* 线程池 */
+INSERT IGNORE INTO `config` (`id`, `tenant_id`, `item_id`, `tp_id`, `tp_name`, `core_size`, `max_size`, `queue_type`, `capacity`, `rejected_type`, `keep_alive_time`, `allow_core_thread_time_out`, `content`, `md5`, `is_alarm`, `capacity_alarm`, `liveness_alarm`, `gmt_create`, `gmt_modified`, `del_flag`) VALUES ('1', 'prescription', 'dynamic-threadpool-example', 'message-consume', '示例消费者线程池', '5', '10', '9', '1024', '2', '9999', '0', '{\"tenantId\":\"prescription\",\"itemId\":\"dynamic-threadpool-example\",\"tpId\":\"message-consume\",\"coreSize\":5,\"maxSize\":10,\"queueType\":9,\"capacity\":1024,\"keepAliveTime\":9999,\"rejectedType\":2,\"isAlarm\":0,\"capacityAlarm\":80,\"livenessAlarm\":80,\"allowCoreThreadTimeOut\":0}', 'f80ea89044889fb6cec20e1a517f2ec3', '0', '80', '80', '2021-10-24 10:24:00', '2021-12-22 08:58:55', '0'), ('2', 'prescription', 'dynamic-threadpool-example', 'message-produce', '示例生产者线程池', '5', '15', '9', '1024', '1', '9999', '0', '{\"tenantId\":\"prescription\",\"itemId\":\"dynamic-threadpool-example\",\"tpId\":\"message-produce\",\"coreSize\":5,\"maxSize\":15,\"queueType\":9,\"capacity\":1024,\"keepAliveTime\":9999,\"rejectedType\":1,\"isAlarm\":0,\"capacityAlarm\":30,\"livenessAlarm\":30,\"allowCoreThreadTimeOut\":0}', '525e1429468bcfe98df7e70a75710051', '0', '30', '30', '2021-10-24 10:24:00', '2021-12-22 08:59:02', '0');
+
+/* 用户 */
+INSERT IGNORE INTO `user` (`id`, `user_name`, `password`, `role`, `gmt_create`, `gmt_modified`, `del_flag`) VALUES ('1', 'admin', '$2a$10$2KCqRbra0Yn2TwvkZxtfLuWuUP5KyCWsljO/ci5pLD27pqR3TV1vy', 'ROLE_ADMIN', '2021-11-04 21:35:17', '2021-11-15 23:04:59', '0');
+
+/* 通知表 */
+INSERT IGNORE INTO `notify` (`id`, `tenant_id`, `item_id`, `tp_id`, `platform`, `type`, `secret_key`, `interval`, `receives`, `enable`, `gmt_create`, `gmt_modified`, `del_flag`) VALUES ('1', 'prescription', 'dynamic-threadpool-example', 'message-produce', 'DING', 'CONFIG', '4a582a588a161d6e3a1bd1de7eea9ee9f562cdfcbe56b6e72029e7fd512b2eae', NULL, '15601166691', '0', '2021-11-18 22:49:50', '2021-11-18 22:49:50', '0'), ('2', 'prescription', 'dynamic-threadpool-example', 'message-produce', 'DING', 'ALARM', '4a582a588a161d6e3a1bd1de7eea9ee9f562cdfcbe56b6e72029e7fd512b2eae', '30', '15601166691', '0', '2021-11-18 22:50:06', '2021-11-18 22:50:06', '0');
diff --git a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/AdapterExecutorProperties.java b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/AdapterExecutorProperties.java
index 6ff8c9e0..c46d8934 100644
--- a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/AdapterExecutorProperties.java
+++ b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/AdapterExecutorProperties.java
@@ -49,4 +49,9 @@ public class AdapterExecutorProperties {
* Nodes, application startup is not affect, change properties is effect
*/
private String nodes;
+
+ /**
+ * these propertied is enabled?
+ */
+ private Boolean enable = true;
}
diff --git a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/WebThreadPoolProperties.java b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/WebThreadPoolProperties.java
index b7cb737c..f2d1ff02 100644
--- a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/WebThreadPoolProperties.java
+++ b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/WebThreadPoolProperties.java
@@ -44,4 +44,9 @@ public class WebThreadPoolProperties {
* Nodes, application startup is not affect, change properties is effect
*/
private String nodes;
+
+ /**
+ * these propertied is enabled?
+ */
+ private Boolean enable = true;
}
diff --git a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/AbstractConfigThreadPoolDynamicRefresh.java b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/AbstractConfigThreadPoolDynamicRefresh.java
index bf545487..ba5933fc 100644
--- a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/AbstractConfigThreadPoolDynamicRefresh.java
+++ b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/AbstractConfigThreadPoolDynamicRefresh.java
@@ -18,6 +18,7 @@
package cn.hippo4j.config.springboot.starter.refresher;
import cn.hippo4j.common.api.ThreadPoolDynamicRefresh;
+import cn.hippo4j.common.api.ThreadPoolInitRefresh;
import cn.hippo4j.common.config.ApplicationContextHolder;
import cn.hippo4j.common.toolkit.CollectionUtil;
import cn.hippo4j.config.springboot.starter.config.BootstrapConfigProperties;
@@ -37,7 +38,11 @@ import java.util.concurrent.ExecutorService;
*/
@Slf4j
@RequiredArgsConstructor
-public abstract class AbstractConfigThreadPoolDynamicRefresh implements ThreadPoolDynamicRefresh, InitializingBean {
+public abstract class AbstractConfigThreadPoolDynamicRefresh
+ implements
+ ThreadPoolDynamicRefresh,
+ ThreadPoolInitRefresh,
+ InitializingBean {
protected final BootstrapConfigProperties bootstrapConfigProperties;
@@ -47,6 +52,11 @@ public abstract class AbstractConfigThreadPoolDynamicRefresh implements ThreadPo
bootstrapConfigProperties = ApplicationContextHolder.getBean(BootstrapConfigProperties.class);
}
+ @Override
+ public void initRefresh(String context) {
+ dynamicRefresh(context);
+ }
+
@Override
public void dynamicRefresh(String configContent) {
dynamicRefresh(configContent, null);
diff --git a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/ApolloRefresherHandler.java b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/ApolloRefresherHandler.java
index bc4ce2e2..90425870 100644
--- a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/ApolloRefresherHandler.java
+++ b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/ApolloRefresherHandler.java
@@ -41,6 +41,16 @@ public class ApolloRefresherHandler extends AbstractConfigThreadPoolDynamicRefre
@Value(APOLLO_PROPERTY)
private String namespace;
+ @Override
+ public String getProperties() {
+ String[] apolloNamespaces = this.namespace.split(",");
+ this.namespace = apolloNamespaces[0];
+ String copyNamespace = this.namespace.replaceAll("." + bootstrapConfigProperties.getConfigFileType().getValue(), "");
+ ConfigFileFormat configFileFormat = ConfigFileFormat.fromString(bootstrapConfigProperties.getConfigFileType().getValue());
+ ConfigFile configFile = ConfigService.getConfigFile(copyNamespace, configFileFormat);
+ return configFile.getContent();
+ }
+
@Override
public void afterPropertiesSet() {
String[] apolloNamespaces = this.namespace.split(",");
diff --git a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/EtcdRefresherHandler.java b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/EtcdRefresherHandler.java
index 30df2d14..5f0cbe25 100644
--- a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/EtcdRefresherHandler.java
+++ b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/EtcdRefresherHandler.java
@@ -52,22 +52,25 @@ public class EtcdRefresherHandler extends AbstractConfigThreadPoolDynamicRefresh
private static final String KEY = "key";
+ @Override
+ public String getProperties() throws Exception {
+ Map etcd = bootstrapConfigProperties.getEtcd();
+ Charset charset = StringUtil.isBlank(etcd.get(CHARSET)) ? StandardCharsets.UTF_8 : Charset.forName(etcd.get(CHARSET));
+ initClient(etcd, charset);
+
+ String key = etcd.get(KEY);
+ GetResponse getResponse = client.getKVClient().get(ByteSequence.from(key, charset)).get();
+ KeyValue keyValue = getResponse.getKvs().get(0);
+ return Objects.isNull(keyValue) ? null : keyValue.getValue().toString(charset);
+ }
+
@Override
public void afterPropertiesSet() throws Exception {
Map etcd = bootstrapConfigProperties.getEtcd();
- String user = etcd.get(USER);
- String password = etcd.get(PASSWORD);
- String endpoints = etcd.get(ENDPOINTS);
- String authority = etcd.get(AUTHORITY);
String key = etcd.get(KEY);
Charset charset = StringUtil.isBlank(etcd.get(CHARSET)) ? StandardCharsets.UTF_8 : Charset.forName(etcd.get(CHARSET));
- ClientBuilder clientBuilder = Client.builder().endpoints(endpoints.split(","));
- // todo
- if (Objects.isNull(client)) {
- client = StringUtil.isAllNotEmpty(user, password) ? clientBuilder.user(ByteSequence.from(user, charset))
- .password(ByteSequence.from(password, charset)).authority(authority)
- .build() : clientBuilder.build();
- }
+ initClient(etcd, charset);
+
// todo Currently only supports json
GetResponse getResponse = client.getKVClient().get(ByteSequence.from(key, charset)).get();
KeyValue keyValue = getResponse.getKvs().get(0);
@@ -100,4 +103,25 @@ public class EtcdRefresherHandler extends AbstractConfigThreadPoolDynamicRefresh
}
});
}
+
+ /**
+ * if client is null, init it
+ *
+ * @param etcd etcd configuration item
+ * @param charset charset
+ */
+ private void initClient(Map etcd, Charset charset) {
+ // todo
+ if (Objects.isNull(client)) {
+ String user = etcd.get(USER);
+ String password = etcd.get(PASSWORD);
+ String authority = etcd.get(AUTHORITY);
+ String endpoints = etcd.get(ENDPOINTS);
+ ClientBuilder clientBuilder = Client.builder().endpoints(endpoints.split(","));
+ client = StringUtil.isAllNotEmpty(user, password) ? clientBuilder.user(ByteSequence.from(user, charset))
+ .password(ByteSequence.from(password, charset)).authority(authority)
+ .build() : clientBuilder.build();
+ }
+ }
+
}
\ No newline at end of file
diff --git a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/NacosCloudRefresherHandler.java b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/NacosCloudRefresherHandler.java
index 4433cfa4..6f328b1f 100644
--- a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/NacosCloudRefresherHandler.java
+++ b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/NacosCloudRefresherHandler.java
@@ -31,17 +31,28 @@ import java.util.concurrent.Executor;
@Slf4j
public class NacosCloudRefresherHandler extends AbstractConfigThreadPoolDynamicRefresh {
+ static final String DATA_ID = "data-id";
+ static final String GROUP = "group";
+
private final NacosConfigManager nacosConfigManager;
public NacosCloudRefresherHandler() {
nacosConfigManager = ApplicationContextHolder.getBean(NacosConfigManager.class);
}
+ @Override
+ public String getProperties() throws Exception {
+ Map nacosConfig = bootstrapConfigProperties.getNacos();
+ String dataId = nacosConfig.get(DATA_ID);
+ String group = nacosConfig.get(GROUP);
+ return nacosConfigManager.getConfigService().getConfig(dataId, group, 5000L);
+ }
+
@Override
public void afterPropertiesSet() throws Exception {
Map nacosConfig = bootstrapConfigProperties.getNacos();
- nacosConfigManager.getConfigService().addListener(nacosConfig.get("data-id"),
- nacosConfig.get("group"), new Listener() {
+ nacosConfigManager.getConfigService().addListener(nacosConfig.get(DATA_ID),
+ nacosConfig.get(GROUP), new Listener() {
@Override
public Executor getExecutor() {
@@ -53,6 +64,6 @@ public class NacosCloudRefresherHandler extends AbstractConfigThreadPoolDynamicR
dynamicRefresh(configInfo);
}
});
- log.info("Dynamic thread pool refresher, add nacos cloud listener success. data-id: {}, group: {}", nacosConfig.get("data-id"), nacosConfig.get("group"));
+ log.info("Dynamic thread pool refresher, add nacos cloud listener success. data-id: {}, group: {}", nacosConfig.get(DATA_ID), nacosConfig.get(GROUP));
}
}
diff --git a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/NacosRefresherHandler.java b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/NacosRefresherHandler.java
index fa5f7e91..ad052018 100644
--- a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/NacosRefresherHandler.java
+++ b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/NacosRefresherHandler.java
@@ -32,6 +32,9 @@ import java.util.concurrent.Executor;
@Slf4j
public class NacosRefresherHandler extends AbstractConfigThreadPoolDynamicRefresh {
+ static final String DATA_ID = "data-id";
+ static final String GROUP = "group";
+
@NacosInjected
private ConfigService configService;
@@ -39,11 +42,19 @@ public class NacosRefresherHandler extends AbstractConfigThreadPoolDynamicRefres
super(bootstrapConfigProperties);
}
+ @Override
+ public String getProperties() throws Exception {
+ Map nacosConfig = bootstrapConfigProperties.getNacos();
+ String dataId = nacosConfig.get(DATA_ID);
+ String group = nacosConfig.get(GROUP);
+ return configService.getConfig(dataId, group, Long.MAX_VALUE);
+ }
+
@Override
public void afterPropertiesSet() throws Exception {
Map nacosConfig = bootstrapConfigProperties.getNacos();
- configService.addListener(nacosConfig.get("data-id"), nacosConfig.get("group"),
+ configService.addListener(nacosConfig.get(DATA_ID), nacosConfig.get(GROUP),
new Listener() {
@Override
@@ -56,6 +67,6 @@ public class NacosRefresherHandler extends AbstractConfigThreadPoolDynamicRefres
dynamicRefresh(configInfo);
}
});
- log.info("Dynamic thread pool refresher, add nacos listener success. data-id: {}, group: {}", nacosConfig.get("data-id"), nacosConfig.get("group"));
+ log.info("Dynamic thread pool refresher, add nacos listener success. data-id: {}, group: {}", nacosConfig.get(DATA_ID), nacosConfig.get(GROUP));
}
}
diff --git a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/ZookeeperRefresherHandler.java b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/ZookeeperRefresherHandler.java
index 479bba79..fe886001 100644
--- a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/ZookeeperRefresherHandler.java
+++ b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/ZookeeperRefresherHandler.java
@@ -41,15 +41,31 @@ import java.util.Map;
@Slf4j
public class ZookeeperRefresherHandler extends AbstractConfigThreadPoolDynamicRefresh {
+ static final String ZK_CONNECT_STR = "zk-connect-str";
+
+ static final String ROOT_NODE = "root-node";
+
+ static final String CONFIG_VERSION = "config-version";
+
+ static final String NODE = "node";
+
private CuratorFramework curatorFramework;
+ @Override
+ public String getProperties() {
+ Map zkConfigs = bootstrapConfigProperties.getZookeeper();
+ String nodePath = ZKPaths.makePath(ZKPaths.makePath(zkConfigs.get(ROOT_NODE),
+ zkConfigs.get(CONFIG_VERSION)), zkConfigs.get(NODE));
+ return nodePathResolver(nodePath);
+ }
+
@Override
public void afterPropertiesSet() {
Map zkConfigs = bootstrapConfigProperties.getZookeeper();
- curatorFramework = CuratorFrameworkFactory.newClient(zkConfigs.get("zk-connect-str"),
+ curatorFramework = CuratorFrameworkFactory.newClient(zkConfigs.get(ZK_CONNECT_STR),
new ExponentialBackoffRetry(1000, 3));
- String nodePath = ZKPaths.makePath(ZKPaths.makePath(zkConfigs.get("root-node"),
- zkConfigs.get("config-version")), zkConfigs.get("node"));
+ String nodePath = ZKPaths.makePath(ZKPaths.makePath(zkConfigs.get(ROOT_NODE),
+ zkConfigs.get(CONFIG_VERSION)), zkConfigs.get(NODE));
final ConnectionStateListener connectionStateListener = (client, newState) -> {
if (newState == ConnectionState.CONNECTED) {
loadNode(nodePath);
@@ -81,6 +97,20 @@ public class ZookeeperRefresherHandler extends AbstractConfigThreadPoolDynamicRe
* @param nodePath zk config node path.
*/
public void loadNode(String nodePath) {
+ String content = nodePathResolver(nodePath);
+ if (content != null) {
+ dynamicRefresh(content);
+ registerNotifyAlarmManage();
+ }
+ }
+
+ /**
+ * resolver for zk config
+ *
+ * @param nodePath zk config node path
+ * @return resolver result
+ */
+ private String nodePathResolver(String nodePath) {
try {
final GetChildrenBuilder childrenBuilder = curatorFramework.getChildren();
final List children = childrenBuilder.watched().forPath(nodePath);
@@ -97,10 +127,10 @@ public class ZookeeperRefresherHandler extends AbstractConfigThreadPoolDynamicRe
}
content.append(nodeName).append("=").append(value).append("\n");
});
- dynamicRefresh(content.toString());
- registerNotifyAlarmManage();
+ return content.toString();
} catch (Exception ex) {
log.error("Load zookeeper node error, nodePath is: {}", nodePath, ex);
+ return null;
}
}
diff --git a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/event/AbstractRefreshListener.java b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/event/AbstractRefreshListener.java
index a630db60..61d6fe08 100644
--- a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/event/AbstractRefreshListener.java
+++ b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/refresher/event/AbstractRefreshListener.java
@@ -17,55 +17,15 @@
package cn.hippo4j.config.springboot.starter.refresher.event;
-import cn.hippo4j.adapter.web.WebThreadPoolHandlerChoose;
-import cn.hippo4j.adapter.web.WebThreadPoolService;
-import cn.hippo4j.common.config.ApplicationContextHolder;
-import cn.hippo4j.common.model.WebIpAndPortInfo;
-import cn.hippo4j.common.toolkit.Assert;
-import cn.hippo4j.common.toolkit.StringUtil;
-import cn.hippo4j.core.toolkit.inet.InetUtils;
+import cn.hippo4j.adapter.web.WebIpAndPortHolder;
import lombok.extern.slf4j.Slf4j;
-import java.util.Arrays;
-import java.util.Objects;
-
/**
* Refresh listener abstract base class.
*/
@Slf4j
public abstract class AbstractRefreshListener implements RefreshListener {
- protected static final String ALL = "*";
-
- protected static final String SEPARATOR = ",";
-
- /**
- * Application ip and application post
- */
- protected static volatile WebIpAndPortInfo webIpAndPort;
-
- protected void initIpAndPort() {
- if (webIpAndPort == null) {
- synchronized (AbstractRefreshListener.class) {
- if (webIpAndPort == null) {
- webIpAndPort = getWebIpAndPortInfo();
- }
- }
- }
- }
-
- private WebIpAndPortInfo getWebIpAndPortInfo() {
- InetUtils inetUtils = ApplicationContextHolder.getBean(InetUtils.class);
- InetUtils.HostInfo loopBackHostInfo = inetUtils.findFirstNonLoopBackHostInfo();
- Assert.notNull(loopBackHostInfo, "Unable to get the application IP address");
- String ip = loopBackHostInfo.getIpAddress();
- WebThreadPoolHandlerChoose webThreadPoolHandlerChoose = ApplicationContextHolder.getBean(WebThreadPoolHandlerChoose.class);
- WebThreadPoolService webThreadPoolService = webThreadPoolHandlerChoose.choose();
- // When get the port at startup, can get the message: "port xxx was already in use" or use two ports
- String port = String.valueOf(webThreadPoolService.getWebServer().getPort());
- return new WebIpAndPortInfo(ip, port);
- }
-
/**
* Matching nodes
* nodes is ip + port.Get 'nodes' in the new Properties,Compare this with the ip + port of Application.
@@ -82,19 +42,8 @@ public abstract class AbstractRefreshListener implements RefreshListener each.check(webIpAndPort.getIpSegment(), webIpAndPort.getPort()));
+ return WebIpAndPortHolder.check(nodes);
}
/**
@@ -104,6 +53,6 @@ public abstract class AbstractRefreshListener implements RefreshListener
chen.ma
machen@apache.org
- https://github.com/mabaiwan
+ https://github.com/itmachen
OpenGoofy
https://github.com/opengoofy