Browse Source

1、添加GPU占用情况设置

pull/127/head
chenzhihang 1 year ago
parent
commit
7011194adc
6 changed files with 49 additions and 2 deletions
  1. +3
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/constant/Constant.java
  2. +19
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/ComputingResource.java
  3. +2
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/ComputingResourceDao.java
  4. +8
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/JupyterServiceImpl.java
  5. +13
    -2
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java
  6. +4
    -0
      ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/ComputingResourceDaoMapper.xml

+ 3
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/constant/Constant.java View File

@@ -7,4 +7,7 @@ public class Constant {

public final static int State_valid = 1; // 有效
public final static int State_invalid = 0; // 无效

public final static int Used_State_used = 1; // 已占用
public final static int Used_State_unused = 0; // 未占用
}

+ 19
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/ComputingResource.java View File

@@ -46,7 +46,11 @@ private Integer id;
@ApiModelProperty(value = "状态标识", notes = "0表示失效,1表示生效")
private Integer state;

@ApiModelProperty(value = "占用情况(1-占用,0-未占用)")
private Integer usedState;

@ApiModelProperty(value = "节点")
private String node;

public Integer getId() {
return id;
@@ -122,5 +126,20 @@ private Integer id;
this.state = state;
}

public Integer getUsedState() {
return usedState;
}

public void setUsedState(Integer usedState) {
this.usedState = usedState;
}

public String getNode() {
return node;
}

public void setNode(String node) {
this.node = node;
}
}


+ 2
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/ComputingResourceDao.java View File

@@ -73,6 +73,8 @@ public interface ComputingResourceDao {
*/
int update(@Param("computingResource") ComputingResource computingResource);

int updateUsedStateByNode(@Param("node")String node, @Param("usedState") Integer usedState);

/**
* 通过主键删除数据
*


+ 8
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/JupyterServiceImpl.java View File

@@ -2,8 +2,10 @@ package com.ruoyi.platform.service.impl;

import com.ruoyi.common.redis.service.RedisService;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.platform.constant.Constant;
import com.ruoyi.platform.domain.DevEnvironment;
import com.ruoyi.platform.domain.PodStatus;
import com.ruoyi.platform.mapper.ComputingResourceDao;
import com.ruoyi.platform.mapper.DevEnvironmentDao;
import com.ruoyi.platform.service.DevEnvironmentService;
import com.ruoyi.platform.service.JupyterService;
@@ -54,6 +56,9 @@ public class JupyterServiceImpl implements JupyterService {
@Resource
private DevEnvironmentDao devEnvironmentDao;

@Resource
private ComputingResourceDao computingResourceDao;

@Resource
@Lazy
private DevEnvironmentService devEnvironmentService;
@@ -126,6 +131,9 @@ public class JupyterServiceImpl implements JupyterService {
if(pod == null){
return "pod不存在!";
}

computingResourceDao.updateUsedStateByNode(pod.getSpec().getNodeName(), Constant.Used_State_unused);

// 使用 Kubernetes API 删除 Pod
String deleteResult = k8sClientUtil.deletePod(podName, namespace);
// 删除service


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

@@ -1,6 +1,8 @@
package com.ruoyi.platform.utils;

import com.alibaba.nacos.shaded.com.google.gson.reflect.TypeToken;
import com.ruoyi.platform.constant.Constant;
import com.ruoyi.platform.mapper.ComputingResourceDao;
import io.kubernetes.client.Exec;
import io.kubernetes.client.custom.IntOrString;
import io.kubernetes.client.custom.Quantity;
@@ -20,6 +22,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
@@ -40,6 +43,8 @@ public class K8sClientUtil {
*/
private static ApiClient apiClient;

@Resource
private ComputingResourceDao computingResourceDao;
/**
* 构建集群POD内通过SA访问的客户端
* loading the in-cluster config, including:
@@ -409,8 +414,6 @@ public class K8sClientUtil {
.namespaces(Collections.singletonList(namespace))
.topologyKey("kubernetes.io/hostname");

// V1WeightedPodAffinityTerm weightedPodAffinityTerm = new V1WeightedPodAffinityTerm().weight(100).podAffinityTerm(podAffinityTerm);

V1PodAntiAffinity podAntiAffinity = new V1PodAntiAffinity()
.requiredDuringSchedulingIgnoredDuringExecution(Collections.singletonList(antiPodAffinityTerm));

@@ -469,6 +472,8 @@ public class K8sClientUtil {

try {
pod = api.createNamespacedPod(namespace, pod, null, null, null);
String nodeName = getNodeName(podName, namespace);
computingResourceDao.updateUsedStateByNode(nodeName, Constant.Used_State_used);
} catch (ApiException e) {
log.error("创建pod异常:" + e.getResponseBody(), e);
} catch (Exception e) {
@@ -569,6 +574,12 @@ public class K8sClientUtil {
return pod.getStatus().getHostIP();
}

public String getNodeName(String podName, String namespace) throws Exception {
CoreV1Api api = new CoreV1Api(apiClient);
V1Pod pod = api.readNamespacedPod(podName, namespace, null, null, null);
return pod.getSpec().getNodeName();
}

public String getPodLogs(String podName,String namespace,String container,int line) {
CoreV1Api api = new CoreV1Api(apiClient);
try {


+ 4
- 0
ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/ComputingResourceDaoMapper.xml View File

@@ -156,6 +156,10 @@ computing_resource = values(computing_resource)standard = values(standard)descri
where id = #{computingResource.id}
</update>

<update id="updateUsedStateByNode">
update computing_resource set used_state = #{usedState} where node = #{node}
</update>

<!--通过主键删除-->
<delete id="deleteById">
delete from computing_resource where id = #{id}


Loading…
Cancel
Save