From 9fcb1a2db04ffcadbdcdad811c429b7ed1826757 Mon Sep 17 00:00:00 2001 From: chenzhihang <709011834@qq.com> Date: Tue, 10 Sep 2024 14:53:55 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E4=BF=AE=E6=94=B9=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E8=B7=AF=E5=BE=84=202=E3=80=81=E4=BF=AE?= =?UTF-8?q?=E6=94=B9tensorboard=20pod=E6=8C=82=E8=BD=BD=E6=96=B9=E5=BC=8F?= =?UTF-8?q?=E4=B8=BAhostpath?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/JupyterServiceImpl.java | 2 +- .../service/impl/MinioServiceImpl.java | 5 +---- .../impl/ModelsVersionServiceImpl.java | 4 +--- .../service/impl/TensorBoardServiceImpl.java | 19 ++++++++++++------- .../ruoyi/platform/utils/K8sClientUtil.java | 5 +++-- 5 files changed, 18 insertions(+), 17 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 cefcead..31dfb09 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 @@ -98,8 +98,8 @@ public class JupyterServiceImpl implements JupyterService { LoginUser loginUser = SecurityUtils.getLoginUser(); //构造pod名称 String podName = loginUser.getUsername().toLowerCase() + "-editor-pod" + "-" + id; - String pvcName = loginUser.getUsername().toLowerCase() + "-editor-pvc"; //新建编辑器的pvc +// String pvcName = loginUser.getUsername().toLowerCase() + "-editor-pvc"; // V1PersistentVolumeClaim pvc = k8sClientUtil.createPvc(namespace, pvcName, storage, storageClassName); //TODO 设置镜像可配置,这里先用默认镜像启动pod diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/MinioServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/MinioServiceImpl.java index dc5fba8..aaf7429 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/MinioServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/MinioServiceImpl.java @@ -26,9 +26,6 @@ import java.util.Map; @Service("MinioService") public class MinioServiceImpl implements MinioService { - @Value("${jupyter.hostPath}") - private String hostPath; - private final MinioUtil minioUtil; public MinioServiceImpl(MinioUtil minioUtil) { @@ -66,7 +63,7 @@ public class MinioServiceImpl implements MinioService { try (InputStream inputStream = file.getInputStream()){ minioUtil.uploadObject(bucketName, objectName, inputStream); result.put("fileName", file.getOriginalFilename()); - objectName = hostPath + "/" + objectName; + objectName = "/" + objectName; result.put("url", objectName); // objectName根据实际情况定义 result.put("fileSize", formattedSize); } catch (Exception e) { diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ModelsVersionServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ModelsVersionServiceImpl.java index f94a3bc..c4dafa9 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ModelsVersionServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ModelsVersionServiceImpl.java @@ -186,10 +186,8 @@ public class ModelsVersionServiceImpl implements ModelsVersionService { .filter(modelsVersion -> modelsVersion.getUrl() != null && !modelsVersion.getUrl().isEmpty()) .findFirst() .ifPresent(modelsVersion -> { - String url = modelsVersion.getUrl(); - String path = bucketName + '/' + url.substring(0, url.lastIndexOf('/')); + String path = modelsVersion.getUrl(); response.put("path", path); - }); response.put("content", modelsVersionList); diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/TensorBoardServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/TensorBoardServiceImpl.java index 2209773..e7dce43 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/TensorBoardServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/TensorBoardServiceImpl.java @@ -28,16 +28,17 @@ public class TensorBoardServiceImpl implements TensorBoardService { private RedisService redisService; @Resource private K8sClientUtil k8sClientUtil; + @Override - public PodStatusVo getTensorBoardStatus(FrameLogPathVo frameLogPathVo){ + public PodStatusVo getTensorBoardStatus(FrameLogPathVo frameLogPathVo) { String status = PodStatus.Terminated.getName(); PodStatusVo tensorboardStatusVo = new PodStatusVo(); tensorboardStatusVo.setStatus(status); - if (StringUtils.isEmpty(frameLogPathVo.getPath())){ + if (StringUtils.isEmpty(frameLogPathVo.getPath())) { return tensorboardStatusVo; } LoginUser loginUser = SecurityUtils.getLoginUser(); - String podName = loginUser.getUsername().toLowerCase()+"-"+frameLogPathVo.getPath().split("/")[2]+ "-tensorboard-pod"; + String podName = loginUser.getUsername().toLowerCase() + "-" + frameLogPathVo.getPath().split("/")[2] + "-tensorboard-pod"; try { String podStatus = k8sClientUtil.getPodStatus(podName, StringUtils.isEmpty(frameLogPathVo.getNamespace()) ? "default" : frameLogPathVo.getNamespace()); @@ -58,13 +59,17 @@ public class TensorBoardServiceImpl implements TensorBoardService { @Override public String runTensorBoard(FrameLogPathVo frameLogPathVo) throws Exception { - if (StringUtils.isEmpty(frameLogPathVo.getPath())||StringUtils.isEmpty(frameLogPathVo.getPvcName())){ - throw new Exception("存储路径或存储为空"); +// if (StringUtils.isEmpty(frameLogPathVo.getPath())||StringUtils.isEmpty(frameLogPathVo.getPvcName())){ +// throw new Exception("存储路径或存储为空"); +// } + if (StringUtils.isEmpty(frameLogPathVo.getPath())) { + throw new Exception("存储路径为空"); } LoginUser loginUser = SecurityUtils.getLoginUser(); String podName = loginUser.getUsername().toLowerCase()+"-"+frameLogPathVo.getPath().split("/")[2]+ "-tensorboard-pod"; - Integer podPort = k8sClientUtil.createPodWithSubPath(podName, StringUtils.isEmpty(frameLogPathVo.getNamespace())?"default":frameLogPathVo.getNamespace(), port, mountPath,frameLogPathVo.getPath(), frameLogPathVo.getPvcName(), image); - redisService.setCacheObject(podName,masterIp + ":" + podPort); + + Integer podPort = k8sClientUtil.createPodWithSubPath(podName, StringUtils.isEmpty(frameLogPathVo.getNamespace()) ? "default" : frameLogPathVo.getNamespace(), port, mountPath, frameLogPathVo.getPath(), frameLogPathVo.getPvcName(), image); + redisService.setCacheObject(podName, masterIp + ":" + podPort); return masterIp + ":" + podPort; } } 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 48f4e28..03648e6 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 @@ -365,13 +365,14 @@ public class K8sClientUtil { .endEnv() .endContainer() .addNewVolume() - .withName("workspace").withPersistentVolumeClaim(new V1PersistentVolumeClaimVolumeSource().claimName(pvcName)) + .withName("workspace") + .withHostPath(new V1HostPathVolumeSource().path(hostPath + "/" + podName + "/tensorboard").type("DirectoryOrCreate")) +// .withPersistentVolumeClaim(new V1PersistentVolumeClaimVolumeSource().claimName(pvcName)) .endVolume() .withTerminationGracePeriodSeconds(14400L) .endSpec() .build(); - try { pod = api.createNamespacedPod(namespace, pod, null, null, null); } catch (ApiException e) {