Merge branch 'feature/docker-api-20220816' into 'master'
修复项目发布docker无法获取镜像 修复项目发布docker无法获取镜像 See merge request !2
Showing
3 changed files
with
105 additions
and
4 deletions
@@ -15,6 +15,12 @@ | @@ -15,6 +15,12 @@ | ||
15 | <dependencies> | 15 | <dependencies> |
16 | 16 | ||
17 | <dependency> | 17 | <dependency> |
18 | + <groupId>com.tencentcloudapi</groupId> | ||
19 | + <artifactId>tencentcloud-sdk-java-tcr</artifactId> | ||
20 | + <version>3.1.572</version> | ||
21 | + </dependency> | ||
22 | + | ||
23 | + <dependency> | ||
18 | <groupId>com.offbytwo.jenkins</groupId> | 24 | <groupId>com.offbytwo.jenkins</groupId> |
19 | <artifactId>jenkins-client</artifactId> | 25 | <artifactId>jenkins-client</artifactId> |
20 | <version>0.3.7</version> | 26 | <version>0.3.7</version> |
@@ -3,6 +3,7 @@ package com.monitor.other.worksystem.dock.qq; | @@ -3,6 +3,7 @@ package com.monitor.other.worksystem.dock.qq; | ||
3 | import com.alibaba.fastjson.JSON; | 3 | import com.alibaba.fastjson.JSON; |
4 | import com.alibaba.fastjson.JSONArray; | 4 | import com.alibaba.fastjson.JSONArray; |
5 | import com.alibaba.fastjson.JSONObject; | 5 | import com.alibaba.fastjson.JSONObject; |
6 | +import com.google.common.collect.Lists; | ||
6 | import org.apache.commons.lang.StringUtils; | 7 | import org.apache.commons.lang.StringUtils; |
7 | import org.apache.commons.lang.math.NumberUtils; | 8 | import org.apache.commons.lang.math.NumberUtils; |
8 | import org.slf4j.Logger; | 9 | import org.slf4j.Logger; |
@@ -107,12 +108,17 @@ public class DockerServerDeployService { | @@ -107,12 +108,17 @@ public class DockerServerDeployService { | ||
107 | 108 | ||
108 | public List<String> queryImageList(String reponame,int offset,boolean includeLatest) { | 109 | public List<String> queryImageList(String reponame,int offset,boolean includeLatest) { |
109 | List<String> stores=new ArrayList<>(); | 110 | List<String> stores=new ArrayList<>(); |
110 | - JSONObject searchResult = txServer.describeImageList(reponame,offset ); | ||
111 | - if(searchResult!=null&&searchResult.getInteger("code")!=null&& searchResult.getInteger("code").equals(NumberUtils.INTEGER_ZERO)){ | ||
112 | - JSONArray ja=searchResult.getJSONObject("data").getJSONArray("tagInfo"); | 111 | +// JSONObject searchResult = txServer.describeImageList(reponame,offset ); |
112 | + JSONObject searchResult = TrcClientUtil.getImageTagList(reponame, offset); | ||
113 | + if (searchResult == null) { | ||
114 | + logger.warn("queryImageList searchResult is null param reponame:{} offset:{}", reponame, offset); | ||
115 | + return Lists.newArrayListWithCapacity(0); | ||
116 | + } | ||
117 | + if(searchResult.getJSONObject("Data") != null){ | ||
118 | + JSONArray ja=searchResult.getJSONObject("Data").getJSONArray("TagInfo"); | ||
113 | if(ja!=null&&ja.size()>0){ | 119 | if(ja!=null&&ja.size()>0){ |
114 | for(int i=0;i<ja.size();i++){ | 120 | for(int i=0;i<ja.size();i++){ |
115 | - String tagName=ja.getJSONObject(i).getString("tagName"); | 121 | + String tagName=ja.getJSONObject(i).getString("TagName"); |
116 | if(!"latest".equals(tagName)){ | 122 | if(!"latest".equals(tagName)){ |
117 | stores.add(tagName); | 123 | stores.add(tagName); |
118 | }else{ | 124 | }else{ |
monitor-service-other/src/main/java/com/monitor/other/worksystem/dock/qq/TrcClientUtil.java
0 → 100644
1 | +package com.monitor.other.worksystem.dock.qq; | ||
2 | + | ||
3 | +import com.alibaba.fastjson.JSONObject; | ||
4 | +import com.tencentcloudapi.common.Credential; | ||
5 | +import com.tencentcloudapi.common.exception.TencentCloudSDKException; | ||
6 | +import com.tencentcloudapi.common.profile.ClientProfile; | ||
7 | +import com.tencentcloudapi.common.profile.HttpProfile; | ||
8 | +import com.tencentcloudapi.tcr.v20190924.TcrClient; | ||
9 | +import com.tencentcloudapi.tcr.v20190924.models.DescribeImagePersonalRequest; | ||
10 | +import com.tencentcloudapi.tcr.v20190924.models.DescribeImagePersonalResponse; | ||
11 | +import org.apache.commons.lang3.StringUtils; | ||
12 | +import org.slf4j.Logger; | ||
13 | +import org.slf4j.LoggerFactory; | ||
14 | + | ||
15 | +/** | ||
16 | + * @author xutao.liu@yoho.cn 2022/8/17 17:19 | ||
17 | + */ | ||
18 | +public class TrcClientUtil { | ||
19 | + private static final Logger logger = LoggerFactory.getLogger(TrcClientUtil.class); | ||
20 | + | ||
21 | + private static final String SECRET_ID = "AKIDIMBl59hWpsgFYel7YljRu89wUmpchUYO"; | ||
22 | + private static final String SECRET_KEY = "kGXYKq8evxkI0VmpfGcjbEckdHgqlRr3"; | ||
23 | + private static final String REGION = "ap-guangzhou"; | ||
24 | + private static final String ENDPOINT = "tcr.tencentcloudapi.com"; | ||
25 | + | ||
26 | + private static TcrClient tcrClient = null; | ||
27 | + | ||
28 | + private TrcClientUtil() { | ||
29 | + } | ||
30 | + | ||
31 | + /** | ||
32 | + * 获取个人版镜像仓库tag列表 | ||
33 | + * | ||
34 | + * @author xutao.liu@yoho.cn | ||
35 | + * 2022/8/17 18:26 | ||
36 | + */ | ||
37 | + static JSONObject getImageTagList(String repoName, long offset) { | ||
38 | + if (StringUtils.isBlank(repoName)) { | ||
39 | + logger.warn("getImageTagList param repoName is blank"); | ||
40 | + return null; | ||
41 | + } | ||
42 | + // 实例化一个请求对象,每个接口都会对应一个request对象 | ||
43 | + DescribeImagePersonalRequest req = new DescribeImagePersonalRequest(); | ||
44 | + req.setRepoName(repoName); | ||
45 | + req.setOffset(offset); | ||
46 | + // 返回的resp是一个DescribeImagePersonalResponse的实例,与请求对象对应 | ||
47 | + DescribeImagePersonalResponse resp; | ||
48 | + try { | ||
49 | + resp = getTcrClient().DescribeImagePersonal(req); | ||
50 | + } catch (TencentCloudSDKException e) { | ||
51 | + logger.error("getImageTagList cause exception repoName:{}", repoName, e); | ||
52 | + return null; | ||
53 | + } | ||
54 | + // 输出json格式的字符串回包 | ||
55 | + String resultStr = DescribeImagePersonalResponse.toJsonString(resp); | ||
56 | + logger.info("DescribeImagePersonalResponse result:{}", resultStr); | ||
57 | + | ||
58 | + return JSONObject.parseObject(resultStr); | ||
59 | + } | ||
60 | + | ||
61 | + private static TcrClient getTcrClient() { | ||
62 | + if (tcrClient == null) { | ||
63 | + synchronized (TrcClientUtil.class) { | ||
64 | + if (tcrClient == null) { | ||
65 | + // 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密 | ||
66 | + // 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取 | ||
67 | + Credential cred = new Credential(SECRET_ID, SECRET_KEY); | ||
68 | + // 实例化一个http选项,可选的,没有特殊需求可以跳过 | ||
69 | + HttpProfile httpProfile = new HttpProfile(); | ||
70 | + httpProfile.setConnTimeout(2); // 请求连接超时时间,单位为秒(默认60秒) | ||
71 | + httpProfile.setReadTimeout(1); // 设置读取超时时间,单位为秒(默认0秒) | ||
72 | + | ||
73 | + httpProfile.setEndpoint(ENDPOINT); | ||
74 | + // 实例化一个client选项,可选的,没有特殊需求可以跳过 | ||
75 | + ClientProfile clientProfile = new ClientProfile(); | ||
76 | + clientProfile.setHttpProfile(httpProfile); | ||
77 | + | ||
78 | + tcrClient = new TcrClient(cred, REGION, clientProfile); | ||
79 | + } | ||
80 | + } | ||
81 | + } | ||
82 | + return tcrClient; | ||
83 | + } | ||
84 | + | ||
85 | + public static void main(String[] args) { | ||
86 | + JSONObject resultStr = getImageTagList("yoho-online/yohobuywap-node-activity", 0); | ||
87 | + System.out.println(resultStr); | ||
88 | + } | ||
89 | +} |
-
Please register or login to post a comment