From 9e0b1ee9a9984ed021714e4474ce44e44738a04c Mon Sep 17 00:00:00 2001 From: Zhuohao Li <604916089@qq.com> Date: Fri, 13 Aug 2021 11:06:53 +0800 Subject: [PATCH 001/119] add history query. (#3878) * add history query. * add CHANGES.md. --- CHANGES.md | 1 + .../controller/CommitController.java | 13 +++++-- .../biz/repository/CommitRepository.java | 1 + .../apollo/biz/service/CommitService.java | 5 +++ .../apollo/portal/api/AdminServiceAPI.java | 10 ++++++ .../portal/controller/CommitController.java | 9 ++++- .../apollo/portal/service/CommitService.java | 7 ++++ .../src/main/resources/static/i18n/en.json | 2 ++ .../src/main/resources/static/i18n/zh-CN.json | 2 ++ .../directive/namespace-panel-directive.js | 34 +++++++++++++++++++ .../static/scripts/services/CommitService.js | 3 +- .../component/namespace-panel-master-tab.html | 13 +++++++ 12 files changed, 95 insertions(+), 5 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 5b3c4c5971f..b441593d17b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -75,6 +75,7 @@ Apollo 1.9.0 * [use jdk 8 to publish apollo-client-config-data](https://github.com/ctripcorp/apollo/pull/3880) * [fix apollo config data loader with profiles](https://github.com/ctripcorp/apollo/pull/3870) * [polish log](https://github.com/ctripcorp/apollo/pull/3882) +* [add history query](https://github.com/ctripcorp/apollo/pull/3878) ------------------ All issues and pull requests are [here](https://github.com/ctripcorp/apollo/milestone/6?closed=1) diff --git a/apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/controller/CommitController.java b/apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/controller/CommitController.java index 8206e99446b..a4430659412 100644 --- a/apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/controller/CommitController.java +++ b/apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/controller/CommitController.java @@ -20,9 +20,11 @@ import com.ctrip.framework.apollo.biz.service.CommitService; import com.ctrip.framework.apollo.common.dto.CommitDTO; import com.ctrip.framework.apollo.common.utils.BeanUtils; +import com.ctrip.framework.apollo.core.utils.StringUtils; import org.springframework.data.domain.Pageable; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.util.List; @@ -39,9 +41,14 @@ public CommitController(final CommitService commitService) { @GetMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/commit") public List find(@PathVariable String appId, @PathVariable String clusterName, - @PathVariable String namespaceName, Pageable pageable){ - - List commits = commitService.find(appId, clusterName, namespaceName, pageable); + @PathVariable String namespaceName, @RequestParam(required = false) String key, Pageable pageable){ + + List commits; + if (StringUtils.isEmpty(key)) { + commits = commitService.find(appId, clusterName, namespaceName, pageable); + } else { + commits = commitService.findByKey(appId, clusterName, namespaceName, key, pageable); + } return BeanUtils.batchTransform(CommitDTO.class, commits); } diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/CommitRepository.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/CommitRepository.java index 0af8fa80c89..337918e4978 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/CommitRepository.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/CommitRepository.java @@ -38,4 +38,5 @@ List findByAppIdAndClusterNameAndNamespaceNameAndDataChangeLastModifiedT @Query("update Commit set isdeleted=1,DataChange_LastModifiedBy = ?4 where appId=?1 and clusterName=?2 and namespaceName = ?3") int batchDelete(String appId, String clusterName, String namespaceName, String operator); + List findByAppIdAndClusterNameAndNamespaceNameAndChangeSetsLikeOrderByIdDesc(String appId, String clusterName, String namespaceName,String changeSets, Pageable page); } diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/CommitService.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/CommitService.java index 5238bb23939..70b19f781f0 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/CommitService.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/CommitService.java @@ -51,6 +51,11 @@ public List find(String appId, String clusterName, String namespaceName, appId, clusterName, namespaceName, lastModifiedTime, page); } + public List findByKey(String appId, String clusterName, String namespaceName, String key,Pageable page){ + String queryKey = "\"key\":\""+ key +"\""; + return commitRepository.findByAppIdAndClusterNameAndNamespaceNameAndChangeSetsLikeOrderByIdDesc(appId, clusterName, namespaceName, "%"+ queryKey + "%", page); + } + @Transactional public int batchDelete(String appId, String clusterName, String namespaceName, String operator){ return commitRepository.batchDelete(appId, clusterName, namespaceName, operator); diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/api/AdminServiceAPI.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/api/AdminServiceAPI.java index 346d2ce96a1..b149501dba0 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/api/AdminServiceAPI.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/api/AdminServiceAPI.java @@ -383,6 +383,16 @@ public List find(String appId, Env env, String clusterName, String na return Arrays.asList(commitDTOs); } + + public List findByKey(String appId, Env env, String clusterName, String namespaceName, String key, int page, int size) { + + CommitDTO[] commitDTOs = restTemplate.get(env, + "apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/commit?key={key}&page={page}&size={size}", + CommitDTO[].class, + appId, clusterName, namespaceName, key, page, size); + + return Arrays.asList(commitDTOs); + } } @Service diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/CommitController.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/CommitController.java index 4444dec1aed..9795c880167 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/CommitController.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/CommitController.java @@ -17,6 +17,7 @@ package com.ctrip.framework.apollo.portal.controller; import com.ctrip.framework.apollo.common.dto.CommitDTO; +import com.ctrip.framework.apollo.core.utils.StringUtils; import com.ctrip.framework.apollo.portal.environment.Env; import com.ctrip.framework.apollo.portal.component.PermissionValidator; import com.ctrip.framework.apollo.portal.service.CommitService; @@ -47,12 +48,18 @@ public CommitController(final CommitService commitService, final PermissionValid @GetMapping("/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/commits") public List find(@PathVariable String appId, @PathVariable String env, @PathVariable String clusterName, @PathVariable String namespaceName, + @RequestParam(required = false) String key, @Valid @PositiveOrZero(message = "page should be positive or 0") @RequestParam(defaultValue = "0") int page, @Valid @Positive(message = "size should be positive number") @RequestParam(defaultValue = "10") int size) { if (permissionValidator.shouldHideConfigToCurrentUser(appId, env, namespaceName)) { return Collections.emptyList(); } - return commitService.find(appId, Env.valueOf(env), clusterName, namespaceName, page, size); + if (StringUtils.isEmpty(key)) { + return commitService.find(appId, Env.valueOf(env), clusterName, namespaceName, page, size); + } else { + return commitService.findByKey(appId, Env.valueOf(env), clusterName, namespaceName, key, page, size); + } + } } diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/CommitService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/CommitService.java index fadc208a033..47f7c439d4a 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/CommitService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/CommitService.java @@ -44,4 +44,11 @@ public List find(String appId, Env env, String clusterName, String na return dtoList; } + public List findByKey(String appId, Env env, String clusterName, String namespaceName, String key, int page, int size) { + List dtoList = commitAPI.findByKey(appId, env, clusterName, namespaceName, key, page, size); + this.additionalUserInfoEnrichService.enrichAdditionalUserInfo(dtoList, + BaseDtoUserInfoEnrichedAdapter::new); + return dtoList; + } + } diff --git a/apollo-portal/src/main/resources/static/i18n/en.json b/apollo-portal/src/main/resources/static/i18n/en.json index ed77dd1b5a6..c254965f4bd 100644 --- a/apollo-portal/src/main/resources/static/i18n/en.json +++ b/apollo-portal/src/main/resources/static/i18n/en.json @@ -242,6 +242,8 @@ "Component.Namespace.Master.Items.Body.HistoryView.Deleted": "Delete", "Component.Namespace.Master.Items.Body.HistoryView.LoadMore": "Load more", "Component.Namespace.Master.Items.Body.HistoryView.NoHistory": "No Change History", + "Component.Namespace.Master.Items.Body.HistoryView.FilterHistory": "Filter History", + "Component.Namespace.Master.Items.Body.HistoryView.FilterHistory.SortByKey": "Filter the history by key", "Component.Namespace.Master.Items.Body.Instance.Tips": "Tips: Only show instances who have fetched configurations in the last 24 hrs ", "Component.Namespace.Master.Items.Body.Instance.UsedNewItem": "Instances using the latest configuration", "Component.Namespace.Master.Items.Body.Instance.NoUsedNewItem": "Instances using outdated configuration", diff --git a/apollo-portal/src/main/resources/static/i18n/zh-CN.json b/apollo-portal/src/main/resources/static/i18n/zh-CN.json index ca1b0def070..6e5c448a840 100644 --- a/apollo-portal/src/main/resources/static/i18n/zh-CN.json +++ b/apollo-portal/src/main/resources/static/i18n/zh-CN.json @@ -242,6 +242,8 @@ "Component.Namespace.Master.Items.Body.HistoryView.Deleted": "删除", "Component.Namespace.Master.Items.Body.HistoryView.LoadMore": "加载更多", "Component.Namespace.Master.Items.Body.HistoryView.NoHistory": "无更改历史", + "Component.Namespace.Master.Items.Body.HistoryView.FilterHistory": "过滤更改历史", + "Component.Namespace.Master.Items.Body.HistoryView.FilterHistory.SortByKey": "按key过滤更改历史", "Component.Namespace.Master.Items.Body.Instance.Tips": "实例说明:只展示最近一天访问过Apollo的实例", "Component.Namespace.Master.Items.Body.Instance.UsedNewItem": "使用最新配置的实例", "Component.Namespace.Master.Items.Body.Instance.NoUsedNewItem": "使用非最新配置的实例", diff --git a/apollo-portal/src/main/resources/static/scripts/directive/namespace-panel-directive.js b/apollo-portal/src/main/resources/static/scripts/directive/namespace-panel-directive.js index b2cee3a4561..d067c17d7c4 100644 --- a/apollo-portal/src/main/resources/static/scripts/directive/namespace-panel-directive.js +++ b/apollo-portal/src/main/resources/static/scripts/directive/namespace-panel-directive.js @@ -64,7 +64,9 @@ function directive($window, $translate, toastr, AppUtil, EventManager, Permissio scope.refreshNamespace = refreshNamespace; scope.switchView = switchView; scope.toggleItemSearchInput = toggleItemSearchInput; + scope.toggleHistorySearchInput = toggleHistorySearchInput; scope.searchItems = searchItems; + scope.searchHistory = searchHistory; scope.loadCommitHistory = loadCommitHistory; scope.toggleTextEditStatus = toggleTextEditStatus; scope.goToSyncPage = goToSyncPage; @@ -129,6 +131,7 @@ function directive($window, $translate, toastr, AppUtil, EventManager, Permissio namespace.displayControl = { currentOperateBranch: 'master', showSearchInput: false, + showHistorySearchInput: false, show: scope.showBody }; scope.showNamespaceBody = namespace.showNamespaceBody ? true : scope.showBody; @@ -472,6 +475,7 @@ function directive($window, $translate, toastr, AppUtil, EventManager, Permissio scope.env, namespace.baseInfo.clusterName, namespace.baseInfo.namespaceName, + namespace.HistorySearchKey, namespace.commitPage, size) .then(function (result) { @@ -859,6 +863,36 @@ function directive($window, $translate, toastr, AppUtil, EventManager, Permissio namespace.viewItems = items; } + function toggleHistorySearchInput(namespace) { + namespace.displayControl.showHistorySearchInput = !namespace.displayControl.showHistorySearchInput; + } + + function searchHistory(namespace) { + namespace.commits = []; + namespace.commitPage = 0; + var size = 10; + CommitService.find_commits(scope.appId, + scope.env, + namespace.baseInfo.clusterName, + namespace.baseInfo.namespaceName, + namespace.HistorySearchKey, + namespace.commitPage, + size) + .then(function (result) { + if (result.length < size) { + namespace.hasLoadAllCommit = true; + } + + for (var i = 0; i < result.length; i++) { + //to json + result[i].changeSets = JSON.parse(result[i].changeSets); + namespace.commits.push(result[i]); + } + }, function (result) { + toastr.error(AppUtil.errorMsg(result), $translate.instant('ApolloNsPanel.LoadingHistoryError')); + }); + } + //normal release and gray release function publish(namespace) { diff --git a/apollo-portal/src/main/resources/static/scripts/services/CommitService.js b/apollo-portal/src/main/resources/static/scripts/services/CommitService.js index 16dcf24bd47..8abefe7a3cc 100644 --- a/apollo-portal/src/main/resources/static/scripts/services/CommitService.js +++ b/apollo-portal/src/main/resources/static/scripts/services/CommitService.js @@ -23,13 +23,14 @@ appService.service('CommitService', ['$resource', '$q','AppUtil', function ($res } }); return { - find_commits: function (appId, env, clusterName, namespaceName, page, size) { + find_commits: function (appId, env, clusterName, namespaceName, key, page, size) { var d = $q.defer(); commit_resource.find_commits({ appId: appId, env: env, clusterName: clusterName, namespaceName: namespaceName, + key: key, page: page, size: size }, diff --git a/apollo-portal/src/main/resources/static/views/component/namespace-panel-master-tab.html b/apollo-portal/src/main/resources/static/views/component/namespace-panel-master-tab.html index 4b9b64099ab..5d374db50c3 100644 --- a/apollo-portal/src/main/resources/static/views/component/namespace-panel-master-tab.html +++ b/apollo-portal/src/main/resources/static/views/component/namespace-panel-master-tab.html @@ -191,6 +191,13 @@ data-target="#commitModal" ng-show="namespace.isTextEditing && namespace.viewType == 'text'" ng-click="modifyByText(namespace)"> + +