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
4276634a
Commit
4276634a
authored
Nov 08, 2021
by
黎博
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增数据同步接口及数据库列表和表列表接口
parent
342ae07d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
88 additions
and
10 deletions
+88
-10
DbSyncController.java
...java/cn/qg/holmes/controller/effect/DbSyncController.java
+67
-10
JenkinsService.java
src/main/java/cn/qg/holmes/utils/JenkinsService.java
+21
-0
No files found.
src/main/java/cn/qg/holmes/controller/effect/DbSyncController.java
View file @
4276634a
...
...
@@ -38,6 +38,18 @@ public class DbSyncController {
@Value
(
"${dbsync.mysql.password}"
)
private
String
password
;
/**
* 数据库同步之数据同步服务器ip地址
*/
@Value
(
"${dbsync.data.mysql.ip}"
)
private
String
dataIp
;
/**
* 数据库同步之数据同步服务器端口号
*/
@Value
(
"${dbsync.data.mysql.port}"
)
private
String
dataPort
;
@Autowired
K8sService
k8sService
;
...
...
@@ -86,7 +98,7 @@ public class DbSyncController {
}
/**
* 获取数据库列表
* 获取数据库列表
, 给db_sync用,源是同步库172.30.5.35
* @return
*/
@GetMapping
(
"/dbs"
)
...
...
@@ -95,7 +107,7 @@ public class DbSyncController {
}
/**
* 获取某个库下的表列表
* 获取某个库下的表列表
,给db_sync用,源是同步库172.30.5.35
* @param dbName 数据库名
* @return
*/
...
...
@@ -107,7 +119,7 @@ public class DbSyncController {
}
/**
*
给数据库同步脚本使用的接口
*
获取表列表,给数据库同步shell脚本使用
* @param database 数据库名
* @return
*/
...
...
@@ -120,7 +132,7 @@ public class DbSyncController {
}
/**
* 获取同步库所有的数据库
* 获取同步库所有的数据库
,给数据库同步shell脚本使用
* 给数据库同步脚本使用的接口
* @return
*/
...
...
@@ -132,11 +144,11 @@ public class DbSyncController {
}
/**
* 同步表结构
* @param targetIp
* @param targetPort
* @param database
* @param table
* 同步表结构
,给数据库同步shell脚本使用
* @param targetIp
目标库ip
* @param targetPort
目标库端口
* @param database
数据库名
* @param table
表名
* @return
*/
@GetMapping
(
"/table/structure"
)
...
...
@@ -162,7 +174,7 @@ public class DbSyncController {
* @param businessData 是否保留业务数据
* @return
*/
@PostMapping
(
"new"
)
@PostMapping
(
"
/
new"
)
public
JsonResult
dbSyncNew
(
@RequestParam
String
namespace
,
@RequestParam
String
targetHost
,
@RequestParam
String
targetPort
,
...
...
@@ -177,6 +189,51 @@ public class DbSyncController {
}
}
/**
* 同步数据库之数据,调用jenkins job db_sync_data
* @param namespace 环境名
* @param targetHost 目标ip
* @param targetPort 目标端口号
* @param database 数据库名称
* @param table 表名称,all-表示所有
* @return
*/
@PostMapping
(
"/data"
)
public
JsonResult
dbSyncData
(
@RequestParam
String
namespace
,
@RequestParam
String
targetHost
,
@RequestParam
String
targetPort
,
@RequestParam
String
database
,
@RequestParam
String
table
)
{
int
buildNum
=
jenkinsService
.
buildDbSyncDataJob
(
namespace
,
targetHost
,
targetPort
,
database
,
table
);
if
(
buildNum
==
0
)
{
return
JsonResult
.
buildErrorStateResult
(
"同步失败!"
,
0
);
}
else
{
return
JsonResult
.
buildSuccessResult
(
"开始同步数据库!"
,
buildNum
);
}
}
/**
* 获取数据库同步之数据同步源下的数据库列表,给db_sync_data用
* @return
*/
@GetMapping
(
"/data/dbs"
)
public
JsonResult
getDataDbSyncDbs
()
{
return
JsonResult
.
buildSuccessResult
(
databaseSyncService
.
getDatabaseList
(
dataIp
,
dataPort
,
username
,
password
));
}
/**
* 获取数据库同步之数据同步源下的某个数据库下表列表,给db_sync_data用
* @param dbName 数据库名
* @return
*/
@GetMapping
(
"/data/tables"
)
public
JsonResult
getDataDbSyncTableList
(
@RequestParam
String
dbName
)
{
List
<
String
>
tableList
=
databaseSyncService
.
getTableListByDb
(
dataIp
,
dataPort
,
username
,
password
,
dbName
);
tableList
.
add
(
0
,
"all"
);
return
JsonResult
.
buildSuccessResult
(
tableList
);
}
/**
* 老数据库同步,调用Jenkins job sync_database_schema
* @param dbName 数据库名
...
...
src/main/java/cn/qg/holmes/utils/JenkinsService.java
View file @
4276634a
...
...
@@ -243,6 +243,27 @@ public class JenkinsService {
}
}
/**
* 构建db_sync_data
*/
public
int
buildDbSyncDataJob
(
String
namespace
,
String
host
,
String
port
,
String
database
,
String
table
)
{
Map
<
String
,
String
>
params
=
new
HashMap
<>();
params
.
put
(
"namespace"
,
namespace
);
params
.
put
(
"target_db_host"
,
host
);
params
.
put
(
"target_db_port"
,
port
);
params
.
put
(
"database"
,
database
);
params
.
put
(
"table"
,
table
);
try
{
jenkinsServer
.
getJob
(
"db_sync_data"
).
build
(
params
);
Build
build
=
jenkinsServer
.
getJob
(
"db_sync_data"
).
getLastBuild
();
return
build
.
getNumber
()
+
1
;
}
catch
(
Exception
e
)
{
log
.
info
(
"执行jenkins job db_sync_data失败,host:{}, port: {}, dbName: {}"
,
host
,
port
,
database
);
e
.
printStackTrace
();
return
0
;
}
}
public
static
void
main
(
String
[]
args
)
throws
IOException
{
JenkinsService
jenkinsApi
=
new
JenkinsService
();
// List<Build> buildList = jenkinsApi.getJobBuildList("tke-java", 1, "kdsp");
...
...
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