Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix get the openapi interface that contains namespace information for deleted items #4596

Merged
merged 6 commits into from
Oct 9, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Apollo 2.1.0
* [fix create namespace with single dot 500 error](https://github.com/apolloconfig/apollo/pull/4568)
* [Add nodejs client sdk and fix doc](https://github.com/apolloconfig/apollo/pull/4590)
* [Move apollo-core, apollo-client, apollo-mockserver, apollo-openapi and apollo-client-config-data to apollo-java repo](https://github.com/apolloconfig/apollo/pull/4594)
* [fix get the openapi interface that contains namespace information for deleted items](https://github.com/apolloconfig/apollo/pull/4596)

------------------
All issues and pull requests are [here](https://github.com/apolloconfig/apollo/milestone/11?closed=1)
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public ServerNamespaceOpenApiService(
public OpenNamespaceDTO getNamespace(String appId, String env, String clusterName,
String namespaceName) {
NamespaceBO namespaceBO = namespaceService.loadNamespaceBO(appId, Env.valueOf
(env), clusterName, namespaceName);
(env), clusterName, namespaceName, false);
if (namespaceBO == null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void exportItems(@PathVariable String appId, @PathVariable String env,
}

NamespaceBO namespaceBO = namespaceService.loadNamespaceBO(appId, Env.valueOf
(env), clusterName, namespaceName);
(env), clusterName, namespaceName, false);

//generate a file.
res.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + fileName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ private void exportNamespaces(final Env env, final App exportApp, final ClusterD
ZipOutputStream zipOutputStream) {
String clusterName = exportCluster.getName();

List<NamespaceBO> namespaceBOS = namespaceService.findNamespaceBOs(exportApp.getAppId(), env, clusterName);
List<NamespaceBO> namespaceBOS = namespaceService.findNamespaceBOs(exportApp.getAppId(), env, clusterName, false);

if (CollectionUtils.isEmpty(namespaceBOS)) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public NamespaceDTO loadNamespaceBaseInfo(String appId, Env env, String clusterN
/**
* load cluster all namespace info with items
*/
public List<NamespaceBO> findNamespaceBOs(String appId, Env env, String clusterName) {
public List<NamespaceBO> findNamespaceBOs(String appId, Env env, String clusterName, boolean includeDeletedItems) {

List<NamespaceDTO> namespaces = namespaceAPI.findNamespaceByCluster(appId, env, clusterName);
if (namespaces == null || namespaces.size() == 0) {
Expand All @@ -200,7 +200,7 @@ public List<NamespaceBO> findNamespaceBOs(String appId, Env env, String clusterN
executorService.submit(() -> {
NamespaceBO namespaceBO;
try {
namespaceBO = transformNamespace2BO(env, namespace);
namespaceBO = transformNamespace2BO(env, namespace, includeDeletedItems);
namespaceBOs.add(namespaceBO);
} catch (Exception e) {
LOGGER.error("parse namespace error. app id:{}, env:{}, clusterName:{}, namespace:{}",
Expand Down Expand Up @@ -228,6 +228,10 @@ public List<NamespaceBO> findNamespaceBOs(String appId, Env env, String clusterN
.collect(Collectors.toList());
}

public List<NamespaceBO> findNamespaceBOs(String appId, Env env, String clusterName) {
return findNamespaceBOs(appId, env, clusterName, true);
}

public List<NamespaceDTO> findNamespaces(String appId, Env env, String clusterName) {
return namespaceAPI.findNamespaceByCluster(appId, env, clusterName);
}
Expand All @@ -246,12 +250,17 @@ public List<NamespaceDTO> getPublicAppNamespaceAllNamespaces(Env env, String pub
}

public NamespaceBO loadNamespaceBO(String appId, Env env, String clusterName,
String namespaceName) {
String namespaceName, boolean includeDeletedItems) {
CalebZYC marked this conversation as resolved.
Show resolved Hide resolved
NamespaceDTO namespace = namespaceAPI.loadNamespace(appId, env, clusterName, namespaceName);
if (namespace == null) {
throw new BadRequestException("namespaces not exist");
}
return transformNamespace2BO(env, namespace);
return transformNamespace2BO(env, namespace, includeDeletedItems);
}

public NamespaceBO loadNamespaceBO(String appId, Env env, String clusterName,
String namespaceName) {
return loadNamespaceBO(appId, env, clusterName, namespaceName, true);
}

public boolean publicAppNamespaceHasAssociatedNamespace(String publicNamespaceName, Env env) {
Expand Down Expand Up @@ -284,7 +293,7 @@ public Map<String, Map<String, Boolean>> getNamespacesPublishInfo(String appId)
return result;
}

private NamespaceBO transformNamespace2BO(Env env, NamespaceDTO namespace) {
private NamespaceBO transformNamespace2BO(Env env, NamespaceDTO namespace, boolean includeDeletedItems) {
NamespaceBO namespaceBO = new NamespaceBO();
namespaceBO.setBaseInfo(namespace);

Expand Down Expand Up @@ -322,20 +331,26 @@ private NamespaceBO transformNamespace2BO(Env env, NamespaceDTO namespace) {
itemBOs.add(itemBO);
}

//deleted items
itemService.findDeletedItems(appId, env, clusterName, namespaceName).forEach(item -> {
deletedItemDTOs.put(item.getKey(),item);
});
if (includeDeletedItems) {
//deleted items
itemService.findDeletedItems(appId, env, clusterName, namespaceName).forEach(item -> {
deletedItemDTOs.put(item.getKey(), item);
});

List<ItemBO> deletedItems = parseDeletedItems(items, releaseItems, deletedItemDTOs);
itemBOs.addAll(deletedItems);
modifiedItemCnt += deletedItems.size();
List<ItemBO> deletedItems = parseDeletedItems(items, releaseItems, deletedItemDTOs);
itemBOs.addAll(deletedItems);
modifiedItemCnt += deletedItems.size();
}

namespaceBO.setItemModifiedCnt(modifiedItemCnt);

return namespaceBO;
}

private NamespaceBO transformNamespace2BO(Env env, NamespaceDTO namespace) {
return transformNamespace2BO(env, namespace, true);
}

private void fillAppNamespaceProperties(NamespaceBO namespace) {

final NamespaceDTO namespaceDTO = namespace.getBaseInfo();
Expand Down