From 7011194adceac20a7fb4859d02126a2ceb67992a Mon Sep 17 00:00:00 2001 From: chenzhihang <709011834@qq.com> Date: Thu, 29 Aug 2024 14:02:18 +0800 Subject: [PATCH 01/12] =?UTF-8?q?1=E3=80=81=E6=B7=BB=E5=8A=A0GPU=E5=8D=A0?= =?UTF-8?q?=E7=94=A8=E6=83=85=E5=86=B5=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ruoyi/platform/constant/Constant.java | 3 +++ .../platform/domain/ComputingResource.java | 19 +++++++++++++++++++ .../platform/mapper/ComputingResourceDao.java | 2 ++ .../service/impl/JupyterServiceImpl.java | 8 ++++++++ .../ruoyi/platform/utils/K8sClientUtil.java | 15 +++++++++++++-- .../ComputingResourceDaoMapper.xml | 4 ++++ 6 files changed, 49 insertions(+), 2 deletions(-) diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/constant/Constant.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/constant/Constant.java index 9d2fe7f..b74c30e 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/constant/Constant.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/constant/Constant.java @@ -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; // 未占用 } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/ComputingResource.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/ComputingResource.java index 47d7892..d0551fa 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/ComputingResource.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/ComputingResource.java @@ -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; + } } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/ComputingResourceDao.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/ComputingResourceDao.java index b9a5de6..93cdaaf 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/ComputingResourceDao.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/ComputingResourceDao.java @@ -73,6 +73,8 @@ public interface ComputingResourceDao { */ int update(@Param("computingResource") ComputingResource computingResource); + int updateUsedStateByNode(@Param("node")String node, @Param("usedState") Integer usedState); + /** * 通过主键删除数据 * diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/JupyterServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/JupyterServiceImpl.java index aa59b6a..6e2dc71 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/JupyterServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/JupyterServiceImpl.java @@ -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 diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java index 06e4062..d022bf3 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java @@ -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 { diff --git a/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/ComputingResourceDaoMapper.xml b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/ComputingResourceDaoMapper.xml index 885da31..162a12f 100644 --- a/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/ComputingResourceDaoMapper.xml +++ b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/ComputingResourceDaoMapper.xml @@ -156,6 +156,10 @@ computing_resource = values(computing_resource)standard = values(standard)descri where id = #{computingResource.id} + + update computing_resource set used_state = #{usedState} where node = #{node} + + delete from computing_resource where id = #{id} From d42b8e918d2eb4b0749c4b46acf571f37ba1e355 Mon Sep 17 00:00:00 2001 From: chenzhihang <709011834@qq.com> Date: Thu, 29 Aug 2024 14:18:13 +0800 Subject: [PATCH 02/12] =?UTF-8?q?1=E3=80=81=E6=B7=BB=E5=8A=A0GPU=E5=8D=A0?= =?UTF-8?q?=E7=94=A8=E6=83=85=E5=86=B5=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ruoyi/platform/constant/Constant.java | 5 ++ .../service/impl/JupyterServiceImpl.java | 33 ++++--- .../ruoyi/platform/utils/K8sClientUtil.java | 88 +++++++++---------- 3 files changed, 65 insertions(+), 61 deletions(-) diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/constant/Constant.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/constant/Constant.java index b74c30e..9d14aa3 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/constant/Constant.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/constant/Constant.java @@ -10,4 +10,9 @@ public class Constant { public final static int Used_State_used = 1; // 已占用 public final static int Used_State_unused = 0; // 未占用 + + + public final static String Computing_Resource_CPU = "CPU"; // 计算资源_CPU + + public final static String Computing_Resource_GPU = "GPU"; // 计算资源_GPU } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/JupyterServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/JupyterServiceImpl.java index 6e2dc71..b99bdb2 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/JupyterServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/JupyterServiceImpl.java @@ -75,7 +75,7 @@ public class JupyterServiceImpl implements JupyterService { LoginUser loginUser = SecurityUtils.getLoginUser(); String podName = loginUser.getUsername().toLowerCase() + "-editor-pod"; String pvcName = loginUser.getUsername().toLowerCase() + "-editor-pvc"; - V1PersistentVolumeClaim pvc = k8sClientUtil.createPvc(namespace, pvcName, storage,storageClassName); + V1PersistentVolumeClaim pvc = k8sClientUtil.createPvc(namespace, pvcName, storage, storageClassName); Integer podPort = k8sClientUtil.createPod(podName, namespace, port, mountPath, pvc, image); return masterIp + ":" + podPort; @@ -84,7 +84,7 @@ public class JupyterServiceImpl implements JupyterService { @Override public String runJupyterService(Integer id) throws Exception { DevEnvironment devEnvironment = this.devEnvironmentDao.queryById(id); - if(devEnvironment == null){ + if (devEnvironment == null) { throw new Exception("开发环境配置不存在"); } @@ -97,7 +97,7 @@ public class JupyterServiceImpl implements JupyterService { LoginUser loginUser = SecurityUtils.getLoginUser(); //构造pod名称 - String podName = loginUser.getUsername().toLowerCase() +"-editor-pod" + "-" + id; + String podName = loginUser.getUsername().toLowerCase() + "-editor-pod" + "-" + id; String pvcName = loginUser.getUsername().toLowerCase() + "-editor-pvc"; //新建编辑器的pvc V1PersistentVolumeClaim pvc = k8sClientUtil.createPvc(namespace, pvcName, storage, storageClassName); @@ -105,13 +105,13 @@ public class JupyterServiceImpl implements JupyterService { //TODO 设置镜像可配置,这里先用默认镜像启动pod // 调用修改后的 createPod 方法,传入额外的参数 - Integer podPort = k8sClientUtil.createConfiguredPod(podName, namespace, port, mountPath, pvc, devEnvironment.getImage(), minioPvcName, datasetPath, modelPath); + Integer podPort = k8sClientUtil.createConfiguredPod(podName, namespace, port, mountPath, pvc, devEnvironment.getImage(), devEnvironment.getComputingResource(), minioPvcName, datasetPath, modelPath); String url = masterIp + ":" + podPort; - redisService.setCacheObject(podName,masterIp + ":" + podPort); + redisService.setCacheObject(podName, masterIp + ":" + podPort); devEnvironment.setStatus("Pending"); devEnvironment.setUrl(url); this.devEnvironmentService.update(devEnvironment); - return url ; + return url; } @@ -119,20 +119,22 @@ public class JupyterServiceImpl implements JupyterService { @Override public String stopJupyterService(Integer id) throws Exception { DevEnvironment devEnvironment = this.devEnvironmentDao.queryById(id); - if (devEnvironment==null){ + if (devEnvironment == null) { throw new Exception("开发环境配置不存在"); } LoginUser loginUser = SecurityUtils.getLoginUser(); //构造pod和svc名称 - String podName = loginUser.getUsername().toLowerCase() +"-editor-pod" + "-" + id; - String svcName = loginUser.getUsername().toLowerCase() + "-editor-pod" + "-" + id + "-svc"; + String podName = loginUser.getUsername().toLowerCase() + "-editor-pod" + "-" + id; + String svcName = loginUser.getUsername().toLowerCase() + "-editor-pod" + "-" + id + "-svc"; //得到pod V1Pod pod = k8sClientUtil.getNSPodList(namespace, podName); - if(pod == null){ + if (pod == null) { return "pod不存在!"; } - computingResourceDao.updateUsedStateByNode(pod.getSpec().getNodeName(), Constant.Used_State_unused); + if (Constant.Computing_Resource_GPU.equals(devEnvironment.getComputingResource())) { + computingResourceDao.updateUsedStateByNode(pod.getSpec().getNodeName(), Constant.Used_State_unused); + } // 使用 Kubernetes API 删除 Pod String deleteResult = k8sClientUtil.deletePod(podName, namespace); @@ -150,11 +152,11 @@ public class JupyterServiceImpl implements JupyterService { String status = PodStatus.Terminated.getName(); PodStatusVo JupyterStatusVo = new PodStatusVo(); JupyterStatusVo.setStatus(status); - if (devEnvironment==null){ + if (devEnvironment == null) { return JupyterStatusVo; } LoginUser loginUser = SecurityUtils.getLoginUser(); - String podName = loginUser.getUsername().toLowerCase() +"-editor-pod" + "-" + devEnvironment.getId(); + String podName = loginUser.getUsername().toLowerCase() + "-editor-pod" + "-" + devEnvironment.getId(); try { // 查询相应pod状态 @@ -180,7 +182,7 @@ public class JupyterServiceImpl implements JupyterService { @Override public void upload(InputStream inputStream) { try { - minioUtil.uploadObject("platform-data","/pytorch/testupload4008208820",inputStream); + minioUtil.uploadObject("platform-data", "/pytorch/testupload4008208820", inputStream); } catch (Exception e) { e.printStackTrace(); } @@ -195,7 +197,4 @@ public class JupyterServiceImpl implements JupyterService { } - - - } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java index d022bf3..d5b5ab2 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java @@ -1,6 +1,5 @@ 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; @@ -8,20 +7,16 @@ import io.kubernetes.client.custom.IntOrString; import io.kubernetes.client.custom.Quantity; import io.kubernetes.client.openapi.ApiClient; import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.ApiResponse; import io.kubernetes.client.openapi.apis.CoreV1Api; import io.kubernetes.client.openapi.models.*; import io.kubernetes.client.util.ClientBuilder; -import io.kubernetes.client.util.Watch; import io.kubernetes.client.util.credentials.AccessTokenAuthentication; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; -import org.apache.poi.ss.formula.functions.T; import org.springframework.beans.factory.annotation.Autowired; 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; @@ -45,6 +40,7 @@ public class K8sClientUtil { @Resource private ComputingResourceDao computingResourceDao; + /** * 构建集群POD内通过SA访问的客户端 * loading the in-cluster config, including: @@ -138,11 +134,11 @@ public class K8sClientUtil { } catch (ApiException e) { log.error("获取 SVC 异常:", e); } - if (v1ServiceList!=null) { + if (v1ServiceList != null) { for (V1Service svc : v1ServiceList.getItems()) { if (StringUtils.equals(svc.getMetadata().getName(), serviceName)) { // SVC 已存在 - return svc; + return svc; } } } @@ -182,22 +178,22 @@ public class K8sClientUtil { /** * 创建k8s PVC * - * @param namespace 命名空间 - * @param pvcName 服务名称 + * @param namespace 命名空间 + * @param pvcName 服务名称 * @return 创建成功的service对象 */ - public V1PersistentVolumeClaim createPvc(String namespace, String pvcName ,String storage, String storageClassName){ + public V1PersistentVolumeClaim createPvc(String namespace, String pvcName, String storage, String storageClassName) { CoreV1Api api = new CoreV1Api(apiClient); V1PersistentVolumeClaimList pvcList = null; try { - pvcList = api.listNamespacedPersistentVolumeClaim(namespace, null,null, null, null, null,null,null, null, null, null); + pvcList = api.listNamespacedPersistentVolumeClaim(namespace, null, null, null, null, null, null, null, null, null, null); } catch (ApiException e) { log.error("获取 PVC 异常:", e); } - if (pvcList!=null) { + if (pvcList != null) { for (V1PersistentVolumeClaim pvc1 : pvcList.getItems()) { - if (StringUtils.equals(pvc1.getMetadata().getName(),pvcName)) { + if (StringUtils.equals(pvc1.getMetadata().getName(), pvcName)) { // PVC 已存在 return pvc1; } @@ -232,16 +228,17 @@ public class K8sClientUtil { /** * 创建k8s 临时POD + * * @param podName pod name - * @param namespace 命名空间 - * @param port port + * @param namespace 命名空间 + * @param port port * @param mountPath 映射路径 - * @param pvc 存储 - * @param image 镜像 + * @param pvc 存储 + * @param image 镜像 * @return 创建成功的pod,的nodePort端口 */ - public Integer createPod(String podName, String namespace, Integer port ,String mountPath, V1PersistentVolumeClaim pvc, String image){ + public Integer createPod(String podName, String namespace, Integer port, String mountPath, V1PersistentVolumeClaim pvc, String image) { Map selector = new LinkedHashMap(); selector.put("k8s-jupyter", podName); @@ -253,7 +250,7 @@ public class K8sClientUtil { } catch (ApiException e) { log.error("获取 POD 异常:", e); } - if (v1PodList!=null) { + if (v1PodList != null) { for (V1Pod pod1 : v1PodList.getItems()) { if (StringUtils.equals(pod1.getMetadata().getName(), podName)) { // PVC 已存在 @@ -301,17 +298,18 @@ public class K8sClientUtil { /** * 创建k8s 临时POD + * * @param podName pod name - * @param namespace 命名空间 - * @param port port + * @param namespace 命名空间 + * @param port port * @param mountPath 映射路径 - * @param subPath pvc子路径 - * @param pvcName 存储名 - * @param image 镜像 + * @param subPath pvc子路径 + * @param pvcName 存储名 + * @param image 镜像 * @return 创建成功的pod,的nodePort端口 */ - public Integer createPodWithSubPath(String podName, String namespace, Integer port ,String mountPath,String subPath,String pvcName, String image){ + public Integer createPodWithSubPath(String podName, String namespace, Integer port, String mountPath, String subPath, String pvcName, String image) { Map selector = new LinkedHashMap(); selector.put("k8s-jupyter", podName); @@ -323,7 +321,7 @@ public class K8sClientUtil { } catch (ApiException e) { log.error("获取 POD 异常:", e); } - if (v1PodList!=null) { + if (v1PodList != null) { for (V1Pod pod1 : v1PodList.getItems()) { if (StringUtils.equals(pod1.getMetadata().getName(), podName)) { // PVC 已存在 @@ -381,7 +379,7 @@ public class K8sClientUtil { } // 创建配置好的Pod - public Integer createConfiguredPod(String podName, String namespace, Integer port, String mountPath, V1PersistentVolumeClaim pvc, String image, String dataPvcName, String datasetPath, String modelPath) { + public Integer createConfiguredPod(String podName, String namespace, Integer port, String mountPath, V1PersistentVolumeClaim pvc, String image, String computingResource, String dataPvcName, String datasetPath, String modelPath) { //设置选择节点,pod反亲和性 Map selector = new LinkedHashMap<>(); @@ -473,7 +471,9 @@ public class K8sClientUtil { try { pod = api.createNamespacedPod(namespace, pod, null, null, null); String nodeName = getNodeName(podName, namespace); - computingResourceDao.updateUsedStateByNode(nodeName, Constant.Used_State_used); + if (Constant.Computing_Resource_GPU.equals(computingResource)) { + computingResourceDao.updateUsedStateByNode(nodeName, Constant.Used_State_used); + } } catch (ApiException e) { log.error("创建pod异常:" + e.getResponseBody(), e); } catch (Exception e) { @@ -485,14 +485,12 @@ public class K8sClientUtil { } - - /** * 根据获取namespace,deploymentName的Pod Name * * @return podList */ - public V1Pod getNSPodList(String namespace,String deploymentName) throws Exception { + public V1Pod getNSPodList(String namespace, String deploymentName) throws Exception { // new a CoreV1Api CoreV1Api api = new CoreV1Api(apiClient); V1PodList v1PodList = null; @@ -513,12 +511,12 @@ public class K8sClientUtil { return null; } - public String executeCommand(V1Pod item, String command) { + public String executeCommand(V1Pod item, String command) { try { // 创建API实例 // 创建Exec实例 Exec exec = new Exec(apiClient); - String[] cmd = { "/bin/sh", "-c", command}; + String[] cmd = {"/bin/sh", "-c", command}; Process proc = exec.exec(item, cmd, false); // 读取输出 BufferedReader reader = new BufferedReader(new InputStreamReader(proc.getInputStream())); @@ -543,10 +541,11 @@ public class K8sClientUtil { /** * 根据Pod的名称和Namespace查询Pod的状态 - * @param podName Pod的名称 + * + * @param podName Pod的名称 * @param namespace Pod所在的Namespace */ - public String getPodStatus(String podName, String namespace) throws Exception { + public String getPodStatus(String podName, String namespace) throws Exception { CoreV1Api api = new CoreV1Api(apiClient); V1Pod pod = api.readNamespacedPod(podName, namespace, null, null, null); return pod.getStatus().getPhase(); @@ -554,14 +553,15 @@ public class K8sClientUtil { /** * 根据Pod的名称和Namespace查询Pod的容器信息 - * @param podName Pod的名称 + * + * @param podName Pod的名称 * @param namespace Pod所在的Namespace */ public String getPodContainerId(String podName, String namespace) throws Exception { CoreV1Api api = new CoreV1Api(apiClient); V1Pod pod = api.readNamespacedPod(podName, namespace, null, null, null); - if(pod.getStatus().getContainerStatuses().size() !=1){ + if (pod.getStatus().getContainerStatuses().size() != 1) { throw new RuntimeException("容器错误"); } String containerId = pod.getStatus().getContainerStatuses().get(0).getContainerID().split("//")[1]; @@ -580,10 +580,10 @@ public class K8sClientUtil { return pod.getSpec().getNodeName(); } - public String getPodLogs(String podName,String namespace,String container,int line) { + public String getPodLogs(String podName, String namespace, String container, int line) { CoreV1Api api = new CoreV1Api(apiClient); try { - String log = api.readNamespacedPodLog(podName, namespace, StringUtils.isEmpty(container)?null:container, null, null, null, null,null, null, line, null); + String log = api.readNamespacedPodLog(podName, namespace, StringUtils.isEmpty(container) ? null : container, null, null, null, null, null, null, line, null); return log; } catch (ApiException e) { throw new RuntimeException("获取Pod日志异常", e); @@ -592,7 +592,7 @@ public class K8sClientUtil { } - public V1Pod createPodWithEnv(String podName,String namespace,String proxyUrl ,String mountPath,String pvcName, String image){ + public V1Pod createPodWithEnv(String podName, String namespace, String proxyUrl, String mountPath, String pvcName, String image) { CoreV1Api api = new CoreV1Api(apiClient); V1PodList v1PodList = null; V1Pod pod = new V1PodBuilder() @@ -636,7 +636,7 @@ public class K8sClientUtil { /** * 删除 Pod * - * @param podName Pod 名称 + * @param podName Pod 名称 * @param namespace 命名空间 * @throws ApiException 异常 */ @@ -655,7 +655,7 @@ public class K8sClientUtil { /** * 删除 Service * - * @param svcName Service 名称 + * @param svcName Service 名称 * @param namespace 命名空间 * @throws ApiException 异常 */ @@ -674,7 +674,7 @@ public class K8sClientUtil { /** * 检查 Pod 是否存在 * - * @param podName Pod 名称 + * @param podName Pod 名称 * @param namespace 命名空间 * @return 是否存在 * @throws ApiException 异常 @@ -682,7 +682,7 @@ public class K8sClientUtil { public boolean checkPodExists(String podName, String namespace) throws ApiException { CoreV1Api api = new CoreV1Api(apiClient); try { - api.readNamespacedPod(podName, namespace, null,false,false); + api.readNamespacedPod(podName, namespace, null, false, false); return true; } catch (ApiException e) { if (e.getCode() == 404) { From 9ac99957ed1f68e4ce83de5f0ddf1aa06826c107 Mon Sep 17 00:00:00 2001 From: chenzhihang <709011834@qq.com> Date: Thu, 29 Aug 2024 15:17:10 +0800 Subject: [PATCH 03/12] =?UTF-8?q?1=E3=80=81=E6=B7=BB=E5=8A=A0=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E9=85=8D=E7=BD=AEsshkey=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/ruoyi/platform/domain/CodeConfig.java | 4 ++++ .../mapper/managementPlatform/CodeConfigDaoMapper.xml | 11 +++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/CodeConfig.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/CodeConfig.java index 957dabe..67d5533 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/CodeConfig.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/CodeConfig.java @@ -36,6 +36,9 @@ public class CodeConfig implements Serializable { @ApiModelProperty(value = "Git密码") private String gitPassword; + @ApiModelProperty(value = "SSH Key") + private String sshKey; + private String createBy; /** * 创建时间 @@ -53,4 +56,5 @@ public class CodeConfig implements Serializable { * 状态,0失效1生效 */ private Integer state; + } diff --git a/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/CodeConfigDaoMapper.xml b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/CodeConfigDaoMapper.xml index 64c72f8..815e0ac 100644 --- a/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/CodeConfigDaoMapper.xml +++ b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/CodeConfigDaoMapper.xml @@ -3,8 +3,9 @@ - insert into code_config(code_repo_name, code_repo_vis, git_url, git_branch, verify_mode, git_user_name, git_password, create_by, create_time, update_by, update_time) - values(#{codeConfig.codeRepoName}, #{codeConfig.codeRepoVis}, #{codeConfig.gitUrl}, #{codeConfig.gitBranch}, #{codeConfig.verifyMode}, #{codeConfig.gitUserName}, #{codeConfig.gitPassword}, #{codeConfig.createBy}, #{codeConfig.createTime}, #{codeConfig.updateBy}, #{codeConfig.updateTime}) + insert into code_config(code_repo_name, code_repo_vis, git_url, git_branch, verify_mode, git_user_name, git_password,ssh_key, create_by, create_time, update_by, update_time) + values(#{codeConfig.codeRepoName}, #{codeConfig.codeRepoVis}, #{codeConfig.gitUrl}, #{codeConfig.gitBranch}, #{codeConfig.verifyMode}, #{codeConfig.gitUserName}, #{codeConfig.gitPassword}, + #{codeConfig.sshKey}, #{codeConfig.createBy}, #{codeConfig.createTime}, #{codeConfig.updateBy}, #{codeConfig.updateTime}) @@ -28,6 +29,12 @@ git_user_name = #{codeConfig.gitUserName}, + + git_password = #{codeConfig.gitPassword}, + + + ssh_key = #{codeConfig.sshKey}, + create_by = #{codeConfig.createBy}, From 85f06999b8be06bcab7ae54d2f307f8262788889 Mon Sep 17 00:00:00 2001 From: chenzhihang <709011834@qq.com> Date: Thu, 29 Aug 2024 15:59:52 +0800 Subject: [PATCH 04/12] =?UTF-8?q?1=E3=80=81=E4=BF=AE=E6=94=B9=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../codeConfig/CodeConfigController.java | 6 ++- .../com/ruoyi/platform/domain/CodeConfig.java | 37 +++++++++---------- .../CodeConfigDaoMapper.xml | 6 +-- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/codeConfig/CodeConfigController.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/codeConfig/CodeConfigController.java index 6a59902..44bc217 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/codeConfig/CodeConfigController.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/codeConfig/CodeConfigController.java @@ -28,8 +28,12 @@ public class CodeConfigController extends BaseController { * @return 查询结果 */ @GetMapping - public GenericsAjaxResult> queryByPage(CodeConfig codeConfig, int page, int size) { + public GenericsAjaxResult> queryByPage( @RequestParam("page")int page, + @RequestParam("size") int size, + @RequestParam(value = "code_repo_name") String codeRepoName) { PageRequest pageRequest = PageRequest.of(page,size); + CodeConfig codeConfig = new CodeConfig(); + codeConfig.setCodeRepoName(codeRepoName); return genericsSuccess(this.codeConfigService.queryByPage(codeConfig, pageRequest)); } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/CodeConfig.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/CodeConfig.java index 67d5533..e5a0c68 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/CodeConfig.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/CodeConfig.java @@ -15,46 +15,43 @@ public class CodeConfig implements Serializable { private Long id; - @ApiModelProperty(value = "代码仓库名称") + @ApiModelProperty(name = "code_repo_name",value = "代码仓库名称") private String codeRepoName; - @ApiModelProperty(value = "代码仓库可见性(1-公开,0-私有)") + @ApiModelProperty(name = "code_repo_vis", value = "代码仓库可见性(1-公开,0-私有)") private Integer codeRepoVis; - @ApiModelProperty(value = "Git地址") + @ApiModelProperty(name = "git_url", value = "Git地址") private String gitUrl; - @ApiModelProperty(value = "代码分支/Tag") + @ApiModelProperty(name = "git_branch", value = "代码分支/Tag") private String gitBranch; - @ApiModelProperty(value = "验证方式(0-用户名密码,1-SSH-Key)") + @ApiModelProperty(name = "verify_mode", value = "验证方式(0-用户名密码,1-SSH-Key)") private Integer verifyMode; - @ApiModelProperty(value = "Git用户名") + @ApiModelProperty(name = "git_user_name", value = "Git用户名") private String gitUserName; - @ApiModelProperty(value = "Git密码") + @ApiModelProperty(name = "git_password", value = "Git密码") private String gitPassword; - @ApiModelProperty(value = "SSH Key") + @ApiModelProperty(name = "ssh_key",value = "SSH Key") private String sshKey; + @ApiModelProperty(name = "create_by", value = "创建者") private String createBy; - /** - * 创建时间 - */ + + @ApiModelProperty(name = "create_time", value = "创建时间") private Date createTime; - /** - * 更新者 - */ + + @ApiModelProperty(name = "update_by", value = "更新者") private String updateBy; - /** - * 更新时间 - */ + + @ApiModelProperty(name = "update_time", value = "更新时间") private Date updateTime; - /** - * 状态,0失效1生效 - */ + + @ApiModelProperty(name = "state", value = "状态,0失效1生效") private Integer state; } diff --git a/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/CodeConfigDaoMapper.xml b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/CodeConfigDaoMapper.xml index 815e0ac..f714f9e 100644 --- a/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/CodeConfigDaoMapper.xml +++ b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/CodeConfigDaoMapper.xml @@ -44,12 +44,10 @@ update_by = #{codeConfig.updateBy}, - - update_time = #{codeConfig.updateTime}, - state = #{codeConfig.state}, + update_time = sysdate() where id = #{codeConfig.id} @@ -81,7 +79,7 @@ and id = #{codeConfig.id} - and code_repo_name = #{codeConfig.codeRepoName} + and code_repo_name LIKE CONCAT('%', #{codeConfig.codeRepoName}, '%') and code_repo_vis = #{codeConfig.codeRepoVis} From f24e764aaabf7e93ea070cec45a70c3d312395ef Mon Sep 17 00:00:00 2001 From: chenzhihang <709011834@qq.com> Date: Thu, 29 Aug 2024 16:11:52 +0800 Subject: [PATCH 05/12] =?UTF-8?q?1=E3=80=81=E7=94=A8=E6=88=B7=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0gitLink=E7=94=A8=E6=88=B7=E5=90=8D=E5=AF=86=E7=A0=81?= =?UTF-8?q?=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ruoyi/system/api/domain/SysUser.java | 279 ++++++++++-------- .../system/controller/SysUserController.java | 140 ++++----- .../ruoyi/system/mapper/SysUserMapper.java | 2 + .../ruoyi/system/service/ISysUserService.java | 2 + .../service/impl/SysUserServiceImpl.java | 11 + .../resources/mapper/system/SysUserMapper.xml | 110 ++++--- 6 files changed, 294 insertions(+), 250 deletions(-) diff --git a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/domain/SysUser.java b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/domain/SysUser.java index a64751a..fc1aa78 100644 --- a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/domain/SysUser.java +++ b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/domain/SysUser.java @@ -1,323 +1,344 @@ package com.ruoyi.system.api.domain; -import java.util.Date; -import java.util.List; -import javax.validation.constraints.*; -import org.apache.commons.lang3.builder.ToStringBuilder; -import org.apache.commons.lang3.builder.ToStringStyle; import com.ruoyi.common.core.annotation.Excel; import com.ruoyi.common.core.annotation.Excel.ColumnType; import com.ruoyi.common.core.annotation.Excel.Type; import com.ruoyi.common.core.annotation.Excels; import com.ruoyi.common.core.web.domain.BaseEntity; import com.ruoyi.common.core.xss.Xss; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import javax.validation.constraints.Email; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.Size; +import java.util.Date; +import java.util.List; /** * 用户对象 sys_user - * + * * @author ruoyi */ -public class SysUser extends BaseEntity -{ +public class SysUser extends BaseEntity { private static final long serialVersionUID = 1L; - /** 用户ID */ + /** + * 用户ID + */ @Excel(name = "用户序号", cellType = ColumnType.NUMERIC, prompt = "用户编号") private Long userId; - /** 部门ID */ + /** + * 部门ID + */ @Excel(name = "部门编号", type = Type.IMPORT) private Long deptId; - /** 用户账号 */ + /** + * 用户账号 + */ @Excel(name = "登录名称") private String userName; - /** 用户昵称 */ + /** + * 用户昵称 + */ @Excel(name = "用户名称") private String nickName; - /** 用户邮箱 */ + /** + * 用户邮箱 + */ @Excel(name = "用户邮箱") private String email; - /** 手机号码 */ + /** + * 手机号码 + */ @Excel(name = "手机号码") private String phonenumber; - /** 用户性别 */ + /** + * 用户性别 + */ @Excel(name = "用户性别", readConverterExp = "0=男,1=女,2=未知") private String sex; - /** 用户头像 */ + /** + * 用户头像 + */ private String avatar; - /** 密码 */ + /** + * 密码 + */ private String password; - /** 帐号状态(0正常 1停用) */ + /** + * 帐号状态(0正常 1停用) + */ @Excel(name = "帐号状态", readConverterExp = "0=正常,1=停用") private String status; - /** 删除标志(0代表存在 2代表删除) */ + /** + * 删除标志(0代表存在 2代表删除) + */ private String delFlag; - /** 最后登录IP */ + /** + * 最后登录IP + */ @Excel(name = "最后登录IP", type = Type.EXPORT) private String loginIp; - /** 最后登录时间 */ + /** + * 最后登录时间 + */ @Excel(name = "最后登录时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss", type = Type.EXPORT) private Date loginDate; - /** 部门对象 */ + /** + * 部门对象 + */ @Excels({ - @Excel(name = "部门名称", targetAttr = "deptName", type = Type.EXPORT), - @Excel(name = "部门负责人", targetAttr = "leader", type = Type.EXPORT) + @Excel(name = "部门名称", targetAttr = "deptName", type = Type.EXPORT), + @Excel(name = "部门负责人", targetAttr = "leader", type = Type.EXPORT) }) private SysDept dept; - /** 角色对象 */ + /** + * 角色对象 + */ private List roles; - /** 角色组 */ + /** + * 角色组 + */ private Long[] roleIds; - /** 岗位组 */ + /** + * 岗位组 + */ private Long[] postIds; - /** 角色ID */ + /** + * 角色ID + */ private Long roleId; - public SysUser() - { + private String gitLinkUsername; + + private String gitLinkPassword; + + public SysUser() { } - public SysUser(Long userId) - { + public SysUser(Long userId) { this.userId = userId; } - public Long getUserId() - { + public Long getUserId() { return userId; } - public void setUserId(Long userId) - { + public void setUserId(Long userId) { this.userId = userId; } - public boolean isAdmin() - { + public boolean isAdmin() { return isAdmin(this.userId); } - public static boolean isAdmin(Long userId) - { + public static boolean isAdmin(Long userId) { return userId != null && 1L == userId; } - public Long getDeptId() - { + public Long getDeptId() { return deptId; } - public void setDeptId(Long deptId) - { + public void setDeptId(Long deptId) { this.deptId = deptId; } @Xss(message = "用户昵称不能包含脚本字符") @Size(min = 0, max = 30, message = "用户昵称长度不能超过30个字符") - public String getNickName() - { + public String getNickName() { return nickName; } - public void setNickName(String nickName) - { + public void setNickName(String nickName) { this.nickName = nickName; } @Xss(message = "用户账号不能包含脚本字符") @NotBlank(message = "用户账号不能为空") @Size(min = 0, max = 30, message = "用户账号长度不能超过30个字符") - public String getUserName() - { + public String getUserName() { return userName; } - public void setUserName(String userName) - { + public void setUserName(String userName) { this.userName = userName; } @Email(message = "邮箱格式不正确") @Size(min = 0, max = 50, message = "邮箱长度不能超过50个字符") - public String getEmail() - { + public String getEmail() { return email; } - public void setEmail(String email) - { + public void setEmail(String email) { this.email = email; } @Size(min = 0, max = 11, message = "手机号码长度不能超过11个字符") - public String getPhonenumber() - { + public String getPhonenumber() { return phonenumber; } - public void setPhonenumber(String phonenumber) - { + public void setPhonenumber(String phonenumber) { this.phonenumber = phonenumber; } - public String getSex() - { + public String getSex() { return sex; } - public void setSex(String sex) - { + public void setSex(String sex) { this.sex = sex; } - public String getAvatar() - { + public String getAvatar() { return avatar; } - public void setAvatar(String avatar) - { + public void setAvatar(String avatar) { this.avatar = avatar; } - public String getPassword() - { + public String getPassword() { return password; } - public void setPassword(String password) - { + public void setPassword(String password) { this.password = password; } - public String getStatus() - { + public String getStatus() { return status; } - public void setStatus(String status) - { + public void setStatus(String status) { this.status = status; } - public String getDelFlag() - { + public String getDelFlag() { return delFlag; } - public void setDelFlag(String delFlag) - { + public void setDelFlag(String delFlag) { this.delFlag = delFlag; } - public String getLoginIp() - { + public String getLoginIp() { return loginIp; } - public void setLoginIp(String loginIp) - { + public void setLoginIp(String loginIp) { this.loginIp = loginIp; } - public Date getLoginDate() - { + public Date getLoginDate() { return loginDate; } - public void setLoginDate(Date loginDate) - { + public void setLoginDate(Date loginDate) { this.loginDate = loginDate; } - public SysDept getDept() - { + public SysDept getDept() { return dept; } - public void setDept(SysDept dept) - { + public void setDept(SysDept dept) { this.dept = dept; } - public List getRoles() - { + public List getRoles() { return roles; } - public void setRoles(List roles) - { + public void setRoles(List roles) { this.roles = roles; } - public Long[] getRoleIds() - { + public Long[] getRoleIds() { return roleIds; } - public void setRoleIds(Long[] roleIds) - { + public void setRoleIds(Long[] roleIds) { this.roleIds = roleIds; } - public Long[] getPostIds() - { + public Long[] getPostIds() { return postIds; } - public void setPostIds(Long[] postIds) - { + public void setPostIds(Long[] postIds) { this.postIds = postIds; } - public Long getRoleId() - { + public Long getRoleId() { return roleId; } - public void setRoleId(Long roleId) - { + public void setRoleId(Long roleId) { this.roleId = roleId; } + + public void setGitLinkUsername(String gitLinkUsername) { + this.gitLinkUsername = gitLinkUsername; + } + + public String getGitLinkUsername() { + return gitLinkUsername; + } + + public void setGitLinkPassword(String gitLinkPassword) { + this.gitLinkPassword = gitLinkPassword; + } + + public String getGitLinkPassword() { + return gitLinkPassword; + } + @Override public String toString() { - return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) - .append("userId", getUserId()) - .append("deptId", getDeptId()) - .append("userName", getUserName()) - .append("nickName", getNickName()) - .append("email", getEmail()) - .append("phonenumber", getPhonenumber()) - .append("sex", getSex()) - .append("avatar", getAvatar()) - .append("password", getPassword()) - .append("status", getStatus()) - .append("delFlag", getDelFlag()) - .append("loginIp", getLoginIp()) - .append("loginDate", getLoginDate()) - .append("createBy", getCreateBy()) - .append("createTime", getCreateTime()) - .append("updateBy", getUpdateBy()) - .append("updateTime", getUpdateTime()) - .append("remark", getRemark()) - .append("dept", getDept()) - .toString(); + return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) + .append("userId", getUserId()) + .append("deptId", getDeptId()) + .append("userName", getUserName()) + .append("nickName", getNickName()) + .append("email", getEmail()) + .append("phonenumber", getPhonenumber()) + .append("sex", getSex()) + .append("avatar", getAvatar()) + .append("password", getPassword()) + .append("status", getStatus()) + .append("delFlag", getDelFlag()) + .append("loginIp", getLoginIp()) + .append("loginDate", getLoginDate()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .append("remark", getRemark()) + .append("dept", getDept()) + .append("gitLinkUsername", getGitLinkUsername()) + .append("gitLinkPassword", getGitLinkPassword()) + .toString(); } } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysUserController.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysUserController.java index bcbbb6a..ed46bc7 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysUserController.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysUserController.java @@ -1,22 +1,5 @@ package com.ruoyi.system.controller; -import java.io.IOException; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; -import javax.servlet.http.HttpServletResponse; -import org.apache.commons.lang3.ArrayUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.multipart.MultipartFile; import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.core.utils.poi.ExcelUtil; @@ -32,22 +15,27 @@ import com.ruoyi.system.api.domain.SysDept; import com.ruoyi.system.api.domain.SysRole; import com.ruoyi.system.api.domain.SysUser; import com.ruoyi.system.api.model.LoginUser; -import com.ruoyi.system.service.ISysConfigService; -import com.ruoyi.system.service.ISysDeptService; -import com.ruoyi.system.service.ISysPermissionService; -import com.ruoyi.system.service.ISysPostService; -import com.ruoyi.system.service.ISysRoleService; -import com.ruoyi.system.service.ISysUserService; +import com.ruoyi.system.service.*; +import org.apache.commons.lang3.ArrayUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; /** * 用户信息 - * + * * @author ruoyi */ @RestController @RequestMapping("/user") -public class SysUserController extends BaseController -{ +public class SysUserController extends BaseController { @Autowired private ISysUserService userService; @@ -71,8 +59,7 @@ public class SysUserController extends BaseController */ @RequiresPermissions("system:user:list") @GetMapping("/list") - public TableDataInfo list(SysUser user) - { + public TableDataInfo list(SysUser user) { startPage(); List list = userService.selectUserList(user); return getDataTable(list); @@ -81,8 +68,7 @@ public class SysUserController extends BaseController @Log(title = "用户管理", businessType = BusinessType.EXPORT) @RequiresPermissions("system:user:export") @PostMapping("/export") - public void export(HttpServletResponse response, SysUser user) - { + public void export(HttpServletResponse response, SysUser user) { List list = userService.selectUserList(user); ExcelUtil util = new ExcelUtil(SysUser.class); util.exportExcel(response, list, "用户数据"); @@ -91,8 +77,7 @@ public class SysUserController extends BaseController @Log(title = "用户管理", businessType = BusinessType.IMPORT) @RequiresPermissions("system:user:import") @PostMapping("/importData") - public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception - { + public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception { ExcelUtil util = new ExcelUtil(SysUser.class); List userList = util.importExcel(file.getInputStream()); String operName = SecurityUtils.getUsername(); @@ -101,8 +86,7 @@ public class SysUserController extends BaseController } @PostMapping("/importTemplate") - public void importTemplate(HttpServletResponse response) throws IOException - { + public void importTemplate(HttpServletResponse response) throws IOException { ExcelUtil util = new ExcelUtil(SysUser.class); util.importTemplateExcel(response, "用户数据"); } @@ -112,11 +96,9 @@ public class SysUserController extends BaseController */ @InnerAuth @GetMapping("/info/{username}") - public R info(@PathVariable("username") String username) - { + public R info(@PathVariable("username") String username) { SysUser sysUser = userService.selectUserByUserName(username); - if (StringUtils.isNull(sysUser)) - { + if (StringUtils.isNull(sysUser)) { return R.fail("用户名或密码错误"); } // 角色集合 @@ -135,15 +117,12 @@ public class SysUserController extends BaseController */ @InnerAuth @PostMapping("/register") - public R register(@RequestBody SysUser sysUser) - { + public R register(@RequestBody SysUser sysUser) { String username = sysUser.getUserName(); - if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser")))) - { + if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser")))) { return R.fail("当前系统没有开启注册功能!"); } - if (!userService.checkUserNameUnique(sysUser)) - { + if (!userService.checkUserNameUnique(sysUser)) { return R.fail("保存用户'" + username + "'失败,注册账号已存在"); } return R.ok(userService.registerUser(sysUser)); @@ -151,12 +130,11 @@ public class SysUserController extends BaseController /** * 获取用户信息 - * + * * @return 用户信息 */ @GetMapping("getInfo") - public AjaxResult getInfo() - { + public AjaxResult getInfo() { SysUser user = userService.selectUserById(SecurityUtils.getUserId()); // 角色集合 Set roles = permissionService.getRolePermission(user); @@ -173,16 +151,14 @@ public class SysUserController extends BaseController * 根据用户编号获取详细信息 */ @RequiresPermissions("system:user:query") - @GetMapping(value = { "/", "/{userId}" }) - public AjaxResult getInfo(@PathVariable(value = "userId", required = false) Long userId) - { + @GetMapping(value = {"/", "/{userId}"}) + public AjaxResult getInfo(@PathVariable(value = "userId", required = false) Long userId) { userService.checkUserDataScope(userId); AjaxResult ajax = AjaxResult.success(); List roles = roleService.selectRoleAll(); ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList())); ajax.put("posts", postService.selectPostAll()); - if (StringUtils.isNotNull(userId)) - { + if (StringUtils.isNotNull(userId)) { SysUser sysUser = userService.selectUserById(userId); ajax.put(AjaxResult.DATA_TAG, sysUser); ajax.put("postIds", postService.selectPostListByUserId(userId)); @@ -197,22 +173,19 @@ public class SysUserController extends BaseController @RequiresPermissions("system:user:add") @Log(title = "用户管理", businessType = BusinessType.INSERT) @PostMapping - public AjaxResult add(@Validated @RequestBody SysUser user) - { - if (!userService.checkUserNameUnique(user)) - { + public AjaxResult add(@Validated @RequestBody SysUser user) { + if (!userService.checkUserNameUnique(user)) { return error("新增用户'" + user.getUserName() + "'失败,登录账号已存在"); - } - else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) - { + } else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) { return error("新增用户'" + user.getUserName() + "'失败,手机号码已存在"); - } - else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) - { + } else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) { return error("新增用户'" + user.getUserName() + "'失败,邮箱账号已存在"); + } else if (StringUtils.isNotEmpty(user.getGitLinkUsername()) && !userService.checktGitLinkUsernameUnique(user)) { + return error("新增用户'" + user.getUserName() + "'失败,gitLink用户名已存在"); } user.setCreateBy(SecurityUtils.getUsername()); user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); + user.setGitLinkPassword(SecurityUtils.encryptPassword(user.getGitLinkPassword())); return toAjax(userService.insertUser(user)); } @@ -222,23 +195,25 @@ public class SysUserController extends BaseController @RequiresPermissions("system:user:edit") @Log(title = "用户管理", businessType = BusinessType.UPDATE) @PutMapping - public AjaxResult edit(@Validated @RequestBody SysUser user) - { + public AjaxResult edit(@Validated @RequestBody SysUser user) { userService.checkUserAllowed(user); userService.checkUserDataScope(user.getUserId()); - if (!userService.checkUserNameUnique(user)) - { + if (!userService.checkUserNameUnique(user)) { return error("修改用户'" + user.getUserName() + "'失败,登录账号已存在"); - } - else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) - { + } else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) { return error("修改用户'" + user.getUserName() + "'失败,手机号码已存在"); - } - else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) - { + } else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) { return error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在"); + } else if (StringUtils.isNotEmpty(user.getGitLinkUsername()) && !userService.checktGitLinkUsernameUnique(user)) { + return error("新增用户'" + user.getUserName() + "'失败,gitLink用户名已存在"); } user.setUpdateBy(SecurityUtils.getUsername()); + if(StringUtils.isNotEmpty(user.getPassword())){ + user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); + } + if(StringUtils.isNotEmpty(user.getGitLinkPassword())){ + user.setGitLinkPassword(SecurityUtils.encryptPassword(user.getGitLinkPassword())); + } return toAjax(userService.updateUser(user)); } @@ -248,10 +223,8 @@ public class SysUserController extends BaseController @RequiresPermissions("system:user:remove") @Log(title = "用户管理", businessType = BusinessType.DELETE) @DeleteMapping("/{userIds}") - public AjaxResult remove(@PathVariable Long[] userIds) - { - if (ArrayUtils.contains(userIds, SecurityUtils.getUserId())) - { + public AjaxResult remove(@PathVariable Long[] userIds) { + if (ArrayUtils.contains(userIds, SecurityUtils.getUserId())) { return error("当前用户不能删除"); } return toAjax(userService.deleteUserByIds(userIds)); @@ -263,8 +236,7 @@ public class SysUserController extends BaseController @RequiresPermissions("system:user:edit") @Log(title = "用户管理", businessType = BusinessType.UPDATE) @PutMapping("/resetPwd") - public AjaxResult resetPwd(@RequestBody SysUser user) - { + public AjaxResult resetPwd(@RequestBody SysUser user) { userService.checkUserAllowed(user); userService.checkUserDataScope(user.getUserId()); user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); @@ -278,8 +250,7 @@ public class SysUserController extends BaseController @RequiresPermissions("system:user:edit") @Log(title = "用户管理", businessType = BusinessType.UPDATE) @PutMapping("/changeStatus") - public AjaxResult changeStatus(@RequestBody SysUser user) - { + public AjaxResult changeStatus(@RequestBody SysUser user) { userService.checkUserAllowed(user); userService.checkUserDataScope(user.getUserId()); user.setUpdateBy(SecurityUtils.getUsername()); @@ -291,8 +262,7 @@ public class SysUserController extends BaseController */ @RequiresPermissions("system:user:query") @GetMapping("/authRole/{userId}") - public AjaxResult authRole(@PathVariable("userId") Long userId) - { + public AjaxResult authRole(@PathVariable("userId") Long userId) { AjaxResult ajax = AjaxResult.success(); SysUser user = userService.selectUserById(userId); List roles = roleService.selectRolesByUserId(userId); @@ -307,8 +277,7 @@ public class SysUserController extends BaseController @RequiresPermissions("system:user:edit") @Log(title = "用户管理", businessType = BusinessType.GRANT) @PutMapping("/authRole") - public AjaxResult insertAuthRole(Long userId, Long[] roleIds) - { + public AjaxResult insertAuthRole(Long userId, Long[] roleIds) { userService.checkUserDataScope(userId); userService.insertUserAuth(userId, roleIds); return success(); @@ -319,8 +288,7 @@ public class SysUserController extends BaseController */ @RequiresPermissions("system:user:list") @GetMapping("/deptTree") - public AjaxResult deptTree(SysDept dept) - { + public AjaxResult deptTree(SysDept dept) { return success(deptService.selectDeptTreeList(dept)); } } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java index 2624ad8..58a622e 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java @@ -124,4 +124,6 @@ public interface SysUserMapper * @return 结果 */ public SysUser checkEmailUnique(String email); + + public SysUser checktGitLinkUsernameUnique(String gitLinkUsername); } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java index 8f30fa3..e1c718a 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java @@ -90,6 +90,8 @@ public interface ISysUserService */ public boolean checkEmailUnique(SysUser user); + public boolean checktGitLinkUsernameUnique(SysUser user); + /** * 校验用户是否允许操作 * diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java index ec165dc..8ea6cb4 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java @@ -212,6 +212,17 @@ public class SysUserServiceImpl implements ISysUserService return UserConstants.UNIQUE; } + @Override + public boolean checktGitLinkUsernameUnique(SysUser user) { + Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId(); + SysUser info = userMapper.checktGitLinkUsernameUnique(user.getGitLinkUsername()); + if(StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue()) + { + return UserConstants.NOT_UNIQUE; + } + return UserConstants.UNIQUE; + } + /** * 校验用户是否允许操作 * diff --git a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml index eca3694..b7c9797 100644 --- a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml +++ b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml @@ -47,43 +47,74 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, - d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.status as dept_status, - r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status + select u.user_id, + u.dept_id, + u.user_name, + u.nick_name, + u.email, + u.avatar, + u.phonenumber, + u.password, + u.git_link_username, + u.git_link_password, + u.sex, + u.status, + u.del_flag, + u.login_ip, + u.login_date, + u.create_by, + u.create_time, + u.remark, + d.dept_id, + d.parent_id, + d.ancestors, + d.dept_name, + d.order_num, + d.leader, + d.status as dept_status, + r.role_id, + r.role_name, + r.role_key, + r.role_sort, + r.data_scope, + r.status as role_status from sys_user u - left join sys_dept d on u.dept_id = d.dept_id - left join sys_user_role ur on u.user_id = ur.user_id - left join sys_role r on r.role_id = ur.role_id + left join sys_dept d on u.dept_id = d.dept_id + left join sys_user_role ur on u.user_id = ur.user_id + left join sys_role r on r.role_id = ur.role_id + select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.sex, u.status, u.git_link_username, + u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader + from sys_user u + left join sys_dept d on u.dept_id = d.dept_id + where u.del_flag = '0' + + AND u.user_id = #{userId} + + + AND u.user_name like concat('%', #{userName}, '%') + + + AND u.status = #{status} + + + AND u.phonenumber like concat('%', #{phonenumber}, '%') + + + AND date_format(u.create_time,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d') + + + AND date_format(u.create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d') + + + AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE find_in_set(#{deptId}, + ancestors) )) + + + ${params.dataScope} + select user_id, email from sys_user where email = #{email} and del_flag = '0' limit 1 - - + + + + insert into sys_user( user_id, dept_id, @@ -190,6 +228,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" login_date = #{loginDate}, update_by = #{updateBy}, remark = #{remark}, + git_link_username = #{gitLinkUsername}, + git_link_password = #{gitLinkPassword}, update_time = sysdate() where user_id = #{userId} From e37dd1d0b5de50c7d0c215c9ef60aae79d0c0073 Mon Sep 17 00:00:00 2001 From: chenzhihang <709011834@qq.com> Date: Thu, 29 Aug 2024 16:17:01 +0800 Subject: [PATCH 06/12] =?UTF-8?q?1=E3=80=81=E4=BF=AE=E6=94=B9=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E9=85=8D=E7=BD=AEbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../codeConfig/CodeConfigController.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/codeConfig/CodeConfigController.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/codeConfig/CodeConfigController.java index 44bc217..058188b 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/codeConfig/CodeConfigController.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/codeConfig/CodeConfigController.java @@ -5,10 +5,10 @@ import com.ruoyi.common.core.web.domain.GenericsAjaxResult; import com.ruoyi.platform.domain.CodeConfig; import com.ruoyi.platform.service.CodeConfigService; import io.swagger.annotations.Api; -import org.springframework.web.bind.annotation.*; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; @@ -22,16 +22,17 @@ public class CodeConfigController extends BaseController { /** * 分页查询 + * * @param codeConfig 筛选条件 - * @param page 页数 - * @param size 每页大小 + * @param page 页数 + * @param size 每页大小 * @return 查询结果 */ @GetMapping - public GenericsAjaxResult> queryByPage( @RequestParam("page")int page, - @RequestParam("size") int size, - @RequestParam(value = "code_repo_name") String codeRepoName) { - PageRequest pageRequest = PageRequest.of(page,size); + public GenericsAjaxResult> queryByPage(@RequestParam("page") int page, + @RequestParam("size") int size, + @RequestParam(value = "code_repo_name", required = false) String codeRepoName) { + PageRequest pageRequest = PageRequest.of(page, size); CodeConfig codeConfig = new CodeConfig(); codeConfig.setCodeRepoName(codeRepoName); return genericsSuccess(this.codeConfigService.queryByPage(codeConfig, pageRequest)); @@ -39,6 +40,7 @@ public class CodeConfigController extends BaseController { /** * 通过主键查询单条数据 + * * @param id * @return 单条数据 */ @@ -49,17 +51,17 @@ public class CodeConfigController extends BaseController { @PostMapping - public GenericsAjaxResult add(@RequestBody CodeConfig codeConfig){ + public GenericsAjaxResult add(@RequestBody CodeConfig codeConfig) { return genericsSuccess(this.codeConfigService.insert(codeConfig)); } @PutMapping - public GenericsAjaxResult update(@RequestBody CodeConfig codeConfig){ + public GenericsAjaxResult update(@RequestBody CodeConfig codeConfig) { return genericsSuccess(this.codeConfigService.update(codeConfig)); } @DeleteMapping("{id}") - public GenericsAjaxResult delete(@PathVariable("id") Long id){ + public GenericsAjaxResult delete(@PathVariable("id") Long id) { return genericsSuccess(this.codeConfigService.removeById(id)); } } From d2c6e9a77ea1c4de3acb437cd2804bb7ae5ebefa Mon Sep 17 00:00:00 2001 From: chenzhihang <709011834@qq.com> Date: Thu, 29 Aug 2024 16:54:08 +0800 Subject: [PATCH 07/12] =?UTF-8?q?1=E3=80=81=E4=BF=AE=E6=94=B9=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ruoyi/platform/constant/Constant.java | 3 +++ .../service/impl/CodeConfigServiceImpl.java | 9 ++++++++- .../managementPlatform/CodeConfigDaoMapper.xml | 16 ++++------------ 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/constant/Constant.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/constant/Constant.java index 9d14aa3..0c7a09f 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/constant/Constant.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/constant/Constant.java @@ -5,6 +5,9 @@ public class Constant { public final static int Image_Type_Pub = 1; // 公共镜像 public final static int Image_Type_Pri = 0; // 私有镜像 + public final static int Code_Repo_Pub = 1; // 代码仓库可见性-公开 + public final static int Code_Repo_Pri = 0; // 代码仓库可见性-私有 + public final static int State_valid = 1; // 有效 public final static int State_invalid = 0; // 无效 diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/CodeConfigServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/CodeConfigServiceImpl.java index 664777d..c857374 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/CodeConfigServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/CodeConfigServiceImpl.java @@ -49,9 +49,16 @@ public class CodeConfigServiceImpl implements CodeConfigService { @Override public CodeConfig update(CodeConfig codeConfig) { + LoginUser loginUser = SecurityUtils.getLoginUser(); codeConfig.setUpdateBy(loginUser.getUsername()); - codeConfig.setUpdateTime(new Date()); + + if (codeConfig.getCodeRepoVis().equals(Constant.Code_Repo_Pub)) { + codeConfig.setVerifyMode(null); + codeConfig.setGitUserName(null); + codeConfig.setGitPassword(null); + codeConfig.setSshKey(null); + } this.codeConfigDao.update(codeConfig); return this.codeConfigDao.queryById(codeConfig.getId()); } diff --git a/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/CodeConfigDaoMapper.xml b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/CodeConfigDaoMapper.xml index f714f9e..1056bf8 100644 --- a/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/CodeConfigDaoMapper.xml +++ b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/CodeConfigDaoMapper.xml @@ -23,18 +23,10 @@ git_branch = #{codeConfig.gitBranch}, - - verify_mode = #{codeConfig.verifyMode}, - - - git_user_name = #{codeConfig.gitUserName}, - - - git_password = #{codeConfig.gitPassword}, - - - ssh_key = #{codeConfig.sshKey}, - + verify_mode = #{codeConfig.verifyMode}, + git_user_name = #{codeConfig.gitUserName}, + git_password = #{codeConfig.gitPassword}, + ssh_key = #{codeConfig.sshKey}, create_by = #{codeConfig.createBy}, From 4d9f831cc98f215814b779bd4084b2bfc5c3bbfc Mon Sep 17 00:00:00 2001 From: chenzhihang <709011834@qq.com> Date: Thu, 29 Aug 2024 17:37:58 +0800 Subject: [PATCH 08/12] =?UTF-8?q?1=E3=80=81=E9=85=8D=E7=BD=AEpod=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E9=99=90=E5=88=B6=E8=B5=84=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/JupyterServiceImpl.java | 2 +- .../ruoyi/platform/utils/K8sClientUtil.java | 27 ++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/JupyterServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/JupyterServiceImpl.java index b99bdb2..e6380f3 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/JupyterServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/JupyterServiceImpl.java @@ -105,7 +105,7 @@ public class JupyterServiceImpl implements JupyterService { //TODO 设置镜像可配置,这里先用默认镜像启动pod // 调用修改后的 createPod 方法,传入额外的参数 - Integer podPort = k8sClientUtil.createConfiguredPod(podName, namespace, port, mountPath, pvc, devEnvironment.getImage(), devEnvironment.getComputingResource(), minioPvcName, datasetPath, modelPath); + Integer podPort = k8sClientUtil.createConfiguredPod(podName, namespace, port, mountPath, pvc, devEnvironment, minioPvcName, datasetPath, modelPath); String url = masterIp + ":" + podPort; redisService.setCacheObject(podName, masterIp + ":" + podPort); devEnvironment.setStatus("Pending"); diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java index d5b5ab2..06e5908 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java @@ -1,6 +1,7 @@ package com.ruoyi.platform.utils; import com.ruoyi.platform.constant.Constant; +import com.ruoyi.platform.domain.DevEnvironment; import com.ruoyi.platform.mapper.ComputingResourceDao; import io.kubernetes.client.Exec; import io.kubernetes.client.custom.IntOrString; @@ -13,6 +14,7 @@ import io.kubernetes.client.util.ClientBuilder; import io.kubernetes.client.util.credentials.AccessTokenAuthentication; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; +import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -379,7 +381,7 @@ public class K8sClientUtil { } // 创建配置好的Pod - public Integer createConfiguredPod(String podName, String namespace, Integer port, String mountPath, V1PersistentVolumeClaim pvc, String image, String computingResource, String dataPvcName, String datasetPath, String modelPath) { + public Integer createConfiguredPod(String podName, String namespace, Integer port, String mountPath, V1PersistentVolumeClaim pvc, DevEnvironment devEnvironment, String dataPvcName, String datasetPath, String modelPath) { //设置选择节点,pod反亲和性 Map selector = new LinkedHashMap<>(); @@ -450,6 +452,24 @@ public class K8sClientUtil { volumes.add(new V1Volume().name("minio-pvc").persistentVolumeClaim(new V1PersistentVolumeClaimVolumeSource().claimName(dataPvcName))); + //配置资源 + JSONObject standardJson = new JSONObject(devEnvironment.getStandard()); + JSONObject valueJson = (JSONObject)standardJson.get("value"); + int cpu = (int)valueJson.get("cpu"); + String memory = (String)valueJson.get("memory"); + + HashMap limitMap = new HashMap<>(); + if (Constant.Computing_Resource_GPU.equals(devEnvironment.getComputingResource())) { + limitMap.put("nvidia.com/gpu", new Quantity("1")); + } + limitMap.put("cpu", new Quantity(String.valueOf(cpu))); + limitMap.put("memory", new Quantity(memory)); + limitMap.put("ephemeral-storage", new Quantity("100Gi")); + + V1ResourceRequirements v1ResourceRequirements = new V1ResourceRequirements(); + v1ResourceRequirements.setRequests(limitMap); + v1ResourceRequirements.setLimits(limitMap); + V1Pod pod = new V1PodBuilder() .withNewMetadata() .withName(podName) @@ -458,9 +478,10 @@ public class K8sClientUtil { .withNewSpec() .addNewContainer() .withName(podName) - .withImage(image) + .withImage(devEnvironment.getImage()) .withPorts(new V1ContainerPort().containerPort(port).protocol("TCP")) .withVolumeMounts(volumeMounts) + .withResources(v1ResourceRequirements) .endContainer() .withVolumes(volumes) .withNodeSelector(nodeSelector) @@ -471,7 +492,7 @@ public class K8sClientUtil { try { pod = api.createNamespacedPod(namespace, pod, null, null, null); String nodeName = getNodeName(podName, namespace); - if (Constant.Computing_Resource_GPU.equals(computingResource)) { + if (Constant.Computing_Resource_GPU.equals(devEnvironment.getComputingResource())) { computingResourceDao.updateUsedStateByNode(nodeName, Constant.Used_State_used); } } catch (ApiException e) { From b4672c5c8692d02a59eaa58455c8dc282870c683 Mon Sep 17 00:00:00 2001 From: chenzhihang <709011834@qq.com> Date: Fri, 30 Aug 2024 09:52:52 +0800 Subject: [PATCH 09/12] =?UTF-8?q?1=E3=80=81=E9=85=8D=E7=BD=AEpod=E8=8A=82?= =?UTF-8?q?=E7=82=B9=E4=BA=B2=E5=92=8C=E6=80=A7=E5=92=8C=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E5=88=86=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/platform/utils/K8sClientUtil.java | 60 ++++++++++--------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java index 06e5908..4dd8e6d 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java @@ -385,41 +385,44 @@ public class K8sClientUtil { //设置选择节点,pod反亲和性 Map selector = new LinkedHashMap<>(); - selector.put("k8s-jupyter", "CPU-GPU"); Map nodeSelector = new LinkedHashMap<>(); - nodeSelector.put("resource-type", "CPU-GPU"); + V1Affinity v1Affinity = new V1Affinity(); + if (Constant.Computing_Resource_GPU.equals(devEnvironment.getComputingResource())) { + selector.put("k8s-jupyter", "CPU-GPU"); + nodeSelector.put("resource-type", "CPU-GPU"); - V1LabelSelectorRequirement labelSelectorRequirement = new V1LabelSelectorRequirement() - .key("k8s-jupyter").operator("NotIn").values(Collections.singletonList("CPU-GPU")); + V1LabelSelectorRequirement labelSelectorRequirement = new V1LabelSelectorRequirement() + .key("k8s-jupyter").operator("NotIn").values(Collections.singletonList("CPU-GPU")); - V1LabelSelector labelSelector = new V1LabelSelector() - .matchExpressions(Collections.singletonList(labelSelectorRequirement)); + V1LabelSelector labelSelector = new V1LabelSelector() + .matchExpressions(Collections.singletonList(labelSelectorRequirement)); - V1PodAffinityTerm podAffinityTerm = new V1PodAffinityTerm() - .labelSelector(labelSelector) - .namespaces(Collections.singletonList(namespace)) - .topologyKey("kubernetes.io/hostname"); + V1PodAffinityTerm podAffinityTerm = new V1PodAffinityTerm() + .labelSelector(labelSelector) + .namespaces(Collections.singletonList(namespace)) + .topologyKey("kubernetes.io/hostname"); - V1PodAffinity podAffinity = new V1PodAffinity() - .requiredDuringSchedulingIgnoredDuringExecution(Collections.singletonList(podAffinityTerm)); + V1PodAffinity podAffinity = new V1PodAffinity() + .requiredDuringSchedulingIgnoredDuringExecution(Collections.singletonList(podAffinityTerm)); - V1LabelSelectorRequirement antiLabelSelectorRequirement = new V1LabelSelectorRequirement() - .key("k8s-jupyter").operator("In").values(Collections.singletonList("CPU-GPU")); + V1LabelSelectorRequirement antiLabelSelectorRequirement = new V1LabelSelectorRequirement() + .key("k8s-jupyter").operator("In").values(Collections.singletonList("CPU-GPU")); - V1LabelSelector antiLabelSelector = new V1LabelSelector() - .matchExpressions(Collections.singletonList(antiLabelSelectorRequirement)); + V1LabelSelector antiLabelSelector = new V1LabelSelector() + .matchExpressions(Collections.singletonList(antiLabelSelectorRequirement)); - V1PodAffinityTerm antiPodAffinityTerm = new V1PodAffinityTerm() - .labelSelector(antiLabelSelector) - .namespaces(Collections.singletonList(namespace)) - .topologyKey("kubernetes.io/hostname"); + V1PodAffinityTerm antiPodAffinityTerm = new V1PodAffinityTerm() + .labelSelector(antiLabelSelector) + .namespaces(Collections.singletonList(namespace)) + .topologyKey("kubernetes.io/hostname"); - V1PodAntiAffinity podAntiAffinity = new V1PodAntiAffinity() - .requiredDuringSchedulingIgnoredDuringExecution(Collections.singletonList(antiPodAffinityTerm)); + V1PodAntiAffinity podAntiAffinity = new V1PodAntiAffinity() + .requiredDuringSchedulingIgnoredDuringExecution(Collections.singletonList(antiPodAffinityTerm)); - V1Affinity v1Affinity = new V1Affinity() - .podAffinity(podAffinity) - .podAntiAffinity(podAntiAffinity); + v1Affinity.podAffinity(podAffinity).podAntiAffinity(podAntiAffinity); + } else { + selector.put("k8s-jupyter", "CPU"); + } // 创建Pod CoreV1Api api = new CoreV1Api(apiClient); @@ -454,9 +457,10 @@ public class K8sClientUtil { //配置资源 JSONObject standardJson = new JSONObject(devEnvironment.getStandard()); - JSONObject valueJson = (JSONObject)standardJson.get("value"); - int cpu = (int)valueJson.get("cpu"); - String memory = (String)valueJson.get("memory"); + JSONObject valueJson = (JSONObject) standardJson.get("value"); + int cpu = (int) valueJson.get("cpu"); + String memory = (String) valueJson.get("memory"); + memory = memory.substring(0, memory.length() - 1).concat("i"); HashMap limitMap = new HashMap<>(); if (Constant.Computing_Resource_GPU.equals(devEnvironment.getComputingResource())) { From e381f5a5494580b59e5edf34a74f96fbe87586ef Mon Sep 17 00:00:00 2001 From: chenzhihang <709011834@qq.com> Date: Fri, 30 Aug 2024 09:57:50 +0800 Subject: [PATCH 10/12] =?UTF-8?q?1=E3=80=81=E4=BC=98=E5=8C=96pod=E8=8A=82?= =?UTF-8?q?=E7=82=B9=E8=B5=84=E6=BA=90=E5=88=86=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java index 4dd8e6d..0c8fcc4 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java @@ -461,10 +461,11 @@ public class K8sClientUtil { int cpu = (int) valueJson.get("cpu"); String memory = (String) valueJson.get("memory"); memory = memory.substring(0, memory.length() - 1).concat("i"); + int gpu = (int) valueJson.get("gpu"); HashMap limitMap = new HashMap<>(); if (Constant.Computing_Resource_GPU.equals(devEnvironment.getComputingResource())) { - limitMap.put("nvidia.com/gpu", new Quantity("1")); + limitMap.put("nvidia.com/gpu", new Quantity(String.valueOf(gpu))); } limitMap.put("cpu", new Quantity(String.valueOf(cpu))); limitMap.put("memory", new Quantity(memory)); From df87d16d8f1684bd7effb689374f11df3ccf8168 Mon Sep 17 00:00:00 2001 From: fanshuai <1141904845@qq.com> Date: Fri, 30 Aug 2024 10:03:07 +0800 Subject: [PATCH 11/12] dvc --- ruoyi-modules/management-platform/pom.xml | 16 +- .../controller/dataset/DatasetController.java | 2 + .../dataset/NewDatasetFromGitController.java | 110 +++++++++ .../controller/jupyter/JupyterController.java | 7 +- .../platform/service/DatasetService.java | 9 + .../service/impl/DatasetServiceImpl.java | 217 +++++++++++++++++- .../com/ruoyi/platform/utils/ConvertUtil.java | 64 +++++- .../com/ruoyi/platform/utils/DVCUtils.java | 32 ++- .../com/ruoyi/platform/utils/HttpUtils.java | 57 ++++- .../com/ruoyi/platform/utils/JsonUtils.java | 5 + .../com/ruoyi/platform/utils/YamlUtils.java | 28 +++ .../java/com/ruoyi/platform/vo/DatasetVo.java | 10 +- .../com/ruoyi/platform/vo/GitProjectVo.java | 67 ++++++ .../com/ruoyi/platform/vo/NewDatasetVo.java | 41 ++++ 14 files changed, 638 insertions(+), 27 deletions(-) create mode 100644 ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/dataset/NewDatasetFromGitController.java create mode 100644 ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/YamlUtils.java create mode 100644 ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/GitProjectVo.java create mode 100644 ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/NewDatasetVo.java diff --git a/ruoyi-modules/management-platform/pom.xml b/ruoyi-modules/management-platform/pom.xml index c004f9a..e7c559f 100644 --- a/ruoyi-modules/management-platform/pom.xml +++ b/ruoyi-modules/management-platform/pom.xml @@ -142,6 +142,11 @@ docker-java 3.2.13 + + commons-beanutils + commons-beanutils + 1.9.4 + com.github.docker-java docker-java-transport-httpclient5 @@ -227,7 +232,16 @@ 2.6 compile - + + org.eclipse.jgit + org.eclipse.jgit + 5.13.0.202109080827-r + + + redis.clients + jedis + 3.6.0 + diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/dataset/DatasetController.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/dataset/DatasetController.java index cbd87f4..8e36471 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/dataset/DatasetController.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/dataset/DatasetController.java @@ -224,5 +224,7 @@ public class DatasetController { public AjaxResult uploadDatasetPipeline(@RequestBody(required =false) DatasetVersion datasetVersion) throws Exception { return AjaxResult.success(this.datasetService.uploadDatasetPipeline(datasetVersion)); } + + } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/dataset/NewDatasetFromGitController.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/dataset/NewDatasetFromGitController.java new file mode 100644 index 0000000..0821d3a --- /dev/null +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/dataset/NewDatasetFromGitController.java @@ -0,0 +1,110 @@ +package com.ruoyi.platform.controller.dataset; + +import com.ruoyi.common.core.web.domain.AjaxResult; +import com.ruoyi.platform.domain.Dataset; +import com.ruoyi.platform.service.DatasetService; +import com.ruoyi.platform.vo.DatasetVo; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.core.io.InputStreamResource; +import org.springframework.data.domain.PageRequest; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import javax.annotation.Resource; +@RestController +@RequestMapping("newdataset") +@Api(value = "新数据集管理") +public class NewDatasetFromGitController { + /** + * 服务对象 + */ + @Resource + private DatasetService datasetService; + + + + /** + * 新增数据集与版本新 + * + * @param datasetVo 实体 + * @return 新增结果 + */ + @PostMapping("/addDatasetAndVersion") + @ApiOperation("添加数据集和版本") + public AjaxResult addDatasetAndVersion(@RequestBody DatasetVo datasetVo) throws Exception { + return AjaxResult.success(this.datasetService.newCreateDataset(datasetVo)); + + } + + + /** + * 新增数据集与版本新 + * + * @param datasetVo 实体 + * @return 新增结果 + */ + @PostMapping("/addVersion") + @ApiOperation("添加版本") + public AjaxResult addVersion(@RequestBody DatasetVo datasetVo) throws Exception { + return AjaxResult.success(this.datasetService.newCreateVersion(datasetVo)); + + } + + + /** + * 上传数据集 + * + * @param files 上传的数据集文件 + * @param uuid 上传唯一标识,构建url + * @return 上传结果 + */ + @CrossOrigin(origins = "*", allowedHeaders = "*") + @PostMapping("/upload") + @ApiOperation(value = "上传数据集") + public AjaxResult uploadDataset(@RequestParam("file") MultipartFile[] files, @RequestParam("uuid") String uuid) throws Exception { + return AjaxResult.success(this.datasetService.uploadDatasetlocal(files,uuid)); + } + + /** + * 数据集打包下载 + * + * @param version 数据集版本 + * @return 单条数据 + */ + @GetMapping("/downloadAllFiles") + @ApiOperation(value = "下载同一版本下所有数据集,并打包") + public ResponseEntity downloadAllDatasetFiles(@RequestParam("repository_name") String repositoryName, @RequestParam("version") String version) throws Exception { + return datasetService.downloadAllDatasetFilesNew(repositoryName, version); + } + + /** + * 下载数据集 + * + * @param dataset_version_id ps:这里的id是dataset_version表的主键 + * @return 单条数据 + */ + + @GetMapping("/download/{dataset_version_id}") + @ApiOperation(value = "下载单个数据集文件", notes = "根据数据集版本表id下载单个数据集文件") + public ResponseEntity downloadDataset(@PathVariable("dataset_version_id") Integer dataset_version_id) throws Exception { + return datasetService.downloadDataset(dataset_version_id); + } + + @GetMapping("/queryDatasets") + @ApiOperation("数据集广场公开数据集分页查询,根据data_type,data_tag筛选,true公开false私有") + public AjaxResult queryDatasets(Dataset dataset, @RequestParam("page") int page, + @RequestParam("size") int size, + @RequestParam(value = "is_public") Boolean isPublic, + @RequestParam(value = "data_type", required = false) String dataType, + @RequestParam(value = "data_tag", required = false) String dataTag) throws Exception { + PageRequest pageRequest = PageRequest.of(page, size); + if(isPublic){ + return AjaxResult.success(this.datasetService.newPubilcQueryByPage(dataset, pageRequest)); + }else { + return AjaxResult.success(this.datasetService.newPersonalQueryByPage(dataset, pageRequest)); + } + } + +} diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/jupyter/JupyterController.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/jupyter/JupyterController.java index 080698c..02bff0d 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/jupyter/JupyterController.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/jupyter/JupyterController.java @@ -90,7 +90,7 @@ public class JupyterController extends BaseController { @GetMapping(value = "/testdvc") public AjaxResult testdvc() throws Exception { DatasetVo datasetVo = new DatasetVo(); - datasetVo.setName("testdvc82sas155"); + datasetVo.setName("testdassad23"); datasetVo.setDescription("sss"); datasetVo.setAvailableRange(0); datasetVo.setDataTag("计算机视觉"); @@ -98,10 +98,9 @@ public class JupyterController extends BaseController { datasetVo.setVersion("dev"); List datasetVersionVos = new ArrayList<>(); VersionVo versionVo = new VersionVo(); - versionVo.setUrl("/home/xxx.txt"); + versionVo.setUrl("E:/test/bb/data/xssa.doc"); datasetVersionVos.add(versionVo); datasetVo.setDatasetVersionVos(datasetVersionVos); - datasetService.newCreateDataset(datasetVo); - return AjaxResult.success(); + return AjaxResult.success(datasetService.newCreateDataset(datasetVo)); } } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/DatasetService.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/DatasetService.java index 148a1eb..a22e710 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/DatasetService.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/DatasetService.java @@ -3,12 +3,14 @@ package com.ruoyi.platform.service; import com.ruoyi.platform.domain.Dataset; import com.ruoyi.platform.domain.DatasetVersion; import com.ruoyi.platform.vo.DatasetVo; +import com.ruoyi.platform.vo.NewDatasetVo; import org.springframework.core.io.InputStreamResource; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.http.ResponseEntity; import org.springframework.web.multipart.MultipartFile; +import java.io.IOException; import java.util.List; import java.util.Map; import java.util.concurrent.CompletableFuture; @@ -91,6 +93,13 @@ DatasetService { CompletableFuture newCreateDataset(DatasetVo datasetVo) throws Exception; + CompletableFuture newCreateVersion(DatasetVo datasetVo); + + List> uploadDatasetlocal(MultipartFile[] files, String uuid) throws Exception; + + ResponseEntity downloadAllDatasetFilesNew(String repositoryName, String version) throws IOException, Exception; + Page newPersonalQueryByPage(Dataset dataset, PageRequest pageRequest) throws Exception; + Page newPubilcQueryByPage(Dataset dataset, PageRequest pageRequest) throws Exception; } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/DatasetServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/DatasetServiceImpl.java index 86a6002..9f59fbb 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/DatasetServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/DatasetServiceImpl.java @@ -1,6 +1,5 @@ package com.ruoyi.platform.service.impl; - import com.ruoyi.common.core.utils.DateUtils; import com.ruoyi.common.security.utils.SecurityUtils; import com.ruoyi.platform.annotations.CheckDuplicate; @@ -13,6 +12,7 @@ import com.ruoyi.platform.service.*; import com.ruoyi.platform.utils.*; import com.ruoyi.platform.vo.DatasetVo; import com.ruoyi.platform.vo.GitProjectVo; +import com.ruoyi.platform.vo.NewDatasetVo; import com.ruoyi.platform.vo.VersionVo; import com.ruoyi.system.api.model.LoginUser; import io.minio.messages.Item; @@ -33,10 +33,11 @@ import org.springframework.web.multipart.MultipartFile; import redis.clients.jedis.Jedis; import javax.annotation.Resource; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; +import java.io.*; import java.lang.reflect.Field; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.text.SimpleDateFormat; import java.util.*; import java.util.concurrent.CompletableFuture; @@ -461,9 +462,7 @@ public class DatasetServiceImpl implements DatasetService { public CompletableFuture newCreateDataset(DatasetVo datasetVo) { return CompletableFuture.supplyAsync(() -> { try { - String gitusername = datasetVo.getGitusername(); - String gitpassword = datasetVo.getGitpassword(); - String token = gitService.login(gitusername, gitpassword); + String token = gitService.login("fanshuai", "h1n2x3j4y5@"); LoginUser loginUser = SecurityUtils.getLoginUser(); String ci4sUsername = loginUser.getUsername(); Jedis jedis = new Jedis(redisHost); @@ -492,11 +491,67 @@ public class DatasetServiceImpl implements DatasetService { // 得到用户操作的路径 String url = datasetVo.getDatasetVersionVos().get(0).getUrl(); - String localPath = "/home/tempwork" + datasetVo.getName(); + String localPath = "E:/test/" + datasetVo.getName(); String sourcePath = url.substring(0, url.lastIndexOf("/")); // 命令行操作 git clone 项目地址 - DVCUtils.gitClone(localPath, projectUrl, branchName, gitusername, gitpassword); + DVCUtils.gitClone(localPath, projectUrl, branchName, "fanshuai", "h1n2x3j4y5@"); String s3Path = "management-platform-files/" + ci4sUsername + "/datasets/" + repositoryName + "/" + branchName; + //拼接生产的元数据后写入yaml文件 + YamlUtils.generateYamlFile(JsonUtils.objectToMap(datasetVo),sourcePath, "dataset"); + + DVCUtils.moveFiles(sourcePath, localPath); + + + + // dvc init 初始化 + DVCUtils.dvcInit(localPath); + // 配置远程S3地址 + DVCUtils.dvcRemoteAdd(localPath, s3Path); + DVCUtils.dvcConfigS3Credentials(localPath, endpoint); + DVCUtils.dvcConfigS3Credentials2(localPath, accessKeyId); + DVCUtils.dvcConfigS3Credentials3(localPath, secretAccessKey); + // dvc 跟踪 + DVCUtils.dvcAdd(localPath, "data"); + // git commit + DVCUtils.gitAdd(localPath, "."); + DVCUtils.gitCommit(localPath, "commit from ci4s with " + loginUser.getUsername()); + DVCUtils.gitPush(localPath, "fanshuai", "h1n2x3j4y5@"); + // dvc push 到远程S3 + DVCUtils.dvcPush(localPath); + return "新增数据集成功"; + } catch (Exception e) { + throw new RuntimeException(e); + } + }); + } + + @Override + public CompletableFuture newCreateVersion(DatasetVo datasetVo) { + return CompletableFuture.supplyAsync(() -> { + try { + String token = gitService.login("fanshuai", "h1n2x3j4y5@"); + LoginUser loginUser = SecurityUtils.getLoginUser(); + String ci4sUsername = loginUser.getUsername(); + Jedis jedis = new Jedis(redisHost); + String userReq = jedis.get(ci4sUsername + "_gitUserInfo"); + Map userInfo = JsonUtils.jsonToMap(userReq); + // 创建分支 + String branchName = datasetVo.getVersion(); + String repositoryName = datasetVo.getRepositoryName(); + gitService.createBranch(token, (String) userInfo.get("login"), repositoryName, branchName, "master"); + // 得到项目地址 + String projectUrl = gitendpoint + "/" +(String) userInfo.get("login") + "/" + repositoryName + ".git"; + + // 得到用户操作的路径 + String url = datasetVo.getDatasetVersionVos().get(0).getUrl(); + String localPath = "E:/test/"+ loginUser.getUsername()+"/datasets/"+ datasetVo.getName(); + String sourcePath = url.substring(0, url.lastIndexOf("/")); + // 命令行操作 git clone 项目地址 + DVCUtils.gitClone(localPath, projectUrl, branchName, "fanshuai", "h1n2x3j4y5@"); + String s3Path = "management-platform-files/" + ci4sUsername + "/datasets/" + repositoryName + "/" + branchName; + //拼接生产的元数据后写入yaml文件 + YamlUtils.generateYamlFile(JsonUtils.objectToMap(datasetVo),sourcePath, "dataset"); + DVCUtils.moveFiles(sourcePath, localPath); // dvc init 初始化 DVCUtils.dvcInit(localPath); @@ -510,7 +565,7 @@ public class DatasetServiceImpl implements DatasetService { // git commit DVCUtils.gitAdd(localPath, "."); DVCUtils.gitCommit(localPath, "commit from ci4s with " + loginUser.getUsername()); - DVCUtils.gitPush(localPath, gitusername, gitpassword); + DVCUtils.gitPush(localPath, "fanshuai", "h1n2x3j4y5@"); // dvc push 到远程S3 DVCUtils.dvcPush(localPath); return "新增数据集成功"; @@ -520,6 +575,56 @@ public class DatasetServiceImpl implements DatasetService { }); } + + @Override + public Page newPersonalQueryByPage(Dataset dataset, PageRequest pageRequest) throws Exception { + LoginUser loginUser = SecurityUtils.getLoginUser(); + String token = gitService.login("fanshuai", "h1n2x3j4y5@"); + String ci4sUsername = loginUser.getUsername(); + Jedis jedis = new Jedis(redisHost); + String userReq = jedis.get(ci4sUsername + "_gitUserInfo"); + Map userInfo = JsonUtils.jsonToMap(userReq); + //拼接查询url + String datasetTagName = dataset.getDatasetTagName(); + String datasetTypeName = dataset.getDatasetTypeName(); + String topic_name = "ci4s_dataset"; + topic_name =StringUtils.isEmpty(datasetTagName)?topic_name : topic_name+",datatag_" + datasetTagName; + topic_name =StringUtils.isEmpty(datasetTagName)?topic_name : topic_name+",datatype_" + datasetTypeName; + String url = gitendpoint + "/api/users/"+(String) userInfo.get("login")+"/projects.json?page="+pageRequest.getPageNumber()+"&limit="+pageRequest.getPageSize()+"&category=manage&topic_name="+topic_name; + String req = HttpUtils.sendGetWithToken(url,null,token); + Map stringObjectMap = JacksonUtil.parseJSONStr2Map(req); + Integer total = (Integer) stringObjectMap.get("count"); + List> projects = (List>) stringObjectMap.get("projects"); + return new PageImpl<>(convert(projects), pageRequest, total); + } + + @Override + public Page newPubilcQueryByPage(Dataset dataset, PageRequest pageRequest) throws Exception { + + LoginUser loginUser = SecurityUtils.getLoginUser(); + String token = gitService.login("fanshuai", "h1n2x3j4y5@"); + String ci4sUsername = loginUser.getUsername(); + Jedis jedis = new Jedis(redisHost); + String userReq = jedis.get(ci4sUsername + "_gitUserInfo"); + Map userInfo = JsonUtils.jsonToMap(userReq); + Integer userId = (Integer) userInfo.get("user_id"); + //拼接查询url + String datasetTagName = dataset.getDatasetTagName(); + String datasetTypeName = dataset.getDatasetTypeName(); + String topic_name = "ci4s_dataset"; + topic_name =StringUtils.isEmpty(datasetTagName)?topic_name : topic_name+",datatag_" + datasetTagName; + topic_name =StringUtils.isEmpty(datasetTagName)?topic_name : topic_name+",datatype_" + datasetTypeName; + + String url = gitendpoint + "/api/projects.json?user_id="+userId+"&page="+pageRequest.getPageNumber()+"&limit="+pageRequest.getPageSize()+"&sort_by=praises_count&topic_name="+topic_name; + String req = HttpUtils.sendGetWithToken(url,null,token); + Map stringObjectMap = JacksonUtil.parseJSONStr2Map(req); + Integer total = (Integer) stringObjectMap.get("total_count"); + List> projects = (List>) stringObjectMap.get("projects"); + return new PageImpl<>(convert(projects), pageRequest, total); + + } + + @Override public List> uploadDatasetlocal(MultipartFile[] files, String uuid) throws Exception { List> results = new ArrayList<>(); @@ -527,7 +632,7 @@ public class DatasetServiceImpl implements DatasetService { // 构建objectName String username = SecurityUtils.getLoginUser().getUsername(); String fileName = file.getOriginalFilename(); - String path = "/datasets/" + username + "/" + uuid + "/"+"/data/" + fileName; + String path = "/temp/"+ username +"/datasets/"+ uuid + "/"+"/data/" + fileName; long sizeInBytes = file.getSize(); String formattedSize = FileUtil.formatFileSize(sizeInBytes); File targetFile = new File(path, file.getOriginalFilename()); @@ -546,4 +651,94 @@ public class DatasetServiceImpl implements DatasetService { return results; } + @Override + public ResponseEntity downloadAllDatasetFilesNew(String repositoryName, String version) throws Exception { + // 命令行操作 git clone 项目地址 + LoginUser loginUser = SecurityUtils.getLoginUser(); + String token = gitService.login("fanshuai", "h1n2x3j4y5@"); + String ci4sUsername = loginUser.getUsername(); + Jedis jedis = new Jedis(redisHost); + String userReq = jedis.get(ci4sUsername + "_gitUserInfo"); + Map userInfo = JsonUtils.jsonToMap(userReq); + Integer userId = (Integer) userInfo.get("user_id"); + String projectUrl = gitendpoint + "/" +(String) userInfo.get("login") + "/" + repositoryName + ".git"; + String localPath = "E:/test/"+ loginUser.getUsername()+"/datasets/" +repositoryName; + File folder = new File(localPath); + if(folder.exists() && folder.isDirectory()){ + //切换分支 + DVCUtils.gitCheckoutBranch(localPath, version); + //pull + DVCUtils.gitPull(localPath,"fanshuai", "h1n2x3j4y5@"); + //dvc pull + DVCUtils.dvcPull(localPath); + }else { + DVCUtils.gitClone(localPath, projectUrl, version, "fanshuai", "h1n2x3j4y5@"); + } + + // 打包 data 文件夹 + String dataFolderPath = localPath + "/data"; + String zipFilePath = localPath + "/data.zip"; + try (FileOutputStream fos = new FileOutputStream(zipFilePath); + ZipOutputStream zos = new ZipOutputStream(fos)) { + Path sourcePath = Paths.get(dataFolderPath); + Files.walk(sourcePath).forEach(path -> { + if (!Files.isDirectory(path)) { + ZipEntry zipEntry = new ZipEntry(sourcePath.relativize(path).toString()); + try { + zos.putNextEntry(zipEntry); + Files.copy(path, zos); + zos.closeEntry(); + } catch (IOException e) { + throw new RuntimeException("Error while zipping: " + path, e); + } + } + }); + } + + // 返回压缩文件的输入流 + File zipFile = new File(zipFilePath); + InputStreamResource resource = new InputStreamResource(new FileInputStream(zipFile)); + + return ResponseEntity.ok() + .header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=data.zip") + .contentType(MediaType.APPLICATION_OCTET_STREAM) + .contentLength(zipFile.length()) + .body(resource); + + } + + + + public List convert(List> lst) { + if (lst != null && lst.size() > 0) { + List newDatasetVos = ConvertUtil.convertListMapToObjectList(lst, NewDatasetVo.class); + + for (NewDatasetVo newDatasetVo : newDatasetVos) { + Map map = lst.stream() + .filter(m -> m.get("repo_id").equals(newDatasetVo.getRepoId())) + .findFirst() + .orElse(null); + + if (map != null) { + List> topics = (List>) map.get("topics"); + if (topics != null) { + topics.forEach(topic -> { + String name = (String) topic.get("name"); + if (name != null) { + if (name.startsWith("datatag_")) { + newDatasetVo.setDataTag(name.substring("datatag_".length())); + } else if (name.startsWith("datatype_")) { + newDatasetVo.setDataType(name.substring("datatype_".length())); + } + } + }); + } + } + } + + return newDatasetVos; + } + return new ArrayList<>(); + } + } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/ConvertUtil.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/ConvertUtil.java index bfc051a..ca13861 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/ConvertUtil.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/ConvertUtil.java @@ -4,10 +4,13 @@ package com.ruoyi.platform.utils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; - +import org.apache.commons.beanutils.PropertyUtils; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Map; /** @@ -60,5 +63,64 @@ public class ConvertUtil { return targetList; } + public static List convertListMapToObjectList(List> listMap, Class targetClass) { + List resultList = new ArrayList<>(); + + if (listMap != null) { + for (Map map : listMap) { + T targetObject = convertMapToObject(map, targetClass); + if (targetObject != null) { + resultList.add(targetObject); + } + } + } + + return resultList; + } + + private static T convertMapToObject(Map map, Class targetClass) { + try { + T targetObject = targetClass.newInstance(); + for (Map.Entry entry : map.entrySet()) { + String key = entry.getKey(); + Object value = entry.getValue(); + String camelCaseKey = toCamelCase(key); + if (hasProperty(targetClass, camelCaseKey)) { + PropertyUtils.setProperty(targetObject, camelCaseKey, value); + } + } + return targetObject; + } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { + e.printStackTrace(); + } + return null; + } + + private static boolean hasProperty(Class clazz, String propertyName) { + try { + Field field = clazz.getDeclaredField(propertyName); + return field != null; + } catch (NoSuchFieldException e) { + return false; + } + } + + private static String toCamelCase(String key) { + StringBuilder sb = new StringBuilder(); + boolean nextUpperCase = false; + for (char c : key.toCharArray()) { + if (c == '_') { + nextUpperCase = true; + } else { + if (nextUpperCase) { + sb.append(Character.toUpperCase(c)); + nextUpperCase = false; + } else { + sb.append(c); + } + } + } + return sb.toString(); + } } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/DVCUtils.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/DVCUtils.java index ce726da..387f09a 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/DVCUtils.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/DVCUtils.java @@ -95,6 +95,33 @@ public class DVCUtils { } } + public static void gitCheckoutBranch(String localPath, String branchName) throws IOException, GitAPIException { + FileRepositoryBuilder builder = new FileRepositoryBuilder(); + Repository repository = builder.setGitDir(new File(localPath, ".git")) + .readEnvironment() + .findGitDir() + .build(); + + try (Git git = new Git(repository)) { + CheckoutCommand checkoutCommand = git.checkout(); + checkoutCommand.setName(branchName).call(); + } + } + + public static void gitPull(String localPath, String username, String password) throws IOException, GitAPIException { + FileRepositoryBuilder builder = new FileRepositoryBuilder(); + Repository repository = builder.setGitDir(new File(localPath, ".git")) + .readEnvironment() + .findGitDir() + .build(); + + try (Git git = new Git(repository)) { + CredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider(username, password); + PullCommand pullCommand = git.pull(); + pullCommand.setCredentialsProvider(credentialsProvider).call(); + } + } + public static void dvcInit(String localPath) throws Exception { String command = "dvc init"; runCommand(command, localPath); @@ -111,13 +138,15 @@ public class DVCUtils { } public static void dvcConfigS3Credentials(String localPath, String endpointurl) throws Exception { - String command = "dvc remote modify myremote endpointurl " + endpointurl ; + String command = "dvc remote modify myremote endpointurl " + endpointurl; runCommand(command, localPath); } + public static void dvcConfigS3Credentials2(String localPath, String accessKeyId) throws Exception { String command = "dvc remote modify myremote access_key_id " + accessKeyId; runCommand(command, localPath); } + public static void dvcConfigS3Credentials3(String localPath, String secretAccessKey) throws Exception { String command = "dvc remote modify myremote secret_access_key " + secretAccessKey; runCommand(command, localPath); @@ -128,6 +157,7 @@ public class DVCUtils { runCommand(command, localPath); } + // 更新的 dvcPull 方法 public static void dvcPull(String localPath) throws Exception { String command = "dvc pull"; runCommand(command, localPath); diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/HttpUtils.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/HttpUtils.java index ccfea3c..504c4c6 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/HttpUtils.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/HttpUtils.java @@ -11,6 +11,7 @@ import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.utils.URIBuilder; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.DefaultHttpClient; @@ -89,15 +90,61 @@ public class HttpUtils { public static String sendGet(String url, String param) { return sendGet(url, param, "UTF-8"); } +// /** +// * 向指定 URL 发送带token的GET方法的请求 +// * +// * @param url 发送请求的 URL +// * @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。 +// * @return 所代表远程资源的响应结果 +// */ +// public static String sendGetWithToken(String url, String param,String token) { +// return sendGet(url, param, "UTF-8",token); +// } /** - * 向指定 URL 发送带token的GET方法的请求 + * 向指定 URL 发送带 token 的 GET 方法的请求,使用 Apache HttpClient * - * @param url 发送请求的 URL - * @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。 + * @param url 发送请求的 URL + * @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。 + * @param token 认证 token * @return 所代表远程资源的响应结果 */ - public static String sendGetWithToken(String url, String param,String token) { - return sendGet(url, param, "UTF-8",token); + public static String sendGetWithToken(String url, String param, String token) { + String result = ""; + try (CloseableHttpClient httpClient = HttpClients.createDefault()) { + URIBuilder uriBuilder = new URIBuilder(url); + if (param != null && !param.isEmpty()) { + String[] pairs = param.split("&"); + for (String pair : pairs) { + int idx = pair.indexOf("="); + if (idx != -1) { + uriBuilder.setParameter(pair.substring(0, idx), pair.substring(idx + 1)); + } + } + } + + URI uri = uriBuilder.build(); + HttpGet httpGet = new HttpGet(uri); + + httpGet.setHeader("Content-Type", "application/json"); + httpGet.setHeader("Authorization", "Bearer " + token); + + log.info("Executing request: " + httpGet.getRequestLine()); + + try (CloseableHttpResponse response = httpClient.execute(httpGet)) { + int statusCode = response.getStatusLine().getStatusCode(); + if (statusCode == 200) { + result = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8); + } else { + throw new IOException("HTTP request failed with response code: " + statusCode); + } + log.info("Response: " + result); + } + } catch (URISyntaxException e) { + log.error("URISyntaxException, url=" + url + ", param=" + param, e); + } catch (IOException e) { + log.error("IOException, url=" + url + ", param=" + param, e); + } + return result; } /** * 向指定 URL 发送带token的GET方法的请求 diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/JsonUtils.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/JsonUtils.java index 78dab0c..2aa0ba0 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/JsonUtils.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/JsonUtils.java @@ -51,4 +51,9 @@ public class JsonUtils { return flatMap; } + + // 将Object转换为Map + public static Map objectToMap(Object object) throws IOException { + return objectMapper.convertValue(object, Map.class); + } } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/YamlUtils.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/YamlUtils.java new file mode 100644 index 0000000..395e78b --- /dev/null +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/YamlUtils.java @@ -0,0 +1,28 @@ +package com.ruoyi.platform.utils; + +import org.yaml.snakeyaml.Yaml; + +import java.io.FileWriter; +import java.io.IOException; +import java.util.Map; + +public class YamlUtils { + + /** + * 将Map对象转换为YAML格式并写入指定路径的文件中 + * + * @param data Map对象 + * @param path 文件路径 + * @param fileName 文件名 + */ + public static void generateYamlFile(Map data, String path, String fileName) { + Yaml yaml = new Yaml(); + String fullPath = path + "/" + fileName + ".yaml"; + + try (FileWriter writer = new FileWriter(fullPath)) { + yaml.dump(data, writer); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/DatasetVo.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/DatasetVo.java index 2253b10..2a1dcc0 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/DatasetVo.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/DatasetVo.java @@ -28,10 +28,6 @@ public class DatasetVo implements Serializable { @ApiModelProperty(name = "data_tag") private String dataTag; - @ApiModelProperty(name = "gitusername") - private String gitusername; - @ApiModelProperty(name = "gitpassword") - private String gitpassword; /** * 版本 */ @@ -47,4 +43,10 @@ public class DatasetVo implements Serializable { @ApiModelProperty(name = "available_cluster") private String availableCluster; + + /** + * 数据集仓库名称 + */ + @ApiModelProperty(name = "repository_name") + private String repositoryName; } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/GitProjectVo.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/GitProjectVo.java new file mode 100644 index 0000000..a31a7cd --- /dev/null +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/GitProjectVo.java @@ -0,0 +1,67 @@ +package com.ruoyi.platform.vo; + +import com.fasterxml.jackson.databind.PropertyNamingStrategy; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + +@ApiModel(description = "Git项目信息") +@Data +@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) +public class GitProjectVo implements Serializable { + + @ApiModelProperty(value = "用户或组织ID", required = true) + private int userId; + + @ApiModelProperty(value = "项目名称", required = true) + private String name; + + @ApiModelProperty(value = "项目描述", required = false) + private String description; + + @ApiModelProperty(value = "项目标识", required = true) + private String repositoryName; + +// @ApiModelProperty(value = "项目分类ID", required = false) +// private int projectCategoryId; +// +// @ApiModelProperty(value = "项目语言ID", required = false) +// private int projectLanguageId; + +// @ApiModelProperty(value = "项目忽略文件ID", required = false) +// private int ignoreId; + +// @ApiModelProperty(value = "项目许可证ID", required = false) +// private int licenseId; + + @ApiModelProperty(value = "项目是否为私有项目", required = false) + private boolean isPrivate; + +// @ApiModelProperty(value = "是否为区块链激励项目", required = false) +// private boolean blockchain; +// +// @ApiModelProperty(value = "区块链激励金额总数", required = false) +// private int blockchainTokenAll; + +// +// @Override +// public String toString() { +// return "GitProjectVo{" + +// "userId=" + userId + +// ", name='" + name + '\'' + +// ", description='" + description + '\'' + +// ", repositoryName='" + repositoryName + '\'' + +// ", projectCategoryId=" + projectCategoryId + +// ", projectLanguageId=" + projectLanguageId + +// ", ignoreId=" + ignoreId + +// ", licenseId=" + licenseId + +// ", isPrivate=" + isPrivate + +// ", blockchain=" + blockchain + +// ", blockchainTokenAll=" + blockchainTokenAll + +// '}'; +// } +} + diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/NewDatasetVo.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/NewDatasetVo.java new file mode 100644 index 0000000..7ea7276 --- /dev/null +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/NewDatasetVo.java @@ -0,0 +1,41 @@ +package com.ruoyi.platform.vo; + +import com.fasterxml.jackson.databind.PropertyNamingStrategy; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.apache.ibatis.annotations.MapKey; + +import java.io.Serializable; +import java.util.List; + +@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) +@Data +public class NewDatasetVo implements Serializable { + + + @ApiModelProperty(name = "name") + private String name; + /** + * 数据集仓库名称 + */ + @ApiModelProperty(name = "identifier") + private String identifier; + @ApiModelProperty(name = "description") + private String description; + /** + * 是否公开1公开,0私有 + */ + @ApiModelProperty(name = "is_public") + private Boolean isPublic; + @ApiModelProperty(name = "data_type") + private String dataType; + @ApiModelProperty(name = "data_tag") + private String dataTag; + @ApiModelProperty(name = "time_ago") + private String timeAgo; + @ApiModelProperty(name = "repo_id") + private Integer repoId; + + +} From 778df909bd0339cf63e903a31a8916b7d0d92b40 Mon Sep 17 00:00:00 2001 From: fanshuai <1141904845@qq.com> Date: Fri, 30 Aug 2024 13:57:55 +0800 Subject: [PATCH 12/12] dvc --- .../controller/dataset/NewDatasetFromGitController.java | 5 +++++ .../ruoyi/platform/service/impl/DatasetServiceImpl.java | 9 +++++++-- .../main/java/com/ruoyi/platform/vo/NewDatasetVo.java | 6 ++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/dataset/NewDatasetFromGitController.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/dataset/NewDatasetFromGitController.java index 0821d3a..636154d 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/dataset/NewDatasetFromGitController.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/dataset/NewDatasetFromGitController.java @@ -107,4 +107,9 @@ public class NewDatasetFromGitController { } } + @GetMapping("/getdatasetDetail") + @ApiOperation(value = "获取数据集详情") + public AjaxResult getDatasetVersions(@PathVariable("datasetId") Integer datasetId) throws Exception { + return AjaxResult.success(this.datasetService.getDatasetVersions(datasetId)); + } } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/DatasetServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/DatasetServiceImpl.java index 9f59fbb..5528418 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/DatasetServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/DatasetServiceImpl.java @@ -536,9 +536,11 @@ public class DatasetServiceImpl implements DatasetService { String userReq = jedis.get(ci4sUsername + "_gitUserInfo"); Map userInfo = JsonUtils.jsonToMap(userReq); // 创建分支 - String branchName = datasetVo.getVersion(); + String branchName = StringUtils.isEmpty(datasetVo.getVersion())? "master" : datasetVo.getVersion(); String repositoryName = datasetVo.getRepositoryName(); - gitService.createBranch(token, (String) userInfo.get("login"), repositoryName, branchName, "master"); + if (StringUtils.equals(branchName, "master")) { + gitService.createBranch(token, (String) userInfo.get("login"), repositoryName, branchName, "master"); + } // 得到项目地址 String projectUrl = gitendpoint + "/" +(String) userInfo.get("login") + "/" + repositoryName + ".git"; @@ -733,6 +735,9 @@ public class DatasetServiceImpl implements DatasetService { } }); } + + Map author = (Map) map.get("author"); + newDatasetVo.setCreateBy((String) author.get("name")); } } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/NewDatasetVo.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/NewDatasetVo.java index 7ea7276..3548c47 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/NewDatasetVo.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/NewDatasetVo.java @@ -36,6 +36,8 @@ public class NewDatasetVo implements Serializable { private String timeAgo; @ApiModelProperty(name = "repo_id") private Integer repoId; - - + @ApiModelProperty(name = "visits") + private Integer visits; + @ApiModelProperty(name = "create_by") + private String createBy; }