| @@ -98,8 +98,8 @@ public class JupyterServiceImpl implements JupyterService { | |||||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | LoginUser loginUser = SecurityUtils.getLoginUser(); | ||||
| //构造pod名称 | //构造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 | //新建编辑器的pvc | ||||
| // String pvcName = loginUser.getUsername().toLowerCase() + "-editor-pvc"; | |||||
| // V1PersistentVolumeClaim pvc = k8sClientUtil.createPvc(namespace, pvcName, storage, storageClassName); | // V1PersistentVolumeClaim pvc = k8sClientUtil.createPvc(namespace, pvcName, storage, storageClassName); | ||||
| //TODO 设置镜像可配置,这里先用默认镜像启动pod | //TODO 设置镜像可配置,这里先用默认镜像启动pod | ||||
| @@ -26,9 +26,6 @@ import java.util.Map; | |||||
| @Service("MinioService") | @Service("MinioService") | ||||
| public class MinioServiceImpl implements MinioService { | public class MinioServiceImpl implements MinioService { | ||||
| @Value("${jupyter.hostPath}") | |||||
| private String hostPath; | |||||
| private final MinioUtil minioUtil; | private final MinioUtil minioUtil; | ||||
| public MinioServiceImpl(MinioUtil minioUtil) { | public MinioServiceImpl(MinioUtil minioUtil) { | ||||
| @@ -66,7 +63,7 @@ public class MinioServiceImpl implements MinioService { | |||||
| try (InputStream inputStream = file.getInputStream()){ | try (InputStream inputStream = file.getInputStream()){ | ||||
| minioUtil.uploadObject(bucketName, objectName, inputStream); | minioUtil.uploadObject(bucketName, objectName, inputStream); | ||||
| result.put("fileName", file.getOriginalFilename()); | result.put("fileName", file.getOriginalFilename()); | ||||
| objectName = hostPath + "/" + objectName; | |||||
| objectName = "/" + objectName; | |||||
| result.put("url", objectName); // objectName根据实际情况定义 | result.put("url", objectName); // objectName根据实际情况定义 | ||||
| result.put("fileSize", formattedSize); | result.put("fileSize", formattedSize); | ||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| @@ -186,10 +186,8 @@ public class ModelsVersionServiceImpl implements ModelsVersionService { | |||||
| .filter(modelsVersion -> modelsVersion.getUrl() != null && !modelsVersion.getUrl().isEmpty()) | .filter(modelsVersion -> modelsVersion.getUrl() != null && !modelsVersion.getUrl().isEmpty()) | ||||
| .findFirst() | .findFirst() | ||||
| .ifPresent(modelsVersion -> { | .ifPresent(modelsVersion -> { | ||||
| String url = modelsVersion.getUrl(); | |||||
| String path = bucketName + '/' + url.substring(0, url.lastIndexOf('/')); | |||||
| String path = modelsVersion.getUrl(); | |||||
| response.put("path", path); | response.put("path", path); | ||||
| }); | }); | ||||
| response.put("content", modelsVersionList); | response.put("content", modelsVersionList); | ||||
| @@ -28,16 +28,17 @@ public class TensorBoardServiceImpl implements TensorBoardService { | |||||
| private RedisService redisService; | private RedisService redisService; | ||||
| @Resource | @Resource | ||||
| private K8sClientUtil k8sClientUtil; | private K8sClientUtil k8sClientUtil; | ||||
| @Override | @Override | ||||
| public PodStatusVo getTensorBoardStatus(FrameLogPathVo frameLogPathVo){ | |||||
| public PodStatusVo getTensorBoardStatus(FrameLogPathVo frameLogPathVo) { | |||||
| String status = PodStatus.Terminated.getName(); | String status = PodStatus.Terminated.getName(); | ||||
| PodStatusVo tensorboardStatusVo = new PodStatusVo(); | PodStatusVo tensorboardStatusVo = new PodStatusVo(); | ||||
| tensorboardStatusVo.setStatus(status); | tensorboardStatusVo.setStatus(status); | ||||
| if (StringUtils.isEmpty(frameLogPathVo.getPath())){ | |||||
| if (StringUtils.isEmpty(frameLogPathVo.getPath())) { | |||||
| return tensorboardStatusVo; | return tensorboardStatusVo; | ||||
| } | } | ||||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | 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 { | try { | ||||
| String podStatus = k8sClientUtil.getPodStatus(podName, StringUtils.isEmpty(frameLogPathVo.getNamespace()) ? "default" : frameLogPathVo.getNamespace()); | String podStatus = k8sClientUtil.getPodStatus(podName, StringUtils.isEmpty(frameLogPathVo.getNamespace()) ? "default" : frameLogPathVo.getNamespace()); | ||||
| @@ -58,13 +59,17 @@ public class TensorBoardServiceImpl implements TensorBoardService { | |||||
| @Override | @Override | ||||
| public String runTensorBoard(FrameLogPathVo frameLogPathVo) throws Exception { | 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(); | 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"; | ||||
| 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; | return masterIp + ":" + podPort; | ||||
| } | } | ||||
| } | } | ||||
| @@ -365,13 +365,14 @@ public class K8sClientUtil { | |||||
| .endEnv() | .endEnv() | ||||
| .endContainer() | .endContainer() | ||||
| .addNewVolume() | .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() | .endVolume() | ||||
| .withTerminationGracePeriodSeconds(14400L) | .withTerminationGracePeriodSeconds(14400L) | ||||
| .endSpec() | .endSpec() | ||||
| .build(); | .build(); | ||||
| try { | try { | ||||
| pod = api.createNamespacedPod(namespace, pod, null, null, null); | pod = api.createNamespacedPod(namespace, pod, null, null, null); | ||||
| } catch (ApiException e) { | } catch (ApiException e) { | ||||