| @@ -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"; | |||
| @@ -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<Page<ActiveLearn>> 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<ActiveLearn> addActiveLearn(@RequestBody ActiveLearnVo activeLearnServiceVo) { | |||
| return genericsSuccess(this.activeLearnService.save(activeLearnServiceVo)); | |||
| public GenericsAjaxResult<ActiveLearn> addActiveLearn(@RequestBody ActiveLearnVo activeLearnVo) throws Exception { | |||
| return genericsSuccess(this.activeLearnService.save(activeLearnVo)); | |||
| } | |||
| @PutMapping | |||
| @ApiOperation("编辑主动学习") | |||
| public GenericsAjaxResult<String> editActiveLearn(@RequestBody ActiveLearnVo activeLearnServiceVo) { | |||
| return genericsSuccess(this.activeLearnService.edit(activeLearnServiceVo)); | |||
| public GenericsAjaxResult<String> editActiveLearn(@RequestBody ActiveLearnVo activeLearnVo) throws Exception { | |||
| return genericsSuccess(this.activeLearnService.edit(activeLearnVo)); | |||
| } | |||
| @GetMapping("/getActiveLearnDetail") | |||
| @@ -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<Page<ActiveLearnIns>> queryByPage(ActiveLearnIns activeLearnIns, int page, int size) throws IOException { | |||
| public GenericsAjaxResult<Page<ActiveLearnIns>> 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<ActiveLearnIns> add(@RequestBody ActiveLearnIns activeLearnIns) { | |||
| return genericsSuccess(this.activeLearnInsService.insert(activeLearnIns)); | |||
| } | |||
| @DeleteMapping("{id}") | |||
| @ApiOperation("删除实验实例") | |||
| public GenericsAjaxResult<String> 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<Boolean> terminateActiveLearnIns(@PathVariable("id") Long id) { | |||
| public GenericsAjaxResult<Boolean> terminateActiveLearnIns(@PathVariable("id") Long id) throws Exception { | |||
| return genericsSuccess(this.activeLearnInsService.terminateActiveLearnIns(id)); | |||
| } | |||
| @GetMapping("{id}") | |||
| @ApiOperation("查看实验实例详情") | |||
| public GenericsAjaxResult<ActiveLearnIns> getDetailById(@PathVariable("id") Long id) { | |||
| public GenericsAjaxResult<ActiveLearnIns> getDetailById(@PathVariable("id") Long id) throws Exception { | |||
| return genericsSuccess(this.activeLearnInsService.getDetailById(id)); | |||
| } | |||
| } | |||
| @@ -115,6 +115,7 @@ public class ImageController extends BaseController { | |||
| * @return 删除是否成功 | |||
| */ | |||
| @DeleteMapping("{id}") | |||
| @ApiOperation("删除镜像") | |||
| public GenericsAjaxResult<String> deleteById(@PathVariable("id") Integer id) throws Exception { | |||
| return genericsSuccess(this.imageService.removeById(id)); | |||
| } | |||
| @@ -50,7 +50,7 @@ public class RayController extends BaseController { | |||
| @DeleteMapping("{id}") | |||
| @ApiOperation("删除自动超参数寻优") | |||
| public GenericsAjaxResult<String> deleteRay(@PathVariable("id") Long id) { | |||
| public GenericsAjaxResult<String> deleteRay(@PathVariable("id") Long id) { | |||
| return genericsSuccess(this.rayService.delete(id)); | |||
| } | |||
| @@ -85,13 +85,13 @@ public class ServiceController extends BaseController { | |||
| @GetMapping("/serviceVersionDetail/{id}") | |||
| @ApiOperation("查询服务版本详细信息") | |||
| public GenericsAjaxResult<ServiceVersionVo> getServiceVersion(@PathVariable("id") Long id) { | |||
| public GenericsAjaxResult<ServiceVersionVo> getServiceVersion(@PathVariable("id") Long id) throws IOException { | |||
| return genericsSuccess(serviceService.getServiceVersion(id)); | |||
| } | |||
| @GetMapping("serviceVersionCompare") | |||
| @ApiOperation("服务版本版本对比") | |||
| public GenericsAjaxResult<Map<String, Object>> serviceVersionCompare(@RequestParam("id1") Long id1, @RequestParam("id2") Long id2) throws IllegalAccessException { | |||
| public GenericsAjaxResult<Map<String, Object>> serviceVersionCompare(@RequestParam("id1") Long id1, @RequestParam("id2") Long id2) throws IllegalAccessException, IOException { | |||
| return genericsSuccess(serviceService.serviceVersionCompare(id1, id2)); | |||
| } | |||
| @@ -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; | |||
| } | |||
| @@ -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; | |||
| } | |||
| @@ -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; | |||
| } | |||
| @@ -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<ActiveLearn> queryByPage(@Param("name") String name, @Param("pageable") Pageable pageable); | |||
| List<ActiveLearn> queryByPage(@Param("name") String name, @Param("pageable") PageRequest pageRequest); | |||
| ActiveLearn getActiveLearnByName(@Param("name") String name); | |||
| @@ -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<ActiveLearnIns> queryAllByLimit(@Param("activeLearnIns") ActiveLearnIns activeLearnIns, @Param("pageable") Pageable pageable); | |||
| List<ActiveLearnIns> 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<ActiveLearnIns> getByActiveLearnId(@Param("activeLearnId") Long activeLearnId); | |||
| List<ActiveLearnIns> queryActiveLearnInsIsNotTerminated(); | |||
| } | |||
| @@ -63,5 +63,11 @@ public interface DevEnvironmentDao { | |||
| int deleteById(Integer id); | |||
| List<DevEnvironment> getRunning(); | |||
| List<DevEnvironment> queryByDatasetId(@Param("datasetId") String datasetId); | |||
| List<DevEnvironment> queryByModelId(@Param("modelId") String modelId); | |||
| List<DevEnvironment> queryByImageId(@Param("imageId") String imageId); | |||
| } | |||
| @@ -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); | |||
| } | |||
| @@ -38,4 +38,10 @@ public interface ServiceDao { | |||
| ServiceVersion getSvByVersion(@Param("version") String version, @Param("serviceId") Long serviceId); | |||
| List<ServiceVersion> getRunning(); | |||
| List<String> queryByModelId(@Param("modelId") String modelId); | |||
| List<String> queryByImageId(@Param("imageId") String imageId); | |||
| List<String> queryByCodeConfig(@Param("codeConfig") String codeConfig); | |||
| } | |||
| @@ -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<Long> activeLearnIds = new ArrayList<>(); | |||
| @Scheduled(cron = "0/30 * * * * ?") // 每30S执行一次 | |||
| public void executeActiveLearnInsStatus() { | |||
| List<ActiveLearnIns> activeLearnInsList = activeLearnInsService.queryActiveLearnInsIsNotTerminated(); | |||
| // 去argo查询状态 | |||
| List<ActiveLearnIns> 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<ActiveLearn> updateActiveLearns = new ArrayList<>(); | |||
| for (Long activeLearnId : activeLearnIds) { | |||
| // 获取当前实验的所有实例列表 | |||
| List<ActiveLearnIns> insList = activeLearnInsDao.getByActiveLearnId(activeLearnId); | |||
| List<String> 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<Long> iterator = activeLearnIds.iterator(); | |||
| while (iterator.hasNext()) { | |||
| Long activeLearnId = iterator.next(); | |||
| for (ActiveLearn activeLearn : updateActiveLearns) { | |||
| if (activeLearn.getId().equals(activeLearnId)) { | |||
| iterator.remove(); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -8,15 +8,21 @@ import java.io.IOException; | |||
| import java.util.List; | |||
| public interface ActiveLearnInsService { | |||
| Page<ActiveLearnIns> queryByPage(ActiveLearnIns activeLearnIns, PageRequest pageRequest) throws IOException; | |||
| Page<ActiveLearnIns> queryByPage(Long activeLearnId, PageRequest pageRequest) throws IOException; | |||
| ActiveLearnIns insert(ActiveLearnIns activeLearnIns); | |||
| String removeById(Long id); | |||
| String deleteById(Long id); | |||
| String batchDelete(List<Long> 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<ActiveLearnIns> queryActiveLearnInsIsNotTerminated(); | |||
| } | |||
| @@ -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<ActiveLearn> 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; | |||
| } | |||
| @@ -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<RayIns> queryByPage(Long rayId, PageRequest pageRequest) throws IOException; | |||
| @@ -22,4 +22,6 @@ public interface ResourceOccupyService { | |||
| Map<String, Double> queryCredit(); | |||
| void update(String taskType, Long taskId, Long taskInsId, Integer computingResourceId, Integer replicas); | |||
| void deleteTaskState(String taskType, Long taskId, Long taskInsId); | |||
| } | |||
| @@ -26,9 +26,9 @@ public interface ServiceService { | |||
| Service getService(Long id); | |||
| ServiceVersionVo getServiceVersion(Long id); | |||
| ServiceVersionVo getServiceVersion(Long id) throws IOException; | |||
| Map<String, Object> serviceVersionCompare(Long id1, Long id2) throws IllegalAccessException; | |||
| Map<String, Object> serviceVersionCompare(Long id1, Long id2) throws IllegalAccessException, IOException; | |||
| String deleteService(Long id) throws Exception; | |||
| @@ -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<ActiveLearnIns> queryByPage(ActiveLearnIns activeLearnIns, PageRequest pageRequest) throws IOException { | |||
| long total = this.activeLearnInsDao.count(activeLearnIns); | |||
| List<ActiveLearnIns> activeLearnInsList = this.activeLearnInsDao.queryAllByLimit(activeLearnIns, pageRequest); | |||
| public Page<ActiveLearnIns> queryByPage(Long activeLearnId, PageRequest pageRequest) throws IOException { | |||
| long total = this.activeLearnInsDao.count(activeLearnId); | |||
| List<ActiveLearnIns> 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<Long> 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<String, Object> requestData = new HashMap<>(); | |||
| requestData.put("namespace", namespace); | |||
| requestData.put("name", name); | |||
| // 创建发送数据map,将请求数据作为"data"键的值 | |||
| Map<String, Object> 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<String, Object> 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<String, Object> nodeMap = JsonUtils.jsonToMap(nodeStatus); | |||
| // 遍历 map | |||
| for (Map.Entry<String, Object> entry : nodeMap.entrySet()) { | |||
| // 获取每个 Map 中的值并强制转换为 Map | |||
| Map<String, Object> innerMap = (Map<String, Object>) 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<ActiveLearnIns> insList = activeLearnInsDao.getByActiveLearnId(activeLearnId); | |||
| List<String> 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<String, Object> requestData = new HashMap<>(); | |||
| requestData.put("namespace", namespace); | |||
| requestData.put("name", name); | |||
| // 创建发送数据map,将请求数据作为"data"键的值 | |||
| Map<String, Object> 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<String, Object> runResMap = JsonUtils.jsonToMap(req); | |||
| // 从响应Map中获取"data"部分 | |||
| Map<String, Object> data = (Map<String, Object>) runResMap.get("data"); | |||
| if (data == null || data.isEmpty()) { | |||
| throw new RuntimeException("工作流数据为空."); | |||
| } | |||
| // 从"data"中获取"status"部分,并返回"phase"的值 | |||
| Map<String, Object> status = (Map<String, Object>) 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<String, Object> nodes = (Map<String, Object>) status.get("nodes"); | |||
| Map<String, Object> modifiedNodes = new LinkedHashMap<>(); | |||
| if (nodes != null) { | |||
| for (Map.Entry<String, Object> nodeEntry : nodes.entrySet()) { | |||
| Map<String, Object> nodeDetails = (Map<String, Object>) 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<ActiveLearnIns> queryActiveLearnInsIsNotTerminated() { | |||
| return activeLearnInsDao.queryActiveLearnInsIsNotTerminated(); | |||
| } | |||
| } | |||
| @@ -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<ActiveLearn> 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<String, Object> converMap = JsonUtils.jsonToMap(convertRes); | |||
| // 组装运行接口json | |||
| Map<String, Object> output = (Map<String, Object>) converMap.get("output"); | |||
| Map<String, Object> runReqMap = new HashMap<>(); | |||
| runReqMap.put("data", converMap.get("data")); | |||
| // 调argo运行接口 | |||
| String runRes = HttpUtils.sendPost(argoUrl + argoWorkflowRun, JsonUtils.mapToJson(runReqMap)); | |||
| if (runRes == null || StringUtils.isEmpty(runRes)) { | |||
| throw new RuntimeException("运行失败"); | |||
| } | |||
| Map<String, Object> runResMap = JsonUtils.jsonToMap(runRes); | |||
| Map<String, Object> data = (Map<String, Object>) runResMap.get("data"); | |||
| //判断data为空 | |||
| if (data == null || MapUtils.isEmpty(data)) { | |||
| throw new RuntimeException("运行失败"); | |||
| } | |||
| Map<String, Object> metadata = (Map<String, Object>) data.get("metadata"); | |||
| // 插入记录到实验实例表 | |||
| 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<String, Object> param_output = (Map<String, Object>) output.get("param_output"); | |||
| List output1 = (ArrayList) param_output.values().toArray()[0]; | |||
| Map<String, String> output2 = (Map<String, String>) output1.get(0); | |||
| String outputPath = output2.get("path").replace("{{workflow.name}}", (String) metadata.get("name")) + "/hpo"; | |||
| 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 "执行成功"; | |||
| } | |||
| } | |||
| @@ -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; | |||
| @@ -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<CodeConfig> queryByPage(CodeConfig codeConfig, PageRequest pageRequest) { | |||
| @@ -112,6 +111,12 @@ public class CodeConfigServiceImpl implements CodeConfigService { | |||
| throw new Exception("该代码配置被主动学习:" + activeLearns + "使用,不能删除,请先删除主动学习。"); | |||
| } | |||
| List<String> 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(); | |||
| @@ -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 ? "删除成功" : "删除失败"; | |||
| } | |||
| } | |||
| @@ -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"); | |||
| } | |||
| @@ -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 ? "删除成功" : "删除失败"; | |||
| @@ -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<DevEnvironment> 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<String> 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); | |||
| @@ -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> 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<String, String> map = new HashMap<>(); | |||
| map.put("version", String.valueOf(id)); | |||
| List<Ray> 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<ActiveLearn> 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<DevEnvironment> 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<String> 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和创建者本身可以删除该数据集 | |||
| @@ -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<ActiveLearn> 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<DevEnvironment> 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<String> 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<Ray> 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<ActiveLearn> 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<DevEnvironment> 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<String> 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(); | |||
| @@ -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<DevEnvironment> 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<DevEnvironment> 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); | |||
| @@ -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; | |||
| @@ -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); | |||
| @@ -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); | |||
| } | |||
| } | |||
| @@ -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<ServiceVersionVo> queryByPageServiceVersion(ServiceVersion serviceVersion, int page, int size) { | |||
| public Page<ServiceVersionVo> 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<String, Object> serviceVersionCompare(Long id1, Long id2) throws IllegalAccessException { | |||
| public Map<String, Object> serviceVersionCompare(Long id1, Long id2) throws IllegalAccessException, IOException { | |||
| HashMap<String, Object> 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<ServiceVersionVo> getServiceVersionVoList(List<ServiceVersion> serviceVersionList) { | |||
| List<ServiceVersionVo> getServiceVersionVoList(List<ServiceVersion> serviceVersionList) throws IOException { | |||
| List<ServiceVersionVo> 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; | |||
| } | |||
| @@ -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<String, String> 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) | |||
| @@ -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<String,Object> codeConfig; | |||
| private Map<String,Object> dataset; | |||
| private Map<String,Object> image; | |||
| private Map<String,Object> 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; | |||
| } | |||
| @@ -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<String,Object> model; | |||
| @ApiModelProperty(value = "代码") | |||
| private Map<String, Object> codeConfig; | |||
| @ApiModelProperty(value = "预训练的模型") | |||
| private Map<String, Object> 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<String,Object> dataset; | |||
| @ApiModelProperty(value = "数据集文件路径") | |||
| private Map<String, Object> dataset; | |||
| @ApiModelProperty(value = "数据量") | |||
| private Integer dataSize; | |||
| @ApiModelProperty(value = "镜像") | |||
| private Map<String,Object> image; | |||
| private Map<String, Object> 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; | |||
| } | |||
| @@ -34,7 +34,7 @@ public class DevEnvironmentVo implements Serializable { | |||
| /** | |||
| * 所用镜像 | |||
| */ | |||
| private String image; | |||
| private Map<String,Object> image; | |||
| /** | |||
| * 对应数据集 | |||
| */ | |||
| @@ -39,8 +39,8 @@ public class ImageVo implements Serializable { | |||
| /** | |||
| * 镜像推送地址 | |||
| */ | |||
| // @ApiModelProperty(name = "url") | |||
| // private String url; | |||
| @ApiModelProperty(name = "value") | |||
| private String value; | |||
| /** | |||
| * 镜像tag名称 | |||
| @@ -24,7 +24,7 @@ public class ServiceVersionVo { | |||
| private ServiceModelVo model; | |||
| private String image; | |||
| private Map<String, Object> image; | |||
| private String resource; | |||
| @@ -1,23 +1,45 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | |||
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||
| <mapper namespace="com.ruoyi.platform.mapper.ActiveLearnDao"> | |||
| <insert id="save"> | |||
| 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}) | |||
| <select id="count" resultType="java.lang.Long"> | |||
| select count(1) from active_learn | |||
| <include refid="common_condition"></include> | |||
| </select> | |||
| <select id="queryByPage" resultType="com.ruoyi.platform.domain.ActiveLearn"> | |||
| select * from active_learn | |||
| <include refid="common_condition"></include> | |||
| order by create_time desc limit #{pageable.offset}, #{pageable.pageSize} | |||
| </select> | |||
| <select id="getActiveLearnByName" resultType="com.ruoyi.platform.domain.ActiveLearn"> | |||
| select * | |||
| from active_learn | |||
| where name = #{name} | |||
| and state = 1 | |||
| </select> | |||
| <insert id="save" keyProperty="id" useGeneratedKeys="true"> | |||
| 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}) | |||
| </insert> | |||
| <update id="edit"> | |||
| @@ -32,6 +54,12 @@ | |||
| <if test="activeLearn.taskType != null and activeLearn.taskType !=''"> | |||
| task_type = #{activeLearn.taskType}, | |||
| </if> | |||
| <if test="activeLearn.frameworkType != null and activeLearn.frameworkType !=''"> | |||
| framework_type = #{activeLearn.frameworkType}, | |||
| </if> | |||
| <if test="activeLearn.codeConfig != null and activeLearn.codeConfig !=''"> | |||
| code_config = #{activeLearn.codeConfig}, | |||
| </if> | |||
| <if test="activeLearn.model != null and activeLearn.model !=''"> | |||
| model = #{activeLearn.model}, | |||
| </if> | |||
| @@ -47,15 +75,15 @@ | |||
| <if test="activeLearn.regressorAlg != null and activeLearn.regressorAlg !=''"> | |||
| regressor_alg = #{activeLearn.regressorAlg}, | |||
| </if> | |||
| <if test="activeLearn.dataset != null and activeLearn.dataset !=''"> | |||
| dataset = #{activeLearn.dataset}, | |||
| </if> | |||
| <if test="activeLearn.datasetPy != null and activeLearn.datasetPy !=''"> | |||
| dataset_py = #{activeLearn.datasetPy}, | |||
| </if> | |||
| <if test="activeLearn.datasetClassName != null and activeLearn.datasetClassName !=''"> | |||
| dataset_class_name = #{activeLearn.datasetClassName}, | |||
| </if> | |||
| <if test="activeLearn.dataset != null and activeLearn.dataset !=''"> | |||
| dataset = #{activeLearn.dataset}, | |||
| </if> | |||
| <if test="activeLearn.dataSize != null"> | |||
| data_size = #{activeLearn.dataSize}, | |||
| </if> | |||
| @@ -83,8 +111,8 @@ | |||
| <if test="activeLearn.queryStrategy != null and activeLearn.queryStrategy !=''"> | |||
| query_strategy = #{activeLearn.queryStrategy}, | |||
| </if> | |||
| <if test="activeLearn.lossPath != null and activeLearn.lossPath !=''"> | |||
| loss_path = #{activeLearn.lossPath}, | |||
| <if test="activeLearn.lossPy != null and activeLearn.lossPy !=''"> | |||
| loss_py = #{activeLearn.lossPy}, | |||
| </if> | |||
| <if test="activeLearn.lossClassName != null and activeLearn.lossClassName !=''"> | |||
| loss_class_name = #{activeLearn.lossClassName}, | |||
| @@ -114,23 +142,6 @@ | |||
| where id = #{activeLearn.id} | |||
| </update> | |||
| <select id="count" resultType="java.lang.Long"> | |||
| select count(1) from active_learn | |||
| <include refid="common_condition"></include> | |||
| </select> | |||
| <select id="queryByPage" resultType="com.ruoyi.platform.domain.ActiveLearn"> | |||
| select * from active_learn | |||
| <include refid="common_condition"></include> | |||
| </select> | |||
| <select id="getActiveLearnByName" resultType="com.ruoyi.platform.domain.ActiveLearn"> | |||
| select * | |||
| from active_learn | |||
| where name = #{name} | |||
| and state = 1 | |||
| </select> | |||
| <select id="getActiveLearnById" resultType="com.ruoyi.platform.domain.ActiveLearn"> | |||
| select * | |||
| from active_learn | |||
| @@ -1,40 +1,12 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | |||
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||
| <mapper namespace="com.ruoyi.platform.mapper.ActiveLearnInsDao"> | |||
| <insert id="insert"> | |||
| insert into active_learn_ins(active_learn_id, status, param, argo_ins_name, argo_ins_ns, result_path) | |||
| values (#{activeLearnIns.activeLearnId}, #{activeLearnIns.status}, #{activeLearnIns.param}, | |||
| #{activeLearnIns.argoInsName}, #{activeLearnIns.argoInsNs}, #{activeLearnIns.resultPath}) | |||
| </insert> | |||
| <update id="update"> | |||
| update active_learn_ins | |||
| <set> | |||
| <if test="activeLearnIns.state != null"> | |||
| state = #{activeLearnIns.state}, | |||
| </if> | |||
| <if test="activeLearnIns.updateTime != null"> | |||
| update_time = #{activeLearnIns.updateTime}, | |||
| </if> | |||
| <if test="activeLearnIns.finishTime != null"> | |||
| finish_time = #{activeLearnIns.finishTime}, | |||
| </if> | |||
| <if test="activeLearnIns.status != null and activeLearnIns.status != ''"> | |||
| status = #{activeLearnIns.status}, | |||
| </if> | |||
| <if test="activeLearnIns.resultPath != null and activeLearnIns.resultPath != ''"> | |||
| result_path = #{activeLearnIns.resultPath}, | |||
| </if> | |||
| </set> | |||
| where id = #{activeLearnIns.id} | |||
| </update> | |||
| <select id="count" resultType="java.lang.Long"> | |||
| select count(1) | |||
| from active_learn_ins | |||
| <where> | |||
| state = 1 | |||
| and active_learn_id = #{autoMlIns.activeLearnId} | |||
| and active_learn_id = #{activeLearnId} | |||
| </where> | |||
| </select> | |||
| @@ -42,12 +14,46 @@ | |||
| select * from active_learn_ins | |||
| <where> | |||
| state = 1 | |||
| and active_learn_id = #{autoMlIns.activeLearnId} | |||
| and active_learn_id = #{activeLearnId} | |||
| </where> | |||
| order by update_time DESC | |||
| limit #{pageable.offset}, #{pageable.pageSize} | |||
| </select> | |||
| <insert id="insert" keyProperty="id" useGeneratedKeys="true"> | |||
| 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}) | |||
| </insert> | |||
| <update id="update"> | |||
| update active_learn_ins | |||
| <set> | |||
| <if test="activeLearnIns.resultPath != null and activeLearnIns.resultPath != ''"> | |||
| result_path = #{activeLearnIns.resultPath}, | |||
| </if> | |||
| <if test="activeLearnIns.status != null and activeLearnIns.status != ''"> | |||
| status = #{activeLearnIns.status}, | |||
| </if> | |||
| <if test="activeLearnIns.nodeStatus != null and activeLearnIns.nodeStatus != ''"> | |||
| node_status = #{activeLearnIns.nodeStatus}, | |||
| </if> | |||
| <if test="activeLearnIns.nodeResult != null and activeLearnIns.nodeResult != ''"> | |||
| node_result = #{activeLearnIns.nodeResult}, | |||
| </if> | |||
| <if test="activeLearnIns.state != null"> | |||
| state = #{activeLearnIns.state}, | |||
| </if> | |||
| <if test="activeLearnIns.finishTime != null"> | |||
| finish_time = #{activeLearnIns.finishTime}, | |||
| </if> | |||
| </set> | |||
| where id = #{activeLearnIns.id} | |||
| </update> | |||
| <select id="queryById" resultType="com.ruoyi.platform.domain.ActiveLearnIns"> | |||
| select * from active_learn_ins | |||
| <where> | |||
| @@ -62,4 +68,12 @@ | |||
| and state = 1 | |||
| order by update_time DESC limit 5 | |||
| </select> | |||
| <select id="queryActiveLearnInsIsNotTerminated" resultType="com.ruoyi.platform.domain.ActiveLearnIns"> | |||
| select * | |||
| from active_learn_ins | |||
| where (status NOT IN ('Terminated', 'Succeeded', 'Failed') | |||
| OR status IS NULL) | |||
| and state = 1 | |||
| </select> | |||
| </mapper> | |||
| @@ -105,9 +105,6 @@ | |||
| <if test="autoMl.targetColumns != null and autoMl.targetColumns !=''"> | |||
| target_columns = #{autoMl.targetColumns}, | |||
| </if> | |||
| <if test="autoMl.updateBy != null and autoMl.updateBy !=''"> | |||
| update_by = #{autoMl.updateBy}, | |||
| </if> | |||
| <if test="autoMl.state != null"> | |||
| state = #{autoMl.state}, | |||
| </if> | |||
| @@ -123,6 +120,7 @@ | |||
| <select id="queryByPage" resultType="com.ruoyi.platform.domain.AutoMl"> | |||
| select * from auto_ml | |||
| <include refid="common_condition"></include> | |||
| order by create_time desc limit #{pageable.offset}, #{pageable.pageSize} | |||
| </select> | |||
| <select id="getAutoMlById" resultType="com.ruoyi.platform.domain.AutoMl"> | |||
| @@ -214,5 +214,26 @@ | |||
| delete from dev_environment where id = #{id} | |||
| </delete> | |||
| <select id="queryByDatasetId" resultType="com.ruoyi.platform.domain.DevEnvironment"> | |||
| select * | |||
| from dev_environment | |||
| where JSON_CONTAINS(dataset, #{datasetId}) | |||
| and state = 1 | |||
| </select> | |||
| <select id="queryByModelId" resultType="com.ruoyi.platform.domain.DevEnvironment"> | |||
| select * | |||
| from dev_environment | |||
| where JSON_CONTAINS(model, #{modelId}) | |||
| and state = 1 | |||
| </select> | |||
| <select id="queryByImageId" resultType="com.ruoyi.platform.domain.DevEnvironment"> | |||
| select * | |||
| from dev_environment | |||
| where JSON_CONTAINS(image, #{imageId}) | |||
| and state = 1 | |||
| </select> | |||
| </mapper> | |||
| @@ -1,7 +1,7 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | |||
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||
| <mapper namespace="com.ruoyi.platform.mapper.RayDao"> | |||
| <insert id="save"> | |||
| <insert id="save" keyProperty="id" useGeneratedKeys="true"> | |||
| 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 @@ | |||
| <select id="queryByPage" resultType="com.ruoyi.platform.domain.Ray"> | |||
| select * from ray | |||
| <include refid="common_condition"></include> | |||
| order by create_time desc limit #{pageable.offset}, #{pageable.pageSize} | |||
| </select> | |||
| <select id="getRayByName" resultType="com.ruoyi.platform.domain.Ray"> | |||
| select * | |||
| from ray _ | |||
| from ray | |||
| where name = #{name} | |||
| and state = 1 | |||
| </select> | |||
| @@ -60,6 +60,17 @@ | |||
| where id = #{id} | |||
| </update> | |||
| <update id="deleteTaskState"> | |||
| update resource_occupy set task_state = 0 | |||
| where task_type = #{taskType} | |||
| <if test="taskId != null and taskId !=''"> | |||
| and task_id = #{taskId} | |||
| </if> | |||
| <if test="taskInsId != null and taskInsId !=''"> | |||
| and task_ins_id = #{taskInsId} | |||
| </if> | |||
| </update> | |||
| <select id="haveResource" resultType="java.lang.Boolean"> | |||
| select case when used + #{need} <= total then TRUE else FALSE end | |||
| from resource | |||
| @@ -190,4 +190,34 @@ | |||
| set run_state = #{runState} | |||
| where deployment_name = #{deploymentName} | |||
| </update> | |||
| <select id="queryByModelId" resultType="java.lang.String"> | |||
| 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 | |||
| </select> | |||
| <select id="queryByImageId" resultType="java.lang.String"> | |||
| select concat(b.service_name, ':', a.version) | |||
| from service_version a, | |||
| service b | |||
| where JSON_CONTAINS(a.image, #{imageId}) | |||
| and a.state = 1 | |||
| and b.state = 1 | |||
| and a.service_id = b.id | |||
| </select> | |||
| <select id="queryByCodeConfig" resultType="java.lang.String"> | |||
| select concat(b.service_name, ':', a.version) | |||
| from service_version a, | |||
| service b | |||
| where JSON_CONTAINS(a.code_config, #{codeConfig}) | |||
| and a.state = 1 | |||
| and b.state = 1 | |||
| and a.service_id = b.id | |||
| </select> | |||
| </mapper> | |||