Commit c68033ba authored by 黎博's avatar 黎博

update

parent f3f9619a
......@@ -3,6 +3,7 @@ package cn.qg.holmes.controller.effect;
import cn.qg.holmes.common.JsonResult;
import cn.qg.holmes.service.effect.DatabaseSyncService;
import cn.qg.holmes.service.k8s.K8sService;
import cn.qg.holmes.service.k8s.TkeService;
import cn.qg.holmes.utils.JenkinsService;
import lombok.extern.slf4j.Slf4j;
import net.sf.jsqlparser.expression.JdbcNamedParameter;
......@@ -51,7 +52,7 @@ public class DbSyncController {
private String dataPort;
@Autowired
K8sService k8sService;
TkeService tkeService;
/**
* 同步数据库
......@@ -65,7 +66,7 @@ public class DbSyncController {
public JsonResult syncDatabase(@RequestParam String namespace, @RequestParam String dbName, @RequestParam String tableName, @RequestParam boolean businessData) {
try {
long startTime = System.currentTimeMillis();
Map<String, String> map = k8sService.getMysqlAddressByNamespace(namespace);
Map<String, String> map = tkeService.getMysqlAddressByNamespace(namespace);
String destIp = map.get("host");
String destPort = map.get("port");
log.info("获取到{}环境的Mysql地址为:{}", namespace, destIp + ":" + destPort);
......
......@@ -30,8 +30,9 @@ import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.*;
@Deprecated
@Slf4j
@Component
//@Component
public class K8sService {
@Autowired
......
......@@ -805,4 +805,39 @@ public class TkeService {
}
}
/**
* 获取运行中的pod列表
*
* @param namespace 环境
* @return
*/
public Map<String, String> getMysqlAddressByNamespace(String namespace) {
// 获取Service
Service service = kubernetesClient.services().inNamespace(namespace).withName("mysql").get();
Map<String, String> labels = new HashMap<>();
labels.put("qcloud-app", "mysql");
labels.put("type", "base");
List<Pod> podList = kubernetesClient.pods().inNamespace(namespace).withLabels(labels).list().getItems();
String port = null;
String host = null;
if (service != null) {
port = String.valueOf(service.getSpec().getPorts().get(0).getNodePort());
}
if (podList.size() == 1) {
host = podList.get(0).getStatus().getHostIP();
}
if (podList.size() >= 2) {
for (Pod pod : podList) {
if (pod.getStatus().getHostIP() != null) {
host = pod.getStatus().getHostIP();
break;
}
}
}
Map<String, String> resultMap = new HashMap<>();
resultMap.put("host", host);
resultMap.put("port", port);
return resultMap;
}
}
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