|
@@ -35,415 +35,421 @@ import java.util.stream.Collectors;
|
|
|
@Slf4j
|
|
|
public class TaskUtil {
|
|
|
|
|
|
- @Value("${minio.bucket-name}")
|
|
|
- private String bucketName;
|
|
|
- @Value("${scheduler.linux-path.score-py}")
|
|
|
- private String pyPath;
|
|
|
- @Value("${scheduler.linux-path.temp}")
|
|
|
- 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}")
|
|
|
- private String resultPathMinio;
|
|
|
- @Resource
|
|
|
- private StringRedisTemplate stringRedisTemplate;
|
|
|
- @Resource
|
|
|
- private TaskMapper taskMapper;
|
|
|
- @Resource
|
|
|
- private MinioClient minioClient;
|
|
|
- @Resource
|
|
|
- private ManualProjectMapper manualProjectMapper;
|
|
|
- @Resource
|
|
|
- private AutoSubProjectMapper autoSubProjectMapper;
|
|
|
- @Resource
|
|
|
- private TaskIndexManager taskIndexManager;
|
|
|
- @Resource
|
|
|
- private IndexMapper indexMapper;
|
|
|
- @Resource
|
|
|
- private ScoringRulesMapper scoringRulesMapper;
|
|
|
- @Resource
|
|
|
- private CloseableHttpClient closeableHttpClient;
|
|
|
- @Resource
|
|
|
- private RequestConfig requestConfig;
|
|
|
- @Resource
|
|
|
- private ProjectUtil projectUtil;
|
|
|
- @Resource
|
|
|
- private VideoFeignClient videoFeignClient;
|
|
|
- @Resource
|
|
|
- private SqlSessionFactory sqlSessionFactory;
|
|
|
- @Resource
|
|
|
- private KubernetesConfiguration kubernetesConfiguration;
|
|
|
- @Resource
|
|
|
- private ApiClient apiClient;
|
|
|
- @Resource(name = "myKafkaAdmin")
|
|
|
- private Admin admin;
|
|
|
+ @Value("${minio.bucket-name}")
|
|
|
+ private String bucketName;
|
|
|
+ @Value("${scheduler.linux-path.score-py}")
|
|
|
+ private String pyPath;
|
|
|
+ @Value("${scheduler.linux-path.temp}")
|
|
|
+ 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}")
|
|
|
+ private String resultPathMinio;
|
|
|
+ @Resource
|
|
|
+ private StringRedisTemplate stringRedisTemplate;
|
|
|
+ @Resource
|
|
|
+ private TaskMapper taskMapper;
|
|
|
+ @Resource
|
|
|
+ private MinioClient minioClient;
|
|
|
+ @Resource
|
|
|
+ private ManualProjectMapper manualProjectMapper;
|
|
|
+ @Resource
|
|
|
+ private AutoSubProjectMapper autoSubProjectMapper;
|
|
|
+ @Resource
|
|
|
+ private TaskIndexManager taskIndexManager;
|
|
|
+ @Resource
|
|
|
+ private IndexMapper indexMapper;
|
|
|
+ @Resource
|
|
|
+ private ScoringRulesMapper scoringRulesMapper;
|
|
|
+ @Resource
|
|
|
+ private CloseableHttpClient closeableHttpClient;
|
|
|
+ @Resource
|
|
|
+ private RequestConfig requestConfig;
|
|
|
+ @Resource
|
|
|
+ private ProjectUtil projectUtil;
|
|
|
+ @Resource
|
|
|
+ private VideoFeignClient videoFeignClient;
|
|
|
+ @Resource
|
|
|
+ private SqlSessionFactory sqlSessionFactory;
|
|
|
+ @Resource
|
|
|
+ private KubernetesConfiguration kubernetesConfiguration;
|
|
|
+ @Resource
|
|
|
+ private ApiClient apiClient;
|
|
|
+ @Resource(name = "myKafkaAdmin")
|
|
|
+ private Admin admin;
|
|
|
|
|
|
- public void batchInsertTask(List<TaskEntity> taskEntityList) {
|
|
|
- try (SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false)) {
|
|
|
- TaskMapper taskMapper1 = sqlSession.getMapper(TaskMapper.class);
|
|
|
- for (TaskEntity taskEntity : taskEntityList) {
|
|
|
- taskMapper1.insert(taskEntity);
|
|
|
- }
|
|
|
- sqlSession.commit();
|
|
|
- }
|
|
|
- }
|
|
|
+ public void saveErrorMessage(String projectType,String projectId,String errorMessage){
|
|
|
+ if(DictConstants.PROJECT_TYPE_MANUAL.equals(projectType)){
|
|
|
+ manualProjectMapper.saveErrorMessage()
|
|
|
+ }
|
|
|
+ };
|
|
|
|
|
|
- public boolean handleErrorTask(PrefixEntity redisPrefix, String projectId, String projectType, String maxSimulationTime, String taskId, String state, String podName) {
|
|
|
- return isProjectCompleted(redisPrefix, projectId, projectType, maxSimulationTime, taskId, state, podName);
|
|
|
- }
|
|
|
+ public void batchInsertTask(List<TaskEntity> taskEntityList) {
|
|
|
+ try (SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false)) {
|
|
|
+ TaskMapper taskMapper1 = sqlSession.getMapper(TaskMapper.class);
|
|
|
+ for (TaskEntity taskEntity : taskEntityList) {
|
|
|
+ taskMapper1.insert(taskEntity);
|
|
|
+ }
|
|
|
+ sqlSession.commit();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
- * 加事务的话高并发情况下会死锁
|
|
|
- */
|
|
|
- @SneakyThrows
|
|
|
- public boolean isProjectCompleted(PrefixEntity redisPrefix, String projectId, String projectType, String maxSimulationTime, String taskId, String state, String podName) {
|
|
|
- boolean result;
|
|
|
- String nodeName = projectUtil.getNodeNameOfPod(projectId, podName);
|
|
|
- if (DictConstants.TASK_RUNNING.equals(state)) {
|
|
|
-
|
|
|
- stringRedisTemplate.opsForValue().set(redisPrefix.getTaskPodKey(), podName);
|
|
|
- taskTick(taskId);
|
|
|
- log.info("修改任务 " + taskId + " 的状态为 " + state + ",pod 名称为:" + podName);
|
|
|
- taskMapper.updateStateWithStartTime(taskId, state, TimeUtil.getNowForMysql());
|
|
|
- return false;
|
|
|
- } else {
|
|
|
-
|
|
|
- log.info("修改任务 {} 的状态为 {} ,pod 名称为 {} ,并删除 pod。", taskId, state, podName);
|
|
|
- if (DictConstants.TASK_ABORTED.equals(state)) {
|
|
|
- String minioPathOfErrorLog = resultPathMinio + projectId + "/" + taskId + "error.log";
|
|
|
- boolean objectExist = MinioUtil.isObjectExist(minioClient, bucketName, minioPathOfErrorLog);
|
|
|
- String targetEvaluate;
|
|
|
- if (objectExist) {
|
|
|
- String errorString = MinioUtil.downloadToString(minioClient, bucketName, minioPathOfErrorLog);
|
|
|
- String[] lines = errorString.split("\n");
|
|
|
- StringBuilder errorMessage = new StringBuilder();
|
|
|
- for (String line : lines) {
|
|
|
- if (line.startsWith("Original Error")) {
|
|
|
- errorMessage.append(line).append("\n");
|
|
|
- }
|
|
|
- if (line.startsWith("Possible Cause")) {
|
|
|
- errorMessage.append(line);
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- targetEvaluate = errorMessage.toString();
|
|
|
- } else {
|
|
|
- targetEvaluate = DictConstants.TASK_ERROR_REASON_2;
|
|
|
+ public boolean handleErrorTask(PrefixEntity redisPrefix, String projectId, String projectType, String maxSimulationTime, String taskId, String state, String podName) {
|
|
|
+ return isProjectCompleted(redisPrefix, projectId, projectType, maxSimulationTime, taskId, state, podName);
|
|
|
}
|
|
|
- taskMapper.updateFailStateWithStopTime(taskId, state, TimeUtil.getNowForMysql(), targetEvaluate);
|
|
|
- } else if (DictConstants.TASK_TERMINATED.equals(state)) {
|
|
|
- taskMapper.updateFailStateWithStopTime(taskId, state, TimeUtil.getNowForMysql(), DictConstants.TASK_ERROR_REASON_3);
|
|
|
- } else if (DictConstants.TASK_ANALYSIS.equals(state)) {
|
|
|
- taskMapper.updateSuccessStateWithStopTime(taskId, state, TimeUtil.getNowForMysql());
|
|
|
-
|
|
|
- String isChoiceGpu = projectUtil.getProjectByProjectId(projectId).getIsChoiceGpu();
|
|
|
- if (DictConstants.VIDEO_GPU.equals(isChoiceGpu)) {
|
|
|
- log.info("项目 {} 使用 GPU 生成视频。", projectId);
|
|
|
- } else if (DictConstants.VIDEO_CPU.equals(isChoiceGpu)) {
|
|
|
- log.info("项目 {} 使用 CPU 生成视频。", projectId);
|
|
|
- videoFeignClient.generateVideo(projectId, projectType, maxSimulationTime, taskId);
|
|
|
- } else {
|
|
|
- throw new RuntimeException("未设置视频生成。");
|
|
|
+
|
|
|
+
|
|
|
+ * 加事务的话高并发情况下会死锁
|
|
|
+ */
|
|
|
+ @SneakyThrows
|
|
|
+ public boolean isProjectCompleted(PrefixEntity redisPrefix, String projectId, String projectType, String maxSimulationTime, String taskId, String state, String podName) {
|
|
|
+ boolean result;
|
|
|
+ String nodeName = projectUtil.getNodeNameOfPod(projectId, podName);
|
|
|
+ if (DictConstants.TASK_RUNNING.equals(state)) {
|
|
|
+
|
|
|
+ stringRedisTemplate.opsForValue().set(redisPrefix.getTaskPodKey(), podName);
|
|
|
+ taskTick(taskId);
|
|
|
+ log.info("修改任务 " + taskId + " 的状态为 " + state + ",pod 名称为:" + podName);
|
|
|
+ taskMapper.updateStateWithStartTime(taskId, state, TimeUtil.getNowForMysql());
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+
|
|
|
+ log.info("修改任务 {} 的状态为 {} ,pod 名称为 {} ,并删除 pod。", taskId, state, podName);
|
|
|
+ if (DictConstants.TASK_ABORTED.equals(state)) {
|
|
|
+ String minioPathOfErrorLog = resultPathMinio + projectId + "/" + taskId + "error.log";
|
|
|
+ boolean objectExist = MinioUtil.isObjectExist(minioClient, bucketName, minioPathOfErrorLog);
|
|
|
+ String targetEvaluate;
|
|
|
+ if (objectExist) {
|
|
|
+ String errorString = MinioUtil.downloadToString(minioClient, bucketName, minioPathOfErrorLog);
|
|
|
+ String[] lines = errorString.split("\n");
|
|
|
+ StringBuilder errorMessage = new StringBuilder();
|
|
|
+ for (String line : lines) {
|
|
|
+ if (line.startsWith("Original Error")) {
|
|
|
+ errorMessage.append(line).append("\n");
|
|
|
+ }
|
|
|
+ if (line.startsWith("Possible Cause")) {
|
|
|
+ errorMessage.append(line);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ targetEvaluate = errorMessage.toString();
|
|
|
+ } else {
|
|
|
+ targetEvaluate = DictConstants.TASK_ERROR_REASON_2;
|
|
|
+ }
|
|
|
+ taskMapper.updateFailStateWithStopTime(taskId, state, TimeUtil.getNowForMysql(), targetEvaluate);
|
|
|
+ } else if (DictConstants.TASK_TERMINATED.equals(state)) {
|
|
|
+ taskMapper.updateFailStateWithStopTime(taskId, state, TimeUtil.getNowForMysql(), DictConstants.TASK_ERROR_REASON_3);
|
|
|
+ } else if (DictConstants.TASK_ANALYSIS.equals(state)) {
|
|
|
+ taskMapper.updateSuccessStateWithStopTime(taskId, state, TimeUtil.getNowForMysql());
|
|
|
+
|
|
|
+ String isChoiceGpu = projectUtil.getProjectByProjectId(projectId).getIsChoiceGpu();
|
|
|
+ if (DictConstants.VIDEO_GPU.equals(isChoiceGpu)) {
|
|
|
+ log.info("项目 {} 使用 GPU 生成视频。", projectId);
|
|
|
+ } else if (DictConstants.VIDEO_CPU.equals(isChoiceGpu)) {
|
|
|
+ log.info("项目 {} 使用 CPU 生成视频。", projectId);
|
|
|
+ videoFeignClient.generateVideo(projectId, projectType, maxSimulationTime, taskId);
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("未设置视频生成。");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ result = projectUtil.complete(redisPrefix, projectId);
|
|
|
+ if (!result) {
|
|
|
+ log.info("项目 " + projectId + " 还未运行完成。");
|
|
|
+ projectUtil.createNextPod(projectId, nodeName, podName);
|
|
|
+ } else {
|
|
|
+
|
|
|
+ KubernetesUtil.deletePod2(apiClient, kubernetesConfiguration.getNamespace(), podName);
|
|
|
+ projectUtil.incrementOneParallelismOfGpuNode(nodeName);
|
|
|
+ }
|
|
|
+ RedisUtil.deleteByPrefix(stringRedisTemplate, redisPrefix.getTaskMessageKey());
|
|
|
+ RedisUtil.deleteByPrefix(stringRedisTemplate, redisPrefix.getTaskPodKey());
|
|
|
+ }
|
|
|
+ return result;
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- result = projectUtil.complete(redisPrefix, projectId);
|
|
|
- if (!result) {
|
|
|
- log.info("项目 " + projectId + " 还未运行完成。");
|
|
|
- projectUtil.createNextPod(projectId, nodeName, podName);
|
|
|
- } else {
|
|
|
-
|
|
|
- KubernetesUtil.deletePod2(apiClient, kubernetesConfiguration.getNamespace(), podName);
|
|
|
- projectUtil.incrementOneParallelismOfGpuNode(nodeName);
|
|
|
- }
|
|
|
- RedisUtil.deleteByPrefix(stringRedisTemplate, redisPrefix.getTaskMessageKey());
|
|
|
- RedisUtil.deleteByPrefix(stringRedisTemplate, redisPrefix.getTaskPodKey());
|
|
|
- }
|
|
|
- return result;
|
|
|
- }
|
|
|
|
|
|
|
|
|
-
|
|
|
- * @param userId 项目创建用户的 id
|
|
|
- */
|
|
|
- @SneakyThrows
|
|
|
- public void score(String projectRunningKey, String userId, String projectId, String projectType) {
|
|
|
- stringRedisTemplate.delete(projectRunningKey);
|
|
|
-
|
|
|
- ProjectEntity projectEntity = null;
|
|
|
- if (DictConstants.PROJECT_TYPE_MANUAL.equals(projectType)) {
|
|
|
- projectEntity = manualProjectMapper.selectById(projectId);
|
|
|
- } else if (DictConstants.PROJECT_TYPE_AUTO_SUB.equals(projectType)) {
|
|
|
- projectEntity = autoSubProjectMapper.selectById(projectId);
|
|
|
- }
|
|
|
- if (projectEntity == null) {
|
|
|
- log.error("不存在项目 {}" + projectId);
|
|
|
- return;
|
|
|
- }
|
|
|
- String packageId = projectEntity.getScenePackageId();
|
|
|
- TimeUnit.SECONDS.sleep(10);
|
|
|
- List<TaskEntity> taskList = taskMapper.selectTaskListByProjectId(projectId);
|
|
|
- if (CollectionUtil.isEmpty(taskList)) {
|
|
|
- log.error("项目 {} 下没有查询到任务!", projectId);
|
|
|
- return;
|
|
|
- }
|
|
|
- indexMapper.deleteFirstByProjectId(projectId);
|
|
|
- indexMapper.deleteLastByProjectId(projectId);
|
|
|
-
|
|
|
- String allIndexKey = "project:" + projectId + ":package:" + packageId + ":all";
|
|
|
- String leafIndexKey = "project:" + projectId + ":package:" + packageId + ":leaf";
|
|
|
- String allIndexTemplateListJson = stringRedisTemplate.opsForValue().get(allIndexKey);
|
|
|
- String leafIndexTemplateListJson = stringRedisTemplate.opsForValue().get(leafIndexKey);
|
|
|
- List<IndexTemplateEntity> allIndexTemplateList = JsonUtil.jsonToList(allIndexTemplateListJson, IndexTemplateEntity.class);
|
|
|
- List<IndexTemplateEntity> leafIndexTemplateList = JsonUtil.jsonToList(leafIndexTemplateListJson, IndexTemplateEntity.class);
|
|
|
- log.info("共有 " + leafIndexTemplateList.size() + "个叶子节点:" + leafIndexTemplateListJson);
|
|
|
- int maxLevel = 1;
|
|
|
- List<LeafIndexEntity> leafIndexList = new ArrayList<>();
|
|
|
- for (int i = 0; i < leafIndexTemplateList.size(); i++) {
|
|
|
- String scoreExplain = null;
|
|
|
- IndexTemplateEntity leafIndexTemplate = leafIndexTemplateList.get(i);
|
|
|
- String indexId = leafIndexTemplate.getIndexId();
|
|
|
- String parentId = leafIndexTemplate.getParentId();
|
|
|
- String rootId = leafIndexTemplate.getRootId();
|
|
|
- String weight = leafIndexTemplate.getWeight();
|
|
|
- Integer packageLevel = leafIndexTemplate.getPackageLevel();
|
|
|
- String ruleName = leafIndexTemplate.getRuleName();
|
|
|
- String ruleDetails = leafIndexTemplate.getRuleDetails();
|
|
|
- if (packageLevel > maxLevel) {
|
|
|
- maxLevel = packageLevel;
|
|
|
- }
|
|
|
- log.info("开始执行对第 " + (i + 1) + " 个叶子节点 " + indexId + " 进行打分!");
|
|
|
-
|
|
|
- String createUserIdOfRule = scoringRulesMapper.selectCreateUserIdByIndexId(indexId);
|
|
|
-
|
|
|
- String scoreDirectoryOfUser = linuxTempPath + "score/" + createUserIdOfRule + "/";
|
|
|
- if (!new File(scoreDirectoryOfUser + "main.py").exists()) {
|
|
|
-
|
|
|
- FileUtil.createDirectory(scoreDirectoryOfUser);
|
|
|
- FileUtil.cpR(pyPath, scoreDirectoryOfUser);
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
+ * @param userId 项目创建用户的 id
|
|
|
+ */
|
|
|
+ @SneakyThrows
|
|
|
+ public void score(String projectRunningKey, String userId, String projectId, String projectType) {
|
|
|
+ stringRedisTemplate.delete(projectRunningKey);
|
|
|
+
|
|
|
+ ProjectEntity projectEntity = null;
|
|
|
+ if (DictConstants.PROJECT_TYPE_MANUAL.equals(projectType)) {
|
|
|
+ projectEntity = manualProjectMapper.selectById(projectId);
|
|
|
+ } else if (DictConstants.PROJECT_TYPE_AUTO_SUB.equals(projectType)) {
|
|
|
+ projectEntity = autoSubProjectMapper.selectById(projectId);
|
|
|
+ }
|
|
|
+ if (projectEntity == null) {
|
|
|
+ log.error("不存在项目 {}" + projectId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String packageId = projectEntity.getScenePackageId();
|
|
|
+ TimeUnit.SECONDS.sleep(10);
|
|
|
+ List<TaskEntity> taskList = taskMapper.selectTaskListByProjectId(projectId);
|
|
|
+ if (CollectionUtil.isEmpty(taskList)) {
|
|
|
+ log.error("项目 {} 下没有查询到任务!", projectId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ indexMapper.deleteFirstByProjectId(projectId);
|
|
|
+ indexMapper.deleteLastByProjectId(projectId);
|
|
|
+
|
|
|
+ String allIndexKey = "project:" + projectId + ":package:" + packageId + ":all";
|
|
|
+ String leafIndexKey = "project:" + projectId + ":package:" + packageId + ":leaf";
|
|
|
+ String allIndexTemplateListJson = stringRedisTemplate.opsForValue().get(allIndexKey);
|
|
|
+ String leafIndexTemplateListJson = stringRedisTemplate.opsForValue().get(leafIndexKey);
|
|
|
+ List<IndexTemplateEntity> allIndexTemplateList = JsonUtil.jsonToList(allIndexTemplateListJson, IndexTemplateEntity.class);
|
|
|
+ List<IndexTemplateEntity> leafIndexTemplateList = JsonUtil.jsonToList(leafIndexTemplateListJson, IndexTemplateEntity.class);
|
|
|
+ log.info("共有 " + leafIndexTemplateList.size() + "个叶子节点:" + leafIndexTemplateListJson);
|
|
|
+ int maxLevel = 1;
|
|
|
+ List<LeafIndexEntity> leafIndexList = new ArrayList<>();
|
|
|
+ for (int i = 0; i < leafIndexTemplateList.size(); i++) {
|
|
|
+ String scoreExplain = null;
|
|
|
+ IndexTemplateEntity leafIndexTemplate = leafIndexTemplateList.get(i);
|
|
|
+ String indexId = leafIndexTemplate.getIndexId();
|
|
|
+ String parentId = leafIndexTemplate.getParentId();
|
|
|
+ String rootId = leafIndexTemplate.getRootId();
|
|
|
+ String weight = leafIndexTemplate.getWeight();
|
|
|
+ Integer packageLevel = leafIndexTemplate.getPackageLevel();
|
|
|
+ String ruleName = leafIndexTemplate.getRuleName();
|
|
|
+ String ruleDetails = leafIndexTemplate.getRuleDetails();
|
|
|
+ if (packageLevel > maxLevel) {
|
|
|
+ maxLevel = packageLevel;
|
|
|
+ }
|
|
|
+ log.info("开始执行对第 " + (i + 1) + " 个叶子节点 " + indexId + " 进行打分!");
|
|
|
+
|
|
|
+ String createUserIdOfRule = scoringRulesMapper.selectCreateUserIdByIndexId(indexId);
|
|
|
+
|
|
|
+ String scoreDirectoryOfUser = linuxTempPath + "score/" + createUserIdOfRule + "/";
|
|
|
+ if (!new File(scoreDirectoryOfUser + "main.py").exists()) {
|
|
|
+
|
|
|
+ FileUtil.createDirectory(scoreDirectoryOfUser);
|
|
|
+ FileUtil.cpR(pyPath, scoreDirectoryOfUser);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
- String ruleFilePath = scoreDirectoryOfUser + "scripts/" + ruleName.split("_")[0] + "/" + ruleName + ".py";
|
|
|
- FileUtil.writeInputStreamToLocalFile(IoUtil.stringToInputStream(ruleDetails), ruleFilePath);
|
|
|
- log.info("将叶子节点 " + indexId + " 对应的打分规则保存到临时目录:" + ruleFilePath);
|
|
|
- List<TaskEntity> taskListOfLeafIndex = taskList.stream().filter(task -> indexId.equals(task.getLastTargetId())).collect(Collectors.toList());
|
|
|
- log.info("叶子节点 " + indexId + " 包括 " + taskListOfLeafIndex.size() + " 个任务:" + taskListOfLeafIndex);
|
|
|
-
|
|
|
-
|
|
|
- for (TaskEntity taskOfLeaf : taskListOfLeafIndex) {
|
|
|
- String task2Id = taskOfLeaf.getId();
|
|
|
+ String ruleFilePath = scoreDirectoryOfUser + "scripts/" + ruleName.split("_")[0] + "/" + ruleName + ".py";
|
|
|
+ FileUtil.writeInputStreamToLocalFile(IoUtil.stringToInputStream(ruleDetails), ruleFilePath);
|
|
|
+ log.info("将叶子节点 " + indexId + " 对应的打分规则保存到临时目录:" + ruleFilePath);
|
|
|
+ List<TaskEntity> taskListOfLeafIndex = taskList.stream().filter(task -> indexId.equals(task.getLastTargetId())).collect(Collectors.toList());
|
|
|
+ log.info("叶子节点 " + indexId + " 包括 " + taskListOfLeafIndex.size() + " 个任务:" + taskListOfLeafIndex);
|
|
|
+
|
|
|
+
|
|
|
+ for (TaskEntity taskOfLeaf : taskListOfLeafIndex) {
|
|
|
+ String task2Id = taskOfLeaf.getId();
|
|
|
|
|
|
- String runState = taskOfLeaf.getRunState();
|
|
|
- log.info("TaskManager--score 任务 " + task2Id + " 的运行状态为:" + runState);
|
|
|
- if (DictConstants.TASK_ANALYSIS.equals(runState)) {
|
|
|
- taskMapper.updateSuccessStateWithStopTime(task2Id, DictConstants.TASK_ANALYSING, TimeUtil.getNowForMysql());
|
|
|
-
|
|
|
- String result1OfMinio = taskOfLeaf.getRunResultFilePath() + "/Ego.csv";
|
|
|
- String result1OfLinux = linuxTempPath + result1OfMinio;
|
|
|
- String result2OfMinio = taskOfLeaf.getRunResultFilePath() + "/evaluation.csv";
|
|
|
- String result2OfLinux = linuxTempPath + result2OfMinio;
|
|
|
- String scoreCommand = "python3 " + scoreDirectoryOfUser + "main.py " + result1OfLinux + " " + result2OfLinux + " " + taskOfLeaf.getSceneType() + " " + ruleName;
|
|
|
- String scoreResult;
|
|
|
- ScoreEntity score = null;
|
|
|
- log.info("下载 minio 上的结果文件 " + result1OfMinio + " 和 " + result2OfMinio + " 到临时目录:" + linuxTempPath);
|
|
|
- MinioUtil.downloadToFile(minioClient, bucketName, result1OfMinio, result1OfLinux);
|
|
|
- MinioUtil.downloadToFile(minioClient, bucketName, result2OfMinio, result2OfLinux);
|
|
|
- log.info("开始执行打分命令:" + scoreCommand);
|
|
|
- Runtime r = Runtime.getRuntime();
|
|
|
- Process p = r.exec(scoreCommand, null, new File(scoreDirectoryOfUser));
|
|
|
- BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
|
|
- StringBuilder sb = new StringBuilder();
|
|
|
- String inline;
|
|
|
- while (null != (inline = br.readLine())) {
|
|
|
- sb.append(inline).append("\n");
|
|
|
- }
|
|
|
- scoreResult = sb.toString();
|
|
|
- log.info("项目" + projectId + " 的任务 " + task2Id + " 打分结束,结果为:" + scoreResult);
|
|
|
- String replace = StringUtil.replace(scoreResult, "'", "\"");
|
|
|
- try {
|
|
|
- score = JsonUtil.jsonToBean(replace, ScoreEntity.class);
|
|
|
- } catch (Exception e) {
|
|
|
- log.info("项目" + projectId + " 的任务 " + task2Id + " 打分失败:", e);
|
|
|
- }
|
|
|
- if (score != null) {
|
|
|
- taskOfLeaf.setReturnSceneId(score.getUnit_scene_ID());
|
|
|
- taskOfLeaf.setTargetEvaluate(score.getEvaluate_item());
|
|
|
- taskOfLeaf.setScoreExplain(score.getScore_description());
|
|
|
- taskOfLeaf.setModifyUserId(userId);
|
|
|
- taskOfLeaf.setModifyTime(TimeUtil.getNowForMysql());
|
|
|
- scoreExplain = score.getScore_description();
|
|
|
- taskOfLeaf.setRunState(DictConstants.TASK_COMPLETED);
|
|
|
- double taskScore = score.getUnit_scene_score();
|
|
|
- if (taskScore == -1.0) {
|
|
|
- taskOfLeaf.setScore(0.0);
|
|
|
- taskOfLeaf.setScored(false);
|
|
|
- } else {
|
|
|
- taskOfLeaf.setScore(NumberUtil.cut(taskScore, 2));
|
|
|
- taskOfLeaf.setScored(true);
|
|
|
- }
|
|
|
- taskMapper.updateSuccessState(taskOfLeaf, DictConstants.TASK_COMPLETED);
|
|
|
- } else {
|
|
|
-
|
|
|
- taskOfLeaf.setRunState(DictConstants.TASK_ABORTED);
|
|
|
- taskOfLeaf.setScore(0.0);
|
|
|
- taskOfLeaf.setScored(false);
|
|
|
- taskMapper.updateFailStateWithStopTime(task2Id, DictConstants.TASK_ABORTED, TimeUtil.getNowForMysql(), DictConstants.TASK_ERROR_REASON_5);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ String runState = taskOfLeaf.getRunState();
|
|
|
+ log.info("TaskManager--score 任务 " + task2Id + " 的运行状态为:" + runState);
|
|
|
+ if (DictConstants.TASK_ANALYSIS.equals(runState)) {
|
|
|
+ taskMapper.updateSuccessStateWithStopTime(task2Id, DictConstants.TASK_ANALYSING, TimeUtil.getNowForMysql());
|
|
|
+
|
|
|
+ String result1OfMinio = taskOfLeaf.getRunResultFilePath() + "/Ego.csv";
|
|
|
+ String result1OfLinux = linuxTempPath + result1OfMinio;
|
|
|
+ String result2OfMinio = taskOfLeaf.getRunResultFilePath() + "/evaluation.csv";
|
|
|
+ String result2OfLinux = linuxTempPath + result2OfMinio;
|
|
|
+ String scoreCommand = "python3 " + scoreDirectoryOfUser + "main.py " + result1OfLinux + " " + result2OfLinux + " " + taskOfLeaf.getSceneType() + " " + ruleName;
|
|
|
+ String scoreResult;
|
|
|
+ ScoreEntity score = null;
|
|
|
+ log.info("下载 minio 上的结果文件 " + result1OfMinio + " 和 " + result2OfMinio + " 到临时目录:" + linuxTempPath);
|
|
|
+ MinioUtil.downloadToFile(minioClient, bucketName, result1OfMinio, result1OfLinux);
|
|
|
+ MinioUtil.downloadToFile(minioClient, bucketName, result2OfMinio, result2OfLinux);
|
|
|
+ log.info("开始执行打分命令:" + scoreCommand);
|
|
|
+ Runtime r = Runtime.getRuntime();
|
|
|
+ Process p = r.exec(scoreCommand, null, new File(scoreDirectoryOfUser));
|
|
|
+ BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ String inline;
|
|
|
+ while (null != (inline = br.readLine())) {
|
|
|
+ sb.append(inline).append("\n");
|
|
|
+ }
|
|
|
+ scoreResult = sb.toString();
|
|
|
+ log.info("项目" + projectId + " 的任务 " + task2Id + " 打分结束,结果为:" + scoreResult);
|
|
|
+ String replace = StringUtil.replace(scoreResult, "'", "\"");
|
|
|
+ try {
|
|
|
+ score = JsonUtil.jsonToBean(replace, ScoreEntity.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("项目" + projectId + " 的任务 " + task2Id + " 打分失败:", e);
|
|
|
+ }
|
|
|
+ if (score != null) {
|
|
|
+ taskOfLeaf.setReturnSceneId(score.getUnit_scene_ID());
|
|
|
+ taskOfLeaf.setTargetEvaluate(score.getEvaluate_item());
|
|
|
+ taskOfLeaf.setScoreExplain(score.getScore_description());
|
|
|
+ taskOfLeaf.setModifyUserId(userId);
|
|
|
+ taskOfLeaf.setModifyTime(TimeUtil.getNowForMysql());
|
|
|
+ scoreExplain = score.getScore_description();
|
|
|
+ taskOfLeaf.setRunState(DictConstants.TASK_COMPLETED);
|
|
|
+ double taskScore = score.getUnit_scene_score();
|
|
|
+ if (taskScore == -1.0) {
|
|
|
+ taskOfLeaf.setScore(0.0);
|
|
|
+ taskOfLeaf.setScored(false);
|
|
|
+ } else {
|
|
|
+ taskOfLeaf.setScore(NumberUtil.cut(taskScore, 2));
|
|
|
+ taskOfLeaf.setScored(true);
|
|
|
+ }
|
|
|
+ taskMapper.updateSuccessState(taskOfLeaf, DictConstants.TASK_COMPLETED);
|
|
|
+ } else {
|
|
|
+
|
|
|
+ taskOfLeaf.setRunState(DictConstants.TASK_ABORTED);
|
|
|
+ taskOfLeaf.setScore(0.0);
|
|
|
+ taskOfLeaf.setScored(false);
|
|
|
+ taskMapper.updateFailStateWithStopTime(task2Id, DictConstants.TASK_ABORTED, TimeUtil.getNowForMysql(), DictConstants.TASK_ERROR_REASON_5);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- int errorSceneNumber = 0;
|
|
|
- int notScoredSceneNumber = 0;
|
|
|
- int notStandardSceneNumber = 0;
|
|
|
- int standardSceneNumber = 0;
|
|
|
- double leafSum = 0.0;
|
|
|
- for (TaskEntity task : taskListOfLeafIndex) {
|
|
|
- Double scoreTemp = task.getScore();
|
|
|
- if (scoreTemp == null) {
|
|
|
- errorSceneNumber++;
|
|
|
- scoreTemp = 0.0;
|
|
|
- } else if (task.getScored() == null || !task.getScored()) {
|
|
|
- notScoredSceneNumber++;
|
|
|
- scoreTemp = 0.0;
|
|
|
- } else if (scoreTemp < 100.0) {
|
|
|
- notStandardSceneNumber++;
|
|
|
- } else if (scoreTemp == 100.0) {
|
|
|
- standardSceneNumber++;
|
|
|
- }
|
|
|
-
|
|
|
- leafSum += scoreTemp;
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ int errorSceneNumber = 0;
|
|
|
+ int notScoredSceneNumber = 0;
|
|
|
+ int notStandardSceneNumber = 0;
|
|
|
+ int standardSceneNumber = 0;
|
|
|
+ double leafSum = 0.0;
|
|
|
+ for (TaskEntity task : taskListOfLeafIndex) {
|
|
|
+ Double scoreTemp = task.getScore();
|
|
|
+ if (scoreTemp == null) {
|
|
|
+ errorSceneNumber++;
|
|
|
+ scoreTemp = 0.0;
|
|
|
+ } else if (task.getScored() == null || !task.getScored()) {
|
|
|
+ notScoredSceneNumber++;
|
|
|
+ scoreTemp = 0.0;
|
|
|
+ } else if (scoreTemp < 100.0) {
|
|
|
+ notStandardSceneNumber++;
|
|
|
+ } else if (scoreTemp == 100.0) {
|
|
|
+ standardSceneNumber++;
|
|
|
+ }
|
|
|
+
|
|
|
+ leafSum += scoreTemp;
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
- long taskNumberToScore = taskListOfLeafIndex.size();
|
|
|
- log.info("项目 " + projectId + " 的叶子指标 " + indexId + " 下参与计算的任务总数为 " + taskNumberToScore + ":仿真异常场景个数 " + errorSceneNumber + "、未达标场景个数 " + notStandardSceneNumber + "、达标场景个数 " + standardSceneNumber);
|
|
|
+
|
|
|
+ long taskNumberToScore = taskListOfLeafIndex.size();
|
|
|
+ log.info("项目 " + projectId + " 的叶子指标 " + indexId + " 下参与计算的任务总数为 " + taskNumberToScore + ":仿真异常场景个数 " + errorSceneNumber + "、未达标场景个数 " + notStandardSceneNumber + "、达标场景个数 " + standardSceneNumber);
|
|
|
|
|
|
-
|
|
|
- double leafIndexScore = NumberUtil.cut(leafSum / taskNumberToScore, 2);
|
|
|
-
|
|
|
- leafIndexTemplate.setTempScore(leafIndexScore);
|
|
|
+
|
|
|
+ double leafIndexScore = NumberUtil.cut(leafSum / taskNumberToScore, 2);
|
|
|
+
|
|
|
+ leafIndexTemplate.setTempScore(leafIndexScore);
|
|
|
|
|
|
- LeafIndexEntity leafIndex = LeafIndexEntity.builder().id(StringUtil.getRandomUUID()).pId(projectId).target(leafIndexTemplate.getIndexId()).errorSceneNum(errorSceneNumber).notScoredSceneNum(notScoredSceneNumber).notStandardSceneNum(notStandardSceneNumber).standardSceneNum(standardSceneNumber).score(leafIndexScore).indexId(indexId).parentId(parentId).rootId(rootId).weight(weight).scoreExplain(scoreExplain).packageLevel(packageLevel).build();
|
|
|
- leafIndex.setCreateUserId(userId);
|
|
|
- leafIndex.setCreateTime(TimeUtil.getNowForMysql());
|
|
|
- leafIndex.setModifyUserId(userId);
|
|
|
- leafIndex.setModifyTime(TimeUtil.getNowForMysql());
|
|
|
- leafIndex.setIsDeleted("0");
|
|
|
+ LeafIndexEntity leafIndex = LeafIndexEntity.builder().id(StringUtil.getRandomUUID()).pId(projectId).target(leafIndexTemplate.getIndexId()).errorSceneNum(errorSceneNumber).notScoredSceneNum(notScoredSceneNumber).notStandardSceneNum(notStandardSceneNumber).standardSceneNum(standardSceneNumber).score(leafIndexScore).indexId(indexId).parentId(parentId).rootId(rootId).weight(weight).scoreExplain(scoreExplain).packageLevel(packageLevel).build();
|
|
|
+ leafIndex.setCreateUserId(userId);
|
|
|
+ leafIndex.setCreateTime(TimeUtil.getNowForMysql());
|
|
|
+ leafIndex.setModifyUserId(userId);
|
|
|
+ leafIndex.setModifyTime(TimeUtil.getNowForMysql());
|
|
|
+ leafIndex.setIsDeleted("0");
|
|
|
|
|
|
- leafIndexList.add(leafIndex);
|
|
|
- }
|
|
|
-
|
|
|
- taskIndexManager.batchInsertLeafIndex(leafIndexList);
|
|
|
-
|
|
|
- log.info("项目 " + projectId + " 的所有任务分数为:" + taskList);
|
|
|
- computeFirst(leafIndexList, allIndexTemplateList, projectId, maxLevel);
|
|
|
- log.info("项目 " + projectId + " 打分完成!");
|
|
|
- }
|
|
|
+ leafIndexList.add(leafIndex);
|
|
|
+ }
|
|
|
+
|
|
|
+ taskIndexManager.batchInsertLeafIndex(leafIndexList);
|
|
|
+
|
|
|
+ log.info("项目 " + projectId + " 的所有任务分数为:" + taskList);
|
|
|
+ computeFirst(leafIndexList, allIndexTemplateList, projectId, maxLevel);
|
|
|
+ log.info("项目 " + projectId + " 打分完成!");
|
|
|
+ }
|
|
|
|
|
|
- public void computeFirst(List<LeafIndexEntity> leafIndexList, List<IndexTemplateEntity> allIndexTemplateList, String projectId, int maxLevel) {
|
|
|
+ public void computeFirst(List<LeafIndexEntity> leafIndexList, List<IndexTemplateEntity> allIndexTemplateList, String projectId, int maxLevel) {
|
|
|
|
|
|
- log.info("计算父指标得分:" + leafIndexList);
|
|
|
- Iterator<LeafIndexEntity> leafTaskIndexIterator = leafIndexList.iterator();
|
|
|
-
|
|
|
- while (leafTaskIndexIterator.hasNext()) {
|
|
|
- LeafIndexEntity leafTaskIndex = leafTaskIndexIterator.next();
|
|
|
- if (leafTaskIndex.getPackageLevel() == 1) {
|
|
|
- leafTaskIndex.setCreateUserId(leafTaskIndex.getCreateUserId());
|
|
|
- leafTaskIndex.setCreateTime(TimeUtil.getNowForMysql());
|
|
|
- leafTaskIndex.setModifyUserId(leafTaskIndex.getModifyUserId());
|
|
|
- leafTaskIndex.setModifyTime(TimeUtil.getNowForMysql());
|
|
|
- leafTaskIndex.setIsDeleted("0");
|
|
|
- indexMapper.insertFirstIndex(leafTaskIndex);
|
|
|
- leafTaskIndexIterator.remove();
|
|
|
- }
|
|
|
- }
|
|
|
- if (leafIndexList.size() > 0) {
|
|
|
- List<LeafIndexEntity> nextLevelIndexList = new ArrayList<>();
|
|
|
-
|
|
|
- leafIndexList.stream().filter(po -> maxLevel != po.getPackageLevel()).forEach(nextLevelIndexList::add);
|
|
|
-
|
|
|
- Map<String, List<LeafIndexEntity>> sonTaskIndexMap = leafIndexList.stream().filter(po -> maxLevel == po.getPackageLevel()).collect(Collectors.groupingBy(LeafIndexEntity::getParentId));
|
|
|
- Set<String> parentIdSet = sonTaskIndexMap.keySet();
|
|
|
- List<String> parentIdList = CollectionUtil.setToList(parentIdSet);
|
|
|
+ log.info("计算父指标得分:" + leafIndexList);
|
|
|
+ Iterator<LeafIndexEntity> leafTaskIndexIterator = leafIndexList.iterator();
|
|
|
+
|
|
|
+ while (leafTaskIndexIterator.hasNext()) {
|
|
|
+ LeafIndexEntity leafTaskIndex = leafTaskIndexIterator.next();
|
|
|
+ if (leafTaskIndex.getPackageLevel() == 1) {
|
|
|
+ leafTaskIndex.setCreateUserId(leafTaskIndex.getCreateUserId());
|
|
|
+ leafTaskIndex.setCreateTime(TimeUtil.getNowForMysql());
|
|
|
+ leafTaskIndex.setModifyUserId(leafTaskIndex.getModifyUserId());
|
|
|
+ leafTaskIndex.setModifyTime(TimeUtil.getNowForMysql());
|
|
|
+ leafTaskIndex.setIsDeleted("0");
|
|
|
+ indexMapper.insertFirstIndex(leafTaskIndex);
|
|
|
+ leafTaskIndexIterator.remove();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (leafIndexList.size() > 0) {
|
|
|
+ List<LeafIndexEntity> nextLevelIndexList = new ArrayList<>();
|
|
|
+
|
|
|
+ leafIndexList.stream().filter(po -> maxLevel != po.getPackageLevel()).forEach(nextLevelIndexList::add);
|
|
|
+
|
|
|
+ Map<String, List<LeafIndexEntity>> sonTaskIndexMap = leafIndexList.stream().filter(po -> maxLevel == po.getPackageLevel()).collect(Collectors.groupingBy(LeafIndexEntity::getParentId));
|
|
|
+ Set<String> parentIdSet = sonTaskIndexMap.keySet();
|
|
|
+ List<String> parentIdList = CollectionUtil.setToList(parentIdSet);
|
|
|
|
|
|
- List<IndexTemplateEntity> parentIndexTemplateList = allIndexTemplateList.stream().filter(indexTemplate -> parentIdList.contains(indexTemplate.getIndexId())).collect(Collectors.toList());
|
|
|
-
|
|
|
- parentIndexTemplateList.forEach(indexTemplate -> {
|
|
|
- String weight = indexTemplate.getWeight();
|
|
|
- List<LeafIndexEntity> sonTaskIndexList = sonTaskIndexMap.get(indexTemplate.getIndexId());
|
|
|
- double parentScore = NumberUtil.cut(sonTaskIndexList.stream().mapToDouble(taskIndex -> taskIndex.getScore() * Double.parseDouble(taskIndex.getWeight()) / 100).sum(), 2);
|
|
|
- LeafIndexEntity parentTaskIndex = LeafIndexEntity.builder().id(StringUtil.getRandomUUID()).pId(projectId).target(indexTemplate.getIndexId()).score(parentScore).indexId(indexTemplate.getIndexId()).parentId(indexTemplate.getParentId()).rootId(indexTemplate.getRootId()).weight(weight).packageLevel(maxLevel - 1).build();
|
|
|
- nextLevelIndexList.add(parentTaskIndex);
|
|
|
- });
|
|
|
-
|
|
|
- computeFirst(nextLevelIndexList, allIndexTemplateList, projectId, maxLevel - 1);
|
|
|
- }
|
|
|
- }
|
|
|
+ List<IndexTemplateEntity> parentIndexTemplateList = allIndexTemplateList.stream().filter(indexTemplate -> parentIdList.contains(indexTemplate.getIndexId())).collect(Collectors.toList());
|
|
|
+
|
|
|
+ parentIndexTemplateList.forEach(indexTemplate -> {
|
|
|
+ String weight = indexTemplate.getWeight();
|
|
|
+ List<LeafIndexEntity> sonTaskIndexList = sonTaskIndexMap.get(indexTemplate.getIndexId());
|
|
|
+ double parentScore = NumberUtil.cut(sonTaskIndexList.stream().mapToDouble(taskIndex -> taskIndex.getScore() * Double.parseDouble(taskIndex.getWeight()) / 100).sum(), 2);
|
|
|
+ LeafIndexEntity parentTaskIndex = LeafIndexEntity.builder().id(StringUtil.getRandomUUID()).pId(projectId).target(indexTemplate.getIndexId()).score(parentScore).indexId(indexTemplate.getIndexId()).parentId(indexTemplate.getParentId()).rootId(indexTemplate.getRootId()).weight(weight).packageLevel(maxLevel - 1).build();
|
|
|
+ nextLevelIndexList.add(parentTaskIndex);
|
|
|
+ });
|
|
|
+
|
|
|
+ computeFirst(nextLevelIndexList, allIndexTemplateList, projectId, maxLevel - 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- @SneakyThrows
|
|
|
- public void evaluationLevel(String projectId) {
|
|
|
- String tokenUrl = tokenUri + "?grant_type=client_credentials" + "&client_id=" + clientId + "&client_secret=" + clientSecret;
|
|
|
- log.info("获取仿真云平台 token:" + tokenUrl);
|
|
|
- String response = HttpUtil.get(closeableHttpClient, requestConfig, tokenUrl);
|
|
|
- ObjectMapper objectMapper = new ObjectMapper();
|
|
|
- JsonNode jsonNode = objectMapper.readTree(response);
|
|
|
- String accessToken = jsonNode.path("access_token").asText();
|
|
|
- log.info("仿真云平台 token 为:" + accessToken);
|
|
|
- Map<String, String> headers = new HashMap<>();
|
|
|
- headers.put("Authorization", "Bearer " + accessToken);
|
|
|
- Map<String, String> params = new HashMap<>();
|
|
|
- params.put("id", projectId);
|
|
|
- String post = HttpUtil.post(closeableHttpClient, requestConfig, evaluationLevelUri, headers, params);
|
|
|
- log.info("访问仿真云平台评价等级接口:" + evaluationLevelUri + ",请求头为:" + headers + ",请求体为:" + params + "结果为:" + post);
|
|
|
- }
|
|
|
+ @SneakyThrows
|
|
|
+ public void evaluationLevel(String projectId) {
|
|
|
+ String tokenUrl = tokenUri + "?grant_type=client_credentials" + "&client_id=" + clientId + "&client_secret=" + clientSecret;
|
|
|
+ log.info("获取仿真云平台 token:" + tokenUrl);
|
|
|
+ String response = HttpUtil.get(closeableHttpClient, requestConfig, tokenUrl);
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ JsonNode jsonNode = objectMapper.readTree(response);
|
|
|
+ String accessToken = jsonNode.path("access_token").asText();
|
|
|
+ log.info("仿真云平台 token 为:" + accessToken);
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
+ headers.put("Authorization", "Bearer " + accessToken);
|
|
|
+ Map<String, String> params = new HashMap<>();
|
|
|
+ params.put("id", projectId);
|
|
|
+ String post = HttpUtil.post(closeableHttpClient, requestConfig, evaluationLevelUri, headers, params);
|
|
|
+ log.info("访问仿真云平台评价等级接口:" + evaluationLevelUri + ",请求头为:" + headers + ",请求体为:" + params + "结果为:" + post);
|
|
|
+ }
|
|
|
|
|
|
|
|
|
- public Boolean taskConfirm(String taskId) {
|
|
|
-
|
|
|
- String state = taskMapper.selectStateById(taskId);
|
|
|
- return DictConstants.TASK_PENDING.equals(state);
|
|
|
- }
|
|
|
+ public Boolean taskConfirm(String taskId) {
|
|
|
+
|
|
|
+ String state = taskMapper.selectStateById(taskId);
|
|
|
+ return DictConstants.TASK_PENDING.equals(state);
|
|
|
+ }
|
|
|
|
|
|
- public void taskTick(String taskId) {
|
|
|
- log.info("收到任务 " + taskId + " 的心跳。");
|
|
|
- TaskEntity taskEntity = taskMapper.selectById(taskId);
|
|
|
- String projectId = taskEntity.getPId();
|
|
|
- String userId = taskEntity.getCreateUserId();
|
|
|
-
|
|
|
- PrefixEntity redisPrefix = projectUtil.getRedisPrefixByUserIdAndProjectIdAndTaskId(userId, projectId, taskId);
|
|
|
- if (RedisUtil.getStringByKey(stringRedisTemplate, redisPrefix.getProjectRunningKey()) != null) {
|
|
|
- stringRedisTemplate.opsForValue().set(redisPrefix.getTaskTickKey(), TimeUtil.getNowString());
|
|
|
- }
|
|
|
+ public void taskTick(String taskId) {
|
|
|
+ log.info("收到任务 " + taskId + " 的心跳。");
|
|
|
+ TaskEntity taskEntity = taskMapper.selectById(taskId);
|
|
|
+ String projectId = taskEntity.getPId();
|
|
|
+ String userId = taskEntity.getCreateUserId();
|
|
|
+
|
|
|
+ PrefixEntity redisPrefix = projectUtil.getRedisPrefixByUserIdAndProjectIdAndTaskId(userId, projectId, taskId);
|
|
|
+ if (RedisUtil.getStringByKey(stringRedisTemplate, redisPrefix.getProjectRunningKey()) != null) {
|
|
|
+ stringRedisTemplate.opsForValue().set(redisPrefix.getTaskTickKey(), TimeUtil.getNowString());
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
- @SneakyThrows
|
|
|
- public void done(PrefixEntity redisPrefix, String projectId, String projectType) {
|
|
|
-
|
|
|
- if (DictConstants.PROJECT_TYPE_MANUAL.equals(projectType)) {
|
|
|
- manualProjectMapper.updateProjectState(projectId, DictConstants.PROJECT_COMPLETED, TimeUtil.getNowForMysql());
|
|
|
- } else if (DictConstants.PROJECT_TYPE_AUTO_SUB.equals(projectType)) {
|
|
|
- autoSubProjectMapper.updateProjectState(projectId, DictConstants.PROJECT_COMPLETED, TimeUtil.getNowForMysql());
|
|
|
- }
|
|
|
-
|
|
|
- ApacheKafkaUtil.deleteTopic(admin, projectId);
|
|
|
-
|
|
|
- RedisUtil.deleteByPrefix(stringRedisTemplate, redisPrefix.getProjectRunningKey());
|
|
|
- RedisUtil.deleteByPrefix(stringRedisTemplate, "project:" + projectId);
|
|
|
-
|
|
|
- projectUtil.deleteYamlByProjectId(projectId);
|
|
|
- }
|
|
|
+ @SneakyThrows
|
|
|
+ public void done(PrefixEntity redisPrefix, String projectId, String projectType) {
|
|
|
+
|
|
|
+ if (DictConstants.PROJECT_TYPE_MANUAL.equals(projectType)) {
|
|
|
+ manualProjectMapper.updateProjectState(projectId, DictConstants.PROJECT_COMPLETED, TimeUtil.getNowForMysql());
|
|
|
+ } else if (DictConstants.PROJECT_TYPE_AUTO_SUB.equals(projectType)) {
|
|
|
+ autoSubProjectMapper.updateProjectState(projectId, DictConstants.PROJECT_COMPLETED, TimeUtil.getNowForMysql());
|
|
|
+ }
|
|
|
+
|
|
|
+ ApacheKafkaUtil.deleteTopic(admin, projectId);
|
|
|
+
|
|
|
+ RedisUtil.deleteByPrefix(stringRedisTemplate, redisPrefix.getProjectRunningKey());
|
|
|
+ RedisUtil.deleteByPrefix(stringRedisTemplate, "project:" + projectId);
|
|
|
+
|
|
|
+ projectUtil.deleteYamlByProjectId(projectId);
|
|
|
+ }
|
|
|
|
|
|
|
|
|
}
|