Commit ef9d7726 authored by 黎博's avatar 黎博

优化

parent eecab0cd
......@@ -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("/dblist")
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));
}
}
......@@ -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
......@@ -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();
}
}
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