From 89ed8ac54467de9e19cbce9c3f29a45f0121c8eb Mon Sep 17 00:00:00 2001 From: chenzhihang <709011834@qq.com> Date: Mon, 6 Jan 2025 14:47:00 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E8=B6=85=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E5=AF=BB=E4=BC=98=E5=AE=9E=E9=AA=8C=E5=8A=9F=E8=83=BD=E5=BC=80?= =?UTF-8?q?=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ray/RayController.java | 62 +++++++++ .../controller/ray/RayInsController.java | 60 ++++++++ .../java/com/ruoyi/platform/domain/Ray.java | 77 +++++++++++ .../com/ruoyi/platform/domain/RayIns.java | 45 ++++++ .../com/ruoyi/platform/mapper/RayDao.java | 21 +++ .../com/ruoyi/platform/mapper/RayInsDao.java | 21 +++ .../ruoyi/platform/service/RayInsService.java | 21 +++ .../ruoyi/platform/service/RayService.java | 22 +++ .../service/impl/RayInsServiceImpl.java | 130 ++++++++++++++++++ .../platform/service/impl/RayServiceImpl.java | 119 ++++++++++++++++ .../java/com/ruoyi/platform/vo/RayVo.java | 76 ++++++++++ .../managementPlatform/RayDaoMapper.xml | 109 +++++++++++++++ .../managementPlatform/RayInsDaoMapper.xml | 69 ++++++++++ 13 files changed, 832 insertions(+) create mode 100644 ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/ray/RayController.java create mode 100644 ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/ray/RayInsController.java create mode 100644 ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/Ray.java create mode 100644 ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/RayIns.java create mode 100644 ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/RayDao.java create mode 100644 ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/RayInsDao.java create mode 100644 ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/RayInsService.java create mode 100644 ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/RayService.java create mode 100644 ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/RayInsServiceImpl.java create mode 100644 ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/RayServiceImpl.java create mode 100644 ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/RayVo.java create mode 100644 ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/RayDaoMapper.xml create mode 100644 ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/RayInsDaoMapper.xml diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/ray/RayController.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/ray/RayController.java new file mode 100644 index 00000000..719f5747 --- /dev/null +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/ray/RayController.java @@ -0,0 +1,62 @@ +package com.ruoyi.platform.controller.ray; + +import com.ruoyi.common.core.web.controller.BaseController; +import com.ruoyi.common.core.web.domain.GenericsAjaxResult; +import com.ruoyi.platform.domain.Ray; +import com.ruoyi.platform.service.RayService; +import com.ruoyi.platform.vo.RayVo; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.io.IOException; + +@RestController +@RequestMapping("ray") +@Api("自动超参数寻优") +public class RayController extends BaseController { + @Resource + private RayService rayService; + + @GetMapping + @ApiOperation("分页查询") + public GenericsAjaxResult> queryByPage(@RequestParam("page") int page, + @RequestParam("size") int size, + @RequestParam(value = "name", required = false) String name) { + PageRequest pageRequest = PageRequest.of(page, size); + return genericsSuccess(this.rayService.queryByPage(name, pageRequest)); + } + + @PostMapping + @ApiOperation("新增自动超参数寻优") + public GenericsAjaxResult addRay(@RequestBody RayVo rayVo) throws Exception { + return genericsSuccess(this.rayService.save(rayVo)); + } + + @PutMapping + @ApiOperation("编辑自动超参数寻优") + public GenericsAjaxResult editRay(@RequestBody RayVo rayVo) throws Exception{ + return genericsSuccess(this.rayService.edit(rayVo)); + } + + @GetMapping("/getRayDetail") + @ApiOperation("获取自动超参数寻优详细信息") + public GenericsAjaxResult getRayDetail(@RequestParam("id") Long id) throws IOException { + return genericsSuccess(this.rayService.getRayDetail(id)); + } + + @DeleteMapping("{id}") + @ApiOperation("删除自动超参数寻优") + public GenericsAjaxResult deleteRay(@PathVariable("id") Long id) { + return genericsSuccess(this.rayService.delete(id)); + } + + @PostMapping("/run/{id}") + @ApiOperation("运行自动超参数寻优实验") + public GenericsAjaxResult runRay(@PathVariable("id") Long id) throws Exception { + return genericsSuccess(this.rayService.runRayIns(id)); + } +} diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/ray/RayInsController.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/ray/RayInsController.java new file mode 100644 index 00000000..469ce497 --- /dev/null +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/ray/RayInsController.java @@ -0,0 +1,60 @@ +package com.ruoyi.platform.controller.ray; + +import com.ruoyi.common.core.web.controller.BaseController; +import com.ruoyi.common.core.web.domain.GenericsAjaxResult; +import com.ruoyi.platform.domain.RayIns; +import com.ruoyi.platform.service.RayInsService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.web.bind.annotation.*; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; + +import javax.annotation.Resource; +import java.io.IOException; +import java.util.List; + +@RestController +@RequestMapping("rayIns") +@Api("自动超参数寻优实验实例") +public class RayInsController extends BaseController { + @Resource + private RayInsService rayInsService; + + @GetMapping + @ApiOperation("分页查询") + public GenericsAjaxResult> queryByPage(Long rayId, int page, int size) throws IOException { + PageRequest pageRequest = PageRequest.of(page, size); + return genericsSuccess(this.rayInsService.queryByPage(rayId, pageRequest)); + } + + @PostMapping + @ApiOperation("新增实验实例") + public GenericsAjaxResult add(@RequestBody RayIns rayIns) { + return genericsSuccess(this.rayInsService.insert(rayIns)); + } + + @DeleteMapping("{id}") + @ApiOperation("删除实验实例") + public GenericsAjaxResult deleteById(@PathVariable("id") Long id) { + return genericsSuccess(this.rayInsService.deleteById(id)); + } + + @DeleteMapping("batchDelete") + @ApiOperation("批量删除实验实例") + public GenericsAjaxResult batchDelete(@RequestBody List ids) { + return genericsSuccess(this.rayInsService.batchDelete(ids)); + } + + @PutMapping("{id}") + @ApiOperation("终止实验实例") + public GenericsAjaxResult terminateRayIns(@PathVariable("id") Long id) throws Exception { + return genericsSuccess(this.rayInsService.terminateRayIns(id)); + } + + @GetMapping("{id}") + @ApiOperation("查看实验实例详情") + public GenericsAjaxResult getDetailById(@PathVariable("id") Long id) { + return genericsSuccess(this.rayInsService.getDetailById(id)); + } +} diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/Ray.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/Ray.java new file mode 100644 index 00000000..838a0311 --- /dev/null +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/Ray.java @@ -0,0 +1,77 @@ +package com.ruoyi.platform.domain; + +import com.fasterxml.jackson.databind.PropertyNamingStrategy; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.Date; + +@Data +@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) +@ApiModel(description = "自动超参数寻优") +public class Ray { + private Long id; + + @ApiModelProperty(value = "实验名称") + private String name; + + @ApiModelProperty(value = "数据集") + private String dataset; + + @ApiModelProperty(value = "代码") + private String code; + + @ApiModelProperty(value = "主函数代码文件") + private String mainPy; + + @ApiModelProperty(value = "总实验次数") + private Integer numSamples; + + @ApiModelProperty(value = "参数") + private String parameters; + + @ApiModelProperty(value = "手动指定需要运行的参数") + private String pointsToEvaluate; + + @ApiModelProperty(value = "保存路径") + private String storagePath; + + @ApiModelProperty(value = "搜索算法") + private String searchAlg; + + @ApiModelProperty(value = "调度算法") + private String scheduler; + + @ApiModelProperty(value = "指标") + private String metric; + + @ApiModelProperty(value = "指标最大化或最小化,min or max") + private String mode; + + @ApiModelProperty(value = "搜索算法为ASHA,HyperBand时传入,每次试验的最大时间单位。测试将在max_t时间单位后停止。") + private Integer maxT; + + @ApiModelProperty(value = "搜索算法为MedianStopping时传入,计算中位数的最小试验数。") + private Integer minSamplesRequired; + + @ApiModelProperty(value = "使用cpu数") + private Integer cpu; + + @ApiModelProperty(value = "使用gpu数") + private Integer gpu; + + private Integer state; + + private String createBy; + + private String updateBy; + + private Date createTime; + + private Date updateTime; + + @ApiModelProperty(value = "状态列表") + private String statusList; +} diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/RayIns.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/RayIns.java new file mode 100644 index 00000000..161a5f98 --- /dev/null +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/RayIns.java @@ -0,0 +1,45 @@ +package com.ruoyi.platform.domain; + +import com.fasterxml.jackson.databind.PropertyNamingStrategy; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.Date; + +@Data +@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) +@ApiModel(description = "自动超参数寻优实验实例") +public class RayIns { + private Long id; + + private Long rayId; + + private String resultPath; + + private Integer state; + + private String status; + + private String nodeStatus; + + private String nodeResult; + + private String param; + + private String source; + + @ApiModelProperty(value = "Argo实例名称") + private String argoInsName; + + @ApiModelProperty(value = "Argo命名空间") + private String argoInsNs; + + private Date createTime; + + private Date updateTime; + + private Date finishTime; +} + diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/RayDao.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/RayDao.java new file mode 100644 index 00000000..dad71b0f --- /dev/null +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/RayDao.java @@ -0,0 +1,21 @@ +package com.ruoyi.platform.mapper; + +import com.ruoyi.platform.domain.Ray; +import org.apache.ibatis.annotations.Param; +import org.springframework.data.domain.PageRequest; + +import java.util.List; + +public interface RayDao { + long count(@Param("name") String name); + + List queryByPage(@Param("name") String name, @Param("pageable") PageRequest pageRequest); + + Ray getRayByName(@Param("name") String name); + + Ray getRayById(@Param("id") Long id); + + int save(@Param("ray") Ray ray); + + int edit(@Param("ray") Ray ray); +} diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/RayInsDao.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/RayInsDao.java new file mode 100644 index 00000000..ceeb581d --- /dev/null +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/RayInsDao.java @@ -0,0 +1,21 @@ +package com.ruoyi.platform.mapper; + +import com.ruoyi.platform.domain.RayIns; +import org.apache.ibatis.annotations.Param; +import org.springframework.data.domain.Pageable; + +import java.util.List; + +public interface RayInsDao { + long count(@Param("rayId") Long rayId); + + List queryAllByLimit(@Param("rayId") Long rayId, @Param("pageable") Pageable pageable); + + RayIns queryById(@Param("id") Long id); + + List getByRayId(@Param("rayId") Long rayId); + + int insert(@Param("rayIns") RayIns rayIns); + + int update(@Param("rayIns") RayIns rayIns); +} diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/RayInsService.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/RayInsService.java new file mode 100644 index 00000000..10ea6983 --- /dev/null +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/RayInsService.java @@ -0,0 +1,21 @@ +package com.ruoyi.platform.service; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import com.ruoyi.platform.domain.RayIns; +import java.io.IOException; +import java.util.List; +public interface RayInsService { + Page queryByPage(Long rayId, PageRequest pageRequest) throws IOException; + + RayIns insert(RayIns rayIns); + + String deleteById(Long id); + + String batchDelete(List ids); + + boolean terminateRayIns(Long id) throws Exception; + + RayIns getDetailById(Long id); + + void updateRayStatus(Long rayId); +} diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/RayService.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/RayService.java new file mode 100644 index 00000000..b3659240 --- /dev/null +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/RayService.java @@ -0,0 +1,22 @@ +package com.ruoyi.platform.service; + +import com.ruoyi.platform.domain.Ray; +import com.ruoyi.platform.vo.RayVo; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; + +import java.io.IOException; + +public interface RayService { + Page queryByPage(String name, PageRequest pageRequest); + + Ray save(RayVo rayVo) throws Exception; + + String edit(RayVo rayVo) throws Exception; + + RayVo getRayDetail(Long id) throws IOException; + + String delete(Long id); + + String runRayIns(Long id) throws Exception; +} diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/RayInsServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/RayInsServiceImpl.java new file mode 100644 index 00000000..a9a00d30 --- /dev/null +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/RayInsServiceImpl.java @@ -0,0 +1,130 @@ +package com.ruoyi.platform.service.impl; + +import com.ruoyi.platform.constant.Constant; +import com.ruoyi.platform.domain.Ray; +import com.ruoyi.platform.domain.RayIns; +import com.ruoyi.platform.mapper.RayDao; +import com.ruoyi.platform.mapper.RayInsDao; +import com.ruoyi.platform.service.RayInsService; +import org.apache.commons.lang3.StringUtils; +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.io.IOException; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +@Service("rayInsService") +public class RayInsServiceImpl implements RayInsService { + @Resource + private RayInsDao rayInsDao; + + @Resource + private RayDao rayDao; + + @Override + public Page queryByPage(Long rayId, PageRequest pageRequest) throws IOException { + long total = this.rayInsDao.count(rayId); + List rayInsList = this.rayInsDao.queryAllByLimit(rayId, pageRequest); + return new PageImpl<>(rayInsList, pageRequest, total); + } + + @Override + public RayIns insert(RayIns rayIns) { + this.rayInsDao.insert(rayIns); + return rayIns; + } + + @Override + public String deleteById(Long id) { + RayIns rayIns = rayInsDao.queryById(id); + if (rayIns == null) { + return "实验实例不存在"; + } + if (StringUtils.isEmpty(rayIns.getStatus())) { + //todo queryStatusFromArgo + } + if (StringUtils.equals(rayIns.getStatus(), Constant.Running)) { + return "实验实例正在运行,不可删除"; + } + + rayIns.setState(Constant.State_invalid); + int update = rayInsDao.update(rayIns); + if (update > 0) { + updateRayStatus(rayIns.getRayId()); + return "删除成功"; + } else { + return "删除失败"; + } + } + + @Override + public String batchDelete(List ids) { + for (Long id : ids) { + String result = deleteById(id); + if (!"删除成功".equals(result)) { + return result; + } + } + return "删除成功"; + } + + @Override + public boolean terminateRayIns(Long id) throws Exception { + RayIns rayIns = rayInsDao.queryById(id); + if (rayIns == null) { + throw new IllegalStateException("实验实例未查询到,id: " + id); + } + + String currentStatus = rayIns.getStatus(); + String name = rayIns.getArgoInsName(); + String namespace = rayIns.getArgoInsNs(); + + // 获取当前状态,如果为空,则从Argo查询 + if (StringUtils.isEmpty(currentStatus)) { + // todo queryStatusFromArgo + } + + // 只有状态是"Running"时才能终止实例 + if (!currentStatus.equalsIgnoreCase(Constant.Running)) { + throw new Exception("终止错误,只有运行状态的实例才能终止"); // 如果不是"Running"状态,则不执行终止操作 + } + + //todo terminateFromArgo + + rayIns.setStatus(Constant.Terminated); + rayIns.setFinishTime(new Date()); + this.rayInsDao.update(rayIns); + updateRayStatus(rayIns.getRayId()); + return true; + } + + @Override + public RayIns getDetailById(Long id) { + RayIns rayIns = rayInsDao.queryById(id); + if (Constant.Running.equals(rayIns.getStatus()) || Constant.Pending.equals(rayIns.getStatus())) { + //todo queryStatusFromArgo + } + return rayIns; + } + + @Override + public void updateRayStatus(Long rayId) { + List insList = rayInsDao.getByRayId(rayId); + List statusList = new ArrayList<>(); + // 更新实验状态列表 + for (int i = 0; i < insList.size(); i++) { + statusList.add(insList.get(i).getStatus()); + } + String subStatus = statusList.toString().substring(1, statusList.toString().length() - 1); + Ray ray = rayDao.getRayById(rayId); + if (!StringUtils.equals(ray.getStatusList(), subStatus)) { + ray.setStatusList(subStatus); + rayDao.edit(ray); + } + } +} diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/RayServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/RayServiceImpl.java new file mode 100644 index 00000000..e3fdebaa --- /dev/null +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/RayServiceImpl.java @@ -0,0 +1,119 @@ +package com.ruoyi.platform.service.impl; + +import com.ruoyi.common.security.utils.SecurityUtils; +import com.ruoyi.platform.constant.Constant; +import com.ruoyi.platform.domain.Ray; +import com.ruoyi.platform.mapper.RayDao; +import com.ruoyi.platform.service.RayService; +import com.ruoyi.platform.utils.JacksonUtil; +import com.ruoyi.platform.utils.JsonUtils; +import com.ruoyi.platform.vo.RayVo; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.BeanUtils; +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.io.IOException; +import java.util.List; + +@Service("rayService") +public class RayServiceImpl implements RayService { + @Resource + private RayDao rayDao; + + @Override + public Page queryByPage(String name, PageRequest pageRequest) { + long total = rayDao.count(name); + List rays = rayDao.queryByPage(name, pageRequest); + return new PageImpl<>(rays, pageRequest, total); + } + + @Override + public Ray save(RayVo rayVo) throws Exception { + Ray rayByName = rayDao.getRayByName(rayVo.getName()); + if (rayByName != null) { + throw new RuntimeException("实验名称已存在"); + } + Ray ray = new Ray(); + BeanUtils.copyProperties(rayVo, ray); + String username = SecurityUtils.getLoginUser().getUsername(); + ray.setCreateBy(username); + ray.setUpdateBy(username); + String datasetJson = JacksonUtil.toJSONString(rayVo.getDataset()); + ray.setDataset(datasetJson); + String codeJson = JacksonUtil.toJSONString(rayVo.getCode()); + ray.setCode(codeJson); + rayDao.save(ray); + return ray; + } + + @Override + public String edit(RayVo rayVo) throws Exception { + Ray oldRay = rayDao.getRayByName(rayVo.getName()); + if (oldRay != null && !oldRay.getId().equals(rayVo.getId())) { + throw new RuntimeException("实验名称已存在"); + } + Ray ray = new Ray(); + BeanUtils.copyProperties(rayVo, ray); + String username = SecurityUtils.getLoginUser().getUsername(); + ray.setUpdateBy(username); + String parameters = JacksonUtil.toJSONString(rayVo.getParameters()); + ray.setParameters(parameters); + String pointsToEvaluate = JacksonUtil.toJSONString(rayVo.getPointsToEvaluate()); + ray.setPointsToEvaluate(pointsToEvaluate); + String datasetJson = JacksonUtil.toJSONString(rayVo.getDataset()); + ray.setDataset(datasetJson); + String codeJson = JacksonUtil.toJSONString(rayVo.getCode()); + ray.setCode(codeJson); + rayDao.edit(ray); + return "修改成功"; + } + + @Override + public RayVo getRayDetail(Long id) throws IOException { + Ray ray = rayDao.getRayById(id); + RayVo rayVo = new RayVo(); + BeanUtils.copyProperties(ray, rayVo); + if (StringUtils.isNotEmpty(ray.getParameters())) { + rayVo.setParameters(JsonUtils.jsonToMap(ray.getParameters())); + } + if (StringUtils.isNotEmpty(ray.getPointsToEvaluate())) { + rayVo.setPointsToEvaluate(JsonUtils.jsonToMap(ray.getPointsToEvaluate())); + } + if (StringUtils.isNotEmpty(ray.getDataset())) { + rayVo.setDataset(JsonUtils.jsonToMap(ray.getDataset())); + } + if (StringUtils.isNotEmpty(ray.getCode())) { + rayVo.setCode(JsonUtils.jsonToMap(ray.getCode())); + } + return rayVo; + } + + @Override + public String delete(Long id) { + Ray ray = rayDao.getRayById(id); + if (ray == null) { + throw new RuntimeException("实验不存在"); + } + String username = SecurityUtils.getLoginUser().getUsername(); + String createBy = ray.getCreateBy(); + if (!(StringUtils.equals(username, "admin") || StringUtils.equals(username, createBy))) { + throw new RuntimeException("无权限删除该实验"); + } + ray.setState(Constant.State_invalid); + return rayDao.edit(ray) > 0 ? "删除成功" : "删除失败"; + } + + @Override + public String runRayIns(Long id) throws Exception { + Ray ray = rayDao.getRayById(id); + if (ray == null) { + throw new Exception("自动超参数寻优配置不存在"); + } + //todo argo + return null; + } +} diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/RayVo.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/RayVo.java new file mode 100644 index 00000000..00f16b12 --- /dev/null +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/RayVo.java @@ -0,0 +1,76 @@ +package com.ruoyi.platform.vo; + +import com.fasterxml.jackson.databind.PropertyNamingStrategy; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.Date; +import java.util.Map; + +@Data +@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) +@ApiModel(description = "自动超参数寻优") +public class RayVo { + private Long id; + + @ApiModelProperty(value = "实验名称") + private String name; + + @ApiModelProperty(value = "主函数代码文件") + private String mainPy; + + @ApiModelProperty(value = "总实验次数") + private Integer numSamples; + + @ApiModelProperty(value = "参数") + private Map parameters; + + @ApiModelProperty(value = "手动指定需要运行的参数") + private Map pointsToEvaluate; + + @ApiModelProperty(value = "保存路径") + private String storagePath; + + @ApiModelProperty(value = "搜索算法") + private String searchAlg; + + @ApiModelProperty(value = "调度算法") + private String scheduler; + + @ApiModelProperty(value = "指标") + private String metric; + + @ApiModelProperty(value = "指标最大化或最小化,min or max") + private String mode; + + @ApiModelProperty(value = "搜索算法为ASHA,HyperBand时传入,每次试验的最大时间单位。测试将在max_t时间单位后停止。") + private Integer maxT; + + @ApiModelProperty(value = "搜索算法为MedianStopping时传入,计算中位数的最小试验数。") + private Integer minSamplesRequired; + + @ApiModelProperty(value = "使用cpu数") + private Integer cpu; + + @ApiModelProperty(value = "使用gpu数") + private Integer gpu; + + private String createBy; + + private Date createTime; + + private String updateBy; + + private Date updateTime; + + private Integer state; + + private String runState; + + @ApiModelProperty(value = "代码") + private Map code; + + private Map dataset; +} diff --git a/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/RayDaoMapper.xml b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/RayDaoMapper.xml new file mode 100644 index 00000000..7d6f8bd8 --- /dev/null +++ b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/RayDaoMapper.xml @@ -0,0 +1,109 @@ + + + + + insert into ray(name, dataset, code, main_py, num_samples, parameters, points_to_evaluate, storage_path, + search_alg, scheduler, metric, mode, max_t, + min_samples_required, cpu, gpu, create_by, update_by) + values (#{ray.name}, #{ray.dataset}, #{ray.code}, #{ray.mainPy}, #{ray.numSamples}, #{ray.parameters}, + #{ray.pointsToEvaluate}, #{ray.storagePath}, + #{ray.searchAlg}, #{ray.scheduler}, #{ray.metric}, #{ray.mode}, #{ray.maxT}, #{ray.minSamplesRequired}, + #{ray.cpu}, #{ray.gpu}, #{ray.createBy}, #{ray.updateBy}) + + + + update ray + + + name = #{ray.name}, + + + dataset = #{ray.dataset}, + + + code = #{ray.code}, + + + main_py = #{ray.mainPy}, + + + num_samples = #{ray.numSamples}, + + + parameters = #{ray.parameters}, + + + points_to_evaluate = #{ray.pointsToEvaluate}, + + + storage_path = #{ray.storagePath}, + + + search_alg = #{ray.searchAlg}, + + + scheduler = #{ray.scheduler}, + + + metric = #{ray.metric}, + + + mode = #{ray.mode}, + + + max_t = #{ray.maxT}, + + + min_samples_required = #{ray.minSamplesRequired}, + + + cpu = #{ray.cpu}, + + + gpu = #{ray.gpu}, + + + update_by = #{ray.updateBy}, + + + status_list = #{ray.statusList}, + + + state = #{ray.state}, + + + where id = #{ray.id} + + + + + + + + + + + + + state = 1 + + and name like concat('%', #{name}, '%') + + + + \ No newline at end of file diff --git a/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/RayInsDaoMapper.xml b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/RayInsDaoMapper.xml new file mode 100644 index 00000000..ca4b7231 --- /dev/null +++ b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/RayInsDaoMapper.xml @@ -0,0 +1,69 @@ + + + + + insert into ray_ins(ray_id, result_path, argo_ins_name, argo_ins_ns, node_status, node_result, param, source, + status) + values (#{rayIns.rayId}, #{rayIns.resultPath}, #{rayIns.argoInsName}, #{rayIns.argoInsNs}, + #{rayIns.nodeStatus}, #{rayIns.nodeResult}, #{rayIns.param}, #{rayIns.source}, #{rayIns.status}) + + + + update ray_ins + + + result_path = #{rayIns.resultPath}, + + + status = #{rayIns.status}, + + + node_status = #{rayIns.nodeStatus}, + + + node_result = #{rayIns.nodeResult}, + + + state = #{rayIns.state}, + + + finish_time = #{rayIns.finishTime}, + + + where id = #{rayIns.id} + + + + + + + + + + \ No newline at end of file