Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
holmes
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
QA
holmes
Commits
7c4e4c6f
Commit
7c4e4c6f
authored
Sep 13, 2021
by
黎博
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
ae3c79e7
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
5 deletions
+70
-5
K8sController.java
src/main/java/cn/qg/holmes/controller/k8s/K8sController.java
+65
-2
ImageService.java
src/main/java/cn/qg/holmes/service/k8s/ImageService.java
+5
-3
No files found.
src/main/java/cn/qg/holmes/controller/k8s/K8sController.java
View file @
7c4e4c6f
...
@@ -9,12 +9,17 @@ import cn.qg.holmes.service.k8s.*;
...
@@ -9,12 +9,17 @@ import cn.qg.holmes.service.k8s.*;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.tencentcloudapi.tcr.v20190924.models.RepoInfo
;
import
com.tencentcloudapi.tcr.v20190924.models.RepoInfo
;
import
com.tencentcloudapi.tcr.v20190924.models.TagInfo
;
import
com.tencentcloudapi.tcr.v20190924.models.TagInfoResp
;
import
io.fabric8.kubernetes.api.model.apps.Deployment
;
import
io.fabric8.kubernetes.api.model.apps.Deployment
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
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.*
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
/**
* k8及容器操作相关接口
* k8及容器操作相关接口
...
@@ -78,7 +83,7 @@ public class K8sController {
...
@@ -78,7 +83,7 @@ public class K8sController {
*/
*/
@GetMapping
(
"/image/list"
)
@GetMapping
(
"/image/list"
)
public
JsonResult
getImageListByServiceName
(
@RequestParam
String
repoName
)
{
public
JsonResult
getImageListByServiceName
(
@RequestParam
String
repoName
)
{
return
JsonResult
.
buildSuccessResult
(
imageService
.
getImageListByService
(
repoName
));
return
JsonResult
.
buildSuccessResult
(
JSON
.
toJSONString
(
imageService
.
getImageListByService
(
repoName
)
));
}
}
/**
/**
...
@@ -460,4 +465,62 @@ public class K8sController {
...
@@ -460,4 +465,62 @@ public class K8sController {
resultList
.
sort
(
String:
:
compareTo
);
resultList
.
sort
(
String:
:
compareTo
);
return
String
.
join
(
"\n"
,
resultList
);
return
String
.
join
(
"\n"
,
resultList
);
}
}
/**
* 按照类型获取所有的服务
* @return
*/
@GetMapping
(
"/repo/getAll"
)
public
JsonResult
getAllRepos
()
{
List
<
Map
<
String
,
Object
>>
resultMapList
=
new
ArrayList
<>();
。
List
<
RepoInfo
>
repoInfoList
=
imageService
.
getRepoInfoList
(
"qa-base"
);
Map
<
String
,
Object
>
base
=
new
HashMap
<>();
List
<
Map
<
String
,
String
>>
baseList
=
new
ArrayList
<>();
for
(
RepoInfo
repoInfo:
repoInfoList
)
{
String
serviceName
=
repoInfo
.
getRepoName
().
split
(
"/"
)[
1
];
TagInfo
[]
tagInfos
=
imageService
.
getImageListByService
(
repoInfo
.
getRepoName
()).
getTagInfo
();
for
(
TagInfo
tagInfo:
tagInfos
)
{
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"appname"
,
serviceName
+
":"
+
tagInfo
.
getTagName
());
map
.
put
(
"type"
,
serviceName
);
map
.
put
(
"label"
,
"base"
);
map
.
put
(
"tag"
,
"qa-base/"
+
serviceName
+
":"
+
tagInfo
.
getTagName
());
map
.
put
(
"domain"
,
serviceName
+
tagInfo
.
getTagName
());
baseList
.
add
(
map
);
}
}
base
.
put
(
"type"
,
"base"
);
base
.
put
(
"repos"
,
baseList
);
resultMapList
.
add
(
base
);
QueryWrapper
<
DockerProject
>
queryWrapper
=
new
QueryWrapper
<>();
queryWrapper
.
groupBy
(
"project_type"
).
select
(
"project_type"
);
List
<
DockerProject
>
projectList
=
dockerProjectService
.
list
(
queryWrapper
);
queryWrapper
.
clear
();
for
(
DockerProject
dp:
projectList
)
{
String
type
=
dp
.
getProjectType
();
Map
<
String
,
Object
>
serviceMap
=
new
HashMap
<>();
List
<
Map
<
String
,
String
>>
serviceMapList
=
new
ArrayList
<>();
queryWrapper
.
eq
(
"project_type"
,
type
)
.
eq
(
"is_active"
,
1
);
List
<
DockerProject
>
dockerProjectList
=
dockerProjectService
.
list
(
queryWrapper
);
for
(
DockerProject
dockerProject:
dockerProjectList
)
{
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"type"
,
type
);
map
.
put
(
"label"
,
type
);
map
.
put
(
"appname"
,
dockerProject
.
getProjectName
());
map
.
put
(
"domain"
,
dockerProject
.
getHostName
().
split
(
"\\."
)[
0
]);
map
.
put
(
"tag"
,
"qa-test/"
+
dockerProject
.
getProjectName
()
+
":latest"
);
serviceMapList
.
add
(
map
);
}
serviceMap
.
put
(
"type"
,
type
);
serviceMap
.
put
(
"repos"
,
serviceMapList
);
resultMapList
.
add
(
serviceMap
);
queryWrapper
.
clear
();
}
return
JsonResult
.
buildSuccessResult
(
resultMapList
);
}
}
}
src/main/java/cn/qg/holmes/service/k8s/ImageService.java
View file @
7c4e4c6f
...
@@ -45,12 +45,13 @@ public class ImageService {
...
@@ -45,12 +45,13 @@ public class ImageService {
* @param repoName 服务名
* @param repoName 服务名
* @return
* @return
*/
*/
public
Map
<
String
,
Object
>
getImageListByService
(
String
repoName
)
{
public
TagInfoResp
getImageListByService
(
String
repoName
)
{
try
{
try
{
DescribeImagePersonalRequest
request
=
new
DescribeImagePersonalRequest
();
DescribeImagePersonalRequest
request
=
new
DescribeImagePersonalRequest
();
request
.
setRepoName
(
repoName
);
request
.
setRepoName
(
repoName
);
DescribeImagePersonalResponse
response
=
tcrClient
.
DescribeImagePersonal
(
request
);
DescribeImagePersonalResponse
response
=
tcrClient
.
DescribeImagePersonal
(
request
);
return
JSON
.
parseObject
(
DescribeImagePersonalResponse
.
toJsonString
(
response
.
getData
()),
Map
.
class
);
// return JSON.parseObject(DescribeImagePersonalResponse.toJsonString(response.getData()), Map.class);
return
response
.
getData
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
return
null
;
return
null
;
...
@@ -97,7 +98,8 @@ public class ImageService {
...
@@ -97,7 +98,8 @@ 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
(
JSON
.
toJSONString
(
imageService
.
getRepoInfoList
(
"qa-test"
)));
// System.out.println(JSON.toJSONString(imageService.getRepoInfoList("qa-base")));
System
.
out
.
println
(
JSON
.
toJSONString
(
imageService
.
getImageListByService
(
"qa-base/mongodb"
)));
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment