Skip to content

Commit

Permalink
style: sql entities mapper improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
Lambert-Rao committed Mar 7, 2024
1 parent 62a478d commit f75c394
Show file tree
Hide file tree
Showing 20 changed files with 268 additions and 75 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
services:
mysql:
image: mysql:8.0
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_bin
env:
# The MySQL docker container requires these environment variables to be set, so we can create and migrate the test database.
MYSQL_DATABASE: eventmesh_dashboard_test
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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";
}
Original file line number Diff line number Diff line change
@@ -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";
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@
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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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<MetaEntity> 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)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<ConnectorEntity> connectorEntityList = new ArrayList<>();
connectorEntityList.add(connectorEntity1);
connectorEntityList.add(connectorEntity2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -58,15 +58,15 @@ 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());
}

@Test
public void testSelectByClusterIdAndType() {
HealthCheckResultEntity healthCheckResultEntity = new HealthCheckResultEntity(1L, 1L, 1, 1L, "", 1);
HealthCheckResultEntity healthCheckResultEntity = new HealthCheckResultEntity(1L, 1, 1L, "", 1);
List<HealthCheckResultEntity> results = healthCheckResultMapper.selectByClusterIdAndType(healthCheckResultEntity);
assertEquals(2, results.size());
}
Expand All @@ -84,33 +84,35 @@ 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());
}

@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<HealthCheckResultEntity> results = healthCheckResultMapper.selectByClusterIdAndType(healthCheckResultEntity1);
assertEquals(4, results.size());
}

@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());
}

@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);
Expand All @@ -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<HealthCheckResultEntity> toBeUpdate = healthCheckResultMapper.getIdsNeedToBeUpdateByClusterIdAndTypeAndTypeId(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
}
}
Loading

0 comments on commit f75c394

Please sign in to comment.