超算接口联调
This commit is contained in:
parent
0dacfe8808
commit
5566b00ea1
|
|
@ -20,6 +20,7 @@ import java.io.IOException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component()
|
||||
@Slf4j
|
||||
|
|
@ -42,10 +43,6 @@ public class AppScheduleTask {
|
|||
}
|
||||
if (source == 1) {
|
||||
startCSAppTask(trainingTask);
|
||||
continue;
|
||||
}
|
||||
if (source == 2) {
|
||||
//TODO
|
||||
}
|
||||
} catch (Exception e) {
|
||||
trainingTask.setStatus(Constant.Failed);
|
||||
|
|
@ -69,9 +66,6 @@ public class AppScheduleTask {
|
|||
if (source == 1) {
|
||||
checkCSAppTaskResult(trainingTask);
|
||||
}
|
||||
if (source == 2) {
|
||||
//TODO
|
||||
}
|
||||
} catch (Exception e) {
|
||||
trainingTask.setStatus(Constant.Failed);
|
||||
trainingTaskDao.update(trainingTask);
|
||||
|
|
@ -147,16 +141,36 @@ public class AppScheduleTask {
|
|||
* @return
|
||||
*/
|
||||
private void startCSAppTask(TrainingTask trainingTask) throws Exception {
|
||||
trainingTask.setStatus("Running");
|
||||
trainingTaskDao.update(trainingTask);
|
||||
|
||||
//异步调用超算任务执行接口
|
||||
JSONObject taskInfo = JSONUtil.parseObj(trainingTask.getTaskInfo());
|
||||
String clusterId = (String) taskInfo.get("type");
|
||||
Integer ntasks = (Integer) taskInfo.get("ntasks");
|
||||
Integer nodes = (Integer) taskInfo.get("nodes");
|
||||
Integer objectId = (Integer) taskInfo.get("input_file");
|
||||
String name = taskInfo.get("name").toString();
|
||||
String taskId = csCollectService.submit(clusterId,name , "fileName", objectId, ntasks, nodes);
|
||||
trainingTask.setTaskId(taskId);
|
||||
trainingTask.setStatus("Running");
|
||||
trainingTaskDao.update(trainingTask);
|
||||
// 异步提交任务
|
||||
CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
return csCollectService.submit(clusterId, name, "fileName", objectId, ntasks, nodes);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("异步提交任务失败", e);
|
||||
}
|
||||
});
|
||||
// 处理异步结果
|
||||
future.thenAcceptAsync(taskId -> {
|
||||
trainingTask.setTaskId(taskId);
|
||||
trainingTaskDao.update(trainingTask);
|
||||
log.info("任务提交成功,taskId: {}", taskId);
|
||||
}).exceptionally(ex -> {
|
||||
log.error("异步处理任务失败", ex);
|
||||
// 这里可以添加失败处理逻辑,比如更新任务状态为失败
|
||||
trainingTask.setStatus("Filed");
|
||||
trainingTaskDao.update(trainingTask);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.ruoyi.platform.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.lang.UUID;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.json.JSONArray;
|
||||
import cn.hutool.json.JSONObject;
|
||||
|
|
@ -15,6 +16,7 @@ import com.ruoyi.platform.mapper.CSServiceDao;
|
|||
import com.ruoyi.platform.mapper.ServiceDao;
|
||||
import com.ruoyi.platform.mapper.TrainingTaskDao;
|
||||
import com.ruoyi.platform.service.CSCollectService;
|
||||
import com.ruoyi.platform.service.MinioService;
|
||||
import com.ruoyi.platform.service.ServiceTempService;
|
||||
import com.ruoyi.platform.service.ServiceVersionService;
|
||||
import com.ruoyi.platform.utils.JacksonUtil;
|
||||
|
|
@ -23,6 +25,7 @@ import com.ruoyi.system.api.model.LoginUser;
|
|||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
|
|
@ -38,6 +41,9 @@ import java.util.stream.Collectors;
|
|||
@Transactional
|
||||
public class CSServiceVersionServiceImpl implements ServiceVersionService {
|
||||
|
||||
@Value("${minio.dataReleaseBucketName}")
|
||||
private String bucketName;
|
||||
|
||||
@Autowired
|
||||
private CSServiceDao csServiceDao;
|
||||
|
||||
|
|
@ -53,6 +59,9 @@ public class CSServiceVersionServiceImpl implements ServiceVersionService {
|
|||
@Autowired
|
||||
private CSCollectService csCollectService;
|
||||
|
||||
@Autowired
|
||||
private MinioService minioService;
|
||||
|
||||
@Override
|
||||
public Integer getSource() {
|
||||
return 1;
|
||||
|
|
@ -181,8 +190,12 @@ public class CSServiceVersionServiceImpl implements ServiceVersionService {
|
|||
com.ruoyi.platform.domain.service.Service service = serviceDao.getServiceById(serviceVersion.getServiceId());
|
||||
ServiceTemp serviceTemp = serviceTempService.getServiceTemp(service.getServiceTempId());
|
||||
Integer objectID = csCollectService.uploadFile(serviceTemp.getName(), file);
|
||||
String savePath = "/mini-model-platform-data/cs-data/upload/"+serviceVersionId+ "/" + UUID.fastUUID()+"/"+file.getOriginalFilename();
|
||||
minioService.uploadFile(bucketName, savePath, file);
|
||||
HashMap<String, Object> result = MapUtil.newHashMap();
|
||||
result.put("file_id", objectID);
|
||||
result.put("direct_url", savePath);
|
||||
result.put("filename", file.getOriginalFilename());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import com.ruoyi.platform.domain.TrainingTask;
|
|||
import com.ruoyi.platform.domain.service.ServiceVersion;
|
||||
import com.ruoyi.platform.mapper.ServiceDao;
|
||||
import com.ruoyi.platform.mapper.TrainingTaskDao;
|
||||
import com.ruoyi.platform.service.MinioService;
|
||||
import com.ruoyi.platform.service.TrainingTaskService;
|
||||
import com.ruoyi.platform.utils.*;
|
||||
import com.ruoyi.platform.vo.serviceVos.TrainingTaskVo;
|
||||
|
|
@ -39,13 +40,13 @@ public class TrainingTaskServiceImpl implements TrainingTaskService {
|
|||
|
||||
@Resource
|
||||
private TrainingTaskDao trainingTaskDao;
|
||||
|
||||
@Resource
|
||||
private ServiceDao serviceDao;
|
||||
|
||||
@Resource
|
||||
private MinioUtil minioUtil;
|
||||
|
||||
@Value("${minio.endpointIp}")
|
||||
String endpointIp;
|
||||
@Value("${minio.dataReleaseBucketName}")
|
||||
private String bucketName;
|
||||
|
||||
|
|
@ -92,7 +93,7 @@ public class TrainingTaskServiceImpl implements TrainingTaskService {
|
|||
/**
|
||||
* 新增数据
|
||||
*
|
||||
* @param trainingTaskVoVo 实例对象
|
||||
* @param trainingTaskVo 实例对象
|
||||
* @return 实例对象
|
||||
*/
|
||||
@Override
|
||||
|
|
@ -214,7 +215,7 @@ public class TrainingTaskServiceImpl implements TrainingTaskService {
|
|||
|
||||
@Override
|
||||
public String downloadSingleFile(String url) throws Exception {
|
||||
return endpointIp + "/" + bucketName + "/" + url;
|
||||
return minioUtil.downloadUrlWithResponseHeader(bucketName, url);
|
||||
}
|
||||
|
||||
private String extractFileName(String urlStr) {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.ruoyi.platform.utils;
|
|||
|
||||
import io.minio.*;
|
||||
import io.minio.errors.MinioException;
|
||||
import io.minio.http.Method;
|
||||
import io.minio.messages.DeleteObject;
|
||||
import io.minio.messages.Item;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
|
@ -18,6 +19,7 @@ import java.nio.charset.StandardCharsets;
|
|||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
|
|
@ -134,6 +136,36 @@ public class MinioUtil {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置响应头下载文件
|
||||
* @param bucket
|
||||
* @param objectPath
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public String downloadUrlWithResponseHeader(String bucket, String objectPath) throws Exception {
|
||||
Map<String, String> queryParams = new HashMap<>();
|
||||
|
||||
// 关键:添加响应头参数
|
||||
queryParams.put("response-content-disposition",
|
||||
"attachment; filename=\"" + "" + "\"");
|
||||
|
||||
// 对于脚本文件,设置 Content-Type
|
||||
if (objectPath.endsWith(".sh") || objectPath.endsWith(".bash")) {
|
||||
queryParams.put("response-content-type", "application/x-sh");
|
||||
}
|
||||
|
||||
return minioClient.getPresignedObjectUrl(
|
||||
GetPresignedObjectUrlArgs.builder()
|
||||
.method(Method.GET)
|
||||
.bucket(bucket)
|
||||
.object(objectPath)
|
||||
.expiry(1, TimeUnit.HOURS)
|
||||
.extraQueryParams(queryParams)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过MultipartFile,上传文件
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue