| @@ -131,6 +131,8 @@ public class SysUser extends BaseEntity { | |||
| private String gitLinkPassword; | |||
| private Float credit; | |||
| public SysUser() { | |||
| } | |||
| @@ -315,6 +317,14 @@ public class SysUser extends BaseEntity { | |||
| return gitLinkPassword; | |||
| } | |||
| public void setCredit(Float credit) { | |||
| this.credit = credit; | |||
| } | |||
| public Float getCredit() { | |||
| return credit; | |||
| } | |||
| @Override | |||
| public String toString() { | |||
| return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) | |||
| @@ -6,9 +6,7 @@ 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.NewDatasetService; | |||
| import com.ruoyi.platform.vo.NewDatasetVo; | |||
| import com.ruoyi.platform.vo.PodStatusVo; | |||
| import com.ruoyi.platform.vo.VersionVo; | |||
| import io.swagger.annotations.Api; | |||
| import io.swagger.annotations.ApiOperation; | |||
| import io.swagger.v3.oas.annotations.responses.ApiResponse; | |||
| @@ -19,8 +17,6 @@ import java.io.File; | |||
| import java.io.FileInputStream; | |||
| import java.io.IOException; | |||
| import java.io.InputStream; | |||
| import java.util.ArrayList; | |||
| import java.util.List; | |||
| @RestController | |||
| @RequestMapping("/jupyter") | |||
| @@ -30,6 +26,7 @@ public class JupyterController extends BaseController { | |||
| private JupyterService jupyterService; | |||
| @Resource | |||
| private NewDatasetService newDatasetService; | |||
| @GetMapping(value = "/getURL") | |||
| @ApiOperation("得到访问地址") | |||
| public GenericsAjaxResult<String> getURL() throws IOException { | |||
| @@ -47,7 +44,7 @@ public class JupyterController extends BaseController { | |||
| @ApiOperation("根据开发环境id启动jupyter pod") | |||
| @ApiResponse | |||
| public GenericsAjaxResult<String> runJupyter(@PathVariable("id") Integer id) throws Exception { | |||
| return genericsSuccess(this.jupyterService.runJupyterService(id)); | |||
| return genericsSuccess(this.jupyterService.runJupyterService(id)); | |||
| } | |||
| @@ -68,7 +65,7 @@ public class JupyterController extends BaseController { | |||
| @ApiOperation("查询jupyter pod状态") | |||
| @ApiResponse | |||
| public GenericsAjaxResult<PodStatusVo> getStatus(DevEnvironment devEnvironment) throws Exception { | |||
| return genericsSuccess(this.jupyterService.getJupyterStatus(devEnvironment)); | |||
| return genericsSuccess(this.jupyterService.getJupyterStatus(devEnvironment)); | |||
| } | |||
| @@ -3,9 +3,10 @@ package com.ruoyi.platform.domain; | |||
| import com.fasterxml.jackson.databind.PropertyNamingStrategy; | |||
| import com.fasterxml.jackson.databind.annotation.JsonNaming; | |||
| import io.swagger.annotations.ApiModelProperty; | |||
| import lombok.Data; | |||
| import java.util.Date; | |||
| import java.io.Serializable; | |||
| import java.util.Date; | |||
| /** | |||
| * (ComputingResource)实体类 | |||
| @@ -14,13 +15,17 @@ import java.io.Serializable; | |||
| * @since 2023-11-29 14:23:01 | |||
| */ | |||
| @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) | |||
| @Data | |||
| public class ComputingResource implements Serializable { | |||
| private static final long serialVersionUID = -42500298368776666L; | |||
| /** | |||
| /** | |||
| * 主键 | |||
| */ | |||
| @ApiModelProperty(value = "编号", notes = "唯一标识符") | |||
| private Integer id; | |||
| @ApiModelProperty(value = "编号", notes = "唯一标识符") | |||
| private Integer id; | |||
| @ApiModelProperty("资源id") | |||
| private Integer resourceId; | |||
| @ApiModelProperty("计算资源的描述") | |||
| private String computingResource; | |||
| @@ -31,6 +36,24 @@ private Integer id; | |||
| @ApiModelProperty("资源的详细描述") | |||
| private String description; | |||
| @ApiModelProperty("cpu核数") | |||
| private Integer cpuCores; | |||
| @ApiModelProperty("内存大小GB") | |||
| private Integer memoryGb; | |||
| @ApiModelProperty("显存大小GB") | |||
| private Integer gpuMemoryGb; | |||
| @ApiModelProperty("GPU个数") | |||
| private Integer gpuNums; | |||
| @ApiModelProperty("积分/小时") | |||
| private Float creditPerHour; | |||
| @ApiModelProperty("标签") | |||
| private String labels; | |||
| @ApiModelProperty(value = "创建者的用户名", example = "admin") | |||
| private String createBy; | |||
| @@ -46,100 +69,8 @@ private Integer id; | |||
| @ApiModelProperty(value = "状态标识", notes = "0表示失效,1表示生效") | |||
| private Integer state; | |||
| @ApiModelProperty(value = "占用情况(1-占用,0-未占用)") | |||
| private Integer usedState; | |||
| @ApiModelProperty(value = "节点") | |||
| private String node; | |||
| public Integer getId() { | |||
| return id; | |||
| } | |||
| public void setId(Integer id) { | |||
| this.id = id; | |||
| } | |||
| public String getComputingResource() { | |||
| return computingResource; | |||
| } | |||
| public void setComputingResource(String computingResource) { | |||
| this.computingResource = computingResource; | |||
| } | |||
| public String getStandard() { | |||
| return standard; | |||
| } | |||
| public void setStandard(String standard) { | |||
| this.standard = standard; | |||
| } | |||
| public String getDescription() { | |||
| return description; | |||
| } | |||
| public void setDescription(String description) { | |||
| this.description = description; | |||
| } | |||
| public String getCreateBy() { | |||
| return createBy; | |||
| } | |||
| public void setCreateBy(String createBy) { | |||
| this.createBy = createBy; | |||
| } | |||
| public Date getCreateTime() { | |||
| return createTime; | |||
| } | |||
| public void setCreateTime(Date createTime) { | |||
| this.createTime = createTime; | |||
| } | |||
| public String getUpdateBy() { | |||
| return updateBy; | |||
| } | |||
| public void setUpdateBy(String updateBy) { | |||
| this.updateBy = updateBy; | |||
| } | |||
| public Date getUpdateTime() { | |||
| return updateTime; | |||
| } | |||
| public void setUpdateTime(Date updateTime) { | |||
| this.updateTime = updateTime; | |||
| } | |||
| public Integer getState() { | |||
| return state; | |||
| } | |||
| public void setState(Integer state) { | |||
| this.state = state; | |||
| } | |||
| public Integer getUsedState() { | |||
| return usedState; | |||
| } | |||
| public void setUsedState(Integer usedState) { | |||
| this.usedState = usedState; | |||
| } | |||
| public String getNode() { | |||
| return node; | |||
| } | |||
| public void setNode(String node) { | |||
| this.node = node; | |||
| } | |||
| } | |||
| @@ -0,0 +1,25 @@ | |||
| package com.ruoyi.platform.domain; | |||
| import com.fasterxml.jackson.databind.PropertyNamingStrategy; | |||
| import com.fasterxml.jackson.databind.annotation.JsonNaming; | |||
| import io.swagger.annotations.ApiModelProperty; | |||
| import lombok.Data; | |||
| @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) | |||
| @Data | |||
| public class Resource { | |||
| @ApiModelProperty(value = "编号", notes = "唯一标识符") | |||
| private Integer id; | |||
| @ApiModelProperty("类型") | |||
| private String type; | |||
| @ApiModelProperty("gpu") | |||
| private String gpu; | |||
| @ApiModelProperty("总数") | |||
| private Integer total; | |||
| @ApiModelProperty("已被占用的数量") | |||
| private Integer used; | |||
| } | |||
| @@ -0,0 +1,39 @@ | |||
| package com.ruoyi.platform.domain; | |||
| import com.fasterxml.jackson.databind.PropertyNamingStrategy; | |||
| import com.fasterxml.jackson.databind.annotation.JsonNaming; | |||
| import io.swagger.annotations.ApiModelProperty; | |||
| import lombok.Data; | |||
| import java.util.Date; | |||
| @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) | |||
| @Data | |||
| public class ResourceOccupy { | |||
| @ApiModelProperty(value = "编号", notes = "唯一标识符") | |||
| private Integer id; | |||
| @ApiModelProperty("用户") | |||
| private Long userId; | |||
| @ApiModelProperty("计算资源") | |||
| private Integer computingResourceId; | |||
| @ApiModelProperty("积分/小时") | |||
| private Float creditPerHour; | |||
| @ApiModelProperty("上一次扣分时间") | |||
| private Date deduceLastTime; | |||
| @ApiModelProperty("状态") | |||
| private Integer state; | |||
| @ApiModelProperty("开始时间") | |||
| private Date startTime; | |||
| @ApiModelProperty("任务类型") | |||
| private String taskType; | |||
| @ApiModelProperty("类型id") | |||
| private Integer taskId; | |||
| } | |||
| @@ -0,0 +1,15 @@ | |||
| package com.ruoyi.platform.mapper; | |||
| import com.ruoyi.platform.domain.ResourceOccupy; | |||
| import org.apache.ibatis.annotations.Param; | |||
| public interface ResourceOccupyDao { | |||
| Boolean haveResource(@Param("id") Integer id, @Param("need") Integer need); | |||
| int save(@Param("resourceOccupy") ResourceOccupy resourceOccupy); | |||
| int edit(@Param("resourceOccupy") ResourceOccupy resourceOccupy); | |||
| ResourceOccupy getResourceOccupyById(@Param("id") Integer id); | |||
| } | |||
| @@ -0,0 +1,13 @@ | |||
| package com.ruoyi.platform.service; | |||
| public interface ResourceOccupyService { | |||
| Boolean haveResource(Integer computingResourceId) throws Exception; | |||
| void startDeduce(Integer computingResourceId); | |||
| void endDeduce(Integer id); | |||
| void deducing(); | |||
| } | |||
| @@ -0,0 +1,71 @@ | |||
| package com.ruoyi.platform.service.impl; | |||
| import com.ruoyi.common.security.utils.SecurityUtils; | |||
| import com.ruoyi.platform.constant.Constant; | |||
| import com.ruoyi.platform.domain.ComputingResource; | |||
| import com.ruoyi.platform.domain.ResourceOccupy; | |||
| import com.ruoyi.platform.mapper.ComputingResourceDao; | |||
| import com.ruoyi.platform.mapper.ResourceOccupyDao; | |||
| import com.ruoyi.platform.service.ResourceOccupyService; | |||
| import com.ruoyi.system.api.model.LoginUser; | |||
| import org.springframework.stereotype.Service; | |||
| import javax.annotation.Resource; | |||
| import java.util.Date; | |||
| @Service("resourceOccupyService") | |||
| public class ResourceOccupyServiceImpl implements ResourceOccupyService { | |||
| @Resource | |||
| private ResourceOccupyDao resourceOccupyDao; | |||
| @Resource | |||
| private ComputingResourceDao computingResourceDao; | |||
| @Override | |||
| public Boolean haveResource(Integer computingResourceId) throws Exception { | |||
| ComputingResource computingResource = computingResourceDao.queryById(computingResourceId); | |||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | |||
| if (loginUser.getSysUser().getCredit() < computingResource.getCreditPerHour()) { | |||
| throw new Exception("积分不足"); | |||
| } | |||
| if (Constant.Computing_Resource_GPU.equals(computingResource.getComputingResource())) { | |||
| if (resourceOccupyDao.haveResource(computingResource.getResourceId(), computingResource.getGpuNums())) { | |||
| return true; | |||
| } else { | |||
| throw new Exception("资源不足,GPU资源已被占用"); | |||
| } | |||
| } else { | |||
| if (resourceOccupyDao.haveResource(computingResource.getResourceId(), computingResource.getCpuCores())) { | |||
| return true; | |||
| } else { | |||
| throw new Exception("资源不足,CPU资源已被占用完"); | |||
| } | |||
| } | |||
| } | |||
| @Override | |||
| public void startDeduce(Integer computingResourceId) { | |||
| ResourceOccupy resourceOccupy = new ResourceOccupy(); | |||
| ComputingResource computingResource = computingResourceDao.queryById(computingResourceId); | |||
| resourceOccupy.setComputingResourceId(computingResourceId); | |||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | |||
| resourceOccupy.setUserId(loginUser.getUserid()); | |||
| resourceOccupy.setCreditPerHour(computingResource.getCreditPerHour()); | |||
| resourceOccupyDao.save(resourceOccupy); | |||
| } | |||
| @Override | |||
| public void endDeduce(Integer id) { | |||
| ResourceOccupy resourceOccupy = resourceOccupyDao.getResourceOccupyById(id); | |||
| resourceOccupy.setState(Constant.State_invalid); | |||
| deducing(); | |||
| resourceOccupy.setDeduceLastTime(new Date()); | |||
| resourceOccupyDao.edit(resourceOccupy); | |||
| } | |||
| @Override | |||
| public void deducing() { | |||
| } | |||
| } | |||
| @@ -2,30 +2,22 @@ | |||
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||
| <mapper namespace="com.ruoyi.platform.mapper.ComputingResourceDao"> | |||
| <resultMap type="com.ruoyi.platform.domain.ComputingResource" id="ComputingResourceMap"> | |||
| <result property="id" column="id" jdbcType="INTEGER"/> | |||
| <result property="computingResource" column="computing_resource" jdbcType="VARCHAR"/> | |||
| <result property="standard" column="standard" jdbcType="VARCHAR"/> | |||
| <result property="description" column="description" jdbcType="VARCHAR"/> | |||
| <result property="createBy" column="create_by" jdbcType="VARCHAR"/> | |||
| <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/> | |||
| <result property="updateBy" column="update_by" jdbcType="VARCHAR"/> | |||
| <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/> | |||
| <result property="state" column="state" jdbcType="INTEGER"/> | |||
| </resultMap> | |||
| <!--查询单个--> | |||
| <select id="queryById" resultMap="ComputingResourceMap"> | |||
| <select id="queryById" resultType="com.ruoyi.platform.domain.ComputingResource"> | |||
| select | |||
| id,computing_resource,standard,description,create_by,create_time,update_by,update_time,state | |||
| id,resource_id,computing_resource,standard,description, | |||
| cpu_cores,memory_gb,gpu_memory_gb,gpu_nums,credit_per_hour,labels, | |||
| create_by,create_time,update_by,update_time,state | |||
| from computing_resource | |||
| where id = #{id} and state = 1 | |||
| </select> | |||
| <!--查询指定行数据--> | |||
| <select id="queryAllByLimit" resultMap="ComputingResourceMap"> | |||
| <select id="queryAllByLimit" resultType="com.ruoyi.platform.domain.ComputingResource"> | |||
| select | |||
| id,computing_resource,standard,description,create_by,create_time,update_by,update_time,state | |||
| id,resource_id,computing_resource,standard,description, | |||
| cpu_cores,memory_gb,gpu_memory_gb,gpu_nums,credit_per_hour,labels, | |||
| create_by,create_time,update_by,update_time,state | |||
| from computing_resource | |||
| <where> | |||
| state = 1 | |||
| @@ -0,0 +1,31 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | |||
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||
| <mapper namespace="com.ruoyi.platform.mapper.ResourceOccupyDao"> | |||
| <insert id="save"> | |||
| insert into resource_occupy (user_id, computing_resource_id, credit_per_hour) | |||
| values (#{resourceOccupy.userId}, #{resourceOccupy.computingResourceId}, #{resourceOccupy.creditPerHour}) | |||
| </insert> | |||
| <update id="edit"> | |||
| update resource_occupy | |||
| <set> | |||
| <if test="resourceOccupy.state != null"> | |||
| state = #{resourceOccupy.state}, | |||
| </if> | |||
| <if test="resourceOccupy.deduceLastTime != null"> | |||
| deduce_last_time = #{resourceOccupy.deduceLastTime}, | |||
| </if> | |||
| </set> | |||
| where id = #{resourceOccupy.id} | |||
| </update> | |||
| <select id="haveResource" resultType="java.lang.Boolean"> | |||
| select case when used + #{need} <= total then TRUE else FALSE end | |||
| from resource | |||
| where id = #{id} | |||
| </select> | |||
| <select id="getResourceOccupyById" resultType="com.ruoyi.platform.domain.ResourceOccupy"> | |||
| select * from resource_occupy where id = #{id} | |||
| </select> | |||
| </mapper> | |||