Commit 36ada25d authored by 黎博's avatar 黎博

修改getSingleTypeApp接口

parent 2b73746c
...@@ -5,10 +5,13 @@ import cn.qg.holmes.entity.k8s.DockerProject; ...@@ -5,10 +5,13 @@ import cn.qg.holmes.entity.k8s.DockerProject;
import cn.qg.holmes.entity.k8s.ServiceCreateVo; import cn.qg.holmes.entity.k8s.ServiceCreateVo;
import cn.qg.holmes.service.k8s.*; import cn.qg.holmes.service.k8s.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tencentcloudapi.tcr.v20190924.models.RepoInfo;
import io.fabric8.kubernetes.api.model.apps.Deployment; import io.fabric8.kubernetes.api.model.apps.Deployment;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -265,8 +268,25 @@ public class K8sController { ...@@ -265,8 +268,25 @@ public class K8sController {
* @return * @return
*/ */
@GetMapping("/getSingleTypeApp") @GetMapping("/getSingleTypeApp")
public JsonResult getSingleTypeApp(@RequestParam String namespace) { public JsonResult getSingleTypeApp(@RequestParam String namespace, @RequestParam String type) {
return JsonResult.buildSuccessResult(imageService.getSingleTypeApp(namespace)); Map<String, Object> repoMap = imageService.getSingleTypeApp(namespace);
Map<String, Object> resultMap = new HashMap<>();
List<RepoInfo> repoInfoList = (List<RepoInfo>) repoMap.get("RepoInfo");
List<RepoInfo> newRepoInfoList = new ArrayList<>();
QueryWrapper<DockerProject> queryWrapper = new QueryWrapper<>();
for (RepoInfo repoInfo: repoInfoList) {
queryWrapper
.eq("project_name", repoInfo.getRepoName().split("/")[1])
.eq("project_type", type)
.eq("is_active", 1);
if (dockerProjectService.getOne(queryWrapper) != null) {
newRepoInfoList.add(repoInfo);
}
queryWrapper.clear();
}
resultMap.put("RepoInfo", newRepoInfoList);
resultMap.put("TotalCount", repoMap.get("TotalCount"));
return JsonResult.buildSuccessResult(resultMap);
} }
/** /**
......
...@@ -6,9 +6,10 @@ import com.tencentcloudapi.common.profile.ClientProfile; ...@@ -6,9 +6,10 @@ import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.tcr.v20190924.TcrClient; import com.tencentcloudapi.tcr.v20190924.TcrClient;
import com.tencentcloudapi.tcr.v20190924.models.*; import com.tencentcloudapi.tcr.v20190924.models.*;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.ArrayUtils;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Map; import java.util.*;
/** /**
* 镜像仓库相关服务 * 镜像仓库相关服务
...@@ -60,8 +61,26 @@ public class ImageService { ...@@ -60,8 +61,26 @@ public class ImageService {
try { try {
DescribeRepositoryFilterPersonalRequest request = new DescribeRepositoryFilterPersonalRequest(); DescribeRepositoryFilterPersonalRequest request = new DescribeRepositoryFilterPersonalRequest();
request.setNamespace(namespace); request.setNamespace(namespace);
request.setPublic(-1L);
request.setOffset(0L);
request.setLimit(100L);
request.setRepoName("");
DescribeRepositoryFilterPersonalResponse response = tcrClient.DescribeRepositoryFilterPersonal(request); DescribeRepositoryFilterPersonalResponse response = tcrClient.DescribeRepositoryFilterPersonal(request);
return JSON.parseObject(DescribeRepositoryFilterPersonalResponse.toJsonString(response.getData()), Map.class); Map<String, Object> resultMap = new HashMap<>();
Long TotalCount = response.getData().getTotalCount();
resultMap.put("TotalCount", TotalCount);
List<RepoInfo> repoInfoList = new ArrayList<>(Arrays.asList(response.getData().getRepoInfo()));
int num = Math.toIntExact(TotalCount / 100);
if ((TotalCount % 100) > 0) {
num = num + 1;
}
for (int i=1; i < num; i++) {
request.setOffset(100L * i);
response = tcrClient.DescribeRepositoryFilterPersonal(request);
repoInfoList.addAll(Arrays.asList(response.getData().getRepoInfo()));
}
resultMap.put("RepoInfo", repoInfoList);
return resultMap;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return null; return null;
...@@ -70,9 +89,7 @@ public class ImageService { ...@@ -70,9 +89,7 @@ public class ImageService {
public static void main(String[] args) { public static void main(String[] args) {
ImageService imageService = new ImageService(); ImageService imageService = new ImageService();
// System.out.println(imageService.getImageListByService("kdsp")); System.out.println(JSON.toJSONString(imageService.getSingleTypeApp("qa-test")));
System.out.println(JSON.toJSONString(imageService.getSingleTypeApp("qa-base")));
System.out.println(JSON.toJSONString(imageService.getSingleTypeApp("qa-java")));
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment