Skip to content

Commit

Permalink
[ISSUE #30] modify mappers and add test (#38)
Browse files Browse the repository at this point in the history
* test: add mappers' tests.

improved connection, connector, client, meta, health mappers and add their unit tests.

* fix: rename database name

rename test database name to `eventmesh_dashboard_test`

* fix: modify text default value into an literal expression

* fix: remove endtime field from client mapper insert method

* style: unify mapper style

array format when using dynamic scripts (<script>)
`+` format when using simple statements
  • Loading branch information
Lambert-Rao committed Feb 20, 2024
1 parent 0d1ebbf commit e952af2
Show file tree
Hide file tree
Showing 35 changed files with 1,343 additions and 177 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ jobs:

services:
mysql:
image: mysql:8
image: mysql:8.0
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
MYSQL_DATABASE: eventmesh_dashboard_test
MYSQL_ROOT_PASSWORD: password
ports:
# https://docs.github.com/en/actions/using-containerized-services/about-service-containers
Expand Down
35 changes: 30 additions & 5 deletions eventmesh-dashboard-console/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- ASP dependency -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>5.1.2.RELEASE</version>
</dependency>

<!-- swagger -->
<dependency>
Expand Down Expand Up @@ -70,19 +76,38 @@
<scope>runtime</scope>
</dependency>

<!-- health check client -->
<!-- Eventmesh SDK -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>5.1.2.RELEASE</version>
<groupId>org.apache.eventmesh</groupId>
<artifactId>eventmesh-sdk-java</artifactId>
<version>1.10.0-release</version>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit-dep</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- storage redis client -->
<dependency>
<groupId>io.lettuce</groupId>
<artifactId>lettuce-core</artifactId>
</dependency>
<!-- health check client end -->


<!-- TODO: remove junit4 dependency -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>


</dependencies>

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

}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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 HealthCheckType {
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 (HealthCheckType healthCheckTypeEnum : HealthCheckType.values()) {
if (healthCheckTypeEnum.name.equals(name)) {
return healthCheckTypeEnum.number;
}
}
return UNKNOWN.number;
}

public static String toName(Integer number) {
for (HealthCheckType healthCheckTypeEnum : HealthCheckType.values()) {
if (healthCheckTypeEnum.number.equals(number)) {
return healthCheckTypeEnum.name;
}
}
return UNKNOWN.name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,41 +19,37 @@

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.
*/
@Mapper
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<ClientEntity> selectByClusterId(ClientEntity clientEntity);

@Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
@Insert(
"INSERT INTO `client` (`cluster_id`, `name`, `platform`,"
+ " `language`, `pid`, `host`, `port`, `protocol`,"
+ " `status`, `config_ids`, `description`, `end_time`) "
+ "`language`, `pid`, `host`, `port`, `protocol`,"
+ "`status`, `config_ids`, `description`) "
+ "VALUES (#{clusterId}, #{name}, #{platform},"
+ " #{language}, #{pid}, #{host}, #{port}, #{protocol},"
+ " #{status}, #{configIds}, #{description}, #{endTime})")
+ "#{language}, #{pid}, #{host}, #{port}, #{protocol},"
+ "#{status}, #{configIds}, #{description})")
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);
}
Loading

0 comments on commit e952af2

Please sign in to comment.