LingxinMeng 2 vuotta sitten
vanhempi
commit
c1df194a8c

+ 9 - 5
api-common/src/main/java/api/common/util/HttpUtil.java

@@ -225,12 +225,16 @@ public class HttpUtil {
      *
      * @param url 请求地址
      * @return 文件流
-     * @throws IOException 异常
      */
-    public static InputStream getInputStream(String url) throws IOException {
-        CloseableHttpClient closeableHttpClient = getCloseableHttpClient();
-        RequestConfig requestConfig = getRequestConfig();
-        return getInputStream(closeableHttpClient, requestConfig, url, null);
+    public static InputStream getInputStream(String url) {
+        try {
+            log.info("发送请求:" + url);
+            CloseableHttpClient closeableHttpClient = getCloseableHttpClient();
+            RequestConfig requestConfig = getRequestConfig();
+            return getInputStream(closeableHttpClient, requestConfig, url, null);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
     }
 
     /**

+ 5 - 8
simulation-resource-monitor/src/main/java/com/css/simulation/resource/monitor/acl/entity/AlgorithmExpandAclEntity.java

@@ -1,15 +1,12 @@
 package com.css.simulation.resource.monitor.acl.entity;
 
 import com.fasterxml.jackson.annotation.JsonAlias;
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-import lombok.Data;
-import lombok.NoArgsConstructor;
 
-@Data
-@AllArgsConstructor
-@NoArgsConstructor
-@Builder
+
+@lombok.Data
+@lombok.Builder
+@lombok.NoArgsConstructor
+@lombok.AllArgsConstructor
 public class AlgorithmExpandAclEntity {
     @JsonAlias({"id"})
     private String id = "";

+ 0 - 1
simulation-resource-monitor/src/main/java/com/css/simulation/resource/monitor/acl/service/impl/AlgorithmExpandAclServiceImpl.java

@@ -24,7 +24,6 @@ public class AlgorithmExpandAclServiceImpl implements AlgorithmExpandAclService
     private AlgorithmExpandConfigurationAclEntity algorithmExpandConfigurationAclEntity;
     @Resource
     private CustomRedisClient customRedisClient;
-    @Resource
 
 
     /**

+ 5 - 4
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/application/service/ProjectApplicationService.java

@@ -737,7 +737,7 @@ public class ProjectApplicationService {
                 throw new RuntimeException("算法 " + algorithmId + " 的 mysql 数据有误!");
             }
         } else {
-            log.debug("项目" + projectId + "使用索为平台算法 " + algorithmId);
+            log.info("项目" + projectId + "使用索为平台算法 " + algorithmId);
             algorithmTarLinuxTempPath = linuxTempPath + "algorithm/" + algorithmId + ".tar";
             String dockerImageWithoutVersion = dockerConfiguration.getRegistry() + "/algorithm_" + algorithmId;
             dockerImage = dockerImageWithoutVersion + ":latest";
@@ -748,15 +748,16 @@ public class ProjectApplicationService {
                 String tokenJson = HttpUtil.get(tokenUrl);
                 String token = new ObjectMapper().readTree(tokenJson).path("data").path("access_token").asText();
                 //2 获取 下载地址
-                String downloadUrl = customConfiguration.getAlgorithmPlatformAlgorithmAddrUri() + "?access_token=" + token + "&id=" + algorithmId;
+                String idOfAlgorithm = algorithmExpandMapper.selectIdByAlgorithmId(AlgorithmExpandEntity.builder().algorithmId(algorithmId).build());
+                String downloadUrl = customConfiguration.getAlgorithmPlatformAlgorithmAddrUri() + "?access_token=" + token + "&id=" + idOfAlgorithm;
                 //3 下载算法包
                 String downloadUrlJson = HttpUtil.get(downloadUrl);
                 String tempDownloadUrl = new ObjectMapper().readTree(downloadUrlJson).path("data").asText();
                 InputStream inputStream = HttpUtil.getInputStream(tempDownloadUrl);
                 FileUtil.writeInputStreamToLocalFile(inputStream, algorithmTarLinuxTempPath);
                 // 本地执行 docker import 算法文件成镜像(可改成用 docker-java 操作仓库)
-                LinuxUtil.execute("docker import " + algorithmTarLinuxTempPath + " " + dockerImage);
-                LinuxUtil.execute("docker push " + dockerImage);
+                OsUtil.exec("docker import " + algorithmTarLinuxTempPath + " " + dockerImage);
+                OsUtil.exec("docker push " + dockerImage);
                 FileUtil.rm(algorithmTarLinuxTempPath);
                 log.info("已删除算法临时文件:" + algorithmTarLinuxTempPath);
             } else {

+ 21 - 12
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/domain/service/TaskDomainService.java

@@ -109,7 +109,7 @@ public class TaskDomainService {
         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);
+        log.debug("共有 " + leafIndexTemplateList.size() + "个叶子节点:" + leafIndexTemplateListJson);
         int maxLevel = 1; // 用于计算指标得分
         List<LeafIndexEntity> leafIndexList = new ArrayList<>();
         for (int i = 0; i < leafIndexTemplateList.size(); i++) {
@@ -152,17 +152,26 @@ public class TaskDomainService {
                 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; // 指定打分脚本
+                    final String runResultFilePath = taskOfLeaf.getRunResultFilePath();
+                    final ArrayList<String> csvResultFilePaths = CollectionUtil.createArrayList(
+                            runResultFilePath + "/Ego.csv",
+                            runResultFilePath + "/evaluation.csv",
+                            runResultFilePath + "/output_objectState_sensor.csv",
+                            runResultFilePath + "/output_objectState.csv",
+                            runResultFilePath + "/output_roadMark.csv",
+                            runResultFilePath + "/output_roadPos.csv",
+                            runResultFilePath + "/output_trafficSignal.csv"
+                    );
+                    for (String csvResultFileMinioPath : csvResultFilePaths) {
+                        String csvResultFileLinuxPath = linuxTempPath + csvResultFileMinioPath;
+                        log.info("下载MINIO上的结果文件:" + csvResultFileMinioPath + " 到LINUX:" + csvResultFileLinuxPath);
+                        MinioUtil.downloadToFile(minioClient, bucketName, csvResultFileMinioPath, csvResultFileLinuxPath);  // 也可改成下载到指定ip的服务器上,需要保证和打分脚本在一台机器上。
+                    }
+
+                    String scoreCommand = "python3 " + scoreDirectoryOfUser + "main.py " + (linuxTempPath + runResultFilePath + "/Ego.csv") + " " + (linuxTempPath + runResultFilePath + "/evaluation.csv") + " " + taskOfLeaf.getSceneType() + " " + ruleName; // 指定打分脚本
                     String scoreResult;
                     ScoreEntity score = null;
-                    log.debug("下载 minio 上的结果文件 " + result1OfMinio + " 和 " + result2OfMinio + " 到临时目录:" + linuxTempPath);
-                    MinioUtil.downloadToFile(minioClient, bucketName, result1OfMinio, result1OfLinux);  // 也可改成下载到指定ip的服务器上,需要保证和打分脚本在一台机器上。
-                    MinioUtil.downloadToFile(minioClient, bucketName, result2OfMinio, result2OfLinux);  // 也可改成下载到指定ip的服务器上,需要保证和打分脚本在一台机器上。
-                    log.debug("开始执行打分命令:" + scoreCommand);
+                    log.info("开始执行打分命令:" + scoreCommand);
                     Runtime r = Runtime.getRuntime();
                     Process p = r.exec(scoreCommand, null, new File(scoreDirectoryOfUser));
                     BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
@@ -172,7 +181,7 @@ public class TaskDomainService {
                         sb.append(inline).append("\n");
                     }
                     scoreResult = sb.toString();
-                    log.debug("项目" + projectId + " 的任务 " + task2Id + " 打分结束,结果为:" + scoreResult);
+                    log.info("项目" + projectId + " 的任务 " + task2Id + " 打分结束,结果为:" + scoreResult);
                     String replace = StringUtil.replace(scoreResult, "'", "\"");
                     try {
                         score = JsonUtil.jsonToBean(replace, ScoreEntity.class);
@@ -356,7 +365,7 @@ public class TaskDomainService {
         // 查询并保存项目报告
         projectDomainService.selectProjectReportById(projectType, projectId);
         // 如果使用算法平台算法则修改状态为测试完成
-        projectDomainService.checkAlgorithmIsExpand(projectType,projectId,DictConstants.ALGORITHM_EXPAND_STATUS_TESTED);
+        projectDomainService.checkAlgorithmIsExpand(projectType, projectId, DictConstants.ALGORITHM_EXPAND_STATUS_TESTED);
     }
 
 

+ 2 - 0
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/infrastructure/db/mysql/mapper/AlgorithmExpandMapper.java

@@ -6,4 +6,6 @@ import org.apache.ibatis.annotations.Mapper;
 @Mapper
 public interface AlgorithmExpandMapper {
     void updateStatusByAlgorithmId(AlgorithmExpandEntity algorithmExpandEntity);
+
+    String selectIdByAlgorithmId(AlgorithmExpandEntity build);
 }

+ 3 - 2
simulation-resource-scheduler/src/main/resources/logback-spring.xml

@@ -20,7 +20,8 @@
         </encoder>
     </appender>
 
-    <!--输出到debug-->
+
+    <!--输出到info-->
     <appender name="debug" class="ch.qos.logback.core.rolling.RollingFileAppender">
         <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
             <!--日志文件输出的文件名-->
@@ -35,7 +36,7 @@
             <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{5}.%M\(%F:%L\) %msg %n</pattern>
             <charset>utf-8</charset>
         </encoder>
-        <filter class="ch.qos.logback.classic.filter.LevelFilter"><!-- 只打印DEBUG日志 -->
+        <filter class="ch.qos.logback.classic.filter.LevelFilter"><!-- 只打印INFO日志 -->
             <level>DEBUG</level>
             <onMatch>ACCEPT</onMatch>
             <onMismatch>DENY</onMismatch>

+ 3 - 0
simulation-resource-scheduler/src/main/resources/mysql/mapper/AlgorithmExpandMapper.xml

@@ -8,4 +8,7 @@
         set status = #{status}
         where algorithm_id = #{algorithmId}
     </update>
+    <select id="selectIdByAlgorithmId" resultType="java.lang.String">
+        select id from algorithm_expand where algorithm_id = #{algorithmId}
+    </select>
 </mapper>