ソースを参照

控制gpu视频生成

root 2 年 前
コミット
0ce14b2958

+ 4 - 0
api-common/src/main/java/api/common/pojo/constants/DictConstants.java

@@ -43,6 +43,10 @@ public class DictConstants {
     public static final String YES = "1";//是
     public static final String NO = "0";//否
 
+    public static final String USE_GPU = "0";//是
+    public static final String NOT_USE_GPU = "1";//否
+
+
     public static final String IS_SHARED = "1";//是
     public static final String IS_DELETED = "1";//是
     public static final String IS_NOT_SHARED = "0";//否

+ 2 - 0
api-common/src/main/java/api/common/pojo/dto/ProjectMessageDTO.java

@@ -33,5 +33,7 @@ public class ProjectMessageDTO {
     private Integer currentParallelism;// 当前正在使用的并行度
     private Integer taskTotal;// 任务总数量
     private Integer taskCompleted;// 任务已完成数量
+    //* -------------------------------- Comment --------------------------------
+    private String isChoiceGpu; //0是1否
 
 }

+ 1 - 11
api-common/src/main/java/api/common/pojo/vo/project/SceneScListVo.java

@@ -9,29 +9,19 @@ import lombok.Setter;
 public class SceneScListVo {
 
     private String sublistName1;
-
     private String sublistName2;
-
     private String sublistName3;
-
     private String sublistName4;
-
     private String sublistName5;
-
     private String sublistName6;
-
     private String sceneId;
-
     private String sceneIdType;
-
     private String sceneScore;
-
     private String targetEvaluate;
-
     private String scoreExplain;
-
     //运行状态
     private String runState;
+    private String eachMaxIndex;
 
 
 }

+ 4 - 1
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/configuration/kubernetes/KubernetesConfiguration.java

@@ -21,7 +21,10 @@ public class KubernetesConfiguration {
 
     private String namespace;
     private String podTimeout;
-    private String vtdImage;
+    private String vtdImageUseGpu;
+    private String vtdImageNotUseGpu;
+    private String vtdCommandUseGpu;
+    private String vtdCommandNotUseGpu;
     private List<KubernetesNodeTO> nodeList;
 
     @Bean

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

@@ -102,6 +102,8 @@ public class ProjectConsumer {
         String initialProjectJson = projectRecord.value();
         ProjectMessageDTO projectMessageDTO = JsonUtil.jsonToBean(initialProjectJson, ProjectMessageDTO.class);
         String projectId = projectMessageDTO.getProjectId();        // 手动执行项目 id 或 自动执行子项目 id
+        ProjectPO projectPO = projectUtil.getProjectByProjectId(projectId);
+        projectMessageDTO.setIsChoiceGpu(projectPO.getIsChoiceGpu());
         FutureTask<Integer> createTaskAndFixDataFutureTask = new FutureTask<>(() -> {
             createTaskAndFixData(projectRecord);
             return 1024;
@@ -119,7 +121,7 @@ public class ProjectConsumer {
         String projectId = projectMessageDTO.getProjectId();        // 手动执行项目 id 或 自动执行子项目 id
         String packageId = projectMessageDTO.getScenePackageId();   // 场景测试包 id
         String vehicleConfigId = projectMessageDTO.getVehicleConfigId();// 模型配置 id
-        String algorithmId = projectMessageDTO.getAlgorithmId();// 模型配置 id
+        String algorithmId = projectMessageDTO.getAlgorithmId();    // 模型配置 id
         long videoTime = projectMessageDTO.getMaxSimulationTime();  // 结果视频的时长
         String projectType = projectMessageDTO.getType();           // 项目类型
         String userId = "";  // 用户 id
@@ -385,6 +387,7 @@ public class ProjectConsumer {
     public void parseProject(ProjectMessageDTO projectMessageDTO, String projectWaitingKey, String projectRunningKey,
                              String userId) {
         String projectId = projectMessageDTO.getProjectId();    // 项目 id
+        String isChoiceGpu = projectMessageDTO.getIsChoiceGpu();
         // 项目类型
         int currentParallelism = projectMessageDTO.getCurrentParallelism();   // 当前并行度
         // 场景测试包 id
@@ -426,6 +429,7 @@ public class ProjectConsumer {
         List<NodeTO> nodeListToCount = projectUtil.getNodeListToCount(nodeMap);
         int messageNumber = 0;
         ApacheKafkaUtil.createTopic(kafkaAdminClient, projectId, realCurrentParallelism, (short) 1);   // 创建主题
+        Thread.sleep(5000);
         // 需要即时启动的任务(并行度的大小)
         CopyOnWriteArrayList<String> yamlListToRun = new CopyOnWriteArrayList<>();
         for (String taskJsonPath : taskJsonList) {
@@ -447,10 +451,10 @@ public class ProjectConsumer {
             log.info("------- ProjectConsumer 发送消息成功, 主题 topic 为:" + topic + " 分区 partition 为:"
                     + partition + " 偏移量为:" + offset + " 消息体为:" + taskJson);
             //4-6 发送成功过的同时创建 pod.yaml 文件并把文件地址存到 redis
-            // 选一个count 最少的node,如果 count 是 0 则直接启动。
+            // 选一个count 最少的 node
             AtomicReference<String> currentNodeName = new AtomicReference<>("");
             AtomicInteger currentCount = new AtomicInteger(Integer.MAX_VALUE);
-            nodeListToCount.forEach(nodeTO -> {
+            for (NodeTO nodeTO : nodeListToCount) {
                 int tempCount = nodeTO.getCount();
                 String tempNodeName = nodeTO.getNodeName();
                 if (tempCount < currentCount.get()) {
@@ -458,17 +462,17 @@ public class ProjectConsumer {
                     currentNodeName.set(tempNodeName);
                     nodeTO.setCount(tempCount + 1);
                 }
-            });
+            }
             String currentNodeNameValue = currentNodeName.get();
             int currentCountValue = currentCount.get();
             String tempYaml = projectManager.createTempYaml(projectId, algorithmDockerImage
-                    , currentNodeNameValue, partition, offset, currentCountValue);
+                    , currentNodeNameValue, partition, offset,isChoiceGpu);
             if (currentCountValue == 0) {
                 yamlListToRun.add(tempYaml);
             }
             messageNumber++;
         }
-        Thread.sleep(10);
+        Thread.sleep(5000);
         log.info("项目 " + projectId + " 共发送了 " + messageNumber + " 条消息。");
         log.info("项目 " + projectId + " 准备首先启动 " + yamlListToRun);
         for (String yaml : yamlListToRun) {

+ 27 - 15
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/manager/ProjectManager.java

@@ -1,5 +1,6 @@
 package com.css.simulation.resource.scheduler.manager;
 
+import api.common.pojo.constants.DictConstants;
 import api.common.util.FileUtil;
 import com.css.simulation.resource.scheduler.configuration.kubernetes.KubernetesConfiguration;
 import com.css.simulation.resource.scheduler.util.ProjectUtil;
@@ -33,28 +34,39 @@ public class ProjectManager {
      */
     @SneakyThrows
     public String createTempYaml(String projectId,
-                               String algorithmDockerImage,
-                               String nodeName,
-                               int kafkaPartition,
-                               long kafkaOffset,
-                               int count
+                                 String algorithmDockerImage,
+                                 String nodeName,
+                                 int kafkaPartition,
+                                 long kafkaOffset,
+                                 String isChoiceGpu
 
     ) {
         String podName = projectUtil.getRandomPodName(projectId);   // 生成 podName
         String podYaml = projectUtil.getPodYamlName(nodeName, podName);     // 模板文件名称
         String podString = FileUtil.read(new File(podTemplateYaml));
         String replace0 = podString.replace("vtd-container", "vtd-" + projectId);
-        String replace1 = replace0.replace("vtd-image", kubernetesConfiguration.getVtdImage());
-        String replace2 = replace1.replace("algorithm-container", "algorithm-" + projectId);
-        String replace3 = replace2.replace("algorithm-image", algorithmDockerImage);
-        String replace4 = replace3.replace("kafkaTopic", projectId);     // 消息主题名称为 projectId
-        String replace5 = replace4.replace("kafka-partition", "\"" + kafkaPartition + "\"");     // 消息主题名称为 projectId
-        String replace6 = replace5.replace("kafka-offset", "\"" + kafkaOffset + "\"");     // 消息主题名称为 projectId
-        String replace7 = replace6.replace("pod-name", podName); // pod 名称包括 projectId 和 随机字符串
-        String replace8 = replace7.replace("namespace-name", kubernetesConfiguration.getNamespace()); // pod 名称包括 projectId 和 随机字符串
-        String replace9 = replace8.replace("node-name", nodeName);     // 指定 pod 运行节点
+        String replace1 = replace0.replace("algorithm-container", "algorithm-" + projectId);
+        String replace2 = replace1.replace("algorithm-image", algorithmDockerImage);
+        String replace3 = replace2.replace("kafkaTopic", projectId);     // 消息主题名称为 projectId
+        String replace4 = replace3.replace("kafka-partition", "\"" + kafkaPartition + "\"");     // 消息主题名称为 projectId
+        String replace5 = replace4.replace("kafka-offset", "\"" + kafkaOffset + "\"");     // 消息主题名称为 projectId
+        String replace6 = replace5.replace("pod-name", podName); // pod 名称包括 projectId 和 随机字符串
+        String replace7 = replace6.replace("namespace-name", kubernetesConfiguration.getNamespace()); // pod 名称包括 projectId 和 随机字符串
+        String replace8 = replace7.replace("node-name", nodeName);     // 指定 pod 运行节点
+        String finalYaml = null;
+        if (DictConstants.USE_GPU.equals(isChoiceGpu)) {
+            String replace9 = replace8.replace("vtd-image", kubernetesConfiguration.getVtdImageUseGpu());
+            finalYaml = replace9.replace("vtd-command", kubernetesConfiguration.getVtdCommandUseGpu());
+        }
+        if (DictConstants.NOT_USE_GPU.equals(isChoiceGpu)) {
+            String replace9 = replace8.replace("vtd-image", kubernetesConfiguration.getVtdImageNotUseGpu());
+            finalYaml = replace9.replace("vtd-command", kubernetesConfiguration.getVtdCommandNotUseGpu());
+        }
+        if (finalYaml == null) {
+            throw new RuntimeException("生成 yaml 错误。");
+        }
 //        log.info("ProjectService--createPod 在节点 " + nodeName + " 开始执行 pod:" + tempPodString);
-        FileUtil.writeStringToLocalFile(replace9, podYamlDirectory + podYaml);
+        FileUtil.writeStringToLocalFile(finalYaml, podYamlDirectory + podYaml);
 //        log.info("ProjectService--createPod 在节点 " + nodeName + " 开始执行 pod。");
 //        projectUtil.createPod(nodeName, podName, tempPodString);
         return podYamlDirectory + podYaml;

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

@@ -149,8 +149,8 @@ public class TaskManager {
                     taskMapper.updateFailStateWithStopTime(taskId, state, TimeUtil.getNowForMysql(), DictConstants.TASK_ERROR_REASON_3);
                 } else if ("PendingAnalysis".equals(state)) {
                     taskMapper.updateSuccessStateWithStopTime(taskId, state, TimeUtil.getNowForMysql());
-                    // 查询项目是否使用 cpu 生成视频
-                    String isChoiceGpu = "1";
+                    // 查询项目是否使用 gpu 生成视频(0是1否)
+                    String isChoiceGpu = "0";
                     if (DictConstants.PROJECT_TYPE_MANUAL.equals(projectType)) {
                         isChoiceGpu = manualProjectMapper.selectIsChoiceGpuById(projectId);
                     }
@@ -158,7 +158,7 @@ public class TaskManager {
                         isChoiceGpu = autoSubProjectMapper.selectIsChoiceGpuById(projectId);
                     }
                     log.info("项目 " + projectId + " 是否需要生成 gpu 视频:" + isChoiceGpu);
-                    if (DictConstants.NO.equals(isChoiceGpu)) {
+                    if ("1".equals(isChoiceGpu)) {
                         FutureTask<ResponseBodyVO<String>> videoTask = new FutureTask<>(() -> videoService.generateVideo(projectId, projectType, maxSimulationTime, taskId));
                         new Thread(videoTask, "video-" + StringUtil.getRandomEightBitUUID()).start();
                     }

+ 2 - 0
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/mapper/ManualProjectMapper.java

@@ -18,11 +18,13 @@ public interface ManualProjectMapper {
             @Result(column = "create_user_id", property = "createUserId", jdbcType = JdbcType.VARCHAR),
             @Result(column = "parallelism", property = "parallelism", jdbcType = JdbcType.VARCHAR),
             @Result(column = "project_type", property = "projectType", jdbcType = JdbcType.VARCHAR),
+            @Result(column = "is_choice_gpu", property = "isChoiceGpu", jdbcType = JdbcType.VARCHAR),
             @Result(column = "max_simulation_time", property = "maxSimulationTime", jdbcType = JdbcType.VARCHAR)
     })
     @Select("select id,\n" +
             "       scene,\n" +
             "       create_user_id,\n" +
+            "       is_choice_gpu,\n" +
             "       '1' project_type,\n" +
             "       max_simulation_time\n" +
             "from simulation_manual_project\n" +

+ 1 - 0
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/pojo/po/ProjectPO.java

@@ -17,6 +17,7 @@ public class ProjectPO {
     private String parallelism;
     private String projectType;
     private String maxSimulationTime;
+    private String isChoiceGpu;
 
 
 }

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

@@ -1088,7 +1088,7 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
         projectReportVo.setSubListScoreLi((List<SubScListVo>) stringObjectMap.get("result"));
 
         //场景得分列表
-        Map<String, Object> maps = selectSceneScore2(poParam.getScene(), poParam.getId(), null,projectReportVo);
+        Map<String, Object> maps = selectSceneScore2(poParam.getScene(), poParam.getId(), null, projectReportVo);
         projectReportVo.setSceneScoreLiTitle((List<Map>) maps.get("headerList"));
         projectReportVo.setSceneScoreLi((List<SceneScListVo>) maps.get("result"));
 
@@ -2214,16 +2214,40 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
             SceneScListVo sceneScListVo = new SceneScListVo();
             for (int i = 0; i < start; i++) {
                 if (0 == i) {
-                    sceneScListVo.setSublistName1(list.get(i));
+                    String s0 = list.get(i);
+                    if (StringUtil.isNotEmpty(s0)) {
+                        sceneScListVo.setEachMaxIndex((i + 1) + "");
+                    }
+                    sceneScListVo.setSublistName1(s0);
                 } else if (1 == i) {
+                    String s1 = list.get(i);
+                    if (StringUtil.isNotEmpty(s1)) {
+                        sceneScListVo.setEachMaxIndex((i + 1) + "");
+                    }
                     sceneScListVo.setSublistName2(list.get(i));
                 } else if (2 == i) {
+                    String s2 = list.get(i);
+                    if (StringUtil.isNotEmpty(s2)) {
+                        sceneScListVo.setEachMaxIndex((i + 1) + "");
+                    }
                     sceneScListVo.setSublistName3(list.get(i));
                 } else if (3 == i) {
+                    String s3 = list.get(i);
+                    if (StringUtil.isNotEmpty(s3)) {
+                        sceneScListVo.setEachMaxIndex((i + 1) + "");
+                    }
                     sceneScListVo.setSublistName4(list.get(i));
                 } else if (4 == i) {
+                    String s4 = list.get(i);
+                    if (StringUtil.isNotEmpty(s4)) {
+                        sceneScListVo.setEachMaxIndex((i + 1) + "");
+                    }
                     sceneScListVo.setSublistName5(list.get(i));
                 } else if (5 == i) {
+                    String s5 = list.get(i);
+                    if (StringUtil.isNotEmpty(s5)) {
+                        sceneScListVo.setEachMaxIndex((i + 1) + "");
+                    }
                     sceneScListVo.setSublistName6(list.get(i));
                 }
             }

+ 23 - 17
simulation-resource-video/src/main/java/com/css/simulation/resource/video/service/VideoService.java

@@ -32,7 +32,6 @@ import java.math.RoundingMode;
 import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.util.Iterator;
-import java.util.Map;
 
 @Service
 @Slf4j
@@ -96,18 +95,18 @@ public class VideoService {
         //3 生成 xosc 文件
         String xoscPath = generateXosc(rootDirectoryPathOfLinux, xodrPathOfLinux, osgbPathOfLinux, projectId, projectType);
         // 启动虚拟窗口
-        log.info("生成xosc文件路径-----"+xoscPath);
+        log.info("生成xosc文件路径-----" + xoscPath);
         //4 生成图片
         String pictureDirectoryPath = rootDirectoryPathOfLinux + "picture";
         FileUtil.createDirectory(pictureDirectoryPath);
         String esminiCommandTemp = esminiCommand + " " + xoscPath + " " + pictureDirectoryPath + "/screenshot " + StringUtil.doubleToString(Double.parseDouble(maxSimulationTime), 2);
         LinuxUtil.execute2(XvfbCommand, esminiCommandTemp);
 //        String esminiResult = LinuxUtil.execute(esminiCommandTemp);
-        int num=14;
-        for (int i=0;i<num;i++ ) {
-            String remove="rm -f "+ pictureDirectoryPath + "/screenshot_0000"+i+".tga";
-            log.info("删除图片=="+remove);
-            LinuxUtil.execute( remove);
+        int num = 14;
+        for (int i = 0; i < num; i++) {
+            String remove = "rm -f " + pictureDirectoryPath + "/screenshot_0000" + i + ".tga";
+            log.info("删除图片==" + remove);
+            LinuxUtil.execute(remove);
         }
 
 
@@ -118,7 +117,7 @@ public class VideoService {
 
         String execute = LinuxUtil.execute("ffmpeg"
                 + " -f image2 -framerate 30 "
-                + "-start_number "+num
+                + "-start_number " + num
                 + " -i " + pictureDirectoryPath + "/screenshot_%05d.tga"
                 + " -c:v libx264 -vf format=yuv420p -crf 20 "
                 + videoTargetPathOfLinux
@@ -127,9 +126,16 @@ public class VideoService {
         MinioUtil.uploadFromFile(minioClient, videoTargetPathOfLinux, bucketName, videoTargetPathOfMinio);
         log.info("上传成功:" + videoTargetPathOfMinio);
         //删除生成的临时文件
-        String removeAll="rm -rf "+ pictureDirectoryPath ;
-        log.info("删除全部图片=="+removeAll);
-        LinuxUtil.execute( removeAll);
+        String removeAll = "rm -rf " + pictureDirectoryPath;
+        log.info("删除全部图片==" + removeAll);
+        FileUtil.rm(xodrPathOfLinux);
+        FileUtil.rm(osgbPathOfLinux);
+        FileUtil.rm(csv1PathOfLinux);
+        FileUtil.rm(csv2PathOfLinux);
+
+        //* -------------------------------- 删除临时文件 --------------------------------
+        LinuxUtil.execute(removeAll);
+
         return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS);
     }
 
@@ -155,7 +161,7 @@ public class VideoService {
         String newXoscPath = oldXoscPath.replace(oldXoscName, newXoscName);
         //获取三维自车对象
         VehicleTypePO po = vehicleById(projectId, projectType);
-        log.info("修改 xosc 文件----=="+po.getModel3d());
+        log.info("修改 xosc 文件----==" + po.getModel3d());
 
         //1 创建Reader对象
         SAXReader reader = new SAXReader();
@@ -184,11 +190,11 @@ public class VideoService {
                                     Attribute vehicleCategory = node3.attribute("vehicleCategory");
                                     vehicleCategory.setText(po.getVehicleCategory());
                                     //node3.addAttribute("model3d", po.getModel3d());//自车渲染
-                                    if(null==po.getModel3d()||po.getModel3d().equals("")){
+                                    if (null == po.getModel3d() || po.getModel3d().equals("")) {
                                         node3.addAttribute("model3d", "/root/disk1/simulation-cloud/esmini/resources/models/car_red.osgb");//自车渲染
-                                    }else{
-                                        log.info(" 车辆类型为 为:"+po.getVehicleCategory()+" 渲染文件为:" + po.getModel3d());
-                                        node3.addAttribute("model3d",po.getModel3d());
+                                    } else {
+                                        log.info(" 车辆类型为 为:" + po.getVehicleCategory() + " 渲染文件为:" + po.getModel3d());
+                                        node3.addAttribute("model3d", po.getModel3d());
                                     }
                                     Iterator<Element> iterator4 = node3.elementIterator();
                                     while (iterator4.hasNext()) {
@@ -343,7 +349,7 @@ public class VideoService {
         String car = vehicleType.substring( vehicleType.indexOf(",")+1,vehicleType.lastIndexOf(","));
         log.info("VideoService--vehicleById 车辆类型为:" + car);
     */
-      String car=vehicleInfo.getModelLabel();
+        String car = vehicleInfo.getModelLabel();
        /*String carPath=dictMapper.getCarPath(car);
         if(null!=carPath&&!carPath.equals("")){
             po.setVehicleCategory(car);