Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #30] modify mappers and add test #31

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.9.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 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,25 @@

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(
Expand All @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -34,15 +35,28 @@
@Mapper
public interface ConnectionMapper {

@Select("SELECT * FROM connection WHERE id = #{id}")
ConnectionEntity selectById(ConnectionEntity connectionEntity);

@Select("SELECT * FROM connection")
List<ConnectionEntity> selectAll();

@Select("SELECT * FROM connection WHERE cluster_id = #{clusterId}")
List<ConnectionEntity> selectByClusterId(ConnectionEntity connectionEntity);

@Select("SELECT * FROM connection WHERE cluster_id = #{clusterId} AND source_id = #{sourceId} AND source_type = #{sourceType}")
public List<ConnectionEntity> selectByClusterIdSourceTypeAndSourceId(ConnectionEntity connectionEntity);

@Select("SELECT * FROM connection WHERE cluster_id = #{clusterId} AND sink_id = #{sinkId} AND sink_type = #{sinkType}")
public List<ConnectionEntity> 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<ConnectionEntity> 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<ConnectionEntity> 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)"
Expand All @@ -64,21 +78,14 @@ public interface ConnectionMapper {
+ "</script>")
void batchInsert(List<ConnectionEntity> 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("<script>"
+ "DELETE FROM connection WHERE id IN "
+ "<foreach item='item' index='index' collection='list' open='(' separator=',' close=')'>"
+ "#{item.id}"
+ "</foreach>"
+ "</script>")
void batchDelete(List<ConnectionEntity> connectionEntityList);
//batch end
@Update({
"<script><foreach collection='list' item='connectionEntity' index='index' separator=';'>",
"UPDATE connection SET status = 1, end_time = NOW() WHERE id = #{connectionEntity.id}",
"</foreach></script>"})
void batchEndConnectionById(List<ConnectionEntity> connectionEntityList);

}
Loading
Loading