Skip to content

Commit

Permalink
Fixed some issues
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoxianhjy committed Sep 6, 2024
1 parent d3be11c commit a90c2ac
Show file tree
Hide file tree
Showing 21 changed files with 55 additions and 123 deletions.
4 changes: 2 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Apollo 2.4.0
------------------
* [Update the server config link in system info page](https://github.com/apolloconfig/apollo/pull/5204)
* [Feature support portal restTemplate Client connection pool config](https://github.com/apolloconfig/apollo/pull/5200)

* [Feature added the ability for administrators to globally search for Value](https://github.com/apolloconfig/apollo/pull/5182)

------------------
All issues and pull requests are [here](https://github.com/apolloconfig/apollo/milestone/15?closed=1)
All issues and pull requests are [here](https://github.com/apolloconfig/apollo/milestone/15?closed=1)
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.ctrip.framework.apollo.biz.service.ItemService;
import com.ctrip.framework.apollo.common.dto.*;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import org.junit.Assert;
Expand Down Expand Up @@ -63,7 +62,7 @@ public void testCreate() {
ClusterDTO cluster = restTemplate.getForObject(clusterBaseUrl(), ClusterDTO.class, app.getAppId(), "default");
assert cluster != null;
NamespaceDTO namespace = restTemplate.getForObject(namespaceBaseUrl(),
NamespaceDTO.class, app.getAppId(), cluster.getName(), "application");
NamespaceDTO.class, app.getAppId(), cluster.getName(), "application");

String itemKey = "test-key";
String itemValue = "test-value";
Expand All @@ -73,12 +72,12 @@ public void testCreate() {
item.setDataChangeLastModifiedBy("apollo");

ResponseEntity<ItemDTO> response = restTemplate.postForEntity(itemBaseUrl(),
item, ItemDTO.class, app.getAppId(), cluster.getName(), namespace.getNamespaceName());
item, ItemDTO.class, app.getAppId(), cluster.getName(), namespace.getNamespaceName());
Assert.assertEquals(HttpStatus.OK, response.getStatusCode());
Assert.assertEquals(itemKey, Objects.requireNonNull(response.getBody()).getKey());

List<Commit> commitList = commitRepository.findByAppIdAndClusterNameAndNamespaceNameOrderByIdDesc(app.getAppId(), cluster.getName(), namespace.getNamespaceName(),
Pageable.ofSize(10));
Pageable.ofSize(10));
Assert.assertEquals(1, commitList.size());

Commit commit = commitList.get(0);
Expand All @@ -98,15 +97,15 @@ public void testUpdate() {
ClusterDTO cluster = restTemplate.getForObject(clusterBaseUrl(), ClusterDTO.class, app.getAppId(), "default");
assert cluster != null;
NamespaceDTO namespace = restTemplate.getForObject(namespaceBaseUrl(),
NamespaceDTO.class, app.getAppId(), cluster.getName(), "application");
NamespaceDTO.class, app.getAppId(), cluster.getName(), "application");

String itemKey = "test-key";
String itemValue = "test-value-updated";

long itemId = itemRepository.findByKey(itemKey, Pageable.ofSize(1))
.getContent()
.get(0)
.getId();
.getContent()
.get(0)
.getId();
ItemDTO item = new ItemDTO(itemKey, itemValue, "", 1);
item.setDataChangeLastModifiedBy("apollo");

Expand All @@ -120,7 +119,7 @@ public void testUpdate() {
});

List<Commit> commitList = commitRepository.findByAppIdAndClusterNameAndNamespaceNameOrderByIdDesc(app.getAppId(), cluster.getName(), namespace.getNamespaceName(),
Pageable.ofSize(10));
Pageable.ofSize(10));
assertThat(commitList).hasSize(2);
}

Expand All @@ -136,23 +135,23 @@ public void testDelete() {
ClusterDTO cluster = restTemplate.getForObject(clusterBaseUrl(), ClusterDTO.class, app.getAppId(), "default");
assert cluster != null;
NamespaceDTO namespace = restTemplate.getForObject(namespaceBaseUrl(),
NamespaceDTO.class, app.getAppId(), cluster.getName(), "application");
NamespaceDTO.class, app.getAppId(), cluster.getName(), "application");

String itemKey = "test-key";

long itemId = itemRepository.findByKey(itemKey, Pageable.ofSize(1))
.getContent()
.get(0)
.getId();
.getContent()
.get(0)
.getId();

String deleteUrl = url( "/items/{itemId}?operator=apollo");
restTemplate.delete(deleteUrl, itemId);
assertThat(itemRepository.findById(itemId).isPresent())
.isFalse();
.isFalse();

assert namespace != null;
List<Commit> commitList = commitRepository.findByAppIdAndClusterNameAndNamespaceNameOrderByIdDesc(app.getAppId(), cluster.getName(), namespace.getNamespaceName(),
Pageable.ofSize(10));
Pageable.ofSize(10));
assertThat(commitList).hasSize(2);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ Release findFirstByAppIdAndClusterNameAndNamespaceNameAndIsAbandonedFalseOrderBy

List<Release> findByIdIn(Set<Long> releaseIds);

List<Release> findAll();

@Modifying
@Query("update Release set IsDeleted = true, DeletedAt = ROUND(UNIX_TIMESTAMP(NOW(4))*1000), DataChange_LastModifiedBy = ?4 where AppId=?1 and ClusterName=?2 and NamespaceName = ?3 and IsDeleted = false")
int batchDelete(String appId, String clusterName, String namespaceName, String operator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
import com.ctrip.framework.apollo.biz.entity.Audit;
import com.ctrip.framework.apollo.biz.entity.Item;
import com.ctrip.framework.apollo.biz.entity.Namespace;
import com.ctrip.framework.apollo.biz.entity.Release;
import com.ctrip.framework.apollo.biz.repository.ItemRepository;
import com.ctrip.framework.apollo.biz.repository.ReleaseRepository;
import com.ctrip.framework.apollo.common.dto.ItemInfoDTO;
import com.ctrip.framework.apollo.common.exception.BadRequestException;
import com.ctrip.framework.apollo.common.exception.NotFoundException;
Expand All @@ -32,13 +30,10 @@

import org.springframework.context.annotation.Lazy;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Clob;
import java.sql.SQLException;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand All @@ -52,19 +47,16 @@ public class ItemService {
private final NamespaceService namespaceService;
private final AuditService auditService;
private final BizConfig bizConfig;
private final ReleaseRepository releaseRepository;

public ItemService(
final ItemRepository itemRepository,
final @Lazy NamespaceService namespaceService,
final AuditService auditService,
final BizConfig bizConfig,
final ReleaseRepository releaseRepository) {
final BizConfig bizConfig) {
this.itemRepository = itemRepository;
this.namespaceService = namespaceService;
this.auditService = auditService;
this.bizConfig = bizConfig;
this.releaseRepository = releaseRepository;
}


Expand Down Expand Up @@ -161,21 +153,6 @@ public Page<ItemInfoDTO> getItemInfoBySearch(String key, String value, Pageable
} else {
itemInfoDTOs = itemRepository.findItemsByKeyAndValueLike(key, value, limit);
}

List<Release> releaseItems = releaseRepository.findAll();
for (ItemInfoDTO itemInfoDTO : itemInfoDTOs.getContent()) {
boolean isIncluded = false;
for (Release releaseItem : releaseItems) {
if (releaseItem.getConfigurations().contains(itemInfoDTO.getKey()) && releaseItem.getConfigurations().contains(itemInfoDTO.getValue())) {
itemInfoDTO.setStatus("1");
isIncluded = true;
break;
}
}
if (!isIncluded) {
itemInfoDTO.setStatus("0");
}
}
return itemInfoDTOs;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import org.springframework.data.domain.PageRequest;
import org.springframework.test.context.jdbc.Sql;

import java.util.List;

public class ItemServiceTest extends AbstractIntegrationTest {

@Autowired
Expand Down Expand Up @@ -84,7 +82,6 @@ public void testSearchItem() {
itemInfoDTO.setAppId("testApp");
itemInfoDTO.setClusterName("default");
itemInfoDTO.setNamespaceName("application");
itemInfoDTO.setStatus("0");
itemInfoDTO.setKey("k1");
itemInfoDTO.setValue("v1");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,16 @@ public class ItemInfoDTO extends BaseDTO{
private String appId;
private String clusterName;
private String namespaceName;
private String status;
private String key;
private String value;

public ItemInfoDTO() {
}

public ItemInfoDTO(String appId, String clusterName, String namespaceName,
String status, String key, String value) {
public ItemInfoDTO(String appId, String clusterName, String namespaceName, String key, String value) {
this.appId = appId;
this.clusterName = clusterName;
this.namespaceName = namespaceName;
this.status = status;
this.key = key;
this.value = value;
}

public ItemInfoDTO(String appId, String clusterName, String namespaceName,
String key, String value) {
this.appId = appId;
this.clusterName = clusterName;
this.namespaceName = namespaceName;
this.status = "0";
this.key = key;
this.value = value;
}
Expand Down Expand Up @@ -72,14 +59,6 @@ public void setNamespaceName(String namespaceName) {
this.namespaceName = namespaceName;
}

public String getStatus() {
return status;
}

public void setStatus(String status) {
this.status = status;
}

public String getKey() {
return key;
}
Expand All @@ -102,7 +81,6 @@ public String toString() {
"appId='" + appId + '\'' +
", clusterName='" + clusterName + '\'' +
", namespaceName='" + namespaceName + '\'' +
", status='" + status + '\'' +
", key='" + key + '\'' +
", value='" + value + '\'' +
'}';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ public ResponseEntity<?> get_ItemInfo_BySearch(@RequestParam(value = "key", requ
AtomicBoolean hasMoreData = new AtomicBoolean(false);
activeEnvs.forEach(env -> {
PageDTO<ItemInfo> perEnvItemInfos = globalSearchValueService.get_PerEnv_ItemInfo_BySearch(env, key, value,0, portalConfig.getPerEnvSearchMaxResults());
if (!perEnvItemInfos.hasContent()) {
return;
}
if(perEnvItemInfos.getTotal() > portalConfig.getPerEnvSearchMaxResults()){
envBeyondLimit.add(env.getName());
hasMoreData.set(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,18 @@ public class ItemInfo {
private String envName;
private String clusterName;
private String namespaceName;
private String status;
private String key;
private String value;

public ItemInfo() {
}

public ItemInfo(String appId, String envName, String clusterName,
String namespaceName, String status, String key, String value) {
String namespaceName, String key, String value) {
this.appId = appId;
this.envName = envName;
this.clusterName = clusterName;
this.namespaceName = namespaceName;
this.status = status;
this.key = key;
this.value = value;
}
Expand Down Expand Up @@ -72,14 +70,6 @@ public void setNamespaceName(String namespaceName) {
this.namespaceName = namespaceName;
}

public String getStatus() {
return status;
}

public void setStatus(String status) {
this.status = status;
}

public String getKey() {
return key;
}
Expand All @@ -103,7 +93,6 @@ public String toString() {
", envName='" + envName + '\'' +
", clusterName='" + clusterName + '\'' +
", namespaceName='" + namespaceName + '\'' +
", status='" + status + '\'' +
", key='" + key + '\'' +
", value='" + value + '\'' +
'}';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import com.ctrip.framework.apollo.portal.api.AdminServiceAPI;
import com.ctrip.framework.apollo.portal.entity.vo.ItemInfo;
import com.ctrip.framework.apollo.portal.environment.Env;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

Expand All @@ -30,6 +32,7 @@
@Service
public class GlobalSearchValueService {

private static final Logger LOGGER = LoggerFactory.getLogger(GlobalSearchValueService.class);
private final AdminServiceAPI.ItemAPI itemAPI;

public GlobalSearchValueService(AdminServiceAPI.ItemAPI itemAPI) {
Expand All @@ -40,8 +43,12 @@ public PageDTO<ItemInfo> get_PerEnv_ItemInfo_BySearch(Env env, String key, Strin
List<ItemInfo> perEnvItemInfos = new ArrayList<>();
PageDTO<ItemInfoDTO> perEnvItemInfoDTOs = itemAPI.getPerEnvItemInfoBySearch(env, key, value, page, size);
perEnvItemInfoDTOs.getContent().forEach(itemInfoDTO -> {
ItemInfo itemInfo = new ItemInfo(itemInfoDTO.getAppId(),env.getName(),itemInfoDTO.getClusterName(),itemInfoDTO.getNamespaceName(),itemInfoDTO.getStatus(),itemInfoDTO.getKey(),itemInfoDTO.getValue());
perEnvItemInfos.add(itemInfo);
try {
ItemInfo itemInfo = new ItemInfo(itemInfoDTO.getAppId(),env.getName(),itemInfoDTO.getClusterName(),itemInfoDTO.getNamespaceName(),itemInfoDTO.getKey(),itemInfoDTO.getValue());
perEnvItemInfos.add(itemInfo);
} catch (Exception e) {
LOGGER.error("Error converting ItemInfoDTO to ItemInfo for item: {}", itemInfoDTO, e);
}
});
return new PageDTO<>(perEnvItemInfos, PageRequest.of(page, size), perEnvItemInfoDTOs.getTotal());
}
Expand Down
27 changes: 2 additions & 25 deletions apollo-portal/src/main/resources/static/global_search_value.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,38 +72,15 @@
<th style="text-align: left;width: 10%">{{'Global.Env' | translate }}</th>
<th style="text-align: left;width: 10%">{{'Global.Cluster' | translate }}</th>
<th style="text-align: left;width: 10%">{{'Global.NameSpace' | translate }}</th>
<th style="text-align: left;width: 10%">{{'Global.Status' | translate }}</th>
<th style="text-align: left;width: 10%">{{'Global.Key' | translate }}</th>
<th style="text-align: left;width: 30%">{{'Global.Value' | translate }}</th>
<th style="text-align: left;width: 15%">{{'Global.Key' | translate }}</th>
<th style="text-align: left;width: 35%">{{'Global.Value' | translate }}</th>
<th style="text-align: left;width: 10%">{{'Global.Operate' | translate }}</th>
</tr>
<tr ng-repeat="item in pageItemInfo track by $index" href="#" class="hover cursor-pointer">
<td>{{ item.appId }}</td>
<td>{{ item.envName }}</td>
<td>{{ item.clusterName }}</td>
<td>{{ item.namespaceName }}</td>
<td>
<div class="status-container" style="display: flex; align-items: center;">
<div ng-show="item.status == '1'" class="status-icon icon1"
style="background: green;
width: 8px;
height: 8px;
border-radius: 1px;
margin-right: 5px;
position: relative;
order: 0;"></div>
<span ng-show="item.status == '1'" class="status-text" style="order: 1;">{{'Item.Published' | translate}}</span>
<div ng-show="item.status == '0'" class="status-icon icon2"
style="background: red;
width: 8px;
height: 8px;
border-radius: 1px;
margin-right: 5px;
position: relative;
order: 0;"></div>
<span ng-show="item.status == '0'" class="status-text" style="order: 1;">{{'Item.UnPublished' | translate}}</span>
</div>
</td>
<td>
<span ng-if="isPageItemInfoDirectlyDisplayKey[$index] == '0'">{{ item.key }}</span>
<span ng-if="!(isPageItemInfoDirectlyDisplayKey[$index] == '0')" ng-bind-html="highlightKeyword(item.key,needToBeHighlightedKey)"></span>
Expand Down
3 changes: 0 additions & 3 deletions apollo-portal/src/main/resources/static/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,6 @@
"Global.Env": "Env Name",
"Global.Cluster": "Cluster Name",
"Global.NameSpace": "NameSpace Name",
"Global.Status" : "Posting Status",
"Global.Key": "Key",
"Global.Value": "Value",
"Global.ValueSearch.Tips" : "(Fuzzy search, key can be the name or content of the configuration item, value is the value of the configuration item.)",
Expand All @@ -910,8 +909,6 @@
"Item.GlobalSearchByKey": "Search by Key",
"Item.GlobalSearchByValue": "Search by Value",
"Item.GlobalSearch": "Search",
"Item.UnPublished" : "UnPublished",
"Item.Published" : "Published",
"Item.GlobalSearchSystemError": "System error, please try again or contact the system administrator",
"Item.GlobalSearch.Tips": "Search hint",
"ApolloGlobalSearch.NoData" : "No data yet, please search or add",
Expand Down
Loading

0 comments on commit a90c2ac

Please sign in to comment.