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
ef9d7726
Commit
ef9d7726
authored
Jun 21, 2021
by
黎博
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化
parent
eecab0cd
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
245 additions
and
30 deletions
+245
-30
DbSyncController.java
...java/cn/qg/holmes/controller/effect/DbSyncController.java
+26
-3
DatabaseSyncService.java
...java/cn/qg/holmes/service/effect/DatabaseSyncService.java
+6
-0
DatabaseSyncServiceImpl.java
...g/holmes/service/effect/impl/DatabaseSyncServiceImpl.java
+211
-21
K8sService.java
src/main/java/cn/qg/holmes/utils/K8sService.java
+2
-6
No files found.
src/main/java/cn/qg/holmes/controller/effect/DbSyncController.java
View file @
ef9d7726
...
...
@@ -10,7 +10,7 @@ import java.util.Map;
@CrossOrigin
@RestController
@RequestMapping
(
"/db"
)
@RequestMapping
(
"/db
/sync
"
)
public
class
DbSyncController
{
@Autowired
...
...
@@ -28,7 +28,7 @@ public class DbSyncController {
@Value
(
"${dbsync.mysql.password}"
)
private
String
password
;
@GetMapping
(
"/
sync/one
"
)
@GetMapping
(
"/
db
"
)
public
JsonResult
syncSingleDatabase
(
@RequestParam
String
namespace
,
@RequestParam
String
dbName
)
{
long
startTime
=
System
.
currentTimeMillis
();
databaseSyncService
.
getDbInfoFromSource
(
ip
,
port
,
username
,
password
,
dbName
);
...
...
@@ -40,12 +40,35 @@ public class DbSyncController {
return
JsonResult
.
buildSuccessResult
((
endTime
-
startTime
)
/
1000
);
}
@GetMapping
(
"/table"
)
public
JsonResult
syncSingleTable
(
@RequestParam
String
namespace
,
@RequestParam
String
dbName
,
@RequestParam
String
tableName
)
{
long
startTime
=
System
.
currentTimeMillis
();
Map
<
String
,
String
>
map
=
databaseSyncService
.
getMysqlInfoByNamespace
(
namespace
);
String
destIp
=
map
.
get
(
"ip"
);
String
destPort
=
map
.
get
(
"port"
);
databaseSyncService
.
getSingleTableFromSource
(
ip
,
port
,
username
,
password
,
dbName
,
tableName
);
databaseSyncService
.
syncSingleTableToDest
(
destIp
,
destPort
,
"qa"
,
"qatest"
,
dbName
,
tableName
);
long
endTime
=
System
.
currentTimeMillis
();
return
JsonResult
.
buildSuccessResult
((
endTime
-
startTime
)
/
1000
);
}
/**
* 获取数据库列表
* @return
*/
@GetMapping
(
"/
sync/
list"
)
@GetMapping
(
"/
db
list"
)
public
JsonResult
getDatabaseList
()
{
return
JsonResult
.
buildSuccessResult
(
databaseSyncService
.
getDatabaseList
(
ip
,
port
,
username
,
password
));
}
/**
* 获取某个库下的表列表
* @param dbName
* @return
*/
@GetMapping
(
"/tablelist"
)
public
JsonResult
getTableList
(
@RequestParam
String
dbName
)
{
return
JsonResult
.
buildSuccessResult
(
databaseSyncService
.
getTableListByDb
(
ip
,
port
,
username
,
password
,
dbName
));
}
}
src/main/java/cn/qg/holmes/service/effect/DatabaseSyncService.java
View file @
ef9d7726
...
...
@@ -9,7 +9,13 @@ public interface DatabaseSyncService {
boolean
syncDbToDest
(
String
ip
,
String
port
,
String
username
,
String
password
,
String
dbName
);
boolean
getSingleTableFromSource
(
String
ip
,
String
port
,
String
username
,
String
password
,
String
dbName
,
String
tableName
);
boolean
syncSingleTableToDest
(
String
ip
,
String
port
,
String
username
,
String
password
,
String
dbName
,
String
tableName
);
List
<
Object
>
getDatabaseList
(
String
ip
,
String
port
,
String
username
,
String
password
);
Map
<
String
,
String
>
getMysqlInfoByNamespace
(
String
namespace
);
List
<
Object
>
getTableListByDb
(
String
ip
,
String
port
,
String
username
,
String
password
,
String
dbName
);
}
\ No newline at end of file
src/main/java/cn/qg/holmes/service/effect/impl/DatabaseSyncServiceImpl.java
View file @
ef9d7726
This diff is collapsed.
Click to expand it.
src/main/java/cn/qg/holmes/utils/K8sService.java
View file @
ef9d7726
...
...
@@ -45,11 +45,7 @@ public class K8sService {
}
public
static
void
main
(
String
[]
args
)
throws
IOException
{
String
configYAML
=
String
.
join
(
"\n"
,
readConfigFile
(
"kube-config.yml"
));
Config
config
=
Config
.
fromKubeconfig
(
configYAML
);
KubernetesClient
client
=
new
DefaultKubernetesClient
(
config
);
String
configCrt
=
String
.
join
(
"\n"
,
readConfigFile
(
"tke-cluster-ca.crt"
));
config
.
setCaCertData
(
configCrt
);
System
.
out
.
println
(
client
.
pods
().
inNamespace
(
"fe"
).
withName
(
"mysql"
).
get
());
K8sService
k8sService
=
new
K8sService
();
}
}
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