From 0d17138f67bfc84402d48616c54f93fea733788a Mon Sep 17 00:00:00 2001 From: jsy Date: Wed, 2 Aug 2023 16:09:18 +0800 Subject: [PATCH] refactor(home): optimize tenantInitService (#582) --- .../home/common/util/cache/local/CacheConst.java | 1 + .../listener/IntegrationGeneratedUpdateListener.java | 8 ++++++-- .../server/home/biz/plugin/core/PortCheckPlugin.java | 7 +++++-- .../server/home/biz/service/TenantInitService.java | 11 ++++++----- .../home/biz/service/agent/AgentLogTailService.java | 3 ++- .../service/impl/DefaultTenantInitServiceImpl.java | 9 +++++---- .../service/impl/IntegrationPluginServiceImpl.java | 3 --- .../server/home/web/controller/MetaFacadeImpl.java | 9 ++------- .../server/home/web/controller/QueryFacadeImpl.java | 6 +++--- .../server/home/web/controller/SearchFacadeImpl.java | 2 +- .../home/web/controller/UserFavoriteFacadeImpl.java | 2 +- 11 files changed, 32 insertions(+), 29 deletions(-) diff --git a/server/home/home-common/src/main/java/io/holoinsight/server/home/common/util/cache/local/CacheConst.java b/server/home/home-common/src/main/java/io/holoinsight/server/home/common/util/cache/local/CacheConst.java index 2a95b05fa..a2fed46e1 100644 --- a/server/home/home-common/src/main/java/io/holoinsight/server/home/common/util/cache/local/CacheConst.java +++ b/server/home/home-common/src/main/java/io/holoinsight/server/home/common/util/cache/local/CacheConst.java @@ -12,6 +12,7 @@ public class CacheConst { public static final String USER_CACHE_KEY = "user_cache_key"; public static final String APP_META_KEY = "app_meta_key"; + public static final String TENANT_USER_META_KEY = "tenant_user_meta_key"; public static final String TENANT_MEMBER_META_KEY = "tenant_member_meta_key"; public static final String INTEGRATION_GENERATED_CACHE_KEY = "integration_generated_cache_key"; } diff --git a/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/listener/IntegrationGeneratedUpdateListener.java b/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/listener/IntegrationGeneratedUpdateListener.java index 97486908a..a839017e6 100644 --- a/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/listener/IntegrationGeneratedUpdateListener.java +++ b/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/listener/IntegrationGeneratedUpdateListener.java @@ -13,6 +13,7 @@ import io.holoinsight.server.home.dal.model.dto.IntegrationGeneratedDTO; import io.holoinsight.server.home.dal.model.dto.IntegrationPluginDTO; import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; @@ -27,7 +28,10 @@ * @version 1.0: IntegrationGeneratedUpdateListener.java, Date: 2023-07-26 Time: 10:57 */ @Component -public class IntegrationGeneratedUpdateListener extends IntegrationPluginUpdateListener { +public class IntegrationGeneratedUpdateListener { + + @Autowired + private IntegrationPluginUpdateListener integrationPluginUpdateListener; @PostConstruct void register() { @@ -44,7 +48,7 @@ public void onEvent(IntegrationGeneratedDTO integrationGeneratedDTO) { if (StringUtils.isBlank(integrationPluginDTO.json) || StringUtils.isBlank(integrationPluginDTO.type)) return; - List upsert = upsertGaea(integrationPluginDTO); + List upsert = integrationPluginUpdateListener.upsertGaea(integrationPluginDTO); notify(upsert); } diff --git a/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/plugin/core/PortCheckPlugin.java b/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/plugin/core/PortCheckPlugin.java index 13ee03b7c..4b257a6eb 100644 --- a/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/plugin/core/PortCheckPlugin.java +++ b/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/plugin/core/PortCheckPlugin.java @@ -93,8 +93,11 @@ public List genPluginList(IntegrationPluginDTO integrationPlugi portCheckPlugin.gaeaTableName = integrationPluginDTO.name + "_" + i++; portCheckPlugin.collectRange = - tenantInitService.getCollectMonitorRange(integrationPluginDTO.getTenant() + "_server", - integrationPluginDTO.getWorkspace(), config.range, config.getMetaLabel()); + tenantInitService.getCollectMonitorRange( + tenantInitService.getTenantServerTable( + integrationPluginDTO.getTenant() + "_server"), + integrationPluginDTO.getTenant(), integrationPluginDTO.getWorkspace(), config.range, + config.getMetaLabel()); portCheckPlugin.portCheckTask = portCheckTask; portCheckPlugin.collectPlugin = "dialcheck"; diff --git a/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/service/TenantInitService.java b/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/service/TenantInitService.java index 6aecc488b..68a229cb9 100644 --- a/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/service/TenantInitService.java +++ b/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/service/TenantInitService.java @@ -60,7 +60,8 @@ public interface TenantInitService { */ String getTsdbTenant(String tenant); - Boolean checkConditions(String workspace, String metric, List filters); + Boolean checkConditions(String tenant, String workspace, String metric, + List filters); /** @@ -69,7 +70,7 @@ public interface TenantInitService { * @param workspace * @return */ - Map getTenantWorkspaceMetaConditions(String workspace); + Map getTenantWorkspaceMetaConditions(String tenant, String workspace); /** * add query filters by workspace @@ -77,7 +78,7 @@ public interface TenantInitService { * @param workspace * @return */ - List getTenantFilters(String workspace); + List getTenantFilters(String tenant, String workspace); /** * logmonitor metric table @@ -88,8 +89,8 @@ public interface TenantInitService { String getLogMonitorMetricTable(String tableName); - CloudMonitorRange getCollectMonitorRange(String table, String workspace, List strings, - MetaLabel metaLabel); + CloudMonitorRange getCollectMonitorRange(String table, String tenant, String workspace, + List strings, MetaLabel metaLabel); Boolean checkCookie(String tenant, String workspace); diff --git a/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/service/agent/AgentLogTailService.java b/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/service/agent/AgentLogTailService.java index ced161d6f..6479e4100 100644 --- a/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/service/agent/AgentLogTailService.java +++ b/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/service/agent/AgentLogTailService.java @@ -138,7 +138,8 @@ private Map getDimByRequest(AgentParamRequest agentParamRequest, } - Map conditions = tenantInitService.getTenantWorkspaceMetaConditions(workspace); + Map conditions = + tenantInitService.getTenantWorkspaceMetaConditions(tenant, workspace); if (!CollectionUtils.isEmpty(conditions)) { queryExample.getParams().putAll(conditions); } diff --git a/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/service/impl/DefaultTenantInitServiceImpl.java b/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/service/impl/DefaultTenantInitServiceImpl.java index d9a7cbd88..91979a784 100644 --- a/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/service/impl/DefaultTenantInitServiceImpl.java +++ b/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/service/impl/DefaultTenantInitServiceImpl.java @@ -53,17 +53,18 @@ public String getTsdbTenant(String tenant) { } @Override - public Boolean checkConditions(String workspace, String metric, List filters) { + public Boolean checkConditions(String tenant, String workspace, String metric, + List filters) { return true; } @Override - public Map getTenantWorkspaceMetaConditions(String workspace) { + public Map getTenantWorkspaceMetaConditions(String tenant, String workspace) { return new HashMap<>(); } @Override - public List getTenantFilters(String workspace) { + public List getTenantFilters(String tenant, String workspace) { return new ArrayList<>(); } @@ -73,7 +74,7 @@ public String getLogMonitorMetricTable(String tableName) { } @Override - public CloudMonitorRange getCollectMonitorRange(String table, String workspace, + public CloudMonitorRange getCollectMonitorRange(String table, String tenant, String workspace, List strings, MetaLabel metaLabel) { return GaeaConvertUtil.convertCloudMonitorRange(table, metaLabel, strings); } diff --git a/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/service/impl/IntegrationPluginServiceImpl.java b/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/service/impl/IntegrationPluginServiceImpl.java index 5ee8e7ebe..7fffd83cc 100644 --- a/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/service/impl/IntegrationPluginServiceImpl.java +++ b/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/service/impl/IntegrationPluginServiceImpl.java @@ -105,10 +105,7 @@ public IntegrationPluginDTO create(IntegrationPluginDTO integrationPluginDTO) { IntegrationPlugin model = integrationPluginConverter.dtoToDO(integrationPluginDTO); save(model); IntegrationPluginDTO integrationPlugin = integrationPluginConverter.doToDTO(model); - EventBusHolder.post(integrationPlugin); - - return integrationPlugin; } diff --git a/server/home/home-web/src/main/java/io/holoinsight/server/home/web/controller/MetaFacadeImpl.java b/server/home/home-web/src/main/java/io/holoinsight/server/home/web/controller/MetaFacadeImpl.java index 2d6d4b621..8e229ade1 100644 --- a/server/home/home-web/src/main/java/io/holoinsight/server/home/web/controller/MetaFacadeImpl.java +++ b/server/home/home-web/src/main/java/io/holoinsight/server/home/web/controller/MetaFacadeImpl.java @@ -7,14 +7,11 @@ import io.holoinsight.server.home.common.util.MonitorException; import io.holoinsight.server.home.common.util.scope.AuthTargetType; import io.holoinsight.server.home.common.util.scope.MonitorScope; -import io.holoinsight.server.home.common.util.scope.MonitorUser; import io.holoinsight.server.home.common.util.scope.PowerConstants; import io.holoinsight.server.home.common.util.scope.RequestContext; -import io.holoinsight.server.home.common.util.scope.RequestContext.Context; import io.holoinsight.server.home.web.common.ManageCallback; import io.holoinsight.server.home.web.common.ParaCheckUtil; import io.holoinsight.server.home.web.interceptor.MonitorScopeAuth; -import io.holoinsight.server.common.J; import io.holoinsight.server.common.JsonResult; import io.holoinsight.server.meta.common.model.QueryExample; import io.holoinsight.server.meta.facade.service.DataClientService; @@ -28,10 +25,8 @@ 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.ResponseBody; import org.springframework.web.bind.annotation.RestController; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -70,7 +65,7 @@ public void doManage() { queryExample.getParams().putAll(condition); MonitorScope ms = RequestContext.getContext().ms; Map conditions = - tenantInitService.getTenantWorkspaceMetaConditions(ms.getWorkspace()); + tenantInitService.getTenantWorkspaceMetaConditions(ms.getTenant(), ms.getWorkspace()); if (!CollectionUtils.isEmpty(conditions)) { queryExample.getParams().putAll(conditions); } @@ -141,7 +136,7 @@ public void doManage() { } MonitorScope ms = RequestContext.getContext().ms; Map conditions = - tenantInitService.getTenantWorkspaceMetaConditions(ms.getWorkspace()); + tenantInitService.getTenantWorkspaceMetaConditions(ms.getTenant(), ms.getWorkspace()); if (!CollectionUtils.isEmpty(conditions)) { conditions.forEach((k, v) -> queryExample.getParams().put(k, v)); } diff --git a/server/home/home-web/src/main/java/io/holoinsight/server/home/web/controller/QueryFacadeImpl.java b/server/home/home-web/src/main/java/io/holoinsight/server/home/web/controller/QueryFacadeImpl.java index a3050f564..da629e4b4 100644 --- a/server/home/home-web/src/main/java/io/holoinsight/server/home/web/controller/QueryFacadeImpl.java +++ b/server/home/home-web/src/main/java/io/holoinsight/server/home/web/controller/QueryFacadeImpl.java @@ -211,7 +211,7 @@ public void doManage() { .setEnd(System.currentTimeMillis() - 60000 * 5); List tenantFilters = - tenantInitService.getTenantFilters(ms.getWorkspace()); + tenantInitService.getTenantFilters(ms.getTenant(), ms.getWorkspace()); if (!CollectionUtils.isEmpty(tenantFilters)) { builder.addAllFilters(tenantFilters); } @@ -297,7 +297,7 @@ public void doManage() { .addAllGroupBy(Collections.singletonList(tagQueryRequest.getKey())); List tenantFilters = - tenantInitService.getTenantFilters(ms.getWorkspace()); + tenantInitService.getTenantFilters(ms.getTenant(), ms.getWorkspace()); if (!CollectionUtils.isEmpty(tagQueryRequest.getConditions())) { tagQueryRequest.getConditions().forEach((k, v) -> { @@ -474,7 +474,7 @@ public QueryProto.QueryRequest convertRequest(DataQueryRequest request) { QueryProto.Datasource.Builder datasourceBuilder = QueryProto.Datasource.newBuilder(); toProtoBean(datasourceBuilder, d); - Boolean aBoolean = tenantInitService.checkConditions(ms.getWorkspace(), + Boolean aBoolean = tenantInitService.checkConditions(ms.getTenant(), ms.getWorkspace(), datasourceBuilder.getMetric(), datasourceBuilder.getFiltersList()); if (!aBoolean) { throw new MonitorException("workspace is illegal"); diff --git a/server/home/home-web/src/main/java/io/holoinsight/server/home/web/controller/SearchFacadeImpl.java b/server/home/home-web/src/main/java/io/holoinsight/server/home/web/controller/SearchFacadeImpl.java index 0cc20a230..6af2b91f8 100644 --- a/server/home/home-web/src/main/java/io/holoinsight/server/home/web/controller/SearchFacadeImpl.java +++ b/server/home/home-web/src/main/java/io/holoinsight/server/home/web/controller/SearchFacadeImpl.java @@ -221,7 +221,7 @@ public SearchKeywordRet searchInfraEntity(String keyword, String tenant, String Pattern.compile(String.format("^.*%s.*$", keyword), Pattern.CASE_INSENSITIVE)); if (StringUtils.isNotBlank(workspace)) { Map conditions = - tenantInitService.getTenantWorkspaceMetaConditions(workspace); + tenantInitService.getTenantWorkspaceMetaConditions(tenant, workspace); if (!CollectionUtils.isEmpty(conditions)) { conditions.forEach((k, v) -> queryExample.getParams().put(k, v)); } diff --git a/server/home/home-web/src/main/java/io/holoinsight/server/home/web/controller/UserFavoriteFacadeImpl.java b/server/home/home-web/src/main/java/io/holoinsight/server/home/web/controller/UserFavoriteFacadeImpl.java index 5286c4415..f1cefac6f 100644 --- a/server/home/home-web/src/main/java/io/holoinsight/server/home/web/controller/UserFavoriteFacadeImpl.java +++ b/server/home/home-web/src/main/java/io/holoinsight/server/home/web/controller/UserFavoriteFacadeImpl.java @@ -131,7 +131,7 @@ public void checkParameter() { map.put("hostname", userFavorite.name); queryExample.setParams(map); Map conditions = tenantInitService - .getTenantWorkspaceMetaConditions(RequestContext.getContext().ms.getWorkspace()); + .getTenantWorkspaceMetaConditions(ms.getTenant(), ms.getWorkspace()); if (!CollectionUtils.isEmpty(conditions)) { queryExample.getParams().putAll(conditions); }