diff --git a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/constant/Constant.java b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/constant/Constant.java index 8ef31ba8..62ec5715 100644 --- a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/constant/Constant.java +++ b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/constant/Constant.java @@ -39,6 +39,10 @@ public class Constant { public final static String Init = "Init"; public final static String Stopped = "Stopped"; public final static String Succeeded = "Succeeded"; + public final static String Error = "Error"; + + public final static String Unknown = "Unknown"; + public final static String Available = "available"; public final static String Type_Train = "train"; public final static String Type_Evaluate = "evaluate"; diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/activeLearn/ActiveLearnController.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/activeLearn/ActiveLearnController.java index 694375aa..09e5bee1 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/activeLearn/ActiveLearnController.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/activeLearn/ActiveLearnController.java @@ -7,9 +7,9 @@ import com.ruoyi.platform.service.ActiveLearnService; import com.ruoyi.platform.vo.ActiveLearnVo; 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 org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.io.IOException; @@ -17,29 +17,29 @@ import java.io.IOException; @RestController @RequestMapping("activeLearn") @Api("主动学习") -public class ActiveLearnController extends BaseController { - +public class ActiveLearnController extends BaseController { @Resource private ActiveLearnService activeLearnService; @GetMapping @ApiOperation("分页查询") public GenericsAjaxResult> queryByPage(@RequestParam("page") int page, - @RequestParam("size") int size, @RequestParam(value = "name", required = false) String name) { + @RequestParam("size") int size, + @RequestParam(value = "name", required = false) String name) { PageRequest pageRequest = PageRequest.of(page, size); return genericsSuccess(this.activeLearnService.queryByPage(name, pageRequest)); } @PostMapping @ApiOperation("新增主动学习") - public GenericsAjaxResult addActiveLearn(@RequestBody ActiveLearnVo activeLearnServiceVo) { - return genericsSuccess(this.activeLearnService.save(activeLearnServiceVo)); + public GenericsAjaxResult addActiveLearn(@RequestBody ActiveLearnVo activeLearnVo) throws Exception { + return genericsSuccess(this.activeLearnService.save(activeLearnVo)); } @PutMapping @ApiOperation("编辑主动学习") - public GenericsAjaxResult editActiveLearn(@RequestBody ActiveLearnVo activeLearnServiceVo) { - return genericsSuccess(this.activeLearnService.edit(activeLearnServiceVo)); + public GenericsAjaxResult editActiveLearn(@RequestBody ActiveLearnVo activeLearnVo) throws Exception { + return genericsSuccess(this.activeLearnService.edit(activeLearnVo)); } @GetMapping("/getActiveLearnDetail") diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/activeLearn/ActiveLearnInsController.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/activeLearn/ActiveLearnInsController.java index 7af4c201..e5112ab5 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/activeLearn/ActiveLearnInsController.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/activeLearn/ActiveLearnInsController.java @@ -6,9 +6,9 @@ import com.ruoyi.platform.domain.ActiveLearnIns; import com.ruoyi.platform.service.ActiveLearnInsService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import org.springframework.data.domain.PageRequest; 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; @@ -23,15 +23,21 @@ public class ActiveLearnInsController extends BaseController { @GetMapping @ApiOperation("分页查询") - public GenericsAjaxResult> queryByPage(ActiveLearnIns activeLearnIns, int page, int size) throws IOException { + public GenericsAjaxResult> queryByPage(Long activeLearnId, int page, int size) throws IOException { PageRequest pageRequest = PageRequest.of(page, size); - return genericsSuccess(this.activeLearnInsService.queryByPage(activeLearnIns, pageRequest)); + return genericsSuccess(this.activeLearnInsService.queryByPage(activeLearnId, pageRequest)); + } + + @PostMapping + @ApiOperation("新增实验实例") + public GenericsAjaxResult add(@RequestBody ActiveLearnIns activeLearnIns) { + return genericsSuccess(this.activeLearnInsService.insert(activeLearnIns)); } @DeleteMapping("{id}") @ApiOperation("删除实验实例") public GenericsAjaxResult deleteById(@PathVariable("id") Long id) { - return genericsSuccess(this.activeLearnInsService.removeById(id)); + return genericsSuccess(this.activeLearnInsService.deleteById(id)); } @DeleteMapping("batchDelete") @@ -42,13 +48,13 @@ public class ActiveLearnInsController extends BaseController { @PutMapping("{id}") @ApiOperation("终止实验实例") - public GenericsAjaxResult terminateActiveLearnIns(@PathVariable("id") Long id) { + public GenericsAjaxResult terminateActiveLearnIns(@PathVariable("id") Long id) throws Exception { return genericsSuccess(this.activeLearnInsService.terminateActiveLearnIns(id)); } @GetMapping("{id}") @ApiOperation("查看实验实例详情") - public GenericsAjaxResult getDetailById(@PathVariable("id") Long id) { + public GenericsAjaxResult getDetailById(@PathVariable("id") Long id) throws Exception { return genericsSuccess(this.activeLearnInsService.getDetailById(id)); } } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/image/ImageController.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/image/ImageController.java index d4be4c95..ff54512c 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/image/ImageController.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/image/ImageController.java @@ -115,6 +115,7 @@ public class ImageController extends BaseController { * @return 删除是否成功 */ @DeleteMapping("{id}") + @ApiOperation("删除镜像") public GenericsAjaxResult deleteById(@PathVariable("id") Integer id) throws Exception { return genericsSuccess(this.imageService.removeById(id)); } 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 index 719f5747..4c8852f4 100644 --- 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 @@ -50,7 +50,7 @@ public class RayController extends BaseController { @DeleteMapping("{id}") @ApiOperation("删除自动超参数寻优") - public GenericsAjaxResult deleteRay(@PathVariable("id") Long id) { + public GenericsAjaxResult deleteRay(@PathVariable("id") Long id) { return genericsSuccess(this.rayService.delete(id)); } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/service/ServiceController.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/service/ServiceController.java index e18d0899..0e06647c 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/service/ServiceController.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/service/ServiceController.java @@ -85,13 +85,13 @@ public class ServiceController extends BaseController { @GetMapping("/serviceVersionDetail/{id}") @ApiOperation("查询服务版本详细信息") - public GenericsAjaxResult getServiceVersion(@PathVariable("id") Long id) { + public GenericsAjaxResult getServiceVersion(@PathVariable("id") Long id) throws IOException { return genericsSuccess(serviceService.getServiceVersion(id)); } @GetMapping("serviceVersionCompare") @ApiOperation("服务版本版本对比") - public GenericsAjaxResult> serviceVersionCompare(@RequestParam("id1") Long id1, @RequestParam("id2") Long id2) throws IllegalAccessException { + public GenericsAjaxResult> serviceVersionCompare(@RequestParam("id1") Long id1, @RequestParam("id2") Long id2) throws IllegalAccessException, IOException { return genericsSuccess(serviceService.serviceVersionCompare(id1, id2)); } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/ActiveLearn.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/ActiveLearn.java index 33cd6426..efa2419c 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/ActiveLearn.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/ActiveLearn.java @@ -20,10 +20,16 @@ public class ActiveLearn { @ApiModelProperty(value = "实验描述") private String description; - @ApiModelProperty(value = "任务类型:classification, regression") + @ApiModelProperty(value = "任务类型:classification或regression") private String taskType; - @ApiModelProperty(value = "预训练模型") + @ApiModelProperty(value = "框架类型: sklearn, keras, pytorch") + private String frameworkType; + + @ApiModelProperty(value = "代码配置") + private String codeConfig; + + @ApiModelProperty(value = "预训练的模型") private String model; @ApiModelProperty(value = "模型文件路径") @@ -38,13 +44,13 @@ public class ActiveLearn { @ApiModelProperty(value = "回归算法") private String regressorAlg; - @ApiModelProperty(value = "dataset文件路径") + @ApiModelProperty(value = "dataset处理文件路径") private String datasetPy; @ApiModelProperty(value = "dataset类名") private String datasetClassName; - @ApiModelProperty(value = "数据集文件路径") + @ApiModelProperty(value = "数据集") private String dataset; @ApiModelProperty(value = "数据量") @@ -53,6 +59,7 @@ public class ActiveLearn { @ApiModelProperty(value = "镜像") private String image; + @ApiModelProperty(value = "计算资源id") private Integer computingResourceId; @ApiModelProperty(value = "是否随机打乱") @@ -91,16 +98,16 @@ public class ActiveLearn { @ApiModelProperty(value = "学习率") private Float lr; - private Integer state; - private String createBy; - private Date createTime; - private String updateBy; + private Date createTime; + private Date updateTime; + private Integer state; + @ApiModelProperty(value = "状态列表") private String statusList; } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/ActiveLearnIns.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/ActiveLearnIns.java index 94bfe470..91b65813 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/ActiveLearnIns.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/ActiveLearnIns.java @@ -3,7 +3,6 @@ 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; @@ -16,23 +15,25 @@ public class ActiveLearnIns { private Long activeLearnId; + private Integer state; + + private String status; + private String param; - private String resultPath; + private Date createTime; - private Integer state; + private Date updateTime; - private String status; + private Date finishTime; - @ApiModelProperty(value = "Argo实例名称") private String argoInsName; - @ApiModelProperty(value = "Argo命名空间") private String argoInsNs; - private Date createTime; + private String resultPath; - private Date updateTime; + private String nodeStatus; - private Date finishTime; + private String nodeResult; } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/ResourceOccupy.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/ResourceOccupy.java index fb7ceb03..754d8ae1 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/ResourceOccupy.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/ResourceOccupy.java @@ -49,9 +49,12 @@ public class ResourceOccupy { @ApiModelProperty("流水线id") private Long workflowId; + @ApiModelProperty("流水线节点id") + private String nodeId; + @ApiModelProperty("任务名称") private String taskName; - @ApiModelProperty("流水线节点id") - private String nodeId; + @ApiModelProperty("任务状态") + private Integer taskState; } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/ActiveLearnDao.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/ActiveLearnDao.java index bfa2d63e..a6f06a27 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/ActiveLearnDao.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/ActiveLearnDao.java @@ -2,14 +2,14 @@ package com.ruoyi.platform.mapper; import com.ruoyi.platform.domain.ActiveLearn; import org.apache.ibatis.annotations.Param; -import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.PageRequest; import java.util.List; public interface ActiveLearnDao { long count(@Param("name") String name); - List queryByPage(@Param("name") String name, @Param("pageable") Pageable pageable); + List queryByPage(@Param("name") String name, @Param("pageable") PageRequest pageRequest); ActiveLearn getActiveLearnByName(@Param("name") String name); diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/ActiveLearnInsDao.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/ActiveLearnInsDao.java index 2793665c..751c8460 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/ActiveLearnInsDao.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/ActiveLearnInsDao.java @@ -7,9 +7,9 @@ import org.springframework.data.domain.Pageable; import java.util.List; public interface ActiveLearnInsDao { - long count(@Param("activeLearnIns") ActiveLearnIns activeLearnIns); + long count(@Param("activeLearnId") Long activeLearnId); - List queryAllByLimit(@Param("activeLearnIns") ActiveLearnIns activeLearnIns, @Param("pageable") Pageable pageable); + List queryAllByLimit(@Param("activeLearnId") Long activeLearnId, @Param("pageable") Pageable pageable); int insert(@Param("activeLearnIns") ActiveLearnIns activeLearnIns); @@ -18,4 +18,6 @@ public interface ActiveLearnInsDao { ActiveLearnIns queryById(@Param("id") Long id); List getByActiveLearnId(@Param("activeLearnId") Long activeLearnId); + + List queryActiveLearnInsIsNotTerminated(); } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/DevEnvironmentDao.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/DevEnvironmentDao.java index 0c1df5fe..60c51286 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/DevEnvironmentDao.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/DevEnvironmentDao.java @@ -63,5 +63,11 @@ public interface DevEnvironmentDao { int deleteById(Integer id); List getRunning(); + + List queryByDatasetId(@Param("datasetId") String datasetId); + + List queryByModelId(@Param("modelId") String modelId); + + List queryByImageId(@Param("imageId") String imageId); } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/ResourceOccupyDao.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/ResourceOccupyDao.java index 5c0b469a..9388f53d 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/ResourceOccupyDao.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/ResourceOccupyDao.java @@ -29,4 +29,6 @@ public interface ResourceOccupyDao { Double getUserCredit(@Param("userId") Long userId); Double getDeduceCredit(@Param("userId") Long userId); + + int deleteTaskState(String taskType, Long taskId, Long taskInsId); } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/ServiceDao.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/ServiceDao.java index 6b65a33d..c499f252 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/ServiceDao.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/ServiceDao.java @@ -38,4 +38,10 @@ public interface ServiceDao { ServiceVersion getSvByVersion(@Param("version") String version, @Param("serviceId") Long serviceId); List getRunning(); + + List queryByModelId(@Param("modelId") String modelId); + + List queryByImageId(@Param("imageId") String imageId); + + List queryByCodeConfig(@Param("codeConfig") String codeConfig); } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/scheduling/ActiveLearnInsStatusTask.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/scheduling/ActiveLearnInsStatusTask.java new file mode 100644 index 00000000..c08d6512 --- /dev/null +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/scheduling/ActiveLearnInsStatusTask.java @@ -0,0 +1,116 @@ +package com.ruoyi.platform.scheduling; + +import com.ruoyi.platform.domain.ActiveLearn; +import com.ruoyi.platform.domain.ActiveLearnIns; +import com.ruoyi.platform.mapper.ActiveLearnDao; +import com.ruoyi.platform.mapper.ActiveLearnInsDao; +import com.ruoyi.platform.mapper.ResourceOccupyDao; +import com.ruoyi.platform.service.ActiveLearnInsService; +import com.ruoyi.platform.service.ResourceOccupyService; +import com.ruoyi.system.api.constant.Constant; +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 ActiveLearnInsStatusTask { + + @Resource + private ActiveLearnInsService activeLearnInsService; + @Resource + private ActiveLearnInsDao activeLearnInsDao; + @Resource + private ActiveLearnDao activeLearnDao; + @Resource + private ResourceOccupyDao resourceOccupyDao; + @Resource + private ResourceOccupyService resourceOccupyService; + + private List activeLearnIds = new ArrayList<>(); + + @Scheduled(cron = "0/30 * * * * ?") // 每30S执行一次 + public void executeActiveLearnInsStatus() { + List activeLearnInsList = activeLearnInsService.queryActiveLearnInsIsNotTerminated(); + + // 去argo查询状态 + List updateList = new ArrayList<>(); + if (activeLearnInsList != null && activeLearnInsList.size() > 0) { + for (ActiveLearnIns activeLearnIns : activeLearnInsList) { + //当原本状态为null或非终止态时才调用argo接口 + try { + Long userId = resourceOccupyDao.getResourceOccupyByTask(Constant.TaskType_ActiveLearn, activeLearnIns.getActiveLearnId(), activeLearnIns.getId(), null).get(0).getUserId(); + if (resourceOccupyDao.getUserCredit(userId) <= 0) { + activeLearnIns.setStatus(Constant.Failed); + activeLearnInsService.terminateActiveLearnIns(activeLearnIns.getId()); + } else { + activeLearnIns = activeLearnInsService.queryStatusFromArgo(activeLearnIns); + // 扣除积分 + if (Constant.Running.equals(activeLearnIns.getStatus())) { + resourceOccupyService.deducing(Constant.TaskType_ActiveLearn, null, activeLearnIns.getId(), null, null); + } else if (Constant.Failed.equals(activeLearnIns.getStatus()) || Constant.Terminated.equals(activeLearnIns.getStatus()) + || Constant.Succeeded.equals(activeLearnIns.getStatus())) { + resourceOccupyService.endDeduce(Constant.TaskType_ActiveLearn, null, activeLearnIns.getId(), null, null); + } + } + } catch (Exception e) { + activeLearnIns.setStatus(Constant.Failed); + // 结束扣除积分 + resourceOccupyService.endDeduce(Constant.TaskType_ActiveLearn, null, activeLearnIns.getId(), null, null); + } + // 线程安全的添加操作 + synchronized (activeLearnIds) { + activeLearnIds.add(activeLearnIns.getActiveLearnId()); + } + updateList.add(activeLearnIns); + } + if (updateList.size() > 0) { + for (ActiveLearnIns activeLearnIns : updateList) { + activeLearnInsDao.update(activeLearnIns); + } + } + } + } + + @Scheduled(cron = "0/30 * * * * ?") // / 每30S执行一次 + public void executeActiveLearnStatus() { + if (activeLearnIds.size() == 0) { + return; + } + // 存储需要更新的实验对象列表 + List updateActiveLearns = new ArrayList<>(); + for (Long activeLearnId : activeLearnIds) { + // 获取当前实验的所有实例列表 + List insList = activeLearnInsDao.getByActiveLearnId(activeLearnId); + 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); + ActiveLearn activeLearn = activeLearnDao.getActiveLearnById(activeLearnId); + if (!StringUtils.equals(activeLearn.getStatusList(), subStatus)) { + activeLearn.setStatusList(subStatus); + updateActiveLearns.add(activeLearn); + activeLearnDao.edit(activeLearn); + } + } + + if (!updateActiveLearns.isEmpty()) { + // 使用Iterator进行安全的删除操作 + Iterator iterator = activeLearnIds.iterator(); + while (iterator.hasNext()) { + Long activeLearnId = iterator.next(); + for (ActiveLearn activeLearn : updateActiveLearns) { + if (activeLearn.getId().equals(activeLearnId)) { + iterator.remove(); + } + } + } + } + } +} diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ActiveLearnInsService.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ActiveLearnInsService.java index 21433f21..09df121b 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ActiveLearnInsService.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ActiveLearnInsService.java @@ -8,15 +8,21 @@ import java.io.IOException; import java.util.List; public interface ActiveLearnInsService { - Page queryByPage(ActiveLearnIns activeLearnIns, PageRequest pageRequest) throws IOException; + Page queryByPage(Long activeLearnId, PageRequest pageRequest) throws IOException; ActiveLearnIns insert(ActiveLearnIns activeLearnIns); - String removeById(Long id); + String deleteById(Long id); String batchDelete(List ids); - boolean terminateActiveLearnIns(Long id); + boolean terminateActiveLearnIns(Long id) throws Exception; - ActiveLearnIns getDetailById(Long id); + ActiveLearnIns getDetailById(Long id) throws Exception; + + void updateActiveLearnStatus(Long activeLearnId); + + ActiveLearnIns queryStatusFromArgo(ActiveLearnIns ins); + + List queryActiveLearnInsIsNotTerminated(); } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ActiveLearnService.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ActiveLearnService.java index 73b82c64..ccf8bea6 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ActiveLearnService.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ActiveLearnService.java @@ -2,22 +2,21 @@ package com.ruoyi.platform.service; import com.ruoyi.platform.domain.ActiveLearn; import com.ruoyi.platform.vo.ActiveLearnVo; -import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Page; import java.io.IOException; public interface ActiveLearnService { Page queryByPage(String name, PageRequest pageRequest); - ActiveLearn save(ActiveLearnVo activeLearnServiceVo); + ActiveLearn save(ActiveLearnVo activeLearnVo) throws Exception; - String edit(ActiveLearnVo activeLearnServiceVo); + String edit(ActiveLearnVo activeLearnVo) throws Exception; ActiveLearnVo getActiveLearnDetail(Long id) throws IOException; String delete(Long id); - String runActiveLearnIns(Long id) throws Exception; - + String runActiveLearnIns (Long id) throws Exception; } 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 42da3ec2..4224599d 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 @@ -4,6 +4,7 @@ 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; diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ResourceOccupyService.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ResourceOccupyService.java index 8d955cd7..5606239e 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ResourceOccupyService.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ResourceOccupyService.java @@ -22,4 +22,6 @@ public interface ResourceOccupyService { Map queryCredit(); void update(String taskType, Long taskId, Long taskInsId, Integer computingResourceId, Integer replicas); + + void deleteTaskState(String taskType, Long taskId, Long taskInsId); } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ServiceService.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ServiceService.java index cf192a93..0c779433 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ServiceService.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ServiceService.java @@ -26,9 +26,9 @@ public interface ServiceService { Service getService(Long id); - ServiceVersionVo getServiceVersion(Long id); + ServiceVersionVo getServiceVersion(Long id) throws IOException; - Map serviceVersionCompare(Long id1, Long id2) throws IllegalAccessException; + Map serviceVersionCompare(Long id1, Long id2) throws IllegalAccessException, IOException; String deleteService(Long id) throws Exception; diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ActiveLearnInsServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ActiveLearnInsServiceImpl.java index d0089e36..53f16b02 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ActiveLearnInsServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ActiveLearnInsServiceImpl.java @@ -5,50 +5,70 @@ import com.ruoyi.platform.domain.ActiveLearnIns; import com.ruoyi.platform.mapper.ActiveLearnDao; import com.ruoyi.platform.mapper.ActiveLearnInsDao; import com.ruoyi.platform.service.ActiveLearnInsService; +import com.ruoyi.platform.service.ResourceOccupyService; +import com.ruoyi.platform.utils.DateUtils; +import com.ruoyi.platform.utils.HttpUtils; +import com.ruoyi.platform.utils.JsonUtils; import com.ruoyi.system.api.constant.Constant; 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; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; +import java.util.*; -@Service("activeLearnInsService") +@Service public class ActiveLearnInsServiceImpl implements ActiveLearnInsService { + @Value("${argo.url}") + private String argoUrl; + @Value("${argo.workflowStatus}") + private String argoWorkflowStatus; + @Value("${argo.workflowTermination}") + private String argoWorkflowTermination; + @Resource private ActiveLearnInsDao activeLearnInsDao; @Resource private ActiveLearnDao activeLearnDao; + @Resource + private ResourceOccupyService resourceOccupyService; @Override - public Page queryByPage(ActiveLearnIns activeLearnIns, PageRequest pageRequest) throws IOException { - long total = this.activeLearnInsDao.count(activeLearnIns); - List activeLearnInsList = this.activeLearnInsDao.queryAllByLimit(activeLearnIns, pageRequest); + public Page queryByPage(Long activeLearnId, PageRequest pageRequest) throws IOException { + long total = this.activeLearnInsDao.count(activeLearnId); + List activeLearnInsList = activeLearnInsDao.queryAllByLimit(activeLearnId, pageRequest); return new PageImpl<>(activeLearnInsList, pageRequest, total); } @Override public ActiveLearnIns insert(ActiveLearnIns activeLearnIns) { - this.activeLearnInsDao.insert(activeLearnIns); + activeLearnInsDao.insert(activeLearnIns); return activeLearnIns; } @Override - public String removeById(Long id) { + @Transactional + public String deleteById(Long id) { ActiveLearnIns activeLearnIns = activeLearnInsDao.queryById(id); if (activeLearnIns == null) { return "实验实例不存在"; } - - //todo queryStatusFromArgo + if (StringUtils.isEmpty(activeLearnIns.getStatus())) { + activeLearnIns = queryStatusFromArgo(activeLearnIns); + } + if (StringUtils.equals(activeLearnIns.getStatus(), Constant.Running)) { + return "实验实例正在运行,不可删除"; + } activeLearnIns.setState(Constant.State_invalid); int update = activeLearnInsDao.update(activeLearnIns); if (update > 0) { + resourceOccupyService.deleteTaskState(Constant.TaskType_ActiveLearn, activeLearnIns.getActiveLearnId(), id); updateActiveLearnStatus(activeLearnIns.getActiveLearnId()); return "删除成功"; } else { @@ -59,7 +79,7 @@ public class ActiveLearnInsServiceImpl implements ActiveLearnInsService { @Override public String batchDelete(List ids) { for (Long id : ids) { - String result = removeById(id); + String result = deleteById(id); if (!"删除成功".equals(result)) { return result; } @@ -68,34 +88,93 @@ public class ActiveLearnInsServiceImpl implements ActiveLearnInsService { } @Override - public boolean terminateActiveLearnIns(Long id) { + public boolean terminateActiveLearnIns(Long id) throws Exception { ActiveLearnIns activeLearnIns = activeLearnInsDao.queryById(id); if (activeLearnIns == null) { throw new IllegalStateException("实验实例未查询到,id: " + id); } - String currentStatus = activeLearnIns.getStatus(); String name = activeLearnIns.getArgoInsName(); String namespace = activeLearnIns.getArgoInsNs(); - //todo queryStatusFromArgo + // 获取当前状态,如果为空,则从Argo查询 + if (StringUtils.isEmpty(currentStatus)) { + currentStatus = queryStatusFromArgo(activeLearnIns).getStatus(); + } + + // 只有状态是"Running"时才能终止实例 + if (!currentStatus.equalsIgnoreCase(Constant.Running)) { + throw new Exception("终止错误,只有运行状态的实例才能终止"); // 如果不是"Running"状态,则不执行终止操作 + } + + // 创建请求数据map + Map requestData = new HashMap<>(); + requestData.put("namespace", namespace); + requestData.put("name", name); + // 创建发送数据map,将请求数据作为"data"键的值 + Map res = new HashMap<>(); + res.put("data", requestData); - return false; + 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,确保状态更新被保存到数据库 + ActiveLearnIns ins = queryStatusFromArgo(activeLearnIns); + String nodeStatus = ins.getNodeStatus(); + Map nodeMap = JsonUtils.jsonToMap(nodeStatus); + + // 遍历 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(Constant.Succeeded, phaseValue)) { + innerMap.put("phase", Constant.Failed); + } + } + } + ins.setNodeStatus(JsonUtils.mapToJson(nodeMap)); + ins.setStatus(Constant.Terminated); + ins.setUpdateTime(new Date()); + activeLearnInsDao.update(ins); + updateActiveLearnStatus(ins.getActiveLearnId()); + // 结束扣积分 + resourceOccupyService.endDeduce(Constant.TaskType_ActiveLearn, null, id, null, null); + return true; + } else { + return false; + } + } catch (Exception e) { + throw new RuntimeException("终止实例错误: " + e.getMessage(), e); + } } @Override - public ActiveLearnIns getDetailById(Long id) { + public ActiveLearnIns getDetailById(Long id) throws Exception { ActiveLearnIns activeLearnIns = activeLearnInsDao.queryById(id); - if(Constant.Running.equals(activeLearnIns.getStatus()) || Constant.Pending.equals(activeLearnIns.getStatus())){ - //todo queryStatusFromArgo + if (Constant.Running.equals(activeLearnIns.getStatus()) || Constant.Pending.equals(activeLearnIns.getStatus())) { + activeLearnIns = queryStatusFromArgo(activeLearnIns); } return activeLearnIns; } + @Override public void updateActiveLearnStatus(Long activeLearnId) { List insList = activeLearnInsDao.getByActiveLearnId(activeLearnId); List statusList = new ArrayList<>(); - // 更新实验状态列表 for (int i = 0; i < insList.size(); i++) { statusList.add(insList.get(i).getStatus()); @@ -108,4 +187,77 @@ public class ActiveLearnInsServiceImpl implements ActiveLearnInsService { } } + @Override + public ActiveLearnIns queryStatusFromArgo(ActiveLearnIns 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(), Constant.Error)) { + ins.setStatus(Constant.Failed); + } + return ins; + } catch (Exception e) { + throw new RuntimeException("查询状态失败: " + e.getMessage(), e); + } + } + + @Override + public List queryActiveLearnInsIsNotTerminated() { + return activeLearnInsDao.queryActiveLearnInsIsNotTerminated(); + } } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ActiveLearnServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ActiveLearnServiceImpl.java index 665785d1..7fc562b2 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ActiveLearnServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ActiveLearnServiceImpl.java @@ -2,27 +2,54 @@ package com.ruoyi.platform.service.impl; import com.ruoyi.common.security.utils.SecurityUtils; import com.ruoyi.platform.domain.ActiveLearn; +import com.ruoyi.platform.domain.ActiveLearnIns; import com.ruoyi.platform.mapper.ActiveLearnDao; +import com.ruoyi.platform.mapper.ActiveLearnInsDao; +import com.ruoyi.platform.service.ActiveLearnInsService; import com.ruoyi.platform.service.ActiveLearnService; +import com.ruoyi.platform.service.ResourceOccupyService; +import com.ruoyi.platform.utils.HttpUtils; import com.ruoyi.platform.utils.JacksonUtil; import com.ruoyi.platform.utils.JsonUtils; +import com.ruoyi.platform.vo.ActiveLearnParamVo; import com.ruoyi.platform.vo.ActiveLearnVo; import com.ruoyi.system.api.constant.Constant; +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; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; -@Service("activeLearnService") +@Service public class ActiveLearnServiceImpl implements ActiveLearnService { + @Value("${argo.url}") + private String argoUrl; + @Value("${argo.workflowRun}") + private String argoWorkflowRun; + @Value("${argo.convertActiveLearn}") + String convertActiveLearn; + + @Resource + private ResourceOccupyService resourceOccupyService; + @Resource private ActiveLearnDao activeLearnDao; + @Resource + private ActiveLearnInsDao activeLearnInsDao; + @Resource + private ActiveLearnInsService activeLearnInsService; + @Override public Page queryByPage(String name, PageRequest pageRequest) { @@ -32,7 +59,7 @@ public class ActiveLearnServiceImpl implements ActiveLearnService { } @Override - public ActiveLearn save(ActiveLearnVo activeLearnVo) { + public ActiveLearn save(ActiveLearnVo activeLearnVo) throws Exception { ActiveLearn activeLearnByName = activeLearnDao.getActiveLearnByName(activeLearnVo.getName()); if (activeLearnByName != null) { throw new RuntimeException("实验名称已存在"); @@ -42,33 +69,28 @@ public class ActiveLearnServiceImpl implements ActiveLearnService { String username = SecurityUtils.getLoginUser().getUsername(); activeLearn.setCreateBy(username); activeLearn.setUpdateBy(username); - - activeLearn.setImage(JacksonUtil.toJSONString(activeLearnVo.getImage())); - activeLearn.setModel(JacksonUtil.toJSONString(activeLearnVo.getModel())); activeLearn.setDataset(JacksonUtil.toJSONString(activeLearnVo.getDataset())); - + activeLearn.setCodeConfig(JacksonUtil.toJSONString(activeLearnVo.getCodeConfig())); + activeLearn.setModel(JacksonUtil.toJSONString(activeLearnVo.getModel())); + activeLearn.setImage(JacksonUtil.toJSONString(activeLearnVo.getImage())); activeLearnDao.save(activeLearn); return activeLearn; } @Override - public String edit(ActiveLearnVo activeLearnVo) { - ActiveLearn activeLearnByName = activeLearnDao.getActiveLearnByName(activeLearnVo.getName()); - if (activeLearnByName != null && !activeLearnByName.getId().equals(activeLearnVo.getId())) { + public String edit(ActiveLearnVo activeLearnVo) throws Exception { + ActiveLearn oldActiveLearn = activeLearnDao.getActiveLearnByName(activeLearnVo.getName()); + if (oldActiveLearn != null && !oldActiveLearn.getId().equals(activeLearnVo.getId())) { throw new RuntimeException("实验名称已存在"); } - ActiveLearn activeLearn = new ActiveLearn(); BeanUtils.copyProperties(activeLearnVo, activeLearn); - String username = SecurityUtils.getLoginUser().getUsername(); - activeLearn.setUpdateBy(username); - - activeLearn.setImage(JacksonUtil.toJSONString(activeLearnVo.getImage())); - activeLearn.setModel(JacksonUtil.toJSONString(activeLearnVo.getModel())); + activeLearn.setUpdateBy(SecurityUtils.getLoginUser().getUsername()); activeLearn.setDataset(JacksonUtil.toJSONString(activeLearnVo.getDataset())); - + activeLearn.setCodeConfig(JacksonUtil.toJSONString(activeLearnVo.getCodeConfig())); + activeLearn.setModel(JacksonUtil.toJSONString(activeLearnVo.getModel())); + activeLearn.setImage(JacksonUtil.toJSONString(activeLearnVo.getImage())); activeLearnDao.edit(activeLearn); - return "修改成功"; } @@ -77,15 +99,15 @@ public class ActiveLearnServiceImpl implements ActiveLearnService { ActiveLearn activeLearn = activeLearnDao.getActiveLearnById(id); ActiveLearnVo activeLearnVo = new ActiveLearnVo(); BeanUtils.copyProperties(activeLearn, activeLearnVo); - if (StringUtils.isNotEmpty(activeLearn.getDatasetPy())) { + if (StringUtils.isNotEmpty(activeLearn.getDataset())) { activeLearnVo.setDataset(JsonUtils.jsonToMap(activeLearn.getDataset())); } + if (StringUtils.isNotEmpty(activeLearn.getCodeConfig())) { + activeLearnVo.setCodeConfig(JsonUtils.jsonToMap(activeLearn.getCodeConfig())); + } if (StringUtils.isNotEmpty(activeLearn.getModel())) { activeLearnVo.setModel(JsonUtils.jsonToMap(activeLearn.getModel())); } - if (StringUtils.isNotEmpty(activeLearn.getDataset())) { - activeLearnVo.setDataset(JsonUtils.jsonToMap(activeLearn.getDataset())); - } if (StringUtils.isNotEmpty(activeLearn.getImage())) { activeLearnVo.setImage(JsonUtils.jsonToMap(activeLearn.getImage())); } @@ -93,6 +115,7 @@ public class ActiveLearnServiceImpl implements ActiveLearnService { } @Override + @Transactional public String delete(Long id) { ActiveLearn activeLearn = activeLearnDao.getActiveLearnById(id); if (activeLearn == null) { @@ -104,6 +127,7 @@ public class ActiveLearnServiceImpl implements ActiveLearnService { throw new RuntimeException("无权限删除该实验"); } activeLearn.setState(Constant.State_invalid); + resourceOccupyService.deleteTaskState(Constant.TaskType_ActiveLearn, id, null); return activeLearnDao.edit(activeLearn) > 0 ? "删除成功" : "删除失败"; } @@ -114,16 +138,64 @@ public class ActiveLearnServiceImpl implements ActiveLearnService { throw new Exception("主动学习配置不存在"); } - ActiveLearnVo activeLearnParam = new ActiveLearnVo(); - BeanUtils.copyProperties(activeLearn, activeLearnParam); - activeLearnParam.setDataset(JsonUtils.jsonToMap(activeLearn.getDataset())); - activeLearnParam.setImage(JsonUtils.jsonToMap(activeLearn.getImage())); - activeLearnParam.setModel(JsonUtils.jsonToMap(activeLearn.getModel())); - - String param = JsonUtils.objectToJson(activeLearnParam); - - // todo 调argo转换接口 - + // 记录开始扣积分 + if (resourceOccupyService.haveResource(activeLearn.getComputingResourceId(), 1)) { + ActiveLearnParamVo activeLearnParamVo = new ActiveLearnParamVo(); + BeanUtils.copyProperties(activeLearn, activeLearnParamVo); + activeLearnParamVo.setCodeConfig(JsonUtils.jsonToMap(activeLearn.getCodeConfig())); + activeLearnParamVo.setDataset(JsonUtils.jsonToMap(activeLearn.getDataset())); + activeLearnParamVo.setModel(JsonUtils.jsonToMap(activeLearn.getModel())); + activeLearnParamVo.setImage(JsonUtils.jsonToMap(activeLearn.getImage())); + String param = JsonUtils.objectToJson(activeLearnParamVo); + + // 调argo转换接口 + try { + String convertRes = HttpUtils.sendPost(argoUrl + convertActiveLearn, 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("运行失败"); + } + Map runResMap = JsonUtils.jsonToMap(runRes); + Map data = (Map) runResMap.get("data"); + //判断data为空 + if (data == null || MapUtils.isEmpty(data)) { + throw new RuntimeException("运行失败"); + } + Map metadata = (Map) data.get("metadata"); + + // 插入记录到实验实例表 + ActiveLearnIns activeLearnIns = new ActiveLearnIns(); + activeLearnIns.setActiveLearnId(id); + activeLearnIns.setArgoInsNs((String) metadata.get("namespace")); + activeLearnIns.setArgoInsName((String) metadata.get("name")); + activeLearnIns.setParam(param); + activeLearnIns.setStatus(Constant.Pending); + //替换argoInsName + String outputString = JsonUtils.mapToJson(output); + activeLearnIns.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 = output2.get("path").replace("{{workflow.name}}", (String) metadata.get("name")) + "/hpo"; + activeLearnIns.setResultPath(outputPath); + activeLearnInsDao.insert(activeLearnIns); + activeLearnInsService.updateActiveLearnStatus(id); + // 记录开始扣除积分 + resourceOccupyService.startDeduce(activeLearn.getComputingResourceId(), 1, Constant.TaskType_ActiveLearn, id, activeLearnIns.getId(), null, activeLearn.getName(), null, null); + } catch (Exception e) { + throw new RuntimeException(e); + } + } return "执行成功"; } } 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 8e32e5e7..2f122a81 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 @@ -146,7 +146,7 @@ public class AutoMlInsServiceImpl implements AutoMlInsService { 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")) { + if (StringUtils.equals(ins.getStatus(), Constant.Error)) { ins.setStatus(Constant.Failed); } return ins; diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/CodeConfigServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/CodeConfigServiceImpl.java index ac59c83a..8c4f02f3 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/CodeConfigServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/CodeConfigServiceImpl.java @@ -3,21 +3,18 @@ package com.ruoyi.platform.service.impl; import com.alibaba.fastjson2.JSON; import com.ruoyi.common.security.utils.SecurityUtils; import com.ruoyi.platform.domain.ActiveLearn; +import com.ruoyi.platform.mapper.*; +import com.ruoyi.system.api.constant.Constant; import com.ruoyi.platform.domain.AssetWorkflow; import com.ruoyi.platform.domain.CodeConfig; -import com.ruoyi.platform.domain.Ray; -import com.ruoyi.platform.mapper.ActiveLearnDao; -import com.ruoyi.platform.mapper.AssetWorkflowDao; -import com.ruoyi.platform.mapper.CodeConfigDao; -import com.ruoyi.platform.mapper.RayDao; import com.ruoyi.platform.service.CodeConfigService; -import com.ruoyi.system.api.constant.Constant; import com.ruoyi.system.api.model.LoginUser; 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 com.ruoyi.platform.domain.Ray; import javax.annotation.Resource; import java.util.Date; @@ -36,6 +33,8 @@ public class CodeConfigServiceImpl implements CodeConfigService { private RayDao rayDao; @Resource private ActiveLearnDao activeLearnDao; + @Resource + private ServiceDao serviceDao; @Override public Page queryByPage(CodeConfig codeConfig, PageRequest pageRequest) { @@ -112,6 +111,12 @@ public class CodeConfigServiceImpl implements CodeConfigService { throw new Exception("该代码配置被主动学习:" + activeLearns + "使用,不能删除,请先删除主动学习。"); } + List serviceVersionList = serviceDao.queryByCodeConfig(JSON.toJSONString(map)); + if (serviceVersionList != null && !serviceVersionList.isEmpty()) { + String serviceVersions = String.join(",", serviceVersionList.stream().collect(Collectors.toSet())); + throw new Exception("该代码配置被服务版本:" + serviceVersions + "使用,不能删除,请先删除服务版本。"); + } + LoginUser loginUser = SecurityUtils.getLoginUser(); String username = loginUser.getUsername(); String createBy = codeConfig.getCreateBy(); diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/DevEnvironmentServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/DevEnvironmentServiceImpl.java index eba5a138..f00a8ca4 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/DevEnvironmentServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/DevEnvironmentServiceImpl.java @@ -6,9 +6,11 @@ import com.ruoyi.platform.domain.PodStatus; import com.ruoyi.platform.mapper.DevEnvironmentDao; import com.ruoyi.platform.service.DevEnvironmentService; import com.ruoyi.platform.service.JupyterService; +import com.ruoyi.platform.service.ResourceOccupyService; import com.ruoyi.platform.utils.JacksonUtil; import com.ruoyi.platform.vo.DevEnvironmentVo; import com.ruoyi.platform.vo.PodStatusVo; +import com.ruoyi.system.api.constant.Constant; import com.ruoyi.system.api.model.LoginUser; import org.apache.commons.lang3.StringUtils; import org.springframework.context.annotation.Lazy; @@ -16,6 +18,7 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.Date; @@ -35,6 +38,8 @@ public class DevEnvironmentServiceImpl implements DevEnvironmentService { @Resource @Lazy private JupyterService jupyterService; + @Resource + private ResourceOccupyService resourceOccupyService; /** * 通过ID查询单条数据 @@ -94,22 +99,19 @@ public class DevEnvironmentServiceImpl implements DevEnvironmentService { LoginUser loginUser = SecurityUtils.getLoginUser(); devEnvironment.setName(devEnvironmentVo.getName()); //状态先设为未知 - devEnvironment.setStatus("Unknown"); + devEnvironment.setStatus(Constant.Unknown); devEnvironment.setComputingResource(devEnvironmentVo.getComputingResource()); devEnvironment.setComputingResourceId(devEnvironmentVo.getComputingResourceId()); devEnvironment.setStandard(devEnvironmentVo.getStandard()); devEnvironment.setEnvVariable(devEnvironmentVo.getEnvVariable()); - devEnvironment.setImage(devEnvironmentVo.getImage()); - // 将 dataset 和 model 转换成 JSON 字符串 - String datasetJson = JacksonUtil.toJSONString(devEnvironmentVo.getDataset()); - String modelJson = JacksonUtil.toJSONString(devEnvironmentVo.getModel()); - devEnvironment.setDataset(datasetJson); - devEnvironment.setModel(modelJson); + devEnvironment.setImage(JacksonUtil.toJSONString(devEnvironmentVo.getImage())); + devEnvironment.setDataset(JacksonUtil.toJSONString(devEnvironmentVo.getDataset())); + devEnvironment.setModel(JacksonUtil.toJSONString(devEnvironmentVo.getModel())); devEnvironment.setCreateBy(loginUser.getUsername()); devEnvironment.setUpdateBy(loginUser.getUsername()); devEnvironment.setUpdateTime(new Date()); devEnvironment.setCreateTime(new Date()); - devEnvironment.setState(1); + devEnvironment.setState(Constant.State_valid); this.devEnvironmentDao.insert(devEnvironment); return devEnvironment; } @@ -140,6 +142,7 @@ public class DevEnvironmentServiceImpl implements DevEnvironmentService { } @Override + @Transactional public String removeById(Integer id) throws Exception { DevEnvironment devEnvironment = this.devEnvironmentDao.queryById(id); if (devEnvironment == null) { @@ -155,9 +158,8 @@ public class DevEnvironmentServiceImpl implements DevEnvironmentService { } jupyterService.stopJupyterService(id); - devEnvironment.setState(0); + devEnvironment.setState(Constant.State_invalid); + resourceOccupyService.deleteTaskState(Constant.TaskType_Dev, Long.valueOf(id), null); return this.devEnvironmentDao.update(devEnvironment) > 0 ? "删除成功" : "删除失败"; } - - } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ExperimentInsServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ExperimentInsServiceImpl.java index b0cf550c..88868fa0 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ExperimentInsServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ExperimentInsServiceImpl.java @@ -2,7 +2,6 @@ package com.ruoyi.platform.service.impl; import com.alibaba.fastjson2.JSON; import com.ruoyi.common.security.utils.SecurityUtils; -import com.ruoyi.system.api.constant.Constant; import com.ruoyi.platform.domain.DatasetTempStorage; import com.ruoyi.platform.domain.Experiment; import com.ruoyi.platform.domain.ExperimentIns; @@ -16,6 +15,7 @@ import com.ruoyi.platform.service.ResourceOccupyService; import com.ruoyi.platform.utils.*; import com.ruoyi.platform.vo.LogRequestVo; import com.ruoyi.platform.vo.PodLogVo; +import com.ruoyi.system.api.constant.Constant; import com.ruoyi.system.api.model.LoginUser; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Value; @@ -23,6 +23,7 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.io.IOException; @@ -204,6 +205,7 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { } @Override + @Transactional public String removeById(Integer id) { ExperimentIns experimentIns = experimentInsDao.queryById(id); if (experimentIns == null) { @@ -227,6 +229,7 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { experimentIns.setState(0); int update = this.experimentInsDao.update(experimentIns); if (update > 0) { + resourceOccupyService.deleteTaskState(Constant.TaskType_Workflow, Long.valueOf(experimentIns.getExperimentId()), Long.valueOf(id)); updateExperimentStatus(experimentIns.getExperimentId()); return "删除成功"; } else { @@ -323,7 +326,7 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { if (!StringUtils.equals(experimentIns.getStatus(), "Terminated")) { experimentIns.setStatus(StringUtils.isNotEmpty((String) status.get("phase")) ? (String) status.get("phase") : "Pending"); } - if (StringUtils.equals(experimentIns.getStatus(), "Error")) { + if (StringUtils.equals(experimentIns.getStatus(), Constant.Error)) { experimentIns.setStatus("Failed"); } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ExperimentServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ExperimentServiceImpl.java index 78e5c545..0a6b2bc7 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ExperimentServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ExperimentServiceImpl.java @@ -28,6 +28,7 @@ import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.io.IOException; @@ -184,6 +185,7 @@ public class ExperimentServiceImpl implements ExperimentService { } @Override + @Transactional public String removeById(Integer id) throws Exception { Experiment experiment = experimentDao.queryById(id); if (experiment == null) { @@ -202,7 +204,8 @@ public class ExperimentServiceImpl implements ExperimentService { if (experimentInsList != null && experimentInsList.size() > 0) { throw new Exception("该实验存在实例,无法删除"); } - experiment.setState(0); + resourceOccupyService.deleteTaskState(Constant.TaskType_Workflow, Long.valueOf(id), null); + experiment.setState(Constant.State_invalid); return this.experimentDao.update(experiment) > 0 ? "删除成功" : "删除失败"; diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ImageServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ImageServiceImpl.java index ad885862..f56d78cc 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ImageServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ImageServiceImpl.java @@ -6,13 +6,12 @@ import com.ruoyi.common.core.web.domain.GenericsAjaxResult; import com.ruoyi.common.security.utils.SecurityUtils; import com.ruoyi.platform.domain.*; import com.ruoyi.platform.mapper.*; -import com.ruoyi.platform.domain.*; -import com.ruoyi.platform.mapper.*; import com.ruoyi.platform.service.ImageService; import com.ruoyi.platform.service.ImageVersionService; import com.ruoyi.platform.service.MinioService; import com.ruoyi.platform.utils.DockerClientUtil; import com.ruoyi.platform.utils.FileUtil; +import com.ruoyi.platform.utils.JacksonUtil; import com.ruoyi.platform.utils.K8sClientUtil; import com.ruoyi.platform.vo.ImageVo; import com.ruoyi.system.api.constant.Constant; @@ -59,7 +58,8 @@ public class ImageServiceImpl implements ImageService { private ActiveLearnDao activeLearnDao; @Resource private ImageVersionService imageVersionService; - + @Resource + private ServiceDao serviceDao; @Resource private K8sClientUtil k8sClientUtil; @Resource @@ -194,6 +194,18 @@ public class ImageServiceImpl implements ImageService { throw new Exception("该镜像被主动学习:" + activeLearns + "使用,不能删除,请先删除主动学习。"); } + List devEnvironmentList = devEnvironmentDao.queryByImageId(JSON.toJSONString(map)); + if (devEnvironmentList != null && !devEnvironmentList.isEmpty()) { + String devEnvironments = String.join(",", devEnvironmentList.stream().map(DevEnvironment::getName).collect(Collectors.toSet())); + throw new Exception("该镜像被开发环境:" + devEnvironments + "使用,不能删除,请先删除开发环境。"); + } + + List serviceVersionList = serviceDao.queryByImageId(JSON.toJSONString(map)); + if (serviceVersionList != null && !serviceVersionList.isEmpty()) { + String serviceVersions = String.join(",", serviceVersionList.stream().collect(Collectors.toSet())); + throw new Exception("该镜像被服务版本:" + serviceVersions + "使用,不能删除,请先删除服务版本。"); + } + //判断权限,只有admin和创建者本身可以删除该数据集 LoginUser loginUser = SecurityUtils.getLoginUser(); String username = loginUser.getUsername(); @@ -445,13 +457,22 @@ public class ImageServiceImpl implements ImageService { imageVersion.setUpdateTime(new Date()); imageVersion.setCreateTime(new Date()); imageVersion.setState(Constant.State_valid); - imageVersion.setStatus("available"); + imageVersion.setStatus(Constant.Available); imageVersionDao.insert(imageVersion); //更新dev环境的镜像信息 DevEnvironment devEnvironment = new DevEnvironment(); devEnvironment.setId(imageVo.getDevEnvironmentId()); - devEnvironment.setImage(resultMap.get("imageName")); + + + imageVo.setValue(resultMap.get("imageName")); + imageVo.setVersion(String.valueOf(imageVersion.getId())); + + resultMap.put("id", String.valueOf(oldImage.getId())); + resultMap.put("version", String.valueOf(imageVersion.getId())); + resultMap.put("value",resultMap.get("imageName")); + + devEnvironment.setImage(JacksonUtil.toJSONString(resultMap)); devEnvironmentDao.update(devEnvironment); } catch (Exception e) { throw new RuntimeException("保存镜像失败:" + e); diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ImageVersionServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ImageVersionServiceImpl.java index efdaa157..2f35c63d 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ImageVersionServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ImageVersionServiceImpl.java @@ -9,10 +9,10 @@ import com.ruoyi.platform.service.ImageVersionService; import com.ruoyi.system.api.constant.Constant; import com.ruoyi.system.api.model.LoginUser; import org.apache.commons.lang3.StringUtils; -import org.springframework.stereotype.Service; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; +import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.Date; @@ -36,6 +36,10 @@ public class ImageVersionServiceImpl implements ImageVersionService { private RayDao rayDao; @Resource private ActiveLearnDao activeLearnDao; + @Resource + private DevEnvironmentDao devEnvironmentDao; + @Resource + private ServiceDao serviceDao; /** * 通过ID查询单条数据 * @@ -79,18 +83,36 @@ public class ImageVersionServiceImpl implements ImageVersionService { return GenericsAjaxResult.error("该版本下模型文件信息不存在"); } + List assetWorkflow = assetWorkflowDao.getAssetWorkflow(Long.valueOf(imageVersion.getImageId()), Constant.Asset_Type_Image, imageVersion.getTagName()); + if (assetWorkflow != null && !assetWorkflow.isEmpty()) { + String workflows = String.join(",", assetWorkflow.stream().map(AssetWorkflow::getWorkflowName).collect(Collectors.toSet())); + return GenericsAjaxResult.error("该镜像版本被流水线:" + workflows + "使用,不能删除,请先删除流水线。"); + } + HashMap map = new HashMap<>(); map.put("version", String.valueOf(id)); List rayList = rayDao.queryByImageId(JSON.toJSONString(map)); if (rayList != null && !rayList.isEmpty()) { String rays = String.join(",", rayList.stream().map(Ray::getName).collect(Collectors.toSet())); - throw new Exception("该镜像版本被超参数自动寻优:" + rays + "使用,不能删除,请先删除超参数自动寻优。"); + return GenericsAjaxResult.error("该镜像版本被超参数自动寻优:" + rays + "使用,不能删除,请先删除超参数自动寻优。"); } List activeLearnList = activeLearnDao.queryByImageId(JSON.toJSONString(map)); if (activeLearnList != null && !activeLearnList.isEmpty()) { String activeLearns = String.join(",", activeLearnList.stream().map(ActiveLearn::getName).collect(Collectors.toSet())); - throw new Exception("该镜像版本被主动学习:" + activeLearns + "使用,不能删除,请先删除主动学习。"); + return GenericsAjaxResult.error("该镜像版本被主动学习:" + activeLearns + "使用,不能删除,请先删除主动学习。"); + } + + List devEnvironmentList = devEnvironmentDao.queryByImageId(JSON.toJSONString(map)); + if (devEnvironmentList != null && !devEnvironmentList.isEmpty()) { + String devEnvironments = String.join(",", devEnvironmentList.stream().map(DevEnvironment::getName).collect(Collectors.toSet())); + throw new Exception("该镜像版本被开发环境:" + devEnvironments + "使用,不能删除,请先删除开发环境。"); + } + + List serviceVersionList = serviceDao.queryByImageId(JSON.toJSONString(map)); + if (serviceVersionList != null && !serviceVersionList.isEmpty()) { + String serviceVersions = String.join(",", serviceVersionList.stream().collect(Collectors.toSet())); + throw new Exception("该镜像版本被服务版本:" + serviceVersions + "使用,不能删除,请先删除服务版本。"); } //判断权限,只有admin和创建者本身可以删除该数据集 diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ModelsServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ModelsServiceImpl.java index cf31aeea..c6c9ae0e 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ModelsServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ModelsServiceImpl.java @@ -67,10 +67,13 @@ public class ModelsServiceImpl implements ModelsService { @Resource private RayDao rayDao; @Resource + private ModelsVersionService modelsVersionService; + @Resource private ActiveLearnDao activeLearnDao; @Resource - private ModelsVersionService modelsVersionService; - + private DevEnvironmentDao devEnvironmentDao; + @Resource + private ServiceDao serviceDao; @Resource private ModelDependency1Dao modelDependency1Dao; @@ -1169,6 +1172,24 @@ public class ModelsServiceImpl implements ModelsService { throw new Exception("该模型被超参数自动寻优:" + rays + "使用,不能删除,请先删除超参数自动寻优。"); } + List activeLearnList = activeLearnDao.queryByModelId(JSON.toJSONString(queryMap)); + if (activeLearnList != null && !activeLearnList.isEmpty()) { + String activeLearns = String.join(",", activeLearnList.stream().map(ActiveLearn::getName).collect(Collectors.toSet())); + throw new Exception("该模型被主动学习:" + activeLearns + "使用,不能删除,请先删除主动学习。"); + } + + List devEnvironmentList = devEnvironmentDao.queryByModelId(JSON.toJSONString(queryMap)); + if (devEnvironmentList != null && !devEnvironmentList.isEmpty()) { + String devEnvironments = String.join(",", devEnvironmentList.stream().map(DevEnvironment::getName).collect(Collectors.toSet())); + throw new Exception("该模型被开发环境:" + devEnvironments + "使用,不能删除,请先删除开发环境。"); + } + + List serviceVersionList = serviceDao.queryByModelId(JSON.toJSONString(queryMap)); + if (serviceVersionList != null && !serviceVersionList.isEmpty()) { + String serviceVersions = String.join(",", serviceVersionList.stream().collect(Collectors.toSet())); + throw new Exception("该模型被服务版本:" + serviceVersions + "使用,不能删除,请先删除服务版本。"); + } + String token = gitService.checkoutToken(); gitService.deleteProject(token, owner, identifier); //删除模型依赖 @@ -1198,7 +1219,25 @@ public class ModelsServiceImpl implements ModelsService { List rayList = rayDao.queryByModelId(JSON.toJSONString(queryMap)); if (rayList != null && !rayList.isEmpty()) { String rays = String.join(",", rayList.stream().map(Ray::getName).collect(Collectors.toSet())); - throw new Exception("该数据集版本被超参数自动寻优:" + rays + "使用,不能删除,请先删除超参数自动寻优。"); + throw new Exception("该模型版本被超参数自动寻优:" + rays + "使用,不能删除,请先删除超参数自动寻优。"); + } + + List activeLearnList = activeLearnDao.queryByModelId(JSON.toJSONString(queryMap)); + if (activeLearnList != null && !activeLearnList.isEmpty()) { + String activeLearns = String.join(",", activeLearnList.stream().map(ActiveLearn::getName).collect(Collectors.toSet())); + throw new Exception("该模型版本被主动学习:" + activeLearns + "使用,不能删除,请先删除主动学习。"); + } + + List devEnvironmentList = devEnvironmentDao.queryByModelId(JSON.toJSONString(queryMap)); + if (devEnvironmentList != null && !devEnvironmentList.isEmpty()) { + String devEnvironments = String.join(",", devEnvironmentList.stream().map(DevEnvironment::getName).collect(Collectors.toSet())); + throw new Exception("该模型版本被开发环境:" + devEnvironments + "使用,不能删除,请先删除开发环境。"); + } + + List serviceVersionList = serviceDao.queryByModelId(JSON.toJSONString(queryMap)); + if (serviceVersionList != null && !serviceVersionList.isEmpty()) { + String serviceVersions = String.join(",", serviceVersionList.stream().collect(Collectors.toSet())); + throw new Exception("该模型版本被服务版本:" + serviceVersions + "使用,不能删除,请先删除服务版本。"); } String token = gitService.checkoutToken(); diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java index 72124423..80b4a986 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java @@ -4,10 +4,7 @@ import com.alibaba.fastjson2.JSON; import com.ruoyi.common.core.utils.DateUtils; import com.ruoyi.common.security.utils.SecurityUtils; import com.ruoyi.platform.domain.*; -import com.ruoyi.platform.mapper.ActiveLearnDao; -import com.ruoyi.platform.mapper.AssetWorkflowDao; -import com.ruoyi.platform.mapper.AutoMlDao; -import com.ruoyi.platform.mapper.RayDao; +import com.ruoyi.platform.mapper.*; import com.ruoyi.platform.service.DatasetTempStorageService; import com.ruoyi.platform.service.GitService; import com.ruoyi.platform.service.NewDatasetService; @@ -59,6 +56,8 @@ public class NewDatasetServiceImpl implements NewDatasetService { private RayDao rayDao; @Resource private ActiveLearnDao activeLearnDao; + @Resource + private DevEnvironmentDao devEnvironmentDao; @Value("${spring.redis.host}") private String redisHost; @@ -439,6 +438,12 @@ public class NewDatasetServiceImpl implements NewDatasetService { throw new Exception("该数据集被主动学习:" + activeLearns + "使用,不能删除,请先删除主动学习。"); } + List devEnvironmentList = devEnvironmentDao.queryByDatasetId(JSON.toJSONString(map)); + if (devEnvironmentList != null && !devEnvironmentList.isEmpty()) { + String devEnvironments = String.join(",", devEnvironmentList.stream().map(DevEnvironment::getName).collect(Collectors.toSet())); + throw new Exception("该数据集被开发环境:" + devEnvironments + "使用,不能删除,请先删除开发环境。"); + } + String token = gitService.checkoutToken(); gitService.deleteProject(token, owner, repo); @@ -476,6 +481,12 @@ public class NewDatasetServiceImpl implements NewDatasetService { throw new Exception("该数据集版本被主动学习:" + activeLearns + "使用,不能删除,请先删除主动学习。"); } + List devEnvironmentList = devEnvironmentDao.queryByDatasetId(JSON.toJSONString(map)); + if (devEnvironmentList != null && !devEnvironmentList.isEmpty()) { + String devEnvironments = String.join(",", devEnvironmentList.stream().map(DevEnvironment::getName).collect(Collectors.toSet())); + throw new Exception("该数据集版本被开发环境:" + devEnvironments + "使用,不能删除,请先删除开发环境。"); + } + String token = gitService.checkoutToken(); String rootPath = Paths.get(localPathlocal + "/" + relativePath).getParent().toString(); gitService.deleteBranch(token, owner, repo, version, rootPath); 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 9f3ec88d..0b70d992 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 @@ -1,6 +1,5 @@ package com.ruoyi.platform.service.impl; -import com.ruoyi.system.api.constant.Constant; import com.ruoyi.platform.domain.Ray; import com.ruoyi.platform.domain.RayIns; import com.ruoyi.platform.mapper.RayDao; @@ -8,6 +7,7 @@ import com.ruoyi.platform.mapper.RayInsDao; import com.ruoyi.platform.service.RayInsService; import com.ruoyi.platform.service.ResourceOccupyService; import com.ruoyi.platform.utils.*; +import com.ruoyi.system.api.constant.Constant; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -16,6 +16,7 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.io.IOException; @@ -69,6 +70,7 @@ public class RayInsServiceImpl implements RayInsService { } @Override + @Transactional public String deleteById(Long id) { RayIns rayIns = rayInsDao.queryById(id); if (rayIns == null) { @@ -84,6 +86,7 @@ public class RayInsServiceImpl implements RayInsService { rayIns.setState(Constant.State_invalid); int update = rayInsDao.update(rayIns); if (update > 0) { + resourceOccupyService.deleteTaskState(Constant.TaskType_Ray, rayIns.getRayId(), id); updateRayStatus(rayIns.getRayId()); return "删除成功"; } else { @@ -264,7 +267,7 @@ public class RayInsServiceImpl implements RayInsService { 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")) { + if (StringUtils.equals(ins.getStatus(), Constant.Error)) { ins.setStatus(Constant.Failed); } return ins; 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 8f4643ed..8a0df23c 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 @@ -3,7 +3,6 @@ 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.system.api.constant.Constant; import com.ruoyi.platform.domain.Ray; import com.ruoyi.platform.domain.RayIns; import com.ruoyi.platform.mapper.RayDao; @@ -16,6 +15,7 @@ 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 com.ruoyi.system.api.constant.Constant; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; @@ -24,6 +24,7 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.io.IOException; @@ -131,6 +132,7 @@ public class RayServiceImpl implements RayService { } @Override + @Transactional public String delete(Long id) { Ray ray = rayDao.getRayById(id); if (ray == null) { @@ -142,6 +144,7 @@ public class RayServiceImpl implements RayService { throw new RuntimeException("无权限删除该实验"); } ray.setState(Constant.State_invalid); + resourceOccupyService.deleteTaskState(Constant.TaskType_Ray, id, null); return rayDao.edit(ray) > 0 ? "删除成功" : "删除失败"; } @@ -156,7 +159,6 @@ public class RayServiceImpl implements RayService { if (resourceOccupyService.haveResource(ray.getComputingResourceId(), 1)) { RayParamVo rayParamVo = new RayParamVo(); BeanUtils.copyProperties(ray, rayParamVo); - rayParamVo.setComputingResourceId(ray.getComputingResourceId()); rayParamVo.setCodeConfig(JsonUtils.jsonToMap(ray.getCodeConfig())); rayParamVo.setDataset(JsonUtils.jsonToMap(ray.getDataset())); rayParamVo.setModel(JsonUtils.jsonToMap(ray.getModel())); @@ -189,7 +191,7 @@ public class RayServiceImpl implements RayService { // 插入记录到实验实例表 RayIns rayIns = new RayIns(); - rayIns.setRayId(ray.getId()); + rayIns.setRayId(id); rayIns.setArgoInsNs((String) metadata.get("namespace")); rayIns.setArgoInsName((String) metadata.get("name")); rayIns.setParam(param); diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ResourceOccupyServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ResourceOccupyServiceImpl.java index 48373b2a..3b63eb43 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ResourceOccupyServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ResourceOccupyServiceImpl.java @@ -168,4 +168,9 @@ public class ResourceOccupyServiceImpl implements ResourceOccupyService { resourceOccupy.setComputingResourceId(computingResourceId); resourceOccupyDao.edit(resourceOccupy); } + + @Override + public void deleteTaskState(String taskType, Long taskId, Long taskInsId) { + resourceOccupyDao.deleteTaskState(taskType,taskId,taskInsId); + } } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ServiceServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ServiceServiceImpl.java index 41b2704c..c48ed069 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ServiceServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ServiceServiceImpl.java @@ -14,6 +14,7 @@ import com.ruoyi.platform.service.ServiceService; import com.ruoyi.platform.utils.ConvertUtil; import com.ruoyi.platform.utils.HttpUtils; import com.ruoyi.platform.utils.JacksonUtil; +import com.ruoyi.platform.utils.JsonUtils; import com.ruoyi.platform.vo.serviceVos.ServiceCodeConfigVo; import com.ruoyi.platform.vo.serviceVos.ServiceModelVo; import com.ruoyi.platform.vo.serviceVos.ServiceVersionVo; @@ -26,8 +27,10 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; @@ -64,7 +67,7 @@ public class ServiceServiceImpl implements ServiceService { } @Override - public Page queryByPageServiceVersion(ServiceVersion serviceVersion, int page, int size) { + public Page queryByPageServiceVersion(ServiceVersion serviceVersion, int page, int size) throws IOException { PageRequest pageRequest; if (StringUtils.isNotEmpty(serviceVersion.getRunState())) { pageRequest = PageRequest.of(page, Integer.MAX_VALUE); @@ -169,7 +172,7 @@ public class ServiceServiceImpl implements ServiceService { } @Override - public ServiceVersionVo getServiceVersion(Long id) { + public ServiceVersionVo getServiceVersion(Long id) throws IOException { ServiceVersion serviceVersion = serviceDao.getServiceVersionById(id); ServiceVersionVo serviceVersionVo = getServiceVersionVo(serviceVersion); com.ruoyi.platform.domain.Service service = serviceDao.getServiceById(serviceVersion.getServiceId()); @@ -195,7 +198,7 @@ public class ServiceServiceImpl implements ServiceService { } @Override - public Map serviceVersionCompare(Long id1, Long id2) throws IllegalAccessException { + public Map serviceVersionCompare(Long id1, Long id2) throws IllegalAccessException, IOException { HashMap result = new HashMap<>(); ServiceVersion serviceVersion1 = serviceDao.getServiceVersionById(id1); @@ -243,11 +246,13 @@ public class ServiceServiceImpl implements ServiceService { throw new RuntimeException("该服务下还有版本,不能删除"); } + resourceOccupyService.deleteTaskState(Constant.TaskType_Service, id, null); service.setState(Constant.State_invalid); return serviceDao.updateService(service) > 0 ? "删除成功" : "删除失败"; } @Override + @Transactional public String deleteServiceVersion(Long id) { ServiceVersion serviceVersion = serviceDao.getServiceVersionById(id); serviceVersion.setState(Constant.State_invalid); @@ -260,6 +265,7 @@ public class ServiceServiceImpl implements ServiceService { // if ((Integer) reqMap.get("code") == 200) { // 结束扣积分 resourceOccupyService.endDeduce(Constant.TaskType_Service, null, id, null, null); + resourceOccupyService.deleteTaskState(Constant.TaskType_Service, serviceVersion.getServiceId(), id); return serviceDao.updateServiceVersion(serviceVersion) > 0 ? "删除成功" : "删除失败"; // } } @@ -278,7 +284,8 @@ public class ServiceServiceImpl implements ServiceService { paramMap.put("replicas", serviceVersion.getReplicas()); paramMap.put("env", JSONObject.parseObject(serviceVersion.getEnvVariables())); paramMap.put("code_config", JSONObject.parseObject(serviceVersion.getCodeConfig())); - paramMap.put("image", serviceVersion.getImage()); + String image = (String)JsonUtils.jsonToMap(serviceVersion.getImage()).get("value"); + paramMap.put("image", image); paramMap.put("model", JSONObject.parseObject(serviceVersion.getModel())); paramMap.put("service_type", service.getServiceType()); paramMap.put("deploy_type", serviceVersion.getDeployType()); @@ -401,11 +408,12 @@ public class ServiceServiceImpl implements ServiceService { serviceVersion.setModel(JSON.toJSONString(serviceVersionVo.getModel())); serviceVersion.setCodeConfig(JSON.toJSONString(serviceVersionVo.getCodeConfig())); serviceVersion.setEnvVariables(JSON.toJSONString(serviceVersionVo.getEnvVariables())); + serviceVersion.setImage(JacksonUtil.toJSONString(serviceVersionVo.getImage())); return serviceVersion; } - List getServiceVersionVoList(List serviceVersionList) { + List getServiceVersionVoList(List serviceVersionList) throws IOException { List result = new ArrayList<>(); for (ServiceVersion sv : serviceVersionList) { @@ -415,7 +423,7 @@ public class ServiceServiceImpl implements ServiceService { return result; } - ServiceVersionVo getServiceVersionVo(ServiceVersion sv) { + ServiceVersionVo getServiceVersionVo(ServiceVersion sv) throws IOException { ServiceVersionVo serviceVersionVo = new ServiceVersionVo(); BeanUtils.copyProperties(sv, serviceVersionVo); ServiceModelVo serviceModelVo = JSON.parseObject(sv.getModel(), ServiceModelVo.class); @@ -425,6 +433,7 @@ public class ServiceServiceImpl implements ServiceService { serviceVersionVo.setCodeConfig(serviceCodeConfigVo); serviceVersionVo.setEnvVariables(JacksonUtil.parseJSONStr2Map(sv.getEnvVariables())); + serviceVersionVo.setImage(JsonUtils.jsonToMap(sv.getImage())); return serviceVersionVo; } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java index 13fab8fd..d1d2a4a0 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java @@ -23,6 +23,7 @@ import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.io.BufferedReader; +import java.io.IOException; import java.io.InputStreamReader; import java.util.*; @@ -400,7 +401,7 @@ public class K8sClientUtil { } // 创建配置好的Pod - public Integer createConfiguredPod(String podName, String namespace, Integer port, String mountPath, V1PersistentVolumeClaim pvc, DevEnvironment devEnvironment, String dataPvcName, String datasetPath, String modelPath) { + public Integer createConfiguredPod(String podName, String namespace, Integer port, String mountPath, V1PersistentVolumeClaim pvc, DevEnvironment devEnvironment, String dataPvcName, String datasetPath, String modelPath) throws IOException { //设置选择节点,pod反亲和性 Map selector = new LinkedHashMap<>(); @@ -494,6 +495,8 @@ public class K8sClientUtil { //配置资源 V1ResourceRequirements v1ResourceRequirements = setPodResource(devEnvironment.getComputingResourceId()); + String image = (String)JsonUtils.jsonToMap(devEnvironment.getImage()).get("value"); + V1Pod pod = new V1PodBuilder() .withNewMetadata() .withName(podName) @@ -502,7 +505,7 @@ public class K8sClientUtil { .withNewSpec() .addNewContainer() .withName(podName) - .withImage(devEnvironment.getImage()) + .withImage(image) .withPorts(new V1ContainerPort().containerPort(port).protocol("TCP")) .withVolumeMounts(volumeMounts) .withResources(v1ResourceRequirements) diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/ActiveLearnParamVo.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/ActiveLearnParamVo.java new file mode 100644 index 00000000..9ecbafe5 --- /dev/null +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/ActiveLearnParamVo.java @@ -0,0 +1,65 @@ +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 ActiveLearnParamVo { + private Map codeConfig; + + private Map dataset; + + private Map image; + + private Map model; + + private String taskType; + + private String modelPy; + + private String modelClassName; + + private String classifierAlg; + + private String regressorAlg; + + private String datasetPy; + + private String datasetClassName; + + private Integer dataSize; + + private Integer computingResourceId; + + private Boolean shuffle; + + private Integer trainSize; + + private Integer nInitial; + + private Integer nQueries; + + private Integer nInstances; + + private String queryStrategy; + + private String lossPy; + + private String lossClassName; + + private Integer nCheckpoint; + + private Integer batchSize; + + private Integer epochs; + + private Float lr; +} diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/ActiveLearnVo.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/ActiveLearnVo.java index 2cb72a5a..5dd68399 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/ActiveLearnVo.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/ActiveLearnVo.java @@ -21,22 +21,25 @@ public class ActiveLearnVo { @ApiModelProperty(value = "实验描述") private String description; - @ApiModelProperty(value = "任务类型:classification, regression") + @ApiModelProperty(value = "任务类型:classification或regression") private String taskType; - @ApiModelProperty(value = "预训练模型") - private Map model; + @ApiModelProperty(value = "代码") + private Map codeConfig; + + @ApiModelProperty(value = "预训练的模型") + private Map model; @ApiModelProperty(value = "模型文件路径") private String modelPy; - @ApiModelProperty(value = "模型类名称") + @ApiModelProperty(value = "类名称") private String modelClassName; @ApiModelProperty(value = "分类算法") private String classifierAlg; - @ApiModelProperty(value = "分类算法") + @ApiModelProperty(value = "回归算法") private String regressorAlg; @ApiModelProperty(value = "dataset文件路径") @@ -45,15 +48,16 @@ public class ActiveLearnVo { @ApiModelProperty(value = "dataset类名") private String datasetClassName; - @ApiModelProperty(value = "数据集") - private Map dataset; + @ApiModelProperty(value = "数据集文件路径") + private Map dataset; @ApiModelProperty(value = "数据量") private Integer dataSize; @ApiModelProperty(value = "镜像") - private Map image; + private Map image; + @ApiModelProperty(value = "计算资源id") private Integer computingResourceId; @ApiModelProperty(value = "是否随机打乱") @@ -92,13 +96,16 @@ public class ActiveLearnVo { @ApiModelProperty(value = "学习率") private Float lr; - private Integer state; - private String createBy; - private Date createTime; - private String updateBy; + private Date createTime; + private Date updateTime; + + private Integer state; + + @ApiModelProperty(value = "状态列表") + private String statusList; } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/DevEnvironmentVo.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/DevEnvironmentVo.java index 0d019417..5fc9030e 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/DevEnvironmentVo.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/DevEnvironmentVo.java @@ -34,7 +34,7 @@ public class DevEnvironmentVo implements Serializable { /** * 所用镜像 */ - private String image; + private Map image; /** * 对应数据集 */ diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/ImageVo.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/ImageVo.java index b6eea537..7c4a7cc9 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/ImageVo.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/ImageVo.java @@ -39,8 +39,8 @@ public class ImageVo implements Serializable { /** * 镜像推送地址 */ -// @ApiModelProperty(name = "url") -// private String url; + @ApiModelProperty(name = "value") + private String value; /** * 镜像tag名称 diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/serviceVos/ServiceVersionVo.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/serviceVos/ServiceVersionVo.java index b42797ad..ae49a1a5 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/serviceVos/ServiceVersionVo.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/serviceVos/ServiceVersionVo.java @@ -24,7 +24,7 @@ public class ServiceVersionVo { private ServiceModelVo model; - private String image; + private Map image; private String resource; diff --git a/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/ActiveLearnDaoMapper.xml b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/ActiveLearnDaoMapper.xml index fba4c6d9..b7890a09 100644 --- a/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/ActiveLearnDaoMapper.xml +++ b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/ActiveLearnDaoMapper.xml @@ -1,23 +1,45 @@ - - insert into active_learn(name, description, task_type, model, model_py, model_class_name, classifier_alg, - regressor_alg, dataset_py, dataset_class_name, dataset, data_size, image, - computing_resource_id, - shuffle, train_size, n_initial, n_queries, n_instances, query_strategy, - loss_path, loss_class_name, n_checkpoint, batch_size, epochs, lr, create_by, update_by) - values (#{activeLearn.name}, #{activeLearn.description}, #{activeLearn.taskType}, #{activeLearn.model}, - #{activeLearn.modelPy}, - #{activeLearn.modelClassName}, #{activeLearn.classifierAlg}, #{activeLearn.regressorAlg}, - #{activeLearn.datasetPy}, #{activeLearn.datasetClassName}, #{activeLearn.dataset}, - #{activeLearn.dataSize}, #{activeLearn.image}, #{activeLearn.computingResourceId}, - #{activeLearn.shuffle}, #{activeLearn.trainSize}, - #{activeLearn.nInitial}, #{activeLearn.nQueries}, #{activeLearn.nInstances}, - #{activeLearn.queryStrategy}, - #{activeLearn.lossPath}, #{activeLearn.lossClassName}, #{activeLearn.nCheckpoint}, - #{activeLearn.batchSize}, #{activeLearn.epochs}, #{activeLearn.lr}, - #{activeLearn.createBy}, #{activeLearn.updateBy}) + + + + + + + + insert into active_learn(name, description, task_type, framework_type, + code_config, + model, model_py, model_class_name, + classifier_alg, regressor_alg, dataset_py, dataset_class_name, + dataset, data_size, image, computing_resource_id, shuffle, + train_size, n_initial, n_queries, n_instances, query_strategy, + loss_py, loss_class_name, n_checkpoint, batch_size, epochs, + lr, create_by, update_by) + values (#{activeLearn.name}, #{activeLearn.description}, #{activeLearn.taskType}, #{activeLearn.frameworkType}, #{activeLearn.codeConfig}, + #{activeLearn.model}, + #{activeLearn.modelPy}, #{activeLearn.modelClassName}, #{activeLearn.classifierAlg}, + #{activeLearn.regressorAlg}, + #{activeLearn.datasetPy}, #{activeLearn.datasetClassName}, + #{activeLearn.dataset}, #{activeLearn.dataSize}, + #{activeLearn.image}, + #{activeLearn.computingResourceId}, #{activeLearn.shuffle}, + #{activeLearn.trainSize}, #{activeLearn.nInitial}, #{activeLearn.nQueries}, #{activeLearn.nInstances}, + #{activeLearn.queryStrategy}, #{activeLearn.lossPy}, + #{activeLearn.lossClassName}, #{activeLearn.nCheckpoint}, #{activeLearn.batchSize}, + #{activeLearn.epochs}, #{activeLearn.lr}, #{activeLearn.createBy}, #{activeLearn.updateBy}) @@ -32,6 +54,12 @@ task_type = #{activeLearn.taskType}, + + framework_type = #{activeLearn.frameworkType}, + + + code_config = #{activeLearn.codeConfig}, + model = #{activeLearn.model}, @@ -47,15 +75,15 @@ regressor_alg = #{activeLearn.regressorAlg}, + + dataset = #{activeLearn.dataset}, + dataset_py = #{activeLearn.datasetPy}, dataset_class_name = #{activeLearn.datasetClassName}, - - dataset = #{activeLearn.dataset}, - data_size = #{activeLearn.dataSize}, @@ -83,8 +111,8 @@ query_strategy = #{activeLearn.queryStrategy}, - - loss_path = #{activeLearn.lossPath}, + + loss_py = #{activeLearn.lossPy}, loss_class_name = #{activeLearn.lossClassName}, @@ -114,23 +142,6 @@ where id = #{activeLearn.id} - - - - - - select count(1) from active_learn_ins state = 1 - and active_learn_id = #{autoMlIns.activeLearnId} + and active_learn_id = #{activeLearnId} @@ -42,12 +14,46 @@ select * from active_learn_ins state = 1 - and active_learn_id = #{autoMlIns.activeLearnId} + and active_learn_id = #{activeLearnId} order by update_time DESC limit #{pageable.offset}, #{pageable.pageSize} + + insert into active_learn_ins(active_learn_id, param, argo_ins_name, argo_ins_ns, node_status, node_result, + result_path, status) + values (#{activeLearnIns.activeLearnId}, #{activeLearnIns.param}, #{activeLearnIns.argoInsName}, + #{activeLearnIns.argoInsNs}, + #{activeLearnIns.nodeStatus}, #{activeLearnIns.nodeResult}, #{activeLearnIns.resultPath}, + #{activeLearnIns.status}) + + + + update active_learn_ins + + + result_path = #{activeLearnIns.resultPath}, + + + status = #{activeLearnIns.status}, + + + node_status = #{activeLearnIns.nodeStatus}, + + + node_result = #{activeLearnIns.nodeResult}, + + + state = #{activeLearnIns.state}, + + + finish_time = #{activeLearnIns.finishTime}, + + + where id = #{activeLearnIns.id} + + + + \ No newline at end of file diff --git a/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/AutoMlDao.xml b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/AutoMlDao.xml index 129228e0..8bf8250f 100644 --- a/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/AutoMlDao.xml +++ b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/AutoMlDao.xml @@ -105,9 +105,6 @@ target_columns = #{autoMl.targetColumns}, - - update_by = #{autoMl.updateBy}, - state = #{autoMl.state}, @@ -123,6 +120,7 @@ + select * + from dev_environment + where JSON_CONTAINS(dataset, #{datasetId}) + and state = 1 + + + + + + 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 7355d286..bd0e2c77 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 @@ -1,7 +1,7 @@ - + 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, @@ -94,11 +94,12 @@ diff --git a/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/ResourceOccupy.xml b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/ResourceOccupy.xml index 22e662a4..3225be5c 100644 --- a/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/ResourceOccupy.xml +++ b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/ResourceOccupy.xml @@ -60,6 +60,17 @@ where id = #{id} + + update resource_occupy set task_state = 0 + where task_type = #{taskType} + + and task_id = #{taskId} + + + and task_ins_id = #{taskInsId} + + + + select concat(b.service_name, ':', a.version) + from service_version a, + service b + where JSON_CONTAINS(a.model, #{modelId}) + and a.state = 1 + and b.state = 1 + and a.service_id = b.id + + + + + \ No newline at end of file