martin 3 년 전
부모
커밋
c2cd0d8674

+ 1 - 1
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/consumer/ManualProjectConsumer.java

@@ -94,7 +94,7 @@ public class ManualProjectConsumer {
         String projectJson = projectRecord.value();
         ProjectMessageDTO projectMessageDTO = JsonUtil.jsonToBean(projectJson, ProjectMessageDTO.class);
         String projectId = projectMessageDTO.getProjectId();    // 项目 id
-        projectMapper.updateProjectState(projectId, "20");   // 修改该 project 的状态为执行中
+        projectMapper.updateProjectState(projectId, "20");   // 修改该 project 的状态为执行中,同时将已完成任务重置为0方便测试
 
 
         // -------------------------------- 1 场景 --------------------------------

+ 2 - 1
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/mapper/ProjectMapper.java

@@ -20,7 +20,8 @@ public interface ProjectMapper {
     ProjectPO selectById(@Param("taskId")String taskId);
 
     @Update("update simulation_manual_project\n" +
-            "set now_run_state = #{state}\n" +
+            "set now_run_state  = #{state},\n" +
+            "    task_completed = '0'\n" +
             "where id = #{id}")
     void updateProjectState(@Param("id") String id, @Param("state") String state);
 

+ 14 - 8
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/service/TaskService.java

@@ -27,6 +27,7 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.data.redis.core.StringRedisTemplate;
 import org.springframework.stereotype.Service;
 
+import java.io.IOException;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -161,15 +162,20 @@ public class TaskService {
 //                        String command = "python3 " + pyPath + " " + runResultLinux + " " + task2.getSceneType();  // 默认使用场景名称找打分脚本
                         String command = "python3 " + pyPath + "main.py " + runResultLinux + " " + task2.getSceneType() + " " + ruleName; // 指定打分脚本
                         try {
-                            log.info("------- /state 下载 minio 上的结果文件 " + runResultMinio + " 到本地:" + runResultLinux);
-                            MinioUtil.downloadToFile(minioClient, bucketName, runResultMinio, runResultLinux);
-                            log.info("------- /state 开始执行打分命令:" + command);
-
-                            score = JsonUtil.jsonToBean(SshUtil.execute(session, command), ScoreTO.class);
-
-                            log.info("------- /state 打分结束,结果为:" + score);
+                            try {
+                                log.info("------- /state 下载 minio 上的结果文件 " + runResultMinio + " 到本地:" + runResultLinux);
+                                MinioUtil.downloadToFile(minioClient, bucketName, runResultMinio, runResultLinux);
+                            } catch (Exception e) {
+                                throw new RuntimeException("------- /state 下载 minio 上的结果文件出错:" + e.getMessage());
+                            }
+                            try {
+                                log.info("------- /state 开始执行打分命令:" + command);
+                                score = JsonUtil.jsonToBean(SshUtil.execute(session, command), ScoreTO.class);
+                                log.info("------- /state 打分结束,结果为:" + score);
+                            } catch (IOException e) {
+                                throw new RuntimeException("------- /state 任务 " + task2Id + " 打分出错,命令为:" + command + " 修改状态为:" + DictConstants.TASK_ABORTED + "\n" + e.getMessage());
+                            }
                         } catch (Exception e) {
-                            log.error("------- /state 任务 " + task2Id + " 打分出错,命令为:" + command + " 修改状态为:" + DictConstants.TASK_ABORTED);
                             taskMapper.updateState(task2Id, DictConstants.TASK_ABORTED);
                             throw new RuntimeException(e.getMessage());
                         }

+ 2 - 5
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/util/MinioUtil.java

@@ -1,10 +1,7 @@
 package com.css.simulation.resource.scheduler.util;
 
 import io.minio.*;
-import io.minio.errors.ErrorResponseException;
-import io.minio.errors.InsufficientDataException;
-import io.minio.errors.InvalidResponseException;
-import io.minio.errors.XmlParserException;
+import io.minio.errors.*;
 import io.minio.http.Method;
 import jdk.nashorn.internal.runtime.regexp.joni.exception.InternalException;
 import org.springframework.web.multipart.MultipartFile;
@@ -111,7 +108,7 @@ public class MinioUtil {
             String bucketName,
             String objectName,
             String targetFilePath
-    ) throws IOException, InsufficientDataException, ErrorResponseException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException, io.minio.errors.ServerException, io.minio.errors.InternalException {
+    ) throws IOException, ServerException, InsufficientDataException, ErrorResponseException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, io.minio.errors.InternalException {
         minioClient.downloadObject(DownloadObjectArgs.builder()
                 .bucket(bucketName)
                 .object(objectName)