diff --git a/eventmesh-dashboard-console/pom.xml b/eventmesh-dashboard-console/pom.xml index b071854f..1fe19058 100644 --- a/eventmesh-dashboard-console/pom.xml +++ b/eventmesh-dashboard-console/pom.xml @@ -65,28 +65,46 @@ runtime - - + - org.apache.eventmesh - eventmesh-sdk-java - 1.10.0-release - - - junit - junit - - - junit - junit-dep - - + com.alibaba.nacos + nacos-client + ${nacos.version} + + + + + + + + + + + + + + + + + + io.lettuce lettuce-core + + + org.apache.rocketmq + rocketmq-client + 4.9.4 + + + org.apache.rocketmq + rocketmq-tools + 5.2.0 + @@ -105,4 +123,19 @@ + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.2.2 + + + **/org/apache/eventmesh/dashboard/console/integration/**/*.java + + + + + + \ No newline at end of file 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/constant/health/HealthCheckTypeConstant.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/constant/health/HealthCheckTypeConstant.java new file mode 100644 index 00000000..6765bab7 --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/constant/health/HealthCheckTypeConstant.java @@ -0,0 +1,39 @@ +/* + * 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.constant.health; + +public class HealthCheckTypeConstant { + + public static final String HEALTH_CHECK_TYPE_UNKNOWN = "unknown"; + + public static final String HEALTH_CHECK_TYPE_CLUSTER = "cluster"; + + public static final String HEALTH_CHECK_TYPE_RUNTIME = "runtime"; + public static final String HEALTH_CHECK_TYPE_STORAGE = "storage"; + public static final String HEALTH_CHECK_TYPE_META = "meta"; + public static final String HEALTH_CHECK_TYPE_TOPIC = "topic"; + + public static final String HEALTH_CHECK_SUBTYPE_REDIS = "redis"; + public static final String HEALTH_CHECK_SUBTYPE_MYSQL = "mysql"; + public static final String HEALTH_CHECK_SUBTYPE_ROCKETMQ_BROKER = "rocketmq4-broker"; + public static final String HEALTH_CHECK_SUBTYPE_ROCKETMQ_NAMESERVER = "rocketmq4-nameserver"; + public static final String HEALTH_CHECK_SUBTYPE_ROCKETMQ_TOPIC = "rocketmq4-topic"; + + public static final String HEALTH_CHECK_SUBTYPE_NACOS_CONFIG = "nacos-config"; + public static final String HEALTH_CHECK_SUBTYPE_NACOS_REGISTER = "nacos-register"; +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/constant/health/HealthConstant.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/constant/health/HealthConstant.java new file mode 100644 index 00000000..e243b30f --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/constant/health/HealthConstant.java @@ -0,0 +1,61 @@ +/* + * 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.constant.health; + +public class HealthConstant { + public static final String NEW_LINE_ENDING = "\n"; + + public static final String RUNTIME_CHECK_TOPIC = "eventmesh-dashboard-healthcheck-topic"; + + public static final String RUNTIME_CHECK_CONTENT_KEY = "eventmesh-dashboard-healthcheck-content"; + + public static final String RUNTIME_CHECK_CONTENT_BODY = "eventmesh-dashboard-healthcheck-content-body"; + + public static final String CLOUDEVENT_CONTENT_TYPE = "application/cloudevents+json"; + + + public static final String ENV = "test"; + public static final String HOST = "localhost"; + public static final String PASSWORD = "PASSWORD"; + public static final String USER_NAME = "PU4283"; + public static final String GROUP = "EventmeshTestGroup"; + public static final String PATH = "/data/app/umg_proxy"; + public static final Integer PORT = 8362; + public static final String VERSION = "2.0.11"; + public static final String IDC = "FT"; + public static final String SUBSYSTEM = "5023"; + + public static final String ROCKETMQ_CHECK_PRODUCER_GROUP = "eventmesh-dashboard-healthcheck-rocketmq-producer-group"; + + public static final String ROCKETMQ_CHECK_CONSUMER_GROUP = "eventmesh-dashboard-healthcheck-rocketmq-consumer-group"; + + public static final String ROCKETMQ_CHECK_TOPIC = "DO-NOT-USE-THIS-TOPIC-" + + "eventmesh-dashboard-healthcheck-rocketmq-topic-90a78a5d-b803-447e-8c48-1c87ab0c74d9"; + public static final String ROCKETMQ_CHECK_TOPIC_MSG = "eventmesh-dashboard-healthcheck-rocketmq-message"; + + public static final String NACOS_CHECK_DATA_ID = "DO-NOT-USE-THIS-" + + "eventmesh-dashboard-healthcheck-nacos-data-id-28e2933f-a47b-439d-b14b-7d9970c37042"; + + public static final String NACOS_CHECK_GROUP = "EVENTMESH_DASHBOARD_HEALTH_CHECK_GROUP"; + + public static final String NACOS_CHECK_CONTENT = "eventmesh-dashboard"; + + public static final String NACOS_CHECK_SERVICE_NAME = "eventmesh-dashboard-healthcheck-nacos-service-name"; + + public static final String NACOS_CHECK_SERVICE_CLUSTER_NAME = "eventmesh-dashboard-healthcheck-nacos-service-cluster-name"; +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/base/BaseEntity.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/base/BaseEntity.java index 14192fad..5d0984d6 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/base/BaseEntity.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/base/BaseEntity.java @@ -24,13 +24,21 @@ import lombok.Data; +/** + * Base Entity provide some basic fields that every Eventmesh Dashboard Entity would have + */ @Data @Schema(name = "BaseEntity", description = "Base entity") public class BaseEntity implements Serializable { private static final long serialVersionUID = -2697805837923579585L; + /** + * Primary key + */ + @Schema(name = "id", description = "primary key") + protected Long id; - private Long clusterId; + protected Long clusterId; protected Timestamp createTime; diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/connection/ConnectionEntity.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/connection/ConnectionEntity.java index 0a451cf1..626e793c 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/connection/ConnectionEntity.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/connection/ConnectionEntity.java @@ -40,12 +40,6 @@ public class ConnectionEntity extends BaseEntity { private static final long serialVersionUID = 6565578252656944905L; - /** - * Primary key - */ - @Schema(name = "id", description = "primary key") - private Long id; - /** * Runtime cluster id */ diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/connector/ConnectorEntity.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/connector/ConnectorEntity.java index 1681ac29..66db0f9b 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/connector/ConnectorEntity.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/connector/ConnectorEntity.java @@ -34,9 +34,6 @@ public class ConnectorEntity extends BaseEntity { private static final long serialVersionUID = -8226303660232951326L; - @Schema(name = "id", description = "primary key") - private Long id; - private Long clusterId; private String name; diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/health/HealthCheckResultEntity.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/health/HealthCheckResultEntity.java index e8578eb0..f427b66b 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/health/HealthCheckResultEntity.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/health/HealthCheckResultEntity.java @@ -32,8 +32,6 @@ public class HealthCheckResultEntity extends BaseEntity { private static final long serialVersionUID = -7350585209577598040L; - @Schema(name = "id", description = "primary key") - private Long id; private Long clusterId; diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/meta/MetaEntity.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/meta/MetaEntity.java index 2c32e284..a6871eb0 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/meta/MetaEntity.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/meta/MetaEntity.java @@ -33,12 +33,6 @@ public class MetaEntity extends BaseEntity { private static final long serialVersionUID = 7176263169716424469L; - /** - * Primary key - */ - @Schema(name = "id", description = "Primary key") - private Long id; - private String name; private String type; @@ -59,6 +53,7 @@ public class MetaEntity extends BaseEntity { /** * 0: not active, 1: active + * * @see StatusEnum */ @Schema(name = "status", defaultValue = "0", allowableValues = {"0", "1"}, description = "0:inactive, 1:active") diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/constant/HealthConstant.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/enums/StoreType.java similarity index 83% rename from eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/constant/HealthConstant.java rename to eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/enums/StoreType.java index 979f5783..b4721cc6 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/constant/HealthConstant.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/enums/StoreType.java @@ -15,8 +15,14 @@ * limitations under the License. */ -package org.apache.eventmesh.dashboard.console.constant; +package org.apache.eventmesh.dashboard.console.enums; + +public enum StoreType { + ROCKETMQ, + KAFKA, + STANDALONE, + PULSAR, + RABBITMQ, + REDIS, -public class HealthConstant { - public static final String NEW_LINE_ENDING = "\n"; } diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/enums/health/HealthCheckType.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/enums/health/HealthCheckType.java index 3ee990bb..abd918f3 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/enums/health/HealthCheckType.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/enums/health/HealthCheckType.java @@ -17,20 +17,26 @@ package org.apache.eventmesh.dashboard.console.enums.health; +import static org.apache.eventmesh.dashboard.console.constant.health.HealthCheckTypeConstant.HEALTH_CHECK_TYPE_CLUSTER; +import static org.apache.eventmesh.dashboard.console.constant.health.HealthCheckTypeConstant.HEALTH_CHECK_TYPE_RUNTIME; +import static org.apache.eventmesh.dashboard.console.constant.health.HealthCheckTypeConstant.HEALTH_CHECK_TYPE_STORAGE; +import static org.apache.eventmesh.dashboard.console.constant.health.HealthCheckTypeConstant.HEALTH_CHECK_TYPE_TOPIC; +import static org.apache.eventmesh.dashboard.console.constant.health.HealthCheckTypeConstant.HEALTH_CHECK_TYPE_UNKNOWN; + import lombok.AllArgsConstructor; import lombok.Getter; @AllArgsConstructor public enum HealthCheckType { - UNKNOWN(0, "unknown"), + UNKNOWN(0, HEALTH_CHECK_TYPE_UNKNOWN), - CLUSTER(1, "cluster"), + CLUSTER(1, HEALTH_CHECK_TYPE_CLUSTER), - RUNTIME(2, "runtime"), + RUNTIME(2, HEALTH_CHECK_TYPE_RUNTIME), - TOPIC(3, "topic"), + TOPIC(3, HEALTH_CHECK_TYPE_TOPIC), - STORAGE(4, "storage"); + STORAGE(4, HEALTH_CHECK_TYPE_STORAGE); @Getter private final Integer number; 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/function/health/check/impl/meta/NacosConfigCheck.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/meta/NacosConfigCheck.java new file mode 100644 index 00000000..db82e1fb --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/meta/NacosConfigCheck.java @@ -0,0 +1,102 @@ +/* + * 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.function.health.check.impl.meta; + +import static org.apache.eventmesh.dashboard.console.constant.health.HealthCheckTypeConstant.HEALTH_CHECK_SUBTYPE_NACOS_CONFIG; +import static org.apache.eventmesh.dashboard.console.constant.health.HealthCheckTypeConstant.HEALTH_CHECK_TYPE_META; +import static org.apache.eventmesh.dashboard.console.constant.health.HealthConstant.NACOS_CHECK_CONTENT; +import static org.apache.eventmesh.dashboard.console.constant.health.HealthConstant.NACOS_CHECK_DATA_ID; +import static org.apache.eventmesh.dashboard.console.constant.health.HealthConstant.NACOS_CHECK_GROUP; + +import org.apache.eventmesh.dashboard.console.function.health.annotation.HealthCheckType; +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 java.util.Properties; +import java.util.concurrent.CompletableFuture; + +import com.alibaba.nacos.api.NacosFactory; +import com.alibaba.nacos.api.config.ConfigService; +import com.alibaba.nacos.api.exception.NacosException; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@HealthCheckType(type = HEALTH_CHECK_TYPE_META, subType = HEALTH_CHECK_SUBTYPE_NACOS_CONFIG) +public class NacosConfigCheck extends AbstractHealthCheckService { + + private ConfigService configService; + + public NacosConfigCheck(HealthCheckObjectConfig healthCheckObjectConfig) { + super(healthCheckObjectConfig); + } + + @Override + public void doCheck(HealthCheckCallback callback) { + CompletableFuture.runAsync(() -> { + try { + String content = configService.getConfig(NACOS_CHECK_DATA_ID, NACOS_CHECK_GROUP, getConfig().getRequestTimeoutMillis()); + if (NACOS_CHECK_CONTENT.equals(content)) { + callback.onSuccess(); + } else { + callback.onFail(new RuntimeException("NacosCheck failed. Content is wrong.")); + } + } catch (NacosException e) { + callback.onFail(e); + } + }); + } + + @Override + public void init() { + //create a config + try { + Properties properties = new Properties(); + properties.put("serverAddr", getConfig().getConnectUrl()); + ConfigService configService = NacosFactory.createConfigService(properties); + boolean isPublishOk = configService.publishConfig(NACOS_CHECK_DATA_ID, NACOS_CHECK_GROUP, + NACOS_CHECK_CONTENT); + if (!isPublishOk) { + log.error("NacosCheck init failed caused by crate config failed"); + } + } catch (NacosException e) { + log.error("NacosCheck init failed caused by {}", e.getErrMsg()); + } + + try { + Properties properties = new Properties(); + properties.put("serverAddr", getConfig().getConnectUrl()); + configService = NacosFactory.createConfigService(properties); + } catch (NacosException e) { + log.error("NacosCheck init failed caused by {}", e.getErrMsg()); + } + } + + @Override + public void destroy() { + if (configService != null) { + try { + configService.removeConfig(NACOS_CHECK_DATA_ID, NACOS_CHECK_GROUP); + } catch (NacosException e) { + log.error("NacosCheck destroy failed caused by {}", e.getErrMsg()); + } + + } + } +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/meta/NacosRegisterCheck.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/meta/NacosRegisterCheck.java new file mode 100644 index 00000000..90ec2ea4 --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/meta/NacosRegisterCheck.java @@ -0,0 +1,87 @@ +/* + * 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.function.health.check.impl.meta; + +import static org.apache.eventmesh.dashboard.console.constant.health.HealthCheckTypeConstant.HEALTH_CHECK_SUBTYPE_NACOS_REGISTER; +import static org.apache.eventmesh.dashboard.console.constant.health.HealthCheckTypeConstant.HEALTH_CHECK_TYPE_META; +import static org.apache.eventmesh.dashboard.console.constant.health.HealthConstant.NACOS_CHECK_SERVICE_CLUSTER_NAME; +import static org.apache.eventmesh.dashboard.console.constant.health.HealthConstant.NACOS_CHECK_SERVICE_NAME; + +import org.apache.eventmesh.dashboard.console.function.health.annotation.HealthCheckType; +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 java.util.Properties; +import java.util.concurrent.CompletableFuture; + +import com.alibaba.nacos.api.exception.NacosException; +import com.alibaba.nacos.api.naming.NamingFactory; +import com.alibaba.nacos.api.naming.NamingService; +import com.alibaba.nacos.api.naming.pojo.Instance; + +import lombok.extern.slf4j.Slf4j; + + +@Slf4j +@HealthCheckType(type = HEALTH_CHECK_TYPE_META, subType = HEALTH_CHECK_SUBTYPE_NACOS_REGISTER) +public class NacosRegisterCheck extends AbstractHealthCheckService { + + private NamingService namingService; + + public NacosRegisterCheck(HealthCheckObjectConfig healthCheckObjectConfig) { + super(healthCheckObjectConfig); + } + + @Override + public void doCheck(HealthCheckCallback callback) { + CompletableFuture.runAsync(() -> { + try { + Instance result = namingService.selectOneHealthyInstance(NACOS_CHECK_SERVICE_NAME); + if (result.isHealthy()) { + callback.onSuccess(); + } else { + callback.onFail(new RuntimeException("NacosCheck failed. Service is not healthy.")); + } + } catch (NacosException e) { + callback.onFail(e); + } + }); + } + + @Override + public void init() { + try { + Properties properties = new Properties(); + properties.put("serverAddr", getConfig().getConnectUrl()); + namingService = NamingFactory.createNamingService(properties); + namingService.registerInstance(NACOS_CHECK_SERVICE_NAME, "11.11.11.11", 8888, NACOS_CHECK_SERVICE_CLUSTER_NAME); + } catch (NacosException e) { + log.error("NacosRegisterCheck init failed", e); + } + } + + @Override + public void destroy() { + try { + namingService.deregisterInstance(NACOS_CHECK_SERVICE_NAME, "11.11.11.11", 8888, NACOS_CHECK_SERVICE_CLUSTER_NAME); + } catch (NacosException e) { + log.error("NacosRegisterCheck destroy failed", e); + } + } +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/check/impl/StorageRedisCheck.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/storage/RedisCheck.java similarity index 73% rename from eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/check/impl/StorageRedisCheck.java rename to eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/storage/RedisCheck.java index 00cfad8e..71488ac7 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/check/impl/StorageRedisCheck.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/storage/RedisCheck.java @@ -15,12 +15,14 @@ * 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.annotation.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 static org.apache.eventmesh.dashboard.console.constant.health.HealthCheckTypeConstant.HEALTH_CHECK_TYPE_STORAGE; + +import org.apache.eventmesh.dashboard.console.function.health.annotation.HealthCheckType; +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 java.time.Duration; import java.util.Objects; @@ -30,13 +32,15 @@ import io.lettuce.core.RedisURI.Builder; import io.lettuce.core.api.async.RedisAsyncCommands; +import lombok.extern.slf4j.Slf4j; -@HealthCheckType(type = "storage", subType = "redis") -public class StorageRedisCheck extends AbstractHealthCheckService { +@Slf4j +@HealthCheckType(type = HEALTH_CHECK_TYPE_STORAGE, subType = "redis") +public class RedisCheck extends AbstractHealthCheckService { private RedisClient redisClient; - public StorageRedisCheck(HealthCheckObjectConfig healthCheckObjectConfig) { + public RedisCheck(HealthCheckObjectConfig healthCheckObjectConfig) { super(healthCheckObjectConfig); } @@ -55,6 +59,7 @@ public void doCheck(HealthCheckCallback callback) { return null; }); } catch (Exception e) { + log.error(e.toString()); callback.onFail(e); } } @@ -79,4 +84,11 @@ public void init() { } redisClient = RedisClient.create(redisUrl); } + + @Override + public void destroy() { + if (redisClient != null) { + redisClient.shutdown(); + } + } } diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/storage/rocketmq4/Rocketmq4BrokerCheck.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/storage/rocketmq4/Rocketmq4BrokerCheck.java new file mode 100644 index 00000000..5fb92cfa --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/storage/rocketmq4/Rocketmq4BrokerCheck.java @@ -0,0 +1,98 @@ +/* + * 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.function.health.check.impl.storage.rocketmq4; + + +import static org.apache.eventmesh.dashboard.console.constant.health.HealthCheckTypeConstant.HEALTH_CHECK_SUBTYPE_ROCKETMQ_BROKER; +import static org.apache.eventmesh.dashboard.console.constant.health.HealthCheckTypeConstant.HEALTH_CHECK_TYPE_STORAGE; + +import org.apache.eventmesh.dashboard.console.function.health.annotation.HealthCheckType; +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.rocketmq.common.protocol.RequestCode; +import org.apache.rocketmq.remoting.InvokeCallback; +import org.apache.rocketmq.remoting.RemotingClient; +import org.apache.rocketmq.remoting.netty.NettyClientConfig; +import org.apache.rocketmq.remoting.netty.NettyRemotingClient; +import org.apache.rocketmq.remoting.netty.ResponseFuture; +import org.apache.rocketmq.remoting.protocol.RemotingCommand; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@HealthCheckType(type = HEALTH_CHECK_TYPE_STORAGE, subType = HEALTH_CHECK_SUBTYPE_ROCKETMQ_BROKER) +public class Rocketmq4BrokerCheck extends AbstractHealthCheckService { + + private RemotingClient remotingClient; + + + public Rocketmq4BrokerCheck(HealthCheckObjectConfig healthCheckObjectConfig) { + super(healthCheckObjectConfig); + } + + @Override + public void doCheck(HealthCheckCallback callback) { + try { + RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_BROKER_RUNTIME_INFO, null); + remotingClient.invokeAsync(getConfig().getRocketmqConfig().getBrokerUrl(), request, getConfig().getRequestTimeoutMillis(), + new InvokeCallback() { + @Override + public void operationComplete(ResponseFuture responseFuture) { + if (responseFuture.isSendRequestOK()) { + callback.onSuccess(); + } else { + callback.onFail(new RuntimeException("RocketmqNameServerCheck failed caused by " + responseFuture.getCause())); + } + } + + }); + } catch (Exception e) { + log.error("RocketmqCheck failed.", e); + callback.onFail(e); + } + } + + @Override + public void init() { + if (getConfig().getRocketmqConfig().getBrokerUrl() == null || getConfig().getRocketmqConfig().getBrokerUrl().isEmpty()) { + throw new IllegalArgumentException("RocketmqCheck failed. BrokerUrl is null."); + } + + NettyClientConfig config = new NettyClientConfig(); + config.setUseTLS(false); + remotingClient = new NettyRemotingClient(config); + remotingClient.start(); + + if (getConfig().getConnectUrl() == null || getConfig().getConnectUrl().isEmpty()) { + if (getConfig().getHost() != null && getConfig().getPort() != null) { + getConfig().setConnectUrl(getConfig().getHost() + ":" + getConfig().getPort()); + } + } + + if (getConfig().getConnectUrl() == null) { + log.error("RocketmqCheck failed. ConnectUrl is null."); + } + } + + @Override + public void destroy() { + + } +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/storage/rocketmq4/Rocketmq4NameServerCheck.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/storage/rocketmq4/Rocketmq4NameServerCheck.java new file mode 100644 index 00000000..08df28b0 --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/storage/rocketmq4/Rocketmq4NameServerCheck.java @@ -0,0 +1,85 @@ +/* + * 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.function.health.check.impl.storage.rocketmq4; + +import org.apache.eventmesh.dashboard.console.constant.health.HealthCheckTypeConstant; +import org.apache.eventmesh.dashboard.console.function.health.annotation.HealthCheckType; +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.rocketmq.common.protocol.RequestCode; +import org.apache.rocketmq.remoting.InvokeCallback; +import org.apache.rocketmq.remoting.RemotingClient; +import org.apache.rocketmq.remoting.netty.NettyClientConfig; +import org.apache.rocketmq.remoting.netty.NettyRemotingClient; +import org.apache.rocketmq.remoting.netty.ResponseFuture; +import org.apache.rocketmq.remoting.protocol.RemotingCommand; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@HealthCheckType(type = HealthCheckTypeConstant.HEALTH_CHECK_TYPE_STORAGE, subType = HealthCheckTypeConstant.HEALTH_CHECK_SUBTYPE_ROCKETMQ_NAMESERVER) +public class Rocketmq4NameServerCheck extends AbstractHealthCheckService { + + private RemotingClient remotingClient; + + public Rocketmq4NameServerCheck(HealthCheckObjectConfig healthCheckObjectConfig) { + super(healthCheckObjectConfig); + } + + @Override + public void doCheck(HealthCheckCallback callback) { + try { + RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_NAMESRV_CONFIG, null); + remotingClient.invokeAsync(getConfig().getRocketmqConfig().getNameServerUrl(), request, getConfig().getRequestTimeoutMillis(), + new InvokeCallback() { + @Override + public void operationComplete(ResponseFuture responseFuture) { + if (responseFuture.isSendRequestOK()) { + callback.onSuccess(); + } else { + callback.onFail(new RuntimeException("RocketmqNameServerCheck failed caused by " + responseFuture.getCause())); + } + } + + }); + } catch (Exception e) { + log.error("RocketmqCheck failed.", e); + callback.onFail(e); + } + } + + @Override + public void init() { + if (getConfig().getRocketmqConfig().getNameServerUrl() == null || getConfig().getRocketmqConfig().getNameServerUrl().isEmpty()) { + throw new RuntimeException("RocketmqNameServerCheck init failed, nameServerUrl is empty"); + } + + NettyClientConfig config = new NettyClientConfig(); + config.setUseTLS(false); + remotingClient = new NettyRemotingClient(config); + remotingClient.start(); + + } + + @Override + public void destroy() { + + } +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/storage/rocketmq4/Rocketmq4TopicCheck.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/storage/rocketmq4/Rocketmq4TopicCheck.java new file mode 100644 index 00000000..75547624 --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/storage/rocketmq4/Rocketmq4TopicCheck.java @@ -0,0 +1,188 @@ +/* + * 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.function.health.check.impl.storage.rocketmq4; + +import static org.apache.rocketmq.client.producer.SendStatus.SEND_OK; + +import org.apache.eventmesh.dashboard.console.constant.health.HealthCheckTypeConstant; +import org.apache.eventmesh.dashboard.console.constant.health.HealthConstant; +import org.apache.eventmesh.dashboard.console.function.health.annotation.HealthCheckType; +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.rocketmq.client.consumer.DefaultMQPushConsumer; +import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext; +import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; +import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently; +import org.apache.rocketmq.client.producer.DefaultMQProducer; +import org.apache.rocketmq.client.producer.SendCallback; +import org.apache.rocketmq.client.producer.SendResult; +import org.apache.rocketmq.common.TopicFilterType; +import org.apache.rocketmq.common.constant.PermName; +import org.apache.rocketmq.common.message.Message; +import org.apache.rocketmq.common.message.MessageExt; +import org.apache.rocketmq.common.protocol.RequestCode; +import org.apache.rocketmq.common.protocol.header.CreateTopicRequestHeader; +import org.apache.rocketmq.common.protocol.heartbeat.MessageModel; +import org.apache.rocketmq.remoting.RemotingClient; +import org.apache.rocketmq.remoting.common.RemotingHelper; +import org.apache.rocketmq.remoting.netty.NettyClientConfig; +import org.apache.rocketmq.remoting.netty.NettyRemotingClient; +import org.apache.rocketmq.remoting.protocol.RemotingCommand; + +import java.util.Arrays; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@HealthCheckType(type = HealthCheckTypeConstant.HEALTH_CHECK_TYPE_STORAGE, subType = HealthCheckTypeConstant.HEALTH_CHECK_SUBTYPE_ROCKETMQ_TOPIC) +public class Rocketmq4TopicCheck extends AbstractHealthCheckService { + + private RemotingClient remotingClient; + + private DefaultMQPushConsumer consumer; + + private DefaultMQProducer producer; + + private Long startTime; + + private BlockingQueue consumedMessages = new LinkedBlockingQueue<>(); + + public Rocketmq4TopicCheck(HealthCheckObjectConfig healthCheckObjectConfig) { + super(healthCheckObjectConfig); + } + + @Override + public void doCheck(HealthCheckCallback callback) { + startTime = System.currentTimeMillis(); + String uuid = UUID.randomUUID().toString(); + log.debug("RocketmqTopicCheck start, uuid:{}", uuid); + try { + Message msg = new Message(HealthConstant.ROCKETMQ_CHECK_TOPIC, "eventmesh-dashboard-rocketmq-topic-check", uuid + .getBytes( + RemotingHelper.DEFAULT_CHARSET)); + synchronized (this) { + producer.send(msg, new SendCallback() { + @Override + public void onSuccess(SendResult sendResult) { + if (!sendResult.getSendStatus().equals(SEND_OK)) { + log.error("send message failed, sendResult:{}", sendResult); + callback.onFail(new Exception("send message failed for reason:" + sendResult.getSendStatus().toString())); + return; + } + consume(callback, uuid); + } + + @Override + public void onException(Throwable e) { + log.error("send message failed", e); + callback.onFail((Exception) e); + } + }); + } + + } catch (Exception e) { + log.error("RocketmqTopicCheck failed when producing message.", e); + callback.onFail(e); + } + + } + + private synchronized void consume(HealthCheckCallback callback, String uuid) { + try { + while (System.currentTimeMillis() - startTime < getConfig().getRequestTimeoutMillis()) { + Message message = consumedMessages.poll(System.currentTimeMillis() - startTime, TimeUnit.MILLISECONDS); + if (message != null) { + log.debug("RocketmqTopicCheck consume message:{}", new String(message.getBody())); + if (Arrays.equals(message.getBody(), uuid.getBytes())) { + callback.onSuccess(); + return; + } + } + } + callback.onFail(new TimeoutException("consume message timeout")); + } catch (Exception e) { + log.error("RocketmqTopicCheck failed when consuming message.", e); + callback.onFail(e); + } + } + + @Override + public void init() { + NettyClientConfig config = new NettyClientConfig(); + config.setUseTLS(false); + remotingClient = new NettyRemotingClient(config); + remotingClient.start(); + + //TODO there are many functions that can be reused, they should be collected in a util module + //this function that create topics can be reused + try { + CreateTopicRequestHeader requestHeader = new CreateTopicRequestHeader(); + requestHeader.setTopic(HealthConstant.ROCKETMQ_CHECK_TOPIC); + requestHeader.setTopicFilterType(TopicFilterType.SINGLE_TAG.name()); + requestHeader.setReadQueueNums(8); + requestHeader.setWriteQueueNums(8); + requestHeader.setPerm(PermName.PERM_READ | PermName.PERM_WRITE); + RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.UPDATE_AND_CREATE_TOPIC, requestHeader); + Object result = remotingClient.invokeSync(getConfig().getRocketmqConfig().getBrokerUrl(), request, getConfig().getRequestTimeoutMillis()); + log.info(result.toString()); + } catch (Exception e) { + log.error("RocketmqTopicCheck init failed when examining topic stats.", e); + return; + } + + try { + producer = new DefaultMQProducer(HealthConstant.ROCKETMQ_CHECK_PRODUCER_GROUP); + producer.setNamesrvAddr(getConfig().getRocketmqConfig().getNameServerUrl()); + producer.setCompressMsgBodyOverHowmuch(16); + producer.start(); + + consumer = new DefaultMQPushConsumer(HealthConstant.ROCKETMQ_CHECK_CONSUMER_GROUP); + consumer.setMessageModel(MessageModel.CLUSTERING); + consumer.setNamesrvAddr(getConfig().getRocketmqConfig().getNameServerUrl()); + consumer.subscribe(HealthConstant.ROCKETMQ_CHECK_TOPIC, "*"); + consumer.registerMessageListener(new MessageListenerConcurrently() { + @Override + public ConsumeConcurrentlyStatus consumeMessage(List list, ConsumeConcurrentlyContext consumeConcurrentlyContext) { + consumedMessages.addAll(list); + return ConsumeConcurrentlyStatus.CONSUME_SUCCESS; + } + }); + consumer.start(); + + } catch (Exception e) { + log.error("RocketmqCheck initialization failed when creating Rocketmq4 clients.", e); + } + + + } + + @Override + public void destroy() { + producer.shutdown(); + consumer.shutdown(); + } +} + diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/meta/MetaMapper.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/meta/MetaMapper.java index ab57fc11..d51a9eff 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/meta/MetaMapper.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/meta/MetaMapper.java @@ -26,6 +26,8 @@ import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Update; +import java.util.List; + /** * Mybatis Mapper for the table of meta. */ @@ -35,7 +37,7 @@ public interface MetaMapper { MetaEntity selectById(MetaEntity metaEntity); @Select("SELECT * FROM meta WHERE cluster_id = #{clusterId} LIMIT 1") - MetaEntity selectByClusterId(MetaEntity metaEntity); + List selectByClusterId(MetaEntity metaEntity); @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id") @Insert("INSERT INTO meta (name, type, version, cluster_id, host, port, role, username, params, status)" 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 c24a5549..7c5e38b5 100644 --- a/eventmesh-dashboard-console/src/main/resources/eventmesh-dashboard.sql +++ b/eventmesh-dashboard-console/src/main/resources/eventmesh-dashboard.sql @@ -132,22 +132,23 @@ create index idx_store_id_runtime_id 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`; @@ -167,7 +168,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`; @@ -189,29 +191,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`; @@ -236,7 +241,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.'; @@ -256,7 +262,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` @@ -283,7 +290,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` @@ -300,7 +308,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` @@ -324,4 +333,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/function/health/check/impl/meta/NacosConfigCheckTest.java b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/meta/NacosConfigCheckTest.java new file mode 100644 index 00000000..66133958 --- /dev/null +++ b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/meta/NacosConfigCheckTest.java @@ -0,0 +1,70 @@ +/* + * 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.function.health.check.impl.meta; + +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.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +class NacosConfigCheckTest { + + private NacosConfigCheck nacosCheck; + + @BeforeEach + public void init() { + HealthCheckObjectConfig config = new HealthCheckObjectConfig(); + config.setInstanceId(1L); + config.setHealthCheckResourceType("meta"); + config.setHealthCheckResourceSubType("nacos"); + config.setClusterId(1L); + config.setConnectUrl("127.0.0.1:8848"); + nacosCheck = new NacosConfigCheck(config); + } + + @Test + public void testDoCheck() throws InterruptedException { + CountDownLatch latch = new CountDownLatch(1); + nacosCheck.doCheck(new HealthCheckCallback() { + @Override + public void onSuccess() { + latch.countDown(); + log.info("{} success", this.getClass().getSimpleName()); + } + + @Override + public void onFail(Exception e) { + latch.countDown(); + log.error("{}, failed for reason {}", this.getClass().getSimpleName(), e); + } + }); + latch.await(); + } + + @AfterEach + public void destroy() { + nacosCheck.destroy(); + } +} \ No newline at end of file diff --git a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/meta/NacosRegisterCheckTest.java b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/meta/NacosRegisterCheckTest.java new file mode 100644 index 00000000..1b97df16 --- /dev/null +++ b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/meta/NacosRegisterCheckTest.java @@ -0,0 +1,70 @@ +/* + * 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.function.health.check.impl.meta; + +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.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +class NacosRegisterCheckTest { + + private NacosRegisterCheck nacosRegisterCheck; + + @BeforeEach + public void init() { + HealthCheckObjectConfig config = new HealthCheckObjectConfig(); + config.setInstanceId(1L); + config.setHealthCheckResourceType("meta"); + config.setHealthCheckResourceSubType("nacos"); + config.setClusterId(1L); + config.setConnectUrl("127.0.0.1:8848"); + nacosRegisterCheck = new NacosRegisterCheck(config); + } + + @Test + public void testDoCheck() throws InterruptedException { + CountDownLatch latch = new CountDownLatch(1); + nacosRegisterCheck.doCheck(new HealthCheckCallback() { + @Override + public void onSuccess() { + latch.countDown(); + log.info("{} success", this.getClass().getSimpleName()); + } + + @Override + public void onFail(Exception e) { + latch.countDown(); + log.error("{}, failed for reason {}", this.getClass().getSimpleName(), e); + } + }); + latch.await(); + } + + @AfterEach + public void destroy() { + nacosRegisterCheck.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/function/health/check/impl/storage/rocketmq4/RocketmqBrokerCheckTest.java b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/storage/rocketmq4/RocketmqBrokerCheckTest.java new file mode 100644 index 00000000..abf7ab29 --- /dev/null +++ b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/storage/rocketmq4/RocketmqBrokerCheckTest.java @@ -0,0 +1,61 @@ +/* + * 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.function.health.check.impl.storage.rocketmq4; + +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; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +class RocketmqBrokerCheckTest { + + private Rocketmq4BrokerCheck rocketmqCheck; + + @BeforeEach + public void init() { + HealthCheckObjectConfig config = new HealthCheckObjectConfig(); + config.getRocketmqConfig().setBrokerUrl("127.0.0.1:10911"); + config.setRequestTimeoutMillis(1000L); + rocketmqCheck = new Rocketmq4BrokerCheck(config); + } + + @Test + public void testDoCheck() throws InterruptedException { + CountDownLatch latch = new CountDownLatch(1); + rocketmqCheck.doCheck(new HealthCheckCallback() { + @Override + public void onSuccess() { + latch.countDown(); + log.info("{} success", this.getClass().getSimpleName()); + } + + @Override + public void onFail(Exception e) { + 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/function/health/check/impl/storage/rocketmq4/RocketmqNameserverCheckTest.java b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/storage/rocketmq4/RocketmqNameserverCheckTest.java new file mode 100644 index 00000000..92677bae --- /dev/null +++ b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/storage/rocketmq4/RocketmqNameserverCheckTest.java @@ -0,0 +1,61 @@ +/* + * 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.function.health.check.impl.storage.rocketmq4; + +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; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +class RocketmqNameserverCheckTest { + + private Rocketmq4NameServerCheck rocketmqCheck; + + @BeforeEach + public void init() { + HealthCheckObjectConfig config = new HealthCheckObjectConfig(); + config.getRocketmqConfig().setNameServerUrl("127.0.0.1:9876"); + config.setRequestTimeoutMillis(1000L); + rocketmqCheck = new Rocketmq4NameServerCheck(config); + } + + @Test + public void testDoCheck() throws InterruptedException { + CountDownLatch latch = new CountDownLatch(1); + rocketmqCheck.doCheck(new HealthCheckCallback() { + @Override + public void onSuccess() { + latch.countDown(); + log.info("{} success", this.getClass().getSimpleName()); + } + + @Override + public void onFail(Exception e) { + 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/function/health/check/impl/storage/rocketmq4/RocketmqTopicCheckTest.java b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/storage/rocketmq4/RocketmqTopicCheckTest.java new file mode 100644 index 00000000..8a90a5bd --- /dev/null +++ b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/storage/rocketmq4/RocketmqTopicCheckTest.java @@ -0,0 +1,75 @@ +/* + * 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.function.health.check.impl.storage.rocketmq4; + +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; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +class RocketmqTopicCheckTest { + + private Rocketmq4TopicCheck rocketmqCheck; + + @BeforeEach + public void init() throws InterruptedException { + HealthCheckObjectConfig config = new HealthCheckObjectConfig(); + config.getRocketmqConfig().setBrokerUrl("127.0.0.1:10911"); + config.getRocketmqConfig().setNameServerUrl("127.0.0.1:9876"); + config.setRequestTimeoutMillis(1000000L); + rocketmqCheck = new Rocketmq4TopicCheck(config); + } + + @Test + public void testDoCheck() throws InterruptedException { + CountDownLatch latch = new CountDownLatch(2); + rocketmqCheck.doCheck(new HealthCheckCallback() { + @Override + public void onSuccess() { + latch.countDown(); + log.info("{} success", this.getClass().getSimpleName()); + } + + @Override + public void onFail(Exception e) { + latch.countDown(); + log.error("{}, failed for reason {}", this.getClass().getSimpleName(), e); + } + }); + rocketmqCheck.doCheck(new HealthCheckCallback() { + @Override + public void onSuccess() { + latch.countDown(); + log.info("{} success", this.getClass().getSimpleName()); + } + + @Override + public void onFail(Exception e) { + 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; diff --git a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/mapper/connection/ConnectionMapperTest.java b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/mapper/connection/ConnectionMapperTest.java index 4f282297..6106e175 100644 --- a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/mapper/connection/ConnectionMapperTest.java +++ b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/mapper/connection/ConnectionMapperTest.java @@ -83,15 +83,15 @@ public void testSelectByClusterIdSinkTypeAndSinkId() { @Test public void testInsert() { - ConnectionEntity connectionEntity = new ConnectionEntity(1L, 1L, "connector", 1L, "connector", 2L, 1L, 0, "topic", 3L, null, "description"); + ConnectionEntity connectionEntity = new ConnectionEntity(1L, "connector", 1L, "connector", 2L, 1L, 0, "topic", 3L, null, "description"); connectionMapper.insert(connectionEntity); assertEquals(7, connectionMapper.selectAll().size()); } @Test public void testBatchInsert() { - ConnectionEntity connectionEntity1 = new ConnectionEntity(1L, 1L, "connector", 1L, "connector", 2L, 1L, 0, "topic", 3L, null, "description"); - ConnectionEntity connectionEntity2 = new ConnectionEntity(1L, 1L, "connector", 1L, "connector", 2L, 1L, 0, "topic", 3L, null, "description"); + ConnectionEntity connectionEntity1 = new ConnectionEntity(1L, "connector", 1L, "connector", 2L, 1L, 0, "topic", 3L, null, "description"); + ConnectionEntity connectionEntity2 = new ConnectionEntity(1L, "connector", 1L, "connector", 2L, 1L, 0, "topic", 3L, null, "description"); connectionMapper.batchInsert(Arrays.asList(connectionEntity1, connectionEntity2)); assertEquals(8, connectionMapper.selectAll().size()); } diff --git a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/mapper/connector/ConnectorMapperTest.java b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/mapper/connector/ConnectorMapperTest.java index 0bb360b1..786597dc 100644 --- a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/mapper/connector/ConnectorMapperTest.java +++ b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/mapper/connector/ConnectorMapperTest.java @@ -69,7 +69,7 @@ public void testSelectByClusterId() { @Test public void testInsert() { - ConnectorEntity connectorEntity = new ConnectorEntity(1L, 1L, "test", "test", "test", 0, 2, "test"); + ConnectorEntity connectorEntity = new ConnectorEntity(1L, "test", "test", "test", 0, 2, "test"); connectorMapper.insert(connectorEntity); assertNotNull(connectorEntity); @@ -78,9 +78,9 @@ public void testInsert() { @Test public void testBatchInsert() { - ConnectorEntity connectorEntity1 = new ConnectorEntity(1L, 1L, "test", "test", "test", 0, 2, "test"); - ConnectorEntity connectorEntity2 = new ConnectorEntity(1L, 1L, "test", "test", "test", 0, 2, "test"); - ConnectorEntity connectorEntity3 = new ConnectorEntity(1L, 1L, "test", "test", "test", 0, 2, "test"); + ConnectorEntity connectorEntity1 = new ConnectorEntity(1L, "test", "test", "test", 0, 2, "test"); + ConnectorEntity connectorEntity2 = new ConnectorEntity(1L, "test", "test", "test", 0, 2, "test"); + ConnectorEntity connectorEntity3 = new ConnectorEntity(1L, "test", "test", "test", 0, 2, "test"); List connectorEntityList = new ArrayList<>(); connectorEntityList.add(connectorEntity1); connectorEntityList.add(connectorEntity2); diff --git a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/mapper/health/HealthCheckResultMapperTest.java b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/mapper/health/HealthCheckResultMapperTest.java index 1ceb8fce..30e66907 100644 --- a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/mapper/health/HealthCheckResultMapperTest.java +++ b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/mapper/health/HealthCheckResultMapperTest.java @@ -17,7 +17,7 @@ package org.apache.eventmesh.dashboard.console.mapper.health; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; import org.apache.eventmesh.dashboard.console.EventMeshDashboardApplication; import org.apache.eventmesh.dashboard.console.entity.health.HealthCheckResultEntity; @@ -58,7 +58,7 @@ public void testSelectById() { @Test public void testSelectByClusterIdAndTypeAndTypeId() { - HealthCheckResultEntity healthCheckResultEntity = new HealthCheckResultEntity(1L, 1L, 1, 1L, "", 1); + HealthCheckResultEntity healthCheckResultEntity = new HealthCheckResultEntity(1L, 1, 1L, "", 1); healthCheckResultEntity = healthCheckResultMapper.selectByClusterIdAndTypeAndTypeId(healthCheckResultEntity).get(0); assertEquals(1, healthCheckResultEntity.getId()); assertEquals(0, healthCheckResultEntity.getStatus()); @@ -66,7 +66,7 @@ public void testSelectByClusterIdAndTypeAndTypeId() { @Test public void testSelectByClusterIdAndType() { - HealthCheckResultEntity healthCheckResultEntity = new HealthCheckResultEntity(1L, 1L, 1, 1L, "", 1); + HealthCheckResultEntity healthCheckResultEntity = new HealthCheckResultEntity(1L, 1, 1L, "", 1); List results = healthCheckResultMapper.selectByClusterIdAndType(healthCheckResultEntity); assertEquals(2, results.size()); } @@ -84,7 +84,7 @@ public void testSelectByClusterIdAndTimeRange() throws ParseException { @Test public void testInsert() { - HealthCheckResultEntity healthCheckResultEntity = new HealthCheckResultEntity(1L, 5L, 1, 5L, "", 1); + HealthCheckResultEntity healthCheckResultEntity = new HealthCheckResultEntity(5L, 1, 5L, "", 1); healthCheckResultMapper.insert(healthCheckResultEntity); healthCheckResultEntity = healthCheckResultMapper.selectById(healthCheckResultEntity); assertEquals(7, healthCheckResultEntity.getId()); @@ -92,8 +92,8 @@ public void testInsert() { @Test public void testBatchInsert() { - HealthCheckResultEntity healthCheckResultEntity1 = new HealthCheckResultEntity(1L, 1L, 1, 5L, "", 1); - HealthCheckResultEntity healthCheckResultEntity2 = new HealthCheckResultEntity(1L, 1L, 1, 6L, "", 1); + HealthCheckResultEntity healthCheckResultEntity1 = new HealthCheckResultEntity(1L, 1, 5L, "", 1); + HealthCheckResultEntity healthCheckResultEntity2 = new HealthCheckResultEntity(1L, 1, 6L, "", 1); healthCheckResultMapper.batchInsert(Arrays.asList(healthCheckResultEntity1, healthCheckResultEntity2)); List results = healthCheckResultMapper.selectByClusterIdAndType(healthCheckResultEntity1); assertEquals(4, results.size()); @@ -101,7 +101,7 @@ public void testBatchInsert() { @Test public void testUpdate() { - HealthCheckResultEntity healthCheckResultEntity = new HealthCheckResultEntity(1L, 1L, 1, 1L, "reason", 0); + HealthCheckResultEntity healthCheckResultEntity = new HealthCheckResultEntity(1L, 1, 1L, "reason", 0); healthCheckResultMapper.update(healthCheckResultEntity); healthCheckResultEntity = healthCheckResultMapper.selectByClusterIdAndTypeAndTypeId(healthCheckResultEntity).get(0); assertEquals(0, healthCheckResultEntity.getStatus()); @@ -109,8 +109,10 @@ public void testUpdate() { @Test public void testBatchUpdate() { - HealthCheckResultEntity healthCheckResultEntity1 = new HealthCheckResultEntity(1L, 1L, 1, 1L, "reason", 0); - HealthCheckResultEntity healthCheckResultEntity2 = new HealthCheckResultEntity(2L, 1L, 1, 1L, "reason", 0); + HealthCheckResultEntity healthCheckResultEntity1 = new HealthCheckResultEntity(1L, 1, 1L, "reason", 0); + healthCheckResultEntity1.setId(1L); + HealthCheckResultEntity healthCheckResultEntity2 = new HealthCheckResultEntity(1L, 1, 1L, "reason", 0); + healthCheckResultEntity2.setId(2L); healthCheckResultMapper.batchUpdate(Arrays.asList(healthCheckResultEntity1, healthCheckResultEntity2)); healthCheckResultEntity1 = healthCheckResultMapper.selectById(healthCheckResultEntity1); healthCheckResultEntity2 = healthCheckResultMapper.selectById(healthCheckResultEntity2); @@ -121,8 +123,8 @@ public void testBatchUpdate() { @Test public void testUpdateByClusterIdAndTypeAndTypeId() { - HealthCheckResultEntity entity1 = new HealthCheckResultEntity(null, 1L, 1, 1L, "reason", 2); - HealthCheckResultEntity entity2 = new HealthCheckResultEntity(null, 1L, 1, 1L, "reason", 2); + HealthCheckResultEntity entity1 = new HealthCheckResultEntity(1L, 1, 1L, "reason", 2); + HealthCheckResultEntity entity2 = new HealthCheckResultEntity(1L, 1, 1L, "reason", 2); healthCheckResultMapper.batchInsert(Arrays.asList(entity1, entity2)); List toBeUpdate = healthCheckResultMapper.getIdsNeedToBeUpdateByClusterIdAndTypeAndTypeId( diff --git a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/mapper/meta/MetaMapperTest.java b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/mapper/meta/MetaMapperTest.java index 9d05b401..5888edae 100644 --- a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/mapper/meta/MetaMapperTest.java +++ b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/mapper/meta/MetaMapperTest.java @@ -20,6 +20,7 @@ import org.apache.eventmesh.dashboard.console.EventMeshDashboardApplication; import org.apache.eventmesh.dashboard.console.entity.meta.MetaEntity; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; @@ -42,6 +43,7 @@ class MetaMapperTest { public void testSelectByClusterId() { MetaEntity metaEntity = new MetaEntity(); metaEntity.setClusterId(1L); - metaEntity = metaMapper.selectByClusterId(metaEntity); + metaEntity = metaMapper.selectByClusterId(metaEntity).get(0); + Assertions.assertEquals("nacos", metaEntity.getType()); } } \ No newline at end of file diff --git a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/group/TestGroupMapper.java b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/group/GroupMapperTest.java similarity index 82% rename from eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/group/TestGroupMapper.java rename to eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/group/GroupMapperTest.java index f02fcafc..41eca99f 100644 --- a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/group/TestGroupMapper.java +++ b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/group/GroupMapperTest.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.unit.group; import org.apache.eventmesh.dashboard.console.EventMeshDashboardApplication; @@ -16,7 +33,7 @@ @RunWith(SpringRunner.class) @SpringBootTest(classes = EventMeshDashboardApplication.class) -public class TestGroupMapper { +public class GroupMapperTest { @Autowired private OprGroupMapper groupMapper; diff --git a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/groupmember/testGroupMemberMapper.java b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/groupmember/GroupMemberMapperTest.java similarity index 88% rename from eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/groupmember/testGroupMemberMapper.java rename to eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/groupmember/GroupMemberMapperTest.java index d3a20a0f..76fa8498 100644 --- a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/groupmember/testGroupMemberMapper.java +++ b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/groupmember/GroupMemberMapperTest.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.unit.groupmember; import org.apache.eventmesh.dashboard.console.EventMeshDashboardApplication; @@ -16,7 +33,7 @@ @RunWith(SpringRunner.class) @SpringBootTest(classes = EventMeshDashboardApplication.class) -public class testGroupMemberMapper { +public class GroupMemberMapperTest { @Autowired OprGroupMemberMapper groupMemberMapper; diff --git a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/topic/testTopicMapper.java b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/topic/TopicMapperTest.java similarity index 84% rename from eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/topic/testTopicMapper.java rename to eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/topic/TopicMapperTest.java index 7472792e..929953a5 100644 --- a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/topic/testTopicMapper.java +++ b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/topic/TopicMapperTest.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.unit.topic; import org.apache.eventmesh.dashboard.console.EventMeshDashboardApplication; @@ -16,7 +33,7 @@ @RunWith(SpringRunner.class) @SpringBootTest(classes = EventMeshDashboardApplication.class) -public class testTopicMapper { +public class TopicMapperTest { @Autowired private TopicMapper topicMapper; diff --git a/eventmesh-dashboard-console/src/test/resources/logback-test.xml b/eventmesh-dashboard-console/src/test/resources/logback-test.xml new file mode 100644 index 00000000..e86bb3ef --- /dev/null +++ b/eventmesh-dashboard-console/src/test/resources/logback-test.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/pom.xml b/pom.xml index 68372bf7..f0645ad3 100644 --- a/pom.xml +++ b/pom.xml @@ -74,13 +74,14 @@ https://github.com/apache/eventmesh-dashboard/issues - - 8 - 8 - UTF-8 - 2.7.6 - 2.3.2 - + + 8 + 8 + UTF-8 + 2.7.6 + 2.3.2 + 2.1.2 + eventmesh-dashboard-console @@ -135,17 +136,6 @@ - - - org.apache.maven.plugins - maven-surefire-plugin - 3.2.2 - - - **/org/apache/eventmesh/dashboard/console/integration/**/*.java - - - \ No newline at end of file