Browse Source

feat:jupyter返回状态查询

pull/95/head
西大锐 1 year ago
parent
commit
7f8219d369
5 changed files with 42 additions and 21 deletions
  1. +3
    -2
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/jupyter/JupyterController.java
  2. +2
    -2
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/JupyterService.java
  3. +26
    -2
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/DevEnvironmentServiceImpl.java
  4. +1
    -2
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ExperimentInsServiceImpl.java
  5. +10
    -13
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/JupyterServiceImpl.java

+ 3
- 2
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/jupyter/JupyterController.java View File

@@ -3,6 +3,7 @@ package com.ruoyi.platform.controller.jupyter;
import com.ruoyi.common.core.web.controller.BaseController; import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult; import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.domain.GenericsAjaxResult; import com.ruoyi.common.core.web.domain.GenericsAjaxResult;
import com.ruoyi.platform.domain.DevEnvironment;
import com.ruoyi.platform.service.JupyterService; import com.ruoyi.platform.service.JupyterService;
import com.ruoyi.platform.vo.FrameLogPathVo; import com.ruoyi.platform.vo.FrameLogPathVo;
import com.ruoyi.platform.vo.PodStatusVo; import com.ruoyi.platform.vo.PodStatusVo;
@@ -60,8 +61,8 @@ public class JupyterController extends BaseController {
@PostMapping("/getStatus") @PostMapping("/getStatus")
@ApiOperation("查询jupyter pod状态") @ApiOperation("查询jupyter pod状态")
@ApiResponse @ApiResponse
public GenericsAjaxResult<PodStatusVo> getStatus(@RequestBody FrameLogPathVo frameLogPathVo) throws Exception {
return genericsSuccess(this.jupyterService.getJupyterStatus(frameLogPathVo));
public GenericsAjaxResult<PodStatusVo> getStatus(DevEnvironment devEnvironment) throws Exception {
return genericsSuccess(this.jupyterService.getJupyterStatus(devEnvironment));
} }






+ 2
- 2
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/JupyterService.java View File

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


import com.ruoyi.platform.vo.FrameLogPathVo;
import com.ruoyi.platform.domain.DevEnvironment;
import com.ruoyi.platform.vo.PodStatusVo; import com.ruoyi.platform.vo.PodStatusVo;


import java.io.InputStream; import java.io.InputStream;
@@ -16,5 +16,5 @@ public interface JupyterService {


String stopJupyterService(Integer id) throws Exception; String stopJupyterService(Integer id) throws Exception;


PodStatusVo getJupyterStatus(FrameLogPathVo frameLogPathVo);
PodStatusVo getJupyterStatus(DevEnvironment devEnvironment) throws Exception;
} }

+ 26
- 2
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/DevEnvironmentServiceImpl.java View File

@@ -2,14 +2,17 @@ package com.ruoyi.platform.service.impl;


import com.ruoyi.common.security.utils.SecurityUtils; import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.platform.domain.DevEnvironment; import com.ruoyi.platform.domain.DevEnvironment;
import com.ruoyi.platform.domain.PodStatus;
import com.ruoyi.platform.mapper.DevEnvironmentDao; import com.ruoyi.platform.mapper.DevEnvironmentDao;
import com.ruoyi.platform.service.DevEnvironmentService; import com.ruoyi.platform.service.DevEnvironmentService;
import com.ruoyi.platform.service.JupyterService; import com.ruoyi.platform.service.JupyterService;
import com.ruoyi.platform.utils.JacksonUtil; import com.ruoyi.platform.utils.JacksonUtil;
import com.ruoyi.platform.vo.DevEnvironmentVo; import com.ruoyi.platform.vo.DevEnvironmentVo;
import com.ruoyi.platform.vo.PodStatusVo;
import com.ruoyi.system.api.model.LoginUser; import com.ruoyi.system.api.model.LoginUser;
import io.kubernetes.client.openapi.models.V1PersistentVolumeClaim; import io.kubernetes.client.openapi.models.V1PersistentVolumeClaim;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageImpl;
@@ -17,6 +20,7 @@ import org.springframework.data.domain.PageRequest;


import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Date; import java.util.Date;
import java.util.List;
import java.util.Map; import java.util.Map;


/** /**
@@ -30,6 +34,10 @@ public class DevEnvironmentServiceImpl implements DevEnvironmentService {
@Resource @Resource
private DevEnvironmentDao devEnvironmentDao; private DevEnvironmentDao devEnvironmentDao;


@Resource
@Lazy
private JupyterService jupyterService;



/** /**
* 通过ID查询单条数据 * 通过ID查询单条数据
@@ -52,13 +60,29 @@ public class DevEnvironmentServiceImpl implements DevEnvironmentService {
@Override @Override
public Page<DevEnvironment> queryByPage(DevEnvironment devEnvironment, PageRequest pageRequest) { public Page<DevEnvironment> queryByPage(DevEnvironment devEnvironment, PageRequest pageRequest) {
long total = this.devEnvironmentDao.count(devEnvironment); long total = this.devEnvironmentDao.count(devEnvironment);
return new PageImpl<>(this.devEnvironmentDao.queryAllByLimit(devEnvironment, pageRequest), pageRequest, total);
List<DevEnvironment> devEnvironmentList = this.devEnvironmentDao.queryAllByLimit(devEnvironment, pageRequest);

//查询每个开发环境的pod状态,注意:只有pod为非终止态时才去调状态接口
devEnvironmentList.forEach(devEnv -> {
try{
if (!devEnv.getStatus().equals(PodStatus.Terminated.getName()) &&
!devEnv.getStatus().equals(PodStatus.Failed.getName())) {
PodStatusVo podStatusVo = this.jupyterService.getJupyterStatus(devEnv);
devEnv.setStatus(podStatusVo.getStatus());
devEnv.setUrl(podStatusVo.getUrl());
}
} catch (Exception e) {
devEnv.setStatus(PodStatus.Unknown.getName());
}
});

return new PageImpl<>(devEnvironmentList, pageRequest, total);
} }


/** /**
* 新增数据 * 新增数据
* *
* @param devEnvironment 实例对象
* @param devEnvironmentVo 实例对象
* @return 实例对象 * @return 实例对象
*/ */
@Override @Override


+ 1
- 2
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ExperimentInsServiceImpl.java View File

@@ -102,7 +102,6 @@ public class ExperimentInsServiceImpl implements ExperimentInsService {
*/ */
@Override @Override
public List<ExperimentIns> getByExperimentId(Integer experimentId) throws IOException { public List<ExperimentIns> getByExperimentId(Integer experimentId) throws IOException {
List<ExperimentIns> experimentInsList = experimentInsDao.getByExperimentId(experimentId);


//代码全部迁移至定时任务 //代码全部迁移至定时任务
//搞个标记,当状态改变才去改表 //搞个标记,当状态改变才去改表
@@ -138,7 +137,7 @@ public class ExperimentInsServiceImpl implements ExperimentInsService {
// experimentDao.update(experiment); // experimentDao.update(experiment);
// } // }


return experimentInsList;
return experimentInsDao.getByExperimentId(experimentId);


} }




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

@@ -1,6 +1,5 @@
package com.ruoyi.platform.service.impl; package com.ruoyi.platform.service.impl;


import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.redis.service.RedisService; import com.ruoyi.common.redis.service.RedisService;
import com.ruoyi.common.security.utils.SecurityUtils; import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.platform.domain.DevEnvironment; import com.ruoyi.platform.domain.DevEnvironment;
@@ -12,7 +11,6 @@ import com.ruoyi.platform.utils.JacksonUtil;
import com.ruoyi.platform.utils.K8sClientUtil; import com.ruoyi.platform.utils.K8sClientUtil;
import com.ruoyi.platform.utils.MinioUtil; import com.ruoyi.platform.utils.MinioUtil;
import com.ruoyi.platform.utils.MlflowUtil; import com.ruoyi.platform.utils.MlflowUtil;
import com.ruoyi.platform.vo.FrameLogPathVo;
import com.ruoyi.platform.vo.PodStatusVo; import com.ruoyi.platform.vo.PodStatusVo;
import com.ruoyi.system.api.model.LoginUser; import com.ruoyi.system.api.model.LoginUser;
import io.kubernetes.client.openapi.models.V1PersistentVolumeClaim; import io.kubernetes.client.openapi.models.V1PersistentVolumeClaim;
@@ -101,12 +99,13 @@ public class JupyterServiceImpl implements JupyterService {


// 调用修改后的 createPod 方法,传入额外的参数 // 调用修改后的 createPod 方法,传入额外的参数
Integer podPort = k8sClientUtil.createConfiguredPod(podName, namespace, port, mountPath, pvc, image, minioPvcName, datasetPath, modelPath); Integer podPort = k8sClientUtil.createConfiguredPod(podName, namespace, port, mountPath, pvc, image, minioPvcName, datasetPath, modelPath);
// 简单的延迟,以便 Pod 有时间启动
Thread.sleep(2500);
//查询pod状态,更新到数据库
String podStatus = k8sClientUtil.getPodStatus(podName, namespace);
// // 简单的延迟,以便 Pod 有时间启动
// Thread.sleep(2500);
// //查询pod状态,更新到数据库
// String podStatus = k8sClientUtil.getPodStatus(podName, namespace);
String url = masterIp + ":" + podPort; String url = masterIp + ":" + podPort;
devEnvironment.setStatus(podStatus);
redisService.setCacheObject(podName,masterIp + ":" + podPort);
devEnvironment.setStatus("Pending");
devEnvironment.setUrl(url); devEnvironment.setUrl(url);
this.devEnvironmentService.update(devEnvironment); this.devEnvironmentService.update(devEnvironment);
return url ; return url ;
@@ -137,19 +136,19 @@ public class JupyterServiceImpl implements JupyterService {
} }


@Override @Override
public PodStatusVo getJupyterStatus(FrameLogPathVo frameLogPathVo) {
public PodStatusVo getJupyterStatus(DevEnvironment devEnvironment) throws Exception {
String status = PodStatus.Terminated.getName(); String status = PodStatus.Terminated.getName();
PodStatusVo JupyterStatusVo = new PodStatusVo(); PodStatusVo JupyterStatusVo = new PodStatusVo();
JupyterStatusVo.setStatus(status); JupyterStatusVo.setStatus(status);
if(StringUtils.isEmpty(frameLogPathVo.getPath())){
if (devEnvironment==null){
return JupyterStatusVo; return JupyterStatusVo;
} }
LoginUser loginUser = SecurityUtils.getLoginUser(); LoginUser loginUser = SecurityUtils.getLoginUser();
String podName = loginUser.getUsername().toLowerCase() + "-editor-pod";
String podName = loginUser.getUsername().toLowerCase() +"-editor-pod" + "-" + devEnvironment.getId();


try { try {
// 查询相应pod状态 // 查询相应pod状态
String podStatus = k8sClientUtil.getPodStatus(podName, StringUtils.isEmpty(frameLogPathVo.getNamespace()) ? "default" : frameLogPathVo.getNamespace());
String podStatus = k8sClientUtil.getPodStatus(podName, namespace);
for (PodStatus s : PodStatus.values()) { for (PodStatus s : PodStatus.values()) {
if (s.getName().equals(podStatus)) { if (s.getName().equals(podStatus)) {
status = s.getName(); status = s.getName();
@@ -159,8 +158,6 @@ public class JupyterServiceImpl implements JupyterService {


} catch (Exception e) { } catch (Exception e) {
return JupyterStatusVo; return JupyterStatusVo;


} }
String url = redisService.getCacheObject(podName); String url = redisService.getCacheObject(podName);
JupyterStatusVo.setStatus(status); JupyterStatusVo.setStatus(status);


Loading…
Cancel
Save