Browse Source

update pom version

dev-restore_mount
fanshuai 1 year ago
parent
commit
c3723ee716
9 changed files with 238 additions and 56 deletions
  1. +11
    -4
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/dataset/NewDatasetFromGitController.java
  2. +7
    -7
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/jupyter/JupyterController.java
  3. +4
    -2
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/DatasetService.java
  4. +88
    -31
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/DatasetServiceImpl.java
  5. +1
    -1
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/ConvertUtil.java
  6. +70
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/DVCUtils.java
  7. +12
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/FileUtil.java
  8. +17
    -2
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/YamlUtils.java
  9. +28
    -9
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/NewDatasetVo.java

+ 11
- 4
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/dataset/NewDatasetFromGitController.java View File

@@ -4,6 +4,7 @@ import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.platform.domain.Dataset; import com.ruoyi.platform.domain.Dataset;
import com.ruoyi.platform.service.DatasetService; import com.ruoyi.platform.service.DatasetService;
import com.ruoyi.platform.vo.DatasetVo; import com.ruoyi.platform.vo.DatasetVo;
import com.ruoyi.platform.vo.NewDatasetVo;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.core.io.InputStreamResource; import org.springframework.core.io.InputStreamResource;
@@ -33,7 +34,7 @@ public class NewDatasetFromGitController {
*/ */
@PostMapping("/addDatasetAndVersion") @PostMapping("/addDatasetAndVersion")
@ApiOperation("添加数据集和版本") @ApiOperation("添加数据集和版本")
public AjaxResult addDatasetAndVersion(@RequestBody DatasetVo datasetVo) throws Exception {
public AjaxResult addDatasetAndVersion(@RequestBody NewDatasetVo datasetVo) throws Exception {
return AjaxResult.success(this.datasetService.newCreateDataset(datasetVo)); return AjaxResult.success(this.datasetService.newCreateDataset(datasetVo));


} }
@@ -47,7 +48,7 @@ public class NewDatasetFromGitController {
*/ */
@PostMapping("/addVersion") @PostMapping("/addVersion")
@ApiOperation("添加版本") @ApiOperation("添加版本")
public AjaxResult addVersion(@RequestBody DatasetVo datasetVo) throws Exception {
public AjaxResult addVersion(@RequestBody NewDatasetVo datasetVo) throws Exception {
return AjaxResult.success(this.datasetService.newCreateVersion(datasetVo)); return AjaxResult.success(this.datasetService.newCreateVersion(datasetVo));


} }
@@ -107,9 +108,15 @@ public class NewDatasetFromGitController {
} }
} }


@GetMapping("/getVersionList")
@ApiOperation(value = "获取分支列表")
public AjaxResult getVersionList(@RequestParam("name") String name,@RequestParam("repo_id") Integer repoId,@RequestParam("version")String version) throws Exception {
return AjaxResult.success(this.datasetService.getNewDatasetDesc(repoId,name,version));
}

@GetMapping("/getdatasetDetail") @GetMapping("/getdatasetDetail")
@ApiOperation(value = "获取数据集详情") @ApiOperation(value = "获取数据集详情")
public AjaxResult getDatasetVersions(@PathVariable("datasetId") Integer datasetId) throws Exception {
return AjaxResult.success(this.datasetService.getDatasetVersions(datasetId));
public AjaxResult getDatasetVersions(@RequestParam("name") String name,@RequestParam("repo_id") Integer repoId,@RequestParam("version")String version) throws Exception {
return AjaxResult.success(this.datasetService.getNewDatasetDesc(repoId,name,version));
} }
} }

+ 7
- 7
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/jupyter/JupyterController.java View File

@@ -6,10 +6,7 @@ import com.ruoyi.common.core.web.domain.GenericsAjaxResult;
import com.ruoyi.platform.domain.DevEnvironment; import com.ruoyi.platform.domain.DevEnvironment;
import com.ruoyi.platform.service.DatasetService; import com.ruoyi.platform.service.DatasetService;
import com.ruoyi.platform.service.JupyterService; import com.ruoyi.platform.service.JupyterService;
import com.ruoyi.platform.vo.DatasetVo;
import com.ruoyi.platform.vo.FrameLogPathVo;
import com.ruoyi.platform.vo.PodStatusVo;
import com.ruoyi.platform.vo.VersionVo;
import com.ruoyi.platform.vo.*;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponse;
@@ -89,16 +86,19 @@ public class JupyterController extends BaseController {


@GetMapping(value = "/testdvc") @GetMapping(value = "/testdvc")
public AjaxResult testdvc() throws Exception { public AjaxResult testdvc() throws Exception {
DatasetVo datasetVo = new DatasetVo();
datasetVo.setName("testdassad23");
NewDatasetVo datasetVo = new NewDatasetVo();
datasetVo.setName("testdvc90412");
datasetVo.setDescription("sss"); datasetVo.setDescription("sss");
datasetVo.setAvailableRange(0);
datasetVo.setIsPublic(false);
datasetVo.setDataTag("计算机视觉"); datasetVo.setDataTag("计算机视觉");
datasetVo.setDataType("机器翻译"); datasetVo.setDataType("机器翻译");
datasetVo.setVersion("dev"); datasetVo.setVersion("dev");
List<VersionVo> datasetVersionVos = new ArrayList<>(); List<VersionVo> datasetVersionVos = new ArrayList<>();
VersionVo versionVo = new VersionVo(); VersionVo versionVo = new VersionVo();
versionVo.setUrl("E:/test/bb/data/xssa.doc"); versionVo.setUrl("E:/test/bb/data/xssa.doc");
datasetVo.setDescription("this is a test");
datasetVo.setProcessingCode("python code");
datasetVo.setVersionDesc("this is a test");
datasetVersionVos.add(versionVo); datasetVersionVos.add(versionVo);
datasetVo.setDatasetVersionVos(datasetVersionVos); datasetVo.setDatasetVersionVos(datasetVersionVos);
return AjaxResult.success(datasetService.newCreateDataset(datasetVo)); return AjaxResult.success(datasetService.newCreateDataset(datasetVo));


+ 4
- 2
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/DatasetService.java View File

@@ -92,8 +92,8 @@ DatasetService {






CompletableFuture<String> newCreateDataset(DatasetVo datasetVo) throws Exception;
CompletableFuture<String> newCreateVersion(DatasetVo datasetVo);
CompletableFuture<String> newCreateDataset(NewDatasetVo datasetVo) throws Exception;
CompletableFuture<String> newCreateVersion(NewDatasetVo datasetVo);






@@ -102,4 +102,6 @@ DatasetService {
ResponseEntity<InputStreamResource> downloadAllDatasetFilesNew(String repositoryName, String version) throws IOException, Exception; ResponseEntity<InputStreamResource> downloadAllDatasetFilesNew(String repositoryName, String version) throws IOException, Exception;
Page<NewDatasetVo> newPersonalQueryByPage(Dataset dataset, PageRequest pageRequest) throws Exception; Page<NewDatasetVo> newPersonalQueryByPage(Dataset dataset, PageRequest pageRequest) throws Exception;
Page<NewDatasetVo> newPubilcQueryByPage(Dataset dataset, PageRequest pageRequest) throws Exception; Page<NewDatasetVo> newPubilcQueryByPage(Dataset dataset, PageRequest pageRequest) throws Exception;

NewDatasetVo getNewDatasetDesc(Integer repoId,String RepositoryName, String version);
} }

+ 88
- 31
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/DatasetServiceImpl.java View File

@@ -91,6 +91,8 @@ public class DatasetServiceImpl implements DatasetService {
String endpoint; String endpoint;
@Value("${git.endpoint}") @Value("${git.endpoint}")
String gitendpoint; String gitendpoint;
@Value("${git.localPath}")
String localPathlocal;


/** /**
* 通过ID查询单条数据 * 通过ID查询单条数据
@@ -459,11 +461,14 @@ public class DatasetServiceImpl implements DatasetService {




@Override @Override
public CompletableFuture<String> newCreateDataset(DatasetVo datasetVo) {
public CompletableFuture<String> newCreateDataset(NewDatasetVo datasetVo) {
return CompletableFuture.supplyAsync(() -> { return CompletableFuture.supplyAsync(() -> {
try { try {
String token = gitService.login("fanshuai", "h1n2x3j4y5@");
LoginUser loginUser = SecurityUtils.getLoginUser(); LoginUser loginUser = SecurityUtils.getLoginUser();
String gitLinkUsername = loginUser.getSysUser().getGitLinkUsername();
String gitLinkPassword = loginUser.getSysUser().getGitLinkPassword();
String token = gitService.login(gitLinkUsername, gitLinkPassword);

String ci4sUsername = loginUser.getUsername(); String ci4sUsername = loginUser.getUsername();
Jedis jedis = new Jedis(redisHost); Jedis jedis = new Jedis(redisHost);
String userReq = jedis.get(ci4sUsername + "_gitUserInfo"); String userReq = jedis.get(ci4sUsername + "_gitUserInfo");
@@ -475,34 +480,41 @@ public class DatasetServiceImpl implements DatasetService {
gitProjectVo.setRepositoryName(repositoryName); gitProjectVo.setRepositoryName(repositoryName);
gitProjectVo.setName(datasetVo.getName()); gitProjectVo.setName(datasetVo.getName());
gitProjectVo.setDescription(datasetVo.getDescription()); gitProjectVo.setDescription(datasetVo.getDescription());
gitProjectVo.setPrivate(datasetVo.getAvailableRange() == 0);
gitProjectVo.setPrivate(!datasetVo.getIsPublic());
gitProjectVo.setUserId(userId); gitProjectVo.setUserId(userId);
// 创建项目 // 创建项目
Map project = gitService.createProject(token, gitProjectVo); Map project = gitService.createProject(token, gitProjectVo);
Integer repoId = (Integer) project.get("id");
// 创建分支 // 创建分支
String branchName = datasetVo.getVersion(); String branchName = datasetVo.getVersion();
gitService.createBranch(token, (String) userInfo.get("login"), repositoryName, branchName, "master"); gitService.createBranch(token, (String) userInfo.get("login"), repositoryName, branchName, "master");
// 定义标签 标签1:ci4s_dataset 标签2:DataTag 标签3:DataType // 定义标签 标签1:ci4s_dataset 标签2:DataTag 标签3:DataType
gitService.createTopic(token, (Integer) project.get("id"), "ci4s_dataset");
gitService.createTopic(token, (Integer) project.get("id"), "DataTag_" + datasetVo.getDataTag());
gitService.createTopic(token, (Integer) project.get("id"), "DataType_" + datasetVo.getDataType());
gitService.createTopic(token, repoId, "ci4s_dataset");
gitService.createTopic(token, repoId, "DataTag_" + datasetVo.getDataTag());
gitService.createTopic(token, repoId, "DataType_" + datasetVo.getDataType());
// 得到项目地址 // 得到项目地址
String projectUrl = gitendpoint + "/" +(String) userInfo.get("login") + "/" + repositoryName + ".git"; String projectUrl = gitendpoint + "/" +(String) userInfo.get("login") + "/" + repositoryName + ".git";


// 得到用户操作的路径 // 得到用户操作的路径
String url = datasetVo.getDatasetVersionVos().get(0).getUrl(); String url = datasetVo.getDatasetVersionVos().get(0).getUrl();
String localPath = "E:/test/" + datasetVo.getName();
String localPath = localPathlocal + "/" + repoId+"/"+datasetVo.getName();
String sourcePath = url.substring(0, url.lastIndexOf("/")); String sourcePath = url.substring(0, url.lastIndexOf("/"));
// 命令行操作 git clone 项目地址 // 命令行操作 git clone 项目地址
DVCUtils.gitClone(localPath, projectUrl, branchName, "fanshuai", "h1n2x3j4y5@");
String s3Path = "management-platform-files/" + ci4sUsername + "/datasets/" + repositoryName + "/" + branchName;
//拼接生产的元数据后写入yaml文件
YamlUtils.generateYamlFile(JsonUtils.objectToMap(datasetVo),sourcePath, "dataset");
DVCUtils.gitClone(localPath, projectUrl, branchName, gitLinkUsername, gitLinkPassword);
String s3Path = "management-platform-files/" + ci4sUsername + "/datasets/"+repoId+"/"+ repositoryName + "/" + branchName;


DVCUtils.moveFiles(sourcePath, localPath); DVCUtils.moveFiles(sourcePath, localPath);



//拼接生产的元数据后写入yaml文件
datasetVo.setCreateBy(String.valueOf(StringUtils.isNotEmpty((String)userInfo.get("nickname"))? userInfo.get("nickname") : userInfo.get("login")));
datasetVo.setUpdateTime(DateUtils.getTime());
datasetVo.setVersionDesc(datasetVo.getDescription());
datasetVo.setUsage("```bash\n" +
"# 克隆数据集配置文件与存储参数到本地\n" +
"git clone -b " + branchName + " " + projectUrl + "\n" +
"# 远程拉取配置文件\n" +
"dvc pull\n" +
"```");
YamlUtils.generateYamlFile(JsonUtils.objectToMap(datasetVo),localPath, "dataset");
// dvc init 初始化 // dvc init 初始化
DVCUtils.dvcInit(localPath); DVCUtils.dvcInit(localPath);
// 配置远程S3地址 // 配置远程S3地址
@@ -515,7 +527,7 @@ public class DatasetServiceImpl implements DatasetService {
// git commit // git commit
DVCUtils.gitAdd(localPath, "."); DVCUtils.gitAdd(localPath, ".");
DVCUtils.gitCommit(localPath, "commit from ci4s with " + loginUser.getUsername()); DVCUtils.gitCommit(localPath, "commit from ci4s with " + loginUser.getUsername());
DVCUtils.gitPush(localPath, "fanshuai", "h1n2x3j4y5@");
DVCUtils.gitPush(localPath, gitLinkUsername, gitLinkPassword);
// dvc push 到远程S3 // dvc push 到远程S3
DVCUtils.dvcPush(localPath); DVCUtils.dvcPush(localPath);
return "新增数据集成功"; return "新增数据集成功";
@@ -526,18 +538,20 @@ public class DatasetServiceImpl implements DatasetService {
} }


@Override @Override
public CompletableFuture<String> newCreateVersion(DatasetVo datasetVo) {
public CompletableFuture<String> newCreateVersion(NewDatasetVo datasetVo) {
return CompletableFuture.supplyAsync(() -> { return CompletableFuture.supplyAsync(() -> {
try { try {
String token = gitService.login("fanshuai", "h1n2x3j4y5@");
LoginUser loginUser = SecurityUtils.getLoginUser(); LoginUser loginUser = SecurityUtils.getLoginUser();
String gitLinkUsername = loginUser.getSysUser().getGitLinkUsername();
String gitLinkPassword = loginUser.getSysUser().getGitLinkPassword();
String token = gitService.login(gitLinkUsername, gitLinkPassword);
String ci4sUsername = loginUser.getUsername(); String ci4sUsername = loginUser.getUsername();
Jedis jedis = new Jedis(redisHost); Jedis jedis = new Jedis(redisHost);
String userReq = jedis.get(ci4sUsername + "_gitUserInfo"); String userReq = jedis.get(ci4sUsername + "_gitUserInfo");
Map<String, Object> userInfo = JsonUtils.jsonToMap(userReq); Map<String, Object> userInfo = JsonUtils.jsonToMap(userReq);
// 创建分支 // 创建分支
String branchName = StringUtils.isEmpty(datasetVo.getVersion())? "master" : datasetVo.getVersion(); String branchName = StringUtils.isEmpty(datasetVo.getVersion())? "master" : datasetVo.getVersion();
String repositoryName = datasetVo.getRepositoryName();
String repositoryName = datasetVo.getIdentifier();
if (StringUtils.equals(branchName, "master")) { if (StringUtils.equals(branchName, "master")) {
gitService.createBranch(token, (String) userInfo.get("login"), repositoryName, branchName, "master"); gitService.createBranch(token, (String) userInfo.get("login"), repositoryName, branchName, "master");
} }
@@ -546,15 +560,31 @@ public class DatasetServiceImpl implements DatasetService {


// 得到用户操作的路径 // 得到用户操作的路径
String url = datasetVo.getDatasetVersionVos().get(0).getUrl(); String url = datasetVo.getDatasetVersionVos().get(0).getUrl();
String localPath = "E:/test/"+ loginUser.getUsername()+"/datasets/"+ datasetVo.getName();
String localPath = localPathlocal+ loginUser.getUsername()+"/datasets/"+ datasetVo.getName();
String sourcePath = url.substring(0, url.lastIndexOf("/")); String sourcePath = url.substring(0, url.lastIndexOf("/"));
// 命令行操作 git clone 项目地址 // 命令行操作 git clone 项目地址
DVCUtils.gitClone(localPath, projectUrl, branchName, "fanshuai", "h1n2x3j4y5@");
String s3Path = "management-platform-files/" + ci4sUsername + "/datasets/" + repositoryName + "/" + branchName;
//拼接生产的元数据后写入yaml文件
YamlUtils.generateYamlFile(JsonUtils.objectToMap(datasetVo),sourcePath, "dataset");
if(FileUtil.checkDirectoryExists(localPath)){
DVCUtils.gitFetch(localPath);
DVCUtils.gitCheckoutBranch(localPath,branchName);
}else {
DVCUtils.gitClone(localPath, projectUrl, branchName, gitLinkUsername, gitLinkPassword);
}

String s3Path = "management-platform-files/" + ci4sUsername + "/datasets/"+ datasetVo.getRepoId()+"/"+ repositoryName + "/" + branchName;


DVCUtils.moveFiles(sourcePath, localPath); DVCUtils.moveFiles(sourcePath, localPath);
//拼接生产的元数据后写入yaml文件
datasetVo.setCreateBy(String.valueOf(StringUtils.isNotEmpty((String)userInfo.get("nickname"))? userInfo.get("nickname") : userInfo.get("login")));
datasetVo.setUpdateTime(DateUtils.getTime());
datasetVo.setVersionDesc(datasetVo.getDescription());
datasetVo.setUsage("```bash\n" +
"# 克隆数据集配置文件与存储参数到本地\n" +
"git clone -b " + branchName + " " + projectUrl + "\n" +
"# 远程拉取配置文件\n" +
"dvc pull\n" +
"```");
YamlUtils.generateYamlFile(JsonUtils.objectToMap(datasetVo),localPath, "dataset");

// dvc init 初始化 // dvc init 初始化
DVCUtils.dvcInit(localPath); DVCUtils.dvcInit(localPath);
// 配置远程S3地址 // 配置远程S3地址
@@ -567,7 +597,7 @@ public class DatasetServiceImpl implements DatasetService {
// git commit // git commit
DVCUtils.gitAdd(localPath, "."); DVCUtils.gitAdd(localPath, ".");
DVCUtils.gitCommit(localPath, "commit from ci4s with " + loginUser.getUsername()); DVCUtils.gitCommit(localPath, "commit from ci4s with " + loginUser.getUsername());
DVCUtils.gitPush(localPath, "fanshuai", "h1n2x3j4y5@");
DVCUtils.gitPush(localPath, gitLinkUsername, gitLinkPassword);
// dvc push 到远程S3 // dvc push 到远程S3
DVCUtils.dvcPush(localPath); DVCUtils.dvcPush(localPath);
return "新增数据集成功"; return "新增数据集成功";
@@ -581,7 +611,9 @@ public class DatasetServiceImpl implements DatasetService {
@Override @Override
public Page<NewDatasetVo> newPersonalQueryByPage(Dataset dataset, PageRequest pageRequest) throws Exception { public Page<NewDatasetVo> newPersonalQueryByPage(Dataset dataset, PageRequest pageRequest) throws Exception {
LoginUser loginUser = SecurityUtils.getLoginUser(); LoginUser loginUser = SecurityUtils.getLoginUser();
String token = gitService.login("fanshuai", "h1n2x3j4y5@");
String gitLinkUsername = loginUser.getSysUser().getGitLinkUsername();
String gitLinkPassword = loginUser.getSysUser().getGitLinkPassword();
String token = gitService.login(gitLinkUsername, gitLinkPassword);
String ci4sUsername = loginUser.getUsername(); String ci4sUsername = loginUser.getUsername();
Jedis jedis = new Jedis(redisHost); Jedis jedis = new Jedis(redisHost);
String userReq = jedis.get(ci4sUsername + "_gitUserInfo"); String userReq = jedis.get(ci4sUsername + "_gitUserInfo");
@@ -602,9 +634,10 @@ public class DatasetServiceImpl implements DatasetService {


@Override @Override
public Page<NewDatasetVo> newPubilcQueryByPage(Dataset dataset, PageRequest pageRequest) throws Exception { public Page<NewDatasetVo> newPubilcQueryByPage(Dataset dataset, PageRequest pageRequest) throws Exception {

LoginUser loginUser = SecurityUtils.getLoginUser(); LoginUser loginUser = SecurityUtils.getLoginUser();
String token = gitService.login("fanshuai", "h1n2x3j4y5@");
String gitLinkUsername = loginUser.getSysUser().getGitLinkUsername();
String gitLinkPassword = loginUser.getSysUser().getGitLinkPassword();
String token = gitService.login(gitLinkUsername, gitLinkPassword);
String ci4sUsername = loginUser.getUsername(); String ci4sUsername = loginUser.getUsername();
Jedis jedis = new Jedis(redisHost); Jedis jedis = new Jedis(redisHost);
String userReq = jedis.get(ci4sUsername + "_gitUserInfo"); String userReq = jedis.get(ci4sUsername + "_gitUserInfo");
@@ -626,6 +659,28 @@ public class DatasetServiceImpl implements DatasetService {


} }


@Override
public NewDatasetVo getNewDatasetDesc(Integer repoId,String repositoryName, String version) {
// cd到 localPathlocal/repoId/下面还有一个文件夹,然后做git pull操作,然后读取里面的文件列表,列出每个文件的大小和名称,封装成MAP
List<Map<String, Object>> fileDetailsAfterGitPull = DVCUtils.getFileDetailsAfterGitPull(localPathlocal+repoId, repositoryName, version);
//在localPathlocal+repoId+"/"+repositoryName目录下的dataset.yaml中取到元数据
Map<String, Object> stringObjectMap = YamlUtils.loadYamlFile(localPathlocal + repoId + "/" + repositoryName + "/dataset.yaml");
NewDatasetVo newDatasetVo = ConvertUtil.convertMapToObject(stringObjectMap, NewDatasetVo.class);
List<VersionVo> versionVos = new ArrayList<VersionVo>();
if (fileDetailsAfterGitPull!=null&&fileDetailsAfterGitPull.size()>0){
for(Map<String, Object> fileDetail : fileDetailsAfterGitPull){
VersionVo versionVo = new VersionVo();
versionVo.setUrl((String) fileDetail.get("filePath"));
versionVo.setFileName((String) fileDetail.get("fileName"));
long size = (long) fileDetail.get("size");
versionVo.setFileSize(FileUtil.formatFileSize(size));
versionVos.add(versionVo);
}
}
newDatasetVo.setDatasetVersionVos(versionVos);
return newDatasetVo;
}

@Override @Override
public List<Map<String, String>> uploadDatasetlocal(MultipartFile[] files, String uuid) throws Exception { public List<Map<String, String>> uploadDatasetlocal(MultipartFile[] files, String uuid) throws Exception {
List<Map<String, String>> results = new ArrayList<>(); List<Map<String, String>> results = new ArrayList<>();
@@ -657,24 +712,26 @@ public class DatasetServiceImpl implements DatasetService {
public ResponseEntity<InputStreamResource> downloadAllDatasetFilesNew(String repositoryName, String version) throws Exception { public ResponseEntity<InputStreamResource> downloadAllDatasetFilesNew(String repositoryName, String version) throws Exception {
// 命令行操作 git clone 项目地址 // 命令行操作 git clone 项目地址
LoginUser loginUser = SecurityUtils.getLoginUser(); LoginUser loginUser = SecurityUtils.getLoginUser();
String token = gitService.login("fanshuai", "h1n2x3j4y5@");
String gitLinkUsername = loginUser.getSysUser().getGitLinkUsername();
String gitLinkPassword = loginUser.getSysUser().getGitLinkPassword();
String token = gitService.login(gitLinkUsername, gitLinkPassword);
String ci4sUsername = loginUser.getUsername(); String ci4sUsername = loginUser.getUsername();
Jedis jedis = new Jedis(redisHost); Jedis jedis = new Jedis(redisHost);
String userReq = jedis.get(ci4sUsername + "_gitUserInfo"); String userReq = jedis.get(ci4sUsername + "_gitUserInfo");
Map<String, Object> userInfo = JsonUtils.jsonToMap(userReq); Map<String, Object> userInfo = JsonUtils.jsonToMap(userReq);
Integer userId = (Integer) userInfo.get("user_id"); Integer userId = (Integer) userInfo.get("user_id");
String projectUrl = gitendpoint + "/" +(String) userInfo.get("login") + "/" + repositoryName + ".git"; String projectUrl = gitendpoint + "/" +(String) userInfo.get("login") + "/" + repositoryName + ".git";
String localPath = "E:/test/"+ loginUser.getUsername()+"/datasets/" +repositoryName;
String localPath = localPathlocal+ loginUser.getUsername()+"/datasets/" +repositoryName;
File folder = new File(localPath); File folder = new File(localPath);
if(folder.exists() && folder.isDirectory()){ if(folder.exists() && folder.isDirectory()){
//切换分支 //切换分支
DVCUtils.gitCheckoutBranch(localPath, version); DVCUtils.gitCheckoutBranch(localPath, version);
//pull //pull
DVCUtils.gitPull(localPath,"fanshuai", "h1n2x3j4y5@");
DVCUtils.gitPull(localPath,gitLinkUsername, gitLinkPassword);
//dvc pull //dvc pull
DVCUtils.dvcPull(localPath); DVCUtils.dvcPull(localPath);
}else { }else {
DVCUtils.gitClone(localPath, projectUrl, version, "fanshuai", "h1n2x3j4y5@");
DVCUtils.gitClone(localPath, projectUrl, version, gitLinkUsername, gitLinkPassword);
} }


// 打包 data 文件夹 // 打包 data 文件夹


+ 1
- 1
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/ConvertUtil.java View File

@@ -78,7 +78,7 @@ public class ConvertUtil {
return resultList; return resultList;
} }


private static <T> T convertMapToObject(Map<String, Object> map, Class<T> targetClass) {
public static <T> T convertMapToObject(Map<String, Object> map, Class<T> targetClass) {
try { try {
T targetObject = targetClass.newInstance(); T targetObject = targetClass.newInstance();
for (Map.Entry<String, Object> entry : map.entrySet()) { for (Map.Entry<String, Object> entry : map.entrySet()) {


+ 70
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/DVCUtils.java View File

@@ -9,6 +9,10 @@ import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;


import java.io.*; import java.io.*;
import java.nio.file.*; import java.nio.file.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class DVCUtils { public class DVCUtils {


@@ -95,6 +99,16 @@ public class DVCUtils {
} }
} }


public static void gitFetch(String localPath) {
try {
ProcessBuilder pb = new ProcessBuilder("git", "fetch");
pb.directory(new File(localPath));
Process process = pb.start();
process.waitFor();
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
public static void gitCheckoutBranch(String localPath, String branchName) throws IOException, GitAPIException { public static void gitCheckoutBranch(String localPath, String branchName) throws IOException, GitAPIException {
FileRepositoryBuilder builder = new FileRepositoryBuilder(); FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repository = builder.setGitDir(new File(localPath, ".git")) Repository repository = builder.setGitDir(new File(localPath, ".git"))
@@ -162,4 +176,60 @@ public class DVCUtils {
String command = "dvc pull"; String command = "dvc pull";
runCommand(command, localPath); runCommand(command, localPath);
} }


/**
* 切换到指定分支并执行git pull,然后获取data文件夹下所有文件的路径、名称和大小
*
* @param localPath 本地路径
* @param repoFolder 仓库文件夹名称
* @param branch 分支名称
* @return 包含文件路径、名称和大小的List<Map<String, Object>>
*/
public static List<Map<String, Object>> getFileDetailsAfterGitPull(String localPath, String repoFolder, String branch) {
List<Map<String, Object>> fileInfoList = new ArrayList<>();

try {
// 切换到指定目录
Path repoPath = Paths.get(localPath, repoFolder);

// 切换到指定分支
ProcessBuilder pb = new ProcessBuilder("git", "checkout", branch);
pb.directory(repoPath.toFile());
Process process = pb.start();
process.waitFor();

// 执行git pull
pb = new ProcessBuilder("git", "pull");
pb.directory(repoPath.toFile());
process = pb.start();
process.waitFor();

// 读取data文件夹中的文件列表
Path dataPath = Paths.get(repoPath.toString(), "data");
File[] files = dataPath.toFile().listFiles();

if (files != null) {
for (File file : files) {
if (file.isFile()) {
long size = Files.size(file.toPath());
String filePath = file.getAbsolutePath();
String fileName = file.getName();

Map<String, Object> fileDetails = new HashMap<>();
fileDetails.put("size", size);
fileDetails.put("filePath", filePath);
fileDetails.put("fileName", fileName);

fileInfoList.add(fileDetails);
}
}
}

} catch (IOException | InterruptedException e) {
e.printStackTrace();
}

return fileInfoList;
}
} }

+ 12
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/FileUtil.java View File

@@ -1,5 +1,7 @@
package com.ruoyi.platform.utils; package com.ruoyi.platform.utils;


import java.io.File;

public class FileUtil { public class FileUtil {


// 格式化文件大小为可读的字符串表示 // 格式化文件大小为可读的字符串表示
@@ -30,6 +32,16 @@ public class FileUtil {
} }
} }


/**
* 检查指定路径的文件夹是否存在
*
* @param localPath 本地路径
* @return 如果文件夹存在返回true,否则返回false
*/
public static boolean checkDirectoryExists(String localPath) {
File directory = new File(localPath);
return directory.exists() && directory.isDirectory();
}








+ 17
- 2
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/YamlUtils.java View File

@@ -2,8 +2,7 @@ package com.ruoyi.platform.utils;


import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.Yaml;


import java.io.FileWriter;
import java.io.IOException;
import java.io.*;
import java.util.Map; import java.util.Map;


public class YamlUtils { public class YamlUtils {
@@ -25,4 +24,20 @@ public class YamlUtils {
e.printStackTrace(); e.printStackTrace();
} }
} }

/**
* 读取YAML文件并将其内容转换为Map<String, Object>
*
* @param filePath YAML文件路径
* @return 包含YAML内容的Map<String, Object>
*/
public static Map<String, Object> loadYamlFile(String filePath) {
Yaml yaml = new Yaml();
try (InputStream inputStream = new FileInputStream(new File(filePath))) {
return yaml.load(inputStream);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
} }

+ 28
- 9
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/NewDatasetVo.java View File

@@ -6,6 +6,8 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;


import java.io.Serializable; import java.io.Serializable;
import java.util.Date;
import java.util.List;


@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
@Data @Data
@@ -17,25 +19,42 @@ public class NewDatasetVo implements Serializable {
/** /**
* 数据集仓库名称 * 数据集仓库名称
*/ */
@ApiModelProperty(name = "identifier")
@ApiModelProperty(name = "identifier", value = "数据集仓库名称")
private String identifier; private String identifier;
@ApiModelProperty(name = "description")
@ApiModelProperty(name = "description",value = "数据集描述")
private String description; private String description;
/** /**
* 是否公开1公开,0私有 * 是否公开1公开,0私有
*/ */
@ApiModelProperty(name = "is_public")
@ApiModelProperty(name = "is_public", value = "是否公开1公开,0私有")
private Boolean isPublic; private Boolean isPublic;
@ApiModelProperty(name = "data_type")
@ApiModelProperty(name = "data_type",value = "数据集类型")
private String dataType; private String dataType;
@ApiModelProperty(name = "data_tag")
@ApiModelProperty(name = "data_tag",value = "数据集标签")
private String dataTag; private String dataTag;
@ApiModelProperty(name = "time_ago")
/**
* 版本
*/
@ApiModelProperty(name = "version",value = "版本")
private String version;
@ApiModelProperty(name = "dataset_version_vos",value = "文件列表")
private List<VersionVo> datasetVersionVos;

@ApiModelProperty(name = "time_ago",value = "更新时间")
private String timeAgo; private String timeAgo;
@ApiModelProperty(name = "repo_id")
@ApiModelProperty(name = "repo_id",value = "数据集仓库id")
private Integer repoId; private Integer repoId;
@ApiModelProperty(name = "visits")
@ApiModelProperty(name = "visits",value = "访问次数")
private Integer visits; private Integer visits;
@ApiModelProperty(name = "create_by")
@ApiModelProperty(name = "create_by",value = "创建者")
private String createBy; private String createBy;
@ApiModelProperty(name = "version_desc",value = "版本描述")
private String versionDesc;
@ApiModelProperty(name = "usage",value = "使用示例")
private String usage;
@ApiModelProperty(name = "update_time",value = "更新时间")
private String updateTime;
@ApiModelProperty(name = "processing_code",value = "处理代码")
private String processingCode;

} }

Loading…
Cancel
Save