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
2ca6b89b
Commit
2ca6b89b
authored
Jun 22, 2021
by
黎博
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增域名替换方法
parent
9d8042ad
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
49 additions
and
327 deletions
+49
-327
DbSyncController.java
...java/cn/qg/holmes/controller/effect/DbSyncController.java
+2
-2
DatabaseSyncService.java
...java/cn/qg/holmes/service/effect/DatabaseSyncService.java
+1
-1
DatabaseSyncServiceImpl.java
...g/holmes/service/effect/impl/DatabaseSyncServiceImpl.java
+11
-1
K8sService.java
src/main/java/cn/qg/holmes/utils/K8sService.java
+35
-6
SqlExecutionUtils.java
src/main/java/cn/qg/holmes/utils/SqlExecutionUtils.java
+0
-317
No files found.
src/main/java/cn/qg/holmes/controller/effect/DbSyncController.java
View file @
2ca6b89b
...
...
@@ -2,6 +2,7 @@ package cn.qg.holmes.controller.effect;
import
cn.qg.holmes.common.JsonResult
;
import
cn.qg.holmes.service.effect.DatabaseSyncService
;
import
cn.qg.holmes.utils.K8sService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
...
...
@@ -42,7 +43,7 @@ public class DbSyncController {
if
(
tableName
.
equalsIgnoreCase
(
"all"
)
||
tableName
.
equals
(
""
))
{
log
.
info
(
"开始同步{}库下所有的表"
,
dbName
);
databaseSyncService
.
getDbInfoFromSource
(
ip
,
port
,
username
,
password
,
dbName
);
databaseSyncService
.
syncDbToDest
(
destIp
,
destPort
,
"qa"
,
"qatest"
,
dbName
);
databaseSyncService
.
syncDbToDest
(
destIp
,
destPort
,
"qa"
,
"qatest"
,
dbName
,
namespace
);
}
else
{
log
.
info
(
"开始同步{}库下{}表"
,
dbName
,
tableName
);
databaseSyncService
.
getSingleTableFromSource
(
ip
,
port
,
username
,
password
,
dbName
,
tableName
);
...
...
@@ -66,7 +67,6 @@ public class DbSyncController {
return
JsonResult
.
buildSuccessResult
(
databaseSyncService
.
getDatabaseList
(
ip
,
port
,
username
,
password
));
}
/**
* 获取某个库下的表列表
* @param dbName 数据库名
...
...
src/main/java/cn/qg/holmes/service/effect/DatabaseSyncService.java
View file @
2ca6b89b
...
...
@@ -7,7 +7,7 @@ public interface DatabaseSyncService {
boolean
getDbInfoFromSource
(
String
ip
,
String
port
,
String
username
,
String
password
,
String
dbName
);
boolean
syncDbToDest
(
String
ip
,
String
port
,
String
username
,
String
password
,
String
dbName
);
boolean
syncDbToDest
(
String
ip
,
String
port
,
String
username
,
String
password
,
String
dbName
,
String
namespace
);
boolean
getSingleTableFromSource
(
String
ip
,
String
port
,
String
username
,
String
password
,
String
dbName
,
String
tableName
);
...
...
src/main/java/cn/qg/holmes/service/effect/impl/DatabaseSyncServiceImpl.java
View file @
2ca6b89b
...
...
@@ -159,7 +159,7 @@ public class DatabaseSyncServiceImpl implements DatabaseSyncService {
* @return
*/
@Override
public
boolean
syncDbToDest
(
String
ip
,
String
port
,
String
username
,
String
password
,
String
dbName
)
{
public
boolean
syncDbToDest
(
String
ip
,
String
port
,
String
username
,
String
password
,
String
dbName
,
String
namespace
)
{
String
driver
=
"com.mysql.jdbc.Driver"
;
String
url
=
"jdbc:mysql://"
+
ip
+
":"
+
port
;
...
...
@@ -210,6 +210,7 @@ public class DatabaseSyncServiceImpl implements DatabaseSyncService {
log
.
info
(
"开始同步表数据!"
);
long
dataStartTime
=
System
.
currentTimeMillis
();
for
(
String
insertSql:
insertTableRedisValue
.
split
(
"\n"
))
{
// statement.addBatch(replaceDomain(insertSql, namespace));
statement
.
addBatch
(
insertSql
);
}
statement
.
executeBatch
();
...
...
@@ -699,4 +700,13 @@ public class DatabaseSyncServiceImpl implements DatabaseSyncService {
}
}
private
String
replaceDomain
(
String
sql
,
String
namespace
)
{
if
(
sql
.
contains
(
"xyqb.com"
))
{
return
sql
.
replace
(
".xyqb.com"
,
"-"
+
namespace
+
".liangkebang.net"
);
}
else
if
(
sql
.
contains
(
".q-gp.com"
))
{
return
sql
.
replace
(
".q-gp.com"
,
"-"
+
namespace
+
".liangkebang.net"
);
}
else
{
return
sql
;
}
}
}
src/main/java/cn/qg/holmes/utils/K8sService.java
View file @
2ca6b89b
package
cn
.
qg
.
holmes
.
utils
;
import
io.fabric8.kubernetes.api.model.Namespace
;
import
io.fabric8.kubernetes.client.Config
;
import
io.fabric8.kubernetes.client.ConfigBuilder
;
import
io.fabric8.kubernetes.client.DefaultKubernetesClient
;
import
io.fabric8.kubernetes.client.KubernetesClient
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.core.io.ClassPathResource
;
import
org.springframework.stereotype.Component
;
import
java.io.*
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
@Slf4j
@Component
//
@Component
public
class
K8sService
{
private
KubernetesClient
kubernetesClient
;
...
...
@@ -32,6 +37,12 @@ public class K8sService {
}
/**
* 读取k8s配置文件
* @param file 配置文件名
* @return
* @throws IOException
*/
public
static
List
<
String
>
readConfigFile
(
String
file
)
throws
IOException
{
String
str
=
""
;
ClassPathResource
resource
=
new
ClassPathResource
(
file
);
...
...
@@ -44,8 +55,26 @@ public class K8sService {
return
result
;
}
public
static
void
main
(
String
[]
args
)
throws
IOException
{
K8sService
k8sService
=
new
K8sService
();
/**
* 获取namespace列表
* @return
*/
public
List
<
Map
<
String
,
Object
>>
getNamespaceList
()
{
List
<
Map
<
String
,
Object
>>
resultList
=
new
ArrayList
<>();
List
<
Namespace
>
namespaceList
=
kubernetesClient
.
namespaces
().
list
().
getItems
();
for
(
Namespace
namespace:
namespaceList
)
{
log
.
info
(
namespace
.
toString
());
if
(
namespace
.
getMetadata
().
getAnnotations
()
!=
null
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"name"
,
namespace
.
getMetadata
().
getName
());
map
.
put
(
"description"
,
namespace
.
getMetadata
().
getAnnotations
().
get
(
"description"
));
map
.
put
(
"owner"
,
namespace
.
getMetadata
().
getAnnotations
().
get
(
"owner"
));
map
.
put
(
"status"
,
namespace
.
getStatus
().
getPhase
());
map
.
put
(
"createdAt"
,
namespace
.
getMetadata
().
getCreationTimestamp
());
resultList
.
add
(
map
);
}
}
return
resultList
;
}
}
src/main/java/cn/qg/holmes/utils/SqlExecutionUtils.java
deleted
100644 → 0
View file @
9d8042ad
This diff is collapsed.
Click to expand it.
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