This commit is contained in:
fanshuai 2024-09-10 14:56:32 +08:00
commit 9b64f38835
5 changed files with 18 additions and 17 deletions

View File

@ -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

View File

@ -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) {

View File

@ -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);

View File

@ -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;
}
}

View File

@ -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) {