root 2 年之前
父节点
当前提交
18db339c64

+ 43 - 32
api-common/src/main/java/api/common/util/HttpUtil.java

@@ -1,5 +1,6 @@
 package api.common.util;
 
+import lombok.extern.slf4j.Slf4j;
 import org.apache.http.client.config.RequestConfig;
 import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpGet;
@@ -31,6 +32,7 @@ import java.util.Map;
  * <version>${http.client.version}</version>
  * </dependency>
  */
+@Slf4j
 public class HttpUtil {
 
     public static CloseableHttpClient getHttpClient() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
@@ -63,27 +65,32 @@ public class HttpUtil {
 
 
     /**
-     * 普通 get 请求
+     * 默认请求头的 get 请求
      *
      * @param closeableHttpClient http 客户端
      * @param requestConfig       请求配置
      * @param url                 请求路径带参数
      * @return 请求结果
-     * @throws IOException IO异常
      */
-    public static String get(CloseableHttpClient closeableHttpClient, RequestConfig requestConfig, String url) throws IOException {
-        //1 创建 post 请求
-        HttpGet get = new HttpGet(url);
-        get.setConfig(requestConfig);
-        //2 发送请求
-        CloseableHttpResponse response = closeableHttpClient.execute(get);
-        //3 处理返回结果,如果状态码为200,就是正常返回
-        int statusCode = response.getStatusLine().getStatusCode();
-        if (statusCode == 200) {
-            return EntityUtils.toString(response.getEntity());
-        } else {
-            throw new RuntimeException("------- 请求错误:" + statusCode);
+    public static String get(CloseableHttpClient closeableHttpClient, RequestConfig requestConfig, String url) {
+        String result = null;
+        try {
+            //1 创建 post 请求
+            HttpGet get = new HttpGet(url);
+            get.setConfig(requestConfig);
+            //2 发送请求
+            CloseableHttpResponse response = closeableHttpClient.execute(get);
+            //3 处理返回结果,如果状态码为200,就是正常返回
+            int statusCode = response.getStatusLine().getStatusCode();
+            if (statusCode == 200) {
+                result = EntityUtils.toString(response.getEntity());
+            } else {
+                throw new RuntimeException("------- 请求错误:" + statusCode);
+            }
+        } catch (Exception e) {
+            log.info("请求 " + url + " 失败。", e);
         }
+        return result;
     }
 
     /**
@@ -129,7 +136,6 @@ public class HttpUtil {
     public static InputStream getInputStream(CloseableHttpClient closeableHttpClient, RequestConfig requestConfig, String url) throws IOException {
         return getInputStream(closeableHttpClient, requestConfig, url, null);
     }
-
     /**
      * 自定义请求头的 get 请求下载文件
      *
@@ -139,24 +145,29 @@ public class HttpUtil {
      * @throws IOException 异常
      */
     public static InputStream getInputStream(CloseableHttpClient closeableHttpClient, RequestConfig requestConfig, String url, Map<String, String> headers) throws IOException {
-        //1 创建 post 请求
-        HttpGet get = new HttpGet(url);
-        //2 设置请求默认配置
-        get.setConfig(requestConfig);
-        //3 设置请求头 post.setHeader("Content-type", "application/json; charset=utf-8");
-        if (!CollectionUtil.isEmpty(headers)) {
-            headers.forEach(get::setHeader);
-        }
-        //4 发送请求
-        CloseableHttpResponse response = closeableHttpClient.execute(get);
-        //5 处理返回结果,
-        //5-1 如果状态码为200,就是正常返回
-        int statusCode = response.getStatusLine().getStatusCode();
-        if (statusCode == 200) {
-            return response.getEntity().getContent();
-        } else {
-            throw new RuntimeException("------- 请求错误:" + statusCode);
+        InputStream result = null;
+        try {
+            //1 创建 post 请求
+            HttpGet get = new HttpGet(url);
+            //2 设置请求默认配置
+            get.setConfig(requestConfig);
+            //3 设置请求头 post.setHeader("Content-type", "application/json; charset=utf-8");
+            if (!CollectionUtil.isEmpty(headers)) {
+                headers.forEach(get::setHeader);
+            }
+            //4 发送请求
+            CloseableHttpResponse response = closeableHttpClient.execute(get);
+            //5 处理返回结果,
+            //5-1 如果状态码为200,就是正常返回
+            int statusCode = response.getStatusLine().getStatusCode();
+            log.info("请求 " + url + " 状态码为:" + statusCode);
+            if (statusCode == 200) {
+                result = response.getEntity().getContent();
+            }
+        } catch (Exception e) {
+            log.info("请求 " + url + " 失败。", e);
         }
+        return result;
     }
 
     /**

+ 0 - 1
simulation-resource-scheduler/pom.xml

@@ -58,7 +58,6 @@
         <dependency>
             <groupId>org.apache.kafka</groupId>
             <artifactId>kafka-clients</artifactId>
-            <version>${kafka-clients.version}</version>
         </dependency>
         <dependency>
             <groupId>org.springframework.kafka</groupId>

+ 5 - 5
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/consumer/ProjectConsumer.java

@@ -103,7 +103,7 @@ public class ProjectConsumer {
         String projectId = projectMessageDTO.getProjectId();        // 手动执行项目 id 或 自动执行子项目 id
         String packageId = projectMessageDTO.getScenePackageId();   // 场景测试包 id
         String vehicleConfigId = projectMessageDTO.getVehicleConfigId();// 模型配置 id
-        String algorithmId = projectMessageDTO.getVehicleConfigId();// 模型配置 id
+        String algorithmId = projectMessageDTO.getAlgorithmId();// 模型配置 id
         long videoTime = projectMessageDTO.getMaxSimulationTime();  // 结果视频的时长
         String projectType = projectMessageDTO.getType();           // 项目类型
         String userId = "";  // 用户 id
@@ -408,7 +408,7 @@ public class ProjectConsumer {
         String algorithmDockerImage = algorithmMapper.selectDockerImageById(algorithmId);
         // -------------------------------- 4 发送任务消息 --------------------------------
         List<NodeTO> nodeListToCount = projectUtil.getNodeListToCount(nodeMap);
-        final int[] messageNumber = CollectionUtil.createIntArray(0);
+        int messageNumber = 0;
         ApacheKafkaUtil.createTopic(kafkaAdminClient, projectId, realCurrentParallelism, (short) 1);   // 创建主题
         for (String taskJsonPath : taskJsonList) {
             String taskId = FileUtil.getFilenameWithoutSuffix(taskJsonPath);
@@ -422,7 +422,7 @@ public class ProjectConsumer {
 
             //4-5 将 projectId 作为 topic 名称,根据 parallelism 分散发送 task 信息到 kafka
 
-            kafkaTemplate.send(projectId, messageNumber[0] % currentParallelism, "", taskJson)
+            kafkaTemplate.send(projectId, messageNumber % currentParallelism, "", taskJson)
                     .addCallback(success -> {
                         // 消息发送到的topic
                         String topic = success.getRecordMetadata().topic();
@@ -450,10 +450,10 @@ public class ProjectConsumer {
                         projectManager.createTempYaml(projectId, algorithmDockerImage, currentNodeNameValue, partition
                                 , offset, currentCountValue);
                     }, failure -> log.error("------- 发送消息失败:" + failure.getMessage()));
-            messageNumber[0] = messageNumber[0] + 1;
+            messageNumber++;
 
         }
-        log.info("ProjectService--sendTaskMessage 共发送了 " + messageNumber[0] + " 条消息!");
+        log.info("ProjectService--sendTaskMessage 共发送了 " + messageNumber + " 条消息!");
     }
 
     @KafkaListener(groupId = "simulation-resource-scheduler", topics = "${scheduler.stop-topic}")

+ 4 - 3
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/manager/TaskManager.java

@@ -157,6 +157,7 @@ public class TaskManager {
                     if (DictConstants.PROJECT_TYPE_AUTO_SUB.equals(projectType)) {
                         isChoiceGpu = autoSubProjectMapper.selectIsChoiceGpuById(projectId);
                     }
+                    log.info("项目 " + projectId + " 是否需要生成 gpu 视频:" + isChoiceGpu);
                     if (DictConstants.NO.equals(isChoiceGpu)) {
                         FutureTask<ResponseBodyVO<String>> videoTask = new FutureTask<>(() -> videoService.generateVideo(projectId, projectType, maxSimulationTime, taskId));
                         new Thread(videoTask, "video-" + StringUtil.getRandomEightBitUUID()).start();
@@ -532,15 +533,15 @@ public class TaskManager {
 
         // 删除 redis 中的 项目运行信息 键值对
         RedisUtil.deleteByPrefix(stringRedisTemplate, redisPrefix.getProjectRunningKey());
-
+        RedisUtil.deleteByPrefix(stringRedisTemplate, "project:" + projectId + ":package:");
+        // 删除剩余 yaml
+        projectUtil.deleteYamlByProjectId(projectId);
         if (DictConstants.PROJECT_TYPE_MANUAL.equals(projectType)) {
             log.info("TaskManager--done 手动运行项目 " + projectId + " 执行完成!");
         } else if (DictConstants.PROJECT_TYPE_AUTO_SUB.equals(projectType)) {
             log.info("TaskManager--done 自动运行子项目 " + projectId + " 执行完成!");
         }
 
-        // 删除剩余 yaml
-        projectUtil.deleteYamlByProjectId(projectId);
 
     }
 

+ 1 - 1
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/service/ProjectService.java

@@ -433,7 +433,7 @@ public class ProjectService {
         String dockerImage;
         String algorithmDirectoryLinuxTempPath;
         String algorithmTarLinuxTempPath = null;
-        if (algorithmPO != null) { // 使用仿真平台自己的算法
+        if (algorithmPO != null) { // 使用仿真平台自己的算法(等于null时有两种可能,除了是索为平台算法,也有可能是数据被彻底删除了)
             String algorithmCode = algorithmPO.getAlgorithmCode();
             String dockerImport = algorithmPO.getDockerImport();
             dockerImage = dockerConfiguration.getRegistry() + "/algorithm_" + algorithmCode + ":latest";

+ 2 - 2
simulation-resource-server/src/main/java/com/css/simulation/resource/home/mapper/HomePageMapper.java

@@ -80,7 +80,7 @@ public interface HomePageMapper {
             "where smpt.is_deleted = '0'\n" +
             "  and (smp.is_deleted = '0' or sas.is_deleted = '0')\n" +
             "  and (smp.now_run_state = '20' or sas.now_run_state = '20')\n" +
-            "  and smpt.run_state in ('Pending', 'Running', 'PendingAnalysis', 'Analysing')\n" +
+            "  and smpt.run_state in ('Running')\n" +
             "  and smpt.create_user_id = #{currentUserId}")
-    Integer getRunningTask(@Param("currentUserId") String currentUserId);
+    int selectRunningTask(@Param("currentUserId") String currentUserId);
 }

+ 7 - 10
simulation-resource-server/src/main/java/com/css/simulation/resource/home/service/HomePageService.java

@@ -94,26 +94,23 @@ public class HomePageService {
     public List<LineChartVO> selectAccess() {
         String dateBegin = TimeUtil.getMinusDaysStr(6);
         List<LineChartVO> listVo = logMapper.getAccessCount(dateBegin);
-        List<LineChartVO> list = makeLineChartDate(listVo, 6);
-        return list;
+        return makeLineChartDate(listVo, 6);
     }
 
     public List<LineChartVO> selectRunTaskChart() {
-        Map<String, String> param = new HashMap();
+        Map<String, String> param = new HashMap<>();
         param.put("dateBegin", TimeUtil.getMinusDaysStr(6));
         param.put("createUserId", AuthUtil.getCurrentUserId());
         List<LineChartVO> listVo = homePageMapper.selectRunTaskChart(param);
-        List<LineChartVO> list = makeLineChartDate(listVo, 6);
-        return list;
+        return makeLineChartDate(listVo, 6);
     }
 
     public List<LineChartVO> selectRunProjectChart() {
-        Map<String, String> param = new HashMap();
+        Map<String, String> param = new HashMap<>();
         param.put("dateBegin", TimeUtil.getMinusDaysStr(6));
         param.put("createUserId", AuthUtil.getCurrentUserId());
         List<LineChartVO> listVo = homePageMapper.selectRunProjectChart(param);
-        List<LineChartVO> list = makeLineChartDate(listVo, 6);
-        return list;
+        return makeLineChartDate(listVo, 6);
     }
 
     /**
@@ -141,7 +138,7 @@ public class HomePageService {
         return list;
     }
 
-    public Integer getRunningTask() {
-        return homePageMapper.getRunningTask(AuthUtil.getCurrentUserId());
+    public int getRunningTask() {
+        return homePageMapper.selectRunningTask(AuthUtil.getCurrentUserId());
     }
 }

+ 6 - 6
simulation-resource-server/src/main/java/com/css/simulation/resource/project/impl/SimulationProjectServiceImpl.java

@@ -1153,20 +1153,20 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
         Optional.ofNullable(param.getId()).orElseThrow(() -> new RuntimeException("项目 id 不能为空"));
         Optional.ofNullable(param.getTaskId()).orElseThrow(() -> new RuntimeException("任务 id 不能为空"));
         Optional.ofNullable(param.getTaskId()).orElseThrow(() -> new RuntimeException("projectType 不能为空"));
-        String id = param.getId();  // fb5b576d962d4077955c1a7c03284309
-        String taskId = param.getTaskId();  // e4ba02667b5f4393a9f3a7a3e33d3e90
+        String id = param.getId();
+        String taskId = param.getTaskId();
         String projectType = param.getProjectType();    // 2
         //2 查询任务信息,手动项目和自动项目共用一个任务表
         ProjectTaskParam projectTaskParam = new ProjectTaskParam();
-        projectTaskParam.setPId(id);    // fb5b576d962d4077955c1a7c03284309
-        projectTaskParam.setId(taskId); // e4ba02667b5f4393a9f3a7a3e33d3e90
+        projectTaskParam.setPId(id);
+        projectTaskParam.setId(taskId);
         List<ManualProjectTaskPo> pos = simulationProjectTaskMapper.selectProjectTask(projectTaskParam);
         if (CollectionUtil.isEmpty(pos)) {
             return new ResponseBodyVO<>(ResponseBodyVO.Response.SERVER_FAILURE, "没有获取到任务信息。");
         }
         ManualProjectTaskPo po = pos.get(0);
-        resultVo.setTaskId(po.getId()); // e4ba02667b5f4393a9f3a7a3e33d3e90
-        String sceneId = po.getSceneId();   // 82ee1b3f2c2441949006ae482b80bc08
+        resultVo.setTaskId(po.getId());
+        String sceneId = po.getSceneId();
         String sceneType = po.getSceneType();   // 4
         SceneBaseInfoVo sceneBaseInfoVo = getSceneNameAndOther(sceneId, sceneType); //  ACC_2-5-1
         resultVo.setSceneName(sceneBaseInfoVo.getCommonSceneName());    //  ACC_2-5-1