diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/cluster/ClusterEntity.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/cluster/ClusterEntity.java new file mode 100644 index 00000000..f81237d9 --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/cluster/ClusterEntity.java @@ -0,0 +1,56 @@ +/* + * 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.cluster; + +import java.sql.Timestamp; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class ClusterEntity { + + private Long id; + + private String name; + + private String registerNameList; + + private String bootstrapServers; + + private String eventmeshVersion; + + private String clientProperties; + + private String jmxProperties; + + private String regProperties; + + private String description; + + private Integer authType; + + private Integer runState; + + private Timestamp createTime; + + private Timestamp updateTime; +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/config/ConfigEntity.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/config/ConfigEntity.java new file mode 100644 index 00000000..dd726a8f --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/config/ConfigEntity.java @@ -0,0 +1,66 @@ +/* + * 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.config; + +import java.sql.Timestamp; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@NoArgsConstructor +@AllArgsConstructor +@Data +public class ConfigEntity { + + private Long id; + + private Long clusterId; + + private String businessType; + + private Integer instanceType; + + private Long instanceId; + + private String configName; + + private String configValue; + + private String startVersion; + + private String eventmeshVersion; + + private Integer status; + + private String endVersion; + + private Integer diffType; + + private String description; + + private Integer edit; + + private Timestamp createTime; + + private Timestamp updateTime; + + private Integer isDefault; + + private Integer isModify; +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/runtime/RuntimeEntity.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/runtime/RuntimeEntity.java new file mode 100644 index 00000000..e070075d --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/runtime/RuntimeEntity.java @@ -0,0 +1,54 @@ +/* + * 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.runtime; + +import java.sql.Timestamp; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class RuntimeEntity { + + private Long id; + + private Long clusterId; + + private String host; + + private Long storageClusterId; + + private Integer port; + + private Integer jmxPort; + + private Long startTimestamp; + + private String rack; + + private Integer status; + + private Timestamp createTime; + + private Timestamp updateTime; + + private String endpointMap; +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/storage/StoreEntity.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/storage/StoreEntity.java new file mode 100644 index 00000000..dd7f4d21 --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/storage/StoreEntity.java @@ -0,0 +1,63 @@ +/* + * 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.storage; + + +import java.sql.Timestamp; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class StoreEntity { + + private Long id; + + private Long clusterId; + + private Integer storeId; + + private String storeType; + + private String host; + + private Long runtimeId; + + private String topicList; + + private Short diffType; + + private Integer port; + + private Integer jmxPort; + + private String rack; + + private Short status; + + private Timestamp createTime; + + private Timestamp updateTime; + + private String endpointMap; + + private Long startTimestamp; +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/cluster/ClusterMapper.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/cluster/ClusterMapper.java new file mode 100644 index 00000000..eea050a8 --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/cluster/ClusterMapper.java @@ -0,0 +1,58 @@ +/* + * 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.cluster; + +import org.apache.eventmesh.dashboard.console.entity.cluster.ClusterEntity; + +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; + +/** + * cluster table operation + */ +@Mapper +public interface ClusterMapper { + + @Select("SELECT * FROM cluster WHERE is_delete=0") + List selectAllCluster(); + + @Select("SELECT * FROM cluster WHERE id=#{id} AND is_delete=0") + ClusterEntity selectClusterById(ClusterEntity cluster); + + @Insert("INSERT INTO cluster (name, register_name_list, bootstrap_servers, eventmesh_version, client_properties, " + + "jmx_properties, reg_properties, description, auth_type, run_state) VALUES (#{name},#{registerNameList}," + + "#{bootstrapServers},#{eventmeshVersion},#{clientProperties},#{jmxProperties},#{regProperties},#{description},#{authType},#{runState})") + @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id") + void addCluster(ClusterEntity cluster); + + @Update("UPDATE cluster SET name =#{name},reg_properties=#{regProperties},bootstrap_servers=#{bootstrapServers}," + + "eventmesh_version=#{eventmeshVersion},client_properties=#{clientProperties},jmx_properties=#{jmxProperties}," + + "reg_properties=#{regProperties},description=#{description},auth_type=#{authType},run_state=#{runState} ," + + "register_name_list=#{registerNameList} WHERE id=#{id}") + void updateClusterById(ClusterEntity cluster); + + @Delete("UPDATE cluster SET is_delete=1 WHERE id=#{id}") + void deleteClusterById(ClusterEntity clusterEntity); + +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/config/ConfigMapper.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/config/ConfigMapper.java new file mode 100644 index 00000000..e7ee325e --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/config/ConfigMapper.java @@ -0,0 +1,60 @@ +/* + * 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.config; + +import org.apache.eventmesh.dashboard.console.entity.config.ConfigEntity; + +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; + +/** + * config table operation + */ +@Mapper +public interface ConfigMapper { + + @Insert("INSERT INTO config (cluster_id, business_type, instance_type, instance_id, config_name," + + " config_value, start_version,eventmesh_version, description, edit,end_version,is_default,is_modify) VALUE " + + "(#{clusterId},#{businessType},#{instanceType},#{instanceId},#{configName}," + + "#{configValue},#{startVersion},#{eventmeshVersion},#{description},#{edit},#{endVersion},#{isDefault},#{isModify})") + @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id") + Integer addConfig(ConfigEntity configEntity); + + @Update("UPDATE config SET status=2 WHERE id=#{id}") + Integer deleteConfig(ConfigEntity configEntity); + + @Update("UPDATE config SET config_value=#{configValue} WHERE status=1 AND edit=2") + void updateConfig(ConfigEntity configEntity); + + @Select("SELECT * FROM config WHERE business_type=#{businessType} AND instance_type=#{instanceType} " + + "AND instance_id=#{instanceId}") + List selectByInstanceId(ConfigEntity configEntity); + + @Select("SELECT * FROM config WHERE cluster_id=-1 AND business_type=#{businessType} AND instance_type=#{instanceType}") + List selectDefaultConfig(ConfigEntity configEntity); + + + @Select("SELECT * FROM config WHERE cluster_id=#{clusterId} AND instance_type=#{instanceType} " + + "AND instance_id=#{instanceId} AND config_name=#{configName} AND status=1") + ConfigEntity selectByUnique(ConfigEntity configEntity); +} 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 fc6756a2..82ebc5c3 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 @@ -35,6 +35,9 @@ @Mapper public interface ConnectionMapper { + @Select("SELECT COUNT(*) FROM connection WHERE cluster_id=#{clusterId}") + Integer selectConnectionNumByCluster(ConnectionEntity connectionEntity); + @Select("SELECT * FROM connection") List selectAll(); diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/group/OprGroupMapper.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/group/OprGroupMapper.java index 78128619..321e76c9 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/group/OprGroupMapper.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/group/OprGroupMapper.java @@ -36,36 +36,36 @@ public interface OprGroupMapper { @Insert("INSERT INTO `group` (cluster_id, name, member_count, members, type, state)" + "VALUE (#{clusterId},#{name},#{memberCount},#{members},#{type},#{state}) " - + "on duplicate key update is_delete=0") + + "ON DUPLICATE KEY UPDATE is_delete=0") @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id") void addGroup(GroupEntity groupEntity); - @Update("update `group`set member_count=#{memberCount}," - + "members=#{members},type=#{type},state=#{state} where id=#{id}") + @Update("UPDATE `group` SET member_count=#{memberCount}," + + "members=#{members},type=#{type},state=#{state} WHERE id=#{id}") @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id") Integer updateGroup(GroupEntity groupEntity); - @Delete("update `group` set is_delete=1 where id=#{id}") + @Delete("UPDATE `group` SET is_delete=1 WHERE id=#{id}") @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id") Integer deleteGroup(GroupEntity groupEntity); - @Select("select * from `group` where cluster_id=#{clusterId} and name=#{name} and is_delete=0") + @Select("SELECT * FROM `group` WHERE cluster_id=#{clusterId} AND name=#{name} AND is_delete=0") GroupEntity selectGroupByUnique(GroupEntity groupEntity); - @Select("select * from `group` where id=#{id} and is_delete=0") + @Select("SELECT * FROM `group` WHERE id=#{id} AND is_delete=0") GroupEntity selectGroupById(GroupEntity groupEntity); @Select({ ""}) List selectGroup(GroupEntity groupEntity); diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/groupmember/OprGroupMemberMapper.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/groupmember/OprGroupMemberMapper.java index aac0a592..b3dab8aa 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/groupmember/OprGroupMemberMapper.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/groupmember/OprGroupMemberMapper.java @@ -36,47 +36,47 @@ @Mapper public interface OprGroupMemberMapper { - @Select("select * from group_member where cluster_id=#{clusterId} and is_delete=0") + @Select("SELECT * FROM group_member WHERE cluster_id=#{clusterId} AND is_delete=0") List getGroupByClusterId(GroupMemberEntity groupMemberEntity); - @Insert("insert into group_member (cluster_id, topic_name, group_name, eventmesh_user,state)" + @Insert("INSERT INTO group_member (cluster_id, topic_name, group_name, eventmesh_user,state)" + " VALUE (#{clusterId},#{topicName},#{groupName},#{eventMeshUser},#{state})" - + "on duplicate key update is_delete=0") + + "ON DUPLICATE KEY UPDATE is_delete=0") @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id") void addGroupMember(GroupMemberEntity groupMemberEntity); - @Update("update group_member set state=#{state} where id=#{id}") + @Update("UPDATE group_member SET state=#{state} WHERE id=#{id}") @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id") void updateGroupMember(GroupMemberEntity groupMemberEntity); - @Delete("update group_member set is_delete=1 where id=#{id} ") + @Delete("UPDATE group_member SET is_delete=1 WHERE id=#{id} ") @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id") GroupMemberEntity deleteGroupMember(GroupMemberEntity groupMemberEntity); - @Select("select * from group_member where cluster_id=#{clusterId} and group_name=#{groupName} and topic_name=#{topicName} and is_delete=0") + @Select("SELECT * FROM group_member WHERE cluster_id=#{clusterId} AND group_name=#{groupName} AND topic_name=#{topicName} AND is_delete=0") GroupMemberEntity selectGroupMemberByUnique(GroupMemberEntity groupMemberEntity); - @Select("select * from group_member where id=#{id} and is_delete=0") + @Select("SELECT * FROM group_member WHERE id=#{id} AND is_delete=0") GroupMemberEntity selectGroupMemberById(GroupMemberEntity groupMemberEntity); @Select({ ""}) List selectMember(GroupMemberEntity groupMemberEntity); - @Update("update group_member set state=#{state} where topic_name=#{topicName}") + @Update("UPDATE group_member SET state=#{state} WHERE topic_name=#{topicName}") void updateMemberByTopic(GroupMemberEntity groupMemberEntity); } \ No newline at end of file diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/log/OprLogMapper.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/log/OprLogMapper.java index 8f2dbf4e..fcc7dc98 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/log/OprLogMapper.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/log/OprLogMapper.java @@ -21,8 +21,8 @@ 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.SelectKey; import org.apache.ibatis.annotations.Update; import java.util.List; @@ -35,27 +35,27 @@ public interface OprLogMapper { @Select({ ""}) List getLogList(LogEntity logEntity); - @Insert("insert into operation_log ( cluster_id, operation_type,target_Type, description,operation_user,result_content)" - + "VALUE (#{clusterId},#{operationType},#{targetType},#{description},#{operationUser},#{resultContent})") - @SelectKey(keyColumn = "id", statement = {" select last_insert_id()"}, keyProperty = "id", before = false, resultType = Long.class) + @Insert("INSERT INTO operation_log ( cluster_id, operation_type,target_Type, content,operation_user,result)" + + "VALUE (#{clusterId},#{operationType},#{targetType},#{content},#{operationUser},#{result})") + @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id") Long addLog(LogEntity logEntity); - @Update("update operation_log set status=#{status} ,result_content=#{resultContent} where id=#{id}") + @Update("UPDATE operation_log SET status=#{status} ,result=#{resultContent} WHERE id=#{id}") Integer updateLog(LogEntity logEntity); } diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/runtime/RuntimeMapper.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/runtime/RuntimeMapper.java new file mode 100644 index 00000000..a9db87f6 --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/runtime/RuntimeMapper.java @@ -0,0 +1,51 @@ +/* + * 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.runtime; + +import org.apache.eventmesh.dashboard.console.entity.runtime.RuntimeEntity; + +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; + +/** + * runtime table operation + */ +@Mapper +public interface RuntimeMapper { + + @Insert("INSERT INTO runtime (cluster_id, host, storage_cluster_id, port, jmx_port, start_timestamp, rack, status, " + + "endpoint_map) VALUES(#{clusterId},#{host},#{storageClusterId},#{port},#{jmxPort},#{startTimestamp},#{rack},#{status},#{endpointMap})") + @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id") + void addRuntime(RuntimeEntity runtimeEntity); + + @Select("SELECT * FROM runtime WHERE cluster_id=#{clusterId} AND is_delete=0") + List selectRuntimeByCluster(RuntimeEntity runtimeEntity); + + @Update("UPDATE runtime SET port=#{port} ,jmx_port=#{jmxPort} ,status=#{status} WHERE cluster_id=#{clusterId} AND is_delete=0") + void updateRuntimeByCluster(RuntimeEntity runtimeEntity); + + @Delete("UPDATE runtime SET is_delete=1 WHERE cluster_id=#{clusterId}") + void deleteRuntimeByCluster(RuntimeEntity runtimeEntity); + +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/storage/StoreMapper.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/storage/StoreMapper.java new file mode 100644 index 00000000..0207903d --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/storage/StoreMapper.java @@ -0,0 +1,51 @@ +/* + * 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.storage; + +import org.apache.eventmesh.dashboard.console.entity.storage.StoreEntity; + +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; + +/** + * store table operation + */ +@Mapper +public interface StoreMapper { + + @Insert("INSERT INTO store (cluster_id, store_id, store_type, host, runtime_id, topic_list, diff_type" + + ", port, jmx_port, start_timestamp, rack, status, endpoint_map ) VALUES (" + + "#{clusterId},#{storeId},#{storeType},#{host},#{runtimeId},#{topicList},#{diffType},#{port},#{jmxPort}" + + ",#{startTimestamp},#{rack},#{status},#{endpointMap})") + @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id") + void addStore(StoreEntity storeEntity); + + @Update("UPDATE store SET is_delete=1 WHERE cluster_id=#{clusterId} AND store_id=#{storeId}") + void deleteStoreByUnique(StoreEntity storeEntity); + + @Select("SELECT * FROM store WHERE cluster_id=#{clusterId} AND is_delete=0") + List selectStoreByCluster(StoreEntity storeEntity); + + @Update("UPDATE store SET status=#{status} WHERE cluster_id=#{clusterId} AND store_id=#{storeId}") + void updateStoreByUnique(StoreEntity storeEntity); +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/topic/TopicMapper.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/topic/TopicMapper.java index 42d68d0d..0fe2cadc 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/topic/TopicMapper.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/topic/TopicMapper.java @@ -35,37 +35,43 @@ @Mapper public interface TopicMapper { + @Select("SELECT count(*) FROM topic WHERE cluster_id=#{clusterId}") + Integer selectTopicNumByCluster(TopicEntity topicEntity); + @Select({ ""}) List getTopicList(TopicEntity topicEntity); @Insert("INSERT INTO topic (cluster_id, topic_name, runtime_id, storage_id, retention_ms, type, description) " + "VALUE (#{clusterId},#{topicName},#{runtimeId},#{storageId},#{retentionMs},#{type},#{description})" - + "on duplicate key update is_delete = 0") + + "ON DUPLICATE KEY UPDATE is_delete = 0") @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id") void addTopic(TopicEntity topicEntity); - @Update("update topic set type=#{type},description=#{description} where id=#{id}") + @Update("UPDATE topic SET type=#{type},description=#{description} WHERE id=#{id}") void updateTopic(TopicEntity topicEntity); - @Delete("update `topic` set is_delete=1 where id=#{id}") + @Delete("UPDATE `topic` SET is_delete=1 WHERE id=#{id}") void deleteTopic(TopicEntity topicEntity); - @Select("select * from topic where cluster_id=#{clusterId} and topic_name=#{topicName}") + @Select("SELECT * FROM topic WHERE cluster_id=#{clusterId} AND topic_name=#{topicName}") TopicEntity selectTopicByUnique(TopicEntity topicEntity); - @Select("select * from topic where id=#{id}") + @Select("SELECT * FROM topic WHERE id=#{id}") TopicEntity selectTopicById(TopicEntity topicEntity); + @Select("SELECT * FROM topic WHERE cluster_id=#{clusterId}") + List selectTopicByCluster(TopicEntity topicEntity); + } \ No newline at end of file diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/cluster/ClusterService.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/cluster/ClusterService.java new file mode 100644 index 00000000..6f0d7cf3 --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/cluster/ClusterService.java @@ -0,0 +1,38 @@ +/* + * 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.cluster; + +import org.apache.eventmesh.dashboard.console.entity.cluster.ClusterEntity; + +import java.util.List; + +/** + * cluster data service + */ +public interface ClusterService { + + void addCluster(ClusterEntity cluster); + + List selectAllCluster(); + + ClusterEntity selectClusterById(ClusterEntity cluster); + + void updateClusterById(ClusterEntity cluster); + + void deleteClusterById(ClusterEntity cluster); +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/cluster/impl/ClusterServiceImpl.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/cluster/impl/ClusterServiceImpl.java new file mode 100644 index 00000000..b669c4e6 --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/cluster/impl/ClusterServiceImpl.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.eventmesh.dashboard.console.service.cluster.impl; + +import org.apache.eventmesh.dashboard.console.entity.cluster.ClusterEntity; +import org.apache.eventmesh.dashboard.console.mapper.cluster.ClusterMapper; +import org.apache.eventmesh.dashboard.console.service.cluster.ClusterService; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + + +@Service +public class ClusterServiceImpl implements ClusterService { + + @Autowired + private ClusterMapper clusterMapper; + + @Override + public void addCluster(ClusterEntity cluster) { + clusterMapper.addCluster(cluster); + } + + @Override + public List selectAllCluster() { + return clusterMapper.selectAllCluster(); + } + + @Override + public ClusterEntity selectClusterById(ClusterEntity cluster) { + return clusterMapper.selectClusterById(cluster); + } + + @Override + public void updateClusterById(ClusterEntity cluster) { + clusterMapper.updateClusterById(cluster); + } + + @Override + public void deleteClusterById(ClusterEntity cluster) { + clusterMapper.deleteClusterById(cluster); + } + +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/ConfigService.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/ConfigService.java new file mode 100644 index 00000000..d2dea9e0 --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/ConfigService.java @@ -0,0 +1,47 @@ +/* + * 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.config; + + +import org.apache.eventmesh.dashboard.console.entity.config.ConfigEntity; + +import java.util.List; +import java.util.Map; + + +/** + * config data service + */ +public interface ConfigService { + + String mapToYaml(Map stringMap); + + Integer addConfig(ConfigEntity configEntity); + + Integer deleteConfig(ConfigEntity configEntity); + + String mapToProperties(Map stringMap); + + + List selectByInstanceId(ConfigEntity configEntity); + + List selectDefaultConfig(ConfigEntity configEntity); + + void updateConfig(ConfigEntity configEntity); + +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/Impl/ConfigServiceImpl.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/Impl/ConfigServiceImpl.java new file mode 100644 index 00000000..9bab90c3 --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/Impl/ConfigServiceImpl.java @@ -0,0 +1,80 @@ +/* + * 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.config.Impl; + +import org.apache.eventmesh.dashboard.console.entity.config.ConfigEntity; +import org.apache.eventmesh.dashboard.console.mapper.config.ConfigMapper; +import org.apache.eventmesh.dashboard.console.service.config.ConfigService; + +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.yaml.snakeyaml.Yaml; + +@Service +public class ConfigServiceImpl implements ConfigService { + + + @Autowired + ConfigMapper configMapper; + + @Override + public String mapToYaml(Map stringMap) { + Yaml yaml = new Yaml(); + return yaml.dumpAsMap(stringMap); + } + + @Override + public String mapToProperties(Map stringMap) { + Properties properties = new Properties(); + stringMap.forEach((key, value) -> { + properties.setProperty(key, value); + }); + return properties.toString().replace(",", ",\n"); + } + + @Override + public Integer addConfig(ConfigEntity configEntity) { + return configMapper.addConfig(configEntity); + } + + @Override + public Integer deleteConfig(ConfigEntity configEntity) { + return configMapper.deleteConfig(configEntity); + } + + @Override + public List selectByInstanceId(ConfigEntity configEntity) { + return configMapper.selectByInstanceId(configEntity); + } + + @Override + public List selectDefaultConfig(ConfigEntity configEntity) { + return configMapper.selectDefaultConfig(configEntity); + } + + @Override + public void updateConfig(ConfigEntity configEntity) { + configMapper.updateConfig(configEntity); + } + + +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/instanceoperation/ConnectorConfigService.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/instanceoperation/ConnectorConfigService.java new file mode 100644 index 00000000..e54b3cc4 --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/instanceoperation/ConnectorConfigService.java @@ -0,0 +1,36 @@ +/* + * 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.config.instanceoperation; + + +import org.apache.eventmesh.dashboard.console.entity.config.ConfigEntity; + +import java.util.List; + +import org.springframework.stereotype.Service; +/** + * TODO Pending interfaces + */ + +@Service +public class ConnectorConfigService { + + public List getConnectorConfigFromInstance(Long clusterId, Long id) { + return null; + } +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/instanceoperation/RuntimeConfigService.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/instanceoperation/RuntimeConfigService.java new file mode 100644 index 00000000..3e8645dd --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/instanceoperation/RuntimeConfigService.java @@ -0,0 +1,36 @@ +/* + * 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.config.instanceoperation; + +import org.apache.eventmesh.dashboard.console.entity.config.ConfigEntity; + +import java.util.List; + +import org.springframework.stereotype.Service; +/** + * TODO Pending interfaces + */ + +@Service +public class RuntimeConfigService { + + public List getRuntimeConfigFromInstance(Long clusterId, String host) { + return null; + } + +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/instanceoperation/StoreConfigService.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/instanceoperation/StoreConfigService.java new file mode 100644 index 00000000..7ad7c16e --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/instanceoperation/StoreConfigService.java @@ -0,0 +1,36 @@ +/* + * 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.config.instanceoperation; + +import org.apache.eventmesh.dashboard.console.entity.config.ConfigEntity; + +import java.util.List; + +import org.springframework.stereotype.Service; +/** + * TODO Pending interfaces + */ + +@Service +public class StoreConfigService { + + public List getStorageConfigFromInstance(Long clusterId, String storeId) { + return null; + } + +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/instanceoperation/TopicConfigService.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/instanceoperation/TopicConfigService.java new file mode 100644 index 00000000..c5564ffc --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/instanceoperation/TopicConfigService.java @@ -0,0 +1,36 @@ +/* + * 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.config.instanceoperation; + +import org.apache.eventmesh.dashboard.console.entity.config.ConfigEntity; + +import java.util.List; + +import org.springframework.stereotype.Service; +/** + * TODO Pending interfaces + */ + +@Service +public class TopicConfigService { + + public List getTopicConfigFromInstance(Long clusterId, String name) { + return null; + } + +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/synchronous/SyncConnectorConfigTask.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/synchronous/SyncConnectorConfigTask.java new file mode 100644 index 00000000..59351866 --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/synchronous/SyncConnectorConfigTask.java @@ -0,0 +1,94 @@ +/* + * 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.config.synchronous; + +import org.apache.eventmesh.dashboard.console.entity.config.ConfigEntity; +import org.apache.eventmesh.dashboard.console.entity.connector.ConnectorEntity; +import org.apache.eventmesh.dashboard.console.service.config.ConfigService; +import org.apache.eventmesh.dashboard.console.service.config.instanceoperation.ConnectorConfigService; +import org.apache.eventmesh.dashboard.console.service.connector.ConnectorDataService; + +import java.util.List; +import java.util.concurrent.ConcurrentHashMap; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * Synchronous DB To Instance + */ +@Service +public class SyncConnectorConfigTask { + + @Autowired + private ConnectorDataService connectorDataService; + + @Autowired + private ConnectorConfigService connectorConfigService; + @Autowired + private ConfigService configService; + + public void synchronousConnectorConfig(Long clusterId) { + List connectorEntities = connectorDataService.selectConnectorByCluster(clusterId); + for (ConnectorEntity connectorEntity : connectorEntities) { + + ConcurrentHashMap connectorConfigMapFromInstance = this.configListToMap( + connectorConfigService.getConnectorConfigFromInstance(clusterId, connectorEntity.getId())); + + ConfigEntity configEntity = this.getConfigEntityBelongInstance(clusterId, connectorEntity.getId()); + + ConcurrentHashMap connectorConfigMapFromDb = this.configListToMap(configService.selectByInstanceId(configEntity)); + + ConcurrentHashMap updateConfigMap = new ConcurrentHashMap<>(); + + connectorConfigMapFromInstance.entrySet().forEach(n -> { + if (connectorConfigMapFromDb.remove(n.getKey(), n.getValue())) { + connectorConfigMapFromInstance.remove(n.getKey()); + } + if (connectorConfigMapFromDb.get(n.getKey()) != null) { + updateConfigMap.put(n.getKey(), connectorConfigMapFromDb.get(n.getKey())); + connectorConfigMapFromInstance.remove(n.getKey()); + connectorConfigMapFromDb.remove(n.getKey()); + } + }); + //add connectorConfigMapFromDb + + //update updateConfigMap + + //delete connectorConfigMapFromInstance + } + } + + private ConcurrentHashMap configListToMap(List configEntityList) { + ConcurrentHashMap connectorConfigMap = new ConcurrentHashMap<>(); + configEntityList.forEach(n -> { + connectorConfigMap.put(n.getConfigName(), n.getConfigValue()); + } + ); + return connectorConfigMap; + } + + + private ConfigEntity getConfigEntityBelongInstance(Long clusterId, Long id) { + ConfigEntity configEntity = new ConfigEntity(); + configEntity.setClusterId(clusterId); + configEntity.setInstanceId(id); + configEntity.setInstanceType(2); + return configEntity; + } +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/synchronous/SyncRuntimeConfigTask.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/synchronous/SyncRuntimeConfigTask.java new file mode 100644 index 00000000..51ee24f1 --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/synchronous/SyncRuntimeConfigTask.java @@ -0,0 +1,97 @@ +/* + * 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.config.synchronous; + +import org.apache.eventmesh.dashboard.console.entity.config.ConfigEntity; +import org.apache.eventmesh.dashboard.console.entity.runtime.RuntimeEntity; +import org.apache.eventmesh.dashboard.console.service.config.ConfigService; +import org.apache.eventmesh.dashboard.console.service.config.instanceoperation.RuntimeConfigService; +import org.apache.eventmesh.dashboard.console.service.runtime.RuntimeService; + +import java.util.List; +import java.util.concurrent.ConcurrentHashMap; + + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * Synchronous DB To Instance + */ + +@Service +public class SyncRuntimeConfigTask { + + @Autowired + private RuntimeService runtimeService; + + @Autowired + private RuntimeConfigService runtimeConfigService; + + @Autowired + private ConfigService configService; + + public void synchronousRuntimeConfig(Long clusterId) { + List runtimeEntityList = runtimeService.getRuntimeByClusterId(clusterId); + for (RuntimeEntity runtimeEntity : runtimeEntityList) { + + ConcurrentHashMap runtimeConfigMapFromInstance = this.configListToMap( + runtimeConfigService.getRuntimeConfigFromInstance(clusterId, runtimeEntity.getHost())); + + ConfigEntity configEntity = this.getConfigEntityBelongInstance(clusterId, runtimeEntity.getId()); + + ConcurrentHashMap runtimeConfigMapFromDb = this.configListToMap(configService.selectByInstanceId(configEntity)); + + ConcurrentHashMap updateConfigMap = new ConcurrentHashMap<>(); + + runtimeConfigMapFromInstance.entrySet().forEach(n -> { + if (runtimeConfigMapFromDb.remove(n.getKey(), n.getValue())) { + runtimeConfigMapFromInstance.remove(n.getKey()); + } + if (runtimeConfigMapFromDb.get(n.getKey()) != null) { + updateConfigMap.put(n.getKey(), runtimeConfigMapFromDb.get(n.getKey())); + runtimeConfigMapFromInstance.remove(n.getKey()); + runtimeConfigMapFromDb.remove(n.getKey()); + } + }); + //add runtimeConfigMapFromDb + + //update updateConfigMap + + //delete runtimeConfigMapFromInstance + } + } + + private ConcurrentHashMap configListToMap(List configEntityList) { + ConcurrentHashMap runtimeConfigMap = new ConcurrentHashMap<>(); + configEntityList.forEach(n -> { + runtimeConfigMap.put(n.getConfigName(), n.getConfigValue()); + } + ); + return runtimeConfigMap; + } + + + private ConfigEntity getConfigEntityBelongInstance(Long clusterId, Long id) { + ConfigEntity configEntity = new ConfigEntity(); + configEntity.setClusterId(clusterId); + configEntity.setInstanceId(id); + configEntity.setInstanceType(0); + return configEntity; + } +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/synchronous/SyncStoreConfigTask.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/synchronous/SyncStoreConfigTask.java new file mode 100644 index 00000000..f5235b0a --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/synchronous/SyncStoreConfigTask.java @@ -0,0 +1,96 @@ +/* + * 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.config.synchronous; + +import org.apache.eventmesh.dashboard.console.entity.config.ConfigEntity; +import org.apache.eventmesh.dashboard.console.entity.storage.StoreEntity; +import org.apache.eventmesh.dashboard.console.service.config.ConfigService; +import org.apache.eventmesh.dashboard.console.service.config.instanceoperation.StoreConfigService; +import org.apache.eventmesh.dashboard.console.service.store.StoreService; + +import java.util.List; +import java.util.concurrent.ConcurrentHashMap; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * Synchronous DB To Instance + */ + +@Service +public class SyncStoreConfigTask { + + @Autowired + private StoreService storeService; + + @Autowired + private StoreConfigService storeConfigService; + + @Autowired + private ConfigService configService; + + public void synchronousStoreConfig(Long clusterId) { + List storeEntityList = storeService.selectStoreByCluster(clusterId); + for (StoreEntity storeEntity : storeEntityList) { + + ConcurrentHashMap storeConfigMapFromInstance = this.configListToMap( + storeConfigService.getStorageConfigFromInstance(clusterId, storeEntity.getHost())); + + ConfigEntity configEntity = this.getConfigEntityBelongInstance(clusterId, storeEntity.getId()); + + ConcurrentHashMap storeConfigMapFromDb = this.configListToMap(configService.selectByInstanceId(configEntity)); + + ConcurrentHashMap updateConfigMap = new ConcurrentHashMap<>(); + + storeConfigMapFromInstance.entrySet().forEach(n -> { + if (storeConfigMapFromDb.remove(n.getKey(), n.getValue())) { + storeConfigMapFromInstance.remove(n.getKey()); + } + if (storeConfigMapFromDb.get(n.getKey()) != null) { + updateConfigMap.put(n.getKey(), storeConfigMapFromDb.get(n.getKey())); + storeConfigMapFromInstance.remove(n.getKey()); + storeConfigMapFromDb.remove(n.getKey()); + } + }); + //add storeConfigMapFromDb + + //update updateConfigMap + + //delete storeConfigMapFromInstance + } + } + + private ConcurrentHashMap configListToMap(List configEntityList) { + ConcurrentHashMap storeConfigMap = new ConcurrentHashMap<>(); + configEntityList.forEach(n -> { + storeConfigMap.put(n.getConfigName(), n.getConfigValue()); + } + ); + return storeConfigMap; + } + + + private ConfigEntity getConfigEntityBelongInstance(Long clusterId, Long id) { + ConfigEntity configEntity = new ConfigEntity(); + configEntity.setClusterId(clusterId); + configEntity.setInstanceId(id); + configEntity.setInstanceType(1); + return configEntity; + } +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/synchronous/SyncTopicConfigTask.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/synchronous/SyncTopicConfigTask.java new file mode 100644 index 00000000..eada0b97 --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/synchronous/SyncTopicConfigTask.java @@ -0,0 +1,96 @@ +/* + * 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.config.synchronous; + +import org.apache.eventmesh.dashboard.console.entity.config.ConfigEntity; +import org.apache.eventmesh.dashboard.console.entity.topic.TopicEntity; +import org.apache.eventmesh.dashboard.console.service.config.ConfigService; +import org.apache.eventmesh.dashboard.console.service.config.instanceoperation.TopicConfigService; +import org.apache.eventmesh.dashboard.console.service.topic.TopicService; + +import java.util.List; +import java.util.concurrent.ConcurrentHashMap; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * Synchronous DB To Instance + */ + +@Service +public class SyncTopicConfigTask { + + @Autowired + private TopicService topicService; + + @Autowired + private TopicConfigService topicConfigService; + + @Autowired + private ConfigService configService; + + public void synchronousTopicConfig(Long clusterId) { + List topicEntityList = topicService.selectTopiByCluster(clusterId); + for (TopicEntity topicEntity : topicEntityList) { + + ConcurrentHashMap topicConfigMapFromInstance = this.configListToMap( + topicConfigService.getTopicConfigFromInstance(clusterId, topicEntity.getTopicName())); + + ConfigEntity configEntity = this.getConfigEntityBelongInstance(clusterId, topicEntity.getId()); + + ConcurrentHashMap topicConfigMapFromDb = this.configListToMap(configService.selectByInstanceId(configEntity)); + + ConcurrentHashMap updateConfigMap = new ConcurrentHashMap<>(); + + topicConfigMapFromInstance.entrySet().forEach(n -> { + if (topicConfigMapFromDb.remove(n.getKey(), n.getValue())) { + topicConfigMapFromInstance.remove(n.getKey()); + } + if (topicConfigMapFromDb.get(n.getKey()) != null) { + updateConfigMap.put(n.getKey(), topicConfigMapFromDb.get(n.getKey())); + topicConfigMapFromInstance.remove(n.getKey()); + topicConfigMapFromDb.remove(n.getKey()); + } + }); + //add topicConfigMapFromDb + + //update updateConfigMap + + //delete topicConfigMapFromInstance + } + } + + private ConcurrentHashMap configListToMap(List configEntityList) { + ConcurrentHashMap topicConfigMap = new ConcurrentHashMap<>(); + configEntityList.forEach(n -> { + topicConfigMap.put(n.getConfigName(), n.getConfigValue()); + } + ); + return topicConfigMap; + } + + + private ConfigEntity getConfigEntityBelongInstance(Long clusterId, Long id) { + ConfigEntity configEntity = new ConfigEntity(); + configEntity.setClusterId(clusterId); + configEntity.setInstanceId(id); + configEntity.setInstanceType(1); + return configEntity; + } +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/connection/ConnectionDataService.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/connection/ConnectionDataService.java index 05361eb2..e4db317d 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/connection/ConnectionDataService.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/connection/ConnectionDataService.java @@ -22,10 +22,15 @@ import java.util.List; /** - * Service providing data of connections. + * Service providing ConnectionEntity data. */ public interface ConnectionDataService { + + Integer selectConnectionNumByCluster(Long clusterId); + List getAllConnections(); + List getAllConnectionsByClusterId(Long clusterId); + void replaceAllConnections(List connectionEntityList); } 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 cf22a831..b8c66348 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 @@ -36,6 +36,8 @@ public class ConnectionDataServiceDatabaseImpl implements ConnectionDataService @Autowired private ConnectionMapper connectionMapper; + + @Override public List getAllConnectionsByClusterId(Long clusterId) { ConnectionEntity connectionEntity = new ConnectionEntity(); connectionEntity.setClusterId(clusterId); @@ -43,6 +45,13 @@ public List getAllConnectionsByClusterId(Long clusterId) { } + @Override + public Integer selectConnectionNumByCluster(Long clusterId) { + ConnectionEntity connectionEntity = new ConnectionEntity(); + connectionEntity.setClusterId(clusterId); + return connectionMapper.selectConnectionNumByCluster(connectionEntity); + } + @Override public List getAllConnections() { return connectionMapper.selectAll(); diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/connector/ConnectorDataService.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/connector/ConnectorDataService.java index b0b96427..a32bbf9e 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/connector/ConnectorDataService.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/connector/ConnectorDataService.java @@ -17,9 +17,14 @@ package org.apache.eventmesh.dashboard.console.service.connector; +import org.apache.eventmesh.dashboard.console.entity.connector.ConnectorEntity; + +import java.util.List; + /** - * Service providing data of connectors. + * Service providing ConnectorEntity data. */ public interface ConnectorDataService { + List selectConnectorByCluster(Long clusterId); } diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/connector/Impl/ConnectorDataServiceImpl.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/connector/Impl/ConnectorDataServiceImpl.java new file mode 100644 index 00000000..7a9a7066 --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/connector/Impl/ConnectorDataServiceImpl.java @@ -0,0 +1,41 @@ +/* + * 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.connector.Impl; + +import org.apache.eventmesh.dashboard.console.entity.connector.ConnectorEntity; +import org.apache.eventmesh.dashboard.console.mapper.connector.ConnectorMapper; +import org.apache.eventmesh.dashboard.console.service.connector.ConnectorDataService; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class ConnectorDataServiceImpl implements ConnectorDataService { + + @Autowired + private ConnectorMapper connectorMapper; + + @Override + public List selectConnectorByCluster(Long clusterId) { + ConnectorEntity connectorEntity = new ConnectorEntity(); + connectorEntity.setClusterId(clusterId); + return connectorMapper.selectByClusterId(connectorEntity); + } +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/runtime/Impl/RuntimeServiceImpl.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/runtime/Impl/RuntimeServiceImpl.java new file mode 100644 index 00000000..7b7ec07f --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/runtime/Impl/RuntimeServiceImpl.java @@ -0,0 +1,56 @@ +/* + * 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.runtime.Impl; + +import org.apache.eventmesh.dashboard.console.entity.runtime.RuntimeEntity; +import org.apache.eventmesh.dashboard.console.mapper.runtime.RuntimeMapper; +import org.apache.eventmesh.dashboard.console.service.runtime.RuntimeService; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class RuntimeServiceImpl implements RuntimeService { + + @Autowired + private RuntimeMapper runtimeMapper; + + @Override + public List getRuntimeByClusterId(Long clusterId) { + RuntimeEntity runtimeEntity = new RuntimeEntity(); + runtimeEntity.setClusterId(clusterId); + return runtimeMapper.selectRuntimeByCluster(runtimeEntity); + } + + @Override + public void addRuntime(RuntimeEntity runtimeEntity) { + runtimeMapper.addRuntime(runtimeEntity); + } + + @Override + public void updateRuntimeByCluster(RuntimeEntity runtimeEntity) { + runtimeMapper.updateRuntimeByCluster(runtimeEntity); + } + + @Override + public void deleteRuntimeByCluster(RuntimeEntity runtimeEntity) { + runtimeMapper.deleteRuntimeByCluster(runtimeEntity); + } +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/runtime/RuntimeService.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/runtime/RuntimeService.java new file mode 100644 index 00000000..c4569cee --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/runtime/RuntimeService.java @@ -0,0 +1,36 @@ +/* + * 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.runtime; + +import org.apache.eventmesh.dashboard.console.entity.runtime.RuntimeEntity; + +import java.util.List; + +/** + * Runtime data service + */ +public interface RuntimeService { + + List getRuntimeByClusterId(Long cluster); + + void addRuntime(RuntimeEntity runtimeEntity); + + void updateRuntimeByCluster(RuntimeEntity runtimeEntity); + + void deleteRuntimeByCluster(RuntimeEntity runtimeEntity); +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/store/Impl/StoreServiceImpl.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/store/Impl/StoreServiceImpl.java new file mode 100644 index 00000000..4e4469bb --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/store/Impl/StoreServiceImpl.java @@ -0,0 +1,56 @@ +/* + * 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.store.Impl; + +import org.apache.eventmesh.dashboard.console.entity.storage.StoreEntity; +import org.apache.eventmesh.dashboard.console.mapper.storage.StoreMapper; +import org.apache.eventmesh.dashboard.console.service.store.StoreService; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class StoreServiceImpl implements StoreService { + + @Autowired + private StoreMapper storeMapper; + + @Override + public void addStore(StoreEntity storeEntity) { + storeMapper.addStore(storeEntity); + } + + @Override + public void deleteStoreByUnique(StoreEntity storeEntity) { + storeMapper.deleteStoreByUnique(storeEntity); + } + + @Override + public List selectStoreByCluster(Long clusterId) { + StoreEntity storeEntity = new StoreEntity(); + storeEntity.setClusterId(clusterId); + return storeMapper.selectStoreByCluster(storeEntity); + } + + @Override + public void updateStoreByUnique(StoreEntity storeEntity) { + storeMapper.updateStoreByUnique(storeEntity); + } +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/store/StoreService.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/store/StoreService.java new file mode 100644 index 00000000..9fdaf4f8 --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/store/StoreService.java @@ -0,0 +1,36 @@ +/* + * 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.store; + +import org.apache.eventmesh.dashboard.console.entity.storage.StoreEntity; + +import java.util.List; + +/** + * store data service + */ +public interface StoreService { + + void addStore(StoreEntity storeEntity); + + void deleteStoreByUnique(StoreEntity storeEntity); + + List selectStoreByCluster(Long clusterId); + + void updateStoreByUnique(StoreEntity storeEntity); +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/topic/TopicService.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/topic/TopicService.java index 95c8a32b..2f8696da 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/topic/TopicService.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/topic/TopicService.java @@ -25,9 +25,12 @@ * Service about Topic */ public interface TopicService { + + Integer selectTopicNumByCluster(Long clusterId); + List getTopicList(TopicEntity topicEntity); - void addTopic_plus(TopicEntity topicEntity); + void addTopic(TopicEntity topicEntity); void updateTopic(TopicEntity topicEntity); @@ -38,4 +41,6 @@ public interface TopicService { TopicEntity selectTopicByUnique(TopicEntity topicEntity); void deleteTopic(TopicEntity topicEntity); + + List selectTopiByCluster(Long clusterId); } diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/topic/TopicServiceImpl.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/topic/TopicServiceImpl.java index aa42e7ba..444de271 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/topic/TopicServiceImpl.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/topic/TopicServiceImpl.java @@ -37,13 +37,20 @@ public class TopicServiceImpl implements TopicService { OprGroupMemberMapper oprGroupMemberMapper; + @Override + public Integer selectTopicNumByCluster(Long clusterId) { + TopicEntity topicEntity = new TopicEntity(); + topicEntity.setClusterId(clusterId); + return topicMapper.selectTopicNumByCluster(topicEntity); + } + @Override public List getTopicList(TopicEntity topicEntity) { return topicMapper.getTopicList(topicEntity); } @Override - public void addTopic_plus(TopicEntity topicEntity) { + public void addTopic(TopicEntity topicEntity) { GroupMemberEntity groupMemberEntity = new GroupMemberEntity(); groupMemberEntity.setTopicName(topicEntity.getTopicName()); groupMemberEntity.setState("active"); @@ -79,4 +86,13 @@ public void deleteTopic(TopicEntity topicEntity) { oprGroupMemberMapper.updateMemberByTopic(groupMemberEntity); topicMapper.deleteTopic(topicEntity); } + + @Override + public List selectTopiByCluster(Long clusterId) { + TopicEntity topicEntity = new TopicEntity(); + topicEntity.setClusterId(clusterId); + return topicMapper.selectTopicByCluster(topicEntity); + } + + } diff --git a/eventmesh-dashboard-console/src/main/resources/eventmesh-dashboard.sql b/eventmesh-dashboard-console/src/main/resources/eventmesh-dashboard.sql index 96d4a849..c24a5549 100644 --- a/eventmesh-dashboard-console/src/main/resources/eventmesh-dashboard.sql +++ b/eventmesh-dashboard-console/src/main/resources/eventmesh-dashboard.sql @@ -14,6 +14,121 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +DROP TABLE IF EXISTS `cluster`; +create table cluster +( + id bigint unsigned auto_increment comment '集群id' + primary key, + name varchar(128) default '' not null comment '集群名称', + register_name_list varchar(4096) default '' not null comment '注册中心名字', + bootstrap_servers varchar(2048) default '' not null comment 'server地址', + eventmesh_version varchar(32) default '' not null comment 'eventmesh版本', + client_properties text null comment 'EventMesh客户端配置', + jmx_properties text null comment 'JMX配置', + reg_properties text null comment '注册中心配置', + description text null comment '备注', + auth_type int default 0 not null comment '认证类型,-1未知,0:无认证,', + run_state tinyint default 1 not null comment '运行状态, 0表示未监控, 1监控中,有注册中心,2:监控中,无注册中心', + create_time timestamp default CURRENT_TIMESTAMP not null comment '接入时间', + update_time timestamp default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '修改时间', + is_delete int default 0 not null comment '0', + constraint uniq_name + unique (name) +) + comment '物理集群信息表'; + +create index idx_uniq_name + on cluster (name); + + +DROP TABLE IF EXISTS `config`; +create table config +( + id bigint unsigned auto_increment + primary key, + cluster_id bigint default -1 not null comment '集群ID', + business_type varchar(64) default '' not null comment '业务类型', + instance_type tinyint not null comment '配置类型 0:runtime,1:storage,2:connector,3:topic', + instance_id bigint default -1 not null comment '实例ID,上面配置对应的(比如runtime)的id', + config_name varchar(192) default '' not null comment '配置名称', + config_value text null comment '配置值', + start_version varchar(64) default '' not null comment '配置开始使用的版本', + status int default 1 not null comment '1 正常 2 禁用', + end_version varchar(64) default '' not null comment '配置结束使用的版本', + diff_type int default -1 not null comment '差异类型', + description varchar(1000) default '' not null comment '备注', + edit int default 1 not null comment '是否可以编辑 1 不可编辑(程序获取) 2 可编辑', + create_time timestamp default CURRENT_TIMESTAMP not null comment '创建时间', + update_time timestamp default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '修改时间', + is_default int not null comment '是否是默认值,0默认,1自定义的', + is_modify int default 0 not null, + eventmesh_version varchar(64) default ' ' not null, + constraint uniq_instance_type_instance_id_config_name + unique (instance_id, config_name, instance_type) +) + comment '配置信息表'; + +create index idx_phy_id_instance_id + on config (cluster_id, instance_id); + + +DROP TABLE IF EXISTS `runtime`; +create table runtime +( + id bigint auto_increment comment 'id' + primary key, + cluster_id bigint default -1 not null comment '物理集群ID', + host varchar(128) default '' not null comment 'runtime主机名', + storage_cluster_id bigint default -1 not null comment 'storageId', + port int default -1 not null comment 'runtime端口', + jmx_port int default -1 not null comment 'Jmx端口', + start_timestamp bigint default -1 not null comment '启动时间', + rack varchar(128) default '' not null comment 'Rack信息', + status int default 0 not null comment '状态: 1启用,0未启用', + create_time timestamp default CURRENT_TIMESTAMP not null comment '创建时间', + update_time timestamp default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '修改时间', + endpoint_map varchar(1024) default '' not null comment '监听信息', + is_delete int default 0 not null comment '0', + constraint uniq_cluster_phy_id__host_port + unique (cluster_id, host) +) + comment 'Runtime信息表'; + +create index idx_phy_id_host_storage_id + on runtime (cluster_id, storage_cluster_id); + + +DROP TABLE IF EXISTS `store`; +create table store +( + id bigint unsigned auto_increment comment 'id' + primary key, + cluster_id bigint default -1 not null comment '物理集群ID', + store_id int default -1 not null comment 'storeId', + store_type varchar(32) default '' not null comment 'Store类型,如rocketmq,redis,...', + host varchar(128) default '' not null comment 'store主机名', + runtime_id bigint default -1 not null comment 'runtimeId', + topic_list varchar(4096) default '' not null comment 'topicName列表', + diff_type int default -1 not null comment '差异类型', + port int default -1 not null comment 'store端口', + jmx_port int default -1 not null comment 'Jmx端口', + start_timestamp bigint default -1 not null comment '启动时间', + rack varchar(128) default '' not null comment 'Rack信息', + status int default 0 not null comment '状态: 1启用,0未启用', + create_time timestamp default CURRENT_TIMESTAMP not null comment '创建时间', + update_time timestamp default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '修改时间', + endpoint_map varchar(1024) default '' not null comment '监听信息', + is_delete int default 0 not null, + constraint uniq_cluster_phy_id__storage_id + unique (cluster_id, store_id) +) + comment 'Store信息表'; + +create index idx_store_id_runtime_id + on store (store_id, cluster_id, runtime_id); + + + DROP TABLE IF EXISTS `group`; CREATE TABLE `group` ( diff --git a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/cluster/TestClusterMapper.java b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/cluster/TestClusterMapper.java new file mode 100644 index 00000000..192c4e0f --- /dev/null +++ b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/cluster/TestClusterMapper.java @@ -0,0 +1,88 @@ +package org.apache.eventmesh.dashboard.console.unit.cluster; + +import org.apache.eventmesh.dashboard.console.EventMeshDashboardApplication; +import org.apache.eventmesh.dashboard.console.entity.cluster.ClusterEntity; +import org.apache.eventmesh.dashboard.console.mapper.cluster.ClusterMapper; + +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = EventMeshDashboardApplication.class) +public class TestClusterMapper { + + @Autowired + private ClusterMapper clusterMapper; + + @Test + public void testAddCluster() { + ClusterEntity clusterEntity = + new ClusterEntity(null, "cl1", "registerList", "server", "1.7.0", "null", "null", "null", "no", 0, 0, null, null); + clusterMapper.addCluster(clusterEntity); + ClusterEntity clusterEntity1 = clusterMapper.selectClusterById(clusterEntity); + clusterEntity1.setUpdateTime(null); + clusterEntity1.setCreateTime(null); + Assert.assertEquals(clusterEntity1, clusterEntity); + } + + @Test + public void testSelectAllCluster() { + ClusterEntity clusterEntity = + new ClusterEntity(null, "cl1", "registerList", "server", "1.7.0", "null", "null", "null", "no", 0, 0, null, null); + ClusterEntity clusterEntity1 = + new ClusterEntity(null, "c1", "registerList", "server", "1.7.0", "null", "null", "null", "no", 0, 0, null, null); + clusterMapper.addCluster(clusterEntity); + clusterMapper.addCluster(clusterEntity1); + List clusterEntities = clusterMapper.selectAllCluster(); + Assert.assertEquals(clusterEntities.size(), 2); + } + + @Test + public void testSelectClusterById() { + ClusterEntity clusterEntity = + new ClusterEntity(null, "cl1", "registerList", "server", "1.7.0", "null", "null", "null", "no", 0, 0, null, null); + clusterMapper.addCluster(clusterEntity); + ClusterEntity clusterEntity1 = clusterMapper.selectClusterById(clusterEntity); + clusterEntity1.setCreateTime(null); + clusterEntity1.setUpdateTime(null); + Assert.assertEquals(clusterEntity1, clusterEntity); + } + + @Test + public void testUpdateCluster() { + ClusterEntity clusterEntity = + new ClusterEntity(null, "cl1", "registerList", "server", "1.7.0", "null", "null", "null", "no", 0, 0, null, null); + clusterMapper.addCluster(clusterEntity); + clusterEntity.setDescription("nothing"); + clusterEntity.setName("cl2"); + clusterEntity.setAuthType(1); + clusterEntity.setBootstrapServers("1999"); + clusterEntity.setClientProperties("nothing"); + clusterEntity.setEventmeshVersion("1.10.0"); + clusterEntity.setJmxProperties("nothing"); + clusterEntity.setRegisterNameList("1.23.18"); + clusterEntity.setRunState(1); + clusterEntity.setRegProperties("nothing"); + clusterMapper.updateClusterById(clusterEntity); + ClusterEntity clusterEntity1 = clusterMapper.selectClusterById(clusterEntity); + clusterEntity1.setCreateTime(null); + clusterEntity1.setUpdateTime(null); + Assert.assertEquals(clusterEntity1, clusterEntity); + } + + @Test + public void testDeleteCluster() { + ClusterEntity clusterEntity = + new ClusterEntity(null, "cl1", "registerList", "server", "1.7.0", "null", "null", "null", "no", 0, 0, null, null); + clusterMapper.addCluster(clusterEntity); + clusterMapper.deleteClusterById(clusterEntity); + ClusterEntity clusterEntity1 = clusterMapper.selectClusterById(clusterEntity); + Assert.assertEquals(clusterEntity1, null); + } +} diff --git a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/config/TestConfigMapper.java b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/config/TestConfigMapper.java new file mode 100644 index 00000000..417d75e8 --- /dev/null +++ b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/config/TestConfigMapper.java @@ -0,0 +1,92 @@ +package org.apache.eventmesh.dashboard.console.unit.config; + + +import org.apache.eventmesh.dashboard.console.EventMeshDashboardApplication; +import org.apache.eventmesh.dashboard.console.entity.config.ConfigEntity; +import org.apache.eventmesh.dashboard.console.mapper.config.ConfigMapper; + + +import java.util.ArrayList; + +import java.util.List; + + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = EventMeshDashboardApplication.class) +public class TestConfigMapper { + + @Autowired + private ConfigMapper configMapper; + + @Test + public void testAddConfig() throws IllegalAccessException { + ConfigEntity config = new ConfigEntity(null, 1L, "rocketmq", 2, 2L, "port", + "127.0.0.1", "1.7.0", "1.8.0", 1, "1.10.0", -1, "666", 0, null, null, 0, 0); + configMapper.addConfig(config); + ConfigEntity configEntity = configMapper.selectByUnique(config); + configEntity.setUpdateTime(null); + configEntity.setCreateTime(null); + Assert.assertEquals(config.getId(), configEntity.getId()); + Assert.assertEquals(config, configEntity); + } + + @Test + public void testDeleteConfig() { + ConfigEntity config = new ConfigEntity(null, 1L, "rocketmq", 2, 2L, "port", + "127.0.0.1", "1.7.0", "1.8.0", 1, "1.10.0", -1, "666", 0, null, null, 0, 0); + configMapper.addConfig(config); + configMapper.deleteConfig(config); + ConfigEntity config1 = configMapper.selectByUnique(config); + Assert.assertEquals(config1, null); + } + + @Test + public void testSelectByInstanceId() { + ConfigEntity config = new ConfigEntity(null, 1L, "rocketmq", 2, 2L, "port", + "127.0.0.1", "1.7.0", "1.8.0", 1, "1.10.0", -1, "666", 0, null, null, 0, 0); + ConfigEntity config1 = new ConfigEntity(null, 1L, "rocketmq", 2, 2L, "name", + "127.0.0.1", "1.7.0", "1.8.0", 1, "1.10.0", -1, "666", 0, null, null, 0, 0); + configMapper.addConfig(config1); + configMapper.addConfig(config); + List configEntityList = new ArrayList<>(); + configEntityList.add(config1); + configEntityList.add(config); + List configEntityList1 = configMapper.selectByInstanceId(config1); + configEntityList1.forEach(n -> { + n.setCreateTime(null); + n.setUpdateTime(null); + }); + Assert.assertEquals(configEntityList, configEntityList1); + } + + @Test + public void testSelectDefaultConfig() { + ConfigEntity config = new ConfigEntity(); + config.setBusinessType("rocketmq"); + config.setInstanceType(1); + List configEntityList = configMapper.selectDefaultConfig(config); + Assert.assertNotEquals(configEntityList.size(), 0); + } + + @Test + public void testUpdateConfig() { + ConfigEntity config = new ConfigEntity(null, 1L, "rocketmq", 2, 2L, "port", + "127.0.0.1", "1.7.0", "1.8.0", 1, "1.10.0", -1, "666", 2, null, null, 0, 0); + configMapper.addConfig(config); + config.setConfigValue("127.1.1.1"); + configMapper.updateConfig(config); + ConfigEntity configEntity = configMapper.selectByUnique(config); + configEntity.setUpdateTime(null); + configEntity.setCreateTime(null); + Assert.assertEquals(configEntity, config); + } +} + diff --git a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/runtime/TestRuntimeMapper.java b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/runtime/TestRuntimeMapper.java new file mode 100644 index 00000000..ad99e091 --- /dev/null +++ b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/runtime/TestRuntimeMapper.java @@ -0,0 +1,58 @@ +package org.apache.eventmesh.dashboard.console.unit.runtime; + +import org.apache.eventmesh.dashboard.console.EventMeshDashboardApplication; +import org.apache.eventmesh.dashboard.console.entity.runtime.RuntimeEntity; +import org.apache.eventmesh.dashboard.console.mapper.runtime.RuntimeMapper; + + +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = EventMeshDashboardApplication.class) +public class TestRuntimeMapper { + + @Autowired + private RuntimeMapper runtimeMapper; + + @Test + public void testAddRuntimeMapper() { + RuntimeEntity runtimeEntity = new RuntimeEntity(null, 1l, "runtime1", 2l, 1019, 1099, 1L, "null", 1, null, null, "null"); + runtimeMapper.addRuntime(runtimeEntity); + List runtimeEntities = runtimeMapper.selectRuntimeByCluster(runtimeEntity); + RuntimeEntity runtimeEntity1 = runtimeEntities.get(0); + runtimeEntity1.setCreateTime(null); + runtimeEntity1.setUpdateTime(null); + Assert.assertEquals(runtimeEntity1, runtimeEntity); + } + + @Test + public void testUpdateRuntimeByCluster() { + RuntimeEntity runtimeEntity = new RuntimeEntity(null, 1l, "runtime1", 2l, 1019, 1099, 1L, "null", 1, null, null, "null"); + runtimeMapper.addRuntime(runtimeEntity); + runtimeEntity.setPort(1000); + runtimeEntity.setJmxPort(1099); + runtimeEntity.setStatus(0); + runtimeMapper.updateRuntimeByCluster(runtimeEntity); + List runtimeEntities = runtimeMapper.selectRuntimeByCluster(runtimeEntity); + RuntimeEntity runtimeEntity1 = runtimeEntities.get(0); + runtimeEntity1.setCreateTime(null); + runtimeEntity1.setUpdateTime(null); + Assert.assertEquals(runtimeEntity, runtimeEntity1); + } + + @Test + public void testDeleteRuntime() { + RuntimeEntity runtimeEntity = new RuntimeEntity(null, 1l, "runtime1", 2l, 1019, 1099, 1L, "null", 1, null, null, "null"); + runtimeMapper.addRuntime(runtimeEntity); + runtimeMapper.deleteRuntimeByCluster(runtimeEntity); + List runtimeEntities = runtimeMapper.selectRuntimeByCluster(runtimeEntity); + Assert.assertEquals(runtimeEntities.size(), 0); + } +} diff --git a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/store/TestStoreMapper.java b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/store/TestStoreMapper.java new file mode 100644 index 00000000..5876f828 --- /dev/null +++ b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/store/TestStoreMapper.java @@ -0,0 +1,62 @@ +package org.apache.eventmesh.dashboard.console.unit.store; + +import org.apache.eventmesh.dashboard.console.EventMeshDashboardApplication; +import org.apache.eventmesh.dashboard.console.entity.storage.StoreEntity; +import org.apache.eventmesh.dashboard.console.mapper.storage.StoreMapper; + +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = EventMeshDashboardApplication.class) +public class TestStoreMapper { + + @Autowired + private StoreMapper storeMapper; + + @Test + public void testAddStore() { + StoreEntity storeEntity = + new StoreEntity(null, 1l, 2, "rocketmq", "run1", 1l, "n,j", (short) -1, 1098, 1099, "nothing", (short) 1, null, null, "nothing", 1l); + StoreEntity storeEntity1 = + new StoreEntity(null, 1l, 1, "rocketmq", "run1", 1l, "n,j", (short) -1, 1098, 1099, "nothing", (short) 1, null, null, "nothing", 1l); + storeMapper.addStore(storeEntity); + storeMapper.addStore(storeEntity1); + List storeEntities = storeMapper.selectStoreByCluster(storeEntity); + storeEntities.forEach(n -> { + n.setUpdateTime(null); + n.setCreateTime(null); + }); + Assert.assertEquals(storeEntities.get(1), storeEntity); + Assert.assertEquals(storeEntities.get(0), storeEntity1); + } + + @Test + public void testDeleteStoreByUnique() { + StoreEntity storeEntity = + new StoreEntity(null, 1l, 2, "rocketmq", "run1", 1l, "n,j", (short) -1, 1098, 1099, "nothing", (short) 1, null, null, "nothing", 1l); + storeMapper.addStore(storeEntity); + storeMapper.deleteStoreByUnique(storeEntity); + List storeEntities = storeMapper.selectStoreByCluster(storeEntity); + Assert.assertEquals(storeEntities.size(), 0); + } + + @Test + public void testUpdateStoreByUnique() { + StoreEntity storeEntity = + new StoreEntity(null, 1l, 2, "rocketmq", "run1", 1l, "n,j", (short) -1, 1098, 1099, "nothing", (short) 1, null, null, "nothing", 1l); + storeMapper.addStore(storeEntity); + storeEntity.setStatus((short) 5); + storeMapper.updateStoreByUnique(storeEntity); + List storeEntities = storeMapper.selectStoreByCluster(storeEntity); + Assert.assertEquals(storeEntities.size(), 1); + Assert.assertEquals(storeEntities.get(0).getStatus(), storeEntity.getStatus()); + } +}