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 01/13] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E8=B6=85=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E5=AF=BB=E4=BC=98=E5=AE=9E=E9=AA=8C=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=BC=80=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 From 42cdfe89ce736db2ab47dce196bb0bd10f70ead4 Mon Sep 17 00:00:00 2001 From: chenzhihang <709011834@qq.com> Date: Mon, 6 Jan 2025 14:48:14 +0800 Subject: [PATCH 02/13] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=9C=BA=E5=99=A8=E5=AD=A6=E4=B9=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../platform/controller/autoML/AutoMlInsController.java | 2 +- .../java/com/ruoyi/platform/service/AutoMlInsService.java | 2 +- .../ruoyi/platform/service/impl/AutoMlInsServiceImpl.java | 6 +++--- .../com/ruoyi/platform/service/impl/AutoMlServiceImpl.java | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/autoML/AutoMlInsController.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/autoML/AutoMlInsController.java index 874ec59c..d57e7dd8 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/autoML/AutoMlInsController.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/autoML/AutoMlInsController.java @@ -49,7 +49,7 @@ public class AutoMlInsController extends BaseController { @PutMapping("{id}") @ApiOperation("终止实验实例") - public GenericsAjaxResult terminateAutoMlIns(@PathVariable("id") Long id) { + public GenericsAjaxResult terminateAutoMlIns(@PathVariable("id") Long id) throws Exception { return genericsSuccess(this.autoMLInsService.terminateAutoMlIns(id)); } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/AutoMlInsService.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/AutoMlInsService.java index 2131fc44..9776fa14 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/AutoMlInsService.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/AutoMlInsService.java @@ -21,7 +21,7 @@ public interface AutoMlInsService { AutoMlIns queryStatusFromArgo(AutoMlIns autoMlIns); - boolean terminateAutoMlIns(Long id); + boolean terminateAutoMlIns(Long id) throws Exception; AutoMlIns getDetailById(Long id); diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/AutoMlInsServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/AutoMlInsServiceImpl.java index dd4c2f07..89358f00 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/AutoMlInsServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/AutoMlInsServiceImpl.java @@ -57,7 +57,7 @@ public class AutoMlInsServiceImpl implements AutoMlInsService { if (StringUtils.isEmpty(autoMlIns.getStatus())) { autoMlIns = queryStatusFromArgo(autoMlIns); } - if (StringUtils.equals(autoMlIns.getStatus(), "Running")) { + if (StringUtils.equals(autoMlIns.getStatus(), Constant.Running)) { return "实验实例正在运行,不可删除"; } @@ -156,7 +156,7 @@ public class AutoMlInsServiceImpl implements AutoMlInsService { } @Override - public boolean terminateAutoMlIns(Long id) { + public boolean terminateAutoMlIns(Long id) throws Exception { AutoMlIns autoMlIns = autoMlInsDao.queryById(id); if (autoMlIns == null) { throw new IllegalStateException("实验实例未查询到,id: " + id); @@ -172,7 +172,7 @@ public class AutoMlInsServiceImpl implements AutoMlInsService { } // 只有状态是"Running"时才能终止实例 if (!currentStatus.equalsIgnoreCase(Constant.Running)) { - return false; // 如果不是"Running"状态,则不执行终止操作 + throw new Exception("终止错误,只有运行状态的实例才能终止"); // 如果不是"Running"状态,则不执行终止操作 } // 创建请求数据map diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/AutoMlServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/AutoMlServiceImpl.java index d5e436e8..dfddf71f 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/AutoMlServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/AutoMlServiceImpl.java @@ -102,13 +102,13 @@ public class AutoMlServiceImpl implements AutoMlService { public String delete(Long id) { AutoMl autoMl = autoMlDao.getAutoMlById(id); if (autoMl == null) { - throw new RuntimeException("服务不存在"); + throw new RuntimeException("实验不存在"); } String username = SecurityUtils.getLoginUser().getUsername(); String createBy = autoMl.getCreateBy(); if (!(StringUtils.equals(username, "admin") || StringUtils.equals(username, createBy))) { - throw new RuntimeException("无权限删除该服务"); + throw new RuntimeException("无权限删除该实验"); } autoMl.setState(Constant.State_invalid); From e61429f7aabcf7e8ab709cfff9131014f66f172f Mon Sep 17 00:00:00 2001 From: chenzhihang <709011834@qq.com> Date: Tue, 7 Jan 2025 08:33:40 +0800 Subject: [PATCH 03/13] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E8=B6=85=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E5=AF=BB=E4=BC=98=E5=AE=9E=E9=AA=8C=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/ruoyi/platform/domain/Ray.java | 3 +++ .../src/main/java/com/ruoyi/platform/vo/RayVo.java | 3 +++ .../resources/mapper/managementPlatform/RayDaoMapper.xml | 5 ++++- 3 files changed, 10 insertions(+), 1 deletion(-) 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 index 838a0311..1cd7dbc8 100644 --- 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 @@ -17,6 +17,9 @@ public class Ray { @ApiModelProperty(value = "实验名称") private String name; + @ApiModelProperty(value = "实验描述") + private String description; + @ApiModelProperty(value = "数据集") private String dataset; 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 index 00f16b12..4f6997c2 100644 --- 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 @@ -18,6 +18,9 @@ public class RayVo { @ApiModelProperty(value = "实验名称") private String name; + @ApiModelProperty(value = "实验描述") + private String description; + @ApiModelProperty(value = "主函数代码文件") private String mainPy; 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 index 7d6f8bd8..2c2e6196 100644 --- a/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/RayDaoMapper.xml +++ b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/RayDaoMapper.xml @@ -2,7 +2,7 @@ - insert into ray(name, dataset, code, main_py, num_samples, parameters, points_to_evaluate, storage_path, + insert into ray(name, description, 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}, @@ -17,6 +17,9 @@ name = #{ray.name}, + + description = #{ray.description}, + dataset = #{ray.dataset}, From 8fc2a4b5cfccc506f7718f4c56bee29b2cbf2d76 Mon Sep 17 00:00:00 2001 From: chenzhihang <709011834@qq.com> Date: Wed, 8 Jan 2025 16:46:04 +0800 Subject: [PATCH 04/13] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E8=B6=85=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E5=AF=BB=E4=BC=98=E5=AE=9E=E9=AA=8C=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/ruoyi/platform/domain/Ray.java | 3 +++ .../src/main/java/com/ruoyi/platform/vo/RayVo.java | 7 +++++-- .../resources/mapper/managementPlatform/RayDaoMapper.xml | 7 +++++-- 3 files changed, 13 insertions(+), 4 deletions(-) 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 index 1cd7dbc8..47a68380 100644 --- 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 @@ -23,6 +23,9 @@ public class Ray { @ApiModelProperty(value = "数据集") private String dataset; + @ApiModelProperty(value = "数据集挂载路径") + private String datasetPath; + @ApiModelProperty(value = "代码") private String code; 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 index 4f6997c2..0f3a7eda 100644 --- 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 @@ -48,10 +48,10 @@ public class RayVo { @ApiModelProperty(value = "指标最大化或最小化,min or max") private String mode; - @ApiModelProperty(value = "搜索算法为ASHA,HyperBand时传入,每次试验的最大时间单位。测试将在max_t时间单位后停止。") + @ApiModelProperty(value = "单次试验最大时间:单位秒,搜索算法为ASHA,HyperBand时传入,每次试验的最大时间单位。测试将在max_t时间单位后停止。") private Integer maxT; - @ApiModelProperty(value = "搜索算法为MedianStopping时传入,计算中位数的最小试验数。") + @ApiModelProperty(value = "计算中位数的最小试验数:搜索算法为MedianStopping时传入,计算中位数的最小试验数。") private Integer minSamplesRequired; @ApiModelProperty(value = "使用cpu数") @@ -76,4 +76,7 @@ public class RayVo { private Map code; private Map dataset; + + @ApiModelProperty(value = "数据集挂载路径") + private String datasetPath; } 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 index 2c2e6196..d592d444 100644 --- a/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/RayDaoMapper.xml +++ b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/RayDaoMapper.xml @@ -2,10 +2,10 @@ - insert into ray(name, description, dataset, code, main_py, num_samples, parameters, points_to_evaluate, storage_path, + insert into ray(name, description, dataset, dataset_path, 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}, + values (#{ray.name}, #{ray.dataset}, #{ray.datasetPath}, #{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}) @@ -23,6 +23,9 @@ dataset = #{ray.dataset}, + + dataset_path = #{ray.datasetPath}, + code = #{ray.code}, From 4358c6b3e2b3cd022d344b18b95a7580be517622 Mon Sep 17 00:00:00 2001 From: chenzhihang <709011834@qq.com> Date: Wed, 8 Jan 2025 16:57:31 +0800 Subject: [PATCH 05/13] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E8=B6=85=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E5=AF=BB=E4=BC=98=E5=AE=9E=E9=AA=8C=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/ruoyi/platform/vo/RayVo.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 index 0f3a7eda..82e66c2b 100644 --- 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 @@ -48,10 +48,10 @@ public class RayVo { @ApiModelProperty(value = "指标最大化或最小化,min or max") private String mode; - @ApiModelProperty(value = "单次试验最大时间:单位秒,搜索算法为ASHA,HyperBand时传入,每次试验的最大时间单位。测试将在max_t时间单位后停止。") + @ApiModelProperty(value = "单次试验最大时间:单位秒,调度算法为ASHA,HyperBand时传入,每次试验的最大时间单位。测试将在max_t时间单位后停止。") private Integer maxT; - @ApiModelProperty(value = "计算中位数的最小试验数:搜索算法为MedianStopping时传入,计算中位数的最小试验数。") + @ApiModelProperty(value = "计算中位数的最小试验数:调度算法为MedianStopping时传入,计算中位数的最小试验数。") private Integer minSamplesRequired; @ApiModelProperty(value = "使用cpu数") From a40a7a3892c3838b6e6da68a31e1195d32f8476a Mon Sep 17 00:00:00 2001 From: chenzhihang <709011834@qq.com> Date: Thu, 9 Jan 2025 17:19:19 +0800 Subject: [PATCH 06/13] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E8=B6=85=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E5=AF=BB=E4=BC=98=E5=AE=9E=E9=AA=8C=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../platform/service/impl/RayServiceImpl.java | 22 +++++++++++++------ .../java/com/ruoyi/platform/vo/RayVo.java | 5 +++-- .../managementPlatform/RayDaoMapper.xml | 2 +- 3 files changed, 19 insertions(+), 10 deletions(-) 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 index e3fdebaa..93add6d3 100644 --- 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 @@ -1,5 +1,7 @@ package com.ruoyi.platform.service.impl; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; import com.ruoyi.common.security.utils.SecurityUtils; import com.ruoyi.platform.constant.Constant; import com.ruoyi.platform.domain.Ray; @@ -17,7 +19,9 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.io.IOException; +import java.lang.reflect.Type; import java.util.List; +import java.util.Map; @Service("rayService") public class RayServiceImpl implements RayService { @@ -39,13 +43,13 @@ public class RayServiceImpl implements RayService { } Ray ray = new Ray(); BeanUtils.copyProperties(rayVo, ray); - String username = SecurityUtils.getLoginUser().getUsername(); +// String username = SecurityUtils.getLoginUser().getUsername(); + String username = "admin"; ray.setCreateBy(username); ray.setUpdateBy(username); - String datasetJson = JacksonUtil.toJSONString(rayVo.getDataset()); - ray.setDataset(datasetJson); - String codeJson = JacksonUtil.toJSONString(rayVo.getCode()); - ray.setCode(codeJson); + ray.setDataset(JacksonUtil.toJSONString(rayVo.getDataset())); + ray.setCode(JacksonUtil.toJSONString(rayVo.getCode())); + ray.setParameters(JacksonUtil.toJSONString(rayVo.getParameters())); rayDao.save(ray); return ray; } @@ -77,11 +81,15 @@ public class RayServiceImpl implements RayService { Ray ray = rayDao.getRayById(id); RayVo rayVo = new RayVo(); BeanUtils.copyProperties(ray, rayVo); + + Gson gson = new Gson(); + Type listType = new TypeToken>>() { + }.getType(); if (StringUtils.isNotEmpty(ray.getParameters())) { - rayVo.setParameters(JsonUtils.jsonToMap(ray.getParameters())); + rayVo.setParameters(gson.fromJson(ray.getParameters(), listType)); } if (StringUtils.isNotEmpty(ray.getPointsToEvaluate())) { - rayVo.setPointsToEvaluate(JsonUtils.jsonToMap(ray.getPointsToEvaluate())); + rayVo.setPointsToEvaluate(gson.fromJson(ray.getPointsToEvaluate(), listType)); } if (StringUtils.isNotEmpty(ray.getDataset())) { rayVo.setDataset(JsonUtils.jsonToMap(ray.getDataset())); 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 index 82e66c2b..af8b3e17 100644 --- 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 @@ -7,6 +7,7 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.util.Date; +import java.util.List; import java.util.Map; @Data @@ -28,10 +29,10 @@ public class RayVo { private Integer numSamples; @ApiModelProperty(value = "参数") - private Map parameters; + private List> parameters; @ApiModelProperty(value = "手动指定需要运行的参数") - private Map pointsToEvaluate; + private List> pointsToEvaluate; @ApiModelProperty(value = "保存路径") private String storagePath; 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 index d592d444..86d88f35 100644 --- a/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/RayDaoMapper.xml +++ b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/RayDaoMapper.xml @@ -5,7 +5,7 @@ insert into ray(name, description, dataset, dataset_path, 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.datasetPath}, #{ray.code}, #{ray.mainPy}, #{ray.numSamples}, #{ray.parameters}, + values (#{ray.name}, #{ray.description}, #{ray.dataset}, #{ray.datasetPath}, #{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}) From b1a7a3c12e50324a06d3526b172cac5398295abb Mon Sep 17 00:00:00 2001 From: chenzhihang <709011834@qq.com> Date: Mon, 13 Jan 2025 14:28:47 +0800 Subject: [PATCH 07/13] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E8=B6=85=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E5=AF=BB=E4=BC=98=E5=AE=9E=E9=AA=8C=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../platform/service/impl/RayServiceImpl.java | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) 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 index 93add6d3..82c983ae 100644 --- 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 @@ -43,13 +43,13 @@ public class RayServiceImpl implements RayService { } Ray ray = new Ray(); BeanUtils.copyProperties(rayVo, ray); -// String username = SecurityUtils.getLoginUser().getUsername(); - String username = "admin"; + String username = SecurityUtils.getLoginUser().getUsername(); ray.setCreateBy(username); ray.setUpdateBy(username); ray.setDataset(JacksonUtil.toJSONString(rayVo.getDataset())); ray.setCode(JacksonUtil.toJSONString(rayVo.getCode())); ray.setParameters(JacksonUtil.toJSONString(rayVo.getParameters())); + ray.setPointsToEvaluate(JacksonUtil.toJSONString(rayVo.getPointsToEvaluate())); rayDao.save(ray); return ray; } @@ -62,16 +62,11 @@ public class RayServiceImpl implements RayService { } 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); + ray.setUpdateBy(SecurityUtils.getLoginUser().getUsername()); + ray.setParameters(JacksonUtil.toJSONString(rayVo.getParameters())); + ray.setPointsToEvaluate(JacksonUtil.toJSONString(rayVo.getPointsToEvaluate())); + ray.setDataset(JacksonUtil.toJSONString(rayVo.getDataset())); + ray.setCode(JacksonUtil.toJSONString(rayVo.getCode())); rayDao.edit(ray); return "修改成功"; } From d895f392bbabd1360f8e4265ca2094f3f789382e Mon Sep 17 00:00:00 2001 From: chenzhihang <709011834@qq.com> Date: Wed, 15 Jan 2025 08:33:29 +0800 Subject: [PATCH 08/13] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E8=B6=85=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E5=AF=BB=E4=BC=98=E5=AE=9E=E9=AA=8C=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/ruoyi/platform/domain/Ray.java | 6 +----- .../src/main/java/com/ruoyi/platform/vo/RayVo.java | 6 +----- .../mapper/managementPlatform/RayDaoMapper.xml | 11 ++++------- 3 files changed, 6 insertions(+), 17 deletions(-) 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 index 47a68380..00ffb645 100644 --- 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 @@ -62,11 +62,7 @@ public class Ray { @ApiModelProperty(value = "搜索算法为MedianStopping时传入,计算中位数的最小试验数。") private Integer minSamplesRequired; - @ApiModelProperty(value = "使用cpu数") - private Integer cpu; - - @ApiModelProperty(value = "使用gpu数") - private Integer gpu; + private String resource; private Integer state; 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 index af8b3e17..8f001f38 100644 --- 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 @@ -55,11 +55,7 @@ public class RayVo { @ApiModelProperty(value = "计算中位数的最小试验数:调度算法为MedianStopping时传入,计算中位数的最小试验数。") private Integer minSamplesRequired; - @ApiModelProperty(value = "使用cpu数") - private Integer cpu; - - @ApiModelProperty(value = "使用gpu数") - private Integer gpu; + private String resource; private String createBy; 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 index 86d88f35..b8a7818c 100644 --- a/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/RayDaoMapper.xml +++ b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/RayDaoMapper.xml @@ -4,11 +4,11 @@ insert into ray(name, description, dataset, dataset_path, 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) + min_samples_required, resource, create_by, update_by) values (#{ray.name}, #{ray.description}, #{ray.dataset}, #{ray.datasetPath}, #{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}) + #{ray.resource}, #{ray.createBy}, #{ray.updateBy}) @@ -62,11 +62,8 @@ min_samples_required = #{ray.minSamplesRequired}, - - cpu = #{ray.cpu}, - - - gpu = #{ray.gpu}, + + resource = #{ray.resource}, update_by = #{ray.updateBy}, From f08114ee03c8d2e5ea87840e7ca723dca75a0bf4 Mon Sep 17 00:00:00 2001 From: chenzhihang <709011834@qq.com> Date: Mon, 20 Jan 2025 10:00:43 +0800 Subject: [PATCH 09/13] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E8=B6=85=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E5=AF=BB=E4=BC=98=E5=AE=9E=E9=AA=8C=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/ruoyi/platform/domain/Ray.java | 5 ++++- .../platform/service/impl/RayServiceImpl.java | 10 ++++++++++ .../main/java/com/ruoyi/platform/vo/RayVo.java | 7 +++++-- .../mapper/managementPlatform/RayDaoMapper.xml | 15 +++++++++------ 4 files changed, 28 insertions(+), 9 deletions(-) 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 index 00ffb645..ce8257ab 100644 --- 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 @@ -24,11 +24,14 @@ public class Ray { private String dataset; @ApiModelProperty(value = "数据集挂载路径") - private String datasetPath; + private String model; @ApiModelProperty(value = "代码") private String code; + @ApiModelProperty(value = "镜像") + private String image; + @ApiModelProperty(value = "主函数代码文件") private String mainPy; 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 index 82c983ae..fc7ef4be 100644 --- 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 @@ -48,6 +48,8 @@ public class RayServiceImpl implements RayService { ray.setUpdateBy(username); ray.setDataset(JacksonUtil.toJSONString(rayVo.getDataset())); ray.setCode(JacksonUtil.toJSONString(rayVo.getCode())); + ray.setModel(JacksonUtil.toJSONString(rayVo.getModel())); + ray.setImage(JacksonUtil.toJSONString(rayVo.getImage())); ray.setParameters(JacksonUtil.toJSONString(rayVo.getParameters())); ray.setPointsToEvaluate(JacksonUtil.toJSONString(rayVo.getPointsToEvaluate())); rayDao.save(ray); @@ -67,6 +69,8 @@ public class RayServiceImpl implements RayService { ray.setPointsToEvaluate(JacksonUtil.toJSONString(rayVo.getPointsToEvaluate())); ray.setDataset(JacksonUtil.toJSONString(rayVo.getDataset())); ray.setCode(JacksonUtil.toJSONString(rayVo.getCode())); + ray.setModel(JacksonUtil.toJSONString(rayVo.getModel())); + ray.setImage(JacksonUtil.toJSONString(rayVo.getImage())); rayDao.edit(ray); return "修改成功"; } @@ -92,6 +96,12 @@ public class RayServiceImpl implements RayService { if (StringUtils.isNotEmpty(ray.getCode())) { rayVo.setCode(JsonUtils.jsonToMap(ray.getCode())); } + if (StringUtils.isNotEmpty(ray.getModel())) { + rayVo.setModel(JsonUtils.jsonToMap(ray.getModel())); + } + if (StringUtils.isNotEmpty(ray.getImage())) { + rayVo.setImage(JsonUtils.jsonToMap(ray.getImage())); + } return rayVo; } 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 index 8f001f38..6e8963ee 100644 --- 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 @@ -74,6 +74,9 @@ public class RayVo { private Map dataset; - @ApiModelProperty(value = "数据集挂载路径") - private String datasetPath; + @ApiModelProperty(value = "模型") + private Map model; + + @ApiModelProperty(value = "镜像") + private Map image; } 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 index b8a7818c..a23ba911 100644 --- a/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/RayDaoMapper.xml +++ b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/RayDaoMapper.xml @@ -2,13 +2,13 @@ - insert into ray(name, description, dataset, dataset_path, code, main_py, num_samples, parameters, points_to_evaluate, storage_path, + insert into ray(name, description, dataset, model, code, main_py, num_samples, parameters, points_to_evaluate, storage_path, search_alg, scheduler, metric, mode, max_t, - min_samples_required, resource, create_by, update_by) - values (#{ray.name}, #{ray.description}, #{ray.dataset}, #{ray.datasetPath}, #{ray.code}, #{ray.mainPy}, #{ray.numSamples}, #{ray.parameters}, + min_samples_required, resource, image, create_by, update_by) + values (#{ray.name}, #{ray.description}, #{ray.dataset}, #{ray.model}, #{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.resource}, #{ray.createBy}, #{ray.updateBy}) + #{ray.resource}, #{ray.image}, #{ray.createBy}, #{ray.updateBy}) @@ -23,12 +23,15 @@ dataset = #{ray.dataset}, - - dataset_path = #{ray.datasetPath}, + + model = #{ray.model}, code = #{ray.code}, + + image = #{ray.image}, + main_py = #{ray.mainPy}, From 5b3daa7019638ac4eac3a804142f5902dd8d42e8 Mon Sep 17 00:00:00 2001 From: chenzhihang <709011834@qq.com> Date: Tue, 11 Feb 2025 09:19:28 +0800 Subject: [PATCH 10/13] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E8=B6=85=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E5=AF=BB=E4=BC=98=E5=AE=9E=E9=AA=8C=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ray/RayInsController.java | 2 +- .../com/ruoyi/platform/domain/RayIns.java | 6 +++ .../ruoyi/platform/service/RayInsService.java | 2 +- .../service/impl/RayInsServiceImpl.java | 43 +++++++++++++++++-- 4 files changed, 47 insertions(+), 6 deletions(-) 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 index 469ce497..d2c34074 100644 --- 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 @@ -54,7 +54,7 @@ public class RayInsController extends BaseController { @GetMapping("{id}") @ApiOperation("查看实验实例详情") - public GenericsAjaxResult getDetailById(@PathVariable("id") Long id) { + public GenericsAjaxResult getDetailById(@PathVariable("id") Long id) throws IOException { return genericsSuccess(this.rayInsService.getDetailById(id)); } } 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 index 161a5f98..3de2e1a9 100644 --- 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 @@ -1,12 +1,15 @@ package com.ruoyi.platform.domain; +import com.baomidou.mybatisplus.annotation.TableField; 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.ArrayList; import java.util.Date; +import java.util.Map; @Data @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) @@ -41,5 +44,8 @@ public class RayIns { private Date updateTime; private Date finishTime; + + @TableField(exist = false) + private ArrayList> trialList; } 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 index 10ea6983..867dd0a9 100644 --- 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 @@ -15,7 +15,7 @@ public interface RayInsService { boolean terminateRayIns(Long id) throws Exception; - RayIns getDetailById(Long id); + RayIns getDetailById(Long id) throws IOException; void updateRayStatus(Long rayId); } 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 index a9a00d30..976a43b5 100644 --- 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 @@ -6,6 +6,7 @@ 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 com.ruoyi.platform.utils.JsonUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; @@ -14,9 +15,11 @@ 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; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.*; +import java.util.stream.Collectors; @Service("rayInsService") public class RayInsServiceImpl implements RayInsService { @@ -104,11 +107,12 @@ public class RayInsServiceImpl implements RayInsService { } @Override - public RayIns getDetailById(Long id) { + public RayIns getDetailById(Long id) throws IOException { RayIns rayIns = rayInsDao.queryById(id); if (Constant.Running.equals(rayIns.getStatus()) || Constant.Pending.equals(rayIns.getStatus())) { //todo queryStatusFromArgo } + rayIns.setTrialList(getTrialList(rayIns.getResultPath())); return rayIns; } @@ -127,4 +131,35 @@ public class RayInsServiceImpl implements RayInsService { rayDao.edit(ray); } } + + public ArrayList> getTrialList(String directoryPath) throws IOException { + // 获取指定路径下的所有文件 + Path dirPath = Paths.get(directoryPath); + Path experimentState = Files.list(dirPath).filter(path -> Files.isRegularFile(path) && path.getFileName().toString().startsWith("experiment_state")).collect(Collectors.toList()).get(0); + String content = new String(Files.readAllBytes(experimentState)); + Map result = JsonUtils.jsonToMap(content); + ArrayList trial_data_list = (ArrayList) result.get("trial_data"); + + ArrayList> trialList = new ArrayList<>(); + + for (ArrayList trial_data : trial_data_list) { + Map trial_data_0 = JsonUtils.jsonToMap((String) trial_data.get(0)); + Map trial_data_1 = JsonUtils.jsonToMap((String) trial_data.get(1)); + + Map trial = new HashMap<>(); + trial.put("trial_id", trial_data_0.get("trial_id")); + trial.put("config", trial_data_0.get("config")); + trial.put("status", trial_data_0.get("status")); + + Map last_result = (Map) trial_data_1.get("last_result"); + Map metric_analysis = (Map) trial_data_1.get("metric_analysis"); + Map time_total_s = (Map) metric_analysis.get("time_total_s"); + + trial.put("training_iteration", last_result.get("training_iteration")); + trial.put("time", time_total_s.get("avg")); + + trialList.add(trial); + } + return trialList; + } } From df55816eb96fcc590dc597b3cb8ad41e7c5e47b9 Mon Sep 17 00:00:00 2001 From: chenzhihang <709011834@qq.com> Date: Tue, 25 Feb 2025 09:09:40 +0800 Subject: [PATCH 11/13] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E8=B6=85=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E5=AF=BB=E4=BC=98=E5=AE=9E=E9=AA=8C=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/ruoyi/platform/domain/Ray.java | 4 ++-- .../com/ruoyi/platform/service/impl/RayServiceImpl.java | 8 ++++---- .../src/main/java/com/ruoyi/platform/vo/RayVo.java | 2 +- .../resources/mapper/managementPlatform/RayDaoMapper.xml | 8 ++++---- 4 files changed, 11 insertions(+), 11 deletions(-) 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 index ce8257ab..674c6e34 100644 --- 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 @@ -26,8 +26,8 @@ public class Ray { @ApiModelProperty(value = "数据集挂载路径") private String model; - @ApiModelProperty(value = "代码") - private String code; + @ApiModelProperty(value = "代码配置") + private String codeConfig; @ApiModelProperty(value = "镜像") private String image; 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 index fc7ef4be..32c19964 100644 --- 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 @@ -47,7 +47,7 @@ public class RayServiceImpl implements RayService { ray.setCreateBy(username); ray.setUpdateBy(username); ray.setDataset(JacksonUtil.toJSONString(rayVo.getDataset())); - ray.setCode(JacksonUtil.toJSONString(rayVo.getCode())); + ray.setCodeConfig(JacksonUtil.toJSONString(rayVo.getCodeConfig())); ray.setModel(JacksonUtil.toJSONString(rayVo.getModel())); ray.setImage(JacksonUtil.toJSONString(rayVo.getImage())); ray.setParameters(JacksonUtil.toJSONString(rayVo.getParameters())); @@ -68,7 +68,7 @@ public class RayServiceImpl implements RayService { ray.setParameters(JacksonUtil.toJSONString(rayVo.getParameters())); ray.setPointsToEvaluate(JacksonUtil.toJSONString(rayVo.getPointsToEvaluate())); ray.setDataset(JacksonUtil.toJSONString(rayVo.getDataset())); - ray.setCode(JacksonUtil.toJSONString(rayVo.getCode())); + ray.setCodeConfig(JacksonUtil.toJSONString(rayVo.getCodeConfig())); ray.setModel(JacksonUtil.toJSONString(rayVo.getModel())); ray.setImage(JacksonUtil.toJSONString(rayVo.getImage())); rayDao.edit(ray); @@ -93,8 +93,8 @@ public class RayServiceImpl implements RayService { if (StringUtils.isNotEmpty(ray.getDataset())) { rayVo.setDataset(JsonUtils.jsonToMap(ray.getDataset())); } - if (StringUtils.isNotEmpty(ray.getCode())) { - rayVo.setCode(JsonUtils.jsonToMap(ray.getCode())); + if (StringUtils.isNotEmpty(ray.getCodeConfig())) { + rayVo.setCodeConfig(JsonUtils.jsonToMap(ray.getCodeConfig())); } if (StringUtils.isNotEmpty(ray.getModel())) { rayVo.setModel(JsonUtils.jsonToMap(ray.getModel())); 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 index 6e8963ee..4cf000e5 100644 --- 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 @@ -70,7 +70,7 @@ public class RayVo { private String runState; @ApiModelProperty(value = "代码") - private Map code; + private Map codeConfig; 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 index a23ba911..236141c4 100644 --- a/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/RayDaoMapper.xml +++ b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/RayDaoMapper.xml @@ -2,10 +2,10 @@ - insert into ray(name, description, dataset, model, code, 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, min_samples_required, resource, image, create_by, update_by) - values (#{ray.name}, #{ray.description}, #{ray.dataset}, #{ray.model}, #{ray.code}, #{ray.mainPy}, #{ray.numSamples}, #{ray.parameters}, + values (#{ray.name}, #{ray.description}, #{ray.dataset}, #{ray.model}, #{ray.codeConfig}, #{ray.mainPy}, #{ray.numSamples}, #{ray.parameters}, #{ray.pointsToEvaluate}, #{ray.storagePath}, #{ray.searchAlg}, #{ray.scheduler}, #{ray.metric}, #{ray.mode}, #{ray.maxT}, #{ray.minSamplesRequired}, #{ray.resource}, #{ray.image}, #{ray.createBy}, #{ray.updateBy}) @@ -26,8 +26,8 @@ model = #{ray.model}, - - code = #{ray.code}, + + code_config = #{ray.codeConfig}, image = #{ray.image}, From 8d6f0e2cb52fe23cf9c1338c19948a87cb3b8e6a Mon Sep 17 00:00:00 2001 From: chenzhihang <709011834@qq.com> Date: Wed, 26 Feb 2025 10:38:39 +0800 Subject: [PATCH 12/13] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E8=B6=85=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E5=AF=BB=E4=BC=98=E5=AE=9E=E9=AA=8C=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ruoyi/platform/mapper/RayInsDao.java | 2 + .../scheduling/AutoMlInsStatusTask.java | 3 +- .../platform/scheduling/RayInsStatusTask.java | 95 ++++++++++++ .../ruoyi/platform/service/RayInsService.java | 4 + .../service/impl/RayInsServiceImpl.java | 146 ++++++++++++++++-- .../platform/service/impl/RayServiceImpl.java | 83 +++++++++- .../com/ruoyi/platform/vo/RayParamVo.java | 50 ++++++ .../managementPlatform/RayInsDaoMapper.xml | 8 + 8 files changed, 379 insertions(+), 12 deletions(-) create mode 100644 ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/scheduling/RayInsStatusTask.java create mode 100644 ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/RayParamVo.java 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 index ceeb581d..86801d04 100644 --- 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 @@ -18,4 +18,6 @@ public interface RayInsDao { int insert(@Param("rayIns") RayIns rayIns); int update(@Param("rayIns") RayIns rayIns); + + List queryByRayInsIsNotTerminated(); } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/scheduling/AutoMlInsStatusTask.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/scheduling/AutoMlInsStatusTask.java index 5c94284f..fa07acf6 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/scheduling/AutoMlInsStatusTask.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/scheduling/AutoMlInsStatusTask.java @@ -1,5 +1,6 @@ package com.ruoyi.platform.scheduling; +import com.ruoyi.platform.constant.Constant; import com.ruoyi.platform.domain.AutoMl; import com.ruoyi.platform.domain.AutoMlIns; import com.ruoyi.platform.mapper.AutoMlDao; @@ -41,7 +42,7 @@ public class AutoMlInsStatusTask { try { autoMlIns = autoMlInsService.queryStatusFromArgo(autoMlIns); } catch (Exception e) { - autoMlIns.setStatus("Failed"); + autoMlIns.setStatus(Constant.Failed); } // 线程安全的添加操作 synchronized (autoMlIds) { diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/scheduling/RayInsStatusTask.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/scheduling/RayInsStatusTask.java new file mode 100644 index 00000000..23d03164 --- /dev/null +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/scheduling/RayInsStatusTask.java @@ -0,0 +1,95 @@ +package com.ruoyi.platform.scheduling; + +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.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +@Component() +public class RayInsStatusTask { + + @Resource + private RayInsService rayInsService; + @Resource + private RayInsDao rayInsDao; + @Resource + private RayDao rayDao; + + private List rayIds = new ArrayList<>(); + + @Scheduled(cron = "0/30 * * * * ?") // 每30S执行一次 + public void executeRayInsStatus() { + List rayInsList = rayInsService.queryByRayInsIsNotTerminated(); + + // 去argo查询状态 + List updateList = new ArrayList<>(); + if (rayInsList != null && rayInsList.size() > 0) { + for (RayIns rayIns : rayInsList) { + //当原本状态为null或非终止态时才调用argo接口 + try { + rayIns = rayInsService.queryStatusFromArgo(rayIns); + } catch (Exception e) { + rayIns.setStatus(Constant.Failed); + } + // 线程安全的添加操作 + synchronized (rayIds) { + rayIds.add(rayIns.getRayId()); + } + updateList.add(rayIns); + } + if (updateList.size() > 0) { + for (RayIns rayIns : updateList) { + rayInsDao.update(rayIns); + } + } + } + } + + @Scheduled(cron = "0/30 * * * * ?") // / 每30S执行一次 + public void executeRayStatus() { + if (rayIds.size() == 0) { + return; + } + // 存储需要更新的实验对象列表 + List updateRays = new ArrayList<>(); + for (Long rayId : rayIds) { + // 获取当前实验的所有实例列表 + 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); + updateRays.add(ray); + rayDao.edit(ray); + } + } + + if (!updateRays.isEmpty()) { + // 使用Iterator进行安全的删除操作 + Iterator iterator = rayIds.iterator(); + while (iterator.hasNext()) { + Long rayId = iterator.next(); + for (Ray ray : updateRays) { + if (ray.getId().equals(rayId)) { + iterator.remove(); + } + } + } + } + } +} 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 index 867dd0a9..63559ffe 100644 --- 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 @@ -18,4 +18,8 @@ public interface RayInsService { RayIns getDetailById(Long id) throws IOException; void updateRayStatus(Long rayId); + + RayIns queryStatusFromArgo(RayIns ins); + + List queryByRayInsIsNotTerminated(); } 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 index 976a43b5..f881faa4 100644 --- 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 @@ -6,8 +6,11 @@ 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 com.ruoyi.platform.utils.DateUtils; +import com.ruoyi.platform.utils.HttpUtils; import com.ruoyi.platform.utils.JsonUtils; import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Value; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; @@ -23,6 +26,13 @@ import java.util.stream.Collectors; @Service("rayInsService") public class RayInsServiceImpl implements RayInsService { + @Value("${argo.url}") + private String argoUrl; + @Value("${argo.workflowStatus}") + private String argoWorkflowStatus; + @Value("${argo.workflowTermination}") + private String argoWorkflowTermination; + @Resource private RayInsDao rayInsDao; @@ -49,7 +59,7 @@ public class RayInsServiceImpl implements RayInsService { return "实验实例不存在"; } if (StringUtils.isEmpty(rayIns.getStatus())) { - //todo queryStatusFromArgo + rayIns = queryStatusFromArgo(rayIns); } if (StringUtils.equals(rayIns.getStatus(), Constant.Running)) { return "实验实例正在运行,不可删除"; @@ -89,7 +99,7 @@ public class RayInsServiceImpl implements RayInsService { // 获取当前状态,如果为空,则从Argo查询 if (StringUtils.isEmpty(currentStatus)) { - // todo queryStatusFromArgo + currentStatus = queryStatusFromArgo(rayIns).getStatus(); } // 只有状态是"Running"时才能终止实例 @@ -97,20 +107,64 @@ public class RayInsServiceImpl implements RayInsService { throw new Exception("终止错误,只有运行状态的实例才能终止"); // 如果不是"Running"状态,则不执行终止操作 } - //todo terminateFromArgo + // 创建请求数据map + Map requestData = new HashMap<>(); + requestData.put("namespace", namespace); + requestData.put("name", name); + // 创建发送数据map,将请求数据作为"data"键的值 + Map res = new HashMap<>(); + res.put("data", requestData); + + try { + // 发送POST请求到Argo工作流状态查询接口,并将请求数据转换为JSON + String req = HttpUtils.sendPost(argoUrl + argoWorkflowTermination, null, JsonUtils.mapToJson(res)); + // 检查响应是否为空或无内容 + if (StringUtils.isEmpty(req)) { + throw new RuntimeException("终止响应内容为空。"); + + } + // 将响应的JSON字符串转换为Map对象 + Map runResMap = JsonUtils.jsonToMap(req); + // 从响应Map中直接获取"errCode"的值 + Integer errCode = (Integer) runResMap.get("errCode"); + if (errCode != null && errCode == 0) { + //更新autoMlIns,确保状态更新被保存到数据库 + RayIns ins = queryStatusFromArgo(rayIns); + String nodeStatus = ins.getNodeStatus(); + Map nodeMap = JsonUtils.jsonToMap(nodeStatus); - rayIns.setStatus(Constant.Terminated); - rayIns.setFinishTime(new Date()); - this.rayInsDao.update(rayIns); - updateRayStatus(rayIns.getRayId()); - return true; + // 遍历 map + for (Map.Entry entry : nodeMap.entrySet()) { + // 获取每个 Map 中的值并强制转换为 Map + Map innerMap = (Map) entry.getValue(); + // 检查 phase 的值 + if (innerMap.containsKey("phase")) { + String phaseValue = (String) innerMap.get("phase"); + // 如果值不等于 Succeeded,则赋值为 Failed + if (!StringUtils.equals("Succeeded", phaseValue)) { + innerMap.put("phase", "Failed"); + } + } + } + ins.setNodeStatus(JsonUtils.mapToJson(nodeMap)); + ins.setStatus(Constant.Terminated); + ins.setUpdateTime(new Date()); + rayInsDao.update(ins); + updateRayStatus(rayIns.getRayId()); + return true; + } else { + return false; + } + } catch (Exception e) { + throw new RuntimeException("终止实例错误: " + e.getMessage(), e); + } } @Override public RayIns getDetailById(Long id) throws IOException { RayIns rayIns = rayInsDao.queryById(id); if (Constant.Running.equals(rayIns.getStatus()) || Constant.Pending.equals(rayIns.getStatus())) { - //todo queryStatusFromArgo + rayIns = queryStatusFromArgo(rayIns); } rayIns.setTrialList(getTrialList(rayIns.getResultPath())); return rayIns; @@ -132,6 +186,80 @@ public class RayInsServiceImpl implements RayInsService { } } + @Override + public RayIns queryStatusFromArgo(RayIns ins) { + String namespace = ins.getArgoInsNs(); + String name = ins.getArgoInsName(); + + // 创建请求数据map + Map requestData = new HashMap<>(); + requestData.put("namespace", namespace); + requestData.put("name", name); + + // 创建发送数据map,将请求数据作为"data"键的值 + Map res = new HashMap<>(); + res.put("data", requestData); + + try { + // 发送POST请求到Argo工作流状态查询接口,并将请求数据转换为JSON + String req = HttpUtils.sendPost(argoUrl + argoWorkflowStatus, null, JsonUtils.mapToJson(res)); + // 检查响应是否为空或无内容 + if (req == null || StringUtils.isEmpty(req)) { + throw new RuntimeException("工作流状态响应为空。"); + } + // 将响应的JSON字符串转换为Map对象 + Map runResMap = JsonUtils.jsonToMap(req); + // 从响应Map中获取"data"部分 + Map data = (Map) runResMap.get("data"); + if (data == null || data.isEmpty()) { + throw new RuntimeException("工作流数据为空."); + } + // 从"data"中获取"status"部分,并返回"phase"的值 + Map status = (Map) data.get("status"); + if (status == null || status.isEmpty()) { + throw new RuntimeException("工作流状态为空。"); + } + + //解析流水线结束时间 + String finishedAtString = (String) status.get("finishedAt"); + if (finishedAtString != null && !finishedAtString.isEmpty()) { + Date finishTime = DateUtils.convertUTCtoShanghaiDate(finishedAtString); + ins.setFinishTime(finishTime); + } + + // 解析nodes字段,提取节点状态并转换为JSON字符串 + Map nodes = (Map) status.get("nodes"); + Map modifiedNodes = new LinkedHashMap<>(); + if (nodes != null) { + for (Map.Entry nodeEntry : nodes.entrySet()) { + Map nodeDetails = (Map) nodeEntry.getValue(); + String templateName = (String) nodeDetails.get("displayName"); + modifiedNodes.put(templateName, nodeDetails); + } + } + + + String nodeStatusJson = JsonUtils.mapToJson(modifiedNodes); + ins.setNodeStatus(nodeStatusJson); + + //终止态为终止不改 + if (!StringUtils.equals(ins.getStatus(), Constant.Terminated)) { + ins.setStatus(StringUtils.isNotEmpty((String) status.get("phase")) ? (String) status.get("phase") : Constant.Pending); + } + if (StringUtils.equals(ins.getStatus(), "Error")) { + ins.setStatus(Constant.Failed); + } + return ins; + } catch (Exception e) { + throw new RuntimeException("查询状态失败: " + e.getMessage(), e); + } + } + + @Override + public List queryByRayInsIsNotTerminated() { + return rayInsDao.queryByRayInsIsNotTerminated(); + } + public ArrayList> getTrialList(String directoryPath) throws IOException { // 获取指定路径下的所有文件 Path dirPath = Paths.get(directoryPath); 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 index 32c19964..1d812659 100644 --- 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 @@ -4,14 +4,22 @@ import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import com.ruoyi.common.security.utils.SecurityUtils; import com.ruoyi.platform.constant.Constant; +import com.ruoyi.platform.domain.AutoMlIns; 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 com.ruoyi.platform.service.RayService; +import com.ruoyi.platform.utils.HttpUtils; import com.ruoyi.platform.utils.JacksonUtil; import com.ruoyi.platform.utils.JsonUtils; +import com.ruoyi.platform.vo.RayParamVo; import com.ruoyi.platform.vo.RayVo; +import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Value; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; @@ -20,13 +28,30 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.io.IOException; import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; @Service("rayService") public class RayServiceImpl implements RayService { + + @Value("${argo.url}") + private String argoUrl; + @Value("${argo.convertRay}") + String convertRay; + @Value("${argo.workflowRun}") + private String argoWorkflowRun; + + @Value("${minio.endpoint}") + private String minioEndpoint; + @Resource private RayDao rayDao; + @Resource + private RayInsDao rayInsDao; + @Resource + private RayInsService rayInsService; @Override public Page queryByPage(String name, PageRequest pageRequest) { @@ -126,7 +151,61 @@ public class RayServiceImpl implements RayService { if (ray == null) { throw new Exception("自动超参数寻优配置不存在"); } - //todo argo - return null; + + 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 converMap = JsonUtils.jsonToMap(convertRes); + // 组装运行接口json + Map output = (Map) converMap.get("output"); + Map 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 runResMap = JsonUtils.jsonToMap(runRes); + Map data = (Map) runResMap.get("data"); + //判断data为空 + if (data == null || MapUtils.isEmpty(data)) { + throw new RuntimeException("Failed to run workflow."); + } + Map metadata = (Map) 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 param_output = (Map) output.get("param_output"); + List output1 = (ArrayList) param_output.values().toArray()[0]; + Map output2 = (Map) output1.get(0); + String outputPath = minioEndpoint + "/" + output2.get("path").replace("{{workflow.name}}", (String) metadata.get("name")) + "/"; + + rayIns.setResultPath(outputPath); + rayInsDao.insert(rayIns); + rayInsService.updateRayStatus(id); + } catch (Exception e) { + throw new RuntimeException(e); + } + return "执行成功"; } } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/RayParamVo.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/RayParamVo.java new file mode 100644 index 00000000..4b6e1c5a --- /dev/null +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/RayParamVo.java @@ -0,0 +1,50 @@ +package com.ruoyi.platform.vo; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.PropertyNamingStrategy; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import io.swagger.annotations.ApiModel; +import lombok.Data; + +import java.util.Map; + +@Data +@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) +@JsonInclude(JsonInclude.Include.NON_NULL) +@ApiModel(description = "超参数寻优参数") +public class RayParamVo { + + private Map codeConfig; + + private Map dataset; + + private Map image; + + private Map model; + + private String mainPy; + + private String name; + + private Integer numSamples; + + private String parameters; + + private String pointsToEvaluate; + + private String storagePath; + + private String searchAlg; + + private String scheduler; + + private String metric; + + private String mode; + + private Integer maxT; + + private Integer minSamplesRequired; + + private String resource; +} 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 index ca4b7231..2b9c12ac 100644 --- a/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/RayInsDaoMapper.xml +++ b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/RayInsDaoMapper.xml @@ -66,4 +66,12 @@ and state = 1 order by update_time DESC limit 5 + + \ No newline at end of file From 0eb5606731a8396a647c77feaf382e9aa9678d3c Mon Sep 17 00:00:00 2001 From: chenzhihang <709011834@qq.com> Date: Wed, 26 Feb 2025 13:39:50 +0800 Subject: [PATCH 13/13] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E8=B6=85=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E5=AF=BB=E4=BC=98=E5=AE=9E=E9=AA=8C=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/ruoyi/platform/service/impl/RayServiceImpl.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 index 1d812659..db003344 100644 --- 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 @@ -4,7 +4,6 @@ import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import com.ruoyi.common.security.utils.SecurityUtils; import com.ruoyi.platform.constant.Constant; -import com.ruoyi.platform.domain.AutoMlIns; import com.ruoyi.platform.domain.Ray; import com.ruoyi.platform.domain.RayIns; import com.ruoyi.platform.mapper.RayDao; @@ -198,7 +197,7 @@ public class RayServiceImpl implements RayService { Map param_output = (Map) output.get("param_output"); List output1 = (ArrayList) param_output.values().toArray()[0]; Map output2 = (Map) output1.get(0); - String outputPath = minioEndpoint + "/" + output2.get("path").replace("{{workflow.name}}", (String) metadata.get("name")) + "/"; + String outputPath = minioEndpoint + "/" + output2.get("path").replace("{{workflow.name}}", (String) metadata.get("name")) + "/" + ray.getName(); rayIns.setResultPath(outputPath); rayInsDao.insert(rayIns);