From bfe90429c70fd44b5d7085a437b4e479441cb47e Mon Sep 17 00:00:00 2001 From: jsy Date: Wed, 24 Apr 2024 09:57:54 +0800 Subject: [PATCH] refactor: remove meta-dal module (#840) --- .../home/biz/plugin/core/LogPluginUtil.java | 39 ++++-- .../server/home/web/common/ParaCheckUtil.java | 5 +- server/meta/meta-core/pom.xml | 5 - .../core/web/controller/AdminController.java | 45 ------- server/meta/meta-dal/pom.xml | 28 ---- .../meta/dal/service/MetaTableService.java | 58 --------- .../dal/service/mapper/MetaDataMapper.java | 43 ------- .../meta/dal/service/model/MetaDataDO.java | 34 ----- .../main/resources/mybatis/mybatis-config.xml | 13 -- .../main/resources/sqlmap/MetaDataMapper.xml | 120 ------------------ server/server-parent/pom.xml | 1 - 11 files changed, 29 insertions(+), 362 deletions(-) delete mode 100644 server/meta/meta-core/src/main/java/io/holoinsight/server/meta/core/web/controller/AdminController.java delete mode 100644 server/meta/meta-dal/pom.xml delete mode 100644 server/meta/meta-dal/src/main/java/io/holoinsight/server/meta/dal/service/MetaTableService.java delete mode 100644 server/meta/meta-dal/src/main/java/io/holoinsight/server/meta/dal/service/mapper/MetaDataMapper.java delete mode 100644 server/meta/meta-dal/src/main/java/io/holoinsight/server/meta/dal/service/model/MetaDataDO.java delete mode 100644 server/meta/meta-dal/src/main/resources/mybatis/mybatis-config.xml delete mode 100644 server/meta/meta-dal/src/main/resources/sqlmap/MetaDataMapper.xml diff --git a/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/plugin/core/LogPluginUtil.java b/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/plugin/core/LogPluginUtil.java index 955487828..34b4f3843 100644 --- a/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/plugin/core/LogPluginUtil.java +++ b/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/plugin/core/LogPluginUtil.java @@ -18,7 +18,9 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.HashSet; import java.util.List; +import java.util.Set; /** * @author jsy1001de @@ -30,15 +32,15 @@ public class LogPluginUtil { public static void addSpmCols(CustomPluginConf conf) { Boolean spm = checkSpmConditions(conf); + Set spmSets = + new HashSet<>(Arrays.asList("total", "success", "fail", "cost", "successPercent")); List newCollectMetrics = new ArrayList<>(); - int cols = 0; if (!CollectionUtils.isEmpty(conf.collectMetrics)) { for (CollectMetric collectMetric : conf.collectMetrics) { if (null == collectMetric.spm || Boolean.FALSE == collectMetric.spm) { - if (spm == Boolean.TRUE - && Arrays.asList("total", "success", "fail", "cost", "successPercent") - .contains(collectMetric.tableName)) { + if (spm == Boolean.TRUE && spmSets.contains(collectMetric.tableName)) { + spmSets.remove(collectMetric.tableName); continue; } newCollectMetrics.add(collectMetric); @@ -49,12 +51,11 @@ public static void addSpmCols(CustomPluginConf conf) { continue; } newCollectMetrics.add(collectMetric); - cols++; } } // add spm metrics - if (spm == Boolean.TRUE && cols == 0) { + if (spm == Boolean.TRUE && !spmSets.isEmpty()) { SpmCols spmCols = conf.spmCols; List tags = new ArrayList<>(); @@ -67,15 +68,27 @@ public static void addSpmCols(CustomPluginConf conf) { }); } - newCollectMetrics.add(genTotalCollectMetric(spmCols, tags)); - newCollectMetrics.add(genSuccessCollectMetric(spmCols, tags)); - newCollectMetrics.add(genFailCollectMetric(spmCols, tags)); - newCollectMetrics.add(genCostCollectMetric(spmCols, tags)); - newCollectMetrics.add(genSuccessPercentCollectMetric(tags)); + for (String apmMetric : spmSets) { + switch (apmMetric) { + case "total": + newCollectMetrics.add(genTotalCollectMetric(spmCols, tags)); + break; + case "success": + newCollectMetrics.add(genSuccessCollectMetric(spmCols, tags)); + break; + case "fail": + newCollectMetrics.add(genFailCollectMetric(spmCols, tags)); + break; + case "cost": + newCollectMetrics.add(genCostCollectMetric(spmCols, tags)); + break; + case "successPercent": + newCollectMetrics.add(genSuccessPercentCollectMetric(tags)); + break; + } + } } - conf.setCollectMetrics(newCollectMetrics); - } diff --git a/server/home/home-web/src/main/java/io/holoinsight/server/home/web/common/ParaCheckUtil.java b/server/home/home-web/src/main/java/io/holoinsight/server/home/web/common/ParaCheckUtil.java index a1e448d01..e0a2b68b4 100644 --- a/server/home/home-web/src/main/java/io/holoinsight/server/home/web/common/ParaCheckUtil.java +++ b/server/home/home-web/src/main/java/io/holoinsight/server/home/web/common/ParaCheckUtil.java @@ -32,8 +32,9 @@ public class ParaCheckUtil { private static final Pattern PATTERN_CLUSTER = Pattern.compile("^[a-z][a-z0-9\\-]{1,20}"); private static final Pattern PATTERN_APPLICATION = Pattern.compile("^[a-z]{1,20}"); - private static Pattern PATTERN_CN_SQL = - Pattern.compile("^[\\u00b7A-Za-z0-9\\u4e00-\\u9fa5\\u3000-\\u303f\\uFF0C\\-_ ,|:\\.]*$"); + + private static Pattern PATTERN_CN_SQL = Pattern.compile( + "^[\\u00b7A-Za-z0-9\\u4e00-\\u9fa5\\u3000-\\u303f\\uFF0C\\-_ (:。&)()@《》<>“”‘’\\[\\]{}【】/%,|:.]*$"); private static Pattern PATTERN_SQL = Pattern.compile("^[\\u00b7A-Za-z0-9\\u4e00-\\u9fa5\\-_ ,|:\\.]*$"); private static Pattern PATTERN_STRICT_SQL = diff --git a/server/meta/meta-core/pom.xml b/server/meta/meta-core/pom.xml index e47ed7da2..772116ebb 100644 --- a/server/meta/meta-core/pom.xml +++ b/server/meta/meta-core/pom.xml @@ -23,11 +23,6 @@ meta-proto ${project.version} - - - - - org.apache.commons commons-lang3 diff --git a/server/meta/meta-core/src/main/java/io/holoinsight/server/meta/core/web/controller/AdminController.java b/server/meta/meta-core/src/main/java/io/holoinsight/server/meta/core/web/controller/AdminController.java deleted file mode 100644 index a804df8a9..000000000 --- a/server/meta/meta-core/src/main/java/io/holoinsight/server/meta/core/web/controller/AdminController.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2022 Holoinsight Project Authors. Licensed under Apache-2.0. - */ -package io.holoinsight.server.meta.core.web.controller; - -import io.holoinsight.server.meta.common.model.QueryExample; -import io.holoinsight.server.common.JsonResult; -import io.holoinsight.server.meta.core.service.DBCoreServiceSwitcher; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import java.util.List; -import java.util.Map; - -/** - * - * @author jsy1001de - * @version : TestController.java, v 0.1 2022年03月03日 5:07 下午 jinsong.yjs Exp $ - */ -@RestController -@RequestMapping("/internal/api/meta") -public class AdminController { - - @Autowired - private DBCoreServiceSwitcher dbCoreServiceSwitcher; - - - @PostMapping("/meta/query/{collection}") - public JsonResult query(@PathVariable("collection") String collection, - @RequestBody Map condition) { - QueryExample queryExample = new QueryExample(); - queryExample.getParams().putAll(condition); - if (condition.containsKey("rowKeys")) { - Object rowKeys = condition.remove("rowKeys"); - queryExample.setRowKeys((List) rowKeys); - } - return JsonResult.createSuccessResult( - dbCoreServiceSwitcher.dbCoreService().queryByExample(collection, queryExample)); - } - -} diff --git a/server/meta/meta-dal/pom.xml b/server/meta/meta-dal/pom.xml deleted file mode 100644 index 034a01168..000000000 --- a/server/meta/meta-dal/pom.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - server-parent - io.holoinsight.server - 1.0.0-SNAPSHOT - ../../server-parent/pom.xml - - 4.0.0 - - meta-dal - - - - - io.holoinsight.server - meta-common - ${project.version} - - - org.mybatis - mybatis - - - - \ No newline at end of file diff --git a/server/meta/meta-dal/src/main/java/io/holoinsight/server/meta/dal/service/MetaTableService.java b/server/meta/meta-dal/src/main/java/io/holoinsight/server/meta/dal/service/MetaTableService.java deleted file mode 100644 index 2f4c35881..000000000 --- a/server/meta/meta-dal/src/main/java/io/holoinsight/server/meta/dal/service/MetaTableService.java +++ /dev/null @@ -1,58 +0,0 @@ -/// * -// * Copyright 2022 Holoinsight Project Authors. Licensed under Apache-2.0. -// */ -// package io.holoinsight.server.meta.dal.service; -// -// import com.google.common.cache.Cache; -// import com.google.common.cache.CacheBuilder; -// import org.springframework.stereotype.Service; -// import org.springframework.util.CollectionUtils; -// -// import java.util.Arrays; -// import java.util.Collections; -// import java.util.HashMap; -// import java.util.List; -// import java.util.Map; -// import java.util.concurrent.TimeUnit; -// -/// ** -// * -// * @author jsy1001de -// * @version 1.0: MetaTableService.java, v 0.1 2022年03月22日 11:37 上午 jinsong.yjs Exp $ -// */ -// @Service -// public class MetaTableService { -// -// private static final Map> ukMaps = new HashMap<>(); -// -// static { -// ukMaps.put("container", Arrays.asList("name", "namespace")); -// ukMaps.put("pod", Arrays.asList("name", "namespace")); -// ukMaps.put("node", Collections.singletonList("name")); -// ukMaps.put("vm", Collections.singletonList("ip")); -// ukMaps.put("node_tenant", Collections.singletonList("_uk")); -// } -// -// -// public Map> getUksForCache(String tableName) { -// -// Map> strings = tableUkCacheMaps.getIfPresent(tableName); -// if (!CollectionUtils.isEmpty(strings)) { -// return strings; -// } -// Map> uks = getUks(tableName); -// -// return uks; -// } -// -// public Map> getUks(String tableName) { -// -// if (tableName.endsWith("_app")) { -// Map> appParam = new HashMap<>(); -// appParam.put("app", Arrays.asList("app", "_workspace")); -// return appParam; -// } -// -// return ukMaps; -// } -// } diff --git a/server/meta/meta-dal/src/main/java/io/holoinsight/server/meta/dal/service/mapper/MetaDataMapper.java b/server/meta/meta-dal/src/main/java/io/holoinsight/server/meta/dal/service/mapper/MetaDataMapper.java deleted file mode 100644 index 665b6b7f0..000000000 --- a/server/meta/meta-dal/src/main/java/io/holoinsight/server/meta/dal/service/mapper/MetaDataMapper.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2022 Holoinsight Project Authors. Licensed under Apache-2.0. - */ -package io.holoinsight.server.meta.dal.service.mapper; - -import java.util.Collection; -import java.util.Date; -import java.util.List; - -import io.holoinsight.server.meta.dal.service.model.MetaDataDO; -import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Param; -import org.springframework.stereotype.Repository; - -/** - * @author ljw - * @Description MetaDataMapper - * @date 2023/4/24 - */ -@Mapper -@Repository -public interface MetaDataMapper { - - void batchInsertOrUpdate(List metaDataList); - - List selectByUks(@Param("tableName") String tableName, - @Param("pkList") Collection pkList); - - Integer softDeleteByUks(@Param("tableName") String tableName, - @Param("pkList") Collection pkList, @Param("gmtModified") Date gmtModified); - - void updateByUk(@Param("tableName") String tableName, @Param("item") MetaDataDO item); - - List queryChangedMeta(@Param("start") Date start, @Param("end") Date end, - @Param("containDeleted") Boolean containDeleted, @Param("offset") int offset, - @Param("limit") int limit); - - List queryTableChangedMeta(@Param("table") String table, @Param("start") Date start, - @Param("end") Date end, @Param("containDeleted") Boolean containDeleted, - @Param("offset") int offset, @Param("limit") int limit); - - Integer cleanMetaData(@Param("end") Date end); -} diff --git a/server/meta/meta-dal/src/main/java/io/holoinsight/server/meta/dal/service/model/MetaDataDO.java b/server/meta/meta-dal/src/main/java/io/holoinsight/server/meta/dal/service/model/MetaDataDO.java deleted file mode 100644 index db8c6e4eb..000000000 --- a/server/meta/meta-dal/src/main/java/io/holoinsight/server/meta/dal/service/model/MetaDataDO.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2022 Holoinsight Project Authors. Licensed under Apache-2.0. - */ -package io.holoinsight.server.meta.dal.service.model; - -import java.util.Date; - -import lombok.Data; - -/** - * @author ljw - * @Description meta data - * @date 2023/4/24 - */ -@Data -public class MetaDataDO { - - private Long id; - - private Date gmtCreate; - - private Date gmtModified; - - private String tableName; - - private String uk; - - private String json; - - private String annotations; - - private Integer deleted; - -} diff --git a/server/meta/meta-dal/src/main/resources/mybatis/mybatis-config.xml b/server/meta/meta-dal/src/main/resources/mybatis/mybatis-config.xml deleted file mode 100644 index 174f768b0..000000000 --- a/server/meta/meta-dal/src/main/resources/mybatis/mybatis-config.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - diff --git a/server/meta/meta-dal/src/main/resources/sqlmap/MetaDataMapper.xml b/server/meta/meta-dal/src/main/resources/sqlmap/MetaDataMapper.xml deleted file mode 100644 index 906b2b60e..000000000 --- a/server/meta/meta-dal/src/main/resources/sqlmap/MetaDataMapper.xml +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - insert into meta_dim_data( - table_name, - uk, - json, - annotations, - deleted, - gmt_create, - gmt_modified - ) - values - - ( - #{item.tableName}, - #{item.uk}, - #{item.json}, - #{item.annotations}, - #{item.deleted}, - #{item.gmtCreate}, - #{item.gmtModified} - ) - - ON DUPLICATE KEY UPDATE - json = VALUES(json), - annotations = VALUES(annotations), - deleted = VALUES(deleted), - gmt_modified = VALUES(gmt_modified) - - - - update meta_dim_data - - json = #{item.json}, annotations = #{item.annotations}, gmt_modified = #{item.gmtModified} - - where table_name = #{tableName} and uk = #{item.uk} and deleted = 0 - - - - update meta_dim_data set deleted = 1, gmt_modified = #{gmtModified} - - table_name = #{tableName} - - - and uk in - - #{item} - - - - - - delete from meta_dim_data where deleted = 1 and - - - - - - - - - \ No newline at end of file diff --git a/server/server-parent/pom.xml b/server/server-parent/pom.xml index 4169a512b..1e130aa19 100644 --- a/server/server-parent/pom.xml +++ b/server/server-parent/pom.xml @@ -24,7 +24,6 @@ ../meta/meta-proto ../meta/meta-common ../meta/meta-facade - ../meta/meta-core ../meta/meta-boot ../meta/meta-bootstrap