Commit cb47ebad authored by 黎博's avatar 黎博

测试

parent ac12fa39
...@@ -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");
......
...@@ -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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment