|
@@ -3,15 +3,18 @@ package com.css.simulation.resource.scheduler.consumer;
|
|
|
|
|
|
import api.common.pojo.constants.DictConstants;
|
|
|
import api.common.pojo.dto.ProjectMessageDTO;
|
|
|
-import api.common.util.JsonUtil;
|
|
|
-import api.common.util.StringUtil;
|
|
|
+import api.common.util.*;
|
|
|
import com.css.simulation.resource.scheduler.mapper.*;
|
|
|
import com.css.simulation.resource.scheduler.pojo.po.*;
|
|
|
-import com.css.simulation.resource.scheduler.pojo.to.PrefixTO;
|
|
|
+import com.css.simulation.resource.scheduler.pojo.to.*;
|
|
|
import com.css.simulation.resource.scheduler.service.ProjectService;
|
|
|
+import com.css.simulation.resource.scheduler.util.MinioUtil;
|
|
|
import com.css.simulation.resource.scheduler.util.ProjectUtil;
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import io.minio.MinioClient;
|
|
|
+import io.minio.errors.*;
|
|
|
import lombok.SneakyThrows;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
|
@@ -21,6 +24,9 @@ import org.springframework.kafka.annotation.KafkaListener;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.io.IOException;
|
|
|
+import java.security.InvalidKeyException;
|
|
|
+import java.security.NoSuchAlgorithmException;
|
|
|
import java.util.*;
|
|
|
|
|
|
@Component
|
|
@@ -34,9 +40,16 @@ public class ProjectConsumer {
|
|
|
String username;
|
|
|
@Value("${scheduler.host.password}")
|
|
|
String password;
|
|
|
+ @Value("${scheduler.linux-path.temp}")
|
|
|
+ String linuxTempPath;
|
|
|
+ @Value("${scheduler.minio-path.project-result}")
|
|
|
+ String projectResultPathOfMinio;
|
|
|
+ @Value("${minio.bucket-name}")
|
|
|
+ String bucketName;
|
|
|
|
|
|
|
|
|
-
|
|
|
+ @Resource
|
|
|
+ MinioClient minioClient;
|
|
|
@Resource
|
|
|
StringRedisTemplate stringRedisTemplate;
|
|
|
@Resource
|
|
@@ -57,6 +70,165 @@ public class ProjectConsumer {
|
|
|
ProjectService projectService;
|
|
|
@Resource
|
|
|
ProjectUtil projectUtil;
|
|
|
+ @Resource
|
|
|
+ IndexMapper indexMapper;
|
|
|
+ @Resource
|
|
|
+ TaskMapper taskMapper;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ * 接收到运行信息立即复制一份数据作为运行数据
|
|
|
+ *
|
|
|
+ * @param projectRecord 项目启动消息
|
|
|
+ */
|
|
|
+ @KafkaListener(groupId = "simulation-resource-scheduler", topics = "${scheduler.start-topic}")
|
|
|
+ @SneakyThrows
|
|
|
+ public void createTaskAndFixData(ConsumerRecord<String, String> projectRecord) {
|
|
|
+
|
|
|
+ String initialProjectJson = projectRecord.value();
|
|
|
+ log.info("ProjectConsumer.fixedData() 接收到项目开始消息为:" + initialProjectJson);
|
|
|
+ ProjectMessageDTO projectMessageDTO = JsonUtil.jsonToBean(initialProjectJson, ProjectMessageDTO.class);
|
|
|
+ String projectId = projectMessageDTO.getProjectId();
|
|
|
+ String packageId = projectMessageDTO.getScenePackageId();
|
|
|
+ String vehicleConfigId = projectMessageDTO.getVehicleConfigId();
|
|
|
+ long videoTime = projectMessageDTO.getMaxSimulationTime();
|
|
|
+ long parallelism = projectMessageDTO.getParallelism();
|
|
|
+ String projectType = projectMessageDTO.getType();
|
|
|
+ String userId = "";
|
|
|
+ if (DictConstants.PROJECT_TYPE_MANUAL.equals(projectType)) {
|
|
|
+ userId = manualProjectMapper.selectCreateUserById(projectId);
|
|
|
+ } else if (DictConstants.PROJECT_TYPE_AUTO_SUB.equals(projectType)) {
|
|
|
+ userId = autoSubProjectMapper.selectCreateUserById(projectId);
|
|
|
+ }
|
|
|
+ String projectPath = linuxTempPath + projectId + "/";
|
|
|
+ FileUtil.mkdir(projectPath);
|
|
|
+
|
|
|
+
|
|
|
+ List<ScenePO> scenePOList = projectService.getSceneList(projectId, packageId, projectPath);
|
|
|
+ int taskTotal = scenePOList.size();
|
|
|
+ projectMessageDTO.setTaskTotal(taskTotal);
|
|
|
+ projectMessageDTO.setTaskCompleted(0);
|
|
|
+
|
|
|
+ Set<ScenePO> scenePOSet = new HashSet<>(scenePOList);
|
|
|
+
|
|
|
+
|
|
|
+ VehiclePO vehiclePO = vehicleMapper.selectByVehicleConfigId(vehicleConfigId);
|
|
|
+ List<CameraPO> cameraPOList = sensorCameraMapper.selectCameraByVehicleConfigId(vehicleConfigId);
|
|
|
+ List<OgtPO> ogtPOList = sensorOgtMapper.selectOgtByVehicleId(vehicleConfigId);
|
|
|
+
|
|
|
+ log.info("ProjectService--sendTaskMessage 项目 " + projectId + " 获得的包括的场景信息为:" + scenePOSet);
|
|
|
+ for (ScenePO scenePO : scenePOSet) {
|
|
|
+ String sceneId = scenePO.getId();
|
|
|
+
|
|
|
+ List<String> lastTargetIdList = null;
|
|
|
+ if (DictConstants.PROJECT_TYPE_MANUAL.equals(projectType)) {
|
|
|
+ lastTargetIdList = indexMapper.selectLeafIndexIdByManualProjectIdAndSceneId(projectId, "%" + sceneId + "%");
|
|
|
+ } else if (DictConstants.PROJECT_TYPE_AUTO_SUB.equals(projectType)) {
|
|
|
+ lastTargetIdList = indexMapper.selectLeafIndexIdByAutoSubProjectIdAndSceneId(projectId, "%" + sceneId + "%");
|
|
|
+ }
|
|
|
+ if (CollectionUtil.isEmpty(lastTargetIdList)) {
|
|
|
+ throw new RuntimeException("ProjectConsumer.createTaskAndFixData() -- 项目 " + projectId + " 使用的场景测试包 " + sceneId + " 不存在指标。");
|
|
|
+ }
|
|
|
+ for (String lastTargetId : lastTargetIdList) {
|
|
|
+ String taskId = StringUtil.getRandomUUID();
|
|
|
+
|
|
|
+ TaskPO taskPO = TaskPO.builder()
|
|
|
+ .id(taskId)
|
|
|
+ .pId(projectId)
|
|
|
+ .sceneId(sceneId)
|
|
|
+ .lastTargetId(lastTargetId)
|
|
|
+ .sceneName(scenePO.getName())
|
|
|
+ .sceneType(scenePO.getType())
|
|
|
+ .runState(DictConstants.TASK_PENDING)
|
|
|
+ .runResultFilePath(projectResultPathOfMinio + projectId + "/" + taskId)
|
|
|
+ .build();
|
|
|
+ taskPO.setCreateTime(TimeUtil.getNowForMysql());
|
|
|
+ taskPO.setCreateUserId(userId);
|
|
|
+ taskPO.setModifyTime(TimeUtil.getNowForMysql());
|
|
|
+ taskPO.setModifyUserId(userId);
|
|
|
+ taskPO.setModifyTime(TimeUtil.getNowForMysql());
|
|
|
+ taskPO.setIsDeleted("0");
|
|
|
+ taskMapper.insert(taskPO);
|
|
|
+
|
|
|
+ String scenarioOdr = scenePO.getScenarioOdr();
|
|
|
+ String scenarioOsgb = scenePO.getScenarioOsgb();
|
|
|
+ String[] splitXodr = scenarioOdr.split("/");
|
|
|
+ String xodrName = splitXodr[splitXodr.length - 1];
|
|
|
+ String[] splitOsgb = scenarioOsgb.split("/");
|
|
|
+ String osgbName = splitOsgb[splitOsgb.length - 1];
|
|
|
+ try {
|
|
|
+ String xodrPathOfLinux = linuxTempPath + "video/" + projectId + "/" + taskId + "/" + xodrName;
|
|
|
+ String xodrPathOfMinio = projectResultPathOfMinio + projectId + "/" + taskId + "/" + taskId + ".xodr";
|
|
|
+ String osgbPathOfLinux = linuxTempPath + "video/" + projectId + "/" + taskId + "/" + osgbName;
|
|
|
+ String osgbPathOfMinio = projectResultPathOfMinio + projectId + "/" + taskId + "/" + taskId + ".osgb";
|
|
|
+ MinioUtil.downloadToFile(minioClient, bucketName, scenarioOdr, xodrPathOfLinux);
|
|
|
+ MinioUtil.uploadFromFile(minioClient, xodrPathOfLinux, bucketName, xodrPathOfMinio);
|
|
|
+ log.info("ProjectService--sendTaskMessage 已经将 xodr 上传到 minio 的结果文件目录:" + xodrPathOfMinio);
|
|
|
+ MinioUtil.downloadToFile(minioClient, bucketName, scenarioOsgb, osgbPathOfLinux);
|
|
|
+ MinioUtil.uploadFromFile(minioClient, osgbPathOfLinux, bucketName, osgbPathOfMinio);
|
|
|
+ log.info("ProjectService--sendTaskMessage 已经将 osgb 上传到 minio 的结果文件目录:" + osgbPathOfMinio);
|
|
|
+ } catch (IOException | ServerException | InsufficientDataException | ErrorResponseException |
|
|
|
+ NoSuchAlgorithmException | InvalidKeyException | InvalidResponseException |
|
|
|
+ XmlParserException | InternalException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ TaskTO taskTO = TaskTO.builder()
|
|
|
+ .info(InfoTO.builder()
|
|
|
+ .project_id(taskPO.getPId())
|
|
|
+ .task_id(taskPO.getId())
|
|
|
+ .task_path(taskPO.getRunResultFilePath())
|
|
|
+ .default_time(videoTime)
|
|
|
+ .build())
|
|
|
+ .scenario(ScenarioTO.builder()
|
|
|
+ .scenario_osc(scenePO.getScenarioOsc())
|
|
|
+ .scenario_odr(scenarioOdr)
|
|
|
+ .scenario_osgb(scenarioOsgb)
|
|
|
+ .build())
|
|
|
+ .vehicle(VehicleTO.builder()
|
|
|
+ .model(ModelTO.builder()
|
|
|
+ .model_label(vehiclePO.getModelLabel())
|
|
|
+ .build())
|
|
|
+ .dynamics(DynamicsTO.builder()
|
|
|
+ .dynamics_maxspeed(vehiclePO.getMaxSpeed())
|
|
|
+ .dynamics_enginepower(vehiclePO.getEnginePower())
|
|
|
+ .dynamics_maxdecel(vehiclePO.getMaxDeceleration())
|
|
|
+ .dynamics_maxsteering(vehiclePO.getMaxSteeringAngle())
|
|
|
+ .dynamics_mass(vehiclePO.getMass())
|
|
|
+ .dynamics_frontsurfaceeffective(vehiclePO.getFrontSurfaceEffective())
|
|
|
+ .dynamics_airdragcoefficient(vehiclePO.getAirDragCoefficient())
|
|
|
+ .dynamics_rollingresistance(vehiclePO.getRollingResistanceCoefficient())
|
|
|
+ .dynamics_wheeldiameter(vehiclePO.getWheelDiameter())
|
|
|
+ .dynamics_wheeldrive(vehiclePO.getWheelDrive())
|
|
|
+ .dynamics_overallefficiency(vehiclePO.getOverallEfficiency())
|
|
|
+ .dynamics_distfront(vehiclePO.getFrontDistance())
|
|
|
+ .dynamics_distrear(vehiclePO.getRearDistance())
|
|
|
+ .dynamics_distleft(vehiclePO.getLeftDistance())
|
|
|
+ .dynamics_distright(vehiclePO.getRightDistance())
|
|
|
+ .dynamics_distheight(vehiclePO.getHeightDistance())
|
|
|
+ .dynamics_wheelbase(vehiclePO.getWheelbase())
|
|
|
+ .build())
|
|
|
+ .sensors(SensorsTO.builder()
|
|
|
+ .camera(cameraPOList)
|
|
|
+ .OGT(ogtPOList)
|
|
|
+ .build())
|
|
|
+ .build())
|
|
|
+ .build();
|
|
|
+
|
|
|
+
|
|
|
+ String taskJson = "";
|
|
|
+ try {
|
|
|
+ taskJson = JsonUtil.beanToJson(taskTO);
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ String finalTaskJson = taskJson;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|