Commit 43645596 authored by 黎博's avatar 黎博

新增方法

parent e6a3713d
......@@ -155,6 +155,11 @@
<version>5.4.1</version>
</dependency>
<dependency>
<groupId>com.tencentcloudapi</groupId>
<artifactId>tencentcloud-sdk-java</artifactId>
<version>3.1.305</version>
</dependency>
</dependencies>
......
......@@ -2,7 +2,6 @@ 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;
......
package cn.qg.holmes.controller.k8s;
import cn.qg.holmes.common.JsonResult;
import cn.qg.holmes.utils.K8sService;
import cn.qg.holmes.service.k8s.ImageService;
import cn.qg.holmes.service.k8s.TkeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
......@@ -14,7 +15,10 @@ import java.util.Map;
public class K8sController {
@Autowired
K8sService k8sService;
TkeService tkeService;
@Autowired
ImageService imageService;
/**
* 获取namespace列表
......@@ -22,7 +26,7 @@ public class K8sController {
*/
@GetMapping("/namespace")
public JsonResult getNamespaceList() {
return JsonResult.buildSuccessResult(k8sService.getNamespaceList());
return JsonResult.buildSuccessResult(tkeService.getNamespaceList());
}
/**
......@@ -32,7 +36,44 @@ public class K8sController {
*/
@GetMapping("/pod/list")
public JsonResult getServiceList(@RequestParam String namespace) {
List<Map<String, Object>> podList = k8sService.getPodList(namespace);
List<Map<String, Object>> podList = tkeService.getPodList(namespace);
return JsonResult.buildSuccessResult(podList);
}
/**
* 根据服务名称获取镜像列表
* @param serviceName 服务名称
* @return
*/
@GetMapping("/image/list")
public JsonResult getImageListByServiceName(@RequestParam String serviceName) {
return JsonResult.buildSuccessResult(imageService.getImageListByService(serviceName));
}
@PostMapping("/pod/create")
public JsonResult createPod() {
return null;
}
/**
* 重置pod
* @param namespace 环境
* @param podName podName
* @return
*/
@PostMapping("/pod/redeploy")
public JsonResult resetPodByName(String namespace, String podName) {
return JsonResult.buildSuccessResult(tkeService.resetPod(namespace, podName));
}
/**
* 删除pod
* @param namespace 环境
* @param serviceName 服务名称
* @return
*/
@PostMapping("/pod/delete")
public JsonResult deletePodByName(String namespace, String serviceName) {
return JsonResult.buildSuccessResult(tkeService.deleteService(namespace, serviceName));
}
}
package cn.qg.holmes.entity.k8s;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.util.Date;
@Data
@TableName("docker_project")
public class DockerProject {
@TableId(type = IdType.AUTO)
private Integer id;
private String projectName;
private String projectType;
private String gitPath;
private String gitPathGroup;
private String hostName;
private String logPath;
private String configPath;
private String desc;
private String owner;
private String buildCommand;
private String startCommand;
private String stopCommand;
private String deployToDocker;
private Integer isActive;
private String database;
private String ddl;
private String wiki;
private String api;
private String memLimit;
private String menRequest;
private String cpuLimit;
private String cpuRequest;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;
}
package cn.qg.holmes.entity.k8s;
import lombok.Data;
/**
* 创建服务接口请求实体类
*/
@Data
public class ServiceCreateVo {
private Integer debug;
private Integer mock;
private String domain;
private String image;
private String label;
private String namespace;
private String serviceName;
private String type;
private Integer wechat;
private String cluster;
}
package cn.qg.holmes.service.k8s;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.tcr.v20190924.TcrClient;
import com.tencentcloudapi.tcr.v20190924.models.DescribeImagePersonalRequest;
import com.tencentcloudapi.tcr.v20190924.models.DescribeImagePersonalResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* 镜像仓库相关服务
* @author libo 2021
*/
@Slf4j
@Component
public class ImageService {
private TcrClient tcrClient;
public ImageService() {
try {
Credential credential = new Credential("AKID4rY7wwNphsUcaFsy1pRtKhQvDj4CA3Ac", "YBduRnjgVRGzmagZJbss3Vo58wWCyhgc");
ClientProfile clientProfile = new ClientProfile();
clientProfile.setSignMethod("HmacSHA256");
tcrClient = new TcrClient(credential, "ap-beijing", clientProfile);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 根据服务名获取镜像列表
* @param serviceName 服务名
* @return
*/
public String getImageListByService(String serviceName) {
try {
String repoName = "qa-test/" + serviceName;
DescribeImagePersonalRequest request = new DescribeImagePersonalRequest();
request.setRepoName(repoName);
DescribeImagePersonalResponse response = tcrClient.DescribeImagePersonal(request);
return DescribeImagePersonalResponse.toJsonString(response);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static void main(String[] args) {
ImageService imageService = new ImageService();
System.out.println(imageService.getImageListByService("kdsp"));
}
}
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