Skip to content

Commit

Permalink
feat: openapi query namespace support not fill item
Browse files Browse the repository at this point in the history
  • Loading branch information
youngzil committed Oct 7, 2024
1 parent 94c28af commit 71f9fa0
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,20 @@ public ServerNamespaceOpenApiService(

@Override
public OpenNamespaceDTO getNamespace(String appId, String env, String clusterName,
String namespaceName) {
String namespaceName, boolean fillItemDetail) {
NamespaceBO namespaceBO = namespaceService.loadNamespaceBO(appId, Env.valueOf
(env), clusterName, namespaceName, false);
(env), clusterName, namespaceName, fillItemDetail, false);
if (namespaceBO == null) {
return null;
}
return OpenApiBeanUtils.transformFromNamespaceBO(namespaceBO);
}

@Override
public List<OpenNamespaceDTO> getNamespaces(String appId, String env, String clusterName) {
public List<OpenNamespaceDTO> getNamespaces(String appId, String env, String clusterName, boolean fillItemDetail) {
return OpenApiBeanUtils
.batchTransformFromNamespaceBOs(namespaceService.findNamespaceBOs(appId, Env
.valueOf(env), clusterName, false));
.valueOf(env), clusterName, fillItemDetail, false));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -81,15 +82,16 @@ public OpenAppNamespaceDTO createNamespace(@PathVariable String appId,

@GetMapping(value = "/openapi/v1/envs/{env}/apps/{appId}/clusters/{clusterName}/namespaces")
public List<OpenNamespaceDTO> findNamespaces(@PathVariable String appId, @PathVariable String env,
@PathVariable String clusterName) {
return this.namespaceOpenApiService.getNamespaces(appId, env, clusterName);
@PathVariable String clusterName,
@RequestParam(defaultValue="true") boolean fillItemDetail) {
return this.namespaceOpenApiService.getNamespaces(appId, env, clusterName, fillItemDetail);
}

@GetMapping(value = "/openapi/v1/envs/{env}/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName:.+}")
public OpenNamespaceDTO loadNamespace(@PathVariable String appId, @PathVariable String env,
@PathVariable String clusterName, @PathVariable String
namespaceName) {
return this.namespaceOpenApiService.getNamespace(appId, env, clusterName, namespaceName);
@PathVariable String clusterName, @PathVariable String namespaceName,
@RequestParam(defaultValue="true") boolean fillItemDetail) {
return this.namespaceOpenApiService.getNamespace(appId, env, clusterName, namespaceName, fillItemDetail);
}

@GetMapping(value = "/openapi/v1/envs/{env}/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/lock")
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, false);
(env), clusterName, namespaceName, true, 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, false);
List<NamespaceBO> namespaceBOS = namespaceService.findNamespaceBOs(exportApp.getAppId(), env, clusterName, true, 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, boolean includeDeletedItems) {
public List<NamespaceBO> findNamespaceBOs(String appId, Env env, String clusterName, boolean fillItemDetail, 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, includeDeletedItems);
namespaceBO = transformNamespace2BO(env, namespace, fillItemDetail, includeDeletedItems);
namespaceBOs.add(namespaceBO);
} catch (Exception e) {
LOGGER.error("parse namespace error. app id:{}, env:{}, clusterName:{}, namespace:{}",
Expand Down Expand Up @@ -229,7 +229,7 @@ public List<NamespaceBO> findNamespaceBOs(String appId, Env env, String clusterN
}

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

public List<NamespaceDTO> findNamespaces(String appId, Env env, String clusterName) {
Expand All @@ -250,17 +250,17 @@ public List<NamespaceDTO> getPublicAppNamespaceAllNamespaces(Env env, String pub
}

public NamespaceBO loadNamespaceBO(String appId, Env env, String clusterName,
String namespaceName, boolean includeDeletedItems) {
String namespaceName, boolean fillItemDetail, boolean includeDeletedItems) {
NamespaceDTO namespace = namespaceAPI.loadNamespace(appId, env, clusterName, namespaceName);
if (namespace == null) {
throw BadRequestException.namespaceNotExists(appId, clusterName, namespaceName);
}
return transformNamespace2BO(env, namespace, includeDeletedItems);
return transformNamespace2BO(env, namespace, fillItemDetail, includeDeletedItems);
}

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

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

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

Expand All @@ -306,6 +306,10 @@ private NamespaceBO transformNamespace2BO(Env env, NamespaceDTO namespace, boole
List<ItemBO> itemBOs = new LinkedList<>();
namespaceBO.setItems(itemBOs);

if (!fillItemDetail) {
return namespaceBO;
}

//latest Release
ReleaseDTO latestRelease;
Map<String, String> releaseItems = new HashMap<>();
Expand Down Expand Up @@ -347,7 +351,7 @@ private NamespaceBO transformNamespace2BO(Env env, NamespaceDTO namespace, boole
}

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

private void fillAppNamespaceProperties(NamespaceBO namespace) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ public void testNamespaceExportImport() throws FileNotFoundException {
when(permissionValidator.isAppAdmin(any())).thenReturn(true);
when(clusterService.findClusters(env, appId1)).thenReturn(app1Clusters);
when(clusterService.findClusters(env, appId2)).thenReturn(app2Clusters);
when(namespaceService.findNamespaceBOs(appId1, Env.DEV, clusterName1, false)).thenReturn(app1Cluster1Namespace);
when(namespaceService.findNamespaceBOs(appId1, Env.DEV, clusterName2, false)).thenReturn(app1Cluster2Namespace);
when(namespaceService.findNamespaceBOs(appId2, Env.DEV, clusterName1, false)).thenReturn(app2Cluster1Namespace);
when(namespaceService.findNamespaceBOs(appId2, Env.DEV, clusterName2, false)).thenReturn(app2Cluster2Namespace);
when(namespaceService.findNamespaceBOs(appId1, Env.DEV, clusterName1, true, false)).thenReturn(app1Cluster1Namespace);
when(namespaceService.findNamespaceBOs(appId1, Env.DEV, clusterName2, true, false)).thenReturn(app1Cluster2Namespace);
when(namespaceService.findNamespaceBOs(appId2, Env.DEV, clusterName1, true, false)).thenReturn(app2Cluster1Namespace);
when(namespaceService.findNamespaceBOs(appId2, Env.DEV, clusterName2, true, false)).thenReturn(app2Cluster2Namespace);

FileOutputStream fileOutputStream = new FileOutputStream(filePath);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public void testLoadNamespaceBO() {
assertThat(namespaceBO1.getItems().size()).isEqualTo(3);
assertThat(namespaceKey1).isEqualTo(Arrays.asList("k1", "k2", "k3"));

NamespaceBO namespaceBO2 = namespaceService.loadNamespaceBO(testAppId, testEnv, testClusterName, testNamespaceName, false);
NamespaceBO namespaceBO2 = namespaceService.loadNamespaceBO(testAppId, testEnv, testClusterName, testNamespaceName, true, false);
List<String> namespaceKey2 = namespaceBO2.getItems().stream().map(s -> s.getItem().getKey()).collect(Collectors.toList());
assertThat(namespaceBO2.getItemModifiedCnt()).isEqualTo(2);
assertThat(namespaceBO2.getItems().size()).isEqualTo(2);
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<revision>2.4.0-SNAPSHOT</revision>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<apollo-java.version>2.2.0</apollo-java.version>
<apollo-java.version>2.4.0-SNAPSHOT</apollo-java.version>
<spring-boot.version>2.7.11</spring-boot.version>
<spring-cloud.version>2021.0.5</spring-cloud.version>
<!-- sort by alphabet -->
Expand Down Expand Up @@ -649,4 +649,4 @@
</snapshots>
</repository>
</repositories>
</project>
</project>

0 comments on commit 71f9fa0

Please sign in to comment.