| @@ -1,14 +1,17 @@ | |||||
| package com.ruoyi.platform.controller.autoML; | package com.ruoyi.platform.controller.autoML; | ||||
| import com.ruoyi.common.core.web.controller.BaseController; | import com.ruoyi.common.core.web.controller.BaseController; | ||||
| import com.ruoyi.common.core.web.domain.AjaxResult; | |||||
| import com.ruoyi.common.core.web.domain.GenericsAjaxResult; | import com.ruoyi.common.core.web.domain.GenericsAjaxResult; | ||||
| import com.ruoyi.platform.domain.AutoMl; | import com.ruoyi.platform.domain.AutoMl; | ||||
| import com.ruoyi.platform.domain.AutoMlIns; | |||||
| import com.ruoyi.platform.service.AutoMLService; | import com.ruoyi.platform.service.AutoMLService; | ||||
| import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||
| import io.swagger.annotations.ApiOperation; | import io.swagger.annotations.ApiOperation; | ||||
| import org.springframework.data.domain.Page; | import org.springframework.data.domain.Page; | ||||
| import org.springframework.data.domain.PageRequest; | import org.springframework.data.domain.PageRequest; | ||||
| import org.springframework.web.bind.annotation.*; | import org.springframework.web.bind.annotation.*; | ||||
| import org.springframework.web.multipart.MultipartFile; | |||||
| import javax.annotation.Resource; | import javax.annotation.Resource; | ||||
| @@ -24,7 +27,7 @@ public class AutoMLController extends BaseController { | |||||
| @ApiOperation("分页查询") | @ApiOperation("分页查询") | ||||
| public GenericsAjaxResult<Page<AutoMl>> queryByPage(@RequestParam("page") int page, | public GenericsAjaxResult<Page<AutoMl>> queryByPage(@RequestParam("page") int page, | ||||
| @RequestParam("size") int size, | @RequestParam("size") int size, | ||||
| @RequestParam(value = "mlName", required = false) String mlName) { | |||||
| @RequestParam(value = "ml_name", required = false) String mlName) { | |||||
| PageRequest pageRequest = PageRequest.of(page, size); | PageRequest pageRequest = PageRequest.of(page, size); | ||||
| return genericsSuccess(this.autoMLService.queryByPage(mlName, pageRequest)); | return genericsSuccess(this.autoMLService.queryByPage(mlName, pageRequest)); | ||||
| } | } | ||||
| @@ -37,14 +40,53 @@ public class AutoMLController extends BaseController { | |||||
| @PutMapping | @PutMapping | ||||
| @ApiOperation("编辑自动机器学习") | @ApiOperation("编辑自动机器学习") | ||||
| public GenericsAjaxResult<String> editAutoMl(@RequestBody AutoMl autoMl){ | |||||
| public GenericsAjaxResult<String> editAutoMl(@RequestBody AutoMl autoMl) { | |||||
| return genericsSuccess(this.autoMLService.edit(autoMl)); | return genericsSuccess(this.autoMLService.edit(autoMl)); | ||||
| } | } | ||||
| @DeleteMapping("{id}") | @DeleteMapping("{id}") | ||||
| @ApiOperation("删除自动机器学习") | @ApiOperation("删除自动机器学习") | ||||
| public GenericsAjaxResult<String> deleteAutoMl(@PathVariable("id") Long id){ | |||||
| public GenericsAjaxResult<String> deleteAutoMl(@PathVariable("id") Long id) { | |||||
| return genericsSuccess(this.autoMLService.delete(id)); | return genericsSuccess(this.autoMLService.delete(id)); | ||||
| } | } | ||||
| @GetMapping("/autoMlIns") | |||||
| @ApiOperation("分页查询自动机器学习实例") | |||||
| public GenericsAjaxResult<Page<AutoMlIns>> queryByPage(@RequestParam("page") int page, | |||||
| @RequestParam("size") int size, | |||||
| @RequestParam("auto_ml_id") Long autoMlId) { | |||||
| PageRequest pageRequest = PageRequest.of(page, size); | |||||
| return genericsSuccess(this.autoMLService.queryAutoMlInsByPage(autoMlId, pageRequest)); | |||||
| } | |||||
| @PostMapping("/autoMlIns") | |||||
| @ApiOperation("新增自动机器学习实例") | |||||
| public GenericsAjaxResult<AutoMlIns> addAutoMlIns(@RequestBody AutoMlIns autoMlIns) throws Exception { | |||||
| return genericsSuccess(this.autoMLService.saveAutoMlIns(autoMlIns)); | |||||
| } | |||||
| @PutMapping("/autoMlIns") | |||||
| @ApiOperation("编辑自动机器学习实例") | |||||
| public GenericsAjaxResult<String> editAutoMlIns(@RequestBody AutoMlIns autoMlIns) throws Exception { | |||||
| return genericsSuccess(this.autoMLService.editAutoMlIns(autoMlIns)); | |||||
| } | |||||
| @DeleteMapping("/autoMlIns/{id}") | |||||
| @ApiOperation("删除自动机器学习实例") | |||||
| public GenericsAjaxResult<String> deleteAutoMlIns(@PathVariable("id") Long id) { | |||||
| return genericsSuccess(this.autoMLService.deleteAutoMlIns(id)); | |||||
| } | |||||
| @CrossOrigin(origins = "*", allowedHeaders = "*") | |||||
| @PostMapping("/upload") | |||||
| @ApiOperation(value = "上传数据文件csv", notes = "上传数据文件csv,并将信息存入数据库。") | |||||
| public AjaxResult upload(@RequestParam("file") MultipartFile file, @RequestParam("uuid") String uuid) throws Exception { | |||||
| return AjaxResult.success(this.autoMLService.upload(file, uuid)); | |||||
| } | |||||
| @PostMapping("{id}") | |||||
| @ApiOperation("运行自动机器学习实验") | |||||
| public GenericsAjaxResult<String> runAutoML(@PathVariable("id") Long id) throws Exception { | |||||
| return genericsSuccess(this.autoMLService.runAutoMlIns(id)); | |||||
| } | |||||
| } | } | ||||
| @@ -0,0 +1,77 @@ | |||||
| package com.ruoyi.platform.domain; | |||||
| import com.baomidou.mybatisplus.annotation.TableField; | |||||
| import com.fasterxml.jackson.databind.PropertyNamingStrategy; | |||||
| import com.fasterxml.jackson.databind.annotation.JsonNaming; | |||||
| import com.ruoyi.platform.vo.VersionVo; | |||||
| import lombok.Data; | |||||
| import java.util.Date; | |||||
| @Data | |||||
| @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) | |||||
| public class AutoMlIns { | |||||
| private Long id; | |||||
| private Long autoMlId; | |||||
| private String taskType; | |||||
| private String datasetName; | |||||
| private Integer timeLeftForThisTask; | |||||
| private Integer perRunTimeLimit; | |||||
| private Integer ensembleSize; | |||||
| private String ensembleClass; | |||||
| private Integer ensembleNbest; | |||||
| private Integer maxModelsOnDisc; | |||||
| private Integer seed; | |||||
| private Integer memoryLimit; | |||||
| private String includeClassifier; | |||||
| private String includeFeaturePreprocessor; | |||||
| private String includeRegressor; | |||||
| private String excludeClassifier; | |||||
| private String excludeRegressor; | |||||
| private String excludeFeaturePreprocessor; | |||||
| private String resamplingStrategy; | |||||
| private Float trainSize; | |||||
| private Boolean shuffle; | |||||
| private Integer folds; | |||||
| private Boolean deleteTmpFolderAfterTerminate; | |||||
| private String dataCsv; | |||||
| private String targetColumns; | |||||
| private Integer state; | |||||
| private String createBy; | |||||
| private String updateBy; | |||||
| private Date createTime; | |||||
| private Date updateTime; | |||||
| @TableField(exist = false) | |||||
| private VersionVo versionVo; | |||||
| } | |||||
| @@ -11,7 +11,7 @@ public interface AutoMLDao { | |||||
| List<AutoMl> queryByPage(@Param("mlName") String mlName, @Param("pageable") Pageable pageable); | List<AutoMl> queryByPage(@Param("mlName") String mlName, @Param("pageable") Pageable pageable); | ||||
| AutoMl getAutoById(@Param("id") Long id); | |||||
| AutoMl getAutoMlById(@Param("id") Long id); | |||||
| int save(@Param("autoMl") AutoMl autoMl); | int save(@Param("autoMl") AutoMl autoMl); | ||||
| @@ -0,0 +1,21 @@ | |||||
| package com.ruoyi.platform.mapper; | |||||
| import com.ruoyi.platform.domain.AutoMlIns; | |||||
| import org.apache.ibatis.annotations.Param; | |||||
| import org.springframework.data.domain.Pageable; | |||||
| import java.util.List; | |||||
| public interface AutoMLInsDao { | |||||
| long count(@Param("autoMlId") Long autoMlId); | |||||
| List<AutoMlIns> queryByPage(@Param("autoMlId") Long autoMlId, @Param("pageable") Pageable pageable); | |||||
| int save(@Param("autoMlIns") AutoMlIns autoMlIns); | |||||
| int edit(@Param("autoMlIns") AutoMlIns autoMlIns); | |||||
| AutoMlIns getById(@Param("id") Long id); | |||||
| AutoMlIns findByDatasetName(@Param("datasetName") String datasetName, @Param("autoMlId") Long autoMlId); | |||||
| } | |||||
| @@ -1,15 +1,32 @@ | |||||
| package com.ruoyi.platform.service; | package com.ruoyi.platform.service; | ||||
| import com.ruoyi.platform.domain.AutoMl; | import com.ruoyi.platform.domain.AutoMl; | ||||
| import com.ruoyi.platform.domain.AutoMlIns; | |||||
| import org.springframework.data.domain.Page; | import org.springframework.data.domain.Page; | ||||
| import org.springframework.data.domain.PageRequest; | import org.springframework.data.domain.PageRequest; | ||||
| import org.springframework.web.multipart.MultipartFile; | |||||
| import java.util.List; | |||||
| import java.util.Map; | |||||
| public interface AutoMLService { | public interface AutoMLService { | ||||
| Page<AutoMl> queryByPage(String mlName, PageRequest pageRequest); | |||||
| Page<AutoMl> queryByPage(String mlName, PageRequest pageRequest); | |||||
| AutoMl save(AutoMl autoMl); | AutoMl save(AutoMl autoMl); | ||||
| String edit(AutoMl autoMl); | String edit(AutoMl autoMl); | ||||
| String delete(Long id); | String delete(Long id); | ||||
| Page<AutoMlIns> queryAutoMlInsByPage(Long autoMlId, PageRequest pageRequest); | |||||
| AutoMlIns saveAutoMlIns(AutoMlIns autoMlIns) throws Exception; | |||||
| String editAutoMlIns(AutoMlIns autoMlIns) throws Exception; | |||||
| String deleteAutoMlIns(Long id); | |||||
| Map<String, String> upload(MultipartFile file, String uuid) throws Exception; | |||||
| String runAutoMlIns(Long id) throws Exception; | |||||
| } | } | ||||
| @@ -3,22 +3,57 @@ package com.ruoyi.platform.service.impl; | |||||
| import com.ruoyi.common.security.utils.SecurityUtils; | import com.ruoyi.common.security.utils.SecurityUtils; | ||||
| import com.ruoyi.platform.constant.Constant; | import com.ruoyi.platform.constant.Constant; | ||||
| import com.ruoyi.platform.domain.AutoMl; | import com.ruoyi.platform.domain.AutoMl; | ||||
| import com.ruoyi.platform.domain.AutoMlIns; | |||||
| import com.ruoyi.platform.mapper.AutoMLDao; | import com.ruoyi.platform.mapper.AutoMLDao; | ||||
| import com.ruoyi.platform.mapper.AutoMLInsDao; | |||||
| import com.ruoyi.platform.service.AutoMLService; | import com.ruoyi.platform.service.AutoMLService; | ||||
| import com.ruoyi.system.api.model.LoginUser; | |||||
| import com.ruoyi.platform.utils.DVCUtils; | |||||
| import com.ruoyi.platform.utils.FileUtil; | |||||
| import com.ruoyi.platform.utils.K8sClientUtil; | |||||
| import io.kubernetes.client.openapi.models.V1Pod; | |||||
| import org.apache.commons.io.FileUtils; | |||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Value; | |||||
| import org.springframework.data.domain.Page; | import org.springframework.data.domain.Page; | ||||
| import org.springframework.data.domain.PageImpl; | import org.springframework.data.domain.PageImpl; | ||||
| import org.springframework.data.domain.PageRequest; | import org.springframework.data.domain.PageRequest; | ||||
| import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||
| import org.springframework.web.multipart.MultipartFile; | |||||
| import javax.annotation.Resource; | import javax.annotation.Resource; | ||||
| import java.io.File; | |||||
| import java.util.HashMap; | |||||
| import java.util.List; | import java.util.List; | ||||
| import java.util.Map; | |||||
| import java.util.concurrent.CompletableFuture; | |||||
| @Service("autoMLService") | @Service("autoMLService") | ||||
| public class AutoMLServiceImpl implements AutoMLService { | public class AutoMLServiceImpl implements AutoMLService { | ||||
| @Value("${harbor.serviceNS}") | |||||
| private String serviceNS; | |||||
| @Value("${dockerpush.proxyUrl}") | |||||
| private String proxyUrl; | |||||
| @Value("${dockerpush.mountPath}") | |||||
| private String mountPath; | |||||
| @Value("${minio.pvcName}") | |||||
| private String pvcName; | |||||
| @Value("${automl.image}") | |||||
| private String image; | |||||
| @Value("${git.localPath}") | |||||
| String localPath; | |||||
| private static final Logger logger = LoggerFactory.getLogger(ModelsServiceImpl.class); | |||||
| @Resource | @Resource | ||||
| private AutoMLDao autoMLDao; | private AutoMLDao autoMLDao; | ||||
| @Resource | |||||
| private AutoMLInsDao autoMLInsDao; | |||||
| @Resource | |||||
| private K8sClientUtil k8sClientUtil; | |||||
| @Resource | |||||
| private DVCUtils dvcUtils; | |||||
| @Override | @Override | ||||
| public Page<AutoMl> queryByPage(String mlName, PageRequest pageRequest) { | public Page<AutoMl> queryByPage(String mlName, PageRequest pageRequest) { | ||||
| @@ -29,25 +64,29 @@ public class AutoMLServiceImpl implements AutoMLService { | |||||
| @Override | @Override | ||||
| public AutoMl save(AutoMl autoMl) { | public AutoMl save(AutoMl autoMl) { | ||||
| String username = SecurityUtils.getLoginUser().getUsername(); | |||||
| autoMl.setCreateBy(username); | |||||
| autoMl.setUpdateBy(username); | |||||
| autoMLDao.save(autoMl); | autoMLDao.save(autoMl); | ||||
| return autoMl; | return autoMl; | ||||
| } | } | ||||
| @Override | @Override | ||||
| public String edit(AutoMl autoMl) { | public String edit(AutoMl autoMl) { | ||||
| String username = SecurityUtils.getLoginUser().getUsername(); | |||||
| autoMl.setUpdateBy(username); | |||||
| autoMLDao.edit(autoMl); | autoMLDao.edit(autoMl); | ||||
| return "修改成功"; | return "修改成功"; | ||||
| } | } | ||||
| @Override | @Override | ||||
| public String delete(Long id) { | public String delete(Long id) { | ||||
| AutoMl autoMl = autoMLDao.getAutoById(id); | |||||
| AutoMl autoMl = autoMLDao.getAutoMlById(id); | |||||
| if (autoMl == null) { | if (autoMl == null) { | ||||
| throw new RuntimeException("服务不存在"); | throw new RuntimeException("服务不存在"); | ||||
| } | } | ||||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | |||||
| String username = loginUser.getUsername(); | |||||
| String username = SecurityUtils.getLoginUser().getUsername(); | |||||
| String createBy = autoMl.getCreateBy(); | String createBy = autoMl.getCreateBy(); | ||||
| if (!(StringUtils.equals(username, "admin") || StringUtils.equals(username, createBy))) { | if (!(StringUtils.equals(username, "admin") || StringUtils.equals(username, createBy))) { | ||||
| throw new RuntimeException("无权限删除该服务"); | throw new RuntimeException("无权限删除该服务"); | ||||
| @@ -56,4 +95,180 @@ public class AutoMLServiceImpl implements AutoMLService { | |||||
| autoMl.setState(Constant.State_invalid); | autoMl.setState(Constant.State_invalid); | ||||
| return autoMLDao.edit(autoMl) > 0 ? "删除成功" : "删除失败"; | return autoMLDao.edit(autoMl) > 0 ? "删除成功" : "删除失败"; | ||||
| } | } | ||||
| @Override | |||||
| public Page<AutoMlIns> queryAutoMlInsByPage(Long autoMlId, PageRequest pageRequest) { | |||||
| long total = autoMLInsDao.count(autoMlId); | |||||
| List<AutoMlIns> autoMlIns = autoMLInsDao.queryByPage(autoMlId, pageRequest); | |||||
| return new PageImpl<>(autoMlIns, pageRequest, total); | |||||
| } | |||||
| @Override | |||||
| public AutoMlIns saveAutoMlIns(AutoMlIns autoMlIns) throws Exception { | |||||
| String ci4sUsername = SecurityUtils.getLoginUser().getUsername(); | |||||
| AutoMlIns oldAutoMlIns = autoMLInsDao.findByDatasetName(autoMlIns.getDatasetName(), autoMlIns.getAutoMlId()); | |||||
| if (oldAutoMlIns != null) { | |||||
| throw new RuntimeException("数据集名称已存在"); | |||||
| } | |||||
| String sourcePath = autoMlIns.getVersionVo().getUrl(); | |||||
| String rootPath = localPath + ci4sUsername + "/automl/" + autoMlIns.getAutoMlId() + "/" + autoMlIns.getDatasetName(); | |||||
| dvcUtils.moveFiles(sourcePath, rootPath); | |||||
| autoMlIns.setDataCsv(rootPath + "/" + autoMlIns.getVersionVo().getFileName()); | |||||
| autoMlIns.setCreateBy(ci4sUsername); | |||||
| autoMlIns.setUpdateBy(ci4sUsername); | |||||
| autoMLInsDao.save(autoMlIns); | |||||
| return autoMlIns; | |||||
| } | |||||
| @Override | |||||
| public String editAutoMlIns(AutoMlIns autoMlIns) throws Exception { | |||||
| AutoMlIns oldAutoMlIns = autoMLInsDao.findByDatasetName(autoMlIns.getDatasetName(), autoMlIns.getAutoMlId()); | |||||
| if (oldAutoMlIns != null && !oldAutoMlIns.getId().equals(autoMlIns.getId())) { | |||||
| throw new RuntimeException("数据集名称已存在"); | |||||
| } | |||||
| String ci4sUsername = SecurityUtils.getLoginUser().getUsername(); | |||||
| autoMlIns.setUpdateBy(ci4sUsername); | |||||
| if (autoMlIns.getVersionVo() != null && StringUtils.isNotEmpty(autoMlIns.getVersionVo().getUrl())) { | |||||
| String sourcePath = autoMlIns.getVersionVo().getUrl(); | |||||
| String rootPath = localPath + ci4sUsername + "/automl/" + autoMlIns.getAutoMlId() + "/" + autoMlIns.getDatasetName(); | |||||
| dvcUtils.moveFiles(sourcePath, rootPath); | |||||
| autoMlIns.setDataCsv(rootPath + "/" + autoMlIns.getVersionVo().getFileName()); | |||||
| } | |||||
| autoMLInsDao.edit(autoMlIns); | |||||
| return "修改成功"; | |||||
| } | |||||
| @Override | |||||
| public String deleteAutoMlIns(Long id) { | |||||
| AutoMlIns autoMlIns = autoMLInsDao.getById(id); | |||||
| if (autoMlIns == null) { | |||||
| throw new RuntimeException("实例不存在"); | |||||
| } | |||||
| String username = SecurityUtils.getLoginUser().getUsername(); | |||||
| String createBy = autoMlIns.getCreateBy(); | |||||
| if (!(StringUtils.equals(username, "admin") || StringUtils.equals(username, createBy))) { | |||||
| throw new RuntimeException("无权限删除该实例"); | |||||
| } | |||||
| autoMlIns.setState(Constant.State_invalid); | |||||
| return autoMLInsDao.edit(autoMlIns) > 0 ? "删除成功" : "删除失败"; | |||||
| } | |||||
| @Override | |||||
| public Map<String, String> upload(MultipartFile file, String uuid) throws Exception { | |||||
| Map<String, String> result = new HashMap<>(); | |||||
| String username = SecurityUtils.getLoginUser().getUsername(); | |||||
| String fileName = file.getOriginalFilename(); | |||||
| String path = localPath + "temp/" + username + "/automl_data/" + uuid; | |||||
| long sizeInBytes = file.getSize(); | |||||
| String formattedSize = FileUtil.formatFileSize(sizeInBytes); | |||||
| File targetFile = new File(path, file.getOriginalFilename()); | |||||
| // 确保目录存在 | |||||
| targetFile.getParentFile().mkdirs(); | |||||
| // 保存文件到目标路径 | |||||
| FileUtils.copyInputStreamToFile(file.getInputStream(), targetFile); | |||||
| // 返回上传文件的路径 | |||||
| result.put("fileName", fileName); | |||||
| result.put("url", path); // objectName根据实际情况定义 | |||||
| result.put("fileSize", formattedSize); | |||||
| return result; | |||||
| } | |||||
| @Override | |||||
| public String runAutoMlIns(Long id) throws Exception { | |||||
| AutoMlIns autoMlIns = autoMLInsDao.getById(id); | |||||
| if (autoMlIns == null) { | |||||
| throw new Exception("开发环境配置不存在"); | |||||
| } | |||||
| StringBuffer command = new StringBuffer(); | |||||
| command.append("nohup python /opt/automl.py --task_type " + autoMlIns.getTaskType()); | |||||
| if (StringUtils.isNotEmpty(autoMlIns.getDataCsv())) { | |||||
| command.append(" --data_csv " + autoMlIns.getDataCsv()); | |||||
| } else { | |||||
| throw new Exception("训练数据为空"); | |||||
| } | |||||
| if (StringUtils.isNotEmpty(autoMlIns.getTargetColumns())) { | |||||
| command.append(" --target_columns " + autoMlIns.getTargetColumns()); | |||||
| } else { | |||||
| throw new Exception("目标列为空"); | |||||
| } | |||||
| if (StringUtils.isNotEmpty(autoMlIns.getDatasetName())) { | |||||
| command.append(" --dataset_name " + autoMlIns.getDatasetName()); | |||||
| } else { | |||||
| throw new Exception("数据集名称为空"); | |||||
| } | |||||
| // String username = SecurityUtils.getLoginUser().getUsername().toLowerCase(); | |||||
| String username = "admin"; | |||||
| //构造pod名称 | |||||
| String podName = username + "-autoMlIns-pod-" + id; | |||||
| V1Pod pod = k8sClientUtil.createPodWithEnv(podName, serviceNS, proxyUrl, mountPath, pvcName, image); | |||||
| if (autoMlIns.getTimeLeftForThisTask() != null) { | |||||
| command.append(" --time_left_for_this_task " + autoMlIns.getTimeLeftForThisTask()); | |||||
| } | |||||
| if (autoMlIns.getPerRunTimeLimit() != null) { | |||||
| command.append(" --per_run_time_limit " + autoMlIns.getPerRunTimeLimit()); | |||||
| } | |||||
| if (autoMlIns.getEnsembleSize() != null) { | |||||
| command.append(" --ensemble_size " + autoMlIns.getEnsembleSize()); | |||||
| } | |||||
| if (StringUtils.isNotEmpty(autoMlIns.getEnsembleClass())) { | |||||
| command.append(" --ensemble_class " + autoMlIns.getEnsembleClass()); | |||||
| } | |||||
| if (autoMlIns.getEnsembleNbest() != null) { | |||||
| command.append(" --ensemble_nbest " + autoMlIns.getEnsembleNbest()); | |||||
| } | |||||
| if (autoMlIns.getMaxModelsOnDisc() != null) { | |||||
| command.append(" --max_models_on_disc " + autoMlIns.getMaxModelsOnDisc()); | |||||
| } | |||||
| if (autoMlIns.getSeed() != null) { | |||||
| command.append(" --seed " + autoMlIns.getSeed()); | |||||
| } | |||||
| if (autoMlIns.getMemoryLimit() != null) { | |||||
| command.append(" --memory_limit " + autoMlIns.getMemoryLimit()); | |||||
| } | |||||
| if (StringUtils.isNotEmpty(autoMlIns.getIncludeClassifier())) { | |||||
| command.append(" --include_classifier " + autoMlIns.getIncludeClassifier()); | |||||
| } | |||||
| if (StringUtils.isNotEmpty(autoMlIns.getIncludeRegressor())) { | |||||
| command.append(" --include_regressor " + autoMlIns.getIncludeRegressor()); | |||||
| } | |||||
| if (StringUtils.isNotEmpty(autoMlIns.getIncludeFeaturePreprocessor())) { | |||||
| command.append(" --include_feature_preprocessor " + autoMlIns.getIncludeFeaturePreprocessor()); | |||||
| } | |||||
| if (StringUtils.isNotEmpty(autoMlIns.getExcludeClassifier())) { | |||||
| command.append(" --exclude_classifier " + autoMlIns.getExcludeClassifier()); | |||||
| } | |||||
| if (StringUtils.isNotEmpty(autoMlIns.getExcludeRegressor())) { | |||||
| command.append(" --exclude_regressor " + autoMlIns.getExcludeRegressor()); | |||||
| } | |||||
| if (StringUtils.isNotEmpty(autoMlIns.getExcludeFeaturePreprocessor())) { | |||||
| command.append(" --exclude_feature_preprocessor " + autoMlIns.getExcludeFeaturePreprocessor()); | |||||
| } | |||||
| if (StringUtils.isNotEmpty(autoMlIns.getResamplingStrategy())) { | |||||
| command.append(" --resampling_strategy " + autoMlIns.getResamplingStrategy()); | |||||
| } | |||||
| if (autoMlIns.getTrainSize() != null) { | |||||
| command.append(" --train_size " + autoMlIns.getTrainSize()); | |||||
| } | |||||
| if (autoMlIns.getShuffle() != null) { | |||||
| command.append(" --shuffle " + autoMlIns.getShuffle()); | |||||
| } | |||||
| if (autoMlIns.getFolds() != null) { | |||||
| command.append(" --folds " + autoMlIns.getFolds()); | |||||
| } | |||||
| command.append(" &"); | |||||
| CompletableFuture.supplyAsync(() -> { | |||||
| try { | |||||
| String log = k8sClientUtil.executeCommand(pod, String.valueOf(command)); | |||||
| } catch (Exception e) { | |||||
| logger.error(e.getMessage(), e); | |||||
| } | |||||
| return null; | |||||
| }); | |||||
| return "执行成功"; | |||||
| } | |||||
| } | } | ||||
| @@ -104,8 +104,6 @@ public class JupyterServiceImpl implements JupyterService { | |||||
| // String pvcName = loginUser.getUsername().toLowerCase() + "-editor-pvc"; | // String pvcName = loginUser.getUsername().toLowerCase() + "-editor-pvc"; | ||||
| // V1PersistentVolumeClaim pvc = k8sClientUtil.createPvc(namespace, pvcName, storage, storageClassName); | // V1PersistentVolumeClaim pvc = k8sClientUtil.createPvc(namespace, pvcName, storage, storageClassName); | ||||
| //TODO 设置镜像可配置,这里先用默认镜像启动pod | |||||
| // 调用修改后的 createPod 方法,传入额外的参数 | // 调用修改后的 createPod 方法,传入额外的参数 | ||||
| // Integer podPort = k8sClientUtil.createConfiguredPod(podName, namespace, port, mountPath, pvc, devEnvironment, minioPvcName, datasetPath, modelPath); | // Integer podPort = k8sClientUtil.createConfiguredPod(podName, namespace, port, mountPath, pvc, devEnvironment, minioPvcName, datasetPath, modelPath); | ||||
| Integer podPort = k8sClientUtil.createConfiguredPod(podName, namespace, port, mountPath, null, devEnvironment, minioPvcName, datasetPath, modelPath); | Integer podPort = k8sClientUtil.createConfiguredPod(podName, namespace, port, mountPath, null, devEnvironment, minioPvcName, datasetPath, modelPath); | ||||
| @@ -38,7 +38,7 @@ | |||||
| <include refid="common_condition"></include> | <include refid="common_condition"></include> | ||||
| </select> | </select> | ||||
| <select id="getAutoById" resultType="com.ruoyi.platform.domain.AutoMl"> | |||||
| <select id="getAutoMlById" resultType="com.ruoyi.platform.domain.AutoMl"> | |||||
| select * from auto_ml where id = #{id} | select * from auto_ml where id = #{id} | ||||
| </select> | </select> | ||||
| @@ -0,0 +1,132 @@ | |||||
| <?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.AutoMLInsDao"> | |||||
| <insert id="save"> | |||||
| insert into auto_ml_ins(auto_ml_id, task_type, dataset_name, time_left_for_this_task, per_run_time_limit, | |||||
| ensemble_size, ensemble_class, ensemble_nbest, max_models_on_disc, seed, memory_limit, | |||||
| include_classifier, include_feature_preprocessor, include_regressor, exclude_classifier, | |||||
| exclude_regressor, exclude_feature_preprocessor, resampling_strategy, train_size, | |||||
| shuffle, folds, delete_tmp_folder_after_terminate, data_csv, target_columns, create_by, | |||||
| update_by) | |||||
| values (#{autoMlIns.autoMlId}, #{autoMlIns.taskType}, #{autoMlIns.datasetName}, | |||||
| #{autoMlIns.timeLeftForThisTask}, #{autoMlIns.perRunTimeLimit}, | |||||
| #{autoMlIns.ensembleSize}, #{autoMlIns.ensembleClass}, #{autoMlIns.ensembleNbest}, | |||||
| #{autoMlIns.maxModelsOnDisc}, #{autoMlIns.seed}, | |||||
| #{autoMlIns.memoryLimit}, #{autoMlIns.includeClassifier}, #{autoMlIns.includeFeaturePreprocessor}, | |||||
| #{autoMlIns.includeRegressor}, #{autoMlIns.excludeClassifier}, | |||||
| #{autoMlIns.excludeRegressor}, #{autoMlIns.excludeFeaturePreprocessor}, #{autoMlIns.resamplingStrategy}, | |||||
| #{autoMlIns.trainSize}, #{autoMlIns.shuffle}, | |||||
| #{autoMlIns.folds}, #{autoMlIns.deleteTmpFolderAfterTerminate}, #{autoMlIns.dataCsv}, | |||||
| #{autoMlIns.targetColumns}, #{autoMlIns.createBy}, #{autoMlIns.updateBy}) | |||||
| </insert> | |||||
| <update id="edit"> | |||||
| update auto_ml_ins | |||||
| <set> | |||||
| <if test="autoMlIns.taskType != null and autoMlIns.taskType !=''"> | |||||
| task_type = #{autoMlIns.taskType}, | |||||
| </if> | |||||
| <if test="autoMlIns.datasetName != null and autoMlIns.datasetName !=''"> | |||||
| dataset_name = #{autoMlIns.datasetName}, | |||||
| </if> | |||||
| <if test="autoMlIns.timeLeftForThisTask != null"> | |||||
| time_left_for_this_task = #{autoMlIns.timeLeftForThisTask}, | |||||
| </if> | |||||
| <if test="autoMlIns.perRunTimeLimit != null"> | |||||
| per_run_time_limit = #{autoMlIns.perRunTimeLimit}, | |||||
| </if> | |||||
| <if test="autoMlIns.ensembleSize != null"> | |||||
| ensemble_size = #{autoMlIns.ensembleSize}, | |||||
| </if> | |||||
| <if test="autoMlIns.ensembleClass != null and autoMlIns.ensembleClass !=''"> | |||||
| ensemble_class = #{autoMlIns.ensembleClass}, | |||||
| </if> | |||||
| <if test="autoMlIns.ensembleNbest != null"> | |||||
| ensemble_nbest = #{autoMlIns.ensembleNbest}, | |||||
| </if> | |||||
| <if test="autoMlIns.maxModelsOnDisc != null"> | |||||
| max_models_on_disc = #{autoMlIns.maxModelsOnDisc}, | |||||
| </if> | |||||
| <if test="autoMlIns.seed != null"> | |||||
| seed = #{autoMlIns.seed}, | |||||
| </if> | |||||
| <if test="autoMlIns.memoryLimit != null"> | |||||
| memory_limit = #{autoMlIns.memoryLimit}, | |||||
| </if> | |||||
| <if test="autoMlIns.includeClassifier != null and autoMlIns.includeClassifier !=''"> | |||||
| include_classifier = #{autoMlIns.includeClassifier}, | |||||
| </if> | |||||
| <if test="autoMlIns.includeFeaturePreprocessor != null and autoMlIns.includeFeaturePreprocessor !=''"> | |||||
| include_feature_preprocessor = #{autoMlIns.includeFeaturePreprocessor}, | |||||
| </if> | |||||
| <if test="autoMlIns.includeRegressor != null and autoMlIns.includeRegressor !=''"> | |||||
| include_regressor = #{autoMlIns.includeRegressor}, | |||||
| </if> | |||||
| <if test="autoMlIns.excludeClassifier != null and autoMlIns.excludeClassifier !=''"> | |||||
| exclude_classifier = #{autoMlIns.excludeClassifier}, | |||||
| </if> | |||||
| <if test="autoMlIns.excludeRegressor != null and autoMlIns.excludeRegressor !=''"> | |||||
| exclude_regressor = #{autoMlIns.excludeRegressor}, | |||||
| </if> | |||||
| <if test="autoMlIns.excludeFeaturePreprocessor != null and autoMlIns.excludeFeaturePreprocessor !=''"> | |||||
| exclude_feature_preprocessor = #{autoMlIns.excludeFeaturePreprocessor}, | |||||
| </if> | |||||
| <if test="autoMlIns.resamplingStrategy != null and autoMlIns.resamplingStrategy !=''"> | |||||
| resampling_strategy = #{autoMlIns.resamplingStrategy}, | |||||
| </if> | |||||
| <if test="autoMlIns.trainSize != null and autoMlIns.trainSize !=''"> | |||||
| train_size = #{autoMlIns.trainSize}, | |||||
| </if> | |||||
| <if test="autoMlIns.shuffle != null"> | |||||
| shuffle = #{autoMlIns.shuffle}, | |||||
| </if> | |||||
| <if test="autoMlIns.folds != null"> | |||||
| folds = #{autoMlIns.folds}, | |||||
| </if> | |||||
| <if test="autoMlIns.deleteTmpFolderAfterTerminate != null"> | |||||
| delete_tmp_folder_after_terminate = #{autoMlIns.deleteTmpFolderAfterTerminate}, | |||||
| </if> | |||||
| <if test="autoMlIns.dataCsv != null and autoMlIns.dataCsv !=''"> | |||||
| data_csv = #{autoMlIns.dataCsv}, | |||||
| </if> | |||||
| <if test="autoMlIns.targetColumns != null and autoMlIns.targetColumns !=''"> | |||||
| target_columns = #{autoMlIns.targetColumns}, | |||||
| </if> | |||||
| <if test="autoMlIns.state != null"> | |||||
| state = #{autoMlIns.state}, | |||||
| </if> | |||||
| <if test="autoMlIns.updateBy != null and autoMlIns.updateBy !=''"> | |||||
| update_by = #{autoMlIns.updateBy}, | |||||
| </if> | |||||
| </set> | |||||
| where id = #{autoMlIns.id} | |||||
| </update> | |||||
| <select id="getById" resultType="com.ruoyi.platform.domain.AutoMlIns"> | |||||
| select * | |||||
| from auto_ml_ins | |||||
| where id = #{id} | |||||
| </select> | |||||
| <select id="count" resultType="java.lang.Long"> | |||||
| select count(1) from auto_ml_ins | |||||
| <include refid="common_condition"></include> | |||||
| </select> | |||||
| <select id="queryByPage" resultType="com.ruoyi.platform.domain.AutoMlIns"> | |||||
| select * from auto_ml_ins | |||||
| <include refid="common_condition"></include> | |||||
| </select> | |||||
| <select id="findByDatasetName" resultType="com.ruoyi.platform.domain.AutoMlIns"> | |||||
| select * from auto_ml_ins | |||||
| <include refid="common_condition"></include> | |||||
| and dataset_name = #{datasetName} | |||||
| </select> | |||||
| <sql id="common_condition"> | |||||
| <where> | |||||
| state = 1 and auto_ml_id = #{autoMlId} | |||||
| </where> | |||||
| </sql> | |||||
| </mapper> | |||||