Browse Source

自动机器学习开发

dev-automl
chenzhihang 1 year ago
parent
commit
a3fa7d4f1b
11 changed files with 272 additions and 29 deletions
  1. +10
    -10
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/autoML/AutoMlController.java
  2. +49
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/autoML/AutoMlInsController.java
  3. +35
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/AutoMlIns.java
  4. +1
    -1
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/AutoMlDao.java
  5. +19
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/AutoMlInsDao.java
  6. +18
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/AutoMlInsService.java
  7. +1
    -1
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/AutoMlService.java
  8. +60
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/AutoMlInsServiceImpl.java
  9. +14
    -16
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/AutoMlServiceImpl.java
  10. +1
    -1
      ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/AutoMlDao.xml
  11. +64
    -0
      ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/AutoMlInsDao.xml

ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/autoML/AutoMLController.java → ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/autoML/AutoMlController.java View File

@@ -4,7 +4,7 @@ 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.platform.domain.AutoMl;
import com.ruoyi.platform.service.AutoMLService;
import com.ruoyi.platform.service.AutoMlService;
import com.ruoyi.platform.vo.AutoMlVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@@ -19,10 +19,10 @@ import java.io.IOException;
@RestController
@RequestMapping("autoML")
@Api("自动机器学习")
public class AutoMLController extends BaseController {
public class AutoMlController extends BaseController {

@Resource
private AutoMLService autoMLService;
private AutoMlService autoMlService;

@GetMapping
@ApiOperation("分页查询")
@@ -30,42 +30,42 @@ public class AutoMLController extends BaseController {
@RequestParam("size") int size,
@RequestParam(value = "ml_name", required = false) String mlName) {
PageRequest pageRequest = PageRequest.of(page, size);
return genericsSuccess(this.autoMLService.queryByPage(mlName, pageRequest));
return genericsSuccess(this.autoMlService.queryByPage(mlName, pageRequest));
}

@PostMapping
@ApiOperation("新增自动机器学习")
public GenericsAjaxResult<AutoMl> addAutoMl(@RequestBody AutoMlVo autoMlVo) throws Exception {
return genericsSuccess(this.autoMLService.save(autoMlVo));
return genericsSuccess(this.autoMlService.save(autoMlVo));
}

@PutMapping
@ApiOperation("编辑自动机器学习")
public GenericsAjaxResult<String> editAutoMl(@RequestBody AutoMlVo autoMlVo) throws Exception {
return genericsSuccess(this.autoMLService.edit(autoMlVo));
return genericsSuccess(this.autoMlService.edit(autoMlVo));
}
@GetMapping("/getAutoMlDetail")
@ApiOperation("获取自动机器学习详细信息")
public GenericsAjaxResult<AutoMlVo> getAutoMlDetail(@RequestParam("id") Long id) throws IOException {
return genericsSuccess(this.autoMLService.getAutoMlDetail(id));
return genericsSuccess(this.autoMlService.getAutoMlDetail(id));
}

@DeleteMapping("{id}")
@ApiOperation("删除自动机器学习")
public GenericsAjaxResult<String> deleteAutoMl(@PathVariable("id") Long id) {
return genericsSuccess(this.autoMLService.delete(id));
return genericsSuccess(this.autoMlService.delete(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));
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));
return genericsSuccess(this.autoMlService.runAutoMlIns(id));
}
}

+ 49
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/autoML/AutoMlInsController.java View File

@@ -0,0 +1,49 @@
package com.ruoyi.platform.controller.autoML;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.GenericsAjaxResult;
import com.ruoyi.platform.domain.AutoMlIns;
import com.ruoyi.platform.service.AutoMlInsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("autoMLIns")
@Api("自动机器学习实验实例")
public class AutoMlInsController extends BaseController {

@Resource
private AutoMlInsService autoMLInsService;

@GetMapping
@ApiOperation("分页查询")
public GenericsAjaxResult<Page<AutoMlIns>> queryByPage(AutoMlIns autoMlIns, int page, int size) throws IOException {
PageRequest pageRequest = PageRequest.of(page, size);
return genericsSuccess(this.autoMLInsService.queryByPage(autoMlIns, pageRequest));
}

@PostMapping
@ApiOperation("新增实验实例")
public GenericsAjaxResult<AutoMlIns> add(@RequestBody AutoMlIns autoMlIns) {
return genericsSuccess(this.autoMLInsService.insert(autoMlIns));
}

@DeleteMapping("{id}")
@ApiOperation("删除实验实例")
public GenericsAjaxResult<String> deleteById(@PathVariable("id") Long id) {
return genericsSuccess(this.autoMLInsService.removeById(id));
}

@DeleteMapping("batchDelete")
@ApiOperation("批量删除实验实例")
public GenericsAjaxResult<String> batchDelete(@RequestBody List<Long> ids) throws Exception {
return genericsSuccess(this.autoMLInsService.batchDelete(ids));
}
}

+ 35
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/AutoMlIns.java View File

@@ -0,0 +1,35 @@
package com.ruoyi.platform.domain;

import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import io.swagger.annotations.ApiModel;
import lombok.Data;

import java.util.Date;

@Data
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
@ApiModel(description = "自动机器学习实验实例")
public class AutoMlIns {
private Long id;

private Long autoMlId;

private String modelPath;

private String imgPath;

private Integer state;

private String status;

private String nodeStatus;

private String nodeResult;

private String param;

private Date createTime;

private Date updateTime;
}

ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/AutoMLDao.java → ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/AutoMlDao.java View File

@@ -6,7 +6,7 @@ import org.springframework.data.domain.Pageable;

import java.util.List;

public interface AutoMLDao {
public interface AutoMlDao {
long count(@Param("mlName") String mlName);

List<AutoMl> queryByPage(@Param("mlName") String mlName, @Param("pageable") Pageable pageable);

+ 19
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/AutoMlInsDao.java View File

@@ -0,0 +1,19 @@
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("autoMlIns") AutoMlIns autoMlIns);

List<AutoMlIns> queryAllByLimit(@Param("autoMlIns") AutoMlIns autoMlIns, @Param("pageable") Pageable pageable);

int insert(@Param("autoMlIns") AutoMlIns autoMlIns);

int update(@Param("autoMlIns") AutoMlIns autoMlIns);

AutoMlIns queryById(@Param("id") Long id);
}

+ 18
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/AutoMlInsService.java View File

@@ -0,0 +1,18 @@
package com.ruoyi.platform.service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import com.ruoyi.platform.domain.AutoMlIns;

import java.io.IOException;
import java.util.List;

public interface AutoMlInsService {

Page<AutoMlIns> queryByPage(AutoMlIns autoMlIns, PageRequest pageRequest) throws IOException;

AutoMlIns insert(AutoMlIns autoMlIns);

String removeById(Long id);

String batchDelete(List<Long> ids);
}

ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/AutoMLService.java → ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/AutoMlService.java View File

@@ -9,7 +9,7 @@ import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.Map;

public interface AutoMLService {
public interface AutoMlService {
Page<AutoMl> queryByPage(String mlName, PageRequest pageRequest);

AutoMl save(AutoMlVo autoMlVo) throws Exception;

+ 60
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/AutoMlInsServiceImpl.java View File

@@ -0,0 +1,60 @@
package com.ruoyi.platform.service.impl;

import com.ruoyi.platform.constant.Constant;
import com.ruoyi.platform.domain.AutoMlIns;
import com.ruoyi.platform.mapper.AutoMlInsDao;
import com.ruoyi.platform.service.AutoMlInsService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

@Service
public class AutoMlInsServiceImpl implements AutoMlInsService {
@Resource
private AutoMlInsDao autoMlInsDao;


@Override
public Page<AutoMlIns> queryByPage(AutoMlIns autoMlIns, PageRequest pageRequest) throws IOException {
long total = this.autoMlInsDao.count(autoMlIns);
List<AutoMlIns> autoMlInsList = this.autoMlInsDao.queryAllByLimit(autoMlIns, pageRequest);
return new PageImpl<>(autoMlInsList, pageRequest, total);
}

@Override
public AutoMlIns insert(AutoMlIns autoMlIns) {
this.autoMlInsDao.insert(autoMlIns);
return autoMlIns;
}

@Override
public String removeById(Long id) {
AutoMlIns autoMlIns = autoMlInsDao.queryById(id);
if (autoMlIns == null) {
return "实验实例不存在";
}
autoMlIns.setState(Constant.State_invalid);
int update = autoMlInsDao.update(autoMlIns);
if (update > 0) {
return "删除成功";
} else {
return "删除失败";
}
}

@Override
public String batchDelete(List<Long> ids) {
for (Long id : ids) {
String result = removeById(id);
if (!"删除成功".equals(result)) {
return result;
}
}
return "删除成功";
}
}

ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/AutoMLServiceImpl.java → ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/AutoMlServiceImpl.java View File

@@ -3,8 +3,8 @@ package com.ruoyi.platform.service.impl;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.platform.constant.Constant;
import com.ruoyi.platform.domain.AutoMl;
import com.ruoyi.platform.mapper.AutoMLDao;
import com.ruoyi.platform.service.AutoMLService;
import com.ruoyi.platform.mapper.AutoMlDao;
import com.ruoyi.platform.service.AutoMlService;
import com.ruoyi.platform.utils.*;
import com.ruoyi.platform.vo.AutoMlVo;
import io.kubernetes.client.openapi.models.V1Pod;
@@ -29,7 +29,7 @@ import java.util.Map;
import java.util.concurrent.CompletableFuture;

@Service("autoMLService")
public class AutoMLServiceImpl implements AutoMLService {
public class AutoMlServiceImpl implements AutoMlService {
@Value("${harbor.serviceNS}")
private String serviceNS;
@Value("${dockerpush.proxyUrl}")
@@ -46,22 +46,20 @@ public class AutoMLServiceImpl implements AutoMLService {
private static final Logger logger = LoggerFactory.getLogger(ModelsServiceImpl.class);

@Resource
private AutoMLDao autoMLDao;
private AutoMlDao autoMlDao;
@Resource
private K8sClientUtil k8sClientUtil;
@Resource
private DVCUtils dvcUtils;

@Override
public Page<AutoMl> queryByPage(String mlName, PageRequest pageRequest) {
long total = autoMLDao.count(mlName);
List<AutoMl> autoMls = autoMLDao.queryByPage(mlName, pageRequest);
long total = autoMlDao.count(mlName);
List<AutoMl> autoMls = autoMlDao.queryByPage(mlName, pageRequest);
return new PageImpl<>(autoMls, pageRequest, total);
}

@Override
public AutoMl save(AutoMlVo autoMlVo) throws Exception {
AutoMl autoMlByName = autoMLDao.getAutoMlByName(autoMlVo.getMlName());
AutoMl autoMlByName = autoMlDao.getAutoMlByName(autoMlVo.getMlName());
if (autoMlByName != null) {
throw new RuntimeException("实验名称已存在");
}
@@ -72,13 +70,13 @@ public class AutoMLServiceImpl implements AutoMLService {
autoMl.setUpdateBy(username);
String datasetJson = JacksonUtil.toJSONString(autoMlVo.getDataset());
autoMl.setDataset(datasetJson);
autoMLDao.save(autoMl);
autoMlDao.save(autoMl);
return autoMl;
}

@Override
public String edit(AutoMlVo autoMlVo) throws Exception {
AutoMl oldAutoMl = autoMLDao.getAutoMlByName(autoMlVo.getMlName());
AutoMl oldAutoMl = autoMlDao.getAutoMlByName(autoMlVo.getMlName());
if (oldAutoMl != null && !oldAutoMl.getId().equals(autoMlVo.getId())) {
throw new RuntimeException("实验名称已存在");
}
@@ -90,13 +88,13 @@ public class AutoMLServiceImpl implements AutoMLService {
String datasetJson = JacksonUtil.toJSONString(autoMlVo.getDataset());
autoMl.setDataset(datasetJson);

autoMLDao.edit(autoMl);
autoMlDao.edit(autoMl);
return "修改成功";
}

@Override
public String delete(Long id) {
AutoMl autoMl = autoMLDao.getAutoMlById(id);
AutoMl autoMl = autoMlDao.getAutoMlById(id);
if (autoMl == null) {
throw new RuntimeException("服务不存在");
}
@@ -108,12 +106,12 @@ public class AutoMLServiceImpl implements AutoMLService {
}

autoMl.setState(Constant.State_invalid);
return autoMLDao.edit(autoMl) > 0 ? "删除成功" : "删除失败";
return autoMlDao.edit(autoMl) > 0 ? "删除成功" : "删除失败";
}

@Override
public AutoMlVo getAutoMlDetail(Long id) throws IOException {
AutoMl autoMl = autoMLDao.getAutoMlById(id);
AutoMl autoMl = autoMlDao.getAutoMlById(id);
AutoMlVo autoMlVo = new AutoMlVo();
BeanUtils.copyProperties(autoMl, autoMlVo);
if (StringUtils.isNotEmpty(autoMl.getDataset())) {
@@ -146,7 +144,7 @@ public class AutoMLServiceImpl implements AutoMLService {

@Override
public String runAutoMlIns(Long id) throws Exception {
AutoMl autoMl = autoMLDao.getAutoMlById(id);
AutoMl autoMl = autoMlDao.getAutoMlById(id);
if (autoMl == null) {
throw new Exception("开发环境配置不存在");
}

ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/AutoMLDaoMapper.xml → ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/AutoMlDao.xml View File

@@ -1,6 +1,6 @@
<?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.AutoMLDao">
<mapper namespace="com.ruoyi.platform.mapper.AutoMlDao">
<insert id="save">
insert into auto_ml(ml_name, ml_description, task_type, dataset, time_left_for_this_task,
per_run_time_limit, ensemble_size, ensemble_class, ensemble_nbest, max_models_on_disc, seed,

+ 64
- 0
ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/AutoMlInsDao.xml View File

@@ -0,0 +1,64 @@
<?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="insert" keyProperty="id" useGeneratedKeys="true">
insert into auto_ml_ins(auto_ml_id, model_path, img_path, node_status, node_result, param)
values (#{autoMlIns.autoMlId}, #{autoMlIns.modelPath}, #{autoMlIns.imgPath}, #{autoMlIns.nodeStatus},
#{autoMlIns.nodeResult}, #{autoMlIns.param})
</insert>

<update id="update">
update auto_ml_ins
<set>
<if test="autoMlIns.modelPath != null and autoMlIns.modelPath != ''">
model_path = #{autoMlIns.modelPath},
</if>
<if test="autoMlIns.imgPath != null and autoMlIns.imgPath != ''">
img_path = #{autoMlIns.imgPath},
</if>
<if test="autoMlIns.status != null and autoMlIns.status != ''">
status = #{autoMlIns.status},
</if>
<if test="autoMlIns.nodeStatus != null and autoMlIns.nodeStatus != ''">
node_status = #{autoMlIns.nodeStatus},
</if>
<if test="autoMlIns.nodeResult != null and autoMlIns.nodeResult != ''">
node_result = #{autoMlIns.nodeResult},
</if>
<if test="autoMlIns.state != null">
state = #{autoMlIns.state},
</if>
</set>
</update>

<select id="count" resultType="java.lang.Long">
select count(1)
from auto_ml_ins
<where>
state = 1
<if test="autoMlIns.autoMlId != null">
and auto_ml_id = #{autoMlIns.autoMlId}
</if>
</where>
</select>

<select id="queryAllByLimit" resultType="com.ruoyi.platform.domain.AutoMlIns">
select * from auto_ml_ins
<where>
state = 1
<if test="autoMlIns.autoMlId != null">
and auto_ml_id = #{autoMlIns.autoMlId}
</if>
</where>
order by update_time DESC
limit #{pageable.offset}, #{pageable.pageSize}
</select>

<select id="queryById" resultType="com.ruoyi.platform.domain.AutoMlIns">
select * from auto_ml_ins
<where>
state = 1 and id = #{id}
</where>
</select>
</mapper>

Loading…
Cancel
Save