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
cb47ebad
Commit
cb47ebad
authored
Oct 13, 2021
by
黎博
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
测试
parent
ac12fa39
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
9 deletions
+20
-9
DbSyncController.java
...java/cn/qg/holmes/controller/effect/DbSyncController.java
+19
-8
DbSyncTask.java
src/main/java/cn/qg/holmes/task/DbSyncTask.java
+1
-1
No files found.
src/main/java/cn/qg/holmes/controller/effect/DbSyncController.java
View file @
cb47ebad
...
@@ -5,6 +5,7 @@ import cn.qg.holmes.service.effect.DatabaseSyncService;
...
@@ -5,6 +5,7 @@ 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.utils.JenkinsService
;
import
cn.qg.holmes.utils.JenkinsService
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
...
@@ -55,6 +56,14 @@ public class DbSyncController {
...
@@ -55,6 +56,14 @@ public class DbSyncController {
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
);
if
(!
StringUtils
.
isEmpty
(
dbName
))
{
// 同步所有数据库
if
(
dbName
.
equalsIgnoreCase
(
"all"
))
{
List
<
String
>
dbList
=
databaseSyncService
.
getDatabaseList
(
ip
,
port
,
username
,
password
);
databaseSyncService
.
getDbInfoFromSource
(
ip
,
port
,
username
,
password
,
dbName
);
databaseSyncService
.
syncDbToDest
(
destIp
,
destPort
,
"qa"
,
"qatest"
,
dbName
,
namespace
,
businessData
);
}
else
{
// 同步单个数据库或单张表
if
(
tableName
.
equalsIgnoreCase
(
"all"
)
||
tableName
.
equals
(
""
))
{
if
(
tableName
.
equalsIgnoreCase
(
"all"
)
||
tableName
.
equals
(
""
))
{
log
.
info
(
"开始同步{}库下所有表到{}环境,保留业务数据:{}"
,
dbName
,
namespace
,
businessData
);
log
.
info
(
"开始同步{}库下所有表到{}环境,保留业务数据:{}"
,
dbName
,
namespace
,
businessData
);
databaseSyncService
.
getDbInfoFromSource
(
ip
,
port
,
username
,
password
,
dbName
);
databaseSyncService
.
getDbInfoFromSource
(
ip
,
port
,
username
,
password
,
dbName
);
...
@@ -64,6 +73,8 @@ public class DbSyncController {
...
@@ -64,6 +73,8 @@ public class DbSyncController {
databaseSyncService
.
getSingleTableFromSource
(
ip
,
port
,
username
,
password
,
dbName
,
tableName
);
databaseSyncService
.
getSingleTableFromSource
(
ip
,
port
,
username
,
password
,
dbName
,
tableName
);
databaseSyncService
.
syncSingleTableToDest
(
destIp
,
destPort
,
"qa"
,
"qatest"
,
dbName
,
tableName
,
businessData
);
databaseSyncService
.
syncSingleTableToDest
(
destIp
,
destPort
,
"qa"
,
"qatest"
,
dbName
,
tableName
,
businessData
);
}
}
}
}
long
endTime
=
System
.
currentTimeMillis
();
long
endTime
=
System
.
currentTimeMillis
();
long
elapsedTime
=
(
endTime
-
startTime
)
/
1000
;
long
elapsedTime
=
(
endTime
-
startTime
)
/
1000
;
return
JsonResult
.
buildSuccessResult
(
elapsedTime
+
"s"
);
return
JsonResult
.
buildSuccessResult
(
elapsedTime
+
"s"
);
...
...
src/main/java/cn/qg/holmes/task/DbSyncTask.java
View file @
cb47ebad
...
@@ -32,7 +32,7 @@ public class DbSyncTask {
...
@@ -32,7 +32,7 @@ public class DbSyncTask {
private
String
password
;
private
String
password
;
// @Scheduled(cron = "0 0 24 * * ?")
// @Scheduled(cron = "0 0 24 * * ?")
@Scheduled
(
cron
=
"0
30
15 * * ?"
)
@Scheduled
(
cron
=
"0
55
15 * * ?"
)
public
void
getDbInfoFromSourceJob
()
{
public
void
getDbInfoFromSourceJob
()
{
List
<
String
>
dbList
=
databaseSyncService
.
getDatabaseList
(
ip
,
port
,
username
,
password
);
List
<
String
>
dbList
=
databaseSyncService
.
getDatabaseList
(
ip
,
port
,
username
,
password
);
for
(
String
dbName:
dbList
)
{
for
(
String
dbName:
dbList
)
{
...
...
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