From 702b96a4a566704bfc28e81077f778f4095f26f1 Mon Sep 17 00:00:00 2001 From: "lambert@arch" Date: Thu, 7 Mar 2024 12:16:16 +0800 Subject: [PATCH] refactor: move health module into function module. more files will be added in function module --- .../console/config/HealthCheckConfig.java | 2 +- .../health/CheckResultCache.java | 6 +- .../{ => function}/health/HealthExecutor.java | 8 +-- .../{ => function}/health/HealthService.java | 15 ++-- .../health/annotation/HealthCheckType.java | 2 +- .../health/callback/HealthCheckCallback.java | 4 +- .../check/AbstractHealthCheckService.java | 4 +- .../health/check/HealthCheckService.java | 8 ++- .../check/config/HealthCheckObjectConfig.java | 19 +++++- .../check/impl/StorageRocketmqCheck.java | 2 +- .../spring/support/FunctionManager.java | 4 +- .../spring/support/FunctionManagerLoader.java | 2 +- .../src/main/resources/application-dev.yml | 7 +- .../main/resources/eventmesh-dashboard.sql | 68 +++++++++++-------- .../src/main/resources/logback-dev.xml | 50 ++++++++++++++ .../health/HealthExecutorTest.java | 14 ++-- .../health/HealthServiceTest.java | 17 +++-- .../check/impl/storage/RedisCheckTest.java} | 33 +++++---- .../health/HealthServiceIntegrateTest.java | 12 ++-- .../console/linkage/log/TestOprLog.java | 17 +++++ 20 files changed, 201 insertions(+), 93 deletions(-) rename eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/{ => function}/health/CheckResultCache.java (93%) rename eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/{ => function}/health/HealthExecutor.java (94%) rename eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/{ => function}/health/HealthService.java (92%) rename eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/{ => function}/health/annotation/HealthCheckType.java (95%) rename eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/{ => function}/health/callback/HealthCheckCallback.java (87%) rename eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/{ => function}/health/check/AbstractHealthCheckService.java (87%) rename eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/{ => function}/health/check/HealthCheckService.java (83%) rename eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/{ => function}/health/check/config/HealthCheckObjectConfig.java (75%) rename eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/{ => function}/health/check/impl/StorageRocketmqCheck.java (91%) create mode 100644 eventmesh-dashboard-console/src/main/resources/logback-dev.xml rename eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/{ => function}/health/HealthExecutorTest.java (93%) rename eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/{ => function}/health/HealthServiceTest.java (88%) rename eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/{health/check/impl/StorageRedisCheckTest.java => function/health/check/impl/storage/RedisCheckTest.java} (57%) diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/config/HealthCheckConfig.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/config/HealthCheckConfig.java index 8588311c..bbf05719 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/config/HealthCheckConfig.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/config/HealthCheckConfig.java @@ -17,7 +17,7 @@ package org.apache.eventmesh.dashboard.console.config; -import org.apache.eventmesh.dashboard.console.health.check.config.HealthCheckObjectConfig; +import org.apache.eventmesh.dashboard.console.function.health.check.config.HealthCheckObjectConfig; import java.util.List; diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/CheckResultCache.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/CheckResultCache.java similarity index 93% rename from eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/CheckResultCache.java rename to eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/CheckResultCache.java index 66dcd44d..4da837fb 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/CheckResultCache.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/CheckResultCache.java @@ -15,11 +15,11 @@ * limitations under the License. */ -package org.apache.eventmesh.dashboard.console.health; +package org.apache.eventmesh.dashboard.console.function.health; -import org.apache.eventmesh.dashboard.console.constant.HealthConstant; +import org.apache.eventmesh.dashboard.console.constant.health.HealthConstant; import org.apache.eventmesh.dashboard.console.enums.health.HealthCheckStatus; -import org.apache.eventmesh.dashboard.console.health.check.config.HealthCheckObjectConfig; +import org.apache.eventmesh.dashboard.console.function.health.check.config.HealthCheckObjectConfig; import java.time.LocalDateTime; import java.util.Collections; diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/HealthExecutor.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/HealthExecutor.java similarity index 94% rename from eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/HealthExecutor.java rename to eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/HealthExecutor.java index 49d76e22..fac6eb76 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/HealthExecutor.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/HealthExecutor.java @@ -15,14 +15,14 @@ * limitations under the License. */ -package org.apache.eventmesh.dashboard.console.health; +package org.apache.eventmesh.dashboard.console.function.health; import org.apache.eventmesh.dashboard.console.entity.health.HealthCheckResultEntity; import org.apache.eventmesh.dashboard.console.enums.health.HealthCheckStatus; import org.apache.eventmesh.dashboard.console.enums.health.HealthCheckType; -import org.apache.eventmesh.dashboard.console.health.CheckResultCache.CheckResult; -import org.apache.eventmesh.dashboard.console.health.callback.HealthCheckCallback; -import org.apache.eventmesh.dashboard.console.health.check.AbstractHealthCheckService; +import org.apache.eventmesh.dashboard.console.function.health.CheckResultCache.CheckResult; +import org.apache.eventmesh.dashboard.console.function.health.callback.HealthCheckCallback; +import org.apache.eventmesh.dashboard.console.function.health.check.AbstractHealthCheckService; import org.apache.eventmesh.dashboard.console.service.health.HealthDataService; import java.util.ArrayList; diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/HealthService.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/HealthService.java similarity index 92% rename from eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/HealthService.java rename to eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/HealthService.java index 333fa995..b07fd64b 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/HealthService.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/HealthService.java @@ -15,13 +15,13 @@ * limitations under the License. */ -package org.apache.eventmesh.dashboard.console.health; +package org.apache.eventmesh.dashboard.console.function.health; -import org.apache.eventmesh.dashboard.console.health.CheckResultCache.CheckResult; -import org.apache.eventmesh.dashboard.console.health.annotation.HealthCheckType; -import org.apache.eventmesh.dashboard.console.health.check.AbstractHealthCheckService; -import org.apache.eventmesh.dashboard.console.health.check.config.HealthCheckObjectConfig; -import org.apache.eventmesh.dashboard.console.health.check.impl.StorageRedisCheck; +import org.apache.eventmesh.dashboard.console.function.health.CheckResultCache.CheckResult; +import org.apache.eventmesh.dashboard.console.function.health.annotation.HealthCheckType; +import org.apache.eventmesh.dashboard.console.function.health.check.AbstractHealthCheckService; +import org.apache.eventmesh.dashboard.console.function.health.check.config.HealthCheckObjectConfig; +import org.apache.eventmesh.dashboard.console.function.health.check.impl.storage.RedisCheck; import org.apache.eventmesh.dashboard.console.service.health.HealthDataService; import java.lang.reflect.Constructor; @@ -55,7 +55,7 @@ public class HealthService { private static final Map> HEALTH_CHECK_CLASS_CACHE = new HashMap<>(); static { - setClassCache(StorageRedisCheck.class); + setClassCache(RedisCheck.class); } private static void setClassCache(Class clazz) { @@ -127,6 +127,7 @@ public void deleteCheckService(String resourceType, Long resourceId) { if (Objects.isNull(subMap)) { return; } + subMap.get(resourceId).destroy(); subMap.remove(resourceId); if (subMap.isEmpty()) { checkServiceMap.remove(resourceType); diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/annotation/HealthCheckType.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/annotation/HealthCheckType.java similarity index 95% rename from eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/annotation/HealthCheckType.java rename to eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/annotation/HealthCheckType.java index 6f396581..7a23b902 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/annotation/HealthCheckType.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/annotation/HealthCheckType.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.eventmesh.dashboard.console.health.annotation; +package org.apache.eventmesh.dashboard.console.function.health.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/callback/HealthCheckCallback.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/callback/HealthCheckCallback.java similarity index 87% rename from eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/callback/HealthCheckCallback.java rename to eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/callback/HealthCheckCallback.java index 7f7b3608..541d30c6 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/callback/HealthCheckCallback.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/callback/HealthCheckCallback.java @@ -15,9 +15,9 @@ * limitations under the License. */ -package org.apache.eventmesh.dashboard.console.health.callback; +package org.apache.eventmesh.dashboard.console.function.health.callback; -import org.apache.eventmesh.dashboard.console.health.HealthExecutor; +import org.apache.eventmesh.dashboard.console.function.health.HealthExecutor; /** * Callback used by HealthService.doCheck to notify the caller of the result of the health check.
diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/check/AbstractHealthCheckService.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/check/AbstractHealthCheckService.java similarity index 87% rename from eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/check/AbstractHealthCheckService.java rename to eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/check/AbstractHealthCheckService.java index 6fa7045d..3a3ab99d 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/check/AbstractHealthCheckService.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/check/AbstractHealthCheckService.java @@ -15,9 +15,9 @@ * limitations under the License. */ -package org.apache.eventmesh.dashboard.console.health.check; +package org.apache.eventmesh.dashboard.console.function.health.check; -import org.apache.eventmesh.dashboard.console.health.check.config.HealthCheckObjectConfig; +import org.apache.eventmesh.dashboard.console.function.health.check.config.HealthCheckObjectConfig; import lombok.Getter; diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/check/HealthCheckService.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/check/HealthCheckService.java similarity index 83% rename from eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/check/HealthCheckService.java rename to eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/check/HealthCheckService.java index 8f373632..1461d384 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/check/HealthCheckService.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/check/HealthCheckService.java @@ -15,10 +15,10 @@ * limitations under the License. */ -package org.apache.eventmesh.dashboard.console.health.check; +package org.apache.eventmesh.dashboard.console.function.health.check; -import org.apache.eventmesh.dashboard.console.health.HealthExecutor; -import org.apache.eventmesh.dashboard.console.health.callback.HealthCheckCallback; +import org.apache.eventmesh.dashboard.console.function.health.HealthExecutor; +import org.apache.eventmesh.dashboard.console.function.health.callback.HealthCheckCallback; /** * Health check service interface.
@@ -36,4 +36,6 @@ public interface HealthCheckService { public void init(); + public void destroy(); + } diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/check/config/HealthCheckObjectConfig.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/check/config/HealthCheckObjectConfig.java similarity index 75% rename from eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/check/config/HealthCheckObjectConfig.java rename to eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/check/config/HealthCheckObjectConfig.java index 8c350b43..79e8c826 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/check/config/HealthCheckObjectConfig.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/check/config/HealthCheckObjectConfig.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.eventmesh.dashboard.console.health.check.config; +package org.apache.eventmesh.dashboard.console.function.health.check.config; import java.util.Properties; @@ -38,8 +38,11 @@ public class HealthCheckObjectConfig { private Long clusterId; + //Prioritize passing in this field for a url. + //redis, nacos private String connectUrl; - //mysql, redis + + //redis private String host; private Integer port; @@ -51,5 +54,15 @@ public class HealthCheckObjectConfig { //mysql, redis private String database; - private Long requestTimeoutMillis = Long.MAX_VALUE; + private Long requestTimeoutMillis = 100000L; + + private RocketmqConfig rocketmqConfig = new RocketmqConfig(); + + @Data + public class RocketmqConfig { + + private String nameServerUrl; + private String brokerUrl; + private String endPoint; + } } \ No newline at end of file diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/check/impl/StorageRocketmqCheck.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/StorageRocketmqCheck.java similarity index 91% rename from eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/check/impl/StorageRocketmqCheck.java rename to eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/StorageRocketmqCheck.java index b6f56b8a..c200f076 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/check/impl/StorageRocketmqCheck.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/StorageRocketmqCheck.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.eventmesh.dashboard.console.health.check.impl; +package org.apache.eventmesh.dashboard.console.function.health.check.impl; public class StorageRocketmqCheck { diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/spring/support/FunctionManager.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/spring/support/FunctionManager.java index 50f5efb0..a0a61301 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/spring/support/FunctionManager.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/spring/support/FunctionManager.java @@ -17,8 +17,8 @@ package org.apache.eventmesh.dashboard.console.spring.support; -import org.apache.eventmesh.dashboard.console.health.CheckResultCache; -import org.apache.eventmesh.dashboard.console.health.HealthService; +import org.apache.eventmesh.dashboard.console.function.health.CheckResultCache; +import org.apache.eventmesh.dashboard.console.function.health.HealthService; import org.apache.eventmesh.dashboard.console.service.health.HealthDataService; import lombok.Getter; diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/spring/support/FunctionManagerLoader.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/spring/support/FunctionManagerLoader.java index 405cedcc..e2fcba48 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/spring/support/FunctionManagerLoader.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/spring/support/FunctionManagerLoader.java @@ -17,7 +17,7 @@ package org.apache.eventmesh.dashboard.console.spring.support; -import org.apache.eventmesh.dashboard.console.health.HealthService; +import org.apache.eventmesh.dashboard.console.function.health.HealthService; import org.apache.eventmesh.dashboard.console.service.health.HealthDataService; import javax.annotation.PostConstruct; diff --git a/eventmesh-dashboard-console/src/main/resources/application-dev.yml b/eventmesh-dashboard-console/src/main/resources/application-dev.yml index 3074e0c5..3b3c83b3 100644 --- a/eventmesh-dashboard-console/src/main/resources/application-dev.yml +++ b/eventmesh-dashboard-console/src/main/resources/application-dev.yml @@ -44,12 +44,11 @@ spring: test-while-idle: true min-evictable-idle-time-millis: 300000 +logging: + config: classpath:logback-dev.xml + mybatis: type-aliases-package: org.apache.eventmesh.dashboard.console.entity -# cron job config, use cron expression -cron: - #health check job - health: "0/15 * * * * ? *" diff --git a/eventmesh-dashboard-console/src/main/resources/eventmesh-dashboard.sql b/eventmesh-dashboard-console/src/main/resources/eventmesh-dashboard.sql index 96d4a849..08aaf274 100644 --- a/eventmesh-dashboard-console/src/main/resources/eventmesh-dashboard.sql +++ b/eventmesh-dashboard-console/src/main/resources/eventmesh-dashboard.sql @@ -17,22 +17,23 @@ DROP TABLE IF EXISTS `group`; CREATE TABLE `group` ( - `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id', - `cluster_id` bigint NOT NULL DEFAULT '-1' COMMENT '集群id', - `name` varchar(192) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '' COMMENT 'Group名称', - `member_count` int unsigned NOT NULL DEFAULT '0' COMMENT '成员数', + `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id', + `cluster_id` bigint NOT NULL DEFAULT '-1' COMMENT '集群id', + `name` varchar(192) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL DEFAULT '' COMMENT 'Group名称', + `member_count` int unsigned NOT NULL DEFAULT '0' COMMENT '成员数', `members` varchar(1024) COMMENT 'group的member列表', - `type` tinyint NOT NULL COMMENT 'group类型 0:consumer 1:producer', - `state` varchar(64) NOT NULL DEFAULT '' COMMENT '状态', - `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间', - `is_delete` int NOT NULL DEFAULT '0', + `type` tinyint NOT NULL COMMENT 'group类型 0:consumer 1:producer', + `state` varchar(64) NOT NULL DEFAULT '' COMMENT '状态', + `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间', + `is_delete` int NOT NULL DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `uniq_cluster_phy_id_name` (`cluster_id`, `name`), KEY `cluster_id` (`cluster_id`, `name`) ) ENGINE = InnoDB AUTO_INCREMENT = 322 - DEFAULT CHARSET = utf8mb3 COMMENT ='Group信息表'; + DEFAULT CHARSET = utf8mb4, + DEFAULT COLLATE = utf8mb4_bin COMMENT ='Group信息表'; DROP TABLE IF EXISTS `group_member`; @@ -52,7 +53,8 @@ CREATE TABLE `group_member` KEY `cluster_id` (`cluster_id`, `topic_name`, `group_name`) ) ENGINE = InnoDB AUTO_INCREMENT = 257 - DEFAULT CHARSET = utf8mb3 COMMENT ='GroupMember信息表'; + DEFAULT CHARSET = utf8mb4, + DEFAULT COLLATE = utf8mb4_bin COMMENT ='GroupMember信息表'; DROP TABLE IF EXISTS `operation_log`; @@ -74,29 +76,32 @@ CREATE TABLE `operation_log` KEY `idx_status` (`status`) ) ENGINE = InnoDB AUTO_INCREMENT = 68 - DEFAULT CHARSET = utf8mb3 COMMENT ='操作记录信息表'; + DEFAULT CHARSET = utf8mb4, + DEFAULT COLLATE = utf8mb4_bin COMMENT ='操作记录信息表'; DROP TABLE IF EXISTS `topic`; CREATE TABLE `topic` ( - `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id', - `cluster_id` bigint NOT NULL DEFAULT '-1' COMMENT '集群ID', - `topic_name` varchar(192) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '' COMMENT 'Topic名称', - `runtime_id` varchar(2048) NOT NULL DEFAULT '' COMMENT 'RuntimeId', - `storage_id` varchar(2048) NOT NULL DEFAULT '' COMMENT 'StorageId', - `retention_ms` bigint NOT NULL DEFAULT '-2' COMMENT '保存时间,-2:未知,-1:无限制,>=0对应时间,单位ms', - `type` tinyint NOT NULL DEFAULT '0' COMMENT 'Topic类型,默认0,0:普通,1:EventMesh内部', - `description` varchar(1024) DEFAULT '' COMMENT '备注信息', - `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间(尽量与Topic实际创建时间一致)', - `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间(尽量与Topic实际创建时间一致)', - `is_delete` int NOT NULL DEFAULT '0', + `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id', + `cluster_id` bigint NOT NULL DEFAULT '-1' COMMENT '集群ID', + `topic_name` varchar(192) CHARACTER SET utf8mb4 + COLLATE utf8mb4_bin NOT NULL DEFAULT '' COMMENT 'Topic名称', + `runtime_id` varchar(2048) NOT NULL DEFAULT '' COMMENT 'RuntimeId', + `storage_id` varchar(2048) NOT NULL DEFAULT '' COMMENT 'StorageId', + `retention_ms` bigint NOT NULL DEFAULT '-2' COMMENT '保存时间,-2:未知,-1:无限制,>=0对应时间,单位ms', + `type` tinyint NOT NULL DEFAULT '0' COMMENT 'Topic类型,默认0,0:普通,1:EventMesh内部', + `description` varchar(1024) DEFAULT '' COMMENT '备注信息', + `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间(尽量与Topic实际创建时间一致)', + `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间(尽量与Topic实际创建时间一致)', + `is_delete` int NOT NULL DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `uniq_cluster_phy_id_topic_name` (`cluster_id`, `topic_name`), KEY `cluster_id` (`cluster_id`, `topic_name`) ) ENGINE = InnoDB AUTO_INCREMENT = 562 - DEFAULT CHARSET = utf8mb3 COMMENT ='Topic信息表'; + DEFAULT CHARSET = utf8mb4, + DEFAULT COLLATE = utf8mb4_bin COMMENT ='Topic信息表'; DROP TABLE IF EXISTS `client`; @@ -121,7 +126,8 @@ CREATE TABLE `client` PRIMARY KEY (`id`), INDEX `idx_cluster_id` (`cluster_id`) ) ENGINE = InnoDB - DEFAULT CHARSET = utf8 COMMENT ='client is an SDK application that can produce or consume events.'; + DEFAULT CHARSET = utf8mb4, + DEFAULT COLLATE = utf8mb4_bin COMMENT ='client is an SDK application that can produce or consume events.'; @@ -141,7 +147,8 @@ CREATE TABLE `connector` PRIMARY KEY (`id`), INDEX `idx_cluster_id` (`cluster_id`) ) ENGINE = InnoDB - DEFAULT CHARSET = utf8 COMMENT ='Connector信息表'; + DEFAULT CHARSET = utf8mb4, + DEFAULT COLLATE = utf8mb4_bin COMMENT ='Connector信息表'; DROP TABLE IF EXISTS `connection`; CREATE TABLE `connection` @@ -168,7 +175,8 @@ CREATE TABLE `connection` INDEX `idx_source_id` (`source_id`), INDEX `idx_sink_id` (`sink_id`) ) ENGINE = InnoDB - DEFAULT CHARSET = utf8 COMMENT ='connection from event source to event sink. event source can be a source connector or a producer client.'; + DEFAULT CHARSET = utf8mb4, + DEFAULT COLLATE = utf8mb4_bin COMMENT ='connection from event source to event sink. event source can be a source connector or a producer client.'; DROP TABLE IF EXISTS `health_check_result`; CREATE TABLE `health_check_result` @@ -185,7 +193,8 @@ CREATE TABLE `health_check_result` INDEX `idx_cluster_id` (`cluster_id`), INDEX `idx_type` (`type`) ) ENGINE = InnoDB - DEFAULT CHARSET = utf8 COMMENT ='健康检查结果'; + DEFAULT CHARSET = utf8mb4, + DEFAULT COLLATE = utf8mb4_bin COMMENT ='健康检查结果'; DROP TABLE IF EXISTS `meta`; CREATE TABLE `meta` @@ -209,4 +218,5 @@ CREATE TABLE `meta` INDEX `idx_cluster_id` (`cluster_id`) ) ENGINE = InnoDB - DEFAULT CHARSET = utf8 COMMENT ='注册中心信息表'; \ No newline at end of file + DEFAULT CHARSET = utf8mb4, + DEFAULT COLLATE = utf8mb4_bin COMMENT ='注册中心信息表'; \ No newline at end of file diff --git a/eventmesh-dashboard-console/src/main/resources/logback-dev.xml b/eventmesh-dashboard-console/src/main/resources/logback-dev.xml new file mode 100644 index 00000000..e86bb3ef --- /dev/null +++ b/eventmesh-dashboard-console/src/main/resources/logback-dev.xml @@ -0,0 +1,50 @@ + + + + + + + [%d{yyyy-MM-dd HH:mm:ss.SSS}] %p %t - %m%n + + + + + ${user.home}/logs/eventmesh-dashboard.log + true + + ${user.home}/logs/eventmesh-dashboard-%d{yyyy-MM-dd}.%i.log + + + 104857600 + + 10 + + + [%d{yyyy-MM-dd HH:mm:ss.SSS}] %p %t - %m%n + UTF-8 + + + + + + + + + \ No newline at end of file diff --git a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/health/HealthExecutorTest.java b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/function/health/HealthExecutorTest.java similarity index 93% rename from eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/health/HealthExecutorTest.java rename to eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/function/health/HealthExecutorTest.java index d7626ed6..e36eb619 100644 --- a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/health/HealthExecutorTest.java +++ b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/function/health/HealthExecutorTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.eventmesh.dashboard.console.health; +package org.apache.eventmesh.dashboard.console.function.health; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; @@ -26,9 +26,9 @@ import org.apache.eventmesh.dashboard.console.entity.health.HealthCheckResultEntity; import org.apache.eventmesh.dashboard.console.enums.health.HealthCheckStatus; import org.apache.eventmesh.dashboard.console.enums.health.HealthCheckType; -import org.apache.eventmesh.dashboard.console.health.callback.HealthCheckCallback; -import org.apache.eventmesh.dashboard.console.health.check.AbstractHealthCheckService; -import org.apache.eventmesh.dashboard.console.health.check.config.HealthCheckObjectConfig; +import org.apache.eventmesh.dashboard.console.function.health.callback.HealthCheckCallback; +import org.apache.eventmesh.dashboard.console.function.health.check.AbstractHealthCheckService; +import org.apache.eventmesh.dashboard.console.function.health.check.config.HealthCheckObjectConfig; import org.apache.eventmesh.dashboard.console.service.health.impl.HealthDataServiceDatabaseImpl; import java.util.concurrent.CompletableFuture; @@ -77,7 +77,7 @@ public void initMock() { }).when(successHealthCheckService).doCheck(any(HealthCheckCallback.class)); Mockito.lenient().doAnswer((Answer) invocation -> { HealthCheckCallback callback = invocation.getArgument(0); - callback.onFail(new RuntimeException("TestRuntimeException")); + callback.onFail(new RuntimeException("TestRuntimeException: This check is designed to be failed. Ignore This!")); return null; }).when(failHealthCheckService).doCheck(any(HealthCheckCallback.class)); Mockito.lenient().doAnswer((Answer) invocation -> { @@ -100,7 +100,7 @@ public void initMock() { config1.setHealthCheckResourceType("storage"); config1.setHealthCheckResourceSubType("redis"); config1.setConnectUrl("redis://localhost:6379"); - config1.setSimpleClassName("StorageRedisCheck"); + config1.setSimpleClassName("RedisCheck"); config1.setClusterId(1L); Mockito.lenient().when(successHealthCheckService.getConfig()).thenReturn(config1); Mockito.lenient().when(timeoutHealthCheckService.getConfig()).thenReturn(config1); @@ -109,7 +109,7 @@ public void initMock() { config2.setHealthCheckResourceType("storage"); config2.setHealthCheckResourceSubType("redis"); config2.setConnectUrl("redis://localhost:6379"); - config2.setSimpleClassName("StorageRedisCheck"); + config2.setSimpleClassName("RedisCheck"); config2.setClusterId(1L); Mockito.lenient().when(failHealthCheckService.getConfig()).thenReturn(config2); } diff --git a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/health/HealthServiceTest.java b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/function/health/HealthServiceTest.java similarity index 88% rename from eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/health/HealthServiceTest.java rename to eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/function/health/HealthServiceTest.java index 9a2c3939..4d15316f 100644 --- a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/health/HealthServiceTest.java +++ b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/function/health/HealthServiceTest.java @@ -15,11 +15,11 @@ * limitations under the License. */ -package org.apache.eventmesh.dashboard.console.health; +package org.apache.eventmesh.dashboard.console.function.health; -import org.apache.eventmesh.dashboard.console.health.callback.HealthCheckCallback; -import org.apache.eventmesh.dashboard.console.health.check.AbstractHealthCheckService; -import org.apache.eventmesh.dashboard.console.health.check.config.HealthCheckObjectConfig; +import org.apache.eventmesh.dashboard.console.function.health.callback.HealthCheckCallback; +import org.apache.eventmesh.dashboard.console.function.health.check.AbstractHealthCheckService; +import org.apache.eventmesh.dashboard.console.function.health.check.config.HealthCheckObjectConfig; import org.apache.eventmesh.dashboard.console.service.health.HealthDataService; import org.junit.jupiter.api.BeforeEach; @@ -58,7 +58,7 @@ void testInsertCheckServiceWithAnnotation() { void testInsertCheckServiceWithSimpleClassName() { HealthCheckObjectConfig config = new HealthCheckObjectConfig(); config.setInstanceId(1L); - config.setSimpleClassName("StorageRedisCheck"); + config.setSimpleClassName("RedisCheck"); config.setHealthCheckResourceType("storage"); config.setHealthCheckResourceSubType("redis"); config.setClusterId(1L); @@ -89,7 +89,7 @@ void testDeleteCheckService() { } @Test - void testExecuteAll(){ + void testExecuteAll() { HealthCheckObjectConfig config = new HealthCheckObjectConfig(); config.setInstanceId(1L); config.setHealthCheckResourceType("storage"); @@ -115,5 +115,10 @@ public void doCheck(HealthCheckCallback callback) { public void init() { } + + @Override + public void destroy() { + + } } } \ No newline at end of file diff --git a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/health/check/impl/StorageRedisCheckTest.java b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/storage/RedisCheckTest.java similarity index 57% rename from eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/health/check/impl/StorageRedisCheckTest.java rename to eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/storage/RedisCheckTest.java index 74ac54cb..45cef819 100644 --- a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/health/check/impl/StorageRedisCheckTest.java +++ b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/storage/RedisCheckTest.java @@ -15,17 +15,22 @@ * limitations under the License. */ -package org.apache.eventmesh.dashboard.console.health.check.impl; +package org.apache.eventmesh.dashboard.console.function.health.check.impl.storage; -import org.apache.eventmesh.dashboard.console.health.callback.HealthCheckCallback; -import org.apache.eventmesh.dashboard.console.health.check.config.HealthCheckObjectConfig; +import org.apache.eventmesh.dashboard.console.function.health.callback.HealthCheckCallback; +import org.apache.eventmesh.dashboard.console.function.health.check.config.HealthCheckObjectConfig; + +import java.util.concurrent.CountDownLatch; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -class StorageRedisCheckTest { +import lombok.extern.slf4j.Slf4j; + +@Slf4j +class RedisCheckTest { - private StorageRedisCheck storageRedisCheck; + private RedisCheck redisCheck; @BeforeEach public void init() { @@ -33,24 +38,28 @@ public void init() { config.setInstanceId(1L); config.setHealthCheckResourceType("storage"); config.setHealthCheckResourceSubType("redis"); - config.setSimpleClassName("StorageRedisCheck"); + config.setSimpleClassName("RedisCheck"); config.setClusterId(1L); - config.setConnectUrl("redis://localhost:6379"); - storageRedisCheck = new StorageRedisCheck(config); + config.setConnectUrl("redis://127.0.0.1:6379"); + redisCheck = new RedisCheck(config); } @Test - public void testDoCheck() { - storageRedisCheck.doCheck(new HealthCheckCallback() { + public void testDoCheck() throws InterruptedException { + CountDownLatch latch = new CountDownLatch(1); + redisCheck.doCheck(new HealthCheckCallback() { @Override public void onSuccess() { - System.out.println("success"); + latch.countDown(); + log.info("{} success", this.getClass().getSimpleName()); } @Override public void onFail(Exception e) { - System.out.println("fail"); + latch.countDown(); + log.error("{}, failed for reason {}", this.getClass().getSimpleName(), e); } }); + latch.await(); } } \ No newline at end of file diff --git a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/integration/health/HealthServiceIntegrateTest.java b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/integration/health/HealthServiceIntegrateTest.java index e8fdb5ff..2a780f40 100644 --- a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/integration/health/HealthServiceIntegrateTest.java +++ b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/integration/health/HealthServiceIntegrateTest.java @@ -19,9 +19,9 @@ import org.apache.eventmesh.dashboard.console.entity.health.HealthCheckResultEntity; import org.apache.eventmesh.dashboard.console.enums.health.HealthCheckType; -import org.apache.eventmesh.dashboard.console.health.CheckResultCache; -import org.apache.eventmesh.dashboard.console.health.HealthService; -import org.apache.eventmesh.dashboard.console.health.check.config.HealthCheckObjectConfig; +import org.apache.eventmesh.dashboard.console.function.health.CheckResultCache; +import org.apache.eventmesh.dashboard.console.function.health.HealthService; +import org.apache.eventmesh.dashboard.console.function.health.check.config.HealthCheckObjectConfig; import org.apache.eventmesh.dashboard.console.service.health.HealthDataService; import java.util.List; @@ -38,12 +38,14 @@ @ActiveProfiles("test") @Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, scripts = {"classpath:use-test-schema.sql", "classpath:eventmesh-dashboard.sql"}) public class HealthServiceIntegrateTest { + HealthService healthService = new HealthService(); @Autowired private HealthDataService healthDataService; private final CheckResultCache checkResultCache = new CheckResultCache(); + @BeforeEach void init() { healthService.createExecutor(healthDataService, checkResultCache); @@ -66,7 +68,7 @@ void testStorageRedis() throws InterruptedException { queryEntity.setClusterId(1L); queryEntity.setType(HealthCheckType.STORAGE.getNumber()); queryEntity.setTypeId(1L); - List results = healthDataService.queryHealthCheckResultByClusterIdAndTypeAndTypeId(queryEntity); - Assertions.assertEquals(2,results.size()); + List results = healthDataService.queryHealthCheckResultByClusterIdAndTypeAndTypeId(queryEntity); + Assertions.assertEquals(2, results.size()); } } diff --git a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/linkage/log/TestOprLog.java b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/linkage/log/TestOprLog.java index afaf8d8c..90047383 100644 --- a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/linkage/log/TestOprLog.java +++ b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/linkage/log/TestOprLog.java @@ -1,3 +1,20 @@ +/* + * 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 org.apache.eventmesh.dashboard.console.linkage.log; import org.apache.eventmesh.dashboard.console.EventMeshDashboardApplication;