This is an automated email from the ASF dual-hosted git repository.
gaoxihui pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozhera.git
The following commit(s) were added to refs/heads/master by this push:
new 06e36135 feat: add query all space by name (#574)
06e36135 is described below
commit 06e361353a915cf1c2b7e7ed1f0a13a2e5508f42
Author: Xue <[email protected]>
AuthorDate: Wed Apr 2 14:59:52 2025 +0800
feat: add query all space by name (#574)
* feat: add query all space by name
- This change allows querying spaces by name, improving discoverability.
* feat: add query all space by name 02
- This change allows querying spaces by name, improving discoverability.
* feat: add query all space by name 02
- This change allows querying spaces by name, improving discoverability.
* feat: add query all space by name 02
- This change allows querying spaces by name, improving discoverability.
---
.../manager/controller/MilogConfigController.java | 5 ++--
.../log/manager/service/LogSpaceService.java | 2 +-
.../manager/service/impl/LogSpaceServiceImpl.java | 29 +++++++++++++---------
3 files changed, 21 insertions(+), 15 deletions(-)
diff --git
a/ozhera-log/log-manager/src/main/java/org/apache/ozhera/log/manager/controller/MilogConfigController.java
b/ozhera-log/log-manager/src/main/java/org/apache/ozhera/log/manager/controller/MilogConfigController.java
index a43e6026..262a8f81 100644
---
a/ozhera-log/log-manager/src/main/java/org/apache/ozhera/log/manager/controller/MilogConfigController.java
+++
b/ozhera-log/log-manager/src/main/java/org/apache/ozhera/log/manager/controller/MilogConfigController.java
@@ -78,8 +78,9 @@ public class MilogConfigController {
}
@RequestMapping(path = "/milog/space/getall", method = "get")
- public Result<List<MapDTO<String, Long>>>
getMilogSpaces(@RequestParam("tenantId") Long tenantId) {
- return logSpaceService.getMilogSpaces(tenantId);
+ public Result<List<MapDTO<String, Long>>>
getMilogSpaces(@RequestParam("tenantId") Long tenantId,
+
@RequestParam("spaceName") String spaceName) {
+ return logSpaceService.getMilogSpaces(tenantId, spaceName);
}
@RequestMapping(path = "/milog/space/getbypage", method = "get")
diff --git
a/ozhera-log/log-manager/src/main/java/org/apache/ozhera/log/manager/service/LogSpaceService.java
b/ozhera-log/log-manager/src/main/java/org/apache/ozhera/log/manager/service/LogSpaceService.java
index 02fd8fc1..c1b5d3c4 100644
---
a/ozhera-log/log-manager/src/main/java/org/apache/ozhera/log/manager/service/LogSpaceService.java
+++
b/ozhera-log/log-manager/src/main/java/org/apache/ozhera/log/manager/service/LogSpaceService.java
@@ -56,7 +56,7 @@ public interface LogSpaceService {
Result<PageInfo<MilogSpaceDTO>> getMilogSpaceByPage(String spaceName, Long
tenantId, Integer page, Integer pagesize);
- Result<List<MapDTO<String, Long>>> getMilogSpaces(Long tenantId);
+ Result<List<MapDTO<String, Long>>> getMilogSpaces(Long tenantId, String
spaceName);
/**
* update
diff --git
a/ozhera-log/log-manager/src/main/java/org/apache/ozhera/log/manager/service/impl/LogSpaceServiceImpl.java
b/ozhera-log/log-manager/src/main/java/org/apache/ozhera/log/manager/service/impl/LogSpaceServiceImpl.java
index abaf72aa..264448d8 100644
---
a/ozhera-log/log-manager/src/main/java/org/apache/ozhera/log/manager/service/impl/LogSpaceServiceImpl.java
+++
b/ozhera-log/log-manager/src/main/java/org/apache/ozhera/log/manager/service/impl/LogSpaceServiceImpl.java
@@ -120,7 +120,7 @@ public class LogSpaceServiceImpl extends BaseService
implements LogSpaceService
com.xiaomi.youpin.infra.rpc.Result tpcResult =
spaceAuthService.saveSpacePerm(dbDO, creator);
addMemberAsync(dbDO.getId(), otherAdmins);
- SPACE_ALL_CACHE.invalidate(buildCacheKey(param.getTenantId()));
+ SPACE_ALL_CACHE.invalidate(buildCacheKey(param.getTenantId(), ""));
if (tpcResult == null || tpcResult.getCode() != 0) {
milogSpaceDao.deleteMilogSpace(dbDO.getId());
@@ -191,18 +191,16 @@ public class LogSpaceServiceImpl extends BaseService
implements LogSpaceService
}
@Override
- public Result<List<MapDTO<String, Long>>> getMilogSpaces(Long tenantId) {
+ public Result<List<MapDTO<String, Long>>> getMilogSpaces(Long tenantId,
String spaceName) {
int pageNum = 1;
int defaultPageSize = 300;
- String defaultSpaceKey = buildCacheKey(tenantId);
+ String defaultSpaceKey = buildCacheKey(tenantId, spaceName);
List<MapDTO<String, Long>> cachedResult =
SPACE_ALL_CACHE.getIfPresent(defaultSpaceKey);
-
// return cached result if available
if (CollectionUtils.isNotEmpty(cachedResult)) {
return Result.success(cachedResult);
}
-
- List<NodeVo> nodeVos = fetchAllNodeVos(pageNum, defaultPageSize);
+ List<NodeVo> nodeVos = fetchAllNodeVos(pageNum, defaultPageSize,
spaceName);
// transform nodeVos to MapDTO list
List<MapDTO<String, Long>> result = nodeVos.parallelStream()
@@ -211,19 +209,26 @@ public class LogSpaceServiceImpl extends BaseService
implements LogSpaceService
// cache the result
SPACE_ALL_CACHE.put(defaultSpaceKey, result);
+
return Result.success(result);
+
+
}
- private static String buildCacheKey(Long tenantId) {
+ private static String buildCacheKey(Long tenantId, String spaceName) {
MoneUser currentUser = MoneUserContext.getCurrentUser();
- return String.format("%s-%s", (tenantId == null) ? "local-key" :
tenantId.toString(), currentUser.getUser());
+ String cacheKey = String.format("%s-%s", (tenantId == null) ?
"local-key" : tenantId.toString(), currentUser.getUser());
+ if (spaceName !=null && !spaceName.isEmpty()){
+ cacheKey = cacheKey + "-" + spaceName;
+ }
+ return cacheKey;
}
- private List<NodeVo> fetchAllNodeVos(int pageNum, int pageSize) {
+ private List<NodeVo> fetchAllNodeVos(int pageNum, int pageSize, String
spaceName) {
List<NodeVo> nodeVos = new ArrayList<>();
while (true) {
- com.xiaomi.youpin.infra.rpc.Result<PageDataVo<NodeVo>> response =
spaceAuthService.getUserPermSpace("", pageNum, pageSize);
+ com.xiaomi.youpin.infra.rpc.Result<PageDataVo<NodeVo>> response =
spaceAuthService.getUserPermSpace(spaceName, pageNum, pageSize);
if (response.getCode() != 0) {
throw new MilogManageException("query space from tpc error");
@@ -281,7 +286,7 @@ public class LogSpaceServiceImpl extends BaseService
implements LogSpaceService
if (milogSpaceDao.update(milogSpace)) {
com.xiaomi.youpin.infra.rpc.Result tpcResult =
spaceAuthService.updateSpaceTpc(param,
MoneUserContext.getCurrentUser().getUser());
- SPACE_ALL_CACHE.invalidate(buildCacheKey(param.getTenantId()));
+ SPACE_ALL_CACHE.invalidate(buildCacheKey(param.getTenantId(), ""));
if (tpcResult == null || tpcResult.getCode() != 0) {
log.error("Modify the space permission system not associated
with it,space:[{}], tpcResult:[{}]", milogSpace, tpcResult);
return Result.success("To modify the unassociated permission
system of space, contact the server-side performance group");
@@ -313,7 +318,7 @@ public class LogSpaceServiceImpl extends BaseService
implements LogSpaceService
if (milogSpaceDao.deleteMilogSpace(id)) {
logTailService.deleteConfigRemote(id, id,
MachineRegionEnum.CN_MACHINE.getEn(), LogStructureEnum.SPACE);
-
SPACE_ALL_CACHE.invalidate(buildCacheKey(milogSpace.getTenantId()));
+
SPACE_ALL_CACHE.invalidate(buildCacheKey(milogSpace.getTenantId(),""));
com.xiaomi.youpin.infra.rpc.Result tpcResult =
spaceAuthService.deleteSpaceTpc(id, MoneUserContext.getCurrentUser().getUser(),
MoneUserContext.getCurrentUser().getUserType());
if (tpcResult == null || tpcResult.getCode() != 0) {
log.error("Remove the space without associated permission
system,space:[{}], tpcResult:[{}]", milogSpace, tpcResult);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]