| @@ -131,6 +131,8 @@ public class SysUser extends BaseEntity { | |||||
| private String gitLinkPassword; | private String gitLinkPassword; | ||||
| private Float credit; | |||||
| public SysUser() { | public SysUser() { | ||||
| } | } | ||||
| @@ -315,6 +317,14 @@ public class SysUser extends BaseEntity { | |||||
| return gitLinkPassword; | return gitLinkPassword; | ||||
| } | } | ||||
| public void setCredit(Float credit) { | |||||
| this.credit = credit; | |||||
| } | |||||
| public Float getCredit() { | |||||
| return credit; | |||||
| } | |||||
| @Override | @Override | ||||
| public String toString() { | public String toString() { | ||||
| return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) | return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) | ||||
| @@ -49,4 +49,12 @@ public class Constant { | |||||
| public final static String Asset_Type_Image = "image"; | public final static String Asset_Type_Image = "image"; | ||||
| public final static String Asset_Type_Code = "code"; | public final static String Asset_Type_Code = "code"; | ||||
| public final static String Asset_Type_Service = "service"; | public final static String Asset_Type_Service = "service"; | ||||
| // 任务类型 | |||||
| public final static String TaskType_Dev = "dev_environment"; | |||||
| public final static String TaskType_Workflow = "workflow"; | |||||
| public final static String TaskType_AutoMl = "auto_ml"; | |||||
| public final static String TaskType_Ray = "ray"; | |||||
| public final static String TaskType_ActiveLearn = "active_learn"; | |||||
| public final static String TaskType_Service = "service"; | |||||
| } | } | ||||
| @@ -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)); | ||||
| } | } | ||||
| @@ -6,9 +6,7 @@ import com.ruoyi.common.core.web.domain.GenericsAjaxResult; | |||||
| import com.ruoyi.platform.domain.DevEnvironment; | import com.ruoyi.platform.domain.DevEnvironment; | ||||
| import com.ruoyi.platform.service.JupyterService; | import com.ruoyi.platform.service.JupyterService; | ||||
| import com.ruoyi.platform.service.NewDatasetService; | import com.ruoyi.platform.service.NewDatasetService; | ||||
| import com.ruoyi.platform.vo.NewDatasetVo; | |||||
| import com.ruoyi.platform.vo.PodStatusVo; | import com.ruoyi.platform.vo.PodStatusVo; | ||||
| import com.ruoyi.platform.vo.VersionVo; | |||||
| import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||
| import io.swagger.annotations.ApiOperation; | import io.swagger.annotations.ApiOperation; | ||||
| import io.swagger.v3.oas.annotations.responses.ApiResponse; | import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||||
| @@ -19,8 +17,6 @@ import java.io.File; | |||||
| import java.io.FileInputStream; | import java.io.FileInputStream; | ||||
| import java.io.IOException; | import java.io.IOException; | ||||
| import java.io.InputStream; | import java.io.InputStream; | ||||
| import java.util.ArrayList; | |||||
| import java.util.List; | |||||
| @RestController | @RestController | ||||
| @RequestMapping("/jupyter") | @RequestMapping("/jupyter") | ||||
| @@ -30,6 +26,7 @@ public class JupyterController extends BaseController { | |||||
| private JupyterService jupyterService; | private JupyterService jupyterService; | ||||
| @Resource | @Resource | ||||
| private NewDatasetService newDatasetService; | private NewDatasetService newDatasetService; | ||||
| @GetMapping(value = "/getURL") | @GetMapping(value = "/getURL") | ||||
| @ApiOperation("得到访问地址") | @ApiOperation("得到访问地址") | ||||
| public GenericsAjaxResult<String> getURL() throws IOException { | public GenericsAjaxResult<String> getURL() throws IOException { | ||||
| @@ -47,7 +44,7 @@ public class JupyterController extends BaseController { | |||||
| @ApiOperation("根据开发环境id启动jupyter pod") | @ApiOperation("根据开发环境id启动jupyter pod") | ||||
| @ApiResponse | @ApiResponse | ||||
| public GenericsAjaxResult<String> runJupyter(@PathVariable("id") Integer id) throws Exception { | 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状态") | @ApiOperation("查询jupyter pod状态") | ||||
| @ApiResponse | @ApiResponse | ||||
| public GenericsAjaxResult<PodStatusVo> getStatus(DevEnvironment devEnvironment) throws Exception { | public GenericsAjaxResult<PodStatusVo> getStatus(DevEnvironment devEnvironment) throws Exception { | ||||
| return genericsSuccess(this.jupyterService.getJupyterStatus(devEnvironment)); | |||||
| return genericsSuccess(this.jupyterService.getJupyterStatus(devEnvironment)); | |||||
| } | } | ||||
| @@ -3,7 +3,9 @@ package com.ruoyi.platform.controller.resources; | |||||
| import com.ruoyi.common.core.web.controller.BaseController; | import com.ruoyi.common.core.web.controller.BaseController; | ||||
| import com.ruoyi.common.core.web.domain.GenericsAjaxResult; | import com.ruoyi.common.core.web.domain.GenericsAjaxResult; | ||||
| import com.ruoyi.platform.domain.ComputingResource; | import com.ruoyi.platform.domain.ComputingResource; | ||||
| import com.ruoyi.platform.domain.ResourceOccupy; | |||||
| import com.ruoyi.platform.service.ComputingResourceService; | import com.ruoyi.platform.service.ComputingResourceService; | ||||
| import com.ruoyi.platform.service.ResourceOccupyService; | |||||
| import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||
| import io.swagger.annotations.ApiOperation; | import io.swagger.annotations.ApiOperation; | ||||
| import org.springframework.data.domain.Page; | import org.springframework.data.domain.Page; | ||||
| @@ -28,6 +30,9 @@ public class ComputingResourceController extends BaseController { | |||||
| @Resource | @Resource | ||||
| private ComputingResourceService computingResourceService; | private ComputingResourceService computingResourceService; | ||||
| @Resource | |||||
| private ResourceOccupyService resourceOccupyService; | |||||
| /** | /** | ||||
| * 分页查询 | * 分页查询 | ||||
| * | * | ||||
| @@ -36,12 +41,12 @@ public class ComputingResourceController extends BaseController { | |||||
| */ | */ | ||||
| @GetMapping | @GetMapping | ||||
| @ApiOperation("分页查询") | @ApiOperation("分页查询") | ||||
| public GenericsAjaxResult<Page<ComputingResource>> queryByPage(ComputingResource computingResource, @RequestParam("page") int page, | |||||
| public GenericsAjaxResult<Page<ComputingResource>> queryByPage(ComputingResource computingResource, @RequestParam("page") int page, | |||||
| @RequestParam("size") int size, | @RequestParam("size") int size, | ||||
| @RequestParam(value = "resource_type") String resourceType ) { | |||||
| @RequestParam(value = "resource_type") String resourceType) { | |||||
| computingResource.setComputingResource(resourceType); | computingResource.setComputingResource(resourceType); | ||||
| PageRequest pageRequest = PageRequest.of(page,size); | |||||
| return genericsSuccess(this.computingResourceService.queryByPage(computingResource, pageRequest)); | |||||
| PageRequest pageRequest = PageRequest.of(page, size); | |||||
| return genericsSuccess(this.computingResourceService.queryByPage(computingResource, pageRequest)); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -53,7 +58,7 @@ public class ComputingResourceController extends BaseController { | |||||
| @GetMapping("{id}") | @GetMapping("{id}") | ||||
| @ApiOperation("根据id查询") | @ApiOperation("根据id查询") | ||||
| public GenericsAjaxResult<ComputingResource> queryById(@PathVariable("id") Integer id) { | public GenericsAjaxResult<ComputingResource> queryById(@PathVariable("id") Integer id) { | ||||
| return genericsSuccess(this.computingResourceService.queryById(id)); | |||||
| return genericsSuccess(this.computingResourceService.queryById(id)); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -65,7 +70,7 @@ public class ComputingResourceController extends BaseController { | |||||
| @PostMapping | @PostMapping | ||||
| @ApiOperation("新增计算资源") | @ApiOperation("新增计算资源") | ||||
| public GenericsAjaxResult<ComputingResource> add(@RequestBody ComputingResource computingResource) { | public GenericsAjaxResult<ComputingResource> add(@RequestBody ComputingResource computingResource) { | ||||
| return genericsSuccess(this.computingResourceService.insert(computingResource)); | |||||
| return genericsSuccess(this.computingResourceService.insert(computingResource)); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -77,7 +82,7 @@ public class ComputingResourceController extends BaseController { | |||||
| @PutMapping | @PutMapping | ||||
| @ApiOperation("编辑计算资源") | @ApiOperation("编辑计算资源") | ||||
| public GenericsAjaxResult<ComputingResource> edit(@RequestBody ComputingResource computingResource) { | public GenericsAjaxResult<ComputingResource> edit(@RequestBody ComputingResource computingResource) { | ||||
| return genericsSuccess(this.computingResourceService.update(computingResource)); | |||||
| return genericsSuccess(this.computingResourceService.update(computingResource)); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -89,8 +94,15 @@ public class ComputingResourceController extends BaseController { | |||||
| @DeleteMapping("{id}") | @DeleteMapping("{id}") | ||||
| @ApiOperation("删除计算资源") | @ApiOperation("删除计算资源") | ||||
| public GenericsAjaxResult<String> deleteById(@PathVariable("id") Integer id) { | public GenericsAjaxResult<String> deleteById(@PathVariable("id") Integer id) { | ||||
| return genericsSuccess(this.computingResourceService.removeById(id)); | |||||
| return genericsSuccess(this.computingResourceService.removeById(id)); | |||||
| } | } | ||||
| @GetMapping("/resouceOccupy") | |||||
| @ApiOperation("分页查询用户资源使用情况") | |||||
| public GenericsAjaxResult<Page<ResourceOccupy>> queryResourceOccupyByPage(@RequestParam("page") int page, | |||||
| @RequestParam("size") int size) { | |||||
| PageRequest pageRequest = PageRequest.of(page, size); | |||||
| return genericsSuccess(resourceOccupyService.queryByPage(pageRequest)); | |||||
| } | |||||
| } | } | ||||
| @@ -61,7 +61,7 @@ public class ServiceController extends BaseController { | |||||
| @PostMapping("/serviceVersion") | @PostMapping("/serviceVersion") | ||||
| @ApiOperation("新增服务版本") | @ApiOperation("新增服务版本") | ||||
| public GenericsAjaxResult<ServiceVersion> addServiceVersion(@RequestBody ServiceVersionVo serviceVersionVo) { | |||||
| public GenericsAjaxResult<ServiceVersion> addServiceVersion(@RequestBody ServiceVersionVo serviceVersionVo) throws Exception { | |||||
| return genericsSuccess(serviceService.addServiceVersion(serviceVersionVo)); | return genericsSuccess(serviceService.addServiceVersion(serviceVersionVo)); | ||||
| } | } | ||||
| @@ -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)); | ||||
| } | } | ||||
| @@ -3,9 +3,10 @@ package com.ruoyi.platform.domain; | |||||
| import com.fasterxml.jackson.databind.PropertyNamingStrategy; | import com.fasterxml.jackson.databind.PropertyNamingStrategy; | ||||
| import com.fasterxml.jackson.databind.annotation.JsonNaming; | import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||||
| import io.swagger.annotations.ApiModelProperty; | import io.swagger.annotations.ApiModelProperty; | ||||
| import lombok.Data; | |||||
| import java.util.Date; | |||||
| import java.io.Serializable; | import java.io.Serializable; | ||||
| import java.util.Date; | |||||
| /** | /** | ||||
| * (ComputingResource)实体类 | * (ComputingResource)实体类 | ||||
| @@ -14,13 +15,17 @@ import java.io.Serializable; | |||||
| * @since 2023-11-29 14:23:01 | * @since 2023-11-29 14:23:01 | ||||
| */ | */ | ||||
| @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) | @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) | ||||
| @Data | |||||
| public class ComputingResource implements Serializable { | public class ComputingResource implements Serializable { | ||||
| private static final long serialVersionUID = -42500298368776666L; | private static final long serialVersionUID = -42500298368776666L; | ||||
| /** | |||||
| /** | |||||
| * 主键 | * 主键 | ||||
| */ | */ | ||||
| @ApiModelProperty(value = "编号", notes = "唯一标识符") | |||||
| private Integer id; | |||||
| @ApiModelProperty(value = "编号", notes = "唯一标识符") | |||||
| private Integer id; | |||||
| @ApiModelProperty("资源id") | |||||
| private Integer resourceId; | |||||
| @ApiModelProperty("计算资源的描述") | @ApiModelProperty("计算资源的描述") | ||||
| private String computingResource; | private String computingResource; | ||||
| @@ -31,6 +36,24 @@ private Integer id; | |||||
| @ApiModelProperty("资源的详细描述") | @ApiModelProperty("资源的详细描述") | ||||
| private String description; | 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") | @ApiModelProperty(value = "创建者的用户名", example = "admin") | ||||
| private String createBy; | private String createBy; | ||||
| @@ -45,101 +68,5 @@ private Integer id; | |||||
| @ApiModelProperty(value = "状态标识", notes = "0表示失效,1表示生效") | @ApiModelProperty(value = "状态标识", notes = "0表示失效,1表示生效") | ||||
| private Integer state; | 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; | |||||
| } | |||||
| } | } | ||||
| @@ -2,6 +2,7 @@ package com.ruoyi.platform.domain; | |||||
| import com.fasterxml.jackson.databind.PropertyNamingStrategy; | import com.fasterxml.jackson.databind.PropertyNamingStrategy; | ||||
| import com.fasterxml.jackson.databind.annotation.JsonNaming; | import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||||
| import lombok.Data; | |||||
| import java.util.Date; | import java.util.Date; | ||||
| import java.io.Serializable; | import java.io.Serializable; | ||||
| @@ -13,6 +14,7 @@ import java.io.Serializable; | |||||
| * @since 2024-06-03 15:17:37 | * @since 2024-06-03 15:17:37 | ||||
| */ | */ | ||||
| @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) | @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) | ||||
| @Data | |||||
| public class DevEnvironment implements Serializable { | public class DevEnvironment implements Serializable { | ||||
| private static final long serialVersionUID = 936999018935545992L; | private static final long serialVersionUID = 936999018935545992L; | ||||
| /** | /** | ||||
| @@ -31,6 +33,9 @@ public class DevEnvironment implements Serializable { | |||||
| * 计算资源 | * 计算资源 | ||||
| */ | */ | ||||
| private String computingResource; | private String computingResource; | ||||
| private Integer computingResourceId; | |||||
| /** | /** | ||||
| * 资源规格 | * 资源规格 | ||||
| */ | */ | ||||
| @@ -80,134 +85,5 @@ public class DevEnvironment implements Serializable { | |||||
| */ | */ | ||||
| private Integer state; | private Integer state; | ||||
| public Integer getId() { | |||||
| return id; | |||||
| } | |||||
| public void setId(Integer id) { | |||||
| this.id = id; | |||||
| } | |||||
| public String getName() { | |||||
| return name; | |||||
| } | |||||
| public void setName(String name) { | |||||
| this.name = name; | |||||
| } | |||||
| public String getStatus() { | |||||
| return status; | |||||
| } | |||||
| public void setStatus(String status) { | |||||
| this.status = status; | |||||
| } | |||||
| 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 getEnvVariable() { | |||||
| return envVariable; | |||||
| } | |||||
| public void setEnvVariable(String envVariable) { | |||||
| this.envVariable = envVariable; | |||||
| } | |||||
| public String getImage() { | |||||
| return image; | |||||
| } | |||||
| public void setImage(String image) { | |||||
| this.image = image; | |||||
| } | |||||
| public String getDataset() { | |||||
| return dataset; | |||||
| } | |||||
| public void setDataset(String dataset) { | |||||
| this.dataset = dataset; | |||||
| } | |||||
| public String getModel() { | |||||
| return model; | |||||
| } | |||||
| public void setModel(String model) { | |||||
| this.model = model; | |||||
| } | |||||
| public String getUrl() { | |||||
| return url; | |||||
| } | |||||
| public void setUrl(String url) { | |||||
| this.url = url; | |||||
| } | |||||
| public String getAltField2() { | |||||
| return altField2; | |||||
| } | |||||
| public void setAltField2(String altField2) { | |||||
| this.altField2 = altField2; | |||||
| } | |||||
| 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; | |||||
| } | |||||
| } | } | ||||
| @@ -67,6 +67,8 @@ public class Ray { | |||||
| private String resource; | private String resource; | ||||
| private Integer computingResourceId; | |||||
| private Integer state; | private Integer state; | ||||
| private String createBy; | private String createBy; | ||||
| @@ -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 Long taskId; | |||||
| } | |||||
| @@ -26,6 +26,8 @@ public class ServiceVersion implements Serializable { | |||||
| private String resource; | private String resource; | ||||
| private Integer computingResourceId; | |||||
| private Integer replicas; | private Integer replicas; | ||||
| private String mountPath; | private String mountPath; | ||||
| @@ -73,8 +73,6 @@ public interface ComputingResourceDao { | |||||
| */ | */ | ||||
| int update(@Param("computingResource") ComputingResource computingResource); | int update(@Param("computingResource") ComputingResource computingResource); | ||||
| int updateUsedStateByNode(@Param("node")String node, @Param("usedState") Integer usedState); | |||||
| /** | /** | ||||
| * 通过主键删除数据 | * 通过主键删除数据 | ||||
| * | * | ||||
| @@ -46,24 +46,6 @@ public interface DevEnvironmentDao { | |||||
| */ | */ | ||||
| int insert(@Param("devEnvironment") DevEnvironment devEnvironment); | int insert(@Param("devEnvironment") DevEnvironment devEnvironment); | ||||
| /** | |||||
| * 批量新增数据(MyBatis原生foreach方法) | |||||
| * | |||||
| * @param entities List<DevEnvironment> 实例对象列表 | |||||
| * @return 影响行数 | |||||
| */ | |||||
| int insertBatch(@Param("entities") List<DevEnvironment> entities); | |||||
| /** | |||||
| * 批量新增或按主键更新数据(MyBatis原生foreach方法) | |||||
| * | |||||
| * @param entities List<DevEnvironment> 实例对象列表 | |||||
| * | |||||
| * @return 影响行数 | |||||
| * @throws org.springframework.jdbc.BadSqlGrammarException 入参是空List的时候会抛SQL语句错误的异常,请自行校验入参 | |||||
| */ | |||||
| int insertOrUpdateBatch(@Param("entities") List<DevEnvironment> entities); | |||||
| /** | /** | ||||
| * 修改数据 | * 修改数据 | ||||
| * | * | ||||
| @@ -80,5 +62,6 @@ public interface DevEnvironmentDao { | |||||
| */ | */ | ||||
| int deleteById(Integer id); | int deleteById(Integer id); | ||||
| List<DevEnvironment> getRunning(); | |||||
| } | } | ||||
| @@ -0,0 +1,28 @@ | |||||
| package com.ruoyi.platform.mapper; | |||||
| import com.ruoyi.platform.domain.ResourceOccupy; | |||||
| import org.apache.ibatis.annotations.Param; | |||||
| import org.springframework.data.domain.Pageable; | |||||
| import java.util.List; | |||||
| 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 getResourceOccupyByTask(@Param("taskType") String taskType, @Param("taskId") Long taskId); | |||||
| 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); | |||||
| long count(); | |||||
| List<ResourceOccupy> queryByPage(@Param("pageable") Pageable pageable); | |||||
| } | |||||
| @@ -36,4 +36,6 @@ public interface ServiceDao { | |||||
| Service getServiceByName(@Param("serviceName") String serviceName); | Service getServiceByName(@Param("serviceName") String serviceName); | ||||
| ServiceVersion getSvByVersion(@Param("version") String version, @Param("serviceId") Long serviceId); | ServiceVersion getSvByVersion(@Param("version") String version, @Param("serviceId") Long serviceId); | ||||
| List<ServiceVersion> getRunning(); | |||||
| } | } | ||||
| @@ -6,6 +6,7 @@ import com.ruoyi.platform.domain.RayIns; | |||||
| import com.ruoyi.platform.mapper.RayDao; | import com.ruoyi.platform.mapper.RayDao; | ||||
| import com.ruoyi.platform.mapper.RayInsDao; | import com.ruoyi.platform.mapper.RayInsDao; | ||||
| import com.ruoyi.platform.service.RayInsService; | import com.ruoyi.platform.service.RayInsService; | ||||
| import com.ruoyi.platform.service.ResourceOccupyService; | |||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
| import org.springframework.scheduling.annotation.Scheduled; | import org.springframework.scheduling.annotation.Scheduled; | ||||
| import org.springframework.stereotype.Component; | import org.springframework.stereotype.Component; | ||||
| @@ -25,6 +26,9 @@ public class RayInsStatusTask { | |||||
| @Resource | @Resource | ||||
| private RayDao rayDao; | private RayDao rayDao; | ||||
| @Resource | |||||
| private ResourceOccupyService resourceOccupyService; | |||||
| private List<Long> rayIds = new ArrayList<>(); | private List<Long> rayIds = new ArrayList<>(); | ||||
| @Scheduled(cron = "0/30 * * * * ?") // 每30S执行一次 | @Scheduled(cron = "0/30 * * * * ?") // 每30S执行一次 | ||||
| @@ -38,6 +42,11 @@ public class RayInsStatusTask { | |||||
| //当原本状态为null或非终止态时才调用argo接口 | //当原本状态为null或非终止态时才调用argo接口 | ||||
| try { | try { | ||||
| rayIns = rayInsService.queryStatusFromArgo(rayIns); | rayIns = rayInsService.queryStatusFromArgo(rayIns); | ||||
| if (Constant.Running.equals(rayIns.getStatus())) { | |||||
| resourceOccupyService.deducing(Constant.TaskType_Ray, rayIns.getId()); | |||||
| } else { | |||||
| resourceOccupyService.endDeduce(Constant.TaskType_Ray, rayIns.getId()); | |||||
| } | |||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| rayIns.setStatus(Constant.Failed); | rayIns.setStatus(Constant.Failed); | ||||
| } | } | ||||
| @@ -0,0 +1,44 @@ | |||||
| package com.ruoyi.platform.scheduling; | |||||
| import com.ruoyi.platform.constant.Constant; | |||||
| import com.ruoyi.platform.domain.DevEnvironment; | |||||
| import com.ruoyi.platform.domain.ServiceVersion; | |||||
| import com.ruoyi.platform.mapper.DevEnvironmentDao; | |||||
| import com.ruoyi.platform.mapper.ServiceDao; | |||||
| import com.ruoyi.platform.service.ResourceOccupyService; | |||||
| import org.springframework.scheduling.annotation.Scheduled; | |||||
| import org.springframework.stereotype.Component; | |||||
| import javax.annotation.Resource; | |||||
| import java.util.List; | |||||
| @Component() | |||||
| public class ResourceOccupyTask { | |||||
| @Resource | |||||
| private ResourceOccupyService resourceOccupyService; | |||||
| @Resource | |||||
| private DevEnvironmentDao devEnvironmentDao; | |||||
| @Resource | |||||
| private ServiceDao serviceDao; | |||||
| // 开发环境功能扣除积分 | |||||
| @Scheduled(cron = "0 0/10 * * * ?") // 每10分钟执行一次 | |||||
| public void devDeduceCredit() { | |||||
| List<DevEnvironment> devEnvironments = devEnvironmentDao.getRunning(); | |||||
| for (DevEnvironment devEnvironment : devEnvironments) { | |||||
| resourceOccupyService.deducing(Constant.TaskType_Dev, Long.valueOf(devEnvironment.getId())); | |||||
| } | |||||
| } | |||||
| // 服务功能扣除积分 | |||||
| @Scheduled(cron = "0 0/10 * * * ?") // 每10分钟执行一次 | |||||
| public void serviceDeduceCredit() { | |||||
| List<ServiceVersion> serviceVersions = serviceDao.getRunning(); | |||||
| for (ServiceVersion serviceVersion : serviceVersions) { | |||||
| resourceOccupyService.deducing(Constant.TaskType_Service, serviceVersion.getId()); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -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; | |||||
| /** | /** | ||||
| * 通过主键删除数据 | * 通过主键删除数据 | ||||
| @@ -0,0 +1,18 @@ | |||||
| package com.ruoyi.platform.service; | |||||
| import com.ruoyi.platform.domain.ResourceOccupy; | |||||
| import org.springframework.data.domain.Page; | |||||
| import org.springframework.data.domain.PageRequest; | |||||
| public interface ResourceOccupyService { | |||||
| Boolean haveResource(Integer computingResourceId) throws Exception; | |||||
| void startDeduce(Integer computingResourceId, String taskType, Long taskId); | |||||
| void endDeduce(String taskType, Long taskId); | |||||
| void deducing(String taskType, Long taskId); | |||||
| Page<ResourceOccupy> queryByPage(PageRequest pageRequest); | |||||
| } | |||||
| @@ -18,11 +18,11 @@ public interface ServiceService { | |||||
| Service addService(Service service); | Service addService(Service service); | ||||
| ServiceVersion addServiceVersion(ServiceVersionVo serviceVersionVo); | |||||
| ServiceVersion addServiceVersion(ServiceVersionVo serviceVersionVo) throws Exception; | |||||
| 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); | ||||
| @@ -34,7 +34,7 @@ public interface ServiceService { | |||||
| String deleteServiceVersion(Long id); | String deleteServiceVersion(Long id); | ||||
| String runServiceVersion(Long id); | |||||
| String runServiceVersion(Long id) throws Exception; | |||||
| String stopServiceVersion(Long id); | String stopServiceVersion(Long id); | ||||
| @@ -10,18 +10,16 @@ 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; | ||||
| import com.ruoyi.system.api.model.LoginUser; | import com.ruoyi.system.api.model.LoginUser; | ||||
| 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.context.annotation.Lazy; | ||||
| 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; | ||||
| import org.springframework.data.domain.PageRequest; | import org.springframework.data.domain.PageRequest; | ||||
| import org.springframework.stereotype.Service; | |||||
| import javax.annotation.Resource; | import javax.annotation.Resource; | ||||
| import java.util.Date; | import java.util.Date; | ||||
| import java.util.List; | import java.util.List; | ||||
| import java.util.Map; | |||||
| /** | /** | ||||
| * (DevEnvironment)表服务实现类 | * (DevEnvironment)表服务实现类 | ||||
| @@ -37,8 +35,6 @@ public class DevEnvironmentServiceImpl implements DevEnvironmentService { | |||||
| @Resource | @Resource | ||||
| @Lazy | @Lazy | ||||
| private JupyterService jupyterService; | private JupyterService jupyterService; | ||||
| /** | /** | ||||
| * 通过ID查询单条数据 | * 通过ID查询单条数据 | ||||
| * | * | ||||
| @@ -54,7 +50,7 @@ public class DevEnvironmentServiceImpl implements DevEnvironmentService { | |||||
| * 分页查询 | * 分页查询 | ||||
| * | * | ||||
| * @param devEnvironment 筛选条件 | * @param devEnvironment 筛选条件 | ||||
| * @param pageRequest 分页对象 | |||||
| * @param pageRequest 分页对象 | |||||
| * @return 查询结果 | * @return 查询结果 | ||||
| */ | */ | ||||
| @Override | @Override | ||||
| @@ -64,12 +60,15 @@ public class DevEnvironmentServiceImpl implements DevEnvironmentService { | |||||
| //查询每个开发环境的pod状态,注意:只有pod为非终止态时才去调状态接口 | //查询每个开发环境的pod状态,注意:只有pod为非终止态时才去调状态接口 | ||||
| devEnvironmentList.forEach(devEnv -> { | devEnvironmentList.forEach(devEnv -> { | ||||
| try{ | |||||
| try { | |||||
| if (!devEnv.getStatus().equals(PodStatus.Terminated.getName()) && | if (!devEnv.getStatus().equals(PodStatus.Terminated.getName()) && | ||||
| !devEnv.getStatus().equals(PodStatus.Failed.getName())) { | !devEnv.getStatus().equals(PodStatus.Failed.getName())) { | ||||
| PodStatusVo podStatusVo = this.jupyterService.getJupyterStatus(devEnv); | PodStatusVo podStatusVo = this.jupyterService.getJupyterStatus(devEnv); | ||||
| devEnv.setStatus(podStatusVo.getStatus()); | devEnv.setStatus(podStatusVo.getStatus()); | ||||
| devEnv.setUrl(podStatusVo.getUrl()); | devEnv.setUrl(podStatusVo.getUrl()); | ||||
| if(!devEnv.getStatus().equals(podStatusVo.getStatus())){ | |||||
| this.devEnvironmentDao.update(devEnv); | |||||
| } | |||||
| } | } | ||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| devEnv.setStatus(PodStatus.Unknown.getName()); | devEnv.setStatus(PodStatus.Unknown.getName()); | ||||
| @@ -86,7 +85,7 @@ public class DevEnvironmentServiceImpl implements DevEnvironmentService { | |||||
| * @return 实例对象 | * @return 实例对象 | ||||
| */ | */ | ||||
| @Override | @Override | ||||
| public DevEnvironment insert(DevEnvironmentVo devEnvironmentVo) { | |||||
| public DevEnvironment insert(DevEnvironmentVo devEnvironmentVo) throws Exception { | |||||
| //插入预备,此时不需要判断版本重复 | //插入预备,此时不需要判断版本重复 | ||||
| DevEnvironment devEnvironment = new DevEnvironment(); | DevEnvironment devEnvironment = new DevEnvironment(); | ||||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | LoginUser loginUser = SecurityUtils.getLoginUser(); | ||||
| @@ -94,6 +93,7 @@ public class DevEnvironmentServiceImpl implements DevEnvironmentService { | |||||
| //状态先设为未知 | //状态先设为未知 | ||||
| devEnvironment.setStatus("Unknown"); | devEnvironment.setStatus("Unknown"); | ||||
| devEnvironment.setComputingResource(devEnvironmentVo.getComputingResource()); | devEnvironment.setComputingResource(devEnvironmentVo.getComputingResource()); | ||||
| devEnvironment.setComputingResourceId(devEnvironmentVo.getComputingResourceId()); | |||||
| devEnvironment.setStandard(devEnvironmentVo.getStandard()); | devEnvironment.setStandard(devEnvironmentVo.getStandard()); | ||||
| devEnvironment.setEnvVariable(devEnvironmentVo.getEnvVariable()); | devEnvironment.setEnvVariable(devEnvironmentVo.getEnvVariable()); | ||||
| devEnvironment.setImage(devEnvironmentVo.getImage()); | devEnvironment.setImage(devEnvironmentVo.getImage()); | ||||
| @@ -118,7 +118,7 @@ public class DevEnvironmentServiceImpl implements DevEnvironmentService { | |||||
| * @return 实例对象 | * @return 实例对象 | ||||
| */ | */ | ||||
| @Override | @Override | ||||
| public DevEnvironment update(DevEnvironment devEnvironment) { | |||||
| public DevEnvironment update(DevEnvironment devEnvironment) throws Exception { | |||||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | LoginUser loginUser = SecurityUtils.getLoginUser(); | ||||
| devEnvironment.setUpdateBy(loginUser.getUsername()); | devEnvironment.setUpdateBy(loginUser.getUsername()); | ||||
| devEnvironment.setUpdateTime(new Date()); | devEnvironment.setUpdateTime(new Date()); | ||||
| @@ -140,7 +140,7 @@ public class DevEnvironmentServiceImpl implements DevEnvironmentService { | |||||
| @Override | @Override | ||||
| public String removeById(Integer id) throws Exception { | public String removeById(Integer id) throws Exception { | ||||
| DevEnvironment devEnvironment = this.devEnvironmentDao.queryById(id); | DevEnvironment devEnvironment = this.devEnvironmentDao.queryById(id); | ||||
| if (devEnvironment == null){ | |||||
| if (devEnvironment == null) { | |||||
| return "开发环境信息不存在"; | return "开发环境信息不存在"; | ||||
| } | } | ||||
| @@ -148,13 +148,13 @@ public class DevEnvironmentServiceImpl implements DevEnvironmentService { | |||||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | LoginUser loginUser = SecurityUtils.getLoginUser(); | ||||
| String username = loginUser.getUsername(); | String username = loginUser.getUsername(); | ||||
| String createdBy = devEnvironment.getCreateBy(); | String createdBy = devEnvironment.getCreateBy(); | ||||
| if (!(StringUtils.equals(username,"admin") || StringUtils.equals(username,createdBy))){ | |||||
| if (!(StringUtils.equals(username, "admin") || StringUtils.equals(username, createdBy))) { | |||||
| return "无权限删除该开发环境"; | return "无权限删除该开发环境"; | ||||
| } | } | ||||
| jupyterService.stopJupyterService(id); | jupyterService.stopJupyterService(id); | ||||
| devEnvironment.setState(0); | devEnvironment.setState(0); | ||||
| return this.devEnvironmentDao.update(devEnvironment)>0?"删除成功":"删除失败"; | |||||
| return this.devEnvironmentDao.update(devEnvironment) > 0 ? "删除成功" : "删除失败"; | |||||
| } | } | ||||
| @@ -46,9 +46,6 @@ import java.util.*; | |||||
| public class ExperimentServiceImpl implements ExperimentService { | public class ExperimentServiceImpl implements ExperimentService { | ||||
| @Resource | @Resource | ||||
| private ExperimentDao experimentDao; | private ExperimentDao experimentDao; | ||||
| @Resource | |||||
| private ExperimentInsDao experimentInsDao; | |||||
| @Resource | @Resource | ||||
| private ModelsService modelsService; | private ModelsService modelsService; | ||||
| @Resource | @Resource | ||||
| @@ -74,8 +71,6 @@ public class ExperimentServiceImpl implements ExperimentService { | |||||
| private String argoConvert; | private String argoConvert; | ||||
| @Value("${argo.workflowRun}") | @Value("${argo.workflowRun}") | ||||
| private String argoWorkflowRun; | private String argoWorkflowRun; | ||||
| @Value("${argo.workflowStatus}") | |||||
| private String argoWorkflowStatus; | |||||
| @Value("${git.localPath}") | @Value("${git.localPath}") | ||||
| String localPath; | String localPath; | ||||
| @@ -5,10 +5,10 @@ import com.ruoyi.common.security.utils.SecurityUtils; | |||||
| import com.ruoyi.platform.constant.Constant; | import com.ruoyi.platform.constant.Constant; | ||||
| import com.ruoyi.platform.domain.DevEnvironment; | import com.ruoyi.platform.domain.DevEnvironment; | ||||
| import com.ruoyi.platform.domain.PodStatus; | import com.ruoyi.platform.domain.PodStatus; | ||||
| import com.ruoyi.platform.mapper.ComputingResourceDao; | |||||
| 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.utils.K8sClientUtil; | import com.ruoyi.platform.utils.K8sClientUtil; | ||||
| import com.ruoyi.platform.utils.MinioUtil; | import com.ruoyi.platform.utils.MinioUtil; | ||||
| @@ -56,9 +56,6 @@ public class JupyterServiceImpl implements JupyterService { | |||||
| @Resource | @Resource | ||||
| private DevEnvironmentDao devEnvironmentDao; | private DevEnvironmentDao devEnvironmentDao; | ||||
| @Resource | |||||
| private ComputingResourceDao computingResourceDao; | |||||
| @Resource | @Resource | ||||
| @Lazy | @Lazy | ||||
| private DevEnvironmentService devEnvironmentService; | private DevEnvironmentService devEnvironmentService; | ||||
| @@ -66,6 +63,9 @@ public class JupyterServiceImpl implements JupyterService { | |||||
| @Resource | @Resource | ||||
| private RedisService redisService; | private RedisService redisService; | ||||
| @Resource | |||||
| private ResourceOccupyService resourceOccupyService; | |||||
| public JupyterServiceImpl(MinioUtil minioUtil) { | public JupyterServiceImpl(MinioUtil minioUtil) { | ||||
| this.minioUtil = minioUtil; | this.minioUtil = minioUtil; | ||||
| } | } | ||||
| @@ -109,7 +109,7 @@ public class JupyterServiceImpl implements JupyterService { | |||||
| Integer podPort = k8sClientUtil.createConfiguredPod(podName, namespace, port, mountPath, null, devEnvironment, minioPvcName, datasetPath, modelPath); | Integer podPort = k8sClientUtil.createConfiguredPod(podName, namespace, port, mountPath, null, devEnvironment, minioPvcName, datasetPath, modelPath); | ||||
| String url = masterIp + ":" + podPort; | String url = masterIp + ":" + podPort; | ||||
| redisService.setCacheObject(podName, masterIp + ":" + podPort); | redisService.setCacheObject(podName, masterIp + ":" + podPort); | ||||
| devEnvironment.setStatus("Pending"); | |||||
| devEnvironment.setStatus(Constant.Pending); | |||||
| devEnvironment.setUrl(url); | devEnvironment.setUrl(url); | ||||
| this.devEnvironmentService.update(devEnvironment); | this.devEnvironmentService.update(devEnvironment); | ||||
| return url; | return url; | ||||
| @@ -133,16 +133,15 @@ public class JupyterServiceImpl implements JupyterService { | |||||
| return "pod不存在!"; | return "pod不存在!"; | ||||
| } | } | ||||
| if (Constant.Computing_Resource_GPU.equals(devEnvironment.getComputingResource())) { | |||||
| computingResourceDao.updateUsedStateByNode(pod.getSpec().getNodeName(), Constant.Used_State_unused); | |||||
| } | |||||
| // 结束扣积分 | |||||
| resourceOccupyService.endDeduce(Constant.TaskType_Dev, Long.valueOf(id)); | |||||
| // 使用 Kubernetes API 删除 Pod | // 使用 Kubernetes API 删除 Pod | ||||
| String deleteResult = k8sClientUtil.deletePod(podName, namespace); | String deleteResult = k8sClientUtil.deletePod(podName, namespace); | ||||
| // 删除service | // 删除service | ||||
| k8sClientUtil.deleteService(svcName, namespace); | k8sClientUtil.deleteService(svcName, namespace); | ||||
| devEnvironment.setStatus("Terminated"); | |||||
| devEnvironment.setStatus(Constant.Terminated); | |||||
| this.devEnvironmentService.update(devEnvironment); | this.devEnvironmentService.update(devEnvironment); | ||||
| return deleteResult + ",编辑器已停止"; | return deleteResult + ",编辑器已停止"; | ||||
| @@ -6,6 +6,7 @@ import com.ruoyi.platform.domain.RayIns; | |||||
| import com.ruoyi.platform.mapper.RayDao; | import com.ruoyi.platform.mapper.RayDao; | ||||
| import com.ruoyi.platform.mapper.RayInsDao; | import com.ruoyi.platform.mapper.RayInsDao; | ||||
| import com.ruoyi.platform.service.RayInsService; | import com.ruoyi.platform.service.RayInsService; | ||||
| import com.ruoyi.platform.service.ResourceOccupyService; | |||||
| import com.ruoyi.platform.utils.*; | import com.ruoyi.platform.utils.*; | ||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| @@ -48,6 +49,9 @@ public class RayInsServiceImpl implements RayInsService { | |||||
| @Resource | @Resource | ||||
| private RayDao rayDao; | private RayDao rayDao; | ||||
| @Resource | |||||
| private ResourceOccupyService resourceOccupyService; | |||||
| @Resource | @Resource | ||||
| private MinioUtil minioUtil; | private MinioUtil minioUtil; | ||||
| @@ -163,6 +167,8 @@ public class RayInsServiceImpl implements RayInsService { | |||||
| ins.setUpdateTime(new Date()); | ins.setUpdateTime(new Date()); | ||||
| rayInsDao.update(ins); | rayInsDao.update(ins); | ||||
| updateRayStatus(rayIns.getRayId()); | updateRayStatus(rayIns.getRayId()); | ||||
| // 结束扣积分 | |||||
| resourceOccupyService.endDeduce(Constant.TaskType_Ray, id); | |||||
| return true; | return true; | ||||
| } else { | } else { | ||||
| return false; | return false; | ||||
| @@ -10,6 +10,7 @@ import com.ruoyi.platform.mapper.RayDao; | |||||
| import com.ruoyi.platform.mapper.RayInsDao; | import com.ruoyi.platform.mapper.RayInsDao; | ||||
| import com.ruoyi.platform.service.RayInsService; | import com.ruoyi.platform.service.RayInsService; | ||||
| import com.ruoyi.platform.service.RayService; | import com.ruoyi.platform.service.RayService; | ||||
| import com.ruoyi.platform.service.ResourceOccupyService; | |||||
| import com.ruoyi.platform.utils.HttpUtils; | import com.ruoyi.platform.utils.HttpUtils; | ||||
| import com.ruoyi.platform.utils.JacksonUtil; | import com.ruoyi.platform.utils.JacksonUtil; | ||||
| import com.ruoyi.platform.utils.JsonUtils; | import com.ruoyi.platform.utils.JsonUtils; | ||||
| @@ -42,8 +43,8 @@ public class RayServiceImpl implements RayService { | |||||
| @Value("${argo.workflowRun}") | @Value("${argo.workflowRun}") | ||||
| private String argoWorkflowRun; | private String argoWorkflowRun; | ||||
| @Value("${minio.endpoint}") | |||||
| private String minioEndpoint; | |||||
| @Resource | |||||
| private ResourceOccupyService resourceOccupyService; | |||||
| @Resource | @Resource | ||||
| private RayDao rayDao; | private RayDao rayDao; | ||||
| @@ -151,58 +152,63 @@ public class RayServiceImpl implements RayService { | |||||
| throw new Exception("自动超参数寻优配置不存在"); | throw new Exception("自动超参数寻优配置不存在"); | ||||
| } | } | ||||
| RayParamVo rayParamVo = new RayParamVo(); | |||||
| BeanUtils.copyProperties(ray, rayParamVo); | |||||
| rayParamVo.setCodeConfig(JsonUtils.jsonToMap(ray.getCodeConfig())); | |||||
| rayParamVo.setDataset(JsonUtils.jsonToMap(ray.getDataset())); | |||||
| rayParamVo.setModel(JsonUtils.jsonToMap(ray.getModel())); | |||||
| rayParamVo.setImage(JsonUtils.jsonToMap(ray.getImage())); | |||||
| String param = JsonUtils.objectToJson(rayParamVo); | |||||
| // 调argo转换接口 | |||||
| try { | |||||
| String convertRes = HttpUtils.sendPost(argoUrl + convertRay, param); | |||||
| if (convertRes == null || StringUtils.isEmpty(convertRes)) { | |||||
| throw new RuntimeException("转换流水线失败"); | |||||
| } | |||||
| Map<String, Object> converMap = JsonUtils.jsonToMap(convertRes); | |||||
| // 组装运行接口json | |||||
| Map<String, Object> output = (Map<String, Object>) converMap.get("output"); | |||||
| Map<String, Object> runReqMap = new HashMap<>(); | |||||
| runReqMap.put("data", converMap.get("data")); | |||||
| // 调argo运行接口 | |||||
| String runRes = HttpUtils.sendPost(argoUrl + argoWorkflowRun, JsonUtils.mapToJson(runReqMap)); | |||||
| if (runRes == null || StringUtils.isEmpty(runRes)) { | |||||
| throw new RuntimeException("Failed to run workflow."); | |||||
| } | |||||
| Map<String, Object> runResMap = JsonUtils.jsonToMap(runRes); | |||||
| Map<String, Object> data = (Map<String, Object>) runResMap.get("data"); | |||||
| //判断data为空 | |||||
| if (data == null || MapUtils.isEmpty(data)) { | |||||
| throw new RuntimeException("Failed to run workflow."); | |||||
| // 记录开始扣积分 | |||||
| if (resourceOccupyService.haveResource(ray.getComputingResourceId())) { | |||||
| RayParamVo rayParamVo = new RayParamVo(); | |||||
| BeanUtils.copyProperties(ray, rayParamVo); | |||||
| rayParamVo.setResource(ray.getComputingResourceId()); | |||||
| rayParamVo.setCodeConfig(JsonUtils.jsonToMap(ray.getCodeConfig())); | |||||
| rayParamVo.setDataset(JsonUtils.jsonToMap(ray.getDataset())); | |||||
| rayParamVo.setModel(JsonUtils.jsonToMap(ray.getModel())); | |||||
| rayParamVo.setImage(JsonUtils.jsonToMap(ray.getImage())); | |||||
| String param = JsonUtils.objectToJson(rayParamVo); | |||||
| // 调argo转换接口 | |||||
| try { | |||||
| String convertRes = HttpUtils.sendPost(argoUrl + convertRay, param); | |||||
| if (convertRes == null || StringUtils.isEmpty(convertRes)) { | |||||
| throw new RuntimeException("转换流水线失败"); | |||||
| } | |||||
| Map<String, Object> converMap = JsonUtils.jsonToMap(convertRes); | |||||
| // 组装运行接口json | |||||
| Map<String, Object> output = (Map<String, Object>) converMap.get("output"); | |||||
| Map<String, Object> runReqMap = new HashMap<>(); | |||||
| runReqMap.put("data", converMap.get("data")); | |||||
| // 调argo运行接口 | |||||
| String runRes = HttpUtils.sendPost(argoUrl + argoWorkflowRun, JsonUtils.mapToJson(runReqMap)); | |||||
| if (runRes == null || StringUtils.isEmpty(runRes)) { | |||||
| throw new RuntimeException("运行失败"); | |||||
| } | |||||
| Map<String, Object> runResMap = JsonUtils.jsonToMap(runRes); | |||||
| Map<String, Object> data = (Map<String, Object>) runResMap.get("data"); | |||||
| //判断data为空 | |||||
| if (data == null || MapUtils.isEmpty(data)) { | |||||
| throw new RuntimeException("运行失败"); | |||||
| } | |||||
| Map<String, Object> metadata = (Map<String, Object>) data.get("metadata"); | |||||
| // 插入记录到实验实例表 | |||||
| RayIns rayIns = new RayIns(); | |||||
| rayIns.setRayId(ray.getId()); | |||||
| rayIns.setArgoInsNs((String) metadata.get("namespace")); | |||||
| rayIns.setArgoInsName((String) metadata.get("name")); | |||||
| rayIns.setParam(param); | |||||
| rayIns.setStatus(Constant.Pending); | |||||
| //替换argoInsName | |||||
| String outputString = JsonUtils.mapToJson(output); | |||||
| rayIns.setNodeResult(outputString.replace("{{workflow.name}}", (String) metadata.get("name"))); | |||||
| Map<String, Object> param_output = (Map<String, Object>) output.get("param_output"); | |||||
| List output1 = (ArrayList) param_output.values().toArray()[0]; | |||||
| Map<String, String> output2 = (Map<String, String>) output1.get(0); | |||||
| String outputPath = output2.get("path").replace("{{workflow.name}}", (String) metadata.get("name")) + "/hpo"; | |||||
| rayIns.setResultPath(outputPath); | |||||
| rayInsDao.insert(rayIns); | |||||
| rayInsService.updateRayStatus(id); | |||||
| resourceOccupyService.startDeduce(ray.getComputingResourceId(), Constant.TaskType_Ray, rayIns.getId()); | |||||
| } catch (Exception e) { | |||||
| throw new RuntimeException(e); | |||||
| } | } | ||||
| Map<String, Object> metadata = (Map<String, Object>) data.get("metadata"); | |||||
| // 插入记录到实验实例表 | |||||
| RayIns rayIns = new RayIns(); | |||||
| rayIns.setRayId(ray.getId()); | |||||
| rayIns.setArgoInsNs((String) metadata.get("namespace")); | |||||
| rayIns.setArgoInsName((String) metadata.get("name")); | |||||
| rayIns.setParam(param); | |||||
| rayIns.setStatus(Constant.Pending); | |||||
| //替换argoInsName | |||||
| String outputString = JsonUtils.mapToJson(output); | |||||
| rayIns.setNodeResult(outputString.replace("{{workflow.name}}", (String) metadata.get("name"))); | |||||
| Map<String, Object> param_output = (Map<String, Object>) output.get("param_output"); | |||||
| List output1 = (ArrayList) param_output.values().toArray()[0]; | |||||
| Map<String, String> output2 = (Map<String, String>) output1.get(0); | |||||
| String outputPath = output2.get("path").replace("{{workflow.name}}", (String) metadata.get("name")) + "/hpo"; | |||||
| rayIns.setResultPath(outputPath); | |||||
| rayInsDao.insert(rayIns); | |||||
| rayInsService.updateRayStatus(id); | |||||
| } catch (Exception e) { | |||||
| throw new RuntimeException(e); | |||||
| } | } | ||||
| return "执行成功"; | return "执行成功"; | ||||
| } | } | ||||
| @@ -0,0 +1,102 @@ | |||||
| 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.data.domain.Page; | |||||
| import org.springframework.data.domain.PageImpl; | |||||
| import org.springframework.data.domain.PageRequest; | |||||
| 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, String taskType, Long taskId) { | |||||
| ResourceOccupy resourceOccupy = new ResourceOccupy(); | |||||
| ComputingResource computingResource = computingResourceDao.queryById(computingResourceId); | |||||
| resourceOccupy.setComputingResourceId(computingResourceId); | |||||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | |||||
| resourceOccupy.setUserId(loginUser.getUserid()); | |||||
| resourceOccupy.setCreditPerHour(computingResource.getCreditPerHour()); | |||||
| resourceOccupy.setTaskType(taskType); | |||||
| resourceOccupy.setTaskId(taskId); | |||||
| 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 | |||||
| public void endDeduce(String taskType, Long taskId) { | |||||
| ResourceOccupy resourceOccupy = resourceOccupyDao.getResourceOccupyByTask(taskType, taskId); | |||||
| deducing(taskType, taskId); | |||||
| resourceOccupy.setState(Constant.State_invalid); | |||||
| 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 | |||||
| public void deducing(String taskType, Long taskId) { | |||||
| ResourceOccupy resourceOccupy = resourceOccupyDao.getResourceOccupyByTask(taskType, taskId); | |||||
| long timeDifferenceMillis = new Date().getTime() - resourceOccupy.getDeduceLastTime().getTime(); | |||||
| Float hours = (float) (timeDifferenceMillis / (1000 * 60 * 60)); | |||||
| float deduceCredit = resourceOccupy.getCreditPerHour() * hours; | |||||
| resourceOccupyDao.deduceCredit(deduceCredit, resourceOccupy.getUserId()); | |||||
| resourceOccupy.setDeduceLastTime(new Date()); | |||||
| resourceOccupyDao.edit(resourceOccupy); | |||||
| } | |||||
| @Override | |||||
| public Page<ResourceOccupy> queryByPage(PageRequest pageRequest) { | |||||
| long total = resourceOccupyDao.count(); | |||||
| return new PageImpl<>(resourceOccupyDao.queryByPage(pageRequest), pageRequest, total); | |||||
| } | |||||
| } | |||||
| @@ -8,6 +8,7 @@ import com.ruoyi.platform.domain.AssetWorkflow; | |||||
| import com.ruoyi.platform.domain.ServiceVersion; | import com.ruoyi.platform.domain.ServiceVersion; | ||||
| import com.ruoyi.platform.mapper.AssetWorkflowDao; | import com.ruoyi.platform.mapper.AssetWorkflowDao; | ||||
| import com.ruoyi.platform.mapper.ServiceDao; | import com.ruoyi.platform.mapper.ServiceDao; | ||||
| import com.ruoyi.platform.service.ResourceOccupyService; | |||||
| import com.ruoyi.platform.service.ServiceService; | import com.ruoyi.platform.service.ServiceService; | ||||
| import com.ruoyi.platform.utils.ConvertUtil; | import com.ruoyi.platform.utils.ConvertUtil; | ||||
| import com.ruoyi.platform.utils.HttpUtils; | import com.ruoyi.platform.utils.HttpUtils; | ||||
| @@ -45,6 +46,9 @@ public class ServiceServiceImpl implements ServiceService { | |||||
| @Resource | @Resource | ||||
| private AssetWorkflowDao assetWorkflowDao; | private AssetWorkflowDao assetWorkflowDao; | ||||
| @Resource | |||||
| private ResourceOccupyService resourceOccupyService; | |||||
| @Override | @Override | ||||
| public Page<com.ruoyi.platform.domain.Service> queryByPageService(com.ruoyi.platform.domain.Service service, PageRequest pageRequest) { | public Page<com.ruoyi.platform.domain.Service> queryByPageService(com.ruoyi.platform.domain.Service service, PageRequest pageRequest) { | ||||
| long total = serviceDao.countService(service); | long total = serviceDao.countService(service); | ||||
| @@ -110,12 +114,11 @@ public class ServiceServiceImpl implements ServiceService { | |||||
| } | } | ||||
| @Override | @Override | ||||
| public ServiceVersion addServiceVersion(ServiceVersionVo serviceVersionVo) { | |||||
| public ServiceVersion addServiceVersion(ServiceVersionVo serviceVersionVo) throws Exception { | |||||
| ServiceVersion svByVersion = serviceDao.getSvByVersion(serviceVersionVo.getVersion(), serviceVersionVo.getServiceId()); | ServiceVersion svByVersion = serviceDao.getSvByVersion(serviceVersionVo.getVersion(), serviceVersionVo.getServiceId()); | ||||
| if (svByVersion != null) { | if (svByVersion != null) { | ||||
| throw new RuntimeException("服务版本已存在,无法新增"); | throw new RuntimeException("服务版本已存在,无法新增"); | ||||
| } | } | ||||
| ServiceVersion serviceVersion = getServiceVersion(serviceVersionVo); | ServiceVersion serviceVersion = getServiceVersion(serviceVersionVo); | ||||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | LoginUser loginUser = SecurityUtils.getLoginUser(); | ||||
| serviceVersion.setCreateBy(loginUser.getUsername()); | serviceVersion.setCreateBy(loginUser.getUsername()); | ||||
| @@ -135,9 +138,8 @@ public class ServiceServiceImpl implements ServiceService { | |||||
| } | } | ||||
| @Override | @Override | ||||
| public String editServiceVersion(ServiceVersionVo serviceVersionVo) { | |||||
| public String editServiceVersion(ServiceVersionVo serviceVersionVo) throws Exception { | |||||
| ServiceVersion serviceVersion = getServiceVersion(serviceVersionVo); | ServiceVersion serviceVersion = getServiceVersion(serviceVersionVo); | ||||
| ServiceVersion oldServiceVersion = serviceDao.getServiceVersionById(serviceVersionVo.getId()); | ServiceVersion oldServiceVersion = serviceDao.getServiceVersionById(serviceVersionVo.getId()); | ||||
| if (!oldServiceVersion.getReplicas().equals(serviceVersionVo.getReplicas()) || !oldServiceVersion.getResource().equals(serviceVersionVo.getResource()) | if (!oldServiceVersion.getReplicas().equals(serviceVersionVo.getReplicas()) || !oldServiceVersion.getResource().equals(serviceVersionVo.getResource()) | ||||
| || serviceVersionVo.getRerun()) { | || serviceVersionVo.getRerun()) { | ||||
| @@ -234,13 +236,13 @@ public class ServiceServiceImpl implements ServiceService { | |||||
| } | } | ||||
| @Override | @Override | ||||
| public String runServiceVersion(Long id) { | |||||
| public String runServiceVersion(Long id) throws Exception { | |||||
| ServiceVersion serviceVersion = serviceDao.getServiceVersionById(id); | ServiceVersion serviceVersion = serviceDao.getServiceVersionById(id); | ||||
| com.ruoyi.platform.domain.Service service = serviceDao.getServiceById(serviceVersion.getServiceId()); | com.ruoyi.platform.domain.Service service = serviceDao.getServiceById(serviceVersion.getServiceId()); | ||||
| HashMap<String, Object> paramMap = new HashMap<>(); | HashMap<String, Object> paramMap = new HashMap<>(); | ||||
| paramMap.put("service_name", service.getServiceName()); | paramMap.put("service_name", service.getServiceName()); | ||||
| paramMap.put("description", serviceVersion.getDescription()); | paramMap.put("description", serviceVersion.getDescription()); | ||||
| paramMap.put("resource", serviceVersion.getResource()); | |||||
| paramMap.put("resource", serviceVersion.getComputingResourceId()); | |||||
| paramMap.put("mount_path", serviceVersion.getMountPath()); | paramMap.put("mount_path", serviceVersion.getMountPath()); | ||||
| paramMap.put("replicas", serviceVersion.getReplicas()); | paramMap.put("replicas", serviceVersion.getReplicas()); | ||||
| paramMap.put("env", JSONObject.parseObject(serviceVersion.getEnvVariables())); | paramMap.put("env", JSONObject.parseObject(serviceVersion.getEnvVariables())); | ||||
| @@ -249,23 +251,29 @@ public class ServiceServiceImpl implements ServiceService { | |||||
| paramMap.put("model", JSONObject.parseObject(serviceVersion.getModel())); | paramMap.put("model", JSONObject.parseObject(serviceVersion.getModel())); | ||||
| paramMap.put("service_type", service.getServiceType()); | paramMap.put("service_type", service.getServiceType()); | ||||
| paramMap.put("deploy_type", serviceVersion.getDeployType()); | paramMap.put("deploy_type", serviceVersion.getDeployType()); | ||||
| String req = HttpUtils.sendPost(argoUrl + modelService + "/create", JSON.toJSONString(paramMap)); | |||||
| if (StringUtils.isNotEmpty(req)) { | |||||
| Map<String, Object> reqMap = JacksonUtil.parseJSONStr2Map(req); | |||||
| if ((Integer) reqMap.get("code") == 200) { | |||||
| Map<String, String> data = (Map<String, String>) reqMap.get("data"); | |||||
| serviceVersion.setUrl(data.get("url")); | |||||
| serviceVersion.setDeploymentName(data.get("deployment_name")); | |||||
| serviceVersion.setSvcName(data.get("svc_name")); | |||||
| serviceVersion.setRunState(Constant.Pending); | |||||
| serviceDao.updateServiceVersion(serviceVersion); | |||||
| return "启动成功"; | |||||
| // 记录开始扣积分 | |||||
| if (resourceOccupyService.haveResource(serviceVersion.getComputingResourceId())) { | |||||
| String req = HttpUtils.sendPost(argoUrl + modelService + "/create", JSON.toJSONString(paramMap)); | |||||
| if (StringUtils.isNotEmpty(req)) { | |||||
| Map<String, Object> reqMap = JacksonUtil.parseJSONStr2Map(req); | |||||
| if ((Integer) reqMap.get("code") == 200) { | |||||
| resourceOccupyService.startDeduce(serviceVersion.getComputingResourceId(), Constant.TaskType_Service, serviceVersion.getId()); | |||||
| Map<String, String> data = (Map<String, String>) reqMap.get("data"); | |||||
| serviceVersion.setUrl(data.get("url")); | |||||
| serviceVersion.setDeploymentName(data.get("deployment_name")); | |||||
| serviceVersion.setSvcName(data.get("svc_name")); | |||||
| serviceVersion.setRunState(Constant.Pending); | |||||
| serviceDao.updateServiceVersion(serviceVersion); | |||||
| return "启动成功"; | |||||
| } else { | |||||
| throw new RuntimeException("启动失败"); | |||||
| } | |||||
| } else { | } else { | ||||
| throw new RuntimeException("启动失败"); | throw new RuntimeException("启动失败"); | ||||
| } | } | ||||
| } else { | |||||
| throw new RuntimeException("启动失败"); | |||||
| } | } | ||||
| return "启动失败"; | |||||
| } | } | ||||
| @Override | @Override | ||||
| @@ -277,6 +285,8 @@ public class ServiceServiceImpl implements ServiceService { | |||||
| if (StringUtils.isNotEmpty(req)) { | if (StringUtils.isNotEmpty(req)) { | ||||
| serviceVersion.setRunState(Constant.Stopped); | serviceVersion.setRunState(Constant.Stopped); | ||||
| serviceDao.updateServiceVersion(serviceVersion); | serviceDao.updateServiceVersion(serviceVersion); | ||||
| // 结束扣积分 | |||||
| resourceOccupyService.endDeduce(Constant.TaskType_Service, id); | |||||
| return "停止成功"; | return "停止成功"; | ||||
| } else { | } else { | ||||
| throw new RuntimeException("停止失败"); | throw new RuntimeException("停止失败"); | ||||
| @@ -2,8 +2,10 @@ package com.ruoyi.platform.utils; | |||||
| import com.alibaba.fastjson2.JSON; | import com.alibaba.fastjson2.JSON; | ||||
| import com.ruoyi.platform.constant.Constant; | import com.ruoyi.platform.constant.Constant; | ||||
| import com.ruoyi.platform.domain.ComputingResource; | |||||
| import com.ruoyi.platform.domain.DevEnvironment; | import com.ruoyi.platform.domain.DevEnvironment; | ||||
| import com.ruoyi.platform.mapper.ComputingResourceDao; | import com.ruoyi.platform.mapper.ComputingResourceDao; | ||||
| import com.ruoyi.platform.service.ResourceOccupyService; | |||||
| import io.kubernetes.client.Exec; | import io.kubernetes.client.Exec; | ||||
| import io.kubernetes.client.custom.IntOrString; | import io.kubernetes.client.custom.IntOrString; | ||||
| import io.kubernetes.client.custom.Quantity; | import io.kubernetes.client.custom.Quantity; | ||||
| @@ -49,6 +51,9 @@ public class K8sClientUtil { | |||||
| */ | */ | ||||
| private static ApiClient apiClient; | private static ApiClient apiClient; | ||||
| @Resource | |||||
| private ResourceOccupyService resourceOccupyService; | |||||
| @Resource | @Resource | ||||
| private ComputingResourceDao computingResourceDao; | private ComputingResourceDao computingResourceDao; | ||||
| @@ -487,7 +492,7 @@ public class K8sClientUtil { | |||||
| //配置资源 | //配置资源 | ||||
| V1ResourceRequirements v1ResourceRequirements = setPodResource(devEnvironment.getStandard()); | |||||
| V1ResourceRequirements v1ResourceRequirements = setPodResource(devEnvironment.getComputingResourceId()); | |||||
| V1Pod pod = new V1PodBuilder() | V1Pod pod = new V1PodBuilder() | ||||
| .withNewMetadata() | .withNewMetadata() | ||||
| @@ -509,10 +514,12 @@ public class K8sClientUtil { | |||||
| .build(); | .build(); | ||||
| try { | try { | ||||
| pod = api.createNamespacedPod(namespace, pod, null, null, null); | |||||
| String nodeName = getNodeName(podName, namespace); | |||||
| if (Constant.Computing_Resource_GPU.equals(devEnvironment.getComputingResource())) { | |||||
| computingResourceDao.updateUsedStateByNode(nodeName, Constant.Used_State_used); | |||||
| // 记录开始扣积分 | |||||
| if (resourceOccupyService.haveResource(devEnvironment.getComputingResourceId())) { | |||||
| pod = api.createNamespacedPod(namespace, pod, null, null, null); | |||||
| String nodeName = getNodeName(podName, namespace); | |||||
| resourceOccupyService.startDeduce(devEnvironment.getComputingResourceId(), Constant.TaskType_Dev, Long.valueOf(devEnvironment.getId())); | |||||
| } | } | ||||
| } catch (ApiException e) { | } catch (ApiException e) { | ||||
| throw new RuntimeException("创建pod异常:" + e.getResponseBody()); | throw new RuntimeException("创建pod异常:" + e.getResponseBody()); | ||||
| @@ -688,87 +695,17 @@ public class K8sClientUtil { | |||||
| } | } | ||||
| public Integer createDeployment(String dpName, String namespace, Integer replicas, String model, String image, Integer port, String resource, String mountPath | |||||
| , String envVariables, String codeConfig) { | |||||
| AppsV1Api api = new AppsV1Api(apiClient); | |||||
| //配置标签选择 | |||||
| HashMap<String, String> selector = new HashMap<>(); | |||||
| selector.put("app", dpName); | |||||
| V1ResourceRequirements setPodResource(Integer computingResourceId) { | |||||
| ComputingResource computingResource = computingResourceDao.queryById(computingResourceId); | |||||
| //配置资源 | |||||
| V1ResourceRequirements v1ResourceRequirements = setPodResource(resource); | |||||
| //配置环境变量 | |||||
| List<V1EnvVar> env = new ArrayList<>(); | |||||
| if (StringUtils.isNotEmpty(envVariables)) { | |||||
| HashMap<String, String> envMap = JSON.parseObject(envVariables, HashMap.class); | |||||
| for (String key : envMap.keySet()) { | |||||
| V1EnvVar envVar = new V1EnvVar().name(key).value(envMap.get(key)); | |||||
| env.add(envVar); | |||||
| } | |||||
| } | |||||
| // 配置卷和卷挂载 | |||||
| // List<V1VolumeMount> volumeMounts = new ArrayList<>(); | |||||
| // volumeMounts.add(new V1VolumeMount().name("workspace").mountPath(mountPath)); | |||||
| // volumeMounts.add(new V1VolumeMount().name("minio-pvc").mountPath("/opt/code").subPath(codeConfig).readOnly(true)); | |||||
| // volumeMounts.add(new V1VolumeMount().name("minio-pvc").mountPath("/opt/model").subPath(model).readOnly(true)); | |||||
| // | |||||
| // List<V1Volume> volumes = new ArrayList<>(); | |||||
| // volumes.add(new V1Volume().name("workspace").persistentVolumeClaim(new V1PersistentVolumeClaimVolumeSource().claimName(pvc.getMetadata().getName()))); | |||||
| // volumes.add(new V1Volume().name("minio-pvc").persistentVolumeClaim(new V1PersistentVolumeClaimVolumeSource().claimName(dataPvcName))); | |||||
| //创建deployment | |||||
| V1Deployment deployment = new V1DeploymentBuilder().withNewMetadata() | |||||
| .withName(dpName) | |||||
| .endMetadata() | |||||
| .withNewSpec() | |||||
| .withReplicas(replicas) | |||||
| .withSelector(new V1LabelSelector().matchLabels(selector)) | |||||
| .withNewTemplate() | |||||
| .withNewMetadata() | |||||
| .addToLabels("app", dpName) | |||||
| .endMetadata() | |||||
| .withNewSpec() | |||||
| .addNewContainer() | |||||
| .withName(dpName) | |||||
| .withImage(image) | |||||
| .withEnv(env) | |||||
| .withPorts(new V1ContainerPort().containerPort(port).protocol("TCP")) | |||||
| .withResources(v1ResourceRequirements) | |||||
| .endContainer() | |||||
| .endSpec() | |||||
| .endTemplate() | |||||
| .endSpec() | |||||
| .build(); | |||||
| try { | |||||
| api.createNamespacedDeployment(namespace, deployment, null, null, null); | |||||
| } catch (ApiException e) { | |||||
| throw new RuntimeException("创建deployment异常:" + e.getResponseBody()); | |||||
| } | |||||
| V1Service service = createService(namespace, dpName + "-svc", port, selector); | |||||
| return service.getSpec().getPorts().get(0).getNodePort(); | |||||
| } | |||||
| V1ResourceRequirements setPodResource(String resource) { | |||||
| //配置pod资源 | //配置pod资源 | ||||
| JSONObject standardJson = new JSONObject(resource); | |||||
| JSONObject valueJson = (JSONObject) standardJson.get("value"); | |||||
| int cpu = (int) valueJson.get("cpu"); | |||||
| String memory = (String) valueJson.get("memory"); | |||||
| String memory = computingResource.getMemoryGb().toString(); | |||||
| memory = memory.substring(0, memory.length() - 1).concat("i"); | memory = memory.substring(0, memory.length() - 1).concat("i"); | ||||
| Integer gpu = (Integer) valueJson.get("gpu"); | |||||
| HashMap<String, Quantity> limitMap = new HashMap<>(); | HashMap<String, Quantity> limitMap = new HashMap<>(); | ||||
| if (gpu != null && gpu != 0) { | |||||
| limitMap.put("nvidia.com/gpu", new Quantity(String.valueOf(gpu))); | |||||
| if (computingResource.getGpuNums() != null && computingResource.getGpuNums() != 0) { | |||||
| limitMap.put("nvidia.com/gpu", new Quantity(String.valueOf(computingResource.getGpuNums()))); | |||||
| } | } | ||||
| limitMap.put("cpu", new Quantity(String.valueOf(cpu))); | |||||
| limitMap.put("cpu", new Quantity(String.valueOf(computingResource.getCpuCores()))); | |||||
| limitMap.put("memory", new Quantity(memory)); | limitMap.put("memory", new Quantity(memory)); | ||||
| limitMap.put("ephemeral-storage", new Quantity("100Gi")); | limitMap.put("ephemeral-storage", new Quantity("100Gi")); | ||||
| @@ -19,6 +19,9 @@ public class DevEnvironmentVo implements Serializable { | |||||
| * 计算资源 | * 计算资源 | ||||
| */ | */ | ||||
| private String computingResource; | private String computingResource; | ||||
| private Integer computingResourceId; | |||||
| /** | /** | ||||
| * 资源规格 | * 资源规格 | ||||
| */ | */ | ||||
| @@ -44,5 +44,5 @@ public class RayParamVo { | |||||
| private Integer minSamplesRequired; | private Integer minSamplesRequired; | ||||
| private String resource; | |||||
| private Integer resource; | |||||
| } | } | ||||
| @@ -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; | ||||
| @@ -28,6 +28,8 @@ public class ServiceVersionVo { | |||||
| private String resource; | private String resource; | ||||
| private Integer computingResourceId; | |||||
| private Integer replicas; | private Integer replicas; | ||||
| private String mountPath; | private String mountPath; | ||||
| @@ -2,30 +2,22 @@ | |||||
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | <!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"> | <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 | 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 | from computing_resource | ||||
| where id = #{id} and state = 1 | where id = #{id} and state = 1 | ||||
| </select> | </select> | ||||
| <!--查询指定行数据--> | <!--查询指定行数据--> | ||||
| <select id="queryAllByLimit" resultMap="ComputingResourceMap"> | |||||
| <select id="queryAllByLimit" resultType="com.ruoyi.platform.domain.ComputingResource"> | |||||
| select | 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 | from computing_resource | ||||
| <where> | <where> | ||||
| state = 1 | state = 1 | ||||
| @@ -156,10 +148,6 @@ computing_resource = values(computing_resource)standard = values(standard)descri | |||||
| where id = #{computingResource.id} | where id = #{computingResource.id} | ||||
| </update> | </update> | ||||
| <update id="updateUsedStateByNode"> | |||||
| update computing_resource set used_state = #{usedState} where node = #{node} | |||||
| </update> | |||||
| <!--通过主键删除--> | <!--通过主键删除--> | ||||
| <delete id="deleteById"> | <delete id="deleteById"> | ||||
| delete from computing_resource where id = #{id} | delete from computing_resource where id = #{id} | ||||
| @@ -1,38 +1,18 @@ | |||||
| <?xml version="1.0" encoding="UTF-8"?> | <?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"> | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||||
| <mapper namespace="com.ruoyi.platform.mapper.DevEnvironmentDao"> | <mapper namespace="com.ruoyi.platform.mapper.DevEnvironmentDao"> | ||||
| <resultMap type="com.ruoyi.platform.domain.DevEnvironment" id="DevEnvironmentMap"> | |||||
| <result property="id" column="id" jdbcType="INTEGER"/> | |||||
| <result property="name" column="name" jdbcType="VARCHAR"/> | |||||
| <result property="status" column="status" jdbcType="VARCHAR"/> | |||||
| <result property="computingResource" column="computing_resource" jdbcType="VARCHAR"/> | |||||
| <result property="standard" column="standard" jdbcType="VARCHAR"/> | |||||
| <result property="envVariable" column="env_variable" jdbcType="VARCHAR"/> | |||||
| <result property="image" column="image" jdbcType="VARCHAR"/> | |||||
| <result property="dataset" column="dataset" jdbcType="VARCHAR"/> | |||||
| <result property="model" column="model" jdbcType="VARCHAR"/> | |||||
| <result property="url" column="url" jdbcType="VARCHAR"/> | |||||
| <result property="altField2" column="alt_field2" 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="DevEnvironmentMap"> | |||||
| <select id="queryById" resultType="com.ruoyi.platform.domain.DevEnvironment"> | |||||
| select | select | ||||
| id,name,status,computing_resource,standard,env_variable,image,dataset,model,url,alt_field2,create_by,create_time,update_by,update_time,state | |||||
| id,name,status,computing_resource,computing_resource_id, standard,env_variable,image,dataset,model,url,alt_field2,create_by,create_time,update_by,update_time,state | |||||
| from dev_environment | from dev_environment | ||||
| where id = #{id} and state = 1 | where id = #{id} and state = 1 | ||||
| </select> | </select> | ||||
| <!--查询指定行数据--> | <!--查询指定行数据--> | ||||
| <select id="queryAllByLimit" resultMap="DevEnvironmentMap"> | |||||
| <select id="queryAllByLimit" resultType="com.ruoyi.platform.domain.DevEnvironment"> | |||||
| select | select | ||||
| id,name,status,computing_resource,standard,env_variable,image,dataset,model,url,alt_field2,create_by,create_time,update_by,update_time,state | |||||
| id,name,status,computing_resource,computing_resource_id,standard,env_variable,image,dataset,model,url,alt_field2,create_by,create_time,update_by,update_time,state | |||||
| from dev_environment | from dev_environment | ||||
| <where> | <where> | ||||
| state = 1 | state = 1 | ||||
| @@ -146,12 +126,17 @@ | |||||
| </where> | </where> | ||||
| </select> | </select> | ||||
| <select id="getRunning" resultType="com.ruoyi.platform.domain.DevEnvironment"> | |||||
| select * from dev_environment where state = 1 and status = 'Running' | |||||
| </select> | |||||
| <!--新增所有列--> | <!--新增所有列--> | ||||
| <insert id="insert" keyProperty="id" useGeneratedKeys="true"> | <insert id="insert" keyProperty="id" useGeneratedKeys="true"> | ||||
| insert into dev_environment(name,status,computing_resource,standard,env_variable,image,dataset,model,url,alt_field2,create_by,create_time,update_by,update_time,state) | |||||
| insert into dev_environment(name,status,computing_resource,computing_resource_id,standard,env_variable,image,dataset,model,url,alt_field2,create_by,create_time,update_by,update_time,state) | |||||
| values (#{devEnvironment.name}, | values (#{devEnvironment.name}, | ||||
| #{devEnvironment.status}, | #{devEnvironment.status}, | ||||
| #{devEnvironment.computingResource}, | #{devEnvironment.computingResource}, | ||||
| #{devEnvironment.computingResourceId}, | |||||
| #{devEnvironment.standard}, | #{devEnvironment.standard}, | ||||
| #{devEnvironment.envVariable}, | #{devEnvironment.envVariable}, | ||||
| #{devEnvironment.image}, | #{devEnvironment.image}, | ||||
| @@ -167,24 +152,6 @@ | |||||
| ) | ) | ||||
| </insert> | </insert> | ||||
| <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true"> | |||||
| insert into dev_environment(name,status,computing_resource,standard,env_variable,image,dataset,model,url,alt_field2,create_by,create_time,update_by,update_time,state ) | |||||
| values | |||||
| <foreach collection="entities" item="entity" separator=","> | |||||
| (#{entity.name},#{entity.status},#{entity.computingResource},#{entity.standard},#{entity.envVariable},#{entity.image},#{entity.dataset},#{entity.model},#{entity.url},#{entity.altField2},#{entity.createBy},#{entity.createTime},#{entity.updateBy},#{entity.updateTime},#{entity.state}) | |||||
| </foreach> | |||||
| </insert> | |||||
| <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true"> | |||||
| insert into dev_environment(name,status,computing_resource,standard,env_variable,image,dataset,model,url,alt_field2,create_by,create_time,update_by,update_time,state) | |||||
| values | |||||
| <foreach collection="entities" item="entity" separator=","> | |||||
| (#{entity.name}#{entity.status}#{entity.computingResource}#{entity.standard}#{entity.envVariable}#{entity.image}#{entity.dataset}#{entity.model}#{entity.url}#{entity.altField2}#{entity.createBy}#{entity.createTime}#{entity.updateBy}#{entity.updateTime}#{entity.state}) | |||||
| </foreach> | |||||
| on duplicate key update | |||||
| name = values(name)status = values(status)computing_resource = values(computing_resource)standard = values(standard)env_variable = values(env_variable)image = values(image)dataset = values(dataset)model = values(model)url = values(url)alt_field2 = values(alt_field2)create_by = values(create_by)create_time = values(create_time)update_by = values(update_by)update_time = values(update_time)state = values(state) | |||||
| </insert> | |||||
| <!--通过主键修改数据--> | <!--通过主键修改数据--> | ||||
| <update id="update"> | <update id="update"> | ||||
| update dev_environment | update dev_environment | ||||
| @@ -198,6 +165,9 @@ name = values(name)status = values(status)computing_resource = values(computing_ | |||||
| <if test="devEnvironment.computingResource != null and devEnvironment.computingResource != ''"> | <if test="devEnvironment.computingResource != null and devEnvironment.computingResource != ''"> | ||||
| computing_resource = #{devEnvironment.computingResource}, | computing_resource = #{devEnvironment.computingResource}, | ||||
| </if> | </if> | ||||
| <if test="devEnvironment.computingResourceId != null and devEnvironment.computingResourceId != ''"> | |||||
| computing_resource_id = #{devEnvironment.computingResourceId}, | |||||
| </if> | |||||
| <if test="devEnvironment.standard != null and devEnvironment.standard != ''"> | <if test="devEnvironment.standard != null and devEnvironment.standard != ''"> | ||||
| standard = #{devEnvironment.standard}, | standard = #{devEnvironment.standard}, | ||||
| </if> | </if> | ||||
| @@ -2,13 +2,15 @@ | |||||
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||||
| <mapper namespace="com.ruoyi.platform.mapper.RayDao"> | <mapper namespace="com.ruoyi.platform.mapper.RayDao"> | ||||
| <insert id="save"> | <insert id="save"> | ||||
| insert into ray(name, description, dataset, model, code_config, main_py, num_samples, parameters, points_to_evaluate, storage_path, | |||||
| insert into ray(name, description, dataset, model, code_config, main_py, num_samples, parameters, | |||||
| points_to_evaluate, storage_path, | |||||
| search_alg, scheduler, metric, mode, max_t, | search_alg, scheduler, metric, mode, max_t, | ||||
| min_samples_required, resource, image, create_by, update_by) | |||||
| values (#{ray.name}, #{ray.description}, #{ray.dataset}, #{ray.model}, #{ray.codeConfig}, #{ray.mainPy}, #{ray.numSamples}, #{ray.parameters}, | |||||
| min_samples_required, resource, computing_resource_id, image, create_by, update_by) | |||||
| values (#{ray.name}, #{ray.description}, #{ray.dataset}, #{ray.model}, #{ray.codeConfig}, #{ray.mainPy}, | |||||
| #{ray.numSamples}, #{ray.parameters}, | |||||
| #{ray.pointsToEvaluate}, #{ray.storagePath}, | #{ray.pointsToEvaluate}, #{ray.storagePath}, | ||||
| #{ray.searchAlg}, #{ray.scheduler}, #{ray.metric}, #{ray.mode}, #{ray.maxT}, #{ray.minSamplesRequired}, | #{ray.searchAlg}, #{ray.scheduler}, #{ray.metric}, #{ray.mode}, #{ray.maxT}, #{ray.minSamplesRequired}, | ||||
| #{ray.resource}, #{ray.image}, #{ray.createBy}, #{ray.updateBy}) | |||||
| #{ray.resource}, #{ray.computingResourceId}, #{ray.image}, #{ray.createBy}, #{ray.updateBy}) | |||||
| </insert> | </insert> | ||||
| <update id="edit"> | <update id="edit"> | ||||
| @@ -68,6 +70,9 @@ | |||||
| <if test="ray.resource != null"> | <if test="ray.resource != null"> | ||||
| resource = #{ray.resource}, | resource = #{ray.resource}, | ||||
| </if> | </if> | ||||
| <if test="ray.computingResourceId != null"> | |||||
| computing_resource_id = #{ray.computingResourceId}, | |||||
| </if> | |||||
| <if test="ray.updateBy != null and ray.updateBy !=''"> | <if test="ray.updateBy != null and ray.updateBy !=''"> | ||||
| update_by = #{ray.updateBy}, | update_by = #{ray.updateBy}, | ||||
| </if> | </if> | ||||
| @@ -1,7 +1,7 @@ | |||||
| <?xml version="1.0" encoding="UTF-8"?> | <?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"> | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||||
| <mapper namespace="com.ruoyi.platform.mapper.RayInsDao"> | <mapper namespace="com.ruoyi.platform.mapper.RayInsDao"> | ||||
| <insert id="insert"> | |||||
| <insert id="insert" keyProperty="id" useGeneratedKeys="true"> | |||||
| insert into ray_ins(ray_id, result_path, argo_ins_name, argo_ins_ns, node_status, node_result, param, source, | insert into ray_ins(ray_id, result_path, argo_ins_name, argo_ins_ns, node_status, node_result, param, source, | ||||
| status) | status) | ||||
| values (#{rayIns.rayId}, #{rayIns.resultPath}, #{rayIns.argoInsName}, #{rayIns.argoInsNs}, | values (#{rayIns.rayId}, #{rayIns.resultPath}, #{rayIns.argoInsName}, #{rayIns.argoInsNs}, | ||||
| @@ -0,0 +1,62 @@ | |||||
| <?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> | |||||
| <update id="deduceCredit"> | |||||
| update sys_user | |||||
| set credit = credit - #{credit} | |||||
| where user_id = #{userId} | |||||
| </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 case when used + #{need} <= total then TRUE else FALSE end | |||||
| from resource | |||||
| where id = #{id} | |||||
| </select> | |||||
| <select id="getResourceOccupyByTask" resultType="com.ruoyi.platform.domain.ResourceOccupy"> | |||||
| select * | |||||
| from resource_occupy | |||||
| where task_type = #{task_type} | |||||
| and task_id = #{task_id} | |||||
| </select> | |||||
| <select id="count" resultType="java.lang.Long"> | |||||
| select count(1) resource_occupy | |||||
| </select> | |||||
| <select id="queryByPage" resultType="com.ruoyi.platform.domain.ResourceOccupy"> | |||||
| select * | |||||
| from resource_occupy | |||||
| order by start_time desc limit #{pageable.offset}, #{pageable.pageSize} | |||||
| </select> | |||||
| </mapper> | |||||
| @@ -84,6 +84,11 @@ | |||||
| where service_id = #{serviceId} and version = #{version} and state = 1 | where service_id = #{serviceId} and version = #{version} and state = 1 | ||||
| </select> | </select> | ||||
| <select id="getRunning" resultType="com.ruoyi.platform.domain.ServiceVersion"> | |||||
| select * | |||||
| from service_version where state = 1 and run_state = 'Running' | |||||
| </select> | |||||
| <insert id="insertService" keyProperty="id" useGeneratedKeys="true"> | <insert id="insertService" keyProperty="id" useGeneratedKeys="true"> | ||||
| insert into service(service_name, service_type, description, create_by, update_by) | insert into service(service_name, service_type, description, create_by, update_by) | ||||
| values (#{service.serviceName}, #{service.serviceType}, #{service.description}, #{service.createBy}, #{service.updateBy}) | values (#{service.serviceName}, #{service.serviceType}, #{service.description}, #{service.createBy}, #{service.updateBy}) | ||||
| @@ -25,6 +25,7 @@ | |||||
| <result property="remark" column="remark"/> | <result property="remark" column="remark"/> | ||||
| <result property="gitLinkUsername" column="git_link_username"/> | <result property="gitLinkUsername" column="git_link_username"/> | ||||
| <result property="gitLinkPassword" column="git_link_password"/> | <result property="gitLinkPassword" column="git_link_password"/> | ||||
| <result property="credit" column="credit"/> | |||||
| <association property="dept" javaType="SysDept" resultMap="deptResult"/> | <association property="dept" javaType="SysDept" resultMap="deptResult"/> | ||||
| <collection property="roles" javaType="java.util.List" resultMap="RoleResult"/> | <collection property="roles" javaType="java.util.List" resultMap="RoleResult"/> | ||||
| </resultMap> | </resultMap> | ||||
| @@ -59,6 +60,7 @@ | |||||
| u.password, | u.password, | ||||
| u.git_link_username, | u.git_link_username, | ||||
| u.git_link_password, | u.git_link_password, | ||||
| u.credit, | |||||
| u.sex, | u.sex, | ||||
| u.status, | u.status, | ||||
| u.del_flag, | u.del_flag, | ||||
| @@ -88,7 +90,7 @@ | |||||
| <select id="selectUserList" parameterType="SysUser" resultMap="SysUserResult"> | <select id="selectUserList" parameterType="SysUser" resultMap="SysUserResult"> | ||||
| select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.sex, u.status, | select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.sex, u.status, | ||||
| u.git_link_username, | |||||
| u.git_link_username, u.credit, | |||||
| u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader | u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader | ||||
| from sys_user u | from sys_user u | ||||
| left join sys_dept d on u.dept_id = d.dept_id | left join sys_dept d on u.dept_id = d.dept_id | ||||
| @@ -123,7 +125,7 @@ | |||||
| </select> | </select> | ||||
| <select id="selectAllocatedList" parameterType="SysUser" resultMap="SysUserResult"> | <select id="selectAllocatedList" parameterType="SysUser" resultMap="SysUserResult"> | ||||
| select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time, u.git_link_username | |||||
| select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time, u.credit, u.git_link_username | |||||
| from sys_user u | from sys_user u | ||||
| left join sys_dept d on u.dept_id = d.dept_id | left join sys_dept d on u.dept_id = d.dept_id | ||||
| left join sys_user_role ur on u.user_id = ur.user_id | left join sys_user_role ur on u.user_id = ur.user_id | ||||
| @@ -140,7 +142,7 @@ | |||||
| </select> | </select> | ||||
| <select id="selectUnallocatedList" parameterType="SysUser" resultMap="SysUserResult"> | <select id="selectUnallocatedList" parameterType="SysUser" resultMap="SysUserResult"> | ||||
| select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time ,u.git_link_username | |||||
| select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time , u.credit, u.git_link_username | |||||
| from sys_user u | from sys_user u | ||||
| left join sys_dept d on u.dept_id = d.dept_id | left join sys_dept d on u.dept_id = d.dept_id | ||||
| left join sys_user_role ur on u.user_id = ur.user_id | left join sys_user_role ur on u.user_id = ur.user_id | ||||
| @@ -212,6 +214,7 @@ | |||||
| <if test="remark != null and remark != ''">remark,</if> | <if test="remark != null and remark != ''">remark,</if> | ||||
| <if test="gitLinkUsername != null and gitLinkUsername != ''">git_link_username,</if> | <if test="gitLinkUsername != null and gitLinkUsername != ''">git_link_username,</if> | ||||
| <if test="gitLinkPassword != null and gitLinkPassword != ''">git_link_password,</if> | <if test="gitLinkPassword != null and gitLinkPassword != ''">git_link_password,</if> | ||||
| <if test="credit != null">credit,</if> | |||||
| create_time | create_time | ||||
| )values( | )values( | ||||
| <if test="userId != null and userId != ''">#{userId},</if> | <if test="userId != null and userId != ''">#{userId},</if> | ||||
| @@ -228,6 +231,7 @@ | |||||
| <if test="remark != null and remark != ''">#{remark},</if> | <if test="remark != null and remark != ''">#{remark},</if> | ||||
| <if test="gitLinkUsername != null and gitLinkUsername != ''">#{gitLinkUsername},</if> | <if test="gitLinkUsername != null and gitLinkUsername != ''">#{gitLinkUsername},</if> | ||||
| <if test="gitLinkPassword != null and gitLinkPassword != ''">#{gitLinkPassword},</if> | <if test="gitLinkPassword != null and gitLinkPassword != ''">#{gitLinkPassword},</if> | ||||
| <if test="credit != null">#{credit},</if> | |||||
| sysdate() | sysdate() | ||||
| ) | ) | ||||
| </insert> | </insert> | ||||
| @@ -250,6 +254,7 @@ | |||||
| <if test="remark != null">remark = #{remark},</if> | <if test="remark != null">remark = #{remark},</if> | ||||
| <if test="gitLinkUsername != null and gitLinkUsername != ''">git_link_username = #{gitLinkUsername},</if> | <if test="gitLinkUsername != null and gitLinkUsername != ''">git_link_username = #{gitLinkUsername},</if> | ||||
| <if test="gitLinkPassword != null and gitLinkPassword != ''">git_link_password = #{gitLinkPassword},</if> | <if test="gitLinkPassword != null and gitLinkPassword != ''">git_link_password = #{gitLinkPassword},</if> | ||||
| <if test="credit != null">credit = #{credit},</if> | |||||
| update_time = sysdate() | update_time = sysdate() | ||||
| </set> | </set> | ||||
| where user_id = #{userId} | where user_id = #{userId} | ||||