|
|
|
@@ -91,6 +91,8 @@ public class DatasetServiceImpl implements DatasetService { |
|
|
|
String endpoint; |
|
|
|
@Value("${git.endpoint}") |
|
|
|
String gitendpoint; |
|
|
|
@Value("${git.localPath}") |
|
|
|
String localPathlocal; |
|
|
|
|
|
|
|
/** |
|
|
|
* 通过ID查询单条数据 |
|
|
|
@@ -459,11 +461,14 @@ public class DatasetServiceImpl implements DatasetService { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public CompletableFuture<String> newCreateDataset(DatasetVo datasetVo) { |
|
|
|
public CompletableFuture<String> newCreateDataset(NewDatasetVo datasetVo) { |
|
|
|
return CompletableFuture.supplyAsync(() -> { |
|
|
|
try { |
|
|
|
String token = gitService.login("fanshuai", "h1n2x3j4y5@"); |
|
|
|
LoginUser loginUser = SecurityUtils.getLoginUser(); |
|
|
|
String gitLinkUsername = loginUser.getSysUser().getGitLinkUsername(); |
|
|
|
String gitLinkPassword = loginUser.getSysUser().getGitLinkPassword(); |
|
|
|
String token = gitService.login(gitLinkUsername, gitLinkPassword); |
|
|
|
|
|
|
|
String ci4sUsername = loginUser.getUsername(); |
|
|
|
Jedis jedis = new Jedis(redisHost); |
|
|
|
String userReq = jedis.get(ci4sUsername + "_gitUserInfo"); |
|
|
|
@@ -475,34 +480,41 @@ public class DatasetServiceImpl implements DatasetService { |
|
|
|
gitProjectVo.setRepositoryName(repositoryName); |
|
|
|
gitProjectVo.setName(datasetVo.getName()); |
|
|
|
gitProjectVo.setDescription(datasetVo.getDescription()); |
|
|
|
gitProjectVo.setPrivate(datasetVo.getAvailableRange() == 0); |
|
|
|
gitProjectVo.setPrivate(!datasetVo.getIsPublic()); |
|
|
|
gitProjectVo.setUserId(userId); |
|
|
|
// 创建项目 |
|
|
|
Map project = gitService.createProject(token, gitProjectVo); |
|
|
|
Integer repoId = (Integer) project.get("id"); |
|
|
|
// 创建分支 |
|
|
|
String branchName = datasetVo.getVersion(); |
|
|
|
gitService.createBranch(token, (String) userInfo.get("login"), repositoryName, branchName, "master"); |
|
|
|
// 定义标签 标签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 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("/")); |
|
|
|
// 命令行操作 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); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//拼接生产的元数据后写入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 初始化 |
|
|
|
DVCUtils.dvcInit(localPath); |
|
|
|
// 配置远程S3地址 |
|
|
|
@@ -515,7 +527,7 @@ public class DatasetServiceImpl implements DatasetService { |
|
|
|
// git commit |
|
|
|
DVCUtils.gitAdd(localPath, "."); |
|
|
|
DVCUtils.gitCommit(localPath, "commit from ci4s with " + loginUser.getUsername()); |
|
|
|
DVCUtils.gitPush(localPath, "fanshuai", "h1n2x3j4y5@"); |
|
|
|
DVCUtils.gitPush(localPath, gitLinkUsername, gitLinkPassword); |
|
|
|
// dvc push 到远程S3 |
|
|
|
DVCUtils.dvcPush(localPath); |
|
|
|
return "新增数据集成功"; |
|
|
|
@@ -526,18 +538,20 @@ public class DatasetServiceImpl implements DatasetService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public CompletableFuture<String> newCreateVersion(DatasetVo datasetVo) { |
|
|
|
public CompletableFuture<String> newCreateVersion(NewDatasetVo datasetVo) { |
|
|
|
return CompletableFuture.supplyAsync(() -> { |
|
|
|
try { |
|
|
|
String token = gitService.login("fanshuai", "h1n2x3j4y5@"); |
|
|
|
LoginUser loginUser = SecurityUtils.getLoginUser(); |
|
|
|
String gitLinkUsername = loginUser.getSysUser().getGitLinkUsername(); |
|
|
|
String gitLinkPassword = loginUser.getSysUser().getGitLinkPassword(); |
|
|
|
String token = gitService.login(gitLinkUsername, gitLinkPassword); |
|
|
|
String ci4sUsername = loginUser.getUsername(); |
|
|
|
Jedis jedis = new Jedis(redisHost); |
|
|
|
String userReq = jedis.get(ci4sUsername + "_gitUserInfo"); |
|
|
|
Map<String, Object> userInfo = JsonUtils.jsonToMap(userReq); |
|
|
|
// 创建分支 |
|
|
|
String branchName = StringUtils.isEmpty(datasetVo.getVersion())? "master" : datasetVo.getVersion(); |
|
|
|
String repositoryName = datasetVo.getRepositoryName(); |
|
|
|
String repositoryName = datasetVo.getIdentifier(); |
|
|
|
if (StringUtils.equals(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 localPath = "E:/test/"+ loginUser.getUsername()+"/datasets/"+ datasetVo.getName(); |
|
|
|
String localPath = localPathlocal+ loginUser.getUsername()+"/datasets/"+ datasetVo.getName(); |
|
|
|
String sourcePath = url.substring(0, url.lastIndexOf("/")); |
|
|
|
// 命令行操作 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); |
|
|
|
//拼接生产的元数据后写入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 初始化 |
|
|
|
DVCUtils.dvcInit(localPath); |
|
|
|
// 配置远程S3地址 |
|
|
|
@@ -567,7 +597,7 @@ public class DatasetServiceImpl implements DatasetService { |
|
|
|
// git commit |
|
|
|
DVCUtils.gitAdd(localPath, "."); |
|
|
|
DVCUtils.gitCommit(localPath, "commit from ci4s with " + loginUser.getUsername()); |
|
|
|
DVCUtils.gitPush(localPath, "fanshuai", "h1n2x3j4y5@"); |
|
|
|
DVCUtils.gitPush(localPath, gitLinkUsername, gitLinkPassword); |
|
|
|
// dvc push 到远程S3 |
|
|
|
DVCUtils.dvcPush(localPath); |
|
|
|
return "新增数据集成功"; |
|
|
|
@@ -581,7 +611,9 @@ public class DatasetServiceImpl implements DatasetService { |
|
|
|
@Override |
|
|
|
public Page<NewDatasetVo> newPersonalQueryByPage(Dataset dataset, PageRequest pageRequest) throws Exception { |
|
|
|
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(); |
|
|
|
Jedis jedis = new Jedis(redisHost); |
|
|
|
String userReq = jedis.get(ci4sUsername + "_gitUserInfo"); |
|
|
|
@@ -602,9 +634,10 @@ public class DatasetServiceImpl implements DatasetService { |
|
|
|
|
|
|
|
@Override |
|
|
|
public Page<NewDatasetVo> newPubilcQueryByPage(Dataset dataset, PageRequest pageRequest) throws Exception { |
|
|
|
|
|
|
|
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(); |
|
|
|
Jedis jedis = new Jedis(redisHost); |
|
|
|
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 |
|
|
|
public List<Map<String, String>> uploadDatasetlocal(MultipartFile[] files, String uuid) throws Exception { |
|
|
|
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 { |
|
|
|
// 命令行操作 git clone 项目地址 |
|
|
|
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(); |
|
|
|
Jedis jedis = new Jedis(redisHost); |
|
|
|
String userReq = jedis.get(ci4sUsername + "_gitUserInfo"); |
|
|
|
Map<String, Object> userInfo = JsonUtils.jsonToMap(userReq); |
|
|
|
Integer userId = (Integer) userInfo.get("user_id"); |
|
|
|
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); |
|
|
|
if(folder.exists() && folder.isDirectory()){ |
|
|
|
//切换分支 |
|
|
|
DVCUtils.gitCheckoutBranch(localPath, version); |
|
|
|
//pull |
|
|
|
DVCUtils.gitPull(localPath,"fanshuai", "h1n2x3j4y5@"); |
|
|
|
DVCUtils.gitPull(localPath,gitLinkUsername, gitLinkPassword); |
|
|
|
//dvc pull |
|
|
|
DVCUtils.dvcPull(localPath); |
|
|
|
}else { |
|
|
|
DVCUtils.gitClone(localPath, projectUrl, version, "fanshuai", "h1n2x3j4y5@"); |
|
|
|
DVCUtils.gitClone(localPath, projectUrl, version, gitLinkUsername, gitLinkPassword); |
|
|
|
} |
|
|
|
|
|
|
|
// 打包 data 文件夹 |
|
|
|
|