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
c68033ba
Commit
c68033ba
authored
Apr 20, 2022
by
黎博
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
f3f9619a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
3 deletions
+40
-3
DbSyncController.java
...java/cn/qg/holmes/controller/effect/DbSyncController.java
+3
-2
K8sService.java
src/main/java/cn/qg/holmes/service/k8s/K8sService.java
+2
-1
TkeService.java
src/main/java/cn/qg/holmes/service/k8s/TkeService.java
+35
-0
No files found.
src/main/java/cn/qg/holmes/controller/effect/DbSyncController.java
View file @
c68033ba
...
@@ -3,6 +3,7 @@ package cn.qg.holmes.controller.effect;
...
@@ -3,6 +3,7 @@ package cn.qg.holmes.controller.effect;
import
cn.qg.holmes.common.JsonResult
;
import
cn.qg.holmes.common.JsonResult
;
import
cn.qg.holmes.service.effect.DatabaseSyncService
;
import
cn.qg.holmes.service.effect.DatabaseSyncService
;
import
cn.qg.holmes.service.k8s.K8sService
;
import
cn.qg.holmes.service.k8s.K8sService
;
import
cn.qg.holmes.service.k8s.TkeService
;
import
cn.qg.holmes.utils.JenkinsService
;
import
cn.qg.holmes.utils.JenkinsService
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
net.sf.jsqlparser.expression.JdbcNamedParameter
;
import
net.sf.jsqlparser.expression.JdbcNamedParameter
;
...
@@ -51,7 +52,7 @@ public class DbSyncController {
...
@@ -51,7 +52,7 @@ public class DbSyncController {
private
String
dataPort
;
private
String
dataPort
;
@Autowired
@Autowired
K8sService
k8s
Service
;
TkeService
tke
Service
;
/**
/**
* 同步数据库
* 同步数据库
...
@@ -65,7 +66,7 @@ public class DbSyncController {
...
@@ -65,7 +66,7 @@ public class DbSyncController {
public
JsonResult
syncDatabase
(
@RequestParam
String
namespace
,
@RequestParam
String
dbName
,
@RequestParam
String
tableName
,
@RequestParam
boolean
businessData
)
{
public
JsonResult
syncDatabase
(
@RequestParam
String
namespace
,
@RequestParam
String
dbName
,
@RequestParam
String
tableName
,
@RequestParam
boolean
businessData
)
{
try
{
try
{
long
startTime
=
System
.
currentTimeMillis
();
long
startTime
=
System
.
currentTimeMillis
();
Map
<
String
,
String
>
map
=
k8s
Service
.
getMysqlAddressByNamespace
(
namespace
);
Map
<
String
,
String
>
map
=
tke
Service
.
getMysqlAddressByNamespace
(
namespace
);
String
destIp
=
map
.
get
(
"host"
);
String
destIp
=
map
.
get
(
"host"
);
String
destPort
=
map
.
get
(
"port"
);
String
destPort
=
map
.
get
(
"port"
);
log
.
info
(
"获取到{}环境的Mysql地址为:{}"
,
namespace
,
destIp
+
":"
+
destPort
);
log
.
info
(
"获取到{}环境的Mysql地址为:{}"
,
namespace
,
destIp
+
":"
+
destPort
);
...
...
src/main/java/cn/qg/holmes/service/k8s/K8sService.java
View file @
c68033ba
...
@@ -30,8 +30,9 @@ import java.io.InputStreamReader;
...
@@ -30,8 +30,9 @@ import java.io.InputStreamReader;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
import
java.util.*
;
@Deprecated
@Slf4j
@Slf4j
@Component
//
@Component
public
class
K8sService
{
public
class
K8sService
{
@Autowired
@Autowired
...
...
src/main/java/cn/qg/holmes/service/k8s/TkeService.java
View file @
c68033ba
...
@@ -805,4 +805,39 @@ public class TkeService {
...
@@ -805,4 +805,39 @@ public class TkeService {
}
}
}
}
/**
* 获取运行中的pod列表
*
* @param namespace 环境
* @return
*/
public
Map
<
String
,
String
>
getMysqlAddressByNamespace
(
String
namespace
)
{
// 获取Service
Service
service
=
kubernetesClient
.
services
().
inNamespace
(
namespace
).
withName
(
"mysql"
).
get
();
Map
<
String
,
String
>
labels
=
new
HashMap
<>();
labels
.
put
(
"qcloud-app"
,
"mysql"
);
labels
.
put
(
"type"
,
"base"
);
List
<
Pod
>
podList
=
kubernetesClient
.
pods
().
inNamespace
(
namespace
).
withLabels
(
labels
).
list
().
getItems
();
String
port
=
null
;
String
host
=
null
;
if
(
service
!=
null
)
{
port
=
String
.
valueOf
(
service
.
getSpec
().
getPorts
().
get
(
0
).
getNodePort
());
}
if
(
podList
.
size
()
==
1
)
{
host
=
podList
.
get
(
0
).
getStatus
().
getHostIP
();
}
if
(
podList
.
size
()
>=
2
)
{
for
(
Pod
pod
:
podList
)
{
if
(
pod
.
getStatus
().
getHostIP
()
!=
null
)
{
host
=
pod
.
getStatus
().
getHostIP
();
break
;
}
}
}
Map
<
String
,
String
>
resultMap
=
new
HashMap
<>();
resultMap
.
put
(
"host"
,
host
);
resultMap
.
put
(
"port"
,
port
);
return
resultMap
;
}
}
}
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