diff --git a/eventmesh-dashboard-console/pom.xml b/eventmesh-dashboard-console/pom.xml index ddf65952..759c8b7c 100644 --- a/eventmesh-dashboard-console/pom.xml +++ b/eventmesh-dashboard-console/pom.xml @@ -29,6 +29,12 @@ spring-boot-starter-test test + + + org.springframework + spring-aspects + 5.1.2.RELEASE + @@ -70,19 +76,38 @@ runtime + + - org.springframework - spring-aspects - 5.1.2.RELEASE + org.apache.eventmesh + eventmesh-sdk-java + 1.9.0-release + + + junit + junit + + + junit + junit-dep + + + + + io.lettuce + lettuce-core + + + + + junit junit 4.13.2 test - - \ No newline at end of file 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 d4d21c51..0a451cf1 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 @@ -25,13 +25,17 @@ import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; /** * A Connection is a link from a source to a sink. */ @Data +@NoArgsConstructor +@AllArgsConstructor public class ConnectionEntity extends BaseEntity { private static final long serialVersionUID = 6565578252656944905L; @@ -42,6 +46,12 @@ public class ConnectionEntity extends BaseEntity { @Schema(name = "id", description = "primary key") private Long id; + /** + * Runtime cluster id + */ + @Schema(name = "clusterId", description = "runtime cluster id") + private Long clusterId; + /** * The type of source. Possible values are "connector" or "client". */ 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 1e7cb07d..1681ac29 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 @@ -37,6 +37,8 @@ public class ConnectorEntity extends BaseEntity { @Schema(name = "id", description = "primary key") private Long id; + private Long clusterId; + private String name; private String className; 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 new file mode 100644 index 00000000..e8578eb0 --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/health/HealthCheckResultEntity.java @@ -0,0 +1,52 @@ +/* + * 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.entity.health; + +import org.apache.eventmesh.dashboard.console.entity.base.BaseEntity; + +import io.swagger.v3.oas.annotations.media.Schema; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Schema(name = "HealthCheckResultEntity", description = "Health check result entity") +public class HealthCheckResultEntity extends BaseEntity { + + private static final long serialVersionUID = -7350585209577598040L; + @Schema(name = "id", description = "primary key") + private Long id; + + private Long clusterId; + + @Schema(description = "Type of Health Check;0:Unknown, 1:Cluster, 2:Runtime, 3:Topic, 4:Storage", defaultValue = "0", allowableValues = {"0", + "1", "2", "3", "4"}) + private Integer type; + + @Schema(description = "Instance id(database schema) of the health check object") + private Long typeId; + + private String resultDesc; + + @Schema(description = "status of a health check, 0: failed, 1: passed, 2: doing check, 3: out of time") + private Integer status; + +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/enums/health/HealthCheckStatus.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/enums/health/HealthCheckStatus.java new file mode 100644 index 00000000..fd5bc125 --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/enums/health/HealthCheckStatus.java @@ -0,0 +1,33 @@ +/* + * 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.enums.health; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum HealthCheckStatus { + FAILED(0, "failed"), + PASSED(1, "passed"), + CHECKING(2, "checking"), + TIMEOUT(3, "timeout"); + + private final Integer number; + private final String name; +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/enums/health/HealthCheckTypeEnum.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/enums/health/HealthCheckTypeEnum.java new file mode 100644 index 00000000..eb7ddce1 --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/enums/health/HealthCheckTypeEnum.java @@ -0,0 +1,57 @@ +/* + * 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.enums.health; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@AllArgsConstructor +public enum HealthCheckTypeEnum { + UNKNOWN(0, "unknown"), + + CLUSTER(1, "cluster"), + + RUNTIME(2, "runtime"), + + TOPIC(3, "topic"), + + STORAGE(4, "storage"); + + @Getter + private final Integer number; + @Getter + private final String name; + + public static Integer toNumber(String name) { + for (HealthCheckTypeEnum healthCheckTypeEnum : HealthCheckTypeEnum.values()) { + if (healthCheckTypeEnum.name.equals(name)) { + return healthCheckTypeEnum.number; + } + } + return UNKNOWN.number; + } + + public static String toName(Integer number) { + for (HealthCheckTypeEnum healthCheckTypeEnum : HealthCheckTypeEnum.values()) { + if (healthCheckTypeEnum.number.equals(number)) { + return healthCheckTypeEnum.name; + } + } + return UNKNOWN.name; + } +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/client/ClientMapper.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/client/ClientMapper.java index 671bd81b..d54808c3 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/client/ClientMapper.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/client/ClientMapper.java @@ -19,13 +19,14 @@ import org.apache.eventmesh.dashboard.console.entity.client.ClientEntity; -import org.apache.ibatis.annotations.Delete; import org.apache.ibatis.annotations.Insert; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Options; import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Update; +import java.util.List; + /** * Mybatis Mapper for the table of client. */ @@ -33,10 +34,10 @@ public interface ClientMapper { @Select("SELECT * FROM `client` WHERE `id` = #{id}") - ClientEntity selectById(Long id); + ClientEntity selectById(ClientEntity clientEntity); @Select("SELECT * FROM `client` WHERE `cluster_id` = #{clusterId}") - ClientEntity selectByClusterId(Long clusterId); + List selectByClusterId(ClientEntity clientEntity); @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id") @Insert( @@ -48,12 +49,7 @@ public interface ClientMapper { + " #{status}, #{configIds}, #{description}, #{endTime})") void insert(ClientEntity clientEntity); - @Update("UPDATE `client` SET status = #{status}, end_time = NOW() WHERE id = #{id}") + @Update("UPDATE `client` SET status = 0, end_time = NOW() WHERE id = #{id}") void deActive(ClientEntity clientEntity); - @Update("UPDATE `client` SET status = #{status} WHERE id = #{id}") - void updateStatus(ClientEntity clientEntity); - - @Delete("DELETE FROM `client` WHERE id = #{id}") - void deleteById(Long id); } diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/connection/ConnectionMapper.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/connection/ConnectionMapper.java index af0a2acb..8d91a635 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/connection/ConnectionMapper.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/connection/ConnectionMapper.java @@ -19,13 +19,14 @@ import org.apache.eventmesh.dashboard.console.entity.connection.ConnectionEntity; -import org.apache.ibatis.annotations.Delete; import org.apache.ibatis.annotations.Insert; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Options; +import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Update; +import java.sql.Timestamp; import java.util.List; /** @@ -34,15 +35,28 @@ @Mapper public interface ConnectionMapper { - @Select("SELECT * FROM connection WHERE id = #{id}") - ConnectionEntity selectById(ConnectionEntity connectionEntity); - @Select("SELECT * FROM connection") List selectAll(); @Select("SELECT * FROM connection WHERE cluster_id = #{clusterId}") List selectByClusterId(ConnectionEntity connectionEntity); + @Select("SELECT * FROM connection WHERE cluster_id = #{clusterId} AND source_id = #{sourceId} AND source_type = #{sourceType}") + public List selectByClusterIdSourceTypeAndSourceId(ConnectionEntity connectionEntity); + + @Select("SELECT * FROM connection WHERE cluster_id = #{clusterId} AND sink_id = #{sinkId} AND sink_type = #{sinkType}") + public List selectByClusterIdSinkTypeAndSinkId(ConnectionEntity connectionEntity); + + @Select("SELECT * FROM connection WHERE cluster_id = #{clusterId} AND source_id = #{sourceId} AND source_type = #{sourceType} " + + "AND create_time > #{startTime} AND create_time < #{endTime}") + public List selectByClusterIdSourceTypeAndSourceIdAndCreateTimeRange(ConnectionEntity connectionEntity, + @Param("startTime") Timestamp startTime, @Param("endTime") Timestamp endTime); + + @Select("SELECT * FROM connection WHERE cluster_id = #{clusterId} AND sink_id = #{sinkId} AND sink_type = #{sinkType} " + + "AND create_time > #{startTime} AND create_time < #{endTime}") + public List selectByClusterIdSinkTypeAndSinkIdAndCreateTimeRange(ConnectionEntity connectionEntity, + @Param("startTime") Timestamp startTime, @Param("endTime") Timestamp endTime); + @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id") @Insert("INSERT INTO connection (cluster_id, source_type, source_id," + " sink_type, sink_id, runtime_id, status, topic, group_id, description)" @@ -64,21 +78,14 @@ public interface ConnectionMapper { + "") void batchInsert(List connectionEntityList); - @Update("UPDATE connection SET status = #{status}, end_time = NOW() WHERE id = #{id}") + @Update("UPDATE connection SET status = 1, end_time = NOW() WHERE id = #{id}") void endConnectionById(ConnectionEntity connectionEntity); - @Delete("DELETE FROM connection WHERE cluster_id = #{clusterId}") - void deleteAllByClusterId(ConnectionEntity connectionEntity); - - @Delete("DELETE FROM connection WHERE id = #{id}") - void deleteById(ConnectionEntity connectionEntity); - - @Delete("") - void batchDelete(List connectionEntityList); + //batch end + @Update({ + ""}) + void batchEndConnectionById(List connectionEntityList); } diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/connector/ConnectorMapper.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/connector/ConnectorMapper.java index 07913275..53a34660 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/connector/ConnectorMapper.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/connector/ConnectorMapper.java @@ -19,7 +19,6 @@ import org.apache.eventmesh.dashboard.console.entity.connector.ConnectorEntity; -import org.apache.ibatis.annotations.Delete; import org.apache.ibatis.annotations.Insert; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Options; @@ -38,11 +37,11 @@ public interface ConnectorMapper { ConnectorEntity selectById(ConnectorEntity connectorEntity); @Select("SELECT * FROM connector WHERE cluster_id = #{clusterId}") - ConnectorEntity selectByClusterId(ConnectorEntity connectorEntity); + List selectByClusterId(ConnectorEntity connectorEntity); @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id") - @Insert("INSERT INTO connector (cluster_id, name, class_name, type, status, pod_state, config_ids) " - + "VALUES (#{connectClusterId}, #{name}, #{className}, #{type}, #{status}, #{podState}, #{configIds})") + @Insert("INSERT INTO connector (cluster_id,name, class_name, type, status, pod_state, config_ids) " + + "VALUES (#{clusterId}, #{name}, #{className}, #{type}, #{status}, #{podState}, #{configIds})") void insert(ConnectorEntity connectorEntity); @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id") @@ -50,7 +49,7 @@ public interface ConnectorMapper { + "INSERT INTO connector (cluster_id, name, class_name, type, status, pod_state, config_ids) VALUES " + "" - + "(#{connectorEntity.connectClusterId}, #{connectorEntity.name}, #{connectorEntity.className}," + + "(#{connectorEntity.clusterId}, #{connectorEntity.name}, #{connectorEntity.className}," + " #{connectorEntity.type}, #{connectorEntity.status}, #{connectorEntity.podState}, #{connectorEntity.configIds})" + "" + "") @@ -65,18 +64,17 @@ public interface ConnectorMapper { @Update("UPDATE connector SET config_ids = #{configIds} WHERE id = #{id}") void updateConfigIds(ConnectorEntity connectorEntity); - @Delete("DELETE FROM connector WHERE id = #{id}") - void deleteById(ConnectorEntity connectorEntity); + @Update("UPDATE connector SET status = 0 WHERE cluster_id = #{clusterId}") + void deActiveById(ConnectorEntity connectorEntity); - @Delete("DELETE FROM connector WHERE cluster_id = #{clusterId}") - void deleteByClusterId(ConnectorEntity connectorEntity); - - @Delete("") - void batchDelete(List connectorEntities); + @Update({ + "" + }) + void batchDeActive(List connectorEntities); } diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/health/HealthCheckResultMapper.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/health/HealthCheckResultMapper.java new file mode 100644 index 00000000..574f9eef --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/health/HealthCheckResultMapper.java @@ -0,0 +1,89 @@ +/* + * 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.mapper.health; + +import org.apache.eventmesh.dashboard.console.entity.health.HealthCheckResultEntity; + +import org.apache.ibatis.annotations.Insert; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Options; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; +import org.apache.ibatis.annotations.Update; + +import java.sql.Timestamp; +import java.util.List; + +/** + * Mapper for health check result + */ +@Mapper +public interface HealthCheckResultMapper { + + @Select("SELECT * FROM health_check_result WHERE id = #{id}") + HealthCheckResultEntity selectById(HealthCheckResultEntity healthCheckResultEntity); + + @Select("SELECT * FROM health_check_result WHERE cluster_id = #{clusterId} AND type = #{type} AND type_id = #{typeId}") + List selectByClusterIdAndTypeAndTypeId(HealthCheckResultEntity healthCheckResultEntity); + + @Select("SELECT * FROM health_check_result WHERE cluster_id = #{clusterId} AND type = #{type}") + List selectByClusterIdAndType(HealthCheckResultEntity healthCheckResultEntity); + + @Select("SELECT * FROM health_check_result WHERE cluster_id = #{clusterId} AND create_time > #{startTime} AND create_time < #{endTime}") + List selectByClusterIdAndCreateTimeRange(@Param("clusterId") Long clusterId, + @Param("startTime") Timestamp startTime, @Param("endTime") Timestamp endTime); + + @Options(useGeneratedKeys = true, keyProperty = "id") + @Insert("INSERT INTO health_check_result(type,type_id, cluster_id, status,result_desc)" + + " VALUES( #{type}, #{typeId}, #{clusterId}, #{status}, #{resultDesc})") + void insert(HealthCheckResultEntity healthCheckResultEntity); + + @Insert({ + "" + }) + void batchInsert(List healthCheckResultEntityList); + + @Update("UPDATE health_check_result SET status = #{status}, result_desc = #{resultDesc} WHERE id = #{id}") + void update(HealthCheckResultEntity healthCheckResultEntity); + + @Update({ + ""}) + void batchUpdate(List healthCheckResultEntityList); + + @Select({ + "" + }) + List getIdsNeedToBeUpdateByClusterIdAndTypeAndTypeId(List healthCheckResultEntityList); + +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/connection/impl/ConnectionDataServiceDatabaseImpl.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/connection/impl/ConnectionDataServiceDatabaseImpl.java index 780ee990..cf22a831 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/connection/impl/ConnectionDataServiceDatabaseImpl.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/connection/impl/ConnectionDataServiceDatabaseImpl.java @@ -61,7 +61,7 @@ public void replaceAllConnections(List connectionEntityList) { List existingConnections = connectionMapper.selectByClusterId(connectionEntity); // Collect connections that are not in the new list - List connectionsToDelete = existingConnections.stream() + List connectionsToInactive = existingConnections.stream() .filter(existingConnection -> !newConnections.contains(existingConnection)) .collect(Collectors.toList()); @@ -71,8 +71,8 @@ public void replaceAllConnections(List connectionEntityList) { .collect(Collectors.toList()); // Delete connections in batch - if (!connectionsToDelete.isEmpty()) { - connectionMapper.batchDelete(connectionsToDelete); + if (!connectionsToInactive.isEmpty()) { + connectionMapper.batchEndConnectionById(connectionsToInactive); } // Insert new connections in batch diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/health/HealthDataService.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/health/HealthDataService.java new file mode 100644 index 00000000..19e3715e --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/health/HealthDataService.java @@ -0,0 +1,40 @@ +/* + * 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.service.health; + +import org.apache.eventmesh.dashboard.console.entity.health.HealthCheckResultEntity; + +import java.sql.Timestamp; +import java.util.List; + +/** + * Service providing data of HealthCheckResult. + */ +public interface HealthDataService { + HealthCheckResultEntity insertHealthCheckResult(HealthCheckResultEntity healthCheckResultEntity); + + void batchInsertHealthCheckResult(List healthCheckResultEntityList); + + List queryHealthCheckResultByClusterIdAndTypeAndTypeId(HealthCheckResultEntity entity); + + void batchUpdateCheckResult(List healthCheckResultEntityList); + + void batchUpdateCheckResultByClusterIdAndTypeAndTypeId(List healthCheckResultEntityList); + + List queryHealthCheckResultByClusterIdAndTimeRange(Long clusterId, Timestamp startTime, Timestamp endTime); +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/health/HealthDataServiceMemoryStorage.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/health/HealthDataServiceMemoryStorage.java new file mode 100644 index 00000000..85a2667f --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/health/HealthDataServiceMemoryStorage.java @@ -0,0 +1,86 @@ +/* + * 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.service.health; + +import org.apache.eventmesh.dashboard.console.entity.health.HealthCheckResultEntity; + +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.locks.ReentrantReadWriteLock; + +import org.springframework.stereotype.Component; + +@Component +public class HealthDataServiceMemoryStorage { + + private static final List cache = new ArrayList<>(); + private static final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); + + + public HealthCheckResultEntity insertHealthCheckResult(HealthCheckResultEntity healthCheckResultEntity) { + lock.writeLock().lock(); + try { + healthCheckResultEntity.setCreateTime(new Timestamp(System.currentTimeMillis())); + cache.add(healthCheckResultEntity); + return healthCheckResultEntity; + } finally { + lock.writeLock().unlock(); + } + } + + + public void batchInsertHealthCheckResult(List healthCheckResultEntityList) { + lock.writeLock().lock(); + try { + for (HealthCheckResultEntity entity : healthCheckResultEntityList) { + entity.setCreateTime(new Timestamp(System.currentTimeMillis())); + cache.add(entity); + } + } finally { + lock.writeLock().unlock(); + } + } + + + public List queryHealthCheckResultByClusterIdAndTimeRange(Long clusterId, Timestamp startTime, Timestamp endTime) { + lock.readLock().lock(); + try { + List result = new ArrayList<>(); + for (HealthCheckResultEntity entity : cache) { + if (entity.getClusterId().equals(clusterId) && entity.getCreateTime().after(startTime) && entity.getCreateTime().before(endTime)) { + result.add(entity); + } + } + return result; + } finally { + lock.readLock().unlock(); + } + } + + public List popAll() { + lock.writeLock().lock(); + try { + List result = new ArrayList<>(cache); + cache.clear(); + return result; + } finally { + lock.writeLock().unlock(); + } + } +} \ No newline at end of file diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/health/impl/HealthDataServiceDatabaseImpl.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/health/impl/HealthDataServiceDatabaseImpl.java new file mode 100644 index 00000000..f1593cc9 --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/health/impl/HealthDataServiceDatabaseImpl.java @@ -0,0 +1,77 @@ +/* + * 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.service.health.impl; + +import org.apache.eventmesh.dashboard.console.entity.health.HealthCheckResultEntity; +import org.apache.eventmesh.dashboard.console.mapper.health.HealthCheckResultMapper; +import org.apache.eventmesh.dashboard.console.service.health.HealthDataService; + +import java.sql.Timestamp; +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class HealthDataServiceDatabaseImpl implements HealthDataService { + + @Autowired + private HealthCheckResultMapper healthCheckResultMapper; + + @Override + public HealthCheckResultEntity insertHealthCheckResult(HealthCheckResultEntity healthCheckResultEntity) { + healthCheckResultMapper.insert(healthCheckResultEntity); + return healthCheckResultEntity; + } + + @Override + public void batchInsertHealthCheckResult(List healthCheckResultEntityList) { + healthCheckResultMapper.batchInsert(healthCheckResultEntityList); + } + + @Override + public List queryHealthCheckResultByClusterIdAndTypeAndTypeId(HealthCheckResultEntity entity) { + return healthCheckResultMapper.selectByClusterIdAndTypeAndTypeId(entity); + } + + @Override + public void batchUpdateCheckResult(List healthCheckResultEntityList) { + healthCheckResultMapper.batchUpdate(healthCheckResultEntityList); + } + + @Override + public void batchUpdateCheckResultByClusterIdAndTypeAndTypeId(List healthCheckResultEntityList) { + List idsNeedToBeUpdate = healthCheckResultMapper.getIdsNeedToBeUpdateByClusterIdAndTypeAndTypeId( + healthCheckResultEntityList); + idsNeedToBeUpdate.forEach(entity -> { + healthCheckResultEntityList.forEach(updateEntity -> { + if (entity.getClusterId().equals(updateEntity.getClusterId()) && entity.getType().equals(updateEntity.getType()) + && entity.getTypeId().equals(updateEntity.getTypeId())) { + updateEntity.setId(entity.getId()); + } + }); + }); + healthCheckResultMapper.batchUpdate(healthCheckResultEntityList); + } + + + @Override + public List queryHealthCheckResultByClusterIdAndTimeRange(Long clusterId, Timestamp startTime, Timestamp endTime) { + return healthCheckResultMapper.selectByClusterIdAndCreateTimeRange(clusterId, startTime, endTime); + } +} diff --git a/eventmesh-dashboard-console/src/main/resources/application-dev.yml b/eventmesh-dashboard-console/src/main/resources/application-dev.yml index 0ff18a15..f7062d76 100644 --- a/eventmesh-dashboard-console/src/main/resources/application-dev.yml +++ b/eventmesh-dashboard-console/src/main/resources/application-dev.yml @@ -31,8 +31,8 @@ spring: druid: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/eventmesh-dashboard?useSSL=false&useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&zeroDateTimeBehavior=convertToNull&allowPublicKeyRetrieval=true - username: root - password: 123456 + username: ${DB_USERNAME} + password: ${DB_PASSWORD} initial-size: 1 max-active: 50 diff --git a/eventmesh-dashboard-console/src/main/resources/eventmesh-dashboard.sql b/eventmesh-dashboard-console/src/main/resources/eventmesh-dashboard.sql index 96cf1e3f..d1ea2d4b 100644 --- a/eventmesh-dashboard-console/src/main/resources/eventmesh-dashboard.sql +++ b/eventmesh-dashboard-console/src/main/resources/eventmesh-dashboard.sql @@ -14,6 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +DROP TABLE IF EXISTS `group`; CREATE TABLE `group` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id', @@ -31,10 +32,10 @@ CREATE TABLE `group` KEY `cluster_id` (`cluster_id`, `name`) ) ENGINE = InnoDB AUTO_INCREMENT = 322 - DEFAULT CHARSET = utf8mb3 COMMENT ='Group信息表' - + DEFAULT CHARSET = utf8mb3 COMMENT ='Group信息表'; +DROP TABLE IF EXISTS `group_member`; CREATE TABLE `group_member` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id', @@ -51,10 +52,10 @@ 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 = utf8mb3 COMMENT ='GroupMember信息表'; +DROP TABLE IF EXISTS `operation_log`; CREATE TABLE `operation_log` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id', @@ -73,10 +74,10 @@ CREATE TABLE `operation_log` KEY `idx_status` (`status`) ) ENGINE = InnoDB AUTO_INCREMENT = 68 - DEFAULT CHARSET = utf8mb3 COMMENT ='操作记录信息表' - + DEFAULT CHARSET = utf8mb3 COMMENT ='操作记录信息表'; +DROP TABLE IF EXISTS `topic`; CREATE TABLE `topic` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id', @@ -95,8 +96,7 @@ CREATE TABLE `topic` KEY `cluster_id` (`cluster_id`, `topic_name`) ) ENGINE = InnoDB AUTO_INCREMENT = 562 - DEFAULT CHARSET = utf8mb3 COMMENT ='Topic信息表' - + DEFAULT CHARSET = utf8mb3 COMMENT ='Topic信息表'; DROP TABLE IF EXISTS `client`; @@ -121,23 +121,23 @@ CREATE TABLE `client` PRIMARY KEY (`id`), INDEX `idx_cluster_id` (`cluster_id`) ) ENGINE = InnoDB - DEFAULT CHARSET = utf8 COMMENT ='客户端信息表'; + DEFAULT CHARSET = utf8 COMMENT ='client is an SDK application that can produce or consume events.'; DROP TABLE IF EXISTS `connector`; CREATE TABLE `connector` ( - `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'id', - `cluster_id` bigint(20) NOT NULL DEFAULT '-1' COMMENT '集群ID', - `name` varchar(512) NOT NULL DEFAULT '' COMMENT 'Connector名称', - `class_name` varchar(512) NOT NULL DEFAULT '' COMMENT 'Connector类', - `type` varchar(32) NOT NULL DEFAULT '' COMMENT 'Connector类型', - `status` tinyint(4) unsigned NOT NULL DEFAULT '0' COMMENT '状态: 1启用,0未启用', - `pod_state` tinyint(4) unsigned NOT NULL DEFAULT '0' COMMENT 'k8s pod状态。0: pending;1: running;2: success;3: failed;4: unknown', - `config_ids` text NOT NULL DEFAULT '' COMMENT 'csv config id list, like:1,3,7', - `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间', + `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'id', + `cluster_id` bigint(20) NOT NULL DEFAULT '-1' COMMENT '集群ID', + `name` varchar(512) NOT NULL DEFAULT '' COMMENT 'Connector名称', + `class_name` varchar(512) NOT NULL DEFAULT '' COMMENT 'Connector类', + `type` varchar(32) NOT NULL DEFAULT '' COMMENT 'Connector类型', + `status` tinyint(4) unsigned NOT NULL DEFAULT '0' COMMENT '状态: 1启用,0未启用', + `pod_state` tinyint(4) unsigned NOT NULL DEFAULT '0' COMMENT 'k8s pod状态。0: pending;1: running;2: success;3: failed;4: unknown', + `config_ids` text NOT NULL DEFAULT '' COMMENT 'csv config id list, like:1,3,7', + `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间', PRIMARY KEY (`id`), INDEX `idx_cluster_id` (`cluster_id`) ) ENGINE = InnoDB @@ -168,22 +168,22 @@ CREATE TABLE `connection` INDEX `idx_source_id` (`source_id`), INDEX `idx_sink_id` (`sink_id`) ) ENGINE = InnoDB - DEFAULT CHARSET = utf8 COMMENT ='client和connector连接关系,这里的client包括runtime'; + DEFAULT CHARSET = utf8 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` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增id', - `dimension` int(11) NOT NULL DEFAULT '0' COMMENT '检查维度(0:未知,1:Cluster,2:Runtime,3:Topic,4:Group)', - `config_name` varchar(192) NOT NULL DEFAULT '' COMMENT '配置名', + `type` tinyint(4) NOT NULL DEFAULT '0' COMMENT '检查维度(0:未知, 1:Cluster, 2:Runtime, 3:Topic, 4:Storage)', + `type_id` bigint(20) unsigned NOT NULL COMMENT '对应检查维度的实例id', `cluster_id` bigint(20) NOT NULL DEFAULT '0' COMMENT '集群ID', - `res_name` varchar(192) NOT NULL DEFAULT '' COMMENT '资源名称', - `passed` tinyint(4) NOT NULL DEFAULT '0' COMMENT '检查通过(0:未通过,1:通过)', + `status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '检查状态(0:未通过,1:通过,2:正在检查,3:超时)', + `result_desc` text 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 '更新时间', PRIMARY KEY (`id`), INDEX `idx_cluster_id` (`cluster_id`), - UNIQUE KEY `uniq_dimension_config_cluster_res` (`dimension`, `config_name`, `cluster_id`, `res_name`) + INDEX `idx_type` (`type`) ) ENGINE = InnoDB DEFAULT CHARSET = utf8 COMMENT ='健康检查结果'; diff --git a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/mapper/client/ClientMapperTest.java b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/mapper/client/ClientMapperTest.java new file mode 100644 index 00000000..8388de66 --- /dev/null +++ b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/mapper/client/ClientMapperTest.java @@ -0,0 +1,95 @@ +/* + * 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.mapper.client; + +import org.apache.eventmesh.dashboard.console.EventMeshDashboardApplication; +import org.apache.eventmesh.dashboard.console.entity.client.ClientEntity; +import org.apache.eventmesh.dashboard.console.enums.StatusEnum; + +import java.util.List; + +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; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.jdbc.Sql; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +@ExtendWith(SpringExtension.class) +@SpringBootTest(classes = EventMeshDashboardApplication.class) +@ActiveProfiles("test") +@Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, scripts = {"classpath:use-test-schema.sql", "classpath:eventmesh-dashboard.sql"}) +@Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, scripts = "classpath:client-test.sql") +class ClientMapperTest { + + @Autowired + private ClientMapper clientMapper; + + @Test + public void testSelectById() { + ClientEntity clientEntity = new ClientEntity(); + clientEntity.setId(1L); + ClientEntity result = clientMapper.selectById(clientEntity); + Assertions.assertEquals("java", result.getLanguage()); + Assertions.assertEquals(3, result.getClusterId()); + } + + @Test + public void testSelectByClusterId() { + ClientEntity clientEntity = new ClientEntity(); + clientEntity.setClusterId(3L); + List results = clientMapper.selectByClusterId(clientEntity); + Assertions.assertEquals(3, results.size()); + Assertions.assertEquals("java", results.get(0).getLanguage()); + Assertions.assertEquals("go", results.get(2).getLanguage()); + } + + @Test + public void testInsert() { + ClientEntity clientEntity = new ClientEntity(); + clientEntity.setHost("127.0.0.1"); + clientEntity.setClusterId(4L); + clientEntity.setName("clientName"); + clientEntity.setDescription(""); + clientEntity.setPid(1L); + clientEntity.setPort(8080); + clientEntity.setStatusEntity(StatusEnum.ACTIVE); + clientEntity.setConfigIds(""); + clientEntity.setLanguage("rust"); + clientEntity.setPlatform(""); + clientEntity.setProtocol("http"); + clientMapper.insert(clientEntity); + + ClientEntity result = clientMapper.selectById(clientEntity); + Assertions.assertEquals("127.0.0.1", result.getHost()); + + Assertions.assertEquals(2, clientMapper.selectByClusterId(clientEntity).size()); + } + + @Test + public void testDeactivate() { + ClientEntity clientEntity = new ClientEntity(); + clientEntity.setId(1L); + clientMapper.deActive(clientEntity); + ClientEntity result = clientMapper.selectById(clientEntity); + Assertions.assertEquals(0, result.getStatus()); + Assertions.assertNotEquals(result.getCreateTime(), result.getEndTime()); + } +} \ No newline at end of file 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 new file mode 100644 index 00000000..7087e007 --- /dev/null +++ b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/mapper/connection/ConnectionMapperTest.java @@ -0,0 +1,124 @@ +/* + * 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.mapper.connection; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import org.apache.eventmesh.dashboard.console.EventMeshDashboardApplication; +import org.apache.eventmesh.dashboard.console.entity.connection.ConnectionEntity; + + +import java.util.Arrays; +import java.util.List; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.jdbc.Sql; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +@ExtendWith(SpringExtension.class) +@SpringBootTest(classes = EventMeshDashboardApplication.class) +@ActiveProfiles("test") +@Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, scripts = {"classpath:use-test-schema.sql", "classpath:eventmesh-dashboard.sql"}) +@Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, scripts = "classpath:connection-test.sql") +class ConnectionMapperTest { + + @Autowired + private ConnectionMapper connectionMapper; + + @Test + public void testSelectAll() { + assertEquals(6, connectionMapper.selectAll().size()); + } + + @Test + public void testSelectByClusterId() { + ConnectionEntity connectionEntity = new ConnectionEntity(); + connectionEntity.setClusterId(1L); + assertEquals(3, connectionMapper.selectByClusterId(connectionEntity).size()); + } + + @Test + public void testSelectByClusterIdSourceTypeAndSourceId() { + ConnectionEntity connectionEntity = new ConnectionEntity(); + connectionEntity.setClusterId(1L); + connectionEntity.setSourceId(1L); + connectionEntity.setSourceType("connector"); + List results = connectionMapper.selectByClusterIdSourceTypeAndSourceId(connectionEntity); + assertEquals(1, results.size()); + assertEquals("connector", results.get(0).getSinkType()); + assertEquals(1, results.get(0).getSinkId()); + } + + @Test + public void testSelectByClusterIdSinkTypeAndSinkId() { + ConnectionEntity connectionEntity = new ConnectionEntity(); + connectionEntity.setClusterId(1L); + connectionEntity.setSinkId(2L); + connectionEntity.setSinkType("connector"); + List results = connectionMapper.selectByClusterIdSinkTypeAndSinkId(connectionEntity); + assertEquals(1, results.size()); + assertEquals("connector", results.get(0).getSourceType()); + assertEquals(2, results.get(0).getSourceId()); + } + + @Test + public void testInsert() { + ConnectionEntity connectionEntity = new ConnectionEntity(1L, 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"); + connectionMapper.batchInsert(Arrays.asList(connectionEntity1, connectionEntity2)); + assertEquals(8, connectionMapper.selectAll().size()); + } + + @Test + public void testEndConnectionById() { + ConnectionEntity connectionEntity = new ConnectionEntity(); + connectionEntity.setId(1L); + connectionMapper.endConnectionById(connectionEntity); + List results = connectionMapper.selectAll(); + ConnectionEntity result = results.get(0); + assertEquals(1, result.getStatus()); + assertNotNull(result.getEndTime()); + } + + @Test + public void testBatchEndConnection() { + ConnectionEntity connectionEntity1 = new ConnectionEntity(); + connectionEntity1.setId(1L); + ConnectionEntity connectionEntity2 = new ConnectionEntity(); + connectionEntity2.setId(2L); + connectionMapper.batchEndConnectionById(Arrays.asList(connectionEntity1, connectionEntity2)); + + List all = connectionMapper.selectAll(); + assertEquals(1, all.get(0).getStatus()); + assertEquals(1, all.get(1).getStatus()); + assertNotEquals(all.get(0).getCreateTime(), all.get(0).getEndTime()); + } +} \ No newline at end of file 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 new file mode 100644 index 00000000..0bb360b1 --- /dev/null +++ b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/mapper/connector/ConnectorMapperTest.java @@ -0,0 +1,128 @@ +/* + * 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.mapper.connector; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import org.apache.eventmesh.dashboard.console.EventMeshDashboardApplication; +import org.apache.eventmesh.dashboard.console.entity.connector.ConnectorEntity; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.jdbc.Sql; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +@ExtendWith(SpringExtension.class) +@SpringBootTest(classes = EventMeshDashboardApplication.class) +@ActiveProfiles("test") +@Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, scripts = {"classpath:use-test-schema.sql", "classpath:eventmesh-dashboard.sql"}) +@Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, scripts = "classpath:connector-test.sql") +class ConnectorMapperTest { + + @Autowired + private ConnectorMapper connectorMapper; + + @Test + public void testSelectById() { + ConnectorEntity connectorEntity = new ConnectorEntity(); + connectorEntity.setId(1L); + + connectorEntity = connectorMapper.selectById(connectorEntity); + + assertNotNull(connectorEntity); + assertEquals(1L, connectorEntity.getClusterId()); + assertEquals("the", connectorEntity.getClassName()); + } + + @Test + public void testSelectByClusterId() { + ConnectorEntity connectorEntity = new ConnectorEntity(); + connectorEntity.setClusterId(1L); + + List results = connectorMapper.selectByClusterId(connectorEntity); + + assertEquals(3, results.size()); + assertEquals("quick", results.get(1).getClassName()); + } + + @Test + public void testInsert() { + ConnectorEntity connectorEntity = new ConnectorEntity(1L, 1L, "test", "test", "test", 0, 2, "test"); + connectorMapper.insert(connectorEntity); + + assertNotNull(connectorEntity); + assertEquals(6, connectorEntity.getId()); + } + + @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"); + List connectorEntityList = new ArrayList<>(); + connectorEntityList.add(connectorEntity1); + connectorEntityList.add(connectorEntity2); + connectorEntityList.add(connectorEntity3); + + connectorMapper.batchInsert(connectorEntityList); + + ConnectorEntity connectorEntity = new ConnectorEntity(); + connectorEntity.setClusterId(1L); + List results = connectorMapper.selectByClusterId(connectorEntity); + assertEquals(6, results.size()); + } + + @Test + public void testUpdateK8sStatus() { + ConnectorEntity connectorEntity = new ConnectorEntity(); + connectorEntity.setId(1L); + connectorEntity.setPodState(3); + connectorMapper.updatePodState(connectorEntity); + + connectorEntity = connectorMapper.selectById(connectorEntity); + assertEquals(3, connectorEntity.getPodState()); + } + + @Test + public void testUpdateConfigIds() { + ConnectorEntity connectorEntity = new ConnectorEntity(); + connectorEntity.setId(1L); + connectorEntity.setConfigIds("1,3,4,5,6,7"); + connectorMapper.updateConfigIds(connectorEntity); + + connectorEntity = connectorMapper.selectById(connectorEntity); + assertEquals("1,3,4,5,6,7", connectorEntity.getConfigIds()); + } + + @Test + public void testDeActiveById() { + ConnectorEntity connectorEntity = new ConnectorEntity(); + connectorEntity.setId(1L); + connectorMapper.deActiveById(connectorEntity); + + connectorEntity = connectorMapper.selectById(connectorEntity); + assertEquals(1, connectorEntity.getStatus()); + } +} \ No newline at end of file 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 new file mode 100644 index 00000000..49cd6ed1 --- /dev/null +++ b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/mapper/health/HealthCheckResultMapperTest.java @@ -0,0 +1,139 @@ +/* + * 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.mapper.health; + +import static org.junit.jupiter.api.Assertions.*; + +import java.sql.Timestamp; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Arrays; +import java.util.Date; +import java.util.List; +import org.apache.eventmesh.dashboard.console.EventMeshDashboardApplication; +import org.apache.eventmesh.dashboard.console.entity.health.HealthCheckResultEntity; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.jdbc.Sql; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +@ExtendWith(SpringExtension.class) +@SpringBootTest(classes = EventMeshDashboardApplication.class) +@ActiveProfiles("test") +@Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, scripts = {"classpath:use-test-schema.sql", "classpath:eventmesh-dashboard.sql"}) +@Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, scripts = "classpath:health-test.sql") +class HealthCheckResultMapperTest { + + @Autowired + private HealthCheckResultMapper healthCheckResultMapper; + + @Test + public void testSelectById() { + HealthCheckResultEntity healthCheckResultEntity = new HealthCheckResultEntity(); + healthCheckResultEntity.setId(1L); + healthCheckResultEntity = healthCheckResultMapper.selectById(healthCheckResultEntity); + assertEquals(1, healthCheckResultEntity.getId()); + assertEquals(0, healthCheckResultEntity.getStatus()); + } + + @Test + public void testSelectByClusterIdAndTypeAndTypeId() { + HealthCheckResultEntity healthCheckResultEntity = new HealthCheckResultEntity(1L, 1L, 1, 1L, "", 1); + healthCheckResultEntity = healthCheckResultMapper.selectByClusterIdAndTypeAndTypeId(healthCheckResultEntity).get(0); + assertEquals(1, healthCheckResultEntity.getId()); + assertEquals(0, healthCheckResultEntity.getStatus()); + } + + @Test + public void testSelectByClusterIdAndType() { + HealthCheckResultEntity healthCheckResultEntity = new HealthCheckResultEntity(1L, 1L, 1, 1L, "", 1); + List results = healthCheckResultMapper.selectByClusterIdAndType(healthCheckResultEntity); + assertEquals(2, results.size()); + } + + @Test + public void testSelectByClusterIdAndTimeRange() throws ParseException { + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); + Date startDate = dateFormat.parse("2024-02-02 10:56:50"); + Timestamp startTimestamp = new Timestamp(startDate.getTime()); + Date endDate = dateFormat.parse("2024-02-03 10:56:52"); + Timestamp endTimestamp = new Timestamp(endDate.getTime()); + List results = healthCheckResultMapper.selectByClusterIdAndCreateTimeRange(1L, startTimestamp, endTimestamp); + assertEquals(4, results.size()); + } + + @Test + public void testInsert() { + HealthCheckResultEntity healthCheckResultEntity = new HealthCheckResultEntity(1L, 5L, 1, 5L, "", 1); + healthCheckResultMapper.insert(healthCheckResultEntity); + healthCheckResultEntity = healthCheckResultMapper.selectById(healthCheckResultEntity); + assertEquals(7, healthCheckResultEntity.getId()); + } + + @Test + public void testBatchInsert() { + HealthCheckResultEntity healthCheckResultEntity1 = new HealthCheckResultEntity(1L, 1L, 1, 5L, "", 1); + HealthCheckResultEntity healthCheckResultEntity2 = new HealthCheckResultEntity(1L, 1L, 1, 6L, "", 1); + healthCheckResultMapper.batchInsert(Arrays.asList(healthCheckResultEntity1, healthCheckResultEntity2)); + List results = healthCheckResultMapper.selectByClusterIdAndType(healthCheckResultEntity1); + assertEquals(4, results.size()); + } + + @Test + public void testUpdate() { + HealthCheckResultEntity healthCheckResultEntity = new HealthCheckResultEntity(1L, 1L, 1, 1L, "reason", 0); + healthCheckResultMapper.update(healthCheckResultEntity); + healthCheckResultEntity = healthCheckResultMapper.selectByClusterIdAndTypeAndTypeId(healthCheckResultEntity).get(0); + assertEquals(0, healthCheckResultEntity.getStatus()); + } + + @Test + public void testBatchUpdate() { + HealthCheckResultEntity healthCheckResultEntity1 = new HealthCheckResultEntity(1L, 1L, 1, 1L, "reason", 0); + HealthCheckResultEntity healthCheckResultEntity2 = new HealthCheckResultEntity(2L, 1L, 1, 1L, "reason", 0); + healthCheckResultMapper.batchUpdate(Arrays.asList(healthCheckResultEntity1, healthCheckResultEntity2)); + healthCheckResultEntity1 = healthCheckResultMapper.selectById(healthCheckResultEntity1); + healthCheckResultEntity2 = healthCheckResultMapper.selectById(healthCheckResultEntity2); + + assertEquals(0, healthCheckResultEntity1.getStatus()); + assertEquals(0, healthCheckResultEntity2.getStatus()); + } + + @Test + public void testUpdateByClusterIdAndTypeAndTypeId() { + HealthCheckResultEntity entity1 = new HealthCheckResultEntity(null, 1L, 1, 1L, "reason", 2); + HealthCheckResultEntity entity2 = new HealthCheckResultEntity(null, 1L, 1, 1L, "reason", 2); + healthCheckResultMapper.batchInsert(Arrays.asList(entity1, entity2)); + + List toBeUpdate = healthCheckResultMapper.getIdsNeedToBeUpdateByClusterIdAndTypeAndTypeId( + Arrays.asList(entity1, entity2)); + + toBeUpdate.forEach(entity -> entity.setStatus(2)); + + healthCheckResultMapper.batchUpdate(toBeUpdate); + entity1.setId(7L); + assertEquals(2, healthCheckResultMapper.selectById(entity1).getStatus()); + entity2.setId(1L); + assertEquals(0, healthCheckResultMapper.selectById(entity2).getStatus()); + } + +} \ No newline at end of file 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 new file mode 100644 index 00000000..e4fb11c1 --- /dev/null +++ b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/mapper/meta/MetaMapperTest.java @@ -0,0 +1,49 @@ +/* + * 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.mapper.meta; + +import static org.junit.jupiter.api.Assertions.*; + +import org.apache.eventmesh.dashboard.console.EventMeshDashboardApplication; +import org.apache.eventmesh.dashboard.console.entity.meta.MetaEntity; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.jdbc.Sql; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +@ExtendWith(SpringExtension.class) +@SpringBootTest(classes = EventMeshDashboardApplication.class) +@ActiveProfiles("test") +@Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, scripts = {"classpath:use-test-schema.sql", "classpath:eventmesh-dashboard.sql"}) +@Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, scripts = "classpath:meta-test.sql") +class MetaMapperTest { + + @Autowired + private MetaMapper metaMapper; + + @Test + public void testSelectByClusterId() { + MetaEntity metaEntity = new MetaEntity(); + metaEntity.setClusterId(1L); + metaEntity = metaMapper.selectByClusterId(metaEntity); + } +} \ No newline at end of file diff --git a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/service/connection/impl/ConnectionDataServiceDatabaseImplTest.java b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/service/connection/impl/ConnectionDataServiceDatabaseImplTest.java new file mode 100644 index 00000000..78cee9d1 --- /dev/null +++ b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/service/connection/impl/ConnectionDataServiceDatabaseImplTest.java @@ -0,0 +1,65 @@ +/* + * 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.service.connection.impl; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.apache.eventmesh.dashboard.console.entity.connection.ConnectionEntity; + +import java.util.List; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.jdbc.Sql; +import org.springframework.test.context.junit.jupiter.SpringExtension; + + + +@ExtendWith(SpringExtension.class) +@ActiveProfiles("test") +@Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, scripts = "classpath:connection-test.sql") +@SpringBootTest +public class ConnectionDataServiceDatabaseImplTest { + + @Autowired + private ConnectionDataServiceDatabaseImpl connectionServiceDatabaseImpl; + + @Test + public void testGetAllConnectionsByClusterId() { + List connectionEntityList = connectionServiceDatabaseImpl.getAllConnectionsByClusterId(1L); + assertEquals(3, connectionEntityList.size()); + } + + @Test + public void testGetAllConnections() { + List connectionEntityList = connectionServiceDatabaseImpl.getAllConnections(); + assertEquals(6, connectionEntityList.size()); + } + + @Test + public void testReplaceAllConnections() { + List connectionEntityList = connectionServiceDatabaseImpl.getAllConnectionsByClusterId(1L); + //change ClusterId into 2 + connectionEntityList.forEach(connectionEntity -> connectionEntity.setClusterId(2L)); + connectionServiceDatabaseImpl.replaceAllConnections(connectionEntityList); + assertEquals(8, connectionServiceDatabaseImpl.getAllConnections().size()); + } +} \ No newline at end of file diff --git a/eventmesh-dashboard-console/src/test/resources/client-test.sql b/eventmesh-dashboard-console/src/test/resources/client-test.sql new file mode 100644 index 00000000..234a3c74 --- /dev/null +++ b/eventmesh-dashboard-console/src/test/resources/client-test.sql @@ -0,0 +1,29 @@ +/* + * 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. + */ + +DELETE +FROM `eventmesh-dashboard-test`.client +WHERE TRUE; +ALTER TABLE `eventmesh-dashboard-test`.client + AUTO_INCREMENT = 1; + +insert into `eventmesh-dashboard-test`.client (id, cluster_id, name, platform, language, pid, host, port, protocol, status, config_ids, description, + create_time, end_time, update_time) +values (1, 3, '', '', 'java', -1, '', -1, '', 1, '', '', '2024-02-02 15:15:15', '2024-02-02 15:15:15', '2024-02-02 15:15:15'), + (2, 3, '', '', 'java', -1, '', -1, '', 1, '', '', '2024-02-02 15:15:15', '2024-02-02 15:15:15', '2024-02-02 15:15:15'), + (3, 3, '', '', 'go', -1, '', -1, '', 1, '', '', '2024-02-02 15:15:15', '2024-02-02 15:15:15', '2024-02-02 15:15:15'), + (4, 4, '', '', 'go', -1, '', -1, '', 1, '', '', '2024-02-02 15:15:15', '2024-02-02 15:15:15', '2024-02-02 15:15:15'); \ No newline at end of file diff --git a/eventmesh-dashboard-console/src/test/resources/connectiontest.sql b/eventmesh-dashboard-console/src/test/resources/connection-test.sql similarity index 100% rename from eventmesh-dashboard-console/src/test/resources/connectiontest.sql rename to eventmesh-dashboard-console/src/test/resources/connection-test.sql diff --git a/eventmesh-dashboard-console/src/test/resources/connector-test.sql b/eventmesh-dashboard-console/src/test/resources/connector-test.sql new file mode 100644 index 00000000..93403b6c --- /dev/null +++ b/eventmesh-dashboard-console/src/test/resources/connector-test.sql @@ -0,0 +1,25 @@ +/* + * 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. + */ +DELETE FROM `eventmesh-dashboard-test`.connection WHERE TRUE; +ALTER TABLE `eventmesh-dashboard-test`.connection AUTO_INCREMENT = 1; + +insert into `eventmesh-dashboard-test`.connector (id, cluster_id, name, class_name, type, status, pod_state, config_ids, create_time, update_time) +values (1, 1, '', 'the', '', 1, 1, '', '2024-02-02 16:43:45', '2024-02-02 16:53:02'), + (2, 1, '', 'quick', '', 1, 1, '', '2024-02-02 16:43:45', '2024-02-02 16:53:02'), + (3, 1, '', 'brown', '', 1, 2, '', '2024-02-02 16:43:45', '2024-02-02 16:53:02'), + (4, 2, '', 'fox', '', 1, 2, '', '2024-02-02 16:43:45', '2024-02-02 16:53:02'), + (5, 3, '', 'jumps', '', 1, 3, '', '2024-02-02 16:43:45', '2024-02-02 16:53:02'); \ No newline at end of file diff --git a/eventmesh-dashboard-console/src/test/resources/health-test.sql b/eventmesh-dashboard-console/src/test/resources/health-test.sql new file mode 100644 index 00000000..1c0b6a3e --- /dev/null +++ b/eventmesh-dashboard-console/src/test/resources/health-test.sql @@ -0,0 +1,26 @@ +/* + * 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. + */ +DELETE FROM `eventmesh-dashboard-test`.health_check_result WHERE TRUE; +ALTER TABLE `eventmesh-dashboard-test`.health_check_result AUTO_INCREMENT = 1; + +insert into `eventmesh-dashboard-test`.health_check_result (id, type, type_id, cluster_id, status, result_desc, create_time, update_time) +values (1, 1, 1, 1, 0, '', '2024-02-02 18:56:50', '2024-02-02 18:56:50'), + (2, 2, 2, 1, 1, '', '2024-02-02 18:56:50', '2024-02-02 18:56:50'), + (3, 3, 3, 1, 1, '', '2024-02-02 18:56:50', '2024-02-02 18:56:50'), + (4, 4, 4, 1, 1, '', '2024-02-02 18:56:50', '2024-02-02 18:56:50'), + (5, 1, 2, 1, 1, '', '2024-02-04 18:56:50', '2024-02-02 19:33:13'), + (6, 4, 2, 2, 0, '', '2024-02-04 18:56:50', '2024-02-02 19:33:13'); \ No newline at end of file diff --git a/eventmesh-dashboard-console/src/test/resources/meta-test.sql b/eventmesh-dashboard-console/src/test/resources/meta-test.sql new file mode 100644 index 00000000..d169c735 --- /dev/null +++ b/eventmesh-dashboard-console/src/test/resources/meta-test.sql @@ -0,0 +1,23 @@ +/* + * 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. + */ + +DELETE FROM `eventmesh-dashboard-test`.meta WHERE TRUE; +ALTER TABLE `eventmesh-dashboard-test`.meta AUTO_INCREMENT = 1; + +insert into `eventmesh-dashboard-test`.meta (id, name, type, version, cluster_id, host, port, role, username, params, status, create_time, update_time) +values (1, '1', 'nacos', '1.0', 1, '', -1, '-1', '', '', 0, '2024-02-03 10:30:02', '2024-02-03 10:30:02'), + (2, '2', 'zookeeper', '1.0', 1, '', -1, '-1', '', '', 0, '2024-02-03 10:30:02', '2024-02-03 10:30:02'); \ No newline at end of file diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/scheduler/health/HealthCheckScheduler.java b/eventmesh-dashboard-console/src/test/resources/use-test-schema.sql similarity index 79% rename from eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/scheduler/health/HealthCheckScheduler.java rename to eventmesh-dashboard-console/src/test/resources/use-test-schema.sql index 7263f7cd..a23fc749 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/scheduler/health/HealthCheckScheduler.java +++ b/eventmesh-dashboard-console/src/test/resources/use-test-schema.sql @@ -15,14 +15,4 @@ * limitations under the License. */ -package org.apache.eventmesh.dashboard.console.scheduler.health; - -import org.springframework.stereotype.Component; - -import lombok.extern.slf4j.Slf4j; - -@Slf4j -@Component -public class HealthCheckScheduler { - -} +USE `eventmesh-dashboard-test`