| @@ -14,7 +14,7 @@ public interface ResourceOccupyDao { | |||||
| int edit(@Param("resourceOccupy") ResourceOccupy resourceOccupy); | int edit(@Param("resourceOccupy") ResourceOccupy resourceOccupy); | ||||
| List<ResourceOccupy> getResourceOccupyByTask(@Param("taskType") String taskType, @Param("taskInsId") Long taskInsId, @Param("nodeId") String nodeId); | |||||
| List<ResourceOccupy> getResourceOccupyByTask(@Param("taskType") String taskType, @Param("taskId") Long taskId, @Param("taskInsId") Long taskInsId, @Param("nodeId") String nodeId); | |||||
| int deduceCredit(@Param("credit") Double credit, @Param("userId") Long userId); | int deduceCredit(@Param("credit") Double credit, @Param("userId") Long userId); | ||||
| @@ -51,7 +51,7 @@ public class ExperimentInstanceStatusTask { | |||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| experimentIns.setStatus(Constant.Failed); | experimentIns.setStatus(Constant.Failed); | ||||
| // 结束扣除积分 | // 结束扣除积分 | ||||
| resourceOccupyService.endDeduce(Constant.TaskType_Workflow, Long.valueOf(experimentIns.getId()), null, null); | |||||
| resourceOccupyService.endDeduce(Constant.TaskType_Workflow, null, Long.valueOf(experimentIns.getId()), null, null); | |||||
| } | } | ||||
| // 扣除积分 | // 扣除积分 | ||||
| @@ -65,9 +65,9 @@ public class ExperimentInstanceStatusTask { | |||||
| String finishedAt = (String) value.get("finishedAt"); | String finishedAt = (String) value.get("finishedAt"); | ||||
| if (StringUtils.isEmpty(finishedAt)) { | if (StringUtils.isEmpty(finishedAt)) { | ||||
| resourceOccupyService.deducing(Constant.TaskType_Workflow, Long.valueOf(experimentIns.getId()), key, startTime); | |||||
| resourceOccupyService.deducing(Constant.TaskType_Workflow, null, Long.valueOf(experimentIns.getId()), key, startTime); | |||||
| } else { | } else { | ||||
| resourceOccupyService.endDeduce(Constant.TaskType_Workflow, Long.valueOf(experimentIns.getId()), key, startTime); | |||||
| resourceOccupyService.endDeduce(Constant.TaskType_Workflow, null, Long.valueOf(experimentIns.getId()), key, startTime); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -45,15 +45,15 @@ public class RayInsStatusTask { | |||||
| // 扣除积分 | // 扣除积分 | ||||
| if (Constant.Running.equals(rayIns.getStatus())) { | if (Constant.Running.equals(rayIns.getStatus())) { | ||||
| resourceOccupyService.deducing(Constant.TaskType_Ray, rayIns.getId(), null,null); | |||||
| resourceOccupyService.deducing(Constant.TaskType_Ray, null, rayIns.getId(), null, null); | |||||
| } else if (Constant.Failed.equals(rayIns.getStatus()) || Constant.Terminated.equals(rayIns.getStatus()) | } else if (Constant.Failed.equals(rayIns.getStatus()) || Constant.Terminated.equals(rayIns.getStatus()) | ||||
| || Constant.Succeeded.equals(rayIns.getStatus())) { | || Constant.Succeeded.equals(rayIns.getStatus())) { | ||||
| resourceOccupyService.endDeduce(Constant.TaskType_Ray, rayIns.getId(), null,null); | |||||
| resourceOccupyService.endDeduce(Constant.TaskType_Ray, null, rayIns.getId(), null, null); | |||||
| } | } | ||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| rayIns.setStatus(Constant.Failed); | rayIns.setStatus(Constant.Failed); | ||||
| // 结束扣除积分 | // 结束扣除积分 | ||||
| resourceOccupyService.endDeduce(Constant.TaskType_Ray, rayIns.getId(), null, null); | |||||
| resourceOccupyService.endDeduce(Constant.TaskType_Ray, null, rayIns.getId(), null, null); | |||||
| } | } | ||||
| // 线程安全的添加操作 | // 线程安全的添加操作 | ||||
| synchronized (rayIds) { | synchronized (rayIds) { | ||||
| @@ -5,7 +5,9 @@ import com.ruoyi.platform.domain.DevEnvironment; | |||||
| import com.ruoyi.platform.domain.ServiceVersion; | import com.ruoyi.platform.domain.ServiceVersion; | ||||
| import com.ruoyi.platform.mapper.DevEnvironmentDao; | import com.ruoyi.platform.mapper.DevEnvironmentDao; | ||||
| import com.ruoyi.platform.mapper.ServiceDao; | import com.ruoyi.platform.mapper.ServiceDao; | ||||
| import com.ruoyi.platform.service.JupyterService; | |||||
| import com.ruoyi.platform.service.ResourceOccupyService; | import com.ruoyi.platform.service.ResourceOccupyService; | ||||
| import com.ruoyi.platform.vo.PodStatusVo; | |||||
| import org.springframework.scheduling.annotation.Scheduled; | import org.springframework.scheduling.annotation.Scheduled; | ||||
| import org.springframework.stereotype.Component; | import org.springframework.stereotype.Component; | ||||
| @@ -24,21 +26,32 @@ public class ResourceOccupyTask { | |||||
| @Resource | @Resource | ||||
| private ServiceDao serviceDao; | private ServiceDao serviceDao; | ||||
| @Resource | |||||
| private JupyterService jupyterService; | |||||
| // 开发环境功能扣除积分 | // 开发环境功能扣除积分 | ||||
| @Scheduled(cron = "0 0/1 * * * ?") // 每10分钟执行一次 | |||||
| public void devDeduceCredit() { | |||||
| @Scheduled(cron = "0 0/1 * * * ?") // 每1分钟执行一次 | |||||
| public void devDeduceCredit() throws Exception { | |||||
| List<DevEnvironment> devEnvironments = devEnvironmentDao.getRunning(); | List<DevEnvironment> devEnvironments = devEnvironmentDao.getRunning(); | ||||
| for (DevEnvironment devEnvironment : devEnvironments) { | |||||
| resourceOccupyService.deducing(Constant.TaskType_Dev, Long.valueOf(devEnvironment.getId()), null, null); | |||||
| for (DevEnvironment devEnv : devEnvironments) { | |||||
| PodStatusVo podStatusVo = this.jupyterService.getJupyterStatus(devEnv); | |||||
| if (!devEnv.getStatus().equals(podStatusVo.getStatus())) { | |||||
| devEnv.setStatus(podStatusVo.getStatus()); | |||||
| devEnv.setUrl(podStatusVo.getUrl()); | |||||
| this.devEnvironmentDao.update(devEnv); | |||||
| } | |||||
| if (Constant.Running.equals(devEnv.getStatus())) { | |||||
| resourceOccupyService.deducing(Constant.TaskType_Dev, Long.valueOf(devEnv.getId()), null, null, null); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| // 服务功能扣除积分 | // 服务功能扣除积分 | ||||
| @Scheduled(cron = "0 0/1 * * * ?") // 每10分钟执行一次 | |||||
| @Scheduled(cron = "0 0/1 * * * ?") // 每1分钟执行一次 | |||||
| public void serviceDeduceCredit() { | public void serviceDeduceCredit() { | ||||
| List<ServiceVersion> serviceVersions = serviceDao.getRunning(); | List<ServiceVersion> serviceVersions = serviceDao.getRunning(); | ||||
| for (ServiceVersion serviceVersion : serviceVersions) { | for (ServiceVersion serviceVersion : serviceVersions) { | ||||
| resourceOccupyService.deducing(Constant.TaskType_Service, serviceVersion.getId(), null, null); | |||||
| resourceOccupyService.deducing(Constant.TaskType_Service, null, serviceVersion.getId(), null, null); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -13,9 +13,9 @@ public interface ResourceOccupyService { | |||||
| void startDeduce(Integer computingResourceId, String taskType, Long taskId, Long taskInsId, Long workflowId, String taskName, String nodeId); | void startDeduce(Integer computingResourceId, String taskType, Long taskId, Long taskInsId, Long workflowId, String taskName, String nodeId); | ||||
| void endDeduce(String taskType, Long taskInsId, String nodeId, Date nodeStartTime); | |||||
| void endDeduce(String taskType, Long taskId, Long taskInsId, String nodeId, Date nodeStartTime); | |||||
| void deducing(String taskType, Long taskInsId, String nodeId, Date nodeStartTime); | |||||
| void deducing(String taskType, Long taskId, Long taskInsId, String nodeId, Date nodeStartTime); | |||||
| Page<ResourceOccupy> queryByPage(PageRequest pageRequest); | Page<ResourceOccupy> queryByPage(PageRequest pageRequest); | ||||
| @@ -1,6 +1,5 @@ | |||||
| package com.ruoyi.platform.service.impl; | package com.ruoyi.platform.service.impl; | ||||
| import cn.hutool.json.JSONUtil; | |||||
| import com.alibaba.fastjson2.JSON; | import com.alibaba.fastjson2.JSON; | ||||
| import com.ruoyi.common.security.utils.SecurityUtils; | import com.ruoyi.common.security.utils.SecurityUtils; | ||||
| import com.ruoyi.platform.constant.Constant; | import com.ruoyi.platform.constant.Constant; | ||||
| @@ -416,7 +415,7 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { | |||||
| updateExperimentStatus(experimentIns.getExperimentId()); | updateExperimentStatus(experimentIns.getExperimentId()); | ||||
| // 结束扣除积分 | // 结束扣除积分 | ||||
| resourceOccupyService.endDeduce(Constant.TaskType_Workflow, Long.valueOf(experimentIns.getId()), null, null); | |||||
| resourceOccupyService.endDeduce(Constant.TaskType_Workflow, null, Long.valueOf(experimentIns.getId()), null, null); | |||||
| return true; | return true; | ||||
| } else { | } else { | ||||
| throw new Exception("终止错误"); | throw new Exception("终止错误"); | ||||
| @@ -142,7 +142,7 @@ public class JupyterServiceImpl implements JupyterService { | |||||
| this.devEnvironmentService.update(devEnvironment); | this.devEnvironmentService.update(devEnvironment); | ||||
| // 结束扣积分 | // 结束扣积分 | ||||
| resourceOccupyService.endDeduce(Constant.TaskType_Dev, Long.valueOf(id), null, null); | |||||
| resourceOccupyService.endDeduce(Constant.TaskType_Dev, Long.valueOf(id), null, null, null); | |||||
| return deleteResult + ",编辑器已停止"; | return deleteResult + ",编辑器已停止"; | ||||
| } | } | ||||
| @@ -168,7 +168,7 @@ public class RayInsServiceImpl implements RayInsService { | |||||
| rayInsDao.update(ins); | rayInsDao.update(ins); | ||||
| updateRayStatus(rayIns.getRayId()); | updateRayStatus(rayIns.getRayId()); | ||||
| // 结束扣积分 | // 结束扣积分 | ||||
| resourceOccupyService.endDeduce(Constant.TaskType_Ray, id, null, null); | |||||
| resourceOccupyService.endDeduce(Constant.TaskType_Ray, null, id, null, null); | |||||
| return true; | return true; | ||||
| } else { | } else { | ||||
| return false; | return false; | ||||
| @@ -78,10 +78,10 @@ public class ResourceOccupyServiceImpl implements ResourceOccupyService { | |||||
| @Override | @Override | ||||
| @Transactional | @Transactional | ||||
| public void endDeduce(String taskType, Long taskInsId, String nodeId, Date nodeStartTime) { | |||||
| List<ResourceOccupy> resourceOccupys = resourceOccupyDao.getResourceOccupyByTask(taskType, taskInsId, nodeId); | |||||
| public void endDeduce(String taskType, Long taskId, Long taskInsId, String nodeId, Date nodeStartTime) { | |||||
| List<ResourceOccupy> resourceOccupys = resourceOccupyDao.getResourceOccupyByTask(taskType, taskId, taskInsId, nodeId); | |||||
| for (ResourceOccupy resourceOccupy : resourceOccupys) { | for (ResourceOccupy resourceOccupy : resourceOccupys) { | ||||
| deducing(taskType, taskInsId, nodeId, nodeStartTime); | |||||
| deducing(taskType, taskId, taskInsId, nodeId, nodeStartTime); | |||||
| resourceOccupy.setState(Constant.State_invalid); | resourceOccupy.setState(Constant.State_invalid); | ||||
| resourceOccupyDao.edit(resourceOccupy); | resourceOccupyDao.edit(resourceOccupy); | ||||
| @@ -96,8 +96,8 @@ public class ResourceOccupyServiceImpl implements ResourceOccupyService { | |||||
| @Override | @Override | ||||
| @Transactional | @Transactional | ||||
| public void deducing(String taskType, Long taskInsId, String nodeId, Date nodeStartTime) { | |||||
| List<ResourceOccupy> resourceOccupys = resourceOccupyDao.getResourceOccupyByTask(taskType, taskInsId, nodeId); | |||||
| public void deducing(String taskType, Long taskId, Long taskInsId, String nodeId, Date nodeStartTime) { | |||||
| List<ResourceOccupy> resourceOccupys = resourceOccupyDao.getResourceOccupyByTask(taskType, taskId, taskInsId, nodeId); | |||||
| for (ResourceOccupy resourceOccupy : resourceOccupys) { | for (ResourceOccupy resourceOccupy : resourceOccupys) { | ||||
| Date now = new Date(); | Date now = new Date(); | ||||
| long timeDifferenceMillis; | long timeDifferenceMillis; | ||||
| @@ -297,7 +297,7 @@ public class ServiceServiceImpl implements ServiceService { | |||||
| serviceVersion.setRunState(Constant.Stopped); | serviceVersion.setRunState(Constant.Stopped); | ||||
| serviceDao.updateServiceVersion(serviceVersion); | serviceDao.updateServiceVersion(serviceVersion); | ||||
| // 结束扣积分 | // 结束扣积分 | ||||
| resourceOccupyService.endDeduce(Constant.TaskType_Service, id, null, null); | |||||
| resourceOccupyService.endDeduce(Constant.TaskType_Service, null, id, null, null); | |||||
| return "停止成功"; | return "停止成功"; | ||||
| } else { | } else { | ||||
| throw new RuntimeException("停止失败"); | throw new RuntimeException("停止失败"); | ||||
| @@ -127,7 +127,7 @@ | |||||
| </select> | </select> | ||||
| <select id="getRunning" resultType="com.ruoyi.platform.domain.DevEnvironment"> | <select id="getRunning" resultType="com.ruoyi.platform.domain.DevEnvironment"> | ||||
| select * from dev_environment where state = 1 and status = 'Running' | |||||
| select * from dev_environment where state = 1 and (status = 'Running' or status = 'Pending' or status = 'Init') | |||||
| </select> | </select> | ||||
| <!--新增所有列--> | <!--新增所有列--> | ||||
| @@ -55,7 +55,12 @@ | |||||
| select * | select * | ||||
| from resource_occupy | from resource_occupy | ||||
| where task_type = #{taskType} | where task_type = #{taskType} | ||||
| and task_ins_id = #{taskInsId} | |||||
| <if test="taskId != null and taskId !=''"> | |||||
| and task_id = #{taskId} | |||||
| </if> | |||||
| <if test="taskInsId != null and taskInsId !=''"> | |||||
| and task_ins_id = #{taskInsId} | |||||
| </if> | |||||
| <if test="nodeId != null and nodeId !=''"> | <if test="nodeId != null and nodeId !=''"> | ||||
| and node_id = #{nodeId} | and node_id = #{nodeId} | ||||
| </if> | </if> | ||||