|
@@ -2,7 +2,7 @@ package com.css.simulation.resource.scheduler.util;
|
|
|
|
|
|
import api.common.pojo.constants.DictConstants;
|
|
import api.common.pojo.constants.DictConstants;
|
|
import api.common.util.*;
|
|
import api.common.util.*;
|
|
-import com.css.simulation.resource.scheduler.configuration.constant.ConstantConfiguration;
|
|
|
|
|
|
+import com.css.simulation.resource.scheduler.configuration.custom.CustomConfiguration;
|
|
import com.css.simulation.resource.scheduler.configuration.kubernetes.KubernetesConfiguration;
|
|
import com.css.simulation.resource.scheduler.configuration.kubernetes.KubernetesConfiguration;
|
|
import com.css.simulation.resource.scheduler.configuration.redis.CustomRedisClient;
|
|
import com.css.simulation.resource.scheduler.configuration.redis.CustomRedisClient;
|
|
import com.css.simulation.resource.scheduler.data.entity.*;
|
|
import com.css.simulation.resource.scheduler.data.entity.*;
|
|
@@ -42,14 +42,6 @@ public class TaskUtil {
|
|
private String pyPath;
|
|
private String pyPath;
|
|
@Value("${scheduler.linux-path.temp}")
|
|
@Value("${scheduler.linux-path.temp}")
|
|
private String linuxTempPath;
|
|
private String linuxTempPath;
|
|
- @Value("${simulation-cloud.client-id}")
|
|
|
|
- private String clientId;
|
|
|
|
- @Value("${simulation-cloud.client-secret}")
|
|
|
|
- private String clientSecret;
|
|
|
|
- @Value("${simulation-cloud.token-uri}")
|
|
|
|
- private String tokenUri;
|
|
|
|
- @Value("${simulation-cloud.evaluation-level-uri}")
|
|
|
|
- private String evaluationLevelUri;
|
|
|
|
@Value("${scheduler.minio-path.project-result}")
|
|
@Value("${scheduler.minio-path.project-result}")
|
|
private String resultPathMinio;
|
|
private String resultPathMinio;
|
|
@Resource
|
|
@Resource
|
|
@@ -69,10 +61,6 @@ public class TaskUtil {
|
|
@Resource
|
|
@Resource
|
|
private ScoringRulesMapper scoringRulesMapper;
|
|
private ScoringRulesMapper scoringRulesMapper;
|
|
@Resource
|
|
@Resource
|
|
- private CloseableHttpClient closeableHttpClient;
|
|
|
|
- @Resource
|
|
|
|
- private RequestConfig requestConfig;
|
|
|
|
- @Resource
|
|
|
|
private ProjectUtil projectUtil;
|
|
private ProjectUtil projectUtil;
|
|
@Resource
|
|
@Resource
|
|
private SqlSessionFactory sqlSessionFactory;
|
|
private SqlSessionFactory sqlSessionFactory;
|
|
@@ -83,11 +71,13 @@ public class TaskUtil {
|
|
@Resource(name = "myKafkaAdmin")
|
|
@Resource(name = "myKafkaAdmin")
|
|
private Admin admin;
|
|
private Admin admin;
|
|
@Resource
|
|
@Resource
|
|
- private TaskUtil taskUtil;
|
|
|
|
- @Resource
|
|
|
|
private CustomRedisClient customRedisClient;
|
|
private CustomRedisClient customRedisClient;
|
|
@Resource
|
|
@Resource
|
|
- private ConstantConfiguration constantConfiguration;
|
|
|
|
|
|
+ private CustomConfiguration customConfiguration;
|
|
|
|
+ @Resource
|
|
|
|
+ private CloseableHttpClient closeableHttpClient;
|
|
|
|
+ @Resource
|
|
|
|
+ private RequestConfig requestConfig;
|
|
|
|
|
|
public void batchInsertTask(List<TaskEntity> taskEntityList) {
|
|
public void batchInsertTask(List<TaskEntity> taskEntityList) {
|
|
try (SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false)) {
|
|
try (SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false)) {
|
|
@@ -147,7 +137,7 @@ public class TaskUtil {
|
|
if (DictConstants.VIDEO_CPU.equals(isChoiceGpu)) {
|
|
if (DictConstants.VIDEO_CPU.equals(isChoiceGpu)) {
|
|
String generateVideoKey = "task:" + taskId + ":generateVideo";
|
|
String generateVideoKey = "task:" + taskId + ":generateVideo";
|
|
customRedisClient.set(generateVideoKey, "0");
|
|
customRedisClient.set(generateVideoKey, "0");
|
|
- HttpUtil.get(constantConfiguration.getGenerateVideoUrl().replace("simulation-resource-video", nodeName) + "?generateVideoKey=" + generateVideoKey + "&nodeName=" + nodeName + "&projectId=" + projectId + "&projectType=" + projectType + "&maxSimulationTime=" + maxSimulationTime + "&taskId=" + taskId);
|
|
|
|
|
|
+ HttpUtil.get(customConfiguration.getGenerateVideoUrl().replace("simulation-resource-video", nodeName) + "?generateVideoKey=" + generateVideoKey + "&nodeName=" + nodeName + "&projectId=" + projectId + "&projectType=" + projectType + "&maxSimulationTime=" + maxSimulationTime + "&taskId=" + taskId);
|
|
// HttpUtil.get("http://" + nodeName + ":8007//simulation/resource/video/generate" + "?generateVideoKey=" + generateVideoKey + "&nodeName=" + nodeName + "&projectId" + projectId + "&projectType" + projectType + "&maxSimulationTime" + maxSimulationTime + "&taskId" + taskId);
|
|
// HttpUtil.get("http://" + nodeName + ":8007//simulation/resource/video/generate" + "?generateVideoKey=" + generateVideoKey + "&nodeName=" + nodeName + "&projectId" + projectId + "&projectType" + projectType + "&maxSimulationTime" + maxSimulationTime + "&taskId" + taskId);
|
|
// videoFeignClient.generateVideo(generateVideoKey, nodeName, projectId, projectType, maxSimulationTime, taskId);
|
|
// videoFeignClient.generateVideo(generateVideoKey, nodeName, projectId, projectType, maxSimulationTime, taskId);
|
|
log.info("任务 {} 使用 CPU 生成视频开始>>>>>>>", taskId);
|
|
log.info("任务 {} 使用 CPU 生成视频开始>>>>>>>", taskId);
|
|
@@ -182,11 +172,11 @@ public class TaskUtil {
|
|
if (isCompleted) {
|
|
if (isCompleted) {
|
|
customRedisClient.tryLock(lock2, 10 * 60L);
|
|
customRedisClient.tryLock(lock2, 10 * 60L);
|
|
log.info("项目 {} 开始打分。", projectId);
|
|
log.info("项目 {} 开始打分。", projectId);
|
|
- taskUtil.score(redisPrefix.getProjectRunningKey(), userId, projectId, projectType);
|
|
|
|
|
|
+ score(redisPrefix.getProjectRunningKey(), userId, projectId, projectType);
|
|
log.info("项目 {} 计算评价等级。", projectId);
|
|
log.info("项目 {} 计算评价等级。", projectId);
|
|
- taskUtil.evaluationLevel(projectId);
|
|
|
|
|
|
+ evaluationLevel(projectId);
|
|
log.info("项目 {} 开始释放资源。", projectId);
|
|
log.info("项目 {} 开始释放资源。", projectId);
|
|
- taskUtil.done(redisPrefix, projectId, projectType);
|
|
|
|
|
|
+ done(redisPrefix, projectId, projectType);
|
|
log.info("项目 {} 运行结束。", projectId);
|
|
log.info("项目 {} 运行结束。", projectId);
|
|
}
|
|
}
|
|
} finally {
|
|
} finally {
|
|
@@ -418,9 +408,9 @@ public class TaskUtil {
|
|
|
|
|
|
@SneakyThrows
|
|
@SneakyThrows
|
|
public void evaluationLevel(String projectId) {
|
|
public void evaluationLevel(String projectId) {
|
|
- String tokenUrl = tokenUri + "?grant_type=client_credentials" + "&client_id=" + clientId + "&client_secret=" + clientSecret;
|
|
|
|
|
|
+ String tokenUrl = customConfiguration.getTokenUri() + "?grant_type=client_credentials" + "&client_id=" + customConfiguration.getClientId() + "&client_secret=" + customConfiguration.getClientSecret();
|
|
log.info("获取仿真云平台 token:" + tokenUrl);
|
|
log.info("获取仿真云平台 token:" + tokenUrl);
|
|
- String response = HttpUtil.get(closeableHttpClient, requestConfig, tokenUrl);
|
|
|
|
|
|
+ String response = HttpUtil.get(tokenUrl);
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
JsonNode jsonNode = objectMapper.readTree(response);
|
|
JsonNode jsonNode = objectMapper.readTree(response);
|
|
String accessToken = jsonNode.path("access_token").asText();
|
|
String accessToken = jsonNode.path("access_token").asText();
|
|
@@ -429,8 +419,8 @@ public class TaskUtil {
|
|
headers.put("Authorization", "Bearer " + accessToken);
|
|
headers.put("Authorization", "Bearer " + accessToken);
|
|
Map<String, String> params = new HashMap<>();
|
|
Map<String, String> params = new HashMap<>();
|
|
params.put("id", projectId);
|
|
params.put("id", projectId);
|
|
- String post = HttpUtil.post(closeableHttpClient, requestConfig, evaluationLevelUri, headers, params);
|
|
|
|
- log.info("访问仿真云平台评价等级接口:" + evaluationLevelUri + ",请求头为:" + headers + ",请求体为:" + params + "结果为:" + post);
|
|
|
|
|
|
+ String post = HttpUtil.post(closeableHttpClient, requestConfig, customConfiguration.getEvaluationLevelUri(), headers, params);
|
|
|
|
+ log.info("访问仿真云平台评价等级接口:" + customConfiguration.getEvaluationLevelUri() + ",请求头为:" + headers + ",请求体为:" + params + "结果为:" + post);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -469,8 +459,10 @@ public class TaskUtil {
|
|
RedisUtil.deleteByPrefix(stringRedisTemplate, "project:" + projectId);
|
|
RedisUtil.deleteByPrefix(stringRedisTemplate, "project:" + projectId);
|
|
// 删除剩余 yaml
|
|
// 删除剩余 yaml
|
|
projectUtil.deleteYamlByProjectId(projectId);
|
|
projectUtil.deleteYamlByProjectId(projectId);
|
|
- // 查询项目详情
|
|
|
|
|
|
+ // 查询并保存项目详情
|
|
projectUtil.selectProjectDetailsById(projectType, projectId);
|
|
projectUtil.selectProjectDetailsById(projectType, projectId);
|
|
|
|
+ // 查询并保存项目报告
|
|
|
|
+ projectUtil.selectProjectReportById(projectType, projectId);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|