| @@ -61,7 +61,7 @@ public class DevEnvironmentController extends BaseController { | |||||
| * @return 新增结果 | * @return 新增结果 | ||||
| */ | */ | ||||
| @PostMapping | @PostMapping | ||||
| public GenericsAjaxResult<DevEnvironment> add(@RequestBody DevEnvironmentVo devEnvironmentVo) { | |||||
| public GenericsAjaxResult<DevEnvironment> add(@RequestBody DevEnvironmentVo devEnvironmentVo) throws Exception { | |||||
| return genericsSuccess(this.devEnvironmentService.insert(devEnvironmentVo)); | return genericsSuccess(this.devEnvironmentService.insert(devEnvironmentVo)); | ||||
| } | } | ||||
| @@ -72,7 +72,7 @@ public class DevEnvironmentController extends BaseController { | |||||
| * @return 编辑结果 | * @return 编辑结果 | ||||
| */ | */ | ||||
| @PutMapping | @PutMapping | ||||
| public GenericsAjaxResult<DevEnvironment> edit(@RequestBody DevEnvironment devEnvironment) { | |||||
| public GenericsAjaxResult<DevEnvironment> edit(@RequestBody DevEnvironment devEnvironment) throws Exception { | |||||
| return genericsSuccess(this.devEnvironmentService.update(devEnvironment)); | return genericsSuccess(this.devEnvironmentService.update(devEnvironment)); | ||||
| } | } | ||||
| @@ -73,7 +73,7 @@ public class ServiceController extends BaseController { | |||||
| @PutMapping("/serviceVersion") | @PutMapping("/serviceVersion") | ||||
| @ApiOperation("编辑服务版本") | @ApiOperation("编辑服务版本") | ||||
| public GenericsAjaxResult<String> editServiceVersion(@RequestBody ServiceVersionVo serviceVersionVo) { | |||||
| public GenericsAjaxResult<String> editServiceVersion(@RequestBody ServiceVersionVo serviceVersionVo) throws Exception { | |||||
| return genericsSuccess(serviceService.editServiceVersion(serviceVersionVo)); | return genericsSuccess(serviceService.editServiceVersion(serviceVersionVo)); | ||||
| } | } | ||||
| @@ -14,4 +14,8 @@ public interface ResourceOccupyDao { | |||||
| ResourceOccupy getResourceOccupyByTask(@Param("taskType") String taskType, @Param("taskId") Long taskId); | ResourceOccupy getResourceOccupyByTask(@Param("taskType") String taskType, @Param("taskId") Long taskId); | ||||
| int deduceCredit(@Param("credit") Float credit, @Param("userId") Long userId); | int deduceCredit(@Param("credit") Float credit, @Param("userId") Long userId); | ||||
| int updateUsed(@Param("id") Integer id, @Param("used") Integer used); | |||||
| int updateUnUsed(@Param("id") Integer id, @Param("used") Integer used); | |||||
| } | } | ||||
| @@ -36,7 +36,7 @@ public interface DevEnvironmentService { | |||||
| * @param devEnvironment 实例对象 | * @param devEnvironment 实例对象 | ||||
| * @return 实例对象 | * @return 实例对象 | ||||
| */ | */ | ||||
| DevEnvironment insert(DevEnvironmentVo devEnvironmentVo); | |||||
| DevEnvironment insert(DevEnvironmentVo devEnvironmentVo) throws Exception; | |||||
| /** | /** | ||||
| * 修改数据 | * 修改数据 | ||||
| @@ -44,7 +44,7 @@ public interface DevEnvironmentService { | |||||
| * @param devEnvironment 实例对象 | * @param devEnvironment 实例对象 | ||||
| * @return 实例对象 | * @return 实例对象 | ||||
| */ | */ | ||||
| DevEnvironment update(DevEnvironment devEnvironment); | |||||
| DevEnvironment update(DevEnvironment devEnvironment) throws Exception; | |||||
| /** | /** | ||||
| * 通过主键删除数据 | * 通过主键删除数据 | ||||
| @@ -22,7 +22,7 @@ public interface ServiceService { | |||||
| Service editService(Service service); | Service editService(Service service); | ||||
| String editServiceVersion(ServiceVersionVo serviceVersionVo); | |||||
| String editServiceVersion(ServiceVersionVo serviceVersionVo) throws Exception; | |||||
| Service getService(Long id); | Service getService(Long id); | ||||
| @@ -6,6 +6,7 @@ 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.service.ResourceOccupyService; | |||||
| 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.platform.vo.PodStatusVo; | ||||
| @@ -36,6 +37,8 @@ public class DevEnvironmentServiceImpl implements DevEnvironmentService { | |||||
| @Lazy | @Lazy | ||||
| private JupyterService jupyterService; | private JupyterService jupyterService; | ||||
| @Resource | |||||
| private ResourceOccupyService resourceOccupyService; | |||||
| /** | /** | ||||
| * 通过ID查询单条数据 | * 通过ID查询单条数据 | ||||
| @@ -87,7 +90,10 @@ public class DevEnvironmentServiceImpl implements DevEnvironmentService { | |||||
| * @return 实例对象 | * @return 实例对象 | ||||
| */ | */ | ||||
| @Override | @Override | ||||
| public DevEnvironment insert(DevEnvironmentVo devEnvironmentVo) { | |||||
| public DevEnvironment insert(DevEnvironmentVo devEnvironmentVo) throws Exception { | |||||
| // 判断是否有资源 | |||||
| resourceOccupyService.haveResource(devEnvironmentVo.getComputingResourceId()); | |||||
| //插入预备,此时不需要判断版本重复 | //插入预备,此时不需要判断版本重复 | ||||
| DevEnvironment devEnvironment = new DevEnvironment(); | DevEnvironment devEnvironment = new DevEnvironment(); | ||||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | LoginUser loginUser = SecurityUtils.getLoginUser(); | ||||
| @@ -120,7 +126,10 @@ public class DevEnvironmentServiceImpl implements DevEnvironmentService { | |||||
| * @return 实例对象 | * @return 实例对象 | ||||
| */ | */ | ||||
| @Override | @Override | ||||
| public DevEnvironment update(DevEnvironment devEnvironment) { | |||||
| public DevEnvironment update(DevEnvironment devEnvironment) throws Exception { | |||||
| // 判断是否有资源 | |||||
| resourceOccupyService.haveResource(devEnvironment.getComputingResourceId()); | |||||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | LoginUser loginUser = SecurityUtils.getLoginUser(); | ||||
| devEnvironment.setUpdateBy(loginUser.getUsername()); | devEnvironment.setUpdateBy(loginUser.getUsername()); | ||||
| devEnvironment.setUpdateTime(new Date()); | devEnvironment.setUpdateTime(new Date()); | ||||
| @@ -66,6 +66,10 @@ public class RayServiceImpl implements RayService { | |||||
| if (rayByName != null) { | if (rayByName != null) { | ||||
| throw new RuntimeException("实验名称已存在"); | throw new RuntimeException("实验名称已存在"); | ||||
| } | } | ||||
| // 判断是否有资源 | |||||
| resourceOccupyService.haveResource(rayVo.getComputingResourceId()); | |||||
| Ray ray = new Ray(); | Ray ray = new Ray(); | ||||
| BeanUtils.copyProperties(rayVo, ray); | BeanUtils.copyProperties(rayVo, ray); | ||||
| String username = SecurityUtils.getLoginUser().getUsername(); | String username = SecurityUtils.getLoginUser().getUsername(); | ||||
| @@ -87,6 +91,10 @@ public class RayServiceImpl implements RayService { | |||||
| if (oldRay != null && !oldRay.getId().equals(rayVo.getId())) { | if (oldRay != null && !oldRay.getId().equals(rayVo.getId())) { | ||||
| throw new RuntimeException("实验名称已存在"); | throw new RuntimeException("实验名称已存在"); | ||||
| } | } | ||||
| // 判断是否有资源 | |||||
| resourceOccupyService.haveResource(rayVo.getComputingResourceId()); | |||||
| Ray ray = new Ray(); | Ray ray = new Ray(); | ||||
| BeanUtils.copyProperties(rayVo, ray); | BeanUtils.copyProperties(rayVo, ray); | ||||
| ray.setUpdateBy(SecurityUtils.getLoginUser().getUsername()); | ray.setUpdateBy(SecurityUtils.getLoginUser().getUsername()); | ||||
| @@ -55,6 +55,12 @@ public class ResourceOccupyServiceImpl implements ResourceOccupyService { | |||||
| resourceOccupy.setTaskType(taskType); | resourceOccupy.setTaskType(taskType); | ||||
| resourceOccupy.setTaskId(taskId); | resourceOccupy.setTaskId(taskId); | ||||
| resourceOccupyDao.save(resourceOccupy); | resourceOccupyDao.save(resourceOccupy); | ||||
| if (Constant.Computing_Resource_GPU.equals(computingResource.getComputingResource())) { | |||||
| resourceOccupyDao.updateUsed(computingResource.getResourceId(), computingResource.getGpuNums()); | |||||
| } else { | |||||
| resourceOccupyDao.updateUsed(computingResource.getResourceId(), computingResource.getCpuCores()); | |||||
| } | |||||
| } | } | ||||
| @Override | @Override | ||||
| @@ -62,8 +68,14 @@ public class ResourceOccupyServiceImpl implements ResourceOccupyService { | |||||
| ResourceOccupy resourceOccupy = resourceOccupyDao.getResourceOccupyByTask(taskType, taskId); | ResourceOccupy resourceOccupy = resourceOccupyDao.getResourceOccupyByTask(taskType, taskId); | ||||
| deducing(taskType, taskId); | deducing(taskType, taskId); | ||||
| resourceOccupy.setState(Constant.State_invalid); | resourceOccupy.setState(Constant.State_invalid); | ||||
| resourceOccupy.setDeduceLastTime(new Date()); | |||||
| resourceOccupyDao.edit(resourceOccupy); | resourceOccupyDao.edit(resourceOccupy); | ||||
| ComputingResource computingResource = computingResourceDao.queryById(resourceOccupy.getComputingResourceId()); | |||||
| if (Constant.Computing_Resource_GPU.equals(computingResource.getComputingResource())) { | |||||
| resourceOccupyDao.updateUnUsed(computingResource.getResourceId(), computingResource.getGpuNums()); | |||||
| } else { | |||||
| resourceOccupyDao.updateUnUsed(computingResource.getResourceId(), computingResource.getCpuCores()); | |||||
| } | |||||
| } | } | ||||
| @Override | @Override | ||||
| @@ -74,5 +86,8 @@ public class ResourceOccupyServiceImpl implements ResourceOccupyService { | |||||
| float deduceCredit = resourceOccupy.getCreditPerHour() * hours; | float deduceCredit = resourceOccupy.getCreditPerHour() * hours; | ||||
| resourceOccupyDao.deduceCredit(deduceCredit, resourceOccupy.getUserId()); | resourceOccupyDao.deduceCredit(deduceCredit, resourceOccupy.getUserId()); | ||||
| resourceOccupy.setDeduceLastTime(new Date()); | |||||
| resourceOccupyDao.edit(resourceOccupy); | |||||
| } | } | ||||
| } | } | ||||
| @@ -120,6 +120,9 @@ public class ServiceServiceImpl implements ServiceService { | |||||
| throw new RuntimeException("服务版本已存在,无法新增"); | throw new RuntimeException("服务版本已存在,无法新增"); | ||||
| } | } | ||||
| // 判断是否有资源 | |||||
| resourceOccupyService.haveResource(serviceVersionVo.getComputingResourceId()); | |||||
| ServiceVersion serviceVersion = getServiceVersion(serviceVersionVo); | ServiceVersion serviceVersion = getServiceVersion(serviceVersionVo); | ||||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | LoginUser loginUser = SecurityUtils.getLoginUser(); | ||||
| serviceVersion.setCreateBy(loginUser.getUsername()); | serviceVersion.setCreateBy(loginUser.getUsername()); | ||||
| @@ -139,7 +142,10 @@ public class ServiceServiceImpl implements ServiceService { | |||||
| } | } | ||||
| @Override | @Override | ||||
| public String editServiceVersion(ServiceVersionVo serviceVersionVo) { | |||||
| public String editServiceVersion(ServiceVersionVo serviceVersionVo) throws Exception { | |||||
| // 判断是否有资源 | |||||
| resourceOccupyService.haveResource(serviceVersionVo.getComputingResourceId()); | |||||
| ServiceVersion serviceVersion = getServiceVersion(serviceVersionVo); | ServiceVersion serviceVersion = getServiceVersion(serviceVersionVo); | ||||
| ServiceVersion oldServiceVersion = serviceDao.getServiceVersionById(serviceVersionVo.getId()); | ServiceVersion oldServiceVersion = serviceDao.getServiceVersionById(serviceVersionVo.getId()); | ||||
| @@ -57,6 +57,8 @@ public class RayVo { | |||||
| private String resource; | private String resource; | ||||
| private Integer computingResourceId; | |||||
| private String createBy; | private String createBy; | ||||
| private Date createTime; | private Date createTime; | ||||
| @@ -25,6 +25,18 @@ | |||||
| where user_id = #{userId} | where user_id = #{userId} | ||||
| </update> | </update> | ||||
| <update id="updateUsed"> | |||||
| update resource | |||||
| set used = used + #{used} | |||||
| where id = #{id} | |||||
| </update> | |||||
| <update id="updateUnUsed"> | |||||
| update resource | |||||
| set used = used - #{used} | |||||
| where id = #{id} | |||||
| </update> | |||||
| <select id="haveResource" resultType="java.lang.Boolean"> | <select id="haveResource" resultType="java.lang.Boolean"> | ||||
| select case when used + #{need} <= total then TRUE else FALSE end | select case when used + #{need} <= total then TRUE else FALSE end | ||||
| from resource | from resource | ||||