Browse Source

Merge remote-tracking branch 'origin/dev' into dev

pull/12/head^2
西大锐 1 year ago
parent
commit
22a085fba3
3 changed files with 37 additions and 36 deletions
  1. +4
    -4
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/PodStatus.java
  2. +10
    -9
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/TensorBoardServiceImpl.java
  3. +23
    -23
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java

ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/TensorBoardStatus.java → ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/PodStatus.java View File

@@ -1,15 +1,15 @@
package com.ruoyi.platform.domain; package com.ruoyi.platform.domain;


public enum TensorBoardStatus {
Pending("Pending",1), Running("Running",2),Terminated("未运行",3);
public enum PodStatus {
Pending("Pending",1), Running("Running",2),Terminated("Terminated",3), Failed("Failed",4), Unknown("Unknown",5);
private String name; private String name;
private int index; private int index;
private TensorBoardStatus(String name, int index) {
private PodStatus(String name, int index) {
this.name = name; this.name = name;
this.index = index; this.index = index;
} }
public static String getName(int index) { public static String getName(int index) {
for (TensorBoardStatus c : TensorBoardStatus.values()) {
for (PodStatus c : PodStatus.values()) {
if (c.getIndex() == index) { if (c.getIndex() == index) {
return c.name; return c.name;
} }

+ 10
- 9
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/TensorBoardServiceImpl.java View File

@@ -2,19 +2,15 @@ package com.ruoyi.platform.service.impl;


import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.security.utils.SecurityUtils; import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.platform.domain.TensorBoardStatus;
import com.ruoyi.platform.domain.PodStatus;
import com.ruoyi.platform.service.TensorBoardService; import com.ruoyi.platform.service.TensorBoardService;
import com.ruoyi.platform.utils.K8sClientUtil; import com.ruoyi.platform.utils.K8sClientUtil;
import com.ruoyi.platform.vo.FrameLogPathVo; import com.ruoyi.platform.vo.FrameLogPathVo;
import com.ruoyi.system.api.model.LoginUser; import com.ruoyi.system.api.model.LoginUser;
import io.kubernetes.client.openapi.models.V1Pod;
import net.sf.jsqlparser.schema.Database;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;


import javax.annotation.Resource; import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;


@Service @Service
public class TensorBoardServiceImpl implements TensorBoardService { public class TensorBoardServiceImpl implements TensorBoardService {
@@ -30,8 +26,8 @@ public class TensorBoardServiceImpl implements TensorBoardService {
private K8sClientUtil k8sClientUtil; private K8sClientUtil k8sClientUtil;
@Override @Override
public String getTensorBoardStatus(FrameLogPathVo frameLogPathVo){ public String getTensorBoardStatus(FrameLogPathVo frameLogPathVo){
String status = TensorBoardStatus.Terminated.getName();
if (StringUtils.isEmpty(frameLogPathVo.getPath())||StringUtils.isEmpty(frameLogPathVo.getPvcName())){
String status = PodStatus.Terminated.getName();
if (StringUtils.isEmpty(frameLogPathVo.getPath())){
return status; return status;
} }
LoginUser loginUser = SecurityUtils.getLoginUser(); LoginUser loginUser = SecurityUtils.getLoginUser();
@@ -39,9 +35,14 @@ public class TensorBoardServiceImpl implements TensorBoardService {


try { try {
String podStatus = k8sClientUtil.getPodStatus(podName, StringUtils.isEmpty(frameLogPathVo.getNamespace()) ? "default" : frameLogPathVo.getNamespace()); String podStatus = k8sClientUtil.getPodStatus(podName, StringUtils.isEmpty(frameLogPathVo.getNamespace()) ? "default" : frameLogPathVo.getNamespace());
System.out.println(podStatus);
for (PodStatus s : PodStatus.values()) {
if (s.getName().equals(podStatus)) {
status = s.getName();
break;
}
}
} catch (Exception e) { } catch (Exception e) {
return TensorBoardStatus.Terminated.getName();
return PodStatus.Terminated.getName();
} }
return status; return status;
} }


+ 23
- 23
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java View File

@@ -50,19 +50,19 @@ public class K8sClientUtil {
* 3. service-account namespace * 3. service-account namespace
* 4. master endpoints(ip, port) from pre-set environment variables * 4. master endpoints(ip, port) from pre-set environment variables
*/ */
@Autowired
public K8sClientUtil(@Value("${k8s.http}") String http, @Value("${k8s.token}") String token) {
this.http = http;
this.token = token;
try {
this.apiClient = new ClientBuilder().
setBasePath(http).setVerifyingSsl(false).
setAuthentication(new AccessTokenAuthentication(token)).build();
} catch (Exception e) {
log.error("构建K8s-Client异常", e);
throw new RuntimeException("构建K8s-Client异常");
}
}
// @Autowired
// public K8sClientUtil(@Value("${k8s.http}") String http, @Value("${k8s.token}") String token) {
// this.http = http;
// this.token = token;
// try {
// this.apiClient = new ClientBuilder().
// setBasePath(http).setVerifyingSsl(false).
// setAuthentication(new AccessTokenAuthentication(token)).build();
// } catch (Exception e) {
// log.error("构建K8s-Client异常", e);
// throw new RuntimeException("构建K8s-Client异常");
// }
// }
// @Autowired // @Autowired
// public K8sClientUtil() { // public K8sClientUtil() {
// try { // try {
@@ -87,16 +87,16 @@ public class K8sClientUtil {
* *
* @param kubeConfigPath kube连接配置文件 * @param kubeConfigPath kube连接配置文件
*/ */
// public K8sClientUtil() {
// try {
// this.apiClient = new ClientBuilder().
// setBasePath("https://172.20.32.181:6443").setVerifyingSsl(false).
// setAuthentication(new AccessTokenAuthentication("eyJhbGciOiJSUzI1NiIsImtpZCI6IjRWcFBPWl9YSFFxQ2tVanRuNHdRT1dnUlJNTnB2bG5TQlVSRjNKdExWNDQifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJkZWZhdWx0LXRva2VuLXNteGxuIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6ImRlZmF1bHQiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiIyZWY1ZjdkMC0zMTdkLTQxN2UtOWY4Ni1mYjA1OTFhYWVhZDQiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6a3ViZS1zeXN0ZW06ZGVmYXVsdCJ9.GMpReYK7YJ0nNy-F6VrUJQzjWQiSauAOeq0-DT8ik2Lx8f2eznYEm_3cHX4kIn_nYgfxo857urcHt4Ft6IgVtWzxLzVTCQVaNP_H2J8bnJn8W2tUKXzF_3d_GwO75H7kN8P3aoShULrOLpiIf3o3Az28_gwHkwCnd42npcKrCXfAKj8A2U7-KUFQXXA-etrWSw81C5t8ziL-2xaiDgwD3ewH-TNYsOpyWjGopNTxJn1F7GyJ7xDlmMJOaZhSnOrDggB7lqDEsE68YmZtqB7lcSaZHnKzvNhEdbKri4R7_urpjttz_k6qcfIi-l6GwPtJLatsPDg3OL3FFnzjvArJ-A")).build();
// } catch (Exception e) {
// log.error("构建K8s-Client异常", e);
// throw new RuntimeException("构建K8s-Client异常");
// }
// }
public K8sClientUtil() {
try {
this.apiClient = new ClientBuilder().
setBasePath("https://172.20.32.181:6443").setVerifyingSsl(false).
setAuthentication(new AccessTokenAuthentication("eyJhbGciOiJSUzI1NiIsImtpZCI6IjRWcFBPWl9YSFFxQ2tVanRuNHdRT1dnUlJNTnB2bG5TQlVSRjNKdExWNDQifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJkZWZhdWx0Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZWNyZXQubmFtZSI6ImFkbWluLXNlcnZpY2UtYWNjb3VudC10b2tlbi14ZDk5eiIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50Lm5hbWUiOiJhZG1pbi1zZXJ2aWNlLWFjY291bnQiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiJmMGEzNmYyMS01MjQyLTQ4MTAtYWVmZS0xOTEwOTZlZjc5YmUiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6ZGVmYXVsdDphZG1pbi1zZXJ2aWNlLWFjY291bnQifQ.fo-Wf0-5-IRC5fhRh65yfqCJqKfE9MrNFIXL2fd1CqVAHD7JBpWO2IsFiSmz9Bm7VfLmFAp2NB7DjW4ZLjC7ODiGhpSseBP8x4ceFuHL6pRGUsEBvHQBBBuQcGhNOcsxIDHnDqUdUzoLprj223lMZNTQowITuqYFU4GVbethyEuS6G5Wh9KHI3KYHFtG4_AeWBgI5Ppz8pDrhHzSFWTFbzxQ3RPGEwF0V-9wEtdrSYnfETi3rdRWif9W4a0RW8HwD9Gf7UCYcyFOs7e5_3-IvmctS85g87PYIfHXMhu_kOw-_Il4bkwPEK5uiBFDw0M1-s9YP-F9r5sXXvOJlsAr1g")).build();
} catch (Exception e) {
log.error("构建K8s-Client异常", e);
throw new RuntimeException("构建K8s-Client异常");
}
}


/** /**
* 获取所有的Pod * 获取所有的Pod


Loading…
Cancel
Save