feat:jupyter返回状态查询
This commit is contained in:
parent
3261418ab5
commit
7f8219d369
|
@ -3,6 +3,7 @@ package com.ruoyi.platform.controller.jupyter;
|
|||
import com.ruoyi.common.core.web.controller.BaseController;
|
||||
import com.ruoyi.common.core.web.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.web.domain.GenericsAjaxResult;
|
||||
import com.ruoyi.platform.domain.DevEnvironment;
|
||||
import com.ruoyi.platform.service.JupyterService;
|
||||
import com.ruoyi.platform.vo.FrameLogPathVo;
|
||||
import com.ruoyi.platform.vo.PodStatusVo;
|
||||
|
@ -60,8 +61,8 @@ public class JupyterController extends BaseController {
|
|||
@PostMapping("/getStatus")
|
||||
@ApiOperation("查询jupyter pod状态")
|
||||
@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));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.ruoyi.platform.service;
|
||||
|
||||
import com.ruoyi.platform.vo.FrameLogPathVo;
|
||||
import com.ruoyi.platform.domain.DevEnvironment;
|
||||
import com.ruoyi.platform.vo.PodStatusVo;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
@ -16,5 +16,5 @@ public interface JupyterService {
|
|||
|
||||
String stopJupyterService(Integer id) throws Exception;
|
||||
|
||||
PodStatusVo getJupyterStatus(FrameLogPathVo frameLogPathVo);
|
||||
PodStatusVo getJupyterStatus(DevEnvironment devEnvironment) throws Exception;
|
||||
}
|
||||
|
|
|
@ -2,14 +2,17 @@ package com.ruoyi.platform.service.impl;
|
|||
|
||||
import com.ruoyi.common.security.utils.SecurityUtils;
|
||||
import com.ruoyi.platform.domain.DevEnvironment;
|
||||
import com.ruoyi.platform.domain.PodStatus;
|
||||
import com.ruoyi.platform.mapper.DevEnvironmentDao;
|
||||
import com.ruoyi.platform.service.DevEnvironmentService;
|
||||
import com.ruoyi.platform.service.JupyterService;
|
||||
import com.ruoyi.platform.utils.JacksonUtil;
|
||||
import com.ruoyi.platform.vo.DevEnvironmentVo;
|
||||
import com.ruoyi.platform.vo.PodStatusVo;
|
||||
import com.ruoyi.system.api.model.LoginUser;
|
||||
import io.kubernetes.client.openapi.models.V1PersistentVolumeClaim;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
|
@ -17,6 +20,7 @@ import org.springframework.data.domain.PageRequest;
|
|||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
@ -30,6 +34,10 @@ public class DevEnvironmentServiceImpl implements DevEnvironmentService {
|
|||
@Resource
|
||||
private DevEnvironmentDao devEnvironmentDao;
|
||||
|
||||
@Resource
|
||||
@Lazy
|
||||
private JupyterService jupyterService;
|
||||
|
||||
|
||||
/**
|
||||
* 通过ID查询单条数据
|
||||
|
@ -52,13 +60,29 @@ public class DevEnvironmentServiceImpl implements DevEnvironmentService {
|
|||
@Override
|
||||
public Page<DevEnvironment> queryByPage(DevEnvironment devEnvironment, PageRequest pageRequest) {
|
||||
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 实例对象
|
||||
*/
|
||||
@Override
|
||||
|
|
|
@ -102,7 +102,6 @@ public class ExperimentInsServiceImpl implements ExperimentInsService {
|
|||
*/
|
||||
@Override
|
||||
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);
|
||||
// }
|
||||
|
||||
return experimentInsList;
|
||||
return experimentInsDao.getByExperimentId(experimentId);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.ruoyi.platform.service.impl;
|
||||
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.ruoyi.common.redis.service.RedisService;
|
||||
import com.ruoyi.common.security.utils.SecurityUtils;
|
||||
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.MinioUtil;
|
||||
import com.ruoyi.platform.utils.MlflowUtil;
|
||||
import com.ruoyi.platform.vo.FrameLogPathVo;
|
||||
import com.ruoyi.platform.vo.PodStatusVo;
|
||||
import com.ruoyi.system.api.model.LoginUser;
|
||||
import io.kubernetes.client.openapi.models.V1PersistentVolumeClaim;
|
||||
|
@ -101,12 +99,13 @@ public class JupyterServiceImpl implements JupyterService {
|
|||
|
||||
// 调用修改后的 createPod 方法,传入额外的参数
|
||||
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;
|
||||
devEnvironment.setStatus(podStatus);
|
||||
redisService.setCacheObject(podName,masterIp + ":" + podPort);
|
||||
devEnvironment.setStatus("Pending");
|
||||
devEnvironment.setUrl(url);
|
||||
this.devEnvironmentService.update(devEnvironment);
|
||||
return url ;
|
||||
|
@ -137,19 +136,19 @@ public class JupyterServiceImpl implements JupyterService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public PodStatusVo getJupyterStatus(FrameLogPathVo frameLogPathVo) {
|
||||
public PodStatusVo getJupyterStatus(DevEnvironment devEnvironment) throws Exception {
|
||||
String status = PodStatus.Terminated.getName();
|
||||
PodStatusVo JupyterStatusVo = new PodStatusVo();
|
||||
JupyterStatusVo.setStatus(status);
|
||||
if(StringUtils.isEmpty(frameLogPathVo.getPath())){
|
||||
if (devEnvironment==null){
|
||||
return JupyterStatusVo;
|
||||
}
|
||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||
String podName = loginUser.getUsername().toLowerCase() + "-editor-pod";
|
||||
String podName = loginUser.getUsername().toLowerCase() +"-editor-pod" + "-" + devEnvironment.getId();
|
||||
|
||||
try {
|
||||
// 查询相应pod状态
|
||||
String podStatus = k8sClientUtil.getPodStatus(podName, StringUtils.isEmpty(frameLogPathVo.getNamespace()) ? "default" : frameLogPathVo.getNamespace());
|
||||
String podStatus = k8sClientUtil.getPodStatus(podName, namespace);
|
||||
for (PodStatus s : PodStatus.values()) {
|
||||
if (s.getName().equals(podStatus)) {
|
||||
status = s.getName();
|
||||
|
@ -159,8 +158,6 @@ public class JupyterServiceImpl implements JupyterService {
|
|||
|
||||
} catch (Exception e) {
|
||||
return JupyterStatusVo;
|
||||
|
||||
|
||||
}
|
||||
String url = redisService.getCacheObject(podName);
|
||||
JupyterStatusVo.setStatus(status);
|
||||
|
|
Loading…
Reference in New Issue